2002-06-12 02:54:19 +00:00
|
|
|
|
/**
|
2007-04-26 04:02:55 +00:00
|
|
|
|
* \file LyXView.cpp
|
2002-09-05 15:14:23 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-11-27 10:30:28 +00:00
|
|
|
|
* \author John Levon
|
2002-09-05 14:10:50 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-12 02:54:19 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2002-06-12 02:54:19 +00:00
|
|
|
|
#include "LyXView.h"
|
2007-08-14 09:54:59 +00:00
|
|
|
|
|
2003-09-05 10:55:42 +00:00
|
|
|
|
#include "Dialogs.h"
|
2006-07-03 22:31:51 +00:00
|
|
|
|
#include "WorkArea.h"
|
2006-12-02 17:39:31 +00:00
|
|
|
|
#include "Gui.h"
|
2003-09-05 10:55:42 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
2007-06-19 14:56:52 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2007-06-04 14:09:51 +00:00
|
|
|
|
#include "BufferList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "BufferParams.h"
|
2003-09-05 10:55:42 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "ErrorList.h"
|
|
|
|
|
#include "FuncRequest.h"
|
2003-09-05 10:55:42 +00:00
|
|
|
|
#include "gettext.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Intl.h"
|
2007-09-29 20:02:32 +00:00
|
|
|
|
#include "Layout.h"
|
2007-06-19 14:56:52 +00:00
|
|
|
|
#include "LyX.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXFunc.h"
|
|
|
|
|
#include "LyXRC.h"
|
2000-09-14 17:53:12 +00:00
|
|
|
|
#include "MenuBackend.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Paragraph.h"
|
2007-10-01 21:36:35 +00:00
|
|
|
|
#include "Session.h"
|
|
|
|
|
#include "Text.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2006-07-14 21:47:48 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2002-06-12 02:54:19 +00:00
|
|
|
|
#include "support/filetools.h" // OnlyFilename()
|
2007-08-11 22:37:09 +00:00
|
|
|
|
#include "support/Timeout.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2005-04-26 10:30:24 +00:00
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
|
# include <sys/time.h>
|
|
|
|
|
#endif
|
2005-01-19 15:26:41 +00:00
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2005-01-20 15:38:14 +00:00
|
|
|
|
# include <unistd.h>
|
2005-01-19 15:26:41 +00:00
|
|
|
|
#endif
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2007-08-14 09:54:59 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
2006-12-02 16:07:15 +00:00
|
|
|
|
using support::bformat;
|
|
|
|
|
using support::FileName;
|
|
|
|
|
using support::makeDisplayPath;
|
|
|
|
|
using support::onlyFilename;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
|
2007-08-14 09:54:59 +00:00
|
|
|
|
namespace frontend {
|
2003-09-05 10:55:42 +00:00
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
|
LyXView::LyXView(int id)
|
2007-10-01 20:45:50 +00:00
|
|
|
|
: autosave_timeout_(new Timeout(5000)),
|
2002-08-15 17:48:53 +00:00
|
|
|
|
dialogs_(new Dialogs(*this)),
|
2007-08-23 13:20:01 +00:00
|
|
|
|
id_(id)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-09-29 23:10:17 +00:00
|
|
|
|
// Start autosave timer
|
|
|
|
|
if (lyxrc.autosave) {
|
|
|
|
|
autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
|
|
|
|
|
autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
|
|
|
|
|
autosave_timeout_->start();
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-19 13:36:20 +00:00
|
|
|
|
|
2006-07-08 20:24:32 +00:00
|
|
|
|
LyXView::~LyXView()
|
|
|
|
|
{
|
2007-09-19 21:28:11 +00:00
|
|
|
|
delete dialogs_;
|
|
|
|
|
delete autosave_timeout_;
|
2006-07-08 20:24:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Buffer * LyXView::buffer()
|
2006-06-26 16:55:35 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
WorkArea * work_area = currentWorkArea();
|
|
|
|
|
if (work_area)
|
2007-08-21 13:03:55 +00:00
|
|
|
|
return &work_area->bufferView().buffer();
|
2007-08-21 07:33:46 +00:00
|
|
|
|
return 0;
|
2006-06-26 16:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Buffer const * LyXView::buffer() const
|
2007-01-05 13:31:34 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
WorkArea const * work_area = currentWorkArea();
|
|
|
|
|
if (work_area)
|
2007-08-21 13:03:55 +00:00
|
|
|
|
return &work_area->bufferView().buffer();
|
2007-08-21 07:33:46 +00:00
|
|
|
|
return 0;
|
2007-01-05 13:31:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
void LyXView::setBuffer(Buffer * newBuffer)
|
2006-07-13 16:37:55 +00:00
|
|
|
|
{
|
2007-08-22 08:48:01 +00:00
|
|
|
|
BOOST_ASSERT(newBuffer);
|
2007-10-23 21:41:17 +00:00
|
|
|
|
setBusy(true);
|
2006-10-26 13:29:10 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
WorkArea * wa = workArea(*newBuffer);
|
|
|
|
|
if (wa == 0) {
|
2007-10-20 10:03:45 +00:00
|
|
|
|
updateLabels(*newBuffer->masterBuffer());
|
2007-08-21 07:33:46 +00:00
|
|
|
|
wa = addWorkArea(*newBuffer);
|
2007-09-11 21:27:57 +00:00
|
|
|
|
} else {
|
2007-08-03 14:07:39 +00:00
|
|
|
|
//Disconnect the old buffer...there's no new one.
|
|
|
|
|
disconnectBuffer();
|
2007-09-11 21:27:57 +00:00
|
|
|
|
}
|
2007-08-21 07:33:46 +00:00
|
|
|
|
connectBuffer(*newBuffer);
|
|
|
|
|
connectBufferView(wa->bufferView());
|
|
|
|
|
setCurrentWorkArea(wa);
|
2006-08-17 21:46:52 +00:00
|
|
|
|
|
2007-10-23 21:41:17 +00:00
|
|
|
|
setBusy(false);
|
2006-07-13 16:37:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Buffer * LyXView::loadLyXFile(FileName const & filename, bool tolastfiles)
|
2006-07-13 16:37:55 +00:00
|
|
|
|
{
|
2007-10-23 21:41:17 +00:00
|
|
|
|
setBusy(true);
|
2007-06-19 14:56:52 +00:00
|
|
|
|
|
2007-06-19 16:03:47 +00:00
|
|
|
|
Buffer * newBuffer = checkAndLoadLyXFile(filename);
|
2007-06-19 14:56:52 +00:00
|
|
|
|
|
2007-06-19 16:03:47 +00:00
|
|
|
|
if (!newBuffer) {
|
2007-06-19 14:56:52 +00:00
|
|
|
|
message(_("Document not loaded."));
|
2007-06-19 16:03:47 +00:00
|
|
|
|
updateStatusBar();
|
2007-10-23 21:41:17 +00:00
|
|
|
|
setBusy(false);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
return 0;
|
2007-06-19 16:03:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-24 07:19:40 +00:00
|
|
|
|
WorkArea * wa = workArea(*newBuffer);
|
|
|
|
|
if (wa == 0)
|
|
|
|
|
wa = addWorkArea(*newBuffer);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
|
|
|
|
// scroll to the position when the file was last closed
|
|
|
|
|
if (lyxrc.use_lastfilepos) {
|
2007-11-02 19:59:08 +00:00
|
|
|
|
LastFilePosSection::FilePos filepos =
|
|
|
|
|
LyX::ref().session().lastFilePos().load(filename);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
// if successfully move to pit (returned par_id is not zero),
|
|
|
|
|
// update metrics and reset font
|
2007-11-02 19:59:08 +00:00
|
|
|
|
wa->bufferView().moveToPosition(filepos.pit, filepos.pos, 0, 0);
|
2007-06-19 16:03:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-22 09:04:31 +00:00
|
|
|
|
if (tolastfiles)
|
|
|
|
|
LyX::ref().session().lastFiles().add(filename);
|
|
|
|
|
|
2007-10-23 21:41:17 +00:00
|
|
|
|
setBusy(false);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
return newBuffer;
|
2006-07-13 16:37:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-14 21:47:48 +00:00
|
|
|
|
|
|
|
|
|
void LyXView::connectBuffer(Buffer & buf)
|
|
|
|
|
{
|
2007-10-02 18:27:20 +00:00
|
|
|
|
buf.setGuiDelegate(this);
|
2006-07-14 21:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::disconnectBuffer()
|
|
|
|
|
{
|
2007-10-02 18:27:20 +00:00
|
|
|
|
if (WorkArea * work_area = currentWorkArea())
|
|
|
|
|
work_area->bufferView().setGuiDelegate(0);
|
2006-07-14 21:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-19 13:36:20 +00:00
|
|
|
|
void LyXView::connectBufferView(BufferView & bv)
|
|
|
|
|
{
|
2007-10-02 18:27:20 +00:00
|
|
|
|
bv.setGuiDelegate(this);
|
2006-09-19 13:36:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::disconnectBufferView()
|
|
|
|
|
{
|
2007-10-02 18:27:20 +00:00
|
|
|
|
if (WorkArea * work_area = currentWorkArea())
|
|
|
|
|
work_area->bufferView().setGuiDelegate(0);
|
2006-09-19 13:36:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-08-13 16:16:43 +00:00
|
|
|
|
void LyXView::showErrorList(string const & error_type)
|
2006-07-14 21:47:48 +00:00
|
|
|
|
{
|
2006-08-13 16:16:43 +00:00
|
|
|
|
ErrorList & el = buffer()->errorList(error_type);
|
2007-10-02 18:27:20 +00:00
|
|
|
|
if (!el.empty())
|
2006-08-13 16:16:43 +00:00
|
|
|
|
getDialogs().show("errorlist", error_type);
|
2006-07-14 21:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-19 13:36:20 +00:00
|
|
|
|
void LyXView::showDialog(string const & name)
|
|
|
|
|
{
|
|
|
|
|
getDialogs().show(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-18 08:44:44 +00:00
|
|
|
|
void LyXView::showDialogWithData(string const & name, string const & data)
|
2006-09-19 13:36:20 +00:00
|
|
|
|
{
|
|
|
|
|
getDialogs().show(name, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::showInsetDialog(string const & name, string const & data,
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * inset)
|
2006-09-19 13:36:20 +00:00
|
|
|
|
{
|
2006-10-02 15:40:39 +00:00
|
|
|
|
getDialogs().show(name, data, inset);
|
2006-09-19 13:36:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::updateDialog(string const & name, string const & data)
|
|
|
|
|
{
|
|
|
|
|
if (getDialogs().visible(name))
|
|
|
|
|
getDialogs().update(name, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-23 21:41:17 +00:00
|
|
|
|
void LyXView::setReadOnly(bool)
|
2006-07-14 21:47:48 +00:00
|
|
|
|
{
|
|
|
|
|
updateWindowTitle();
|
|
|
|
|
getDialogs().updateBufferDependent(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
BufferView * LyXView::view()
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
WorkArea * wa = currentWorkArea();
|
|
|
|
|
return wa? &wa->bufferView() : 0;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-03-12 11:23:41 +00:00
|
|
|
|
void LyXView::updateToc()
|
|
|
|
|
{
|
|
|
|
|
updateDialog("toc", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-04 14:34:42 +00:00
|
|
|
|
void LyXView::updateEmbeddedFiles()
|
|
|
|
|
{
|
|
|
|
|
updateDialog("embedding", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-12 11:34:13 +00:00
|
|
|
|
void LyXView::autoSave()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::INFO) << "Running autoSave()" << endl;
|
2002-06-12 11:34:13 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (buffer())
|
2007-10-03 11:00:18 +00:00
|
|
|
|
view()->buffer().autoSave();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
void LyXView::resetAutosaveTimer()
|
|
|
|
|
{
|
2000-03-12 10:35:05 +00:00
|
|
|
|
if (lyxrc.autosave)
|
2002-06-12 02:54:19 +00:00
|
|
|
|
autosave_timeout_->restart();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
|
void LyXView::updateWindowTitle()
|
|
|
|
|
{
|
2007-09-11 21:27:57 +00:00
|
|
|
|
docstring maximize_title = from_ascii("LyX");
|
|
|
|
|
docstring minimize_title = from_ascii("LyX");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Buffer * buf = buffer();
|
|
|
|
|
if (buf) {
|
2007-10-20 10:03:45 +00:00
|
|
|
|
string const cur_title = buf->absFileName();
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (!cur_title.empty()) {
|
2006-10-11 19:40:50 +00:00
|
|
|
|
maximize_title += ": " + makeDisplayPath(cur_title, 30);
|
2006-09-11 08:54:10 +00:00
|
|
|
|
minimize_title = lyx::from_utf8(onlyFilename(cur_title));
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (!buf->isClean()) {
|
2006-09-11 08:54:10 +00:00
|
|
|
|
maximize_title += _(" (changed)");
|
2007-09-11 21:27:57 +00:00
|
|
|
|
minimize_title += char_type('*');
|
2002-09-11 18:05:42 +00:00
|
|
|
|
}
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (buf->isReadonly())
|
2006-09-11 08:54:10 +00:00
|
|
|
|
maximize_title += _(" (read only)");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-06-12 02:54:19 +00:00
|
|
|
|
|
2006-11-05 15:34:18 +00:00
|
|
|
|
setWindowTitle(maximize_title, minimize_title);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-15 17:34:44 +00:00
|
|
|
|
void LyXView::dispatch(FuncRequest const & cmd)
|
2002-08-13 17:43:40 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2002-08-13 17:43:40 +00:00
|
|
|
|
}
|
2003-10-14 21:30:23 +00:00
|
|
|
|
|
|
|
|
|
|
2007-09-16 10:36:57 +00:00
|
|
|
|
Buffer const * LyXView::updateInset(Inset const * inset)
|
2003-10-14 21:30:23 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
WorkArea * work_area = currentWorkArea();
|
|
|
|
|
if (!work_area)
|
|
|
|
|
return 0;
|
2007-01-16 15:16:09 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (inset) {
|
|
|
|
|
BOOST_ASSERT(work_area);
|
|
|
|
|
work_area->scheduleRedraw();
|
2003-10-14 21:30:23 +00:00
|
|
|
|
}
|
2007-08-21 13:03:55 +00:00
|
|
|
|
return &work_area->bufferView().buffer();
|
2003-10-14 21:30:23 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2007-08-14 09:54:59 +00:00
|
|
|
|
} // namespace frontend
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|