diff --git a/bpy_speckle/operators/streams.py b/bpy_speckle/operators/streams.py index 36ddb89..ac40b4a 100644 --- a/bpy_speckle/operators/streams.py +++ b/bpy_speckle/operators/streams.py @@ -33,7 +33,7 @@ ) from bpy_speckle.clients import speckle_clients from bpy_speckle.operators.users import LoadUserStreams, add_user_stream -from bpy_speckle.properties.scene import SpeckleSceneSettings, SpeckleStreamObject, SpeckleUserObject, get_speckle +from bpy_speckle.properties.scene import SpeckleSceneSettings, SpeckleStreamObject, SpeckleUserObject, get_speckle, selection_state from bpy_speckle.convert.util import ConversionSkippedException, add_to_hierarchy from specklepy.core.api.models import Commit from specklepy.core.api import operations, host_applications @@ -380,6 +380,11 @@ def send(self, context: Context) -> None: _report(f"Commit Created {sent_url}") + selection_state.selected_commit_id = COMMIT_ID + selection_state.selected_branch_id = branch.id + selection_state.selected_stream_id = stream.id + selection_state.selected_user_id = user.id + bpy.ops.speckle.load_user_streams() # refresh loaded commits context.view_layer.update() diff --git a/bpy_speckle/properties/scene.py b/bpy_speckle/properties/scene.py index a252692..9e4bbfa 100644 --- a/bpy_speckle/properties/scene.py +++ b/bpy_speckle/properties/scene.py @@ -42,6 +42,7 @@ def get_commits(self, context): def commit_update_hook(self, context: bpy.types.Context): selection_state.selected_commit_id = SelectionState.get_item_id_by_index(self.commits, self.commit) selection_state.selected_branch_id = self.id + # print(f"commit_update_hook: {selection_state.selected_commit_id=}, {selection_state.selected_branch_id=}") name: StringProperty(default="main") # type: ignore id: StringProperty(default="") # type: ignore @@ -95,6 +96,7 @@ def get_branches(self, context): def branch_update_hook(self, context: bpy.types.Context): selection_state.selected_branch_id = SelectionState.get_item_id_by_index(self.branches, self.branch) + # print(f"branch_update_hook: {selection_state.selected_branch_id=}, {selection_state.selected_stream_id=}") name: StringProperty(default="") # type: ignore description: StringProperty(default="") # type: ignore @@ -123,6 +125,7 @@ def fetch_stream_branches(self, context: bpy.types.Context, stream: SpeckleStrea def stream_update_hook(self, context: bpy.types.Context): stream = SelectionState.get_item_by_index(self.streams, self.active_stream) selection_state.selected_stream_id = stream.id + # print(f"stream_update_hook: {selection_state.selected_stream_id=}, {selection_state.selected_user_id=}") if len(stream.branches) == 0: # do not reload on selection, same as the old behavior self.fetch_stream_branches(context, stream) @@ -164,7 +167,7 @@ def get_users(self, context): for i, user in enumerate(USERS) ] - def set_user(self, context): + def user_update_hook(self, context): bpy.ops.speckle.load_user_streams() # type: ignore selection_state.selected_user_id = SelectionState.get_item_id_by_index(self.users, self.active_user) @@ -172,7 +175,7 @@ def set_user(self, context): items=get_users, name="Account", description="Select account", - update=set_user, + update=user_update_hook, get=None, set=None, ) # type: ignore @@ -200,7 +203,7 @@ def set_user(self, context): ) # type: ignore def get_active_user(self) -> Optional[SpeckleUserObject]: - if not self.active_user: + if self.active_user is None: return None selected_index = int(self.active_user) if 0 <= selected_index < len(self.users): @@ -282,17 +285,22 @@ def restore_selection_state(speckle: SpeckleSceneSettings) -> None: # Restore branch selection state if selection_state.selected_branch_id != None: (active_user, active_stream) = speckle.validate_stream_selection() + # print(f"restore_selection_state: {active_user.id=}, {active_stream.id=}") + # print(f"restore_selection_state: {selection_state.selected_user_id=}, {selection_state.selected_stream_id=}, {selection_state.selected_branch_id=}, {selection_state.selected_commit_id=}") is_same_user = active_user.id == selection_state.selected_user_id - is_same_stream = active_stream.id == selection_state.selected_stream_id - if is_same_user and is_same_stream: + if is_same_user: + active_user.active_stream = int(SelectionState.get_item_index_by_id(active_user.streams, selection_state.selected_stream_id)) + active_stream = SelectionState.get_item_by_index(active_user.streams, active_user.active_stream) if branch := SelectionState.get_item_index_by_id(active_stream.branches, selection_state.selected_branch_id): active_stream.branch = branch # Restore commit selection state if selection_state.selected_commit_id != None: (active_user, active_stream, active_branch) = speckle.validate_branch_selection() + # print(f"restore_selection_state: {active_user.id=}, {active_stream.id=}, {active_branch.id=}") + # print(f"restore_selection_state: {selection_state.selected_user_id=}, {selection_state.selected_stream_id=}, {selection_state.selected_branch_id=}, {selection_state.selected_commit_id=}") is_same_user = active_user.id == selection_state.selected_user_id is_same_stream = active_stream.id == selection_state.selected_stream_id