Set the paste button in the GTK dialog as default

This commit is contained in:
Daniel Fox
2024-12-31 14:18:04 -08:00
parent 3461204741
commit d3973b8fad

View File

@ -89,6 +89,8 @@ fn init(
const view = try PrimaryView.init(self, data); const view = try PrimaryView.init(self, data);
self.view = view; self.view = view;
c.gtk_window_set_child(@ptrCast(window), view.root); c.gtk_window_set_child(@ptrCast(window), view.root);
_ = c.gtk_widget_grab_focus(view.buttons.confirm_button);
c.gtk_widget_show(window); c.gtk_widget_show(window);
// Block the main window from input. // Block the main window from input.
@ -104,6 +106,7 @@ fn gtkDestroy(_: *c.GtkWidget, ud: ?*anyopaque) callconv(.C) void {
const PrimaryView = struct { const PrimaryView = struct {
root: *c.GtkWidget, root: *c.GtkWidget,
text: *c.GtkTextView, text: *c.GtkTextView,
buttons: ButtonsView,
pub fn init(root: *ClipboardConfirmation, data: []const u8) !PrimaryView { pub fn init(root: *ClipboardConfirmation, data: []const u8) !PrimaryView {
// All our widgets // All our widgets
@ -135,7 +138,7 @@ const PrimaryView = struct {
c.gtk_text_view_set_right_margin(@ptrCast(text), 8); c.gtk_text_view_set_right_margin(@ptrCast(text), 8);
c.gtk_text_view_set_monospace(@ptrCast(text), 1); c.gtk_text_view_set_monospace(@ptrCast(text), 1);
return .{ .root = view.root, .text = @ptrCast(text) }; return .{ .root = view.root, .text = @ptrCast(text), .buttons = buttons };
} }
/// Returns the GtkTextBuffer for the data that was unsafe. /// Returns the GtkTextBuffer for the data that was unsafe.
@ -158,6 +161,7 @@ const PrimaryView = struct {
const ButtonsView = struct { const ButtonsView = struct {
root: *c.GtkWidget, root: *c.GtkWidget,
confirm_button: *c.GtkWidget,
pub fn init(root: *ClipboardConfirmation) !ButtonsView { pub fn init(root: *ClipboardConfirmation) !ButtonsView {
const cancel_text, const confirm_text = switch (root.pending_req) { const cancel_text, const confirm_text = switch (root.pending_req) {
@ -172,7 +176,7 @@ const ButtonsView = struct {
errdefer c.g_object_unref(confirm_button); errdefer c.g_object_unref(confirm_button);
// TODO: Focus on the paste button // TODO: Focus on the paste button
// c.gtk_widget_grab_focus(confirm_button); _ = c.gtk_widget_grab_focus(confirm_button);
// Create our view // Create our view
const view = try View.init(&.{ const view = try View.init(&.{
@ -198,7 +202,7 @@ const ButtonsView = struct {
c.G_CONNECT_DEFAULT, c.G_CONNECT_DEFAULT,
); );
return .{ .root = view.root }; return .{ .root = view.root, .confirm_button = confirm_button };
} }
fn gtkCancelClick(_: *c.GtkWidget, ud: ?*anyopaque) callconv(.C) void { fn gtkCancelClick(_: *c.GtkWidget, ud: ?*anyopaque) callconv(.C) void {