← Back to team overview

elementaryart team mailing list archive

[Merge] lp:~voluntatefaber/granite/contract-menu-with-icons into lp:granite

 

Andrea Basso has proposed merging lp:~voluntatefaber/granite/contract-menu-with-icons into lp:granite.

Requested reviews:
  elementary Pantheon team (elementary-pantheon)

For more details, see:
https://code.launchpad.net/~voluntatefaber/granite/contract-menu-with-icons/+merge/93729
-- 
https://code.launchpad.net/~voluntatefaber/granite/contract-menu-with-icons/+merge/93729
Your team elementaryart (old) is subscribed to branch lp:granite.
=== modified file 'lib/CMakeLists.txt'
--- lib/CMakeLists.txt	2012-02-06 21:19:07 +0000
+++ lib/CMakeLists.txt	2012-02-19 14:01:17 +0000
@@ -68,6 +68,7 @@
     Widgets/ToolButtonWithMenu.vala
     Widgets/PopOver.vala
     Widgets/ContractorView.vala
+    Widgets/ContractorMenu.vala
     Main.vala
     config.vapi
 CUSTOM_VAPIS

=== added file 'lib/Widgets/ContractorMenu.vala'
--- lib/Widgets/ContractorMenu.vala	1970-01-01 00:00:00 +0000
+++ lib/Widgets/ContractorMenu.vala	2012-02-19 14:01:17 +0000
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2012 Andrea Basso
+ *
+ * This is a 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 of the
+ * License, or (at your option) any later version.
+ *
+ * This 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 program; see the file COPYING.  If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+
+public class Granite.Widgets.ContractorMenu : Gtk.Menu {
+    HashTable<string,string>[] contracts;
+    Gee.HashMap <string,string> execs;
+    public delegate void ContractCallback ();
+    
+    public ContractorMenu (string filename, string mime) {
+        contracts = Granite.Services.Contractor.get_contract (filename, mime);
+        execs = new Gee.HashMap<string,string> ();
+        
+        for (int i=0;i<contracts.length;i++) {
+            execs[contracts[i].lookup ("Name")] = contracts[i].lookup ("Exec");
+            
+            var item = new Gtk.ImageMenuItem ();
+            item.set_always_show_image (true);
+            var image = new Gtk.Image.from_icon_name (contracts[i].lookup ("IconName"), Gtk.IconSize.MENU);
+            item.set_label (contracts[i].lookup ("Name"));
+            item.set_image (image);
+            item.activate.connect ( ()=> {
+                try {
+ 	                Process.spawn_command_line_async (execs.get(item.get_label ()));
+ 	            } catch (Error e) {
+ 	                error (e.message);
+ 	            }
+            });
+            append (item);
+        }
+    }
+    
+    public void add_item (string name, string icon_name, int position, ContractCallback method) {
+        var item = new Gtk.ImageMenuItem ();
+        item.set_always_show_image (true);
+        var image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.MENU);
+        item.set_label (name);
+        item.set_image (image);
+        item.activate.connect (()=>{method();});
+        insert(item, position);
+    }
+    
+    public void name_blacklist (string[] names) {
+        this.foreach ((item)=> {
+            if (((Gtk.MenuItem)item).get_label () in names)
+                remove (item);
+        });
+    }
+}


Follow ups