diff options
Diffstat (limited to 'fileview.cpp')
-rw-r--r-- | fileview.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/fileview.cpp b/fileview.cpp index 31c9aca..5995d60 100644 --- a/fileview.cpp +++ b/fileview.cpp @@ -22,6 +22,8 @@ FileView::FileView(QWidget *parent) : QTreeView(parent) { setRootIsDecorated(false); mMarkDialog = new MessageDialog(tr("Enter pattern to mark"), this); connect(mMarkDialog, SIGNAL(accepted()), this, SLOT(doMark())); + mCreateFolderDialog = new MessageDialog(tr("Enter folder name"), this); + connect(mCreateFolderDialog, SIGNAL(accepted()), this, SLOT(doCreateFolder())); } void FileView::markFiles(){ @@ -32,6 +34,10 @@ void FileView::unmarkFiles(){ selectionModel()->clearSelection(); } +void FileView::createFolder(){ + mCreateFolderDialog->show(); +} + void FileView::doMark(){ int rowCount = model()->rowCount(rootIndex()); QString sRegex = mMarkDialog->text(); @@ -39,6 +45,7 @@ void FileView::doMark(){ QRegExp re(sRegex); QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(model()); QDirModel *model = static_cast<QDirModel*>(proxy->sourceModel()); + bool match(false); for(int i = 0; i < rowCount; ++i){ QModelIndex cur = rootIndex().child(i, 0); QModelIndex sCur = proxy->mapToSource(cur); @@ -47,8 +54,35 @@ void FileView::doMark(){ } if(re.indexIn(cur.data().toString()) != -1){ selectionModel()->select(cur, QItemSelectionModel::Select | QItemSelectionModel::Rows); + match = true; } } + if(match){ + statusbarMessage(QString()); + }else{ + emit statusbarMessage(tr("No match found!")); + } + }else{ + emit statusbarMessage(tr("Nothing to mark!")); + } +} + +void FileView::doCreateFolder(){ + QString folderName = mCreateFolderDialog->text(); + if(folderName.isEmpty()){ + emit statusbarMessage(tr("No foldername given!")); + return; + } + QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(model()); + QDirModel *model = static_cast<QDirModel*>(proxy->sourceModel()); + QModelIndex sRoot = proxy->mapToSource(rootIndex()); + QModelIndex newIdx = model->mkdir(sRoot, folderName); + if(newIdx == QModelIndex()){ + QString msg = QString(tr("Failed to create %1/%2")).arg(model->filePath(sRoot)).arg(folderName); + emit statusbarMessage(msg); + }else{ + QString msg = QString(tr("Created folder %1")).arg(model->filePath(newIdx)); + emit statusbarMessage(msg); } } @@ -57,7 +91,7 @@ void FileView::contextMenuEvent(QContextMenuEvent *e){ int ctr(0); foreach(QAction *a, actions()){ contextMenu.addAction(a); - if(false){ + if((ctr == 1)){ contextMenu.addSeparator(); } ++ctr; |