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