Added a hopeful quit blocking dialog.

This commit is contained in:
Greyson Parrelli committed 2026-08-25 16:24:00 -04:00
1 parent 3721ec38ba
commit 198258c181
4 files changed
+292 -2

No files matched your search

+78
View File
@@ -105,6 +105,10 @@ theme_buttons: [std.enums.values(Settings.Theme).len]*gtk.ToggleButton,
/// changes which palette it is editing, so it has to be told.
colors: *PaletteEditor,
/// The confirm-before-quitting toggle. Held only so the switch can be built in
/// one place and read in another; nothing re-checks it.
confirm_quit: *gtk.Switch,
/// Container the startup rows live in, so rows can be added and removed after
/// the page is already on screen.
startup_box: *gtk.Box,
@@ -140,6 +144,7 @@ pub fn present(alloc: std.mem.Allocator, parent: *gtk.Window, opts: Options) !vo
.ctx = opts.ctx,
.theme_buttons = undefined,
.colors = undefined,
.confirm_quit = gtk.Switch.new(),
.startup_box = gtk.Box.new(.vertical, 6),
.error_label = gtk.Label.new(null),
};
@@ -160,6 +165,7 @@ pub fn present(alloc: std.mem.Allocator, parent: *gtk.Window, opts: Options) !vo
content.as(gtk.Widget).addCssClass("playpen-dialog-content");
content.append(self.buildAppearance());
content.append(self.buildQuitting());
content.append(self.buildStartup());
self.error_label.setXalign(0);
@@ -324,6 +330,78 @@ fn onThemeToggled(button: *gtk.ToggleButton, self: *SettingsDialog) callconv(.c)
self.colors.refresh();
}
// -------------------------------------------------------------------------
// Quitting
/// The Quitting section: whether closing the window asks first.
///
/// Above the startup list rather than below it. That list grows with the number
/// of tabs someone opens at launch, and a single-row group underneath it would
/// be reachable only by scrolling past every one of them.
fn buildQuitting(self: *SettingsDialog) *gtk.Widget {
const group = gtk.Box.new(.vertical, 10);
group.as(gtk.Widget).addCssClass("playpen-settings-group");
const title = gtk.Label.new("Quitting");
title.setXalign(0);
title.as(gtk.Widget).addCssClass("playpen-settings-title");
group.append(title.as(gtk.Widget));
const row = gtk.Box.new(.horizontal, 12);
const labels = gtk.Box.new(.vertical, 2);
labels.as(gtk.Widget).setHexpand(1);
labels.as(gtk.Widget).setValign(.center);
const name = gtk.Label.new("Confirm before closing the window");
name.setXalign(0);
name.as(gtk.Widget).addCssClass("playpen-dialog-label");
labels.append(name.as(gtk.Widget));
const hint_label = gtk.Label.new(
"Closing the window exits every shell in every tab. Off, the window " ++
"goes the moment the window manager says so.",
);
hint_label.setXalign(0);
hint_label.setWrap(1);
hint_label.as(gtk.Widget).addCssClass("playpen-dialog-sublabel");
labels.append(hint_label.as(gtk.Widget));
row.append(labels.as(gtk.Widget));
self.confirm_quit.setActive(@intFromBool(Settings.get().confirm_quit));
self.confirm_quit.as(gtk.Widget).setValign(.center);
_ = gobject.Object.signals.notify.connect(
self.confirm_quit,
*SettingsDialog,
&onConfirmQuitChanged,
self,
.{ .detail = "active" },
);
row.append(self.confirm_quit.as(gtk.Widget));
group.append(row.as(gtk.Widget));
return group.as(gtk.Widget);
}
/// Straight to the file, as the theme picker does, rather than through
/// `persist`: this is one flag, and `commit` would re-read every startup row to
/// save it.
fn onConfirmQuitChanged(
toggle: *gtk.Switch,
_: *gobject.ParamSpec,
self: *SettingsDialog,
) callconv(.c) void {
Settings.get().confirm_quit = toggle.getActive() != 0;
Settings.get().save() catch {
self.showError("Could not write the settings file.");
return;
};
self.showError(null);
}
// -------------------------------------------------------------------------
// Startup
//