[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16048] branches/soc-2008-quorn: Fixed inconsistencies between the text plugins and them not suggesting when called from the menu .

Ian Thompson quornian at googlemail.com
Sun Aug 10 18:07:20 CEST 2008


Revision: 16048
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16048
Author:   quorn
Date:     2008-08-10 18:07:14 +0200 (Sun, 10 Aug 2008)

Log Message:
-----------
Fixed inconsistencies between the text plugins and them not suggesting when called from the menu.

Modified Paths:
--------------
    branches/soc-2008-quorn/release/scripts/textplugin_functiondocs.py
    branches/soc-2008-quorn/release/scripts/textplugin_imports.py
    branches/soc-2008-quorn/release/scripts/textplugin_membersuggest.py
    branches/soc-2008-quorn/release/scripts/textplugin_outliner.py
    branches/soc-2008-quorn/release/scripts/textplugin_suggest.py
    branches/soc-2008-quorn/release/scripts/textplugin_templates.py
    branches/soc-2008-quorn/source/blender/src/drawtext.c

Modified: branches/soc-2008-quorn/release/scripts/textplugin_functiondocs.py
===================================================================
--- branches/soc-2008-quorn/release/scripts/textplugin_functiondocs.py	2008-08-10 14:24:14 UTC (rev 16047)
+++ branches/soc-2008-quorn/release/scripts/textplugin_functiondocs.py	2008-08-10 16:07:14 UTC (rev 16048)
@@ -1,6 +1,6 @@
 #!BPY
 """
-Name: 'Function Documentation'
+Name: 'Function Documentation | Ctrl I'
 Blender: 246
 Group: 'TextPlugin'
 Shortcut: 'Ctrl+I'
@@ -29,14 +29,22 @@
 	
 	# Look backwards for first '(' without ')'
 	b = 0
+	found = False
 	for i in range(c-1, -1, -1):
 		if line[i] == ')': b += 1
 		elif line[i] == '(':
 			b -= 1
 			if b < 0:
+				found = True
 				c = i
 				break
 	
+	# Otherwise identify the name under the cursor
+	if not found:
+		llen = len(line)
+		while c<llen and (line[c].isalnum() or line[c]=='_'):
+			c += 1
+	
 	pre = get_targets(line, c)
 	
 	if len(pre) == 0:

Modified: branches/soc-2008-quorn/release/scripts/textplugin_imports.py
===================================================================
--- branches/soc-2008-quorn/release/scripts/textplugin_imports.py	2008-08-10 14:24:14 UTC (rev 16047)
+++ branches/soc-2008-quorn/release/scripts/textplugin_imports.py	2008-08-10 16:07:14 UTC (rev 16048)
@@ -1,6 +1,6 @@
 #!BPY
 """
-Name: 'Import Complete'
+Name: 'Import Complete|Space'
 Blender: 246
 Group: 'TextPlugin'
 Shortcut: 'Space'
@@ -31,41 +31,62 @@
 	
 	# No 'from' found
 	if pos == -1:
-		# Check instead for straight 'import'
+		# Check instead for straight 'import xxxx'
 		pos2 = line.rfind('import ', 0, c)
-		if pos2 != -1 and (pos2 == c-7 or (pos2 < c-7 and line[c-2]==',')):
+		if pos2 != -1:
+			pos2 += 7
+			for i in range(pos2, c):
+				if line[i]==',' or (line[i]==' ' and line[i-1]==','):
+					pos2 = i+1
+				elif not line[i].isalnum() and line[i] != '_':
+					return
 			items = [(m, 'm') for m in get_modules()]
 			items.sort(cmp = suggest_cmp)
-			txt.suggest(items, '')
+			txt.suggest(items, line[pos2:c].strip())
+		return
 	
-	# Immediate 'from' before cursor
-	elif pos == c-5:
+	# Found 'from xxxxx' before cursor
+	immediate = True
+	pos += 5
+	for i in range(pos, c):
+		if line[i]=='.':
+			pos = i+1
+		elif not line[i].isalnum() and line[i] != '_':
+			immediate = False
+			break
+	
+	# Immediate 'from' followed by at most a module name
+	if immediate:
 		items = [(m, 'm') for m in get_modules()]
 		items.sort(cmp = suggest_cmp)
 		txt.suggest(items, '')
+		return
 	
-	# Found 'from' earlier
-	else:
-		pos2 = line.rfind('import ', pos+5, c)
+	# Found 'from' earlier, suggest import if not already there
+	pos2 = line.rfind('import ', pos, c)
+	
+	# No 'import' found after 'from' so suggest it
+	if pos2 == -1:
+		txt.suggest([('import', 'k')], '')
+		return
 		
-		# No 'import' found after 'from' so suggest it
-		if pos2 == -1:
-			txt.suggest([('import', 'k')], '')
-			
-		# Immediate 'import' before cursor and after 'from...'
-		elif pos2 == c-7 or line[c-2] == ',':
-			between = line[pos+5:pos2-1].strip()
-			try:
-				mod = get_module(between)
-			except ImportError:
-				print 'Module not found:', between
-				return
-			
-			items = [('*', 'k')]
-			for (k,v) in mod.__dict__.items():
-				items.append((k, type_char(v)))
-			items.sort(cmp = suggest_cmp)
-			txt.suggest(items, '')
+	# Immediate 'import' before cursor and after 'from...'
+	for i in range(pos2+7, c):
+		if line[i]==',' or (line[i]==' ' and line[i-1]==','):
+			pass
+		elif not line[i].isalnum() and line[i] != '_':
+			return
+	between = line[pos:pos2-1].strip()
+	try:
+		mod = get_module(between)
+	except ImportError:
+		return
+	
+	items = [('*', 'k')]
+	for (k,v) in mod.__dict__.items():
+		items.append((k, type_char(v)))
+	items.sort(cmp = suggest_cmp)
+	txt.suggest(items, '')
 
 # Check we are running as a script and not imported as a module
 if __name__ == "__main__" and OK:

Modified: branches/soc-2008-quorn/release/scripts/textplugin_membersuggest.py
===================================================================
--- branches/soc-2008-quorn/release/scripts/textplugin_membersuggest.py	2008-08-10 14:24:14 UTC (rev 16047)
+++ branches/soc-2008-quorn/release/scripts/textplugin_membersuggest.py	2008-08-10 16:07:14 UTC (rev 16048)
@@ -1,6 +1,6 @@
 #!BPY
 """
-Name: 'Member Suggest'
+Name: 'Member Suggest | .'
 Blender: 246
 Group: 'TextPlugin'
 Shortcut: 'Period'

Modified: branches/soc-2008-quorn/release/scripts/textplugin_outliner.py
===================================================================
--- branches/soc-2008-quorn/release/scripts/textplugin_outliner.py	2008-08-10 14:24:14 UTC (rev 16047)
+++ branches/soc-2008-quorn/release/scripts/textplugin_outliner.py	2008-08-10 16:07:14 UTC (rev 16048)
@@ -1,6 +1,6 @@
 #!BPY
 """
-Name: 'Outline'
+Name: 'Code Outline | Ctrl T'
 Blender: 246
 Group: 'TextPlugin'
 Shortcut: 'Ctrl+T'
@@ -99,7 +99,7 @@
 	vars_menu_length = len(tmp)
 	items.extend(tmp)
 	
-	menu = [('Outliner%t', 0),
+	menu = [('Script %t', 0),
 			('Classes', class_menu),
 			('Functions', defs_menu),
 			('Variables', vars_menu)]

Modified: branches/soc-2008-quorn/release/scripts/textplugin_suggest.py
===================================================================
--- branches/soc-2008-quorn/release/scripts/textplugin_suggest.py	2008-08-10 14:24:14 UTC (rev 16047)
+++ branches/soc-2008-quorn/release/scripts/textplugin_suggest.py	2008-08-10 16:07:14 UTC (rev 16048)
@@ -1,6 +1,6 @@
 #!BPY
 """
-Name: 'Suggest All'
+Name: 'Suggest All | Ctrl Space'
 Blender: 246
 Group: 'TextPlugin'
 Shortcut: 'Ctrl+Space'
@@ -21,14 +21,22 @@
 	if pos == -1:
 		return False
 	for s in line[pos+1:c]:
-		if not s.isalnum() and not s == '_':
+		if not s.isalnum() and s != '_':
 			return False
 	return True
 
 def check_imports(line, c):
-	if c >= 7 and line.rfind('import ', 0, c) == c-7:
+	pos = line.rfind('import ', 0, c)
+	if pos > -1:
+		for s in line[pos+7:c]:
+			if not s.isalnum() and s != '_':
+				return False
 		return True
-	if c >= 5 and line.rfind('from ', 0, c) == c-5:
+	pos = line.rfind('from ', 0, c)
+	if pos > -1:
+		for s in line[pos+5:c]:
+			if not s.isalnum() and s != '_':
+				return False
 		return True
 	return False
 

Modified: branches/soc-2008-quorn/release/scripts/textplugin_templates.py
===================================================================
--- branches/soc-2008-quorn/release/scripts/textplugin_templates.py	2008-08-10 14:24:14 UTC (rev 16047)
+++ branches/soc-2008-quorn/release/scripts/textplugin_templates.py	2008-08-10 16:07:14 UTC (rev 16048)
@@ -1,6 +1,6 @@
 #!BPY
 """
-Name: 'Templates'
+Name: 'Template Completion | Tab'
 Blender: 246
 Group: 'TextPlugin'
 Shortcut: 'Tab'

Modified: branches/soc-2008-quorn/source/blender/src/drawtext.c
===================================================================
--- branches/soc-2008-quorn/source/blender/src/drawtext.c	2008-08-10 14:24:14 UTC (rev 16047)
+++ branches/soc-2008-quorn/source/blender/src/drawtext.c	2008-08-10 16:07:14 UTC (rev 16048)
@@ -2267,7 +2267,7 @@
 		}
 		if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
 
-	} else if (val==1) {
+	} else if (val==1 && evnt) {
 		switch (evnt) {
 			case LEFTMOUSE:
 				if (do_suggest_select(st))





More information about the Bf-blender-cvs mailing list