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