diff options
Diffstat (limited to 'source/blender/editors/space_text')
-rw-r--r-- | source/blender/editors/space_text/Makefile | 2 | ||||
-rw-r--r-- | source/blender/editors/space_text/space_text.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_draw.c | 99 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_header.c | 9 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 40 |
5 files changed, 100 insertions, 55 deletions
diff --git a/source/blender/editors/space_text/Makefile b/source/blender/editors/space_text/Makefile index 50871017085..8bc12852e18 100644 --- a/source/blender/editors/space_text/Makefile +++ b/source/blender/editors/space_text/Makefile @@ -15,7 +15,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # The Original Code is Copyright (C) 2007 Blender Foundation # All rights reserved. diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 7f3741e8e17..c8c19a0bc93 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -38,7 +38,6 @@ #include "BLI_math.h" #include "BLI_rand.h" -#include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_screen.h" @@ -274,6 +273,8 @@ static void text_keymap(struct wmKeyConfig *keyconf) RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_LINE); RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_PAGE); RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_PAGE); + RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", HOMEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", FILE_TOP); + RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", ENDKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", FILE_BOTTOM); RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_BEGIN); RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_END); @@ -285,6 +286,8 @@ static void text_keymap(struct wmKeyConfig *keyconf) RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_LINE); RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_PAGE); RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_PAGE); + RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", FILE_TOP); + RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", FILE_BOTTOM); RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_NEXT_CHAR); RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_CHAR); diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 873deb30511..62274fc664a 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -44,14 +44,11 @@ #include "DNA_userdef_types.h" #include "BKE_context.h" -#include "BKE_global.h" -#include "BKE_main.h" #include "BKE_suggestions.h" #include "BKE_text.h" #include "BKE_utildefines.h" #include "BIF_gl.h" -#include "BIF_glutil.h" #include "ED_datafiles.h" #include "UI_interface.h" @@ -113,8 +110,8 @@ static void flatten_string_append(FlattenString *fs, char c, int accum) nbuf= MEM_callocN(sizeof(*fs->buf)*fs->len, "fs->buf"); naccum= MEM_callocN(sizeof(*fs->accum)*fs->len, "fs->accum"); - memcpy(nbuf, fs->buf, fs->pos); - memcpy(naccum, fs->accum, fs->pos); + memcpy(nbuf, fs->buf, fs->pos * sizeof(*fs->buf)); + memcpy(naccum, fs->accum, fs->pos * sizeof(*fs->accum)); if(fs->buf != fs->fixedbuf) { MEM_freeN(fs->buf); @@ -174,12 +171,13 @@ void flatten_string_free(FlattenString *fs) static int find_builtinfunc(char *string) { int a, i; - char builtinfuncs[][11] = {"and", "as", "assert", "break", "class", "continue", "def", + char builtinfuncs[][9] = {"and", "as", "assert", "break", "class", "continue", "def", "del", "elif", "else", "except", "exec", "finally", "for", "from", "global", "if", "import", "in", "is", "lambda", "not", "or", "pass", "print", - "raise", "return", "try", "while", "yield"}; - for(a=0; a<30; a++) { + "raise", "return", "try", "while", "yield", "with"}; + + for(a=0; a < sizeof(builtinfuncs)/sizeof(builtinfuncs[0]); a++) { i = 0; while(1) { /* If we hit the end of a keyword... (eg. "def") */ @@ -224,6 +222,18 @@ static int find_specialvar(char *string) return i; } +static int find_decorator(char *string) +{ + if(string[0] == '@') { + int i = 1; + while(text_check_identifier(string[i])) { + i++; + } + return i; + } + return -1; +} + static int find_bool(char *string) { int i = 0; @@ -377,6 +387,8 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next) prev = 'v'; else if((i=find_builtinfunc(str)) != -1) prev = 'b'; + else if((i=find_decorator(str)) != -1) + prev = 'v'; /* could have a new color for this */ if(i>0) { while(i>1) { *fmt = prev; fmt++; str++; @@ -1102,6 +1114,22 @@ static void draw_cursor(SpaceText *st, ARegion *ar) } } + if(st->line_hlight) { + y= ar->winy-2 - vsell*st->lheight; + if(!(y<0 || y > ar->winy)) { /* check we need to draw */ + int x1= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; + int x2= x1 + ar->winx; + y= ar->winy-2 - vsell*st->lheight; + + glColor4ub(255, 255, 255, 32); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glRecti(x1-4, y, x2, y-st->lheight+1); + glDisable(GL_BLEND); + } + } + if(!hidden) { /* Draw the cursor itself (we draw the sel. cursor as this is the leading edge) */ x= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; @@ -1132,7 +1160,8 @@ static void draw_brackets(SpaceText *st, ARegion *ar) int viewc, viewl, offl, offc, x, y; char ch; - if(!text->curl) return; + // showsyntax must be on or else the format string will be null + if(!text->curl || !st->showsyntax) return; startl= text->curl; startc= text->curc; @@ -1146,23 +1175,29 @@ static void draw_brackets(SpaceText *st, ARegion *ar) endc= -1; find= -b; stack= 0; + + /* Dont highlight backets if syntax HL is off or bracket in string or comment. */ + if(!linep->format || linep->format[c] == 'l' || linep->format[c] == '#') + return; if(b>0) { /* opening bracket, search forward for close */ c++; while(linep) { while(c<linep->len) { - b= text_check_bracket(linep->line[c]); - if(b==find) { - if(stack==0) { - endl= linep; - endc= c; - break; + if(linep->format && linep->format[c] != 'l' && linep->format[c] != '#') { + b= text_check_bracket(linep->line[c]); + if(b==find) { + if(stack==0) { + endl= linep; + endc= c; + break; + } + stack--; + } + else if(b==-find) { + stack++; } - stack--; - } - else if(b==-find) { - stack++; } c++; } @@ -1176,17 +1211,19 @@ static void draw_brackets(SpaceText *st, ARegion *ar) c--; while(linep) { while(c>=0) { - b= text_check_bracket(linep->line[c]); - if(b==find) { - if(stack==0) { - endl= linep; - endc= c; - break; + if(linep->format && linep->format[c] != 'l' && linep->format[c] != '#') { + b= text_check_bracket(linep->line[c]); + if(b==find) { + if(stack==0) { + endl= linep; + endc= c; + break; + } + stack--; + } + else if(b==-find) { + stack++; } - stack--; - } - else if(b==-find) { - stack++; } c--; } @@ -1280,7 +1317,7 @@ void draw_text_main(SpaceText *st, ARegion *ar) } y= ar->winy-st->lheight; winx= ar->winx - TXT_SCROLL_WIDTH; - + /* draw cursor */ draw_cursor(st, ar); @@ -1348,7 +1385,7 @@ void text_update_cursor_moved(bContext *C) ARegion *ar; int i, x, winx= 0; - if(!st || !st->text || st->text->curl) return; + if(ELEM3(NULL, st, st->text, st->text->curl)) return; text= st->text; diff --git a/source/blender/editors/space_text/text_header.c b/source/blender/editors/space_text/text_header.c index 3b1c882ff2f..672940cf3cb 100644 --- a/source/blender/editors/space_text/text_header.c +++ b/source/blender/editors/space_text/text_header.c @@ -49,24 +49,15 @@ #include "BLI_blenlib.h" #include "BKE_context.h" -#include "BKE_global.h" -#include "BKE_library.h" -#include "BKE_main.h" -#include "BKE_scene.h" -#include "BKE_screen.h" -#include "BKE_text.h" #include "ED_screen.h" #include "WM_types.h" -#include "BIF_gl.h" -#include "BIF_glutil.h" #ifndef DISABLE_PYTHON -#include "BPY_extern.h" // XXX #include "BPY_menus.h" #endif diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index a684c4dce0e..d39056c6bbc 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -34,19 +34,17 @@ #include "MEM_guardedalloc.h" -#include "DNA_constraint_types.h" #include "DNA_text_types.h" +#include "DNA_userdef_types.h" #include "BLI_blenlib.h" #include "PIL_time.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_global.h" #include "BKE_library.h" #include "BKE_main.h" #include "BKE_report.h" -#include "BKE_suggestions.h" #include "BKE_text.h" #include "WM_api.h" @@ -218,7 +216,7 @@ static int open_exec(bContext *C, wmOperator *op) PropertyPointerRNA *pprop; PointerRNA idptr; char str[FILE_MAX]; - short internal = RNA_int_get(op->ptr, "internal"); + short internal = RNA_boolean_get(op->ptr, "internal"); RNA_string_get(op->ptr, "filepath", str); @@ -583,14 +581,17 @@ void TEXT_OT_run_script(wmOperatorType *ot) /* api callbacks */ ot->poll= run_script_poll; ot->exec= run_script_exec; -} + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} /******************* refresh pyconstraints operator *********************/ static int refresh_pyconstraints_exec(bContext *C, wmOperator *op) { #ifndef DISABLE_PYTHON +#if 0 Text *text= CTX_data_edit_text(C); Object *ob; bConstraint *con; @@ -625,6 +626,7 @@ static int refresh_pyconstraints_exec(bContext *C, wmOperator *op) } } #endif +#endif return OPERATOR_FINISHED; } @@ -902,15 +904,22 @@ void TEXT_OT_unindent(wmOperatorType *ot) static int line_break_exec(bContext *C, wmOperator *op) { + SpaceText *st= CTX_wm_space_text(C); Text *text= CTX_data_edit_text(C); - int a, curtab; + int a, curts; + int space = (text->flags & TXT_TABSTOSPACES) ? st->tabnumber : 1; - // double check tabs before splitting the line - curtab= setcurr_tab(text); + // double check tabs/spaces before splitting the line + curts= setcurr_tab_spaces(text, space); txt_split_curline(text); - for(a=0; a < curtab; a++) - txt_add_char(text, '\t'); + for(a=0; a < curts; a++) { + if (text->flags & TXT_TABSTOSPACES) { + txt_add_char(text, ' '); + } else { + txt_add_char(text, '\t'); + } + } if(text->curl) { if(text->curl->prev) @@ -1020,7 +1029,7 @@ static int convert_whitespace_exec(bContext *C, wmOperator *op) tmp = text->lines.first; - //first convert to all space, this make it alot easier to convert to tabs because there is no mixtures of ' ' && '\t' + //first convert to all space, this make it a lot easier to convert to tabs because there is no mixtures of ' ' && '\t' while(tmp) { text_check_line = tmp->line; number = flatten_string(st, &fs, text_check_line)+1; @@ -1700,6 +1709,8 @@ static int toggle_overwrite_exec(bContext *C, wmOperator *op) st->overwrite= !st->overwrite; + WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); + return OPERATOR_FINISHED; } @@ -2352,9 +2363,11 @@ void TEXT_OT_insert(wmOperatorType *ot) static int find_and_replace(bContext *C, wmOperator *op, short mode) { + Main *bmain= CTX_data_main(C); SpaceText *st= CTX_wm_space_text(C); Text *start= NULL, *text= st->text; int flags, first= 1; + int found = 0; char *tmp; if(!st->findstr[0] || (mode == TEXT_REPLACE && !st->replacestr[0])) @@ -2413,16 +2426,17 @@ static int find_and_replace(bContext *C, wmOperator *op, short mode) if(text->id.next) text= st->text= text->id.next; else - text= st->text= G.main->text.first; + text= st->text= bmain->text.first; txt_move_toline(text, 0, 0); text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); first= 1; } else { - BKE_reportf(op->reports, RPT_ERROR, "Text not found: %s", st->findstr); + if(!found) BKE_reportf(op->reports, RPT_ERROR, "Text not found: %s", st->findstr); break; } + found = 1; } while(mode==TEXT_MARK_ALL); return OPERATOR_FINISHED; |