[#139 state:fixed] Make "mark selected" behave in a more standard way.

This commit is contained in:
Virgil Dupras 2011-09-22 12:12:43 -04:00
parent 01731a8277
commit 48e2acf0a2
3 changed files with 37 additions and 13 deletions

View File

@ -20,7 +20,7 @@ from hscommon.reg import RegistrableApplication
from hscommon.notify import Broadcaster
from hscommon.path import Path
from hscommon.conflict import smart_move, smart_copy
from hscommon.util import delete_if_empty, first, escape, nonone, format_time_decimal
from hscommon.util import delete_if_empty, first, escape, nonone, format_time_decimal, allsame
from hscommon.trans import tr, trmsg
from . import directories, results, scanner, export, fs
@ -422,8 +422,15 @@ class DupeGuru(RegistrableApplication, Broadcaster):
self.view.start_job(JobType.Scan, do)
def toggle_selected_mark_state(self):
for dupe in self.selected_dupes:
self.results.mark_toggle(dupe)
selected = self.without_ref(self.selected_dupes)
if not selected:
return
if allsame(self.results.is_marked(d) for d in selected):
markfunc = self.results.mark_toggle
else:
markfunc = self.results.mark
for dupe in selected:
markfunc(dupe)
self.notify('marking_changed')
def without_ref(self, dupes):

View File

@ -11,13 +11,6 @@ class Markable:
self.__marked = set()
self.__inverted = False
#---Private
def __get_mark_count(self):
if self.__inverted:
return self._get_markable_count() - len(self.__marked)
else:
return len(self.__marked)
#---Virtual
#About did_mark and did_unmark: They only happen what an object is actually added/removed
# in self.__marked, and is not affected by __inverted. Thus, self.mark while __inverted
@ -87,8 +80,17 @@ class Markable:
return False
return self.mark_toggle(o)
mark_count = property(__get_mark_count)
mark_inverted = property(lambda self :self.__inverted)
#--- Properties
@property
def mark_count(self):
if self.__inverted:
return self._get_markable_count() - len(self.__marked)
else:
return len(self.__marked)
@property
def mark_inverted(self):
return self.__inverted
class MarkableList(list, Markable):
def __init__(self):

View File

@ -267,7 +267,7 @@ class TestCaseDupeGuruWithResults:
assert app.selected_dupes[1] is objects[2]
assert app.selected_dupes[2] is objects[1]
def test_toggleSelectedMark(self, do_setup):
def test_toggle_selected_mark_state(self, do_setup):
app = self.app
objects = self.objects
app.toggle_selected_mark_state()
@ -281,6 +281,21 @@ class TestCaseDupeGuruWithResults:
assert not app.results.is_marked(objects[3])
assert app.results.is_marked(objects[4])
def test_toggle_selected_mark_state_with_different_selected_state(self, do_setup):
# When marking selected dupes with a heterogenous selection, mark all selected dupes. When
# it's homogenous, simply toggle.
app = self.app
objects = self.objects
self.rtable.select([1])
app.toggle_selected_mark_state()
# index 0 is unmarkable, but we throw it in the bunch to be sure that it doesn't make the
# selection heterogenoug when it shouldn't.
self.rtable.select([0, 1, 4])
app.toggle_selected_mark_state()
eq_(app.results.mark_count, 2)
app.toggle_selected_mark_state()
eq_(app.results.mark_count, 0)
def test_refreshDetailsWithSelected(self, do_setup):
self.rtable.select([1, 4])
eq_(self.dpanel.row(0), ('Filename', 'bar bleh', 'foo bar'))