~ubuntu-branches/ubuntu/quantal/kdevplatform/quantal-proposed

« back to all changes in this revision

Viewing changes to plugins/externalscript/externalscriptitem.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-24 00:06:18 UTC
  • mfrom: (0.3.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20101024000618-7otebin77mfcmt3b
Tags: 1.1.0-0ubuntu1
* New upstream release
  - Bump build-dependencies
  - Build against libboost-serialization1.42-dev
  - Update kdevplatform1-libs.install
  - Update kdevplatform-dev.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This plugin is part of KDevelop.
 
3
 
 
4
    Copyright (C) 2010 Milian Wolff <mail@milianw.de>
 
5
 
 
6
    This library is free software; you can redistribute it and/or
 
7
    modify it under the terms of the GNU Lesser General Public
 
8
    License as published by the Free Software Foundation; either
 
9
    version 2.1 of the License, or (at your option) any later version.
 
10
 
 
11
    This library is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
    Lesser General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU Lesser General Public
 
17
    License along with this library; if not, write to the Free Software
 
18
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
19
*/
 
20
 
 
21
#ifndef EXTERNALSCRIPTITEM_H
 
22
#define EXTERNALSCRIPTITEM_H
 
23
 
 
24
#include <QStandardItemModel>
 
25
 
 
26
class KAction;
 
27
 
 
28
/**
 
29
 * NOTE: use @c text() and @c setText() to define the label/name of the external script.
 
30
 */
 
31
class ExternalScriptItem : public QStandardItem
 
32
{
 
33
public:
 
34
  ExternalScriptItem();
 
35
 
 
36
  /**
 
37
   * @return The command to execute. Working dir will be that of the active document.
 
38
   */
 
39
  QString command() const;
 
40
  /**
 
41
   * Sets the command to execute. Working dir will be that of the active document.
 
42
   */
 
43
  void setCommand( const QString& command );
 
44
 
 
45
  enum SaveMode {
 
46
    /// Nothing needs to be saved.
 
47
    SaveNone,
 
48
    /// Currently active document gets saved.
 
49
    SaveCurrentDocument,
 
50
    /// All opened documents get saved.
 
51
    SaveAllDocuments
 
52
  };
 
53
  /**
 
54
   * @return @c SaveMode that decides what document should be saved before executing this script.
 
55
   */
 
56
  SaveMode saveMode() const;
 
57
  /**
 
58
   * Sets the @c SaveMode that decides what document should be saved before executing this script.
 
59
   */
 
60
  void setSaveMode( SaveMode mode );
 
61
 
 
62
  /// Defines what should be done with the @c STDOUT of a script run.
 
63
  enum OutputMode {
 
64
    /// Ignore output and do nothing.
 
65
    OutputNone,
 
66
    /// Output gets inserted at the cursor position of the current document.
 
67
    OutputInsertAtCursor,
 
68
    /// Current selection gets replaced in the active document.
 
69
    /// If no selection exists, the output will get inserted at the
 
70
    /// current cursor position in the active document view.
 
71
    OutputReplaceSelectionOrInsertAtCursor,
 
72
    /// Current selection gets replaced in the active document.
 
73
    /// If no selection exists, the whole document gets replaced.
 
74
    OutputReplaceSelectionOrDocument,
 
75
    /// The whole contents of the active document gets replaced.
 
76
    OutputReplaceDocument,
 
77
    /// Create a new file from the output.
 
78
    OutputCreateNewFile
 
79
  };
 
80
  /**
 
81
   * @return @c OutputMode that decides what parts of the active document should be replaced by the
 
82
   *         @c STDOUT of the @c command() execution.
 
83
   */
 
84
  OutputMode outputMode() const;
 
85
  /**
 
86
   * Sets the @c OutputMode that decides what parts of the active document should be replaced by the
 
87
   * @c STDOUT of the @c command() execution.
 
88
   */
 
89
  void setOutputMode( OutputMode mode );
 
90
 
 
91
  /// Defines what should be done with the @c STDERR of a script run.
 
92
  enum ErrorMode {
 
93
    /// Ignore errors and do nothing.
 
94
    ErrorNone,
 
95
    /// Merge with @c STDOUT and use @c OutputMode.
 
96
    ErrorMergeOutput,
 
97
    /// Errors get inserted at the cursor position of the current document.
 
98
    ErrorInsertAtCursor,
 
99
    /// Current selection gets replaced in the active document.
 
100
    /// If no selection exists, the output will get inserted at the
 
101
    /// current cursor position in the active document view.
 
102
    ErrorReplaceSelectionOrInsertAtCursor,
 
103
    /// Current selection gets replaced in the active document.
 
104
    /// If no selection exists, the whole document gets replaced.
 
105
    ErrorReplaceSelectionOrDocument,
 
106
    /// The whole contents of the active document gets replaced.
 
107
    ErrorReplaceDocument,
 
108
    /// Create a new file from the errors.
 
109
    ErrorCreateNewFile
 
110
  };
 
111
 
 
112
  /**
 
113
   * @return @c ErrorMode that decides what parts of the active document should be replaced by the
 
114
   *         @c STDERR of the @c command() execution.
 
115
   */
 
116
  ErrorMode errorMode() const;
 
117
  /**
 
118
   * Sets the @c ErrorMode that decides what parts of the active document should be replaced by the
 
119
   * @c STDERR of the @c command() execution.
 
120
   */
 
121
  void setErrorMode( ErrorMode mode );
 
122
 
 
123
  enum InputMode {
 
124
    /// Nothing gets streamed to the @c STDIN of the external script.
 
125
    InputNone,
 
126
    /// Current selection gets streamed into the @c STDIN of the external script.
 
127
    /// If no selection exists, nothing gets streamed.
 
128
    InputSelectionOrNone,
 
129
    /// Current selection gets streamed into the @c STDIN of the external script.
 
130
    /// If no selection exists, the whole document gets streamed.
 
131
    InputSelectionOrDocument,
 
132
    /// The whole contents of the active document get streamed into the @c STDIN of the external script.
 
133
    InputDocument,
 
134
  };
 
135
  /**
 
136
   * @return @c InputMode that decides what parts of the active document should be streamded into
 
137
   *         the @c STDIN of the external script.
 
138
   */
 
139
  InputMode inputMode() const;
 
140
  /**
 
141
   * Sets the @c InputMode that decides what parts of the active document should be streamded into
 
142
   * the @c STDIN of the external script.
 
143
   */
 
144
  void setInputMode( InputMode mode );
 
145
 
 
146
  /**
 
147
   * Action to trigger insertion of this snippet.
 
148
   */
 
149
  KAction* action();
 
150
 
 
151
  /**
 
152
   * @return True when this command should have its output shown, false otherwise.
 
153
   */
 
154
  bool showOutput() const;
 
155
  /**
 
156
   * Set @p show to true when the output of this command shout be shown, false otherwise.
 
157
   */
 
158
  void setShowOutput( bool show );
 
159
 
 
160
  ///TODO: custom icon
 
161
  ///TODO: mimetype / language filter
 
162
  ///TODO: kate commandline integration
 
163
  ///TODO: filter for local/remote files
 
164
 
 
165
  /**
 
166
   * Saves this item after changes.
 
167
   */
 
168
  void save() const;
 
169
private:
 
170
  QString m_command;
 
171
  SaveMode m_saveMode;
 
172
  OutputMode m_outputMode;
 
173
  ErrorMode m_errorMode;
 
174
  InputMode m_inputMode;
 
175
  KAction* m_action;
 
176
  bool m_showOutput;
 
177
};
 
178
 
 
179
Q_DECLARE_METATYPE(ExternalScriptItem*)
 
180
 
 
181
#endif // EXTERNALSCRIPTITEM_H
 
182
 
 
183
// kate: indent-mode cstyle; space-indent on; indent-width 2; replace-tabs on;