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"
|
2004-08-14 14:03:42 +00:00
|
|
|
|
#include "coordcache.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
#include "cursor.h"
|
2005-11-29 15:08:35 +00:00
|
|
|
|
#include "CutAndPaste.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"
|
2004-04-01 08:58:45 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "intl.h"
|
2004-03-27 12:42:10 +00:00
|
|
|
|
#include "insetiterator.h"
|
2005-01-24 17:12:19 +00:00
|
|
|
|
#include "LaTeXFeatures.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"
|
2006-04-05 22:56:18 +00:00
|
|
|
|
#include "session.h"
|
2004-11-30 01:59:49 +00:00
|
|
|
|
#include "metricsinfo.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"
|
2004-03-28 22:00:22 +00:00
|
|
|
|
#include "pariterator.h"
|
2006-03-29 05:08:42 +00:00
|
|
|
|
#include "toc.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
|
|
|
|
|
2005-06-25 15:57:15 +00:00
|
|
|
|
#include "insets/insetbibtex.h"
|
2003-02-21 09:20:18 +00:00
|
|
|
|
#include "insets/insetref.h"
|
2004-03-18 12:53:43 +00:00
|
|
|
|
#include "insets/insettext.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/Alert.h"
|
|
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
|
#include "frontends/FileDialog.h"
|
2005-01-10 09:28:06 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
2006-06-20 08:39:16 +00:00
|
|
|
|
#include "frontends/Gui.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
Split clipboard and X selection
* src/LyXAction.C
(LyXAction::init): handle new LFUN_CLIPBOARD_PASTE
* src/insets/insettabular.C
(InsetTabular::doDispatch): ditto
* src/insets/insetbox.C
(InsetBox::doDispatch): ditto
* src/insets/insetert.C
(InsetERT::doDispatch): ditto
(InsetERT::getStatus): ditto
* src/insets/insetcharstyle.C
(InsetCharStyle::doDispatch): ditto
* src/BufferView_pimpl.C
(BufferView::Pimpl::selectionRequest): stuff selection, not clipboard
* src/mathed/math_nestinset.C
(MathNestInset::lfunMousePress): get stuff selection, not clipboard
(MathNestInset::lfunMouseRelease): clipboard -> selection in
commented code
* src/CutAndPaste.C
(cutSelection): ditto
* src/frontends/{qt3,gtk}/GuiImplementation.C
(GuiImplementation::newWorkArea): create new selection, not clipboard,
since the clipboard is now an object
(GuiImplementation::destroyWorkArea): destroy selection, not clipboard
* src/frontends/{qt4,qt3,gtk}/GuiSelection.h: new, copied from
GuiClipboard.h
* src/frontends/{qt4,qt3,gtk}/GuiSelection.C: new, copied from
GuiClipboard.C
* src/frontends/{qt3,gtk}/GuiImplementation.h
(selection): new accessor for selection_
(selection_): new, the global selection object
* src/frontends/{qt4,qt3,gtk}/Makefile.am: add GuiSelection.C and
GuiSelection.h
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.C
(GuiClipboard::get): return clipboard, not selection
(GuiClipboard::put): stuff clipboard, not selection
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.h
(haveSelection): remove (this is now in GuiSelection)
* src/frontends/{qt3,gtk}/GuiClipboard.h
(old_work_area_): remove, since it is not needed anymore
* src/frontends/gtk/ghelpers.C
(getGTKStockIcon): handle LFUN_CLIPBOARD_PASTE
* src/frontends/Clipboard.h
(haveSelection): remove (this is now in Selection)
* src/frontends/qt4/GuiImplementation.[Ch]
(GuiImplementation::selection): new accessor for selection_
* src/frontends/Gui.h
(selection): New accessor for the global selection object
* src/frontends/Selection.h; new, copied from Clipboard.h
* src/frontends/Makefile.am: add Selection.h
* src/text3.C
(various): s/clipboard().haveSelection/selection().haveSelection/
(LyXText::dispatch): handle LFUN_CLIPBOARD_PASTE
(LyXText::getStatus): ditto
* src/lfuns.h: new lfun LFUN_CLIPBOARD_PASTE
* lib/ui/stdmenus.ui: add new lfun LFUN_CLIPBOARD_PASTE
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14408 a592a061-630c-0410-9148-cb99ea01b6c8
2006-07-10 11:32:25 +00:00
|
|
|
|
#include "frontends/Selection.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
|
#include "graphics/Previews.h"
|
|
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
|
#include "support/convert.h"
|
2004-11-25 11:08:32 +00:00
|
|
|
|
#include "support/filefilterlist.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "support/filetools.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
|
#include "support/package.h"
|
2004-04-07 20:20:15 +00:00
|
|
|
|
#include "support/types.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
2005-02-25 11:55:36 +00:00
|
|
|
|
#include <boost/current_function.hpp>
|
2002-05-29 16:21:03 +00:00
|
|
|
|
|
2004-11-06 15:23:12 +00:00
|
|
|
|
#include <functional>
|
2005-02-22 11:41:22 +00:00
|
|
|
|
#include <vector>
|
2004-11-06 15:23:12 +00:00
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
|
using lyx::frontend::Clipboard;
|
|
|
|
|
using lyx::frontend::Gui;
|
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::pos_type;
|
|
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
|
using lyx::support::addPath;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::bformat;
|
2004-01-08 10:59:51 +00:00
|
|
|
|
using lyx::support::FileFilterList;
|
2006-04-08 22:31:11 +00:00
|
|
|
|
using lyx::support::fileSearch;
|
2006-04-08 09:09:57 +00:00
|
|
|
|
using lyx::support::isDirWriteable;
|
2006-04-08 22:31:11 +00:00
|
|
|
|
using lyx::support::makeDisplayPath;
|
|
|
|
|
using lyx::support::makeAbsPath;
|
2005-01-10 19:17:43 +00:00
|
|
|
|
using lyx::support::package;
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
using std::endl;
|
2004-02-13 11:05:29 +00:00
|
|
|
|
using std::istringstream;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
using std::make_pair;
|
2001-01-28 18:31:36 +00:00
|
|
|
|
using std::min;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
using std::max;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2004-11-06 15:23:12 +00:00
|
|
|
|
using std::mem_fun_ref;
|
2005-02-22 11:41:22 +00:00
|
|
|
|
using std::vector;
|
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;
|
|
|
|
|
|
2006-07-13 16:37:55 +00:00
|
|
|
|
|
2005-06-25 15:57:15 +00:00
|
|
|
|
/// Return an inset of this class if it exists at the current cursor position
|
2004-08-14 00:27:15 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-17 02:06:21 +00:00
|
|
|
|
} // anon namespace
|
|
|
|
|
|
2000-04-14 19:20:33 +00:00
|
|
|
|
|
2006-07-03 22:31:51 +00:00
|
|
|
|
BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner)
|
2006-07-08 22:06:50 +00:00
|
|
|
|
: bv_(&bv), owner_(owner), buffer_(0), wh_(0),
|
2006-07-08 21:22:18 +00:00
|
|
|
|
cursor_(bv),
|
2006-07-14 09:56:21 +00:00
|
|
|
|
multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2003-12-12 15:19:35 +00:00
|
|
|
|
xsel_cache_.set = false;
|
|
|
|
|
|
2001-01-28 18:31:36 +00:00
|
|
|
|
saved_positions.resize(saved_positions_num);
|
2006-04-05 22:56:18 +00:00
|
|
|
|
// load saved bookmarks
|
|
|
|
|
lyx::Session::BookmarkList & bmList = LyX::ref().session().loadBookmarks();
|
|
|
|
|
for (lyx::Session::BookmarkList::iterator bm = bmList.begin();
|
|
|
|
|
bm != bmList.end(); ++bm)
|
|
|
|
|
if (bm->get<0>() < saved_positions_num)
|
|
|
|
|
saved_positions[bm->get<0>()] = Position( bm->get<1>(), bm->get<2>(), bm->get<3>() );
|
2006-04-05 23:56:29 +00:00
|
|
|
|
// and then clear them
|
2006-04-05 22:56:18 +00:00
|
|
|
|
bmList.clear();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2003-06-20 12:46:28 +00:00
|
|
|
|
bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
|
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Get absolute path of file and add ".lyx"
|
|
|
|
|
// to the filename if necessary
|
2006-04-08 22:31:11 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// File already open?
|
2003-06-20 12:46:28 +00:00
|
|
|
|
if (bufferlist.exists(s)) {
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string const file = makeDisplayPath(s, 20);
|
2003-06-20 12:46:28 +00:00
|
|
|
|
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) {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
setBuffer(bufferlist.getBuffer(s));
|
2003-06-20 12:46:28 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-03-18 12:53:43 +00:00
|
|
|
|
// FIXME: should be LFUN_REVERT
|
|
|
|
|
if (!bufferlist.close(bufferlist.getBuffer(s), false))
|
|
|
|
|
return false;
|
|
|
|
|
// Fall through to new load. (Asger)
|
2003-06-20 12:46:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-05 08:41:28 +00:00
|
|
|
|
Buffer * b = 0;
|
2003-06-20 23:03:43 +00:00
|
|
|
|
|
2003-07-29 16:40:26 +00:00
|
|
|
|
if (found) {
|
|
|
|
|
b = bufferlist.newBuffer(s);
|
|
|
|
|
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)
|
2006-07-13 16:37:55 +00:00
|
|
|
|
b = newFile(s, string(), true);
|
2003-07-29 16:40:26 +00:00
|
|
|
|
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
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
setBuffer(b);
|
2006-07-14 21:47:48 +00:00
|
|
|
|
owner_->showErrorList(_("Parse"));
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2006-04-05 22:56:18 +00:00
|
|
|
|
// scroll to the position when the file was last closed
|
|
|
|
|
if (lyxrc.use_lastfilepos) {
|
|
|
|
|
lyx::pit_type pit;
|
|
|
|
|
lyx::pos_type pos;
|
|
|
|
|
boost::tie(pit, pos) = LyX::ref().session().loadFilePosition(s);
|
|
|
|
|
// I am not sure how to separate the following part to a function
|
2006-04-05 23:56:29 +00:00
|
|
|
|
// so I will leave this to Lars.
|
2006-04-05 22:56:18 +00:00
|
|
|
|
//
|
|
|
|
|
// check pit since the document may be externally changed.
|
|
|
|
|
if ( static_cast<size_t>(pit) < b->paragraphs().size() ) {
|
|
|
|
|
ParIterator it = b->par_iterator_begin();
|
|
|
|
|
ParIterator const end = b->par_iterator_end();
|
|
|
|
|
for (; it != end; ++it)
|
|
|
|
|
if (it.pit() == pit) {
|
|
|
|
|
// restored pos may be bigger than it->size
|
|
|
|
|
bv_->setCursor(makeDocIterator(it, min(pos, it->size())));
|
|
|
|
|
bv_->update(Update::FitCursor);
|
|
|
|
|
break;
|
2006-04-05 23:56:29 +00:00
|
|
|
|
}
|
2006-04-05 22:56:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
|
|
|
|
if (tolastfiles)
|
2006-04-05 22:56:18 +00:00
|
|
|
|
LyX::ref().session().addLastFile(b->fileName());
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-07 08:37:02 +00:00
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
|
lyx::frontend::Gui & BufferView::Pimpl::gui() const
|
|
|
|
|
{
|
|
|
|
|
return owner_->gui();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
int BufferView::Pimpl::width() const
|
|
|
|
|
{
|
|
|
|
|
return width_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int BufferView::Pimpl::height() const
|
|
|
|
|
{
|
|
|
|
|
return height_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void BufferView::Pimpl::setBuffer(Buffer * b)
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "[ b = " << b << "]" << endl;
|
|
|
|
|
|
2005-07-17 14:29:35 +00:00
|
|
|
|
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());
|
2006-04-05 22:56:18 +00:00
|
|
|
|
// current buffer is going to be switched-off, save cursor pos
|
|
|
|
|
LyX::ref().session().saveFilePosition(buffer_->fileName(),
|
|
|
|
|
boost::tie(cursor_.pit(), cursor_.pos()) );
|
2005-07-17 14:29:35 +00:00
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// If we are closing current buffer, switch to the first in
|
2004-10-15 08:27:59 +00:00
|
|
|
|
// buffer list.
|
|
|
|
|
if (!b) {
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " No Buffer!" << endl;
|
|
|
|
|
// We are closing the buffer, use the first buffer as current
|
2004-10-15 08:27:59 +00:00
|
|
|
|
buffer_ = bufferlist.first();
|
|
|
|
|
owner_->getDialogs().hideBufferDependent();
|
|
|
|
|
} else {
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Set current buffer
|
2004-10-15 08:27:59 +00:00
|
|
|
|
buffer_ = b;
|
|
|
|
|
}
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Reset old cursor
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cursor_ = LCursor(*bv_);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
anchor_ref_ = 0;
|
|
|
|
|
offset_ref_ = 0;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +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
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
if (buffer_) {
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "Buffer addr: " << buffer_ << endl;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cursor_.push(buffer_->inset());
|
|
|
|
|
cursor_.resetAnchor();
|
2003-12-01 00:35:26 +00:00
|
|
|
|
buffer_->text().init(bv_);
|
2004-08-08 22:36:34 +00:00
|
|
|
|
buffer_->text().setCurrentFont(cursor_);
|
2005-07-17 14:29:35 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
2003-12-01 00:35:26 +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);
|
2004-10-26 21:16:44 +00:00
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2003-08-01 15:27:57 +00:00
|
|
|
|
update();
|
2006-07-13 16:37:55 +00:00
|
|
|
|
|
|
|
|
|
if (buffer_ && lyx::graphics::Previews::status() != LyXRC::PREVIEW_OFF)
|
|
|
|
|
lyx::graphics::Previews::get().generateBufferPreviews(*buffer_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string BufferView::Pimpl::firstLayout()
|
|
|
|
|
{
|
|
|
|
|
string firstlayout;
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
2004-07-05 14:34:50 +00:00
|
|
|
|
// This is done after the layout combox has been populated
|
2005-09-15 13:55:45 +00:00
|
|
|
|
if (buffer_) {
|
|
|
|
|
size_t i = cursor_.depth() - 1;
|
|
|
|
|
// we know we'll eventually find a paragraph
|
|
|
|
|
while (true) {
|
|
|
|
|
CursorSlice const & slice = cursor_[i];
|
|
|
|
|
if (!slice.inset().inMathed()) {
|
|
|
|
|
LyXLayout_ptr const layout = slice.paragraph().layout();
|
2006-07-13 16:37:55 +00:00
|
|
|
|
firstlayout = layout->name();
|
2005-09-15 13:55:45 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
BOOST_ASSERT(i>0);
|
|
|
|
|
--i;
|
|
|
|
|
}
|
2006-04-05 23:56:29 +00:00
|
|
|
|
}
|
2006-07-13 16:37:55 +00:00
|
|
|
|
return firstlayout;
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-02 22:20:49 +00:00
|
|
|
|
|
2003-08-11 09:09:01 +00:00
|
|
|
|
void BufferView::Pimpl::resizeCurrentBuffer()
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << endl;
|
2003-02-14 14:49:51 +00:00
|
|
|
|
owner_->busy(true);
|
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();
|
|
|
|
|
if (!text)
|
2003-11-28 15:08:38 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2004-03-01 16:29:30 +00:00
|
|
|
|
text->init(bv_);
|
2003-12-02 10:51:58 +00:00
|
|
|
|
update();
|
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
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Reset the "Formatting..." message
|
2003-04-07 16:57:38 +00:00
|
|
|
|
owner_->clearMessage();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::Pimpl::updateScrollbar()
|
|
|
|
|
{
|
2003-11-28 08:55:12 +00:00
|
|
|
|
if (!bv_->text()) {
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " no text in updateScrollbar" << endl;
|
2006-06-26 16:55:35 +00:00
|
|
|
|
scrollbarParameters_.reset();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
LyXText & t = *bv_->text();
|
2005-11-07 15:06:42 +00:00
|
|
|
|
int const parsize = int(t.paragraphs().size() - 1);
|
|
|
|
|
if (anchor_ref_ > parsize) {
|
|
|
|
|
anchor_ref_ = parsize;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
offset_ref_ = 0;
|
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
lyxerr[Debug::GUI]
|
2005-02-06 00:30:11 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " Updating scrollbar: height: " << t.paragraphs().size()
|
2005-02-07 15:37:07 +00:00
|
|
|
|
<< " curr par: " << cursor_.bottom().pit()
|
2004-03-18 12:53:43 +00:00
|
|
|
|
<< " default height " << defaultRowHeight() << endl;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// It would be better to fix the scrollbar to understand
|
|
|
|
|
// values in [0..1] and divide everything by wh
|
2005-08-02 14:25:48 +00:00
|
|
|
|
|
|
|
|
|
// estimated average paragraph height:
|
2005-11-07 15:06:42 +00:00
|
|
|
|
if (wh_ == 0)
|
2006-06-26 16:55:35 +00:00
|
|
|
|
wh_ = height_ / 4;
|
2005-08-02 14:25:48 +00:00
|
|
|
|
int h = t.getPar(anchor_ref_).height();
|
2005-11-07 15:06:42 +00:00
|
|
|
|
|
2005-08-02 14:25:48 +00:00
|
|
|
|
// Normalize anchor/offset (MV):
|
2005-11-07 15:06:42 +00:00
|
|
|
|
while (offset_ref_ > h && anchor_ref_ < parsize) {
|
2005-08-02 14:25:48 +00:00
|
|
|
|
anchor_ref_++;
|
|
|
|
|
offset_ref_ -= h;
|
|
|
|
|
h = t.getPar(anchor_ref_).height();
|
|
|
|
|
}
|
2005-11-07 15:06:42 +00:00
|
|
|
|
// Look at paragraph heights on-screen
|
|
|
|
|
int sumh = 0;
|
|
|
|
|
int nh = 0;
|
|
|
|
|
for (lyx::pit_type pit = anchor_ref_; pit <= parsize; ++pit) {
|
2006-06-26 16:55:35 +00:00
|
|
|
|
if (sumh > height_)
|
2005-11-07 15:06:42 +00:00
|
|
|
|
break;
|
2006-04-05 23:56:29 +00:00
|
|
|
|
int const h2 = t.getPar(pit).height();
|
2005-11-07 15:06:42 +00:00
|
|
|
|
sumh += h2;
|
|
|
|
|
nh++;
|
|
|
|
|
}
|
|
|
|
|
int const hav = sumh / nh;
|
|
|
|
|
// More realistic average paragraph height
|
|
|
|
|
if (hav > wh_)
|
|
|
|
|
wh_ = hav;
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2006-06-26 16:55:35 +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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ScrollbarParameters const & BufferView::Pimpl::scrollbarParameters() const
|
|
|
|
|
{
|
|
|
|
|
return scrollbarParameters_;
|
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
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "[ value = " << 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
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
LyXText & t = *bv_->text();
|
|
|
|
|
|
2005-11-07 15:06:42 +00:00
|
|
|
|
float const bar = value / float(wh_ * t.paragraphs().size());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
anchor_ref_ = int(bar * t.paragraphs().size());
|
2005-11-07 15:06:42 +00:00
|
|
|
|
if (anchor_ref_ > int(t.paragraphs().size()) - 1)
|
|
|
|
|
anchor_ref_ = int(t.paragraphs().size()) - 1;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
t.redoParagraph(anchor_ref_);
|
|
|
|
|
int const h = t.getPar(anchor_ref_).height();
|
|
|
|
|
offset_ref_ = int((bar * t.paragraphs().size() - anchor_ref_) * h);
|
|
|
|
|
update();
|
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
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int const height = 2 * defaultRowHeight();
|
|
|
|
|
int const first = height;
|
2006-06-26 16:55:35 +00:00
|
|
|
|
int const last = height_ - height;
|
2005-02-07 15:37:07 +00:00
|
|
|
|
LCursor & cur = cursor_;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
bv_funcs::CurStatus st = bv_funcs::status(bv_, cur);
|
2003-03-18 20:54:01 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
switch (st) {
|
|
|
|
|
case bv_funcs::CUR_ABOVE:
|
|
|
|
|
t.setCursorFromCoordinates(cur, 0, first);
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
break;
|
|
|
|
|
case bv_funcs::CUR_BELOW:
|
|
|
|
|
t.setCursorFromCoordinates(cur, 0, last);
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
break;
|
|
|
|
|
case bv_funcs::CUR_INSIDE:
|
2005-07-15 15:49:40 +00:00
|
|
|
|
int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int const newy = min(last, max(y, first));
|
|
|
|
|
if (y != newy) {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cur.reset(buffer_->inset());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
t.setCursorFromCoordinates(cur, 0, newy);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-26 15:55:52 +00:00
|
|
|
|
owner_->updateLayoutChoice();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 13:18:05 +00:00
|
|
|
|
void BufferView::Pimpl::scroll(int /*lines*/)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// if (!buffer_)
|
|
|
|
|
// return;
|
|
|
|
|
//
|
|
|
|
|
// LyXText const * t = bv_->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);
|
|
|
|
|
//
|
|
|
|
|
// // Update the scrollbar.
|
2006-07-13 16:37:55 +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
|
|
|
|
{
|
2005-02-07 15:37:07 +00:00
|
|
|
|
owner_->getLyXFunc().processKeySym(key, state);
|
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
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
LCursor & cur = 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 ||
|
2005-02-08 13:18:05 +00:00
|
|
|
|
cur.top() != xsel_cache_.cursor ||
|
|
|
|
|
cur.anchor_.top() != xsel_cache_.anchor)
|
2002-03-20 10:36:03 +00:00
|
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
|
xsel_cache_.cursor = cur.top();
|
|
|
|
|
xsel_cache_.anchor = cur.anchor_.top();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
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())
|
Split clipboard and X selection
* src/LyXAction.C
(LyXAction::init): handle new LFUN_CLIPBOARD_PASTE
* src/insets/insettabular.C
(InsetTabular::doDispatch): ditto
* src/insets/insetbox.C
(InsetBox::doDispatch): ditto
* src/insets/insetert.C
(InsetERT::doDispatch): ditto
(InsetERT::getStatus): ditto
* src/insets/insetcharstyle.C
(InsetCharStyle::doDispatch): ditto
* src/BufferView_pimpl.C
(BufferView::Pimpl::selectionRequest): stuff selection, not clipboard
* src/mathed/math_nestinset.C
(MathNestInset::lfunMousePress): get stuff selection, not clipboard
(MathNestInset::lfunMouseRelease): clipboard -> selection in
commented code
* src/CutAndPaste.C
(cutSelection): ditto
* src/frontends/{qt3,gtk}/GuiImplementation.C
(GuiImplementation::newWorkArea): create new selection, not clipboard,
since the clipboard is now an object
(GuiImplementation::destroyWorkArea): destroy selection, not clipboard
* src/frontends/{qt4,qt3,gtk}/GuiSelection.h: new, copied from
GuiClipboard.h
* src/frontends/{qt4,qt3,gtk}/GuiSelection.C: new, copied from
GuiClipboard.C
* src/frontends/{qt3,gtk}/GuiImplementation.h
(selection): new accessor for selection_
(selection_): new, the global selection object
* src/frontends/{qt4,qt3,gtk}/Makefile.am: add GuiSelection.C and
GuiSelection.h
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.C
(GuiClipboard::get): return clipboard, not selection
(GuiClipboard::put): stuff clipboard, not selection
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.h
(haveSelection): remove (this is now in GuiSelection)
* src/frontends/{qt3,gtk}/GuiClipboard.h
(old_work_area_): remove, since it is not needed anymore
* src/frontends/gtk/ghelpers.C
(getGTKStockIcon): handle LFUN_CLIPBOARD_PASTE
* src/frontends/Clipboard.h
(haveSelection): remove (this is now in Selection)
* src/frontends/qt4/GuiImplementation.[Ch]
(GuiImplementation::selection): new accessor for selection_
* src/frontends/Gui.h
(selection): New accessor for the global selection object
* src/frontends/Selection.h; new, copied from Clipboard.h
* src/frontends/Makefile.am: add Selection.h
* src/text3.C
(various): s/clipboard().haveSelection/selection().haveSelection/
(LyXText::dispatch): handle LFUN_CLIPBOARD_PASTE
(LyXText::getStatus): ditto
* src/lfuns.h: new lfun LFUN_CLIPBOARD_PASTE
* lib/ui/stdmenus.ui: add new lfun LFUN_CLIPBOARD_PASTE
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14408 a592a061-630c-0410-9148-cb99ea01b6c8
2006-07-10 11:32:25 +00:00
|
|
|
|
owner_->gui().selection().put(sel);
|
2004-03-24 17:38:54 +00:00
|
|
|
|
}
|
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()) {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
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
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
void BufferView::Pimpl::workAreaResize(int width, int height)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2006-06-26 16:55:35 +00:00
|
|
|
|
bool const widthChange = width != width_;
|
|
|
|
|
bool const heightChange = height != height_;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Update from work area
|
2006-06-26 16:55:35 +00:00
|
|
|
|
width_ = width;
|
|
|
|
|
height_ = height;
|
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
|
|
|
|
owner_->updateLayoutChoice();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
bool BufferView::Pimpl::fitCursor()
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2005-02-07 15:37:07 +00:00
|
|
|
|
if (bv_funcs::status(bv_, cursor_) == bv_funcs::CUR_INSIDE) {
|
|
|
|
|
LyXFont const font = cursor_.getFont();
|
2005-01-10 09:28:06 +00:00
|
|
|
|
int const asc = font_metrics::maxAscent(font);
|
|
|
|
|
int const des = font_metrics::maxDescent(font);
|
2005-07-15 15:49:40 +00:00
|
|
|
|
Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
|
2006-06-26 16:55:35 +00:00
|
|
|
|
if (p.y_ - asc >= 0 && p.y_ + des < height_)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2005-02-07 15:37:07 +00:00
|
|
|
|
center();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 13:23:14 +00:00
|
|
|
|
|
2006-03-10 16:10:35 +00:00
|
|
|
|
bool BufferView::Pimpl::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_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-07-04 00:04:46 +00:00
|
|
|
|
ViewMetricsInfo const & BufferView::Pimpl::viewMetricsInfo()
|
|
|
|
|
{
|
|
|
|
|
return metrics_info_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-07-14 09:56:21 +00:00
|
|
|
|
bool BufferView::Pimpl::update(Update::flags flags)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
2006-07-04 00:30:34 +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;
|
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Check needed to survive LyX startup
|
2006-07-13 16:37:55 +00:00
|
|
|
|
if (!buffer_)
|
2006-07-14 09:56:21 +00:00
|
|
|
|
return false;
|
2004-04-13 06:27:29 +00:00
|
|
|
|
|
2006-07-13 16:37:55 +00:00
|
|
|
|
// Update macro store
|
|
|
|
|
buffer_->buildMacros();
|
2004-08-14 14:03:42 +00:00
|
|
|
|
|
2006-07-13 16:37:55 +00:00
|
|
|
|
// First drawing step
|
2006-07-14 09:56:21 +00:00
|
|
|
|
updateMetrics(flags & Update::SinglePar);
|
2006-07-13 16:37:55 +00:00
|
|
|
|
|
2006-07-14 09:56:21 +00:00
|
|
|
|
// The second drawing step is done in WorkArea::redraw() if needed.
|
|
|
|
|
bool const need_second_step =
|
|
|
|
|
(flags & (Update::Force | Update::FitCursor | Update::MultiParSel))
|
|
|
|
|
&& (fitCursor() || multiParSel());
|
|
|
|
|
|
|
|
|
|
return need_second_step;
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
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()
|
|
|
|
|
{
|
2005-02-07 15:37:07 +00:00
|
|
|
|
if (!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();
|
2005-02-07 15:37:07 +00:00
|
|
|
|
LCursor & cur = 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-11-24 21:53:46 +00:00
|
|
|
|
return text->getPar(cur.selBegin().pit()).
|
2006-05-05 23:11:19 +00:00
|
|
|
|
lookupChange(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;
|
2005-02-07 15:37:07 +00:00
|
|
|
|
BOOST_ASSERT(cursor_.inTexted());
|
2001-01-28 18:31:36 +00:00
|
|
|
|
saved_positions[i] = Position(buffer_->fileName(),
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cursor_.paragraph().id(),
|
|
|
|
|
cursor_.pos());
|
2003-05-13 09:48:57 +00:00
|
|
|
|
if (i > 0)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
owner_->message(bformat(_("Saved bookmark %1$d"), 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
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
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);
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Don't ask, just load it
|
|
|
|
|
::loadLyXFile(b, fname);
|
2003-06-20 12:46:28 +00:00
|
|
|
|
}
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (b)
|
2004-03-18 12:53:43 +00:00
|
|
|
|
setBuffer(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;
|
|
|
|
|
|
2005-02-22 11:41:22 +00:00
|
|
|
|
bv_->setCursor(makeDocIterator(par, 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)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
owner_->message(bformat(_("Moved to bookmark %1$d"), 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
|
|
|
|
|
2006-04-05 22:56:18 +00:00
|
|
|
|
void BufferView::Pimpl::saveSavedPositions()
|
|
|
|
|
{
|
|
|
|
|
// save bookmarks. It is better to use the pit interface
|
|
|
|
|
// but I do not know how to effectively convert between
|
|
|
|
|
// par_id and pit.
|
|
|
|
|
for (unsigned int i=1; i < saved_positions_num; ++i) {
|
|
|
|
|
if ( isSavedPosition(i) )
|
|
|
|
|
LyX::ref().session().saveBookmark( boost::tie(
|
2006-04-05 23:56:29 +00:00
|
|
|
|
i,
|
2006-04-05 22:56:18 +00:00
|
|
|
|
saved_positions[i].filename,
|
|
|
|
|
saved_positions[i].par_id,
|
|
|
|
|
saved_positions[i].par_pos) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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)
|
2006-04-09 00:26:19 +00:00
|
|
|
|
intl.keyMapSec();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
} else {
|
2003-11-10 09:06:48 +00:00
|
|
|
|
if (intl.keymap == Intl::SECONDARY)
|
2006-04-09 00:26:19 +00:00
|
|
|
|
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
|
|
|
|
{
|
2005-02-07 15:37:07 +00:00
|
|
|
|
CursorSlice & bot = cursor_.bottom();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
lyx::pit_type const pit = bot.pit();
|
|
|
|
|
bot.text()->redoParagraph(pit);
|
|
|
|
|
Paragraph const & par = bot.text()->paragraphs()[pit];
|
|
|
|
|
anchor_ref_ = pit;
|
2005-07-15 15:49:40 +00:00
|
|
|
|
offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_
|
2006-06-26 16:55:35 +00:00
|
|
|
|
+ par.ascent() - height_ / 2;
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
2000-05-20 01:38:25 +00:00
|
|
|
|
|
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
void BufferView::Pimpl::menuInsertLyXFile(string const & filenm)
|
2001-02-23 16:10:03 +00:00
|
|
|
|
{
|
2005-11-29 15:08:35 +00:00
|
|
|
|
BOOST_ASSERT(cursor_.inTexted());
|
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()) {
|
2006-07-13 16:37:55 +00:00
|
|
|
|
string const trypath = buffer_->filePath();
|
2001-02-23 16:10:03 +00:00
|
|
|
|
// If directory is writeable, use this as default.
|
2006-04-08 09:09:57 +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")),
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string(addPath(package().system_support(), "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
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Get absolute path of file and add ".lyx"
|
|
|
|
|
// to the filename if necessary
|
2006-04-08 22:31:11 +00:00
|
|
|
|
filename = fileSearch(string(), filename, "lyx");
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string const disp_fn = makeDisplayPath(filename);
|
2003-05-13 09:48:57 +00:00
|
|
|
|
owner_->message(bformat(_("Inserting document %1$s..."), disp_fn));
|
2004-08-14 19:55:00 +00:00
|
|
|
|
|
2005-11-29 15:08:35 +00:00
|
|
|
|
string res;
|
|
|
|
|
Buffer buf("", false);
|
2006-07-15 22:43:37 +00:00
|
|
|
|
// FIXME: is there a need for something like that?
|
|
|
|
|
//buf.errors.connect(boost::bind(&LyXView::showErrorList, owner_, _1));
|
2006-04-08 22:31:11 +00:00
|
|
|
|
if (::loadLyXFile(&buf, makeAbsPath(filename))) {
|
2006-04-05 23:56:29 +00:00
|
|
|
|
lyx::cap::pasteParagraphList(cursor_, buf.paragraphs(),
|
2005-11-29 15:08:35 +00:00
|
|
|
|
buf.params().textclass);
|
|
|
|
|
res = _("Document %1$s inserted.");
|
|
|
|
|
} else
|
|
|
|
|
res = _("Could not insert document %1$s");
|
2004-08-14 19:55:00 +00:00
|
|
|
|
|
2005-11-29 15:08:35 +00:00
|
|
|
|
owner_->message(bformat(res, disp_fn));
|
2006-07-14 21:47:48 +00:00
|
|
|
|
owner_->showErrorList(_("Document insertion"));
|
2005-02-07 15:37:07 +00:00
|
|
|
|
resizeCurrentBuffer();
|
2001-02-23 16:10:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
void BufferView::Pimpl::trackChanges()
|
|
|
|
|
{
|
2005-02-07 15:37:07 +00:00
|
|
|
|
bool const tracking = buffer_->params().tracking_changes;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
|
|
if (!tracking) {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
for_each(buffer_->par_iterator_begin(),
|
|
|
|
|
buffer_->par_iterator_end(),
|
2004-11-06 15:23:12 +00:00
|
|
|
|
bind(&Paragraph::trackChanges, _1, Change::UNCHANGED));
|
2005-02-07 15:37:07 +00:00
|
|
|
|
buffer_->params().tracking_changes = true;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// We cannot allow undos beyond the freeze point
|
2005-02-07 15:37:07 +00:00
|
|
|
|
buffer_->undostack().clear();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
} else {
|
2005-09-07 10:00:19 +00:00
|
|
|
|
cursor_.setCursor(doc_iterator_begin(buffer_->inset()));
|
2006-03-10 16:46:03 +00:00
|
|
|
|
if (lyx::find::findNextChange(bv_)) {
|
2003-03-09 21:03:43 +00:00
|
|
|
|
owner_->getDialogs().show("changes");
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
for_each(buffer_->par_iterator_begin(),
|
|
|
|
|
buffer_->par_iterator_end(),
|
2004-11-06 15:23:12 +00:00
|
|
|
|
mem_fun_ref(&Paragraph::untrackChanges));
|
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
buffer_->params().tracking_changes = false;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
buffer_->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
|
|
|
|
{
|
2005-07-15 00:39:44 +00:00
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION << "[ cmd0 " << cmd0 << "]" << endl;
|
2005-02-06 00:30:11 +00:00
|
|
|
|
|
|
|
|
|
// This is only called for mouse related events including
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// LFUN_FILE_OPEN generated by drag-and-drop.
|
2004-01-30 11:41:12 +00:00
|
|
|
|
FuncRequest cmd = cmd0;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Handle drag&drop
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (cmd.action == LFUN_FILE_OPEN) {
|
|
|
|
|
owner_->dispatch(cmd);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
if (!buffer_)
|
2004-04-13 06:27:29 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
LCursor cur(*bv_);
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cur.push(buffer_->inset());
|
|
|
|
|
cur.selection() = cursor_.selection();
|
2003-03-24 02:31:44 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +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
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// E.g. Qt mouse press when no buffer
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!available())
|
|
|
|
|
return false;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
2004-04-07 08:07:26 +00:00
|
|
|
|
// Either the inset under the cursor or the
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// surrounding LyXText will handle this event.
|
|
|
|
|
|
2004-04-07 08:07:26 +00:00
|
|
|
|
// Build temporary cursor.
|
2006-06-26 16:55:35 +00:00
|
|
|
|
cmd.y = min(max(cmd.y, -1), height_);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y);
|
2005-07-15 00:39:44 +00:00
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION
|
|
|
|
|
// << " * hit inset at tip: " << inset << endl;
|
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION
|
|
|
|
|
// << " * created temp cursor:" << cur << endl;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
2004-04-07 08:07:26 +00:00
|
|
|
|
// Put anchor at the same position.
|
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// Try to dispatch to an non-editable inset near this position
|
2004-04-03 08:37:12 +00:00
|
|
|
|
// via the temp cursor. If the inset wishes to change the real
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// cursor it has to do so explicitly by using
|
2004-08-14 19:55:00 +00:00
|
|
|
|
// cur.bv().cursor() = cur; (or similar)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (inset)
|
|
|
|
|
inset->dispatch(cur, cmd);
|
|
|
|
|
|
2004-04-07 08:07:26 +00:00
|
|
|
|
// Now dispatch to the temporary cursor. If the real cursor should
|
2004-04-20 08:51:15 +00:00
|
|
|
|
// be modified, the inset's dispatch has to do so explicitly.
|
2004-08-13 14:56:06 +00:00
|
|
|
|
if (!cur.result().dispatched())
|
|
|
|
|
cur.dispatch(cmd);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
2004-08-13 14:56:06 +00:00
|
|
|
|
if (cur.result().dispatched()) {
|
2004-04-07 20:20:15 +00:00
|
|
|
|
// Redraw if requested or necessary.
|
2005-05-31 14:40:30 +00:00
|
|
|
|
if (cur.result().update())
|
|
|
|
|
update(Update::FitCursor | Update::Force);
|
|
|
|
|
else
|
2006-03-10 16:10:35 +00:00
|
|
|
|
update(Update::FitCursor | Update::MultiParSel);
|
2004-04-07 20:20:15 +00:00
|
|
|
|
}
|
2003-05-03 18:05:53 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Skip these when selecting
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (cmd.action != LFUN_MOUSE_MOTION) {
|
|
|
|
|
owner_->updateLayoutChoice();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
owner_->updateToolbars();
|
2003-08-05 19:51:45 +00:00
|
|
|
|
}
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Slight hack: this is only called currently when we
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// clicked somewhere, so we force through the display
|
|
|
|
|
// of the new status here.
|
|
|
|
|
owner_->clearMessage();
|
2004-01-30 11:41:12 +00:00
|
|
|
|
return true;
|
2003-03-24 02:31:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-01 08:58:45 +00:00
|
|
|
|
FuncStatus BufferView::Pimpl::getStatus(FuncRequest const & cmd)
|
|
|
|
|
{
|
|
|
|
|
FuncStatus flag;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-04-01 08:58:45 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_UNDO:
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.enabled(!buffer_->undostack().empty());
|
2004-04-01 08:58:45 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_REDO:
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.enabled(!buffer_->redostack().empty());
|
2004-04-01 08:58:45 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_FILE_INSERT:
|
|
|
|
|
case LFUN_FILE_INSERT_ASCII_PARA:
|
|
|
|
|
case LFUN_FILE_INSERT_ASCII:
|
2006-05-22 14:28:43 +00:00
|
|
|
|
case LFUN_BOOKMARK_SAVE:
|
2005-11-29 15:08:35 +00:00
|
|
|
|
// FIXME: Actually, these LFUNS should be moved to LyXText
|
|
|
|
|
flag.enabled(cursor_.inTexted());
|
|
|
|
|
break;
|
2004-04-01 08:58:45 +00:00
|
|
|
|
case LFUN_FONT_STATE:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_LABEL_INSERT:
|
|
|
|
|
case LFUN_PARAGRAPH_GOTO:
|
2006-04-26 17:43:03 +00:00
|
|
|
|
// FIXME handle non-trivially
|
|
|
|
|
case LFUN_OUTLINE_UP:
|
|
|
|
|
case LFUN_OUTLINE_DOWN:
|
|
|
|
|
case LFUN_OUTLINE_IN:
|
|
|
|
|
case LFUN_OUTLINE_OUT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_ERROR_NEXT:
|
|
|
|
|
case LFUN_NOTE_NEXT:
|
|
|
|
|
case LFUN_REFERENCE_NEXT:
|
2004-04-01 08:58:45 +00:00
|
|
|
|
case LFUN_WORD_FIND:
|
|
|
|
|
case LFUN_WORD_REPLACE:
|
|
|
|
|
case LFUN_MARK_OFF:
|
|
|
|
|
case LFUN_MARK_ON:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_MARK_TOGGLE:
|
|
|
|
|
case LFUN_SCREEN_RECENTER:
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_ADD:
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_DEL:
|
2004-12-27 16:30:27 +00:00
|
|
|
|
case LFUN_WORDS_COUNT:
|
2004-04-01 08:58:45 +00:00
|
|
|
|
flag.enabled(true);
|
|
|
|
|
break;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-06-06 13:11:30 +00:00
|
|
|
|
case LFUN_LABEL_GOTO: {
|
|
|
|
|
flag.enabled(!cmd.argument.empty()
|
|
|
|
|
|| getInsetByCode<InsetRef>(cursor_, InsetBase::REF_CODE));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-01 08:58:45 +00:00
|
|
|
|
case LFUN_BOOKMARK_GOTO:
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.enabled(isSavedPosition(convert<unsigned int>(cmd.argument)));
|
2004-04-01 08:58:45 +00:00
|
|
|
|
break;
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_CHANGES_TRACK:
|
2004-04-01 08:58:45 +00:00
|
|
|
|
flag.enabled(true);
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.setOnOff(buffer_->params().tracking_changes);
|
2004-04-01 08:58:45 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_CHANGES_OUTPUT: {
|
2006-03-28 18:49:46 +00:00
|
|
|
|
OutputParams runparams;
|
|
|
|
|
LaTeXFeatures features(*buffer_, buffer_->params(), runparams);
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.enabled(buffer_ && buffer_->params().tracking_changes
|
2005-01-24 17:12:19 +00:00
|
|
|
|
&& features.isAvailable("dvipost"));
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.setOnOff(buffer_->params().output_changes);
|
2005-01-24 17:12:19 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_CHANGES_MERGE:
|
|
|
|
|
case LFUN_CHANGE_ACCEPT: // what about these two
|
|
|
|
|
case LFUN_CHANGE_REJECT: // what about these two
|
|
|
|
|
case LFUN_ALL_CHANGES_ACCEPT:
|
|
|
|
|
case LFUN_ALL_CHANGES_REJECT:
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.enabled(buffer_ && buffer_->params().tracking_changes);
|
2004-04-01 08:58:45 +00:00
|
|
|
|
break;
|
2006-04-28 16:13:35 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_BUFFER_TOGGLE_COMPRESSION: {
|
2006-04-28 16:13:35 +00:00
|
|
|
|
flag.setOnOff(buffer_->params().compressed);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-01 08:58:45 +00:00
|
|
|
|
default:
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
|
2001-02-23 16:10:03 +00:00
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION
|
|
|
|
|
// << [ cmd = " << cmd << "]" << endl;
|
|
|
|
|
|
2003-02-26 19:28:38 +00:00
|
|
|
|
// Make sure that the cached BufferView is correct.
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::ACTION] << BOOST_CURRENT_FUNCTION
|
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
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
LCursor & cur = 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:
|
2006-04-09 00:26:19 +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:
|
2006-04-09 00:26:19 +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:
|
2006-04-09 00:26:19 +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
|
|
|
|
|
2001-02-23 16:10:03 +00:00
|
|
|
|
case LFUN_BOOKMARK_SAVE:
|
2005-01-27 21:05:44 +00:00
|
|
|
|
savePosition(convert<unsigned int>(cmd.argument));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BOOKMARK_GOTO:
|
2005-01-27 21:05:44 +00:00
|
|
|
|
restorePosition(convert<unsigned int>(cmd.argument));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2005-05-08 10:02:38 +00:00
|
|
|
|
case LFUN_LABEL_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 =
|
2005-02-07 15:37:07 +00:00
|
|
|
|
getInsetByCode<InsetRef>(cursor_,
|
2004-08-14 00:27:15 +00:00
|
|
|
|
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
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_PARAGRAPH_GOTO: {
|
2005-02-09 11:27:21 +00:00
|
|
|
|
int const id = convert<int>(cmd.argument);
|
|
|
|
|
ParIterator par = buffer_->getParFromID(id);
|
|
|
|
|
if (par == buffer_->par_iterator_end()) {
|
|
|
|
|
lyxerr[Debug::INFO] << "No matching paragraph found! ["
|
|
|
|
|
<< id << ']' << endl;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::INFO] << "Paragraph " << par->id()
|
|
|
|
|
<< " found." << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the cursor
|
2005-02-22 11:41:22 +00:00
|
|
|
|
bv_->setCursor(makeDocIterator(par, 0));
|
2005-02-09 11:27:21 +00:00
|
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
switchKeyMap();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-26 17:43:03 +00:00
|
|
|
|
case LFUN_OUTLINE_UP:
|
2006-04-28 07:28:10 +00:00
|
|
|
|
lyx::toc::outline(lyx::toc::Up, cursor_);
|
2006-04-20 06:50:26 +00:00
|
|
|
|
cursor_.text()->setCursor(cursor_, cursor_.pit(), 0);
|
2006-04-16 14:19:25 +00:00
|
|
|
|
updateLabels(*buffer_);
|
2006-04-26 17:43:03 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_OUTLINE_DOWN:
|
2006-04-28 07:28:10 +00:00
|
|
|
|
lyx::toc::outline(lyx::toc::Down, cursor_);
|
2006-04-26 17:43:03 +00:00
|
|
|
|
cursor_.text()->setCursor(cursor_, cursor_.pit(), 0);
|
|
|
|
|
updateLabels(*buffer_);
|
|
|
|
|
break;
|
|
|
|
|
case LFUN_OUTLINE_IN:
|
2006-04-28 07:28:10 +00:00
|
|
|
|
lyx::toc::outline(lyx::toc::In, cursor_);
|
2006-04-26 17:43:03 +00:00
|
|
|
|
updateLabels(*buffer_);
|
2006-07-03 22:31:51 +00:00
|
|
|
|
break;
|
2006-04-26 17:43:03 +00:00
|
|
|
|
case LFUN_OUTLINE_OUT:
|
2006-04-28 07:28:10 +00:00
|
|
|
|
lyx::toc::outline(lyx::toc::Out, cursor_);
|
2006-04-26 17:43:03 +00:00
|
|
|
|
updateLabels(*buffer_);
|
|
|
|
|
break;
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_ERROR_NEXT:
|
2005-02-22 11:41:22 +00:00
|
|
|
|
bv_funcs::gotoInset(bv_, InsetBase::ERROR_CODE, false);
|
|
|
|
|
break;
|
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_NOTE_NEXT:
|
2005-02-22 11:41:22 +00:00
|
|
|
|
bv_funcs::gotoInset(bv_, InsetBase::NOTE_CODE, false);
|
|
|
|
|
break;
|
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_REFERENCE_NEXT: {
|
2005-02-22 11:41:22 +00:00
|
|
|
|
vector<InsetBase_code> tmp;
|
|
|
|
|
tmp.push_back(InsetBase::LABEL_CODE);
|
|
|
|
|
tmp.push_back(InsetBase::REF_CODE);
|
|
|
|
|
bv_funcs::gotoInset(bv_, tmp, true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_CHANGES_TRACK:
|
2003-02-08 19:18:01 +00:00
|
|
|
|
trackChanges();
|
|
|
|
|
break;
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_CHANGES_OUTPUT: {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
bool const state = buffer_->params().output_changes;
|
|
|
|
|
buffer_->params().output_changes = !state;
|
2005-01-24 17:12:19 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_CHANGES_MERGE:
|
2006-03-10 16:46:03 +00:00
|
|
|
|
if (lyx::find::findNextChange(bv_))
|
|
|
|
|
owner_->getDialogs().show("changes");
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_ALL_CHANGES_ACCEPT: {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cursor_.reset(buffer_->inset());
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-03-02 12:16:00 +00:00
|
|
|
|
#warning FIXME changes
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2003-08-04 09:06:35 +00:00
|
|
|
|
while (lyx::find::findNextChange(bv_))
|
2005-02-07 15:37:07 +00:00
|
|
|
|
bv_->getLyXText()->acceptChange(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
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_ALL_CHANGES_REJECT: {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cursor_.reset(buffer_->inset());
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-03-02 12:16:00 +00:00
|
|
|
|
#warning FIXME changes
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2003-08-04 09:06:35 +00:00
|
|
|
|
while (lyx::find::findNextChange(bv_))
|
2005-02-07 15:37:07 +00:00
|
|
|
|
bv_->getLyXText()->rejectChange(cursor_);
|
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();
|
|
|
|
|
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;
|
|
|
|
|
cur.resetAnchor();
|
2004-02-03 11:49:05 +00:00
|
|
|
|
cur.message(N_("Mark on"));
|
2004-01-14 17:21:39 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_MARK_TOGGLE:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (cur.mark()) {
|
2004-03-01 17:12:09 +00:00
|
|
|
|
cur.mark() = false;
|
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-01-14 17:21:39 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_SCREEN_RECENTER:
|
2005-02-07 15:37:07 +00:00
|
|
|
|
center();
|
2004-02-20 11:00:41 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_BIBTEX_DATABASE_ADD: {
|
2005-06-25 15:57:15 +00:00
|
|
|
|
LCursor tmpcur = cursor_;
|
|
|
|
|
bv_funcs::findInset(tmpcur, InsetBase::BIBTEX_CODE, false);
|
|
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
|
|
|
|
InsetBase::BIBTEX_CODE);
|
2006-04-15 11:46:17 +00:00
|
|
|
|
if (inset) {
|
|
|
|
|
if (inset->addDatabase(cmd.argument))
|
|
|
|
|
buffer_->updateBibfilesCache();
|
|
|
|
|
}
|
2005-06-25 15:57:15 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_BIBTEX_DATABASE_DEL: {
|
2005-06-25 15:57:15 +00:00
|
|
|
|
LCursor tmpcur = cursor_;
|
|
|
|
|
bv_funcs::findInset(tmpcur, InsetBase::BIBTEX_CODE, false);
|
|
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
|
|
|
|
InsetBase::BIBTEX_CODE);
|
2006-04-15 11:46:17 +00:00
|
|
|
|
if (inset) {
|
|
|
|
|
if (inset->delDatabase(cmd.argument))
|
|
|
|
|
buffer_->updateBibfilesCache();
|
|
|
|
|
}
|
2005-06-25 15:57:15 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-27 16:30:27 +00:00
|
|
|
|
case LFUN_WORDS_COUNT: {
|
|
|
|
|
DocIterator from, to;
|
|
|
|
|
if (cur.selection()) {
|
|
|
|
|
from = cur.selectionBegin();
|
|
|
|
|
to = cur.selectionEnd();
|
|
|
|
|
} else {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
from = doc_iterator_begin(buffer_->inset());
|
|
|
|
|
to = doc_iterator_end(buffer_->inset());
|
2004-12-27 16:30:27 +00:00
|
|
|
|
}
|
|
|
|
|
int const count = countWords(from, to);
|
|
|
|
|
string message;
|
|
|
|
|
if (count != 1) {
|
|
|
|
|
if (cur.selection())
|
2005-01-06 15:40:49 +00:00
|
|
|
|
message = bformat(_("%1$d words in selection."),
|
|
|
|
|
count);
|
2004-12-27 16:30:27 +00:00
|
|
|
|
else
|
2005-01-06 15:40:49 +00:00
|
|
|
|
message = bformat(_("%1$d words in document."),
|
|
|
|
|
count);
|
2004-12-27 16:30:27 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (cur.selection())
|
|
|
|
|
message = _("One word in selection.");
|
2005-01-06 15:40:49 +00:00
|
|
|
|
else
|
2004-12-27 16:30:27 +00:00
|
|
|
|
message = _("One word in document.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Alert::information(_("Count words"), message);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-04-28 16:13:35 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_BUFFER_TOGGLE_COMPRESSION:
|
2006-04-28 16:13:35 +00:00
|
|
|
|
// turn compression on/off
|
|
|
|
|
buffer_->params().compressed = !buffer_->params().compressed;
|
|
|
|
|
break;
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
2006-07-04 00:04:46 +00:00
|
|
|
|
void BufferView::Pimpl::updateMetrics(bool singlepar)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Remove old position cache
|
2004-11-30 01:59:49 +00:00
|
|
|
|
theCoords.clear();
|
|
|
|
|
BufferView & bv = *bv_;
|
|
|
|
|
LyXText * const text = bv.text();
|
2006-03-20 15:05:07 +00:00
|
|
|
|
lyx::pit_type size = int(text->paragraphs().size());
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (anchor_ref_ > int(text->paragraphs().size() - 1)) {
|
|
|
|
|
anchor_ref_ = int(text->paragraphs().size() - 1);
|
|
|
|
|
offset_ref_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lyx::pit_type const pit = anchor_ref_;
|
|
|
|
|
int pit1 = pit;
|
|
|
|
|
int pit2 = pit;
|
2005-02-06 00:30:11 +00:00
|
|
|
|
size_t const npit = text->paragraphs().size();
|
|
|
|
|
|
2005-10-07 12:00:41 +00:00
|
|
|
|
// Rebreak anchor paragraph. In Single Paragraph mode, rebreak only
|
|
|
|
|
// the (main text, not inset!) paragraph containing the cursor.
|
2006-04-05 23:56:29 +00:00
|
|
|
|
// (if this paragraph contains insets etc., rebreaking will
|
2005-10-07 12:00:41 +00:00
|
|
|
|
// recursively descend)
|
|
|
|
|
if (!singlepar || pit == cursor_.bottom().pit())
|
|
|
|
|
text->redoParagraph(pit);
|
|
|
|
|
int y0 = text->getPar(pit).ascent() - offset_ref_;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-10-07 12:00:41 +00:00
|
|
|
|
// Redo paragraphs above anchor if necessary; again, in Single Par
|
|
|
|
|
// mode, only if we encounter the (main text) one having the cursor.
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int y1 = y0;
|
2005-10-07 12:00:41 +00:00
|
|
|
|
while (y1 > 0 && pit1 > 0) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y1 -= text->getPar(pit1).ascent();
|
|
|
|
|
--pit1;
|
2005-10-07 12:00:41 +00:00
|
|
|
|
if (!singlepar || pit1 == cursor_.bottom().pit())
|
|
|
|
|
text->redoParagraph(pit1);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y1 -= text->getPar(pit1).descent();
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Take care of ascent of first line
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y1 -= text->getPar(pit1).ascent();
|
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Normalize anchor for next time
|
2004-11-30 01:59:49 +00:00
|
|
|
|
anchor_ref_ = pit1;
|
|
|
|
|
offset_ref_ = -y1;
|
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Grey at the beginning is ugly
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (pit1 == 0 && y1 > 0) {
|
|
|
|
|
y0 -= y1;
|
|
|
|
|
y1 = 0;
|
|
|
|
|
anchor_ref_ = 0;
|
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-10-07 12:00:41 +00:00
|
|
|
|
// Redo paragraphs below the anchor if necessary. Single par mode:
|
|
|
|
|
// only the one containing the cursor if encountered.
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int y2 = y0;
|
2005-10-07 12:00:41 +00:00
|
|
|
|
while (y2 < bv.workHeight() && pit2 < int(npit) - 1) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y2 += text->getPar(pit2).descent();
|
|
|
|
|
++pit2;
|
2005-10-07 12:00:41 +00:00
|
|
|
|
if (!singlepar || pit2 == cursor_.bottom().pit())
|
|
|
|
|
text->redoParagraph(pit2);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y2 += text->getPar(pit2).ascent();
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Take care of descent of last line
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y2 += text->getPar(pit2).descent();
|
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// The coordinates of all these paragraphs are correct, cache them
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int y = y1;
|
2006-07-10 17:14:44 +00:00
|
|
|
|
CoordCache::InnerParPosCache & parPos = theCoords.parPos()[text];
|
2004-11-30 01:59:49 +00:00
|
|
|
|
for (lyx::pit_type pit = pit1; pit <= pit2; ++pit) {
|
2006-07-10 17:30:35 +00:00
|
|
|
|
Paragraph const & par = text->getPar(pit);
|
2006-07-10 14:32:11 +00:00
|
|
|
|
y += par.ascent();
|
|
|
|
|
parPos[pit] = Point(0, y);
|
2005-10-07 12:00:41 +00:00
|
|
|
|
if (singlepar && pit == cursor_.bottom().pit()) {
|
2006-04-05 23:56:29 +00:00
|
|
|
|
// In Single Paragraph mode, collect here the
|
|
|
|
|
// y1 and y2 of the (one) paragraph the cursor is in
|
2006-07-10 14:32:11 +00:00
|
|
|
|
y1 = y - par.ascent();
|
|
|
|
|
y2 = y + par.descent();
|
2005-10-07 12:00:41 +00:00
|
|
|
|
}
|
2006-07-10 14:32:11 +00:00
|
|
|
|
y += par.descent();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-10-11 11:29:35 +00:00
|
|
|
|
if (singlepar) {
|
|
|
|
|
// collect cursor paragraph iter bounds
|
2005-10-07 12:00:41 +00:00
|
|
|
|
pit1 = cursor_.bottom().pit();
|
|
|
|
|
pit2 = cursor_.bottom().pit();
|
|
|
|
|
}
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2006-04-05 23:56:29 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " y1: " << y1
|
|
|
|
|
<< " y2: " << y2
|
|
|
|
|
<< " pit1: " << pit1
|
|
|
|
|
<< " pit2: " << pit2
|
|
|
|
|
<< " npit: " << npit
|
|
|
|
|
<< " singlepar: " << singlepar
|
|
|
|
|
<< "size: " << size
|
|
|
|
|
<< endl;
|
2005-02-06 00:30:11 +00:00
|
|
|
|
|
2006-07-04 00:04:46 +00:00
|
|
|
|
metrics_info_ = ViewMetricsInfo(pit1, pit2, y1, y2, singlepar, size);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|