diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-07-12 16:47:34 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-07-12 16:47:34 +0400 |
commit | 78703a9ef8983ce513c1d428ba947dfbe1a58f97 (patch) | |
tree | d0215bade63f860be539885656b0f2e871fb588d /source | |
parent | 184dca5396ee0de4535523c66d19f896cfb7a939 (diff) |
python console in ~80 lines
Shift+Enter in the text editor executes the TEXT_OT_line_console operator defined in space_text.py
The operator's class stores a namespace for each text block.
Eventually this should have its own input rather then using the text editor.
Tested with py3.1 and 2.6
TEXT_OT_insert was only using the first char from a string, added support for inserting strings.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_text/space_text.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 24 |
2 files changed, 16 insertions, 12 deletions
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 8759fd00f74..5d3da461f71 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -285,6 +285,10 @@ static void text_keymap(struct wmWindowManager *wm) WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "TEXT_OT_line_break", RETKEY, KM_PRESS, 0, 0); +#ifndef DISABLE_PYTHON + WM_keymap_add_item(keymap, "TEXT_OT_line_console", RETKEY, KM_PRESS, KM_SHIFT, 0); /* python operator - space_text.py */ +#endif + WM_keymap_add_item(keymap, "TEXT_OT_line_number", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); WM_keymap_add_item(keymap, "TEXT_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last! } diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index f9485f17bdc..e6d97071ef5 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -248,8 +248,6 @@ static int reload_exec(bContext *C, wmOperator *op) #ifndef DISABLE_PYTHON if(text->compiled) BPY_free_compiled_text(text); - - text->compiled = NULL; #endif text_update_edited(text); @@ -2229,19 +2227,21 @@ static int insert_exec(bContext *C, wmOperator *op) SpaceText *st= CTX_wm_space_text(C); Text *text= CTX_data_edit_text(C); char *str; - int done, ascii; + int done = 0, i; str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); - ascii= str[0]; - MEM_freeN(str); - if(!ascii) - return OPERATOR_CANCELLED; + if(st && st->overwrite) { + for(i=0; str[i]; i++) { + done |= txt_replace_char(text, str[i]); + } + } else { + for(i=0; str[i]; i++) { + done |= txt_add_char(text, str[i]); + } + } - if(st && st->overwrite) - done= txt_replace_char(text, ascii); - else - done= txt_add_char(text, ascii); + MEM_freeN(str); if(!done) return OPERATOR_CANCELLED; @@ -2273,7 +2273,7 @@ static int insert_invoke(bContext *C, wmOperator *op, wmEvent *event) /* run the script while editing, evil but useful */ if(ret==OPERATOR_FINISHED && CTX_wm_space_text(C)->live_edit) run_script_exec(C, op); - + return ret; } |