Skip to content
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

Merged
merged 9 commits into from May 22, 2021

Conversation

lazyhacker
Copy link
Contributor

Description:

Adding additional comment that the callback function is triggered for both Open and Cancel.

Fixes #(issue)

#2152

Checklist:

  • Tests included.
  • [X ] Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

Copy link
Member

@Jacalz Jacalz left a 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
Comment on lines 28 to 42
// 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)
// }
// )
//
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 :)

Copy link
Member

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.

dialog/folder.go Outdated Show resolved Hide resolved
Copy link
Member

@andydotxyz andydotxyz left a 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 Show resolved Hide resolved
dialog/folder.go Outdated
Comment on lines 28 to 42
// 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)
// }
// )
//
Copy link
Member

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.

lazyhacker and others added 3 commits April 21, 2021 10:17
Co-authored-by: Jacob <Jacalz@users.noreply.github.com>
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.
Copy link
Member

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.

Copy link
Member

@Jacalz Jacalz left a 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.

andydotxyz
andydotxyz previously approved these changes Apr 26, 2021
Copy link
Member

@andydotxyz andydotxyz left a 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

@andydotxyz
Copy link
Member

I'm so sorry that this dropped off my watch list.
It seems that GitHub stopped auto-running CI for new contributors and so I didn't get the usual notifications.

@andydotxyz
Copy link
Member

I think this is waiting for your re-review @Jacalz if you could check it out :)

Copy link
Member

@Jacalz Jacalz left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.

Copy link
Member

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.

Copy link
Member

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 😅

Copy link
Member

@Jacalz Jacalz left a 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.

@andydotxyz andydotxyz merged commit 8864cb4 into fyne-io:develop May 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants