apprt/gtk: hook up next/prev match

pull/9756/head
Mitchell Hashimoto 2025-11-29 15:27:52 -08:00
parent 0ea85fc483
commit 76496d40fd
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
4 changed files with 68 additions and 0 deletions

View File

@ -102,6 +102,30 @@ pub const SearchOverlay = extern struct {
void, void,
); );
}; };
/// Emitted when navigating to the next match.
pub const @"next-match" = struct {
pub const name = "next-match";
pub const connect = impl.connect;
const impl = gobject.ext.defineSignal(
name,
Self,
&.{},
void,
);
};
/// Emitted when navigating to the previous match.
pub const @"previous-match" = struct {
pub const name = "previous-match";
pub const connect = impl.connect;
const impl = gobject.ext.defineSignal(
name,
Self,
&.{},
void,
);
};
}; };
const Private = struct { const Private = struct {
@ -168,6 +192,22 @@ pub const SearchOverlay = extern struct {
signals.@"search-changed".impl.emit(self, null, .{text}, null); signals.@"search-changed".impl.emit(self, null, .{text}, null);
} }
fn nextMatch(_: *gtk.Button, self: *Self) callconv(.c) void {
signals.@"next-match".impl.emit(self, null, .{}, null);
}
fn previousMatch(_: *gtk.Button, self: *Self) callconv(.c) void {
signals.@"previous-match".impl.emit(self, null, .{}, null);
}
fn nextMatchEntry(_: *gtk.SearchEntry, self: *Self) callconv(.c) void {
signals.@"next-match".impl.emit(self, null, .{}, null);
}
fn previousMatchEntry(_: *gtk.SearchEntry, self: *Self) callconv(.c) void {
signals.@"previous-match".impl.emit(self, null, .{}, null);
}
//--------------------------------------------------------------- //---------------------------------------------------------------
// Virtual methods // Virtual methods
@ -224,6 +264,10 @@ pub const SearchOverlay = extern struct {
class.bindTemplateCallback("stop_search", &stopSearch); class.bindTemplateCallback("stop_search", &stopSearch);
class.bindTemplateCallback("search_changed", &searchChanged); class.bindTemplateCallback("search_changed", &searchChanged);
class.bindTemplateCallback("match_label_closure", &closureMatchLabel); class.bindTemplateCallback("match_label_closure", &closureMatchLabel);
class.bindTemplateCallback("next_match", &nextMatch);
class.bindTemplateCallback("previous_match", &previousMatch);
class.bindTemplateCallback("next_match_entry", &nextMatchEntry);
class.bindTemplateCallback("previous_match_entry", &previousMatchEntry);
// Properties // Properties
gobject.ext.registerProperties(class, &.{ gobject.ext.registerProperties(class, &.{
@ -235,6 +279,8 @@ pub const SearchOverlay = extern struct {
// Signals // Signals
signals.@"stop-search".impl.register(.{}); signals.@"stop-search".impl.register(.{});
signals.@"search-changed".impl.register(.{}); signals.@"search-changed".impl.register(.{});
signals.@"next-match".impl.register(.{});
signals.@"previous-match".impl.register(.{});
// Virtual methods // Virtual methods
gobject.Object.virtual_methods.dispose.implement(class, &dispose); gobject.Object.virtual_methods.dispose.implement(class, &dispose);

View File

@ -3211,6 +3211,20 @@ pub const Surface = extern struct {
}; };
} }
fn searchNextMatch(_: *SearchOverlay, self: *Self) callconv(.c) void {
const surface = self.core() orelse return;
_ = surface.performBindingAction(.{ .navigate_search = .next }) catch |err| {
log.warn("unable to perform navigate_search action err={}", .{err});
};
}
fn searchPreviousMatch(_: *SearchOverlay, self: *Self) callconv(.c) void {
const surface = self.core() orelse return;
_ = surface.performBindingAction(.{ .navigate_search = .previous }) catch |err| {
log.warn("unable to perform navigate_search action err={}", .{err});
};
}
const C = Common(Self, Private); const C = Common(Self, Private);
pub const as = C.as; pub const as = C.as;
pub const ref = C.ref; pub const ref = C.ref;
@ -3285,6 +3299,8 @@ pub const Surface = extern struct {
class.bindTemplateCallback("should_unfocused_split_be_shown", &closureShouldUnfocusedSplitBeShown); class.bindTemplateCallback("should_unfocused_split_be_shown", &closureShouldUnfocusedSplitBeShown);
class.bindTemplateCallback("search_stop", &searchStop); class.bindTemplateCallback("search_stop", &searchStop);
class.bindTemplateCallback("search_changed", &searchChanged); class.bindTemplateCallback("search_changed", &searchChanged);
class.bindTemplateCallback("search_next_match", &searchNextMatch);
class.bindTemplateCallback("search_previous_match", &searchPreviousMatch);
// Properties // Properties
gobject.ext.registerProperties(class, &.{ gobject.ext.registerProperties(class, &.{

View File

@ -23,6 +23,8 @@ template $GhosttySearchOverlay: Adw.Bin {
hexpand: true; hexpand: true;
stop-search => $stop_search(); stop-search => $stop_search();
search-changed => $search_changed(); search-changed => $search_changed();
next-match => $next_match_entry();
previous-match => $previous_match_entry();
} }
Label { Label {
@ -46,6 +48,7 @@ template $GhosttySearchOverlay: Adw.Bin {
Button prev_button { Button prev_button {
icon-name: "go-up-symbolic"; icon-name: "go-up-symbolic";
tooltip-text: _("Previous Match"); tooltip-text: _("Previous Match");
clicked => $next_match();
cursor: Gdk.Cursor { cursor: Gdk.Cursor {
name: "pointer"; name: "pointer";
@ -55,6 +58,7 @@ template $GhosttySearchOverlay: Adw.Bin {
Button next_button { Button next_button {
icon-name: "go-down-symbolic"; icon-name: "go-down-symbolic";
tooltip-text: _("Next Match"); tooltip-text: _("Next Match");
clicked => $previous_match();
cursor: Gdk.Cursor { cursor: Gdk.Cursor {
name: "pointer"; name: "pointer";

View File

@ -153,6 +153,8 @@ Overlay terminal_page {
valign: start; valign: start;
stop-search => $search_stop(); stop-search => $search_stop();
search-changed => $search_changed(); search-changed => $search_changed();
next-match => $search_next_match();
previous-match => $search_previous_match();
} }
[overlay] [overlay]