Skip to content

Commit 7b14191

Browse files
committed
feat: sidebar entry.
1 parent 48e4942 commit 7b14191

File tree

7 files changed

+157
-16
lines changed

7 files changed

+157
-16
lines changed

package.json

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
],
1212
"activationEvents": [
1313
"onCommand:catCoding.show",
14-
"onWebviewPanel:catCoding"
14+
"onWebviewPanel:catCoding",
15+
"onView:treeviewSample"
1516
],
1617
"repository": {
1718
"type": "git",
@@ -25,7 +26,26 @@
2526
"title": "Start cat coding session",
2627
"category": "Cat Coding"
2728
}
28-
]
29+
],
30+
"viewsContainers": {
31+
"activitybar": [
32+
{
33+
"id": "treeview-sample",
34+
"title": "Treeview Sample",
35+
"icon": "src/coding.svg"
36+
}
37+
]
38+
},
39+
"views": {
40+
"treeview-sample": [
41+
{
42+
"id": "treeviewSample",
43+
"name": "Treeview Sample",
44+
"icon": "src/coding.svg",
45+
"contextualTitle": "List"
46+
}
47+
]
48+
}
2949
},
3050
"scripts": {
3151
"vscode:prepublish": "npm run compile",
@@ -38,6 +58,7 @@
3858
"lint": "eslint . --ext .ts,.tsx"
3959
},
4060
"dependencies": {
61+
"got": "^11.7.0",
4162
"react": "^16.14.0",
4263
"react-dom": "^16.14.0"
4364
},

src/coding.svg

Lines changed: 1 addition & 0 deletions
Loading

src/extension.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
import * as vscode from 'vscode';
22
import * as path from 'path';
33

4+
import { ListProvider } from './tree';
5+
46
export function activate(context: vscode.ExtensionContext) {
57
context.subscriptions.push(
68
vscode.commands.registerCommand('catCoding.show', () => {
79
CatCodingPanel.createOrShow(context);
810
})
9-
);
11+
);
12+
13+
context.subscriptions.push(
14+
vscode.commands.registerCommand('catCoding.openConvertPage', k => {
15+
CatCodingPanel.createOrShow(context);
16+
// CatCodingPanel.currentPanel?.webview.postMessage()
17+
})
18+
);
19+
20+
vscode.window.registerTreeDataProvider(
21+
`treeviewSample`,
22+
new ListProvider(``)
23+
);
1024

1125
if (vscode.window.registerWebviewPanelSerializer) {
1226
// Make sure we register a serializer in activation event
1327
vscode.window.registerWebviewPanelSerializer(CatCodingPanel.viewType, {
1428
async deserializeWebviewPanel(webviewPanel: vscode.WebviewPanel, state: any) {
15-
console.log(`Got state: ${state}`);
1629
CatCodingPanel.revive(webviewPanel, context.extensionUri, context.extensionPath);
1730
}
1831
});
@@ -170,7 +183,10 @@ class CatCodingPanel {
170183
style-src vscode-resource: 'unsafe-inline';">
171184
172185
<script>
173-
window.acquireVsCodeApi = acquireVsCodeApi;
186+
window.addEventListener('message', event => {
187+
const message = event.data; // The JSON data our extension sent
188+
console.log(message);
189+
});
174190
</script>
175191
</head>
176192
<body>
@@ -181,12 +197,3 @@ class CatCodingPanel {
181197
</html>`;
182198
}
183199
}
184-
185-
function getNonce() {
186-
let text = '';
187-
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
188-
for (let i = 0; i < 32; i++) {
189-
text += possible.charAt(Math.floor(Math.random() * possible.length));
190-
}
191-
return text;
192-
}

src/star.dark.svg

Lines changed: 1 addition & 0 deletions
Loading

src/star.light.svg

Lines changed: 1 addition & 0 deletions
Loading

src/tree.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as vscode from 'vscode';
2+
import * as path from 'path';
3+
import got from 'got';
4+
5+
export class ListProvider implements vscode.TreeDataProvider<ListItem> {
6+
constructor(private workspaceRoot: string) { }
7+
8+
getTreeItem(element: ListItem): vscode.TreeItem {
9+
return element;
10+
}
11+
12+
getChildren(element?: ListItem): Thenable<ListItem[]> {
13+
if (element) {
14+
return Promise.resolve([]);
15+
}
16+
17+
return got(`https://api.frankfurter.app/currencies`, { responseType: 'json' })
18+
.then(({ body }) => {
19+
return Object.entries(body as object).map(([k, v]) => {
20+
return new ListItem(k, v, vscode.TreeItemCollapsibleState.None, {
21+
command: 'catCoding.openConvertPage',
22+
title: `${k}: ${v}`,
23+
arguments: [k],
24+
})
25+
})
26+
})
27+
.catch(err => {
28+
console.error(err);
29+
vscode.window.showErrorMessage(`Fetch currency list failed.`);
30+
return [];
31+
});
32+
}
33+
}
34+
35+
export class ListItem extends vscode.TreeItem {
36+
contextValue = `listItem`;
37+
38+
iconPath = {
39+
light: path.join(__filename, '..', '..', 'src', 'star.light.svg'),
40+
dark: path.join(__filename, '..', '..', 'src', 'star.dark.svg'),
41+
}
42+
43+
constructor(
44+
public readonly label: string,
45+
public readonly value: string,
46+
public readonly collapsibleState: vscode.TreeItemCollapsibleState,
47+
public readonly command?: vscode.Command
48+
) {
49+
super(label, collapsibleState);
50+
51+
this.value = value;
52+
}
53+
}

yarn.lock

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,12 @@
916916
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-2.1.1.tgz#ceff6a28a5b4867c2dd4a1ba513de278ccbe8bb1"
917917
integrity sha512-/aPsuoj/1Dw/kzhkgz+ES6TxG0zfTMGLwuK2ZG00k/iJzYHTLCE8mVU8EPqEOp/lmxPoq1C1C9RYToRKb2KEfg==
918918

919-
"@szmarczak/http-timer@^4.0.0":
919+
"@sindresorhus/is@^3.1.1":
920+
version "3.1.2"
921+
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-3.1.2.tgz#548650de521b344e3781fbdb0ece4aa6f729afb8"
922+
integrity sha512-JiX9vxoKMmu8Y3Zr2RVathBL1Cdu4Nt4MuNWemt1Nc06A0RAin9c5FArkhGsyMBWfCu4zj+9b+GxtjAnE4qqLQ==
923+
924+
"@szmarczak/http-timer@^4.0.0", "@szmarczak/http-timer@^4.0.5":
920925
version "4.0.5"
921926
resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-4.0.5.tgz#bfbd50211e9dfa51ba07da58a14cdfd333205152"
922927
integrity sha512-PyRA9sm1Yayuj5OIoJ1hGt2YISX45w9WcFbh6ddT0Z/0yaFxOtGLInr4jUfU1EAFVs0Yfyfev4RNwBlUaHdlDQ==
@@ -998,7 +1003,7 @@
9981003
"@types/prop-types" "*"
9991004
csstype "^3.0.2"
10001005

1001-
"@types/responselike@*":
1006+
"@types/responselike@*", "@types/responselike@^1.0.0":
10021007
version "1.0.0"
10031008
resolved "https://registry.yarnpkg.com/@types/responselike/-/responselike-1.0.0.tgz#251f4fe7d154d2bad125abe1b429b23afd262e29"
10041009
integrity sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==
@@ -1802,6 +1807,11 @@ cacheable-lookup@^2.0.0:
18021807
"@types/keyv" "^3.1.1"
18031808
keyv "^4.0.0"
18041809

1810+
cacheable-lookup@^5.0.3:
1811+
version "5.0.3"
1812+
resolved "https://registry.yarnpkg.com/cacheable-lookup/-/cacheable-lookup-5.0.3.tgz#049fdc59dffdd4fc285e8f4f82936591bd59fec3"
1813+
integrity sha512-W+JBqF9SWe18A72XFzN/V/CULFzPm7sBXzzR6ekkE+3tLG72wFZrBiBZhrZuDoYexop4PHJVdFAKb/Nj9+tm9w==
1814+
18051815
cacheable-request@^7.0.1:
18061816
version "7.0.1"
18071817
resolved "https://registry.yarnpkg.com/cacheable-request/-/cacheable-request-7.0.1.tgz#062031c2856232782ed694a257fa35da93942a58"
@@ -2301,6 +2311,13 @@ decompress-response@^5.0.0:
23012311
dependencies:
23022312
mimic-response "^2.0.0"
23032313

2314+
decompress-response@^6.0.0:
2315+
version "6.0.0"
2316+
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-6.0.0.tgz#ca387612ddb7e104bd16d85aab00d5ecf09c66fc"
2317+
integrity sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==
2318+
dependencies:
2319+
mimic-response "^3.1.0"
2320+
23042321
deep-extend@^0.6.0, deep-extend@~0.6.0:
23052322
version "0.6.0"
23062323
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac"
@@ -3216,6 +3233,23 @@ got@^10.7.0:
32163233
to-readable-stream "^2.0.0"
32173234
type-fest "^0.10.0"
32183235

3236+
got@^11.7.0:
3237+
version "11.7.0"
3238+
resolved "https://registry.yarnpkg.com/got/-/got-11.7.0.tgz#a386360305571a74548872e674932b4ef70d3b24"
3239+
integrity sha512-7en2XwH2MEqOsrK0xaKhbWibBoZqy+f1RSUoIeF1BLcnf+pyQdDsljWMfmOh+QKJwuvDIiKx38GtPh5wFdGGjg==
3240+
dependencies:
3241+
"@sindresorhus/is" "^3.1.1"
3242+
"@szmarczak/http-timer" "^4.0.5"
3243+
"@types/cacheable-request" "^6.0.1"
3244+
"@types/responselike" "^1.0.0"
3245+
cacheable-lookup "^5.0.3"
3246+
cacheable-request "^7.0.1"
3247+
decompress-response "^6.0.0"
3248+
http2-wrapper "^1.0.0-beta.5.2"
3249+
lowercase-keys "^2.0.0"
3250+
p-cancelable "^2.0.0"
3251+
responselike "^2.0.0"
3252+
32193253
got@^6.2.0:
32203254
version "6.7.1"
32213255
resolved "https://registry.yarnpkg.com/got/-/got-6.7.1.tgz#240cd05785a9a18e561dc1b44b41c763ef1e8db0"
@@ -3363,6 +3397,14 @@ http-signature@~1.2.0:
33633397
jsprim "^1.2.2"
33643398
sshpk "^1.7.0"
33653399

3400+
http2-wrapper@^1.0.0-beta.5.2:
3401+
version "1.0.0-beta.5.2"
3402+
resolved "https://registry.yarnpkg.com/http2-wrapper/-/http2-wrapper-1.0.0-beta.5.2.tgz#8b923deb90144aea65cf834b016a340fc98556f3"
3403+
integrity sha512-xYz9goEyBnC8XwXDTuC/MZ6t+MrKVQZOk4s7+PaDkwIsQd8IwqvM+0M6bA/2lvG8GHXcPdf+MejTUeO2LCPCeQ==
3404+
dependencies:
3405+
quick-lru "^5.1.1"
3406+
resolve-alpn "^1.0.0"
3407+
33663408
https-browserify@^1.0.0:
33673409
version "1.0.0"
33683410
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
@@ -4198,6 +4240,11 @@ mimic-response@^2.0.0, mimic-response@^2.1.0:
41984240
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-2.1.0.tgz#d13763d35f613d09ec37ebb30bac0469c0ee8f43"
41994241
integrity sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==
42004242

4243+
mimic-response@^3.1.0:
4244+
version "3.1.0"
4245+
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-3.1.0.tgz#2d1d59af9c1b129815accc2c46a022a5ce1fa3c9"
4246+
integrity sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==
4247+
42014248
minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1:
42024249
version "1.0.1"
42034250
resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7"
@@ -4960,6 +5007,11 @@ [email protected]:
49605007
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
49615008
integrity sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=
49625009

5010+
quick-lru@^5.1.1:
5011+
version "5.1.1"
5012+
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-5.1.1.tgz#366493e6b3e42a3a6885e2e99d18f80fb7a8c932"
5013+
integrity sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==
5014+
49635015
randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5, randombytes@^2.1.0:
49645016
version "2.1.0"
49655017
resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a"
@@ -5208,6 +5260,11 @@ request@^2.88.0:
52085260
tunnel-agent "^0.6.0"
52095261
uuid "^3.3.2"
52105262

5263+
resolve-alpn@^1.0.0:
5264+
version "1.0.0"
5265+
resolved "https://registry.yarnpkg.com/resolve-alpn/-/resolve-alpn-1.0.0.tgz#745ad60b3d6aff4b4a48e01b8c0bdc70959e0e8c"
5266+
integrity sha512-rTuiIEqFmGxne4IovivKSDzld2lWW9QCjqv80SYjPgf+gS35eaCAjaP54CCwGAwBtnCsvNLYtqxe1Nw+i6JEmA==
5267+
52115268
resolve-cwd@^3.0.0:
52125269
version "3.0.0"
52135270
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-3.0.0.tgz#0f0075f1bb2544766cf73ba6a6e2adfebcb13f2d"

0 commit comments

Comments
 (0)