Skip to content

Commit

Permalink
[SHOT-3125] Context lost after loading a file in a newly created file (
Browse files Browse the repository at this point in the history
…#11)

* Removed save_file_as
* Reorganized OPEN FILE operations
* Remove open_file as new stage
* Added target parameter to open file
* Updated plugin
* Adjusted reset
* Made on stage selected
  • Loading branch information
000paradox000 authored Nov 13, 2019
1 parent 043d410 commit 5cf0167
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 157 deletions.
74 changes: 53 additions & 21 deletions engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ def __init__(self, tk, context, engine_instance_name, env):
self.alias_codename = None
self.alias_execpath = None
self.alias_bindir = None
self._stage_context = {}
self._dialog_parent = None

self.menu = None
self.operations = None
self._contexts_by_stage_name = {}
self._contexts_by_path = {}
self.running_operation = False
self.current_operation = None
self.parent_action = None

if not hasattr(sys, 'argv'):
sys.argv = ['']
Expand All @@ -49,6 +53,10 @@ def post_context_change(self, old_context, new_context):
"""
self.logger.debug("%s: Post context change...", self)
if self.context_change_allowed:
if not self.running_operation and \
self.current_operation == "prepare_new" and \
self.parent_action == "new_file":
self.save_context_for_stage_name(ctx=new_context)
self._create_menu()

def pre_app_init(self):
Expand Down Expand Up @@ -185,30 +193,54 @@ def _create_menu(self):

alias_api.create_menu(self.menu.options)

def stage_selected(self):
"""Stage was selected"""
self.logger.debug("Stage selected")
def _get_dialog_parent(self):
""" Get Alias dialog parent"""
return self._dialog_parent.get_dialog_parent()

def on_stage_selected(self):
"""An stage was selected."""
path = self.operations.get_current_path()
name = self.operations.get_current_stage()
current_context = self.context
current_operation = self.current_operation
parent_action = self.parent_action
running_operation = self.running_operation

if path:
self.logger.debug("Stage with path {} selected".format(path))
ctx = self.sgtk.context_from_path(path, self.context)

if not ctx.project:
self.logger.debug("The context is not valid with this path, project context selected".format(path))
ctx = self.sgtk.context_from_entity(self.context.project["type"], self.context.project["id"])
self.logger.debug("-" * 50)
self.logger.debug("Stage selected")
self.logger.debug("stage name: {}, path: {}, current_context: {}".format(name, path, current_context))
self.logger.debug("current_operation: {}, parent_action: {}, running_operation: {}".format(current_operation,
parent_action,
running_operation))
self.logger.debug("-" * 50)

if self.running_operation:
return

# No name and not path
if not name and not path:
return

# Known path
if path and path in self._contexts_by_path:
self.change_context(self._contexts_by_path[path])
# Known stage
elif name and name in self._contexts_by_stage_name:
self.change_context(self._contexts_by_stage_name[name])
else:
self.logger.debug("Empty Stage selected")
ctx = self.sgtk.context_from_entity(self.context.project["type"], self.context.project["id"])
self.change_context(self._get_project_context())

if ctx != sgtk.platform.current_engine().context:
self.change_context(ctx)
self.logger.debug("Context changed")
else:
self.logger.debug("Context not changed")
def save_context_for_path(self, path=None, ctx=None):
path = path or self.operations.get_current_path()

def _get_dialog_parent(self):
""" Get Alias dialog parent"""
return self._dialog_parent.get_dialog_parent()
if path:
self._contexts_by_path[path] = ctx or self.context

def save_context_for_stage_name(self, name=None, ctx=None):
name = name or self.operations.get_current_stage()
if name:
self._contexts_by_stage_name[name] = ctx or self.context

def _get_project_context(self):
return self.sgtk.context_from_entity(self.context.project["type"], self.context.project["id"])

4 changes: 2 additions & 2 deletions hooks/tk-multi-publish2/basic/alias_publish_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ def publish(self, settings, item):
# add dependencies for the base class to register when publishing
item.properties["publish_dependencies"] = self._obtain_references()

operations.save_file()
operations.save_file(operations.get_current_path())
super(AliasPublishFilePlugin, self).publish(settings, item)
self.logger.info("Saving new version")
operations.save_file_as(item.properties["next_version_path"])
operations.save_file(item.properties["next_version_path"])

def accept(self, settings, item):
"""
Expand Down
6 changes: 3 additions & 3 deletions hooks/tk-multi-publish2/basic/publish_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def validate(self, settings, item):
"label": "Save to v%s" % (version,),
"tooltip": "Save to the next available version number, "
"v%s" % (version,),
"callback": lambda: operations.save_file_as(next_version_path)
"callback": lambda: operations.save_file(next_version_path)
}
}
)
Expand Down Expand Up @@ -305,7 +305,7 @@ def publish(self, settings, item):
path = sgtk.util.ShotgunPath.normalize(_session_path())

# ensure the session is saved
operations.save_file_as(path)
operations.save_file(path)

# update the item with the saved session path
item.properties["path"] = path
Expand Down Expand Up @@ -334,7 +334,7 @@ def finalize(self, settings, item):
super(AliasSessionPublishPlugin, self).finalize(settings, item)

# bump the session file to the next version
self._save_to_next_version(item.properties["path"], item, operations.save_file_as)
self._save_to_next_version(item.properties["path"], item, operations.save_file)


def _alias_find_additional_session_dependencies():
Expand Down
4 changes: 2 additions & 2 deletions hooks/tk-multi-publish2/basic/start_version_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ def publish(self, settings, item):
path = sgtk.util.ShotgunPath.normalize(_session_path())

# ensure the session is saved in its current state
operations.save_file()
operations.save_file(operations.get_current_path())

# get the path to a versioned copy of the file.
version_path = publisher.util.get_version_path(path, "v001")

# save to the new version path
operations.save_file_as(version_path)
operations.save_file(version_path)
self.logger.info("A version number has been added to the Alias file...")
self.logger.info(" Alias file path: %s" % (version_path,))

Expand Down
6 changes: 3 additions & 3 deletions hooks/tk-multi-snapshot/basic/scene_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def execute(self, operation, file_path, **kwargs):
operations.open_file(file_path)

elif operation == "save":
operations.save_file()
operations.save_file(operations.get_current_path())

elif operation == "save_as":
operations.save_file_as(file_path)
operations.save_file(file_path)

elif operation == "reset":
if kwargs.get("parent_action", "") != "open_file":
operations.reset_scene()
operations.reset()

return True
2 changes: 1 addition & 1 deletion hooks/tk-multi-workfiles2/basic/custom_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ def execute_action(self, action, file, work_versions, publish_versions, context,
if not allowed_to_open:
return False

operations.open_file_as_new_stage(path)
operations.open_file(path, target=operations.OPEN_FILE_TARGET_NEW_STAGE)

return True
22 changes: 18 additions & 4 deletions hooks/tk-multi-workfiles2/basic/scene_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def execute(self, operation, file_path, context=None, parent_action=None, file_v

engine = self.parent.engine
operations = engine.operations
engine.running_operation = True
engine.current_operation = operation
engine.parent_action = parent_action

engine.logger.debug("tk-multi-workfiles2 scene_operation, "
"operation: {}, "
Expand All @@ -24,21 +27,32 @@ def execute(self, operation, file_path, context=None, parent_action=None, file_v
read_only))

if operation == "current_path":
engine.running_operation = False
return operations.get_current_path()

elif operation == "open":
operations.open_file(file_path)
engine.running_operation = False

elif operation == "save":
operations.save_file()
operations.save_file(operations.get_current_path())
engine.running_operation = False

elif operation == "save_as":
operations.save_file_as(file_path)
operations.save_file(file_path)
engine.running_operation = False

elif operation == "reset":
if parent_action == "new_file":
operations.create_new_file()
if operations.is_pristine():
operations.reset()
elif operations.want_to_delete_current_objects():
operations.reset()
elif parent_action != "open_file":
operations.reset_scene()
operations.reset()

engine.running_operation = False

return True
else:
engine.running_operation = False
Binary file modified plugins/shotgun.plugin
Binary file not shown.
Loading

0 comments on commit 5cf0167

Please sign in to comment.