Amaranth Addon
[blender-addons-contrib.git] / amaranth / scene / current_blend.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 > Go to Current Blend's Folder
16
17 For when you're lost browsing files and want to go back to the currently
18 open blend's directory. Look for it on the File Browser's header, only
19 shows up if the file is saved.
20 """
21
22 import bpy
23
24
25 class AMTH_FILE_OT_directory_current_blend(bpy.types.Operator):
26
27     """Go to the directory of the currently open blend file"""
28     bl_idname = "file.directory_current_blend"
29     bl_label = "Current Blend's Folder"
30
31     def execute(self, context):
32         bpy.ops.file.select_bookmark(dir="//")
33         return {"FINISHED"}
34
35
36 def button_directory_current_blend(self, context):
37     if bpy.data.filepath:
38         self.layout.operator(
39             AMTH_FILE_OT_directory_current_blend.bl_idname,
40             text="Current Blend's Folder",
41             icon="APPEND_BLEND")
42
43
44 def register():
45     bpy.utils.register_class(AMTH_FILE_OT_directory_current_blend)
46     bpy.types.FILEBROWSER_HT_header.append(button_directory_current_blend)
47
48
49 def unregister():
50     bpy.utils.unregister_class(AMTH_FILE_OT_directory_current_blend)
51     bpy.types.FILEBROWSER_HT_header.remove(button_directory_current_blend)