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

Adds translator to the NotebookShell #6725

Merged
merged 3 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,19 @@ const treePathUpdater: JupyterFrontEndPlugin<ITreePathUpdater> = {
autoStart: true
};

const translator: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/application-extension:translator',
requires: [INotebookShell, ITranslator],
autoStart: true,
activate: (
app: JupyterFrontEnd,
notebookShell: INotebookShell,
translator: ITranslator
) => {
notebookShell.translator = translator;
}
};

/**
* Zen mode plugin
*/
Expand Down Expand Up @@ -920,6 +933,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
topVisibility,
tree,
treePathUpdater,
translator,
zen
];

Expand Down
20 changes: 14 additions & 6 deletions packages/application/src/panelhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ export class SidePanelHandler extends PanelHandler {
this._widgetPanel = new StackedPanel();
this._widgetPanel.widgetRemoved.connect(this._onWidgetRemoved, this);

const closeButton = document.createElement('button');
this._closeButton = document.createElement('button');
closeIcon.element({
container: closeButton,
container: this._closeButton,
height: '16px',
width: 'auto'
});
closeButton.onclick = () => {
this._closeButton.onclick = () => {
this.collapse();
this.hide();
};
closeButton.className = 'jp-Button jp-SidePanel-collapse';
closeButton.title = 'Collapse side panel';
this._closeButton.className = 'jp-Button jp-SidePanel-collapse';
this._closeButton.title = 'Collapse side panel';

const icon = new Widget({ node: closeButton });
const icon = new Widget({ node: this._closeButton });
this._panel.addWidget(icon);
this._panel.addWidget(this._widgetPanel);
}
Expand Down Expand Up @@ -150,6 +150,13 @@ export class SidePanelHandler extends PanelHandler {
return this._widgetRemoved;
}

/**
* Get the close button element.
*/
get closeButton(): HTMLButtonElement {
return this._closeButton;
}

/**
* Expand the sidebar.
*
Expand Down Expand Up @@ -283,6 +290,7 @@ export class SidePanelHandler extends PanelHandler {
private _widgetPanel: StackedPanel;
private _currentWidget: Widget | null;
private _lastCurrentWidget: Widget | null;
private _closeButton: HTMLButtonElement;
private _widgetAdded: Signal<SidePanelHandler, Widget> = new Signal(this);
private _widgetRemoved: Signal<SidePanelHandler, Widget> = new Signal(this);
}
Expand Down
23 changes: 23 additions & 0 deletions packages/application/src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { JupyterFrontEnd } from '@jupyterlab/application';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { ITranslator, nullTranslator } from '@jupyterlab/translation';

import { find } from '@lumino/algorithm';
import { PromiseDelegate, Token } from '@lumino/coreutils';
Expand Down Expand Up @@ -179,6 +180,27 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
return this._mainWidgetLoaded.promise;
}

/**
* Getter and setter for the translator.
*/
get translator(): ITranslator {
return this._translator ?? nullTranslator;
}
set translator(value: ITranslator) {
if (value !== this._translator) {
this._translator = value;
const trans = value.load('notebook');
this._leftHandler.closeButton.title = trans.__(
'Collapse %1 side panel',
this._leftHandler.area
);
this._rightHandler.closeButton.title = trans.__(
'Collapse %1 side panel',
this._rightHandler.area
);
}
}

/**
* Activate a widget in its area.
*/
Expand Down Expand Up @@ -324,6 +346,7 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
private _rightHandler: SidePanelHandler;
private _spacer: Widget;
private _main: Panel;
private _translator: ITranslator = nullTranslator;
private _currentChanged = new Signal<this, void>(this);
private _mainWidgetLoaded = new PromiseDelegate<void>();
}
Expand Down