Index: release/scripts/startup/bl_ui/space_text.py =================================================================== --- release/scripts/startup/bl_ui/space_text.py (revision 51429) +++ release/scripts/startup/bl_ui/space_text.py (working copy) @@ -96,12 +96,14 @@ flow = layout.column_flow() flow.prop(st, "font_size") - flow.prop(st, "tab_width") text = st.text + if text: + flow.prop(st, "tab_width") flow.prop(text, "use_tabs_as_spaces") + flow.prop(st, "show_margin") col = flow.column() col.active = st.show_margin Index: release/scripts/startup/bl_ui/space_userpref.py =================================================================== --- release/scripts/startup/bl_ui/space_userpref.py (revision 51429) +++ release/scripts/startup/bl_ui/space_userpref.py (working copy) @@ -841,9 +841,13 @@ col.label(text="Scripts:") col.prop(system, "use_scripts_auto_execute") - col.prop(system, "use_tabs_as_spaces") + colsubsplit = col.split(percentage=0.5) + colsubsplit.prop(system, "use_tabs_as_spaces") + colsubsplit.prop(system, "tab_size") + + from bl_ui.space_userpref_keymap import InputKeyMapPanel Index: source/blender/makesrna/intern/rna_userdef.c =================================================================== --- source/blender/makesrna/intern/rna_userdef.c (revision 51429) +++ source/blender/makesrna/intern/rna_userdef.c (working copy) @@ -3135,6 +3135,12 @@ RNA_def_property_ui_text(prop, "Tabs as Spaces", "Automatically convert all new tabs into spaces for new and loaded text files"); + prop = RNA_def_property(srna, "tab_size", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "tab_size"); + RNA_def_property_range(prop, 2, 8); + RNA_def_property_int_default(prop, 2); + RNA_def_property_ui_text(prop, "Tab size", "Tab size editing a text file"); + prop = RNA_def_property(srna, "prefetch_frames", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "prefetchframes"); RNA_def_property_range(prop, 0, 500); Index: source/blender/makesrna/intern/rna_text.c =================================================================== --- source/blender/makesrna/intern/rna_text.c (revision 51429) +++ source/blender/makesrna/intern/rna_text.c (working copy) @@ -30,14 +30,19 @@ #include "MEM_guardedalloc.h" -#include "BKE_text.h" +#include "BLI_utildefines.h" +#include "BKE_main.h" +#include "BKE_text.h" #include "RNA_define.h" #include "rna_internal.h" +#include "DNA_scene_types.h" #include "DNA_text_types.h" +#include "DNA_space_types.h" +#include "WM_api.h" #include "WM_types.h" #ifdef RNA_RUNTIME @@ -115,6 +120,7 @@ #else + static void rna_def_text_line(BlenderRNA *brna) { StructRNA *srna; @@ -172,6 +178,7 @@ RNA_def_property_ui_text(prop, "Color", "Color to display the marker with"); } + static void rna_def_text(BlenderRNA *brna) { StructRNA *srna; @@ -210,6 +217,12 @@ RNA_def_property_boolean_sdna(prop, NULL, "flags", TXT_TABSTOSPACES); RNA_def_property_ui_text(prop, "Tabs as Spaces", "Automatically converts all new tabs into spaces"); + prop = RNA_def_property(srna, "tab_width", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "tab_size"); + RNA_def_property_range(prop, 2, TXT_MAX_TABSIZE); + RNA_def_property_int_default(prop, 2); + RNA_def_property_ui_text(prop, "Tab size", "Tab size in spaces"); + prop = RNA_def_property(srna, "lines", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "TextLine"); RNA_def_property_ui_text(prop, "Lines", "Lines of text"); Index: source/blender/makesrna/intern/rna_space.c =================================================================== --- source/blender/makesrna/intern/rna_space.c (revision 51429) +++ source/blender/makesrna/intern/rna_space.c (working copy) @@ -47,6 +47,7 @@ #include "DNA_sequence_types.h" #include "DNA_mask_types.h" #include "DNA_view3d_types.h" +#include "DNA_text_types.h" #include "WM_api.h" #include "WM_types.h" @@ -696,6 +697,7 @@ SpaceText *st = (SpaceText *)(ptr->data); st->text = value.data; + st->tabnumber = st->text->tab_size; WM_main_add_notifier(NC_TEXT | NA_SELECTED, st->text); } @@ -705,7 +707,10 @@ SpaceText *st = (SpaceText *)ptr->data; if (st->text) + { + st->text->tab_size=st->tabnumber; WM_main_add_notifier(NC_TEXT | NA_EDITED, st->text); + } } Index: source/blender/blenloader/intern/versioning_legacy.c =================================================================== --- source/blender/blenloader/intern/versioning_legacy.c (revision 51429) +++ source/blender/blenloader/intern/versioning_legacy.c (working copy) @@ -1814,9 +1814,9 @@ v3d->flag |= V3D_ZBUF_SELECT; } else if (sl->spacetype == SPACE_TEXT) { - SpaceText *st = (SpaceText *)sl; - if (st->tabnumber == 0) - st->tabnumber = 2; + SpaceText *st = (SpaceText *)sl; + if (st->tabnumber == 0) + st->tabnumber = 2; } } } Index: source/blender/blenloader/intern/readfile.c =================================================================== --- source/blender/blenloader/intern/readfile.c (revision 51429) +++ source/blender/blenloader/intern/readfile.c (working copy) @@ -8149,6 +8149,15 @@ do_version_node_cleanup_dynamic_sockets_264(NULL, NULL, ntree); } + if (main->versionfile < 264 || (main->versionfile==264 && main->subversionfile<21)) { + { + Text *text; + for (text = main->text.first; text; text = text->id.next) { + text->tab_size=4; + } + U.tab_size=4; + } + } /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */ Index: source/blender/editors/space_text/space_text.c =================================================================== --- source/blender/editors/space_text/space_text.c (revision 51429) +++ source/blender/editors/space_text/space_text.c (working copy) @@ -74,7 +74,6 @@ stext->spacetype = SPACE_TEXT; stext->lheight = 12; - stext->tabnumber = 4; stext->margin_column = 80; /* header */ Index: source/blender/editors/space_text/text_draw.c =================================================================== --- source/blender/editors/space_text/text_draw.c (revision 51429) +++ source/blender/editors/space_text/text_draw.c (working copy) @@ -149,7 +149,7 @@ for (r = 0, i = 0; *in; r++) { if (*in == '\t') { - i = st->tabnumber - (total % st->tabnumber); + i = st->text->tab_size - (total % st->text->tab_size); total += i; while (i--) @@ -534,7 +534,7 @@ { Text *text; TextLine *linep; - int i, j, start, end, max, chop; + int i, j, start, end, max, chop, tab_size; char ch; *offl = *offc = 0; @@ -543,6 +543,7 @@ if (!st->wordwrap) return; text = st->text; + tab_size=text->tab_size; /* Move pointer to first visible line (top) */ linep = text->lines.first; @@ -581,7 +582,7 @@ /* Mimic replacement of tabs */ ch = linep->line[j]; if (ch == '\t') { - chars = st->tabnumber - i % st->tabnumber; + chars = tab_size - i % tab_size; if (linep == linein && i < cursin) cursin += chars - 1; ch = ' '; } @@ -624,7 +625,7 @@ /* cursin - mem, offc - view */ void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *offl, int *offc) { - int i, j, start, end, chars, max, chop; + int i, j, start, end, chars, max, chop, tab_size; char ch; *offl = *offc = 0; @@ -638,6 +639,7 @@ end = max; chop = 1; *offc = 0; + tab_size=st->text->tab_size; cursin = txt_utf8_offset_to_index(linein->line, cursin); for (i = 0, j = 0; linein->line[j]; j += BLI_str_utf8_size(linein->line + j)) { @@ -645,7 +647,7 @@ /* Mimic replacement of tabs */ ch = linein->line[j]; if (ch == '\t') { - chars = st->tabnumber - i % st->tabnumber; + chars = tab_size - i % tab_size; if (i < cursin) cursin += chars - 1; ch = ' '; } @@ -687,7 +689,7 @@ for (i = 0; i < cur && line[i]; i += BLI_str_utf8_size(line + i)) { if (line[i] == '\t') - a += st->tabnumber - a % st->tabnumber; + a += st->text->tab_size - a % st->text->tab_size; else a++; } @@ -851,7 +853,7 @@ full_update |= drawcache->winx != ar->winx; /* area was resized */ full_update |= drawcache->wordwrap != st->wordwrap; /* word-wrapping option was toggled */ full_update |= drawcache->showlinenrs != st->showlinenrs; /* word-wrapping option was toggled */ - full_update |= drawcache->tabnumber != st->tabnumber; /* word-wrapping option was toggled */ + full_update |= drawcache->tabnumber != txt->tab_size; /* word-wrapping option was toggled */ full_update |= drawcache->lheight != st->lheight; /* word-wrapping option was toggled */ full_update |= drawcache->cwidth != st->cwidth; /* word-wrapping option was toggled */ full_update |= strncmp(drawcache->text_id, txt->id.name, MAX_ID_NAME); /* text datablock was changed */ @@ -931,7 +933,7 @@ drawcache->lheight = st->lheight; drawcache->cwidth = st->cwidth; drawcache->showlinenrs = st->showlinenrs; - drawcache->tabnumber = st->tabnumber; + drawcache->tabnumber = st->text->tab_size; strncpy(drawcache->text_id, txt->id.name, MAX_ID_NAME); @@ -1020,7 +1022,7 @@ /* Mimic replacement of tabs */ ch = str[j]; if (ch == '\t') { - chars = st->tabnumber - i % st->tabnumber; + chars = st->text->tab_size - i % st->text->tab_size; ch = ' '; } else chars = 1; @@ -1592,7 +1594,7 @@ char ch = text->sell->line[text->selc]; w = st->cwidth; - if (ch == '\t') w *= st->tabnumber - (vselc + st->left) % st->tabnumber; + if (ch == '\t') w *= st->text->tab_size - (vselc + st->left) % st->text->tab_size; UI_ThemeColor(TH_HILITE); glRecti(x, y - st->lheight - 1, x + w, y - st->lheight + 1); Index: source/blender/editors/space_text/text_ops.c =================================================================== --- source/blender/editors/space_text/text_ops.c (revision 51429) +++ source/blender/editors/space_text/text_ops.c (working copy) @@ -261,6 +261,7 @@ else if (st) { st->text = text; st->top = 0; + st->tabnumber= U.tab_size; } if (internal) { @@ -1006,7 +1007,7 @@ SpaceText *st = CTX_wm_space_text(C); Text *text = CTX_data_edit_text(C); int a, curts; - int space = (text->flags & TXT_TABSTOSPACES) ? st->tabnumber : 1; + int space = (text->flags & TXT_TABSTOSPACES) ? text->tab_size : 1; text_drawcache_tag_update(st, 0); @@ -1184,7 +1185,7 @@ extra = 0; for (a = 0; a < strlen(text_check_line); a++) { number = 0; - for (j = 0; j < (size_t)st->tabnumber; j++) { + for (j = 0; j < (size_t)text->tab_size; j++) { if ((a + j) <= strlen(text_check_line)) { //check to make sure we are not pass the end of the line if (text_check_line[a + j] != ' ') { number = 1; @@ -1192,17 +1193,17 @@ } } if (!number) { //found all number of space to equal a tab - a = a + (st->tabnumber - 1); + a = a + (text->tab_size - 1); extra = extra + 1; } } if (extra > 0) { //got tabs make malloc and do what you have to do - new_line = MEM_callocN(strlen(text_check_line) - (((st->tabnumber * extra) - extra) - 1), "Converted_Line"); + new_line = MEM_callocN(strlen(text_check_line) - (((text->tab_size * extra) - extra) - 1), "Converted_Line"); extra = 0; //reuse vars for (a = 0; a < strlen(text_check_line); a++) { number = 0; - for (j = 0; j < (size_t)st->tabnumber; j++) { + for (j = 0; j < (size_t)text->tab_size; j++) { if ((a + j) <= strlen(text_check_line)) { //check to make sure we are not pass the end of the line if (text_check_line[a + j] != ' ') { number = 1; @@ -1212,7 +1213,7 @@ if (!number) { //found all number of space to equal a tab new_line[extra] = '\t'; - a = a + (st->tabnumber - 1); + a = a + (text->tab_size- 1); extra++; } @@ -1508,7 +1509,7 @@ /* Mimic replacement of tabs */ ch = linein->line[j]; if (ch == '\t') { - chars = st->tabnumber - i % st->tabnumber; + chars = st->text->tab_size - i % st->text->tab_size; ch = ' '; } else chars = 1; @@ -1687,7 +1688,7 @@ /* Mimic replacement of tabs */ ch = (*linep)->line[j]; if (ch == '\t') { - chars = st->tabnumber - i % st->tabnumber; + chars = text->tab_size - i % text->tab_size; ch = ' '; } else chars = 1; @@ -1755,7 +1756,7 @@ /* Mimic replacement of tabs */ ch = (*linep)->line[j]; if (ch == '\t') { - chars = st->tabnumber - i % st->tabnumber; + chars = text->tab_size - i % text->tab_size; ch = ' '; } else chars = 1; @@ -2464,7 +2465,7 @@ for (i = 0; str[i]; i += BLI_str_utf8_size(str + i)) { if (str[i] == '\t') { - total += st->tabnumber - total % st->tabnumber; + total += st->text->tab_size - total % st->text->tab_size; } else total++; } @@ -2477,7 +2478,7 @@ int i, j; for (i = 0, j = 0; i < index; j += BLI_str_utf8_size(str + j)) if (str[j] == '\t') - i += st->tabnumber - i % st->tabnumber; + i += st->text->tab_size - i % st->text->tab_size; else i++; @@ -2525,7 +2526,7 @@ /* Mimic replacement of tabs */ ch = linep->line[j]; if (ch == '\t') { - chars = st->tabnumber - i % st->tabnumber; + chars = text->tab_size - i % text->tab_size; ch = ' '; } else chars = 1; Index: source/blender/blenkernel/BKE_blender.h =================================================================== --- source/blender/blenkernel/BKE_blender.h (revision 51429) +++ source/blender/blenkernel/BKE_blender.h (working copy) @@ -42,7 +42,7 @@ * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 264 -#define BLENDER_SUBVERSION 4 +#define BLENDER_SUBVERSION 21 /* 262 was the last editmesh release but its has compatibility code for bmesh data, * so set the minversion to 2.61 */ Index: source/blender/blenkernel/intern/text.c =================================================================== --- source/blender/blenkernel/intern/text.c (revision 51429) +++ source/blender/blenkernel/intern/text.c (working copy) @@ -218,6 +218,7 @@ ta->curc = 0; ta->sell = ta->lines.first; ta->selc = 0; + ta->tab_size=U.tab_size; return ta; } @@ -401,6 +402,7 @@ if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0) ta->flags = TXT_TABSTOSPACES; + ta->tab_size=U.tab_size; fseek(fp, 0L, SEEK_END); len = ftell(fp); @@ -888,9 +890,8 @@ } else { // do nice left only if there are only spaces - // TXT_TABSIZE hardcoded in DNA_text_types.h if (text->flags & TXT_TABSTOSPACES) { - tabsize = (*charp < TXT_TABSIZE) ? *charp : TXT_TABSIZE; + tabsize = (*charp < text->tab_size) ? *charp : text->tab_size; for (i = 0; i < (*charp); i++) if ((*linep)->line[i] != ' ') { @@ -899,8 +900,8 @@ } // if in the middle of the space-tab - if (tabsize && (*charp) % TXT_TABSIZE != 0) - tabsize = ((*charp) % TXT_TABSIZE); + if (tabsize && (*charp) % text->tab_size != 0) + tabsize = ((*charp) % text->tab_size); } if (tabsize) @@ -937,7 +938,6 @@ } else { // do nice right only if there are only spaces - // spaces hardcoded in DNA_text_types.h if (text->flags & TXT_TABSTOSPACES && (*linep)->line[*charp] == ' ') { do_tab = TRUE; for (i = 0; i < *charp; i++) @@ -948,8 +948,8 @@ } if (do_tab) { - int tabsize = (*charp) % TXT_TABSIZE + 1; - for (i = *charp + 1; (*linep)->line[i] == ' ' && tabsize < TXT_TABSIZE; i++) + int tabsize = (*charp) % text->tab_size + 1; + for (i = *charp + 1; (*linep)->line[i] == ' ' && tabsize < text->tab_size; i++) tabsize++; (*charp) = i; } @@ -2701,18 +2701,17 @@ txt_delete_sel(text); } -/* Max spaces to replace a tab with, currently hardcoded to TXT_TABSIZE = 4. - * Used by txt_convert_tab_to_spaces, indent and unindent. + /* Used by txt_convert_tab_to_spaces, indent and unindent. * Remember to change this string according to max tab size */ -static char tab_to_spaces[] = " "; +static char tab_to_spaces[] = " "; static void txt_convert_tab_to_spaces(Text *text) { /* sb aims to pad adjust the tab-width needed so that the right number of spaces * is added so that the indention of the line is the right width (i.e. aligned - * to multiples of TXT_TABSIZE) + * to multiples of Text->tabsize) */ - char *sb = &tab_to_spaces[text->curc % TXT_TABSIZE]; + char *sb = &tab_to_spaces[TXT_MAX_TABSIZE-text->tab_size+(text->curc % text->tab_size)]; txt_insert_buf(text, sb); } @@ -2840,8 +2839,7 @@ const char *add = "\t"; int indentlen = 1; - /* hardcoded: TXT_TABSIZE = 4 spaces: */ - int spaceslen = TXT_TABSIZE; + int spaceslen = text->tab_size; if (ELEM3(NULL, text, text->curl, text->sell)) { return; @@ -2853,7 +2851,7 @@ /* insert spaces rather than tabs */ if (text->flags & TXT_TABSTOSPACES) { - add = tab_to_spaces; + add = &(tab_to_spaces[TXT_MAX_TABSIZE-spaceslen]); indentlen = spaceslen; } @@ -2902,8 +2900,7 @@ const char *remove = "\t"; int indent = 1; - /* hardcoded: TXT_TABSIZE = 4 spaces: */ - int spaceslen = TXT_TABSIZE; + int spaceslen = text->tab_size; if (!text) return; if (!text->curl) return; @@ -2911,7 +2908,7 @@ /* insert spaces rather than tabs */ if (text->flags & TXT_TABSTOSPACES) { - remove = tab_to_spaces; + remove = &(tab_to_spaces[TXT_MAX_TABSIZE-spaceslen]); indent = spaceslen; } Index: source/blender/makesdna/DNA_text_types.h =================================================================== --- source/blender/makesdna/DNA_text_types.h (revision 51429) +++ source/blender/makesdna/DNA_text_types.h (working copy) @@ -70,9 +70,11 @@ void *compiled; double mtime; + int tab_size; //Tab size in spaces + int pad; } Text; -#define TXT_TABSIZE 4 +#define TXT_MAX_TABSIZE 8 #define TXT_INIT_UNDO 1024 #define TXT_MAX_UNDO (TXT_INIT_UNDO*TXT_INIT_UNDO) Index: source/blender/makesdna/DNA_userdef_types.h =================================================================== --- source/blender/makesdna/DNA_userdef_types.h (revision 51429) +++ source/blender/makesdna/DNA_userdef_types.h (working copy) @@ -440,7 +440,9 @@ int compute_device_id; float fcu_inactive_alpha; /* opacity of inactive F-Curves in F-Curve Editor */ - float pad; + + short tab_size; /* Tab size fot text editing */ + short pad; } UserDef; extern UserDef U; /* from blenkernel blender.c */ Index: source/blender/makesdna/DNA_space_types.h =================================================================== --- source/blender/makesdna/DNA_space_types.h (revision 51429) +++ source/blender/makesdna/DNA_space_types.h (working copy) @@ -801,7 +801,7 @@ char cwidth, linenrs_tot; /* runtime computed, character width and the number of chars to use when showing line numbers */ int left; int showlinenrs; - int tabnumber; + int tabnumber; short showsyntax; short line_hlight;