1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2024-10-31 22:05:58 +00:00

[#179] Refactored folder deletion so that it uses selection in the core's directory_tree instead of using the one from the GUI layer.

This commit is contained in:
Virgil Dupras 2011-11-28 14:21:10 -05:00
parent 561b469e41
commit 3342b32882
8 changed files with 34 additions and 18 deletions

View File

@ -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

View File

@ -11,4 +11,5 @@ http://www.hardcoded.net/licenses/bsd_license
@interface PyDirectoryOutline : PyOutline
- (void)addDirectory:(NSString *)directoryPath;
- (void)removeSelectedDirectory;
@end

View File

@ -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;

View File

@ -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()

View File

@ -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.

View File

@ -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()

View File

@ -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:

View File

@ -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,11 +60,15 @@ 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()