From 1d7046b921712c42e06961fbd79cd5264399a5f7 Mon Sep 17 00:00:00 2001 From: ciusji Date: Tue, 3 May 2022 11:41:35 +0800 Subject: [PATCH] Feature: add terminal to `context-menu` --- packages/application-extension/src/index.tsx | 2 +- .../filebrowser-extension/schema/browser.json | 5 ++++ packages/filebrowser-extension/src/index.ts | 27 +++++++++++++++++-- packages/notebook-extension/src/index.ts | 1 - 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/application-extension/src/index.tsx b/packages/application-extension/src/index.tsx index 1db32df..17bcd57 100644 --- a/packages/application-extension/src/index.tsx +++ b/packages/application-extension/src/index.tsx @@ -336,7 +336,7 @@ const mainCommands: JupyterFrontEndPlugin = { } }); - // Fixme by Bingqi_Ji + // Fixme by cius // commands.addCommand(CommandIDs.toggleMode, { // label: trans.__('Simple Interface'), // isToggled: () => labShell.mode === 'single-document', diff --git a/packages/filebrowser-extension/schema/browser.json b/packages/filebrowser-extension/schema/browser.json index 6947106..3aa2b0d 100644 --- a/packages/filebrowser-extension/schema/browser.json +++ b/packages/filebrowser-extension/schema/browser.json @@ -82,6 +82,11 @@ "selector": ".jp-DirListing-content", "rank": 4 }, + { + "command": "filebrowser:create-main-terminal", + "selector": ".jp-DirListing-content", + "rank": 4 + }, { "type": "separator", "selector": ".jp-DirListing-item[data-isdir]", diff --git a/packages/filebrowser-extension/src/index.ts b/packages/filebrowser-extension/src/index.ts index f96c50d..1242ab6 100644 --- a/packages/filebrowser-extension/src/index.ts +++ b/packages/filebrowser-extension/src/index.ts @@ -29,7 +29,7 @@ import { FileBrowser, FileUploadStatus, FilterFileBrowserModel, - IFileBrowserFactory + IFileBrowserFactory, } from '@jupyterlab/filebrowser'; import { Launcher } from '@jupyterlab/launcher'; import { Contents } from '@jupyterlab/services'; @@ -51,11 +51,13 @@ import { newFolderIcon, pasteIcon, stopIcon, + terminalIcon, textEditorIcon } from '@jupyterlab/ui-components'; import { find, IIterator, map, reduce, toArray } from '@lumino/algorithm'; import { CommandRegistry } from '@lumino/commands'; import { ContextMenu } from '@lumino/widgets'; +import { Terminal } from "@jupyterlab/terminal"; /** * The command IDs used by the file browser plugin. @@ -68,6 +70,8 @@ namespace CommandIDs { // For main browser only. export const createLauncher = 'filebrowser:create-main-launcher'; + export const createTerminal = 'filebrowser:create-main-terminal'; + export const cut = 'filebrowser:cut'; export const del = 'filebrowser:delete'; @@ -1027,6 +1031,12 @@ function addCommands( label: trans.__('New Text File') }); + commands.addCommand(CommandIDs.createTerminal, { + execute: () => Private.createTerminal(commands, browser), + icon: terminalIcon.bindprops({ stylesheet: 'menuItem' }), + label: trans.__('New Terminal') + }); + commands.addCommand(CommandIDs.createNewMarkdownFile, { execute: () => { const widget = tracker.currentWidget; @@ -1186,6 +1196,19 @@ namespace Private { }); } + export function createTerminal( + commands: CommandRegistry, + browser: FileBrowser + ): Promise> { + const { model } = browser; + + return commands + .execute('terminal:create-new', { cwd: model.path }) + .then((terminal: MainAreaWidget) => { + return terminal; + }); + } + /** * Get browser object given file path. */ @@ -1299,7 +1322,7 @@ namespace Private { const plugins: JupyterFrontEndPlugin[] = [ factory, browser, - // shareFile, + shareFile, fileUploadStatus, // downloadPlugin, browserWidget, diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index 3cd0697..f21fd5f 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -1421,7 +1421,6 @@ function activateNotebookHandler( '' ); } - console.log(args); if (args['isContextMenu']) { return trans.__('New Notebook'); }