# # # patch "guitone/src/view/InventoryView.cpp" # from [df7b80811e13e8b4fcce64000642bef16bf8c48e] # to [8f0ceb0921280a462369fb87a7d07326b05cf30d] # # patch "guitone/src/view/InventoryView.h" # from [8b3986b9a58118e1f929b14465b2b4a7227853ac] # to [3343bdca9c2444705454763a8ac39e684b3822b1] # ============================================================ --- guitone/src/view/InventoryView.cpp df7b80811e13e8b4fcce64000642bef16bf8c48e +++ guitone/src/view/InventoryView.cpp 8f0ceb0921280a462369fb87a7d07326b05cf30d @@ -21,10 +21,12 @@ #include "InventoryView.h" #include "../util/Settings.h" #include "../model/InventoryItem.h" +#include "dialogs/FileDiff.h" #include #include #include +#include InventoryView::InventoryView(QWidget* parent, Type type_, QString objName) : TreeView(parent, objName), type(type_) @@ -53,14 +55,17 @@ InventoryView::~InventoryView() {} InventoryView::~InventoryView() {} +// adds elements to the popup menu based on the selected items +// since not all actions may apply on all items void InventoryView::contextMenuEvent(QContextMenuEvent* ev) { + QItemSelectionModel* selection = selectionModel(); + // // make sure the element under the cursor is selected as well // TODO: it seems as sometimes the selection is screwed up for // no particular reason... why? // - QItemSelectionModel* selection = selectionModel(); QModelIndex index = indexAt(ev->pos()); selection->select(index, QItemSelectionModel::Select | @@ -68,10 +73,6 @@ void InventoryView::contextMenuEvent(QCo ); setSelectionModel(selection); - // - // add elements to the popup menu based on the selected items - // since not all actions may apply on all items - // QList indexList = selection->selectedIndexes(); qDebug("Selected indexes: %d", indexList.size()); @@ -79,8 +80,13 @@ void InventoryView::contextMenuEvent(QCo if (indexList.size() == 1) { QMenu menu(this); - InventoryItem* item = (InventoryItem*)indexList[0].internalPointer(); + QModelIndex sourceIndex = static_cast(indexList[0].model())->mapToSource(indexList[0]); + + InventoryItem* item = static_cast(sourceIndex.internalPointer()); + + qDebug("Item Status: %d", item->getStatus()); + if (item->hasStatus(InventoryItem::Unknown)) { menu.addAction(actAdd); @@ -92,10 +98,19 @@ void InventoryView::contextMenuEvent(QCo menu.addAction(actUnignore); } + // TODO: we need some marker on directories to express that contents + // in this directory have been changed and act accordingly + if (item->isDirectory() || ( + item->hasNotStatus(InventoryItem::Unchanged) && + item->hasNotStatus(InventoryItem::Ignored) && + item->hasNotStatus(InventoryItem::Unknown))) + { + menu.addAction(actCommit); + } + if (item->hasNotStatus(InventoryItem::Ignored) && item->hasNotStatus(InventoryItem::Unknown)) { - menu.addAction(actCommit); menu.addAction(actRemove); menu.addAction(actRename); } @@ -106,6 +121,7 @@ void InventoryView::contextMenuEvent(QCo item->hasNotStatus(InventoryItem::Unknown)) { menu.addAction(actRevert); + menu.addAction(actDiff); } menu.exec(mapToGlobal(ev->pos())); @@ -168,6 +184,11 @@ void InventoryView::createAndConnectCont actRevert->setStatusTip(tr("Revert uncommitted changes")); connect(actRevert, SIGNAL(triggered()), this, SLOT(slotRevert())); + actDiff = new QAction(tr("D&iff"), this); + actDiff->setShortcut(tr("Ctrl+D", "Diff")); + actDiff->setStatusTip(tr("Diff against base revision")); + connect(actDiff, SIGNAL(triggered()), this, SLOT(slotDiff())); + actRename = new QAction(tr("Rena&me"), this); actRename->setShortcut(tr("Ctrl+M", "Rename")); actRename->setStatusTip(tr("Rename file")); @@ -234,3 +255,30 @@ void InventoryView::slotUnignore(void) { qDebug("InventoryView::slotUnignore!!!"); } + +void InventoryView::slotDiff(void) +{ + QItemSelectionModel *selectionModel = this->selectionModel(); + QList indexList(selectionModel->selectedIndexes()); + + if (indexList.size() == 0) + { + qDebug("InventoryView::slotAdd: You didn't select the file properly!"); + return; + } + + if (indexList.size() > 1) + { + qWarning("InventoryView::slotDiff: Only diffing the first item of the selection"); + } + + QModelIndex sourceIndex = static_cast(indexList[0].model())->mapToSource(indexList[0]); + + InventoryItem * item = static_cast(sourceIndex.internalPointer()); + + FileDiff dlg(this, item->getPath()); + dlg.exec(); + + clearSelection(); +} + ============================================================ --- guitone/src/view/InventoryView.h 8b3986b9a58118e1f929b14465b2b4a7227853ac +++ guitone/src/view/InventoryView.h 3343bdca9c2444705454763a8ac39e684b3822b1 @@ -52,9 +52,10 @@ private: QAction *actUnignore; QAction *actRevert; QAction *actRename; + QAction *actDiff; + + Type type; - Type type; - private slots: void slotAdd(void); void slotRemove(void); @@ -63,6 +64,7 @@ private slots: void slotUnignore(void); void slotRevert(void); void slotRename(void); + void slotDiff(void); }; #endif