本文整理汇总了TypeScript中phosphor-keymap.KeymapManager.add方法的典型用法代码示例。如果您正苦于以下问题:TypeScript KeymapManager.add方法的具体用法?TypeScript KeymapManager.add怎么用?TypeScript KeymapManager.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phosphor-keymap.KeymapManager
的用法示例。
在下文中一共展示了KeymapManager.add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: main
function main(): void {
let baseUrl = getConfigOption('baseUrl');
let contentsManager = new ContentsManager(baseUrl);
let sessionsManager = new NotebookSessionManager({ baseUrl: baseUrl });
let fbModel = new FileBrowserModel(contentsManager, sessionsManager);
let fbWidget = new FileBrowserWidget(fbModel)
let fileHandler = new FileHandler(contentsManager);
let docManager = new DocumentManager();
docManager.registerDefault(fileHandler);
let panel = new SplitPanel();
panel.id = 'main';
panel.addChild(fbWidget);
SplitPanel.setStretch(fbWidget, 0);
let dock = new DockPanel();
panel.addChild(dock);
SplitPanel.setStretch(dock, 1);
dock.spacing = 8;
fbWidget.widgetFactory = model => {
return docManager.open(model);
};
fbModel.openRequested.connect((fbModel, model) => {
let editor = docManager.open(model);
dock.insertTabAfter(editor);
});
fbModel.fileChanged.connect((fbModel, args) => {
docManager.rename(args.oldValue, args.newValue);
});
let keymapManager = new KeymapManager();
keymapManager.add([{
sequence: ['Enter'],
selector: '.jp-DirListing',
handler: () => {
fbWidget.open();
return true;
}
}, {
sequence: ['Ctrl N'], // Add emacs keybinding for select next.
selector: '.jp-DirListing',
handler: () => {
fbWidget.selectNext();
return true;
}
}, {
sequence: ['Ctrl P'], // Add emacs keybinding for select previous.
selector: '.jp-DirListing',
handler: () => {
fbWidget.selectPrevious();
return true;
}
}, {
sequence: ['Accel S'],
selector: '.jp-CodeMirrorWidget',
handler: () => {
docManager.save();
return true;
}
}]);
window.addEventListener('keydown', (event) => {
keymapManager.processKeydownEvent(event);
});
let contextMenu = new Menu([
new MenuItem({
text: '&Open',
icon: 'fa fa-folder-open-o',
shortcut: 'Ctrl+O',
handler: () => { fbWidget.open(); }
}),
new MenuItem({
text: '&Rename',
icon: 'fa fa-edit',
shortcut: 'Ctrl+R',
handler: () => { fbWidget.rename(); }
}),
new MenuItem({
text: '&Delete',
icon: 'fa fa-remove',
shortcut: 'Ctrl+D',
handler: () => { fbWidget.delete(); }
}),
new MenuItem({
text: 'Duplicate',
icon: 'fa fa-copy',
handler: () => { fbWidget.duplicate(); }
}),
new MenuItem({
text: 'Cut',
icon: 'fa fa-cut',
shortcut: 'Ctrl+X',
handler: () => { fbWidget.cut(); }
}),
//.........这里部分代码省略.........
示例2: startApp
function startApp(session: ISession) {
// Initialize the keymap manager with the bindings.
let keymap = new KeymapManager();
// Setup the keydown listener for the document.
document.addEventListener('keydown', event => {
keymap.processKeydownEvent(event);
});
const transformers = [
new JavascriptRenderer(),
new MarkdownRenderer(),
new HTMLRenderer(),
new ImageRenderer(),
new SVGRenderer(),
new LatexRenderer(),
new TextRenderer()
];
let renderers: RenderMime.MimeMap<RenderMime.IRenderer> = {};
let order: string[] = [];
for (let t of transformers) {
for (let m of t.mimetypes) {
renderers[m] = t;
order.push(m);
}
}
let sanitizer = defaultSanitizer;
let rendermime = new RenderMime({ renderers, order, sanitizer });
let consolePanel = new ConsolePanel({ session, rendermime });
consolePanel.title.text = TITLE;
let pModel = new StandardPaletteModel();
let palette = new CommandPalette();
palette.model = pModel;
let panel = new SplitPanel();
panel.id = 'main';
panel.orientation = SplitPanel.Horizontal;
panel.spacing = 0;
SplitPanel.setStretch(palette, 0);
SplitPanel.setStretch(consolePanel, 1);
panel.attach(document.body);
panel.addChild(palette);
panel.addChild(consolePanel);
window.onresize = () => { panel.update(); };
let items: IStandardPaletteItemOptions[] = [
{
category: 'Console',
text: 'Clear',
shortcut: 'Accel R',
handler: () => { consolePanel.content.clear(); }
},
{
category: 'Console',
text: 'Execute Prompt',
shortcut: 'Shift Enter',
handler: () => { consolePanel.content.execute(); }
}
];
pModel.addItems(items);
let bindings = [
{
selector: '.jp-ConsolePanel',
sequence: ['Accel R'],
handler: () => { consolePanel.content.clear(); }
},
{
selector: '.jp-ConsolePanel',
sequence: ['Shift Enter'],
handler: () => { consolePanel.content.execute(); }
},
{
selector: 'body',
sequence: ['Escape'],
handler: () => { consolePanel.content.dismissCompletion(); }
}
];
keymap.add(bindings);
}
示例3: main
function main(): void {
let baseUrl = getConfigOption('baseUrl');
let contentsManager = new ContentsManager(baseUrl);
let sessionsManager = new NotebookSessionManager({ baseUrl: baseUrl });
let fbModel = new FileBrowserModel(contentsManager, sessionsManager);
let registry = new FileHandlerRegistry();
let fileHandler = new FileHandler(contentsManager);
registry.addDefaultHandler(fileHandler);
let fbWidget = new FileBrowserWidget(fbModel, registry);
let dirCreator = new FileCreator(contentsManager, 'directory');
let fileCreator = new FileCreator(contentsManager, 'file');
registry.addCreator(
'New Directory', dirCreator.createNew.bind(dirCreator));
registry.addCreator('New File', fileCreator.createNew.bind(fileCreator));
let widgets: CodeMirrorWidget[] = [];
registry.opened.connect((r, widget) => {
dock.insertTabAfter(widget);
widgets.push(widget as CodeMirrorWidget);
});
let panel = new SplitPanel();
panel.id = 'main';
panel.addChild(fbWidget);
SplitPanel.setStretch(fbWidget, 0);
let dock = new DockPanel();
panel.addChild(dock);
SplitPanel.setStretch(dock, 1);
dock.spacing = 8;
let activeWidget: CodeMirrorWidget;
document.addEventListener('focus', event => {
for (let i = 0; i < widgets.length; i++) {
let widget = widgets[i];
if (widget.node.contains(event.target as HTMLElement)) {
activeWidget = widget;
break;
}
}
});
let keymapManager = new KeymapManager();
keymapManager.add([{
sequence: ['Enter'],
selector: '.jp-DirListing',
handler: () => {
fbWidget.open();
return true;
}
}, {
sequence: ['Ctrl N'], // Add emacs keybinding for select next.
selector: '.jp-DirListing',
handler: () => {
fbWidget.selectNext();
return true;
}
}, {
sequence: ['Ctrl P'], // Add emacs keybinding for select previous.
selector: '.jp-DirListing',
handler: () => {
fbWidget.selectPrevious();
return true;
}
}, {
sequence: ['Accel S'],
selector: '.jp-CodeMirrorWidget',
handler: () => {
let path = fileHandler.findModel(activeWidget).path;
fileHandler.save(path);
return true;
}
}]);
window.addEventListener('keydown', (event) => {
keymapManager.processKeydownEvent(event);
});
let contextMenu = new Menu([
new MenuItem({
text: '&Open',
icon: 'fa fa-folder-open-o',
shortcut: 'Ctrl+O',
handler: () => { fbWidget.open(); }
}),
new MenuItem({
text: '&Rename',
icon: 'fa fa-edit',
shortcut: 'Ctrl+R',
handler: () => { fbWidget.rename(); }
}),
new MenuItem({
text: '&Delete',
icon: 'fa fa-remove',
shortcut: 'Ctrl+D',
//.........这里部分代码省略.........
示例4: createApp
function createApp(manager: IServiceManager): void {
let widgets: Widget[] = [];
let activeWidget: Widget;
let opener = {
open: (widget: Widget) => {
if (widgets.indexOf(widget) === -1) {
dock.insertTabAfter(widget);
widgets.push(widget);
}
dock.selectWidget(widget);
activeWidget = widget;
widget.disposed.connect((w: Widget) => {
let index = widgets.indexOf(w);
widgets.splice(index, 1);
});
}
};
let docRegistry = new DocumentRegistry();
let docManager = new DocumentManager({
registry: docRegistry,
manager,
opener
});
let mFactory = new TextModelFactory();
let wFactory = new EditorWidgetFactory();
docRegistry.addModelFactory(mFactory);
docRegistry.addWidgetFactory(wFactory, {
displayName: 'Editor',
modelName: 'text',
fileExtensions: ['.*'],
defaultFor: ['.*'],
preferKernel: false,
canStartKernel: true
});
let fbModel = new FileBrowserModel({ manager });
let fbWidget = new FileBrowserWidget({
model: fbModel,
manager: docManager,
opener
});
let panel = new SplitPanel();
panel.id = 'main';
panel.addChild(fbWidget);
SplitPanel.setStretch(fbWidget, 0);
let dock = new DockPanel();
panel.addChild(dock);
SplitPanel.setStretch(dock, 1);
dock.spacing = 8;
document.addEventListener('focus', event => {
for (let i = 0; i < widgets.length; i++) {
let widget = widgets[i];
if (widget.node.contains(event.target as HTMLElement)) {
activeWidget = widget;
break;
}
}
});
let keymapManager = new KeymapManager();
keymapManager.add([{
sequence: ['Enter'],
selector: '.jp-DirListing',
handler: () => {
fbWidget.open();
}
}, {
sequence: ['Ctrl N'], // Add emacs keybinding for select next.
selector: '.jp-DirListing',
handler: () => {
fbWidget.selectNext();
}
}, {
sequence: ['Ctrl P'], // Add emacs keybinding for select previous.
selector: '.jp-DirListing',
handler: () => {
fbWidget.selectPrevious();
}
}, {
sequence: ['Accel S'],
selector: '.jp-CodeMirrorWidget',
handler: () => {
let context = docManager.contextForWidget(activeWidget);
context.save();
}
}]);
window.addEventListener('keydown', (event) => {
keymapManager.processKeydownEvent(event);
});
let contextMenu = new Menu([
new MenuItem({
text: '&Open',
icon: 'fa fa-folder-open-o',
shortcut: 'Ctrl+O',
//.........这里部分代码省略.........
示例5: createApp
function createApp(manager: IServiceManager): void {
// Initialize the keymap manager with the bindings.
let keymap = new KeymapManager();
let useCapture = true;
// Setup the keydown listener for the document.
document.addEventListener('keydown', event => {
keymap.processKeydownEvent(event);
}, useCapture);
const transformers = [
new JavascriptRenderer(),
new MarkdownRenderer(),
new HTMLRenderer(),
new ImageRenderer(),
new SVGRenderer(),
new LatexRenderer(),
new TextRenderer()
];
let renderers: MimeMap<IRenderer<Widget>> = {};
let order: string[] = [];
for (let t of transformers) {
for (let m of t.mimetypes) {
renderers[m] = t;
order.push(m);
}
}
let rendermime = new RenderMime<Widget>(renderers, order);
let opener = {
open: (widget: Widget) => {
// Do nothing for sibling widgets for now.
}
};
let docRegistry = new DocumentRegistry();
let docManager = new DocumentManager({
registry: docRegistry,
manager,
opener
});
let mFactory = new NotebookModelFactory();
let clipboard = new MimeData();
let wFactory = new NotebookWidgetFactory(rendermime, clipboard);
docRegistry.addModelFactory(mFactory);
docRegistry.addWidgetFactory(wFactory, {
displayName: 'Notebook',
modelName: 'notebook',
fileExtensions: ['.ipynb'],
defaultFor: ['.ipynb'],
preferKernel: true,
canStartKernel: true
});
let nbWidget = docManager.open(NOTEBOOK) as NotebookPanel;
let pModel = new StandardPaletteModel();
let palette = new CommandPalette();
palette.model = pModel;
let panel = new SplitPanel();
panel.id = 'main';
panel.orientation = SplitPanel.Horizontal;
panel.spacing = 0;
SplitPanel.setStretch(palette, 0);
panel.attach(document.body);
panel.addChild(palette);
panel.addChild(nbWidget);
SplitPanel.setStretch(nbWidget, 1);
window.onresize = () => panel.update();
let saveHandler = () => nbWidget.context.save();
let interruptHandler = () => {
if (nbWidget.context.kernel) {
nbWidget.context.kernel.interrupt();
}
};
let restartHandler = () => {
restartKernel(nbWidget.kernel, nbWidget.node);
};
let switchHandler = () => {
selectKernelForContext(nbWidget.context, nbWidget.node);
};
let runAdvanceHandler = () => {
NotebookActions.runAndAdvance(nbWidget.content, nbWidget.context.kernel);
};
let editHandler = () => { nbWidget.content.mode = 'edit'; };
let commandHandler = () => { nbWidget.content.mode = 'command'; };
let codeHandler = () => {
NotebookActions.changeCellType(nbWidget.content, 'code');
};
let markdownHandler = () => {
NotebookActions.changeCellType(nbWidget.content, 'markdown');
};
let rawHandler = () => {
NotebookActions.changeCellType(nbWidget.content, 'raw');
};
let selectBelowHandler = () => {
NotebookActions.selectBelow(nbWidget.content);
};
let selectAboveHandler = () => {
//.........这里部分代码省略.........
示例6: main
function main(): void {
// Initialize the keymap manager with the bindings.
var keymap = new KeymapManager();
let useCapture = true;
// Setup the keydown listener for the document.
document.addEventListener('keydown', event => {
keymap.processKeydownEvent(event);
}, useCapture);
// TODO: check out static example from the history
// and make that a separate example.
let contents = new ContentsManager();
let sessions = new NotebookSessionManager();
let rendermime = new RenderMime<Widget>();
const transformers = [
new JavascriptRenderer(),
new MarkdownRenderer(),
new HTMLRenderer(),
new ImageRenderer(),
new SVGRenderer(),
new LatexRenderer(),
new ConsoleTextRenderer(),
new TextRenderer()
];
for (let t of transformers) {
for (let m of t.mimetypes) {
rendermime.order.push(m);
rendermime.renderers[m] = t;
}
}
let handler = new NotebookFileHandler(contents, sessions, rendermime);
let nbWidget = handler.open(NOTEBOOK);
let nbModel = nbWidget.model;
let nbManager = nbWidget.manager;
let pModel = new StandardPaletteModel();
let palette = new CommandPalette();
palette.model = pModel;
let panel = new SplitPanel();
panel.id = 'main';
panel.orientation = SplitPanel.Horizontal;
panel.spacing = 0;
SplitPanel.setStretch(palette, 0);
SplitPanel.setStretch(nbWidget, 1);
panel.attach(document.body);
panel.addChild(palette);
panel.addChild(nbWidget);
window.onresize = () => { panel.update(); };
let kernelspecs: IKernelSpecIds;
let items: IStandardPaletteItemOptions[] = [
{
category: 'Notebook',
text: 'Save',
shortcut: 'Accel S',
handler: () => { nbManager.save() ; }
},
{
category: 'Notebook',
text: 'Switch Kernel',
handler: () => {
if (!kernelspecs) {
return;
}
selectKernel(nbWidget.node, nbModel.kernelspec.name, kernelspecs)
.then(name => {
if (name) {
nbModel.session.changeKernel({name});
}
});
}
},
{
category: 'Notebook',
text: 'Interrupt Kernel',
shortcut: 'I I',
handler: () => { nbManager.interrupt() ; }
},
{
category: 'Notebook',
text: 'Restart Kernel',
shortcut: '0 0',
handler: () => { nbManager.restart() ; }
},
{
category: 'Notebook',
text: 'Trust Notebook',
handler: () => {
trustNotebook(nbModel, nbWidget.node);
}
},
{
category: 'Notebook Cell',
text: 'Run and Advance',
shortcut: 'Shift Enter',
//.........这里部分代码省略.........
示例7: main
function main(): void {
// Initialize the keymap manager with the bindings.
var keymap = new KeymapManager();
// Setup the keydown listener for the document.
document.addEventListener('keydown', event => {
keymap.processKeydownEvent(event);
});
let contents = new ContentsManager(SERVER_URL);
let rendermime = new RenderMime<Widget>();
const transformers = [
new JavascriptRenderer(),
new HTMLRenderer(),
new ImageRenderer(),
new SVGRenderer(),
new LatexRenderer(),
new ConsoleTextRenderer(),
new TextRenderer(),
new MarkdownRenderer()
];
for (let t of transformers) {
for (let m of t.mimetypes) {
rendermime.order.push(m);
rendermime.renderers[m] = t;
}
}
let consoleModel = new ConsoleModel();
let consoleWidget = new ConsolePanel(consoleModel, rendermime);
consoleWidget.title.text = TITLE;
let pModel = new StandardPaletteModel();
let palette = new CommandPalette();
palette.model = pModel;
let panel = new SplitPanel();
panel.id = 'main';
panel.orientation = SplitPanel.Horizontal;
panel.spacing = 0;
SplitPanel.setStretch(palette, 0);
SplitPanel.setStretch(consoleWidget, 1);
panel.attach(document.body);
panel.addChild(palette);
panel.addChild(consoleWidget);
window.onresize = () => { panel.update(); };
let kernelspecs: IKernelSpecIds;
let items: IStandardPaletteItemOptions[] = [
{
category: 'Console',
text: 'Execute Prompt',
shortcut: 'Shift Enter',
handler: () => { consoleModel.run(); }
}
];
pModel.addItems(items);
let bindings = [
{
selector: '.jp-Console',
sequence: ['Shift Enter'],
handler: () => { consoleModel.run(); }
}
]
keymap.add(bindings);
getKernelSpecs({}).then(specs => {
kernelspecs = specs;
let kernelName = specs.default;
let language = specs.default;
console.log('specs', specs);
return startNewSession({
notebookPath: 'fake_path',
kernelName: findKernel(kernelName, language, specs),
baseUrl: SERVER_URL
});
}).then(session => consoleModel.session = session);
}