Skip to content

Commit

Permalink
Change "Interface" menu to "Open in...", shorten names of menu items …
Browse files Browse the repository at this point in the history
…inside (#6847)

* rename commandLabel

* attemp to keep longer name in command palette

* Remove trying to keep longer name for command palette

* Attempt to register 2 commands to show the same command in the command palette

* fix passing paletteCommand to palette.addItem

* account for "args" being potentially passed to label

* change command palette wording to "Open in"

* capitalize "in" in "Open In..." btn title for consistency

* Make "in" not capitalized in "Open in..."

* use 'Open in %1' string formation form

* Update snapshots

* rename commandPaletteLabel into commandDescription

* use command with description as a label in view menu

* update snapshots manually

* update more snapshots manually

* Use isPalette and isMenu

* Lint

---------

Co-authored-by: Jeremy Tuloup <jeremy.tuloup@gmail.com>
  • Loading branch information
andrii-i and jtpio authored May 5, 2023
1 parent f4d2286 commit d7d110c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 14 deletions.
10 changes: 8 additions & 2 deletions packages/lab-extension/schema/interface-switcher.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
"items": [
{
"command": "jupyter-notebook:open-notebook",
"rank": 10
"rank": 10,
"args": {
"isMenu": true
}
},
{
"command": "jupyter-notebook:open-lab",
"rank": 10
"rank": 10,
"args": {
"isMenu": true
}
}
]
}
Expand Down
40 changes: 28 additions & 12 deletions packages/lab-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace CommandIDs {
interface ISwitcherChoice {
command: string;
commandLabel: string;
commandDescription: string;
buttonLabel: string;
urlPrefix: string;
}
Expand Down Expand Up @@ -78,7 +79,7 @@ const interfaceSwitcher: JupyterFrontEndPlugin<void> = {
};
const menubar = new MenuBar(overflowOptions);
const switcher = new Menu({ commands });
switcher.title.label = trans.__('Interface');
switcher.title.label = trans.__('Open in...');
switcher.title.icon = caretDownIcon;
menubar.addMenu(switcher);

Expand All @@ -90,22 +91,35 @@ const interfaceSwitcher: JupyterFrontEndPlugin<void> = {
};

const addInterface = (option: ISwitcherChoice) => {
const { command, commandLabel, urlPrefix } = option;
const { command, commandLabel, commandDescription, urlPrefix } = option;

const execute = () => {
const current = notebookTracker.currentWidget;
if (!current) {
return;
}
window.open(`${urlPrefix}${current.context.path}`);
};

commands.addCommand(command, {
label: (args) => (args.noLabel ? '' : commandLabel),
caption: commandLabel,
execute: () => {
const current = notebookTracker.currentWidget;
if (!current) {
return;
label: (args) => {
args.noLabel ? '' : commandLabel;
if (args.isMenu || args.isPalette) {
return commandDescription;
}
window.open(`${urlPrefix}${current.context.path}`);
return commandLabel;
},
caption: commandLabel,
execute,
isEnabled,
});

if (palette) {
palette.addItem({ command, category: 'Other' });
palette.addItem({
command,
category: 'Other',
args: { isPalette: true },
});
}

switcher.addItem({ command });
Expand All @@ -114,7 +128,8 @@ const interfaceSwitcher: JupyterFrontEndPlugin<void> = {
if (!notebookShell) {
addInterface({
command: CommandIDs.openNotebook,
commandLabel: trans.__('Open With %1', 'Jupyter Notebook'),
commandLabel: trans.__('Notebook'),
commandDescription: trans.__('Open in %1', 'Jupyter Notebook'),
buttonLabel: 'openNotebook',
urlPrefix: `${baseUrl}tree/`,
});
Expand All @@ -123,7 +138,8 @@ const interfaceSwitcher: JupyterFrontEndPlugin<void> = {
if (!labShell) {
addInterface({
command: CommandIDs.openLab,
commandLabel: trans.__('Open With %1', 'JupyterLab'),
commandLabel: trans.__('JupyterLab'),
commandDescription: trans.__('Open in %1', 'JupyterLab'),
buttonLabel: 'openLab',
urlPrefix: `${baseUrl}doc/tree/`,
});
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d7d110c

Please sign in to comment.