@jupyterlab/apputils#ICommandPalette TypeScript Examples
The following examples show how to use
@jupyterlab/apputils#ICommandPalette.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: plugin.ts From jupyter-videochat with BSD 3-Clause "New" or "Revised" License | 6 votes |
function activateToggleArea(
app: JupyterFrontEnd,
chat: IVideoChatManager,
palette?: ICommandPalette
): void {
const { shell, commands } = app;
const { __ } = chat;
const labShell = isFullLab(app) ? (shell as LabShell) : null;
if (!labShell) {
return;
}
const toggleBtn = new CommandToolbarButton({
id: CommandIds.toggleArea,
commands,
icon: launcherIcon,
});
chat.mainWidget
.then((widget) => {
widget.toolbar.insertBefore(
ToolbarIds.SPACER_LEFT,
ToolbarIds.TOGGLE_AREA,
toggleBtn
);
})
.catch((err) => console.warn(__(`Couldn't add Video Chat area toggle`), err));
if (palette) {
palette.addItem({ command: CommandIds.toggleArea, category: __(category) });
}
}
Example #2
Source File: index.ts From stickyland with BSD 3-Clause "New" or "Revised" License | 6 votes |
plugin = {
id: 'jupyterlab_stickyland',
autoStart: true,
requires: [ICommandPalette],
activate: function (app: JupyterFrontEnd) {
console.log('Activating StickyLand.');
app.docRegistry.addWidgetExtension('Notebook', new ButtonExtension());
}
}
Example #3
Source File: index.ts From jupyter-extensions with Apache License 2.0 | 5 votes |
function activate(
app: JupyterFrontEnd,
labShell: ILabShell,
palette: ICommandPalette,
docManager: IDocumentManager
) {
console.log('JupyterLab extension jupyterlab_comments is activated!');
let widget: MainAreaWidget<CommentsWidget>;
let content: CommentsWidget;
const context = {
labShell: labShell,
docManager: docManager,
};
// Add an application command
const command = 'comments:open';
app.commands.addCommand(command, {
label: 'Notebook comments in git',
execute: () => {
if (!widget || widget.isDisposed) {
content = new CommentsWidget(context);
widget = new MainAreaWidget<CommentsWidget>({ content });
widget.id = 'jupyterlab_comments';
widget.title.label = 'Comments';
widget.title.closable = true;
}
if (!widget.isAttached) {
app.shell.add(widget, 'right', { rank: 200 });
}
app.shell.activateById(widget.id);
},
});
// Add the command to the palette.
palette.addItem({ command, category: 'Collaboration' });
/*
Command for adding new comment to currently selected line in the file
This command only support non-Notebook files
*/
const addNewComment = 'comments:add';
app.commands.addCommand(addNewComment, {
execute: () => {
const file = (labShell.currentWidget as IDocumentWidget)
.content as FileEditor;
if (!widget) {
return;
}
const selectionObj = file.editor.getSelection(); //contains start and end line and column attributes
const dialogWidget = new NewCommentDialogWidget(selectionObj, context);
dialogWidget.id = 'new_comment';
app.shell.add(dialogWidget, 'bottom'); //attach widget to UI to display dialog
app.shell.activateById(dialogWidget.id);
},
label: 'New comment',
});
//Add command to file editor's right click context menu
app.contextMenu.addItem({
command: addNewComment,
selector: '.jp-FileEditor',
rank: 1,
});
}
Example #4
Source File: index.ts From jupyter-extensions with Apache License 2.0 | 5 votes |
extension: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab-comments',
autoStart: true,
activate: activate,
requires: [ILabShell, ICommandPalette, IDocumentManager],
}
Example #5
Source File: index.ts From jupyterlab-ros with BSD 3-Clause "New" or "Revised" License | 5 votes |
logConsole: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab-ros/logConsole',
autoStart: true,
requires: [ICommandPalette, ILayoutRestorer],
optional: [],
activate: (app: JupyterFrontEnd, palette: ICommandPalette, restorer: ILayoutRestorer) => {
const { commands } = app;
let widget: LogConsoleWidget = null;
const tracker = new WidgetTracker<LogConsoleWidget>({
namespace: 'roslogconsole'
});
restorer.restore(tracker, {
command: 'jupyterlab-ros/logConsole:open',
name: () => 'roslogconsole'
});
// Creating some buttons for the widget toolbar
commands.addCommand('jupyterlab-ros/logConsole:checkpoint', {
execute: () => widget?.checkpoint(),
icon: addIcon,
label: 'Add Checkpoint'
});
commands.addCommand('jupyterlab-ros/logConsole:clear', {
execute: () => widget?.clear(),
icon: clearIcon,
label: 'Clear Log'
});
commands.addCommand('jupyterlab-ros/logConsole:open', {
label: 'Ros log',
caption: 'Log console for ROS.',
isVisible: () => true,
isEnabled: () => true,
isToggled: () => widget !== null,
execute: () => {
if (widget) {
widget.dispose();
} else {
widget = new LogConsoleWidget(app);
widget.disposed.connect(() => {
widget = null;
commands.notifyCommandChanged();
});
app.shell.add(widget, 'main', { mode: 'split-bottom' });
tracker.add(widget);
widget.update();
commands.notifyCommandChanged();
}
}
});
palette.addItem({ command: 'jupyterlab-ros/logConsole:open', category: 'ROS' });
}
}
Example #6
Source File: index.ts From jupyterlab-ros with BSD 3-Clause "New" or "Revised" License | 5 votes |
settings: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab-ros/settings',
autoStart: true,
requires: [ICommandPalette, ILayoutRestorer, ISettingRegistry],
optional: [],
activate: (app: JupyterFrontEnd, palette: ICommandPalette, restorer: ILayoutRestorer, settings: ISettingRegistry) => {
const { commands } = app;
const server = ServerConnection.makeSettings();
const url = URLExt.join(server.baseUrl, 'ros/setting');
let content: SettingsWidget = null;
let widget: MainAreaWidget<SettingsWidget> = null;
const tracker = new WidgetTracker<MainAreaWidget<SettingsWidget>>({
namespace: 'rossettings'
});
restorer.restore(tracker, {
command: 'jupyterlab-ros/settings:open',
name: () => 'rossettings'
});
const command = 'jupyterlab-ros/settings:open';
commands.addCommand(command, {
label: 'Settings',
caption: 'Specify your JupyterLab-ROS env.',
isVisible: () => true,
isEnabled: () => true,
isToggled: () => widget !== null,
execute: () => {
if (widget) {
widget.dispose();
} else {
content = new SettingsWidget(settings, '@robostack/jupyterlab-ros:settings');
widget = new MainAreaWidget<SettingsWidget>({ content });
widget.title.label = 'ROS Settings';
widget.disposed.connect(() => {
content.dispose();
content = null;
widget = null;
commands.notifyCommandChanged();
});
app.shell.add(widget, 'main');
tracker.add(widget);
widget.update();
commands.notifyCommandChanged();
}
}
});
palette.addItem({ command, category: 'ROS' });
const loadSetting = (setting: ISettingRegistry.ISettings): void => {
const env = setting.get('env').composite as string;
const master = setting.get('master').composite as string;
if ( env != "" || master != "" ) {
const msg = { method: 'PUT', body: JSON.stringify({ env, master }) };
ServerConnection.makeRequest(url, msg, server)
.then( resp => {})
.catch( err => console.log(err) );
}
}
settings.load('@robostack/jupyterlab-ros:settings')
.then(rosSetting => {
rosSetting.changed.connect(loadSetting);
loadSetting(rosSetting);
}).catch(err => console.log(err));
}
}
Example #7
Source File: index.ts From jupyterlab-ros with BSD 3-Clause "New" or "Revised" License | 5 votes |
zethus: JupyterFrontEndPlugin<void> = {
id: "jupyterlab-ros/zethus",
autoStart: true,
requires: [ICommandPalette, ILayoutRestorer],
activate: (app: JupyterFrontEnd, palette: ICommandPalette, restorer: ILayoutRestorer) => {
const { commands } = app;
let widget = null;
const tracker = new WidgetTracker<ZethusWidget>({
namespace: 'zethus'
});
restorer.restore(tracker, {
command: 'jupyterlab-ros/zethus:open',
name: () => 'zethus'
});
let command = 'jupyterlab-ros/zethus:open';
commands.addCommand(command, {
label: 'Open Zethus',
caption: 'Open a new Zethus view.',
isVisible: () => true,
isEnabled: () => true,
isToggled: () => widget !== null,
execute: () => {
if (widget) {
widget.dispose();
} else {
widget = new ZethusWidget();
widget.disposed.connect(() => {
widget = null;
commands.notifyCommandChanged();
});
app.shell.add(widget, 'main');
tracker.add(widget);
widget.update();
commands.notifyCommandChanged();
}
}
});
palette.addItem({ command, category: 'ROS' });
}
}
Example #8
Source File: index.ts From jlab-enhanced-launcher with BSD 3-Clause "New" or "Revised" License | 5 votes |
plugin: JupyterFrontEndPlugin<ILauncher> = {
activate,
id: EXTENSION_ID,
requires: [ITranslator],
optional: [ILabShell, ICommandPalette, ISettingRegistry, IStateDB],
provides: ILauncher,
autoStart: true
}
Example #9
Source File: plugin.ts From jupyter-videochat with BSD 3-Clause "New" or "Revised" License | 5 votes |
corePlugin: JupyterFrontEndPlugin<IVideoChatManager> = {
id: `${NS}:plugin`,
autoStart: true,
requires: [ISettingRegistry],
optional: [ITranslator, ICommandPalette, ILauncher, ILayoutRestorer, IMainMenu],
provides: IVideoChatManager,
activate: activateCore,
}
Example #10
Source File: plugin.ts From jupyter-videochat with BSD 3-Clause "New" or "Revised" License | 5 votes |
publicRoomsPlugin: JupyterFrontEndPlugin<void> = {
id: `${NS}:rooms-public`,
autoStart: true,
requires: [IVideoChatManager],
optional: [IRouter, ICommandPalette],
activate: activatePublicRooms,
}
Example #11
Source File: plugin.ts From jupyter-videochat with BSD 3-Clause "New" or "Revised" License | 5 votes |
areaTogglePlugin: JupyterFrontEndPlugin<void> = {
id: `${NS}:toggle-area`,
autoStart: true,
requires: [IVideoChatManager],
optional: [ICommandPalette],
activate: activateToggleArea,
}
Example #12
Source File: plugin.tsx From jupyterlab-tour with BSD 3-Clause "New" or "Revised" License | 5 votes |
function activate(
app: JupyterFrontEnd,
stateDB: IStateDB,
palette?: ICommandPalette,
menu?: MainMenu,
translator?: ITranslator
): ITourManager {
const { commands } = app;
translator = translator ?? nullTranslator;
// Create tour manager
const manager = new TourManager(stateDB, translator, menu);
commands.addCommand(CommandIDs.launch, {
label: args => {
if (args['id']) {
const tour = manager.tours.get(args['id'] as string) as TourHandler;
return manager.translator.__(tour.label);
} else {
return manager.translator.__('Launch a Tour');
}
},
usage: manager.translator.__(
'Launch a tour.\nIf no id provided, prompt the user.\nArguments {id: Tour ID}'
),
isEnabled: () => !manager.activeTour,
execute: async args => {
let id = args['id'] as string;
const force =
args['force'] === undefined ? true : (args['force'] as boolean);
if (!id) {
const answer = await InputDialog.getItem({
items: Array.from(manager.tours.keys()),
title: manager.translator.__('Choose a tour')
});
if (answer.button.accept && answer.value) {
id = answer.value;
} else {
return;
}
}
manager.launch([id], force);
}
});
commands.addCommand(CommandIDs.addTour, {
label: manager.translator.__('Add a tour'),
usage: manager.translator.__(
'Add a tour and returns it.\nArguments {tour: ITour}\nReturns `null` if a failure occurs.'
),
execute: (args): ITourHandler | null => {
return manager.addTour(args.tour as any);
}
});
if (palette) {
palette.addItem({
category: manager.translator.__('Help'),
command: CommandIDs.launch
});
}
const node = document.createElement('div');
document.body.appendChild(node);
ReactDOM.render(<TourContainer tourLaunched={manager.tourLaunched} />, node);
return manager;
}
Example #13
Source File: plugin.tsx From jupyterlab-tour with BSD 3-Clause "New" or "Revised" License | 5 votes |
corePlugin: JupyterFrontEndPlugin<ITourManager> = {
id: PLUGIN_ID,
autoStart: true,
activate,
requires: [IStateDB],
optional: [ICommandPalette, IMainMenu, ITranslator],
provides: ITourManager
}
Example #14
Source File: index.ts From jlab-enhanced-launcher with BSD 3-Clause "New" or "Revised" License | 4 votes |
/**
* Activate the launcher.
*/
async function activate(
app: JupyterFrontEnd,
translator: ITranslator,
labShell: ILabShell | null,
palette: ICommandPalette | null,
settingRegistry: ISettingRegistry | null,
state: IStateDB | null
): Promise<ILauncher> {
const { commands, shell } = app;
const trans = translator.load('jupyterlab');
let settings: ISettingRegistry.ISettings | null = null;
if (settingRegistry) {
try {
settings = await settingRegistry.load(EXTENSION_ID);
} catch (reason) {
console.log(`Failed to load settings for ${EXTENSION_ID}.`, reason);
}
}
const model = new LauncherModel(settings, state);
if (state) {
Promise.all([
state.fetch(`${EXTENSION_ID}:usageData`),
state.fetch(`${EXTENSION_ID}:viewMode`),
app.restored
])
.then(([usage, mode]) => {
model.viewMode = (mode as any) || 'cards';
for (const key in usage as any) {
model.usage[key] = (usage as any)[key];
}
})
.catch(reason => {
console.error('Fail to restore launcher usage data', reason);
});
}
commands.addCommand(CommandIDs.create, {
label: trans.__('New Launcher'),
execute: (args: ReadonlyPartialJSONObject) => {
const cwd = args['cwd'] ? String(args['cwd']) : '';
const id = `launcher-${Private.id++}`;
const callback = (item: Widget): void => {
shell.add(item, 'main', { ref: id });
};
const launcher = new Launcher({ model, cwd, callback, commands });
launcher.model = model;
launcher.title.icon = launcherIcon;
launcher.title.label = trans.__('Launcher');
const main = new MainAreaWidget({ content: launcher });
// If there are any other widgets open, remove the launcher close icon.
main.title.closable = !!toArray(shell.widgets('main')).length;
main.id = id;
shell.add(main, 'main', {
activate: args['activate'] as boolean,
ref: args['ref'] as string
});
if (labShell) {
labShell.layoutModified.connect(() => {
// If there is only a launcher open, remove the close icon.
main.title.closable = toArray(labShell.widgets('main')).length > 1;
}, main);
}
return main;
}
});
if (palette) {
palette.addItem({
command: CommandIDs.create,
category: trans.__('Launcher')
});
}
if (labShell && app.version >= '3.4.0') {
labShell.addButtonEnabled = true;
labShell.addRequested.connect((sender: DockPanel, arg: TabBar<Widget>) => {
// Get the ref for the current tab of the tabbar which the add button was clicked
const ref =
arg.currentTitle?.owner.id ||
arg.titles[arg.titles.length - 1].owner.id;
if (commands.hasCommand('filebrowser:create-main-launcher')) {
// If a file browser is defined connect the launcher to it
return commands.execute('filebrowser:create-main-launcher', { ref });
}
return commands.execute(CommandIDs.create, { ref });
});
}
return model;
}
Example #15
Source File: plugin.ts From jupyter-videochat with BSD 3-Clause "New" or "Revised" License | 4 votes |
/**
* Handle application-level concerns
*/
async function activateCore(
app: JupyterFrontEnd,
settingRegistry: ISettingRegistry,
translator?: ITranslator,
palette?: ICommandPalette,
launcher?: ILauncher,
restorer?: ILayoutRestorer,
mainmenu?: IMainMenu
): Promise<IVideoChatManager> {
const { commands, shell } = app;
const labShell = isFullLab(app) ? (shell as LabShell) : null;
const manager = new VideoChatManager({
trans: (translator || nullTranslator).load(NS),
});
const { __ } = manager;
let widget: MainAreaWidget;
let chat: VideoChat;
let subject: string | null = null;
const tracker = new WidgetTracker<MainAreaWidget>({ namespace: NS });
if (!widget || widget.isDisposed) {
// Create widget
chat = new VideoChat(manager, {});
widget = new MainAreaWidget({ content: chat });
widget.addClass(`${CSS}-wrapper`);
manager.setMainWidget(widget);
widget.toolbar.addItem(ToolbarIds.SPACER_LEFT, Toolbar.createSpacerItem());
widget.toolbar.addItem(ToolbarIds.TITLE, new RoomTitle(manager));
widget.toolbar.addItem(ToolbarIds.SPACER_RIGHT, Toolbar.createSpacerItem());
const disconnectBtn = new CommandToolbarButton({
id: CommandIds.disconnect,
commands,
icon: stopIcon,
});
const onCurrentRoomChanged = () => {
if (manager.currentRoom) {
disconnectBtn.show();
} else {
disconnectBtn.hide();
}
};
manager.currentRoomChanged.connect(onCurrentRoomChanged);
widget.toolbar.addItem(ToolbarIds.DISCONNECT, disconnectBtn);
onCurrentRoomChanged();
chat.id = `id-${NS}`;
chat.title.caption = __(DEFAULT_LABEL);
chat.title.closable = false;
chat.title.icon = chatIcon;
}
// hide the label when in sidebar, as it shows the rotated text
function updateTitle() {
if (subject != null) {
widget.title.caption = subject;
} else {
widget.title.caption = __(DEFAULT_LABEL);
}
widget.title.label = manager.currentArea === 'main' ? widget.title.caption : '';
}
// add to shell, update tracker, title, etc.
function addToShell(area?: ILabShell.Area, activate = true) {
DEBUG && console.warn(`add to shell in are ${area}, ${!activate || 'not '} active`);
area = area || manager.currentArea;
if (labShell) {
labShell.add(widget, area);
updateTitle();
widget.update();
if (!tracker.has(widget)) {
tracker.add(widget).catch(void 0);
}
if (activate) {
shell.activateById(widget.id);
}
} else if (window.location.search.indexOf(FORCE_URL_PARAM) !== -1) {
document.title = [document.title.split(' - ')[0], __(DEFAULT_LABEL)].join(' - ');
app.shell.currentWidget.parent = null;
app.shell.add(widget, 'main', { rank: 0 });
const { parent } = widget;
parent.addClass(`${CSS}-main-parent`);
setTimeout(() => {
parent.update();
parent.fit();
app.shell.fit();
app.shell.update();
}, 100);
}
}
// listen for the subject to update the widget title dynamically
manager.meetChanged.connect(() => {
if (manager.meet) {
manager.meet.on('subjectChange', (args: any) => {
subject = args.subject;
updateTitle();
});
} else {
subject = null;
}
updateTitle();
});
// connect settings
settingRegistry
.load(corePlugin.id)
.then((settings) => {
manager.settings = settings;
let lastArea = manager.settings.composite.area;
settings.changed.connect(() => {
if (lastArea !== manager.settings.composite.area) {
addToShell();
}
lastArea = manager.settings.composite.area;
});
addToShell(null, false);
})
.catch(() => addToShell(null, false));
// add commands
commands.addCommand(CommandIds.open, {
label: __(DEFAULT_LABEL),
icon: prettyChatIcon,
execute: async (args: IChatArgs) => {
await manager.initialized;
addToShell(null, true);
// Potentially navigate to new room
if (manager.currentRoom?.displayName !== args.displayName) {
manager.currentRoom = { displayName: args.displayName };
}
},
});
commands.addCommand(CommandIds.disconnect, {
label: __('Disconnect Video Chat'),
execute: () => (manager.currentRoom = null),
icon: stopIcon,
});
commands.addCommand(CommandIds.toggleArea, {
label: __('Toggle Video Chat Sidebar'),
icon: launcherIcon,
execute: async () => {
manager.currentArea = ['right', 'left'].includes(manager.currentArea)
? 'main'
: 'right';
},
});
// If available, add the commands to the palette
if (palette) {
palette.addItem({ command: CommandIds.open, category: __(category) });
}
// If available, add a card to the launcher
if (launcher) {
launcher.add({ command: CommandIds.open, args: { area: 'main' } });
}
// If available, restore the position
if (restorer) {
restorer
.restore(tracker, { command: CommandIds.open, name: () => `id-${NS}` })
.catch(console.warn);
}
// If available, add to the file->new menu.... new tab handled in retroPlugin
if (mainmenu && labShell) {
mainmenu.fileMenu.newMenu.addGroup([{ command: CommandIds.open }]);
}
// Return the manager that others extensions can use
return manager;
}
Example #16
Source File: plugin.ts From jupyter-videochat with BSD 3-Clause "New" or "Revised" License | 4 votes |
/**
* Create the public room plugin
*
* In the future, this might `provide` itself with some reasonable API,
* but is already accessible from the manager, which is likely preferable.
*/
async function activatePublicRooms(
app: JupyterFrontEnd,
chat: IVideoChatManager,
router?: IRouter,
palette?: ICommandPalette
): Promise<void> {
const { commands } = app;
const { __ } = chat;
chat.registerRoomProvider({
id: 'public',
label: __('Public'),
rank: 999,
provider: {
updateRooms: async () => [],
canCreateRooms: false,
updateConfig: async () => {
return {} as any;
},
},
});
commands.addCommand(CommandIds.togglePublicRooms, {
label: __('Toggle Video Chat Public Rooms'),
isVisible: () => !!chat.settings,
isToggleable: true,
isToggled: () => !chat.settings?.composite.disablePublicRooms,
execute: async () => {
if (!chat.settings) {
console.warn(__('Video chat settings not loaded'));
return;
}
await chat.settings.set(
'disablePublicRooms',
!chat.settings?.composite.disablePublicRooms
);
},
});
// If available, Add to the router
if (router) {
commands.addCommand(CommandIds.publicRouterStart, {
label: __('Open Public Video Chat from URL'),
execute: async (args) => {
const { request } = args as IRouter.ILocation;
const url = new URL(`http://example.com${request}`);
const params = url.searchParams;
const roomId = params.get(PUBLIC_URL_PARAM);
const chatAfterRoute = async () => {
router.routed.disconnect(chatAfterRoute);
if (chat.currentRoom?.displayName != roomId) {
chat.currentRoom = {
id: roomId,
displayName: roomId,
description: __('A Public Room'),
};
}
};
router.routed.connect(chatAfterRoute);
},
});
router.register({
command: CommandIds.publicRouterStart,
pattern: /.*/,
rank: 99,
});
}
// If available, add to command palette
if (palette) {
palette.addItem({ command: CommandIds.togglePublicRooms, category });
}
}