mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 05:34:36 +00:00
[#153 state:fixed] Fixed a refresh bug in directory panel.
This commit is contained in:
parent
fa0c3aeb78
commit
731e68f164
@ -16,12 +16,12 @@ STATE_ORDER = [STATE_NORMAL, STATE_REFERENCE, STATE_EXCLUDED]
|
|||||||
|
|
||||||
# Lazily loads children
|
# Lazily loads children
|
||||||
class DirectoryNode(Node):
|
class DirectoryNode(Node):
|
||||||
def __init__(self, app, path, name):
|
def __init__(self, tree, path, name):
|
||||||
Node.__init__(self, name)
|
Node.__init__(self, name)
|
||||||
self._app = app
|
self._tree = tree
|
||||||
self._directory_path = path
|
self._directory_path = path
|
||||||
self._loaded = False
|
self._loaded = False
|
||||||
self._state = STATE_ORDER.index(self._app.directories.get_state(path))
|
self._state = STATE_ORDER.index(self._tree.app.directories.get_state(path))
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
if not self._loaded:
|
if not self._loaded:
|
||||||
@ -30,9 +30,9 @@ class DirectoryNode(Node):
|
|||||||
|
|
||||||
def _load(self):
|
def _load(self):
|
||||||
self.clear()
|
self.clear()
|
||||||
subpaths = self._app.directories.get_subfolders(self._directory_path)
|
subpaths = self._tree.app.directories.get_subfolders(self._directory_path)
|
||||||
for path in subpaths:
|
for path in subpaths:
|
||||||
self.append(DirectoryNode(self._app, path, path[-1]))
|
self.append(DirectoryNode(self._tree, path, path[-1]))
|
||||||
self._loaded = True
|
self._loaded = True
|
||||||
|
|
||||||
# The state propery is an index to the combobox
|
# The state propery is an index to the combobox
|
||||||
@ -46,7 +46,9 @@ class DirectoryNode(Node):
|
|||||||
return
|
return
|
||||||
self._state = value
|
self._state = value
|
||||||
state = STATE_ORDER[value]
|
state = STATE_ORDER[value]
|
||||||
self._app.directories.set_state(self._directory_path, state)
|
self._tree.app.directories.set_state(self._directory_path, state)
|
||||||
|
self._tree._refresh()
|
||||||
|
self._tree.view.refresh()
|
||||||
|
|
||||||
|
|
||||||
class DirectoryTree(GUIObject, Tree):
|
class DirectoryTree(GUIObject, Tree):
|
||||||
@ -62,7 +64,7 @@ class DirectoryTree(GUIObject, Tree):
|
|||||||
def _refresh(self):
|
def _refresh(self):
|
||||||
self.clear()
|
self.clear()
|
||||||
for path in self.app.directories:
|
for path in self.app.directories:
|
||||||
self.append(DirectoryNode(self.app, path, str(path)))
|
self.append(DirectoryNode(self, path, str(path)))
|
||||||
|
|
||||||
def add_directory(self, path):
|
def add_directory(self, path):
|
||||||
self.app.add_directory(path)
|
self.app.add_directory(path)
|
||||||
|
@ -462,3 +462,31 @@ class TestCaseDupeGuru_renameSelected:
|
|||||||
assert 'foo bar 2' in names
|
assert 'foo bar 2' in names
|
||||||
eq_(g.dupes[0].name, 'foo bar 2')
|
eq_(g.dupes[0].name, 'foo bar 2')
|
||||||
|
|
||||||
|
|
||||||
|
class TestAppWithDirectoriesInTree:
|
||||||
|
def pytest_funcarg__do_setup(self, request):
|
||||||
|
tmpdir = request.getfuncargvalue('tmpdir')
|
||||||
|
p = Path(str(tmpdir))
|
||||||
|
io.mkdir(p + 'sub1')
|
||||||
|
io.mkdir(p + 'sub2')
|
||||||
|
io.mkdir(p + 'sub3')
|
||||||
|
self.app = DupeGuru()
|
||||||
|
self.dtree_gui = CallLogger()
|
||||||
|
self.dtree = DirectoryTree(self.dtree_gui, self.app)
|
||||||
|
self.dtree.connect()
|
||||||
|
self.dtree.add_directory(p)
|
||||||
|
self.dtree_gui.clear_calls()
|
||||||
|
|
||||||
|
def test_set_root_as_ref_makes_subfolders_ref_as_well(self, do_setup):
|
||||||
|
# Setting a node state to something also affect subnodes. These subnodes must be correctly
|
||||||
|
# refreshed.
|
||||||
|
node = self.dtree[0]
|
||||||
|
eq_(len(node), 3) # a len() call is required for subnodes to be loaded
|
||||||
|
subnode = node[0]
|
||||||
|
node.state = 1 # the state property is a state index
|
||||||
|
node = self.dtree[0]
|
||||||
|
eq_(len(node), 3)
|
||||||
|
subnode = node[0]
|
||||||
|
eq_(subnode.state, 1)
|
||||||
|
self.dtree_gui.check_gui_calls(['refresh'])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user