Re: [Geany-devel] File type icons?

2010-10-27 Thread Nick Treleaven
On Tue, 26 Oct 2010 20:24:29 +0200
Colomban Wendling lists@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
___
Geany-devel mailing list
Geany-devel@uvena.de
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel


Re: [Geany-devel] File type icons?

2010-10-26 Thread Nick Treleaven
On Fri, 22 Oct 2010 02:34:23 +0200
Colomban Wendling lists@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
___
Geany-devel mailing list
Geany-devel@uvena.de
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel


Re: [Geany-devel] File type icons?

2010-10-26 Thread Nick Treleaven
On Fri, 22 Oct 2010 02:30:27 +0200
Colomban Wendling lists@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
___
Geany-devel mailing list
Geany-devel@uvena.de
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel


Re: [Geany-devel] File type icons?

2010-10-21 Thread Nick Treleaven
On Sat, 16 Oct 2010 17:59:28 +0200
Colomban Wendling lists@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
___
Geany-devel mailing list
Geany-devel@uvena.de
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel


Re: [Geany-devel] File type icons?

2010-10-21 Thread Colomban Wendling
Le 21/10/2010 17:19, Nick Treleaven a écrit :
 On Sat, 16 Oct 2010 17:59:28 +0200
 Colomban Wendling lists@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
___
Geany-devel mailing list
Geany-devel@uvena.de
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel


Re: [Geany-devel] File type icons?

2010-10-21 Thread Colomban Wendling
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@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
From 1ec32aeb5fda9a827ffa271417390909bfe3ad4e Mon Sep 17 00:00:00 2001
From: Colomban Wendling b...@herbesfolles.org
Date: Wed, 13 Oct 2010 22:39:54 +0200
Subject: [PATCH 1/4] Add MIME type to GeanyFiletype

MIME-type is a generic way to describe content-type, and is wide-spread.
It then can be useful to communicate with API that needs to know the
content type of the file.

Some examples of possible usage:
 * MIME-type based file chooser filter;
 * Filetype icons through GIO GContentType and GIcon;
 * ...

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.
---
 src/filetypes.c |   52 
 src/filetypes.h |1 +
 2 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/src/filetypes.c b/src/filetypes.c
index 3661ca2..92e9045 100644
--- a/src/filetypes.c
+++ b/src/filetypes.c
@@ -95,6 +95,7 @@ static void init_builtin_filetypes(void)
 	ft = filetypes[GEANY_FILETYPES_NONE];
 	ft-name = g_strdup(_(None));
 	ft-title = g_strdup(_(None));
+	ft-mime_type = g_strdup(text/plain);
 	ft-group = GEANY_FILETYPE_GROUP_NONE;
 
 #define C
@@ -102,6 +103,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 0;
 	ft-name = g_strdup(C);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-csrc);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define CPP
@@ -109,6 +111,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 1;
 	ft-name = g_strdup(C++);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-c++src);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define CS
@@ -116,6 +119,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 25;
 	ft-name = g_strdup(C#);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-csharp);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define VALA
@@ -123,6 +127,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 33;
 	ft-name = g_strdup(Vala);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-vala);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define D
@@ -130,6 +135,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 17;
 	ft-name = g_strdup(D);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-dsrc);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define JAVA
@@ -137,6 +143,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 2;
 	ft-name = g_strdup(Java);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-java);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define PAS /* to avoid warnings when building under Windows, the symbol PASCAL is there defined */
@@ -144,6 +151,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 

Re: [Geany-devel] File type icons?

2010-10-21 Thread Colomban Wendling
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@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
diff --git a/src/filetypes.c b/src/filetypes.c
index 3661ca2..192c7ed 100644
--- a/src/filetypes.c
+++ b/src/filetypes.c
@@ -95,6 +95,7 @@ static void init_builtin_filetypes(void)
 	ft = filetypes[GEANY_FILETYPES_NONE];
 	ft-name = g_strdup(_(None));
 	ft-title = g_strdup(_(None));
+	ft-mime_type = g_strdup(text/plain);
 	ft-group = GEANY_FILETYPE_GROUP_NONE;
 
 #define C
@@ -102,6 +103,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 0;
 	ft-name = g_strdup(C);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-csrc);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define CPP
@@ -109,6 +111,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 1;
 	ft-name = g_strdup(C++);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-c++src);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define CS
@@ -116,6 +119,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 25;
 	ft-name = g_strdup(C#);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-csharp);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define VALA
@@ -123,6 +127,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 33;
 	ft-name = g_strdup(Vala);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-vala);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define D
@@ -130,6 +135,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 17;
 	ft-name = g_strdup(D);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-dsrc);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define JAVA
@@ -137,6 +143,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 2;
 	ft-name = g_strdup(Java);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-java);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define PAS /* to avoid warnings when building under Windows, the symbol PASCAL is there defined */
@@ -144,6 +151,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 4;
 	ft-name = g_strdup(Pascal);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/x-pascal);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define ASM
@@ -151,6 +159,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 9;
 	ft-name = g_strdup(ASM);
 	ft-title = g_strdup_printf(_(%s source file), Assembler);
+	ft-mime_type = g_strdup(text/plain); /* FIXME */
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define BASIC
@@ -158,6 +167,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 26;
 	ft-name = g_strdup(FreeBasic);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/plain); /* FIXME */
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define FORTRAN
@@ -165,6 +175,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 18;
 	ft-name = g_strdup(Fortran);
 	ft-title = g_strdup_printf(_(%s source file), Fortran (F90));
+	ft-mime_type = g_strdup(text/x-fortran);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define F77
@@ -172,6 +183,7 @@ static void init_builtin_filetypes(void)
 	ft-lang = 30;
 	ft-name = g_strdup(F77);
 	ft-title = g_strdup_printf(_(%s source file), Fortran (F77));
+	ft-mime_type = g_strdup(text/x-fortran);
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define GLSL
@@ -179,12 +191,14 @@ static void init_builtin_filetypes(void)
 	ft-lang = 31;
 	ft-name = g_strdup(GLSL);
 	filetype_make_title(ft, TITLE_SOURCE_FILE);
+	ft-mime_type = g_strdup(text/plain); /* FIXME */
 	ft-group = GEANY_FILETYPE_GROUP_COMPILED;
 
 #define CAML
 	ft = filetypes[GEANY_FILETYPES_CAML];
 	ft-name = g_strdup(CAML);
 	ft-title = g_strdup_printf(_(%s source file), 

Re: [Geany-devel] File type icons?

2010-10-14 Thread Dominic Hopf
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:
 
 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.
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

-- 
Dominic Hopf dma...@googlemail.com
http://dominichopf.de/

Key Fingerprint: A7DF C4FC 07AE 4DDC 5CA0 BD93 AAB0 6019 CA7D 868D


signature.asc
Description: This is a digitally signed message part
___
Geany-devel mailing list
Geany-devel@uvena.de
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel


Re: [Geany-devel] File type icons?

2010-10-14 Thread Colomban Wendling
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:

 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.
 4) 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
From 9297355ff0b589d37f2683e90bf7dcea602673a7 Mon Sep 17 00:00:00 2001
From: Colomban Wendling b...@herbesfolles.org
Date: Thu, 14 Oct 2010 16:32:10 +0200
Subject: [PATCH] Add filetype icon

Filetypes now have an icon based on their MIME type, available as
filetype-icon.

If built against GLib  2.18, the icon is currently always
GTK_STOCK_FILE.
---
 src/filetypes.c |6 ++
 src/filetypes.h |1 +
 src/ui_utils.c  |   54 ++
 src/ui_utils.h  |2 ++
 4 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/src/filetypes.c b/src/filetypes.c
index 405338e..5a3fefd 100644
--- a/src/filetypes.c
+++ b/src/filetypes.c
@@ -710,6 +710,7 @@ static GeanyFiletype *filetype_new(void)
 
 	ft-lang = -2;	/* assume no tagmanager parser */
 	ft-project_list_entry = -1; /* no entry */
+	ft-icon = NULL;
 
 	ft-priv = g_new0(GeanyFiletypePrivate, 1);
 	return ft;
@@ -741,6 +742,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);
 }
 
 
@@ -1228,6 +1232,8 @@ static void filetype_free(gpointer data, G_GNUC_UNUSED gpointer user_data)
 	g_free(ft-ftdefcmds);
 	g_free(ft-execcmds);
 	set_error_regex(ft, NULL);
+	if (ft-icon)
+		g_object_unref(ft-icon);
 
 	g_strfreev(ft-pattern);
 	g_free(ft-priv);
diff --git a/src/filetypes.h b/src/filetypes.h
index 50f4c74..e0e767a 100644
--- a/src/filetypes.h
+++ b/src/filetypes.h
@@ -129,6 +129,7 @@ struct GeanyFiletype
 	gchar			 *error_regex_string;
 	GeanyFiletype	 *lexer_filetype;
 	gchar			 *mime_type;
+	GdkPixbuf		 *icon;
 
 	struct GeanyFiletypePrivate	*priv;	/* must be last, append fields before this item */
 #ifdef GEANY_PRIVATE
diff --git a/src/ui_utils.c b/src/ui_utils.c
index a728052..68946df 100644
--- a/src/ui_utils.c
+++ b/src/ui_utils.c
@@ -2453,3 +2453,57 @@ void ui_editable_insert_text_callback(GtkEditable *editable, gchar *new_text,
 		g_signal_stop_emission_by_name(editable, insert-text);
 }
 
+
+/* gets the icon that applies to a particular MIME type */
+GdkPixbuf *ui_get_mime_icon(const gchar *mime_type, GtkIconSize size)
+{
+	GdkPixbuf *icon = NULL;
+#if defined(HAVE_GIO)  GLIB_CHECK_VERSION(2, 18, 0)
+	gchar *ctype;
+	GIcon *gicon;
+	GtkIconInfo *info;
+	GtkIconTheme *theme;
+	gint real_size = 16;
+
+	switch (size)
+	{
+		default:
+		case GTK_ICON_SIZE_SMALL_TOOLBAR:
+		case GTK_ICON_SIZE_MENU:			real_size = 16; break;
+		case GTK_ICON_SIZE_LARGE_TOOLBAR:
+		case GTK_ICON_SIZE_BUTTON:			real_size = 24; break;
+		case GTK_ICON_SIZE_DND:
+		case GTK_ICON_SIZE_DIALOG:			real_size = 48; break;
+	}
+
+	theme = gtk_icon_theme_get_default();
+	ctype = g_content_type_from_mime_type(mime_type);
+	gicon = g_content_type_get_icon(ctype);
+	info = gtk_icon_theme_lookup_by_gicon(theme, gicon, real_size, 0);
+	g_object_unref(gicon);
+	g_free(ctype);
+
+	if (info)
+	{
+		icon = gtk_icon_info_load_icon(info, NULL);
+		gtk_icon_info_free(info);
+	}
+#else
+	const 

Re: [Geany-devel] File type icons?

2010-10-14 Thread Colomban Wendling
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:
 
 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)
 
 [...]
 
 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
From cf8547073d85a5bc6ea45a9fecf8497b41771c4c Mon Sep 17 00:00:00 2001
From: Colomban Wendling b...@herbesfolles.org
Date: Fri, 15 Oct 2010 01:03:19 +0200
Subject: [PATCH] Add filetype-specific icon to the document list sidebar

---
 src/document.c |3 +++
 src/sidebar.c  |   20 +++-
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/document.c b/src/document.c
index 15c64b3..1afe54e 100644
--- a/src/document.c
+++ b/src/document.c
@@ -2507,7 +2507,10 @@ void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type)
 	document_load_config(doc, type, ft_changed);
 
 	if (ft_changed)
+	{
+		sidebar_openfiles_update(doc); /* to update the icon */
 		g_signal_emit_by_name(geany_object, document-filetype-set, doc, old_ft);
+	}
 }
 
 
diff --git a/src/sidebar.c b/src/sidebar.c
index d0063fb..893a2bf 100644
--- a/src/sidebar.c
+++ b/src/sidebar.c
@@ -272,7 +272,7 @@ static void prepare_openfiles(void)
 
 	/* store the icon and the short filename to show, and the index as reference,
 	 * the colour (black/red/green) and the full name for the tooltip */
-	store_openfiles = gtk_tree_store_new(5, G_TYPE_STRING, G_TYPE_STRING,
+	store_openfiles = gtk_tree_store_new(5, GDK_TYPE_PIXBUF, G_TYPE_STRING,
 		G_TYPE_POINTER, GDK_TYPE_COLOR, G_TYPE_STRING);
 	gtk_tree_view_set_model(GTK_TREE_VIEW(tv.tree_openfiles), GTK_TREE_MODEL(store_openfiles));
 
@@ -287,7 +287,7 @@ static void prepare_openfiles(void)
 	g_object_set(text_renderer, ellipsize, PANGO_ELLIPSIZE_MIDDLE, NULL);
 	column = gtk_tree_view_column_new();
 	gtk_tree_view_column_pack_start(column, icon_renderer, FALSE);
-	gtk_tree_view_column_set_attributes(column, icon_renderer, stock-id, DOCUMENTS_ICON, NULL);
+	gtk_tree_view_column_set_attributes(column, icon_renderer, pixbuf, DOCUMENTS_ICON, NULL);
 	gtk_tree_view_column_pack_start(column, text_renderer, TRUE);
 	gtk_tree_view_column_set_attributes(column, text_renderer, text, DOCUMENTS_SHORTNAME,
 		foreground-gdk, DOCUMENTS_COLOR, NULL);
@@ -399,6 +399,7 @@ static GtkTreeIter *get_doc_parent(GeanyDocument *doc)
 	gchar *dirname = NULL;
 	static GtkTreeIter parent;
 	GtkTreeModel *model = GTK_TREE_MODEL(store_openfiles);
+	static GdkPixbuf *dir_icon = NULL;
 
 	if (!documents_show_paths)
 		return NULL;
@@ -420,8 +421,10 @@ static GtkTreeIter *get_doc_parent(GeanyDocument *doc)
 		while (gtk_tree_model_iter_next(model, parent));
 	}
 	/* no match, add dir parent */
+	if (G_UNLIKELY(!dir_icon))
+		dir_icon = ui_get_mime_icon(inode/directory, GTK_ICON_SIZE_MENU);
 	gtk_tree_store_append(store_openfiles, parent, NULL);
-	gtk_tree_store_set(store_openfiles, parent, DOCUMENTS_ICON, GTK_STOCK_DIRECTORY,
+	gtk_tree_store_set(store_openfiles, parent, DOCUMENTS_ICON, dir_icon,
 		DOCUMENTS_FILENAME, path,
 		DOCUMENTS_SHORTNAME, doc-file_name ? dirname : GEANY_STRING_UNTITLED, -1);
 
@@ -439,6 +442,7 @@ void sidebar_openfiles_add(GeanyDocument *doc)
 	GtkTreeIter *parent = get_doc_parent(doc);
 	gchar *basename;
 	const GdkColor *color = document_get_status_color(doc);
+	static GdkPixbuf *file_icon = NULL;
 
 	gtk_tree_store_append(store_openfiles, iter, parent);
 
@@ -452,8 +456,11 @@ void sidebar_openfiles_add(GeanyDocument *doc)
 		gtk_tree_view_expand_row(GTK_TREE_VIEW(tv.tree_openfiles), path, TRUE);
 		gtk_tree_path_free(path);
 	}
+	if (G_UNLIKELY(!file_icon  (!doc-file_type || !doc-file_type-icon)))
+		file_icon = ui_get_mime_icon(text/plain, GTK_ICON_SIZE_MENU);
 	basename = g_path_get_basename(DOC_FILENAME(doc));
-	gtk_tree_store_set(store_openfiles, iter, DOCUMENTS_ICON, GTK_STOCK_FILE,
+	gtk_tree_store_set(store_openfiles, iter,
+		DOCUMENTS_ICON, (doc-file_type  doc-file_type-icon) ? doc-file_type-icon : file_icon,
 		DOCUMENTS_SHORTNAME, basename,