Overwrite mode added, toggled with INSERTKEY
authorIan Thompson <quornian@googlemail.com>
Wed, 4 Jun 2008 12:32:06 +0000 (12:32 +0000)
committerIan Thompson <quornian@googlemail.com>
Wed, 4 Jun 2008 12:32:06 +0000 (12:32 +0000)
source/blender/blenkernel/BKE_text.h
source/blender/blenkernel/intern/text.c
source/blender/makesdna/DNA_space_types.h
source/blender/src/drawtext.c
source/blender/src/space.c

index 6f891ab4887d7430e7c1ce77364d6342b5b7a32c..ea1afc3754af077afb2e414074b4e2865464cb88 100644 (file)
@@ -81,6 +81,7 @@ void  txt_do_redo                     (struct Text *text);
 void   txt_split_curline       (struct Text *text);
 void   txt_backspace_char      (struct Text *text);
 int            txt_add_char            (struct Text *text, char add);
+int            txt_replace_char        (struct Text *text, char add);
 void   txt_find_panel          (struct SpaceText *st, int again);
 void   run_python_script       (struct SpaceText *st);
 int    jumptoline_interactive  (struct SpaceText *st);
index 872f81ead632a3b7139ceac9602753baf53e1f47..af37f513ff67e276ea1bca5ac762308f7784da55 100644 (file)
@@ -2140,6 +2140,34 @@ int txt_add_char (Text *text, char add)
        return 1;
 }
 
+int txt_replace_char (Text *text, char add)
+{
+       char del;
+       
+       if (!text) return 0;
+       if (!text->curl) return 0;
+
+       /* If text is selected or we're at the end of the line just use txt_add_char */
+       if (text->curc==text->curl->len || text->sell!=text->curl || text->selc!=text->curc || add=='\n') {
+               return txt_add_char(text, add);
+       }
+       
+       del= text->curl->line[text->curc];
+       text->curl->line[text->curc]= (unsigned char) add;
+       text->curc++;
+       txt_pop_sel(text);
+       
+       txt_make_dirty(text);
+       txt_clean_text(text);
+
+       /* Should probably create a new op for this */
+       if(!undoing) {
+               txt_undo_add_charop(text, UNDO_DEL, del);
+               txt_undo_add_charop(text, UNDO_INSERT, add);
+       }
+       return 1;
+}
+
 void indent(Text *text)
 {
        int len, num;
index 619dfbb43a057e14d94321922348f48d430374c8..e4544d7763484de05a2b703de8ac939611d1e0c0 100644 (file)
@@ -281,7 +281,7 @@ typedef struct SpaceText {
        int tabnumber;
        int currtab_set; 
        int showsyntax;
-       int unused_padd;
+       int overwrite;
        
        float pix_per_line;
 
index 71f0bbef7ca4ba157f28f64e124388f71555a45f..31bdea0e07ec44fbe8636bdedc757a538f22e07b 100644 (file)
@@ -634,10 +634,11 @@ static void set_cursor_to_pos (SpaceText *st, int x, int y, int sel)
 }
 
 static void draw_cursor(SpaceText *st) {
-       int h, x, i;
+       int h, x, i, w;
        Text *text= st->text;
        TextLine *linef, *linel;
        int charf, charl;
+       char ch[2];
        
        if (text->curl==text->sell && text->curc==text->selc) {
                x= text_draw(st, text->curl->line, st->left, text->curc, 0, 0, 0, NULL);
@@ -645,9 +646,19 @@ static void draw_cursor(SpaceText *st) {
                if (x) {
                        h= txt_get_span(text->lines.first, text->curl) - st->top;
 
-                       BIF_ThemeColor(TH_HILITE);
-                       
-                       glRecti(x-1, curarea->winy-st->lheight*(h)-2, x+1, curarea->winy-st->lheight*(h+1)-2);
+                       if (st->overwrite) {
+                               ch[0]= (unsigned char) text->curl->line[text->curc];
+                               if (ch[0]=='\0') ch[0]=' ';
+                               ch[1]= '\0';
+                               w= BMF_GetStringWidth(spacetext_get_font(st), ch);
+                               BIF_ThemeColor(TH_SHADE2);
+                               glRecti(x, curarea->winy-st->lheight*(h)-2, x+w, curarea->winy-st->lheight*(h+1)-2);
+                               BIF_ThemeColor(TH_HILITE);
+                               glRecti(x, curarea->winy-st->lheight*(h+1)-3, x+w, curarea->winy-st->lheight*(h+1)-1);
+                       } else {
+                               BIF_ThemeColor(TH_HILITE);
+                               glRecti(x-1, curarea->winy-st->lheight*(h)-2, x+1, curarea->winy-st->lheight*(h+1)-2);
+                       }
                }
        } else {
                int span= txt_get_span(text->curl, text->sell);
@@ -1594,7 +1605,7 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        }
                }
        } else if (ascii) {
-               if (txt_add_char(text, ascii)) {
+               if ((st->overwrite && txt_replace_char(text, ascii)) || txt_add_char(text, ascii)) {
                        if (st->showsyntax) get_format_string(st);
                        pop_space_text(st);
                        do_draw= 1;
@@ -1894,6 +1905,10 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        pop_space_text(st);
                        st->currtab_set = setcurr_tab(text);
                        break;
+               case INSERTKEY:
+                       st->overwrite= !st->overwrite;
+                       do_draw= 1;
+                       break;
                case DOWNARROWKEY:
                        txt_move_down(text, G.qual & LR_SHIFTKEY);
                        set_tabs(text);
index 47e3387755b223f4d041a36904b28728e37f30cd..1a32bd35ecad1f6dadb12bbf805517afc5635a80 100644 (file)
@@ -6011,6 +6011,8 @@ static void init_textspace(ScrArea *sa)
        st->lheight= 12;
        st->showlinenrs= 0;
        st->tabnumber = 4;
+       st->showsyntax= 0;
+       st->overwrite= 0;
        st->currtab_set = 0;
        
        st->top= 0;