1
# ##### BEGIN GPL LICENSE BLOCK #####
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software Foundation,
15
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
# ##### END GPL LICENSE BLOCK #####
20
'name': "Class Viewer",
21
'author': "Mackraken", "batFinger"
24
'location': "Text Editor > Toolbar, Text Editor > Right Click",
26
'description': "List text's classes and definitions",
27
'wiki_url': "https://sites.google.com/site/aleonserra/home/scripts/class-viewer",
28
'category': "Development"}
32
#lists all defs, comment or classes
33
#space = current text editor
35
#tipo = kind of struct to look for
36
#escape = character right next to the class or def name
38
def getfunc(space, sort, tipo="def ", escape= ""):
40
if space.type=="TEXT_EDITOR":
44
for i, l in enumerate(txt.lines):
50
if line[0:len(tipo)]==tipo:
51
end = line.find(escape)
53
func = line[len(tipo)::]
55
func = line[len(tipo):end]
56
defs.append([func, i+1])
62
class TEXT_OT_Jumptoline(bpy.types.Operator):
64
bl_idname = "text.jumptoline"
65
__doc__ = "Jump to line"
66
line = bpy.props.IntProperty(default=-1)
69
def poll(cls, context):
70
if context.area.spaces[0].type!="TEXT_EDITOR":
73
return context.area.spaces[0].text!=None
75
def execute(self, context):
80
bpy.ops.text.jump(line=self.line)
86
class CommentsMenu(bpy.types.Menu):
87
bl_idname = "OBJECT_MT_select_comments"
93
def poll(cls, context):
94
if context.area.spaces[0].type!="TEXT_EDITOR":
97
return context.area.spaces[0].text!=None
99
def draw(self, context):
102
space = context.area.spaces[0]
104
items = getfunc(space, 1, "### ", "")
107
layout.operator("text.jumptoline",text=it[0]).line = it[1]
109
class DefsMenu(bpy.types.Menu):
110
bl_idname = "OBJECT_MT_select_defs"
113
tipo = bpy.props.BoolProperty(default=False)
116
def poll(cls, context):
117
if context.area.spaces[0].type!="TEXT_EDITOR":
120
return context.area.spaces[0].text!=None
122
def draw(self, context):
125
space = context.area.spaces[0]
129
items = getfunc(space, 1, "def ", "(")
132
layout.operator("text.jumptoline",text=it[0]).line = it[1]
134
class ClassesMenu(bpy.types.Menu):
135
bl_idname = "OBJECT_MT_select_classes"
141
def poll(cls, context):
142
if context.area.spaces[0].type!="TEXT_EDITOR":
145
return context.area.spaces[0].text!=None
147
def draw(self, context):
150
space = context.area.spaces[0]
154
items = getfunc(space, 1, "class ", "(")
157
layout.operator("text.jumptoline",text=it[0]).line = it[1]
161
def GotoComments(self, context):
162
self.layout.menu("OBJECT_MT_select_comments", text="Comments", icon='PLUGIN')
165
def GotoDefs(self, context):
166
self.layout.menu("OBJECT_MT_select_defs", text="Defs", icon='PLUGIN')
169
def GotoClasses(self, context):
170
self.layout.menu("OBJECT_MT_select_classes", text="Classes", icon='PLUGIN')
174
classes = [TEXT_OT_Jumptoline, ClassesMenu, DefsMenu, CommentsMenu]
179
bpy.utils.register_class(c)
181
bpy.types.TEXT_MT_toolbox.append(GotoComments)
182
bpy.types.TEXT_MT_toolbox.append(GotoDefs)
183
bpy.types.TEXT_MT_toolbox.append(GotoClasses)
187
bpy.utils.unregister_class(c)
189
bpy.types.TEXT_MT_toolbox.remove(GotoComments)
190
bpy.types.TEXT_MT_toolbox.remove(GotoDefs)
191
bpy.types.TEXT_MT_toolbox.remove(GotoClasses)
193
if __name__ == "__main__":