mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
option to tag notes in find dupes function
This commit is contained in:
parent
33403fd890
commit
b55761190f
2 changed files with 23 additions and 3 deletions
|
@ -512,7 +512,7 @@ def fieldNames(col, downcase=True):
|
||||||
|
|
||||||
# Find duplicates
|
# Find duplicates
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
# returns array of ("dupestr", [nids])
|
||||||
def findDupes(col, fieldName, search=""):
|
def findDupes(col, fieldName, search=""):
|
||||||
# limit search to notes with applicable field name
|
# limit search to notes with applicable field name
|
||||||
if search:
|
if search:
|
||||||
|
|
|
@ -7,6 +7,7 @@ import cgi
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
from anki.lang import ngettext
|
||||||
|
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
import anki
|
import anki
|
||||||
|
@ -1324,6 +1325,7 @@ update cards set usn=?, mod=?, did=? where id in """ + scids,
|
||||||
restoreGeom(d, "findDupes")
|
restoreGeom(d, "findDupes")
|
||||||
fields = sorted(anki.find.fieldNames(self.col, downcase=False))
|
fields = sorted(anki.find.fieldNames(self.col, downcase=False))
|
||||||
frm.fields.addItems(fields)
|
frm.fields.addItems(fields)
|
||||||
|
self._dupesButton = None
|
||||||
# links
|
# links
|
||||||
frm.webView.page().setLinkDelegationPolicy(
|
frm.webView.page().setLinkDelegationPolicy(
|
||||||
QWebPage.DelegateAllLinks)
|
QWebPage.DelegateAllLinks)
|
||||||
|
@ -1335,15 +1337,19 @@ update cards set usn=?, mod=?, did=? where id in """ + scids,
|
||||||
self.connect(d, SIGNAL("finished(int)"), onFin)
|
self.connect(d, SIGNAL("finished(int)"), onFin)
|
||||||
def onClick():
|
def onClick():
|
||||||
field = fields[frm.fields.currentIndex()]
|
field = fields[frm.fields.currentIndex()]
|
||||||
self.duplicatesReport(frm.webView, field, frm.search.text())
|
self.duplicatesReport(frm.webView, field, frm.search.text(), frm)
|
||||||
search = frm.buttonBox.addButton(
|
search = frm.buttonBox.addButton(
|
||||||
_("Search"), QDialogButtonBox.ActionRole)
|
_("Search"), QDialogButtonBox.ActionRole)
|
||||||
self.connect(search, SIGNAL("clicked()"), onClick)
|
self.connect(search, SIGNAL("clicked()"), onClick)
|
||||||
d.show()
|
d.show()
|
||||||
|
|
||||||
def duplicatesReport(self, web, fname, search):
|
def duplicatesReport(self, web, fname, search, frm):
|
||||||
self.mw.progress.start()
|
self.mw.progress.start()
|
||||||
res = self.mw.col.findDupes(fname, search)
|
res = self.mw.col.findDupes(fname, search)
|
||||||
|
if not self._dupesButton:
|
||||||
|
self._dupesButton = b = frm.buttonBox.addButton(
|
||||||
|
_("Tag Duplicates"), QDialogButtonBox.ActionRole)
|
||||||
|
self.connect(b, SIGNAL("clicked()"), lambda: self._onTagDupes(res))
|
||||||
t = "<html><body>"
|
t = "<html><body>"
|
||||||
groups = len(res)
|
groups = len(res)
|
||||||
notes = sum(len(r[1]) for r in res)
|
notes = sum(len(r[1]) for r in res)
|
||||||
|
@ -1361,6 +1367,20 @@ update cards set usn=?, mod=?, did=? where id in """ + scids,
|
||||||
web.setHtml(t)
|
web.setHtml(t)
|
||||||
self.mw.progress.finish()
|
self.mw.progress.finish()
|
||||||
|
|
||||||
|
def _onTagDupes(self, res):
|
||||||
|
if not res:
|
||||||
|
return
|
||||||
|
self.model.beginReset()
|
||||||
|
self.mw.checkpoint(_("Tag Duplicates"))
|
||||||
|
nids = set()
|
||||||
|
for s, nidlist in res:
|
||||||
|
nids.update(nidlist)
|
||||||
|
self.col.tags.bulkAdd(nids, _("duplicate"))
|
||||||
|
self.mw.progress.finish()
|
||||||
|
self.model.endReset()
|
||||||
|
self.mw.requireReset()
|
||||||
|
tooltip(_("Notes tagged."))
|
||||||
|
|
||||||
def dupeLinkClicked(self, link):
|
def dupeLinkClicked(self, link):
|
||||||
self.form.searchEdit.lineEdit().setText(link.toString())
|
self.form.searchEdit.lineEdit().setText(link.toString())
|
||||||
self.onSearch()
|
self.onSearch()
|
||||||
|
|
Loading…
Reference in a new issue