| 69 | } |
| 70 | |
| 71 | QList<QAction*> KDiff3FileItemAction::actions(const KFileItemListProperties& fileItemInfos, QWidget* pParentWidget) |
| 72 | { |
| 73 | QList<QAction*> actions; |
| 74 | |
| 75 | if(QStandardPaths::findExecutable("kdiff3").isEmpty()) |
| 76 | return actions; |
| 77 | |
| 78 | //m_fileItemInfos = fileItemInfos; |
| 79 | m_pParentWidget = pParentWidget; |
| 80 | |
| 81 | QAction* pMenuAction = new QAction(QIcon::fromTheme(QStringLiteral("kdiff3")), i18nc("Contexualmenu title", "KDiff3..."), this); |
| 82 | QMenu* pActionMenu = new QMenu(); |
| 83 | pMenuAction->setMenu(pActionMenu); |
| 84 | |
| 85 | // remember currently selected files |
| 86 | m_list = fileItemInfos.urlList(); |
| 87 | |
| 88 | /* Menu structure: |
| 89 | KDiff3 -> (1 File selected): Save 'selection' for later comparison (push onto history stack) |
| 90 | Compare 'selection' with first file on history stack. |
| 91 | Compare 'selection' with -> choice from history stack |
| 92 | Merge 'selection' with first file on history stack. |
| 93 | Merge 'selection' with last two files on history stack. |
| 94 | (2 Files selected): Compare 's1' with 's2' |
| 95 | Merge 's1' with 's2' |
| 96 | (3 Files selected): Compare 's1', 's2' and 's3' |
| 97 | */ |
| 98 | |
| 99 | QAction* pAction = nullptr; |
| 100 | QString actionText; |
| 101 | |
| 102 | if(m_list.count() == 1) |
| 103 | { |
| 104 | qsizetype historyCount = s_pHistory ? s_pHistory->count() : 0; |
| 105 | |
| 106 | actionText = i18nc("Contexualmenu option", "Compare with %1", (historyCount > 0 ? s_pHistory->first() : QString())); |
| 107 | pAction = new QAction(actionText, this); |
| 108 | connect(pAction, &QAction::triggered, this, &KDiff3FileItemAction::slotCompareWith); |
| 109 | pAction->setEnabled(m_list.count() > 0 && historyCount > 0); |
| 110 | pActionMenu->addAction(pAction); |
| 111 | |
| 112 | actionText = i18nc("Contexualmenu option", "Merge with %1", historyCount > 0 ? s_pHistory->first() : QString()); |
| 113 | pAction = new QAction(actionText, this); |
| 114 | connect(pAction, &QAction::triggered, this, &KDiff3FileItemAction::slotMergeWith); |
| 115 | pAction->setEnabled(m_list.count() > 0 && historyCount > 0); |
| 116 | pActionMenu->addAction(pAction); |
| 117 | |
| 118 | actionText = i18nc("Contexualmenu option", "Save '%1' for later", m_list.first().fileName()); |
| 119 | pAction = new QAction(actionText, this); |
| 120 | connect(pAction, &QAction::triggered, this, &KDiff3FileItemAction::slotSaveForLater); |
| 121 | pAction->setEnabled(m_list.count() > 0); |
| 122 | pActionMenu->addAction(pAction); |
| 123 | |
| 124 | pAction = new QAction(i18nc("Contexualmenu option", "3-way merge with base"), this); |
| 125 | connect(pAction, &QAction::triggered, this, &KDiff3FileItemAction::slotMergeThreeWay); |
| 126 | pAction->setEnabled(m_list.count() > 0 && historyCount >= 2); |
| 127 | pActionMenu->addAction(pAction); |
| 128 |
no test coverage detected