eric6/Plugins/ViewManagerPlugins/Listspace/Listspace.py

branch
maintenance
changeset 6989
8b8cadf8d7e9
parent 6646
51eefa621de4
parent 6942
2602857055c5
child 7286
7eb04391adf7
equal deleted inserted replaced
6938:7926553b7509 6989:8b8cadf8d7e9
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2002 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the listspace viewmanager class.
8 """
9
10 from __future__ import unicode_literals
11
12 import os
13
14 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QFileInfo, QEvent, Qt
15 from PyQt5.QtWidgets import QStackedWidget, QSplitter, QListWidget, \
16 QListWidgetItem, QSizePolicy, QMenu, QApplication
17
18 from ViewManager.ViewManager import ViewManager
19
20 import QScintilla.Editor
21 from QScintilla.Editor import Editor
22 from QScintilla.EditorAssembly import EditorAssembly
23
24 import UI.PixmapCache
25
26
27 class StackedWidget(QStackedWidget):
28 """
29 Class implementing a custimized StackedWidget.
30 """
31 def __init__(self, parent):
32 """
33 Constructor
34
35 @param parent parent widget
36 @type QWidget
37 """
38 super(StackedWidget, self).__init__(parent)
39
40 self.editors = []
41
42 def addWidget(self, assembly):
43 """
44 Public method to add a new widget.
45
46 @param assembly editor assembly object to be added
47 @type QScintilla.EditorAssembly.EditorAssembly
48 """
49 editor = assembly.getEditor()
50 super(StackedWidget, self).addWidget(assembly)
51 if editor not in self.editors:
52 self.editors.append(editor)
53
54 def removeWidget(self, widget):
55 """
56 Public method to remove a widget.
57
58 @param widget widget to be removed
59 @type QWidget
60 """
61 if isinstance(widget, QScintilla.Editor.Editor):
62 self.editors.remove(widget)
63 widget = widget.parent()
64 super(StackedWidget, self).removeWidget(widget)
65
66 def currentWidget(self):
67 """
68 Public method to get a reference to the current editor.
69
70 @return reference to the current editor
71 @rtype Editor
72 """
73 widget = super(StackedWidget, self).currentWidget()
74 if widget is not None:
75 widget = widget.getEditor()
76 return widget
77
78 def setCurrentWidget(self, widget):
79 """
80 Public method to set the current widget.
81
82 @param widget widget to be made current
83 @type QWidget
84 """
85 if widget is not None:
86 if isinstance(widget, QScintilla.Editor.Editor):
87 self.editors.remove(widget)
88 self.editors.insert(0, widget)
89 widget = widget.parent()
90 super(StackedWidget, self).setCurrentWidget(widget)
91
92 def setCurrentIndex(self, index):
93 """
94 Public method to set the current widget by its index.
95
96 @param index index of widget to be made current
97 @type int
98 """
99 widget = self.widget(index)
100 if widget is not None:
101 self.setCurrentWidget(widget)
102
103 def nextTab(self):
104 """
105 Public slot used to show the next tab.
106 """
107 ind = self.currentIndex() + 1
108 if ind == self.count():
109 ind = 0
110
111 self.setCurrentIndex(ind)
112 self.currentWidget().setFocus()
113
114 def prevTab(self):
115 """
116 Public slot used to show the previous tab.
117 """
118 ind = self.currentIndex() - 1
119 if ind == -1:
120 ind = self.count() - 1
121
122 self.setCurrentIndex(ind)
123 self.currentWidget().setFocus()
124
125 def hasEditor(self, editor):
126 """
127 Public method to check for an editor.
128
129 @param editor editor object to check for
130 @type Editor
131 @return flag indicating, whether the editor to be checked belongs
132 to the list of editors managed by this stacked widget.
133 @rtype bool
134 """
135 return editor in self.editors
136
137 def firstEditor(self):
138 """
139 Public method to retrieve the first editor in the list of managed
140 editors.
141
142 @return first editor in list
143 @rtype QScintilla.Editor.Editor
144 """
145 return len(self.editors) and self.editors[0] or None
146
147
148 class Listspace(ViewManager):
149 """
150 Class implementing the listspace viewmanager class.
151
152 @signal changeCaption(str) emitted if a change of the caption is necessary
153 @signal editorChanged(str) emitted when the current editor has changed
154 @signal editorChangedEd(Editor) emitted when the current editor has changed
155 @signal lastEditorClosed() emitted after the last editor window was closed
156 @signal editorOpened(str) emitted after an editor window was opened
157 @signal editorOpenedEd(Editor) emitted after an editor window was opened
158 @signal editorClosed(str) emitted just before an editor window gets closed
159 @signal editorClosedEd(Editor) emitted just before an editor window gets
160 closed
161 @signal editorRenamed(str) emitted after an editor was renamed
162 @signal editorRenamedEd(Editor) emitted after an editor was renamed
163 @signal editorSaved(str) emitted after an editor window was saved
164 @signal editorSavedEd(Editor) emitted after an editor window was saved
165 @signal checkActions(Editor) emitted when some actions should be checked
166 for their status
167 @signal cursorChanged(Editor) emitted after the cursor position of the
168 active window has changed
169 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled.
170 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled.
171 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled.
172 @signal previewStateChanged(bool) emitted to signal a change in the
173 preview state
174 @signal previewStateChanged(bool) emitted to signal a change in the
175 preview state
176 @signal astViewerStateChanged(bool) emitted to signal a change in the
177 AST viewer state
178 @signal editorLanguageChanged(Editor) emitted to signal a change of an
179 editors language
180 @signal editorTextChanged(Editor) emitted to signal a change of an
181 editor's text
182 @signal editorLineChanged(str,int) emitted to signal a change of an
183 editor's current line (line is given one based)
184 """
185 changeCaption = pyqtSignal(str)
186 editorChanged = pyqtSignal(str)
187 editorChangedEd = pyqtSignal(Editor)
188 lastEditorClosed = pyqtSignal()
189 editorOpened = pyqtSignal(str)
190 editorOpenedEd = pyqtSignal(Editor)
191 editorClosed = pyqtSignal(str)
192 editorClosedEd = pyqtSignal(Editor)
193 editorRenamed = pyqtSignal(str)
194 editorRenamedEd = pyqtSignal(Editor)
195 editorSaved = pyqtSignal(str)
196 editorSavedEd = pyqtSignal(Editor)
197 checkActions = pyqtSignal(Editor)
198 cursorChanged = pyqtSignal(Editor)
199 breakpointToggled = pyqtSignal(Editor)
200 bookmarkToggled = pyqtSignal(Editor)
201 syntaxerrorToggled = pyqtSignal(Editor)
202 previewStateChanged = pyqtSignal(bool)
203 astViewerStateChanged = pyqtSignal(bool)
204 editorLanguageChanged = pyqtSignal(Editor)
205 editorTextChanged = pyqtSignal(Editor)
206 editorLineChanged = pyqtSignal(str, int)
207
208 def __init__(self, parent):
209 """
210 Constructor
211
212 @param parent parent widget
213 @type QWidget
214 """
215 self.stacks = []
216
217 self.__splitter = QSplitter(parent)
218 ViewManager.__init__(self)
219 self.__splitter.setChildrenCollapsible(False)
220
221 self.viewlist = QListWidget(self)
222 policy = self.viewlist.sizePolicy()
223 policy.setHorizontalPolicy(QSizePolicy.Ignored)
224 self.viewlist.setSizePolicy(policy)
225 self.__splitter.addWidget(self.viewlist)
226 self.viewlist.setContextMenuPolicy(Qt.CustomContextMenu)
227 self.viewlist.currentRowChanged.connect(self.__showSelectedView)
228 self.viewlist.customContextMenuRequested.connect(self.__showMenu)
229
230 self.stackArea = QSplitter(self)
231 self.stackArea.setChildrenCollapsible(False)
232 self.__splitter.addWidget(self.stackArea)
233 self.stackArea.setOrientation(Qt.Vertical)
234 stack = StackedWidget(self.stackArea)
235 self.stackArea.addWidget(stack)
236 self.stacks.append(stack)
237 self.currentStack = stack
238 stack.currentChanged.connect(self.__currentChanged)
239 stack.installEventFilter(self)
240 self.__splitter.setSizes(
241 [int(self.width() * 0.2), int(self.width() * 0.8)])
242 # 20% for viewlist, 80% for the editors
243 self.__inRemoveView = False
244
245 self.__initMenu()
246 self.contextMenuEditor = None
247 self.contextMenuIndex = -1
248
249 def __initMenu(self):
250 """
251 Private method to initialize the viewlist context menu.
252 """
253 self.__menu = QMenu(self)
254 self.__menu.addAction(
255 UI.PixmapCache.getIcon("tabClose.png"),
256 self.tr('Close'), self.__contextMenuClose)
257 self.closeOthersMenuAct = self.__menu.addAction(
258 UI.PixmapCache.getIcon("tabCloseOther.png"),
259 self.tr("Close Others"),
260 self.__contextMenuCloseOthers)
261 self.__menu.addAction(
262 self.tr('Close All'), self.__contextMenuCloseAll)
263 self.__menu.addSeparator()
264 self.saveMenuAct = self.__menu.addAction(
265 UI.PixmapCache.getIcon("fileSave.png"),
266 self.tr('Save'), self.__contextMenuSave)
267 self.__menu.addAction(
268 UI.PixmapCache.getIcon("fileSaveAs.png"),
269 self.tr('Save As...'), self.__contextMenuSaveAs)
270 self.__menu.addAction(
271 UI.PixmapCache.getIcon("fileSaveAll.png"),
272 self.tr('Save All'), self.__contextMenuSaveAll)
273 self.__menu.addSeparator()
274 self.openRejectionsMenuAct = self.__menu.addAction(
275 self.tr("Open 'rejection' file"),
276 self.__contextMenuOpenRejections)
277 self.__menu.addSeparator()
278 self.__menu.addAction(
279 UI.PixmapCache.getIcon("print.png"),
280 self.tr('Print'), self.__contextMenuPrintFile)
281 self.__menu.addSeparator()
282 self.copyPathAct = self.__menu.addAction(
283 self.tr("Copy Path to Clipboard"),
284 self.__contextMenuCopyPathToClipboard)
285
286 def __showMenu(self, point):
287 """
288 Private slot to handle the customContextMenuRequested signal of
289 the viewlist.
290
291 @param point position to open the menu at
292 @type QPoint
293 """
294 if self.editors:
295 itm = self.viewlist.itemAt(point)
296 if itm is not None:
297 row = self.viewlist.row(itm)
298 self.contextMenuEditor = self.editors[row]
299 self.contextMenuIndex = row
300 if self.contextMenuEditor:
301 self.saveMenuAct.setEnabled(
302 self.contextMenuEditor.isModified())
303 fileName = self.contextMenuEditor.getFileName()
304 self.copyPathAct.setEnabled(bool(fileName))
305 if fileName:
306 rej = "{0}.rej".format(fileName)
307 self.openRejectionsMenuAct.setEnabled(
308 os.path.exists(rej))
309 else:
310 self.openRejectionsMenuAct.setEnabled(False)
311
312 self.closeOthersMenuAct.setEnabled(
313 self.viewlist.count() > 1)
314
315 self.__menu.popup(self.viewlist.mapToGlobal(point))
316
317 def mainWidget(self):
318 """
319 Public method to return a reference to the main Widget of a
320 specific view manager subclass.
321
322 @return reference to the main widget
323 @rtype QWidget
324 """
325 return self.__splitter
326
327 def canCascade(self):
328 """
329 Public method to signal if cascading of managed windows is available.
330
331 @return flag indicating cascading of windows is available
332 @rtype bool
333 """
334 return False
335
336 def canTile(self):
337 """
338 Public method to signal if tiling of managed windows is available.
339
340 @return flag indicating tiling of windows is available
341 @rtype bool
342 """
343 return False
344
345 def canSplit(self):
346 """
347 public method to signal if splitting of the view is available.
348
349 @return flag indicating splitting of the view is available
350 @rtype bool
351 """
352 return True
353
354 def tile(self):
355 """
356 Public method to tile the managed windows.
357 """
358 pass
359
360 def cascade(self):
361 """
362 Public method to cascade the managed windows.
363 """
364 pass
365
366 def _removeAllViews(self):
367 """
368 Protected method to remove all views (i.e. windows).
369 """
370 self.viewlist.clear()
371 for win in self.editors:
372 for stack in self.stacks:
373 if stack.hasEditor(win):
374 stack.removeWidget(win)
375 break
376 win.closeIt()
377
378 def _removeView(self, win):
379 """
380 Protected method to remove a view (i.e. window).
381
382 @param win editor window to be removed
383 @type Editor
384 """
385 self.__inRemoveView = True
386 ind = self.editors.index(win)
387 itm = self.viewlist.takeItem(ind)
388 if itm:
389 del itm
390 for stack in self.stacks:
391 if stack.hasEditor(win):
392 stack.removeWidget(win)
393 break
394 win.closeIt()
395 self.__inRemoveView = False
396 if ind > 0:
397 ind -= 1
398 else:
399 if len(self.editors) > 1:
400 ind = 1
401 else:
402 return
403 stack.setCurrentWidget(stack.firstEditor())
404 self._showView(self.editors[ind].parent())
405
406 aw = self.activeWindow()
407 fn = aw and aw.getFileName() or None
408 if fn:
409 self.changeCaption.emit(fn)
410 self.editorChanged.emit(fn)
411 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1)
412 else:
413 self.changeCaption.emit("")
414 self.editorChangedEd.emit(aw)
415
416 def _addView(self, win, fn=None, noName="", addNext=False, indexes=None):
417 """
418 Protected method to add a view (i.e. window).
419
420 @param win editor assembly to be added
421 @type EditorAssembly
422 @param fn filename of this editor
423 @type str
424 @param noName name to be used for an unnamed editor
425 @type str
426 @param addNext flag indicating to add the view next to the current
427 view
428 @type bool
429 @param indexes of the editor, first the split view index, second the
430 index within the view
431 @type tuple of two int
432 """
433 editor = win.getEditor()
434 if not fn:
435 if not noName:
436 self.untitledCount += 1
437 noName = self.tr("Untitled {0}").format(self.untitledCount)
438 self.viewlist.addItem(noName)
439 editor.setNoName(noName)
440 else:
441 txt = os.path.basename(fn)
442 if not QFileInfo(fn).isWritable():
443 txt = self.tr("{0} (ro)").format(txt)
444 itm = QListWidgetItem(txt)
445 itm.setToolTip(fn)
446 self.viewlist.addItem(itm)
447 if indexes:
448 if indexes[0] < len(self.stacks):
449 stack = self.stacks[indexes[0]]
450 else:
451 stack = self.stacks[-1]
452 stack.addWidget(win)
453 else:
454 self.currentStack.addWidget(win)
455 self.currentStack.setCurrentWidget(win)
456 editor.captionChanged.connect(self.__captionChange)
457 editor.cursorLineChanged.connect(
458 lambda lineno: self.__cursorLineChanged(lineno, editor))
459
460 index = self.editors.index(editor)
461 self.viewlist.setCurrentRow(index)
462 editor.setFocus()
463 if fn:
464 self.changeCaption.emit(fn)
465 self.editorChanged.emit(fn)
466 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1)
467 else:
468 self.changeCaption.emit("")
469 self.editorChangedEd.emit(editor)
470
471 def __captionChange(self, cap, editor):
472 """
473 Private method to handle caption change signals from the editor.
474
475 Updates the listwidget text to reflect the new caption information.
476
477 @param cap Caption for the editor
478 @type str
479 @param editor Editor to update the caption for
480 @type Editor
481 """
482 fn = editor.getFileName()
483 if fn:
484 self.setEditorName(editor, fn)
485
486 def __cursorLineChanged(self, lineno, editor):
487 """
488 Private slot to handle a change of the current editor's cursor line.
489
490 @param lineno line number of the editor's cursor (zero based)
491 @type int
492 @param editor reference to the editor
493 @type Editor
494 """
495 if editor:
496 fn = editor.getFileName()
497 if fn:
498 self.editorLineChanged.emit(fn, lineno + 1)
499
500 def _showView(self, win, fn=None):
501 """
502 Protected method to show a view (i.e. window).
503
504 @param win editor assembly to be shown
505 @type EditorAssembly
506 @param fn filename of this editor
507 @type string
508 """
509 editor = win.getEditor()
510 for stack in self.stacks:
511 if stack.hasEditor(editor):
512 stack.setCurrentWidget(win)
513 self.currentStack = stack
514 break
515 index = self.editors.index(editor)
516 self.viewlist.setCurrentRow(index)
517 editor.setFocus()
518 fn = editor.getFileName()
519 if fn:
520 self.changeCaption.emit(fn)
521 self.editorChanged.emit(fn)
522 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1)
523 else:
524 self.changeCaption.emit("")
525 self.editorChangedEd.emit(editor)
526
527 def __showSelectedView(self, row):
528 """
529 Private slot called to show a view selected in the list.
530
531 @param row row number of the item clicked on
532 @type int
533 """
534 if row != -1:
535 self._showView(self.editors[row].parent())
536 self._checkActions(self.editors[row])
537
538 def activeWindow(self):
539 """
540 Public method to return the active (i.e. current) window.
541
542 @return reference to the active editor
543 @rtype EditorAssembly
544 """
545 return self.currentStack.currentWidget()
546
547 def showWindowMenu(self, windowMenu):
548 """
549 Public method to set up the viewmanager part of the Window menu.
550
551 @param windowMenu reference to the window menu
552 @type QMenu
553 """
554 pass
555
556 def _initWindowActions(self):
557 """
558 Protected method to define the user interface actions for window
559 handling.
560 """
561 pass
562
563 def setEditorName(self, editor, newName):
564 """
565 Public method to change the displayed name of the editor.
566
567 @param editor editor window to be changed
568 @type Editor
569 @param newName new name to be shown
570 @type str
571 """
572 if newName:
573 currentRow = self.viewlist.currentRow()
574 index = self.editors.index(editor)
575 txt = os.path.basename(newName)
576 if not QFileInfo(newName).isWritable():
577 txt = self.tr("{0} (ro)").format(txt)
578 itm = self.viewlist.item(index)
579 if itm:
580 itm.setText(txt)
581 itm.setToolTip(newName)
582 self.viewlist.setCurrentRow(currentRow)
583 self.changeCaption.emit(newName)
584
585 def _modificationStatusChanged(self, m, editor):
586 """
587 Protected slot to handle the modificationStatusChanged signal.
588
589 @param m flag indicating the modification status
590 @type bool
591 @param editor editor window changed
592 @type Editor
593 """
594 currentRow = self.viewlist.currentRow()
595 index = self.editors.index(editor)
596 keys = []
597 if m:
598 keys.append("fileModified.png")
599 if editor.hasSyntaxErrors():
600 keys.append("syntaxError22.png")
601 elif editor.hasWarnings():
602 keys.append("warning22.png")
603 if not keys:
604 keys.append("empty.png")
605 item = self.viewlist.item(index)
606 if item:
607 item.setIcon(UI.PixmapCache.getCombinedIcon(keys))
608 self.viewlist.setCurrentRow(currentRow)
609 self._checkActions(editor)
610
611 def _syntaxErrorToggled(self, editor):
612 """
613 Protected slot to handle the syntaxerrorToggled signal.
614
615 @param editor editor that sent the signal
616 @type Editor
617 """
618 currentRow = self.viewlist.currentRow()
619 index = self.editors.index(editor)
620 keys = []
621 if editor.isModified():
622 keys.append("fileModified.png")
623 if editor.hasSyntaxErrors():
624 keys.append("syntaxError22.png")
625 elif editor.hasWarnings():
626 keys.append("warning22.png")
627 if not keys:
628 keys.append("empty.png")
629 item = self.viewlist.item(index)
630 if item:
631 item.setIcon(UI.PixmapCache.getCombinedIcon(keys))
632 self.viewlist.setCurrentRow(currentRow)
633
634 ViewManager._syntaxErrorToggled(self, editor)
635
636 def addSplit(self):
637 """
638 Public method used to split the current view.
639 """
640 stack = StackedWidget(self.stackArea)
641 stack.show()
642 self.stackArea.addWidget(stack)
643 self.stacks.append(stack)
644 self.currentStack = stack
645 stack.currentChanged.connect(self.__currentChanged)
646 stack.installEventFilter(self)
647 if self.stackArea.orientation() == Qt.Horizontal:
648 size = self.stackArea.width()
649 else:
650 size = self.stackArea.height()
651 self.stackArea.setSizes(
652 [int(size / len(self.stacks))] * len(self.stacks))
653 self.splitRemoveAct.setEnabled(True)
654 self.nextSplitAct.setEnabled(True)
655 self.prevSplitAct.setEnabled(True)
656
657 @pyqtSlot()
658 def removeSplit(self, index=-1):
659 """
660 Public method used to remove the current split view or a split view
661 by index.
662
663 @param index index of the split to be removed (-1 means to
664 delete the current split)
665 @type int
666 @return flag indicating successful deletion
667 @rtype bool
668 """
669 if len(self.stacks) > 1:
670 if index == -1:
671 stack = self.currentStack
672 else:
673 if index < len(self.stacks):
674 stack = self.stacks[index]
675 else:
676 stack = self.stacks[-1]
677 res = True
678 savedEditors = stack.editors[:]
679 for editor in savedEditors:
680 res &= self.closeEditor(editor)
681 if res:
682 try:
683 i = self.stacks.index(stack)
684 except ValueError:
685 return True
686 if i == len(self.stacks) - 1:
687 i -= 1
688 self.stacks.remove(stack)
689 stack.close()
690 self.currentStack = self.stacks[i]
691 if len(self.stacks) == 1:
692 self.splitRemoveAct.setEnabled(False)
693 self.nextSplitAct.setEnabled(False)
694 self.prevSplitAct.setEnabled(False)
695 return True
696
697 return False
698
699 def splitCount(self):
700 """
701 Public method to get the number of splitted views.
702
703 @return number of splitted views
704 @rtype int
705 """
706 return len(self.stacks)
707
708 def setSplitCount(self, count):
709 """
710 Public method to set the number of split views.
711
712 @param count number of split views
713 @type int
714 """
715 if count > self.splitCount():
716 while self.splitCount() < count:
717 self.addSplit()
718 elif count < self.splitCount():
719 while self.splitCount() > count:
720 # use an arbitrarily large index to remove the last one
721 self.removeSplit(index=100)
722
723 def getSplitOrientation(self):
724 """
725 Public method to get the orientation of the split view.
726
727 @return orientation of the split
728 @rtype Qt.Horizontal or Qt.Vertical
729 """
730 return self.stackArea.orientation()
731
732 def setSplitOrientation(self, orientation):
733 """
734 Public method used to set the orientation of the split view.
735
736 @param orientation orientation of the split
737 @type Qt.Horizontal or Qt.Vertical
738 """
739 self.stackArea.setOrientation(orientation)
740
741 def nextSplit(self):
742 """
743 Public slot used to move to the next split.
744 """
745 aw = self.activeWindow()
746 _hasFocus = aw and aw.hasFocus()
747 ind = self.stacks.index(self.currentStack) + 1
748 if ind == len(self.stacks):
749 ind = 0
750
751 self.currentStack = self.stacks[ind]
752 if _hasFocus:
753 aw = self.activeWindow()
754 if aw:
755 aw.setFocus()
756
757 cw = self.currentStack.currentWidget()
758 if cw:
759 index = self.editors.index(cw)
760 self.viewlist.setCurrentRow(index)
761
762 def prevSplit(self):
763 """
764 Public slot used to move to the previous split.
765 """
766 aw = self.activeWindow()
767 _hasFocus = aw and aw.hasFocus()
768 ind = self.stacks.index(self.currentStack) - 1
769 if ind == -1:
770 ind = len(self.stacks) - 1
771
772 self.currentStack = self.stacks[ind]
773 if _hasFocus:
774 aw = self.activeWindow()
775 if aw:
776 aw.setFocus()
777
778 cw = self.currentStack.currentWidget()
779 if cw:
780 index = self.editors.index(cw)
781 self.viewlist.setCurrentRow(index)
782
783 def __contextMenuClose(self):
784 """
785 Private method to close the selected editor.
786 """
787 if self.contextMenuEditor:
788 self.closeEditorWindow(self.contextMenuEditor)
789
790 def __contextMenuCloseOthers(self):
791 """
792 Private method to close the other editors.
793 """
794 index = self.contextMenuIndex
795 for i in list(range(self.viewlist.count() - 1, index, -1)) + \
796 list(range(index - 1, -1, -1)):
797 editor = self.editors[i]
798 self.closeEditorWindow(editor)
799
800 def __contextMenuCloseAll(self):
801 """
802 Private method to close all editors.
803 """
804 savedEditors = self.editors[:]
805 for editor in savedEditors:
806 self.closeEditorWindow(editor)
807
808 def __contextMenuSave(self):
809 """
810 Private method to save the selected editor.
811 """
812 if self.contextMenuEditor:
813 self.saveEditorEd(self.contextMenuEditor)
814
815 def __contextMenuSaveAs(self):
816 """
817 Private method to save the selected editor to a new file.
818 """
819 if self.contextMenuEditor:
820 self.saveAsEditorEd(self.contextMenuEditor)
821
822 def __contextMenuSaveAll(self):
823 """
824 Private method to save all editors.
825 """
826 self.saveEditorsList(self.editors)
827
828 def __contextMenuOpenRejections(self):
829 """
830 Private slot to open a rejections file associated with the selected
831 editor.
832 """
833 if self.contextMenuEditor:
834 fileName = self.contextMenuEditor.getFileName()
835 if fileName:
836 rej = "{0}.rej".format(fileName)
837 if os.path.exists(rej):
838 self.openSourceFile(rej)
839
840 def __contextMenuPrintFile(self):
841 """
842 Private method to print the selected editor.
843 """
844 if self.contextMenuEditor:
845 self.printEditor(self.contextMenuEditor)
846
847 def __contextMenuCopyPathToClipboard(self):
848 """
849 Private method to copy the file name of the selected editor to the
850 clipboard.
851 """
852 if self.contextMenuEditor:
853 fn = self.contextMenuEditor.getFileName()
854 if fn:
855 cb = QApplication.clipboard()
856 cb.setText(fn)
857
858 def __currentChanged(self, index):
859 """
860 Private slot to handle the currentChanged signal.
861
862 @param index index of the current editor
863 @type int
864 """
865 if index == -1 or not self.editors:
866 return
867
868 editor = self.activeWindow()
869 if editor is None:
870 return
871
872 self._checkActions(editor)
873 editor.setFocus()
874 fn = editor.getFileName()
875 if fn:
876 self.changeCaption.emit(fn)
877 if not self.__inRemoveView:
878 self.editorChanged.emit(fn)
879 self.editorLineChanged.emit(
880 fn, editor.getCursorPosition()[0] + 1)
881 else:
882 self.changeCaption.emit("")
883 self.editorChangedEd.emit(editor)
884
885 cindex = self.editors.index(editor)
886 self.viewlist.setCurrentRow(cindex)
887
888 def eventFilter(self, watched, event):
889 """
890 Public method called to filter the event queue.
891
892 @param watched the QObject being watched
893 @type QObject
894 @param event the event that occurred
895 @type QEvent
896 @return flag indicating, if we handled the event
897 @rtype bool
898 """
899 if event.type() == QEvent.MouseButtonPress and \
900 not event.button() == Qt.RightButton:
901 switched = True
902 if isinstance(watched, QStackedWidget):
903 switched = watched is not self.currentStack
904 self.currentStack = watched
905 elif isinstance(watched, QScintilla.Editor.Editor):
906 for stack in self.stacks:
907 if stack.hasEditor(watched):
908 switched = stack is not self.currentStack
909 self.currentStack = stack
910 break
911 currentWidget = self.currentStack.currentWidget()
912 if currentWidget:
913 index = self.editors.index(currentWidget)
914 self.viewlist.setCurrentRow(index)
915
916 aw = self.activeWindow()
917 if aw is not None:
918 self._checkActions(aw)
919 aw.setFocus()
920 fn = aw.getFileName()
921 if fn:
922 self.changeCaption.emit(fn)
923 if switched:
924 self.editorChanged.emit(fn)
925 self.editorLineChanged.emit(
926 fn, aw.getCursorPosition()[0] + 1)
927 else:
928 self.changeCaption.emit("")
929 self.editorChangedEd.emit(aw)
930
931 return False
932
933 def getOpenEditorsForSession(self):
934 """
935 Public method to get a lists of all open editors.
936
937 The returned list contains one list per split view. If the view manager
938 cannot split the view, only one list of editors is returned.
939
940 @return list of list of editor references
941 @rtype list of list of Editor
942 """
943 editorLists = []
944 for stack in self.stacks:
945 editors = []
946 for index in range(stack.count()):
947 widget = stack.widget(index)
948 if isinstance(widget, EditorAssembly):
949 editor = widget.getEditor()
950 editors.append(editor)
951 editorLists.append(editors)
952 return editorLists

eric ide

mercurial