[KNewFileMenu] Add extension to proposed filename
ClosedPublic

Authored by ahmadsamir on Mar 26 2020, 11:09 AM.

Details

Summary

Using "create new" text or html file, add the extension to the proposed
filename, this makes those plain text files work for other OS's e.g.
Windows (with Linux plain text files (.txt) don't usually have a extension
relying on mimetype detection); as for but HTML filenames they do have
extensions even on Linux.

Adapt the knewfilemenutest to the changes.

BUG: 61669

Test Plan

make && ctest; and using the create name text/html file menu in dolphin

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ahmadsamir created this revision.Mar 26 2020, 11:09 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptMar 26 2020, 11:09 AM
ahmadsamir requested review of this revision.Mar 26 2020, 11:09 AM
dfaure requested changes to this revision.Mar 28 2020, 9:49 AM

Thanks for all your work, I'm impressed!

src/filewidgets/knewfilemenu.cpp
467

typo: extenstion -> extension

469

The old code was using a translated string as suggested file name.
You're using a filename that it going to be always in English.

How about appending the extension from templatePath to the translated text?

This revision now requires changes to proceed.Mar 28 2020, 9:49 AM
  • Change it as suggested by dfaure to use the translated text from Name= entry
  • Fix typos
dfaure added inline comments.Mar 28 2020, 11:22 AM
src/filewidgets/knewfilemenu.cpp
467

"use the translation" is done before that comment, so it's a bit of a confusing place for it.

470

text += fileName.midRef(....);

This also assumes all those files always have an extension.... mid(-1) returns the whole string.
Since users can create additional templates, maybe this is worth a >=0 check?

ahmadsamir updated this revision to Diff 78731.Mar 28 2020, 3:16 PM
ahmadsamir edited the summary of this revision. (Show Details)
  • Fix unit test
  • Handle the case that a templatePath is a file with no extension
dfaure accepted this revision.Mar 28 2020, 4:49 PM
This revision is now accepted and ready to land.Mar 28 2020, 4:49 PM
This revision was automatically updated to reflect the committed changes.