From 52b256663fc9733526ad0c0692308a2a90fa19c9 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 2 Feb 2021 18:12:50 +1000 Subject: [PATCH] collapsed->expanded in TagTreeNode --- qt/aqt/sidebar.py | 2 +- rslib/backend.proto | 2 +- rslib/src/dbcheck.rs | 6 +++--- rslib/src/storage/tag/mod.rs | 8 ++++---- rslib/src/tags.rs | 9 +++++---- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index 07f4281b3..9bc5c80aa 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -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, ) diff --git a/rslib/backend.proto b/rslib/backend.proto index 70e436a7c..526488c2b 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -865,7 +865,7 @@ message TagTreeNode { string name = 1; repeated TagTreeNode children = 2; uint32 level = 3; - bool collapsed = 4; + bool expanded = 4; } message SetConfigJsonIn { diff --git a/rslib/src/dbcheck.rs b/rslib/src/dbcheck.rs index 0ca55361b..cf7e7a203 100644 --- a/rslib/src/dbcheck.rs +++ b/rslib/src/dbcheck.rs @@ -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)?; diff --git a/rslib/src/storage/tag/mod.rs b/rslib/src/storage/tag/mod.rs index e0f1b0bd4..3965097d4 100644 --- a/rslib/src/storage/tag/mod.rs +++ b/rslib/src/storage/tag/mod.rs @@ -24,17 +24,17 @@ impl SqliteStorage { .collect() } - pub(crate) fn collapsed_tags(&self) -> Result> { + pub(crate) fn expanded_tags(&self) -> Result> { 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::>>() } - 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])?; } diff --git a/rslib/src/tags.rs b/rslib/src/tags.rs index cf209fa93..7994af592 100644 --- a/rslib/src/tags.rs +++ b/rslib/src/tags.rs @@ -171,7 +171,7 @@ fn add_child_nodes(tags: &mut Peekable>, 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);