4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2009 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation, Andrea Weikert
26 * ***** END GPL LICENSE BLOCK *****
29 #include "BKE_context.h"
30 #include "BKE_screen.h"
32 #include "BLI_blenlib.h"
34 #include "DNA_screen_types.h"
35 #include "DNA_space_types.h"
36 #include "DNA_userdef_types.h"
37 #include "DNA_windowmanager_types.h"
39 #include "MEM_guardedalloc.h"
41 #include "RNA_access.h"
43 #include "UI_interface.h"
44 #include "UI_resources.h"
45 #include "UI_view2d.h"
47 #include "file_intern.h"
52 static void do_file_panel_events(bContext *C, void *arg, int event)
57 static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory category, int icon, int allow_delete)
60 uiStyle *style= U.uistyles.first;
62 int fontsize = file_font_pointsize();
63 struct FSMenu* fsmenu = fsmenu_get();
64 int nentries = fsmenu_get_nentries(fsmenu, category);
66 uiLayoutSetAlignment(pa->layout, UI_LAYOUT_ALIGN_LEFT);
67 block= uiLayoutFreeBlock(pa->layout);
68 uiBlockSetHandleFunc(block, do_file_panel_events, NULL);
69 uiBlockSetEmboss(block, UI_EMBOSSP);
70 uiBlockBeginAlign(block);
71 for (i=0; i< nentries;++i) {
72 uiLayout* layout = uiLayoutRow(pa->layout, UI_LAYOUT_ALIGN_LEFT);
73 char *fname = fsmenu_get_entry(fsmenu, category, i);
74 uiItemStringO(layout, fname, icon, "FILE_OT_select_bookmark", "dir", fname);
75 if (allow_delete && fsmenu_can_save(fsmenu, category, i) )
76 uiItemIntO(layout, "", ICON_X, "FILE_OT_delete_bookmark", "index", i);
78 uiBlockEndAlign(block);
81 static void file_panel_system(const bContext *C, Panel *pa)
83 file_panel_category(C, pa, FS_CATEGORY_SYSTEM, ICON_DISK_DRIVE, 0);
86 static void file_panel_bookmarks(const bContext *C, Panel *pa)
88 file_panel_category(C, pa, FS_CATEGORY_BOOKMARKS, ICON_BOOKMARKS, 1);
92 static void file_panel_recent(const bContext *C, Panel *pa)
94 file_panel_category(C, pa, FS_CATEGORY_RECENT, ICON_FILE_FOLDER, 0);
98 static void file_panel_operator(const bContext *C, Panel *pa)
100 SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
101 struct wmOperator *op = sfile ? sfile->op : NULL;
105 block= uiLayoutFreeBlock(pa->layout);
106 uiBlockSetHandleFunc(block, do_file_panel_events, NULL);
110 uiBlockBeginAlign(block);
111 RNA_STRUCT_BEGIN(op->ptr, prop) {
112 if(strcmp(RNA_property_identifier(prop), "rna_type") == 0)
114 if(strcmp(RNA_property_identifier(prop), "filename") == 0)
117 uiItemFullR(pa->layout, NULL, 0, op->ptr, prop, -1, 0, 0, 0, 0);
120 uiBlockEndAlign(block);
122 uiBlockLayoutResolve(C, block, NULL, &sy);
123 uiEndBlock(C, block);
124 uiDrawBlock(C, block);
128 void file_panels_register(ARegionType *art)
132 pt= MEM_callocN(sizeof(PanelType), "spacetype file system directories");
133 strcpy(pt->idname, "FILE_PT_system");
134 strcpy(pt->label, "System");
135 pt->draw= file_panel_system;
136 BLI_addtail(&art->paneltypes, pt);
138 pt= MEM_callocN(sizeof(PanelType), "spacetype file bookmarks");
139 strcpy(pt->idname, "FILE_PT_bookmarks");
140 strcpy(pt->label, "Bookmarks");
141 pt->draw= file_panel_bookmarks;
142 BLI_addtail(&art->paneltypes, pt);
144 pt= MEM_callocN(sizeof(PanelType), "spacetype file recent directories");
145 strcpy(pt->idname, "FILE_PT_recent");
146 strcpy(pt->label, "Recent");
147 pt->draw= file_panel_recent;
148 BLI_addtail(&art->paneltypes, pt);
150 pt= MEM_callocN(sizeof(PanelType), "spacetype file operator properties");
151 strcpy(pt->idname, "FILE_PT_operator");
152 strcpy(pt->label, "Operator");
153 pt->draw= file_panel_operator;
154 BLI_addtail(&art->paneltypes, pt);