From c9c24b567dd51d6ac9abc737bce97192bf2a8855 Mon Sep 17 00:00:00 2001 From: Felicitas Pojtinger Date: Wed, 17 Jul 2024 21:37:56 -0400 Subject: [PATCH] refactor: Port preferences to dialog from window Signed-off-by: Felicitas Pojtinger --- internal/components/assistant.go | 4 ++-- internal/components/main_menu.go | 20 +++++++------------- internal/resources/preferences.ui | 4 +--- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/internal/components/assistant.go b/internal/components/assistant.go index a156963..ddf0d7c 100644 --- a/internal/components/assistant.go +++ b/internal/components/assistant.go @@ -539,7 +539,7 @@ func OpenAssistantWindow( nextButton.ConnectClicked(onNext) previousButton.ConnectClicked(onPrevious) - preferencesWindow, mpvCommandInput := AddMainMenu(ctx, app, window, settings, menuButton, overlay, gateway, nil, cancel) + preferencesDialog, mpvCommandInput := AddMainMenu(ctx, app, window, settings, menuButton, overlay, gateway, nil, cancel) mediaInfoButton.ConnectClicked(func() { descriptionWindow.SetVisible(true) @@ -747,7 +747,7 @@ func OpenAssistantWindow( mpvManualConfigurationButton.ConnectClicked(func() { warningDialog.Close() - preferencesWindow.SetVisible(true) + preferencesDialog.Present(&window.Window) mpvCommandInput.GrabFocus() }) diff --git a/internal/components/main_menu.go b/internal/components/main_menu.go index 50938b2..645f5bc 100644 --- a/internal/components/main_menu.go +++ b/internal/components/main_menu.go @@ -27,7 +27,7 @@ func AddMainMenu( gateway *server.Gateway, getMagnetLink func() string, cancel func(), -) (*adw.PreferencesWindow, *gtk.Entry) { +) (*adw.PreferencesDialog, *gtk.Entry) { menuBuilder := gtk.NewBuilderFromResource(resources.GResourceMenuPath) menu := menuBuilder.GetObject("main-menu").Cast().(*gio.Menu) @@ -37,7 +37,7 @@ func AddMainMenu( aboutDialog.SetCopyright("© 2024 Felicitas Pojtinger") preferencesBuilder := gtk.NewBuilderFromResource(resources.GResourcePreferencesPath) - preferencesWindow := preferencesBuilder.GetObject("preferences-window").Cast().(*adw.PreferencesWindow) + preferencesDialog := preferencesBuilder.GetObject("preferences-dialog").Cast().(*adw.PreferencesDialog) storageLocationInput := preferencesBuilder.GetObject("storage-location-input").Cast().(*gtk.Button) mpvCommandInput := preferencesBuilder.GetObject("mpv-command-input").Cast().(*gtk.Entry) verbosityLevelInput := preferencesBuilder.GetObject("verbosity-level-input").Cast().(*gtk.SpinButton) @@ -57,7 +57,7 @@ func AddMainMenu( preferencesAction := gio.NewSimpleAction(preferencesActionName, nil) preferencesAction.ConnectActivate(func(parameter *glib.Variant) { - preferencesWindow.SetVisible(true) + preferencesDialog.Present(&window.Window) }) app.SetAccelsForAction("win."+preferencesActionName, []string{`comma`}) window.AddAction(preferencesAction) @@ -80,11 +80,7 @@ func AddMainMenu( window.AddAction(copyMagnetLinkAction) } - preferencesWindow.SetTransientFor(&window.Window) - preferencesWindow.ConnectCloseRequest(func() (ok bool) { - preferencesWindow.Close() - preferencesWindow.SetVisible(false) - + preferencesDialog.ConnectHide(func() { if preferencesHaveChanged { settings.Apply() @@ -96,8 +92,6 @@ func AddMainMenu( } preferencesHaveChanged = false - - return ok }) syncSensitivityState := func() { @@ -111,7 +105,7 @@ func AddMainMenu( remoteGatewayPasswordRow.SetSensitive(false) } } - preferencesWindow.ConnectShow(syncSensitivityState) + preferencesDialog.ConnectShow(syncSensitivityState) applyPreferencesAction := gio.NewSimpleAction(applyPreferencesActionName, nil) applyPreferencesAction.ConnectActivate(func(parameter *glib.Variant) { @@ -145,7 +139,7 @@ func AddMainMenu( storageLocationInput.ConnectClicked(func() { filePicker := gtk.NewFileChooserNative( "Select storage location", - &preferencesWindow.Window.Window, + &window.Window, gtk.FileChooserActionSelectFolder, "", "") @@ -234,5 +228,5 @@ func AddMainMenu( menuButton.SetMenuModel(menu) - return preferencesWindow, mpvCommandInput + return preferencesDialog, mpvCommandInput } diff --git a/internal/resources/preferences.ui b/internal/resources/preferences.ui index c1a5af3..65c365b 100644 --- a/internal/resources/preferences.ui +++ b/internal/resources/preferences.ui @@ -3,9 +3,7 @@ - - true - + Playback