# # # patch "src/view/InventoryView.cpp" # from [d3ece7990df1ebfc6f944b00204b0959d26c5888] # to [5f14786855eed3da97bcb3a048a2b3f1a4c3137f] # ============================================================ --- src/view/InventoryView.cpp d3ece7990df1ebfc6f944b00204b0959d26c5888 +++ src/view/InventoryView.cpp 5f14786855eed3da97bcb3a048a2b3f1a4c3137f @@ -235,10 +235,11 @@ void InventoryView::slotContextMenuReque // since not all actions may apply on all items void InventoryView::slotContextMenuRequested(const QModelIndexList & indexList, const QPoint & pos) { - D(QString("Selected indexes: %1").arg(indexList.size())); + if (indexList.size() == 0) return; - QMenu menu(this); - + // + // single item selected + // if (indexList.size() == 1) { QModelIndex sourceIndex = static_cast @@ -252,6 +253,8 @@ void InventoryView::slotContextMenuReque if (!invitem) return; + QMenu menu(this); + if (invitem->isDirectory()) { menu.addAction(actChdir); @@ -344,94 +347,97 @@ void InventoryView::slotContextMenuReque } menu.exec(pos); + return; } - else - { - ModelItem * item; - InventoryItem * invitem; - QModelIndex sourceIndex; - QStringList actions; - actions << "add" << "drop" << "commit" - << "ignore" << "unignore" << "revert"; + // + // multiple items selected + // + ModelItem * item; + InventoryItem * invitem; + QModelIndex sourceIndex; - QMap actionMapping; - actionMapping.insert("add", actAddMultiple); - actionMapping.insert("drop", actRemoveMultiple); - actionMapping.insert("commit", actCommitMultiple); - actionMapping.insert("revert", actRevertMultiple); - actionMapping.insert("ignore", actIgnoreMultiple); - actionMapping.insert("unignore", actUnignoreMultiple); + QStringList actions; + actions << "add" << "drop" << "commit" + << "ignore" << "unignore" << "revert"; - QMap actionCounter; + QMap actionMapping; + actionMapping.insert("add", actAddMultiple); + actionMapping.insert("drop", actRemoveMultiple); + actionMapping.insert("commit", actCommitMultiple); + actionMapping.insert("revert", actRevertMultiple); + actionMapping.insert("ignore", actIgnoreMultiple); + actionMapping.insert("unignore", actUnignoreMultiple); - foreach (QString action, actions) - { - actionCounter.insert(action, 0); - } + QMap actionCounter; - foreach (QModelIndex index, indexList) - { - sourceIndex = - static_cast(index.model()) - ->mapToSource(index); + foreach (QString action, actions) + { + actionCounter.insert(action, 0); + } - item = static_cast(sourceIndex.internalPointer()); - invitem = dynamic_cast(item); + foreach (QModelIndex index, indexList) + { + sourceIndex = + static_cast(index.model()) + ->mapToSource(index); - // skip actions on anything other than InventoryItems - if (!invitem) - continue; + item = static_cast(sourceIndex.internalPointer()); + invitem = dynamic_cast(item); - if (!invitem->isTracked()) - { - actionCounter["add"]++; + // skip actions on anything other than InventoryItems + if (!invitem) + continue; - if (invitem->hasStatus(InventoryItem::Unknown)) - { - actionCounter["ignore"]++; - } - else - { - actionCounter["unignore"]++; - } - continue; + if (!invitem->isTracked()) + { + actionCounter["add"]++; + + if (invitem->hasStatus(InventoryItem::Unknown)) + { + actionCounter["ignore"]++; } - - if (invitem->hasChangedRecursive()) + else { - actionCounter["commit"]++; - actionCounter["revert"]++; + actionCounter["unignore"]++; } + continue; + } - actionCounter["drop"]++; + if (invitem->hasChangedRecursive()) + { + actionCounter["commit"]++; + actionCounter["revert"]++; } - QMapIterator i(actionCounter); - int totalItems = indexList.size(); - bool commonActions = false; + actionCounter["drop"]++; + } - while (i.hasNext()) - { - i.next(); - if (i.value() < totalItems) continue; - commonActions = true; - QAction * act = actionMapping[i.key()]; - act->setText(act->text().arg(totalItems)); - menu.addAction(act); - } + QMapIterator i(actionCounter); + int totalItems = indexList.size(); + bool commonActions = false; - if (!commonActions) - { - QAction * act = new QAction( - tr("No common action for selected items"), this - ); - menu.addAction(act); - } + QMenu menu(this); - menu.exec(pos); - return; + while (i.hasNext()) + { + i.next(); + if (i.value() < totalItems) continue; + commonActions = true; + QAction * act = actionMapping[i.key()]; + act->setText(act->text().arg(totalItems)); + menu.addAction(act); } + + if (!commonActions) + { + QAction * act = new QAction( + tr("No common action for selected items"), this + ); + menu.addAction(act); + } + + menu.exec(pos); } void InventoryView::slotChdir()