[meld/ui-next] vcview: Move all VC-specific actions to GActions



commit 2d463108b80f1014906b94203c8e646054366346
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Feb 24 08:56:11 2019 +1000

    vcview: Move all VC-specific actions to GActions
    
    This is the last of the vcview GtkUIManager actions. The UI here is
    clearly still extremely placeholder, but in service of getting the
    actions into GActions it's good enough.
    
    The popup menu still needs to be reinstated, but that's a task for later
    when the remainder of the menu conversion has been done.

 data/ui/vcview-ui.xml       |  52 ------------
 meld/accelerators.py        |   1 +
 meld/melddoc.py             |  12 ++-
 meld/resources/ui/vcview.ui | 196 +++++++++++++++++++++++++++-----------------
 meld/vcview.py              |  64 +++++++--------
 5 files changed, 159 insertions(+), 166 deletions(-)
---
diff --git a/meld/accelerators.py b/meld/accelerators.py
index 3d67f919..ce06b0d1 100644
--- a/meld/accelerators.py
+++ b/meld/accelerators.py
@@ -12,6 +12,7 @@ def register_accels(app: Gtk.Application):
         ('view.save-all', '<Primary><Shift>L'),
         ('view.save-as', '<Primary><Shift>S'),
         ('view.undo', '<Primary>Z'),
+        ('view.vc-commit', '<Primary>M'),
         ('view.vc-console-visible', 'F9'),
         ('win.close', '<Primary>W'),
         ("win.stop", "Escape"),
diff --git a/meld/melddoc.py b/meld/melddoc.py
index cdcc4737..51d5ef7f 100644
--- a/meld/melddoc.py
+++ b/meld/melddoc.py
@@ -201,8 +201,10 @@ class MeldDoc(LabeledObjectMixin, GObject.GObject):
     def on_container_switch_in_event(self, uimanager, window):
         """Called when the container app switches to this tab.
         """
-        self.ui_merge_id = uimanager.add_ui_from_file(self.ui_file)
-        uimanager.insert_action_group(self.actiongroup, -1)
+        if hasattr(self, 'ui_file'):
+            self.ui_merge_id = uimanager.add_ui_from_file(self.ui_file)
+        if hasattr(self, 'actiongroup'):
+            uimanager.insert_action_group(self.actiongroup, -1)
         self.popup_menu = uimanager.get_widget("/Popup")
         action_groups = uimanager.get_action_groups()
         self.main_actiongroup = [
@@ -218,8 +220,10 @@ class MeldDoc(LabeledObjectMixin, GObject.GObject):
     def on_container_switch_out_event(self, uimanager, window):
         """Called when the container app switches away from this tab.
         """
-        uimanager.remove_action_group(self.actiongroup)
-        uimanager.remove_ui(self.ui_merge_id)
+        if hasattr(self, 'actiongroup'):
+            uimanager.remove_action_group(self.actiongroup)
+        if hasattr(self, 'ui_file'):
+            uimanager.remove_ui(self.ui_merge_id)
         self.main_actiongroup = None
         self.popup_menu = None
         self.ui_merge_id = None
diff --git a/meld/resources/ui/vcview.ui b/meld/resources/ui/vcview.ui
index 9fd5354a..0e2643c3 100644
--- a/meld/resources/ui/vcview.ui
+++ b/meld/resources/ui/vcview.ui
@@ -1,82 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
+  <!-- interface-requires gtk+ 3.20 -->
   <!-- interface-requires meld.ui.gladesupport 0.0 -->
-  <object class="GtkActionGroup" id="VcviewActions">
-    <child>
-      <object class="GtkAction" id="VcCompare">
-        <property name="label" translatable="yes">_Compare</property>
-        <property name="tooltip" translatable="yes">Compare selected files</property>
-        <property name="stock_id">gtk-dialog-info</property>
-        <property name="is_important">True</property>
-        <signal name="activate" handler="on_button_diff_clicked" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkAction" id="VcCommit">
-        <property name="label" translatable="yes">Co_mmit…</property>
-        <property name="tooltip" translatable="yes">Commit changes to version control</property>
-        <property name="icon_name">vc-commit-24</property>
-        <signal name="activate" handler="on_button_commit_clicked" swapped="no"/>
-      </object>
-      <accelerator key="M" modifiers="GDK_CONTROL_MASK"/>
-    </child>
-    <child>
-      <object class="GtkAction" id="VcUpdate">
-        <property name="label" translatable="yes">_Update</property>
-        <property name="tooltip" translatable="yes">Update working copy from version control</property>
-        <property name="icon_name">vc-update-24</property>
-        <signal name="activate" handler="on_button_update_clicked" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkAction" id="VcPush">
-        <property name="label" translatable="yes">_Push</property>
-        <property name="tooltip" translatable="yes">Push local changes to remote</property>
-        <property name="icon_name">vc-push-24</property>
-        <signal name="activate" handler="on_button_push_clicked" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkAction" id="VcAdd">
-        <property name="label" translatable="yes">_Add</property>
-        <property name="tooltip" translatable="yes">Add to version control</property>
-        <property name="icon_name">vc-add-24</property>
-        <signal name="activate" handler="on_button_add_clicked" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkAction" id="VcRemove">
-        <property name="label" translatable="yes">_Remove</property>
-        <property name="tooltip" translatable="yes">Remove from version control</property>
-        <property name="icon_name">vc-remove-24</property>
-        <signal name="activate" handler="on_button_remove_clicked" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkAction" id="VcResolved">
-        <property name="label" translatable="yes">Mar_k as Resolved</property>
-        <property name="tooltip" translatable="yes">Mark as resolved in version control</property>
-        <property name="icon_name">vc-resolve-24</property>
-        <signal name="activate" handler="on_button_resolved_clicked" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkAction" id="VcRevert">
-        <property name="label" translatable="yes">Re_vert</property>
-        <property name="tooltip" translatable="yes">Revert working copy to original state</property>
-        <property name="stock_id">gtk-revert-to-saved</property>
-        <signal name="activate" handler="on_button_revert_clicked" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkAction" id="VcDeleteLocally">
-        <property name="tooltip" translatable="yes">Delete from working copy</property>
-        <property name="stock_id">gtk-delete</property>
-        <signal name="activate" handler="on_button_delete_clicked" swapped="no"/>
-      </object>
-    </child>
-  </object>
   <template class="VcView" parent="GtkVBox">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -105,7 +30,7 @@
             </child>
           </object>
           <packing>
-            <property name="expand">True</property>
+            <property name="expand">False</property>
           </packing>
         </child>
         <child>
@@ -134,6 +59,123 @@
             <property name="expand">False</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkToolItem">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkModelButton">
+                <property name="visible">True</property>
+                <property name="action_name">view.compare</property>
+                <property name="text" translatable="yes">Compare</property>
+                <property name="tooltip_text" translatable="yes">Compare selected files</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkToolItem">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkModelButton">
+                <property name="visible">True</property>
+                <property name="action_name">view.vc-commit</property>
+                <property name="text" translatable="yes">Commit…</property>
+                <property name="tooltip_text" translatable="yes">Commit changes to version control</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkToolItem">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkModelButton">
+                <property name="visible">True</property>
+                <property name="action_name">view.vc-update</property>
+                <property name="text" translatable="yes">Update</property>
+                <property name="tooltip_text" translatable="yes">Update working copy from version 
control</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkToolItem">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkModelButton">
+                <property name="visible">True</property>
+                <property name="action_name">view.vc-push</property>
+                <property name="text" translatable="yes">Push</property>
+                <property name="tooltip_text" translatable="yes">Push local changes to remote</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkToolItem">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkModelButton">
+                <property name="visible">True</property>
+                <property name="action_name">view.vc-add</property>
+                <property name="text" translatable="yes">Add</property>
+                <property name="tooltip_text" translatable="yes">Add to version control</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkToolItem">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkModelButton">
+                <property name="visible">True</property>
+                <property name="action_name">view.vc-remove</property>
+                <property name="text" translatable="yes">Remove</property>
+                <property name="tooltip_text" translatable="yes">Remove from version control</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkToolItem">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkModelButton">
+                <property name="visible">True</property>
+                <property name="action_name">view.vc-resolve</property>
+                <property name="text" translatable="yes">Mark as Resolved</property>
+                <property name="tooltip_text" translatable="yes">Mark as resolved in version 
control</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkToolItem">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkModelButton">
+                <property name="visible">True</property>
+                <property name="action_name">view.vc-revert</property>
+                <property name="text" translatable="yes">Revert</property>
+                <property name="tooltip_text" translatable="yes">Revert working copy to original 
state</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkToolItem">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkModelButton">
+                <property name="visible">True</property>
+                <property name="action_name">view.vc-delete-locally</property>
+                <property name="text" translatable="yes">Delete</property>
+                <property name="tooltip_text" translatable="yes">Delete from working copy</property>
+              </object>
+            </child>
+          </object>
+        </child>
       </object>
       <packing>
         <property name="expand">False</property>
diff --git a/meld/vcview.py b/meld/vcview.py
index 87353f77..7e1a78ff 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -173,7 +173,6 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
     status_renderer = Template.Child()
     treeview = Template.Child()
     vc_console_vpaned = Template.Child()
-    VcviewActions = Template.Child()
 
     def __init__(self):
         super().__init__()
@@ -189,10 +188,6 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
         self.init_template()
         bind_settings(self)
 
-        self.ui_file = ui_file("vcview-ui.xml")
-        self.actiongroup = self.VcviewActions
-        self.actiongroup.set_translation_domain("meld")
-
         # Set up per-view action group for top-level menu insertion
         self.view_action_group = Gio.SimpleActionGroup()
 
@@ -205,10 +200,19 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
 
         # Manually handle GAction additions
         actions = (
+            ('compare', self.action_diff),
             ('next-change', self.action_next_change),
             ('open-external', self.action_open_external),
             ('previous-change', self.action_previous_change),
             ('refresh', self.action_refresh),
+            ('vc-add', self.action_add),
+            ('vc-commit', self.action_commit),
+            ('vc-delete-locally', self.action_delete),
+            ('vc-push', self.action_push),
+            ('vc-remove', self.action_remove),
+            ('vc-resolve', self.action_resolved),
+            ('vc-revert', self.action_revert),
+            ('vc-update', self.action_update),
         )
         for name, callback in actions:
             action = Gio.SimpleAction.new(name, None)
@@ -580,18 +584,18 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
 
         valid_actions = self.vc.get_valid_actions(path_states)
         action_sensitivity = {
-            "VcCompare": 'compare' in valid_actions,
-            "VcCommit": 'commit' in valid_actions,
-            "VcUpdate": 'update' in valid_actions,
-            "VcPush": 'push' in valid_actions,
-            "VcAdd": 'add' in valid_actions,
-            "VcResolved": 'resolve' in valid_actions,
-            "VcRemove": 'remove' in valid_actions,
-            "VcRevert": 'revert' in valid_actions,
-            "VcDeleteLocally": bool(paths) and self.vc.root not in paths,
+            'compare': 'compare' in valid_actions,
+            'vc-add': 'add' in valid_actions,
+            'vc-commit': 'commit' in valid_actions,
+            'vc-delete-locally': bool(paths) and self.vc.root not in paths,
+            'vc-push': 'push' in valid_actions,
+            'vc-remove': 'remove' in valid_actions,
+            'vc-resolve': 'resolve' in valid_actions,
+            'vc-revert': 'revert' in valid_actions,
+            'vc-update': 'update' in valid_actions,
         }
         for action, sensitivity in action_sensitivity.items():
-            self.actiongroup.get_action(action).set_sensitive(sensitivity)
+            self.set_action_enabled(action, sensitivity)
 
     def _get_selected_files(self):
         model, rows = self.treeview.get_selection().get_selected_rows()
@@ -679,29 +683,24 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
         for it in self._command_iter(command, files, refresh, working_dir):
             pass
 
-    @Template.Callback()
-    def on_button_update_clicked(self, obj):
+    def action_update(self, *args):
         self.vc.update(self.runner)
 
-    @Template.Callback()
-    def on_button_push_clicked(self, obj):
+    def action_push(self, *args):
         response = PushDialog(self).run()
         if response == Gtk.ResponseType.OK:
             self.vc.push(self.runner)
 
-    @Template.Callback()
-    def on_button_commit_clicked(self, obj):
+    def action_commit(self, *args):
         response, commit_msg = CommitDialog(self).run()
         if response == Gtk.ResponseType.OK:
             self.vc.commit(
                 self.runner, self._get_selected_files(), commit_msg)
 
-    @Template.Callback()
-    def on_button_add_clicked(self, obj):
+    def action_add(self, *args):
         self.vc.add(self.runner, self._get_selected_files())
 
-    @Template.Callback()
-    def on_button_remove_clicked(self, obj):
+    def action_remove(self, *args):
         selected = self._get_selected_files()
         if any(os.path.isdir(p) for p in selected):
             # TODO: Improve and reuse this dialog for the non-VC delete action
@@ -724,16 +723,13 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
 
         self.vc.remove(self.runner, selected)
 
-    @Template.Callback()
-    def on_button_resolved_clicked(self, obj):
+    def action_resolved(self, *args):
         self.vc.resolve(self.runner, self._get_selected_files())
 
-    @Template.Callback()
-    def on_button_revert_clicked(self, obj):
+    def action_revert(self, *args):
         self.vc.revert(self.runner, self._get_selected_files())
 
-    @Template.Callback()
-    def on_button_delete_clicked(self, obj):
+    def action_delete(self, *args):
         files = self._get_selected_files()
         for name in files:
             gfile = Gio.File.new_for_path(name)
@@ -751,8 +747,10 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
         workdir = os.path.dirname(os.path.commonprefix(files))
         self.refresh_partial(workdir)
 
-    @Template.Callback()
-    def on_button_diff_clicked(self, obj):
+    def action_diff(self, *args):
+        # TODO: Review the compare/diff action. It doesn't really add much
+        # over activate, since the folder compare doesn't work and hasn't
+        # for... a long time.
         files = self._get_selected_files()
         for f in files:
             self.run_diff(f)


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