diff --git a/ui/pages/requests/container.go b/ui/pages/requests/container.go index c89a192..12aec5b 100644 --- a/ui/pages/requests/container.go +++ b/ui/pages/requests/container.go @@ -27,8 +27,6 @@ type Container interface { type GrpcContainer interface { Container - SetOnProtoFileSelect(func(id string)) - SetProtoBodyFilePath(filePath string) SetOnReload(func(id string)) SetServices(services []domain.GRPCService) SetMethodsLoading(loading bool) diff --git a/ui/pages/requests/controller.go b/ui/pages/requests/controller.go index 6155de0..934dd6f 100644 --- a/ui/pages/requests/controller.go +++ b/ui/pages/requests/controller.go @@ -62,7 +62,6 @@ func NewController(view *View, repo repository.Repository, model *state.Requests view.SetOnSubmit(c.onSubmit) view.SetOnCopyResponse(c.onCopyResponse) view.SetOnBinaryFileSelect(c.onSelectBinaryFile) - view.SetOnProtoFileSelect(c.onProtoFileSelect) view.SetOnPostRequestSetChanged(c.onPostRequestSetChanged) view.SetOnFormDataFileSelect(c.onFormDataFileSelect) view.SetOnServerInfoReload(c.onServerInfoReload) @@ -185,22 +184,6 @@ func (c *Controller) onLoadRequestExample(id string) { c.view.SetSetGrpcRequestBody(id, example) } -func (c *Controller) onProtoFileSelect(id string) { - c.explorer.ChoseFile(func(result explorer.Result) { - if result.Error != nil { - c.view.ShowGRPCRequestError(id, "Error", result.Error.Error()) - return - } - c.view.HideGRPCRequestError(id) - - if result.FilePath == "" { - return - } - c.view.SetProtoFilePath(id, result.FilePath) - - }, ".proto") -} - func (c *Controller) onPostRequestSetChanged(id string, statusCode int, item, from, fromKey string) { req := c.model.GetRequest(id) if req == nil { diff --git a/ui/pages/requests/grpc/grpc.go b/ui/pages/requests/grpc/grpc.go index 3c317f5..fc093f0 100644 --- a/ui/pages/requests/grpc/grpc.go +++ b/ui/pages/requests/grpc/grpc.go @@ -192,19 +192,6 @@ func (r *Grpc) SetOnSetOnTriggerRequestChanged(f func(id, collectionID, requestI }) } -func (r *Grpc) SetOnProtoFileSelect(f func(id string)) { - r.Request.ServerInfo.FileSelector.SetOnSelectFile(func() { - f(r.Req.MetaData.ID) - }) -} - -func (r *Grpc) SetProtoBodyFilePath(filePath string) { - r.Request.ServerInfo.FileSelector.SetFileName(filePath) - if r.onDataChanged != nil { - r.onDataChanged(r.Req.MetaData.ID, r.Req) - } -} - func (r *Grpc) ShowRequestPrompt(title, content, modalType string, onSubmit func(selectedOption string, remember bool), options ...widgets.Option) { r.Request.Prompt.Type = modalType r.Request.Prompt.Title = title diff --git a/ui/pages/requests/grpc/server_info.go b/ui/pages/requests/grpc/server_info.go index 93c4496..752da31 100644 --- a/ui/pages/requests/grpc/server_info.go +++ b/ui/pages/requests/grpc/server_info.go @@ -33,7 +33,7 @@ func NewServerInfo(explorer *explorer.Explorer, info domain.ServerInfo) *ServerI s := &ServerInfo{ definitionFrom: new(widget.Enum), - FileSelector: widgets.NewFileSelector(fileName, explorer), + FileSelector: widgets.NewFileSelector(fileName, explorer, ".proto"), ReloadButton: new(widget.Clickable), IsLoading: false, } diff --git a/ui/pages/requests/view.go b/ui/pages/requests/view.go index 4f13b86..d2cb8f3 100644 --- a/ui/pages/requests/view.go +++ b/ui/pages/requests/view.go @@ -76,7 +76,6 @@ type View struct { onOnPostRequestSetChanged func(id string, statusCode int, item, from, fromKey string) onOnSetOnTriggerRequestChanged func(id, collectionID, requestID string) onBinaryFileSelect func(id string) - onProtoFileSelect func(id string) onFromDataFileSelect func(requestID, fieldID string) onServerInfoReload func(id string) onGrpcInvoke func(id string) @@ -256,10 +255,6 @@ func (v *View) SetOnBinaryFileSelect(f func(id string)) { v.onBinaryFileSelect = f } -func (v *View) SetOnProtoFileSelect(f func(id string)) { - v.onProtoFileSelect = f -} - func (v *View) SetOnServerInfoReload(f func(id string)) { v.onServerInfoReload = f } @@ -288,14 +283,6 @@ func (v *View) SetBinaryBodyFilePath(id, filePath string) { } } -func (v *View) SetProtoFilePath(id, filePath string) { - if ct, ok := v.containers.Get(id); ok { - if ct, ok := ct.(GrpcContainer); ok { - ct.SetProtoBodyFilePath(filePath) - } - } -} - func (v *View) SetGRPCServices(id string, services []domain.GRPCService) { if ct, ok := v.containers.Get(id); ok { if ct, ok := ct.(GrpcContainer); ok { @@ -512,12 +499,6 @@ func (v *View) createGrpcContainer(req *domain.Request) Container { } }) - ct.SetOnProtoFileSelect(func(id string) { - if v.onProtoFileSelect != nil { - v.onProtoFileSelect(id) - } - }) - ct.SetOnReload(func(id string) { if v.onServerInfoReload != nil { v.onServerInfoReload(id) diff --git a/ui/widgets/file_selector.go b/ui/widgets/file_selector.go index ea0312e..829f025 100644 --- a/ui/widgets/file_selector.go +++ b/ui/widgets/file_selector.go @@ -1,6 +1,7 @@ package widgets import ( + "errors" "fmt" "gioui.org/layout" @@ -50,7 +51,10 @@ func (b *FileSelector) handleExplorerSelect() { b.explorer.ChoseFile(func(result explorer.Result) { if result.Error != nil { - fmt.Println("failed to get file", result.Error) + if !errors.Is(result.Error, explorer.ErrUserDecline) { + fmt.Printf("failed to get file, %s\n", result.Error) + return + } return } if result.FilePath == "" { @@ -67,12 +71,11 @@ func (b *FileSelector) SetOnSelectFile(f func()) { b.textField.SetOnIconClick(func() { if b.FileName != "" { b.RemoveFile() - b.changed = true - b.onChangeCallback() return } else { // Select file f() + b.onChangeCallback() } }) }