本文整理汇总了TypeScript中@jupyterlab/apputils.IMainMenu.addMenu方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IMainMenu.addMenu方法的具体用法?TypeScript IMainMenu.addMenu怎么用?TypeScript IMainMenu.addMenu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@jupyterlab/apputils.IMainMenu
的用法示例。
在下文中一共展示了IMainMenu.addMenu方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: DocumentManager
activate: (app: JupyterLab, manager: IServiceManager, registry: IDocumentRegistry, palette: ICommandPalette, mainMenu: IMainMenu): IDocumentManager => {
const opener: DocumentManager.IWidgetOpener = {
open: widget => {
if (!widget.id) {
widget.id = `document-manager-${++Private.id}`;
}
if (!widget.isAttached) {
app.shell.addToMainArea(widget);
}
app.shell.activateById(widget.id);
}
};
const docManager = new DocumentManager({ registry, manager, opener });
let menu = createMenu(app, docManager, registry);
populateCreators(app, docManager, registry, palette, menu);
mainMenu.addMenu(menu, { rank: 1 });
// Register the file operations commands.
addCommands(app, docManager, registry, palette);
// Handle fileCreator items as they are added.
registry.changed.connect((sender, args) => {
if (args.type === 'fileCreator') {
menu.dispose();
menu = createMenu(app, docManager, registry);
populateCreators(app, docManager, registry, palette, menu);
mainMenu.addMenu(menu, { rank: 1 });
}
});
return docManager;
}
示例2: createMenu
registry.changed.connect((sender, args) => {
if (args.type === 'fileCreator') {
menu.dispose();
menu = createMenu(app, docManager, registry);
populateCreators(app, docManager, registry, palette, menu);
mainMenu.addMenu(menu, { rank: 1 });
}
});
示例3: addCreator
registry.changed.connect((sender, args) => {
if (args.type === 'fileCreator') {
menu.dispose();
let name = args.name;
if (args.change === 'added') {
addCreator(name);
} else {
creatorCmds[name].dispose();
delete creatorCmds[name];
}
menu = createMenu(app, Object.keys(creatorCmds));
mainMenu.addMenu(menu, { rank: 1 });
}
});
示例4: activateFileBrowser
/**
* Activate the default file browser in the sidebar.
*/
function activateFileBrowser(app: JupyterLab, factory: IFileBrowserFactory, docManager: IDocumentManager, mainMenu: IMainMenu, palette: ICommandPalette, restorer: ILayoutRestorer): void {
const fbWidget = factory.defaultBrowser;
// Let the application restorer track the primary file browser (that is
// automatically created) for restoration of application state (e.g. setting
// the file browser as the current side bar widget).
//
// All other file browsers created by using the factory function are
// responsible for their own restoration behavior, if any.
restorer.add(fbWidget, namespace);
addCommands(app, factory.tracker, fbWidget);
fbWidget.title.label = 'Files';
app.shell.addToLeftArea(fbWidget, { rank: 100 });
// If the layout is a fresh session without saved data, open file browser.
app.restored.then(layout => {
if (layout.fresh) {
app.commands.execute(CommandIDs.showBrowser, void 0);
}
});
// Create a launcher if there are no open items.
app.shell.layoutModified.connect(() => {
if (app.shell.isEmpty('main')) {
// Make sure the model is restored.
fbWidget.model.restored.then(() => {
app.commands.execute('launcher:create', {
cwd: fbWidget.model.path
});
});
}
});
let menu = createMenu(app);
mainMenu.addMenu(menu, { rank: 1 });
}
示例5: activateConsole
//.........这里部分代码省略.........
});
palette.addItem({ command, category });
command = CommandIDs.interrupt;
commands.addCommand(command, {
label: 'Interrupt Kernel',
execute: args => {
let current = getCurrent(args);
if (!current) {
return;
}
let kernel = current.console.session.kernel;
if (kernel) {
return kernel.interrupt();
}
}
});
palette.addItem({ command, category });
command = CommandIDs.restart;
commands.addCommand(command, {
label: 'Restart Kernel',
execute: args => {
let current = getCurrent(args);
if (!current) {
return;
}
return current.console.session.restart();
}
});
palette.addItem({ command, category });
command = CommandIDs.closeAndShutdown;
commands.addCommand(command, {
label: 'Close and Shutdown',
execute: args => {
let current = getCurrent(args);
if (!current) {
return;
}
return showDialog({
title: 'Shutdown the console?',
body: `Are you sure you want to close "${current.title.label}"?`,
buttons: [Dialog.cancelButton(), Dialog.warnButton()]
}).then(result => {
if (result.accept) {
current.console.session.shutdown().then(() => {
current.dispose();
});
} else {
return false;
}
});
}
});
command = CommandIDs.inject;
commands.addCommand(command, {
execute: (args: JSONObject) => {
let path = args['path'];
tracker.find(widget => {
if (widget.console.session.path === path) {
if (args['activate'] !== false) {
tracker.activate(widget);
}
widget.console.inject(args['code'] as string);
return true;
}
});
}
});
command = CommandIDs.switchKernel;
commands.addCommand(command, {
label: 'Switch Kernel',
execute: args => {
let current = getCurrent(args);
if (!current) {
return;
}
return current.console.session.selectKernel();
}
});
palette.addItem({ command, category });
menu.addItem({ command: CommandIDs.run });
menu.addItem({ command: CommandIDs.runForced });
menu.addItem({ command: CommandIDs.linebreak });
menu.addItem({ type: 'separator' });
menu.addItem({ command: CommandIDs.clear });
menu.addItem({ type: 'separator' });
menu.addItem({ command: CommandIDs.interrupt });
menu.addItem({ command: CommandIDs.restart });
menu.addItem({ command: CommandIDs.switchKernel });
menu.addItem({ type: 'separator' });
menu.addItem({ command: CommandIDs.closeAndShutdown });
mainMenu.addMenu(menu, {rank: 50});
return tracker;
}
示例6: activate
/**
* Activate the help handler extension.
*
* @param app - The phosphide application object.
*
* returns A promise that resolves when the extension is activated.
*/
function activate(app: JupyterLab, mainMenu: IMainMenu, palette: ICommandPalette, restorer: ILayoutRestorer): void {
let counter = 0;
const category = 'Help';
const namespace = 'help-doc';
const command = CommandIDs.open;
const menu = createMenu();
const { commands, shell } = app;
const tracker = new InstanceTracker<ClosableIFrame>({ namespace, shell });
// Handle state restoration.
restorer.restore(tracker, {
command,
args: widget => ({ url: widget.url, text: widget.title.label }),
name: widget => widget.url
});
/**
* Create a new ClosableIFrame widget.
*/
function newClosableIFrame(url: string, text: string): ClosableIFrame {
let iframe = new ClosableIFrame();
iframe.addClass(HELP_CLASS);
iframe.title.label = text;
iframe.title.closable = true;
iframe.id = `${namespace}-${++counter}`;
iframe.url = url;
tracker.add(iframe);
return iframe;
}
/**
* Create a menu for the help plugin.
*/
function createMenu(): Menu {
let { commands } = app;
let menu = new Menu({ commands });
menu.title.label = category;
menu.addItem({ command: 'about-jupyterlab:open' });
menu.addItem({ command: 'faq-jupyterlab:open' });
menu.addItem({ command: CommandIDs.launchClassic });
menu.addItem({ type: 'separator' });
RESOURCES.forEach(args => { menu.addItem({ args, command }); });
menu.addItem({ type: 'separator' });
menu.addItem({ command: 'statedb:clear' });
return menu;
}
commands.addCommand(command, {
label: args => args['text'] as string,
execute: args => {
const url = args['url'] as string;
const text = args['text'] as string;
// If help resource will generate a mixed content error, load externally.
if (LAB_IS_SECURE && URLExt.parse(url).protocol !== 'https:') {
window.open(url);
return;
}
let iframe = newClosableIFrame(url, text);
shell.addToMainArea(iframe);
tracker.activate(iframe);
}
});
commands.addCommand(CommandIDs.launchClassic, {
label: 'Launch Classic Notebook',
execute: () => { window.open(PageConfig.getBaseUrl() + 'tree'); }
});
RESOURCES.forEach(args => { palette.addItem({ args, command, category }); });
palette.addItem({ command: 'statedb:clear', category });
palette.addItem({ command: CommandIDs.launchClassic, category });
mainMenu.addMenu(menu);
}
示例7: activate
/**
* Activate the terminal plugin.
*/
function activate(app: JupyterLab, mainMenu: IMainMenu, palette: ICommandPalette, restorer: ILayoutRestorer, launcher: ILauncher | null): ITerminalTracker {
const { commands, serviceManager } = app;
const category = 'Terminal';
const namespace = 'terminal';
const tracker = new InstanceTracker<Terminal>({ namespace });
// Bail if there are no terminals available.
if (!serviceManager.terminals.isAvailable()) {
console.log('Disabling terminals plugin because they are not available on the server');
return tracker;
}
// Handle state restoration.
restorer.restore(tracker, {
command: CommandIDs.createNew,
args: widget => ({ name: widget.session.name }),
name: widget => widget.session && widget.session.name
});
// Update the command registry when the terminal state changes.
tracker.currentChanged.connect(() => {
if (tracker.size <= 1) {
commands.notifyCommandChanged(CommandIDs.refresh);
}
});
addCommands(app, serviceManager, tracker);
// Add command palette and menu items.
let menu = new Menu({ commands });
menu.title.label = category;
[
CommandIDs.createNew,
CommandIDs.refresh,
CommandIDs.increaseFont,
CommandIDs.decreaseFont,
CommandIDs.toggleTheme
].forEach(command => {
palette.addItem({ command, category });
if (command !== CommandIDs.createNew) {
menu.addItem({ command });
}
});
mainMenu.addMenu(menu, {rank: 40});
// Add a launcher item if the launcher is available.
if (launcher) {
launcher.add({
displayName: 'Terminal',
category: 'Other',
rank: 0,
iconClass: TERMINAL_ICON_CLASS,
callback: () => {
return commands.execute(CommandIDs.createNew);
}
});
}
app.contextMenu.addItem({command: CommandIDs.refresh, selector: '.jp-Terminal', rank: 1});
return tracker;
}
示例8: activateEditorCommands
/**
* Set up the editor widget menu and commands.
*/
function activateEditorCommands(app: JupyterLab, tracker: IEditorTracker, mainMenu: IMainMenu, palette: ICommandPalette): void {
let { commands } = app;
/**
* Toggle editor matching brackets
*/
function toggleMatchBrackets(): void {
if (tracker.currentWidget) {
let editor = tracker.currentWidget.editor;
if (editor instanceof CodeMirrorEditor) {
let cm = editor.editor;
cm.setOption('matchBrackets', !cm.getOption('matchBrackets'));
}
}
}
/**
* Toggle the editor's vim mode
*/
function toggleVim(): void {
tracker.forEach(widget => {
if (widget.editor instanceof CodeMirrorEditor) {
let cm = widget.editor.editor;
let keymap = cm.getOption('keyMap') === 'vim' ? 'default'
: 'vim';
cm.setOption('keyMap', keymap);
}
});
}
/**
* Create a menu for the editor.
*/
function createMenu(): Menu {
let theme = new Menu({ commands });
let menu = new Menu({ commands });
menu.title.label = 'Editor';
theme.title.label = 'Theme';
commands.addCommand(CommandIDs.changeTheme, {
label: args => args['theme'] as string,
execute: args => {
let name = args['theme'] as string || CodeMirrorEditor.DEFAULT_THEME;
tracker.forEach(widget => {
if (widget.editor instanceof CodeMirrorEditor) {
let cm = widget.editor.editor;
cm.setOption('theme', name);
}
});
}
});
[
'jupyter', 'default', 'abcdef', 'base16-dark', 'base16-light',
'hopscotch', 'material', 'mbo', 'mdn-like', 'seti', 'the-matrix',
'xq-light', 'zenburn'
].forEach(name => theme.addItem({
command: 'codemirror:change-theme',
args: { theme: name }
}));
menu.addItem({ command: 'editor:line-numbers' });
menu.addItem({ command: 'editor:line-wrap' });
menu.addItem({ command: CommandIDs.matchBrackets });
menu.addItem({ command: CommandIDs.vimMode });
menu.addItem({ type: 'separator' });
menu.addItem({ type: 'submenu', submenu: theme });
return menu;
}
mainMenu.addMenu(createMenu(), { rank: 30 });
commands.addCommand(CommandIDs.matchBrackets, {
execute: () => { toggleMatchBrackets(); },
label: 'Toggle Match Brackets',
});
commands.addCommand(CommandIDs.vimMode, {
execute: () => { toggleVim(); },
label: 'Toggle Vim Mode'
});
[
'editor:line-numbers',
'editor:line-wrap',
CommandIDs.matchBrackets,
CommandIDs.vimMode,
'editor:create-console',
'editor:run-code'
].forEach(command => palette.addItem({ command, category: 'Editor' }));
}
示例9: activateEditorCommands
//.........这里部分代码省略.........
});
commands.addCommand(CommandIDs.changeMode, {
label: args => args['name'] as string,
execute: args => {
let name = args['name'] as string;
let widget = tracker.currentWidget;
if (name && widget) {
let spec = Mode.findByName(name);
if (spec) {
widget.model.mimeType = spec.mime;
}
}
},
isEnabled: hasWidget,
isToggled: args => {
let widget = tracker.currentWidget;
if (!widget) {
return false;
}
let mime = widget.model.mimeType;
let spec = Mode.findByMIME(mime);
let name = spec && spec.name;
return args['name'] === name;
}
});
Mode.getModeInfo().sort((a, b) => {
let aName = a.name || '';
let bName = b.name || '';
return aName.localeCompare(bName);
}).forEach(spec => {
// Avoid mode name with a curse word.
if (spec.mode.indexOf('brainf') === 0) {
return;
}
modeMenu.addItem({
command: CommandIDs.changeMode,
args: {...spec}
});
});
[
'jupyter', 'default', 'abcdef', 'base16-dark', 'base16-light',
'hopscotch', 'material', 'mbo', 'mdn-like', 'seti', 'the-matrix',
'xq-light', 'zenburn'
].forEach(name => themeMenu.addItem({
command: CommandIDs.changeTheme,
args: { theme: name }
}));
['default', 'sublime', 'vim', 'emacs'].forEach(name => {
keyMapMenu.addItem({
command: CommandIDs.changeKeyMap,
args: { keyMap: name }
});
});
let args: JSONObject = {
insertSpaces: false, size: 4, name: 'Indent with Tab'
};
let command = 'fileeditor:change-tabs';
tabMenu.addItem({ command, args });
palette.addItem({ command, args, category: 'Editor' });
for (let size of [1, 2, 4, 8]) {
let args: JSONObject = {
insertSpaces: true, size, name: `Spaces: ${size} `
};
tabMenu.addItem({ command, args });
palette.addItem({ command, args, category: 'Editor' });
}
menu.addItem({ type: 'submenu', submenu: modeMenu });
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: keyMapMenu });
menu.addItem({ type: 'submenu', submenu: themeMenu });
return menu;
}
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' }));
}
示例10: activateFileBrowserMenu
/**
* Activate the default file browser menu in the main menu.
*/
function activateFileBrowserMenu(app: JupyterLab, mainMenu: IMainMenu): void {
let menu = createMenu(app);
mainMenu.addMenu(menu, { rank: 1 });
}