本文整理匯總了TypeScript中@phosphor/widgets.CommandPalette.addItem方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript CommandPalette.addItem方法的具體用法?TypeScript CommandPalette.addItem怎麽用?TypeScript CommandPalette.addItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@phosphor/widgets.CommandPalette
的用法示例。
在下文中一共展示了CommandPalette.addItem方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
].forEach(command => palette.addItem({ command, category }));
示例2: main
//.........這裏部分代碼省略.........
});
commands.addKeyBinding({
keys: ['Accel J', 'Accel J'],
selector: 'body',
command: 'example:new-tab'
});
commands.addKeyBinding({
keys: ['Accel M'],
selector: 'body',
command: 'example:open-task-manager'
});
let menu1 = createMenu();
menu1.title.label = 'File';
menu1.title.mnemonic = 0;
let menu2 = createMenu();
menu2.title.label = 'Edit';
menu2.title.mnemonic = 0;
let menu3 = createMenu();
menu3.title.label = 'View';
menu3.title.mnemonic = 0;
let bar = new MenuBar();
bar.addMenu(menu1);
bar.addMenu(menu2);
bar.addMenu(menu3);
bar.id = 'menuBar';
let palette = new CommandPalette({ commands });
palette.addItem({ command: 'example:cut', category: 'Edit' });
palette.addItem({ command: 'example:copy', category: 'Edit' });
palette.addItem({ command: 'example:paste', category: 'Edit' });
palette.addItem({ command: 'example:one', category: 'Number' });
palette.addItem({ command: 'example:two', category: 'Number' });
palette.addItem({ command: 'example:three', category: 'Number' });
palette.addItem({ command: 'example:four', category: 'Number' });
palette.addItem({ command: 'example:black', category: 'Number' });
palette.addItem({ command: 'example:new-tab', category: 'File' });
palette.addItem({ command: 'example:close-tab', category: 'File' });
palette.addItem({ command: 'example:save-on-exit', category: 'File' });
palette.addItem({ command: 'example:open-task-manager', category: 'File' });
palette.addItem({ command: 'example:close', category: 'File' });
palette.addItem({ command: 'example:clear-cell', category: 'Notebook Cell Operations' });
palette.addItem({ command: 'example:cut-cells', category: 'Notebook Cell Operations' });
palette.addItem({ command: 'example:run-cell', category: 'Notebook Cell Operations' });
palette.addItem({ command: 'example:cell-test', category: 'Console' });
palette.addItem({ command: 'notebook:new', category: 'Notebook' });
palette.id = 'palette';
let contextMenu = new ContextMenu({ commands });
document.addEventListener('contextmenu', (event: MouseEvent) => {
if (contextMenu.open(event)) {
event.preventDefault();
}
});
contextMenu.addItem({ command: 'example:cut', selector: '.content' });
contextMenu.addItem({ command: 'example:copy', selector: '.content' });
contextMenu.addItem({ command: 'example:paste', selector: '.content' });
contextMenu.addItem({ command: 'example:one', selector: '.p-CommandPalette' });
示例3: startApp
/**
* Start the application.
*/
function startApp(path: string, manager: ServiceManager.IManager) {
// Initialize the command registry with the key bindings.
let commands = new CommandRegistry();
// Setup the keydown listener for the document.
document.addEventListener('keydown', event => {
commands.processKeydownEvent(event);
});
let rendermime = new RenderMimeRegistry({ initialFactories });
let editorFactory = editorServices.factoryService.newInlineEditor;
let contentFactory = new ConsolePanel.ContentFactory({ editorFactory });
let consolePanel = new ConsolePanel({
rendermime,
manager,
path,
contentFactory,
mimeTypeService: editorServices.mimeTypeService
});
consolePanel.title.label = TITLE;
let palette = new CommandPalette({ commands });
let panel = new SplitPanel();
panel.id = 'main';
panel.orientation = 'horizontal';
panel.spacing = 0;
SplitPanel.setStretch(palette, 0);
SplitPanel.setStretch(consolePanel, 1);
panel.addWidget(palette);
panel.addWidget(consolePanel);
// Attach the panel to the DOM.
Widget.attach(panel, document.body);
// Handle resize events.
window.addEventListener('resize', () => {
panel.update();
});
let selector = '.jp-ConsolePanel';
let category = 'Console';
let command: string;
// Add the commands.
command = 'console:clear';
commands.addCommand(command, {
label: 'Clear',
execute: () => {
consolePanel.console.clear();
}
});
palette.addItem({ command, category });
command = 'console:execute';
commands.addCommand(command, {
label: 'Execute Prompt',
execute: () => {
consolePanel.console.execute();
}
});
palette.addItem({ command, category });
commands.addKeyBinding({ command, selector, keys: ['Enter'] });
command = 'console:execute-forced';
commands.addCommand(command, {
label: 'Execute Cell (forced)',
execute: () => {
consolePanel.console.execute(true);
}
});
palette.addItem({ command, category });
commands.addKeyBinding({ command, selector, keys: ['Shift Enter'] });
command = 'console:linebreak';
commands.addCommand(command, {
label: 'Insert Line Break',
execute: () => {
consolePanel.console.insertLinebreak();
}
});
palette.addItem({ command, category });
commands.addKeyBinding({ command, selector, keys: ['Ctrl Enter'] });
}
示例4: main
//.........這裏部分代碼省略.........
});
commands.addKeyBinding({
keys: ['Accel J', 'Accel J'],
selector: 'body',
command: 'example:new-tab'
});
commands.addKeyBinding({
keys: ['Accel M'],
selector: 'body',
command: 'example:open-task-manager'
});
let menu1 = createMenu();
menu1.title.label = 'File';
menu1.title.mnemonic = 0;
let menu2 = createMenu();
menu2.title.label = 'Edit';
menu2.title.mnemonic = 0;
let menu3 = createMenu();
menu3.title.label = 'View';
menu3.title.mnemonic = 0;
let ctxt = createMenu();
let bar = new MenuBar();
bar.addMenu(menu1);
bar.addMenu(menu2);
bar.addMenu(menu3);
bar.id = 'menuBar';
let palette = new CommandPalette({ commands });
palette.addItem({ command: 'example:cut', category: 'Edit' });
palette.addItem({ command: 'example:copy', category: 'Edit' });
palette.addItem({ command: 'example:paste', category: 'Edit' });
palette.addItem({ command: 'example:one', category: 'Number' });
palette.addItem({ command: 'example:two', category: 'Number' });
palette.addItem({ command: 'example:three', category: 'Number' });
palette.addItem({ command: 'example:four', category: 'Number' });
palette.addItem({ command: 'example:black', category: 'Number' });
palette.addItem({ command: 'example:new-tab', category: 'File' });
palette.addItem({ command: 'example:close-tab', category: 'File' });
palette.addItem({ command: 'example:save-on-exit', category: 'File' });
palette.addItem({ command: 'example:open-task-manager', category: 'File' });
palette.addItem({ command: 'example:close', category: 'File' });
palette.addItem({ command: 'notebook:new', category: 'Notebook' });
palette.id = 'palette';
document.addEventListener('contextmenu', (event: MouseEvent) => {
event.preventDefault();
ctxt.open(event.clientX, event.clientY);
console.log('ctxt menu');
});
document.addEventListener('keydown', (event: KeyboardEvent) => {
// if (!event.ctrlKey && !event.shiftKey && !event.metaKey && event.keyCode === 18) {
// event.preventDefault();
// event.stopPropagation();
// bar.activeIndex = 0;
// bar.activate();
// } else {
// keymap.processKeydownEvent(event);
// }
commands.processKeydownEvent(event);
});
let r1 = new ContentWidget('Red');
let b1 = new ContentWidget('Blue');
let g1 = new ContentWidget('Green');
let y1 = new ContentWidget('Yellow');
let r2 = new ContentWidget('Red');
let b2 = new ContentWidget('Blue');
// let g2 = new ContentWidget('Green');
// let y2 = new ContentWidget('Yellow');
let dock = new DockPanel();
dock.addWidget(r1);
dock.addWidget(b1, { mode: 'split-right', ref: r1 });
dock.addWidget(y1, { mode: 'split-bottom', ref: b1 });
dock.addWidget(g1, { mode: 'split-left', ref: y1 });
dock.addWidget(r2, { ref: b1 });
dock.addWidget(b2, { mode: 'split-right', ref: y1 });
dock.id = 'dock';
BoxPanel.setStretch(dock, 1);
let main = new BoxPanel({ direction: 'left-to-right', spacing: 0 });
main.id = 'main';
main.addWidget(palette);
main.addWidget(dock);
window.onresize = () => { main.update(); };
Widget.attach(bar, document.body);
Widget.attach(main, document.body);
}