diff options
author | Ian Thompson <quornian@googlemail.com> | 2008-07-21 04:38:42 +0400 |
---|---|---|
committer | Ian Thompson <quornian@googlemail.com> | 2008-07-21 04:38:42 +0400 |
commit | 6352cd509e6e6f834684ec1e24c42e274a2ed31b (patch) | |
tree | b6c0857db136f08ee149feb66f0136249aa05a3b /release/scripts/textplugin_outliner.py | |
parent | f042a468fdd0f06ca41c022c9ed6ac59d35ff143 (diff) |
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.
Diffstat (limited to 'release/scripts/textplugin_outliner.py')
-rw-r--r-- | release/scripts/textplugin_outliner.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/release/scripts/textplugin_outliner.py b/release/scripts/textplugin_outliner.py new file mode 100644 index 00000000000..64750b6ba13 --- /dev/null +++ b/release/scripts/textplugin_outliner.py @@ -0,0 +1,81 @@ +#!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() |