Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Thompson <quornian@googlemail.com>2008-07-15 21:03:59 +0400
committerIan Thompson <quornian@googlemail.com>2008-07-15 21:03:59 +0400
commit512eec04aa239d49ea655151cdd34ba5d754c466 (patch)
tree8145bb631d55a08a9b81e97e51d571aa0ef39aa0 /source/blender
parent9037159d7a5d2e114174e77ca1e763c68de14b44 (diff)
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.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/intern/suggestions.c23
-rw-r--r--source/blender/src/drawtext.c91
2 files changed, 81 insertions, 33 deletions
diff --git a/source/blender/blenkernel/intern/suggestions.c b/source/blender/blenkernel/intern/suggestions.c
index ae0c7baa146..dd5b770db93 100644
--- a/source/blender/blenkernel/intern/suggestions.c
+++ b/source/blender/blenkernel/intern/suggestions.c
@@ -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 @@ void suggest_add(const char *name, char type) {
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 @@ void suggest_prefix(const char *prefix) {
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 @@ void suggest_prefix(const char *prefix) {
suggestions.selected = suggestions.firstmatch = first;
suggestions.lastmatch = last;
} else {
- suggestions.selected = suggestions.firstmatch = suggestions.lastmatch = NULL;
+ suggestions.firstmatch = suggestions.lastmatch = NULL;
}
}
diff --git a/source/blender/src/drawtext.c b/source/blender/src/drawtext.c
index b8cf99383a0..ae994b3e61d 100644
--- a/source/blender/src/drawtext.c
+++ b/source/blender/src/drawtext.c
@@ -108,7 +108,7 @@ static int check_specialvars(char *string);
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 @@ static int do_suggest_select(SpaceText *st)
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 @@ void draw_suggestion_list(SpaceText *st) {
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 @@ static void get_suggest_prefix(Text *text) {
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 @@ static void confirm_suggestion(Text *text) {
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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
return;
}
- suggesting = suggest_is_active(text);
+ suggesting = st->showsyntax && suggest_is_active(text);
if (event==LEFTMOUSE) {
if (val) {
@@ -1781,7 +1797,7 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
} 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
break;
}
if (suggesting) {
- confirm_suggestion(text);
+ confirm_suggestion(text, 0);
if (st->showsyntax) get_format_string(st);
break;
}
@@ -2174,14 +2186,24 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
}
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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
do_draw= 1;
break;
default:
+ /* We don't want all sorts of events closing the suggestions box */
do_suggest= 0;
}
}
@@ -2581,6 +2612,12 @@ static int check_identifier(char ch) {
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;