[meld/pathlabel: 9/10] filediff: Add open-folder and copy-path actions to file context menu




commit 3f7eb648d141baa3692f8557156ecf4925d33673
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Jan 10 12:28:48 2021 +1000

    filediff: Add open-folder and copy-path actions to file context menu
    
    This is copying these actions from the PathLabel widget. Ideally, they'd
    re-use the same actions, but focus issues make that a bit tricky, and
    they're small enough that duplicating the code is only a minor crime.

 meld/filediff.py                    | 23 +++++++++++++++++++++++
 meld/resources/ui/filediff-menus.ui | 11 +++++++++++
 2 files changed, 34 insertions(+)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index e7de5c5b..eef5a40f 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -314,6 +314,7 @@ class FileDiff(Gtk.VBox, MeldDoc):
             ('add-sync-point', self.add_sync_point),
             ('clear-sync-point', self.clear_sync_points),
             ('copy', self.action_copy),
+            ('copy-full-path', self.action_copy_full_path),
             ('cut', self.action_cut),
             ('file-previous-conflict', self.action_previous_conflict),
             ('file-next-conflict', self.action_next_conflict),
@@ -338,6 +339,7 @@ class FileDiff(Gtk.VBox, MeldDoc):
             ('next-change', self.action_next_change),
             ('next-pane', self.action_next_pane),
             ('open-external', self.action_open_external),
+            ('open-folder', self.action_open_folder),
             ('paste', self.action_paste),
             ('previous-change', self.action_previous_change),
             ('previous-pane', self.action_prev_pane),
@@ -1283,6 +1285,27 @@ class FileDiff(Gtk.VBox, MeldDoc):
     def on_can_redo(self, undosequence, can_redo):
         self.set_action_enabled('redo', can_redo)
 
+    @with_focused_pane
+    def action_copy_full_path(self, pane, *args):
+        gfile = self.textbuffer[pane].data.gfile
+        if not gfile:
+            return
+
+        path = gfile.get_path() or gfile.get_uri()
+        clip = Gtk.Clipboard.get_default(Gdk.Display.get_default())
+        clip.set_text(path, -1)
+        clip.store()
+
+    @with_focused_pane
+    def action_open_folder(self, pane, *args):
+        gfile = self.textbuffer[pane].data.gfile
+        if not gfile:
+            return
+
+        parent = gfile.get_parent()
+        if parent:
+            open_files_external(gfiles=[parent])
+
     @with_focused_pane
     def action_open_external(self, pane, *args):
         if not self.textbuffer[pane].data.gfile:
diff --git a/meld/resources/ui/filediff-menus.ui b/meld/resources/ui/filediff-menus.ui
index 0d37a2c3..288250f2 100644
--- a/meld/resources/ui/filediff-menus.ui
+++ b/meld/resources/ui/filediff-menus.ui
@@ -48,6 +48,17 @@
         <attribute name="action">view.paste</attribute>
       </item>
     </section>
+    <section>
+      <attribute name="id">file-section</attribute>
+      <item>
+        <attribute name="label" translatable="yes">Open Containing Folder</attribute>
+        <attribute name="action">view.open-folder</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Copy Full Path</attribute>
+        <attribute name="action">view.copy-full-path</attribute>
+      </item>
+    </section>
     <section>
       <attribute name="id">syncpoint-section</attribute>
       <item>


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