Commit 3a5cd569 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

ensure to not crash on missing context menu

contextMenu() is allowed to return a nullptr

check for this to avoid crash on menubar hide/show

see backtrace in related bug, nullptr as menu

BUG: 426939
parent fa1c0602
......@@ -689,7 +689,9 @@ void KateMainWindow::toggleShowMenuBar(bool showMessage)
{
if (m_paShowMenuBar->isChecked()) {
menuBar()->show();
removeMenuBarActionFromContextMenu();
if (m_viewManager->activeView() && m_viewManager->activeView()->contextMenu()) {
m_viewManager->activeView()->contextMenu()->removeAction(m_paShowMenuBar);
}
} else {
if (showMessage) {
const QString accel = m_paShowMenuBar->shortcut().toString();
......@@ -701,21 +703,9 @@ void KateMainWindow::toggleShowMenuBar(bool showMessage)
QStringLiteral("HideMenuBarWarning"));
}
menuBar()->hide();
addMenuBarActionToContextMenu();
}
}
void KateMainWindow::addMenuBarActionToContextMenu()
{
if (m_viewManager->activeView()) {
m_viewManager->activeView()->contextMenu()->addAction(m_paShowMenuBar);
}
}
void KateMainWindow::removeMenuBarActionFromContextMenu()
{
if (m_viewManager->activeView()) {
m_viewManager->activeView()->contextMenu()->removeAction(m_paShowMenuBar);
if (m_viewManager->activeView() && m_viewManager->activeView()->contextMenu()) {
m_viewManager->activeView()->contextMenu()->addAction(m_paShowMenuBar);
}
}
}
......
......@@ -146,9 +146,6 @@ private:
void setupActions();
bool queryClose() override;
void addMenuBarActionToContextMenu();
void removeMenuBarActionFromContextMenu();
/**
* read some global options from katerc
*/
......
......@@ -268,7 +268,9 @@ void KWrite::toggleMenuBar(bool showMessage)
{
if (m_paShowMenuBar->isChecked()) {
menuBar()->show();
removeMenuBarActionFromContextMenu();
if (m_view->contextMenu()) {
m_view->contextMenu()->removeAction(m_paShowMenuBar);
}
} else {
if (showMessage) {
const QString accel = m_paShowMenuBar->shortcut().toString();
......@@ -280,20 +282,12 @@ void KWrite::toggleMenuBar(bool showMessage)
QStringLiteral("HideMenuBarWarning"));
}
menuBar()->hide();
addMenuBarActionToContextMenu();
if (m_view->contextMenu()) {
m_view->contextMenu()->addAction(m_paShowMenuBar);
}
}
}
void KWrite::addMenuBarActionToContextMenu()
{
m_view->contextMenu()->addAction(m_paShowMenuBar);
}
void KWrite::removeMenuBarActionFromContextMenu()
{
m_view->contextMenu()->removeAction(m_paShowMenuBar);
}
void KWrite::toggleStatusBar()
{
m_view->setStatusBarEnabled(m_paShowStatusBar->isChecked());
......
......@@ -42,9 +42,6 @@ public:
private:
void setupActions();
void addMenuBarActionToContextMenu();
void removeMenuBarActionFromContextMenu();
bool queryClose() override;
void dragEnterEvent(QDragEnterEvent *) override;
......
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