Switch from AdwPreferencesWindow to AdwPreferencesDialog

This commit is contained in:
Michael Catanzaro 2024-07-08 16:30:39 -05:00
parent 98adf9c494
commit cce143a6fa
7 changed files with 37 additions and 43 deletions

View file

@ -2,8 +2,8 @@
<gresources>
<gresource prefix="/org/gnome/Chess/ui">
<file preprocess="xml-stripblanks">chess-window.ui</file>
<file preprocess="xml-stripblanks">new-game-window.ui</file>
<file preprocess="xml-stripblanks">preferences-window.ui</file>
<file preprocess="xml-stripblanks">new-game-dialog.ui</file>
<file preprocess="xml-stripblanks">preferences-dialog.ui</file>
<file preprocess="xml-stripblanks">promotion-type-selector.ui</file>
</gresource>
<gresource prefix="/org/gnome/Chess/pieces">

View file

@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<template class="NewGameWindow" parent="AdwPreferencesWindow">
<template class="NewGameDialog" parent="AdwPreferencesDialog">
<property name="title" translatable="yes">New Game</property>
<property name="hide-on-close">true</property>
<property name="modal">true</property>
<property name="search-enabled">false</property>
<property name="default_width">400</property>
<property name="default_height">550</property>
<property name="content-width">400</property>
<property name="content-height">550</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
@ -20,7 +18,7 @@
<property name="label" translatable="yes">_Cancel</property>
<property name="valign">center</property>
<property name="use-underline">true</property>
<signal name="clicked" handler="gtk_window_close" object="NewGameWindow" swapped="yes"/>
<signal name="clicked" handler="adw_dialog_close" object="NewGameDialog" swapped="yes"/>
</object>
</child>
<child type="end">

View file

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<template class="PreferencesWindow" parent="AdwPreferencesWindow">
<template class="PreferencesDialog" parent="AdwPreferencesDialog">
<property name="search-enabled">false</property>
<property name="hide-on-close">true</property>
<property name="default_width">400</property>
<property name="default_height">380</property>
<property name="content-width">400</property>
<property name="content-height">380</property>
<child>
<object class="AdwPreferencesPage">
<child>

View file

@ -53,8 +53,8 @@ public class ChessApplication : Adw.Application
get { return view.scene; }
}
private NewGameWindow? new_game_window = null;
private PreferencesWindow? preferences_window = null;
private NewGameDialog? new_game_dialog = null;
private PreferencesDialog? preferences_dialog = null;
private Adw.AboutDialog? about_dialog = null;
private Gtk.FileDialog? open_dialog = null;
private Gtk.FileDialog? save_dialog = null;
@ -1148,27 +1148,27 @@ Copyright © 20152016 Sahil Sareen""";
private void configure_new_game ()
{
if (new_game_window != null)
if (new_game_dialog != null)
{
new_game_window.show ();
new_game_dialog.present (window);
return;
}
new_game_window = new NewGameWindow (window, preferences, ai_profiles);
new_game_window.new_game_requested.connect (() => start_new_game ());
new_game_window.show ();
new_game_dialog = new NewGameDialog (preferences, ai_profiles);
new_game_dialog.new_game_requested.connect (() => start_new_game ());
new_game_dialog.present (window);
}
private void preferences_cb ()
{
if (preferences_window != null)
if (preferences_dialog != null)
{
preferences_window.show ();
preferences_dialog.present (window);
return;
}
preferences_window = new PreferencesWindow (window, preferences);
preferences_window.show ();
preferences_dialog = new PreferencesDialog (preferences);
preferences_dialog.present (window);
}
public void help_cb ()

View file

@ -5,8 +5,8 @@ chess_sources = [
'chess-view.vala',
'chess-window.vala',
'gnome-chess.vala',
'new-game-window.vala',
'preferences-window.vala',
'new-game-dialog.vala',
'preferences-dialog.vala',
'preferences.vala',
'promotion-type-selector-dialog.vala',
]

View file

@ -9,8 +9,8 @@
* license.
*/
[GtkTemplate (ui = "/org/gnome/Chess/ui/new-game-window.ui")]
public class NewGameWindow : Adw.PreferencesWindow
[GtkTemplate (ui = "/org/gnome/Chess/ui/new-game-dialog.ui")]
public class NewGameDialog : Adw.PreferencesDialog
{
private bool syncing_time_limit = false;
private Preferences preferences;
@ -34,10 +34,8 @@ public class NewGameWindow : Adw.PreferencesWindow
[GtkChild]
private unowned Gtk.Switch time_limit_switch;
public NewGameWindow (Gtk.Window window, Preferences preferences, List<AIProfile> ai_profiles)
public NewGameDialog (Preferences preferences, List<AIProfile> ai_profiles)
{
transient_for = window;
this.preferences = preferences;
this.ai_profiles = ai_profiles;
initialize_opponents (ai_profiles);
@ -46,10 +44,10 @@ public class NewGameWindow : Adw.PreferencesWindow
preferences.bind_property ("difficulty", difficulty_combo, "selected", BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE, null, null);
preferences.bind_property (
"opponent",
opponent_combo,
"opponent",
opponent_combo,
"selected",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE,
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE,
(binding, from_value, ref to_value) =>
{
var opponent = (Opponent) from_value.get_object ();
@ -104,21 +102,21 @@ public class NewGameWindow : Adw.PreferencesWindow
close ();
new_game_requested ();
}
[GtkCallback]
private string play_as_display_name_cb (Adw.EnumListItem item)
{
var value = (PlayAs) item.value;
return value.display_name ();
}
[GtkCallback]
private string difficulty_display_name_cb (Adw.EnumListItem item)
{
var value = (Difficulty) item.value;
return value.display_name ();
}
[GtkCallback]
private string clock_type_display_name_cb (Adw.EnumListItem item)
{
@ -191,7 +189,7 @@ public class NewGameWindow : Adw.PreferencesWindow
{
if (opponent.display_name == display_name)
return i;
i++;
i++;
}
return 0;
}

View file

@ -9,8 +9,8 @@
* license.
*/
[GtkTemplate (ui = "/org/gnome/Chess/ui/preferences-window.ui")]
public class PreferencesWindow : Adw.PreferencesWindow
[GtkTemplate (ui = "/org/gnome/Chess/ui/preferences-dialog.ui")]
public class PreferencesDialog : Adw.PreferencesDialog
{
private Preferences preferences;
@ -25,9 +25,8 @@ public class PreferencesWindow : Adw.PreferencesWindow
[GtkChild]
private unowned Gtk.Switch move_hints_switch;
public PreferencesWindow (Gtk.Window window, Preferences preferences)
public PreferencesDialog (Preferences preferences)
{
transient_for = window;
this.preferences = preferences;
preferences.bind_property ("show-board-numbering", board_numbering_switch, "active", BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE, null, null);
@ -36,14 +35,14 @@ public class PreferencesWindow : Adw.PreferencesWindow
preferences.bind_property ("move-format", move_format_combo, "selected", BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE, null, null);
preferences.bind_property ("board-orientation", board_orientation_combo, "selected", BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE, null, null);
}
[GtkCallback]
private string board_orientation_display_name_cb (Adw.EnumListItem item)
{
var value = (BoardOrientation) item.value;
return value.display_name ();
}
[GtkCallback]
private string move_format_display_name_cb (Adw.EnumListItem item)
{