Skip to content

Commit

Permalink
history対応
Browse files Browse the repository at this point in the history
  • Loading branch information
wraith13 committed Mar 2, 2017
1 parent 2a9a105 commit a980583
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -272,6 +274,11 @@
"menuSeparator": "─────────────────────────────────────────────"
},
"description": "set emoji"
},
"wandbox.maxHistorySize": {
"type": "integer",
"default": 256,
"description": "set max share history size"
}
}
},
Expand Down Expand Up @@ -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",
Expand Down
73 changes: 72 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ module fx
module WandboxVSCode
{
const extentionName = "wandbox-vscode";
let context: vscode.ExtensionContext;
var fileSetting = { };
var pass_through;

Expand All @@ -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<HistoryEntry[]>
{
return await context.globalState.get<HistoryEntry[]>("history", []);
}
async function updateHistory(history : HistoryEntry[]) : Promise<void>
{
await context.globalState.update("history", history);
}

function emoji(key : string) : string
{
var result : string = getConfiguration("emoji")[key];
Expand Down Expand Up @@ -302,6 +320,29 @@ module WandboxVSCode
return json;
}

async function appendHistory(compiler : string, shareUrl : string) : Promise<void>
{
let history = await getHistory();
let maxHistorySize = Math.max(0, getConfiguration<number>("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<void>
{
var requestUrl = getUrl() +`/api/compile.json`;
Expand Down Expand Up @@ -372,6 +413,7 @@ module WandboxVSCode
vscode.Uri.parse(body.url)
);
}
await appendHistory(json['compiler'], body.url);
}

}
Expand Down Expand Up @@ -658,6 +700,26 @@ module WandboxVSCode
);
}

async function showHistory() : Promise<void>
{
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<void>
{
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<string>) : Promise<void>
{
var document = WorkSpace.getActiveDocument();
Expand Down Expand Up @@ -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',
Expand All @@ -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
Expand Down

0 comments on commit a980583

Please sign in to comment.