Skip to content

Commit

Permalink
Update selected object between documents
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Oct 25, 2024
1 parent dc7af59 commit a4fda90
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
44 changes: 30 additions & 14 deletions packages/base/src/panelview/objectproperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,30 @@ class ObjectPropertiesReact extends React.Component<IProps, IStates> {
if (changed) {
this.props.cpModel.disconnect(this._sharedJcadModelChanged);
this.props.cpModel.disconnect(this._onClientSharedStateChanged);
const currentModel = changed.context.model;
currentModel.sharedObjectsChanged.connect(this._sharedJcadModelChanged);
const clients = currentModel.sharedModel.awareness.getStates() as Map<
number,
IJupyterCadClientState
>;

changed.context.model.sharedObjectsChanged.connect(
this._sharedJcadModelChanged
);
changed.context.model.clientStateChanged.connect(
this._onClientSharedStateChanged
this.setState(
old => ({
jcadOption: undefined,
selectedObjectData: undefined,
selectedObject: undefined,
schema: undefined,
filePath: changed.context.localPath,
jcadObject: this.props.cpModel.jcadModel?.getAllObject(),
clientId: currentModel.getClientId()
}),
() => {
this._onClientSharedStateChanged(currentModel, clients);
currentModel.clientStateChanged.connect(
this._onClientSharedStateChanged
);
}
);
this.setState(old => ({
jcadOption: undefined,
selectedObjectData: undefined,
selectedObject: undefined,
schema: undefined,
filePath: changed.context.localPath,
jcadObject: this.props.cpModel.jcadModel?.getAllObject(),
clientId: changed.context.model.getClientId()
}));
} else {
this.setState({
jcadOption: undefined,
Expand Down Expand Up @@ -251,6 +259,7 @@ class ObjectPropertiesReact extends React.Component<IProps, IStates> {
newState = localState;
}
}

if (newState) {
const selection = newState.selected.value;
const selectedObjectNames = Object.keys(selection || {});
Expand Down Expand Up @@ -294,6 +303,13 @@ class ObjectPropertiesReact extends React.Component<IProps, IStates> {
}));
}
}
} else {
this.setState(old => ({
...old,
schema: undefined,
selectedObject: '',
selectedObjectData: undefined
}));
}
};

Expand Down
7 changes: 5 additions & 2 deletions packages/base/src/panelview/rightpanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class RightPanelWidget extends SidePanel {
clients: Map<number, IJupyterCadClientState>
) => {
const localState = sender.localState;

if (!localState) {
return;
}
Expand All @@ -49,7 +48,6 @@ export class RightPanelWidget extends SidePanel {
} else if (localState.selected?.value) {
selection = localState.selected.value;
}

const selectionNames = Object.keys(selection);
if (selectionNames.length === 1) {
const selected = selectionNames[0];
Expand All @@ -73,6 +71,11 @@ export class RightPanelWidget extends SidePanel {

if (changed.context.model.sharedModel.editable) {
currentModel = changed.context.model;
const clients = currentModel.sharedModel.awareness.getStates() as Map<
number,
IJupyterCadClientState
>;
updateTitle(currentModel, clients);
currentModel.clientStateChanged.connect(updateTitle);

properties.show();
Expand Down

0 comments on commit a4fda90

Please sign in to comment.