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


TypeScript mainmenu.FileMenu類代碼示例

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


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

示例1: createFileMenu

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

  // Add a delegator command for closing and cleaning up an activity.
  commands.addCommand(CommandIDs.closeAndCleanup, {
    label: () => {
      const action = Private.delegateLabel(
        app,
        menu.closeAndCleaners,
        'action'
      );
      const name = Private.delegateLabel(app, menu.closeAndCleaners, 'name');
      return `Close and ${action ? ` ${action} ${name}` : 'Shutdown'}`;
    },
    isEnabled: Private.delegateEnabled(
      app,
      menu.closeAndCleaners,
      'closeAndCleanup'
    ),
    execute: Private.delegateExecute(
      app,
      menu.closeAndCleaners,
      'closeAndCleanup'
    )
  });

  // Add a delegator command for persisting data then saving.
  commands.addCommand(CommandIDs.persistAndSave, {
    label: () => {
      const action = Private.delegateLabel(
        app,
        menu.persistAndSavers,
        'action'
      );
      const name = Private.delegateLabel(app, menu.persistAndSavers, 'name');
      return `Save ${name} ${action || 'with Extras'}`;
    },
    isEnabled: args => {
      return (
        Private.delegateEnabled(
          app,
          menu.persistAndSavers,
          'persistAndSave'
        )() && commands.isEnabled('docmanager:save', args)
      );
    },
    execute: Private.delegateExecute(
      app,
      menu.persistAndSavers,
      'persistAndSave'
    )
  });

  // Add a delegator command for creating a console for an activity.
  commands.addCommand(CommandIDs.createConsole, {
    label: () => {
      const name = Private.delegateLabel(app, menu.consoleCreators, 'name');
      const label = `New Console for ${name ? name : 'Activity'}`;
      return label;
    },
    isEnabled: Private.delegateEnabled(
      app,
      menu.consoleCreators,
      'createConsole'
    ),
    execute: Private.delegateExecute(app, menu.consoleCreators, 'createConsole')
  });

  commands.addCommand(CommandIDs.quit, {
    label: 'Quit',
    caption: 'Quit JupyterLab',
    execute: () => {
      showDialog({
        title: 'Quit confirmation',
        body: 'Please confirm you want to quit JupyterLab.',
        buttons: [Dialog.cancelButton(), Dialog.warnButton({ label: 'Quit' })]
      }).then(result => {
        if (result.button.accept) {
          let setting = ServerConnection.makeSettings();
          let apiURL = URLExt.join(setting.baseUrl, 'api/shutdown');
          ServerConnection.makeRequest(apiURL, { method: 'POST' }, setting)
            .then(result => {
              if (result.ok) {
                // Close this window if the shutdown request has been successful
                let body = document.createElement('div');
                body.innerHTML = `<p>You have shut down the Jupyter server. You can now close this tab.</p>
                  <p>To use JupyterLab again, you will need to relaunch it.</p>`;
                showDialog({
                  title: 'Server stopped',
                  body: new Widget({ node: body }),
                  buttons: []
                });
                window.close();
              } else {
                throw new ServerConnection.ResponseError(result);
              }
            })
            .catch(data => {
              throw new ServerConnection.NetworkError(data);
            });
//.........這裏部分代碼省略.........
開發者ID:SylvainCorlay,項目名稱:jupyterlab,代碼行數:101,代碼來源:index.ts

示例2: describe

  describe('FileMenu', () => {
    let commands: CommandRegistry;
    let menu: FileMenu;
    let tracker: InstanceTracker<Wodget>;
    let wodget = new Wodget();

    before(() => {
      commands = new CommandRegistry();
    });

    beforeEach(() => {
      menu = new FileMenu({ commands });
      tracker = new InstanceTracker<Wodget>({ namespace: 'wodget' });
      tracker.add(wodget);
    });

    afterEach(() => {
      menu.dispose();
      tracker.dispose();
      wodget.dispose();
    });

    describe('#constructor()', () => {
      it('should construct a new file menu', () => {
        expect(menu).to.be.an(FileMenu);
        expect(menu.menu.title.label).to.be('File');
      });
    });

    describe('#newMenu', () => {
      it('should be a submenu for `New...` commands', () => {
        expect(menu.newMenu.menu.title.label).to.be('New');
      });
    });

    describe('#cleaners', () => {
      it('should allow setting of an ICloseAndCleaner', () => {
        const cleaner: IFileMenu.ICloseAndCleaner<Wodget> = {
          tracker,
          name: 'Wodget',
          action: 'Clean',
          closeAndCleanup: widget => {
            widget.state = 'clean';
            return Promise.resolve(void 0);
          }
        };
        menu.closeAndCleaners.add(cleaner);
        delegateExecute(wodget, menu.closeAndCleaners, 'closeAndCleanup');
        expect(wodget.state).to.be('clean');
      });
    });

    describe('#persistAndSavers', () => {
      it('should allow setting of an IPersistAndSave', () => {
        const persistAndSaver: IFileMenu.IPersistAndSave<Wodget> = {
          tracker,
          name: 'Wodget',
          action: 'with Save',
          persistAndSave: widget => {
            widget.state = 'saved';
            return Promise.resolve(void 0);
          }
        };
        menu.persistAndSavers.add(persistAndSaver);
        delegateExecute(wodget, menu.persistAndSavers, 'persistAndSave');
        expect(wodget.state).to.be('saved');
      });
    });

    describe('#consoleCreators', () => {
      it('should allow setting of an IConsoleCreator', () => {
        const creator: IFileMenu.IConsoleCreator<Wodget> = {
          tracker,
          name: 'Wodget',
          createConsole: widget => {
            widget.state = 'create';
            return Promise.resolve(void 0);
          }
        };
        menu.consoleCreators.add(creator);
        delegateExecute(wodget, menu.consoleCreators, 'createConsole');
        expect(wodget.state).to.be('create');
      });
    });
  });
開發者ID:dalejung,項目名稱:jupyterlab,代碼行數:85,代碼來源:file.spec.ts

示例3: createFileMenu

function createFileMenu(app: JupyterLab, menu: FileMenu): void {
  const commands = menu.menu.commands;

  // Add a delegator command for closing and cleaning up an activity.
  commands.addCommand(CommandIDs.closeAndCleanup, {
    label: () => {
      const action =
        Private.delegateLabel(app, menu.closeAndCleaners, 'action');
      const name =
        Private.delegateLabel(app, menu.closeAndCleaners, 'name');
      return `Close and ${action ? ` ${action} ${name}` : 'Shutdown'}`;
    },
    isEnabled:
      Private.delegateEnabled(app, menu.closeAndCleaners, 'closeAndCleanup'),
    execute:
      Private.delegateExecute(app, menu.closeAndCleaners, 'closeAndCleanup')
  });

  // Add a delegator command for creating a console for an activity.
  commands.addCommand(CommandIDs.createConsole, {
    label: () => {
      const name = Private.delegateLabel(app, menu.consoleCreators, 'name');
      const label = `New Console for ${name ? name : 'Activity' }`;
      return label;
    },
    isEnabled: Private.delegateEnabled(app, menu.consoleCreators, 'createConsole'),
    execute: Private.delegateExecute(app, menu.consoleCreators, 'createConsole')
  });

  // Add the new group
  const newGroup = [
    { type: 'submenu' as Menu.ItemType, submenu: menu.newMenu.menu },
    { command: 'filebrowser:create-main-launcher' },
  ];

  const newViewGroup = [
    { command: 'docmanager:clone' },
    { command: CommandIDs.createConsole }
  ];

  // Add the close group
  const closeGroup = [
    'docmanager:close',
    'filemenu:close-and-cleanup',
    'docmanager:close-all-files'
  ].map(command => { return { command }; });

  // Add save group.
  const saveGroup = [
    'docmanager:save',
    'docmanager:save-as',
    'docmanager:save-all'
  ].map(command => { return { command }; });

  // Add the re group.
  const reGroup = [
    'docmanager:restore-checkpoint',
    'docmanager:rename'
  ].map(command => { return { command }; });

  menu.addGroup(newGroup, 0);
  menu.addGroup(newViewGroup, 1);
  menu.addGroup(closeGroup, 2);
  menu.addGroup(saveGroup, 3);
  menu.addGroup(reGroup, 4);
}
開發者ID:7125messi,項目名稱:jupyterlab,代碼行數:66,代碼來源:index.ts

示例4: afterEach

 afterEach(() => {
   menu.dispose();
   tracker.dispose();
   wodget.dispose();
 });
開發者ID:dalejung,項目名稱:jupyterlab,代碼行數:5,代碼來源:file.spec.ts


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