1 | /* This file is part of the KDE project |
2 | Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> |
3 | Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> |
4 | Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> |
5 | |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public |
8 | License version 2 as published by the Free Software Foundation. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #ifndef __KATE_VIEWMANAGER_H__ |
22 | #define __KATE_VIEWMANAGER_H__ |
23 | |
24 | #include "katemain.h" |
25 | #include "katedocmanager.h" |
26 | |
27 | |
28 | #include <KTextEditor/View> |
29 | #include <KTextEditor/Document> |
30 | |
31 | #include <QPointer> |
32 | #include <QList> |
33 | #include <QSplitter> |
34 | #include <QStackedWidget> |
35 | |
36 | #include <config.h> |
37 | |
38 | #ifdef KActivities_FOUND |
39 | namespace KActivities { class ResourceInstance; } |
40 | #endif |
41 | |
42 | class KateDocumentInfo; |
43 | |
44 | class KConfigGroup; |
45 | class KConfigBase; |
46 | class KateMainWindow; |
47 | class KateViewSpace; |
48 | class KAction; |
49 | |
50 | class QToolButton; |
51 | |
52 | class KateViewManager : public QSplitter |
53 | { |
54 | Q_OBJECT |
55 | |
56 | friend class KateViewSpace; |
57 | friend class KateVSStatusBar; |
58 | |
59 | public: |
60 | KateViewManager (QWidget *parentW, KateMainWindow *parent); |
61 | ~KateViewManager (); |
62 | |
63 | void updateViewSpaceActions (); |
64 | |
65 | private: |
66 | /** |
67 | * create all actions needed for the view manager |
68 | */ |
69 | void setupActions (); |
70 | |
71 | public: |
72 | /* This will save the splitter configuration */ |
73 | void saveViewConfiguration(KConfigGroup& group); |
74 | |
75 | /* restore it */ |
76 | void restoreViewConfiguration (const KConfigGroup& group); |
77 | |
78 | KTextEditor::Document *openUrl (const KUrl &url, |
79 | const QString& encoding, |
80 | bool activate = true, |
81 | bool isTempFile = false, |
82 | const KateDocumentInfo& docInfo = KateDocumentInfo()); |
83 | |
84 | KTextEditor::Document *openUrls (const QList<KUrl> &url, |
85 | const QString& encoding, |
86 | bool isTempFile = false, |
87 | const KateDocumentInfo& docInfo = KateDocumentInfo()); |
88 | |
89 | KTextEditor::View *openUrlWithView (const KUrl &url, const QString& encoding); |
90 | |
91 | public Q_SLOTS: |
92 | void openUrl (const KUrl &url); |
93 | |
94 | public: |
95 | |
96 | void setViewActivationBlocked (bool block); |
97 | |
98 | |
99 | public: |
100 | void closeViews(KTextEditor::Document *doc); |
101 | KateMainWindow *mainWindow(); |
102 | |
103 | bool isCursorPositionVisible() const; |
104 | bool isCharactersCountVisible() const; |
105 | bool isInsertModeVisible() const; |
106 | bool isSelectModeVisible() const; |
107 | bool isEncodingVisible() const; |
108 | bool isDocumentNameVisible() const; |
109 | |
110 | private Q_SLOTS: |
111 | void activateView ( KTextEditor::View *view ); |
112 | void activateSpace ( KTextEditor::View* v ); |
113 | |
114 | public Q_SLOTS: |
115 | void slotDocumentNew (); |
116 | void slotDocumentOpen (); |
117 | void slotDocumentClose (); |
118 | void slotDocumentClose (KTextEditor::Document *document); |
119 | |
120 | void setActiveSpace ( KateViewSpace* vs ); |
121 | void setActiveView ( KTextEditor::View* view ); |
122 | |
123 | void activateNextView(); |
124 | void activatePrevView(); |
125 | |
126 | protected: |
127 | QPointer<KTextEditor::View> guiMergedView; |
128 | |
129 | Q_SIGNALS: |
130 | void statChanged (); |
131 | void viewChanged (); |
132 | void viewCreated (KTextEditor::View *); |
133 | |
134 | void cursorPositionItemVisibilityChanged(bool); |
135 | void charactersCountItemVisibilityChanged(bool); |
136 | void insertModeItemVisibilityChanged(bool); |
137 | void selectModeItemVisibilityChanged(bool); |
138 | void encodingItemVisibilityChanged(bool); |
139 | void documentNameItemVisibilityChanged(bool); |
140 | |
141 | public: |
142 | inline QList<KTextEditor::View*> &viewList () |
143 | { |
144 | return m_viewList; |
145 | } |
146 | |
147 | private: |
148 | /** |
149 | * create and activate a new view for doc, if doc == 0, then |
150 | * create a new document |
151 | */ |
152 | bool createView ( KTextEditor::Document *doc = 0L ); |
153 | |
154 | bool deleteView ( KTextEditor::View *view, bool delViewSpace = true); |
155 | |
156 | void moveViewtoSplit (KTextEditor::View *view); |
157 | void moveViewtoStack (KTextEditor::View *view); |
158 | |
159 | /* Save the configuration of a single splitter. |
160 | * If child splitters are found, it calls it self with those as the argument. |
161 | * If a viewspace child is found, it is asked to save its filelist. |
162 | */ |
163 | void saveSplitterConfig(QSplitter* s, KConfigBase* config, const QString& viewConfGrp); |
164 | |
165 | /** Restore a single splitter. |
166 | * This is all the work is done for @see saveSplitterConfig() |
167 | */ |
168 | void restoreSplitter ( const KConfigBase* config, const QString &group, QSplitter* parent, const QString& viewConfGrp); |
169 | |
170 | void removeViewSpace (KateViewSpace *viewspace); |
171 | |
172 | public: |
173 | KTextEditor::View* activeView (); |
174 | KateViewSpace* activeViewSpace (); |
175 | |
176 | int viewCount () const; |
177 | int viewSpaceCount () const; |
178 | |
179 | bool isViewActivationBlocked() |
180 | { |
181 | return m_blockViewCreationAndActivation; |
182 | } |
183 | |
184 | private Q_SLOTS: |
185 | void slotViewChanged(); |
186 | |
187 | void documentCreated (KTextEditor::Document *doc); |
188 | void documentDeleted (KTextEditor::Document *doc); |
189 | |
190 | void documentSavedOrUploaded(KTextEditor::Document* document,bool saveAs); |
191 | |
192 | public Q_SLOTS: |
193 | /** |
194 | * Splits a KateViewSpace into two in the following steps: |
195 | * 1. create a QSplitter in the parent of the KateViewSpace to be split |
196 | * 2. move the to-be-split KateViewSpace to the new splitter |
197 | * 3. create new KateViewSpace and added to the new splitter |
198 | * 4. create KateView to populate the new viewspace. |
199 | * 5. The new KateView is made the active one, because createView() does that. |
200 | * If no viewspace is provided, the result of activeViewSpace() is used. |
201 | * The orientation of the new splitter is determined by the value of o. |
202 | * Note: horizontal splitter means vertically aligned views. |
203 | */ |
204 | void splitViewSpace( KateViewSpace* vs = 0L, Qt::Orientation o = Qt::Horizontal ); |
205 | |
206 | /** |
207 | * activate view for given document |
208 | * @param doc document to activate view for |
209 | */ |
210 | KTextEditor::View *activateView ( KTextEditor::Document *doc ); |
211 | |
212 | /** Splits the active viewspace horizontally */ |
213 | void slotSplitViewSpaceHoriz () |
214 | { |
215 | splitViewSpace(0L, Qt::Vertical); |
216 | } |
217 | |
218 | /** Splits the active viewspace vertically */ |
219 | void slotSplitViewSpaceVert () |
220 | { |
221 | splitViewSpace(); |
222 | } |
223 | |
224 | /** moves the splitter according to the key that has been pressed */ |
225 | void moveSplitter(Qt::Key key, int repeats = 1); |
226 | |
227 | /** moves the splitter to the right */ |
228 | void moveSplitterRight() |
229 | { |
230 | moveSplitter(Qt::Key_Right); |
231 | } |
232 | |
233 | /** moves the splitter to the left */ |
234 | void moveSplitterLeft() |
235 | { |
236 | moveSplitter(Qt::Key_Left); |
237 | } |
238 | |
239 | /** moves the splitter up */ |
240 | void moveSplitterUp() |
241 | { |
242 | moveSplitter(Qt::Key_Up); |
243 | } |
244 | |
245 | /** moves the splitter down */ |
246 | void moveSplitterDown() |
247 | { |
248 | moveSplitter(Qt::Key_Down); |
249 | } |
250 | |
251 | void slotCloseCurrentViewSpace(); |
252 | |
253 | /** closes every view but the active one */ |
254 | void slotCloseOtherViews(); |
255 | |
256 | void reactivateActiveView(); |
257 | |
258 | /** |
259 | * get views => age mapping |
260 | * useful to show views in a LRU way |
261 | * important: smallest age ==> latest used view |
262 | */ |
263 | const QHash<KTextEditor::View *, qint64> &lruViews () const |
264 | { |
265 | return m_lruViews; |
266 | } |
267 | |
268 | private: |
269 | KateMainWindow *m_mainWindow; |
270 | bool m_init; |
271 | |
272 | KAction *m_closeView; |
273 | KAction *m_closeOtherViews; |
274 | KAction *goNext; |
275 | KAction *goPrev; |
276 | KAction *m_cursorPosToggle; |
277 | KAction *m_charCountToggle; |
278 | KAction *m_insertModeToggle; |
279 | KAction *m_selectModeToggle; |
280 | KAction *m_encodingToggle; |
281 | KAction *m_docNameToggle; |
282 | |
283 | QList<KateViewSpace*> m_viewSpaceList; |
284 | QList<KTextEditor::View*> m_viewList; |
285 | QHash<KTextEditor::View*, bool> m_activeStates; |
286 | |
287 | #ifdef KActivities_FOUND |
288 | QHash<KTextEditor::View*, KActivities::ResourceInstance*> m_activityResources; |
289 | #endif |
290 | |
291 | bool m_blockViewCreationAndActivation; |
292 | |
293 | bool m_activeViewRunning; |
294 | |
295 | int m_splitterIndex; // used during saving splitter config. |
296 | |
297 | /** |
298 | * history of view activations |
299 | * map view => number, the lower, the more recent activated |
300 | */ |
301 | QHash<KTextEditor::View *, qint64> m_lruViews; |
302 | |
303 | /** |
304 | * current minimal age |
305 | */ |
306 | qint64 m_minAge; |
307 | |
308 | friend class KateContainer; |
309 | }; |
310 | |
311 | #endif |
312 | // kate: space-indent on; indent-width 2; replace-tabs on; |
313 | |
314 | |