ViewManager/ViewManager.py

branch
Py2 comp.
changeset 2677
3d4277929fb3
parent 2525
8b507a9a2d40
parent 2673
c62efb5f2d79
child 2791
a9577f248f04
equal deleted inserted replaced
2670:e60ea6cb8e11 2677:3d4277929fb3
1173 """ left of the cursor.</p>""" 1173 """ left of the cursor.</p>"""
1174 )) 1174 ))
1175 self.calltipsAct.triggered[()].connect(self.__editShowCallTips) 1175 self.calltipsAct.triggered[()].connect(self.__editShowCallTips)
1176 self.editActions.append(self.calltipsAct) 1176 self.editActions.append(self.calltipsAct)
1177 1177
1178 self.sortAct = E5Action(QApplication.translate('ViewManager', 'Sort'),
1179 QApplication.translate('ViewManager', 'Sort'),
1180 QKeySequence(QApplication.translate('ViewManager',
1181 "Ctrl+Alt+S", "Edit|Sort")),
1182 0,
1183 self.editActGrp, 'vm_edit_sort')
1184 self.sortAct.setStatusTip(QApplication.translate('ViewManager',
1185 'Sort the lines containing the rectangular selection'))
1186 self.sortAct.setWhatsThis(QApplication.translate('ViewManager',
1187 """<b>Sort</b>"""
1188 """<p>Sort the lines spanned by a rectangular selection based on the"""
1189 """ selection ignoring leading and trailing whitespace.</p>"""
1190 ))
1191 self.sortAct.triggered[()].connect(self.__editSortSelectedLines)
1192 self.editActions.append(self.sortAct)
1193
1178 self.editActGrp.setEnabled(False) 1194 self.editActGrp.setEnabled(False)
1179 self.copyActGrp.setEnabled(False) 1195 self.copyActGrp.setEnabled(False)
1180 1196
1181 #################################################################### 1197 ####################################################################
1182 ## Below follow the actions for QScintilla standard commands. 1198 ## Below follow the actions for QScintilla standard commands.
1786 act = E5Action(QApplication.translate('ViewManager', 'Toggle insert/overtype'), 1802 act = E5Action(QApplication.translate('ViewManager', 'Toggle insert/overtype'),
1787 QApplication.translate('ViewManager', 'Toggle insert/overtype'), 1803 QApplication.translate('ViewManager', 'Toggle insert/overtype'),
1788 QKeySequence(QApplication.translate('ViewManager', 'Ins')), 0, 1804 QKeySequence(QApplication.translate('ViewManager', 'Ins')), 0,
1789 self.editorActGrp, 'vm_edit_toggle_insert_overtype') 1805 self.editorActGrp, 'vm_edit_toggle_insert_overtype')
1790 self.esm.setMapping(act, QsciScintilla.SCI_EDITTOGGLEOVERTYPE) 1806 self.esm.setMapping(act, QsciScintilla.SCI_EDITTOGGLEOVERTYPE)
1791 act.triggered[()].connect(self.esm.map)
1792 self.editActions.append(act)
1793
1794 act = E5Action(QApplication.translate('ViewManager',
1795 'Convert selection to lower case'),
1796 QApplication.translate('ViewManager',
1797 'Convert selection to lower case'),
1798 QKeySequence(QApplication.translate('ViewManager', 'Alt+Shift+U')),
1799 0,
1800 self.editorActGrp, 'vm_edit_convert_selection_lower')
1801 self.esm.setMapping(act, QsciScintilla.SCI_LOWERCASE)
1802 act.triggered[()].connect(self.esm.map)
1803 self.editActions.append(act)
1804
1805 act = E5Action(QApplication.translate('ViewManager',
1806 'Convert selection to upper case'),
1807 QApplication.translate('ViewManager',
1808 'Convert selection to upper case'),
1809 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Shift+U')),
1810 0,
1811 self.editorActGrp, 'vm_edit_convert_selection_upper')
1812 self.esm.setMapping(act, QsciScintilla.SCI_UPPERCASE)
1813 act.triggered[()].connect(self.esm.map) 1807 act.triggered[()].connect(self.esm.map)
1814 self.editActions.append(act) 1808 self.editActions.append(act)
1815 1809
1816 act = E5Action(QApplication.translate('ViewManager', 1810 act = E5Action(QApplication.translate('ViewManager',
1817 'Move to end of display line'), 1811 'Move to end of display line'),
2288 self.esm.setMapping(act, QsciScintilla.SCI_MOVESELECTEDLINESDOWN) 2282 self.esm.setMapping(act, QsciScintilla.SCI_MOVESELECTEDLINESDOWN)
2289 act.triggered[()].connect(self.esm.map) 2283 act.triggered[()].connect(self.esm.map)
2290 self.editActions.append(act) 2284 self.editActions.append(act)
2291 2285
2292 self.editorActGrp.setEnabled(False) 2286 self.editorActGrp.setEnabled(False)
2287
2288 self.editLowerCaseAct = E5Action(QApplication.translate('ViewManager',
2289 'Convert selection to lower case'),
2290 QApplication.translate('ViewManager',
2291 'Convert selection to lower case'),
2292 QKeySequence(QApplication.translate('ViewManager', 'Alt+Shift+U')),
2293 0,
2294 self.editActGrp, 'vm_edit_convert_selection_lower')
2295 self.esm.setMapping(self.editLowerCaseAct, QsciScintilla.SCI_LOWERCASE)
2296 self.editLowerCaseAct.triggered[()].connect(self.esm.map)
2297 self.editActions.append(self.editLowerCaseAct)
2298
2299 self.editUpperCaseAct = E5Action(QApplication.translate('ViewManager',
2300 'Convert selection to upper case'),
2301 QApplication.translate('ViewManager',
2302 'Convert selection to upper case'),
2303 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Shift+U')),
2304 0,
2305 self.editActGrp, 'vm_edit_convert_selection_upper')
2306 self.esm.setMapping(self.editUpperCaseAct, QsciScintilla.SCI_UPPERCASE)
2307 self.editUpperCaseAct.triggered[()].connect(self.esm.map)
2308 self.editActions.append(self.editUpperCaseAct)
2293 2309
2294 def initEditMenu(self): 2310 def initEditMenu(self):
2295 """ 2311 """
2296 Public method to create the Edit menu 2312 Public method to create the Edit menu
2297 2313
2345 menu.addAction(self.commentAct) 2361 menu.addAction(self.commentAct)
2346 menu.addAction(self.uncommentAct) 2362 menu.addAction(self.uncommentAct)
2347 menu.addAction(self.toggleCommentAct) 2363 menu.addAction(self.toggleCommentAct)
2348 menu.addAction(self.streamCommentAct) 2364 menu.addAction(self.streamCommentAct)
2349 menu.addAction(self.boxCommentAct) 2365 menu.addAction(self.boxCommentAct)
2366 menu.addSeparator()
2367 menu.addAction(self.editUpperCaseAct)
2368 menu.addAction(self.editLowerCaseAct)
2369 menu.addAction(self.sortAct)
2350 menu.addSeparator() 2370 menu.addSeparator()
2351 menu.addMenu(autocompletionMenu) 2371 menu.addMenu(autocompletionMenu)
2352 menu.addSeparator() 2372 menu.addSeparator()
2353 menu.addMenu(searchMenu) 2373 menu.addMenu(searchMenu)
2354 menu.addSeparator() 2374 menu.addSeparator()
3615 self.__editProjectPWL) 3635 self.__editProjectPWL)
3616 self.__editProjectPelAct = self.__editSpellingMenu.addAction( 3636 self.__editProjectPelAct = self.__editSpellingMenu.addAction(
3617 QApplication.translate('ViewManager', "Project Exception List"), 3637 QApplication.translate('ViewManager', "Project Exception List"),
3618 self.__editProjectPEL) 3638 self.__editProjectPEL)
3619 self.__editSpellingMenu.addSeparator() 3639 self.__editSpellingMenu.addSeparator()
3620 self.__editSpellingMenu.addAction( 3640 self.__editUserPwlAct = self.__editSpellingMenu.addAction(
3621 QApplication.translate('ViewManager', "User Word List"), 3641 QApplication.translate('ViewManager', "User Word List"),
3622 self.__editUserPWL) 3642 self.__editUserPWL)
3623 self.__editSpellingMenu.addAction( 3643 self.__editUserPelAct = self.__editSpellingMenu.addAction(
3624 QApplication.translate('ViewManager', "User Exception List"), 3644 QApplication.translate('ViewManager', "User Exception List"),
3625 self.__editUserPEL) 3645 self.__editUserPEL)
3626 self.__editProjectPwlAct.setEnabled(False) 3646 self.__editSpellingMenu.aboutToShow.connect(self.__showEditSpellingMenu)
3627 self.__editProjectPelAct.setEnabled(False)
3628 3647
3629 menu.addAction(self.spellCheckAct) 3648 menu.addAction(self.spellCheckAct)
3630 menu.addAction(self.autoSpellCheckAct) 3649 menu.addAction(self.autoSpellCheckAct)
3631 menu.addMenu(self.__editSpellingMenu) 3650 menu.addMenu(self.__editSpellingMenu)
3632 menu.addSeparator() 3651 menu.addSeparator()
3882 editor.languageChanged.connect(self.__editorConfigChanged) 3901 editor.languageChanged.connect(self.__editorConfigChanged)
3883 editor.eolChanged.connect(self.__editorConfigChanged) 3902 editor.eolChanged.connect(self.__editorConfigChanged)
3884 editor.encodingChanged.connect(self.__editorConfigChanged) 3903 editor.encodingChanged.connect(self.__editorConfigChanged)
3885 editor.selectionChanged.connect(self.__searchWidget.selectionChanged) 3904 editor.selectionChanged.connect(self.__searchWidget.selectionChanged)
3886 editor.selectionChanged.connect(self.__replaceWidget.selectionChanged) 3905 editor.selectionChanged.connect(self.__replaceWidget.selectionChanged)
3906 editor.selectionChanged.connect(self.__editorSelectionChanged)
3887 editor.lastEditPositionAvailable.connect(self.__lastEditPositionAvailable) 3907 editor.lastEditPositionAvailable.connect(self.__lastEditPositionAvailable)
3888 editor.zoomValueChanged.connect(self.zoomValueChanged) 3908 editor.zoomValueChanged.connect(self.zoomValueChanged)
3889 3909
3890 editor.languageChanged.connect(lambda: self.editorLanguageChanged.emit(editor)) 3910 editor.languageChanged.connect(lambda: self.editorLanguageChanged.emit(editor))
3891 editor.textChanged.connect(lambda: self.editorTextChanged.emit(editor)) 3911 editor.textChanged.connect(lambda: self.editorTextChanged.emit(editor))
5407 5427
5408 ################################################################## 5428 ##################################################################
5409 ## Below are the action methods for the spell checking functions 5429 ## Below are the action methods for the spell checking functions
5410 ################################################################## 5430 ##################################################################
5411 5431
5432 def __showEditSpellingMenu(self):
5433 """
5434 Private method to set up the edit dictionaries menu.
5435 """
5436 proj = e5App().getObject("Project")
5437 projetOpen = proj.isOpen()
5438 pwl = e5App().getObject("Project").getProjectDictionaries()[0]
5439 self.__editProjectPwlAct.setEnabled(projetOpen and bool(pwl))
5440 pel = e5App().getObject("Project").getProjectDictionaries()[1]
5441 self.__editProjectPelAct.setEnabled(projetOpen and bool(pel))
5442
5443 from QScintilla.SpellChecker import SpellChecker
5444 pwl = SpellChecker.getUserDictionaryPath()
5445 self.__editUserPwlAct.setEnabled(bool(pwl))
5446 pel = SpellChecker.getUserDictionaryPath(True)
5447 self.__editUserPelAct.setEnabled(bool(pel))
5448
5412 def __setAutoSpellChecking(self): 5449 def __setAutoSpellChecking(self):
5413 """ 5450 """
5414 Private slot to set the automatic spell checking of all editors. 5451 Private slot to set the automatic spell checking of all editors.
5415 """ 5452 """
5416 enabled = self.autoSpellCheckAct.isChecked() 5453 enabled = self.autoSpellCheckAct.isChecked()
5429 def __editProjectPWL(self): 5466 def __editProjectPWL(self):
5430 """ 5467 """
5431 Private slot to edit the project word list. 5468 Private slot to edit the project word list.
5432 """ 5469 """
5433 pwl = e5App().getObject("Project").getProjectDictionaries()[0] 5470 pwl = e5App().getObject("Project").getProjectDictionaries()[0]
5434 if pwl: 5471 self.__editSpellingDictionary(pwl)
5435 self.__editSpellingDictionary(pwl)
5436 else:
5437 E5MessageBox.warning(self.ui,
5438 QApplication.translate('ViewManager', "Edit Project Word List"),
5439 QApplication.translate('ViewManager',
5440 """No word list defined for the current project."""))
5441 5472
5442 def __editProjectPEL(self): 5473 def __editProjectPEL(self):
5443 """ 5474 """
5444 Private slot to edit the project exception list. 5475 Private slot to edit the project exception list.
5445 """ 5476 """
5446 pel = e5App().getObject("Project").getProjectDictionaries()[1] 5477 pel = e5App().getObject("Project").getProjectDictionaries()[1]
5447 if pel: 5478 self.__editSpellingDictionary(pel)
5448 self.__editSpellingDictionary(pel)
5449 else:
5450 E5MessageBox.warning(self.ui,
5451 QApplication.translate('ViewManager', "Edit Project Exception List"),
5452 QApplication.translate('ViewManager',
5453 """No exception list defined for the current project."""))
5454 5479
5455 def __editUserPWL(self): 5480 def __editUserPWL(self):
5456 """ 5481 """
5457 Private slot to edit the user word list. 5482 Private slot to edit the user word list.
5458 """ 5483 """
5723 self.gotoNextDefAct.setEnabled(True) 5748 self.gotoNextDefAct.setEnabled(True)
5724 else: 5749 else:
5725 self.gotoPreviousDefAct.setEnabled(False) 5750 self.gotoPreviousDefAct.setEnabled(False)
5726 self.gotoNextDefAct.setEnabled(False) 5751 self.gotoNextDefAct.setEnabled(False)
5727 5752
5753 self.sortAct.setEnabled(editor.selectionIsRectangle())
5754 enable = editor.hasSelection()
5755 self.editUpperCaseAct.setEnabled(enable)
5756 self.editLowerCaseAct.setEnabled(enable)
5757
5728 if setSb: 5758 if setSb:
5729 line, pos = editor.getCursorPosition() 5759 line, pos = editor.getCursorPosition()
5730 enc = editor.getEncoding() 5760 enc = editor.getEncoding()
5731 lang = editor.getLanguage() 5761 lang = editor.getLanguage()
5732 eol = editor.getEolIndicator() 5762 eol = editor.getEolIndicator()
5878 eol = editor.getEolIndicator() 5908 eol = editor.getEolIndicator()
5879 zoom = editor.getZoom() 5909 zoom = editor.getZoom()
5880 self.__setSbFile( 5910 self.__setSbFile(
5881 fn, line + 1, pos, encoding=enc, language=lang, eol=eol, zoom=zoom) 5911 fn, line + 1, pos, encoding=enc, language=lang, eol=eol, zoom=zoom)
5882 self._checkActions(editor, False) 5912 self._checkActions(editor, False)
5913
5914 def __editorSelectionChanged(self):
5915 """
5916 Private slot to handle changes of the current editors selection.
5917 """
5918 editor = self.sender()
5919 if editor:
5920 self.sortAct.setEnabled(editor.selectionIsRectangle())
5921 enable = editor.hasSelection()
5922 self.editUpperCaseAct.setEnabled(enable)
5923 self.editLowerCaseAct.setEnabled(enable)
5924 else:
5925 self.sortAct.setEnabled(False)
5926
5927 def __editSortSelectedLines(self):
5928 """
5929 Private slot to sort the selected lines.
5930 """
5931 editor = self.activeWindow()
5932 if editor:
5933 editor.sortLines()
5883 5934
5884 ################################################################## 5935 ##################################################################
5885 ## Below are protected utility methods 5936 ## Below are protected utility methods
5886 ################################################################## 5937 ##################################################################
5887 5938

eric ide

mercurial