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:
Diffstat (limited to 'source/blender/editors/space_console/console_ops.c')
-rw-r--r--source/blender/editors/space_console/console_ops.c237
1 files changed, 140 insertions, 97 deletions
diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c
index 9a53531ba73..05c3561d25e 100644
--- a/source/blender/editors/space_console/console_ops.c
+++ b/source/blender/editors/space_console/console_ops.c
@@ -17,11 +17,6 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
@@ -38,6 +33,7 @@
#include "BLI_blenlib.h"
#include "BLI_dynstr.h"
+#include "BLI_utildefines.h"
#include "BKE_context.h"
#include "BKE_text.h" /* only for character utility funcs */
@@ -45,6 +41,7 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "UI_view2d.h"
#include "ED_screen.h"
#include "RNA_access.h"
@@ -52,6 +49,19 @@
#include "console_intern.h"
+static void console_textview_update_rect(SpaceConsole *sc, ARegion *ar)
+{
+ View2D *v2d= &ar->v2d;
+
+ UI_view2d_totRect_set(v2d, ar->winx-1, console_textview_height(sc, ar));
+}
+
+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);
@@ -188,7 +198,7 @@ static ConsoleLine *console_scrollback_add(const bContext *C, ConsoleLine *from)
}
#endif
-static ConsoleLine *console_lb_add_str__internal(ListBase *lb, const bContext *C, char *str, int own)
+static ConsoleLine *console_lb_add_str__internal(ListBase *lb, char *str, int own)
{
ConsoleLine *ci= MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add");
if(own) ci->line= str;
@@ -199,13 +209,15 @@ static ConsoleLine *console_lb_add_str__internal(ListBase *lb, const bContext *C
BLI_addtail(lb, ci);
return ci;
}
-ConsoleLine *console_history_add_str(const bContext *C, char *str, int own)
+ConsoleLine *console_history_add_str(SpaceConsole *sc, char *str, int own)
{
- return console_lb_add_str__internal(&CTX_wm_space_console(C)->history, C, str, own);
+ return console_lb_add_str__internal(&sc->history, str, own);
}
-ConsoleLine *console_scrollback_add_str(const bContext *C, char *str, int own)
+ConsoleLine *console_scrollback_add_str(SpaceConsole *sc, char *str, int own)
{
- return console_lb_add_str__internal(&CTX_wm_space_console(C)->scrollback, C, str, own);
+ ConsoleLine *ci= console_lb_add_str__internal(&sc->scrollback, str, own);
+ console_select_offset(sc, ci->len + 1);
+ return ci;
}
ConsoleLine *console_history_verify(const bContext *C)
@@ -256,22 +268,6 @@ static int console_line_insert(ConsoleLine *ci, char *str)
return len;
}
-static int console_edit_poll(bContext *C)
-{
- SpaceConsole *sc= CTX_wm_space_console(C);
-
- if(!sc || sc->type != CONSOLE_TYPE_PYTHON)
- return 0;
-
- return 1;
-}
-#if 0
-static int console_poll(bContext *C)
-{
- return (CTX_wm_space_console(C) != NULL);
-}
-#endif
-
/* static funcs for text editing */
/* similar to the text editor, with some not used. keep compatible */
@@ -353,25 +349,42 @@ void CONSOLE_OT_move(wmOperatorType *ot)
/* api callbacks */
ot->exec= move_exec;
- ot->poll= console_edit_poll;
+ ot->poll= ED_operator_console_active;
/* properties */
RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to.");
}
-
+#define TAB_LENGTH 4
static int insert_exec(bContext *C, wmOperator *op)
{
+ SpaceConsole *sc= CTX_wm_space_console(C);
+ ARegion *ar= CTX_wm_region(C);
ConsoleLine *ci= console_history_verify(C);
char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0);
-
- int len= console_line_insert(ci, str);
+ int len;
+
+ // XXX, alligned tab key hack
+ if(str[0]=='\t' && str[1]=='\0') {
+ len= TAB_LENGTH - (ci->cursor % TAB_LENGTH);
+ MEM_freeN(str);
+ str= MEM_mallocN(len + 1, "insert_exec");
+ memset(str, ' ', len);
+ str[len]= '\0';
+ }
+
+ len= console_line_insert(ci, str);
MEM_freeN(str);
- if(len==0)
+ if(len==0) {
return OPERATOR_CANCELLED;
-
+ }
+ else {
+ console_select_offset(sc, len);
+ }
+
+ console_textview_update_rect(sc, ar);
ED_area_tag_redraw(CTX_wm_area(C));
return OPERATOR_FINISHED;
@@ -379,9 +392,19 @@ static int insert_exec(bContext *C, wmOperator *op)
static int insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
- if(!RNA_property_is_set(op->ptr, "text")) {
- char str[2] = {event->ascii, '\0'};
- RNA_string_set(op->ptr, "text", str);
+ // if(!RNA_property_is_set(op->ptr, "text")) { /* always set from keymap XXX */
+ if(!RNA_string_length(op->ptr, "text")) {
+ /* if alt/ctrl/super are pressed pass through */
+ if(event->ctrl || event->oskey) {
+ return OPERATOR_PASS_THROUGH;
+ }
+ else {
+ char str[2];
+ str[0]= event->ascii;
+ str[1]= '\0';
+
+ RNA_string_set(op->ptr, "text", str);
+ }
}
return insert_exec(C, op);
}
@@ -396,7 +419,7 @@ void CONSOLE_OT_insert(wmOperatorType *ot)
/* api callbacks */
ot->exec= insert_exec;
ot->invoke= insert_invoke;
- ot->poll= console_edit_poll;
+ ot->poll= ED_operator_console_active;
/* properties */
RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position.");
@@ -412,13 +435,12 @@ static EnumPropertyItem delete_type_items[]= {
static int delete_exec(bContext *C, wmOperator *op)
{
-
+ SpaceConsole *sc= CTX_wm_space_console(C);
+ ARegion *ar= CTX_wm_region(C);
ConsoleLine *ci= console_history_verify(C);
-
-
- int done = 0;
- int type= RNA_enum_get(op->ptr, "type");
+ const short type= RNA_enum_get(op->ptr, "type");
+ int done = 0;
if(ci->len==0) {
return OPERATOR_CANCELLED;
@@ -442,9 +464,14 @@ static int delete_exec(bContext *C, wmOperator *op)
break;
}
- if(!done)
+ if(!done) {
return OPERATOR_CANCELLED;
-
+ }
+ else {
+ console_select_offset(sc, -1);
+ }
+
+ console_textview_update_rect(sc, ar);
ED_area_tag_redraw(CTX_wm_area(C));
return OPERATOR_FINISHED;
@@ -460,7 +487,7 @@ void CONSOLE_OT_delete(wmOperatorType *ot)
/* api callbacks */
ot->exec= delete_exec;
- ot->poll= console_edit_poll;
+ ot->poll= ED_operator_console_active;
/* properties */
RNA_def_enum(ot->srna, "type", delete_type_items, DEL_NEXT_CHAR, "Type", "Which part of the text to delete.");
@@ -471,6 +498,7 @@ void CONSOLE_OT_delete(wmOperatorType *ot)
static int clear_exec(bContext *C, wmOperator *op)
{
SpaceConsole *sc= CTX_wm_space_console(C);
+ ARegion *ar= CTX_wm_region(C);
short scrollback= RNA_boolean_get(op->ptr, "scrollback");
short history= RNA_boolean_get(op->ptr, "history");
@@ -486,9 +514,10 @@ static int clear_exec(bContext *C, wmOperator *op)
while(sc->history.first)
console_history_free(sc, sc->history.first);
}
-
+
+ console_textview_update_rect(sc, ar);
ED_area_tag_redraw(CTX_wm_area(C));
-
+
return OPERATOR_FINISHED;
}
@@ -501,7 +530,7 @@ void CONSOLE_OT_clear(wmOperatorType *ot)
/* api callbacks */
ot->exec= clear_exec;
- ot->poll= console_edit_poll;
+ ot->poll= ED_operator_console_active;
/* properties */
RNA_def_boolean(ot->srna, "scrollback", 1, "Scrollback", "Clear the scrollback history");
@@ -514,9 +543,11 @@ void CONSOLE_OT_clear(wmOperatorType *ot)
static int history_cycle_exec(bContext *C, wmOperator *op)
{
SpaceConsole *sc= CTX_wm_space_console(C);
+ ARegion *ar= CTX_wm_region(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 */
@@ -545,7 +576,12 @@ 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);
+ /* could be wrapped so update scroll rect */
+ console_textview_update_rect(sc, ar);
ED_area_tag_redraw(CTX_wm_area(C));
return OPERATOR_FINISHED;
@@ -560,7 +596,7 @@ void CONSOLE_OT_history_cycle(wmOperatorType *ot)
/* api callbacks */
ot->exec= history_cycle_exec;
- ot->poll= console_edit_poll;
+ ot->poll= ED_operator_console_active;
/* properties */
RNA_def_boolean(ot->srna, "reverse", 0, "Reverse", "reverse cycle history");
@@ -570,13 +606,15 @@ 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);
+ ScrArea *sa= CTX_wm_area(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);
ConsoleLine *cl;
while((cl= console_history_find(sc, ci->line, ci)))
@@ -588,11 +626,12 @@ 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(sc, 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));
-
+
+ ED_area_tag_redraw(sa);
+
return OPERATOR_FINISHED;
}
@@ -605,7 +644,7 @@ void CONSOLE_OT_history_append(wmOperatorType *ot)
/* api callbacks */
ot->exec= history_append_exec;
- ot->poll= console_edit_poll;
+ ot->poll= ED_operator_console_active;
/* properties */
RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position.");
@@ -618,16 +657,20 @@ void CONSOLE_OT_history_append(wmOperatorType *ot)
static int scrollback_append_exec(bContext *C, wmOperator *op)
{
SpaceConsole *sc= CTX_wm_space_console(C);
- ConsoleLine *ci= console_history_verify(C);
+ ARegion *ar= CTX_wm_region(C);
+ ConsoleLine *ci;
char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, dont free */
int type= RNA_enum_get(op->ptr, "type");
+
+ console_history_verify(C);
- ci= console_scrollback_add_str(C, str, 1); /* own the string */
+ ci= console_scrollback_add_str(sc, str, 1); /* own the string */
ci->type= type;
console_scrollback_limit(sc);
-
+
+ console_textview_update_rect(sc, ar);
ED_area_tag_redraw(CTX_wm_area(C));
return OPERATOR_FINISHED;
@@ -650,7 +693,7 @@ void CONSOLE_OT_scrollback_append(wmOperatorType *ot)
/* api callbacks */
ot->exec= scrollback_append_exec;
- ot->poll= console_edit_poll;
+ ot->poll= ED_operator_console_active;
/* properties */
RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position.");
@@ -658,10 +701,9 @@ void CONSOLE_OT_scrollback_append(wmOperatorType *ot)
}
-static int copy_exec(bContext *C, wmOperator *op)
+static int copy_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceConsole *sc= CTX_wm_space_console(C);
- int buf_len;
DynStr *buf_dyn= BLI_dynstr_new();
char *buf_str;
@@ -670,6 +712,8 @@ static int copy_exec(bContext *C, wmOperator *op)
int sel[2];
int offset= 0;
+ ConsoleLine cl_dummy= {0};
+
#if 0
/* copy whole file */
for(cl= sc->scrollback.first; cl; cl= cl->next) {
@@ -681,43 +725,25 @@ static int copy_exec(bContext *C, wmOperator *op)
if(sc->sel_start == sc->sel_end)
return OPERATOR_CANCELLED;
+ console_scrollback_prompt_begin(sc, &cl_dummy);
for(cl= sc->scrollback.first; cl; cl= cl->next) {
offset += cl->len + 1;
}
- if(offset==0)
+ if(offset==0) {
+ console_scrollback_prompt_end(sc, &cl_dummy);
return OPERATOR_CANCELLED;
-
+ }
offset -= 1;
sel[0]= offset - sc->sel_end;
sel[1]= offset - sc->sel_start;
for(cl= sc->scrollback.first; cl; cl= cl->next) {
-
- int sta= MAX2(0, sel[0]);
- int end= MIN2(cl->len, sel[1]);
-
if(sel[0] <= cl->len && sel[1] >= 0) {
- int str_len= cl->len;
-
- /* highly confusing but draws correctly */
- if(sel[0] < 0 || sel[1] > str_len) {
- if(sel[0] > 0) {
- end= sta;
- sta= 0;
- }
- if (sel[1] <= str_len) {
- sta= end;
- end= str_len;
- }
- }
- /* end confusement */
-
- SWAP(int, sta, end);
- end= cl->len - end;
- sta= cl->len - sta;
+ int sta= MAX2(sel[0], 0);
+ int end= MIN2(sel[1], cl->len);
if(BLI_dynstr_get_len(buf_dyn))
BLI_dynstr_append(buf_dyn, "\n");
@@ -730,11 +756,14 @@ static int copy_exec(bContext *C, wmOperator *op)
}
buf_str= BLI_dynstr_get_cstring(buf_dyn);
- buf_len= BLI_dynstr_get_len(buf_dyn);
+
BLI_dynstr_free(buf_dyn);
WM_clipboard_text_set(buf_str, 0);
MEM_freeN(buf_str);
+
+ console_scrollback_prompt_end(sc, &cl_dummy);
+
return OPERATOR_FINISHED;
}
@@ -746,14 +775,16 @@ void CONSOLE_OT_copy(wmOperatorType *ot)
ot->idname= "CONSOLE_OT_copy";
/* api callbacks */
- ot->poll= console_edit_poll;
+ ot->poll= ED_operator_console_active;
ot->exec= copy_exec;
/* properties */
}
-static int paste_exec(bContext *C, wmOperator *op)
+static int paste_exec(bContext *C, wmOperator *UNUSED(op))
{
+ SpaceConsole *sc= CTX_wm_space_console(C);
+ ARegion *ar= CTX_wm_region(C);
ConsoleLine *ci= console_history_verify(C);
char *buf_str= WM_clipboard_text_get(0);
@@ -762,7 +793,6 @@ static int paste_exec(bContext *C, wmOperator *op)
if(buf_str==NULL)
return OPERATOR_CANCELLED;
- buf_next= buf_str;
buf_step= buf_str;
while((buf_next=buf_step) && buf_next[0] != '\0') {
@@ -777,11 +807,12 @@ static int paste_exec(bContext *C, wmOperator *op)
ci= console_history_verify(C);
}
- console_line_insert(ci, buf_next);
+ console_select_offset(sc, console_line_insert(ci, buf_next));
}
MEM_freeN(buf_str);
+ console_textview_update_rect(sc, ar);
ED_area_tag_redraw(CTX_wm_area(C));
return OPERATOR_FINISHED;
@@ -795,7 +826,7 @@ void CONSOLE_OT_paste(wmOperatorType *ot)
ot->idname= "CONSOLE_OT_paste";
/* api callbacks */
- ot->poll= console_edit_poll;
+ ot->poll= ED_operator_console_active;
ot->exec= paste_exec;
/* properties */
@@ -806,10 +837,11 @@ typedef struct SetConsoleCursor {
int sel_init;
} SetConsoleCursor;
-static void set_cursor_to_pos(SpaceConsole *sc, ARegion *ar, SetConsoleCursor *scu, int mval[2], int sel)
+// TODO, cursor placement without selection
+static void set_cursor_to_pos(SpaceConsole *sc, ARegion *ar, SetConsoleCursor *scu, int mval[2], int UNUSED(sel))
{
int pos;
- pos= console_char_pick(sc, ar, NULL, mval);
+ pos= console_char_pick(sc, ar, mval);
if(scu->sel_init == INT_MAX) {
scu->sel_init= pos;
@@ -835,13 +867,24 @@ static void console_modal_select_apply(bContext *C, wmOperator *op, wmEvent *eve
SpaceConsole *sc= CTX_wm_space_console(C);
ARegion *ar= CTX_wm_region(C);
SetConsoleCursor *scu= op->customdata;
- int mval[2] = {event->mval[0], event->mval[1]};
+ int mval[2];
+ int sel_prev[2];
+
+ mval[0]= event->mval[0];
+ mval[1]= event->mval[1];
+ sel_prev[0]= sc->sel_start;
+ sel_prev[1]= sc->sel_end;
+
set_cursor_to_pos(sc, ar, scu, mval, TRUE);
- ED_area_tag_redraw(CTX_wm_area(C));
+
+ /* only redraw if the selection changed */
+ if(sel_prev[0] != sc->sel_start || sel_prev[1] != sc->sel_end) {
+ ED_area_tag_redraw(CTX_wm_area(C));
+ }
}
-static void set_cursor_exit(bContext *C, wmOperator *op)
+static void set_cursor_exit(bContext *UNUSED(C), wmOperator *op)
{
// SpaceConsole *sc= CTX_wm_space_console(C);
SetConsoleCursor *scu= op->customdata;
@@ -910,5 +953,5 @@ void CONSOLE_OT_select_set(wmOperatorType *ot)
ot->invoke= console_modal_select_invoke;
ot->modal= console_modal_select;
ot->cancel= console_modal_select_cancel;
- ot->poll= console_edit_poll;
+ ot->poll= ED_operator_console_active;
}