當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript apputils.ILayoutRestorer類代碼示例

本文整理匯總了TypeScript中@jupyterlab/apputils.ILayoutRestorer的典型用法代碼示例。如果您正苦於以下問題:TypeScript ILayoutRestorer類的具體用法?TypeScript ILayoutRestorer怎麽用?TypeScript ILayoutRestorer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ILayoutRestorer類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: activate

/**
 * Activate the table widget extension.
 */
function activate(app: JupyterLab, registry: IDocumentRegistry, restorer: ILayoutRestorer): void {
  const factory = new CSVViewerFactory({
    name: FACTORY,
    fileExtensions: ['.csv'],
    defaultFor: ['.csv']
  });
  const tracker = new InstanceTracker<CSVViewer>({
    namespace: 'csvviewer',
    shell: app.shell
  });

  // Handle state restoration.
  restorer.restore(tracker, {
    command: 'file-operations:open',
    args: widget => ({ path: widget.context.path, factory: FACTORY }),
    name: widget => widget.context.path
  });

  registry.addWidgetFactory(factory);
  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); });
  });
}
開發者ID:charnpreetsingh185,項目名稱:jupyterlab,代碼行數:29,代碼來源:index.ts

示例2: activate

/**
 * Activate the image widget extension.
 */
function activate(app: JupyterLab, registry: IDocumentRegistry, palette: ICommandPalette, restorer: ILayoutRestorer): IImageTracker {
  const namespace = 'image-widget';
  const factory = new ImageWidgetFactory({
    name: FACTORY,
    modelName: 'base64',
    fileExtensions: EXTENSIONS,
    defaultFor: EXTENSIONS
  });
  const { shell } = app;
  const tracker = new InstanceTracker<ImageWidget>({ namespace, shell });

  // Handle state restoration.
  restorer.restore(tracker, {
    command: 'file-operations:open',
    args: widget => ({ path: widget.context.path, factory: FACTORY }),
    name: widget => widget.context.path
  });

  registry.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);
  });

  let category = 'Image Widget';
  [CommandIDs.zoomIn, CommandIDs.zoomOut, CommandIDs.resetZoom]
    .forEach(command => { palette.addItem({ command, category }); });

  return tracker;
}
開發者ID:faricacarroll,項目名稱:jupyterlab,代碼行數:35,代碼來源:index.ts

示例3: 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();
    });
  },
開發者ID:charnpreetsingh185,項目名稱:jupyterlab,代碼行數:31,代碼來源:index.ts

示例4: activateFileBrowser

/**
 * Activate the file browser in the sidebar.
 */
function activateFileBrowser(app: JupyterLab, factory: IFileBrowserFactory, docManager: IDocumentManager, mainMenu: IMainMenu, palette: ICommandPalette, restorer: ILayoutRestorer): void {
  const { commands } = app;
  const fbWidget = factory.createFileBrowser('filebrowser', {
    commands,
    documentManager: docManager
  });

  // 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.model.pathChanged.connect((sender: any, args: IChangedArgs<string>) => {
    docManager.cwd = args.newValue;
  });

  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);
    }
  });
}
開發者ID:eskirk,項目名稱:jupyterlab,代碼行數:34,代碼來源:index.ts

示例5: activate

/**
 * Activate the markdown plugin.
 */
function activate(app: JupyterLab, registry: IDocumentRegistry, rendermime: IRenderMime, restorer: ILayoutRestorer) {
    const factory = new MarkdownWidgetFactory({
      name: FACTORY,
      fileExtensions: ['.md'],
      rendermime
    });
    const shell = app.shell;
    const namespace = 'rendered-markdown';
    const tracker = new InstanceTracker<MarkdownWidget>({ namespace, shell });

    // Handle state restoration.
    restorer.restore(tracker, {
      command: 'file-operations:open',
      args: widget => ({ path: widget.context.path, factory: FACTORY }),
      name: widget => widget.context.path
    });

    factory.widgetCreated.connect((sender, widget) => {
      widget.title.icon = TEXTEDITOR_ICON_CLASS;
      // Notify the instance tracker if restore data needs to update.
      widget.context.pathChanged.connect(() => { tracker.save(widget); });
      tracker.add(widget);
    });

    registry.addWidgetFactory(factory);
  }
開發者ID:faricacarroll,項目名稱:jupyterlab,代碼行數:29,代碼來源:index.ts

示例6: activate

/**
 * Activate the running plugin.
 */
function activate(app: JupyterLab, services: IServiceManager, restorer: ILayoutRestorer): void {
  let running = new RunningSessions({ manager: services });
  running.id = 'jp-running-sessions';
  running.title.label = 'Running';

  // 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).
  restorer.add(running, 'running-sessions');

  running.sessionOpenRequested.connect((sender, model) => {
    let path = model.notebook.path;
    let name = path.split('/').pop();
    if (CONSOLE_REGEX.test(name)) {
      app.commands.execute('console:open', { id: model.id });
    } else {
      app.commands.execute('file-operations: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.addToLeftArea(running, { rank: 200 });
}
開發者ID:charnpreetsingh185,項目名稱:jupyterlab,代碼行數:32,代碼來源:index.ts

示例7: activate

/**
 * Activate the launcher.
 */
function activate(app: JupyterLab, services: IServiceManager, palette: ICommandPalette, linker: ICommandLinker, restorer: ILayoutRestorer): ILauncher {
  const { commands, shell } = app;

  let model = new LauncherModel();
  let widget = new LauncherWidget({ linker });

  widget.model = model;
  widget.id = 'launcher';
  widget.title.label = 'Launcher';

  // Let the application restorer track the launcher for restoration of
  // application state (e.g. setting the launcher as the current side bar
  // widget).
  restorer.add(widget, 'launcher');

  commands.addCommand(CommandIDs.show, {
    label: 'Show Launcher',
    execute: () => {
      if (!widget.isAttached) {
        shell.addToLeftArea(widget);
      }
      shell.activateById(widget.id);
    }
  });
  palette.addItem({ command: CommandIDs.show, category: 'Help' });

  shell.addToLeftArea(widget);

  return model;
}
開發者ID:charnpreetsingh185,項目名稱:jupyterlab,代碼行數:33,代碼來源:index.ts

示例8: 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 tracker = new InstanceTracker<InspectorPanel>({
      namespace: 'inspector',
      shell
    });

    /**
     * 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) {
          tracker.activate(manager.inspector);
        }
      }
    });
    palette.addItem({ command, category });

    return manager;
  }
開發者ID:samvasko,項目名稱:jupyterlab,代碼行數:59,代碼來源:index.ts

示例9: activate

/**
 * Activate the landing plugin.
 */
function activate(app: JupyterLab, linker: ICommandLinker, palette: ICommandPalette, services: IServiceManager, restorer: ILayoutRestorer): void {
  const { commands, shell } = app;
  const category = 'Help';
  const command = CommandIDs.open;
  const model = new LandingModel(services.terminals.isAvailable());
  const tracker = new InstanceTracker<LandingWidget>({
    namespace: 'landing',
    shell
  });

  // Handle state restoration.
  restorer.restore(tracker, {
    command,
    args: () => null,
    name: () => 'landing'
  });

  let widget: LandingWidget;

  function newWidget(): LandingWidget {
    let widget = new LandingWidget(linker);
    widget.model = model;
    widget.id = 'landing-jupyterlab';
    widget.title.label = 'Landing';
    widget.title.closable = true;
    widget.addClass(LANDING_CLASS);
    tracker.add(widget);
    return widget;
  }

  commands.addCommand(command, {
    label: 'Open Landing',
    execute: () => {
      if (!widget || widget.isDisposed) {
        widget = newWidget();
        shell.addToMainArea(widget);
      }
      tracker.activate(widget);
    }
  });

  palette.addItem({ category, command });

  // Only create a landing page if there are no other tabs open.
  app.restored.then(() => {
    if (shell.isEmpty('main')) {
      commands.execute(command, void 0);
    }
  });
}
開發者ID:charnpreetsingh185,項目名稱:jupyterlab,代碼行數:53,代碼來源:index.ts

示例10: activate

/**
 * Activate the editor tracker plugin.
 */
function activate(app: JupyterLab, registry: IDocumentRegistry, restorer: ILayoutRestorer, editorServices: IEditorServices, launcher: ILauncher | null): IEditorTracker {
  const factory = new EditorWidgetFactory({
    editorServices,
    factoryOptions: {
      name: FACTORY,
      fileExtensions: ['*'],
      defaultFor: ['*']
    }
  });
  const shell = app.shell;
  const tracker = new InstanceTracker<EditorWidget>({
    namespace: 'editor',
    shell
  });

  // Handle state restoration.
  restorer.restore(tracker, {
    command: 'file-operations:open',
    args: widget => ({ path: widget.context.path, factory: FACTORY }),
    name: widget => widget.context.path
  });

  factory.widgetCreated.connect((sender, widget) => {
    widget.title.icon = EDITOR_ICON_CLASS;
    // Notify the instance tracker if restore data needs to update.
    widget.context.pathChanged.connect(() => { tracker.save(widget); });
    tracker.add(widget);
  });
  registry.addWidgetFactory(factory);

  addDefaultCommands(tracker, app.commands);

  // Add a launcher item if the launcher is available.
  if (launcher) {
    launcher.add({
      name: 'Text Editor',
      command: 'filebrowser:new-text-file'
    });
  }

  return tracker;
}
開發者ID:samvasko,項目名稱:jupyterlab,代碼行數:45,代碼來源:index.ts


注:本文中的@jupyterlab/apputils.ILayoutRestorer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。