From 3342b328823d93e912bcecb825da39c5af453f37 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 28 Nov 2011 14:21:10 -0500 Subject: [PATCH] [#179] Refactored folder deletion so that it uses selection in the core's directory_tree instead of using the one from the GUI layer. --- cocoa/base/DirectoryPanel.m | 2 +- cocoa/base/PyDirectoryOutline.h | 1 + cocoa/base/PyDupeGuru.h | 1 - cocoa/inter/app.py | 3 --- cocoa/inter/directory_outline.py | 3 +++ core/gui/directory_tree.py | 5 +++++ qt/base/directories_dialog.py | 23 ++++++++++++----------- qt/base/directories_model.py | 14 ++++++++++++-- 8 files changed, 34 insertions(+), 18 deletions(-) diff --git a/cocoa/base/DirectoryPanel.m b/cocoa/base/DirectoryPanel.m index ab876dda..0511b905 100644 --- a/cocoa/base/DirectoryPanel.m +++ b/cocoa/base/DirectoryPanel.m @@ -105,7 +105,7 @@ http://www.hardcoded.net/licenses/bsd_license NSIndexPath *path = [outline selectedIndexPath]; NSInteger state = [outline intProperty:@"state" valueAtPath:path]; if (([path length] == 1) && (state != 2)) { - [_py removeDirectory:i2n([path indexAtPosition:0])]; + [[outline py] removeSelectedDirectory]; } else { NSInteger newState = state == 2 ? 0 : 2; // If excluded, put it back diff --git a/cocoa/base/PyDirectoryOutline.h b/cocoa/base/PyDirectoryOutline.h index 5ac068a2..6c1f27fa 100644 --- a/cocoa/base/PyDirectoryOutline.h +++ b/cocoa/base/PyDirectoryOutline.h @@ -11,4 +11,5 @@ http://www.hardcoded.net/licenses/bsd_license @interface PyDirectoryOutline : PyOutline - (void)addDirectory:(NSString *)directoryPath; +- (void)removeSelectedDirectory; @end \ No newline at end of file diff --git a/cocoa/base/PyDupeGuru.h b/cocoa/base/PyDupeGuru.h index 55adf670..fb8dcf1e 100644 --- a/cocoa/base/PyDupeGuru.h +++ b/cocoa/base/PyDupeGuru.h @@ -15,7 +15,6 @@ http://www.hardcoded.net/licenses/bsd_license - (PyResultTable *)resultTable; //Actions - (NSNumber *)addDirectory:(NSString *)name; -- (void)removeDirectory:(NSNumber *)index; - (void)loadResultsFrom:(NSString *)filename; - (void)saveResultsAs:(NSString *)filename; - (void)loadSession; diff --git a/cocoa/inter/app.py b/cocoa/inter/app.py index 8b42a652..90add3ff 100644 --- a/cocoa/inter/app.py +++ b/cocoa/inter/app.py @@ -38,9 +38,6 @@ class PyDupeGuruBase(PyFairware): def addDirectory_(self, directory): return self.py.add_directory(directory) - def removeDirectory_(self, index): - self.py.remove_directory(index) - #---Results def clearIgnoreList(self): self.py.scanner.ignore_list.Clear() diff --git a/cocoa/inter/directory_outline.py b/cocoa/inter/directory_outline.py index a0fb80d3..72d4921c 100644 --- a/cocoa/inter/directory_outline.py +++ b/cocoa/inter/directory_outline.py @@ -8,6 +8,9 @@ class PyDirectoryOutline(PyOutline): def addDirectory_(self, path): self.py.add_directory(path) + def removeSelectedDirectory(self): + self.py.remove_selected() + # python --> cocoa def refresh_states(self): # Under cocoa, both refresh() and refresh_states() do the same thing. diff --git a/core/gui/directory_tree.py b/core/gui/directory_tree.py index 050067c7..68589349 100644 --- a/core/gui/directory_tree.py +++ b/core/gui/directory_tree.py @@ -76,6 +76,11 @@ class DirectoryTree(GUIObject, Tree): def add_directory(self, path): self.app.add_directory(path) + def remove_selected(self): + assert len(self.selected_path) == 1 + root_index = self.selected_path[0] + self.app.remove_directory(root_index) + def update_all_states(self): for node in self: node.update_all_states() diff --git a/qt/base/directories_dialog.py b/qt/base/directories_dialog.py index f2e03445..48e9d22b 100644 --- a/qt/base/directories_dialog.py +++ b/qt/base/directories_dialog.py @@ -27,9 +27,11 @@ class DirectoriesDialog(QMainWindow): self.app = app self.lastAddedFolder = platform.INITIAL_FOLDER_IN_DIALOGS self.recentFolders = Recent(self.app, 'recentFolders') - self.directoriesModel = DirectoriesModel(self.app) - self.directoriesDelegate = DirectoriesDelegate() self._setupUi() + self.directoriesModel = DirectoriesModel(self.app, view=self.treeView) + self.directoriesDelegate = DirectoriesDelegate() + self.treeView.setItemDelegate(self.directoriesDelegate) + self._setupColumns() self.app.recentResults.addMenu(self.menuLoadRecent) self.app.recentResults.addMenu(self.menuRecentResults) self.recentFolders.addMenu(self.menuRecentFolders) @@ -106,8 +108,6 @@ class DirectoriesDialog(QMainWindow): self.promptLabel = QLabel(tr("Select folders to scan and press \"Scan\"."), self.centralwidget) self.verticalLayout.addWidget(self.promptLabel) self.treeView = QTreeView(self.centralwidget) - self.treeView.setItemDelegate(self.directoriesDelegate) - self.treeView.setModel(self.directoriesModel) self.treeView.setAcceptDrops(True) triggers = QAbstractItemView.DoubleClicked|QAbstractItemView.EditKeyPressed\ |QAbstractItemView.SelectedClicked @@ -115,11 +115,6 @@ class DirectoriesDialog(QMainWindow): self.treeView.setDragDropOverwriteMode(True) self.treeView.setDragDropMode(QAbstractItemView.DropOnly) self.treeView.setUniformRowHeights(True) - header = self.treeView.header() - header.setStretchLastSection(False) - header.setResizeMode(0, QHeaderView.Stretch) - header.setResizeMode(1, QHeaderView.Fixed) - header.resizeSection(1, 100) self.verticalLayout.addWidget(self.treeView) self.horizontalLayout = QHBoxLayout() self.removeFolderButton = QPushButton(self.centralwidget) @@ -149,6 +144,13 @@ class DirectoriesDialog(QMainWindow): else: moveToScreenCenter(self) + def _setupColumns(self): + header = self.treeView.header() + header.setStretchLastSection(False) + header.setResizeMode(0, QHeaderView.Stretch) + header.setResizeMode(1, QHeaderView.Fixed) + header.resizeSection(1, 100) + def _updateAddButton(self): if self.recentFolders.isEmpty(): self.addFolderButton.setMenu(None) @@ -212,8 +214,7 @@ class DirectoriesDialog(QMainWindow): index = indexes[0] node = index.internalPointer() if node.parent is None: - row = index.row() - self.app.model.remove_directory(row) + self.directoriesModel.model.remove_selected() def scanButtonClicked(self): if self.app.model.results.is_modified: diff --git a/qt/base/directories_model.py b/qt/base/directories_model.py index f7eb5c77..161b24c0 100644 --- a/qt/base/directories_model.py +++ b/qt/base/directories_model.py @@ -10,7 +10,7 @@ import urllib.parse from PyQt4.QtCore import pyqtSignal, Qt, QRect, QUrl, QModelIndex from PyQt4.QtGui import (QComboBox, QStyledItemDelegate, QApplication, QBrush, QStyle, - QStyleOptionComboBox, QStyleOptionViewItemV4) + QStyleOptionComboBox, QStyleOptionViewItemV4, QItemSelection) from hscommon.trans import trget from qtlib.tree_model import RefNode, TreeModel @@ -60,10 +60,14 @@ class DirectoriesDelegate(QStyledItemDelegate): class DirectoriesModel(TreeModel): - def __init__(self, app): + def __init__(self, app, view): TreeModel.__init__(self) self.model = DirectoryTree(self, app.model) + self.view = view + self.view.setModel(self) self.model.connect() + + self.view.selectionModel().selectionChanged[(QItemSelection, QItemSelection)].connect(self.selectionChanged) def _createNode(self, ref, row): return RefNode(self, None, ref, row) @@ -139,8 +143,14 @@ class DirectoriesModel(TreeModel): # work with ActionMove either. So screw that, and accept anything. return Qt.ActionMask + #--- Events + def selectionChanged(self, selected, deselected): + newNodes = [modelIndex.internalPointer().ref for modelIndex in self.view.selectionModel().selectedRows()] + self.model.selected_nodes = newNodes + #--- Signals foldersAdded = pyqtSignal(list) + #--- model --> view def refresh(self): self.reset()