2008-06-24 15:25:25 +00:00
|
|
|
#!BPY
|
|
|
|
"""
|
2008-08-10 16:07:14 +00:00
|
|
|
Name: 'Suggest All | Ctrl Space'
|
2008-07-15 07:34:46 +00:00
|
|
|
Blender: 246
|
2008-06-24 15:25:25 +00:00
|
|
|
Group: 'TextPlugin'
|
2008-07-15 07:04:31 +00:00
|
|
|
Shortcut: 'Ctrl+Space'
|
2008-07-15 07:34:46 +00:00
|
|
|
Tooltip: 'Performs suggestions based on the context of the cursor'
|
2008-06-24 15:25:25 +00:00
|
|
|
"""
|
|
|
|
|
2008-07-15 07:34:46 +00:00
|
|
|
# Only run if we have the required modules
|
|
|
|
try:
|
|
|
|
import bpy
|
|
|
|
from BPyTextPlugin import *
|
2008-07-15 12:55:20 +00:00
|
|
|
except ImportError:
|
2008-07-15 07:34:46 +00:00
|
|
|
OK = False
|
2008-07-26 20:02:10 +00:00
|
|
|
else:
|
|
|
|
OK = True
|
2008-06-24 15:25:25 +00:00
|
|
|
|
2008-07-15 12:55:20 +00:00
|
|
|
def check_membersuggest(line, c):
|
|
|
|
pos = line.rfind('.', 0, c)
|
|
|
|
if pos == -1:
|
|
|
|
return False
|
|
|
|
for s in line[pos+1:c]:
|
2008-08-10 16:07:14 +00:00
|
|
|
if not s.isalnum() and s != '_':
|
2008-07-15 12:55:20 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def check_imports(line, c):
|
2008-08-10 16:07:14 +00:00
|
|
|
pos = line.rfind('import ', 0, c)
|
|
|
|
if pos > -1:
|
|
|
|
for s in line[pos+7:c]:
|
|
|
|
if not s.isalnum() and s != '_':
|
|
|
|
return False
|
2008-07-15 12:55:20 +00:00
|
|
|
return True
|
2008-08-10 16:07:14 +00:00
|
|
|
pos = line.rfind('from ', 0, c)
|
|
|
|
if pos > -1:
|
|
|
|
for s in line[pos+5:c]:
|
|
|
|
if not s.isalnum() and s != '_':
|
|
|
|
return False
|
2008-07-15 12:55:20 +00:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2008-07-15 07:34:46 +00:00
|
|
|
def main():
|
|
|
|
txt = bpy.data.texts.active
|
2008-07-16 12:56:23 +00:00
|
|
|
if not txt:
|
|
|
|
return
|
|
|
|
|
2008-08-15 23:14:22 +00:00
|
|
|
line, c = current_line(txt)
|
2008-06-24 15:25:25 +00:00
|
|
|
|
2008-07-15 07:34:46 +00:00
|
|
|
# Check we are in a normal context
|
2008-07-21 00:38:42 +00:00
|
|
|
if get_context(txt) != CTX_NORMAL:
|
2008-07-15 07:34:46 +00:00
|
|
|
return
|
2008-06-24 15:25:25 +00:00
|
|
|
|
2008-07-15 12:55:20 +00:00
|
|
|
# Check the character preceding the cursor and execute the corresponding script
|
2008-06-24 15:25:25 +00:00
|
|
|
|
2008-07-15 12:55:20 +00:00
|
|
|
if check_membersuggest(line, c):
|
2008-07-15 07:34:46 +00:00
|
|
|
import textplugin_membersuggest
|
2008-07-16 10:33:48 +00:00
|
|
|
textplugin_membersuggest.main()
|
2008-07-15 07:34:46 +00:00
|
|
|
return
|
2008-07-15 12:55:20 +00:00
|
|
|
|
|
|
|
elif check_imports(line, c):
|
2008-07-15 07:34:46 +00:00
|
|
|
import textplugin_imports
|
2008-07-16 10:33:48 +00:00
|
|
|
textplugin_imports.main()
|
2008-07-15 07:34:46 +00:00
|
|
|
return
|
2008-06-24 15:25:25 +00:00
|
|
|
|
2008-07-15 12:55:20 +00:00
|
|
|
# Otherwise we suggest globals, keywords, etc.
|
2008-07-15 07:34:46 +00:00
|
|
|
list = []
|
2008-08-15 23:14:22 +00:00
|
|
|
targets = get_targets(line, c)
|
2008-08-12 15:17:08 +00:00
|
|
|
desc = get_cached_descriptor(txt)
|
2008-06-24 15:25:25 +00:00
|
|
|
|
2008-07-15 07:34:46 +00:00
|
|
|
for k in KEYWORDS:
|
|
|
|
list.append((k, 'k'))
|
2008-06-24 15:25:25 +00:00
|
|
|
|
2008-07-15 07:34:46 +00:00
|
|
|
for k, v in get_builtins().items():
|
|
|
|
list.append((k, type_char(v)))
|
2008-06-24 15:25:25 +00:00
|
|
|
|
2008-08-12 15:17:08 +00:00
|
|
|
for k, v in desc.imports.items():
|
2008-07-15 07:34:46 +00:00
|
|
|
list.append((k, type_char(v)))
|
2008-06-24 15:25:25 +00:00
|
|
|
|
2008-08-12 15:17:08 +00:00
|
|
|
for k, v in desc.classes.items():
|
2008-07-15 07:34:46 +00:00
|
|
|
list.append((k, 'f'))
|
2008-06-25 13:51:54 +00:00
|
|
|
|
2008-08-12 15:17:08 +00:00
|
|
|
for k, v in desc.defs.items():
|
|
|
|
list.append((k, 'f'))
|
|
|
|
|
|
|
|
for k, v in desc.vars.items():
|
2008-07-15 12:55:20 +00:00
|
|
|
list.append((k, 'v'))
|
|
|
|
|
2008-07-15 07:34:46 +00:00
|
|
|
list.sort(cmp = suggest_cmp)
|
2008-08-15 23:14:22 +00:00
|
|
|
txt.suggest(list, targets[-1])
|
2008-06-24 15:25:25 +00:00
|
|
|
|
2008-07-16 10:33:48 +00:00
|
|
|
# Check we are running as a script and not imported as a module
|
|
|
|
if __name__ == "__main__" and OK:
|
2008-07-15 07:34:46 +00:00
|
|
|
main()
|