Skip to content

Commit

Permalink
refactor: Port preferences to dialog from window
Browse files Browse the repository at this point in the history
Signed-off-by: Felicitas Pojtinger <[email protected]>
  • Loading branch information
pojntfx committed Jul 18, 2024
1 parent abfb1b4 commit c9c24b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions internal/components/assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -747,7 +747,7 @@ func OpenAssistantWindow(
mpvManualConfigurationButton.ConnectClicked(func() {
warningDialog.Close()

preferencesWindow.SetVisible(true)
preferencesDialog.Present(&window.Window)
mpvCommandInput.GrabFocus()
})

Expand Down
20 changes: 7 additions & 13 deletions internal/components/main_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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{`<Primary>comma`})
window.AddAction(preferencesAction)
Expand All @@ -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()

Expand All @@ -96,8 +92,6 @@ func AddMainMenu(
}

preferencesHaveChanged = false

return ok
})

syncSensitivityState := func() {
Expand All @@ -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) {
Expand Down Expand Up @@ -145,7 +139,7 @@ func AddMainMenu(
storageLocationInput.ConnectClicked(func() {
filePicker := gtk.NewFileChooserNative(
"Select storage location",
&preferencesWindow.Window.Window,
&window.Window,
gtk.FileChooserActionSelectFolder,
"",
"")
Expand Down Expand Up @@ -234,5 +228,5 @@ func AddMainMenu(

menuButton.SetMenuModel(menu)

return preferencesWindow, mpvCommandInput
return preferencesDialog, mpvCommandInput
}
4 changes: 1 addition & 3 deletions internal/resources/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
<requires lib="libadwaita" version="1.5" />
<requires lib="gtk" version="4.0" />

<object class="AdwPreferencesWindow" id="preferences-window">
<property name="modal">true</property>

<object class="AdwPreferencesDialog" id="preferences-dialog">
<child>
<object class="AdwPreferencesPage">
<property name="title" translatable="yes">Playback</property>
Expand Down

0 comments on commit c9c24b5

Please sign in to comment.