2002-06-12 02:54:19 +00:00
|
|
|
/**
|
|
|
|
* \file LyXView.C
|
|
|
|
* Copyright 1995-2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2002-06-12 02:54:19 +00:00
|
|
|
* \author Lars Gullik Bjornes
|
|
|
|
* \author John Levon <moz@compsoc.man.ac.uk>
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2002-06-12 02:54:19 +00:00
|
|
|
#include "LyXView.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "minibuffer.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "intl.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "lyxtext.h"
|
2000-04-08 17:02:02 +00:00
|
|
|
#include "buffer.h"
|
2000-09-14 17:53:12 +00:00
|
|
|
#include "MenuBackend.h"
|
2001-04-17 15:15:59 +00:00
|
|
|
#include "gettext.h"
|
2001-04-24 17:33:01 +00:00
|
|
|
#include "lyxfunc.h"
|
2002-06-12 02:54:19 +00:00
|
|
|
#include "lyx_cb.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
2002-06-12 02:54:19 +00:00
|
|
|
#include "bufferview_funcs.h"
|
2002-03-02 16:39:54 +00:00
|
|
|
#include "lyxtextclasslist.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
#include "frontends/Toolbar.h"
|
2002-02-18 19:13:48 +00:00
|
|
|
#include "frontends/Timeout.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
#include "frontends/Menubar.h"
|
|
|
|
|
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>
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
extern void AutoSave(BufferView *);
|
1999-09-27 18:44:28 +00:00
|
|
|
extern void QuitLyX();
|
|
|
|
|
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()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
|
2001-04-17 15:15:59 +00:00
|
|
|
|
2002-06-12 02:54:19 +00:00
|
|
|
lyxfunc_.reset(new LyXFunc(this));
|
|
|
|
intl_.reset(new Intl);
|
2000-06-12 11:55:12 +00:00
|
|
|
|
2002-02-18 19:13:48 +00:00
|
|
|
// Give the timeout some default sensible value.
|
2002-06-12 02:54:19 +00:00
|
|
|
autosave_timeout_.reset(new Timeout(5000));
|
2002-02-18 19:13:48 +00:00
|
|
|
|
2002-06-12 02:54:19 +00:00
|
|
|
dialogs_.reset(new Dialogs(this));
|
2002-05-29 16:21:03 +00:00
|
|
|
Dialogs::redrawGUI.connect(boost::bind(&LyXView::redraw, this));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXView::~LyXView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
void LyXView::resize()
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
view()->resize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BufferView * LyXView::view() const
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
return bufferview_.get();
|
2000-04-08 17:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Toolbar * LyXView::getToolbar() const
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
return toolbar_.get();
|
2000-04-08 17:02:02 +00:00
|
|
|
}
|
|
|
|
|
2000-07-25 10:46:18 +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()
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
toolbar_->update();
|
2000-07-25 10:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
LyXFunc * LyXView::getLyXFunc() const
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
return lyxfunc_.get();
|
2000-04-08 17:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MiniBuffer * LyXView::getMiniBuffer() const
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
return minibuffer_.get();
|
2000-04-08 17:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void LyXView::message(string const & str)
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
minibuffer_->message(str);
|
2001-04-17 15:15:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::messagePush(string const & str)
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
minibuffer_->messagePush(str);
|
2001-04-17 15:15:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::messagePop()
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
minibuffer_->messagePop();
|
2001-04-17 15:15:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
Menubar * LyXView::getMenubar() const
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
return menubar_.get();
|
2000-07-24 13:53:19 +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
|
|
|
if (!view()->buffer() && menubackend.hasMenu("main_nobuffer")) {
|
|
|
|
menubar_->set("main_nobuffer");
|
|
|
|
} else {
|
|
|
|
menubar_->set("main");
|
|
|
|
}
|
|
|
|
|
|
|
|
menubar_->update();
|
2000-07-24 13:53:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
|
|
Intl * LyXView::getIntl() const
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
return intl_.get();
|
2000-04-08 17:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
void LyXView::AutoSave()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
|
2000-04-11 22:55:29 +00:00
|
|
|
if (view()->available())
|
|
|
|
::AutoSave(view());
|
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::invalidateLayoutChoice()
|
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
last_textclass_ = -1;
|
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
|
|
|
|
if (last_textclass_ != int(buffer()->params.textclass)) {
|
|
|
|
toolbar_->updateLayoutList(true);
|
|
|
|
last_textclass_ = int(buffer()->params.textclass);
|
|
|
|
current_layout = textclasslist[last_textclass_].defaultLayoutName();
|
2001-08-03 18:28:11 +00:00
|
|
|
} else {
|
2002-06-12 02:54:19 +00:00
|
|
|
toolbar_->updateLayoutList(false);
|
2001-08-03 18:28:11 +00:00
|
|
|
}
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
|
|
string const & layout =
|
2002-06-12 02:54:19 +00:00
|
|
|
bufferview_->getLyXText()->cursor.par()->layout();
|
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";
|
1999-10-02 16:21:10 +00:00
|
|
|
string title = "LyX";
|
2002-01-03 03:14:40 +00:00
|
|
|
string icon_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()) {
|
2000-09-26 13:10:34 +00:00
|
|
|
title += ": " + MakeDisplayPath(cur_title, 30);
|
1999-11-09 23:52:04 +00:00
|
|
|
if (!buffer()->isLyxClean())
|
2002-06-12 02:54:19 +00:00
|
|
|
title += _(" (changed)");
|
1999-11-09 23:52:04 +00:00
|
|
|
if (buffer()->isReadonly())
|
1999-09-27 18:44:28 +00:00
|
|
|
title += _(" (read only)");
|
2002-06-12 02:54:19 +00:00
|
|
|
// Show only the filename if it's available
|
2002-01-03 03:14:40 +00:00
|
|
|
icon_title = OnlyFilename(cur_title);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-12 02:54:19 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
if (title != last_title) {
|
2002-01-03 03:14:40 +00:00
|
|
|
setWindowTitle(title, icon_title);
|
2001-08-01 10:08:53 +00:00
|
|
|
last_title = title;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
2000-07-20 11:39:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
void LyXView::showState()
|
|
|
|
{
|
2001-08-02 18:46:53 +00:00
|
|
|
message(currentState(view()));
|
2000-07-20 11:39:14 +00:00
|
|
|
}
|