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_MAINWINDOW_H__ |
22 | #define __KATE_MAINWINDOW_H__ |
23 | |
24 | #include "katemain.h" |
25 | #include "katemdi.h" |
26 | |
27 | #include <KTextEditor/View> |
28 | #include <KTextEditor/Document> |
29 | |
30 | #include <KParts/Part> |
31 | |
32 | #include <KAction> |
33 | |
34 | #include <QDragEnterEvent> |
35 | #include <QEvent> |
36 | #include <QDropEvent> |
37 | #include <QVBoxLayout> |
38 | #include <QModelIndex> |
39 | #include <QHash> |
40 | #include <QStackedWidget> |
41 | |
42 | class ; |
43 | |
44 | namespace KIO |
45 | { |
46 | class UDSEntry; |
47 | typedef class QList<UDSEntry> UDSEntryList; |
48 | } |
49 | |
50 | namespace Kate |
51 | { |
52 | class MainWindow; |
53 | class Plugin; |
54 | class PluginView; |
55 | class PluginConfigPageInterface; |
56 | } |
57 | |
58 | class KFileItem; |
59 | class KRecentFilesAction; |
60 | |
61 | class KateViewManager; |
62 | class KateMwModOnHdDialog; |
63 | class KateQuickOpen; |
64 | |
65 | #include <QtGui/QStackedLayout> |
66 | // Helper layout class to always provide minimum size |
67 | class KateContainerStackedLayout : public QStackedLayout |
68 | { |
69 | Q_OBJECT |
70 | public: |
71 | KateContainerStackedLayout(QWidget* parent); |
72 | virtual QSize sizeHint() const; |
73 | virtual QSize minimumSize() const; |
74 | }; |
75 | |
76 | |
77 | class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBase |
78 | { |
79 | Q_OBJECT |
80 | |
81 | friend class KateConfigDialog; |
82 | friend class KateViewManager; |
83 | |
84 | public: |
85 | /** |
86 | * Construct the window and restore its state from given config if any |
87 | * @param sconfig session config for this window, 0 if none |
88 | * @param sgroup session config group to use |
89 | */ |
90 | KateMainWindow (KConfig *sconfig, const QString &sgroup); |
91 | |
92 | /** |
93 | * Destruct the nice window |
94 | */ |
95 | ~KateMainWindow(); |
96 | |
97 | /** |
98 | * Accessor methodes for interface and child objects |
99 | */ |
100 | public: |
101 | Kate::MainWindow *mainWindow () |
102 | { |
103 | return m_mainWindow; |
104 | } |
105 | |
106 | KateViewManager *viewManager () |
107 | { |
108 | return m_viewManager; |
109 | } |
110 | |
111 | /** |
112 | * get a plugin view with identifier \p name. |
113 | * \param name the plugin's name |
114 | * \return pointer to the plugin view if a plugin with \p name is loaded and has a view for this mainwindow, |
115 | * otherwise null |
116 | */ |
117 | Kate::PluginView *pluginView (const QString &name); |
118 | |
119 | public: |
120 | /** Returns the URL of the current document. |
121 | * anders: I add this for use from the file selector. */ |
122 | KUrl activeDocumentUrl(); |
123 | |
124 | uint mainWindowNumber () const |
125 | { |
126 | return myID; |
127 | } |
128 | |
129 | /** |
130 | * Prompts the user for what to do with files that are modified on disk if any. |
131 | * This is optionally run when the window receives focus, and when the last |
132 | * window is closed. |
133 | * @return true if no documents are modified on disk, or all documents were |
134 | * handled by the dialog; otherwise (the dialog was canceled) false. |
135 | */ |
136 | bool showModOnDiskPrompt(); |
137 | |
138 | public: |
139 | /*reimp*/ void readProperties(const KConfigGroup& config); |
140 | /*reimp*/ void saveProperties(KConfigGroup& config); |
141 | /*reimp*/ void saveGlobalProperties( KConfig* sessionConfig ); |
142 | |
143 | public: |
144 | bool queryClose_internal(KTextEditor::Document *doc = NULL); |
145 | |
146 | /** |
147 | * save the settings, size and state of this window in |
148 | * the provided config group |
149 | */ |
150 | void saveWindowConfig(const KConfigGroup &); |
151 | /** |
152 | * restore the settings, size and state of this window from |
153 | * the provided config group. |
154 | */ |
155 | void restoreWindowConfig(const KConfigGroup &); |
156 | |
157 | private: |
158 | /** |
159 | * Setup actions which pointers are needed already in setupMainWindow |
160 | */ |
161 | void setupImportantActions (); |
162 | |
163 | void setupMainWindow(); |
164 | void setupActions(); |
165 | bool queryClose(); |
166 | void addMenuBarActionToContextMenu(); |
167 | void removeMenuBarActionFromContextMenu(); |
168 | |
169 | /** |
170 | * read some global options from katerc |
171 | */ |
172 | void readOptions(); |
173 | |
174 | /** |
175 | * save some global options to katerc |
176 | */ |
177 | void saveOptions(); |
178 | |
179 | void dragEnterEvent( QDragEnterEvent * ); |
180 | void dropEvent( QDropEvent * ); |
181 | |
182 | public Q_SLOTS: |
183 | void slotFileClose(); |
184 | void slotFileQuit(); |
185 | void queueModifiedOnDisc(KTextEditor::Document *doc); |
186 | |
187 | /** |
188 | * slots used for actions in the menus/toolbars |
189 | * or internal signal connections |
190 | */ |
191 | private Q_SLOTS: |
192 | void newWindow (); |
193 | |
194 | void slotConfigure(); |
195 | |
196 | void slotOpenWithMenuAction(QAction* a); |
197 | |
198 | void slotEditToolbars(); |
199 | void slotNewToolbarConfig(); |
200 | void slotUpdateOpenWith(); |
201 | void slotOpenDocument(KUrl); |
202 | |
203 | void slotDropEvent(QDropEvent *); |
204 | void editKeys(); |
205 | void mSlotFixOpenWithMenu(); |
206 | |
207 | /** |
208 | * Show quick open |
209 | */ |
210 | void slotQuickOpen (); |
211 | |
212 | void tipOfTheDay(); |
213 | |
214 | /* to update the caption */ |
215 | void slotDocumentCreated (KTextEditor::Document *doc); |
216 | void updateCaption (KTextEditor::Document *doc); |
217 | // calls updateCaption(doc) with the current document |
218 | void updateCaption (); |
219 | |
220 | void pluginHelp (); |
221 | void aboutEditor(); |
222 | void slotFullScreen(bool); |
223 | |
224 | void slotListRecursiveEntries(KIO::Job *job, const KIO::UDSEntryList &list); |
225 | |
226 | private Q_SLOTS: |
227 | void toggleShowStatusBar (); |
228 | void toggleShowMenuBar(bool showMessage = true); |
229 | |
230 | public: |
231 | bool showStatusBar (); |
232 | |
233 | Q_SIGNALS: |
234 | void statusBarToggled (); |
235 | void unhandledShortcutOverride (QEvent *e); |
236 | |
237 | public: |
238 | void openUrl (const QString &name = QString()); |
239 | |
240 | QHash<Kate::Plugin*, Kate::PluginView*> &pluginViews () |
241 | { |
242 | return m_pluginViews; |
243 | } |
244 | |
245 | inline QWidget *bottomViewBarContainer() {return m_bottomViewBarContainer;} |
246 | inline void addToBottomViewBarContainer(KTextEditor::View *view,QWidget *bar){m_bottomContainerStack->addWidget (bar); m_bottomViewBarMapping[view]=BarState(bar);} |
247 | inline void hideBottomViewBarForView(KTextEditor::View *view) {QWidget *bar; BarState state=m_bottomViewBarMapping.value(view); bar=state.bar(); if (bar) {m_bottomContainerStack->setCurrentWidget(bar); bar->hide(); state.setState(false); m_bottomViewBarMapping[view]=state;} m_bottomViewBarContainer->hide();} |
248 | inline void showBottomViewBarForView(KTextEditor::View *view) {QWidget *bar; BarState state=m_bottomViewBarMapping.value(view); bar=state.bar(); if (bar) {m_bottomContainerStack->setCurrentWidget(bar); bar->show(); state.setState(true); m_bottomViewBarMapping[view]=state; m_bottomViewBarContainer->show();}} |
249 | inline void deleteBottomViewBarForView(KTextEditor::View *view) {QWidget *bar; BarState state=m_bottomViewBarMapping.take(view); bar=state.bar(); if (bar) {if (m_bottomContainerStack->currentWidget()==bar) m_bottomViewBarContainer->hide(); delete bar;}} |
250 | |
251 | inline QWidget *topViewBarContainer() {return m_topViewBarContainer;} |
252 | inline void addToTopViewBarContainer(KTextEditor::View *view,QWidget *bar){m_topContainerStack->addWidget (bar); m_topViewBarMapping[view]=BarState(bar);} |
253 | inline void hideTopViewBarForView(KTextEditor::View *view) {QWidget *bar; BarState state=m_topViewBarMapping.value(view); bar=state.bar(); if (bar) {m_topContainerStack->setCurrentWidget(bar); bar->hide(); state.setState(false); m_topViewBarMapping[view]=state;} m_topViewBarContainer->hide();} |
254 | inline void showTopViewBarForView(KTextEditor::View *view) {QWidget *bar; BarState state=m_topViewBarMapping.value(view); bar=state.bar(); if (bar) {m_topContainerStack->setCurrentWidget(bar); bar->show(); state.setState(true); m_topViewBarMapping[view]=state; m_topViewBarContainer->show();}} |
255 | inline void deleteTopViewBarForView(KTextEditor::View *view) {QWidget *bar; BarState state=m_topViewBarMapping.take(view); bar=state.bar(); if (bar) {if (m_topContainerStack->currentWidget()==bar) m_topViewBarContainer->hide(); delete bar;}} |
256 | |
257 | private Q_SLOTS: |
258 | void slotUpdateBottomViewBar(); |
259 | void slotUpdateTopViewBar(); |
260 | |
261 | private Q_SLOTS: |
262 | void slotDocumentCloseAll(); |
263 | void slotDocumentCloseOther(); |
264 | void slotDocumentCloseOther(KTextEditor::Document *document); |
265 | void slotDocumentCloseSelected(const QList<KTextEditor::Document*>&); |
266 | private: |
267 | static uint uniqueID; |
268 | uint myID; |
269 | |
270 | Kate::MainWindow *m_mainWindow; |
271 | |
272 | bool modNotification; |
273 | |
274 | /** |
275 | * stacked widget containing the central area, aka view manager, quickopen, ... |
276 | */ |
277 | QStackedWidget *m_mainStackedWidget; |
278 | |
279 | /** |
280 | * quick open to fast switch documents |
281 | */ |
282 | KateQuickOpen *m_quickOpen; |
283 | |
284 | /** |
285 | * keeps track of views |
286 | */ |
287 | KateViewManager *m_viewManager; |
288 | |
289 | KRecentFilesAction *fileOpenRecent; |
290 | |
291 | KActionMenu* documentOpenWith; |
292 | |
293 | KToggleAction* settingsShowFileselector; |
294 | |
295 | bool m_modignore; |
296 | |
297 | // all plugin views for this mainwindow, used by the pluginmanager |
298 | QHash<Kate::Plugin*, Kate::PluginView*> m_pluginViews; |
299 | |
300 | // options: show statusbar + show path |
301 | KToggleAction *m_paShowPath; |
302 | KToggleAction *m_paShowStatusBar; |
303 | KToggleAction *m_paShowMenuBar; |
304 | QWidget *m_bottomViewBarContainer; |
305 | KateContainerStackedLayout *m_bottomContainerStack; |
306 | QWidget *m_topViewBarContainer; |
307 | KateContainerStackedLayout *m_topContainerStack; |
308 | |
309 | class BarState{ |
310 | public: |
311 | BarState():m_bar(0),m_state(false){} |
312 | BarState(QWidget* bar):m_bar(bar),m_state(false){} |
313 | ~BarState(){} |
314 | QWidget *bar(){return m_bar;} |
315 | bool state(){return m_state;} |
316 | void setState(bool state){m_state=state;} |
317 | private: |
318 | QWidget *m_bar; |
319 | bool m_state; |
320 | }; |
321 | QHash<KTextEditor::View*,BarState> m_bottomViewBarMapping; |
322 | QHash<KTextEditor::View*,BarState> m_topViewBarMapping; |
323 | |
324 | public: |
325 | static void unsetModifiedOnDiscDialogIfIf(KateMwModOnHdDialog* diag) { |
326 | if (s_modOnHdDialog==diag) s_modOnHdDialog=0; |
327 | } |
328 | private: |
329 | static KateMwModOnHdDialog *s_modOnHdDialog; |
330 | |
331 | public Q_SLOTS: |
332 | void showPluginConfigPage(Kate::PluginConfigPageInterface *configpageinterface,uint id); |
333 | |
334 | void slotWindowActivated (); |
335 | |
336 | protected: |
337 | virtual bool event( QEvent *e ); |
338 | }; |
339 | |
340 | #endif |
341 | |
342 | // kate: space-indent on; indent-width 2; replace-tabs on; |
343 | |