|
@@ -64,8 +64,6 @@ import { IPropertyInspectorProvider } from '@jupyterlab/property-inspector';
|
|
|
|
|
|
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
|
|
|
|
-import { ServiceManager } from '@jupyterlab/services';
|
|
|
-
|
|
|
import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
|
|
|
|
import { IStateDB } from '@jupyterlab/statedb';
|
|
@@ -257,7 +255,7 @@ const FORMAT_EXCLUDE = ['notebook', 'python', 'custom'];
|
|
|
const trackerPlugin: JupyterFrontEndPlugin<INotebookTracker> = {
|
|
|
id: '@jupyterlab/notebook-extension:tracker',
|
|
|
provides: INotebookTracker,
|
|
|
- requires: [INotebookWidgetFactory, IDocumentManager, ITranslator],
|
|
|
+ requires: [INotebookWidgetFactory, ITranslator],
|
|
|
optional: [
|
|
|
ICommandPalette,
|
|
|
IFileBrowserFactory,
|
|
@@ -336,6 +334,116 @@ export const commandEditItem: JupyterFrontEndPlugin<void> = {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * A plugin providing export commands in the main menu and command palette
|
|
|
+ */
|
|
|
+export const exportPlugin: JupyterFrontEndPlugin<void> = {
|
|
|
+ id: '@jupyterlab/notebook-extension:export',
|
|
|
+ autoStart: true,
|
|
|
+ requires: [ITranslator, INotebookTracker],
|
|
|
+ optional: [IMainMenu, ICommandPalette],
|
|
|
+ activate: (
|
|
|
+ app: JupyterFrontEnd,
|
|
|
+ translator: ITranslator,
|
|
|
+ tracker: INotebookTracker,
|
|
|
+ mainMenu: IMainMenu | null,
|
|
|
+ palette: ICommandPalette | null
|
|
|
+ ) => {
|
|
|
+ const trans = translator.load('jupyterlab');
|
|
|
+ const { commands, shell } = app;
|
|
|
+ const services = app.serviceManager;
|
|
|
+
|
|
|
+ const isEnabled = (): boolean => {
|
|
|
+ return Private.isEnabled(shell, tracker);
|
|
|
+ };
|
|
|
+
|
|
|
+ commands.addCommand(CommandIDs.exportToFormat, {
|
|
|
+ label: args => {
|
|
|
+ const formatLabel = args['label'] as string;
|
|
|
+ return args['isPalette']
|
|
|
+ ? trans.__('Export Notebook: %1', formatLabel)
|
|
|
+ : formatLabel;
|
|
|
+ },
|
|
|
+ execute: args => {
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
+
|
|
|
+ if (!current) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const url = PageConfig.getNBConvertURL({
|
|
|
+ format: args['format'] as string,
|
|
|
+ download: true,
|
|
|
+ path: current.context.path
|
|
|
+ });
|
|
|
+ const child = window.open('', '_blank');
|
|
|
+ const { context } = current;
|
|
|
+
|
|
|
+ if (child) {
|
|
|
+ child.opener = null;
|
|
|
+ }
|
|
|
+ if (context.model.dirty && !context.model.readOnly) {
|
|
|
+ return context.save().then(() => {
|
|
|
+ child?.location.assign(url);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return new Promise<void>(resolve => {
|
|
|
+ child?.location.assign(url);
|
|
|
+ resolve(undefined);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ isEnabled
|
|
|
+ });
|
|
|
+
|
|
|
+ // Add a notebook group to the File menu.
|
|
|
+ const exportTo = new Menu({ commands });
|
|
|
+ exportTo.title.label = trans.__('Export Notebook As…');
|
|
|
+ void services.nbconvert.getExportFormats().then(response => {
|
|
|
+ if (response) {
|
|
|
+ const formatLabels: any = Private.getFormatLabels(translator);
|
|
|
+
|
|
|
+ // Convert export list to palette and menu items.
|
|
|
+ const formatList = Object.keys(response);
|
|
|
+ formatList.forEach(function (key) {
|
|
|
+ const capCaseKey = trans.__(key[0].toUpperCase() + key.substr(1));
|
|
|
+ const labelStr = formatLabels[key] ? formatLabels[key] : capCaseKey;
|
|
|
+ let args = {
|
|
|
+ format: key,
|
|
|
+ label: labelStr,
|
|
|
+ isPalette: false
|
|
|
+ };
|
|
|
+ if (FORMAT_EXCLUDE.indexOf(key) === -1) {
|
|
|
+ exportTo.addItem({
|
|
|
+ command: CommandIDs.exportToFormat,
|
|
|
+ args: args
|
|
|
+ });
|
|
|
+ if (palette) {
|
|
|
+ args = {
|
|
|
+ format: key,
|
|
|
+ label: labelStr,
|
|
|
+ isPalette: true
|
|
|
+ };
|
|
|
+ const category = trans.__('Notebook Operations');
|
|
|
+ palette.addItem({
|
|
|
+ command: CommandIDs.exportToFormat,
|
|
|
+ category,
|
|
|
+ args
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (mainMenu) {
|
|
|
+ const fileGroup = [
|
|
|
+ { type: 'submenu', submenu: exportTo } as Menu.IItemOptions
|
|
|
+ ];
|
|
|
+ mainMenu.fileMenu.addGroup(fileGroup, 10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* A plugin that adds a notebook trust status item to the status bar.
|
|
|
*/
|
|
@@ -422,6 +530,7 @@ const codeConsolePlugin: JupyterFrontEndPlugin<void> = {
|
|
|
const plugins: JupyterFrontEndPlugin<any>[] = [
|
|
|
factory,
|
|
|
trackerPlugin,
|
|
|
+ exportPlugin,
|
|
|
tools,
|
|
|
commandEditItem,
|
|
|
notebookTrustItem,
|
|
@@ -827,7 +936,6 @@ function activateCodeConsole(
|
|
|
function activateNotebookHandler(
|
|
|
app: JupyterFrontEnd,
|
|
|
factory: NotebookWidgetFactory.IFactory,
|
|
|
- docManager: IDocumentManager,
|
|
|
translator: ITranslator,
|
|
|
palette: ICommandPalette | null,
|
|
|
browserFactory: IFileBrowserFactory | null,
|
|
@@ -859,7 +967,7 @@ function activateNotebookHandler(
|
|
|
addCommands(app, tracker, translator, sessionDialogs);
|
|
|
|
|
|
if (palette) {
|
|
|
- populatePalette(palette, services, translator);
|
|
|
+ populatePalette(palette, translator);
|
|
|
}
|
|
|
|
|
|
let id = 0; // The ID counter for notebook panels.
|
|
@@ -950,15 +1058,7 @@ function activateNotebookHandler(
|
|
|
|
|
|
// Add main menu notebook menu.
|
|
|
if (mainMenu) {
|
|
|
- populateMenus(
|
|
|
- app,
|
|
|
- mainMenu,
|
|
|
- tracker,
|
|
|
- services,
|
|
|
- translator,
|
|
|
- palette,
|
|
|
- sessionDialogs
|
|
|
- );
|
|
|
+ populateMenus(app, mainMenu, tracker, translator, sessionDialogs);
|
|
|
}
|
|
|
|
|
|
// Utility function to create a new notebook.
|
|
@@ -1169,6 +1269,22 @@ function activateNotebookHandler(
|
|
|
return tracker;
|
|
|
}
|
|
|
|
|
|
+// Get the current widget and activate unless the args specify otherwise.
|
|
|
+function getCurrent(
|
|
|
+ tracker: INotebookTracker,
|
|
|
+ shell: JupyterFrontEnd.IShell,
|
|
|
+ args: ReadonlyPartialJSONObject
|
|
|
+): NotebookPanel | null {
|
|
|
+ const widget = tracker.currentWidget;
|
|
|
+ const activate = args['activate'] !== false;
|
|
|
+
|
|
|
+ if (activate && widget) {
|
|
|
+ shell.activateById(widget.id);
|
|
|
+ }
|
|
|
+
|
|
|
+ return widget;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Add the notebook commands to the application's command registry.
|
|
|
*/
|
|
@@ -1183,18 +1299,6 @@ function addCommands(
|
|
|
|
|
|
sessionDialogs = sessionDialogs ?? sessionContextDialogs;
|
|
|
|
|
|
- // Get the current widget and activate unless the args specify otherwise.
|
|
|
- function getCurrent(args: ReadonlyPartialJSONObject): NotebookPanel | null {
|
|
|
- const widget = tracker.currentWidget;
|
|
|
- const activate = args['activate'] !== false;
|
|
|
-
|
|
|
- if (activate && widget) {
|
|
|
- shell.activateById(widget.id);
|
|
|
- }
|
|
|
-
|
|
|
- return widget;
|
|
|
- }
|
|
|
-
|
|
|
const isEnabled = (): boolean => {
|
|
|
return Private.isEnabled(shell, tracker);
|
|
|
};
|
|
@@ -1206,7 +1310,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.runAndAdvance, {
|
|
|
label: trans.__('Run Selected Cells'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
const { context, content } = current;
|
|
@@ -1219,7 +1323,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.run, {
|
|
|
label: trans.__("Run Selected Cells and Don't Advance"),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
const { context, content } = current;
|
|
@@ -1232,7 +1336,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.runAndInsert, {
|
|
|
label: trans.__('Run Selected Cells and Insert Below'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
const { context, content } = current;
|
|
@@ -1245,7 +1349,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.runAll, {
|
|
|
label: trans.__('Run All Cells'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
const { context, content } = current;
|
|
@@ -1258,7 +1362,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.runAllAbove, {
|
|
|
label: trans.__('Run All Above Selected Cell'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
const { context, content } = current;
|
|
@@ -1278,7 +1382,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.runAllBelow, {
|
|
|
label: trans.__('Run Selected Cell and All Below'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
const { context, content } = current;
|
|
@@ -1299,7 +1403,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.renderAllMarkdown, {
|
|
|
label: trans.__('Render All Markdown Cells'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
if (current) {
|
|
|
const { context, content } = current;
|
|
|
return NotebookActions.renderAllMarkdown(
|
|
@@ -1313,7 +1417,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.restart, {
|
|
|
label: trans.__('Restart Kernel…'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return sessionDialogs!.restart(current.sessionContext, translator);
|
|
@@ -1324,7 +1428,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.closeAndShutdown, {
|
|
|
label: trans.__('Close and Shut Down'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (!current) {
|
|
|
return;
|
|
@@ -1349,7 +1453,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.trust, {
|
|
|
label: () => trans.__('Trust Notebook'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
if (current) {
|
|
|
const { context, content } = current;
|
|
|
return NotebookActions.trust(content).then(() => context.save());
|
|
@@ -1357,48 +1461,10 @@ function addCommands(
|
|
|
},
|
|
|
isEnabled
|
|
|
});
|
|
|
- commands.addCommand(CommandIDs.exportToFormat, {
|
|
|
- label: args => {
|
|
|
- const formatLabel = args['label'] as string;
|
|
|
- return args['isPalette']
|
|
|
- ? trans.__('Export Notebook: %1', formatLabel)
|
|
|
- : formatLabel;
|
|
|
- },
|
|
|
- execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
-
|
|
|
- if (!current) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const url = PageConfig.getNBConvertURL({
|
|
|
- format: args['format'] as string,
|
|
|
- download: true,
|
|
|
- path: current.context.path
|
|
|
- });
|
|
|
- const child = window.open('', '_blank');
|
|
|
- const { context } = current;
|
|
|
-
|
|
|
- if (child) {
|
|
|
- child.opener = null;
|
|
|
- }
|
|
|
- if (context.model.dirty && !context.model.readOnly) {
|
|
|
- return context.save().then(() => {
|
|
|
- child?.location.assign(url);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- return new Promise<void>(resolve => {
|
|
|
- child?.location.assign(url);
|
|
|
- resolve(undefined);
|
|
|
- });
|
|
|
- },
|
|
|
- isEnabled
|
|
|
- });
|
|
|
commands.addCommand(CommandIDs.restartClear, {
|
|
|
label: trans.__('Restart Kernel and Clear All Outputs…'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
const { content, sessionContext } = current;
|
|
@@ -1413,7 +1479,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.restartAndRunToSelected, {
|
|
|
label: trans.__('Restart Kernel and Run up to Selected Cell…'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
if (current) {
|
|
|
const { context, content } = current;
|
|
|
return sessionDialogs!
|
|
@@ -1437,7 +1503,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.restartRunAll, {
|
|
|
label: trans.__('Restart Kernel and Run All Cells…'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
const { context, content, sessionContext } = current;
|
|
@@ -1457,7 +1523,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.clearAllOutputs, {
|
|
|
label: trans.__('Clear All Outputs'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.clearAllOutputs(current.content);
|
|
@@ -1468,7 +1534,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.clearOutputs, {
|
|
|
label: trans.__('Clear Outputs'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.clearOutputs(current.content);
|
|
@@ -1479,7 +1545,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.interrupt, {
|
|
|
label: trans.__('Interrupt Kernel'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (!current) {
|
|
|
return;
|
|
@@ -1496,7 +1562,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.toCode, {
|
|
|
label: trans.__('Change to Code Cell Type'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.changeCellType(current.content, 'code');
|
|
@@ -1507,7 +1573,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.toMarkdown, {
|
|
|
label: trans.__('Change to Markdown Cell Type'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.changeCellType(current.content, 'markdown');
|
|
@@ -1518,7 +1584,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.toRaw, {
|
|
|
label: trans.__('Change to Raw Cell Type'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.changeCellType(current.content, 'raw');
|
|
@@ -1529,7 +1595,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.cut, {
|
|
|
label: trans.__('Cut Cells'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.cut(current.content);
|
|
@@ -1540,7 +1606,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.copy, {
|
|
|
label: trans.__('Copy Cells'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.copy(current.content);
|
|
@@ -1551,7 +1617,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.pasteBelow, {
|
|
|
label: trans.__('Paste Cells Below'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.paste(current.content, 'below');
|
|
@@ -1562,7 +1628,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.pasteAbove, {
|
|
|
label: trans.__('Paste Cells Above'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.paste(current.content, 'above');
|
|
@@ -1573,7 +1639,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.pasteAndReplace, {
|
|
|
label: trans.__('Paste Cells and Replace'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.paste(current.content, 'replace');
|
|
@@ -1584,7 +1650,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.deleteCell, {
|
|
|
label: trans.__('Delete Cells'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.deleteCells(current.content);
|
|
@@ -1595,7 +1661,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.split, {
|
|
|
label: trans.__('Split Cell'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.splitCell(current.content);
|
|
@@ -1606,7 +1672,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.merge, {
|
|
|
label: trans.__('Merge Selected Cells'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.mergeCells(current.content);
|
|
@@ -1617,7 +1683,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.insertAbove, {
|
|
|
label: trans.__('Insert Cell Above'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.insertAbove(current.content);
|
|
@@ -1628,7 +1694,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.insertBelow, {
|
|
|
label: trans.__('Insert Cell Below'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.insertBelow(current.content);
|
|
@@ -1639,7 +1705,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.selectAbove, {
|
|
|
label: trans.__('Select Cell Above'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.selectAbove(current.content);
|
|
@@ -1650,7 +1716,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.selectBelow, {
|
|
|
label: trans.__('Select Cell Below'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.selectBelow(current.content);
|
|
@@ -1661,7 +1727,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.extendAbove, {
|
|
|
label: trans.__('Extend Selection Above'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.extendSelectionAbove(current.content);
|
|
@@ -1672,7 +1738,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.extendTop, {
|
|
|
label: trans.__('Extend Selection to Top'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.extendSelectionAbove(current.content, true);
|
|
@@ -1683,7 +1749,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.extendBelow, {
|
|
|
label: trans.__('Extend Selection Below'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.extendSelectionBelow(current.content);
|
|
@@ -1694,7 +1760,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.extendBottom, {
|
|
|
label: trans.__('Extend Selection to Bottom'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.extendSelectionBelow(current.content, true);
|
|
@@ -1705,7 +1771,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.selectAll, {
|
|
|
label: trans.__('Select All Cells'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.selectAll(current.content);
|
|
@@ -1716,7 +1782,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.deselectAll, {
|
|
|
label: trans.__('Deselect All Cells'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.deselectAll(current.content);
|
|
@@ -1727,7 +1793,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.moveUp, {
|
|
|
label: trans.__('Move Cells Up'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.moveUp(current.content);
|
|
@@ -1738,7 +1804,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.moveDown, {
|
|
|
label: trans.__('Move Cells Down'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.moveDown(current.content);
|
|
@@ -1749,7 +1815,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.toggleAllLines, {
|
|
|
label: trans.__('Toggle All Line Numbers'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.toggleAllLineNumbers(current.content);
|
|
@@ -1760,7 +1826,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.commandMode, {
|
|
|
label: trans.__('Enter Command Mode'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
current.content.mode = 'command';
|
|
@@ -1771,7 +1837,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.editMode, {
|
|
|
label: trans.__('Enter Edit Mode'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
current.content.mode = 'edit';
|
|
@@ -1782,7 +1848,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.undoCellAction, {
|
|
|
label: trans.__('Undo Cell Operation'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.undo(current.content);
|
|
@@ -1793,7 +1859,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.redoCellAction, {
|
|
|
label: trans.__('Redo Cell Operation'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.redo(current.content);
|
|
@@ -1804,7 +1870,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.changeKernel, {
|
|
|
label: trans.__('Change Kernel…'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return sessionDialogs!.selectKernel(
|
|
@@ -1818,7 +1884,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.reconnectToKernel, {
|
|
|
label: trans.__('Reconnect To Kernel'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (!current) {
|
|
|
return;
|
|
@@ -1835,7 +1901,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.markdown1, {
|
|
|
label: trans.__('Change to Heading 1'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.setMarkdownHeader(current.content, 1);
|
|
@@ -1846,7 +1912,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.markdown2, {
|
|
|
label: trans.__('Change to Heading 2'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.setMarkdownHeader(current.content, 2);
|
|
@@ -1857,7 +1923,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.markdown3, {
|
|
|
label: trans.__('Change to Heading 3'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.setMarkdownHeader(current.content, 3);
|
|
@@ -1868,7 +1934,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.markdown4, {
|
|
|
label: trans.__('Change to Heading 4'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.setMarkdownHeader(current.content, 4);
|
|
@@ -1879,7 +1945,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.markdown5, {
|
|
|
label: trans.__('Change to Heading 5'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.setMarkdownHeader(current.content, 5);
|
|
@@ -1890,7 +1956,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.markdown6, {
|
|
|
label: trans.__('Change to Heading 6'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.setMarkdownHeader(current.content, 6);
|
|
@@ -1901,7 +1967,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.hideCode, {
|
|
|
label: trans.__('Collapse Selected Code'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.hideCode(current.content);
|
|
@@ -1912,7 +1978,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.showCode, {
|
|
|
label: trans.__('Expand Selected Code'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.showCode(current.content);
|
|
@@ -1923,7 +1989,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.hideAllCode, {
|
|
|
label: trans.__('Collapse All Code'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.hideAllCode(current.content);
|
|
@@ -1934,7 +2000,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.showAllCode, {
|
|
|
label: trans.__('Expand All Code'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.showAllCode(current.content);
|
|
@@ -1945,7 +2011,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.hideOutput, {
|
|
|
label: trans.__('Collapse Selected Outputs'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.hideOutput(current.content);
|
|
@@ -1956,7 +2022,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.showOutput, {
|
|
|
label: trans.__('Expand Selected Outputs'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.showOutput(current.content);
|
|
@@ -1967,7 +2033,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.hideAllOutputs, {
|
|
|
label: trans.__('Collapse All Outputs'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.hideAllOutputs(current.content);
|
|
@@ -1978,7 +2044,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.showAllOutputs, {
|
|
|
label: trans.__('Expand All Outputs'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.showAllOutputs(current.content);
|
|
@@ -1989,7 +2055,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.enableOutputScrolling, {
|
|
|
label: trans.__('Enable Scrolling for Outputs'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.enableOutputScrolling(current.content);
|
|
@@ -2000,7 +2066,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.disableOutputScrolling, {
|
|
|
label: trans.__('Disable Scrolling for Outputs'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.disableOutputScrolling(current.content);
|
|
@@ -2011,7 +2077,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.selectLastRunCell, {
|
|
|
label: trans.__('Select current running or last run cell'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
|
|
|
if (current) {
|
|
|
return NotebookActions.selectLastRunCell(current.content);
|
|
@@ -2022,7 +2088,7 @@ function addCommands(
|
|
|
commands.addCommand(CommandIDs.replaceSelection, {
|
|
|
label: trans.__('Replace Selection in Notebook Cell'),
|
|
|
execute: args => {
|
|
|
- const current = getCurrent(args);
|
|
|
+ const current = getCurrent(tracker, shell, args);
|
|
|
const text: string = (args['text'] as string) || '';
|
|
|
if (current) {
|
|
|
return NotebookActions.replaceSelection(current.content, text);
|
|
@@ -2037,7 +2103,6 @@ function addCommands(
|
|
|
*/
|
|
|
function populatePalette(
|
|
|
palette: ICommandPalette,
|
|
|
- services: ServiceManager,
|
|
|
translator: ITranslator
|
|
|
): void {
|
|
|
const trans = translator.load('jupyterlab');
|
|
@@ -2132,9 +2197,7 @@ function populateMenus(
|
|
|
app: JupyterFrontEnd,
|
|
|
mainMenu: IMainMenu,
|
|
|
tracker: INotebookTracker,
|
|
|
- services: ServiceManager,
|
|
|
translator: ITranslator,
|
|
|
- palette: ICommandPalette | null,
|
|
|
sessionDialogs: ISessionContextDialogs | null
|
|
|
): void {
|
|
|
const trans = translator.load('jupyterlab');
|
|
@@ -2191,50 +2254,6 @@ function populateMenus(
|
|
|
}
|
|
|
} as IFileMenu.ICloseAndCleaner<NotebookPanel>);
|
|
|
|
|
|
- // Add a notebook group to the File menu.
|
|
|
- const exportTo = new Menu({ commands });
|
|
|
- exportTo.title.label = trans.__('Export Notebook As…');
|
|
|
- void services.nbconvert.getExportFormats().then(response => {
|
|
|
- if (response) {
|
|
|
- const formatLabels: any = Private.getFormatLabels(translator);
|
|
|
-
|
|
|
- // Convert export list to palette and menu items.
|
|
|
- const formatList = Object.keys(response);
|
|
|
- formatList.forEach(function (key) {
|
|
|
- const capCaseKey = trans.__(key[0].toUpperCase() + key.substr(1));
|
|
|
- const labelStr = formatLabels[key] ? formatLabels[key] : capCaseKey;
|
|
|
- let args = {
|
|
|
- format: key,
|
|
|
- label: labelStr,
|
|
|
- isPalette: false
|
|
|
- };
|
|
|
- if (FORMAT_EXCLUDE.indexOf(key) === -1) {
|
|
|
- exportTo.addItem({
|
|
|
- command: CommandIDs.exportToFormat,
|
|
|
- args: args
|
|
|
- });
|
|
|
- if (palette) {
|
|
|
- args = {
|
|
|
- format: key,
|
|
|
- label: labelStr,
|
|
|
- isPalette: true
|
|
|
- };
|
|
|
- const category = trans.__('Notebook Operations');
|
|
|
- palette.addItem({
|
|
|
- command: CommandIDs.exportToFormat,
|
|
|
- category,
|
|
|
- args
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- const fileGroup = [
|
|
|
- { type: 'submenu', submenu: exportTo } as Menu.IItemOptions
|
|
|
- ];
|
|
|
- mainMenu.fileMenu.addGroup(fileGroup, 10);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
// Add a kernel user to the Kernel menu
|
|
|
mainMenu.kernelMenu.kernelUsers.add({
|
|
|
tracker,
|