[v2] Dialog fixes

This commit is contained in:
Lea Anthony
2021-06-26 18:20:24 +10:00
parent 695f78861d
commit 509c70a97c
5 changed files with 12 additions and 39 deletions

View File

@@ -12,7 +12,7 @@ require (
github.com/leaanthony/clir v1.0.4
github.com/leaanthony/debme v1.2.1
github.com/leaanthony/go-ansi-parser v1.0.1
github.com/leaanthony/go-common-file-dialog v1.0.2
github.com/leaanthony/go-common-file-dialog v1.0.3
github.com/leaanthony/gosod v1.0.1
github.com/leaanthony/slicer v1.5.0
github.com/leaanthony/webview2runtime v1.1.0

View File

@@ -50,8 +50,8 @@ github.com/leaanthony/debme v1.2.1 h1:9Tgwf+kjcrbMQ4WnPcEIUcQuIZYqdWftzZkBr+i/oO
github.com/leaanthony/debme v1.2.1/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA=
github.com/leaanthony/go-ansi-parser v1.0.1 h1:97v6c5kYppVsbScf4r/VZdXyQ21KQIfeQOk2DgKxGG4=
github.com/leaanthony/go-ansi-parser v1.0.1/go.mod h1:7arTzgVI47srICYhvgUV4CGd063sGEeoSlych5yeSPM=
github.com/leaanthony/go-common-file-dialog v1.0.2 h1:uJ2zXCxP4GwbpR/k/y6unuNbSJn3WTjt4rvHolX3Eys=
github.com/leaanthony/go-common-file-dialog v1.0.2/go.mod h1:TGhEc9eSJgRsupZ+iH1ZgAOnEo9zp05cRH2j08RPrF0=
github.com/leaanthony/go-common-file-dialog v1.0.3 h1:O0uGjKnWtdEADGrkg+TyAAbZylykMwwx/MNEXn9fp+Y=
github.com/leaanthony/go-common-file-dialog v1.0.3/go.mod h1:TGhEc9eSJgRsupZ+iH1ZgAOnEo9zp05cRH2j08RPrF0=
github.com/leaanthony/gosod v1.0.1 h1:F+4c3DmEBfigi7oAswCV2RpQ+k4DcNbhuCZUGdBHacQ=
github.com/leaanthony/gosod v1.0.1/go.mod h1:W8RyeSFBXu7RpIxPGEJfW4moSyGGEjlJMLV25wEbAdU=
github.com/leaanthony/slicer v1.5.0 h1:aHYTN8xbCCLxJmkNKiLB6tgcMARl4eWmH9/F+S/0HtY=

View File

@@ -139,10 +139,6 @@ func convertFilters(filters []dialog.FileFilter) []cfd.FileFilter {
return result
}
func userCancelled(err error) bool {
return err.Error() == "cancelled by user"
}
// OpenFileDialog will open a dialog with the given title and filter
func (c *Client) OpenFileDialog(options *dialog.OpenDialog, callbackID string) {
config := cfd.DialogConfig{
@@ -162,16 +158,11 @@ func (c *Client) OpenFileDialog(options *dialog.OpenDialog, callbackID string) {
}
}(thisdialog)
result, err := thisdialog.ShowAndGetResult()
if err != nil && !userCancelled(err) {
if err != nil && err != cfd.ErrorCancelled {
log.Fatal(err)
}
resultJSON, err := json.Marshal([]string{result})
if err != nil {
log.Fatal(err)
}
dispatcher.DispatchMessage("DO" + callbackID + "|" + string(resultJSON))
dispatcher.DispatchMessage("DO" + callbackID + "|" + result)
}
// OpenDirectoryDialog will open a dialog with the given title and filter
@@ -193,11 +184,10 @@ func (c *Client) OpenDirectoryDialog(dialogOptions *dialog.OpenDialog, callbackI
}
}(thisDialog)
result, err := thisDialog.ShowAndGetResult()
if err != nil && !userCancelled(err) {
if err != nil && err != cfd.ErrorCancelled {
log.Fatal(err)
}
resultJSON, err := json.Marshal(result)
dispatcher.DispatchMessage("DD" + callbackID + "|" + string(resultJSON))
dispatcher.DispatchMessage("DD" + callbackID + "|" + result)
}
// OpenMultipleFilesDialog will open a dialog with the given title and filter
@@ -221,7 +211,7 @@ func (c *Client) OpenMultipleFilesDialog(dialogOptions *dialog.OpenDialog, callb
}
}(thisdialog)
result, err := thisdialog.ShowAndGetResults()
if err != nil && !userCancelled(err) {
if err != nil && err != cfd.ErrorCancelled {
log.Fatal(err)
}
resultJSON, err := json.Marshal(result)
@@ -249,7 +239,7 @@ func (c *Client) SaveDialog(dialogOptions *dialog.SaveDialog, callbackID string)
log.Fatal(err)
}
result, err := saveDialog.GetResult()
if err != nil && !userCancelled(err) {
if err != nil && err != cfd.ErrorCancelled {
log.Fatal(err)
}
dispatcher.DispatchMessage("DS" + callbackID + "|" + result)

View File

@@ -32,21 +32,11 @@ func dialogMessageParser(message string) (*parsedMessage, error) {
switch dialogType {
case 'O':
var data string
topic = "dialog:openselected:" + callbackID
err := json.Unmarshal([]byte(payloadData), &data)
if err != nil {
return nil, err
}
responseMessage = &parsedMessage{Topic: topic, Data: data}
responseMessage = &parsedMessage{Topic: topic, Data: payloadData}
case 'D':
var data string
topic = "dialog:opendirectoryselected:" + callbackID
err := json.Unmarshal([]byte(payloadData), &data)
if err != nil {
return nil, err
}
responseMessage = &parsedMessage{Topic: topic, Data: data}
responseMessage = &parsedMessage{Topic: topic, Data: payloadData}
case '*':
var data []string
topic = "dialog:openmultipleselected:" + callbackID

View File

@@ -29,7 +29,6 @@ func newDialog(bus *servicebus.ServiceBus) Dialog {
}
}
// processTitleAndFilter return the title and filter from the given params.
// title is the first string, filter is the second
func (r *dialog) processTitleAndFilter(params ...string) (string, string) {
@@ -94,13 +93,7 @@ func (r *dialog) OpenFile(dialogOptions *dialogoptions.OpenDialog) (string, erro
// Delete subscription to response topic
r.bus.UnSubscribe(responseTopic)
files := result.Data().([]string)
res := ""
if len(files) > 0 {
res = files[0]
}
return res, nil
return result.Data().(string), nil
}
// OpenMultipleFiles prompts the user to select a file