2
Copyright (C) 2012-2013 Andrea Basso <andrea@elementaryos.org>
4
This program or library is free software; you can redistribute it
5
and/or modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 3 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General
15
Public License along with this library; if not, write to the
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301 USA.
21
* This class provides a simple menu for managing Contractor.
22
* It uses a long-obsolete and unused revision of Contractor API and will not
23
* work with stable releases of Contractor.
25
[Deprecated (since = "0.2")]
26
public class Granite.Widgets.ContractorMenu : Gtk.Menu {
28
* The Hashtable of available contracts
30
HashTable<string,string>[] contracts;
32
* The Hashtable of executables
34
Gee.HashMap <string,string> execs;
35
public delegate void ContractCallback ();
36
private string filepath;
37
private string filemime;
40
* Passes when contract is clicked
42
public signal void contract_activated (string contract_name);
45
* Makes new Contractor Meu
47
* @param filename the filename of the file
48
* @param mime the mime-type of the file
50
public ContractorMenu (string filename, string mime) {
53
load_items (filename, mime);
57
* Adds new item to Contractor Menu
59
* @param name name of menu item
60
* @param icon_name the desired icon for menu item
61
* @param position desired position of menu item
62
* @param method method to be called when menu item is clicked
63
* @param use_stock tells whether to use stock for menu item
65
public void add_item (string name, string icon_name, int position, ContractCallback method, bool use_stock = true) {
66
var item = new Gtk.ImageMenuItem ();
67
item.set_always_show_image (true);
68
item.set_use_stock (use_stock);
69
var image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.MENU);
70
item.set_label (name);
71
item.set_image (image);
72
item.activate.connect (()=> {
73
contract_activated (name);
76
insert(item, position);
81
* Deletes a group of menu items
83
* @param names of menu items to delete
85
public void name_blacklist (string[] names) {
86
this.foreach ((item)=> {
87
if (((Gtk.MenuItem)item).get_label () in names)
92
private void load_items (string filename, string mime) {
93
contracts = Granite.Services.Contractor.get_contract (filename, mime);
94
execs = new Gee.HashMap<string,string> ();
96
for (int i=0;i<contracts.length;i++) {
97
execs[contracts[i].lookup ("Name")] = contracts[i].lookup ("Exec");
99
var item = new Gtk.ImageMenuItem ();
100
item.set_always_show_image (true);
101
var image = new Gtk.Image.from_icon_name (contracts[i].lookup ("IconName"), Gtk.IconSize.MENU);
102
item.set_label (contracts[i].lookup ("Name"));
103
item.set_image (image);
104
item.activate.connect ( ()=> {
106
Process.spawn_command_line_async (execs.get(item.get_label ()));
117
* Updates Contractor menu items
119
* @param filename the filename of the file
120
* @param mime the mime-type of the file
122
public void update (string? filename, string? mime) {
123
this.foreach ((w) => {remove (w);});
128
if (filename != null) {