eric7/QScintilla/MiniEditor.py

branch
eric7
changeset 8312
800c432b34c8
parent 8298
83ddb87b3bc1
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing an editor for simple editing tasks.
8 """
9
10 import os
11 import re
12 import contextlib
13
14 import editorconfig
15
16 from PyQt5.QtCore import (
17 pyqtSignal, Qt, QSignalMapper, QPoint, QTimer, QFileInfo, QSize,
18 QCoreApplication
19 )
20 from PyQt5.QtGui import QKeySequence, QPalette, QFont, QPixmap
21 from PyQt5.QtWidgets import (
22 QWidget, QWhatsThis, QActionGroup, QDialog, QInputDialog, QApplication,
23 QMenu, QVBoxLayout, QHBoxLayout, QLabel
24 )
25 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog
26 from PyQt5.Qsci import QsciScintilla
27
28 from E5Gui.E5Action import E5Action, createActionGroup
29 from E5Gui import E5MessageBox, E5FileDialog
30 from E5Gui.E5MainWindow import E5MainWindow
31 from E5Gui.E5ClickableLabel import E5ClickableLabel
32 from E5Gui.E5ZoomWidget import E5ZoomWidget
33 from E5Gui.E5OverrideCursor import E5OverrideCursor
34
35 from .QsciScintillaCompat import QsciScintillaCompat
36
37 import UI.PixmapCache
38 import UI.Config
39
40 from Globals import isMacPlatform
41
42 import Utilities
43 import Preferences
44
45
46 class MiniScintilla(QsciScintillaCompat):
47 """
48 Class implementing a QsciScintillaCompat subclass for handling focus
49 events.
50 """
51 EncloseChars = {
52 '"': '"',
53 "'": "'",
54 "(": "()",
55 ")": "()",
56 "{": "{}", # __IGNORE_WARNING_M613__
57 "}": "{}", # __IGNORE_WARNING_M613__
58 "[": "[]",
59 "]": "[]",
60 "<": "<>",
61 ">": "<>",
62 }
63
64 def __init__(self, parent=None):
65 """
66 Constructor
67
68 @param parent parent widget
69 @type QWidget
70 """
71 super().__init__(parent)
72
73 self.mw = parent
74
75 def getFileName(self):
76 """
77 Public method to return the name of the file being displayed.
78
79 @return filename of the displayed file
80 @rtype str
81 """
82 return self.mw.getFileName()
83
84 def editorCommand(self, cmd):
85 """
86 Public method to perform a simple editor command.
87
88 @param cmd the scintilla command to be performed (integer)
89 """
90 if cmd == QsciScintilla.SCI_DELETEBACK:
91 line, index = self.getCursorPosition()
92 text = self.text(line)[index - 1:index + 1]
93 matchingPairs = ['()', '[]', '{}', '<>', "''", '""']
94 # __IGNORE_WARNING_M613__
95 if text in matchingPairs:
96 self.delete()
97
98 super().editorCommand(cmd)
99
100 def keyPressEvent(self, ev):
101 """
102 Protected method to handle the user input a key at a time.
103
104 @param ev key event
105 @type QKeyEvent
106 """
107 def encloseSelectedText(encString):
108 """
109 Local function to enclose the current selection with some
110 characters.
111
112 @param encString string to use to enclose the selection
113 (one or two characters)
114 @type str
115 """
116 startChar = encString[0]
117 endChar = encString[1] if len(encString) == 2 else startChar
118
119 sline, sindex, eline, eindex = self.getSelection()
120 replaceText = startChar + self.selectedText() + endChar
121 self.beginUndoAction()
122 self.replaceSelectedText(replaceText)
123 self.endUndoAction()
124 self.setSelection(sline, sindex + 1, eline, eindex + 1)
125
126 txt = ev.text()
127
128 # See it is text to insert.
129 if len(txt) and txt >= " ":
130 if (
131 self.hasSelectedText() and
132 txt in MiniScintilla.EncloseChars
133 ):
134 encloseSelectedText(MiniScintilla.EncloseChars[txt])
135 ev.accept()
136 return
137
138 super().keyPressEvent(ev)
139 else:
140 ev.ignore()
141
142 def focusInEvent(self, event):
143 """
144 Protected method called when the editor receives focus.
145
146 This method checks for modifications of the current file and
147 rereads it upon request. The cursor is placed at the current position
148 assuming, that it is in the vicinity of the old position after the
149 reread.
150
151 @param event the event object
152 @type QFocusEvent
153 """
154 self.mw.editorActGrp.setEnabled(True)
155 with contextlib.suppress(AttributeError):
156 self.setCaretWidth(self.mw.caretWidth)
157
158 self.setCursorFlashTime(QApplication.cursorFlashTime())
159
160 super().focusInEvent(event)
161
162 def focusOutEvent(self, event):
163 """
164 Protected method called when the editor loses focus.
165
166 @param event the event object
167 @type QFocusEvent
168 """
169 self.mw.editorActGrp.setEnabled(False)
170 self.setCaretWidth(0)
171
172 super().focusOutEvent(event)
173
174 def removeTrailingWhitespace(self):
175 """
176 Public method to remove trailing whitespace.
177 """
178 searchRE = r"[ \t]+$" # whitespace at the end of a line
179
180 ok = self.findFirstTarget(searchRE, True, False, False, 0, 0)
181 self.beginUndoAction()
182 while ok:
183 self.replaceTarget("")
184 ok = self.findNextTarget()
185 self.endUndoAction()
186
187
188 class MiniEditor(E5MainWindow):
189 """
190 Class implementing an editor for simple editing tasks.
191
192 @signal editorSaved() emitted after the file has been saved
193 @signal languageChanged(str) emitted when the editors language was set. The
194 language is passed as a parameter.
195 @signal editorRenamed(str) emitted after the editor got a new name
196 (i.e. after a 'Save As')
197 @signal cursorLineChanged(int) emitted when the cursor line was changed
198
199 @signal refreshed() dummy signal to emulate the Editor interface
200 """
201 editorSaved = pyqtSignal()
202 languageChanged = pyqtSignal(str)
203 editorRenamed = pyqtSignal(str)
204 cursorLineChanged = pyqtSignal(int)
205
206 refreshed = pyqtSignal()
207
208 def __init__(self, filename="", filetype="", parent=None, name=None):
209 """
210 Constructor
211
212 @param filename name of the file to open (string)
213 @param filetype type of the source file (string)
214 @param parent reference to the parent widget (QWidget)
215 @param name object name of the window (string)
216 """
217 super().__init__(parent)
218 if name is not None:
219 self.setObjectName(name)
220 self.setWindowIcon(UI.PixmapCache.getIcon("editor"))
221
222 self.setStyle(Preferences.getUI("Style"),
223 Preferences.getUI("StyleSheet"))
224
225 self.__textEdit = MiniScintilla(self)
226 self.__textEdit.clearSearchIndicators = self.clearSearchIndicators
227 self.__textEdit.setSearchIndicator = self.setSearchIndicator
228 self.__textEdit.setUtf8(True)
229
230 self.getCursorPosition = self.__textEdit.getCursorPosition
231 self.text = self.__textEdit.text
232 self.getZoom = self.__textEdit.getZoom
233 self.zoomTo = self.__textEdit.zoomTo
234 self.zoomIn = self.__textEdit.zoomIn
235 self.zoomOut = self.__textEdit.zoomOut
236
237 self.__curFile = filename
238 self.__lastLine = 0
239
240 self.srHistory = {
241 "search": [],
242 "replace": []
243 }
244 from .SearchReplaceWidget import SearchReplaceWidget
245 self.__searchWidget = SearchReplaceWidget(False, self, self)
246 self.__replaceWidget = SearchReplaceWidget(True, self, self)
247
248 from .EditorOutline import EditorOutlineView
249 self.__sourceOutline = EditorOutlineView(self, populate=False)
250 self.__sourceOutline.setMaximumWidth(
251 Preferences.getEditor("SourceOutlineWidth"))
252
253 hlayout = QHBoxLayout()
254 hlayout.setContentsMargins(0, 0, 0, 0)
255 hlayout.setSpacing(1)
256 hlayout.addWidget(self.__textEdit)
257 hlayout.addWidget(self.__sourceOutline)
258
259 centralWidget = QWidget()
260 layout = QVBoxLayout()
261 layout.setContentsMargins(1, 1, 1, 1)
262 layout.addLayout(hlayout)
263 layout.addWidget(self.__searchWidget)
264 layout.addWidget(self.__replaceWidget)
265 centralWidget.setLayout(layout)
266 self.setCentralWidget(centralWidget)
267 self.__searchWidget.hide()
268 self.__replaceWidget.hide()
269
270 self.lexer_ = None
271 self.apiLanguage = ""
272 self.filetype = ""
273
274 self.__loadEditorConfig(filename)
275
276 self.__createActions()
277 self.__createMenus()
278 self.__createToolBars()
279 self.__createStatusBar()
280
281 self.__setTextDisplay()
282 self.__setMargins()
283 self.__setEolMode()
284
285 self.__readSettings()
286
287 # clear QScintilla defined keyboard commands
288 # we do our own handling through the view manager
289 self.__textEdit.clearAlternateKeys()
290 self.__textEdit.clearKeys()
291
292 # initialise the mark occurrences timer
293 self.__markOccurrencesTimer = QTimer(self)
294 self.__markOccurrencesTimer.setSingleShot(True)
295 self.__markOccurrencesTimer.setInterval(
296 Preferences.getEditor("MarkOccurrencesTimeout"))
297 self.__markOccurrencesTimer.timeout.connect(self.__markOccurrences)
298 self.__markedText = ""
299
300 self.__changeTimer = QTimer(self)
301 self.__changeTimer.setSingleShot(True)
302 self.__changeTimer.setInterval(5 * 1000)
303 self.__textEdit.textChanged.connect(self.__resetChangeTimer)
304
305 self.__textEdit.textChanged.connect(self.__documentWasModified)
306 self.__textEdit.modificationChanged.connect(self.__modificationChanged)
307 self.__textEdit.cursorPositionChanged.connect(
308 self.__cursorPositionChanged)
309 self.__textEdit.linesChanged.connect(self.__resizeLinenoMargin)
310
311 self.__textEdit.setContextMenuPolicy(
312 Qt.ContextMenuPolicy.CustomContextMenu)
313 self.__textEdit.customContextMenuRequested.connect(
314 self.__contextMenuRequested)
315
316 self.__textEdit.selectionChanged.connect(
317 lambda: self.__searchWidget.selectionChanged(self.__textEdit))
318 self.__textEdit.selectionChanged.connect(
319 lambda: self.__replaceWidget.selectionChanged(self.__textEdit))
320
321 if filename:
322 self.__loadFile(filename, filetype)
323 else:
324 self.__setCurrentFile("")
325 self.encoding = self.__getEditorConfig("DefaultEncoding")
326
327 self.__checkActions()
328
329 self.__sourceOutline.setActive(True)
330 self.__sourceOutline.setVisible(
331 self.__sourceOutline.isSupportedLanguage(
332 self.getLanguage()
333 )
334 )
335 self.__changeTimer.timeout.connect(self.__sourceOutline.repopulate)
336 self.languageChanged.connect(self.__editorChanged)
337 self.editorRenamed.connect(self.__editorChanged)
338
339 def closeEvent(self, event):
340 """
341 Protected method to handle the close event.
342
343 @param event close event (QCloseEvent)
344 """
345 if self.__maybeSave():
346 self.__writeSettings()
347 event.accept()
348 else:
349 event.ignore()
350
351 def __newFile(self):
352 """
353 Private slot to create a new file.
354 """
355 if self.__maybeSave():
356 self.__textEdit.clear()
357 self.__setCurrentFile("")
358
359 self.__checkActions()
360
361 def __open(self):
362 """
363 Private slot to open a file.
364 """
365 if self.__maybeSave():
366 fileName = E5FileDialog.getOpenFileName(self)
367 if fileName:
368 self.__loadFile(fileName)
369 self.__checkActions()
370
371 def __save(self):
372 """
373 Private slot to save a file.
374
375 @return flag indicating success (boolean)
376 """
377 if not self.__curFile:
378 return self.__saveAs()
379 else:
380 return self.__saveFile(self.__curFile)
381
382 def __saveAs(self):
383 """
384 Private slot to save a file with a new name.
385
386 @return flag indicating success (boolean)
387 """
388 fileName = E5FileDialog.getSaveFileName(self)
389 if not fileName:
390 return False
391
392 result = self.__saveFile(fileName)
393
394 self.editorRenamed.emit(fileName)
395
396 return result
397
398 def __saveCopy(self):
399 """
400 Private slot to save a copy of the file with a new name.
401 """
402 fileName = E5FileDialog.getSaveFileName(self)
403 if not fileName:
404 return
405
406 self.__writeFile(fileName)
407
408 def __about(self):
409 """
410 Private slot to show a little About message.
411 """
412 E5MessageBox.about(
413 self,
414 self.tr("About eric Mini Editor"),
415 self.tr(
416 "The eric Mini Editor is an editor component"
417 " based on QScintilla. It may be used for simple"
418 " editing tasks, that don't need the power of"
419 " a full blown editor."))
420
421 def __aboutQt(self):
422 """
423 Private slot to handle the About Qt dialog.
424 """
425 E5MessageBox.aboutQt(self, "eric Mini Editor")
426
427 def __whatsThis(self):
428 """
429 Private slot called in to enter Whats This mode.
430 """
431 QWhatsThis.enterWhatsThisMode()
432
433 def __documentWasModified(self):
434 """
435 Private slot to handle a change in the documents modification status.
436 """
437 self.setWindowModified(self.__textEdit.isModified())
438
439 def __checkActions(self, setSb=True):
440 """
441 Private slot to check some actions for their enable/disable status
442 and set the statusbar info.
443
444 @param setSb flag indicating an update of the status bar is wanted
445 (boolean)
446 """
447 self.saveAct.setEnabled(self.__textEdit.isModified())
448
449 self.undoAct.setEnabled(self.__textEdit.isUndoAvailable())
450 self.redoAct.setEnabled(self.__textEdit.isRedoAvailable())
451
452 if setSb:
453 line, pos = self.getCursorPosition()
454 lang = self.getLanguage()
455 self.__setSbFile(line + 1, pos, lang)
456
457 def __setSbFile(self, line=None, pos=None, language=None, zoom=None):
458 """
459 Private method to set the file info in the status bar.
460
461 @param line line number to display
462 @type int
463 @param pos character position to display
464 @type int
465 @param language language to display
466 @type str
467 @param zoom zoom value
468 @type int
469 """
470 if not self.__curFile:
471 writ = ' '
472 else:
473 if QFileInfo(self.__curFile).isWritable():
474 writ = ' rw'
475 else:
476 writ = ' ro'
477
478 self.sbWritable.setText(writ)
479
480 if line is None:
481 line = ''
482 self.sbLine.setText(self.tr('Line: {0:5}').format(line))
483
484 if pos is None:
485 pos = ''
486 self.sbPos.setText(self.tr('Pos: {0:5}').format(pos))
487
488 if language is None:
489 pixmap = QPixmap()
490 elif language == "":
491 pixmap = UI.PixmapCache.getPixmap("fileText")
492 else:
493 import QScintilla.Lexers
494 pixmap = QScintilla.Lexers.getLanguageIcon(language, True)
495 self.sbLanguage.setPixmap(pixmap)
496 if pixmap.isNull():
497 self.sbLanguage.setText(language)
498 self.sbLanguage.setToolTip("")
499 else:
500 self.sbLanguage.setText("")
501 self.sbLanguage.setToolTip(
502 self.tr('Language: {0}').format(language))
503
504 if zoom is None:
505 self.sbZoom.setValue(self.getZoom())
506 else:
507 self.sbZoom.setValue(zoom)
508
509 def __readShortcut(self, act, category):
510 """
511 Private function to read a single keyboard shortcut from the settings.
512
513 @param act reference to the action object (E5Action)
514 @param category category the action belongs to (string)
515 """
516 if act.objectName():
517 accel = Preferences.Prefs.settings.value(
518 "Shortcuts/{0}/{1}/Accel".format(category, act.objectName()))
519 if accel is not None:
520 act.setShortcut(QKeySequence(accel))
521 accel = Preferences.Prefs.settings.value(
522 "Shortcuts/{0}/{1}/AltAccel".format(
523 category, act.objectName()))
524 if accel is not None:
525 act.setAlternateShortcut(QKeySequence(accel), removeEmpty=True)
526
527 def __createActions(self):
528 """
529 Private method to create the actions.
530 """
531 self.fileActions = []
532 self.editActions = []
533 self.helpActions = []
534 self.searchActions = []
535 self.viewActions = []
536
537 self.__createFileActions()
538 self.__createEditActions()
539 self.__createHelpActions()
540 self.__createSearchActions()
541 self.__createViewActions()
542
543 # read the keyboard shortcuts and make them identical to the main
544 # eric shortcuts
545 for act in self.helpActions:
546 self.__readShortcut(act, "General")
547 for act in self.editActions:
548 self.__readShortcut(act, "Edit")
549 for act in self.fileActions:
550 self.__readShortcut(act, "File")
551 for act in self.searchActions:
552 self.__readShortcut(act, "Search")
553 for act in self.viewActions:
554 self.__readShortcut(act, "View")
555
556 def __createFileActions(self):
557 """
558 Private method to create the File actions.
559 """
560 self.newAct = E5Action(
561 self.tr('New'),
562 UI.PixmapCache.getIcon("new"),
563 self.tr('&New'),
564 QKeySequence(self.tr("Ctrl+N", "File|New")),
565 0, self, 'vm_file_new')
566 self.newAct.setStatusTip(self.tr('Open an empty editor window'))
567 self.newAct.setWhatsThis(self.tr(
568 """<b>New</b>"""
569 """<p>An empty editor window will be created.</p>"""
570 ))
571 self.newAct.triggered.connect(self.__newFile)
572 self.fileActions.append(self.newAct)
573
574 self.openAct = E5Action(
575 self.tr('Open'),
576 UI.PixmapCache.getIcon("open"),
577 self.tr('&Open...'),
578 QKeySequence(self.tr("Ctrl+O", "File|Open")),
579 0, self, 'vm_file_open')
580 self.openAct.setStatusTip(self.tr('Open a file'))
581 self.openAct.setWhatsThis(self.tr(
582 """<b>Open a file</b>"""
583 """<p>You will be asked for the name of a file to be opened.</p>"""
584 ))
585 self.openAct.triggered.connect(self.__open)
586 self.fileActions.append(self.openAct)
587
588 self.saveAct = E5Action(
589 self.tr('Save'),
590 UI.PixmapCache.getIcon("fileSave"),
591 self.tr('&Save'),
592 QKeySequence(self.tr("Ctrl+S", "File|Save")),
593 0, self, 'vm_file_save')
594 self.saveAct.setStatusTip(self.tr('Save the current file'))
595 self.saveAct.setWhatsThis(self.tr(
596 """<b>Save File</b>"""
597 """<p>Save the contents of current editor window.</p>"""
598 ))
599 self.saveAct.triggered.connect(self.__save)
600 self.fileActions.append(self.saveAct)
601
602 self.saveAsAct = E5Action(
603 self.tr('Save as'),
604 UI.PixmapCache.getIcon("fileSaveAs"),
605 self.tr('Save &as...'),
606 QKeySequence(self.tr("Shift+Ctrl+S", "File|Save As")),
607 0, self, 'vm_file_save_as')
608 self.saveAsAct.setStatusTip(self.tr(
609 'Save the current file to a new one'))
610 self.saveAsAct.setWhatsThis(self.tr(
611 """<b>Save File as</b>"""
612 """<p>Save the contents of current editor window to a new file."""
613 """ The file can be entered in a file selection dialog.</p>"""
614 ))
615 self.saveAsAct.triggered.connect(self.__saveAs)
616 self.fileActions.append(self.saveAsAct)
617
618 self.saveCopyAct = E5Action(
619 self.tr('Save Copy'),
620 UI.PixmapCache.getIcon("fileSaveCopy"),
621 self.tr('Save &Copy...'),
622 0, 0, self, 'vm_file_save_copy')
623 self.saveCopyAct.setStatusTip(self.tr(
624 'Save a copy of the current file'))
625 self.saveCopyAct.setWhatsThis(self.tr(
626 """<b>Save Copy</b>"""
627 """<p>Save a copy of the contents of current editor window."""
628 """ The file can be entered in a file selection dialog.</p>"""
629 ))
630 self.saveCopyAct.triggered.connect(self.__saveCopy)
631 self.fileActions.append(self.saveCopyAct)
632
633 self.closeAct = E5Action(
634 self.tr('Close'),
635 UI.PixmapCache.getIcon("close"),
636 self.tr('&Close'),
637 QKeySequence(self.tr("Ctrl+W", "File|Close")),
638 0, self, 'vm_file_close')
639 self.closeAct.setStatusTip(self.tr('Close the editor window'))
640 self.closeAct.setWhatsThis(self.tr(
641 """<b>Close Window</b>"""
642 """<p>Close the current window.</p>"""
643 ))
644 self.closeAct.triggered.connect(self.close)
645 self.fileActions.append(self.closeAct)
646
647 self.printAct = E5Action(
648 self.tr('Print'),
649 UI.PixmapCache.getIcon("print"),
650 self.tr('&Print'),
651 QKeySequence(self.tr("Ctrl+P", "File|Print")),
652 0, self, 'vm_file_print')
653 self.printAct.setStatusTip(self.tr('Print the current file'))
654 self.printAct.setWhatsThis(self.tr(
655 """<b>Print File</b>"""
656 """<p>Print the contents of the current file.</p>"""
657 ))
658 self.printAct.triggered.connect(self.__printFile)
659 self.fileActions.append(self.printAct)
660
661 self.printPreviewAct = E5Action(
662 self.tr('Print Preview'),
663 UI.PixmapCache.getIcon("printPreview"),
664 QCoreApplication.translate('ViewManager', 'Print Preview'),
665 0, 0, self, 'vm_file_print_preview')
666 self.printPreviewAct.setStatusTip(self.tr(
667 'Print preview of the current file'))
668 self.printPreviewAct.setWhatsThis(self.tr(
669 """<b>Print Preview</b>"""
670 """<p>Print preview of the current file.</p>"""
671 ))
672 self.printPreviewAct.triggered.connect(self.__printPreviewFile)
673 self.fileActions.append(self.printPreviewAct)
674
675 def __createEditActions(self):
676 """
677 Private method to create the Edit actions.
678 """
679 self.undoAct = E5Action(
680 self.tr('Undo'),
681 UI.PixmapCache.getIcon("editUndo"),
682 self.tr('&Undo'),
683 QKeySequence(self.tr("Ctrl+Z", "Edit|Undo")),
684 QKeySequence(self.tr("Alt+Backspace", "Edit|Undo")),
685 self, 'vm_edit_undo')
686 self.undoAct.setStatusTip(self.tr('Undo the last change'))
687 self.undoAct.setWhatsThis(self.tr(
688 """<b>Undo</b>"""
689 """<p>Undo the last change done in the current editor.</p>"""
690 ))
691 self.undoAct.triggered.connect(self.__undo)
692 self.editActions.append(self.undoAct)
693
694 self.redoAct = E5Action(
695 self.tr('Redo'),
696 UI.PixmapCache.getIcon("editRedo"),
697 self.tr('&Redo'),
698 QKeySequence(self.tr("Ctrl+Shift+Z", "Edit|Redo")),
699 0, self, 'vm_edit_redo')
700 self.redoAct.setStatusTip(self.tr('Redo the last change'))
701 self.redoAct.setWhatsThis(self.tr(
702 """<b>Redo</b>"""
703 """<p>Redo the last change done in the current editor.</p>"""
704 ))
705 self.redoAct.triggered.connect(self.__redo)
706 self.editActions.append(self.redoAct)
707
708 self.cutAct = E5Action(
709 self.tr('Cut'),
710 UI.PixmapCache.getIcon("editCut"),
711 self.tr('Cu&t'),
712 QKeySequence(self.tr("Ctrl+X", "Edit|Cut")),
713 QKeySequence(self.tr("Shift+Del", "Edit|Cut")),
714 self, 'vm_edit_cut')
715 self.cutAct.setStatusTip(self.tr('Cut the selection'))
716 self.cutAct.setWhatsThis(self.tr(
717 """<b>Cut</b>"""
718 """<p>Cut the selected text of the current editor to the"""
719 """ clipboard.</p>"""
720 ))
721 self.cutAct.triggered.connect(self.__textEdit.cut)
722 self.editActions.append(self.cutAct)
723
724 self.copyAct = E5Action(
725 self.tr('Copy'),
726 UI.PixmapCache.getIcon("editCopy"),
727 self.tr('&Copy'),
728 QKeySequence(self.tr("Ctrl+C", "Edit|Copy")),
729 QKeySequence(self.tr("Ctrl+Ins", "Edit|Copy")),
730 self, 'vm_edit_copy')
731 self.copyAct.setStatusTip(self.tr('Copy the selection'))
732 self.copyAct.setWhatsThis(self.tr(
733 """<b>Copy</b>"""
734 """<p>Copy the selected text of the current editor to the"""
735 """ clipboard.</p>"""
736 ))
737 self.copyAct.triggered.connect(self.__textEdit.copy)
738 self.editActions.append(self.copyAct)
739
740 self.pasteAct = E5Action(
741 self.tr('Paste'),
742 UI.PixmapCache.getIcon("editPaste"),
743 self.tr('&Paste'),
744 QKeySequence(self.tr("Ctrl+V", "Edit|Paste")),
745 QKeySequence(self.tr("Shift+Ins", "Edit|Paste")),
746 self, 'vm_edit_paste')
747 self.pasteAct.setStatusTip(self.tr(
748 'Paste the last cut/copied text'))
749 self.pasteAct.setWhatsThis(self.tr(
750 """<b>Paste</b>"""
751 """<p>Paste the last cut/copied text from the clipboard to"""
752 """ the current editor.</p>"""
753 ))
754 self.pasteAct.triggered.connect(self.__textEdit.paste)
755 self.editActions.append(self.pasteAct)
756
757 self.deleteAct = E5Action(
758 self.tr('Clear'),
759 UI.PixmapCache.getIcon("editDelete"),
760 self.tr('Cl&ear'),
761 QKeySequence(self.tr("Alt+Shift+C", "Edit|Clear")),
762 0,
763 self, 'vm_edit_clear')
764 self.deleteAct.setStatusTip(self.tr('Clear all text'))
765 self.deleteAct.setWhatsThis(self.tr(
766 """<b>Clear</b>"""
767 """<p>Delete all text of the current editor.</p>"""
768 ))
769 self.deleteAct.triggered.connect(self.__textEdit.clear)
770 self.editActions.append(self.deleteAct)
771
772 self.cutAct.setEnabled(False)
773 self.copyAct.setEnabled(False)
774 self.__textEdit.copyAvailable.connect(self.cutAct.setEnabled)
775 self.__textEdit.copyAvailable.connect(self.copyAct.setEnabled)
776
777 ####################################################################
778 ## Below follow the actions for QScintilla standard commands.
779 ####################################################################
780
781 self.esm = QSignalMapper(self)
782 try:
783 self.esm.mappedInt.connect(self.__textEdit.editorCommand)
784 except AttributeError:
785 # pre Qt 5.15
786 self.esm.mapped[int].connect(self.__textEdit.editorCommand)
787
788 self.editorActGrp = createActionGroup(self)
789
790 act = E5Action(
791 QCoreApplication.translate('ViewManager',
792 'Move left one character'),
793 QCoreApplication.translate('ViewManager',
794 'Move left one character'),
795 QKeySequence(QCoreApplication.translate('ViewManager', 'Left')), 0,
796 self.editorActGrp, 'vm_edit_move_left_char')
797 self.esm.setMapping(act, QsciScintilla.SCI_CHARLEFT)
798 if isMacPlatform():
799 act.setAlternateShortcut(QKeySequence(
800 QCoreApplication.translate('ViewManager', 'Meta+B')))
801 act.triggered.connect(self.esm.map)
802 self.editActions.append(act)
803
804 act = E5Action(
805 QCoreApplication.translate('ViewManager',
806 'Move right one character'),
807 QCoreApplication.translate('ViewManager',
808 'Move right one character'),
809 QKeySequence(QCoreApplication.translate('ViewManager', 'Right')),
810 0, self.editorActGrp, 'vm_edit_move_right_char')
811 if isMacPlatform():
812 act.setAlternateShortcut(QKeySequence(
813 QCoreApplication.translate('ViewManager', 'Meta+F')))
814 self.esm.setMapping(act, QsciScintilla.SCI_CHARRIGHT)
815 act.triggered.connect(self.esm.map)
816 self.editActions.append(act)
817
818 act = E5Action(
819 QCoreApplication.translate('ViewManager', 'Move up one line'),
820 QCoreApplication.translate('ViewManager', 'Move up one line'),
821 QKeySequence(QCoreApplication.translate('ViewManager', 'Up')), 0,
822 self.editorActGrp, 'vm_edit_move_up_line')
823 if isMacPlatform():
824 act.setAlternateShortcut(QKeySequence(
825 QCoreApplication.translate('ViewManager', 'Meta+P')))
826 self.esm.setMapping(act, QsciScintilla.SCI_LINEUP)
827 act.triggered.connect(self.esm.map)
828 self.editActions.append(act)
829
830 act = E5Action(
831 QCoreApplication.translate('ViewManager', 'Move down one line'),
832 QCoreApplication.translate('ViewManager', 'Move down one line'),
833 QKeySequence(QCoreApplication.translate('ViewManager', 'Down')), 0,
834 self.editorActGrp, 'vm_edit_move_down_line')
835 if isMacPlatform():
836 act.setAlternateShortcut(QKeySequence(
837 QCoreApplication.translate('ViewManager', 'Meta+N')))
838 self.esm.setMapping(act, QsciScintilla.SCI_LINEDOWN)
839 act.triggered.connect(self.esm.map)
840 self.editActions.append(act)
841
842 act = E5Action(
843 QCoreApplication.translate('ViewManager',
844 'Move left one word part'),
845 QCoreApplication.translate('ViewManager',
846 'Move left one word part'),
847 0, 0,
848 self.editorActGrp, 'vm_edit_move_left_word_part')
849 if not isMacPlatform():
850 act.setShortcut(QKeySequence(
851 QCoreApplication.translate('ViewManager', 'Alt+Left')))
852 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTLEFT)
853 act.triggered.connect(self.esm.map)
854 self.editActions.append(act)
855
856 act = E5Action(
857 QCoreApplication.translate('ViewManager',
858 'Move right one word part'),
859 QCoreApplication.translate('ViewManager',
860 'Move right one word part'),
861 0, 0,
862 self.editorActGrp, 'vm_edit_move_right_word_part')
863 if not isMacPlatform():
864 act.setShortcut(QKeySequence(
865 QCoreApplication.translate('ViewManager', 'Alt+Right')))
866 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTRIGHT)
867 act.triggered.connect(self.esm.map)
868 self.editActions.append(act)
869
870 act = E5Action(
871 QCoreApplication.translate('ViewManager', 'Move left one word'),
872 QCoreApplication.translate('ViewManager', 'Move left one word'),
873 0, 0,
874 self.editorActGrp, 'vm_edit_move_left_word')
875 if isMacPlatform():
876 act.setShortcut(QKeySequence(
877 QCoreApplication.translate('ViewManager', 'Alt+Left')))
878 else:
879 act.setShortcut(QKeySequence(
880 QCoreApplication.translate('ViewManager', 'Ctrl+Left')))
881 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFT)
882 act.triggered.connect(self.esm.map)
883 self.editActions.append(act)
884
885 act = E5Action(
886 QCoreApplication.translate('ViewManager', 'Move right one word'),
887 QCoreApplication.translate('ViewManager', 'Move right one word'),
888 0, 0,
889 self.editorActGrp, 'vm_edit_move_right_word')
890 if isMacPlatform():
891 act.setShortcut(QKeySequence(
892 QCoreApplication.translate('ViewManager', 'Alt+Right')))
893 else:
894 act.setShortcut(QKeySequence(
895 QCoreApplication.translate('ViewManager', 'Ctrl+Right')))
896 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHT)
897 act.triggered.connect(self.esm.map)
898 self.editActions.append(act)
899
900 act = E5Action(
901 QCoreApplication.translate(
902 'ViewManager',
903 'Move to first visible character in document line'),
904 QCoreApplication.translate(
905 'ViewManager',
906 'Move to first visible character in document line'),
907 0, 0,
908 self.editorActGrp, 'vm_edit_move_first_visible_char')
909 if not isMacPlatform():
910 act.setShortcut(QKeySequence(
911 QCoreApplication.translate('ViewManager', 'Home')))
912 self.esm.setMapping(act, QsciScintilla.SCI_VCHOME)
913 act.triggered.connect(self.esm.map)
914 self.editActions.append(act)
915
916 act = E5Action(
917 QCoreApplication.translate(
918 'ViewManager',
919 'Move to start of display line'),
920 QCoreApplication.translate(
921 'ViewManager',
922 'Move to start of display line'),
923 0, 0,
924 self.editorActGrp, 'vm_edit_move_start_line')
925 if isMacPlatform():
926 act.setShortcut(QKeySequence(
927 QCoreApplication.translate('ViewManager', 'Ctrl+Left')))
928 else:
929 act.setShortcut(QKeySequence(
930 QCoreApplication.translate('ViewManager', 'Alt+Home')))
931 self.esm.setMapping(act, QsciScintilla.SCI_HOMEDISPLAY)
932 act.triggered.connect(self.esm.map)
933 self.editActions.append(act)
934
935 act = E5Action(
936 QCoreApplication.translate(
937 'ViewManager',
938 'Move to end of document line'),
939 QCoreApplication.translate(
940 'ViewManager',
941 'Move to end of document line'),
942 0, 0,
943 self.editorActGrp, 'vm_edit_move_end_line')
944 if isMacPlatform():
945 act.setShortcut(QKeySequence(
946 QCoreApplication.translate('ViewManager', 'Meta+E')))
947 else:
948 act.setShortcut(QKeySequence(
949 QCoreApplication.translate('ViewManager', 'End')))
950 self.esm.setMapping(act, QsciScintilla.SCI_LINEEND)
951 act.triggered.connect(self.esm.map)
952 self.editActions.append(act)
953
954 act = E5Action(
955 QCoreApplication.translate('ViewManager',
956 'Scroll view down one line'),
957 QCoreApplication.translate('ViewManager',
958 'Scroll view down one line'),
959 QKeySequence(QCoreApplication.translate('ViewManager',
960 'Ctrl+Down')),
961 0, self.editorActGrp, 'vm_edit_scroll_down_line')
962 self.esm.setMapping(act, QsciScintilla.SCI_LINESCROLLDOWN)
963 act.triggered.connect(self.esm.map)
964 self.editActions.append(act)
965
966 act = E5Action(
967 QCoreApplication.translate('ViewManager',
968 'Scroll view up one line'),
969 QCoreApplication.translate('ViewManager',
970 'Scroll view up one line'),
971 QKeySequence(QCoreApplication.translate('ViewManager', 'Ctrl+Up')),
972 0, self.editorActGrp, 'vm_edit_scroll_up_line')
973 self.esm.setMapping(act, QsciScintilla.SCI_LINESCROLLUP)
974 act.triggered.connect(self.esm.map)
975 self.editActions.append(act)
976
977 act = E5Action(
978 QCoreApplication.translate('ViewManager', 'Move up one paragraph'),
979 QCoreApplication.translate('ViewManager', 'Move up one paragraph'),
980 QKeySequence(QCoreApplication.translate('ViewManager', 'Alt+Up')),
981 0, self.editorActGrp, 'vm_edit_move_up_para')
982 self.esm.setMapping(act, QsciScintilla.SCI_PARAUP)
983 act.triggered.connect(self.esm.map)
984 self.editActions.append(act)
985
986 act = E5Action(
987 QCoreApplication.translate('ViewManager',
988 'Move down one paragraph'),
989 QCoreApplication.translate('ViewManager',
990 'Move down one paragraph'),
991 QKeySequence(QCoreApplication.translate('ViewManager',
992 'Alt+Down')),
993 0, self.editorActGrp, 'vm_edit_move_down_para')
994 self.esm.setMapping(act, QsciScintilla.SCI_PARADOWN)
995 act.triggered.connect(self.esm.map)
996 self.editActions.append(act)
997
998 act = E5Action(
999 QCoreApplication.translate('ViewManager', 'Move up one page'),
1000 QCoreApplication.translate('ViewManager', 'Move up one page'),
1001 QKeySequence(QCoreApplication.translate('ViewManager', 'PgUp')), 0,
1002 self.editorActGrp, 'vm_edit_move_up_page')
1003 self.esm.setMapping(act, QsciScintilla.SCI_PAGEUP)
1004 act.triggered.connect(self.esm.map)
1005 self.editActions.append(act)
1006
1007 act = E5Action(
1008 QCoreApplication.translate('ViewManager', 'Move down one page'),
1009 QCoreApplication.translate('ViewManager', 'Move down one page'),
1010 QKeySequence(QCoreApplication.translate('ViewManager', 'PgDown')),
1011 0, self.editorActGrp, 'vm_edit_move_down_page')
1012 if isMacPlatform():
1013 act.setAlternateShortcut(QKeySequence(
1014 QCoreApplication.translate('ViewManager', 'Meta+V')))
1015 self.esm.setMapping(act, QsciScintilla.SCI_PAGEDOWN)
1016 act.triggered.connect(self.esm.map)
1017 self.editActions.append(act)
1018
1019 act = E5Action(
1020 QCoreApplication.translate('ViewManager',
1021 'Move to start of document'),
1022 QCoreApplication.translate('ViewManager',
1023 'Move to start of document'),
1024 0, 0,
1025 self.editorActGrp, 'vm_edit_move_start_text')
1026 if isMacPlatform():
1027 act.setShortcut(QKeySequence(
1028 QCoreApplication.translate('ViewManager', 'Ctrl+Up')))
1029 else:
1030 act.setShortcut(QKeySequence(
1031 QCoreApplication.translate('ViewManager', 'Ctrl+Home')))
1032 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTSTART)
1033 act.triggered.connect(self.esm.map)
1034 self.editActions.append(act)
1035
1036 act = E5Action(
1037 QCoreApplication.translate('ViewManager',
1038 'Move to end of document'),
1039 QCoreApplication.translate('ViewManager',
1040 'Move to end of document'),
1041 0, 0,
1042 self.editorActGrp, 'vm_edit_move_end_text')
1043 if isMacPlatform():
1044 act.setShortcut(QKeySequence(
1045 QCoreApplication.translate('ViewManager', 'Ctrl+Down')))
1046 else:
1047 act.setShortcut(QKeySequence(
1048 QCoreApplication.translate('ViewManager', 'Ctrl+End')))
1049 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTEND)
1050 act.triggered.connect(self.esm.map)
1051 self.editActions.append(act)
1052
1053 act = E5Action(
1054 QCoreApplication.translate('ViewManager', 'Indent one level'),
1055 QCoreApplication.translate('ViewManager', 'Indent one level'),
1056 QKeySequence(QCoreApplication.translate('ViewManager', 'Tab')), 0,
1057 self.editorActGrp, 'vm_edit_indent_one_level')
1058 self.esm.setMapping(act, QsciScintilla.SCI_TAB)
1059 act.triggered.connect(self.esm.map)
1060 self.editActions.append(act)
1061
1062 act = E5Action(
1063 QCoreApplication.translate('ViewManager', 'Unindent one level'),
1064 QCoreApplication.translate('ViewManager', 'Unindent one level'),
1065 QKeySequence(QCoreApplication.translate('ViewManager',
1066 'Shift+Tab')),
1067 0, self.editorActGrp, 'vm_edit_unindent_one_level')
1068 self.esm.setMapping(act, QsciScintilla.SCI_BACKTAB)
1069 act.triggered.connect(self.esm.map)
1070 self.editActions.append(act)
1071
1072 act = E5Action(
1073 QCoreApplication.translate(
1074 'ViewManager', 'Extend selection left one character'),
1075 QCoreApplication.translate(
1076 'ViewManager',
1077 'Extend selection left one character'),
1078 QKeySequence(QCoreApplication.translate('ViewManager',
1079 'Shift+Left')),
1080 0, self.editorActGrp, 'vm_edit_extend_selection_left_char')
1081 if isMacPlatform():
1082 act.setAlternateShortcut(QKeySequence(
1083 QCoreApplication.translate('ViewManager', 'Meta+Shift+B')))
1084 self.esm.setMapping(act, QsciScintilla.SCI_CHARLEFTEXTEND)
1085 act.triggered.connect(self.esm.map)
1086 self.editActions.append(act)
1087
1088 act = E5Action(
1089 QCoreApplication.translate(
1090 'ViewManager',
1091 'Extend selection right one character'),
1092 QCoreApplication.translate(
1093 'ViewManager',
1094 'Extend selection right one character'),
1095 QKeySequence(QCoreApplication.translate('ViewManager',
1096 'Shift+Right')),
1097 0, self.editorActGrp, 'vm_edit_extend_selection_right_char')
1098 if isMacPlatform():
1099 act.setAlternateShortcut(QKeySequence(
1100 QCoreApplication.translate('ViewManager', 'Meta+Shift+F')))
1101 self.esm.setMapping(act, QsciScintilla.SCI_CHARRIGHTEXTEND)
1102 act.triggered.connect(self.esm.map)
1103 self.editActions.append(act)
1104
1105 act = E5Action(
1106 QCoreApplication.translate(
1107 'ViewManager',
1108 'Extend selection up one line'),
1109 QCoreApplication.translate(
1110 'ViewManager',
1111 'Extend selection up one line'),
1112 QKeySequence(QCoreApplication.translate('ViewManager',
1113 'Shift+Up')),
1114 0, self.editorActGrp, 'vm_edit_extend_selection_up_line')
1115 if isMacPlatform():
1116 act.setAlternateShortcut(QKeySequence(
1117 QCoreApplication.translate('ViewManager', 'Meta+Shift+P')))
1118 self.esm.setMapping(act, QsciScintilla.SCI_LINEUPEXTEND)
1119 act.triggered.connect(self.esm.map)
1120 self.editActions.append(act)
1121
1122 act = E5Action(
1123 QCoreApplication.translate(
1124 'ViewManager',
1125 'Extend selection down one line'),
1126 QCoreApplication.translate(
1127 'ViewManager',
1128 'Extend selection down one line'),
1129 QKeySequence(QCoreApplication.translate('ViewManager',
1130 'Shift+Down')),
1131 0, self.editorActGrp, 'vm_edit_extend_selection_down_line')
1132 if isMacPlatform():
1133 act.setAlternateShortcut(QKeySequence(
1134 QCoreApplication.translate('ViewManager', 'Meta+Shift+N')))
1135 self.esm.setMapping(act, QsciScintilla.SCI_LINEDOWNEXTEND)
1136 act.triggered.connect(self.esm.map)
1137 self.editActions.append(act)
1138
1139 act = E5Action(
1140 QCoreApplication.translate(
1141 'ViewManager',
1142 'Extend selection left one word part'),
1143 QCoreApplication.translate(
1144 'ViewManager',
1145 'Extend selection left one word part'),
1146 0, 0,
1147 self.editorActGrp, 'vm_edit_extend_selection_left_word_part')
1148 if not isMacPlatform():
1149 act.setShortcut(QKeySequence(
1150 QCoreApplication.translate('ViewManager', 'Alt+Shift+Left')))
1151 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTLEFTEXTEND)
1152 act.triggered.connect(self.esm.map)
1153 self.editActions.append(act)
1154
1155 act = E5Action(
1156 QCoreApplication.translate(
1157 'ViewManager',
1158 'Extend selection right one word part'),
1159 QCoreApplication.translate(
1160 'ViewManager',
1161 'Extend selection right one word part'),
1162 0, 0,
1163 self.editorActGrp, 'vm_edit_extend_selection_right_word_part')
1164 if not isMacPlatform():
1165 act.setShortcut(QKeySequence(
1166 QCoreApplication.translate('ViewManager', 'Alt+Shift+Right')))
1167 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTRIGHTEXTEND)
1168 act.triggered.connect(self.esm.map)
1169 self.editActions.append(act)
1170
1171 act = E5Action(
1172 QCoreApplication.translate(
1173 'ViewManager', 'Extend selection left one word'),
1174 QCoreApplication.translate(
1175 'ViewManager', 'Extend selection left one word'),
1176 0, 0,
1177 self.editorActGrp, 'vm_edit_extend_selection_left_word')
1178 if isMacPlatform():
1179 act.setShortcut(QKeySequence(
1180 QCoreApplication.translate('ViewManager', 'Alt+Shift+Left')))
1181 else:
1182 act.setShortcut(QKeySequence(
1183 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Left')))
1184 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFTEXTEND)
1185 act.triggered.connect(self.esm.map)
1186 self.editActions.append(act)
1187
1188 act = E5Action(
1189 QCoreApplication.translate(
1190 'ViewManager', 'Extend selection right one word'),
1191 QCoreApplication.translate(
1192 'ViewManager', 'Extend selection right one word'),
1193 0, 0,
1194 self.editorActGrp, 'vm_edit_extend_selection_right_word')
1195 if isMacPlatform():
1196 act.setShortcut(QKeySequence(
1197 QCoreApplication.translate('ViewManager', 'Alt+Shift+Right')))
1198 else:
1199 act.setShortcut(QKeySequence(
1200 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Right')))
1201 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHTEXTEND)
1202 act.triggered.connect(self.esm.map)
1203 self.editActions.append(act)
1204
1205 act = E5Action(
1206 QCoreApplication.translate(
1207 'ViewManager',
1208 'Extend selection to first visible character in document'
1209 ' line'),
1210 QCoreApplication.translate(
1211 'ViewManager',
1212 'Extend selection to first visible character in document'
1213 ' line'),
1214 0, 0,
1215 self.editorActGrp, 'vm_edit_extend_selection_first_visible_char')
1216 if not isMacPlatform():
1217 act.setShortcut(QKeySequence(
1218 QCoreApplication.translate('ViewManager', 'Shift+Home')))
1219 self.esm.setMapping(act, QsciScintilla.SCI_VCHOMEEXTEND)
1220 act.triggered.connect(self.esm.map)
1221 self.editActions.append(act)
1222
1223 act = E5Action(
1224 QCoreApplication.translate(
1225 'ViewManager', 'Extend selection to end of document line'),
1226 QCoreApplication.translate(
1227 'ViewManager', 'Extend selection to end of document line'),
1228 0, 0,
1229 self.editorActGrp, 'vm_edit_extend_selection_end_line')
1230 if isMacPlatform():
1231 act.setShortcut(QKeySequence(
1232 QCoreApplication.translate('ViewManager', 'Meta+Shift+E')))
1233 else:
1234 act.setShortcut(QKeySequence(
1235 QCoreApplication.translate('ViewManager', 'Shift+End')))
1236 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDEXTEND)
1237 act.triggered.connect(self.esm.map)
1238 self.editActions.append(act)
1239
1240 act = E5Action(
1241 QCoreApplication.translate(
1242 'ViewManager',
1243 'Extend selection up one paragraph'),
1244 QCoreApplication.translate(
1245 'ViewManager',
1246 'Extend selection up one paragraph'),
1247 QKeySequence(QCoreApplication.translate('ViewManager',
1248 'Alt+Shift+Up')),
1249 0, self.editorActGrp, 'vm_edit_extend_selection_up_para')
1250 self.esm.setMapping(act, QsciScintilla.SCI_PARAUPEXTEND)
1251 act.triggered.connect(self.esm.map)
1252 self.editActions.append(act)
1253
1254 act = E5Action(
1255 QCoreApplication.translate(
1256 'ViewManager', 'Extend selection down one paragraph'),
1257 QCoreApplication.translate(
1258 'ViewManager', 'Extend selection down one paragraph'),
1259 QKeySequence(QCoreApplication.translate('ViewManager',
1260 'Alt+Shift+Down')),
1261 0,
1262 self.editorActGrp, 'vm_edit_extend_selection_down_para')
1263 self.esm.setMapping(act, QsciScintilla.SCI_PARADOWNEXTEND)
1264 act.triggered.connect(self.esm.map)
1265 self.editActions.append(act)
1266
1267 act = E5Action(
1268 QCoreApplication.translate(
1269 'ViewManager',
1270 'Extend selection up one page'),
1271 QCoreApplication.translate(
1272 'ViewManager',
1273 'Extend selection up one page'),
1274 QKeySequence(QCoreApplication.translate('ViewManager',
1275 'Shift+PgUp')),
1276 0, self.editorActGrp, 'vm_edit_extend_selection_up_page')
1277 self.esm.setMapping(act, QsciScintilla.SCI_PAGEUPEXTEND)
1278 act.triggered.connect(self.esm.map)
1279 self.editActions.append(act)
1280
1281 act = E5Action(
1282 QCoreApplication.translate(
1283 'ViewManager',
1284 'Extend selection down one page'),
1285 QCoreApplication.translate(
1286 'ViewManager',
1287 'Extend selection down one page'),
1288 QKeySequence(QCoreApplication.translate('ViewManager',
1289 'Shift+PgDown')),
1290 0, self.editorActGrp, 'vm_edit_extend_selection_down_page')
1291 if isMacPlatform():
1292 act.setAlternateShortcut(QKeySequence(
1293 QCoreApplication.translate('ViewManager', 'Meta+Shift+V')))
1294 self.esm.setMapping(act, QsciScintilla.SCI_PAGEDOWNEXTEND)
1295 act.triggered.connect(self.esm.map)
1296 self.editActions.append(act)
1297
1298 act = E5Action(
1299 QCoreApplication.translate(
1300 'ViewManager', 'Extend selection to start of document'),
1301 QCoreApplication.translate(
1302 'ViewManager', 'Extend selection to start of document'),
1303 0, 0,
1304 self.editorActGrp, 'vm_edit_extend_selection_start_text')
1305 if isMacPlatform():
1306 act.setShortcut(QKeySequence(
1307 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Up')))
1308 else:
1309 act.setShortcut(QKeySequence(
1310 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Home')))
1311 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTSTARTEXTEND)
1312 act.triggered.connect(self.esm.map)
1313 self.editActions.append(act)
1314
1315 act = E5Action(
1316 QCoreApplication.translate(
1317 'ViewManager', 'Extend selection to end of document'),
1318 QCoreApplication.translate(
1319 'ViewManager', 'Extend selection to end of document'),
1320 0, 0,
1321 self.editorActGrp, 'vm_edit_extend_selection_end_text')
1322 if isMacPlatform():
1323 act.setShortcut(QKeySequence(
1324 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Down')))
1325 else:
1326 act.setShortcut(QKeySequence(
1327 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+End')))
1328 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTENDEXTEND)
1329 act.triggered.connect(self.esm.map)
1330 self.editActions.append(act)
1331
1332 act = E5Action(
1333 QCoreApplication.translate('ViewManager',
1334 'Delete previous character'),
1335 QCoreApplication.translate('ViewManager',
1336 'Delete previous character'),
1337 QKeySequence(QCoreApplication.translate('ViewManager',
1338 'Backspace')),
1339 0, self.editorActGrp, 'vm_edit_delete_previous_char')
1340 if isMacPlatform():
1341 act.setAlternateShortcut(QKeySequence(
1342 QCoreApplication.translate('ViewManager', 'Meta+H')))
1343 else:
1344 act.setAlternateShortcut(QKeySequence(
1345 QCoreApplication.translate('ViewManager', 'Shift+Backspace')))
1346 self.esm.setMapping(act, QsciScintilla.SCI_DELETEBACK)
1347 act.triggered.connect(self.esm.map)
1348 self.editActions.append(act)
1349
1350 act = E5Action(
1351 QCoreApplication.translate(
1352 'ViewManager',
1353 'Delete previous character if not at start of line'),
1354 QCoreApplication.translate(
1355 'ViewManager',
1356 'Delete previous character if not at start of line'),
1357 0, 0,
1358 self.editorActGrp, 'vm_edit_delet_previous_char_not_line_start')
1359 self.esm.setMapping(act, QsciScintilla.SCI_DELETEBACKNOTLINE)
1360 act.triggered.connect(self.esm.map)
1361 self.editActions.append(act)
1362
1363 act = E5Action(
1364 QCoreApplication.translate('ViewManager',
1365 'Delete current character'),
1366 QCoreApplication.translate('ViewManager',
1367 'Delete current character'),
1368 QKeySequence(QCoreApplication.translate('ViewManager', 'Del')), 0,
1369 self.editorActGrp, 'vm_edit_delete_current_char')
1370 if isMacPlatform():
1371 act.setAlternateShortcut(QKeySequence(
1372 QCoreApplication.translate('ViewManager', 'Meta+D')))
1373 self.esm.setMapping(act, QsciScintilla.SCI_CLEAR)
1374 act.triggered.connect(self.esm.map)
1375 self.editActions.append(act)
1376
1377 act = E5Action(
1378 QCoreApplication.translate('ViewManager', 'Delete word to left'),
1379 QCoreApplication.translate('ViewManager', 'Delete word to left'),
1380 QKeySequence(QCoreApplication.translate('ViewManager',
1381 'Ctrl+Backspace')),
1382 0, self.editorActGrp, 'vm_edit_delete_word_left')
1383 self.esm.setMapping(act, QsciScintilla.SCI_DELWORDLEFT)
1384 act.triggered.connect(self.esm.map)
1385 self.editActions.append(act)
1386
1387 act = E5Action(
1388 QCoreApplication.translate('ViewManager', 'Delete word to right'),
1389 QCoreApplication.translate('ViewManager', 'Delete word to right'),
1390 QKeySequence(QCoreApplication.translate('ViewManager',
1391 'Ctrl+Del')),
1392 0, self.editorActGrp, 'vm_edit_delete_word_right')
1393 self.esm.setMapping(act, QsciScintilla.SCI_DELWORDRIGHT)
1394 act.triggered.connect(self.esm.map)
1395 self.editActions.append(act)
1396
1397 act = E5Action(
1398 QCoreApplication.translate('ViewManager', 'Delete line to left'),
1399 QCoreApplication.translate('ViewManager', 'Delete line to left'),
1400 QKeySequence(QCoreApplication.translate('ViewManager',
1401 'Ctrl+Shift+Backspace')),
1402 0, self.editorActGrp, 'vm_edit_delete_line_left')
1403 self.esm.setMapping(act, QsciScintilla.SCI_DELLINELEFT)
1404 act.triggered.connect(self.esm.map)
1405 self.editActions.append(act)
1406
1407 act = E5Action(
1408 QCoreApplication.translate('ViewManager', 'Delete line to right'),
1409 QCoreApplication.translate('ViewManager', 'Delete line to right'),
1410 0, 0,
1411 self.editorActGrp, 'vm_edit_delete_line_right')
1412 if isMacPlatform():
1413 act.setShortcut(QKeySequence(
1414 QCoreApplication.translate('ViewManager', 'Meta+K')))
1415 else:
1416 act.setShortcut(QKeySequence(
1417 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Del')))
1418 self.esm.setMapping(act, QsciScintilla.SCI_DELLINERIGHT)
1419 act.triggered.connect(self.esm.map)
1420 self.editActions.append(act)
1421
1422 act = E5Action(
1423 QCoreApplication.translate('ViewManager', 'Insert new line'),
1424 QCoreApplication.translate('ViewManager', 'Insert new line'),
1425 QKeySequence(QCoreApplication.translate('ViewManager', 'Return')),
1426 QKeySequence(QCoreApplication.translate('ViewManager', 'Enter')),
1427 self.editorActGrp, 'vm_edit_insert_line')
1428 self.esm.setMapping(act, QsciScintilla.SCI_NEWLINE)
1429 act.triggered.connect(self.esm.map)
1430 self.editActions.append(act)
1431
1432 act = E5Action(
1433 QCoreApplication.translate('ViewManager', 'Delete current line'),
1434 QCoreApplication.translate('ViewManager', 'Delete current line'),
1435 QKeySequence(QCoreApplication.translate('ViewManager',
1436 'Ctrl+Shift+L')),
1437 0, self.editorActGrp, 'vm_edit_delete_current_line')
1438 self.esm.setMapping(act, QsciScintilla.SCI_LINEDELETE)
1439 act.triggered.connect(self.esm.map)
1440 self.editActions.append(act)
1441
1442 act = E5Action(
1443 QCoreApplication.translate('ViewManager',
1444 'Duplicate current line'),
1445 QCoreApplication.translate('ViewManager',
1446 'Duplicate current line'),
1447 QKeySequence(QCoreApplication.translate('ViewManager', 'Ctrl+D')),
1448 0, self.editorActGrp, 'vm_edit_duplicate_current_line')
1449 self.esm.setMapping(act, QsciScintilla.SCI_LINEDUPLICATE)
1450 act.triggered.connect(self.esm.map)
1451 self.editActions.append(act)
1452
1453 act = E5Action(
1454 QCoreApplication.translate(
1455 'ViewManager',
1456 'Swap current and previous lines'),
1457 QCoreApplication.translate(
1458 'ViewManager',
1459 'Swap current and previous lines'),
1460 QKeySequence(QCoreApplication.translate('ViewManager', 'Ctrl+T')),
1461 0, self.editorActGrp, 'vm_edit_swap_current_previous_line')
1462 self.esm.setMapping(act, QsciScintilla.SCI_LINETRANSPOSE)
1463 act.triggered.connect(self.esm.map)
1464 self.editActions.append(act)
1465
1466 act = E5Action(
1467 QCoreApplication.translate('ViewManager',
1468 'Reverse selected lines'),
1469 QCoreApplication.translate('ViewManager',
1470 'Reverse selected lines'),
1471 QKeySequence(QCoreApplication.translate('ViewManager',
1472 'Meta+Alt+R')),
1473 0, self.editorActGrp, 'vm_edit_reverse selected_lines')
1474 self.esm.setMapping(act, QsciScintilla.SCI_LINEREVERSE)
1475 act.triggered.connect(self.esm.map)
1476 self.editActions.append(act)
1477
1478 act = E5Action(
1479 QCoreApplication.translate('ViewManager', 'Cut current line'),
1480 QCoreApplication.translate('ViewManager', 'Cut current line'),
1481 QKeySequence(QCoreApplication.translate('ViewManager',
1482 'Alt+Shift+L')),
1483 0, self.editorActGrp, 'vm_edit_cut_current_line')
1484 self.esm.setMapping(act, QsciScintilla.SCI_LINECUT)
1485 act.triggered.connect(self.esm.map)
1486 self.editActions.append(act)
1487
1488 act = E5Action(
1489 QCoreApplication.translate('ViewManager', 'Copy current line'),
1490 QCoreApplication.translate('ViewManager', 'Copy current line'),
1491 QKeySequence(QCoreApplication.translate('ViewManager',
1492 'Ctrl+Shift+T')),
1493 0, self.editorActGrp, 'vm_edit_copy_current_line')
1494 self.esm.setMapping(act, QsciScintilla.SCI_LINECOPY)
1495 act.triggered.connect(self.esm.map)
1496 self.editActions.append(act)
1497
1498 act = E5Action(
1499 QCoreApplication.translate('ViewManager',
1500 'Toggle insert/overtype'),
1501 QCoreApplication.translate('ViewManager',
1502 'Toggle insert/overtype'),
1503 QKeySequence(QCoreApplication.translate('ViewManager', 'Ins')), 0,
1504 self.editorActGrp, 'vm_edit_toggle_insert_overtype')
1505 self.esm.setMapping(act, QsciScintilla.SCI_EDITTOGGLEOVERTYPE)
1506 act.triggered.connect(self.esm.map)
1507 self.editActions.append(act)
1508
1509 act = E5Action(
1510 QCoreApplication.translate(
1511 'ViewManager',
1512 'Convert selection to lower case'),
1513 QCoreApplication.translate(
1514 'ViewManager',
1515 'Convert selection to lower case'),
1516 QKeySequence(QCoreApplication.translate('ViewManager',
1517 'Alt+Shift+U')),
1518 0, self.editorActGrp, 'vm_edit_convert_selection_lower')
1519 self.esm.setMapping(act, QsciScintilla.SCI_LOWERCASE)
1520 act.triggered.connect(self.esm.map)
1521 self.editActions.append(act)
1522
1523 act = E5Action(
1524 QCoreApplication.translate(
1525 'ViewManager',
1526 'Convert selection to upper case'),
1527 QCoreApplication.translate(
1528 'ViewManager',
1529 'Convert selection to upper case'),
1530 QKeySequence(QCoreApplication.translate('ViewManager',
1531 'Ctrl+Shift+U')),
1532 0, self.editorActGrp, 'vm_edit_convert_selection_upper')
1533 self.esm.setMapping(act, QsciScintilla.SCI_UPPERCASE)
1534 act.triggered.connect(self.esm.map)
1535 self.editActions.append(act)
1536
1537 act = E5Action(
1538 QCoreApplication.translate(
1539 'ViewManager', 'Move to end of display line'),
1540 QCoreApplication.translate(
1541 'ViewManager', 'Move to end of display line'),
1542 0, 0,
1543 self.editorActGrp, 'vm_edit_move_end_displayed_line')
1544 if isMacPlatform():
1545 act.setShortcut(QKeySequence(
1546 QCoreApplication.translate('ViewManager', 'Ctrl+Right')))
1547 else:
1548 act.setShortcut(QKeySequence(
1549 QCoreApplication.translate('ViewManager', 'Alt+End')))
1550 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDDISPLAY)
1551 act.triggered.connect(self.esm.map)
1552 self.editActions.append(act)
1553
1554 act = E5Action(
1555 QCoreApplication.translate(
1556 'ViewManager',
1557 'Extend selection to end of display line'),
1558 QCoreApplication.translate(
1559 'ViewManager',
1560 'Extend selection to end of display line'),
1561 0, 0,
1562 self.editorActGrp, 'vm_edit_extend_selection_end_displayed_line')
1563 if isMacPlatform():
1564 act.setShortcut(QKeySequence(
1565 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Right')))
1566 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDDISPLAYEXTEND)
1567 act.triggered.connect(self.esm.map)
1568 self.editActions.append(act)
1569
1570 act = E5Action(
1571 QCoreApplication.translate('ViewManager', 'Formfeed'),
1572 QCoreApplication.translate('ViewManager', 'Formfeed'),
1573 0, 0,
1574 self.editorActGrp, 'vm_edit_formfeed')
1575 self.esm.setMapping(act, QsciScintilla.SCI_FORMFEED)
1576 act.triggered.connect(self.esm.map)
1577 self.editActions.append(act)
1578
1579 act = E5Action(
1580 QCoreApplication.translate('ViewManager', 'Escape'),
1581 QCoreApplication.translate('ViewManager', 'Escape'),
1582 QKeySequence(QCoreApplication.translate('ViewManager', 'Esc')), 0,
1583 self.editorActGrp, 'vm_edit_escape')
1584 self.esm.setMapping(act, QsciScintilla.SCI_CANCEL)
1585 act.triggered.connect(self.esm.map)
1586 self.editActions.append(act)
1587
1588 act = E5Action(
1589 QCoreApplication.translate(
1590 'ViewManager',
1591 'Extend rectangular selection down one line'),
1592 QCoreApplication.translate(
1593 'ViewManager',
1594 'Extend rectangular selection down one line'),
1595 QKeySequence(QCoreApplication.translate('ViewManager',
1596 'Alt+Ctrl+Down')),
1597 0, self.editorActGrp, 'vm_edit_extend_rect_selection_down_line')
1598 if isMacPlatform():
1599 act.setAlternateShortcut(QKeySequence(
1600 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+N')))
1601 self.esm.setMapping(act, QsciScintilla.SCI_LINEDOWNRECTEXTEND)
1602 act.triggered.connect(self.esm.map)
1603 self.editActions.append(act)
1604
1605 act = E5Action(
1606 QCoreApplication.translate(
1607 'ViewManager',
1608 'Extend rectangular selection up one line'),
1609 QCoreApplication.translate(
1610 'ViewManager',
1611 'Extend rectangular selection up one line'),
1612 QKeySequence(QCoreApplication.translate('ViewManager',
1613 'Alt+Ctrl+Up')),
1614 0, self.editorActGrp, 'vm_edit_extend_rect_selection_up_line')
1615 if isMacPlatform():
1616 act.setAlternateShortcut(QKeySequence(
1617 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+P')))
1618 self.esm.setMapping(act, QsciScintilla.SCI_LINEUPRECTEXTEND)
1619 act.triggered.connect(self.esm.map)
1620 self.editActions.append(act)
1621
1622 act = E5Action(
1623 QCoreApplication.translate(
1624 'ViewManager',
1625 'Extend rectangular selection left one character'),
1626 QCoreApplication.translate(
1627 'ViewManager',
1628 'Extend rectangular selection left one character'),
1629 QKeySequence(QCoreApplication.translate('ViewManager',
1630 'Alt+Ctrl+Left')),
1631 0, self.editorActGrp, 'vm_edit_extend_rect_selection_left_char')
1632 if isMacPlatform():
1633 act.setAlternateShortcut(QKeySequence(
1634 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+B')))
1635 self.esm.setMapping(act, QsciScintilla.SCI_CHARLEFTRECTEXTEND)
1636 act.triggered.connect(self.esm.map)
1637 self.editActions.append(act)
1638
1639 act = E5Action(
1640 QCoreApplication.translate(
1641 'ViewManager',
1642 'Extend rectangular selection right one character'),
1643 QCoreApplication.translate(
1644 'ViewManager',
1645 'Extend rectangular selection right one character'),
1646 QKeySequence(QCoreApplication.translate('ViewManager',
1647 'Alt+Ctrl+Right')),
1648 0, self.editorActGrp, 'vm_edit_extend_rect_selection_right_char')
1649 if isMacPlatform():
1650 act.setAlternateShortcut(QKeySequence(
1651 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+F')))
1652 self.esm.setMapping(act, QsciScintilla.SCI_CHARRIGHTRECTEXTEND)
1653 act.triggered.connect(self.esm.map)
1654 self.editActions.append(act)
1655
1656 act = E5Action(
1657 QCoreApplication.translate(
1658 'ViewManager',
1659 'Extend rectangular selection to first'
1660 ' visible character in document line'),
1661 QCoreApplication.translate(
1662 'ViewManager',
1663 'Extend rectangular selection to first'
1664 ' visible character in document line'),
1665 0, 0,
1666 self.editorActGrp,
1667 'vm_edit_extend_rect_selection_first_visible_char')
1668 if not isMacPlatform():
1669 act.setShortcut(QKeySequence(
1670 QCoreApplication.translate('ViewManager', 'Alt+Shift+Home')))
1671 self.esm.setMapping(act, QsciScintilla.SCI_VCHOMERECTEXTEND)
1672 act.triggered.connect(self.esm.map)
1673 self.editActions.append(act)
1674
1675 act = E5Action(
1676 QCoreApplication.translate(
1677 'ViewManager',
1678 'Extend rectangular selection to end of document line'),
1679 QCoreApplication.translate(
1680 'ViewManager',
1681 'Extend rectangular selection to end of document line'),
1682 0, 0,
1683 self.editorActGrp, 'vm_edit_extend_rect_selection_end_line')
1684 if isMacPlatform():
1685 act.setShortcut(QKeySequence(
1686 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+E')))
1687 else:
1688 act.setShortcut(QKeySequence(
1689 QCoreApplication.translate('ViewManager', 'Alt+Shift+End')))
1690 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDRECTEXTEND)
1691 act.triggered.connect(self.esm.map)
1692 self.editActions.append(act)
1693
1694 act = E5Action(
1695 QCoreApplication.translate(
1696 'ViewManager',
1697 'Extend rectangular selection up one page'),
1698 QCoreApplication.translate(
1699 'ViewManager',
1700 'Extend rectangular selection up one page'),
1701 QKeySequence(QCoreApplication.translate('ViewManager',
1702 'Alt+Shift+PgUp')),
1703 0, self.editorActGrp, 'vm_edit_extend_rect_selection_up_page')
1704 self.esm.setMapping(act, QsciScintilla.SCI_PAGEUPRECTEXTEND)
1705 act.triggered.connect(self.esm.map)
1706 self.editActions.append(act)
1707
1708 act = E5Action(
1709 QCoreApplication.translate(
1710 'ViewManager',
1711 'Extend rectangular selection down one page'),
1712 QCoreApplication.translate(
1713 'ViewManager',
1714 'Extend rectangular selection down one page'),
1715 QKeySequence(QCoreApplication.translate('ViewManager',
1716 'Alt+Shift+PgDown')),
1717 0, self.editorActGrp, 'vm_edit_extend_rect_selection_down_page')
1718 if isMacPlatform():
1719 act.setAlternateShortcut(QKeySequence(
1720 QCoreApplication.translate('ViewManager', 'Meta+Alt+Shift+V')))
1721 self.esm.setMapping(act, QsciScintilla.SCI_PAGEDOWNRECTEXTEND)
1722 act.triggered.connect(self.esm.map)
1723 self.editActions.append(act)
1724
1725 act = E5Action(
1726 QCoreApplication.translate(
1727 'ViewManager',
1728 'Duplicate current selection'),
1729 QCoreApplication.translate(
1730 'ViewManager',
1731 'Duplicate current selection'),
1732 QKeySequence(QCoreApplication.translate('ViewManager',
1733 'Ctrl+Shift+D')),
1734 0, self.editorActGrp, 'vm_edit_duplicate_current_selection')
1735 self.esm.setMapping(act, QsciScintilla.SCI_SELECTIONDUPLICATE)
1736 act.triggered.connect(self.esm.map)
1737 self.editActions.append(act)
1738
1739 if hasattr(QsciScintilla, "SCI_SCROLLTOSTART"):
1740 act = E5Action(
1741 QCoreApplication.translate(
1742 'ViewManager', 'Scroll to start of document'),
1743 QCoreApplication.translate(
1744 'ViewManager', 'Scroll to start of document'),
1745 0, 0,
1746 self.editorActGrp, 'vm_edit_scroll_start_text')
1747 if isMacPlatform():
1748 act.setShortcut(QKeySequence(
1749 QCoreApplication.translate('ViewManager', 'Home')))
1750 self.esm.setMapping(act, QsciScintilla.SCI_SCROLLTOSTART)
1751 act.triggered.connect(self.esm.map)
1752 self.editActions.append(act)
1753
1754 if hasattr(QsciScintilla, "SCI_SCROLLTOEND"):
1755 act = E5Action(
1756 QCoreApplication.translate(
1757 'ViewManager', 'Scroll to end of document'),
1758 QCoreApplication.translate(
1759 'ViewManager', 'Scroll to end of document'),
1760 0, 0,
1761 self.editorActGrp, 'vm_edit_scroll_end_text')
1762 if isMacPlatform():
1763 act.setShortcut(QKeySequence(
1764 QCoreApplication.translate('ViewManager', 'End')))
1765 self.esm.setMapping(act, QsciScintilla.SCI_SCROLLTOEND)
1766 act.triggered.connect(self.esm.map)
1767 self.editActions.append(act)
1768
1769 if hasattr(QsciScintilla, "SCI_VERTICALCENTRECARET"):
1770 act = E5Action(
1771 QCoreApplication.translate(
1772 'ViewManager', 'Scroll vertically to center current line'),
1773 QCoreApplication.translate(
1774 'ViewManager', 'Scroll vertically to center current line'),
1775 0, 0,
1776 self.editorActGrp, 'vm_edit_scroll_vertically_center')
1777 if isMacPlatform():
1778 act.setShortcut(QKeySequence(
1779 QCoreApplication.translate('ViewManager', 'Meta+L')))
1780 self.esm.setMapping(act, QsciScintilla.SCI_VERTICALCENTRECARET)
1781 act.triggered.connect(self.esm.map)
1782 self.editActions.append(act)
1783
1784 if hasattr(QsciScintilla, "SCI_WORDRIGHTEND"):
1785 act = E5Action(
1786 QCoreApplication.translate(
1787 'ViewManager', 'Move to end of next word'),
1788 QCoreApplication.translate(
1789 'ViewManager', 'Move to end of next word'),
1790 0, 0,
1791 self.editorActGrp, 'vm_edit_move_end_next_word')
1792 if isMacPlatform():
1793 act.setShortcut(QKeySequence(
1794 QCoreApplication.translate('ViewManager', 'Alt+Right')))
1795 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHTEND)
1796 act.triggered.connect(self.esm.map)
1797 self.editActions.append(act)
1798
1799 if hasattr(QsciScintilla, "SCI_WORDRIGHTENDEXTEND"):
1800 act = E5Action(
1801 QCoreApplication.translate(
1802 'ViewManager', 'Extend selection to end of next word'),
1803 QCoreApplication.translate(
1804 'ViewManager', 'Extend selection to end of next word'),
1805 0, 0,
1806 self.editorActGrp, 'vm_edit_select_end_next_word')
1807 if isMacPlatform():
1808 act.setShortcut(QKeySequence(
1809 QCoreApplication.translate('ViewManager',
1810 'Alt+Shift+Right')))
1811 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHTENDEXTEND)
1812 act.triggered.connect(self.esm.map)
1813 self.editActions.append(act)
1814
1815 if hasattr(QsciScintilla, "SCI_WORDLEFTEND"):
1816 act = E5Action(
1817 QCoreApplication.translate(
1818 'ViewManager', 'Move to end of previous word'),
1819 QCoreApplication.translate(
1820 'ViewManager', 'Move to end of previous word'),
1821 0, 0,
1822 self.editorActGrp, 'vm_edit_move_end_previous_word')
1823 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFTEND)
1824 act.triggered.connect(self.esm.map)
1825 self.editActions.append(act)
1826
1827 if hasattr(QsciScintilla, "SCI_WORDLEFTENDEXTEND"):
1828 act = E5Action(
1829 QCoreApplication.translate(
1830 'ViewManager', 'Extend selection to end of previous word'),
1831 QCoreApplication.translate(
1832 'ViewManager', 'Extend selection to end of previous word'),
1833 0, 0,
1834 self.editorActGrp, 'vm_edit_select_end_previous_word')
1835 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFTENDEXTEND)
1836 act.triggered.connect(self.esm.map)
1837 self.editActions.append(act)
1838
1839 if hasattr(QsciScintilla, "SCI_HOME"):
1840 act = E5Action(
1841 QCoreApplication.translate(
1842 'ViewManager', 'Move to start of document line'),
1843 QCoreApplication.translate(
1844 'ViewManager', 'Move to start of document line'),
1845 0, 0,
1846 self.editorActGrp, 'vm_edit_move_start_document_line')
1847 if isMacPlatform():
1848 act.setShortcut(QKeySequence(
1849 QCoreApplication.translate('ViewManager', 'Meta+A')))
1850 self.esm.setMapping(act, QsciScintilla.SCI_HOME)
1851 act.triggered.connect(self.esm.map)
1852 self.editActions.append(act)
1853
1854 if hasattr(QsciScintilla, "SCI_HOMEEXTEND"):
1855 act = E5Action(
1856 QCoreApplication.translate(
1857 'ViewManager',
1858 'Extend selection to start of document line'),
1859 QCoreApplication.translate(
1860 'ViewManager',
1861 'Extend selection to start of document line'),
1862 0, 0,
1863 self.editorActGrp,
1864 'vm_edit_extend_selection_start_document_line')
1865 if isMacPlatform():
1866 act.setShortcut(QKeySequence(
1867 QCoreApplication.translate('ViewManager', 'Meta+Shift+A')))
1868 self.esm.setMapping(act, QsciScintilla.SCI_HOME)
1869 act.triggered.connect(self.esm.map)
1870 self.editActions.append(act)
1871
1872 if hasattr(QsciScintilla, "SCI_HOMERECTEXTEND"):
1873 act = E5Action(
1874 QCoreApplication.translate(
1875 'ViewManager',
1876 'Extend rectangular selection to start of document line'),
1877 QCoreApplication.translate(
1878 'ViewManager',
1879 'Extend rectangular selection to start of document line'),
1880 0, 0,
1881 self.editorActGrp, 'vm_edit_select_rect_start_line')
1882 if isMacPlatform():
1883 act.setShortcut(QKeySequence(
1884 QCoreApplication.translate('ViewManager',
1885 'Meta+Alt+Shift+A')))
1886 self.esm.setMapping(act, QsciScintilla.SCI_HOMERECTEXTEND)
1887 act.triggered.connect(self.esm.map)
1888 self.editActions.append(act)
1889
1890 if hasattr(QsciScintilla, "SCI_HOMEDISPLAYEXTEND"):
1891 act = E5Action(
1892 QCoreApplication.translate(
1893 'ViewManager',
1894 'Extend selection to start of display line'),
1895 QCoreApplication.translate(
1896 'ViewManager',
1897 'Extend selection to start of display line'),
1898 0, 0,
1899 self.editorActGrp,
1900 'vm_edit_extend_selection_start_display_line')
1901 if isMacPlatform():
1902 act.setShortcut(QKeySequence(
1903 QCoreApplication.translate('ViewManager',
1904 'Ctrl+Shift+Left')))
1905 self.esm.setMapping(act, QsciScintilla.SCI_HOMEDISPLAYEXTEND)
1906 act.triggered.connect(self.esm.map)
1907 self.editActions.append(act)
1908
1909 if hasattr(QsciScintilla, "SCI_HOMEWRAP"):
1910 act = E5Action(
1911 QCoreApplication.translate(
1912 'ViewManager',
1913 'Move to start of display or document line'),
1914 QCoreApplication.translate(
1915 'ViewManager',
1916 'Move to start of display or document line'),
1917 0, 0,
1918 self.editorActGrp, 'vm_edit_move_start_display_document_line')
1919 self.esm.setMapping(act, QsciScintilla.SCI_HOMEWRAP)
1920 act.triggered.connect(self.esm.map)
1921 self.editActions.append(act)
1922
1923 if hasattr(QsciScintilla, "SCI_HOMEWRAPEXTEND"):
1924 act = E5Action(
1925 QCoreApplication.translate(
1926 'ViewManager',
1927 'Extend selection to start of display or document line'),
1928 QCoreApplication.translate(
1929 'ViewManager',
1930 'Extend selection to start of display or document line'),
1931 0, 0,
1932 self.editorActGrp,
1933 'vm_edit_extend_selection_start_display_document_line')
1934 self.esm.setMapping(act, QsciScintilla.SCI_HOMEWRAPEXTEND)
1935 act.triggered.connect(self.esm.map)
1936 self.editActions.append(act)
1937
1938 if hasattr(QsciScintilla, "SCI_VCHOMEWRAP"):
1939 act = E5Action(
1940 QCoreApplication.translate(
1941 'ViewManager',
1942 'Move to first visible character in display'
1943 ' or document line'),
1944 QCoreApplication.translate(
1945 'ViewManager',
1946 'Move to first visible character in display'
1947 ' or document line'),
1948 0, 0,
1949 self.editorActGrp,
1950 'vm_edit_move_first_visible_char_document_line')
1951 self.esm.setMapping(act, QsciScintilla.SCI_VCHOMEWRAP)
1952 act.triggered.connect(self.esm.map)
1953 self.editActions.append(act)
1954
1955 if hasattr(QsciScintilla, "SCI_VCHOMEWRAPEXTEND"):
1956 act = E5Action(
1957 QCoreApplication.translate(
1958 'ViewManager',
1959 'Extend selection to first visible character in'
1960 ' display or document line'),
1961 QCoreApplication.translate(
1962 'ViewManager',
1963 'Extend selection to first visible character in'
1964 ' display or document line'),
1965 0, 0,
1966 self.editorActGrp,
1967 'vm_edit_extend_selection_first_visible_char_document_line')
1968 self.esm.setMapping(act, QsciScintilla.SCI_VCHOMEWRAPEXTEND)
1969 act.triggered.connect(self.esm.map)
1970 self.editActions.append(act)
1971
1972 if hasattr(QsciScintilla, "SCI_LINEENDWRAP"):
1973 act = E5Action(
1974 QCoreApplication.translate(
1975 'ViewManager',
1976 'Move to end of display or document line'),
1977 QCoreApplication.translate(
1978 'ViewManager',
1979 'Move to end of display or document line'),
1980 0, 0,
1981 self.editorActGrp, 'vm_edit_end_start_display_document_line')
1982 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDWRAP)
1983 act.triggered.connect(self.esm.map)
1984 self.editActions.append(act)
1985
1986 if hasattr(QsciScintilla, "SCI_LINEENDWRAPEXTEND"):
1987 act = E5Action(
1988 QCoreApplication.translate(
1989 'ViewManager',
1990 'Extend selection to end of display or document line'),
1991 QCoreApplication.translate(
1992 'ViewManager',
1993 'Extend selection to end of display or document line'),
1994 0, 0,
1995 self.editorActGrp,
1996 'vm_edit_extend_selection_end_display_document_line')
1997 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDWRAPEXTEND)
1998 act.triggered.connect(self.esm.map)
1999 self.editActions.append(act)
2000
2001 if hasattr(QsciScintilla, "SCI_STUTTEREDPAGEUP"):
2002 act = E5Action(
2003 QCoreApplication.translate(
2004 'ViewManager', 'Stuttered move up one page'),
2005 QCoreApplication.translate(
2006 'ViewManager', 'Stuttered move up one page'),
2007 0, 0,
2008 self.editorActGrp, 'vm_edit_stuttered_move_up_page')
2009 self.esm.setMapping(act, QsciScintilla.SCI_STUTTEREDPAGEUP)
2010 act.triggered.connect(self.esm.map)
2011 self.editActions.append(act)
2012
2013 if hasattr(QsciScintilla, "SCI_STUTTEREDPAGEUPEXTEND"):
2014 act = E5Action(
2015 QCoreApplication.translate(
2016 'ViewManager',
2017 'Stuttered extend selection up one page'),
2018 QCoreApplication.translate(
2019 'ViewManager',
2020 'Stuttered extend selection up one page'),
2021 0, 0,
2022 self.editorActGrp,
2023 'vm_edit_stuttered_extend_selection_up_page')
2024 self.esm.setMapping(act, QsciScintilla.SCI_STUTTEREDPAGEUPEXTEND)
2025 act.triggered.connect(self.esm.map)
2026 self.editActions.append(act)
2027
2028 if hasattr(QsciScintilla, "SCI_STUTTEREDPAGEDOWN"):
2029 act = E5Action(
2030 QCoreApplication.translate(
2031 'ViewManager', 'Stuttered move down one page'),
2032 QCoreApplication.translate(
2033 'ViewManager', 'Stuttered move down one page'),
2034 0, 0,
2035 self.editorActGrp, 'vm_edit_stuttered_move_down_page')
2036 self.esm.setMapping(act, QsciScintilla.SCI_STUTTEREDPAGEDOWN)
2037 act.triggered.connect(self.esm.map)
2038 self.editActions.append(act)
2039
2040 if hasattr(QsciScintilla, "SCI_STUTTEREDPAGEDOWNEXTEND"):
2041 act = E5Action(
2042 QCoreApplication.translate(
2043 'ViewManager',
2044 'Stuttered extend selection down one page'),
2045 QCoreApplication.translate(
2046 'ViewManager',
2047 'Stuttered extend selection down one page'),
2048 0, 0,
2049 self.editorActGrp,
2050 'vm_edit_stuttered_extend_selection_down_page')
2051 self.esm.setMapping(act, QsciScintilla.SCI_STUTTEREDPAGEDOWNEXTEND)
2052 act.triggered.connect(self.esm.map)
2053 self.editActions.append(act)
2054
2055 if hasattr(QsciScintilla, "SCI_DELWORDRIGHTEND"):
2056 act = E5Action(
2057 QCoreApplication.translate(
2058 'ViewManager',
2059 'Delete right to end of next word'),
2060 QCoreApplication.translate(
2061 'ViewManager',
2062 'Delete right to end of next word'),
2063 0, 0,
2064 self.editorActGrp, 'vm_edit_delete_right_end_next_word')
2065 if isMacPlatform():
2066 act.setShortcut(QKeySequence(
2067 QCoreApplication.translate('ViewManager', 'Alt+Del')))
2068 self.esm.setMapping(act, QsciScintilla.SCI_DELWORDRIGHTEND)
2069 act.triggered.connect(self.esm.map)
2070 self.editActions.append(act)
2071
2072 if hasattr(QsciScintilla, "SCI_MOVESELECTEDLINESUP"):
2073 act = E5Action(
2074 QCoreApplication.translate(
2075 'ViewManager',
2076 'Move selected lines up one line'),
2077 QCoreApplication.translate(
2078 'ViewManager',
2079 'Move selected lines up one line'),
2080 0, 0,
2081 self.editorActGrp, 'vm_edit_move_selection_up_one_line')
2082 self.esm.setMapping(act, QsciScintilla.SCI_MOVESELECTEDLINESUP)
2083 act.triggered.connect(self.esm.map)
2084 self.editActions.append(act)
2085
2086 if hasattr(QsciScintilla, "SCI_MOVESELECTEDLINESDOWN"):
2087 act = E5Action(
2088 QCoreApplication.translate(
2089 'ViewManager',
2090 'Move selected lines down one line'),
2091 QCoreApplication.translate(
2092 'ViewManager',
2093 'Move selected lines down one line'),
2094 0, 0,
2095 self.editorActGrp, 'vm_edit_move_selection_down_one_line')
2096 self.esm.setMapping(act, QsciScintilla.SCI_MOVESELECTEDLINESDOWN)
2097 act.triggered.connect(self.esm.map)
2098 self.editActions.append(act)
2099
2100 act = E5Action(
2101 QCoreApplication.translate(
2102 'ViewManager',
2103 'Duplicate current selection'),
2104 QCoreApplication.translate(
2105 'ViewManager',
2106 'Duplicate current selection'),
2107 QKeySequence(QCoreApplication.translate('ViewManager',
2108 'Ctrl+Shift+D')),
2109 0, self.editorActGrp, 'vm_edit_duplicate_current_selection')
2110 self.esm.setMapping(act, QsciScintilla.SCI_SELECTIONDUPLICATE)
2111 act.triggered.connect(self.esm.map)
2112 self.editActions.append(act)
2113
2114 self.__textEdit.addActions(self.editorActGrp.actions())
2115
2116 def __createSearchActions(self):
2117 """
2118 Private method defining the user interface actions for the search
2119 commands.
2120 """
2121 self.searchAct = E5Action(
2122 QCoreApplication.translate('ViewManager', 'Search'),
2123 UI.PixmapCache.getIcon("find"),
2124 QCoreApplication.translate('ViewManager', '&Search...'),
2125 QKeySequence(QCoreApplication.translate(
2126 'ViewManager', "Ctrl+F", "Search|Search")),
2127 0,
2128 self, 'vm_search')
2129 self.searchAct.setStatusTip(
2130 QCoreApplication.translate('ViewManager', 'Search for a text'))
2131 self.searchAct.setWhatsThis(QCoreApplication.translate(
2132 'ViewManager',
2133 """<b>Search</b>"""
2134 """<p>Search for some text in the current editor. A"""
2135 """ dialog is shown to enter the searchtext and options"""
2136 """ for the search.</p>"""
2137 ))
2138 self.searchAct.triggered.connect(self.showSearchWidget)
2139 self.searchActions.append(self.searchAct)
2140
2141 self.searchNextAct = E5Action(
2142 QCoreApplication.translate('ViewManager', 'Search next'),
2143 UI.PixmapCache.getIcon("findNext"),
2144 QCoreApplication.translate('ViewManager', 'Search &next'),
2145 QKeySequence(QCoreApplication.translate(
2146 'ViewManager', "F3", "Search|Search next")),
2147 0,
2148 self, 'vm_search_next')
2149 self.searchNextAct.setStatusTip(QCoreApplication.translate(
2150 'ViewManager', 'Search next occurrence of text'))
2151 self.searchNextAct.setWhatsThis(QCoreApplication.translate(
2152 'ViewManager',
2153 """<b>Search next</b>"""
2154 """<p>Search the next occurrence of some text in the current"""
2155 """ editor. The previously entered searchtext and options are"""
2156 """ reused.</p>"""
2157 ))
2158 self.searchNextAct.triggered.connect(self.__searchNext)
2159 self.searchActions.append(self.searchNextAct)
2160
2161 self.searchPrevAct = E5Action(
2162 QCoreApplication.translate('ViewManager', 'Search previous'),
2163 UI.PixmapCache.getIcon("findPrev"),
2164 QCoreApplication.translate('ViewManager', 'Search &previous'),
2165 QKeySequence(QCoreApplication.translate(
2166 'ViewManager', "Shift+F3", "Search|Search previous")),
2167 0,
2168 self, 'vm_search_previous')
2169 self.searchPrevAct.setStatusTip(QCoreApplication.translate(
2170 'ViewManager', 'Search previous occurrence of text'))
2171 self.searchPrevAct.setWhatsThis(QCoreApplication.translate(
2172 'ViewManager',
2173 """<b>Search previous</b>"""
2174 """<p>Search the previous occurrence of some text in the"""
2175 """ current editor. The previously entered searchtext and"""
2176 """ options are reused.</p>"""
2177 ))
2178 self.searchPrevAct.triggered.connect(self.__searchPrev)
2179 self.searchActions.append(self.searchPrevAct)
2180
2181 self.searchClearMarkersAct = E5Action(
2182 QCoreApplication.translate('ViewManager',
2183 'Clear search markers'),
2184 UI.PixmapCache.getIcon("findClear"),
2185 QCoreApplication.translate('ViewManager', 'Clear search markers'),
2186 QKeySequence(QCoreApplication.translate(
2187 'ViewManager', "Ctrl+3", "Search|Clear search markers")),
2188 0,
2189 self, 'vm_clear_search_markers')
2190 self.searchClearMarkersAct.setStatusTip(QCoreApplication.translate(
2191 'ViewManager', 'Clear all displayed search markers'))
2192 self.searchClearMarkersAct.setWhatsThis(QCoreApplication.translate(
2193 'ViewManager',
2194 """<b>Clear search markers</b>"""
2195 """<p>Clear all displayed search markers.</p>"""
2196 ))
2197 self.searchClearMarkersAct.triggered.connect(
2198 self.__searchClearMarkers)
2199 self.searchActions.append(self.searchClearMarkersAct)
2200
2201 self.replaceAct = E5Action(
2202 QCoreApplication.translate('ViewManager', 'Replace'),
2203 QCoreApplication.translate('ViewManager', '&Replace...'),
2204 QKeySequence(QCoreApplication.translate(
2205 'ViewManager', "Ctrl+R", "Search|Replace")),
2206 0,
2207 self, 'vm_search_replace')
2208 self.replaceAct.setStatusTip(QCoreApplication.translate(
2209 'ViewManager', 'Replace some text'))
2210 self.replaceAct.setWhatsThis(QCoreApplication.translate(
2211 'ViewManager',
2212 """<b>Replace</b>"""
2213 """<p>Search for some text in the current editor and replace"""
2214 """ it. A dialog is shown to enter the searchtext, the"""
2215 """ replacement text and options for the search and replace.</p>"""
2216 ))
2217 self.replaceAct.triggered.connect(self.showReplaceWidget)
2218 self.searchActions.append(self.replaceAct)
2219
2220 self.replaceAndSearchAct = E5Action(
2221 QCoreApplication.translate(
2222 'ViewManager', 'Replace and Search'),
2223 UI.PixmapCache.getIcon("editReplaceSearch"),
2224 QCoreApplication.translate(
2225 'ViewManager', 'Replace and Search'),
2226 QKeySequence(QCoreApplication.translate(
2227 'ViewManager', "Meta+R", "Search|Replace and Search")),
2228 0,
2229 self, 'vm_replace_search')
2230 self.replaceAndSearchAct.setStatusTip(QCoreApplication.translate(
2231 'ViewManager',
2232 'Replace the found text and search the next occurrence'))
2233 self.replaceAndSearchAct.setWhatsThis(QCoreApplication.translate(
2234 'ViewManager',
2235 """<b>Replace and Search</b>"""
2236 """<p>Replace the found occurrence of text in the current"""
2237 """ editor and search for the next one. The previously entered"""
2238 """ search text and options are reused.</p>"""
2239 ))
2240 self.replaceAndSearchAct.triggered.connect(
2241 self.__replaceWidget.replaceSearch)
2242 self.searchActions.append(self.replaceAndSearchAct)
2243
2244 self.replaceSelectionAct = E5Action(
2245 QCoreApplication.translate(
2246 'ViewManager', 'Replace Occurrence'),
2247 UI.PixmapCache.getIcon("editReplace"),
2248 QCoreApplication.translate(
2249 'ViewManager', 'Replace Occurrence'),
2250 QKeySequence(QCoreApplication.translate(
2251 'ViewManager', "Ctrl+Meta+R", "Search|Replace Occurrence")),
2252 0,
2253 self, 'vm_replace_occurrence')
2254 self.replaceSelectionAct.setStatusTip(QCoreApplication.translate(
2255 'ViewManager', 'Replace the found text'))
2256 self.replaceSelectionAct.setWhatsThis(QCoreApplication.translate(
2257 'ViewManager',
2258 """<b>Replace Occurrence</b>"""
2259 """<p>Replace the found occurrence of the search text in the"""
2260 """ current editor.</p>"""
2261 ))
2262 self.replaceSelectionAct.triggered.connect(
2263 self.__replaceWidget.replace)
2264 self.searchActions.append(self.replaceSelectionAct)
2265
2266 self.replaceAllAct = E5Action(
2267 QCoreApplication.translate(
2268 'ViewManager', 'Replace All'),
2269 UI.PixmapCache.getIcon("editReplaceAll"),
2270 QCoreApplication.translate(
2271 'ViewManager', 'Replace All'),
2272 QKeySequence(QCoreApplication.translate(
2273 'ViewManager', "Shift+Meta+R", "Search|Replace All")),
2274 0,
2275 self, 'vm_replace_all')
2276 self.replaceAllAct.setStatusTip(QCoreApplication.translate(
2277 'ViewManager', 'Replace search text occurrences'))
2278 self.replaceAllAct.setWhatsThis(QCoreApplication.translate(
2279 'ViewManager',
2280 """<b>Replace All</b>"""
2281 """<p>Replace all occurrences of the search text in the current"""
2282 """ editor.</p>"""
2283 ))
2284 self.replaceAllAct.triggered.connect(
2285 self.__replaceWidget.replaceAll)
2286 self.searchActions.append(self.replaceAllAct)
2287
2288 def __createViewActions(self):
2289 """
2290 Private method to create the View actions.
2291 """
2292 self.zoomInAct = E5Action(
2293 QCoreApplication.translate('ViewManager', 'Zoom in'),
2294 UI.PixmapCache.getIcon("zoomIn"),
2295 QCoreApplication.translate('ViewManager', 'Zoom &in'),
2296 QKeySequence(QCoreApplication.translate(
2297 'ViewManager', "Ctrl++", "View|Zoom in")),
2298 QKeySequence(QCoreApplication.translate(
2299 'ViewManager', "Zoom In", "View|Zoom in")),
2300 self, 'vm_view_zoom_in')
2301 self.zoomInAct.setStatusTip(QCoreApplication.translate(
2302 'ViewManager', 'Zoom in on the text'))
2303 self.zoomInAct.setWhatsThis(QCoreApplication.translate(
2304 'ViewManager',
2305 """<b>Zoom in</b>"""
2306 """<p>Zoom in on the text. This makes the text bigger.</p>"""
2307 ))
2308 self.zoomInAct.triggered.connect(self.__zoomIn)
2309 self.viewActions.append(self.zoomInAct)
2310
2311 self.zoomOutAct = E5Action(
2312 QCoreApplication.translate('ViewManager', 'Zoom out'),
2313 UI.PixmapCache.getIcon("zoomOut"),
2314 QCoreApplication.translate('ViewManager', 'Zoom &out'),
2315 QKeySequence(QCoreApplication.translate(
2316 'ViewManager', "Ctrl+-", "View|Zoom out")),
2317 QKeySequence(QCoreApplication.translate(
2318 'ViewManager', "Zoom Out", "View|Zoom out")),
2319 self, 'vm_view_zoom_out')
2320 self.zoomOutAct.setStatusTip(QCoreApplication.translate(
2321 'ViewManager', 'Zoom out on the text'))
2322 self.zoomOutAct.setWhatsThis(QCoreApplication.translate(
2323 'ViewManager',
2324 """<b>Zoom out</b>"""
2325 """<p>Zoom out on the text. This makes the text smaller.</p>"""
2326 ))
2327 self.zoomOutAct.triggered.connect(self.__zoomOut)
2328 self.viewActions.append(self.zoomOutAct)
2329
2330 self.zoomResetAct = E5Action(
2331 QCoreApplication.translate('ViewManager', 'Zoom reset'),
2332 UI.PixmapCache.getIcon("zoomReset"),
2333 QCoreApplication.translate('ViewManager', 'Zoom &reset'),
2334 QKeySequence(QCoreApplication.translate(
2335 'ViewManager', "Ctrl+0", "View|Zoom reset")),
2336 0,
2337 self, 'vm_view_zoom_reset')
2338 self.zoomResetAct.setStatusTip(QCoreApplication.translate(
2339 'ViewManager', 'Reset the zoom of the text'))
2340 self.zoomResetAct.setWhatsThis(QCoreApplication.translate(
2341 'ViewManager',
2342 """<b>Zoom reset</b>"""
2343 """<p>Reset the zoom of the text. """
2344 """This sets the zoom factor to 100%.</p>"""
2345 ))
2346 self.zoomResetAct.triggered.connect(self.__zoomReset)
2347 self.viewActions.append(self.zoomResetAct)
2348
2349 self.zoomToAct = E5Action(
2350 QCoreApplication.translate('ViewManager', 'Zoom'),
2351 UI.PixmapCache.getIcon("zoomTo"),
2352 QCoreApplication.translate('ViewManager', '&Zoom'),
2353 QKeySequence(QCoreApplication.translate(
2354 'ViewManager', "Ctrl+#", "View|Zoom")),
2355 0,
2356 self, 'vm_view_zoom')
2357 self.zoomToAct.setStatusTip(QCoreApplication.translate(
2358 'ViewManager', 'Zoom the text'))
2359 self.zoomToAct.setWhatsThis(QCoreApplication.translate(
2360 'ViewManager',
2361 """<b>Zoom</b>"""
2362 """<p>Zoom the text. This opens a dialog where the"""
2363 """ desired size can be entered.</p>"""
2364 ))
2365 self.zoomToAct.triggered.connect(self.__zoom)
2366 self.viewActions.append(self.zoomToAct)
2367
2368 def __createHelpActions(self):
2369 """
2370 Private method to create the Help actions.
2371 """
2372 self.aboutAct = E5Action(
2373 self.tr('About'),
2374 self.tr('&About'),
2375 0, 0, self, 'about_eric')
2376 self.aboutAct.setStatusTip(self.tr(
2377 'Display information about this software'))
2378 self.aboutAct.setWhatsThis(self.tr(
2379 """<b>About</b>"""
2380 """<p>Display some information about this software.</p>"""))
2381 self.aboutAct.triggered.connect(self.__about)
2382 self.helpActions.append(self.aboutAct)
2383
2384 self.aboutQtAct = E5Action(
2385 self.tr('About Qt'),
2386 self.tr('About &Qt'),
2387 0, 0, self, 'about_qt')
2388 self.aboutQtAct.setStatusTip(
2389 self.tr('Display information about the Qt toolkit'))
2390 self.aboutQtAct.setWhatsThis(self.tr(
2391 """<b>About Qt</b>"""
2392 """<p>Display some information about the Qt toolkit.</p>"""
2393 ))
2394 self.aboutQtAct.triggered.connect(self.__aboutQt)
2395 self.helpActions.append(self.aboutQtAct)
2396
2397 self.whatsThisAct = E5Action(
2398 self.tr('What\'s This?'),
2399 UI.PixmapCache.getIcon("whatsThis"),
2400 self.tr('&What\'s This?'),
2401 QKeySequence(self.tr("Shift+F1", "Help|What's This?'")),
2402 0, self, 'help_help_whats_this')
2403 self.whatsThisAct.setStatusTip(self.tr('Context sensitive help'))
2404 self.whatsThisAct.setWhatsThis(self.tr(
2405 """<b>Display context sensitive help</b>"""
2406 """<p>In What's This? mode, the mouse cursor shows an arrow"""
2407 """ with a question mark, and you can click on the interface"""
2408 """ elements to get a short description of what they do and"""
2409 """ how to use them. In dialogs, this feature can be"""
2410 """ accessed using the context help button in the titlebar."""
2411 """</p>"""
2412 ))
2413 self.whatsThisAct.triggered.connect(self.__whatsThis)
2414 self.helpActions.append(self.whatsThisAct)
2415
2416 def __createMenus(self):
2417 """
2418 Private method to create the menus of the menu bar.
2419 """
2420 self.fileMenu = self.menuBar().addMenu(self.tr("&File"))
2421 self.fileMenu.addAction(self.newAct)
2422 self.fileMenu.addAction(self.openAct)
2423 self.fileMenu.addAction(self.saveAct)
2424 self.fileMenu.addAction(self.saveAsAct)
2425 self.fileMenu.addAction(self.saveCopyAct)
2426 self.fileMenu.addSeparator()
2427 self.fileMenu.addAction(self.printPreviewAct)
2428 self.fileMenu.addAction(self.printAct)
2429 self.fileMenu.addSeparator()
2430 self.fileMenu.addAction(self.closeAct)
2431
2432 self.editMenu = self.menuBar().addMenu(self.tr("&Edit"))
2433 self.editMenu.addAction(self.undoAct)
2434 self.editMenu.addAction(self.redoAct)
2435 self.editMenu.addSeparator()
2436 self.editMenu.addAction(self.cutAct)
2437 self.editMenu.addAction(self.copyAct)
2438 self.editMenu.addAction(self.pasteAct)
2439 self.editMenu.addAction(self.deleteAct)
2440 self.editMenu.addSeparator()
2441 self.editMenu.addAction(self.searchAct)
2442 self.editMenu.addAction(self.searchNextAct)
2443 self.editMenu.addAction(self.searchPrevAct)
2444 self.editMenu.addAction(self.searchClearMarkersAct)
2445 self.editMenu.addAction(self.replaceAct)
2446 self.editMenu.addAction(self.replaceAndSearchAct)
2447 self.editMenu.addAction(self.replaceSelectionAct)
2448 self.editMenu.addAction(self.replaceAllAct)
2449
2450 self.viewMenu = self.menuBar().addMenu(self.tr("&View"))
2451 self.viewMenu.addAction(self.zoomInAct)
2452 self.viewMenu.addAction(self.zoomOutAct)
2453 self.viewMenu.addAction(self.zoomResetAct)
2454 self.viewMenu.addAction(self.zoomToAct)
2455
2456 self.menuBar().addSeparator()
2457
2458 self.helpMenu = self.menuBar().addMenu(self.tr("&Help"))
2459 self.helpMenu.addAction(self.aboutAct)
2460 self.helpMenu.addAction(self.aboutQtAct)
2461 self.helpMenu.addSeparator()
2462 self.helpMenu.addAction(self.whatsThisAct)
2463
2464 self.__initContextMenu()
2465
2466 def __createToolBars(self):
2467 """
2468 Private method to create the various toolbars.
2469 """
2470 filetb = self.addToolBar(self.tr("File"))
2471 filetb.setIconSize(UI.Config.ToolBarIconSize)
2472 filetb.addAction(self.newAct)
2473 filetb.addAction(self.openAct)
2474 filetb.addAction(self.saveAct)
2475 filetb.addAction(self.saveAsAct)
2476 filetb.addAction(self.saveCopyAct)
2477 filetb.addSeparator()
2478 filetb.addAction(self.printPreviewAct)
2479 filetb.addAction(self.printAct)
2480 filetb.addSeparator()
2481 filetb.addAction(self.closeAct)
2482
2483 edittb = self.addToolBar(self.tr("Edit"))
2484 edittb.setIconSize(UI.Config.ToolBarIconSize)
2485 edittb.addAction(self.undoAct)
2486 edittb.addAction(self.redoAct)
2487 edittb.addSeparator()
2488 edittb.addAction(self.cutAct)
2489 edittb.addAction(self.copyAct)
2490 edittb.addAction(self.pasteAct)
2491 edittb.addAction(self.deleteAct)
2492
2493 findtb = self.addToolBar(self.tr("Find"))
2494 findtb.setIconSize(UI.Config.ToolBarIconSize)
2495 findtb.addAction(self.searchAct)
2496 findtb.addAction(self.searchNextAct)
2497 findtb.addAction(self.searchPrevAct)
2498 findtb.addAction(self.searchClearMarkersAct)
2499
2500 viewtb = self.addToolBar(self.tr("View"))
2501 viewtb.setIconSize(UI.Config.ToolBarIconSize)
2502 viewtb.addAction(self.zoomInAct)
2503 viewtb.addAction(self.zoomOutAct)
2504 viewtb.addAction(self.zoomResetAct)
2505 viewtb.addAction(self.zoomToAct)
2506
2507 helptb = self.addToolBar(self.tr("Help"))
2508 helptb.setIconSize(UI.Config.ToolBarIconSize)
2509 helptb.addAction(self.whatsThisAct)
2510
2511 def __createStatusBar(self):
2512 """
2513 Private method to initialize the status bar.
2514 """
2515 self.__statusBar = self.statusBar()
2516 self.__statusBar.setSizeGripEnabled(True)
2517
2518 self.sbLanguage = E5ClickableLabel(self.__statusBar)
2519 self.__statusBar.addPermanentWidget(self.sbLanguage)
2520 self.sbLanguage.setWhatsThis(self.tr(
2521 """<p>This part of the status bar displays the"""
2522 """ editor language.</p>"""
2523 ))
2524 self.sbLanguage.clicked.connect(self.__showLanguagesMenu)
2525
2526 self.sbWritable = QLabel(self.__statusBar)
2527 self.__statusBar.addPermanentWidget(self.sbWritable)
2528 self.sbWritable.setWhatsThis(self.tr(
2529 """<p>This part of the status bar displays an indication of the"""
2530 """ editors files writability.</p>"""
2531 ))
2532
2533 self.sbLine = QLabel(self.__statusBar)
2534 self.__statusBar.addPermanentWidget(self.sbLine)
2535 self.sbLine.setWhatsThis(self.tr(
2536 """<p>This part of the status bar displays the line number of"""
2537 """ the editor.</p>"""
2538 ))
2539
2540 self.sbPos = QLabel(self.__statusBar)
2541 self.__statusBar.addPermanentWidget(self.sbPos)
2542 self.sbPos.setWhatsThis(self.tr(
2543 """<p>This part of the status bar displays the cursor position"""
2544 """ of the editor.</p>"""
2545 ))
2546
2547 self.sbZoom = E5ZoomWidget(
2548 UI.PixmapCache.getPixmap("zoomOut"),
2549 UI.PixmapCache.getPixmap("zoomIn"),
2550 UI.PixmapCache.getPixmap("zoomReset"),
2551 self.__statusBar)
2552 self.__statusBar.addPermanentWidget(self.sbZoom)
2553 self.sbZoom.setWhatsThis(self.tr(
2554 """<p>This part of the status bar allows zooming the editor."""
2555 """</p>"""
2556 ))
2557 self.sbZoom.valueChanged.connect(self.__zoomTo)
2558
2559 self.__statusBar.showMessage(self.tr("Ready"))
2560
2561 def __readSettings(self):
2562 """
2563 Private method to read the settings remembered last time.
2564 """
2565 settings = Preferences.Prefs.settings
2566 pos = settings.value("MiniEditor/Position", QPoint(0, 0))
2567 size = settings.value("MiniEditor/Size", QSize(800, 600))
2568 self.resize(size)
2569 self.move(pos)
2570
2571 def __writeSettings(self):
2572 """
2573 Private method to write the settings for reuse.
2574 """
2575 settings = Preferences.Prefs.settings
2576 settings.setValue("MiniEditor/Position", self.pos())
2577 settings.setValue("MiniEditor/Size", self.size())
2578
2579 def __maybeSave(self):
2580 """
2581 Private method to ask the user to save the file, if it was modified.
2582
2583 @return flag indicating, if it is ok to continue (boolean)
2584 """
2585 if self.__textEdit.isModified():
2586 ret = E5MessageBox.okToClearData(
2587 self,
2588 self.tr("eric Mini Editor"),
2589 self.tr("The document has unsaved changes."),
2590 self.__save)
2591 return ret
2592 return True
2593
2594 def __loadFile(self, fileName, filetype=None):
2595 """
2596 Private method to load the given file.
2597
2598 @param fileName name of the file to load (string)
2599 @param filetype type of the source file (string)
2600 """
2601 self.__loadEditorConfig(fileName=fileName)
2602
2603 try:
2604 with E5OverrideCursor():
2605 encoding = self.__getEditorConfig("DefaultEncoding",
2606 nodefault=True)
2607 if encoding:
2608 txt, self.encoding = Utilities.readEncodedFileWithEncoding(
2609 fileName, encoding)
2610 else:
2611 txt, self.encoding = Utilities.readEncodedFile(fileName)
2612 except (UnicodeDecodeError, OSError) as why:
2613 E5MessageBox.critical(
2614 self, self.tr('Open File'),
2615 self.tr('<p>The file <b>{0}</b> could not be opened.</p>'
2616 '<p>Reason: {1}</p>')
2617 .format(fileName, str(why)))
2618 return
2619
2620 with E5OverrideCursor():
2621 self.__textEdit.setText(txt)
2622
2623 if filetype is None:
2624 self.filetype = ""
2625 else:
2626 self.filetype = filetype
2627 self.__setCurrentFile(fileName)
2628
2629 self.__textEdit.setModified(False)
2630 self.setWindowModified(False)
2631
2632 self.__convertTabs()
2633
2634 eolMode = self.__getEditorConfig("EOLMode", nodefault=True)
2635 if eolMode is None:
2636 fileEol = self.__textEdit.detectEolString(txt)
2637 self.__textEdit.setEolModeByEolString(fileEol)
2638 else:
2639 self.__textEdit.convertEols(eolMode)
2640
2641 self.__statusBar.showMessage(self.tr("File loaded"), 2000)
2642
2643 def __convertTabs(self):
2644 """
2645 Private slot to convert tabulators to spaces.
2646 """
2647 if (
2648 (not self.__getEditorConfig("TabForIndentation")) and
2649 Preferences.getEditor("ConvertTabsOnLoad") and
2650 not (self.lexer_ and
2651 self.lexer_.alwaysKeepTabs())
2652 ):
2653 txt = self.__textEdit.text()
2654 txtExpanded = txt.expandtabs(self.__getEditorConfig("TabWidth"))
2655 if txtExpanded != txt:
2656 self.__textEdit.beginUndoAction()
2657 self.__textEdit.setText(txt)
2658 self.__textEdit.endUndoAction()
2659
2660 self.__textEdit.setModified(True)
2661 self.setWindowModified(True)
2662
2663 def __saveFile(self, fileName):
2664 """
2665 Private method to save to the given file.
2666
2667 @param fileName name of the file to save to
2668 @type str
2669 @return flag indicating success
2670 @rtype bool
2671 """
2672 res = self.__writeFile(fileName)
2673
2674 if res:
2675 self.editorSaved.emit()
2676 self.__setCurrentFile(fileName)
2677
2678 self.__checkActions()
2679
2680 return res
2681
2682 def __writeFile(self, fileName):
2683 """
2684 Private method to write the current editor text to a file.
2685
2686 @param fileName name of the file to be written to
2687 @type str
2688 @return flag indicating success
2689 @rtype bool
2690 """
2691 config = self.__loadEditorConfigObject(fileName)
2692
2693 eol = self.__getEditorConfig("EOLMode", nodefault=True, config=config)
2694 if eol is not None:
2695 self.__textEdit.convertEols(eol)
2696
2697 if self.__getEditorConfig("StripTrailingWhitespace", config=config):
2698 self.__textEdit.removeTrailingWhitespace()
2699
2700 txt = self.__textEdit.text()
2701
2702 if self.__getEditorConfig("InsertFinalNewline", config=config):
2703 eol = self.__textEdit.getLineSeparator()
2704 if eol:
2705 if len(txt) >= len(eol):
2706 if txt[-len(eol):] != eol:
2707 txt += eol
2708 else:
2709 txt += eol
2710
2711 # now write text to the file
2712 try:
2713 with E5OverrideCursor():
2714 editorConfigEncoding = self.__getEditorConfig(
2715 "DefaultEncoding", nodefault=True, config=config)
2716 self.encoding = Utilities.writeEncodedFile(
2717 fileName, txt, self.encoding,
2718 forcedEncoding=editorConfigEncoding)
2719 except (OSError, Utilities.CodingError, UnicodeError) as why:
2720 E5MessageBox.critical(
2721 self, self.tr('Save File'),
2722 self.tr('<p>The file <b>{0}</b> could not be saved.<br/>'
2723 'Reason: {1}</p>')
2724 .format(fileName, str(why)))
2725 return False
2726
2727 self.__statusBar.showMessage(self.tr("File saved"), 2000)
2728
2729 return True
2730
2731 def setWindowModified(self, modified):
2732 """
2733 Public method to set the window modification status.
2734
2735 @param modified flag indicating the modification status
2736 @type bool
2737 """
2738 if "[*]" not in self.windowTitle():
2739 self.setWindowTitle(self.tr("[*] - {0}")
2740 .format(self.tr("Mini Editor")))
2741 super().setWindowModified(modified)
2742
2743 def __setCurrentFile(self, fileName):
2744 """
2745 Private method to register the file name of the current file.
2746
2747 @param fileName name of the file to register (string)
2748 """
2749 self.__curFile = fileName
2750
2751 shownName = (
2752 self.tr("Untitled")
2753 if not self.__curFile else
2754 self.__strippedName(self.__curFile)
2755 )
2756
2757 self.setWindowTitle(self.tr("{0}[*] - {1}")
2758 .format(shownName, self.tr("Mini Editor")))
2759
2760 self.__textEdit.setModified(False)
2761 self.setWindowModified(False)
2762
2763 self.setLanguage(self.__bindName(self.__textEdit.text(0)))
2764
2765 self.__loadEditorConfig()
2766
2767 def getFileName(self):
2768 """
2769 Public method to return the name of the file being displayed.
2770
2771 @return filename of the displayed file (string)
2772 """
2773 return self.__curFile
2774
2775 def __strippedName(self, fullFileName):
2776 """
2777 Private method to return the filename part of the given path.
2778
2779 @param fullFileName full pathname of the given file (string)
2780 @return filename part (string)
2781 """
2782 return QFileInfo(fullFileName).fileName()
2783
2784 def __modificationChanged(self, m):
2785 """
2786 Private slot to handle the modificationChanged signal.
2787
2788 @param m modification status
2789 """
2790 self.setWindowModified(m)
2791 self.__checkActions()
2792
2793 def __cursorPositionChanged(self, line, pos):
2794 """
2795 Private slot to handle the cursorPositionChanged signal.
2796
2797 @param line line number of the cursor
2798 @param pos position in line of the cursor
2799 """
2800 lang = self.getLanguage()
2801 self.__setSbFile(line + 1, pos, lang)
2802
2803 if Preferences.getEditor("MarkOccurrencesEnabled"):
2804 self.__markOccurrencesTimer.stop()
2805 self.__markOccurrencesTimer.start()
2806
2807 if self.__lastLine != line:
2808 self.cursorLineChanged.emit(line)
2809 self.__lastLine = line
2810
2811 def __undo(self):
2812 """
2813 Private method to undo the last recorded change.
2814 """
2815 self.__textEdit.undo()
2816 self.__checkActions()
2817
2818 def __redo(self):
2819 """
2820 Private method to redo the last recorded change.
2821 """
2822 self.__textEdit.redo()
2823 self.__checkActions()
2824
2825 def __selectAll(self):
2826 """
2827 Private slot handling the select all context menu action.
2828 """
2829 self.__textEdit.selectAll(True)
2830
2831 def __deselectAll(self):
2832 """
2833 Private slot handling the deselect all context menu action.
2834 """
2835 self.__textEdit.selectAll(False)
2836
2837 def __setMargins(self):
2838 """
2839 Private method to configure the margins.
2840 """
2841 # set the settings for all margins
2842 self.__textEdit.setMarginsFont(
2843 Preferences.getEditorOtherFonts("MarginsFont"))
2844 self.__textEdit.setMarginsForegroundColor(
2845 Preferences.getEditorColour("MarginsForeground"))
2846 self.__textEdit.setMarginsBackgroundColor(
2847 Preferences.getEditorColour("MarginsBackground"))
2848
2849 # set margin 0 settings
2850 linenoMargin = Preferences.getEditor("LinenoMargin")
2851 self.__textEdit.setMarginLineNumbers(0, linenoMargin)
2852 if linenoMargin:
2853 self.__resizeLinenoMargin()
2854 else:
2855 self.__textEdit.setMarginWidth(0, 16)
2856
2857 # set margin 1 settings
2858 self.__textEdit.setMarginWidth(1, 0)
2859
2860 # set margin 2 settings
2861 self.__textEdit.setMarginWidth(2, 16)
2862 if Preferences.getEditor("FoldingMargin"):
2863 folding = Preferences.getEditor("FoldingStyle")
2864 with contextlib.suppress(AttributeError):
2865 folding = QsciScintilla.FoldStyle(folding)
2866 self.__textEdit.setFolding(folding)
2867 self.__textEdit.setFoldMarginColors(
2868 Preferences.getEditorColour("FoldmarginBackground"),
2869 Preferences.getEditorColour("FoldmarginBackground"))
2870 self.__textEdit.setFoldMarkersColors(
2871 Preferences.getEditorColour("FoldMarkersForeground"),
2872 Preferences.getEditorColour("FoldMarkersBackground"))
2873 else:
2874 self.__textEdit.setFolding(QsciScintilla.FoldStyle.NoFoldStyle)
2875
2876 def __resizeLinenoMargin(self):
2877 """
2878 Private slot to resize the line numbers margin.
2879 """
2880 linenoMargin = Preferences.getEditor("LinenoMargin")
2881 if linenoMargin:
2882 self.__textEdit.setMarginWidth(
2883 0, '8' * (len(str(self.__textEdit.lines())) + 1))
2884
2885 def __setTabAndIndent(self):
2886 """
2887 Private method to set indentation size and style and tab width.
2888 """
2889 self.__textEdit.setTabWidth(self.__getEditorConfig("TabWidth"))
2890 self.__textEdit.setIndentationWidth(
2891 self.__getEditorConfig("IndentWidth"))
2892 if self.lexer_ and self.lexer_.alwaysKeepTabs():
2893 self.__textEdit.setIndentationsUseTabs(True)
2894 else:
2895 self.__textEdit.setIndentationsUseTabs(
2896 self.__getEditorConfig("TabForIndentation"))
2897
2898 def __setTextDisplay(self):
2899 """
2900 Private method to configure the text display.
2901 """
2902 self.__setTabAndIndent()
2903
2904 self.__textEdit.setTabIndents(Preferences.getEditor("TabIndents"))
2905 self.__textEdit.setBackspaceUnindents(
2906 Preferences.getEditor("TabIndents"))
2907 self.__textEdit.setIndentationGuides(
2908 Preferences.getEditor("IndentationGuides"))
2909 self.__textEdit.setIndentationGuidesBackgroundColor(
2910 Preferences.getEditorColour("IndentationGuidesBackground"))
2911 self.__textEdit.setIndentationGuidesForegroundColor(
2912 Preferences.getEditorColour("IndentationGuidesForeground"))
2913 if Preferences.getEditor("ShowWhitespace"):
2914 self.__textEdit.setWhitespaceVisibility(
2915 QsciScintilla.WhitespaceVisibility.WsVisible)
2916 self.__textEdit.setWhitespaceForegroundColor(
2917 Preferences.getEditorColour("WhitespaceForeground"))
2918 self.__textEdit.setWhitespaceBackgroundColor(
2919 Preferences.getEditorColour("WhitespaceBackground"))
2920 self.__textEdit.setWhitespaceSize(
2921 Preferences.getEditor("WhitespaceSize"))
2922 else:
2923 self.__textEdit.setWhitespaceVisibility(
2924 QsciScintilla.WhitespaceVisibility.WsInvisible)
2925 self.__textEdit.setEolVisibility(Preferences.getEditor("ShowEOL"))
2926 self.__textEdit.setAutoIndent(Preferences.getEditor("AutoIndentation"))
2927 if Preferences.getEditor("BraceHighlighting"):
2928 self.__textEdit.setBraceMatching(
2929 QsciScintilla.BraceMatch.SloppyBraceMatch)
2930 else:
2931 self.__textEdit.setBraceMatching(
2932 QsciScintilla.BraceMatch.NoBraceMatch)
2933 self.__textEdit.setMatchedBraceForegroundColor(
2934 Preferences.getEditorColour("MatchingBrace"))
2935 self.__textEdit.setMatchedBraceBackgroundColor(
2936 Preferences.getEditorColour("MatchingBraceBack"))
2937 self.__textEdit.setUnmatchedBraceForegroundColor(
2938 Preferences.getEditorColour("NonmatchingBrace"))
2939 self.__textEdit.setUnmatchedBraceBackgroundColor(
2940 Preferences.getEditorColour("NonmatchingBraceBack"))
2941 if Preferences.getEditor("CustomSelectionColours"):
2942 self.__textEdit.setSelectionBackgroundColor(
2943 Preferences.getEditorColour("SelectionBackground"))
2944 else:
2945 self.__textEdit.setSelectionBackgroundColor(
2946 QApplication.palette().color(QPalette.ColorRole.Highlight))
2947 if Preferences.getEditor("ColourizeSelText"):
2948 self.__textEdit.resetSelectionForegroundColor()
2949 elif Preferences.getEditor("CustomSelectionColours"):
2950 self.__textEdit.setSelectionForegroundColor(
2951 Preferences.getEditorColour("SelectionForeground"))
2952 else:
2953 self.__textEdit.setSelectionForegroundColor(
2954 QApplication.palette().color(
2955 QPalette.ColorRole.HighlightedText))
2956 self.__textEdit.setSelectionToEol(
2957 Preferences.getEditor("ExtendSelectionToEol"))
2958 self.__textEdit.setCaretForegroundColor(
2959 Preferences.getEditorColour("CaretForeground"))
2960 self.__textEdit.setCaretLineBackgroundColor(
2961 Preferences.getEditorColour("CaretLineBackground"))
2962 self.__textEdit.setCaretLineVisible(
2963 Preferences.getEditor("CaretLineVisible"))
2964 self.__textEdit.setCaretLineAlwaysVisible(
2965 Preferences.getEditor("CaretLineAlwaysVisible"))
2966 self.caretWidth = Preferences.getEditor("CaretWidth")
2967 self.__textEdit.setCaretWidth(self.caretWidth)
2968 self.caretLineFrameWidth = Preferences.getEditor("CaretLineFrameWidth")
2969 self.__textEdit.setCaretLineFrameWidth(self.caretLineFrameWidth)
2970 self.useMonospaced = Preferences.getEditor("UseMonospacedFont")
2971 self.__setMonospaced(self.useMonospaced)
2972 edgeMode = Preferences.getEditor("EdgeMode")
2973 edge = QsciScintilla.EdgeMode(edgeMode)
2974 self.__textEdit.setEdgeMode(edge)
2975 if edgeMode:
2976 self.__textEdit.setEdgeColumn(Preferences.getEditor("EdgeColumn"))
2977 self.__textEdit.setEdgeColor(Preferences.getEditorColour("Edge"))
2978
2979 wrapVisualFlag = Preferences.getEditor("WrapVisualFlag")
2980 self.__textEdit.setWrapMode(Preferences.getEditor("WrapLongLinesMode"))
2981 self.__textEdit.setWrapVisualFlags(wrapVisualFlag, wrapVisualFlag)
2982 self.__textEdit.setWrapIndentMode(
2983 Preferences.getEditor("WrapIndentMode"))
2984 self.__textEdit.setWrapStartIndent(
2985 Preferences.getEditor("WrapStartIndent"))
2986
2987 self.searchIndicator = QsciScintilla.INDIC_CONTAINER
2988 self.__textEdit.indicatorDefine(
2989 self.searchIndicator, QsciScintilla.INDIC_BOX,
2990 Preferences.getEditorColour("SearchMarkers"))
2991
2992 self.__textEdit.setCursorFlashTime(QApplication.cursorFlashTime())
2993
2994 if Preferences.getEditor("OverrideEditAreaColours"):
2995 self.__textEdit.setColor(
2996 Preferences.getEditorColour("EditAreaForeground"))
2997 self.__textEdit.setPaper(
2998 Preferences.getEditorColour("EditAreaBackground"))
2999
3000 self.__textEdit.setVirtualSpaceOptions(
3001 Preferences.getEditor("VirtualSpaceOptions"))
3002
3003 # to avoid errors due to line endings by pasting
3004 self.__textEdit.SendScintilla(
3005 QsciScintilla.SCI_SETPASTECONVERTENDINGS, True)
3006
3007 def __setEolMode(self):
3008 """
3009 Private method to configure the eol mode of the editor.
3010 """
3011 eolMode = self.__getEditorConfig("EOLMode")
3012 eolMode = QsciScintilla.EolMode(eolMode)
3013 self.__textEdit.setEolMode(eolMode)
3014
3015 def __setMonospaced(self, on):
3016 """
3017 Private method to set/reset a monospaced font.
3018
3019 @param on flag to indicate usage of a monospace font (boolean)
3020 """
3021 if on:
3022 if not self.lexer_:
3023 f = Preferences.getEditorOtherFonts("MonospacedFont")
3024 self.__textEdit.monospacedStyles(f)
3025 else:
3026 if not self.lexer_:
3027 self.__textEdit.clearStyles()
3028 self.__setMargins()
3029 self.__textEdit.setFont(
3030 Preferences.getEditorOtherFonts("DefaultFont"))
3031
3032 self.useMonospaced = on
3033
3034 def __printFile(self):
3035 """
3036 Private slot to print the text.
3037 """
3038 from .Printer import Printer
3039 printer = Printer(mode=QPrinter.PrinterMode.HighResolution)
3040 sb = self.statusBar()
3041 printDialog = QPrintDialog(printer, self)
3042 if self.__textEdit.hasSelectedText():
3043 printDialog.setOption(
3044 QAbstractPrintDialog.PrintDialogOption.PrintSelection,
3045 True)
3046 if printDialog.exec() == QDialog.DialogCode.Accepted:
3047 sb.showMessage(self.tr('Printing...'))
3048 QApplication.processEvents()
3049 if self.__curFile:
3050 printer.setDocName(QFileInfo(self.__curFile).fileName())
3051 else:
3052 printer.setDocName(self.tr("Untitled"))
3053 if (
3054 printDialog.printRange() ==
3055 QAbstractPrintDialog.PrintRange.Selection
3056 ):
3057 # get the selection
3058 fromLine, fromIndex, toLine, toIndex = (
3059 self.__textEdit.getSelection()
3060 )
3061 if toIndex == 0:
3062 toLine -= 1
3063 # QScintilla seems to print one line more than told
3064 res = printer.printRange(self.__textEdit, fromLine, toLine - 1)
3065 else:
3066 res = printer.printRange(self.__textEdit)
3067 if res:
3068 sb.showMessage(self.tr('Printing completed'), 2000)
3069 else:
3070 sb.showMessage(self.tr('Error while printing'), 2000)
3071 QApplication.processEvents()
3072 else:
3073 sb.showMessage(self.tr('Printing aborted'), 2000)
3074 QApplication.processEvents()
3075
3076 def __printPreviewFile(self):
3077 """
3078 Private slot to show a print preview of the text.
3079 """
3080 from PyQt5.QtPrintSupport import QPrintPreviewDialog
3081 from .Printer import Printer
3082
3083 printer = Printer(mode=QPrinter.PrinterMode.HighResolution)
3084 if self.__curFile:
3085 printer.setDocName(QFileInfo(self.__curFile).fileName())
3086 else:
3087 printer.setDocName(self.tr("Untitled"))
3088 preview = QPrintPreviewDialog(printer, self)
3089 preview.paintRequested.connect(self.__printPreview)
3090 preview.exec()
3091
3092 def __printPreview(self, printer):
3093 """
3094 Private slot to generate a print preview.
3095
3096 @param printer reference to the printer object
3097 (QScintilla.Printer.Printer)
3098 """
3099 printer.printRange(self.__textEdit)
3100
3101 #########################################################
3102 ## Methods needed by the context menu
3103 #########################################################
3104
3105 def __contextMenuRequested(self, coord):
3106 """
3107 Private slot to show the context menu.
3108
3109 @param coord the position of the mouse pointer (QPoint)
3110 """
3111 self.contextMenu.popup(self.mapToGlobal(coord))
3112
3113 def __initContextMenu(self):
3114 """
3115 Private method used to setup the context menu.
3116 """
3117 self.contextMenu = QMenu()
3118
3119 self.languagesMenu = self.__initContextMenuLanguages()
3120
3121 self.contextMenu.addAction(self.undoAct)
3122 self.contextMenu.addAction(self.redoAct)
3123 self.contextMenu.addSeparator()
3124 self.contextMenu.addAction(self.cutAct)
3125 self.contextMenu.addAction(self.copyAct)
3126 self.contextMenu.addAction(self.pasteAct)
3127 self.contextMenu.addSeparator()
3128 self.contextMenu.addAction(self.tr('Select all'), self.__selectAll)
3129 self.contextMenu.addAction(
3130 self.tr('Deselect all'), self.__deselectAll)
3131 self.contextMenu.addSeparator()
3132 self.languagesMenuAct = self.contextMenu.addMenu(self.languagesMenu)
3133 self.contextMenu.addSeparator()
3134 self.contextMenu.addAction(self.printPreviewAct)
3135 self.contextMenu.addAction(self.printAct)
3136
3137 def __initContextMenuLanguages(self):
3138 """
3139 Private method used to setup the Languages context sub menu.
3140
3141 @return reference to the generated menu (QMenu)
3142 """
3143 menu = QMenu(self.tr("Languages"))
3144
3145 self.languagesActGrp = QActionGroup(self)
3146 self.noLanguageAct = menu.addAction(self.tr("No Language"))
3147 self.noLanguageAct.setCheckable(True)
3148 self.noLanguageAct.setData("None")
3149 self.languagesActGrp.addAction(self.noLanguageAct)
3150 menu.addSeparator()
3151
3152 from . import Lexers
3153 self.supportedLanguages = {}
3154 supportedLanguages = Lexers.getSupportedLanguages()
3155 languages = sorted(list(supportedLanguages.keys()))
3156 for language in languages:
3157 if language != "Guessed":
3158 self.supportedLanguages[language] = (
3159 supportedLanguages[language][:2]
3160 )
3161 act = menu.addAction(
3162 UI.PixmapCache.getIcon(supportedLanguages[language][2]),
3163 self.supportedLanguages[language][0])
3164 act.setCheckable(True)
3165 act.setData(language)
3166 self.supportedLanguages[language].append(act)
3167 self.languagesActGrp.addAction(act)
3168
3169 menu.addSeparator()
3170 self.pygmentsAct = menu.addAction(self.tr("Guessed"))
3171 self.pygmentsAct.setCheckable(True)
3172 self.pygmentsAct.setData("Guessed")
3173 self.languagesActGrp.addAction(self.pygmentsAct)
3174 self.pygmentsSelAct = menu.addAction(self.tr("Alternatives"))
3175 self.pygmentsSelAct.setData("Alternatives")
3176
3177 menu.triggered.connect(self.__languageMenuTriggered)
3178 menu.aboutToShow.connect(self.__showContextMenuLanguages)
3179
3180 return menu
3181
3182 def __showContextMenuLanguages(self):
3183 """
3184 Private slot handling the aboutToShow signal of the languages context
3185 menu.
3186 """
3187 if self.apiLanguage.startswith("Pygments|"):
3188 self.pygmentsSelAct.setText(
3189 self.tr("Alternatives ({0})").format(
3190 self.getLanguage(normalized=False)))
3191 else:
3192 self.pygmentsSelAct.setText(self.tr("Alternatives"))
3193
3194 def __showLanguagesMenu(self, pos):
3195 """
3196 Private slot to show the Languages menu of the status bar.
3197
3198 @param pos position the menu should be shown at (QPoint)
3199 """
3200 self.languagesMenu.exec(pos)
3201
3202 def __selectPygmentsLexer(self):
3203 """
3204 Private method to select a specific pygments lexer.
3205
3206 @return name of the selected pygments lexer
3207 @rtype str
3208 """
3209 from pygments.lexers import get_all_lexers
3210 lexerList = sorted(lex[0] for lex in get_all_lexers())
3211 try:
3212 lexerSel = lexerList.index(
3213 self.getLanguage(normalized=False, forPygments=True))
3214 except ValueError:
3215 lexerSel = 0
3216 lexerName, ok = QInputDialog.getItem(
3217 self,
3218 self.tr("Pygments Lexer"),
3219 self.tr("Select the Pygments lexer to apply."),
3220 lexerList,
3221 lexerSel,
3222 False)
3223 if ok and lexerName:
3224 return lexerName
3225 else:
3226 return ""
3227
3228 def __languageMenuTriggered(self, act):
3229 """
3230 Private method to handle the selection of a lexer language.
3231
3232 @param act reference to the action that was triggered (QAction)
3233 """
3234 if act == self.noLanguageAct:
3235 self.__resetLanguage()
3236 elif act == self.pygmentsAct:
3237 self.setLanguage("dummy.pygments")
3238 elif act == self.pygmentsSelAct:
3239 language = self.__selectPygmentsLexer()
3240 if language:
3241 self.setLanguage("dummy.pygments", pyname=language)
3242 else:
3243 language = act.data()
3244 if language:
3245 self.setLanguage(self.supportedLanguages[language][1])
3246
3247 def __resetLanguage(self):
3248 """
3249 Private method used to reset the language selection.
3250 """
3251 if (
3252 self.lexer_ is not None and
3253 (self.lexer_.lexer() == "container" or
3254 self.lexer_.lexer() is None)
3255 ):
3256 self.__textEdit.SCN_STYLENEEDED.disconnect(self.__styleNeeded)
3257
3258 self.apiLanguage = ""
3259 self.lexer_ = None
3260 self.__textEdit.setLexer()
3261 self.__setMonospaced(self.useMonospaced)
3262
3263 if Preferences.getEditor("OverrideEditAreaColours"):
3264 self.__textEdit.setColor(
3265 Preferences.getEditorColour("EditAreaForeground"))
3266 self.__textEdit.setPaper(
3267 Preferences.getEditorColour("EditAreaBackground"))
3268
3269 self.languageChanged.emit(self.apiLanguage)
3270
3271 def setLanguage(self, filename, initTextDisplay=True, pyname=""):
3272 """
3273 Public method to set a lexer language.
3274
3275 @param filename filename used to determine the associated lexer
3276 language (string)
3277 @param initTextDisplay flag indicating an initialization of the text
3278 display is required as well (boolean)
3279 @param pyname name of the pygments lexer to use (string)
3280 """
3281 self.__bindLexer(filename, pyname=pyname)
3282 self.__textEdit.recolor()
3283 self.__checkLanguage()
3284
3285 # set the text display
3286 if initTextDisplay:
3287 self.__setTextDisplay()
3288 self.__setMargins()
3289
3290 self.languageChanged.emit(self.apiLanguage)
3291
3292 def getLanguage(self, normalized=True, forPygments=False):
3293 """
3294 Public method to retrieve the language of the editor.
3295
3296 @param normalized flag indicating to normalize some Pygments
3297 lexer names
3298 @type bool
3299 @param forPygments flag indicating to normalize some lexer
3300 names for Pygments
3301 @type bool
3302 @return language of the editor
3303 @rtype str
3304 """
3305 if (
3306 self.apiLanguage == "Guessed" or
3307 self.apiLanguage.startswith("Pygments|")
3308 ):
3309 lang = self.lexer_.name()
3310 if normalized:
3311 # adjust some Pygments lexer names
3312 if lang in ("Python 2.x", "Python"):
3313 lang = "Python3"
3314 elif lang == "Protocol Buffer":
3315 lang = "Protocol"
3316
3317 else:
3318 lang = self.apiLanguage
3319 if forPygments:
3320 # adjust some names to Pygments lexer names
3321 if lang == "Python3":
3322 lang = "Python"
3323 elif lang == "Protocol":
3324 lang = "Protocol Buffer"
3325 return lang
3326
3327 def __checkLanguage(self):
3328 """
3329 Private method to check the selected language of the language submenu.
3330 """
3331 if self.apiLanguage == "":
3332 self.noLanguageAct.setChecked(True)
3333 elif self.apiLanguage == "Guessed":
3334 self.pygmentsAct.setChecked(True)
3335 elif self.apiLanguage.startswith("Pygments|"):
3336 act = self.languagesActGrp.checkedAction()
3337 if act:
3338 act.setChecked(False)
3339 else:
3340 self.supportedLanguages[self.apiLanguage][2].setChecked(True)
3341
3342 def __bindLexer(self, filename, pyname=""):
3343 """
3344 Private slot to set the correct lexer depending on language.
3345
3346 @param filename filename used to determine the associated lexer
3347 language (string)
3348 @param pyname name of the pygments lexer to use (string)
3349 """
3350 if (
3351 self.lexer_ is not None and
3352 (self.lexer_.lexer() == "container" or
3353 self.lexer_.lexer() is None)
3354 ):
3355 self.__textEdit.SCN_STYLENEEDED.disconnect(self.__styleNeeded)
3356
3357 filename = os.path.basename(filename)
3358 language = Preferences.getEditorLexerAssoc(filename)
3359 if language == "Python":
3360 language = "Python3"
3361 if language.startswith("Pygments|"):
3362 pyname = language.split("|", 1)[1]
3363 language = ""
3364
3365 if not self.filetype:
3366 if not language and pyname:
3367 self.filetype = pyname
3368 else:
3369 self.filetype = language
3370
3371 from . import Lexers
3372 self.lexer_ = Lexers.getLexer(language, self.__textEdit, pyname=pyname)
3373 if self.lexer_ is None:
3374 self.__textEdit.setLexer()
3375 self.apiLanguage = ""
3376 return
3377
3378 if pyname:
3379 if pyname.startswith("Pygments|"):
3380 self.apiLanguage = pyname
3381 else:
3382 self.apiLanguage = "Pygments|{0}".format(pyname)
3383 else:
3384 if language == "Protocol":
3385 self.apiLanguage = language
3386 else:
3387 # Change API language for lexer where QScintilla reports
3388 # an abbreviated name.
3389 self.apiLanguage = self.lexer_.language()
3390 if self.apiLanguage == "POV":
3391 self.apiLanguage = "Povray"
3392 elif self.apiLanguage == "PO":
3393 self.apiLanguage = "Gettext"
3394 self.__textEdit.setLexer(self.lexer_)
3395 if self.lexer_.lexer() == "container" or self.lexer_.lexer() is None:
3396 self.__textEdit.SCN_STYLENEEDED.connect(self.__styleNeeded)
3397
3398 # get the font for style 0 and set it as the default font
3399 key = (
3400 'Scintilla/Guessed/style0/font'
3401 if pyname and pyname.startswith("Pygments|") else
3402 'Scintilla/{0}/style0/font'.format(self.lexer_.language())
3403 )
3404 fdesc = Preferences.Prefs.settings.value(key)
3405 if fdesc is not None:
3406 font = QFont(fdesc[0], int(fdesc[1]))
3407 self.lexer_.setDefaultFont(font)
3408 self.lexer_.readSettings(Preferences.Prefs.settings, "Scintilla")
3409 if self.lexer_.hasSubstyles():
3410 self.lexer_.readSubstyles(self.__textEdit)
3411
3412 # now set the lexer properties
3413 self.lexer_.initProperties()
3414
3415 self.lexer_.setDefaultColor(self.lexer_.color(0))
3416 self.lexer_.setDefaultPaper(self.lexer_.paper(0))
3417
3418 def __styleNeeded(self, position):
3419 """
3420 Private slot to handle the need for more styling.
3421
3422 @param position end position, that needs styling (integer)
3423 """
3424 self.lexer_.styleText(self.__textEdit.getEndStyled(), position)
3425
3426 def __bindName(self, line0):
3427 """
3428 Private method to generate a dummy filename for binding a lexer.
3429
3430 @param line0 first line of text to use in the generation process
3431 (string)
3432 @return dummy file name to be used for binding a lexer (string)
3433 """
3434 bindName = ""
3435 line0 = line0.lower()
3436
3437 # check first line if it does not start with #!
3438 if line0.startswith(("<html", "<!doctype html", "<?php")):
3439 bindName = "dummy.html"
3440 elif line0.startswith(("<?xml", "<!doctype")):
3441 bindName = "dummy.xml"
3442 elif line0.startswith("index: "):
3443 bindName = "dummy.diff"
3444 elif line0.startswith("\\documentclass"):
3445 bindName = "dummy.tex"
3446
3447 if not bindName and self.filetype:
3448 # check filetype
3449 from . import Lexers
3450 supportedLanguages = Lexers.getSupportedLanguages()
3451 if self.filetype in supportedLanguages:
3452 bindName = supportedLanguages[self.filetype][1]
3453 elif self.filetype in ["Python", "Python3", "MicroPython"]:
3454 bindName = "dummy.py"
3455
3456 if not bindName and line0.startswith("#!"):
3457 # #! marker detection
3458 if (
3459 "python3" in line0 or
3460 "python" in line0
3461 ):
3462 bindName = "dummy.py"
3463 self.filetype = "Python3"
3464 elif ("/bash" in line0 or "/sh" in line0):
3465 bindName = "dummy.sh"
3466 elif "ruby" in line0:
3467 bindName = "dummy.rb"
3468 self.filetype = "Ruby"
3469 elif "perl" in line0:
3470 bindName = "dummy.pl"
3471 elif "lua" in line0:
3472 bindName = "dummy.lua"
3473 elif "dmd" in line0:
3474 bindName = "dummy.d"
3475 self.filetype = "D"
3476
3477 if not bindName:
3478 # mode line detection: -*- mode: python -*-
3479 match = re.search(r"mode[:=]\s*([-\w_.]+)", line0)
3480 if match:
3481 mode = match.group(1).lower()
3482 if mode in ["python3", "pypy3"]:
3483 bindName = "dummy.py"
3484 self.filetype = "Python3"
3485 elif mode == "ruby":
3486 bindName = "dummy.rb"
3487 self.filetype = "Ruby"
3488 elif mode == "perl":
3489 bindName = "dummy.pl"
3490 elif mode == "lua":
3491 bindName = "dummy.lua"
3492 elif mode in ["dmd", "d"]:
3493 bindName = "dummy.d"
3494 self.filetype = "D"
3495
3496 if not bindName:
3497 bindName = self.__curFile
3498
3499 return bindName
3500
3501 ##########################################################
3502 ## Methods needed for the search functionality
3503 ##########################################################
3504
3505 def getSRHistory(self, key):
3506 """
3507 Public method to get the search or replace history list.
3508
3509 @param key list to return (must be 'search' or 'replace')
3510 @return the requested history list (list of strings)
3511 """
3512 return self.srHistory[key][:]
3513
3514 def textForFind(self):
3515 """
3516 Public method to determine the selection or the current word for the
3517 next find operation.
3518
3519 @return selection or current word (string)
3520 """
3521 if self.__textEdit.hasSelectedText():
3522 text = self.__textEdit.selectedText()
3523 if '\r' in text or '\n' in text:
3524 # the selection contains at least a newline, it is
3525 # unlikely to be the expression to search for
3526 return ''
3527
3528 return text
3529
3530 # no selected text, determine the word at the current position
3531 return self.__getCurrentWord()
3532
3533 def __getWord(self, line, index):
3534 """
3535 Private method to get the word at a position.
3536
3537 @param line number of line to look at
3538 @type int
3539 @param index position to look at
3540 @type int
3541 @return the word at that position
3542 @rtype str
3543 """
3544 wc = self.__textEdit.wordCharacters()
3545 if wc is None:
3546 pattern = r"\b[\w_]+\b"
3547 else:
3548 wc = re.sub(r'\w', "", wc)
3549 pattern = r"\b[\w{0}]+\b".format(re.escape(wc))
3550 rx = (
3551 re.compile(pattern)
3552 if self.__textEdit.caseSensitive() else
3553 re.compile(pattern, re.IGNORECASE)
3554 )
3555
3556 text = self.text(line)
3557 for match in rx.finditer(text):
3558 start, end = match.span()
3559 if start <= index <= end:
3560 return match.group()
3561
3562 return ""
3563
3564 def __getCurrentWord(self):
3565 """
3566 Private method to get the word at the current position.
3567
3568 @return the word at that current position
3569 """
3570 line, index = self.getCursorPosition()
3571 return self.__getWord(line, index)
3572
3573 def showSearchWidget(self):
3574 """
3575 Public method to show the search widget.
3576 """
3577 self.__replaceWidget.hide()
3578 self.__searchWidget.show()
3579 self.__searchWidget.show(self.textForFind())
3580
3581 def __searchNext(self):
3582 """
3583 Private slot to handle the search next action.
3584 """
3585 if self.__replaceWidget.isVisible():
3586 self.__replaceWidget.findNext()
3587 else:
3588 self.__searchWidget.findNext()
3589
3590 def __searchPrev(self):
3591 """
3592 Private slot to handle the search previous action.
3593 """
3594 if self.__replaceWidget.isVisible():
3595 self.__replaceWidget.findPrev()
3596 else:
3597 self.__searchWidget.findPrev()
3598
3599 def showReplaceWidget(self):
3600 """
3601 Public method to show the replace widget.
3602 """
3603 self.__searchWidget.hide()
3604 self.__replaceWidget.show(self.textForFind())
3605
3606 def __searchClearMarkers(self):
3607 """
3608 Private method to clear the search markers of the active window.
3609 """
3610 self.clearSearchIndicators()
3611
3612 def activeWindow(self):
3613 """
3614 Public method to fulfill the ViewManager interface.
3615
3616 @return reference to the text edit component (QsciScintillaCompat)
3617 """
3618 return self.__textEdit
3619
3620 def setSearchIndicator(self, startPos, indicLength):
3621 """
3622 Public method to set a search indicator for the given range.
3623
3624 @param startPos start position of the indicator (integer)
3625 @param indicLength length of the indicator (integer)
3626 """
3627 self.__textEdit.setIndicatorRange(
3628 self.searchIndicator, startPos, indicLength)
3629
3630 def clearSearchIndicators(self):
3631 """
3632 Public method to clear all search indicators.
3633 """
3634 self.__textEdit.clearAllIndicators(self.searchIndicator)
3635 self.__markedText = ""
3636
3637 def __markOccurrences(self):
3638 """
3639 Private method to mark all occurrences of the current word.
3640 """
3641 word = self.__getCurrentWord()
3642 if not word:
3643 self.clearSearchIndicators()
3644 return
3645
3646 if self.__markedText == word:
3647 return
3648
3649 self.clearSearchIndicators()
3650 ok = self.__textEdit.findFirstTarget(
3651 word, False, self.__textEdit.caseSensitive(), True, 0, 0)
3652 while ok:
3653 tgtPos, tgtLen = self.__textEdit.getFoundTarget()
3654 self.setSearchIndicator(tgtPos, tgtLen)
3655 ok = self.__textEdit.findNextTarget()
3656 self.__markedText = word
3657
3658 ##########################################################
3659 ## Methods exhibiting some QScintilla API methods
3660 ##########################################################
3661
3662 def setText(self, txt, filetype=None):
3663 """
3664 Public method to set the text programatically.
3665
3666 @param txt text to be set (string)
3667 @param filetype type of the source file (string)
3668 """
3669 self.__textEdit.setText(txt)
3670
3671 if filetype is None:
3672 self.filetype = ""
3673 else:
3674 self.filetype = filetype
3675
3676 eolMode = self.__getEditorConfig("EOLMode", nodefault=True)
3677 if eolMode is None:
3678 fileEol = self.__textEdit.detectEolString(txt)
3679 self.__textEdit.setEolModeByEolString(fileEol)
3680 else:
3681 self.__textEdit.convertEols(eolMode)
3682
3683 self.__textEdit.setModified(False)
3684 self.setWindowModified(False)
3685
3686 def gotoLine(self, line, pos=1):
3687 """
3688 Public slot to jump to the beginning of a line.
3689
3690 @param line line number to go to
3691 @type int
3692 @param pos position in line to go to
3693 @type int
3694 """
3695 self.__textEdit.setCursorPosition(line - 1, pos - 1)
3696 self.__textEdit.ensureLineVisible(line - 1)
3697 self.__textEdit.setFirstVisibleLine(line - 1)
3698 self.__textEdit.ensureCursorVisible()
3699
3700 #######################################################################
3701 ## Methods implementing the interface to EditorConfig
3702 #######################################################################
3703
3704 def __loadEditorConfig(self, fileName=""):
3705 """
3706 Private method to load the EditorConfig properties.
3707
3708 @param fileName name of the file
3709 @type str
3710 """
3711 if not fileName:
3712 fileName = self.__curFile
3713
3714 self.__editorConfig = self.__loadEditorConfigObject(fileName)
3715
3716 if fileName:
3717 self.__setTabAndIndent()
3718
3719 def __loadEditorConfigObject(self, fileName):
3720 """
3721 Private method to load the EditorConfig properties for the given
3722 file name.
3723
3724 @param fileName name of the file
3725 @type str
3726 @return EditorConfig dictionary
3727 @rtype dict
3728 """
3729 editorConfig = {}
3730
3731 if fileName:
3732 try:
3733 editorConfig = editorconfig.get_properties(fileName)
3734 except editorconfig.EditorConfigError:
3735 E5MessageBox.warning(
3736 self,
3737 self.tr("EditorConfig Properties"),
3738 self.tr("""<p>The EditorConfig properties for file"""
3739 """ <b>{0}</b> could not be loaded.</p>""")
3740 .format(fileName))
3741
3742 return editorConfig
3743
3744 def __getEditorConfig(self, option, nodefault=False, config=None):
3745 """
3746 Private method to get the requested option via EditorConfig.
3747
3748 If there is no EditorConfig defined, the equivalent built-in option
3749 will be used (Preferences.getEditor(). The option must be given as the
3750 Preferences option key. The mapping to the EditorConfig option name
3751 will be done within this method.
3752
3753 @param option Preferences option key
3754 @type str
3755 @param nodefault flag indicating to not get the default value from
3756 Preferences but return None instead
3757 @type bool
3758 @param config reference to an EditorConfig object or None
3759 @type dict
3760 @return value of requested setting or None if nothing was found and
3761 nodefault parameter was True
3762 @rtype any
3763 """
3764 if config is None:
3765 config = self.__editorConfig
3766
3767 if not config:
3768 if nodefault:
3769 return None
3770 else:
3771 value = self.__getOverrideValue(option)
3772 if value is None:
3773 # no override
3774 value = Preferences.getEditor(option)
3775 return value
3776
3777 try:
3778 if option == "EOLMode":
3779 value = config["end_of_line"]
3780 if value == "lf":
3781 value = QsciScintilla.EolMode.EolUnix
3782 elif value == "crlf":
3783 value = QsciScintilla.EolMode.EolWindows
3784 elif value == "cr":
3785 value = QsciScintilla.EolMode.EolMac
3786 else:
3787 value = None
3788 elif option == "DefaultEncoding":
3789 value = config["charset"]
3790 elif option == "InsertFinalNewline":
3791 value = Utilities.toBool(config["insert_final_newline"])
3792 elif option == "StripTrailingWhitespace":
3793 value = Utilities.toBool(config["trim_trailing_whitespace"])
3794 elif option == "TabWidth":
3795 value = int(config["tab_width"])
3796 elif option == "IndentWidth":
3797 value = config["indent_size"]
3798 if value == "tab":
3799 value = self.__getEditorConfig("TabWidth", config=config)
3800 else:
3801 value = int(value)
3802 elif option == "TabForIndentation":
3803 value = config["indent_style"] == "tab"
3804 except KeyError:
3805 value = None
3806
3807 if value is None and not nodefault:
3808 # use Preferences as default in case of error
3809 value = self.__getOverrideValue(option)
3810 if value is None:
3811 # no override
3812 value = Preferences.getEditor(option)
3813
3814 return value
3815
3816 def __getOverrideValue(self, option):
3817 """
3818 Private method to get an override value for the current file type.
3819
3820 @param option Preferences option key
3821 @type str
3822 @return override value; None in case nothing is defined
3823 @rtype any
3824 """
3825 if option in ("TabWidth", "IndentWidth"):
3826 overrides = Preferences.getEditor("TabIndentOverride")
3827 language = self.filetype or self.apiLanguage
3828 if language in overrides:
3829 if option == "TabWidth":
3830 return overrides[self.filetype][0]
3831 elif option == "IndentWidth":
3832 return overrides[self.filetype][1]
3833
3834 return None
3835
3836 #######################################################################
3837 ## Methods supporting the outline view below
3838 #######################################################################
3839
3840 def __resetChangeTimer(self):
3841 """
3842 Private slot to reset the parse timer.
3843 """
3844 self.__changeTimer.stop()
3845 self.__changeTimer.start()
3846
3847 def __editorChanged(self):
3848 """
3849 Private slot handling changes of the editor language or file name.
3850 """
3851 supported = self.__sourceOutline.isSupportedLanguage(
3852 self.getLanguage())
3853
3854 self.__sourceOutline.setVisible(supported)
3855
3856 line, pos = self.getCursorPosition()
3857 lang = self.getLanguage()
3858 self.__setSbFile(line + 1, pos, language=lang)
3859
3860 #######################################################################
3861 ## Methods supporting zooming
3862 #######################################################################
3863
3864 def __zoomIn(self):
3865 """
3866 Private method to handle the zoom in action.
3867 """
3868 self.zoomIn()
3869 self.sbZoom.setValue(self.getZoom())
3870
3871 def __zoomOut(self):
3872 """
3873 Private method to handle the zoom out action.
3874 """
3875 self.zoomOut()
3876 self.sbZoom.setValue(self.getZoom())
3877
3878 def __zoomReset(self):
3879 """
3880 Private method to reset the zoom factor.
3881 """
3882 self.__zoomTo(0)
3883
3884 def __zoom(self):
3885 """
3886 Private method to handle the zoom action.
3887 """
3888 from QScintilla.ZoomDialog import ZoomDialog
3889 dlg = ZoomDialog(self.getZoom(), self, None, True)
3890 if dlg.exec() == QDialog.DialogCode.Accepted:
3891 value = dlg.getZoomSize()
3892 self.__zoomTo(value)
3893
3894 def __zoomTo(self, value):
3895 """
3896 Private slot to zoom to a given value.
3897
3898 @param value zoom value to be set (integer)
3899 """
3900 self.zoomTo(value)
3901 self.sbZoom.setValue(self.getZoom())

eric ide

mercurial