src/eric7/ViewManager/ViewManager.py

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

eric ide

mercurial