[meld] meld.ui.notebook: Move tab movement handling to MeldNotebook class
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] meld.ui.notebook: Move tab movement handling to MeldNotebook class
- Date: Sun, 1 May 2016 20:45:31 +0000 (UTC)
commit 675d2333d4cc662c1a13888a7e4760d72fc0484d
Author: Kai Willadsen <kai willadsen gmail com>
Date: Wed Nov 4 07:50:24 2015 +1000
meld.ui.notebook: Move tab movement handling to MeldNotebook class
data/ui/meldapp-ui.xml | 7 ----
data/ui/meldapp.ui | 2 +-
meld/meldwindow.py | 39 -------------------------
meld/ui/notebook.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 76 insertions(+), 47 deletions(-)
---
diff --git a/data/ui/meldapp-ui.xml b/data/ui/meldapp-ui.xml
index 330ecb3..d475f76 100644
--- a/data/ui/meldapp-ui.xml
+++ b/data/ui/meldapp-ui.xml
@@ -51,13 +51,6 @@
<menuitem action="Stop" />
<menuitem action="Refresh" />
</menu>
- <menu action="TabMenu">
- <menuitem action="PrevTab" />
- <menuitem action="NextTab" />
- <separator/>
- <menuitem action="MoveTabPrev" />
- <menuitem action="MoveTabNext" />
- </menu>
</menubar>
<toolbar action="Toolbar">
diff --git a/data/ui/meldapp.ui b/data/ui/meldapp.ui
index 4ac2c93..932aef7 100644
--- a/data/ui/meldapp.ui
+++ b/data/ui/meldapp.ui
@@ -28,7 +28,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="scrollable">True</property>
- <property name="enable_popup">True</property>
+ <property name="enable_popup">False</property>
<signal name="page-reordered" handler="after_page_reordered" after="yes" swapped="no"/>
<signal name="switch-page" handler="on_switch_page" swapped="no"/>
<signal name="switch-page" handler="after_switch_page" after="yes" swapped="no"/>
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index efbdac3..d3c5ad5 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -108,22 +108,6 @@ class MeldWindow(gnomeglade.Component):
("Refresh", Gtk.STOCK_REFRESH, None, "<Primary>R",
_("Refresh the view"),
self.on_menu_refresh_activate),
-
- ("TabMenu", None, _("_Tabs")),
- ("PrevTab", None, _("_Previous Tab"), "<Ctrl><Alt>Page_Up",
- _("Activate previous tab"),
- self.on_prev_tab),
- ("NextTab", None, _("_Next Tab"), "<Ctrl><Alt>Page_Down",
- _("Activate next tab"),
- self.on_next_tab),
- ("MoveTabPrev", None,
- _("Move Tab _Left"), "<Ctrl><Alt><Shift>Page_Up",
- _("Move current tab to left"),
- self.on_move_tab_prev),
- ("MoveTabNext", None,
- _("Move Tab _Right"), "<Ctrl><Alt><Shift>Page_Down",
- _("Move current tab to right"),
- self.on_move_tab_next),
)
toggleactions = (
("Fullscreen", None, _("Fullscreen"), "F11",
@@ -328,12 +312,6 @@ class MeldWindow(gnomeglade.Component):
def _update_page_action_sensitivity(self):
current_page = self.notebook.get_current_page()
- have_prev_tab = current_page > 0
- have_next_tab = current_page < self.notebook.get_n_pages() - 1
- self.actiongroup.get_action("PrevTab").set_sensitive(have_prev_tab)
- self.actiongroup.get_action("NextTab").set_sensitive(have_next_tab)
- self.actiongroup.get_action("MoveTabPrev").set_sensitive(have_prev_tab)
- self.actiongroup.get_action("MoveTabNext").set_sensitive(have_next_tab)
if current_page != -1:
page = self.notebook.get_nth_page(current_page).pyobject
@@ -532,23 +510,6 @@ class MeldWindow(gnomeglade.Component):
def on_toolbar_stop_clicked(self, *args):
self.current_doc().stop()
- def on_prev_tab(self, *args):
- self.notebook.prev_page()
-
- def on_next_tab(self, *args):
- self.notebook.next_page()
-
- def on_move_tab_prev(self, *args):
- page_num = self.notebook.get_current_page()
- child = self.notebook.get_nth_page(page_num)
- page_num = page_num - 1 if page_num > 0 else 0
- self.notebook.reorder_child(child, page_num)
-
- def on_move_tab_next(self, *args):
- page_num = self.notebook.get_current_page()
- child = self.notebook.get_nth_page(page_num)
- self.notebook.reorder_child(child, page_num + 1)
-
def page_removed(self, page, status):
if hasattr(page, 'scheduler'):
self.scheduler.remove_scheduler(page.scheduler)
diff --git a/meld/ui/notebook.py b/meld/ui/notebook.py
index 8f70caf..916533b 100644
--- a/meld/ui/notebook.py
+++ b/meld/ui/notebook.py
@@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gdk
+from gi.repository import Gio
from gi.repository import GObject
from gi.repository import Gtk
@@ -31,9 +32,45 @@ class MeldNotebook(Gtk.Notebook):
MeldNotebook { gtk-key-bindings: TabSwitchBindings; }
"""
+ ui = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <interface>
+ <menu id="tab-menu">
+ <item>
+ <attribute name="label">Move _Left</attribute>
+ <attribute name="action">popup.tabmoveleft</attribute>
+ </item>
+ <item>
+ <attribute name="label">Move _Right</attribute>
+ <attribute name="action">popup.tabmoveright</attribute>
+ </item>
+ <item>
+ <attribute name="label">_Close</attribute>
+ <attribute name="action">win.close</attribute>
+ </item>
+ </menu>
+ </interface>
+ """
+
def __init__(self, *args, **kwargs):
Gtk.Notebook.__init__(self, *args, **kwargs)
+ self.action_group = Gio.SimpleActionGroup()
+
+ actions = (
+ ("tabmoveleft", self.on_tab_move_left),
+ ("tabmoveright", self.on_tab_move_right),
+ )
+ for (name, callback) in actions:
+ action = Gio.SimpleAction.new(name, None)
+ action.connect('activate', callback)
+ self.action_group.add_action(action)
+
+ self.insert_action_group("popup", self.action_group)
+
+ builder = Gtk.Builder.new_from_string(self.ui, -1)
+ self.popup_menu = builder.get_object("tab-menu")
+
provider = Gtk.CssProvider()
provider.load_from_data(self.css)
Gtk.StyleContext.add_provider_for_screen(
@@ -49,5 +86,43 @@ class MeldNotebook(Gtk.Notebook):
bindings, 'bind "<Alt>%d" { "tab-switch" (%d) };' % (key, i))
self.connect('tab-switch', self.do_tab_switch)
+ self.connect('button-press-event', self.on_button_press_event)
+ self.connect('popup-menu', self.on_popup_menu)
+
def do_tab_switch(self, notebook, page_num):
notebook.set_current_page(page_num)
+
+ def on_popup_menu(self, widget, event=None):
+ self.action_group.lookup_action("tabmoveleft").set_enabled(
+ self.get_current_page() > 0)
+ self.action_group.lookup_action("tabmoveright").set_enabled(
+ self.get_current_page() < self.get_n_pages() - 1)
+
+ if event:
+ button = event.button
+ time = event.time
+ else:
+ button = 0
+ time = Gtk.get_current_event_time()
+ popup = Gtk.Menu.new_from_model(self.popup_menu)
+ popup.attach_to_widget(widget, None)
+ popup.show_all()
+ popup.popup(None, None, None, None, button, time)
+ return True
+
+ def on_button_press_event(self, widget, event):
+ if (event.triggers_context_menu() and
+ event.type == Gdk.EventType.BUTTON_PRESS):
+ return self.on_popup_menu(widget, event)
+ return False
+
+ def on_tab_move_left(self, *args):
+ page_num = self.get_current_page()
+ child = self.get_nth_page(page_num)
+ page_num = page_num - 1 if page_num > 0 else 0
+ self.reorder_child(child, page_num)
+
+ def on_tab_move_right(self, *args):
+ page_num = self.get_current_page()
+ child = self.get_nth_page(page_num)
+ self.reorder_child(child, page_num + 1)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]