From 3cbba03cf065c4f7adcf6619931180ff22c9eb60 Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 27 Nov 2015 17:36:49 +0100 Subject: Remember selections between dir changes Select all items previously selected when going back() --- filesystemwidget.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'filesystemwidget.cpp') diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index 0e6e591..07e058d 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -162,13 +162,17 @@ void FilesystemWidget::directoryChanged(const QModelIndex &selected, const QMode } QModelIndex realPrev = mDirProxy->mapToSource(deselected); if(realPrev.isValid()){ - mLastDir = realPrev.data(QFileSystemModel::FilePathRole).toString(); + mLastFiles[Previous] = mLastFiles[Current]; + mLastFiles[Current] = mFileView->selectedItems(); + mLastDir = realPrev.data(QFileSystemModel::FilePathRole).toString(); } mModel->setRootPath(mModel->filePath(real)); mDirEdit->setText(mModel->filePath(real)); setWindowTitle(); - mFileView->selectionModel()->clear(); + + mFileView->selectionModel()->clear(); mFileModel->setDir(mModel->filePath(real)); + resizeFileView(); } @@ -253,10 +257,15 @@ void FilesystemWidget::goBack(){ if(mLastDir.isEmpty()){ return; } - QModelIndex lastIdx = mModel->index(mLastDir); - if(lastIdx.isValid()){ - mDirView->selectionModel()->setCurrentIndex(mDirProxy->mapFromSource(lastIdx), QItemSelectionModel::ClearAndSelect); - } + QModelIndex lastIdx = mModel->index(mLastDir); + mDirView->selectionModel()->setCurrentIndex(mDirProxy->mapFromSource(lastIdx), QItemSelectionModel::ClearAndSelect); + if(lastIdx.isValid()){ + if(!mLastFiles[Previous].isEmpty()){ + foreach(QString lf, mLastFiles[Previous]){ + mFileView->selectItem(lf); + } + } + } } void FilesystemWidget::deleteFiles(){ -- cgit v1.2.3-70-g09d2