本文整理汇总了TypeScript中@jupyterlab/apputils.ICommandPalette类的典型用法代码示例。如果您正苦于以下问题:TypeScript ICommandPalette类的具体用法?TypeScript ICommandPalette怎么用?TypeScript ICommandPalette使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ICommandPalette类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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;
}
示例2: SearchProviderRegistry
activate: (
app: JupyterFrontEnd,
palette: ICommandPalette,
mainMenu: IMainMenu | null
) => {
// Create registry, retrieve all default providers
const registry: SearchProviderRegistry = new SearchProviderRegistry();
// TODO: Should register the default providers, with an application-specific
// enabler.
const activeSearches = new Map<string, SearchInstance>();
const startCommand: string = 'documentsearch:start';
const nextCommand: string = 'documentsearch:highlightNext';
const prevCommand: string = 'documentsearch:highlightPrevious';
app.commands.addCommand(startCommand, {
label: 'FindâŚ',
isEnabled: () => {
const currentWidget = app.shell.currentWidget;
if (!currentWidget) {
return;
}
return registry.getProviderForWidget(currentWidget) !== undefined;
},
execute: () => {
const currentWidget = app.shell.currentWidget;
if (!currentWidget) {
return;
}
const widgetId = currentWidget.id;
let searchInstance = activeSearches.get(widgetId);
if (!searchInstance) {
const searchProvider = registry.getProviderForWidget(currentWidget);
if (!searchProvider) {
return;
}
searchInstance = new SearchInstance(currentWidget, searchProvider);
activeSearches.set(widgetId, searchInstance);
// find next and previous are now enabled
app.commands.notifyCommandChanged();
searchInstance.disposed.connect(() => {
activeSearches.delete(widgetId);
// find next and previous are now not enabled
app.commands.notifyCommandChanged();
});
}
searchInstance.focusInput();
}
});
app.commands.addCommand(nextCommand, {
label: 'Find Next',
isEnabled: () => {
const currentWidget = app.shell.currentWidget;
if (!currentWidget) {
return;
}
return activeSearches.has(currentWidget.id);
},
execute: async () => {
const currentWidget = app.shell.currentWidget;
if (!currentWidget) {
return;
}
const instance = activeSearches.get(currentWidget.id);
if (!instance) {
return;
}
await instance.provider.highlightNext();
instance.updateIndices();
}
});
app.commands.addCommand(prevCommand, {
label: 'Find Previous',
isEnabled: () => {
const currentWidget = app.shell.currentWidget;
if (!currentWidget) {
return;
}
return activeSearches.has(currentWidget.id);
},
execute: async () => {
const currentWidget = app.shell.currentWidget;
if (!currentWidget) {
return;
}
const instance = activeSearches.get(currentWidget.id);
if (!instance) {
return;
}
await instance.provider.highlightPrevious();
instance.updateIndices();
}
});
//.........这里部分代码省略.........
示例3: 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,
//.........这里部分代码省略.........
示例4: 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);
});
}
/**
* Whether there is an active console.
*/
function hasWidget(): boolean {
return tracker.currentWidget !== null;
}
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 {
//.........这里部分代码省略.........
示例5: 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.toggleLeftArea;
app.commands.addCommand(command, {
label: args => args['isPalette'] ?
'Toggle Left Area' : 'Show Left Area',
execute: () => {
if (app.shell.leftCollapsed) {
app.shell.expandLeft();
} else {
app.shell.collapseLeft();
app.shell.activateById(app.shell.currentWidget.id);
}
},
isToggled: () => !app.shell.leftCollapsed,
isVisible: () => !app.shell.isEmpty('left')
});
palette.addItem({ command, category, args: { 'isPalette': true } });
command = CommandIDs.toggleRightArea;
app.commands.addCommand(command, {
label: args => args['isPalette'] ?
'Toggle Right Area' : 'Show Right Area',
execute: () => {
if (app.shell.rightCollapsed) {
app.shell.expandRight();
} else {
app.shell.collapseRight();
app.shell.activateById(app.shell.currentWidget.id);
}
},
isToggled: () => !app.shell.rightCollapsed,
isVisible: () => !app.shell.isEmpty('right')
});
palette.addItem({ command, category, args: { 'isPalette': true } });
command = CommandIDs.togglePresentationMode;
app.commands.addCommand(command, {
label: args => args['isPalette'] ?
'Toggle Presentation Mode' : 'Presentation Mode',
execute: () => {
app.shell.presentationMode = !app.shell.presentationMode;
},
isToggled: () => app.shell.presentationMode,
isVisible: () => true
});
palette.addItem({ command, category, args: { 'isPalette': true } });
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: args => args['isPalette'] ?
'Toggle Single-Document Mode' : 'Single-Document Mode',
isToggled: () => app.shell.mode === 'single-document',
execute: () => {
const args = app.shell.mode === 'multiple-document' ?
{ mode: 'single-document' } : { mode: 'multiple-document' };
return app.commands.execute(CommandIDs.setMode, args);
}
});
//.........这里部分代码省略.........
示例6:
].forEach(command => {
palette.addItem({ command, category, args: { isPalette: true } });
});
示例7:
].forEach(command => palette.addItem({ command, category: 'Editor' }));
示例8:
manager.themes.forEach(theme => {
palette.addItem({ command, args: { isPalette, theme }, category });
});
示例9:
RESOURCES.forEach(args => {
palette.addItem({ args, command: CommandIDs.open, category });
});
示例10:
EXPORT_TO_FORMATS.forEach(exportToFormat => {
let args = { 'format': exportToFormat['format'], 'label': exportToFormat['label'], 'isPalette': true };
palette.addItem({ command: CommandIDs.exportToFormat, category: category, args: args });
});