Fixing the problems with diffing on model stores

This commit is contained in:
Sumner Evans
2019-09-06 20:00:04 -06:00
parent b9e6b4161b
commit a959f378ff
2 changed files with 14 additions and 14 deletions

View File

@@ -508,7 +508,7 @@ class PlaylistDetailPanel(Gtk.Overlay):
def on_delete_playlist(e):
CacheManager.delete_playlist(self.playlist_id)
dialog.destroy()
self.update_playlist_list(force=True)
self.update_playlist_view(force=True)
dialog.connect('delete-playlist', on_delete_playlist)

View File

@@ -74,6 +74,10 @@ def _parse_diff_location(location):
def diff_song_store(store_to_edit, new_store):
"""
Diffing song stores is nice, because we can easily make edits by modifying
the underlying store.
"""
old_store = [row[:] for row in store_to_edit]
# Diff the lists to determine what needs to be changed.
@@ -95,23 +99,19 @@ def diff_song_store(store_to_edit, new_store):
def diff_model_store(store_to_edit, new_store):
"""
The diff here is that if there are any differences, then we refresh the
entire list. This is because it is too hard to do editing.
"""
old_store = store_to_edit[:]
diff = DeepDiff(old_store, new_store)
changed = diff.get('values_changed', {})
added = diff.get('iterable_item_added', {})
removed = diff.get('iterable_item_removed', {})
if diff == {}:
return
for edit_location, diff in changed.items():
idx, field = _parse_diff_location(edit_location)
store_to_edit[int(idx)].set_property(field[17:], diff['new_value'])
for add_location, value in added.items():
store_to_edit.append(value)
for remove_location, value in reversed(list(removed.items())):
remove_at = int(_parse_diff_location(remove_location)[0])
del store_to_edit[remove_at]
store_to_edit.remove_all()
for model in new_store:
store_to_edit.append(model)
def show_song_popover(