|
@@ -1,7 +1,7 @@
|
|
|
// Copyright (c) Jupyter Development Team.
|
|
|
// Distributed under the terms of the Modified BSD License.
|
|
|
|
|
|
-import { each } from '@phosphor/algorithm';
|
|
|
+import { each, find } from '@phosphor/algorithm';
|
|
|
|
|
|
import { IDisposable } from '@phosphor/disposable';
|
|
|
|
|
@@ -32,9 +32,6 @@ import { ServerConnection } from '@jupyterlab/services';
|
|
|
* A namespace for command IDs of semantic extension points.
|
|
|
*/
|
|
|
export namespace CommandIDs {
|
|
|
- export const activatePreviouslyUsedTab =
|
|
|
- 'tabmenu:activate-previously-used-tab';
|
|
|
-
|
|
|
export const undo = 'editmenu:undo';
|
|
|
|
|
|
export const redo = 'editmenu:redo';
|
|
@@ -84,6 +81,11 @@ export namespace CommandIDs {
|
|
|
export const runAbove = 'runmenu:run-above';
|
|
|
|
|
|
export const runBelow = 'runmenu:run-below';
|
|
|
+
|
|
|
+ export const activateById = 'tabmenu:activate-by-id';
|
|
|
+
|
|
|
+ export const activatePreviouslyUsedTab =
|
|
|
+ 'tabmenu:activate-previously-used-tab';
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -636,31 +638,27 @@ export function createTabsMenu(app: JupyterLab, menu: TabsMenu): void {
|
|
|
// A disposable for getting rid of the out-of-date tabs list.
|
|
|
let disposable: IDisposable;
|
|
|
|
|
|
- // Utility function to create a command to activate
|
|
|
- // a given tab, or get it if it already exists.
|
|
|
- const createMenuItem = (widget: Widget): Menu.IItemOptions => {
|
|
|
- const commandID = `tabmenu:activate-${widget.id}`;
|
|
|
- if (!commands.hasCommand(commandID)) {
|
|
|
- commands.addCommand(commandID, {
|
|
|
- label: () => widget.title.label,
|
|
|
- isVisible: () => !widget.isDisposed,
|
|
|
- isEnabled: () => !widget.isDisposed,
|
|
|
- isToggled: () => app.shell.currentWidget === widget,
|
|
|
- execute: () => app.shell.activateById(widget.id)
|
|
|
- });
|
|
|
- }
|
|
|
- return { command: commandID };
|
|
|
- };
|
|
|
+ // Command to activate a widget by id.
|
|
|
+ commands.addCommand(CommandIDs.activateById, {
|
|
|
+ label: args => {
|
|
|
+ const id = args['id'] || '';
|
|
|
+ const widget = find(app.shell.widgets('main'), w => w.id === id);
|
|
|
+ return (widget && widget.title.label) || '';
|
|
|
+ },
|
|
|
+ isToggled: args => {
|
|
|
+ const id = args['id'] || '';
|
|
|
+ return app.shell.currentWidget && app.shell.currentWidget.id === id;
|
|
|
+ },
|
|
|
+ execute: args => app.shell.activateById((args['id'] as string) || '')
|
|
|
+ });
|
|
|
|
|
|
let previousId = '';
|
|
|
-
|
|
|
// Command to toggle between the current
|
|
|
// tab and the last modified tab.
|
|
|
commands.addCommand(CommandIDs.activatePreviouslyUsedTab, {
|
|
|
label: 'Activate Previously Used Tab',
|
|
|
isEnabled: () => !!previousId,
|
|
|
- execute: () =>
|
|
|
- previousId && app.commands.execute(`tabmenu:activate-${previousId}`)
|
|
|
+ execute: () => commands.execute(CommandIDs.activateById, { id: previousId })
|
|
|
});
|
|
|
|
|
|
app.restored.then(() => {
|
|
@@ -679,7 +677,10 @@ export function createTabsMenu(app: JupyterLab, menu: TabsMenu): void {
|
|
|
if (widget.id === previousId) {
|
|
|
isPreviouslyUsedTabAttached = true;
|
|
|
}
|
|
|
- tabGroup.push(createMenuItem(widget));
|
|
|
+ tabGroup.push({
|
|
|
+ command: CommandIDs.activateById,
|
|
|
+ args: { id: widget.id }
|
|
|
+ });
|
|
|
});
|
|
|
disposable = menu.addGroup(tabGroup, 1);
|
|
|
previousId = isPreviouslyUsedTabAttached ? previousId : '';
|