Commit 84dbc21f authored by Jarosław Staniek's avatar Jarosław Staniek
Browse files

Make main shortcuts trigger only enabled actions

This fixes a crash (when pressing Ctrl+S i Data mode) introduced while fixing bug #334587.
In addition added condition for Save/Save As methods so they are ignored in Data mode even if called explicitly.

CCBUG:334587
parent b8a9832a
/* This file is part of the KDE project
Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
Copyright (C) 2003-2013 Jarosław Staniek <staniek@kde.org>
Copyright (C) 2003-2014 Jarosław Staniek <staniek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -296,6 +296,24 @@ int KexiMainWindow::create(int argc, char *argv[], const KAboutData &aboutData)
//-------------------------------------------------
KexiMainMenuActionShortcut::KexiMainMenuActionShortcut(const QKeySequence& key,
QWidget *parent, QAction *action)
: QShortcut(key, parent)
, m_action(action)
{
connect(this, SIGNAL(activated()), this, SLOT(slotActivated()));
}
void KexiMainMenuActionShortcut::slotActivated()
{
if (!m_action->isEnabled()) {
return;
}
m_action->trigger();
}
//-------------------------------------------------
KexiMainWindow::KexiMainWindow(QWidget *parent)
: KexiMainWindowSuper(parent)
, KexiMainWindowIface()
......@@ -406,12 +424,10 @@ void KexiMainWindow::setupMainMenuActionShortcut(KAction* action)
{
if (!action->shortcut().isEmpty()) {
if (!action->shortcut().primary().isEmpty()) {
QShortcut *s = new QShortcut(action->shortcut().primary(), this);
connect(s, SIGNAL(activated()), action, SLOT(trigger()));
(void)new KexiMainMenuActionShortcut(action->shortcut().primary(), this, action);
}
if (!action->shortcut().alternate().isEmpty()) {
QShortcut *s = new QShortcut(action->shortcut().alternate(), this);
connect(s, SIGNAL(activated()), action, SLOT(trigger()));
(void)new KexiMainMenuActionShortcut(action->shortcut().alternate(), this, action);
}
}
}
......@@ -2532,8 +2548,9 @@ void KexiMainWindow::slotProjectWelcome()
void
KexiMainWindow::slotProjectSave()
{
if (!currentWindow())
if (!currentWindow() || currentWindow()->currentViewMode() == Kexi::DataViewMode) {
return;
}
saveObject(currentWindow());
updateAppCaption();
invalidateActions();
......@@ -2542,8 +2559,9 @@ KexiMainWindow::slotProjectSave()
void
KexiMainWindow::slotProjectSaveAs()
{
if (!currentWindow())
if (!currentWindow() || currentWindow()->currentViewMode() == Kexi::DataViewMode) {
return;
}
saveObject(currentWindow(), QString(), SaveObjectAs);
updateAppCaption();
invalidateActions();
......
/* This file is part of the KDE project
Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
Copyright (C) 2003-2013 Jarosław Staniek <staniek@kde.org>
Copyright (C) 2003-2014 Jarosław Staniek <staniek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -2160,4 +2160,22 @@ private:
KexiFindDialog *m_findDialog;
};
//------------------------------------------
//! Action shortcut used by KexiMainWindow::setupMainMenuActionShortcut(KAction*)
//! Activates action only if enabled.
class KexiMainMenuActionShortcut : public QShortcut
{
Q_OBJECT
public:
KexiMainMenuActionShortcut(const QKeySequence& key, QWidget *parent, QAction *action);
protected slots:
//! Triggers associated action only when this action is enabled
void slotActivated();
private:
QPointer<QAction> m_action;
};
#endif
Supports Markdown
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