2.5: Text editor, port menu code to python.

This commit is contained in:
Brecht Van Lommel 2009-06-16 01:10:47 +00:00
parent f10541f7cf
commit 18d8454f2e
4 changed files with 108 additions and 112 deletions

@ -2,12 +2,8 @@
import bpy import bpy
# temporary # temporary
ICON_LINENUMBERS_OFF = 588
ICON_WORDWRAP_OFF = 584
ICON_SYNTAX_OFF = 586
ICON_TEXT = 120 ICON_TEXT = 120
ICON_HELP = 1 ICON_HELP = 1
ICON_SCRIPTPLUGINS = 1
class TEXT_HT_header(bpy.types.Header): class TEXT_HT_header(bpy.types.Header):
__space_type__ = "TEXT_EDITOR" __space_type__ = "TEXT_EDITOR"
@ -21,7 +17,7 @@ class TEXT_HT_header(bpy.types.Header):
layout.template_header(context) layout.template_header(context)
if context.area.show_menus: if context.area.show_menus:
row = layout.row(align=True) row = layout.row()
row.itemM(context, "TEXT_MT_text") row.itemM(context, "TEXT_MT_text")
if text: if text:
row.itemM(context, "TEXT_MT_edit") row.itemM(context, "TEXT_MT_edit")
@ -33,10 +29,9 @@ class TEXT_HT_header(bpy.types.Header):
row.itemO("TEXT_OT_resolve_conflict", text="", icon='ICON_HELP') row.itemO("TEXT_OT_resolve_conflict", text="", icon='ICON_HELP')
row = layout.row(align=True) row = layout.row(align=True)
row.itemR(st, "line_numbers", text="", icon='ICON_LINENUMBERS_OFF') row.itemR(st, "line_numbers", text="")
row.itemR(st, "word_wrap", text="", icon='ICON_WORDWRAP_OFF') row.itemR(st, "word_wrap", text="")
row.itemR(st, "syntax_highlight", text="", icon='ICON_SYNTAX_OFF') row.itemR(st, "syntax_highlight", text="")
# row.itemR(st, "do_python_plugins", text="", icon=ICON_SCRIPTPLUGINS)
layout.template_ID(context, st, "text", new="TEXT_OT_new", open="TEXT_OT_open", unlink="TEXT_OT_unlink") layout.template_ID(context, st, "text", new="TEXT_OT_new", open="TEXT_OT_open", unlink="TEXT_OT_unlink")
@ -63,9 +58,9 @@ class TEXT_PT_properties(bpy.types.Panel):
layout = self.layout layout = self.layout
flow = layout.column_flow() flow = layout.column_flow()
flow.itemR(st, "line_numbers", icon='ICON_LINENUMBERS_OFF') flow.itemR(st, "line_numbers")
flow.itemR(st, "word_wrap", icon='ICON_WORDWRAP_OFF') flow.itemR(st, "word_wrap")
flow.itemR(st, "syntax_highlight", icon='ICON_SYNTAX_OFF') flow.itemR(st, "syntax_highlight")
flow.itemR(st, "live_edit") flow.itemR(st, "live_edit")
flow = layout.column_flow() flow = layout.column_flow()
@ -140,8 +135,109 @@ class TEXT_MT_text(bpy.types.Menu):
# XXX uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, ""); # XXX uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, "");
#endif #endif
class TEXT_MT_edit_view(bpy.types.Menu):
__space_type__ = "TEXT_EDITOR"
__label__ = "View"
def draw(self, context):
layout = self.layout
layout.item_enumO("TEXT_OT_move", "type", "FILE_TOP", text="Top of File")
layout.item_enumO("TEXT_OT_move", "type", "FILE_BOTTOM", text="Bottom of File")
class TEXT_MT_edit_select(bpy.types.Menu):
__space_type__ = "TEXT_EDITOR"
__label__ = "Select"
def draw(self, context):
layout = self.layout
layout.itemO("TEXT_OT_select_all")
layout.itemO("TEXT_OT_select_line")
class TEXT_MT_edit_markers(bpy.types.Menu):
__space_type__ = "TEXT_EDITOR"
__label__ = "Markers"
def draw(self, context):
layout = self.layout
layout.itemO("TEXT_OT_markers_clear")
layout.itemO("TEXT_OT_next_marker")
layout.itemO("TEXT_OT_previous_marker")
class TEXT_MT_format(bpy.types.Menu):
__space_type__ = "TEXT_EDITOR"
__label__ = "Format"
def draw(self, context):
layout = self.layout
layout.itemO("TEXT_OT_indent")
layout.itemO("TEXT_OT_unindent")
layout.itemS()
layout.itemO("TEXT_OT_comment")
layout.itemO("TEXT_OT_uncomment")
layout.itemS()
layout.item_menu_enumO("TEXT_OT_convert_whitespace", "type")
class TEXT_MT_edit_to3d(bpy.types.Menu):
__space_type__ = "TEXT_EDITOR"
__label__ = "Text To 3D Object"
def draw(self, context):
layout = self.layout
layout.item_booleanO("TEXT_OT_to_3d_object", "split_lines", False, text="One Object");
layout.item_booleanO("TEXT_OT_to_3d_object", "split_lines", True, text="One Object Per Line");
class TEXT_MT_edit(bpy.types.Menu):
__space_type__ = "TEXT_EDITOR"
__label__ = "Edit"
def poll(self, context):
st = context.space_data
return st.text != None
def draw(self, context):
layout = self.layout
layout.itemO("ED_OT_undo")
layout.itemO("ED_OT_redo")
layout.itemS()
layout.itemO("TEXT_OT_cut")
layout.itemO("TEXT_OT_copy")
layout.itemO("TEXT_OT_paste")
layout.itemS()
layout.itemM(context, "TEXT_MT_edit_view")
layout.itemM(context, "TEXT_MT_edit_select")
layout.itemM(context, "TEXT_MT_edit_markers")
layout.itemS()
layout.itemO("TEXT_OT_jump")
layout.itemO("TEXT_OT_properties")
layout.itemS()
layout.itemM(context, "TEXT_MT_edit_to3d")
bpy.types.register(TEXT_HT_header) bpy.types.register(TEXT_HT_header)
bpy.types.register(TEXT_PT_properties) bpy.types.register(TEXT_PT_properties)
bpy.types.register(TEXT_PT_find) bpy.types.register(TEXT_PT_find)
bpy.types.register(TEXT_MT_text) bpy.types.register(TEXT_MT_text)
bpy.types.register(TEXT_MT_format)
bpy.types.register(TEXT_MT_edit)
bpy.types.register(TEXT_MT_edit_view)
bpy.types.register(TEXT_MT_edit_select)
bpy.types.register(TEXT_MT_edit_markers)
bpy.types.register(TEXT_MT_edit_to3d)

@ -416,8 +416,6 @@ void ED_spacetype_text(void)
art->init= text_header_area_init; art->init= text_header_area_init;
art->draw= text_header_area_draw; art->draw= text_header_area_draw;
text_header_register(art);
BLI_addhead(&st->regiontypes, art); BLI_addhead(&st->regiontypes, art);
BKE_spacetype_register(st); BKE_spacetype_register(st);

@ -155,101 +155,6 @@ static uiBlock *text_plugin_scriptsmenu(bContext *C, void *args_unused)
} }
#endif #endif
static void text_editmenu_viewmenu(bContext *C, uiLayout *layout, void *arg_unused)
{
uiItemEnumO(layout, "Top of File", 0, "TEXT_OT_move", "type", FILE_TOP);
uiItemEnumO(layout, "Bottom of File", 0, "TEXT_OT_move", "type", FILE_BOTTOM);
}
static void text_editmenu_selectmenu(bContext *C, uiLayout *layout, void *arg_unused)
{
uiItemO(layout, NULL, 0, "TEXT_OT_select_all");
uiItemO(layout, NULL, 0, "TEXT_OT_select_line");
}
static void text_editmenu_markermenu(bContext *C, uiLayout *layout, void *arg_unused)
{
uiItemO(layout, NULL, 0, "TEXT_OT_markers_clear");
uiItemO(layout, NULL, 0, "TEXT_OT_next_marker");
uiItemO(layout, NULL, 0, "TEXT_OT_previous_marker");
}
static void text_formatmenu(const bContext *C, Menu *menu)
{
uiLayout *layout= menu->layout;
uiItemO(layout, NULL, 0, "TEXT_OT_indent");
uiItemO(layout, NULL, 0, "TEXT_OT_unindent");
uiItemS(layout);
uiItemO(layout, NULL, 0, "TEXT_OT_comment");
uiItemO(layout, NULL, 0, "TEXT_OT_uncomment");
uiItemS(layout);
uiItemMenuEnumO(layout, NULL, 0, "TEXT_OT_convert_whitespace", "type");
}
static void text_editmenu_to3dmenu(bContext *C, uiLayout *layout, void *arg_unused)
{
uiItemBooleanO(layout, "One Object", 0, "TEXT_OT_to_3d_object", "split_lines", 0);
uiItemBooleanO(layout, "One Object Per Line", 0, "TEXT_OT_to_3d_object", "split_lines", 1);
}
static int text_menu_edit_poll(bContext *C)
{
return (CTX_data_edit_text(C) != NULL);
}
static void text_editmenu(const bContext *C, Menu *menu)
{
uiLayout *layout= menu->layout;
uiItemO(layout, NULL, 0, "ED_OT_undo");
uiItemO(layout, NULL, 0, "ED_OT_redo");
uiItemS(layout);
uiItemO(layout, NULL, 0, "TEXT_OT_cut");
uiItemO(layout, NULL, 0, "TEXT_OT_copy");
uiItemO(layout, NULL, 0, "TEXT_OT_paste");
uiItemS(layout);
uiItemMenuF(layout, "View", 0, text_editmenu_viewmenu);
uiItemMenuF(layout, "Select", 0, text_editmenu_selectmenu);
uiItemMenuF(layout, "Markers", 0, text_editmenu_markermenu);
uiItemS(layout);
uiItemO(layout, NULL, 0, "TEXT_OT_jump");
uiItemO(layout, NULL, 0, "TEXT_OT_properties");
uiItemS(layout);
uiItemMenuF(layout, "Text to 3D Object", 0, text_editmenu_to3dmenu);
}
/********************** header buttons ***********************/
void text_header_register(ARegionType *art)
{
MenuType *mt;
mt= MEM_callocN(sizeof(MenuType), "spacetype text menu edit");
strcpy(mt->idname, "TEXT_MT_edit");
strcpy(mt->label, "Edit");
mt->draw= text_editmenu;
BLI_addhead(&art->menutypes, mt);
mt= MEM_callocN(sizeof(MenuType), "spacetype text menu format");
strcpy(mt->idname, "TEXT_MT_format");
strcpy(mt->label, "Format");
mt->draw= text_formatmenu;
BLI_addhead(&art->menutypes, mt);
}
/************************** properties ******************************/ /************************** properties ******************************/
ARegion *text_has_properties_region(ScrArea *sa) ARegion *text_has_properties_region(ScrArea *sa)

@ -41,9 +41,6 @@ struct TextLine;
struct wmOperatorType; struct wmOperatorType;
struct wmWindowManager; struct wmWindowManager;
/* text_header.c */
void text_header_register(struct ARegionType *art);
/* text_draw.c */ /* text_draw.c */
void draw_text_main(struct SpaceText *st, struct ARegion *ar); void draw_text_main(struct SpaceText *st, struct ARegion *ar);