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 #ifndef KDEVPLATFORM_PLUGIN_EXTERNALSCRIPTITEM_H 0008 #define KDEVPLATFORM_PLUGIN_EXTERNALSCRIPTITEM_H 0009 0010 #include <QStandardItem> 0011 0012 class QAction; 0013 0014 /** 0015 * NOTE: use @c text() and @c setText() to define the label/name of the external script. 0016 */ 0017 class ExternalScriptItem 0018 : public QStandardItem 0019 { 0020 public: 0021 ExternalScriptItem(); 0022 0023 /** 0024 * The key is supposed to be unique inside the model 0025 * @return The key of this script item 0026 */ 0027 QString key() const; 0028 /** 0029 * Sets the label 0030 */ 0031 void setKey(const QString& key); 0032 0033 /** 0034 * @return The command to execute. 0035 */ 0036 QString command() const; 0037 /** 0038 * Sets the command to execute. 0039 */ 0040 void setCommand(const QString& command); 0041 0042 /** 0043 * @return The working directory where to execute the command. 0044 * If this is empty (default), it should be derived from the active document. 0045 */ 0046 QString workingDirectory() const; 0047 0048 /** 0049 * Specify the working directory where the command should be executed 0050 */ 0051 void setWorkingDirectory(const QString& workingDirectory); 0052 0053 /** 0054 * Whether placeholders like %b etc. in the command should be substituted. Default is true. 0055 * */ 0056 bool performParameterReplacement() const; 0057 0058 /** 0059 * Set whether placeholders like %b etc. in the command should be substituted. Default is true. 0060 * */ 0061 void setPerformParameterReplacement(bool perform); 0062 0063 enum SaveMode { 0064 /// Nothing needs to be saved. 0065 SaveNone, 0066 /// Currently active document gets saved. 0067 SaveCurrentDocument, 0068 /// All opened documents get saved. 0069 SaveAllDocuments 0070 }; 0071 /** 0072 * @return @c SaveMode that decides what document should be saved before executing this script. 0073 */ 0074 SaveMode saveMode() const; 0075 /** 0076 * Sets the @c SaveMode that decides what document should be saved before executing this script. 0077 */ 0078 void setSaveMode(SaveMode mode); 0079 0080 /** 0081 * @return what type of filter should be applied to the execution of the external script 0082 **/ 0083 int filterMode() const; 0084 0085 /** 0086 * Sets the filtering mode 0087 **/ 0088 void setFilterMode(int mode); 0089 0090 /// Defines what should be done with the @c STDOUT of a script run. 0091 enum OutputMode { 0092 /// Ignore output and do nothing. 0093 OutputNone, 0094 /// Output gets inserted at the cursor position of the current document. 0095 OutputInsertAtCursor, 0096 /// Current selection gets replaced in the active document. 0097 /// If no selection exists, the output will get inserted at the 0098 /// current cursor position in the active document view. 0099 OutputReplaceSelectionOrInsertAtCursor, 0100 /// Current selection gets replaced in the active document. 0101 /// If no selection exists, the whole document gets replaced. 0102 OutputReplaceSelectionOrDocument, 0103 /// The whole contents of the active document gets replaced. 0104 OutputReplaceDocument, 0105 /// Create a new file from the output. 0106 OutputCreateNewFile 0107 }; 0108 /** 0109 * @return @c OutputMode that decides what parts of the active document should be replaced by the 0110 * @c STDOUT of the @c command() execution. 0111 */ 0112 OutputMode outputMode() const; 0113 /** 0114 * Sets the @c OutputMode that decides what parts of the active document should be replaced by the 0115 * @c STDOUT of the @c command() execution. 0116 */ 0117 void setOutputMode(OutputMode mode); 0118 0119 /// Defines what should be done with the @c STDERR of a script run. 0120 enum ErrorMode { 0121 /// Ignore errors and do nothing. 0122 ErrorNone, 0123 /// Merge with @c STDOUT and use @c OutputMode. 0124 ErrorMergeOutput, 0125 /// Errors get inserted at the cursor position of the current document. 0126 ErrorInsertAtCursor, 0127 /// Current selection gets replaced in the active document. 0128 /// If no selection exists, the output will get inserted at the 0129 /// current cursor position in the active document view. 0130 ErrorReplaceSelectionOrInsertAtCursor, 0131 /// Current selection gets replaced in the active document. 0132 /// If no selection exists, the whole document gets replaced. 0133 ErrorReplaceSelectionOrDocument, 0134 /// The whole contents of the active document gets replaced. 0135 ErrorReplaceDocument, 0136 /// Create a new file from the errors. 0137 ErrorCreateNewFile 0138 }; 0139 0140 /** 0141 * @return @c ErrorMode that decides what parts of the active document should be replaced by the 0142 * @c STDERR of the @c command() execution. 0143 */ 0144 ErrorMode errorMode() const; 0145 /** 0146 * Sets the @c ErrorMode that decides what parts of the active document should be replaced by the 0147 * @c STDERR of the @c command() execution. 0148 */ 0149 void setErrorMode(ErrorMode mode); 0150 0151 enum InputMode { 0152 /// Nothing gets streamed to the @c STDIN of the external script. 0153 InputNone, 0154 /// Current selection gets streamed into the @c STDIN of the external script. 0155 /// If no selection exists, nothing gets streamed. 0156 InputSelectionOrNone, 0157 /// Current selection gets streamed into the @c STDIN of the external script. 0158 /// If no selection exists, the whole document gets streamed. 0159 InputSelectionOrDocument, 0160 /// The whole contents of the active document get streamed into the @c STDIN of the external script. 0161 InputDocument, 0162 }; 0163 /** 0164 * @return @c InputMode that decides what parts of the active document should be streamded into 0165 * the @c STDIN of the external script. 0166 */ 0167 InputMode inputMode() const; 0168 /** 0169 * Sets the @c InputMode that decides what parts of the active document should be streamded into 0170 * the @c STDIN of the external script. 0171 */ 0172 void setInputMode(InputMode mode); 0173 0174 /** 0175 * Action to trigger insertion of this snippet. 0176 */ 0177 QAction* action(); 0178 0179 /** 0180 * @return True when this command should have its output shown, false otherwise. 0181 */ 0182 bool showOutput() const; 0183 /** 0184 * Set @p show to true when the output of this command shout be shown, false otherwise. 0185 */ 0186 void setShowOutput(bool show); 0187 0188 ///TODO: custom icon 0189 ///TODO: mimetype / language filter 0190 ///TODO: kate commandline integration 0191 ///TODO: filter for local/remote files 0192 0193 /** 0194 * Saves this item after changes. 0195 */ 0196 void save() const; 0197 0198 private: 0199 QString m_key; 0200 QString m_command; 0201 QString m_workingDirectory; 0202 SaveMode m_saveMode = SaveNone; 0203 OutputMode m_outputMode = OutputNone; 0204 ErrorMode m_errorMode = ErrorNone; 0205 InputMode m_inputMode = InputNone; 0206 QAction* m_action = nullptr; 0207 bool m_showOutput = true; 0208 int m_filterMode = 0; 0209 bool m_performReplacements = true; 0210 }; 0211 0212 Q_DECLARE_METATYPE(ExternalScriptItem*) 0213 0214 #endif // KDEVPLATFORM_PLUGIN_EXTERNALSCRIPTITEM_H