collapsed->expanded in other tag uses for consistency

This commit is contained in:
Damien Elmes 2021-02-02 18:49:34 +10:00
parent 8e0f69b71c
commit 467064f873
7 changed files with 24 additions and 24 deletions

View File

@ -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
#############################################################

View File

@ -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(

View File

@ -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 {

View File

@ -1412,10 +1412,10 @@ impl BackendService for Backend {
})
}
fn set_tag_collapsed(&self, input: pb::SetTagCollapsedIn) -> BackendResult<pb::Empty> {
fn set_tag_expanded(&self, input: pb::SetTagExpandedIn) -> BackendResult<pb::Empty> {
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())
})
})

View File

@ -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(())
}

View File

@ -11,7 +11,7 @@ fn row_to_tag(row: &Row) -> Result<Tag> {
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(())
}

View File

@ -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<impl Iterator<Item = Tag>>, 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<R: Replacer>(
@ -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(())
}