Skip to content

Commit

Permalink
Implement _syncEditor in JupyterCadPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
arjxn-py committed Oct 9, 2024
1 parent 0c32b2a commit 021efa3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
2 changes: 0 additions & 2 deletions packages/base/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import { DocumentRegistry } from '@jupyterlab/docregistry';
import { PathExt } from '@jupyterlab/coreutils';
import { MainViewModel } from './3dview/mainviewmodel';
import { handleRemoveObject } from './panelview';
import { syncEditor } from './widget';

export function newName(type: string, model: IJupyterCadModel): string {
const sharedModel = model.sharedModel;
Expand Down Expand Up @@ -684,7 +683,6 @@ export function addCommands(
const trans = translator.load('jupyterlab');
const { commands } = app;
Private.updateFormSchema(formSchemaRegistry);
syncEditor(tracker);

commands.addCommand(CommandIDs.toggleConsole, {
label: trans.__('Toggle console'),
Expand Down
24 changes: 13 additions & 11 deletions packages/base/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ export class JupyterCadWidget
};
}

export function syncEditor(tracker: WidgetTracker<JupyterCadWidget>) {
tracker.currentChanged.connect(() => {
const currentWidget = tracker.currentWidget;

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

export class JupyterCadPanel extends SplitPanel {
constructor(options: JupyterCadPanel.IOptions) {
super({ orientation: 'vertical', spacing: 0 });
Expand All @@ -57,6 +46,7 @@ export class JupyterCadPanel extends SplitPanel {
this._initView();
this._consoleOption = consoleOption;
this._consoleTracker = consoleTracker;
this._syncEditor(options.tracker);
}

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

private _syncEditor(tracker: WidgetTracker<IJupyterCadWidget>) {
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 @@ -241,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

0 comments on commit 021efa3

Please sign in to comment.