Add helpers for working with external files and docs
This commit is contained in:
parent
9d9fd57fe6
commit
7dc083e361
10 changed files with 114 additions and 4 deletions
62
__init__.py
62
__init__.py
|
|
@ -13,8 +13,10 @@
|
|||
|
||||
import bpy
|
||||
import os
|
||||
import webbrowser
|
||||
|
||||
from .tree import *
|
||||
from .api.tree import *
|
||||
from .preferences import GeometryScriptPreferences
|
||||
|
||||
# Set the `geometry_script` module to the current module in case the folder is named differently.
|
||||
import sys
|
||||
|
|
@ -42,13 +44,69 @@ class TEXT_MT_templates_geometryscript(bpy.types.Menu):
|
|||
filter_ext=lambda ext: (ext.lower() == ".py")
|
||||
)
|
||||
|
||||
class OpenDocumentation(bpy.types.Operator):
|
||||
bl_idname = "geometry_script.open_documentation"
|
||||
bl_label = "Open Documentation"
|
||||
|
||||
def execute(self, context):
|
||||
webbrowser.open('file://' + os.path.join(os.path.dirname(__file__), 'docs/documentation.html'))
|
||||
return {'FINISHED'}
|
||||
|
||||
class GeometryScriptSettings(bpy.types.PropertyGroup):
|
||||
auto_resolve: bpy.props.BoolProperty(name="Auto Resolve", default=False, description="If the file is edited externally, automatically accept the changes")
|
||||
|
||||
class GeometryScriptMenu(bpy.types.Menu):
|
||||
bl_idname = "TEXT_MT_geometryscript"
|
||||
bl_label = "Geometry Script"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
text = context.space_data.text
|
||||
if text and len(text.filepath) > 0:
|
||||
layout.prop(context.scene.geometry_script_settings, 'auto_resolve')
|
||||
layout.operator(OpenDocumentation.bl_idname)
|
||||
|
||||
def templates_menu_draw(self, context):
|
||||
self.layout.menu(TEXT_MT_templates_geometryscript.__name__)
|
||||
|
||||
def editor_header_draw(self, context):
|
||||
self.layout.menu(GeometryScriptMenu.bl_idname)
|
||||
|
||||
def auto_resolve():
|
||||
if bpy.context.scene.geometry_script_settings.auto_resolve:
|
||||
for area in bpy.context.screen.areas:
|
||||
for space in area.spaces:
|
||||
if space.type == 'NODE_EDITOR':
|
||||
with bpy.context.temp_override(area=area, space=space):
|
||||
text = bpy.context.space_data.text
|
||||
if text and text.is_modified:
|
||||
bpy.ops.text.resolve_conflict(resolution='RELOAD')
|
||||
return 1
|
||||
|
||||
def register():
|
||||
bpy.utils.register_class(TEXT_MT_templates_geometryscript)
|
||||
bpy.types.TEXT_MT_templates.append(templates_menu_draw)
|
||||
bpy.utils.register_class(GeometryScriptSettings)
|
||||
bpy.utils.register_class(GeometryScriptPreferences)
|
||||
bpy.utils.register_class(OpenDocumentation)
|
||||
bpy.utils.register_class(GeometryScriptMenu)
|
||||
|
||||
bpy.types.TEXT_HT_header.append(editor_header_draw)
|
||||
|
||||
bpy.types.Scene.geometry_script_settings = bpy.props.PointerProperty(type=GeometryScriptSettings)
|
||||
|
||||
bpy.app.timers.register(auto_resolve)
|
||||
|
||||
def unregister():
|
||||
bpy.utils.unregister_class(TEXT_MT_templates_geometryscript)
|
||||
bpy.types.TEXT_MT_templates.remove(templates_menu_draw)
|
||||
bpy.types.TEXT_MT_templates.remove(templates_menu_draw)
|
||||
bpy.utils.unregister_class(GeometryScriptSettings)
|
||||
bpy.utils.unregister_class(GeometryScriptPreferences)
|
||||
bpy.utils.unregister_class(OpenDocumentation)
|
||||
bpy.utils.unregister_class(GeometryScriptMenu)
|
||||
bpy.types.TEXT_HT_header.remove(editor_header_draw)
|
||||
try:
|
||||
bpy.app.timers.unregister(auto_resolve)
|
||||
except:
|
||||
pass
|
||||
Reference in a new issue