Commit 4c3856c0 authored by Amish Naidu's avatar Amish Naidu
Browse files

Allow configuring shortcut for Run Scratch action and add to Run menu

Summary: Add "Run Scratch" action to main window and thus allow configuring it.

Reviewers: kfunk

Reviewed By: kfunk

Subscribers: arrowd, kdevelop-devel

Tags: #kdevelop

Differential Revision: https://phabricator.kde.org/D17569
parent e7bd7d39
......@@ -7,6 +7,8 @@ set(scratchpad_SRCS
ki18n_wrap_ui(scratchpad_SRCS scratchpadview.ui)
qt5_add_resources(scratchpad_SRCS kdevscratchpad.qrc)
declare_qt_logging_category(scratchpad_SRCS
TYPE PLUGIN
IDENTIFIER PLUGIN_SCRATCHPAD
......
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource prefix="/kxmlgui5/scratchpad">
<file>kdevscratchpad.rc</file>
</qresource>
</RCC>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="scratchpad" version="1" translationDomain="kdevscratchpad">
<MenuBar>
<Menu name="run">
<Action name="run_scratch"/>
</Menu>
</MenuBar>
</gui>
......@@ -33,6 +33,7 @@
#include <KLocalizedString>
#include <KSharedConfig>
#include <KConfigGroup>
#include <KActionCollection>
#include <QStandardItemModel>
#include <QStandardPaths>
......@@ -108,6 +109,7 @@ Scratchpad::Scratchpad(QObject* parent, const QVariantList& args)
: KDevelop::IPlugin(QStringLiteral("scratchpad"), parent)
, m_factory(new ScratchpadToolViewFactory(this))
, m_model(new QStandardItemModel(this))
, m_runAction(new QAction(this))
{
Q_UNUSED(args);
......@@ -258,4 +260,21 @@ void Scratchpad::setCommand(const QModelIndex& index, const QString& command)
mimeCommands().writeEntry(QFileInfo(index.data().toString()).suffix(), command);
}
QAction* Scratchpad::runAction() const
{
return m_runAction;
}
void Scratchpad::createActionsForMainWindow(Sublime::MainWindow* window, QString& xmlFile, KActionCollection& actions)
{
Q_UNUSED(window);
xmlFile = QStringLiteral("kdevscratchpad.rc");
// add to gui action collection, so that the shorcut is easily configurable
// action setup done in ScratchpadView
actions.addAction(QStringLiteral("run_scratch"), m_runAction);
}
#include "scratchpad.moc"
......@@ -31,6 +31,7 @@ class QStandardItemModel;
class QModelIndex;
class QFileInfo;
class QString;
class QAction;
class Scratchpad
: public KDevelop::IPlugin
......@@ -42,8 +43,12 @@ public:
QStandardItemModel* model() const;
QAction* runAction() const;
static QString dataDirectory();
void createActionsForMainWindow(Sublime::MainWindow* window, QString& xmlFile, KActionCollection& actions) override;
enum ExtraRoles {
FullPathRole = Qt::UserRole + 1,
RunCommandRole,
......@@ -66,6 +71,8 @@ private:
ScratchpadToolViewFactory* m_factory;
QStandardItemModel* m_model;
QFileIconProvider m_iconProvider;
QAction* const m_runAction;
};
#endif // SCRATCHPAD_H
......@@ -159,7 +159,9 @@ void ScratchpadView::setupActions()
addAction(action);
m_itemActions.push_back(action);
action = new QAction(QIcon::fromTheme(QStringLiteral("media-playback-start")), i18n("Run Scratch"), this);
action = m_scratchpad->runAction();
action->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start")));
action->setText(i18n("Run Scratch"));
connect(action, &QAction::triggered, this, &ScratchpadView::runSelectedScratch);
addAction(action);
m_itemActions.push_back(action);
......
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