Hi,
I realized that in the "documents" sidebar each and every files have an icon, but they all have the same, no matter what. I had a little time and I decided to play a bit with the idea of having file-type based icons.
Such icons could be displayed at a few places:
1) In the Documents sidebar: there is already icons and it would probably ease to find a particular item (if different filetypes are mixed, of course). Anyway I think it's better to have the "right" icons rather than always using the same. (capture joined)
2) In the document notebook popup. This will perhaps ease finding the item, but perhaps adds clutter. Not sure. (capture joined)
3) In the tab title, like GEdit does. I think this one is a bad idea since it is probably useless and only use a little more space.
Before any deeper thoughts, I want to add a few technical details: I added MIME type for every built-in filetypes [1] (see below why). I think that anyway it's a good thing to have the MIME type since it may allow to e.g. filter file selection by MIME type rather that extension only [2], etc. So this might be interesting to keep even without filetype icons.
I use g_content_type_get_icon() (GLib/GIO 2.14 AFAIK, but not sure) and g_content_type_from_mime_type() (ouch, GLib/GIO 2.18). The first is obviously useful, and the second is there because I didn't wanted to use g_content_type_guess() because I think it'd be slow, and because we already know the filetype. I have a fallback if not available, but it doesn't provide different icons for different file types (currently only file/directory icons).
So, the problem is mainly the GLib version in use, 2.18, that is probably not really acceptable... but it isn't a real "feature" but rather a UI candy, so the fallback is perhaps fine.
And finally, the current points that are problematic: When sidebar_openfiles_add() is called, it's very likely that the document's filetype isn't set yet, so no icon (or a default one). It only appears when an opened file is renamed, since it updates the entry and the filetype is set at this time. Not sure how to fix this, but I haven't investigated yet. Same applies for notebook tabs, but since I'm really not sure it's a good idea to add them, I didn't tried yet.
So, before going further and fixing the things that don't work, what do you think of this? Would it be better with or without it?
Regards, Colomban
[1] Patch joined, 0001-Add-MIME-type-to-GeanyFiletype.patch. I have set the MIME type to text/plain when I didn't find the right one, but perhaps NULL would be better to denote that it isn't reliable. [2] Patch 0001-Add-MIME-type-filtering-in-file-chooser-dialog.patch
Am Donnerstag, den 14.10.2010, 16:36 +0200 schrieb Colomban Wendling:
Hi,
I realized that in the "documents" sidebar each and every files have an icon, but they all have the same, no matter what. I had a little time and I decided to play a bit with the idea of having file-type based icons.
Such icons could be displayed at a few places:
- In the Documents sidebar: there is already icons and it would
probably ease to find a particular item (if different filetypes are mixed, of course). Anyway I think it's better to have the "right" icons rather than always using the same. (capture joined)
- In the document notebook popup. This will perhaps ease finding the
item, but perhaps adds clutter. Not sure. (capture joined)
- In the tab title, like GEdit does. I think this one is a bad idea
since it is probably useless and only use a little more space.
4) In file browser and tree browser plugin, which maybe could use functions provided by Geany for showing those icons.
I short: I love this idea! :)
Regards, Dominic
Le 15/10/2010 00:03, Dominic Hopf a écrit :
Am Donnerstag, den 14.10.2010, 16:36 +0200 schrieb Colomban Wendling:
Hi,
I realized that in the "documents" sidebar each and every files have an icon, but they all have the same, no matter what. I had a little time and I decided to play a bit with the idea of having file-type based icons.
Such icons could be displayed at a few places:
- In the Documents sidebar: there is already icons and it would
probably ease to find a particular item (if different filetypes are mixed, of course). Anyway I think it's better to have the "right" icons rather than always using the same. (capture joined)
- In the document notebook popup. This will perhaps ease finding the
item, but perhaps adds clutter. Not sure. (capture joined)
- In the tab title, like GEdit does. I think this one is a bad idea
since it is probably useless and only use a little more space.
- In file browser and tree browser plugin, which maybe could use
functions provided by Geany for showing those icons.
Not sure it's really helpful for *browsers, because you have to know the file type already. I'd think g_content_type_guess() is probably more appropriate there since we don't know the content type already, and then you directly get the icon (with g_content_type_get_icon()).
I short: I love this idea! :)
Fine then :) Having that icon is fairly easy, but as said, I'm currently unable to display it reliably in the document sidebar.
Joined 0001-Add-filetype-icon.patch (depends on previous 0001-Add-MIME-type-to-GeanyFiletype.patch) that add filetype->icon, a 16x16 GdkPixbuf icon that represents the file type.
Also joined 0001-Add-filetype-icon-to-the-editor-notebook-popup.patch that... huh, adds filetype icon to the editor notebook popup entries, to show how it looks like. (this was suggestion 2).
Regards, Colomban
Le 15/10/2010 00:35, Colomban Wendling a écrit :
Joined 0001-Add-filetype-icon.patch (depends on previous 0001-Add-MIME-type-to-GeanyFiletype.patch) that add filetype->icon, a 16x16 GdkPixbuf icon that represents the file type.
Joined is an updated patch, thanks to Andrian Dimitrov for finding gtk_icon_size_lookup() :)
Regards, Colomban
On Sat, 16 Oct 2010 17:59:28 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
Le 15/10/2010 00:35, Colomban Wendling a écrit :
Joined 0001-Add-filetype-icon.patch (depends on previous 0001-Add-MIME-type-to-GeanyFiletype.patch) that add filetype->icon, a 16x16 GdkPixbuf icon that represents the file type.
Joined is an updated patch, thanks to Andrian Dimitrov for finding gtk_icon_size_lookup() :)
I like the idea but haven't examined the patches yet. If it makes sense can you combine the patches into one to review as it's a bit confusing at the moment.
Nick
Le 21/10/2010 17:19, Nick Treleaven a écrit :
On Sat, 16 Oct 2010 17:59:28 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
Le 15/10/2010 00:35, Colomban Wendling a écrit :
Joined 0001-Add-filetype-icon.patch (depends on previous 0001-Add-MIME-type-to-GeanyFiletype.patch) that add filetype->icon, a 16x16 GdkPixbuf icon that represents the file type.
Joined is an updated patch, thanks to Andrian Dimitrov for finding gtk_icon_size_lookup() :)
I like the idea but haven't examined the patches yet. If it makes sense can you combine the patches into one to review as it's a bit confusing at the moment.
OK, no problem. Which one would you have combined? All stuff needed for the one that adds filetype->icon, or also the one that uses these icons in the Documents sidebar?
Regards, Colomban
Le 21/10/2010 19:08, Colomban Wendling a écrit :
Le 21/10/2010 17:19, Nick Treleaven a écrit :
On Sat, 16 Oct 2010 17:59:28 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
Le 15/10/2010 00:35, Colomban Wendling a écrit :
Joined 0001-Add-filetype-icon.patch (depends on previous 0001-Add-MIME-type-to-GeanyFiletype.patch) that add filetype->icon, a 16x16 GdkPixbuf icon that represents the file type.
Joined is an updated patch, thanks to Andrian Dimitrov for finding gtk_icon_size_lookup() :)
I like the idea but haven't examined the patches yet. If it makes sense can you combine the patches into one to review as it's a bit confusing at the moment.
OK, no problem. Which one would you have combined? All stuff needed for the one that adds filetype->icon, or also the one that uses these icons in the Documents sidebar?
Anyway, I join here the following updated patches against HEAD. Main ones:
0001-Add-MIME-type-to-GeanyFiletype.patch: * Adds MIME type to GeanyFiletype for every filetype. If I didn't find the actual file type, it is set to text/plain and have a FIXME
0002-Add-filetype-icon.patch: * Adds icon to each and every filetype. Depends on the previous patch, 0001-Add-MIME-type-to-GeanyFiletype.patch.
0003-Add-filetype-specific-icon-to-the-document-list-side.patch * Use filetype's icon in the Document sidebar as the file's icon. Depends on the previous patch, 0002-Add-filetype-icon.patch.
And some additional patch that may also be interesting:
0003-Add-filetype-icon-to-the-editor-notebook-popup.patch: * Display filetype's icon in the notebook's editor popup menu. Depends on 0002-Add-filetype-icon.patch.
0002-Add-MIME-type-filtering-in-file-chooser-dialog.patch: * Very short patch, adds MIME-type based filtering for file filtering.
Basically you can trust the heading number for the dependency, > 0 means it has a dependency on another patch.
The combined patch(es) will come separately in a few minutes for less confusion.
Best regards, Colomban
Le 22/10/2010 02:30, Colomban Wendling a écrit :
Le 21/10/2010 19:08, Colomban Wendling a écrit :
Le 21/10/2010 17:19, Nick Treleaven a écrit :
On Sat, 16 Oct 2010 17:59:28 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
Le 15/10/2010 00:35, Colomban Wendling a écrit :
Joined 0001-Add-filetype-icon.patch (depends on previous 0001-Add-MIME-type-to-GeanyFiletype.patch) that add filetype->icon, a 16x16 GdkPixbuf icon that represents the file type.
Joined is an updated patch, thanks to Andrian Dimitrov for finding gtk_icon_size_lookup() :)
I like the idea but haven't examined the patches yet. If it makes sense can you combine the patches into one to review as it's a bit confusing at the moment.
OK, no problem. Which one would you have combined? All stuff needed for the one that adds filetype->icon, or also the one that uses these icons in the Documents sidebar?
[…]
The combined patch(es) will come separately in a few minutes for less confusion.
Here we are:
0001-Add-MIME-type-and-icon-to-GeanyFiletype.patch: * Combination of 0001-Add-MIME-type-to-GeanyFiletype.patch and 0002-Add-filetype-icon.patch, so it adds both MIME type and icon to filetypes.
@Nick: If you want me to provide further combination of some of these patches, just tell me :)
Regards, Colomban
On Fri, 22 Oct 2010 02:34:23 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
The combined patch(es) will come separately in a few minutes for less confusion.
Here we are:
0001-Add-MIME-type-and-icon-to-GeanyFiletype.patch:
- Combination of 0001-Add-MIME-type-to-GeanyFiletype.patch and 0002-Add-filetype-icon.patch, so it adds both MIME type and icon to filetypes.
Thanks, applied. Minor changes below:
@@ -480,6 +532,9 @@ static void filetype_add(GeanyFiletype *ft) g_hash_table_insert(filetypes_hash, ft->name, ft);
filetypes_by_title = g_slist_insert_sorted(filetypes_by_title, ft, cmp_filetype);
- if (!ft->icon && ft->mime_type)
ft->icon = ui_get_mime_icon(ft->mime_type, GTK_ICON_SIZE_MENU);
ft->icon should always be null there so I removed that part.
+GdkPixbuf *ui_get_mime_icon(const gchar *mime_type, GtkIconSize size) +{
...
- gint real_size;
- g_return_val_if_fail(gtk_icon_size_lookup(size, &real_size, NULL), NULL);
You shouldn't put side effects into an assert statement because asserts can be disabled. Fixed.
Nick
Le 26/10/2010 18:06, Nick Treleaven a écrit :
On Fri, 22 Oct 2010 02:34:23 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
The combined patch(es) will come separately in a few minutes for less confusion.
Here we are:
0001-Add-MIME-type-and-icon-to-GeanyFiletype.patch:
- Combination of 0001-Add-MIME-type-to-GeanyFiletype.patch and 0002-Add-filetype-icon.patch, so it adds both MIME type and icon to filetypes.
Thanks, applied. Minor changes below:
@@ -480,6 +532,9 @@ static void filetype_add(GeanyFiletype *ft) g_hash_table_insert(filetypes_hash, ft->name, ft);
filetypes_by_title = g_slist_insert_sorted(filetypes_by_title, ft, cmp_filetype);
- if (!ft->icon && ft->mime_type)
ft->icon = ui_get_mime_icon(ft->mime_type, GTK_ICON_SIZE_MENU);
ft->icon should always be null there so I removed that part.
True, the check is useless.
+GdkPixbuf *ui_get_mime_icon(const gchar *mime_type, GtkIconSize size) +{
...
- gint real_size;
- g_return_val_if_fail(gtk_icon_size_lookup(size, &real_size, NULL), NULL);
You shouldn't put side effects into an assert statement because asserts can be disabled. Fixed.
Right, I didn't thought about that. But I' not sure it's a good idea to do the call twice, I'd think it's probably better to store the return value of gtk_icon_size_lookup() and check it, don't you think? We would have a less beautiful error message if the check fails, but in most cases we avoid to lookup the size twice.
Anyway, thanks for reviewing :)
Regards, Colomban
On Tue, 26 Oct 2010 19:56:37 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
You shouldn't put side effects into an assert statement because asserts can be disabled. Fixed.
Right, I didn't thought about that. But I' not sure it's a good idea to do the call twice, I'd think it's probably better to store the return value of gtk_icon_size_lookup() and check it, don't you think? We would have a less beautiful error message if the check fails, but in most cases we avoid to lookup the size twice.
You're right, it was a bit ugly. Now fixed.
Nick
On Fri, 22 Oct 2010 02:30:27 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
0003-Add-filetype-specific-icon-to-the-document-list-side.patch
- Use filetype's icon in the Document sidebar as the file's icon. Depends on the previous patch, 0002-Add-filetype-icon.patch.
0003-Add-filetype-icon-to-the-editor-notebook-popup.patch:
- Display filetype's icon in the notebook's editor popup menu. Depends on 0002-Add-filetype-icon.patch.
Committed both, thanks. I haven't tested them on GTK 2.18 yet.
0002-Add-MIME-type-filtering-in-file-chooser-dialog.patch:
- Very short patch, adds MIME-type based filtering for file filtering.
Not sure about this. So file extensions not known by Geany but known by system mime type can be recognised when opening files with the file chooser? I think that might be inconsistent with opening files in other ways.
Nick
Le 26/10/2010 19:42, Nick Treleaven a écrit :
On Fri, 22 Oct 2010 02:30:27 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
0003-Add-filetype-specific-icon-to-the-document-list-side.patch
- Use filetype's icon in the Document sidebar as the file's icon. Depends on the previous patch, 0002-Add-filetype-icon.patch.
0003-Add-filetype-icon-to-the-editor-notebook-popup.patch:
- Display filetype's icon in the notebook's editor popup menu. Depends on 0002-Add-filetype-icon.patch.
Committed both, thanks. I haven't tested them on GTK 2.18 yet.
0002-Add-MIME-type-filtering-in-file-chooser-dialog.patch:
- Very short patch, adds MIME-type based filtering for file filtering.
Not sure about this. So file extensions not known by Geany but known by system mime type can be recognised when opening files with the file chooser? I think that might be inconsistent with opening files in other ways.
True, it might be a bit strange for the user... The idea I had is that it brings us the system MIME-type detection mechanism, so e.g. a web page without extension would be recognized as HTML; and I'd think Geany would do somewhat compatible detection after opening the file -- e.g. it detects the HTML files as HTML even without extension.
But I totally understand your remark, and I quite agree with it. So... perhaps it wasn't a good idea, not sure either.
Regards, Colomban
Le 14/10/2010 16:36, Colomban Wendling a écrit :
Hi,
I realized that in the "documents" sidebar each and every files have an icon, but they all have the same, no matter what. I had a little time and I decided to play a bit with the idea of having file-type based icons.
Such icons could be displayed at a few places:
- In the Documents sidebar: there is already icons and it would
probably ease to find a particular item (if different filetypes are mixed, of course). Anyway I think it's better to have the "right" icons rather than always using the same. (capture joined)
[...]
And finally, the current points that are problematic: When sidebar_openfiles_add() is called, it's very likely that the document's filetype isn't set yet, so no icon (or a default one). It only appears when an opened file is renamed, since it updates the entry and the filetype is set at this time. Not sure how to fix this, but I haven't investigated yet.
After a small investigation I managed to find a quite simple way, so there's a patch! Needs the 0001-Add-filetype-icon.patch patch (in another mail from this thread), there's 0001-Add-filetype-specific-icon-to-the-document-list-side.patch joined.
Regards, Colomban
On Thu, 14 Oct 2010 16:36:43 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
This patch adds a new mime_type field to GeanyFiletype and sets it for every built-in filetype. Built-in filetypes for which I didn't find the MIME type defaults to text/plain, but it would perhaps be better to set it to NULL to explicitly say that it isn't the right one.
I've removed text/plain defaults now. I think it will help when testing. Custom filetypes were NULL too, so I fixed the menu item icon code to handle NULL.
Nick
Le 26/10/2010 19:45, Nick Treleaven a écrit :
On Thu, 14 Oct 2010 16:36:43 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
This patch adds a new mime_type field to GeanyFiletype and sets it for every built-in filetype. Built-in filetypes for which I didn't find the MIME type defaults to text/plain, but it would perhaps be better to set it to NULL to explicitly say that it isn't the right one.
I've removed text/plain defaults now. I think it will help when testing.
OK. Are you sure about removing it also for GEANY_FILETYPES_NONE?
Custom filetypes were NULL too, so I fixed the menu item icon code to handle NULL.
Oups, forgot about custom filetypes at all :/
But your code for handling file_type->icon == NULL will not output a theme-based icon, and will be different that the one shown in the documents sidebar (when build against GLib >= 2.18). To be the same, you need to use ui_get_filetype_icon("text/plain", ...).
Regards, Colomban
On Tue, 26 Oct 2010 20:24:29 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
This patch adds a new mime_type field to GeanyFiletype and sets it for every built-in filetype. Built-in filetypes for which I didn't find the MIME type defaults to text/plain, but it would perhaps be better to set it to NULL to explicitly say that it isn't the right one.
I've removed text/plain defaults now. I think it will help when testing.
OK. Are you sure about removing it also for GEANY_FILETYPES_NONE?
I just changed the mime_type field to be "text/plain" if it wasn't initialized.
Custom filetypes were NULL too, so I fixed the menu item icon code to handle NULL.
Oups, forgot about custom filetypes at all :/
But your code for handling file_type->icon == NULL will not output a theme-based icon, and will be different that the one shown in the documents sidebar (when build against GLib >= 2.18). To be the same, you need to use ui_get_filetype_icon("text/plain", ...).
OK, should be fixed now.
Nick