2002-06-12 02:54:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file BufferView.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-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-10-20 11:41:21 +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 John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
*
|
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
|
|
#include "BufferView.h"
|
2003-09-09 22:13:45 +00:00
|
|
|
|
|
2002-08-29 13:05:55 +00:00
|
|
|
|
#include "buffer.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2006-09-29 22:06:28 +00:00
|
|
|
|
#include "bufferlist.h"
|
2004-02-04 09:44:12 +00:00
|
|
|
|
#include "bufferparams.h"
|
2006-12-29 23:54:48 +00:00
|
|
|
|
#include "bufferview_funcs.h"
|
2004-11-30 01:59:49 +00:00
|
|
|
|
#include "coordcache.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2003-11-10 09:06:48 +00:00
|
|
|
|
#include "debug.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "dispatchresult.h"
|
|
|
|
|
#include "errorlist.h"
|
|
|
|
|
#include "factory.h"
|
|
|
|
|
#include "FloatList.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "funcrequest.h"
|
2004-04-01 08:58:45 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "gettext.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "intl.h"
|
2004-03-27 12:42:10 +00:00
|
|
|
|
#include "insetiterator.h"
|
2002-08-29 13:05:55 +00:00
|
|
|
|
#include "language.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
#include "lyx_cb.h" // added for Dispatch functions
|
|
|
|
|
#include "lyx_main.h"
|
|
|
|
|
#include "lyxfind.h"
|
|
|
|
|
#include "lyxfunc.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "lyxlayout.h"
|
2000-04-09 22:48:51 +00:00
|
|
|
|
#include "lyxtext.h"
|
2004-02-04 09:44:12 +00:00
|
|
|
|
#include "lyxtextclass.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "session.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-04-15 00:11:03 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2004-03-28 22:00:22 +00:00
|
|
|
|
#include "pariterator.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "texrow.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "toc.h"
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "undo.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "vspace.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "WordLangTuple.h"
|
2006-07-04 00:04:46 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "insets/insetbibtex.h"
|
|
|
|
|
#include "insets/insetcommand.h" // ChangeRefs
|
|
|
|
|
#include "insets/insetref.h"
|
|
|
|
|
#include "insets/insettext.h"
|
|
|
|
|
|
2002-08-29 13:05:55 +00:00
|
|
|
|
#include "frontends/Alert.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "frontends/FileDialog.h"
|
2006-10-07 16:15:06 +00:00
|
|
|
|
#include "frontends/FontMetrics.h"
|
2007-01-07 14:44:44 +00:00
|
|
|
|
#include "frontends/Selection.h"
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "graphics/Previews.h"
|
|
|
|
|
|
|
|
|
|
#include "support/convert.h"
|
|
|
|
|
#include "support/filefilterlist.h"
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
|
#include "support/package.h"
|
|
|
|
|
#include "support/types.h"
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
#include <boost/current_function.hpp>
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include <functional>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::addPath;
|
|
|
|
|
using support::bformat;
|
|
|
|
|
using support::FileFilterList;
|
2006-12-02 16:07:15 +00:00
|
|
|
|
using support::FileName;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::fileSearch;
|
|
|
|
|
using support::isDirWriteable;
|
2006-12-02 16:07:15 +00:00
|
|
|
|
using support::isFileReadable;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::makeDisplayPath;
|
|
|
|
|
using support::package;
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2004-01-28 16:21:29 +00:00
|
|
|
|
using std::distance;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
using std::istringstream;
|
|
|
|
|
using std::make_pair;
|
|
|
|
|
using std::min;
|
|
|
|
|
using std::max;
|
|
|
|
|
using std::mem_fun_ref;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::vector;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace Alert = frontend::Alert;
|
2006-10-07 16:47:54 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
/// Return an inset of this class if it exists at the current cursor position
|
|
|
|
|
template <class T>
|
|
|
|
|
T * getInsetByCode(LCursor & cur, InsetBase::Code code)
|
|
|
|
|
{
|
|
|
|
|
T * inset = 0;
|
|
|
|
|
DocIterator it = cur;
|
|
|
|
|
if (it.nextInset() &&
|
|
|
|
|
it.nextInset()->lyxCode() == code) {
|
|
|
|
|
inset = static_cast<T*>(it.nextInset());
|
|
|
|
|
}
|
|
|
|
|
return inset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
|
|
2006-09-26 10:06:46 +00:00
|
|
|
|
BufferView::BufferView()
|
2006-10-29 16:16:00 +00:00
|
|
|
|
: width_(0), height_(0), buffer_(0), wh_(0),
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cursor_(*this),
|
2006-09-17 10:03:00 +00:00
|
|
|
|
multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0),
|
2006-12-15 21:39:57 +00:00
|
|
|
|
intl_(new Intl), last_inset_(0)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
{
|
|
|
|
|
xsel_cache_.set = false;
|
2006-09-17 10:03:00 +00:00
|
|
|
|
intl_->initKeyMapper(lyxrc.use_kbmap);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
BufferView::~BufferView()
|
|
|
|
|
{
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer * BufferView::buffer() const
|
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return buffer_;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void BufferView::setBuffer(Buffer * b)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "[ b = " << b << "]" << endl;
|
|
|
|
|
|
|
|
|
|
if (buffer_) {
|
|
|
|
|
// Save the actual cursor position and anchor inside the
|
|
|
|
|
// buffer so that it can be restored in case we rechange
|
|
|
|
|
// to this buffer later on.
|
|
|
|
|
buffer_->saveCursor(cursor_.selectionBegin(),
|
|
|
|
|
cursor_.selectionEnd());
|
2007-01-28 21:12:33 +00:00
|
|
|
|
// update bookmark pit of the current buffer before switch
|
|
|
|
|
for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i) {
|
|
|
|
|
BookmarksSection::Bookmark const & bm = LyX::ref().session().bookmarks().bookmark(i);
|
|
|
|
|
if (buffer()->fileName() != bm.filename.absFilename())
|
|
|
|
|
continue;
|
|
|
|
|
// if par_id or pit has been changed, reset par_pit and par_id
|
|
|
|
|
// see http://bugzilla.lyx.org/show_bug.cgi?id=3092
|
|
|
|
|
pit_type new_pit;
|
|
|
|
|
int new_id;
|
|
|
|
|
boost::tie(new_pit, new_id) = moveToPosition(bm.par_pit, bm.par_id, bm.par_pos);
|
|
|
|
|
if (bm.par_pit != new_pit || bm.par_id != new_id)
|
|
|
|
|
const_cast<BookmarksSection::Bookmark &>(bm).setPos(new_pit, new_id);
|
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// current buffer is going to be switched-off, save cursor pos
|
2006-12-02 16:07:15 +00:00
|
|
|
|
LyX::ref().session().lastFilePos().save(FileName(buffer_->fileName()),
|
2006-09-16 10:08:51 +00:00
|
|
|
|
boost::tie(cursor_.pit(), cursor_.pos()) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we're quitting lyx, don't bother updating stuff
|
|
|
|
|
if (quitting) {
|
|
|
|
|
buffer_ = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we are closing current buffer, switch to the first in
|
|
|
|
|
// buffer list.
|
|
|
|
|
if (!b) {
|
|
|
|
|
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " No Buffer!" << endl;
|
|
|
|
|
// We are closing the buffer, use the first buffer as current
|
2006-10-11 17:24:46 +00:00
|
|
|
|
buffer_ = theBufferList().first();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Set current buffer
|
|
|
|
|
buffer_ = b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reset old cursor
|
|
|
|
|
cursor_ = LCursor(*this);
|
|
|
|
|
anchor_ref_ = 0;
|
|
|
|
|
offset_ref_ = 0;
|
|
|
|
|
|
|
|
|
|
if (buffer_) {
|
|
|
|
|
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "Buffer addr: " << buffer_ << endl;
|
|
|
|
|
cursor_.push(buffer_->inset());
|
|
|
|
|
cursor_.resetAnchor();
|
|
|
|
|
buffer_->text().setCurrentFont(cursor_);
|
|
|
|
|
if (buffer_->getCursor().size() > 0 &&
|
|
|
|
|
buffer_->getAnchor().size() > 0)
|
|
|
|
|
{
|
|
|
|
|
cursor_.setCursor(buffer_->getAnchor().asDocIterator(&(buffer_->inset())));
|
|
|
|
|
cursor_.resetAnchor();
|
|
|
|
|
cursor_.setCursor(buffer_->getCursor().asDocIterator(&(buffer_->inset())));
|
|
|
|
|
cursor_.setSelection();
|
2007-01-07 14:44:44 +00:00
|
|
|
|
theSelection().haveSelection(cursor_.selection());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-20 16:43:36 +00:00
|
|
|
|
if (buffer_)
|
|
|
|
|
updateMetrics(false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (buffer_ && graphics::Previews::status() != LyXRC::PREVIEW_OFF)
|
|
|
|
|
graphics::Previews::get().generateBufferPreviews(*buffer_);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-02 16:07:15 +00:00
|
|
|
|
bool BufferView::loadLyXFile(FileName const & filename, bool tolastfiles)
|
2003-06-20 12:46:28 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// File already open?
|
2006-12-02 16:07:15 +00:00
|
|
|
|
if (theBufferList().exists(filename.absFilename())) {
|
|
|
|
|
docstring const file = makeDisplayPath(filename.absFilename(), 20);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
docstring 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) {
|
2006-12-02 16:07:15 +00:00
|
|
|
|
setBuffer(theBufferList().getBuffer(filename.absFilename()));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// FIXME: should be LFUN_REVERT
|
2006-12-02 16:07:15 +00:00
|
|
|
|
if (!theBufferList().close(theBufferList().getBuffer(filename.absFilename()), false))
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return false;
|
|
|
|
|
// Fall through to new load. (Asger)
|
2006-10-26 13:29:10 +00:00
|
|
|
|
buffer_ = 0;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer * b = 0;
|
|
|
|
|
|
2006-12-02 16:07:15 +00:00
|
|
|
|
if (isFileReadable(filename)) {
|
|
|
|
|
b = theBufferList().newBuffer(filename.absFilename());
|
|
|
|
|
if (!lyx::loadLyXFile(b, filename)) {
|
2006-10-11 17:24:46 +00:00
|
|
|
|
theBufferList().release(b);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
docstring text = bformat(_("The document %1$s does not yet "
|
|
|
|
|
"exist.\n\nDo you want to create "
|
2006-12-02 16:07:15 +00:00
|
|
|
|
"a new document?"), from_utf8(filename.absFilename()));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int const ret = Alert::prompt(_("Create new document?"),
|
|
|
|
|
text, 0, 1, _("&Create"), _("Cancel"));
|
|
|
|
|
|
|
|
|
|
if (ret == 0) {
|
2006-12-02 16:07:15 +00:00
|
|
|
|
b = newFile(filename.absFilename(), string(), true);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (!b)
|
|
|
|
|
return false;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setBuffer(b);
|
|
|
|
|
// Send the "errors" signal in case of parsing errors
|
|
|
|
|
b->errors("Parse");
|
|
|
|
|
|
2007-01-11 08:34:23 +00:00
|
|
|
|
// Update the labels and section numbering.
|
|
|
|
|
updateLabels(*buffer_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// scroll to the position when the file was last closed
|
|
|
|
|
if (lyxrc.use_lastfilepos) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
pit_type pit;
|
|
|
|
|
pos_type pos;
|
2006-12-02 16:07:15 +00:00
|
|
|
|
boost::tie(pit, pos) = LyX::ref().session().lastFilePos().load(filename);
|
2007-01-11 16:01:10 +00:00
|
|
|
|
// if successfully move to pit (returned par_id is not zero), update metrics
|
|
|
|
|
if (moveToPosition(pit, 0, pos).get<1>()) {
|
|
|
|
|
if (fitCursor())
|
|
|
|
|
updateMetrics(false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tolastfiles)
|
2006-12-02 16:07:15 +00:00
|
|
|
|
LyX::ref().session().lastFiles().add(FileName(b->fileName()));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
2003-06-20 12:46:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
void BufferView::resize()
|
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (!buffer_)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << endl;
|
|
|
|
|
|
2006-12-15 16:16:20 +00:00
|
|
|
|
updateMetrics(false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
switchKeyMap();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-29 15:49:45 +00:00
|
|
|
|
bool BufferView::fitCursor()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (bv_funcs::status(this, cursor_) == bv_funcs::CUR_INSIDE) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
frontend::FontMetrics const & fm =
|
2006-10-11 17:24:46 +00:00
|
|
|
|
theFontMetrics(cursor_.getFont());
|
2006-10-07 16:15:06 +00:00
|
|
|
|
int const asc = fm.maxAscent();
|
|
|
|
|
int const des = fm.maxDescent();
|
2006-10-13 16:44:44 +00:00
|
|
|
|
Point const p = bv_funcs::getPos(*this, cursor_, cursor_.boundary());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (p.y_ - asc >= 0 && p.y_ + des < height_)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
center();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BufferView::multiParSel()
|
|
|
|
|
{
|
|
|
|
|
if (!cursor_.selection())
|
|
|
|
|
return false;
|
|
|
|
|
bool ret = multiparsel_cache_;
|
|
|
|
|
multiparsel_cache_ = cursor_.selBegin().pit() != cursor_.selEnd().pit();
|
|
|
|
|
// Either this, or previous selection spans paragraphs
|
|
|
|
|
return ret || multiparsel_cache_;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-07 11:46:27 +00:00
|
|
|
|
bool BufferView::update(Update::flags flags)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-01-03 23:05:27 +00:00
|
|
|
|
// last_inset_ points to the last visited inset. This pointer may become
|
2007-01-04 19:59:58 +00:00
|
|
|
|
// invalid because of keyboard editing. Since all such operations
|
2007-01-03 23:05:27 +00:00
|
|
|
|
// causes screen update(), I reset last_inset_ to avoid such a problem.
|
|
|
|
|
last_inset_ = 0;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// This is close to a hot-path.
|
|
|
|
|
if (lyxerr.debugging(Debug::DEBUG)) {
|
|
|
|
|
lyxerr[Debug::DEBUG]
|
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "[fitcursor = " << (flags & Update::FitCursor)
|
|
|
|
|
<< ", forceupdate = " << (flags & Update::Force)
|
|
|
|
|
<< ", singlepar = " << (flags & Update::SinglePar)
|
|
|
|
|
<< "] buffer: " << buffer_ << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check needed to survive LyX startup
|
|
|
|
|
if (!buffer_)
|
2006-12-07 11:46:27 +00:00
|
|
|
|
return false;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2006-11-07 21:31:33 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::WORKAREA)) {
|
|
|
|
|
lyxerr[Debug::WORKAREA] << "BufferView::update" << std::endl;
|
|
|
|
|
}
|
2006-10-21 10:56:36 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// Update macro store
|
|
|
|
|
buffer_->buildMacros();
|
|
|
|
|
|
2006-11-17 17:42:52 +00:00
|
|
|
|
// Now do the first drawing step if needed. This consists on updating
|
|
|
|
|
// the CoordCache in updateMetrics().
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// The second drawing step is done in WorkArea::redraw() if needed.
|
|
|
|
|
|
2006-11-17 17:42:52 +00:00
|
|
|
|
// Case when no explicit update is requested.
|
2006-11-20 14:42:18 +00:00
|
|
|
|
if (!flags) {
|
2006-12-07 11:46:27 +00:00
|
|
|
|
// no need to redraw anything.
|
2007-01-20 01:23:07 +00:00
|
|
|
|
metrics_info_.update_strategy = NoScreenUpdate;
|
2006-12-07 11:46:27 +00:00
|
|
|
|
return false;
|
2006-11-17 17:42:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-01-20 01:23:07 +00:00
|
|
|
|
if (flags == Update::Decoration) {
|
|
|
|
|
metrics_info_.update_strategy = DecorationUpdate;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags == Update::FitCursor
|
|
|
|
|
|| flags == (Update::Decoration | Update::FitCursor)) {
|
2006-11-21 16:58:45 +00:00
|
|
|
|
bool const fit_cursor = fitCursor();
|
2006-12-07 11:46:27 +00:00
|
|
|
|
// tell the frontend to update the screen if needed.
|
2007-01-20 01:23:07 +00:00
|
|
|
|
if (fit_cursor) {
|
|
|
|
|
updateMetrics(false);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (flags & Update::Decoration) {
|
|
|
|
|
metrics_info_.update_strategy = DecorationUpdate;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// no screen update is needed.
|
|
|
|
|
metrics_info_.update_strategy = NoScreenUpdate;
|
|
|
|
|
return false;
|
2006-11-21 16:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-20 14:42:18 +00:00
|
|
|
|
bool full_metrics = flags & Update::Force;
|
|
|
|
|
if (flags & Update::MultiParSel)
|
|
|
|
|
full_metrics |= multiParSel();
|
|
|
|
|
|
|
|
|
|
bool const single_par = !full_metrics;
|
2006-11-17 17:42:52 +00:00
|
|
|
|
updateMetrics(single_par);
|
|
|
|
|
|
2006-11-20 14:42:18 +00:00
|
|
|
|
if (flags & Update::FitCursor && fitCursor())
|
|
|
|
|
updateMetrics(false);
|
2006-11-17 17:42:52 +00:00
|
|
|
|
|
2006-11-20 14:42:18 +00:00
|
|
|
|
// tell the frontend to update the screen.
|
2006-12-07 11:46:27 +00:00
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::updateScrollbar()
|
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (!buffer_) {
|
|
|
|
|
lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " no text in updateScrollbar" << endl;
|
|
|
|
|
scrollbarParameters_.reset();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LyXText & t = buffer_->text();
|
2006-12-29 23:54:48 +00:00
|
|
|
|
TextMetrics & tm = text_metrics_[&t];
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int const parsize = int(t.paragraphs().size() - 1);
|
|
|
|
|
if (anchor_ref_ > parsize) {
|
|
|
|
|
anchor_ref_ = parsize;
|
|
|
|
|
offset_ref_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-07 21:31:33 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::GUI)) {
|
|
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " Updating scrollbar: height: " << t.paragraphs().size()
|
|
|
|
|
<< " curr par: " << cursor_.bottom().pit()
|
|
|
|
|
<< " default height " << defaultRowHeight() << endl;
|
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// It would be better to fix the scrollbar to understand
|
|
|
|
|
// values in [0..1] and divide everything by wh
|
|
|
|
|
|
|
|
|
|
// estimated average paragraph height:
|
|
|
|
|
if (wh_ == 0)
|
|
|
|
|
wh_ = height_ / 4;
|
2006-12-29 23:54:48 +00:00
|
|
|
|
|
|
|
|
|
int h = tm.parMetrics(anchor_ref_).height();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// Normalize anchor/offset (MV):
|
|
|
|
|
while (offset_ref_ > h && anchor_ref_ < parsize) {
|
|
|
|
|
anchor_ref_++;
|
|
|
|
|
offset_ref_ -= h;
|
2006-12-29 23:54:48 +00:00
|
|
|
|
h = tm.parMetrics(anchor_ref_).height();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
// Look at paragraph heights on-screen
|
|
|
|
|
int sumh = 0;
|
|
|
|
|
int nh = 0;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
for (pit_type pit = anchor_ref_; pit <= parsize; ++pit) {
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (sumh > height_)
|
|
|
|
|
break;
|
2006-12-29 23:54:48 +00:00
|
|
|
|
int const h2 = tm.parMetrics(pit).height();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
sumh += h2;
|
|
|
|
|
nh++;
|
|
|
|
|
}
|
2006-10-26 08:10:22 +00:00
|
|
|
|
|
|
|
|
|
BOOST_ASSERT(nh);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int const hav = sumh / nh;
|
|
|
|
|
// More realistic average paragraph height
|
|
|
|
|
if (hav > wh_)
|
|
|
|
|
wh_ = hav;
|
|
|
|
|
|
2006-10-26 08:10:22 +00:00
|
|
|
|
BOOST_ASSERT(h);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
scrollbarParameters_.height = (parsize + 1) * wh_;
|
|
|
|
|
scrollbarParameters_.position = anchor_ref_ * wh_ + int(offset_ref_ * wh_ / float(h));
|
|
|
|
|
scrollbarParameters_.lineScrollHeight = int(wh_ * defaultRowHeight() / float(h));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
ScrollbarParameters const & BufferView::scrollbarParameters() const
|
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return scrollbarParameters_;
|
2006-06-26 16:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
|
void BufferView::scrollDocView(int value)
|
2001-02-19 16:01:31 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "[ value = " << value << "]" << endl;
|
|
|
|
|
|
|
|
|
|
if (!buffer_)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LyXText & t = buffer_->text();
|
2006-12-29 23:54:48 +00:00
|
|
|
|
TextMetrics & tm = text_metrics_[&t];
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
float const bar = value / float(wh_ * t.paragraphs().size());
|
|
|
|
|
|
|
|
|
|
anchor_ref_ = int(bar * t.paragraphs().size());
|
|
|
|
|
if (anchor_ref_ > int(t.paragraphs().size()) - 1)
|
|
|
|
|
anchor_ref_ = int(t.paragraphs().size()) - 1;
|
2006-12-29 23:54:48 +00:00
|
|
|
|
|
|
|
|
|
tm.redoParagraph(anchor_ref_);
|
|
|
|
|
int const h = tm.parMetrics(anchor_ref_).height();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
offset_ref_ = int((bar * t.paragraphs().size() - anchor_ref_) * h);
|
2006-11-20 14:42:18 +00:00
|
|
|
|
updateMetrics(false);
|
2001-02-19 16:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-08-16 15:24:38 +00:00
|
|
|
|
void BufferView::setCursorFromScrollbar()
|
|
|
|
|
{
|
2007-01-29 10:05:41 +00:00
|
|
|
|
if (!buffer_)
|
2007-01-29 10:04:02 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
LyXText & t = buffer_->text();
|
|
|
|
|
|
|
|
|
|
int const height = 2 * defaultRowHeight();
|
|
|
|
|
int const first = height;
|
|
|
|
|
int const last = height_ - height;
|
|
|
|
|
LCursor & cur = cursor_;
|
|
|
|
|
|
|
|
|
|
bv_funcs::CurStatus st = bv_funcs::status(this, cur);
|
|
|
|
|
|
|
|
|
|
switch (st) {
|
|
|
|
|
case bv_funcs::CUR_ABOVE:
|
2007-01-27 09:04:36 +00:00
|
|
|
|
// We reset the cursor because bv_funcs::status() does not
|
|
|
|
|
// work when the cursor is within mathed.
|
|
|
|
|
cur.reset(buffer_->inset());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
t.setCursorFromCoordinates(cur, 0, first);
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
break;
|
|
|
|
|
case bv_funcs::CUR_BELOW:
|
2007-01-27 09:04:36 +00:00
|
|
|
|
// We reset the cursor because bv_funcs::status() does not
|
|
|
|
|
// work when the cursor is within mathed.
|
|
|
|
|
cur.reset(buffer_->inset());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
t.setCursorFromCoordinates(cur, 0, last);
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
break;
|
|
|
|
|
case bv_funcs::CUR_INSIDE:
|
2006-10-13 16:44:44 +00:00
|
|
|
|
int const y = bv_funcs::getPos(*this, cur, cur.boundary()).y_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int const newy = min(last, max(y, first));
|
|
|
|
|
if (y != newy) {
|
|
|
|
|
cur.reset(buffer_->inset());
|
|
|
|
|
t.setCursorFromCoordinates(cur, 0, newy);
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-08-16 15:24:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 20:01:32 +00:00
|
|
|
|
Change const BufferView::getCurrentChange() const
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2006-10-06 18:53:35 +00:00
|
|
|
|
if (!cursor_.selection())
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return Change(Change::UNCHANGED);
|
|
|
|
|
|
|
|
|
|
DocIterator dit = cursor_.selectionBegin();
|
|
|
|
|
return dit.paragraph().lookupChange(dit.pos());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2006-11-01 15:55:17 +00:00
|
|
|
|
void BufferView::saveBookmark(bool persistent)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-11-01 15:55:17 +00:00
|
|
|
|
LyX::ref().session().bookmarks().save(
|
2006-12-02 16:07:15 +00:00
|
|
|
|
FileName(buffer_->fileName()),
|
2007-01-11 16:01:10 +00:00
|
|
|
|
cursor_.pit(),
|
2006-11-01 15:55:17 +00:00
|
|
|
|
cursor_.paragraph().id(),
|
|
|
|
|
cursor_.pos(),
|
|
|
|
|
persistent
|
|
|
|
|
);
|
|
|
|
|
if (persistent)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// emit message signal.
|
2006-11-01 15:55:17 +00:00
|
|
|
|
message(_("Save bookmark"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-11 16:01:10 +00:00
|
|
|
|
boost::tuple<pit_type, int> BufferView::moveToPosition(pit_type par_pit, int par_id, pos_type par_pos)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cursor_.clearSelection();
|
|
|
|
|
|
2007-01-11 16:01:10 +00:00
|
|
|
|
// if a valid par_id is given, try it first
|
|
|
|
|
if (par_id > 0) {
|
|
|
|
|
ParIterator par = buffer_->getParFromID(par_id);
|
|
|
|
|
if (par != buffer_->par_iterator_end()) {
|
|
|
|
|
setCursor(makeDocIterator(par, min(par->size(), par_pos)));
|
|
|
|
|
return boost::make_tuple(cursor_.pit(), par_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// if par_id == 0, or searching through par_id failed
|
|
|
|
|
if (static_cast<size_t>(par_pit) < buffer_->paragraphs().size()) {
|
|
|
|
|
ParIterator it = buffer_->par_iterator_begin();
|
|
|
|
|
ParIterator const end = buffer_->par_iterator_end();
|
|
|
|
|
for (; it != end; ++it)
|
|
|
|
|
if (it.pit() == par_pit) {
|
|
|
|
|
// restored pos may be bigger than it->size
|
|
|
|
|
setCursor(makeDocIterator(it, min(par_pos, it->size())));
|
|
|
|
|
return boost::make_tuple(par_pit, it->id());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// both methods fail
|
|
|
|
|
return boost::make_tuple(pit_type(0), 0);
|
2000-06-05 15:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-17 04:13:41 +00:00
|
|
|
|
void BufferView::switchKeyMap()
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (!lyxrc.rtl_support)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (getLyXText()->real_current_font.isRightToLeft()) {
|
2006-09-17 10:03:00 +00:00
|
|
|
|
if (intl_->keymap == Intl::PRIMARY)
|
|
|
|
|
intl_->keyMapSec();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
} else {
|
2006-09-17 10:03:00 +00:00
|
|
|
|
if (intl_->keymap == Intl::SECONDARY)
|
|
|
|
|
intl_->keyMapPrim();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
2000-01-07 03:42:16 +00:00
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
int BufferView::workWidth() const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return width_;
|
2000-02-23 16:39:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
void BufferView::center()
|
2000-02-17 19:59:08 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
CursorSlice & bot = cursor_.bottom();
|
2006-12-29 23:54:48 +00:00
|
|
|
|
TextMetrics & tm = text_metrics_[bot.text()];
|
2006-10-21 00:16:43 +00:00
|
|
|
|
pit_type const pit = bot.pit();
|
2006-12-29 23:54:48 +00:00
|
|
|
|
tm.redoParagraph(pit);
|
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(pit);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
anchor_ref_ = pit;
|
2006-10-17 16:23:27 +00:00
|
|
|
|
offset_ref_ = bv_funcs::coordOffset(*this, cursor_, cursor_.boundary()).y_
|
2006-12-29 23:54:48 +00:00
|
|
|
|
+ pm.ascent() - height_ / 2;
|
2000-02-17 19:59:08 +00:00
|
|
|
|
}
|
2000-05-20 01:38:25 +00:00
|
|
|
|
|
|
|
|
|
|
2004-04-01 08:58:45 +00:00
|
|
|
|
FuncStatus BufferView::getStatus(FuncRequest const & cmd)
|
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
FuncStatus flag;
|
|
|
|
|
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_UNDO:
|
|
|
|
|
flag.enabled(!buffer_->undostack().empty());
|
|
|
|
|
break;
|
|
|
|
|
case LFUN_REDO:
|
|
|
|
|
flag.enabled(!buffer_->redostack().empty());
|
|
|
|
|
break;
|
|
|
|
|
case LFUN_FILE_INSERT:
|
2007-01-15 22:49:14 +00:00
|
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
|
|
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT:
|
2006-09-16 10:08:51 +00:00
|
|
|
|
case LFUN_BOOKMARK_SAVE:
|
|
|
|
|
// FIXME: Actually, these LFUNS should be moved to LyXText
|
|
|
|
|
flag.enabled(cursor_.inTexted());
|
|
|
|
|
break;
|
|
|
|
|
case LFUN_FONT_STATE:
|
|
|
|
|
case LFUN_LABEL_INSERT:
|
|
|
|
|
case LFUN_PARAGRAPH_GOTO:
|
|
|
|
|
// FIXME handle non-trivially
|
|
|
|
|
case LFUN_OUTLINE_UP:
|
|
|
|
|
case LFUN_OUTLINE_DOWN:
|
|
|
|
|
case LFUN_OUTLINE_IN:
|
|
|
|
|
case LFUN_OUTLINE_OUT:
|
|
|
|
|
case LFUN_NOTE_NEXT:
|
|
|
|
|
case LFUN_REFERENCE_NEXT:
|
|
|
|
|
case LFUN_WORD_FIND:
|
|
|
|
|
case LFUN_WORD_REPLACE:
|
|
|
|
|
case LFUN_MARK_OFF:
|
|
|
|
|
case LFUN_MARK_ON:
|
|
|
|
|
case LFUN_MARK_TOGGLE:
|
|
|
|
|
case LFUN_SCREEN_RECENTER:
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_ADD:
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_DEL:
|
|
|
|
|
case LFUN_WORDS_COUNT:
|
|
|
|
|
case LFUN_NEXT_INSET_TOGGLE:
|
|
|
|
|
flag.enabled(true);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_LABEL_GOTO: {
|
|
|
|
|
flag.enabled(!cmd.argument().empty()
|
|
|
|
|
|| getInsetByCode<InsetRef>(cursor_, InsetBase::REF_CODE));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_CHANGES_TRACK:
|
|
|
|
|
flag.enabled(true);
|
2006-10-06 18:53:35 +00:00
|
|
|
|
flag.setOnOff(buffer_->params().trackChanges);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_CHANGES_OUTPUT: {
|
|
|
|
|
OutputParams runparams;
|
|
|
|
|
LaTeXFeatures features(*buffer_, buffer_->params(), runparams);
|
2006-10-06 18:53:35 +00:00
|
|
|
|
flag.enabled(buffer_ && features.isAvailable("dvipost"));
|
|
|
|
|
flag.setOnOff(buffer_->params().outputChanges);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_CHANGES_MERGE:
|
2006-10-04 21:43:40 +00:00
|
|
|
|
case LFUN_CHANGE_NEXT:
|
2006-09-16 10:08:51 +00:00
|
|
|
|
case LFUN_ALL_CHANGES_ACCEPT:
|
|
|
|
|
case LFUN_ALL_CHANGES_REJECT:
|
2006-11-24 23:01:24 +00:00
|
|
|
|
// TODO: context-sensitive enabling of LFUNs
|
|
|
|
|
// In principle, these command should only be enabled if there
|
|
|
|
|
// is a change in the document. However, without proper
|
|
|
|
|
// optimizations, this will inevitably result in poor performance.
|
|
|
|
|
flag.enabled(buffer_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BUFFER_TOGGLE_COMPRESSION: {
|
|
|
|
|
flag.setOnOff(buffer_->params().compressed);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flag;
|
2004-04-01 08:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-24 23:10:03 +00:00
|
|
|
|
Update::flags BufferView::dispatch(FuncRequest const & cmd)
|
2001-02-23 16:10:03 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION
|
|
|
|
|
// << [ cmd = " << cmd << "]" << endl;
|
|
|
|
|
|
|
|
|
|
// Make sure that the cached BufferView is correct.
|
|
|
|
|
lyxerr[Debug::ACTION] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " action[" << cmd.action << ']'
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< " arg[" << to_utf8(cmd.argument()) << ']'
|
2006-09-16 10:08:51 +00:00
|
|
|
|
<< " x[" << cmd.x << ']'
|
|
|
|
|
<< " y[" << cmd.y << ']'
|
|
|
|
|
<< " button[" << cmd.button() << ']'
|
|
|
|
|
<< endl;
|
|
|
|
|
|
2007-01-24 23:10:03 +00:00
|
|
|
|
// FIXME: this should not be possible.
|
|
|
|
|
if (!buffer_)
|
|
|
|
|
return Update::None;
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
LCursor & cur = cursor_;
|
2007-01-24 23:10:03 +00:00
|
|
|
|
// Default Update flags.
|
|
|
|
|
Update::flags updateFlags = Update::Force | Update::FitCursor;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_UNDO:
|
2007-01-24 23:10:03 +00:00
|
|
|
|
cur.message(_("Undo"));
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (!textUndo(*this)) {
|
|
|
|
|
cur.message(_("No further undo information"));
|
|
|
|
|
updateFlags = Update::None;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2007-01-24 23:10:03 +00:00
|
|
|
|
switchKeyMap();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_REDO:
|
2007-01-24 23:10:03 +00:00
|
|
|
|
cur.message(_("Redo"));
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (!textRedo(*this)) {
|
|
|
|
|
cur.message(_("No further redo information"));
|
|
|
|
|
updateFlags = Update::None;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2007-01-24 23:10:03 +00:00
|
|
|
|
switchKeyMap();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_FILE_INSERT:
|
2006-12-04 14:45:17 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
menuInsertLyXFile(to_utf8(cmd.argument()));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-01-15 22:49:14 +00:00
|
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
|
2006-12-04 14:45:17 +00:00
|
|
|
|
// FIXME UNICODE
|
2007-01-15 22:49:14 +00:00
|
|
|
|
insertPlaintextFile(this, to_utf8(cmd.argument()), true);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-01-15 22:49:14 +00:00
|
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT:
|
2006-12-04 14:45:17 +00:00
|
|
|
|
// FIXME UNICODE
|
2007-01-15 22:49:14 +00:00
|
|
|
|
insertPlaintextFile(this, to_utf8(cmd.argument()), false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_FONT_STATE:
|
2006-12-21 13:58:28 +00:00
|
|
|
|
cur.message(cur.currentState());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BOOKMARK_SAVE:
|
2006-11-01 15:55:17 +00:00
|
|
|
|
saveBookmark(convert<unsigned int>(to_utf8(cmd.argument())));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_LABEL_GOTO: {
|
2006-10-12 10:50:45 +00:00
|
|
|
|
docstring label = cmd.argument();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (label.empty()) {
|
|
|
|
|
InsetRef * inset =
|
|
|
|
|
getInsetByCode<InsetRef>(cursor_,
|
|
|
|
|
InsetBase::REF_CODE);
|
|
|
|
|
if (inset) {
|
2006-10-20 16:12:49 +00:00
|
|
|
|
label = inset->getParam("reference");
|
2006-11-01 15:55:17 +00:00
|
|
|
|
// persistent=false: use temp_bookmark
|
|
|
|
|
saveBookmark(false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!label.empty())
|
|
|
|
|
gotoLabel(label);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_PARAGRAPH_GOTO: {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
int const id = convert<int>(to_utf8(cmd.argument()));
|
2006-11-13 16:53:49 +00:00
|
|
|
|
int i = 0;
|
|
|
|
|
for (Buffer * b = buffer_; i == 0 || b != buffer_; b = theBufferList().next(b)) {
|
|
|
|
|
ParIterator par = b->getParFromID(id);
|
|
|
|
|
if (par == b->par_iterator_end()) {
|
|
|
|
|
lyxerr[Debug::INFO]
|
|
|
|
|
<< "No matching paragraph found! ["
|
|
|
|
|
<< id << "]." << endl;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::INFO]
|
|
|
|
|
<< "Paragraph " << par->id()
|
|
|
|
|
<< " found in buffer `"
|
|
|
|
|
<< b->fileName() << "'." << endl;
|
|
|
|
|
|
|
|
|
|
if (b == buffer_) {
|
|
|
|
|
// Set the cursor
|
|
|
|
|
setCursor(makeDocIterator(par, 0));
|
|
|
|
|
switchKeyMap();
|
|
|
|
|
} else {
|
|
|
|
|
// Switch to other buffer view and resend cmd
|
|
|
|
|
theLyXFunc().dispatch(FuncRequest(
|
|
|
|
|
LFUN_BUFFER_SWITCH, b->fileName()));
|
|
|
|
|
theLyXFunc().dispatch(cmd);
|
2007-01-24 23:10:03 +00:00
|
|
|
|
updateFlags = Update::None;
|
2006-11-13 16:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_OUTLINE_UP:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
toc::outline(toc::Up, cursor_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cursor_.text()->setCursor(cursor_, cursor_.pit(), 0);
|
|
|
|
|
updateLabels(*buffer_);
|
|
|
|
|
break;
|
|
|
|
|
case LFUN_OUTLINE_DOWN:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
toc::outline(toc::Down, cursor_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cursor_.text()->setCursor(cursor_, cursor_.pit(), 0);
|
|
|
|
|
updateLabels(*buffer_);
|
|
|
|
|
break;
|
|
|
|
|
case LFUN_OUTLINE_IN:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
toc::outline(toc::In, cursor_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
updateLabels(*buffer_);
|
|
|
|
|
break;
|
|
|
|
|
case LFUN_OUTLINE_OUT:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
toc::outline(toc::Out, cursor_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
updateLabels(*buffer_);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_NOTE_NEXT:
|
|
|
|
|
bv_funcs::gotoInset(this, InsetBase::NOTE_CODE, false);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_REFERENCE_NEXT: {
|
|
|
|
|
vector<InsetBase_code> tmp;
|
|
|
|
|
tmp.push_back(InsetBase::LABEL_CODE);
|
|
|
|
|
tmp.push_back(InsetBase::REF_CODE);
|
|
|
|
|
bv_funcs::gotoInset(this, tmp, true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_CHANGES_TRACK:
|
2006-10-06 18:53:35 +00:00
|
|
|
|
buffer_->params().trackChanges = !buffer_->params().trackChanges;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-01-24 23:10:03 +00:00
|
|
|
|
case LFUN_CHANGES_OUTPUT:
|
2006-10-06 18:53:35 +00:00
|
|
|
|
buffer_->params().outputChanges = !buffer_->params().outputChanges;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2006-10-04 21:43:40 +00:00
|
|
|
|
case LFUN_CHANGE_NEXT:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
findNextChange(this);
|
2006-10-04 21:43:40 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
case LFUN_CHANGES_MERGE:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (findNextChange(this))
|
2006-09-19 13:36:20 +00:00
|
|
|
|
showDialog("changes");
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_ALL_CHANGES_ACCEPT: {
|
|
|
|
|
cursor_.reset(buffer_->inset());
|
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning FIXME changes
|
|
|
|
|
#endif
|
2006-10-21 00:16:43 +00:00
|
|
|
|
while (findNextChange(this))
|
2007-01-26 04:08:27 +00:00
|
|
|
|
getLyXText()->acceptOrRejectChanges(cursor_, LyXText::ACCEPT);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_ALL_CHANGES_REJECT: {
|
|
|
|
|
cursor_.reset(buffer_->inset());
|
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning FIXME changes
|
|
|
|
|
#endif
|
2006-10-21 00:16:43 +00:00
|
|
|
|
while (findNextChange(this))
|
2007-01-26 04:08:27 +00:00
|
|
|
|
getLyXText()->acceptOrRejectChanges(cursor_, LyXText::REJECT);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_WORD_FIND:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
find(this, cmd);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_WORD_REPLACE:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
replace(this, cmd);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_MARK_OFF:
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
cur.resetAnchor();
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cur.message(from_utf8(N_("Mark off")));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_MARK_ON:
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
cur.mark() = true;
|
|
|
|
|
cur.resetAnchor();
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cur.message(from_utf8(N_("Mark on")));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_MARK_TOGGLE:
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (cur.mark()) {
|
|
|
|
|
cur.mark() = false;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cur.message(from_utf8(N_("Mark removed")));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
} else {
|
|
|
|
|
cur.mark() = true;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cur.message(from_utf8(N_("Mark set")));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_SCREEN_RECENTER:
|
|
|
|
|
center();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_ADD: {
|
|
|
|
|
LCursor tmpcur = cursor_;
|
|
|
|
|
bv_funcs::findInset(tmpcur, InsetBase::BIBTEX_CODE, false);
|
|
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
|
|
|
|
InsetBase::BIBTEX_CODE);
|
|
|
|
|
if (inset) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (inset->addDatabase(to_utf8(cmd.argument())))
|
2006-09-16 10:08:51 +00:00
|
|
|
|
buffer_->updateBibfilesCache();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_DEL: {
|
|
|
|
|
LCursor tmpcur = cursor_;
|
|
|
|
|
bv_funcs::findInset(tmpcur, InsetBase::BIBTEX_CODE, false);
|
|
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
|
|
|
|
InsetBase::BIBTEX_CODE);
|
|
|
|
|
if (inset) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (inset->delDatabase(to_utf8(cmd.argument())))
|
2006-09-16 10:08:51 +00:00
|
|
|
|
buffer_->updateBibfilesCache();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_WORDS_COUNT: {
|
|
|
|
|
DocIterator from, to;
|
|
|
|
|
if (cur.selection()) {
|
|
|
|
|
from = cur.selectionBegin();
|
|
|
|
|
to = cur.selectionEnd();
|
|
|
|
|
} else {
|
|
|
|
|
from = doc_iterator_begin(buffer_->inset());
|
|
|
|
|
to = doc_iterator_end(buffer_->inset());
|
|
|
|
|
}
|
|
|
|
|
int const count = countWords(from, to);
|
|
|
|
|
docstring message;
|
|
|
|
|
if (count != 1) {
|
|
|
|
|
if (cur.selection())
|
|
|
|
|
message = bformat(_("%1$d words in selection."),
|
|
|
|
|
count);
|
|
|
|
|
else
|
|
|
|
|
message = bformat(_("%1$d words in document."),
|
|
|
|
|
count);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (cur.selection())
|
|
|
|
|
message = _("One word in selection.");
|
|
|
|
|
else
|
|
|
|
|
message = _("One word in document.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Alert::information(_("Count words"), message);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BUFFER_TOGGLE_COMPRESSION:
|
|
|
|
|
// turn compression on/off
|
|
|
|
|
buffer_->params().compressed = !buffer_->params().compressed;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_NEXT_INSET_TOGGLE: {
|
|
|
|
|
// this is the real function we want to invoke
|
|
|
|
|
FuncRequest tmpcmd = FuncRequest(LFUN_INSET_TOGGLE, cmd.origin);
|
|
|
|
|
// if there is an inset at cursor, see whether it
|
|
|
|
|
// wants to toggle.
|
|
|
|
|
InsetBase * inset = cur.nextInset();
|
|
|
|
|
if (inset && inset->isActive()) {
|
|
|
|
|
LCursor tmpcur = cur;
|
|
|
|
|
tmpcur.pushLeft(*inset);
|
|
|
|
|
inset->dispatch(tmpcur, tmpcmd);
|
|
|
|
|
if (tmpcur.result().dispatched()) {
|
|
|
|
|
cur.dispatched();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// if it did not work, try the underlying inset.
|
|
|
|
|
if (!cur.result().dispatched())
|
|
|
|
|
cur.dispatch(tmpcmd);
|
|
|
|
|
|
|
|
|
|
if (cur.result().dispatched())
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
2007-01-24 23:10:03 +00:00
|
|
|
|
updateFlags = Update::None;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-01-24 23:10:03 +00:00
|
|
|
|
return updateFlags;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
}
|
2002-08-28 10:45:38 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-17 08:35:12 +00:00
|
|
|
|
docstring const BufferView::requestSelection()
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (!buffer_)
|
2006-09-17 08:35:12 +00:00
|
|
|
|
return docstring();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
LCursor & cur = cursor_;
|
|
|
|
|
|
|
|
|
|
if (!cur.selection()) {
|
|
|
|
|
xsel_cache_.set = false;
|
2006-09-17 08:35:12 +00:00
|
|
|
|
return docstring();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!xsel_cache_.set ||
|
|
|
|
|
cur.top() != xsel_cache_.cursor ||
|
|
|
|
|
cur.anchor_.top() != xsel_cache_.anchor)
|
|
|
|
|
{
|
|
|
|
|
xsel_cache_.cursor = cur.top();
|
|
|
|
|
xsel_cache_.anchor = cur.anchor_.top();
|
|
|
|
|
xsel_cache_.set = cur.selection();
|
2006-09-17 08:35:12 +00:00
|
|
|
|
return cur.selectionAsString(false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2006-09-17 08:35:12 +00:00
|
|
|
|
return docstring();
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-17 08:35:12 +00:00
|
|
|
|
void BufferView::clearSelection()
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (buffer_) {
|
|
|
|
|
cursor_.clearSelection();
|
|
|
|
|
xsel_cache_.set = false;
|
2007-01-05 09:21:30 +00:00
|
|
|
|
// The buffer did not really change, but this causes the
|
|
|
|
|
// redraw we need because we cleared the selection above.
|
|
|
|
|
buffer_->changed();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
void BufferView::workAreaResize(int width, int height)
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// Update from work area
|
|
|
|
|
width_ = width;
|
|
|
|
|
height_ = height;
|
|
|
|
|
|
2007-01-06 23:24:55 +00:00
|
|
|
|
// The complete text metrics will be redone.
|
2006-12-29 23:54:48 +00:00
|
|
|
|
text_metrics_.clear();
|
|
|
|
|
|
2006-11-03 00:21:48 +00:00
|
|
|
|
if (buffer_)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
resize();
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-07 11:46:27 +00:00
|
|
|
|
bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION << "[ cmd0 " << cmd0 << "]" << endl;
|
|
|
|
|
|
|
|
|
|
// This is only called for mouse related events including
|
|
|
|
|
// LFUN_FILE_OPEN generated by drag-and-drop.
|
|
|
|
|
FuncRequest cmd = cmd0;
|
|
|
|
|
|
2006-11-12 16:14:45 +00:00
|
|
|
|
// E.g. Qt mouse press when no buffer
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (!buffer_)
|
2006-12-07 11:46:27 +00:00
|
|
|
|
return false;
|
2006-11-12 16:14:45 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
LCursor cur(*this);
|
|
|
|
|
cur.push(buffer_->inset());
|
|
|
|
|
cur.selection() = cursor_.selection();
|
|
|
|
|
|
|
|
|
|
// Either the inset under the cursor or the
|
|
|
|
|
// surrounding LyXText will handle this event.
|
|
|
|
|
|
|
|
|
|
// Build temporary cursor.
|
|
|
|
|
cmd.y = min(max(cmd.y, -1), height_);
|
|
|
|
|
InsetBase * inset = buffer_->text().editXY(cur, cmd.x, cmd.y);
|
2006-11-12 16:14:45 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION
|
|
|
|
|
// << " * hit inset at tip: " << inset << endl;
|
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION
|
|
|
|
|
// << " * created temp cursor:" << cur << endl;
|
|
|
|
|
|
2006-12-07 11:46:27 +00:00
|
|
|
|
// NOTE: editXY returns the top level inset of nested insets. If you happen
|
2006-12-04 04:31:18 +00:00
|
|
|
|
// to move from a text (inset=0) to a text inside an inset (e.g. an opened
|
|
|
|
|
// footnote inset, again inset=0), that inset will not be redrawn.
|
|
|
|
|
if (cmd.action == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::none) {
|
2006-12-07 11:46:27 +00:00
|
|
|
|
bool need_redraw = false;
|
2006-12-04 04:31:18 +00:00
|
|
|
|
|
2006-12-15 16:48:09 +00:00
|
|
|
|
if (inset != last_inset_) {
|
|
|
|
|
if (last_inset_)
|
|
|
|
|
need_redraw |= last_inset_->setMouseHover(false);
|
2006-12-04 04:31:18 +00:00
|
|
|
|
if (inset)
|
2006-12-07 11:46:27 +00:00
|
|
|
|
need_redraw |= inset->setMouseHover(true);
|
2006-12-15 16:48:09 +00:00
|
|
|
|
last_inset_ = inset;
|
2006-12-04 04:31:18 +00:00
|
|
|
|
}
|
2006-12-07 11:46:27 +00:00
|
|
|
|
|
|
|
|
|
// if last metrics update was in singlepar mode, WorkArea::redraw() will
|
|
|
|
|
// not expose the button for redraw. We adjust here the metrics dimension
|
|
|
|
|
// to enable a full redraw.
|
|
|
|
|
// FIXME: It is possible to redraw only the area around the button!
|
2007-01-20 01:23:07 +00:00
|
|
|
|
if (need_redraw
|
|
|
|
|
&& metrics_info_.update_strategy == SingleParUpdate) {
|
2006-12-07 11:46:27 +00:00
|
|
|
|
// FIXME: It should be possible to redraw only the area around
|
|
|
|
|
// the button by doing this:
|
|
|
|
|
//
|
|
|
|
|
//metrics_info_.singlepar = false;
|
|
|
|
|
//metrics_info_.y1 = ymin of button;
|
|
|
|
|
//metrics_info_.y2 = ymax of button;
|
|
|
|
|
//
|
|
|
|
|
// Unfortunately, rowpainter.C:paintText() does not distinguish
|
|
|
|
|
// between background updates and text updates. So we use the hammer
|
|
|
|
|
// solution for now. We could also avoid the updateMetrics() below
|
|
|
|
|
// by using the first and last pit of the CoordCache. Have a look
|
|
|
|
|
// at LyXText::getPitNearY() to see what I mean.
|
|
|
|
|
//
|
|
|
|
|
//metrics_info_.pit1 = first pit of CoordCache;
|
|
|
|
|
//metrics_info_.pit2 = last pit of CoordCache;
|
|
|
|
|
//metrics_info_.singlepar = false;
|
|
|
|
|
//metrics_info_.y1 = 0;
|
|
|
|
|
//metrics_info_.y2 = height_;
|
|
|
|
|
//
|
|
|
|
|
updateMetrics(false);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-04 04:31:18 +00:00
|
|
|
|
// This event (moving without mouse click) is not passed further.
|
|
|
|
|
// This should be changed if it is further utilized.
|
2006-12-07 11:46:27 +00:00
|
|
|
|
return need_redraw;
|
2006-12-04 04:31:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// Put anchor at the same position.
|
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
|
|
|
|
|
// Try to dispatch to an non-editable inset near this position
|
|
|
|
|
// via the temp cursor. If the inset wishes to change the real
|
|
|
|
|
// cursor it has to do so explicitly by using
|
|
|
|
|
// cur.bv().cursor() = cur; (or similar)
|
2006-11-12 16:14:45 +00:00
|
|
|
|
if (inset) {
|
2006-09-16 10:08:51 +00:00
|
|
|
|
inset->dispatch(cur, cmd);
|
2006-11-12 16:14:45 +00:00
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// Now dispatch to the temporary cursor. If the real cursor should
|
|
|
|
|
// be modified, the inset's dispatch has to do so explicitly.
|
|
|
|
|
if (!cur.result().dispatched())
|
|
|
|
|
cur.dispatch(cmd);
|
|
|
|
|
|
2006-11-17 17:42:52 +00:00
|
|
|
|
// Redraw if requested and necessary.
|
|
|
|
|
if (cur.result().dispatched() && cur.result().update())
|
|
|
|
|
return update(cur.result().update());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2006-12-07 11:46:27 +00:00
|
|
|
|
return false;
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
void BufferView::scroll(int /*lines*/)
|
2002-08-28 10:45:38 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// if (!buffer_)
|
|
|
|
|
// return;
|
|
|
|
|
//
|
|
|
|
|
// LyXText const * t = &buffer_->text();
|
|
|
|
|
// int const line_height = defaultRowHeight();
|
|
|
|
|
//
|
|
|
|
|
// // The new absolute coordinate
|
|
|
|
|
// int new_top_y = top_y() + lines * line_height;
|
|
|
|
|
//
|
|
|
|
|
// // Restrict to a valid value
|
|
|
|
|
// new_top_y = std::min(t->height() - 4 * line_height, new_top_y);
|
|
|
|
|
// new_top_y = std::max(0, new_top_y);
|
|
|
|
|
//
|
|
|
|
|
// scrollDocView(new_top_y);
|
|
|
|
|
//
|
2002-08-28 10:45:38 +00:00
|
|
|
|
}
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::setCursorFromRow(int row)
|
|
|
|
|
{
|
|
|
|
|
int tmpid = -1;
|
|
|
|
|
int tmppos = -1;
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
buffer_->texrow().getIdFromRow(row, tmpid, tmppos);
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (tmpid == -1)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
buffer_->text().setCursor(cursor_, 0, 0);
|
2003-10-09 10:52:12 +00:00
|
|
|
|
else
|
2006-09-16 10:08:51 +00:00
|
|
|
|
buffer_->text().setCursor(cursor_, buffer_->getParFromID(tmpid).pit(), tmppos);
|
2002-08-29 13:05:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-12 10:50:45 +00:00
|
|
|
|
void BufferView::gotoLabel(docstring const & label)
|
2002-08-29 13:05:55 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
for (InsetIterator it = inset_iterator_begin(buffer_->inset()); it; ++it) {
|
2006-10-12 10:50:45 +00:00
|
|
|
|
vector<docstring> labels;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
it->getLabelList(*buffer_, labels);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (std::find(labels.begin(), labels.end(), label) != labels.end()) {
|
2005-02-22 11:41:22 +00:00
|
|
|
|
setCursor(it);
|
2003-08-04 09:06:35 +00:00
|
|
|
|
update();
|
2003-03-29 10:29:38 +00:00
|
|
|
|
return;
|
2002-08-29 13:05:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
LyXText * BufferView::getLyXText()
|
2002-08-29 13:05:55 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
LyXText * text = cursor_.innerText();
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(text);
|
|
|
|
|
return text;
|
2002-08-29 13:05:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
LyXText const * BufferView::getLyXText() const
|
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
LyXText const * text = cursor_.innerText();
|
2005-01-31 16:29:48 +00:00
|
|
|
|
BOOST_ASSERT(text);
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-29 23:54:48 +00:00
|
|
|
|
TextMetrics const & BufferView::textMetrics(LyXText const * t) const
|
|
|
|
|
{
|
|
|
|
|
return const_cast<BufferView *>(this)->textMetrics(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TextMetrics & BufferView::textMetrics(LyXText const * t)
|
|
|
|
|
{
|
|
|
|
|
TextMetricsCache::iterator tmc_it = text_metrics_.find(t);
|
|
|
|
|
if (tmc_it == text_metrics_.end()) {
|
|
|
|
|
tmc_it = text_metrics_.insert(
|
|
|
|
|
make_pair(t, TextMetrics(this, const_cast<LyXText *>(t)))).first;
|
|
|
|
|
}
|
|
|
|
|
return tmc_it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphMetrics const & BufferView::parMetrics(LyXText const * t,
|
|
|
|
|
pit_type pit) const
|
|
|
|
|
{
|
|
|
|
|
return textMetrics(t).parMetrics(pit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-29 13:41:58 +00:00
|
|
|
|
int BufferView::workHeight() const
|
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return height_;
|
2002-08-29 13:41:58 +00:00
|
|
|
|
}
|
2003-11-04 07:43:03 +00:00
|
|
|
|
|
|
|
|
|
|
2005-02-22 11:41:22 +00:00
|
|
|
|
void BufferView::setCursor(DocIterator const & dit)
|
2004-02-02 11:07:51 +00:00
|
|
|
|
{
|
2005-02-22 11:41:22 +00:00
|
|
|
|
size_t const n = dit.depth();
|
|
|
|
|
for (size_t i = 0; i < n; ++i)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
dit[i].inset().edit(cursor_, true);
|
2004-03-31 17:58:11 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cursor_.setCursor(dit);
|
|
|
|
|
cursor_.selection() = false;
|
2004-02-02 11:07:51 +00:00
|
|
|
|
}
|
2004-01-14 17:21:39 +00:00
|
|
|
|
|
2005-02-08 13:18:05 +00:00
|
|
|
|
|
2006-12-30 15:05:15 +00:00
|
|
|
|
bool BufferView::checkDepm(LCursor & cur, LCursor & old)
|
|
|
|
|
{
|
|
|
|
|
// Would be wrong to delete anything if we have a selection.
|
|
|
|
|
if (cur.selection())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool need_anchor_change = false;
|
|
|
|
|
bool changed = cursor_.text()->deleteEmptyParagraphMechanism(cur, old,
|
|
|
|
|
need_anchor_change);
|
|
|
|
|
|
|
|
|
|
if (need_anchor_change)
|
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
|
|
|
|
|
if (!changed)
|
|
|
|
|
return false;
|
|
|
|
|
|
2007-01-31 14:07:37 +00:00
|
|
|
|
updateLabels(*buffer_);
|
|
|
|
|
|
2006-12-30 15:05:15 +00:00
|
|
|
|
updateMetrics(false);
|
|
|
|
|
buffer_->changed();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-11 13:59:40 +00:00
|
|
|
|
bool BufferView::mouseSetCursor(LCursor & cur)
|
2005-12-01 10:28:50 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(&cur.bv() == this);
|
|
|
|
|
|
|
|
|
|
// Has the cursor just left the inset?
|
2006-08-17 21:32:04 +00:00
|
|
|
|
bool badcursor = false;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (&cursor_.inset() != &cur.inset())
|
|
|
|
|
badcursor = cursor_.inset().notifyCursorLeaves(cursor_);
|
2005-12-01 10:28:50 +00:00
|
|
|
|
|
|
|
|
|
// do the dEPM magic if needed
|
2006-08-17 21:32:04 +00:00
|
|
|
|
// FIXME: move this to InsetText::notifyCursorLeaves?
|
2006-12-11 13:59:40 +00:00
|
|
|
|
bool update = false;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (!badcursor && cursor_.inTexted())
|
2006-12-30 15:05:15 +00:00
|
|
|
|
checkDepm(cur, cursor_);
|
2005-12-01 10:28:50 +00:00
|
|
|
|
|
2007-01-17 15:32:43 +00:00
|
|
|
|
// if the cursor was in an empty script inset and the new
|
|
|
|
|
// position is in the nucleus of the inset, notifyCursorLeaves
|
|
|
|
|
// will kill the script inset itself. So we check all the
|
|
|
|
|
// elements of the cursor to make sure that they are correct.
|
|
|
|
|
// For an example, see bug 2933:
|
|
|
|
|
// http://bugzilla.lyx.org/show_bug.cgi?id=2933
|
|
|
|
|
// The code below could maybe be moved to a DocIterator method.
|
|
|
|
|
//lyxerr << "cur before " << cur <<std::endl;
|
|
|
|
|
DocIterator dit(cur.inset());
|
|
|
|
|
dit.push_back(cur.bottom());
|
|
|
|
|
size_t i = 1;
|
|
|
|
|
while (i < cur.depth() && dit.nextInset() == &cur[i].inset()) {
|
|
|
|
|
dit.push_back(cur[i]);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
//lyxerr << "5 cur after" << dit <<std::endl;
|
|
|
|
|
|
|
|
|
|
cursor_.setCursor(dit);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cursor_.clearSelection();
|
2007-01-10 10:59:18 +00:00
|
|
|
|
// remember new position.
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cursor_.setTargetX();
|
2005-12-01 10:28:50 +00:00
|
|
|
|
finishUndo();
|
2006-12-11 13:59:40 +00:00
|
|
|
|
return update;
|
2005-12-01 10:28:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void BufferView::putSelectionAt(DocIterator const & cur,
|
2004-03-28 22:00:22 +00:00
|
|
|
|
int length, bool backwards)
|
2004-01-14 17:21:39 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cursor_.clearSelection();
|
2004-01-14 17:21:39 +00:00
|
|
|
|
|
2005-02-22 11:41:22 +00:00
|
|
|
|
setCursor(cur);
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-01-14 17:21:39 +00:00
|
|
|
|
if (length) {
|
2004-03-01 17:12:09 +00:00
|
|
|
|
if (backwards) {
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cursor_.pos() += length;
|
|
|
|
|
cursor_.setSelection(cursor_, -length);
|
2004-03-31 17:58:11 +00:00
|
|
|
|
} else
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cursor_.setSelection(cursor_, length);
|
2007-01-07 14:44:44 +00:00
|
|
|
|
theSelection().haveSelection(cursor_.selection());
|
2004-01-14 17:21:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-15 11:58:35 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & BufferView::cursor()
|
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return cursor_;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LCursor const & BufferView::cursor() const
|
2004-01-15 11:58:35 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return cursor_;
|
2004-01-15 11:58:35 +00:00
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
pit_type BufferView::anchor_ref() const
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return anchor_ref_;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-07-04 00:04:46 +00:00
|
|
|
|
ViewMetricsInfo const & BufferView::viewMetricsInfo()
|
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return metrics_info_;
|
2006-07-04 00:04:46 +00:00
|
|
|
|
}
|
2006-07-08 20:24:32 +00:00
|
|
|
|
|
|
|
|
|
|
2007-01-05 15:35:10 +00:00
|
|
|
|
// FIXME: We should split-up updateMetrics() for the singlepar case.
|
2006-07-14 09:56:21 +00:00
|
|
|
|
void BufferView::updateMetrics(bool singlepar)
|
2006-07-08 20:24:32 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
LyXText & buftext = buffer_->text();
|
2006-12-29 23:54:48 +00:00
|
|
|
|
TextMetrics & tm = textMetrics(&buftext);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
pit_type size = int(buftext.paragraphs().size());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
if (anchor_ref_ > int(buftext.paragraphs().size() - 1)) {
|
|
|
|
|
anchor_ref_ = int(buftext.paragraphs().size() - 1);
|
|
|
|
|
offset_ref_ = 0;
|
|
|
|
|
}
|
2007-01-05 14:31:59 +00:00
|
|
|
|
|
2007-01-05 15:35:10 +00:00
|
|
|
|
// If the paragraph metrics has changed, we can not
|
|
|
|
|
// use the singlepar optimisation.
|
2007-01-06 09:15:59 +00:00
|
|
|
|
if (singlepar
|
|
|
|
|
// In Single Paragraph mode, rebreak only
|
|
|
|
|
// the (main text, not inset!) paragraph containing the cursor.
|
|
|
|
|
// (if this paragraph contains insets etc., rebreaking will
|
|
|
|
|
// recursively descend)
|
|
|
|
|
&& tm.redoParagraph(cursor_.bottom().pit()))
|
|
|
|
|
singlepar = false;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
pit_type const pit = anchor_ref_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int pit1 = pit;
|
|
|
|
|
int pit2 = pit;
|
|
|
|
|
size_t const npit = buftext.paragraphs().size();
|
|
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
|
// Rebreak anchor paragraph.
|
|
|
|
|
if (!singlepar)
|
|
|
|
|
tm.redoParagraph(pit);
|
2006-12-29 23:54:48 +00:00
|
|
|
|
|
|
|
|
|
// Clear out the position cache in case of full screen redraw.
|
|
|
|
|
if (!singlepar)
|
|
|
|
|
coord_cache_.clear();
|
|
|
|
|
|
|
|
|
|
int y0 = tm.parMetrics(pit).ascent() - offset_ref_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
|
// Redo paragraphs above anchor if necessary.
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int y1 = y0;
|
|
|
|
|
while (y1 > 0 && pit1 > 0) {
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y1 -= tm.parMetrics(pit1).ascent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
--pit1;
|
2007-01-06 09:15:59 +00:00
|
|
|
|
if (!singlepar)
|
2006-12-29 23:54:48 +00:00
|
|
|
|
tm.redoParagraph(pit1);
|
|
|
|
|
y1 -= tm.parMetrics(pit1).descent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Take care of ascent of first line
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y1 -= tm.parMetrics(pit1).ascent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// Normalize anchor for next time
|
|
|
|
|
anchor_ref_ = pit1;
|
|
|
|
|
offset_ref_ = -y1;
|
|
|
|
|
|
|
|
|
|
// Grey at the beginning is ugly
|
|
|
|
|
if (pit1 == 0 && y1 > 0) {
|
|
|
|
|
y0 -= y1;
|
|
|
|
|
y1 = 0;
|
|
|
|
|
anchor_ref_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
|
// Redo paragraphs below the anchor if necessary.
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int y2 = y0;
|
|
|
|
|
while (y2 < height_ && pit2 < int(npit) - 1) {
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y2 += tm.parMetrics(pit2).descent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
++pit2;
|
2007-01-06 09:15:59 +00:00
|
|
|
|
if (!singlepar)
|
2006-12-29 23:54:48 +00:00
|
|
|
|
tm.redoParagraph(pit2);
|
|
|
|
|
y2 += tm.parMetrics(pit2).ascent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Take care of descent of last line
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y2 += tm.parMetrics(pit2).descent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// The coordinates of all these paragraphs are correct, cache them
|
|
|
|
|
int y = y1;
|
2006-10-13 16:44:44 +00:00
|
|
|
|
CoordCache::InnerParPosCache & parPos = coord_cache_.parPos()[&buftext];
|
2006-10-21 00:16:43 +00:00
|
|
|
|
for (pit_type pit = pit1; pit <= pit2; ++pit) {
|
2006-12-29 23:54:48 +00:00
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(pit);
|
|
|
|
|
y += pm.ascent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
parPos[pit] = Point(0, y);
|
|
|
|
|
if (singlepar && pit == cursor_.bottom().pit()) {
|
|
|
|
|
// In Single Paragraph mode, collect here the
|
|
|
|
|
// y1 and y2 of the (one) paragraph the cursor is in
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y1 = y - pm.ascent();
|
|
|
|
|
y2 = y + pm.descent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y += pm.descent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (singlepar) {
|
|
|
|
|
// collect cursor paragraph iter bounds
|
|
|
|
|
pit1 = cursor_.bottom().pit();
|
|
|
|
|
pit2 = cursor_.bottom().pit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lyxerr[Debug::DEBUG]
|
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " y1: " << y1
|
|
|
|
|
<< " y2: " << y2
|
|
|
|
|
<< " pit1: " << pit1
|
|
|
|
|
<< " pit2: " << pit2
|
|
|
|
|
<< " npit: " << npit
|
|
|
|
|
<< " singlepar: " << singlepar
|
|
|
|
|
<< "size: " << size
|
|
|
|
|
<< endl;
|
|
|
|
|
|
2007-01-20 01:23:07 +00:00
|
|
|
|
metrics_info_ = ViewMetricsInfo(pit1, pit2, y1, y2,
|
|
|
|
|
singlepar? SingleParUpdate: FullScreenUpdate, size);
|
2006-10-20 20:57:21 +00:00
|
|
|
|
|
|
|
|
|
if (lyxerr.debugging(Debug::WORKAREA)) {
|
2006-10-21 11:29:34 +00:00
|
|
|
|
lyxerr[Debug::WORKAREA] << "BufferView::updateMetrics" << endl;
|
2006-10-20 20:57:21 +00:00
|
|
|
|
coord_cache_.dump();
|
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::menuInsertLyXFile(string const & filenm)
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(cursor_.inTexted());
|
|
|
|
|
string filename = filenm;
|
|
|
|
|
|
|
|
|
|
if (filename.empty()) {
|
|
|
|
|
// Launch a file browser
|
2006-10-09 16:33:20 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-09-16 10:08:51 +00:00
|
|
|
|
string initpath = lyxrc.document_path;
|
|
|
|
|
|
2006-09-16 14:00:13 +00:00
|
|
|
|
if (buffer_) {
|
2006-09-16 10:08:51 +00:00
|
|
|
|
string const trypath = buffer_->filePath();
|
|
|
|
|
// If directory is writeable, use this as default.
|
2006-12-27 10:56:11 +00:00
|
|
|
|
if (isDirWriteable(FileName(trypath)))
|
2006-09-16 10:08:51 +00:00
|
|
|
|
initpath = trypath;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-09 16:33:20 +00:00
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
FileDialog fileDlg(_("Select LyX document to insert"),
|
2006-09-16 10:08:51 +00:00
|
|
|
|
LFUN_FILE_INSERT,
|
2006-10-21 00:16:43 +00:00
|
|
|
|
make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
|
|
|
|
|
make_pair(_("Examples|#E#e"), from_utf8(addPath(package().system_support(), "examples"))));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
FileDialog::Result result =
|
2006-10-21 00:16:43 +00:00
|
|
|
|
fileDlg.open(from_utf8(initpath),
|
2006-10-09 16:33:20 +00:00
|
|
|
|
FileFilterList(_("LyX Documents (*.lyx)")),
|
|
|
|
|
docstring());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
|
return;
|
|
|
|
|
|
2006-10-09 16:33:20 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
filename = to_utf8(result.second);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// check selected filename
|
|
|
|
|
if (filename.empty()) {
|
|
|
|
|
// emit message signal.
|
|
|
|
|
message(_("Canceled."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get absolute path of file and add ".lyx"
|
|
|
|
|
// to the filename if necessary
|
2006-11-26 21:30:39 +00:00
|
|
|
|
filename = fileSearch(string(), filename, "lyx").absFilename();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
docstring const disp_fn = makeDisplayPath(filename);
|
|
|
|
|
// emit message signal.
|
|
|
|
|
message(bformat(_("Inserting document %1$s..."), disp_fn));
|
|
|
|
|
|
|
|
|
|
docstring res;
|
|
|
|
|
Buffer buf("", false);
|
2006-12-02 16:07:15 +00:00
|
|
|
|
if (lyx::loadLyXFile(&buf, FileName(filename))) {
|
2006-09-16 10:08:51 +00:00
|
|
|
|
ErrorList & el = buffer_->errorList("Parse");
|
|
|
|
|
// Copy the inserted document error list into the current buffer one.
|
|
|
|
|
el = buf.errorList("Parse");
|
2006-11-12 15:48:33 +00:00
|
|
|
|
recordUndo(cursor_);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cap::pasteParagraphList(cursor_, buf.paragraphs(),
|
2006-09-16 10:08:51 +00:00
|
|
|
|
buf.params().textclass, el);
|
|
|
|
|
res = _("Document %1$s inserted.");
|
|
|
|
|
} else
|
|
|
|
|
res = _("Could not insert document %1$s");
|
|
|
|
|
|
|
|
|
|
// emit message signal.
|
|
|
|
|
message(bformat(res, disp_fn));
|
|
|
|
|
buffer_->errors("Parse");
|
|
|
|
|
resize();
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|