New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added additional documentation and example code snippet. #2156
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I very much appreciate the PR. There are a few changes that I would suggest, but thanks for taking on this effort 🙂
This kind of documentation should be added to the other file dialogs as fell (Save and Open) as they will be called with nil values as well.
dialog/folder.go
Outdated
// a := app.New() | ||
// w := a.NewWindow("example") | ||
// button := widget.NewButtonWithIcon("", theme.FolderIcon(), | ||
// func() { | ||
// dialog.ShowFolderOpen( | ||
// func (uri fyne.ListableURI, err error) { | ||
// // Cancel will pass a nil value. | ||
// if uri == nil || err != nil { | ||
// return | ||
// } | ||
// fmt.Println("URI", uri) | ||
// }, w) | ||
// } | ||
// ) | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really appreciate the effort, but you are not supposed to add code examples to the API docs in this way. See this link for an example https://blog.golang.org/examples on how it should be done for interactive examples.
However, we do have the fyne_demo
application so I don't know if we really should add this kind of example in (someone else will have to comment on that) because adding it to one function would mean that we open up the possibility of adding to much more functions in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interactive examples are normally able to be executed as a test and in the browser and I'm not sure how to get something like that to work in this case where it's rendering a GUI dialog box. That's why I just put in in a code snippet as an example similar to what Go's doc do for similar cases (e.g. https://golang.org/pkg/net/).
It's perfectly alright with me if this is not the right fit for the project so please feel free to reject the PR.
If the fyne_demo
has the illustrative snippet of code, my suggestion would be to add a direct reference to it somehow in the doc to make it easy to find. A demo app's source code (especially one as complete as the demo) isn't as easily navigable IMHO so help to get to the right part would help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fyne code can be rendered in the playground in theory, but there is a 5sec timeout that I am sure means we can’t get the app compiled (you could check out the tools/playground package though).
With WASM aiming for 2.1 this may get much better :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am nervous about adding code examples like this (i.e. entire applications) because it includes so much outside the scope of this function. Linking to the fyne_demo project could be a nice way to do it, though those links may go stale as well.
I liked what was done with the clarification in the paragraph of text above the example, but feel that large examples like this would be better placed in the tutorials at https://developer.fyne.io.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clarification of usage is a great addition, but let's not go down the path of what could be an application per-function
dialog/folder.go
Outdated
// a := app.New() | ||
// w := a.NewWindow("example") | ||
// button := widget.NewButtonWithIcon("", theme.FolderIcon(), | ||
// func() { | ||
// dialog.ShowFolderOpen( | ||
// func (uri fyne.ListableURI, err error) { | ||
// // Cancel will pass a nil value. | ||
// if uri == nil || err != nil { | ||
// return | ||
// } | ||
// fmt.Println("URI", uri) | ||
// }, w) | ||
// } | ||
// ) | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am nervous about adding code examples like this (i.e. entire applications) because it includes so much outside the scope of this function. Linking to the fyne_demo project could be a nice way to do it, though those links may go stale as well.
I liked what was done with the clarification in the paragraph of text above the example, but feel that large examples like this would be better placed in the tutorials at https://developer.fyne.io.
Co-authored-by: Jacob <Jacalz@users.noreply.github.com>
Bring fork up-to-date
dialog/folder.go
Outdated
// ShowFolderOpen creates and shows a file dialog allowing the user to choose a folder to open. | ||
// ShowFolderOpen creates and shows a file dialog allowing the user to choose a | ||
// folder to open. The callback function will run when the dialog closes. The | ||
// URI will be nil when nothing is selected or cancelled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest change made this slightly ambiguous sorry - "nothing is selected or cancelled".
I think "the user cancelled or nothing is selected" is clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @andydotxyz on the wording. Also please update the other file/folder dialogs with the same note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for this clarification
I'm so sorry that this dropped off my watch list. |
I think this is waiting for your re-review @Jacalz if you could check it out :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I had forgotten about this. I had a minor thing that I found when re-reviewing this. Please remove the double spaces 🙂
dialog/file.go
Outdated
// The dialog will appear over the window specified when Show() is called. | ||
func NewFileSave(callback func(fyne.URIWriteCloser, error), parent fyne.Window) *FileDialog { | ||
dialog := &FileDialog{callback: callback, parent: parent, save: true} | ||
return dialog | ||
} | ||
|
||
// ShowFileOpen creates and shows a file dialog allowing the user to choose a file to open. | ||
// ShowFileOpen creates and shows a file dialog allowing the user to choose a | ||
// file to open. The callback function will run when the dialog closes. The URI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// file to open. The callback function will run when the dialog closes. The URI | |
// file to open. The callback function will run when the dialog closes. The URI |
It's grammatically incorrect with double spaces. There are a few more places where this occurs but I just made one comment about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is actually a school of thinking that says double space is grammatically correct. However I agree that we have settled on single spacing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not know that. It is very, very forbidden in Swedish at least 😅
…ce standard instead of double space standard after periods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Sorry for the long wait, but I never got a request for a re-review.
Description:
Adding additional comment that the callback function is triggered for both Open and Cancel.
Fixes #(issue)
#2152
Checklist:
Where applicable: