mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
collapsed->expanded in TagTreeNode
This commit is contained in:
parent
7d8448a321
commit
52b256663f
5 changed files with 14 additions and 13 deletions
|
@ -548,7 +548,7 @@ class SidebarTreeView(QTreeView):
|
|||
icon,
|
||||
self._filter_func(SearchTerm(tag=head + node.name)),
|
||||
toggle_expand(),
|
||||
not node.collapsed,
|
||||
node.expanded,
|
||||
item_type=SidebarItemType.TAG,
|
||||
full_name=head + node.name,
|
||||
)
|
||||
|
|
|
@ -865,7 +865,7 @@ message TagTreeNode {
|
|||
string name = 1;
|
||||
repeated TagTreeNode children = 2;
|
||||
uint32 level = 3;
|
||||
bool collapsed = 4;
|
||||
bool expanded = 4;
|
||||
}
|
||||
|
||||
message SetConfigJsonIn {
|
||||
|
|
|
@ -242,7 +242,7 @@ impl Collection {
|
|||
let usn = self.usn()?;
|
||||
let stamp = TimestampMillis::now();
|
||||
|
||||
let collapsed_tags = self.storage.collapsed_tags()?;
|
||||
let expanded_tags = self.storage.expanded_tags()?;
|
||||
self.storage.clear_tags()?;
|
||||
|
||||
let total_notes = self.storage.total_notes()?;
|
||||
|
@ -296,7 +296,7 @@ impl Collection {
|
|||
|
||||
// the note rebuilding process took care of adding tags back, so we just need
|
||||
// to ensure to restore the collapse state
|
||||
self.storage.restore_collapsed_tags(&collapsed_tags)?;
|
||||
self.storage.restore_expanded_tags(&expanded_tags)?;
|
||||
|
||||
// if the collection is empty and the user has deleted all note types, ensure at least
|
||||
// one note type exists
|
||||
|
@ -646,7 +646,7 @@ mod test {
|
|||
note.tags.push("two".into());
|
||||
col.add_note(&mut note, DeckID(1))?;
|
||||
|
||||
col.set_tag_collapsed("two", true)?;
|
||||
col.set_tag_collapsed("one", false)?;
|
||||
|
||||
col.check_database(progress_fn)?;
|
||||
|
||||
|
|
|
@ -24,17 +24,17 @@ impl SqliteStorage {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn collapsed_tags(&self) -> Result<Vec<String>> {
|
||||
pub(crate) fn expanded_tags(&self) -> Result<Vec<String>> {
|
||||
self.db
|
||||
.prepare_cached("select tag from tags where collapsed = true")?
|
||||
.prepare_cached("select tag from tags where collapsed = false")?
|
||||
.query_and_then(NO_PARAMS, |r| r.get::<_, String>(0).map_err(Into::into))?
|
||||
.collect::<Result<Vec<_>>>()
|
||||
}
|
||||
|
||||
pub(crate) fn restore_collapsed_tags(&self, tags: &[String]) -> Result<()> {
|
||||
pub(crate) fn restore_expanded_tags(&self, tags: &[String]) -> Result<()> {
|
||||
let mut stmt = self
|
||||
.db
|
||||
.prepare_cached("update tags set collapsed = true where tag = ?")?;
|
||||
.prepare_cached("update tags set collapsed = false where tag = ?")?;
|
||||
for tag in tags {
|
||||
stmt.execute(&[tag])?;
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ fn add_child_nodes(tags: &mut Peekable<impl Iterator<Item = Tag>>, parent: &mut
|
|||
name: (*split_name.last().unwrap()).into(),
|
||||
children: vec![],
|
||||
level: parent.level + 1,
|
||||
collapsed: tag.collapsed,
|
||||
expanded: !tag.collapsed,
|
||||
});
|
||||
tags.next();
|
||||
}
|
||||
|
@ -273,13 +273,13 @@ impl Collection {
|
|||
}
|
||||
|
||||
pub fn clear_unused_tags(&self) -> Result<()> {
|
||||
let collapsed: HashSet<_> = self.storage.collapsed_tags()?.into_iter().collect();
|
||||
let expanded: HashSet<_> = self.storage.expanded_tags()?.into_iter().collect();
|
||||
self.storage.clear_tags()?;
|
||||
let usn = self.usn()?;
|
||||
for name in self.storage.all_tags_in_notes()? {
|
||||
let name = normalize_tag_name(&name).into();
|
||||
self.storage.register_tag(&Tag {
|
||||
collapsed: collapsed.contains(&name),
|
||||
collapsed: !expanded.contains(&name),
|
||||
name,
|
||||
usn,
|
||||
})?;
|
||||
|
@ -503,6 +503,7 @@ mod test {
|
|||
name: name.into(),
|
||||
level,
|
||||
children,
|
||||
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
@ -607,7 +608,7 @@ mod test {
|
|||
note.tags.push("two".into());
|
||||
col.add_note(&mut note, DeckID(1))?;
|
||||
|
||||
col.set_tag_collapsed("two", true)?;
|
||||
col.set_tag_collapsed("one", false)?;
|
||||
col.clear_unused_tags()?;
|
||||
assert_eq!(col.storage.get_tag("one")?.unwrap().collapsed, false);
|
||||
assert_eq!(col.storage.get_tag("two")?.unwrap().collapsed, true);
|
||||
|
|
Loading…
Reference in a new issue