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:
parent
561b469e41
commit
3342b32882
@ -105,7 +105,7 @@ http://www.hardcoded.net/licenses/bsd_license
|
|||||||
NSIndexPath *path = [outline selectedIndexPath];
|
NSIndexPath *path = [outline selectedIndexPath];
|
||||||
NSInteger state = [outline intProperty:@"state" valueAtPath:path];
|
NSInteger state = [outline intProperty:@"state" valueAtPath:path];
|
||||||
if (([path length] == 1) && (state != 2)) {
|
if (([path length] == 1) && (state != 2)) {
|
||||||
[_py removeDirectory:i2n([path indexAtPosition:0])];
|
[[outline py] removeSelectedDirectory];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
NSInteger newState = state == 2 ? 0 : 2; // If excluded, put it back
|
NSInteger newState = state == 2 ? 0 : 2; // If excluded, put it back
|
||||||
|
@ -11,4 +11,5 @@ http://www.hardcoded.net/licenses/bsd_license
|
|||||||
|
|
||||||
@interface PyDirectoryOutline : PyOutline
|
@interface PyDirectoryOutline : PyOutline
|
||||||
- (void)addDirectory:(NSString *)directoryPath;
|
- (void)addDirectory:(NSString *)directoryPath;
|
||||||
|
- (void)removeSelectedDirectory;
|
||||||
@end
|
@end
|
@ -15,7 +15,6 @@ http://www.hardcoded.net/licenses/bsd_license
|
|||||||
- (PyResultTable *)resultTable;
|
- (PyResultTable *)resultTable;
|
||||||
//Actions
|
//Actions
|
||||||
- (NSNumber *)addDirectory:(NSString *)name;
|
- (NSNumber *)addDirectory:(NSString *)name;
|
||||||
- (void)removeDirectory:(NSNumber *)index;
|
|
||||||
- (void)loadResultsFrom:(NSString *)filename;
|
- (void)loadResultsFrom:(NSString *)filename;
|
||||||
- (void)saveResultsAs:(NSString *)filename;
|
- (void)saveResultsAs:(NSString *)filename;
|
||||||
- (void)loadSession;
|
- (void)loadSession;
|
||||||
|
@ -38,9 +38,6 @@ class PyDupeGuruBase(PyFairware):
|
|||||||
def addDirectory_(self, directory):
|
def addDirectory_(self, directory):
|
||||||
return self.py.add_directory(directory)
|
return self.py.add_directory(directory)
|
||||||
|
|
||||||
def removeDirectory_(self, index):
|
|
||||||
self.py.remove_directory(index)
|
|
||||||
|
|
||||||
#---Results
|
#---Results
|
||||||
def clearIgnoreList(self):
|
def clearIgnoreList(self):
|
||||||
self.py.scanner.ignore_list.Clear()
|
self.py.scanner.ignore_list.Clear()
|
||||||
|
@ -8,6 +8,9 @@ class PyDirectoryOutline(PyOutline):
|
|||||||
def addDirectory_(self, path):
|
def addDirectory_(self, path):
|
||||||
self.py.add_directory(path)
|
self.py.add_directory(path)
|
||||||
|
|
||||||
|
def removeSelectedDirectory(self):
|
||||||
|
self.py.remove_selected()
|
||||||
|
|
||||||
# python --> cocoa
|
# python --> cocoa
|
||||||
def refresh_states(self):
|
def refresh_states(self):
|
||||||
# Under cocoa, both refresh() and refresh_states() do the same thing.
|
# Under cocoa, both refresh() and refresh_states() do the same thing.
|
||||||
|
@ -76,6 +76,11 @@ class DirectoryTree(GUIObject, Tree):
|
|||||||
def add_directory(self, path):
|
def add_directory(self, path):
|
||||||
self.app.add_directory(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):
|
def update_all_states(self):
|
||||||
for node in self:
|
for node in self:
|
||||||
node.update_all_states()
|
node.update_all_states()
|
||||||
|
@ -27,9 +27,11 @@ class DirectoriesDialog(QMainWindow):
|
|||||||
self.app = app
|
self.app = app
|
||||||
self.lastAddedFolder = platform.INITIAL_FOLDER_IN_DIALOGS
|
self.lastAddedFolder = platform.INITIAL_FOLDER_IN_DIALOGS
|
||||||
self.recentFolders = Recent(self.app, 'recentFolders')
|
self.recentFolders = Recent(self.app, 'recentFolders')
|
||||||
self.directoriesModel = DirectoriesModel(self.app)
|
|
||||||
self.directoriesDelegate = DirectoriesDelegate()
|
|
||||||
self._setupUi()
|
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.menuLoadRecent)
|
||||||
self.app.recentResults.addMenu(self.menuRecentResults)
|
self.app.recentResults.addMenu(self.menuRecentResults)
|
||||||
self.recentFolders.addMenu(self.menuRecentFolders)
|
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.promptLabel = QLabel(tr("Select folders to scan and press \"Scan\"."), self.centralwidget)
|
||||||
self.verticalLayout.addWidget(self.promptLabel)
|
self.verticalLayout.addWidget(self.promptLabel)
|
||||||
self.treeView = QTreeView(self.centralwidget)
|
self.treeView = QTreeView(self.centralwidget)
|
||||||
self.treeView.setItemDelegate(self.directoriesDelegate)
|
|
||||||
self.treeView.setModel(self.directoriesModel)
|
|
||||||
self.treeView.setAcceptDrops(True)
|
self.treeView.setAcceptDrops(True)
|
||||||
triggers = QAbstractItemView.DoubleClicked|QAbstractItemView.EditKeyPressed\
|
triggers = QAbstractItemView.DoubleClicked|QAbstractItemView.EditKeyPressed\
|
||||||
|QAbstractItemView.SelectedClicked
|
|QAbstractItemView.SelectedClicked
|
||||||
@ -115,11 +115,6 @@ class DirectoriesDialog(QMainWindow):
|
|||||||
self.treeView.setDragDropOverwriteMode(True)
|
self.treeView.setDragDropOverwriteMode(True)
|
||||||
self.treeView.setDragDropMode(QAbstractItemView.DropOnly)
|
self.treeView.setDragDropMode(QAbstractItemView.DropOnly)
|
||||||
self.treeView.setUniformRowHeights(True)
|
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.verticalLayout.addWidget(self.treeView)
|
||||||
self.horizontalLayout = QHBoxLayout()
|
self.horizontalLayout = QHBoxLayout()
|
||||||
self.removeFolderButton = QPushButton(self.centralwidget)
|
self.removeFolderButton = QPushButton(self.centralwidget)
|
||||||
@ -149,6 +144,13 @@ class DirectoriesDialog(QMainWindow):
|
|||||||
else:
|
else:
|
||||||
moveToScreenCenter(self)
|
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):
|
def _updateAddButton(self):
|
||||||
if self.recentFolders.isEmpty():
|
if self.recentFolders.isEmpty():
|
||||||
self.addFolderButton.setMenu(None)
|
self.addFolderButton.setMenu(None)
|
||||||
@ -212,8 +214,7 @@ class DirectoriesDialog(QMainWindow):
|
|||||||
index = indexes[0]
|
index = indexes[0]
|
||||||
node = index.internalPointer()
|
node = index.internalPointer()
|
||||||
if node.parent is None:
|
if node.parent is None:
|
||||||
row = index.row()
|
self.directoriesModel.model.remove_selected()
|
||||||
self.app.model.remove_directory(row)
|
|
||||||
|
|
||||||
def scanButtonClicked(self):
|
def scanButtonClicked(self):
|
||||||
if self.app.model.results.is_modified:
|
if self.app.model.results.is_modified:
|
||||||
|
@ -10,7 +10,7 @@ import urllib.parse
|
|||||||
|
|
||||||
from PyQt4.QtCore import pyqtSignal, Qt, QRect, QUrl, QModelIndex
|
from PyQt4.QtCore import pyqtSignal, Qt, QRect, QUrl, QModelIndex
|
||||||
from PyQt4.QtGui import (QComboBox, QStyledItemDelegate, QApplication, QBrush, QStyle,
|
from PyQt4.QtGui import (QComboBox, QStyledItemDelegate, QApplication, QBrush, QStyle,
|
||||||
QStyleOptionComboBox, QStyleOptionViewItemV4)
|
QStyleOptionComboBox, QStyleOptionViewItemV4, QItemSelection)
|
||||||
|
|
||||||
from hscommon.trans import trget
|
from hscommon.trans import trget
|
||||||
from qtlib.tree_model import RefNode, TreeModel
|
from qtlib.tree_model import RefNode, TreeModel
|
||||||
@ -60,11 +60,15 @@ class DirectoriesDelegate(QStyledItemDelegate):
|
|||||||
|
|
||||||
|
|
||||||
class DirectoriesModel(TreeModel):
|
class DirectoriesModel(TreeModel):
|
||||||
def __init__(self, app):
|
def __init__(self, app, view):
|
||||||
TreeModel.__init__(self)
|
TreeModel.__init__(self)
|
||||||
self.model = DirectoryTree(self, app.model)
|
self.model = DirectoryTree(self, app.model)
|
||||||
|
self.view = view
|
||||||
|
self.view.setModel(self)
|
||||||
self.model.connect()
|
self.model.connect()
|
||||||
|
|
||||||
|
self.view.selectionModel().selectionChanged[(QItemSelection, QItemSelection)].connect(self.selectionChanged)
|
||||||
|
|
||||||
def _createNode(self, ref, row):
|
def _createNode(self, ref, row):
|
||||||
return RefNode(self, None, 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.
|
# work with ActionMove either. So screw that, and accept anything.
|
||||||
return Qt.ActionMask
|
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
|
#--- Signals
|
||||||
foldersAdded = pyqtSignal(list)
|
foldersAdded = pyqtSignal(list)
|
||||||
|
|
||||||
#--- model --> view
|
#--- model --> view
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
self.reset()
|
self.reset()
|
||||||
|
Loading…
Reference in New Issue
Block a user