eric7/ViewManager/ViewManager.py

branch
eric7
changeset 8312
800c432b34c8
parent 8260
2161475d9639
child 8314
e3642a6a1e71
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2002 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the view manager base class.
8 """
9
10 import re
11 import os
12 import contextlib
13
14 from PyQt5.QtCore import (
15 pyqtSignal, pyqtSlot, Qt, QSignalMapper, QTimer, QFileInfo, QPoint,
16 QCoreApplication
17 )
18 from PyQt5.QtGui import QKeySequence, QPixmap
19 from PyQt5.QtWidgets import (
20 QToolBar, QDialog, QApplication, QMenu, QWidget
21 )
22 from PyQt5.Qsci import QsciScintilla
23
24 from E5Gui.E5Application import e5App
25 from E5Gui import E5FileDialog, E5MessageBox
26
27 from Globals import recentNameFiles, isMacPlatform
28
29 import Preferences
30
31 from QScintilla.Editor import Editor
32
33 import Utilities
34
35 import UI.PixmapCache
36 import UI.Config
37
38 from E5Gui.E5Action import E5Action, createActionGroup
39
40
41 class 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.alignMapper.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 &current 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 closeEditor(self, editor, ignoreDirty=False):
4425 """
4426 Public method to close an editor window.
4427
4428 @param editor editor window to be closed
4429 @type Editor
4430 @param ignoreDirty flag indicating to ignore the 'dirty' status
4431 @type bool
4432 @return flag indicating success
4433 @rtype bool
4434 """
4435 # save file if necessary
4436 if not ignoreDirty and not self.checkDirty(editor):
4437 return False
4438
4439 # get the filename of the editor for later use
4440 fn = editor.getFileName()
4441
4442 # remove the window
4443 editor.parent().shutdownTimer()
4444 self._removeView(editor)
4445 self.editors.remove(editor)
4446
4447 # send a signal, if it was the last editor for this filename
4448 if fn and self.getOpenEditor(fn) is None:
4449 self.editorClosed.emit(fn)
4450 self.editorClosedEd.emit(editor)
4451
4452 # send a signal, if it was the very last editor
4453 if not len(self.editors):
4454 self.__lastEditorClosed()
4455 self.lastEditorClosed.emit()
4456
4457 editor.deleteLater()
4458
4459 return True
4460
4461 def closeCurrentWindow(self):
4462 """
4463 Public method to close the current window.
4464
4465 @return flag indicating success (boolean)
4466 """
4467 aw = self.activeWindow()
4468 if aw is None:
4469 return False
4470
4471 res = self.closeEditor(aw)
4472 if res and aw == self.currentEditor:
4473 self.currentEditor = None
4474
4475 return res
4476
4477 def closeAllWindows(self):
4478 """
4479 Public method to close all editor windows via file menu.
4480 """
4481 savedEditors = self.editors[:]
4482 for editor in savedEditors:
4483 self.closeEditor(editor)
4484
4485 def closeWindow(self, fn, ignoreDirty=False):
4486 """
4487 Public method to close an arbitrary source editor.
4488
4489 @param fn file name of the editor to be closed
4490 @type str
4491 @param ignoreDirty flag indicating to ignore the 'dirty' status
4492 @type bool
4493 @return flag indicating success
4494 @rtype bool
4495 """
4496 for editor in self.editors:
4497 if Utilities.samepath(fn, editor.getFileName()):
4498 break
4499 else:
4500 return True
4501
4502 res = self.closeEditor(editor, ignoreDirty=ignoreDirty)
4503 if res and editor == self.currentEditor:
4504 self.currentEditor = None
4505
4506 return res
4507
4508 def closeEditorWindow(self, editor):
4509 """
4510 Public method to close an arbitrary source editor.
4511
4512 @param editor editor to be closed
4513 """
4514 if editor is None:
4515 return
4516
4517 res = self.closeEditor(editor)
4518 if res and editor == self.currentEditor:
4519 self.currentEditor = None
4520
4521 def exit(self):
4522 """
4523 Public method to handle the debugged program terminating.
4524 """
4525 if self.currentEditor is not None:
4526 self.currentEditor.highlight()
4527 self.currentEditor = None
4528
4529 for editor in self.editors:
4530 editor.refreshCoverageAnnotations()
4531
4532 self.__setSbFile()
4533
4534 def openSourceFile(self, fn, lineno=-1, filetype="",
4535 selStart=0, selEnd=0, pos=0, addNext=False,
4536 indexes=None):
4537 """
4538 Public slot to display a file in an editor.
4539
4540 @param fn name of file to be opened
4541 @type str
4542 @param lineno line number to place the cursor at or list of line
4543 numbers (cursor will be placed at the next line greater than
4544 the current one)
4545 @type int or list of int
4546 @param filetype type of the source file
4547 @type str
4548 @param selStart start of an area to be selected
4549 @type int
4550 @param selEnd end of an area to be selected
4551 @type int
4552 @param pos position within the line to place the cursor at
4553 @type int
4554 @param addNext flag indicating to add the file next to the current
4555 editor
4556 @type bool
4557 @param indexes of the editor, first the split view index, second the
4558 index within the view
4559 @type tuple of two int
4560 @return reference to the opened editor
4561 @rtype Editor
4562 """
4563 try:
4564 newWin, editor = self.getEditor(fn, filetype=filetype,
4565 addNext=addNext, indexes=indexes)
4566 except (OSError, UnicodeDecodeError):
4567 return None
4568
4569 if newWin:
4570 self._modificationStatusChanged(editor.isModified(), editor)
4571 self._checkActions(editor)
4572
4573 cline, cindex = editor.getCursorPosition()
4574 cline += 1
4575 if isinstance(lineno, list):
4576 if len(lineno) > 1:
4577 for line in lineno:
4578 if line > cline:
4579 break
4580 else:
4581 line = lineno[0]
4582 elif len(lineno) == 1:
4583 line = lineno[0]
4584 else:
4585 line = -1
4586 else:
4587 line = lineno
4588
4589 if line >= 0 and line != cline:
4590 editor.ensureVisibleTop(line)
4591 editor.gotoLine(line, pos)
4592
4593 if selStart != selEnd:
4594 editor.setSelection(line - 1, selStart, line - 1, selEnd)
4595
4596 # insert filename into list of recently opened files
4597 self.addToRecentList(fn)
4598
4599 return editor
4600
4601 def __connectEditor(self, editor):
4602 """
4603 Private method to establish all editor connections.
4604
4605 @param editor reference to the editor object to be connected
4606 """
4607 editor.modificationStatusChanged.connect(
4608 self._modificationStatusChanged)
4609 editor.cursorChanged.connect(
4610 lambda f, l, p: self.__cursorChanged(f, l, p, editor))
4611 editor.editorSaved.connect(
4612 lambda fn: self.__editorSaved(fn, editor))
4613 editor.editorRenamed.connect(
4614 lambda fn: self.__editorRenamed(fn, editor))
4615 editor.breakpointToggled.connect(self.__breakpointToggled)
4616 editor.bookmarkToggled.connect(self.__bookmarkToggled)
4617 editor.syntaxerrorToggled.connect(self._syntaxErrorToggled)
4618 editor.coverageMarkersShown.connect(self.__coverageMarkersShown)
4619 editor.autoCompletionAPIsAvailable.connect(
4620 lambda a: self.__editorAutoCompletionAPIsAvailable(a, editor))
4621 editor.undoAvailable.connect(self.undoAct.setEnabled)
4622 editor.redoAvailable.connect(self.redoAct.setEnabled)
4623 editor.taskMarkersUpdated.connect(self.__taskMarkersUpdated)
4624 editor.changeMarkersUpdated.connect(self.__changeMarkersUpdated)
4625 editor.languageChanged.connect(
4626 lambda: self.__editorConfigChanged(editor))
4627 editor.eolChanged.connect(
4628 lambda: self.__editorConfigChanged(editor))
4629 editor.encodingChanged.connect(
4630 lambda: self.__editorConfigChanged(editor))
4631 editor.selectionChanged.connect(
4632 lambda: self.__searchWidget.selectionChanged(editor))
4633 editor.selectionChanged.connect(
4634 lambda: self.__replaceWidget.selectionChanged(editor))
4635 editor.selectionChanged.connect(
4636 lambda: self.__editorSelectionChanged(editor))
4637 editor.lastEditPositionAvailable.connect(
4638 self.__lastEditPositionAvailable)
4639 editor.zoomValueChanged.connect(
4640 lambda v: self.zoomValueChanged(v, editor))
4641 editor.mouseDoubleClick.connect(
4642 lambda pos, buttons: self.__editorDoubleClicked(editor, pos,
4643 buttons))
4644
4645 editor.languageChanged.connect(
4646 lambda: self.editorLanguageChanged.emit(editor))
4647 editor.textChanged.connect(lambda: self.editorTextChanged.emit(editor))
4648
4649 def newEditorView(self, fn, caller, filetype="", indexes=None):
4650 """
4651 Public method to create a new editor displaying the given document.
4652
4653 @param fn filename of this view
4654 @type str
4655 @param caller reference to the editor calling this method
4656 @type Editor
4657 @param filetype type of the source file
4658 @type str
4659 @param indexes of the editor, first the split view index, second the
4660 index within the view
4661 @type tuple of two int
4662 @return reference to the new editor object
4663 @rtype Editor
4664 """
4665 editor, assembly = self.cloneEditor(caller, filetype, fn)
4666
4667 self._addView(assembly, fn, caller.getNoName(), indexes=indexes)
4668 self._modificationStatusChanged(editor.isModified(), editor)
4669 self._checkActions(editor)
4670
4671 return editor
4672
4673 def cloneEditor(self, caller, filetype, fn):
4674 """
4675 Public method to clone an editor displaying the given document.
4676
4677 @param caller reference to the editor calling this method
4678 @param filetype type of the source file (string)
4679 @param fn filename of this view
4680 @return reference to the new editor object (Editor.Editor) and the new
4681 editor assembly object (EditorAssembly.EditorAssembly)
4682 """
4683 from QScintilla.EditorAssembly import EditorAssembly
4684 assembly = EditorAssembly(self.dbs, fn, self, filetype=filetype,
4685 editor=caller,
4686 tv=e5App().getObject("TaskViewer"))
4687 editor = assembly.getEditor()
4688 self.editors.append(editor)
4689 self.__connectEditor(editor)
4690 self.__editorOpened()
4691 self.editorOpened.emit(fn)
4692 self.editorOpenedEd.emit(editor)
4693
4694 return editor, assembly
4695
4696 def addToRecentList(self, fn):
4697 """
4698 Public slot to add a filename to the list of recently opened files.
4699
4700 @param fn name of the file to be added
4701 """
4702 for recent in self.recent[:]:
4703 if Utilities.samepath(fn, recent):
4704 self.recent.remove(recent)
4705 self.recent.insert(0, fn)
4706 maxRecent = Preferences.getUI("RecentNumber")
4707 if len(self.recent) > maxRecent:
4708 self.recent = self.recent[:maxRecent]
4709 self.__saveRecent()
4710
4711 def showDebugSource(self, fn, line):
4712 """
4713 Public method to open the given file and highlight the given line in
4714 it.
4715
4716 @param fn filename of editor to update (string)
4717 @param line line number to highlight (int)
4718 """
4719 if not fn.startswith('<'):
4720 self.openSourceFile(fn, line)
4721 self.setFileLine(fn, line)
4722
4723 def setFileLine(self, fn, line, error=False, syntaxError=False):
4724 """
4725 Public method to update the user interface when the current program
4726 or line changes.
4727
4728 @param fn filename of editor to update (string)
4729 @param line line number to highlight (int)
4730 @param error flag indicating an error highlight (boolean)
4731 @param syntaxError flag indicating a syntax error
4732 """
4733 try:
4734 newWin, self.currentEditor = self.getEditor(fn)
4735 except (OSError, UnicodeDecodeError):
4736 return
4737
4738 enc = self.currentEditor.getEncoding()
4739 lang = self.currentEditor.getLanguage()
4740 eol = self.currentEditor.getEolIndicator()
4741 zoom = self.currentEditor.getZoom()
4742 self.__setSbFile(fn, line, encoding=enc, language=lang, eol=eol,
4743 zoom=zoom)
4744
4745 # Change the highlighted line.
4746 self.currentEditor.highlight(line, error, syntaxError)
4747
4748 self.currentEditor.highlightVisible()
4749 self._checkActions(self.currentEditor, False)
4750
4751 def __setSbFile(self, fn=None, line=None, pos=None,
4752 encoding=None, language=None, eol=None,
4753 zoom=None):
4754 """
4755 Private method to set the file info in the status bar.
4756
4757 @param fn filename to display (string)
4758 @param line line number to display (int)
4759 @param pos character position to display (int)
4760 @param encoding encoding name to display (string)
4761 @param language language to display (string)
4762 @param eol eol indicator to display (string)
4763 @param zoom zoom value (integer)
4764 """
4765 if not fn:
4766 fn = ''
4767 writ = ' '
4768 else:
4769 if QFileInfo(fn).isWritable():
4770 writ = 'rw'
4771 else:
4772 writ = 'ro'
4773 self.sbWritable.setText(writ)
4774
4775 if line is None:
4776 line = ''
4777 self.sbLine.setText(
4778 QCoreApplication.translate('ViewManager', 'Line: {0:5}')
4779 .format(line))
4780
4781 if pos is None:
4782 pos = ''
4783 self.sbPos.setText(
4784 QCoreApplication.translate('ViewManager', 'Pos: {0:5}')
4785 .format(pos))
4786
4787 if encoding is None:
4788 encoding = ''
4789 self.sbEnc.setText(encoding)
4790
4791 if language is None:
4792 pixmap = QPixmap()
4793 elif language == "":
4794 pixmap = UI.PixmapCache.getPixmap("fileText")
4795 else:
4796 import QScintilla.Lexers
4797 pixmap = QScintilla.Lexers.getLanguageIcon(language, True)
4798 self.sbLang.setPixmap(pixmap)
4799 if pixmap.isNull():
4800 self.sbLang.setText(language)
4801 self.sbLang.setToolTip("")
4802 else:
4803 self.sbLang.setText("")
4804 self.sbLang.setToolTip(
4805 QCoreApplication.translate('ViewManager', 'Language: {0}')
4806 .format(language))
4807
4808 if eol is None:
4809 eol = ''
4810 self.sbEol.setPixmap(self.__eolPixmap(eol))
4811 self.sbEol.setToolTip(
4812 QCoreApplication.translate('ViewManager', 'EOL Mode: {0}')
4813 .format(eol))
4814
4815 if zoom is None:
4816 if QApplication.focusWidget() == e5App().getObject("Shell"):
4817 aw = e5App().getObject("Shell")
4818 else:
4819 aw = self.activeWindow()
4820 if aw:
4821 self.sbZoom.setValue(aw.getZoom())
4822 else:
4823 self.sbZoom.setValue(zoom)
4824
4825 def __eolPixmap(self, eolIndicator):
4826 """
4827 Private method to get an EOL pixmap for an EOL string.
4828
4829 @param eolIndicator eol indicator string (string)
4830 @return pixmap for the eol indicator (QPixmap)
4831 """
4832 if eolIndicator == "LF":
4833 pixmap = UI.PixmapCache.getPixmap("eolLinux")
4834 elif eolIndicator == "CR":
4835 pixmap = UI.PixmapCache.getPixmap("eolMac")
4836 elif eolIndicator == "CRLF":
4837 pixmap = UI.PixmapCache.getPixmap("eolWindows")
4838 else:
4839 pixmap = QPixmap()
4840 return pixmap
4841
4842 def __unhighlight(self):
4843 """
4844 Private slot to switch of all highlights.
4845 """
4846 self.unhighlight()
4847
4848 def unhighlight(self, current=False):
4849 """
4850 Public method to switch off all highlights or the highlight of
4851 the current editor.
4852
4853 @param current flag indicating only the current editor should be
4854 unhighlighted (boolean)
4855 """
4856 if current:
4857 if self.currentEditor is not None:
4858 self.currentEditor.highlight()
4859 else:
4860 for editor in self.editors:
4861 editor.highlight()
4862
4863 def getOpenFilenames(self):
4864 """
4865 Public method returning a list of the filenames of all editors.
4866
4867 @return list of all opened filenames (list of strings)
4868 """
4869 filenames = []
4870 for editor in self.editors:
4871 fn = editor.getFileName()
4872 if fn is not None and fn not in filenames and os.path.exists(fn):
4873 # only return names of existing files
4874 filenames.append(fn)
4875
4876 return filenames
4877
4878 def getEditor(self, fn, filetype="", addNext=False, indexes=None):
4879 """
4880 Public method to return the editor displaying the given file.
4881
4882 If there is no editor with the given file, a new editor window is
4883 created.
4884
4885 @param fn filename to look for
4886 @type str
4887 @param filetype type of the source file
4888 @type str
4889 @param addNext flag indicating that if a new editor needs to be
4890 created, it should be added next to the current editor
4891 @type bool
4892 @param indexes of the editor, first the split view index, second the
4893 index within the view
4894 @type tuple of two int
4895 @return tuple of two values giving a flag indicating a new window
4896 creation and a reference to the editor displaying this file
4897 @rtype tuple of (bool, Editor)
4898 """
4899 newWin = False
4900 editor = self.activeWindow()
4901 if editor is None or not Utilities.samepath(fn, editor.getFileName()):
4902 for editor in self.editors:
4903 if Utilities.samepath(fn, editor.getFileName()):
4904 break
4905 else:
4906 from QScintilla.EditorAssembly import EditorAssembly
4907 assembly = EditorAssembly(self.dbs, fn, self,
4908 filetype=filetype,
4909 tv=e5App().getObject("TaskViewer"))
4910 editor = assembly.getEditor()
4911 self.editors.append(editor)
4912 self.__connectEditor(editor)
4913 self.__editorOpened()
4914 self.editorOpened.emit(fn)
4915 self.editorOpenedEd.emit(editor)
4916 newWin = True
4917
4918 if newWin:
4919 self._addView(assembly, fn, addNext=addNext, indexes=indexes)
4920 else:
4921 self._showView(editor.parent(), fn)
4922
4923 return (newWin, editor)
4924
4925 def getOpenEditors(self):
4926 """
4927 Public method to get references to all open editors.
4928
4929 @return list of references to all open editors (list of
4930 QScintilla.editor)
4931 """
4932 return self.editors
4933
4934 def getOpenEditorsCount(self):
4935 """
4936 Public method to get the number of open editors.
4937
4938 @return number of open editors (integer)
4939 """
4940 return len(self.editors)
4941
4942 def getOpenEditor(self, fn):
4943 """
4944 Public method to return the editor displaying the given file.
4945
4946 @param fn filename to look for
4947 @return a reference to the editor displaying this file or None, if
4948 no editor was found
4949 """
4950 for editor in self.editors:
4951 if Utilities.samepath(fn, editor.getFileName()):
4952 return editor
4953
4954 return None
4955
4956 def getOpenEditorCount(self, fn):
4957 """
4958 Public method to return the count of editors displaying the given file.
4959
4960 @param fn filename to look for
4961 @return count of editors displaying this file (integer)
4962 """
4963 count = 0
4964 for editor in self.editors:
4965 if Utilities.samepath(fn, editor.getFileName()):
4966 count += 1
4967 return count
4968
4969 def getOpenEditorsForSession(self):
4970 """
4971 Public method to get a lists of all open editors.
4972
4973 The returned list contains one list per split view. If the view manager
4974 cannot split the view, only one list of editors is returned.
4975
4976 Note: This method should be implemented by subclasses.
4977
4978 @return list of list of editor references
4979 @rtype list of list of Editor
4980 """
4981 return [self.editors]
4982
4983 def getActiveName(self):
4984 """
4985 Public method to retrieve the filename of the active window.
4986
4987 @return filename of active window (string)
4988 """
4989 aw = self.activeWindow()
4990 if aw:
4991 return aw.getFileName()
4992 else:
4993 return None
4994
4995 def saveEditor(self, fn):
4996 """
4997 Public method to save a named editor file.
4998
4999 @param fn filename of editor to be saved (string)
5000 @return flag indicating success (boolean)
5001 """
5002 for editor in self.editors:
5003 if Utilities.samepath(fn, editor.getFileName()):
5004 break
5005 else:
5006 return True
5007
5008 if not editor.isModified():
5009 return True
5010 else:
5011 ok = editor.saveFile()
5012 return ok
5013
5014 def saveEditorEd(self, ed):
5015 """
5016 Public slot to save the contents of an editor.
5017
5018 @param ed editor to be saved
5019 @return flag indicating success (boolean)
5020 """
5021 if ed:
5022 if not ed.isModified():
5023 return True
5024 else:
5025 ok = ed.saveFile()
5026 if ok:
5027 self.setEditorName(ed, ed.getFileName())
5028 return ok
5029 else:
5030 return False
5031
5032 def saveCurrentEditor(self):
5033 """
5034 Public slot to save the contents of the current editor.
5035 """
5036 aw = self.activeWindow()
5037 self.saveEditorEd(aw)
5038
5039 def saveAsEditorEd(self, ed):
5040 """
5041 Public slot to save the contents of an editor to a new file.
5042
5043 @param ed editor to be saved
5044 """
5045 if ed:
5046 ok = ed.saveFileAs()
5047 if ok:
5048 self.setEditorName(ed, ed.getFileName())
5049
5050 def saveAsCurrentEditor(self):
5051 """
5052 Public slot to save the contents of the current editor to a new file.
5053 """
5054 aw = self.activeWindow()
5055 self.saveAsEditorEd(aw)
5056
5057 def saveCopyEditorEd(self, ed):
5058 """
5059 Public slot to save the contents of an editor to a new copy of
5060 the file.
5061
5062 @param ed editor to be saved
5063 """
5064 if ed:
5065 ed.saveFileCopy()
5066
5067 def saveCopyCurrentEditor(self):
5068 """
5069 Public slot to save the contents of the current editor to a new copy
5070 of the file.
5071 """
5072 aw = self.activeWindow()
5073 self.saveCopyEditorEd(aw)
5074
5075 def saveEditorsList(self, editors):
5076 """
5077 Public slot to save a list of editors.
5078
5079 @param editors list of editors to be saved
5080 """
5081 for editor in editors:
5082 ok = editor.saveFile()
5083 if ok:
5084 self.setEditorName(editor, editor.getFileName())
5085
5086 def saveAllEditors(self):
5087 """
5088 Public slot to save the contents of all editors.
5089 """
5090 for editor in self.editors:
5091 ok = editor.saveFile()
5092 if ok:
5093 self.setEditorName(editor, editor.getFileName())
5094
5095 # restart autosave timer
5096 if self.autosaveInterval > 0:
5097 self.autosaveTimer.start(self.autosaveInterval * 60000)
5098
5099 def __exportMenuTriggered(self, act):
5100 """
5101 Private method to handle the selection of an export format.
5102
5103 @param act reference to the action that was triggered (QAction)
5104 """
5105 aw = self.activeWindow()
5106 if aw:
5107 exporterFormat = act.data()
5108 aw.exportFile(exporterFormat)
5109
5110 def newEditor(self):
5111 """
5112 Public slot to generate a new empty editor.
5113 """
5114 from QScintilla.EditorAssembly import EditorAssembly
5115 assembly = EditorAssembly(self.dbs, "", self,
5116 tv=e5App().getObject("TaskViewer"))
5117 editor = assembly.getEditor()
5118 self.editors.append(editor)
5119 self.__connectEditor(editor)
5120 self._addView(assembly, None)
5121 self.__editorOpened()
5122 self._checkActions(editor)
5123 self.editorOpened.emit("")
5124 self.editorOpenedEd.emit(editor)
5125
5126 def printEditor(self, editor):
5127 """
5128 Public slot to print an editor.
5129
5130 @param editor editor to be printed
5131 """
5132 if editor:
5133 editor.printFile()
5134 else:
5135 return
5136
5137 def printCurrentEditor(self):
5138 """
5139 Public slot to print the contents of the current editor.
5140 """
5141 aw = self.activeWindow()
5142 self.printEditor(aw)
5143
5144 def printPreviewCurrentEditor(self):
5145 """
5146 Public slot to show a print preview of the current editor.
5147 """
5148 aw = self.activeWindow()
5149 if aw:
5150 aw.printPreviewFile()
5151
5152 def __showFileMenu(self):
5153 """
5154 Private method to set up the file menu.
5155 """
5156 self.menuRecentAct.setEnabled(len(self.recent) > 0)
5157
5158 def __showRecentMenu(self):
5159 """
5160 Private method to set up recent files menu.
5161 """
5162 self.__loadRecent()
5163
5164 self.recentMenu.clear()
5165
5166 for idx, rs in enumerate(self.recent, start=1):
5167 formatStr = '&{0:d}. {1}' if idx < 10 else '{0:d}. {1}'
5168 act = self.recentMenu.addAction(
5169 formatStr.format(
5170 idx,
5171 Utilities.compactPath(rs, self.ui.maxMenuFilePathLen)))
5172 act.setData(rs)
5173 act.setEnabled(QFileInfo(rs).exists())
5174
5175 self.recentMenu.addSeparator()
5176 self.recentMenu.addAction(
5177 QCoreApplication.translate('ViewManager', '&Clear'),
5178 self.clearRecent)
5179
5180 def __openSourceFile(self, act):
5181 """
5182 Private method to open a file from the list of recently opened files.
5183
5184 @param act reference to the action that triggered (QAction)
5185 """
5186 file = act.data()
5187 if file:
5188 self.openSourceFile(file)
5189
5190 def clearRecent(self):
5191 """
5192 Public method to clear the recent files menu.
5193 """
5194 self.recent = []
5195 self.__saveRecent()
5196
5197 def __showBookmarkedMenu(self):
5198 """
5199 Private method to set up bookmarked files menu.
5200 """
5201 self.bookmarkedMenu.clear()
5202
5203 for rp in self.bookmarked:
5204 act = self.bookmarkedMenu.addAction(
5205 Utilities.compactPath(rp, self.ui.maxMenuFilePathLen))
5206 act.setData(rp)
5207 act.setEnabled(QFileInfo(rp).exists())
5208
5209 if len(self.bookmarked):
5210 self.bookmarkedMenu.addSeparator()
5211 self.bookmarkedMenu.addAction(
5212 QCoreApplication.translate('ViewManager', '&Add'),
5213 self.__addBookmarked)
5214 self.bookmarkedMenu.addAction(
5215 QCoreApplication.translate('ViewManager', '&Edit...'),
5216 self.__editBookmarked)
5217 self.bookmarkedMenu.addAction(
5218 QCoreApplication.translate('ViewManager', '&Clear'),
5219 self.__clearBookmarked)
5220
5221 def __addBookmarked(self):
5222 """
5223 Private method to add the current file to the list of bookmarked files.
5224 """
5225 an = self.getActiveName()
5226 if an is not None and an not in self.bookmarked:
5227 self.bookmarked.append(an)
5228
5229 def __editBookmarked(self):
5230 """
5231 Private method to edit the list of bookmarked files.
5232 """
5233 from .BookmarkedFilesDialog import BookmarkedFilesDialog
5234 dlg = BookmarkedFilesDialog(self.bookmarked, self.ui)
5235 if dlg.exec() == QDialog.DialogCode.Accepted:
5236 self.bookmarked = dlg.getBookmarkedFiles()
5237
5238 def __clearBookmarked(self):
5239 """
5240 Private method to clear the bookmarked files menu.
5241 """
5242 self.bookmarked = []
5243
5244 def projectOpened(self):
5245 """
5246 Public slot to handle the projectOpened signal.
5247 """
5248 for editor in self.editors:
5249 editor.projectOpened()
5250
5251 self.__editProjectPwlAct.setEnabled(True)
5252 self.__editProjectPelAct.setEnabled(True)
5253
5254 def projectClosed(self):
5255 """
5256 Public slot to handle the projectClosed signal.
5257 """
5258 for editor in self.editors:
5259 editor.projectClosed()
5260
5261 self.__editProjectPwlAct.setEnabled(False)
5262 self.__editProjectPelAct.setEnabled(False)
5263
5264 def projectFileRenamed(self, oldfn, newfn):
5265 """
5266 Public slot to handle the projectFileRenamed signal.
5267
5268 @param oldfn old filename of the file (string)
5269 @param newfn new filename of the file (string)
5270 """
5271 editor = self.getOpenEditor(oldfn)
5272 if editor:
5273 editor.fileRenamed(newfn)
5274
5275 def projectLexerAssociationsChanged(self):
5276 """
5277 Public slot to handle changes of the project lexer associations.
5278 """
5279 for editor in self.editors:
5280 editor.projectLexerAssociationsChanged()
5281
5282 def enableEditorsCheckFocusIn(self, enabled):
5283 """
5284 Public method to set a flag enabling the editors to perform focus in
5285 checks.
5286
5287 @param enabled flag indicating focus in checks should be performed
5288 (boolean)
5289 """
5290 self.editorsCheckFocusIn = enabled
5291
5292 def editorsCheckFocusInEnabled(self):
5293 """
5294 Public method returning the flag indicating editors should perform
5295 focus in checks.
5296
5297 @return flag indicating focus in checks should be performed (boolean)
5298 """
5299 return self.editorsCheckFocusIn
5300
5301 def __findFileName(self):
5302 """
5303 Private method to handle the search for file action.
5304 """
5305 self.ui.showFindFileByNameDialog()
5306
5307 def appFocusChanged(self, old, now):
5308 """
5309 Public method to handle the global change of focus.
5310
5311 @param old reference to the widget loosing focus
5312 @type QWidget
5313 @param now reference to the widget gaining focus
5314 @type QWidget
5315 """
5316 # Focus handling was changed with Qt 5.13.1; this copes with that
5317 if now is None:
5318 return
5319
5320 from QScintilla.Shell import Shell
5321
5322 if not isinstance(now, (Editor, Shell)):
5323 self.editActGrp.setEnabled(False)
5324 self.copyActGrp.setEnabled(False)
5325 self.viewActGrp.setEnabled(False)
5326 self.sbZoom.setEnabled(False)
5327 else:
5328 self.sbZoom.setEnabled(True)
5329 self.sbZoom.setValue(now.getZoom())
5330
5331 if not isinstance(now, (Editor, Shell)):
5332 self.searchActGrp.setEnabled(False)
5333
5334 if not isinstance(now, (Editor, Shell)):
5335 self.__lastFocusWidget = old
5336
5337 ##################################################################
5338 ## Below are the action methods for the edit menu
5339 ##################################################################
5340
5341 def __editUndo(self):
5342 """
5343 Private method to handle the undo action.
5344 """
5345 self.activeWindow().undo()
5346
5347 def __editRedo(self):
5348 """
5349 Private method to handle the redo action.
5350 """
5351 self.activeWindow().redo()
5352
5353 def __editRevert(self):
5354 """
5355 Private method to handle the revert action.
5356 """
5357 self.activeWindow().revertToUnmodified()
5358
5359 def __editCut(self):
5360 """
5361 Private method to handle the cut action.
5362 """
5363 if QApplication.focusWidget() == e5App().getObject("Shell"):
5364 e5App().getObject("Shell").cut()
5365 else:
5366 self.activeWindow().cut()
5367
5368 def __editCopy(self):
5369 """
5370 Private method to handle the copy action.
5371 """
5372 if QApplication.focusWidget() == e5App().getObject("Shell"):
5373 e5App().getObject("Shell").copy()
5374 else:
5375 self.activeWindow().copy()
5376
5377 def __editPaste(self):
5378 """
5379 Private method to handle the paste action.
5380 """
5381 if QApplication.focusWidget() == e5App().getObject("Shell"):
5382 e5App().getObject("Shell").paste()
5383 else:
5384 self.activeWindow().paste()
5385
5386 def __editDelete(self):
5387 """
5388 Private method to handle the delete action.
5389 """
5390 if QApplication.focusWidget() == e5App().getObject("Shell"):
5391 e5App().getObject("Shell").clear()
5392 else:
5393 self.activeWindow().clear()
5394
5395 def __editJoin(self):
5396 """
5397 Private method to handle the join action.
5398 """
5399 self.activeWindow().joinLines()
5400
5401 def __editIndent(self):
5402 """
5403 Private method to handle the indent action.
5404 """
5405 self.activeWindow().indentLineOrSelection()
5406
5407 def __editUnindent(self):
5408 """
5409 Private method to handle the unindent action.
5410 """
5411 self.activeWindow().unindentLineOrSelection()
5412
5413 def __editSmartIndent(self):
5414 """
5415 Private method to handle the smart indent action.
5416 """
5417 self.activeWindow().smartIndentLineOrSelection()
5418
5419 def __editToggleComment(self):
5420 """
5421 Private method to handle the toggle comment action.
5422 """
5423 self.activeWindow().toggleCommentBlock()
5424
5425 def __editComment(self):
5426 """
5427 Private method to handle the comment action.
5428 """
5429 self.activeWindow().commentLineOrSelection()
5430
5431 def __editUncomment(self):
5432 """
5433 Private method to handle the uncomment action.
5434 """
5435 self.activeWindow().uncommentLineOrSelection()
5436
5437 def __editStreamComment(self):
5438 """
5439 Private method to handle the stream comment action.
5440 """
5441 self.activeWindow().streamCommentLineOrSelection()
5442
5443 def __editBoxComment(self):
5444 """
5445 Private method to handle the box comment action.
5446 """
5447 self.activeWindow().boxCommentLineOrSelection()
5448
5449 def __editSelectBrace(self):
5450 """
5451 Private method to handle the select to brace action.
5452 """
5453 self.activeWindow().selectToMatchingBrace()
5454
5455 def __editSelectAll(self):
5456 """
5457 Private method to handle the select all action.
5458 """
5459 self.activeWindow().selectAll(True)
5460
5461 def __editDeselectAll(self):
5462 """
5463 Private method to handle the select all action.
5464 """
5465 self.activeWindow().selectAll(False)
5466
5467 def __convertEOL(self):
5468 """
5469 Private method to handle the convert line end characters action.
5470 """
5471 aw = self.activeWindow()
5472 aw.convertEols(aw.eolMode())
5473
5474 def __shortenEmptyLines(self):
5475 """
5476 Private method to handle the shorten empty lines action.
5477 """
5478 self.activeWindow().shortenEmptyLines()
5479
5480 def __editAutoComplete(self):
5481 """
5482 Private method to handle the autocomplete action.
5483 """
5484 self.activeWindow().autoComplete()
5485
5486 def __editAutoCompleteFromDoc(self):
5487 """
5488 Private method to handle the autocomplete from document action.
5489 """
5490 self.activeWindow().autoCompleteFromDocument()
5491
5492 def __editAutoCompleteFromAPIs(self):
5493 """
5494 Private method to handle the autocomplete from APIs action.
5495 """
5496 self.activeWindow().autoCompleteFromAPIs()
5497
5498 def __editAutoCompleteFromAll(self):
5499 """
5500 Private method to handle the autocomplete from All action.
5501 """
5502 self.activeWindow().autoCompleteFromAll()
5503
5504 def __editorAutoCompletionAPIsAvailable(self, available, editor):
5505 """
5506 Private method to handle the availability of API autocompletion signal.
5507
5508 @param available flag indicating the availability of API
5509 autocompletion
5510 @type bool
5511 @param editor reference to the editor
5512 @type Editor
5513 """
5514 self.autoCompleteAct.setEnabled(
5515 editor.canProvideDynamicAutoCompletion())
5516 self.autoCompleteFromAPIsAct.setEnabled(available)
5517 self.autoCompleteFromAllAct.setEnabled(available)
5518 self.calltipsAct.setEnabled(editor.canProvideCallTipps())
5519
5520 def __editShowCallTips(self):
5521 """
5522 Private method to handle the calltips action.
5523 """
5524 self.activeWindow().callTip()
5525
5526 def __editShowCodeInfo(self):
5527 """
5528 Private method to handle the code info action.
5529 """
5530 self.showEditorInfo(self.activeWindow())
5531
5532 ##################################################################
5533 ## Below are the action and utility methods for the search menu
5534 ##################################################################
5535
5536 def textForFind(self, getCurrentWord=True):
5537 """
5538 Public method to determine the selection or the current word for the
5539 next find operation.
5540
5541 @param getCurrentWord flag indicating to return the current word, if
5542 no selected text was found (boolean)
5543 @return selection or current word (string)
5544 """
5545 aw = self.activeWindow()
5546 if aw is None:
5547 return ""
5548
5549 return aw.getSearchText(not getCurrentWord)
5550
5551 def getSRHistory(self, key):
5552 """
5553 Public method to get the search or replace history list.
5554
5555 @param key list to return (must be 'search' or 'replace')
5556 @return the requested history list (list of strings)
5557 """
5558 return self.srHistory[key]
5559
5560 def showSearchWidget(self):
5561 """
5562 Public method to show the search widget.
5563 """
5564 self.__replaceWidget.hide()
5565 self.__searchWidget.show()
5566 self.__searchWidget.show(self.textForFind())
5567
5568 def __searchNext(self):
5569 """
5570 Private slot to handle the search next action.
5571 """
5572 if self.__replaceWidget.isVisible():
5573 self.__replaceWidget.findNext()
5574 else:
5575 self.__searchWidget.findNext()
5576
5577 def __searchPrev(self):
5578 """
5579 Private slot to handle the search previous action.
5580 """
5581 if self.__replaceWidget.isVisible():
5582 self.__replaceWidget.findPrev()
5583 else:
5584 self.__searchWidget.findPrev()
5585
5586 def showReplaceWidget(self):
5587 """
5588 Public method to show the replace widget.
5589 """
5590 self.__searchWidget.hide()
5591 self.__replaceWidget.show(self.textForFind())
5592
5593 def __findNextWord(self):
5594 """
5595 Private slot to find the next occurrence of the current word of the
5596 current editor.
5597 """
5598 self.activeWindow().searchCurrentWordForward()
5599
5600 def __findPrevWord(self):
5601 """
5602 Private slot to find the previous occurrence of the current word of
5603 the current editor.
5604 """
5605 self.activeWindow().searchCurrentWordBackward()
5606
5607 def __searchClearMarkers(self):
5608 """
5609 Private method to clear the search markers of the active window.
5610 """
5611 self.activeWindow().clearSearchIndicators()
5612
5613 def __goto(self):
5614 """
5615 Private method to handle the goto action.
5616 """
5617 from QScintilla.GotoDialog import GotoDialog
5618
5619 aw = self.activeWindow()
5620 lines = aw.lines()
5621 curLine = aw.getCursorPosition()[0] + 1
5622 dlg = GotoDialog(lines, curLine, self.ui, None, True)
5623 if dlg.exec() == QDialog.DialogCode.Accepted:
5624 aw.gotoLine(dlg.getLinenumber(), expand=True)
5625
5626 def __gotoBrace(self):
5627 """
5628 Private method to handle the goto brace action.
5629 """
5630 self.activeWindow().moveToMatchingBrace()
5631
5632 def __gotoLastEditPosition(self):
5633 """
5634 Private method to move the cursor to the last edit position.
5635 """
5636 self.activeWindow().gotoLastEditPosition()
5637
5638 def __lastEditPositionAvailable(self):
5639 """
5640 Private slot to handle the lastEditPositionAvailable signal of an
5641 editor.
5642 """
5643 self.gotoLastEditAct.setEnabled(True)
5644
5645 def __gotoNextMethodClass(self):
5646 """
5647 Private slot to go to the next Python/Ruby method or class definition.
5648 """
5649 self.activeWindow().gotoMethodClass(False)
5650
5651 def __gotoPreviousMethodClass(self):
5652 """
5653 Private slot to go to the previous Python/Ruby method or class
5654 definition.
5655 """
5656 self.activeWindow().gotoMethodClass(True)
5657
5658 def __searchFiles(self):
5659 """
5660 Private method to handle the search in files action.
5661 """
5662 self.ui.showFindFilesDialog(self.textForFind())
5663
5664 def __replaceFiles(self):
5665 """
5666 Private method to handle the replace in files action.
5667 """
5668 self.ui.showReplaceFilesDialog(self.textForFind())
5669
5670 def __searchOpenFiles(self):
5671 """
5672 Private method to handle the search in open files action.
5673 """
5674 self.ui.showFindFilesDialog(self.textForFind(), openFiles=True)
5675
5676 def __replaceOpenFiles(self):
5677 """
5678 Private method to handle the replace in open files action.
5679 """
5680 self.ui.showReplaceFilesDialog(self.textForFind(), openFiles=True)
5681
5682 ##################################################################
5683 ## Below are the action methods for the view menu
5684 ##################################################################
5685
5686 def __zoomIn(self):
5687 """
5688 Private method to handle the zoom in action.
5689 """
5690 if QApplication.focusWidget() == e5App().getObject("Shell"):
5691 e5App().getObject("Shell").zoomIn()
5692 else:
5693 aw = self.activeWindow()
5694 if aw:
5695 aw.zoomIn()
5696 self.sbZoom.setValue(aw.getZoom())
5697
5698 def __zoomOut(self):
5699 """
5700 Private method to handle the zoom out action.
5701 """
5702 if QApplication.focusWidget() == e5App().getObject("Shell"):
5703 e5App().getObject("Shell").zoomOut()
5704 else:
5705 aw = self.activeWindow()
5706 if aw:
5707 aw.zoomOut()
5708 self.sbZoom.setValue(aw.getZoom())
5709
5710 def __zoomReset(self):
5711 """
5712 Private method to reset the zoom factor.
5713 """
5714 self.__zoomTo(0)
5715
5716 def __zoom(self):
5717 """
5718 Private method to handle the zoom action.
5719 """
5720 aw = (
5721 e5App().getObject("Shell")
5722 if QApplication.focusWidget() == e5App().getObject("Shell") else
5723 self.activeWindow()
5724 )
5725 if aw:
5726 from QScintilla.ZoomDialog import ZoomDialog
5727 dlg = ZoomDialog(aw.getZoom(), self.ui, None, True)
5728 if dlg.exec() == QDialog.DialogCode.Accepted:
5729 value = dlg.getZoomSize()
5730 self.__zoomTo(value)
5731
5732 def __zoomTo(self, value):
5733 """
5734 Private slot to zoom to a given value.
5735
5736 @param value zoom value to be set (integer)
5737 """
5738 aw = (
5739 e5App().getObject("Shell")
5740 if QApplication.focusWidget() == e5App().getObject("Shell") else
5741 self.activeWindow()
5742 )
5743 if aw:
5744 aw.zoomTo(value)
5745 self.sbZoom.setValue(aw.getZoom())
5746
5747 def zoomValueChanged(self, value, zoomingWidget):
5748 """
5749 Public slot to handle changes of the zoom value.
5750
5751 @param value new zoom value
5752 @type int
5753 @param zoomingWidget reference to the widget triggering the slot
5754 @type Editor or Shell
5755 """
5756 aw = (
5757 e5App().getObject("Shell")
5758 if QApplication.focusWidget() == e5App().getObject("Shell") else
5759 self.activeWindow()
5760 )
5761 if aw and aw == zoomingWidget:
5762 self.sbZoom.setValue(value)
5763
5764 def __clearAllFolds(self):
5765 """
5766 Private method to handle the clear all folds action.
5767 """
5768 aw = self.activeWindow()
5769 if aw:
5770 aw.clearFolds()
5771
5772 def __toggleAll(self):
5773 """
5774 Private method to handle the toggle all folds action.
5775 """
5776 aw = self.activeWindow()
5777 if aw:
5778 aw.foldAll()
5779
5780 def __toggleAllChildren(self):
5781 """
5782 Private method to handle the toggle all folds (including children)
5783 action.
5784 """
5785 aw = self.activeWindow()
5786 if aw:
5787 aw.foldAll(True)
5788
5789 def __toggleCurrent(self):
5790 """
5791 Private method to handle the toggle current fold action.
5792 """
5793 aw = self.activeWindow()
5794 if aw:
5795 aw.toggleCurrentFold()
5796
5797 def __newDocumentView(self):
5798 """
5799 Private method to open a new view of the current editor.
5800 """
5801 aw = self.activeWindow()
5802 if aw:
5803 self.newEditorView(aw.getFileName(), aw, aw.getFileType())
5804
5805 def __newDocumentSplitView(self):
5806 """
5807 Private method to open a new view of the current editor in a new split.
5808 """
5809 aw = self.activeWindow()
5810 if aw:
5811 self.addSplit()
5812 self.newEditorView(aw.getFileName(), aw, aw.getFileType())
5813
5814 def __splitView(self):
5815 """
5816 Private method to handle the split view action.
5817 """
5818 self.addSplit()
5819
5820 def __splitOrientation(self, checked):
5821 """
5822 Private method to handle the split orientation action.
5823
5824 @param checked flag indicating the checked state of the action
5825 (boolean). True means splitting horizontally.
5826 """
5827 if checked:
5828 self.setSplitOrientation(Qt.Orientation.Horizontal)
5829 self.splitViewAct.setIcon(
5830 UI.PixmapCache.getIcon("splitHorizontal"))
5831 self.splitRemoveAct.setIcon(
5832 UI.PixmapCache.getIcon("remsplitHorizontal"))
5833 self.newDocumentSplitViewAct.setIcon(
5834 UI.PixmapCache.getIcon("splitHorizontal"))
5835 else:
5836 self.setSplitOrientation(Qt.Orientation.Vertical)
5837 self.splitViewAct.setIcon(
5838 UI.PixmapCache.getIcon("splitVertical"))
5839 self.splitRemoveAct.setIcon(
5840 UI.PixmapCache.getIcon("remsplitVertical"))
5841 self.newDocumentSplitViewAct.setIcon(
5842 UI.PixmapCache.getIcon("splitVertical"))
5843 Preferences.setUI("SplitOrientationVertical", checked)
5844
5845 def __previewEditor(self, checked):
5846 """
5847 Private slot to handle a change of the preview selection state.
5848
5849 @param checked state of the action (boolean)
5850 """
5851 Preferences.setUI("ShowFilePreview", checked)
5852 self.previewStateChanged.emit(checked)
5853
5854 def __astViewer(self, checked):
5855 """
5856 Private slot to handle a change of the AST Viewer selection state.
5857
5858 @param checked state of the action (boolean)
5859 """
5860 self.astViewerStateChanged.emit(checked)
5861
5862 def __disViewer(self, checked):
5863 """
5864 Private slot to handle a change of the DIS Viewer selection state.
5865
5866 @param checked state of the action (boolean)
5867 """
5868 self.disViewerStateChanged.emit(checked)
5869
5870 ##################################################################
5871 ## Below are the action methods for the macro menu
5872 ##################################################################
5873
5874 def __macroStartRecording(self):
5875 """
5876 Private method to handle the start macro recording action.
5877 """
5878 self.activeWindow().macroRecordingStart()
5879
5880 def __macroStopRecording(self):
5881 """
5882 Private method to handle the stop macro recording action.
5883 """
5884 self.activeWindow().macroRecordingStop()
5885
5886 def __macroRun(self):
5887 """
5888 Private method to handle the run macro action.
5889 """
5890 self.activeWindow().macroRun()
5891
5892 def __macroDelete(self):
5893 """
5894 Private method to handle the delete macro action.
5895 """
5896 self.activeWindow().macroDelete()
5897
5898 def __macroLoad(self):
5899 """
5900 Private method to handle the load macro action.
5901 """
5902 self.activeWindow().macroLoad()
5903
5904 def __macroSave(self):
5905 """
5906 Private method to handle the save macro action.
5907 """
5908 self.activeWindow().macroSave()
5909
5910 ##################################################################
5911 ## Below are the action methods for the bookmarks menu
5912 ##################################################################
5913
5914 def __toggleBookmark(self):
5915 """
5916 Private method to handle the toggle bookmark action.
5917 """
5918 self.activeWindow().menuToggleBookmark()
5919
5920 def __nextBookmark(self):
5921 """
5922 Private method to handle the next bookmark action.
5923 """
5924 self.activeWindow().nextBookmark()
5925
5926 def __previousBookmark(self):
5927 """
5928 Private method to handle the previous bookmark action.
5929 """
5930 self.activeWindow().previousBookmark()
5931
5932 def __clearAllBookmarks(self):
5933 """
5934 Private method to handle the clear all bookmarks action.
5935 """
5936 for editor in self.editors:
5937 editor.clearBookmarks()
5938
5939 self.bookmarkNextAct.setEnabled(False)
5940 self.bookmarkPreviousAct.setEnabled(False)
5941 self.bookmarkClearAct.setEnabled(False)
5942
5943 def __showBookmarkMenu(self):
5944 """
5945 Private method to set up the bookmark menu.
5946 """
5947 bookmarksFound = 0
5948 filenames = self.getOpenFilenames()
5949 for filename in filenames:
5950 editor = self.getOpenEditor(filename)
5951 bookmarksFound = len(editor.getBookmarks()) > 0
5952 if bookmarksFound:
5953 self.menuBookmarksAct.setEnabled(True)
5954 return
5955 self.menuBookmarksAct.setEnabled(False)
5956
5957 def __showBookmarksMenu(self):
5958 """
5959 Private method to handle the show bookmarks menu signal.
5960 """
5961 self.bookmarksMenu.clear()
5962
5963 filenames = self.getOpenFilenames()
5964 for filename in sorted(filenames):
5965 editor = self.getOpenEditor(filename)
5966 for bookmark in editor.getBookmarks():
5967 bmSuffix = " : {0:d}".format(bookmark)
5968 act = self.bookmarksMenu.addAction(
5969 "{0}{1}".format(
5970 Utilities.compactPath(
5971 filename,
5972 self.ui.maxMenuFilePathLen - len(bmSuffix)),
5973 bmSuffix))
5974 act.setData([filename, bookmark])
5975
5976 def __bookmarkSelected(self, act):
5977 """
5978 Private method to handle the bookmark selected signal.
5979
5980 @param act reference to the action that triggered (QAction)
5981 """
5982 bmList = act.data()
5983 filename = bmList[0]
5984 line = bmList[1]
5985 self.openSourceFile(filename, line)
5986
5987 def __bookmarkToggled(self, editor):
5988 """
5989 Private slot to handle the bookmarkToggled signal.
5990
5991 It checks some bookmark actions and reemits the signal.
5992
5993 @param editor editor that sent the signal
5994 """
5995 if editor.hasBookmarks():
5996 self.bookmarkNextAct.setEnabled(True)
5997 self.bookmarkPreviousAct.setEnabled(True)
5998 self.bookmarkClearAct.setEnabled(True)
5999 else:
6000 self.bookmarkNextAct.setEnabled(False)
6001 self.bookmarkPreviousAct.setEnabled(False)
6002 self.bookmarkClearAct.setEnabled(False)
6003 self.bookmarkToggled.emit(editor)
6004
6005 def __gotoSyntaxError(self):
6006 """
6007 Private method to handle the goto syntax error action.
6008 """
6009 self.activeWindow().gotoSyntaxError()
6010
6011 def __clearAllSyntaxErrors(self):
6012 """
6013 Private method to handle the clear all syntax errors action.
6014 """
6015 for editor in self.editors:
6016 editor.clearSyntaxError()
6017
6018 def _syntaxErrorToggled(self, editor):
6019 """
6020 Protected slot to handle the syntaxerrorToggled signal.
6021
6022 It checks some syntax error actions and reemits the signal.
6023
6024 @param editor editor that sent the signal
6025 """
6026 if editor.hasSyntaxErrors():
6027 self.syntaxErrorGotoAct.setEnabled(True)
6028 self.syntaxErrorClearAct.setEnabled(True)
6029 else:
6030 self.syntaxErrorGotoAct.setEnabled(False)
6031 self.syntaxErrorClearAct.setEnabled(False)
6032 if editor.hasWarnings():
6033 self.warningsNextAct.setEnabled(True)
6034 self.warningsPreviousAct.setEnabled(True)
6035 self.warningsClearAct.setEnabled(True)
6036 else:
6037 self.warningsNextAct.setEnabled(False)
6038 self.warningsPreviousAct.setEnabled(False)
6039 self.warningsClearAct.setEnabled(False)
6040 self.syntaxerrorToggled.emit(editor)
6041
6042 def __nextWarning(self):
6043 """
6044 Private method to handle the next warning action.
6045 """
6046 self.activeWindow().nextWarning()
6047
6048 def __previousWarning(self):
6049 """
6050 Private method to handle the previous warning action.
6051 """
6052 self.activeWindow().previousWarning()
6053
6054 def __clearAllWarnings(self):
6055 """
6056 Private method to handle the clear all warnings action.
6057 """
6058 for editor in self.editors:
6059 editor.clearWarnings()
6060
6061 def __nextUncovered(self):
6062 """
6063 Private method to handle the next uncovered action.
6064 """
6065 self.activeWindow().nextUncovered()
6066
6067 def __previousUncovered(self):
6068 """
6069 Private method to handle the previous uncovered action.
6070 """
6071 self.activeWindow().previousUncovered()
6072
6073 def __coverageMarkersShown(self, shown):
6074 """
6075 Private slot to handle the coverageMarkersShown signal.
6076
6077 @param shown flag indicating whether the markers were shown or cleared
6078 """
6079 if shown:
6080 self.notcoveredNextAct.setEnabled(True)
6081 self.notcoveredPreviousAct.setEnabled(True)
6082 else:
6083 self.notcoveredNextAct.setEnabled(False)
6084 self.notcoveredPreviousAct.setEnabled(False)
6085
6086 def __taskMarkersUpdated(self, editor):
6087 """
6088 Private slot to handle the taskMarkersUpdated signal.
6089
6090 @param editor editor that sent the signal
6091 """
6092 if editor.hasTaskMarkers():
6093 self.taskNextAct.setEnabled(True)
6094 self.taskPreviousAct.setEnabled(True)
6095 else:
6096 self.taskNextAct.setEnabled(False)
6097 self.taskPreviousAct.setEnabled(False)
6098
6099 def __nextTask(self):
6100 """
6101 Private method to handle the next task action.
6102 """
6103 self.activeWindow().nextTask()
6104
6105 def __previousTask(self):
6106 """
6107 Private method to handle the previous task action.
6108 """
6109 self.activeWindow().previousTask()
6110
6111 def __changeMarkersUpdated(self, editor):
6112 """
6113 Private slot to handle the changeMarkersUpdated signal.
6114
6115 @param editor editor that sent the signal
6116 """
6117 if editor.hasChangeMarkers():
6118 self.changeNextAct.setEnabled(True)
6119 self.changePreviousAct.setEnabled(True)
6120 else:
6121 self.changeNextAct.setEnabled(False)
6122 self.changePreviousAct.setEnabled(False)
6123
6124 def __nextChange(self):
6125 """
6126 Private method to handle the next change action.
6127 """
6128 self.activeWindow().nextChange()
6129
6130 def __previousChange(self):
6131 """
6132 Private method to handle the previous change action.
6133 """
6134 self.activeWindow().previousChange()
6135
6136 ##################################################################
6137 ## Below are the action methods for the spell checking functions
6138 ##################################################################
6139
6140 def __showEditSpellingMenu(self):
6141 """
6142 Private method to set up the edit dictionaries menu.
6143 """
6144 proj = e5App().getObject("Project")
6145 projetOpen = proj.isOpen()
6146 pwl = e5App().getObject("Project").getProjectDictionaries()[0]
6147 self.__editProjectPwlAct.setEnabled(projetOpen and bool(pwl))
6148 pel = e5App().getObject("Project").getProjectDictionaries()[1]
6149 self.__editProjectPelAct.setEnabled(projetOpen and bool(pel))
6150
6151 from QScintilla.SpellChecker import SpellChecker
6152 pwl = SpellChecker.getUserDictionaryPath()
6153 self.__editUserPwlAct.setEnabled(bool(pwl))
6154 pel = SpellChecker.getUserDictionaryPath(True)
6155 self.__editUserPelAct.setEnabled(bool(pel))
6156
6157 def __setAutoSpellChecking(self):
6158 """
6159 Private slot to set the automatic spell checking of all editors.
6160 """
6161 enabled = self.autoSpellCheckAct.isChecked()
6162 Preferences.setEditor("AutoSpellCheckingEnabled", enabled)
6163 for editor in self.editors:
6164 editor.setAutoSpellChecking()
6165
6166 def __spellCheck(self):
6167 """
6168 Private slot to perform a spell check of the current editor.
6169 """
6170 aw = self.activeWindow()
6171 if aw:
6172 aw.checkSpelling()
6173
6174 def __editProjectPWL(self):
6175 """
6176 Private slot to edit the project word list.
6177 """
6178 pwl = e5App().getObject("Project").getProjectDictionaries()[0]
6179 self.__editSpellingDictionary(pwl)
6180
6181 def __editProjectPEL(self):
6182 """
6183 Private slot to edit the project exception list.
6184 """
6185 pel = e5App().getObject("Project").getProjectDictionaries()[1]
6186 self.__editSpellingDictionary(pel)
6187
6188 def __editUserPWL(self):
6189 """
6190 Private slot to edit the user word list.
6191 """
6192 from QScintilla.SpellChecker import SpellChecker
6193 pwl = SpellChecker.getUserDictionaryPath()
6194 self.__editSpellingDictionary(pwl)
6195
6196 def __editUserPEL(self):
6197 """
6198 Private slot to edit the user exception list.
6199 """
6200 from QScintilla.SpellChecker import SpellChecker
6201 pel = SpellChecker.getUserDictionaryPath(True)
6202 self.__editSpellingDictionary(pel)
6203
6204 def __editSpellingDictionary(self, dictionaryFile):
6205 """
6206 Private slot to edit the given spelling dictionary.
6207
6208 @param dictionaryFile file name of the dictionary to edit (string)
6209 """
6210 if os.path.exists(dictionaryFile):
6211 try:
6212 with open(dictionaryFile, "r", encoding="utf-8") as f:
6213 data = f.read()
6214 except OSError as err:
6215 E5MessageBox.critical(
6216 self.ui,
6217 QCoreApplication.translate(
6218 'ViewManager', "Edit Spelling Dictionary"),
6219 QCoreApplication.translate(
6220 'ViewManager',
6221 """<p>The spelling dictionary file <b>{0}</b> could"""
6222 """ not be read.</p><p>Reason: {1}</p>""").format(
6223 dictionaryFile, str(err)))
6224 return
6225
6226 fileInfo = (
6227 dictionaryFile if len(dictionaryFile) < 40
6228 else "...{0}".format(dictionaryFile[-40:])
6229 )
6230 from QScintilla.SpellingDictionaryEditDialog import (
6231 SpellingDictionaryEditDialog
6232 )
6233 dlg = SpellingDictionaryEditDialog(
6234 data,
6235 QCoreApplication.translate('ViewManager', "Editing {0}")
6236 .format(fileInfo),
6237 self.ui)
6238 if dlg.exec() == QDialog.DialogCode.Accepted:
6239 data = dlg.getData()
6240 try:
6241 with open(dictionaryFile, "w", encoding="utf-8") as f:
6242 f.write(data)
6243 except OSError as err:
6244 E5MessageBox.critical(
6245 self.ui,
6246 QCoreApplication.translate(
6247 'ViewManager', "Edit Spelling Dictionary"),
6248 QCoreApplication.translate(
6249 'ViewManager',
6250 """<p>The spelling dictionary file <b>{0}</b>"""
6251 """ could not be written.</p>"""
6252 """<p>Reason: {1}</p>""").format(
6253 dictionaryFile, str(err)))
6254 return
6255
6256 self.ui.showNotification(
6257 UI.PixmapCache.getPixmap("spellchecking48"),
6258 QCoreApplication.translate(
6259 'ViewManager', "Edit Spelling Dictionary"),
6260 QCoreApplication.translate(
6261 'ViewManager',
6262 "The spelling dictionary was saved successfully."))
6263
6264 ##################################################################
6265 ## Below are general utility methods
6266 ##################################################################
6267
6268 def handleResetUI(self):
6269 """
6270 Public slot to handle the resetUI signal.
6271 """
6272 editor = self.activeWindow()
6273 if editor is None:
6274 self.__setSbFile()
6275 else:
6276 line, pos = editor.getCursorPosition()
6277 enc = editor.getEncoding()
6278 lang = editor.getLanguage()
6279 eol = editor.getEolIndicator()
6280 zoom = editor.getZoom()
6281 self.__setSbFile(editor.getFileName(), line + 1, pos, enc, lang,
6282 eol, zoom)
6283
6284 def closeViewManager(self):
6285 """
6286 Public method to shutdown the viewmanager.
6287
6288 If it cannot close all editor windows, it aborts the shutdown process.
6289
6290 @return flag indicating success (boolean)
6291 """
6292 with contextlib.suppress(TypeError):
6293 e5App().focusChanged.disconnect(self.appFocusChanged)
6294
6295 self.closeAllWindows()
6296 self.currentEditor = None
6297
6298 # save the list of recently opened projects
6299 self.__saveRecent()
6300
6301 # save the list of recently opened projects
6302 Preferences.Prefs.settings.setValue(
6303 'Bookmarked/Sources', self.bookmarked)
6304
6305 res = len(self.editors) == 0
6306
6307 if not res:
6308 e5App().focusChanged.connect(self.appFocusChanged)
6309
6310 return res
6311
6312 def __lastEditorClosed(self):
6313 """
6314 Private slot to handle the lastEditorClosed signal.
6315 """
6316 self.closeActGrp.setEnabled(False)
6317 self.saveActGrp.setEnabled(False)
6318 self.exportersMenuAct.setEnabled(False)
6319 self.printAct.setEnabled(False)
6320 if self.printPreviewAct:
6321 self.printPreviewAct.setEnabled(False)
6322 self.editActGrp.setEnabled(False)
6323 self.searchActGrp.setEnabled(False)
6324 self.viewActGrp.setEnabled(False)
6325 self.viewFoldActGrp.setEnabled(False)
6326 self.unhighlightAct.setEnabled(False)
6327 self.newDocumentViewAct.setEnabled(False)
6328 self.newDocumentSplitViewAct.setEnabled(False)
6329 self.splitViewAct.setEnabled(False)
6330 self.splitOrientationAct.setEnabled(False)
6331 self.previewAct.setEnabled(True)
6332 self.astViewerAct.setEnabled(False)
6333 self.disViewerAct.setEnabled(False)
6334 self.macroActGrp.setEnabled(False)
6335 self.bookmarkActGrp.setEnabled(False)
6336 self.__enableSpellingActions()
6337 self.__setSbFile(zoom=0)
6338
6339 # remove all split views, if this is supported
6340 if self.canSplit():
6341 while self.removeSplit():
6342 pass
6343
6344 # stop the autosave timer
6345 if self.autosaveTimer.isActive():
6346 self.autosaveTimer.stop()
6347
6348 # hide search and replace widgets
6349 self.__searchWidget.hide()
6350 self.__replaceWidget.hide()
6351
6352 # hide the AST Viewer via its action
6353 self.astViewerAct.setChecked(False)
6354
6355 # hide the DIS Viewer via its action
6356 self.disViewerAct.setChecked(False)
6357
6358 def __editorOpened(self):
6359 """
6360 Private slot to handle the editorOpened signal.
6361 """
6362 self.closeActGrp.setEnabled(True)
6363 self.saveActGrp.setEnabled(True)
6364 self.exportersMenuAct.setEnabled(True)
6365 self.printAct.setEnabled(True)
6366 if self.printPreviewAct:
6367 self.printPreviewAct.setEnabled(True)
6368 self.editActGrp.setEnabled(True)
6369 self.searchActGrp.setEnabled(True)
6370 self.viewActGrp.setEnabled(True)
6371 self.viewFoldActGrp.setEnabled(True)
6372 self.unhighlightAct.setEnabled(True)
6373 self.newDocumentViewAct.setEnabled(True)
6374 if self.canSplit():
6375 self.newDocumentSplitViewAct.setEnabled(True)
6376 self.splitViewAct.setEnabled(True)
6377 self.splitOrientationAct.setEnabled(True)
6378 self.macroActGrp.setEnabled(True)
6379 self.bookmarkActGrp.setEnabled(True)
6380 self.__enableSpellingActions()
6381 self.astViewerAct.setEnabled(True)
6382 self.disViewerAct.setEnabled(True)
6383
6384 # activate the autosave timer
6385 if (
6386 not self.autosaveTimer.isActive() and
6387 self.autosaveInterval > 0
6388 ):
6389 self.autosaveTimer.start(self.autosaveInterval * 60000)
6390
6391 def __autosave(self):
6392 """
6393 Private slot to save the contents of all editors automatically.
6394
6395 Only named editors will be saved by the autosave timer.
6396 """
6397 for editor in self.editors:
6398 if editor.shouldAutosave():
6399 ok = editor.saveFile()
6400 if ok:
6401 self.setEditorName(editor, editor.getFileName())
6402
6403 # restart autosave timer
6404 if self.autosaveInterval > 0:
6405 self.autosaveTimer.start(self.autosaveInterval * 60000)
6406
6407 def _checkActions(self, editor, setSb=True):
6408 """
6409 Protected slot to check some actions for their enable/disable status
6410 and set the statusbar info.
6411
6412 @param editor editor window
6413 @param setSb flag indicating an update of the status bar is wanted
6414 (boolean)
6415 """
6416 if editor is not None:
6417 self.saveAct.setEnabled(editor.isModified())
6418 self.revertAct.setEnabled(editor.isModified())
6419
6420 self.undoAct.setEnabled(editor.isUndoAvailable())
6421 self.redoAct.setEnabled(editor.isRedoAvailable())
6422 self.gotoLastEditAct.setEnabled(
6423 editor.isLastEditPositionAvailable())
6424
6425 lex = editor.getLexer()
6426 if lex is not None:
6427 self.commentAct.setEnabled(lex.canBlockComment())
6428 self.uncommentAct.setEnabled(lex.canBlockComment())
6429 self.streamCommentAct.setEnabled(lex.canStreamComment())
6430 self.boxCommentAct.setEnabled(lex.canBoxComment())
6431 else:
6432 self.commentAct.setEnabled(False)
6433 self.uncommentAct.setEnabled(False)
6434 self.streamCommentAct.setEnabled(False)
6435 self.boxCommentAct.setEnabled(False)
6436
6437 if editor.hasBookmarks():
6438 self.bookmarkNextAct.setEnabled(True)
6439 self.bookmarkPreviousAct.setEnabled(True)
6440 self.bookmarkClearAct.setEnabled(True)
6441 else:
6442 self.bookmarkNextAct.setEnabled(False)
6443 self.bookmarkPreviousAct.setEnabled(False)
6444 self.bookmarkClearAct.setEnabled(False)
6445
6446 if editor.hasSyntaxErrors():
6447 self.syntaxErrorGotoAct.setEnabled(True)
6448 self.syntaxErrorClearAct.setEnabled(True)
6449 else:
6450 self.syntaxErrorGotoAct.setEnabled(False)
6451 self.syntaxErrorClearAct.setEnabled(False)
6452
6453 if editor.hasWarnings():
6454 self.warningsNextAct.setEnabled(True)
6455 self.warningsPreviousAct.setEnabled(True)
6456 self.warningsClearAct.setEnabled(True)
6457 else:
6458 self.warningsNextAct.setEnabled(False)
6459 self.warningsPreviousAct.setEnabled(False)
6460 self.warningsClearAct.setEnabled(False)
6461
6462 if editor.hasCoverageMarkers():
6463 self.notcoveredNextAct.setEnabled(True)
6464 self.notcoveredPreviousAct.setEnabled(True)
6465 else:
6466 self.notcoveredNextAct.setEnabled(False)
6467 self.notcoveredPreviousAct.setEnabled(False)
6468
6469 if editor.hasTaskMarkers():
6470 self.taskNextAct.setEnabled(True)
6471 self.taskPreviousAct.setEnabled(True)
6472 else:
6473 self.taskNextAct.setEnabled(False)
6474 self.taskPreviousAct.setEnabled(False)
6475
6476 if editor.hasChangeMarkers():
6477 self.changeNextAct.setEnabled(True)
6478 self.changePreviousAct.setEnabled(True)
6479 else:
6480 self.changeNextAct.setEnabled(False)
6481 self.changePreviousAct.setEnabled(False)
6482
6483 if editor.canAutoCompleteFromAPIs():
6484 self.autoCompleteFromAPIsAct.setEnabled(True)
6485 self.autoCompleteFromAllAct.setEnabled(True)
6486 else:
6487 self.autoCompleteFromAPIsAct.setEnabled(False)
6488 self.autoCompleteFromAllAct.setEnabled(False)
6489 self.autoCompleteAct.setEnabled(
6490 editor.canProvideDynamicAutoCompletion())
6491 self.calltipsAct.setEnabled(editor.canProvideCallTipps())
6492 self.codeInfoAct.setEnabled(self.__isEditorInfoSupportedEd(editor))
6493
6494 if editor.isPyFile() or editor.isRubyFile():
6495 self.gotoPreviousDefAct.setEnabled(True)
6496 self.gotoNextDefAct.setEnabled(True)
6497 else:
6498 self.gotoPreviousDefAct.setEnabled(False)
6499 self.gotoNextDefAct.setEnabled(False)
6500
6501 self.sortAct.setEnabled(editor.selectionIsRectangle())
6502 enable = editor.hasSelection()
6503 self.editUpperCaseAct.setEnabled(enable)
6504 self.editLowerCaseAct.setEnabled(enable)
6505
6506 if setSb:
6507 line, pos = editor.getCursorPosition()
6508 enc = editor.getEncoding()
6509 lang = editor.getLanguage()
6510 eol = editor.getEolIndicator()
6511 zoom = editor.getZoom()
6512 self.__setSbFile(
6513 editor.getFileName(), line + 1, pos, enc, lang, eol, zoom)
6514
6515 self.checkActions.emit(editor)
6516
6517 saveAllEnable = False
6518 for editor in self.editors:
6519 if editor.isModified():
6520 saveAllEnable = True
6521 self.saveAllAct.setEnabled(saveAllEnable)
6522
6523 def preferencesChanged(self):
6524 """
6525 Public slot to handle the preferencesChanged signal.
6526
6527 This method performs the following actions
6528 <ul>
6529 <li>reread the colours for the syntax highlighting</li>
6530 <li>reloads the already created API objetcs</li>
6531 <li>starts or stops the autosave timer</li>
6532 <li><b>Note</b>: changes in viewmanager type are activated
6533 on an application restart.</li>
6534 </ul>
6535 """
6536 # reload the APIs
6537 self.apisManager.reloadAPIs()
6538
6539 # reload editor settings
6540 for editor in self.editors:
6541 zoom = editor.getZoom()
6542 editor.readSettings()
6543 editor.zoomTo(zoom)
6544
6545 # reload the autosave timer setting
6546 self.autosaveInterval = Preferences.getEditor("AutosaveInterval")
6547 if len(self.editors):
6548 if (
6549 self.autosaveTimer.isActive() and
6550 self.autosaveInterval == 0
6551 ):
6552 self.autosaveTimer.stop()
6553 elif (
6554 not self.autosaveTimer.isActive() and
6555 self.autosaveInterval > 0
6556 ):
6557 self.autosaveTimer.start(self.autosaveInterval * 60000)
6558
6559 self.__enableSpellingActions()
6560
6561 def __editorSaved(self, fn, editor):
6562 """
6563 Private slot to handle the editorSaved signal.
6564
6565 It simply re-emits the signal.
6566
6567 @param fn filename of the saved editor
6568 @type str
6569 @param editor reference to the editor
6570 @type Editor
6571 """
6572 self.editorSaved.emit(fn)
6573 self.editorSavedEd.emit(editor)
6574
6575 def __editorRenamed(self, fn, editor):
6576 """
6577 Private slot to handle the editorRenamed signal.
6578
6579 It simply re-emits the signal.
6580
6581 @param fn filename of the renamed editor
6582 @type str
6583 @param editor reference to the editor
6584 @type Editor
6585 """
6586 self.editorRenamed.emit(fn)
6587 self.editorRenamedEd.emit(editor)
6588
6589 def __cursorChanged(self, fn, line, pos, editor):
6590 """
6591 Private slot to handle the cursorChanged signal.
6592
6593 It emits the signal cursorChanged with parameter editor.
6594
6595 @param fn filename
6596 @type str
6597 @param line line number of the cursor
6598 @type int
6599 @param pos position in line of the cursor
6600 @type int
6601 @param editor reference to the editor
6602 @type Editor
6603 """
6604 enc = editor.getEncoding()
6605 lang = editor.getLanguage()
6606 eol = editor.getEolIndicator()
6607 self.__setSbFile(fn, line, pos, enc, lang, eol)
6608 self.cursorChanged.emit(editor)
6609
6610 def __editorDoubleClicked(self, editor, pos, buttons):
6611 """
6612 Private slot handling mouse double clicks of an editor.
6613
6614 Note: This method is simply a multiplexer to re-emit the signal
6615 with the editor prepended.
6616
6617 @param editor reference to the editor, that emitted the signal
6618 @type Editor
6619 @param pos position of the double click
6620 @type QPoint
6621 @param buttons mouse buttons that were double clicked
6622 @type Qt.MouseButtons
6623 """
6624 self.editorDoubleClickedEd.emit(editor, pos, buttons)
6625
6626 def __breakpointToggled(self, editor):
6627 """
6628 Private slot to handle the breakpointToggled signal.
6629
6630 It simply reemits the signal.
6631
6632 @param editor editor that sent the signal
6633 """
6634 self.breakpointToggled.emit(editor)
6635
6636 def getActions(self, actionSetType):
6637 """
6638 Public method to get a list of all actions.
6639
6640 @param actionSetType string denoting the action set to get.
6641 It must be one of "edit", "file", "search", "view", "window",
6642 "macro", "bookmark" or "spelling".
6643 @return list of all actions (list of E5Action)
6644 """
6645 try:
6646 return self.__actions[actionSetType][:]
6647 except KeyError:
6648 return []
6649
6650 def __editorCommand(self, cmd):
6651 """
6652 Private method to send an editor command to the active window.
6653
6654 @param cmd the scintilla command to be sent
6655 """
6656 focusWidget = QApplication.focusWidget()
6657 if focusWidget == e5App().getObject("Shell"):
6658 e5App().getObject("Shell").editorCommand(cmd)
6659 else:
6660 aw = self.activeWindow()
6661 if aw:
6662 aw.editorCommand(cmd)
6663
6664 def __newLineBelow(self):
6665 """
6666 Private method to insert a new line below the current one even if
6667 cursor is not at the end of the line.
6668 """
6669 focusWidget = QApplication.focusWidget()
6670 if focusWidget == e5App().getObject("Shell"):
6671 return
6672 else:
6673 aw = self.activeWindow()
6674 if aw:
6675 aw.newLineBelow()
6676
6677 def __editorConfigChanged(self, editor):
6678 """
6679 Private slot to handle changes of an editor's configuration.
6680
6681 @param editor reference to the editor
6682 @type Editor
6683 """
6684 fn = editor.getFileName()
6685 line, pos = editor.getCursorPosition()
6686 enc = editor.getEncoding()
6687 lang = editor.getLanguage()
6688 eol = editor.getEolIndicator()
6689 zoom = editor.getZoom()
6690 self.__setSbFile(
6691 fn, line + 1, pos, encoding=enc, language=lang, eol=eol, zoom=zoom)
6692 self._checkActions(editor, False)
6693
6694 def __editorSelectionChanged(self, editor):
6695 """
6696 Private slot to handle changes of the current editors selection.
6697
6698 @param editor reference to the editor
6699 @type Editor
6700 """
6701 self.sortAct.setEnabled(editor.selectionIsRectangle())
6702 enable = editor.hasSelection()
6703 self.editUpperCaseAct.setEnabled(enable)
6704 self.editLowerCaseAct.setEnabled(enable)
6705
6706 def __editSortSelectedLines(self):
6707 """
6708 Private slot to sort the selected lines.
6709 """
6710 editor = self.activeWindow()
6711 if editor:
6712 editor.sortLines()
6713
6714 def __editInsertDocstring(self):
6715 """
6716 Private method to insert a docstring.
6717 """
6718 editor = self.activeWindow()
6719 if editor:
6720 editor.insertDocstring()
6721
6722 def showEditorInfo(self, editor):
6723 """
6724 Public method to show some information for a given editor.
6725
6726 @param editor editor to show information text for
6727 @type Editor
6728 """
6729 documentationViewer = self.ui.documentationViewer()
6730 if documentationViewer:
6731 documentationViewer.showInfo(editor)
6732
6733 def isEditorInfoSupported(self, language):
6734 """
6735 Public method to check, if a language is supported by the
6736 documentation viewer.
6737
6738 @param language editor programming language to check
6739 @type str
6740 @return flag indicating the support status
6741 @rtype bool
6742 """
6743 documentationViewer = self.ui.documentationViewer()
6744 if documentationViewer:
6745 return documentationViewer.isSupportedLanguage(language)
6746 else:
6747 return False
6748
6749 def __isEditorInfoSupportedEd(self, editor):
6750 """
6751 Private method to check, if an editor is supported by the
6752 documentation viewer.
6753
6754 @param editor reference to the editor to check for
6755 @type Editor
6756 @return flag indicating the support status
6757 @rtype bool
6758 """
6759 language = editor.getLanguage()
6760 return self.isEditorInfoSupported(language)
6761
6762 ##################################################################
6763 ## Below are protected utility methods
6764 ##################################################################
6765
6766 def _getOpenStartDir(self):
6767 """
6768 Protected method to return the starting directory for a file open
6769 dialog.
6770
6771 The appropriate starting directory is calculated
6772 using the following search order, until a match is found:<br />
6773 1: Directory of currently active editor<br />
6774 2: Directory of currently active Project<br />
6775 3: CWD
6776
6777 @return name of directory to start (string)
6778 """
6779 # if we have an active source, return its path
6780 if (
6781 self.activeWindow() is not None and
6782 self.activeWindow().getFileName()
6783 ):
6784 return os.path.dirname(self.activeWindow().getFileName())
6785
6786 # check, if there is an active project and return its path
6787 elif e5App().getObject("Project").isOpen():
6788 return e5App().getObject("Project").ppath
6789
6790 else:
6791 return (
6792 Preferences.getMultiProject("Workspace") or
6793 Utilities.getHomeDir()
6794 )
6795
6796 def _getOpenFileFilter(self):
6797 """
6798 Protected method to return the active filename filter for a file open
6799 dialog.
6800
6801 The appropriate filename filter is determined by file extension of
6802 the currently active editor.
6803
6804 @return name of the filename filter (string) or None
6805 """
6806 if (
6807 self.activeWindow() is not None and
6808 self.activeWindow().getFileName()
6809 ):
6810 ext = os.path.splitext(self.activeWindow().getFileName())[1]
6811 rx = re.compile(r".*\*\.{0}[ )].*".format(ext[1:]))
6812 import QScintilla.Lexers
6813 filters = QScintilla.Lexers.getOpenFileFiltersList()
6814 index = -1
6815 for i in range(len(filters)):
6816 if rx.fullmatch(filters[i]):
6817 index = i
6818 break
6819 if index == -1:
6820 return Preferences.getEditor("DefaultOpenFilter")
6821 else:
6822 return filters[index]
6823 else:
6824 return Preferences.getEditor("DefaultOpenFilter")
6825
6826 ##################################################################
6827 ## Below are API handling methods
6828 ##################################################################
6829
6830 def getAPIsManager(self):
6831 """
6832 Public method to get a reference to the APIs manager.
6833
6834 @return the APIs manager object (eric6.QScintilla.APIsManager)
6835 """
6836 return self.apisManager
6837
6838 #######################################################################
6839 ## Cooperation related methods
6840 #######################################################################
6841
6842 def setCooperationClient(self, client):
6843 """
6844 Public method to set a reference to the cooperation client.
6845
6846 @param client reference to the cooperation client (CooperationClient)
6847 """
6848 self.__cooperationClient = client
6849
6850 def isConnected(self):
6851 """
6852 Public method to check the connection status of the IDE.
6853
6854 @return flag indicating the connection status (boolean)
6855 """
6856 return self.__cooperationClient.hasConnections()
6857
6858 def send(self, fileName, message):
6859 """
6860 Public method to send an editor command to remote editors.
6861
6862 @param fileName file name of the editor (string)
6863 @param message command message to be sent (string)
6864 """
6865 project = e5App().getObject("Project")
6866 if project.isProjectFile(fileName):
6867 self.__cooperationClient.sendEditorCommand(
6868 project.getHash(),
6869 project.getRelativeUniversalPath(fileName),
6870 message
6871 )
6872
6873 def receive(self, projectHash, fileName, command):
6874 """
6875 Public slot to handle received editor commands.
6876
6877 @param projectHash hash of the project (string)
6878 @param fileName project relative file name of the editor (string)
6879 @param command command string (string)
6880 """
6881 project = e5App().getObject("Project")
6882 if projectHash == project.getHash():
6883 fn = project.getAbsoluteUniversalPath(fileName)
6884 editor = self.getOpenEditor(fn)
6885 if editor:
6886 editor.receive(command)
6887
6888 def shareConnected(self, connected):
6889 """
6890 Public slot to handle a change of the connected state.
6891
6892 @param connected flag indicating the connected state (boolean)
6893 """
6894 for editor in self.getOpenEditors():
6895 editor.shareConnected(connected)
6896
6897 def shareEditor(self, share):
6898 """
6899 Public slot to set the shared status of the current editor.
6900
6901 @param share flag indicating the share status (boolean)
6902 """
6903 aw = self.activeWindow()
6904 if aw is not None:
6905 fn = aw.getFileName()
6906 if fn and e5App().getObject("Project").isProjectFile(fn):
6907 aw.shareEditor(share)
6908
6909 def startSharedEdit(self):
6910 """
6911 Public slot to start a shared edit session for the current editor.
6912 """
6913 aw = self.activeWindow()
6914 if aw is not None:
6915 fn = aw.getFileName()
6916 if fn and e5App().getObject("Project").isProjectFile(fn):
6917 aw.startSharedEdit()
6918
6919 def sendSharedEdit(self):
6920 """
6921 Public slot to end a shared edit session for the current editor and
6922 send the changes.
6923 """
6924 aw = self.activeWindow()
6925 if aw is not None:
6926 fn = aw.getFileName()
6927 if fn and e5App().getObject("Project").isProjectFile(fn):
6928 aw.sendSharedEdit()
6929
6930 def cancelSharedEdit(self):
6931 """
6932 Public slot to cancel a shared edit session for the current editor.
6933 """
6934 aw = self.activeWindow()
6935 if aw is not None:
6936 fn = aw.getFileName()
6937 if fn and e5App().getObject("Project").isProjectFile(fn):
6938 aw.cancelSharedEdit()
6939
6940 #######################################################################
6941 ## Symbols viewer related methods
6942 #######################################################################
6943
6944 def insertSymbol(self, txt):
6945 """
6946 Public slot to insert a symbol text into the active window.
6947
6948 @param txt text to be inserted (string)
6949 """
6950 if self.__lastFocusWidget == e5App().getObject("Shell"):
6951 e5App().getObject("Shell").insert(txt)
6952 else:
6953 aw = self.activeWindow()
6954 if aw is not None:
6955 curline, curindex = aw.getCursorPosition()
6956 aw.insert(txt)
6957 aw.setCursorPosition(curline, curindex + len(txt))
6958
6959 #######################################################################
6960 ## Numbers viewer related methods
6961 #######################################################################
6962
6963 def insertNumber(self, txt):
6964 """
6965 Public slot to insert a number text into the active window.
6966
6967 @param txt text to be inserted (string)
6968 """
6969 if self.__lastFocusWidget == e5App().getObject("Shell"):
6970 aw = e5App().getObject("Shell")
6971 if aw.hasSelectedText():
6972 aw.removeSelectedText()
6973 aw.insert(txt)
6974 else:
6975 aw = self.activeWindow()
6976 if aw is not None:
6977 if aw.hasSelectedText():
6978 aw.removeSelectedText()
6979 curline, curindex = aw.getCursorPosition()
6980 aw.insert(txt)
6981 aw.setCursorPosition(curline, curindex + len(txt))
6982
6983 def getNumber(self):
6984 """
6985 Public method to get a number from the active window.
6986
6987 @return selected text of the active window (string)
6988 """
6989 txt = ""
6990 if self.__lastFocusWidget == e5App().getObject("Shell"):
6991 aw = e5App().getObject("Shell")
6992 if aw.hasSelectedText():
6993 txt = aw.selectedText()
6994 else:
6995 aw = self.activeWindow()
6996 if aw is not None and aw.hasSelectedText():
6997 txt = aw.selectedText()
6998 return txt

eric ide

mercurial