diff --git a/addons/externaltools/externaltools b/addons/externaltools/externaltools index e44e8bdbc..953eb8afd 100644 --- a/addons/externaltools/externaltools +++ b/addons/externaltools/externaltools @@ -1,163 +1,163 @@ [Global] tools=10 version=1 [Tool 0] actionName=externaltool_RunShellScript arguments=-e sh -c "cd %{directory} && pwd && chmod -vc a+x %{filename} && ./%{filename} ; echo Press any key to continue. && read -n 1" category= cmdname=run-script executable=konsole icon=system-run includeStderr=false input= mimetypes= name=Run Shell Script -output=0 +output=Ignore reload=false -save=1 +save=CurrentDocument workingDir=%{directory} [Tool 1] actionName=externaltool_GoogleSelectedText arguments="https://www.google.com/search?q=%{selection}" category= cmdname=google executable=xdg-open icon=globe includeStderr=false input= mimetypes= name=Google Selected Text -output=0 +output=Ignore reload=false -save=0 +save=None workingDir= [Tool 2] actionName=externaltool_gitcola arguments=-r %{directory} category=Git cmdname=git-cola executable=git-cola icon=git-cola includeStderr=false input= mimetypes= name=git-cola -output=0 +output=Ignore reload=false -save=0 +save=None workingDir= [Tool 3] actionName=externaltool_gitk arguments= category=Git cmdname=gitk executable=gitk icon=git-gui includeStderr=false input= mimetypes= name=gitk -output=0 +output=Ignore reload=false -save=0 +save=None workingDir=%{directory} [Tool 4] actionName=externaltool_gitblame arguments=gui blame %{filename} category=Git cmdname=git-blame executable=git icon= includeStderr=false input= mimetypes= name=git blame -output=0 +output=Ignore reload=false -save=1 +save=CurrentDocument workingDir=%{directory} [Tool 5] actionName=externaltool_QtQuick2Previewqmlscene arguments=%filename category=Tools cmdname=qml-preview executable=qmlscene icon= includeStderr=false input= mimetypes=text/x-qml name=Qt Quick 2 Preview (qmlscene) -output=0 +output=Ignore reload=false -save=1 +save=CurrentDocument workingDir=%{directory} [Tool 6] actionName=externaltool_InsertUUID arguments= category=Tools cmdname=uuid executable=uuidgen icon= includeStderr=false input= mimetypes= name=Insert UUID -output=1 +output=InsertAtCursor reload=false -save=0 +save=None workingDir= [Tool 7] actionName=externaltool_ClangFormatFullFile arguments=-i %{filename} category=Tools cmdname=clang-format-file executable=clang-format icon= includeStderr=false input= mimetypes= name=Clang Format Full File -output=0 +output=Ignore reload=true -save=1 +save=CurrentDocument workingDir=%{directory} [Tool 8] actionName=externaltool_ClangFormatSelectedText arguments=-assume-filename=%{filename} category=Tools cmdname=clang-format-selection executable=clang-format icon= includeStderr=false input=\s%{selection} mimetypes= name=Clang Format Selected Text -output=2 +output=ReplaceSelectedText reload=false -save=0 +save=None workingDir=%{directory} [Tool 9] actionName=externaltool_perl arguments=asdfasdfasdf category=Tools cmdname=perl executable=ls icon= includeStderr=true input= mimetypes= name=perl -output=1 +output=InsertAtCursor reload=false -save=0 +save=None workingDir= diff --git a/addons/externaltools/kateexternaltool.cpp b/addons/externaltools/kateexternaltool.cpp index 702622306..24f25286e 100644 --- a/addons/externaltools/kateexternaltool.cpp +++ b/addons/externaltools/kateexternaltool.cpp @@ -1,91 +1,139 @@ /* This file is part of the KDE project * * Copyright 2019 Dominik Haumann * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kateexternaltool.h" #include #include +namespace { + QString toString(KateExternalTool::SaveMode saveMode) + { + switch (saveMode) { + case KateExternalTool::SaveMode::None: return QStringLiteral("None"); + case KateExternalTool::SaveMode::CurrentDocument: return QStringLiteral("CurrentDocument"); + case KateExternalTool::SaveMode::AllDocuments: return QStringLiteral("AllDocuments"); + } + Q_ASSERT(false); // yout forgot a case above + return QStringLiteral("None"); + } + + KateExternalTool::SaveMode toSaveMode(const QString & mode) + { + if (mode == QStringLiteral("None")) return KateExternalTool::SaveMode::None; + if (mode == QStringLiteral("CurrentDocument")) return KateExternalTool::SaveMode::CurrentDocument; + if (mode == QStringLiteral("AllDocuments")) return KateExternalTool::SaveMode::AllDocuments; + return KateExternalTool::SaveMode::None; + } + + QString toString(KateExternalTool::OutputMode outputMode) + { + switch (outputMode) { + case KateExternalTool::OutputMode::Ignore: return QStringLiteral("Ignore"); + case KateExternalTool::OutputMode::InsertAtCursor: return QStringLiteral("InsertAtCursor"); + case KateExternalTool::OutputMode::ReplaceSelectedText: return QStringLiteral("ReplaceSelectedText"); + case KateExternalTool::OutputMode::ReplaceCurrentDocument: return QStringLiteral("ReplaceCurrentDocument"); + case KateExternalTool::OutputMode::AppendToCurrentDocument: return QStringLiteral("AppendToCurrentDocument"); + case KateExternalTool::OutputMode::InsertInNewDocument: return QStringLiteral("InsertInNewDocument"); + case KateExternalTool::OutputMode::DisplayInPane: return QStringLiteral("DisplayInPane"); + } + Q_ASSERT(false); // yout forgot a case above + return QStringLiteral("Ignore"); + } + + KateExternalTool::OutputMode toOutputMode(const QString & mode) + { + if (mode == QStringLiteral("Ignore")) return KateExternalTool::OutputMode::Ignore; + if (mode == QStringLiteral("InsertAtCursor")) return KateExternalTool::OutputMode::InsertAtCursor; + if (mode == QStringLiteral("ReplaceSelectedText")) return KateExternalTool::OutputMode::ReplaceSelectedText; + if (mode == QStringLiteral("ReplaceCurrentDocument")) return KateExternalTool::OutputMode::ReplaceCurrentDocument; + if (mode == QStringLiteral("AppendToCurrentDocument")) return KateExternalTool::OutputMode::AppendToCurrentDocument; + if (mode == QStringLiteral("InsertInNewDocument")) return KateExternalTool::OutputMode::InsertInNewDocument; + if (mode == QStringLiteral("DisplayInPane")) return KateExternalTool::OutputMode::DisplayInPane; + return KateExternalTool::OutputMode::Ignore; + } +} + bool KateExternalTool::checkExec() const { return !QStandardPaths::findExecutable(executable).isEmpty(); } bool KateExternalTool::matchesMimetype(const QString& mt) const { return mimetypes.isEmpty() || mimetypes.contains(mt); } void KateExternalTool::load(const KConfigGroup& cg) { category = cg.readEntry("category", ""); name = cg.readEntry("name", ""); icon = cg.readEntry("icon", ""); executable = cg.readEntry("executable", ""); arguments = cg.readEntry("arguments", ""); input = cg.readEntry("input", ""); workingDir = cg.readEntry("workingDir", ""); mimetypes = cg.readEntry("mimetypes", QStringList()); actionName = cg.readEntry("actionName"); cmdname = cg.readEntry("cmdname"); - saveMode = static_cast(cg.readEntry("save", 0)); + saveMode = toSaveMode(cg.readEntry("save", "None")); reload = cg.readEntry("reload", false); - outputMode = static_cast(cg.readEntry("output", 0)); + outputMode = toOutputMode(cg.readEntry("output", "Ignore")); includeStderr = cg.readEntry("includeStderr", false); hasexec = checkExec(); } void KateExternalTool::save(KConfigGroup& cg) const { cg.writeEntry("category", category); cg.writeEntry("name", name); cg.writeEntry("icon", icon); cg.writeEntry("executable", executable); cg.writeEntry("arguments", arguments); cg.writeEntry("input", input); cg.writeEntry("workingDir", workingDir); cg.writeEntry("mimetypes", mimetypes); cg.writeEntry("actionName", actionName); cg.writeEntry("cmdname", cmdname); - cg.writeEntry("save", static_cast(saveMode)); + cg.writeEntry("save", toString(saveMode)); cg.writeEntry("reload", reload); - cg.writeEntry("output", static_cast(outputMode)); + cg.writeEntry("output", toString(outputMode)); cg.writeEntry("includeStderr", includeStderr); } bool operator==(const KateExternalTool & lhs, const KateExternalTool & rhs) { return lhs.category == rhs.category && lhs.name == rhs.name && lhs.icon == rhs.icon && lhs.executable == rhs.executable && lhs.arguments == rhs.arguments && lhs.input == rhs.input && lhs.workingDir == rhs.workingDir && lhs.mimetypes == rhs.mimetypes && lhs.actionName == rhs.actionName && lhs.cmdname == rhs.cmdname && lhs.saveMode == rhs.saveMode && lhs.reload == rhs.reload && lhs.outputMode == rhs.outputMode && lhs.includeStderr == rhs.includeStderr; } // kate: space-indent on; indent-width 4; replace-tabs on;