本文整理汇总了TypeScript中@jupyterlab/launcher.ILauncher.add方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ILauncher.add方法的具体用法?TypeScript ILauncher.add怎么用?TypeScript ILauncher.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@jupyterlab/launcher.ILauncher
的用法示例。
在下文中一共展示了ILauncher.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: DisposableSet
const onSpecsChanged = () => {
if (disposables) {
disposables.dispose();
disposables = null;
}
const specs = manager.specs;
if (!specs) {
return;
}
disposables = new DisposableSet();
let baseUrl = PageConfig.getBaseUrl();
for (let name in specs.kernelspecs) {
let rank = name === specs.default ? 0 : Infinity;
let kernelIconUrl = specs.kernelspecs[name].resources['logo-64x64'];
if (kernelIconUrl) {
let index = kernelIconUrl.indexOf('kernelspecs');
kernelIconUrl = baseUrl + kernelIconUrl.slice(index);
}
disposables.add(
launcher.add({
command: CommandIDs.create,
args: { isLauncher: true, kernelPreference: { name } },
category: 'Console',
rank,
kernelIconUrl
})
);
}
};
示例2:
manager.ready.then(() => {
const specs = manager.specs;
if (!specs) {
return;
}
let baseUrl = PageConfig.getBaseUrl();
for (let name in specs.kernelspecs) {
let displayName = specs.kernelspecs[name].display_name;
let rank = name === specs.default ? 0 : Infinity;
let kernelIconUrl = specs.kernelspecs[name].resources['logo-64x64'];
if (kernelIconUrl) {
let index = kernelIconUrl.indexOf('kernelspecs');
kernelIconUrl = baseUrl + kernelIconUrl.slice(index);
}
launcher.add({
displayName,
category: 'Console',
name,
iconClass: 'jp-CodeConsoleIcon',
callback,
rank,
kernelIconUrl
});
}
});
示例3: 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<MainAreaWidget<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.content.session.name }),
name: widget => widget.content.session && widget.content.session.name
});
addCommands(app, serviceManager, tracker);
// Add some commands to the application view menu.
const viewGroup = [
CommandIDs.increaseFont,
CommandIDs.decreaseFont,
CommandIDs.toggleTheme
].map(command => { return { command }; });
mainMenu.viewMenu.addGroup(viewGroup, 30);
// Add command palette items.
[
CommandIDs.createNew,
CommandIDs.refresh,
CommandIDs.increaseFont,
CommandIDs.decreaseFont,
CommandIDs.toggleTheme
].forEach(command => {
palette.addItem({ command, category, args: { 'isPalette': true } });
});
// Add terminal creation to the file menu.
mainMenu.fileMenu.newMenu.addGroup([{ command: CommandIDs.createNew }], 20);
// Add a launcher item if the launcher is available.
if (launcher) {
launcher.add({
displayName: 'Terminal',
category: 'Other',
rank: 0,
iconClass: TERMINAL_ICON_CLASS,
callback: () => commands.execute(CommandIDs.createNew)
});
}
app.contextMenu.addItem({command: CommandIDs.refresh, selector: '.jp-Terminal', rank: 1});
return tracker;
}
示例4: activate
/**
* Activate the editor tracker plugin.
*/
function activate(app: JupyterLab, registry: IDocumentRegistry, restorer: ILayoutRestorer, editorServices: IEditorServices, launcher: ILauncher | null): IEditorTracker {
const factory = new EditorWidgetFactory({
editorServices,
factoryOptions: {
name: FACTORY,
fileExtensions: ['*'],
defaultFor: ['*']
}
});
const shell = app.shell;
const tracker = new InstanceTracker<EditorWidget>({
namespace: 'editor',
shell
});
// Handle state restoration.
restorer.restore(tracker, {
command: 'file-operations:open',
args: widget => ({ path: widget.context.path, factory: FACTORY }),
name: widget => widget.context.path
});
factory.widgetCreated.connect((sender, widget) => {
widget.title.icon = EDITOR_ICON_CLASS;
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => { tracker.save(widget); });
tracker.add(widget);
});
registry.addWidgetFactory(factory);
addDefaultCommands(tracker, app.commands);
// Add a launcher item if the launcher is available.
if (launcher) {
launcher.add({
name: 'Text Editor',
command: 'filebrowser:new-text-file'
});
}
return tracker;
}
示例5:
services.ready.then(() => {
const specs = services.specs;
const baseUrl = PageConfig.getBaseUrl();
for (let name in specs.kernelspecs) {
let rank = name === specs.default ? 0 : Infinity;
let kernelIconUrl = specs.kernelspecs[name].resources['logo-64x64'];
if (kernelIconUrl) {
let index = kernelIconUrl.indexOf('kernelspecs');
kernelIconUrl = baseUrl + kernelIconUrl.slice(index);
}
launcher.add({
command: CommandIDs.createNew,
args: { isLauncher: true, kernelName: name },
category: 'Notebook',
rank,
kernelIconUrl
});
}
});
示例6:
manager.ready.then(() => {
const specs = manager.specs;
if (!specs) {
return;
}
let baseUrl = PageConfig.getBaseUrl();
for (let name in specs.kernelspecs) {
let rank = name === specs.default ? 0 : Infinity;
let kernelIconUrl = specs.kernelspecs[name].resources['logo-64x64'];
if (kernelIconUrl) {
let index = kernelIconUrl.indexOf('kernelspecs');
kernelIconUrl = baseUrl + kernelIconUrl.slice(index);
}
launcher.add({
command: CommandIDs.create,
args: { isLauncher: true, kernelPreference: { name } },
category: 'Console',
rank,
kernelIconUrl
});
}
});
示例7:
services.ready.then(() => {
let specs = services.specs;
let baseUrl = PageConfig.getBaseUrl();
for (let name in specs.kernelspecs) {
let displayName = specs.kernelspecs[name].display_name;
let rank = name === specs.default ? 0 : Infinity;
let kernelIconUrl = specs.kernelspecs[name].resources['logo-64x64'];
if (kernelIconUrl) {
let index = kernelIconUrl.indexOf('kernelspecs');
kernelIconUrl = baseUrl + kernelIconUrl.slice(index);
}
launcher.add({
displayName,
category: 'Notebook',
name,
iconClass: 'jp-NotebookRunningIcon',
callback,
rank,
kernelIconUrl
});
}
});
示例8: activate
/**
* Activate the editor tracker plugin.
*/
function activate(
app: JupyterLab,
consoleTracker: IConsoleTracker,
editorServices: IEditorServices,
browserFactory: IFileBrowserFactory,
restorer: ILayoutRestorer,
settingRegistry: ISettingRegistry,
palette: ICommandPalette,
launcher: ILauncher | null,
menu: IMainMenu | null
): IEditorTracker {
const id = plugin.id;
const namespace = 'editor';
const factory = new FileEditorFactory({
editorServices,
factoryOptions: {
name: FACTORY,
fileTypes: ['markdown', '*'], // Explicitly add the markdown fileType so
defaultFor: ['markdown', '*'] // it outranks the defaultRendered viewer.
}
});
const { commands, restored } = app;
const tracker = new InstanceTracker<IDocumentWidget<FileEditor>>({
namespace
});
const isEnabled = () =>
tracker.currentWidget !== null &&
tracker.currentWidget === app.shell.currentWidget;
let config = { ...CodeEditor.defaultConfig };
// Handle state restoration.
restorer.restore(tracker, {
command: 'docmanager:open',
args: widget => ({ path: widget.context.path, factory: FACTORY }),
name: widget => widget.context.path
});
/**
* Update the setting values.
*/
function updateSettings(settings: ISettingRegistry.ISettings): void {
let cached = settings.get('editorConfig').composite as Partial<
CodeEditor.IConfig
>;
Object.keys(config).forEach((key: keyof CodeEditor.IConfig) => {
config[key] =
cached[key] === null || cached[key] === undefined
? CodeEditor.defaultConfig[key]
: cached[key];
});
// Trigger a refresh of the rendered commands
app.commands.notifyCommandChanged();
}
/**
* Update the settings of the current tracker instances.
*/
function updateTracker(): void {
tracker.forEach(widget => {
updateWidget(widget.content);
});
}
/**
* Update the settings of a widget.
*/
function updateWidget(widget: FileEditor): void {
const editor = widget.editor;
Object.keys(config).forEach((key: keyof CodeEditor.IConfig) => {
editor.setOption(key, config[key]);
});
}
// Add a console creator to the File menu
// Fetch the initial state of the settings.
Promise.all([settingRegistry.load(id), restored])
.then(([settings]) => {
updateSettings(settings);
updateTracker();
settings.changed.connect(() => {
updateSettings(settings);
updateTracker();
});
})
.catch((reason: Error) => {
console.error(reason.message);
updateTracker();
});
factory.widgetCreated.connect((sender, widget) => {
widget.title.icon = EDITOR_ICON_CLASS;
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => {
tracker.save(widget);
});
//.........这里部分代码省略.........
示例9: activate
/**
* Activate the terminal plugin.
*/
function activate(
app: JupyterFrontEnd,
settingRegistry: ISettingRegistry,
palette: ICommandPalette | null,
launcher: ILauncher | null,
restorer: ILayoutRestorer | null,
mainMenu: IMainMenu | null
): ITerminalTracker {
const { serviceManager } = app;
const category = 'Terminal';
const namespace = 'terminal';
const tracker = new InstanceTracker<MainAreaWidget<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.
if (restorer) {
restorer.restore(tracker, {
command: CommandIDs.createNew,
args: widget => ({ name: widget.content.session.name }),
name: widget => widget.content.session && widget.content.session.name
});
}
// The terminal options from the setting editor.
let options: Partial<Terminal.IOptions>;
/**
* Update the option values.
*/
function updateOptions(settings: ISettingRegistry.ISettings): void {
options = settings.composite as Partial<Terminal.IOptions>;
Object.keys(options).forEach((key: keyof Terminal.IOptions) => {
Terminal.defaultOptions[key] = options[key];
});
}
/**
* Update terminal
*/
function updateTerminal(widget: MainAreaWidget<Terminal>): void {
const terminal = widget.content;
if (!terminal) {
return;
}
Object.keys(options).forEach((key: keyof Terminal.IOptions) => {
terminal.setOption(key, options[key]);
});
}
/**
* Update the settings of the current tracker instances.
*/
function updateTracker(): void {
tracker.forEach(widget => updateTerminal(widget));
}
// Fetch the initial state of the settings.
settingRegistry
.load(plugin.id)
.then(settings => {
updateOptions(settings);
updateTracker();
settings.changed.connect(() => {
updateOptions(settings);
updateTracker();
});
})
.catch((reason: Error) => {
console.error(reason.message);
});
addCommands(app, tracker, settingRegistry);
if (mainMenu) {
// Add some commands to the application view menu.
const viewGroup = [
CommandIDs.increaseFont,
CommandIDs.decreaseFont,
CommandIDs.toggleTheme
].map(command => {
return { command };
});
mainMenu.settingsMenu.addGroup(viewGroup, 40);
// Add terminal creation to the file menu.
mainMenu.fileMenu.newMenu.addGroup([{ command: CommandIDs.createNew }], 20);
}
if (palette) {
// Add command palette items.
//.........这里部分代码省略.........
示例10: activateConsole
/**
* Activate the console extension.
*/
function activateConsole(app: JupyterLab, manager: IServiceManager, rendermime: IRenderMime, mainMenu: IMainMenu, palette: ICommandPalette, contentFactory: ConsolePanel.IContentFactory, editorServices: IEditorServices, restorer: ILayoutRestorer, launcher: ILauncher | null): IConsoleTracker {
let { commands, shell } = app;
let category = 'Console';
let command: string;
let menu = new Menu({ commands });
// Create an instance tracker for all console panels.
const tracker = new InstanceTracker<ConsolePanel>({
namespace: 'console',
shell
});
// Handle state restoration.
restorer.restore(tracker, {
command: CommandIDs.open,
args: panel => ({
path: panel.console.session.path,
name: panel.console.session.name
}),
name: panel => panel.console.session.path,
when: manager.ready
});
// Add a launcher item if the launcher is available.
if (launcher) {
launcher.add({
name: 'Code Console',
command: CommandIDs.create
});
}
// Set the main menu title.
menu.title.label = category;
/**
* Create a console for a given path.
*/
function createConsole(options: Partial<ConsolePanel.IOptions>): Promise<void> {
return manager.ready.then(() => {
let panel = new ConsolePanel({
manager,
rendermime: rendermime.clone(),
contentFactory,
mimeTypeService: editorServices.mimeTypeService,
...options
});
// Add the console panel to the tracker.
tracker.add(panel);
shell.addToMainArea(panel);
tracker.activate(panel);
});
}
command = CommandIDs.open;
commands.addCommand(command, {
execute: (args: Partial<ConsolePanel.IOptions>) => {
let path = args['path'];
let widget = tracker.find(value => {
if (value.console.session.path === path) {
return true;
}
});
if (widget) {
tracker.activate(widget);
} else {
return manager.ready.then(() => {
let model = find(manager.sessions.running(), item => {
return item.path === path;
});
if (model) {
return createConsole(args);
}
});
}
}
});
command = CommandIDs.create;
commands.addCommand(command, {
label: 'Start New Console',
execute: (args: Partial<ConsolePanel.IOptions>) => {
let basePath = args.basePath || '.';
return createConsole({ basePath, ...args });
}
});
palette.addItem({ command, category });
// Get the current widget and activate unless the args specify otherwise.
function getCurrent(args: JSONObject): ConsolePanel | null {
let widget = tracker.currentWidget;
let activate = args['activate'] !== false;
if (activate && widget) {
tracker.activate(widget);
}
return widget;
}
//.........这里部分代码省略.........
示例11: activate
/**
* Activate the terminal plugin.
*/
function activate(
app: JupyterFrontEnd,
settingRegistry: ISettingRegistry,
palette: ICommandPalette | null,
launcher: ILauncher | null,
restorer: ILayoutRestorer | null,
mainMenu: IMainMenu | null,
themeManager: IThemeManager
): ITerminalTracker {
const { serviceManager, commands } = app;
const category = 'Terminal';
const namespace = 'terminal';
const tracker = new InstanceTracker<MainAreaWidget<ITerminal.ITerminal>>({
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.
if (restorer) {
restorer.restore(tracker, {
command: CommandIDs.createNew,
args: widget => ({ name: widget.content.session.name }),
name: widget => widget.content.session && widget.content.session.name
});
}
// The terminal options from the setting editor.
let options: Partial<ITerminal.IOptions>;
/**
* Update the option values.
*/
function updateOptions(settings: ISettingRegistry.ISettings): void {
options = settings.composite as Partial<ITerminal.IOptions>;
Object.keys(options).forEach((key: keyof ITerminal.IOptions) => {
ITerminal.defaultOptions[key] = options[key];
});
}
/**
* Update terminal
*/
function updateTerminal(widget: MainAreaWidget<ITerminal.ITerminal>): void {
const terminal = widget.content;
if (!terminal) {
return;
}
Object.keys(options).forEach((key: keyof ITerminal.IOptions) => {
terminal.setOption(key, options[key]);
});
}
/**
* Update the settings of the current tracker instances.
*/
function updateTracker(): void {
tracker.forEach(widget => updateTerminal(widget));
}
// Fetch the initial state of the settings.
settingRegistry
.load(plugin.id)
.then(settings => {
updateOptions(settings);
updateTracker();
settings.changed.connect(() => {
updateOptions(settings);
updateTracker();
});
})
.catch(Private.showErrorMessage);
// Subscribe to changes in theme.
themeManager.themeChanged.connect((sender, args) => {
tracker.forEach(widget => {
const terminal = widget.content;
if (terminal.getOption('theme') === 'inherit') {
terminal.setOption('theme', 'inherit');
}
});
});
addCommands(app, tracker, settingRegistry);
if (mainMenu) {
// Add "Terminal Theme" menu below "JupyterLab Themes" menu.
const themeMenu = new Menu({ commands });
themeMenu.title.label = 'Terminal Theme';
themeMenu.addItem({
command: CommandIDs.setTheme,
//.........这里部分代码省略.........
示例12: activate
/**
* Activate the editor tracker plugin.
*/
function activate(app: JupyterLab, restorer: ILayoutRestorer, editorServices: IEditorServices, settingRegistry: ISettingRegistry, launcher: ILauncher | null): IEditorTracker {
const id = plugin.id;
const namespace = 'editor';
const factory = new FileEditorFactory({
editorServices,
factoryOptions: { name: FACTORY, fileTypes: ['*'], defaultFor: ['*'] }
});
const { commands, restored } = app;
const tracker = new InstanceTracker<FileEditor>({ namespace });
const hasWidget = () => !!tracker.currentWidget;
let {
lineNumbers, lineWrap, matchBrackets, autoClosingBrackets
} = CodeEditor.defaultConfig;
// Handle state restoration.
restorer.restore(tracker, {
command: 'docmanager:open',
args: widget => ({ path: widget.context.path, factory: FACTORY }),
name: widget => widget.context.path
});
/**
* Update the setting values.
*/
function updateSettings(settings: ISettingRegistry.ISettings): void {
let cached = settings.get('lineNumbers').composite as boolean | null;
lineNumbers = cached === null ? lineNumbers : !!cached;
cached = settings.get('matchBrackets').composite as boolean | null;
matchBrackets = cached === null ? matchBrackets : !!cached;
cached = settings.get('autoClosingBrackets').composite as boolean | null;
autoClosingBrackets = cached === null ? autoClosingBrackets : !!cached;
cached = settings.get('lineWrap').composite as boolean | null;
lineWrap = cached === null ? lineWrap : !!cached;
}
/**
* Update the settings of the current tracker instances.
*/
function updateTracker(): void {
tracker.forEach(widget => { updateWidget(widget); });
}
/**
* Update the settings of a widget.
*/
function updateWidget(widget: FileEditor): void {
const editor = widget.editor;
editor.setOption('lineNumbers', lineNumbers);
editor.setOption('lineWrap', lineWrap);
editor.setOption('matchBrackets', matchBrackets);
editor.setOption('autoClosingBrackets', autoClosingBrackets);
}
// Fetch the initial state of the settings.
Promise.all([settingRegistry.load(id), restored]).then(([settings]) => {
updateSettings(settings);
updateTracker();
settings.changed.connect(() => {
updateSettings(settings);
updateTracker();
});
}).catch((reason: Error) => {
console.error(reason.message);
updateTracker();
});
factory.widgetCreated.connect((sender, widget) => {
widget.title.icon = EDITOR_ICON_CLASS;
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => { tracker.save(widget); });
tracker.add(widget);
updateWidget(widget);
});
app.docRegistry.addWidgetFactory(factory);
// Handle the settings of new widgets.
tracker.widgetAdded.connect((sender, widget) => {
updateWidget(widget);
});
commands.addCommand(CommandIDs.lineNumbers, {
execute: () => {
const key = 'lineNumbers';
const value = lineNumbers = !lineNumbers;
updateTracker();
return settingRegistry.set(id, key, value).catch((reason: Error) => {
console.error(`Failed to set ${id}:${key} - ${reason.message}`);
});
},
isEnabled: hasWidget,
isToggled: () => lineNumbers,
label: 'Line Numbers'
});
//.........这里部分代码省略.........
示例13: openInspector
activate: (
app: JupyterFrontEnd,
palette: ICommandPalette | null,
launcher: ILauncher | null,
restorer: ILayoutRestorer | null
): IInspector => {
const { commands, shell } = app;
const command = CommandIDs.open;
const label = 'Open Inspector';
const title = 'Inspector';
const namespace = 'inspector';
const tracker = new InstanceTracker<MainAreaWidget<InspectorPanel>>({
namespace
});
let source: IInspector.IInspectable | null = null;
let inspector: MainAreaWidget<InspectorPanel>;
function openInspector(): MainAreaWidget<InspectorPanel> {
if (!inspector || inspector.isDisposed) {
inspector = new MainAreaWidget({ content: new InspectorPanel() });
inspector.id = 'jp-inspector';
inspector.title.label = title;
tracker.add(inspector);
source = source && !source.isDisposed ? source : null;
inspector.content.source = source;
}
if (!inspector.isAttached) {
shell.add(inspector, 'main', { activate: false });
}
shell.activateById(inspector.id);
return inspector;
}
// Add command to registry.
commands.addCommand(command, {
caption: 'Live updating code documentation from the active kernel',
isEnabled: () =>
!inspector ||
inspector.isDisposed ||
!inspector.isAttached ||
!inspector.isVisible,
label: args => (args.isLauncher ? title : label),
iconClass: args =>
args.isLauncher ? 'jp-MaterialIcon jp-InspectorIcon' : '',
execute: () => openInspector()
});
// Add command to UI where possible.
if (palette) {
palette.addItem({ command, category: title });
}
if (launcher) {
launcher.add({ command, args: { isLauncher: true } });
}
// Handle state restoration.
if (restorer) {
restorer.restore(tracker, {
command,
args: () => null,
name: () => 'inspector'
});
}
// Create a proxy to pass the `source` to the current inspector.
const proxy: IInspector = Object.defineProperty({}, 'source', {
get: (): IInspector.IInspectable | null =>
!inspector || inspector.isDisposed ? null : inspector.content.source,
set: (src: IInspector.IInspectable | null) => {
source = src && !src.isDisposed ? src : null;
if (inspector && !inspector.isDisposed) {
inspector.content.source = source;
}
}
});
return proxy;
}
示例14: activate
/**
* Activate the terminal plugin.
*/
function activate(app: JupyterLab, services: IServiceManager, mainMenu: IMainMenu, palette: ICommandPalette, restorer: ILayoutRestorer, launcher: ILauncher | null): ITerminalTracker {
// Bail if there are no terminals available.
if (!services.terminals.isAvailable()) {
console.log('Disabling terminals plugin because they are not available on the server');
return;
}
const { commands, shell } = app;
const category = 'Terminal';
const namespace = 'terminal';
const tracker = new InstanceTracker<TerminalWidget>({ namespace, shell });
// Handle state restoration.
restorer.restore(tracker, {
command: CommandIDs.createNew,
args: widget => ({ name: widget.session.name }),
name: widget => widget.session && widget.session.name
});
addDefaultCommands(tracker, commands);
// Add terminal commands.
commands.addCommand(CommandIDs.createNew, {
label: 'New Terminal',
caption: 'Start a new terminal session',
execute: args => {
let name = args ? args['name'] as string : '';
let term = new TerminalWidget();
term.title.closable = true;
term.title.icon = TERMINAL_ICON_CLASS;
term.title.label = '...';
shell.addToMainArea(term);
let promise = name ?
services.terminals.connectTo(name)
: services.terminals.startNew();
return promise.then(session => {
term.session = session;
tracker.add(term);
tracker.activate(term);
}).catch(() => { term.dispose(); });
}
});
commands.addCommand(CommandIDs.open, {
execute: args => {
let name = args['name'] as string;
// Check for a running terminal with the given name.
let widget = tracker.find(value => value.session.name === name);
if (widget) {
tracker.activate(widget);
} else {
// Otherwise, create a new terminal with a given name.
return commands.execute(CommandIDs.createNew, { name });
}
}
});
commands.addCommand(CommandIDs.refresh, {
label: 'Refresh Terminal',
caption: 'Refresh the current terminal session',
execute: () => {
let current = tracker.currentWidget;
if (!current) {
return;
}
tracker.activate(current);
return current.refresh().then(() => {
current.activate();
});
},
isEnabled: () => { return tracker.currentWidget !== null; }
});
// 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 });
menu.addItem({ command });
});
mainMenu.addMenu(menu, {rank: 40});
// Add a launcher item if the launcher is available.
if (launcher) {
launcher.add({
name: 'Terminal',
command: CommandIDs.createNew
});
}
//.........这里部分代码省略.........
示例15: activateNotebookHandler
/**
* Activate the notebook handler extension.
*/
function activateNotebookHandler(app: JupyterLab, registry: IDocumentRegistry, services: IServiceManager, rendermime: IRenderMime, mainMenu: IMainMenu, palette: ICommandPalette, contentFactory: NotebookPanel.IContentFactory, editorServices: IEditorServices, restorer: ILayoutRestorer, launcher: ILauncher | null): INotebookTracker {
const factory = new NotebookWidgetFactory({
name: FACTORY,
fileExtensions: ['.ipynb'],
modelName: 'notebook',
defaultFor: ['.ipynb'],
preferKernel: true,
canStartKernel: true,
rendermime,
contentFactory,
mimeTypeService: editorServices.mimeTypeService
});
const shell = app.shell;
const tracker = new NotebookTracker({ namespace: 'notebook', shell });
// Handle state restoration.
restorer.restore(tracker, {
command: 'file-operations:open',
args: panel => ({ path: panel.context.path, factory: FACTORY }),
name: panel => panel.context.path,
when: services.ready
});
registry.addModelFactory(new NotebookModelFactory({}));
registry.addWidgetFactory(factory);
registry.addFileType({
name: 'Notebook',
extension: '.ipynb',
contentType: 'notebook',
fileFormat: 'json'
});
registry.addCreator({
name: 'Notebook',
fileType: 'Notebook',
widgetName: 'Notebook'
});
addCommands(app, services, tracker);
populatePalette(palette);
let id = 0; // The ID counter for notebook panels.
factory.widgetCreated.connect((sender, widget) => {
// If the notebook panel does not have an ID, assign it one.
widget.id = widget.id || `notebook-${++id}`;
widget.title.icon = NOTEBOOK_ICON_CLASS;
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => { tracker.save(widget); });
// Add the notebook panel to the tracker.
tracker.add(widget);
});
// Add main menu notebook menu.
mainMenu.addMenu(createMenu(app), { rank: 20 });
// Add a launcher item if the launcher is available.
if (launcher) {
launcher.add({
args: { creatorName: 'Notebook' },
command: 'file-operations:create-from',
name: 'Notebook'
});
}
app.contextMenu.addItem({command: CommandIDs.clearOutputs, selector: '.jp-Notebook .jp-Cell'});
app.contextMenu.addItem({command: CommandIDs.split, selector: '.jp-Notebook .jp-Cell'});
app.contextMenu.addItem({ type: 'separator', selector: '.jp-Notebook', rank: 0 });
app.contextMenu.addItem({command: CommandIDs.undo, selector: '.jp-Notebook', rank: 1});
app.contextMenu.addItem({command: CommandIDs.redo, selector: '.jp-Notebook', rank: 2});
app.contextMenu.addItem({ type: 'separator', selector: '.jp-Notebook', rank: 0 });
app.contextMenu.addItem({command: CommandIDs.createConsole, selector: '.jp-Notebook', rank: 3});
return tracker;
}