Text Editor UI

Tweak Text Editor to fit better with the rest of Blender 2.8:

  - Move sidebar to the right
  - Add proper context menu
  - Move view toggles to the View menu
  - Change the indentation option to be an enum between spaces and tabs
  - Several layout tweaks

Patch by @tintwotin / Peter Fog with additional tweaks by me.

Differential Revision https://developer.blender.org/D5028

Reviewers: Brecht, Campbell
This commit is contained in:
William Reynish 2019-08-04 12:51:28 +02:00
parent c0aada58c9
commit a2fe386153
Notes: blender-bot 2023-02-14 02:30:11 +01:00
Referenced by commit 38d7e14dc8, Fix (unreported0 bad usage of `do_versions_find_region()` in versionning code.
4 changed files with 91 additions and 38 deletions

View File

@ -47,11 +47,6 @@ class TEXT_HT_header(Header):
layout.separator_spacer()
row = layout.row(align=True)
row.prop(st, "show_line_numbers", text="")
row.prop(st, "show_word_wrap", text="")
row.prop(st, "show_syntax_highlight", text="")
if text:
is_osl = text.name.endswith((".osl", ".osl"))
@ -125,60 +120,63 @@ class TEXT_PT_properties(Panel):
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
st = context.space_data
flow = layout.column_flow()
flow.prop(st, "show_line_numbers")
flow.prop(st, "show_word_wrap")
flow.prop(st, "show_syntax_highlight")
flow.prop(st, "show_line_highlight")
flow.prop(st, "use_live_edit")
if not st.text:
flow.active = False
row = flow.row(align=True)
st = context.space_data
row.prop(st, "show_margin", text = "Margin")
rowsub = row.row()
rowsub.active = st.show_margin
rowsub.prop(st, "margin_column", text = "")
flow = layout.column_flow()
flow.prop(st, "font_size")
flow.prop(st, "tab_width")
text = st.text
if text:
flow.prop(text, "use_tabs_as_spaces")
flow.prop(st, "show_margin")
col = flow.column()
col.active = st.show_margin
col.prop(st, "margin_column")
layout.prop(text, "indentation")
class TEXT_PT_find(Panel):
bl_space_type = 'TEXT_EDITOR'
bl_region_type = 'UI'
bl_category = "Text"
bl_label = "Find"
bl_label = "Find & Replace"
def draw(self, context):
layout = self.layout
st = context.space_data
# find
col = layout.column(align=True)
col = layout.column()
row = col.row(align=True)
row.prop(st, "find_text", text="")
row.operator("text.find_set_selected", text="", icon='TEXT')
row.prop(st, "find_text", icon='VIEWZOOM', text="")
row.operator("text.find_set_selected", text="", icon='EYEDROPPER')
col.operator("text.find")
layout.separator()
# replace
col = layout.column(align=True)
col = layout.column()
row = col.row(align=True)
row.prop(st, "replace_text", text="")
row.operator("text.replace_set_selected", text="", icon='TEXT')
row.prop(st, "replace_text", icon='DECORATE_OVERRIDE', text="")
row.operator("text.replace_set_selected", text="", icon='EYEDROPPER')
col.operator("text.replace")
layout.separator()
# settings
layout.prop(st, "use_match_case")
row = layout.row(align=True)
row.prop(st, "use_find_wrap", text="Wrap")
row.prop(st, "use_find_all", text="All")
if not st.text:
row.active = False
row.prop(st, "use_match_case", text="Case", toggle=True)
row.prop(st, "use_find_wrap", text="Wrap", toggle=True)
row.prop(st, "use_find_all", text="All", toggle=True)
class TEXT_MT_view(Menu):
@ -193,6 +191,13 @@ class TEXT_MT_view(Menu):
layout.separator()
layout.prop(st, "show_line_numbers")
layout.prop(st, "show_word_wrap")
layout.prop(st, "show_syntax_highlight")
layout.prop(st, "show_line_highlight")
layout.separator()
layout.operator("text.move",
text="Top of File",
).type = 'FILE_TOP'
@ -280,6 +285,8 @@ class TEXT_MT_format(Menu):
def draw(self, _context):
layout = self.layout
st = _context.space_data
text = st.text
layout.operator("text.indent")
layout.operator("text.unindent")
@ -318,6 +325,8 @@ class TEXT_MT_edit(Menu):
def draw(self, _context):
layout = self.layout
st = _context.space_data
text = st.text
layout.operator("ed.undo")
layout.operator("ed.redo")
@ -331,6 +340,10 @@ class TEXT_MT_edit(Menu):
layout.separator()
layout.prop(st, "use_live_edit")
layout.separator()
layout.operator("text.move_lines",
text="Move line(s) up").direction = 'UP'
layout.operator("text.move_lines",
@ -356,16 +369,36 @@ class TEXT_MT_toolbox(Menu):
def draw(self, _context):
layout = self.layout
st = _context.space_data
text = st.text
layout.operator_context = 'INVOKE_DEFAULT'
layout.operator("text.cut")
layout.operator("text.copy")
layout.operator("text.paste")
layout.operator("text.copy", icon='COPYDOWN')
layout.operator("text.paste", icon='PASTEDOWN')
layout.separator()
layout.operator("text.run_script")
layout.operator("text.duplicate_line")
layout.operator("text.move_lines",
text="Move Lines Up").direction = 'UP'
layout.operator("text.move_lines",
text="Move Lines Down").direction = 'DOWN'
layout.separator()
layout.operator("text.indent")
layout.operator("text.unindent")
layout.separator()
layout.operator("text.comment", text="Comment")
layout.operator("text.uncomment", text="Uncomment")
layout.separator()
layout.operator("text.autocomplete")
classes = (
@ -373,8 +406,8 @@ classes = (
TEXT_HT_footer,
TEXT_MT_edit,
TEXT_MT_editor_menus,
TEXT_PT_properties,
TEXT_PT_find,
TEXT_PT_properties,
TEXT_MT_view,
TEXT_MT_text,
TEXT_MT_templates,

View File

@ -3555,5 +3555,18 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
U.view_rotate_sensitivity_turntable = DEG2RADF(0.4f);
U.view_rotate_sensitivity_trackball = 1.0f;
}
for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_TEXT) {
ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
ARegion *ar = do_versions_find_region(regionbase, RGN_TYPE_UI);
if (ar) {
ar->alignment = RGN_ALIGN_RIGHT;
}
}
}
}
}
}
}

View File

@ -82,7 +82,7 @@ static SpaceLink *text_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scen
BLI_addtail(&stext->regionbase, ar);
ar->regiontype = RGN_TYPE_UI;
ar->alignment = RGN_ALIGN_LEFT;
ar->alignment = RGN_ALIGN_RIGHT;
ar->flag = RGN_FLAG_HIDDEN;
/* main region */

View File

@ -146,6 +146,13 @@ static void rna_def_text_line(BlenderRNA *brna)
static void rna_def_text(BlenderRNA *brna)
{
static const EnumPropertyItem indentation_items[] = {
{0, "TABS", 0, "Tabs", "Indent using tabs"},
{TXT_TABSTOSPACES, "SPACES", 0, "Spaces", "Indent using spaces"},
{0, NULL, 0, NULL, NULL},
};
StructRNA *srna;
PropertyRNA *prop;
@ -182,10 +189,10 @@ static void rna_def_text(BlenderRNA *brna)
RNA_def_property_ui_text(
prop, "Register", "Run this text as a script on loading, Text name must end with \".py\"");
prop = RNA_def_property(srna, "use_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, "indentation", PROP_ENUM, PROP_NONE); /* as an enum */
RNA_def_property_enum_bitflag_sdna(prop, NULL, "flags");
RNA_def_property_enum_items(prop, indentation_items);
RNA_def_property_ui_text(prop, "Indentation", "Use tabs or spaces for indentation");
prop = RNA_def_property(srna, "lines", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "TextLine");