当前位置: 首页>>代码示例>>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;未经允许,请勿转载。