#include "ui_ViewSourceUi.h"
-#include "controllers/Dialog.h"
+#include "DockView.h"
#include "GuiView.h"
#include "qt_helpers.h"
-#include "debug.h"
#include <QDockWidget>
-#include <QWidget>
-#include <QSyntaxHighlighter>
+#include <QString>
#include <QTextCharFormat>
class QTextDocument;
namespace lyx {
namespace frontend {
-class ControlViewSource;
+class GuiViewSource;
class LaTeXHighlighter;
-class GuiViewSourceDialog : public QWidget, public Ui::ViewSourceUi
+class ViewSourceWidget : public QWidget, public Ui::ViewSourceUi
{
Q_OBJECT
public:
- GuiViewSourceDialog(ControlViewSource &);
+ ViewSourceWidget(GuiViewSource &);
public Q_SLOTS:
// update content
void updateView();
- ///
- QTextDocument * document() { return document_; }
- ///
- void update(bool full_source);
private:
///
- ControlViewSource & controller_;
+ GuiViewSource & controller_;
///
QTextDocument * document_;
/// LaTeX syntax highlighter
LaTeXHighlighter * highlighter_;
};
-/**
- * A controller for a read-only text browser.
- */
-class ControlViewSource : public Controller {
+
+class GuiViewSource : public DockView
+{
+ Q_OBJECT
+
public:
- ///
- ControlViewSource(Dialog &);
- /** \param source source code to be displayed
- */
+ GuiViewSource(
+ GuiView & parent, ///< the main window where to dock.
+ Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
+ Qt::WindowFlags flags = 0);
+
+ ~GuiViewSource();
+
+ /// Controller inherited method.
+ ///@{
bool initialiseParams(std::string const & source);
- ///
void clearParams() {}
- ///
void dispatchParams() {}
- ///
bool isBufferDependent() const { return true; }
- ///
bool canApply() const { return true; }
- ///
bool canApplyToReadOnly() const { return true; }
+ void updateView();
+ void enableView(bool enable);
+ void saveSession() const;
+ void restoreSession();
+ ///@}
/// The title displayed by the dialog reflects source type.
- docstring const title() const;
+ QString title() const;
/** get the source code of selected paragraphs, or the whole document
\param fullSource get full source code
*/
- docstring const updateContent(bool fullSource);
- /** get the cursor position in the source code
- */
- std::pair<int, int> getRows() const;
-};
-
+ QString getContent(bool fullSource);
+ // cursor position in the source code
+ struct Row { int begin; int end; };
+ Row getRows() const;
-class GuiViewSource : public QDockWidget, public Dialog
-{
-public:
- GuiViewSource(GuiViewBase & parent)
- : QDockWidget(&parent, Qt::WindowFlags(0)), name_("view-source")
- {
- ControlViewSource * c = new ControlViewSource(*this);
- controller_ = c;
- controller_->setLyXView(parent);
- widget_ = new GuiViewSourceDialog(*c);
- setWidget(widget_);
- setWindowTitle(widget_->windowTitle());
- parent.addDockWidget(Qt::BottomDockWidgetArea, this);
- }
- ~GuiViewSource() { delete widget_; delete controller_; }
-
- /// Dialog inherited methods
- //@{
- void applyView() {}
- void hideView() { QDockWidget::hide(); }
- void showData(std::string const & data)
- {
- controller_->initialiseParams(data);
- showView();
- }
- void showView()
- {
- widget_->updateView(); // make sure its up-to-date
- QDockWidget::show();
- }
- bool isVisibleView() const { return QDockWidget::isVisible(); }
- void checkStatus() { updateView(); }
- void redraw() { redrawView(); }
- void redrawView() {}
- void updateData(std::string const & data)
- {
- controller_->initialiseParams(data);
- updateView();
- }
- void updateView()
- {
- widget_->updateView();
- QDockWidget::update();
- }
- bool isClosing() const { return false; }
- void partialUpdateView(int /*id*/) {}
- Controller & controller() { return *controller_; }
- std::string name() const { return name_; }
- //@}
private:
/// The encapsulated widget.
- GuiViewSourceDialog * widget_;
- Controller * controller_;
- std::string name_;
+ ViewSourceWidget * widget_;
};
} // namespace frontend