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


TypeScript mainmenu.TabsMenu類代碼示例

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


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

示例1: createTabsMenu

function createTabsMenu(app: JupyterLab, menu: TabsMenu): void {
  const commands = app.commands;

  // Add commands for cycling the active tabs.
  menu.addGroup([
    { command: 'application:activate-next-tab' },
    { command: 'application:activate-previous-tab' }
  ], 0);


  let tabGroup: Menu.IItemOptions[] = [];

  // Utility function to create a command to activate
  // a given tab, or get it if it already exists.
  const createMenuItem = (widget: Widget): Menu.IItemOptions => {
    const commandID = `tabmenu:activate-${widget.id}`;
    if (!commands.hasCommand(commandID)) {
      commands.addCommand(commandID, {
        label: () => widget.title.label,
        isVisible: () => !widget.isDisposed,
        isEnabled: () => !widget.isDisposed,
        isToggled: () => app.shell.currentWidget === widget,
        execute: () => app.shell.activateById(widget.id)
      });
    }
    return { command: commandID };
  };

  app.restored.then(() => {
    // Iterate over the current widgets in the
    // main area, and add them to the tab group
    // of the menu.
    const populateTabs = () => {
      menu.removeGroup(tabGroup);
      tabGroup.length = 0;
      each(app.shell.widgets('main'), widget => {
        tabGroup.push(createMenuItem(widget));
      });
      menu.addGroup(tabGroup, 1);
    };
    populateTabs();
    app.shell.layoutModified.connect(() => { populateTabs(); });
  });
}
開發者ID:7125messi,項目名稱:jupyterlab,代碼行數:44,代碼來源:index.ts

示例2: createTabsMenu

export function createTabsMenu(app: JupyterLab, menu: TabsMenu): void {
  const commands = app.commands;

  // Add commands for cycling the active tabs.
  menu.addGroup(
    [
      { command: 'application:activate-next-tab' },
      { command: 'application:activate-previous-tab' },
      { command: CommandIDs.activatePreviouslyUsedTab }
    ],
    0
  );

  // A list of the active tabs in the main area.
  const tabGroup: Menu.IItemOptions[] = [];
  // A disposable for getting rid of the out-of-date tabs list.
  let disposable: IDisposable;

  // Utility function to create a command to activate
  // a given tab, or get it if it already exists.
  const createMenuItem = (widget: Widget): Menu.IItemOptions => {
    const commandID = `tabmenu:activate-${widget.id}`;
    if (!commands.hasCommand(commandID)) {
      commands.addCommand(commandID, {
        label: () => widget.title.label,
        isVisible: () => !widget.isDisposed,
        isEnabled: () => !widget.isDisposed,
        isToggled: () => app.shell.currentWidget === widget,
        execute: () => app.shell.activateById(widget.id)
      });
    }
    return { command: commandID };
  };

  let previousId = '';

  // Command to toggle between the current
  // tab and the last modified tab.
  commands.addCommand(CommandIDs.activatePreviouslyUsedTab, {
    label: 'Activate Previously Used Tab',
    isEnabled: () => !!previousId,
    execute: () =>
      previousId && app.commands.execute(`tabmenu:activate-${previousId}`)
  });

  app.restored.then(() => {
    // Iterate over the current widgets in the
    // main area, and add them to the tab group
    // of the menu.
    const populateTabs = () => {
      // remove the previous tab list
      if (disposable && !disposable.isDisposed) {
        disposable.dispose();
      }
      tabGroup.length = 0;

      let isPreviouslyUsedTabAttached = false;
      each(app.shell.widgets('main'), widget => {
        if (widget.id === previousId) {
          isPreviouslyUsedTabAttached = true;
        }
        tabGroup.push(createMenuItem(widget));
      });
      disposable = menu.addGroup(tabGroup, 1);
      previousId = isPreviouslyUsedTabAttached ? previousId : '';
    };
    populateTabs();
    app.shell.layoutModified.connect(() => {
      populateTabs();
    });
    // Update the id of the previous active tab if
    // a new tab is selected.
    app.shell.currentChanged.connect((sender, args) => {
      let widget = args.oldValue;
      if (!widget) {
        return;
      }
      previousId = widget.id;
    });
  });
}
開發者ID:SylvainCorlay,項目名稱:jupyterlab,代碼行數:81,代碼來源:index.ts

示例3: createTabsMenu

export function createTabsMenu(
  app: JupyterFrontEnd,
  menu: TabsMenu,
  labShell: ILabShell | null
): void {
  const commands = app.commands;

  // Add commands for cycling the active tabs.
  menu.addGroup(
    [
      { command: 'application:activate-next-tab' },
      { command: 'application:activate-previous-tab' },
      { command: CommandIDs.activatePreviouslyUsedTab }
    ],
    0
  );

  // A list of the active tabs in the main area.
  const tabGroup: Menu.IItemOptions[] = [];
  // A disposable for getting rid of the out-of-date tabs list.
  let disposable: IDisposable;

  // Command to activate a widget by id.
  commands.addCommand(CommandIDs.activateById, {
    label: args => {
      const id = args['id'] || '';
      const widget = find(app.shell.widgets('main'), w => w.id === id);
      return (widget && widget.title.label) || '';
    },
    isToggled: args => {
      const id = args['id'] || '';
      return app.shell.currentWidget && app.shell.currentWidget.id === id;
    },
    execute: args => app.shell.activateById((args['id'] as string) || '')
  });

  let previousId = '';
  // Command to toggle between the current
  // tab and the last modified tab.
  commands.addCommand(CommandIDs.activatePreviouslyUsedTab, {
    label: 'Activate Previously Used Tab',
    isEnabled: () => !!previousId,
    execute: () => commands.execute(CommandIDs.activateById, { id: previousId })
  });

  if (labShell) {
    app.restored.then(() => {
      // Iterate over the current widgets in the
      // main area, and add them to the tab group
      // of the menu.
      const populateTabs = () => {
        // remove the previous tab list
        if (disposable && !disposable.isDisposed) {
          disposable.dispose();
        }
        tabGroup.length = 0;

        let isPreviouslyUsedTabAttached = false;
        each(app.shell.widgets('main'), widget => {
          if (widget.id === previousId) {
            isPreviouslyUsedTabAttached = true;
          }
          tabGroup.push({
            command: CommandIDs.activateById,
            args: { id: widget.id }
          });
        });
        disposable = menu.addGroup(tabGroup, 1);
        previousId = isPreviouslyUsedTabAttached ? previousId : '';
      };
      populateTabs();
      labShell.layoutModified.connect(() => {
        populateTabs();
      });
      // Update the ID of the previous active tab if a new tab is selected.
      labShell.currentChanged.connect((_, args) => {
        let widget = args.oldValue;
        if (!widget) {
          return;
        }
        previousId = widget.id;
      });
    });
  }
}
開發者ID:ellisonbg,項目名稱:jupyterlab,代碼行數:85,代碼來源:index.ts

示例4: each

 const populateTabs = () => {
   menu.removeGroup(tabGroup);
   tabGroup.length = 0;
   each(app.shell.widgets('main'), widget => {
     tabGroup.push(createMenuItem(widget));
   });
   menu.addGroup(tabGroup, 1);
 };
開發者ID:7125messi,項目名稱:jupyterlab,代碼行數:8,代碼來源:index.ts

示例5: each

 const populateTabs = () => {
   menu.removeGroup(tabGroup);
   tabGroup.length = 0;
   let isPreviouslyUsedTabAttached = false;
   each(app.shell.widgets('main'), widget => {
     if (widget.id === previousId) {
       isPreviouslyUsedTabAttached = true;
     }
     tabGroup.push(createMenuItem(widget));
   });
   menu.addGroup(tabGroup, 1);
   previousId = isPreviouslyUsedTabAttached ? previousId : '';
 };
開發者ID:groutr,項目名稱:jupyterlab,代碼行數:13,代碼來源:index.ts

示例6: each

    const populateTabs = () => {
      // remove the previous tab list
      if (disposable && !disposable.isDisposed) {
        disposable.dispose();
      }
      tabGroup.length = 0;

      let isPreviouslyUsedTabAttached = false;
      each(app.shell.widgets('main'), widget => {
        if (widget.id === previousId) {
          isPreviouslyUsedTabAttached = true;
        }
        tabGroup.push(createMenuItem(widget));
      });
      disposable = menu.addGroup(tabGroup, 1);
      previousId = isPreviouslyUsedTabAttached ? previousId : '';
    };
開發者ID:SylvainCorlay,項目名稱:jupyterlab,代碼行數:17,代碼來源:index.ts

示例7: each

      const populateTabs = () => {
        // remove the previous tab list
        if (disposable && !disposable.isDisposed) {
          disposable.dispose();
        }
        tabGroup.length = 0;

        let isPreviouslyUsedTabAttached = false;
        each(app.shell.widgets('main'), widget => {
          if (widget.id === previousId) {
            isPreviouslyUsedTabAttached = true;
          }
          tabGroup.push({
            command: CommandIDs.activateById,
            args: { id: widget.id }
          });
        });
        disposable = menu.addGroup(tabGroup, 1);
        previousId = isPreviouslyUsedTabAttached ? previousId : '';
      };
開發者ID:ellisonbg,項目名稱:jupyterlab,代碼行數:20,代碼來源:index.ts


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