This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/release/scripts/textplugin_outliner.py
Ian Thompson 6352cd509e BPyTextPlugin now has descriptors for variables, functions and classes (and their variables/functions). Each descriptor also holds the line number of the definition allowing a simple outliner to be written.
Text.setCursorPos(row, col) now pops the text into view if it is in the active window space. The outliner uses this to jump to any definition in a script; it is invoked with Ctrl+T.
2008-07-21 00:38:42 +00:00

82 lines
1.5 KiB
Python

#!BPY
"""
Name: 'Outline'
Blender: 246
Group: 'TextPlugin'
Shortcut: 'Ctrl+T'
Tooltip: 'Provides a menu for jumping to class and functions definitions.'
"""
# Only run if we have the required modules
try:
import bpy
from BPyTextPlugin import *
from Blender import Draw
OK = True
except ImportError:
OK = False
def do_long_menu(title, items):
n = len(items)
if n < 20:
return Draw.PupMenu(title+'%t|'+'|'.join(items))
letters = []
check = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_' # Cannot start 0-9 so just letters
for c in check:
for item in items:
if item[0].upper() == c:
letters.append(c)
break
i = Draw.PupMenu(title+'%t|'+'|'.join(letters))
if i < 1:
return i
c = letters[i-1]
newitems = []
i = 0
for item in items:
i += 1
if item[0].upper() == c:
newitems.append(item+'%x'+str(i))
return Draw.PupMenu(title+'%t|'+'|'.join(newitems))
def main():
txt = bpy.data.texts.active
if not txt:
return
items = []
i = Draw.PupMenu('Outliner%t|Classes|Defs|Variables')
if i < 1: return
script = get_cached_descriptor(txt)
if i == 1:
type = script.classes
elif i == 2:
type = script.defs
elif i == 3:
type = script.vars
else:
return
items.extend(type.keys())
items.sort(cmp = suggest_cmp)
i = do_long_menu('Outliner', items)
if i < 1:
return
try:
desc = type[items[i-1]]
except:
desc = None
if desc:
txt.setCursorPos(desc.lineno-1, 0)
# Check we are running as a script and not imported as a module
if __name__ == "__main__" and OK:
main()