mirror of
https://github.com/arsenetar/dupeguru.git
synced 2026-01-22 14:41:39 +00:00
Overwrite subfolders' state when setting states in folder dialog
Fixes #248
This commit is contained in:
@@ -51,6 +51,7 @@ class Directories:
|
||||
#---Override
|
||||
def __init__(self, fileclasses=[fs.File]):
|
||||
self._dirs = []
|
||||
# {path: state}
|
||||
self.states = {}
|
||||
self.fileclasses = fileclasses
|
||||
self.folderclass = fs.Folder
|
||||
@@ -220,7 +221,7 @@ class Directories:
|
||||
continue
|
||||
path = attrib['path']
|
||||
state = attrib['value']
|
||||
self.set_state(Path(path), int(state))
|
||||
self.states[Path(path)] = int(state)
|
||||
|
||||
def save_to_file(self, outfile):
|
||||
"""Save folder selection as XML to ``outfile``.
|
||||
@@ -248,11 +249,8 @@ class Directories:
|
||||
"""
|
||||
if self.get_state(path) == state:
|
||||
return
|
||||
# we don't want to needlessly fill self.states. if get_state returns the same thing
|
||||
# without an explicit entry, remove that entry
|
||||
if path in self.states:
|
||||
del self.states[path]
|
||||
if self.get_state(path) == state: # no need for an entry
|
||||
return
|
||||
for iter_path in list(self.states.keys()):
|
||||
if path.is_parent_of(iter_path):
|
||||
del self.states[iter_path]
|
||||
self.states[path] = state
|
||||
|
||||
|
||||
@@ -135,31 +135,18 @@ def test_get_state_with_path_not_there():
|
||||
d.add_path(testpath['onefile'])
|
||||
eq_(d.get_state(testpath), DirectoryState.Normal)
|
||||
|
||||
def test_states_remain_when_larger_directory_eat_smaller_ones():
|
||||
def test_states_overwritten_when_larger_directory_eat_smaller_ones():
|
||||
# ref #248
|
||||
# When setting the state of a folder, we overwrite previously set states for subfolders.
|
||||
d = Directories()
|
||||
p = testpath['onefile']
|
||||
d.add_path(p)
|
||||
d.set_state(p, DirectoryState.Excluded)
|
||||
d.add_path(testpath)
|
||||
d.set_state(testpath, DirectoryState.Reference)
|
||||
eq_(DirectoryState.Excluded ,d.get_state(p))
|
||||
eq_(DirectoryState.Excluded ,d.get_state(p['dir1']))
|
||||
eq_(DirectoryState.Reference ,d.get_state(testpath))
|
||||
|
||||
def test_set_state_keep_state_dict_size_to_minimum():
|
||||
d = Directories()
|
||||
p = testpath['fs']
|
||||
d.add_path(p)
|
||||
d.set_state(p, DirectoryState.Reference)
|
||||
d.set_state(p['dir1'], DirectoryState.Reference)
|
||||
eq_(1,len(d.states))
|
||||
eq_(DirectoryState.Reference ,d.get_state(p['dir1']))
|
||||
d.set_state(p['dir1'], DirectoryState.Normal)
|
||||
eq_(2,len(d.states))
|
||||
eq_(DirectoryState.Normal ,d.get_state(p['dir1']))
|
||||
d.set_state(p['dir1'], DirectoryState.Reference)
|
||||
eq_(1,len(d.states))
|
||||
eq_(DirectoryState.Reference ,d.get_state(p['dir1']))
|
||||
eq_(d.get_state(p), DirectoryState.Reference)
|
||||
eq_(d.get_state(p['dir1']), DirectoryState.Reference)
|
||||
eq_(d.get_state(testpath), DirectoryState.Reference)
|
||||
|
||||
def test_get_files():
|
||||
d = Directories()
|
||||
|
||||
Reference in New Issue
Block a user