-
-
Notifications
You must be signed in to change notification settings - Fork 90
Library: Add Adw.MessageDialog example #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3aab56c
library: Add Message Dialog Example
halfmexican ad19d62
main.blp: remove empty lines
halfmexican 40d59f4
Update src/Library/demos/Dialogs/main.json
halfmexican 29cdab6
Update src/Library/demos/Dialogs/main.js
halfmexican 8a0f9d3
Update src/Library/demos/Dialogs/main.blp
halfmexican d7ec37e
spaces
halfmexican ea091fa
edit comments
halfmexican 4136ebb
Merge branch 'sonnyp:main' into main
halfmexican 6edf528
Dialogs: prefer properties instead of methods
halfmexican 8ab17c8
Dialogs: Use response id instead of label
halfmexican c3e5df8
Dialogs: Add button and update API Reference
halfmexican 4882b6f
Dialogs: Change widget names
halfmexican 7d781c2
Dialogs: follow HIG
halfmexican aec22e0
Dialogs: Update main.vala with changes
halfmexican ac016e2
Merge branch 'sonnyp:main' into main
halfmexican 215d07e
no need for exclamation
sonnyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| using Gtk 4.0; | ||
| using Adw 1; | ||
|
|
||
| Adw.StatusPage { | ||
| title: "Dialogs"; | ||
| description: _("Present options, choices or information to users"); | ||
|
|
||
| Box { | ||
| orientation: vertical; | ||
| halign: center; | ||
|
|
||
| Button button_confirmation { | ||
| label: "Confirmation Dialog"; | ||
| margin-bottom: 30; | ||
| styles ["pill"] | ||
| } | ||
|
|
||
| Button button_error { | ||
| label: "Error Dialog"; | ||
| margin-bottom: 30; | ||
| styles ["pill"] | ||
| } | ||
|
|
||
| Button button_advanced { | ||
| label: "Advanced Error Dialog"; | ||
| margin-bottom: 30; | ||
| styles ["pill"] | ||
| } | ||
|
|
||
| LinkButton { | ||
| label: "API Reference"; | ||
| uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.2/class.MessageDialog.html"; | ||
| } | ||
|
|
||
| LinkButton { | ||
| label: "Human Interface Guidelines"; | ||
| uri: "https://developer.gnome.org/hig/patterns/feedback/dialogs.html"; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import Adw from "gi://Adw"; | ||
| import Gtk from "gi://Gtk"; | ||
|
|
||
| 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_confirmation.get_ancestor(Gtk.Window); | ||
|
|
||
| function createConfirmationDialog() { | ||
| let dialog = new Adw.MessageDialog({ | ||
| 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, | ||
| }); | ||
|
|
||
| dialog.add_response("cancel", "Cancel"); | ||
| dialog.add_response("replace", "Replace"); | ||
|
|
||
| // Use DESTRUCTIVE appearance to draw attention to the potentially damaging consequences of this action | ||
| dialog.set_response_appearance("replace", Adw.ResponseAppearance.DESTRUCTIVE); | ||
|
|
||
| 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.`); | ||
| }); | ||
|
|
||
| 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, | ||
| 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, | ||
| }); | ||
|
|
||
| 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()}"`, | ||
| ); | ||
| } else { | ||
| console.log(`Selected "${response}" response.`); | ||
| } | ||
| }); | ||
|
|
||
| dialog.present(); | ||
| } | ||
|
|
||
| button_confirmation.connect("clicked", createConfirmationDialog); | ||
| button_error.connect("clicked", createErrorDialog); | ||
| button_advanced.connect("clicked", createAdvancedDialog); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "Dialogs", | ||
| "category": "user_interface", | ||
| "description": "Present options, choices or information to users", | ||
| "panels": [ | ||
| "code", | ||
| "preview" | ||
| ], | ||
| "autorun": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #! /usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 | ||
|
|
||
| public void main() { | ||
| 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_confirmation.clicked.connect(_create_confirmation_dialog); | ||
| button_error.clicked.connect(_create_error_dialog); | ||
| button_advanced.clicked.connect(_create_advanced_dialog); | ||
| } | ||
|
|
||
| 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, | ||
| "Replace File?", | ||
| """A file named "example.png" already exists. Do you want to replace it?"""); | ||
|
|
||
| dialog.close_response = "replace"; | ||
|
|
||
| dialog.add_response("cancel", "Cancel"); | ||
| dialog.add_response("replace", "Replace"); | ||
|
|
||
| //Use DESTRUCTIVE to draw attention to the potentially damaging consequences of using response. | ||
| 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; | ||
|
|
||
| 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("Selected \"%s\" response.\n", response); | ||
| }); | ||
|
|
||
| dialog.present(); | ||
|
|
||
| } | ||
|
|
||
| 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; | ||
|
|
||
| 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() {show_peek_icon = true}; | ||
|
|
||
| dialog.set_extra_child(entry); | ||
|
|
||
| dialog.response.connect((response) => { | ||
| if (dialog.get_response_label(response) == "Login") { | ||
| message("Selected \"%s\" response with password \"%s\".", response, entry.get_text()); | ||
| } else { | ||
| message("Selected \"%s\" response.", response); | ||
| } | ||
| }); | ||
|
|
||
| dialog.present(); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.