1// Package gtk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gtk
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/gio"
12 "github.com/bnema/puregotk/v4/glib"
13 "github.com/bnema/puregotk/v4/gobject"
14 "github.com/bnema/puregotk/v4/gobject/types"
15)
16
17type FileChooserNativeClass struct {
18 _ structs.HostLayout
19
20 ParentClass NativeDialogClass
21}
22
23func (x *FileChooserNativeClass) GoPointer() uintptr {
24 return uintptr(unsafe.Pointer(x))
25}
26
27// `GtkFileChooserNative` is an abstraction of a dialog suitable
28// for use with “File Open” or “File Save as” commands.
29//
30// By default, this just uses a `GtkFileChooserDialog` to implement
31// the actual dialog. However, on some platforms, such as Windows and
32// macOS, the native platform file chooser is used instead. When the
33// application is running in a sandboxed environment without direct
34// filesystem access (such as Flatpak), `GtkFileChooserNative` may call
35// the proper APIs (portals) to let the user choose a file and make it
36// available to the application.
37//
38// While the API of `GtkFileChooserNative` closely mirrors `GtkFileChooserDialog`,
39// the main difference is that there is no access to any `GtkWindow` or `GtkWidget`
40// for the dialog. This is required, as there may not be one in the case of a
41// platform native dialog.
42//
43// Showing, hiding and running the dialog is handled by the
44// [class@Gtk.NativeDialog] functions.
45//
46// Note that unlike `GtkFileChooserDialog`, `GtkFileChooserNative` objects
47// are not toplevel widgets, and GTK does not keep them alive. It is your
48// responsibility to keep a reference until you are done with the
49// object.
50//
51// ## Typical usage
52//
53// In the simplest of cases, you can the following code to use
54// `GtkFileChooserNative` to select a file for opening:
55//
56// ```c
57// static void
58// on_response (GtkNativeDialog *native,
59//
60// int response)
61//
62// {
63// if (response == GTK_RESPONSE_ACCEPT)
64// {
65// GtkFileChooser *chooser = GTK_FILE_CHOOSER (native);
66// GFile *file = gtk_file_chooser_get_file (chooser);
67//
68// open_file (file);
69//
70// g_object_unref (file);
71// }
72//
73// g_object_unref (native);
74// }
75//
76// // ...
77// GtkFileChooserNative *native;
78// GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
79//
80// native = gtk_file_chooser_native_new ("Open File",
81// parent_window,
82// action,
83// "_Open",
84// "_Cancel");
85//
86// g_signal_connect (native, "response", G_CALLBACK (on_response), NULL);
87// gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
88//
89// ```
90//
91// To use a `GtkFileChooserNative` for saving, you can use this:
92//
93// ```c
94// static void
95// on_response (GtkNativeDialog *native,
96//
97// int response)
98//
99// {
100// if (response == GTK_RESPONSE_ACCEPT)
101// {
102// GtkFileChooser *chooser = GTK_FILE_CHOOSER (native);
103// GFile *file = gtk_file_chooser_get_file (chooser);
104//
105// save_to_file (file);
106//
107// g_object_unref (file);
108// }
109//
110// g_object_unref (native);
111// }
112//
113// // ...
114// GtkFileChooserNative *native;
115// GtkFileChooser *chooser;
116// GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
117//
118// native = gtk_file_chooser_native_new ("Save File",
119// parent_window,
120// action,
121// "_Save",
122// "_Cancel");
123// chooser = GTK_FILE_CHOOSER (native);
124//
125// if (user_edited_a_new_document)
126// gtk_file_chooser_set_current_name (chooser, _("Untitled document"));
127// else
128// gtk_file_chooser_set_file (chooser, existing_file, NULL);
129//
130// g_signal_connect (native, "response", G_CALLBACK (on_response), NULL);
131// gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
132//
133// ```
134//
135// For more information on how to best set up a file dialog,
136// see the [class@Gtk.FileChooserDialog] documentation.
137//
138// ## Response Codes
139//
140// `GtkFileChooserNative` inherits from [class@Gtk.NativeDialog],
141// which means it will return %GTK_RESPONSE_ACCEPT if the user accepted,
142// and %GTK_RESPONSE_CANCEL if he pressed cancel. It can also return
143// %GTK_RESPONSE_DELETE_EVENT if the window was unexpectedly closed.
144//
145// ## Differences from `GtkFileChooserDialog`
146//
147// There are a few things in the [iface@Gtk.FileChooser] interface that
148// are not possible to use with `GtkFileChooserNative`, as such use would
149// prohibit the use of a native dialog.
150//
151// No operations that change the dialog work while the dialog is visible.
152// Set all the properties that are required before showing the dialog.
153//
154// ## Win32 details
155//
156// On windows the `IFileDialog` implementation (added in Windows Vista) is
157// used. It supports many of the features that `GtkFileChooser` has, but
158// there are some things it does not handle:
159//
160// * Any [class@Gtk.FileFilter] added using a mimetype
161//
162// If any of these features are used the regular `GtkFileChooserDialog`
163// will be used in place of the native one.
164//
165// ## Portal details
166//
167// When the `org.freedesktop.portal.FileChooser` portal is available on
168// the session bus, it is used to bring up an out-of-process file chooser.
169// Depending on the kind of session the application is running in, this may
170// or may not be a GTK file chooser.
171//
172// ## macOS details
173//
174// On macOS the `NSSavePanel` and `NSOpenPanel` classes are used to provide
175// native file chooser dialogs. Some features provided by `GtkFileChooser`
176// are not supported:
177//
178// * Shortcut folders.
179type FileChooserNative struct {
180 NativeDialog
181}
182
183var xFileChooserNativeGLibType func() types.GType
184
185func FileChooserNativeGLibType() types.GType {
186 return xFileChooserNativeGLibType()
187}
188
189func FileChooserNativeNewFromInternalPtr(ptr uintptr) *FileChooserNative {
190 cls := &FileChooserNative{}
191 cls.Ptr = ptr
192 return cls
193}
194
195var xNewFileChooserNative func(uintptr, uintptr, FileChooserAction, uintptr, uintptr) uintptr
196
197// Creates a new `GtkFileChooserNative`.
198func NewFileChooserNative(TitleVar *string, ParentVar *Window, ActionVar FileChooserAction, AcceptLabelVar *string, CancelLabelVar *string) *FileChooserNative {
199 var cls *FileChooserNative
200
201 TitleVarPtr := core.GStrdupNullable(TitleVar)
202 defer core.GFreeNullable(TitleVarPtr)
203
204 AcceptLabelVarPtr := core.GStrdupNullable(AcceptLabelVar)
205 defer core.GFreeNullable(AcceptLabelVarPtr)
206
207 CancelLabelVarPtr := core.GStrdupNullable(CancelLabelVar)
208 defer core.GFreeNullable(CancelLabelVarPtr)
209
210 cret := xNewFileChooserNative(TitleVarPtr, ParentVar.GoPointer(), ActionVar, AcceptLabelVarPtr, CancelLabelVarPtr)
211
212 if cret == 0 {
213 return nil
214 }
215 cls = &FileChooserNative{}
216 cls.Ptr = cret
217 return cls
218}
219
220var xFileChooserNativeGetAcceptLabel func(uintptr) string
221
222// Retrieves the custom label text for the accept button.
223func (x *FileChooserNative) GetAcceptLabel() string {
224
225 cret := xFileChooserNativeGetAcceptLabel(x.GoPointer())
226 return cret
227}
228
229var xFileChooserNativeGetCancelLabel func(uintptr) string
230
231// Retrieves the custom label text for the cancel button.
232func (x *FileChooserNative) GetCancelLabel() string {
233
234 cret := xFileChooserNativeGetCancelLabel(x.GoPointer())
235 return cret
236}
237
238var xFileChooserNativeSetAcceptLabel func(uintptr, uintptr)
239
240// Sets the custom label text for the accept button.
241//
242// If characters in @label are preceded by an underscore, they are
243// underlined. If you need a literal underscore character in a label,
244// use “__” (two underscores). The first underlined character represents
245// a keyboard accelerator called a mnemonic.
246//
247// Pressing Alt and that key should activate the button.
248func (x *FileChooserNative) SetAcceptLabel(AcceptLabelVar *string) {
249
250 AcceptLabelVarPtr := core.GStrdupNullable(AcceptLabelVar)
251 defer core.GFreeNullable(AcceptLabelVarPtr)
252
253 xFileChooserNativeSetAcceptLabel(x.GoPointer(), AcceptLabelVarPtr)
254
255}
256
257var xFileChooserNativeSetCancelLabel func(uintptr, uintptr)
258
259// Sets the custom label text for the cancel button.
260//
261// If characters in @label are preceded by an underscore, they are
262// underlined. If you need a literal underscore character in a label,
263// use “__” (two underscores). The first underlined character represents
264// a keyboard accelerator called a mnemonic.
265//
266// Pressing Alt and that key should activate the button.
267func (x *FileChooserNative) SetCancelLabel(CancelLabelVar *string) {
268
269 CancelLabelVarPtr := core.GStrdupNullable(CancelLabelVar)
270 defer core.GFreeNullable(CancelLabelVarPtr)
271
272 xFileChooserNativeSetCancelLabel(x.GoPointer(), CancelLabelVarPtr)
273
274}
275
276func (c *FileChooserNative) GoPointer() uintptr {
277 if c == nil {
278 return 0
279 }
280 return c.Ptr
281}
282
283func (c *FileChooserNative) SetGoPointer(ptr uintptr) {
284 c.Ptr = ptr
285}
286
287// SetPropertyAcceptLabel sets the "accept-label" property.
288// The text used for the label on the accept button in the dialog, or
289// %NULL to use the default text.
290func (x *FileChooserNative) SetPropertyAcceptLabel(value string) {
291 var v gobject.Value
292 v.Init(gobject.TypeStringVal)
293 v.SetString(&value)
294 x.SetProperty("accept-label", &v)
295}
296
297// GetPropertyAcceptLabel gets the "accept-label" property.
298// The text used for the label on the accept button in the dialog, or
299// %NULL to use the default text.
300func (x *FileChooserNative) GetPropertyAcceptLabel() string {
301 var v gobject.Value
302 x.GetProperty("accept-label", &v)
303 return v.GetString()
304}
305
306// SetPropertyCancelLabel sets the "cancel-label" property.
307// The text used for the label on the cancel button in the dialog, or
308// %NULL to use the default text.
309func (x *FileChooserNative) SetPropertyCancelLabel(value string) {
310 var v gobject.Value
311 v.Init(gobject.TypeStringVal)
312 v.SetString(&value)
313 x.SetProperty("cancel-label", &v)
314}
315
316// GetPropertyCancelLabel gets the "cancel-label" property.
317// The text used for the label on the cancel button in the dialog, or
318// %NULL to use the default text.
319func (x *FileChooserNative) GetPropertyCancelLabel() string {
320 var v gobject.Value
321 x.GetProperty("cancel-label", &v)
322 return v.GetString()
323}
324
325// Adds a 'choice' to the file chooser.
326//
327// This is typically implemented as a combobox or, for boolean choices,
328// as a checkbutton. You can select a value using
329// [method@Gtk.FileChooser.set_choice] before the dialog is shown,
330// and you can obtain the user-selected value in the
331// [signal@Gtk.Dialog::response] signal handler using
332// [method@Gtk.FileChooser.get_choice].
333func (x *FileChooserNative) AddChoice(IdVar string, LabelVar string, OptionsVar []string, OptionLabelsVar []string) {
334
335 XGtkFileChooserAddChoice(x.GoPointer(), IdVar, LabelVar, OptionsVar, OptionLabelsVar)
336
337}
338
339// Adds @filter to the list of filters that the user can select between.
340//
341// When a filter is selected, only files that are passed by that
342// filter are displayed.
343//
344// Note that the @chooser takes ownership of the filter if it is floating,
345// so you have to ref and sink it if you want to keep a reference.
346func (x *FileChooserNative) AddFilter(FilterVar *FileFilter) {
347
348 XGtkFileChooserAddFilter(x.GoPointer(), FilterVar.GoPointer())
349
350}
351
352// Adds a folder to be displayed with the shortcut folders
353// in a file chooser.
354func (x *FileChooserNative) AddShortcutFolder(FolderVar gio.File) (bool, error) {
355 var cerr *glib.Error
356
357 cret := XGtkFileChooserAddShortcutFolder(x.GoPointer(), FolderVar.GoPointer(), &cerr)
358 if cerr == nil {
359 return cret, nil
360 }
361 return cret, cerr
362
363}
364
365// Gets the type of operation that the file chooser is performing.
366func (x *FileChooserNative) GetAction() FileChooserAction {
367
368 cret := XGtkFileChooserGetAction(x.GoPointer())
369 return cret
370}
371
372// Gets the currently selected option in the 'choice' with the given ID.
373func (x *FileChooserNative) GetChoice(IdVar string) string {
374
375 cret := XGtkFileChooserGetChoice(x.GoPointer(), IdVar)
376 return cret
377}
378
379// Gets whether file chooser will offer to create new folders.
380func (x *FileChooserNative) GetCreateFolders() bool {
381
382 cret := XGtkFileChooserGetCreateFolders(x.GoPointer())
383 return cret
384}
385
386// Gets the current folder of @chooser as `GFile`.
387func (x *FileChooserNative) GetCurrentFolder() *gio.FileBase {
388 var cls *gio.FileBase
389
390 cret := XGtkFileChooserGetCurrentFolder(x.GoPointer())
391
392 if cret == 0 {
393 return nil
394 }
395 cls = &gio.FileBase{}
396 cls.Ptr = cret
397 return cls
398}
399
400// Gets the current name in the file selector, as entered by the user.
401//
402// This is meant to be used in save dialogs, to get the currently typed
403// filename when the file itself does not exist yet.
404func (x *FileChooserNative) GetCurrentName() string {
405
406 cret := XGtkFileChooserGetCurrentName(x.GoPointer())
407 return cret
408}
409
410// Gets the `GFile` for the currently selected file in
411// the file selector.
412//
413// If multiple files are selected, one of the files will be
414// returned at random.
415//
416// If the file chooser is in folder mode, this function returns
417// the selected folder.
418func (x *FileChooserNative) GetFile() *gio.FileBase {
419 var cls *gio.FileBase
420
421 cret := XGtkFileChooserGetFile(x.GoPointer())
422
423 if cret == 0 {
424 return nil
425 }
426 cls = &gio.FileBase{}
427 cls.Ptr = cret
428 return cls
429}
430
431// Lists all the selected files and subfolders in the current folder
432// of @chooser as `GFile`.
433func (x *FileChooserNative) GetFiles() *gio.ListModelBase {
434 var cls *gio.ListModelBase
435
436 cret := XGtkFileChooserGetFiles(x.GoPointer())
437
438 if cret == 0 {
439 return nil
440 }
441 cls = &gio.ListModelBase{}
442 cls.Ptr = cret
443 return cls
444}
445
446// Gets the current filter.
447func (x *FileChooserNative) GetFilter() *FileFilter {
448 var cls *FileFilter
449
450 cret := XGtkFileChooserGetFilter(x.GoPointer())
451
452 if cret == 0 {
453 return nil
454 }
455 gobject.IncreaseRef(cret)
456 cls = &FileFilter{}
457 cls.Ptr = cret
458 return cls
459}
460
461// Gets the current set of user-selectable filters, as a list model.
462//
463// See [method@Gtk.FileChooser.add_filter] and
464// [method@Gtk.FileChooser.remove_filter] for changing individual filters.
465//
466// You should not modify the returned list model. Future changes to
467// @chooser may or may not affect the returned model.
468func (x *FileChooserNative) GetFilters() *gio.ListModelBase {
469 var cls *gio.ListModelBase
470
471 cret := XGtkFileChooserGetFilters(x.GoPointer())
472
473 if cret == 0 {
474 return nil
475 }
476 cls = &gio.ListModelBase{}
477 cls.Ptr = cret
478 return cls
479}
480
481// Gets whether multiple files can be selected in the file
482// chooser.
483func (x *FileChooserNative) GetSelectMultiple() bool {
484
485 cret := XGtkFileChooserGetSelectMultiple(x.GoPointer())
486 return cret
487}
488
489// Queries the list of shortcut folders in the file chooser.
490//
491// You should not modify the returned list model. Future changes to
492// @chooser may or may not affect the returned model.
493func (x *FileChooserNative) GetShortcutFolders() *gio.ListModelBase {
494 var cls *gio.ListModelBase
495
496 cret := XGtkFileChooserGetShortcutFolders(x.GoPointer())
497
498 if cret == 0 {
499 return nil
500 }
501 cls = &gio.ListModelBase{}
502 cls.Ptr = cret
503 return cls
504}
505
506// Removes a 'choice' that has been added with gtk_file_chooser_add_choice().
507func (x *FileChooserNative) RemoveChoice(IdVar string) {
508
509 XGtkFileChooserRemoveChoice(x.GoPointer(), IdVar)
510
511}
512
513// Removes @filter from the list of filters that the user can select between.
514func (x *FileChooserNative) RemoveFilter(FilterVar *FileFilter) {
515
516 XGtkFileChooserRemoveFilter(x.GoPointer(), FilterVar.GoPointer())
517
518}
519
520// Removes a folder from the shortcut folders in a file chooser.
521func (x *FileChooserNative) RemoveShortcutFolder(FolderVar gio.File) (bool, error) {
522 var cerr *glib.Error
523
524 cret := XGtkFileChooserRemoveShortcutFolder(x.GoPointer(), FolderVar.GoPointer(), &cerr)
525 if cerr == nil {
526 return cret, nil
527 }
528 return cret, cerr
529
530}
531
532// Sets the type of operation that the chooser is performing.
533//
534// The user interface is adapted to suit the selected action.
535//
536// For example, an option to create a new folder might be shown
537// if the action is %GTK_FILE_CHOOSER_ACTION_SAVE but not if the
538// action is %GTK_FILE_CHOOSER_ACTION_OPEN.
539func (x *FileChooserNative) SetAction(ActionVar FileChooserAction) {
540
541 XGtkFileChooserSetAction(x.GoPointer(), ActionVar)
542
543}
544
545// Selects an option in a 'choice' that has been added with
546// gtk_file_chooser_add_choice().
547//
548// For a boolean choice, the possible options are "true" and "false".
549func (x *FileChooserNative) SetChoice(IdVar string, OptionVar string) {
550
551 XGtkFileChooserSetChoice(x.GoPointer(), IdVar, OptionVar)
552
553}
554
555// Sets whether file chooser will offer to create new folders.
556//
557// This is only relevant if the action is not set to be
558// %GTK_FILE_CHOOSER_ACTION_OPEN.
559func (x *FileChooserNative) SetCreateFolders(CreateFoldersVar bool) {
560
561 XGtkFileChooserSetCreateFolders(x.GoPointer(), CreateFoldersVar)
562
563}
564
565// Sets the current folder for @chooser from a `GFile`.
566func (x *FileChooserNative) SetCurrentFolder(FileVar gio.File) (bool, error) {
567 var cerr *glib.Error
568
569 cret := XGtkFileChooserSetCurrentFolder(x.GoPointer(), FileVar.GoPointer(), &cerr)
570 if cerr == nil {
571 return cret, nil
572 }
573 return cret, cerr
574
575}
576
577// Sets the current name in the file selector, as if entered
578// by the user.
579//
580// Note that the name passed in here is a UTF-8 string rather
581// than a filename. This function is meant for such uses as a
582// suggested name in a “Save As...” dialog. You can pass
583// “Untitled.doc” or a similarly suitable suggestion for the @name.
584//
585// If you want to preselect a particular existing file, you should
586// use [method@Gtk.FileChooser.set_file] instead.
587//
588// Please see the documentation for those functions for an example
589// of using [method@Gtk.FileChooser.set_current_name] as well.
590func (x *FileChooserNative) SetCurrentName(NameVar string) {
591
592 XGtkFileChooserSetCurrentName(x.GoPointer(), NameVar)
593
594}
595
596// Sets @file as the current filename for the file chooser.
597//
598// This includes changing to the file’s parent folder and actually selecting
599// the file in list. If the @chooser is in %GTK_FILE_CHOOSER_ACTION_SAVE mode,
600// the file’s base name will also appear in the dialog’s file name entry.
601//
602// If the file name isn’t in the current folder of @chooser, then the current
603// folder of @chooser will be changed to the folder containing @file.
604//
605// Note that the file must exist, or nothing will be done except
606// for the directory change.
607//
608// If you are implementing a save dialog, you should use this function if
609// you already have a file name to which the user may save; for example,
610// when the user opens an existing file and then does “Save As…”. If you
611// don’t have a file name already — for example, if the user just created
612// a new file and is saving it for the first time, do not call this function.
613//
614// Instead, use something similar to this:
615//
616// ```c
617// static void
618// prepare_file_chooser (GtkFileChooser *chooser,
619//
620// GFile *existing_file)
621//
622// {
623// gboolean document_is_new = (existing_file == NULL);
624//
625// if (document_is_new)
626// {
627// GFile *default_file_for_saving = g_file_new_for_path ("./out.txt");
628// // the user just created a new document
629// gtk_file_chooser_set_current_folder (chooser, default_file_for_saving, NULL);
630// gtk_file_chooser_set_current_name (chooser, "Untitled document");
631// g_object_unref (default_file_for_saving);
632// }
633// else
634// {
635// // the user edited an existing document
636// gtk_file_chooser_set_file (chooser, existing_file, NULL);
637// }
638// }
639//
640// ```
641func (x *FileChooserNative) SetFile(FileVar gio.File) (bool, error) {
642 var cerr *glib.Error
643
644 cret := XGtkFileChooserSetFile(x.GoPointer(), FileVar.GoPointer(), &cerr)
645 if cerr == nil {
646 return cret, nil
647 }
648 return cret, cerr
649
650}
651
652// Sets the current filter.
653//
654// Only the files that pass the filter will be displayed.
655// If the user-selectable list of filters is non-empty, then
656// the filter should be one of the filters in that list.
657//
658// Setting the current filter when the list of filters is
659// empty is useful if you want to restrict the displayed
660// set of files without letting the user change it.
661func (x *FileChooserNative) SetFilter(FilterVar *FileFilter) {
662
663 XGtkFileChooserSetFilter(x.GoPointer(), FilterVar.GoPointer())
664
665}
666
667// Sets whether multiple files can be selected in the file chooser.
668//
669// This is only relevant if the action is set to be
670// %GTK_FILE_CHOOSER_ACTION_OPEN or
671// %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
672func (x *FileChooserNative) SetSelectMultiple(SelectMultipleVar bool) {
673
674 XGtkFileChooserSetSelectMultiple(x.GoPointer(), SelectMultipleVar)
675
676}
677
678func init() {
679 core.SetPackageName("GTK", "gtk4")
680 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
681 var libs []uintptr
682 for _, libPath := range core.GetPaths("GTK") {
683 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
684 if err != nil {
685 panic(err)
686 }
687 libs = append(libs, lib)
688 }
689
690 core.PuregoSafeRegister(&xFileChooserNativeGLibType, libs, "gtk_file_chooser_native_get_type")
691
692 core.PuregoSafeRegister(&xNewFileChooserNative, libs, "gtk_file_chooser_native_new")
693
694 core.PuregoSafeRegister(&xFileChooserNativeGetAcceptLabel, libs, "gtk_file_chooser_native_get_accept_label")
695 core.PuregoSafeRegister(&xFileChooserNativeGetCancelLabel, libs, "gtk_file_chooser_native_get_cancel_label")
696 core.PuregoSafeRegister(&xFileChooserNativeSetAcceptLabel, libs, "gtk_file_chooser_native_set_accept_label")
697 core.PuregoSafeRegister(&xFileChooserNativeSetCancelLabel, libs, "gtk_file_chooser_native_set_cancel_label")
698
699}