当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ISettingRegistry.load方法代码示例

本文整理汇总了TypeScript中@jupyterlab/coreutils.ISettingRegistry.load方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ISettingRegistry.load方法的具体用法?TypeScript ISettingRegistry.load怎么用?TypeScript ISettingRegistry.load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@jupyterlab/coreutils.ISettingRegistry的用法示例。


在下文中一共展示了ISettingRegistry.load方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Menu

  activate: (
    app: JupyterFrontEnd,
    statusBar: IStatusBar,
    editorTracker: IEditorTracker,
    settingRegistry: ISettingRegistry
  ) => {
    // Create a menu for switching tabs vs spaces.
    const menu = new Menu({ commands: app.commands });
    const command = 'fileeditor:change-tabs';
    const { shell } = app;
    const args: JSONObject = {
      insertSpaces: false,
      size: 4,
      name: 'Indent with Tab'
    };
    menu.addItem({ command, args });
    for (let size of [1, 2, 4, 8]) {
      let args: JSONObject = {
        insertSpaces: true,
        size,
        name: `Spaces: ${size} `
      };
      menu.addItem({ command, args });
    }

    // Create the status item.
    const item = new TabSpaceStatus({ menu });

    // Keep a reference to the code editor config from the settings system.
    const updateSettings = (settings: ISettingRegistry.ISettings): void => {
      const cached = settings.get('editorConfig').composite as Partial<
        CodeEditor.IConfig
      >;
      const config: CodeEditor.IConfig = {
        ...CodeEditor.defaultConfig,
        ...cached
      };
      item.model!.config = config;
    };
    void Promise.all([
      settingRegistry.load('@jupyterlab/fileeditor-extension:plugin'),
      app.restored
    ]).then(([settings]) => {
      updateSettings(settings);
      settings.changed.connect(updateSettings);
    });

    // Add the status item.
    statusBar.registerStatusItem(
      '@jupyterlab/fileeditor-extension:tab-space-status',
      {
        item,
        align: 'right',
        rank: 1,
        isActive: () => {
          return shell.currentWidget && editorTracker.has(shell.currentWidget);
        }
      }
    );
  }
开发者ID:alexmorley,项目名称:jupyterlab,代码行数:60,代码来源:index.ts

示例2: handleContext

  activate: (app: JupyterLab, palette: ICommandPalette, menu: IMainMenu, settingRegistry: ISettingRegistry): IDocumentManager => {
    const manager = app.serviceManager;
    const contexts = new WeakSet<DocumentRegistry.Context>();
    const opener: DocumentManager.IWidgetOpener = {
      open: (widget, options) => {
        const shell = app.shell;
        if (!widget.id) {
          widget.id = `document-manager-${++Private.id}`;
        }
        widget.title.dataset = {
          'type': 'document-title',
          ...widget.title.dataset
        };
        if (!widget.isAttached) {
          app.shell.addToMainArea(widget, options || {});
        }
        shell.activateById(widget.id);

        // Handle dirty state for open documents.
        let context = docManager.contextForWidget(widget);
        if (!contexts.has(context)) {
          handleContext(app, context);
          contexts.add(context);
        }
      }
    };
    const registry = app.docRegistry;
    const when = app.restored.then(() => void 0);
    const docManager = new DocumentManager({ registry, manager, opener, when, setBusy: app.setBusy.bind(app) });

    // Register the file operations commands.
    addCommands(app, docManager, palette, opener, settingRegistry);

    // Keep up to date with the settings registry.
    const onSettingsUpdated = (settings: ISettingRegistry.ISettings) => {
      const autosave = settings.get('autosave').composite as boolean | null;
      docManager.autosave = (autosave === true || autosave === false)
                            ? autosave
                            : true;
      app.commands.notifyCommandChanged(CommandIDs.toggleAutosave);
    };

    // Fetch the initial state of the settings.
    Promise.all([settingRegistry.load(pluginId), app.restored])
    .then(([settings]) => {
      settings.changed.connect(onSettingsUpdated);
      onSettingsUpdated(settings);
    }).catch((reason: Error) => {
      console.error(reason.message);
    });
    menu.settingsMenu.addGroup([{ command: CommandIDs.toggleAutosave }], 5);

    return docManager;
  }
开发者ID:groutr,项目名称:jupyterlab,代码行数:54,代码来源:index.ts

示例3:

  activate: (app: JupyterLab, settingReqistry: ISettingRegistry): void => {
    const { commands } = app;

    settingReqistry.load(plugin.id).then(settings => {
      Private.loadShortcuts(commands, settings.composite);
      settings.changed.connect(() => {
        Private.loadShortcuts(commands, settings.composite);
      });
    }).catch((reason: Error) => {
      console.error('Loading shortcut settings failed.', reason.message);
    });
  },
开发者ID:7125messi,项目名称:jupyterlab,代码行数:12,代码来源:index.ts

示例4: maybeCreate

  Promise.all([app.restored, browser.model.restored]).then(() => {
    function maybeCreate() {
      // Create a launcher if there are no open items.
      if (labShell.isEmpty('main')) {
        Private.createLauncher(commands, browser);
      }
    }

    // When layout is modified, create a launcher if there are no open items.
    labShell.layoutModified.connect(() => {
      maybeCreate();
    });

    let navigateToCurrentDirectory: boolean = false;

    settingRegistry
      .load('@jupyterlab/filebrowser-extension:browser')
      .then(settings => {
        settings.changed.connect(settings => {
          navigateToCurrentDirectory = settings.get(
            'navigateToCurrentDirectory'
          ).composite as boolean;
        });
        navigateToCurrentDirectory = settings.get('navigateToCurrentDirectory')
          .composite as boolean;
      });

    // Whether to automatically navigate to a document's current directory
    labShell.currentChanged.connect((_, change) => {
      if (navigateToCurrentDirectory && change.newValue) {
        const { newValue } = change;
        const context = docManager.contextForWidget(newValue);
        if (context) {
          const { path } = context;
          Private.navigateToPath(path, factory)
            .then(() => {
              labShell.currentWidget.activate();
            })
            .catch((reason: any) => {
              console.warn(
                `${CommandIDs.navigate} failed to open: ${path}`,
                reason
              );
            });
        }
      }
    });

    maybeCreate();
  });
开发者ID:ellisonbg,项目名称:jupyterlab,代码行数:50,代码来源:index.ts

示例5: async

  activate: async (
    app: JupyterFrontEnd,
    registry: ISettingRegistry,
    labShell: ILabShell | null,
    restorer: ILayoutRestorer | null
  ) => {
    const settings = await registry.load(plugin.id);
    let enabled = settings.composite['enabled'] === true;

    const { serviceManager, shell } = app;
    let view: ExtensionView | undefined;

    const createView = () => {
      const v = new ExtensionView(serviceManager);
      v.id = 'extensionmanager.main-view';
      v.title.iconClass = 'jp-ExtensionIcon jp-SideBar-tabIcon';
      v.title.caption = 'Extension Manager';
      if (restorer) {
        restorer.add(v, v.id);
      }
      return v;
    };

    if (enabled) {
      view = createView();
      shell.add(view, 'left', { rank: 1000 });
    }

    // If the extension is enabled or disabled,
    // add or remove it from the left area.
    void app.restored.then(() => {
      settings.changed.connect(async () => {
        enabled = settings.composite['enabled'] === true;
        if (enabled && (!view || (view && !view.isAttached))) {
          const accepted = await Private.showWarning();
          if (!accepted) {
            void settings.set('enabled', false);
            return;
          }
          view = view || createView();
          shell.add(view, 'left');
        } else if (!enabled && view && view.isAttached) {
          view.close();
        }
      });
    });

    addCommands(app, view, labShell);
  }
开发者ID:afshin,项目名称:jupyterlab,代码行数:49,代码来源:index.ts

示例6: async

  activate: async (
    app: JupyterLab,
    registry: ISettingRegistry,
    restorer: ILayoutRestorer,
    router: IRouter
  ) => {
    const settings = await registry.load(plugin.id);
    let enabled = settings.composite['enabled'] === true;

    const { shell, serviceManager } = app;
    const view = new ExtensionView(serviceManager);

    view.id = 'extensionmanager.main-view';
    view.title.label = 'Extensions';
    restorer.add(view, view.id);

    if (enabled) {
      shell.addToLeftArea(view);
    }

    // If the extension is enabled or disabled,
    // add or remove it from the left area.
    app.restored.then(() => {
      settings.changed.connect(async () => {
        enabled = settings.composite['enabled'] === true;
        if (enabled && !view.isAttached) {
          const accepted = await Private.showWarning();
          if (!accepted) {
            settings.set('enabled', false);
            return;
          }
          shell.addToLeftArea(view);
        } else if (!enabled && view.isAttached) {
          view.close();
        }
      });
    });

    addCommands(app, view);
  }
开发者ID:dalejung,项目名称:jupyterlab,代码行数:40,代码来源:index.ts

示例7: activate

/**
 * Activate the editor tracker plugin.
 */
function activate(
  app: JupyterLab,
  consoleTracker: IConsoleTracker,
  editorServices: IEditorServices,
  browserFactory: IFileBrowserFactory,
  restorer: ILayoutRestorer,
  settingRegistry: ISettingRegistry,
  palette: ICommandPalette,
  launcher: ILauncher | null,
  menu: IMainMenu | null
): IEditorTracker {
  const id = plugin.id;
  const namespace = 'editor';
  const factory = new FileEditorFactory({
    editorServices,
    factoryOptions: {
      name: FACTORY,
      fileTypes: ['markdown', '*'], // Explicitly add the markdown fileType so
      defaultFor: ['markdown', '*'] // it outranks the defaultRendered viewer.
    }
  });
  const { commands, restored } = app;
  const tracker = new InstanceTracker<IDocumentWidget<FileEditor>>({
    namespace
  });
  const isEnabled = () =>
    tracker.currentWidget !== null &&
    tracker.currentWidget === app.shell.currentWidget;

  let config = { ...CodeEditor.defaultConfig };

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

  /**
   * Update the setting values.
   */
  function updateSettings(settings: ISettingRegistry.ISettings): void {
    let cached = settings.get('editorConfig').composite as Partial<
      CodeEditor.IConfig
    >;
    Object.keys(config).forEach((key: keyof CodeEditor.IConfig) => {
      config[key] =
        cached[key] === null || cached[key] === undefined
          ? CodeEditor.defaultConfig[key]
          : cached[key];
    });
    // Trigger a refresh of the rendered commands
    app.commands.notifyCommandChanged();
  }

  /**
   * Update the settings of the current tracker instances.
   */
  function updateTracker(): void {
    tracker.forEach(widget => {
      updateWidget(widget.content);
    });
  }

  /**
   * Update the settings of a widget.
   */
  function updateWidget(widget: FileEditor): void {
    const editor = widget.editor;
    Object.keys(config).forEach((key: keyof CodeEditor.IConfig) => {
      editor.setOption(key, config[key]);
    });
  }

  // Add a console creator to the File menu
  // Fetch the initial state of the settings.
  Promise.all([settingRegistry.load(id), restored])
    .then(([settings]) => {
      updateSettings(settings);
      updateTracker();
      settings.changed.connect(() => {
        updateSettings(settings);
        updateTracker();
      });
    })
    .catch((reason: Error) => {
      console.error(reason.message);
      updateTracker();
    });

  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);
    });
//.........这里部分代码省略.........
开发者ID:dalejung,项目名称:jupyterlab,代码行数:101,代码来源:index.ts

示例8: activate

/**
 * Activate the terminal plugin.
 */
function activate(
  app: JupyterFrontEnd,
  settingRegistry: ISettingRegistry,
  palette: ICommandPalette | null,
  launcher: ILauncher | null,
  restorer: ILayoutRestorer | null,
  mainMenu: IMainMenu | null
): ITerminalTracker {
  const { serviceManager } = app;
  const category = 'Terminal';
  const namespace = 'terminal';
  const tracker = new InstanceTracker<MainAreaWidget<Terminal>>({ namespace });

  // Bail if there are no terminals available.
  if (!serviceManager.terminals.isAvailable()) {
    console.log(
      'Disabling terminals plugin because they are not available on the server'
    );
    return tracker;
  }

  // Handle state restoration.
  if (restorer) {
    restorer.restore(tracker, {
      command: CommandIDs.createNew,
      args: widget => ({ name: widget.content.session.name }),
      name: widget => widget.content.session && widget.content.session.name
    });
  }

  // The terminal options from the setting editor.
  let options: Partial<Terminal.IOptions>;

  /**
   * Update the option values.
   */
  function updateOptions(settings: ISettingRegistry.ISettings): void {
    options = settings.composite as Partial<Terminal.IOptions>;
    Object.keys(options).forEach((key: keyof Terminal.IOptions) => {
      Terminal.defaultOptions[key] = options[key];
    });
  }

  /**
   * Update terminal
   */
  function updateTerminal(widget: MainAreaWidget<Terminal>): void {
    const terminal = widget.content;
    if (!terminal) {
      return;
    }
    Object.keys(options).forEach((key: keyof Terminal.IOptions) => {
      terminal.setOption(key, options[key]);
    });
  }

  /**
   * Update the settings of the current tracker instances.
   */
  function updateTracker(): void {
    tracker.forEach(widget => updateTerminal(widget));
  }

  // Fetch the initial state of the settings.
  settingRegistry
    .load(plugin.id)
    .then(settings => {
      updateOptions(settings);
      updateTracker();
      settings.changed.connect(() => {
        updateOptions(settings);
        updateTracker();
      });
    })
    .catch((reason: Error) => {
      console.error(reason.message);
    });

  addCommands(app, tracker, settingRegistry);

  if (mainMenu) {
    // Add some commands to the application view menu.
    const viewGroup = [
      CommandIDs.increaseFont,
      CommandIDs.decreaseFont,
      CommandIDs.toggleTheme
    ].map(command => {
      return { command };
    });
    mainMenu.settingsMenu.addGroup(viewGroup, 40);

    // Add terminal creation to the file menu.
    mainMenu.fileMenu.newMenu.addGroup([{ command: CommandIDs.createNew }], 20);
  }

  if (palette) {
    // Add command palette items.
//.........这里部分代码省略.........
开发者ID:alexmorley,项目名称:jupyterlab,代码行数:101,代码来源:index.ts

示例9: activateEditorCommands

/**
 * Set up the editor widget menu and commands.
 */
function activateEditorCommands(
  app: JupyterFrontEnd,
  tracker: IEditorTracker,
  settingRegistry: ISettingRegistry,
  mainMenu: IMainMenu | null
): void {
  const { commands, restored } = app;
  let {
    theme,
    keyMap,
    scrollPastEnd,
    styleActiveLine,
    styleSelectedText,
    selectionPointer
  } = CodeMirrorEditor.defaultConfig;

  /**
   * Update the setting values.
   */
  function updateSettings(settings: ISettingRegistry.ISettings): void {
    keyMap = (settings.get('keyMap').composite as string | null) || keyMap;
    theme = (settings.get('theme').composite as string | null) || theme;
    scrollPastEnd = settings.get('scrollPastEnd').composite as boolean | null;
    styleActiveLine =
      (settings.get('styleActiveLine').composite as boolean | object) ||
      styleActiveLine;
    styleSelectedText =
      (settings.get('styleSelectedText').composite as boolean) ||
      styleSelectedText;
    selectionPointer =
      (settings.get('selectionPointer').composite as boolean | string) ||
      selectionPointer;
  }

  /**
   * Update the settings of the current tracker instances.
   */
  function updateTracker(): void {
    tracker.forEach(widget => {
      if (widget.content.editor instanceof CodeMirrorEditor) {
        let cm = widget.content.editor.editor;
        cm.setOption('keyMap', keyMap);
        cm.setOption('theme', theme);
        cm.setOption('scrollPastEnd', scrollPastEnd);
        cm.setOption('styleActiveLine', styleActiveLine);
        cm.setOption('styleSelectedText', styleSelectedText);
        cm.setOption('selectionPointer', selectionPointer);
      }
    });
  }

  // Fetch the initial state of the settings.
  Promise.all([settingRegistry.load(id), restored])
    .then(([settings]) => {
      updateSettings(settings);
      updateTracker();
      settings.changed.connect(() => {
        updateSettings(settings);
        updateTracker();
      });
    })
    .catch((reason: Error) => {
      console.error(reason.message);
      updateTracker();
    });

  /**
   * Handle the settings of new widgets.
   */
  tracker.widgetAdded.connect((sender, widget) => {
    if (widget.content.editor instanceof CodeMirrorEditor) {
      let cm = widget.content.editor.editor;
      cm.setOption('keyMap', keyMap);
      cm.setOption('theme', theme);
      cm.setOption('scrollPastEnd', scrollPastEnd);
      cm.setOption('styleActiveLine', styleActiveLine);
      cm.setOption('styleSelectedText', styleSelectedText);
      cm.setOption('selectionPointer', selectionPointer);
    }
  });

  /**
   * A test for whether the tracker has an active widget.
   */
  function isEnabled(): boolean {
    return (
      tracker.currentWidget !== null &&
      tracker.currentWidget === app.shell.currentWidget
    );
  }

  /**
   * Create a menu for the editor.
   */
  const themeMenu = new Menu({ commands });
  const keyMapMenu = new Menu({ commands });
  const modeMenu = new Menu({ commands });
//.........这里部分代码省略.........
开发者ID:afshin,项目名称:jupyterlab,代码行数:101,代码来源:index.ts

示例10: async

  activate: async (app: JupyterLab, registry: ISettingRegistry) => {
    try {
      const old = await registry.load(plugin.id);
      const settings = await registry.load(shortcuts.id);
      const keys = Object.keys(old.user);
      const deprecated: ISettingRegistry.IShortcut[] = [];
      const port = (deprecated: ISettingRegistry.IShortcut[]) => {
        if (!deprecated.length) {
          return;
        }

        const memo: {
          [keys: string]: { [selector: string]: null };
        } = {};
        const shortcuts = settings.user
          .shortcuts as ISettingRegistry.IShortcut[];

        // Add the current shortcuts into the memo.
        shortcuts.forEach(shortcut => {
          const keys = shortcut.keys.join(RECORD_SEPARATOR);
          const { selector } = shortcut;

          if (!keys) {
            return;
          }
          if (!(keys in memo)) {
            memo[keys] = {};
          }
          if (!(selector in memo[keys])) {
            memo[keys][selector] = null;
          }
        });

        // Add deprecated shortcuts that don't exist to the current list.
        deprecated.forEach(shortcut => {
          const { selector } = shortcut;
          const keys = shortcut.keys.join(RECORD_SEPARATOR);

          if (!(keys in memo)) {
            memo[keys] = {};
          }
          if (!(selector in memo[keys])) {
            memo[keys][selector] = null;
            shortcuts.push(shortcut);
          }
        });

        // Save the reconciled list.
        settings.set('shortcuts', shortcuts);
      };

      if (!keys.length) {
        return;
      }
      keys.forEach(key => {
        const { command, keys, selector } = old.user[
          key
        ] as ISettingRegistry.IShortcut;

        // Only port shortcuts over if they are valid.
        if (command && selector && keys && keys.length) {
          deprecated.push({ command, keys, selector });
        }
      });

      // Port the deprecated shortcuts to the new plugin.
      port(deprecated);

      // Remove all old shortcuts;
      old.save('{}');
    } catch (error) {
      console.error(`Loading ${plugin.id} failed.`, error);
    }
  },
开发者ID:AlbertHilb,项目名称:jupyterlab,代码行数:74,代码来源:index.ts


注:本文中的@jupyterlab/coreutils.ISettingRegistry.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。