mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 05:34:36 +00:00
[#204 state:fixed] Added a message after re-prioritization telling how many dupe groups were changed by it.
This commit is contained in:
parent
8cd1e13814
commit
4f097a3a89
@ -502,9 +502,13 @@ class DupeGuru(RegistrableApplication, Broadcaster):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def reprioritize_groups(self, sort_key):
|
def reprioritize_groups(self, sort_key):
|
||||||
|
count = 0
|
||||||
for group in self.results.groups:
|
for group in self.results.groups:
|
||||||
group.prioritize(key_func=sort_key)
|
if group.prioritize(key_func=sort_key):
|
||||||
|
count += 1
|
||||||
self._results_changed()
|
self._results_changed()
|
||||||
|
msg = tr("{} duplicate groups were changed by the re-prioritization.").format(count)
|
||||||
|
self.view.show_message(msg)
|
||||||
|
|
||||||
def reveal_selected(self):
|
def reveal_selected(self):
|
||||||
if self.selected_dupes:
|
if self.selected_dupes:
|
||||||
|
@ -290,10 +290,13 @@ class Group:
|
|||||||
|
|
||||||
def prioritize(self, key_func, tie_breaker=None):
|
def prioritize(self, key_func, tie_breaker=None):
|
||||||
# tie_breaker(ref, dupe) --> True if dupe should be ref
|
# tie_breaker(ref, dupe) --> True if dupe should be ref
|
||||||
|
# Returns True if anything changed during prioritization.
|
||||||
master_key_func = lambda x: (-x.is_ref, key_func(x))
|
master_key_func = lambda x: (-x.is_ref, key_func(x))
|
||||||
self.ordered.sort(key=master_key_func)
|
new_order = sorted(self.ordered, key=master_key_func)
|
||||||
|
changed = new_order != self.ordered
|
||||||
|
self.ordered = new_order
|
||||||
if tie_breaker is None:
|
if tie_breaker is None:
|
||||||
return
|
return changed
|
||||||
ref = self.ref
|
ref = self.ref
|
||||||
key_value = key_func(ref)
|
key_value = key_func(ref)
|
||||||
for dupe in self.dupes:
|
for dupe in self.dupes:
|
||||||
@ -303,6 +306,8 @@ class Group:
|
|||||||
ref = dupe
|
ref = dupe
|
||||||
if ref is not self.ref:
|
if ref is not self.ref:
|
||||||
self.switch_ref(ref)
|
self.switch_ref(ref)
|
||||||
|
return True
|
||||||
|
return changed
|
||||||
|
|
||||||
def remove_dupe(self, item, discard_matches=True):
|
def remove_dupe(self, item, discard_matches=True):
|
||||||
try:
|
try:
|
||||||
|
@ -656,7 +656,7 @@ class TestCaseGroup:
|
|||||||
g.add_match(m2)
|
g.add_match(m2)
|
||||||
g.add_match(m3)
|
g.add_match(m3)
|
||||||
assert o1 is g.ref
|
assert o1 is g.ref
|
||||||
g.prioritize(lambda x:x.name)
|
assert g.prioritize(lambda x:x.name)
|
||||||
assert o3 is g.ref
|
assert o3 is g.ref
|
||||||
|
|
||||||
def test_prioritize_with_tie_breaker(self):
|
def test_prioritize_with_tie_breaker(self):
|
||||||
@ -703,6 +703,14 @@ class TestCaseGroup:
|
|||||||
g.prioritize(lambda x: -x.size)
|
g.prioritize(lambda x: -x.size)
|
||||||
assert g.ref is o1
|
assert g.ref is o1
|
||||||
|
|
||||||
|
def test_prioritize_nothing_changes(self):
|
||||||
|
# prioritize() returns False when nothing changes in the group.
|
||||||
|
g = get_test_group()
|
||||||
|
g[0].name = 'a'
|
||||||
|
g[1].name = 'b'
|
||||||
|
g[2].name = 'c'
|
||||||
|
assert not g.prioritize(lambda x:x.name)
|
||||||
|
|
||||||
def test_list_like(self):
|
def test_list_like(self):
|
||||||
g = Group()
|
g = Group()
|
||||||
o1,o2 = (NamedObject("foo",True),NamedObject("bar",True))
|
o1,o2 = (NamedObject("foo",True),NamedObject("bar",True))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user