diff options
author | Christian Dywan <christian@twotoasts.de> | 2018-07-30 23:36:21 +0200 |
---|---|---|
committer | Christian Dywan <christian@twotoasts.de> | 2018-07-30 23:36:21 +0200 |
commit | 22ed9990ff911440f7a4bb247c930075003e951d (patch) | |
tree | 27c203ed857c47145ddcb74d0897b69c05f284f5 | |
parent | 22b6b89e7d03e479b6e81a7c5557e38c0a1d3107 (diff) | |
download | midori-git-22ed9990ff911440f7a4bb247c930075003e951d.tar.gz |
Implement a context menu for tab labelstally-menu
-rw-r--r-- | core/tally.vala | 32 | ||||
-rw-r--r-- | ui/menus.ui | 14 |
2 files changed, 44 insertions, 2 deletions
diff --git a/core/tally.vala b/core/tally.vala index 2897c40c..a3cd4683 100644 --- a/core/tally.vala +++ b/core/tally.vala @@ -33,6 +33,8 @@ namespace Midori { } } } + SimpleActionGroup? group = null; + [GtkChild] Gtk.Label caption; [GtkChild] @@ -72,14 +74,40 @@ namespace Midori { leave_notify_event.connect ((event) => { unset_state_flags (Gtk.StateFlags.PRELIGHT); }); + + group = new SimpleActionGroup (); + var action = new SimpleAction ("pin", null); + action.activate.connect (() => { + tab.pinned = true; + }); + group.add_action (action); + action = new SimpleAction ("unpin", null); + action.activate.connect (() => { + tab.pinned = false; + }); + group.add_action (action); + insert_action_group ("tally", group); + } + + protected override bool button_press_event (Gdk.EventButton event) { + switch (event.button) { + case Gdk.BUTTON_SECONDARY: + ((SimpleAction)group.lookup_action ("pin")).set_enabled (!tab.pinned); + ((SimpleAction)group.lookup_action ("unpin")).set_enabled (tab.pinned); + var app = (App)Application.get_default (); + var menu = new Gtk.Popover.from_model (this, app.get_menu_by_id ("tally-menu")); + menu.show (); + break; + } + return true; } protected override bool button_release_event (Gdk.EventButton event) { switch (event.button) { - case 1: + case Gdk.BUTTON_PRIMARY: clicked (); break; - case 3: + case Gdk.BUTTON_MIDDLE: tab.try_close (); break; } diff --git a/ui/menus.ui b/ui/menus.ui index a8937a57..0f648ea0 100644 --- a/ui/menus.ui +++ b/ui/menus.ui @@ -53,4 +53,18 @@ </item> </section> </menu> + <menu id="tally-menu"> + <section> + <item> + <attribute name="action">tally.pin</attribute> + <attribute name="hidden-when">action-disabled</attribute> + <attribute name="label" translatable="yes">_Pin Tab</attribute> + </item> + <item> + <attribute name="action">tally.unpin</attribute> + <attribute name="hidden-when">action-disabled</attribute> + <attribute name="label" translatable="yes">Unpin Ta_b</attribute> + </item> + </section> + </menu> </interface> |