| 86 | ExternalScriptPlugin* ExternalScriptPlugin::m_self = nullptr; |
| 87 | |
| 88 | ExternalScriptPlugin::ExternalScriptPlugin(QObject* parent, const KPluginMetaData& metaData, |
| 89 | const QVariantList& /*args*/) |
| 90 | : IPlugin(QStringLiteral("kdevexternalscript"), parent, metaData) |
| 91 | , m_model(new QStandardItemModel(this)) |
| 92 | , m_factory(new ExternalScriptViewFactory(this)) |
| 93 | { |
| 94 | Q_ASSERT(!m_self); |
| 95 | m_self = this; |
| 96 | |
| 97 | QDBusConnection::sessionBus().registerObject(QStringLiteral( |
| 98 | "/org/kdevelop/ExternalScriptPlugin"), this, |
| 99 | QDBusConnection::ExportScriptableSlots); |
| 100 | |
| 101 | setXMLFile(QStringLiteral("kdevexternalscript.rc")); |
| 102 | |
| 103 | //BEGIN load config |
| 104 | KConfigGroup config = getConfig(); |
| 105 | const auto groups = config.groupList(); |
| 106 | for (const QString& group : groups) { |
| 107 | KConfigGroup script = config.group(group); |
| 108 | if (script.hasKey("name") && script.hasKey("command")) { |
| 109 | auto* item = new ExternalScriptItem; |
| 110 | item->setKey(script.name()); |
| 111 | item->setText(script.readEntry("name")); |
| 112 | item->setCommand(script.readEntry("command")); |
| 113 | item->setInputMode(static_cast<ExternalScriptItem::InputMode>(script.readEntry("inputMode", 0u))); |
| 114 | item->setOutputMode(static_cast<ExternalScriptItem::OutputMode>(script.readEntry("outputMode", 0u))); |
| 115 | item->setErrorMode(static_cast<ExternalScriptItem::ErrorMode>(script.readEntry("errorMode", 0u))); |
| 116 | item->setSaveMode(static_cast<ExternalScriptItem::SaveMode>(script.readEntry("saveMode", 0u))); |
| 117 | item->setFilterMode(script.readEntry("filterMode", 0u)); |
| 118 | item->action()->setShortcut(QKeySequence(script.readEntry("shortcuts"))); |
| 119 | item->setShowOutput(script.readEntry("showOutput", true)); |
| 120 | m_model->appendRow(item); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | //END load config |
| 125 | |
| 126 | core()->uiController()->addToolView(i18n("External Scripts"), m_factory); |
| 127 | |
| 128 | connect(m_model, &QStandardItemModel::rowsAboutToBeRemoved, |
| 129 | this, &ExternalScriptPlugin::rowsAboutToBeRemoved); |
| 130 | connect(m_model, &QStandardItemModel::rowsInserted, |
| 131 | this, &ExternalScriptPlugin::rowsInserted); |
| 132 | |
| 133 | const bool firstUse = config.readEntry("firstUse", true); |
| 134 | if (firstUse) { |
| 135 | // some example scripts |
| 136 | auto* item = new ExternalScriptItem; |
| 137 | item->setText(i18n("Quick Compile")); |
| 138 | item->setCommand(QStringLiteral("g++ -o %b %f && ./%b")); |
| 139 | m_model->appendRow(item); |
| 140 | |
| 141 | #ifndef Q_OS_WIN |
| 142 | item = new ExternalScriptItem; |
| 143 | item->setText(i18n("Sort Selection")); |
| 144 | item->setCommand(QStringLiteral("sort")); |
| 145 | item->setInputMode(ExternalScriptItem::InputSelectionOrDocument); |
nothing calls this directly
no test coverage detected