ViewManager/ViewManager.py

changeset 2589
a51b0c113ed7
parent 2484
105d78ba97d4
child 2593
a2df0adce985
diff -r 28a8bbfe097b -r a51b0c113ed7 ViewManager/ViewManager.py
--- a/ViewManager/ViewManager.py	Mon Apr 15 20:27:07 2013 +0200
+++ b/ViewManager/ViewManager.py	Wed Apr 17 19:58:24 2013 +0200
@@ -1173,6 +1173,22 @@
         self.calltipsAct.triggered[()].connect(self.__editShowCallTips)
         self.editActions.append(self.calltipsAct)
         
+        self.sortAct = E5Action(QApplication.translate('ViewManager', 'Sort'),
+                QApplication.translate('ViewManager', 'Sort'),
+                QKeySequence(QApplication.translate('ViewManager',
+                    "Ctrl+Alt+S", "Edit|Sort")),
+                0,
+                self.editActGrp, 'vm_edit_sort')
+        self.sortAct.setStatusTip(QApplication.translate('ViewManager',
+            'Sort the lines containing the rectangular selection'))
+        self.sortAct.setWhatsThis(QApplication.translate('ViewManager',
+            """<b>Sort</b>"""
+            """<p>Sort the lines spanned by a rectangular selection based on the"""
+            """ selection ignoring leading and trailing whitespace.</p>"""
+        ))
+        self.sortAct.triggered[()].connect(self.__editSortSelectedLines)
+        self.editActions.append(self.sortAct)
+        
         self.editActGrp.setEnabled(False)
         self.copyActGrp.setEnabled(False)
         
@@ -2350,6 +2366,8 @@
         menu.addSeparator()
         menu.addMenu(searchMenu)
         menu.addSeparator()
+        menu.addAction(self.sortAct)
+        menu.addSeparator()
         menu.addAction(self.gotoAct)
         menu.addAction(self.gotoBraceAct)
         menu.addAction(self.gotoLastEditAct)
@@ -3882,6 +3900,7 @@
         editor.encodingChanged.connect(self.__editorConfigChanged)
         editor.selectionChanged.connect(self.__searchWidget.selectionChanged)
         editor.selectionChanged.connect(self.__replaceWidget.selectionChanged)
+        editor.selectionChanged.connect(self.__editorSelectionChanged)
         editor.lastEditPositionAvailable.connect(self.__lastEditPositionAvailable)
         editor.zoomValueChanged.connect(self.zoomValueChanged)
         
@@ -5723,6 +5742,8 @@
                 self.gotoPreviousDefAct.setEnabled(False)
                 self.gotoNextDefAct.setEnabled(False)
             
+            self.sortAct.setEnabled(editor.selectionIsRectangle())
+            
             if setSb:
                 line, pos = editor.getCursorPosition()
                 enc = editor.getEncoding()
@@ -5879,6 +5900,24 @@
             fn, line + 1, pos, encoding=enc, language=lang, eol=eol, zoom=zoom)
         self._checkActions(editor, False)
     
+    def __editorSelectionChanged(self):
+        """
+        Private slot to handle changes of the current editors selection.
+        """
+        editor = self.sender()
+        if editor:
+            self.sortAct.setEnabled(editor.selectionIsRectangle())
+        else:
+            self.sortAct.setEnabled(False)
+    
+    def __editSortSelectedLines(self):
+        """
+        Private slot to sort the selected lines.
+        """
+        editor = self.activeWindow()
+        if editor:
+            editor.sortLines()
+    
     ##################################################################
     ## Below are protected utility methods
     ##################################################################

eric ide

mercurial