From 467064f873a0bdc2333a92fec1fe0a128f721913 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 2 Feb 2021 18:49:34 +1000 Subject: [PATCH] collapsed->expanded in other tag uses for consistency --- pylib/anki/tags.py | 6 +++--- qt/aqt/sidebar.py | 4 ++-- rslib/backend.proto | 6 +++--- rslib/src/backend/mod.rs | 4 ++-- rslib/src/dbcheck.rs | 6 +++--- rslib/src/storage/tag/mod.rs | 4 ++-- rslib/src/tags.rs | 18 +++++++++--------- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/pylib/anki/tags.py b/pylib/anki/tags.py index 7fa0d99ff..2eab6a3c8 100644 --- a/pylib/anki/tags.py +++ b/pylib/anki/tags.py @@ -68,9 +68,9 @@ class TagManager: res = self.col.db.list(query) return list(set(self.split(" ".join(res)))) - def set_collapsed(self, tag: str, collapsed: bool) -> None: - "Set browser collapse state for tag, registering the tag if missing." - self.col._backend.set_tag_collapsed(name=tag, collapsed=collapsed) + def set_expanded(self, tag: str, expanded: bool) -> None: + "Set browser expansion state for tag, registering the tag if missing." + self.col._backend.set_tag_expanded(name=tag, expanded=expanded) # Bulk addition/removal from notes ############################################################# diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index 9bc5c80aa..85b9614d0 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -539,8 +539,8 @@ class SidebarTreeView(QTreeView): def toggle_expand() -> Callable[[bool], None]: full_name = head + node.name # pylint: disable=cell-var-from-loop - return lambda expanded: self.mw.col.tags.set_collapsed( - full_name, not expanded + return lambda expanded: self.mw.col.tags.set_expanded( + full_name, expanded ) item = SidebarItem( diff --git a/rslib/backend.proto b/rslib/backend.proto index 88d9271e8..196add3a3 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -217,7 +217,7 @@ service BackendService { rpc ClearUnusedTags(Empty) returns (Empty); rpc AllTags(Empty) returns (StringList); - rpc SetTagCollapsed(SetTagCollapsedIn) returns (Empty); + rpc SetTagExpanded(SetTagExpandedIn) returns (Empty); rpc ClearTag(String) returns (Empty); rpc TagTree(Empty) returns (TagTreeNode); @@ -846,9 +846,9 @@ message AddOrUpdateDeckConfigLegacyIn { bool preserve_usn_and_mtime = 2; } -message SetTagCollapsedIn { +message SetTagExpandedIn { string name = 1; - bool collapsed = 2; + bool expanded = 2; } message GetChangedTagsOut { diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index 924235c05..cce55d3d1 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -1412,10 +1412,10 @@ impl BackendService for Backend { }) } - fn set_tag_collapsed(&self, input: pb::SetTagCollapsedIn) -> BackendResult { + fn set_tag_expanded(&self, input: pb::SetTagExpandedIn) -> BackendResult { self.with_col(|col| { col.transact(None, |col| { - col.set_tag_collapsed(&input.name, input.collapsed)?; + col.set_tag_expanded(&input.name, input.expanded)?; Ok(().into()) }) }) diff --git a/rslib/src/dbcheck.rs b/rslib/src/dbcheck.rs index cf7e7a203..9035de2f8 100644 --- a/rslib/src/dbcheck.rs +++ b/rslib/src/dbcheck.rs @@ -646,12 +646,12 @@ mod test { note.tags.push("two".into()); col.add_note(&mut note, DeckID(1))?; - col.set_tag_collapsed("one", false)?; + col.set_tag_expanded("one", true)?; col.check_database(progress_fn)?; - assert_eq!(col.storage.get_tag("one")?.unwrap().collapsed, false); - assert_eq!(col.storage.get_tag("two")?.unwrap().collapsed, true); + assert_eq!(col.storage.get_tag("one")?.unwrap().expanded, true); + assert_eq!(col.storage.get_tag("two")?.unwrap().expanded, false); Ok(()) } diff --git a/rslib/src/storage/tag/mod.rs b/rslib/src/storage/tag/mod.rs index 3965097d4..d3c56c2a2 100644 --- a/rslib/src/storage/tag/mod.rs +++ b/rslib/src/storage/tag/mod.rs @@ -11,7 +11,7 @@ fn row_to_tag(row: &Row) -> Result { Ok(Tag { name: row.get(0)?, usn: row.get(1)?, - collapsed: row.get(2)?, + expanded: !row.get(2)?, }) } @@ -52,7 +52,7 @@ impl SqliteStorage { pub(crate) fn register_tag(&self, tag: &Tag) -> Result<()> { self.db .prepare_cached(include_str!("add.sql"))? - .execute(params![tag.name, tag.usn, tag.collapsed])?; + .execute(params![tag.name, tag.usn, !tag.expanded])?; Ok(()) } diff --git a/rslib/src/tags.rs b/rslib/src/tags.rs index 1956b4e1e..87f50438b 100644 --- a/rslib/src/tags.rs +++ b/rslib/src/tags.rs @@ -18,7 +18,7 @@ use unicase::UniCase; pub struct Tag { pub name: String, pub usn: Usn, - pub collapsed: bool, + pub expanded: bool, } impl Tag { @@ -26,7 +26,7 @@ impl Tag { Tag { name, usn, - collapsed: true, + expanded: false, } } } @@ -151,7 +151,7 @@ fn add_child_nodes(tags: &mut Peekable>, parent: &mut name: (*split_name.last().unwrap()).into(), children: vec![], level: parent.level + 1, - expanded: !tag.collapsed, + expanded: tag.expanded, }); tags.next(); } @@ -259,7 +259,7 @@ impl Collection { for name in self.storage.all_tags_in_notes()? { let name = normalize_tag_name(&name).into(); self.storage.register_tag(&Tag { - collapsed: !expanded.contains(&name), + expanded: expanded.contains(&name), name, usn, })?; @@ -268,7 +268,7 @@ impl Collection { Ok(()) } - pub(crate) fn set_tag_collapsed(&self, name: &str, collapsed: bool) -> Result<()> { + pub(crate) fn set_tag_expanded(&self, name: &str, expanded: bool) -> Result<()> { let mut name = name; let tag; if self.storage.get_tag(name)?.is_none() { @@ -277,7 +277,7 @@ impl Collection { self.storage.register_tag(&tag)?; name = &tag.name; } - self.storage.set_tag_collapsed(name, collapsed) + self.storage.set_tag_collapsed(name, !expanded) } fn replace_tags_for_notes_inner( @@ -588,10 +588,10 @@ mod test { note.tags.push("two".into()); col.add_note(&mut note, DeckID(1))?; - col.set_tag_collapsed("one", false)?; + col.set_tag_expanded("one", true)?; col.clear_unused_tags()?; - assert_eq!(col.storage.get_tag("one")?.unwrap().collapsed, false); - assert_eq!(col.storage.get_tag("two")?.unwrap().collapsed, true); + assert_eq!(col.storage.get_tag("one")?.unwrap().expanded, true); + assert_eq!(col.storage.get_tag("two")?.unwrap().expanded, false); Ok(()) }