patch [#22570] Text editor syntax coloring update
[blender.git] / source / blender / editors / space_text / space_text.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_text_types.h"
33 #include "DNA_object_types.h"
34
35 #include "MEM_guardedalloc.h"
36
37 #include "BLI_blenlib.h"
38 #include "BLI_math.h"
39 #include "BLI_rand.h"
40
41 #include "BKE_colortools.h"
42 #include "BKE_context.h"
43 #include "BKE_screen.h"
44
45 #include "ED_screen.h"
46
47 #include "BIF_gl.h"
48
49 #include "WM_api.h"
50 #include "WM_types.h"
51
52 #include "UI_interface.h"
53 #include "UI_resources.h"
54 #include "UI_view2d.h"
55
56 #include "RNA_access.h"
57
58
59 #include "text_intern.h"        // own include
60
61 /* ******************** default callbacks for text space ***************** */
62
63 static SpaceLink *text_new(const bContext *C)
64 {
65         ARegion *ar;
66         SpaceText *stext;
67         
68         stext= MEM_callocN(sizeof(SpaceText), "inittext");
69         stext->spacetype= SPACE_TEXT;
70
71         stext->lheight= 12;
72         stext->tabnumber= 4;
73         
74         /* header */
75         ar= MEM_callocN(sizeof(ARegion), "header for text");
76         
77         BLI_addtail(&stext->regionbase, ar);
78         ar->regiontype= RGN_TYPE_HEADER;
79         ar->alignment= RGN_ALIGN_BOTTOM;
80         
81         /* main area */
82         ar= MEM_callocN(sizeof(ARegion), "main area for text");
83         
84         BLI_addtail(&stext->regionbase, ar);
85         ar->regiontype= RGN_TYPE_WINDOW;
86         
87         return (SpaceLink *)stext;
88 }
89
90 /* not spacelink itself */
91 static void text_free(SpaceLink *sl)
92 {       
93         SpaceText *stext= (SpaceText*) sl;
94         
95         stext->text= NULL;
96 }
97
98
99 /* spacetype; init callback */
100 static void text_init(struct wmWindowManager *wm, ScrArea *sa)
101 {
102
103 }
104
105 static SpaceLink *text_duplicate(SpaceLink *sl)
106 {
107         SpaceText *stextn= MEM_dupallocN(sl);
108         
109         /* clear or remove stuff from old */
110         
111         return (SpaceLink *)stextn;
112 }
113
114 static void text_listener(ScrArea *sa, wmNotifier *wmn)
115 {
116         SpaceText *st= sa->spacedata.first;
117
118         /* context changes */
119         switch(wmn->category) {
120                 case NC_TEXT:
121                         if(!wmn->reference || wmn->reference == st->text || wmn->data == ND_DISPLAY || wmn->action == NA_EDITED) {
122                                 ED_area_tag_redraw(sa);
123
124                                 if(wmn->action == NA_EDITED)
125                                         if(st->text)
126                                                 text_update_edited(st->text);
127                         }
128
129                         break;
130                 case NC_SPACE:
131                         if(wmn->data == ND_SPACE_TEXT)
132                                 ED_area_tag_redraw(sa);
133                         break;
134         }
135 }
136
137 static void text_operatortypes(void)
138 {
139         WM_operatortype_append(TEXT_OT_new);
140         WM_operatortype_append(TEXT_OT_open);
141         WM_operatortype_append(TEXT_OT_reload);
142         WM_operatortype_append(TEXT_OT_unlink);
143         WM_operatortype_append(TEXT_OT_save);
144         WM_operatortype_append(TEXT_OT_save_as);
145         WM_operatortype_append(TEXT_OT_make_internal);
146         WM_operatortype_append(TEXT_OT_run_script);
147         WM_operatortype_append(TEXT_OT_refresh_pyconstraints);
148
149         WM_operatortype_append(TEXT_OT_paste);
150         WM_operatortype_append(TEXT_OT_copy);
151         WM_operatortype_append(TEXT_OT_cut);
152
153         WM_operatortype_append(TEXT_OT_convert_whitespace);
154         WM_operatortype_append(TEXT_OT_uncomment);
155         WM_operatortype_append(TEXT_OT_comment);
156         WM_operatortype_append(TEXT_OT_unindent);
157         WM_operatortype_append(TEXT_OT_indent);
158
159         WM_operatortype_append(TEXT_OT_markers_clear);
160         WM_operatortype_append(TEXT_OT_next_marker);
161         WM_operatortype_append(TEXT_OT_previous_marker);
162
163         WM_operatortype_append(TEXT_OT_select_line);
164         WM_operatortype_append(TEXT_OT_select_all);
165
166         WM_operatortype_append(TEXT_OT_jump);
167         WM_operatortype_append(TEXT_OT_move);
168         WM_operatortype_append(TEXT_OT_move_select);
169         WM_operatortype_append(TEXT_OT_delete);
170         WM_operatortype_append(TEXT_OT_overwrite_toggle);
171
172         WM_operatortype_append(TEXT_OT_cursor_set);
173         WM_operatortype_append(TEXT_OT_scroll);
174         WM_operatortype_append(TEXT_OT_scroll_bar);
175         WM_operatortype_append(TEXT_OT_line_number);
176
177         WM_operatortype_append(TEXT_OT_line_break);
178         WM_operatortype_append(TEXT_OT_insert);
179
180         WM_operatortype_append(TEXT_OT_properties);
181
182         WM_operatortype_append(TEXT_OT_find);
183         WM_operatortype_append(TEXT_OT_find_set_selected);
184         WM_operatortype_append(TEXT_OT_replace);
185         WM_operatortype_append(TEXT_OT_replace_set_selected);
186         WM_operatortype_append(TEXT_OT_mark_all);
187
188         WM_operatortype_append(TEXT_OT_to_3d_object);
189
190         WM_operatortype_append(TEXT_OT_resolve_conflict);
191 }
192
193 static void text_keymap(struct wmKeyConfig *keyconf)
194 {
195         wmKeyMap *keymap;
196         wmKeyMapItem *kmi;
197         
198         keymap= WM_keymap_find(keyconf, "Text", SPACE_TEXT, 0);
199         
200         #ifdef __APPLE__
201         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
202         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
203         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
204         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
205         WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT|KM_OSKEY, 0);
206         WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_OSKEY, 0);
207         WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_OSKEY, 0);
208         WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_OSKEY, 0); 
209         WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
210         WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_OSKEY, 0);
211         WM_keymap_add_item(keymap, "TEXT_OT_find_set_selected", EKEY, KM_PRESS, KM_OSKEY, 0);
212         WM_keymap_add_item(keymap, "TEXT_OT_find", GKEY, KM_PRESS, KM_OSKEY, 0);
213         WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_OSKEY, 0);
214         WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
215         #endif
216         
217         kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
218         RNA_string_set(kmi->ptr, "path", "space_data.font_size");
219         RNA_boolean_set(kmi->ptr, "reverse", 0);
220         
221         kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
222         RNA_string_set(kmi->ptr, "path", "space_data.font_size");
223         RNA_boolean_set(kmi->ptr, "reverse", 1);
224
225         kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
226         RNA_string_set(kmi->ptr, "path", "space_data.font_size");
227         RNA_boolean_set(kmi->ptr, "reverse", 0);
228         
229         kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADMINUS, KM_PRESS, KM_CTRL, 0);
230         RNA_string_set(kmi->ptr, "path", "space_data.font_size");
231         RNA_boolean_set(kmi->ptr, "reverse", 1);
232         
233         WM_keymap_add_item(keymap, "TEXT_OT_new", NKEY, KM_PRESS, KM_ALT, 0);
234         WM_keymap_add_item(keymap, "TEXT_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
235         WM_keymap_add_item(keymap, "TEXT_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
236         WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT, 0);
237         WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_CTRL, 0);
238
239         WM_keymap_add_item(keymap, "TEXT_OT_run_script", PKEY, KM_PRESS, KM_ALT, 0);
240         
241         WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_CTRL, 0);
242         WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
243         WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
244
245         if(U.uiflag & USER_MMB_PASTE) // XXX not dynamic
246                 RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0)->ptr, "selection", 1);
247
248         WM_keymap_add_item(keymap, "TEXT_OT_jump", JKEY, KM_PRESS, KM_CTRL, 0);
249         WM_keymap_add_item(keymap, "TEXT_OT_find", GKEY, KM_PRESS, KM_CTRL, 0);
250         
251         WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_CTRL, 0);
252         WM_keymap_add_item(keymap, "TEXT_OT_replace", HKEY, KM_PRESS, KM_CTRL, 0);
253
254         WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0);
255
256         WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_CTRL, 0);
257         WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
258         
259
260         WM_keymap_add_item(keymap, "TEXT_OT_indent", TABKEY, KM_PRESS, 0, 0);
261         WM_keymap_add_item(keymap, "TEXT_OT_unindent", TABKEY, KM_PRESS, KM_SHIFT, 0);
262         WM_keymap_add_item(keymap, "TEXT_OT_uncomment", DKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
263
264         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", HOMEKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_BEGIN);
265         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", ENDKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_END);
266         
267         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", EKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", LINE_END);
268         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", EKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "type", LINE_END);
269         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_CHAR);
270         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_CHAR);
271         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", PREV_WORD);
272         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", NEXT_WORD);
273         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_LINE);
274         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_LINE);
275         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_PAGE);
276         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_PAGE);
277
278         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_BEGIN);
279         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_END);
280         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_CHAR);
281         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_CHAR);
282         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", PREV_WORD);
283         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", NEXT_WORD);
284         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_LINE);
285         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_LINE);
286         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_PAGE);
287         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_PAGE);
288
289         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_NEXT_CHAR);
290         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_CHAR);
291         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_PREV_CHAR);
292         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_WORD);
293         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_PREV_WORD);
294
295         WM_keymap_add_item(keymap, "TEXT_OT_overwrite_toggle", INSERTKEY, KM_PRESS, 0, 0);
296
297         WM_keymap_add_item(keymap, "TEXT_OT_scroll", MIDDLEMOUSE, KM_PRESS, 0, 0);
298         WM_keymap_add_item(keymap, "TEXT_OT_scroll", MOUSEPAN, 0, 0, 0);
299         WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", LEFTMOUSE, KM_PRESS, 0, 0);
300         WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, 0, 0);
301         RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select", 1);
302         RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELUPMOUSE, KM_PRESS, 0, 0)->ptr, "lines", -1);
303         RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELDOWNMOUSE, KM_PRESS, 0, 0)->ptr, "lines", 1);
304
305         WM_keymap_add_item(keymap, "TEXT_OT_line_break", RETKEY, KM_PRESS, 0, 0);
306         WM_keymap_add_item(keymap, "TEXT_OT_line_break", PADENTER, KM_PRESS, 0, 0);
307
308         WM_keymap_add_menu(keymap, "TEXT_MT_toolbox", RIGHTMOUSE, KM_PRESS, KM_ANY, 0);
309         
310         WM_keymap_add_item(keymap, "TEXT_OT_line_number", KM_TEXTINPUT, KM_ANY, KM_ANY, 0);
311         WM_keymap_add_item(keymap, "TEXT_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last!
312 }
313
314 static int text_context(const bContext *C, const char *member, bContextDataResult *result)
315 {
316         SpaceText *st= CTX_wm_space_text(C);
317
318         if(CTX_data_dir(member)) {
319                 static const char *dir[] = {"edit_text", NULL};
320                 CTX_data_dir_set(result, dir);
321                 return 1;
322         }
323         else if(CTX_data_equals(member, "edit_text")) {
324                 CTX_data_id_pointer_set(result, &st->text->id);
325                 return 1;
326         }
327
328         return 0;
329 }
330
331 /********************* main region ********************/
332
333 /* add handlers, stuff you only do once or on area/region changes */
334 static void text_main_area_init(wmWindowManager *wm, ARegion *ar)
335 {
336         wmKeyMap *keymap;
337         ListBase *lb;
338         
339         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
340         
341         /* own keymap */
342         keymap= WM_keymap_find(wm->defaultconf, "Text", SPACE_TEXT, 0);
343         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
344         
345         /* add drop boxes */
346         lb = WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
347         
348         WM_event_add_dropbox_handler(&ar->handlers, lb);
349 }
350
351 static void text_main_area_draw(const bContext *C, ARegion *ar)
352 {
353         /* draw entirely, view changes should be handled here */
354         SpaceText *st= CTX_wm_space_text(C);
355         //View2D *v2d= &ar->v2d;
356         
357         /* clear and setup matrix */
358         UI_ThemeClearColor(TH_BACK);
359         glClear(GL_COLOR_BUFFER_BIT);
360         
361         // UI_view2d_view_ortho(C, v2d);
362                 
363         /* data... */
364         draw_text_main(st, ar);
365         
366         /* reset view matrix */
367         // UI_view2d_view_restore(C);
368         
369         /* scrollers? */
370 }
371
372 static void text_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
373 {
374         WM_cursor_set(win, BC_TEXTEDITCURSOR);
375 }
376
377
378
379 /* ************* dropboxes ************* */
380
381 static int text_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
382 {
383         if(drag->type==WM_DRAG_PATH)
384                 if(ELEM(drag->icon, 0, ICON_FILE_BLANK))        /* rule might not work? */
385                         return 1;
386         return 0;
387 }
388
389 static void text_drop_copy(wmDrag *drag, wmDropBox *drop)
390 {
391         /* copy drag path to properties */
392         RNA_string_set(drop->ptr, "path", drag->path);
393 }
394
395 /* this region dropbox definition */
396 static void text_dropboxes(void)
397 {
398         ListBase *lb= WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
399         
400         WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy);
401
402 }
403
404 /* ************* end drop *********** */
405
406
407 /****************** header region ******************/
408
409 /* add handlers, stuff you only do once or on area/region changes */
410 static void text_header_area_init(wmWindowManager *wm, ARegion *ar)
411 {
412         ED_region_header_init(ar);
413 }
414
415 static void text_header_area_draw(const bContext *C, ARegion *ar)
416 {
417         ED_region_header(C, ar);
418 }
419
420 /****************** properties region ******************/
421
422 /* add handlers, stuff you only do once or on area/region changes */
423 static void text_properties_area_init(wmWindowManager *wm, ARegion *ar)
424 {
425         ED_region_panels_init(wm, ar);
426 }
427
428 static void text_properties_area_draw(const bContext *C, ARegion *ar)
429 {
430         ED_region_panels(C, ar, 1, NULL, -1);
431 }
432
433 /********************* registration ********************/
434
435 /* only called once, from space/spacetypes.c */
436 void ED_spacetype_text(void)
437 {
438         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype text");
439         ARegionType *art;
440         
441         st->spaceid= SPACE_TEXT;
442         strncpy(st->name, "Text", BKE_ST_MAXNAME);
443         
444         st->new= text_new;
445         st->free= text_free;
446         st->init= text_init;
447         st->duplicate= text_duplicate;
448         st->operatortypes= text_operatortypes;
449         st->keymap= text_keymap;
450         st->listener= text_listener;
451         st->context= text_context;
452         st->dropboxes = text_dropboxes;
453         
454         /* regions: main window */
455         art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
456         art->regionid = RGN_TYPE_WINDOW;
457         art->init= text_main_area_init;
458         art->draw= text_main_area_draw;
459         art->cursor= text_cursor;
460
461         BLI_addhead(&st->regiontypes, art);
462         
463         /* regions: properties */
464         art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
465         art->regionid = RGN_TYPE_UI;
466         art->prefsizex= UI_COMPACT_PANEL_WIDTH;
467         art->keymapflag= ED_KEYMAP_UI;
468         
469         art->init= text_properties_area_init;
470         art->draw= text_properties_area_draw;
471         BLI_addhead(&st->regiontypes, art);
472
473         /* regions: header */
474         art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
475         art->regionid = RGN_TYPE_HEADER;
476         art->prefsizey= HEADERY;
477         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
478         
479         art->init= text_header_area_init;
480         art->draw= text_header_area_draw;
481
482         BLI_addhead(&st->regiontypes, art);
483
484         BKE_spacetype_register(st);
485 }
486