mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
add bookmarks limit option
This commit is contained in:
parent
ce14920d23
commit
1c4bde4004
3 changed files with 9 additions and 5 deletions
|
|
@ -207,7 +207,7 @@ impl Menu for MenuButton {
|
||||||
move |_| {
|
move |_| {
|
||||||
// Bookmarks
|
// Bookmarks
|
||||||
main_bookmarks.remove_all();
|
main_bookmarks.remove_all();
|
||||||
for bookmark in profile.bookmark.recent() {
|
for bookmark in profile.bookmark.recent(None) {
|
||||||
let menu_item = gio::MenuItem::new(Some(&ellipsize(&bookmark.request, LABEL_MAX_LENGTH)), None);
|
let menu_item = gio::MenuItem::new(Some(&ellipsize(&bookmark.request, LABEL_MAX_LENGTH)), None);
|
||||||
menu_item.set_action_and_target_value(Some(&format!(
|
menu_item.set_action_and_target_value(Some(&format!(
|
||||||
"{}.{}",
|
"{}.{}",
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,8 @@ impl Bookmark {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get recent Items vector from `memory`, sorted by `ID` DESC
|
/// Get recent Items vector from `memory`, sorted by `ID` DESC
|
||||||
pub fn recent(&self) -> Vec<Item> {
|
pub fn recent(&self, limit: Option<usize>) -> Vec<Item> {
|
||||||
self.memory.borrow().recent()
|
self.memory.borrow().recent(limit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,17 @@ impl Memory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get recent Items vector sorted by `ID` DESC
|
/// Get recent Items vector sorted by `ID` DESC
|
||||||
pub fn recent(&self) -> Vec<Item> {
|
pub fn recent(&self, limit: Option<usize>) -> Vec<Item> {
|
||||||
let mut recent: Vec<Item> = Vec::new();
|
let mut recent: Vec<Item> = Vec::new();
|
||||||
for item in self
|
for (i, item) in self
|
||||||
.0
|
.0
|
||||||
.iter()
|
.iter()
|
||||||
.sorted_by(|a, b| Ord::cmp(&b.request, &a.request))
|
.sorted_by(|a, b| Ord::cmp(&b.request, &a.request))
|
||||||
|
.enumerate()
|
||||||
{
|
{
|
||||||
|
if limit.is_some_and(|l| i > l) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
recent.push(item.clone())
|
recent.push(item.clone())
|
||||||
}
|
}
|
||||||
recent
|
recent
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue