- remove unused includes IMB_*, BIF_* & MEM_*
[blender.git] / source / blender / editors / space_text / text_header.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 <stdlib.h>
30 #include <string.h>
31 #include <stdio.h>
32
33 /* file time checking */
34 #include <ctype.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37
38 #ifndef _WIN32
39 #include <unistd.h>
40 #else
41 #include <io.h>
42 #include "BLI_winstuff.h"
43 #endif
44
45 #include "DNA_windowmanager_types.h"
46
47 #include "MEM_guardedalloc.h"
48
49 #include "BLI_blenlib.h"
50
51 #include "BKE_context.h"
52
53 #include "ED_screen.h"
54
55 #include "WM_types.h"
56
57
58
59
60 #ifndef DISABLE_PYTHON
61 // XXX #include "BPY_menus.h"
62 #endif
63
64 #include "text_intern.h"
65
66 #define HEADER_PATH_MAX 260
67
68 /* ************************ header area region *********************** */
69
70 /************************** properties ******************************/
71
72 ARegion *text_has_properties_region(ScrArea *sa)
73 {
74         ARegion *ar, *arnew;
75         
76         for(ar= sa->regionbase.first; ar; ar= ar->next)
77                 if(ar->regiontype==RGN_TYPE_UI)
78                         return ar;
79         
80         /* add subdiv level; after header */
81         for(ar= sa->regionbase.first; ar; ar= ar->next)
82                 if(ar->regiontype==RGN_TYPE_HEADER)
83                         break;
84         
85         /* is error! */
86         if(ar==NULL) return NULL;
87         
88         arnew= MEM_callocN(sizeof(ARegion), "properties region");
89         
90         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
91         arnew->regiontype= RGN_TYPE_UI;
92         arnew->alignment= RGN_ALIGN_LEFT;
93         
94         arnew->flag = RGN_FLAG_HIDDEN;
95         
96         return arnew;
97 }
98
99 static int properties_poll(bContext *C)
100 {
101         return (CTX_wm_space_text(C) != NULL);
102 }
103
104 static int properties_exec(bContext *C, wmOperator *op)
105 {
106         ScrArea *sa= CTX_wm_area(C);
107         ARegion *ar= text_has_properties_region(sa);
108         
109         if(ar)
110                 ED_region_toggle_hidden(C, ar);
111
112         return OPERATOR_FINISHED;
113 }
114
115 void TEXT_OT_properties(wmOperatorType *ot)
116 {
117         /* identifiers */
118         ot->name= "Properties";
119         ot->description= "Toggle text properties panel";
120         ot->idname= "TEXT_OT_properties";
121         
122         /* api callbacks */
123         ot->exec= properties_exec;
124         ot->poll= properties_poll;
125 }
126
127 /******************** XXX popup menus *******************/
128
129 #if 0
130 {
131         // RMB
132
133         uiPopupMenu *pup;
134
135         if(text) {
136                 pup= uiPupMenuBegin(C, "Text", 0);
137                 if(txt_has_sel(text)) {
138                         uiItemO(layout, NULL, 0, "TEXT_OT_cut");
139                         uiItemO(layout, NULL, 0, "TEXT_OT_copy");
140                 }
141                 uiItemO(layout, NULL, 0, "TEXT_OT_paste");
142                 uiItemO(layout, NULL, 0, "TEXT_OT_new");
143                 uiItemO(layout, NULL, 0, "TEXT_OT_open");
144                 uiItemO(layout, NULL, 0, "TEXT_OT_save");
145                 uiItemO(layout, NULL, 0, "TEXT_OT_save_as");
146                 uiItemO(layout, NULL, 0, "TEXT_OT_run_script");
147                 uiPupMenuEnd(C, pup);
148         }
149         else {
150                 pup= uiPupMenuBegin(C, "File", 0);
151                 uiItemO(layout, NULL, 0, "TEXT_OT_new");
152                 uiItemO(layout, NULL, 0, "TEXT_OT_open");
153                 uiPupMenuEnd(C, pup);
154         }
155 }
156
157 {
158         // Alt+Shift+E
159
160         uiPopupMenu *pup;
161
162         pup= uiPupMenuBegin(C, "Edit", 0);
163         uiItemO(layout, NULL, 0, "TEXT_OT_cut");
164         uiItemO(layout, NULL, 0, "TEXT_OT_copy");
165         uiItemO(layout, NULL, 0, "TEXT_OT_paste");
166         uiPupMenuEnd(C, pup);
167 }
168
169 {
170         // Alt+Shift+F
171
172         uiPopupMenu *pup;
173
174         if(text) {
175                 pup= uiPupMenuBegin(C, "Text", 0);
176                 uiItemO(layout, NULL, 0, "TEXT_OT_new");
177                 uiItemO(layout, NULL, 0, "TEXT_OT_open");
178                 uiItemO(layout, NULL, 0, "TEXT_OT_save");
179                 uiItemO(layout, NULL, 0, "TEXT_OT_save_as");
180                 uiItemO(layout, NULL, 0, "TEXT_OT_run_script");
181                 uiPupMenuEnd(C, pup);
182         }
183         else {
184                 pup= uiPupMenuBegin(C, "File", 0);
185                 uiItemO(layout, NULL, 0, "TEXT_OT_new");
186                 uiItemO(layout, NULL, 0, "TEXT_OT_open");
187                 uiPupMenuEnd(C, pup);
188         }
189 }
190
191 {
192         // Alt+Shift+V
193
194         uiPopupMenu *pup;
195
196         pup= uiPupMenuBegin(C, "Text", 0);
197         uiItemEnumO(layout, "TEXT_OT_move", "Top of File", 0, "type", FILE_TOP);
198         uiItemEnumO(layout, "TEXT_OT_move", "Bottom of File", 0, "type", FILE_BOTTOM);
199         uiItemEnumO(layout, "TEXT_OT_move", "Page Up", 0, "type", PREV_PAGE);
200         uiItemEnumO(layout, "TEXT_OT_move", "Page Down", 0, "type", NEXT_PAGE);
201         uiPupMenuEnd(C, pup);
202 }
203 #endif
204