File indexing completed on 2024-04-28 04:38:40
0001 /* 0002 SPDX-FileCopyrightText: 2010 Milian Wolff <mail@milianw.de> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include "externalscriptitem.h" 0008 0009 #include "externalscriptplugin.h" 0010 0011 #include <QAction> 0012 0013 #include <KParts/MainWindow> 0014 #include <KLocalizedString> 0015 0016 #include <interfaces/icore.h> 0017 #include <interfaces/iuicontroller.h> 0018 0019 ExternalScriptItem::ExternalScriptItem() 0020 { 0021 } 0022 0023 QString ExternalScriptItem::key() const 0024 { 0025 return m_key; 0026 } 0027 0028 void ExternalScriptItem::setKey(const QString& key) 0029 { 0030 m_key = key; 0031 } 0032 0033 QString ExternalScriptItem::command() const 0034 { 0035 return m_command; 0036 } 0037 0038 void ExternalScriptItem::setCommand(const QString& command) 0039 { 0040 m_command = command; 0041 } 0042 0043 void ExternalScriptItem::setWorkingDirectory(const QString& workingDirectory) 0044 { 0045 m_workingDirectory = workingDirectory; 0046 } 0047 0048 QString ExternalScriptItem::workingDirectory() const 0049 { 0050 return m_workingDirectory; 0051 } 0052 0053 ExternalScriptItem::SaveMode ExternalScriptItem::saveMode() const 0054 { 0055 return m_saveMode; 0056 } 0057 0058 void ExternalScriptItem::setSaveMode(ExternalScriptItem::SaveMode mode) 0059 { 0060 m_saveMode = mode; 0061 } 0062 0063 ExternalScriptItem::OutputMode ExternalScriptItem::outputMode() const 0064 { 0065 return m_outputMode; 0066 } 0067 0068 void ExternalScriptItem::setOutputMode(ExternalScriptItem::OutputMode mode) 0069 { 0070 m_outputMode = mode; 0071 } 0072 0073 ExternalScriptItem::ErrorMode ExternalScriptItem::errorMode() const 0074 { 0075 return m_errorMode; 0076 } 0077 0078 void ExternalScriptItem::setErrorMode(ExternalScriptItem::ErrorMode mode) 0079 { 0080 m_errorMode = mode; 0081 } 0082 0083 ExternalScriptItem::InputMode ExternalScriptItem::inputMode() const 0084 { 0085 return m_inputMode; 0086 } 0087 0088 void ExternalScriptItem::setInputMode(ExternalScriptItem::InputMode mode) 0089 { 0090 m_inputMode = mode; 0091 } 0092 0093 int ExternalScriptItem::filterMode() const 0094 { 0095 return m_filterMode; 0096 } 0097 0098 void ExternalScriptItem::setFilterMode(int mode) 0099 { 0100 m_filterMode = mode; 0101 } 0102 0103 QAction* ExternalScriptItem::action() 0104 { 0105 ///TODO: this is quite ugly, or is it? if someone knows how to do it better, please refactor 0106 if (!m_action) { 0107 static int actionCount = 0; 0108 m_action = new QAction(QStringLiteral("executeScript%1").arg(actionCount), ExternalScriptPlugin::self()); 0109 m_action->setData(QVariant::fromValue<ExternalScriptItem*>(this)); 0110 ExternalScriptPlugin::self()->connect( 0111 m_action, &QAction::triggered, 0112 ExternalScriptPlugin::self(), &ExternalScriptPlugin::executeScriptFromActionData 0113 ); 0114 m_action->setShortcut(QKeySequence()); 0115 // action needs to be added to a widget before it can work... 0116 KDevelop::ICore::self()->uiController()->activeMainWindow()->addAction(m_action); 0117 } 0118 0119 Q_ASSERT(m_action); 0120 return m_action; 0121 } 0122 0123 bool ExternalScriptItem::showOutput() const 0124 { 0125 return m_showOutput; 0126 } 0127 0128 void ExternalScriptItem::setShowOutput(bool show) 0129 { 0130 m_showOutput = show; 0131 } 0132 0133 bool ExternalScriptItem::performParameterReplacement() const 0134 { 0135 return m_performReplacements; 0136 } 0137 0138 void ExternalScriptItem::setPerformParameterReplacement(bool perform) 0139 { 0140 m_performReplacements = perform; 0141 } 0142 0143 void ExternalScriptItem::save() const 0144 { 0145 ExternalScriptPlugin::self()->saveItem(this); 0146 }