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