本文整理汇总了TypeScript中@jupyterlab/application.ILayoutRestorer.add方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ILayoutRestorer.add方法的具体用法?TypeScript ILayoutRestorer.add怎么用?TypeScript ILayoutRestorer.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@jupyterlab/application.ILayoutRestorer
的用法示例。
在下文中一共展示了ILayoutRestorer.add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: activate
/**
* Activate the running plugin.
*/
function activate(
app: JupyterFrontEnd,
restorer: ILayoutRestorer | null
): void {
let running = new RunningSessions({ manager: app.serviceManager });
running.id = 'jp-running-sessions';
running.title.iconClass = 'jp-DirectionsRunIcon jp-SideBar-tabIcon';
running.title.caption = 'Running Terminals and Kernels';
// Let the application restorer track the running panel for restoration of
// application state (e.g. setting the running panel as the current side bar
// widget).
if (restorer) {
restorer.add(running, 'running-sessions');
}
running.sessionOpenRequested.connect((sender, model) => {
let path = model.path;
if (model.type.toLowerCase() === 'console') {
app.commands.execute('console:open', { path });
} else {
app.commands.execute('docmanager:open', { path });
}
});
running.terminalOpenRequested.connect((sender, model) => {
app.commands.execute('terminal:open', { name: model.name });
});
// Rank has been chosen somewhat arbitrarily to give priority to the running
// sessions widget in the sidebar.
app.shell.add(running, 'left', { rank: 200 });
}
示例2: each
activate: (app: JupyterLab, restorer: ILayoutRestorer): void => {
const { shell } = app;
const tabs = new TabBar<Widget>({ orientation: 'vertical' });
const header = document.createElement('header');
restorer.add(tabs, 'tab-manager');
tabs.id = 'tab-manager';
tabs.title.label = 'Tabs';
header.textContent = 'Open Tabs';
tabs.node.insertBefore(header, tabs.contentNode);
shell.addToLeftArea(tabs, { rank: 600 });
app.restored.then(() => {
const populate = () => {
tabs.clearTabs();
each(shell.widgets('main'), widget => { tabs.addTab(widget.title); });
};
// Connect signal handlers.
shell.layoutModified.connect(() => { populate(); });
tabs.tabActivateRequested.connect((sender, tab) => {
shell.activateById(tab.title.owner.id);
});
tabs.tabCloseRequested.connect((sender, tab) => {
tab.title.owner.close();
});
// Populate the tab manager.
populate();
});
},
示例3: activateFileBrowser
/**
* Activate the default file browser in the sidebar.
*/
function activateFileBrowser(app: JupyterLab, factory: IFileBrowserFactory, docManager: IDocumentManager, palette: ICommandPalette, restorer: ILayoutRestorer): void {
const fbWidget = factory.defaultBrowser;
// 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);
addCommands(app, factory.tracker, fbWidget);
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);
}
});
// Create a launcher if there are no open items.
app.shell.layoutModified.connect(() => {
if (app.shell.isEmpty('main')) {
// Make sure the model is restored.
fbWidget.model.restored.then(() => {
app.commands.execute('launcher:create', {
cwd: fbWidget.model.path
});
});
}
});
}
示例4: ExtensionView
const createView = () => {
const v = new ExtensionView(serviceManager);
v.id = 'extensionmanager.main-view';
v.title.iconClass = 'jp-ExtensionIcon jp-SideBar-tabIcon';
v.title.caption = 'Extension Manager';
restorer.add(v, v.id);
return v;
};
示例5: restorePalette
function restorePalette(app: JupyterLab, restorer: ILayoutRestorer): void {
const palette = Private.createPalette(app);
// Let the application restorer track the command palette for restoration of
// application state (e.g. setting the command palette as the current side bar
// widget).
restorer.add(palette, 'command-palette');
}
示例6: each
activate: (
app: JupyterFrontEnd,
labShell: ILabShell | null,
restorer: ILayoutRestorer | null
): void => {
const { shell } = app;
const tabs = new TabBar<Widget>({ orientation: 'vertical' });
const header = document.createElement('header');
if (restorer) {
restorer.add(tabs, 'tab-manager');
}
tabs.id = 'tab-manager';
tabs.title.iconClass = 'jp-TabIcon jp-SideBar-tabIcon';
tabs.title.caption = 'Open Tabs';
header.textContent = 'Open Tabs';
tabs.node.insertBefore(header, tabs.contentNode);
shell.add(tabs, 'left', { rank: 600 });
void app.restored.then(() => {
const populate = () => {
tabs.clearTabs();
each(shell.widgets('main'), widget => {
tabs.addTab(widget.title);
});
};
// Connect signal handlers.
tabs.tabActivateRequested.connect((sender, tab) => {
shell.activateById(tab.title.owner.id);
});
tabs.tabCloseRequested.connect((sender, tab) => {
tab.title.owner.close();
populate();
});
// If available, connect to the shell's layout modified signal.
if (labShell) {
labShell.layoutModified.connect(() => {
populate();
});
}
// Populate the tab manager.
populate();
});
},
示例7: activateBrowser
/**
* Activate the default file browser in the sidebar.
*/
function activateBrowser(
app: JupyterLab,
factory: IFileBrowserFactory,
restorer: ILayoutRestorer
): void {
const browser = factory.defaultBrowser;
const { commands, shell } = app;
// 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(browser, namespace);
addCommands(app, factory.tracker, browser);
browser.title.iconClass = 'jp-FolderIcon jp-SideBar-tabIcon';
browser.title.caption = 'File Browser';
shell.addToLeftArea(browser, { rank: 100 });
// If the layout is a fresh session without saved data, open file browser.
app.restored.then(layout => {
if (layout.fresh) {
commands.execute(CommandIDs.showBrowser, void 0);
}
});
Promise.all([app.restored, browser.model.restored]).then(() => {
function maybeCreate() {
// Create a launcher if there are no open items.
if (app.shell.isEmpty('main')) {
createLauncher(commands, browser);
}
}
// When layout is modified, create a launcher if there are no open items.
shell.layoutModified.connect(() => {
maybeCreate();
});
maybeCreate();
});
}
示例8: activatePalette
function activatePalette(app: JupyterLab, restorer: ILayoutRestorer): ICommandPalette {
const { commands, shell } = app;
const palette = new CommandPalette({ commands });
// Let the application restorer track the command palette for restoration of
// application state (e.g. setting the command palette as the current side bar
// widget).
restorer.add(palette, 'command-palette');
palette.id = 'command-palette';
palette.title.label = 'Commands';
commands.addCommand(CommandIDs.activate, {
execute: () => { shell.activateById(palette.id); },
label: 'Activate Command Palette'
});
commands.addCommand(CommandIDs.hide, {
execute: () => {
if (!palette.isHidden) {
shell.collapseLeft();
}
},
label: 'Hide Command Palette'
});
commands.addCommand(CommandIDs.toggle, {
execute: () => {
if (palette.isHidden) {
return commands.execute(CommandIDs.activate, void 0);
}
return commands.execute(CommandIDs.hide, void 0);
},
label: 'Toggle Command Palette'
});
palette.inputNode.placeholder = 'SEARCH';
shell.addToLeftArea(palette);
return new Palette(palette);
}
示例9: async
activate: async (
app: JupyterLab,
registry: ISettingRegistry,
restorer: ILayoutRestorer,
router: IRouter
) => {
const settings = await registry.load(plugin.id);
let enabled = settings.composite['enabled'] === true;
const { shell, serviceManager } = app;
const view = new ExtensionView(serviceManager);
view.id = 'extensionmanager.main-view';
view.title.label = 'Extensions';
restorer.add(view, view.id);
if (enabled) {
shell.addToLeftArea(view);
}
// If the extension is enabled or disabled,
// add or remove it from the left area.
app.restored.then(() => {
settings.changed.connect(async () => {
enabled = settings.composite['enabled'] === true;
if (enabled && !view.isAttached) {
const accepted = await Private.showWarning();
if (!accepted) {
settings.set('enabled', false);
return;
}
shell.addToLeftArea(view);
} else if (!enabled && view.isAttached) {
view.close();
}
});
});
addCommands(app, view);
}
示例10: activateBrowser
/**
* Activate the default file browser in the sidebar.
*/
function activateBrowser(
app: JupyterFrontEnd,
factory: IFileBrowserFactory,
docManager: IDocumentManager,
labShell: ILabShell,
restorer: ILayoutRestorer,
settingRegistry: ISettingRegistry
): void {
const browser = factory.defaultBrowser;
const { commands } = app;
// 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(browser, namespace);
addCommands(app, factory, labShell, docManager);
browser.title.iconClass = 'jp-FolderIcon jp-SideBar-tabIcon';
browser.title.caption = 'File Browser';
labShell.add(browser, 'left', { rank: 100 });
// If the layout is a fresh session without saved data, open file browser.
labShell.restored.then(layout => {
if (layout.fresh) {
commands.execute(CommandIDs.showBrowser, void 0);
}
});
Promise.all([app.restored, browser.model.restored]).then(() => {
function maybeCreate() {
// Create a launcher if there are no open items.
if (labShell.isEmpty('main')) {
Private.createLauncher(commands, browser);
}
}
// When layout is modified, create a launcher if there are no open items.
labShell.layoutModified.connect(() => {
maybeCreate();
});
let navigateToCurrentDirectory: boolean = false;
settingRegistry
.load('@jupyterlab/filebrowser-extension:browser')
.then(settings => {
settings.changed.connect(settings => {
navigateToCurrentDirectory = settings.get(
'navigateToCurrentDirectory'
).composite as boolean;
});
navigateToCurrentDirectory = settings.get('navigateToCurrentDirectory')
.composite as boolean;
});
// Whether to automatically navigate to a document's current directory
labShell.currentChanged.connect((_, change) => {
if (navigateToCurrentDirectory && change.newValue) {
const { newValue } = change;
const context = docManager.contextForWidget(newValue);
if (context) {
const { path } = context;
Private.navigateToPath(path, factory)
.then(() => {
labShell.currentWidget.activate();
})
.catch((reason: any) => {
console.warn(
`${CommandIDs.navigate} failed to open: ${path}`,
reason
);
});
}
}
});
maybeCreate();
});
}