From c55281d67a2677fd1e37ccff6f235d396969072d Mon Sep 17 00:00:00 2001 From: Venkata Ramana Date: Tue, 5 Jan 2021 07:31:56 +0530 Subject: [PATCH] added removeEmptyNotes (#221) * clearUnusedTags and replaceTags are added * added clearUnusedTags and replaceTags * added clearUnusedTags and replaceTags * removed whitespaces and indentations * removed white spaces and indentations * added removeEmptyNotes --- actions/notes.md | 21 +++++++++++++++++++++ plugin/__init__.py | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/actions/notes.md b/actions/notes.md index 83cc514..05510f3 100644 --- a/actions/notes.md +++ b/actions/notes.md @@ -433,3 +433,24 @@ "error": null } ``` + +* **removeEmptyNotes** + + Removes all the empty notes for the current user. + + *Sample request*: + ```json + { + "action": "removeEmptyNotes", + "version": 6 + } + ``` + + *Sample result*: + ```json + { + "result": null, + "error": null + } + ``` + \ No newline at end of file diff --git a/plugin/__init__.py b/plugin/__init__.py index 050ebf8..996c2b9 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -1085,7 +1085,12 @@ class AnkiConnect: finally: self.stopEditing() - + @util.api() + def removeEmptyNotes(self): + for model in self.collection().models.all(): + if self.collection().models.useCount(model) == 0: + self.collection().models.rem(model) + self.window().requireReset() @util.api()