Commit 3fb42e62 authored by Michael Reeves's avatar Michael Reeves

Refactor action init

parent 09922b9d
......@@ -599,15 +599,7 @@ void KDiff3App::initActions(KActionCollection* ac)
showWhiteSpace = GuiUtils::createAction<KToggleAction>(i18n("Show White Space"), QIcon(QPixmap(showwhitespace)), i18n("White\nDeltas"), this, &KDiff3App::slotShowWhiteSpaceToggled, ac, "diff_show_whitespace");
showLineNumbers = GuiUtils::createAction<KToggleAction>(i18n("Show Line Numbers"), QIcon(QPixmap(showlinenumbers)), i18n("Line\nNumbers"), this, &KDiff3App::slotShowLineNumbersToggled, ac, "diff_showlinenumbers");
chooseAEverywhere = GuiUtils::createAction<QAction>(i18n("Choose A Everywhere"), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_1), this, &KDiff3App::slotChooseAEverywhere, ac, "merge_choose_a_everywhere");
chooseBEverywhere = GuiUtils::createAction<QAction>(i18n("Choose B Everywhere"), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_2), this, &KDiff3App::slotChooseBEverywhere, ac, "merge_choose_b_everywhere");
chooseCEverywhere = GuiUtils::createAction<QAction>(i18n("Choose C Everywhere"), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_3), this, &KDiff3App::slotChooseCEverywhere, ac, "merge_choose_c_everywhere");
chooseAForUnsolvedConflicts = GuiUtils::createAction<QAction>(i18n("Choose A for All Unsolved Conflicts"), this, &KDiff3App::slotChooseAForUnsolvedConflicts, ac, "merge_choose_a_for_unsolved_conflicts");
chooseBForUnsolvedConflicts = GuiUtils::createAction<QAction>(i18n("Choose B for All Unsolved Conflicts"), this, &KDiff3App::slotChooseBForUnsolvedConflicts, ac, "merge_choose_b_for_unsolved_conflicts");
chooseCForUnsolvedConflicts = GuiUtils::createAction<QAction>(i18n("Choose C for All Unsolved Conflicts"), this, &KDiff3App::slotChooseCForUnsolvedConflicts, ac, "merge_choose_c_for_unsolved_conflicts");
chooseAForUnsolvedWhiteSpaceConflicts = GuiUtils::createAction<QAction>(i18n("Choose A for All Unsolved Whitespace Conflicts"), this, &KDiff3App::slotChooseAForUnsolvedWhiteSpaceConflicts, ac, "merge_choose_a_for_unsolved_whitespace_conflicts");
chooseBForUnsolvedWhiteSpaceConflicts = GuiUtils::createAction<QAction>(i18n("Choose B for All Unsolved Whitespace Conflicts"), this, &KDiff3App::slotChooseBForUnsolvedWhiteSpaceConflicts, ac, "merge_choose_b_for_unsolved_whitespace_conflicts");
chooseCForUnsolvedWhiteSpaceConflicts = GuiUtils::createAction<QAction>(i18n("Choose C for All Unsolved Whitespace Conflicts"), this, &KDiff3App::slotChooseCForUnsolvedWhiteSpaceConflicts, ac, "merge_choose_c_for_unsolved_whitespace_conflicts");
autoSolve = GuiUtils::createAction<QAction>(i18n("Automatically Solve Simple Conflicts"), this, &KDiff3App::slotAutoSolve, ac, "merge_autosolve");
unsolve = GuiUtils::createAction<QAction>(i18n("Set Deltas to Conflicts"), this, &KDiff3App::slotUnsolve, ac, "merge_autounsolve");
mergeRegExp = GuiUtils::createAction<QAction>(i18n("Run Regular Expression Auto Merge"), this, &KDiff3App::slotRegExpAutoMerge, ac, "merge_regexp_automerge");
......
......@@ -219,15 +219,6 @@ class KDiff3App : public QSplitter
void slotUnsolve();
void slotMergeHistory();
void slotRegExpAutoMerge();
void slotChooseAEverywhere();
void slotChooseBEverywhere();
void slotChooseCEverywhere();
void slotChooseAForUnsolvedConflicts();
void slotChooseBForUnsolvedConflicts();
void slotChooseCForUnsolvedConflicts();
void slotChooseAForUnsolvedWhiteSpaceConflicts();
void slotChooseBForUnsolvedWhiteSpaceConflicts();
void slotChooseCForUnsolvedWhiteSpaceConflicts();
void slotConfigure();
void slotConfigureKeys();
void slotRefresh();
......@@ -305,15 +296,6 @@ class KDiff3App : public QSplitter
KToggleAction* showWhiteSpaceCharacters;
KToggleAction* showWhiteSpace;
KToggleAction* showLineNumbers;
QAction* chooseAEverywhere;
QAction* chooseBEverywhere;
QAction* chooseCEverywhere;
QAction* chooseAForUnsolvedConflicts;
QAction* chooseBForUnsolvedConflicts;
QAction* chooseCForUnsolvedConflicts;
QAction* chooseAForUnsolvedWhiteSpaceConflicts;
QAction* chooseBForUnsolvedWhiteSpaceConflicts;
QAction* chooseCForUnsolvedWhiteSpaceConflicts;
QAction* autoSolve;
QAction* unsolve;
QAction* mergeHistory;
......
......@@ -12,6 +12,7 @@
#include "mergeresultwindow.h"
#include "options.h"
#include "RLPainter.h"
#include "guiutils.h"
#include <QApplication>
#include <QClipboard>
......@@ -33,6 +34,7 @@
#include <QTextStream>
#include <QUrl>
#include <QAction>
#include <QDropEvent>
#include <QEvent>
#include <QFocusEvent>
......@@ -44,8 +46,10 @@
#include <QTimerEvent>
#include <QWheelEvent>
#include <KActionCollection>
#include <KLocalizedString>
#include <KMessageBox>
#include <KToggleAction>
int g_bAutoSolve = true;
......@@ -144,6 +148,24 @@ void MergeResultWindow::init(
showUnsolvedConflictsStatusMessage();
}
void MergeResultWindow::initActions(KActionCollection* ac)
{
if(ac == nullptr){
KMessageBox::error(nullptr, "actionCollection==0");
exit(-1);//we cannot recover from this.
}
chooseAEverywhere = GuiUtils::createAction<QAction>(i18n("Choose A Everywhere"), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_1), this, &MergeResultWindow::slotChooseAEverywhere, ac, "merge_choose_a_everywhere");
chooseBEverywhere = GuiUtils::createAction<QAction>(i18n("Choose B Everywhere"), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_2), this, &MergeResultWindow::slotChooseBEverywhere, ac, "merge_choose_b_everywhere");
chooseCEverywhere = GuiUtils::createAction<QAction>(i18n("Choose C Everywhere"), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_3), this, &MergeResultWindow::slotChooseCEverywhere, ac, "merge_choose_c_everywhere");
chooseAForUnsolvedConflicts = GuiUtils::createAction<QAction>(i18n("Choose A for All Unsolved Conflicts"), this, &MergeResultWindow::slotChooseAForUnsolvedConflicts, ac, "merge_choose_a_for_unsolved_conflicts");
chooseBForUnsolvedConflicts = GuiUtils::createAction<QAction>(i18n("Choose B for All Unsolved Conflicts"), this, &MergeResultWindow::slotChooseBForUnsolvedConflicts, ac, "merge_choose_b_for_unsolved_conflicts");
chooseCForUnsolvedConflicts = GuiUtils::createAction<QAction>(i18n("Choose C for All Unsolved Conflicts"), this, &MergeResultWindow::slotChooseCForUnsolvedConflicts, ac, "merge_choose_c_for_unsolved_conflicts");
chooseAForUnsolvedWhiteSpaceConflicts = GuiUtils::createAction<QAction>(i18n("Choose A for All Unsolved Whitespace Conflicts"), this, &MergeResultWindow::slotChooseAForUnsolvedWhiteSpaceConflicts, ac, "merge_choose_a_for_unsolved_whitespace_conflicts");
chooseBForUnsolvedWhiteSpaceConflicts = GuiUtils::createAction<QAction>(i18n("Choose B for All Unsolved Whitespace Conflicts"), this, &MergeResultWindow::slotChooseBForUnsolvedWhiteSpaceConflicts, ac, "merge_choose_b_for_unsolved_whitespace_conflicts");
chooseCForUnsolvedWhiteSpaceConflicts = GuiUtils::createAction<QAction>(i18n("Choose C for All Unsolved Whitespace Conflicts"), this, &MergeResultWindow::slotChooseCForUnsolvedWhiteSpaceConflicts, ac, "merge_choose_c_for_unsolved_whitespace_conflicts");
}
void MergeResultWindow::showUnsolvedConflictsStatusMessage()
{
if(m_pStatusBar)
......@@ -156,6 +178,19 @@ void MergeResultWindow::showUnsolvedConflictsStatusMessage()
}
}
void MergeResultWindow::slotUpdateAvailabilities(bool bMergeEditorVisible,const bool bTripleDiff)
{
chooseAEverywhere->setEnabled(bMergeEditorVisible);
chooseBEverywhere->setEnabled(bMergeEditorVisible);
chooseCEverywhere->setEnabled(bMergeEditorVisible && bTripleDiff);
chooseAForUnsolvedConflicts->setEnabled(bMergeEditorVisible);
chooseBForUnsolvedConflicts->setEnabled(bMergeEditorVisible);
chooseCForUnsolvedConflicts->setEnabled(bMergeEditorVisible && bTripleDiff);
chooseAForUnsolvedWhiteSpaceConflicts->setEnabled(bMergeEditorVisible);
chooseBForUnsolvedWhiteSpaceConflicts->setEnabled(bMergeEditorVisible);
chooseCForUnsolvedWhiteSpaceConflicts->setEnabled(bMergeEditorVisible && bTripleDiff);
}
void MergeResultWindow::slotStatusMessageChanged(const QString& s)
{
if(s.isEmpty() && !m_persistentStatusMessage.isEmpty())
......
......@@ -23,6 +23,8 @@
class QPainter;
class RLPainter;
class KActionCollection;
class KToggleAction;
class MergeResultWindow : public QWidget
{
Q_OBJECT
......@@ -36,7 +38,7 @@ public:
const Diff3LineList* pDiff3LineList,
TotalDiffStatus* pTotalDiffStatus
);
void initActions(KActionCollection* ac);
void reset();
bool saveDocument( const QString& fileName, QTextCodec* pEncoding, e_LineEndStyle eLineEndStyle );
......@@ -62,6 +64,9 @@ public:
void setSelection( int firstLine, int startPos, int lastLine, int endPos );
void setOverviewMode( Overview::e_OverviewMode eOverviewMode );
Overview::e_OverviewMode getOverviewMode();
void slotUpdateAvailabilities(const bool bMergeEditorVisible, const bool m_bTripleDiff);
public Q_SLOTS:
void setFirstLine(int firstLine);
void setHorizScrollOffset(int horizScrollOffset);
......@@ -86,7 +91,17 @@ public Q_SLOTS:
void updateSourceMask();
void slotStatusMessageChanged( const QString& );
Q_SIGNALS:
void slotChooseAEverywhere() { chooseGlobal(A, false, false); }
void slotChooseBEverywhere() { chooseGlobal(B, false, false); }
void slotChooseCEverywhere() { chooseGlobal(C, false, false); }
void slotChooseAForUnsolvedConflicts() { chooseGlobal(A, true, false); }
void slotChooseBForUnsolvedConflicts() { chooseGlobal(B, true, false); }
void slotChooseCForUnsolvedConflicts() { chooseGlobal(C, true, false); }
void slotChooseAForUnsolvedWhiteSpaceConflicts() { chooseGlobal(A, true, true); }
void slotChooseBForUnsolvedWhiteSpaceConflicts() { chooseGlobal(B, true, true); }
void slotChooseCForUnsolvedWhiteSpaceConflicts() { chooseGlobal(C, true, true); }
Q_SIGNALS:
void scrollMergeResultWindow( int deltaX, int deltaY );
void modifiedChanged(bool bModified);
void setFastSelectorRange( int line1, int nofLines );
......@@ -102,7 +117,17 @@ private:
void merge(bool bAutoSolve, e_SrcSelector defaultSelector, bool bConflictsOnly=false, bool bWhiteSpaceOnly=false );
QString getString( int lineIdx );
Options* m_pOptions;
QAction* chooseAEverywhere = nullptr;
QAction* chooseBEverywhere = nullptr;
QAction* chooseCEverywhere = nullptr;
QAction* chooseAForUnsolvedConflicts = nullptr;
QAction* chooseBForUnsolvedConflicts = nullptr;
QAction* chooseCForUnsolvedConflicts = nullptr;
QAction* chooseAForUnsolvedWhiteSpaceConflicts = nullptr;
QAction* chooseBForUnsolvedWhiteSpaceConflicts = nullptr;
QAction* chooseCForUnsolvedWhiteSpaceConflicts = nullptr;
Options* m_pOptions = nullptr;
const LineData* m_pldA;
const LineData* m_pldB;
......@@ -138,10 +163,10 @@ private:
Diff3LineList::const_iterator id3l(){return m_id3l;}
// getString() is implemented as MergeResultWindow::getString()
private:
Diff3LineList::const_iterator m_id3l;
e_SrcSelector m_src; // 1, 2 or 3 for A, B or C respectively, or 0 when line is from neither source.
QString m_str; // String when modified by user or null-string when orig data is used.
bool m_bLineRemoved;
Diff3LineList::const_iterator m_id3l;
e_SrcSelector m_src; // 1, 2 or 3 for A, B or C respectively, or 0 when line is from neither source.
QString m_str; // String when modified by user or null-string when orig data is used.
bool m_bLineRemoved;
};
class MergeEditLineList : private std::list<MergeEditLine>
......
......@@ -335,6 +335,7 @@ void KDiff3App::mainInit(TotalDiffStatus* pTotalDiffStatus, bool bLoadFiles, boo
oldHeights = m_pMainSplitter->sizes();
initView();
m_pMergeResultWindow->initActions(actionCollection());
if(m_pDirectoryMergeSplitter->isVisible())
{
......@@ -1375,25 +1376,6 @@ void KDiff3App::slotChooseA() { choose(A); }
void KDiff3App::slotChooseB() { choose(B); }
void KDiff3App::slotChooseC() { choose(C); }
// bConflictsOnly automatically choose for conflicts only (true) or for everywhere
static void mergeChooseGlobal(MergeResultWindow* pMRW, int selector, bool bConflictsOnly, bool bWhiteSpaceOnly)
{
if(pMRW)
{
pMRW->chooseGlobal(selector, bConflictsOnly, bWhiteSpaceOnly);
}
}
void KDiff3App::slotChooseAEverywhere() { mergeChooseGlobal(m_pMergeResultWindow, A, false, false); }
void KDiff3App::slotChooseBEverywhere() { mergeChooseGlobal(m_pMergeResultWindow, B, false, false); }
void KDiff3App::slotChooseCEverywhere() { mergeChooseGlobal(m_pMergeResultWindow, C, false, false); }
void KDiff3App::slotChooseAForUnsolvedConflicts() { mergeChooseGlobal(m_pMergeResultWindow, A, true, false); }
void KDiff3App::slotChooseBForUnsolvedConflicts() { mergeChooseGlobal(m_pMergeResultWindow, B, true, false); }
void KDiff3App::slotChooseCForUnsolvedConflicts() { mergeChooseGlobal(m_pMergeResultWindow, C, true, false); }
void KDiff3App::slotChooseAForUnsolvedWhiteSpaceConflicts() { mergeChooseGlobal(m_pMergeResultWindow, A, true, true); }
void KDiff3App::slotChooseBForUnsolvedWhiteSpaceConflicts() { mergeChooseGlobal(m_pMergeResultWindow, B, true, true); }
void KDiff3App::slotChooseCForUnsolvedWhiteSpaceConflicts() { mergeChooseGlobal(m_pMergeResultWindow, C, true, true); }
void KDiff3App::slotAutoSolve()
{
if(m_pMergeResultWindow)
......@@ -2434,7 +2416,7 @@ void KDiff3App::slotUpdateAvailabilities()
}
bool bDiffWindowVisible = m_pMainWidget != nullptr && m_pMainWidget->isVisible();
bool bMergeEditorVisible = m_pMergeWindowFrame != nullptr && m_pMergeWindowFrame->isVisible();
bool bMergeEditorVisible = m_pMergeWindowFrame != nullptr && m_pMergeWindowFrame->isVisible() && m_pMergeResultWindow != nullptr;
m_pDirectoryMergeWindow->updateAvailabilities(m_bDirCompare, bDiffWindowVisible, chooseA, chooseB, chooseC);
......@@ -2457,15 +2439,11 @@ void KDiff3App::slotUpdateAvailabilities()
chooseB->setEnabled(bMergeEditorVisible);
chooseC->setEnabled(bMergeEditorVisible && m_bTripleDiff);
}
chooseAEverywhere->setEnabled(bMergeEditorVisible);
chooseBEverywhere->setEnabled(bMergeEditorVisible);
chooseCEverywhere->setEnabled(bMergeEditorVisible && m_bTripleDiff);
chooseAForUnsolvedConflicts->setEnabled(bMergeEditorVisible);
chooseBForUnsolvedConflicts->setEnabled(bMergeEditorVisible);
chooseCForUnsolvedConflicts->setEnabled(bMergeEditorVisible && m_bTripleDiff);
chooseAForUnsolvedWhiteSpaceConflicts->setEnabled(bMergeEditorVisible);
chooseBForUnsolvedWhiteSpaceConflicts->setEnabled(bMergeEditorVisible);
chooseCForUnsolvedWhiteSpaceConflicts->setEnabled(bMergeEditorVisible && m_bTripleDiff);
if(m_pMergeResultWindow != nullptr)
{
m_pMergeResultWindow->slotUpdateAvailabilities(bMergeEditorVisible, m_bTripleDiff);
}
mergeHistory->setEnabled(bMergeEditorVisible);
mergeRegExp->setEnabled(bMergeEditorVisible);
showWindowA->setEnabled(bDiffWindowVisible && (m_pDiffTextWindow2->isVisible() || m_pDiffTextWindow3->isVisible()));
......@@ -2480,15 +2458,15 @@ void KDiff3App::slotUpdateAvailabilities()
fileSave->setEnabled(m_bOutputModified && bSavable);
fileSaveAs->setEnabled(bSavable);
goTop->setEnabled(bDiffWindowVisible && m_pMergeResultWindow->isDeltaAboveCurrent());
goBottom->setEnabled(bDiffWindowVisible && m_pMergeResultWindow->isDeltaBelowCurrent());
goTop->setEnabled(bDiffWindowVisible && bMergeEditorVisible && m_pMergeResultWindow->isDeltaAboveCurrent());
goBottom->setEnabled(bDiffWindowVisible && bMergeEditorVisible && m_pMergeResultWindow->isDeltaBelowCurrent());
goCurrent->setEnabled(bDiffWindowVisible);
goPrevUnsolvedConflict->setEnabled(bMergeEditorVisible && m_pMergeResultWindow->isUnsolvedConflictAboveCurrent());
goNextUnsolvedConflict->setEnabled(bMergeEditorVisible && m_pMergeResultWindow->isUnsolvedConflictBelowCurrent());
goPrevConflict->setEnabled(bDiffWindowVisible && m_pMergeResultWindow->isConflictAboveCurrent());
goNextConflict->setEnabled(bDiffWindowVisible && m_pMergeResultWindow->isConflictBelowCurrent());
goPrevDelta->setEnabled(bDiffWindowVisible && m_pMergeResultWindow->isDeltaAboveCurrent());
goNextDelta->setEnabled(bDiffWindowVisible && m_pMergeResultWindow->isDeltaBelowCurrent());
goPrevConflict->setEnabled(bDiffWindowVisible && bMergeEditorVisible &&m_pMergeResultWindow->isConflictAboveCurrent());
goNextConflict->setEnabled(bDiffWindowVisible && bMergeEditorVisible &&m_pMergeResultWindow->isConflictBelowCurrent());
goPrevDelta->setEnabled(bDiffWindowVisible && bMergeEditorVisible && m_pMergeResultWindow->isDeltaAboveCurrent());
goNextDelta->setEnabled(bDiffWindowVisible && bMergeEditorVisible && m_pMergeResultWindow->isDeltaBelowCurrent());
overviewModeNormal->setEnabled(m_bTripleDiff && bDiffWindowVisible);
overviewModeAB->setEnabled(m_bTripleDiff && bDiffWindowVisible);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment