Pārlūkot izejas kodu

fix copy-to-clipboard key binding on macOS (#393)

* fixes trac issue https://trac.osgeo.org/grass/ticket/3008,
binding cmd+c to copy-to-clipboard in output console and
python shell

* fixes trac issue https://trac.osgeo.org/grass/ticket/3592,
binding cmd+c to copy-to-clipboard import/export dialogs
nilason 5 gadi atpakaļ
vecāks
revīzija
69148c8c2a
2 mainītis faili ar 29 papildinājumiem un 0 dzēšanām
  1. 14 0
      gui/wxpython/lmgr/frame.py
  2. 15 0
      gui/wxpython/modules/import_export.py

+ 14 - 0
gui/wxpython/lmgr/frame.py

@@ -250,6 +250,13 @@ class GMFrame(wx.Frame):
 
         show_menu_errors(menu_errors)
 
+        # Enable copying to clipboard with cmd+c from console and python shell on macOS
+        # (default key binding will clear the console), trac #3008
+        if sys.platform == "darwin":
+            self.Bind(wx.EVT_MENU, self.OnCopyToClipboard, id=wx.ID_COPY)
+            self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord("C"), wx.ID_COPY)])
+            self.SetAcceleratorTable(self.accel_tbl)
+
         # start with layer manager on top
         if self.currentPage:
             self.GetMapDisplay().Raise()
@@ -708,6 +715,13 @@ class GMFrame(wx.Frame):
                     return False
         return True
 
+    def OnCopyToClipboard(self, event):
+        """Copy selected text in shell to the clipboard"""
+        try:
+            wx.Window.FindFocus().Copy()
+        except:
+            pass
+
     def _switchPageHandler(self, event, notification):
         self._switchPage(notification=notification)
         event.Skip()

+ 15 - 0
gui/wxpython/modules/import_export.py

@@ -21,6 +21,7 @@ This program is free software under the GNU General Public License
 """
 
 import os
+import sys
 
 import wx
 from core import globalvar
@@ -137,6 +138,13 @@ class ImportDialog(wx.Dialog):
 
         self.createSettingsPage()
 
+        # Enable copying to clipboard with cmd+c from dialog on macOS
+        # (default key binding will close the dialog), trac #3592
+        if sys.platform == "darwin":
+            self.Bind(wx.EVT_MENU, self.OnCopyToClipboard, id=wx.ID_COPY)
+            self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord("C"), wx.ID_COPY)])
+            self.SetAcceleratorTable(self.accel_tbl)
+
     def createSettingsPage(self):
 
         self._blackList = {
@@ -310,6 +318,13 @@ class ImportDialog(wx.Dialog):
         """Do what has to be done after importing"""
         pass
 
+    def OnCopyToClipboard(self, event):
+        """Copy selected text in dialog to the clipboard"""
+        try:
+            wx.Window.FindFocus().Copy()
+        except:
+            pass
+
     def _getLayersToReprojetion(self, projMatch_idx, grassName_idx):
         """If there are layers with different projection from loation projection,
            show dialog to user to explicitly select layers which will be reprojected..."""