Allow creating empty file in filesystem browser
ClosedPublic

Authored by abogdanenko on Dec 23 2018, 4:26 PM.

Details

Summary

This commit allows user to create new empty files from filesystem
browser plugin. Filenames without extension are supported.

Menu items which produce such files were missing from Create New menu.
This is due to the way MIME type filter was configured. The filter
included files of type text/plain. However, empty files without
extension, for example, an empty file named "empty", do not belong to
class text/plain.

Both kmimetypefinder5 and xdg-mime utilities classify such a file as
application/x-zerosize. According to the current Shared MIME-Info
database, application/x-zerosize MIME type is not a subclass of type
text/plain, see
https://gitlab.freedesktop.org/xdg/shared-mime-info/blob/58bee0a8b52f4ced82c3ac227e688e24dc4259bf/freedesktop.org.xml.in#L3966.

This commit extends the filter accordingly.

Diff Detail

Repository
R40 Kate
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
abogdanenko created this revision.Dec 23 2018, 4:26 PM
Restricted Application added a project: Kate. · View Herald TranscriptDec 23 2018, 4:26 PM
Restricted Application added a subscriber: kwrite-devel. · View Herald Transcript
abogdanenko requested review of this revision.Dec 23 2018, 4:26 PM

Here is an example template which generates "Empty File..." menu item.

First, create directories for templates:

mkdir --parents --verbose ~/.local/share/templates/.source

Second, create empty template file:

touch ~/.local/share/templates/.source/empty

Third, create desktop entry. Create file ~/.local/share/templates/empty.desktop with the following contents:

[Desktop Entry]
Name=Empty File...

Comment=Enter filename:

Type=Link
URL=.source/empty
Icon=none

I'm confused. I can already create new empty files from the Filesystem Browser view:

I can see why you are confused. According to the documentation for Create New
menu, we could expect empty file to be created.

See The Konqueror Handbook. 3. Konqueror the File Manager. Create New

> Use this to create an ordinary, empty, text file.

See also The Dolphin Handbook. Chapter 4. Command Reference

> Creates a new object (such as a folder or a text file) in the current
> folder.
>
> You will find an explanation of all available objects in Konqueror's
> handbook in the chapter Create New.

However, this is not what we get, see
KDE Neon > Dolphin > Create New > Text File: File not empty. • KDE Community Forums.

Current template is defined here
https://phabricator.kde.org/source/kio/browse/master/src/new_file_templates/TextFile.txt
(View as Hexdump) and referenced in desktop file here
https://phabricator.kde.org/source/kio/browse/master/src/new_file_templates/TextFile.desktop.

As far as I understand, on my computer running Debian testing the template is
hard-coded into shared library shipped with libkf5kiofilewidgets5 package,
so a user can't change the template.

Anyway, here I'm not suggesting we change the template, we could discuss that
separately. I'm merely asking to support user-defined templates like the one I
published in a comment above.

As a developer, I often create empty files in the same directory where the
current open file is, so this feature is useful to me.

I think kwrite is the wrong target audience. Much better would be KIO and Dolphin.

Ah sorry, I only now see this us for the file system browser. Then this should be ok. Can you attach a screenshot?

Ah, I see what you mean now. Thanks for explaining! Makes sense to me.

abogdanenko added a comment.EditedDec 24 2018, 3:54 PM

I'm posting before and after pictures as requested.

Note that before starting the editor, I had created "Empty File..." template as
described in my comment above. See the comment published on Sun, Dec 23 at
7:50 PM.

Before my patch menu item is missing:

After my patch:

cullmann accepted this revision.Dec 26 2018, 9:19 PM
cullmann added a subscriber: cullmann.

Fine with that, thanks for the addition.

This revision is now accepted and ready to land.Dec 26 2018, 9:19 PM
This revision was automatically updated to reflect the committed changes.