Usablity:
[blender-staging.git] / source / blender / editors / space_text / text_header.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_text/text_header.c
28  *  \ingroup sptext
29  */
30
31
32
33 /* file time checking */
34
35 #ifndef _WIN32
36 #else
37 #endif
38
39 #include "DNA_windowmanager_types.h"
40
41 #include "MEM_guardedalloc.h"
42
43 #include "BLI_blenlib.h"
44
45 #include "BLF_translation.h"
46
47 #include "BKE_context.h"
48 #include "BKE_screen.h"
49
50 #include "ED_screen.h"
51
52 #include "WM_types.h"
53
54 #ifdef WITH_PYTHON
55 // XXX #include "BPY_menus.h"
56 #endif
57
58 #include "text_intern.h"
59
60 /* ************************ header area region *********************** */
61
62 /************************** properties ******************************/
63
64 static ARegion *text_has_properties_region(ScrArea *sa)
65 {
66         ARegion *ar, *arnew;
67
68         ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
69         if (ar) return ar;
70         
71         /* add subdiv level; after header */
72         ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
73
74         /* is error! */
75         if (ar == NULL) return NULL;
76         
77         arnew = MEM_callocN(sizeof(ARegion), "properties region");
78         
79         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
80         arnew->regiontype = RGN_TYPE_UI;
81         arnew->alignment = RGN_ALIGN_LEFT;
82         
83         arnew->flag = RGN_FLAG_HIDDEN;
84         
85         return arnew;
86 }
87
88 static int text_properties_poll(bContext *C)
89 {
90         return (CTX_wm_space_text(C) != NULL);
91 }
92
93 static int text_properties_exec(bContext *C, wmOperator *UNUSED(op))
94 {
95         ScrArea *sa = CTX_wm_area(C);
96         ARegion *ar = text_has_properties_region(sa);
97         
98         if (ar)
99                 ED_region_toggle_hidden(C, ar);
100
101         return OPERATOR_FINISHED;
102 }
103
104 void TEXT_OT_properties(wmOperatorType *ot)
105 {
106         /* identifiers */
107         ot->name = "Properties";
108         ot->description = "Toggle text properties panel";
109         ot->idname = "TEXT_OT_properties";
110         
111         /* api callbacks */
112         ot->exec = text_properties_exec;
113         ot->poll = text_properties_poll;
114 }
115
116 static int text_text_search_exec(bContext *C, wmOperator *UNUSED(op))
117 {
118         ScrArea *sa = CTX_wm_area(C);
119         ARegion *ar = text_has_properties_region(sa);
120         SpaceText *st = CTX_wm_space_text(C);
121         
122         if (ar) {
123                 if (ar->flag & RGN_FLAG_HIDDEN)
124                         ED_region_toggle_hidden(C, ar);
125                 
126                 /* cannot send a button activate yet for case when region wasn't visible yet */
127                 /* flag gets checked and cleared in main draw callback */
128                 st->flags |= ST_FIND_ACTIVATE;
129                 
130                 ED_region_tag_redraw(ar);
131         }
132         return OPERATOR_FINISHED;
133 }
134
135
136 void TEXT_OT_start_find(wmOperatorType *ot)
137 {
138         /* identifiers */
139         ot->name = "Find";
140         ot->description = "Start searching text";
141         ot->idname = "TEXT_OT_start_find";
142         
143         /* api callbacks */
144         ot->exec = text_text_search_exec;
145         ot->poll = text_properties_poll;
146 }
147
148 /******************** XXX popup menus *******************/
149
150 #if 0
151 {
152         // RMB
153
154         uiPopupMenu *pup;
155
156         if (text) {
157                 pup = uiPupMenuBegin(C, IFACE_("Text"), ICON_NONE);
158                 if (txt_has_sel(text)) {
159                         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_cut");
160                         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_copy");
161                 }
162                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_paste");
163                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
164                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
165                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_save");
166                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_save_as");
167                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_run_script");
168                 uiPupMenuEnd(C, pup);
169         }
170         else {
171                 pup = uiPupMenuBegin(C, IFACE_("File"), ICON_NONE);
172                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
173                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
174                 uiPupMenuEnd(C, pup);
175         }
176 }
177
178 {
179         // Alt+Shift+E
180
181         uiPopupMenu *pup;
182
183         pup = uiPupMenuBegin(C, IFACE_("Edit"), ICON_NONE);
184         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_cut");
185         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_copy");
186         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_paste");
187         uiPupMenuEnd(C, pup);
188 }
189
190 {
191         // Alt+Shift+F
192
193         uiPopupMenu *pup;
194
195         if (text) {
196                 pup = uiPupMenuBegin(C, IFACE_("Text"), ICON_NONE);
197                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
198                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
199                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_save");
200                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_save_as");
201                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_run_script");
202                 uiPupMenuEnd(C, pup);
203         }
204         else {
205                 pup = uiPupMenuBegin(C, IFACE_("File"), ICON_NONE);
206                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
207                 uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
208                 uiPupMenuEnd(C, pup);
209         }
210 }
211
212 {
213         // Alt+Shift+V
214
215         uiPopupMenu *pup;
216
217         pup = uiPupMenuBegin(C, IFACE_("Text"), ICON_NONE);
218         uiItemEnumO(layout, "TEXT_OT_move", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Top of File"),
219                     0, "type", FILE_TOP);
220         uiItemEnumO(layout, "TEXT_OT_move", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Bottom of File"),
221                     0, "type", FILE_BOTTOM);
222         uiItemEnumO(layout, "TEXT_OT_move", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Page Up"), 0, "type", PREV_PAGE);
223         uiItemEnumO(layout, "TEXT_OT_move", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Page Down"),
224                     0, "type", NEXT_PAGE);
225         uiPupMenuEnd(C, pup);
226 }
227 #endif
228