Moving classes to separate listing broke panel order
[blender-staging.git] / release / scripts / startup / bl_ui / space_filebrowser.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Header, Panel, Menu
22
23
24 class FILEBROWSER_HT_header(Header):
25     bl_space_type = 'FILE_BROWSER'
26
27     def draw(self, context):
28         layout = self.layout
29
30         st = context.space_data
31
32         layout.template_header()
33
34         row = layout.row()
35         row.separator()
36
37         row = layout.row(align=True)
38         row.operator("file.previous", text="", icon='BACK')
39         row.operator("file.next", text="", icon='FORWARD')
40         row.operator("file.parent", text="", icon='FILE_PARENT')
41         row.operator("file.refresh", text="", icon='FILE_REFRESH')
42
43         layout.separator()
44         layout.operator_context = 'EXEC_DEFAULT'
45         layout.operator("file.directory_new", icon='NEWFOLDER', text="")
46         layout.separator()
47
48         layout.operator_context = 'INVOKE_DEFAULT'
49         params = st.params
50
51         # can be None when save/reload with a file selector open
52         if params:
53             is_lib_browser = params.use_library_browsing
54
55             layout.prop(params, "recursion_level", text="")
56
57             layout.prop(params, "display_type", expand=True, text="")
58
59             layout.prop(params, "display_size", text="")
60
61             layout.prop(params, "sort_method", expand=True, text="")
62
63             layout.prop(params, "show_hidden", text="", icon='FILE_HIDDEN')
64             layout.prop(params, "use_filter", text="", icon='FILTER')
65
66             row = layout.row(align=True)
67             row.active = params.use_filter
68
69             row.prop(params, "use_filter_folder", text="")
70
71             if params.filter_glob:
72                 # if st.active_operator and hasattr(st.active_operator, "filter_glob"):
73                 #     row.prop(params, "filter_glob", text="")
74                 row.label(params.filter_glob)
75             else:
76                 row.prop(params, "use_filter_blender", text="")
77                 row.prop(params, "use_filter_backup", text="")
78                 row.prop(params, "use_filter_image", text="")
79                 row.prop(params, "use_filter_movie", text="")
80                 row.prop(params, "use_filter_script", text="")
81                 row.prop(params, "use_filter_font", text="")
82                 row.prop(params, "use_filter_sound", text="")
83                 row.prop(params, "use_filter_text", text="")
84
85             if is_lib_browser:
86                 row.prop(params, "use_filter_blendid", text="")
87                 if params.use_filter_blendid:
88                     row.separator()
89                     row.prop(params, "filter_id_category", text="")
90
91             row.separator()
92             row.prop(params, "filter_search", text="", icon='VIEWZOOM')
93
94         layout.template_running_jobs()
95
96
97 class FILEBROWSER_UL_dir(bpy.types.UIList):
98     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
99         direntry = item
100         # space = context.space_data
101         icon = 'NONE'
102         if active_propname == "system_folders_active":
103             icon = 'DISK_DRIVE'
104         if active_propname == "system_bookmarks_active":
105             icon = 'BOOKMARKS'
106         if active_propname == "bookmarks_active":
107             icon = 'BOOKMARKS'
108         if active_propname == "recent_folders_active":
109             icon = 'FILE_FOLDER'
110
111         if self.layout_type in {'DEFAULT', 'COMPACT'}:
112             row = layout.row(align=True)
113             row.enabled = direntry.is_valid
114             # Non-editable entries would show grayed-out, which is bad in this specific case, so switch to mere label.
115             if direntry.is_property_readonly("name"):
116                 row.label(text=direntry.name, icon=icon)
117             else:
118                 row.prop(direntry, "name", text="", emboss=False, icon=icon)
119
120         elif self.layout_type == 'GRID':
121             layout.alignment = 'CENTER'
122             layout.prop(direntry, "path", text="")
123
124
125 class FILEBROWSER_PT_system_folders(Panel):
126     bl_space_type = 'FILE_BROWSER'
127     bl_region_type = 'TOOLS'
128     bl_category = "Bookmarks"
129     bl_label = "System"
130
131     def draw(self, context):
132         layout = self.layout
133         space = context.space_data
134
135         if space.system_folders:
136             row = layout.row()
137             row.template_list("FILEBROWSER_UL_dir", "system_folders", space, "system_folders",
138                               space, "system_folders_active", item_dyntip_propname="path", rows=1, maxrows=10)
139
140
141 class FILEBROWSER_PT_system_bookmarks(Panel):
142     bl_space_type = 'FILE_BROWSER'
143     bl_region_type = 'TOOLS'
144     bl_category = "Bookmarks"
145     bl_label = "System Bookmarks"
146
147     @classmethod
148     def poll(cls, context):
149         return not context.user_preferences.filepaths.hide_system_bookmarks
150
151     def draw(self, context):
152         layout = self.layout
153         space = context.space_data
154
155         if space.system_bookmarks:
156             row = layout.row()
157             row.template_list("FILEBROWSER_UL_dir", "system_bookmarks", space, "system_bookmarks",
158                               space, "system_bookmarks_active", item_dyntip_propname="path", rows=1, maxrows=10)
159
160
161 class FILEBROWSER_MT_bookmarks_specials(Menu):
162     bl_label = "Bookmarks Specials"
163
164     def draw(self, context):
165         layout = self.layout
166         layout.operator("file.bookmark_cleanup", icon='X', text="Cleanup")
167
168         layout.separator()
169         layout.operator("file.bookmark_move", icon='TRIA_UP_BAR', text="Move To Top").direction = 'TOP'
170         layout.operator("file.bookmark_move", icon='TRIA_DOWN_BAR', text="Move To Bottom").direction = 'BOTTOM'
171
172
173 class FILEBROWSER_PT_bookmarks(Panel):
174     bl_space_type = 'FILE_BROWSER'
175     bl_region_type = 'TOOLS'
176     bl_category = "Bookmarks"
177     bl_label = "Bookmarks"
178
179     def draw(self, context):
180         layout = self.layout
181         space = context.space_data
182
183         if space.bookmarks:
184             row = layout.row()
185             num_rows = len(space.bookmarks)
186             row.template_list("FILEBROWSER_UL_dir", "bookmarks", space, "bookmarks",
187                               space, "bookmarks_active", item_dyntip_propname="path",
188                               rows=(2 if num_rows < 2 else 4), maxrows=10)
189
190             col = row.column(align=True)
191             col.operator("file.bookmark_add", icon='ZOOMIN', text="")
192             col.operator("file.bookmark_delete", icon='ZOOMOUT', text="")
193             col.menu("FILEBROWSER_MT_bookmarks_specials", icon='DOWNARROW_HLT', text="")
194
195             if num_rows > 1:
196                 col.separator()
197                 col.operator("file.bookmark_move", icon='TRIA_UP', text="").direction = 'UP'
198                 col.operator("file.bookmark_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
199         else:
200             layout.operator("file.bookmark_add", icon='ZOOMIN')
201
202
203 class FILEBROWSER_PT_recent_folders(Panel):
204     bl_space_type = 'FILE_BROWSER'
205     bl_region_type = 'TOOLS'
206     bl_category = "Bookmarks"
207     bl_label = "Recent"
208
209     @classmethod
210     def poll(cls, context):
211         return not context.user_preferences.filepaths.hide_recent_locations
212
213     def draw(self, context):
214         layout = self.layout
215         space = context.space_data
216
217         if space.recent_folders:
218             row = layout.row()
219             row.template_list("FILEBROWSER_UL_dir", "recent_folders", space, "recent_folders",
220                               space, "recent_folders_active", item_dyntip_propname="path", rows=1, maxrows=10)
221
222             col = row.column(align=True)
223             col.operator("file.reset_recent", icon='X', text="")
224
225
226 class FILEBROWSER_PT_advanced_filter(Panel):
227     bl_space_type = 'FILE_BROWSER'
228     bl_region_type = 'TOOLS'
229     bl_category = "Filter"
230     bl_label = "Advanced Filter"
231
232     @classmethod
233     def poll(cls, context):
234         # only useful in append/link (library) context currently...
235         return context.space_data.params.use_library_browsing
236
237     def draw(self, context):
238         layout = self.layout
239         space = context.space_data
240         params = space.params
241
242         if params and params.use_library_browsing:
243             layout.prop(params, "use_filter_blendid")
244             if params.use_filter_blendid:
245                 layout.separator()
246                 col = layout.column()
247                 col.prop(params, "filter_id")
248
249
250 classes = (
251     FILEBROWSER_HT_header,
252     FILEBROWSER_UL_dir,
253     FILEBROWSER_PT_system_folders,
254     FILEBROWSER_PT_system_bookmarks,
255     FILEBROWSER_MT_bookmarks_specials,
256     FILEBROWSER_PT_bookmarks,
257     FILEBROWSER_PT_recent_folders,
258     FILEBROWSER_PT_advanced_filter,
259 )
260
261 if __name__ == "__main__":  # only for live edit.
262     from bpy.utils import register_class
263     for cls in classes:
264         register_class(cls)