--- a/Plugins/ViewManagerPlugins/Listspace/Listspace.py Sun Dec 31 18:54:06 2017 +0100 +++ b/Plugins/ViewManagerPlugins/Listspace/Listspace.py Mon Jan 01 19:06:33 2018 +0100 @@ -19,6 +19,7 @@ import QScintilla.Editor from QScintilla.Editor import Editor +from QScintilla.EditorAssembly import EditorAssembly import UI.PixmapCache @@ -31,7 +32,8 @@ """ Constructor - @param parent parent widget (QWidget) + @param parent parent widget + @type QWidget """ super(StackedWidget, self).__init__(parent) @@ -42,7 +44,7 @@ Public method to add a new widget. @param assembly editor assembly object to be added - (QScintilla.EditorAssembly.EditorAssembly) + @type QScintilla.EditorAssembly.EditorAssembly """ editor = assembly.getEditor() super(StackedWidget, self).addWidget(assembly) @@ -53,7 +55,8 @@ """ Public method to remove a widget. - @param widget widget to be removed (QWidget) + @param widget widget to be removed + @type QWidget """ if isinstance(widget, QScintilla.Editor.Editor): self.editors.remove(widget) @@ -64,7 +67,8 @@ """ Public method to get a reference to the current editor. - @return reference to the current editor (Editor) + @return reference to the current editor + @rtype Editor """ widget = super(StackedWidget, self).currentWidget() if widget is not None: @@ -75,7 +79,8 @@ """ Public method to set the current widget. - @param widget widget to be made current (QWidget) + @param widget widget to be made current + @type QWidget """ if widget is not None: if isinstance(widget, QScintilla.Editor.Editor): @@ -88,7 +93,8 @@ """ Public method to set the current widget by its index. - @param index index of widget to be made current (integer) + @param index index of widget to be made current + @type int """ widget = self.widget(index) if widget is not None: @@ -121,8 +127,10 @@ Public method to check for an editor. @param editor editor object to check for + @type Editor @return flag indicating, whether the editor to be checked belongs to the list of editors managed by this stacked widget. + @rtype bool """ return editor in self.editors @@ -131,7 +139,8 @@ Public method to retrieve the first editor in the list of managed editors. - @return first editor in list (QScintilla.Editor.Editor) + @return first editor in list + @rtype QScintilla.Editor.Editor """ return len(self.editors) and self.editors[0] or None @@ -195,7 +204,8 @@ """ Constructor - @param parent parent widget (QWidget) + @param parent parent widget + @type QWidget """ self.stacks = [] @@ -273,7 +283,8 @@ Private slot to handle the customContextMenuRequested signal of the viewlist. - @param point position to open the menu at (QPoint) + @param point position to open the menu at + @type QPoint """ if self.editors: itm = self.viewlist.itemAt(point) @@ -313,6 +324,7 @@ Public method to signal if cascading of managed windows is available. @return flag indicating cascading of windows is available + @rtype bool """ return False @@ -321,6 +333,7 @@ Public method to signal if tiling of managed windows is available. @return flag indicating tiling of windows is available + @rtype bool """ return False @@ -328,7 +341,8 @@ """ public method to signal if splitting of the view is available. - @return flag indicating splitting of the view is available. + @return flag indicating splitting of the view is available + @rtype bool """ return True @@ -361,6 +375,7 @@ Protected method to remove a view (i.e. window). @param win editor window to be removed + @type Editor """ self.__inRemoveView = True ind = self.editors.index(win) @@ -393,15 +408,22 @@ self.changeCaption.emit("") self.editorChangedEd.emit(aw) - def _addView(self, win, fn=None, noName="", addNext=False): + def _addView(self, win, fn=None, noName="", addNext=False, indexes=None): """ Protected method to add a view (i.e. window). @param win editor assembly to be added - @param fn filename of this editor (string) - @param noName name to be used for an unnamed editor (string) + @type EditorAssembly + @param fn filename of this editor + @type str + @param noName name to be used for an unnamed editor + @type str @param addNext flag indicating to add the view next to the current - view (bool) + view + @type bool + @param indexes of the editor, first the split view index, second the + index within the view + @type tuple of two int """ editor = win.getEditor() if fn is None: @@ -417,8 +439,15 @@ itm = QListWidgetItem(txt) itm.setToolTip(fn) self.viewlist.addItem(itm) - self.currentStack.addWidget(win) - self.currentStack.setCurrentWidget(win) + if indexes: + if indexes[0] < len(self.stacks): + stack = self.stacks[indexes[0]] + else: + stack = self.stacks[-1] + stack.addWidget(win) + else: + self.currentStack.addWidget(win) + self.currentStack.setCurrentWidget(win) editor.captionChanged.connect(self.__captionChange) editor.cursorLineChanged.connect(self.__cursorLineChanged) @@ -439,8 +468,10 @@ Updates the listwidget text to reflect the new caption information. - @param cap Caption for the editor (string) + @param cap Caption for the editor + @type str @param editor Editor to update the caption for + @type Editor """ fn = editor.getFileName() if fn: @@ -451,6 +482,7 @@ Private slot to handle a change of the current editor's cursor line. @param lineno line number of the current editor's cursor (zero based) + @type int """ editor = self.sender() if editor: @@ -463,7 +495,9 @@ Protected method to show a view (i.e. window). @param win editor assembly to be shown - @param fn filename of this editor (string) + @type EditorAssembly + @param fn filename of this editor + @type string """ editor = win.getEditor() for stack in self.stacks: @@ -487,7 +521,8 @@ """ Private slot called to show a view selected in the list. - @param row row number of the item clicked on (integer) + @param row row number of the item clicked on + @type int """ if row != -1: self._showView(self.editors[row].parent()) @@ -498,6 +533,7 @@ Public method to return the active (i.e. current) window. @return reference to the active editor + @rtype EditorAssembly """ return self.currentStack.currentWidget() @@ -506,6 +542,7 @@ Public method to set up the viewmanager part of the Window menu. @param windowMenu reference to the window menu + @type QMenu """ pass @@ -521,7 +558,9 @@ Public method to change the displayed name of the editor. @param editor editor window to be changed - @param newName new name to be shown (string) + @type Editor + @param newName new name to be shown + @type str """ if newName: currentRow = self.viewlist.currentRow() @@ -540,8 +579,10 @@ """ Protected slot to handle the modificationStatusChanged signal. - @param m flag indicating the modification status (boolean) + @param m flag indicating the modification status + @type bool @param editor editor window changed + @type Editor """ currentRow = self.viewlist.currentRow() index = self.editors.index(editor) @@ -565,6 +606,7 @@ Protected slot to handle the syntaxerrorToggled signal. @param editor editor that sent the signal + @type Editor """ currentRow = self.viewlist.currentRow() index = self.editors.index(editor) @@ -605,14 +647,25 @@ self.nextSplitAct.setEnabled(True) self.prevSplitAct.setEnabled(True) - def removeSplit(self): + def removeSplit(self, index=-1): """ - Public method used to remove the current split view. + Public method used to remove the current split view or a split view + by index. - @return flag indicating successfull removal + @param index index of the split to be removed (-1 means to + delete the current split) + @type int + @return flag indicating successful deletion + @rtype bool """ if len(self.stacks) > 1: - stack = self.currentStack + if index == -1: + stack = self.currentStack + else: + if index < len(self.stacks): + stack = self.stacks[index] + else: + stack = self.stacks[-1] res = True savedEditors = stack.editors[:] for editor in savedEditors: @@ -635,11 +688,36 @@ return False + def splitCount(self): + """ + Public method to get the number of splitted views. + + @return number of splitted views + @rtype int + """ + return len(self.stacks) + + def setSplitCount(self, count): + """ + Public method to set the number of split views. + + @param count number of split views + @type int + """ + if count > self.splitCount(): + while self.splitCount() < count: + self.addSplit() + elif count < self.splitCount(): + while self.splitCount() > count: + # use an arbitrarily large index to remove the last one + self.removeSplit(index=100) + def getSplitOrientation(self): """ Public method to get the orientation of the split view. - @return orientation of the split (Qt.Horizontal or Qt.Vertical) + @return orientation of the split + @rtype Qt.Horizontal or Qt.Vertical """ return self.stackArea.orientation() @@ -648,7 +726,7 @@ Public method used to set the orientation of the split view. @param orientation orientation of the split - (Qt.Horizontal or Qt.Vertical) + @type Qt.Horizontal or Qt.Vertical """ self.stackArea.setOrientation(orientation) @@ -774,6 +852,7 @@ Private slot to handle the currentChanged signal. @param index index of the current editor + @type int """ if index == -1 or not self.editors: return @@ -803,8 +882,11 @@ Public method called to filter the event queue. @param watched the QObject being watched + @type QObject @param event the event that occurred + @type QEvent @return flag indicating, if we handled the event + @rtype bool """ if event.type() == QEvent.MouseButtonPress and \ not event.button() == Qt.RightButton: @@ -839,3 +921,24 @@ self.editorChangedEd.emit(aw) return False + + def getOpenEditorsForSession(self): + """ + Public method to get a lists of all open editors. + + The returned list contains one list per split view. If the view manager + cannot split the view, only one list of editors is returned. + + @return list of list of editor references + @rtype list of list of Editor + """ + editorLists = [] + for stack in self.stacks: + editors = [] + for index in range(stack.count()): + widget = stack.widget(index) + if isinstance(widget, EditorAssembly): + editor = widget.getEditor() + editors.append(editor) + editorLists.append(editors) + return editorLists