Refactor: Node Wrangler: PreviewNode operator
[blender-addons.git] / amaranth / scene / goto_library.py
blob8def91a38dd89323528e05bcbb6703755dcbcc6b
1 # SPDX-FileCopyrightText: 2019-2023 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 """
6 File Browser: Libraries Bookmark
8 The "Libraries" panel on the File Browser displays the path to all the
9 libraries linked to that .blend. So you can quickly go to the folders
10 related to the file.
12 Click on any path to go to that directory.
13 Developed during Caminandes Open Movie Project
14 """
16 import bpy
19 class AMTH_FILE_PT_libraries(bpy.types.Panel):
20 bl_space_type = "FILE_BROWSER"
21 bl_region_type = "TOOLS"
22 bl_category = "Bookmarks"
23 bl_label = "Libraries"
25 @classmethod
26 def poll(cls, context):
27 return context.area.ui_type == 'FILES'
29 def draw(self, context):
30 layout = self.layout
32 libs = bpy.data.libraries
33 libslist = []
35 # Build the list of folders from libraries
36 import os.path
38 for lib in libs:
39 directory_name = os.path.dirname(lib.filepath)
40 libslist.append(directory_name)
42 # Remove duplicates and sort by name
43 libslist = set(libslist)
44 libslist = sorted(libslist)
46 # Draw the box with libs
47 row = layout.row()
48 box = row.box()
50 if libslist:
51 col = box.column()
52 for filepath in libslist:
53 if filepath != "//":
54 row = col.row()
55 row.alignment = "LEFT"
56 props = row.operator(
57 AMTH_FILE_OT_directory_go_to.bl_idname,
58 text=filepath, icon="BOOKMARKS",
59 emboss=False)
60 props.filepath = filepath
61 else:
62 box.label(text="No libraries loaded")
65 class AMTH_FILE_OT_directory_go_to(bpy.types.Operator):
67 """Go to this library"s directory"""
68 bl_idname = "file.directory_go_to"
69 bl_label = "Go To"
71 filepath: bpy.props.StringProperty(subtype="FILE_PATH")
73 def execute(self, context):
74 bpy.ops.file.select_bookmark(dir=self.filepath)
75 return {"FINISHED"}
78 def register():
79 bpy.utils.register_class(AMTH_FILE_PT_libraries)
80 bpy.utils.register_class(AMTH_FILE_OT_directory_go_to)
83 def unregister():
84 bpy.utils.unregister_class(AMTH_FILE_PT_libraries)
85 bpy.utils.unregister_class(AMTH_FILE_OT_directory_go_to)