Skip to content

Commit

Permalink
Add supports for custom explorer viewlet
Browse files Browse the repository at this point in the history
  • Loading branch information
spywhere committed Sep 20, 2017
1 parent 1d22cca commit 7645927
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 13 deletions.
12 changes: 12 additions & 0 deletions images/octicons/dark/book.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions images/octicons/dark/list-unordered.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions images/octicons/dark/pencil.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions images/octicons/light/book.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions images/octicons/light/list-unordered.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions images/octicons/light/pencil.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions package.json
Expand Up @@ -2,7 +2,7 @@
"name": "mark-jump",
"displayName": "Mark Jump",
"description": "Jump to the marked section in the code",
"version": "0.6.0",
"version": "0.7.0",
"publisher": "spywhere",
"icon": "images/icon.png",
"bugs": {
Expand All @@ -21,7 +21,7 @@
"url": "https://github.com/spywhere/vscode-mark-jump.git"
},
"engines": {
"vscode": "^1.12.0"
"vscode": "^1.13.0"
},
"categories": [
"Other"
Expand All @@ -31,6 +31,15 @@
],
"main": "./out/extension",
"contributes": {
"views": {
"explorer": [
{
"id": "markJump",
"name": "Mark Jump",
"when": "config.markJump.showExplorerView == true"
}
]
},
"commands": [
{
"command": "markJump.jumpToProjectMark",
Expand Down Expand Up @@ -194,6 +203,11 @@
"type": "boolean",
"default": true,
"description": "Show numbers of marks in the status bar."
},
"markJump.showExplorerView": {
"type": "boolean",
"default": true,
"description": "Show marks in the explorer viewlet."
}
}
}
Expand Down
79 changes: 69 additions & 10 deletions src/extension.ts
Expand Up @@ -7,6 +7,9 @@ import * as path from "path";
export function activate(context: vscode.ExtensionContext) {
let markJump = new MarkJump();
context.subscriptions.push(markJump);
context.subscriptions.push(vscode.window.registerTreeDataProvider(
"markJump", new MarkJumpTreeProvider(markJump, context)
));
context.subscriptions.push(new MarkJumpController(markJump));
}

Expand Down Expand Up @@ -75,6 +78,11 @@ class MarkJumpController {
}
));
});
subscriptions.push(vscode.commands.registerCommand(
"markJump.revealMark", (mark: BaseMarkItem) => {
this.markJump.openAndRevealMark(mark);
}
));
this.markJump.createStatusBar();
vscode.workspace.onDidOpenTextDocument(document => {
this.markJump.updateStatusBar(false);
Expand Down Expand Up @@ -113,6 +121,53 @@ class MarkJumpController {
}
}

class MarkJumpTreeProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
private markJump: MarkJump;
private context: vscode.ExtensionContext;

constructor(markJump: MarkJump, context: vscode.ExtensionContext){
this.markJump = markJump;
this.context = context;
}

getTreeItem(element: vscode.TreeItem){
return element;
}

getChildren(element?: vscode.TreeItem) {
return this.markJump.getMarks(
vscode.window.activeTextEditor, undefined, true
).then(marks => {
return marks.map<vscode.TreeItem>(mark => {
let type = "";
if (mark.type === "note") {
type = "book";
} else if (mark.type === "todo") {
type = "pencil";
} else if (mark.type === "section") {
type = "list-unordered";
}
return {
command: {
title: "Reveal",
command: "markJump.revealMark",
arguments: [mark]
},
label: `${ mark.description }`,
iconPath: {
light: this.context.asAbsolutePath(
`./images/octicons/light/${ type }.svg`
),
dark: this.context.asAbsolutePath(
`./images/octicons/dark/${ type }.svg`
)
}
}
});
});
}
}

interface BaseMarkItem {
range: vscode.Range;
uri: vscode.Uri;
Expand Down Expand Up @@ -436,16 +491,7 @@ class MarkJump {
);
}
if(!editor){
if(!mark){
return;
}
vscode.workspace.openTextDocument(
mark.uri
).then(document => {
return vscode.window.showTextDocument(document);
}).then(editor => {
this.revealMark(editor, mark);
});
this.openAndRevealMark(mark);
return;
}

Expand All @@ -456,6 +502,19 @@ class MarkJump {
});
}

openAndRevealMark(mark: BaseMarkItem){
let editor = vscode.window.visibleTextEditors.find((editor) => (
editor.document.uri.toString() === mark.uri.toString()
));
(
editor ?
Promise.resolve(editor.document) :
vscode.workspace.openTextDocument(mark.uri)
).then((document) => vscode.window.showTextDocument(document, {
preview: false
})).then((editor) => this.revealMark(editor, mark));
}

revealMark(
editor: vscode.TextEditor,
mark?: BaseMarkItem
Expand Down

0 comments on commit 7645927

Please sign in to comment.