2002-06-12 02:54:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file BufferView_pimpl.C
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-12 02:54:19 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Asger Alstrup
|
2004-01-30 11:41:12 +00:00
|
|
|
|
* \author Alfredo Braunstein
|
2003-06-30 23:56:22 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author Dekel Tsur
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-12 02:54:19 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "BufferView_pimpl.h"
|
2003-05-23 13:54:09 +00:00
|
|
|
|
#include "buffer.h"
|
2003-06-20 12:46:28 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "bufferlist.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
#include "cursor.h"
|
2001-07-29 15:34:18 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "factory.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "FloatList.h"
|
2002-08-07 08:11:41 +00:00
|
|
|
|
#include "funcrequest.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "intl.h"
|
2003-02-08 19:18:01 +00:00
|
|
|
|
#include "iterators.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "lyx_cb.h" // added for Dispatch functions
|
|
|
|
|
#include "lyx_main.h"
|
2003-02-08 19:18:01 +00:00
|
|
|
|
#include "lyxfind.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "lyxrc.h"
|
2003-06-20 12:46:28 +00:00
|
|
|
|
#include "lastfiles.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-08-27 13:51:18 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "undo.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "vspace.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
|
#include "insets/insetref.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/Alert.h"
|
|
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
|
#include "frontends/FileDialog.h"
|
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
#include "frontends/LyXScreenFactory.h"
|
|
|
|
|
#include "frontends/screen.h"
|
|
|
|
|
#include "frontends/WorkArea.h"
|
|
|
|
|
#include "frontends/WorkAreaFactory.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
|
#include "graphics/Previews.h"
|
|
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "support/filetools.h"
|
2004-01-08 10:59:51 +00:00
|
|
|
|
#include "support/globbing.h"
|
2003-07-27 21:04:02 +00:00
|
|
|
|
#include "support/path_defines.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "support/tostr.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::pos_type;
|
|
|
|
|
|
|
|
|
|
using lyx::support::AddPath;
|
|
|
|
|
using lyx::support::bformat;
|
2004-01-08 10:59:51 +00:00
|
|
|
|
using lyx::support::FileFilterList;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::FileSearch;
|
|
|
|
|
using lyx::support::IsDirWriteable;
|
|
|
|
|
using lyx::support::MakeDisplayPath;
|
|
|
|
|
using lyx::support::strToUnsignedInt;
|
|
|
|
|
using lyx::support::system_lyxdir;
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
using std::endl;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
using std::make_pair;
|
2001-01-28 18:31:36 +00:00
|
|
|
|
using std::min;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2001-11-29 17:12:21 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
|
|
|
|
extern BufferList bufferlist;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
|
|
2001-03-17 02:06:21 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2002-07-22 20:57:58 +00:00
|
|
|
|
unsigned int const saved_positions_num = 20;
|
|
|
|
|
|
|
|
|
|
// All the below connection objects are needed because of a bug in some
|
|
|
|
|
// versions of GCC (<=2.96 are on the suspects list.) By having and assigning
|
|
|
|
|
// to these connections we avoid a segfault upon startup, and also at exit.
|
|
|
|
|
// (Lgb)
|
|
|
|
|
|
2002-08-28 08:30:27 +00:00
|
|
|
|
boost::signals::connection dispatchcon;
|
2002-07-22 20:57:58 +00:00
|
|
|
|
boost::signals::connection timecon;
|
|
|
|
|
boost::signals::connection doccon;
|
|
|
|
|
boost::signals::connection resizecon;
|
|
|
|
|
boost::signals::connection kpresscon;
|
|
|
|
|
boost::signals::connection selectioncon;
|
|
|
|
|
boost::signals::connection lostcon;
|
2000-04-14 19:20:33 +00:00
|
|
|
|
|
2002-08-27 16:16:17 +00:00
|
|
|
|
|
2001-03-17 02:06:21 +00:00
|
|
|
|
} // anon namespace
|
|
|
|
|
|
2000-04-14 19:20:33 +00:00
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner,
|
2000-04-08 17:02:02 +00:00
|
|
|
|
int xpos, int ypos, int width, int height)
|
2004-01-16 10:55:19 +00:00
|
|
|
|
: bv_(&bv), owner_(owner), buffer_(0), cursor_timeout(400),
|
2003-11-04 12:36:59 +00:00
|
|
|
|
using_xterm_cursor(false), cursor_(bv)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2003-12-12 15:19:35 +00:00
|
|
|
|
xsel_cache_.set = false;
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
|
|
|
|
|
screen_.reset(LyXScreenFactory::create(workarea()));
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2000-08-14 15:31:16 +00:00
|
|
|
|
// Setup the signals
|
2002-08-19 15:39:25 +00:00
|
|
|
|
doccon = workarea().scrollDocView
|
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
|
2002-07-22 20:57:58 +00:00
|
|
|
|
resizecon = workarea().workAreaResize
|
2002-06-20 20:37:42 +00:00
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
|
2002-08-28 08:30:27 +00:00
|
|
|
|
dispatchcon = workarea().dispatch
|
2003-03-24 02:31:44 +00:00
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::workAreaDispatch, this, _1));
|
2002-07-22 20:57:58 +00:00
|
|
|
|
kpresscon = workarea().workAreaKeyPress
|
2002-05-29 16:21:03 +00:00
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
|
2002-07-22 20:57:58 +00:00
|
|
|
|
selectioncon = workarea().selectionRequested
|
2002-05-29 16:21:03 +00:00
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
|
2002-07-22 20:57:58 +00:00
|
|
|
|
lostcon = workarea().selectionLost
|
2002-05-29 16:21:03 +00:00
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-19 15:39:25 +00:00
|
|
|
|
timecon = cursor_timeout.timeout
|
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor_timeout.start();
|
2001-01-28 18:31:36 +00:00
|
|
|
|
saved_positions.resize(saved_positions_num);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2003-06-20 23:03:43 +00:00
|
|
|
|
void BufferView::Pimpl::addError(ErrorItem const & ei)
|
|
|
|
|
{
|
|
|
|
|
errorlist_.push_back(ei);
|
2003-07-07 08:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-06-20 23:03:43 +00:00
|
|
|
|
|
2003-07-10 12:26:40 +00:00
|
|
|
|
void BufferView::Pimpl::showReadonly(bool)
|
|
|
|
|
{
|
|
|
|
|
owner_->updateWindowTitle();
|
|
|
|
|
owner_->getDialogs().updateBufferDependent(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-07 08:37:02 +00:00
|
|
|
|
void BufferView::Pimpl::connectBuffer(Buffer & buf)
|
|
|
|
|
{
|
|
|
|
|
if (errorConnection_.connected())
|
|
|
|
|
disconnectBuffer();
|
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
errorConnection_ =
|
|
|
|
|
buf.error.connect(boost::bind(&BufferView::Pimpl::addError, this, _1));
|
|
|
|
|
messageConnection_ =
|
|
|
|
|
buf.message.connect(boost::bind(&LyXView::message, owner_, _1));
|
|
|
|
|
busyConnection_ =
|
|
|
|
|
buf.busy.connect(boost::bind(&LyXView::busy, owner_, _1));
|
|
|
|
|
titleConnection_ =
|
|
|
|
|
buf.updateTitles.connect(boost::bind(&LyXView::updateWindowTitle, owner_));
|
|
|
|
|
timerConnection_ =
|
|
|
|
|
buf.resetAutosaveTimers.connect(boost::bind(&LyXView::resetAutosaveTimer, owner_));
|
|
|
|
|
readonlyConnection_ =
|
|
|
|
|
buf.readonly.connect(boost::bind(&BufferView::Pimpl::showReadonly, this, _1));
|
|
|
|
|
closingConnection_ =
|
|
|
|
|
buf.closing.connect(boost::bind(&BufferView::Pimpl::buffer, this, (Buffer *)0));
|
2003-07-07 08:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::Pimpl::disconnectBuffer()
|
|
|
|
|
{
|
|
|
|
|
errorConnection_.disconnect();
|
|
|
|
|
messageConnection_.disconnect();
|
|
|
|
|
busyConnection_.disconnect();
|
2003-07-10 12:26:40 +00:00
|
|
|
|
titleConnection_.disconnect();
|
|
|
|
|
timerConnection_.disconnect();
|
|
|
|
|
readonlyConnection_.disconnect();
|
2003-07-11 12:21:31 +00:00
|
|
|
|
closingConnection_.disconnect();
|
2003-07-07 08:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
bool BufferView::Pimpl::newFile(string const & filename,
|
2003-07-07 08:37:02 +00:00
|
|
|
|
string const & tname,
|
|
|
|
|
bool isNamed)
|
|
|
|
|
{
|
|
|
|
|
Buffer * b = ::newFile(filename, tname, isNamed);
|
|
|
|
|
buffer(b);
|
|
|
|
|
return true;
|
2003-06-20 23:03:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
|
|
|
|
bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
|
|
|
|
|
{
|
|
|
|
|
// get absolute path of file and add ".lyx" to the filename if
|
|
|
|
|
// necessary
|
|
|
|
|
string s = FileSearch(string(), filename, "lyx");
|
2003-08-01 21:18:49 +00:00
|
|
|
|
|
2003-07-29 16:40:26 +00:00
|
|
|
|
bool const found = !s.empty();
|
|
|
|
|
|
2003-08-01 21:18:49 +00:00
|
|
|
|
if (!found)
|
2003-06-20 12:46:28 +00:00
|
|
|
|
s = filename;
|
|
|
|
|
|
|
|
|
|
// file already open?
|
|
|
|
|
if (bufferlist.exists(s)) {
|
|
|
|
|
string const file = MakeDisplayPath(s, 20);
|
|
|
|
|
string text = bformat(_("The document %1$s is already "
|
|
|
|
|
"loaded.\n\nDo you want to revert "
|
|
|
|
|
"to the saved version?"), file);
|
|
|
|
|
int const ret = Alert::prompt(_("Revert to saved document?"),
|
|
|
|
|
text, 0, 1, _("&Revert"), _("&Switch to document"));
|
|
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
|
buffer(bufferlist.getBuffer(s));
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
// FIXME: should be LFUN_REVERT
|
|
|
|
|
if (!bufferlist.close(bufferlist.getBuffer(s), false))
|
|
|
|
|
return false;
|
|
|
|
|
// Fall through to new load. (Asger)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 16:40:26 +00:00
|
|
|
|
Buffer * b;
|
2003-06-20 23:03:43 +00:00
|
|
|
|
|
2003-07-29 16:40:26 +00:00
|
|
|
|
if (found) {
|
|
|
|
|
b = bufferlist.newBuffer(s);
|
|
|
|
|
connectBuffer(*b);
|
|
|
|
|
if (!::loadLyXFile(b, s)) {
|
|
|
|
|
bufferlist.release(b);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2003-07-07 08:37:02 +00:00
|
|
|
|
string text = bformat(_("The document %1$s does not yet "
|
|
|
|
|
"exist.\n\nDo you want to create "
|
2003-06-20 12:46:28 +00:00
|
|
|
|
"a new document?"), s);
|
|
|
|
|
int const ret = Alert::prompt(_("Create new document?"),
|
|
|
|
|
text, 0, 1, _("&Create"), _("Cancel"));
|
|
|
|
|
|
2003-07-29 16:40:26 +00:00
|
|
|
|
if (ret == 0)
|
|
|
|
|
b = ::newFile(s, string(), true);
|
|
|
|
|
else
|
2003-06-27 07:11:31 +00:00
|
|
|
|
return false;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
}
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
|
|
|
|
buffer(b);
|
2003-07-29 16:40:26 +00:00
|
|
|
|
bv_->showErrorList(_("Parse"));
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
|
|
|
|
if (tolastfiles)
|
2003-10-14 21:30:23 +00:00
|
|
|
|
LyX::ref().lastfiles().newFile(b->fileName());
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-07 08:37:02 +00:00
|
|
|
|
|
2002-06-11 22:38:49 +00:00
|
|
|
|
WorkArea & BufferView::Pimpl::workarea() const
|
|
|
|
|
{
|
|
|
|
|
return *workarea_.get();
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
LyXScreen & BufferView::Pimpl::screen() const
|
2002-06-11 23:47:58 +00:00
|
|
|
|
{
|
|
|
|
|
return *screen_.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-12 02:54:19 +00:00
|
|
|
|
Painter & BufferView::Pimpl::painter() const
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2002-06-11 22:38:49 +00:00
|
|
|
|
return workarea().getPainter();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-27 14:55:20 +00:00
|
|
|
|
void BufferView::Pimpl::top_y(int y)
|
|
|
|
|
{
|
|
|
|
|
top_y_ = y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int BufferView::Pimpl::top_y() const
|
|
|
|
|
{
|
|
|
|
|
return top_y_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
void BufferView::Pimpl::buffer(Buffer * b)
|
|
|
|
|
{
|
|
|
|
|
lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
|
2002-11-27 10:30:28 +00:00
|
|
|
|
<< b << ')' << endl;
|
2000-04-09 22:48:51 +00:00
|
|
|
|
if (buffer_) {
|
2003-07-07 08:37:02 +00:00
|
|
|
|
disconnectBuffer();
|
2003-11-28 15:08:38 +00:00
|
|
|
|
//delete bv_->text();
|
|
|
|
|
//bv_->setText(0);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// reset old cursor
|
|
|
|
|
cursor_.reset();
|
|
|
|
|
|
2002-08-19 15:39:25 +00:00
|
|
|
|
// set current buffer
|
2000-04-09 22:48:51 +00:00
|
|
|
|
buffer_ = b;
|
|
|
|
|
|
2003-08-27 14:55:20 +00:00
|
|
|
|
top_y_ = 0;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
|
2003-03-02 12:16:00 +00:00
|
|
|
|
// if we're quitting lyx, don't bother updating stuff
|
2003-02-15 19:21:11 +00:00
|
|
|
|
if (quitting)
|
2003-03-02 12:16:00 +00:00
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-19 15:39:25 +00:00
|
|
|
|
// if we are closing the buffer, use the first buffer as current
|
2003-07-29 16:40:26 +00:00
|
|
|
|
if (!buffer_)
|
2000-04-09 22:48:51 +00:00
|
|
|
|
buffer_ = bufferlist.first();
|
|
|
|
|
|
|
|
|
|
if (buffer_) {
|
|
|
|
|
lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
|
2003-07-07 08:37:02 +00:00
|
|
|
|
connectBuffer(*buffer_);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2003-12-01 00:35:26 +00:00
|
|
|
|
buffer_->text().init(bv_);
|
|
|
|
|
buffer_->text().textwidth_ = workarea().workWidth();
|
|
|
|
|
buffer_->text().fullRebreak();
|
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
// If we don't have a text object for this, we make one
|
2003-11-28 08:55:12 +00:00
|
|
|
|
if (bv_->text() == 0)
|
2000-04-09 22:48:51 +00:00
|
|
|
|
resizeCurrentBuffer();
|
2002-06-21 02:22:13 +00:00
|
|
|
|
|
2003-04-02 09:10:08 +00:00
|
|
|
|
// Buffer-dependent dialogs should be updated or
|
2000-10-10 11:50:43 +00:00
|
|
|
|
// hidden. This should go here because some dialogs (eg ToC)
|
|
|
|
|
// require bv_->text.
|
2002-08-13 14:40:38 +00:00
|
|
|
|
owner_->getDialogs().updateBufferDependent(true);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::INFO] << " No Buffer!" << endl;
|
2002-08-13 14:40:38 +00:00
|
|
|
|
owner_->getDialogs().hideBufferDependent();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2003-08-01 15:27:57 +00:00
|
|
|
|
update();
|
2002-06-21 02:22:13 +00:00
|
|
|
|
updateScrollbar();
|
|
|
|
|
owner_->updateMenubar();
|
|
|
|
|
owner_->updateToolbar();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
owner_->updateLayoutChoice();
|
|
|
|
|
owner_->updateWindowTitle();
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
// Don't forget to update the Layout
|
|
|
|
|
if (buffer_)
|
2004-02-12 16:36:01 +00:00
|
|
|
|
owner_->setLayout(bv_->text()->getPar(0)->layout()->name());
|
2003-04-02 09:10:08 +00:00
|
|
|
|
|
2003-07-21 21:30:57 +00:00
|
|
|
|
if (lyx::graphics::Previews::activated() && buffer_)
|
|
|
|
|
lyx::graphics::Previews::get().generateBufferPreviews(*buffer_);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-20 21:37:05 +00:00
|
|
|
|
|
2001-08-02 14:55:06 +00:00
|
|
|
|
bool BufferView::Pimpl::fitCursor()
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2003-11-13 08:50:26 +00:00
|
|
|
|
if (screen().fitCursor(bv_)) {
|
2003-11-11 09:06:41 +00:00
|
|
|
|
updateScrollbar();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::Pimpl::redoCurrentBuffer()
|
|
|
|
|
{
|
|
|
|
|
lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
|
2003-11-28 08:55:12 +00:00
|
|
|
|
if (buffer_ && bv_->text()) {
|
2002-06-20 20:37:42 +00:00
|
|
|
|
resizeCurrentBuffer();
|
2002-08-07 14:15:06 +00:00
|
|
|
|
updateScrollbar();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
owner_->updateLayoutChoice();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-11 09:09:01 +00:00
|
|
|
|
void BufferView::Pimpl::resizeCurrentBuffer()
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
|
|
|
|
lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
int par = -1;
|
|
|
|
|
int selstartpar = -1;
|
|
|
|
|
int selendpar = -1;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos = 0;
|
|
|
|
|
pos_type selstartpos = 0;
|
|
|
|
|
pos_type selendpos = 0;
|
2004-01-14 14:16:11 +00:00
|
|
|
|
bool sel = false;
|
2001-03-08 12:58:40 +00:00
|
|
|
|
bool mark_set = false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-02-14 14:49:51 +00:00
|
|
|
|
owner_->busy(true);
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2001-04-24 17:33:01 +00:00
|
|
|
|
owner_->message(_("Formatting document..."));
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
LyXText * text = bv_->text();
|
|
|
|
|
lyxerr << "### resizeCurrentBuffer: text " << text << endl;
|
|
|
|
|
if (!text)
|
2003-11-28 15:08:38 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv_->cursor();
|
|
|
|
|
par = cur.par();
|
|
|
|
|
pos = cur.pos();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
selstartpar = cur.selBegin().par();
|
|
|
|
|
selstartpos = cur.selBegin().pos();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
selendpar = cur.selEnd().par();
|
|
|
|
|
selendpos = cur.selEnd().pos();
|
|
|
|
|
sel = cur.selection();
|
|
|
|
|
mark_set = cur.mark();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
text->textwidth_ = bv_->workWidth();
|
|
|
|
|
text->fullRebreak();
|
2003-12-02 10:51:58 +00:00
|
|
|
|
update();
|
2002-03-12 17:15:44 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (par != -1) {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.selection() = true;
|
2002-03-12 17:15:44 +00:00
|
|
|
|
// At this point just to avoid the Delete-Empty-Paragraph-
|
|
|
|
|
// Mechanism when setting the cursor.
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.mark() = mark_set;
|
2004-01-14 14:16:11 +00:00
|
|
|
|
if (sel) {
|
2004-01-13 10:37:38 +00:00
|
|
|
|
text->setCursor(selstartpar, selstartpos);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
text->setCursor(selendpar, selendpos);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.setSelection();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
text->setCursor(par, pos);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
} else {
|
2004-01-13 10:37:38 +00:00
|
|
|
|
text->setCursor(par, pos);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
cur.selection() = false;
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-12 17:15:44 +00:00
|
|
|
|
|
2003-11-13 08:50:26 +00:00
|
|
|
|
fitCursor();
|
2002-03-12 17:15:44 +00:00
|
|
|
|
|
2002-07-17 04:13:41 +00:00
|
|
|
|
switchKeyMap();
|
2003-02-14 14:49:51 +00:00
|
|
|
|
owner_->busy(false);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2003-04-07 16:57:38 +00:00
|
|
|
|
// reset the "Formatting..." message
|
|
|
|
|
owner_->clearMessage();
|
|
|
|
|
|
2002-08-07 14:15:06 +00:00
|
|
|
|
updateScrollbar();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::Pimpl::updateScrollbar()
|
|
|
|
|
{
|
2003-11-28 08:55:12 +00:00
|
|
|
|
if (!bv_->text()) {
|
2002-03-25 17:00:04 +00:00
|
|
|
|
lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
workarea().setScrollbarParams(0, 0, 0);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-28 08:55:12 +00:00
|
|
|
|
LyXText const & t = *bv_->text();
|
2002-07-22 20:57:58 +00:00
|
|
|
|
|
2003-03-06 20:21:21 +00:00
|
|
|
|
lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
|
2003-08-27 14:55:20 +00:00
|
|
|
|
<< top_y() << ", default height " << defaultRowHeight() << endl;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2003-08-27 14:55:20 +00:00
|
|
|
|
workarea().setScrollbarParams(t.height, top_y(), defaultRowHeight());
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
|
void BufferView::Pimpl::scrollDocView(int value)
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2002-06-12 15:01:32 +00:00
|
|
|
|
lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
|
2002-04-05 15:17:24 +00:00
|
|
|
|
|
2002-08-29 13:05:55 +00:00
|
|
|
|
if (!buffer_)
|
|
|
|
|
return;
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2003-05-03 18:05:53 +00:00
|
|
|
|
screen().hideCursor();
|
|
|
|
|
|
2003-08-27 14:55:20 +00:00
|
|
|
|
top_y(value);
|
2003-08-25 11:03:19 +00:00
|
|
|
|
screen().redraw(*bv_);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2002-08-29 13:05:55 +00:00
|
|
|
|
if (!lyxrc.cursor_follows_scrollbar)
|
2001-02-07 16:44:49 +00:00
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-02-14 00:41:44 +00:00
|
|
|
|
int const height = defaultRowHeight();
|
2003-08-27 14:55:20 +00:00
|
|
|
|
int const first = top_y() + height;
|
|
|
|
|
int const last = top_y() + workarea().workHeight() - height;
|
2003-08-26 10:33:59 +00:00
|
|
|
|
|
2003-11-28 08:55:12 +00:00
|
|
|
|
LyXText * text = bv_->text();
|
2004-01-30 11:41:12 +00:00
|
|
|
|
int y = text->cursorY(bv_->cursor().cursor_.front());
|
|
|
|
|
if (y < first)
|
2003-08-26 10:33:59 +00:00
|
|
|
|
text->setCursorFromCoordinates(0, first);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
else if (y > last)
|
2003-08-26 10:33:59 +00:00
|
|
|
|
text->setCursorFromCoordinates(0, last);
|
2003-03-18 20:54:01 +00:00
|
|
|
|
|
2003-03-26 15:55:52 +00:00
|
|
|
|
owner_->updateLayoutChoice();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-10-21 00:15:48 +00:00
|
|
|
|
void BufferView::Pimpl::scroll(int lines)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
if (!buffer_)
|
2002-10-21 00:15:48 +00:00
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-28 08:55:12 +00:00
|
|
|
|
LyXText const * t = bv_->text();
|
2003-02-14 00:41:44 +00:00
|
|
|
|
int const line_height = defaultRowHeight();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-10-21 15:29:41 +00:00
|
|
|
|
// The new absolute coordinate
|
2003-08-27 14:55:20 +00:00
|
|
|
|
int new_top_y = top_y() + lines * line_height;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-10-21 00:15:48 +00:00
|
|
|
|
// Restrict to a valid value
|
2003-03-06 20:21:21 +00:00
|
|
|
|
new_top_y = std::min(t->height - 4 * line_height, new_top_y);
|
|
|
|
|
new_top_y = std::max(0, new_top_y);
|
2003-11-21 11:16:37 +00:00
|
|
|
|
|
2003-03-06 20:21:21 +00:00
|
|
|
|
scrollDocView(new_top_y);
|
2002-10-21 00:15:48 +00:00
|
|
|
|
|
|
|
|
|
// Update the scrollbar.
|
2003-08-27 14:55:20 +00:00
|
|
|
|
workarea().setScrollbarParams(t->height, top_y(), defaultRowHeight());
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
|
|
|
|
|
key_modifier::state state)
|
2000-08-14 15:31:16 +00:00
|
|
|
|
{
|
2002-08-13 14:40:38 +00:00
|
|
|
|
bv_->owner()->getLyXFunc().processKeySym(key, state);
|
2003-05-03 18:05:53 +00:00
|
|
|
|
|
|
|
|
|
/* This is perhaps a bit of a hack. When we move
|
|
|
|
|
* around, or type, it's nice to be able to see
|
|
|
|
|
* the cursor immediately after the keypress. So
|
|
|
|
|
* we reset the toggle timeout and force the visibility
|
|
|
|
|
* of the cursor. Note we cannot do this inside
|
|
|
|
|
* dispatch() itself, because that's called recursively.
|
|
|
|
|
*/
|
|
|
|
|
if (available()) {
|
|
|
|
|
cursor_timeout.restart();
|
|
|
|
|
screen().showCursor(*bv_);
|
|
|
|
|
}
|
2000-08-14 15:31:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-01-13 17:28:42 +00:00
|
|
|
|
void BufferView::Pimpl::selectionRequested()
|
|
|
|
|
{
|
2002-03-20 10:36:03 +00:00
|
|
|
|
static string sel;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-02-04 11:30:25 +00:00
|
|
|
|
if (!available())
|
|
|
|
|
return;
|
2002-03-20 10:36:03 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv_->cursor();
|
2002-03-20 10:36:03 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!cur.selection()) {
|
2003-12-12 15:19:35 +00:00
|
|
|
|
xsel_cache_.set = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!xsel_cache_.set ||
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.cursor_.back() != xsel_cache_.cursor ||
|
|
|
|
|
cur.anchor_.back() != xsel_cache_.anchor)
|
2002-03-20 10:36:03 +00:00
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
xsel_cache_.cursor = cur.cursor_.back();
|
|
|
|
|
xsel_cache_.anchor = cur.anchor_.back();
|
|
|
|
|
xsel_cache_.set = cur.selection();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
sel = cur.selectionAsString(false);
|
2003-12-12 15:19:35 +00:00
|
|
|
|
if (!sel.empty())
|
|
|
|
|
workarea().putClipboard(sel);
|
|
|
|
|
}
|
2002-01-13 17:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-02-07 16:43:54 +00:00
|
|
|
|
void BufferView::Pimpl::selectionLost()
|
|
|
|
|
{
|
2002-06-11 22:38:49 +00:00
|
|
|
|
if (available()) {
|
2003-05-03 18:05:53 +00:00
|
|
|
|
screen().hideCursor();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bv_->cursor().clearSelection();
|
2003-12-12 15:19:35 +00:00
|
|
|
|
xsel_cache_.set = false;
|
2002-03-05 16:18:02 +00:00
|
|
|
|
}
|
2002-02-07 16:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-20 20:37:42 +00:00
|
|
|
|
void BufferView::Pimpl::workAreaResize()
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2001-06-04 23:57:32 +00:00
|
|
|
|
static int work_area_width;
|
2002-07-01 14:31:57 +00:00
|
|
|
|
static int work_area_height;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2002-06-11 22:38:49 +00:00
|
|
|
|
bool const widthChange = workarea().workWidth() != work_area_width;
|
2002-06-12 00:51:45 +00:00
|
|
|
|
bool const heightChange = workarea().workHeight() != work_area_height;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
|
|
|
|
// update from work area
|
2002-06-11 22:38:49 +00:00
|
|
|
|
work_area_width = workarea().workWidth();
|
2002-06-12 00:51:45 +00:00
|
|
|
|
work_area_height = workarea().workHeight();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (buffer_ && widthChange) {
|
|
|
|
|
// The visible LyXView need a resize
|
|
|
|
|
resizeCurrentBuffer();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-01 15:27:57 +00:00
|
|
|
|
if (widthChange || heightChange)
|
|
|
|
|
update();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
// always make sure that the scrollbar is sane.
|
2000-04-09 22:48:51 +00:00
|
|
|
|
updateScrollbar();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
owner_->updateLayoutChoice();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
void BufferView::Pimpl::update()
|
|
|
|
|
{
|
2003-09-12 17:13:22 +00:00
|
|
|
|
//lyxerr << "BufferView::update()" << endl;
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// fix cursor coordinate cache in case something went wrong
|
2003-11-10 13:23:14 +00:00
|
|
|
|
|
|
|
|
|
// check needed to survive LyX startup
|
2003-08-11 09:09:01 +00:00
|
|
|
|
if (bv_->getLyXText()) {
|
2003-11-10 13:23:14 +00:00
|
|
|
|
// update all 'visible' paragraphs
|
2003-11-10 18:15:55 +00:00
|
|
|
|
ParagraphList::iterator beg;
|
|
|
|
|
ParagraphList::iterator end;
|
|
|
|
|
getParsInRange(buffer_->paragraphs(),
|
|
|
|
|
top_y(), top_y() + workarea().workHeight(),
|
|
|
|
|
beg, end);
|
2003-11-28 08:55:12 +00:00
|
|
|
|
bv_->text()->redoParagraphs(beg, end);
|
2003-11-10 13:23:14 +00:00
|
|
|
|
updateScrollbar();
|
2003-08-11 09:09:01 +00:00
|
|
|
|
}
|
2003-08-01 14:51:09 +00:00
|
|
|
|
screen().redraw(*bv_);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
// Callback for cursor timer
|
|
|
|
|
void BufferView::Pimpl::cursorToggle()
|
|
|
|
|
{
|
|
|
|
|
if (!buffer_) {
|
2001-02-07 16:44:49 +00:00
|
|
|
|
cursor_timeout.restart();
|
|
|
|
|
return;
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-05-03 18:05:53 +00:00
|
|
|
|
screen().toggleCursor(*bv_);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor_timeout.restart();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BufferView::Pimpl::available() const
|
|
|
|
|
{
|
2003-11-28 08:55:12 +00:00
|
|
|
|
return buffer_ && bv_->text();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
Change const BufferView::Pimpl::getCurrentChange()
|
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (!bv_->buffer()->params().tracking_changes)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return Change(Change::UNCHANGED);
|
|
|
|
|
|
2003-08-15 10:24:39 +00:00
|
|
|
|
LyXText * text = bv_->getLyXText();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv_->cursor();
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!cur.selection())
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return Change(Change::UNCHANGED);
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return text->getPar(cur.selBegin())
|
|
|
|
|
->lookupChangeFull(cur.selBegin().pos());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-01-28 18:31:36 +00:00
|
|
|
|
void BufferView::Pimpl::savePosition(unsigned int i)
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2001-01-28 18:31:36 +00:00
|
|
|
|
if (i >= saved_positions_num)
|
|
|
|
|
return;
|
|
|
|
|
saved_positions[i] = Position(buffer_->fileName(),
|
2003-11-28 08:55:12 +00:00
|
|
|
|
bv_->text()->cursorPar()->id(),
|
2004-01-13 10:37:38 +00:00
|
|
|
|
bv_->text()->cursor().pos());
|
2003-05-13 09:48:57 +00:00
|
|
|
|
if (i > 0)
|
|
|
|
|
owner_->message(bformat(_("Saved bookmark %1$s"), tostr(i)));
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-01-28 18:31:36 +00:00
|
|
|
|
void BufferView::Pimpl::restorePosition(unsigned int i)
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2001-01-28 18:31:36 +00:00
|
|
|
|
if (i >= saved_positions_num)
|
|
|
|
|
return;
|
|
|
|
|
|
2001-05-03 14:31:33 +00:00
|
|
|
|
string const fname = saved_positions[i].filename;
|
2000-08-08 13:55:26 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bv_->cursor().clearSelection();
|
2000-08-08 13:55:26 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (fname != buffer_->fileName()) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
Buffer * b = 0;
|
2003-06-20 12:46:28 +00:00
|
|
|
|
if (bufferlist.exists(fname))
|
|
|
|
|
b = bufferlist.getBuffer(fname);
|
|
|
|
|
else {
|
|
|
|
|
b = bufferlist.newBuffer(fname);
|
|
|
|
|
::loadLyXFile(b, fname); // don't ask, just load it
|
|
|
|
|
}
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (b)
|
2003-06-20 12:46:28 +00:00
|
|
|
|
buffer(b);
|
2000-08-08 13:55:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-22 08:01:41 +00:00
|
|
|
|
ParIterator par = buffer_->getParFromID(saved_positions[i].par_id);
|
|
|
|
|
if (par == buffer_->par_iterator_end())
|
2001-01-28 18:31:36 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
bv_->text()->setCursor(bv_->text()->parOffset(par.pit()),
|
2003-06-12 11:09:55 +00:00
|
|
|
|
min(par->size(), saved_positions[i].par_pos));
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
if (i > 0)
|
|
|
|
|
owner_->message(bformat(_("Moved to bookmark %1$s"), tostr(i)));
|
2000-08-08 13:55:26 +00:00
|
|
|
|
}
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2000-06-21 12:41:18 +00:00
|
|
|
|
|
2001-01-28 18:31:36 +00:00
|
|
|
|
bool BufferView::Pimpl::isSavedPosition(unsigned int i)
|
2000-06-05 15:12:09 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
return i < saved_positions_num && !saved_positions[i].filename.empty();
|
2000-06-05 15:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2002-07-17 04:13:41 +00:00
|
|
|
|
void BufferView::Pimpl::switchKeyMap()
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
|
|
|
|
if (!lyxrc.rtl_support)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
Intl & intl = owner_->getIntl();
|
|
|
|
|
if (bv_->getLyXText()->real_current_font.isRightToLeft()) {
|
|
|
|
|
if (intl.keymap == Intl::PRIMARY)
|
|
|
|
|
intl.KeyMapSec();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
} else {
|
2003-11-10 09:06:48 +00:00
|
|
|
|
if (intl.keymap == Intl::SECONDARY)
|
|
|
|
|
intl.KeyMapPrim();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
void BufferView::Pimpl::center()
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2003-11-28 08:55:12 +00:00
|
|
|
|
LyXText * text = bv_->text();
|
2002-07-22 20:57:58 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bv_->cursor().clearSelection();
|
2002-07-09 16:19:14 +00:00
|
|
|
|
int const half_height = workarea().workHeight() / 2;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
int new_y = text->cursorY(bv_->cursor().cursor_.front()) - half_height;
|
|
|
|
|
if (new_y < 0)
|
|
|
|
|
new_y = 0;
|
2002-07-22 20:57:58 +00:00
|
|
|
|
|
2003-03-19 14:45:22 +00:00
|
|
|
|
// FIXME: look at this comment again ...
|
2003-03-06 20:21:21 +00:00
|
|
|
|
// This updates top_y() but means the fitCursor() call
|
2002-07-09 16:19:14 +00:00
|
|
|
|
// from the update(FITCUR) doesn't realise that we might
|
|
|
|
|
// have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
|
|
|
|
|
// the scrollbar to be updated as it should, so we have
|
|
|
|
|
// to do it manually. Any operation that does a center()
|
2003-03-06 20:21:21 +00:00
|
|
|
|
// and also might have moved top_y() must make sure to call
|
2002-07-22 20:57:58 +00:00
|
|
|
|
// updateScrollbar() currently. Never mind that this is a
|
2004-01-30 11:41:12 +00:00
|
|
|
|
// pretty obfuscated way of updating text->top_y()
|
2003-08-27 14:55:20 +00:00
|
|
|
|
top_y(new_y);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
2000-05-20 01:38:25 +00:00
|
|
|
|
|
|
|
|
|
|
2000-05-20 21:37:05 +00:00
|
|
|
|
void BufferView::Pimpl::stuffClipboard(string const & stuff) const
|
|
|
|
|
{
|
2002-06-11 22:38:49 +00:00
|
|
|
|
workarea().putClipboard(stuff);
|
2000-05-20 21:37:05 +00:00
|
|
|
|
}
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
InsetBase * BufferView::Pimpl::getInsetByCode(InsetBase::Code code)
|
2001-02-23 16:10:03 +00:00
|
|
|
|
{
|
2002-08-20 17:18:21 +00:00
|
|
|
|
// Ok, this is a little bit too brute force but it
|
2003-08-18 08:23:03 +00:00
|
|
|
|
// should work for now. Better infrastructure is coming. (Lgb)
|
2002-08-20 17:18:21 +00:00
|
|
|
|
|
|
|
|
|
Buffer * b = bv_->buffer();
|
2004-01-14 17:21:39 +00:00
|
|
|
|
LyXText * text = bv_->getLyXText();
|
2002-08-20 17:18:21 +00:00
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator beg = b->inset_iterator_begin();
|
|
|
|
|
Buffer::inset_iterator end = b->inset_iterator_end();
|
|
|
|
|
|
2003-12-10 09:45:32 +00:00
|
|
|
|
bool cursor_par_seen = false;
|
2002-08-20 20:04:24 +00:00
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
for (; beg != end; ++beg) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (beg.getPar() == text->cursorPar()) {
|
2003-12-10 09:45:32 +00:00
|
|
|
|
cursor_par_seen = true;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
2003-12-10 09:45:32 +00:00
|
|
|
|
if (cursor_par_seen) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (beg.getPar() == text->cursorPar()
|
2004-01-13 10:37:38 +00:00
|
|
|
|
&& beg.getPos() >= text->cursor().pos()) {
|
2002-08-20 17:18:21 +00:00
|
|
|
|
break;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
if (beg.getPar() != text->cursorPar()) {
|
2002-08-20 17:18:21 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-08-20 20:04:24 +00:00
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
if (beg != end) {
|
|
|
|
|
// Now find the first inset that matches code.
|
|
|
|
|
for (; beg != end; ++beg) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
if (beg->lyxCode() == code)
|
2002-08-20 17:18:21 +00:00
|
|
|
|
return &(*beg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
void BufferView::Pimpl::MenuInsertLyXFile(string const & filenm)
|
2001-02-23 16:10:03 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
string filename = filenm;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
|
|
|
|
if (filename.empty()) {
|
|
|
|
|
// Launch a file browser
|
|
|
|
|
string initpath = lyxrc.document_path;
|
|
|
|
|
|
|
|
|
|
if (available()) {
|
2002-01-14 23:31:23 +00:00
|
|
|
|
string const trypath = owner_->buffer()->filePath();
|
2001-02-23 16:10:03 +00:00
|
|
|
|
// If directory is writeable, use this as default.
|
2001-08-01 10:08:53 +00:00
|
|
|
|
if (IsDirWriteable(trypath))
|
2001-02-23 16:10:03 +00:00
|
|
|
|
initpath = trypath;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
|
FileDialog fileDlg(_("Select LyX document to insert"),
|
2001-03-07 14:25:31 +00:00
|
|
|
|
LFUN_FILE_INSERT,
|
2002-01-13 15:01:25 +00:00
|
|
|
|
make_pair(string(_("Documents|#o#O")),
|
2001-05-29 09:50:02 +00:00
|
|
|
|
string(lyxrc.document_path)),
|
2002-01-13 15:01:25 +00:00
|
|
|
|
make_pair(string(_("Examples|#E#e")),
|
2003-07-27 21:04:02 +00:00
|
|
|
|
string(AddPath(system_lyxdir(), "examples"))));
|
2001-05-29 09:50:02 +00:00
|
|
|
|
|
|
|
|
|
FileDialog::Result result =
|
2002-11-17 08:32:09 +00:00
|
|
|
|
fileDlg.open(initpath,
|
2004-01-08 10:59:51 +00:00
|
|
|
|
FileFilterList(_("LyX Documents (*.lyx)")),
|
|
|
|
|
string());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
filename = result.second;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
|
|
|
|
// check selected filename
|
|
|
|
|
if (filename.empty()) {
|
2001-04-24 17:33:01 +00:00
|
|
|
|
owner_->message(_("Canceled."));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2001-03-07 14:25:31 +00:00
|
|
|
|
}
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
// get absolute path of file and add ".lyx" to the filename if
|
|
|
|
|
// necessary
|
|
|
|
|
filename = FileSearch(string(), filename, "lyx");
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
string const disp_fn = MakeDisplayPath(filename);
|
|
|
|
|
owner_->message(bformat(_("Inserting document %1$s..."), disp_fn));
|
2003-07-10 12:26:40 +00:00
|
|
|
|
if (bv_->insertLyXFile(filename))
|
2003-07-25 17:11:25 +00:00
|
|
|
|
owner_->message(bformat(_("Document %1$s inserted."),
|
2003-07-10 12:26:40 +00:00
|
|
|
|
disp_fn));
|
2003-05-21 21:20:50 +00:00
|
|
|
|
else
|
2003-07-25 17:11:25 +00:00
|
|
|
|
owner_->message(bformat(_("Could not insert document %1$s"),
|
2003-07-10 12:26:40 +00:00
|
|
|
|
disp_fn));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
void BufferView::Pimpl::trackChanges()
|
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
Buffer * buf = bv_->buffer();
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bool const tracking(buf->params().tracking_changes);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
|
|
if (!tracking) {
|
|
|
|
|
ParIterator const end = buf->par_iterator_end();
|
2003-06-17 15:33:49 +00:00
|
|
|
|
for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
|
2003-06-12 11:09:55 +00:00
|
|
|
|
it->trackChanges();
|
2003-09-09 09:47:59 +00:00
|
|
|
|
buf->params().tracking_changes = true;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
|
|
// we cannot allow undos beyond the freeze point
|
2003-09-09 09:47:59 +00:00
|
|
|
|
buf->undostack().clear();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
} else {
|
2003-08-04 09:06:35 +00:00
|
|
|
|
update();
|
2003-11-28 08:55:12 +00:00
|
|
|
|
bv_->text()->setCursor(0, 0);
|
2003-03-02 12:16:00 +00:00
|
|
|
|
#warning changes FIXME
|
2003-07-27 12:02:58 +00:00
|
|
|
|
bool found = lyx::find::findNextChange(bv_);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (found) {
|
2003-03-09 21:03:43 +00:00
|
|
|
|
owner_->getDialogs().show("changes");
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParIterator const end = buf->par_iterator_end();
|
2003-06-12 11:09:55 +00:00
|
|
|
|
for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
|
|
|
|
|
it->untrackChanges();
|
2003-09-09 09:47:59 +00:00
|
|
|
|
buf->params().tracking_changes = false;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
buf->redostack().clear();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
|
2003-08-05 19:51:45 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
//
|
|
|
|
|
// this is only called for mouse related events.
|
|
|
|
|
//
|
|
|
|
|
FuncRequest cmd = cmd0;
|
|
|
|
|
cmd.y += bv_->top_y();
|
2004-02-06 09:34:04 +00:00
|
|
|
|
//lyxerr << "*** workAreaDispatch: request: " << cmd << std::endl;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
LCursor cur(*bv_);
|
2004-02-06 16:50:29 +00:00
|
|
|
|
cur.selection() = bv_->cursor().selection();
|
2003-11-10 09:06:48 +00:00
|
|
|
|
switch (cmd.action) {
|
2004-02-06 16:50:29 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
#if 0
|
2003-11-17 20:28:11 +00:00
|
|
|
|
case LFUN_MOUSE_MOTION: {
|
2003-12-12 10:31:09 +00:00
|
|
|
|
if (!available())
|
|
|
|
|
return false;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
FuncRequest cmd1 = cmd;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetBase * inset = cur.inset();
|
2003-11-17 20:28:11 +00:00
|
|
|
|
DispatchResult res;
|
|
|
|
|
if (inset) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
res = inset->dispatch(cur, cmd);
|
2003-11-17 20:28:11 +00:00
|
|
|
|
} else {
|
2004-02-02 16:38:13 +00:00
|
|
|
|
res = bv_->text()->dispatch(cur, cmd);
|
2003-11-17 20:28:11 +00:00
|
|
|
|
}
|
2003-11-22 14:44:59 +00:00
|
|
|
|
|
2004-02-02 17:32:56 +00:00
|
|
|
|
if (fitCursor() || res.update()) {
|
2004-02-11 14:45:44 +00:00
|
|
|
|
update();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.updatePos();
|
2003-11-17 20:28:11 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-02-06 16:50:29 +00:00
|
|
|
|
#else
|
|
|
|
|
case LFUN_MOUSE_MOTION:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
#endif
|
2003-11-17 20:28:11 +00:00
|
|
|
|
|
2003-08-05 19:51:45 +00:00
|
|
|
|
case LFUN_MOUSE_PRESS:
|
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
case LFUN_MOUSE_DOUBLE:
|
2003-11-10 09:06:48 +00:00
|
|
|
|
case LFUN_MOUSE_TRIPLE: {
|
2003-08-05 19:51:45 +00:00
|
|
|
|
// We pass those directly to the Bufferview, since
|
|
|
|
|
// otherwise selection handling breaks down
|
2003-03-24 02:31:44 +00:00
|
|
|
|
|
2003-08-05 19:51:45 +00:00
|
|
|
|
// Doesn't go through lyxfunc, so we need to update
|
|
|
|
|
// the layout choice etc. ourselves
|
2003-05-03 18:05:53 +00:00
|
|
|
|
|
2003-08-05 19:51:45 +00:00
|
|
|
|
// e.g. Qt mouse press when no buffer
|
|
|
|
|
if (!available())
|
|
|
|
|
return false;
|
2003-07-02 17:09:56 +00:00
|
|
|
|
|
2003-08-05 19:51:45 +00:00
|
|
|
|
screen().hideCursor();
|
2003-03-24 02:31:44 +00:00
|
|
|
|
|
2004-02-02 11:07:51 +00:00
|
|
|
|
// either the inset under the cursor or the
|
|
|
|
|
// surrounding LyXText will handle this event.
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
|
|
|
|
// built temporary path to inset
|
2004-01-30 11:41:12 +00:00
|
|
|
|
LyXText * text = bv_->text();
|
|
|
|
|
InsetBase * const inset_hit = text->checkInsetHit(cmd.x, cmd.y);
|
|
|
|
|
if (inset_hit)
|
|
|
|
|
inset_hit->edit(cur, cmd.x, cmd.y);
|
|
|
|
|
else
|
|
|
|
|
text->setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
|
|
|
|
|
lyxerr << "created temp cursor: " << cur << endl;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
// Dispatch to the temp cursor.
|
|
|
|
|
// An inset (or LyXText) can assign this to bv->cursor()
|
|
|
|
|
// if it wishes to do so.
|
|
|
|
|
DispatchResult res = cur.dispatch(cmd);
|
|
|
|
|
|
2004-02-02 17:32:56 +00:00
|
|
|
|
if (fitCursor() || res.update())
|
2004-02-11 14:45:44 +00:00
|
|
|
|
update();
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2003-08-05 19:51:45 +00:00
|
|
|
|
// see workAreaKeyPress
|
|
|
|
|
cursor_timeout.restart();
|
|
|
|
|
screen().showCursor(*bv_);
|
2003-05-03 18:05:53 +00:00
|
|
|
|
|
2003-11-13 08:50:26 +00:00
|
|
|
|
// skip these when selecting
|
|
|
|
|
if (cmd.action != LFUN_MOUSE_MOTION) {
|
|
|
|
|
owner_->updateLayoutChoice();
|
|
|
|
|
owner_->updateToolbar();
|
|
|
|
|
}
|
2003-03-24 02:31:44 +00:00
|
|
|
|
|
2003-08-05 19:51:45 +00:00
|
|
|
|
// slight hack: this is only called currently when we
|
|
|
|
|
// clicked somewhere, so we force through the display
|
|
|
|
|
// of the new status here.
|
|
|
|
|
owner_->clearMessage();
|
2003-11-10 09:06:48 +00:00
|
|
|
|
return true;
|
2003-08-05 19:51:45 +00:00
|
|
|
|
}
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2003-08-05 19:51:45 +00:00
|
|
|
|
default:
|
2004-02-06 09:34:04 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2003-08-05 19:51:45 +00:00
|
|
|
|
}
|
2004-01-30 11:41:12 +00:00
|
|
|
|
return true;
|
2003-03-24 02:31:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
|
2001-02-23 16:10:03 +00:00
|
|
|
|
{
|
2004-02-06 11:12:49 +00:00
|
|
|
|
//lyxerr << "*** BufferView::Pimpl: request: " << cmd << std::endl;
|
2003-02-26 19:28:38 +00:00
|
|
|
|
// Make sure that the cached BufferView is correct.
|
2002-08-28 08:30:27 +00:00
|
|
|
|
lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
<< " action[" << cmd.action << ']'
|
|
|
|
|
<< " arg[" << cmd.argument << ']'
|
|
|
|
|
<< " x[" << cmd.x << ']'
|
|
|
|
|
<< " y[" << cmd.y << ']'
|
|
|
|
|
<< " button[" << cmd.button() << ']'
|
2002-08-28 08:30:27 +00:00
|
|
|
|
<< endl;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv_->cursor();
|
2002-05-01 22:17:09 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
switch (cmd.action) {
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
2004-02-11 14:45:44 +00:00
|
|
|
|
case LFUN_UNDO:
|
|
|
|
|
if (available()) {
|
|
|
|
|
cur.message(_("Undo"));
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (!textUndo(*bv_))
|
|
|
|
|
cur.message(_("No further undo information"));
|
|
|
|
|
update();
|
|
|
|
|
switchKeyMap();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_REDO:
|
|
|
|
|
if (available()) {
|
|
|
|
|
cur.message(_("Redo"));
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (!textRedo(*bv_))
|
|
|
|
|
cur.message(_("No further redo information"));
|
|
|
|
|
update();
|
|
|
|
|
switchKeyMap();
|
|
|
|
|
}
|
2001-02-23 16:10:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_FILE_INSERT:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
MenuInsertLyXFile(cmd.argument);
|
2001-11-29 17:12:21 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
|
case LFUN_FILE_INSERT_ASCII_PARA:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
InsertAsciiFile(bv_, cmd.argument, true);
|
2001-03-07 14:25:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2001-02-23 16:10:03 +00:00
|
|
|
|
case LFUN_FILE_INSERT_ASCII:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
InsertAsciiFile(bv_, cmd.argument, false);
|
2001-03-07 14:25:31 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-02-23 16:10:03 +00:00
|
|
|
|
case LFUN_FONT_STATE:
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.message(cur.currentState());
|
2001-02-23 16:10:03 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-02-27 16:24:14 +00:00
|
|
|
|
case LFUN_INSERT_LABEL: {
|
|
|
|
|
// Try and generate a valid label
|
2004-01-30 11:41:12 +00:00
|
|
|
|
string const contents = cmd.argument.empty() ?
|
|
|
|
|
getPossibleLabel(*bv_) : cmd.argument;
|
2003-02-27 16:24:14 +00:00
|
|
|
|
InsetCommandParams icp("label", contents);
|
|
|
|
|
string data = InsetCommandMailer::params2string("label", icp);
|
|
|
|
|
owner_->getDialogs().show("label", data, 0);
|
2003-11-10 09:06:48 +00:00
|
|
|
|
break;
|
2003-02-27 16:24:14 +00:00
|
|
|
|
}
|
2001-11-09 13:44:48 +00:00
|
|
|
|
|
2001-02-23 16:10:03 +00:00
|
|
|
|
case LFUN_BOOKMARK_SAVE:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
savePosition(strToUnsignedInt(cmd.argument));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BOOKMARK_GOTO:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
restorePosition(strToUnsignedInt(cmd.argument));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2003-03-29 10:29:38 +00:00
|
|
|
|
case LFUN_REF_GOTO: {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
string label = cmd.argument;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
if (label.empty()) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
InsetRef * inset =
|
2004-01-26 10:13:15 +00:00
|
|
|
|
static_cast<InsetRef*>(getInsetByCode(InsetBase::REF_CODE));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
if (inset) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
label = inset->getContents();
|
2001-02-23 16:10:03 +00:00
|
|
|
|
savePosition(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-29 10:29:38 +00:00
|
|
|
|
if (!label.empty())
|
|
|
|
|
bv_->gotoLabel(label);
|
2004-02-13 07:30:59 +00:00
|
|
|
|
break;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
|
case LFUN_PARAGRAPH_APPLY:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
setParagraphParams(*bv_, cmd.argument);
|
2003-03-13 13:56:25 +00:00
|
|
|
|
break;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case LFUN_TRACK_CHANGES:
|
|
|
|
|
trackChanges();
|
|
|
|
|
break;
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case LFUN_MERGE_CHANGES:
|
2003-03-09 21:03:43 +00:00
|
|
|
|
owner_->getDialogs().show("changes");
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case LFUN_ACCEPT_ALL_CHANGES: {
|
2004-02-13 07:30:59 +00:00
|
|
|
|
bv_->cursor().reset();
|
2003-03-02 12:16:00 +00:00
|
|
|
|
#warning FIXME changes
|
2003-08-04 09:06:35 +00:00
|
|
|
|
while (lyx::find::findNextChange(bv_))
|
2004-02-13 07:30:59 +00:00
|
|
|
|
bv_->getLyXText()->acceptChange(bv_->cursor());
|
2003-08-04 09:06:35 +00:00
|
|
|
|
update();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case LFUN_REJECT_ALL_CHANGES: {
|
2004-02-13 07:30:59 +00:00
|
|
|
|
bv_->cursor().reset();
|
2003-03-02 12:16:00 +00:00
|
|
|
|
#warning FIXME changes
|
2003-08-04 09:06:35 +00:00
|
|
|
|
while (lyx::find::findNextChange(bv_))
|
2004-02-13 07:30:59 +00:00
|
|
|
|
bv_->getLyXText()->rejectChange(bv_->cursor());
|
2003-08-04 09:06:35 +00:00
|
|
|
|
update();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2004-01-07 17:00:03 +00:00
|
|
|
|
case LFUN_WORD_FIND:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
lyx::find::find(bv_, cmd);
|
2004-01-07 17:00:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_WORD_REPLACE:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
lyx::find::replace(bv_, cmd);
|
2004-01-07 17:00:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2004-01-14 17:21:39 +00:00
|
|
|
|
case LFUN_MARK_OFF:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
update();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-02-03 11:49:05 +00:00
|
|
|
|
cur.message(N_("Mark off"));
|
2004-01-14 17:21:39 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_MARK_ON:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
|
|
|
|
cur.mark() = true;
|
2004-02-11 14:45:44 +00:00
|
|
|
|
update();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-02-03 11:49:05 +00:00
|
|
|
|
cur.message(N_("Mark on"));
|
2004-01-14 17:21:39 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_SETMARK:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (cur.mark()) {
|
2004-02-03 11:49:05 +00:00
|
|
|
|
cur.message(N_("Mark removed"));
|
2004-01-14 17:21:39 +00:00
|
|
|
|
} else {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.mark() = true;
|
2004-02-03 11:49:05 +00:00
|
|
|
|
cur.message(N_("Mark set"));
|
2004-01-14 17:21:39 +00:00
|
|
|
|
}
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
update();
|
2004-01-14 17:21:39 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2001-02-23 16:10:03 +00:00
|
|
|
|
case LFUN_UNKNOWN_ACTION:
|
2004-02-03 11:49:05 +00:00
|
|
|
|
cur.errorMessage(N_("Unknown function!"));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-09-21 23:00:47 +00:00
|
|
|
|
default:
|
2004-02-03 09:08:15 +00:00
|
|
|
|
return false;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2001-05-18 07:37:14 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
bool BufferView::Pimpl::ChangeInsets(InsetBase::Code code,
|
2003-09-06 19:16:30 +00:00
|
|
|
|
string const & from, string const & to)
|
|
|
|
|
{
|
|
|
|
|
bool need_update = false;
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice cur = bv_->text()->cursor();
|
2003-09-06 19:16:30 +00:00
|
|
|
|
|
|
|
|
|
ParIterator end = bv_->buffer()->par_iterator_end();
|
|
|
|
|
for (ParIterator it = bv_->buffer()->par_iterator_begin();
|
|
|
|
|
it != end; ++it) {
|
|
|
|
|
bool changed_inset = false;
|
|
|
|
|
for (InsetList::iterator it2 = it->insetlist.begin();
|
|
|
|
|
it2 != it->insetlist.end(); ++it2) {
|
|
|
|
|
if (it2->inset->lyxCode() == code) {
|
|
|
|
|
InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
|
|
|
|
|
if (inset->getContents() == from) {
|
|
|
|
|
inset->setContents(to);
|
|
|
|
|
changed_inset = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (changed_inset) {
|
|
|
|
|
need_update = true;
|
|
|
|
|
|
|
|
|
|
// FIXME
|
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
// The test it.size() == 1 was needed to prevent crashes.
|
|
|
|
|
// How to set the cursor correctly when it.size() > 1 ??
|
2003-09-06 19:16:30 +00:00
|
|
|
|
if (it.size() == 1) {
|
2003-11-28 08:55:12 +00:00
|
|
|
|
bv_->text()->setCursorIntern(bv_->text()->parOffset(it.pit()), 0);
|
|
|
|
|
bv_->text()->redoParagraph(bv_->text()->cursorPar());
|
2003-09-06 19:16:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-01-13 10:37:38 +00:00
|
|
|
|
bv_->text()->setCursorIntern(cur.par(), cur.pos());
|
2003-09-06 19:16:30 +00:00
|
|
|
|
return need_update;
|
|
|
|
|
}
|