Skip to content

Commit c842ee4

Browse files
authored
Add device commands to Devices view context menu, nest device info (#853)
1 parent 886af51 commit c842ee4

4 files changed

Lines changed: 512 additions & 164 deletions

File tree

package.json

Lines changed: 198 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -491,34 +491,79 @@
491491
"group": "inline"
492492
},
493493
{
494-
"command": "extension.brightscript.setActiveDevice",
495-
"when": "view == devicesView && viewItem =~ /^device-/",
496-
"group": "navigation@1"
494+
"command": "extension.brightscript.devicesView.deviceMenu.setActiveDevice",
495+
"when": "view == devicesView && viewItem =~ /^device\\b/",
496+
"group": "1_primary@1"
497497
},
498498
{
499-
"command": "extension.brightscript.refreshDevice",
500-
"when": "view == devicesView && viewItem =~ /^device-/",
501-
"group": "navigation@2"
499+
"command": "extension.brightscript.devicesView.deviceMenu.captureScreenshot",
500+
"when": "view == devicesView && viewItem =~ /^device\\b/",
501+
"group": "1_primary@2"
502+
},
503+
{
504+
"command": "extension.brightscript.devicesView.deviceMenu.switchTvInput",
505+
"when": "view == devicesView && viewItem =~ /-isTv\\b/",
506+
"group": "1_primary@3"
507+
},
508+
{
509+
"command": "extension.brightscript.devicesView.deviceMenu.refreshDevice",
510+
"when": "view == devicesView && viewItem =~ /^device\\b/",
511+
"group": "2_device@1"
512+
},
513+
{
514+
"command": "extension.brightscript.devicesView.deviceMenu.restartDevice",
515+
"when": "view == devicesView && viewItem =~ /-canRestart\\b/",
516+
"group": "2_device@2"
517+
},
518+
{
519+
"command": "extension.brightscript.devicesView.deviceMenu.checkAndInstallUpdates",
520+
"when": "view == devicesView && viewItem =~ /-canRestart\\b/",
521+
"group": "2_device@3"
522+
},
523+
{
524+
"command": "extension.brightscript.devicesView.deviceMenu.openWebPortal",
525+
"when": "view == devicesView && viewItem =~ /^device\\b/",
526+
"group": "3_web@1"
527+
},
528+
{
529+
"command": "extension.brightscript.devicesView.deviceMenu.viewRegistry",
530+
"when": "view == devicesView && viewItem =~ /-canViewRegistry\\b/",
531+
"group": "3_web@2"
502532
},
503533
{
504-
"command": "extension.brightscript.addDeviceToUserSettings",
505-
"when": "view == devicesView && (viewItem == 'device' || viewItem == 'device-workspace')",
506-
"group": "settings@1"
534+
"command": "extension.brightscript.devicesView.deviceMenu.setDevicePassword",
535+
"when": "view == devicesView && viewItem =~ /-noPassword\\b/",
536+
"group": "4_password@1"
507537
},
508538
{
509-
"command": "extension.brightscript.editDeviceInUserSettings",
510-
"when": "view == devicesView && (viewItem == 'device-user' || viewItem == 'device-user-workspace')",
511-
"group": "settings@1"
539+
"command": "extension.brightscript.devicesView.deviceMenu.changeDevicePassword",
540+
"when": "view == devicesView && viewItem =~ /-hasPassword\\b/",
541+
"group": "4_password@1"
512542
},
513543
{
514-
"command": "extension.brightscript.addDeviceToWorkspaceSettings",
515-
"when": "view == devicesView && (viewItem == 'device' || viewItem == 'device-user')",
516-
"group": "settings@2"
544+
"command": "extension.brightscript.devicesView.deviceMenu.clearDevicePassword",
545+
"when": "view == devicesView && viewItem =~ /-hasPassword\\b/",
546+
"group": "4_password@2"
517547
},
518548
{
519-
"command": "extension.brightscript.editDeviceInWorkspaceSettings",
520-
"when": "view == devicesView && (viewItem == 'device-workspace' || viewItem == 'device-user-workspace')",
521-
"group": "settings@2"
549+
"command": "extension.brightscript.devicesView.deviceMenu.addToUserSettings",
550+
"when": "view == devicesView && viewItem =~ /-notInUser\\b/",
551+
"group": "5_settings@1"
552+
},
553+
{
554+
"command": "extension.brightscript.devicesView.deviceMenu.editInUserSettings",
555+
"when": "view == devicesView && viewItem =~ /-inUser\\b/",
556+
"group": "5_settings@1"
557+
},
558+
{
559+
"command": "extension.brightscript.devicesView.deviceMenu.addToWorkspaceSettings",
560+
"when": "view == devicesView && viewItem =~ /-notInWorkspace\\b/",
561+
"group": "5_settings@2"
562+
},
563+
{
564+
"command": "extension.brightscript.devicesView.deviceMenu.editInWorkspaceSettings",
565+
"when": "view == devicesView && viewItem =~ /-inWorkspace\\b/",
566+
"group": "5_settings@2"
522567
}
523568
],
524569
"explorer/context": [
@@ -702,6 +747,66 @@
702747
{
703748
"command": "extension.brightscript.devicesView.toggleFilter.autoDetected.active",
704749
"when": "false"
750+
},
751+
{
752+
"command": "extension.brightscript.devicesView.deviceMenu.setActiveDevice",
753+
"when": "false"
754+
},
755+
{
756+
"command": "extension.brightscript.devicesView.deviceMenu.captureScreenshot",
757+
"when": "false"
758+
},
759+
{
760+
"command": "extension.brightscript.devicesView.deviceMenu.switchTvInput",
761+
"when": "false"
762+
},
763+
{
764+
"command": "extension.brightscript.devicesView.deviceMenu.refreshDevice",
765+
"when": "false"
766+
},
767+
{
768+
"command": "extension.brightscript.devicesView.deviceMenu.restartDevice",
769+
"when": "false"
770+
},
771+
{
772+
"command": "extension.brightscript.devicesView.deviceMenu.checkAndInstallUpdates",
773+
"when": "false"
774+
},
775+
{
776+
"command": "extension.brightscript.devicesView.deviceMenu.openWebPortal",
777+
"when": "false"
778+
},
779+
{
780+
"command": "extension.brightscript.devicesView.deviceMenu.viewRegistry",
781+
"when": "false"
782+
},
783+
{
784+
"command": "extension.brightscript.devicesView.deviceMenu.setDevicePassword",
785+
"when": "false"
786+
},
787+
{
788+
"command": "extension.brightscript.devicesView.deviceMenu.changeDevicePassword",
789+
"when": "false"
790+
},
791+
{
792+
"command": "extension.brightscript.devicesView.deviceMenu.clearDevicePassword",
793+
"when": "false"
794+
},
795+
{
796+
"command": "extension.brightscript.devicesView.deviceMenu.addToUserSettings",
797+
"when": "false"
798+
},
799+
{
800+
"command": "extension.brightscript.devicesView.deviceMenu.editInUserSettings",
801+
"when": "false"
802+
},
803+
{
804+
"command": "extension.brightscript.devicesView.deviceMenu.addToWorkspaceSettings",
805+
"when": "false"
806+
},
807+
{
808+
"command": "extension.brightscript.devicesView.deviceMenu.editInWorkspaceSettings",
809+
"when": "false"
705810
}
706811
]
707812
},
@@ -3914,6 +4019,81 @@
39144019
"category": "BrightScript",
39154020
"icon": "$(cloud-download)"
39164021
},
4022+
{
4023+
"command": "extension.brightscript.devicesView.deviceMenu.setActiveDevice",
4024+
"title": "⭐ Set as Active Device",
4025+
"category": "BrightScript"
4026+
},
4027+
{
4028+
"command": "extension.brightscript.devicesView.deviceMenu.captureScreenshot",
4029+
"title": "📷 Capture Screenshot",
4030+
"category": "BrightScript"
4031+
},
4032+
{
4033+
"command": "extension.brightscript.devicesView.deviceMenu.switchTvInput",
4034+
"title": "📺 Switch TV Input",
4035+
"category": "BrightScript"
4036+
},
4037+
{
4038+
"command": "extension.brightscript.devicesView.deviceMenu.refreshDevice",
4039+
"title": "🔃 Refresh Device",
4040+
"category": "BrightScript"
4041+
},
4042+
{
4043+
"command": "extension.brightscript.devicesView.deviceMenu.restartDevice",
4044+
"title": "🔁 Restart Device",
4045+
"category": "BrightScript"
4046+
},
4047+
{
4048+
"command": "extension.brightscript.devicesView.deviceMenu.checkAndInstallUpdates",
4049+
"title": "🔄 Check for Software Updates",
4050+
"category": "BrightScript"
4051+
},
4052+
{
4053+
"command": "extension.brightscript.devicesView.deviceMenu.openWebPortal",
4054+
"title": "🔗 Open Device Web Portal",
4055+
"category": "BrightScript"
4056+
},
4057+
{
4058+
"command": "extension.brightscript.devicesView.deviceMenu.viewRegistry",
4059+
"title": "📋 View Registry",
4060+
"category": "BrightScript"
4061+
},
4062+
{
4063+
"command": "extension.brightscript.devicesView.deviceMenu.setDevicePassword",
4064+
"title": "🔑 Set Device Password",
4065+
"category": "BrightScript"
4066+
},
4067+
{
4068+
"command": "extension.brightscript.devicesView.deviceMenu.changeDevicePassword",
4069+
"title": "🔑 Change Device Password",
4070+
"category": "BrightScript"
4071+
},
4072+
{
4073+
"command": "extension.brightscript.devicesView.deviceMenu.clearDevicePassword",
4074+
"title": "🗑️ Clear Device Password",
4075+
"category": "BrightScript"
4076+
},
4077+
{
4078+
"command": "extension.brightscript.devicesView.deviceMenu.addToUserSettings",
4079+
"title": "👤 Add to User Settings",
4080+
"category": "BrightScript"
4081+
},
4082+
{
4083+
"command": "extension.brightscript.devicesView.deviceMenu.editInUserSettings",
4084+
"title": "👤 Edit in User Settings",
4085+
"category": "BrightScript"
4086+
},
4087+
{
4088+
"command": "extension.brightscript.devicesView.deviceMenu.addToWorkspaceSettings",
4089+
"title": "📁 Add to Workspace Settings",
4090+
"category": "BrightScript"
4091+
},
4092+
{
4093+
"command": "extension.brightscript.devicesView.deviceMenu.editInWorkspaceSettings",
4094+
"title": "📁 Edit in Workspace Settings",
4095+
"category": "BrightScript"
4096+
},
39174097
{
39184098
"command": "extension.brightscript.addDeviceToUserSettings",
39194099
"title": "Add to User Settings",

src/BrightScriptCommands.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,71 @@ export class BrightScriptCommands {
11801180
this.registerCommand('devicesView.checkAndInstallUpdates', (element?: { key?: string }) => {
11811181
return this.checkForUpdates(element?.key ? this.deviceManager.getDevice(element.key)?.ip : undefined);
11821182
});
1183+
1184+
this.registerDeviceContextMenuCommands();
1185+
}
1186+
1187+
/**
1188+
* Register the commands behind the right-click context menu on a device in the Devices view.
1189+
* Each receives the clicked tree element and resolves it into the argument shape its
1190+
* underlying command expects. These are hidden from the command palette (they only make
1191+
* sense with a tree element), which also lets their titles carry the emoji icons shown
1192+
* in the context menu.
1193+
*/
1194+
private registerDeviceContextMenuCommands() {
1195+
const getDevice = (element?: { key?: string }) => {
1196+
return element?.key ? this.deviceManager.getDevice(element.key) : undefined;
1197+
};
1198+
1199+
this.registerCommand('devicesView.deviceMenu.setActiveDevice', (element?: { key?: string }) => {
1200+
return vscode.commands.executeCommand('extension.brightscript.setActiveDevice', element);
1201+
});
1202+
this.registerCommand('devicesView.deviceMenu.captureScreenshot', (element?: { key?: string }) => {
1203+
return vscode.commands.executeCommand('extension.brightscript.captureScreenshot', getDevice(element)?.ip);
1204+
});
1205+
this.registerCommand('devicesView.deviceMenu.switchTvInput', (element?: { key?: string }) => {
1206+
return vscode.commands.executeCommand('extension.brightscript.changeTvInput', getDevice(element)?.ip);
1207+
});
1208+
this.registerCommand('devicesView.deviceMenu.refreshDevice', (element?: { key?: string }) => {
1209+
return vscode.commands.executeCommand('extension.brightscript.refreshDevice', element);
1210+
});
1211+
this.registerCommand('devicesView.deviceMenu.restartDevice', (element?: { key?: string }) => {
1212+
return this.restartDevice(getDevice(element)?.ip);
1213+
});
1214+
this.registerCommand('devicesView.deviceMenu.checkAndInstallUpdates', (element?: { key?: string }) => {
1215+
return this.checkForUpdates(getDevice(element)?.ip);
1216+
});
1217+
this.registerCommand('devicesView.deviceMenu.openWebPortal', (element?: { key?: string }) => {
1218+
const ip = getDevice(element)?.ip;
1219+
if (!ip) {
1220+
return vscode.window.showErrorMessage('Could not determine the IP address for this device');
1221+
}
1222+
return vscode.commands.executeCommand('extension.brightscript.openUrl', `http://${ip}`);
1223+
});
1224+
this.registerCommand('devicesView.deviceMenu.viewRegistry', (element?: { key?: string }) => {
1225+
return vscode.commands.executeCommand('extension.brightscript.openRegistryInBrowser', getDevice(element)?.ip);
1226+
});
1227+
// Set and Change share a handler; the menu shows one or the other based on whether a password is stored
1228+
for (const commandName of ['devicesView.deviceMenu.setDevicePassword', 'devicesView.deviceMenu.changeDevicePassword']) {
1229+
this.registerCommand(commandName, (element?: { key?: string }) => {
1230+
return vscode.commands.executeCommand('extension.brightscript.setDevicePassword', getDevice(element)?.serialNumber);
1231+
});
1232+
}
1233+
this.registerCommand('devicesView.deviceMenu.clearDevicePassword', (element?: { key?: string }) => {
1234+
return vscode.commands.executeCommand('extension.brightscript.clearDevicePassword', getDevice(element)?.serialNumber);
1235+
});
1236+
this.registerCommand('devicesView.deviceMenu.addToUserSettings', (element?: { key?: string }) => {
1237+
return vscode.commands.executeCommand('extension.brightscript.addDeviceToUserSettings', element);
1238+
});
1239+
this.registerCommand('devicesView.deviceMenu.editInUserSettings', (element?: { key?: string }) => {
1240+
return vscode.commands.executeCommand('extension.brightscript.editDeviceInUserSettings', element);
1241+
});
1242+
this.registerCommand('devicesView.deviceMenu.addToWorkspaceSettings', (element?: { key?: string }) => {
1243+
return vscode.commands.executeCommand('extension.brightscript.addDeviceToWorkspaceSettings', element);
1244+
});
1245+
this.registerCommand('devicesView.deviceMenu.editInWorkspaceSettings', (element?: { key?: string }) => {
1246+
return vscode.commands.executeCommand('extension.brightscript.editDeviceInWorkspaceSettings', element);
1247+
});
11831248
}
11841249

11851250
private async sendAsciiToDevice(character: string) {

0 commit comments

Comments
 (0)