~and471/slickpanel/trunk

« back to all changes in this revision

Viewing changes to panel/items/windowlist/windowmenu.vala

  • Committer: Andrew Higginson
  • Date: 2014-12-29 17:48:31 UTC
  • Revision ID: at.higginson@gmail.com-20141229174831-bukedaw8kny4aq8t
updating

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
namespace SlickPanel {
 
2
 
 
3
public class WindowMenu : Gtk.Menu {
 
4
 
 
5
    private QuickLists.QuickList? quicklist;
 
6
    private Wnck.Window window;
 
7
    
 
8
    private Gtk.MenuItem menuitem_maximize;
 
9
    private Gtk.MenuItem menuitem_minimize;
 
10
 
 
11
    public WindowMenu(Wnck.Window window, QuickLists.QuickList? quicklist) {
 
12
        this.quicklist = quicklist;
 
13
        this.window = window;
 
14
        this.create_quicklist_action_items();
 
15
        this.create_window_action_items();
 
16
        this.create_end_items();
 
17
        this.show_all();
 
18
        this.window.state_changed.connect(this.on_window_state_changed);
 
19
    }
 
20
    
 
21
    private void create_quicklist_action_items() {
 
22
        if (quicklist == null) {
 
23
            return;
 
24
        }
 
25
        foreach (QuickLists.Action action in quicklist.get_actions()) {
 
26
            var name = action.name; // Needs to be declared to avoid weird valac bug
 
27
            var menuitem = new Gtk.MenuItem.with_label(name);
 
28
            menuitem.activate.connect(this.on_quicklist_action_menuitem_activate);
 
29
            this.add(menuitem);
 
30
        }
 
31
        if (quicklist.get_actions().length > 0) {
 
32
            this.add_separator();
 
33
        }
 
34
        this.on_window_state_changed(window.get_state(), window.get_state());
 
35
    }
 
36
    
 
37
    private void create_window_action_items() {
 
38
        for (int i = 0; i < WindowAction.N_ACTIONS; i++) {
 
39
            var action = (WindowAction) i;
 
40
            var menuitem = new Gtk.MenuItem.with_label(action.get_name());
 
41
            menuitem.activate.connect(() => {
 
42
                this.on_window_action_menuitem_activate(action);
 
43
            });
 
44
            this.add(menuitem);
 
45
            switch(action) {
 
46
                case WindowAction.MAXIMIZE:
 
47
                    this.menuitem_maximize = menuitem;
 
48
                    break;
 
49
                case WindowAction.MINIMIZE:
 
50
                    this.menuitem_minimize = menuitem;
 
51
                    break;
 
52
                default:
 
53
                    break;
 
54
            }
 
55
        }
 
56
        this.add_separator();
 
57
    }
 
58
    
 
59
    private void create_end_items() {
 
60
        var menuitem_close = new Gtk.MenuItem.with_label(_("Close"));
 
61
        menuitem_close.activate.connect(this.on_menuitem_close_activate);
 
62
        this.add(menuitem_close);
 
63
    }
 
64
    
 
65
    private void add_separator() {
 
66
        var menuitem_separator = new Gtk.SeparatorMenuItem();
 
67
        this.add(menuitem_separator);
 
68
    }
 
69
    
 
70
    private void on_quicklist_action_menuitem_activate(Gtk.MenuItem menuitem) {
 
71
        var action = this.quicklist.get_action_from_name(menuitem.get_label());
 
72
        Process.spawn_async(null, action.exec.split(" "), null, SpawnFlags.SEARCH_PATH, null, null);
 
73
    }
 
74
    
 
75
    private void on_window_action_menuitem_activate(WindowAction action) {
 
76
        action.do_(this.window);
 
77
    }
 
78
    
 
79
    private void on_menuitem_close_activate() {
 
80
        this.window.close(Gtk.get_current_event_time());
 
81
    }
 
82
    
 
83
    private void on_window_state_changed(Wnck.WindowState changed_mask, Wnck.WindowState new_state) {
 
84
        bool maximized = (Wnck.WindowState.MAXIMIZED_VERTICALLY in new_state);
 
85
        bool minimized = (Wnck.WindowState.MINIMIZED in new_state);
 
86
        
 
87
        this.menuitem_maximize.set_label(WindowAction.MAXIMIZE.get_name(maximized));
 
88
        this.menuitem_minimize.set_label(WindowAction.MINIMIZE.get_name(minimized));
 
89
    }
 
90
}
 
91
}
 
92