本文整理匯總了TypeScript中@jupyterlab/apputils.ICommandPalette.addItem方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ICommandPalette.addItem方法的具體用法?TypeScript ICommandPalette.addItem怎麽用?TypeScript ICommandPalette.addItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@jupyterlab/apputils.ICommandPalette
的用法示例。
在下文中一共展示了ICommandPalette.addItem方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: MainMenu
activate: (app: JupyterLab, palette: ICommandPalette): IMainMenu => {
let menu = new MainMenu(app.commands);
menu.id = 'jp-MainMenu';
let logo = new Widget();
logo.addClass('jp-MainAreaPortraitIcon');
logo.addClass('jp-JupyterIcon');
logo.id = 'jp-MainLogo';
// Create the application menus.
createEditMenu(app, menu.editMenu);
createFileMenu(app, menu.fileMenu);
createKernelMenu(app, menu.kernelMenu);
createRunMenu(app, menu.runMenu);
createSettingsMenu(app, menu.settingsMenu);
createViewMenu(app, menu.viewMenu);
createTabsMenu(app, menu.tabsMenu);
palette.addItem({
command: CommandIDs.shutdownAllKernels,
category: 'Kernel Operations'
});
palette.addItem({
command: CommandIDs.activatePreviouslyUsedTab,
category: 'Main Area'
});
app.shell.addToTopArea(logo);
app.shell.addToTopArea(menu);
return menu;
}
示例2: addCommands
/**
* Add the main application commands.
*/
function addCommands(app: JupyterLab, palette: ICommandPalette): void {
const category = 'Main Area';
let command = CommandIDs.activateNextTab;
app.commands.addCommand(command, {
label: 'Activate Next Tab',
execute: () => { app.shell.activateNextTab(); }
});
palette.addItem({ command, category });
command = CommandIDs.activatePreviousTab;
app.commands.addCommand(command, {
label: 'Activate Previous Tab',
execute: () => { app.shell.activatePreviousTab(); }
});
palette.addItem({ command, category });
command = CommandIDs.closeAll;
app.commands.addCommand(command, {
label: 'Close All Widgets',
execute: () => { app.shell.closeAll(); }
});
palette.addItem({ command, category });
command = CommandIDs.setMode;
app.commands.addCommand(command, {
isVisible: args => {
const mode = args['mode'] as string;
return mode === 'single-document' || mode === 'multiple-document';
},
execute: args => {
const mode = args['mode'] as string;
if (mode === 'single-document' || mode === 'multiple-document') {
app.shell.mode = mode;
return;
}
throw new Error(`Unsupported application shell mode: ${mode}`);
}
});
command = CommandIDs.toggleMode;
app.commands.addCommand(command, {
label: 'Toggle Single-Document Mode',
execute: () => {
const args = app.shell.mode === 'multiple-document' ?
{ mode: 'single-document' } : { mode: 'multiple-document' };
return app.commands.execute(CommandIDs.setMode, args);
}
});
palette.addItem({ command, category });
}
示例3: activate
/**
* Activate the launcher.
*/
function activate(app: JupyterLab, services: IServiceManager, palette: ICommandPalette, linker: ICommandLinker, restorer: ILayoutRestorer): ILauncher {
const { commands, shell } = app;
let model = new LauncherModel();
let widget = new LauncherWidget({ linker });
widget.model = model;
widget.id = 'launcher';
widget.title.label = 'Launcher';
// Let the application restorer track the launcher for restoration of
// application state (e.g. setting the launcher as the current side bar
// widget).
restorer.add(widget, 'launcher');
commands.addCommand(CommandIDs.show, {
label: 'Show Launcher',
execute: () => {
if (!widget.isAttached) {
shell.addToLeftArea(widget);
}
shell.activateById(widget.id);
}
});
palette.addItem({ command: CommandIDs.show, category: 'Help' });
shell.addToLeftArea(widget);
return model;
}
示例4: activate
/**
* Activate the launcher.
*/
function activate(app: JupyterLab, palette: ICommandPalette): ILauncher {
const { commands, shell } = app;
let model = new LauncherModel();
commands.addCommand(CommandIDs.create, {
label: 'New Launcher',
execute: (args: JSONObject) => {
let cwd = args['cwd'] ? String(args['cwd']) : '';
let id = `launcher-${Private.id++}`;
let callback = (item: Widget) => {
shell.addToMainArea(item, { ref: id });
shell.activateById(item.id);
};
let widget = new Launcher({ cwd, callback });
widget.model = model;
widget.id = id;
widget.title.label = 'Launcher';
widget.title.iconClass = 'jp-LauncherIcon';
widget.title.closable = true;
shell.addToMainArea(widget);
if (args['activate'] !== false) {
shell.activateById(widget.id);
}
}
});
palette.addItem({ command: CommandIDs.create, category: 'Launcher'});
return model;
}
示例5: InspectorManager
activate: (app: JupyterLab, palette: ICommandPalette, restorer: ILayoutRestorer): IInspector => {
const { commands, shell } = app;
const manager = new InspectorManager();
const category = 'Inspector';
const command = CommandIDs.open;
const label = 'Open Inspector';
const tracker = new InstanceTracker<InspectorPanel>({
namespace: 'inspector',
shell
});
/**
* Create and track a new inspector.
*/
function newInspectorPanel(): InspectorPanel {
const inspector = new InspectorPanel();
inspector.id = 'jp-inspector';
inspector.title.label = 'Inspector';
inspector.title.closable = true;
inspector.disposed.connect(() => {
if (manager.inspector === inspector) {
manager.inspector = null;
}
});
// Track the inspector.
tracker.add(inspector);
// Add the default inspector child items.
Private.defaultInspectorItems.forEach(item => { inspector.add(item); });
return inspector;
}
// Handle state restoration.
restorer.restore(tracker, {
command,
args: () => null,
name: () => 'inspector'
});
// Add command to registry and palette.
commands.addCommand(command, {
label,
execute: () => {
if (!manager.inspector || manager.inspector.isDisposed) {
manager.inspector = newInspectorPanel();
shell.addToMainArea(manager.inspector);
}
if (manager.inspector.isAttached) {
tracker.activate(manager.inspector);
}
}
});
palette.addItem({ command, category });
return manager;
}
示例6:
EXPORT_TO_FORMATS.forEach(exportToFormat => {
let args = {
format: exportToFormat['format'],
label: exportToFormat['label'],
isPalette: true
};
palette.addItem({ command: CommandIDs.exportToFormat, category, args });
});
示例7: each
each(registry.creators(), creator => {
const command = CommandIDs.createFrom;
const creatorName = creator.name;
const label = `New ${creatorName}`;
const args = { creatorName, label };
menu.insertItem(0, { args, command });
Private.creators.add(palette.addItem({ args, category, command }));
});
示例8: DisposableSet
let addCreator = (name: string) => {
let disposables = creatorCmds[name] = new DisposableSet();
let command = Private.commandForName(name);
disposables.add(commands.addCommand(command, {
execute: () => fbWidget.createFrom(name),
label: `New ${name}`
}));
disposables.add(palette.addItem({ command, category }));
};
示例9: activate
/* tslint:enable */
/**
* Activate the FAQ plugin.
*/
function activate(
app: JupyterFrontEnd,
rendermime: IRenderMimeRegistry,
palette: ICommandPalette | null,
restorer: ILayoutRestorer | null
): void {
const category = 'Help';
const command = CommandIDs.open;
const { commands, shell } = app;
const tracker = new InstanceTracker<MainAreaWidget>({ namespace: 'faq' });
// Handle state restoration.
if (restorer) {
restorer.restore(tracker, {
command,
args: () => JSONExt.emptyObject,
name: () => 'faq'
});
}
let createWidget = () => {
let content = rendermime.createRenderer('text/markdown');
const model = rendermime.createModel({
data: { 'text/markdown': SOURCE }
});
void content.renderModel(model);
content.addClass('jp-FAQ-content');
let widget = new MainAreaWidget({ content });
widget.addClass('jp-FAQ');
widget.title.label = 'FAQ';
return widget;
};
let widget: MainAreaWidget;
commands.addCommand(command, {
label: 'Open FAQ',
execute: () => {
if (!widget || widget.isDisposed) {
widget = createWidget();
}
if (!tracker.has(widget)) {
void tracker.add(widget);
shell.add(widget, 'main', { activate: false });
}
shell.activateById(widget.id);
}
});
if (palette) {
palette.addItem({ command, category });
}
}
示例10: activate
/**
* Activate the landing plugin.
*/
function activate(app: JupyterLab, linker: ICommandLinker, palette: ICommandPalette, services: IServiceManager, restorer: ILayoutRestorer): void {
const { commands, shell } = app;
const category = 'Help';
const command = CommandIDs.open;
const model = new LandingModel(services.terminals.isAvailable());
const tracker = new InstanceTracker<LandingWidget>({
namespace: 'landing',
shell
});
// Handle state restoration.
restorer.restore(tracker, {
command,
args: () => null,
name: () => 'landing'
});
let widget: LandingWidget;
function newWidget(): LandingWidget {
let widget = new LandingWidget(linker);
widget.model = model;
widget.id = 'landing-jupyterlab';
widget.title.label = 'Landing';
widget.title.closable = true;
widget.addClass(LANDING_CLASS);
tracker.add(widget);
return widget;
}
commands.addCommand(command, {
label: 'Open Landing',
execute: () => {
if (!widget || widget.isDisposed) {
widget = newWidget();
shell.addToMainArea(widget);
}
tracker.activate(widget);
}
});
palette.addItem({ category, command });
// Only create a landing page if there are no other tabs open.
app.restored.then(() => {
if (shell.isEmpty('main')) {
commands.execute(command, void 0);
}
});
}