Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync editor upon editor change #448

Merged
merged 8 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
14 changes: 14 additions & 0 deletions packages/base/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { JupyterCadMainViewPanel } from './3dview';
import { MainViewModel } from './3dview/mainviewmodel';
import { ConsoleView } from './console';
import { AxeHelper, CameraSettings, ClipSettings, ExplodedView } from './types';
import { WidgetTracker } from '@jupyterlab/apputils';

export class JupyterCadWidget
extends DocumentWidget<JupyterCadPanel, IJupyterCadModel>
Expand Down Expand Up @@ -45,6 +46,7 @@ export class JupyterCadPanel extends SplitPanel {
this._initView();
this._consoleOption = consoleOption;
this._consoleTracker = consoleTracker;
this._syncEditor(options.tracker);
}

_initModel(options: {
Expand All @@ -67,6 +69,17 @@ export class JupyterCadPanel extends SplitPanel {
SplitPanel.setStretch(this._jupyterCadMainViewPanel, 1);
}

private _syncEditor(tracker: WidgetTracker<IJupyterCadWidget>) {
trungleduc marked this conversation as resolved.
Show resolved Hide resolved
tracker.currentChanged.connect(() => {
const currentWidget = tracker.currentWidget;

if (currentWidget) {
const resizeEvent = new Event('resize');
window.dispatchEvent(resizeEvent);
}
});
}

get jupyterCadMainViewPanel(): JupyterCadMainViewPanel {
return this._jupyterCadMainViewPanel;
}
Expand Down Expand Up @@ -229,5 +242,6 @@ export namespace JupyterCadPanel {
model: IJupyterCadModel;
workerRegistry: IJCadWorkerRegistry;
consoleTracker?: IConsoleTracker;
tracker: WidgetTracker<IJupyterCadWidget>;
}
}
9 changes: 5 additions & 4 deletions python/jupytercad_core/src/factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ConsolePanel, IConsoleTracker } from '@jupyterlab/console';
import {
JupyterCadModel,
IJupyterCadTracker,
IJCadWorkerRegistry,
IJCadExternalCommandRegistry
} from '@jupytercad/schema';
Expand All @@ -15,9 +14,10 @@ import {
ToolbarWidget
} from '@jupytercad/base';
import { ServiceManager } from '@jupyterlab/services';

import { WidgetTracker } from '@jupyterlab/apputils';
import { IJupyterCadWidget } from '@jupytercad/schema';
interface IOptions extends DocumentRegistry.IWidgetFactoryOptions {
tracker: IJupyterCadTracker;
tracker: WidgetTracker<IJupyterCadWidget>;
commands: CommandRegistry;
workerRegistry: IJCadWorkerRegistry;
externalCommandRegistry: IJCadExternalCommandRegistry;
Expand Down Expand Up @@ -66,7 +66,8 @@ export class JupyterCadWidgetFactory extends ABCWidgetFactory<
mimeTypeService: this.options.mimeTypeService,
rendermime: this.options.rendermime,
consoleTracker: this.options.consoleTracker,
commandRegistry: this.options.commands
commandRegistry: this.options.commands,
tracker: this.options.tracker
});
const toolbar = new ToolbarWidget({
commands: this._commands,
Expand Down
11 changes: 9 additions & 2 deletions python/jupytercad_lab/src/notebookrenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
IJCadWorkerRegistry,
IJCadWorkerRegistryToken,
IJupyterCadDoc,
IJupyterCadWidget,
JupyterCadModel
} from '@jupytercad/schema';

Expand All @@ -20,7 +21,7 @@ import {
IJupyterYWidgetManager,
JupyterYModel
} from 'yjs-widgets';

import { WidgetTracker } from '@jupyterlab/apputils';
export interface ICommMetadata {
create_ydoc: boolean;
path: string;
Expand All @@ -39,6 +40,7 @@ export class YJupyterCADLuminoWidget extends Panel {
constructor(options: {
model: JupyterCadModel;
workerRegistry: IJCadWorkerRegistry;
tracker: WidgetTracker<IJupyterCadWidget>;
}) {
super();

Expand Down Expand Up @@ -78,6 +80,10 @@ export const notebookRenderePlugin: JupyterFrontEndPlugin<void> = {
console.error('Missing ICollaborativeDrive token!');
return;
}

const tracker = new WidgetTracker<IJupyterCadWidget>({
namespace: 'jupytercad'
});
class YJupyterCADModelFactory extends YJupyterCADModel {
ydocFactory(commMetadata: ICommMetadata): Y.Doc {
const { path, format, contentType } = commMetadata;
Expand Down Expand Up @@ -105,7 +111,8 @@ export const notebookRenderePlugin: JupyterFrontEndPlugin<void> = {

const widget = new YJupyterCADLuminoWidget({
model: yModel.jupyterCADModel,
workerRegistry
workerRegistry,
tracker
});
// Widget.attach(widget, node);

Expand Down
Loading