2 * header_script.c nov-2003
4 * Functions to draw the "Script Window" window header
5 * and handle user events sent to it.
9 * ***** BEGIN GPL LICENSE BLOCK *****
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
26 * All rights reserved.
28 * Contributor(s): Willian P. Germano.
30 * ***** END GPL LICENSE BLOCK *****
41 #include "BLI_blenlib.h"
43 #include "BSE_headerbuttons.h"
46 #include "DNA_screen_types.h"
47 #include "DNA_space_types.h"
49 #include "BIF_interface.h"
50 #include "BIF_resources.h"
51 #include "BIF_screen.h"
52 #include "BIF_space.h"
53 #include "BIF_toolbox.h"
54 #include "BKE_global.h"
55 #include "BKE_library.h"
58 #include "BSE_filesel.h"
60 #include "BPY_extern.h"
61 #include "BPY_menus.h"
66 #include "BLO_sys_types.h" // for intptr_t support
68 /* ********************** SCRIPT ****************************** */
70 /* action executed after clicking in Scripts menu */
71 static void do_scripts_submenus(void *int_arg, int event)
73 int menutype = (intptr_t)int_arg;
75 BPY_menu_do_python (menutype, event);
77 //allqueue(REDRAWSCRIPT, 0);
80 static uiBlock *script_scripts_submenus(void *int_menutype)
83 short yco = 20, menuwidth = 120;
85 int i = 0, menutype = (intptr_t)int_menutype;
87 if ((menutype < 0) || (menutype > PYMENU_SCRIPTS_MENU_TOTAL))
90 block= uiNewBlock(&curarea->uiblocks, "scriptsscriptssubmenus", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
91 uiBlockSetButmFunc(block, do_scripts_submenus, int_menutype);
93 for (pym = BPyMenuTable[menutype]; pym; pym = pym->next, i++) {
94 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i, pym->tooltip?pym->tooltip:pym->filename);
97 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
99 uiBlockSetDirection(block, UI_RIGHT);
100 uiTextBoundsBlock(block, 60);
105 static void do_script_scriptsmenu(void *arg, int event)
109 if(curarea->spacetype==SPACE_INFO) {
110 sa= closest_bigger_area();
114 /* these are no defines, easier this way, the codes are in the function below */
116 case 0: /* update menus */
117 if (BPY_path_update()==0) {
118 error("Invalid scripts dir: check console");
123 // allqueue(REDRAWSCRIPT, 0);
127 static uiBlock *script_scriptsmenu(void *arg_unused)
130 short yco = 0, menuwidth = 120;
133 block= uiNewBlock(&curarea->uiblocks, "script_scriptsmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
134 uiBlockSetButmFunc(block, do_script_scriptsmenu, NULL);
136 for (i = 0; i < PYMENU_SCRIPTS_MENU_TOTAL; i++) {
137 uiDefIconTextBlockBut(block, script_scripts_submenus, (void *)(intptr_t)i, ICON_RIGHTARROW_THIN, BPyMenu_group_itoa(i), 0, yco-=20, menuwidth, 19, "");
140 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
142 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Update Menus", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "Use when a scripts folder or its contents are modified");
144 if(curarea->headertype==HEADERTOP) {
145 uiBlockSetDirection(block, UI_DOWN);
148 uiBlockSetDirection(block, UI_TOP);
149 uiBlockFlipOrder(block);
152 uiTextBoundsBlock(block, 50);
156 void do_script_buttons(unsigned short event)
158 SpaceScript *sc= curarea->spacedata.first;
161 Script *script = sc->script;
164 if (sc->spacetype != SPACE_SCRIPT) return;
168 if (sc->menunr==-2) {
169 activate_databrowse((ID *)script, ID_SCR, 0, B_SCRIPTBROWSE,
170 &sc->menunr, do_script_buttons);
174 if(sc->menunr < 0) break;
179 idtest= G.main->script.first;
185 idtest= idtest->next;
188 sc->script= (Script *)idtest;
190 allqueue(REDRAWSCRIPT, 0);
191 allqueue(REDRAWHEADERS, 0);
196 BLI_remlink(&curarea->spacedata, sc);
197 BLI_addtail(&curarea->spacedata, sc);
198 sc = curarea->spacedata.first;
199 newspace(curarea, sc->spacetype);
207 void script_buttons(void)
210 SpaceScript *sc= curarea->spacedata.first;
214 if (!sc || sc->spacetype != SPACE_SCRIPT) return;
216 sprintf(naam, "header %d", curarea->headwin);
217 block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->headwin);
219 if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
220 else uiBlockSetCol(block, TH_HEADERDESEL);
222 curarea->butspacetype= SPACE_SCRIPT;
224 uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D,
225 windowtype_pup(), xco,0,XIC+10,YIC, &(curarea->butspacetype), 1.0,
226 SPACEICONMAX, 0, 0, "Displays Current Window Type. Click for menu"
227 " of available types.");
230 uiBlockSetEmboss(block, UI_EMBOSSN);
231 if(curarea->flag & HEADER_NO_PULLDOWN) {
232 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
234 &(curarea->flag), 0, 0, 0, 0, "Enables display of pulldown menus");
236 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
238 &(curarea->flag), 0, 0, 0, 0, "Hides pulldown menus");
240 uiBlockSetEmboss(block, UI_EMBOSS);
243 /* pull down menus */
244 if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
245 uiBlockSetEmboss(block, UI_EMBOSSP);
247 xmax= GetButStringLength("Scripts");
248 uiDefPulldownBut(block,script_scriptsmenu, NULL, "Scripts", xco, 0, xmax, 20, "");
252 uiBlockSetEmboss(block, UI_EMBOSS);
254 uiBlockBeginAlign(block);
255 uiDefIconBut(block, BUT, B_SCRIPT2PREV, ICON_GO_LEFT, xco+=XIC, 0, XIC, YIC,
256 0, 0, 0, 0, 0, "Returns to previous window");
260 uiDefIconBut(block, BUT,B_FULL, ICON_SPLITSCREEN, xco+=XIC,0,XIC,YIC, 0, 0,
261 0, 0, 0, "Returns to multiple views window (CTRL+Up arrow)");
263 uiDefIconBut(block, BUT,B_FULL, ICON_FULLSCREEN, xco+=XIC,0,XIC,YIC, 0, 0,
264 0, 0, 0, "Makes current window full screen (CTRL+Down arrow)");
265 uiBlockEndAlign(block);
267 /* STD SCRIPT BUTTONS */
269 xco= std_libbuttons(block, xco, 0, 0, NULL, B_SCRIPTBROWSE, ID_SCRIPT, 0, (ID*)sc->script, 0, &(sc->menunr), 0, 0, 0, 0, 0);
272 curarea->headbutlen= xco+2*XIC;
278 /* ********************** SCRIPT ****************************** */