diff options
Diffstat (limited to 'filesystemwidget.cpp')
| -rw-r--r-- | filesystemwidget.cpp | 76 | 
1 files changed, 51 insertions, 25 deletions
| diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index bd02098..187d92c 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -82,29 +82,13 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) {  	fileWidget->setLayout(fwLayout);  	connect(mDirView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(directoryChanged(const QModelIndex &, const QModelIndex &))); +	connect(mDirView, SIGNAL(expanded(QModelIndex)), this, SLOT(dirExpanded(QModelIndex))); +	connect(mDirView, SIGNAL(collapsed(QModelIndex)), this, SLOT(dirCollapsed(QModelIndex)));  	connect(mFileView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(fileViewActivated(const QModelIndex &)));  	connect(mFileView, SIGNAL(enterPressed(const QModelIndex &)), this, SLOT(fileViewActivated(const QModelIndex &)));  	connect(mFileView, SIGNAL(upDir()), this, SLOT(parentDir()));  	connect(mDirEdit, SIGNAL(returnPressed()), this, SLOT(directoryEdited())); -	QSettings s; -	QStringList expandPaths = s.value("ui/expandpaths").toStringList(); -	QString last; -	foreach(QString p, expandPaths){ -		QModelIndex idx = mModel->index(p); -		last = p; -		if(idx.isValid()){ -			QModelIndex proxy = mDirProxy->mapFromSource(idx); -			mDirView->setExpanded(proxy, true); -			expandParents(proxy); -		} -	} -	QString select = s.value("ui/selectstartup").toString(); -	windowTitle(select); -	setWindowTitle(select); -	QModelIndex sel = mModel->index(select); -	mDirView->setCurrentIndex(mDirProxy->mapFromSource(sel)); -  	mFileView->resizeColumnToContents(0);  	QVBoxLayout *mainLayout = new QVBoxLayout; @@ -407,6 +391,42 @@ void FilesystemWidget::playSelected(){  	QProcess::startDetached(program, programArgs);  } +void FilesystemWidget::readSettings(){ +	QSettings s; +	QStringList expandedDirs = s.value("paths/expandeddirs").toStringList(); +	if(expandedDirs.isEmpty()){ +		expandedDirs << QDir::homePath(); +	} +	foreach(QString p, expandedDirs){ +		QModelIndex idx = mModel->index(p); +		if(idx.isValid()){ +			QModelIndex pidx = mDirProxy->mapFromSource(idx); +			if(pidx.isValid()){ +				mDirView->setExpanded(pidx, true); +			} +		} +	} +	QString selectedDir = s.value("paths/selecteddir").toString(); +	if(!selectedDir.isEmpty()){ +		QModelIndex diridx = mModel->index(selectedDir); +		if(diridx.isValid()){ +			QModelIndex pidx = mDirProxy->mapFromSource(diridx); +			mDirView->selectionModel()->setCurrentIndex(pidx, QItemSelectionModel::ClearAndSelect); +		} +	} +} + +void FilesystemWidget::writeSettings(){ +	QSettings s; +	s.setValue("paths/expandeddirs", mExpandedDirs); +	QModelIndex currentDir = mDirView->selectionModel()->currentIndex(); +	if(currentDir.isValid()){ +		QModelIndex real = mDirProxy->mapToSource(currentDir); +		QString dir = mModel->filePath(real); +		s.setValue("paths/selecteddir", dir); +	} +} +  void FilesystemWidget::setWindowTitle(const QString &dir){  	mWindowTitle = QString("%1 - %2").arg(qApp->applicationName()).arg(dir);  	emit windowTitle(mWindowTitle); @@ -466,14 +486,20 @@ void FilesystemWidget::doRenameFile(){  	emit newTemplate(mTemplate);  } -void FilesystemWidget::expandParents(const QModelIndex &idx){ -	if(idx.isValid()){ -		QModelIndex parent = idx.parent(); -		do{ -			mDirView->setExpanded(parent, true); -			parent = parent.parent(); +void FilesystemWidget::dirExpanded(const QModelIndex &idx){ +	QModelIndex real = mDirProxy->mapToSource(idx); +	if(real.isValid()){ +		mExpandedDirs << mModel->filePath(real); +	} +} -		}while(parent.isValid()); +void FilesystemWidget::dirCollapsed(const QModelIndex &idx){ +	QModelIndex real = mDirProxy->mapToSource(idx); +	if(real.isValid()){ +		QString path = mModel->filePath(real); +		if(mExpandedDirs.contains(path)){ +			mExpandedDirs.removeAll(path); +		}  	}  } | 
