Skip to content

Commit

Permalink
misc: port PreferencesWindow to AdwPrefencesDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaDve committed Feb 8, 2024
1 parent 77b87be commit eae389f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion data/resources/resources.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<file compressed="true" preprocess="xml-stripblanks">ui/information-row.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/inspector-page.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/playback-button.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/preferences-window.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/preferences-dialog.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/recognized-page.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/recognized-page-tile.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/recognizer-status.ui</file>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="MsaiPreferencesWindow" parent="AdwPreferencesWindow">
<template class="MsaiPreferencesDialog" parent="AdwPreferencesDialog">
<child>
<object class="AdwPreferencesPage">
<child>
Expand Down
11 changes: 7 additions & 4 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
database::{self, EnvExt, Migrations},
database_error_window::DatabaseErrorWindow,
inspector_page::InspectorPage,
preferences_window::PreferencesWindow,
preferences_dialog::PreferencesDialog,
recognizer::Recordings,
settings::Settings,
song_list::SongList,
Expand Down Expand Up @@ -216,9 +216,12 @@ impl Application {
.build();
let show_preferences_action = gio::ActionEntry::builder("show-preferences")
.activate(|obj: &Self, _, _| {
let window = PreferencesWindow::new(obj.settings());
window.set_transient_for(obj.window().as_ref());
window.present();
if let Some(window) = obj.window() {
let dialog = PreferencesDialog::new(obj.settings());
dialog.present(&window);
} else {
tracing::warn!("Can't present preferences dialog without an active window");
}
})
.build();
let show_about_action = gio::ActionEntry::builder("show-about")
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mod external_links;
mod i18n;
mod inspector_page;
mod player;
mod preferences_window;
mod preferences_dialog;
mod recognizer;
mod serde_helpers;
mod settings;
Expand Down
29 changes: 14 additions & 15 deletions src/preferences_window.rs → src/preferences_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ mod imp {
use super::*;

#[derive(Default, glib::Properties, gtk::CompositeTemplate)]
#[properties(wrapper_type = super::PreferencesWindow)]
#[template(resource = "/io/github/seadve/Mousai/ui/preferences-window.ui")]
pub struct PreferencesWindow {
#[properties(wrapper_type = super::PreferencesDialog)]
#[template(resource = "/io/github/seadve/Mousai/ui/preferences-dialog.ui")]
pub struct PreferencesDialog {
#[property(get, set, construct_only)]
pub(super) settings: OnceCell<Settings>,

Expand All @@ -40,10 +40,10 @@ mod imp {
}

#[glib::object_subclass]
impl ObjectSubclass for PreferencesWindow {
const NAME: &'static str = "MsaiPreferencesWindow";
type Type = super::PreferencesWindow;
type ParentType = adw::PreferencesWindow;
impl ObjectSubclass for PreferencesDialog {
const NAME: &'static str = "MsaiPreferencesDialog";
type Type = super::PreferencesDialog;
type ParentType = adw::PreferencesDialog;

fn class_init(klass: &mut Self::Class) {
klass.bind_template();
Expand All @@ -55,7 +55,7 @@ mod imp {
}

#[glib::derived_properties]
impl ObjectImpl for PreferencesWindow {
impl ObjectImpl for PreferencesDialog {
fn constructed(&self) {
self.parent_constructed();

Expand All @@ -71,18 +71,17 @@ mod imp {
}
}

impl WidgetImpl for PreferencesWindow {}
impl WindowImpl for PreferencesWindow {}
impl AdwWindowImpl for PreferencesWindow {}
impl PreferencesWindowImpl for PreferencesWindow {}
impl WidgetImpl for PreferencesDialog {}
impl AdwDialogImpl for PreferencesDialog {}
impl PreferencesDialogImpl for PreferencesDialog {}
}

glib::wrapper! {
pub struct PreferencesWindow(ObjectSubclass<imp::PreferencesWindow>)
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, adw::ApplicationWindow;
pub struct PreferencesDialog(ObjectSubclass<imp::PreferencesDialog>)
@extends gtk::Widget, adw::Dialog, adw::PreferencesDialog;
}

impl PreferencesWindow {
impl PreferencesDialog {
pub fn new(settings: &Settings) -> Self {
glib::Object::builder()
.property("settings", settings)
Expand Down
9 changes: 4 additions & 5 deletions src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use self::{history_view::HistoryView, recognizer_view::RecognizerView, song_bar:
use crate::{
config::PROFILE,
player::{Player, PlayerState},
preferences_window::PreferencesWindow,
preferences_dialog::PreferencesDialog,
recognizer::{RecognizeError, RecognizeErrorKind, Recognizer, RecognizerState, Recordings},
song::Song,
song_list::SongList,
Expand Down Expand Up @@ -363,11 +363,10 @@ impl Window {
clone!(@weak self as obj => move |_, id| {
debug_assert_eq!(id, OPEN_RESPONSE_ID);

let window = PreferencesWindow::new(Application::get().settings());
window.set_transient_for(Some(&obj));
window.present();
let dialog = PreferencesDialog::new(Application::get().settings());
dialog.present(&obj);

let is_focused = window.focus_aud_d_api_token_row();
let is_focused = dialog.focus_aud_d_api_token_row();
debug_assert!(is_focused, "token row must be focused");
}),
);
Expand Down

0 comments on commit eae389f

Please sign in to comment.