本文整理匯總了TypeScript中@jupyterlab/docregistry.IDocumentRegistry.creators方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript IDocumentRegistry.creators方法的具體用法?TypeScript IDocumentRegistry.creators怎麽用?TypeScript IDocumentRegistry.creators使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@jupyterlab/docregistry.IDocumentRegistry
的用法示例。
在下文中一共展示了IDocumentRegistry.creators方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: populateCreators
/**
* Populate the command palette and the file menu with the registered creators.
*/
function populateCreators(app: JupyterLab, docManager: IDocumentManager, registry: IDocumentRegistry, palette: ICommandPalette, menu: Menu): void {
const category = 'File Operations';
// Clear any previously added creator palette items.
if (Private.creators) {
Private.creators.dispose();
}
Private.creators = new DisposableSet();
// Add the "create from" commands.
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 }));
});
}
示例2: activateFileBrowser
/**
* Activate the file browser in the sidebar.
*/
function activateFileBrowser(app: JupyterLab, factory: IFileBrowserFactory, manager: IServiceManager, documentManager: IDocumentManager, registry: IDocumentRegistry, mainMenu: IMainMenu, palette: ICommandPalette, restorer: ILayoutRestorer): void {
const { commands } = app;
const category = 'File Operations';
const fbWidget = factory.createFileBrowser('filebrowser', {
commands: commands,
documentManager: documentManager,
serviceManager: manager
});
// Let the application restorer track the primary file browser (that is
// automatically created) for restoration of application state (e.g. setting
// the file browser as the current side bar widget).
//
// All other file browsers created by using the factory function are
// responsible for their own restoration behavior, if any.
restorer.add(fbWidget, namespace);
let creatorCmds: { [key: string]: DisposableSet } = Object.create(null);
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 }));
};
each(registry.creators(), creator => { addCreator(creator.name); });
// Add a context menu to the dir listing.
let node = fbWidget.node.getElementsByClassName('jp-DirListing-content')[0];
node.addEventListener('contextmenu', (event: MouseEvent) => {
event.preventDefault();
let path = fbWidget.pathForClick(event) || '';
let ext = DocumentRegistry.extname(path);
let factories = registry.preferredWidgetFactories(ext);
let widgetNames = toArray(map(factories, factory => factory.name));
let prefix = `${namespace}-contextmenu-${++Private.id}`;
let openWith: Menu = null;
if (path && widgetNames.length > 1) {
let disposables = new DisposableSet();
let command: string;
openWith = new Menu({ commands });
openWith.title.label = 'Open With...';
openWith.disposed.connect(() => { disposables.dispose(); });
for (let widgetName of widgetNames) {
command = `${prefix}:${widgetName}`;
disposables.add(commands.addCommand(command, {
execute: () => fbWidget.openPath(path, widgetName),
label: widgetName
}));
openWith.addItem({ command });
}
}
let menu = createContextMenu(fbWidget, openWith);
menu.open(event.clientX, event.clientY);
});
addCommands(app, fbWidget);
let menu = createMenu(app, Object.keys(creatorCmds));
mainMenu.addMenu(menu, { rank: 1 });
fbWidget.title.label = 'Files';
app.shell.addToLeftArea(fbWidget, { rank: 100 });
// If the layout is a fresh session without saved data, open file browser.
app.restored.then(layout => {
if (layout.fresh) {
app.commands.execute(CommandIDs.showBrowser, void 0);
}
});
// Handle fileCreator items as they are added.
registry.changed.connect((sender, args) => {
if (args.type === 'fileCreator') {
menu.dispose();
let name = args.name;
if (args.change === 'added') {
addCreator(name);
} else {
creatorCmds[name].dispose();
delete creatorCmds[name];
}
menu = createMenu(app, Object.keys(creatorCmds));
mainMenu.addMenu(menu, { rank: 1 });
}
});
}