]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
Sanitize the way Buffers are saved, renamed and closed.
[lyx.git] / src / frontends / qt4 / GuiView.h
1 // -*- C++ -*-
2 /**
3  * \file GuiView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjornes
8  * \author John Levon
9  * \author Abdelrazak Younes
10  * \author Peter Kümmel
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef GUI_VIEW_H
16 #define GUI_VIEW_H
17
18 #include "frontends/Delegates.h"
19 #include "frontends/LyXView.h"
20
21 #include "support/strfwd.h"
22
23 #include <QMainWindow>
24
25 class QCloseEvent;
26 class QDragEnterEvent;
27 class QDropEvent;
28 class QMenu;
29 class QShowEvent;
30
31
32 namespace lyx {
33
34 class ToolbarInfo;
35
36 namespace frontend {
37
38 class Dialog;
39 class GuiLayoutBox;
40 class GuiToolbar;
41 class GuiWorkArea;
42
43 /**
44  * GuiView - Qt4 implementation of LyXView
45  *
46  * qt4-private implementation of the main LyX window.
47  *
48  * Note: a QObject emits a destroyed(QObject *) Qt signal when it
49  * is deleted. This might be useful for closing other dialogs
50  * depending on a given GuiView.
51  */
52 class GuiView : public QMainWindow, public LyXView, public GuiBufferViewDelegate,
53         public GuiBufferDelegate
54 {
55         Q_OBJECT
56 public:
57         /// create a main window of the given dimensions
58         GuiView(int id);
59
60         ~GuiView();
61
62         ///
63         int id() const { return id_; }
64         void close();
65         void setFocus();
66         void setBusy(bool);
67         /// returns true if this view has the focus.
68         bool hasFocus() const;
69
70         /// add toolbar, if newline==true, add a toolbar break before the toolbar
71         GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
72         virtual void updateStatusBar();
73         virtual void message(docstring const & str);
74
75         /// updates the possible layouts selectable
76         void updateLayoutList();
77         void updateToolbars();
78         QMenu * createPopupMenu();
79         FuncStatus getStatus(FuncRequest const & cmd);
80         bool dispatch(FuncRequest const & cmd);
81
82         ///
83         void setLayoutDialog(GuiLayoutBox *);
84
85         /// \return the buffer currently shown in this window
86         Buffer * buffer();
87         Buffer const * buffer() const;
88         /// set a buffer to the current workarea.
89         void setBuffer(Buffer * b); ///< \c Buffer to set.
90         ///
91         bool closeBuffer();
92         /// write all buffers, asking the user, returns false if cancelled
93         bool quitWriteAll();
94
95         /// GuiBufferDelegate.
96         ///@{
97         void resetAutosaveTimers();
98         void errors(std::string const &);
99         void structureChanged() { updateToc(); }
100         ///@}
101         
102         /// called on timeout
103         void autoSave();
104         ///
105         void updateEmbeddedFiles();
106
107         /// \return the current buffer view.
108         BufferView * view();
109
110         /** redraw \c inset in all the BufferViews in which it is currently
111          *  visible. If successful return a pointer to the owning Buffer.
112          */
113         Buffer const * updateInset(Inset const *);
114         ///
115         void restartCursor();
116
117         /// \return the \c Workarea associated to \p  Buffer
118         /// \retval 0 if no \c WorkArea is found.
119         GuiWorkArea * workArea(Buffer & buffer);
120
121         /// Add a \c WorkArea 
122         /// \return the \c Workarea associated to \p  Buffer
123         /// \retval 0 if no \c WorkArea is found.
124         GuiWorkArea * addWorkArea(Buffer & buffer);
125         ///
126         void setCurrentWorkArea(GuiWorkArea * work_area);
127         ///
128         void removeWorkArea(GuiWorkArea * work_area);
129         /// return the current WorkArea (the one that has the focus).
130         GuiWorkArea const * currentWorkArea() const;
131
132 Q_SIGNALS:
133         void closing(int);
134
135 public Q_SLOTS:
136         /// idle timeout.
137         /// clear any temporary message and replace with current status.
138         void clearMessage();
139
140 private Q_SLOTS:
141         ///
142         void updateWindowTitle(GuiWorkArea * wa);
143
144         ///
145         void on_currentWorkAreaChanged(GuiWorkArea *);
146
147         /// slots to change the icon size
148         void smallSizedIcons();
149         void normalSizedIcons();
150         void bigSizedIcons();
151
152 private:
153         ///
154         void addTabWorkArea();
155
156         /// connect to signals in the given BufferView
157         void connectBufferView(BufferView & bv);
158         /// disconnect from signals in the given BufferView
159         void disconnectBufferView();
160         /// connect to signals in the given buffer
161         void connectBuffer(Buffer & buf);
162         /// disconnect from signals in the given buffer
163         void disconnectBuffer();
164         ///
165         void updateToc();
166         ///
167         void dragEnterEvent(QDragEnterEvent * ev);
168         ///
169         void dropEvent(QDropEvent * ev);
170         /// make sure we quit cleanly
171         void closeEvent(QCloseEvent * e);
172         ///
173         void showEvent(QShowEvent *);
174
175         /// in order to catch Tab key press.
176         bool event(QEvent * e);
177         bool focusNextPrevChild(bool);
178
179         ///
180         struct GuiViewPrivate;
181         GuiViewPrivate & d;
182
183 public:
184         ///
185         /// dialogs for this view
186         ///
187
188         ///
189         void resetDialogs();
190
191         /** Check the status of all visible dialogs and disable or reenable
192          *  them as appropriate.
193          *
194          *  Disabling is needed for example when a dialog is open and the
195          *  cursor moves to a position where the corresponding inset is not
196          *  allowed.
197          */
198         void checkStatus();
199
200         /// Hide all visible dialogs
201         void hideAll() const;
202         /// Hide any dialogs that require a buffer for them to operate
203         void hideBufferDependent() const;
204         /** Update visible, buffer-dependent dialogs
205             If the bool is true then a buffer change has occurred
206             else it is still the same buffer.
207          */
208         void updateBufferDependent(bool) const;
209
210         /** \param name == "bibtex", "citation" etc; an identifier used to
211             launch a particular dialog.
212             \param data is a string representation of the Inset contents.
213             It is often little more than the output from Inset::write.
214             It is passed to, and parsed by, the frontend dialog.
215             Several of these dialogs do not need any data,
216             so it defaults to string().
217             \param inset ownership is _not_ passed to the frontend dialog.
218             It is stored internally and used by the kernel to ascertain
219             what to do with the FuncRequest dispatched from the frontend
220             dialog on 'Apply'; should it be used to create a new inset at
221             the current cursor position or modify an existing, 'open' inset?
222         */
223         void showDialog(std::string const & name,
224                 std::string const & data, Inset * inset = 0);
225
226         /** \param name == "citation", "bibtex" etc; an identifier used
227             to update the contents of a particular dialog with \param data.
228             See the comments to 'show', above.
229         */
230         void updateDialog(std::string const & name, std::string const & data);
231
232         /** All Dialogs of the given \param name will be closed if they are
233             connected to the given \param inset.
234         */
235         void hideDialog(std::string const & name, Inset * inset);
236         ///
237         void disconnectDialog(std::string const & name);
238
239 private:
240         ///
241         void insertLyXFile(docstring const & fname);
242         ///
243         void insertPlaintextFile(docstring const & fname,
244                 bool asParagraph);
245
246         /// Save a buffer as a new file. 
247         /**
248         Write a buffer to a new file name and rename the buffer
249     according to the new file name.
250
251     This function is e.g. used by menu callbacks and
252     LFUN_BUFFER_WRITE_AS.
253
254     If 'newname' is empty, the user is asked via a
255     dialog for the buffer's new name and location.
256
257     If 'newname' is non-empty and has an absolute path, that is used.
258     Otherwise the base directory of the buffer is used as the base
259     for any relative path in 'newname'.
260         */
261         bool renameBuffer(Buffer & b, docstring const & newname);
262         ///
263         bool saveBuffer(Buffer & b);
264         ///
265         bool closeBuffer(Buffer & buf);
266
267         ///
268         Inset * getOpenInset(std::string const & name) const;
269
270         /// Is the dialog currently visible?
271         bool isDialogVisible(std::string const & name) const;
272         ///
273         Dialog * find_or_build(std::string const & name);
274         ///
275         Dialog * build(std::string const & name);
276
277         /// This view ID.
278         int id_;
279 };
280
281 } // namespace frontend
282 } // namespace lyx
283
284 #endif // GUIVIEW_H