2001-06-25 00:06:33 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-10-02 16:21:10 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-10-02 16:21:10 +00:00
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "LyXView.h"
|
|
|
|
#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"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h" // OnlyFilename()
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyxtext.h"
|
2000-04-08 17:02:02 +00:00
|
|
|
#include "buffer.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
#include "frontends/Dialogs.h"
|
2000-07-24 13:53:19 +00:00
|
|
|
#include "frontends/Toolbar.h"
|
2000-09-14 17:53:12 +00:00
|
|
|
#include "frontends/Menubar.h"
|
|
|
|
#include "MenuBackend.h"
|
2000-11-28 06:46:06 +00:00
|
|
|
#include "lyx_gui_misc.h" // [update,Close,Redraw]AllBufferRelatedDialogs
|
2000-07-20 11:39:14 +00:00
|
|
|
#include "bufferview_funcs.h" // CurrentState()
|
2001-04-17 15:15:59 +00:00
|
|
|
#include "gettext.h"
|
2001-04-24 17:33:01 +00:00
|
|
|
#include "lyxfunc.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
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();
|
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
LyXTextClass::size_type current_layout = 0;
|
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;
|
1999-09-27 18:44:28 +00:00
|
|
|
lyxfunc = new LyXFunc(this);
|
2001-04-17 15:15:59 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
intl = new Intl;
|
2000-06-12 11:55:12 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
dialogs_ = new Dialogs(this);
|
|
|
|
// temporary until all dialogs moved into Dialogs.
|
|
|
|
dialogs_->updateBufferDependent
|
2001-03-15 18:21:56 +00:00
|
|
|
.connect(SigC::slot(&updateAllVisibleBufferRelatedDialogs));
|
2000-06-12 11:27:15 +00:00
|
|
|
dialogs_->hideBufferDependent
|
2001-03-15 18:21:56 +00:00
|
|
|
.connect(SigC::slot(&CloseAllBufferRelatedDialogs));
|
|
|
|
Dialogs::redrawGUI.connect(SigC::slot(this, &LyXView::redraw));
|
|
|
|
Dialogs::redrawGUI.connect(SigC::slot(&RedrawAllBufferRelatedDialogs));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXView::~LyXView()
|
|
|
|
{
|
2000-07-24 13:53:19 +00:00
|
|
|
delete menubar;
|
1999-09-27 18:44:28 +00:00
|
|
|
delete toolbar;
|
|
|
|
delete bufferview;
|
|
|
|
delete minibuffer;
|
|
|
|
delete lyxfunc;
|
|
|
|
delete intl;
|
2000-06-12 11:27:15 +00:00
|
|
|
delete dialogs_;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void LyXView::resize()
|
|
|
|
{
|
|
|
|
view()->resize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
/// returns the buffer currently shown in the main form.
|
|
|
|
Buffer * LyXView::buffer() const
|
|
|
|
{
|
|
|
|
return bufferview->buffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BufferView * LyXView::view() const
|
|
|
|
{
|
|
|
|
return bufferview;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Toolbar * LyXView::getToolbar() const
|
|
|
|
{
|
|
|
|
return toolbar;
|
|
|
|
}
|
|
|
|
|
2000-07-25 10:46:18 +00:00
|
|
|
|
2000-09-27 18:13:30 +00:00
|
|
|
void LyXView::setLayout(LyXTextClass::size_type layout)
|
2000-07-24 13:53:19 +00:00
|
|
|
{
|
|
|
|
toolbar->setLayout(layout);
|
|
|
|
}
|
2000-04-08 17:02:02 +00:00
|
|
|
|
2000-07-25 10:46:18 +00:00
|
|
|
|
|
|
|
void LyXView::updateToolbar()
|
|
|
|
{
|
|
|
|
toolbar->update();
|
2000-08-09 13:51:59 +00:00
|
|
|
menubar->update();
|
2000-07-25 10:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
LyXFunc * LyXView::getLyXFunc() const
|
|
|
|
{
|
|
|
|
return lyxfunc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MiniBuffer * LyXView::getMiniBuffer() const
|
|
|
|
{
|
|
|
|
return minibuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void LyXView::message(string const & str)
|
|
|
|
{
|
|
|
|
minibuffer->message(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::messagePush(string const & str)
|
|
|
|
{
|
|
|
|
minibuffer->messagePush(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::messagePop()
|
|
|
|
{
|
|
|
|
minibuffer->messagePop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
Menubar * LyXView::getMenubar() const
|
|
|
|
{
|
|
|
|
return menubar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::updateMenubar()
|
|
|
|
{
|
|
|
|
if ((!view() || !view()->buffer())
|
|
|
|
&& menubackend.hasMenu("main_nobuffer"))
|
|
|
|
menubar->set("main_nobuffer");
|
|
|
|
else
|
|
|
|
menubar->set("main");
|
|
|
|
}
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
|
|
Intl * LyXView::getIntl() const
|
|
|
|
{
|
|
|
|
return intl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Callback for autosave timer
|
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
|
|
|
/// Reset autosave timer
|
|
|
|
void LyXView::resetAutosaveTimer()
|
|
|
|
{
|
2000-03-12 10:35:05 +00:00
|
|
|
if (lyxrc.autosave)
|
2000-06-08 23:16:16 +00:00
|
|
|
autosave_timeout.restart();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::invalidateLayoutChoice()
|
|
|
|
{
|
|
|
|
last_textclass = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXView::updateLayoutChoice()
|
|
|
|
{
|
1999-12-19 22:35:36 +00:00
|
|
|
// This has a side-effect that the layouts are not showed when no
|
1999-09-27 18:44:28 +00:00
|
|
|
// document is loaded.
|
2000-07-24 13:53:19 +00:00
|
|
|
if (!view() || !view()->buffer()) {
|
|
|
|
toolbar->clearLayoutList();
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
// Update the layout display
|
|
|
|
if (last_textclass != int(buffer()->params.textclass)) {
|
|
|
|
toolbar->updateLayoutList(true);
|
1999-11-09 23:52:04 +00:00
|
|
|
last_textclass = int(buffer()->params.textclass);
|
1999-09-27 18:44:28 +00:00
|
|
|
current_layout = 0;
|
2001-08-03 18:28:11 +00:00
|
|
|
} else {
|
2000-07-24 13:53:19 +00:00
|
|
|
toolbar->updateLayoutList(false);
|
2001-08-03 18:28:11 +00:00
|
|
|
}
|
2000-07-24 13:53:19 +00:00
|
|
|
|
2000-06-21 12:41:18 +00:00
|
|
|
LyXTextClass::size_type layout =
|
2001-06-25 00:06:33 +00:00
|
|
|
bufferview->text->cursor.par()->getLayout();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (layout != current_layout){
|
2000-07-24 13:53:19 +00:00
|
|
|
toolbar->setLayout(layout);
|
1999-09-27 18:44:28 +00:00
|
|
|
current_layout = layout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Updates the title of the window with the filename of the current document
|
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";
|
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();
|
1999-09-27 18:44:28 +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())
|
1999-09-27 18:44:28 +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)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (title != last_title) {
|
2001-07-03 15:19:04 +00:00
|
|
|
setWindowTitle(title);
|
2001-08-01 10:08:53 +00:00
|
|
|
last_title = title;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-08-16 10:19:59 +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
|
|
|
getToolbar()->update();
|
2000-08-09 13:51:59 +00:00
|
|
|
menubar->update();
|
2000-07-20 11:39:14 +00:00
|
|
|
}
|