QScintilla/MiniEditor.py

changeset 0
de9c2efb9d02
child 7
c679fb30c8f3
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a minimalistic editor for simple editing tasks.
8 """
9
10 import sys
11 import os
12 import re
13
14 from PyQt4.QtCore import *
15 from PyQt4.QtGui import *
16 from PyQt4.Qsci import QsciScintilla
17
18 from E4Gui.E4Application import e4App
19 from E4Gui.E4Action import E4Action, createActionGroup
20
21 import Lexers
22 from QsciScintillaCompat import QsciScintillaCompat, QSCINTILLA_VERSION
23 from SearchReplaceWidget import SearchReplaceWidget
24
25 import UI.PixmapCache
26 import UI.Config
27
28 from Printer import Printer
29
30 import Preferences
31
32 class MiniScintilla(QsciScintillaCompat):
33 """
34 Class implementing a QsciScintillaCompat subclass for handling focus events.
35 """
36 def __init__(self, parent = None):
37 """
38 Constructor
39
40 @param parent parent widget (QWidget)
41 @param name name of this instance (string)
42 @param flags window flags
43 """
44 QsciScintillaCompat.__init__(self, parent)
45
46 self.mw = parent
47
48 def focusInEvent(self, event):
49 """
50 Protected method called when the editor receives focus.
51
52 This method checks for modifications of the current file and
53 rereads it upon request. The cursor is placed at the current position
54 assuming, that it is in the vicinity of the old position after the reread.
55
56 @param event the event object (QFocusEvent)
57 """
58 self.mw.editorActGrp.setEnabled(True)
59 try:
60 self.setCaretWidth(self.mw.caretWidth)
61 except AttributeError:
62 pass
63
64 QsciScintillaCompat.focusInEvent(self, event)
65
66 def focusOutEvent(self, event):
67 """
68 Public method called when the editor loses focus.
69
70 @param event the event object (QFocusEvent)
71 """
72 self.mw.editorActGrp.setEnabled(False)
73 self.setCaretWidth(0)
74
75 QsciScintillaCompat.focusOutEvent(self, event)
76
77 class MiniEditor(QMainWindow):
78 """
79 Class implementing a minimalistic editor for simple editing tasks.
80
81 @signal editorSaved emitted after the file has been saved
82 """
83 def __init__(self, filename = "", filetype = "", parent = None, name = None):
84 """
85 Constructor
86
87 @param filename name of the file to open (string)
88 @param filetype type of the source file (string)
89 @param parent reference to the parent widget (QWidget)
90 @param name object name of the window (string)
91 """
92 QMainWindow.__init__(self, parent)
93 if name is not None:
94 self.setObjectName(name)
95 self.setAttribute(Qt.WA_DeleteOnClose)
96 self.setWindowIcon(UI.PixmapCache.getIcon("editor.png"))
97
98 self.__textEdit = MiniScintilla(self)
99 self.__textEdit.clearSearchIndicators = self.clearSearchIndicators
100 self.__textEdit.setSearchIndicator = self.setSearchIndicator
101
102 self.srHistory = {
103 "search" : [],
104 "replace" : []
105 }
106 self.searchDlg = SearchReplaceWidget(False, self, self)
107 self.replaceDlg = SearchReplaceWidget(True, self, self)
108
109 centralWidget = QWidget()
110 layout = QVBoxLayout()
111 layout.setContentsMargins(1, 1, 1, 1)
112 layout.addWidget(self.__textEdit)
113 layout.addWidget(self.searchDlg)
114 layout.addWidget(self.replaceDlg)
115 centralWidget.setLayout(layout)
116 self.setCentralWidget(centralWidget)
117 self.searchDlg.hide()
118 self.replaceDlg.hide()
119
120 self.lexer_ = None
121 self.apiLanguage = ""
122 self.filetype = ""
123
124 self.__createActions()
125 self.__createMenus()
126 self.__createToolBars()
127 self.__createStatusBar()
128
129 self.__setTextDisplay()
130 self.__setMargins()
131 self.__setEolMode()
132
133 self.__readSettings()
134
135 # clear QScintilla defined keyboard commands
136 # we do our own handling through the view manager
137 self.__textEdit.clearAlternateKeys()
138 self.__textEdit.clearKeys()
139
140 # initialise the mark occurrences timer
141 self.__markOccurrencesTimer = QTimer(self)
142 self.__markOccurrencesTimer.setSingleShot(True)
143 self.__markOccurrencesTimer.setInterval(
144 Preferences.getEditor("MarkOccurrencesTimeout"))
145 self.connect(self.__markOccurrencesTimer, SIGNAL("timeout()"),
146 self.__markOccurrences)
147 self.__markedText = ""
148
149 self.connect(self.__textEdit, SIGNAL("textChanged()"), self.__documentWasModified)
150 self.connect(self.__textEdit, SIGNAL('modificationChanged(bool)'),
151 self.__modificationChanged)
152 self.connect(self.__textEdit, SIGNAL('cursorPositionChanged(int, int)'),
153 self.__cursorPositionChanged)
154
155 self.__textEdit.setContextMenuPolicy(Qt.CustomContextMenu)
156 self.connect(self.__textEdit,
157 SIGNAL("customContextMenuRequested(const QPoint &)"),
158 self.__contextMenuRequested)
159
160 self.connect(self.__textEdit,
161 SIGNAL("selectionChanged()"),
162 self.searchDlg.selectionChanged)
163 self.connect(self.__textEdit,
164 SIGNAL("selectionChanged()"),
165 self.replaceDlg.selectionChanged)
166
167 self.__setCurrentFile("")
168 if filename:
169 self.__loadFile(filename, filetype)
170
171 self.__checkActions()
172
173 def closeEvent(self, event):
174 """
175 Public method to handle the close event.
176
177 @param event close event (QCloseEvent)
178 """
179 if self.__maybeSave():
180 self.__writeSettings()
181 event.accept()
182 else:
183 event.ignore()
184
185 def __newFile(self):
186 """
187 Private slot to create a new file.
188 """
189 if self.__maybeSave():
190 self.__textEdit.clear()
191 self.__setCurrentFile("")
192
193 self.__checkActions()
194
195 def __open(self):
196 """
197 Private slot to open a file.
198 """
199 if self.__maybeSave():
200 fileName = QFileDialog.getOpenFileName(self)
201 if fileName:
202 self.__loadFile(fileName)
203 self.__checkActions()
204
205 def __save(self):
206 """
207 Private slot to save a file.
208 """
209 if not self.__curFile:
210 return self.__saveAs()
211 else:
212 return self.__saveFile(self.__curFile)
213
214 def __saveAs(self):
215 """
216 Private slot to save a file with a new name.
217 """
218 fileName = QFileDialog.getSaveFileName(self)
219 if not fileName:
220 return False
221
222 return self.__saveFile(fileName)
223
224 def __about(self):
225 """
226 Private slot to show a little About message.
227 """
228 QMessageBox.about(self, self.trUtf8("About eric4 Mini Editor"),
229 self.trUtf8("The eric4 Mini Editor is an editor component"
230 " based on QScintilla. It may be used for simple"
231 " editing tasks, that don't need the power of"
232 " a full blown editor."))
233
234 def __aboutQt(self):
235 """
236 Private slot to handle the About Qt dialog.
237 """
238 QMessageBox.aboutQt(self, "eric4 Mini Editor")
239
240 def __whatsThis(self):
241 """
242 Private slot called in to enter Whats This mode.
243 """
244 QWhatsThis.enterWhatsThisMode()
245
246 def __documentWasModified(self):
247 """
248 Private slot to handle a change in the documents modification status.
249 """
250 self.setWindowModified(self.__textEdit.isModified())
251
252 def __checkActions(self, setSb = True):
253 """
254 Private slot to check some actions for their enable/disable status
255 and set the statusbar info.
256
257 @param setSb flag indicating an update of the status bar is wanted (boolean)
258 """
259 self.saveAct.setEnabled(self.__textEdit.isModified())
260
261 self.undoAct.setEnabled(self.__textEdit.isUndoAvailable())
262 self.redoAct.setEnabled(self.__textEdit.isRedoAvailable())
263
264 if setSb:
265 line, pos = self.__textEdit.getCursorPosition()
266 self.__setSbFile(line + 1, pos)
267
268 def __setSbFile(self, line = None, pos = None):
269 """
270 Private method to set the file info in the status bar.
271
272 @param line line number to display (int)
273 @param pos character position to display (int)
274 """
275 if not self.__curFile:
276 writ = ' '
277 else:
278 if QFileInfo(self.__curFile).isWritable():
279 writ = ' rw'
280 else:
281 writ = ' ro'
282
283 self.sbWritable.setText(writ)
284
285 if line is None:
286 line = ''
287 self.sbLine.setText(self.trUtf8('Line: {0:5}').format(line))
288
289 if pos is None:
290 pos = ''
291 self.sbPos.setText(self.trUtf8('Pos: {0:5}').format(pos))
292
293 def __readShortcut(self, act, category):
294 """
295 Private function to read a single keyboard shortcut from the settings.
296
297 @param act reference to the action object (E4Action)
298 @param category category the action belongs to (string)
299 @param prefClass preferences class used as the storage area
300 """
301 if act.objectName():
302 accel = Preferences.Prefs.settings.value(\
303 "Shortcuts/{0}/{1}/Accel".format(category, act.objectName()))
304 if accel.isValid():
305 act.setShortcut(QKeySequence(accel.toString()))
306 accel = Preferences.Prefs.settings.value(\
307 "Shortcuts/{0}/{1}/AltAccel".format(category, act.objectName()))
308 if accel.isValid():
309 act.setAlternateShortcut(QKeySequence(accel.toString()))
310
311 def __createActions(self):
312 """
313 Private method to create the actions.
314 """
315 self.fileActions = []
316 self.editActions = []
317 self.helpActions = []
318 self.searchActions = []
319
320 self.__createFileActions()
321 self.__createEditActions()
322 self.__createHelpActions()
323 self.__createSearchActions()
324
325 # read the keyboard shortcuts and make them identical to the main
326 # eric4 shortcuts
327 for act in self.helpActions:
328 self.__readShortcut(act, "General")
329 for act in self.editActions:
330 self.__readShortcut(act, "Edit")
331 for act in self.fileActions:
332 self.__readShortcut(act, "File")
333 for act in self.searchActions:
334 self.__readShortcut(act, "Search")
335
336 def __createFileActions(self):
337 """
338 Private method to create the File actions.
339 """
340 self.newAct = E4Action(self.trUtf8('New'),
341 UI.PixmapCache.getIcon("new.png"),
342 self.trUtf8('&New'),
343 QKeySequence(self.trUtf8("Ctrl+N", "File|New")),
344 0, self, 'vm_file_new')
345 self.newAct.setStatusTip(self.trUtf8('Open an empty editor window'))
346 self.newAct.setWhatsThis(self.trUtf8(\
347 """<b>New</b>"""
348 """<p>An empty editor window will be created.</p>"""
349 ))
350 self.connect(self.newAct, SIGNAL('triggered()'), self.__newFile)
351 self.fileActions.append(self.newAct)
352
353 self.openAct = E4Action(self.trUtf8('Open'),
354 UI.PixmapCache.getIcon("open.png"),
355 self.trUtf8('&Open...'),
356 QKeySequence(self.trUtf8("Ctrl+O", "File|Open")),
357 0, self, 'vm_file_open')
358 self.openAct.setStatusTip(self.trUtf8('Open a file'))
359 self.openAct.setWhatsThis(self.trUtf8(\
360 """<b>Open a file</b>"""
361 """<p>You will be asked for the name of a file to be opened.</p>"""
362 ))
363 self.connect(self.openAct, SIGNAL('triggered()'), self.__open)
364 self.fileActions.append(self.openAct)
365
366 self.saveAct = E4Action(self.trUtf8('Save'),
367 UI.PixmapCache.getIcon("fileSave.png"),
368 self.trUtf8('&Save'),
369 QKeySequence(self.trUtf8("Ctrl+S", "File|Save")),
370 0, self, 'vm_file_save')
371 self.saveAct.setStatusTip(self.trUtf8('Save the current file'))
372 self.saveAct.setWhatsThis(self.trUtf8(\
373 """<b>Save File</b>"""
374 """<p>Save the contents of current editor window.</p>"""
375 ))
376 self.connect(self.saveAct, SIGNAL('triggered()'), self.__save)
377 self.fileActions.append(self.saveAct)
378
379 self.saveAsAct = E4Action(self.trUtf8('Save as'),
380 UI.PixmapCache.getIcon("fileSaveAs.png"),
381 self.trUtf8('Save &as...'),
382 QKeySequence(self.trUtf8("Shift+Ctrl+S", "File|Save As")),
383 0, self, 'vm_file_save_as')
384 self.saveAsAct.setStatusTip(self.trUtf8('Save the current file to a new one'))
385 self.saveAsAct.setWhatsThis(self.trUtf8(\
386 """<b>Save File as</b>"""
387 """<p>Save the contents of current editor window to a new file."""
388 """ The file can be entered in a file selection dialog.</p>"""
389 ))
390 self.connect(self.saveAsAct, SIGNAL('triggered()'), self.__saveAs)
391 self.fileActions.append(self.saveAsAct)
392
393 self.closeAct = E4Action(self.trUtf8('Close'),
394 UI.PixmapCache.getIcon("close.png"),
395 self.trUtf8('&Close'),
396 QKeySequence(self.trUtf8("Ctrl+W", "File|Close")),
397 0, self, 'vm_file_close')
398 self.closeAct.setStatusTip(self.trUtf8('Close the editor window'))
399 self.closeAct.setWhatsThis(self.trUtf8(\
400 """<b>Close Window</b>"""
401 """<p>Close the current window.</p>"""
402 ))
403 self.connect(self.closeAct, SIGNAL('triggered()'), self.close)
404 self.fileActions.append(self.closeAct)
405
406 self.printAct = E4Action(self.trUtf8('Print'),
407 UI.PixmapCache.getIcon("print.png"),
408 self.trUtf8('&Print'),
409 QKeySequence(self.trUtf8("Ctrl+P", "File|Print")),
410 0, self, 'vm_file_print')
411 self.printAct.setStatusTip(self.trUtf8('Print the current file'))
412 self.printAct.setWhatsThis(self.trUtf8(
413 """<b>Print File</b>"""
414 """<p>Print the contents of the current file.</p>"""
415 ))
416 self.connect(self.printAct, SIGNAL('triggered()'), self.__printFile)
417 self.fileActions.append(self.printAct)
418
419 self.printPreviewAct = \
420 E4Action(self.trUtf8('Print Preview'),
421 UI.PixmapCache.getIcon("printPreview.png"),
422 QApplication.translate('ViewManager', 'Print Preview'),
423 0, 0, self, 'vm_file_print_preview')
424 self.printPreviewAct.setStatusTip(self.trUtf8(
425 'Print preview of the current file'))
426 self.printPreviewAct.setWhatsThis(self.trUtf8(
427 """<b>Print Preview</b>"""
428 """<p>Print preview of the current file.</p>"""
429 ))
430 self.connect(self.printPreviewAct, SIGNAL('triggered()'),
431 self.__printPreviewFile)
432 self.fileActions.append(self.printPreviewAct)
433
434 def __createEditActions(self):
435 """
436 Private method to create the Edit actions.
437 """
438 self.undoAct = E4Action(self.trUtf8('Undo'),
439 UI.PixmapCache.getIcon("editUndo.png"),
440 self.trUtf8('&Undo'),
441 QKeySequence(self.trUtf8("Ctrl+Z", "Edit|Undo")),
442 QKeySequence(self.trUtf8("Alt+Backspace", "Edit|Undo")),
443 self, 'vm_edit_undo')
444 self.undoAct.setStatusTip(self.trUtf8('Undo the last change'))
445 self.undoAct.setWhatsThis(self.trUtf8(\
446 """<b>Undo</b>"""
447 """<p>Undo the last change done in the current editor.</p>"""
448 ))
449 self.connect(self.undoAct, SIGNAL('triggered()'), self.__undo)
450 self.editActions.append(self.undoAct)
451
452 self.redoAct = E4Action(self.trUtf8('Redo'),
453 UI.PixmapCache.getIcon("editRedo.png"),
454 self.trUtf8('&Redo'),
455 QKeySequence(self.trUtf8("Ctrl+Shift+Z", "Edit|Redo")),
456 0, self, 'vm_edit_redo')
457 self.redoAct.setStatusTip(self.trUtf8('Redo the last change'))
458 self.redoAct.setWhatsThis(self.trUtf8(\
459 """<b>Redo</b>"""
460 """<p>Redo the last change done in the current editor.</p>"""
461 ))
462 self.connect(self.redoAct, SIGNAL('triggered()'), self.__redo)
463 self.editActions.append(self.redoAct)
464
465 self.cutAct = E4Action(self.trUtf8('Cut'),
466 UI.PixmapCache.getIcon("editCut.png"),
467 self.trUtf8('Cu&t'),
468 QKeySequence(self.trUtf8("Ctrl+X", "Edit|Cut")),
469 QKeySequence(self.trUtf8("Shift+Del", "Edit|Cut")),
470 self, 'vm_edit_cut')
471 self.cutAct.setStatusTip(self.trUtf8('Cut the selection'))
472 self.cutAct.setWhatsThis(self.trUtf8(\
473 """<b>Cut</b>"""
474 """<p>Cut the selected text of the current editor to the clipboard.</p>"""
475 ))
476 self.connect(self.cutAct, SIGNAL('triggered()'), self.__textEdit.cut)
477 self.editActions.append(self.cutAct)
478
479 self.copyAct = E4Action(self.trUtf8('Copy'),
480 UI.PixmapCache.getIcon("editCopy.png"),
481 self.trUtf8('&Copy'),
482 QKeySequence(self.trUtf8("Ctrl+C", "Edit|Copy")),
483 QKeySequence(self.trUtf8("Ctrl+Ins", "Edit|Copy")),
484 self, 'vm_edit_copy')
485 self.copyAct.setStatusTip(self.trUtf8('Copy the selection'))
486 self.copyAct.setWhatsThis(self.trUtf8(\
487 """<b>Copy</b>"""
488 """<p>Copy the selected text of the current editor to the clipboard.</p>"""
489 ))
490 self.connect(self.copyAct, SIGNAL('triggered()'), self.__textEdit.copy)
491 self.editActions.append(self.copyAct)
492
493 self.pasteAct = E4Action(self.trUtf8('Paste'),
494 UI.PixmapCache.getIcon("editPaste.png"),
495 self.trUtf8('&Paste'),
496 QKeySequence(self.trUtf8("Ctrl+V", "Edit|Paste")),
497 QKeySequence(self.trUtf8("Shift+Ins", "Edit|Paste")),
498 self, 'vm_edit_paste')
499 self.pasteAct.setStatusTip(self.trUtf8('Paste the last cut/copied text'))
500 self.pasteAct.setWhatsThis(self.trUtf8(\
501 """<b>Paste</b>"""
502 """<p>Paste the last cut/copied text from the clipboard to"""
503 """ the current editor.</p>"""
504 ))
505 self.connect(self.pasteAct, SIGNAL('triggered()'), self.__textEdit.paste)
506 self.editActions.append(self.pasteAct)
507
508 self.deleteAct = E4Action(self.trUtf8('Clear'),
509 UI.PixmapCache.getIcon("editDelete.png"),
510 self.trUtf8('Cl&ear'),
511 QKeySequence(self.trUtf8("Alt+Shift+C", "Edit|Clear")),
512 0,
513 self, 'vm_edit_clear')
514 self.deleteAct.setStatusTip(self.trUtf8('Clear all text'))
515 self.deleteAct.setWhatsThis(self.trUtf8(\
516 """<b>Clear</b>"""
517 """<p>Delete all text of the current editor.</p>"""
518 ))
519 self.connect(self.deleteAct, SIGNAL('triggered()'), self.__textEdit.clear)
520 self.editActions.append(self.deleteAct)
521
522 self.cutAct.setEnabled(False);
523 self.copyAct.setEnabled(False);
524 self.connect(self.__textEdit, SIGNAL("copyAvailable(bool)"),
525 self.cutAct, SLOT("setEnabled(bool)"))
526 self.connect(self.__textEdit, SIGNAL("copyAvailable(bool)"),
527 self.copyAct, SLOT("setEnabled(bool)"))
528
529 ####################################################################
530 ## Below follow the actions for qscintilla standard commands.
531 ####################################################################
532
533 self.esm = QSignalMapper(self)
534 self.connect(self.esm, SIGNAL('mapped(int)'), self.__textEdit.editorCommand)
535
536 self.editorActGrp = createActionGroup(self)
537
538 act = E4Action(QApplication.translate('ViewManager', 'Move left one character'),
539 QApplication.translate('ViewManager', 'Move left one character'),
540 QKeySequence(QApplication.translate('ViewManager', 'Left')), 0,
541 self.editorActGrp, 'vm_edit_move_left_char')
542 self.esm.setMapping(act, QsciScintilla.SCI_CHARLEFT)
543 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
544 self.editActions.append(act)
545
546 act = E4Action(QApplication.translate('ViewManager', 'Move right one character'),
547 QApplication.translate('ViewManager', 'Move right one character'),
548 QKeySequence(QApplication.translate('ViewManager', 'Right')), 0,
549 self.editorActGrp, 'vm_edit_move_right_char')
550 self.esm.setMapping(act, QsciScintilla.SCI_CHARRIGHT)
551 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
552 self.editActions.append(act)
553
554 act = E4Action(QApplication.translate('ViewManager', 'Move up one line'),
555 QApplication.translate('ViewManager', 'Move up one line'),
556 QKeySequence(QApplication.translate('ViewManager', 'Up')), 0,
557 self.editorActGrp, 'vm_edit_move_up_line')
558 self.esm.setMapping(act, QsciScintilla.SCI_LINEUP)
559 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
560 self.editActions.append(act)
561
562 act = E4Action(QApplication.translate('ViewManager', 'Move down one line'),
563 QApplication.translate('ViewManager', 'Move down one line'),
564 QKeySequence(QApplication.translate('ViewManager', 'Down')), 0,
565 self.editorActGrp, 'vm_edit_move_down_line')
566 self.esm.setMapping(act, QsciScintilla.SCI_LINEDOWN)
567 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
568 self.editActions.append(act)
569
570 act = E4Action(QApplication.translate('ViewManager', 'Move left one word part'),
571 QApplication.translate('ViewManager', 'Move left one word part'),
572 QKeySequence(QApplication.translate('ViewManager', 'Alt+Left')), 0,
573 self.editorActGrp, 'vm_edit_move_left_word_part')
574 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTLEFT)
575 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
576 self.editActions.append(act)
577
578 act = E4Action(QApplication.translate('ViewManager', 'Move right one word part'),
579 QApplication.translate('ViewManager', 'Move right one word part'),
580 QKeySequence(QApplication.translate('ViewManager', 'Alt+Right')), 0,
581 self.editorActGrp, 'vm_edit_move_right_word_part')
582 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTRIGHT)
583 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
584 self.editActions.append(act)
585
586 act = E4Action(QApplication.translate('ViewManager', 'Move left one word'),
587 QApplication.translate('ViewManager', 'Move left one word'),
588 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Left')), 0,
589 self.editorActGrp, 'vm_edit_move_left_word')
590 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFT)
591 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
592 self.editActions.append(act)
593
594 act = E4Action(QApplication.translate('ViewManager', 'Move right one word'),
595 QApplication.translate('ViewManager', 'Move right one word'),
596 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Right')),
597 0,
598 self.editorActGrp, 'vm_edit_move_right_word')
599 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHT)
600 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
601 self.editActions.append(act)
602
603 act = E4Action(QApplication.translate('ViewManager',
604 'Move to first visible character in line'),
605 QApplication.translate('ViewManager',
606 'Move to first visible character in line'),
607 QKeySequence(QApplication.translate('ViewManager', 'Home')), 0,
608 self.editorActGrp, 'vm_edit_move_first_visible_char')
609 self.esm.setMapping(act, QsciScintilla.SCI_VCHOME)
610 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
611 self.editActions.append(act)
612
613 act = E4Action(QApplication.translate('ViewManager',
614 'Move to start of displayed line'),
615 QApplication.translate('ViewManager',
616 'Move to start of displayed line'),
617 QKeySequence(QApplication.translate('ViewManager', 'Alt+Home')), 0,
618 self.editorActGrp, 'vm_edit_move_start_line')
619 self.esm.setMapping(act, QsciScintilla.SCI_HOMEDISPLAY)
620 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
621 self.editActions.append(act)
622
623 act = E4Action(QApplication.translate('ViewManager', 'Move to end of line'),
624 QApplication.translate('ViewManager', 'Move to end of line'),
625 QKeySequence(QApplication.translate('ViewManager', 'End')), 0,
626 self.editorActGrp, 'vm_edit_move_end_line')
627 self.esm.setMapping(act, QsciScintilla.SCI_LINEEND)
628 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
629 self.editActions.append(act)
630
631 act = E4Action(QApplication.translate('ViewManager', 'Scroll view down one line'),
632 QApplication.translate('ViewManager', 'Scroll view down one line'),
633 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Down')), 0,
634 self.editorActGrp, 'vm_edit_scroll_down_line')
635 self.esm.setMapping(act, QsciScintilla.SCI_LINESCROLLDOWN)
636 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
637 self.editActions.append(act)
638
639 act = E4Action(QApplication.translate('ViewManager', 'Scroll view up one line'),
640 QApplication.translate('ViewManager', 'Scroll view up one line'),
641 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Up')), 0,
642 self.editorActGrp, 'vm_edit_scroll_up_line')
643 self.esm.setMapping(act, QsciScintilla.SCI_LINESCROLLUP)
644 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
645 self.editActions.append(act)
646
647 act = E4Action(QApplication.translate('ViewManager', 'Move up one paragraph'),
648 QApplication.translate('ViewManager', 'Move up one paragraph'),
649 QKeySequence(QApplication.translate('ViewManager', 'Alt+Up')), 0,
650 self.editorActGrp, 'vm_edit_move_up_para')
651 self.esm.setMapping(act, QsciScintilla.SCI_PARAUP)
652 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
653 self.editActions.append(act)
654
655 act = E4Action(QApplication.translate('ViewManager', 'Move down one paragraph'),
656 QApplication.translate('ViewManager', 'Move down one paragraph'),
657 QKeySequence(QApplication.translate('ViewManager', 'Alt+Down')), 0,
658 self.editorActGrp, 'vm_edit_move_down_para')
659 self.esm.setMapping(act, QsciScintilla.SCI_PARADOWN)
660 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
661 self.editActions.append(act)
662
663 act = E4Action(QApplication.translate('ViewManager', 'Move up one page'),
664 QApplication.translate('ViewManager', 'Move up one page'),
665 QKeySequence(QApplication.translate('ViewManager', 'PgUp')), 0,
666 self.editorActGrp, 'vm_edit_move_up_page')
667 self.esm.setMapping(act, QsciScintilla.SCI_PAGEUP)
668 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
669 self.editActions.append(act)
670
671 act = E4Action(QApplication.translate('ViewManager', 'Move down one page'),
672 QApplication.translate('ViewManager', 'Move down one page'),
673 QKeySequence(QApplication.translate('ViewManager', 'PgDown')), 0,
674 self.editorActGrp, 'vm_edit_move_down_page')
675 self.esm.setMapping(act, QsciScintilla.SCI_PAGEDOWN)
676 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
677 self.editActions.append(act)
678
679 act = E4Action(QApplication.translate('ViewManager', 'Move to start of text'),
680 QApplication.translate('ViewManager', 'Move to start of text'),
681 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Home')), 0,
682 self.editorActGrp, 'vm_edit_move_start_text')
683 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTSTART)
684 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
685 self.editActions.append(act)
686
687 act = E4Action(QApplication.translate('ViewManager', 'Move to end of text'),
688 QApplication.translate('ViewManager', 'Move to end of text'),
689 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+End')), 0,
690 self.editorActGrp, 'vm_edit_move_end_text')
691 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTEND)
692 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
693 self.editActions.append(act)
694
695 act = E4Action(QApplication.translate('ViewManager', 'Indent one level'),
696 QApplication.translate('ViewManager', 'Indent one level'),
697 QKeySequence(QApplication.translate('ViewManager', 'Tab')), 0,
698 self.editorActGrp, 'vm_edit_indent_one_level')
699 self.esm.setMapping(act, QsciScintilla.SCI_TAB)
700 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
701 self.editActions.append(act)
702
703 act = E4Action(QApplication.translate('ViewManager', 'Unindent one level'),
704 QApplication.translate('ViewManager', 'Unindent one level'),
705 QKeySequence(QApplication.translate('ViewManager', 'Shift+Tab')), 0,
706 self.editorActGrp, 'vm_edit_unindent_one_level')
707 self.esm.setMapping(act, QsciScintilla.SCI_BACKTAB)
708 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
709 self.editActions.append(act)
710
711 act = E4Action(QApplication.translate('ViewManager',
712 'Extend selection left one character'),
713 QApplication.translate('ViewManager',
714 'Extend selection left one character'),
715 QKeySequence(QApplication.translate('ViewManager', 'Shift+Left')),
716 0,
717 self.editorActGrp, 'vm_edit_extend_selection_left_char')
718 self.esm.setMapping(act, QsciScintilla.SCI_CHARLEFTEXTEND)
719 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
720 self.editActions.append(act)
721
722 act = E4Action(QApplication.translate('ViewManager',
723 'Extend selection right one character'),
724 QApplication.translate('ViewManager',
725 'Extend selection right one character'),
726 QKeySequence(QApplication.translate('ViewManager', 'Shift+Right')),
727 0,
728 self.editorActGrp, 'vm_edit_extend_selection_right_char')
729 self.esm.setMapping(act, QsciScintilla.SCI_CHARRIGHTEXTEND)
730 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
731 self.editActions.append(act)
732
733 act = E4Action(QApplication.translate('ViewManager',
734 'Extend selection up one line'),
735 QApplication.translate('ViewManager',
736 'Extend selection up one line'),
737 QKeySequence(QApplication.translate('ViewManager', 'Shift+Up')), 0,
738 self.editorActGrp, 'vm_edit_extend_selection_up_line')
739 self.esm.setMapping(act, QsciScintilla.SCI_LINEUPEXTEND)
740 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
741 self.editActions.append(act)
742
743 act = E4Action(QApplication.translate('ViewManager',
744 'Extend selection down one line'),
745 QApplication.translate('ViewManager',
746 'Extend selection down one line'),
747 QKeySequence(QApplication.translate('ViewManager', 'Shift+Down')),
748 0,
749 self.editorActGrp, 'vm_edit_extend_selection_down_line')
750 self.esm.setMapping(act, QsciScintilla.SCI_LINEDOWNEXTEND)
751 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
752 self.editActions.append(act)
753
754 act = E4Action(QApplication.translate('ViewManager',
755 'Extend selection left one word part'),
756 QApplication.translate('ViewManager',
757 'Extend selection left one word part'),
758 QKeySequence(QApplication.translate('ViewManager',
759 'Alt+Shift+Left')),
760 0,
761 self.editorActGrp, 'vm_edit_extend_selection_left_word_part')
762 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTLEFTEXTEND)
763 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
764 self.editActions.append(act)
765
766 act = E4Action(QApplication.translate('ViewManager',
767 'Extend selection right one word part'),
768 QApplication.translate('ViewManager',
769 'Extend selection right one word part'),
770 QKeySequence(QApplication.translate('ViewManager',
771 'Alt+Shift+Right')),
772 0,
773 self.editorActGrp, 'vm_edit_extend_selection_right_word_part')
774 self.esm.setMapping(act, QsciScintilla.SCI_WORDPARTRIGHTEXTEND)
775 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
776 self.editActions.append(act)
777
778 act = E4Action(QApplication.translate('ViewManager',
779 'Extend selection left one word'),
780 QApplication.translate('ViewManager',
781 'Extend selection left one word'),
782 QKeySequence(QApplication.translate('ViewManager',
783 'Ctrl+Shift+Left')),
784 0,
785 self.editorActGrp, 'vm_edit_extend_selection_left_word')
786 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFTEXTEND)
787 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
788 self.editActions.append(act)
789
790 act = E4Action(QApplication.translate('ViewManager',
791 'Extend selection right one word'),
792 QApplication.translate('ViewManager',
793 'Extend selection right one word'),
794 QKeySequence(QApplication.translate('ViewManager',
795 'Ctrl+Shift+Right')),
796 0,
797 self.editorActGrp, 'vm_edit_extend_selection_right_word')
798 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHTEXTEND)
799 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
800 self.editActions.append(act)
801
802 act = E4Action(QApplication.translate('ViewManager',
803 'Extend selection to first visible character in line'),
804 QApplication.translate('ViewManager',
805 'Extend selection to first visible character in line'),
806 QKeySequence(QApplication.translate('ViewManager', 'Shift+Home')),
807 0,
808 self.editorActGrp, 'vm_edit_extend_selection_first_visible_char')
809 self.esm.setMapping(act, QsciScintilla.SCI_VCHOMEEXTEND)
810 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
811 self.editActions.append(act)
812
813 act = E4Action(QApplication.translate('ViewManager',
814 'Extend selection to start of line'),
815 QApplication.translate('ViewManager',
816 'Extend selection to start of line'),
817 QKeySequence(QApplication.translate('ViewManager',
818 'Alt+Shift+Home')),
819 0,
820 self.editorActGrp, 'vm_edit_extend_selection_start_line')
821 self.esm.setMapping(act, QsciScintilla.SCI_HOMEDISPLAYEXTEND)
822 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
823 self.editActions.append(act)
824
825 act = E4Action(QApplication.translate('ViewManager',
826 'Extend selection to end of line'),
827 QApplication.translate('ViewManager',
828 'Extend selection to end of line'),
829 QKeySequence(QApplication.translate('ViewManager', 'Shift+End')), 0,
830 self.editorActGrp, 'vm_edit_extend_selection_end_line')
831 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDEXTEND)
832 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
833 self.editActions.append(act)
834
835 act = E4Action(QApplication.translate('ViewManager',
836 'Extend selection up one paragraph'),
837 QApplication.translate('ViewManager',
838 'Extend selection up one paragraph'),
839 QKeySequence(QApplication.translate('ViewManager', 'Alt+Shift+Up')),
840 0,
841 self.editorActGrp, 'vm_edit_extend_selection_up_para')
842 self.esm.setMapping(act, QsciScintilla.SCI_PARAUPEXTEND)
843 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
844 self.editActions.append(act)
845
846 act = E4Action(QApplication.translate('ViewManager',
847 'Extend selection down one paragraph'),
848 QApplication.translate('ViewManager',
849 'Extend selection down one paragraph'),
850 QKeySequence(QApplication.translate('ViewManager',
851 'Alt+Shift+Down')),
852 0,
853 self.editorActGrp, 'vm_edit_extend_selection_down_para')
854 self.esm.setMapping(act, QsciScintilla.SCI_PARADOWNEXTEND)
855 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
856 self.editActions.append(act)
857
858 act = E4Action(QApplication.translate('ViewManager',
859 'Extend selection up one page'),
860 QApplication.translate('ViewManager',
861 'Extend selection up one page'),
862 QKeySequence(QApplication.translate('ViewManager', 'Shift+PgUp')),
863 0,
864 self.editorActGrp, 'vm_edit_extend_selection_up_page')
865 self.esm.setMapping(act, QsciScintilla.SCI_PAGEUPEXTEND)
866 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
867 self.editActions.append(act)
868
869 act = E4Action(QApplication.translate('ViewManager',
870 'Extend selection down one page'),
871 QApplication.translate('ViewManager',
872 'Extend selection down one page'),
873 QKeySequence(QApplication.translate('ViewManager', 'Shift+PgDown')),
874 0,
875 self.editorActGrp, 'vm_edit_extend_selection_down_page')
876 self.esm.setMapping(act, QsciScintilla.SCI_PAGEDOWNEXTEND)
877 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
878 self.editActions.append(act)
879
880 act = E4Action(QApplication.translate('ViewManager',
881 'Extend selection to start of text'),
882 QApplication.translate('ViewManager',
883 'Extend selection to start of text'),
884 QKeySequence(QApplication.translate('ViewManager',
885 'Ctrl+Shift+Home')),
886 0,
887 self.editorActGrp, 'vm_edit_extend_selection_start_text')
888 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTSTARTEXTEND)
889 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
890 self.editActions.append(act)
891
892 act = E4Action(QApplication.translate('ViewManager',
893 'Extend selection to end of text'),
894 QApplication.translate('ViewManager',
895 'Extend selection to end of text'),
896 QKeySequence(QApplication.translate('ViewManager',
897 'Ctrl+Shift+End')),
898 0,
899 self.editorActGrp, 'vm_edit_extend_selection_end_text')
900 self.esm.setMapping(act, QsciScintilla.SCI_DOCUMENTENDEXTEND)
901 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
902 self.editActions.append(act)
903
904 act = E4Action(QApplication.translate('ViewManager',
905 'Delete previous character'),
906 QApplication.translate('ViewManager', 'Delete previous character'),
907 QKeySequence(QApplication.translate('ViewManager', 'Backspace')),
908 QKeySequence(QApplication.translate('ViewManager',
909 'Shift+Backspace')),
910 self.editorActGrp, 'vm_edit_delete_previous_char')
911 self.esm.setMapping(act, QsciScintilla.SCI_DELETEBACK)
912 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
913 self.editActions.append(act)
914
915 act = E4Action(QApplication.translate('ViewManager',
916 'Delete previous character if not at line start'),
917 QApplication.translate('ViewManager',
918 'Delete previous character if not at line start'),
919 0, 0,
920 self.editorActGrp, 'vm_edit_delet_previous_char_not_line_start')
921 self.esm.setMapping(act, QsciScintilla.SCI_DELETEBACKNOTLINE)
922 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
923 self.editActions.append(act)
924
925 act = E4Action(QApplication.translate('ViewManager', 'Delete current character'),
926 QApplication.translate('ViewManager', 'Delete current character'),
927 QKeySequence(QApplication.translate('ViewManager', 'Del')), 0,
928 self.editorActGrp, 'vm_edit_delete_current_char')
929 self.esm.setMapping(act, QsciScintilla.SCI_CLEAR)
930 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
931 self.editActions.append(act)
932
933 act = E4Action(QApplication.translate('ViewManager', 'Delete word to left'),
934 QApplication.translate('ViewManager', 'Delete word to left'),
935 QKeySequence(QApplication.translate('ViewManager',
936 'Ctrl+Backspace')),
937 0,
938 self.editorActGrp, 'vm_edit_delete_word_left')
939 self.esm.setMapping(act, QsciScintilla.SCI_DELWORDLEFT)
940 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
941 self.editActions.append(act)
942
943 act = E4Action(QApplication.translate('ViewManager', 'Delete word to right'),
944 QApplication.translate('ViewManager', 'Delete word to right'),
945 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Del')), 0,
946 self.editorActGrp, 'vm_edit_delete_word_right')
947 self.esm.setMapping(act, QsciScintilla.SCI_DELWORDRIGHT)
948 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
949 self.editActions.append(act)
950
951 act = E4Action(QApplication.translate('ViewManager', 'Delete line to left'),
952 QApplication.translate('ViewManager', 'Delete line to left'),
953 QKeySequence(QApplication.translate('ViewManager',
954 'Ctrl+Shift+Backspace')),
955 0,
956 self.editorActGrp, 'vm_edit_delete_line_left')
957 self.esm.setMapping(act, QsciScintilla.SCI_DELLINELEFT)
958 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
959 self.editActions.append(act)
960
961 act = E4Action(QApplication.translate('ViewManager', 'Delete line to right'),
962 QApplication.translate('ViewManager', 'Delete line to right'),
963 QKeySequence(QApplication.translate('ViewManager',
964 'Ctrl+Shift+Del')),
965 0,
966 self.editorActGrp, 'vm_edit_delete_line_right')
967 self.esm.setMapping(act, QsciScintilla.SCI_DELLINERIGHT)
968 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
969 self.editActions.append(act)
970
971 act = E4Action(QApplication.translate('ViewManager', 'Insert new line'),
972 QApplication.translate('ViewManager', 'Insert new line'),
973 QKeySequence(QApplication.translate('ViewManager', 'Return')),
974 QKeySequence(QApplication.translate('ViewManager', 'Enter')),
975 self.editorActGrp, 'vm_edit_insert_line')
976 self.esm.setMapping(act, QsciScintilla.SCI_NEWLINE)
977 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
978 self.editActions.append(act)
979
980 act = E4Action(QApplication.translate('ViewManager',
981 'Insert new line below current line'),
982 QApplication.translate('ViewManager',
983 'Insert new line below current line'),
984 QKeySequence(QApplication.translate('ViewManager', 'Shift+Return')),
985 QKeySequence(QApplication.translate('ViewManager', 'Shift+Enter')),
986 self.editorActGrp, 'vm_edit_insert_line_below')
987 self.connect(act, SIGNAL('triggered()'), self.__textEdit.newLineBelow)
988 self.editActions.append(act)
989
990 act = E4Action(QApplication.translate('ViewManager', 'Delete current line'),
991 QApplication.translate('ViewManager', 'Delete current line'),
992 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+U')),
993 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Shift+L')),
994 self.editorActGrp, 'vm_edit_delete_current_line')
995 self.esm.setMapping(act, QsciScintilla.SCI_LINEDELETE)
996 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
997 self.editActions.append(act)
998
999 act = E4Action(QApplication.translate('ViewManager', 'Duplicate current line'),
1000 QApplication.translate('ViewManager', 'Duplicate current line'),
1001 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+D')), 0,
1002 self.editorActGrp, 'vm_edit_duplicate_current_line')
1003 self.esm.setMapping(act, QsciScintilla.SCI_LINEDUPLICATE)
1004 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1005 self.editActions.append(act)
1006
1007 act = E4Action(QApplication.translate('ViewManager',
1008 'Swap current and previous lines'),
1009 QApplication.translate('ViewManager',
1010 'Swap current and previous lines'),
1011 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+T')), 0,
1012 self.editorActGrp, 'vm_edit_swap_current_previous_line')
1013 self.esm.setMapping(act, QsciScintilla.SCI_LINETRANSPOSE)
1014 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1015 self.editActions.append(act)
1016
1017 act = E4Action(QApplication.translate('ViewManager', 'Cut current line'),
1018 QApplication.translate('ViewManager', 'Cut current line'),
1019 QKeySequence(QApplication.translate('ViewManager', 'Alt+Shift+L')),
1020 0,
1021 self.editorActGrp, 'vm_edit_cut_current_line')
1022 self.esm.setMapping(act, QsciScintilla.SCI_LINECUT)
1023 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1024 self.editActions.append(act)
1025
1026 act = E4Action(QApplication.translate('ViewManager', 'Copy current line'),
1027 QApplication.translate('ViewManager', 'Copy current line'),
1028 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Shift+T')),
1029 0,
1030 self.editorActGrp, 'vm_edit_copy_current_line')
1031 self.esm.setMapping(act, QsciScintilla.SCI_LINECOPY)
1032 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1033 self.editActions.append(act)
1034
1035 act = E4Action(QApplication.translate('ViewManager', 'Toggle insert/overtype'),
1036 QApplication.translate('ViewManager', 'Toggle insert/overtype'),
1037 QKeySequence(QApplication.translate('ViewManager', 'Ins')), 0,
1038 self.editorActGrp, 'vm_edit_toggle_insert_overtype')
1039 self.esm.setMapping(act, QsciScintilla.SCI_EDITTOGGLEOVERTYPE)
1040 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1041 self.editActions.append(act)
1042
1043 act = E4Action(QApplication.translate('ViewManager',
1044 'Convert selection to lower case'),
1045 QApplication.translate('ViewManager',
1046 'Convert selection to lower case'),
1047 QKeySequence(QApplication.translate('ViewManager', 'Alt+Shift+U')),
1048 0,
1049 self.editorActGrp, 'vm_edit_convert_selection_lower')
1050 self.esm.setMapping(act, QsciScintilla.SCI_LOWERCASE)
1051 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1052 self.editActions.append(act)
1053
1054 act = E4Action(QApplication.translate('ViewManager',
1055 'Convert selection to upper case'),
1056 QApplication.translate('ViewManager',
1057 'Convert selection to upper case'),
1058 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Shift+U')),
1059 0,
1060 self.editorActGrp, 'vm_edit_convert_selection_upper')
1061 self.esm.setMapping(act, QsciScintilla.SCI_UPPERCASE)
1062 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1063 self.editActions.append(act)
1064
1065 act = E4Action(QApplication.translate('ViewManager',
1066 'Move to end of displayed line'),
1067 QApplication.translate('ViewManager',
1068 'Move to end of displayed line'),
1069 QKeySequence(QApplication.translate('ViewManager', 'Alt+End')), 0,
1070 self.editorActGrp, 'vm_edit_move_end_displayed_line')
1071 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDDISPLAY)
1072 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1073 self.editActions.append(act)
1074
1075 act = E4Action(QApplication.translate('ViewManager',
1076 'Extend selection to end of displayed line'),
1077 QApplication.translate('ViewManager',
1078 'Extend selection to end of displayed line'),
1079 0, 0,
1080 self.editorActGrp, 'vm_edit_extend_selection_end_displayed_line')
1081 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDDISPLAYEXTEND)
1082 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1083 self.editActions.append(act)
1084
1085 act = E4Action(QApplication.translate('ViewManager', 'Formfeed'),
1086 QApplication.translate('ViewManager', 'Formfeed'),
1087 0, 0,
1088 self.editorActGrp, 'vm_edit_formfeed')
1089 self.esm.setMapping(act, QsciScintilla.SCI_FORMFEED)
1090 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1091 self.editActions.append(act)
1092
1093 act = E4Action(QApplication.translate('ViewManager', 'Escape'),
1094 QApplication.translate('ViewManager', 'Escape'),
1095 QKeySequence(QApplication.translate('ViewManager', 'Esc')), 0,
1096 self.editorActGrp, 'vm_edit_escape')
1097 self.esm.setMapping(act, QsciScintilla.SCI_CANCEL)
1098 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1099 self.editActions.append(act)
1100
1101 act = E4Action(QApplication.translate('ViewManager',
1102 'Extend rectangular selection down one line'),
1103 QApplication.translate('ViewManager',
1104 'Extend rectangular selection down one line'),
1105 QKeySequence(QApplication.translate('ViewManager',
1106 'Alt+Ctrl+Down')),
1107 0,
1108 self.editorActGrp, 'vm_edit_extend_rect_selection_down_line')
1109 self.esm.setMapping(act, QsciScintilla.SCI_LINEDOWNRECTEXTEND)
1110 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1111 self.editActions.append(act)
1112
1113 act = E4Action(QApplication.translate('ViewManager',
1114 'Extend rectangular selection up one line'),
1115 QApplication.translate('ViewManager',
1116 'Extend rectangular selection up one line'),
1117 QKeySequence(QApplication.translate('ViewManager', 'Alt+Ctrl+Up')),
1118 0,
1119 self.editorActGrp, 'vm_edit_extend_rect_selection_up_line')
1120 self.esm.setMapping(act, QsciScintilla.SCI_LINEUPRECTEXTEND)
1121 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1122 self.editActions.append(act)
1123
1124 act = E4Action(QApplication.translate('ViewManager',
1125 'Extend rectangular selection left one character'),
1126 QApplication.translate('ViewManager',
1127 'Extend rectangular selection left one character'),
1128 QKeySequence(QApplication.translate('ViewManager',
1129 'Alt+Ctrl+Left')),
1130 0,
1131 self.editorActGrp, 'vm_edit_extend_rect_selection_left_char')
1132 self.esm.setMapping(act, QsciScintilla.SCI_CHARLEFTRECTEXTEND)
1133 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1134 self.editActions.append(act)
1135
1136 act = E4Action(QApplication.translate('ViewManager',
1137 'Extend rectangular selection right one character'),
1138 QApplication.translate('ViewManager',
1139 'Extend rectangular selection right one character'),
1140 QKeySequence(QApplication.translate('ViewManager',
1141 'Alt+Ctrl+Right')),
1142 0,
1143 self.editorActGrp, 'vm_edit_extend_rect_selection_right_char')
1144 self.esm.setMapping(act, QsciScintilla.SCI_CHARRIGHTRECTEXTEND)
1145 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1146 self.editActions.append(act)
1147
1148 act = E4Action(QApplication.translate('ViewManager',
1149 'Extend rectangular selection to first'
1150 ' visible character in line'),
1151 QApplication.translate('ViewManager',
1152 'Extend rectangular selection to first'
1153 ' visible character in line'),
1154 QKeySequence(QApplication.translate('ViewManager',
1155 'Alt+Ctrl+Home')),
1156 0,
1157 self.editorActGrp,
1158 'vm_edit_extend_rect_selection_first_visible_char')
1159 self.esm.setMapping(act, QsciScintilla.SCI_VCHOMERECTEXTEND)
1160 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1161 self.editActions.append(act)
1162
1163 act = E4Action(QApplication.translate('ViewManager',
1164 'Extend rectangular selection to end of line'),
1165 QApplication.translate('ViewManager',
1166 'Extend rectangular selection to end of line'),
1167 QKeySequence(QApplication.translate('ViewManager', 'Alt+Ctrl+End')),
1168 0,
1169 self.editorActGrp, 'vm_edit_extend_rect_selection_end_line')
1170 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDRECTEXTEND)
1171 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1172 self.editActions.append(act)
1173
1174 act = E4Action(QApplication.translate('ViewManager',
1175 'Extend rectangular selection up one page'),
1176 QApplication.translate('ViewManager',
1177 'Extend rectangular selection up one page'),
1178 QKeySequence(QApplication.translate('ViewManager',
1179 'Alt+Ctrl+PgUp')),
1180 0,
1181 self.editorActGrp, 'vm_edit_extend_rect_selection_up_page')
1182 self.esm.setMapping(act, QsciScintilla.SCI_PAGEUPRECTEXTEND)
1183 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1184 self.editActions.append(act)
1185
1186 act = E4Action(QApplication.translate('ViewManager',
1187 'Extend rectangular selection down one page'),
1188 QApplication.translate('ViewManager',
1189 'Extend rectangular selection down one page'),
1190 QKeySequence(QApplication.translate('ViewManager',
1191 'Alt+Ctrl+PgDown')),
1192 0,
1193 self.editorActGrp, 'vm_edit_extend_rect_selection_down_page')
1194 self.esm.setMapping(act, QsciScintilla.SCI_PAGEDOWNRECTEXTEND)
1195 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1196 self.editActions.append(act)
1197
1198 act = E4Action(QApplication.translate('ViewManager',
1199 'Duplicate current selection'),
1200 QApplication.translate('ViewManager',
1201 'Duplicate current selection'),
1202 QKeySequence(QApplication.translate('ViewManager', 'Ctrl+Shift+D')),
1203 0,
1204 self.editorActGrp, 'vm_edit_duplicate_current_selection')
1205 self.esm.setMapping(act, QsciScintilla.SCI_SELECTIONDUPLICATE)
1206 self.connect(act, SIGNAL('triggered()'), self.esm, SLOT('map()'))
1207 self.editActions.append(act)
1208
1209 self.__textEdit.addActions(self.editorActGrp.actions())
1210
1211 def __createSearchActions(self):
1212 """
1213 Private method defining the user interface actions for the search commands.
1214 """
1215 self.searchAct = E4Action(QApplication.translate('ViewManager', 'Search'),
1216 UI.PixmapCache.getIcon("find.png"),
1217 QApplication.translate('ViewManager', '&Search...'),
1218 QKeySequence(QApplication.translate('ViewManager',
1219 "Ctrl+F", "Search|Search")),
1220 0,
1221 self, 'vm_search')
1222 self.searchAct.setStatusTip(QApplication.translate('ViewManager',
1223 'Search for a text'))
1224 self.searchAct.setWhatsThis(QApplication.translate('ViewManager',
1225 """<b>Search</b>"""
1226 """<p>Search for some text in the current editor. A"""
1227 """ dialog is shown to enter the searchtext and options"""
1228 """ for the search.</p>"""
1229 ))
1230 self.connect(self.searchAct, SIGNAL('triggered()'), self.__search)
1231 self.searchActions.append(self.searchAct)
1232
1233 self.searchNextAct = E4Action(QApplication.translate('ViewManager',
1234 'Search next'),
1235 UI.PixmapCache.getIcon("findNext.png"),
1236 QApplication.translate('ViewManager', 'Search &next'),
1237 QKeySequence(QApplication.translate('ViewManager',
1238 "F3", "Search|Search next")),
1239 0,
1240 self, 'vm_search_next')
1241 self.searchNextAct.setStatusTip(QApplication.translate('ViewManager',
1242 'Search next occurrence of text'))
1243 self.searchNextAct.setWhatsThis(QApplication.translate('ViewManager',
1244 """<b>Search next</b>"""
1245 """<p>Search the next occurrence of some text in the current editor."""
1246 """ The previously entered searchtext and options are reused.</p>"""
1247 ))
1248 self.connect(self.searchNextAct, SIGNAL('triggered()'), self.searchDlg.findNext)
1249 self.searchActions.append(self.searchNextAct)
1250
1251 self.searchPrevAct = E4Action(QApplication.translate('ViewManager',
1252 'Search previous'),
1253 UI.PixmapCache.getIcon("findPrev.png"),
1254 QApplication.translate('ViewManager', 'Search &previous'),
1255 QKeySequence(QApplication.translate('ViewManager',
1256 "Shift+F3", "Search|Search previous")),
1257 0,
1258 self, 'vm_search_previous')
1259 self.searchPrevAct.setStatusTip(QApplication.translate('ViewManager',
1260 'Search previous occurrence of text'))
1261 self.searchPrevAct.setWhatsThis(QApplication.translate('ViewManager',
1262 """<b>Search previous</b>"""
1263 """<p>Search the previous occurrence of some text in the current editor."""
1264 """ The previously entered searchtext and options are reused.</p>"""
1265 ))
1266 self.connect(self.searchPrevAct, SIGNAL('triggered()'), self.searchDlg.findPrev)
1267 self.searchActions.append(self.searchPrevAct)
1268
1269 self.searchClearMarkersAct = E4Action(QApplication.translate('ViewManager',
1270 'Clear search markers'),
1271 UI.PixmapCache.getIcon("findClear.png"),
1272 QApplication.translate('ViewManager', 'Clear search markers'),
1273 QKeySequence(QApplication.translate('ViewManager',
1274 "Ctrl+3", "Search|Clear search markers")),
1275 0,
1276 self, 'vm_clear_search_markers')
1277 self.searchClearMarkersAct.setStatusTip(QApplication.translate('ViewManager',
1278 'Clear all displayed search markers'))
1279 self.searchClearMarkersAct.setWhatsThis(QApplication.translate('ViewManager',
1280 """<b>Clear search markers</b>"""
1281 """<p>Clear all displayed search markers.</p>"""
1282 ))
1283 self.connect(self.searchClearMarkersAct, SIGNAL('triggered()'),
1284 self.__searchClearMarkers)
1285 self.searchActions.append(self.searchClearMarkersAct)
1286
1287 self.replaceAct = E4Action(QApplication.translate('ViewManager', 'Replace'),
1288 QApplication.translate('ViewManager', '&Replace...'),
1289 QKeySequence(QApplication.translate('ViewManager',
1290 "Ctrl+R", "Search|Replace")),
1291 0,
1292 self, 'vm_search_replace')
1293 self.replaceAct.setStatusTip(QApplication.translate('ViewManager',
1294 'Replace some text'))
1295 self.replaceAct.setWhatsThis(QApplication.translate('ViewManager',
1296 """<b>Replace</b>"""
1297 """<p>Search for some text in the current editor and replace it. A"""
1298 """ dialog is shown to enter the searchtext, the replacement text"""
1299 """ and options for the search and replace.</p>"""
1300 ))
1301 self.connect(self.replaceAct, SIGNAL('triggered()'), self.__replace)
1302 self.searchActions.append(self.replaceAct)
1303
1304 def __createHelpActions(self):
1305 """
1306 Private method to create the Help actions.
1307 """
1308 self.aboutAct = E4Action(self.trUtf8('About'),
1309 self.trUtf8('&About'),
1310 0, 0, self, 'about_eric')
1311 self.aboutAct.setStatusTip(self.trUtf8('Display information about this software'))
1312 self.aboutAct.setWhatsThis(self.trUtf8(
1313 """<b>About</b>"""
1314 """<p>Display some information about this software.</p>"""))
1315 self.connect(self.aboutAct, SIGNAL('triggered()'), self.__about)
1316 self.helpActions.append(self.aboutAct)
1317
1318 self.aboutQtAct = E4Action(self.trUtf8('About Qt'),
1319 self.trUtf8('About &Qt'), 0, 0, self, 'about_qt')
1320 self.aboutQtAct.setStatusTip(\
1321 self.trUtf8('Display information about the Qt toolkit'))
1322 self.aboutQtAct.setWhatsThis(self.trUtf8(
1323 """<b>About Qt</b>"""
1324 """<p>Display some information about the Qt toolkit.</p>"""
1325 ))
1326 self.connect(self.aboutQtAct, SIGNAL('triggered()'), self.__aboutQt)
1327 self.helpActions.append(self.aboutQtAct)
1328
1329 self.whatsThisAct = E4Action(self.trUtf8('What\'s This?'),
1330 UI.PixmapCache.getIcon("whatsThis.png"),
1331 self.trUtf8('&What\'s This?'),
1332 QKeySequence(self.trUtf8("Shift+F1","Help|What's This?'")),
1333 0, self, 'help_help_whats_this')
1334 self.whatsThisAct.setStatusTip(self.trUtf8('Context sensitive help'))
1335 self.whatsThisAct.setWhatsThis(self.trUtf8(
1336 """<b>Display context sensitive help</b>"""
1337 """<p>In What's This? mode, the mouse cursor shows an arrow with a"""
1338 """ question mark, and you can click on the interface elements to get"""
1339 """ a short description of what they do and how to use them. In"""
1340 """ dialogs, this feature can be accessed using the context help button"""
1341 """ in the titlebar.</p>"""
1342 ))
1343 self.connect(self.whatsThisAct, SIGNAL('triggered()'), self.__whatsThis)
1344 self.helpActions.append(self.whatsThisAct)
1345
1346 def __createMenus(self):
1347 """
1348 Private method to create the menus of the menu bar.
1349 """
1350 self.fileMenu = self.menuBar().addMenu(self.trUtf8("&File"))
1351 self.fileMenu.addAction(self.newAct)
1352 self.fileMenu.addAction(self.openAct)
1353 self.fileMenu.addAction(self.saveAct)
1354 self.fileMenu.addAction(self.saveAsAct)
1355 self.fileMenu.addSeparator()
1356 self.fileMenu.addAction(self.printPreviewAct)
1357 self.fileMenu.addAction(self.printAct)
1358 self.fileMenu.addSeparator()
1359 self.fileMenu.addAction(self.closeAct)
1360
1361 self.editMenu = self.menuBar().addMenu(self.trUtf8("&Edit"));
1362 self.editMenu.addAction(self.undoAct)
1363 self.editMenu.addAction(self.redoAct)
1364 self.editMenu.addSeparator()
1365 self.editMenu.addAction(self.cutAct)
1366 self.editMenu.addAction(self.copyAct)
1367 self.editMenu.addAction(self.pasteAct)
1368 self.editMenu.addAction(self.deleteAct)
1369 self.editMenu.addSeparator()
1370 self.editMenu.addAction(self.searchAct)
1371 self.editMenu.addAction(self.searchNextAct)
1372 self.editMenu.addAction(self.searchPrevAct)
1373 self.editMenu.addAction(self.searchClearMarkersAct)
1374 self.editMenu.addAction(self.replaceAct)
1375
1376 self.menuBar().addSeparator()
1377
1378 self.helpMenu = self.menuBar().addMenu(self.trUtf8("&Help"))
1379 self.helpMenu.addAction(self.aboutAct)
1380 self.helpMenu.addAction(self.aboutQtAct)
1381 self.helpMenu.addSeparator()
1382 self.helpMenu.addAction(self.whatsThisAct)
1383
1384 self.__initContextMenu()
1385
1386 def __createToolBars(self):
1387 """
1388 Private method to create the various toolbars.
1389 """
1390 filetb = self.addToolBar(self.trUtf8("File"))
1391 filetb.setIconSize(UI.Config.ToolBarIconSize)
1392 filetb.addAction(self.newAct)
1393 filetb.addAction(self.openAct)
1394 filetb.addAction(self.saveAct)
1395 filetb.addAction(self.saveAsAct)
1396 filetb.addSeparator()
1397 filetb.addAction(self.printPreviewAct)
1398 filetb.addAction(self.printAct)
1399 filetb.addSeparator()
1400 filetb.addAction(self.closeAct)
1401
1402 edittb = self.addToolBar(self.trUtf8("Edit"))
1403 edittb.setIconSize(UI.Config.ToolBarIconSize)
1404 edittb.addAction(self.undoAct)
1405 edittb.addAction(self.redoAct)
1406 edittb.addSeparator()
1407 edittb.addAction(self.cutAct)
1408 edittb.addAction(self.copyAct)
1409 edittb.addAction(self.pasteAct)
1410 edittb.addAction(self.deleteAct)
1411
1412 findtb = self.addToolBar(self.trUtf8("Find"))
1413 findtb.setIconSize(UI.Config.ToolBarIconSize)
1414 findtb.addAction(self.searchAct)
1415 findtb.addAction(self.searchNextAct)
1416 findtb.addAction(self.searchPrevAct)
1417 findtb.addAction(self.searchClearMarkersAct)
1418
1419 helptb = self.addToolBar(self.trUtf8("Help"))
1420 helptb.setIconSize(UI.Config.ToolBarIconSize)
1421 helptb.addAction(self.whatsThisAct)
1422
1423 def __createStatusBar(self):
1424 """
1425 Private method to initialize the status bar.
1426 """
1427 self.__statusBar = self.statusBar()
1428 self.__statusBar.setSizeGripEnabled(True)
1429
1430 self.sbWritable = QLabel(self.__statusBar)
1431 self.__statusBar.addPermanentWidget(self.sbWritable)
1432 self.sbWritable.setWhatsThis(self.trUtf8(
1433 """<p>This part of the status bar displays an indication of the"""
1434 """ editors files writability.</p>"""
1435 ))
1436
1437 self.sbLine = QLabel(self.__statusBar)
1438 self.__statusBar.addPermanentWidget(self.sbLine)
1439 self.sbLine.setWhatsThis(self.trUtf8(
1440 """<p>This part of the status bar displays the line number of the"""
1441 """ editor.</p>"""
1442 ))
1443
1444 self.sbPos = QLabel(self.__statusBar)
1445 self.__statusBar.addPermanentWidget(self.sbPos)
1446 self.sbPos.setWhatsThis(self.trUtf8(
1447 """<p>This part of the status bar displays the cursor position of"""
1448 """ the editor.</p>"""
1449 ))
1450
1451 self.__statusBar.showMessage(self.trUtf8("Ready"))
1452
1453 def __readSettings(self):
1454 """
1455 Private method to read the settings remembered last time.
1456 """
1457 settings = Preferences.Prefs.settings
1458 pos = settings.value("MiniEditor/Position", QVariant(QPoint(0, 0))).toPoint()
1459 size = settings.value("MiniEditor/Size", QVariant(QSize(800, 600))).toSize()
1460 self.resize(size)
1461 self.move(pos)
1462
1463 def __writeSettings(self):
1464 """
1465 Private method to write the settings for reuse.
1466 """
1467 settings = Preferences.Prefs.settings
1468 settings.setValue("MiniEditor/Position", QVariant(self.pos()))
1469 settings.setValue("MiniEditor/Size", QVariant(self.size()))
1470
1471 def __maybeSave(self):
1472 """
1473 Private method to ask the user to save the file, if it was modified.
1474
1475 @return flag indicating, if it is ok to continue (boolean)
1476 """
1477 if self.__textEdit.isModified():
1478 ret = QMessageBox.warning(self,
1479 self.trUtf8("eric4 Mini Editor"),
1480 self.trUtf8("The document has been modified.\n"
1481 "Do you want to save your changes?"),
1482 QMessageBox.StandardButtons(\
1483 QMessageBox.Cancel | \
1484 QMessageBox.No | \
1485 QMessageBox.Yes),
1486 QMessageBox.Cancel)
1487 if ret == QMessageBox.Yes:
1488 return self.__save()
1489 elif ret == QMessageBox.Cancel:
1490 return False
1491 return True
1492
1493 def __loadFile(self, fileName, filetype = None):
1494 """
1495 Private method to load the given file.
1496
1497 @param fileName name of the file to load (string)
1498 @param filetype type of the source file (string)
1499 """
1500 file= QFile(fileName)
1501 if not file.open(QFile.ReadOnly):
1502 QMessageBox.warning(self, self.trUtf8("eric4 Mini Editor"),
1503 self.trUtf8("Cannot read file {0}:\n{1}.")\
1504 .format(fileName, file.errorString()))
1505 return
1506
1507 input = QTextStream(file)
1508 QApplication.setOverrideCursor(Qt.WaitCursor)
1509 txt = input.readAll()
1510 self.__textEdit.setText(txt)
1511 QApplication.restoreOverrideCursor()
1512
1513 if filetype is None:
1514 self.filetype = ""
1515 else:
1516 self.filetype = filetype
1517 self.__setCurrentFile(fileName)
1518
1519 fileEol = self.__textEdit.detectEolString(txt)
1520 self.__textEdit.setEolModeByEolString(fileEol)
1521
1522 self.__statusBar.showMessage(self.trUtf8("File loaded"), 2000)
1523
1524 def __saveFile(self, fileName):
1525 """
1526 Private method to save to the given file.
1527
1528 @param fileName name of the file to save to (string)
1529 @return flag indicating success (boolean)
1530 """
1531 file = QFile(fileName)
1532 if not file.open(QFile.WriteOnly):
1533 QMessageBox.warning(self, self.trUtf8("eric4 Mini Editor"),
1534 self.trUtf8("Cannot write file {0}:\n{1}.")\
1535 .format(fileName, file.errorString()))
1536
1537 self.__checkActions()
1538
1539 return False
1540
1541 out = QTextStream(file)
1542 QApplication.setOverrideCursor(Qt.WaitCursor)
1543 out << self.__textEdit.text()
1544 QApplication.restoreOverrideCursor()
1545 self.emit(SIGNAL("editorSaved"))
1546
1547 self.__setCurrentFile(fileName)
1548 self.__statusBar.showMessage(self.trUtf8("File saved"), 2000)
1549
1550 self.__checkActions()
1551
1552 return True
1553
1554 def __setCurrentFile(self, fileName):
1555 """
1556 Private method to register the file name of the current file.
1557
1558 @param fileName name of the file to register (string)
1559 """
1560 self.__curFile = fileName
1561
1562 if not self.__curFile:
1563 shownName = self.trUtf8("Untitled")
1564 else:
1565 shownName = self.__strippedName(self.__curFile)
1566
1567 self.setWindowTitle(self.trUtf8("{0}[*] - {1}")\
1568 .format(shownName, self.trUtf8("Mini Editor")))
1569
1570 self.__textEdit.setModified(False)
1571 self.setWindowModified(False)
1572
1573 try:
1574 line0 = self.readLine0(self.__curFile)
1575 except IOError:
1576 line0 = ""
1577 self.setLanguage(self.__bindName(line0))
1578
1579 def getFileName(self):
1580 """
1581 Public method to return the name of the file being displayed.
1582
1583 @return filename of the displayed file (string)
1584 """
1585 return self.__curFile
1586
1587 def __strippedName(self, fullFileName):
1588 """
1589 Private method to return the filename part of the given path.
1590
1591 @param fullFileName full pathname of the given file (string)
1592 @return filename part (string)
1593 """
1594 return QFileInfo(fullFileName).fileName()
1595
1596 def __modificationChanged(self, m):
1597 """
1598 Private slot to handle the modificationChanged signal.
1599
1600 @param m modification status
1601 """
1602 self.setWindowModified(m)
1603 self.__checkActions()
1604
1605 def __cursorPositionChanged(self, line, pos):
1606 """
1607 Private slot to handle the cursorPositionChanged signal.
1608
1609 @param line line number of the cursor
1610 @param pos position in line of the cursor
1611 """
1612 self.__setSbFile(line + 1, pos)
1613
1614 if Preferences.getEditor("MarkOccurrencesEnabled"):
1615 self.__markOccurrencesTimer.stop()
1616 self.__markOccurrencesTimer.start()
1617
1618 def __undo(self):
1619 """
1620 Public method to undo the last recorded change.
1621 """
1622 self.__textEdit.undo()
1623 self.__checkActions()
1624
1625 def __redo(self):
1626 """
1627 Public method to redo the last recorded change.
1628 """
1629 self.__textEdit.redo()
1630 self.__checkActions()
1631
1632 def __selectAll(self):
1633 """
1634 Private slot handling the select all context menu action.
1635 """
1636 self.__textEdit.selectAll(True)
1637
1638 def __deselectAll(self):
1639 """
1640 Private slot handling the deselect all context menu action.
1641 """
1642 self.__textEdit.selectAll(False)
1643
1644 def __setMargins(self):
1645 """
1646 Private method to configure the margins.
1647 """
1648 # set the settings for all margins
1649 self.__textEdit.setMarginsFont(Preferences.getEditorOtherFonts("MarginsFont"))
1650 self.__textEdit.setMarginsForegroundColor(
1651 Preferences.getEditorColour("MarginsForeground"))
1652 self.__textEdit.setMarginsBackgroundColor(
1653 Preferences.getEditorColour("MarginsBackground"))
1654
1655 # set margin 0 settings
1656 linenoMargin = Preferences.getEditor("LinenoMargin")
1657 self.__textEdit.setMarginLineNumbers(0, linenoMargin)
1658 if linenoMargin:
1659 self.__textEdit.setMarginWidth(0,
1660 ' ' + '8' * Preferences.getEditor("LinenoWidth"))
1661 else:
1662 self.__textEdit.setMarginWidth(0, 16)
1663
1664 # set margin 1 settings
1665 self.__textEdit.setMarginWidth(1, 0)
1666
1667 # set margin 2 settings
1668 self.__textEdit.setMarginWidth(2, 16)
1669 if Preferences.getEditor("FoldingMargin"):
1670 folding = Preferences.getEditor("FoldingStyle")
1671 try:
1672 folding = QsciScintilla.FoldStyle(folding)
1673 except AttributeError:
1674 pass
1675 self.__textEdit.setFolding(folding)
1676 self.__textEdit.setFoldMarginColors(
1677 Preferences.getEditorColour("FoldmarginBackground"),
1678 Preferences.getEditorColour("FoldmarginBackground"))
1679 else:
1680 self.__textEdit.setFolding(QsciScintilla.NoFoldStyle)
1681
1682 def __setTextDisplay(self):
1683 """
1684 Private method to configure the text display.
1685 """
1686 self.__textEdit.setTabWidth(Preferences.getEditor("TabWidth"))
1687 self.__textEdit.setIndentationWidth(Preferences.getEditor("IndentWidth"))
1688 if self.lexer_ and self.lexer_.alwaysKeepTabs():
1689 self.__textEdit.setIndentationsUseTabs(True)
1690 else:
1691 self.__textEdit.setIndentationsUseTabs(\
1692 Preferences.getEditor("TabForIndentation"))
1693 self.__textEdit.setTabIndents(Preferences.getEditor("TabIndents"))
1694 self.__textEdit.setBackspaceUnindents(Preferences.getEditor("TabIndents"))
1695 self.__textEdit.setIndentationGuides(Preferences.getEditor("IndentationGuides"))
1696 if Preferences.getEditor("ShowWhitespace"):
1697 self.__textEdit.setWhitespaceVisibility(QsciScintilla.WsVisible)
1698 else:
1699 self.__textEdit.setWhitespaceVisibility(QsciScintilla.WsInvisible)
1700 self.__textEdit.setEolVisibility(Preferences.getEditor("ShowEOL"))
1701 self.__textEdit.setAutoIndent(Preferences.getEditor("AutoIndentation"))
1702 if Preferences.getEditor("BraceHighlighting"):
1703 self.__textEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch)
1704 else:
1705 self.__textEdit.setBraceMatching(QsciScintilla.NoBraceMatch)
1706 self.__textEdit.setMatchedBraceForegroundColor(
1707 Preferences.getEditorColour("MatchingBrace"))
1708 self.__textEdit.setMatchedBraceBackgroundColor(
1709 Preferences.getEditorColour("MatchingBraceBack"))
1710 self.__textEdit.setUnmatchedBraceForegroundColor(
1711 Preferences.getEditorColour("NonmatchingBrace"))
1712 self.__textEdit.setUnmatchedBraceBackgroundColor(
1713 Preferences.getEditorColour("NonmatchingBraceBack"))
1714 if Preferences.getEditor("CustomSelectionColours"):
1715 self.__textEdit.setSelectionBackgroundColor(\
1716 Preferences.getEditorColour("SelectionBackground"))
1717 else:
1718 self.__textEdit.setSelectionBackgroundColor(\
1719 QApplication.palette().color(QPalette.Highlight))
1720 if Preferences.getEditor("ColourizeSelText"):
1721 self.__textEdit.resetSelectionForegroundColor()
1722 elif Preferences.getEditor("CustomSelectionColours"):
1723 self.__textEdit.setSelectionForegroundColor(\
1724 Preferences.getEditorColour("SelectionForeground"))
1725 else:
1726 self.__textEdit.setSelectionForegroundColor(\
1727 QApplication.palette().color(QPalette.HighlightedText))
1728 self.__textEdit.setSelectionToEol(Preferences.getEditor("ExtendSelectionToEol"))
1729 self.__textEdit.setCaretForegroundColor(
1730 Preferences.getEditorColour("CaretForeground"))
1731 self.__textEdit.setCaretLineBackgroundColor(
1732 Preferences.getEditorColour("CaretLineBackground"))
1733 self.__textEdit.setCaretLineVisible(Preferences.getEditor("CaretLineVisible"))
1734 self.caretWidth = Preferences.getEditor("CaretWidth")
1735 self.__textEdit.setCaretWidth(self.caretWidth)
1736 self.useMonospaced = Preferences.getEditor("UseMonospacedFont")
1737 self.__setMonospaced(self.useMonospaced)
1738 edgeMode = Preferences.getEditor("EdgeMode")
1739 edge = QsciScintilla.EdgeMode(edgeMode)
1740 self.__textEdit.setEdgeMode(edge)
1741 if edgeMode:
1742 self.__textEdit.setEdgeColumn(Preferences.getEditor("EdgeColumn"))
1743 self.__textEdit.setEdgeColor(Preferences.getEditorColour("Edge"))
1744
1745 if Preferences.getEditor("WrapLongLines"):
1746 self.__textEdit.setWrapMode(QsciScintilla.WrapWord)
1747 self.__textEdit.setWrapVisualFlags(\
1748 QsciScintilla.WrapFlagByBorder, QsciScintilla.WrapFlagByBorder)
1749 else:
1750 self.__textEdit.setWrapMode(QsciScintilla.WrapNone)
1751 self.__textEdit.setWrapVisualFlags(\
1752 QsciScintilla.WrapFlagNone, QsciScintilla.WrapFlagNone)
1753
1754 self.searchIndicator = QsciScintilla.INDIC_CONTAINER
1755 self.__textEdit.indicatorDefine(self.searchIndicator, QsciScintilla.INDIC_BOX,
1756 Preferences.getEditorColour("SearchMarkers"))
1757
1758 def __setEolMode(self):
1759 """
1760 Private method to configure the eol mode of the editor.
1761 """
1762 eolMode = Preferences.getEditor("EOLMode")
1763 eolMode = QsciScintilla.EolMode(eolMode)
1764 self.__textEdit.setEolMode(eolMode)
1765
1766 def __setMonospaced(self, on):
1767 """
1768 Private method to set/reset a monospaced font.
1769
1770 @param on flag to indicate usage of a monospace font (boolean)
1771 """
1772 if on:
1773 f = Preferences.getEditorOtherFonts("MonospacedFont")
1774 self.__textEdit.monospacedStyles(f)
1775 else:
1776 if not self.lexer_:
1777 self.__textEdit.clearStyles()
1778 self.__setMargins()
1779 self.__textEdit.setFont(Preferences.getEditorOtherFonts("DefaultFont"))
1780
1781 self.useMonospaced = on
1782
1783 def __printFile(self):
1784 """
1785 Private slot to print the text.
1786 """
1787 printer = Printer(mode = QPrinter.HighResolution)
1788 sb = self.statusBar()
1789 printDialog = QPrintDialog(printer, self)
1790 if self.__textEdit.hasSelectedText():
1791 printDialog.addEnabledOption(QAbstractPrintDialog.PrintSelection)
1792 if printDialog.exec_() == QDialog.Accepted:
1793 sb.showMessage(self.trUtf8('Printing...'))
1794 QApplication.processEvents()
1795 if self.__curFile:
1796 printer.setDocName(QFileInfo(self.__curFile).fileName())
1797 else:
1798 printer.setDocName(self.trUtf8("Untitled"))
1799 if printDialog.printRange() == QAbstractPrintDialog.Selection:
1800 # get the selection
1801 fromLine, fromIndex, toLine, toIndex = self.__textEdit.getSelection()
1802 if toIndex == 0:
1803 toLine -= 1
1804 # Qscintilla seems to print one line more than told
1805 res = printer.printRange(self.__textEdit, fromLine, toLine-1)
1806 else:
1807 res = printer.printRange(self.__textEdit)
1808 if res:
1809 sb.showMessage(self.trUtf8('Printing completed'), 2000)
1810 else:
1811 sb.showMessage(self.trUtf8('Error while printing'), 2000)
1812 QApplication.processEvents()
1813 else:
1814 sb.showMessage(self.trUtf8('Printing aborted'), 2000)
1815 QApplication.processEvents()
1816
1817 def __printPreviewFile(self):
1818 """
1819 Private slot to show a print preview of the text.
1820 """
1821 from PyQt4.QtGui import QPrintPreviewDialog
1822
1823 printer = Printer(mode = QPrinter.HighResolution)
1824 if self.__curFile:
1825 printer.setDocName(QFileInfo(self.__curFile).fileName())
1826 else:
1827 printer.setDocName(self.trUtf8("Untitled"))
1828 preview = QPrintPreviewDialog(printer, self)
1829 self.connect(preview, SIGNAL("paintRequested(QPrinter*)"), self.__printPreview)
1830 preview.exec_()
1831
1832 def __printPreview(self, printer):
1833 """
1834 Private slot to generate a print preview.
1835
1836 @param printer reference to the printer object (QScintilla.Printer.Printer)
1837 """
1838 printer.printRange(self.__textEdit)
1839
1840 #########################################################
1841 ## Methods needed by the context menu
1842 #########################################################
1843
1844 def __contextMenuRequested(self, coord):
1845 """
1846 Private slot to show the context menu.
1847
1848 @param coord the position of the mouse pointer (QPoint)
1849 """
1850 self.contextMenu.popup(self.mapToGlobal(coord))
1851
1852 def __initContextMenu(self):
1853 """
1854 Private method used to setup the context menu
1855 """
1856 self.contextMenu = QMenu()
1857
1858 self.languagesMenu = self.__initContextMenuLanguages()
1859
1860 self.contextMenu.addAction(self.undoAct)
1861 self.contextMenu.addAction(self.redoAct)
1862 self.contextMenu.addSeparator()
1863 self.contextMenu.addAction(self.cutAct)
1864 self.contextMenu.addAction(self.copyAct)
1865 self.contextMenu.addAction(self.pasteAct)
1866 self.contextMenu.addSeparator()
1867 self.contextMenu.addAction(self.trUtf8('Select all'), self.__selectAll)
1868 self.contextMenu.addAction(self.trUtf8('Deselect all'), self.__deselectAll)
1869 self.contextMenu.addSeparator()
1870 self.languagesMenuAct = self.contextMenu.addMenu(self.languagesMenu)
1871 self.contextMenu.addSeparator()
1872 self.contextMenu.addAction(self.printPreviewAct)
1873 self.contextMenu.addAction(self.printAct)
1874
1875 def __initContextMenuLanguages(self):
1876 """
1877 Private method used to setup the Languages context sub menu.
1878 """
1879 menu = QMenu(self.trUtf8("Languages"))
1880
1881 self.languagesActGrp = QActionGroup(self)
1882 self.noLanguageAct = menu.addAction(self.trUtf8("No Language"))
1883 self.noLanguageAct.setCheckable(True)
1884 self.noLanguageAct.setData(QVariant("None"))
1885 self.languagesActGrp.addAction(self.noLanguageAct)
1886 menu.addSeparator()
1887
1888 self.supportedLanguages = {}
1889 supportedLanguages = Lexers.getSupportedLanguages()
1890 languages = supportedLanguages.keys()
1891 languages.sort()
1892 for language in languages:
1893 if language != "Guessed":
1894 self.supportedLanguages[language] = supportedLanguages[language][:]
1895 act = menu.addAction(self.supportedLanguages[language][0])
1896 act.setCheckable(True)
1897 act.setData(QVariant(language))
1898 self.supportedLanguages[language].append(act)
1899 self.languagesActGrp.addAction(act)
1900
1901 menu.addSeparator()
1902 self.pygmentsAct = menu.addAction(self.trUtf8("Guessed"))
1903 self.pygmentsAct.setCheckable(True)
1904 self.pygmentsAct.setData(QVariant("Guessed"))
1905 self.languagesActGrp.addAction(self.pygmentsAct)
1906 self.pygmentsSelAct = menu.addAction(self.trUtf8("Alternatives"))
1907 self.pygmentsSelAct.setData(QVariant("Alternatives"))
1908
1909 self.connect(menu, SIGNAL('triggered(QAction *)'), self.__languageMenuTriggered)
1910 self.connect(menu, SIGNAL('aboutToShow()'), self.__showContextMenuLanguages)
1911
1912 return menu
1913
1914 def __showContextMenuLanguages(self):
1915 """
1916 Private slot handling the aboutToShow signal of the languages context menu.
1917 """
1918 if self.apiLanguage.startswith("Pygments|"):
1919 self.pygmentsSelAct.setText(
1920 self.trUtf8("Alternatives ({0})").format(self.getLanguage()))
1921 else:
1922 self.pygmentsSelAct.setText(self.trUtf8("Alternatives"))
1923
1924 def __selectPygmentsLexer(self):
1925 """
1926 Private method to select a specific pygments lexer.
1927
1928 @return name of the selected pygments lexer (string)
1929 """
1930 from pygments.lexers import get_all_lexers
1931 lexerList = sorted([l[0] for l in get_all_lexers()])
1932 try:
1933 lexerSel = lexerList.index(self.getLanguage())
1934 except ValueError:
1935 lexerSel = 0
1936 lexerName, ok = QInputDialog.getItem(\
1937 self,
1938 self.trUtf8("Pygments Lexer"),
1939 self.trUtf8("Select the Pygments lexer to apply."),
1940 lexerList,
1941 lexerSel,
1942 False)
1943 if ok and lexerName:
1944 return lexerName
1945 else:
1946 return ""
1947
1948 def __languageMenuTriggered(self, act):
1949 """
1950 Private method to handle the selection of a lexer language.
1951
1952 @param act reference to the action that was triggered (QAction)
1953 """
1954 if act == self.noLanguageAct:
1955 self.__resetLanguage()
1956 elif act == self.pygmentsAct:
1957 self.setLanguage("dummy.pygments")
1958 elif act == self.pygmentsSelAct:
1959 language = self.__selectPygmentsLexer()
1960 if language:
1961 self.setLanguage("dummy.pygments", pyname = language)
1962 else:
1963 language = act.data().toString()
1964 if language:
1965 self.setLanguage(self.supportedLanguages[language][1])
1966
1967 def __resetLanguage(self):
1968 """
1969 Private method used to reset the language selection.
1970 """
1971 if self.lexer_ is not None and \
1972 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None):
1973 self.disconnect(self.__textEdit, SIGNAL("SCN_STYLENEEDED(int)"),
1974 self.__styleNeeded)
1975
1976 self.apiLanguage = ""
1977 self.lexer_ = None
1978 self.__textEdit.setLexer()
1979 self.__setMonospaced(self.useMonospaced)
1980
1981 def setLanguage(self, filename, initTextDisplay = True, pyname = ""):
1982 """
1983 Public method to set a lexer language.
1984
1985 @param filename filename used to determine the associated lexer language (string)
1986 @param initTextDisplay flag indicating an initialization of the text display
1987 is required as well (boolean)
1988 @keyparam pyname name of the pygments lexer to use (string)
1989 """
1990 self.__bindLexer(filename, pyname = pyname)
1991 self.__textEdit.recolor()
1992 self.__checkLanguage()
1993
1994 # set the text display
1995 if initTextDisplay:
1996 self.__setTextDisplay()
1997 self.__setMargins()
1998
1999 def getLanguage(self):
2000 """
2001 Public method to retrieve the language of the editor.
2002
2003 @return language of the editor (string)
2004 """
2005 if self.apiLanguage == "Guessed" or self.apiLanguage.startswith("Pygments|"):
2006 return self.lexer_.name()
2007 else:
2008 return self.apiLanguage
2009
2010 def __checkLanguage(self):
2011 """
2012 Private method to check the selected language of the language submenu.
2013 """
2014 if self.apiLanguage == "":
2015 self.noLanguageAct.setChecked(True)
2016 elif self.apiLanguage == "Guessed":
2017 self.pygmentsAct.setChecked(True)
2018 elif self.apiLanguage.startswith("Pygments|"):
2019 act = self.languagesActGrp.checkedAction()
2020 if act:
2021 act.setChecked(False)
2022 else:
2023 self.supportedLanguages[self.apiLanguage][2].setChecked(True)
2024
2025 def __bindLexer(self, filename, pyname = ""):
2026 """
2027 Private slot to set the correct lexer depending on language.
2028
2029 @param filename filename used to determine the associated lexer language (string)
2030 @keyparam pyname name of the pygments lexer to use (string)
2031 """
2032 if self.lexer_ is not None and \
2033 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None):
2034 self.disconnect(self.__textEdit, SIGNAL("SCN_STYLENEEDED(int)"),
2035 self.__styleNeeded)
2036
2037 filename = os.path.basename(filename)
2038 language = Preferences.getEditorLexerAssoc(filename)
2039 if language.startswith("Pygments|"):
2040 pyname = language.split("|", 1)[1]
2041 language = ""
2042
2043 self.lexer_ = Lexers.getLexer(language, self.__textEdit, pyname = pyname)
2044 if self.lexer_ is None:
2045 self.__textEdit.setLexer()
2046 self.apiLanguage = ""
2047 return
2048
2049 if pyname:
2050 self.apiLanguage = "Pygments|%s" % pyname
2051 else:
2052 self.apiLanguage = self.lexer_.language()
2053 self.__textEdit.setLexer(self.lexer_)
2054 if self.lexer_.lexer() == "container" or self.lexer_.lexer() is None:
2055 self.__textEdit.setStyleBits(self.lexer_.styleBitsNeeded())
2056 self.connect(self.__textEdit, SIGNAL("SCN_STYLENEEDED(int)"),
2057 self.__styleNeeded)
2058
2059 # get the font for style 0 and set it as the default font
2060 key = 'Scintilla/%s/style0/font' % self.lexer_.language()
2061 fontVariant = Preferences.Prefs.settings.value(key)
2062 if fontVariant.isValid():
2063 fdesc = fontVariant.toStringList()
2064 font = QFont(fdesc[0], int(str(fdesc[1])))
2065 self.lexer_.setDefaultFont(font)
2066 self.lexer_.readSettings(Preferences.Prefs.settings, "Scintilla")
2067
2068 # now set the lexer properties
2069 self.lexer_.initProperties()
2070
2071 # initialize the auto indent style of the lexer
2072 ais = self.lexer_.autoIndentStyle()
2073
2074 def __styleNeeded(self, position):
2075 """
2076 Private slot to handle the need for more styling.
2077
2078 @param position end position, that needs styling (integer)
2079 """
2080 self.lexer_.styleText(self.__textEdit.getEndStyled(), position)
2081
2082 def __bindName(self, line0):
2083 """
2084 Private method to generate a dummy filename for binding a lexer.
2085
2086 @param line0 first line of text to use in the generation process (string)
2087 """
2088 bindName = self.__curFile
2089
2090 if line0.startswith("<?xml"):
2091 # override extension for XML files
2092 bindName = "dummy.xml"
2093
2094 # check filetype
2095 if self.filetype == "Python":
2096 bindName = "dummy.py"
2097 elif self.filetype == "Ruby":
2098 bindName = "dummy.rb"
2099 elif self.filetype == "D":
2100 bindName = "dummy.d"
2101 elif self.filetype == "Properties":
2102 bindName = "dummy.ini"
2103
2104 # #! marker detection
2105 if line0.startswith("#!"):
2106 if "python3" in line0:
2107 bindName = "dummy.py"
2108 self.filetype = "Python3"
2109 elif "python2" in line0:
2110 bindName = "dummy.py"
2111 self.filetype = "Python"
2112 elif "python" in line0:
2113 bindName = "dummy.py"
2114 self.filetype = "Python"
2115 elif ("/bash" in line0 or "/sh" in line0):
2116 bindName = "dummy.sh"
2117 elif "ruby" in line0:
2118 bindName = "dummy.rb"
2119 self.filetype = "Ruby"
2120 elif "perl" in line0:
2121 bindName = "dummy.pl"
2122 elif "lua" in line0:
2123 bindName = "dummy.lua"
2124 elif "dmd" in line0:
2125 bindName = "dummy.d"
2126 self.filetype = "D"
2127 return bindName
2128
2129 def readLine0(self, fn, createIt = False):
2130 """
2131 Public slot to read the first line from a file.
2132
2133 @param fn filename to read from (string)
2134 @param createIt flag indicating the creation of a new file, if the given
2135 one doesn't exist (boolean)
2136 @return first line of the file (string)
2137 """
2138 if not fn:
2139 return ""
2140
2141 try:
2142 if createIt and not os.path.exists(fn):
2143 f = open(fn, "wb")
2144 f.close()
2145 f = open(fn, 'rb')
2146 except IOError:
2147 QMessageBox.critical(self, self.trUtf8('Open File'),
2148 self.trUtf8('<p>The file <b>{0}</b> could not be opened.</p>')
2149 .format(fn))
2150 raise
2151
2152 txt = f.readline()
2153 f.close()
2154 return txt
2155
2156 ##########################################################
2157 ## Methods needed for the search functionality
2158 ##########################################################
2159
2160 def getSRHistory(self, key):
2161 """
2162 Public method to get the search or replace history list.
2163
2164 @param key list to return (must be 'search' or 'replace')
2165 @return the requested history list (list of strings)
2166 """
2167 return self.srHistory[key][:]
2168
2169 def textForFind(self):
2170 """
2171 Public method to determine the selection or the current word for the next
2172 find operation.
2173
2174 @return selection or current word (string)
2175 """
2176 if self.__textEdit.hasSelectedText():
2177 text = self.__textEdit.selectedText()
2178 if '\r' in text or '\n' in text:
2179 # the selection contains at least a newline, it is
2180 # unlikely to be the expression to search for
2181 return ''
2182
2183 return text
2184
2185 # no selected text, determine the word at the current position
2186 return self.__getCurrentWord()
2187
2188 def __getWord(self, line, index):
2189 """
2190 Private method to get the word at a position.
2191
2192 @param line number of line to look at (int)
2193 @param index position to look at (int)
2194 @return the word at that position (string)
2195 """
2196 text = self.__textEdit.text(line)
2197 if self.__textEdit.caseSensitive():
2198 cs = Qt.CaseSensitive
2199 else:
2200 cs = Qt.CaseInsensitive
2201 wc = self.__textEdit.wordCharacters()
2202 if wc is None:
2203 regExp = QRegExp('[^\w_]', cs)
2204 else:
2205 regExp = QRegExp('[^%s]' % re.escape(wc), cs)
2206 start = regExp.lastIndexIn(text, index) + 1
2207 end = regExp.indexIn(text, index)
2208 if start == end + 1 and index > 0:
2209 # we are on a word boundary, try again
2210 start = regExp.lastIndexIn(text, index - 1) + 1
2211 if start == -1:
2212 start = 0
2213 if end == -1:
2214 end = len(text)
2215 if end > start:
2216 word = text[start:end]
2217 else:
2218 word = ''
2219 return word
2220
2221 def __getCurrentWord(self):
2222 """
2223 Private method to get the word at the current position.
2224
2225 @return the word at that current position
2226 """
2227 line, index = self.__textEdit.getCursorPosition()
2228 return self.__getWord(line, index)
2229
2230 def __search(self):
2231 """
2232 Private method to handle the search action.
2233 """
2234 self.replaceDlg.close()
2235 self.searchDlg.show(self.textForFind())
2236
2237 def __searchClearMarkers(self):
2238 """
2239 Private method to clear the search markers of the active window.
2240 """
2241 self.clearSearchIndicators()
2242
2243 def __replace(self):
2244 """
2245 Private method to handle the replace action.
2246 """
2247 self.searchDlg.close()
2248 self.replaceDlg.show(self.textForFind())
2249
2250 def activeWindow(self):
2251 """
2252 Public method to fulfill the ViewManager interface.
2253
2254 @return reference to the text edit component (QsciScintillaCompat)
2255 """
2256 return self.__textEdit
2257
2258 def setSearchIndicator(self, startPos, indicLength):
2259 """
2260 Public method to set a search indicator for the given range.
2261
2262 @param startPos start position of the indicator (integer)
2263 @param indicLength length of the indicator (integer)
2264 """
2265 self.__textEdit.setIndicatorRange(self.searchIndicator, startPos, indicLength)
2266
2267 def clearSearchIndicators(self):
2268 """
2269 Public method to clear all search indicators.
2270 """
2271 self.__textEdit.clearAllIndicators(self.searchIndicator)
2272 self.__markedText = ""
2273
2274 def __markOccurrences(self):
2275 """
2276 Private method to mark all occurrences of the current word.
2277 """
2278 word = self.__getCurrentWord()
2279 if not word:
2280 self.clearSearchIndicators()
2281 return
2282
2283 if self.__markedText == word:
2284 return
2285
2286 self.clearSearchIndicators()
2287 ok = self.__textEdit.findFirstTarget(word,
2288 False, self.__textEdit.caseSensitive(), True,
2289 0, 0)
2290 while ok:
2291 tgtPos, tgtLen = self.__textEdit.getFoundTarget()
2292 self.setSearchIndicator(tgtPos, tgtLen)
2293 ok = self.__textEdit.findNextTarget()
2294 self.__markedText = word
2295
2296 ##########################################################
2297 ## Methods exhibiting some QScintilla API methods
2298 ##########################################################
2299
2300 def setText(self, txt, filetype = None):
2301 """
2302 Public method to set the text programatically.
2303
2304 @param txt text to be set (string)
2305 @param filetype type of the source file (string)
2306 """
2307 self.__textEdit.setText(txt)
2308
2309 if filetype is None:
2310 self.filetype = ""
2311 else:
2312 self.filetype = filetype
2313
2314 fileEol = self.__textEdit.detectEolString(txt)
2315 self.__textEdit.setEolModeByEolString(fileEol)
2316
2317 self.__textEdit.setModified(False)

eric ide

mercurial