Blender V2.61 - r43446

text_header.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2008 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * 
00022  * Contributor(s): Blender Foundation
00023  *
00024  * ***** END GPL LICENSE BLOCK *****
00025  */
00026 
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <stdio.h>
00035 
00036 /* file time checking */
00037 #include <ctype.h>
00038 #include <sys/types.h>
00039 #include <sys/stat.h>
00040 
00041 #ifndef _WIN32
00042 #include <unistd.h>
00043 #else
00044 #include <io.h>
00045 #include "BLI_winstuff.h"
00046 #endif
00047 
00048 #include "DNA_windowmanager_types.h"
00049 
00050 #include "MEM_guardedalloc.h"
00051 
00052 #include "BLI_blenlib.h"
00053 #include "BLI_utildefines.h"
00054 
00055 #include "BKE_context.h"
00056 #include "BKE_screen.h"
00057 
00058 #include "ED_screen.h"
00059 
00060 #include "WM_types.h"
00061 
00062 
00063 
00064 
00065 #ifdef WITH_PYTHON
00066 // XXX #include "BPY_menus.h"
00067 #endif
00068 
00069 #include "text_intern.h"
00070 
00071 #define HEADER_PATH_MAX 260
00072 
00073 /* ************************ header area region *********************** */
00074 
00075 /************************** properties ******************************/
00076 
00077 static ARegion *text_has_properties_region(ScrArea *sa)
00078 {
00079     ARegion *ar, *arnew;
00080 
00081     ar= BKE_area_find_region_type(sa, RGN_TYPE_UI);
00082     if(ar) return ar;
00083     
00084     /* add subdiv level; after header */
00085     ar= BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
00086 
00087     /* is error! */
00088     if(ar==NULL) return NULL;
00089     
00090     arnew= MEM_callocN(sizeof(ARegion), "properties region");
00091     
00092     BLI_insertlinkafter(&sa->regionbase, ar, arnew);
00093     arnew->regiontype= RGN_TYPE_UI;
00094     arnew->alignment= RGN_ALIGN_LEFT;
00095     
00096     arnew->flag = RGN_FLAG_HIDDEN;
00097     
00098     return arnew;
00099 }
00100 
00101 static int text_properties_poll(bContext *C)
00102 {
00103     return (CTX_wm_space_text(C) != NULL);
00104 }
00105 
00106 static int text_properties_exec(bContext *C, wmOperator *UNUSED(op))
00107 {
00108     ScrArea *sa= CTX_wm_area(C);
00109     ARegion *ar= text_has_properties_region(sa);
00110     
00111     if(ar)
00112         ED_region_toggle_hidden(C, ar);
00113 
00114     return OPERATOR_FINISHED;
00115 }
00116 
00117 void TEXT_OT_properties(wmOperatorType *ot)
00118 {
00119     /* identifiers */
00120     ot->name= "Properties";
00121     ot->description= "Toggle text properties panel";
00122     ot->idname= "TEXT_OT_properties";
00123     
00124     /* api callbacks */
00125     ot->exec= text_properties_exec;
00126     ot->poll= text_properties_poll;
00127 }
00128 
00129 /******************** XXX popup menus *******************/
00130 
00131 #if 0
00132 {
00133     // RMB
00134 
00135     uiPopupMenu *pup;
00136 
00137     if(text) {
00138         pup= uiPupMenuBegin(C, "Text", ICON_NONE);
00139         if(txt_has_sel(text)) {
00140             uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_cut");
00141             uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_copy");
00142         }
00143         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_paste");
00144         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
00145         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
00146         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_save");
00147         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_save_as");
00148         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_run_script");
00149         uiPupMenuEnd(C, pup);
00150     }
00151     else {
00152         pup= uiPupMenuBegin(C, "File", ICON_NONE);
00153         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
00154         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
00155         uiPupMenuEnd(C, pup);
00156     }
00157 }
00158 
00159 {
00160     // Alt+Shift+E
00161 
00162     uiPopupMenu *pup;
00163 
00164     pup= uiPupMenuBegin(C, "Edit", ICON_NONE);
00165     uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_cut");
00166     uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_copy");
00167     uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_paste");
00168     uiPupMenuEnd(C, pup);
00169 }
00170 
00171 {
00172     // Alt+Shift+F
00173 
00174     uiPopupMenu *pup;
00175 
00176     if(text) {
00177         pup= uiPupMenuBegin(C, "Text", ICON_NONE);
00178         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
00179         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
00180         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_save");
00181         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_save_as");
00182         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_run_script");
00183         uiPupMenuEnd(C, pup);
00184     }
00185     else {
00186         pup= uiPupMenuBegin(C, "File", ICON_NONE);
00187         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
00188         uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
00189         uiPupMenuEnd(C, pup);
00190     }
00191 }
00192 
00193 {
00194     // Alt+Shift+V
00195 
00196     uiPopupMenu *pup;
00197 
00198     pup= uiPupMenuBegin(C, "Text", ICON_NONE);
00199     uiItemEnumO(layout, "TEXT_OT_move", "Top of File", 0, "type", FILE_TOP);
00200     uiItemEnumO(layout, "TEXT_OT_move", "Bottom of File", 0, "type", FILE_BOTTOM);
00201     uiItemEnumO(layout, "TEXT_OT_move", "Page Up", 0, "type", PREV_PAGE);
00202     uiItemEnumO(layout, "TEXT_OT_move", "Page Down", 0, "type", NEXT_PAGE);
00203     uiPupMenuEnd(C, pup);
00204 }
00205 #endif
00206