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?
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),
(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:
For those who ends up here,
Add another possible reason for IFileBrowserFactory being undefined: the order of parameters for activate function matters, requires parameters must be put before optional parameters.
If you put the required IFileBrowserFactory parameter after an optional parameter, it will be undefined.