mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
return tags as a string list directly; we don't need usn or collapse state
This commit is contained in:
parent
52b256663f
commit
8e0f69b71c
4 changed files with 20 additions and 49 deletions
|
@ -13,7 +13,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import pprint
|
import pprint
|
||||||
import re
|
import re
|
||||||
from typing import Collection, List, Match, Optional, Sequence, Tuple
|
from typing import Collection, List, Match, Optional, Sequence
|
||||||
|
|
||||||
import anki # pylint: disable=unused-import
|
import anki # pylint: disable=unused-import
|
||||||
import anki._backend.backend_pb2 as _pb
|
import anki._backend.backend_pb2 as _pb
|
||||||
|
@ -28,19 +28,15 @@ class TagManager:
|
||||||
def __init__(self, col: anki.collection.Collection) -> None:
|
def __init__(self, col: anki.collection.Collection) -> None:
|
||||||
self.col = col.weakref()
|
self.col = col.weakref()
|
||||||
|
|
||||||
# all tags
|
# legacy add-on code expects a List return type
|
||||||
def all(self) -> List[str]:
|
def all(self) -> List[str]:
|
||||||
return [t.name for t in self.col._backend.all_tags()]
|
return list(self.col._backend.all_tags())
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
d = dict(self.__dict__)
|
d = dict(self.__dict__)
|
||||||
del d["col"]
|
del d["col"]
|
||||||
return f"{super().__repr__()} {pprint.pformat(d, width=300)}"
|
return f"{super().__repr__()} {pprint.pformat(d, width=300)}"
|
||||||
|
|
||||||
# # List of (tag, usn)
|
|
||||||
def allItems(self) -> List[Tuple[str, int]]:
|
|
||||||
return [(t.name, t.usn) for t in self.col._backend.all_tags()]
|
|
||||||
|
|
||||||
def tree(self) -> TagTreeNode:
|
def tree(self) -> TagTreeNode:
|
||||||
return self.col._backend.tag_tree()
|
return self.col._backend.tag_tree()
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,10 @@ message Bool {
|
||||||
bool val = 1;
|
bool val = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message StringList {
|
||||||
|
repeated string vals = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// IDs used in RPC calls
|
// IDs used in RPC calls
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -212,7 +216,7 @@ service BackendService {
|
||||||
// tags
|
// tags
|
||||||
|
|
||||||
rpc ClearUnusedTags(Empty) returns (Empty);
|
rpc ClearUnusedTags(Empty) returns (Empty);
|
||||||
rpc AllTags(Empty) returns (AllTagsOut);
|
rpc AllTags(Empty) returns (StringList);
|
||||||
rpc SetTagCollapsed(SetTagCollapsedIn) returns (Empty);
|
rpc SetTagCollapsed(SetTagCollapsedIn) returns (Empty);
|
||||||
rpc ClearTag(String) returns (Empty);
|
rpc ClearTag(String) returns (Empty);
|
||||||
rpc TagTree(Empty) returns (TagTreeNode);
|
rpc TagTree(Empty) returns (TagTreeNode);
|
||||||
|
@ -842,21 +846,11 @@ message AddOrUpdateDeckConfigLegacyIn {
|
||||||
bool preserve_usn_and_mtime = 2;
|
bool preserve_usn_and_mtime = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message AllTagsOut {
|
|
||||||
repeated Tag tags = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message SetTagCollapsedIn {
|
message SetTagCollapsedIn {
|
||||||
string name = 1;
|
string name = 1;
|
||||||
bool collapsed = 2;
|
bool collapsed = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Tag {
|
|
||||||
string name = 1;
|
|
||||||
sint32 usn = 2;
|
|
||||||
bool collapsed = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetChangedTagsOut {
|
message GetChangedTagsOut {
|
||||||
repeated string tags = 1;
|
repeated string tags = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1399,16 +1399,17 @@ impl BackendService for Backend {
|
||||||
// tags
|
// tags
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
|
|
||||||
fn all_tags(&self, _input: Empty) -> BackendResult<pb::AllTagsOut> {
|
fn all_tags(&self, _input: Empty) -> BackendResult<pb::StringList> {
|
||||||
let tags: Vec<pb::Tag> = self.with_col(|col| {
|
Ok(pb::StringList {
|
||||||
Ok(col
|
vals: self.with_col(|col| {
|
||||||
.storage
|
Ok(col
|
||||||
.all_tags()?
|
.storage
|
||||||
.into_iter()
|
.all_tags()?
|
||||||
.map(|t| t.into())
|
.into_iter()
|
||||||
.collect())
|
.map(|t| t.name)
|
||||||
})?;
|
.collect())
|
||||||
Ok(pb::AllTagsOut { tags })
|
})?,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_tag_collapsed(&self, input: pb::SetTagCollapsedIn) -> BackendResult<pb::Empty> {
|
fn set_tag_collapsed(&self, input: pb::SetTagCollapsedIn) -> BackendResult<pb::Empty> {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto::{Tag as TagProto, TagTreeNode},
|
backend_proto::TagTreeNode,
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
err::{AnkiError, Result},
|
err::{AnkiError, Result},
|
||||||
notes::{NoteID, TransformNoteOutput},
|
notes::{NoteID, TransformNoteOutput},
|
||||||
|
@ -21,26 +21,6 @@ pub struct Tag {
|
||||||
pub collapsed: bool,
|
pub collapsed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Tag> for TagProto {
|
|
||||||
fn from(t: Tag) -> Self {
|
|
||||||
TagProto {
|
|
||||||
name: t.name,
|
|
||||||
usn: t.usn.0,
|
|
||||||
collapsed: t.collapsed,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<TagProto> for Tag {
|
|
||||||
fn from(t: TagProto) -> Self {
|
|
||||||
Tag {
|
|
||||||
name: t.name,
|
|
||||||
usn: Usn(t.usn),
|
|
||||||
collapsed: t.collapsed,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Tag {
|
impl Tag {
|
||||||
pub fn new(name: String, usn: Usn) -> Self {
|
pub fn new(name: String, usn: Usn) -> Self {
|
||||||
Tag {
|
Tag {
|
||||||
|
|
Loading…
Reference in a new issue