From 8edb869fdc39eb2bfc7cdb7b27b28b667a87c04f Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 6 Feb 2010 12:44:21 +0100 Subject: [PATCH] Removed logic duplication across toolkit code in "Remove Selected" action. --- core/app.py | 3 +++ core/app_cocoa.py | 3 --- core/app_cocoa_inter.py | 2 +- core/tests/app_cocoa_test.py | 16 ++++++++-------- qt/base/app.py | 9 +++++++++ qt/base/main_window.py | 8 +------- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/app.py b/core/app.py index 6aafaf3c..eb8fb211 100644 --- a/core/app.py +++ b/core/app.py @@ -235,6 +235,9 @@ class DupeGuru(RegistrableApplication, Broadcaster): def remove_duplicates(self, duplicates): self.results.remove_duplicates(duplicates) + def remove_selected(self): + self.remove_duplicates(self.selected_dupes) + def save(self): if not op.exists(self.appdata): os.makedirs(self.appdata) diff --git a/core/app_cocoa.py b/core/app_cocoa.py index 50dc20c2..7c94f5a9 100644 --- a/core/app_cocoa.py +++ b/core/app_cocoa.py @@ -106,9 +106,6 @@ class DupeGuru(app.DupeGuru): except IndexError: pass - def RemoveSelected(self): - self.results.remove_duplicates(self.selected_dupes) - def RenameSelected(self, newname): try: d = self.selected_dupes[0] diff --git a/core/app_cocoa_inter.py b/core/app_cocoa_inter.py index 5ebeaee2..3cebb984 100644 --- a/core/app_cocoa_inter.py +++ b/core/app_cocoa_inter.py @@ -106,7 +106,7 @@ class PyDupeGuruBase(PyApp): self.app.results.perform_on_marked(lambda x:True, True) def removeSelected(self): - self.app.RemoveSelected() + self.app.remove_selected() def renameSelected_(self,newname): return self.app.RenameSelected(newname) diff --git a/core/tests/app_cocoa_test.py b/core/tests/app_cocoa_test.py index cc7b23bf..5af6ae92 100644 --- a/core/tests/app_cocoa_test.py +++ b/core/tests/app_cocoa_test.py @@ -150,7 +150,7 @@ class TCDupeGuru(TestCase): objects = self.objects paths = [[0, 0], [0, 1], [1]] app.SelectResultNodePaths(paths) - app.RemoveSelected() + app.remove_selected() # The first 2 dupes have been removed. The 3rd one is a ref. it stays there, in first pos. eq_(app.selected_result_node_paths(), [[0]]) # no exception @@ -206,7 +206,7 @@ class TCDupeGuru(TestCase): objects = self.objects paths = r2np([0, 1, 2]) app.SelectPowerMarkerNodePaths(paths) - app.RemoveSelected() + app.remove_selected() eq_(app.selected_powermarker_node_paths(), []) # no exception def test_selectPowerMarkerRows(self): @@ -281,13 +281,13 @@ class TCDupeGuru(TestCase): def test_removeSelected(self): app = self.app app.SelectPowerMarkerNodePaths(r2np([0,2])) - app.RemoveSelected() - self.assertEqual(1,len(app.results.dupes)) - app.RemoveSelected() - self.assertEqual(1,len(app.results.dupes)) + app.remove_selected() + eq_(len(app.results.dupes), 1) + app.remove_selected() + eq_(len(app.results.dupes), 1) app.SelectPowerMarkerNodePaths(r2np([0,2])) - app.RemoveSelected() - self.assertEqual(0,len(app.results.dupes)) + app.remove_selected() + eq_(len(app.results.dupes), 0) def test_addDirectory_simple(self): # There's already a directory in self.app, so adding another once makes 2 of em diff --git a/qt/base/app.py b/qt/base/app.py index 6925d5b5..cbba7cb9 100644 --- a/qt/base/app.py +++ b/qt/base/app.py @@ -169,6 +169,15 @@ class DupeGuru(DupeGuruBase, QObject): DupeGuruBase.remove_duplicates(self, duplicates) self.emit(SIGNAL('resultsChanged()')) + def remove_selected(self): + dupes = self.without_ref(self.selected_dupes) + if not dupes: + return + title = "Remove duplicates" + msg = "You are about to remove {0} files from results. Continue?".format(len(dupes)) + if self.main_window._confirm(title, msg): + DupeGuruBase.remove_selected(self) + #--- Public def askForRegCode(self): self.reg.ask_for_code() diff --git a/qt/base/main_window.py b/qt/base/main_window.py index dc15532f..862784ed 100644 --- a/qt/base/main_window.py +++ b/qt/base/main_window.py @@ -248,13 +248,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.app.remove_marked_duplicates() def removeSelectedTriggered(self): - dupes = self.resultsView.selectedDupes() - if not dupes: - return - title = "Remove duplicates" - msg = "You are about to remove {0} files from results. Continue?".format(len(dupes)) - if self._confirm(title, msg): - self.app.remove_duplicates(dupes) + self.app.remove_selected() def renameTriggered(self): self.resultsView.edit(self.resultsView.selectionModel().currentIndex())