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