Issue with IFileBrowserFactory and ICommandPalette
See original GitHub issueI encounter an error and blocked when developed my jupyterlab extension and tried to reproduce it with the official jlab extension example. For this extension-examples/launcher: I found that if I add ICommandPalette to the requires like :
requires: [IFileBrowserFactory, ICommandPalette],
optional: [ILauncher, IMainMenu],
instead of:
requires: [IFileBrowserFactory],
optional: [ILauncher, IMainMenu, ICommandPalette],
The rest of the code is identical, the plugin will be failed to activate and console shows:
Plugin 'launcher' failed to activate.
TypeError: launcher.add is not a function
at activate (index.js:48)
at jlab_core.ec15f8c091a46864d4c7.js:formatted:59045
at async Promise.all (:8888/lab/workspaces/index 101)
So seems that ICommandPalette cannot be in ‘requires’ along with IFileBrowserFactory. So the Question is, for my use case: When click on this command (from command palette and in menu.fileMenu)then I can get opened file(.py, .md, .ipynb …) local path. I have done the most part of this extension but currently blocked by how to retrieve the current opened file path in the code block:
commands.addCommand(command, {
label: 'xxx',
caption: 'xxx,
icon: args => (args['isPalette'] ? null : icon),
execute: async args => {
...
I was thinking that something like this:
const extension: JupyterFrontEndPlugin<void> = {
id: 'main-menu',
autoStart: true,
requires: [ICommandPalette, IMainMenu, IFileBrowserFactory],
activate: (
app: JupyterFrontEnd,
browserFactory: IFileBrowserFactory,
palette: ICommandPalette,
mainMenu: IMainMenu,
trans: ITranslator
) => {
commands.addCommand(command, {
label: 'xxxx',
caption: 'xxxx',
icon: args => (args['isPalette'] ? null : icon),
execute: async args => {
const path = browserFactory.defaultBrowser.model.path;
console.log(path);
But like I mentioned at the very beginning, I cannot make IFileBrowserFactory and ICommandPalette at ‘requires’ field at the same time. any idea for how to achieve above functionality?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
The arguments to the
activate
function are therequires
services, then theoptional
services, in order. When you moved the command palette to the requires, you changed the order of the services passed into your activate function. You need to also change the order of the parameters in your activate function arguments.For example, with your change:
the order of services passed to the activate function would be
IFileBrowserFactory, ICommandPalette, ILauncher, IMainMenu
nvm, issue resolved! Thanks for your help.