本文整理汇总了TypeScript中@jupyterlab/application.ILayoutRestorer类的典型用法代码示例。如果您正苦于以下问题:TypeScript ILayoutRestorer类的具体用法?TypeScript ILayoutRestorer怎么用?TypeScript ILayoutRestorer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ILayoutRestorer类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: activate
/**
* Activate the table widget extension.
*/
function activate(app: JupyterLab, restorer: ILayoutRestorer): void {
const factory = new CSVViewerFactory({
name: FACTORY,
fileTypes: ['csv'],
defaultFor: ['csv'],
readOnly: true
});
const tracker = new InstanceTracker<CSVViewer>({ namespace: 'csvviewer' });
// Handle state restoration.
restorer.restore(tracker, {
command: 'docmanager:open',
args: widget => ({ path: widget.context.path, factory: FACTORY }),
name: widget => widget.context.path
});
app.docRegistry.addWidgetFactory(factory);
let ft = app.docRegistry.getFileType('csv');
factory.widgetCreated.connect((sender, widget) => {
// Track the widget.
tracker.add(widget);
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => { tracker.save(widget); });
if (ft) {
widget.title.iconClass = ft.iconClass;
widget.title.iconLabel = ft.iconLabel;
}
});
}
示例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: activate
/**
* Activate the image widget extension.
*/
function activate(
app: JupyterLab,
palette: ICommandPalette,
restorer: ILayoutRestorer
): IImageTracker {
const namespace = 'image-widget';
const factory = new ImageViewerFactory({
name: FACTORY,
modelName: 'base64',
fileTypes: FILE_TYPES,
defaultFor: FILE_TYPES,
readOnly: true
});
const tracker = new InstanceTracker<IDocumentWidget<ImageViewer>>({
namespace
});
// Handle state restoration.
restorer.restore(tracker, {
command: 'docmanager:open',
args: widget => ({ path: widget.context.path, factory: FACTORY }),
name: widget => widget.context.path
});
app.docRegistry.addWidgetFactory(factory);
factory.widgetCreated.connect((sender, widget) => {
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => {
tracker.save(widget);
});
tracker.add(widget);
const types = app.docRegistry.getFileTypesForPath(widget.context.path);
if (types.length > 0) {
widget.title.iconClass = types[0].iconClass;
widget.title.iconLabel = types[0].iconLabel;
}
});
addCommands(app, tracker);
const category = 'Image Viewer';
[
CommandIDs.zoomIn,
CommandIDs.zoomOut,
CommandIDs.resetImage,
CommandIDs.rotateClockwise,
CommandIDs.rotateCounterclockwise,
CommandIDs.flipHorizontal,
CommandIDs.flipVertical,
CommandIDs.invertColors
].forEach(command => {
palette.addItem({ command, category });
});
return tracker;
}
示例5: 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 });
}
示例6: 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');
}
示例7: activate
/**
* Activate the terminal plugin.
*/
function activate(app: JupyterLab, mainMenu: IMainMenu, palette: ICommandPalette, restorer: ILayoutRestorer, launcher: ILauncher | null): ITerminalTracker {
const { commands, serviceManager } = app;
const category = 'Terminal';
const namespace = 'terminal';
const tracker = new InstanceTracker<MainAreaWidget<Terminal>>({ 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.
restorer.restore(tracker, {
command: CommandIDs.createNew,
args: widget => ({ name: widget.content.session.name }),
name: widget => widget.content.session && widget.content.session.name
});
addCommands(app, serviceManager, tracker);
// Add some commands to the application view menu.
const viewGroup = [
CommandIDs.increaseFont,
CommandIDs.decreaseFont,
CommandIDs.toggleTheme
].map(command => { return { command }; });
mainMenu.viewMenu.addGroup(viewGroup, 30);
// Add command palette items.
[
CommandIDs.createNew,
CommandIDs.refresh,
CommandIDs.increaseFont,
CommandIDs.decreaseFont,
CommandIDs.toggleTheme
].forEach(command => {
palette.addItem({ command, category, args: { 'isPalette': true } });
});
// Add terminal creation to the file menu.
mainMenu.fileMenu.newMenu.addGroup([{ command: CommandIDs.createNew }], 20);
// Add a launcher item if the launcher is available.
if (launcher) {
launcher.add({
displayName: 'Terminal',
category: 'Other',
rank: 0,
iconClass: TERMINAL_ICON_CLASS,
callback: () => commands.execute(CommandIDs.createNew)
});
}
app.contextMenu.addItem({command: CommandIDs.refresh, selector: '.jp-Terminal', rank: 1});
return tracker;
}
示例8: activateCsv
/**
* Activate cssviewer extension for CSV files
*/
function activateCsv(
app: JupyterLab,
restorer: ILayoutRestorer,
themeManager: IThemeManager
): void {
const factory = new CSVViewerFactory({
name: FACTORY_CSV,
fileTypes: ['csv'],
defaultFor: ['csv'],
readOnly: true
});
const tracker = new InstanceTracker<IDocumentWidget<CSVViewer>>({
namespace: 'csvviewer'
});
// The current styles for the data grids.
let style: DataGrid.IStyle = Private.LIGHT_STYLE;
let renderer: TextRenderer = Private.LIGHT_RENDERER;
// Handle state restoration.
restorer.restore(tracker, {
command: 'docmanager:open',
args: widget => ({ path: widget.context.path, factory: FACTORY_CSV }),
name: widget => widget.context.path
});
app.docRegistry.addWidgetFactory(factory);
let ft = app.docRegistry.getFileType('csv');
factory.widgetCreated.connect((sender, widget) => {
// Track the widget.
tracker.add(widget);
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => {
tracker.save(widget);
});
if (ft) {
widget.title.iconClass = ft.iconClass;
widget.title.iconLabel = ft.iconLabel;
}
// Set the theme for the new widget.
widget.content.style = style;
widget.content.renderer = renderer;
});
// Keep the themes up-to-date.
const updateThemes = () => {
const isLight = themeManager.isLight(themeManager.theme);
style = isLight ? Private.LIGHT_STYLE : Private.DARK_STYLE;
renderer = isLight ? Private.LIGHT_RENDERER : Private.DARK_RENDERER;
tracker.forEach(grid => {
grid.content.style = style;
grid.content.renderer = renderer;
});
};
themeManager.themeChanged.connect(updateThemes);
}
示例9: newInspectorPanel
activate: (app: JupyterLab, palette: ICommandPalette, restorer: ILayoutRestorer): IInspector => {
const { commands, shell } = app;
const manager = new InspectorManager();
const category = 'Inspector';
const command = CommandIDs.open;
const label = 'Open Inspector';
const namespace = 'inspector';
const tracker = new InstanceTracker<InspectorPanel>({ namespace });
/**
* Create and track a new inspector.
*/
function newInspectorPanel(): InspectorPanel {
const inspector = new InspectorPanel();
inspector.id = 'jp-inspector';
inspector.title.label = 'Inspector';
inspector.title.closable = true;
inspector.disposed.connect(() => {
if (manager.inspector === inspector) {
manager.inspector = null;
}
});
// Track the inspector.
tracker.add(inspector);
// Add the default inspector child items.
Private.defaultInspectorItems.forEach(item => { inspector.add(item); });
return inspector;
}
// Handle state restoration.
restorer.restore(tracker, {
command,
args: () => null,
name: () => 'inspector'
});
// Add command to registry and palette.
commands.addCommand(command, {
label,
execute: () => {
if (!manager.inspector || manager.inspector.isDisposed) {
manager.inspector = newInspectorPanel();
shell.addToMainArea(manager.inspector);
}
if (manager.inspector.isAttached) {
shell.activateById(manager.inspector.id);
}
}
});
palette.addItem({ command, category });
return manager;
}
示例10: 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;
};