Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions src/Library/demos/Dialogs/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import Adw from "gi://Adw";
import Gtk from "gi://Gtk";
import Gio from "gi://Gio";

Gio._promisify(Adw.MessageDialog.prototype, "choose", "choose_finish");

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 = workbench.window;

function createConfirmationDialog() {
async function createConfirmationDialog() {
const dialog = new Adw.MessageDialog({
heading: "Replace File?",
body: "A file named `example.png` already exists. Do you want to replace it?",
Expand All @@ -21,14 +24,11 @@ function createConfirmationDialog() {
// 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", (_self, response) => {
console.log(`Selected "${response}" response.`);
});

dialog.present();
const response = await dialog.choose(null);
console.log(`Selected "${response}" response.`);
}

function createErrorDialog() {
async function createErrorDialog() {
const dialog = new Adw.MessageDialog({
heading: "Critical Error",
body: "You did something you should not have",
Expand All @@ -39,15 +39,12 @@ function createErrorDialog() {

dialog.add_response("okay", "Okay");

dialog.connect("response", (_self, response) => {
console.log(`Selected "${response}" response.`);
});

dialog.present();
const response = await dialog.choose(null);
console.log(`Selected "${response}" response.`);
}

//Creates a message dialog with an extra child
function createAdvancedDialog() {
async function createAdvancedDialog() {
const dialog = new Adw.MessageDialog({
heading: "Login",
body: "A valid password is needed to continue",
Expand All @@ -68,19 +65,22 @@ function createAdvancedDialog() {

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();
const response = await dialog.choose(null);
if (response === "login") {
console.log(
`Selected "${response}" response with password "${entry.get_text()}"`,
);
} else {
console.log(`Selected "${response}" response.`);
}
}

button_confirmation.connect("clicked", createConfirmationDialog);
button_error.connect("clicked", createErrorDialog);
button_advanced.connect("clicked", createAdvancedDialog);
button_confirmation.connect("clicked", () => {
createConfirmationDialog().catch(logError);
});
button_error.connect("clicked", () => {
createErrorDialog().catch(logError);
});
button_advanced.connect("clicked", () => {
createAdvancedDialog().catch(logError);
});
15 changes: 9 additions & 6 deletions src/Library/demos/Welcome/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Gtk from "gi://Gtk";
import Adw from "gi://Adw";
import Gio from "gi://Gio";

Gio._promisify(Adw.MessageDialog.prototype, "choose", "choose_finish");

const box = workbench.builder.get_object("subtitle");

Expand All @@ -9,22 +12,22 @@ const button = new Gtk.Button({
margin_top: 6,
css_classes: ["suggested-action"],
});
button.connect("clicked", greet);
button.connect("clicked", () => {
greet().catch(logError);
});
box.append(button);

console.log("Welcome to Workbench!");

function greet() {
async function greet() {
// https://gjs-docs.gnome.org/adw1~1/adw.messagedialog
const dialog = new Adw.MessageDialog({
body: "Hello World!",
transient_for: workbench.window,
});

dialog.add_response("ok", "OK");
dialog.connect("response", (self, response) => {
console.log(response);
});

dialog.present();
const response = await dialog.choose(null);
console.log(response);
}
2 changes: 2 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import "gi://Pango?version=1.0";

import Gtk from "gi://Gtk";
import Gio from "gi://Gio";
import Adw from "gi://Adw";
import Xdp from "gi://Xdp";
import Source from "gi://GtkSource";
import WebKit from "gi://WebKit";

Gio._promisify(Adw.MessageDialog.prototype, "choose", "choose_finish");
Gio._promisify(Xdp.Portal.prototype, "trash_file", "trash_file_finish");
Gio._promisify(Xdp.Portal.prototype, "open_uri", "open_uri_finish");
Gio._promisify(Xdp.Portal.prototype, "open_file", "open_file_finish");
Expand Down
5 changes: 1 addition & 4 deletions src/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,7 @@ async function onCloseSession({ session, window }) {
updateSaveButton();
}

const response = await new Promise((resolve) => {
dialog.connect("response", (self, response) => resolve(response));
});

const response = await dialog.choose(null);
if (response === "cancel") return;

if (response === "discard") {
Expand Down