Skip to content

Commit

Permalink
Adding support for the notebook editor
Browse files Browse the repository at this point in the history
  • Loading branch information
lostintangent authored Nov 20, 2021
1 parent e448414 commit 3a0ac31
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.4.0 (11/20/21)

- Added `Copy File to Gist` command to the notebook editor toolbar
- Changed the `Showcase` view to be hidden by default

## v0.3.0 (07/06/21)

- Fixed a bug with updating notebook files
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "GistPad",
"description": "Manage your code snippets and developer notes using GitHub Gists and repositories.",
"publisher": "vsls-contrib",
"version": "0.3.0",
"version": "0.4.0",
"extensionKind": [
"ui",
"workspace"
Expand Down Expand Up @@ -127,7 +127,8 @@
},
{
"command": "gistpad.addFileToGist",
"title": "Copy File to Gist"
"title": "Copy File to Gist",
"icon": "$(github)"
},
{
"command": "gistpad.addGistComment",
Expand Down Expand Up @@ -1407,6 +1408,11 @@
"group": "inline",
"when": "commentController == gistpad:repo && commentThreadIsEmpty && gistpad:state == SignedIn"
}
],
"notebook/toolbar": [
{
"command": "gistpad.addFileToGist"
}
]
},
"viewsContainers": {
Expand All @@ -1431,7 +1437,7 @@
{
"id": "gistpad.showcase",
"name": "Showcase",
"visibility": "collapsed",
"visibility": "hidden",
"when": "gistpad:state == SignedIn"
}
]
Expand Down
13 changes: 10 additions & 3 deletions src/commands/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,16 @@ export async function promptForGistSelection(files: GistFile[]) {
}

export function registerEditorCommands(context: ExtensionContext) {
// This command can be called from four different contexts:
// 1) Right-clicking a file in the "Explorer" tree (Uri)
// 2) Right-clicking the editor tab of a file (Uri)
// 3) Right-clicking a file in the "Gists" tree (GistFileNode)
// 4) From the toolbar of the notebook editor
context.subscriptions.push(
commands.registerCommand(
`${EXTENSION_NAME}.addFileToGist`,
async (
targetNode: GistFileNode | Uri,
targetNode: GistFileNode | Uri | { notebookEditor: { notebookUri: Uri }},
multiSelectNodes?: GistFileNode[] | Uri[]
) => {
await ensureAuthenticated();
Expand All @@ -124,12 +129,14 @@ export function registerEditorCommands(context: ExtensionContext) {
)
});
} else {
const uri = node instanceof Uri ? node : node.notebookEditor.notebookUri;

// The command is being called as a response to
// right-clicking a file node in the explorer
// and/or right-clicking the editor tab
files.push({
filename: path.basename(node.path),
content: byteArrayToString(await workspace.fs.readFile(node))
filename: path.basename(uri.path),
content: byteArrayToString(await workspace.fs.readFile(uri))
});
}
}
Expand Down

0 comments on commit 3a0ac31

Please sign in to comment.