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