Text Editor: Add an option "Tabs as Spaces".

So now tab is not ALWAYS converted to spaces.
This is stored by text datablock (what allows to do nice things in the future, as automatic check for the indentation type of the file).

Ideally we should redraw the other Text Editor windows after changing that (in case the same file is opened and the Property panel is also open). Not sure how to do that though.

I'm using TABSTOSPACES as the DEFINE flag because TABSASSPACES sounds too ugly.

(also fix for interface divisor bug)
This commit is contained in:
Dalai Felinto 2010-01-14 21:30:51 +00:00
parent 5d16a5b7d9
commit 690ad15099
5 changed files with 9 additions and 2 deletions

View File

@ -78,6 +78,7 @@ class TEXT_PT_properties(bpy.types.Panel):
layout = self.layout
st = context.space_data
text = st.text
flow = layout.column_flow()
flow.prop(st, "line_numbers")
@ -88,6 +89,7 @@ class TEXT_PT_properties(bpy.types.Panel):
flow = layout.column_flow()
flow.prop(st, "font_size")
flow.prop(st, "tab_width")
flow.prop(text, "tabs_as_spaces")
class TEXT_PT_find(bpy.types.Panel):

View File

@ -2380,7 +2380,7 @@ int txt_add_char (Text *text, char add)
}
/* insert spaces rather then tabs */
if (add == '\t') {
if (add == '\t' && text->flags & TXT_TABSTOSPACES) {
txt_convert_tab_to_spaces(text);
return 1;
}

View File

@ -1800,7 +1800,7 @@ static void ui_draw_but_HSV_v(uiBut *but, rcti *rect)
static void ui_draw_separator(uiBut *but, rcti *rect, uiWidgetColors *wcol)
{
int y = rect->ymin + (rect->ymax - rect->ymin)/2 - 1;
unsigned char col[3];
unsigned char col[4];
col[0] = wcol->text[0];
col[1] = wcol->text[1];

View File

@ -84,6 +84,7 @@ typedef struct Text {
#define TXT_ISSCRIPT 0x0010 /* used by space handler scriptlinks */
#define TXT_READONLY 0x0100
#define TXT_FOLLOW 0x0200 /* always follow cursor (console) */
#define TXT_TABSTOSPACES 0x0400 /* use space instead of tabs */
/* format continuation flags */
#define TXT_NOCONT 0x00 /* no continuation */

View File

@ -198,6 +198,10 @@ static void rna_def_text(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "flags", TXT_ISSCRIPT);
RNA_def_property_ui_text(prop, "Register", "Register this text as a module on loading.");
prop= RNA_def_property(srna, "tabs_as_spaces", PROP_BOOLEAN, PROP_NONE);
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, "lines", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "TextLine");
RNA_def_property_ui_text(prop, "Lines", "Lines of text.");