Another small text space usability: option to show right margin (aka print marign)
[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 #include "BLI_utildefines.h"
51
52 #include "BKE_context.h"
53
54 #include "ED_screen.h"
55
56 #include "WM_types.h"
57
58
59
60
61 #ifdef WITH_PYTHON
62 // XXX #include "BPY_menus.h"
63 #endif
64
65 #include "text_intern.h"
66
67 #define HEADER_PATH_MAX 260
68
69 /* ************************ header area region *********************** */
70
71 /************************** properties ******************************/
72
73 static ARegion *text_has_properties_region(ScrArea *sa)
74 {
75         ARegion *ar, *arnew;
76         
77         for(ar= sa->regionbase.first; ar; ar= ar->next)
78                 if(ar->regiontype==RGN_TYPE_UI)
79                         return ar;
80         
81         /* add subdiv level; after header */
82         for(ar= sa->regionbase.first; ar; ar= ar->next)
83                 if(ar->regiontype==RGN_TYPE_HEADER)
84                         break;
85         
86         /* is error! */
87         if(ar==NULL) return NULL;
88         
89         arnew= MEM_callocN(sizeof(ARegion), "properties region");
90         
91         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
92         arnew->regiontype= RGN_TYPE_UI;
93         arnew->alignment= RGN_ALIGN_LEFT;
94         
95         arnew->flag = RGN_FLAG_HIDDEN;
96         
97         return arnew;
98 }
99
100 static int properties_poll(bContext *C)
101 {
102         return (CTX_wm_space_text(C) != NULL);
103 }
104
105 static int properties_exec(bContext *C, wmOperator *UNUSED(op))
106 {
107         ScrArea *sa= CTX_wm_area(C);
108         ARegion *ar= text_has_properties_region(sa);
109         
110         if(ar)
111                 ED_region_toggle_hidden(C, ar);
112
113         return OPERATOR_FINISHED;
114 }
115
116 void TEXT_OT_properties(wmOperatorType *ot)
117 {
118         /* identifiers */
119         ot->name= "Properties";
120         ot->description= "Toggle text properties panel";
121         ot->idname= "TEXT_OT_properties";
122         
123         /* api callbacks */
124         ot->exec= properties_exec;
125         ot->poll= 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= uiPupMenuBegin(C, "Text", ICON_NULL);
138                 if(txt_has_sel(text)) {
139                         uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_cut");
140                         uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_copy");
141                 }
142                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_paste");
143                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_new");
144                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_open");
145                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_save");
146                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_save_as");
147                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_run_script");
148                 uiPupMenuEnd(C, pup);
149         }
150         else {
151                 pup= uiPupMenuBegin(C, "File", ICON_NULL);
152                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_new");
153                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_open");
154                 uiPupMenuEnd(C, pup);
155         }
156 }
157
158 {
159         // Alt+Shift+E
160
161         uiPopupMenu *pup;
162
163         pup= uiPupMenuBegin(C, "Edit", ICON_NULL);
164         uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_cut");
165         uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_copy");
166         uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_paste");
167         uiPupMenuEnd(C, pup);
168 }
169
170 {
171         // Alt+Shift+F
172
173         uiPopupMenu *pup;
174
175         if(text) {
176                 pup= uiPupMenuBegin(C, "Text", ICON_NULL);
177                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_new");
178                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_open");
179                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_save");
180                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_save_as");
181                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_run_script");
182                 uiPupMenuEnd(C, pup);
183         }
184         else {
185                 pup= uiPupMenuBegin(C, "File", ICON_NULL);
186                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_new");
187                 uiItemO(layout, NULL, ICON_NULL, "TEXT_OT_open");
188                 uiPupMenuEnd(C, pup);
189         }
190 }
191
192 {
193         // Alt+Shift+V
194
195         uiPopupMenu *pup;
196
197         pup= uiPupMenuBegin(C, "Text", ICON_NULL);
198         uiItemEnumO(layout, "TEXT_OT_move", "Top of File", 0, "type", FILE_TOP);
199         uiItemEnumO(layout, "TEXT_OT_move", "Bottom of File", 0, "type", FILE_BOTTOM);
200         uiItemEnumO(layout, "TEXT_OT_move", "Page Up", 0, "type", PREV_PAGE);
201         uiItemEnumO(layout, "TEXT_OT_move", "Page Down", 0, "type", NEXT_PAGE);
202         uiPupMenuEnd(C, pup);
203 }
204 #endif
205