mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-09-12 23:12:00 +00:00
implement notice banner
This commit is contained in:
parent
a68033bc01
commit
12474b0f44
@ -63,6 +63,7 @@ impl Item {
|
|||||||
));
|
));
|
||||||
|
|
||||||
target_child.append(&page.navigation.g_box);
|
target_child.append(&page.navigation.g_box);
|
||||||
|
target_child.append(&page.notice);
|
||||||
target_child.append(&page.content.g_box);
|
target_child.append(&page.content.g_box);
|
||||||
target_child.append(&page.search.g_box);
|
target_child.append(&page.search.g_box);
|
||||||
target_child.append(&page.input.clamp);
|
target_child.append(&page.input.clamp);
|
||||||
|
@ -260,6 +260,9 @@ fn handle(
|
|||||||
_ => panic!() // unexpected
|
_ => panic!() // unexpected
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if let Some(notice) = widget.meta.notice {
|
||||||
|
page.notice(¬ice)
|
||||||
|
}
|
||||||
page.search.set(Some(widget.text_view));
|
page.search.set(Some(widget.text_view));
|
||||||
page.set_title(&match widget.meta.title {
|
page.set_title(&match widget.meta.title {
|
||||||
Some(title) => title.into(), // @TODO
|
Some(title) => title.into(), // @TODO
|
||||||
|
@ -3,14 +3,16 @@ mod database;
|
|||||||
mod error;
|
mod error;
|
||||||
mod input;
|
mod input;
|
||||||
mod navigation;
|
mod navigation;
|
||||||
|
mod notice;
|
||||||
mod search;
|
mod search;
|
||||||
|
|
||||||
use super::{Action as ItemAction, BrowserAction, Profile, TabAction, WindowAction};
|
use super::{Action as ItemAction, BrowserAction, Profile, TabAction, WindowAction};
|
||||||
use adw::TabPage;
|
use adw::{Banner, TabPage};
|
||||||
use content::Content;
|
use content::Content;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use input::Input;
|
use input::Input;
|
||||||
use navigation::Navigation;
|
use navigation::Navigation;
|
||||||
|
use notice::Notice;
|
||||||
use search::Search;
|
use search::Search;
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@ -23,9 +25,10 @@ pub struct Page {
|
|||||||
pub window_action: Rc<WindowAction>,
|
pub window_action: Rc<WindowAction>,
|
||||||
// Components
|
// Components
|
||||||
pub content: Rc<Content>,
|
pub content: Rc<Content>,
|
||||||
pub search: Rc<Search>,
|
|
||||||
pub input: Rc<Input>,
|
pub input: Rc<Input>,
|
||||||
pub navigation: Rc<Navigation>,
|
pub navigation: Rc<Navigation>,
|
||||||
|
pub notice: Banner,
|
||||||
|
pub search: Rc<Search>,
|
||||||
// System
|
// System
|
||||||
/// Reference to [TabPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabPage.html)
|
/// Reference to [TabPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabPage.html)
|
||||||
/// wanted to update title, loading status and other features related with page.
|
/// wanted to update title, loading status and other features related with page.
|
||||||
@ -56,6 +59,7 @@ impl Page {
|
|||||||
(window_action, tab_action, item_action),
|
(window_action, tab_action, item_action),
|
||||||
));
|
));
|
||||||
let input = Rc::new(Input::new());
|
let input = Rc::new(Input::new());
|
||||||
|
let notice = Banner::notice();
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
Self {
|
Self {
|
||||||
@ -67,9 +71,10 @@ impl Page {
|
|||||||
window_action: window_action.clone(),
|
window_action: window_action.clone(),
|
||||||
// Components
|
// Components
|
||||||
content,
|
content,
|
||||||
search,
|
|
||||||
input,
|
input,
|
||||||
navigation,
|
navigation,
|
||||||
|
notice,
|
||||||
|
search,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,6 +104,11 @@ impl Page {
|
|||||||
self.search.show()
|
self.search.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Toggle `Notice` widget
|
||||||
|
pub fn notice(&self, title: &str) {
|
||||||
|
self.notice.show(title)
|
||||||
|
}
|
||||||
|
|
||||||
/// Cleanup session for `Self`
|
/// Cleanup session for `Self`
|
||||||
pub fn clean(
|
pub fn clean(
|
||||||
&self,
|
&self,
|
||||||
|
@ -12,6 +12,7 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
pub struct Meta {
|
pub struct Meta {
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
|
pub notice: Option<String>,
|
||||||
} // @TODO move to separated mod
|
} // @TODO move to separated mod
|
||||||
|
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
@ -27,7 +28,15 @@ impl Text {
|
|||||||
gemtext: &str,
|
gemtext: &str,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// Init gemtext reader
|
// Init gemtext reader
|
||||||
let gemini = Gemini::build(actions, base, gemtext).unwrap(); // @TODO handle
|
let (gemini, notice) = match Gemini::build(actions, base, gemtext) {
|
||||||
|
Ok(gemini) => (gemini, None),
|
||||||
|
Err(e) => {
|
||||||
|
let notice = e.message();
|
||||||
|
match e {
|
||||||
|
gemini::Error::Multiline(gemini) => (gemini, Some(notice)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Init container widget
|
// Init container widget
|
||||||
let clamp_scrollable = ClampScrollable::builder()
|
let clamp_scrollable = ClampScrollable::builder()
|
||||||
@ -42,6 +51,7 @@ impl Text {
|
|||||||
text_view: gemini.text_view,
|
text_view: gemini.text_view,
|
||||||
meta: Meta {
|
meta: Meta {
|
||||||
title: gemini.title,
|
title: gemini.title,
|
||||||
|
notice,
|
||||||
},
|
},
|
||||||
scrolled_window: ScrolledWindow::builder().child(&clamp_scrollable).build(),
|
scrolled_window: ScrolledWindow::builder().child(&clamp_scrollable).build(),
|
||||||
}
|
}
|
||||||
@ -60,7 +70,10 @@ impl Text {
|
|||||||
Self {
|
Self {
|
||||||
scrolled_window: ScrolledWindow::builder().child(&clamp_scrollable).build(),
|
scrolled_window: ScrolledWindow::builder().child(&clamp_scrollable).build(),
|
||||||
text_view,
|
text_view,
|
||||||
meta: Meta { title: None },
|
meta: Meta {
|
||||||
|
title: None,
|
||||||
|
notice: None,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +82,10 @@ impl Text {
|
|||||||
Self {
|
Self {
|
||||||
scrolled_window: ScrolledWindow::builder().child(&source).build(),
|
scrolled_window: ScrolledWindow::builder().child(&source).build(),
|
||||||
text_view: source.into_text_view(),
|
text_view: source.into_text_view(),
|
||||||
meta: Meta { title: None },
|
meta: Meta {
|
||||||
|
title: None,
|
||||||
|
notice: None,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ impl Gemini {
|
|||||||
// Skip other actions for this line
|
// Skip other actions for this line
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Err(e) => return Err(Error::Gemtext(e.to_string())),
|
Err(_) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -502,6 +502,10 @@ impl Gemini {
|
|||||||
}); // @TODO may be expensive for CPU, add timeout?
|
}); // @TODO may be expensive for CPU, add timeout?
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
Ok(Self { text_view, title })
|
if is_multiline_enabled {
|
||||||
|
Ok(Self { text_view, title })
|
||||||
|
} else {
|
||||||
|
Err(Error::Multiline(Self { text_view, title }))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
use std::fmt::{Display, Formatter, Result};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Gemtext(String),
|
Multiline(super::Gemini),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Error {
|
impl Error {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
pub fn message(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Self::Gemtext(e) => {
|
Self::Multiline(_) => {
|
||||||
write!(f, "Gemtext error: {e}")
|
"Invalid multiline markup! Gemtext format partially ignored.".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
src/app/browser/window/tab/item/page/notice.rs
Normal file
24
src/app/browser/window/tab/item/page/notice.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use adw::Banner;
|
||||||
|
|
||||||
|
pub trait Notice {
|
||||||
|
fn notice() -> Self;
|
||||||
|
fn show(&self, title: &str);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Notice for Banner {
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
/// Create new `Self`
|
||||||
|
fn notice() -> Self {
|
||||||
|
let banner = Banner::builder().button_label("Ok").revealed(false).build();
|
||||||
|
banner.connect_button_clicked(|this| this.set_revealed(false));
|
||||||
|
banner
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
|
fn show(&self, title: &str) {
|
||||||
|
self.set_title(title);
|
||||||
|
self.set_revealed(true);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user