[meld] Remove tab list from menu, replacing with keybinding actions
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] Remove tab list from menu, replacing with keybinding actions
- Date: Sun, 1 May 2016 20:45:26 +0000 (UTC)
commit df4cf9796a277a2d2924f5ef916590a823f7cef5
Author: Kai Willadsen <kai willadsen gmail com>
Date: Tue Nov 3 11:11:21 2015 +1000
Remove tab list from menu, replacing with keybinding actions
This commit creates a new MeldNotebook class for handling some contained
notebook behaviours and keybindings. Since we're looking to reduce the
overall UI handled by UIManager, and because it's no longer standard to
keep a list of open tabs as menu items, we're dropping that bit of the
UI and accompanying handling. This reimplements only the Alt+number
keybindings for quick tab switching.
data/ui/meldapp-ui.xml | 2 -
data/ui/meldapp.ui | 5 +---
meld/meldwindow.py | 56 -----------------------------------------------
meld/ui/gladesupport.py | 1 +
meld/ui/notebook.py | 53 ++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 55 insertions(+), 62 deletions(-)
---
diff --git a/data/ui/meldapp-ui.xml b/data/ui/meldapp-ui.xml
index 3cde9bd..330ecb3 100644
--- a/data/ui/meldapp-ui.xml
+++ b/data/ui/meldapp-ui.xml
@@ -57,8 +57,6 @@
<separator/>
<menuitem action="MoveTabPrev" />
<menuitem action="MoveTabNext" />
- <separator/>
- <placeholder name="TabPlaceholder" />
</menu>
</menubar>
diff --git a/data/ui/meldapp.ui b/data/ui/meldapp.ui
index b06c068..4ac2c93 100644
--- a/data/ui/meldapp.ui
+++ b/data/ui/meldapp.ui
@@ -24,17 +24,14 @@
</packing>
</child>
<child>
- <object class="GtkNotebook" id="notebook">
+ <object class="MeldNotebook" id="notebook">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="scrollable">True</property>
<property name="enable_popup">True</property>
- <signal name="page-reordered" handler="_update_notebook_menu" swapped="no"/>
<signal name="page-reordered" handler="after_page_reordered" after="yes" swapped="no"/>
- <signal name="page-added" handler="_update_notebook_menu" swapped="no"/>
<signal name="switch-page" handler="on_switch_page" swapped="no"/>
<signal name="switch-page" handler="after_switch_page" after="yes" swapped="no"/>
- <signal name="page-removed" handler="_update_notebook_menu" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index d419692..efbdac3 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -184,9 +184,6 @@ class MeldWindow(gnomeglade.Component):
self.ui.add_ui_from_file(ui_file)
self.widget.set_show_menubar(False)
- 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
self.widget.add_accel_group(self.ui.get_accel_group())
@@ -410,10 +407,6 @@ class MeldWindow(gnomeglade.Component):
def after_switch_page(self, notebook, page, which):
self._update_page_action_sensitivity()
- actiongroup = self.tab_switch_actiongroup
- if actiongroup:
- action_name = "SwitchTab%d" % which
- actiongroup.get_action(action_name).set_active(True)
def after_page_reordered(self, notebook, page, page_num):
self._update_page_action_sensitivity()
@@ -431,13 +424,6 @@ class MeldWindow(gnomeglade.Component):
text = text.encode('utf8')
self.notebook.child_set_property(page, "menu-label", text)
- actiongroup = self.tab_switch_actiongroup
- if actiongroup:
- idx = self.notebook.page_num(page)
- action_name = "SwitchTab%d" % idx
- label = text.replace("_", "__")
- actiongroup.get_action(action_name).set_label(label)
-
def on_can_undo(self, undosequence, can):
self.actiongroup.get_action("Undo").set_sensitive(can)
@@ -563,48 +549,6 @@ 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.ui.ensure_update()
- self.tab_switch_merge_id = None
- self.tab_switch_actiongroup = None
-
- if not self.notebook.get_n_pages():
- return
-
- self.tab_switch_merge_id = self.ui.new_merge_id()
- self.tab_switch_actiongroup = Gtk.ActionGroup(name="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 ""
- label = label.replace("_", "__")
- name = "SwitchTab%d" % i
- tooltip = _("Switch to this tab")
- action = Gtk.RadioAction(
- name=name, label=label, tooltip=tooltip,
- stock_id=None, value=i)
- action.join_group(group)
- 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.UIManagerItemType.MENUITEM, False)
-
def page_removed(self, page, status):
if hasattr(page, 'scheduler'):
self.scheduler.remove_scheduler(page.scheduler)
diff --git a/meld/ui/gladesupport.py b/meld/ui/gladesupport.py
index 4ea0442..fe100b0 100644
--- a/meld/ui/gladesupport.py
+++ b/meld/ui/gladesupport.py
@@ -7,4 +7,5 @@ from meld import sourceview
from meld.ui import emblemcellrenderer
from meld.ui import historyentry
from meld.ui import msgarea
+from meld.ui import notebook
from meld.ui import statusbar
diff --git a/meld/ui/notebook.py b/meld/ui/notebook.py
new file mode 100644
index 0000000..8f70caf
--- /dev/null
+++ b/meld/ui/notebook.py
@@ -0,0 +1,53 @@
+# Copyright (C) 2015 Kai Willadsen <kai willadsen gmail com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or (at
+# your option) any later version.
+#
+# This program 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from gi.repository import Gdk
+from gi.repository import GObject
+from gi.repository import Gtk
+
+
+class MeldNotebook(Gtk.Notebook):
+
+ __gtype_name__ = "MeldNotebook"
+
+ __gsignals__ = {
+ 'tab-switch': (GObject.SignalFlags.ACTION, None, (int,)),
+ }
+
+ css = """
+ @binding-set TabSwitchBindings {}
+ MeldNotebook { gtk-key-bindings: TabSwitchBindings; }
+ """
+
+ def __init__(self, *args, **kwargs):
+ Gtk.Notebook.__init__(self, *args, **kwargs)
+
+ provider = Gtk.CssProvider()
+ provider.load_from_data(self.css)
+ Gtk.StyleContext.add_provider_for_screen(
+ Gdk.Screen.get_default(), provider,
+ Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
+
+ # Awful hacks because we can't create GtkBindingArg from Python, or
+ # create a BindingSet from Python, or get a set by class from Python.
+ bindings = Gtk.BindingSet.find('TabSwitchBindings')
+ for i in range(10):
+ key = (i + 1) % 10
+ Gtk.BindingEntry().add_signal_from_string(
+ bindings, 'bind "<Alt>%d" { "tab-switch" (%d) };' % (key, i))
+ self.connect('tab-switch', self.do_tab_switch)
+
+ def do_tab_switch(self, notebook, page_num):
+ notebook.set_current_page(page_num)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]