Skip to content

Commit

Permalink
Get choices working in the file choosers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Mar 20, 2024
1 parent 6fc2da2 commit fab70c9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
18 changes: 18 additions & 0 deletions filechooser/choices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package filechooser

// ComboBox represents a serialized combo box that can be added to the dialog.
// None of the strings, except for the initial selection, should be empty.
// As a special case, passing an empty array for the list of choices indicates
// a boolean choice that is typically displayed as a check button, using “true” and “false” as the choices.
type ComboBox struct {
ID string // An ID that will be returned with the response.
Label string // A user-visible label.
Choices []Choice // The list of choices.
InitialSelection string // Default selection of choice. Leave empty to let the portal decide.
}

// Choice represent a choice that can be made in a ComboBox.
type Choice struct {
ID string // An ID that will be returned with the response.
Label string // A user-visible label.
}
21 changes: 13 additions & 8 deletions filechooser/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ const openFileCallName = fileChooserCallName + ".OpenFile"

// OpenFileOptions contains the options for how files are to be selected.
type OpenFileOptions struct {
HandleToken string // A string that will be used as the last element of the handle. Must be a valid object path element.
AcceptLabel string // Label for the accept button. Mnemonic underlines are allowed.
NotModal bool // Whether the dialog should not be modal.
Multiple bool // Whether multiple files can be selected or not.
Directory bool // Whether to select for folders instead of files.
Filters []*Filter // Each item specifies a single filter to offer to the user.
CurrentFilter *Filter // Request that this filter be set by default at dialog creation.
CurrentFolder string // Suggested folder from which the files should be opened.
HandleToken string // A string that will be used as the last element of the handle. Must be a valid object path element.
AcceptLabel string // Label for the accept button. Mnemonic underlines are allowed.
NotModal bool // Whether the dialog should not be modal.
Multiple bool // Whether multiple files can be selected or not.
Directory bool // Whether to select for folders instead of files.
Filters []*Filter // Each item specifies a single filter to offer to the user.
CurrentFilter *Filter // Request that this filter be set by default at dialog creation.
Choices []*ComboBox // List of serialized combo boxes to add to the file chooser.
CurrentFolder string // Suggested folder from which the files should be opened.
}

// OpenFile opens a filechooser for selecting a file to open.
Expand Down Expand Up @@ -53,6 +54,10 @@ func OpenFile(parentWindow, title string, options *OpenFileOptions) ([]string, e
data["current_filter"] = dbus.MakeVariant(options.CurrentFilter)
}

if len(options.Choices) > 0 {
data["choices"] = dbus.MakeVariant(options.Choices)
}

if options.CurrentFolder != "" {
data["current_folder"] = convert.ToNullTerminated(options.CurrentFolder)
}
Expand Down
36 changes: 23 additions & 13 deletions filechooser/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ const (

// SaveFileOptions contains the options for how a file is saved.
type SaveFileOptions struct {
HandleToken string // A string that will be used as the last element of the handle. Must be a valid object path element.
AcceptLabel string // Label for the accept button. Mnemonic underlines are allowed.
NotModal bool // Whether the dialog should not be modal.
Filters []Filter // Each item specifies a single filter to offer to the user.
CurrentFilter *Filter // Request that this filter be set by default at dialog creation.
CurrentName string // Suggested name of the file.
CurrentFolder string // Suggested folder in which the file should be saved.
HandleToken string // A string that will be used as the last element of the handle. Must be a valid object path element.
AcceptLabel string // Label for the accept button. Mnemonic underlines are allowed.
NotModal bool // Whether the dialog should not be modal.
Filters []*Filter // Each item specifies a single filter to offer to the user.
CurrentFilter *Filter // Request that this filter be set by default at dialog creation.
Choices []*ComboBox // List of serialized combo boxes to add to the file chooser.
CurrentFolder string // Suggested folder in which the file should be saved.
CurrentName string // Suggested name of the file.
}

// SaveFile opens a filechooser for selecting where to save a file.
Expand Down Expand Up @@ -53,6 +54,10 @@ func SaveFile(parentWindow, title string, options *SaveFileOptions) ([]string, e
data["current_filter"] = dbus.MakeVariant(options.CurrentFilter)
}

if len(options.Choices) > 0 {
data["choices"] = dbus.MakeVariant(options.Choices)
}

if options.CurrentName != "" {
data["current_name"] = convert.FromString(options.CurrentName)
}
Expand All @@ -73,12 +78,13 @@ func SaveFile(parentWindow, title string, options *SaveFileOptions) ([]string, e

// SaveFilesOptions contains the options for how files are saved.
type SaveFilesOptions struct {
HandleToken string // A string that will be used as the last element of the handle. Must be a valid object path element.
AcceptLabel string // Label for the accept button. Mnemonic underlines are allowed.
NotModal bool // Whether the dialog should be modal.
Filters []Filter // Each item specifies a single filter to offer to the user.
CurrentFilter *Filter // Request that this filter be set by default at dialog creation.
CurrentFolder string // Suggested folder in which the file should be saved.
HandleToken string // A string that will be used as the last element of the handle. Must be a valid object path element.
AcceptLabel string // Label for the accept button. Mnemonic underlines are allowed.
NotModal bool // Whether the dialog should be modal.
Filters []*Filter // Each item specifies a single filter to offer to the user.
CurrentFilter *Filter // Request that this filter be set by default at dialog creation.
Choices []*ComboBox // List of serialized combo boxes to add to the file chooser.
CurrentFolder string // Suggested folder in which the file should be saved.
}

// SaveFiles opens a filechooser for selecting where to save one or more files.
Expand Down Expand Up @@ -112,6 +118,10 @@ func SaveFiles(parentWindow, title string, options *SaveFilesOptions) ([]string,
data["current_filter"] = dbus.MakeVariant(options.CurrentFilter)
}

if len(options.Choices) > 0 {
data["choices"] = dbus.MakeVariant(options.Choices)
}

if options.CurrentFolder != "" {
data["current_folder"] = convert.ToNullTerminated(options.CurrentFolder)
}
Expand Down

0 comments on commit fab70c9

Please sign in to comment.