eric6/QScintilla/EditorOutline.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7750
b16930e5baa9
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7750
diff changeset
3 # Copyright (c) 2020 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing an outline widget for source code navigation of the editor.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
10 from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication, QModelIndex, QPoint
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
11 from PyQt5.QtWidgets import QTreeView, QAbstractItemView, QMenu, QApplication
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from UI.BrowserSortFilterProxyModel import BrowserSortFilterProxyModel
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
14 from UI.BrowserModel import (
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
15 BrowserImportsItem, BrowserGlobalsItem, BrowserClassAttributeItem,
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
16 BrowserImportItem
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
17 )
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from .EditorOutlineModel import EditorOutlineModel
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
21 import Preferences
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
23
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 class EditorOutlineView(QTreeView):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Class implementing an outline widget for source code navigation of the
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 editor.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
29 def __init__(self, editor, populate=True, parent=None):
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Constructor
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param editor reference to the editor widget
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @type Editor
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
35 @param populate flag indicating to populate the outline
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
36 @type bool
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @param parent reference to the parent widget
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @type QWidget
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 super(EditorOutlineView, self).__init__(parent)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
42 self.__model = EditorOutlineModel(editor, populate=populate)
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.__sortModel = BrowserSortFilterProxyModel()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.__sortModel.setSourceModel(self.__model)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.setModel(self.__sortModel)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.setRootIsDecorated(True)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.setAlternatingRowColors(True)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 header = self.header()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 header.setSortIndicator(0, Qt.AscendingOrder)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 header.setSortIndicatorShown(True)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 header.setSectionsClickable(True)
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
54 self.setHeaderHidden(True)
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.setSortingEnabled(True)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.setSelectionMode(QAbstractItemView.SingleSelection)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.setSelectionBehavior(QAbstractItemView.SelectRows)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
61 self.setContextMenuPolicy(Qt.CustomContextMenu)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
62 self.customContextMenuRequested.connect(self.__contextMenuRequested)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
63 self.__createPopupMenus()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
64
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.activated.connect(self.__gotoItem)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.expanded.connect(self.__resizeColumns)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.collapsed.connect(self.__resizeColumns)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.__resizeColumns()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__expandedNames = []
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__currentItemName = ""
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
73 self.__signalsConnected = False
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
74
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
75 def setActive(self, active):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
76 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
77 Public method to activate or deactivate the outline view.
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
78
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
79 @param active flag indicating the requested action
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
80 @type bool
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
81 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
82 if active and not self.__signalsConnected:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
83 editor = self.__model.editor()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
84 editor.refreshed.connect(self.repopulate)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
85 editor.languageChanged.connect(self.__editorLanguageChanged)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
86 editor.editorRenamed.connect(self.__editorRenamed)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
87 editor.cursorLineChanged.connect(self.__editorCursorLineChanged)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
88
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
89 self.__model.repopulate()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
90 self.__resizeColumns()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
91
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
92 line, _ = editor.getCursorPosition()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
93 self.__editorCursorLineChanged(line)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
94
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
95 elif not active and self.__signalsConnected:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
96 editor = self.__model.editor()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
97 editor.refreshed.disconnect(self.repopulate)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
98 editor.languageChanged.disconnect(self.__editorLanguageChanged)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
99 editor.editorRenamed.disconnect(self.__editorRenamed)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
100 editor.cursorLineChanged.disconnect(self.__editorCursorLineChanged)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
101
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
102 self.__model.clear()
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
104 @pyqtSlot()
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 def __resizeColumns(self):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 Private slot to resize the view when items get expanded or collapsed.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 self.resizeColumnToContents(0)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 def isPopulated(self):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 Public method to check, if the model is populated.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @return flag indicating a populated model
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @rtype bool
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 return self.__model.isPopulated()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
120 @pyqtSlot()
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 def repopulate(self):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 Public slot to repopulate the model.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 if self.isPopulated():
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.__prepareRepopulate()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 self.__model.repopulate()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 self.__completeRepopulate()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
130 @pyqtSlot()
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 def __prepareRepopulate(self):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 Private slot to prepare to repopulate the outline view.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 itm = self.__currentItem()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 if itm is not None:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 self.__currentItemName = itm.data(0)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 self.__expandedNames = []
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 childIndex = self.model().index(0, 0)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 while childIndex.isValid():
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 if self.isExpanded(childIndex):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 self.__expandedNames.append(
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 self.model().item(childIndex).data(0))
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 childIndex = self.indexBelow(childIndex)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
148 @pyqtSlot()
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 def __completeRepopulate(self):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 Private slot to complete the repopulate of the outline view.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 childIndex = self.model().index(0, 0)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 while childIndex.isValid():
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 name = self.model().item(childIndex).data(0)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 if (self.__currentItemName and self.__currentItemName == name):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 self.setCurrentIndex(childIndex)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 if name in self.__expandedNames:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 self.setExpanded(childIndex, True)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 childIndex = self.indexBelow(childIndex)
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
161 self.__resizeColumns()
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 self.__expandedNames = []
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 self.__currentItemName = ""
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 def isSupportedLanguage(self, language):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 Public method to check, if outlining a given language is supported.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 @param language source language to be checked
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 @type str
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 @return flag indicating support
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 @rtype bool
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 return language in EditorOutlineModel.SupportedLanguages
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
177 @pyqtSlot(QModelIndex)
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 def __gotoItem(self, index):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 Private slot to set the editor cursor.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 @param index index of the item to set the cursor for
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 @type QModelIndex
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 if index.isValid():
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 itm = self.model().item(index)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 if itm:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 try:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 lineno = itm.lineno()
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
190 self.__model.editor().gotoLine(lineno)
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 except AttributeError:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 # don't care
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 pass
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 def mouseDoubleClickEvent(self, mouseEvent):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 Protected method of QAbstractItemView.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 Reimplemented to disable expanding/collapsing of items when
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 double-clicking. Instead the double-clicked entry is opened.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 @param mouseEvent the mouse event (QMouseEvent)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 index = self.indexAt(mouseEvent.pos())
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 if index.isValid():
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 itm = self.model().item(index)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 if isinstance(itm, (BrowserImportsItem, BrowserGlobalsItem)):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 self.setExpanded(index, not self.isExpanded(index))
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 else:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 self.__gotoItem(index)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 def __currentItem(self):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 Private method to get a reference to the current item.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 @return reference to the current item
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 @rtype BrowserItem
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 itm = self.model().item(self.currentIndex())
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 return itm
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
221
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
222 #######################################################################
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
223 ## Context menu methods below
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
224 #######################################################################
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
225
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
226 def __createPopupMenus(self):
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
227 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
228 Private method to generate the various popup menus.
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
229 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
230 # create the popup menu for general use
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
231 self.__menu = QMenu(self)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
232 self.__menu.addAction(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
233 QCoreApplication.translate('EditorOutlineView', 'Goto'),
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
234 self.__goto)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
235 self.__menu.addSeparator()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
236 self.__menu.addAction(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
237 QCoreApplication.translate('EditorOutlineView', 'Refresh'),
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
238 self.repopulate)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
239 self.__menu.addSeparator()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
240 self.__menu.addAction(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
241 QCoreApplication.translate(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
242 'EditorOutlineView', 'Copy Path to Clipboard'),
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
243 self.__copyToClipboard)
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
244 self.__menu.addSeparator()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
245 self.__menu.addAction(
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
246 QCoreApplication.translate(
7692
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
247 'EditorOutlineView', 'Expand All'),
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
248 lambda: self.expandToDepth(-1))
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
249 self.__menu.addAction(
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
250 QCoreApplication.translate(
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
251 'EditorOutlineView', 'Collapse All'),
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
252 self.collapseAll)
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
253 self.__menu.addSeparator()
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
254 self.__menu.addAction(
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
255 QCoreApplication.translate(
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
256 'EditorOutlineView', 'Increment Width'),
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
257 self.__incWidth)
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
258 self.__decWidthAct = self.__menu.addAction(
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
259 QCoreApplication.translate(
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
260 'EditorOutlineView', 'Decrement Width'),
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
261 self.__decWidth)
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
262 self.__menu.addAction(
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
263 QCoreApplication.translate(
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
264 'EditorOutlineView', 'Set Default Width'),
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
265 self.__defaultWidth)
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
266
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
267 # create the attribute/import menu
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
268 self.__gotoMenu = QMenu(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
269 QCoreApplication.translate('EditorOutlineView', "Goto"),
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
270 self)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
271 self.__gotoMenu.aboutToShow.connect(self.__showGotoMenu)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
272 self.__gotoMenu.triggered.connect(self.__gotoAttribute)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
273
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
274 self.__attributeMenu = QMenu(self)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
275 self.__attributeMenu.addMenu(self.__gotoMenu)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
276 self.__attributeMenu.addSeparator()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
277 self.__attributeMenu.addAction(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
278 QCoreApplication.translate('EditorOutlineView', 'Refresh'),
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
279 self.repopulate)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
280 self.__attributeMenu.addSeparator()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
281 self.__attributeMenu.addAction(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
282 QCoreApplication.translate(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
283 'EditorOutlineView', 'Copy Path to Clipboard'),
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
284 self.__copyToClipboard)
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
285 self.__attributeMenu.addSeparator()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
286 self.__attributeMenu.addAction(
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
287 QCoreApplication.translate(
7692
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
288 'EditorOutlineView', 'Expand All'),
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
289 lambda: self.expandToDepth(-1))
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
290 self.__attributeMenu.addAction(
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
291 QCoreApplication.translate(
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
292 'EditorOutlineView', 'Collapse All'),
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
293 self.collapseAll)
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
294 self.__attributeMenu.addSeparator()
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
295 self.__attributeMenu.addAction(
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
296 QCoreApplication.translate(
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
297 'EditorOutlineView', 'Increment Width'),
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
298 self.__incWidth)
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
299 self.__attributeDecWidthAct = self.__attributeMenu.addAction(
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
300 QCoreApplication.translate(
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
301 'EditorOutlineView', 'Decrement Width'),
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
302 self.__decWidth)
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
303 self.__attributeMenu.addAction(
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
304 QCoreApplication.translate(
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
305 'EditorOutlineView', 'Set Default Width'),
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
306 self.__defaultWidth)
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
307
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
308 # create the background menu
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
309 self.__backMenu = QMenu(self)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
310 self.__backMenu.addAction(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
311 QCoreApplication.translate('EditorOutlineView', 'Refresh'),
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
312 self.repopulate)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
313 self.__backMenu.addSeparator()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
314 self.__backMenu.addAction(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
315 QCoreApplication.translate(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
316 'EditorOutlineView', 'Copy Path to Clipboard'),
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
317 self.__copyToClipboard)
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
318 self.__backMenu.addSeparator()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
319 self.__backMenu.addAction(
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
320 QCoreApplication.translate(
7692
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
321 'EditorOutlineView', 'Expand All'),
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
322 lambda: self.expandToDepth(-1))
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
323 self.__backMenu.addAction(
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
324 QCoreApplication.translate(
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
325 'EditorOutlineView', 'Collapse All'),
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
326 self.collapseAll)
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
327 self.__backMenu.addSeparator()
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
328 self.__backMenu.addAction(
94f0017f9372 EditorOutline: added actions to collapse/expand all entries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
329 QCoreApplication.translate(
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
330 'EditorOutlineView', 'Increment Width'),
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
331 self.__incWidth)
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
332 self.__backDecWidthAct = self.__backMenu.addAction(
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
333 QCoreApplication.translate(
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
334 'EditorOutlineView', 'Decrement Width'),
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
335 self.__decWidth)
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
336 self.__backMenu.addAction(
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
337 QCoreApplication.translate(
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
338 'EditorOutlineView', 'Set Default Width'),
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
339 self.__defaultWidth)
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
340
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
341 @pyqtSlot(QPoint)
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
342 def __contextMenuRequested(self, coord):
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
343 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
344 Private slot to show the context menu.
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
345
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
346 @param coord position of the mouse pointer
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
347 @type QPoint
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
348 """
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
349 index = self.indexAt(coord)
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
350 coord = self.mapToGlobal(coord)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
351
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
352 decWidthEnable = (
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
353 self.maximumWidth() !=
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
354 2 * Preferences.getEditor("SourceOutlineStepSize")
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
355 )
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
356
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
357 if index.isValid():
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
358 self.setCurrentIndex(index)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
359
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
360 itm = self.model().item(index)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
361 if isinstance(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
362 itm, (BrowserClassAttributeItem, BrowserImportItem)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
363 ):
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
364 self.__attributeDecWidthAct.setEnabled(decWidthEnable)
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
365 self.__attributeMenu.popup(coord)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
366 else:
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
367 self.__decWidthAct.setEnabled(decWidthEnable)
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
368 self.__menu.popup(coord)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
369 else:
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
370 self.__backDecWidthAct.setEnabled(decWidthEnable)
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
371 self.__backMenu.popup(coord)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
372
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
373 @pyqtSlot()
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
374 def __showGotoMenu(self):
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
375 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
376 Private slot to prepare the goto submenu of the attribute menu.
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
377 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
378 self.__gotoMenu.clear()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
379
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
380 itm = self.model().item(self.currentIndex())
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
381 try:
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
382 linenos = itm.linenos()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
383 except AttributeError:
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
384 try:
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
385 linenos = [itm.lineno()]
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
386 except AttributeError:
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
387 return
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
388
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
389 for lineno in sorted(linenos):
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
390 act = self.__gotoMenu.addAction(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
391 QCoreApplication.translate(
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
392 'EditorOutlineView', "Line {0}").format(lineno))
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
393 act.setData(lineno)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
394
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
395 #######################################################################
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
396 ## Context menu handlers below
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
397 #######################################################################
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
398
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
399 @pyqtSlot()
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
400 def __gotoAttribute(self, act):
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
401 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
402 Private slot to handle the selection of the goto menu.
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
403
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
404 @param act reference to the action (E5Action)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
405 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
406 lineno = act.data()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
407 self.__model.editor().gotoLine(lineno)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
408
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
409 @pyqtSlot()
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
410 def __goto(self):
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
411 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
412 Private slot to move the editor cursor to the line of the context item.
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
413 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
414 self.__gotoItem(self.currentIndex())
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
415
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
416 @pyqtSlot()
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
417 def __copyToClipboard(self):
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
418 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
419 Private slot to copy the file name of the editor to the clipboard.
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
420 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
421 fn = self.__model.fileName()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
422
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
423 if fn:
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
424 cb = QApplication.clipboard()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
425 cb.setText(fn)
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
426
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
427 @pyqtSlot()
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
428 def __incWidth(self):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
429 """
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
430 Private slot to increment the width of the outline.
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
431 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
432 self.setMaximumWidth(
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
433 self.maximumWidth() +
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
434 Preferences.getEditor("SourceOutlineStepSize")
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
435 )
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
436 self.updateGeometry()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
437
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
438 @pyqtSlot()
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
439 def __decWidth(self):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
440 """
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
441 Private slot to decrement the width of the outline.
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
442 """
7750
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
443 stepSize = Preferences.getEditor("SourceOutlineStepSize")
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
444 newWidth = self.maximumWidth() - stepSize
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
445
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
446 self.setMaximumWidth(max(newWidth, 2 * stepSize))
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
447 self.updateGeometry()
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
448
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
449 @pyqtSlot()
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
450 def __defaultWidth(self):
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
451 """
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
452 Private slot to set the outline to the default width.
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
453 """
b16930e5baa9 Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7749
diff changeset
454 self.setMaximumWidth(Preferences.getEditor("SourceOutlineWidth"))
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
455 self.updateGeometry()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
456
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
457 #######################################################################
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
458 ## Methods handling editor signals below
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
459 #######################################################################
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
460
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
461 @pyqtSlot()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
462 def __editorLanguageChanged(self):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
463 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
464 Private slot handling a change of the associated editors source code
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
465 language.
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
466 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
467 self.__model.repopulate()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
468 self.__resizeColumns()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
469
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
470 @pyqtSlot()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
471 def __editorRenamed(self):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
472 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
473 Private slot handling a renaming of the associated editor.
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
474 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
475 self.__model.repopulate()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
476 self.__resizeColumns()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
477
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
478 @pyqtSlot(int)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
479 def __editorCursorLineChanged(self, lineno):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
480 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
481 Private method to highlight a node given its line number.
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
482
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
483 @param lineno zero based line number of the item
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
484 @type int
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
485 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
486 sindex = self.__model.itemIndexByLine(lineno + 1)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
487 if sindex.isValid():
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
488 index = self.model().mapFromSource(sindex)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
489 if index.isValid():
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
490 self.setCurrentIndex(index)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
491 self.scrollTo(index)
7696
f7e2cb3fc9d4 EditorOutline: reset the current item marker when no item could be found matching the cursor position.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7692
diff changeset
492 else:
f7e2cb3fc9d4 EditorOutline: reset the current item marker when no item could be found matching the cursor position.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7692
diff changeset
493 self.setCurrentIndex(QModelIndex())

eric ide

mercurial