Refactor: Node Wrangler: PreviewNode operator
[blender-addons.git] / amaranth / scene / current_blend.py
blobe0ad7a977110c0dceb5947ba7d45d05b8151d196
1 # SPDX-FileCopyrightText: 2019-2023 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 """
6 File Browser > Go to Current Blend's Folder
8 For when you're lost browsing files and want to go back to the currently
9 open blend's directory. Look for it on the File Browser's header, only
10 shows up if the file is saved.
11 """
13 import bpy
15 # From space_filebrowser.py
16 def panel_poll_is_upper_region(region):
17 # The upper region is left-aligned, the lower is split into it then.
18 # Note that after "Flip Regions" it's right-aligned.
19 return region.alignment in {'LEFT', 'RIGHT'}
22 class AMTH_FILE_OT_directory_current_blend(bpy.types.Operator):
24 """Go to the directory of the currently open blend file"""
25 bl_idname = "file.directory_current_blend"
26 bl_label = "Current Blend's Folder"
28 def execute(self, context):
29 bpy.ops.file.select_bookmark(dir="//")
30 return {"FINISHED"}
33 class FILEBROWSER_PT_amaranth(bpy.types.Panel):
34 bl_space_type = 'FILE_BROWSER'
35 bl_region_type = 'TOOLS'
36 bl_category = "Bookmarks"
37 bl_label = "Amaranth"
38 bl_options = {'HIDE_HEADER'}
40 @classmethod
41 def poll(cls, context):
42 return context.area.ui_type == 'FILES' and panel_poll_is_upper_region(context.region)
44 def draw(self, context):
45 layout = self.layout
46 layout.scale_x = 1.3
47 layout.scale_y = 1.3
49 if bpy.data.filepath:
50 row = layout.row()
51 flow = row.grid_flow(row_major=False, columns=0, even_columns=False, even_rows=False, align=True)
53 subrow = flow.row()
54 subsubrow = subrow.row(align=True)
55 subsubrow.operator(
56 AMTH_FILE_OT_directory_current_blend.bl_idname,
57 icon="DESKTOP")
60 classes = (
61 AMTH_FILE_OT_directory_current_blend,
62 FILEBROWSER_PT_amaranth
65 def register():
66 for cls in classes:
67 bpy.utils.register_class(cls)
69 def unregister():
70 for cls in classes:
71 bpy.utils.unregister_class(cls)