diff --git a/README.md b/README.md index 9393f43..e34dc83 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,11 @@ Bash script, C, C#, C++, CoffeeScript, CPP, D, Elixir, Erlang, Groovy, Haskell, * `Wandbox: Show Web Site` : open wandbox web site * `Wandbox: Show Settings` : show all wandbox-vscode settings +* `Wandbox: Show History` : show share history + +## Clear Commands + +* `Wandbox: Clear History` : clear share history ## Setting Commands @@ -81,6 +86,7 @@ This extension contributes the following settings: * `wandbox.runtimeOptionRaw`: set raw runtime option by compiler * `wandbox.helloWolrdFiles`: set hello world files * `wandbox.emoji`: set emoji +* `wandbox.maxHistorySize`: set max share history size > You can set following if your environment's font is poor. >```json diff --git a/package.json b/package.json index 7ac4074..3531645 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,8 @@ "onCommand:extension.showWandboxListJson", "onCommand:extension.showWandboxWeb", "onCommand:extension.showWandboxSettings", + "onCommand:extension.showHistory", + "onCommand:extension.clearHistory", "onCommand:extension.setWandboxFileServer", "onCommand:extension.setWandboxFileCompiler", "onCommand:extension.setWandboxFileOptions", @@ -272,6 +274,11 @@ "menuSeparator": "─────────────────────────────────────────────" }, "description": "set emoji" + }, + "wandbox.maxHistorySize": { + "type": "integer", + "default": 256, + "description": "set max share history size" } } }, @@ -306,6 +313,16 @@ "title": "Show Settings", "category": "Wandbox" }, + { + "command": "extension.showHistory", + "title": "Show History", + "category": "Wandbox" + }, + { + "command": "extension.clearHistory", + "title": "Clear History", + "category": "Wandbox" + }, { "command": "extension.setWandboxFileServer", "title": "Set Server", diff --git a/src/extension.ts b/src/extension.ts index 762eeda..b45be49 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -97,6 +97,7 @@ module fx module WandboxVSCode { const extentionName = "wandbox-vscode"; + let context: vscode.ExtensionContext; var fileSetting = { }; var pass_through; @@ -115,6 +116,23 @@ module WandboxVSCode configuration; } + class HistoryEntry + { + public timestamp : Date; + public language : string; + public compiler : string; + public shareUrl : string; + } + + async function getHistory() : Promise + { + return await context.globalState.get("history", []); + } + async function updateHistory(history : HistoryEntry[]) : Promise + { + await context.globalState.update("history", history); + } + function emoji(key : string) : string { var result : string = getConfiguration("emoji")[key]; @@ -302,6 +320,29 @@ module WandboxVSCode return json; } + async function appendHistory(compiler : string, shareUrl : string) : Promise + { + let history = await getHistory(); + let maxHistorySize = Math.max(0, getConfiguration("maxHistorySize")); + if (maxHistorySize || history.length) + { + history.push + ( + { + timestamp: new Date(), + language: (await makeSureList()).find(i => i.name === compiler).language, + compiler, + shareUrl, + } + ); + while(maxHistorySize < history.length) + { + history.shift(); + } + await updateHistory(history); + } + } + export async function compile(json : { }) : Promise { var requestUrl = getUrl() +`/api/compile.json`; @@ -372,6 +413,7 @@ module WandboxVSCode vscode.Uri.parse(body.url) ); } + await appendHistory(json['compiler'], body.url); } } @@ -658,6 +700,26 @@ module WandboxVSCode ); } + async function showHistory() : Promise + { + let history = await getHistory(); + history.forEach(entry => OutputChannel.appendLine(`${entry.timestamp}\t${entry.shareUrl}\t${entry.language}\t${entry.compiler}\t`)) + OutputChannel.appendLine(`${history.length} share urls`); + } + + async function clearHistory() : Promise + { + if ("Yes" === await vscode.window.showWarningMessage("Are you sure to clear share history?", "Yes")) + { + updateHistory([]); + OutputChannel.appendLine(`Cleared share history.`); + } + else + { + OutputChannel.canceled(); + } + } + async function setSetting(name : string, dialog : () => Promise) : Promise { var document = WorkSpace.getActiveDocument(); @@ -1411,8 +1473,9 @@ module WandboxVSCode } } - export function registerCommand(context: vscode.ExtensionContext) : void + export function registerCommand(aContext: vscode.ExtensionContext) : void { + context = aContext; [ { command: 'extension.showWandboxSettings', @@ -1426,6 +1489,14 @@ module WandboxVSCode command: 'extension.showWandboxListJson', callback: showWandboxListJson }, + { + command: 'extension.showHistory', + callback: showHistory + }, + { + command: 'extension.clearHistory', + callback: clearHistory + }, { command: 'extension.setWandboxFileServer', callback: setServerSetting