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:
authorCampbell Barton <ideasman42@gmail.com>2010-10-03 02:31:48 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-10-03 02:31:48 +0400
commit27c444acb6585d31bc026eb46b1fef0fb9c55d5f (patch)
treeff6ee87c37f98b088060f25b659228783d5e06ed /source/blender/editors/space_console
parent491aebbf671d14f760da6ca87b8594420c932009 (diff)
python console prompt + edit line is how selectable.
Diffstat (limited to 'source/blender/editors/space_console')
-rw-r--r--source/blender/editors/space_console/console_draw.c37
-rw-r--r--source/blender/editors/space_console/console_ops.c31
2 files changed, 46 insertions, 22 deletions
diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c
index e12ccd03d04..d1fa4e17e6f 100644
--- a/source/blender/editors/space_console/console_draw.c
+++ b/source/blender/editors/space_console/console_draw.c
@@ -45,6 +45,8 @@
#include "BKE_report.h"
#include "BKE_utildefines.h"
+#include "MEM_guardedalloc.h"
+
#include "BIF_gl.h"
#include "BIF_glutil.h"
@@ -329,7 +331,8 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
cdc.draw= draw;
if(sc->type==CONSOLE_TYPE_PYTHON) {
- int prompt_len;
+ ConsoleLine cl_dummy= {0};
+ int prompt_len= strlen(sc->prompt);
if(sc->sel_start != sc->sel_end) {
sel[0]= sc->sel_start;
@@ -338,28 +341,24 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
/* text */
if(draw) {
- prompt_len= strlen(sc->prompt);
- console_line_color(fg, CONSOLE_LINE_INPUT);
- glColor3ubv(fg);
-
- /* command line */
- if(prompt_len) {
- BLF_position(mono, xy[0], xy[1], 0); xy[0] += cwidth * prompt_len;
- BLF_draw(mono, sc->prompt);
- }
- BLF_position(mono, xy[0], xy[1], 0);
- BLF_draw(mono, cl->line);
-
/* cursor */
UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, (char *)fg);
glColor3ubv(fg);
- glRecti(xy[0]+(cwidth*cl->cursor) -1, xy[1]-2, xy[0]+(cwidth*cl->cursor) +1, xy[1]+sc->lheight-2);
+ glRecti(xy[0]+(cwidth*(cl->cursor+prompt_len)) -1, xy[1]-2, xy[0]+(cwidth*(cl->cursor+prompt_len)) +1, xy[1]+sc->lheight-2);
xy[0]= x_orig; /* remove prompt offset */
}
-
- xy[1] += sc->lheight;
-
+
+ /* fake the edit line being in the scroll buffer */
+ cl_dummy.type= CONSOLE_LINE_INPUT;
+ cl_dummy.len= cl_dummy.len_alloc= prompt_len + cl->len;
+ cl_dummy.len_alloc= cl_dummy.len + 1;
+ cl_dummy.line= MEM_mallocN(cl_dummy.len_alloc, "cl_dummy");
+ memcpy(cl_dummy.line, sc->prompt, (cl_dummy.len_alloc - cl->len));
+ memcpy(cl_dummy.line + ((cl_dummy.len_alloc - cl->len)) - 1, cl->line, cl->len + 1);
+ BLI_addtail(&sc->scrollback, &cl_dummy);
+
+
for(cl= sc->scrollback.last; cl; cl= cl->prev) {
y_prev= xy[1];
@@ -378,6 +377,10 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
break;
}
}
+
+ /* temp line end */
+ MEM_freeN(cl_dummy.line);
+ BLI_remlink(&sc->scrollback, &cl_dummy);
}
else {
Report *report;
diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c
index ec3c600beab..a49581cb417 100644
--- a/source/blender/editors/space_console/console_ops.c
+++ b/source/blender/editors/space_console/console_ops.c
@@ -52,6 +52,12 @@
#include "console_intern.h"
+static void console_select_offset(SpaceConsole *sc, const int offset)
+{
+ sc->sel_start += offset;
+ sc->sel_end += offset;
+}
+
void console_history_free(SpaceConsole *sc, ConsoleLine *cl)
{
BLI_remlink(&sc->history, cl);
@@ -207,8 +213,7 @@ ConsoleLine *console_scrollback_add_str(const bContext *C, char *str, int own)
{
SpaceConsole *sc= CTX_wm_space_console(C);
ConsoleLine *ci= console_lb_add_str__internal(&sc->scrollback, C, str, own);
- sc->sel_start += ci->len + 1;
- sc->sel_end += ci->len + 1;
+ console_select_offset(sc, ci->len + 1);
return ci;
}
@@ -383,8 +388,13 @@ static int insert_exec(bContext *C, wmOperator *op)
MEM_freeN(str);
- if(len==0)
+ if(len==0) {
return OPERATOR_CANCELLED;
+ }
+ else {
+ SpaceConsole *sc= CTX_wm_space_console(C);
+ console_select_offset(sc, len);
+ }
ED_area_tag_redraw(CTX_wm_area(C));
@@ -456,8 +466,13 @@ static int delete_exec(bContext *C, wmOperator *op)
break;
}
- if(!done)
+ if(!done) {
return OPERATOR_CANCELLED;
+ }
+ else {
+ SpaceConsole *sc= CTX_wm_space_console(C);
+ console_select_offset(sc, -1);
+ }
ED_area_tag_redraw(CTX_wm_area(C));
@@ -529,8 +544,8 @@ static int history_cycle_exec(bContext *C, wmOperator *op)
{
SpaceConsole *sc= CTX_wm_space_console(C);
ConsoleLine *ci= console_history_verify(C); /* TODO - stupid, just prevernts crashes when no command line */
-
short reverse= RNA_boolean_get(op->ptr, "reverse"); /* assumes down, reverse is up */
+ int prev_len= ci->len;
/* keep a copy of the line above so when history is cycled
* this is the only function that needs to know about the double-up */
@@ -559,6 +574,9 @@ static int history_cycle_exec(bContext *C, wmOperator *op)
console_history_add(C, (ConsoleLine *)sc->history.last);
}
+
+ ci= sc->history.last;
+ console_select_offset(sc, ci->len - prev_len);
ED_area_tag_redraw(CTX_wm_area(C));
@@ -584,10 +602,12 @@ void CONSOLE_OT_history_cycle(wmOperatorType *ot)
/* the python exec operator uses this */
static int history_append_exec(bContext *C, wmOperator *op)
{
+ SpaceConsole *sc= CTX_wm_space_console(C);
ConsoleLine *ci= console_history_verify(C);
char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, dont free */
int cursor= RNA_int_get(op->ptr, "current_character");
short rem_dupes= RNA_boolean_get(op->ptr, "remove_duplicates");
+ int prev_len= ci->len;
if(rem_dupes) {
SpaceConsole *sc= CTX_wm_space_console(C);
@@ -603,6 +623,7 @@ static int history_append_exec(bContext *C, wmOperator *op)
}
ci= console_history_add_str(C, str, 1); /* own the string */
+ console_select_offset(sc, ci->len - prev_len);
console_line_cursor_set(ci, cursor);
ED_area_tag_redraw(CTX_wm_area(C));