diff options
author | Arno <am@disconnect.de> | 2010-12-18 12:02:44 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-12-18 12:02:44 +0100 |
commit | 8abf0a7882dbd1c80e24e5d01b79cd1cf60925e2 (patch) | |
tree | 498ca056a3de589b546c4a2602fa0c1268fcac74 /filesystemwidget.cpp | |
parent | 4f64bd4ee5b465fe64237500b32b03f286dd7faf (diff) | |
download | SheMov-8abf0a7882dbd1c80e24e5d01b79cd1cf60925e2.tar.gz SheMov-8abf0a7882dbd1c80e24e5d01b79cd1cf60925e2.tar.bz2 SheMov-8abf0a7882dbd1c80e24e5d01b79cd1cf60925e2.zip |
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...
Diffstat (limited to 'filesystemwidget.cpp')
-rw-r--r-- | filesystemwidget.cpp | 47 |
1 files changed, 11 insertions, 36 deletions
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<QSortFilterProxyModel*>(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<QSortFilterProxyModel*>(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(); |