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