From 3aab56cc19488173dbadc24ff31bf31fdc224d71 Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Tue, 7 Mar 2023 20:47:06 -0600 Subject: [PATCH 01/14] library: Add Message Dialog Example --- src/Library/demos/Dialogs/main.blp | 46 ++++++++++++++++++ src/Library/demos/Dialogs/main.js | 69 +++++++++++++++++++++++++++ src/Library/demos/Dialogs/main.json | 10 ++++ src/Library/demos/Dialogs/main.vala | 72 +++++++++++++++++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 src/Library/demos/Dialogs/main.blp create mode 100644 src/Library/demos/Dialogs/main.js create mode 100644 src/Library/demos/Dialogs/main.json create mode 100644 src/Library/demos/Dialogs/main.vala diff --git a/src/Library/demos/Dialogs/main.blp b/src/Library/demos/Dialogs/main.blp new file mode 100644 index 000000000..4eea683d5 --- /dev/null +++ b/src/Library/demos/Dialogs/main.blp @@ -0,0 +1,46 @@ +using Gtk 4.0; +using Adw 1; + +Adw.StatusPage { + title: "Dialogs"; + description: _("Message Dialogs convey important information to the user. These adaptive dialogs have a heading, a body, an optional child widget, and one or multiple responses, each presented as a button. "); + icon-name: "dialog-symbolic"; + + Box { + orientation: vertical; + halign: center; + + Button button_simple { + label: "Message Dialog"; + margin-bottom: 30; + styles["pill"] + } + + Button button_advanced { + label: "Advanced Dialog"; + margin-bottom: 30; + styles["pill"] + } + + LinkButton { + label: "API Reference"; + uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.MessageDialog.html"; + } + + LinkButton { + label: "Human Interface Guidelines"; + uri: "https://developer.gnome.org/hig/patterns/feedback/dialogs.html"; + } + } +} + + + + + + + + + + + diff --git a/src/Library/demos/Dialogs/main.js b/src/Library/demos/Dialogs/main.js new file mode 100644 index 000000000..97268adf7 --- /dev/null +++ b/src/Library/demos/Dialogs/main.js @@ -0,0 +1,69 @@ +import Adw from "gi://Adw"; +import Gtk from "gi://Gtk"; + +const button_simple = workbench.builder.get_object("button_simple"); +const button_advanced = workbench.builder.get_object("button_advanced"); +const window = button_simple.get_ancestor(Gtk.Window); + +function createSimpleDialog() { + let dialog = new Adw.MessageDialog({ + heading: "Save Changes?", + body: "Opened files have unsaved changes. Unsaved changes will be lost forever!", + close_response: "cancel", + modal: true, + }); + + // Make the dialog transient over the main window + dialog.set_transient_for(window); + + //Negative responses like Cancel or Close should use the default appearance. + dialog.add_response("cancel", "Cancel"); + + //Use DESTRUCTIVE to draw attention to the potentially damaging consequences of using response. + dialog.add_response("discard", "Discard"); + dialog.set_response_appearance("discard", Adw.ResponseAppearance.DESTRUCTIVE); + + //Use SUGGESTED to mark important responses such as the affirmative action, like the Save button in the example. + dialog.add_response("save", "Save"); + dialog.set_response_appearance("save", Adw.ResponseAppearance.SUGGESTED); + + dialog.connect("response", (dialog, response) => { + console.log(`Clicked "${dialog.get_response_label(response)}" response.`); + }); + + dialog.present(); +} + +//Creates a message dialog with an extra child +function createAdvancedDialog() { + let dialog = new Adw.MessageDialog({ + heading: "Login", + body: "A valid password is needed to continue!", + close_response: "cancel", + modal: true, + }); + + dialog.set_transient_for(window); + dialog.add_response("cancel", "Cancel"); + dialog.add_response("login", "Login"); + dialog.set_response_appearance("login", Adw.ResponseAppearance.SUGGESTED); + + let entry = new Gtk.PasswordEntry(); + entry.set_show_peek_icon(true); + + dialog.set_extra_child(entry); + + dialog.connect("response", (dialog, response) => { + if (dialog.get_response_label(response) === "Login") { + console.log(`Clicked "${dialog.get_response_label(response)}" response with password "${entry.get_text()}"`); + } else { + console.log(`Clicked "${dialog.get_response_label(response)}" response.`); + } + }); + + dialog.present(); +} + +button_simple.connect("clicked", createSimpleDialog); +button_advanced.connect("clicked", createAdvancedDialog); + diff --git a/src/Library/demos/Dialogs/main.json b/src/Library/demos/Dialogs/main.json new file mode 100644 index 000000000..a3b930fb0 --- /dev/null +++ b/src/Library/demos/Dialogs/main.json @@ -0,0 +1,10 @@ +{ + "name": "Dialogs", + "category": "user_interface", + "description": "A widget to convery important information to the user", + "panels": [ + "code", + "preview" + ], + "autorun": true +} diff --git a/src/Library/demos/Dialogs/main.vala b/src/Library/demos/Dialogs/main.vala new file mode 100644 index 000000000..78b3dc1c3 --- /dev/null +++ b/src/Library/demos/Dialogs/main.vala @@ -0,0 +1,72 @@ +#! /usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 + +public void main() { + var button_simple = workbench.builder.get_object("button_simple") as Gtk.Button; + var button_advanced = workbench.builder.get_object("button_advanced") as Gtk.Button; + + button_simple.clicked.connect(create_simple_dialog); + button_advanced.clicked.connect(create_advanced_dialog); +} + +private void create_simple_dialog (Gtk.Button button) { + // Get the parent window + var window_type = GLib.Type.from_name("GtkWindow"); + Gtk.Window window = button.get_ancestor(window_type) as Gtk.Window; + + Adw.MessageDialog dialog = new Adw.MessageDialog + (window, + "Save Changes?", + "Opened files have unsaved changes. Unsaved changes will be lost forever!"); + + dialog.close_response = "cancel"; + + //Negative responses like Cancel or Close should use the default appearance. + dialog.add_response("cancel", "Cancel"); + + //Use DESTRUCTIVE to draw attention to the potentially damaging consequences of using response. + dialog.add_response("discard", "Discard"); + dialog.set_response_appearance("discard", Adw.ResponseAppearance.DESTRUCTIVE); + + //Use SUGGESTED to mark important responses such as the affirmative action, like the Save button in the example. + dialog.add_response("save", "Save"); + dialog.set_response_appearance("save", Adw.ResponseAppearance.SUGGESTED); + + dialog.response.connect((response) => { + message("Clicked \"%s\" response.\n", + dialog.get_response_label(response)); + }); + +dialog.present(); + +} + +static void create_advanced_dialog(Gtk.Button button) { + // Get the parent window + var window_type = GLib.Type.from_name("GtkWindow"); + Gtk.Window window = button.get_ancestor(window_type) as Gtk.Window; + + Adw.MessageDialog dialog = new Adw.MessageDialog ( + window, + "Login", + "A valid password is needed to continue!"); + + dialog.close_response = "cancel"; + dialog.add_response("cancel", "Cancel"); + dialog.add_response("login", "Login"); + dialog.set_response_appearance("login", Adw.ResponseAppearance.SUGGESTED); + + var entry = new Gtk.PasswordEntry(); + entry.set_show_peek_icon(true); + dialog.set_extra_child(entry); + + dialog.response.connect((response) => { + if (dialog.get_response_label(response) == "Login") { + message("Clicked \"%s\" response with password \"%s\".", dialog.get_response_label(response), entry.get_text()); + } else { + message("Clicked \"%s\" response.", dialog.get_response_label(response)); + } + }); + + dialog.present(); +} + From ad19d625f0ba771f9a9cc3da9c610d7573382706 Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Tue, 7 Mar 2023 20:48:23 -0600 Subject: [PATCH 02/14] main.blp: remove empty lines --- src/Library/demos/Dialogs/main.blp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Library/demos/Dialogs/main.blp b/src/Library/demos/Dialogs/main.blp index 4eea683d5..5eec65cae 100644 --- a/src/Library/demos/Dialogs/main.blp +++ b/src/Library/demos/Dialogs/main.blp @@ -33,14 +33,3 @@ Adw.StatusPage { } } } - - - - - - - - - - - From 40d59f4990c375c7db9968f1e64fcb352603d545 Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Wed, 8 Mar 2023 08:37:41 -0600 Subject: [PATCH 03/14] Update src/Library/demos/Dialogs/main.json Co-authored-by: Sonny Piers --- src/Library/demos/Dialogs/main.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library/demos/Dialogs/main.json b/src/Library/demos/Dialogs/main.json index a3b930fb0..38ef62293 100644 --- a/src/Library/demos/Dialogs/main.json +++ b/src/Library/demos/Dialogs/main.json @@ -1,7 +1,7 @@ { "name": "Dialogs", "category": "user_interface", - "description": "A widget to convery important information to the user", + "description": "Present options, choices or information to users", "panels": [ "code", "preview" From 29cdab63b7e03ef9ebe42b24e7a161976a7b11ad Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Wed, 8 Mar 2023 08:54:53 -0600 Subject: [PATCH 04/14] Update src/Library/demos/Dialogs/main.js Co-authored-by: Sonny Piers --- src/Library/demos/Dialogs/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library/demos/Dialogs/main.js b/src/Library/demos/Dialogs/main.js index 97268adf7..f697839e0 100644 --- a/src/Library/demos/Dialogs/main.js +++ b/src/Library/demos/Dialogs/main.js @@ -23,8 +23,8 @@ function createSimpleDialog() { dialog.add_response("discard", "Discard"); dialog.set_response_appearance("discard", Adw.ResponseAppearance.DESTRUCTIVE); - //Use SUGGESTED to mark important responses such as the affirmative action, like the Save button in the example. dialog.add_response("save", "Save"); + // Use SUGGESTED appearance to mark important responses such as the affirmative action dialog.set_response_appearance("save", Adw.ResponseAppearance.SUGGESTED); dialog.connect("response", (dialog, response) => { From 8a0f9d35ebe5b95bd32f923cbf69ab827ca6d7bc Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Wed, 8 Mar 2023 10:25:44 -0600 Subject: [PATCH 05/14] Update src/Library/demos/Dialogs/main.blp spaces Co-authored-by: Sonny Piers --- src/Library/demos/Dialogs/main.blp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library/demos/Dialogs/main.blp b/src/Library/demos/Dialogs/main.blp index 5eec65cae..b8d9df055 100644 --- a/src/Library/demos/Dialogs/main.blp +++ b/src/Library/demos/Dialogs/main.blp @@ -13,7 +13,7 @@ Adw.StatusPage { Button button_simple { label: "Message Dialog"; margin-bottom: 30; - styles["pill"] + styles ["pill"] } Button button_advanced { From d7ec37ea33364870f7aef26c3e6d9f8f2aa7c350 Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Wed, 8 Mar 2023 10:26:01 -0600 Subject: [PATCH 06/14] spaces spaces Co-authored-by: Sonny Piers --- src/Library/demos/Dialogs/main.blp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library/demos/Dialogs/main.blp b/src/Library/demos/Dialogs/main.blp index b8d9df055..143a029d9 100644 --- a/src/Library/demos/Dialogs/main.blp +++ b/src/Library/demos/Dialogs/main.blp @@ -19,7 +19,7 @@ Adw.StatusPage { Button button_advanced { label: "Advanced Dialog"; margin-bottom: 30; - styles["pill"] + styles ["pill"] } LinkButton { From ea091faf57d7c06947774b22b5832a5e87299443 Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Wed, 8 Mar 2023 10:26:43 -0600 Subject: [PATCH 07/14] edit comments Co-authored-by: Sonny Piers --- src/Library/demos/Dialogs/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library/demos/Dialogs/main.js b/src/Library/demos/Dialogs/main.js index f697839e0..323ee608a 100644 --- a/src/Library/demos/Dialogs/main.js +++ b/src/Library/demos/Dialogs/main.js @@ -19,8 +19,8 @@ function createSimpleDialog() { //Negative responses like Cancel or Close should use the default appearance. dialog.add_response("cancel", "Cancel"); - //Use DESTRUCTIVE to draw attention to the potentially damaging consequences of using response. dialog.add_response("discard", "Discard"); + // Use DESTRUCTIVE appearance to draw attention to the potentially damaging consequences of this action dialog.set_response_appearance("discard", Adw.ResponseAppearance.DESTRUCTIVE); dialog.add_response("save", "Save"); From 6edf52873fa9cb7d652f7ab80e26742be656e1dc Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Wed, 8 Mar 2023 11:01:57 -0600 Subject: [PATCH 08/14] Dialogs: prefer properties instead of methods replace methods with their equivalent property during construction --- src/Library/demos/Dialogs/main.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Library/demos/Dialogs/main.js b/src/Library/demos/Dialogs/main.js index 323ee608a..cd15e59d2 100644 --- a/src/Library/demos/Dialogs/main.js +++ b/src/Library/demos/Dialogs/main.js @@ -11,12 +11,9 @@ function createSimpleDialog() { body: "Opened files have unsaved changes. Unsaved changes will be lost forever!", close_response: "cancel", modal: true, + transient_for: window }); - // Make the dialog transient over the main window - dialog.set_transient_for(window); - - //Negative responses like Cancel or Close should use the default appearance. dialog.add_response("cancel", "Cancel"); dialog.add_response("discard", "Discard"); @@ -41,15 +38,16 @@ function createAdvancedDialog() { body: "A valid password is needed to continue!", close_response: "cancel", modal: true, + transient_for: window }); - dialog.set_transient_for(window); dialog.add_response("cancel", "Cancel"); dialog.add_response("login", "Login"); dialog.set_response_appearance("login", Adw.ResponseAppearance.SUGGESTED); - let entry = new Gtk.PasswordEntry(); - entry.set_show_peek_icon(true); + let entry = new Gtk.PasswordEntry({ + show_peek_icon : true + }); dialog.set_extra_child(entry); @@ -66,4 +64,3 @@ function createAdvancedDialog() { button_simple.connect("clicked", createSimpleDialog); button_advanced.connect("clicked", createAdvancedDialog); - From 8ab17c8142d55966a54162c6f414a32546c48341 Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Wed, 8 Mar 2023 11:13:18 -0600 Subject: [PATCH 09/14] Dialogs: Use response id instead of label --- src/Library/demos/Dialogs/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Library/demos/Dialogs/main.js b/src/Library/demos/Dialogs/main.js index cd15e59d2..61069e4cf 100644 --- a/src/Library/demos/Dialogs/main.js +++ b/src/Library/demos/Dialogs/main.js @@ -25,7 +25,7 @@ function createSimpleDialog() { dialog.set_response_appearance("save", Adw.ResponseAppearance.SUGGESTED); dialog.connect("response", (dialog, response) => { - console.log(`Clicked "${dialog.get_response_label(response)}" response.`); + console.log(`Selected "${response}" response.`); }); dialog.present(); @@ -53,9 +53,9 @@ function createAdvancedDialog() { dialog.connect("response", (dialog, response) => { if (dialog.get_response_label(response) === "Login") { - console.log(`Clicked "${dialog.get_response_label(response)}" response with password "${entry.get_text()}"`); + console.log(`Selected "${response}" response with password "${entry.get_text()}"`); } else { - console.log(`Clicked "${dialog.get_response_label(response)}" response.`); + console.log(`Selected "${response}" response.`); } }); From c3e5df8d73b3c4b96514c84117ddb7545d5917b8 Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Wed, 8 Mar 2023 11:38:42 -0600 Subject: [PATCH 10/14] Dialogs: Add button and update API Reference --- src/Library/demos/Dialogs/main.blp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Library/demos/Dialogs/main.blp b/src/Library/demos/Dialogs/main.blp index 143a029d9..4eb53f4f5 100644 --- a/src/Library/demos/Dialogs/main.blp +++ b/src/Library/demos/Dialogs/main.blp @@ -3,28 +3,33 @@ using Adw 1; Adw.StatusPage { title: "Dialogs"; - description: _("Message Dialogs convey important information to the user. These adaptive dialogs have a heading, a body, an optional child widget, and one or multiple responses, each presented as a button. "); - icon-name: "dialog-symbolic"; + description: _("These adaptive dialogs have a heading, a body, an optional child widget, and one or multiple responses, each presented as a button. "); Box { orientation: vertical; halign: center; Button button_simple { - label: "Message Dialog"; + label: "Confirmation Dialog"; + margin-bottom: 30; + styles ["pill"] + } + + Button button_error { + label: "Error Dialog"; margin-bottom: 30; styles ["pill"] } Button button_advanced { - label: "Advanced Dialog"; + label: "Advanced Error Dialog"; margin-bottom: 30; styles ["pill"] } LinkButton { label: "API Reference"; - uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.MessageDialog.html"; + uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.2/class.MessageDialog.html"; } LinkButton { From 4882b6fe9d08fa8004da26832ff387dd6ff9952e Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Wed, 8 Mar 2023 22:46:29 -0600 Subject: [PATCH 11/14] Dialogs: Change widget names --- src/Library/demos/Dialogs/main.blp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library/demos/Dialogs/main.blp b/src/Library/demos/Dialogs/main.blp index 4eb53f4f5..3f0861f3a 100644 --- a/src/Library/demos/Dialogs/main.blp +++ b/src/Library/demos/Dialogs/main.blp @@ -9,7 +9,7 @@ Adw.StatusPage { orientation: vertical; halign: center; - Button button_simple { + Button button_confirmation { label: "Confirmation Dialog"; margin-bottom: 30; styles ["pill"] From 7d781c2aec2104979c68029dcd4b08bfc8e3ed8a Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Wed, 8 Mar 2023 22:51:56 -0600 Subject: [PATCH 12/14] Dialogs: follow HIG We now have a confirmation, error, and advanced error dialog. --- src/Library/demos/Dialogs/main.js | 50 +++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/src/Library/demos/Dialogs/main.js b/src/Library/demos/Dialogs/main.js index 61069e4cf..d75e25775 100644 --- a/src/Library/demos/Dialogs/main.js +++ b/src/Library/demos/Dialogs/main.js @@ -1,28 +1,43 @@ import Adw from "gi://Adw"; import Gtk from "gi://Gtk"; -const button_simple = workbench.builder.get_object("button_simple"); +const button_confirmation = workbench.builder.get_object("button_confirmation"); +const button_error = workbench.builder.get_object("button_error"); const button_advanced = workbench.builder.get_object("button_advanced"); -const window = button_simple.get_ancestor(Gtk.Window); +const window = button_confirmation.get_ancestor(Gtk.Window); -function createSimpleDialog() { +function createConfirmationDialog() { let dialog = new Adw.MessageDialog({ - heading: "Save Changes?", - body: "Opened files have unsaved changes. Unsaved changes will be lost forever!", + heading: "Replace File?", + body: 'A file named "example.png" already exists. Do you want to replace it?', close_response: "cancel", modal: true, - transient_for: window + transient_for: window, }); dialog.add_response("cancel", "Cancel"); + dialog.add_response("replace", "Replace"); - dialog.add_response("discard", "Discard"); // Use DESTRUCTIVE appearance to draw attention to the potentially damaging consequences of this action - dialog.set_response_appearance("discard", Adw.ResponseAppearance.DESTRUCTIVE); + dialog.set_response_appearance("replace", Adw.ResponseAppearance.DESTRUCTIVE); - dialog.add_response("save", "Save"); - // Use SUGGESTED appearance to mark important responses such as the affirmative action - dialog.set_response_appearance("save", Adw.ResponseAppearance.SUGGESTED); + dialog.connect("response", (dialog, response) => { + console.log(`Selected "${response}" response.`); + }); + + dialog.present(); +} + +function createErrorDialog() { + let dialog = new Adw.MessageDialog({ + heading: "Critical Error", + body: "You did something you should not have", + close_response: "okay", + modal: true, + transient_for: window, + }); + + dialog.add_response("okay", "Okay"); dialog.connect("response", (dialog, response) => { console.log(`Selected "${response}" response.`); @@ -38,22 +53,26 @@ function createAdvancedDialog() { body: "A valid password is needed to continue!", close_response: "cancel", modal: true, - transient_for: window + transient_for: window, }); dialog.add_response("cancel", "Cancel"); dialog.add_response("login", "Login"); + + // Use SUGGESTED appearance to mark important responses such as the affirmative action dialog.set_response_appearance("login", Adw.ResponseAppearance.SUGGESTED); let entry = new Gtk.PasswordEntry({ - show_peek_icon : true + show_peek_icon: true, }); dialog.set_extra_child(entry); dialog.connect("response", (dialog, response) => { if (dialog.get_response_label(response) === "Login") { - console.log(`Selected "${response}" response with password "${entry.get_text()}"`); + console.log( + `Selected "${response}" response with password "${entry.get_text()}"`, + ); } else { console.log(`Selected "${response}" response.`); } @@ -62,5 +81,6 @@ function createAdvancedDialog() { dialog.present(); } -button_simple.connect("clicked", createSimpleDialog); +button_confirmation.connect("clicked", createConfirmationDialog); +button_error.connect("clicked", createErrorDialog); button_advanced.connect("clicked", createAdvancedDialog); From aec22e0c92ae0ebe7b9a7398317382ffbdefa148 Mon Sep 17 00:00:00 2001 From: halfmexican <103920890+halfmexican@users.noreply.github.com> Date: Wed, 8 Mar 2023 22:53:31 -0600 Subject: [PATCH 13/14] Dialogs: Update main.vala with changes updates the vala code to work with the newly updated main.blp --- src/Library/demos/Dialogs/main.vala | 59 +++++++++++++++++++---------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/src/Library/demos/Dialogs/main.vala b/src/Library/demos/Dialogs/main.vala index 78b3dc1c3..b945e7a0c 100644 --- a/src/Library/demos/Dialogs/main.vala +++ b/src/Library/demos/Dialogs/main.vala @@ -1,46 +1,64 @@ #! /usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 public void main() { - var button_simple = workbench.builder.get_object("button_simple") as Gtk.Button; + var button_confirmation = workbench.builder.get_object("button_confirmation") as Gtk.Button; + var button_error = workbench.builder.get_object("button_error") as Gtk.Button; var button_advanced = workbench.builder.get_object("button_advanced") as Gtk.Button; - button_simple.clicked.connect(create_simple_dialog); - button_advanced.clicked.connect(create_advanced_dialog); + button_confirmation.clicked.connect(_create_confirmation_dialog); + button_error.clicked.connect(_create_error_dialog); + button_advanced.clicked.connect(_create_advanced_dialog); } -private void create_simple_dialog (Gtk.Button button) { +private void _create_confirmation_dialog (Gtk.Button button) { // Get the parent window var window_type = GLib.Type.from_name("GtkWindow"); Gtk.Window window = button.get_ancestor(window_type) as Gtk.Window; Adw.MessageDialog dialog = new Adw.MessageDialog (window, - "Save Changes?", - "Opened files have unsaved changes. Unsaved changes will be lost forever!"); + "Replace File?", + """A file named "example.png" already exists. Do you want to replace it?"""); - dialog.close_response = "cancel"; + dialog.close_response = "replace"; - //Negative responses like Cancel or Close should use the default appearance. dialog.add_response("cancel", "Cancel"); + dialog.add_response("replace", "Replace"); //Use DESTRUCTIVE to draw attention to the potentially damaging consequences of using response. - dialog.add_response("discard", "Discard"); - dialog.set_response_appearance("discard", Adw.ResponseAppearance.DESTRUCTIVE); + dialog.set_response_appearance("replace", Adw.ResponseAppearance.DESTRUCTIVE); + + dialog.response.connect((response) => { + message("Selected \"%s\" response.\n", response); + }); + +dialog.present(); + +} + +private void _create_error_dialog (Gtk.Button button) { + // Get the parent window + var window_type = GLib.Type.from_name("GtkWindow"); + Gtk.Window window = button.get_ancestor(window_type) as Gtk.Window; - //Use SUGGESTED to mark important responses such as the affirmative action, like the Save button in the example. - dialog.add_response("save", "Save"); - dialog.set_response_appearance("save", Adw.ResponseAppearance.SUGGESTED); + Adw.MessageDialog dialog = new Adw.MessageDialog + (window, + "Critical Error", + "You did something you should not have"); + + dialog.close_response = "okay"; + + dialog.add_response("okay", "Okay"); dialog.response.connect((response) => { - message("Clicked \"%s\" response.\n", - dialog.get_response_label(response)); + message("Selected \"%s\" response.\n", response); }); dialog.present(); } -static void create_advanced_dialog(Gtk.Button button) { +private void _create_advanced_dialog(Gtk.Button button) { // Get the parent window var window_type = GLib.Type.from_name("GtkWindow"); Gtk.Window window = button.get_ancestor(window_type) as Gtk.Window; @@ -55,18 +73,17 @@ static void create_advanced_dialog(Gtk.Button button) { dialog.add_response("login", "Login"); dialog.set_response_appearance("login", Adw.ResponseAppearance.SUGGESTED); - var entry = new Gtk.PasswordEntry(); - entry.set_show_peek_icon(true); + var entry = new Gtk.PasswordEntry() {show_peek_icon = true}; + dialog.set_extra_child(entry); dialog.response.connect((response) => { if (dialog.get_response_label(response) == "Login") { - message("Clicked \"%s\" response with password \"%s\".", dialog.get_response_label(response), entry.get_text()); + message("Selected \"%s\" response with password \"%s\".", response, entry.get_text()); } else { - message("Clicked \"%s\" response.", dialog.get_response_label(response)); + message("Selected \"%s\" response.", response); } }); dialog.present(); } - From 215d07e5131eb0ee2ac6aa35a817955be7c6aea1 Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Mon, 13 Mar 2023 00:19:41 +0100 Subject: [PATCH 14/14] no need for exclamation --- src/Library/demos/Dialogs/main.blp | 2 +- src/Library/demos/Dialogs/main.js | 2 +- src/Library/demos/Dialogs/main.json | 2 +- src/Library/demos/Dialogs/main.vala | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Library/demos/Dialogs/main.blp b/src/Library/demos/Dialogs/main.blp index 3f0861f3a..e35e6d42d 100644 --- a/src/Library/demos/Dialogs/main.blp +++ b/src/Library/demos/Dialogs/main.blp @@ -3,7 +3,7 @@ using Adw 1; Adw.StatusPage { title: "Dialogs"; - description: _("These adaptive dialogs have a heading, a body, an optional child widget, and one or multiple responses, each presented as a button. "); + description: _("Present options, choices or information to users"); Box { orientation: vertical; diff --git a/src/Library/demos/Dialogs/main.js b/src/Library/demos/Dialogs/main.js index d75e25775..f839ec193 100644 --- a/src/Library/demos/Dialogs/main.js +++ b/src/Library/demos/Dialogs/main.js @@ -50,7 +50,7 @@ function createErrorDialog() { function createAdvancedDialog() { let dialog = new Adw.MessageDialog({ heading: "Login", - body: "A valid password is needed to continue!", + body: "A valid password is needed to continue", close_response: "cancel", modal: true, transient_for: window, diff --git a/src/Library/demos/Dialogs/main.json b/src/Library/demos/Dialogs/main.json index 38ef62293..b39ef0af9 100644 --- a/src/Library/demos/Dialogs/main.json +++ b/src/Library/demos/Dialogs/main.json @@ -7,4 +7,4 @@ "preview" ], "autorun": true -} +} \ No newline at end of file diff --git a/src/Library/demos/Dialogs/main.vala b/src/Library/demos/Dialogs/main.vala index b945e7a0c..6d4e9aa68 100644 --- a/src/Library/demos/Dialogs/main.vala +++ b/src/Library/demos/Dialogs/main.vala @@ -66,7 +66,7 @@ private void _create_advanced_dialog(Gtk.Button button) { Adw.MessageDialog dialog = new Adw.MessageDialog ( window, "Login", - "A valid password is needed to continue!"); + "A valid password is needed to continue"); dialog.close_response = "cancel"; dialog.add_response("cancel", "Cancel");