Commit 1c86432a authored by Michael Reeves's avatar Michael Reeves

Fix missing menu items.

Make sure all menu related actions are created before calling  KXMLGUIClient::setXMLFile.
The actual signal connections can happen later.

Perfer having MergeResultWindow handle the creation and connection
of merge related actions that depend on it to function. Avoids potential
nullptr issue if one is triggered unexpectedly early in startup.  This also
improves readability KDiff3App is quite large even without this and would
just have small wrapper functions for these actions.

Thanks turtle@think-electric.com for spotting the bug.

BUG: 411602
FIXED-IN: 1.8.2
parent 71434569
......@@ -129,6 +129,98 @@ namespace GuiUtils {
theAction->setIconText( iconText );
return theAction;
}
//Allow actions to be created without connecting them immediately.
template <class T>
inline typename std::enable_if<std::is_same<T, QAction>::value, QAction>::type* createAction(
const QString& text,
KActionCollection* ac,
const QString& actionName)
{
Q_ASSERT(ac != nullptr);
QAction* theAction;
theAction = ac->addAction(actionName);
theAction->setText(text);
return theAction;
}
template <class T>
inline typename std::enable_if<std::is_same<T, KToggleAction>::value, KToggleAction>::type* createAction(
const QString& text,
KActionCollection* ac,
const QString &actionName) {
Q_ASSERT( ac != nullptr );
KToggleAction* theAction = new KToggleAction(ac);
ac->addAction( actionName, theAction );
theAction->setText( text );
return theAction;
}
template <class T>
T* createAction(
const QString& text,
const QKeySequence& shortcut,
KActionCollection* ac,
const QString &actionName)
{
T* theAction = createAction<T>( text, ac, actionName );
ac->setDefaultShortcut(theAction, shortcut);
return theAction;
}
template <class T>
T* createAction(
const QString& text,
const QIcon& icon,
KActionCollection* ac,
const QString &actionName)
{
T* theAction = createAction<T>( text, ac, actionName );
theAction->setIcon( icon );
return theAction;
}
template <class T>
T* createAction(
const QString& text,
const QIcon& icon,
const QString& iconText,
KActionCollection* ac,
const QString &actionName)
{
T* theAction = createAction<T>( text, ac, actionName );
theAction->setIcon( icon );
theAction->setIconText( iconText );
return theAction;
}
template <class T>
T* createAction(
const QString& text,
const QIcon& icon,
const QKeySequence& shortcut,
KActionCollection* ac,
const QString &actionName)
{
T* theAction = createAction<T>( text, shortcut, ac, actionName );
theAction->setIcon( icon );
return theAction;
}
template <class T>
T* createAction(
const QString& text,
const QIcon& icon,
const QString& iconText,
const QKeySequence& shortcut,
KActionCollection* ac,
const QString &actionName)
{
T* theAction = createAction<T>( text, shortcut, ac, actionName );
theAction->setIcon( icon );
theAction->setIconText( iconText );
return theAction;
}
}
#endif
......@@ -312,6 +312,8 @@ KDiff3App::KDiff3App(QWidget* pParent, const QString& name, KDiff3Part* pKDiff3P
///////////////////////////////////////////////////////////////////
// call inits to invoke all other construction parts
initActions(actionCollection());
MergeResultWindow::initActions(actionCollection());
initStatusBar();
m_pFindDialog = new FindDialog(this);
......
......@@ -55,6 +55,16 @@ bool g_bAutoSolve = true;
#undef leftInfoWidth
QAction* MergeResultWindow::chooseAEverywhere = nullptr;
QAction* MergeResultWindow::chooseBEverywhere = nullptr;
QAction* MergeResultWindow::chooseCEverywhere = nullptr;
QAction* MergeResultWindow::chooseAForUnsolvedConflicts = nullptr;
QAction* MergeResultWindow::chooseBForUnsolvedConflicts = nullptr;
QAction* MergeResultWindow::chooseCForUnsolvedConflicts = nullptr;
QAction* MergeResultWindow::chooseAForUnsolvedWhiteSpaceConflicts = nullptr;
QAction* MergeResultWindow::chooseBForUnsolvedWhiteSpaceConflicts = nullptr;
QAction* MergeResultWindow::chooseCForUnsolvedWhiteSpaceConflicts = nullptr;
MergeResultWindow::MergeResultWindow(
QWidget* pParent,
Options* pOptions,
......@@ -147,6 +157,8 @@ void MergeResultWindow::init(
showUnsolvedConflictsStatusMessage();
}
//This must be called before KXMLGui::SetXMLFile and friends or the actions will not be shown in the menu.
//At that point in startup we don't have a MergeResultWindow object so we cannot connect the signals yet.
void MergeResultWindow::initActions(KActionCollection* ac)
{
if(ac == nullptr){
......@@ -154,15 +166,30 @@ void MergeResultWindow::initActions(KActionCollection* ac)
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");
chooseAEverywhere = GuiUtils::createAction<QAction>(i18n("Choose A Everywhere"), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_1), ac, "merge_choose_a_everywhere");
chooseBEverywhere = GuiUtils::createAction<QAction>(i18n("Choose B Everywhere"), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_2), ac, "merge_choose_b_everywhere");
chooseCEverywhere = GuiUtils::createAction<QAction>(i18n("Choose C Everywhere"), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_3), ac, "merge_choose_c_everywhere");
chooseAForUnsolvedConflicts = GuiUtils::createAction<QAction>(i18n("Choose A for All Unsolved Conflicts"), ac, "merge_choose_a_for_unsolved_conflicts");
chooseBForUnsolvedConflicts = GuiUtils::createAction<QAction>(i18n("Choose B for All Unsolved Conflicts"), ac, "merge_choose_b_for_unsolved_conflicts");
chooseCForUnsolvedConflicts = GuiUtils::createAction<QAction>(i18n("Choose C for All Unsolved Conflicts"), ac, "merge_choose_c_for_unsolved_conflicts");
chooseAForUnsolvedWhiteSpaceConflicts = GuiUtils::createAction<QAction>(i18n("Choose A for All Unsolved Whitespace Conflicts"), ac, "merge_choose_a_for_unsolved_whitespace_conflicts");
chooseBForUnsolvedWhiteSpaceConflicts = GuiUtils::createAction<QAction>(i18n("Choose B for All Unsolved Whitespace Conflicts"), ac, "merge_choose_b_for_unsolved_whitespace_conflicts");
chooseCForUnsolvedWhiteSpaceConflicts = GuiUtils::createAction<QAction>(i18n("Choose C for All Unsolved Whitespace Conflicts"), ac, "merge_choose_c_for_unsolved_whitespace_conflicts");
}
void MergeResultWindow::connectActions()
{
QObject::connect(chooseAEverywhere, &QAction::triggered, this, &MergeResultWindow::slotChooseAEverywhere);
QObject::connect(chooseBEverywhere, &QAction::triggered, this, &MergeResultWindow::slotChooseBEverywhere);
QObject::connect(chooseCEverywhere, &QAction::triggered, this, &MergeResultWindow::slotChooseCEverywhere);
QObject::connect(chooseAForUnsolvedConflicts, &QAction::triggered, this, &MergeResultWindow::slotChooseAForUnsolvedConflicts);
QObject::connect(chooseBForUnsolvedConflicts, &QAction::triggered, this, &MergeResultWindow::slotChooseBForUnsolvedConflicts);
QObject::connect(chooseCForUnsolvedConflicts, &QAction::triggered, this, &MergeResultWindow::slotChooseCForUnsolvedConflicts);
QObject::connect(chooseAForUnsolvedWhiteSpaceConflicts, &QAction::triggered, this, &MergeResultWindow::slotChooseAForUnsolvedWhiteSpaceConflicts);
QObject::connect(chooseBForUnsolvedWhiteSpaceConflicts, &QAction::triggered, this, &MergeResultWindow::slotChooseBForUnsolvedWhiteSpaceConflicts);
QObject::connect(chooseCForUnsolvedWhiteSpaceConflicts, &QAction::triggered, this, &MergeResultWindow::slotChooseCForUnsolvedWhiteSpaceConflicts);
}
void MergeResultWindow::showUnsolvedConflictsStatusMessage()
......
......@@ -47,7 +47,9 @@ public:
m_mergeLineList.clear();
}
void initActions(KActionCollection* ac);
static void initActions(KActionCollection* ac);
void connectActions();
void reset();
bool saveDocument( const QString& fileName, QTextCodec* pEncoding, e_LineEndStyle eLineEndStyle );
......@@ -126,15 +128,15 @@ private:
void merge(bool bAutoSolve, e_SrcSelector defaultSelector, bool bConflictsOnly=false, bool bWhiteSpaceOnly=false );
QString getString( int lineIdx );
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;
static QAction* chooseAEverywhere;
static QAction* chooseBEverywhere;
static QAction* chooseCEverywhere;
static QAction* chooseAForUnsolvedConflicts;
static QAction* chooseBForUnsolvedConflicts;
static QAction* chooseCForUnsolvedConflicts;
static QAction* chooseAForUnsolvedWhiteSpaceConflicts;
static QAction* chooseBForUnsolvedWhiteSpaceConflicts;
static QAction* chooseCForUnsolvedWhiteSpaceConflicts;
Options* m_pOptions = nullptr;
......
......@@ -345,7 +345,7 @@ void KDiff3App::mainInit(TotalDiffStatus* pTotalDiffStatus, bool bLoadFiles, boo
oldHeights = m_pMainSplitter->sizes();
initView();
m_pMergeResultWindow->initActions(actionCollection());
m_pMergeResultWindow->connectActions();
if(m_pDirectoryMergeSplitter->isVisible())
{
......
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