Skip to content

Commit

Permalink
Improve Status and Saved Instrument Behavior
Browse files Browse the repository at this point in the history
- Only save instruments when explicitly connected or saved
- Add "Save" icon
- Fix status change when refreshing instrument list while connected to an instrument
- Fix status change when connected to 2 separate instruments and closing one of the terminals
  • Loading branch information
esarver committed Jan 23, 2025
1 parent eec705d commit c32afa9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 26 deletions.
43 changes: 27 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@
{
"command": "InstrumentsExplorer.save",
"title": "Save",
"category": "TSP"
"category": "TSP",
"icon": "$(save)"
},
{
"command": "InstrumentsExplorer.remove",
Expand Down Expand Up @@ -337,7 +338,7 @@
"view/item/context": [
{
"command": "InstrumentsExplorer.rename",
"when": "view == InstrumentsExplorer && viewItem =~ /Instr.*Saved.*/",
"when": "view == InstrumentsExplorer && viewItem =~ /Instr.*Saved.*/ && !(viewItem =~ /.*Connected.*/)",
"group": "inline"
},
{
Expand All @@ -362,11 +363,12 @@
},
{
"command": "InstrumentsExplorer.save",
"when": "view == InstrumentsExplorer && viewItem =~ /Instr.*Discovered.*/"
"when": "view == InstrumentsExplorer && viewItem =~ /Instr.*/ && !(viewItem =~ /.*Saved.*/)",
"group": "inline"
},
{
"command": "InstrumentsExplorer.remove",
"when": "view == InstrumentsExplorer && viewItem =~ /Instr.*Saved.*/",
"when": "view == InstrumentsExplorer && viewItem =~ /Instr.*Saved.*/ && !(viewItem =~ /.*Connected.*/)",
"group": "inline"
}
],
Expand Down
12 changes: 8 additions & 4 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ export class Connection extends vscode.TreeItem implements vscode.Disposable {
}

get status(): ConnectionStatus | undefined {
if (this.terminal && this._terminal?.exitStatus === undefined) {
this.status = ConnectionStatus.Connected
}
return this._status
}

Expand Down Expand Up @@ -438,22 +441,23 @@ export class Connection extends vscode.TreeItem implements vscode.Disposable {
this._terminal?.show(false)
vscode.window.onDidCloseTerminal((t) => {
Log.info("Terminal closed", LOGLOC)
this.status = ConnectionStatus.Active
this._terminal = undefined
if (
t.creationOptions.iconPath !== undefined &&
// eslint-disable-next-line @typescript-eslint/no-base-to-string
t.creationOptions.iconPath
.toString()
.search("tsp-terminal-icon")
.search("tsp-terminal-icon") &&
t.name === this._parent?.name
) {
this.status = ConnectionStatus.Active
this._terminal = undefined
setTimeout(() => {
Log.debug("Resetting closed instrument", LOGLOC)
this.reset().catch(() => {})
this.status = ConnectionStatus.Active
}, 500)
}
})
}, this)

Log.debug(`Connected to ${this._parent.name}`, LOGLOC)

Expand Down
12 changes: 11 additions & 1 deletion src/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ export class InactiveInstrumentList extends vscode.TreeItem {
}
}

/**
* A class used to indicate the start of the Ignored Instruments section of the instrument
* list. This class stores no data and is simply a sentinel.
*/
export class IgnoredInstruments extends vscode.TreeItem {
constructor() {
super("Ignored Instruments", vscode.TreeItemCollapsibleState.Collapsed)
}
}

/**
* Information describing an instrument that is either saved or discovered.
*/
Expand Down Expand Up @@ -139,7 +149,7 @@ export class Instrument extends vscode.TreeItem implements vscode.Disposable {
this.contextValue += "Reg"
}
this.contextValue += "Inactive"
this.contextValue += "Discovered"
this.saved = false
}
dispose() {
for (const c of this._connections) {
Expand Down
6 changes: 5 additions & 1 deletion src/instrumentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export class InstrumentProvider implements VscTdp, vscode.Disposable {
file: "instruments.ts",
func: "InstrumentTreeDataProvider.updateSaved()",
}
if (!instrument.saved) {
// If the instrument isn't listed as saved, we don't need to update the saved list
return
}

Log.debug(
`Updating saved instrument with sn ${instrument.info.serial_number}`,
Expand Down Expand Up @@ -529,11 +533,11 @@ export class InstrumentProvider implements VscTdp, vscode.Disposable {
resolve(this.instruments_discovered)
},
() => {
reject(new Error("RPC Instr List Fetch failed!"))
Log.error("RPC Instr List Fetch failed!", {
file: "instruments.ts",
func: "InstrumentProvider.getContent()",
})
reject(new Error("RPC Instr List Fetch failed!"))
},
)
//todo
Expand Down

0 comments on commit c32afa9

Please sign in to comment.