diff options
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 155 | ||||
-rw-r--r-- | source/blender/include/blendef.h | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_space_types.h | 5 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_text_types.h | 1 | ||||
-rw-r--r-- | source/blender/src/drawtext.c | 41 | ||||
-rw-r--r-- | source/blender/src/header_text.c | 52 | ||||
-rw-r--r-- | source/blender/src/space.c | 2 |
8 files changed, 257 insertions, 11 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index e1badf34ce4..c693b1f83c3 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -88,6 +88,15 @@ void txt_find_panel (struct SpaceText *st, int again); void run_python_script (struct SpaceText *st); int jumptoline_interactive (struct SpaceText *st); void txt_export_to_object (struct Text *text); +void indent_paste (struct Text *text); +void unindent (struct Text *text); +void comment (struct Text *text); +void uncommen (struct Text *text); +void indent (struct Text *text, char *in_buffer); +void unindent_lines (struct Text *text, char *in_buffer); +void comment_paste (struct Text *text, char *in_buffer); +void uncomment_paste (struct Text *text, char *in_buffer); +//void set_tabs (struct Text *text); /* Undo opcodes */ @@ -130,4 +139,3 @@ void txt_export_to_object (struct Text *text); #endif #endif - diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 4ad4ac648f2..25ac2b46800 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -1989,3 +1989,158 @@ int txt_add_char (Text *text, char add) { if(!undoing) txt_undo_add_charop(text, UNDO_INSERT, add); return 1; } + +//Antihc3(rick) used the paste function below +//used txt_cut_sel, txt_insert_buf modified + +void indent_paste(Text *text) +{ + + indent(text, txt_cut_buffer); +} + +void indent(Text *text, char *in_buffer) +{ + int i=0, len; + + if (!text) return; + if (!text->curl) return; + if (!text->sell) return; + if (!in_buffer) return; + + txt_delete_sel(text); //need to change this to remove the undo + + /* Read the first line (or as close as possible */ + len= strlen(in_buffer); + while ( i < len ) { + txt_add_char(text, '\t'); + while (in_buffer[i] && in_buffer[i]!='\n') { + txt_add_char(text, in_buffer[i]); + i++; + } + + if (in_buffer[i]=='\n') { + txt_add_char(text, '\n'); + + } + i++; + } +} + +void unindent(Text *text) +{ + unindent_lines(text, txt_cut_buffer); +} + +void unindent_lines(Text *text, char *in_buffer) +{ + int i=0, len; + + if (!text) return; + if (!text->curl) return; + if (!text->sell) return; + if (!in_buffer) return; + + txt_delete_sel(text); + + /* Read the first line (or as close as possible */ + len = strlen(in_buffer); + while ( i < len ) { + if (in_buffer[i] != '\t') { + while (in_buffer[i] && in_buffer[i]!='\n') { + txt_add_char(text, in_buffer[i]); + i++; + } + + if (in_buffer[i]=='\n') { + txt_add_char(text, '\n'); + + } + i++; + } + else { + i++; + while (in_buffer[i] && in_buffer[i]!='\n') { + txt_add_char(text, in_buffer[i]); + i++; + } + + if (in_buffer[i]=='\n') { + txt_add_char(text, '\n'); + + } + i++; + } + } +} + +void comment(Text *text) +{ + comment_paste(text, txt_cut_buffer); +} + +void comment_paste(Text *text, char *in_buffer) +{ + int i=0, len; + + if (!text) return; + if (!text->curl) return; + if (!text->sell) return; + if (!in_buffer) return; + + txt_delete_sel(text); + + /* Read the first line (or as close as possible */ + + len= strlen(in_buffer); + while ( i < len ) { + txt_add_char(text, '#'); + while (in_buffer[i] && in_buffer[i]!='\n') { + txt_add_char(text, in_buffer[i]); + i++; + } + + if (in_buffer[i]=='\n') { + txt_add_char(text, '\n'); + + } + i++; + } +} + + +void uncomment(Text *text) +{ + uncomment_paste(text, txt_cut_buffer); +} + +void uncomment_paste(Text *text, char *in_buffer) +{ + + int i=0, len; + + if (!text) return; + if (!text->curl) return; + if (!text->sell) return; + + if (!in_buffer) return; + + txt_delete_sel(text); + + /* Read the first line (or as close as possible */ + len = strlen(in_buffer); + while ( i < len ) { + if (in_buffer[i] != '#') { + while (in_buffer[i] && in_buffer[i]!='\n') { + txt_add_char(text, in_buffer[i]); + i++; + } + + if (in_buffer[i]=='\n') { + txt_add_char(text, '\n'); + + } + } + i++; + } +} diff --git a/source/blender/include/blendef.h b/source/blender/include/blendef.h index ba62238bb17..2df88ff064c 100644 --- a/source/blender/include/blendef.h +++ b/source/blender/include/blendef.h @@ -346,6 +346,7 @@ #define B_TEXTFONT 505 #define B_TEXTSTORE 506 #define B_TEXTLINENUM 507 +#define B_TAB_NUMBERS 508 /* SCRIPT: 525 */ #define B_SCRIPTBROWSE 526 @@ -452,4 +453,3 @@ #define GS(a) (*((short *)(a))) #endif - diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index 7017a4155cb..b4280756586 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -255,6 +255,10 @@ typedef struct SpaceText { int left; int showlinenrs; + int tabnumber; + int currtab_set; + /* had to make my 64 bits some how */ + float pix_per_line; struct rcti txtscroll, txtbar; @@ -516,4 +520,3 @@ typedef struct SpaceImaSel { #define IMS_INFILESLI 4 #endif - diff --git a/source/blender/makesdna/DNA_text_types.h b/source/blender/makesdna/DNA_text_types.h index 264ca33013c..391142db302 100644 --- a/source/blender/makesdna/DNA_text_types.h +++ b/source/blender/makesdna/DNA_text_types.h @@ -77,4 +77,3 @@ typedef struct Text { #define TXT_FOLLOW 0x0200 // always follow cursor (console) #endif - diff --git a/source/blender/src/drawtext.c b/source/blender/src/drawtext.c index 0758198ab86..88895ed1983 100644 --- a/source/blender/src/drawtext.c +++ b/source/blender/src/drawtext.c @@ -156,12 +156,13 @@ void free_txt_data(void) { } static int render_string (char *in) { + SpaceText *st= curarea->spacedata.first; int r= 0, i; while(*in) { if (*in=='\t') { - if (temp_char_pos && *(in-1)=='\t') i= TXT_TABSIZE; - else i= TXT_TABSIZE - (temp_char_pos%TXT_TABSIZE); + if (temp_char_pos && *(in-1)=='\t') i= st->tabnumber; + else i= st->tabnumber - (temp_char_pos%st->tabnumber); while(i--) temp_char_write(' ', r); } else temp_char_write(*in, r); @@ -975,6 +976,24 @@ void run_python_script(SpaceText *st) } } +void set_tabs(Text *text) { + + TextLine *line = text->curl; + SpaceText *st = curarea->spacedata.first; + int pos = 0; + int max; + max = line->len; + st->currtab_set = 0; + while ( pos < max-1) { + if (line->line[pos] == '\t') { + st->currtab_set++; + pos++; + } + else { + pos++; + } + } +} void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) { @@ -1045,7 +1064,7 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) if (event==LEFTMOUSE) { if (val) { short mval[2]; - + set_tabs(text); getmouseco_areawin(mval); if (mval[0]>2 && mval[0]<20 && mval[1]>2 && mval[1]<curarea->winy-2) { @@ -1324,41 +1343,57 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) break; case TABKEY: txt_add_char(text, '\t'); + st->currtab_set++; + printf("currenttab_set is :%d\n", st->currtab_set); pop_space_text(st); do_draw= 1; break; case RETKEY: txt_split_curline(text); + int a = 0; + while ( a < st->currtab_set) + { + txt_add_char(text, '\t'); + a++; + } do_draw= 1; pop_space_text(st); break; case BACKSPACEKEY: txt_backspace_char(text); + set_tabs(text); do_draw= 1; pop_space_text(st); break; case DELKEY: + if ( text->curl->line[text->curc] == '\t') { + st->currtab_set--; + } txt_delete_char(text); do_draw= 1; pop_space_text(st); break; case DOWNARROWKEY: txt_move_down(text, G.qual & LR_SHIFTKEY); + set_tabs(text); do_draw= 1; pop_space_text(st); break; case LEFTARROWKEY: txt_move_left(text, G.qual & LR_SHIFTKEY); + set_tabs(text); do_draw= 1; pop_space_text(st); break; case RIGHTARROWKEY: txt_move_right(text, G.qual & LR_SHIFTKEY); + set_tabs(text); do_draw= 1; pop_space_text(st); break; case UPARROWKEY: txt_move_up(text, G.qual & LR_SHIFTKEY); + set_tabs(text); do_draw= 1; pop_space_text(st); break; diff --git a/source/blender/src/header_text.c b/source/blender/src/header_text.c index 4d770c4eaf0..8ce574d440d 100644 --- a/source/blender/src/header_text.c +++ b/source/blender/src/header_text.c @@ -175,13 +175,18 @@ void do_text_buttons(unsigned short event) case 0: st->lheight= 12; break; case 1: - st->lheight= 15; break; + st->lheight= 15; + break; } - + allqueue(REDRAWTEXT, 0); allqueue(REDRAWHEADERS, 0); break; + case B_TAB_NUMBERS: + allqueue(REDRAWTEXT, 0); + allqueue(REDRAWHEADERS, 0); + break; } } @@ -325,6 +330,37 @@ static void do_text_editmenu_selectmenu(void *arg, int event) case 2: txt_sel_line(text); break; + case 3: + if (txt_has_sel(text)) { + txt_cut_sel(text); + indent_paste(text); + break; + } + else { + txt_add_char(text, '\t'); + break; + } + case 4: + if ( txt_has_sel(text)) { + txt_cut_sel(text); + unindent(text); + break; + } + break; + case 5: + if ( txt_has_sel(text)) { + txt_cut_sel(text); + comment(text); + break; + } + break; + case 6: + if ( txt_has_sel(text)) { + txt_cut_sel(text); + uncomment(text); + break; + } + break; default: break; } @@ -366,7 +402,13 @@ static uiBlock *text_editmenu_selectmenu(void *arg_unused) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select All|Ctrl A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Line", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, ""); - + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Indent", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "UnIndent", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, ""); + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Comment", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "UnComment", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, ""); + uiBlockSetDirection(block, UI_RIGHT); uiTextBoundsBlock(block, 60); @@ -528,7 +570,9 @@ void text_buttons(void) if(st->font_id>1) st->font_id= 0; uiDefButI(block, MENU, B_TEXTFONT, "Screen 12 %x0|Screen 15%x1", xco,0,100,YIC, &st->font_id, 0, 0, 0, 0, "Displays available fonts"); xco+=100; - + + uiDefButI(block, NUM, B_TAB_NUMBERS, "Tab:", xco+=XIC, 0, XIC+50, YIC, &st->tabnumber, 2, 8, 0, 0, "Set spacing of Tab"); + /* always as last */ curarea->headbutlen= xco+2*XIC; diff --git a/source/blender/src/space.c b/source/blender/src/space.c index 8713d57efee..c53649c0f37 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -3416,6 +3416,8 @@ static void init_textspace(ScrArea *sa) st->font_id= 5; st->lheight= 12; st->showlinenrs= 0; + st->tabnumber = 4; + st->currtab_set = 0; st->top= 0; } |