space_filebrowser.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. # <pep8 compliant>
  19. from bpy.types import Header, Panel, Menu, UIList
  20. class FILEBROWSER_HT_header(Header):
  21. bl_space_type = 'FILE_BROWSER'
  22. def draw(self, context):
  23. layout = self.layout
  24. st = context.space_data
  25. params = st.params
  26. if st.active_operator is None:
  27. layout.template_header()
  28. layout.menu("FILEBROWSER_MT_view")
  29. row = layout.row(align=True)
  30. row.operator("file.previous", text="", icon='BACK')
  31. row.operator("file.next", text="", icon='FORWARD')
  32. row.operator("file.parent", text="", icon='FILE_PARENT')
  33. row.operator("file.refresh", text="", icon='FILE_REFRESH')
  34. layout.operator_context = 'EXEC_DEFAULT'
  35. layout.operator("file.directory_new", icon='NEWFOLDER', text="")
  36. layout.operator_context = 'INVOKE_DEFAULT'
  37. # can be None when save/reload with a file selector open
  38. if params:
  39. is_lib_browser = params.use_library_browsing
  40. layout.prop(params, "display_type", expand=True, text="")
  41. layout.prop(params, "sort_method", expand=True, text="")
  42. layout.prop(params, "show_hidden", text="", icon='FILE_HIDDEN')
  43. layout.separator_spacer()
  44. layout.template_running_jobs()
  45. if params:
  46. layout.prop(params, "use_filter", text="", icon='FILTER')
  47. row = layout.row(align=True)
  48. row.active = params.use_filter
  49. row.prop(params, "use_filter_folder", text="")
  50. if params.filter_glob:
  51. # if st.active_operator and hasattr(st.active_operator, "filter_glob"):
  52. # row.prop(params, "filter_glob", text="")
  53. row.label(text=params.filter_glob)
  54. else:
  55. row.prop(params, "use_filter_blender", text="")
  56. row.prop(params, "use_filter_backup", text="")
  57. row.prop(params, "use_filter_image", text="")
  58. row.prop(params, "use_filter_movie", text="")
  59. row.prop(params, "use_filter_script", text="")
  60. row.prop(params, "use_filter_font", text="")
  61. row.prop(params, "use_filter_sound", text="")
  62. row.prop(params, "use_filter_text", text="")
  63. if is_lib_browser:
  64. row.prop(params, "use_filter_blendid", text="")
  65. if params.use_filter_blendid:
  66. row.separator()
  67. row.prop(params, "filter_id_category", text="")
  68. row.separator()
  69. row.prop(params, "filter_search", text="", icon='VIEWZOOM')
  70. class FILEBROWSER_UL_dir(UIList):
  71. def draw_item(self, _context, layout, _data, item, icon, _active_data, active_propname, _index):
  72. direntry = item
  73. # space = context.space_data
  74. icon = 'NONE'
  75. if active_propname == "system_folders_active":
  76. icon = 'DISK_DRIVE'
  77. if active_propname == "system_bookmarks_active":
  78. icon = 'BOOKMARKS'
  79. if active_propname == "bookmarks_active":
  80. icon = 'BOOKMARKS'
  81. if active_propname == "recent_folders_active":
  82. icon = 'FILE_FOLDER'
  83. if self.layout_type in {'DEFAULT', 'COMPACT'}:
  84. row = layout.row(align=True)
  85. row.enabled = direntry.is_valid
  86. # Non-editable entries would show grayed-out, which is bad in this specific case, so switch to mere label.
  87. if direntry.is_property_readonly("name"):
  88. row.label(text=direntry.name, icon=icon)
  89. else:
  90. row.prop(direntry, "name", text="", emboss=False, icon=icon)
  91. elif self.layout_type == 'GRID':
  92. layout.alignment = 'CENTER'
  93. layout.prop(direntry, "path", text="")
  94. class FILEBROWSER_PT_bookmarks_volumes(Panel):
  95. bl_space_type = 'FILE_BROWSER'
  96. bl_region_type = 'TOOLS'
  97. bl_options = {'DEFAULT_CLOSED'}
  98. bl_category = "Bookmarks"
  99. bl_label = "Volumes"
  100. def draw(self, context):
  101. layout = self.layout
  102. space = context.space_data
  103. if space.system_folders:
  104. row = layout.row()
  105. row.template_list("FILEBROWSER_UL_dir", "system_folders", space, "system_folders",
  106. space, "system_folders_active", item_dyntip_propname="path", rows=1, maxrows=10)
  107. class FILEBROWSER_PT_bookmarks_system(Panel):
  108. bl_space_type = 'FILE_BROWSER'
  109. bl_region_type = 'TOOLS'
  110. bl_category = "Bookmarks"
  111. bl_label = "System"
  112. @classmethod
  113. def poll(cls, context):
  114. return not context.preferences.filepaths.hide_system_bookmarks
  115. def draw(self, context):
  116. layout = self.layout
  117. space = context.space_data
  118. if space.system_bookmarks:
  119. row = layout.row()
  120. row.template_list("FILEBROWSER_UL_dir", "system_bookmarks", space, "system_bookmarks",
  121. space, "system_bookmarks_active", item_dyntip_propname="path", rows=1, maxrows=10)
  122. class FILEBROWSER_MT_bookmarks_context_menu(Menu):
  123. bl_label = "Bookmarks Specials"
  124. def draw(self, _context):
  125. layout = self.layout
  126. layout.operator("file.bookmark_cleanup", icon='X', text="Cleanup")
  127. layout.separator()
  128. layout.operator("file.bookmark_move", icon='TRIA_UP_BAR', text="Move To Top").direction = 'TOP'
  129. layout.operator("file.bookmark_move", icon='TRIA_DOWN_BAR', text="Move To Bottom").direction = 'BOTTOM'
  130. class FILEBROWSER_PT_bookmarks_favorites(Panel):
  131. bl_space_type = 'FILE_BROWSER'
  132. bl_region_type = 'TOOLS'
  133. bl_category = "Bookmarks"
  134. bl_label = "Favorites"
  135. def draw(self, context):
  136. layout = self.layout
  137. space = context.space_data
  138. if space.bookmarks:
  139. row = layout.row()
  140. num_rows = len(space.bookmarks)
  141. row.template_list("FILEBROWSER_UL_dir", "bookmarks", space, "bookmarks",
  142. space, "bookmarks_active", item_dyntip_propname="path",
  143. rows=(2 if num_rows < 2 else 4), maxrows=10)
  144. col = row.column(align=True)
  145. col.operator("file.bookmark_add", icon='ADD', text="")
  146. col.operator("file.bookmark_delete", icon='REMOVE', text="")
  147. col.menu("FILEBROWSER_MT_bookmarks_context_menu", icon='DOWNARROW_HLT', text="")
  148. if num_rows > 1:
  149. col.separator()
  150. col.operator("file.bookmark_move", icon='TRIA_UP', text="").direction = 'UP'
  151. col.operator("file.bookmark_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
  152. else:
  153. layout.operator("file.bookmark_add", icon='ADD')
  154. class FILEBROWSER_PT_bookmarks_recents(Panel):
  155. bl_space_type = 'FILE_BROWSER'
  156. bl_region_type = 'TOOLS'
  157. bl_category = "Bookmarks"
  158. bl_label = "Recents"
  159. @classmethod
  160. def poll(cls, context):
  161. return not context.preferences.filepaths.hide_recent_locations
  162. def draw(self, context):
  163. layout = self.layout
  164. space = context.space_data
  165. if space.recent_folders:
  166. row = layout.row()
  167. row.template_list("FILEBROWSER_UL_dir", "recent_folders", space, "recent_folders",
  168. space, "recent_folders_active", item_dyntip_propname="path", rows=1, maxrows=10)
  169. col = row.column(align=True)
  170. col.operator("file.reset_recent", icon='X', text="")
  171. class FILEBROWSER_PT_advanced_filter(Panel):
  172. bl_space_type = 'FILE_BROWSER'
  173. bl_region_type = 'TOOLS'
  174. bl_category = "Filter"
  175. bl_label = "Advanced Filter"
  176. @classmethod
  177. def poll(cls, context):
  178. # only useful in append/link (library) context currently...
  179. return context.space_data.params.use_library_browsing
  180. def draw(self, context):
  181. layout = self.layout
  182. space = context.space_data
  183. params = space.params
  184. if params and params.use_library_browsing:
  185. layout.prop(params, "use_filter_blendid")
  186. if params.use_filter_blendid:
  187. layout.separator()
  188. col = layout.column()
  189. col.prop(params, "filter_id")
  190. class FILEBROWSER_MT_view(Menu):
  191. bl_label = "View"
  192. def draw(self, context):
  193. layout = self.layout
  194. st = context.space_data
  195. params = st.params
  196. layout.prop(st, "show_region_toolbar")
  197. layout.prop(st, "show_region_ui", text="File Path")
  198. layout.separator()
  199. layout.prop_menu_enum(params, "display_size")
  200. layout.prop_menu_enum(params, "recursion_level")
  201. layout.separator()
  202. layout.menu("INFO_MT_area")
  203. classes = (
  204. FILEBROWSER_HT_header,
  205. FILEBROWSER_UL_dir,
  206. FILEBROWSER_PT_bookmarks_volumes,
  207. FILEBROWSER_PT_bookmarks_system,
  208. FILEBROWSER_MT_bookmarks_context_menu,
  209. FILEBROWSER_PT_bookmarks_favorites,
  210. FILEBROWSER_PT_bookmarks_recents,
  211. FILEBROWSER_PT_advanced_filter,
  212. FILEBROWSER_MT_view,
  213. )
  214. if __name__ == "__main__": # only for live edit.
  215. from bpy.utils import register_class
  216. for cls in classes:
  217. register_class(cls)