[meld/ui-next] Move version control status filters to GActions
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/ui-next] Move version control status filters to GActions
- Date: Sat, 23 Mar 2019 02:00:51 +0000 (UTC)
commit 558b9a3e7da8a81928e3b1bee1a5d1af7c551531
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Feb 24 07:04:33 2019 +1000
Move version control status filters to GActions
data/ui/vcview-ui.xml | 19 ------------------
meld/meldwindow.py | 5 +++++
meld/resources/gtk/menus.ui | 28 ++++++++++++++++++++++++++
meld/resources/ui/appwindow.ui | 15 ++++++++++++++
meld/resources/ui/vcview.ui | 45 ------------------------------------------
meld/vcview.py | 44 ++++++++++++++++++++++++++---------------
6 files changed, 76 insertions(+), 80 deletions(-)
---
diff --git a/data/ui/vcview-ui.xml b/data/ui/vcview-ui.xml
index bd43b8cd..a068fafd 100644
--- a/data/ui/vcview-ui.xml
+++ b/data/ui/vcview-ui.xml
@@ -16,17 +16,6 @@
<menuitem action="VcResolved" />
</placeholder>
</menu>
- <menu action="ViewMenu">
- <placeholder name="ViewPlaceholder">
- <menuitem action="VcFlatten" />
- </placeholder>
- <menu action="VcStatus">
- <menuitem action="VcShowModified" />
- <menuitem action="VcShowNormal" />
- <menuitem action="VcShowNonVC" />
- <menuitem action="VcShowIgnored" />
- </menu>
- </menu>
</menubar>
<toolbar name="Toolbar">
@@ -45,14 +34,6 @@
<separator/>
<toolitem action="VcResolved" />
</placeholder>
- <placeholder name="FilterActions">
- <toolitem action="VcFlatten" />
- <separator/>
- <toolitem action="VcShowModified" />
- <toolitem action="VcShowNormal" />
- <toolitem action="VcShowNonVC" />
- <toolitem action="VcShowIgnored" />
- </placeholder>
</toolbar>
<popup name="Popup">
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index 68964c36..8e3f1e7c 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -50,6 +50,7 @@ class MeldWindow(Gtk.ApplicationWindow):
notebook = Template.Child("notebook")
spinner = Template.Child("spinner")
toolbar_holder = Template.Child("toolbar_holder")
+ vc_filter_button = Template.Child()
def __init__(self):
super().__init__()
@@ -174,6 +175,10 @@ class MeldWindow(Gtk.ApplicationWindow):
self.folder_filter_button.set_popover(
Gtk.Popover.new_from_model(self.folder_filter_button, filter_menu))
+ vc_filter_model = app.get_menu_by_id('vc-status-filter-menu')
+ self.vc_filter_button.set_popover(
+ Gtk.Popover.new_from_model(self.vc_filter_button, vc_filter_model))
+
meld.ui.util.extract_accels_from_menu(menu, self.get_application())
def on_widget_drag_data_received(
diff --git a/meld/resources/gtk/menus.ui b/meld/resources/gtk/menus.ui
index e974673c..7fafd898 100644
--- a/meld/resources/gtk/menus.ui
+++ b/meld/resources/gtk/menus.ui
@@ -137,4 +137,32 @@
</item>
</section>
</menu>
+ <menu id="vc-status-filter-menu">
+ <section>
+ <attribute name="id">status-section</attribute>
+ <item>
+ <attribute name="label">Modified</attribute>
+ <attribute name="action">view.vc-status-modified</attribute>
+ </item>
+ <item>
+ <attribute name="label">Normal</attribute>
+ <attribute name="action">view.vc-status-normal</attribute>
+ </item>
+ <item>
+ <attribute name="label">Unversioned</attribute>
+ <attribute name="action">view.vc-status-unknown</attribute>
+ </item>
+ <item>
+ <attribute name="label">Ignored</attribute>
+ <attribute name="action">view.vc-status-ignored</attribute>
+ </item>
+ </section>
+ <section>
+ <attribute name="id">view-section</attribute>
+ <item>
+ <attribute name="label">Flatten folders</attribute>
+ <attribute name="action">view.vc-flatten</attribute>
+ </item>
+ </section>
+ </menu>
</interface>
diff --git a/meld/resources/ui/appwindow.ui b/meld/resources/ui/appwindow.ui
index afbe72b2..8a812f14 100644
--- a/meld/resources/ui/appwindow.ui
+++ b/meld/resources/ui/appwindow.ui
@@ -130,6 +130,21 @@
<property name="pack-type">end</property>
</packing>
</child>
+ <child>
+ <object class="GtkMenuButton" id="vc_filter_button">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Version Filters</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
<child>
<object class="GtkMenuButton" id="folder_filter_button">
<property name="visible">True</property>
diff --git a/meld/resources/ui/vcview.ui b/meld/resources/ui/vcview.ui
index 958d9871..9fd5354a 100644
--- a/meld/resources/ui/vcview.ui
+++ b/meld/resources/ui/vcview.ui
@@ -76,51 +76,6 @@
<signal name="activate" handler="on_button_delete_clicked" swapped="no"/>
</object>
</child>
- <child>
- <object class="GtkToggleAction" id="VcFlatten">
- <property name="label" translatable="yes">_Flatten</property>
- <property name="tooltip" translatable="yes">Flatten directories</property>
- <property name="stock_id">gtk-goto-bottom</property>
- <property name="is_important">True</property>
- <signal name="toggled" handler="on_filter_state_toggled" swapped="no"/>
- </object>
- </child>
- <child>
- <object class="GtkToggleAction" id="VcShowModified">
- <property name="label" translatable="yes">_Modified</property>
- <property name="tooltip" translatable="yes">Show modified files</property>
- <property name="icon_name">filter-modified-24</property>
- <property name="is_important">True</property>
- <signal name="toggled" handler="on_filter_state_toggled" swapped="no"/>
- </object>
- </child>
- <child>
- <object class="GtkToggleAction" id="VcShowNormal">
- <property name="label" translatable="yes">_Normal</property>
- <property name="tooltip" translatable="yes">Show normal files</property>
- <property name="icon_name">filter-normal-24</property>
- <property name="is_important">True</property>
- <signal name="toggled" handler="on_filter_state_toggled" swapped="no"/>
- </object>
- </child>
- <child>
- <object class="GtkToggleAction" id="VcShowNonVC">
- <property name="label" translatable="yes">Un_versioned</property>
- <property name="tooltip" translatable="yes">Show unversioned files</property>
- <property name="icon_name">filter-nonvc-24</property>
- <property name="is_important">True</property>
- <signal name="toggled" handler="on_filter_state_toggled" swapped="no"/>
- </object>
- </child>
- <child>
- <object class="GtkToggleAction" id="VcShowIgnored">
- <property name="label" translatable="yes">Ignored</property>
- <property name="tooltip" translatable="yes">Show ignored files</property>
- <property name="icon_name">filter-ignored-24</property>
- <property name="is_important">True</property>
- <signal name="toggled" handler="on_filter_state_toggled" swapped="no"/>
- </object>
- </child>
</object>
<template class="VcView" parent="GtkVBox">
<property name="visible">True</property>
diff --git a/meld/vcview.py b/meld/vcview.py
index eda93fc1..87353f77 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -150,11 +150,11 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
}
state_actions = {
- "flatten": ("VcFlatten", None),
- "modified": ("VcShowModified", Entry.is_modified),
- "normal": ("VcShowNormal", Entry.is_normal),
- "unknown": ("VcShowNonVC", Entry.is_nonvc),
- "ignored": ("VcShowIgnored", Entry.is_ignored),
+ 'flatten': ('vc-flatten', None),
+ 'modified': ('vc-status-modified', Entry.is_modified),
+ 'normal': ('vc-status-normal', Entry.is_normal),
+ 'unknown': ('vc-status-unknown', Entry.is_nonvc),
+ 'ignored': ('vc-status-ignored', Entry.is_ignored),
}
combobox_vcs = Template.Child()
@@ -215,6 +215,24 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
action.connect('activate', callback)
self.view_action_group.add_action(action)
+ new_boolean = GLib.Variant.new_boolean
+ stateful_actions = (
+ ('vc-flatten', self.action_filter_state_change,
+ new_boolean('flatten' in self.props.status_filters)),
+ ('vc-status-modified', self.action_filter_state_change,
+ new_boolean('modified' in self.props.status_filters)),
+ ('vc-status-normal', self.action_filter_state_change,
+ new_boolean('normal' in self.props.status_filters)),
+ ('vc-status-unknown', self.action_filter_state_change,
+ new_boolean('unknown' in self.props.status_filters)),
+ ('vc-status-ignored', self.action_filter_state_change,
+ new_boolean('ignored' in self.props.status_filters)),
+ )
+ for (name, callback, state) in stateful_actions:
+ action = Gio.SimpleAction.new_stateful(name, None, state)
+ action.connect('change-state', callback)
+ self.view_action_group.add_action(action)
+
self.model = VcTreeStore()
self.connect("style-updated", self.model.on_style_updated)
self.model.on_style_updated(self)
@@ -241,8 +259,6 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
self.status_renderer, markup=COL_STATUS)
self.extra_column.set_attributes(
self.extra_renderer, markup=COL_OPTIONS)
- self.location_column.bind_property(
- 'visible', self.actiongroup.get_action("VcFlatten"), 'active')
self.consolestream = ConsoleStream(self.consoleview)
self.location = None
@@ -253,11 +269,6 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
settings.bind('vc-console-pane-position', self.vc_console_vpaned,
'position', Gio.SettingsBindFlags.DEFAULT)
- for s in self.props.status_filters:
- if s in self.state_actions:
- self.actiongroup.get_action(
- self.state_actions[s][0]).set_active(True)
-
def on_container_switch_in_event(self, ui, window):
super().on_container_switch_in_event(ui, window)
# FIXME: open-external should be tied to having a treeview selection
@@ -545,11 +556,12 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
kwargs,
)
- @Template.Callback()
- def on_filter_state_toggled(self, button):
+ def action_filter_state_change(self, action, value):
+ action.set_state(value)
+
active_filters = [
k for k, (action_name, fn) in self.state_actions.items()
- if self.actiongroup.get_action(action_name).get_active()
+ if self.get_action_state(action_name)
]
if set(active_filters) == set(self.props.status_filters):
@@ -755,7 +767,7 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
self.set_location(self.model.get_file_path(root))
def refresh_partial(self, where):
- if not self.actiongroup.get_action("VcFlatten").get_active():
+ if not self.get_action_state('vc-flatten'):
it = self.find_iter_by_name(where)
if not it:
return
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]