Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/tree_clipper/src/tree_clipper/import_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,3 +696,7 @@ def import_all(self, parameters: ImportParameters) -> ImportReport:
while self.step():
pass
return self.importer.report


def preliminary_check(string: str) -> bool:
return string.startswith((MAGIC_STRING, "{"))
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ def draw_export_active(self, _context):
self.layout.operator(SCENE_OT_Tree_Clipper_Export_Active.bl_idname)


def draw_import(self, _context):
def draw_import(self, context):
if not SCENE_OT_Tree_Clipper_Import_Clipboard_Prepare.poll(context):
import_text = "Import Tree Clipper (Invalid Clipboard Content)"
else:
import_text = "Import Tree Clipper"

self.layout.operator(
SCENE_OT_Tree_Clipper_Import_Clipboard_Prepare.bl_idname,
text="Import Tree Clipper",
text=import_text,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
class SCENE_OT_Tree_Clipper_Export_Prepare(bpy.types.Operator):
bl_idname = "scene.tree_clipper_export_prepare"
bl_label = "Export"
bl_description = "Export the node tree as a Tree Clipper string."
bl_options: ClassVar[set[str]] = {"REGISTER"} # ty:ignore[invalid-attribute-override]

is_material: bpy.props.BoolProperty(name="Top level Material") # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

from ._vendor.tree_clipper.common import DEFAULT_FILE
from ._vendor.tree_clipper.dynamic_pointer import add_all_known_pointer_properties
from ._vendor.tree_clipper.import_nodes import ImportIntermediate, ImportParameters
from ._vendor.tree_clipper.import_nodes import (
ImportIntermediate,
ImportParameters,
preliminary_check,
)
from ._vendor.tree_clipper.specific_handlers import (
BUILT_IN_IMPORTER,
)
Expand All @@ -25,6 +29,7 @@
class SCENE_OT_Tree_Clipper_Import_File_Prepare(bpy.types.Operator):
bl_idname = "scene.tree_clipper_import_file_prepare"
bl_label = "Import File"
bl_description = "Import a Tree Clipper string from a file."
bl_options: ClassVar[set[str]] = {"REGISTER"} # ty:ignore[invalid-attribute-override]

input_file: bpy.props.StringProperty(
Expand Down Expand Up @@ -52,8 +57,13 @@ def execute(
class SCENE_OT_Tree_Clipper_Import_Clipboard_Prepare(bpy.types.Operator):
bl_idname = "scene.tree_clipper_import_clipboard_prepare"
bl_label = "Import Clipboard"
bl_description = "Import a Tree Clipper string from the clipboard."
bl_options: ClassVar[set[str]] = {"REGISTER"} # ty:ignore[invalid-attribute-override]

@classmethod
def poll(cls, context: bpy.types.Context) -> bool:
return preliminary_check(bpy.context.window_manager.clipboard) # ty:ignore[unresolved-attribute]

def execute(
self, context: bpy.types.Context
) -> set["rna_enums.OperatorReturnItems"]:
Expand Down
8 changes: 7 additions & 1 deletion packages/tree_clipper_addon/src/tree_clipper_addon/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,11 @@ def draw(self, context: bpy.types.Context) -> None:
self.layout.separator() # ty:ignore[possibly-missing-attribute]

import_col = self.layout.column() # ty:ignore[possibly-missing-attribute]
import_col.operator(SCENE_OT_Tree_Clipper_Import_Clipboard_Prepare.bl_idname)
if SCENE_OT_Tree_Clipper_Import_Clipboard_Prepare.poll(context):
import_text = SCENE_OT_Tree_Clipper_Import_Clipboard_Prepare.bl_label
else:
import_text = "Invalid Clipboard Content"
import_col.operator(
SCENE_OT_Tree_Clipper_Import_Clipboard_Prepare.bl_idname, text=import_text
)
import_col.operator(SCENE_OT_Tree_Clipper_Import_File_Prepare.bl_idname)
3 changes: 0 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading