2002-06-12 02:54:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file LyXView.C
|
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"
|
2003-09-05 10:55:42 +00:00
|
|
|
|
#include "Dialogs.h"
|
|
|
|
|
#include "Timeout.h"
|
|
|
|
|
#include "Toolbar.h"
|
|
|
|
|
#include "Menubar.h"
|
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2003-09-05 10:55:42 +00:00
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "bufferview_funcs.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
2003-09-05 10:55:42 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "intl.h"
|
2003-09-05 10:55:42 +00:00
|
|
|
|
#include "lyx_cb.h"
|
|
|
|
|
#include "lyxfunc.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "lyxtext.h"
|
2000-09-14 17:53:12 +00:00
|
|
|
|
#include "MenuBackend.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-07-19 20:56:31 +00:00
|
|
|
|
#include "controllers/ControlCommandBuffer.h"
|
2003-09-05 10:55:42 +00:00
|
|
|
|
|
2003-04-10 14:08:06 +00:00
|
|
|
|
#include "mathed/math_cursor.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2002-06-12 02:54:19 +00:00
|
|
|
|
#include "support/filetools.h" // OnlyFilename()
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::MakeDisplayPath;
|
|
|
|
|
using lyx::support::OnlyFilename;
|
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
|
2003-09-05 10:55:42 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
string current_layout;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
|
LyXView::LyXView()
|
2002-08-14 09:52:30 +00:00
|
|
|
|
: intl_(new Intl),
|
2002-08-13 14:40:38 +00:00
|
|
|
|
autosave_timeout_(new Timeout(5000)),
|
|
|
|
|
lyxfunc_(new LyXFunc(this)),
|
2002-08-15 17:48:53 +00:00
|
|
|
|
dialogs_(new Dialogs(*this)),
|
2003-04-02 09:23:24 +00:00
|
|
|
|
controlcommand_(new ControlCommandBuffer(*this))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXView::~LyXView()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
|
|
2002-06-12 11:34:13 +00:00
|
|
|
|
void LyXView::init()
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2002-06-12 11:34:13 +00:00
|
|
|
|
updateLayoutChoice();
|
|
|
|
|
updateMenubar();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-06-12 11:34:13 +00:00
|
|
|
|
// Start autosave timer
|
|
|
|
|
if (lyxrc.autosave) {
|
2002-07-21 01:38:24 +00:00
|
|
|
|
autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
|
2002-06-12 11:34:13 +00:00
|
|
|
|
autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
|
|
|
|
|
autosave_timeout_->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intl_->InitKeyMapper(lyxrc.use_kbmap);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
Buffer * LyXView::buffer() const
|
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
|
return bufferview_->buffer();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 09:21:50 +00:00
|
|
|
|
boost::shared_ptr<BufferView> const & LyXView::view() const
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2002-08-02 09:21:50 +00:00
|
|
|
|
return bufferview_;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
void LyXView::setLayout(string const & layout)
|
2000-07-24 13:53:19 +00:00
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
|
toolbar_->setLayout(layout);
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2000-07-25 10:46:18 +00:00
|
|
|
|
|
|
|
|
|
void LyXView::updateToolbar()
|
|
|
|
|
{
|
2003-04-10 14:08:06 +00:00
|
|
|
|
bool const math = mathcursor;
|
|
|
|
|
bool const table =
|
|
|
|
|
!getLyXFunc().getStatus(LFUN_LAYOUT_TABULAR).disabled();
|
|
|
|
|
toolbar_->update(math, table);
|
2000-07-25 10:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
void LyXView::updateMenubar()
|
2000-07-24 13:53:19 +00:00
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
|
menubar_->update();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2002-06-12 11:34:13 +00:00
|
|
|
|
void LyXView::autoSave()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-06-12 11:34:13 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Running autoSave()" << endl;
|
|
|
|
|
|
|
|
|
|
if (view()->available()) {
|
2002-08-02 09:21:50 +00:00
|
|
|
|
::AutoSave(view().get());
|
2002-06-12 11:34:13 +00:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::updateLayoutChoice()
|
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
|
// don't show any layouts without a buffer
|
|
|
|
|
if (!view()->buffer()) {
|
|
|
|
|
toolbar_->clearLayoutList();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-12 02:54:19 +00:00
|
|
|
|
// update the layout display
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (toolbar_->updateLayoutList(buffer()->params().textclass)) {
|
|
|
|
|
current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
|
2001-08-03 18:28:11 +00:00
|
|
|
|
}
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
|
|
|
|
string const & layout =
|
2002-06-24 20:28:12 +00:00
|
|
|
|
bufferview_->getLyXText()->cursor.par()->layout()->name();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-12-05 23:16:13 +00:00
|
|
|
|
if (layout != current_layout) {
|
2002-06-12 02:54:19 +00:00
|
|
|
|
toolbar_->setLayout(layout);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
current_layout = layout;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
|
void LyXView::updateWindowTitle()
|
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
static string last_title = "LyX";
|
2002-09-11 18:05:42 +00:00
|
|
|
|
string maximize_title = "LyX";
|
|
|
|
|
string minimize_title = "LyX";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
if (view()->available()) {
|
2001-04-17 15:15:59 +00:00
|
|
|
|
string const cur_title = buffer()->fileName();
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (!cur_title.empty()) {
|
2002-09-11 18:05:42 +00:00
|
|
|
|
maximize_title += ": " + MakeDisplayPath(cur_title, 30);
|
|
|
|
|
minimize_title = OnlyFilename(cur_title);
|
|
|
|
|
if (!buffer()->isClean()) {
|
|
|
|
|
maximize_title += _(" (changed)");
|
2002-11-27 10:30:28 +00:00
|
|
|
|
minimize_title += '*';
|
2002-09-11 18:05:42 +00:00
|
|
|
|
}
|
1999-11-09 23:52:04 +00:00
|
|
|
|
if (buffer()->isReadonly())
|
2002-09-11 18:05:42 +00:00
|
|
|
|
maximize_title += _(" (read only)");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-06-12 02:54:19 +00:00
|
|
|
|
|
2002-09-11 18:05:42 +00:00
|
|
|
|
if (maximize_title != last_title) {
|
|
|
|
|
setWindowTitle(maximize_title, minimize_title);
|
|
|
|
|
last_title = maximize_title;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::dispatch(FuncRequest const & req)
|
|
|
|
|
{
|
|
|
|
|
// substitute the correct BufferView here
|
|
|
|
|
FuncRequest r = req;
|
|
|
|
|
r.setView(view().get());
|
2002-11-27 10:30:28 +00:00
|
|
|
|
getLyXFunc().dispatch(r);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
}
|