[alacarte/vala+garcon] initial work on element editor



commit f12d7f60223255e0a995c55dc33285429bf5b254
Author: Travis Watkins <amaranth ubuntu com>
Date:   Sun May 17 23:36:41 2009 -0500

    initial work on element editor
    
    Added the UI and class for the element editor. It currently
    displays all of the information from an element and morphs
    based on if it is showing an item, a menu, or creating a new item
    or menu. It does not, however, actually save any changes you make.
---
 .gitignore             |    4 +
 data/alacarte.ui       |  270 +++++++++++++++++++++++++++++++++++++++++++++++-
 src/Makefile.am        |    2 +
 src/elementeditor.vala |  150 +++++++++++++++++++++++++++
 src/mainwindow.vala    |   81 ++++-----------
 src/util.vala          |   82 +++++++++++++++
 6 files changed, 526 insertions(+), 63 deletions(-)

diff --git a/.gitignore b/.gitignore
index 5597ac4..5582a58 100644
--- a/.gitignore
+++ b/.gitignore
@@ -117,8 +117,12 @@ src/alacarte.vala.stamp
 src/config.c
 src/config.o
 src/config.vala
+src/elementeditor.c
+src/elementeditor.o
 src/mainwindow.c
 src/mainwindow.o
+src/util.c
+src/util.o
 stamp-h1
 ChangeLog
 m4/intltool.m4
diff --git a/data/alacarte.ui b/data/alacarte.ui
index dc9d562..3da2c1b 100644
--- a/data/alacarte.ui
+++ b/data/alacarte.ui
@@ -46,6 +46,20 @@
       <column type="gpointer"/>
     </columns>
   </object>
+  <object class="GtkListStore" id="item_type_store">
+    <columns>
+      <!-- column-name gchararray1 -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Application</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Application in Terminal</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkListStore" id="item_tree_store">
     <columns>
       <!-- column-name item_show -->
@@ -232,7 +246,6 @@
                                                   <object class="GtkImage" id="image21">
                                                     <property name="visible">True</property>
                                                     <property name="stock">gtk-new</property>
-                                                    <property name="icon-size">4</property>
                                                   </object>
                                                   <packing>
                                                     <property name="expand">False</property>
@@ -283,7 +296,6 @@
                                                   <object class="GtkImage" id="image22">
                                                     <property name="visible">True</property>
                                                     <property name="stock">gtk-add</property>
-                                                    <property name="icon-size">4</property>
                                                   </object>
                                                   <packing>
                                                     <property name="expand">False</property>
@@ -365,7 +377,6 @@
                                                       <object class="GtkImage" id="image23">
                                                         <property name="visible">True</property>
                                                         <property name="stock">gtk-go-up</property>
-                                                        <property name="icon-size">4</property>
                                                       </object>
                                                       <packing>
                                                         <property name="expand">False</property>
@@ -416,7 +427,6 @@
                                                       <object class="GtkImage" id="image24">
                                                         <property name="visible">True</property>
                                                         <property name="stock">gtk-go-down</property>
-                                                        <property name="icon-size">4</property>
                                                       </object>
                                                       <packing>
                                                         <property name="expand">False</property>
@@ -612,4 +622,256 @@
       <action-widget response="0">confirm_revert_button</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkDialog" id="element_dialog">
+    <property name="border_width">5</property>
+    <property name="type_hint">dialog</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox3">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkAlignment" id="alignment1">
+            <property name="visible">True</property>
+            <property name="top_padding">5</property>
+            <property name="bottom_padding">5</property>
+            <property name="left_padding">5</property>
+            <property name="right_padding">5</property>
+            <child>
+              <object class="GtkHBox" id="hbox1">
+                <property name="visible">True</property>
+                <property name="spacing">10</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment2">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0</property>
+                    <property name="xscale">0</property>
+                    <property name="yscale">0</property>
+                    <child>
+                      <object class="GtkButton" id="icon_button">
+                        <property name="width_request">64</property>
+                        <property name="height_request">64</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkTable" id="element_table">
+                    <property name="visible">True</property>
+                    <property name="n_rows">4</property>
+                    <property name="n_columns">2</property>
+                    <property name="column_spacing">10</property>
+                    <property name="row_spacing">5</property>
+                    <child>
+                      <object class="GtkLabel" id="label2">
+                        <property name="visible">True</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">_Name:</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">element_name_entry</property>
+                        <attributes>
+                          <attribute name="weight" value="bold"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="item_command_label">
+                        <property name="visible">True</property>
+                        <property name="xalign">1</property>
+                        <property name="ypad">1</property>
+                        <property name="label" translatable="yes">Comm_and:</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">item_command_entry</property>
+                        <attributes>
+                          <attribute name="weight" value="bold"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label4">
+                        <property name="visible">True</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">Co_mment:</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">element_comment_entry</property>
+                        <attributes>
+                          <attribute name="weight" value="bold"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkComboBox" id="item_type_combo">
+                        <property name="visible">True</property>
+                        <property name="model">item_type_store</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkEntry" id="element_name_entry">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="invisible_char">&#x25CF;</property>
+                        <property name="activates_default">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkHBox" id="hbox2">
+                        <property name="visible">True</property>
+                        <property name="spacing">10</property>
+                        <child>
+                          <object class="GtkEntry" id="item_command_entry">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="invisible_char">&#x25CF;</property>
+                            <property name="activates_default">True</property>
+                          </object>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkButton" id="item_command_button">
+                            <property name="label" translatable="yes">Browse...</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkEntry" id="element_comment_entry">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="invisible_char">&#x25CF;</property>
+                        <property name="activates_default">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="item_type_label">
+                        <property name="visible">True</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">_Type:</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">item_type_combo</property>
+                        <attributes>
+                          <attribute name="weight" value="bold"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area3">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="cancel_button">
+                <property name="label" translatable="yes">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="ok_button">
+                <property name="label" translatable="yes">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="is_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-1">cancel_button</action-widget>
+      <action-widget response="0">ok_button</action-widget>
+    </action-widgets>
+  </object>
 </interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index fcaa6c1..cf9c479 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,6 +14,8 @@ BUILT_SOURCES = alacarte.vala.stamp
 
 alacarte_VALASOURCES = \
 	mainwindow.vala \
+	elementeditor.vala \
+	util.vala \
 	config.vala \
 	$(NULL)
 
diff --git a/src/elementeditor.vala b/src/elementeditor.vala
new file mode 100644
index 0000000..87f2072
--- /dev/null
+++ b/src/elementeditor.vala
@@ -0,0 +1,150 @@
+/* elementeditor.vala
+ *
+ * Copyright (C) 2009 Travis Watkins
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:
+ *      Travis Watkins <amaranth ubuntu com>
+ */
+
+using GLib;
+using Gtk;
+using Garcon;
+using Config;
+
+public class ElementEditor
+{
+	private Builder builder;
+	private Garcon.MenuElement element;
+	private Garcon.Menu parent;
+	private string new_type;
+
+
+	public ElementEditor (Garcon.MenuElement element)
+	{
+		this.element = element;
+	}
+
+	public ElementEditor.new_item (Garcon.Menu parent, string new_type)
+	{
+		this.parent = parent;
+		this.new_type = new_type;
+	}
+
+	private void setup_dialog ()
+	{
+		var dialog = builder.get_object ("element_dialog") as Gtk.Dialog;
+
+		if (element != null)
+		{
+			var cancel_button = builder.get_object ("cancel_button") as Gtk.Button;
+			cancel_button.set_label (Gtk.STOCK_REVERT_TO_SAVED);
+			var ok_button = builder.get_object ("ok_button") as Gtk.Button;
+			ok_button.set_label (Gtk.STOCK_CLOSE);
+
+			var name_entry = builder.get_object ("element_name_entry") as Gtk.Entry;
+			name_entry.set_text (element.get_name ());
+			name_entry.select_region (0, -1);
+			var comment_entry = builder.get_object ("element_comment_entry") as Gtk.Entry;
+			comment_entry.set_text (element.get_comment ());
+
+			var icon_button = builder.get_object ("icon_button") as Gtk.Button;
+			var image = new Gtk.Image.from_pixbuf (Util.get_icon (element, 48));
+			icon_button.set_image (image);
+		}
+
+		if (element != null && element is Garcon.MenuItem)
+		{
+			dialog.set_title ("Item Properties");
+			var item = element as Garcon.MenuItem;
+			var type_combo = builder.get_object ("item_type_combo") as Gtk.ComboBox;
+			var renderer = new Gtk.CellRendererText ();
+			type_combo.pack_start (renderer, false);
+			type_combo.set_attributes (renderer, "text", 0, null);
+			if (item.requires_terminal)
+				type_combo.set_active (1);
+			else
+				type_combo.set_active (0);
+
+			var command_entry = builder.get_object ("item_command_entry") as Gtk.Entry;
+			command_entry.set_text (item.command);
+		}
+		else if ((element != null && element is Garcon.Menu) || new_type == "menu")
+		{
+			dialog.set_title ("Menu Properties");
+			var type_combo = builder.get_object ("item_type_combo") as Gtk.ComboBox;
+			var type_label = builder.get_object ("item_type_label") as Gtk.Label;
+			var command_label = builder.get_object ("item_command_label") as Gtk.Label;
+			var command_entry = builder.get_object ("item_command_entry") as Gtk.Entry;
+			var command_button = builder.get_object ("item_command_button") as Gtk.Button;
+			(type_combo.get_parent () as Gtk.Container).remove (type_combo);
+			(type_label.get_parent () as Gtk.Container).remove (type_label);
+			(command_label.get_parent () as Gtk.Container).remove (command_label);
+			(command_entry.get_parent () as Gtk.Container).remove (command_entry);
+			(command_button.get_parent () as Gtk.Container).remove (command_button);
+
+			var table = builder.get_object ("element_table") as Gtk.Table;
+			table.resize (2, 2);
+		}
+	}
+
+	[CCode (instance_pos = -1)]
+	private void connect_signals (Builder builder, GLib.Object object,
+								  string signal_name, string handler_name,
+								  GLib.Object? connect_object,
+								  ConnectFlags flags)
+	{
+		var module = Module.open (null, ModuleFlags.BIND_LAZY);
+		void* sym;
+
+		var real_handler_name = "element_editor_" + handler_name;
+
+		if (!module.symbol (real_handler_name, out sym))
+		{
+			stdout.printf ("Symbol %s not found!\n", real_handler_name);
+		}
+		else
+		{
+			Signal.connect (object, signal_name, (GLib.Callback) sym, this);
+		}
+	}
+
+	public void run ()
+	{
+		try
+		{
+			string[] objects = {
+				"element_dialog",
+				"item_type_store",
+				null
+			};
+			builder = new Builder ();
+			builder.add_objects_from_file (Config.pkgdatadir + "/alacarte.ui", objects);
+		}
+		catch (Error e)
+		{
+			var msg = new MessageDialog (null, DialogFlags.MODAL,
+										 MessageType.ERROR, ButtonsType.CLOSE,
+										 "Failed to load UI\n%s", e.message);
+			msg.run ();
+		}
+
+		builder.connect_signals_full (connect_signals);
+		setup_dialog ();
+		var dialog = builder.get_object ("element_dialog") as Gtk.Dialog;
+		dialog.show_all ();
+	}
+}
+
diff --git a/src/mainwindow.vala b/src/mainwindow.vala
index ecb816b..6215133 100644
--- a/src/mainwindow.vala
+++ b/src/mainwindow.vala
@@ -21,7 +21,6 @@
 
 using GLib;
 using Gtk;
-using Gdk;
 using Garcon;
 using Config;
 
@@ -31,59 +30,6 @@ public class MainWindow
 	private Builder builder;
 	private Garcon.Menu applications;
 
-	private Gdk.Pixbuf? get_icon (Garcon.MenuElement item)
-	{
-		var icon_theme = Gtk.IconTheme.get_default ();
-		Gdk.Pixbuf pixbuf = null;
-
-		var icon_name = item.get_icon_name ();
-		if (icon_name != null)
-		{
-			// Strip extension if it is a common icon extension
-			if (!GLib.Path.is_absolute (icon_name))
-			{
-				if (icon_name.has_suffix (".xpm") ||
-					icon_name.has_suffix (".png") ||
-					icon_name.has_suffix (".jpg") ||
-					icon_name.has_suffix (".gif"))
-				{
-					var basename = GLib.Path.get_basename (icon_name);
-					var extension = basename.rchr (-1, '.');
-
-					if (extension != null)
-						icon_name = basename.substring (0, basename.size () - extension.size ());
-				}
-			}
-
-			try
-			{
-				pixbuf = icon_theme.load_icon (icon_name, 24, Gtk.IconLookupFlags.USE_BUILTIN);
-			}
-			catch (Error e)
-			{
-				if (GLib.Path.is_absolute (icon_name) && GLib.FileUtils.test (icon_name, GLib.FileTest.EXISTS))
-					pixbuf = new Gdk.Pixbuf.from_file_at_scale (icon_name, 24, 24, true);
-			}
-		}
-
-		if (pixbuf == null)
-		{
-			if (item is Garcon.Menu)
-				icon_name = "gnome-fs-directory";
-			else if (item is Garcon.MenuItem)
-				icon_name = "application-default-icon";
-			else
-				return null;
-
-			pixbuf = icon_theme.load_icon (icon_name, 24, Gtk.IconLookupFlags.USE_BUILTIN);
-		}
-
-		if (pixbuf != null)
-			pixbuf = pixbuf.scale_simple (24, 24, Gdk.InterpType.BILINEAR);
-
-		return pixbuf;
-	}
-
 	private void update_icons (Gtk.TreeIter iter)
 	{
 		Gtk.TreeIter child_iter;
@@ -91,7 +37,7 @@ public class MainWindow
 
 		var tree_store = builder.get_object ("menu_tree_store") as Gtk.TreeStore;
 		tree_store.get (iter, 2, out menu, -1);
-		tree_store.set (iter, 0, get_icon (menu), -1);
+		tree_store.set (iter, 0, Util.get_icon (menu), -1);
 
 		if (tree_store.iter_has_child (iter))
 		{
@@ -120,7 +66,7 @@ public class MainWindow
 					name = "<small><i>" + name + "</i></small>";
 
 				tree_store.append (out iter, parent);
-				tree_store.set (iter, 0, get_icon (item), -1);
+				tree_store.set (iter, 0, Util.get_icon (item), -1);
 				tree_store.set (iter, 1, name, -1);
 				tree_store.set (iter, 2, item);
 
@@ -154,7 +100,7 @@ public class MainWindow
 				name = "<small><i>" + name + "</i></small>";
 
 			list_store.set (iter, 0, item.get_visible (), -1);
-			list_store.set (iter, 1, get_icon (item), -1);
+			list_store.set (iter, 1, Util.get_icon (item), -1);
 			list_store.set (iter, 2, name, -1);
 			list_store.set (iter, 3, item);
 		}
@@ -205,7 +151,7 @@ public class MainWindow
 		Gtk.TreeIter iter;
 		var tree_store = builder.get_object ("menu_tree_store") as Gtk.TreeStore;
 		tree_store.append (out iter, null);
-		tree_store.set (iter, 0, get_icon (applications), -1);
+		tree_store.set (iter, 0, Util.get_icon (applications), -1);
 		tree_store.set (iter, 1, GLib.Markup.escape_text (applications.get_name ()), -1);
 		tree_store.set (iter, 2, applications);
 
@@ -364,7 +310,7 @@ public class MainWindow
 
 
 	//start of item tree signal handlers
-	public bool do_popup_menu (Gtk.Widget widget, Gdk.EventButton? event)
+	private bool do_popup_menu (Gtk.Widget widget, Gdk.EventButton? event)
 	{
 		uint button;
 		uint event_time;
@@ -403,6 +349,23 @@ public class MainWindow
 	{
 		return do_popup_menu (widget, event);
 	}
+
+	[CCode (instance_pos = -1)]
+	public void on_item_tree_row_activated (Gtk.TreeView tree_view,
+											Gtk.TreePath path,
+											Gtk.TreeViewColumn column)
+	{
+		Gtk.TreeIter iter;
+		weak Gtk.TreeModel model;
+		unowned Garcon.MenuElement element;
+
+		var selection = tree_view.get_selection ();
+		selection.get_selected (out model, out iter);
+
+		model.get (iter, 3, out element, -1);
+		var item_editor = new ElementEditor (element);
+		item_editor.run ();
+	}
 }
 
 static int main (string[] args)
diff --git a/src/util.vala b/src/util.vala
new file mode 100644
index 0000000..df5852d
--- /dev/null
+++ b/src/util.vala
@@ -0,0 +1,82 @@
+/* util.vala
+ *
+ * Copyright (C) 2009 Travis Watkins
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:
+ *      Travis Watkins <amaranth ubuntu com>
+ */
+
+using GLib;
+using Gtk;
+using Gdk;
+using Garcon;
+
+namespace Util
+{
+	private Gdk.Pixbuf? get_icon (Garcon.MenuElement item, int size = 24)
+	{
+		var icon_theme = Gtk.IconTheme.get_default ();
+		Gdk.Pixbuf pixbuf = null;
+
+		var icon_name = item.get_icon_name ();
+		if (icon_name != null)
+		{
+			// Strip extension if it is a common icon extension
+			if (!GLib.Path.is_absolute (icon_name))
+			{
+				if (icon_name.has_suffix (".xpm") ||
+					icon_name.has_suffix (".png") ||
+					icon_name.has_suffix (".jpg") ||
+					icon_name.has_suffix (".gif"))
+				{
+					var basename = GLib.Path.get_basename (icon_name);
+					var extension = basename.rchr (-1, '.');
+
+					if (extension != null)
+						icon_name = basename.substring (0, basename.size () - extension.size ());
+				}
+			}
+
+			try
+			{
+				pixbuf = icon_theme.load_icon (icon_name, size, Gtk.IconLookupFlags.USE_BUILTIN);
+			}
+			catch (Error e)
+			{
+				if (GLib.Path.is_absolute (icon_name) && GLib.FileUtils.test (icon_name, GLib.FileTest.EXISTS))
+					pixbuf = new Gdk.Pixbuf.from_file_at_scale (icon_name, size, size, true);
+			}
+		}
+
+		if (pixbuf == null)
+		{
+			if (item is Garcon.Menu)
+				icon_name = "gnome-fs-directory";
+			else if (item is Garcon.MenuItem)
+				icon_name = "application-default-icon";
+			else
+				return null;
+
+			pixbuf = icon_theme.load_icon (icon_name, size, Gtk.IconLookupFlags.USE_BUILTIN);
+		}
+
+		if (pixbuf != null)
+			pixbuf = pixbuf.scale_simple (size, size, Gdk.InterpType.BILINEAR);
+
+		return pixbuf;
+	}
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]