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
229
|
/*
This file is part of the Kate text editor of the KDE project.
It describes a "external tools" action for kate and provides a dialog
page to configure that.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
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.
---
Copyright (C) 2004, Anders Lund <anders@alweb.dk>
*/
#ifndef _KATE_EXTERNAL_TOOLS_H_
#define _KATE_EXTERNAL_TOOLS_H_
#include <kaction.h>
#include <kdialogbase.h>
#include <kate/document.h>
#include <kmacroexpander.h>
#include <tqpixmap.h>
/**
* The external tools action
* This action creates a menu, in which each item will launch a process
* with the provided arguments, which may include the following macros:
* - %URLS: the URLs of all open documents.
* - %URL: The URL of the active document.
* - %filedir: The directory of the current document, if that is a local file.
* - %selection: The selection of the active document.
* - %text: The text of the active document.
* - %line: The line number of the cursor in the active view.
* - %column: The column of the cursor in the active view.
*
* Each item has the following properties:
* - Name: The friendly text for the menu
* - Exec: The command to execute, including arguments.
* - TryExec: the name of the executable, if not available, the
* item will not be displayed.
* - MimeTypes: An optional list of mimetypes. The item will be disabled or
* hidden if the current file is not of one of the indicated types.
*
*/
class KateExternalToolsMenuAction : public TDEActionMenu
{
friend class KateExternalToolAction;
Q_OBJECT
public:
KateExternalToolsMenuAction( const TQString &text=TQString::null, TQObject *parent=0, const char* name=0, class KateMainWindow *mw=0 );
~KateExternalToolsMenuAction() {};
/**
* This will load all the confiured services.
*/
void reload();
class TDEActionCollection *actionCollection() { return m_actionCollection; }
private slots:
void slotDocumentChanged();
private:
class TDEActionCollection *m_actionCollection;
class KateMainWindow *mainwindow; // for the actions to access view/doc managers
};
/**
* This Action contains a KateExternalTool
*/
class KateExternalToolAction : public TDEAction, public KWordMacroExpander
{
Q_OBJECT
public:
KateExternalToolAction( TQObject *parent, const char *name, class KateExternalTool *t );
~KateExternalToolAction();
protected:
virtual bool expandMacro( const TQString &str, TQStringList &ret );
private slots:
void slotRun();
public:
class KateExternalTool *tool;
};
/**
* This class defines a single external tool.
*/
class KateExternalTool
{
public:
KateExternalTool( const TQString &name=TQString::null,
const TQString &command=TQString::null,
const TQString &icon=TQString::null,
const TQString &tryexec=TQString::null,
const TQStringList &mimetypes=TQStringList(),
const TQString &acname=TQString::null,
const TQString &cmdname=TQString::null,
int save=0 );
~KateExternalTool() {};
TQString name; ///< The name used in the menu.
TQString command; ///< The command to execute.
TQString icon; ///< the icon to use in the menu.
TQString tryexec; ///< The name or path of the executable.
TQStringList mimetypes; ///< Optional list of mimetypes for which this action is valid.
bool hasexec; ///< This is set by the constructor by calling checkExec(), if a value is present.
TQString acname; ///< The name for the action. This is generated first time the action is is created.
TQString cmdname; ///< The name for the commandline.
int save; ///< We can save documents prior to activating the tool command: 0 = nothing, 1 = current document, 2 = all documents.
/**
* @return true if mimetypes is empty, or the @p mimetype matches.
*/
bool valid( const TQString &mimetype ) const;
/**
* @return true if "tryexec" exists and has the executable bit set, or is
* empty.
* This is run at least once, and the tool is disabled if it fails.
*/
bool checkExec();
private:
TQString m_exec; ///< The fully qualified path of the executable.
};
/**
* The config widget.
* The config widget allows the user to view a list of services of the type
* "Kate/ExternalTool" and add, remove or edit them.
*/
class KateExternalToolsConfigWidget : public Kate::ConfigPage
{
Q_OBJECT
public:
KateExternalToolsConfigWidget( TQWidget *parent, const char* name);
virtual ~KateExternalToolsConfigWidget();
virtual void apply();
virtual void reload();
virtual void reset() { reload(); } // sigh
virtual void defaults() { reload(); } // double sigh
private slots:
void slotNew();
void slotEdit();
void slotRemove();
void slotInsertSeparator();
void slotMoveUp();
void slotMoveDown();
void slotSelectionChanged();
private:
TQPixmap blankIcon();
TQStringList m_removed;
class TDEListBox *lbTools;
class TQPushButton *btnNew, *btnRemove, *btnEdit, *btnMoveUp, *btnMoveDwn;
class TDEConfig *config;
bool m_changed;
};
/**
* A Singleton class for invoking external tools with the view command line
*/
class KateExternalToolsCommand : public Kate::Command {
public:
KateExternalToolsCommand ();
virtual ~KateExternalToolsCommand () {};
static KateExternalToolsCommand *self();
void reload();
public:
virtual TQStringList cmds ();
virtual bool exec (Kate::View *view, const TQString &cmd, TQString &msg);
virtual bool help (Kate::View *view, const TQString &cmd, TQString &msg);
private:
static KateExternalToolsCommand *s_self;
TQStringList m_list;
TQMap<TQString,TQString> m_map;
bool m_inited;
};
/**
* A Dialog to edit a single KateExternalTool object
*/
class KateExternalToolServiceEditor : public KDialogBase
{
Q_OBJECT
public:
KateExternalToolServiceEditor( KateExternalTool *tool=0,
TQWidget *parent=0, const char *name=0 );
class TQLineEdit *leName, *leExecutable, *leMimetypes,*leCmdLine;
class TQTextEdit *teCommand;
class KIconButton *btnIcon;
class TQComboBox *cmbSave;
private slots:
/**
* Run when the OK button is clicked, to ensure critical values are provided
*/
void slotOk();
/**
* show a mimetype chooser dialog
*/
void showMTDlg();
private:
KateExternalTool *tool;
};
#endif //_KATE_EXTERNAL_TOOLS_H_
|