diff --git a/autotests/knewfilemenutest.cpp b/autotests/knewfilemenutest.cpp --- a/autotests/knewfilemenutest.cpp +++ b/autotests/knewfilemenutest.cpp @@ -94,9 +94,9 @@ QTest::addColumn("typedFilename"); // what the user is typing QTest::addColumn("expectedFilename"); // the final file name - QTest::newRow("text file") << "Text File" << "Text File" << "tmp_knewfilemenutest.txt" << "tmp_knewfilemenutest.txt"; - QTest::newRow("text file with jpeg extension") << "Text File" << "Text File" << "foo.jpg" << "foo.jpg.txt"; - QTest::newRow("html file") << "HTML File" << "HTML File" << "foo.html" << "foo.html"; + QTest::newRow("text file") << "Text File" << "Text File.txt" << "tmp_knewfilemenutest.txt" << "tmp_knewfilemenutest.txt"; + QTest::newRow("text file with jpeg extension") << "Text File" << "Text File.txt" << "foo.jpg" << "foo.jpg.txt"; + QTest::newRow("html file") << "HTML File" << "HTML File.html" << "foo.html" << "foo.html"; QTest::newRow("url desktop file") << "Link to Location " << "" << "tmp_link.desktop" << "tmp_link.desktop"; QTest::newRow("url desktop file no extension") << "Link to Location " << "" << "tmp_link" << "tmp_link"; QTest::newRow("url desktop file .pl extension") << "Link to Location " << "" << "tmp_link.pl" << "tmp_link.pl.desktop"; diff --git a/src/filewidgets/knewfilemenu.cpp b/src/filewidgets/knewfilemenu.cpp --- a/src/filewidgets/knewfilemenu.cpp +++ b/src/filewidgets/knewfilemenu.cpp @@ -460,10 +460,15 @@ void KNewFileMenuPrivate::executeRealFileOrDir(const KNewFileMenuSingleton::Entry &entry) { // The template is not a desktop file - // Show the small dialog for getting the destination filename + // Prompt the user to set the destination filename QString text = entry.text; text.remove(QStringLiteral("...")); // the ... is fine for the menu item but not for the default filename text = text.trimmed(); // In some languages, there is a space in front of "...", see bug 268895 + // add the extension (from the templatePath), should work with .txt, .html and with ".tar.gz"... etc + const QString fileName = entry.templatePath.mid(entry.templatePath.lastIndexOf(QLatin1Char('/'))); + const int dotIndex = fileName.indexOf(QLatin1Char('.')); + text += dotIndex > 0 ? fileName.midRef(dotIndex) : QStringRef(); + m_copyData.m_src = entry.templatePath; const QUrl directory = mostLocalUrl(m_popupFiles.first());