pida-patches / kill-outliner-types-enum

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# HG changeset patch
# User Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
# Date 1280876358 -7200
# Node ID d2deb6f3af308ed68f2952d00e9a6c533cf5c978
# Parent 67c254c58f20267d279479e02de51171cfe7b0d0
replace the LANG_TYPES enum with the OUTLINER symbol bag

diff --git a/pida-plugins/ctags/ctags.py b/pida-plugins/ctags/ctags.py
--- a/pida-plugins/ctags/ctags.py
+++ b/pida-plugins/ctags/ctags.py
@@ -37,7 +37,7 @@ from pida.core.options import OptionsCon
 from pida.core.languages import (LanguageService, Outliner, Validator,
     Completer, LanguageServiceFeaturesConfig, LanguageInfo, Definer, Documentator)
 
-from pida.utils.languages import (LANG_PRIO, LANG_OUTLINER_TYPES, OutlineItem )
+from pida.utils.languages import LANG_PRIO, OutlineItem
 
 # locale
 from pida.core.locale import Locale
@@ -282,19 +282,21 @@ class CtagsOutliner(Outliner):
 		v	variable        
         """
         def v2t(i):
-            if i == 'm': return LANG_OUTLINER_TYPES.MEMBER
-            if i == 'c': return LANG_OUTLINER_TYPES.CLASS
-            if i == 'd': return LANG_OUTLINER_TYPES.DEFINE
-            if i == 'e': return LANG_OUTLINER_TYPES.ENUMERATION
-            if i == 'f': return LANG_OUTLINER_TYPES.FUNCTION
-            if i == 'g': return LANG_OUTLINER_TYPES.ENUMERATION_NAME
-            if i == 'n': return LANG_OUTLINER_TYPES.NAMESPACE
-            if i == 'p': return LANG_OUTLINER_TYPES.PROTOTYPE
-            if i == 's': return LANG_OUTLINER_TYPES.STRUCTURE
-            if i == 't': return LANG_OUTLINER_TYPES.TYPEDEF
-            if i == 'u': return LANG_OUTLINER_TYPES.UNION
-            if i == 'v': return LANG_OUTLINER_TYPES.VARIABLE
-            return LANG_OUTLINER_TYPES.UNKNOWN
+            mapping = {
+                'm': 'member',
+                'c': 'class',
+                'd': 'define',
+                'e': 'enumeration',
+                'f': 'function',
+                'g': 'enumeration_name',
+                'n': 'namespace',
+                'p': 'prototype',
+                's': 'structure',
+                't': 'typedef',
+                'u': 'union',
+                'v': 'variable',
+            }
+            return mapping.get(i, 'unknown')
 
         if len(tokrow) == 4 and isinstance(tokrow[3], int):
             return tokrow[3]
@@ -304,8 +306,8 @@ class CtagsOutliner(Outliner):
                 return v2t(i)# most common case: just one char
             elif i[:4] == "kind":
                 return v2t(i[5:])
-            return LANG_OUTLINER_TYPES.UNKNOWN
-        return LANG_OUTLINER_TYPES.UNKNOWN
+            return 'unknown'
+        return 'unknown'
 
 
     def _get_container_name(self, tokrow):
@@ -327,15 +329,9 @@ class CtagsOutliner(Outliner):
         """ class, enumerations, structs and unions are considerer containers.
             See Issue 13 for some issues we had with this.
         """
-        if self._get_type(tokrow) in (
-            LANG_OUTLINER_TYPES.CLASS,
-            LANG_OUTLINER_TYPES.ENUMERATION_NAME,
-            LANG_OUTLINER_TYPES.STRUCTURE,
-            LANG_OUTLINER_TYPES.UNION,
-            LANG_OUTLINER_TYPES.TYPEDEF): 
-                return True
-        return False
-            
+        return self._get_type(tokrow) in (
+            'class', 'enumeration_name',
+            'structure', 'union', 'typedef')
         # remove temp file
         #os.remove(tmpfile)
 
diff --git a/pida-plugins/python/python.py b/pida-plugins/python/python.py
--- a/pida-plugins/python/python.py
+++ b/pida-plugins/python/python.py
@@ -39,7 +39,6 @@ from pida.core.languages import (Languag
 
 from pida.utils.languages import (
     COMPLETER, VALIDATOR_LEVEL, VALIDATOR_KIND,
-    LANG_OUTLINER_TYPES, 
     LANG_PRIO, Definition, Suggestion, Documentation, ValidationError)
 
 # services
@@ -132,14 +131,10 @@ class PythonOutliner(Outliner):
     description = _("A very deep and precises, but slow outliner")
 
 
-    filter_type = (LANG_OUTLINER_TYPES.IMPORT,
-                    LANG_OUTLINER_TYPES.BUILTIN,
-                    LANG_OUTLINER_TYPES.METHOD,
-                    LANG_OUTLINER_TYPES.FUNCTION,
-                    LANG_OUTLINER_TYPES.PROPERTY,
-                    LANG_OUTLINER_TYPES.ATTRIBUTE,
-                    LANG_OUTLINER_TYPES.SUPERMETHOD,
-                    )
+    filter_type = (
+        'import', 'builtin', 'method', 'function',
+        'property', 'attribute', 'supermethod',
+        )
 
     def get_outline(self):
         from rope.base.exceptions import RopeError
diff --git a/pida-plugins/python/ropebrowser.py b/pida-plugins/python/ropebrowser.py
--- a/pida-plugins/python/ropebrowser.py
+++ b/pida-plugins/python/ropebrowser.py
@@ -14,7 +14,7 @@ from pida.core.projects import Project a
 from rope.base.project import Project, get_no_project
 from rope.base import pynames, pyobjects, builtins
 
-from pida.utils.languages import LANG_OUTLINER_TYPES, OutlineItem
+from pida.utils.languages import OutlineItem
 from itertools import count
 
 OUTLINE_COUNTER = count()
@@ -70,7 +70,7 @@ class TreeOptions(object):
     position = 0
     has_children = False
     icon_name = 'source-property'
-    filter_type =  LANG_OUTLINER_TYPES.UNKNOWN
+    filter_type = 'unknown'
 
     def __init__(self, treeitem, obj):
         pass
@@ -91,7 +91,7 @@ class FunctionOptions(TreeOptions):
     icon_name = 'source-function'
     type_color = '#900000'
     position = 2
-    filter_type = LANG_OUTLINER_TYPES.UNKNOWN
+    filter_type = 'unknown'
 
     def __init__(self, item, obj):
         decs = []
@@ -126,13 +126,13 @@ class EvaluatedOptions(TreeOptions):
     type_name = 'p'
     icon_name = 'source-property'
     type_color = '#900090'
-    filter_type = LANG_OUTLINER_TYPES.PROPERTY
+    filter_type = 'property'
 
 class MethodOptions(FunctionOptions):
 
     type_name = 'm'
     icon_name = 'source-method'
-    filter_type = LANG_OUTLINER_TYPES.METHOD
+    filter_type = 'method'
 
 
 class SuperMethodOptions(MethodOptions):
@@ -140,7 +140,7 @@ class SuperMethodOptions(MethodOptions):
     type_name = '(m)'
     icon_name = 'source-extramethod'
     position = 6
-    filter_type = LANG_OUTLINER_TYPES.SUPERMETHOD
+    filter_type = 'supermethod'
 
 
 class ClassMethodOptions(MethodOptions):
@@ -188,7 +188,7 @@ class AssignedOptions(TreeOptions):
     icon_name = 'source-attribute'
     type_color = '#009000'
     position = 5
-    filter_type = LANG_OUTLINER_TYPES.ATTRIBUTE
+    filter_type = 'attribute'
 
 
 class BuiltinOptions(TreeOptions):
@@ -197,7 +197,7 @@ class BuiltinOptions(TreeOptions):
     icon_name = None
     type_color = '#999999'
     position = 7
-    filter_type = LANG_OUTLINER_TYPES.BUILTIN
+    filter_type = 'builtin'
 
 
 class ImportedOptions(TreeOptions):
@@ -206,7 +206,7 @@ class ImportedOptions(TreeOptions):
     icon_name = 'source-import'
     type_color = '#999999'
     position = 8
-    filter_type = LANG_OUTLINER_TYPES.IMPORT
+    filter_type = 'import'
 
 
 def get_option_for_item(item, node, obj, parent_obj=None):
diff --git a/pida-plugins/rst/rst.py b/pida-plugins/rst/rst.py
--- a/pida-plugins/rst/rst.py
+++ b/pida-plugins/rst/rst.py
@@ -13,7 +13,7 @@ from collections import defaultdict
 # PIDA imports
 from pida.core.languages import LanguageService, Outliner, Validator
 from pida.utils.languages import (
-    LANG_PRIO, LANG_OUTLINER_TYPES,
+    LANG_PRIO,
     VALIDATOR_LEVEL, VALIDATOR_KIND,
     OutlineItem, ValidationError,
 )
@@ -248,8 +248,7 @@ class RSTOutliner(Outliner):
     name = "rst outliner"
     description = _("An outliner for ReStructuredText")
 
-    section_types = (LANG_OUTLINER_TYPES.SECTION,
-                     LANG_OUTLINER_TYPES.PARAGRAPH)
+    section_types = ('section', 'paragraph')
 
     def get_outline(self):
         self.doc_items = RSTTokenList()
@@ -281,7 +280,7 @@ class RSTOutliner(Outliner):
                   isinstance(node, nodes.figure)):
                 new_item = True
                 name = node.attributes['uri']
-                type = LANG_OUTLINER_TYPES.UNKNOWN
+                type = 'unknown'
                 is_container = False
                 # nodes with options have no line attribute
                 linenumber = node.line or node.parent.line
diff --git a/pida/services/language/outlinefilter.py b/pida/services/language/outlinefilter.py
--- a/pida/services/language/outlinefilter.py
+++ b/pida/services/language/outlinefilter.py
@@ -1,56 +1,56 @@
-from pida.utils.languages import LANG_OUTLINER_TYPES
+from pida.utils.languages import OUTLINER
 
 FILTERMAP = {
-    LANG_OUTLINER_TYPES.IMPORT: {
+    OUTLINER.IMPORT: {
         "name": "import",
         "alias": "include",
         "display": "Imports",
         "icon": "source-import",
         "default": True 
     },
-    LANG_OUTLINER_TYPES.BUILTIN: {
+    OUTLINER.BUILTIN: {
         "name": "builtin",
         "alias": "",
         "display": "Builtins",
         "icon": "source-module",
         "default": True
     },
-    LANG_OUTLINER_TYPES.ATTRIBUTE: {
+    OUTLINER.ATTRIBUTE: {
         "name": "attribute",
         "alias": "",
         "display": "Attributes",
         "icon": "source-attribute",
         "default": True
     },
-    LANG_OUTLINER_TYPES.METHOD: {
+    OUTLINER.METHOD: {
         "name": "method",
         "alias": "",
         "display": "Methods",
         "icon": "source-method",
         "default": True
     },
-    LANG_OUTLINER_TYPES.PROPERTY: {
+    OUTLINER.PROPERTY: {
         "name": "property",
         "alias": "",
         "display": "Properties",
         "icon": "source-property",
         "default": True
     },
-    LANG_OUTLINER_TYPES.FUNCTION: {
+    OUTLINER.FUNCTION: {
         "name": "function",
         "alias": "",
         "display": "Functions",
         "icon": "source-function",
         "default": True
     },
-    LANG_OUTLINER_TYPES.SUPERMETHOD: {
+    OUTLINER.SUPERMETHOD: {
         "name": "import",
         "alias": "include",
         "display": "Super methods",
         "icon": "source-extramethod",
         "default": True 
     },
-    LANG_OUTLINER_TYPES.SUPERPROPERTY: {
+    OUTLINER.SUPERPROPERTY: {
         "name": "import",
         "alias": "include",
         "display": "Super properties",
diff --git a/pida/services/language/views.py b/pida/services/language/views.py
--- a/pida/services/language/views.py
+++ b/pida/services/language/views.py
@@ -517,7 +517,7 @@ class BrowserView(PidaView):
                 )
             for f in self.filter_map:
                 tool_button = gtk.ToggleToolButton()
-                tool_button.set_name(str(f))
+                tool_button.set_data('pida/outliner', f)
                 tool_button.set_active(self.filter_map[f])
                 #FIXME no tooltip on win32
                 if not on_windows:
@@ -539,7 +539,8 @@ class BrowserView(PidaView):
         self.options_vbox.show_all()
 
     def on_filter_toggled(self, but, outliner):
-        self.filter_map[int(but.get_name())] = not self.filter_map[int(but.get_name())]
+        name = but.get_data('pida/outliner')
+        self.filter_map[name] = not self.filter_map[name]
         #self.set_outliner(outliner, self.document)
         self.filter_model.refilter()
 
diff --git a/pida/utils/languages.py b/pida/utils/languages.py
--- a/pida/utils/languages.py
+++ b/pida/utils/languages.py
@@ -51,14 +51,13 @@ VALIDATOR_LEVEL = Symbols('validation le
 
 # validation sub types
 
-LANG_TYPES = Enumeration('LANG_TYPES',
- ('', 'UNKNOWN', 
- 'ATTRIBUTE', 'BUILTIN', 'CLASS', 'DEFINE', 'ENUMERATION',
- 'ENUMERATION_NAME', 'FUNCTION', 'IMPORT', 'MEMBER', 'METHOD', 'PROPERTY',
- 'PROTOTYPE', 'STRUCTURE', 'SUPERMETHOD', 'SUPERPROPERTY', 'TYPEDEF', 'UNION',
- 'VARIABLE', 'NAMESPACE', 'ELEMENT', 'SECTION', 'CHAPTER', 'PARAGRAPH'))
+OUTLINER = Symbols('outline',
+ ('unknown',
+ 'attribute', 'builtin', 'class', 'define', 'enumeration',
+ 'enumeration_name', 'function', 'import', 'member', 'method', 'property',
+ 'prototype', 'structure', 'supermethod', 'superproperty', 'typedef', 'union',
+ 'variable', 'namespace', 'element', 'section', 'chapter', 'paragraph'))
 
-LANG_OUTLINER_TYPES = LANG_TYPES
 
 LANG_PRIO = Enumeration('LANG_PRIORITIES',
 (
@@ -72,29 +71,29 @@ LANG_PRIO = Enumeration('LANG_PRIORITIES
 
 
 LANG_IMAGE_MAP = {
-    LANG_TYPES.ATTRIBUTE: 'source-attribute',
-    LANG_TYPES.BUILTIN: 'source-attribute',
-    LANG_TYPES.CLASS: 'source-class',
-    LANG_TYPES.DEFINE: 'source-define',
-    LANG_TYPES.ENUMERATION: 'source-enum',
-    LANG_TYPES.ENUMERATION_NAME: 'source-enumarator',
-    LANG_TYPES.FUNCTION: 'source-function',
-    LANG_TYPES.IMPORT: 'source-import',
-    LANG_TYPES.MEMBER: 'source-member',
-    LANG_TYPES.METHOD: 'source-method',
-    LANG_TYPES.PROTOTYPE: 'source-interface',
-    LANG_TYPES.PROPERTY: 'source-property',
-    LANG_TYPES.METHOD: 'source-method',
-    LANG_TYPES.SUPERMETHOD: 'source-extramethod',
+    OUTLINER.ATTRIBUTE: 'source-attribute',
+    OUTLINER.BUILTIN: 'source-attribute',
+    OUTLINER.CLASS: 'source-class',
+    OUTLINER.DEFINE: 'source-define',
+    OUTLINER.ENUMERATION: 'source-enum',
+    OUTLINER.ENUMERATION_NAME: 'source-enumarator',
+    OUTLINER.FUNCTION: 'source-function',
+    OUTLINER.IMPORT: 'source-import',
+    OUTLINER.MEMBER: 'source-member',
+    OUTLINER.METHOD: 'source-method',
+    OUTLINER.PROTOTYPE: 'source-interface',
+    OUTLINER.PROPERTY: 'source-property',
+    OUTLINER.METHOD: 'source-method',
+    OUTLINER.SUPERMETHOD: 'source-extramethod',
     #FIXME: superproperty icon
-    LANG_TYPES.SUPERPROPERTY: 'source-property',
-    LANG_TYPES.TYPEDEF: 'source-typedef',
-    LANG_TYPES.UNION: 'source-union',
-    LANG_TYPES.VARIABLE: 'source-variable',
-    LANG_TYPES.SECTION: 'source-section',
-    LANG_TYPES.PARAGRAPH: 'source-paragraph',
-    LANG_TYPES.NAMESPACE: 'source-namespace',
-    LANG_TYPES.ELEMENT: 'source-element',
+    OUTLINER.SUPERPROPERTY: 'source-property',
+    OUTLINER.TYPEDEF: 'source-typedef',
+    OUTLINER.UNION: 'source-union',
+    OUTLINER.VARIABLE: 'source-variable',
+    OUTLINER.SECTION: 'source-section',
+    OUTLINER.PARAGRAPH: 'source-paragraph',
+    OUTLINER.NAMESPACE: 'source-namespace',
+    OUTLINER.ELEMENT: 'source-element',
 }
 
 
@@ -159,7 +158,7 @@ class OutlineItem(InitObject):
     """
     Outlines are returned by an Outliner class
     """
-    type = LANG_TYPES.UNKNOWN
+    type = OUTLINER.UNKNOWN
     name = ''
     parent = None
     id = None
@@ -196,7 +195,7 @@ class OutlineItem(InitObject):
 
 class Definition(InitObject):
     """Returned by a Definer instance"""
-    type = LANG_TYPES.UNKNOWN
+    type = OUTLINER.UNKNOWN
     file_name = None
     offset = None
     length = None
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.