d4187c10b69beb752ad3938705f2059efcf234f1
[blender-staging.git] / release / ui / space_text.py
1
2 import bpy
3
4 # temporary
5 ICON_LINENUMBERS_OFF = 588
6 ICON_WORDWRAP_OFF = 584
7 ICON_SYNTAX_OFF = 586
8 ICON_TEXT = 120
9 ICON_HELP = 1
10 ICON_SCRIPTPLUGINS = 1
11
12 class TEXT_HT_header(bpy.types.Header):
13         __space_type__ = "TEXT_EDITOR"
14         __idname__ = "TEXT_HT_header"
15
16         def draw(self, context):
17                 st = context.space_data
18                 text = st.text
19                 layout = self.layout
20
21                 layout.template_header(context)
22
23                 if context.area.show_menus:
24                         row = layout.row(align=True)
25                         row.itemM(context, "TEXT_MT_text")
26                         if text:
27                                 row.itemM(context, "TEXT_MT_edit")
28                                 row.itemM(context, "TEXT_MT_format")
29
30                 if text and text.modified:
31                         row = layout.row()
32                         # row.color(redalert)
33                         row.itemO("TEXT_OT_resolve_conflict", text="", icon=ICON_HELP)
34
35                 row = layout.row(align=True)
36                 row.itemR(st, "line_numbers", text="", icon=ICON_LINENUMBERS_OFF)
37                 row.itemR(st, "word_wrap", text="", icon=ICON_WORDWRAP_OFF)
38                 row.itemR(st, "syntax_highlight", text="", icon=ICON_SYNTAX_OFF)
39                 # row.itemR(st, "do_python_plugins", text="", icon=ICON_SCRIPTPLUGINS)
40
41                 layout.template_header_ID(context, st, "text", new="TEXT_OT_new", open="TEXT_OT_open", unlink="TEXT_OT_unlink")
42
43                 if text:
44                         row = layout.row()
45                         if text.filename != "":
46                                 if text.dirty:
47                                         row.itemL(text="File: *" + text.filename + " (unsaved)")
48                                 else:
49                                         row.itemL(text="File: " + text.filename)
50                         else:
51                                 if text.library:
52                                         row.itemL(text="Text: External")
53                                 else:
54                                         row.itemL(text="Text: Internal")
55
56 class TEXT_PT_properties(bpy.types.Panel):
57         __space_type__ = "TEXT_EDITOR"
58         __region_type__ = "UI"
59         __label__ = "Properties"
60
61         def draw(self, context):
62                 st = context.space_data
63                 layout = self.layout
64
65                 flow = layout.column_flow()
66                 flow.itemR(st, "line_numbers", icon=ICON_LINENUMBERS_OFF)
67                 flow.itemR(st, "word_wrap", icon=ICON_WORDWRAP_OFF)
68                 flow.itemR(st, "syntax_highlight", icon=ICON_SYNTAX_OFF)
69
70                 flow = layout.column_flow()
71                 flow.itemR(st, "font_size")
72                 flow.itemR(st, "tab_width")
73
74 class TEXT_PT_find(bpy.types.Panel):
75         __space_type__ = "TEXT_EDITOR"
76         __region_type__ = "UI"
77         __label__ = "Find"
78
79         def draw(self, context):
80                 st = context.space_data
81                 layout = self.layout
82
83                 # find
84                 col = layout.column(align=True)
85                 row = col.row()
86                 row.itemR(st, "find_text", text="")
87                 row.itemO("TEXT_OT_find_set_selected", text="", icon=ICON_TEXT)
88                 col.itemO("TEXT_OT_find")
89
90                 # replace
91                 col = layout.column(align=True)
92                 row = col.row()
93                 row.itemR(st, "replace_text", text="")
94                 row.itemO("TEXT_OT_replace_set_selected", text="", icon=ICON_TEXT)
95                 col.itemO("TEXT_OT_replace")
96
97                 # mark
98                 layout.itemO("TEXT_OT_mark_all")
99
100                 # settings
101                 row = layout.row()
102                 row.itemR(st, "find_wrap", text="Wrap")
103                 row.itemR(st, "find_all", text="All")
104
105 class TEXT_MT_text(bpy.types.Menu):
106         __space_type__ = "TEXT_EDITOR"
107         __label__ = "Text"
108
109         def draw(self, context):
110                 layout = self.layout
111                 st = context.space_data
112                 text = st.text
113
114                 layout.column()
115                 layout.itemO("TEXT_OT_new")
116                 layout.itemO("TEXT_OT_open")
117
118                 if text:
119                         layout.itemO("TEXT_OT_reload")
120
121                         layout.column()
122                         layout.itemO("TEXT_OT_save")
123                         layout.itemO("TEXT_OT_save_as")
124
125                         if text.filename != "":
126                                 layout.itemO("TEXT_OT_make_internal")
127
128                         layout.column()
129                         layout.itemO("TEXT_OT_run_script")
130
131                         #ifndef DISABLE_PYTHON
132                         # XXX if(BPY_is_pyconstraint(text))
133                         # XXX   uiMenuItemO(head, 0, "TEXT_OT_refresh_pyconstraints");
134                         #endif
135                 
136                 #ifndef DISABLE_PYTHON
137                 # XXX layout.column()
138                 # XXX uiDefIconTextBlockBut(block, text_template_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Script Templates", 0, yco-=20, 120, 19, "");
139                 # XXX uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, "");
140                 #endif
141
142 bpy.types.register(TEXT_HT_header)
143 bpy.types.register(TEXT_PT_properties)
144 bpy.types.register(TEXT_PT_find)
145 bpy.types.register(TEXT_MT_text)
146