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


TypeScript Menu.addItem方法代碼示例

本文整理匯總了TypeScript中phosphor/lib/ui/menu.Menu.addItem方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Menu.addItem方法的具體用法?TypeScript Menu.addItem怎麽用?TypeScript Menu.addItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在phosphor/lib/ui/menu.Menu的用法示例。


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

示例1: createMenu

/**
 * Create a menu for the editor.
 */
function createMenu(app: JupyterLab): Menu {
  const { commands, keymap } = app;
  const menu = new Menu({ commands, keymap });
  menu.title.label = 'Editor';

  menu.addItem({ command: 'file-operations:new-text-file' });
  menu.addItem({ command: 'file-operations:save' });
  menu.addItem({ command: cmdIds.closeAll });
  menu.addItem({ type: 'separator' });

  return menu;
}
開發者ID:TypeFox,項目名稱:jupyterlab,代碼行數:15,代碼來源:plugin.ts

示例2: createMenu

  /**
   * Create a menu for the help plugin.
   */
  function createMenu(): Menu {
    let { commands, keymap } = app;
    let menu = new Menu({ commands, keymap });
    menu.title.label = category;

    menu.addItem({ command: 'about-jupyterlab:show' });
    menu.addItem({ command: 'faq-jupyterlab:show' });
    menu.addItem({ command: 'classic-notebook:open' });

    COMMANDS.forEach(item => menu.addItem({ command: item.id }));

    menu.addItem({ command: 'statedb:clear' });

    return menu;
  }
開發者ID:danielballan,項目名稱:jupyterlab,代碼行數:18,代碼來源:plugin.ts

示例3: createMenu

  /**
   * Create a menu for the help plugin.
   */
  function createMenu(): Menu {
    let { commands, keymap } = app;
    let menu = new Menu({ commands, keymap });
    menu.title.label = category;

    menu.addItem({ command: 'about-jupyterlab:show' });
    menu.addItem({ command: 'faq-jupyterlab:show' });
    menu.addItem({ command: 'classic-notebook:open' });

    RESOURCES.forEach(args => { menu.addItem({ args, command }); });

    menu.addItem({ command: 'statedb:clear' });

    return menu;
  }
開發者ID:fperez,項目名稱:jupyterlab,代碼行數:18,代碼來源:plugin.ts

示例4: DisposableSet

  node.addEventListener('contextmenu', (event: MouseEvent) => {
    event.preventDefault();
    let path = fbWidget.pathForClick(event) || '';
    let ext = '.' + path.split('.').pop();
    let widgetNames = registry.listWidgetFactories(ext);
    let prefix = `file-browser-contextmenu-${++Private.id}`;
    let openWith: Menu = null;
    if (path && widgetNames.length > 1) {
      let disposables = new DisposableSet();
      let command: string;

      openWith = new Menu({ commands, keymap });
      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);
  });
開發者ID:recoveringMathmo,項目名稱:jupyterlab,代碼行數:28,代碼來源:plugin.ts

示例5: createMenu

/**
 * Create a menu for the editor.
 */
function createMenu(app: JupyterLab, tracker: IEditorTracker): Menu {
  let { commands, keymap } = app;
  let settings = new Menu({ commands, keymap });
  let theme = new Menu({ commands, keymap });
  let menu = new Menu({ commands, keymap });

  menu.title.label = 'Editor';
  settings.title.label = 'Settings';
  theme.title.label = 'Theme';

  settings.addItem({ command: cmdIds.lineNumbers });
  settings.addItem({ command: cmdIds.lineWrap });
  settings.addItem({ command: cmdIds.matchBrackets });
  settings.addItem({ command: cmdIds.vimMode });

  commands.addCommand(cmdIds.changeTheme, {
    label: args => {
      return args['theme'] as string;
    },
    execute: args => {
      let name: string = args['theme'] as string || DEFAULT_CODEMIRROR_THEME;
      each(tracker.widgets, widget => {
        widget.editor.setOption('theme', name);
      });
    }
  });

  [
   'jupyter', 'default', 'abcdef', 'base16-dark', 'base16-light',
   'hopscotch', 'material', 'mbo', 'mdn-like', 'seti', 'the-matrix',
   'xq-light', 'zenburn'
  ].forEach(name => theme.addItem({
    command: 'editor:change-theme',
    args: { theme: name }
  }));

  menu.addItem({ command: 'file-operations:new-text-file' });
  menu.addItem({ command: 'file-operations:save' });
  menu.addItem({ command: cmdIds.closeAll });
  menu.addItem({ type: 'separator' });
  menu.addItem({ type: 'submenu', menu: settings });
  menu.addItem({ type: 'submenu', menu: theme });

  return menu;
}
開發者ID:matt-bowers,項目名稱:jupyterlab,代碼行數:48,代碼來源:plugin.ts

示例6: createMenu

  /**
   * Create a menu for the help plugin.
   */
  function createMenu(): Menu {
    let { commands, keymap } = app;
    let menu = new Menu({ commands, keymap });
    menu.title.label = category;

    menu.addItem({ command: aboutCmdIds.open });
    menu.addItem({ command: faqCmdIds.open });
    menu.addItem({ command: cmdIds.launchClassic });
    menu.addItem({ type: 'separator' });
    RESOURCES.forEach(args => { menu.addItem({ args, command }); });
    menu.addItem({ type: 'separator' });
    menu.addItem({ command: statedbCmdIds.clear });

    return menu;
  }
開發者ID:Carreau,項目名稱:jupyterlab,代碼行數:18,代碼來源:plugin.ts

示例7: createApp


//.........這裏部分代碼省略.........
    execute: () => {
      let context = docManager.contextForWidget(activeWidget);
      context.save();
    }
  });
  commands.addCommand('file-cut', {
    label: 'Cut',
    icon: 'fa fa-cut',
    execute: () => { fbWidget.cut(); }
  });
  commands.addCommand('file-copy', {
    label: 'Copy',
    icon: 'fa fa-copy',
    mnemonic: 0,
    execute: () => { fbWidget.copy(); }
  });
  commands.addCommand('file-delete', {
    label: 'Delete',
    icon: 'fa fa-remove',
    mnemonic: 0,
    execute: () => { fbWidget.delete(); }
  });
  commands.addCommand('file-duplicate', {
    label: 'Duplicate',
    icon: 'fa fa-copy',
    mnemonic: 0,
    execute: () => { fbWidget.duplicate(); }
  });
  commands.addCommand('file-paste', {
    label: 'Paste',
    icon: 'fa fa-paste',
    mnemonic: 0,
    execute: () => { fbWidget.paste(); }
  });
  commands.addCommand('file-download', {
    label: 'Download',
    icon: 'fa fa-download',
    execute: () => { fbWidget.download(); }
  });
  commands.addCommand('file-shutdown-kernel', {
    label: 'Shutdown Kernel',
    icon: 'fa fa-stop-circle-o',
    execute: () => { fbWidget.shutdownKernels(); }
  });
  commands.addCommand('file-dialog-demo', {
    label: 'Dialog Demo',
    execute: () => { dialogDemo(); }
  });
  commands.addCommand('file-info-demo', {
    label: 'Info Demo',
    execute: () => {
      let msg = 'The quick brown fox jumped over the lazy dog';
      showDialog({
        title: 'Cool Title',
        body: msg,
        buttons: [okButton]
      });
    }
  });

  keymap.addBinding({
    keys: ['Enter'],
    selector: '.jp-DirListing',
    command: 'file-open'
  });
  keymap.addBinding({
    keys: ['Accel S'],
    selector: '.jp-CodeMirrorWidget',
    command: 'file-save'
  });
  window.addEventListener('keydown', (event) => {
    keymap.processKeydownEvent(event);
  });

  let menu = new Menu({ commands, keymap });
  menu.addItem({ command: 'file-open' });
  menu.addItem({ command: 'file-rename' });
  menu.addItem({ command: 'file-remove' });
  menu.addItem({ command: 'file-duplicate' });
  menu.addItem({ command: 'file-delete' });
  menu.addItem({ command: 'file-cut' });
  menu.addItem({ command: 'file-copy' });
  menu.addItem({ command: 'file-paste' });
  menu.addItem({ command: 'file-shutdown-kernel' });
  menu.addItem({ command: 'file-dialog-demo' });
  menu.addItem({ command: 'file-info-demo' });

  // 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 x = event.clientX;
    let y = event.clientY;
    menu.open(x, y);
  });

  Widget.attach(panel, document.body);

  window.onresize = () => panel.update();
}
開發者ID:fperez,項目名稱:jupyterlab,代碼行數:101,代碼來源:index.ts

示例8: activateConsole

/**
 * Activate the console extension.
 */
function activateConsole(app: JupyterLab, services: IServiceManager, rendermime: IRenderMime, mainMenu: IMainMenu, inspector: IInspector, palette: ICommandPalette, pathTracker: IPathTracker, contentFactory: ConsolePanel.IContentFactory,  editorServices: IEditorServices, restorer: IInstanceRestorer): IConsoleTracker {
  let manager = services.sessions;
  let { commands, keymap } = app;
  let category = 'Console';
  let command: string;
  let count = 0;
  let menu = new Menu({ commands, keymap });

  // Create an instance tracker for all console panels.
  const tracker = new InstanceTracker<ConsolePanel>({ namespace: 'console' });

  // Handle state restoration.
  restorer.restore(tracker, {
    command: cmdIds.create,
    args: panel => ({ id: panel.console.session.id }),
    name: panel => panel.console.session && panel.console.session.id,
    when: manager.ready
  });

  // Set the source of the code inspector.
  tracker.currentChanged.connect((sender, widget) => {
    if (widget) {
      inspector.source = widget.inspectionHandler;
    }
  });

  // Set the main menu title.
  menu.title.label = category;

  command = cmdIds.create;
  commands.addCommand(command, {
    label: 'Start New Console',
    execute: (args?: ICreateConsoleArgs) => {
      let name = `Console ${++count}`;

      args = args || {};

      // If we get a session, use it.
      if (args.id) {
        return manager.ready.then(() => manager.connectTo(args.id))
          .then(session => {
            name = session.path.split('/').pop();
            name = `Console ${name.match(CONSOLE_REGEX)[1]}`;
            createConsole(session, name);
            return session.id;
          });
      }

      // Find the correct path for the new session.
      // Use the given path or the cwd.
      let path = args.path || pathTracker.path;
      if (ContentsManager.extname(path)) {
        path = ContentsManager.dirname(path);
      }
      path = `${path}/console-${count}-${utils.uuid()}`;

      // Get the kernel model.
      return manager.ready.then(() => getKernel(args, name)).then(kernel => {
        if (!kernel || (kernel && !kernel.id && !kernel.name)) {
          return;
        }
        // Start the session.
        let options: Session.IOptions = {
          path,
          kernelName: kernel.name,
          kernelId: kernel.id
        };
        return manager.startNew(options).then(session => {
          createConsole(session, name);
          return session.id;
        });
      });
    }
  });
  palette.addItem({ command, category });
  menu.addItem({ command });

  command = cmdIds.clear;
  commands.addCommand(command, {
    label: 'Clear Cells',
    execute: () => {
      let current = tracker.currentWidget;
      if (current) {
        current.console.clear();
      }
    }
  });
  palette.addItem({ command, category });
  menu.addItem({ command });

  command = cmdIds.run;
  commands.addCommand(command, {
    label: 'Run Cell',
    execute: () => {
      let current = tracker.currentWidget;
      if (current) {
        current.console.execute();
//.........這裏部分代碼省略.........
開發者ID:Carreau,項目名稱:jupyterlab,代碼行數:101,代碼來源:plugin.ts


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