Skip to content

Commit

Permalink
Port PreferencesWindow to PreferencesDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Feb 11, 2024
1 parent f4fdc7c commit 323b300
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 61 deletions.
4 changes: 2 additions & 2 deletions demos/About Dialog/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn on_button_clicked() {
.application_name("Typeset")
.developer_name("Angela Avery")
.version("1.2.3")
.comments("Typeset is an app that doesn’t exist and is used as an example content for About Window.")
.comments("Typeset is an app that doesn’t exist and is used as an example content for About Dialog.")
.website("https://example.org")
.issue_url("https://example.org")
.support_url("https://example.org")
Expand All @@ -40,5 +40,5 @@ fn on_button_clicked() {

dialog.add_acknowledgement_section(Some("Special thanks to"), &["My cat"]);

dialog.present(workbench::window);
dialog.present(workbench::window());
}
2 changes: 1 addition & 1 deletion demos/About Dialog/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function openAboutDialog() {
developer_name: "Angela Avery",
version: "1.2.3",
comments: _(
"Typeset is an app that doesn’t exist and is used as an example content for About Window.",
"Typeset is an app that doesn’t exist and is used as an example content for About Dialog.",
),
website: "https://example.org",
issue_url: "https://example.org",
Expand Down
2 changes: 1 addition & 1 deletion demos/About Dialog/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def open_about_window(_widget):
developer_name="Angela Avery",
version="1.2.3",
comments=_(
"Typeset is an app that doesn’t exist and is used as an example content for About Window.",
"Typeset is an app that doesn’t exist and is used as an example content for About Dialog.",
),
website="https://example.org",
issue_url="https://example.org",
Expand Down
3 changes: 1 addition & 2 deletions demos/About Dialog/main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ public void main () {
}

public void on_button_clicked () {
// https://valadoc.org/libadwaita-1/Adw.AboutWindow.html
var dialog = new Adw.AboutDialog () {
application_icon = "application-x-executable",
application_name = "Typeset",
developer_name = "Angela Avery",
version = "1.2.3",
comments = "Typeset is an app that doesn’t exist and is used as an example content for About Window.",
comments = "Typeset is an app that doesn’t exist and is used as an example content for About Dialog.",
website = "https://example.org",
issue_url = "https://example.org",
support_url = "https://example.org",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
using Gtk 4.0;
using Adw 1;

Adw.PreferencesWindow pref_window {
default-width: 800;
default-height: 600;
Adw.StatusPage {
title: _("Preferences Dialog");
description: _("A dialog showing application’s preferences");

Box {
spacing: 12;
halign: center;
orientation: vertical;

Button button {
label: _("Open");

styles [
"suggested-action",
"pill"
]
}

FlowBox {
orientation: horizontal;
margin-top: 12;
max-children-per-line: 2;
min-children-per-line: 2;

LinkButton {
label: _("PreferencesDialog");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.5/class.PreferencesDialog.html";
}

LinkButton {
label: _("PreferencesPage");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.5/class.PreferencesPage.html";
}

LinkButton {
label: _("PreferencesGroup");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.5/class.PreferencesGroup.html";
}

LinkButton {
label: _("PreferencesRow");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.5/class.PreferencesRow.html";
}
}
}
}

Adw.PreferencesDialog dialog {
content-width: 800;
content-height: 600;
title: _("Preferences");

Adw.PreferencesPage appearance_page {
Expand Down Expand Up @@ -46,37 +93,6 @@ Adw.PreferencesWindow pref_window {
}
}
}

Adw.PreferencesGroup {
title: _("API References");

FlowBox {
orientation: horizontal;
margin-top: 12;
max-children-per-line: 2;
min-children-per-line: 2;

LinkButton {
label: _("PreferencesWindow");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.5/class.PreferencesWindow.html";
}

LinkButton {
label: _("PreferencesPage");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.5/class.PreferencesPage.html";
}

LinkButton {
label: _("PreferencesGroup");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.5/class.PreferencesGroup.html";
}

LinkButton {
label: _("PreferencesRow");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.5/class.PreferencesRow.html";
}
}
}
}

Adw.PreferencesPage {
Expand Down Expand Up @@ -118,11 +134,11 @@ Adw.PreferencesWindow pref_window {
description: _("Manage user data related settings.");

Adw.SwitchRow {
title: _("Enable Telemetry");
title: _("Enable Debug");
}

Adw.SwitchRow {
title: _("Enable Auto-Updates");
title: _("Check for updates");
}

Adw.ActionRow subpage_row {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Adw from "gi://Adw";

const pref_window = workbench.builder.get_object("pref_window");
const dialog = workbench.builder.get_object("dialog");
const dm_switch = workbench.builder.get_object("dm_switch");
const subpage = workbench.builder.get_object("subpage");
const subpage_row = workbench.builder.get_object("subpage_row");
const subpage_button = workbench.builder.get_object("subpage_button");
const toast_button = workbench.builder.get_object("toast_button");
const style_manager = Adw.StyleManager.get_default();
const button = workbench.builder.get_object("button");

dm_switch.active = style_manager.dark;

Expand All @@ -19,19 +20,23 @@ dm_switch.connect("notify::active", () => {
}
});

// Preferences windows can display subpages
// Preferences dialogs can display subpages
subpage_row.connect("activated", () => {
pref_window.push_subpage(subpage);
dialog.push_subpage(subpage);
});

subpage_button.connect("clicked", () => {
pref_window.pop_subpage();
dialog.pop_subpage();
});

toast_button.connect("clicked", () => {
const toast = new Adw.Toast({
title: "Preferences windows can display toasts",
title: "Preferences dialogs can display toasts",
});

pref_window.add_toast(toast);
dialog.add_toast(toast);
});

button.connect("clicked", () => {
dialog.present(workbench.window);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"category": "user_interface",
"description": "A window containing an application's preferences",
"description": "A dialog showing applications preferences",
"panels": ["ui", "preview"],
"autorun": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from gi.repository import Adw
import workbench

pref_window = workbench.builder.get_object("pref_window")
dialog = workbench.builder.get_object("dialog")
dm_switch = workbench.builder.get_object("dm_switch")
subpage = workbench.builder.get_object("subpage")
subpage_row = workbench.builder.get_object("subpage_row")
subpage_button = workbench.builder.get_object("subpage_button")
toast_button = workbench.builder.get_object("toast_button")
button = workbench.builder.get_object("button")

style_manager = Adw.StyleManager.get_default()

dm_switch.set_active(style_manager.get_dark())
Expand All @@ -24,16 +26,18 @@
),
)

# Preferences windows can display subpages
subpage_row.connect("activated", lambda *_: pref_window.push_subpage(subpage))
# Preferences dialogs can display subpages
subpage_row.connect("activated", lambda *_: dialog.push_subpage(subpage))

subpage_button.connect("clicked", lambda *_: pref_window.pop_subpage())
subpage_button.connect("clicked", lambda *_: dialog.pop_subpage())

toast_button.connect(
"clicked",
lambda *_: pref_window.add_toast(
lambda *_: dialog.add_toast(
Adw.Toast(
title="Preferences windows can display toasts",
title="Preferences dialogs can display toasts",
)
),
)

button.connect("clicked", lambda *_: dialog.present(workbench.window))
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#! /usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1

public void main () {
var pref_window = (Adw.PreferencesWindow) workbench.builder.get_object ("pref_window");
var dialog = (Adw.PreferencesDialog) workbench.builder.get_object ("dialog");
var dm_switch = (Adw.SwitchRow) workbench.builder.get_object ("dm_switch");
var subpage = (Adw.NavigationPage) workbench.builder.get_object ("subpage");
var subpage_row = (Adw.ActionRow) workbench.builder.get_object ("subpage_row");
var subpage_button = (Gtk.Button) workbench.builder.get_object ("subpage_button");
var toast_button = (Gtk.Button) workbench.builder.get_object ("toast_button");
var button = (Gtk.Button) workbench.builder.get_object ("button");
var style_manager = Adw.StyleManager.get_default ();

dm_switch.active = style_manager.dark;
Expand All @@ -20,14 +21,18 @@ public void main () {
}
});

// Preferences windows can display subpages
subpage_row.activated.connect (() => pref_window.push_subpage (subpage));
// Preferences dialogs can display subpages
subpage_row.activated.connect (() => dialog.push_subpage (subpage));

subpage_button.clicked.connect (() => pref_window.pop_subpage ());
subpage_button.clicked.connect (() => dialog.pop_subpage ());

toast_button.clicked.connect (() => {
var toast = new Adw.Toast ("Preferences windows can display toasts");
var toast = new Adw.Toast ("Preferences dialogs can display toasts");

pref_window.add_toast (toast);
dialog.add_toast (toast);
});

button.clicked.connect (() => {
dialog.present (workbench.window);
});
}

0 comments on commit 323b300

Please sign in to comment.