1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
/*
This plugin is part of KDevelop.
Copyright (C) 2010 Milian Wolff <mail@milianw.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef KDEVPLATFORM_PLUGIN_EXTERNALSCRIPTITEM_H
#define KDEVPLATFORM_PLUGIN_EXTERNALSCRIPTITEM_H
#include <QStandardItem>
class QAction;
/**
* NOTE: use @c text() and @c setText() to define the label/name of the external script.
*/
class ExternalScriptItem
: public QStandardItem
{
public:
ExternalScriptItem();
/**
* The key is supposed to be unique inside the model
* @return The key of this script item
*/
QString key() const;
/**
* Sets the label
*/
void setKey(const QString& key);
/**
* @return The command to execute.
*/
QString command() const;
/**
* Sets the command to execute.
*/
void setCommand(const QString& command);
/**
* @return The working directory where to execute the command.
* If this is empty (default), it should be derived from the active document.
*/
QString workingDirectory() const;
/**
* Specify the working directory where the command should be executed
*/
void setWorkingDirectory(const QString& workingDirectory);
/**
* Whether placeholders like %b etc. in the command should be substituted. Default is true.
* */
bool performParameterReplacement() const;
/**
* Set whether placeholders like %b etc. in the command should be substituted. Default is true.
* */
void setPerformParameterReplacement(bool perform);
enum SaveMode {
/// Nothing needs to be saved.
SaveNone,
/// Currently active document gets saved.
SaveCurrentDocument,
/// All opened documents get saved.
SaveAllDocuments
};
/**
* @return @c SaveMode that decides what document should be saved before executing this script.
*/
SaveMode saveMode() const;
/**
* Sets the @c SaveMode that decides what document should be saved before executing this script.
*/
void setSaveMode(SaveMode mode);
/**
* @return what type of filter should be applied to the execution of the external script
**/
int filterMode() const;
/**
* Sets the filtering mode
**/
void setFilterMode(int mode);
/// Defines what should be done with the @c STDOUT of a script run.
enum OutputMode {
/// Ignore output and do nothing.
OutputNone,
/// Output gets inserted at the cursor position of the current document.
OutputInsertAtCursor,
/// Current selection gets replaced in the active document.
/// If no selection exists, the output will get inserted at the
/// current cursor position in the active document view.
OutputReplaceSelectionOrInsertAtCursor,
/// Current selection gets replaced in the active document.
/// If no selection exists, the whole document gets replaced.
OutputReplaceSelectionOrDocument,
/// The whole contents of the active document gets replaced.
OutputReplaceDocument,
/// Create a new file from the output.
OutputCreateNewFile
};
/**
* @return @c OutputMode that decides what parts of the active document should be replaced by the
* @c STDOUT of the @c command() execution.
*/
OutputMode outputMode() const;
/**
* Sets the @c OutputMode that decides what parts of the active document should be replaced by the
* @c STDOUT of the @c command() execution.
*/
void setOutputMode(OutputMode mode);
/// Defines what should be done with the @c STDERR of a script run.
enum ErrorMode {
/// Ignore errors and do nothing.
ErrorNone,
/// Merge with @c STDOUT and use @c OutputMode.
ErrorMergeOutput,
/// Errors get inserted at the cursor position of the current document.
ErrorInsertAtCursor,
/// Current selection gets replaced in the active document.
/// If no selection exists, the output will get inserted at the
/// current cursor position in the active document view.
ErrorReplaceSelectionOrInsertAtCursor,
/// Current selection gets replaced in the active document.
/// If no selection exists, the whole document gets replaced.
ErrorReplaceSelectionOrDocument,
/// The whole contents of the active document gets replaced.
ErrorReplaceDocument,
/// Create a new file from the errors.
ErrorCreateNewFile
};
/**
* @return @c ErrorMode that decides what parts of the active document should be replaced by the
* @c STDERR of the @c command() execution.
*/
ErrorMode errorMode() const;
/**
* Sets the @c ErrorMode that decides what parts of the active document should be replaced by the
* @c STDERR of the @c command() execution.
*/
void setErrorMode(ErrorMode mode);
enum InputMode {
/// Nothing gets streamed to the @c STDIN of the external script.
InputNone,
/// Current selection gets streamed into the @c STDIN of the external script.
/// If no selection exists, nothing gets streamed.
InputSelectionOrNone,
/// Current selection gets streamed into the @c STDIN of the external script.
/// If no selection exists, the whole document gets streamed.
InputSelectionOrDocument,
/// The whole contents of the active document get streamed into the @c STDIN of the external script.
InputDocument,
};
/**
* @return @c InputMode that decides what parts of the active document should be streamded into
* the @c STDIN of the external script.
*/
InputMode inputMode() const;
/**
* Sets the @c InputMode that decides what parts of the active document should be streamded into
* the @c STDIN of the external script.
*/
void setInputMode(InputMode mode);
/**
* Action to trigger insertion of this snippet.
*/
QAction* action();
/**
* @return True when this command should have its output shown, false otherwise.
*/
bool showOutput() const;
/**
* Set @p show to true when the output of this command shout be shown, false otherwise.
*/
void setShowOutput(bool show);
///TODO: custom icon
///TODO: mimetype / language filter
///TODO: kate commandline integration
///TODO: filter for local/remote files
/**
* Saves this item after changes.
*/
void save() const;
private:
QString m_key;
QString m_command;
QString m_workingDirectory;
SaveMode m_saveMode = SaveNone;
OutputMode m_outputMode = OutputNone;
ErrorMode m_errorMode = ErrorNone;
InputMode m_inputMode = InputNone;
QAction* m_action = nullptr;
bool m_showOutput = true;
int m_filterMode = 0;
bool m_performReplacements = true;
};
Q_DECLARE_METATYPE(ExternalScriptItem*)
#endif // KDEVPLATFORM_PLUGIN_EXTERNALSCRIPTITEM_H
|