[meld/ui-next] dirdiff: Move state filters and ignore case to GActions
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/ui-next] dirdiff: Move state filters and ignore case to GActions
- Date: Sat, 23 Mar 2019 02:00:31 +0000 (UTC)
commit 05b531a8f73e2264fdad7391bd3be0cc521d4a7b
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Feb 23 07:57:59 2019 +1000
dirdiff: Move state filters and ignore case to GActions
data/ui/dirdiff-ui.xml | 14 ------------
meld/dirdiff.py | 50 ++++++++++++++++++++++++++++--------------
meld/melddoc.py | 8 +++++++
meld/meldwindow.py | 5 +++++
meld/resources/gtk/menus.ui | 27 ++++++++++++++++++++++-
meld/resources/ui/appwindow.ui | 15 +++++++++++++
meld/resources/ui/dirdiff.ui | 35 -----------------------------
7 files changed, 88 insertions(+), 66 deletions(-)
---
diff --git a/data/ui/dirdiff-ui.xml b/data/ui/dirdiff-ui.xml
index 8aaebd29..65b7af3b 100644
--- a/data/ui/dirdiff-ui.xml
+++ b/data/ui/dirdiff-ui.xml
@@ -1,15 +1,5 @@
<ui>
<menubar name="Menubar">
- <menu action="ViewMenu">
- <placeholder name="ViewPlaceholder">
- <menuitem action="IgnoreCase" />
- </placeholder>
- <menu action="FileStatus">
- <menuitem action="ShowSame" />
- <menuitem action="ShowNew" />
- <menuitem action="ShowModified" />
- </menu>
- </menu>
<menu action="ChangesMenu">
<placeholder name="ChangesActions">
<menuitem action="DirCopyLeft" />
@@ -32,10 +22,6 @@
<toolitem action="DirDelete" />
</placeholder>
<placeholder name="FilterActions">
- <toolitem action="ShowSame" />
- <toolitem action="ShowNew" />
- <toolitem action="ShowModified" />
- <separator/>
<toolitem action="CustomFilterMenu"/>
<placeholder name="FilterButtons" />
</placeholder>
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index b85621d9..2c852327 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -387,10 +387,10 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
}
state_actions = {
- tree.STATE_NORMAL: ("normal", "ShowSame"),
- tree.STATE_NOCHANGE: ("normal", "ShowSame"),
- tree.STATE_NEW: ("new", "ShowNew"),
- tree.STATE_MODIFIED: ("modified", "ShowModified"),
+ tree.STATE_NORMAL: ("normal", "folder-status-same"),
+ tree.STATE_NOCHANGE: ("normal", "folder-status-same"),
+ tree.STATE_NEW: ("new", "folder-status-new"),
+ tree.STATE_MODIFIED: ("modified", "folder-status-modified"),
}
def __init__(self, num_panes):
@@ -423,6 +423,21 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
action.connect('activate', callback)
self.view_action_group.add_action(action)
+ actions = (
+ ("folder-status-same", self.action_filter_state_change,
+ GLib.Variant.new_boolean(False)),
+ ("folder-status-new", self.action_filter_state_change,
+ GLib.Variant.new_boolean(False)),
+ ("folder-status-modified", self.action_filter_state_change,
+ GLib.Variant.new_boolean(False)),
+ ("folder-ignore-case", self.action_ignore_case_change,
+ GLib.Variant.new_boolean(False)),
+ )
+ for (name, callback, state) in actions:
+ action = Gio.SimpleAction.new_stateful(name, None, state)
+ action.connect('change-state', callback)
+ self.view_action_group.add_action(action)
+
self.name_filters = []
self.text_filters = []
self.create_name_filters()
@@ -533,11 +548,12 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
# toggled callback modifies the state while we're constructing it.
self.state_filters = []
state_filters = []
- status_filters = list(self.props.status_filters)
- for state, (filter_name, action_name) in self.state_actions.items():
- if filter_name in status_filters:
- state_filters.append(state)
- self.actiongroup.get_action(action_name).set_active(True)
+ for s in self.state_actions:
+ if self.state_actions[s][0] in self.props.status_filters:
+ state_filters.append(s)
+ action_name = self.state_actions[s][1]
+ self.set_action_state(
+ action_name, GLib.Variant.new_boolean(True))
self.state_filters = state_filters
self._scan_in_progress = 0
@@ -806,7 +822,8 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
encoding_errors = []
canonicalize = None
- if self.actiongroup.get_action("IgnoreCase").get_active():
+ # TODO: Map this to a GObject prop instead?
+ if self.get_action_state('folder-ignore-case'):
canonicalize = CanonicalListing.canonicalize_lower
dirs = CanonicalListing(self.num_panes, canonicalize)
files = CanonicalListing(self.num_panes, canonicalize)
@@ -1361,15 +1378,16 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
if files:
self._open_files(files)
- @Template.Callback()
- def on_button_ignore_case_toggled(self, button):
+ def action_ignore_case_change(self, action, value):
+ action.set_state(value)
self.refresh()
- @Template.Callback()
- def on_filter_state_toggled(self, button):
+ def action_filter_state_change(self, action, value):
+ action.set_state(value)
+
active_filters = [
- state for state, (_, action_name) in self.state_actions.items()
- if self.actiongroup.get_action(action_name).get_active()
+ a for a in self.state_actions
+ if self.get_action_state(self.state_actions[a][1])
]
if set(active_filters) == set(self.state_filters):
diff --git a/meld/melddoc.py b/meld/melddoc.py
index b7249d9e..cdcc4737 100644
--- a/meld/melddoc.py
+++ b/meld/melddoc.py
@@ -187,6 +187,14 @@ class MeldDoc(LabeledObjectMixin, GObject.GObject):
def set_labels(self, lst):
pass
+ def get_action_state(self, action_name: str):
+ action = self.view_action_group.lookup_action(action_name)
+ return action.get_state().unpack()
+
+ def set_action_state(self, action_name: str, state):
+ # TODO: Try to do GLib.Variant things here instead of in callers
+ self.view_action_group.lookup_action(action_name).set_state(state)
+
def set_action_enabled(self, action, enabled):
self.view_action_group.lookup_action(action).set_enabled(enabled)
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index bbc90cae..9e7f3926 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -45,6 +45,7 @@ class MeldWindow(Gtk.ApplicationWindow):
__gtype_name__ = 'MeldWindow'
appvbox = Template.Child("appvbox")
+ folder_filter_button = Template.Child()
gear_menu_button = Template.Child("gear_menu_button")
notebook = Template.Child("notebook")
spinner = Template.Child("spinner")
@@ -176,6 +177,10 @@ class MeldWindow(Gtk.ApplicationWindow):
self.gear_menu_button.set_popover(
Gtk.Popover.new_from_model(self.gear_menu_button, menu))
+ filter_menu = app.get_menu_by_id("folder-status-filter-menu")
+ self.folder_filter_button.set_popover(
+ Gtk.Popover.new_from_model(self.folder_filter_button, filter_menu))
+
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 f262fa7b..1b3483fd 100644
--- a/meld/resources/gtk/menus.ui
+++ b/meld/resources/gtk/menus.ui
@@ -65,7 +65,7 @@
<section>
<attribute name="id">tool-section</attribute>
<item>
- <attribute name="label">Format as Patch…</attribute>
+ <attribute name="label" translatable="yes">Format as Patch…</attribute>
<attribute name="action">view.format-as-patch</attribute>
</item>
</section>
@@ -104,4 +104,29 @@
</item>
</section>
</menu>
+ <menu id="folder-status-filter-menu">
+ <section>
+ <attribute name="id">status-section</attribute>
+ <attribute name="label" translatable="yes">File status</attribute>
+ <item>
+ <attribute name="label" translatable="yes">Same</attribute>
+ <attribute name="action">view.folder-status-same</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">New</attribute>
+ <attribute name="action">view.folder-status-new</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Modified</attribute>
+ <attribute name="action">view.folder-status-modified</attribute>
+ </item>
+ </section>
+ <section>
+ <attribute name="id">options-section</attribute>
+ <item>
+ <attribute name="label" translatable="yes">Ignore filename case</attribute>
+ <attribute name="action">view.folder-ignore-case</attribute>
+ </item>
+ </section>
+ </menu>
</interface>
diff --git a/meld/resources/ui/appwindow.ui b/meld/resources/ui/appwindow.ui
index a625af51..afbe72b2 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="folder_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">File Filters</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
</object>
</child>
diff --git a/meld/resources/ui/dirdiff.ui b/meld/resources/ui/dirdiff.ui
index 79d73bc7..4a0dedfe 100644
--- a/meld/resources/ui/dirdiff.ui
+++ b/meld/resources/ui/dirdiff.ui
@@ -68,41 +68,6 @@
<signal name="activate" handler="on_filter_hide_current_clicked" swapped="no"/>
</object>
</child>
- <child>
- <object class="GtkToggleAction" id="IgnoreCase">
- <property name="label" translatable="yes">Ignore Filename Case</property>
- <property name="tooltip" translatable="yes">Consider differently-cased filenames that are
otherwise-identical to be the same</property>
- <property name="stock_id">gtk-italic</property>
- <signal name="toggled" handler="on_button_ignore_case_toggled" swapped="no"/>
- </object>
- </child>
- <child>
- <object class="GtkToggleAction" id="ShowSame">
- <property name="label" translatable="yes">Same</property>
- <property name="tooltip" translatable="yes">Show identical</property>
- <property name="stock_id">gtk-apply</property>
- <property name="is_important">True</property>
- <signal name="toggled" handler="on_filter_state_toggled" swapped="no"/>
- </object>
- </child>
- <child>
- <object class="GtkToggleAction" id="ShowNew">
- <property name="label" translatable="yes">New</property>
- <property name="tooltip" translatable="yes">Show new</property>
- <property name="stock_id">gtk-add</property>
- <property name="is_important">True</property>
- <signal name="toggled" handler="on_filter_state_toggled" swapped="no"/>
- </object>
- </child>
- <child>
- <object class="GtkToggleAction" id="ShowModified">
- <property name="label" translatable="yes">Modified</property>
- <property name="tooltip" translatable="yes">Show modified</property>
- <property name="stock_id">gtk-remove</property>
- <property name="is_important">True</property>
- <signal name="toggled" handler="on_filter_state_toggled" swapped="no"/>
- </object>
- </child>
<child>
<object class="GtkToggleAction" id="CustomFilterMenu">
<property name="label" translatable="yes">Filters</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]