Skip to content

Commit

Permalink
Adds translator to the NotebookShell
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Feb 9, 2023
1 parent 6e6ac27 commit 87fb953
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async function main() {
require('@jupyter-notebook/documentsearch-extension'),
require('@jupyter-notebook/help-extension'),
require('@jupyter-notebook/notebook-extension'),
require('@jupyter-notebook/translation-extension'),
// to handle opening new tabs after creating a new terminal
require('@jupyter-notebook/terminal-extension'),

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
57 changes: 57 additions & 0 deletions packages/translation-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@jupyter-notebook/translation-extension",
"version": "7.0.0-alpha.12",
"description": "Jupyter Notebook - Tree Extension",
"homepage": "https://github.com/jupyter/notebook",
"bugs": {
"url": "https://github.com/jupyter/notebook/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/jupyter/notebook.git"
},
"license": "BSD-3-Clause",
"author": "Project Jupyter",
"sideEffects": [
"style/**/*.css",
"style/index.js"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"style": "style/index.css",
"directories": {
"lib": "lib/"
},
"files": [
"lib/*.d.ts",
"lib/*.js.map",
"lib/*.js",
"schema/*.json",
"style/**/*.css",
"style/index.js"
],
"scripts": {
"build": "tsc -b",
"build:prod": "tsc -b",
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
"docs": "typedoc src",
"prepublishOnly": "npm run build",
"watch": "tsc -b --watch"
},
"dependencies": {
"@jupyter-notebook/application": "^7.0.0-alpha.12",
"@jupyterlab/translation": "^4.0.0-alpha.18"
},
"devDependencies": {
"rimraf": "^3.0.2",
"typescript": "~4.9.3"
},
"publishConfig": {
"access": "public"
},
"jupyterlab": {
"extension": true,
"schemaDir": "schema"
},
"styleModule": "style/index.js"
}
21 changes: 21 additions & 0 deletions packages/translation-extension/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { ITranslator } from '@jupyterlab/translation';
import { INotebookShell } from '@jupyter-notebook/application';

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

export default translator;
13 changes: 13 additions & 0 deletions packages/translation-extension/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfigbase",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"include": ["src/**/*"],
"references": [
{
"path": "../application"
}
]
}

0 comments on commit 87fb953

Please sign in to comment.