From b700071a54e9ce9e9097a704fb1d71dc2a795bfb Mon Sep 17 00:00:00 2001 From: am Date: Fri, 10 Jul 2009 18:35:14 +0000 Subject: -fixed display of windowTitle -focus FileView after startup and changing dir via directorybar -implemented createFolder -display action in statusBar() git-svn-id: file:///var/svn/repos2/shemov/trunk@383 f440f766-f032-0410-8965-dc7d17de2ca0 --- fileview.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'fileview.cpp') 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(model()); QDirModel *model = static_cast(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(model()); + QDirModel *model = static_cast(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; -- cgit v1.2.3-70-g09d2