[meld/CompChange: 2/3] Add menu entries and accelerators for directly switching to given tabs
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/CompChange: 2/3] Add menu entries and accelerators for directly switching to given tabs
- Date: Mon, 14 Mar 2011 21:18:18 +0000 (UTC)
commit d63d2e72817cd3d83f378c46c38958d96d0d7551
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Mar 5 13:02:06 2011 +1000
Add menu entries and accelerators for directly switching to given tabs
data/ui/meldapp-ui.xml | 2 +
data/ui/meldapp.ui | 4 +++
meld/meldwindow.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 56 insertions(+), 2 deletions(-)
---
diff --git a/data/ui/meldapp-ui.xml b/data/ui/meldapp-ui.xml
index 704fb7a..1c54a49 100644
--- a/data/ui/meldapp-ui.xml
+++ b/data/ui/meldapp-ui.xml
@@ -54,6 +54,8 @@
<separator/>
<menuitem action="MoveTabPrev" />
<menuitem action="MoveTabNext" />
+ <separator/>
+ <placeholder name="TabPlaceholder" />
</menu>
<menu action="HelpMenu">
<menuitem action="Help" />
diff --git a/data/ui/meldapp.ui b/data/ui/meldapp.ui
index 872ac35..49d8c7f 100644
--- a/data/ui/meldapp.ui
+++ b/data/ui/meldapp.ui
@@ -17,6 +17,10 @@
<property name="scrollable">True</property>
<property name="enable_popup">True</property>
<signal handler="on_switch_page" name="switch_page"/>
+ <signal handler="after_switch_page" name="switch_page" after="True"/>
+ <signal handler="_update_notebook_menu" name="page-added"/>
+ <signal handler="_update_notebook_menu" name="page-removed"/>
+ <signal handler="_update_notebook_menu" name="page-reordered"/>
</object>
<packing>
<property name="position">1</property>
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index d7915db..2336301 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -178,6 +178,8 @@ class MeldWindow(gnomeglade.Component):
self.ui.add_ui_from_file(ui_file)
self.ui.connect("connect-proxy", self._on_uimanager_connect_proxy)
self.ui.connect("disconnect-proxy", self._on_uimanager_disconnect_proxy)
+ self.tab_switch_actiongroup = None
+ self.tab_switch_merge_id = None
for menuitem in ("Save", "Undo"):
self.actiongroup.get_action(menuitem).props.is_important = True
@@ -318,12 +320,25 @@ class MeldWindow(gnomeglade.Component):
newdoc.on_container_switch_in_event(self.ui)
self.scheduler.add_task( newdoc.scheduler )
+ def after_switch_page(self, notebook, page, which):
+ actiongroup = self.tab_switch_actiongroup
+ if actiongroup:
+ action_name = "SwitchTab%d" % which
+ actiongroup.get_action(action_name).set_active(True)
+
def on_notebook_label_changed(self, component, text, tooltip):
- nbl = self.notebook.get_tab_label( component.widget )
+ page = component.widget
+ nbl = self.notebook.get_tab_label(page)
nbl.set_label_text(text)
nbl.set_tooltip_text(tooltip)
self.widget.set_title(text + " - Meld")
- self.notebook.child_set_property(component.widget, "menu-label", text)
+ self.notebook.child_set_property(page, "menu-label", text)
+
+ actiongroup = self.tab_switch_actiongroup
+ if actiongroup:
+ idx = self.notebook.child_get_property(page, "position")
+ action_name = "SwitchTab%d" % idx
+ actiongroup.get_action(action_name).set_label(text)
def on_can_undo(self, undosequence, can):
self.actiongroup.get_action("Undo").set_sensitive(can)
@@ -485,6 +500,39 @@ class MeldWindow(gnomeglade.Component):
child = self.notebook.get_nth_page(page_num)
self.notebook.reorder_child(child, page_num + 1)
+ def _update_notebook_menu(self, *args):
+ if self.tab_switch_merge_id:
+ self.ui.remove_ui(self.tab_switch_merge_id)
+ self.ui.remove_action_group(self.tab_switch_actiongroup)
+
+ self.tab_switch_merge_id = self.ui.new_merge_id()
+ self.tab_switch_actiongroup = gtk.ActionGroup("TabSwitchActions")
+ self.ui.insert_action_group(self.tab_switch_actiongroup)
+ group = None
+ current_page = self.notebook.get_current_page()
+ for i in range(self.notebook.get_n_pages()):
+ page = self.notebook.get_nth_page(i)
+ label = self.notebook.get_menu_label_text(page) or ""
+ name = "SwitchTab%d" % i
+ tooltip = _("Switch to this tab")
+ action = gtk.RadioAction(name, label, tooltip, None, i)
+ action.set_group(group)
+ if group is None:
+ group = action
+ action.set_active(current_page == i)
+ def current_tab_changed_cb(action, current):
+ if action == current:
+ self.notebook.set_current_page(action.get_current_value())
+ action.connect("changed", current_tab_changed_cb)
+ if i < 10:
+ accel = "<Alt>%d" % ((i + 1) % 10)
+ else:
+ accel = None
+ self.tab_switch_actiongroup.add_action_with_accel(action, accel)
+ self.ui.add_ui(self.tab_switch_merge_id,
+ "/Menubar/TabMenu/TabPlaceholder",
+ name, name, gtk.UI_MANAGER_MENUITEM, False)
+
def try_remove_page(self, page, appquit=0):
"See if a page will allow itself to be removed"
response = page.on_delete_event(appquit)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]