Welcome to mirror list, hosted at ThFree Co, Russian Federation.

goto_library.py « scene « amaranth - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 08f1689c32cc6f682a7216a6b83d0107e2ae8a61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
File Browser: Libraries Bookmark

The "Libraries" panel on the File Browser displays the path to all the
libraries linked to that .blend. So you can quickly go to the folders
related to the file.

Click on any path to go to that directory.
Developed during Caminandes Open Movie Project
"""

import bpy


class AMTH_FILE_PT_libraries(bpy.types.Panel):
    bl_space_type = "FILE_BROWSER"
    bl_region_type = "TOOLS"
    bl_category = "Bookmarks"
    bl_label = "Libraries"

    def draw(self, context):
        layout = self.layout

        libs = bpy.data.libraries
        libslist = []

        # Build the list of folders from libraries
        import os.path

        for lib in libs:
            directory_name = os.path.dirname(lib.filepath)
            libslist.append(directory_name)

        # Remove duplicates and sort by name
        libslist = set(libslist)
        libslist = sorted(libslist)

        # Draw the box with libs
        row = layout.row()
        box = row.box()

        if libslist:
            col = box.column()
            for filepath in libslist:
                if filepath != "//":
                    row = col.row()
                    row.alignment = "LEFT"
                    props = row.operator(
                        AMTH_FILE_OT_directory_go_to.bl_idname,
                        text=filepath, icon="BOOKMARKS",
                        emboss=False)
                    props.filepath = filepath
        else:
            box.label(text="No libraries loaded")


class AMTH_FILE_OT_directory_go_to(bpy.types.Operator):

    """Go to this library"s directory"""
    bl_idname = "file.directory_go_to"
    bl_label = "Go To"

    filepath: bpy.props.StringProperty(subtype="FILE_PATH")

    def execute(self, context):
        bpy.ops.file.select_bookmark(dir=self.filepath)
        return {"FINISHED"}


def register():
    bpy.utils.register_class(AMTH_FILE_PT_libraries)
    bpy.utils.register_class(AMTH_FILE_OT_directory_go_to)


def unregister():
    bpy.utils.unregister_class(AMTH_FILE_PT_libraries)
    bpy.utils.unregister_class(AMTH_FILE_OT_directory_go_to)