1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2025-03-10 05:34:36 +00:00

Tweaked Make Selected into Reference.

Having dupes from ref folders (which makes ref switching impossible) would make
the new feature glitchy (selection would be emptied). Now, in cases where the action
results in nothing being changed, the selection stays intact. [#222]
This commit is contained in:
Virgil Dupras 2013-04-28 14:12:08 -04:00
parent aa3cf9700d
commit 70e505ad92
3 changed files with 12 additions and 7 deletions

View File

@ -442,14 +442,16 @@ class DupeGuru(RegistrableApplication, Broadcaster):
for dupe in dupes: for dupe in dupes:
g = self.results.get_group_of_duplicate(dupe) g = self.results.get_group_of_duplicate(dupe)
if g not in changed_groups: if g not in changed_groups:
self.results.make_ref(dupe) if self.results.make_ref(dupe):
changed_groups.add(g) changed_groups.add(g)
# It's not always obvious to users what this action does, so to make it a bit clearer, # It's not always obvious to users what this action does, so to make it a bit clearer,
# we change our selection to the ref of all changed groups. However, we also want to keep # we change our selection to the ref of all changed groups. However, we also want to keep
# the files that were ref before and weren't changed by the action. In effect, what this # the files that were ref before and weren't changed by the action. In effect, what this
# does is that we keep our old selection, but remove all non-ref dupes from it. # does is that we keep our old selection, but remove all non-ref dupes from it.
self.selected_dupes = [d for d in self.selected_dupes # If no group was changed, however, we don't touch the selection.
if self.results.get_group_of_duplicate(d).ref is d] if changed_groups:
self.selected_dupes = [d for d in self.selected_dupes
if self.results.get_group_of_duplicate(d).ref is d]
self.notify('results_changed') self.notify('results_changed')
def mark_all(self): def mark_all(self):

View File

@ -325,14 +325,15 @@ class Group:
def switch_ref(self, with_dupe): def switch_ref(self, with_dupe):
if self.ref.is_ref: if self.ref.is_ref:
return return False
try: try:
self.ordered.remove(with_dupe) self.ordered.remove(with_dupe)
self.ordered.insert(0, with_dupe) self.ordered.insert(0, with_dupe)
self._percentage = None self._percentage = None
self._matches_for_ref = None self._matches_for_ref = None
return True
except ValueError: except ValueError:
pass return False
dupes = property(lambda self: self[1:]) dupes = property(lambda self: self[1:])

View File

@ -244,8 +244,9 @@ class Results(Markable):
def make_ref(self, dupe): def make_ref(self, dupe):
g = self.get_group_of_duplicate(dupe) g = self.get_group_of_duplicate(dupe)
r = g.ref r = g.ref
if not g.switch_ref(dupe):
return False
self._remove_mark_flag(dupe) self._remove_mark_flag(dupe)
g.switch_ref(dupe);
if not r.is_ref: if not r.is_ref:
self.__total_count += 1 self.__total_count += 1
self.__total_size += r.size self.__total_size += r.size
@ -254,6 +255,7 @@ class Results(Markable):
self.__total_size -= dupe.size self.__total_size -= dupe.size
self.__dupes = None self.__dupes = None
self.is_modified = True self.is_modified = True
return True
def perform_on_marked(self, func, remove_from_results): def perform_on_marked(self, func, remove_from_results):
# Performs `func` on all marked dupes. If an EnvironmentError is raised during the call, # Performs `func` on all marked dupes. If an EnvironmentError is raised during the call,