What does IFileBrowserFactory.defaultBrowser do?

Hello,

New to jupyterlab extensions and trying to create my own extension that uses parts of the existing jupyterlab-git extension. I came across some puzzling behavior w/ IFileBrowserFactory and was hoping someone could provide guidance.

I copied the code used in jupyterlab-git here
into my own extension, but found that filebrowser was undefined in my extension (but [object Object] in the jupyterlab-git extension).

async function activate(
  app: JupyterFrontEnd,
  mainMenu: IMainMenu,
  restorer: ILayoutRestorer,
  factory: IFileBrowserFactory,
  renderMime: IRenderMimeRegistry,
  settingRegistry: ISettingRegistry,
  docmanager: IDocumentManager,
  statusBar: IStatusBar,
  translator?: ITranslator
): Promise<IGitExtension> {
  let gitExtension: GitExtension | null = null;
  let settings: ISettingRegistry.ISettings;
  let serverSettings: Git.IServerSettings;
  const filebrowser = factory.defaultBrowser;
  console.log(`filebrowser is ${filebrowser}`);

Question 1: What does IFileBrowserFactory.defaultBrowser do in the jupyterlab-git extension? I believe it’s an object that creates filebrowsers, but not sure why it’s needed.

Question 2: Why is IFileBrowserFactory undefined in my extension? Do I need to use other jupyterlab packages to activate it?

Many thanks!

1 Like

Question 1: What does IFileBrowserFactory.defaultBrowser do in the jupyterlab-git extension? I believe it’s an object that creates filebrowsers, but not sure why it’s needed.

The git extension integrates with the file browser in several ways:

  • when the directory is changed it check if the new directory is a git repository and updates the button for cloning (and state of the extension models) accordingly; this is implemented by listening on IFileBrowserFactory.defaultBrowser.model.pathChanged (which assumes that the default file browser is used),
  • when user right-clicks/opens context menu for any file a “Git” sub-menu which allows to git track/ignore/add/remove the selected file or files (see https://github.com/jupyterlab/jupyterlab-git/pull/877)
  • (in future we may want to highlight modified file)

Question 2: Why is IFileBrowserFactory undefined in my extension? Do I need to use other jupyterlab packages to activate it?

I cannot answer confidently without seeing your code, but I would guess that it might be missing in the list or required tokens (requires field in plugin: JupyterFrontEndPlugin<something> object), which for jupyterlab-git is in:

1 Like