2003-02-25 14:51:38 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file Dialog.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-25 14:51:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DIALOG_H
|
|
|
|
#define DIALOG_H
|
|
|
|
|
2005-04-26 09:37:52 +00:00
|
|
|
#include "lfuns.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2008-02-05 15:16:49 +00:00
|
|
|
#include <QString>
|
2007-12-08 13:59:32 +00:00
|
|
|
#include <string>
|
2006-10-09 10:35:14 +00:00
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
class QWidget;
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
2007-09-10 22:32:59 +00:00
|
|
|
|
|
|
|
class Buffer;
|
|
|
|
class BufferView;
|
|
|
|
class FuncRequest;
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
class GuiView;
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2007-09-10 22:32:59 +00:00
|
|
|
/** \enum KernelDocType used to flag the different kinds of buffer
|
|
|
|
* without making the kernel header files available to the
|
|
|
|
* dialog's Controller or View.
|
|
|
|
*/
|
|
|
|
enum KernelDocType
|
|
|
|
{
|
|
|
|
LATEX,
|
|
|
|
LITERATE,
|
|
|
|
DOCBOOK
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-06-28 01:23:11 +00:00
|
|
|
/** \c Dialog collects the different parts of a Model-Controller-View
|
2003-03-14 00:20:42 +00:00
|
|
|
* split of a generic dialog together.
|
|
|
|
*/
|
2007-09-08 21:16:54 +00:00
|
|
|
class Dialog
|
|
|
|
{
|
2003-02-25 14:51:38 +00:00
|
|
|
public:
|
2003-07-16 20:10:59 +00:00
|
|
|
/// \param lv is the access point for the dialog to the LyX kernel.
|
|
|
|
/// \param name is the identifier given to the dialog by its parent
|
|
|
|
/// container.
|
2008-02-05 12:43:19 +00:00
|
|
|
/// \param title is the window title used for decoration.
|
|
|
|
Dialog(GuiView & lv, std::string const & name, QString const & title);
|
2007-11-23 10:45:14 +00:00
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
virtual ~Dialog();
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
virtual QWidget * asQWidget() = 0;
|
|
|
|
virtual QWidget const * asQWidget() const = 0;
|
|
|
|
|
2007-12-10 13:05:00 +00:00
|
|
|
/// Session key.
|
|
|
|
/**
|
|
|
|
* This key must be used for any session setting.
|
|
|
|
**/
|
|
|
|
QString sessionKey() const;
|
|
|
|
|
|
|
|
/// Save session settings.
|
|
|
|
/**
|
|
|
|
* This default implementation saves the geometry state.
|
|
|
|
* Reimplement to save more settings.
|
|
|
|
**/
|
|
|
|
virtual void saveSession() const;
|
|
|
|
|
|
|
|
/// Restore session settings.
|
|
|
|
/**
|
|
|
|
* This default implementation restores the geometry state.
|
|
|
|
* Reimplement to restore more settings.
|
|
|
|
**/
|
|
|
|
virtual void restoreSession();
|
|
|
|
|
2003-07-16 20:10:59 +00:00
|
|
|
/** \name Container Access
|
|
|
|
* These methods are publicly accessible because they are invoked
|
|
|
|
* by the parent container acting on commands from the LyX kernel.
|
2003-03-14 00:20:42 +00:00
|
|
|
*/
|
2003-07-16 20:10:59 +00:00
|
|
|
//@{
|
|
|
|
/// \param data is a string encoding of the data to be displayed.
|
|
|
|
/// It is passed to the Controller to be translated into a useable form.
|
2007-12-09 22:35:04 +00:00
|
|
|
virtual void showData(std::string const & data);
|
|
|
|
virtual void updateData(std::string const & data);
|
2003-02-25 14:51:38 +00:00
|
|
|
//@}
|
|
|
|
|
2007-05-27 04:02:54 +00:00
|
|
|
/** Check whether we may apply our data.
|
2005-04-13 09:43:58 +00:00
|
|
|
*
|
|
|
|
* The buttons are disabled if not and (re-)enabled if yes.
|
|
|
|
*/
|
2007-12-09 22:35:04 +00:00
|
|
|
virtual void checkStatus();
|
2005-04-13 09:43:58 +00:00
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
/** When applying, it's useful to know whether the dialog is about
|
2003-02-25 14:51:38 +00:00
|
|
|
* to close or not (no point refreshing the display for example).
|
|
|
|
*/
|
2007-09-10 22:32:59 +00:00
|
|
|
virtual bool isClosing() const { return false; }
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
/** \c View part
|
|
|
|
* of a Model-Controller-View split of a generic dialog.
|
|
|
|
* These few methods are all that a generic dialog needs of a
|
|
|
|
* view.
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
/** A request to modify the data structures stored by the
|
|
|
|
* accompanying Controller in preparation for their dispatch to
|
|
|
|
* the LyX kernel.
|
|
|
|
*/
|
|
|
|
virtual void applyView() = 0;
|
|
|
|
|
|
|
|
/// Hide the dialog from sight
|
2007-12-09 22:35:04 +00:00
|
|
|
void hideView();
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
/// Create the dialog if necessary, update it and display it.
|
2007-12-09 22:35:04 +00:00
|
|
|
void showView();
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
/// Update the display of the dialog whilst it is still visible.
|
|
|
|
virtual void updateView() = 0;
|
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
// Default Implementation does nothing.
|
|
|
|
// Each dialog has to choose what control to enable or disable.
|
|
|
|
virtual void enableView(bool /*enable*/) {}
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
/// \return true if the dialog is visible.
|
2007-12-09 22:35:04 +00:00
|
|
|
virtual bool isVisibleView() const;
|
2007-09-05 20:33:29 +00:00
|
|
|
//@}
|
|
|
|
|
2007-12-08 13:59:32 +00:00
|
|
|
/// Dialog identifier.
|
|
|
|
/// FIXME for Andre': Now that Dialog is entirely within qt4/
|
|
|
|
/// We can use QString instead in order to avoid <string> inclusion
|
|
|
|
/// or we can pimpl name_.
|
|
|
|
std::string const & name() const;
|
2007-09-10 22:32:59 +00:00
|
|
|
|
2003-07-16 20:10:59 +00:00
|
|
|
//@{
|
|
|
|
/** Enable the controller to initialise its data structures.
|
|
|
|
* \param data is a string encoding of the parameters to be displayed.
|
2003-03-14 00:20:42 +00:00
|
|
|
* \return true if the translation was successful.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
virtual bool initialiseParams(std::string const & data) = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
|
|
|
/// Enable the controller to clean up its data structures.
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual void clearParams() = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
|
|
|
/// Enable the Controller to dispatch its data back to the LyX kernel.
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual void dispatchParams() = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
/** \return true if the dialog should be shown only when
|
2003-07-16 20:10:59 +00:00
|
|
|
* a buffer is open.
|
2003-03-14 00:20:42 +00:00
|
|
|
*/
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual bool isBufferDependent() const = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
2007-07-02 13:54:30 +00:00
|
|
|
/** \return true if the dialog can apply data also
|
|
|
|
* for ReadOnly buffers.
|
|
|
|
* This has to be distinguished from isBufferDependent()
|
|
|
|
*/
|
|
|
|
virtual bool canApplyToReadOnly() const { return false; }
|
|
|
|
|
2005-04-26 09:37:52 +00:00
|
|
|
/** The lfun that is sent for applying the data.
|
|
|
|
*
|
|
|
|
* This method is used by the default implementation of canApply()
|
2007-05-27 04:02:54 +00:00
|
|
|
* for buffer dependent dialogs that send one lfun when applying the
|
2005-04-26 09:37:52 +00:00
|
|
|
* data.
|
|
|
|
* It should be used in dispatchParams(), too for consistency reasons.
|
|
|
|
* \returns the lfun that is sent for applying the data.
|
|
|
|
*/
|
|
|
|
virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
|
|
|
|
|
|
|
|
/** Check whether we may apply our data.
|
|
|
|
*
|
|
|
|
* The default implementation works for all dialogs that send one
|
|
|
|
* lfun when applying the data. Dialogs that send none or more than
|
|
|
|
* one lfun need to reimplement it.
|
|
|
|
* \returns whether the data can be applied or not.
|
|
|
|
*/
|
|
|
|
virtual bool canApply() const;
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
/** \return true if the kernel should disconnect the dialog from
|
|
|
|
* a particular inset after the data has been applied to it.
|
|
|
|
* Clearly this makes sense only for dialogs modifying the contents
|
|
|
|
* of an inset :-)
|
|
|
|
* In practise, only a very few dialogs (e.g. the citation dialog)
|
|
|
|
* return true.
|
|
|
|
*/
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual bool disconnectOnApply() const { return false; }
|
2005-07-28 10:26:33 +00:00
|
|
|
|
|
|
|
/** \return true if Dialog::View::show() should not display the dialog
|
2006-04-05 23:56:29 +00:00
|
|
|
* after running update. Currently, only ControlSpellchecker
|
2005-07-28 10:26:33 +00:00
|
|
|
* makes use of that.
|
|
|
|
*/
|
|
|
|
virtual bool exitEarly() const { return false; }
|
2003-03-14 00:20:42 +00:00
|
|
|
//@}
|
2007-09-10 22:32:59 +00:00
|
|
|
|
|
|
|
/** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
|
|
|
|
* (Ie, it provides an interface to the Model part of the Model-Controller-
|
|
|
|
* View split.
|
|
|
|
* In an ideal world, it will shrink as more info is passed to the
|
|
|
|
* Dialog::show() and Dialog::update() methods.
|
|
|
|
*/
|
2003-03-14 00:20:42 +00:00
|
|
|
|
2007-09-10 22:32:59 +00:00
|
|
|
|
|
|
|
/** This method is the primary purpose of the class. It provides
|
|
|
|
* the "gateway" by which the dialog can send a request (of a
|
|
|
|
* change in the data, for more information) to the kernel.
|
|
|
|
* \param fr is the encoding of the request.
|
|
|
|
*/
|
|
|
|
void dispatch(FuncRequest const & fr) const;
|
|
|
|
|
|
|
|
/** The dialog has received a request from the user
|
|
|
|
* (who pressed the "Restore" button) to update contents.
|
|
|
|
* It must, therefore, ask the kernel to provide this information.
|
|
|
|
* \param name is used to identify the dialog to the kernel.
|
|
|
|
*/
|
2007-11-23 10:45:14 +00:00
|
|
|
void updateDialog() const;
|
2007-09-10 22:32:59 +00:00
|
|
|
|
|
|
|
/** A request from the Controller that future changes to the data
|
|
|
|
* stored by the dialog are not applied to the inset currently
|
|
|
|
* connected to the dialog. Instead, they will be used to generate
|
|
|
|
* a new inset at the cursor position.
|
|
|
|
* \param name is used to identify the dialog to the kernel.
|
|
|
|
*/
|
2007-11-23 10:45:14 +00:00
|
|
|
void disconnect() const;
|
2007-09-10 22:32:59 +00:00
|
|
|
|
|
|
|
/** \name Kernel Wrappers
|
|
|
|
* Simple wrapper functions to Buffer methods.
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
bool isBufferAvailable() const;
|
|
|
|
bool isBufferReadonly() const;
|
|
|
|
std::string const bufferFilepath() const;
|
|
|
|
//@}
|
|
|
|
|
|
|
|
/// The type of the current buffer.
|
|
|
|
KernelDocType docType() const;
|
|
|
|
|
|
|
|
/** \name Kernel Nasties
|
|
|
|
* Unpleasantly public internals of the LyX kernel.
|
|
|
|
* We should aim to reduce/remove these from the interface.
|
|
|
|
*/
|
|
|
|
//@{
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiView & lyxview() { return *lyxview_; }
|
|
|
|
GuiView const & lyxview() const { return *lyxview_; }
|
2007-09-10 22:32:59 +00:00
|
|
|
|
|
|
|
Buffer & buffer();
|
|
|
|
Buffer const & buffer() const;
|
|
|
|
|
|
|
|
BufferView * bufferview();
|
|
|
|
BufferView const * bufferview() const;
|
2003-03-14 00:20:42 +00:00
|
|
|
//@}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2007-10-09 21:21:01 +00:00
|
|
|
protected:
|
2008-02-05 12:43:19 +00:00
|
|
|
///
|
|
|
|
void setTitle(QString const & title) { title_ = title; }
|
|
|
|
///
|
2007-12-09 22:35:04 +00:00
|
|
|
virtual void apply();
|
2007-09-08 21:16:54 +00:00
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
private:
|
2007-11-23 10:45:14 +00:00
|
|
|
/** The Dialog's name is the means by which a dialog identifies
|
|
|
|
* itself to the LyXView.
|
|
|
|
*/
|
2007-12-08 14:24:11 +00:00
|
|
|
std::string const name_;
|
2007-11-23 10:45:14 +00:00
|
|
|
///
|
2008-02-05 12:43:19 +00:00
|
|
|
QString title_;
|
|
|
|
///
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiView * lyxview_;
|
2007-10-09 21:21:01 +00:00
|
|
|
|
|
|
|
/// intentionally unimplemented, therefore uncopiable
|
|
|
|
Dialog(Dialog const &);
|
|
|
|
void operator=(Dialog const &);
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
#endif // DIALOG_H
|