Amaranth Addon
[blender-addons-contrib.git] / amaranth / scene / goto_library.py
1 #  This program is free software; you can redistribute it and/or
2 #  modify it under the terms of the GNU General Public License
3 #  as published by the Free Software Foundation; either version 2
4 #  of the License, or (at your option) any later version.
5 #
6 #  This program is distributed in the hope that it will be useful,
7 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
8 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9 #  GNU General Public License for more details.
10 #
11 #  You should have received a copy of the GNU General Public License
12 #  along with this program; if not, write to the Free Software Foundation,
13 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14 """
15 File Browser: Libraries Bookmark
16
17 The "Libraries" panel on the File Browser displays the path to all the
18 libraries linked to that .blend. So you can quickly go to the folders
19 related to the file.
20
21 Click on any path to go to that directory.
22 Developed during Caminandes Open Movie Project
23 """
24
25 import bpy
26
27
28 class AMTH_FILE_PT_libraries(bpy.types.Panel):
29     bl_space_type = "FILE_BROWSER"
30     bl_region_type = "TOOLS"
31     bl_category = "Bookmarks"
32     bl_label = "Libraries"
33
34     def draw(self, context):
35         layout = self.layout
36
37         libs = bpy.data.libraries
38         libslist = []
39
40         # Build the list of folders from libraries
41         import os.path
42
43         for lib in libs:
44             directory_name = os.path.dirname(lib.filepath)
45             libslist.append(directory_name)
46
47         # Remove duplicates and sort by name
48         libslist = set(libslist)
49         libslist = sorted(libslist)
50
51         # Draw the box with libs
52         row = layout.row()
53         box = row.box()
54
55         if libslist:
56             col = box.column()
57             for filepath in libslist:
58                 if filepath != "//":
59                     row = col.row()
60                     row.alignment = "LEFT"
61                     props = row.operator(
62                         AMTH_FILE_OT_directory_go_to.bl_idname,
63                         text=filepath, icon="BOOKMARKS",
64                         emboss=False)
65                     props.filepath = filepath
66         else:
67             box.label(text="No libraries loaded")
68
69
70 class AMTH_FILE_OT_directory_go_to(bpy.types.Operator):
71
72     """Go to this library"s directory"""
73     bl_idname = "file.directory_go_to"
74     bl_label = "Go To"
75
76     filepath = bpy.props.StringProperty(subtype="FILE_PATH")
77
78     def execute(self, context):
79         bpy.ops.file.select_bookmark(dir=self.filepath)
80         return {"FINISHED"}
81
82
83 def register():
84     bpy.utils.register_class(AMTH_FILE_PT_libraries)
85     bpy.utils.register_class(AMTH_FILE_OT_directory_go_to)
86
87
88 def unregister():
89     bpy.utils.unregister_class(AMTH_FILE_PT_libraries)
90     bpy.utils.unregister_class(AMTH_FILE_OT_directory_go_to)