[meld/ui-next] Move save & revert actions to GActions



commit 12084c7171b2bf91c0cab10229425e8ebc3d580f
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Feb 17 14:52:46 2019 +1000

    Move save & revert actions to GActions

 data/ui/filediff-ui.xml       |  8 --------
 data/ui/meldapp-ui.xml        |  4 ----
 meld/accelerators.py          |  3 +++
 meld/filediff.py              | 25 ++++++++++++-------------
 meld/melddoc.py               |  6 ------
 meld/meldwindow.py            | 21 ---------------------
 meld/resources/gtk/menus.ui   | 19 +++++++++++++++++++
 meld/resources/ui/filediff.ui | 15 ---------------
 8 files changed, 34 insertions(+), 67 deletions(-)
---
diff --git a/data/ui/filediff-ui.xml b/data/ui/filediff-ui.xml
index f3fc2e66..55c69509 100644
--- a/data/ui/filediff-ui.xml
+++ b/data/ui/filediff-ui.xml
@@ -1,11 +1,5 @@
 <ui>
   <menubar name="Menubar">
-    <menu action="FileMenu">
-      <placeholder name="RevertPlaceholder">
-        <menuitem action="SaveAll"/>
-        <menuitem action="Revert"/>
-      </placeholder>
-    </menu>
     <menu action="EditMenu">
       <placeholder name="EditActionsPlaceholder">
         <menuitem action="SplitAdd"/>
@@ -58,8 +52,6 @@
     <menuitem action="SplitClear"/>
     <separator/>
     <menuitem action="OpenExternal" />
-    <menuitem action="Save" />
-    <menuitem action="SaveAs" />
   </popup>
 
 </ui>
diff --git a/data/ui/meldapp-ui.xml b/data/ui/meldapp-ui.xml
index 1d4addb6..037a89a8 100644
--- a/data/ui/meldapp-ui.xml
+++ b/data/ui/meldapp-ui.xml
@@ -1,10 +1,6 @@
 <ui>
   <menubar name="Menubar">
     <menu action="FileMenu">
-      <menuitem action="Save" />
-      <menuitem action="SaveAs" />
-      <placeholder name="RevertPlaceholder" />
-      <separator/>
       <menuitem action="Recent" />
       <menuitem action="Close" />
     </menu>
diff --git a/meld/accelerators.py b/meld/accelerators.py
index 6a4d8fa1..efeb5322 100644
--- a/meld/accelerators.py
+++ b/meld/accelerators.py
@@ -7,6 +7,9 @@ def register_accels(app: Gtk.Application):
         ("view.next-change", ("<Alt>Down", "<Alt>KP_Down", "<Primary>D")),
         ("view.previous-change", ("<Alt>Up", "<Alt>KP_Up", "<Primary>E")),
         ("view.refresh", ("<control>R", "F5")),
+        ('view.save', '<Primary>S'),
+        ('view.save-all', '<Primary><Shift>L'),
+        ('view.save-as', '<Primary><Shift>S'),
         ("win.stop", "Escape"),
     )
     for (name, accel) in view_accels:
diff --git a/meld/filediff.py b/meld/filediff.py
index 20fd45c6..0d109a9a 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -282,6 +282,10 @@ class FileDiff(Gtk.VBox, MeldDoc):
             ('next-change', self.action_next_change),
             ('previous-change', self.action_previous_change),
             ('refresh', self.action_refresh),
+            ('revert', self.action_revert),
+            ('save', self.action_save),
+            ('save-all', self.action_save_all),
+            ('save-as', self.action_save_as),
         )
         for name, callback in actions:
             action = Gio.SimpleAction.new(name, None)
@@ -1216,12 +1220,9 @@ class FileDiff(Gtk.VBox, MeldDoc):
 
     def _set_save_action_sensitivity(self):
         pane = self._get_focused_pane()
-        modified = (
-            False if pane == -1 else self.textbuffer[pane].get_modified())
-        if self.main_actiongroup:
-            self.main_actiongroup.get_action("Save").set_sensitive(modified)
-        any_modified = any(b.get_modified() for b in self.textbuffer)
-        self.actiongroup.get_action("SaveAll").set_sensitive(any_modified)
+        modified_panes = [b.get_modified() for b in self.textbuffer]
+        self.set_action_enabled('save', pane != -1 and modified_panes[pane])
+        self.set_action_enabled('save-all', any(modified_panes))
 
     def recompute_label(self):
         self._set_save_action_sensitivity()
@@ -1459,7 +1460,7 @@ class FileDiff(Gtk.VBox, MeldDoc):
         secondary = _("Do you want to reload the file?")
         self.msgarea_mgr[pane].add_action_msg(
             'dialog-warning-symbolic', primary, secondary, _("_Reload"),
-            self.on_revert_activate)
+            self.action_revert)
 
     def refresh_comparison(self, *args):
         """Refresh the view by clearing and redoing all comparisons"""
@@ -1831,15 +1832,14 @@ class FileDiff(Gtk.VBox, MeldDoc):
         self.on_cursor_position_changed(buf, None, True)
 
     @with_focused_pane
-    def save(self, pane):
+    def action_save(self, pane, *args):
         self.save_file(pane)
 
     @with_focused_pane
-    def save_as(self, pane):
+    def action_save_as(self, pane, *args):
         self.save_file(pane, saveas=True)
 
-    @Template.Callback()
-    def on_save_all_activate(self, action):
+    def action_save_all(self, *args):
         for i in range(self.num_panes):
             if self.textbuffer[i].get_modified():
                 self.save_file(i)
@@ -1895,8 +1895,7 @@ class FileDiff(Gtk.VBox, MeldDoc):
         dialog.destroy()
         return response == Gtk.ResponseType.OK
 
-    @Template.Callback()
-    def on_revert_activate(self, *extra):
+    def action_revert(self, *extra):
         if not self.check_unsaved_changes():
             return
 
diff --git a/meld/melddoc.py b/meld/melddoc.py
index 2a9007de..74939519 100644
--- a/meld/melddoc.py
+++ b/meld/melddoc.py
@@ -115,12 +115,6 @@ class MeldDoc(LabeledObjectMixin, GObject.GObject):
         if self.scheduler.tasks_pending():
             self.scheduler.remove_task(self.scheduler.get_current_task())
 
-    def save(self):
-        pass
-
-    def save_as(self):
-        pass
-
     def _open_files(self, selected, line=0):
         query_attrs = ",".join((Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
                                 Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE))
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index d10f05c4..56e0b1d5 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -57,12 +57,6 @@ class MeldWindow(Gtk.ApplicationWindow):
 
         actions = (
             ("FileMenu", None, _("_File")),
-            ("Save", Gtk.STOCK_SAVE, None, None,
-                _("Save the current file"),
-                self.on_menu_save_activate),
-            ("SaveAs", Gtk.STOCK_SAVE_AS, _("Save As…"), "<Primary><shift>S",
-                _("Save the current file with a different name"),
-                self.on_menu_save_as_activate),
             ("Close", Gtk.STOCK_CLOSE, None, None,
                 _("Close the current file"),
                 self.on_menu_close_activate),
@@ -124,8 +118,6 @@ class MeldWindow(Gtk.ApplicationWindow):
         self.ui.insert_action_group(self.actiongroup, 0)
         self.ui.add_ui_from_file(ui_file("meldapp-ui.xml"))
 
-        for menuitem in ("Save", "Undo"):
-            self.actiongroup.get_action(menuitem).props.is_important = True
         self.add_accel_group(self.ui.get_accel_group())
         self.menubar = self.ui.get_widget('/Menubar')
         self.toolbar = self.ui.get_widget('/Toolbar')
@@ -309,13 +301,6 @@ class MeldWindow(Gtk.ApplicationWindow):
         self.actiongroup.get_action("Undo").set_sensitive(can_undo)
         self.actiongroup.get_action("Redo").set_sensitive(can_redo)
 
-        # FileDiff handles save sensitivity; it makes no sense for other modes
-        if not isinstance(newdoc, FileDiff):
-            self.actiongroup.get_action("Save").set_sensitive(False)
-            self.actiongroup.get_action("SaveAs").set_sensitive(False)
-        else:
-            self.actiongroup.get_action("SaveAs").set_sensitive(True)
-
         if newdoc:
             nbl = self.notebook.get_tab_label(newdoc)
             self.set_title(nbl.props.label_text)
@@ -348,12 +333,6 @@ class MeldWindow(Gtk.ApplicationWindow):
     def on_action_new_tab_activate(self, action, parameter):
         self.append_new_comparison()
 
-    def on_menu_save_activate(self, menuitem):
-        self.current_doc().save()
-
-    def on_menu_save_as_activate(self, menuitem):
-        self.current_doc().save_as()
-
     def on_action_recent(self, action):
         uri = action.get_current_uri()
         if not uri:
diff --git a/meld/resources/gtk/menus.ui b/meld/resources/gtk/menus.ui
index b90e0148..df5c5783 100644
--- a/meld/resources/gtk/menus.ui
+++ b/meld/resources/gtk/menus.ui
@@ -20,6 +20,25 @@
         <attribute name="accel">F11</attribute>
       </item>
     </section>
+    <section>
+      <attribute name="id">file-section</attribute>
+      <item>
+        <attribute name="label" translatable="yes">_Save</attribute>
+        <attribute name="action">view.save</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Save As…</attribute>
+        <attribute name="action">view.save-as</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Save A_ll</attribute>
+        <attribute name="action">view.save-all</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Revert files…</attribute>
+        <attribute name="action">view.revert</attribute>
+      </item>
+    </section>
     <section>
       <submenu>
         <attribute name="label" translatable="yes">View</attribute>
diff --git a/meld/resources/ui/filediff.ui b/meld/resources/ui/filediff.ui
index 1af42ec8..785314e2 100644
--- a/meld/resources/ui/filediff.ui
+++ b/meld/resources/ui/filediff.ui
@@ -730,21 +730,6 @@
     </child>
   </template>
   <object class="GtkActionGroup" id="FilediffActions">
-    <child>
-      <object class="GtkAction" id="SaveAll">
-        <property name="label" translatable="yes">Save A_ll</property>
-        <property name="tooltip" translatable="yes">Save all files in the current comparison</property>
-        <signal name="activate" handler="on_save_all_activate" swapped="no"/>
-      </object>
-      <accelerator key="L" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
-    </child>
-    <child>
-      <object class="GtkAction" id="Revert">
-        <property name="tooltip" translatable="yes">Revert files to their saved versions</property>
-        <property name="stock_id">gtk-revert-to-saved</property>
-        <signal name="activate" handler="on_revert_activate" swapped="no"/>
-      </object>
-    </child>
     <child>
       <object class="GtkAction" id="SplitAdd">
         <property name="label" translatable="yes">Add Synchronization Point</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]