diff options
-rw-r--r-- | filesystemwidget.cpp | 47 | ||||
-rw-r--r-- | filesystemwidget.h | 4 | ||||
-rw-r--r-- | fileview.cpp | 13 | ||||
-rw-r--r-- | fileview.h | 4 | ||||
-rw-r--r-- | shemov.cpp | 2 |
5 files changed, 30 insertions, 40 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(); diff --git a/filesystemwidget.h b/filesystemwidget.h index e41ff52..ee0b9b3 100644 --- a/filesystemwidget.h +++ b/filesystemwidget.h @@ -24,7 +24,6 @@ class QLineEdit; class QFileInfo; class QAction; class QVariant; -class MessageDialog; class PictureViewer; class QStringList; class FileSystemModel; @@ -67,9 +66,9 @@ class FilesystemWidget : public QWidget { void markSeen(); private slots: - void doRenameFile(); void dirExpanded(const QModelIndex &idx); void dirCollapsed(const QModelIndex &idx); + void fileEditorClosed(const QModelIndex &idx); private: void setWindowTitle(const QString &dir); @@ -85,7 +84,6 @@ class FilesystemWidget : public QWidget { FilesystemFileProxy *mFileProxy; QLineEdit *mDirEdit; QString mWindowTitle; - MessageDialog *mRenameDialog; QString mTemplate; qint64 mSize; PictureViewer *mPicViewer; diff --git a/fileview.cpp b/fileview.cpp index 082ec92..331c7b8 100644 --- a/fileview.cpp +++ b/fileview.cpp @@ -22,6 +22,9 @@ #include <QVariant> #include <QList> #include <QDir> +#include <QSortFilterProxyModel> + +#include <QDebug> #include "fileview.h" #include "messagedialog.h" @@ -66,6 +69,12 @@ void FileView::readConfig(){ mHoverWin->setWindowOpacity(s.value("ui/hoveropacity", 10).toFloat() / 10.0); } +void FileView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint){ + QTreeView::closeEditor(editor, hint); + QSortFilterProxyModel *proxy = qobject_cast<QSortFilterProxyModel*>(model()); + QModelIndex sourceIdx = proxy->mapToSource(currentIndex()); + emit editorClosed(sourceIdx); +} void FileView::doMark(){ int rowCount = model()->rowCount(rootIndex()); @@ -124,6 +133,10 @@ void FileView::contextMenuEvent(QContextMenuEvent *e){ } void FileView::keyPressEvent(QKeyEvent *e){ + if(!hasFocus()){ + QTreeView::keyPressEvent(e); + return; + } switch(e->key()){ case Qt::Key_Backspace: emit upDir(); @@ -31,6 +31,7 @@ class FileView : public QTreeView { void delFiles(); void enterPressed(const QModelIndex &); void statusbarMessage(const QString &); + void editorClosed(const QModelIndex &idx); public slots: void markFiles(); @@ -38,6 +39,9 @@ class FileView : public QTreeView { void createFolder(); void readConfig(); + protected slots: + virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint); + private slots: void doMark(); void doCreateFolder(); @@ -338,7 +338,7 @@ void SheMov::createActions(){ mMoveA = new QAction(tr("Move file(s)..."), this); mMoveA->setShortcut(tr("CTRL+m")); connect(mMoveA, SIGNAL(triggered()), mFSWidget, SLOT(moveFiles())); - mRenameA = new QAction(tr("Rename file..."), this); + mRenameA = new QAction(tr("Rename..."), this); mRenameA->setShortcut(tr("CTRL+r")); connect(mRenameA, SIGNAL(triggered()), mFSWidget, SLOT(renameFile())); mMountDvdA = new QAction(QIcon(":/diaper.png"), tr("(Un)mount DVD drive"), this); |