[meld/ui-next] Remove custom cut/copy/paste actions



commit 17903440ab7108b9137babc503a4c81ba05c29fb
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Mar 1 08:27:59 2019 +1000

    Remove custom cut/copy/paste actions
    
    Correctly managing the behaviour of these actions isn't that hard - we
    already did a pretty good job in the MeldWindow callbacks - but managing
    their sensitivity is an actual nightmare. In order to do this correctly,
    you need to hook in to focus changes, then connect to selection-changed
    and editability-changed signals (which GtkEditable doesn't even have)
    and then manage those signal connections so that you can clean them up
    when your focus changes.
    
    I started doing all of the above, and then realised a few things...
    
    Firstly, UIs that I'm using as a model don't really expose these actions
    as top-level user-visible items anyway. They're expected to be used via
    shortcuts or context menus.
    
    Secondly, the context menu handlers for the widgets where this is
    relevant already handle all of the sensitivity logic, and can easily do
    so because they only need to run the sensitivity checks when the context
    menu is invoked.
    
    So all I'm doing here is removing the custom actions, and we'll see how
    we go with just relying on the built-in behaviours of GtkEditable and
    GtkSourceView. Maybe we'll need to reinstate some of this, but maybe
    we'll get away without.

 data/ui/filediff-ui.xml |  8 --------
 data/ui/meldapp-ui.xml  |  4 ----
 meld/filediff.py        | 19 -------------------
 meld/meldwindow.py      | 31 ++-----------------------------
 4 files changed, 2 insertions(+), 60 deletions(-)
---
diff --git a/data/ui/filediff-ui.xml b/data/ui/filediff-ui.xml
index 02d015d5..28679a08 100644
--- a/data/ui/filediff-ui.xml
+++ b/data/ui/filediff-ui.xml
@@ -22,12 +22,4 @@
       </placeholder>
     </menu>
   </menubar>
-
-  <popup name="Popup">
-    <menuitem action="Cut" />
-    <menuitem action="Copy" />
-    <menuitem action="Paste" />
-  </popup>
-
 </ui>
-
diff --git a/data/ui/meldapp-ui.xml b/data/ui/meldapp-ui.xml
index 34f0711d..7fbde953 100644
--- a/data/ui/meldapp-ui.xml
+++ b/data/ui/meldapp-ui.xml
@@ -1,10 +1,6 @@
 <ui>
   <menubar name="Menubar">
     <menu action="EditMenu">
-      <menuitem action="Cut"/>
-      <menuitem action="Copy"/>
-      <menuitem action="Paste"/>
-      <separator/>
       <menuitem action="Find"/>
       <menuitem action="FindNext"/>
       <menuitem action="FindPrevious"/>
diff --git a/meld/filediff.py b/meld/filediff.py
index be32d75f..d58f98dc 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -320,8 +320,6 @@ class FileDiff(Gtk.VBox, MeldDoc):
 
         for buf in self.textbuffer:
             buf.undo_sequence = self.undosequence
-            buf.connect("notify::has-selection",
-                        self.update_text_actions_sensitivity)
             buf.data.file_changed_signal.connect(self.notify_file_changed)
 
         self.ui_file = ui_file("filediff-ui.xml")
@@ -953,7 +951,6 @@ class FileDiff(Gtk.VBox, MeldDoc):
         self._set_save_action_sensitivity()
         self._set_merge_action_sensitivity()
         self._set_external_action_sensitivity()
-        self.update_text_actions_sensitivity()
 
     @Template.Callback()
     def on_textview_focus_out_event(self, view, event):
@@ -1149,22 +1146,6 @@ class FileDiff(Gtk.VBox, MeldDoc):
         path = self.textbuffer[pane].data.gfile.get_path()
         self._open_files([path], line)
 
-    def update_text_actions_sensitivity(self, *args):
-        widget = self.focus_pane
-        if not widget:
-            cut, copy, paste = False, False, False
-        else:
-            cut = copy = widget.get_buffer().get_has_selection()
-            # Ideally, this would check whether the clipboard included
-            # something pasteable. However, there is no changed signal.
-            # widget.get_clipboard(
-            #    Gdk.SELECTION_CLIPBOARD).wait_is_text_available()
-            paste = widget.get_editable()
-        if self.main_actiongroup:
-            for action, sens in zip(
-                    ("Cut", "Copy", "Paste"), (cut, copy, paste)):
-                self.main_actiongroup.get_action(action).set_sensitive(sens)
-
     @with_focused_pane
     def get_selected_text(self, pane):
         """Returns selected text of active pane"""
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index fdc1f735..b1ea0913 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -64,12 +64,6 @@ class MeldWindow(Gtk.ApplicationWindow):
 
         actions = (
             ("EditMenu", None, _("_Edit")),
-            ("Cut", Gtk.STOCK_CUT, None, None, _("Cut the selection"),
-                self.on_menu_cut_activate),
-            ("Copy", Gtk.STOCK_COPY, None, None, _("Copy the selection"),
-                self.on_menu_copy_activate),
-            ("Paste", Gtk.STOCK_PASTE, None, None, _("Paste the clipboard"),
-                self.on_menu_paste_activate),
             ("Find", Gtk.STOCK_FIND, _("Find…"), None, _("Search for text"),
                 self.on_menu_find_activate),
             ("FindNext", None, _("Find Ne_xt"), "<Primary>G",
@@ -243,7 +237,7 @@ class MeldWindow(Gtk.ApplicationWindow):
 
         self.lookup_action('close').set_enabled(bool(page))
         if not isinstance(page, MeldDoc):
-            for action in ("Cut", "Copy", "Paste",
+            for action in (
                            "Find", "FindNext", "FindPrevious", "Replace",
                            "GoToLine"):
                 self.actiongroup.get_action(action).set_sensitive(False)
@@ -251,7 +245,7 @@ class MeldWindow(Gtk.ApplicationWindow):
             for action in ("Find",):
                 self.actiongroup.get_action(action).set_sensitive(True)
             is_filediff = isinstance(page, FileDiff)
-            for action in ("Cut", "Copy", "Paste", "FindNext", "FindPrevious",
+            for action in ("FindNext", "FindPrevious",
                            "Replace", "GoToLine"):
                 self.actiongroup.get_action(action).set_sensitive(is_filediff)
 
@@ -314,27 +308,6 @@ class MeldWindow(Gtk.ApplicationWindow):
     def on_menu_go_to_line_activate(self, *extra):
         self.current_doc().on_go_to_line_activate()
 
-    def on_menu_copy_activate(self, *extra):
-        widget = self.get_focus()
-        if isinstance(widget, Gtk.Editable):
-            widget.copy_clipboard()
-        elif isinstance(widget, Gtk.TextView):
-            widget.emit("copy-clipboard")
-
-    def on_menu_cut_activate(self, *extra):
-        widget = self.get_focus()
-        if isinstance(widget, Gtk.Editable):
-            widget.cut_clipboard()
-        elif isinstance(widget, Gtk.TextView):
-            widget.emit("cut-clipboard")
-
-    def on_menu_paste_activate(self, *extra):
-        widget = self.get_focus()
-        if isinstance(widget, Gtk.Editable):
-            widget.paste_clipboard()
-        elif isinstance(widget, Gtk.TextView):
-            widget.emit("paste-clipboard")
-
     def on_action_fullscreen_change_state(self, action, state):
         window_state = self.get_window().get_state()
         is_full = window_state & Gdk.WindowState.FULLSCREEN


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