Skip to content

Commit 07db915

Browse files
committed
Improve selection/removal
1 parent ef3cf45 commit 07db915

File tree

3 files changed

+601
-74
lines changed

3 files changed

+601
-74
lines changed

app/static/js/workspace_manager.js

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@ class WorkspaceState {
77
this.files = {}; // File path -> content mapping
88
this.selectedFile = null;
99
this.expandedFolders = new Set();
10+
11+
// Action/Tool states - unified state for toggles
12+
this.actionStates = {
13+
mcps: {
14+
expanded: false,
15+
active: false,
16+
items: {} // name -> checked state
17+
},
18+
agents: {
19+
expanded: false,
20+
active: false,
21+
items: {} // name -> checked state
22+
},
23+
rules: {
24+
expanded: false,
25+
active: false,
26+
items: {} // name -> checked state
27+
}
28+
};
29+
30+
// Agent name to file path mappings for easier removal
31+
this.agentMappings = {};
32+
1033
this.history = {
1134
past: [],
1235
present: null,
@@ -20,6 +43,12 @@ class WorkspaceState {
2043
this.files = {};
2144
this.selectedFile = null;
2245
this.expandedFolders = new Set();
46+
this.actionStates = {
47+
mcps: { expanded: false, active: false, items: {} },
48+
agents: { expanded: false, active: false, items: {} },
49+
rules: { expanded: false, active: false, items: {} }
50+
};
51+
this.agentMappings = {};
2352
this.history.present = this.snapshot();
2453
this.history.past = [];
2554
this.history.future = [];
@@ -31,6 +60,8 @@ class WorkspaceState {
3160
files: { ...this.files },
3261
selectedFile: this.selectedFile,
3362
expandedFolders: Array.from(this.expandedFolders),
63+
actionStates: JSON.parse(JSON.stringify(this.actionStates)),
64+
agentMappings: { ...this.agentMappings },
3465
timestamp: new Date().toISOString()
3566
};
3667
}
@@ -95,6 +126,12 @@ class WorkspaceState {
95126
this.files = { ...snapshot.files };
96127
this.selectedFile = snapshot.selectedFile;
97128
this.expandedFolders = new Set(snapshot.expandedFolders || []);
129+
this.actionStates = snapshot.actionStates ? JSON.parse(JSON.stringify(snapshot.actionStates)) : {
130+
mcps: { expanded: false, active: false, items: {} },
131+
agents: { expanded: false, active: false, items: {} },
132+
rules: { expanded: false, active: false, items: {} }
133+
};
134+
this.agentMappings = snapshot.agentMappings ? { ...snapshot.agentMappings } : {};
98135
}
99136

100137
// Reset to empty state
@@ -103,8 +140,62 @@ class WorkspaceState {
103140
this.files = {};
104141
this.selectedFile = null;
105142
this.expandedFolders = new Set();
143+
this.actionStates = {
144+
mcps: { expanded: false, active: false, items: {} },
145+
agents: { expanded: false, active: false, items: {} },
146+
rules: { expanded: false, active: false, items: {} }
147+
};
148+
this.agentMappings = {};
106149
this.history.present = this.snapshot();
107150
}
151+
152+
// Toggle action category (MCPs, Agents, Rules)
153+
toggleActionCategory(category) {
154+
if (this.actionStates[category]) {
155+
this.actionStates[category].active = !this.actionStates[category].active;
156+
this.actionStates[category].expanded = this.actionStates[category].active;
157+
}
158+
}
159+
160+
// Set action category state
161+
setActionCategoryState(category, active, expanded) {
162+
if (this.actionStates[category]) {
163+
this.actionStates[category].active = active;
164+
this.actionStates[category].expanded = expanded;
165+
}
166+
}
167+
168+
// Toggle individual action item
169+
toggleActionItem(category, itemName) {
170+
if (this.actionStates[category]) {
171+
if (!this.actionStates[category].items[itemName]) {
172+
this.actionStates[category].items[itemName] = false;
173+
}
174+
this.actionStates[category].items[itemName] = !this.actionStates[category].items[itemName];
175+
}
176+
}
177+
178+
// Set action item state
179+
setActionItemState(category, itemName, checked) {
180+
if (this.actionStates[category]) {
181+
this.actionStates[category].items[itemName] = checked;
182+
}
183+
}
184+
185+
// Check if action category is active
186+
isActionCategoryActive(category) {
187+
return this.actionStates[category]?.active || false;
188+
}
189+
190+
// Check if action category is expanded
191+
isActionCategoryExpanded(category) {
192+
return this.actionStates[category]?.expanded || false;
193+
}
194+
195+
// Check if action item is checked
196+
isActionItemChecked(category, itemName) {
197+
return this.actionStates[category]?.items[itemName] || false;
198+
}
108199

109200
// Check if we can undo/redo
110201
canUndo() {
@@ -122,6 +213,8 @@ class WorkspaceState {
122213
files: this.files,
123214
selectedFile: this.selectedFile,
124215
expandedFolders: Array.from(this.expandedFolders),
216+
actionStates: this.actionStates,
217+
agentMappings: this.agentMappings,
125218
history: {
126219
past: this.history.past,
127220
present: this.history.present,
@@ -140,6 +233,16 @@ class WorkspaceState {
140233
state.selectedFile = parsed.selectedFile || null;
141234
state.expandedFolders = new Set(parsed.expandedFolders || []);
142235

236+
// Restore action states
237+
if (parsed.actionStates) {
238+
state.actionStates = parsed.actionStates;
239+
}
240+
241+
// Restore agent mappings
242+
if (parsed.agentMappings) {
243+
state.agentMappings = parsed.agentMappings;
244+
}
245+
143246
if (parsed.history) {
144247
state.history.past = parsed.history.past || [];
145248
state.history.present = parsed.history.present || state.snapshot();
@@ -316,6 +419,11 @@ class WorkspaceManager {
316419
}
317420
}
318421

422+
// Restore action states UI
423+
if (window.restoreActionStates) {
424+
window.restoreActionStates();
425+
}
426+
319427
this.updateHistoryButtons();
320428
this.updateContextDropdown();
321429
}
@@ -355,10 +463,10 @@ class WorkspaceManager {
355463
}
356464

357465
// Include a file (main action for adding files)
358-
includeFile(path, content) {
466+
includeFile(path, content, skipConfirmation = false) {
359467
if (!this.currentState) return false;
360468

361-
if (this.currentState.files[path]) {
469+
if (this.currentState.files[path] && !skipConfirmation) {
362470
if (!confirm(`File "${path}" already exists. Overwrite?`)) {
363471
return false;
364472
}
@@ -371,10 +479,10 @@ class WorkspaceManager {
371479
}
372480

373481
// Delete a file
374-
deleteFile(path) {
482+
deleteFile(path, skipConfirmation = false) {
375483
if (!this.currentState) return false;
376484

377-
if (!confirm(`Delete "${path}"?`)) {
485+
if (!skipConfirmation && !confirm(`Delete "${path}"?`)) {
378486
return false;
379487
}
380488

0 commit comments

Comments
 (0)