]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
Fix handling of the add branch textfield in GuiBranches
[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
20 #include "support/strfwd.h"
21
22 #include <QMainWindow>
23
24 class QCloseEvent;
25 class QDragEnterEvent;
26 class QDropEvent;
27 class QMenu;
28 class QShowEvent;
29
30
31 namespace lyx {
32
33 namespace support { class FileName; }
34
35 class Buffer;
36 class BufferView;
37 class Cursor;
38 class DispatchResult;
39 class FuncStatus;
40 class FuncRequest;
41 class Inset;
42
43 namespace frontend {
44
45 class Dialog;
46 class LayoutBox;
47 class GuiToolbar;
48 class GuiWorkArea;
49 class TabWorkArea;
50 class TocModels;
51 class ToolbarInfo;
52
53 /**
54  * GuiView - Qt4 main LyX window
55  *
56  * This class represents the main LyX window and provides
57  * accessor functions to its content.
58  *
59  * Note: a QObject emits a destroyed(QObject *) Qt signal when it
60  * is deleted. This might be useful for closing other dialogs
61  * depending on a given GuiView.
62  */
63 class GuiView : public QMainWindow, public GuiBufferViewDelegate,
64         public GuiBufferDelegate
65 {
66         Q_OBJECT
67
68 public:
69         /// create a main window of the given dimensions
70         GuiView(int id);
71
72         ~GuiView();
73
74         /// closes the view such that the view knows that is closed
75         /// programmatically and not by the user clicking the x.
76         bool closeScheduled();
77
78         int id() const { return id_; }
79
80         /// are we busy ?
81         bool busy() const;
82
83
84         /// \name Generic accessor functions
85         //@{
86         /// The current BufferView refers to the BufferView that has the focus,
87         /// including for example the one that is created when you use the
88         /// advanced search and replace pane.
89         /// \return the currently selected buffer view.
90         BufferView * currentBufferView();
91         BufferView const * currentBufferView() const;
92
93         /// The document BufferView always refers to the view's main document
94         /// BufferView. So, even if the BufferView in e.g., the advanced
95         /// search and replace pane has the focus.
96         /// \return the current document buffer view.
97         BufferView * documentBufferView();
98         BufferView const * documentBufferView() const;
99
100         void newDocument(std::string const & filename,
101                 bool fromTemplate);
102
103         /// display a message in the view
104         /// could be called from any thread
105         void message(docstring const &);
106         
107         bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
108         /// dispatch command.
109         /// \return true if the \c FuncRequest has been dispatched.
110         void dispatch(FuncRequest const & cmd, DispatchResult & dr);
111
112         void restartCursor();
113         /// Update the completion popup and the inline completion state.
114         /// If \c start is true, then a new completion might be started.
115         /// If \c keep is true, an active completion will be kept active
116         /// even though the cursor moved. The update flags of \c cur might
117         /// be changed.
118         void updateCompletion(Cursor & cur, bool start, bool keep);
119
120         ///
121         void setFocus();
122
123         ///
124         void focusInEvent(QFocusEvent * e);
125         /// set a buffer to the current workarea.
126         void setBuffer(Buffer * b); ///< \c Buffer to set.
127
128         /// load a document into the current workarea.
129         Buffer * loadDocument(
130                 support::FileName const &  name, ///< File to load.
131                 bool tolastfiles = true  ///< append to the "Open recent" menu?
132                 );
133
134         /// add toolbar, if newline==true, add a toolbar break before the toolbar
135         GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
136         void updateStatusBar();
137
138         /// updates the possible layouts selectable
139         void updateLayoutList();
140         void updateToolbars();
141         QMenu * createPopupMenu();
142
143         ///
144         LayoutBox * getLayoutDialog() const;
145
146         /// hides the workarea and makes sure it is clean
147         bool hideWorkArea(GuiWorkArea * wa);
148         /// closes the workarea
149         bool closeWorkArea(GuiWorkArea * wa);
150         /// closes the buffer
151         bool closeBuffer(Buffer & buf);
152         ///
153         void openDocument(std::string const & filename);
154         ///
155         void importDocument(std::string const &);
156
157         /// \name GuiBufferDelegate.
158         //@{
159         void resetAutosaveTimers();
160         void errors(std::string const &, bool from_master = false);
161         void structureChanged();
162         void updateTocItem(std::string const &, DocIterator const &);
163         //@}
164
165         ///
166         TocModels & tocModels();
167         
168         /// called on timeout
169         void autoSave();
170
171         /// check for external change of any opened buffer, mainly for svn usage
172         void checkExternallyModifiedBuffers();
173
174         /** redraw \c inset in all the BufferViews in which it is currently
175          *  visible. If successful return a pointer to the owning Buffer.
176          */
177         Buffer const * updateInset(Inset const *);
178
179         /// \return the \c Workarea associated to \p  Buffer
180         /// \retval 0 if no \c WorkArea is found.
181         GuiWorkArea * workArea(Buffer & buffer);
182         /// \return the \c Workarea at index \c index
183         GuiWorkArea * workArea(int index);
184
185         /// Add a \c WorkArea 
186         /// \return the \c Workarea associated to \p  Buffer
187         /// \retval 0 if no \c WorkArea is found.
188         GuiWorkArea * addWorkArea(Buffer & buffer);
189         /// \param work_area The current \c WorkArea, or \c NULL
190         void setCurrentWorkArea(GuiWorkArea * work_area);
191         ///
192         void removeWorkArea(GuiWorkArea * work_area);
193         /// return the current WorkArea (the one that has the focus).
194         GuiWorkArea const * currentWorkArea() const;
195         /// return the current WorkArea (the one that has the focus).
196         GuiWorkArea * currentWorkArea();
197
198         /// return the current document WorkArea (it may not have the focus).
199         GuiWorkArea const * currentMainWorkArea() const;
200         /// return the current document WorkArea (it may not have the focus).
201         GuiWorkArea * currentMainWorkArea();
202
203 Q_SIGNALS:
204         void closing(int);
205         void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
206
207 public Q_SLOTS:
208         ///
209         void setBusy(bool);
210         /// idle timeout.
211         /// clear any temporary message and replace with current status.
212         void clearMessage();
213
214 private Q_SLOTS:
215         ///
216         void updateWindowTitle(GuiWorkArea * wa);
217         ///
218         void resetWindowTitleAndIconText();
219
220         ///
221         void on_currentWorkAreaChanged(GuiWorkArea *);
222         ///
223         void on_lastWorkAreaRemoved();
224
225         /// slots to change the icon size
226         void smallSizedIcons();
227         void normalSizedIcons();
228         void bigSizedIcons();
229
230         /// For completion of autosave or export threads.
231         void processingThreadStarted();
232         void processingThreadFinished();
233         void autoSaveThreadFinished();
234
235         /// must be called in GUI thread
236         void doShowDialog(QString const & qname, QString const & qdata,
237         Inset * inset);
238
239         /// must be called from GUI thread
240         void updateStatusBarMessage(QString const & str);
241         void clearMessageText();
242
243 private:
244         /// Open given child document in current buffer directory.
245         void openChildDocument(std::string const & filename);
246         /// Close current document buffer.
247         bool closeBuffer();
248         /// Close all document buffers.
249         bool closeBufferAll();
250         ///
251         TabWorkArea * addTabWorkArea();
252
253         /// connect to signals in the given BufferView
254         void connectBufferView(BufferView & bv);
255         /// disconnect from signals in the given BufferView
256         void disconnectBufferView();
257         /// connect to signals in the given buffer
258         void connectBuffer(Buffer & buf);
259         /// disconnect from signals in the given buffer
260         void disconnectBuffer();
261         ///
262         void dragEnterEvent(QDragEnterEvent * ev);
263         ///
264         void dropEvent(QDropEvent * ev);
265         /// make sure we quit cleanly
266         void closeEvent(QCloseEvent * e);
267         ///
268         void showEvent(QShowEvent *);
269
270         /// in order to catch Tab key press.
271         bool event(QEvent * e);
272         bool focusNextPrevChild(bool);
273
274         ///
275         bool goToFileRow(std::string const & argument);
276
277         ///
278         struct GuiViewPrivate;
279         GuiViewPrivate & d;
280
281 public:
282         ///
283         /// dialogs for this view
284         ///
285
286         ///
287         void resetDialogs();
288
289         /// Hide all visible dialogs
290         void hideAll() const;
291
292         /// Update all visible dialogs.
293         /** 
294          *  Check the status of all visible dialogs and disable or reenable
295          *  them as appropriate.
296          *
297          *  Disabling is needed for example when a dialog is open and the
298          *  cursor moves to a position where the corresponding inset is not
299          *  allowed.
300          */
301         void updateDialogs();
302
303         /** Show dialog could be called from arbitrary threads.
304             \param name == "bibtex", "citation" etc; an identifier used to
305             launch a particular dialog.
306             \param data is a string representation of the Inset contents.
307             It is often little more than the output from Inset::write.
308             It is passed to, and parsed by, the frontend dialog.
309             Several of these dialogs do not need any data,
310             so it defaults to string().
311             \param inset ownership is _not_ passed to the frontend dialog.
312             It is stored internally and used by the kernel to ascertain
313             what to do with the FuncRequest dispatched from the frontend
314             dialog on 'Apply'; should it be used to create a new inset at
315             the current cursor position or modify an existing, 'open' inset?
316         */
317         void showDialog(std::string const & name,
318                 std::string const & data, Inset * inset = 0);
319
320         /** \param name == "citation", "bibtex" etc; an identifier used
321             to reset the contents of a particular dialog with \param data.
322             See the comments to 'show', above.
323         */
324         void updateDialog(std::string const & name, std::string const & data);
325
326         /** All Dialogs of the given \param name will be closed if they are
327             connected to the given \param inset.
328         */
329         void hideDialog(std::string const & name, Inset * inset);
330         ///
331         void disconnectDialog(std::string const & name);
332
333 private:
334         /// Saves the layout and geometry of the window
335         void saveLayout() const;
336         /// Saves the settings of toolbars and all dialogs
337         void saveUISettings() const;
338         ///
339         bool restoreLayout();
340         ///
341         GuiToolbar * toolbar(std::string const & name);
342         ///
343         void constructToolbars();
344         ///
345         void initToolbars();
346         ///
347         bool lfunUiToggle(std::string const & ui_component);
348         ///
349         void toggleFullScreen();
350         ///
351         void insertLyXFile(docstring const & fname);
352         ///
353         void insertPlaintextFile(docstring const & fname,
354                 bool asParagraph);
355         ///
356         bool exportBufferAs(Buffer & b);
357
358         /// Save a buffer as a new file. 
359         /**
360         Write a buffer to a new file name and rename the buffer
361     according to the new file name.
362
363     This function is e.g. used by menu callbacks and
364     LFUN_BUFFER_WRITE_AS.
365
366     If 'newname' is empty, the user is asked via a
367     dialog for the buffer's new name and location.
368
369     If 'newname' is non-empty and has an absolute path, that is used.
370     Otherwise the base directory of the buffer is used as the base
371     for any relative path in 'newname'.
372         */
373         bool renameBuffer(Buffer & b, docstring const & newname);
374         ///
375         bool saveBuffer(Buffer & b);
376         /// save and rename buffer to fn. If fn is empty, the buffer
377         /// is just saved as the filename it already has.
378         bool saveBuffer(Buffer & b, support::FileName const & fn);
379         /// closes a workarea, if close_buffer is true the buffer will
380         /// also be released, otherwise the buffer will be hidden.
381         bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
382         /// closes the tabworkarea and all tabs. If we are in a close event,
383         /// all buffers will be closed, otherwise they will be hidden.
384         bool closeTabWorkArea(TabWorkArea * twa);
385         /// gives the user the possibility to save his work 
386         /// or to discard the changes. If hiding is true, the
387         /// document will be reloaded.
388         bool saveBufferIfNeeded(Buffer & buf, bool hiding);
389         /// closes all workareas
390         bool closeWorkAreaAll();
391         /// write all open workareas into the session file
392         void writeSession() const;
393         /// is the buffer in this workarea also shown in another tab ?
394         /// This tab can either be in the same view or in another one.
395         bool inMultiTabs(GuiWorkArea * wa);
396         /// is the buffer shown in some other view ?
397         bool inOtherView(Buffer & buf);
398         ///
399         enum NextOrPrevious {
400                 NEXTBUFFER,
401                 PREVBUFFER
402         };
403         ///
404         void gotoNextOrPreviousBuffer(NextOrPrevious np);
405
406         /// Is the dialog currently visible?
407         bool isDialogVisible(std::string const & name) const;
408         ///
409         Dialog * findOrBuild(std::string const & name, bool hide_it);
410         ///
411         Dialog * build(std::string const & name);
412         ///
413         bool reloadBuffer(Buffer & buffer);
414         ///
415         void dispatchVC(FuncRequest const & cmd, DispatchResult & dr);
416         ///
417         void dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr);
418         ///
419         void showMessage();
420
421         /// This view ID.
422         int id_;
423
424         /// flag to avoid two concurrent close events.
425         bool closing_;
426         /// if the view is busy the cursor shouldn't blink for instance.
427         /// This counts the number of times more often we called
428         /// setBusy(true) compared to setBusy(false), so we can nest
429         /// functions that call setBusy;
430         int busy_;
431
432 };
433
434 } // namespace frontend
435 } // namespace lyx
436
437 #endif // GUIVIEW_H