1 | /* This file is part of the KDE project |
2 | Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> |
3 | Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License version 2 as published by the Free Software Foundation. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef __KATE_APP_H__ |
21 | #define __KATE_APP_H__ |
22 | |
23 | #include <kate_export.h> |
24 | |
25 | #include "katemain.h" |
26 | #include <kate/mainwindow.h> |
27 | |
28 | #include <KApplication> |
29 | |
30 | #include <QList> |
31 | |
32 | class KateSessionManager; |
33 | class KateMainWindow; |
34 | class KatePluginManager; |
35 | class KateDocManager; |
36 | class KateAppCommands; |
37 | class KateAppAdaptor; |
38 | |
39 | namespace KTextEditor |
40 | { |
41 | class Document; |
42 | } |
43 | |
44 | namespace Kate |
45 | { |
46 | class Application; |
47 | } |
48 | |
49 | class KCmdLineArgs; |
50 | |
51 | /** |
52 | * Kate Application |
53 | * This class represents the core kate application object |
54 | */ |
55 | class KATEINTERFACES_EXPORT KateApp : public KApplication |
56 | { |
57 | Q_OBJECT |
58 | |
59 | /** |
60 | * constructors & accessor to app object + plugin interface for it |
61 | */ |
62 | public: |
63 | /** |
64 | * application constructor |
65 | * @param args parsed command line args |
66 | */ |
67 | KateApp (KCmdLineArgs *args); |
68 | |
69 | /** |
70 | * application destructor |
71 | */ |
72 | ~KateApp (); |
73 | |
74 | /** |
75 | * static accessor to avoid casting ;) |
76 | * @return app instance |
77 | */ |
78 | static KateApp *self (); |
79 | |
80 | /** |
81 | * accessor to the Kate::Application plugin interface |
82 | * @return application plugin interface |
83 | */ |
84 | Kate::Application *application (); |
85 | |
86 | /** |
87 | * Returns the current Kate version (X.Y) or (X.Y.Z) |
88 | * @param fullVersion should full version be returned? |
89 | * @return Kate version |
90 | */ |
91 | static QString kateVersion (bool fullVersion = true); |
92 | |
93 | /** |
94 | * kate init |
95 | */ |
96 | private: |
97 | /** |
98 | * get kate inited |
99 | */ |
100 | void initKate (); |
101 | |
102 | /** |
103 | * restore a old kate session |
104 | */ |
105 | void restoreKate (); |
106 | |
107 | /** |
108 | * try to start kate |
109 | * @return success, if false, kate should exit |
110 | */ |
111 | bool startupKate (); |
112 | |
113 | /** |
114 | * kate shutdown |
115 | */ |
116 | public: |
117 | /** |
118 | * shutdown kate application |
119 | * @param win mainwindow which is used for dialogs |
120 | */ |
121 | void shutdownKate (KateMainWindow *win); |
122 | |
123 | /** |
124 | * other accessors for global unique instances |
125 | */ |
126 | public: |
127 | /** |
128 | * accessor to plugin manager |
129 | * @return plugin manager instance |
130 | */ |
131 | KatePluginManager *pluginManager(); |
132 | |
133 | /** |
134 | * accessor to document manager |
135 | * @return document manager instance |
136 | */ |
137 | KateDocManager *documentManager (); |
138 | |
139 | /** |
140 | * accessor to session manager |
141 | * @return session manager instance |
142 | */ |
143 | KateSessionManager *sessionManager (); |
144 | |
145 | /** |
146 | * window management |
147 | */ |
148 | public: |
149 | /** |
150 | * create a new main window, use given config if any for restore |
151 | * @param sconfig session config object |
152 | * @param sgroup session group for this window |
153 | * @return new constructed main window |
154 | */ |
155 | KateMainWindow *newMainWindow (KConfig *sconfig = 0, const QString &sgroup = "" ); |
156 | |
157 | /** |
158 | * add the mainwindow given |
159 | * should be called in mainwindow constructor |
160 | * @param mainWindow window to remove |
161 | */ |
162 | void addMainWindow (KateMainWindow *mainWindow); |
163 | |
164 | /** |
165 | * removes the mainwindow given, DOES NOT DELETE IT |
166 | * should be called in mainwindow destructor |
167 | * @param mainWindow window to remove |
168 | */ |
169 | void removeMainWindow (KateMainWindow *mainWindow); |
170 | |
171 | /** |
172 | * give back current active main window |
173 | * can only be 0 at app start or exit |
174 | * @return current active main window |
175 | */ |
176 | KateMainWindow *activeMainWindow (); |
177 | |
178 | /** |
179 | * give back number of existing main windows |
180 | * @return number of main windows |
181 | */ |
182 | int mainWindows () const; |
183 | |
184 | /** |
185 | * give back the window you want |
186 | * @param n window index |
187 | * @return requested main window |
188 | */ |
189 | KateMainWindow *mainWindow (int n); |
190 | |
191 | int mainWindowID(KateMainWindow *window); |
192 | |
193 | /** |
194 | * some stuff for the dcop API |
195 | */ |
196 | public: |
197 | /** |
198 | * open url with given encoding |
199 | * used by kate if --use given |
200 | * @param url filename |
201 | * @param encoding encoding name |
202 | * @return success |
203 | */ |
204 | bool openUrl (const KUrl &url, const QString &encoding, bool isTempFile); |
205 | |
206 | KTextEditor::Document* openDocUrl (const KUrl &url, const QString &encoding, bool isTempFile); |
207 | |
208 | void emitDocumentClosed(const QString& token); |
209 | |
210 | /** |
211 | * position cursor in current active view |
212 | * @param line line to set |
213 | * @param column column to set |
214 | * @return success |
215 | */ |
216 | bool setCursor (int line, int column); |
217 | |
218 | /** |
219 | * helper to handle stdin input |
220 | * open a new document/view, fill it with the text given |
221 | * @param text text to fill in the new doc/view |
222 | * @return success |
223 | */ |
224 | bool openInput (const QString &text); |
225 | |
226 | bool shouldExit() const |
227 | { |
228 | return m_shouldExit; |
229 | } |
230 | |
231 | /** |
232 | * Get a list of all mainwindows interfaces for the plugins. |
233 | * @return all mainwindows |
234 | * @see activeMainWindow() |
235 | */ |
236 | const QList<Kate::MainWindow*> &mainWindowsInterfaces () const |
237 | { |
238 | return m_mainWindowsInterfaces; |
239 | } |
240 | |
241 | private: |
242 | bool m_shouldExit; |
243 | /** |
244 | * kate's command line args |
245 | */ |
246 | KCmdLineArgs *m_args; |
247 | |
248 | /** |
249 | * plugin interface |
250 | */ |
251 | Kate::Application *m_application; |
252 | |
253 | /** |
254 | * document manager |
255 | */ |
256 | KateDocManager *m_docManager; |
257 | |
258 | /** |
259 | * plugin manager |
260 | */ |
261 | KatePluginManager *m_pluginManager; |
262 | |
263 | /** |
264 | * session manager |
265 | */ |
266 | KateSessionManager *m_sessionManager; |
267 | |
268 | /** |
269 | * dbus interface |
270 | */ |
271 | KateAppAdaptor *m_adaptor; |
272 | |
273 | /** |
274 | * known main windows |
275 | */ |
276 | QList<KateMainWindow*> m_mainWindows; |
277 | QList<Kate::MainWindow*> m_mainWindowsInterfaces; |
278 | |
279 | // various vim-inspired command line commands |
280 | KateAppCommands *m_appCommands; |
281 | |
282 | }; |
283 | |
284 | #endif |
285 | // kate: space-indent on; indent-width 2; replace-tabs on; |
286 | |
287 | |