1# -*- coding: utf-8 -*- 2 3# Copyright (c) 2002 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> 4# 5 6""" 7Module implementing the view manager base class. 8""" 9 10import re 11import os 12import contextlib 13 14from PyQt5.QtCore import ( 15 pyqtSignal, pyqtSlot, Qt, QSignalMapper, QTimer, QFileInfo, QPoint, 16 QCoreApplication 17) 18from PyQt5.QtGui import QKeySequence, QPixmap 19from PyQt5.QtWidgets import ( 20 QToolBar, QDialog, QApplication, QMenu, QWidget 21) 22from PyQt5.Qsci import QsciScintilla 23 24from E5Gui.E5Application import e5App 25from E5Gui import E5FileDialog, E5MessageBox 26 27from Globals import recentNameFiles, isMacPlatform 28 29import Preferences 30 31from QScintilla.Editor import Editor 32 33import Utilities 34 35import UI.PixmapCache 36import UI.Config 37 38from E5Gui.E5Action import E5Action, createActionGroup 39 40 41class ViewManager(QWidget): 42 """ 43 Base class inherited by all specific view manager classes. 44 45 It defines the interface to be implemented by specific 46 view manager classes and all common methods. 47 48 @signal changeCaption(str) emitted if a change of the caption is necessary 49 @signal editorChanged(str) emitted when the current editor has changed 50 @signal editorChangedEd(Editor) emitted when the current editor has changed 51 @signal lastEditorClosed() emitted after the last editor window was closed 52 @signal editorOpened(str) emitted after an editor window was opened 53 @signal editorOpenedEd(Editor) emitted after an editor window was opened 54 @signal editorClosed(str) emitted just before an editor window gets closed 55 @signal editorClosedEd(Editor) emitted just before an editor window gets 56 closed 57 @signal editorRenamed(str) emitted after an editor was renamed 58 @signal editorRenamedEd(Editor) emitted after an editor was renamed 59 @signal editorSaved(str) emitted after an editor window was saved 60 @signal editorSavedEd(Editor) emitted after an editor window was saved 61 @signal checkActions(Editor) emitted when some actions should be checked 62 for their status 63 @signal cursorChanged(Editor) emitted after the cursor position of the 64 active window has changed 65 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled 66 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled 67 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled 68 @signal previewStateChanged(bool) emitted to signal a change in the 69 preview state 70 @signal astViewerStateChanged(bool) emitted to signal a change in the 71 AST viewer state 72 @signal disViewerStateChanged(bool) emitted to signal a change in the 73 DIS viewer state 74 @signal editorLanguageChanged(Editor) emitted to signal a change of an 75 editor's language 76 @signal editorTextChanged(Editor) emitted to signal a change of an 77 editor's text 78 @signal editorLineChanged(str,int) emitted to signal a change of an 79 editor's current line (line is given one based) 80 @signal editorLineChangedEd(Editor,int) emitted to signal a change of an 81 editor's current line (line is given one based) 82 @signal editorDoubleClickedEd(Editor, position, buttons) emitted to signal 83 a mouse double click in an editor 84 """ 85 changeCaption = pyqtSignal(str) 86 editorChanged = pyqtSignal(str) 87 editorChangedEd = pyqtSignal(Editor) 88 lastEditorClosed = pyqtSignal() 89 editorOpened = pyqtSignal(str) 90 editorOpenedEd = pyqtSignal(Editor) 91 editorClosed = pyqtSignal(str) 92 editorClosedEd = pyqtSignal(Editor) 93 editorRenamed = pyqtSignal(str) 94 editorRenamedEd = pyqtSignal(Editor) 95 editorSaved = pyqtSignal(str) 96 editorSavedEd = pyqtSignal(Editor) 97 checkActions = pyqtSignal(Editor) 98 cursorChanged = pyqtSignal(Editor) 99 breakpointToggled = pyqtSignal(Editor) 100 bookmarkToggled = pyqtSignal(Editor) 101 syntaxerrorToggled = pyqtSignal(Editor) 102 previewStateChanged = pyqtSignal(bool) 103 astViewerStateChanged = pyqtSignal(bool) 104 disViewerStateChanged = pyqtSignal(bool) 105 editorLanguageChanged = pyqtSignal(Editor) 106 editorTextChanged = pyqtSignal(Editor) 107 editorLineChanged = pyqtSignal(str, int) 108 editorLineChangedEd = pyqtSignal(Editor, int) 109 editorDoubleClickedEd = pyqtSignal(Editor, QPoint, int) 110 111 def __init__(self): 112 """ 113 Constructor 114 """ 115 super().__init__() 116 117 # initialize the instance variables 118 self.editors = [] 119 self.currentEditor = None 120 self.untitledCount = 0 121 self.srHistory = { 122 "search": [], 123 "replace": [] 124 } 125 self.editorsCheckFocusIn = True 126 127 self.recent = [] 128 self.__loadRecent() 129 130 self.bookmarked = [] 131 bs = Preferences.Prefs.settings.value("Bookmarked/Sources") 132 if bs is not None: 133 self.bookmarked = bs 134 135 # initialize the autosave timer 136 self.autosaveInterval = Preferences.getEditor("AutosaveInterval") 137 self.autosaveTimer = QTimer(self) 138 self.autosaveTimer.setObjectName("AutosaveTimer") 139 self.autosaveTimer.setSingleShot(True) 140 self.autosaveTimer.timeout.connect(self.__autosave) 141 142 # initialize the APIs manager 143 from QScintilla.APIsManager import APIsManager 144 self.apisManager = APIsManager(parent=self) 145 146 self.__cooperationClient = None 147 148 self.__lastFocusWidget = None 149 150 def setReferences(self, ui, dbs): 151 """ 152 Public method to set some references needed later on. 153 154 @param ui reference to the main user interface 155 @param dbs reference to the debug server object 156 """ 157 from QScintilla.SearchReplaceWidget import SearchReplaceSlidingWidget 158 159 self.ui = ui 160 self.dbs = dbs 161 162 self.__searchWidget = SearchReplaceSlidingWidget(False, self, ui) 163 self.__replaceWidget = SearchReplaceSlidingWidget(True, self, ui) 164 165 self.checkActions.connect(self.__searchWidget.updateSelectionCheckBox) 166 self.checkActions.connect(self.__replaceWidget.updateSelectionCheckBox) 167 168 def searchWidget(self): 169 """ 170 Public method to get a reference to the search widget. 171 172 @return reference to the search widget (SearchReplaceSlidingWidget) 173 """ 174 return self.__searchWidget 175 176 def replaceWidget(self): 177 """ 178 Public method to get a reference to the replace widget. 179 180 @return reference to the replace widget (SearchReplaceSlidingWidget) 181 """ 182 return self.__replaceWidget 183 184 def __loadRecent(self): 185 """ 186 Private method to load the recently opened filenames. 187 """ 188 self.recent = [] 189 Preferences.Prefs.rsettings.sync() 190 rs = Preferences.Prefs.rsettings.value(recentNameFiles) 191 if rs is not None: 192 for f in Preferences.toList(rs): 193 if QFileInfo(f).exists(): 194 self.recent.append(f) 195 196 def __saveRecent(self): 197 """ 198 Private method to save the list of recently opened filenames. 199 """ 200 Preferences.Prefs.rsettings.setValue(recentNameFiles, self.recent) 201 Preferences.Prefs.rsettings.sync() 202 203 def getMostRecent(self): 204 """ 205 Public method to get the most recently opened file. 206 207 @return path of the most recently opened file (string) 208 """ 209 if len(self.recent): 210 return self.recent[0] 211 else: 212 return None 213 214 def setSbInfo(self, sbLine, sbPos, sbWritable, sbEncoding, sbLanguage, 215 sbEol, sbZoom): 216 """ 217 Public method to transfer statusbar info from the user interface to 218 viewmanager. 219 220 @param sbLine reference to the line number part of the statusbar 221 (QLabel) 222 @param sbPos reference to the character position part of the statusbar 223 (QLabel) 224 @param sbWritable reference to the writability indicator part of 225 the statusbar (QLabel) 226 @param sbEncoding reference to the encoding indicator part of the 227 statusbar (QLabel) 228 @param sbLanguage reference to the language indicator part of the 229 statusbar (QLabel) 230 @param sbEol reference to the eol indicator part of the statusbar 231 (QLabel) 232 @param sbZoom reference to the zoom widget (E5ZoomWidget) 233 """ 234 self.sbLine = sbLine 235 self.sbPos = sbPos 236 self.sbWritable = sbWritable 237 self.sbEnc = sbEncoding 238 self.sbLang = sbLanguage 239 self.sbEol = sbEol 240 self.sbZoom = sbZoom 241 self.sbZoom.valueChanged.connect(self.__zoomTo) 242 self.__setSbFile(zoom=0) 243 244 self.sbLang.clicked.connect(self.__showLanguagesMenu) 245 self.sbEol.clicked.connect(self.__showEolMenu) 246 self.sbEnc.clicked.connect(self.__showEncodingsMenu) 247 248 ################################################################## 249 ## Below are menu handling methods for status bar labels 250 ################################################################## 251 252 def __showLanguagesMenu(self, pos): 253 """ 254 Private slot to show the Languages menu of the current editor. 255 256 @param pos position the menu should be shown at (QPoint) 257 """ 258 aw = self.activeWindow() 259 if aw is not None: 260 menu = aw.getMenu("Languages") 261 if menu is not None: 262 menu.exec(pos) 263 264 def __showEolMenu(self, pos): 265 """ 266 Private slot to show the EOL menu of the current editor. 267 268 @param pos position the menu should be shown at (QPoint) 269 """ 270 aw = self.activeWindow() 271 if aw is not None: 272 menu = aw.getMenu("Eol") 273 if menu is not None: 274 menu.exec(pos) 275 276 def __showEncodingsMenu(self, pos): 277 """ 278 Private slot to show the Encodings menu of the current editor. 279 280 @param pos position the menu should be shown at (QPoint) 281 """ 282 aw = self.activeWindow() 283 if aw is not None: 284 menu = aw.getMenu("Encodings") 285 if menu is not None: 286 menu.exec(pos) 287 288 ########################################################################### 289 ## methods below need to be implemented by a subclass 290 ########################################################################### 291 292 def canCascade(self): 293 """ 294 Public method to signal if cascading of managed windows is available. 295 296 @return flag indicating cascading of windows is available 297 @exception RuntimeError Not implemented 298 """ 299 raise RuntimeError('Not implemented') 300 301 return False 302 303 def canTile(self): 304 """ 305 Public method to signal if tiling of managed windows is available. 306 307 @return flag indicating tiling of windows is available 308 @exception RuntimeError Not implemented 309 """ 310 raise RuntimeError('Not implemented') 311 312 return False 313 314 def tile(self): 315 """ 316 Public method to tile the managed windows. 317 318 @exception RuntimeError Not implemented 319 """ 320 raise RuntimeError('Not implemented') 321 322 def cascade(self): 323 """ 324 Public method to cascade the managed windows. 325 326 @exception RuntimeError Not implemented 327 """ 328 raise RuntimeError('Not implemented') 329 330 def activeWindow(self): 331 """ 332 Public method to return the active (i.e. current) window. 333 334 @return reference to the active editor 335 @exception RuntimeError Not implemented 336 """ 337 raise RuntimeError('Not implemented') 338 339 return None # __IGNORE_WARNING_M831__ 340 341 def _removeAllViews(self): 342 """ 343 Protected method to remove all views (i.e. windows). 344 345 @exception RuntimeError Not implemented 346 """ 347 raise RuntimeError('Not implemented') 348 349 def _removeView(self, win): 350 """ 351 Protected method to remove a view (i.e. window). 352 353 @param win editor window to be removed 354 @exception RuntimeError Not implemented 355 """ 356 raise RuntimeError('Not implemented') 357 358 def _addView(self, win, fn=None, noName="", addNext=False, indexes=None): 359 """ 360 Protected method to add a view (i.e. window). 361 362 @param win editor assembly to be added 363 @type EditorAssembly 364 @param fn filename of this editor 365 @type str 366 @param noName name to be used for an unnamed editor 367 @type str 368 @param addNext flag indicating to add the view next to the current 369 view 370 @type bool 371 @param indexes of the editor, first the split view index, second the 372 index within the view 373 @type tuple of two int 374 @exception RuntimeError Not implemented 375 """ 376 raise RuntimeError('Not implemented') 377 378 def _showView(self, win, fn=None): 379 """ 380 Protected method to show a view (i.e. window). 381 382 @param win editor assembly to be shown 383 @param fn filename of this editor 384 @exception RuntimeError Not implemented 385 """ 386 raise RuntimeError('Not implemented') 387 388 def showWindowMenu(self, windowMenu): 389 """ 390 Public method to set up the viewmanager part of the Window menu. 391 392 @param windowMenu reference to the window menu 393 @exception RuntimeError Not implemented 394 """ 395 raise RuntimeError('Not implemented') 396 397 def _initWindowActions(self): 398 """ 399 Protected method to define the user interface actions for window 400 handling. 401 402 @exception RuntimeError Not implemented 403 """ 404 raise RuntimeError('Not implemented') 405 406 def setEditorName(self, editor, newName): 407 """ 408 Public method to change the displayed name of the editor. 409 410 @param editor editor window to be changed 411 @param newName new name to be shown (string) 412 @exception RuntimeError Not implemented 413 """ 414 raise RuntimeError('Not implemented') 415 416 def _modificationStatusChanged(self, m, editor): 417 """ 418 Protected slot to handle the modificationStatusChanged signal. 419 420 @param m flag indicating the modification status (boolean) 421 @param editor editor window changed 422 @exception RuntimeError Not implemented 423 """ 424 raise RuntimeError('Not implemented') 425 426 def mainWidget(self): 427 """ 428 Public method to return a reference to the main Widget of a 429 specific view manager subclass. 430 431 @exception RuntimeError Not implemented 432 """ 433 raise RuntimeError('Not implemented') 434 435 ##################################################################### 436 ## methods above need to be implemented by a subclass 437 ##################################################################### 438 439 def canSplit(self): 440 """ 441 Public method to signal if splitting of the view is available. 442 443 @return flag indicating splitting of the view is available. 444 """ 445 return False 446 447 def addSplit(self): 448 """ 449 Public method used to split the current view. 450 """ 451 pass 452 453 @pyqtSlot() 454 def removeSplit(self, index=-1): 455 """ 456 Public method used to remove the current split view or a split view 457 by index. 458 459 @param index index of the split to be removed (-1 means to 460 delete the current split) 461 @type int 462 @return flag indicating successful deletion 463 @rtype bool 464 """ 465 return False 466 467 def splitCount(self): 468 """ 469 Public method to get the number of split views. 470 471 @return number of split views 472 @rtype int 473 """ 474 return 0 475 476 def setSplitCount(self, count): 477 """ 478 Public method to set the number of split views. 479 480 @param count number of split views 481 @type int 482 """ 483 pass 484 485 def getSplitOrientation(self): 486 """ 487 Public method to get the orientation of the split view. 488 489 @return orientation of the split (Qt.Orientation.Horizontal or 490 Qt.Orientation.Vertical) 491 """ 492 return Qt.Orientation.Vertical 493 494 def setSplitOrientation(self, orientation): 495 """ 496 Public method used to set the orientation of the split view. 497 498 @param orientation orientation of the split 499 (Qt.Orientation.Horizontal or Qt.Orientation.Vertical) 500 """ 501 pass 502 503 def nextSplit(self): 504 """ 505 Public slot used to move to the next split. 506 """ 507 pass 508 509 def prevSplit(self): 510 """ 511 Public slot used to move to the previous split. 512 """ 513 pass 514 515 def eventFilter(self, qobject, event): 516 """ 517 Public method called to filter an event. 518 519 @param qobject object, that generated the event (QObject) 520 @param event the event, that was generated by object (QEvent) 521 @return flag indicating if event was filtered out 522 """ 523 return False 524 525 ##################################################################### 526 ## methods above need to be implemented by a subclass, that supports 527 ## splitting of the viewmanager area. 528 ##################################################################### 529 530 def initActions(self): 531 """ 532 Public method defining the user interface actions. 533 """ 534 # list containing all edit actions 535 self.editActions = [] 536 537 # list containing all file actions 538 self.fileActions = [] 539 540 # list containing all search actions 541 self.searchActions = [] 542 543 # list containing all view actions 544 self.viewActions = [] 545 546 # list containing all window actions 547 self.windowActions = [] 548 549 # list containing all macro actions 550 self.macroActions = [] 551 552 # list containing all bookmark actions 553 self.bookmarkActions = [] 554 555 # list containing all spell checking actions 556 self.spellingActions = [] 557 558 self.__actions = { 559 "bookmark": self.bookmarkActions, 560 "edit": self.editActions, 561 "file": self.fileActions, 562 "macro": self.macroActions, 563 "search": self.searchActions, 564 "spelling": self.spellingActions, 565 "view": self.viewActions, 566 "window": self.windowActions, 567 } 568 569 self._initWindowActions() 570 self.__initFileActions() 571 self.__initEditActions() 572 self.__initSearchActions() 573 self.__initViewActions() 574 self.__initMacroActions() 575 self.__initBookmarkActions() 576 self.__initSpellingActions() 577 578 ################################################################## 579 ## Initialize the file related actions, file menu and toolbar 580 ################################################################## 581 582 def __initFileActions(self): 583 """ 584 Private method defining the user interface actions for file handling. 585 """ 586 self.newAct = E5Action( 587 QCoreApplication.translate('ViewManager', 'New'), 588 UI.PixmapCache.getIcon("new"), 589 QCoreApplication.translate('ViewManager', '&New'), 590 QKeySequence( 591 QCoreApplication.translate('ViewManager', "Ctrl+N", 592 "File|New")), 593 0, self, 'vm_file_new') 594 self.newAct.setStatusTip( 595 QCoreApplication.translate( 596 'ViewManager', 'Open an empty editor window')) 597 self.newAct.setWhatsThis(QCoreApplication.translate( 598 'ViewManager', 599 """<b>New</b>""" 600 """<p>An empty editor window will be created.</p>""" 601 )) 602 self.newAct.triggered.connect(self.newEditor) 603 self.fileActions.append(self.newAct) 604 605 self.openAct = E5Action( 606 QCoreApplication.translate('ViewManager', 'Open'), 607 UI.PixmapCache.getIcon("open"), 608 QCoreApplication.translate('ViewManager', '&Open...'), 609 QKeySequence( 610 QCoreApplication.translate('ViewManager', "Ctrl+O", 611 "File|Open")), 612 0, self, 'vm_file_open') 613 self.openAct.setStatusTip(QCoreApplication.translate( 614 'ViewManager', 'Open a file')) 615 self.openAct.setWhatsThis(QCoreApplication.translate( 616 'ViewManager', 617 """<b>Open a file</b>""" 618 """<p>You will be asked for the name of a file to be opened""" 619 """ in an editor window.</p>""" 620 )) 621 self.openAct.triggered.connect(self.__openFiles) 622 self.fileActions.append(self.openAct) 623 624 self.closeActGrp = createActionGroup(self) 625 626 self.closeAct = E5Action( 627 QCoreApplication.translate('ViewManager', 'Close'), 628 UI.PixmapCache.getIcon("closeEditor"), 629 QCoreApplication.translate('ViewManager', '&Close'), 630 QKeySequence( 631 QCoreApplication.translate('ViewManager', "Ctrl+W", 632 "File|Close")), 633 0, self.closeActGrp, 'vm_file_close') 634 self.closeAct.setStatusTip( 635 QCoreApplication.translate('ViewManager', 636 'Close the current window')) 637 self.closeAct.setWhatsThis(QCoreApplication.translate( 638 'ViewManager', 639 """<b>Close Window</b>""" 640 """<p>Close the current window.</p>""" 641 )) 642 self.closeAct.triggered.connect(self.closeCurrentWindow) 643 self.fileActions.append(self.closeAct) 644 645 self.closeAllAct = E5Action( 646 QCoreApplication.translate('ViewManager', 'Close All'), 647 QCoreApplication.translate('ViewManager', 'Clos&e All'), 648 0, 0, self.closeActGrp, 'vm_file_close_all') 649 self.closeAllAct.setStatusTip( 650 QCoreApplication.translate('ViewManager', 651 'Close all editor windows')) 652 self.closeAllAct.setWhatsThis(QCoreApplication.translate( 653 'ViewManager', 654 """<b>Close All Windows</b>""" 655 """<p>Close all editor windows.</p>""" 656 )) 657 self.closeAllAct.triggered.connect(self.closeAllWindows) 658 self.fileActions.append(self.closeAllAct) 659 660 self.closeActGrp.setEnabled(False) 661 662 self.saveActGrp = createActionGroup(self) 663 664 self.saveAct = E5Action( 665 QCoreApplication.translate('ViewManager', 'Save'), 666 UI.PixmapCache.getIcon("fileSave"), 667 QCoreApplication.translate('ViewManager', '&Save'), 668 QKeySequence(QCoreApplication.translate( 669 'ViewManager', "Ctrl+S", "File|Save")), 670 0, self.saveActGrp, 'vm_file_save') 671 self.saveAct.setStatusTip( 672 QCoreApplication.translate('ViewManager', 'Save the current file')) 673 self.saveAct.setWhatsThis(QCoreApplication.translate( 674 'ViewManager', 675 """<b>Save File</b>""" 676 """<p>Save the contents of current editor window.</p>""" 677 )) 678 self.saveAct.triggered.connect(self.saveCurrentEditor) 679 self.fileActions.append(self.saveAct) 680 681 self.saveAsAct = E5Action( 682 QCoreApplication.translate('ViewManager', 'Save as'), 683 UI.PixmapCache.getIcon("fileSaveAs"), 684 QCoreApplication.translate('ViewManager', 'Save &as...'), 685 QKeySequence(QCoreApplication.translate( 686 'ViewManager', "Shift+Ctrl+S", "File|Save As")), 687 0, self.saveActGrp, 'vm_file_save_as') 688 self.saveAsAct.setStatusTip(QCoreApplication.translate( 689 'ViewManager', 'Save the current file to a new one')) 690 self.saveAsAct.setWhatsThis(QCoreApplication.translate( 691 'ViewManager', 692 """<b>Save File as</b>""" 693 """<p>Save the contents of current editor window to a new file.""" 694 """ The file can be entered in a file selection dialog.</p>""" 695 )) 696 self.saveAsAct.triggered.connect(self.saveAsCurrentEditor) 697 self.fileActions.append(self.saveAsAct) 698 699 self.saveCopyAct = E5Action( 700 QCoreApplication.translate('ViewManager', 'Save Copy'), 701 UI.PixmapCache.getIcon("fileSaveCopy"), 702 QCoreApplication.translate('ViewManager', 'Save &Copy...'), 703 0, 0, self.saveActGrp, 'vm_file_save_copy') 704 self.saveCopyAct.setStatusTip(QCoreApplication.translate( 705 'ViewManager', 'Save a copy of the current file')) 706 self.saveCopyAct.setWhatsThis(QCoreApplication.translate( 707 'ViewManager', 708 """<b>Save Copy</b>""" 709 """<p>Save a copy of the contents of current editor window.""" 710 """ The file can be entered in a file selection dialog.</p>""" 711 )) 712 self.saveCopyAct.triggered.connect(self.saveCopyCurrentEditor) 713 self.fileActions.append(self.saveCopyAct) 714 715 self.saveAllAct = E5Action( 716 QCoreApplication.translate('ViewManager', 'Save all'), 717 UI.PixmapCache.getIcon("fileSaveAll"), 718 QCoreApplication.translate('ViewManager', 'Save a&ll'), 719 0, 0, self.saveActGrp, 'vm_file_save_all') 720 self.saveAllAct.setStatusTip(QCoreApplication.translate( 721 'ViewManager', 'Save all files')) 722 self.saveAllAct.setWhatsThis(QCoreApplication.translate( 723 'ViewManager', 724 """<b>Save All Files</b>""" 725 """<p>Save the contents of all editor windows.</p>""" 726 )) 727 self.saveAllAct.triggered.connect(self.saveAllEditors) 728 self.fileActions.append(self.saveAllAct) 729 730 self.saveActGrp.setEnabled(False) 731 732 self.printAct = E5Action( 733 QCoreApplication.translate('ViewManager', 'Print'), 734 UI.PixmapCache.getIcon("print"), 735 QCoreApplication.translate('ViewManager', '&Print'), 736 QKeySequence(QCoreApplication.translate( 737 'ViewManager', "Ctrl+P", "File|Print")), 738 0, self, 'vm_file_print') 739 self.printAct.setStatusTip(QCoreApplication.translate( 740 'ViewManager', 'Print the current file')) 741 self.printAct.setWhatsThis(QCoreApplication.translate( 742 'ViewManager', 743 """<b>Print File</b>""" 744 """<p>Print the contents of current editor window.</p>""" 745 )) 746 self.printAct.triggered.connect(self.printCurrentEditor) 747 self.printAct.setEnabled(False) 748 self.fileActions.append(self.printAct) 749 750 self.printPreviewAct = E5Action( 751 QCoreApplication.translate('ViewManager', 'Print Preview'), 752 UI.PixmapCache.getIcon("printPreview"), 753 QCoreApplication.translate('ViewManager', 'Print Preview'), 754 0, 0, self, 'vm_file_print_preview') 755 self.printPreviewAct.setStatusTip(QCoreApplication.translate( 756 'ViewManager', 'Print preview of the current file')) 757 self.printPreviewAct.setWhatsThis(QCoreApplication.translate( 758 'ViewManager', 759 """<b>Print Preview</b>""" 760 """<p>Print preview of the current editor window.</p>""" 761 )) 762 self.printPreviewAct.triggered.connect( 763 self.printPreviewCurrentEditor) 764 self.printPreviewAct.setEnabled(False) 765 self.fileActions.append(self.printPreviewAct) 766 767 self.findFileNameAct = E5Action( 768 QCoreApplication.translate('ViewManager', 'Search File'), 769 QCoreApplication.translate('ViewManager', 'Search &File...'), 770 QKeySequence(QCoreApplication.translate( 771 'ViewManager', "Alt+Ctrl+F", "File|Search File")), 772 0, self, 'vm_file_search_file') 773 self.findFileNameAct.setStatusTip(QCoreApplication.translate( 774 'ViewManager', 'Search for a file')) 775 self.findFileNameAct.setWhatsThis(QCoreApplication.translate( 776 'ViewManager', 777 """<b>Search File</b>""" 778 """<p>Search for a file.</p>""" 779 )) 780 self.findFileNameAct.triggered.connect(self.__findFileName) 781 self.fileActions.append(self.findFileNameAct) 782 783 def initFileMenu(self): 784 """ 785 Public method to create the File menu. 786 787 @return the generated menu 788 """ 789 menu = QMenu(QCoreApplication.translate('ViewManager', '&File'), 790 self.ui) 791 self.recentMenu = QMenu( 792 QCoreApplication.translate('ViewManager', 'Open &Recent Files'), 793 menu) 794 self.bookmarkedMenu = QMenu( 795 QCoreApplication.translate('ViewManager', 796 'Open &Bookmarked Files'), 797 menu) 798 self.exportersMenu = self.__initContextMenuExporters() 799 menu.setTearOffEnabled(True) 800 801 menu.addAction(self.newAct) 802 menu.addAction(self.openAct) 803 self.menuRecentAct = menu.addMenu(self.recentMenu) 804 menu.addMenu(self.bookmarkedMenu) 805 menu.addSeparator() 806 menu.addAction(self.closeAct) 807 menu.addAction(self.closeAllAct) 808 menu.addSeparator() 809 menu.addAction(self.findFileNameAct) 810 menu.addSeparator() 811 menu.addAction(self.saveAct) 812 menu.addAction(self.saveAsAct) 813 menu.addAction(self.saveCopyAct) 814 menu.addAction(self.saveAllAct) 815 self.exportersMenuAct = menu.addMenu(self.exportersMenu) 816 menu.addSeparator() 817 menu.addAction(self.printPreviewAct) 818 menu.addAction(self.printAct) 819 820 self.recentMenu.aboutToShow.connect(self.__showRecentMenu) 821 self.recentMenu.triggered.connect(self.__openSourceFile) 822 self.bookmarkedMenu.aboutToShow.connect(self.__showBookmarkedMenu) 823 self.bookmarkedMenu.triggered.connect(self.__openSourceFile) 824 menu.aboutToShow.connect(self.__showFileMenu) 825 826 self.exportersMenuAct.setEnabled(False) 827 828 return menu 829 830 def initFileToolbar(self, toolbarManager): 831 """ 832 Public method to create the File toolbar. 833 834 @param toolbarManager reference to a toolbar manager object 835 (E5ToolBarManager) 836 @return the generated toolbar 837 """ 838 tb = QToolBar(QCoreApplication.translate('ViewManager', 'File'), 839 self.ui) 840 tb.setIconSize(UI.Config.ToolBarIconSize) 841 tb.setObjectName("FileToolbar") 842 tb.setToolTip(QCoreApplication.translate('ViewManager', 'File')) 843 844 tb.addAction(self.newAct) 845 tb.addAction(self.openAct) 846 tb.addAction(self.closeAct) 847 tb.addSeparator() 848 tb.addAction(self.saveAct) 849 tb.addAction(self.saveAsAct) 850 tb.addAction(self.saveCopyAct) 851 tb.addAction(self.saveAllAct) 852 853 toolbarManager.addToolBar(tb, tb.windowTitle()) 854 toolbarManager.addAction(self.printPreviewAct, tb.windowTitle()) 855 toolbarManager.addAction(self.printAct, tb.windowTitle()) 856 857 return tb 858 859 def __initContextMenuExporters(self): 860 """ 861 Private method used to setup the Exporters sub menu. 862 863 @return reference to the generated menu (QMenu) 864 """ 865 menu = QMenu(QCoreApplication.translate('ViewManager', "Export as")) 866 867 import QScintilla.Exporters 868 supportedExporters = QScintilla.Exporters.getSupportedFormats() 869 exporters = sorted(list(supportedExporters.keys())) 870 for exporter in exporters: 871 act = menu.addAction(supportedExporters[exporter]) 872 act.setData(exporter) 873 874 menu.triggered.connect(self.__exportMenuTriggered) 875 876 return menu 877 878 ################################################################## 879 ## Initialize the edit related actions, edit menu and toolbar 880 ################################################################## 881 882 def __initEditActions(self): 883 """ 884 Private method defining the user interface actions for the edit 885 commands. 886 """ 887 self.editActGrp = createActionGroup(self) 888 889 self.undoAct = E5Action( 890 QCoreApplication.translate('ViewManager', 'Undo'), 891 UI.PixmapCache.getIcon("editUndo"), 892 QCoreApplication.translate('ViewManager', '&Undo'), 893 QKeySequence(QCoreApplication.translate( 894 'ViewManager', "Ctrl+Z", "Edit|Undo")), 895 QKeySequence(QCoreApplication.translate( 896 'ViewManager', "Alt+Backspace", "Edit|Undo")), 897 self.editActGrp, 'vm_edit_undo') 898 self.undoAct.setStatusTip(QCoreApplication.translate( 899 'ViewManager', 'Undo the last change')) 900 self.undoAct.setWhatsThis(QCoreApplication.translate( 901 'ViewManager', 902 """<b>Undo</b>""" 903 """<p>Undo the last change done in the current editor.</p>""" 904 )) 905 self.undoAct.triggered.connect(self.__editUndo) 906 self.editActions.append(self.undoAct) 907 908 self.redoAct = E5Action( 909 QCoreApplication.translate('ViewManager', 'Redo'), 910 UI.PixmapCache.getIcon("editRedo"), 911 QCoreApplication.translate('ViewManager', '&Redo'), 912 QKeySequence(QCoreApplication.translate( 913 'ViewManager', "Ctrl+Shift+Z", "Edit|Redo")), 914 0, 915 self.editActGrp, 'vm_edit_redo') 916 self.redoAct.setStatusTip(QCoreApplication.translate( 917 'ViewManager', 'Redo the last change')) 918 self.redoAct.setWhatsThis(QCoreApplication.translate( 919 'ViewManager', 920 """<b>Redo</b>""" 921 """<p>Redo the last change done in the current editor.</p>""" 922 )) 923 self.redoAct.triggered.connect(self.__editRedo) 924 self.editActions.append(self.redoAct) 925 926 self.revertAct = E5Action( 927 QCoreApplication.translate( 928 'ViewManager', 'Revert to last saved state'), 929 QCoreApplication.translate( 930 'ViewManager', 'Re&vert to last saved state'), 931 QKeySequence(QCoreApplication.translate( 932 'ViewManager', "Ctrl+Y", "Edit|Revert")), 933 0, 934 self.editActGrp, 'vm_edit_revert') 935 self.revertAct.setStatusTip(QCoreApplication.translate( 936 'ViewManager', 'Revert to last saved state')) 937 self.revertAct.setWhatsThis(QCoreApplication.translate( 938 'ViewManager', 939 """<b>Revert to last saved state</b>""" 940 """<p>Undo all changes up to the last saved state""" 941 """ of the current editor.</p>""" 942 )) 943 self.revertAct.triggered.connect(self.__editRevert) 944 self.editActions.append(self.revertAct) 945 946 self.copyActGrp = createActionGroup(self.editActGrp) 947 948 self.cutAct = E5Action( 949 QCoreApplication.translate('ViewManager', 'Cut'), 950 UI.PixmapCache.getIcon("editCut"), 951 QCoreApplication.translate('ViewManager', 'Cu&t'), 952 QKeySequence(QCoreApplication.translate( 953 'ViewManager', "Ctrl+X", "Edit|Cut")), 954 QKeySequence(QCoreApplication.translate( 955 'ViewManager', "Shift+Del", "Edit|Cut")), 956 self.copyActGrp, 'vm_edit_cut') 957 self.cutAct.setStatusTip(QCoreApplication.translate( 958 'ViewManager', 'Cut the selection')) 959 self.cutAct.setWhatsThis(QCoreApplication.translate( 960 'ViewManager', 961 """<b>Cut</b>""" 962 """<p>Cut the selected text of the current editor to the""" 963 """ clipboard.</p>""" 964 )) 965 self.cutAct.triggered.connect(self.__editCut) 966 self.editActions.append(self.cutAct) 967 968 self.copyAct = E5Action( 969 QCoreApplication.translate('ViewManager', 'Copy'), 970 UI.PixmapCache.getIcon("editCopy"), 971 QCoreApplication.translate('ViewManager', '&Copy'), 972 QKeySequence(QCoreApplication.translate( 973 'ViewManager', "Ctrl+C", "Edit|Copy")), 974 QKeySequence(QCoreApplication.translate( 975 'ViewManager', "Ctrl+Ins", "Edit|Copy")), 976 self.copyActGrp, 'vm_edit_copy') 977 self.copyAct.setStatusTip(QCoreApplication.translate( 978 'ViewManager', 'Copy the selection')) 979 self.copyAct.setWhatsThis(QCoreApplication.translate( 980 'ViewManager', 981 """<b>Copy</b>""" 982 """<p>Copy the selected text of the current editor to the""" 983 """ clipboard.</p>""" 984 )) 985 self.copyAct.triggered.connect(self.__editCopy) 986 self.editActions.append(self.copyAct) 987 988 self.pasteAct = E5Action( 989 QCoreApplication.translate('ViewManager', 'Paste'), 990 UI.PixmapCache.getIcon("editPaste"), 991 QCoreApplication.translate('ViewManager', '&Paste'), 992 QKeySequence(QCoreApplication.translate( 993 'ViewManager', "Ctrl+V", "Edit|Paste")), 994 QKeySequence(QCoreApplication.translate( 995 'ViewManager', "Shift+Ins", "Edit|Paste")), 996 self.copyActGrp, 'vm_edit_paste') 997 self.pasteAct.setStatusTip(QCoreApplication.translate( 998 'ViewManager', 'Paste the last cut/copied text')) 999 self.pasteAct.setWhatsThis(QCoreApplication.translate( 1000 'ViewManager', 1001 """<b>Paste</b>""" 1002 """<p>Paste the last cut/copied text from the clipboard to""" 1003 """ the current editor.</p>""" 1004 )) 1005 self.pasteAct.triggered.connect(self.__editPaste) 1006 self.editActions.append(self.pasteAct) 1007 1008 self.deleteAct = E5Action( 1009 QCoreApplication.translate('ViewManager', 'Clear'), 1010 UI.PixmapCache.getIcon("editDelete"), 1011 QCoreApplication.translate('ViewManager', 'Clear'), 1012 QKeySequence(QCoreApplication.translate( 1013 'ViewManager', "Alt+Shift+C", "Edit|Clear")), 1014 0, 1015 self.copyActGrp, 'vm_edit_clear') 1016 self.deleteAct.setStatusTip(QCoreApplication.translate( 1017 'ViewManager', 'Clear all text')) 1018 self.deleteAct.setWhatsThis(QCoreApplication.translate( 1019 'ViewManager', 1020 """<b>Clear</b>""" 1021 """<p>Delete all text of the current editor.</p>""" 1022 )) 1023 self.deleteAct.triggered.connect(self.__editDelete) 1024 self.editActions.append(self.deleteAct) 1025 1026 self.joinAct = E5Action( 1027 QCoreApplication.translate('ViewManager', 'Join Lines'), 1028 QCoreApplication.translate('ViewManager', 'Join Lines'), 1029 QKeySequence(QCoreApplication.translate( 1030 'ViewManager', "Ctrl+J", "Edit|Join Lines")), 1031 0, 1032 self.editActGrp, 'vm_edit_join_lines') 1033 self.joinAct.setStatusTip(QCoreApplication.translate( 1034 'ViewManager', 'Join Lines')) 1035 self.joinAct.setWhatsThis(QCoreApplication.translate( 1036 'ViewManager', 1037 """<b>Join Lines</b>""" 1038 """<p>Join the current and the next lines.</p>""" 1039 )) 1040 self.joinAct.triggered.connect(self.__editJoin) 1041 self.editActions.append(self.joinAct) 1042 1043 self.indentAct = E5Action( 1044 QCoreApplication.translate('ViewManager', 'Indent'), 1045 UI.PixmapCache.getIcon("editIndent"), 1046 QCoreApplication.translate('ViewManager', '&Indent'), 1047 QKeySequence(QCoreApplication.translate( 1048 'ViewManager', "Ctrl+I", "Edit|Indent")), 1049 0, 1050 self.editActGrp, 'vm_edit_indent') 1051 self.indentAct.setStatusTip(QCoreApplication.translate( 1052 'ViewManager', 'Indent line')) 1053 self.indentAct.setWhatsThis(QCoreApplication.translate( 1054 'ViewManager', 1055 """<b>Indent</b>""" 1056 """<p>Indents the current line or the lines of the""" 1057 """ selection by one level.</p>""" 1058 )) 1059 self.indentAct.triggered.connect(self.__editIndent) 1060 self.editActions.append(self.indentAct) 1061 1062 self.unindentAct = E5Action( 1063 QCoreApplication.translate('ViewManager', 'Unindent'), 1064 UI.PixmapCache.getIcon("editUnindent"), 1065 QCoreApplication.translate('ViewManager', 'U&nindent'), 1066 QKeySequence(QCoreApplication.translate( 1067 'ViewManager', "Ctrl+Shift+I", "Edit|Unindent")), 1068 0, 1069 self.editActGrp, 'vm_edit_unindent') 1070 self.unindentAct.setStatusTip(QCoreApplication.translate( 1071 'ViewManager', 'Unindent line')) 1072 self.unindentAct.setWhatsThis(QCoreApplication.translate( 1073 'ViewManager', 1074 """<b>Unindent</b>""" 1075 """<p>Unindents the current line or the lines of the""" 1076 """ selection by one level.</p>""" 1077 )) 1078 self.unindentAct.triggered.connect(self.__editUnindent) 1079 self.editActions.append(self.unindentAct) 1080 1081 self.smartIndentAct = E5Action( 1082 QCoreApplication.translate('ViewManager', 'Smart indent'), 1083 UI.PixmapCache.getIcon("editSmartIndent"), 1084 QCoreApplication.translate('ViewManager', 'Smart indent'), 1085 0, 0, 1086 self.editActGrp, 'vm_edit_smart_indent') 1087 self.smartIndentAct.setStatusTip(QCoreApplication.translate( 1088 'ViewManager', 'Smart indent Line or Selection')) 1089 self.smartIndentAct.setWhatsThis(QCoreApplication.translate( 1090 'ViewManager', 1091 """<b>Smart indent</b>""" 1092 """<p>Indents the current line or the lines of the""" 1093 """ current selection smartly.</p>""" 1094 )) 1095 self.smartIndentAct.triggered.connect(self.__editSmartIndent) 1096 self.editActions.append(self.smartIndentAct) 1097 1098 self.commentAct = E5Action( 1099 QCoreApplication.translate('ViewManager', 'Comment'), 1100 UI.PixmapCache.getIcon("editComment"), 1101 QCoreApplication.translate('ViewManager', 'C&omment'), 1102 QKeySequence(QCoreApplication.translate( 1103 'ViewManager', "Ctrl+M", "Edit|Comment")), 1104 0, 1105 self.editActGrp, 'vm_edit_comment') 1106 self.commentAct.setStatusTip(QCoreApplication.translate( 1107 'ViewManager', 'Comment Line or Selection')) 1108 self.commentAct.setWhatsThis(QCoreApplication.translate( 1109 'ViewManager', 1110 """<b>Comment</b>""" 1111 """<p>Comments the current line or the lines of the""" 1112 """ current selection.</p>""" 1113 )) 1114 self.commentAct.triggered.connect(self.__editComment) 1115 self.editActions.append(self.commentAct) 1116 1117 self.uncommentAct = E5Action( 1118 QCoreApplication.translate('ViewManager', 'Uncomment'), 1119 UI.PixmapCache.getIcon("editUncomment"), 1120 QCoreApplication.translate('ViewManager', 'Unco&mment'), 1121 QKeySequence(QCoreApplication.translate( 1122 'ViewManager', "Alt+Ctrl+M", "Edit|Uncomment")), 1123 0, 1124 self.editActGrp, 'vm_edit_uncomment') 1125 self.uncommentAct.setStatusTip(QCoreApplication.translate( 1126 'ViewManager', 'Uncomment Line or Selection')) 1127 self.uncommentAct.setWhatsThis(QCoreApplication.translate( 1128 'ViewManager', 1129 """<b>Uncomment</b>""" 1130 """<p>Uncomments the current line or the lines of the""" 1131 """ current selection.</p>""" 1132 )) 1133 self.uncommentAct.triggered.connect(self.__editUncomment) 1134 self.editActions.append(self.uncommentAct) 1135 1136 self.toggleCommentAct = E5Action( 1137 QCoreApplication.translate('ViewManager', 'Toggle Comment'), 1138 UI.PixmapCache.getIcon("editToggleComment"), 1139 QCoreApplication.translate('ViewManager', 'Toggle Comment'), 1140 QKeySequence(QCoreApplication.translate( 1141 'ViewManager', "Ctrl+Shift+M", "Edit|Toggle Comment")), 1142 0, 1143 self.editActGrp, 'vm_edit_toggle_comment') 1144 self.toggleCommentAct.setStatusTip(QCoreApplication.translate( 1145 'ViewManager', 1146 'Toggle the comment of the current line, selection or' 1147 ' comment block')) 1148 self.toggleCommentAct.setWhatsThis(QCoreApplication.translate( 1149 'ViewManager', 1150 """<b>Toggle Comment</b>""" 1151 """<p>If the current line does not start with a block comment,""" 1152 """ the current line or selection is commented. If it is already""" 1153 """ commented, this comment block is uncommented. </p>""" 1154 )) 1155 self.toggleCommentAct.triggered.connect(self.__editToggleComment) 1156 self.editActions.append(self.toggleCommentAct) 1157 1158 self.streamCommentAct = E5Action( 1159 QCoreApplication.translate('ViewManager', 'Stream Comment'), 1160 QCoreApplication.translate('ViewManager', 'Stream Comment'), 1161 0, 0, 1162 self.editActGrp, 'vm_edit_stream_comment') 1163 self.streamCommentAct.setStatusTip(QCoreApplication.translate( 1164 'ViewManager', 1165 'Stream Comment Line or Selection')) 1166 self.streamCommentAct.setWhatsThis(QCoreApplication.translate( 1167 'ViewManager', 1168 """<b>Stream Comment</b>""" 1169 """<p>Stream comments the current line or the current""" 1170 """ selection.</p>""" 1171 )) 1172 self.streamCommentAct.triggered.connect(self.__editStreamComment) 1173 self.editActions.append(self.streamCommentAct) 1174 1175 self.boxCommentAct = E5Action( 1176 QCoreApplication.translate('ViewManager', 'Box Comment'), 1177 QCoreApplication.translate('ViewManager', 'Box Comment'), 1178 0, 0, 1179 self.editActGrp, 'vm_edit_box_comment') 1180 self.boxCommentAct.setStatusTip(QCoreApplication.translate( 1181 'ViewManager', 'Box Comment Line or Selection')) 1182 self.boxCommentAct.setWhatsThis(QCoreApplication.translate( 1183 'ViewManager', 1184 """<b>Box Comment</b>""" 1185 """<p>Box comments the current line or the lines of the""" 1186 """ current selection.</p>""" 1187 )) 1188 self.boxCommentAct.triggered.connect(self.__editBoxComment) 1189 self.editActions.append(self.boxCommentAct) 1190 1191 self.selectBraceAct = E5Action( 1192 QCoreApplication.translate('ViewManager', 'Select to brace'), 1193 QCoreApplication.translate('ViewManager', 'Select to &brace'), 1194 QKeySequence(QCoreApplication.translate( 1195 'ViewManager', "Ctrl+E", "Edit|Select to brace")), 1196 0, 1197 self.editActGrp, 'vm_edit_select_to_brace') 1198 self.selectBraceAct.setStatusTip(QCoreApplication.translate( 1199 'ViewManager', 'Select text to the matching brace')) 1200 self.selectBraceAct.setWhatsThis(QCoreApplication.translate( 1201 'ViewManager', 1202 """<b>Select to brace</b>""" 1203 """<p>Select text of the current editor to the matching""" 1204 """ brace.</p>""" 1205 )) 1206 self.selectBraceAct.triggered.connect(self.__editSelectBrace) 1207 self.editActions.append(self.selectBraceAct) 1208 1209 self.selectAllAct = E5Action( 1210 QCoreApplication.translate('ViewManager', 'Select all'), 1211 UI.PixmapCache.getIcon("editSelectAll"), 1212 QCoreApplication.translate('ViewManager', '&Select all'), 1213 QKeySequence(QCoreApplication.translate( 1214 'ViewManager', "Ctrl+A", "Edit|Select all")), 1215 0, 1216 self.editActGrp, 'vm_edit_select_all') 1217 self.selectAllAct.setStatusTip(QCoreApplication.translate( 1218 'ViewManager', 'Select all text')) 1219 self.selectAllAct.setWhatsThis(QCoreApplication.translate( 1220 'ViewManager', 1221 """<b>Select All</b>""" 1222 """<p>Select all text of the current editor.</p>""" 1223 )) 1224 self.selectAllAct.triggered.connect(self.__editSelectAll) 1225 self.editActions.append(self.selectAllAct) 1226 1227 self.deselectAllAct = E5Action( 1228 QCoreApplication.translate('ViewManager', 'Deselect all'), 1229 QCoreApplication.translate('ViewManager', '&Deselect all'), 1230 QKeySequence(QCoreApplication.translate( 1231 'ViewManager', "Alt+Ctrl+A", "Edit|Deselect all")), 1232 0, 1233 self.editActGrp, 'vm_edit_deselect_all') 1234 self.deselectAllAct.setStatusTip(QCoreApplication.translate( 1235 'ViewManager', 'Deselect all text')) 1236 self.deselectAllAct.setWhatsThis(QCoreApplication.translate( 1237 'ViewManager', 1238 """<b>Deselect All</b>""" 1239 """<p>Deselect all text of the current editor.</p>""" 1240 )) 1241 self.deselectAllAct.triggered.connect(self.__editDeselectAll) 1242 self.editActions.append(self.deselectAllAct) 1243 1244 self.convertEOLAct = E5Action( 1245 QCoreApplication.translate( 1246 'ViewManager', 'Convert Line End Characters'), 1247 QCoreApplication.translate( 1248 'ViewManager', 'Convert &Line End Characters'), 1249 0, 0, 1250 self.editActGrp, 'vm_edit_convert_eol') 1251 self.convertEOLAct.setStatusTip(QCoreApplication.translate( 1252 'ViewManager', 'Convert Line End Characters')) 1253 self.convertEOLAct.setWhatsThis(QCoreApplication.translate( 1254 'ViewManager', 1255 """<b>Convert Line End Characters</b>""" 1256 """<p>Convert the line end characters to the currently set""" 1257 """ type.</p>""" 1258 )) 1259 self.convertEOLAct.triggered.connect(self.__convertEOL) 1260 self.editActions.append(self.convertEOLAct) 1261 1262 self.shortenEmptyAct = E5Action( 1263 QCoreApplication.translate('ViewManager', 'Shorten empty lines'), 1264 QCoreApplication.translate('ViewManager', 'Shorten empty lines'), 1265 0, 0, 1266 self.editActGrp, 'vm_edit_shorten_empty_lines') 1267 self.shortenEmptyAct.setStatusTip(QCoreApplication.translate( 1268 'ViewManager', 'Shorten empty lines')) 1269 self.shortenEmptyAct.setWhatsThis(QCoreApplication.translate( 1270 'ViewManager', 1271 """<b>Shorten empty lines</b>""" 1272 """<p>Shorten lines consisting solely of whitespace""" 1273 """ characters.</p>""" 1274 )) 1275 self.shortenEmptyAct.triggered.connect(self.__shortenEmptyLines) 1276 self.editActions.append(self.shortenEmptyAct) 1277 1278 self.autoCompleteAct = E5Action( 1279 QCoreApplication.translate('ViewManager', 'Complete'), 1280 QCoreApplication.translate('ViewManager', '&Complete'), 1281 QKeySequence(QCoreApplication.translate( 1282 'ViewManager', "Ctrl+Space", "Edit|Complete")), 1283 0, 1284 self.editActGrp, 'vm_edit_autocomplete') 1285 self.autoCompleteAct.setStatusTip(QCoreApplication.translate( 1286 'ViewManager', 'Complete current word')) 1287 self.autoCompleteAct.setWhatsThis(QCoreApplication.translate( 1288 'ViewManager', 1289 """<b>Complete</b>""" 1290 """<p>Performs a completion of the word containing""" 1291 """ the cursor.</p>""" 1292 )) 1293 self.autoCompleteAct.triggered.connect(self.__editAutoComplete) 1294 self.editActions.append(self.autoCompleteAct) 1295 1296 self.autoCompleteFromDocAct = E5Action( 1297 QCoreApplication.translate( 1298 'ViewManager', 'Complete from Document'), 1299 QCoreApplication.translate( 1300 'ViewManager', 'Complete from Document'), 1301 QKeySequence(QCoreApplication.translate( 1302 'ViewManager', "Ctrl+Shift+Space", 1303 "Edit|Complete from Document")), 1304 0, 1305 self.editActGrp, 'vm_edit_autocomplete_from_document') 1306 self.autoCompleteFromDocAct.setStatusTip(QCoreApplication.translate( 1307 'ViewManager', 1308 'Complete current word from Document')) 1309 self.autoCompleteFromDocAct.setWhatsThis(QCoreApplication.translate( 1310 'ViewManager', 1311 """<b>Complete from Document</b>""" 1312 """<p>Performs a completion from document of the word""" 1313 """ containing the cursor.</p>""" 1314 )) 1315 self.autoCompleteFromDocAct.triggered.connect( 1316 self.__editAutoCompleteFromDoc) 1317 self.editActions.append(self.autoCompleteFromDocAct) 1318 1319 self.autoCompleteFromAPIsAct = E5Action( 1320 QCoreApplication.translate('ViewManager', 1321 'Complete from APIs'), 1322 QCoreApplication.translate('ViewManager', 1323 'Complete from APIs'), 1324 QKeySequence(QCoreApplication.translate( 1325 'ViewManager', "Ctrl+Alt+Space", 1326 "Edit|Complete from APIs")), 1327 0, 1328 self.editActGrp, 'vm_edit_autocomplete_from_api') 1329 self.autoCompleteFromAPIsAct.setStatusTip(QCoreApplication.translate( 1330 'ViewManager', 1331 'Complete current word from APIs')) 1332 self.autoCompleteFromAPIsAct.setWhatsThis(QCoreApplication.translate( 1333 'ViewManager', 1334 """<b>Complete from APIs</b>""" 1335 """<p>Performs a completion from APIs of the word""" 1336 """ containing the cursor.</p>""" 1337 )) 1338 self.autoCompleteFromAPIsAct.triggered.connect( 1339 self.__editAutoCompleteFromAPIs) 1340 self.editActions.append(self.autoCompleteFromAPIsAct) 1341 1342 self.autoCompleteFromAllAct = E5Action( 1343 QCoreApplication.translate( 1344 'ViewManager', 'Complete from Document and APIs'), 1345 QCoreApplication.translate( 1346 'ViewManager', 'Complete from Document and APIs'), 1347 QKeySequence(QCoreApplication.translate( 1348 'ViewManager', "Alt+Shift+Space", 1349 "Edit|Complete from Document and APIs")), 1350 0, 1351 self.editActGrp, 'vm_edit_autocomplete_from_all') 1352 self.autoCompleteFromAllAct.setStatusTip(QCoreApplication.translate( 1353 'ViewManager', 1354 'Complete current word from Document and APIs')) 1355 self.autoCompleteFromAllAct.setWhatsThis(QCoreApplication.translate( 1356 'ViewManager', 1357 """<b>Complete from Document and APIs</b>""" 1358 """<p>Performs a completion from document and APIs""" 1359 """ of the word containing the cursor.</p>""" 1360 )) 1361 self.autoCompleteFromAllAct.triggered.connect( 1362 self.__editAutoCompleteFromAll) 1363 self.editActions.append(self.autoCompleteFromAllAct) 1364 1365 self.calltipsAct = E5Action( 1366 QCoreApplication.translate('ViewManager', 'Calltip'), 1367 QCoreApplication.translate('ViewManager', '&Calltip'), 1368 QKeySequence(QCoreApplication.translate( 1369 'ViewManager', "Meta+Alt+Space", "Edit|Calltip")), 1370 0, 1371 self.editActGrp, 'vm_edit_calltip') 1372 self.calltipsAct.setStatusTip(QCoreApplication.translate( 1373 'ViewManager', 'Show Calltips')) 1374 self.calltipsAct.setWhatsThis(QCoreApplication.translate( 1375 'ViewManager', 1376 """<b>Calltip</b>""" 1377 """<p>Show calltips based on the characters immediately to the""" 1378 """ left of the cursor.</p>""" 1379 )) 1380 self.calltipsAct.triggered.connect(self.__editShowCallTips) 1381 self.editActions.append(self.calltipsAct) 1382 1383 self.codeInfoAct = E5Action( 1384 QCoreApplication.translate('ViewManager', 'Code Info'), 1385 UI.PixmapCache.getIcon("codeDocuViewer"), 1386 QCoreApplication.translate('ViewManager', 'Code Info'), 1387 QKeySequence(QCoreApplication.translate( 1388 'ViewManager', "Ctrl+Alt+I", "Edit|Code Info")), 1389 0, 1390 self.editActGrp, 'vm_edit_codeinfo') 1391 self.codeInfoAct.setStatusTip(QCoreApplication.translate( 1392 'ViewManager', 'Show Code Info')) 1393 self.codeInfoAct.setWhatsThis(QCoreApplication.translate( 1394 'ViewManager', 1395 """<b>Code Info</b>""" 1396 """<p>Show code information based on the cursor position.</p>""" 1397 )) 1398 self.codeInfoAct.triggered.connect(self.__editShowCodeInfo) 1399 self.editActions.append(self.codeInfoAct) 1400 1401 self.sortAct = E5Action( 1402 QCoreApplication.translate('ViewManager', 'Sort'), 1403 QCoreApplication.translate('ViewManager', 'Sort'), 1404 QKeySequence(QCoreApplication.translate( 1405 'ViewManager', "Ctrl+Alt+S", "Edit|Sort")), 1406 0, 1407 self.editActGrp, 'vm_edit_sort') 1408 self.sortAct.setStatusTip(QCoreApplication.translate( 1409 'ViewManager', 1410 'Sort the lines containing the rectangular selection')) 1411 self.sortAct.setWhatsThis(QCoreApplication.translate( 1412 'ViewManager', 1413 """<b>Sort</b>""" 1414 """<p>Sort the lines spanned by a rectangular selection based on""" 1415 """ the selection ignoring leading and trailing whitespace.</p>""" 1416 )) 1417 self.sortAct.triggered.connect(self.__editSortSelectedLines) 1418 self.editActions.append(self.sortAct) 1419 1420 self.docstringAct = E5Action( 1421 QCoreApplication.translate('ViewManager', 'Generate Docstring'), 1422 QCoreApplication.translate('ViewManager', 'Generate Docstring'), 1423 QKeySequence(QCoreApplication.translate( 1424 'ViewManager', "Ctrl+Alt+D", "Edit|Generate Docstring")), 1425 0, 1426 self.editActGrp, 'vm_edit_generate_docstring') 1427 self.docstringAct.setStatusTip(QCoreApplication.translate( 1428 'ViewManager', 1429 'Generate a docstring for the current function/method')) 1430 self.docstringAct.setWhatsThis(QCoreApplication.translate( 1431 'ViewManager', 1432 """<b>Generate Docstring</b>""" 1433 """<p>Generate a docstring for the current function/method if""" 1434 """ the cursor is placed on the line starting the function""" 1435 """ definition or on the line thereafter. The docstring is""" 1436 """ inserted at the appropriate position and the cursor is""" 1437 """ placed at the end of the description line.</p>""" 1438 )) 1439 self.docstringAct.triggered.connect(self.__editInsertDocstring) 1440 self.editActions.append(self.docstringAct) 1441 1442 self.editActGrp.setEnabled(False) 1443 self.copyActGrp.setEnabled(False) 1444 1445 #################################################################### 1446 ## Below follow the actions for QScintilla standard commands. 1447 #################################################################### 1448 1449 self.esm = QSignalMapper(self) 1450 try: 1451 self.esm.mappedInt.connect(self.__editorCommand) 1452 except AttributeError: 1453 # pre Qt 5.15 1454 self.esm.mapped[int].connect(self.__editorCommand) 1455 1456 self.editorActGrp = createActionGroup(self.editActGrp) 1457 1458 act = E5Action( 1459 QCoreApplication.translate('ViewManager', 1460 'Move left one character'), 1461 QCoreApplication.translate('ViewManager', 1462 'Move left one character'), 1463 QKeySequence(QCoreApplication.translate('ViewManager', 'Left')), 0, 1464 self.editorActGrp, 'vm_edit_move_left_char') 1465 self.esm.setMapping(act, QsciScintilla.SCI_CHARLEFT) 1466 if isMacPlatform(): 1467 act.setAlternateShortcut(QKeySequence( 1468 QCoreApplication.translate('ViewManager', 'Meta+B'))) 1469 act.triggered.connect(self.esm.map) 1470 self.editActions.append(act) 1471 1472 act = E5Action( 1473 QCoreApplication.translate('ViewManager', 1474 'Move right one character'), 1475 QCoreApplication.translate('ViewManager', 1476 'Move right one character'), 1477 QKeySequence(QCoreApplication.translate('ViewManager', 'Right')), 1478 0, self.editorActGrp, 'vm_edit_move_right_char') 1479 if isMacPlatform(): 1480 act.setAlternateShortcut(QKeySequence( 1481 QCoreApplication.translate('ViewManager', 'Meta+F'))) 1482 self.esm.setMapping(act, QsciScintilla.SCI_CHARRIGHT) 1483 act.triggered.connect(self.esm.map) 1484 self.editActions.append(act) 1485 1486 act = E5Action( 1487 QCoreApplication.translate('ViewManager', 'Move up one line'), 1488 QCoreApplication.translate('ViewManager', 'Move up one line'), 1489 QKeySequence(QCoreApplication.translate('ViewManager', 'Up')), 0, 1490 self.editorActGrp, 'vm_edit_move_up_line') 1491 if isMacPlatform(): 1492 act.setAlternateShortcut(QKeySequence( 1493 QCoreApplication.translate('ViewManager', 'Meta+P'))) 1494 self.esm.setMapping(act, QsciScintilla.SCI_LINEUP) 1495 act.triggered.connect(self.esm.map) 1496 self.editActions.append(act) 1497 1498 act = E5Action( 1499 QCoreApplication.translate('ViewManager', 'Move down one line'), 1500 QCoreApplication.translate('ViewManager', 'Move down one line'), 1501 QKeySequence(QCoreApplication.translate('ViewManager', 'Down')), 0, 1502 self.editorActGrp, 'vm_edit_move_down_line') 1503 if isMacPlatform(): 1504 act.setAlternateShortcut(QKeySequence( 1505 QCoreApplication.translate('ViewManager', 'Meta+N'))) 1506 self.esm.setMapping(act, QsciScintilla.SCI_LINEDOWN) 1507 act.triggered.connect(self.esm.map) 1508 self.editActions.append(act) 1509 1510 act = E5Action( 1511 QCoreApplication.translate('ViewManager', 1512 'Move left one word part'), 1513 QCoreApplication.translate('ViewManager', 1514 'Move left one word part'), 1515 0, 0, 1516 self.editorActGrp, 'vm_edit_move_left_word_part') 1517 if not isMacPlatform(): 1518 act.setShortcut(QKeySequence( 1519 QCoreApplication.translate('ViewManager', 'Alt+Left'))) 1520 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTLEFT) 1521 act.triggered.connect(self.esm.map) 1522 self.editActions.append(act) 1523 1524 act = E5Action( 1525 QCoreApplication.translate('ViewManager', 1526 'Move right one word part'), 1527 QCoreApplication.translate('ViewManager', 1528 'Move right one word part'), 1529 0, 0, 1530 self.editorActGrp, 'vm_edit_move_right_word_part') 1531 if not isMacPlatform(): 1532 act.setShortcut(QKeySequence( 1533 QCoreApplication.translate('ViewManager', 'Alt+Right'))) 1534 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTRIGHT) 1535 act.triggered.connect(self.esm.map) 1536 self.editActions.append(act) 1537 1538 act = E5Action( 1539 QCoreApplication.translate('ViewManager', 'Move left one word'), 1540 QCoreApplication.translate('ViewManager', 'Move left one word'), 1541 0, 0, 1542 self.editorActGrp, 'vm_edit_move_left_word') 1543 if isMacPlatform(): 1544 act.setShortcut(QKeySequence( 1545 QCoreApplication.translate('ViewManager', 'Alt+Left'))) 1546 else: 1547 act.setShortcut(QKeySequence( 1548 QCoreApplication.translate('ViewManager', 'Ctrl+Left'))) 1549 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFT) 1550 act.triggered.connect(self.esm.map) 1551 self.editActions.append(act) 1552 1553 act = E5Action( 1554 QCoreApplication.translate('ViewManager', 'Move right one word'), 1555 QCoreApplication.translate('ViewManager', 'Move right one word'), 1556 0, 0, 1557 self.editorActGrp, 'vm_edit_move_right_word') 1558 if not isMacPlatform(): 1559 act.setShortcut(QKeySequence( 1560 QCoreApplication.translate('ViewManager', 'Ctrl+Right'))) 1561 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHT) 1562 act.triggered.connect(self.esm.map) 1563 self.editActions.append(act) 1564 1565 act = E5Action( 1566 QCoreApplication.translate( 1567 'ViewManager', 1568 'Move to first visible character in document line'), 1569 QCoreApplication.translate( 1570 'ViewManager', 1571 'Move to first visible character in document line'), 1572 0, 0, 1573 self.editorActGrp, 'vm_edit_move_first_visible_char') 1574 if not isMacPlatform(): 1575 act.setShortcut(QKeySequence( 1576 QCoreApplication.translate('ViewManager', 'Home'))) 1577 self.esm.setMapping(act, QsciScintilla.SCI_VCHOME) 1578 act.triggered.connect(self.esm.map) 1579 self.editActions.append(act) 1580 1581 act = E5Action( 1582 QCoreApplication.translate( 1583 'ViewManager', 'Move to start of display line'), 1584 QCoreApplication.translate( 1585 'ViewManager', 'Move to start of display line'), 1586 0, 0, 1587 self.editorActGrp, 'vm_edit_move_start_line') 1588 if isMacPlatform(): 1589 act.setShortcut(QKeySequence( 1590 QCoreApplication.translate('ViewManager', 'Ctrl+Left'))) 1591 else: 1592 act.setShortcut(QKeySequence( 1593 QCoreApplication.translate('ViewManager', 'Alt+Home'))) 1594 self.esm.setMapping(act, QsciScintilla.SCI_HOMEDISPLAY) 1595 act.triggered.connect(self.esm.map) 1596 self.editActions.append(act) 1597 1598 act = E5Action( 1599 QCoreApplication.translate( 1600 'ViewManager', 'Move to end of document line'), 1601 QCoreApplication.translate( 1602 'ViewManager', 'Move to end of document line'), 1603 0, 0, 1604 self.editorActGrp, 'vm_edit_move_end_line') 1605 if isMacPlatform(): 1606 act.setShortcut(QKeySequence( 1607 QCoreApplication.translate('ViewManager', 'Meta+E'))) 1608 else: 1609 act.setShortcut(QKeySequence( 1610 QCoreApplication.translate('ViewManager', 'End'))) 1611 self.esm.setMapping(act, QsciScintilla.SCI_LINEEND) 1612 act.triggered.connect(self.esm.map) 1613 self.editActions.append(act) 1614 1615 act = E5Action( 1616 QCoreApplication.translate('ViewManager', 1617 'Scroll view down one line'), 1618 QCoreApplication.translate('ViewManager', 1619 'Scroll view down one line'), 1620 QKeySequence(QCoreApplication.translate('ViewManager', 1621 'Ctrl+Down')), 1622 0, self.editorActGrp, 'vm_edit_scroll_down_line') 1623 self.esm.setMapping(act, QsciScintilla.SCI_LINESCROLLDOWN) 1624 act.triggered.connect(self.esm.map) 1625 self.editActions.append(act) 1626 1627 act = E5Action( 1628 QCoreApplication.translate('ViewManager', 1629 'Scroll view up one line'), 1630 QCoreApplication.translate('ViewManager', 1631 'Scroll view up one line'), 1632 QKeySequence(QCoreApplication.translate('ViewManager', 'Ctrl+Up')), 1633 0, self.editorActGrp, 'vm_edit_scroll_up_line') 1634 self.esm.setMapping(act, QsciScintilla.SCI_LINESCROLLUP) 1635 act.triggered.connect(self.esm.map) 1636 self.editActions.append(act) 1637 1638 act = E5Action( 1639 QCoreApplication.translate('ViewManager', 'Move up one paragraph'), 1640 QCoreApplication.translate('ViewManager', 'Move up one paragraph'), 1641 QKeySequence(QCoreApplication.translate('ViewManager', 'Alt+Up')), 1642 0, self.editorActGrp, 'vm_edit_move_up_para') 1643 self.esm.setMapping(act, QsciScintilla.SCI_PARAUP) 1644 act.triggered.connect(self.esm.map) 1645 self.editActions.append(act) 1646 1647 act = E5Action( 1648 QCoreApplication.translate('ViewManager', 1649 'Move down one paragraph'), 1650 QCoreApplication.translate('ViewManager', 1651 'Move down one paragraph'), 1652 QKeySequence(QCoreApplication.translate('ViewManager', 1653 'Alt+Down')), 1654 0, self.editorActGrp, 'vm_edit_move_down_para') 1655 self.esm.setMapping(act, QsciScintilla.SCI_PARADOWN) 1656 act.triggered.connect(self.esm.map) 1657 self.editActions.append(act) 1658 1659 act = E5Action( 1660 QCoreApplication.translate('ViewManager', 'Move up one page'), 1661 QCoreApplication.translate('ViewManager', 'Move up one page'), 1662 QKeySequence(QCoreApplication.translate('ViewManager', 'PgUp')), 0, 1663 self.editorActGrp, 'vm_edit_move_up_page') 1664 self.esm.setMapping(act, QsciScintilla.SCI_PAGEUP) 1665 act.triggered.connect(self.esm.map) 1666 self.editActions.append(act) 1667 1668 act = E5Action( 1669 QCoreApplication.translate('ViewManager', 'Move down one page'), 1670 QCoreApplication.translate('ViewManager', 'Move down one page'), 1671 QKeySequence(QCoreApplication.translate('ViewManager', 'PgDown')), 1672 0, self.editorActGrp, 'vm_edit_move_down_page') 1673 if isMacPlatform(): 1674 act.setAlternateShortcut(QKeySequence( 1675 QCoreApplication.translate('ViewManager', 'Meta+V'))) 1676 self.esm.setMapping(act, QsciScintilla.SCI_PAGEDOWN) 1677 act.triggered.connect(self.esm.map) 1678 self.editActions.append(act) 1679 1680 act = E5Action( 1681 QCoreApplication.translate('ViewManager', 1682 'Move to start of document'), 1683 QCoreApplication.translate('ViewManager', 1684 'Move to start of document'), 1685 0, 0, 1686 self.editorActGrp, 'vm_edit_move_start_text') 1687 if isMacPlatform(): 1688 act.setShortcut(QKeySequence( 1689 QCoreApplication.translate('ViewManager', 'Ctrl+Up'))) 1690 else: 1691 act.setShortcut(QKeySequence( 1692 QCoreApplication.translate('ViewManager', 'Ctrl+Home'))) 1693 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTSTART) 1694 act.triggered.connect(self.esm.map) 1695 self.editActions.append(act) 1696 1697 act = E5Action( 1698 QCoreApplication.translate('ViewManager', 1699 'Move to end of document'), 1700 QCoreApplication.translate('ViewManager', 1701 'Move to end of document'), 1702 0, 0, 1703 self.editorActGrp, 'vm_edit_move_end_text') 1704 if isMacPlatform(): 1705 act.setShortcut(QKeySequence( 1706 QCoreApplication.translate('ViewManager', 'Ctrl+Down'))) 1707 else: 1708 act.setShortcut(QKeySequence( 1709 QCoreApplication.translate('ViewManager', 'Ctrl+End'))) 1710 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTEND) 1711 act.triggered.connect(self.esm.map) 1712 self.editActions.append(act) 1713 1714 act = E5Action( 1715 QCoreApplication.translate('ViewManager', 'Indent one level'), 1716 QCoreApplication.translate('ViewManager', 'Indent one level'), 1717 QKeySequence(QCoreApplication.translate('ViewManager', 'Tab')), 0, 1718 self.editorActGrp, 'vm_edit_indent_one_level') 1719 self.esm.setMapping(act, QsciScintilla.SCI_TAB) 1720 act.triggered.connect(self.esm.map) 1721 self.editActions.append(act) 1722 1723 act = E5Action( 1724 QCoreApplication.translate('ViewManager', 'Unindent one level'), 1725 QCoreApplication.translate('ViewManager', 'Unindent one level'), 1726 QKeySequence(QCoreApplication.translate('ViewManager', 1727 'Shift+Tab')), 1728 0, self.editorActGrp, 'vm_edit_unindent_one_level') 1729 self.esm.setMapping(act, QsciScintilla.SCI_BACKTAB) 1730 act.triggered.connect(self.esm.map) 1731 self.editActions.append(act) 1732 1733 act = E5Action( 1734 QCoreApplication.translate( 1735 'ViewManager', 'Extend selection left one character'), 1736 QCoreApplication.translate( 1737 'ViewManager', 'Extend selection left one character'), 1738 QKeySequence(QCoreApplication.translate('ViewManager', 1739 'Shift+Left')), 1740 0, self.editorActGrp, 'vm_edit_extend_selection_left_char') 1741 if isMacPlatform(): 1742 act.setAlternateShortcut(QKeySequence( 1743 QCoreApplication.translate('ViewManager', 'Meta+Shift+B'))) 1744 self.esm.setMapping(act, QsciScintilla.SCI_CHARLEFTEXTEND) 1745 act.triggered.connect(self.esm.map) 1746 self.editActions.append(act) 1747 1748 act = E5Action( 1749 QCoreApplication.translate( 1750 'ViewManager', 'Extend selection right one character'), 1751 QCoreApplication.translate( 1752 'ViewManager', 'Extend selection right one character'), 1753 QKeySequence(QCoreApplication.translate('ViewManager', 1754 'Shift+Right')), 1755 0, self.editorActGrp, 'vm_edit_extend_selection_right_char') 1756 if isMacPlatform(): 1757 act.setAlternateShortcut(QKeySequence( 1758 QCoreApplication.translate('ViewManager', 'Meta+Shift+F'))) 1759 self.esm.setMapping(act, QsciScintilla.SCI_CHARRIGHTEXTEND) 1760 act.triggered.connect(self.esm.map) 1761 self.editActions.append(act) 1762 1763 act = E5Action( 1764 QCoreApplication.translate( 1765 'ViewManager', 'Extend selection up one line'), 1766 QCoreApplication.translate( 1767 'ViewManager', 'Extend selection up one line'), 1768 QKeySequence(QCoreApplication.translate('ViewManager', 1769 'Shift+Up')), 1770 0, self.editorActGrp, 'vm_edit_extend_selection_up_line') 1771 if isMacPlatform(): 1772 act.setAlternateShortcut(QKeySequence( 1773 QCoreApplication.translate('ViewManager', 'Meta+Shift+P'))) 1774 self.esm.setMapping(act, QsciScintilla.SCI_LINEUPEXTEND) 1775 act.triggered.connect(self.esm.map) 1776 self.editActions.append(act) 1777 1778 act = E5Action( 1779 QCoreApplication.translate( 1780 'ViewManager', 'Extend selection down one line'), 1781 QCoreApplication.translate( 1782 'ViewManager', 'Extend selection down one line'), 1783 QKeySequence(QCoreApplication.translate('ViewManager', 1784 'Shift+Down')), 1785 0, self.editorActGrp, 'vm_edit_extend_selection_down_line') 1786 if isMacPlatform(): 1787 act.setAlternateShortcut(QKeySequence( 1788 QCoreApplication.translate('ViewManager', 'Meta+Shift+N'))) 1789 self.esm.setMapping(act, QsciScintilla.SCI_LINEDOWNEXTEND) 1790 act.triggered.connect(self.esm.map) 1791 self.editActions.append(act) 1792 1793 act = E5Action( 1794 QCoreApplication.translate( 1795 'ViewManager', 'Extend selection left one word part'), 1796 QCoreApplication.translate( 1797 'ViewManager', 'Extend selection left one word part'), 1798 0, 0, 1799 self.editorActGrp, 'vm_edit_extend_selection_left_word_part') 1800 if not isMacPlatform(): 1801 act.setShortcut(QKeySequence( 1802 QCoreApplication.translate('ViewManager', 'Alt+Shift+Left'))) 1803 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTLEFTEXTEND) 1804 act.triggered.connect(self.esm.map) 1805 self.editActions.append(act) 1806 1807 act = E5Action( 1808 QCoreApplication.translate( 1809 'ViewManager', 'Extend selection right one word part'), 1810 QCoreApplication.translate( 1811 'ViewManager', 'Extend selection right one word part'), 1812 0, 0, 1813 self.editorActGrp, 'vm_edit_extend_selection_right_word_part') 1814 if not isMacPlatform(): 1815 act.setShortcut(QKeySequence( 1816 QCoreApplication.translate('ViewManager', 'Alt+Shift+Right'))) 1817 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTRIGHTEXTEND) 1818 act.triggered.connect(self.esm.map) 1819 self.editActions.append(act) 1820 1821 act = E5Action( 1822 QCoreApplication.translate( 1823 'ViewManager', 'Extend selection left one word'), 1824 QCoreApplication.translate( 1825 'ViewManager', 'Extend selection left one word'), 1826 0, 0, 1827 self.editorActGrp, 'vm_edit_extend_selection_left_word') 1828 if isMacPlatform(): 1829 act.setShortcut(QKeySequence( 1830 QCoreApplication.translate('ViewManager', 'Alt+Shift+Left'))) 1831 else: 1832 act.setShortcut(QKeySequence( 1833 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Left'))) 1834 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFTEXTEND) 1835 act.triggered.connect(self.esm.map) 1836 self.editActions.append(act) 1837 1838 act = E5Action( 1839 QCoreApplication.translate( 1840 'ViewManager', 'Extend selection right one word'), 1841 QCoreApplication.translate( 1842 'ViewManager', 'Extend selection right one word'), 1843 0, 0, 1844 self.editorActGrp, 'vm_edit_extend_selection_right_word') 1845 if isMacPlatform(): 1846 act.setShortcut(QKeySequence( 1847 QCoreApplication.translate('ViewManager', 'Alt+Shift+Right'))) 1848 else: 1849 act.setShortcut(QKeySequence( 1850 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Right'))) 1851 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHTEXTEND) 1852 act.triggered.connect(self.esm.map) 1853 self.editActions.append(act) 1854 1855 act = E5Action( 1856 QCoreApplication.translate( 1857 'ViewManager', 1858 'Extend selection to first visible character in document' 1859 ' line'), 1860 QCoreApplication.translate( 1861 'ViewManager', 1862 'Extend selection to first visible character in document' 1863 ' line'), 1864 0, 0, 1865 self.editorActGrp, 'vm_edit_extend_selection_first_visible_char') 1866 if not isMacPlatform(): 1867 act.setShortcut(QKeySequence( 1868 QCoreApplication.translate('ViewManager', 'Shift+Home'))) 1869 self.esm.setMapping(act, QsciScintilla.SCI_VCHOMEEXTEND) 1870 act.triggered.connect(self.esm.map) 1871 self.editActions.append(act) 1872 1873 act = E5Action( 1874 QCoreApplication.translate( 1875 'ViewManager', 'Extend selection to end of document line'), 1876 QCoreApplication.translate( 1877 'ViewManager', 'Extend selection to end of document line'), 1878 0, 0, 1879 self.editorActGrp, 'vm_edit_extend_selection_end_line') 1880 if isMacPlatform(): 1881 act.setShortcut(QKeySequence( 1882 QCoreApplication.translate('ViewManager', 'Meta+Shift+E'))) 1883 else: 1884 act.setShortcut(QKeySequence( 1885 QCoreApplication.translate('ViewManager', 'Shift+End'))) 1886 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDEXTEND) 1887 act.triggered.connect(self.esm.map) 1888 self.editActions.append(act) 1889 1890 act = E5Action( 1891 QCoreApplication.translate( 1892 'ViewManager', 'Extend selection up one paragraph'), 1893 QCoreApplication.translate( 1894 'ViewManager', 'Extend selection up one paragraph'), 1895 QKeySequence(QCoreApplication.translate( 1896 'ViewManager', 'Alt+Shift+Up')), 1897 0, 1898 self.editorActGrp, 'vm_edit_extend_selection_up_para') 1899 self.esm.setMapping(act, QsciScintilla.SCI_PARAUPEXTEND) 1900 act.triggered.connect(self.esm.map) 1901 self.editActions.append(act) 1902 1903 act = E5Action( 1904 QCoreApplication.translate( 1905 'ViewManager', 'Extend selection down one paragraph'), 1906 QCoreApplication.translate( 1907 'ViewManager', 'Extend selection down one paragraph'), 1908 QKeySequence(QCoreApplication.translate( 1909 'ViewManager', 'Alt+Shift+Down')), 1910 0, 1911 self.editorActGrp, 'vm_edit_extend_selection_down_para') 1912 self.esm.setMapping(act, QsciScintilla.SCI_PARADOWNEXTEND) 1913 act.triggered.connect(self.esm.map) 1914 self.editActions.append(act) 1915 1916 act = E5Action( 1917 QCoreApplication.translate( 1918 'ViewManager', 'Extend selection up one page'), 1919 QCoreApplication.translate( 1920 'ViewManager', 'Extend selection up one page'), 1921 QKeySequence(QCoreApplication.translate('ViewManager', 1922 'Shift+PgUp')), 1923 0, self.editorActGrp, 'vm_edit_extend_selection_up_page') 1924 self.esm.setMapping(act, QsciScintilla.SCI_PAGEUPEXTEND) 1925 act.triggered.connect(self.esm.map) 1926 self.editActions.append(act) 1927 1928 act = E5Action( 1929 QCoreApplication.translate( 1930 'ViewManager', 'Extend selection down one page'), 1931 QCoreApplication.translate( 1932 'ViewManager', 'Extend selection down one page'), 1933 QKeySequence(QCoreApplication.translate( 1934 'ViewManager', 'Shift+PgDown')), 1935 0, 1936 self.editorActGrp, 'vm_edit_extend_selection_down_page') 1937 if isMacPlatform(): 1938 act.setAlternateShortcut(QKeySequence( 1939 QCoreApplication.translate('ViewManager', 'Meta+Shift+V'))) 1940 self.esm.setMapping(act, QsciScintilla.SCI_PAGEDOWNEXTEND) 1941 act.triggered.connect(self.esm.map) 1942 self.editActions.append(act) 1943 1944 act = E5Action( 1945 QCoreApplication.translate( 1946 'ViewManager', 'Extend selection to start of document'), 1947 QCoreApplication.translate( 1948 'ViewManager', 'Extend selection to start of document'), 1949 0, 0, 1950 self.editorActGrp, 'vm_edit_extend_selection_start_text') 1951 if isMacPlatform(): 1952 act.setShortcut(QKeySequence( 1953 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Up'))) 1954 else: 1955 act.setShortcut(QKeySequence( 1956 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Home'))) 1957 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTSTARTEXTEND) 1958 act.triggered.connect(self.esm.map) 1959 self.editActions.append(act) 1960 1961 act = E5Action( 1962 QCoreApplication.translate( 1963 'ViewManager', 'Extend selection to end of document'), 1964 QCoreApplication.translate( 1965 'ViewManager', 'Extend selection to end of document'), 1966 0, 0, 1967 self.editorActGrp, 'vm_edit_extend_selection_end_text') 1968 if isMacPlatform(): 1969 act.setShortcut(QKeySequence( 1970 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Down'))) 1971 else: 1972 act.setShortcut(QKeySequence( 1973 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+End'))) 1974 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTENDEXTEND) 1975 act.triggered.connect(self.esm.map) 1976 self.editActions.append(act) 1977 1978 act = E5Action( 1979 QCoreApplication.translate('ViewManager', 1980 'Delete previous character'), 1981 QCoreApplication.translate('ViewManager', 1982 'Delete previous character'), 1983 QKeySequence(QCoreApplication.translate('ViewManager', 1984 'Backspace')), 1985 0, self.editorActGrp, 'vm_edit_delete_previous_char') 1986 if isMacPlatform(): 1987 act.setAlternateShortcut(QKeySequence( 1988 QCoreApplication.translate('ViewManager', 'Meta+H'))) 1989 else: 1990 act.setAlternateShortcut(QKeySequence( 1991 QCoreApplication.translate('ViewManager', 'Shift+Backspace'))) 1992 self.esm.setMapping(act, QsciScintilla.SCI_DELETEBACK) 1993 act.triggered.connect(self.esm.map) 1994 self.editActions.append(act) 1995 1996 act = E5Action( 1997 QCoreApplication.translate( 1998 'ViewManager', 1999 'Delete previous character if not at start of line'), 2000 QCoreApplication.translate( 2001 'ViewManager', 2002 'Delete previous character if not at start of line'), 2003 0, 0, 2004 self.editorActGrp, 'vm_edit_delet_previous_char_not_line_start') 2005 self.esm.setMapping(act, QsciScintilla.SCI_DELETEBACKNOTLINE) 2006 act.triggered.connect(self.esm.map) 2007 self.editActions.append(act) 2008 2009 act = E5Action( 2010 QCoreApplication.translate('ViewManager', 2011 'Delete current character'), 2012 QCoreApplication.translate('ViewManager', 2013 'Delete current character'), 2014 QKeySequence(QCoreApplication.translate('ViewManager', 'Del')), 2015 0, self.editorActGrp, 'vm_edit_delete_current_char') 2016 if isMacPlatform(): 2017 act.setAlternateShortcut(QKeySequence( 2018 QCoreApplication.translate('ViewManager', 'Meta+D'))) 2019 self.esm.setMapping(act, QsciScintilla.SCI_CLEAR) 2020 act.triggered.connect(self.esm.map) 2021 self.editActions.append(act) 2022 2023 act = E5Action( 2024 QCoreApplication.translate('ViewManager', 'Delete word to left'), 2025 QCoreApplication.translate('ViewManager', 'Delete word to left'), 2026 QKeySequence(QCoreApplication.translate( 2027 'ViewManager', 'Ctrl+Backspace')), 2028 0, 2029 self.editorActGrp, 'vm_edit_delete_word_left') 2030 self.esm.setMapping(act, QsciScintilla.SCI_DELWORDLEFT) 2031 act.triggered.connect(self.esm.map) 2032 self.editActions.append(act) 2033 2034 act = E5Action( 2035 QCoreApplication.translate('ViewManager', 'Delete word to right'), 2036 QCoreApplication.translate('ViewManager', 'Delete word to right'), 2037 QKeySequence(QCoreApplication.translate('ViewManager', 2038 'Ctrl+Del')), 2039 0, self.editorActGrp, 'vm_edit_delete_word_right') 2040 self.esm.setMapping(act, QsciScintilla.SCI_DELWORDRIGHT) 2041 act.triggered.connect(self.esm.map) 2042 self.editActions.append(act) 2043 2044 act = E5Action( 2045 QCoreApplication.translate('ViewManager', 'Delete line to left'), 2046 QCoreApplication.translate('ViewManager', 'Delete line to left'), 2047 QKeySequence(QCoreApplication.translate( 2048 'ViewManager', 'Ctrl+Shift+Backspace')), 2049 0, 2050 self.editorActGrp, 'vm_edit_delete_line_left') 2051 self.esm.setMapping(act, QsciScintilla.SCI_DELLINELEFT) 2052 act.triggered.connect(self.esm.map) 2053 self.editActions.append(act) 2054 2055 act = E5Action( 2056 QCoreApplication.translate('ViewManager', 'Delete line to right'), 2057 QCoreApplication.translate('ViewManager', 'Delete line to right'), 2058 0, 0, 2059 self.editorActGrp, 'vm_edit_delete_line_right') 2060 if isMacPlatform(): 2061 act.setShortcut(QKeySequence( 2062 QCoreApplication.translate('ViewManager', 'Meta+K'))) 2063 else: 2064 act.setShortcut(QKeySequence( 2065 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Del'))) 2066 self.esm.setMapping(act, QsciScintilla.SCI_DELLINERIGHT) 2067 act.triggered.connect(self.esm.map) 2068 self.editActions.append(act) 2069 2070 act = E5Action( 2071 QCoreApplication.translate('ViewManager', 'Insert new line'), 2072 QCoreApplication.translate('ViewManager', 'Insert new line'), 2073 QKeySequence(QCoreApplication.translate('ViewManager', 'Return')), 2074 QKeySequence(QCoreApplication.translate('ViewManager', 'Enter')), 2075 self.editorActGrp, 'vm_edit_insert_line') 2076 self.esm.setMapping(act, QsciScintilla.SCI_NEWLINE) 2077 act.triggered.connect(self.esm.map) 2078 self.editActions.append(act) 2079 2080 act = E5Action( 2081 QCoreApplication.translate( 2082 'ViewManager', 'Insert new line below current line'), 2083 QCoreApplication.translate( 2084 'ViewManager', 'Insert new line below current line'), 2085 QKeySequence(QCoreApplication.translate( 2086 'ViewManager', 'Shift+Return')), 2087 QKeySequence(QCoreApplication.translate('ViewManager', 2088 'Shift+Enter')), 2089 self.editorActGrp, 'vm_edit_insert_line_below') 2090 act.triggered.connect(self.__newLineBelow) 2091 self.editActions.append(act) 2092 2093 act = E5Action( 2094 QCoreApplication.translate('ViewManager', 'Delete current line'), 2095 QCoreApplication.translate('ViewManager', 'Delete current line'), 2096 QKeySequence(QCoreApplication.translate( 2097 'ViewManager', 'Ctrl+Shift+L')), 2098 0, 2099 self.editorActGrp, 'vm_edit_delete_current_line') 2100 self.esm.setMapping(act, QsciScintilla.SCI_LINEDELETE) 2101 act.triggered.connect(self.esm.map) 2102 self.editActions.append(act) 2103 2104 act = E5Action( 2105 QCoreApplication.translate( 2106 'ViewManager', 'Duplicate current line'), 2107 QCoreApplication.translate( 2108 'ViewManager', 'Duplicate current line'), 2109 QKeySequence(QCoreApplication.translate('ViewManager', 'Ctrl+D')), 2110 0, self.editorActGrp, 'vm_edit_duplicate_current_line') 2111 self.esm.setMapping(act, QsciScintilla.SCI_LINEDUPLICATE) 2112 act.triggered.connect(self.esm.map) 2113 self.editActions.append(act) 2114 2115 act = E5Action( 2116 QCoreApplication.translate( 2117 'ViewManager', 'Swap current and previous lines'), 2118 QCoreApplication.translate( 2119 'ViewManager', 'Swap current and previous lines'), 2120 QKeySequence(QCoreApplication.translate('ViewManager', 'Ctrl+T')), 2121 0, self.editorActGrp, 'vm_edit_swap_current_previous_line') 2122 self.esm.setMapping(act, QsciScintilla.SCI_LINETRANSPOSE) 2123 act.triggered.connect(self.esm.map) 2124 self.editActions.append(act) 2125 2126 act = E5Action( 2127 QCoreApplication.translate('ViewManager', 2128 'Reverse selected lines'), 2129 QCoreApplication.translate('ViewManager', 2130 'Reverse selected lines'), 2131 QKeySequence(QCoreApplication.translate('ViewManager', 2132 'Meta+Alt+R')), 2133 0, self.editorActGrp, 'vm_edit_reverse selected_lines') 2134 self.esm.setMapping(act, QsciScintilla.SCI_LINEREVERSE) 2135 act.triggered.connect(self.esm.map) 2136 self.editActions.append(act) 2137 2138 act = E5Action( 2139 QCoreApplication.translate('ViewManager', 'Cut current line'), 2140 QCoreApplication.translate('ViewManager', 'Cut current line'), 2141 QKeySequence(QCoreApplication.translate('ViewManager', 2142 'Alt+Shift+L')), 2143 0, self.editorActGrp, 'vm_edit_cut_current_line') 2144 self.esm.setMapping(act, QsciScintilla.SCI_LINECUT) 2145 act.triggered.connect(self.esm.map) 2146 self.editActions.append(act) 2147 2148 act = E5Action( 2149 QCoreApplication.translate('ViewManager', 'Copy current line'), 2150 QCoreApplication.translate('ViewManager', 'Copy current line'), 2151 QKeySequence(QCoreApplication.translate( 2152 'ViewManager', 'Ctrl+Shift+T')), 2153 0, 2154 self.editorActGrp, 'vm_edit_copy_current_line') 2155 self.esm.setMapping(act, QsciScintilla.SCI_LINECOPY) 2156 act.triggered.connect(self.esm.map) 2157 self.editActions.append(act) 2158 2159 act = E5Action( 2160 QCoreApplication.translate( 2161 'ViewManager', 'Toggle insert/overtype'), 2162 QCoreApplication.translate( 2163 'ViewManager', 'Toggle insert/overtype'), 2164 QKeySequence(QCoreApplication.translate('ViewManager', 'Ins')), 2165 0, self.editorActGrp, 'vm_edit_toggle_insert_overtype') 2166 self.esm.setMapping(act, QsciScintilla.SCI_EDITTOGGLEOVERTYPE) 2167 act.triggered.connect(self.esm.map) 2168 self.editActions.append(act) 2169 2170 act = E5Action( 2171 QCoreApplication.translate( 2172 'ViewManager', 'Move to end of display line'), 2173 QCoreApplication.translate( 2174 'ViewManager', 'Move to end of display line'), 2175 0, 0, 2176 self.editorActGrp, 'vm_edit_move_end_displayed_line') 2177 if isMacPlatform(): 2178 act.setShortcut(QKeySequence( 2179 QCoreApplication.translate('ViewManager', 'Ctrl+Right'))) 2180 else: 2181 act.setShortcut(QKeySequence( 2182 QCoreApplication.translate('ViewManager', 'Alt+End'))) 2183 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDDISPLAY) 2184 act.triggered.connect(self.esm.map) 2185 self.editActions.append(act) 2186 2187 act = E5Action( 2188 QCoreApplication.translate( 2189 'ViewManager', 'Extend selection to end of display line'), 2190 QCoreApplication.translate( 2191 'ViewManager', 'Extend selection to end of display line'), 2192 0, 0, 2193 self.editorActGrp, 'vm_edit_extend_selection_end_displayed_line') 2194 if isMacPlatform(): 2195 act.setShortcut(QKeySequence( 2196 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Right'))) 2197 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDDISPLAYEXTEND) 2198 act.triggered.connect(self.esm.map) 2199 self.editActions.append(act) 2200 2201 act = E5Action( 2202 QCoreApplication.translate('ViewManager', 'Formfeed'), 2203 QCoreApplication.translate('ViewManager', 'Formfeed'), 2204 0, 0, 2205 self.editorActGrp, 'vm_edit_formfeed') 2206 self.esm.setMapping(act, QsciScintilla.SCI_FORMFEED) 2207 act.triggered.connect(self.esm.map) 2208 self.editActions.append(act) 2209 2210 act = E5Action( 2211 QCoreApplication.translate('ViewManager', 'Escape'), 2212 QCoreApplication.translate('ViewManager', 'Escape'), 2213 QKeySequence(QCoreApplication.translate('ViewManager', 'Esc')), 0, 2214 self.editorActGrp, 'vm_edit_escape') 2215 self.esm.setMapping(act, QsciScintilla.SCI_CANCEL) 2216 act.triggered.connect(self.esm.map) 2217 self.editActions.append(act) 2218 2219 act = E5Action( 2220 QCoreApplication.translate( 2221 'ViewManager', 'Extend rectangular selection down one line'), 2222 QCoreApplication.translate( 2223 'ViewManager', 'Extend rectangular selection down one line'), 2224 QKeySequence(QCoreApplication.translate( 2225 'ViewManager', 'Alt+Ctrl+Down')), 2226 0, 2227 self.editorActGrp, 'vm_edit_extend_rect_selection_down_line') 2228 if isMacPlatform(): 2229 act.setAlternateShortcut(QKeySequence( 2230 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+N'))) 2231 self.esm.setMapping(act, QsciScintilla.SCI_LINEDOWNRECTEXTEND) 2232 act.triggered.connect(self.esm.map) 2233 self.editActions.append(act) 2234 2235 act = E5Action( 2236 QCoreApplication.translate( 2237 'ViewManager', 'Extend rectangular selection up one line'), 2238 QCoreApplication.translate( 2239 'ViewManager', 'Extend rectangular selection up one line'), 2240 QKeySequence(QCoreApplication.translate('ViewManager', 2241 'Alt+Ctrl+Up')), 2242 0, self.editorActGrp, 'vm_edit_extend_rect_selection_up_line') 2243 if isMacPlatform(): 2244 act.setAlternateShortcut(QKeySequence( 2245 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+P'))) 2246 self.esm.setMapping(act, QsciScintilla.SCI_LINEUPRECTEXTEND) 2247 act.triggered.connect(self.esm.map) 2248 self.editActions.append(act) 2249 2250 act = E5Action( 2251 QCoreApplication.translate( 2252 'ViewManager', 2253 'Extend rectangular selection left one character'), 2254 QCoreApplication.translate( 2255 'ViewManager', 2256 'Extend rectangular selection left one character'), 2257 QKeySequence(QCoreApplication.translate( 2258 'ViewManager', 'Alt+Ctrl+Left')), 2259 0, 2260 self.editorActGrp, 'vm_edit_extend_rect_selection_left_char') 2261 if isMacPlatform(): 2262 act.setAlternateShortcut(QKeySequence( 2263 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+B'))) 2264 self.esm.setMapping(act, QsciScintilla.SCI_CHARLEFTRECTEXTEND) 2265 act.triggered.connect(self.esm.map) 2266 self.editActions.append(act) 2267 2268 act = E5Action( 2269 QCoreApplication.translate( 2270 'ViewManager', 2271 'Extend rectangular selection right one character'), 2272 QCoreApplication.translate( 2273 'ViewManager', 2274 'Extend rectangular selection right one character'), 2275 QKeySequence(QCoreApplication.translate( 2276 'ViewManager', 'Alt+Ctrl+Right')), 2277 0, 2278 self.editorActGrp, 'vm_edit_extend_rect_selection_right_char') 2279 if isMacPlatform(): 2280 act.setAlternateShortcut(QKeySequence( 2281 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+F'))) 2282 self.esm.setMapping(act, QsciScintilla.SCI_CHARRIGHTRECTEXTEND) 2283 act.triggered.connect(self.esm.map) 2284 self.editActions.append(act) 2285 2286 act = E5Action( 2287 QCoreApplication.translate( 2288 'ViewManager', 2289 'Extend rectangular selection to first visible character in' 2290 ' document line'), 2291 QCoreApplication.translate( 2292 'ViewManager', 2293 'Extend rectangular selection to first visible character in' 2294 ' document line'), 2295 0, 0, 2296 self.editorActGrp, 2297 'vm_edit_extend_rect_selection_first_visible_char') 2298 if not isMacPlatform(): 2299 act.setShortcut(QKeySequence( 2300 QCoreApplication.translate('ViewManager', 'Alt+Shift+Home'))) 2301 self.esm.setMapping(act, QsciScintilla.SCI_VCHOMERECTEXTEND) 2302 act.triggered.connect(self.esm.map) 2303 self.editActions.append(act) 2304 2305 act = E5Action( 2306 QCoreApplication.translate( 2307 'ViewManager', 2308 'Extend rectangular selection to end of document line'), 2309 QCoreApplication.translate( 2310 'ViewManager', 2311 'Extend rectangular selection to end of document line'), 2312 0, 0, 2313 self.editorActGrp, 'vm_edit_extend_rect_selection_end_line') 2314 if isMacPlatform(): 2315 act.setShortcut(QKeySequence( 2316 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+E'))) 2317 else: 2318 act.setShortcut(QKeySequence( 2319 QCoreApplication.translate('ViewManager', 'Alt+Shift+End'))) 2320 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDRECTEXTEND) 2321 act.triggered.connect(self.esm.map) 2322 self.editActions.append(act) 2323 2324 act = E5Action( 2325 QCoreApplication.translate( 2326 'ViewManager', 2327 'Extend rectangular selection up one page'), 2328 QCoreApplication.translate( 2329 'ViewManager', 2330 'Extend rectangular selection up one page'), 2331 QKeySequence(QCoreApplication.translate( 2332 'ViewManager', 'Alt+Shift+PgUp')), 2333 0, 2334 self.editorActGrp, 'vm_edit_extend_rect_selection_up_page') 2335 self.esm.setMapping(act, QsciScintilla.SCI_PAGEUPRECTEXTEND) 2336 act.triggered.connect(self.esm.map) 2337 self.editActions.append(act) 2338 2339 act = E5Action( 2340 QCoreApplication.translate( 2341 'ViewManager', 2342 'Extend rectangular selection down one page'), 2343 QCoreApplication.translate( 2344 'ViewManager', 2345 'Extend rectangular selection down one page'), 2346 QKeySequence(QCoreApplication.translate( 2347 'ViewManager', 'Alt+Shift+PgDown')), 2348 0, 2349 self.editorActGrp, 'vm_edit_extend_rect_selection_down_page') 2350 if isMacPlatform(): 2351 act.setAlternateShortcut(QKeySequence( 2352 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+V'))) 2353 self.esm.setMapping(act, QsciScintilla.SCI_PAGEDOWNRECTEXTEND) 2354 act.triggered.connect(self.esm.map) 2355 self.editActions.append(act) 2356 2357 act = E5Action( 2358 QCoreApplication.translate( 2359 'ViewManager', 'Duplicate current selection'), 2360 QCoreApplication.translate( 2361 'ViewManager', 'Duplicate current selection'), 2362 QKeySequence(QCoreApplication.translate( 2363 'ViewManager', 'Ctrl+Shift+D')), 2364 0, 2365 self.editorActGrp, 'vm_edit_duplicate_current_selection') 2366 self.esm.setMapping(act, QsciScintilla.SCI_SELECTIONDUPLICATE) 2367 act.triggered.connect(self.esm.map) 2368 self.editActions.append(act) 2369 2370 if hasattr(QsciScintilla, "SCI_SCROLLTOSTART"): 2371 act = E5Action( 2372 QCoreApplication.translate( 2373 'ViewManager', 'Scroll to start of document'), 2374 QCoreApplication.translate( 2375 'ViewManager', 'Scroll to start of document'), 2376 0, 0, 2377 self.editorActGrp, 'vm_edit_scroll_start_text') 2378 if isMacPlatform(): 2379 act.setShortcut(QKeySequence( 2380 QCoreApplication.translate('ViewManager', 'Home'))) 2381 self.esm.setMapping(act, QsciScintilla.SCI_SCROLLTOSTART) 2382 act.triggered.connect(self.esm.map) 2383 self.editActions.append(act) 2384 2385 if hasattr(QsciScintilla, "SCI_SCROLLTOEND"): 2386 act = E5Action( 2387 QCoreApplication.translate( 2388 'ViewManager', 'Scroll to end of document'), 2389 QCoreApplication.translate( 2390 'ViewManager', 'Scroll to end of document'), 2391 0, 0, 2392 self.editorActGrp, 'vm_edit_scroll_end_text') 2393 if isMacPlatform(): 2394 act.setShortcut(QKeySequence( 2395 QCoreApplication.translate('ViewManager', 'End'))) 2396 self.esm.setMapping(act, QsciScintilla.SCI_SCROLLTOEND) 2397 act.triggered.connect(self.esm.map) 2398 self.editActions.append(act) 2399 2400 if hasattr(QsciScintilla, "SCI_VERTICALCENTRECARET"): 2401 act = E5Action( 2402 QCoreApplication.translate( 2403 'ViewManager', 'Scroll vertically to center current line'), 2404 QCoreApplication.translate( 2405 'ViewManager', 'Scroll vertically to center current line'), 2406 0, 0, 2407 self.editorActGrp, 'vm_edit_scroll_vertically_center') 2408 if isMacPlatform(): 2409 act.setShortcut(QKeySequence( 2410 QCoreApplication.translate('ViewManager', 'Meta+L'))) 2411 self.esm.setMapping(act, QsciScintilla.SCI_VERTICALCENTRECARET) 2412 act.triggered.connect(self.esm.map) 2413 self.editActions.append(act) 2414 2415 if hasattr(QsciScintilla, "SCI_WORDRIGHTEND"): 2416 act = E5Action( 2417 QCoreApplication.translate( 2418 'ViewManager', 'Move to end of next word'), 2419 QCoreApplication.translate( 2420 'ViewManager', 'Move to end of next word'), 2421 0, 0, 2422 self.editorActGrp, 'vm_edit_move_end_next_word') 2423 if isMacPlatform(): 2424 act.setShortcut(QKeySequence( 2425 QCoreApplication.translate('ViewManager', 'Alt+Right'))) 2426 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHTEND) 2427 act.triggered.connect(self.esm.map) 2428 self.editActions.append(act) 2429 2430 if hasattr(QsciScintilla, "SCI_WORDRIGHTENDEXTEND"): 2431 act = E5Action( 2432 QCoreApplication.translate( 2433 'ViewManager', 'Extend selection to end of next word'), 2434 QCoreApplication.translate( 2435 'ViewManager', 'Extend selection to end of next word'), 2436 0, 0, 2437 self.editorActGrp, 'vm_edit_select_end_next_word') 2438 if isMacPlatform(): 2439 act.setShortcut(QKeySequence( 2440 QCoreApplication.translate('ViewManager', 2441 'Alt+Shift+Right'))) 2442 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHTENDEXTEND) 2443 act.triggered.connect(self.esm.map) 2444 self.editActions.append(act) 2445 2446 if hasattr(QsciScintilla, "SCI_WORDLEFTEND"): 2447 act = E5Action( 2448 QCoreApplication.translate( 2449 'ViewManager', 'Move to end of previous word'), 2450 QCoreApplication.translate( 2451 'ViewManager', 'Move to end of previous word'), 2452 0, 0, 2453 self.editorActGrp, 'vm_edit_move_end_previous_word') 2454 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFTEND) 2455 act.triggered.connect(self.esm.map) 2456 self.editActions.append(act) 2457 2458 if hasattr(QsciScintilla, "SCI_WORDLEFTENDEXTEND"): 2459 act = E5Action( 2460 QCoreApplication.translate( 2461 'ViewManager', 'Extend selection to end of previous word'), 2462 QCoreApplication.translate( 2463 'ViewManager', 'Extend selection to end of previous word'), 2464 0, 0, 2465 self.editorActGrp, 'vm_edit_select_end_previous_word') 2466 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFTENDEXTEND) 2467 act.triggered.connect(self.esm.map) 2468 self.editActions.append(act) 2469 2470 if hasattr(QsciScintilla, "SCI_HOME"): 2471 act = E5Action( 2472 QCoreApplication.translate( 2473 'ViewManager', 'Move to start of document line'), 2474 QCoreApplication.translate( 2475 'ViewManager', 'Move to start of document line'), 2476 0, 0, 2477 self.editorActGrp, 'vm_edit_move_start_document_line') 2478 if isMacPlatform(): 2479 act.setShortcut(QKeySequence( 2480 QCoreApplication.translate('ViewManager', 'Meta+A'))) 2481 self.esm.setMapping(act, QsciScintilla.SCI_HOME) 2482 act.triggered.connect(self.esm.map) 2483 self.editActions.append(act) 2484 2485 if hasattr(QsciScintilla, "SCI_HOMEEXTEND"): 2486 act = E5Action( 2487 QCoreApplication.translate( 2488 'ViewManager', 2489 'Extend selection to start of document line'), 2490 QCoreApplication.translate( 2491 'ViewManager', 2492 'Extend selection to start of document line'), 2493 0, 0, 2494 self.editorActGrp, 2495 'vm_edit_extend_selection_start_document_line') 2496 if isMacPlatform(): 2497 act.setShortcut(QKeySequence( 2498 QCoreApplication.translate('ViewManager', 'Meta+Shift+A'))) 2499 self.esm.setMapping(act, QsciScintilla.SCI_HOMEEXTEND) 2500 act.triggered.connect(self.esm.map) 2501 self.editActions.append(act) 2502 2503 if hasattr(QsciScintilla, "SCI_HOMERECTEXTEND"): 2504 act = E5Action( 2505 QCoreApplication.translate( 2506 'ViewManager', 2507 'Extend rectangular selection to start of document line'), 2508 QCoreApplication.translate( 2509 'ViewManager', 2510 'Extend rectangular selection to start of document line'), 2511 0, 0, 2512 self.editorActGrp, 'vm_edit_select_rect_start_line') 2513 if isMacPlatform(): 2514 act.setShortcut(QKeySequence( 2515 QCoreApplication.translate('ViewManager', 2516 'Meta+Alt+Shift+A'))) 2517 self.esm.setMapping(act, QsciScintilla.SCI_HOMERECTEXTEND) 2518 act.triggered.connect(self.esm.map) 2519 self.editActions.append(act) 2520 2521 if hasattr(QsciScintilla, "SCI_HOMEDISPLAYEXTEND"): 2522 act = E5Action( 2523 QCoreApplication.translate( 2524 'ViewManager', 2525 'Extend selection to start of display line'), 2526 QCoreApplication.translate( 2527 'ViewManager', 2528 'Extend selection to start of display line'), 2529 0, 0, 2530 self.editorActGrp, 2531 'vm_edit_extend_selection_start_display_line') 2532 if isMacPlatform(): 2533 act.setShortcut(QKeySequence( 2534 QCoreApplication.translate('ViewManager', 2535 'Ctrl+Shift+Left'))) 2536 self.esm.setMapping(act, QsciScintilla.SCI_HOMEDISPLAYEXTEND) 2537 act.triggered.connect(self.esm.map) 2538 self.editActions.append(act) 2539 2540 if hasattr(QsciScintilla, "SCI_HOMEWRAP"): 2541 act = E5Action( 2542 QCoreApplication.translate( 2543 'ViewManager', 2544 'Move to start of display or document line'), 2545 QCoreApplication.translate( 2546 'ViewManager', 2547 'Move to start of display or document line'), 2548 0, 0, 2549 self.editorActGrp, 'vm_edit_move_start_display_document_line') 2550 self.esm.setMapping(act, QsciScintilla.SCI_HOMEWRAP) 2551 act.triggered.connect(self.esm.map) 2552 self.editActions.append(act) 2553 2554 if hasattr(QsciScintilla, "SCI_HOMEWRAPEXTEND"): 2555 act = E5Action( 2556 QCoreApplication.translate( 2557 'ViewManager', 2558 'Extend selection to start of display or document line'), 2559 QCoreApplication.translate( 2560 'ViewManager', 2561 'Extend selection to start of display or document line'), 2562 0, 0, 2563 self.editorActGrp, 2564 'vm_edit_extend_selection_start_display_document_line') 2565 self.esm.setMapping(act, QsciScintilla.SCI_HOMEWRAPEXTEND) 2566 act.triggered.connect(self.esm.map) 2567 self.editActions.append(act) 2568 2569 if hasattr(QsciScintilla, "SCI_VCHOMEWRAP"): 2570 act = E5Action( 2571 QCoreApplication.translate( 2572 'ViewManager', 2573 'Move to first visible character in display or document' 2574 ' line'), 2575 QCoreApplication.translate( 2576 'ViewManager', 2577 'Move to first visible character in display or document' 2578 ' line'), 2579 0, 0, 2580 self.editorActGrp, 2581 'vm_edit_move_first_visible_char_document_line') 2582 self.esm.setMapping(act, QsciScintilla.SCI_VCHOMEWRAP) 2583 act.triggered.connect(self.esm.map) 2584 self.editActions.append(act) 2585 2586 if hasattr(QsciScintilla, "SCI_VCHOMEWRAPEXTEND"): 2587 act = E5Action( 2588 QCoreApplication.translate( 2589 'ViewManager', 2590 'Extend selection to first visible character in' 2591 ' display or document line'), 2592 QCoreApplication.translate( 2593 'ViewManager', 2594 'Extend selection to first visible character in' 2595 ' display or document line'), 2596 0, 0, 2597 self.editorActGrp, 2598 'vm_edit_extend_selection_first_visible_char_document_line') 2599 self.esm.setMapping(act, QsciScintilla.SCI_VCHOMEWRAPEXTEND) 2600 act.triggered.connect(self.esm.map) 2601 self.editActions.append(act) 2602 2603 if hasattr(QsciScintilla, "SCI_LINEENDWRAP"): 2604 act = E5Action( 2605 QCoreApplication.translate( 2606 'ViewManager', 2607 'Move to end of display or document line'), 2608 QCoreApplication.translate( 2609 'ViewManager', 2610 'Move to end of display or document line'), 2611 0, 0, 2612 self.editorActGrp, 'vm_edit_end_start_display_document_line') 2613 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDWRAP) 2614 act.triggered.connect(self.esm.map) 2615 self.editActions.append(act) 2616 2617 if hasattr(QsciScintilla, "SCI_LINEENDWRAPEXTEND"): 2618 act = E5Action( 2619 QCoreApplication.translate( 2620 'ViewManager', 2621 'Extend selection to end of display or document line'), 2622 QCoreApplication.translate( 2623 'ViewManager', 2624 'Extend selection to end of display or document line'), 2625 0, 0, 2626 self.editorActGrp, 2627 'vm_edit_extend_selection_end_display_document_line') 2628 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDWRAPEXTEND) 2629 act.triggered.connect(self.esm.map) 2630 self.editActions.append(act) 2631 2632 if hasattr(QsciScintilla, "SCI_STUTTEREDPAGEUP"): 2633 act = E5Action( 2634 QCoreApplication.translate( 2635 'ViewManager', 'Stuttered move up one page'), 2636 QCoreApplication.translate( 2637 'ViewManager', 'Stuttered move up one page'), 2638 0, 0, 2639 self.editorActGrp, 'vm_edit_stuttered_move_up_page') 2640 self.esm.setMapping(act, QsciScintilla.SCI_STUTTEREDPAGEUP) 2641 act.triggered.connect(self.esm.map) 2642 self.editActions.append(act) 2643 2644 if hasattr(QsciScintilla, "SCI_STUTTEREDPAGEUPEXTEND"): 2645 act = E5Action( 2646 QCoreApplication.translate( 2647 'ViewManager', 'Stuttered extend selection up one page'), 2648 QCoreApplication.translate( 2649 'ViewManager', 'Stuttered extend selection up one page'), 2650 0, 0, 2651 self.editorActGrp, 2652 'vm_edit_stuttered_extend_selection_up_page') 2653 self.esm.setMapping(act, QsciScintilla.SCI_STUTTEREDPAGEUPEXTEND) 2654 act.triggered.connect(self.esm.map) 2655 self.editActions.append(act) 2656 2657 if hasattr(QsciScintilla, "SCI_STUTTEREDPAGEDOWN"): 2658 act = E5Action( 2659 QCoreApplication.translate( 2660 'ViewManager', 'Stuttered move down one page'), 2661 QCoreApplication.translate( 2662 'ViewManager', 'Stuttered move down one page'), 2663 0, 0, 2664 self.editorActGrp, 'vm_edit_stuttered_move_down_page') 2665 self.esm.setMapping(act, QsciScintilla.SCI_STUTTEREDPAGEDOWN) 2666 act.triggered.connect(self.esm.map) 2667 self.editActions.append(act) 2668 2669 if hasattr(QsciScintilla, "SCI_STUTTEREDPAGEDOWNEXTEND"): 2670 act = E5Action( 2671 QCoreApplication.translate( 2672 'ViewManager', 'Stuttered extend selection down one page'), 2673 QCoreApplication.translate( 2674 'ViewManager', 'Stuttered extend selection down one page'), 2675 0, 0, 2676 self.editorActGrp, 2677 'vm_edit_stuttered_extend_selection_down_page') 2678 self.esm.setMapping(act, QsciScintilla.SCI_STUTTEREDPAGEDOWNEXTEND) 2679 act.triggered.connect(self.esm.map) 2680 self.editActions.append(act) 2681 2682 if hasattr(QsciScintilla, "SCI_DELWORDRIGHTEND"): 2683 act = E5Action( 2684 QCoreApplication.translate( 2685 'ViewManager', 'Delete right to end of next word'), 2686 QCoreApplication.translate( 2687 'ViewManager', 'Delete right to end of next word'), 2688 0, 0, 2689 self.editorActGrp, 'vm_edit_delete_right_end_next_word') 2690 if isMacPlatform(): 2691 act.setShortcut(QKeySequence( 2692 QCoreApplication.translate('ViewManager', 'Alt+Del'))) 2693 self.esm.setMapping(act, QsciScintilla.SCI_DELWORDRIGHTEND) 2694 act.triggered.connect(self.esm.map) 2695 self.editActions.append(act) 2696 2697 if hasattr(QsciScintilla, "SCI_MOVESELECTEDLINESUP"): 2698 act = E5Action( 2699 QCoreApplication.translate( 2700 'ViewManager', 'Move selected lines up one line'), 2701 QCoreApplication.translate( 2702 'ViewManager', 'Move selected lines up one line'), 2703 0, 0, 2704 self.editorActGrp, 'vm_edit_move_selection_up_one_line') 2705 self.esm.setMapping(act, QsciScintilla.SCI_MOVESELECTEDLINESUP) 2706 act.triggered.connect(self.esm.map) 2707 self.editActions.append(act) 2708 2709 if hasattr(QsciScintilla, "SCI_MOVESELECTEDLINESDOWN"): 2710 act = E5Action( 2711 QCoreApplication.translate( 2712 'ViewManager', 'Move selected lines down one line'), 2713 QCoreApplication.translate( 2714 'ViewManager', 'Move selected lines down one line'), 2715 0, 0, 2716 self.editorActGrp, 'vm_edit_move_selection_down_one_line') 2717 self.esm.setMapping(act, QsciScintilla.SCI_MOVESELECTEDLINESDOWN) 2718 act.triggered.connect(self.esm.map) 2719 self.editActions.append(act) 2720 2721 self.editorActGrp.setEnabled(False) 2722 2723 self.editLowerCaseAct = E5Action( 2724 QCoreApplication.translate( 2725 'ViewManager', 'Convert selection to lower case'), 2726 QCoreApplication.translate( 2727 'ViewManager', 'Convert selection to lower case'), 2728 QKeySequence(QCoreApplication.translate('ViewManager', 2729 'Alt+Shift+U')), 2730 0, self.editActGrp, 'vm_edit_convert_selection_lower') 2731 self.esm.setMapping(self.editLowerCaseAct, QsciScintilla.SCI_LOWERCASE) 2732 self.editLowerCaseAct.triggered.connect(self.esm.map) 2733 self.editActions.append(self.editLowerCaseAct) 2734 2735 self.editUpperCaseAct = E5Action( 2736 QCoreApplication.translate( 2737 'ViewManager', 'Convert selection to upper case'), 2738 QCoreApplication.translate( 2739 'ViewManager', 'Convert selection to upper case'), 2740 QKeySequence(QCoreApplication.translate( 2741 'ViewManager', 'Ctrl+Shift+U')), 2742 0, 2743 self.editActGrp, 'vm_edit_convert_selection_upper') 2744 self.esm.setMapping(self.editUpperCaseAct, QsciScintilla.SCI_UPPERCASE) 2745 self.editUpperCaseAct.triggered.connect(self.esm.map) 2746 self.editActions.append(self.editUpperCaseAct) 2747 2748 def initEditMenu(self): 2749 """ 2750 Public method to create the Edit menu. 2751 2752 @return the generated menu 2753 """ 2754 autocompletionMenu = QMenu( 2755 QCoreApplication.translate('ViewManager', 'Complete'), 2756 self.ui) 2757 autocompletionMenu.setTearOffEnabled(True) 2758 autocompletionMenu.addAction(self.autoCompleteAct) 2759 autocompletionMenu.addSeparator() 2760 autocompletionMenu.addAction(self.autoCompleteFromDocAct) 2761 autocompletionMenu.addAction(self.autoCompleteFromAPIsAct) 2762 autocompletionMenu.addAction(self.autoCompleteFromAllAct) 2763 2764 menu = QMenu(QCoreApplication.translate('ViewManager', '&Edit'), 2765 self.ui) 2766 menu.setTearOffEnabled(True) 2767 menu.addAction(self.undoAct) 2768 menu.addAction(self.redoAct) 2769 menu.addAction(self.revertAct) 2770 menu.addSeparator() 2771 menu.addAction(self.cutAct) 2772 menu.addAction(self.copyAct) 2773 menu.addAction(self.pasteAct) 2774 menu.addAction(self.deleteAct) 2775 menu.addSeparator() 2776 menu.addAction(self.indentAct) 2777 menu.addAction(self.unindentAct) 2778 menu.addAction(self.smartIndentAct) 2779 menu.addSeparator() 2780 menu.addAction(self.commentAct) 2781 menu.addAction(self.uncommentAct) 2782 menu.addAction(self.toggleCommentAct) 2783 menu.addAction(self.streamCommentAct) 2784 menu.addAction(self.boxCommentAct) 2785 menu.addSeparator() 2786 menu.addAction(self.docstringAct) 2787 menu.addSeparator() 2788 menu.addAction(self.editUpperCaseAct) 2789 menu.addAction(self.editLowerCaseAct) 2790 menu.addAction(self.sortAct) 2791 menu.addSeparator() 2792 menu.addMenu(autocompletionMenu) 2793 menu.addAction(self.calltipsAct) 2794 menu.addAction(self.codeInfoAct) 2795 menu.addSeparator() 2796 menu.addAction(self.gotoAct) 2797 menu.addAction(self.gotoBraceAct) 2798 menu.addAction(self.gotoLastEditAct) 2799 menu.addAction(self.gotoPreviousDefAct) 2800 menu.addAction(self.gotoNextDefAct) 2801 menu.addSeparator() 2802 menu.addAction(self.selectBraceAct) 2803 menu.addAction(self.selectAllAct) 2804 menu.addAction(self.deselectAllAct) 2805 menu.addSeparator() 2806 menu.addAction(self.shortenEmptyAct) 2807 menu.addAction(self.convertEOLAct) 2808 2809 return menu 2810 2811 def initEditToolbar(self, toolbarManager): 2812 """ 2813 Public method to create the Edit toolbar. 2814 2815 @param toolbarManager reference to a toolbar manager object 2816 (E5ToolBarManager) 2817 @return the generated toolbar 2818 """ 2819 tb = QToolBar(QCoreApplication.translate('ViewManager', 'Edit'), 2820 self.ui) 2821 tb.setIconSize(UI.Config.ToolBarIconSize) 2822 tb.setObjectName("EditToolbar") 2823 tb.setToolTip(QCoreApplication.translate('ViewManager', 'Edit')) 2824 2825 tb.addAction(self.undoAct) 2826 tb.addAction(self.redoAct) 2827 tb.addSeparator() 2828 tb.addAction(self.cutAct) 2829 tb.addAction(self.copyAct) 2830 tb.addAction(self.pasteAct) 2831 tb.addAction(self.deleteAct) 2832 tb.addSeparator() 2833 tb.addAction(self.commentAct) 2834 tb.addAction(self.uncommentAct) 2835 tb.addAction(self.toggleCommentAct) 2836 2837 toolbarManager.addToolBar(tb, tb.windowTitle()) 2838 toolbarManager.addAction(self.smartIndentAct, tb.windowTitle()) 2839 toolbarManager.addAction(self.indentAct, tb.windowTitle()) 2840 toolbarManager.addAction(self.unindentAct, tb.windowTitle()) 2841 2842 return tb 2843 2844 ################################################################## 2845 ## Initialize the search related actions and the search toolbar 2846 ################################################################## 2847 2848 def __initSearchActions(self): 2849 """ 2850 Private method defining the user interface actions for the search 2851 commands. 2852 """ 2853 self.searchActGrp = createActionGroup(self) 2854 2855 self.searchAct = E5Action( 2856 QCoreApplication.translate('ViewManager', 'Search'), 2857 UI.PixmapCache.getIcon("find"), 2858 QCoreApplication.translate('ViewManager', '&Search...'), 2859 QKeySequence(QCoreApplication.translate( 2860 'ViewManager', "Ctrl+F", "Search|Search")), 2861 0, 2862 self.searchActGrp, 'vm_search') 2863 self.searchAct.setStatusTip(QCoreApplication.translate( 2864 'ViewManager', 'Search for a text')) 2865 self.searchAct.setWhatsThis(QCoreApplication.translate( 2866 'ViewManager', 2867 """<b>Search</b>""" 2868 """<p>Search for some text in the current editor. A""" 2869 """ dialog is shown to enter the searchtext and options""" 2870 """ for the search.</p>""" 2871 )) 2872 self.searchAct.triggered.connect(self.showSearchWidget) 2873 self.searchActions.append(self.searchAct) 2874 2875 self.searchNextAct = E5Action( 2876 QCoreApplication.translate( 2877 'ViewManager', 'Search next'), 2878 UI.PixmapCache.getIcon("findNext"), 2879 QCoreApplication.translate('ViewManager', 'Search &next'), 2880 QKeySequence(QCoreApplication.translate( 2881 'ViewManager', "F3", "Search|Search next")), 2882 0, 2883 self.searchActGrp, 'vm_search_next') 2884 self.searchNextAct.setStatusTip(QCoreApplication.translate( 2885 'ViewManager', 'Search next occurrence of text')) 2886 self.searchNextAct.setWhatsThis(QCoreApplication.translate( 2887 'ViewManager', 2888 """<b>Search next</b>""" 2889 """<p>Search the next occurrence of some text in the current""" 2890 """ editor. The previously entered searchtext and options are""" 2891 """ reused.</p>""" 2892 )) 2893 self.searchNextAct.triggered.connect(self.__searchNext) 2894 self.searchActions.append(self.searchNextAct) 2895 2896 self.searchPrevAct = E5Action( 2897 QCoreApplication.translate('ViewManager', 'Search previous'), 2898 UI.PixmapCache.getIcon("findPrev"), 2899 QCoreApplication.translate('ViewManager', 'Search &previous'), 2900 QKeySequence(QCoreApplication.translate( 2901 'ViewManager', "Shift+F3", "Search|Search previous")), 2902 0, 2903 self.searchActGrp, 'vm_search_previous') 2904 self.searchPrevAct.setStatusTip(QCoreApplication.translate( 2905 'ViewManager', 'Search previous occurrence of text')) 2906 self.searchPrevAct.setWhatsThis(QCoreApplication.translate( 2907 'ViewManager', 2908 """<b>Search previous</b>""" 2909 """<p>Search the previous occurrence of some text in the current""" 2910 """ editor. The previously entered searchtext and options are""" 2911 """ reused.</p>""" 2912 )) 2913 self.searchPrevAct.triggered.connect(self.__searchPrev) 2914 self.searchActions.append(self.searchPrevAct) 2915 2916 self.searchClearMarkersAct = E5Action( 2917 QCoreApplication.translate('ViewManager', 'Clear search markers'), 2918 UI.PixmapCache.getIcon("findClear"), 2919 QCoreApplication.translate('ViewManager', 'Clear search markers'), 2920 QKeySequence(QCoreApplication.translate( 2921 'ViewManager', "Ctrl+3", "Search|Clear search markers")), 2922 0, 2923 self.searchActGrp, 'vm_clear_search_markers') 2924 self.searchClearMarkersAct.setStatusTip(QCoreApplication.translate( 2925 'ViewManager', 'Clear all displayed search markers')) 2926 self.searchClearMarkersAct.setWhatsThis(QCoreApplication.translate( 2927 'ViewManager', 2928 """<b>Clear search markers</b>""" 2929 """<p>Clear all displayed search markers.</p>""" 2930 )) 2931 self.searchClearMarkersAct.triggered.connect( 2932 self.__searchClearMarkers) 2933 self.searchActions.append(self.searchClearMarkersAct) 2934 2935 self.searchNextWordAct = E5Action( 2936 QCoreApplication.translate( 2937 'ViewManager', 'Search current word forward'), 2938 UI.PixmapCache.getIcon("findWordNext"), 2939 QCoreApplication.translate( 2940 'ViewManager', 'Search current word forward'), 2941 QKeySequence(QCoreApplication.translate( 2942 'ViewManager', 2943 "Ctrl+.", "Search|Search current word forward")), 2944 0, 2945 self.searchActGrp, 'vm_search_word_next') 2946 self.searchNextWordAct.setStatusTip(QCoreApplication.translate( 2947 'ViewManager', 2948 'Search next occurrence of the current word')) 2949 self.searchNextWordAct.setWhatsThis(QCoreApplication.translate( 2950 'ViewManager', 2951 """<b>Search current word forward</b>""" 2952 """<p>Search the next occurrence of the current word of the""" 2953 """ current editor.</p>""" 2954 )) 2955 self.searchNextWordAct.triggered.connect(self.__findNextWord) 2956 self.searchActions.append(self.searchNextWordAct) 2957 2958 self.searchPrevWordAct = E5Action( 2959 QCoreApplication.translate( 2960 'ViewManager', 'Search current word backward'), 2961 UI.PixmapCache.getIcon("findWordPrev"), 2962 QCoreApplication.translate( 2963 'ViewManager', 'Search current word backward'), 2964 QKeySequence(QCoreApplication.translate( 2965 'ViewManager', 2966 "Ctrl+,", "Search|Search current word backward")), 2967 0, 2968 self.searchActGrp, 'vm_search_word_previous') 2969 self.searchPrevWordAct.setStatusTip(QCoreApplication.translate( 2970 'ViewManager', 2971 'Search previous occurrence of the current word')) 2972 self.searchPrevWordAct.setWhatsThis(QCoreApplication.translate( 2973 'ViewManager', 2974 """<b>Search current word backward</b>""" 2975 """<p>Search the previous occurrence of the current word of the""" 2976 """ current editor.</p>""" 2977 )) 2978 self.searchPrevWordAct.triggered.connect(self.__findPrevWord) 2979 self.searchActions.append(self.searchPrevWordAct) 2980 2981 self.replaceAct = E5Action( 2982 QCoreApplication.translate('ViewManager', 'Replace'), 2983 QCoreApplication.translate('ViewManager', '&Replace...'), 2984 QKeySequence(QCoreApplication.translate( 2985 'ViewManager', "Ctrl+R", "Search|Replace")), 2986 0, 2987 self.searchActGrp, 'vm_search_replace') 2988 self.replaceAct.setStatusTip(QCoreApplication.translate( 2989 'ViewManager', 'Replace some text')) 2990 self.replaceAct.setWhatsThis(QCoreApplication.translate( 2991 'ViewManager', 2992 """<b>Replace</b>""" 2993 """<p>Search for some text in the current editor and replace it.""" 2994 """ A dialog is shown to enter the searchtext, the replacement""" 2995 """ text and options for the search and replace.</p>""" 2996 )) 2997 self.replaceAct.triggered.connect(self.showReplaceWidget) 2998 self.searchActions.append(self.replaceAct) 2999 3000 self.replaceAndSearchAct = E5Action( 3001 QCoreApplication.translate( 3002 'ViewManager', 'Replace and Search'), 3003 UI.PixmapCache.getIcon("editReplaceSearch"), 3004 QCoreApplication.translate( 3005 'ViewManager', 'Replace and Search'), 3006 QKeySequence(QCoreApplication.translate( 3007 'ViewManager', "Meta+R", "Search|Replace and Search")), 3008 0, 3009 self.searchActGrp, 'vm_replace_search') 3010 self.replaceAndSearchAct.setStatusTip(QCoreApplication.translate( 3011 'ViewManager', 3012 'Replace the found text and search the next occurrence')) 3013 self.replaceAndSearchAct.setWhatsThis(QCoreApplication.translate( 3014 'ViewManager', 3015 """<b>Replace and Search</b>""" 3016 """<p>Replace the found occurrence of text in the current""" 3017 """ editor and search for the next one. The previously entered""" 3018 """ search text and options are reused.</p>""" 3019 )) 3020 self.replaceAndSearchAct.triggered.connect( 3021 self.__replaceWidget.replaceSearch) 3022 self.searchActions.append(self.replaceAndSearchAct) 3023 3024 self.replaceSelectionAct = E5Action( 3025 QCoreApplication.translate( 3026 'ViewManager', 'Replace Occurrence'), 3027 UI.PixmapCache.getIcon("editReplace"), 3028 QCoreApplication.translate( 3029 'ViewManager', 'Replace Occurrence'), 3030 QKeySequence(QCoreApplication.translate( 3031 'ViewManager', "Ctrl+Meta+R", "Search|Replace Occurrence")), 3032 0, 3033 self.searchActGrp, 'vm_replace_occurrence') 3034 self.replaceSelectionAct.setStatusTip(QCoreApplication.translate( 3035 'ViewManager', 'Replace the found text')) 3036 self.replaceSelectionAct.setWhatsThis(QCoreApplication.translate( 3037 'ViewManager', 3038 """<b>Replace Occurrence</b>""" 3039 """<p>Replace the found occurrence of the search text in the""" 3040 """ current editor.</p>""" 3041 )) 3042 self.replaceSelectionAct.triggered.connect( 3043 self.__replaceWidget.replace) 3044 self.searchActions.append(self.replaceSelectionAct) 3045 3046 self.replaceAllAct = E5Action( 3047 QCoreApplication.translate( 3048 'ViewManager', 'Replace All'), 3049 UI.PixmapCache.getIcon("editReplaceAll"), 3050 QCoreApplication.translate( 3051 'ViewManager', 'Replace All'), 3052 QKeySequence(QCoreApplication.translate( 3053 'ViewManager', "Shift+Meta+R", "Search|Replace All")), 3054 0, 3055 self.searchActGrp, 'vm_replace_all') 3056 self.replaceAllAct.setStatusTip(QCoreApplication.translate( 3057 'ViewManager', 'Replace search text occurrences')) 3058 self.replaceAllAct.setWhatsThis(QCoreApplication.translate( 3059 'ViewManager', 3060 """<b>Replace All</b>""" 3061 """<p>Replace all occurrences of the search text in the current""" 3062 """ editor.</p>""" 3063 )) 3064 self.replaceAllAct.triggered.connect( 3065 self.__replaceWidget.replaceAll) 3066 self.searchActions.append(self.replaceAllAct) 3067 3068 self.gotoAct = E5Action( 3069 QCoreApplication.translate('ViewManager', 'Goto Line'), 3070 UI.PixmapCache.getIcon("goto"), 3071 QCoreApplication.translate('ViewManager', '&Goto Line...'), 3072 QKeySequence(QCoreApplication.translate( 3073 'ViewManager', "Ctrl+G", "Search|Goto Line")), 3074 0, 3075 self.searchActGrp, 'vm_search_goto_line') 3076 self.gotoAct.setStatusTip(QCoreApplication.translate( 3077 'ViewManager', 'Goto Line')) 3078 self.gotoAct.setWhatsThis(QCoreApplication.translate( 3079 'ViewManager', 3080 """<b>Goto Line</b>""" 3081 """<p>Go to a specific line of text in the current editor.""" 3082 """ A dialog is shown to enter the linenumber.</p>""" 3083 )) 3084 self.gotoAct.triggered.connect(self.__goto) 3085 self.searchActions.append(self.gotoAct) 3086 3087 self.gotoBraceAct = E5Action( 3088 QCoreApplication.translate('ViewManager', 'Goto Brace'), 3089 UI.PixmapCache.getIcon("gotoBrace"), 3090 QCoreApplication.translate('ViewManager', 'Goto &Brace'), 3091 QKeySequence(QCoreApplication.translate( 3092 'ViewManager', "Ctrl+L", "Search|Goto Brace")), 3093 0, 3094 self.searchActGrp, 'vm_search_goto_brace') 3095 self.gotoBraceAct.setStatusTip(QCoreApplication.translate( 3096 'ViewManager', 'Goto Brace')) 3097 self.gotoBraceAct.setWhatsThis(QCoreApplication.translate( 3098 'ViewManager', 3099 """<b>Goto Brace</b>""" 3100 """<p>Go to the matching brace in the current editor.</p>""" 3101 )) 3102 self.gotoBraceAct.triggered.connect(self.__gotoBrace) 3103 self.searchActions.append(self.gotoBraceAct) 3104 3105 self.gotoLastEditAct = E5Action( 3106 QCoreApplication.translate( 3107 'ViewManager', 'Goto Last Edit Location'), 3108 UI.PixmapCache.getIcon("gotoLastEditPosition"), 3109 QCoreApplication.translate( 3110 'ViewManager', 'Goto Last &Edit Location'), 3111 QKeySequence(QCoreApplication.translate( 3112 'ViewManager', 3113 "Ctrl+Shift+G", "Search|Goto Last Edit Location")), 3114 0, 3115 self.searchActGrp, 'vm_search_goto_last_edit_location') 3116 self.gotoLastEditAct.setStatusTip( 3117 QCoreApplication.translate( 3118 'ViewManager', 'Goto Last Edit Location')) 3119 self.gotoLastEditAct.setWhatsThis(QCoreApplication.translate( 3120 'ViewManager', 3121 """<b>Goto Last Edit Location</b>""" 3122 """<p>Go to the location of the last edit in the current""" 3123 """ editor.</p>""" 3124 )) 3125 self.gotoLastEditAct.triggered.connect(self.__gotoLastEditPosition) 3126 self.searchActions.append(self.gotoLastEditAct) 3127 3128 self.gotoPreviousDefAct = E5Action( 3129 QCoreApplication.translate( 3130 'ViewManager', 'Goto Previous Method or Class'), 3131 QCoreApplication.translate( 3132 'ViewManager', 'Goto Previous Method or Class'), 3133 QKeySequence(QCoreApplication.translate( 3134 'ViewManager', 3135 "Ctrl+Shift+Up", "Search|Goto Previous Method or Class")), 3136 0, 3137 self.searchActGrp, 'vm_search_goto_previous_method_or_class') 3138 self.gotoPreviousDefAct.setStatusTip( 3139 QCoreApplication.translate( 3140 'ViewManager', 3141 'Go to the previous method or class definition')) 3142 self.gotoPreviousDefAct.setWhatsThis(QCoreApplication.translate( 3143 'ViewManager', 3144 """<b>Goto Previous Method or Class</b>""" 3145 """<p>Goes to the line of the previous method or class""" 3146 """ definition and highlights the name.</p>""" 3147 )) 3148 self.gotoPreviousDefAct.triggered.connect( 3149 self.__gotoPreviousMethodClass) 3150 self.searchActions.append(self.gotoPreviousDefAct) 3151 3152 self.gotoNextDefAct = E5Action( 3153 QCoreApplication.translate( 3154 'ViewManager', 'Goto Next Method or Class'), 3155 QCoreApplication.translate( 3156 'ViewManager', 'Goto Next Method or Class'), 3157 QKeySequence(QCoreApplication.translate( 3158 'ViewManager', 3159 "Ctrl+Shift+Down", "Search|Goto Next Method or Class")), 3160 0, 3161 self.searchActGrp, 'vm_search_goto_next_method_or_class') 3162 self.gotoNextDefAct.setStatusTip(QCoreApplication.translate( 3163 'ViewManager', 'Go to the next method or class definition')) 3164 self.gotoNextDefAct.setWhatsThis(QCoreApplication.translate( 3165 'ViewManager', 3166 """<b>Goto Next Method or Class</b>""" 3167 """<p>Goes to the line of the next method or class definition""" 3168 """ and highlights the name.</p>""" 3169 )) 3170 self.gotoNextDefAct.triggered.connect(self.__gotoNextMethodClass) 3171 self.searchActions.append(self.gotoNextDefAct) 3172 3173 self.searchActGrp.setEnabled(False) 3174 3175 self.searchFilesAct = E5Action( 3176 QCoreApplication.translate('ViewManager', 'Search in Files'), 3177 UI.PixmapCache.getIcon("projectFind"), 3178 QCoreApplication.translate('ViewManager', 'Search in &Files...'), 3179 QKeySequence(QCoreApplication.translate( 3180 'ViewManager', "Shift+Ctrl+F", "Search|Search Files")), 3181 0, 3182 self, 'vm_search_in_files') 3183 self.searchFilesAct.setStatusTip(QCoreApplication.translate( 3184 'ViewManager', 'Search for a text in files')) 3185 self.searchFilesAct.setWhatsThis(QCoreApplication.translate( 3186 'ViewManager', 3187 """<b>Search in Files</b>""" 3188 """<p>Search for some text in the files of a directory tree""" 3189 """ or the project. A dialog is shown to enter the searchtext""" 3190 """ and options for the search and to display the result.</p>""" 3191 )) 3192 self.searchFilesAct.triggered.connect(self.__searchFiles) 3193 self.searchActions.append(self.searchFilesAct) 3194 3195 self.replaceFilesAct = E5Action( 3196 QCoreApplication.translate('ViewManager', 'Replace in Files'), 3197 QCoreApplication.translate('ViewManager', 'Replace in F&iles...'), 3198 QKeySequence(QCoreApplication.translate( 3199 'ViewManager', "Shift+Ctrl+R", "Search|Replace in Files")), 3200 0, 3201 self, 'vm_replace_in_files') 3202 self.replaceFilesAct.setStatusTip(QCoreApplication.translate( 3203 'ViewManager', 'Search for a text in files and replace it')) 3204 self.replaceFilesAct.setWhatsThis(QCoreApplication.translate( 3205 'ViewManager', 3206 """<b>Replace in Files</b>""" 3207 """<p>Search for some text in the files of a directory tree""" 3208 """ or the project and replace it. A dialog is shown to enter""" 3209 """ the searchtext, the replacement text and options for the""" 3210 """ search and to display the result.</p>""" 3211 )) 3212 self.replaceFilesAct.triggered.connect(self.__replaceFiles) 3213 self.searchActions.append(self.replaceFilesAct) 3214 3215 self.searchOpenFilesAct = E5Action( 3216 QCoreApplication.translate( 3217 'ViewManager', 'Search in Open Files'), 3218 UI.PixmapCache.getIcon("documentFind"), 3219 QCoreApplication.translate( 3220 'ViewManager', 'Search in Open Files...'), 3221 QKeySequence(QCoreApplication.translate( 3222 'ViewManager', 3223 "Meta+Ctrl+Alt+F", "Search|Search Open Files")), 3224 0, 3225 self.searchActGrp, 'vm_search_in_open_files') 3226 self.searchOpenFilesAct.setStatusTip(QCoreApplication.translate( 3227 'ViewManager', 'Search for a text in open files')) 3228 self.searchOpenFilesAct.setWhatsThis(QCoreApplication.translate( 3229 'ViewManager', 3230 """<b>Search in Open Files</b>""" 3231 """<p>Search for some text in the currently opened files.""" 3232 """ A dialog is shown to enter the searchtext""" 3233 """ and options for the search and to display the result.</p>""" 3234 )) 3235 self.searchOpenFilesAct.triggered.connect(self.__searchOpenFiles) 3236 self.searchActions.append(self.searchOpenFilesAct) 3237 3238 self.replaceOpenFilesAct = E5Action( 3239 QCoreApplication.translate( 3240 'ViewManager', 'Replace in Open Files'), 3241 QCoreApplication.translate( 3242 'ViewManager', 'Replace in Open Files...'), 3243 QKeySequence(QCoreApplication.translate( 3244 'ViewManager', 3245 "Meta+Ctrl+Alt+R", "Search|Replace in Open Files")), 3246 0, 3247 self.searchActGrp, 'vm_replace_in_open_files') 3248 self.replaceOpenFilesAct.setStatusTip(QCoreApplication.translate( 3249 'ViewManager', 'Search for a text in open files and replace it')) 3250 self.replaceOpenFilesAct.setWhatsThis(QCoreApplication.translate( 3251 'ViewManager', 3252 """<b>Replace in Open Files</b>""" 3253 """<p>Search for some text in the currently opened files""" 3254 """ and replace it. A dialog is shown to enter""" 3255 """ the searchtext, the replacement text and options for the""" 3256 """ search and to display the result.</p>""" 3257 )) 3258 self.replaceOpenFilesAct.triggered.connect(self.__replaceOpenFiles) 3259 self.searchActions.append(self.replaceOpenFilesAct) 3260 3261 def initSearchMenu(self): 3262 """ 3263 Public method to create the Search menu. 3264 3265 @return the generated menu 3266 @rtype QMenu 3267 """ 3268 menu = QMenu( 3269 QCoreApplication.translate('ViewManager', '&Search'), 3270 self.ui) 3271 menu.setTearOffEnabled(True) 3272 menu.addAction(self.searchAct) 3273 menu.addAction(self.searchNextAct) 3274 menu.addAction(self.searchPrevAct) 3275 menu.addAction(self.searchNextWordAct) 3276 menu.addAction(self.searchPrevWordAct) 3277 menu.addAction(self.replaceAct) 3278 menu.addSeparator() 3279 menu.addAction(self.searchClearMarkersAct) 3280 menu.addSeparator() 3281 menu.addAction(self.searchFilesAct) 3282 menu.addAction(self.replaceFilesAct) 3283 menu.addSeparator() 3284 menu.addAction(self.searchOpenFilesAct) 3285 menu.addAction(self.replaceOpenFilesAct) 3286 3287 return menu 3288 3289 def initSearchToolbar(self, toolbarManager): 3290 """ 3291 Public method to create the Search toolbar. 3292 3293 @param toolbarManager reference to a toolbar manager object 3294 @type E5ToolBarManager 3295 @return generated toolbar 3296 @rtype QToolBar 3297 """ 3298 tb = QToolBar(QCoreApplication.translate('ViewManager', 'Search'), 3299 self.ui) 3300 tb.setIconSize(UI.Config.ToolBarIconSize) 3301 tb.setObjectName("SearchToolbar") 3302 tb.setToolTip(QCoreApplication.translate('ViewManager', 'Search')) 3303 3304 tb.addAction(self.searchAct) 3305 tb.addAction(self.searchNextAct) 3306 tb.addAction(self.searchPrevAct) 3307 tb.addAction(self.searchNextWordAct) 3308 tb.addAction(self.searchPrevWordAct) 3309 tb.addSeparator() 3310 tb.addAction(self.searchClearMarkersAct) 3311 tb.addSeparator() 3312 tb.addAction(self.searchFilesAct) 3313 tb.addAction(self.searchOpenFilesAct) 3314 tb.addSeparator() 3315 tb.addAction(self.gotoLastEditAct) 3316 3317 tb.setAllowedAreas( 3318 Qt.ToolBarAreas(Qt.ToolBarArea.TopToolBarArea | 3319 Qt.ToolBarArea.BottomToolBarArea)) 3320 3321 toolbarManager.addToolBar(tb, tb.windowTitle()) 3322 toolbarManager.addAction(self.gotoAct, tb.windowTitle()) 3323 toolbarManager.addAction(self.gotoBraceAct, tb.windowTitle()) 3324 toolbarManager.addAction(self.replaceSelectionAct, tb.windowTitle()) 3325 toolbarManager.addAction(self.replaceAllAct, tb.windowTitle()) 3326 toolbarManager.addAction(self.replaceAndSearchAct, tb.windowTitle()) 3327 3328 return tb 3329 3330 ################################################################## 3331 ## Initialize the view related actions, view menu and toolbar 3332 ################################################################## 3333 3334 def __initViewActions(self): 3335 """ 3336 Private method defining the user interface actions for the view 3337 commands. 3338 """ 3339 self.viewActGrp = createActionGroup(self) 3340 self.viewFoldActGrp = createActionGroup(self) 3341 3342 self.zoomInAct = E5Action( 3343 QCoreApplication.translate('ViewManager', 'Zoom in'), 3344 UI.PixmapCache.getIcon("zoomIn"), 3345 QCoreApplication.translate('ViewManager', 'Zoom &in'), 3346 QKeySequence(QCoreApplication.translate( 3347 'ViewManager', "Ctrl++", "View|Zoom in")), 3348 QKeySequence(QCoreApplication.translate( 3349 'ViewManager', "Zoom In", "View|Zoom in")), 3350 self.viewActGrp, 'vm_view_zoom_in') 3351 self.zoomInAct.setStatusTip(QCoreApplication.translate( 3352 'ViewManager', 'Zoom in on the text')) 3353 self.zoomInAct.setWhatsThis(QCoreApplication.translate( 3354 'ViewManager', 3355 """<b>Zoom in</b>""" 3356 """<p>Zoom in on the text. This makes the text bigger.</p>""" 3357 )) 3358 self.zoomInAct.triggered.connect(self.__zoomIn) 3359 self.viewActions.append(self.zoomInAct) 3360 3361 self.zoomOutAct = E5Action( 3362 QCoreApplication.translate('ViewManager', 'Zoom out'), 3363 UI.PixmapCache.getIcon("zoomOut"), 3364 QCoreApplication.translate('ViewManager', 'Zoom &out'), 3365 QKeySequence(QCoreApplication.translate( 3366 'ViewManager', "Ctrl+-", "View|Zoom out")), 3367 QKeySequence(QCoreApplication.translate( 3368 'ViewManager', "Zoom Out", "View|Zoom out")), 3369 self.viewActGrp, 'vm_view_zoom_out') 3370 self.zoomOutAct.setStatusTip(QCoreApplication.translate( 3371 'ViewManager', 'Zoom out on the text')) 3372 self.zoomOutAct.setWhatsThis(QCoreApplication.translate( 3373 'ViewManager', 3374 """<b>Zoom out</b>""" 3375 """<p>Zoom out on the text. This makes the text smaller.</p>""" 3376 )) 3377 self.zoomOutAct.triggered.connect(self.__zoomOut) 3378 self.viewActions.append(self.zoomOutAct) 3379 3380 self.zoomResetAct = E5Action( 3381 QCoreApplication.translate('ViewManager', 'Zoom reset'), 3382 UI.PixmapCache.getIcon("zoomReset"), 3383 QCoreApplication.translate('ViewManager', 'Zoom &reset'), 3384 QKeySequence(QCoreApplication.translate( 3385 'ViewManager', "Ctrl+0", "View|Zoom reset")), 3386 0, 3387 self.viewActGrp, 'vm_view_zoom_reset') 3388 self.zoomResetAct.setStatusTip(QCoreApplication.translate( 3389 'ViewManager', 'Reset the zoom of the text')) 3390 self.zoomResetAct.setWhatsThis(QCoreApplication.translate( 3391 'ViewManager', 3392 """<b>Zoom reset</b>""" 3393 """<p>Reset the zoom of the text. """ 3394 """This sets the zoom factor to 100%.</p>""" 3395 )) 3396 self.zoomResetAct.triggered.connect(self.__zoomReset) 3397 self.viewActions.append(self.zoomResetAct) 3398 3399 self.zoomToAct = E5Action( 3400 QCoreApplication.translate('ViewManager', 'Zoom'), 3401 UI.PixmapCache.getIcon("zoomTo"), 3402 QCoreApplication.translate('ViewManager', '&Zoom'), 3403 QKeySequence(QCoreApplication.translate( 3404 'ViewManager', "Ctrl+#", "View|Zoom")), 3405 0, 3406 self.viewActGrp, 'vm_view_zoom') 3407 self.zoomToAct.setStatusTip(QCoreApplication.translate( 3408 'ViewManager', 'Zoom the text')) 3409 self.zoomToAct.setWhatsThis(QCoreApplication.translate( 3410 'ViewManager', 3411 """<b>Zoom</b>""" 3412 """<p>Zoom the text. This opens a dialog where the""" 3413 """ desired size can be entered.</p>""" 3414 )) 3415 self.zoomToAct.triggered.connect(self.__zoom) 3416 self.viewActions.append(self.zoomToAct) 3417 3418 self.toggleAllAct = E5Action( 3419 QCoreApplication.translate('ViewManager', 'Toggle all folds'), 3420 QCoreApplication.translate('ViewManager', '&Toggle all folds'), 3421 0, 0, self.viewFoldActGrp, 'vm_view_toggle_all_folds') 3422 self.toggleAllAct.setStatusTip(QCoreApplication.translate( 3423 'ViewManager', 'Toggle all folds')) 3424 self.toggleAllAct.setWhatsThis(QCoreApplication.translate( 3425 'ViewManager', 3426 """<b>Toggle all folds</b>""" 3427 """<p>Toggle all folds of the current editor.</p>""" 3428 )) 3429 self.toggleAllAct.triggered.connect(self.__toggleAll) 3430 self.viewActions.append(self.toggleAllAct) 3431 3432 self.toggleAllChildrenAct = E5Action( 3433 QCoreApplication.translate( 3434 'ViewManager', 'Toggle all folds (including children)'), 3435 QCoreApplication.translate( 3436 'ViewManager', 'Toggle all &folds (including children)'), 3437 0, 0, self.viewFoldActGrp, 'vm_view_toggle_all_folds_children') 3438 self.toggleAllChildrenAct.setStatusTip(QCoreApplication.translate( 3439 'ViewManager', 'Toggle all folds (including children)')) 3440 self.toggleAllChildrenAct.setWhatsThis(QCoreApplication.translate( 3441 'ViewManager', 3442 """<b>Toggle all folds (including children)</b>""" 3443 """<p>Toggle all folds of the current editor including""" 3444 """ all children.</p>""" 3445 )) 3446 self.toggleAllChildrenAct.triggered.connect( 3447 self.__toggleAllChildren) 3448 self.viewActions.append(self.toggleAllChildrenAct) 3449 3450 self.toggleCurrentAct = E5Action( 3451 QCoreApplication.translate('ViewManager', 'Toggle current fold'), 3452 QCoreApplication.translate('ViewManager', 'Toggle ¤t fold'), 3453 0, 0, self.viewFoldActGrp, 'vm_view_toggle_current_fold') 3454 self.toggleCurrentAct.setStatusTip(QCoreApplication.translate( 3455 'ViewManager', 'Toggle current fold')) 3456 self.toggleCurrentAct.setWhatsThis(QCoreApplication.translate( 3457 'ViewManager', 3458 """<b>Toggle current fold</b>""" 3459 """<p>Toggle the folds of the current line of the current""" 3460 """ editor.</p>""" 3461 )) 3462 self.toggleCurrentAct.triggered.connect(self.__toggleCurrent) 3463 self.viewActions.append(self.toggleCurrentAct) 3464 3465 self.clearAllFoldsAct = E5Action( 3466 QCoreApplication.translate('ViewManager', 'Clear all folds'), 3467 QCoreApplication.translate('ViewManager', 'Clear &all folds'), 3468 0, 0, self.viewFoldActGrp, 'vm_view_clear_all_folds') 3469 self.clearAllFoldsAct.setStatusTip(QCoreApplication.translate( 3470 'ViewManager', 'Clear all folds')) 3471 self.clearAllFoldsAct.setWhatsThis(QCoreApplication.translate( 3472 'ViewManager', 3473 """<b>Clear all folds</b>""" 3474 """<p>Clear all folds of the current editor, i.e. ensure that""" 3475 """ all lines are displayed unfolded.</p>""" 3476 )) 3477 self.clearAllFoldsAct.triggered.connect(self.__clearAllFolds) 3478 self.viewActions.append(self.clearAllFoldsAct) 3479 3480 self.unhighlightAct = E5Action( 3481 QCoreApplication.translate('ViewManager', 'Remove all highlights'), 3482 UI.PixmapCache.getIcon("unhighlight"), 3483 QCoreApplication.translate('ViewManager', 'Remove all highlights'), 3484 0, 0, 3485 self, 'vm_view_unhighlight') 3486 self.unhighlightAct.setStatusTip(QCoreApplication.translate( 3487 'ViewManager', 'Remove all highlights')) 3488 self.unhighlightAct.setWhatsThis(QCoreApplication.translate( 3489 'ViewManager', 3490 """<b>Remove all highlights</b>""" 3491 """<p>Remove the highlights of all editors.</p>""" 3492 )) 3493 self.unhighlightAct.triggered.connect(self.__unhighlight) 3494 self.viewActions.append(self.unhighlightAct) 3495 3496 self.newDocumentViewAct = E5Action( 3497 QCoreApplication.translate('ViewManager', 'New Document View'), 3498 UI.PixmapCache.getIcon("documentNewView"), 3499 QCoreApplication.translate('ViewManager', 'New &Document View'), 3500 0, 0, self, 'vm_view_new_document_view') 3501 self.newDocumentViewAct.setStatusTip(QCoreApplication.translate( 3502 'ViewManager', 'Open a new view of the current document')) 3503 self.newDocumentViewAct.setWhatsThis(QCoreApplication.translate( 3504 'ViewManager', 3505 """<b>New Document View</b>""" 3506 """<p>Opens a new view of the current document. Both views show""" 3507 """ the same document. However, the cursors may be positioned""" 3508 """ independently.</p>""" 3509 )) 3510 self.newDocumentViewAct.triggered.connect(self.__newDocumentView) 3511 self.viewActions.append(self.newDocumentViewAct) 3512 3513 self.newDocumentSplitViewAct = E5Action( 3514 QCoreApplication.translate( 3515 'ViewManager', 'New Document View (with new split)'), 3516 UI.PixmapCache.getIcon("splitVertical"), 3517 QCoreApplication.translate( 3518 'ViewManager', 'New Document View (with new split)'), 3519 0, 0, self, 'vm_view_new_document_split_view') 3520 self.newDocumentSplitViewAct.setStatusTip(QCoreApplication.translate( 3521 'ViewManager', 3522 'Open a new view of the current document in a new split')) 3523 self.newDocumentSplitViewAct.setWhatsThis(QCoreApplication.translate( 3524 'ViewManager', 3525 """<b>New Document View</b>""" 3526 """<p>Opens a new view of the current document in a new split.""" 3527 """ Both views show the same document. However, the cursors may""" 3528 """ be positioned independently.</p>""" 3529 )) 3530 self.newDocumentSplitViewAct.triggered.connect( 3531 self.__newDocumentSplitView) 3532 self.viewActions.append(self.newDocumentSplitViewAct) 3533 3534 self.splitViewAct = E5Action( 3535 QCoreApplication.translate('ViewManager', 'Split view'), 3536 UI.PixmapCache.getIcon("splitVertical"), 3537 QCoreApplication.translate('ViewManager', '&Split view'), 3538 0, 0, self, 'vm_view_split_view') 3539 self.splitViewAct.setStatusTip(QCoreApplication.translate( 3540 'ViewManager', 'Add a split to the view')) 3541 self.splitViewAct.setWhatsThis(QCoreApplication.translate( 3542 'ViewManager', 3543 """<b>Split view</b>""" 3544 """<p>Add a split to the view.</p>""" 3545 )) 3546 self.splitViewAct.triggered.connect(self.__splitView) 3547 self.viewActions.append(self.splitViewAct) 3548 3549 self.splitOrientationAct = E5Action( 3550 QCoreApplication.translate('ViewManager', 'Arrange horizontally'), 3551 QCoreApplication.translate('ViewManager', 'Arrange &horizontally'), 3552 0, 0, self, 'vm_view_arrange_horizontally', True) 3553 self.splitOrientationAct.setStatusTip(QCoreApplication.translate( 3554 'ViewManager', 'Arrange the splitted views horizontally')) 3555 self.splitOrientationAct.setWhatsThis(QCoreApplication.translate( 3556 'ViewManager', 3557 """<b>Arrange horizontally</b>""" 3558 """<p>Arrange the splitted views horizontally.</p>""" 3559 )) 3560 self.splitOrientationAct.setChecked(False) 3561 self.splitOrientationAct.toggled[bool].connect(self.__splitOrientation) 3562 self.viewActions.append(self.splitOrientationAct) 3563 3564 self.splitRemoveAct = E5Action( 3565 QCoreApplication.translate('ViewManager', 'Remove split'), 3566 UI.PixmapCache.getIcon("remsplitVertical"), 3567 QCoreApplication.translate('ViewManager', '&Remove split'), 3568 0, 0, self, 'vm_view_remove_split') 3569 self.splitRemoveAct.setStatusTip(QCoreApplication.translate( 3570 'ViewManager', 'Remove the current split')) 3571 self.splitRemoveAct.setWhatsThis(QCoreApplication.translate( 3572 'ViewManager', 3573 """<b>Remove split</b>""" 3574 """<p>Remove the current split.</p>""" 3575 )) 3576 self.splitRemoveAct.triggered.connect(self.removeSplit) 3577 self.viewActions.append(self.splitRemoveAct) 3578 3579 self.nextSplitAct = E5Action( 3580 QCoreApplication.translate('ViewManager', 'Next split'), 3581 QCoreApplication.translate('ViewManager', '&Next split'), 3582 QKeySequence(QCoreApplication.translate( 3583 'ViewManager', "Ctrl+Alt+N", "View|Next split")), 3584 0, 3585 self, 'vm_next_split') 3586 self.nextSplitAct.setStatusTip(QCoreApplication.translate( 3587 'ViewManager', 'Move to the next split')) 3588 self.nextSplitAct.setWhatsThis(QCoreApplication.translate( 3589 'ViewManager', 3590 """<b>Next split</b>""" 3591 """<p>Move to the next split.</p>""" 3592 )) 3593 self.nextSplitAct.triggered.connect(self.nextSplit) 3594 self.viewActions.append(self.nextSplitAct) 3595 3596 self.prevSplitAct = E5Action( 3597 QCoreApplication.translate('ViewManager', 'Previous split'), 3598 QCoreApplication.translate('ViewManager', '&Previous split'), 3599 QKeySequence(QCoreApplication.translate( 3600 'ViewManager', "Ctrl+Alt+P", "View|Previous split")), 3601 0, self, 'vm_previous_split') 3602 self.prevSplitAct.setStatusTip(QCoreApplication.translate( 3603 'ViewManager', 'Move to the previous split')) 3604 self.prevSplitAct.setWhatsThis(QCoreApplication.translate( 3605 'ViewManager', 3606 """<b>Previous split</b>""" 3607 """<p>Move to the previous split.</p>""" 3608 )) 3609 self.prevSplitAct.triggered.connect(self.prevSplit) 3610 self.viewActions.append(self.prevSplitAct) 3611 3612 self.previewAct = E5Action( 3613 QCoreApplication.translate('ViewManager', 'Preview'), 3614 UI.PixmapCache.getIcon("previewer"), 3615 QCoreApplication.translate('ViewManager', 'Preview'), 3616 0, 0, self, 'vm_preview', True) 3617 self.previewAct.setStatusTip(QCoreApplication.translate( 3618 'ViewManager', 'Preview the current file in the web browser')) 3619 self.previewAct.setWhatsThis(QCoreApplication.translate( 3620 'ViewManager', 3621 """<b>Preview</b>""" 3622 """<p>This opens the web browser with a preview of""" 3623 """ the current file.</p>""" 3624 )) 3625 self.previewAct.setChecked(Preferences.getUI("ShowFilePreview")) 3626 self.previewAct.toggled[bool].connect(self.__previewEditor) 3627 self.viewActions.append(self.previewAct) 3628 3629 self.astViewerAct = E5Action( 3630 QCoreApplication.translate('ViewManager', 'Python AST Viewer'), 3631 UI.PixmapCache.getIcon("astTree"), 3632 QCoreApplication.translate('ViewManager', 'Python AST Viewer'), 3633 0, 0, self, 'vm_python_ast_viewer', True) 3634 self.astViewerAct.setStatusTip(QCoreApplication.translate( 3635 'ViewManager', 'Show the AST for the current Python file')) 3636 self.astViewerAct.setWhatsThis(QCoreApplication.translate( 3637 'ViewManager', 3638 """<b>Python AST Viewer</b>""" 3639 """<p>This opens the a tree view of the AST of the current""" 3640 """ Python source file.</p>""" 3641 )) 3642 self.astViewerAct.setChecked(False) 3643 self.astViewerAct.toggled[bool].connect(self.__astViewer) 3644 self.viewActions.append(self.astViewerAct) 3645 3646 self.disViewerAct = E5Action( 3647 QCoreApplication.translate( 3648 'ViewManager', 'Python Disassembly Viewer'), 3649 UI.PixmapCache.getIcon("disassembly"), 3650 QCoreApplication.translate( 3651 'ViewManager', 'Python Disassembly Viewer'), 3652 0, 0, self, 'vm_python_dis_viewer', True) 3653 self.disViewerAct.setStatusTip(QCoreApplication.translate( 3654 'ViewManager', 'Show the Disassembly for the current Python file')) 3655 self.disViewerAct.setWhatsThis(QCoreApplication.translate( 3656 'ViewManager', 3657 """<b>Python Disassembly Viewer</b>""" 3658 """<p>This opens the a tree view of the Disassembly of the""" 3659 """ current Python source file.</p>""" 3660 )) 3661 self.disViewerAct.setChecked(False) 3662 self.disViewerAct.toggled[bool].connect(self.__disViewer) 3663 self.viewActions.append(self.disViewerAct) 3664 3665 self.viewActGrp.setEnabled(False) 3666 self.viewFoldActGrp.setEnabled(False) 3667 self.unhighlightAct.setEnabled(False) 3668 self.splitViewAct.setEnabled(False) 3669 self.splitOrientationAct.setEnabled(False) 3670 self.splitRemoveAct.setEnabled(False) 3671 self.nextSplitAct.setEnabled(False) 3672 self.prevSplitAct.setEnabled(False) 3673 self.previewAct.setEnabled(True) 3674 self.astViewerAct.setEnabled(False) 3675 self.disViewerAct.setEnabled(False) 3676 self.newDocumentViewAct.setEnabled(False) 3677 self.newDocumentSplitViewAct.setEnabled(False) 3678 3679 self.splitOrientationAct.setChecked( 3680 Preferences.getUI("SplitOrientationVertical")) 3681 3682 def initViewMenu(self): 3683 """ 3684 Public method to create the View menu. 3685 3686 @return the generated menu 3687 """ 3688 menu = QMenu(QCoreApplication.translate('ViewManager', '&View'), 3689 self.ui) 3690 menu.setTearOffEnabled(True) 3691 menu.addActions(self.viewActGrp.actions()) 3692 menu.addSeparator() 3693 menu.addActions(self.viewFoldActGrp.actions()) 3694 menu.addSeparator() 3695 menu.addAction(self.previewAct) 3696 menu.addAction(self.astViewerAct) 3697 menu.addAction(self.disViewerAct) 3698 menu.addSeparator() 3699 menu.addAction(self.unhighlightAct) 3700 menu.addSeparator() 3701 menu.addAction(self.newDocumentViewAct) 3702 if self.canSplit(): 3703 menu.addAction(self.newDocumentSplitViewAct) 3704 menu.addSeparator() 3705 menu.addAction(self.splitViewAct) 3706 menu.addAction(self.splitOrientationAct) 3707 menu.addAction(self.splitRemoveAct) 3708 menu.addAction(self.nextSplitAct) 3709 menu.addAction(self.prevSplitAct) 3710 3711 return menu 3712 3713 def initViewToolbar(self, toolbarManager): 3714 """ 3715 Public method to create the View toolbar. 3716 3717 @param toolbarManager reference to a toolbar manager object 3718 (E5ToolBarManager) 3719 @return the generated toolbar 3720 """ 3721 tb = QToolBar(QCoreApplication.translate('ViewManager', 'View'), 3722 self.ui) 3723 tb.setIconSize(UI.Config.ToolBarIconSize) 3724 tb.setObjectName("ViewToolbar") 3725 tb.setToolTip(QCoreApplication.translate('ViewManager', 'View')) 3726 3727 tb.addActions(self.viewActGrp.actions()) 3728 tb.addSeparator() 3729 tb.addAction(self.previewAct) 3730 tb.addAction(self.astViewerAct) 3731 tb.addAction(self.disViewerAct) 3732 tb.addSeparator() 3733 tb.addAction(self.newDocumentViewAct) 3734 if self.canSplit(): 3735 tb.addAction(self.newDocumentSplitViewAct) 3736 3737 toolbarManager.addToolBar(tb, tb.windowTitle()) 3738 toolbarManager.addAction(self.unhighlightAct, tb.windowTitle()) 3739 toolbarManager.addAction(self.splitViewAct, tb.windowTitle()) 3740 toolbarManager.addAction(self.splitRemoveAct, tb.windowTitle()) 3741 3742 return tb 3743 3744 ################################################################## 3745 ## Initialize the macro related actions and macro menu 3746 ################################################################## 3747 3748 def __initMacroActions(self): 3749 """ 3750 Private method defining the user interface actions for the macro 3751 commands. 3752 """ 3753 self.macroActGrp = createActionGroup(self) 3754 3755 self.macroStartRecAct = E5Action( 3756 QCoreApplication.translate( 3757 'ViewManager', 'Start Macro Recording'), 3758 QCoreApplication.translate( 3759 'ViewManager', 'S&tart Macro Recording'), 3760 0, 0, self.macroActGrp, 'vm_macro_start_recording') 3761 self.macroStartRecAct.setStatusTip(QCoreApplication.translate( 3762 'ViewManager', 'Start Macro Recording')) 3763 self.macroStartRecAct.setWhatsThis(QCoreApplication.translate( 3764 'ViewManager', 3765 """<b>Start Macro Recording</b>""" 3766 """<p>Start recording editor commands into a new macro.</p>""" 3767 )) 3768 self.macroStartRecAct.triggered.connect(self.__macroStartRecording) 3769 self.macroActions.append(self.macroStartRecAct) 3770 3771 self.macroStopRecAct = E5Action( 3772 QCoreApplication.translate('ViewManager', 'Stop Macro Recording'), 3773 QCoreApplication.translate('ViewManager', 'Sto&p Macro Recording'), 3774 0, 0, self.macroActGrp, 'vm_macro_stop_recording') 3775 self.macroStopRecAct.setStatusTip(QCoreApplication.translate( 3776 'ViewManager', 'Stop Macro Recording')) 3777 self.macroStopRecAct.setWhatsThis(QCoreApplication.translate( 3778 'ViewManager', 3779 """<b>Stop Macro Recording</b>""" 3780 """<p>Stop recording editor commands into a new macro.</p>""" 3781 )) 3782 self.macroStopRecAct.triggered.connect(self.__macroStopRecording) 3783 self.macroActions.append(self.macroStopRecAct) 3784 3785 self.macroRunAct = E5Action( 3786 QCoreApplication.translate('ViewManager', 'Run Macro'), 3787 QCoreApplication.translate('ViewManager', '&Run Macro'), 3788 0, 0, self.macroActGrp, 'vm_macro_run') 3789 self.macroRunAct.setStatusTip(QCoreApplication.translate( 3790 'ViewManager', 'Run Macro')) 3791 self.macroRunAct.setWhatsThis(QCoreApplication.translate( 3792 'ViewManager', 3793 """<b>Run Macro</b>""" 3794 """<p>Run a previously recorded editor macro.</p>""" 3795 )) 3796 self.macroRunAct.triggered.connect(self.__macroRun) 3797 self.macroActions.append(self.macroRunAct) 3798 3799 self.macroDeleteAct = E5Action( 3800 QCoreApplication.translate('ViewManager', 'Delete Macro'), 3801 QCoreApplication.translate('ViewManager', '&Delete Macro'), 3802 0, 0, self.macroActGrp, 'vm_macro_delete') 3803 self.macroDeleteAct.setStatusTip(QCoreApplication.translate( 3804 'ViewManager', 'Delete Macro')) 3805 self.macroDeleteAct.setWhatsThis(QCoreApplication.translate( 3806 'ViewManager', 3807 """<b>Delete Macro</b>""" 3808 """<p>Delete a previously recorded editor macro.</p>""" 3809 )) 3810 self.macroDeleteAct.triggered.connect(self.__macroDelete) 3811 self.macroActions.append(self.macroDeleteAct) 3812 3813 self.macroLoadAct = E5Action( 3814 QCoreApplication.translate('ViewManager', 'Load Macro'), 3815 QCoreApplication.translate('ViewManager', '&Load Macro'), 3816 0, 0, self.macroActGrp, 'vm_macro_load') 3817 self.macroLoadAct.setStatusTip(QCoreApplication.translate( 3818 'ViewManager', 'Load Macro')) 3819 self.macroLoadAct.setWhatsThis(QCoreApplication.translate( 3820 'ViewManager', 3821 """<b>Load Macro</b>""" 3822 """<p>Load an editor macro from a file.</p>""" 3823 )) 3824 self.macroLoadAct.triggered.connect(self.__macroLoad) 3825 self.macroActions.append(self.macroLoadAct) 3826 3827 self.macroSaveAct = E5Action( 3828 QCoreApplication.translate('ViewManager', 'Save Macro'), 3829 QCoreApplication.translate('ViewManager', '&Save Macro'), 3830 0, 0, self.macroActGrp, 'vm_macro_save') 3831 self.macroSaveAct.setStatusTip(QCoreApplication.translate( 3832 'ViewManager', 'Save Macro')) 3833 self.macroSaveAct.setWhatsThis(QCoreApplication.translate( 3834 'ViewManager', 3835 """<b>Save Macro</b>""" 3836 """<p>Save a previously recorded editor macro to a file.</p>""" 3837 )) 3838 self.macroSaveAct.triggered.connect(self.__macroSave) 3839 self.macroActions.append(self.macroSaveAct) 3840 3841 self.macroActGrp.setEnabled(False) 3842 3843 def initMacroMenu(self): 3844 """ 3845 Public method to create the Macro menu. 3846 3847 @return the generated menu 3848 """ 3849 menu = QMenu(QCoreApplication.translate('ViewManager', "&Macros"), 3850 self.ui) 3851 menu.setTearOffEnabled(True) 3852 menu.addActions(self.macroActGrp.actions()) 3853 3854 return menu 3855 3856 ##################################################################### 3857 ## Initialize the bookmark related actions, bookmark menu and toolbar 3858 ##################################################################### 3859 3860 def __initBookmarkActions(self): 3861 """ 3862 Private method defining the user interface actions for the bookmarks 3863 commands. 3864 """ 3865 self.bookmarkActGrp = createActionGroup(self) 3866 3867 self.bookmarkToggleAct = E5Action( 3868 QCoreApplication.translate('ViewManager', 'Toggle Bookmark'), 3869 UI.PixmapCache.getIcon("bookmarkToggle"), 3870 QCoreApplication.translate('ViewManager', '&Toggle Bookmark'), 3871 QKeySequence(QCoreApplication.translate( 3872 'ViewManager', "Alt+Ctrl+T", "Bookmark|Toggle")), 3873 0, 3874 self.bookmarkActGrp, 'vm_bookmark_toggle') 3875 self.bookmarkToggleAct.setStatusTip(QCoreApplication.translate( 3876 'ViewManager', 'Toggle Bookmark')) 3877 self.bookmarkToggleAct.setWhatsThis(QCoreApplication.translate( 3878 'ViewManager', 3879 """<b>Toggle Bookmark</b>""" 3880 """<p>Toggle a bookmark at the current line of the current""" 3881 """ editor.</p>""" 3882 )) 3883 self.bookmarkToggleAct.triggered.connect(self.__toggleBookmark) 3884 self.bookmarkActions.append(self.bookmarkToggleAct) 3885 3886 self.bookmarkNextAct = E5Action( 3887 QCoreApplication.translate('ViewManager', 'Next Bookmark'), 3888 UI.PixmapCache.getIcon("bookmarkNext"), 3889 QCoreApplication.translate('ViewManager', '&Next Bookmark'), 3890 QKeySequence(QCoreApplication.translate( 3891 'ViewManager', "Ctrl+PgDown", "Bookmark|Next")), 3892 0, 3893 self.bookmarkActGrp, 'vm_bookmark_next') 3894 self.bookmarkNextAct.setStatusTip(QCoreApplication.translate( 3895 'ViewManager', 'Next Bookmark')) 3896 self.bookmarkNextAct.setWhatsThis(QCoreApplication.translate( 3897 'ViewManager', 3898 """<b>Next Bookmark</b>""" 3899 """<p>Go to next bookmark of the current editor.</p>""" 3900 )) 3901 self.bookmarkNextAct.triggered.connect(self.__nextBookmark) 3902 self.bookmarkActions.append(self.bookmarkNextAct) 3903 3904 self.bookmarkPreviousAct = E5Action( 3905 QCoreApplication.translate('ViewManager', 'Previous Bookmark'), 3906 UI.PixmapCache.getIcon("bookmarkPrevious"), 3907 QCoreApplication.translate('ViewManager', '&Previous Bookmark'), 3908 QKeySequence(QCoreApplication.translate( 3909 'ViewManager', "Ctrl+PgUp", "Bookmark|Previous")), 3910 0, 3911 self.bookmarkActGrp, 'vm_bookmark_previous') 3912 self.bookmarkPreviousAct.setStatusTip(QCoreApplication.translate( 3913 'ViewManager', 'Previous Bookmark')) 3914 self.bookmarkPreviousAct.setWhatsThis(QCoreApplication.translate( 3915 'ViewManager', 3916 """<b>Previous Bookmark</b>""" 3917 """<p>Go to previous bookmark of the current editor.</p>""" 3918 )) 3919 self.bookmarkPreviousAct.triggered.connect(self.__previousBookmark) 3920 self.bookmarkActions.append(self.bookmarkPreviousAct) 3921 3922 self.bookmarkClearAct = E5Action( 3923 QCoreApplication.translate('ViewManager', 'Clear Bookmarks'), 3924 QCoreApplication.translate('ViewManager', '&Clear Bookmarks'), 3925 QKeySequence(QCoreApplication.translate( 3926 'ViewManager', "Alt+Ctrl+C", "Bookmark|Clear")), 3927 0, 3928 self.bookmarkActGrp, 'vm_bookmark_clear') 3929 self.bookmarkClearAct.setStatusTip(QCoreApplication.translate( 3930 'ViewManager', 'Clear Bookmarks')) 3931 self.bookmarkClearAct.setWhatsThis(QCoreApplication.translate( 3932 'ViewManager', 3933 """<b>Clear Bookmarks</b>""" 3934 """<p>Clear bookmarks of all editors.</p>""" 3935 )) 3936 self.bookmarkClearAct.triggered.connect(self.__clearAllBookmarks) 3937 self.bookmarkActions.append(self.bookmarkClearAct) 3938 3939 self.syntaxErrorGotoAct = E5Action( 3940 QCoreApplication.translate('ViewManager', 'Goto Syntax Error'), 3941 UI.PixmapCache.getIcon("syntaxErrorGoto"), 3942 QCoreApplication.translate('ViewManager', '&Goto Syntax Error'), 3943 0, 0, 3944 self.bookmarkActGrp, 'vm_syntaxerror_goto') 3945 self.syntaxErrorGotoAct.setStatusTip(QCoreApplication.translate( 3946 'ViewManager', 'Goto Syntax Error')) 3947 self.syntaxErrorGotoAct.setWhatsThis(QCoreApplication.translate( 3948 'ViewManager', 3949 """<b>Goto Syntax Error</b>""" 3950 """<p>Go to next syntax error of the current editor.</p>""" 3951 )) 3952 self.syntaxErrorGotoAct.triggered.connect(self.__gotoSyntaxError) 3953 self.bookmarkActions.append(self.syntaxErrorGotoAct) 3954 3955 self.syntaxErrorClearAct = E5Action( 3956 QCoreApplication.translate('ViewManager', 'Clear Syntax Errors'), 3957 QCoreApplication.translate('ViewManager', 'Clear &Syntax Errors'), 3958 0, 0, 3959 self.bookmarkActGrp, 'vm_syntaxerror_clear') 3960 self.syntaxErrorClearAct.setStatusTip(QCoreApplication.translate( 3961 'ViewManager', 'Clear Syntax Errors')) 3962 self.syntaxErrorClearAct.setWhatsThis(QCoreApplication.translate( 3963 'ViewManager', 3964 """<b>Clear Syntax Errors</b>""" 3965 """<p>Clear syntax errors of all editors.</p>""" 3966 )) 3967 self.syntaxErrorClearAct.triggered.connect( 3968 self.__clearAllSyntaxErrors) 3969 self.bookmarkActions.append(self.syntaxErrorClearAct) 3970 3971 self.warningsNextAct = E5Action( 3972 QCoreApplication.translate('ViewManager', 'Next warning message'), 3973 UI.PixmapCache.getIcon("warningNext"), 3974 QCoreApplication.translate('ViewManager', '&Next warning message'), 3975 0, 0, 3976 self.bookmarkActGrp, 'vm_warning_next') 3977 self.warningsNextAct.setStatusTip(QCoreApplication.translate( 3978 'ViewManager', 'Next warning message')) 3979 self.warningsNextAct.setWhatsThis(QCoreApplication.translate( 3980 'ViewManager', 3981 """<b>Next warning message</b>""" 3982 """<p>Go to next line of the current editor""" 3983 """ having a pyflakes warning.</p>""" 3984 )) 3985 self.warningsNextAct.triggered.connect(self.__nextWarning) 3986 self.bookmarkActions.append(self.warningsNextAct) 3987 3988 self.warningsPreviousAct = E5Action( 3989 QCoreApplication.translate( 3990 'ViewManager', 'Previous warning message'), 3991 UI.PixmapCache.getIcon("warningPrev"), 3992 QCoreApplication.translate( 3993 'ViewManager', '&Previous warning message'), 3994 0, 0, 3995 self.bookmarkActGrp, 'vm_warning_previous') 3996 self.warningsPreviousAct.setStatusTip(QCoreApplication.translate( 3997 'ViewManager', 'Previous warning message')) 3998 self.warningsPreviousAct.setWhatsThis(QCoreApplication.translate( 3999 'ViewManager', 4000 """<b>Previous warning message</b>""" 4001 """<p>Go to previous line of the current editor""" 4002 """ having a pyflakes warning.</p>""" 4003 )) 4004 self.warningsPreviousAct.triggered.connect(self.__previousWarning) 4005 self.bookmarkActions.append(self.warningsPreviousAct) 4006 4007 self.warningsClearAct = E5Action( 4008 QCoreApplication.translate( 4009 'ViewManager', 'Clear Warning Messages'), 4010 QCoreApplication.translate( 4011 'ViewManager', 'Clear &Warning Messages'), 4012 0, 0, 4013 self.bookmarkActGrp, 'vm_warnings_clear') 4014 self.warningsClearAct.setStatusTip(QCoreApplication.translate( 4015 'ViewManager', 'Clear Warning Messages')) 4016 self.warningsClearAct.setWhatsThis(QCoreApplication.translate( 4017 'ViewManager', 4018 """<b>Clear Warning Messages</b>""" 4019 """<p>Clear pyflakes warning messages of all editors.</p>""" 4020 )) 4021 self.warningsClearAct.triggered.connect(self.__clearAllWarnings) 4022 self.bookmarkActions.append(self.warningsClearAct) 4023 4024 self.notcoveredNextAct = E5Action( 4025 QCoreApplication.translate('ViewManager', 'Next uncovered line'), 4026 UI.PixmapCache.getIcon("notcoveredNext"), 4027 QCoreApplication.translate('ViewManager', '&Next uncovered line'), 4028 0, 0, 4029 self.bookmarkActGrp, 'vm_uncovered_next') 4030 self.notcoveredNextAct.setStatusTip(QCoreApplication.translate( 4031 'ViewManager', 'Next uncovered line')) 4032 self.notcoveredNextAct.setWhatsThis(QCoreApplication.translate( 4033 'ViewManager', 4034 """<b>Next uncovered line</b>""" 4035 """<p>Go to next line of the current editor marked as not""" 4036 """ covered.</p>""" 4037 )) 4038 self.notcoveredNextAct.triggered.connect(self.__nextUncovered) 4039 self.bookmarkActions.append(self.notcoveredNextAct) 4040 4041 self.notcoveredPreviousAct = E5Action( 4042 QCoreApplication.translate( 4043 'ViewManager', 'Previous uncovered line'), 4044 UI.PixmapCache.getIcon("notcoveredPrev"), 4045 QCoreApplication.translate( 4046 'ViewManager', '&Previous uncovered line'), 4047 0, 0, 4048 self.bookmarkActGrp, 'vm_uncovered_previous') 4049 self.notcoveredPreviousAct.setStatusTip(QCoreApplication.translate( 4050 'ViewManager', 'Previous uncovered line')) 4051 self.notcoveredPreviousAct.setWhatsThis(QCoreApplication.translate( 4052 'ViewManager', 4053 """<b>Previous uncovered line</b>""" 4054 """<p>Go to previous line of the current editor marked""" 4055 """ as not covered.</p>""" 4056 )) 4057 self.notcoveredPreviousAct.triggered.connect( 4058 self.__previousUncovered) 4059 self.bookmarkActions.append(self.notcoveredPreviousAct) 4060 4061 self.taskNextAct = E5Action( 4062 QCoreApplication.translate('ViewManager', 'Next Task'), 4063 UI.PixmapCache.getIcon("taskNext"), 4064 QCoreApplication.translate('ViewManager', '&Next Task'), 4065 0, 0, 4066 self.bookmarkActGrp, 'vm_task_next') 4067 self.taskNextAct.setStatusTip(QCoreApplication.translate( 4068 'ViewManager', 'Next Task')) 4069 self.taskNextAct.setWhatsThis(QCoreApplication.translate( 4070 'ViewManager', 4071 """<b>Next Task</b>""" 4072 """<p>Go to next line of the current editor having a task.</p>""" 4073 )) 4074 self.taskNextAct.triggered.connect(self.__nextTask) 4075 self.bookmarkActions.append(self.taskNextAct) 4076 4077 self.taskPreviousAct = E5Action( 4078 QCoreApplication.translate('ViewManager', 'Previous Task'), 4079 UI.PixmapCache.getIcon("taskPrev"), 4080 QCoreApplication.translate( 4081 'ViewManager', '&Previous Task'), 4082 0, 0, 4083 self.bookmarkActGrp, 'vm_task_previous') 4084 self.taskPreviousAct.setStatusTip(QCoreApplication.translate( 4085 'ViewManager', 'Previous Task')) 4086 self.taskPreviousAct.setWhatsThis(QCoreApplication.translate( 4087 'ViewManager', 4088 """<b>Previous Task</b>""" 4089 """<p>Go to previous line of the current editor having a""" 4090 """ task.</p>""" 4091 )) 4092 self.taskPreviousAct.triggered.connect(self.__previousTask) 4093 self.bookmarkActions.append(self.taskPreviousAct) 4094 4095 self.changeNextAct = E5Action( 4096 QCoreApplication.translate('ViewManager', 'Next Change'), 4097 UI.PixmapCache.getIcon("changeNext"), 4098 QCoreApplication.translate('ViewManager', '&Next Change'), 4099 0, 0, 4100 self.bookmarkActGrp, 'vm_change_next') 4101 self.changeNextAct.setStatusTip(QCoreApplication.translate( 4102 'ViewManager', 'Next Change')) 4103 self.changeNextAct.setWhatsThis(QCoreApplication.translate( 4104 'ViewManager', 4105 """<b>Next Change</b>""" 4106 """<p>Go to next line of the current editor having a change""" 4107 """ marker.</p>""" 4108 )) 4109 self.changeNextAct.triggered.connect(self.__nextChange) 4110 self.bookmarkActions.append(self.changeNextAct) 4111 4112 self.changePreviousAct = E5Action( 4113 QCoreApplication.translate('ViewManager', 'Previous Change'), 4114 UI.PixmapCache.getIcon("changePrev"), 4115 QCoreApplication.translate( 4116 'ViewManager', '&Previous Change'), 4117 0, 0, 4118 self.bookmarkActGrp, 'vm_change_previous') 4119 self.changePreviousAct.setStatusTip(QCoreApplication.translate( 4120 'ViewManager', 'Previous Change')) 4121 self.changePreviousAct.setWhatsThis(QCoreApplication.translate( 4122 'ViewManager', 4123 """<b>Previous Change</b>""" 4124 """<p>Go to previous line of the current editor having""" 4125 """ a change marker.</p>""" 4126 )) 4127 self.changePreviousAct.triggered.connect(self.__previousChange) 4128 self.bookmarkActions.append(self.changePreviousAct) 4129 4130 self.bookmarkActGrp.setEnabled(False) 4131 4132 def initBookmarkMenu(self): 4133 """ 4134 Public method to create the Bookmark menu. 4135 4136 @return the generated menu 4137 """ 4138 menu = QMenu(QCoreApplication.translate('ViewManager', '&Bookmarks'), 4139 self.ui) 4140 self.bookmarksMenu = QMenu( 4141 QCoreApplication.translate('ViewManager', '&Bookmarks'), 4142 menu) 4143 menu.setTearOffEnabled(True) 4144 4145 menu.addAction(self.bookmarkToggleAct) 4146 menu.addAction(self.bookmarkNextAct) 4147 menu.addAction(self.bookmarkPreviousAct) 4148 menu.addAction(self.bookmarkClearAct) 4149 menu.addSeparator() 4150 self.menuBookmarksAct = menu.addMenu(self.bookmarksMenu) 4151 menu.addSeparator() 4152 menu.addAction(self.syntaxErrorGotoAct) 4153 menu.addAction(self.syntaxErrorClearAct) 4154 menu.addSeparator() 4155 menu.addAction(self.warningsNextAct) 4156 menu.addAction(self.warningsPreviousAct) 4157 menu.addAction(self.warningsClearAct) 4158 menu.addSeparator() 4159 menu.addAction(self.notcoveredNextAct) 4160 menu.addAction(self.notcoveredPreviousAct) 4161 menu.addSeparator() 4162 menu.addAction(self.taskNextAct) 4163 menu.addAction(self.taskPreviousAct) 4164 menu.addSeparator() 4165 menu.addAction(self.changeNextAct) 4166 menu.addAction(self.changePreviousAct) 4167 4168 self.bookmarksMenu.aboutToShow.connect(self.__showBookmarksMenu) 4169 self.bookmarksMenu.triggered.connect(self.__bookmarkSelected) 4170 menu.aboutToShow.connect(self.__showBookmarkMenu) 4171 4172 return menu 4173 4174 def initBookmarkToolbar(self, toolbarManager): 4175 """ 4176 Public method to create the Bookmark toolbar. 4177 4178 @param toolbarManager reference to a toolbar manager object 4179 (E5ToolBarManager) 4180 @return the generated toolbar 4181 """ 4182 tb = QToolBar(QCoreApplication.translate('ViewManager', 'Bookmarks'), 4183 self.ui) 4184 tb.setIconSize(UI.Config.ToolBarIconSize) 4185 tb.setObjectName("BookmarksToolbar") 4186 tb.setToolTip(QCoreApplication.translate('ViewManager', 'Bookmarks')) 4187 4188 tb.addAction(self.bookmarkToggleAct) 4189 tb.addAction(self.bookmarkNextAct) 4190 tb.addAction(self.bookmarkPreviousAct) 4191 tb.addSeparator() 4192 tb.addAction(self.syntaxErrorGotoAct) 4193 tb.addSeparator() 4194 tb.addAction(self.warningsNextAct) 4195 tb.addAction(self.warningsPreviousAct) 4196 tb.addSeparator() 4197 tb.addAction(self.taskNextAct) 4198 tb.addAction(self.taskPreviousAct) 4199 tb.addSeparator() 4200 tb.addAction(self.changeNextAct) 4201 tb.addAction(self.changePreviousAct) 4202 4203 toolbarManager.addToolBar(tb, tb.windowTitle()) 4204 toolbarManager.addAction(self.notcoveredNextAct, tb.windowTitle()) 4205 toolbarManager.addAction(self.notcoveredPreviousAct, tb.windowTitle()) 4206 4207 return tb 4208 4209 ################################################################## 4210 ## Initialize the spell checking related actions 4211 ################################################################## 4212 4213 def __initSpellingActions(self): 4214 """ 4215 Private method to initialize the spell checking actions. 4216 """ 4217 self.spellingActGrp = createActionGroup(self) 4218 4219 self.spellCheckAct = E5Action( 4220 QCoreApplication.translate('ViewManager', 'Check spelling'), 4221 UI.PixmapCache.getIcon("spellchecking"), 4222 QCoreApplication.translate( 4223 'ViewManager', 'Check &spelling...'), 4224 QKeySequence(QCoreApplication.translate( 4225 'ViewManager', "Shift+F7", "Spelling|Spell Check")), 4226 0, 4227 self.spellingActGrp, 'vm_spelling_spellcheck') 4228 self.spellCheckAct.setStatusTip(QCoreApplication.translate( 4229 'ViewManager', 'Perform spell check of current editor')) 4230 self.spellCheckAct.setWhatsThis(QCoreApplication.translate( 4231 'ViewManager', 4232 """<b>Check spelling</b>""" 4233 """<p>Perform a spell check of the current editor.</p>""" 4234 )) 4235 self.spellCheckAct.triggered.connect(self.__spellCheck) 4236 self.spellingActions.append(self.spellCheckAct) 4237 4238 self.autoSpellCheckAct = E5Action( 4239 QCoreApplication.translate( 4240 'ViewManager', 'Automatic spell checking'), 4241 UI.PixmapCache.getIcon("autospellchecking"), 4242 QCoreApplication.translate( 4243 'ViewManager', '&Automatic spell checking'), 4244 0, 0, 4245 self.spellingActGrp, 'vm_spelling_autospellcheck', True) 4246 self.autoSpellCheckAct.setStatusTip(QCoreApplication.translate( 4247 'ViewManager', '(De-)Activate automatic spell checking')) 4248 self.autoSpellCheckAct.setWhatsThis(QCoreApplication.translate( 4249 'ViewManager', 4250 """<b>Automatic spell checking</b>""" 4251 """<p>Activate or deactivate the automatic spell checking""" 4252 """ function of all editors.</p>""" 4253 )) 4254 self.autoSpellCheckAct.setChecked( 4255 Preferences.getEditor("AutoSpellCheckingEnabled")) 4256 self.autoSpellCheckAct.triggered.connect( 4257 self.__setAutoSpellChecking) 4258 self.spellingActions.append(self.autoSpellCheckAct) 4259 4260 self.__enableSpellingActions() 4261 4262 def __enableSpellingActions(self): 4263 """ 4264 Private method to set the enabled state of the spelling actions. 4265 """ 4266 from QScintilla.SpellChecker import SpellChecker 4267 spellingAvailable = SpellChecker.isAvailable() 4268 4269 self.spellCheckAct.setEnabled( 4270 len(self.editors) != 0 and spellingAvailable) 4271 self.autoSpellCheckAct.setEnabled(spellingAvailable) 4272 4273 def addToExtrasMenu(self, menu): 4274 """ 4275 Public method to add some actions to the Extras menu. 4276 4277 @param menu reference to the menu to add actions to (QMenu) 4278 """ 4279 self.__editSpellingMenu = QMenu(QCoreApplication.translate( 4280 'ViewManager', "Edit Dictionary")) 4281 self.__editProjectPwlAct = self.__editSpellingMenu.addAction( 4282 QCoreApplication.translate('ViewManager', "Project Word List"), 4283 self.__editProjectPWL) 4284 self.__editProjectPelAct = self.__editSpellingMenu.addAction( 4285 QCoreApplication.translate( 4286 'ViewManager', "Project Exception List"), 4287 self.__editProjectPEL) 4288 self.__editSpellingMenu.addSeparator() 4289 self.__editUserPwlAct = self.__editSpellingMenu.addAction( 4290 QCoreApplication.translate('ViewManager', "User Word List"), 4291 self.__editUserPWL) 4292 self.__editUserPelAct = self.__editSpellingMenu.addAction( 4293 QCoreApplication.translate('ViewManager', "User Exception List"), 4294 self.__editUserPEL) 4295 self.__editSpellingMenu.aboutToShow.connect( 4296 self.__showEditSpellingMenu) 4297 4298 menu.addAction(self.spellCheckAct) 4299 menu.addAction(self.autoSpellCheckAct) 4300 menu.addMenu(self.__editSpellingMenu) 4301 menu.addSeparator() 4302 4303 def initSpellingToolbar(self, toolbarManager): 4304 """ 4305 Public method to create the Spelling toolbar. 4306 4307 @param toolbarManager reference to a toolbar manager object 4308 (E5ToolBarManager) 4309 @return the generated toolbar 4310 """ 4311 tb = QToolBar(QCoreApplication.translate('ViewManager', 'Spelling'), 4312 self.ui) 4313 tb.setIconSize(UI.Config.ToolBarIconSize) 4314 tb.setObjectName("SpellingToolbar") 4315 tb.setToolTip(QCoreApplication.translate('ViewManager', 'Spelling')) 4316 4317 tb.addAction(self.spellCheckAct) 4318 tb.addAction(self.autoSpellCheckAct) 4319 4320 toolbarManager.addToolBar(tb, tb.windowTitle()) 4321 4322 return tb 4323 4324 ################################################################## 4325 ## Methods and slots that deal with file and window handling 4326 ################################################################## 4327 4328 def __openFiles(self): 4329 """ 4330 Private slot to open some files. 4331 """ 4332 # set the cwd of the dialog based on the following search criteria: 4333 # 1: Directory of currently active editor 4334 # 2: Directory of currently active project 4335 # 3: CWD 4336 import QScintilla.Lexers 4337 fileFilter = self._getOpenFileFilter() 4338 progs = E5FileDialog.getOpenFileNamesAndFilter( 4339 self.ui, 4340 QCoreApplication.translate('ViewManager', "Open files"), 4341 self._getOpenStartDir(), 4342 QScintilla.Lexers.getOpenFileFiltersList(True, True), 4343 fileFilter)[0] 4344 for prog in progs: 4345 self.openFiles(prog) 4346 4347 def openFiles(self, prog): 4348 """ 4349 Public slot to open some files. 4350 4351 @param prog name of file to be opened (string) 4352 """ 4353 prog = os.path.abspath(prog) 4354 # Open up the new files. 4355 self.openSourceFile(prog) 4356 4357 def checkDirty(self, editor, autosave=False): 4358 """ 4359 Public method to check the dirty status and open a message window. 4360 4361 @param editor editor window to check 4362 @type Editor 4363 @param autosave flag indicating that the file should be saved 4364 automatically 4365 @type bool 4366 @return flag indicating successful reset of the dirty flag 4367 @rtype bool 4368 """ 4369 if editor.isModified(): 4370 fn = editor.getFileName() 4371 # ignore the dirty status, if there is more than one open editor 4372 # for the same file 4373 if fn and self.getOpenEditorCount(fn) > 1: 4374 return True 4375 4376 if fn is None: 4377 fn = editor.getNoName() 4378 autosave = False 4379 if autosave: 4380 res = editor.saveFile() 4381 else: 4382 res = E5MessageBox.okToClearData( 4383 self.ui, 4384 QCoreApplication.translate('ViewManager', "File Modified"), 4385 QCoreApplication.translate( 4386 'ViewManager', 4387 """<p>The file <b>{0}</b> has unsaved changes.</p>""") 4388 .format(fn), 4389 editor.saveFile) 4390 if res: 4391 self.setEditorName(editor, editor.getFileName()) 4392 return res 4393 4394 return True 4395 4396 def checkAllDirty(self): 4397 """ 4398 Public method to check the dirty status of all editors. 4399 4400 @return flag indicating successful reset of all dirty flags 4401 @rtype bool 4402 """ 4403 return all(self.checkDirty(editor) for editor in self.editors) 4404 4405 def checkFileDirty(self, fn): 4406 """ 4407 Public method to check the dirty status of an editor given its file 4408 name and open a message window. 4409 4410 @param fn file name of editor to be checked 4411 @type str 4412 @return flag indicating successful reset of the dirty flag 4413 @rtype bool 4414 """ 4415 for editor in self.editors: 4416 if Utilities.samepath(fn, editor.getFileName()): 4417 break 4418 else: 4419 return True 4420 4421 res = self.checkDirty(editor) 4422 return res 4423 4424 def hasDirtyEditor(self): 4425 """ 4426 Public method to ask, if any of the open editors contains unsaved 4427 changes. 4428 4429 @return flag indicating at least one editor has unsaved changes 4430 @rtype bool 4431 """ 4432 return any(editor.isModified() for editor in self.editors) 4433 4434 def closeEditor(self, editor, ignoreDirty=False): 4435 """ 4436 Public method to close an editor window. 4437 4438 @param editor editor window to be closed 4439 @type Editor 4440 @param ignoreDirty flag indicating to ignore the 'dirty' status 4441 @type bool 4442 @return flag indicating success 4443 @rtype bool 4444 """ 4445 # save file if necessary 4446 if not ignoreDirty and not self.checkDirty(editor): 4447 return False 4448 4449 # get the filename of the editor for later use 4450 fn = editor.getFileName() 4451 4452 # remove the window 4453 editor.parent().shutdownTimer() 4454 self._removeView(editor) 4455 self.editors.remove(editor) 4456 4457 # send a signal, if it was the last editor for this filename 4458 if fn and self.getOpenEditor(fn) is None: 4459 self.editorClosed.emit(fn) 4460 self.editorClosedEd.emit(editor) 4461 4462 # send a signal, if it was the very last editor 4463 if not len(self.editors): 4464 self.__lastEditorClosed() 4465 self.lastEditorClosed.emit() 4466 4467 editor.deleteLater() 4468 4469 return True 4470 4471 def closeCurrentWindow(self): 4472 """ 4473 Public method to close the current window. 4474 4475 @return flag indicating success (boolean) 4476 """ 4477 aw = self.activeWindow() 4478 if aw is None: 4479 return False 4480 4481 res = self.closeEditor(aw) 4482 if res and aw == self.currentEditor: 4483 self.currentEditor = None 4484 4485 return res 4486 4487 def closeAllWindows(self, ignoreDirty=False): 4488 """ 4489 Public method to close all editor windows. 4490 4491 @param ignoreDirty flag indicating to ignore the 'dirty' status 4492 @type bool 4493 """ 4494 savedEditors = self.editors[:] 4495 for editor in savedEditors: 4496 self.closeEditor(editor, ignoreDirty=ignoreDirty) 4497 4498 def closeWindow(self, fn, ignoreDirty=False): 4499 """ 4500 Public method to close an arbitrary source editor. 4501 4502 @param fn file name of the editor to be closed 4503 @type str 4504 @param ignoreDirty flag indicating to ignore the 'dirty' status 4505 @type bool 4506 @return flag indicating success 4507 @rtype bool 4508 """ 4509 for editor in self.editors: 4510 if Utilities.samepath(fn, editor.getFileName()): 4511 break 4512 else: 4513 return True 4514 4515 res = self.closeEditor(editor, ignoreDirty=ignoreDirty) 4516 if res and editor == self.currentEditor: 4517 self.currentEditor = None 4518 4519 return res 4520 4521 def closeEditorWindow(self, editor): 4522 """ 4523 Public method to close an arbitrary source editor. 4524 4525 @param editor editor to be closed 4526 """ 4527 if editor is None: 4528 return 4529 4530 res = self.closeEditor(editor) 4531 if res and editor == self.currentEditor: 4532 self.currentEditor = None 4533 4534 def exit(self): 4535 """ 4536 Public method to handle the debugged program terminating. 4537 """ 4538 if self.currentEditor is not None: 4539 self.currentEditor.highlight() 4540 self.currentEditor = None 4541 4542 for editor in self.editors: 4543 editor.refreshCoverageAnnotations() 4544 4545 self.__setSbFile() 4546 4547 def openSourceFile(self, fn, lineno=-1, filetype="", 4548 selStart=0, selEnd=0, pos=0, addNext=False, 4549 indexes=None): 4550 """ 4551 Public slot to display a file in an editor. 4552 4553 @param fn name of file to be opened 4554 @type str 4555 @param lineno line number to place the cursor at or list of line 4556 numbers (cursor will be placed at the next line greater than 4557 the current one) 4558 @type int or list of int 4559 @param filetype type of the source file 4560 @type str 4561 @param selStart start of an area to be selected 4562 @type int 4563 @param selEnd end of an area to be selected 4564 @type int 4565 @param pos position within the line to place the cursor at 4566 @type int 4567 @param addNext flag indicating to add the file next to the current 4568 editor 4569 @type bool 4570 @param indexes of the editor, first the split view index, second the 4571 index within the view 4572 @type tuple of two int 4573 @return reference to the opened editor 4574 @rtype Editor 4575 """ 4576 try: 4577 newWin, editor = self.getEditor(fn, filetype=filetype, 4578 addNext=addNext, indexes=indexes) 4579 except (OSError, UnicodeDecodeError): 4580 return None 4581 4582 if newWin: 4583 self._modificationStatusChanged(editor.isModified(), editor) 4584 self._checkActions(editor) 4585 4586 cline, cindex = editor.getCursorPosition() 4587 cline += 1 4588 if isinstance(lineno, list): 4589 if len(lineno) > 1: 4590 for line in lineno: 4591 if line > cline: 4592 break 4593 else: 4594 line = lineno[0] 4595 elif len(lineno) == 1: 4596 line = lineno[0] 4597 else: 4598 line = -1 4599 else: 4600 line = lineno 4601 4602 if line >= 0 and line != cline: 4603 editor.ensureVisibleTop(line) 4604 editor.gotoLine(line, pos) 4605 4606 if selStart != selEnd: 4607 editor.setSelection(line - 1, selStart, line - 1, selEnd) 4608 4609 # insert filename into list of recently opened files 4610 self.addToRecentList(fn) 4611 4612 return editor 4613 4614 def __connectEditor(self, editor): 4615 """ 4616 Private method to establish all editor connections. 4617 4618 @param editor reference to the editor object to be connected 4619 """ 4620 editor.modificationStatusChanged.connect( 4621 self._modificationStatusChanged) 4622 editor.cursorChanged.connect( 4623 lambda f, l, p: self.__cursorChanged(f, l, p, editor)) 4624 editor.editorSaved.connect( 4625 lambda fn: self.__editorSaved(fn, editor)) 4626 editor.editorRenamed.connect( 4627 lambda fn: self.__editorRenamed(fn, editor)) 4628 editor.breakpointToggled.connect(self.__breakpointToggled) 4629 editor.bookmarkToggled.connect(self.__bookmarkToggled) 4630 editor.syntaxerrorToggled.connect(self._syntaxErrorToggled) 4631 editor.coverageMarkersShown.connect(self.__coverageMarkersShown) 4632 editor.autoCompletionAPIsAvailable.connect( 4633 lambda a: self.__editorAutoCompletionAPIsAvailable(a, editor)) 4634 editor.undoAvailable.connect(self.undoAct.setEnabled) 4635 editor.redoAvailable.connect(self.redoAct.setEnabled) 4636 editor.taskMarkersUpdated.connect(self.__taskMarkersUpdated) 4637 editor.changeMarkersUpdated.connect(self.__changeMarkersUpdated) 4638 editor.languageChanged.connect( 4639 lambda: self.__editorConfigChanged(editor)) 4640 editor.eolChanged.connect( 4641 lambda: self.__editorConfigChanged(editor)) 4642 editor.encodingChanged.connect( 4643 lambda: self.__editorConfigChanged(editor)) 4644 editor.selectionChanged.connect( 4645 lambda: self.__searchWidget.selectionChanged(editor)) 4646 editor.selectionChanged.connect( 4647 lambda: self.__replaceWidget.selectionChanged(editor)) 4648 editor.selectionChanged.connect( 4649 lambda: self.__editorSelectionChanged(editor)) 4650 editor.lastEditPositionAvailable.connect( 4651 self.__lastEditPositionAvailable) 4652 editor.zoomValueChanged.connect( 4653 lambda v: self.zoomValueChanged(v, editor)) 4654 editor.mouseDoubleClick.connect( 4655 lambda pos, buttons: self.__editorDoubleClicked(editor, pos, 4656 buttons)) 4657 4658 editor.languageChanged.connect( 4659 lambda: self.editorLanguageChanged.emit(editor)) 4660 editor.textChanged.connect(lambda: self.editorTextChanged.emit(editor)) 4661 4662 def newEditorView(self, fn, caller, filetype="", indexes=None): 4663 """ 4664 Public method to create a new editor displaying the given document. 4665 4666 @param fn filename of this view 4667 @type str 4668 @param caller reference to the editor calling this method 4669 @type Editor 4670 @param filetype type of the source file 4671 @type str 4672 @param indexes of the editor, first the split view index, second the 4673 index within the view 4674 @type tuple of two int 4675 @return reference to the new editor object 4676 @rtype Editor 4677 """ 4678 editor, assembly = self.cloneEditor(caller, filetype, fn) 4679 4680 self._addView(assembly, fn, caller.getNoName(), indexes=indexes) 4681 self._modificationStatusChanged(editor.isModified(), editor) 4682 self._checkActions(editor) 4683 4684 return editor 4685 4686 def cloneEditor(self, caller, filetype, fn): 4687 """ 4688 Public method to clone an editor displaying the given document. 4689 4690 @param caller reference to the editor calling this method 4691 @param filetype type of the source file (string) 4692 @param fn filename of this view 4693 @return reference to the new editor object (Editor.Editor) and the new 4694 editor assembly object (EditorAssembly.EditorAssembly) 4695 """ 4696 from QScintilla.EditorAssembly import EditorAssembly 4697 assembly = EditorAssembly(self.dbs, fn, self, filetype=filetype, 4698 editor=caller, 4699 tv=e5App().getObject("TaskViewer")) 4700 editor = assembly.getEditor() 4701 self.editors.append(editor) 4702 self.__connectEditor(editor) 4703 self.__editorOpened() 4704 self.editorOpened.emit(fn) 4705 self.editorOpenedEd.emit(editor) 4706 4707 return editor, assembly 4708 4709 def addToRecentList(self, fn): 4710 """ 4711 Public slot to add a filename to the list of recently opened files. 4712 4713 @param fn name of the file to be added 4714 """ 4715 for recent in self.recent[:]: 4716 if Utilities.samepath(fn, recent): 4717 self.recent.remove(recent) 4718 self.recent.insert(0, fn) 4719 maxRecent = Preferences.getUI("RecentNumber") 4720 if len(self.recent) > maxRecent: 4721 self.recent = self.recent[:maxRecent] 4722 self.__saveRecent() 4723 4724 def showDebugSource(self, fn, line): 4725 """ 4726 Public method to open the given file and highlight the given line in 4727 it. 4728 4729 @param fn filename of editor to update (string) 4730 @param line line number to highlight (int) 4731 """ 4732 if not fn.startswith('<'): 4733 self.openSourceFile(fn, line) 4734 self.setFileLine(fn, line) 4735 4736 def setFileLine(self, fn, line, error=False, syntaxError=False): 4737 """ 4738 Public method to update the user interface when the current program 4739 or line changes. 4740 4741 @param fn filename of editor to update (string) 4742 @param line line number to highlight (int) 4743 @param error flag indicating an error highlight (boolean) 4744 @param syntaxError flag indicating a syntax error 4745 """ 4746 try: 4747 newWin, self.currentEditor = self.getEditor(fn) 4748 except (OSError, UnicodeDecodeError): 4749 return 4750 4751 enc = self.currentEditor.getEncoding() 4752 lang = self.currentEditor.getLanguage() 4753 eol = self.currentEditor.getEolIndicator() 4754 zoom = self.currentEditor.getZoom() 4755 self.__setSbFile(fn, line, encoding=enc, language=lang, eol=eol, 4756 zoom=zoom) 4757 4758 # Change the highlighted line. 4759 self.currentEditor.highlight(line, error, syntaxError) 4760 4761 self.currentEditor.highlightVisible() 4762 self._checkActions(self.currentEditor, False) 4763 4764 def __setSbFile(self, fn=None, line=None, pos=None, 4765 encoding=None, language=None, eol=None, 4766 zoom=None): 4767 """ 4768 Private method to set the file info in the status bar. 4769 4770 @param fn filename to display (string) 4771 @param line line number to display (int) 4772 @param pos character position to display (int) 4773 @param encoding encoding name to display (string) 4774 @param language language to display (string) 4775 @param eol eol indicator to display (string) 4776 @param zoom zoom value (integer) 4777 """ 4778 if not fn: 4779 fn = '' 4780 writ = ' ' 4781 else: 4782 if QFileInfo(fn).isWritable(): 4783 writ = 'rw' 4784 else: 4785 writ = 'ro' 4786 self.sbWritable.setText(writ) 4787 4788 if line is None: 4789 line = '' 4790 self.sbLine.setText( 4791 QCoreApplication.translate('ViewManager', 'Line: {0:5}') 4792 .format(line)) 4793 4794 if pos is None: 4795 pos = '' 4796 self.sbPos.setText( 4797 QCoreApplication.translate('ViewManager', 'Pos: {0:5}') 4798 .format(pos)) 4799 4800 if encoding is None: 4801 encoding = '' 4802 self.sbEnc.setText(encoding) 4803 4804 if language is None: 4805 pixmap = QPixmap() 4806 elif language == "": 4807 pixmap = UI.PixmapCache.getPixmap("fileText") 4808 else: 4809 import QScintilla.Lexers 4810 pixmap = QScintilla.Lexers.getLanguageIcon(language, True) 4811 self.sbLang.setPixmap(pixmap) 4812 if pixmap.isNull(): 4813 self.sbLang.setText(language) 4814 self.sbLang.setToolTip("") 4815 else: 4816 self.sbLang.setText("") 4817 self.sbLang.setToolTip( 4818 QCoreApplication.translate('ViewManager', 'Language: {0}') 4819 .format(language)) 4820 4821 if eol is None: 4822 eol = '' 4823 self.sbEol.setPixmap(self.__eolPixmap(eol)) 4824 self.sbEol.setToolTip( 4825 QCoreApplication.translate('ViewManager', 'EOL Mode: {0}') 4826 .format(eol)) 4827 4828 if zoom is None: 4829 if QApplication.focusWidget() == e5App().getObject("Shell"): 4830 aw = e5App().getObject("Shell") 4831 else: 4832 aw = self.activeWindow() 4833 if aw: 4834 self.sbZoom.setValue(aw.getZoom()) 4835 else: 4836 self.sbZoom.setValue(zoom) 4837 4838 def __eolPixmap(self, eolIndicator): 4839 """ 4840 Private method to get an EOL pixmap for an EOL string. 4841 4842 @param eolIndicator eol indicator string (string) 4843 @return pixmap for the eol indicator (QPixmap) 4844 """ 4845 if eolIndicator == "LF": 4846 pixmap = UI.PixmapCache.getPixmap("eolLinux") 4847 elif eolIndicator == "CR": 4848 pixmap = UI.PixmapCache.getPixmap("eolMac") 4849 elif eolIndicator == "CRLF": 4850 pixmap = UI.PixmapCache.getPixmap("eolWindows") 4851 else: 4852 pixmap = QPixmap() 4853 return pixmap 4854 4855 def __unhighlight(self): 4856 """ 4857 Private slot to switch of all highlights. 4858 """ 4859 self.unhighlight() 4860 4861 def unhighlight(self, current=False): 4862 """ 4863 Public method to switch off all highlights or the highlight of 4864 the current editor. 4865 4866 @param current flag indicating only the current editor should be 4867 unhighlighted (boolean) 4868 """ 4869 if current: 4870 if self.currentEditor is not None: 4871 self.currentEditor.highlight() 4872 else: 4873 for editor in self.editors: 4874 editor.highlight() 4875 4876 def getOpenFilenames(self): 4877 """ 4878 Public method returning a list of the filenames of all editors. 4879 4880 @return list of all opened filenames (list of strings) 4881 """ 4882 filenames = [] 4883 for editor in self.editors: 4884 fn = editor.getFileName() 4885 if fn is not None and fn not in filenames and os.path.exists(fn): 4886 # only return names of existing files 4887 filenames.append(fn) 4888 4889 return filenames 4890 4891 def getEditor(self, fn, filetype="", addNext=False, indexes=None): 4892 """ 4893 Public method to return the editor displaying the given file. 4894 4895 If there is no editor with the given file, a new editor window is 4896 created. 4897 4898 @param fn filename to look for 4899 @type str 4900 @param filetype type of the source file 4901 @type str 4902 @param addNext flag indicating that if a new editor needs to be 4903 created, it should be added next to the current editor 4904 @type bool 4905 @param indexes of the editor, first the split view index, second the 4906 index within the view 4907 @type tuple of two int 4908 @return tuple of two values giving a flag indicating a new window 4909 creation and a reference to the editor displaying this file 4910 @rtype tuple of (bool, Editor) 4911 """ 4912 newWin = False 4913 editor = self.activeWindow() 4914 if editor is None or not Utilities.samepath(fn, editor.getFileName()): 4915 for editor in self.editors: 4916 if Utilities.samepath(fn, editor.getFileName()): 4917 break 4918 else: 4919 from QScintilla.EditorAssembly import EditorAssembly 4920 assembly = EditorAssembly(self.dbs, fn, self, 4921 filetype=filetype, 4922 tv=e5App().getObject("TaskViewer")) 4923 editor = assembly.getEditor() 4924 self.editors.append(editor) 4925 self.__connectEditor(editor) 4926 self.__editorOpened() 4927 self.editorOpened.emit(fn) 4928 self.editorOpenedEd.emit(editor) 4929 newWin = True 4930 4931 if newWin: 4932 self._addView(assembly, fn, addNext=addNext, indexes=indexes) 4933 else: 4934 self._showView(editor.parent(), fn) 4935 4936 return (newWin, editor) 4937 4938 def getOpenEditors(self): 4939 """ 4940 Public method to get references to all open editors. 4941 4942 @return list of references to all open editors (list of 4943 QScintilla.editor) 4944 """ 4945 return self.editors 4946 4947 def getOpenEditorsCount(self): 4948 """ 4949 Public method to get the number of open editors. 4950 4951 @return number of open editors (integer) 4952 """ 4953 return len(self.editors) 4954 4955 def getOpenEditor(self, fn): 4956 """ 4957 Public method to return the editor displaying the given file. 4958 4959 @param fn filename to look for 4960 @return a reference to the editor displaying this file or None, if 4961 no editor was found 4962 """ 4963 for editor in self.editors: 4964 if Utilities.samepath(fn, editor.getFileName()): 4965 return editor 4966 4967 return None 4968 4969 def getOpenEditorCount(self, fn): 4970 """ 4971 Public method to return the count of editors displaying the given file. 4972 4973 @param fn filename to look for 4974 @return count of editors displaying this file (integer) 4975 """ 4976 count = 0 4977 for editor in self.editors: 4978 if Utilities.samepath(fn, editor.getFileName()): 4979 count += 1 4980 return count 4981 4982 def getOpenEditorsForSession(self): 4983 """ 4984 Public method to get a lists of all open editors. 4985 4986 The returned list contains one list per split view. If the view manager 4987 cannot split the view, only one list of editors is returned. 4988 4989 Note: This method should be implemented by subclasses. 4990 4991 @return list of list of editor references 4992 @rtype list of list of Editor 4993 """ 4994 return [self.editors] 4995 4996 def getActiveName(self): 4997 """ 4998 Public method to retrieve the filename of the active window. 4999 5000 @return filename of active window (string) 5001 """ 5002 aw = self.activeWindow() 5003 if aw: 5004 return aw.getFileName() 5005 else: 5006 return None 5007 5008 def saveEditor(self, fn): 5009 """ 5010 Public method to save a named editor file. 5011 5012 @param fn filename of editor to be saved (string) 5013 @return flag indicating success (boolean) 5014 """ 5015 for editor in self.editors: 5016 if Utilities.samepath(fn, editor.getFileName()): 5017 break 5018 else: 5019 return True 5020 5021 if not editor.isModified(): 5022 return True 5023 else: 5024 ok = editor.saveFile() 5025 return ok 5026 5027 def saveEditorEd(self, ed): 5028 """ 5029 Public slot to save the contents of an editor. 5030 5031 @param ed editor to be saved 5032 @return flag indicating success (boolean) 5033 """ 5034 if ed: 5035 if not ed.isModified(): 5036 return True 5037 else: 5038 ok = ed.saveFile() 5039 if ok: 5040 self.setEditorName(ed, ed.getFileName()) 5041 return ok 5042 else: 5043 return False 5044 5045 def saveCurrentEditor(self): 5046 """ 5047 Public slot to save the contents of the current editor. 5048 """ 5049 aw = self.activeWindow() 5050 self.saveEditorEd(aw) 5051 5052 def saveAsEditorEd(self, ed): 5053 """ 5054 Public slot to save the contents of an editor to a new file. 5055 5056 @param ed editor to be saved 5057 """ 5058 if ed: 5059 ok = ed.saveFileAs() 5060 if ok: 5061 self.setEditorName(ed, ed.getFileName()) 5062 5063 def saveAsCurrentEditor(self): 5064 """ 5065 Public slot to save the contents of the current editor to a new file. 5066 """ 5067 aw = self.activeWindow() 5068 self.saveAsEditorEd(aw) 5069 5070 def saveCopyEditorEd(self, ed): 5071 """ 5072 Public slot to save the contents of an editor to a new copy of 5073 the file. 5074 5075 @param ed editor to be saved 5076 """ 5077 if ed: 5078 ed.saveFileCopy() 5079 5080 def saveCopyCurrentEditor(self): 5081 """ 5082 Public slot to save the contents of the current editor to a new copy 5083 of the file. 5084 """ 5085 aw = self.activeWindow() 5086 self.saveCopyEditorEd(aw) 5087 5088 def saveEditorsList(self, editors): 5089 """ 5090 Public slot to save a list of editors. 5091 5092 @param editors list of editors to be saved 5093 """ 5094 for editor in editors: 5095 ok = editor.saveFile() 5096 if ok: 5097 self.setEditorName(editor, editor.getFileName()) 5098 5099 def saveAllEditors(self): 5100 """ 5101 Public slot to save the contents of all editors. 5102 """ 5103 for editor in self.editors: 5104 ok = editor.saveFile() 5105 if ok: 5106 self.setEditorName(editor, editor.getFileName()) 5107 5108 # restart autosave timer 5109 if self.autosaveInterval > 0: 5110 self.autosaveTimer.start(self.autosaveInterval * 60000) 5111 5112 def __exportMenuTriggered(self, act): 5113 """ 5114 Private method to handle the selection of an export format. 5115 5116 @param act reference to the action that was triggered (QAction) 5117 """ 5118 aw = self.activeWindow() 5119 if aw: 5120 exporterFormat = act.data() 5121 aw.exportFile(exporterFormat) 5122 5123 def newEditor(self): 5124 """ 5125 Public slot to generate a new empty editor. 5126 """ 5127 from QScintilla.EditorAssembly import EditorAssembly 5128 assembly = EditorAssembly(self.dbs, "", self, 5129 tv=e5App().getObject("TaskViewer")) 5130 editor = assembly.getEditor() 5131 self.editors.append(editor) 5132 self.__connectEditor(editor) 5133 self._addView(assembly, None) 5134 self.__editorOpened() 5135 self._checkActions(editor) 5136 self.editorOpened.emit("") 5137 self.editorOpenedEd.emit(editor) 5138 5139 def printEditor(self, editor): 5140 """ 5141 Public slot to print an editor. 5142 5143 @param editor editor to be printed 5144 """ 5145 if editor: 5146 editor.printFile() 5147 else: 5148 return 5149 5150 def printCurrentEditor(self): 5151 """ 5152 Public slot to print the contents of the current editor. 5153 """ 5154 aw = self.activeWindow() 5155 self.printEditor(aw) 5156 5157 def printPreviewCurrentEditor(self): 5158 """ 5159 Public slot to show a print preview of the current editor. 5160 """ 5161 aw = self.activeWindow() 5162 if aw: 5163 aw.printPreviewFile() 5164 5165 def __showFileMenu(self): 5166 """ 5167 Private method to set up the file menu. 5168 """ 5169 self.menuRecentAct.setEnabled(len(self.recent) > 0) 5170 5171 def __showRecentMenu(self): 5172 """ 5173 Private method to set up recent files menu. 5174 """ 5175 self.__loadRecent() 5176 5177 self.recentMenu.clear() 5178 5179 for idx, rs in enumerate(self.recent, start=1): 5180 formatStr = '&{0:d}. {1}' if idx < 10 else '{0:d}. {1}' 5181 act = self.recentMenu.addAction( 5182 formatStr.format( 5183 idx, 5184 Utilities.compactPath(rs, self.ui.maxMenuFilePathLen))) 5185 act.setData(rs) 5186 act.setEnabled(QFileInfo(rs).exists()) 5187 5188 self.recentMenu.addSeparator() 5189 self.recentMenu.addAction( 5190 QCoreApplication.translate('ViewManager', '&Clear'), 5191 self.clearRecent) 5192 5193 def __openSourceFile(self, act): 5194 """ 5195 Private method to open a file from the list of recently opened files. 5196 5197 @param act reference to the action that triggered (QAction) 5198 """ 5199 file = act.data() 5200 if file: 5201 self.openSourceFile(file) 5202 5203 def clearRecent(self): 5204 """ 5205 Public method to clear the recent files menu. 5206 """ 5207 self.recent = [] 5208 self.__saveRecent() 5209 5210 def __showBookmarkedMenu(self): 5211 """ 5212 Private method to set up bookmarked files menu. 5213 """ 5214 self.bookmarkedMenu.clear() 5215 5216 for rp in self.bookmarked: 5217 act = self.bookmarkedMenu.addAction( 5218 Utilities.compactPath(rp, self.ui.maxMenuFilePathLen)) 5219 act.setData(rp) 5220 act.setEnabled(QFileInfo(rp).exists()) 5221 5222 if len(self.bookmarked): 5223 self.bookmarkedMenu.addSeparator() 5224 self.bookmarkedMenu.addAction( 5225 QCoreApplication.translate('ViewManager', '&Add'), 5226 self.__addBookmarked) 5227 self.bookmarkedMenu.addAction( 5228 QCoreApplication.translate('ViewManager', '&Edit...'), 5229 self.__editBookmarked) 5230 self.bookmarkedMenu.addAction( 5231 QCoreApplication.translate('ViewManager', '&Clear'), 5232 self.__clearBookmarked) 5233 5234 def __addBookmarked(self): 5235 """ 5236 Private method to add the current file to the list of bookmarked files. 5237 """ 5238 an = self.getActiveName() 5239 if an is not None and an not in self.bookmarked: 5240 self.bookmarked.append(an) 5241 5242 def __editBookmarked(self): 5243 """ 5244 Private method to edit the list of bookmarked files. 5245 """ 5246 from .BookmarkedFilesDialog import BookmarkedFilesDialog 5247 dlg = BookmarkedFilesDialog(self.bookmarked, self.ui) 5248 if dlg.exec() == QDialog.DialogCode.Accepted: 5249 self.bookmarked = dlg.getBookmarkedFiles() 5250 5251 def __clearBookmarked(self): 5252 """ 5253 Private method to clear the bookmarked files menu. 5254 """ 5255 self.bookmarked = [] 5256 5257 def projectOpened(self): 5258 """ 5259 Public slot to handle the projectOpened signal. 5260 """ 5261 for editor in self.editors: 5262 editor.projectOpened() 5263 5264 self.__editProjectPwlAct.setEnabled(True) 5265 self.__editProjectPelAct.setEnabled(True) 5266 5267 def projectClosed(self): 5268 """ 5269 Public slot to handle the projectClosed signal. 5270 """ 5271 for editor in self.editors: 5272 editor.projectClosed() 5273 5274 self.__editProjectPwlAct.setEnabled(False) 5275 self.__editProjectPelAct.setEnabled(False) 5276 5277 def projectFileRenamed(self, oldfn, newfn): 5278 """ 5279 Public slot to handle the projectFileRenamed signal. 5280 5281 @param oldfn old filename of the file (string) 5282 @param newfn new filename of the file (string) 5283 """ 5284 editor = self.getOpenEditor(oldfn) 5285 if editor: 5286 editor.fileRenamed(newfn) 5287 5288 def projectLexerAssociationsChanged(self): 5289 """ 5290 Public slot to handle changes of the project lexer associations. 5291 """ 5292 for editor in self.editors: 5293 editor.projectLexerAssociationsChanged() 5294 5295 def enableEditorsCheckFocusIn(self, enabled): 5296 """ 5297 Public method to set a flag enabling the editors to perform focus in 5298 checks. 5299 5300 @param enabled flag indicating focus in checks should be performed 5301 (boolean) 5302 """ 5303 self.editorsCheckFocusIn = enabled 5304 5305 def editorsCheckFocusInEnabled(self): 5306 """ 5307 Public method returning the flag indicating editors should perform 5308 focus in checks. 5309 5310 @return flag indicating focus in checks should be performed (boolean) 5311 """ 5312 return self.editorsCheckFocusIn 5313 5314 def __findFileName(self): 5315 """ 5316 Private method to handle the search for file action. 5317 """ 5318 self.ui.showFindFileByNameDialog() 5319 5320 def appFocusChanged(self, old, now): 5321 """ 5322 Public method to handle the global change of focus. 5323 5324 @param old reference to the widget loosing focus 5325 @type QWidget 5326 @param now reference to the widget gaining focus 5327 @type QWidget 5328 """ 5329 # Focus handling was changed with Qt 5.13.1; this copes with that 5330 if now is None: 5331 return 5332 5333 from QScintilla.Shell import Shell 5334 5335 if not isinstance(now, (Editor, Shell)): 5336 self.editActGrp.setEnabled(False) 5337 self.copyActGrp.setEnabled(False) 5338 self.viewActGrp.setEnabled(False) 5339 self.sbZoom.setEnabled(False) 5340 else: 5341 self.sbZoom.setEnabled(True) 5342 self.sbZoom.setValue(now.getZoom()) 5343 5344 if not isinstance(now, (Editor, Shell)): 5345 self.searchActGrp.setEnabled(False) 5346 5347 if not isinstance(now, (Editor, Shell)): 5348 self.__lastFocusWidget = old 5349 5350 ################################################################## 5351 ## Below are the action methods for the edit menu 5352 ################################################################## 5353 5354 def __editUndo(self): 5355 """ 5356 Private method to handle the undo action. 5357 """ 5358 self.activeWindow().undo() 5359 5360 def __editRedo(self): 5361 """ 5362 Private method to handle the redo action. 5363 """ 5364 self.activeWindow().redo() 5365 5366 def __editRevert(self): 5367 """ 5368 Private method to handle the revert action. 5369 """ 5370 self.activeWindow().revertToUnmodified() 5371 5372 def __editCut(self): 5373 """ 5374 Private method to handle the cut action. 5375 """ 5376 if QApplication.focusWidget() == e5App().getObject("Shell"): 5377 e5App().getObject("Shell").cut() 5378 else: 5379 self.activeWindow().cut() 5380 5381 def __editCopy(self): 5382 """ 5383 Private method to handle the copy action. 5384 """ 5385 if QApplication.focusWidget() == e5App().getObject("Shell"): 5386 e5App().getObject("Shell").copy() 5387 else: 5388 self.activeWindow().copy() 5389 5390 def __editPaste(self): 5391 """ 5392 Private method to handle the paste action. 5393 """ 5394 if QApplication.focusWidget() == e5App().getObject("Shell"): 5395 e5App().getObject("Shell").paste() 5396 else: 5397 self.activeWindow().paste() 5398 5399 def __editDelete(self): 5400 """ 5401 Private method to handle the delete action. 5402 """ 5403 if QApplication.focusWidget() == e5App().getObject("Shell"): 5404 e5App().getObject("Shell").clear() 5405 else: 5406 self.activeWindow().clear() 5407 5408 def __editJoin(self): 5409 """ 5410 Private method to handle the join action. 5411 """ 5412 self.activeWindow().joinLines() 5413 5414 def __editIndent(self): 5415 """ 5416 Private method to handle the indent action. 5417 """ 5418 self.activeWindow().indentLineOrSelection() 5419 5420 def __editUnindent(self): 5421 """ 5422 Private method to handle the unindent action. 5423 """ 5424 self.activeWindow().unindentLineOrSelection() 5425 5426 def __editSmartIndent(self): 5427 """ 5428 Private method to handle the smart indent action. 5429 """ 5430 self.activeWindow().smartIndentLineOrSelection() 5431 5432 def __editToggleComment(self): 5433 """ 5434 Private method to handle the toggle comment action. 5435 """ 5436 self.activeWindow().toggleCommentBlock() 5437 5438 def __editComment(self): 5439 """ 5440 Private method to handle the comment action. 5441 """ 5442 self.activeWindow().commentLineOrSelection() 5443 5444 def __editUncomment(self): 5445 """ 5446 Private method to handle the uncomment action. 5447 """ 5448 self.activeWindow().uncommentLineOrSelection() 5449 5450 def __editStreamComment(self): 5451 """ 5452 Private method to handle the stream comment action. 5453 """ 5454 self.activeWindow().streamCommentLineOrSelection() 5455 5456 def __editBoxComment(self): 5457 """ 5458 Private method to handle the box comment action. 5459 """ 5460 self.activeWindow().boxCommentLineOrSelection() 5461 5462 def __editSelectBrace(self): 5463 """ 5464 Private method to handle the select to brace action. 5465 """ 5466 self.activeWindow().selectToMatchingBrace() 5467 5468 def __editSelectAll(self): 5469 """ 5470 Private method to handle the select all action. 5471 """ 5472 self.activeWindow().selectAll(True) 5473 5474 def __editDeselectAll(self): 5475 """ 5476 Private method to handle the select all action. 5477 """ 5478 self.activeWindow().selectAll(False) 5479 5480 def __convertEOL(self): 5481 """ 5482 Private method to handle the convert line end characters action. 5483 """ 5484 aw = self.activeWindow() 5485 aw.convertEols(aw.eolMode()) 5486 5487 def __shortenEmptyLines(self): 5488 """ 5489 Private method to handle the shorten empty lines action. 5490 """ 5491 self.activeWindow().shortenEmptyLines() 5492 5493 def __editAutoComplete(self): 5494 """ 5495 Private method to handle the autocomplete action. 5496 """ 5497 self.activeWindow().autoComplete() 5498 5499 def __editAutoCompleteFromDoc(self): 5500 """ 5501 Private method to handle the autocomplete from document action. 5502 """ 5503 self.activeWindow().autoCompleteFromDocument() 5504 5505 def __editAutoCompleteFromAPIs(self): 5506 """ 5507 Private method to handle the autocomplete from APIs action. 5508 """ 5509 self.activeWindow().autoCompleteFromAPIs() 5510 5511 def __editAutoCompleteFromAll(self): 5512 """ 5513 Private method to handle the autocomplete from All action. 5514 """ 5515 self.activeWindow().autoCompleteFromAll() 5516 5517 def __editorAutoCompletionAPIsAvailable(self, available, editor): 5518 """ 5519 Private method to handle the availability of API autocompletion signal. 5520 5521 @param available flag indicating the availability of API 5522 autocompletion 5523 @type bool 5524 @param editor reference to the editor 5525 @type Editor 5526 """ 5527 self.autoCompleteAct.setEnabled( 5528 editor.canProvideDynamicAutoCompletion()) 5529 self.autoCompleteFromAPIsAct.setEnabled(available) 5530 self.autoCompleteFromAllAct.setEnabled(available) 5531 self.calltipsAct.setEnabled(editor.canProvideCallTipps()) 5532 5533 def __editShowCallTips(self): 5534 """ 5535 Private method to handle the calltips action. 5536 """ 5537 self.activeWindow().callTip() 5538 5539 def __editShowCodeInfo(self): 5540 """ 5541 Private method to handle the code info action. 5542 """ 5543 self.showEditorInfo(self.activeWindow()) 5544 5545 ################################################################## 5546 ## Below are the action and utility methods for the search menu 5547 ################################################################## 5548 5549 def textForFind(self, getCurrentWord=True): 5550 """ 5551 Public method to determine the selection or the current word for the 5552 next find operation. 5553 5554 @param getCurrentWord flag indicating to return the current word, if 5555 no selected text was found (boolean) 5556 @return selection or current word (string) 5557 """ 5558 aw = self.activeWindow() 5559 if aw is None: 5560 return "" 5561 5562 return aw.getSearchText(not getCurrentWord) 5563 5564 def getSRHistory(self, key): 5565 """ 5566 Public method to get the search or replace history list. 5567 5568 @param key list to return (must be 'search' or 'replace') 5569 @return the requested history list (list of strings) 5570 """ 5571 return self.srHistory[key] 5572 5573 def showSearchWidget(self): 5574 """ 5575 Public method to show the search widget. 5576 """ 5577 self.__replaceWidget.hide() 5578 self.__searchWidget.show() 5579 self.__searchWidget.show(self.textForFind()) 5580 5581 def __searchNext(self): 5582 """ 5583 Private slot to handle the search next action. 5584 """ 5585 if self.__replaceWidget.isVisible(): 5586 self.__replaceWidget.findNext() 5587 else: 5588 self.__searchWidget.findNext() 5589 5590 def __searchPrev(self): 5591 """ 5592 Private slot to handle the search previous action. 5593 """ 5594 if self.__replaceWidget.isVisible(): 5595 self.__replaceWidget.findPrev() 5596 else: 5597 self.__searchWidget.findPrev() 5598 5599 def showReplaceWidget(self): 5600 """ 5601 Public method to show the replace widget. 5602 """ 5603 self.__searchWidget.hide() 5604 self.__replaceWidget.show(self.textForFind()) 5605 5606 def __findNextWord(self): 5607 """ 5608 Private slot to find the next occurrence of the current word of the 5609 current editor. 5610 """ 5611 self.activeWindow().searchCurrentWordForward() 5612 5613 def __findPrevWord(self): 5614 """ 5615 Private slot to find the previous occurrence of the current word of 5616 the current editor. 5617 """ 5618 self.activeWindow().searchCurrentWordBackward() 5619 5620 def __searchClearMarkers(self): 5621 """ 5622 Private method to clear the search markers of the active window. 5623 """ 5624 self.activeWindow().clearSearchIndicators() 5625 5626 def __goto(self): 5627 """ 5628 Private method to handle the goto action. 5629 """ 5630 from QScintilla.GotoDialog import GotoDialog 5631 5632 aw = self.activeWindow() 5633 lines = aw.lines() 5634 curLine = aw.getCursorPosition()[0] + 1 5635 dlg = GotoDialog(lines, curLine, self.ui, None, True) 5636 if dlg.exec() == QDialog.DialogCode.Accepted: 5637 aw.gotoLine(dlg.getLinenumber(), expand=True) 5638 5639 def __gotoBrace(self): 5640 """ 5641 Private method to handle the goto brace action. 5642 """ 5643 self.activeWindow().moveToMatchingBrace() 5644 5645 def __gotoLastEditPosition(self): 5646 """ 5647 Private method to move the cursor to the last edit position. 5648 """ 5649 self.activeWindow().gotoLastEditPosition() 5650 5651 def __lastEditPositionAvailable(self): 5652 """ 5653 Private slot to handle the lastEditPositionAvailable signal of an 5654 editor. 5655 """ 5656 self.gotoLastEditAct.setEnabled(True) 5657 5658 def __gotoNextMethodClass(self): 5659 """ 5660 Private slot to go to the next Python/Ruby method or class definition. 5661 """ 5662 self.activeWindow().gotoMethodClass(False) 5663 5664 def __gotoPreviousMethodClass(self): 5665 """ 5666 Private slot to go to the previous Python/Ruby method or class 5667 definition. 5668 """ 5669 self.activeWindow().gotoMethodClass(True) 5670 5671 def __searchFiles(self): 5672 """ 5673 Private method to handle the search in files action. 5674 """ 5675 self.ui.showFindFilesDialog(self.textForFind()) 5676 5677 def __replaceFiles(self): 5678 """ 5679 Private method to handle the replace in files action. 5680 """ 5681 self.ui.showReplaceFilesDialog(self.textForFind()) 5682 5683 def __searchOpenFiles(self): 5684 """ 5685 Private method to handle the search in open files action. 5686 """ 5687 self.ui.showFindFilesDialog(self.textForFind(), openFiles=True) 5688 5689 def __replaceOpenFiles(self): 5690 """ 5691 Private method to handle the replace in open files action. 5692 """ 5693 self.ui.showReplaceFilesDialog(self.textForFind(), openFiles=True) 5694 5695 ################################################################## 5696 ## Below are the action methods for the view menu 5697 ################################################################## 5698 5699 def __zoomIn(self): 5700 """ 5701 Private method to handle the zoom in action. 5702 """ 5703 if QApplication.focusWidget() == e5App().getObject("Shell"): 5704 e5App().getObject("Shell").zoomIn() 5705 else: 5706 aw = self.activeWindow() 5707 if aw: 5708 aw.zoomIn() 5709 self.sbZoom.setValue(aw.getZoom()) 5710 5711 def __zoomOut(self): 5712 """ 5713 Private method to handle the zoom out action. 5714 """ 5715 if QApplication.focusWidget() == e5App().getObject("Shell"): 5716 e5App().getObject("Shell").zoomOut() 5717 else: 5718 aw = self.activeWindow() 5719 if aw: 5720 aw.zoomOut() 5721 self.sbZoom.setValue(aw.getZoom()) 5722 5723 def __zoomReset(self): 5724 """ 5725 Private method to reset the zoom factor. 5726 """ 5727 self.__zoomTo(0) 5728 5729 def __zoom(self): 5730 """ 5731 Private method to handle the zoom action. 5732 """ 5733 aw = ( 5734 e5App().getObject("Shell") 5735 if QApplication.focusWidget() == e5App().getObject("Shell") else 5736 self.activeWindow() 5737 ) 5738 if aw: 5739 from QScintilla.ZoomDialog import ZoomDialog 5740 dlg = ZoomDialog(aw.getZoom(), self.ui, None, True) 5741 if dlg.exec() == QDialog.DialogCode.Accepted: 5742 value = dlg.getZoomSize() 5743 self.__zoomTo(value) 5744 5745 def __zoomTo(self, value): 5746 """ 5747 Private slot to zoom to a given value. 5748 5749 @param value zoom value to be set (integer) 5750 """ 5751 aw = ( 5752 e5App().getObject("Shell") 5753 if QApplication.focusWidget() == e5App().getObject("Shell") else 5754 self.activeWindow() 5755 ) 5756 if aw: 5757 aw.zoomTo(value) 5758 self.sbZoom.setValue(aw.getZoom()) 5759 5760 def zoomValueChanged(self, value, zoomingWidget): 5761 """ 5762 Public slot to handle changes of the zoom value. 5763 5764 @param value new zoom value 5765 @type int 5766 @param zoomingWidget reference to the widget triggering the slot 5767 @type Editor or Shell 5768 """ 5769 aw = ( 5770 e5App().getObject("Shell") 5771 if QApplication.focusWidget() == e5App().getObject("Shell") else 5772 self.activeWindow() 5773 ) 5774 if aw and aw == zoomingWidget: 5775 self.sbZoom.setValue(value) 5776 5777 def __clearAllFolds(self): 5778 """ 5779 Private method to handle the clear all folds action. 5780 """ 5781 aw = self.activeWindow() 5782 if aw: 5783 aw.clearFolds() 5784 5785 def __toggleAll(self): 5786 """ 5787 Private method to handle the toggle all folds action. 5788 """ 5789 aw = self.activeWindow() 5790 if aw: 5791 aw.foldAll() 5792 5793 def __toggleAllChildren(self): 5794 """ 5795 Private method to handle the toggle all folds (including children) 5796 action. 5797 """ 5798 aw = self.activeWindow() 5799 if aw: 5800 aw.foldAll(True) 5801 5802 def __toggleCurrent(self): 5803 """ 5804 Private method to handle the toggle current fold action. 5805 """ 5806 aw = self.activeWindow() 5807 if aw: 5808 aw.toggleCurrentFold() 5809 5810 def __newDocumentView(self): 5811 """ 5812 Private method to open a new view of the current editor. 5813 """ 5814 aw = self.activeWindow() 5815 if aw: 5816 self.newEditorView(aw.getFileName(), aw, aw.getFileType()) 5817 5818 def __newDocumentSplitView(self): 5819 """ 5820 Private method to open a new view of the current editor in a new split. 5821 """ 5822 aw = self.activeWindow() 5823 if aw: 5824 self.addSplit() 5825 self.newEditorView(aw.getFileName(), aw, aw.getFileType()) 5826 5827 def __splitView(self): 5828 """ 5829 Private method to handle the split view action. 5830 """ 5831 self.addSplit() 5832 5833 def __splitOrientation(self, checked): 5834 """ 5835 Private method to handle the split orientation action. 5836 5837 @param checked flag indicating the checked state of the action 5838 (boolean). True means splitting horizontally. 5839 """ 5840 if checked: 5841 self.setSplitOrientation(Qt.Orientation.Horizontal) 5842 self.splitViewAct.setIcon( 5843 UI.PixmapCache.getIcon("splitHorizontal")) 5844 self.splitRemoveAct.setIcon( 5845 UI.PixmapCache.getIcon("remsplitHorizontal")) 5846 self.newDocumentSplitViewAct.setIcon( 5847 UI.PixmapCache.getIcon("splitHorizontal")) 5848 else: 5849 self.setSplitOrientation(Qt.Orientation.Vertical) 5850 self.splitViewAct.setIcon( 5851 UI.PixmapCache.getIcon("splitVertical")) 5852 self.splitRemoveAct.setIcon( 5853 UI.PixmapCache.getIcon("remsplitVertical")) 5854 self.newDocumentSplitViewAct.setIcon( 5855 UI.PixmapCache.getIcon("splitVertical")) 5856 Preferences.setUI("SplitOrientationVertical", checked) 5857 5858 def __previewEditor(self, checked): 5859 """ 5860 Private slot to handle a change of the preview selection state. 5861 5862 @param checked state of the action (boolean) 5863 """ 5864 Preferences.setUI("ShowFilePreview", checked) 5865 self.previewStateChanged.emit(checked) 5866 5867 def __astViewer(self, checked): 5868 """ 5869 Private slot to handle a change of the AST Viewer selection state. 5870 5871 @param checked state of the action (boolean) 5872 """ 5873 self.astViewerStateChanged.emit(checked) 5874 5875 def __disViewer(self, checked): 5876 """ 5877 Private slot to handle a change of the DIS Viewer selection state. 5878 5879 @param checked state of the action (boolean) 5880 """ 5881 self.disViewerStateChanged.emit(checked) 5882 5883 ################################################################## 5884 ## Below are the action methods for the macro menu 5885 ################################################################## 5886 5887 def __macroStartRecording(self): 5888 """ 5889 Private method to handle the start macro recording action. 5890 """ 5891 self.activeWindow().macroRecordingStart() 5892 5893 def __macroStopRecording(self): 5894 """ 5895 Private method to handle the stop macro recording action. 5896 """ 5897 self.activeWindow().macroRecordingStop() 5898 5899 def __macroRun(self): 5900 """ 5901 Private method to handle the run macro action. 5902 """ 5903 self.activeWindow().macroRun() 5904 5905 def __macroDelete(self): 5906 """ 5907 Private method to handle the delete macro action. 5908 """ 5909 self.activeWindow().macroDelete() 5910 5911 def __macroLoad(self): 5912 """ 5913 Private method to handle the load macro action. 5914 """ 5915 self.activeWindow().macroLoad() 5916 5917 def __macroSave(self): 5918 """ 5919 Private method to handle the save macro action. 5920 """ 5921 self.activeWindow().macroSave() 5922 5923 ################################################################## 5924 ## Below are the action methods for the bookmarks menu 5925 ################################################################## 5926 5927 def __toggleBookmark(self): 5928 """ 5929 Private method to handle the toggle bookmark action. 5930 """ 5931 self.activeWindow().menuToggleBookmark() 5932 5933 def __nextBookmark(self): 5934 """ 5935 Private method to handle the next bookmark action. 5936 """ 5937 self.activeWindow().nextBookmark() 5938 5939 def __previousBookmark(self): 5940 """ 5941 Private method to handle the previous bookmark action. 5942 """ 5943 self.activeWindow().previousBookmark() 5944 5945 def __clearAllBookmarks(self): 5946 """ 5947 Private method to handle the clear all bookmarks action. 5948 """ 5949 for editor in self.editors: 5950 editor.clearBookmarks() 5951 5952 self.bookmarkNextAct.setEnabled(False) 5953 self.bookmarkPreviousAct.setEnabled(False) 5954 self.bookmarkClearAct.setEnabled(False) 5955 5956 def __showBookmarkMenu(self): 5957 """ 5958 Private method to set up the bookmark menu. 5959 """ 5960 bookmarksFound = 0 5961 filenames = self.getOpenFilenames() 5962 for filename in filenames: 5963 editor = self.getOpenEditor(filename) 5964 bookmarksFound = len(editor.getBookmarks()) > 0 5965 if bookmarksFound: 5966 self.menuBookmarksAct.setEnabled(True) 5967 return 5968 self.menuBookmarksAct.setEnabled(False) 5969 5970 def __showBookmarksMenu(self): 5971 """ 5972 Private method to handle the show bookmarks menu signal. 5973 """ 5974 self.bookmarksMenu.clear() 5975 5976 filenames = self.getOpenFilenames() 5977 for filename in sorted(filenames): 5978 editor = self.getOpenEditor(filename) 5979 for bookmark in editor.getBookmarks(): 5980 bmSuffix = " : {0:d}".format(bookmark) 5981 act = self.bookmarksMenu.addAction( 5982 "{0}{1}".format( 5983 Utilities.compactPath( 5984 filename, 5985 self.ui.maxMenuFilePathLen - len(bmSuffix)), 5986 bmSuffix)) 5987 act.setData([filename, bookmark]) 5988 5989 def __bookmarkSelected(self, act): 5990 """ 5991 Private method to handle the bookmark selected signal. 5992 5993 @param act reference to the action that triggered (QAction) 5994 """ 5995 bmList = act.data() 5996 filename = bmList[0] 5997 line = bmList[1] 5998 self.openSourceFile(filename, line) 5999 6000 def __bookmarkToggled(self, editor): 6001 """ 6002 Private slot to handle the bookmarkToggled signal. 6003 6004 It checks some bookmark actions and reemits the signal. 6005 6006 @param editor editor that sent the signal 6007 """ 6008 if editor.hasBookmarks(): 6009 self.bookmarkNextAct.setEnabled(True) 6010 self.bookmarkPreviousAct.setEnabled(True) 6011 self.bookmarkClearAct.setEnabled(True) 6012 else: 6013 self.bookmarkNextAct.setEnabled(False) 6014 self.bookmarkPreviousAct.setEnabled(False) 6015 self.bookmarkClearAct.setEnabled(False) 6016 self.bookmarkToggled.emit(editor) 6017 6018 def __gotoSyntaxError(self): 6019 """ 6020 Private method to handle the goto syntax error action. 6021 """ 6022 self.activeWindow().gotoSyntaxError() 6023 6024 def __clearAllSyntaxErrors(self): 6025 """ 6026 Private method to handle the clear all syntax errors action. 6027 """ 6028 for editor in self.editors: 6029 editor.clearSyntaxError() 6030 6031 def _syntaxErrorToggled(self, editor): 6032 """ 6033 Protected slot to handle the syntaxerrorToggled signal. 6034 6035 It checks some syntax error actions and reemits the signal. 6036 6037 @param editor editor that sent the signal 6038 """ 6039 if editor.hasSyntaxErrors(): 6040 self.syntaxErrorGotoAct.setEnabled(True) 6041 self.syntaxErrorClearAct.setEnabled(True) 6042 else: 6043 self.syntaxErrorGotoAct.setEnabled(False) 6044 self.syntaxErrorClearAct.setEnabled(False) 6045 if editor.hasWarnings(): 6046 self.warningsNextAct.setEnabled(True) 6047 self.warningsPreviousAct.setEnabled(True) 6048 self.warningsClearAct.setEnabled(True) 6049 else: 6050 self.warningsNextAct.setEnabled(False) 6051 self.warningsPreviousAct.setEnabled(False) 6052 self.warningsClearAct.setEnabled(False) 6053 self.syntaxerrorToggled.emit(editor) 6054 6055 def __nextWarning(self): 6056 """ 6057 Private method to handle the next warning action. 6058 """ 6059 self.activeWindow().nextWarning() 6060 6061 def __previousWarning(self): 6062 """ 6063 Private method to handle the previous warning action. 6064 """ 6065 self.activeWindow().previousWarning() 6066 6067 def __clearAllWarnings(self): 6068 """ 6069 Private method to handle the clear all warnings action. 6070 """ 6071 for editor in self.editors: 6072 editor.clearWarnings() 6073 6074 def __nextUncovered(self): 6075 """ 6076 Private method to handle the next uncovered action. 6077 """ 6078 self.activeWindow().nextUncovered() 6079 6080 def __previousUncovered(self): 6081 """ 6082 Private method to handle the previous uncovered action. 6083 """ 6084 self.activeWindow().previousUncovered() 6085 6086 def __coverageMarkersShown(self, shown): 6087 """ 6088 Private slot to handle the coverageMarkersShown signal. 6089 6090 @param shown flag indicating whether the markers were shown or cleared 6091 """ 6092 if shown: 6093 self.notcoveredNextAct.setEnabled(True) 6094 self.notcoveredPreviousAct.setEnabled(True) 6095 else: 6096 self.notcoveredNextAct.setEnabled(False) 6097 self.notcoveredPreviousAct.setEnabled(False) 6098 6099 def __taskMarkersUpdated(self, editor): 6100 """ 6101 Private slot to handle the taskMarkersUpdated signal. 6102 6103 @param editor editor that sent the signal 6104 """ 6105 if editor.hasTaskMarkers(): 6106 self.taskNextAct.setEnabled(True) 6107 self.taskPreviousAct.setEnabled(True) 6108 else: 6109 self.taskNextAct.setEnabled(False) 6110 self.taskPreviousAct.setEnabled(False) 6111 6112 def __nextTask(self): 6113 """ 6114 Private method to handle the next task action. 6115 """ 6116 self.activeWindow().nextTask() 6117 6118 def __previousTask(self): 6119 """ 6120 Private method to handle the previous task action. 6121 """ 6122 self.activeWindow().previousTask() 6123 6124 def __changeMarkersUpdated(self, editor): 6125 """ 6126 Private slot to handle the changeMarkersUpdated signal. 6127 6128 @param editor editor that sent the signal 6129 """ 6130 if editor.hasChangeMarkers(): 6131 self.changeNextAct.setEnabled(True) 6132 self.changePreviousAct.setEnabled(True) 6133 else: 6134 self.changeNextAct.setEnabled(False) 6135 self.changePreviousAct.setEnabled(False) 6136 6137 def __nextChange(self): 6138 """ 6139 Private method to handle the next change action. 6140 """ 6141 self.activeWindow().nextChange() 6142 6143 def __previousChange(self): 6144 """ 6145 Private method to handle the previous change action. 6146 """ 6147 self.activeWindow().previousChange() 6148 6149 ################################################################## 6150 ## Below are the action methods for the spell checking functions 6151 ################################################################## 6152 6153 def __showEditSpellingMenu(self): 6154 """ 6155 Private method to set up the edit dictionaries menu. 6156 """ 6157 proj = e5App().getObject("Project") 6158 projetOpen = proj.isOpen() 6159 pwl = e5App().getObject("Project").getProjectDictionaries()[0] 6160 self.__editProjectPwlAct.setEnabled(projetOpen and bool(pwl)) 6161 pel = e5App().getObject("Project").getProjectDictionaries()[1] 6162 self.__editProjectPelAct.setEnabled(projetOpen and bool(pel)) 6163 6164 from QScintilla.SpellChecker import SpellChecker 6165 pwl = SpellChecker.getUserDictionaryPath() 6166 self.__editUserPwlAct.setEnabled(bool(pwl)) 6167 pel = SpellChecker.getUserDictionaryPath(True) 6168 self.__editUserPelAct.setEnabled(bool(pel)) 6169 6170 def __setAutoSpellChecking(self): 6171 """ 6172 Private slot to set the automatic spell checking of all editors. 6173 """ 6174 enabled = self.autoSpellCheckAct.isChecked() 6175 Preferences.setEditor("AutoSpellCheckingEnabled", enabled) 6176 for editor in self.editors: 6177 editor.setAutoSpellChecking() 6178 6179 def __spellCheck(self): 6180 """ 6181 Private slot to perform a spell check of the current editor. 6182 """ 6183 aw = self.activeWindow() 6184 if aw: 6185 aw.checkSpelling() 6186 6187 def __editProjectPWL(self): 6188 """ 6189 Private slot to edit the project word list. 6190 """ 6191 pwl = e5App().getObject("Project").getProjectDictionaries()[0] 6192 self.__editSpellingDictionary(pwl) 6193 6194 def __editProjectPEL(self): 6195 """ 6196 Private slot to edit the project exception list. 6197 """ 6198 pel = e5App().getObject("Project").getProjectDictionaries()[1] 6199 self.__editSpellingDictionary(pel) 6200 6201 def __editUserPWL(self): 6202 """ 6203 Private slot to edit the user word list. 6204 """ 6205 from QScintilla.SpellChecker import SpellChecker 6206 pwl = SpellChecker.getUserDictionaryPath() 6207 self.__editSpellingDictionary(pwl) 6208 6209 def __editUserPEL(self): 6210 """ 6211 Private slot to edit the user exception list. 6212 """ 6213 from QScintilla.SpellChecker import SpellChecker 6214 pel = SpellChecker.getUserDictionaryPath(True) 6215 self.__editSpellingDictionary(pel) 6216 6217 def __editSpellingDictionary(self, dictionaryFile): 6218 """ 6219 Private slot to edit the given spelling dictionary. 6220 6221 @param dictionaryFile file name of the dictionary to edit (string) 6222 """ 6223 if os.path.exists(dictionaryFile): 6224 try: 6225 with open(dictionaryFile, "r", encoding="utf-8") as f: 6226 data = f.read() 6227 except OSError as err: 6228 E5MessageBox.critical( 6229 self.ui, 6230 QCoreApplication.translate( 6231 'ViewManager', "Edit Spelling Dictionary"), 6232 QCoreApplication.translate( 6233 'ViewManager', 6234 """<p>The spelling dictionary file <b>{0}</b> could""" 6235 """ not be read.</p><p>Reason: {1}</p>""").format( 6236 dictionaryFile, str(err))) 6237 return 6238 6239 fileInfo = ( 6240 dictionaryFile if len(dictionaryFile) < 40 6241 else "...{0}".format(dictionaryFile[-40:]) 6242 ) 6243 from QScintilla.SpellingDictionaryEditDialog import ( 6244 SpellingDictionaryEditDialog 6245 ) 6246 dlg = SpellingDictionaryEditDialog( 6247 data, 6248 QCoreApplication.translate('ViewManager', "Editing {0}") 6249 .format(fileInfo), 6250 self.ui) 6251 if dlg.exec() == QDialog.DialogCode.Accepted: 6252 data = dlg.getData() 6253 try: 6254 with open(dictionaryFile, "w", encoding="utf-8") as f: 6255 f.write(data) 6256 except OSError as err: 6257 E5MessageBox.critical( 6258 self.ui, 6259 QCoreApplication.translate( 6260 'ViewManager', "Edit Spelling Dictionary"), 6261 QCoreApplication.translate( 6262 'ViewManager', 6263 """<p>The spelling dictionary file <b>{0}</b>""" 6264 """ could not be written.</p>""" 6265 """<p>Reason: {1}</p>""").format( 6266 dictionaryFile, str(err))) 6267 return 6268 6269 self.ui.showNotification( 6270 UI.PixmapCache.getPixmap("spellchecking48"), 6271 QCoreApplication.translate( 6272 'ViewManager', "Edit Spelling Dictionary"), 6273 QCoreApplication.translate( 6274 'ViewManager', 6275 "The spelling dictionary was saved successfully.")) 6276 6277 ################################################################## 6278 ## Below are general utility methods 6279 ################################################################## 6280 6281 def handleResetUI(self): 6282 """ 6283 Public slot to handle the resetUI signal. 6284 """ 6285 editor = self.activeWindow() 6286 if editor is None: 6287 self.__setSbFile() 6288 else: 6289 line, pos = editor.getCursorPosition() 6290 enc = editor.getEncoding() 6291 lang = editor.getLanguage() 6292 eol = editor.getEolIndicator() 6293 zoom = editor.getZoom() 6294 self.__setSbFile(editor.getFileName(), line + 1, pos, enc, lang, 6295 eol, zoom) 6296 6297 def closeViewManager(self): 6298 """ 6299 Public method to shutdown the viewmanager. 6300 6301 If it cannot close all editor windows, it aborts the shutdown process. 6302 6303 @return flag indicating success (boolean) 6304 """ 6305 with contextlib.suppress(TypeError): 6306 e5App().focusChanged.disconnect(self.appFocusChanged) 6307 6308 self.closeAllWindows() 6309 self.currentEditor = None 6310 6311 # save the list of recently opened projects 6312 self.__saveRecent() 6313 6314 # save the list of recently opened projects 6315 Preferences.Prefs.settings.setValue( 6316 'Bookmarked/Sources', self.bookmarked) 6317 6318 res = len(self.editors) == 0 6319 6320 if not res: 6321 e5App().focusChanged.connect(self.appFocusChanged) 6322 6323 return res 6324 6325 def __lastEditorClosed(self): 6326 """ 6327 Private slot to handle the lastEditorClosed signal. 6328 """ 6329 self.closeActGrp.setEnabled(False) 6330 self.saveActGrp.setEnabled(False) 6331 self.exportersMenuAct.setEnabled(False) 6332 self.printAct.setEnabled(False) 6333 if self.printPreviewAct: 6334 self.printPreviewAct.setEnabled(False) 6335 self.editActGrp.setEnabled(False) 6336 self.searchActGrp.setEnabled(False) 6337 self.viewActGrp.setEnabled(False) 6338 self.viewFoldActGrp.setEnabled(False) 6339 self.unhighlightAct.setEnabled(False) 6340 self.newDocumentViewAct.setEnabled(False) 6341 self.newDocumentSplitViewAct.setEnabled(False) 6342 self.splitViewAct.setEnabled(False) 6343 self.splitOrientationAct.setEnabled(False) 6344 self.previewAct.setEnabled(True) 6345 self.astViewerAct.setEnabled(False) 6346 self.disViewerAct.setEnabled(False) 6347 self.macroActGrp.setEnabled(False) 6348 self.bookmarkActGrp.setEnabled(False) 6349 self.__enableSpellingActions() 6350 self.__setSbFile(zoom=0) 6351 6352 # remove all split views, if this is supported 6353 if self.canSplit(): 6354 while self.removeSplit(): 6355 pass 6356 6357 # stop the autosave timer 6358 if self.autosaveTimer.isActive(): 6359 self.autosaveTimer.stop() 6360 6361 # hide search and replace widgets 6362 self.__searchWidget.hide() 6363 self.__replaceWidget.hide() 6364 6365 # hide the AST Viewer via its action 6366 self.astViewerAct.setChecked(False) 6367 6368 # hide the DIS Viewer via its action 6369 self.disViewerAct.setChecked(False) 6370 6371 def __editorOpened(self): 6372 """ 6373 Private slot to handle the editorOpened signal. 6374 """ 6375 self.closeActGrp.setEnabled(True) 6376 self.saveActGrp.setEnabled(True) 6377 self.exportersMenuAct.setEnabled(True) 6378 self.printAct.setEnabled(True) 6379 if self.printPreviewAct: 6380 self.printPreviewAct.setEnabled(True) 6381 self.editActGrp.setEnabled(True) 6382 self.searchActGrp.setEnabled(True) 6383 self.viewActGrp.setEnabled(True) 6384 self.viewFoldActGrp.setEnabled(True) 6385 self.unhighlightAct.setEnabled(True) 6386 self.newDocumentViewAct.setEnabled(True) 6387 if self.canSplit(): 6388 self.newDocumentSplitViewAct.setEnabled(True) 6389 self.splitViewAct.setEnabled(True) 6390 self.splitOrientationAct.setEnabled(True) 6391 self.macroActGrp.setEnabled(True) 6392 self.bookmarkActGrp.setEnabled(True) 6393 self.__enableSpellingActions() 6394 self.astViewerAct.setEnabled(True) 6395 self.disViewerAct.setEnabled(True) 6396 6397 # activate the autosave timer 6398 if ( 6399 not self.autosaveTimer.isActive() and 6400 self.autosaveInterval > 0 6401 ): 6402 self.autosaveTimer.start(self.autosaveInterval * 60000) 6403 6404 def __autosave(self): 6405 """ 6406 Private slot to save the contents of all editors automatically. 6407 6408 Only named editors will be saved by the autosave timer. 6409 """ 6410 for editor in self.editors: 6411 if editor.shouldAutosave(): 6412 ok = editor.saveFile() 6413 if ok: 6414 self.setEditorName(editor, editor.getFileName()) 6415 6416 # restart autosave timer 6417 if self.autosaveInterval > 0: 6418 self.autosaveTimer.start(self.autosaveInterval * 60000) 6419 6420 def _checkActions(self, editor, setSb=True): 6421 """ 6422 Protected slot to check some actions for their enable/disable status 6423 and set the statusbar info. 6424 6425 @param editor editor window 6426 @param setSb flag indicating an update of the status bar is wanted 6427 (boolean) 6428 """ 6429 if editor is not None: 6430 self.saveAct.setEnabled(editor.isModified()) 6431 self.revertAct.setEnabled(editor.isModified()) 6432 6433 self.undoAct.setEnabled(editor.isUndoAvailable()) 6434 self.redoAct.setEnabled(editor.isRedoAvailable()) 6435 self.gotoLastEditAct.setEnabled( 6436 editor.isLastEditPositionAvailable()) 6437 6438 lex = editor.getLexer() 6439 if lex is not None: 6440 self.commentAct.setEnabled(lex.canBlockComment()) 6441 self.uncommentAct.setEnabled(lex.canBlockComment()) 6442 self.streamCommentAct.setEnabled(lex.canStreamComment()) 6443 self.boxCommentAct.setEnabled(lex.canBoxComment()) 6444 else: 6445 self.commentAct.setEnabled(False) 6446 self.uncommentAct.setEnabled(False) 6447 self.streamCommentAct.setEnabled(False) 6448 self.boxCommentAct.setEnabled(False) 6449 6450 if editor.hasBookmarks(): 6451 self.bookmarkNextAct.setEnabled(True) 6452 self.bookmarkPreviousAct.setEnabled(True) 6453 self.bookmarkClearAct.setEnabled(True) 6454 else: 6455 self.bookmarkNextAct.setEnabled(False) 6456 self.bookmarkPreviousAct.setEnabled(False) 6457 self.bookmarkClearAct.setEnabled(False) 6458 6459 if editor.hasSyntaxErrors(): 6460 self.syntaxErrorGotoAct.setEnabled(True) 6461 self.syntaxErrorClearAct.setEnabled(True) 6462 else: 6463 self.syntaxErrorGotoAct.setEnabled(False) 6464 self.syntaxErrorClearAct.setEnabled(False) 6465 6466 if editor.hasWarnings(): 6467 self.warningsNextAct.setEnabled(True) 6468 self.warningsPreviousAct.setEnabled(True) 6469 self.warningsClearAct.setEnabled(True) 6470 else: 6471 self.warningsNextAct.setEnabled(False) 6472 self.warningsPreviousAct.setEnabled(False) 6473 self.warningsClearAct.setEnabled(False) 6474 6475 if editor.hasCoverageMarkers(): 6476 self.notcoveredNextAct.setEnabled(True) 6477 self.notcoveredPreviousAct.setEnabled(True) 6478 else: 6479 self.notcoveredNextAct.setEnabled(False) 6480 self.notcoveredPreviousAct.setEnabled(False) 6481 6482 if editor.hasTaskMarkers(): 6483 self.taskNextAct.setEnabled(True) 6484 self.taskPreviousAct.setEnabled(True) 6485 else: 6486 self.taskNextAct.setEnabled(False) 6487 self.taskPreviousAct.setEnabled(False) 6488 6489 if editor.hasChangeMarkers(): 6490 self.changeNextAct.setEnabled(True) 6491 self.changePreviousAct.setEnabled(True) 6492 else: 6493 self.changeNextAct.setEnabled(False) 6494 self.changePreviousAct.setEnabled(False) 6495 6496 if editor.canAutoCompleteFromAPIs(): 6497 self.autoCompleteFromAPIsAct.setEnabled(True) 6498 self.autoCompleteFromAllAct.setEnabled(True) 6499 else: 6500 self.autoCompleteFromAPIsAct.setEnabled(False) 6501 self.autoCompleteFromAllAct.setEnabled(False) 6502 self.autoCompleteAct.setEnabled( 6503 editor.canProvideDynamicAutoCompletion()) 6504 self.calltipsAct.setEnabled(editor.canProvideCallTipps()) 6505 self.codeInfoAct.setEnabled(self.__isEditorInfoSupportedEd(editor)) 6506 6507 if editor.isPyFile() or editor.isRubyFile(): 6508 self.gotoPreviousDefAct.setEnabled(True) 6509 self.gotoNextDefAct.setEnabled(True) 6510 else: 6511 self.gotoPreviousDefAct.setEnabled(False) 6512 self.gotoNextDefAct.setEnabled(False) 6513 6514 self.sortAct.setEnabled(editor.selectionIsRectangle()) 6515 enable = editor.hasSelection() 6516 self.editUpperCaseAct.setEnabled(enable) 6517 self.editLowerCaseAct.setEnabled(enable) 6518 6519 if setSb: 6520 line, pos = editor.getCursorPosition() 6521 enc = editor.getEncoding() 6522 lang = editor.getLanguage() 6523 eol = editor.getEolIndicator() 6524 zoom = editor.getZoom() 6525 self.__setSbFile( 6526 editor.getFileName(), line + 1, pos, enc, lang, eol, zoom) 6527 6528 self.checkActions.emit(editor) 6529 6530 saveAllEnable = False 6531 for editor in self.editors: 6532 if editor.isModified(): 6533 saveAllEnable = True 6534 self.saveAllAct.setEnabled(saveAllEnable) 6535 6536 def preferencesChanged(self): 6537 """ 6538 Public slot to handle the preferencesChanged signal. 6539 6540 This method performs the following actions 6541 <ul> 6542 <li>reread the colours for the syntax highlighting</li> 6543 <li>reloads the already created API objetcs</li> 6544 <li>starts or stops the autosave timer</li> 6545 <li><b>Note</b>: changes in viewmanager type are activated 6546 on an application restart.</li> 6547 </ul> 6548 """ 6549 # reload the APIs 6550 self.apisManager.reloadAPIs() 6551 6552 # reload editor settings 6553 for editor in self.editors: 6554 zoom = editor.getZoom() 6555 editor.readSettings() 6556 editor.zoomTo(zoom) 6557 6558 # reload the autosave timer setting 6559 self.autosaveInterval = Preferences.getEditor("AutosaveInterval") 6560 if len(self.editors): 6561 if ( 6562 self.autosaveTimer.isActive() and 6563 self.autosaveInterval == 0 6564 ): 6565 self.autosaveTimer.stop() 6566 elif ( 6567 not self.autosaveTimer.isActive() and 6568 self.autosaveInterval > 0 6569 ): 6570 self.autosaveTimer.start(self.autosaveInterval * 60000) 6571 6572 self.__enableSpellingActions() 6573 6574 def __editorSaved(self, fn, editor): 6575 """ 6576 Private slot to handle the editorSaved signal. 6577 6578 It simply re-emits the signal. 6579 6580 @param fn filename of the saved editor 6581 @type str 6582 @param editor reference to the editor 6583 @type Editor 6584 """ 6585 self.editorSaved.emit(fn) 6586 self.editorSavedEd.emit(editor) 6587 6588 def __editorRenamed(self, fn, editor): 6589 """ 6590 Private slot to handle the editorRenamed signal. 6591 6592 It simply re-emits the signal. 6593 6594 @param fn filename of the renamed editor 6595 @type str 6596 @param editor reference to the editor 6597 @type Editor 6598 """ 6599 self.editorRenamed.emit(fn) 6600 self.editorRenamedEd.emit(editor) 6601 6602 def __cursorChanged(self, fn, line, pos, editor): 6603 """ 6604 Private slot to handle the cursorChanged signal. 6605 6606 It emits the signal cursorChanged with parameter editor. 6607 6608 @param fn filename 6609 @type str 6610 @param line line number of the cursor 6611 @type int 6612 @param pos position in line of the cursor 6613 @type int 6614 @param editor reference to the editor 6615 @type Editor 6616 """ 6617 enc = editor.getEncoding() 6618 lang = editor.getLanguage() 6619 eol = editor.getEolIndicator() 6620 self.__setSbFile(fn, line, pos, enc, lang, eol) 6621 self.cursorChanged.emit(editor) 6622 6623 def __editorDoubleClicked(self, editor, pos, buttons): 6624 """ 6625 Private slot handling mouse double clicks of an editor. 6626 6627 Note: This method is simply a multiplexer to re-emit the signal 6628 with the editor prepended. 6629 6630 @param editor reference to the editor, that emitted the signal 6631 @type Editor 6632 @param pos position of the double click 6633 @type QPoint 6634 @param buttons mouse buttons that were double clicked 6635 @type Qt.MouseButtons 6636 """ 6637 self.editorDoubleClickedEd.emit(editor, pos, buttons) 6638 6639 def __breakpointToggled(self, editor): 6640 """ 6641 Private slot to handle the breakpointToggled signal. 6642 6643 It simply reemits the signal. 6644 6645 @param editor editor that sent the signal 6646 """ 6647 self.breakpointToggled.emit(editor) 6648 6649 def getActions(self, actionSetType): 6650 """ 6651 Public method to get a list of all actions. 6652 6653 @param actionSetType string denoting the action set to get. 6654 It must be one of "edit", "file", "search", "view", "window", 6655 "macro", "bookmark" or "spelling". 6656 @return list of all actions (list of E5Action) 6657 """ 6658 try: 6659 return self.__actions[actionSetType][:] 6660 except KeyError: 6661 return [] 6662 6663 def __editorCommand(self, cmd): 6664 """ 6665 Private method to send an editor command to the active window. 6666 6667 @param cmd the scintilla command to be sent 6668 """ 6669 focusWidget = QApplication.focusWidget() 6670 if focusWidget == e5App().getObject("Shell"): 6671 e5App().getObject("Shell").editorCommand(cmd) 6672 else: 6673 aw = self.activeWindow() 6674 if aw: 6675 aw.editorCommand(cmd) 6676 6677 def __newLineBelow(self): 6678 """ 6679 Private method to insert a new line below the current one even if 6680 cursor is not at the end of the line. 6681 """ 6682 focusWidget = QApplication.focusWidget() 6683 if focusWidget == e5App().getObject("Shell"): 6684 return 6685 else: 6686 aw = self.activeWindow() 6687 if aw: 6688 aw.newLineBelow() 6689 6690 def __editorConfigChanged(self, editor): 6691 """ 6692 Private slot to handle changes of an editor's configuration. 6693 6694 @param editor reference to the editor 6695 @type Editor 6696 """ 6697 fn = editor.getFileName() 6698 line, pos = editor.getCursorPosition() 6699 enc = editor.getEncoding() 6700 lang = editor.getLanguage() 6701 eol = editor.getEolIndicator() 6702 zoom = editor.getZoom() 6703 self.__setSbFile( 6704 fn, line + 1, pos, encoding=enc, language=lang, eol=eol, zoom=zoom) 6705 self._checkActions(editor, False) 6706 6707 def __editorSelectionChanged(self, editor): 6708 """ 6709 Private slot to handle changes of the current editors selection. 6710 6711 @param editor reference to the editor 6712 @type Editor 6713 """ 6714 self.sortAct.setEnabled(editor.selectionIsRectangle()) 6715 enable = editor.hasSelection() 6716 self.editUpperCaseAct.setEnabled(enable) 6717 self.editLowerCaseAct.setEnabled(enable) 6718 6719 def __editSortSelectedLines(self): 6720 """ 6721 Private slot to sort the selected lines. 6722 """ 6723 editor = self.activeWindow() 6724 if editor: 6725 editor.sortLines() 6726 6727 def __editInsertDocstring(self): 6728 """ 6729 Private method to insert a docstring. 6730 """ 6731 editor = self.activeWindow() 6732 if editor: 6733 editor.insertDocstring() 6734 6735 def showEditorInfo(self, editor): 6736 """ 6737 Public method to show some information for a given editor. 6738 6739 @param editor editor to show information text for 6740 @type Editor 6741 """ 6742 documentationViewer = self.ui.documentationViewer() 6743 if documentationViewer: 6744 documentationViewer.showInfo(editor) 6745 6746 def isEditorInfoSupported(self, language): 6747 """ 6748 Public method to check, if a language is supported by the 6749 documentation viewer. 6750 6751 @param language editor programming language to check 6752 @type str 6753 @return flag indicating the support status 6754 @rtype bool 6755 """ 6756 documentationViewer = self.ui.documentationViewer() 6757 if documentationViewer: 6758 return documentationViewer.isSupportedLanguage(language) 6759 else: 6760 return False 6761 6762 def __isEditorInfoSupportedEd(self, editor): 6763 """ 6764 Private method to check, if an editor is supported by the 6765 documentation viewer. 6766 6767 @param editor reference to the editor to check for 6768 @type Editor 6769 @return flag indicating the support status 6770 @rtype bool 6771 """ 6772 language = editor.getLanguage() 6773 return self.isEditorInfoSupported(language) 6774 6775 ################################################################## 6776 ## Below are protected utility methods 6777 ################################################################## 6778 6779 def _getOpenStartDir(self): 6780 """ 6781 Protected method to return the starting directory for a file open 6782 dialog. 6783 6784 The appropriate starting directory is calculated 6785 using the following search order, until a match is found:<br /> 6786 1: Directory of currently active editor<br /> 6787 2: Directory of currently active Project<br /> 6788 3: CWD 6789 6790 @return name of directory to start (string) 6791 """ 6792 # if we have an active source, return its path 6793 if ( 6794 self.activeWindow() is not None and 6795 self.activeWindow().getFileName() 6796 ): 6797 return os.path.dirname(self.activeWindow().getFileName()) 6798 6799 # check, if there is an active project and return its path 6800 elif e5App().getObject("Project").isOpen(): 6801 return e5App().getObject("Project").ppath 6802 6803 else: 6804 return ( 6805 Preferences.getMultiProject("Workspace") or 6806 Utilities.getHomeDir() 6807 ) 6808 6809 def _getOpenFileFilter(self): 6810 """ 6811 Protected method to return the active filename filter for a file open 6812 dialog. 6813 6814 The appropriate filename filter is determined by file extension of 6815 the currently active editor. 6816 6817 @return name of the filename filter (string) or None 6818 """ 6819 if ( 6820 self.activeWindow() is not None and 6821 self.activeWindow().getFileName() 6822 ): 6823 ext = os.path.splitext(self.activeWindow().getFileName())[1] 6824 rx = re.compile(r".*\*\.{0}[ )].*".format(ext[1:])) 6825 import QScintilla.Lexers 6826 filters = QScintilla.Lexers.getOpenFileFiltersList() 6827 index = -1 6828 for i in range(len(filters)): 6829 if rx.fullmatch(filters[i]): 6830 index = i 6831 break 6832 if index == -1: 6833 return Preferences.getEditor("DefaultOpenFilter") 6834 else: 6835 return filters[index] 6836 else: 6837 return Preferences.getEditor("DefaultOpenFilter") 6838 6839 ################################################################## 6840 ## Below are API handling methods 6841 ################################################################## 6842 6843 def getAPIsManager(self): 6844 """ 6845 Public method to get a reference to the APIs manager. 6846 6847 @return the APIs manager object (eric6.QScintilla.APIsManager) 6848 """ 6849 return self.apisManager 6850 6851 ####################################################################### 6852 ## Cooperation related methods 6853 ####################################################################### 6854 6855 def setCooperationClient(self, client): 6856 """ 6857 Public method to set a reference to the cooperation client. 6858 6859 @param client reference to the cooperation client (CooperationClient) 6860 """ 6861 self.__cooperationClient = client 6862 6863 def isConnected(self): 6864 """ 6865 Public method to check the connection status of the IDE. 6866 6867 @return flag indicating the connection status (boolean) 6868 """ 6869 return self.__cooperationClient.hasConnections() 6870 6871 def send(self, fileName, message): 6872 """ 6873 Public method to send an editor command to remote editors. 6874 6875 @param fileName file name of the editor (string) 6876 @param message command message to be sent (string) 6877 """ 6878 project = e5App().getObject("Project") 6879 if project.isProjectFile(fileName): 6880 self.__cooperationClient.sendEditorCommand( 6881 project.getHash(), 6882 project.getRelativeUniversalPath(fileName), 6883 message 6884 ) 6885 6886 def receive(self, projectHash, fileName, command): 6887 """ 6888 Public slot to handle received editor commands. 6889 6890 @param projectHash hash of the project (string) 6891 @param fileName project relative file name of the editor (string) 6892 @param command command string (string) 6893 """ 6894 project = e5App().getObject("Project") 6895 if projectHash == project.getHash(): 6896 fn = project.getAbsoluteUniversalPath(fileName) 6897 editor = self.getOpenEditor(fn) 6898 if editor: 6899 editor.receive(command) 6900 6901 def shareConnected(self, connected): 6902 """ 6903 Public slot to handle a change of the connected state. 6904 6905 @param connected flag indicating the connected state (boolean) 6906 """ 6907 for editor in self.getOpenEditors(): 6908 editor.shareConnected(connected) 6909 6910 def shareEditor(self, share): 6911 """ 6912 Public slot to set the shared status of the current editor. 6913 6914 @param share flag indicating the share status (boolean) 6915 """ 6916 aw = self.activeWindow() 6917 if aw is not None: 6918 fn = aw.getFileName() 6919 if fn and e5App().getObject("Project").isProjectFile(fn): 6920 aw.shareEditor(share) 6921 6922 def startSharedEdit(self): 6923 """ 6924 Public slot to start a shared edit session for the current editor. 6925 """ 6926 aw = self.activeWindow() 6927 if aw is not None: 6928 fn = aw.getFileName() 6929 if fn and e5App().getObject("Project").isProjectFile(fn): 6930 aw.startSharedEdit() 6931 6932 def sendSharedEdit(self): 6933 """ 6934 Public slot to end a shared edit session for the current editor and 6935 send the changes. 6936 """ 6937 aw = self.activeWindow() 6938 if aw is not None: 6939 fn = aw.getFileName() 6940 if fn and e5App().getObject("Project").isProjectFile(fn): 6941 aw.sendSharedEdit() 6942 6943 def cancelSharedEdit(self): 6944 """ 6945 Public slot to cancel a shared edit session for the current editor. 6946 """ 6947 aw = self.activeWindow() 6948 if aw is not None: 6949 fn = aw.getFileName() 6950 if fn and e5App().getObject("Project").isProjectFile(fn): 6951 aw.cancelSharedEdit() 6952 6953 ####################################################################### 6954 ## Symbols viewer related methods 6955 ####################################################################### 6956 6957 def insertSymbol(self, txt): 6958 """ 6959 Public slot to insert a symbol text into the active window. 6960 6961 @param txt text to be inserted (string) 6962 """ 6963 if self.__lastFocusWidget == e5App().getObject("Shell"): 6964 e5App().getObject("Shell").insert(txt) 6965 else: 6966 aw = self.activeWindow() 6967 if aw is not None: 6968 curline, curindex = aw.getCursorPosition() 6969 aw.insert(txt) 6970 aw.setCursorPosition(curline, curindex + len(txt)) 6971 6972 ####################################################################### 6973 ## Numbers viewer related methods 6974 ####################################################################### 6975 6976 def insertNumber(self, txt): 6977 """ 6978 Public slot to insert a number text into the active window. 6979 6980 @param txt text to be inserted (string) 6981 """ 6982 if self.__lastFocusWidget == e5App().getObject("Shell"): 6983 aw = e5App().getObject("Shell") 6984 if aw.hasSelectedText(): 6985 aw.removeSelectedText() 6986 aw.insert(txt) 6987 else: 6988 aw = self.activeWindow() 6989 if aw is not None: 6990 if aw.hasSelectedText(): 6991 aw.removeSelectedText() 6992 curline, curindex = aw.getCursorPosition() 6993 aw.insert(txt) 6994 aw.setCursorPosition(curline, curindex + len(txt)) 6995 6996 def getNumber(self): 6997 """ 6998 Public method to get a number from the active window. 6999 7000 @return selected text of the active window (string) 7001 """ 7002 txt = "" 7003 if self.__lastFocusWidget == e5App().getObject("Shell"): 7004 aw = e5App().getObject("Shell") 7005 if aw.hasSelectedText(): 7006 txt = aw.selectedText() 7007 else: 7008 aw = self.activeWindow() 7009 if aw is not None and aw.hasSelectedText(): 7010 txt = aw.selectedText() 7011 return txt 7012