Skip to content

Commit

Permalink
Merge pull request #3182 from ian-r-rose/menu-refactor
Browse files Browse the repository at this point in the history
Menu refactor
  • Loading branch information
jasongrout committed Nov 29, 2017
2 parents d2c117e + f753c32 commit d1193ab
Show file tree
Hide file tree
Showing 60 changed files with 3,199 additions and 819 deletions.
316 changes: 171 additions & 145 deletions docs/dependency-graph.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/scripts/graph-dependencies.js
Expand Up @@ -2,6 +2,7 @@ var childProcess = require('child_process');
var fs = require('fs-extra');
var glob = require('glob');
var path = require('path');
var url = require('url');

var basePath = path.resolve('..');
var baseUrl = 'https://github.com/jupyterlab/jupyterlab/tree/master/packages';
Expand Down Expand Up @@ -40,7 +41,7 @@ packages.forEach(function(packagePath) {
}

// Construct a URL to the package on GitHub.
var Url = path.join(baseUrl, path.basename(packagePath));
var Url = url.resolve(baseUrl, 'packages/'+path.basename(packagePath));

// Remove the '@jupyterlab' part of the name.
var name = '"'+data.name.split('/')[1] +'"';
Expand Down
5 changes: 5 additions & 0 deletions jupyterlab/package.json
Expand Up @@ -41,6 +41,8 @@
"@jupyterlab/json-extension": "^0.12.0",
"@jupyterlab/launcher": "^0.12.0",
"@jupyterlab/launcher-extension": "^0.12.0",
"@jupyterlab/mainmenu": "^0.1.0",
"@jupyterlab/mainmenu-extension": "^0.1.0",
"@jupyterlab/markdownviewer-extension": "^0.12.0",
"@jupyterlab/notebook": "^0.12.0",
"@jupyterlab/notebook-extension": "^0.12.0",
Expand Down Expand Up @@ -98,6 +100,7 @@
"@jupyterlab/imageviewer-extension": "",
"@jupyterlab/inspector-extension": "",
"@jupyterlab/launcher-extension": "",
"@jupyterlab/mainmenu-extension": "",
"@jupyterlab/markdownviewer-extension": "",
"@jupyterlab/notebook-extension": "",
"@jupyterlab/running-extension": "",
Expand Down Expand Up @@ -169,6 +172,8 @@
"@jupyterlab/json-extension": "../packages/json-extension",
"@jupyterlab/launcher": "../packages/launcher",
"@jupyterlab/launcher-extension": "../packages/launcher-extension",
"@jupyterlab/mainmenu": "../packages/mainmenu",
"@jupyterlab/mainmenu-extension": "../packages/mainmenu-extension",
"@jupyterlab/markdownviewer-extension": "../packages/markdownviewer-extension",
"@jupyterlab/notebook": "../packages/notebook",
"@jupyterlab/notebook-extension": "../packages/notebook-extension",
Expand Down
6 changes: 6 additions & 0 deletions packages/application-extension/src/index.ts
Expand Up @@ -47,6 +47,12 @@ const main: JupyterLabPlugin<void> = {
activate: (app: JupyterLab, palette: ICommandPalette) => {
addCommands(app, palette);

// If the currently active widget changes,
// trigger a refresh of the commands.
app.shell.currentChanged.connect(() => {
app.commands.notifyCommandChanged(CommandIDs.closeAll);
});

let builder = app.serviceManager.builder;

let doBuild = () => {
Expand Down
31 changes: 2 additions & 29 deletions packages/apputils-extension/src/index.ts
Expand Up @@ -8,7 +8,7 @@ import {
} from '@jupyterlab/application';

import {
ICommandPalette, IMainMenu, MainMenu, IThemeManager, ThemeManager,
ICommandPalette, IThemeManager, ThemeManager,
ISplashScreen
} from '@jupyterlab/apputils';

Expand All @@ -28,10 +28,6 @@ import {
DisposableDelegate, IDisposable
} from '@phosphor/disposable';

import {
Widget
} from '@phosphor/widgets';

import {
activatePalette
} from './palette';
Expand Down Expand Up @@ -102,29 +98,6 @@ class SettingsConnector extends DataConnector<ISettingRegistry.IPlugin, string>
}


/**
* A service providing an interface to the main menu.
*/
const menu: JupyterLabPlugin<IMainMenu> = {
id: '@jupyterlab/apputils-extension:menu',
provides: IMainMenu,
activate: (app: JupyterLab): IMainMenu => {
let menu = new MainMenu();
menu.id = 'jp-MainMenu';

let logo = new Widget();
logo.addClass('jp-MainAreaPortraitIcon');
logo.addClass('jp-JupyterIcon');
logo.id = 'jp-MainLogo';

app.shell.addToTopArea(logo);
app.shell.addToTopArea(menu);

return menu;
}
};


/**
* The default commmand palette extension.
*/
Expand Down Expand Up @@ -231,7 +204,7 @@ const state: JupyterLabPlugin<IStateDB> = {
* Export the plugins as default.
*/
const plugins: JupyterLabPlugin<any>[] = [
menu, palette, settings, state, splash, themes
palette, settings, state, splash, themes
];
export default plugins;

Expand Down
1 change: 0 additions & 1 deletion packages/apputils/src/index.ts
Expand Up @@ -12,7 +12,6 @@ export * from './domutils';
export * from './hoverbox';
export * from './iframe';
export * from './instancetracker';
export * from './mainmenu';
export * from './sanitizer';
export * from './spinner';
export * from './splash';
Expand Down
1 change: 1 addition & 0 deletions packages/codemirror-extension/package.json
Expand Up @@ -36,6 +36,7 @@
"@jupyterlab/codemirror": "^0.12.0",
"@jupyterlab/coreutils": "^0.12.0",
"@jupyterlab/fileeditor": "^0.12.0",
"@jupyterlab/mainmenu": "^0.1.0",
"@phosphor/coreutils": "^1.3.0",
"@phosphor/widgets": "^1.5.0"
},
Expand Down
64 changes: 30 additions & 34 deletions packages/codemirror-extension/src/index.ts
Expand Up @@ -14,9 +14,13 @@ import {
} from '@jupyterlab/application';

import {
ICommandPalette, IMainMenu
ICommandPalette
} from '@jupyterlab/apputils';

import {
IMainMenu, IEditMenu
} from '@jupyterlab/mainmenu';

import {
IEditorServices
} from '@jupyterlab/codeeditor';
Expand All @@ -30,7 +34,7 @@ import {
} from '@jupyterlab/coreutils';

import {
IEditorTracker
IEditorTracker, FileEditor
} from '@jupyterlab/fileeditor';


Expand Down Expand Up @@ -146,18 +150,12 @@ function activateEditorCommands(app: JupyterLab, tracker: IEditorTracker, mainMe
}
});

// Update the command registry when the codemirror state changes.
tracker.currentChanged.connect(() => {
if (tracker.size <= 1) {
commands.notifyCommandChanged(CommandIDs.changeKeyMap);
}
});

/**
* A test for whether the tracker has an active widget.
*/
function hasWidget(): boolean {
return tracker.currentWidget !== null;
function isEnabled(): boolean {
return tracker.currentWidget !== null &&
tracker.currentWidget === app.shell.currentWidget;
}

/**
Expand Down Expand Up @@ -187,7 +185,7 @@ function activateEditorCommands(app: JupyterLab, tracker: IEditorTracker, mainMe
console.error(`Failed to set ${id}:${key} - ${reason.message}`);
});
},
isEnabled: hasWidget,
isEnabled,
isToggled: args => args['theme'] === theme
});

Expand All @@ -205,12 +203,12 @@ function activateEditorCommands(app: JupyterLab, tracker: IEditorTracker, mainMe
console.error(`Failed to set ${id}:${key} - ${reason.message}`);
});
},
isEnabled: hasWidget,
isEnabled,
isToggled: args => args['keyMap'] === keyMap
});

commands.addCommand(CommandIDs.find, {
label: 'Find',
label: 'Find...',
execute: () => {
let widget = tracker.currentWidget;
if (!widget) {
Expand All @@ -219,11 +217,11 @@ function activateEditorCommands(app: JupyterLab, tracker: IEditorTracker, mainMe
let editor = widget.editor as CodeMirrorEditor;
editor.execCommand('find');
},
isEnabled: hasWidget
isEnabled
});

commands.addCommand(CommandIDs.findAndReplace, {
label: 'Find & Replace',
label: 'Find & Replace...',
execute: () => {
let widget = tracker.currentWidget;
if (!widget) {
Expand All @@ -232,7 +230,7 @@ function activateEditorCommands(app: JupyterLab, tracker: IEditorTracker, mainMe
let editor = widget.editor as CodeMirrorEditor;
editor.execCommand('replace');
},
isEnabled: hasWidget
isEnabled
});

commands.addCommand(CommandIDs.changeMode, {
Expand All @@ -247,7 +245,7 @@ function activateEditorCommands(app: JupyterLab, tracker: IEditorTracker, mainMe
}
}
},
isEnabled: hasWidget,
isEnabled,
isToggled: args => {
let widget = tracker.currentWidget;
if (!widget) {
Expand Down Expand Up @@ -306,15 +304,10 @@ function activateEditorCommands(app: JupyterLab, tracker: IEditorTracker, mainMe
palette.addItem({ command, args, category: 'Editor' });
}

menu.addItem({ type: 'submenu', submenu: modeMenu });
menu.addItem({ command: 'fileeditor:toggle-autoclosing-brackets' });
menu.addItem({ type: 'submenu', submenu: tabMenu });
menu.addItem({ command: CommandIDs.find });
menu.addItem({ command: CommandIDs.findAndReplace });
menu.addItem({ type: 'separator' });
menu.addItem({ command: 'fileeditor:toggle-line-numbers' });
menu.addItem({ command: 'fileeditor:toggle-line-wrap' });
menu.addItem({ command: 'fileeditor:toggle-match-brackets' });
menu.addItem({ command: 'fileeditor:toggle-autoclosing-brackets' });
menu.addItem({ type: 'submenu', submenu: modeMenu });
menu.addItem({ type: 'submenu', submenu: keyMapMenu });
menu.addItem({ type: 'submenu', submenu: themeMenu });

Expand All @@ -323,13 +316,16 @@ function activateEditorCommands(app: JupyterLab, tracker: IEditorTracker, mainMe

mainMenu.addMenu(createMenu(), { rank: 30 });

[
'editor:line-numbers',
'editor:line-wrap',
'editor:match-brackets',
'editor-autoclosing-brackets',
'editor:create-console',
'editor:run-code'
].forEach(command => palette.addItem({ command, category: 'Editor' }));

// Add find-replace capabilities to the edit menu.
mainMenu.editMenu.findReplacers.set('Editor', {
tracker,
find: (widget: FileEditor) => {
let editor = widget.editor as CodeMirrorEditor;
editor.execCommand('find');
},
findAndReplace: (widget: FileEditor) => {
let editor = widget.editor as CodeMirrorEditor;
editor.execCommand('replace');
}
} as IEditMenu.IFindReplacer<FileEditor>)
}
5 changes: 3 additions & 2 deletions packages/console-extension/package.json
Expand Up @@ -34,10 +34,11 @@
"@jupyterlab/codeeditor": "^0.12.0",
"@jupyterlab/console": "^0.12.0",
"@jupyterlab/coreutils": "^0.12.0",
"@jupyterlab/filebrowser": "^0.12.1",
"@jupyterlab/launcher": "^0.12.0",
"@jupyterlab/mainmenu": "^0.1.0",
"@phosphor/algorithm": "^1.1.2",
"@phosphor/coreutils": "^1.3.0",
"@phosphor/widgets": "^1.5.0"
"@phosphor/coreutils": "^1.3.0"
},
"devDependencies": {
"rimraf": "~2.6.2",
Expand Down

0 comments on commit d1193ab

Please sign in to comment.