Commit 46eb52dc authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

interactiveconsole: Allow specifying mode from command line parameter

This is needed for the runner, which has two different keywords for the two scripting modes

CCBUG: 444366


(cherry picked from commit 63bea079)
parent f126732f
......@@ -48,7 +48,7 @@ static const QString s_autosaveFileName(QStringLiteral("interactiveconsoleautosa
static const QString s_kwinService = QStringLiteral("org.kde.KWin");
static const QString s_plasmaShellService = QStringLiteral("org.kde.plasmashell");
InteractiveConsole::InteractiveConsole(QWidget *parent)
InteractiveConsole::InteractiveConsole(ConsoleMode mode, QWidget *parent)
: QDialog(parent)
, m_splitter(new QSplitter(Qt::Vertical, this))
, m_editorPart(nullptr)
......@@ -63,7 +63,7 @@ InteractiveConsole::InteractiveConsole(QWidget *parent)
, m_snippetsMenu(new QMenu(i18n("Templates"), this))
, m_fileDialog(nullptr)
, m_closeWhenCompleted(false)
, m_mode(PlasmaConsole)
, m_mode(mode)
{
addAction(KStandardAction::close(this, SLOT(close()), this));
addAction(m_saveAction);
......@@ -101,7 +101,8 @@ InteractiveConsole::InteractiveConsole(QWidget *parent)
modeGroup->addAction(m_kwinAction);
m_plasmaAction->setCheckable(true);
m_kwinAction->setCheckable(true);
m_plasmaAction->setChecked(true);
m_kwinAction->setChecked(mode == KWinConsole);
m_plasmaAction->setChecked(mode == PlasmaConsole);
connect(modeGroup, &QActionGroup::triggered, this, &InteractiveConsole::modeSelectionChanged);
KToolBar *toolBar = new KToolBar(this, true, false);
......
......@@ -37,14 +37,14 @@ class InteractiveConsole : public QDialog
Q_OBJECT
public:
explicit InteractiveConsole(QWidget *parent = nullptr);
~InteractiveConsole() override;
enum ConsoleMode {
PlasmaConsole,
KWinConsole,
};
explicit InteractiveConsole(ConsoleMode mode, QWidget *parent = nullptr);
~InteractiveConsole() override;
void setMode(const QString &mode);
QString mode() const;
......
/*
SPDX-FileCopyrightText: 2021 David Edmundson <davidedmundson@kde.org>
SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "interactiveconsole.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QDebug>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
InteractiveConsole::ConsoleMode mode = InteractiveConsole::PlasmaConsole;
QCommandLineParser parser;
QCommandLineOption plasmaOpt(QStringLiteral("plasma"));
QCommandLineOption kwinOpt(QStringLiteral("kwin"));
parser.addOption(plasmaOpt);
parser.addOption(kwinOpt);
parser.addHelpOption();
parser.process(app);
if (parser.isSet(kwinOpt)) {
mode = InteractiveConsole::KWinConsole;
} else if (parser.isSet(plasmaOpt)) {
mode = InteractiveConsole::PlasmaConsole;
} else if (parser.isSet(plasmaOpt) && parser.isSet(kwinOpt)) {
qWarning() << "Only one mode can be specified when launching the interactive console";
exit(1);
}
// set to delete on close
auto console = new InteractiveConsole;
auto console = new InteractiveConsole(mode);
console->show();
app.exec();
}
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