diff options
author | Michael J Mulligan <mike@belineperspectives.com> | 2021-03-22 15:13:30 +0300 |
---|---|---|
committer | Michael J Mulligan <mike@belineperspectives.com> | 2021-03-22 15:13:30 +0300 |
commit | 7abd0178ede0cc7d413b4e1433d2c0c3b817a7ea (patch) | |
tree | 9293538d7c6f8b0458c97c51f9f38e3d7d7904dd | |
parent | 88015ff857f1d6e99fdeb8db907df28292f82e11 (diff) |
Method names are hard. ;-)
-rwxr-xr-x | ui/FilesPanel.go | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/ui/FilesPanel.go b/ui/FilesPanel.go index 592b226..ac97b0f 100755 --- a/ui/FilesPanel.go +++ b/ui/FilesPanel.go @@ -95,23 +95,28 @@ func (this *filesPanel) createBackButton() *gtk.Button { func (this *filesPanel) doLoadFiles() { utils.EmptyTheContainer(&this.listBox.Container) - if this.isRoot() { - if this.sdReady() { - this.addRootLocations() - } else { - this.locationHistory = utils.LocationHistory { - Locations: []dataModels.Location{dataModels.Local}, - } + atRootLevel := this.displayRootLocations() + /** + * If we are at `root` (display the option for SD AND Local), but SD is not + * ready, push us up and into Local so the user doesn't have to work harder + * than they have to. + */ + if atRootLevel && !this.sdIsReady() { + atRootLevel = false + this.locationHistory = utils.LocationHistory { + Locations: []dataModels.Location{dataModels.Local}, } } - if !this.isRoot() { + if atRootLevel { + this.addRootLocations() + } else { sortedFiles := this.getSortedFiles() this.addSortedFiles(sortedFiles) } this.listBox.ShowAll() } -func (this *filesPanel) sdReady() bool { +func (this *filesPanel) sdIsReady() bool { err := (&octoprintApis.SdRefreshRequest {}).Do(this.UI.Client) if err == nil { sdState, err := (&octoprintApis.SdStateRequest {}).Do(this.UI.Client) @@ -126,11 +131,11 @@ func (this *filesPanel) sdReady() bool { } func (this *filesPanel) goBack() { - if this.isRoot() { + if this.displayRootLocations() { this.UI.GoToPreviousPanel() } else if this.locationHistory.IsRoot() { this.locationHistory.GoBack() - if this.sdReady() { + if this.sdIsReady() { this.doLoadFiles() } else { this.UI.GoToPreviousPanel() @@ -141,7 +146,7 @@ func (this *filesPanel) goBack() { } } -func (this *filesPanel) isRoot() bool { +func (this *filesPanel) displayRootLocations() bool { if this.locationHistory.Length() < 1 { return true } else { @@ -152,7 +157,7 @@ func (this *filesPanel) isRoot() bool { func (this *filesPanel) getSortedFiles() []*dataModels.FileResponse { var files []*dataModels.FileResponse - if this.isRoot() { + if this.displayRootLocations() { return nil } |