statusbar-quick-actions 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,536 @@
1
+ # Preset System and Dynamic Labels
2
+
3
+ This document describes the new preset system and dynamic label features added to the StatusBar Quick Actions extension.
4
+
5
+ ## Overview
6
+
7
+ The extension has been enhanced with two major features:
8
+
9
+ 1. **Preset System**: Save and load predefined button configurations
10
+ 2. **Dynamic Labels**: Display live information in button labels (time, git status, URLs, etc.)
11
+
12
+ ---
13
+
14
+ ## Preset System
15
+
16
+ ### What are Presets?
17
+
18
+ Presets allow you to save your current button configuration and quickly apply it later. This is useful for:
19
+
20
+ - Switching between different development contexts (frontend, backend, testing, etc.)
21
+ - Sharing configurations with team members
22
+ - Maintaining different setups for different projects
23
+ - Quick recovery if configuration gets corrupted
24
+
25
+ ### Preset Features
26
+
27
+ #### 1. Save Current Configuration as Preset
28
+
29
+ Save your current button setup with a name and description:
30
+
31
+ ```typescript
32
+ // Via Command Palette
33
+ "StatusBar Quick Actions: Manage Presets" → "Create New Preset"
34
+ ```
35
+
36
+ Each preset stores:
37
+
38
+ - All button configurations
39
+ - Theme settings (if customized)
40
+ - Metadata (creation date, modification date, tags)
41
+
42
+ #### 2. Apply Presets
43
+
44
+ Load a saved preset with three application modes:
45
+
46
+ - **Replace**: Remove all current buttons and replace with preset buttons
47
+ - **Merge**: Merge preset buttons with current buttons (overwrites buttons with same ID)
48
+ - **Append**: Add preset buttons to current buttons (generates new IDs for conflicts)
49
+
50
+ When applying a preset, you'll see an impact preview showing:
51
+
52
+ - Number of buttons to be added
53
+ - Number of buttons to be modified
54
+ - Number of buttons to be removed
55
+
56
+ #### 3. Preset Management
57
+
58
+ Access via `StatusBar Quick Actions: Edit Button` → `Manage Presets`:
59
+
60
+ - **Create New Preset**: Save current configuration
61
+ - **Apply Preset**: Load a saved preset
62
+ - **View All Presets**: Browse and manage all saved presets
63
+ - **Export Preset**: Export a preset to a JSON file
64
+ - **Import Preset**: Import a preset from a JSON file
65
+
66
+ ### Preset Storage
67
+
68
+ Presets are stored in VSCode's global state and persist across:
69
+
70
+ - VSCode restarts
71
+ - Workspace changes
72
+ - Extension updates
73
+
74
+ ### Preset File Format
75
+
76
+ Exported presets use the following JSON structure:
77
+
78
+ ```json
79
+ {
80
+ "id": "preset_1234567890",
81
+ "name": "My Development Setup",
82
+ "description": "Standard buttons for Node.js development",
83
+ "buttons": [
84
+ {
85
+ "id": "build",
86
+ "text": "Build",
87
+ "command": {
88
+ "type": "npm",
89
+ "script": "build"
90
+ }
91
+ // ... other button properties
92
+ }
93
+ ],
94
+ "theme": {
95
+ // optional theme configuration
96
+ },
97
+ "metadata": {
98
+ "created": "2025-01-01T00:00:00.000Z",
99
+ "modified": "2025-01-01T00:00:00.000Z",
100
+ "author": "optional",
101
+ "tags": ["development", "nodejs"]
102
+ }
103
+ }
104
+ ```
105
+
106
+ ---
107
+
108
+ ## Dynamic Labels
109
+
110
+ ### What are Dynamic Labels?
111
+
112
+ Dynamic labels allow buttons to display live, automatically updating information instead of static text. This enables buttons to show:
113
+
114
+ - Current time/date
115
+ - Git branch name or status
116
+ - Content fetched from URLs
117
+ - Environment variables
118
+ - Custom computed values
119
+
120
+ ### Dynamic Label Types
121
+
122
+ #### 1. Time-based Labels
123
+
124
+ Display current time or date with custom formatting:
125
+
126
+ ```json
127
+ {
128
+ "id": "clock",
129
+ "text": "Time",
130
+ "dynamicLabel": {
131
+ "type": "time",
132
+ "format": "HH:mm:ss",
133
+ "refreshInterval": 1000,
134
+ "template": "🕐 ${value}"
135
+ },
136
+ "command": {
137
+ "type": "vscode",
138
+ "command": "workbench.action.showCommands"
139
+ }
140
+ }
141
+ ```
142
+
143
+ **Format Tokens:**
144
+
145
+ - `YYYY` - Full year (2025)
146
+ - `YY` - Short year (25)
147
+ - `MM` - Month (01-12)
148
+ - `DD` - Day (01-31)
149
+ - `HH` - Hours 24-hour (00-23)
150
+ - `hh` - Hours 12-hour (01-12)
151
+ - `mm` - Minutes (00-59)
152
+ - `ss` - Seconds (00-59)
153
+ - `A` - AM/PM uppercase
154
+ - `a` - am/pm lowercase
155
+
156
+ #### 2. URL-based Labels
157
+
158
+ Fetch and display content from URLs:
159
+
160
+ ```json
161
+ {
162
+ "id": "api-status",
163
+ "text": "API Status",
164
+ "dynamicLabel": {
165
+ "type": "url",
166
+ "url": "https://api.example.com/status",
167
+ "refreshInterval": 30000,
168
+ "fallback": "Unknown",
169
+ "template": "API: ${value}"
170
+ },
171
+ "command": {
172
+ "type": "shell",
173
+ "command": "curl https://api.example.com/status"
174
+ }
175
+ }
176
+ ```
177
+
178
+ **Features:**
179
+
180
+ - Automatically parses JSON responses
181
+ - Truncates long text responses (max 100 chars)
182
+ - 5-second timeout for requests
183
+ - Supports both HTTP and HTTPS
184
+
185
+ #### 3. Environment Variable Labels
186
+
187
+ Display environment variable values:
188
+
189
+ ```json
190
+ {
191
+ "id": "node-env",
192
+ "text": "Environment",
193
+ "dynamicLabel": {
194
+ "type": "env",
195
+ "envVar": "NODE_ENV",
196
+ "fallback": "development",
197
+ "template": "ENV: ${value}"
198
+ },
199
+ "command": {
200
+ "type": "shell",
201
+ "command": "echo $NODE_ENV"
202
+ }
203
+ }
204
+ ```
205
+
206
+ #### 4. Git Information Labels
207
+
208
+ Display git repository information:
209
+
210
+ ```json
211
+ {
212
+ "id": "git-branch",
213
+ "text": "Branch",
214
+ "dynamicLabel": {
215
+ "type": "git",
216
+ "gitInfo": "branch",
217
+ "refreshInterval": 5000,
218
+ "template": "⎇ ${value}"
219
+ },
220
+ "command": {
221
+ "type": "shell",
222
+ "command": "git status"
223
+ }
224
+ }
225
+ ```
226
+
227
+ **Git Info Types:**
228
+
229
+ - `branch` - Current branch name
230
+ - `status` - Working tree status (number of changes or "Clean")
231
+ - `remote` - Remote repository name
232
+
233
+ #### 5. Custom Labels (Reserved for Future)
234
+
235
+ Placeholder for user-defined custom functions:
236
+
237
+ ```json
238
+ {
239
+ "id": "custom",
240
+ "text": "Custom",
241
+ "dynamicLabel": {
242
+ "type": "custom",
243
+ "customFunction": "myCustomFunction",
244
+ "fallback": "N/A"
245
+ }
246
+ }
247
+ ```
248
+
249
+ _Note: Custom functions are not yet implemented but are reserved for future extension._
250
+
251
+ ### Dynamic Label Properties
252
+
253
+ All dynamic label configurations support these properties:
254
+
255
+ | Property | Type | Required | Description |
256
+ | ----------------- | ------ | -------- | ------------------------------------------------------------ |
257
+ | `type` | string | Yes | Label type: "time", "url", "env", "git", "custom" |
258
+ | `format` | string | No | Format string (for "time" type) |
259
+ | `url` | string | No | URL to fetch from (for "url" type) |
260
+ | `envVar` | string | No | Environment variable name (for "env" type) |
261
+ | `gitInfo` | string | No | Git info type (for "git" type): "branch", "status", "remote" |
262
+ | `customFunction` | string | No | Function name (for "custom" type) |
263
+ | `refreshInterval` | number | No | Auto-refresh interval in milliseconds (0 = no auto-refresh) |
264
+ | `fallback` | string | No | Fallback value if evaluation fails |
265
+ | `template` | string | No | Template string with `${value}` placeholder |
266
+
267
+ ### Refresh Behavior
268
+
269
+ Dynamic labels can be configured to refresh automatically:
270
+
271
+ - **Manual refresh**: Set `refreshInterval` to `0` or omit it
272
+ - **Auto-refresh**: Set `refreshInterval` to milliseconds (e.g., `1000` for every second)
273
+ - **On-demand refresh**: Labels refresh when button configuration changes
274
+
275
+ ### Error Handling
276
+
277
+ If a dynamic label fails to evaluate:
278
+
279
+ 1. The fallback value is used (if provided)
280
+ 2. Error is logged to console
281
+ 3. Button remains functional with fallback text
282
+ 4. Refresh continues attempting if interval is set
283
+
284
+ ---
285
+
286
+ ## API Reference
287
+
288
+ ### ConfigManager Methods
289
+
290
+ ```typescript
291
+ // Apply a preset to current configuration
292
+ async applyPreset(preset: PresetConfig, mode: PresetApplicationMode): Promise<void>
293
+
294
+ // Get impact preview of applying a preset
295
+ getPresetImpact(preset: PresetConfig, mode: PresetApplicationMode): {
296
+ added: number;
297
+ modified: number;
298
+ removed: number;
299
+ total: number;
300
+ }
301
+
302
+ // Validate preset before application
303
+ validatePresetApplication(preset: PresetConfig): {
304
+ isValid: boolean;
305
+ errors: string[];
306
+ }
307
+ ```
308
+
309
+ ### PresetManager Methods
310
+
311
+ ```typescript
312
+ // Get all presets
313
+ getAllPresets(): PresetConfig[]
314
+
315
+ // Get a preset by ID
316
+ getPreset(presetId: string): PresetConfig | null
317
+
318
+ // Save a preset
319
+ async savePreset(preset: PresetConfig): Promise<void>
320
+
321
+ // Delete a preset
322
+ async deletePreset(presetId: string): Promise<void>
323
+
324
+ // Create preset from current config
325
+ async createPresetFromConfig(
326
+ name: string,
327
+ description: string,
328
+ currentConfig: ExtensionConfig,
329
+ tags?: string[]
330
+ ): Promise<PresetConfig>
331
+
332
+ // Apply preset to config
333
+ applyPreset(
334
+ preset: PresetConfig,
335
+ currentConfig: ExtensionConfig,
336
+ mode: PresetApplicationMode
337
+ ): ExtensionConfig
338
+
339
+ // Export/Import presets
340
+ async exportPreset(preset: PresetConfig): Promise<void>
341
+ async importPreset(): Promise<PresetConfig | null>
342
+
343
+ // Duplicate preset
344
+ async duplicatePreset(presetId: string): Promise<PresetConfig | null>
345
+
346
+ // Search presets
347
+ searchPresets(query: string): PresetConfig[]
348
+ ```
349
+
350
+ ### DynamicLabelManager Methods
351
+
352
+ ```typescript
353
+ // Evaluate a dynamic label
354
+ async evaluateLabel(buttonId: string, field: DynamicLabelField): Promise<string>
355
+
356
+ // Get label state
357
+ getLabelState(buttonId: string): DynamicLabelState | undefined
358
+
359
+ // Force refresh a label
360
+ async refreshLabel(buttonId: string): Promise<string | null>
361
+
362
+ // Stop refresh timer
363
+ stopRefreshTimer(buttonId: string): void
364
+
365
+ // Clear label state
366
+ clearLabelState(buttonId: string): void
367
+ ```
368
+
369
+ ---
370
+
371
+ ## Commands
372
+
373
+ The following commands are available in the Command Palette:
374
+
375
+ - `StatusBar Quick Actions: Manage Presets` - Open preset management UI
376
+ - `StatusBar Quick Actions: Apply Preset` - Quick apply a preset
377
+ - `StatusBar Quick Actions: Save As Preset` - Save current config as preset
378
+ - `StatusBar Quick Actions: Edit Button` - Main settings menu (includes preset management)
379
+
380
+ ---
381
+
382
+ ## Examples
383
+
384
+ ### Example 1: Development Environment Preset
385
+
386
+ ```json
387
+ {
388
+ "id": "preset_dev",
389
+ "name": "Development Environment",
390
+ "description": "Standard buttons for active development",
391
+ "buttons": [
392
+ {
393
+ "id": "dev_server",
394
+ "text": "Dev Server",
395
+ "command": { "type": "npm", "script": "dev" },
396
+ "icon": { "id": "server" }
397
+ },
398
+ {
399
+ "id": "build",
400
+ "text": "Build",
401
+ "command": { "type": "npm", "script": "build" },
402
+ "icon": { "id": "package" }
403
+ },
404
+ {
405
+ "id": "test",
406
+ "text": "Test",
407
+ "command": { "type": "npm", "script": "test" },
408
+ "icon": { "id": "beaker" }
409
+ }
410
+ ]
411
+ }
412
+ ```
413
+
414
+ ### Example 2: Time Display Button
415
+
416
+ ```json
417
+ {
418
+ "id": "clock",
419
+ "text": "Loading...",
420
+ "tooltip": "Current Time",
421
+ "dynamicLabel": {
422
+ "type": "time",
423
+ "format": "HH:mm:ss",
424
+ "refreshInterval": 1000,
425
+ "template": "🕐 ${value}"
426
+ },
427
+ "command": {
428
+ "type": "vscode",
429
+ "command": "workbench.action.showCommands"
430
+ },
431
+ "alignment": "right",
432
+ "priority": 1000
433
+ }
434
+ ```
435
+
436
+ ### Example 3: Git Branch Display
437
+
438
+ ```json
439
+ {
440
+ "id": "git_branch",
441
+ "text": "Branch",
442
+ "tooltip": "Current Git Branch",
443
+ "dynamicLabel": {
444
+ "type": "git",
445
+ "gitInfo": "branch",
446
+ "refreshInterval": 5000,
447
+ "fallback": "No Git",
448
+ "template": "⎇ ${value}"
449
+ },
450
+ "command": {
451
+ "type": "shell",
452
+ "command": "git status"
453
+ },
454
+ "alignment": "left",
455
+ "priority": 500
456
+ }
457
+ ```
458
+
459
+ ---
460
+
461
+ ## Best Practices
462
+
463
+ ### Presets
464
+
465
+ 1. **Naming**: Use descriptive names that indicate the purpose (e.g., "Frontend Development", "Testing Environment")
466
+ 2. **Documentation**: Add detailed descriptions to help others understand the preset's purpose
467
+ 3. **Tagging**: Use tags to organize presets by category or project
468
+ 4. **Version Control**: Export important presets and commit them to version control
469
+ 5. **Team Sharing**: Share preset files with team members for consistent setups
470
+
471
+ ### Dynamic Labels
472
+
473
+ 1. **Refresh Intervals**: Choose appropriate intervals to balance freshness with performance
474
+ - Time: 1000ms (1 second) for clocks
475
+ - Git: 5000ms (5 seconds) for branch info
476
+ - URLs: 30000ms (30 seconds) or more for external APIs
477
+ 2. **Fallbacks**: Always provide fallback values for graceful degradation
478
+ 3. **Templates**: Use templates to add context (icons, prefixes) to values
479
+ 4. **Error Handling**: Monitor console for errors if labels aren't updating
480
+ 5. **Performance**: Limit the number of auto-refreshing labels to avoid performance impact
481
+
482
+ ---
483
+
484
+ ## Troubleshooting
485
+
486
+ ### Presets Not Saving
487
+
488
+ - Check if you have write permissions
489
+ - Verify the preset name is unique
490
+ - Check console for error messages
491
+
492
+ ### Dynamic Labels Not Updating
493
+
494
+ - Verify `refreshInterval` is set and greater than 0
495
+ - Check if the label type configuration is correct
496
+ - Look for errors in the console
497
+ - Ensure required dependencies are available (e.g., Git extension for git labels)
498
+
499
+ ### URL Labels Timeout
500
+
501
+ - Check network connectivity
502
+ - Verify the URL is accessible
503
+ - Consider increasing the timeout (currently hardcoded to 5 seconds)
504
+ - Use a fallback value for offline scenarios
505
+
506
+ ### Git Labels Not Working
507
+
508
+ - Ensure Git extension is installed and enabled
509
+ - Verify you're in a Git repository
510
+ - Check if the Git extension API is available
511
+
512
+ ---
513
+
514
+ ## Future Enhancements
515
+
516
+ Potential future improvements:
517
+
518
+ 1. **Custom Functions**: Allow users to define custom JavaScript functions for labels
519
+ 2. **Preset Categories**: Organize presets into categories
520
+ 3. **Preset Sharing**: Built-in marketplace or sharing system
521
+ 4. **More Label Types**: Weather, system metrics, API responses with JSONPath
522
+ 5. **Conditional Labels**: Show different values based on conditions
523
+ 6. **Label Animations**: Transition effects for changing values
524
+ 7. **Preset Templates**: Pre-built presets for common scenarios
525
+
526
+ ---
527
+
528
+ ## Migration Guide
529
+
530
+ If you're upgrading from a version without these features:
531
+
532
+ 1. **No Action Required**: Existing configurations continue to work unchanged
533
+ 2. **Optional**: Create presets from your existing configurations for easier management
534
+ 3. **Optional**: Add dynamic labels to existing buttons for live information
535
+
536
+ The new features are fully backward compatible and opt-in.