eric6/QScintilla/EditorOutlineModel.py

Wed, 09 Sep 2020 18:05:58 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 09 Sep 2020 18:05:58 +0200
changeset 7697
c981a807aab1
parent 7690
a59680062837
child 7757
1f9f35f9be6d
permissions
-rw-r--r--

EditorOutlineModel: fixed an issue causing ProtoBuf files not being outlined.

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
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de>
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 the editor outline model.
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
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt5.QtCore import QCoreApplication, QModelIndex
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from UI.BrowserModel import (
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 BrowserModel, BrowserItem, BrowserClassItem, BrowserCodingItem,
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
16 BrowserGlobalsItem, BrowserImportsItem, BrowserImportItem,
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
17 BrowserClassAttributesItem, BrowserMethodItem
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
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 class EditorOutlineModel(BrowserModel):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Class implementing the editor outline model.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 SupportedLanguages = (
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 "IDL", "JavaScript", "Protocol", "Python3", "MicroPython", "Ruby",
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 )
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):
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 containing the source text
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 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 super(EditorOutlineModel, self).__init__(nopopulate=True)
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 self.__editor = editor
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.__populated = False
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 rootData = QCoreApplication.translate("EditorOutlineModel", "Name")
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.rootItem = BrowserItem(None, rootData)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
47 if populate:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
48 self.__populateModel()
7685
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 def __populateModel(self, repopulate=False):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 Private slot to populate the model.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 @param repopulate flag indicating a repopulation
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 @type bool
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 """
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
57 self.__filename = self.__editor.getFileName()
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
58 self.__module = os.path.basename(self.__filename)
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
59
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 language = self.__editor.getLanguage()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 if language in EditorOutlineModel.SupportedLanguages:
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
62 if language == "IDL":
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
63 from Utilities.ClassBrowsers import idlclbr
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
64 dictionary = idlclbr.scan(
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
65 self.__editor.text(), self.__filename, self.__module)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
66 idlclbr._modules.clear()
7697
c981a807aab1 EditorOutlineModel: fixed an issue causing ProtoBuf files not being outlined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
67 elif language == "Protocol":
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
68 from Utilities.ClassBrowsers import protoclbr
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
69 dictionary = protoclbr.scan(
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
70 self.__editor.text(), self.__filename, self.__module)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
71 protoclbr._modules.clear()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
72 elif language == "Ruby":
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
73 from Utilities.ClassBrowsers import rbclbr
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
74 dictionary = rbclbr.scan(
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
75 self.__editor.text(), self.__filename, self.__module)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
76 rbclbr._modules.clear()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
77 elif language == "JavaScript":
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
78 from Utilities.ClassBrowsers import jsclbr
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
79 dictionary = jsclbr.scan(
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
80 self.__editor.text(), self.__filename, self.__module)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
81 jsclbr._modules.clear()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
82 elif language in ("Python3", "MicroPython"):
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 from Utilities.ClassBrowsers import pyclbr
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
84 dictionary = pyclbr.scan(
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
85 self.__editor.text(), self.__filename, self.__module)
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 pyclbr._modules.clear()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 keys = list(dictionary.keys())
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 if len(keys) > 0:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 parentItem = self.rootItem
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 if repopulate:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.beginInsertRows(
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 QModelIndex(),
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 0, len(keys) - 1)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 for key in keys:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 if key.startswith("@@"):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 # special treatment done later
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 continue
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 cl = dictionary[key]
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 try:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 if cl.module == self.__module:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 node = BrowserClassItem(
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 parentItem, cl, self.__filename)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 self._addItem(node, parentItem)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 except AttributeError:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 pass
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 if "@@Coding@@" in keys:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 node = BrowserCodingItem(
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 parentItem,
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 QCoreApplication.translate(
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 "EditorOutlineModel", "Coding: {0}")
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
114 .format(dictionary["@@Coding@@"].coding),
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
115 dictionary["@@Coding@@"].linenumber)
7685
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 self._addItem(node, parentItem)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 if "@@Globals@@" in keys:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 node = BrowserGlobalsItem(
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 parentItem,
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 dictionary["@@Globals@@"].globals,
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 QCoreApplication.translate(
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 "EditorOutlineModel", "Globals"))
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 self._addItem(node, parentItem)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 if "@@Import@@" in keys or "@@ImportFrom@@" in keys:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 node = BrowserImportsItem(
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 parentItem,
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 QCoreApplication.translate(
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 "EditorOutlineModel", "Imports"))
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 self._addItem(node, parentItem)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 if "@@Import@@" in keys:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 for importedModule in (
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 dictionary["@@Import@@"].getImports().values()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 ):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 m_node = BrowserImportItem(
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 node,
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 importedModule.importedModuleName,
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 importedModule.file,
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 importedModule.linenos)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 self._addItem(m_node, node)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 for importedName, linenos in (
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 importedModule.importedNames.items()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 ):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 mn_node = BrowserImportItem(
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 m_node,
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 importedName,
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 importedModule.file,
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 linenos,
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 isModule=False)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self._addItem(mn_node, m_node)
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 if repopulate:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 self.endInsertRows()
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 self.__populated = True
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 else:
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 self.clear()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 self.__populated = False
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 def isPopulated(self):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 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
161
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 @return flag indicating a populated model
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 @rtype bool
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 return self.__populated
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 def repopulate(self):
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 Public slot to repopulate the model.
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 self.clear()
0b6e8c0d6403 Started implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 self.__populateModel(repopulate=True)
7686
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
173
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
174 def editor(self):
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
175 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
176 Public method to retrieve a reference to the editor.
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
177
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
178 @return reference to the editor
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
179 @rtype Editor
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
180 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
181 return self.__editor
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
182
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
183 def fileName(self):
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
184 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
185 Public method to retrieve the file name of the editor.
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
186
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
187 @return file name of the editor
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
188 @rtype str
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
189 """
379d402162ca Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
190 return self.__filename
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
191
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
192 def itemIndexByLine(self, lineno):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
193 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
194 Public method to find an item's index given a line number.
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
195
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
196 @param lineno one based line number of the item
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
197 @type int
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
198 @return index of the item found
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
199 @rtype QModelIndex
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
200 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
201 def findItem(lineno, parent):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
202 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
203 Function to iteratively search for an item containing the given
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
204 line.
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
205
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
206 @param lineno one based line number of the item
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
207 @type int
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
208 @param parent reference to the parent item
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
209 @type BrowserItem
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
210 @return found item or None
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
211 @rtype BrowserItem
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
212 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
213 if not parent.isPopulated():
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
214 if parent.isLazyPopulated():
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
215 self.populateItem(parent)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
216 else:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
217 return None
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
218 for child in parent.children():
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
219 if isinstance(child, BrowserClassAttributesItem):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
220 itm = findItem(lineno, child)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
221 if itm is not None:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
222 return itm
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
223 elif isinstance(child, (BrowserClassItem, BrowserMethodItem)):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
224 start, end = child.boundaries()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
225 if end == -1:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
226 end = 1000000 # assume end of file
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
227 if start <= lineno <= end:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
228 itm = findItem(lineno, child)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
229 if itm is not None:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
230 return itm
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
231 else:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
232 return child
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
233 elif hasattr(child, "linenos"):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
234 if lineno in child.linenos():
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
235 return child
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
236 elif hasattr(child, "lineno"):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
237 if lineno == child.lineno():
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
238 return child
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
239 else:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
240 return None
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
241
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
242 if self.__populated:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
243 for rootChild in self.rootItem.children():
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
244 itm = None
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
245 if isinstance(rootChild, BrowserClassItem):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
246 start, end = rootChild.boundaries()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
247 if end == -1:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
248 end = 1000000 # assume end of file
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
249 if start <= lineno <= end:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
250 itm = findItem(lineno, rootChild)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
251 if itm is None:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
252 itm = rootChild
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
253 elif isinstance(rootChild,
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
254 (BrowserImportsItem, BrowserGlobalsItem)):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
255 itm = findItem(lineno, rootChild)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
256 elif (
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
257 isinstance(rootChild, BrowserCodingItem) and
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
258 lineno == rootChild.lineno()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
259 ):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
260 itm = rootChild
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
261 if itm is not None:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
262 return self.createIndex(itm.row(), 0, itm)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
263 else:
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
264 return QModelIndex()
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
265
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7686
diff changeset
266 return QModelIndex()

eric ide

mercurial