forked from bartvdbraak/blender
python console prompt + edit line is how selectable.
This commit is contained in:
parent
491aebbf67
commit
27c444acb6
@ -45,6 +45,8 @@
|
|||||||
#include "BKE_report.h"
|
#include "BKE_report.h"
|
||||||
#include "BKE_utildefines.h"
|
#include "BKE_utildefines.h"
|
||||||
|
|
||||||
|
#include "MEM_guardedalloc.h"
|
||||||
|
|
||||||
#include "BIF_gl.h"
|
#include "BIF_gl.h"
|
||||||
#include "BIF_glutil.h"
|
#include "BIF_glutil.h"
|
||||||
|
|
||||||
@ -329,7 +331,8 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
|
|||||||
cdc.draw= draw;
|
cdc.draw= draw;
|
||||||
|
|
||||||
if(sc->type==CONSOLE_TYPE_PYTHON) {
|
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) {
|
if(sc->sel_start != sc->sel_end) {
|
||||||
sel[0]= sc->sel_start;
|
sel[0]= sc->sel_start;
|
||||||
@ -338,28 +341,24 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
|
|||||||
|
|
||||||
/* text */
|
/* text */
|
||||||
if(draw) {
|
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 */
|
/* cursor */
|
||||||
UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, (char *)fg);
|
UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, (char *)fg);
|
||||||
glColor3ubv(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[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) {
|
for(cl= sc->scrollback.last; cl; cl= cl->prev) {
|
||||||
y_prev= xy[1];
|
y_prev= xy[1];
|
||||||
|
|
||||||
@ -378,6 +377,10 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* temp line end */
|
||||||
|
MEM_freeN(cl_dummy.line);
|
||||||
|
BLI_remlink(&sc->scrollback, &cl_dummy);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Report *report;
|
Report *report;
|
||||||
|
@ -52,6 +52,12 @@
|
|||||||
|
|
||||||
#include "console_intern.h"
|
#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)
|
void console_history_free(SpaceConsole *sc, ConsoleLine *cl)
|
||||||
{
|
{
|
||||||
BLI_remlink(&sc->history, 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);
|
SpaceConsole *sc= CTX_wm_space_console(C);
|
||||||
ConsoleLine *ci= console_lb_add_str__internal(&sc->scrollback, C, str, own);
|
ConsoleLine *ci= console_lb_add_str__internal(&sc->scrollback, C, str, own);
|
||||||
sc->sel_start += ci->len + 1;
|
console_select_offset(sc, ci->len + 1);
|
||||||
sc->sel_end += ci->len + 1;
|
|
||||||
return ci;
|
return ci;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,8 +388,13 @@ static int insert_exec(bContext *C, wmOperator *op)
|
|||||||
|
|
||||||
MEM_freeN(str);
|
MEM_freeN(str);
|
||||||
|
|
||||||
if(len==0)
|
if(len==0) {
|
||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SpaceConsole *sc= CTX_wm_space_console(C);
|
||||||
|
console_select_offset(sc, len);
|
||||||
|
}
|
||||||
|
|
||||||
ED_area_tag_redraw(CTX_wm_area(C));
|
ED_area_tag_redraw(CTX_wm_area(C));
|
||||||
|
|
||||||
@ -456,8 +466,13 @@ static int delete_exec(bContext *C, wmOperator *op)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!done)
|
if(!done) {
|
||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SpaceConsole *sc= CTX_wm_space_console(C);
|
||||||
|
console_select_offset(sc, -1);
|
||||||
|
}
|
||||||
|
|
||||||
ED_area_tag_redraw(CTX_wm_area(C));
|
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);
|
SpaceConsole *sc= CTX_wm_space_console(C);
|
||||||
ConsoleLine *ci= console_history_verify(C); /* TODO - stupid, just prevernts crashes when no command line */
|
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 */
|
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
|
/* 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 */
|
* 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);
|
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));
|
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 */
|
/* the python exec operator uses this */
|
||||||
static int history_append_exec(bContext *C, wmOperator *op)
|
static int history_append_exec(bContext *C, wmOperator *op)
|
||||||
{
|
{
|
||||||
|
SpaceConsole *sc= CTX_wm_space_console(C);
|
||||||
ConsoleLine *ci= console_history_verify(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 */
|
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");
|
int cursor= RNA_int_get(op->ptr, "current_character");
|
||||||
short rem_dupes= RNA_boolean_get(op->ptr, "remove_duplicates");
|
short rem_dupes= RNA_boolean_get(op->ptr, "remove_duplicates");
|
||||||
|
int prev_len= ci->len;
|
||||||
|
|
||||||
if(rem_dupes) {
|
if(rem_dupes) {
|
||||||
SpaceConsole *sc= CTX_wm_space_console(C);
|
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 */
|
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);
|
console_line_cursor_set(ci, cursor);
|
||||||
|
|
||||||
ED_area_tag_redraw(CTX_wm_area(C));
|
ED_area_tag_redraw(CTX_wm_area(C));
|
||||||
|
Loading…
Reference in New Issue
Block a user