From 1513ed576615f2990a00f84006ab23ecb304f311 Mon Sep 17 00:00:00 2001 From: EvieePy Date: Fri, 15 Dec 2023 10:58:21 +1000 Subject: [PATCH] Add file context menus. --- CHANGELOG.md | 12 ++++++++++-- README.md | 12 +++++++++--- package.json | 8 +++++++- src/upload.ts | 7 +++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aea193..0e40be5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,20 @@ # Change Log +## [0.0.3] - 2023-12-15 + +### Added + +- Editor Context Menu. + - Right click to upload a file or selection(s). (Max Size of 30_000 bytes per selection && Max Selections of 5) + + ## [0.0.2] - 2023-10-25 ### Added -- Explorer Right Click Menu. - - Right Click to upload a files contents. (Max Size of 30_000 bytes.) +- Explorer Context Menu. + - Right Click a file in the explorer to upload its contents. (Max Size of 30_000 bytes.) ### Fiexed - Filename parsing was inaccurate. Added a parser for better results. diff --git a/README.md b/README.md index cd58d38..ea9517a 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ ## Features - Paste full files or text of any language to MystBin with ``>Share`` (`mystbin.share`). +- Editor and Explorer Context Menus for ease of use. Right Click to send to MystBin. - Select up to **5** snippets in an open editor and send them to MystBin as separate files. - Automatically copies the paste URL and has a button to open it in your browser. @@ -13,7 +14,6 @@ ## Planned - Editor Icon/Button for quickly saving a workspace or file. -- Context Menus for quickly pasting files from the explorer or selected text in an editor. - Fetch and edit existing MystBin pastes via ID or URL. - Ability to provide your API token for saving pastes to your account. @@ -26,10 +26,16 @@ ## Release Notes +### 0.0.3 + +- Added: Editor Context Menu. + - Right click to upload a file or selection(s). (Max Size of 30_000 bytes per selection && Max Selections of 5) + + ### 0.0.2 -- Added: Explorer Right Click Menu. - - Right Click to upload a files contents. (Max Size of 30_000 bytes.) +- Added: Explorer Context Menu. + - Right Click a file in the explorer to upload its contents. (Max Size of 30_000 bytes.) - Fixed: Filename parsing was inaccurate. Added a parser for better results. diff --git a/package.json b/package.json index fb76759..80250d6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "mystbin", "displayName": "MystBin", "description": "Easily share text and code with mystb.in", - "version": "0.0.2", + "version": "0.0.3", "license": "SEE LICENSE IN LICENSE", "publisher": "PythonistaGuild", "author": { @@ -41,6 +41,12 @@ "command": "mystbin.share", "when": "resourceScheme == file" } + ], + "editor/context": [ + { + "command": "mystbin.share", + "when": "editorHasSelection || editorFocus" + } ] } }, diff --git a/src/upload.ts b/src/upload.ts index 5d4aa63..9630c06 100644 --- a/src/upload.ts +++ b/src/upload.ts @@ -36,11 +36,10 @@ interface PasteContent { export async function singleEditorUpload(menuResource: vscode.Uri | undefined = undefined) { + let activeEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor; let highlighted: FileSelection[]; if (!menuResource) { - let activeEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor; - if (!activeEditor) { vscode.window.showErrorMessage("Please open a file and re-run this command to upload to MystBin. Or Right Click a File in your explorer."); return; @@ -49,6 +48,10 @@ export async function singleEditorUpload(menuResource: vscode.Uri | undefined = highlighted = getEditorSelections(activeEditor); } + else if (menuResource.path === activeEditor?.document.uri.path) { + highlighted = getEditorSelections(activeEditor); + } + else { let fileBytes: Uint8Array = await vscode.workspace.fs.readFile(menuResource); if (fileBytes.length > MAX_SIZE) {