Add layout dialog helper.
This commit is contained in:
1 parent
448e31ae88
commit
3721ec38ba
9 files changed
+1185
-25
No files matched your search
+31
-8
@@ -33,6 +33,7 @@ const gtk = @import("gtk");
|
||||
|
||||
const Layouts = @import("Layouts.zig");
|
||||
const PaletteEditor = @import("PaletteEditor.zig");
|
||||
const PathEntry = @import("PathEntry.zig");
|
||||
const Settings = @import("Settings.zig");
|
||||
const appearance = @import("appearance.zig");
|
||||
|
||||
@@ -64,6 +65,10 @@ const plain_label = "Plain terminal";
|
||||
/// be reading freed memory at the next keystroke.
|
||||
const ParamField = struct {
|
||||
name: []u8,
|
||||
|
||||
/// The text box holding the value. For a directory parameter it is the one
|
||||
/// inside a `PathEntry`, which frees itself with its widgets — so a row
|
||||
/// rebuilt for a different layout leaves nothing of it behind to track.
|
||||
entry: *gtk.Entry,
|
||||
};
|
||||
|
||||
@@ -553,9 +558,33 @@ fn fillParams(
|
||||
const field = try self.alloc.create(ParamField);
|
||||
errdefer self.alloc.destroy(field);
|
||||
|
||||
var hint_buf: [128]u8 = undefined;
|
||||
const placeholder: ?[*:0]const u8 =
|
||||
std.fmt.bufPrintZ(&hint_buf, "{{{{{s}}}}}", .{param.name}) catch null;
|
||||
const value = valueOf(values, param.name) orelse param.default;
|
||||
|
||||
// The same two shapes the layout prompt offers, for the same reason: a
|
||||
// startup entry names the same directories, and picking one out of a
|
||||
// chooser here is worth as much as it is there.
|
||||
const entry, const widget = switch (param.type) {
|
||||
.string => blk: {
|
||||
const e = gtk.Entry.new();
|
||||
e.setPlaceholderText(placeholder);
|
||||
e.as(gtk.Widget).setHexpand(1);
|
||||
setEntryText(e, value);
|
||||
break :blk .{ e, e.as(gtk.Widget) };
|
||||
},
|
||||
.directory => blk: {
|
||||
const path = try PathEntry.create(self.alloc);
|
||||
path.setPlaceholderText(placeholder);
|
||||
path.setText(value);
|
||||
break :blk .{ path.entry, path.widget() };
|
||||
},
|
||||
};
|
||||
|
||||
field.* = .{
|
||||
.name = try self.alloc.dupe(u8, param.name),
|
||||
.entry = gtk.Entry.new(),
|
||||
.entry = entry,
|
||||
};
|
||||
errdefer self.alloc.free(field.name);
|
||||
|
||||
@@ -568,12 +597,6 @@ fn fillParams(
|
||||
label.as(gtk.Widget).addCssClass("playpen-dialog-sublabel");
|
||||
grid.attach(label.as(gtk.Widget), 0, @intCast(i), 1, 1);
|
||||
|
||||
var hint_buf: [128]u8 = undefined;
|
||||
field.entry.setPlaceholderText(
|
||||
std.fmt.bufPrintZ(&hint_buf, "{{{{{s}}}}}", .{param.name}) catch null,
|
||||
);
|
||||
field.entry.as(gtk.Widget).setHexpand(1);
|
||||
setEntryText(field.entry, valueOf(values, param.name) orelse param.default);
|
||||
_ = gtk.Editable.signals.changed.connect(
|
||||
field.entry,
|
||||
*StartupRow,
|
||||
@@ -581,7 +604,7 @@ fn fillParams(
|
||||
row,
|
||||
.{},
|
||||
);
|
||||
grid.attach(field.entry.as(gtk.Widget), 1, @intCast(i), 1, 1);
|
||||
grid.attach(widget, 1, @intCast(i), 1, 1);
|
||||
|
||||
try row.params.append(self.alloc, field);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user