From 8abf0a7882dbd1c80e24e5d01b79cd1cf60925e2 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 18 Dec 2010 12:02:44 +0100 Subject: Fix rename files in FSWidget Rename files inline, letting the model do all the work. Part of getting rid of MessageDialog. Maybe this broke the filename templates. We'll see... --- filesystemwidget.cpp | 47 +++++++++++------------------------------------ 1 file changed, 11 insertions(+), 36 deletions(-) (limited to 'filesystemwidget.cpp') diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index 8b302dc..33c6be5 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -68,10 +68,6 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { mPicViewer = SmGlobals::instance()->pictureViewer(); - QString title = QString(tr("%1 - Rename file")).arg(qApp->applicationName()); - mRenameDialog = new MessageDialog(tr("Rename dummy to:"), title, this); - connect(mRenameDialog, SIGNAL(accepted()), this, SLOT(doRenameFile())); - QWidget *fileWidget = new QWidget; QHBoxLayout *directoryEdit = new QHBoxLayout; QLabel *dirLabel = new QLabel(tr("&Directory")); @@ -96,6 +92,7 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { connect(mFileView, SIGNAL(upDir()), this, SLOT(parentDir())); connect(mDirEdit, SIGNAL(returnPressed()), this, SLOT(directoryEdited())); connect(mFileView, SIGNAL(delFiles()), this, SLOT(deleteFiles())); + connect(mFileView, SIGNAL(editorClosed(QModelIndex)), this, SLOT(fileEditorClosed(QModelIndex))); mFileView->resizeColumnToContents(0); @@ -301,24 +298,11 @@ void FilesystemWidget::moveFiles(){ } void FilesystemWidget::renameFile(){ - QModelIndex cur = mFileView->currentIndex(); - if(!cur.isValid()){ - emit statusbarMessage(tr("Nothing to rename!")); + QModelIndex curIdx = mFileView->currentIndex(); + if(curIdx.data().toString() == ".."){ return; } - QSortFilterProxyModel *proxy = static_cast(mFileView->model()); - QModelIndex source = proxy->mapToSource(cur); - QFileInfo info = mModel->fileInfo(source); - QString text = QString(tr("Rename %1 to:")).arg(info.fileName()); - mRenameDialog->setMessage(text); - QString newFilename = info.fileName().toLower(); - QRegExp re2("['#()&%!]+"); - newFilename.replace(re2, " "); - QRegExp re1("\\s{2,}"); - newFilename.replace(re1, " "); - newFilename.replace(' ', '.'); - mRenameDialog->setText(newFilename); - mRenameDialog->exec(); + mFileView->edit(curIdx); } void FilesystemWidget::renameCover(const QString &infix){ @@ -537,22 +521,6 @@ void FilesystemWidget::copyRecursive(const QFileInfo &start, const QString &dest } } -void FilesystemWidget::doRenameFile(){ - QString name = mRenameDialog->text(); - QSortFilterProxyModel *proxy = static_cast(mFileView->model()); - QModelIndex cur = mFileView->currentIndex(); - QModelIndex real = proxy->mapToSource(cur); - QFileInfo info = mModel->fileInfo(real); - QString newName = QString("%1/%2").arg(info.absolutePath()).arg(name); - if(QFile::rename(info.absoluteFilePath(), newName)){ - QString message = QString(tr("Renamed %1 to %2")).arg(info.absoluteFilePath()).arg(newName); - emit statusbarMessage(message); - } - QFileInfo n(newName); - mTemplate = n.completeBaseName(); - emit newTemplate(mTemplate); -} - void FilesystemWidget::dirExpanded(const QModelIndex &idx){ QModelIndex real = mDirProxy->mapToSource(idx); if(real.isValid()){ @@ -570,6 +538,13 @@ void FilesystemWidget::dirCollapsed(const QModelIndex &idx){ } } +void FilesystemWidget::fileEditorClosed(const QModelIndex &idx){ + QModelIndex real = mDirProxy->mapFromSource(idx); + if(real.isValid()){ + mDirView->update(real); + } +} + QStringList FilesystemWidget::selectedFiles(){ QStringList retval; QModelIndexList selected = fileView()->selectionModel()->selectedRows(); -- cgit v1.2.3-70-g09d2