UI: File Browser bookmarks panels
[blender.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 from bpy.types import Header, Panel, Menu, UIList
21
22
23 class FILEBROWSER_HT_header(Header):
24     bl_space_type = 'FILE_BROWSER'
25
26     def draw(self, context):
27         layout = self.layout
28
29         st = context.space_data
30         params = st.params
31
32         if st.active_operator is None:
33             layout.template_header()
34
35         layout.menu("FILEBROWSER_MT_view")
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.operator_context = 'EXEC_DEFAULT'
44         layout.operator("file.directory_new", icon='NEWFOLDER', text="")
45
46         layout.operator_context = 'INVOKE_DEFAULT'
47
48         # can be None when save/reload with a file selector open
49         if params:
50             is_lib_browser = params.use_library_browsing
51
52             layout.prop(params, "display_type", expand=True, text="")
53             layout.prop(params, "sort_method", expand=True, text="")
54             layout.prop(params, "show_hidden", text="", icon='FILE_HIDDEN')
55
56         layout.separator_spacer()
57
58         layout.template_running_jobs()
59
60         if params:
61             layout.prop(params, "use_filter", text="", icon='FILTER')
62
63             row = layout.row(align=True)
64             row.active = params.use_filter
65             row.prop(params, "use_filter_folder", text="")
66
67             if params.filter_glob:
68                 # if st.active_operator and hasattr(st.active_operator, "filter_glob"):
69                 #     row.prop(params, "filter_glob", text="")
70                 row.label(text=params.filter_glob)
71             else:
72                 row.prop(params, "use_filter_blender", text="")
73                 row.prop(params, "use_filter_backup", text="")
74                 row.prop(params, "use_filter_image", text="")
75                 row.prop(params, "use_filter_movie", text="")
76                 row.prop(params, "use_filter_script", text="")
77                 row.prop(params, "use_filter_font", text="")
78                 row.prop(params, "use_filter_sound", text="")
79                 row.prop(params, "use_filter_text", text="")
80
81             if is_lib_browser:
82                 row.prop(params, "use_filter_blendid", text="")
83                 if params.use_filter_blendid:
84                     row.separator()
85                     row.prop(params, "filter_id_category", text="")
86
87             row.separator()
88             row.prop(params, "filter_search", text="", icon='VIEWZOOM')
89
90
91 class FILEBROWSER_UL_dir(UIList):
92     def draw_item(self, _context, layout, _data, item, icon, _active_data, active_propname, _index):
93         direntry = item
94         # space = context.space_data
95         icon = 'NONE'
96         if active_propname == "system_folders_active":
97             icon = 'DISK_DRIVE'
98         if active_propname == "system_bookmarks_active":
99             icon = 'BOOKMARKS'
100         if active_propname == "bookmarks_active":
101             icon = 'BOOKMARKS'
102         if active_propname == "recent_folders_active":
103             icon = 'FILE_FOLDER'
104
105         if self.layout_type in {'DEFAULT', 'COMPACT'}:
106             row = layout.row(align=True)
107             row.enabled = direntry.is_valid
108             # Non-editable entries would show grayed-out, which is bad in this specific case, so switch to mere label.
109             if direntry.is_property_readonly("name"):
110                 row.label(text=direntry.name, icon=icon)
111             else:
112                 row.prop(direntry, "name", text="", emboss=False, icon=icon)
113
114         elif self.layout_type == 'GRID':
115             layout.alignment = 'CENTER'
116             layout.prop(direntry, "path", text="")
117
118
119
120 class FILEBROWSER_PT_bookmarks(Panel):
121     bl_space_type = 'FILE_BROWSER'
122     bl_region_type = 'TOOLS'
123     bl_category = "Bookmarks"
124     bl_label = "Bookmarks"
125
126     def draw(self, context):
127         pass
128
129
130 class FILEBROWSER_PT_bookmarks_volumes(Panel):
131     bl_space_type = 'FILE_BROWSER'
132     bl_region_type = 'TOOLS'
133     bl_parent_id = "FILEBROWSER_PT_bookmarks"
134     bl_options = {'DEFAULT_CLOSED'}
135     bl_category = "Bookmarks"
136     bl_label = "Volumes"
137
138     def draw(self, context):
139         layout = self.layout
140         space = context.space_data
141
142         if space.system_folders:
143             row = layout.row()
144             row.template_list("FILEBROWSER_UL_dir", "system_folders", space, "system_folders",
145                               space, "system_folders_active", item_dyntip_propname="path", rows=1, maxrows=10)
146
147
148 class FILEBROWSER_PT_bookmarks_system(Panel):
149     bl_space_type = 'FILE_BROWSER'
150     bl_region_type = 'TOOLS'
151     bl_parent_id = "FILEBROWSER_PT_bookmarks"
152     bl_category = "Bookmarks"
153     bl_label = "System"
154
155     @classmethod
156     def poll(cls, context):
157         return not context.preferences.filepaths.hide_system_bookmarks
158
159     def draw(self, context):
160         layout = self.layout
161         space = context.space_data
162
163         if space.system_bookmarks:
164             row = layout.row()
165             row.template_list("FILEBROWSER_UL_dir", "system_bookmarks", space, "system_bookmarks",
166                               space, "system_bookmarks_active", item_dyntip_propname="path", rows=1, maxrows=10)
167
168
169 class FILEBROWSER_MT_bookmarks_context_menu(Menu):
170     bl_label = "Bookmarks Specials"
171
172     def draw(self, _context):
173         layout = self.layout
174         layout.operator("file.bookmark_cleanup", icon='X', text="Cleanup")
175
176         layout.separator()
177         layout.operator("file.bookmark_move", icon='TRIA_UP_BAR', text="Move To Top").direction = 'TOP'
178         layout.operator("file.bookmark_move", icon='TRIA_DOWN_BAR', text="Move To Bottom").direction = 'BOTTOM'
179
180
181 class FILEBROWSER_PT_bookmarks_favorites(Panel):
182     bl_space_type = 'FILE_BROWSER'
183     bl_region_type = 'TOOLS'
184     bl_parent_id = "FILEBROWSER_PT_bookmarks"
185     bl_category = "Bookmarks"
186     bl_label = "Favorites"
187
188     def draw(self, context):
189         layout = self.layout
190         space = context.space_data
191
192         if space.bookmarks:
193             row = layout.row()
194             num_rows = len(space.bookmarks)
195             row.template_list("FILEBROWSER_UL_dir", "bookmarks", space, "bookmarks",
196                               space, "bookmarks_active", item_dyntip_propname="path",
197                               rows=(2 if num_rows < 2 else 4), maxrows=10)
198
199             col = row.column(align=True)
200             col.operator("file.bookmark_add", icon='ADD', text="")
201             col.operator("file.bookmark_delete", icon='REMOVE', text="")
202             col.menu("FILEBROWSER_MT_bookmarks_context_menu", icon='DOWNARROW_HLT', text="")
203
204             if num_rows > 1:
205                 col.separator()
206                 col.operator("file.bookmark_move", icon='TRIA_UP', text="").direction = 'UP'
207                 col.operator("file.bookmark_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
208         else:
209             layout.operator("file.bookmark_add", icon='ADD')
210
211
212 class FILEBROWSER_PT_bookmarks_recents(Panel):
213     bl_space_type = 'FILE_BROWSER'
214     bl_region_type = 'TOOLS'
215     bl_parent_id = "FILEBROWSER_PT_bookmarks"
216     bl_category = "Bookmarks"
217     bl_options = {'DEFAULT_CLOSED'}
218     bl_label = "Recents"
219
220     @classmethod
221     def poll(cls, context):
222         return not context.preferences.filepaths.hide_recent_locations
223
224     def draw(self, context):
225         layout = self.layout
226         space = context.space_data
227
228         if space.recent_folders:
229             row = layout.row()
230             row.template_list("FILEBROWSER_UL_dir", "recent_folders", space, "recent_folders",
231                               space, "recent_folders_active", item_dyntip_propname="path", rows=1, maxrows=10)
232
233             col = row.column(align=True)
234             col.operator("file.reset_recent", icon='X', text="")
235
236
237 class FILEBROWSER_PT_advanced_filter(Panel):
238     bl_space_type = 'FILE_BROWSER'
239     bl_region_type = 'TOOLS'
240     bl_parent_id = "FILEBROWSER_PT_bookmarks"
241     bl_category = "Filter"
242     bl_label = "Advanced Filter"
243
244     @classmethod
245     def poll(cls, context):
246         # only useful in append/link (library) context currently...
247         return context.space_data.params.use_library_browsing
248
249     def draw(self, context):
250         layout = self.layout
251         space = context.space_data
252         params = space.params
253
254         if params and params.use_library_browsing:
255             layout.prop(params, "use_filter_blendid")
256             if params.use_filter_blendid:
257                 layout.separator()
258                 col = layout.column()
259                 col.prop(params, "filter_id")
260
261
262 class FILEBROWSER_MT_view(Menu):
263     bl_label = "View"
264
265     def draw(self, context):
266         layout = self.layout
267         st = context.space_data
268         params = st.params
269
270         layout.prop_menu_enum(params, "display_size")
271         layout.prop_menu_enum(params, "recursion_level")
272
273         layout.separator()
274
275         layout.menu("INFO_MT_area")
276
277
278 classes = (
279     FILEBROWSER_HT_header,
280     FILEBROWSER_UL_dir,
281     FILEBROWSER_PT_bookmarks,
282     FILEBROWSER_PT_bookmarks_volumes,
283     FILEBROWSER_PT_bookmarks_system,
284     FILEBROWSER_MT_bookmarks_context_menu,
285     FILEBROWSER_PT_bookmarks_favorites,
286     FILEBROWSER_PT_bookmarks_recents,
287     FILEBROWSER_PT_advanced_filter,
288     FILEBROWSER_MT_view,
289 )
290
291 if __name__ == "__main__":  # only for live edit.
292     from bpy.utils import register_class
293     for cls in classes:
294         register_class(cls)