forked from bartvdbraak/blender
text autocomplete
- make the popup box line up the X axis with the current word. - add poll function for the operator
This commit is contained in:
parent
f54b6eee45
commit
dd62a2c375
@ -106,6 +106,7 @@ int text_check_delim(const char ch);
|
|||||||
int text_check_digit(const char ch);
|
int text_check_digit(const char ch);
|
||||||
int text_check_identifier(const char ch);
|
int text_check_identifier(const char ch);
|
||||||
int text_check_whitespace(const char ch);
|
int text_check_whitespace(const char ch);
|
||||||
|
int text_find_identifier_start(const char *str, int i);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TXT_MOVE_LINE_UP = -1,
|
TXT_MOVE_LINE_UP = -1,
|
||||||
|
@ -2936,3 +2936,14 @@ int text_check_whitespace(const char ch)
|
|||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int text_find_identifier_start(const char *str, int i)
|
||||||
|
{
|
||||||
|
while (i--) {
|
||||||
|
if (!text_check_identifier(str[i])) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
@ -147,13 +147,7 @@ static GHash *text_autocomplete_build(Text *text)
|
|||||||
|
|
||||||
/* first get the word we're at */
|
/* first get the word we're at */
|
||||||
{
|
{
|
||||||
int i = text->curc;
|
const int i = text_find_identifier_start(text->curl->line, text->curc);
|
||||||
while (i--) {
|
|
||||||
if (!text_check_identifier(text->curl->line[i])) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
seek_len = text->curc - i;
|
seek_len = text->curc - i;
|
||||||
seek = text->curl->line + i;
|
seek = text->curl->line + i;
|
||||||
|
|
||||||
@ -550,7 +544,7 @@ void TEXT_OT_autocomplete(wmOperatorType *ot)
|
|||||||
ot->invoke = text_autocomplete_invoke;
|
ot->invoke = text_autocomplete_invoke;
|
||||||
ot->cancel = text_autocomplete_cancel;
|
ot->cancel = text_autocomplete_cancel;
|
||||||
ot->modal = text_autocomplete_modal;
|
ot->modal = text_autocomplete_modal;
|
||||||
//ot->poll = ED_operator_view3d_active;
|
ot->poll = text_space_edit_poll;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_BLOCKING;
|
ot->flag = OPTYPE_BLOCKING;
|
||||||
|
@ -958,8 +958,10 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
|
|||||||
TextLine *tmp;
|
TextLine *tmp;
|
||||||
char str[SUGG_LIST_WIDTH + 1];
|
char str[SUGG_LIST_WIDTH + 1];
|
||||||
int w, boxw = 0, boxh, i, l, x, y, b, *top;
|
int w, boxw = 0, boxh, i, l, x, y, b, *top;
|
||||||
|
const int lheight = st->lheight_dpi + TXT_LINE_SPACING;
|
||||||
|
const int margin_x = 2;
|
||||||
|
|
||||||
if (!st || !st->text) return;
|
if (!st->text) return;
|
||||||
if (!texttool_text_is_active(st->text)) return;
|
if (!texttool_text_is_active(st->text)) return;
|
||||||
|
|
||||||
first = texttool_suggest_first();
|
first = texttool_suggest_first();
|
||||||
@ -981,14 +983,20 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
|
|||||||
else {
|
else {
|
||||||
x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET - 4;
|
x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET - 4;
|
||||||
}
|
}
|
||||||
y = ar->winy - (st->lheight_dpi + TXT_LINE_SPACING) * l - 2;
|
/* offset back so the start of the text lines up with the suggestions,
|
||||||
|
* not essential but makes suggestions easier to follow */
|
||||||
|
x -= st->cwidth * (st->text->curc - text_find_identifier_start(st->text->curl->line, st->text->curc));
|
||||||
|
y = ar->winy - lheight * l - 2;
|
||||||
|
|
||||||
boxw = SUGG_LIST_WIDTH * st->cwidth + 20;
|
boxw = SUGG_LIST_WIDTH * st->cwidth + 20;
|
||||||
boxh = SUGG_LIST_SIZE * st->lheight_dpi + 8;
|
boxh = SUGG_LIST_SIZE * lheight + 8;
|
||||||
|
|
||||||
|
/* not needed but stands out nicer */
|
||||||
|
uiDrawBoxShadow(220, x, y - boxh, x + boxw, y);
|
||||||
|
|
||||||
UI_ThemeColor(TH_SHADE1);
|
UI_ThemeColor(TH_SHADE1);
|
||||||
glRecti(x - 1, y + 1, x + boxw + 1, y - boxh - 1);
|
glRecti(x - 1, y + 1, x + boxw + 1, y - boxh - 1);
|
||||||
UI_ThemeColor(TH_BACK);
|
UI_ThemeColorShade(TH_BACK, 16);
|
||||||
glRecti(x, y, x + boxw, y - boxh);
|
glRecti(x, y, x + boxw, y - boxh);
|
||||||
|
|
||||||
/* Set the top 'item' of the visible list */
|
/* Set the top 'item' of the visible list */
|
||||||
@ -996,7 +1004,7 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
|
|||||||
|
|
||||||
for (i = 0; i < SUGG_LIST_SIZE && item; i++, item = item->next) {
|
for (i = 0; i < SUGG_LIST_SIZE && item; i++, item = item->next) {
|
||||||
|
|
||||||
y -= st->lheight_dpi;
|
y -= lheight;
|
||||||
|
|
||||||
BLI_strncpy(str, item->name, SUGG_LIST_WIDTH);
|
BLI_strncpy(str, item->name, SUGG_LIST_WIDTH);
|
||||||
|
|
||||||
@ -1004,7 +1012,7 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
|
|||||||
|
|
||||||
if (item == sel) {
|
if (item == sel) {
|
||||||
UI_ThemeColor(TH_SHADE2);
|
UI_ThemeColor(TH_SHADE2);
|
||||||
glRecti(x + 16, y - 3, x + 16 + w, y + st->lheight_dpi - 3);
|
glRecti(x + margin_x, y - 3, x + margin_x + w, y + lheight - 3);
|
||||||
}
|
}
|
||||||
b = 1; /* b=1 color block, text is default. b=0 no block, color text */
|
b = 1; /* b=1 color block, text is default. b=0 no block, color text */
|
||||||
switch (item->type) {
|
switch (item->type) {
|
||||||
@ -1018,7 +1026,7 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
|
|||||||
glRecti(x + 8, y + 2, x + 11, y + 5);
|
glRecti(x + 8, y + 2, x + 11, y + 5);
|
||||||
UI_ThemeColor(TH_TEXT);
|
UI_ThemeColor(TH_TEXT);
|
||||||
}
|
}
|
||||||
text_draw(st, str, 0, 0, 1, x + 16, y - 1, NULL);
|
text_draw(st, str, 0, 0, 1, x + margin_x, y - 1, NULL);
|
||||||
|
|
||||||
if (item == last) break;
|
if (item == last) break;
|
||||||
}
|
}
|
||||||
@ -1031,7 +1039,7 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
|
|||||||
Text *text = st->text;
|
Text *text = st->text;
|
||||||
int vcurl, vcurc, vsell, vselc, hidden = 0;
|
int vcurl, vcurc, vsell, vselc, hidden = 0;
|
||||||
int x, y, w, i;
|
int x, y, w, i;
|
||||||
int lheight = st->lheight_dpi + TXT_LINE_SPACING;
|
const int lheight = st->lheight_dpi + TXT_LINE_SPACING;
|
||||||
|
|
||||||
/* Draw the selection */
|
/* Draw the selection */
|
||||||
if (text->curl != text->sell || text->curc != text->selc) {
|
if (text->curl != text->sell || text->curc != text->selc) {
|
||||||
|
@ -143,6 +143,9 @@ void TEXT_OT_to_3d_object(struct wmOperatorType *ot);
|
|||||||
|
|
||||||
void TEXT_OT_resolve_conflict(struct wmOperatorType *ot);
|
void TEXT_OT_resolve_conflict(struct wmOperatorType *ot);
|
||||||
|
|
||||||
|
int text_space_edit_poll(struct bContext *C);
|
||||||
|
|
||||||
|
/* text_autocomplete.c */
|
||||||
void TEXT_OT_autocomplete(struct wmOperatorType *ot);
|
void TEXT_OT_autocomplete(struct wmOperatorType *ot);
|
||||||
|
|
||||||
/* space_text.c */
|
/* space_text.c */
|
||||||
|
@ -98,7 +98,7 @@ static int text_edit_poll(bContext *C)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int text_space_edit_poll(bContext *C)
|
int text_space_edit_poll(bContext *C)
|
||||||
{
|
{
|
||||||
SpaceText *st = CTX_wm_space_text(C);
|
SpaceText *st = CTX_wm_space_text(C);
|
||||||
Text *text = CTX_data_edit_text(C);
|
Text *text = CTX_data_edit_text(C);
|
||||||
|
Loading…
Reference in New Issue
Block a user