Commit cebd94fe authored by Michal Humpula's avatar Michal Humpula

migrate from KAction to QAction (3/3)

REVIEW: 114509
parent b570690e
......@@ -31,7 +31,6 @@
#include <KLocalizedString>
#include <KPushButton>
#include <KAction>
#include <KMimeTypeTrader>
#include <KIcon>
#include <KShortcut>
......@@ -122,7 +121,7 @@ EditSnippet::EditSnippet(SnippetRepository* repository, Snippet* snippet, QWidge
m_ui->snippetNameEdit->setText(m_snippet->text());
m_ui->snippetPostfixEdit->setText(m_snippet->postfix());
m_ui->snippetPrefixEdit->setText(m_snippet->prefix());
m_ui->snippetShortcutWidget->setShortcut(m_snippet->action()->shortcut());
m_ui->snippetShortcutWidget->setShortcut(m_snippet->action()->shortcuts());
// unset modified flags
m_snippetView->document()->setModified(false);
......@@ -189,7 +188,7 @@ void EditSnippet::save()
m_snippet->setText(m_ui->snippetNameEdit->text());
m_snippet->setPostfix(m_ui->snippetPostfixEdit->text());
m_snippet->setPrefix(m_ui->snippetPrefixEdit->text());
m_snippet->action()->setShortcut(m_ui->snippetShortcutWidget->shortcut());
m_snippet->action()->setShortcuts(m_ui->snippetShortcutWidget->shortcut());
m_repo->setScript(m_scriptsView->document()->text());
m_scriptsView->document()->setModified(false);
m_topBoxModified = false;
......
......@@ -22,15 +22,12 @@
*/
#include "snippet.h"
#include "katesnippetglobal.h"
#include <KLocalizedString>
#include <KIcon>
#include <KColorScheme>
#include "katesnippetglobal.h"
#include <KActionCollection>
#include <KAction>
#include <KParts/MainWindow>
Snippet::Snippet()
......@@ -84,12 +81,12 @@ void Snippet::setArguments(const QString& arguments)
m_arguments = arguments;
}
KAction* Snippet::action()
QAction* Snippet::action()
{
///TODO: this is quite ugly, or is it? if someone knows how to do it better, please refactor
if ( !m_action ) {
static int actionCount = 0;
m_action = new KAction(QString("insertSnippet%1").arg(actionCount), KateSnippetGlobal::self());
m_action = new QAction(QString("insertSnippet%1").arg(actionCount), KateSnippetGlobal::self());
m_action->setData(QVariant::fromValue<Snippet*>(this));
KateSnippetGlobal::self()->connect(m_action, SIGNAL(triggered()),
KateSnippetGlobal::self(), SLOT(insertSnippetFromActionData()));
......
......@@ -27,7 +27,7 @@
#include <QStandardItem>
class SnippetRepository;
class KAction;
class QAction;
/**
* One object of this class represents a single snippet.
......@@ -87,7 +87,7 @@ public:
/**
* Action to trigger insertion of this snippet.
*/
KAction* action();
QAction* action();
virtual QVariant data(int role = Qt::UserRole + 1) const;
......@@ -101,7 +101,7 @@ private:
/// the display arguments aka \code<displayarguments>\endcode
QString m_arguments;
/// the insertion action for this snippet.
KAction* m_action;
QAction* m_action;
};
Q_DECLARE_METATYPE ( Snippet* )
......
......@@ -28,6 +28,7 @@
#include <QTimer>
#include <QFile>
#include <QFileInfo>
#include <QAction>
#include <KIcon>
#include <KGlobal>
......@@ -44,7 +45,6 @@
#include <KUser>
#include <KAction>
#include <KShortcut>
#include "snippetstore.h"
......@@ -249,9 +249,14 @@ void SnippetRepository::save()
if ( !snippet ) {
continue;
}
config.writeEntry("shortcut " + snippet->text(),
QStringList() << snippet->action()->shortcut().primary().toString()
<< snippet->action()->shortcut().alternate().toString());
QStringList shortcuts;
foreach ( const QKeySequence &keys, snippet->action()->shortcuts() ) {
shortcuts << keys.toString();
}
config.writeEntry( "shortcut " + snippet->text(), shortcuts );
}
config.sync();
}
......@@ -336,12 +341,15 @@ void SnippetRepository::slotParseFile()
continue;
} else {
const QStringList shortcuts = config.readEntry("shortcut " + snippet->text(), QStringList());
if ( shortcuts.count() >= 2 ) {
KShortcut shortcut;
shortcut.setPrimary(shortcuts.value(0));
shortcut.setAlternate(shortcuts.value(1));
snippet->action()->setShortcut(shortcut);
QList<QKeySequence> sequences;
foreach ( const QString &shortcut, shortcuts ) {
sequences << QKeySequence::fromString( shortcut );
}
snippet->action()->setShortcuts( sequences );
appendRow(snippet);
}
}
......
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