From e58a2a3a9071a35408634b41275895dd473efe19 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 15 Dec 2024 17:29:31 +0200 Subject: [PATCH] move `connect_icon_release` to constructor --- .../content/text/gemini/reader/widget/find.rs | 8 +------- .../text/gemini/reader/widget/find/entry.rs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find.rs index 6ffe9eae..b90cf948 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find.rs @@ -9,8 +9,7 @@ use tag::Tag; use gtk::{ prelude::{BoxExt, ButtonExt, CheckButtonExt, EditableExt, EntryExt, TextBufferExt, WidgetExt}, - Box, Button, Entry, EntryIconPosition, Orientation, TextBuffer, TextIter, TextSearchFlags, - TextTag, + Box, Button, Entry, Orientation, TextBuffer, TextIter, TextSearchFlags, TextTag, }; use std::{cell::Cell, rc::Rc}; @@ -84,11 +83,6 @@ impl Find { } }); - entry.connect_icon_release(move |this, position| match position { - EntryIconPosition::Secondary => this.delete_text(0, -1), - _ => todo!(), // unexpected - }); - match_case.connect_toggled({ let entry = entry.clone(); let found_tag = tag.found.clone(); diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/entry.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/entry.rs index 0d7f5e4c..2d71cacf 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/entry.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/entry.rs @@ -1,8 +1,12 @@ use super::MARGIN; -use gtk::Entry; +use gtk::{ + prelude::{EditableExt, EntryExt}, + Entry, EntryIconPosition, +}; pub fn new() -> Entry { - Entry::builder() + // Init widget + let entry = Entry::builder() .hexpand(true) .margin_bottom(MARGIN) .margin_end(MARGIN) @@ -12,5 +16,14 @@ pub fn new() -> Entry { .primary_icon_activatable(false) .primary_icon_sensitive(false) .primary_icon_name("system-search-symbolic") - .build() + .build(); + + // Connect events + entry.connect_icon_release(|this, position| match position { + EntryIconPosition::Secondary => this.delete_text(0, -1), + _ => todo!(), // unexpected + }); + + // Done + entry }