From 0d83598eebf2a0df6ec24a9966e1f2c504246701 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Wed, 9 Dec 2020 00:59:45 +0100 Subject: [PATCH 1/5] Combine the running and file browsers on tree --- builder/index.js | 3 +- packages/filebrowser-extension/src/index.ts | 51 ++++++++++--------- packages/filebrowser-extension/style/base.css | 21 ++++++++ packages/running-extension/src/index.ts | 17 +------ 4 files changed, 53 insertions(+), 39 deletions(-) diff --git a/builder/index.js b/builder/index.js index 4615c2206..fe633a941 100644 --- a/builder/index.js +++ b/builder/index.js @@ -112,7 +112,8 @@ async function main() { '@jupyterlab-classic/filebrowser-extension:browser', '@jupyterlab-classic/filebrowser-extension:factory' ].includes(id) - ) + ), + require('@jupyterlab/running-extension') ]); } else if (page === 'running') { mods = mods.concat([ diff --git a/packages/filebrowser-extension/src/index.ts b/packages/filebrowser-extension/src/index.ts index ac10b6c85..5322b5c6a 100644 --- a/packages/filebrowser-extension/src/index.ts +++ b/packages/filebrowser-extension/src/index.ts @@ -39,6 +39,8 @@ import { Launcher } from '@jupyterlab/launcher'; import { IMainMenu } from '@jupyterlab/mainmenu'; +import { IRunningSessionManagers, RunningSessions } from '@jupyterlab/running'; + import { Contents } from '@jupyterlab/services'; import { ISettingRegistry } from '@jupyterlab/settingregistry'; @@ -59,17 +61,18 @@ import { markdownIcon, newFolderIcon, pasteIcon, + runningIcon, stopIcon, textEditorIcon } from '@jupyterlab/ui-components'; -import { IIterator, map, reduce, toArray, find } from '@lumino/algorithm'; +import { IIterator, map, reduce, toArray } from '@lumino/algorithm'; import { CommandRegistry } from '@lumino/commands'; import { Message } from '@lumino/messaging'; -import { Menu } from '@lumino/widgets'; +import { Menu, TabPanel } from '@lumino/widgets'; /** * The command IDs used by the file browser plugin. @@ -149,13 +152,16 @@ const browser: JupyterFrontEndPlugin = { ICommandPalette, IMainMenu, ILayoutRestorer, - ITreePathUpdater + ITreePathUpdater, + IRunningSessionManagers ], autoStart: true }; /** * The default file browser factory provider. + * + * TODO: remove and use upstream plugin */ const factory: JupyterFrontEndPlugin = { activate: activateFactory, @@ -261,9 +267,9 @@ function activateBrowser( commandPalette: ICommandPalette | null, mainMenu: IMainMenu | null, restorer: ILayoutRestorer | null, - treePathUpdater: ITreePathUpdater | null + treePathUpdater: ITreePathUpdater | null, + manager: IRunningSessionManagers | null ): void { - const trans = translator.load('jupyterlab'); const browser = factory.defaultBrowser; const { commands } = app; @@ -288,25 +294,24 @@ function activateBrowser( ); browser.title.icon = folderIcon; - // Show the current file browser shortcut in its title. - const updateBrowserTitle = () => { - const binding = find( - app.commands.keyBindings, - b => b.command === CommandIDs.toggleBrowser - ); - if (binding) { - const ks = CommandRegistry.formatKeystroke(binding.keys.join(' ')); - browser.title.caption = trans.__('File Browser (%1)', ks); - } else { - browser.title.caption = trans.__('File Browser'); - } - }; - updateBrowserTitle(); - app.commands.keyBindingChanged.connect(() => { - updateBrowserTitle(); - }); - app.shell.add(browser, 'main', { rank: 100 }); + const tabPanel = new TabPanel({ tabPlacement: 'top', tabsMovable: false }); + tabPanel.addClass('jp-TreePanel'); + + browser.title.label = 'File Browser'; + tabPanel.addWidget(browser); + tabPanel.tabBar.addTab(browser.title); + + if (manager) { + const running = new RunningSessions(manager, translator); + running.id = 'jp-running-sessions'; + running.title.label = 'Running Sessions'; + running.title.icon = runningIcon; + tabPanel.addWidget(running); + tabPanel.tabBar.addTab(running.title); + } + + app.shell.add(tabPanel, 'main', { rank: 100 }); // If the layout is a fresh session without saved data and not in single document // mode, open file browser. diff --git a/packages/filebrowser-extension/style/base.css b/packages/filebrowser-extension/style/base.css index c0b120aa8..05c570e80 100644 --- a/packages/filebrowser-extension/style/base.css +++ b/packages/filebrowser-extension/style/base.css @@ -1,3 +1,24 @@ .jp-FileBrowser { height: 100%; } + +.lm-TabPanel { + height: 100%; +} + +.jp-TreePanel .lm-TabPanel-tabBar { + border: none; + overflow: visible; + min-height: 28px; +} + +.jp-TreePanel .lm-TabBar-tab { + color: var(--jp-ui-font-color0); + border: solid 1px var(--jp-layout-color1); + padding: 5px; +} + +.jp-TreePanel .lm-TabBar-tabLabel { + padding-left: 5px; + padding-right: 5px; +} diff --git a/packages/running-extension/src/index.ts b/packages/running-extension/src/index.ts index ebdc76b66..64ff4e3b7 100644 --- a/packages/running-extension/src/index.ts +++ b/packages/running-extension/src/index.ts @@ -6,27 +6,14 @@ import { JupyterFrontEndPlugin } from '@jupyterlab/application'; -import { IRunningSessionManagers, RunningSessions } from '@jupyterlab/running'; - -import { ITranslator } from '@jupyterlab/translation'; - /** * The default running sessions extension. */ const plugin: JupyterFrontEndPlugin = { id: '@jupyterlab-classic/running-extension:plugin', - requires: [IRunningSessionManagers], autoStart: true, - activate: ( - app: JupyterFrontEnd, - manager: IRunningSessionManagers, - translator: ITranslator - ): void => { - const running = new RunningSessions(manager, translator); - running.id = 'jp-running-sessions'; - - // re-add the widget to the main area - app.shell.add(running, 'main'); + activate: (app: JupyterFrontEnd): void => { + console.log('nope'); } }; From c01e82a98c3aec349b2645a4c1fb9c28eac78d68 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Wed, 9 Dec 2020 01:42:17 +0100 Subject: [PATCH 2/5] Tabs movable --- packages/filebrowser-extension/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/filebrowser-extension/src/index.ts b/packages/filebrowser-extension/src/index.ts index 5322b5c6a..9741bbc65 100644 --- a/packages/filebrowser-extension/src/index.ts +++ b/packages/filebrowser-extension/src/index.ts @@ -295,7 +295,7 @@ function activateBrowser( browser.title.icon = folderIcon; - const tabPanel = new TabPanel({ tabPlacement: 'top', tabsMovable: false }); + const tabPanel = new TabPanel({ tabPlacement: 'top', tabsMovable: true }); tabPanel.addClass('jp-TreePanel'); browser.title.label = 'File Browser'; From 3ba40defd9acc1ae6292035da61a87a5458ba4cf Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Wed, 9 Dec 2020 10:52:16 +0100 Subject: [PATCH 3/5] CSS tweaks and cleanup --- packages/filebrowser-extension/package.json | 1 - packages/filebrowser-extension/src/index.ts | 162 +----------------- packages/filebrowser-extension/style/base.css | 2 +- packages/notebook-extension/style/base.css | 1 + 4 files changed, 4 insertions(+), 162 deletions(-) diff --git a/packages/filebrowser-extension/package.json b/packages/filebrowser-extension/package.json index 7f018fa7b..e7cdb2434 100644 --- a/packages/filebrowser-extension/package.json +++ b/packages/filebrowser-extension/package.json @@ -42,7 +42,6 @@ "@jupyterlab/coreutils": "^5.0.0-rc.13", "@jupyterlab/docmanager": "^3.0.0-rc.13", "@jupyterlab/filebrowser": "^3.0.0-rc.13", - "@jupyterlab/launcher": "^3.0.0-rc.13", "@jupyterlab/mainmenu": "^3.0.0-rc.13", "@jupyterlab/services": "^6.0.0-rc.13", "@jupyterlab/settingregistry": "^3.0.0-rc.13", diff --git a/packages/filebrowser-extension/src/index.ts b/packages/filebrowser-extension/src/index.ts index 9741bbc65..42ccd791d 100644 --- a/packages/filebrowser-extension/src/index.ts +++ b/packages/filebrowser-extension/src/index.ts @@ -6,7 +6,6 @@ // Distributed under the terms of the Modified BSD License. import { - ILabShell, ILayoutRestorer, ITreePathUpdater, IRouter, @@ -16,8 +15,6 @@ import { import { Clipboard, - MainAreaWidget, - ToolbarButton, WidgetTracker, ICommandPalette, InputDialog, @@ -25,7 +22,7 @@ import { DOMUtils } from '@jupyterlab/apputils'; -import { PageConfig, PathExt } from '@jupyterlab/coreutils'; +import { PathExt } from '@jupyterlab/coreutils'; import { IDocumentManager } from '@jupyterlab/docmanager'; @@ -35,8 +32,6 @@ import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; -import { Launcher } from '@jupyterlab/launcher'; - import { IMainMenu } from '@jupyterlab/mainmenu'; import { IRunningSessionManagers, RunningSessions } from '@jupyterlab/running'; @@ -82,9 +77,6 @@ namespace CommandIDs { export const copyDownloadLink = 'filebrowser:copy-download-link'; - // For main browser only. - export const createLauncher = 'filebrowser:create-main-launcher'; - export const cut = 'filebrowser:cut'; export const del = 'filebrowser:delete'; @@ -148,7 +140,6 @@ const browser: JupyterFrontEndPlugin = { ITranslator ], optional: [ - ILabShell, ICommandPalette, IMainMenu, ILayoutRestorer, @@ -168,7 +159,7 @@ const factory: JupyterFrontEndPlugin = { id: '@jupyterlab-classic/filebrowser-extension:factory', provides: IFileBrowserFactory, requires: [IDocumentManager, ITranslator], - optional: [ILabShell, IStateDB, IRouter, JupyterFrontEnd.ITreeResolver] + optional: [IStateDB, IRouter, JupyterFrontEnd.ITreeResolver] }; /** @@ -189,12 +180,10 @@ async function activateFactory( app: JupyterFrontEnd, docManager: IDocumentManager, translator: ITranslator, - labShell: ILabShell | null, state: IStateDB | null, router: IRouter | null, tree: JupyterFrontEnd.ITreeResolver | null ): Promise { - const trans = translator.load('jupyterlab'); const { commands } = app; const tracker = new WidgetTracker({ namespace }); const createFileBrowser = ( @@ -213,31 +202,6 @@ async function activateFactory( const restore = options.restore; const widget = new FileBrowser({ id, model, restore, translator }); - // Add a launcher toolbar item. - if (labShell) { - const launcher = new ToolbarButton({ - icon: addIcon, - onClick: () => { - if ( - labShell.mode === 'multiple-document' && - commands.hasCommand('launcher:create') - ) { - return Private.createLauncher(commands, widget); - } else { - const newUrl = PageConfig.getUrl({ - mode: labShell.mode, - workspace: PageConfig.defaultWorkspace, - treePath: model.path - }); - window.open(newUrl, '_blank'); - } - }, - tooltip: trans.__('New Launcher'), - actualOnClick: true - }); - widget.toolbar.insertItem(0, 'launch', launcher); - } - // Track the newly created file browser. void tracker.add(widget); @@ -263,7 +227,6 @@ function activateBrowser( docManager: IDocumentManager, settingRegistry: ISettingRegistry, translator: ITranslator, - labShell: ILabShell | null, commandPalette: ICommandPalette | null, mainMenu: IMainMenu | null, restorer: ILayoutRestorer | null, @@ -271,7 +234,6 @@ function activateBrowser( manager: IRunningSessionManagers | null ): void { const browser = factory.defaultBrowser; - const { commands } = app; // Let the application restorer track the primary file browser (that is // automatically created) for restoration of application state (e.g. setting @@ -288,7 +250,6 @@ function activateBrowser( factory, settingRegistry, translator, - labShell, commandPalette, mainMenu ); @@ -313,34 +274,7 @@ function activateBrowser( app.shell.add(tabPanel, 'main', { rank: 100 }); - // If the layout is a fresh session without saved data and not in single document - // mode, open file browser. - if (labShell) { - void labShell.restored.then(layout => { - if (layout.fresh && labShell.mode !== 'single-document') { - void commands.execute(CommandIDs.showBrowser, void 0); - } - }); - } - void Promise.all([app.restored, browser.model.restored]).then(() => { - function maybeCreate() { - // Create a launcher if there are no open items. - if ( - toArray(app.shell.widgets('main')).length === 0 && - commands.hasCommand('launcher:create') - ) { - void Private.createLauncher(commands, browser); - } - } - - // When layout is modified, create a launcher if there are no open items. - if (labShell) { - labShell.layoutModified.connect(() => { - maybeCreate(); - }); - } - let navigateToCurrentDirectory = false; let useFuzzyFilter = true; @@ -364,35 +298,11 @@ function activateBrowser( browser.useFuzzyFilter = useFuzzyFilter; }); - // Whether to automatically navigate to a document's current directory - if (labShell) { - labShell.currentChanged.connect(async (_, change) => { - if (navigateToCurrentDirectory && change.newValue) { - const { newValue } = change; - const context = docManager.contextForWidget(newValue); - if (context) { - const { path } = context; - try { - await Private.navigateToPath(path, factory, translator); - labShell.currentWidget?.activate(); - } catch (reason) { - console.warn( - `${CommandIDs.goToPath} failed to open: ${path}`, - reason - ); - } - } - } - }); - } - if (treePathUpdater) { browser.model.pathChanged.connect((sender, args) => { treePathUpdater(args.newValue); }); } - - maybeCreate(); }); } @@ -404,7 +314,6 @@ function addCommands( factory: IFileBrowserFactory, settingRegistry: ISettingRegistry, translator: ITranslator, - labShell: ILabShell | null, commandPalette: ICommandPalette | null, mainMenu: IMainMenu | null ): void { @@ -474,17 +383,6 @@ function addCommands( label: trans.__('Duplicate') }); - if (labShell) { - commands.addCommand(CommandIDs.hideBrowser, { - execute: () => { - const widget = tracker.currentWidget; - if (widget && !widget.isHidden) { - labShell.collapseLeft(); - } - } - }); - } - commands.addCommand(CommandIDs.goToPath, { execute: async args => { const path = (args.path as string) || ''; @@ -745,36 +643,6 @@ function addCommands( label: trans.__('Copy Path') }); - commands.addCommand(CommandIDs.showBrowser, { - execute: args => { - const path = (args.path as string) || ''; - const browserForPath = Private.getBrowserForPath(path, factory); - - // Check for browser not found - if (!browserForPath) { - return; - } - // Shortcut if we are using the main file browser - if (browser === browserForPath) { - app.shell.activateById(browser.id); - return; - } else { - const areas: ILabShell.Area[] = ['left', 'right']; - for (const area of areas) { - const it = app.shell.widgets(area); - let widget = it.next(); - while (widget) { - if (widget.contains(browserForPath)) { - app.shell.activateById(widget.id); - return; - } - widget = it.next(); - } - } - } - } - }); - commands.addCommand(CommandIDs.shutdown, { execute: () => { const widget = tracker.currentWidget; @@ -797,11 +665,6 @@ function addCommands( } }); - commands.addCommand(CommandIDs.createLauncher, { - label: trans.__('New Launcher'), - execute: () => Private.createLauncher(commands, browser) - }); - commands.addCommand(CommandIDs.toggleNavigateToCurrentDirectory, { label: trans.__('Show Active File in File Browser'), isToggled: () => browser.navigateToCurrentDirectory, @@ -1046,27 +909,6 @@ function addCommands( * A namespace for private module data. */ namespace Private { - /** - * Create a launcher for a given filebrowser widget. - */ - export function createLauncher( - commands: CommandRegistry, - browser: FileBrowser - ): Promise> { - const { model } = browser; - - return commands - .execute('launcher:create', { cwd: model.path }) - .then((launcher: MainAreaWidget) => { - model.pathChanged.connect(() => { - if (launcher.content) { - launcher.content.cwd = model.path; - } - }, launcher); - return launcher; - }); - } - /** * Get browser object given file path. */ diff --git a/packages/filebrowser-extension/style/base.css b/packages/filebrowser-extension/style/base.css index 05c570e80..66acc305e 100644 --- a/packages/filebrowser-extension/style/base.css +++ b/packages/filebrowser-extension/style/base.css @@ -14,7 +14,7 @@ .jp-TreePanel .lm-TabBar-tab { color: var(--jp-ui-font-color0); - border: solid 1px var(--jp-layout-color1); + font-size: var(--jp-ui-font-size1); padding: 5px; } diff --git a/packages/notebook-extension/style/base.css b/packages/notebook-extension/style/base.css index 80215fcd2..460f7a21e 100644 --- a/packages/notebook-extension/style/base.css +++ b/packages/notebook-extension/style/base.css @@ -19,6 +19,7 @@ } .jp-ClassicKernelStatus { + /* TODO: replace with lab variable */ font-size: 12px; margin: 0; font-weight: normal; From 167fe671412bc1c1b40b293e1be99137312089fd Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Wed, 9 Dec 2020 11:10:40 +0100 Subject: [PATCH 4/5] Remove running page and handler --- builder/index.js | 5 - builder/package.json | 1 - builder/style.css | 1 - jupyterlab_classic/app.py | 15 --- jupyterlab_classic/templates/running.html | 36 ------- packages/application-extension/src/index.ts | 28 +---- packages/filebrowser-extension/package.json | 1 - packages/filebrowser-extension/src/index.ts | 110 +------------------- packages/running-extension/package.json | 53 ---------- packages/running-extension/src/index.ts | 23 ---- packages/running-extension/style/base.css | 3 - packages/running-extension/style/index.css | 3 - packages/running-extension/tsconfig.json | 8 -- yarn.lock | 18 +--- 14 files changed, 9 insertions(+), 296 deletions(-) delete mode 100644 jupyterlab_classic/templates/running.html delete mode 100644 packages/running-extension/package.json delete mode 100644 packages/running-extension/src/index.ts delete mode 100644 packages/running-extension/style/base.css delete mode 100644 packages/running-extension/style/index.css delete mode 100644 packages/running-extension/tsconfig.json diff --git a/builder/index.js b/builder/index.js index fe633a941..5104e529b 100644 --- a/builder/index.js +++ b/builder/index.js @@ -115,11 +115,6 @@ async function main() { ), require('@jupyterlab/running-extension') ]); - } else if (page === 'running') { - mods = mods.concat([ - require('@jupyterlab-classic/running-extension'), - require('@jupyterlab/running-extension') - ]); } else if (page === 'notebooks') { mods = mods.concat([ require('@jupyterlab/completer-extension').default.filter(({ id }) => diff --git a/builder/package.json b/builder/package.json index 2447ad297..d9a846a88 100644 --- a/builder/package.json +++ b/builder/package.json @@ -15,7 +15,6 @@ "@jupyterlab-classic/docmanager-extension": "^0.1.0", "@jupyterlab-classic/filebrowser-extension": "^0.1.0", "@jupyterlab-classic/notebook-extension": "^0.1.0", - "@jupyterlab-classic/running-extension": "^0.1.0", "@jupyterlab-classic/ui-components": "^0.1.0", "@jupyterlab/apputils-extension": "^3.0.0-rc.12", "@jupyterlab/codemirror-extension": "^3.0.0-rc.12", diff --git a/builder/style.css b/builder/style.css index 5b4cd751e..5783c2793 100644 --- a/builder/style.css +++ b/builder/style.css @@ -1,7 +1,6 @@ @import url('~@jupyterlab-classic/application-extension/style/index.css'); @import url('~@jupyterlab-classic/filebrowser-extension/style/index.css'); @import url('~@jupyterlab-classic/notebook-extension/style/index.css'); -@import url('~@jupyterlab-classic/running-extension/style/index.css'); @import url('~@jupyterlab-classic/ui-components/style/index.css'); /* TODO: check is the the extension package can be used directly */ diff --git a/jupyterlab_classic/app.py b/jupyterlab_classic/app.py index 8aa089933..da4d5c7f3 100644 --- a/jupyterlab_classic/app.py +++ b/jupyterlab_classic/app.py @@ -87,20 +87,6 @@ class ClassicTreeHandler(ClassicPageConfigMixin, ExtensionHandlerJinjaMixin, Ext ) -class ClassicRunningHandler(ClassicPageConfigMixin, ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler): - @web.authenticated - def get(self, path=None): - page_config = self.get_page_config() - return self.write( - self.render_template( - "running.html", - base_url=self.base_url, - token=self.settings["token"], - page_config=page_config, - ) - ) - - class ClassicNotebookHandler(ClassicPageConfigMixin, ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler): @web.authenticated def get(self, path=None): @@ -131,7 +117,6 @@ class ClassicApp(NBClassicConfigShimMixin, LabServerApp): def initialize_handlers(self): super().initialize_handlers() self.handlers.append(("/classic/tree(.*)", ClassicTreeHandler)) - self.handlers.append(("/classic/running", ClassicRunningHandler)) self.handlers.append(("/classic/notebooks(.*)", ClassicNotebookHandler)) def initialize_templates(self): diff --git a/jupyterlab_classic/templates/running.html b/jupyterlab_classic/templates/running.html deleted file mode 100644 index 126474aa4..000000000 --- a/jupyterlab_classic/templates/running.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - {{page_config['appName'] | e}} - Running Sessions - - - - {# Copy so we do not modify the page_config with updates. #} - {% set page_config_full = page_config.copy() %} - - {# Set a dummy variable - we just want the side effect of the update. #} - {% set _ = page_config_full.update(baseUrl=base_url, wsUrl=ws_url) %} - - {# Sentinel value to say that we are on the tree page #} - {% set _ = page_config_full.update(classicPage='running') %} - - - - - - - - diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index df95f4e9a..f3114d6cf 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -54,11 +54,6 @@ namespace CommandIDs { * Open the tree page. */ export const openTree = 'application:open-tree'; - - /** - * Open the runnning page. - */ - export const openRunning = 'application:open-running'; } /** @@ -120,34 +115,21 @@ const pages: JupyterFrontEndPlugin = { }); app.commands.addCommand(CommandIDs.openTree, { - label: 'Open the File Browser', + label: 'Open File Browser', execute: () => { window.open(`${baseUrl}classic/tree`); } }); - app.commands.addCommand(CommandIDs.openRunning, { - label: 'Open the Running Sessions', - execute: () => { - window.open(`${baseUrl}classic/running`); - } - }); - if (palette) { - [CommandIDs.openLab, CommandIDs.openRunning, CommandIDs.openTree].forEach( - command => { - palette.addItem({ command, category: 'View' }); - } - ); + [CommandIDs.openLab, CommandIDs.openTree].forEach(command => { + palette.addItem({ command, category: 'View' }); + }); } if (menu) { menu.viewMenu.addGroup( - [ - { command: CommandIDs.openLab }, - { command: CommandIDs.openTree }, - { command: CommandIDs.openRunning } - ], + [{ command: CommandIDs.openLab }, { command: CommandIDs.openTree }], 0 ); } diff --git a/packages/filebrowser-extension/package.json b/packages/filebrowser-extension/package.json index e7cdb2434..8c2ecbf7b 100644 --- a/packages/filebrowser-extension/package.json +++ b/packages/filebrowser-extension/package.json @@ -50,7 +50,6 @@ "@jupyterlab/ui-components": "^3.0.0-rc.13", "@lumino/algorithm": "^1.3.3", "@lumino/commands": "^1.12.0", - "@lumino/messaging": "^1.4.3", "@lumino/widgets": "^1.16.1" }, "devDependencies": { diff --git a/packages/filebrowser-extension/src/index.ts b/packages/filebrowser-extension/src/index.ts index 42ccd791d..09056dcef 100644 --- a/packages/filebrowser-extension/src/index.ts +++ b/packages/filebrowser-extension/src/index.ts @@ -61,13 +61,11 @@ import { textEditorIcon } from '@jupyterlab/ui-components'; -import { IIterator, map, reduce, toArray } from '@lumino/algorithm'; +import { map, toArray } from '@lumino/algorithm'; import { CommandRegistry } from '@lumino/commands'; -import { Message } from '@lumino/messaging'; - -import { Menu, TabPanel } from '@lumino/widgets'; +import { TabPanel } from '@lumino/widgets'; /** * The command IDs used by the file browser plugin. @@ -85,9 +83,6 @@ namespace CommandIDs { export const duplicate = 'filebrowser:duplicate'; - // For main browser only. - export const hideBrowser = 'filebrowser:hide-main'; - export const goToPath = 'filebrowser:go-to-path'; export const openPath = 'filebrowser:open-path'; @@ -112,13 +107,8 @@ namespace CommandIDs { // For main browser only. export const copyPath = 'filebrowser:copy-path'; - export const showBrowser = 'filebrowser:activate'; - export const shutdown = 'filebrowser:shutdown'; - // For main browser only. - export const toggleBrowser = 'filebrowser:toggle-main'; - export const toggleNavigateToCurrentDirectory = 'filebrowser:toggle-navigate-to-current-directory'; @@ -386,10 +376,9 @@ function addCommands( commands.addCommand(CommandIDs.goToPath, { execute: async args => { const path = (args.path as string) || ''; - const showBrowser = !(args?.dontShowBrowser ?? false); try { const item = await Private.navigateToPath(path, factory, translator); - if (item.type !== 'directory' && showBrowser) { + if (item.type !== 'directory') { const browserForPath = Private.getBrowserForPath(path, factory); if (browserForPath) { browserForPath.clearSelectedItems(); @@ -403,9 +392,6 @@ function addCommands( } catch (reason) { console.warn(`${CommandIDs.goToPath} failed to go to: ${path}`, reason); } - if (showBrowser) { - return commands.execute(CommandIDs.showBrowser, { path }); - } } }); @@ -655,16 +641,6 @@ function addCommands( label: trans.__('Shut Down Kernel') }); - commands.addCommand(CommandIDs.toggleBrowser, { - execute: () => { - if (browser.isHidden) { - return commands.execute(CommandIDs.showBrowser, void 0); - } - - return commands.execute(CommandIDs.hideBrowser, void 0); - } - }); - commands.addCommand(CommandIDs.toggleNavigateToCurrentDirectory, { label: trans.__('Show Active File in File Browser'), isToggled: () => browser.navigateToCurrentDirectory, @@ -720,77 +696,6 @@ function addCommands( }); } - /** - * A menu widget that dynamically populates with different widget factories - * based on current filebrowser selection. - */ - class OpenWithMenu extends Menu { - protected onBeforeAttach(msg: Message): void { - // clear the current menu items - this.clearItems(); - - // get the widget factories that could be used to open all of the items - // in the current filebrowser selection - const factories = tracker.currentWidget - ? OpenWithMenu._intersection( - map(tracker.currentWidget.selectedItems(), i => { - return OpenWithMenu._getFactories(i); - }) - ) - : undefined; - - if (factories) { - // make new menu items from the widget factories - factories.forEach(factory => { - this.addItem({ - args: { factory: factory }, - command: CommandIDs.open - }); - }); - } - - super.onBeforeAttach(msg); - } - - static _getFactories(item: Contents.IModel): Array { - const factories = registry - .preferredWidgetFactories(item.path) - .map(f => f.name); - const notebookFactory = registry.getWidgetFactory('notebook')?.name; - if ( - notebookFactory && - item.type === 'notebook' && - factories.indexOf(notebookFactory) === -1 - ) { - factories.unshift(notebookFactory); - } - - return factories; - } - - static _intersection(iter: IIterator>): Set | void { - // pop the first element of iter - const first = iter.next(); - // first will be undefined if iter is empty - if (!first) { - return; - } - - // "initialize" the intersection from first - const isect = new Set(first); - // reduce over the remaining elements of iter - return reduce( - iter, - (isect, subarr) => { - // filter out all elements not present in both isect and subarr, - // accumulate result in new set - return new Set(subarr.filter(x => isect.has(x))); - }, - isect - ); - } - } - // matches anywhere on filebrowser const selectorContent = '.jp-DirListing-content'; // matches all filebrowser items @@ -830,15 +735,6 @@ function addCommands( rank: 1 }); - const openWith = new OpenWithMenu({ commands }); - openWith.title.label = trans.__('Open With'); - app.contextMenu.addItem({ - type: 'submenu', - submenu: openWith, - selector: selectorNotDir, - rank: 2 - }); - app.contextMenu.addItem({ command: CommandIDs.openBrowserTab, selector: selectorNotDir, diff --git a/packages/running-extension/package.json b/packages/running-extension/package.json deleted file mode 100644 index af0cf2e3f..000000000 --- a/packages/running-extension/package.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "@jupyterlab-classic/running-extension", - "version": "0.1.0", - "description": "JupyterLab Classic - Running Extension", - "homepage": "https://github.com/jtpio/jupyterlab-classic", - "bugs": { - "url": "https://github.com/jtpio/jupyterlab-classic/issues" - }, - "repository": { - "type": "git", - "url": "https://github.com/jtpio/jupyterlab-classic.git" - }, - "license": "BSD-3-Clause", - "author": "Project Jupyter", - "sideEffects": [ - "style/**/*.css" - ], - "main": "lib/index.js", - "types": "lib/index.d.ts", - "style": "style/index.css", - "directories": { - "lib": "lib/" - }, - "files": [ - "lib/*.d.ts", - "lib/*.js.map", - "lib/*.js", - "schema/*.json", - "style/**/*.css" - ], - "scripts": { - "build": "tsc -b", - "clean": "rimraf lib && rimraf tsconfig.tsbuildinfo", - "docs": "typedoc src", - "prepublishOnly": "npm run build", - "watch": "tsc -b --watch" - }, - "dependencies": { - "@jupyterlab/application": "^3.0.0-rc.12", - "@jupyterlab/running": "^3.0.0-rc.12", - "@jupyterlab/translation": "^3.0.0-rc.12" - }, - "devDependencies": { - "rimraf": "~3.0.0", - "typescript": "~4.0.2" - }, - "publishConfig": { - "access": "public" - }, - "jupyterlab": { - "extension": true - } -} diff --git a/packages/running-extension/src/index.ts b/packages/running-extension/src/index.ts deleted file mode 100644 index 64ff4e3b7..000000000 --- a/packages/running-extension/src/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Jupyter Development Team. -// Distributed under the terms of the Modified BSD License. - -import { - JupyterFrontEnd, - JupyterFrontEndPlugin -} from '@jupyterlab/application'; - -/** - * The default running sessions extension. - */ -const plugin: JupyterFrontEndPlugin = { - id: '@jupyterlab-classic/running-extension:plugin', - autoStart: true, - activate: (app: JupyterFrontEnd): void => { - console.log('nope'); - } -}; - -/** - * Export the plugin as default. - */ -export default plugin; diff --git a/packages/running-extension/style/base.css b/packages/running-extension/style/base.css deleted file mode 100644 index efb564000..000000000 --- a/packages/running-extension/style/base.css +++ /dev/null @@ -1,3 +0,0 @@ -.jp-RunningSessions { - height: 100%; -} diff --git a/packages/running-extension/style/index.css b/packages/running-extension/style/index.css deleted file mode 100644 index 0dfc4ba6c..000000000 --- a/packages/running-extension/style/index.css +++ /dev/null @@ -1,3 +0,0 @@ -@import url('~@jupyterlab/running/style/index.css'); - -@import url('./base.css'); diff --git a/packages/running-extension/tsconfig.json b/packages/running-extension/tsconfig.json deleted file mode 100644 index 399b75b7a..000000000 --- a/packages/running-extension/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfigbase", - "compilerOptions": { - "outDir": "lib", - "rootDir": "src" - }, - "include": ["src/**/*"] -} diff --git a/yarn.lock b/yarn.lock index 976e09306..c07523441 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1806,22 +1806,6 @@ "@lumino/widgets" "^1.16.1" react "^17.0.1" -"@jupyterlab/launcher@^3.0.0-rc.13": - version "3.0.0-rc.13" - resolved "https://registry.yarnpkg.com/@jupyterlab/launcher/-/launcher-3.0.0-rc.13.tgz#f128c1bbb0d23b44ed38a9ff08c4f7f6e8b4b2fd" - integrity sha512-Rh0tELQhHcxEUtsDPaNLA2GLOBFW9U5kXqrGXs8imLyDoxxfgwjugcfab79IltDWX6c6brTHFu6Uei9zaDwdmQ== - dependencies: - "@jupyterlab/apputils" "^3.0.0-rc.13" - "@jupyterlab/translation" "^3.0.0-rc.13" - "@jupyterlab/ui-components" "^3.0.0-rc.13" - "@lumino/algorithm" "^1.3.3" - "@lumino/commands" "^1.12.0" - "@lumino/coreutils" "^1.5.3" - "@lumino/disposable" "^1.4.3" - "@lumino/properties" "^1.2.3" - "@lumino/widgets" "^1.16.1" - react "^17.0.1" - "@jupyterlab/logconsole@^3.0.0-rc.12": version "3.0.0-rc.12" resolved "https://registry.yarnpkg.com/@jupyterlab/logconsole/-/logconsole-3.0.0-rc.12.tgz#cb3b9e48577542bdeeb4221c17218b59909ce5cd" @@ -2164,7 +2148,7 @@ "@lumino/signaling" "^1.4.3" "@lumino/widgets" "^1.16.1" -"@jupyterlab/running@^3.0.0-rc.12", "@jupyterlab/running@^3.0.0-rc.13": +"@jupyterlab/running@^3.0.0-rc.13": version "3.0.0-rc.13" resolved "https://registry.yarnpkg.com/@jupyterlab/running/-/running-3.0.0-rc.13.tgz#df0d732d23d6c0c56a1512bfb0a988b05a8af4df" integrity sha512-852VZ6+H3xSl6DtPBe5VE1NhVprY6xgL9a5EAxeqrTljeC2IbBgt9FjBjYDfBcBkj9kdupuyU8biHbFJKNlSiw== From c3c4867bf633afaa5390b065b74aec50087961f1 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Wed, 9 Dec 2020 11:22:46 +0100 Subject: [PATCH 5/5] Move to tree-extension --- builder/index.js | 11 +++++------ builder/package.json | 2 +- builder/style.css | 2 +- .../package.json | 4 ++-- .../src/index.ts | 4 ++-- .../style/base.css | 0 .../style/index.css | 0 .../tsconfig.json | 0 8 files changed, 11 insertions(+), 12 deletions(-) rename packages/{filebrowser-extension => tree-extension}/package.json (93%) rename packages/{filebrowser-extension => tree-extension}/src/index.ts (99%) rename packages/{filebrowser-extension => tree-extension}/style/base.css (100%) rename packages/{filebrowser-extension => tree-extension}/style/index.css (100%) rename packages/{filebrowser-extension => tree-extension}/tsconfig.json (100%) diff --git a/builder/index.js b/builder/index.js index 5104e529b..9091dfcdb 100644 --- a/builder/index.js +++ b/builder/index.js @@ -106,12 +106,11 @@ async function main() { const page = PageConfig.getOption('classicPage'); if (page === 'tree') { mods = mods.concat([ - require('@jupyterlab-classic/filebrowser-extension').default.filter( - ({ id }) => - [ - '@jupyterlab-classic/filebrowser-extension:browser', - '@jupyterlab-classic/filebrowser-extension:factory' - ].includes(id) + require('@jupyterlab-classic/tree-extension').default.filter(({ id }) => + [ + '@jupyterlab-classic/tree-extension:browser', + '@jupyterlab-classic/tree-extension:factory' + ].includes(id) ), require('@jupyterlab/running-extension') ]); diff --git a/builder/package.json b/builder/package.json index d9a846a88..26c48f00c 100644 --- a/builder/package.json +++ b/builder/package.json @@ -13,8 +13,8 @@ "@jupyterlab-classic/application": "^0.1.0", "@jupyterlab-classic/application-extension": "^0.1.0", "@jupyterlab-classic/docmanager-extension": "^0.1.0", - "@jupyterlab-classic/filebrowser-extension": "^0.1.0", "@jupyterlab-classic/notebook-extension": "^0.1.0", + "@jupyterlab-classic/tree-extension": "^0.1.0", "@jupyterlab-classic/ui-components": "^0.1.0", "@jupyterlab/apputils-extension": "^3.0.0-rc.12", "@jupyterlab/codemirror-extension": "^3.0.0-rc.12", diff --git a/builder/style.css b/builder/style.css index 5783c2793..41f777daa 100644 --- a/builder/style.css +++ b/builder/style.css @@ -1,6 +1,6 @@ @import url('~@jupyterlab-classic/application-extension/style/index.css'); -@import url('~@jupyterlab-classic/filebrowser-extension/style/index.css'); @import url('~@jupyterlab-classic/notebook-extension/style/index.css'); +@import url('~@jupyterlab-classic/tree-extension/style/index.css'); @import url('~@jupyterlab-classic/ui-components/style/index.css'); /* TODO: check is the the extension package can be used directly */ diff --git a/packages/filebrowser-extension/package.json b/packages/tree-extension/package.json similarity index 93% rename from packages/filebrowser-extension/package.json rename to packages/tree-extension/package.json index 8c2ecbf7b..5fb825a2c 100644 --- a/packages/filebrowser-extension/package.json +++ b/packages/tree-extension/package.json @@ -1,7 +1,7 @@ { - "name": "@jupyterlab-classic/filebrowser-extension", + "name": "@jupyterlab-classic/tree-extension", "version": "0.1.0", - "description": "JupyterLab Classic - File browser Extension", + "description": "JupyterLab Classic - Tree Extension", "homepage": "https://github.com/jtpio/jupyterlab-classic", "bugs": { "url": "https://github.com/jtpio/jupyterlab-classic/issues" diff --git a/packages/filebrowser-extension/src/index.ts b/packages/tree-extension/src/index.ts similarity index 99% rename from packages/filebrowser-extension/src/index.ts rename to packages/tree-extension/src/index.ts index 09056dcef..4fc441e56 100644 --- a/packages/filebrowser-extension/src/index.ts +++ b/packages/tree-extension/src/index.ts @@ -122,7 +122,7 @@ namespace CommandIDs { */ const browser: JupyterFrontEndPlugin = { activate: activateBrowser, - id: '@jupyterlab-classic/filebrowser-extension:browser', + id: '@jupyterlab-classic/tree-extension:browser', requires: [ IFileBrowserFactory, IDocumentManager, @@ -146,7 +146,7 @@ const browser: JupyterFrontEndPlugin = { */ const factory: JupyterFrontEndPlugin = { activate: activateFactory, - id: '@jupyterlab-classic/filebrowser-extension:factory', + id: '@jupyterlab-classic/tree-extension:factory', provides: IFileBrowserFactory, requires: [IDocumentManager, ITranslator], optional: [IStateDB, IRouter, JupyterFrontEnd.ITreeResolver] diff --git a/packages/filebrowser-extension/style/base.css b/packages/tree-extension/style/base.css similarity index 100% rename from packages/filebrowser-extension/style/base.css rename to packages/tree-extension/style/base.css diff --git a/packages/filebrowser-extension/style/index.css b/packages/tree-extension/style/index.css similarity index 100% rename from packages/filebrowser-extension/style/index.css rename to packages/tree-extension/style/index.css diff --git a/packages/filebrowser-extension/tsconfig.json b/packages/tree-extension/tsconfig.json similarity index 100% rename from packages/filebrowser-extension/tsconfig.json rename to packages/tree-extension/tsconfig.json