mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
make LyXView almost pure virtual. Merge implementation with GuiView
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21566 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
fec095e310
commit
309232d26b
@ -1,283 +0,0 @@
|
||||
/**
|
||||
* \file LyXView.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Lars Gullik Bjønnes
|
||||
* \author John Levon
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "LyXView.h"
|
||||
|
||||
#include "Dialogs.h"
|
||||
#include "WorkArea.h"
|
||||
#include "Gui.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "buffer_funcs.h"
|
||||
#include "BufferList.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "Cursor.h"
|
||||
#include "debug.h"
|
||||
#include "ErrorList.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "gettext.h"
|
||||
#include "Intl.h"
|
||||
#include "Layout.h"
|
||||
#include "LyX.h"
|
||||
#include "LyXFunc.h"
|
||||
#include "LyXRC.h"
|
||||
#include "MenuBackend.h"
|
||||
#include "Paragraph.h"
|
||||
#include "Session.h"
|
||||
#include "Text.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "support/filetools.h" // OnlyFilename()
|
||||
#include "support/Timeout.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::bformat;
|
||||
using support::FileName;
|
||||
using support::makeDisplayPath;
|
||||
using support::onlyFilename;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
LyXView::LyXView(int id)
|
||||
: autosave_timeout_(new Timeout(5000)),
|
||||
dialogs_(new Dialogs(*this)),
|
||||
id_(id)
|
||||
{
|
||||
// Start autosave timer
|
||||
if (lyxrc.autosave) {
|
||||
autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
|
||||
autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
|
||||
autosave_timeout_->start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LyXView::~LyXView()
|
||||
{
|
||||
delete dialogs_;
|
||||
delete autosave_timeout_;
|
||||
}
|
||||
|
||||
|
||||
Buffer * LyXView::buffer()
|
||||
{
|
||||
WorkArea * work_area = currentWorkArea();
|
||||
if (work_area)
|
||||
return &work_area->bufferView().buffer();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Buffer const * LyXView::buffer() const
|
||||
{
|
||||
WorkArea const * work_area = currentWorkArea();
|
||||
if (work_area)
|
||||
return &work_area->bufferView().buffer();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void LyXView::setBuffer(Buffer * newBuffer)
|
||||
{
|
||||
BOOST_ASSERT(newBuffer);
|
||||
setBusy(true);
|
||||
|
||||
WorkArea * wa = workArea(*newBuffer);
|
||||
if (wa == 0) {
|
||||
updateLabels(*newBuffer->masterBuffer());
|
||||
wa = addWorkArea(*newBuffer);
|
||||
} else {
|
||||
//Disconnect the old buffer...there's no new one.
|
||||
disconnectBuffer();
|
||||
}
|
||||
connectBuffer(*newBuffer);
|
||||
connectBufferView(wa->bufferView());
|
||||
setCurrentWorkArea(wa);
|
||||
|
||||
setBusy(false);
|
||||
}
|
||||
|
||||
|
||||
Buffer * LyXView::loadLyXFile(FileName const & filename, bool tolastfiles)
|
||||
{
|
||||
setBusy(true);
|
||||
|
||||
Buffer * newBuffer = checkAndLoadLyXFile(filename);
|
||||
|
||||
if (!newBuffer) {
|
||||
message(_("Document not loaded."));
|
||||
updateStatusBar();
|
||||
setBusy(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
WorkArea * wa = workArea(*newBuffer);
|
||||
if (wa == 0)
|
||||
wa = addWorkArea(*newBuffer);
|
||||
|
||||
// scroll to the position when the file was last closed
|
||||
if (lyxrc.use_lastfilepos) {
|
||||
LastFilePosSection::FilePos filepos =
|
||||
LyX::ref().session().lastFilePos().load(filename);
|
||||
// if successfully move to pit (returned par_id is not zero),
|
||||
// update metrics and reset font
|
||||
wa->bufferView().moveToPosition(filepos.pit, filepos.pos, 0, 0);
|
||||
}
|
||||
|
||||
if (tolastfiles)
|
||||
LyX::ref().session().lastFiles().add(filename);
|
||||
|
||||
setBusy(false);
|
||||
return newBuffer;
|
||||
}
|
||||
|
||||
|
||||
void LyXView::connectBuffer(Buffer & buf)
|
||||
{
|
||||
buf.setGuiDelegate(this);
|
||||
}
|
||||
|
||||
|
||||
void LyXView::disconnectBuffer()
|
||||
{
|
||||
if (WorkArea * work_area = currentWorkArea())
|
||||
work_area->bufferView().setGuiDelegate(0);
|
||||
}
|
||||
|
||||
|
||||
void LyXView::connectBufferView(BufferView & bv)
|
||||
{
|
||||
bv.setGuiDelegate(this);
|
||||
}
|
||||
|
||||
|
||||
void LyXView::disconnectBufferView()
|
||||
{
|
||||
if (WorkArea * work_area = currentWorkArea())
|
||||
work_area->bufferView().setGuiDelegate(0);
|
||||
}
|
||||
|
||||
|
||||
void LyXView::showErrorList(string const & error_type)
|
||||
{
|
||||
ErrorList & el = buffer()->errorList(error_type);
|
||||
if (!el.empty())
|
||||
getDialogs().show("errorlist", error_type);
|
||||
}
|
||||
|
||||
|
||||
void LyXView::showDialog(string const & name)
|
||||
{
|
||||
getDialogs().show(name);
|
||||
}
|
||||
|
||||
|
||||
void LyXView::showDialogWithData(string const & name, string const & data)
|
||||
{
|
||||
getDialogs().show(name, data);
|
||||
}
|
||||
|
||||
|
||||
void LyXView::showInsetDialog(string const & name, string const & data,
|
||||
Inset * inset)
|
||||
{
|
||||
getDialogs().show(name, data, inset);
|
||||
}
|
||||
|
||||
|
||||
void LyXView::updateDialog(string const & name, string const & data)
|
||||
{
|
||||
if (getDialogs().visible(name))
|
||||
getDialogs().update(name, data);
|
||||
}
|
||||
|
||||
|
||||
BufferView * LyXView::view()
|
||||
{
|
||||
WorkArea * wa = currentWorkArea();
|
||||
return wa? &wa->bufferView() : 0;
|
||||
}
|
||||
|
||||
|
||||
void LyXView::updateToc()
|
||||
{
|
||||
updateDialog("toc", "");
|
||||
}
|
||||
|
||||
|
||||
void LyXView::updateEmbeddedFiles()
|
||||
{
|
||||
updateDialog("embedding", "");
|
||||
}
|
||||
|
||||
|
||||
void LyXView::autoSave()
|
||||
{
|
||||
LYXERR(Debug::INFO) << "Running autoSave()" << endl;
|
||||
|
||||
if (buffer())
|
||||
view()->buffer().autoSave();
|
||||
}
|
||||
|
||||
|
||||
void LyXView::resetAutosaveTimer()
|
||||
{
|
||||
if (lyxrc.autosave)
|
||||
autosave_timeout_->restart();
|
||||
}
|
||||
|
||||
|
||||
void LyXView::dispatch(FuncRequest const & cmd)
|
||||
{
|
||||
string const argument = to_utf8(cmd.argument());
|
||||
switch(cmd.action) {
|
||||
case LFUN_BUFFER_SWITCH:
|
||||
setBuffer(theBufferList().getBuffer(to_utf8(cmd.argument())));
|
||||
break;
|
||||
default:
|
||||
theLyXFunc().setLyXView(this);
|
||||
lyx::dispatch(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Buffer const * LyXView::updateInset(Inset const * inset)
|
||||
{
|
||||
WorkArea * work_area = currentWorkArea();
|
||||
if (!work_area)
|
||||
return 0;
|
||||
|
||||
if (inset) {
|
||||
BOOST_ASSERT(work_area);
|
||||
work_area->scheduleRedraw();
|
||||
}
|
||||
return &work_area->bufferView().buffer();
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
@ -13,9 +13,8 @@
|
||||
#ifndef LYXVIEW_H
|
||||
#define LYXVIEW_H
|
||||
|
||||
#include "frontends/Application.h"
|
||||
#include "frontends/Delegates.h"
|
||||
#include "support/docstring.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -23,12 +22,10 @@ namespace lyx {
|
||||
|
||||
namespace support { class FileName; }
|
||||
|
||||
class Font;
|
||||
class Buffer;
|
||||
class BufferView;
|
||||
class FuncRequest;
|
||||
class Inset;
|
||||
class Timeout;
|
||||
class ToolbarInfo;
|
||||
|
||||
namespace frontend {
|
||||
@ -54,7 +51,7 @@ class LyXView
|
||||
{
|
||||
public:
|
||||
///
|
||||
LyXView(int id);
|
||||
LyXView(int id) : id_(id) {}
|
||||
///
|
||||
virtual ~LyXView();
|
||||
///
|
||||
@ -110,11 +107,13 @@ public:
|
||||
//@{ generic accessor functions
|
||||
|
||||
/// \return the current buffer view.
|
||||
BufferView * view();
|
||||
virtual BufferView * view() = 0;
|
||||
|
||||
/// \return the buffer currently shown in this window
|
||||
Buffer * buffer();
|
||||
Buffer const * buffer() const;
|
||||
virtual Buffer * buffer() = 0;
|
||||
virtual Buffer const * buffer() const = 0;
|
||||
/// set a buffer to the current workarea.
|
||||
virtual void setBuffer(Buffer * b) = 0; ///< \c Buffer to set.
|
||||
|
||||
///
|
||||
virtual void openLayoutList() = 0;
|
||||
@ -125,18 +124,15 @@ public:
|
||||
virtual void openMenu(docstring const & name) = 0;
|
||||
|
||||
/// get access to the dialogs
|
||||
Dialogs & getDialogs() { return *dialogs_; }
|
||||
virtual Dialogs & getDialogs() = 0;
|
||||
///
|
||||
Dialogs const & getDialogs() const { return *dialogs_; }
|
||||
virtual Dialogs const & getDialogs() const = 0;
|
||||
|
||||
//@}
|
||||
|
||||
/// load a buffer into the current workarea.
|
||||
Buffer * loadLyXFile(support::FileName const & name, ///< File to load.
|
||||
bool tolastfiles = true); ///< append to the "Open recent" menu?
|
||||
|
||||
/// set a buffer to the current workarea.
|
||||
void setBuffer(Buffer * b); ///< \c Buffer to set.
|
||||
virtual Buffer * loadLyXFile(support::FileName const & name, ///< File to load.
|
||||
bool tolastfiles = true) = 0; ///< append to the "Open recent" menu?
|
||||
|
||||
/// updates the possible layouts selectable
|
||||
virtual void updateLayoutChoice(bool force) = 0;
|
||||
@ -157,72 +153,58 @@ public:
|
||||
virtual void clearMessage() = 0;
|
||||
|
||||
/// reset autosave timer
|
||||
void resetAutosaveTimer();
|
||||
virtual void resetAutosaveTimer() = 0;
|
||||
|
||||
/// dispatch to current BufferView
|
||||
void dispatch(FuncRequest const & cmd);
|
||||
virtual void dispatch(FuncRequest const & cmd) = 0;
|
||||
|
||||
/** redraw \c inset in all the BufferViews in which it is currently
|
||||
* visible. If successful return a pointer to the owning Buffer.
|
||||
*/
|
||||
Buffer const * updateInset(Inset const *);
|
||||
virtual Buffer const * updateInset(Inset const *) = 0;
|
||||
|
||||
/// returns true if this view has the focus.
|
||||
virtual bool hasFocus() const = 0;
|
||||
|
||||
/// show the error list to the user
|
||||
void showErrorList(std::string const &);
|
||||
virtual void showErrorList(std::string const &) = 0;
|
||||
|
||||
|
||||
//
|
||||
// GuiBufferDelegate
|
||||
//
|
||||
/// This function is called when the buffer structure is changed.
|
||||
void structureChanged() { updateToc(); }
|
||||
virtual void structureChanged() = 0;
|
||||
/// This function is called when some parsing error shows up.
|
||||
void errors(std::string const & err) { showErrorList(err); }
|
||||
/// Reset autosave timers for all users.
|
||||
void resetAutosaveTimers() { resetAutosaveTimer(); }
|
||||
|
||||
/// connect to signals in the given BufferView
|
||||
void connectBufferView(BufferView & bv);
|
||||
virtual void connectBufferView(BufferView & bv) = 0;
|
||||
/// disconnect from signals in the given BufferView
|
||||
void disconnectBufferView();
|
||||
virtual void disconnectBufferView() = 0;
|
||||
/// connect to signals in the given buffer
|
||||
void connectBuffer(Buffer & buf);
|
||||
virtual void connectBuffer(Buffer & buf) = 0;
|
||||
/// disconnect from signals in the given buffer
|
||||
void disconnectBuffer();
|
||||
virtual void disconnectBuffer() = 0;
|
||||
|
||||
private:
|
||||
/// noncopyable
|
||||
LyXView(LyXView const &);
|
||||
void operator=(LyXView const &);
|
||||
|
||||
/// called on timeout
|
||||
void autoSave();
|
||||
|
||||
/// auto-saving of buffers
|
||||
Timeout * const autosave_timeout_;
|
||||
/// dialogs for this view
|
||||
Dialogs * dialogs_;
|
||||
|
||||
/// Bind methods for BufferView messages signal connection
|
||||
//@{
|
||||
void showDialog(std::string const & name);
|
||||
void showDialogWithData(std::string const & name,
|
||||
std::string const & data);
|
||||
void showInsetDialog(std::string const & name,
|
||||
std::string const & data, Inset * inset);
|
||||
void updateDialog(std::string const & name,
|
||||
std::string const & data);
|
||||
virtual void showDialog(std::string const & name) = 0;
|
||||
virtual void showDialogWithData(std::string const & name,
|
||||
std::string const & data) = 0;
|
||||
virtual void showInsetDialog(std::string const & name,
|
||||
std::string const & data, Inset * inset) = 0;
|
||||
virtual void updateDialog(std::string const & name,
|
||||
std::string const & data) = 0;
|
||||
//@}
|
||||
|
||||
protected:
|
||||
///
|
||||
void updateToc();
|
||||
///
|
||||
void updateEmbeddedFiles();
|
||||
|
||||
private:
|
||||
int id_;
|
||||
};
|
||||
|
@ -27,7 +27,6 @@ liblyxfrontends_la_SOURCES = \
|
||||
FontMetrics.h \
|
||||
KeyModifier.h \
|
||||
KeySymbol.h \
|
||||
LyXView.cpp \
|
||||
LyXView.h \
|
||||
Painter.cpp \
|
||||
Painter.h \
|
||||
|
@ -21,6 +21,10 @@
|
||||
#include "GuiMenubar.h"
|
||||
#include "GuiToolbar.h"
|
||||
#include "GuiToolbars.h"
|
||||
#include "Dialogs.h"
|
||||
#include "WorkArea.h"
|
||||
#include "Gui.h"
|
||||
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "frontends/Application.h"
|
||||
@ -33,24 +37,33 @@
|
||||
#include "support/lstrings.h"
|
||||
#include "support/os.h"
|
||||
|
||||
#include "buffer_funcs.h"
|
||||
#include "Buffer.h"
|
||||
#include "BufferList.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "BufferList.h"
|
||||
#include "Cursor.h"
|
||||
#include "debug.h"
|
||||
#include "ErrorList.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "gettext.h"
|
||||
#include "Intl.h"
|
||||
#include "Layout.h"
|
||||
#include "LyX.h"
|
||||
#include "LyXFunc.h"
|
||||
#include "LyX.h"
|
||||
#include "LyXRC.h"
|
||||
#include "MenuBackend.h"
|
||||
#include "Paragraph.h"
|
||||
#include "Session.h"
|
||||
#include "TextClass.h"
|
||||
#include "Text.h"
|
||||
#include "ToolbarBackend.h"
|
||||
#include "version.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "support/filetools.h" // OnlyFilename()
|
||||
#include "support/Timeout.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QCloseEvent>
|
||||
@ -68,8 +81,16 @@
|
||||
#include <QToolBar>
|
||||
#include <QUrl>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/current_function.hpp>
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
using std::endl;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@ -80,6 +101,11 @@ extern bool quitting;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
using support::bformat;
|
||||
using support::FileName;
|
||||
using support::makeDisplayPath;
|
||||
using support::onlyFilename;
|
||||
|
||||
namespace {
|
||||
|
||||
int const statusbar_timer_value = 3000;
|
||||
@ -126,22 +152,6 @@ private:
|
||||
|
||||
struct GuiView::GuiViewPrivate
|
||||
{
|
||||
string cur_title;
|
||||
|
||||
int posx_offset;
|
||||
int posy_offset;
|
||||
|
||||
GuiWorkArea * current_work_area_;
|
||||
QSplitter * splitter_;
|
||||
QStackedWidget * stack_widget_;
|
||||
BackgroundWidget * bg_widget_;
|
||||
/// view's menubar
|
||||
GuiMenubar * menubar_;
|
||||
/// view's toolbars
|
||||
GuiToolbars * toolbars_;
|
||||
///
|
||||
docstring current_layout;
|
||||
|
||||
GuiViewPrivate()
|
||||
: current_work_area_(0), posx_offset(0), posy_offset(0)
|
||||
{}
|
||||
@ -170,19 +180,22 @@ struct GuiView::GuiViewPrivate
|
||||
QAction * smallIcons = new QAction(iconSizeGroup);
|
||||
smallIcons->setText(qt_("Small-sized icons"));
|
||||
smallIcons->setCheckable(true);
|
||||
QObject::connect(smallIcons, SIGNAL(triggered()), parent, SLOT(smallSizedIcons()));
|
||||
QObject::connect(smallIcons, SIGNAL(triggered()),
|
||||
parent, SLOT(smallSizedIcons()));
|
||||
menu->addAction(smallIcons);
|
||||
|
||||
QAction * normalIcons = new QAction(iconSizeGroup);
|
||||
normalIcons->setText(qt_("Normal-sized icons"));
|
||||
normalIcons->setCheckable(true);
|
||||
QObject::connect(normalIcons, SIGNAL(triggered()), parent, SLOT(normalSizedIcons()));
|
||||
QObject::connect(normalIcons, SIGNAL(triggered()),
|
||||
parent, SLOT(normalSizedIcons()));
|
||||
menu->addAction(normalIcons);
|
||||
|
||||
QAction * bigIcons = new QAction(iconSizeGroup);
|
||||
bigIcons->setText(qt_("Big-sized icons"));
|
||||
bigIcons->setCheckable(true);
|
||||
QObject::connect(bigIcons, SIGNAL(triggered()), parent, SLOT(bigSizedIcons()));
|
||||
QObject::connect(bigIcons, SIGNAL(triggered()),
|
||||
parent, SLOT(bigSizedIcons()));
|
||||
menu->addAction(bigIcons);
|
||||
|
||||
unsigned int cur = parent->iconSize().width();
|
||||
@ -233,16 +246,48 @@ struct GuiView::GuiViewPrivate
|
||||
|
||||
return tab_widget;
|
||||
}
|
||||
|
||||
public:
|
||||
///
|
||||
string cur_title;
|
||||
|
||||
GuiWorkArea * current_work_area_;
|
||||
int posx_offset;
|
||||
int posy_offset;
|
||||
|
||||
QSplitter * splitter_;
|
||||
QStackedWidget * stack_widget_;
|
||||
BackgroundWidget * bg_widget_;
|
||||
/// view's menubar
|
||||
GuiMenubar * menubar_;
|
||||
/// view's toolbars
|
||||
GuiToolbars * toolbars_;
|
||||
///
|
||||
docstring current_layout;
|
||||
};
|
||||
|
||||
|
||||
unsigned int GuiView::GuiViewPrivate::lastIconSize = 0;
|
||||
|
||||
|
||||
/// FIXME
|
||||
LyXView::~LyXView() {}
|
||||
|
||||
|
||||
GuiView::GuiView(int id)
|
||||
: QMainWindow(), LyXView(id), quitting_by_menu_(false),
|
||||
d(*new GuiViewPrivate)
|
||||
: QMainWindow(), LyXView(id),
|
||||
d(*new GuiViewPrivate),
|
||||
quitting_by_menu_(false),
|
||||
autosave_timeout_(new Timeout(5000)),
|
||||
dialogs_(new Dialogs(*this))
|
||||
{
|
||||
// Start autosave timer
|
||||
if (lyxrc.autosave) {
|
||||
autosave_timeout_->timeout.connect(boost::bind(&GuiView::autoSave, this));
|
||||
autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
|
||||
autosave_timeout_->start();
|
||||
}
|
||||
|
||||
// Qt bug? signal lastWindowClosed does not work
|
||||
setAttribute(Qt::WA_QuitOnClose, false);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
@ -275,6 +320,8 @@ GuiView::GuiView(int id)
|
||||
|
||||
GuiView::~GuiView()
|
||||
{
|
||||
delete dialogs_;
|
||||
delete autosave_timeout_;
|
||||
delete &d;
|
||||
}
|
||||
|
||||
@ -1024,6 +1071,201 @@ void GuiView::toggleToolbarState(string const & name, bool allowauto)
|
||||
}
|
||||
|
||||
|
||||
Buffer * GuiView::buffer()
|
||||
{
|
||||
WorkArea * work_area = currentWorkArea();
|
||||
if (work_area)
|
||||
return &work_area->bufferView().buffer();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Buffer const * GuiView::buffer() const
|
||||
{
|
||||
WorkArea const * work_area = currentWorkArea();
|
||||
if (work_area)
|
||||
return &work_area->bufferView().buffer();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void GuiView::setBuffer(Buffer * newBuffer)
|
||||
{
|
||||
BOOST_ASSERT(newBuffer);
|
||||
setBusy(true);
|
||||
|
||||
WorkArea * wa = workArea(*newBuffer);
|
||||
if (wa == 0) {
|
||||
updateLabels(*newBuffer->masterBuffer());
|
||||
wa = addWorkArea(*newBuffer);
|
||||
} else {
|
||||
//Disconnect the old buffer...there's no new one.
|
||||
disconnectBuffer();
|
||||
}
|
||||
connectBuffer(*newBuffer);
|
||||
connectBufferView(wa->bufferView());
|
||||
setCurrentWorkArea(wa);
|
||||
|
||||
setBusy(false);
|
||||
}
|
||||
|
||||
|
||||
Buffer * GuiView::loadLyXFile(FileName const & filename, bool tolastfiles)
|
||||
{
|
||||
setBusy(true);
|
||||
|
||||
Buffer * newBuffer = checkAndLoadLyXFile(filename);
|
||||
|
||||
if (!newBuffer) {
|
||||
message(_("Document not loaded."));
|
||||
updateStatusBar();
|
||||
setBusy(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
WorkArea * wa = workArea(*newBuffer);
|
||||
if (wa == 0)
|
||||
wa = addWorkArea(*newBuffer);
|
||||
|
||||
// scroll to the position when the file was last closed
|
||||
if (lyxrc.use_lastfilepos) {
|
||||
LastFilePosSection::FilePos filepos =
|
||||
LyX::ref().session().lastFilePos().load(filename);
|
||||
// if successfully move to pit (returned par_id is not zero),
|
||||
// update metrics and reset font
|
||||
wa->bufferView().moveToPosition(filepos.pit, filepos.pos, 0, 0);
|
||||
}
|
||||
|
||||
if (tolastfiles)
|
||||
LyX::ref().session().lastFiles().add(filename);
|
||||
|
||||
setBusy(false);
|
||||
return newBuffer;
|
||||
}
|
||||
|
||||
|
||||
void GuiView::connectBuffer(Buffer & buf)
|
||||
{
|
||||
buf.setGuiDelegate(this);
|
||||
}
|
||||
|
||||
|
||||
void GuiView::disconnectBuffer()
|
||||
{
|
||||
if (WorkArea * work_area = currentWorkArea())
|
||||
work_area->bufferView().setGuiDelegate(0);
|
||||
}
|
||||
|
||||
|
||||
void GuiView::connectBufferView(BufferView & bv)
|
||||
{
|
||||
bv.setGuiDelegate(this);
|
||||
}
|
||||
|
||||
|
||||
void GuiView::disconnectBufferView()
|
||||
{
|
||||
if (WorkArea * work_area = currentWorkArea())
|
||||
work_area->bufferView().setGuiDelegate(0);
|
||||
}
|
||||
|
||||
|
||||
void GuiView::showErrorList(string const & error_type)
|
||||
{
|
||||
ErrorList & el = buffer()->errorList(error_type);
|
||||
if (!el.empty())
|
||||
getDialogs().show("errorlist", error_type);
|
||||
}
|
||||
|
||||
|
||||
void GuiView::showDialog(string const & name)
|
||||
{
|
||||
getDialogs().show(name);
|
||||
}
|
||||
|
||||
|
||||
void GuiView::showDialogWithData(string const & name, string const & data)
|
||||
{
|
||||
getDialogs().show(name, data);
|
||||
}
|
||||
|
||||
|
||||
void GuiView::showInsetDialog(string const & name, string const & data,
|
||||
Inset * inset)
|
||||
{
|
||||
getDialogs().show(name, data, inset);
|
||||
}
|
||||
|
||||
|
||||
void GuiView::updateDialog(string const & name, string const & data)
|
||||
{
|
||||
if (getDialogs().visible(name))
|
||||
getDialogs().update(name, data);
|
||||
}
|
||||
|
||||
|
||||
BufferView * GuiView::view()
|
||||
{
|
||||
WorkArea * wa = currentWorkArea();
|
||||
return wa ? &wa->bufferView() : 0;
|
||||
}
|
||||
|
||||
|
||||
void GuiView::updateToc()
|
||||
{
|
||||
updateDialog("toc", "");
|
||||
}
|
||||
|
||||
|
||||
void GuiView::updateEmbeddedFiles()
|
||||
{
|
||||
updateDialog("embedding", "");
|
||||
}
|
||||
|
||||
|
||||
void GuiView::autoSave()
|
||||
{
|
||||
LYXERR(Debug::INFO) << "Running autoSave()" << endl;
|
||||
|
||||
if (buffer())
|
||||
view()->buffer().autoSave();
|
||||
}
|
||||
|
||||
|
||||
void GuiView::resetAutosaveTimer()
|
||||
{
|
||||
if (lyxrc.autosave)
|
||||
autosave_timeout_->restart();
|
||||
}
|
||||
|
||||
|
||||
void GuiView::dispatch(FuncRequest const & cmd)
|
||||
{
|
||||
string const argument = to_utf8(cmd.argument());
|
||||
switch(cmd.action) {
|
||||
case LFUN_BUFFER_SWITCH:
|
||||
setBuffer(theBufferList().getBuffer(to_utf8(cmd.argument())));
|
||||
break;
|
||||
default:
|
||||
theLyXFunc().setLyXView(this);
|
||||
lyx::dispatch(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Buffer const * GuiView::updateInset(Inset const * inset)
|
||||
{
|
||||
WorkArea * work_area = currentWorkArea();
|
||||
if (!work_area)
|
||||
return 0;
|
||||
|
||||
if (inset) {
|
||||
BOOST_ASSERT(work_area);
|
||||
work_area->scheduleRedraw();
|
||||
}
|
||||
return &work_area->bufferView().buffer();
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -16,20 +16,20 @@
|
||||
#define GUI_VIEW_H
|
||||
|
||||
#include "frontends/LyXView.h"
|
||||
#include "FuncRequest.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QCloseEvent>
|
||||
#include <QMainWindow>
|
||||
#include <QTabWidget>
|
||||
#include <QTimer>
|
||||
|
||||
class QCloseEvent;
|
||||
class QDragEnterEvent;
|
||||
class QDropEvent;
|
||||
class QMenu;
|
||||
class QToolBar;
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
class Timeout;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
class GuiToolbar;
|
||||
@ -88,10 +88,21 @@ public:
|
||||
/// menu item has been selected
|
||||
void activated(FuncRequest const &);
|
||||
|
||||
QMenu* createPopupMenu();
|
||||
///
|
||||
QMenu * createPopupMenu();
|
||||
|
||||
///
|
||||
void addTabWorkArea();
|
||||
|
||||
/// dispatch to current BufferView
|
||||
void dispatch(FuncRequest const & cmd);
|
||||
|
||||
/// \return the buffer currently shown in this window
|
||||
Buffer * buffer();
|
||||
Buffer const * buffer() const;
|
||||
/// set a buffer to the current workarea.
|
||||
void setBuffer(Buffer * b); ///< \c Buffer to set.
|
||||
|
||||
Q_SIGNALS:
|
||||
void closing(int);
|
||||
|
||||
@ -110,7 +121,7 @@ public Q_SLOTS:
|
||||
void normalSizedIcons();
|
||||
void bigSizedIcons();
|
||||
|
||||
protected:
|
||||
private:
|
||||
/// make sure we quit cleanly
|
||||
virtual void closeEvent(QCloseEvent * e);
|
||||
///
|
||||
@ -131,7 +142,32 @@ protected:
|
||||
WorkArea const * currentWorkArea() const;
|
||||
WorkArea * currentWorkArea();
|
||||
|
||||
private:
|
||||
///
|
||||
void resetAutosaveTimer();
|
||||
///
|
||||
void showErrorList(std::string const & error_type);
|
||||
///
|
||||
void structureChanged() { updateToc(); }
|
||||
///
|
||||
void connectBuffer(Buffer & buf);
|
||||
///
|
||||
void disconnectBuffer();
|
||||
///
|
||||
void connectBufferView(BufferView & bv);
|
||||
///
|
||||
void disconnectBufferView();
|
||||
////
|
||||
void showDialog(std::string const & name);
|
||||
void showDialogWithData(std::string const & name,
|
||||
std::string const & data);
|
||||
void showInsetDialog(std::string const & name,
|
||||
std::string const & data, Inset * inset);
|
||||
void updateDialog(std::string const & name,
|
||||
std::string const & data);
|
||||
|
||||
///
|
||||
void updateToc();
|
||||
|
||||
///
|
||||
void dragEnterEvent(QDragEnterEvent * ev);
|
||||
///
|
||||
@ -142,6 +178,30 @@ private:
|
||||
bool focusNextPrevChild(bool);
|
||||
///
|
||||
QRect updateFloatingGeometry();
|
||||
/// called on timeout
|
||||
void autoSave();
|
||||
///
|
||||
void updateEmbeddedFiles();
|
||||
|
||||
/// \return the current buffer view.
|
||||
BufferView * view();
|
||||
|
||||
/// get access to the dialogs
|
||||
Dialogs & getDialogs() { return *dialogs_; }
|
||||
///
|
||||
Dialogs const & getDialogs() const { return *dialogs_; }
|
||||
|
||||
//@}
|
||||
|
||||
/// load a buffer into the current workarea.
|
||||
Buffer * loadLyXFile(support::FileName const & name, ///< File to load.
|
||||
bool tolastfiles = true); ///< append to the "Open recent" menu?
|
||||
|
||||
/** redraw \c inset in all the BufferViews in which it is currently
|
||||
* visible. If successful return a pointer to the owning Buffer.
|
||||
*/
|
||||
Buffer const * updateInset(Inset const *);
|
||||
|
||||
|
||||
private:
|
||||
///
|
||||
@ -167,6 +227,11 @@ private:
|
||||
};
|
||||
|
||||
ToolbarSize toolbarSize_;
|
||||
|
||||
/// auto-saving of buffers
|
||||
Timeout * const autosave_timeout_;
|
||||
/// dialogs for this view
|
||||
Dialogs * dialogs_;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user