mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 09:10:08 +00:00
toggle find action depending of content type
This commit is contained in:
parent
3c82ab9de9
commit
957e56cc3e
@ -19,13 +19,12 @@ impl Find {
|
|||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
let simple_action =
|
||||||
simple_action: SimpleAction::new_stateful(
|
SimpleAction::new_stateful(&uuid_string_random(), None, &DEFAULT_STATE.to_variant());
|
||||||
&uuid_string_random(),
|
|
||||||
None,
|
simple_action.set_enabled(false);
|
||||||
&DEFAULT_STATE.to_variant(),
|
|
||||||
),
|
Self { simple_action }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
@ -38,6 +38,7 @@ pub struct Page {
|
|||||||
// Actions
|
// Actions
|
||||||
browser_action: Rc<BrowserAction>,
|
browser_action: Rc<BrowserAction>,
|
||||||
tab_action: Rc<TabAction>,
|
tab_action: Rc<TabAction>,
|
||||||
|
window_action: Rc<WindowAction>,
|
||||||
// Components
|
// Components
|
||||||
pub client: Rc<Client>,
|
pub client: Rc<Client>,
|
||||||
pub content: Rc<Content>,
|
pub content: Rc<Content>,
|
||||||
@ -53,14 +54,22 @@ impl Page {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
id: Rc<GString>,
|
id: Rc<GString>,
|
||||||
profile: Rc<Profile>,
|
profile: Rc<Profile>,
|
||||||
action: (Rc<BrowserAction>, Rc<WindowAction>, Rc<TabAction>),
|
(browser_action, window_action, tab_action): (
|
||||||
|
Rc<BrowserAction>,
|
||||||
|
Rc<WindowAction>,
|
||||||
|
Rc<TabAction>,
|
||||||
|
),
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// Init components
|
// Init components
|
||||||
let content = Rc::new(Content::new((action.1.clone(), action.2.clone())));
|
let content = Rc::new(Content::new((window_action.clone(), tab_action.clone())));
|
||||||
|
|
||||||
let navigation = Rc::new(Navigation::new(
|
let navigation = Rc::new(Navigation::new(
|
||||||
profile.clone(),
|
profile.clone(),
|
||||||
(action.0.clone(), action.1.clone(), action.2.clone()),
|
(
|
||||||
|
browser_action.clone(),
|
||||||
|
window_action.clone(),
|
||||||
|
tab_action.clone(),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
let input = Rc::new(Input::new());
|
let input = Rc::new(Input::new());
|
||||||
@ -79,8 +88,9 @@ impl Page {
|
|||||||
id,
|
id,
|
||||||
profile,
|
profile,
|
||||||
// Actions
|
// Actions
|
||||||
browser_action: action.0,
|
browser_action,
|
||||||
tab_action: action.2,
|
tab_action,
|
||||||
|
window_action,
|
||||||
// Components
|
// Components
|
||||||
client: Rc::new(Client::new()),
|
client: Rc::new(Client::new()),
|
||||||
content,
|
content,
|
||||||
@ -151,6 +161,9 @@ impl Page {
|
|||||||
// Move focus out from navigation entry
|
// Move focus out from navigation entry
|
||||||
self.browser_action.focus.activate();
|
self.browser_action.focus.activate();
|
||||||
|
|
||||||
|
// Initially disable find action
|
||||||
|
self.window_action.find.simple_action.set_enabled(false);
|
||||||
|
|
||||||
// Reset widgets
|
// Reset widgets
|
||||||
self.input.unset();
|
self.input.unset();
|
||||||
|
|
||||||
@ -356,13 +369,14 @@ impl Page {
|
|||||||
|
|
||||||
// Init shared clones
|
// Init shared clones
|
||||||
let cancellable = self.client.cancellable();
|
let cancellable = self.client.cancellable();
|
||||||
let update = self.browser_action.update.clone();
|
|
||||||
let tab_action = self.tab_action.clone();
|
|
||||||
let navigation = self.navigation.clone();
|
|
||||||
let content = self.content.clone();
|
let content = self.content.clone();
|
||||||
|
let find = self.window_action.find.clone();
|
||||||
let id = self.id.clone();
|
let id = self.id.clone();
|
||||||
let input = self.input.clone();
|
let input = self.input.clone();
|
||||||
let meta = self.meta.clone();
|
let meta = self.meta.clone();
|
||||||
|
let navigation = self.navigation.clone();
|
||||||
|
let tab_action = self.tab_action.clone();
|
||||||
|
let update = self.browser_action.update.clone();
|
||||||
|
|
||||||
// Listen for connection status updates
|
// Listen for connection status updates
|
||||||
self.client.gemini.socket.connect_event({
|
self.client.gemini.socket.connect_event({
|
||||||
@ -515,6 +529,7 @@ impl Page {
|
|||||||
cancellable.clone(),
|
cancellable.clone(),
|
||||||
{
|
{
|
||||||
let content = content.clone();
|
let content = content.clone();
|
||||||
|
let find = find.clone();
|
||||||
let id = id.clone();
|
let id = id.clone();
|
||||||
let meta = meta.clone();
|
let meta = meta.clone();
|
||||||
let update = update.clone();
|
let update = update.clone();
|
||||||
@ -524,26 +539,26 @@ impl Page {
|
|||||||
Ok(buffer) => {
|
Ok(buffer) => {
|
||||||
// Set children component,
|
// Set children component,
|
||||||
// extract title from meta parsed
|
// extract title from meta parsed
|
||||||
let title = if is_source {
|
let text = if is_source {
|
||||||
content.to_text_source(
|
content.to_text_source(
|
||||||
&buffer.data
|
&buffer.data
|
||||||
);
|
)
|
||||||
uri_to_title(&uri)
|
|
||||||
} else {
|
} else {
|
||||||
match content.to_text_gemini(
|
content.to_text_gemini(
|
||||||
&uri,
|
&uri,
|
||||||
&buffer.data
|
&buffer.data
|
||||||
).meta.title {
|
)
|
||||||
Some(meta_title) => meta_title,
|
|
||||||
None => uri_to_title(&uri)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update page meta
|
// Update page meta
|
||||||
meta.set_status(Status::Success)
|
meta.set_status(Status::Success)
|
||||||
.set_title(&title);
|
.set_title(&match text.meta.title {
|
||||||
|
Some(meta_title) => meta_title,
|
||||||
|
None => uri_to_title(&uri)
|
||||||
|
});
|
||||||
|
|
||||||
// Update window components
|
// Update window components
|
||||||
|
find.simple_action.set_enabled(text.has_search);
|
||||||
update.activate(Some(&id));
|
update.activate(Some(&id));
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -19,8 +19,9 @@ pub struct Meta {
|
|||||||
} // @TODO move to separated mod
|
} // @TODO move to separated mod
|
||||||
|
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
pub meta: Meta,
|
|
||||||
pub g_box: Box,
|
pub g_box: Box,
|
||||||
|
pub has_search: bool,
|
||||||
|
pub meta: Meta,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Text {
|
impl Text {
|
||||||
@ -86,6 +87,7 @@ impl Text {
|
|||||||
meta: Meta {
|
meta: Meta {
|
||||||
title: gemini.reader.title.clone(),
|
title: gemini.reader.title.clone(),
|
||||||
},
|
},
|
||||||
|
has_search: true,
|
||||||
g_box,
|
g_box,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,6 +103,7 @@ impl Text {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
meta: Meta { title: None },
|
meta: Meta { title: None },
|
||||||
|
has_search: false,
|
||||||
g_box,
|
g_box,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user