mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
show redirection numbers
This commit is contained in:
parent
37c8a70f41
commit
ff906181a2
1 changed files with 29 additions and 13 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use super::Info;
|
use super::Info;
|
||||||
use adw::{
|
use adw::{
|
||||||
ActionRow, PreferencesDialog, PreferencesGroup, PreferencesPage,
|
ActionRow, PreferencesDialog, PreferencesGroup, PreferencesPage,
|
||||||
prelude::{PreferencesDialogExt, PreferencesGroupExt, PreferencesPageExt},
|
prelude::{ActionRowExt, PreferencesDialogExt, PreferencesGroupExt, PreferencesPageExt},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait Dialog {
|
pub trait Dialog {
|
||||||
|
|
@ -55,27 +55,43 @@ impl Dialog for PreferencesDialog {
|
||||||
});
|
});
|
||||||
if info.redirect.is_some() {
|
if info.redirect.is_some() {
|
||||||
d.add(&{
|
d.add(&{
|
||||||
// collect redirections into the vector,
|
|
||||||
// to reverse chain before add its members to widget
|
|
||||||
// * capacity optimized for Gemini protocol (as default)
|
|
||||||
let mut v = Vec::with_capacity(5);
|
|
||||||
|
|
||||||
let g = PreferencesGroup::new();
|
let g = PreferencesGroup::new();
|
||||||
let p = PreferencesPage::builder()
|
let p = PreferencesPage::builder()
|
||||||
.title("Redirect")
|
.title("Redirect")
|
||||||
.icon_name("insert-link-symbolic")
|
.icon_name("insert-link-symbolic")
|
||||||
.build();
|
.build();
|
||||||
p.add(&{
|
p.add(&{
|
||||||
fn chain<'a>(v: &mut Vec<&'a Info>, i: &'a Info) {
|
// Collect redirections into the buffer,
|
||||||
v.push(i);
|
// to reverse chain before add its members to widget
|
||||||
|
// * capacity optimized for Gemini protocol (as default)
|
||||||
|
let mut b = Vec::with_capacity(5);
|
||||||
|
/// Recursively collect redirection members into the given vector
|
||||||
|
fn chain<'a>(b: &mut Vec<&'a Info>, i: &'a Info) {
|
||||||
|
b.push(i);
|
||||||
if let Some(ref r) = i.redirect {
|
if let Some(ref r) = i.redirect {
|
||||||
chain(v, r)
|
chain(b, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chain(&mut v, info);
|
chain(&mut b, info);
|
||||||
v.reverse();
|
b.reverse();
|
||||||
for r in v {
|
let l = b.len(); // calculate once
|
||||||
g.add(&ActionRow::builder().title(r.request().unwrap()).build());
|
for (i, r) in b.iter().enumerate() {
|
||||||
|
g.add(&{
|
||||||
|
let a = ActionRow::builder().title(r.request().unwrap()).build();
|
||||||
|
a.add_prefix(&{
|
||||||
|
let c = i + 1;
|
||||||
|
gtk::Button::builder()
|
||||||
|
.css_classes([
|
||||||
|
"circular",
|
||||||
|
if c == l { "success" } else { "accent" },
|
||||||
|
])
|
||||||
|
.label(&c.to_string())
|
||||||
|
.sensitive(false)
|
||||||
|
.valign(gtk::Align::Center)
|
||||||
|
.build()
|
||||||
|
});
|
||||||
|
a
|
||||||
|
});
|
||||||
}
|
}
|
||||||
g
|
g
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue