# # # patch "src/view/InventoryView.cpp" # from [7c9731090329ba1e93c45a9436e7327951733419] # to [e6a2b0542a11473d1953ed2ea2f86deabb11abc3] # # patch "src/view/InventoryView.h" # from [0434946fdcb50d819048da08fac8a5c626c47e27] # to [de7bdd693c187a8611d3af9b80ae05fdd56f6e40] # ============================================================ --- src/view/InventoryView.cpp 7c9731090329ba1e93c45a9436e7327951733419 +++ src/view/InventoryView.cpp e6a2b0542a11473d1953ed2ea2f86deabb11abc3 @@ -44,11 +44,6 @@ InventoryView::InventoryView(QWidget * p createAndConnectContextActions(); connect( - this, SIGNAL(doubleClicked(const QModelIndex &)), - this, SLOT(itemClicked(const QModelIndex &)) - ); - - connect( this, SIGNAL(contextMenuRequested(const QModelIndexList &, const QPoint &)), this, SLOT(slotContextMenuRequested(const QModelIndexList &, const QPoint &)) ); @@ -68,11 +63,21 @@ void InventoryView::setType(Type t) this, SLOT(itemClicked(const QModelIndex &)) ); + connect( + this, SIGNAL(doubleClicked(const QModelIndex &)), + this, SLOT(itemDoubleClicked(const QModelIndex &)) + ); + setRootIsDecorated(false); setItemsExpandable(false); } else { + disconnect( + this, SIGNAL(clicked(const QModelIndex &)), + this, SLOT(itemDoubleClicked(const QModelIndex &)) + ); + connect( this, SIGNAL(clicked(const QModelIndex &)), this, SLOT(itemClicked(const QModelIndex &)) @@ -284,9 +289,12 @@ void InventoryView::slotContextMenuReque menu.addAction(actChdir); } - if (invitem->isNewNode() && - invitem->hasNotStatus(InventoryItem::Missing) && - invitem->hasNotStatus(InventoryItem::Invalid)) + if (invitem->hasStatus(InventoryItem::Unknown) || + invitem->hasStatus(InventoryItem::Ignored) || ( + invitem->isNewNode() && + invitem->hasNotStatus(InventoryItem::Missing) && + invitem->hasNotStatus(InventoryItem::Invalid) + )) { menu.addAction(actOpen); } @@ -340,34 +348,27 @@ void InventoryView::slotContextMenuReque } // - // determine the default action + // mark the default action with bold text // + DefaultAction act = getDefaultAction(indexList[0]); QFont activeFont; activeFont.setBold(true); - - if (invitem->isDirectory()) + switch (act) { - actChdir->setFont(activeFont); - } - else - { - if (invitem->hasStatus(InventoryItem::ContentsChanged) && - invitem->hasNotStatus(InventoryItem::Added)) - { + case Chdir: + actChdir->setFont(activeFont); + break; + case FileDiff: actFileDiff->setFont(activeFont); - } - else - if (invitem->isNewNode() && - invitem->hasNotStatus(InventoryItem::Missing) && - invitem->hasNotStatus(InventoryItem::Invalid)) - { + break; + case Commit: + actCommit->setFont(activeFont); + break; + case Open: actOpen->setFont(activeFont); - } - else - if (invitem->hasChanged()) - { - actRevert->setFont(activeFont); - } + break; + default: + break; } menu.exec(pos); @@ -628,7 +629,7 @@ void InventoryView::slotRevisionDiff() emit diffRevision(invitem->getPath(), QString(), QString()); } -QModelIndex InventoryView::getSingleSelection(bool mapToSource /* = true */) +QModelIndex InventoryView::getSingleSelection(bool mapToSource /* = true */) const { QItemSelectionModel * selectionModel = this->selectionModel(); QList list(selectionModel->selectedIndexes()); @@ -651,9 +652,45 @@ void InventoryView::itemClicked(const QM void InventoryView::itemClicked(const QModelIndex & index) { - if (!index.isValid()) return; + DefaultAction act = getDefaultAction(index); + if (act == Chdir) + { + emit directoryChanged(index); + changeDirectory(index); + } +} + +void InventoryView::itemDoubleClicked(const QModelIndex & index) +{ + DefaultAction act = getDefaultAction(index); + switch (act) + { + case Chdir: + emit directoryChanged(index); + changeDirectory(index); + break; + case FileDiff: + slotFileDiff(); + break; + case Commit: + slotCommit(); + break; + case Open: + slotOpen(); + break; + default: + break; + } +} + +InventoryView::DefaultAction InventoryView::getDefaultAction(const QModelIndex & index) const +{ + if (!index.isValid()) + return None; + QModelIndex sourceIndex = static_cast(index.model())->mapToSource(index); + I(sourceIndex.isValid()); ModelItem * item = static_cast(sourceIndex.internalPointer()); InventoryItem * invitem = dynamic_cast(item); @@ -662,24 +699,35 @@ void InventoryView::itemClicked(const QM if ((invitem && invitem->isDirectory()) || (psitem && psitem->isCdUp())) { - emit directoryChanged(index); - changeDirectory(index); - return; + return Chdir; } - if (!invitem) - return; + I(invitem); if (invitem->hasStatus(InventoryItem::ContentsChanged) && invitem->hasNotStatus(InventoryItem::Added)) { - slotFileDiff(); - return; + return FileDiff; } - // default action on double click - slotOpen(); - return; + if (invitem->hasChangedRecursive()) + { + return Commit; + } + + if (invitem->hasStatus(InventoryItem::Unknown) || + invitem->hasStatus(InventoryItem::Ignored) || ( + invitem->isNewNode() && + invitem->hasNotStatus(InventoryItem::Missing) && + invitem->hasNotStatus(InventoryItem::Invalid) + )) + { + return Open; + } + + L(QString("no default action for item %1 applicable") + .arg(invitem->getLabel())); + return None; } /*! ============================================================ --- src/view/InventoryView.h 0434946fdcb50d819048da08fac8a5c626c47e27 +++ src/view/InventoryView.h de7bdd693c187a8611d3af9b80ae05fdd56f6e40 @@ -50,10 +50,13 @@ private: void fileHistory(const QString &); private: + enum DefaultAction { None, Chdir, Open, FileDiff, Commit }; + void setModel(QAbstractItemModel *); + QModelIndex getSingleSelection(bool mapToSource = true) const; + DefaultAction getDefaultAction(const QModelIndex &) const; void createAndConnectContextActions(); void closeEvent(); - QModelIndex getSingleSelection(bool mapToSource = true); QAction * actChdir; QAction * actOpen; @@ -82,9 +85,10 @@ private slots: private slots: void newNodeLoaded(const QModelIndex &, const QModelIndex &); void changeDirectory(const QModelIndex &); + void slotContextMenuRequested(const QModelIndexList &, const QPoint &); void itemClicked(const QModelIndex & index); + void itemDoubleClicked(const QModelIndex & index); void setBackgroundImage(); - void slotContextMenuRequested(const QModelIndexList &, const QPoint &); void slotChdir(); void slotOpen();