[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15588] branches/soc-2008-quorn: Made suggestions case-insensitive which also puts _ prefixed items at the bottom .

Ian Thompson quornian at googlemail.com
Tue Jul 15 19:04:07 CEST 2008


Revision: 15588
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15588
Author:   quorn
Date:     2008-07-15 19:03:59 +0200 (Tue, 15 Jul 2008)

Log Message:
-----------
Made suggestions case-insensitive which also puts _ prefixed items at the bottom. Improvements have also been made to the way the list works, when it should disappear/update/confirm, etc.

Modified Paths:
--------------
    branches/soc-2008-quorn/release/scripts/bpymodules/BPyTextPlugin.py
    branches/soc-2008-quorn/source/blender/blenkernel/intern/suggestions.c
    branches/soc-2008-quorn/source/blender/src/drawtext.c

Modified: branches/soc-2008-quorn/release/scripts/bpymodules/BPyTextPlugin.py
===================================================================
--- branches/soc-2008-quorn/release/scripts/bpymodules/BPyTextPlugin.py	2008-07-15 16:57:21 UTC (rev 15587)
+++ branches/soc-2008-quorn/release/scripts/bpymodules/BPyTextPlugin.py	2008-07-15 17:03:59 UTC (rev 15588)
@@ -26,7 +26,7 @@
 	"""Use this method when sorting a list of suggestions.
 	"""
 	
-	return cmp(x[0], y[0])
+	return cmp(x[0].upper(), y[0].upper())
 
 def cached_generate_tokens(txt, since=1):
 	"""A caching version of generate tokens for multiple parsing of the same

Modified: branches/soc-2008-quorn/source/blender/blenkernel/intern/suggestions.c
===================================================================
--- branches/soc-2008-quorn/source/blender/blenkernel/intern/suggestions.c	2008-07-15 16:57:21 UTC (rev 15587)
+++ branches/soc-2008-quorn/source/blender/blenkernel/intern/suggestions.c	2008-07-15 17:03:59 UTC (rev 15588)
@@ -22,13 +22,14 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): Ian Thompson.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "MEM_guardedalloc.h"
 #include "BLI_blenlib.h"
@@ -36,9 +37,19 @@
 #include "BKE_text.h"
 #include "BKE_suggestions.h"
 
-static SuggList suggestions= {NULL, NULL, NULL, NULL};
+static SuggList suggestions= {NULL, NULL, NULL, NULL, NULL};
 static Text *suggText = NULL;
+static SuggItem *lastInsert= NULL;
 
+static suggest_cmp(const char *first, const char *second, int len) {	
+	int cmp, i;
+	for (cmp=0, i=0; i<len; i++) {
+		if (cmp= toupper(first[i]) - toupper(second[i])) {
+			break;
+		}
+	}
+	return cmp;
+}
 void free_suggestions() {
 	SuggItem *item, *prev;
 	for (item = suggestions.last; item; item=prev) {
@@ -66,17 +77,17 @@
 
 	if (!suggestions.first) {
 		suggestions.first = suggestions.last = newitem;
-		suggestions.selected = newitem;
 	} else {
 		newitem->prev = suggestions.last;
 		suggestions.last->next = newitem;
 		suggestions.last = newitem;
 	}
+	suggestions.selected = NULL;
 }
 
 void suggest_prefix(const char *prefix) {
 	SuggItem *match, *first, *last;
-	int cmp, len = strlen(prefix);
+	int cmp, len = strlen(prefix), i;
 
 	if (!suggestions.first) return;
 	if (len==0) {
@@ -87,7 +98,7 @@
 	
 	first = last = NULL;
 	for (match=suggestions.first; match; match=match->next) {
-		cmp = strncmp(prefix, match->name, len);
+		cmp = suggest_cmp(prefix, match->name, len);
 		if (cmp==0) {
 			if (!first)
 				first = match;
@@ -103,7 +114,7 @@
 		suggestions.selected = suggestions.firstmatch = first;
 		suggestions.lastmatch = last;
 	} else {
-		suggestions.selected = suggestions.firstmatch = suggestions.lastmatch = NULL;
+		suggestions.firstmatch = suggestions.lastmatch = NULL;
 	}
 }
 

Modified: branches/soc-2008-quorn/source/blender/src/drawtext.c
===================================================================
--- branches/soc-2008-quorn/source/blender/src/drawtext.c	2008-07-15 16:57:21 UTC (rev 15587)
+++ branches/soc-2008-quorn/source/blender/src/drawtext.c	2008-07-15 17:03:59 UTC (rev 15588)
@@ -108,7 +108,7 @@
 static int check_identifier(char ch);
 
 static void get_suggest_prefix(Text *text);
-static void confirm_suggestion(Text *text);
+static void confirm_suggestion(Text *text, int skipleft);
 
 static void *last_txt_find_string= NULL;
 static double last_check_time= 0;
@@ -1026,7 +1026,7 @@
 	last = suggest_last();
 	sel = suggest_get_selected();
 
-	if (!sel || !last || !first)
+	if (!last || !first)
 		return 0;
 
 	/* Count the visible lines to the cursor */
@@ -1100,7 +1100,10 @@
 	BIF_ThemeColor(TH_BACK);
 	glRecti(x, y, x+boxw, y-boxh);
 
+	/* Set the top 'item' of the visible list */
 	for (i=0, item=sel; i<3 && item && item!=first; i++, item=item->prev);
+	if (!item)
+		item = first;
 
 	for (i=0; i<SUGG_LIST_SIZE && item; i++, item=item->next) {
 
@@ -1653,15 +1656,15 @@
 	len= text->curc-i;
 	if (len > 255) {
 		printf("Suggestion prefix too long\n");
-		return;
+		len = 255;
 	}
 	strncpy(tmp, line+i, len);
 	tmp[len]= '\0';
 	suggest_prefix(tmp);
 }
 
-static void confirm_suggestion(Text *text) {
-	int i, len;
+static void confirm_suggestion(Text *text, int skipleft) {
+	int i, over=0;
 	char *line;
 	SuggItem *sel;
 
@@ -1672,12 +1675,25 @@
 	if (!sel) return;
 
 	line= text->curl->line;
-	for (i=text->curc-1; i>=0; i--)
+	i=text->curc-skipleft-1;
+	while (i>=0) {
 		if (!check_identifier(line[i]))
 			break;
-	i++;
-	len= text->curc-i;
-	txt_insert_buf(text, sel->name+len);
+		over++;
+		i--;
+	}
+
+	for (i=0; i<skipleft; i++)
+		txt_move_left(text, 0);
+	for (i=0; i<over; i++)
+		txt_move_left(text, 1);
+
+	txt_insert_buf(text, sel->name);
+	
+	for (i=0; i<skipleft; i++)
+		txt_move_right(text, 0);
+
+	suggest_clear_text();
 }
 
 void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
@@ -1752,7 +1768,7 @@
 		return;
 	}
 
-	suggesting = suggest_is_active(text);
+	suggesting = st->showsyntax && suggest_is_active(text);
 	
 	if (event==LEFTMOUSE) {
 		if (val) {
@@ -1781,7 +1797,7 @@
 	} else if (event==MIDDLEMOUSE) {
 		if (val) {
 			if (do_suggest_select(st)) {
-				confirm_suggestion(text);
+				confirm_suggestion(text, 0);
 				do_draw= 1;
 				do_suggest= 0;
 			} else if (U.uiflag & USER_MMB_PASTE) {
@@ -1834,12 +1850,14 @@
 			if (st->showsyntax) get_format_string(st);
 			pop_space_text(st);
 			do_draw= 1;
-			if (suggesting && ispunct(ascii)) {
-				confirm_suggestion(text);
-				if (st->showsyntax) get_format_string(st);
-				do_suggest= 0;
-			} else {
-				do_suggest= 1;
+			if (suggesting) {
+				if (ispunct(ascii) || check_whitespace(ascii)) {
+					confirm_suggestion(text, 1);
+					if (st->showsyntax) get_format_string(st);
+					do_suggest= 0;
+				} else {
+					do_suggest= 1;
+				}
 			}
 		}
 	} else if (val) {
@@ -2110,12 +2128,6 @@
 		case ESCKEY:
 			do_suggest= -1;
 			break;
-		case SPACEKEY:
-			if (suggesting) {
-				confirm_suggestion(text);
-				if (st->showsyntax) get_format_string(st);
-			}
-			break;
 		case TABKEY:
 			if (text && text->id.lib) {
 				error_libdata();
@@ -2146,7 +2158,7 @@
 				break;
 			}
 			if (suggesting) {
-				confirm_suggestion(text);
+				confirm_suggestion(text, 0);
 				if (st->showsyntax) get_format_string(st);
 				break;
 			}
@@ -2174,14 +2186,24 @@
 			}
 			if (G.qual & (LR_ALTKEY | LR_CTRLKEY)) {
 				txt_backspace_word(text);
+				do_suggest= -1;
 			} else {
+				/* Work out which char we are about to delete */
+				if (text && text->curl && text->curc > 0) {
+					char ch= text->curl->line[text->curc-1];
+					if (ispunct(ch) || check_whitespace(ch))
+						do_suggest= -1;
+					else
+						do_suggest= 1;
+				} else {
+					do_suggest= -1;
+				}
 				txt_backspace_char(text);
 			}
 			set_tabs(text);
 			if (st->showsyntax) get_format_string(st);
 			do_draw= 1;
 			pop_space_text(st);
-			do_suggest= 1;
 			break;
 		case DELKEY:
 			if (text && text->id.lib) {
@@ -2206,8 +2228,11 @@
 		case DOWNARROWKEY:
 			if (suggesting) {
 				SuggItem *sel = suggest_get_selected();
-				if (sel && sel!=suggest_last() && sel->next)
+				if (!sel) {
+					suggest_set_selected(suggest_first());
+				} else if (sel!=suggest_last() && sel->next) {
 					suggest_set_selected(sel->next);
+				}
 				do_suggest= 0;
 				break;
 			}
@@ -2255,6 +2280,8 @@
 			if (suggesting) {
 				int i;
 				SuggItem *sel = suggest_get_selected();
+				if (!sel)
+					sel = suggest_first();
 				for (i=0; i<SUGG_LIST_SIZE-1 && sel && sel!=suggest_last() && sel->next; i++, sel=sel->next)
 					suggest_set_selected(sel->next);
 				do_suggest= 0;
@@ -2301,8 +2328,11 @@
 		case WHEELDOWNMOUSE:
 			if (suggesting) {
 				SuggItem *sel = suggest_get_selected();
-				if (sel && sel!=suggest_last() && sel->next)
+				if (!sel) {
+					suggest_set_selected(suggest_first());
+				} else if (sel && sel!=suggest_last() && sel->next) {
 					suggest_set_selected(sel->next);
+				}
 				do_suggest= 0;
 			} else {
 				screen_skip(st, U.wheellinescroll);
@@ -2310,6 +2340,7 @@
 			do_draw= 1;
 			break;
 		default:
+			/* We don't want all sorts of events closing the suggestions box */
 			do_suggest= 0;
 		}
 	}
@@ -2581,6 +2612,12 @@
 	return 0;
 }
 
+static int check_whitespace(char ch) {
+	if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n')
+		return 1;
+	return 0;
+}
+
 void convert_tabs (struct SpaceText *st, int tab)
 {
 	Text *text = st->text;





More information about the Bf-blender-cvs mailing list