Skip to content

Commit b295150

Browse files
committed
Separate the "Websites" context from the main workspace view into its own dedicated Activity Bar panel
1 parent b839975 commit b295150

4 files changed

Lines changed: 106 additions & 144 deletions

File tree

‎packages/vscode/package.json‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@
7676
"name": "Context",
7777
"icon": "resources/activity-bar-icon.svg"
7878
},
79+
{
80+
"id": "codeWebChatViewWebsites",
81+
"name": "Websites",
82+
"icon": "resources/activity-bar-icon.svg",
83+
"visibility": "collapsed"
84+
},
7985
{
8086
"id": "codeWebChatView",
8187
"name": "Code Web Chat",
@@ -222,6 +228,18 @@
222228
"command": "codeWebChat.previewWebsite",
223229
"title": "Preview Website Content"
224230
},
231+
{
232+
"command": "codeWebChat.checkAllWebsites",
233+
"title": "Check All",
234+
"category": "Code Web Chat",
235+
"icon": "$(check-all)"
236+
},
237+
{
238+
"command": "codeWebChat.clearChecksWebsites",
239+
"title": "Clear All Checks",
240+
"category": "Code Web Chat",
241+
"icon": "$(clear-all)"
242+
},
225243
{
226244
"command": "codeWebChat.delete",
227245
"title": "Delete"
@@ -301,6 +319,14 @@
301319
"command": "codeWebChat.previewWebsite",
302320
"when": "false"
303321
},
322+
{
323+
"command": "codeWebChat.checkAllWebsites",
324+
"when": "false"
325+
},
326+
{
327+
"command": "codeWebChat.clearChecksWebsites",
328+
"when": "false"
329+
},
304330
{
305331
"command": "codeWebChat.applyContext",
306332
"when": "false"
@@ -400,6 +426,16 @@
400426
"when": "view == codeWebChatViewOpenEditors",
401427
"group": "navigation@5"
402428
},
429+
{
430+
"command": "codeWebChat.checkAllWebsites",
431+
"when": "view == codeWebChatViewWebsites",
432+
"group": "navigation@1"
433+
},
434+
{
435+
"command": "codeWebChat.clearChecksWebsites",
436+
"when": "view == codeWebChatViewWebsites",
437+
"group": "navigation@2"
438+
},
403439
{
404440
"command": "codeWebChat.openRepository",
405441
"when": "view == codeWebChatView",

‎packages/vscode/src/context/context-initialization.ts‎

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path'
33
import {
44
WorkspaceProvider,
55
FileItem,
6-
WebsitesFolderItem
6+
ContextFolderItem
77
} from './providers/workspace-provider'
88
import { FilesCollector } from '../utils/files-collector'
99
import { OpenEditorsProvider } from './providers/open-editors-provider'
@@ -23,15 +23,12 @@ export function context_initialization(context: vscode.ExtensionContext): {
2323
} {
2424
const workspace_folders = vscode.workspace.workspaceFolders ?? []
2525

26-
let workspace_view: vscode.TreeView<
27-
FileItem | WebsiteItem | WebsitesFolderItem
28-
>
26+
let workspace_view: vscode.TreeView<FileItem | ContextFolderItem>
2927

3028
const websites_provider = new WebsitesProvider(context)
3129
const workspace_provider = new WorkspaceProvider(
3230
workspace_folders as any,
33-
context,
34-
websites_provider
31+
context
3532
)
3633
context.subscriptions.push(websites_provider)
3734

@@ -47,22 +44,24 @@ export function context_initialization(context: vscode.ExtensionContext): {
4744
)
4845

4946
const update_activity_bar_badge_token_count = async () => {
50-
let total_token_count = 0
51-
52-
if (workspace_provider) {
53-
total_token_count +=
47+
if (workspace_provider && workspace_view) {
48+
const workspace_token_count =
5449
await workspace_provider.get_checked_files_token_count()
50+
workspace_view.badge = {
51+
value: workspace_token_count,
52+
tooltip: workspace_token_count
53+
? `About ${workspace_token_count} tokens in context`
54+
: ''
55+
}
5556
}
5657

57-
if (websites_provider) {
58-
total_token_count += websites_provider.get_checked_websites_token_count()
59-
}
60-
61-
if (workspace_view) {
62-
workspace_view.badge = {
63-
value: total_token_count,
64-
tooltip: total_token_count
65-
? `About ${total_token_count} tokens in context`
58+
if (websites_provider && websites_view) {
59+
const websites_token_count =
60+
websites_provider.get_checked_websites_token_count()
61+
websites_view.badge = {
62+
value: websites_token_count,
63+
tooltip: websites_token_count
64+
? `About ${websites_token_count} tokens in context`
6665
: ''
6766
}
6867
}
@@ -80,7 +79,7 @@ export function context_initialization(context: vscode.ExtensionContext): {
8079
})
8180

8281
const register_workspace_view_handlers = (
83-
view: vscode.TreeView<FileItem | WebsiteItem | WebsitesFolderItem>
82+
view: vscode.TreeView<FileItem | ContextFolderItem>
8483
) => {
8584
view.onDidChangeCheckboxState(async (e) => {
8685
for (const [item, state] of e.items) {
@@ -109,11 +108,37 @@ export function context_initialization(context: vscode.ExtensionContext): {
109108
}
110109
)
111110

111+
const websites_view = vscode.window.createTreeView(
112+
'codeWebChatViewWebsites',
113+
{
114+
treeDataProvider: websites_provider,
115+
manageCheckboxStateManually: true
116+
}
117+
)
118+
119+
const update_websites_view_message = () => {
120+
websites_view.message =
121+
websites_provider.get_websites_count() > 0
122+
? undefined
123+
: 'Websites added with the browser extension appear here.'
124+
}
125+
126+
update_websites_view_message()
127+
128+
websites_view.onDidChangeCheckboxState(async (e) => {
129+
for (const [item, state] of e.items) {
130+
if (item instanceof WebsiteItem) {
131+
await websites_provider.update_check_state(item, state)
132+
}
133+
}
134+
})
135+
112136
context.subscriptions.push(
113137
workspace_provider,
114138
open_editors_provider,
115139
workspace_view,
116-
open_editors_view
140+
open_editors_view,
141+
websites_view
117142
)
118143

119144
context.subscriptions.push(
@@ -242,6 +267,12 @@ export function context_initialization(context: vscode.ExtensionContext): {
242267
await open_editors_provider!.check_all()
243268
}
244269
),
270+
vscode.commands.registerCommand('codeWebChat.checkAllWebsites', () => {
271+
websites_provider.check_all()
272+
}),
273+
vscode.commands.registerCommand('codeWebChat.clearChecksWebsites', () => {
274+
websites_provider.clear_checks()
275+
}),
245276
vscode.commands.registerCommand(
246277
'codeWebChat.previewWebsite',
247278
async (website: WebsiteItem) => {
@@ -308,6 +339,7 @@ export function context_initialization(context: vscode.ExtensionContext): {
308339
// Fixes badge not updating when websites list changes
309340
websites_provider.onDidChangeTreeData(() => {
310341
update_activity_bar_badge_token_count()
342+
update_websites_view_message()
311343
})
312344
)
313345

‎packages/vscode/src/context/providers/websites-provider.ts‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,6 @@ export class WebsiteItem extends vscode.TreeItem {
3838
}
3939
}
4040

41-
export class EmptyMessageItem extends vscode.TreeItem {
42-
constructor() {
43-
super(
44-
'No websites available for context',
45-
vscode.TreeItemCollapsibleState.None
46-
)
47-
this.description = 'Use browser extension to add some'
48-
this.tooltip = 'Use browser extension to add some'
49-
this.iconPath = new vscode.ThemeIcon('info')
50-
this.contextValue = 'empty'
51-
}
52-
}
53-
5441
export class WebsitesProvider
5542
implements vscode.TreeDataProvider<WebsiteItem>, vscode.Disposable
5643
{
@@ -111,6 +98,10 @@ export class WebsitesProvider
11198
)
11299
}
113100

101+
get_websites_count(): number {
102+
return this._websites.length
103+
}
104+
114105
get_checked_websites(): Website[] {
115106
return this._websites.filter(
116107
(website) =>

0 commit comments

Comments
 (0)