2002-06-12 02:54:19 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file BufferView.cpp
|
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
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "BufferList.h"
|
|
|
|
|
#include "BufferParams.h"
|
2006-12-29 23:54:48 +00:00
|
|
|
|
#include "bufferview_funcs.h"
|
2007-04-26 04:41:58 +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"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
|
#include "ErrorList.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "factory.h"
|
|
|
|
|
#include "FloatList.h"
|
2007-04-26 04:41:58 +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"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Intl.h"
|
|
|
|
|
#include "InsetIterator.h"
|
|
|
|
|
#include "Language.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "callback.h" // added for Dispatch functions
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyX.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "lyxfind.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXFunc.h"
|
2007-04-29 18:58:28 +00:00
|
|
|
|
#include "Layout.h"
|
2007-04-29 23:33:02 +00:00
|
|
|
|
#include "Text.h"
|
2007-04-29 19:53:54 +00:00
|
|
|
|
#include "TextClass.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXRC.h"
|
|
|
|
|
#include "Session.h"
|
|
|
|
|
#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"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "ParIterator.h"
|
|
|
|
|
#include "TexRow.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "toc.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Undo.h"
|
|
|
|
|
#include "VSpace.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "WordLangTuple.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "MetricsInfo.h"
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetBibtex.h"
|
|
|
|
|
#include "insets/InsetCommand.h" // ChangeRefs
|
|
|
|
|
#include "insets/InsetRef.h"
|
|
|
|
|
#include "insets/InsetText.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-04-28 20:44:46 +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-08-10 10:21:09 +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"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
|
#include "support/FileFilterList.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "support/filetools.h"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
|
#include "support/Package.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#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>
|
|
|
|
|
|
2007-07-17 17:40:44 +00:00
|
|
|
|
using std::distance;
|
|
|
|
|
using std::endl;
|
|
|
|
|
using std::istringstream;
|
|
|
|
|
using std::make_pair;
|
|
|
|
|
using std::min;
|
|
|
|
|
using std::max;
|
|
|
|
|
using std::mem_fun_ref;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
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
|
|
|
|
|
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>
|
2007-04-29 13:39:47 +00:00
|
|
|
|
T * getInsetByCode(Cursor & cur, Inset::Code code)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
{
|
|
|
|
|
T * inset = 0;
|
|
|
|
|
DocIterator it = cur;
|
|
|
|
|
if (it.nextInset() &&
|
|
|
|
|
it.nextInset()->lyxCode() == code) {
|
|
|
|
|
inset = static_cast<T*>(it.nextInset());
|
|
|
|
|
}
|
|
|
|
|
return inset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
BufferView::BufferView(Buffer & buf)
|
|
|
|
|
: width_(0), height_(0), buffer_(buf), 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);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cursor_.push(buffer_.inset());
|
|
|
|
|
cursor_.resetAnchor();
|
|
|
|
|
buffer_.text().setCurrentFont(cursor_);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
|
|
|
|
|
graphics::Previews::get().generateBufferPreviews(buffer_);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
BufferView::~BufferView()
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2007-08-22 09:06:13 +00:00
|
|
|
|
// current buffer is going to be switched-off, save cursor pos
|
|
|
|
|
// Ideally, the whole cursor stack should be saved, but session
|
|
|
|
|
// currently can only handle bottom (whole document) level pit and pos.
|
|
|
|
|
// That is to say, if a cursor is in a nested inset, it will be
|
|
|
|
|
// restore to the left of the top level inset.
|
|
|
|
|
LyX::ref().session().lastFilePos().save(
|
|
|
|
|
support::FileName(buffer_.fileName()),
|
|
|
|
|
boost::tie(cursor_.bottom().pit(), cursor_.bottom().pos()) );
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-21 13:03:55 +00:00
|
|
|
|
Buffer & BufferView::buffer()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-08-21 13:03:55 +00:00
|
|
|
|
return buffer_;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-19 17:57:40 +00:00
|
|
|
|
|
2007-08-21 13:03:55 +00:00
|
|
|
|
Buffer const & BufferView::buffer() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-08-21 13:03:55 +00:00
|
|
|
|
return buffer_;
|
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.
|
2007-04-01 15:09:08 +00:00
|
|
|
|
LYXERR(Debug::DEBUG)
|
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "[fitcursor = " << (flags & Update::FitCursor)
|
|
|
|
|
<< ", forceupdate = " << (flags & Update::Force)
|
|
|
|
|
<< ", singlepar = " << (flags & Update::SinglePar)
|
2007-08-21 07:33:46 +00:00
|
|
|
|
<< "] buffer: " << &buffer_ << endl;
|
2006-10-21 10:56:36 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// Update macro store
|
2007-04-19 13:37:17 +00:00
|
|
|
|
if (!(cursor().inMathed() && cursor().inMacroMode()))
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.buildMacros();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
|
if (flags == Update::FitCursor
|
2007-01-20 01:23:07 +00:00
|
|
|
|
|| 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()
|
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Text & 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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-01 15:09:08 +00:00
|
|
|
|
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
|
|
|
|
{
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION
|
2006-09-16 10:08:51 +00:00
|
|
|
|
<< "[ value = " << value << "]" << endl;
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Text & 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-08-21 07:33:46 +00:00
|
|
|
|
Text & t = buffer_.text();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
int const height = 2 * defaultRowHeight();
|
|
|
|
|
int const first = height;
|
|
|
|
|
int const last = height_ - height;
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor & cur = cursor_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
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.
|
2007-08-21 07:33:46 +00:00
|
|
|
|
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.
|
2007-08-21 07:33:46 +00:00
|
|
|
|
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) {
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cur.reset(buffer_.inset());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
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
|
|
|
|
|
2007-03-29 03:41:55 +00:00
|
|
|
|
void BufferView::saveBookmark(unsigned int idx)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-04-16 19:01:32 +00:00
|
|
|
|
// tenatively save bookmark, id and pos will be used to
|
|
|
|
|
// acturately locate a bookmark in a 'live' lyx session.
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// pit and pos will be updated with bottom level pit/pos
|
2007-04-16 19:01:32 +00:00
|
|
|
|
// when lyx exits.
|
2006-11-01 15:55:17 +00:00
|
|
|
|
LyX::ref().session().bookmarks().save(
|
2007-08-21 07:33:46 +00:00
|
|
|
|
FileName(buffer_.fileName()),
|
2007-04-16 19:01:32 +00:00
|
|
|
|
cursor_.bottom().pit(),
|
|
|
|
|
cursor_.bottom().pos(),
|
2006-11-01 15:55:17 +00:00
|
|
|
|
cursor_.paragraph().id(),
|
|
|
|
|
cursor_.pos(),
|
2007-03-29 03:41:55 +00:00
|
|
|
|
idx
|
2006-11-01 15:55:17 +00:00
|
|
|
|
);
|
2007-03-29 03:41:55 +00:00
|
|
|
|
if (idx)
|
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-04-16 19:01:32 +00:00
|
|
|
|
boost::tuple<pit_type, pos_type, int> BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
|
|
|
|
|
int top_id, pos_type top_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
|
2007-04-16 19:01:32 +00:00
|
|
|
|
// This is the case for a 'live' bookmark when unique paragraph ID
|
|
|
|
|
// is used to track bookmarks.
|
|
|
|
|
if (top_id > 0) {
|
2007-08-21 07:33:46 +00:00
|
|
|
|
ParIterator par = buffer_.getParFromID(top_id);
|
|
|
|
|
if (par != buffer_.par_iterator_end()) {
|
2007-04-16 20:47:40 +00:00
|
|
|
|
DocIterator dit = makeDocIterator(par, min(par->size(), top_pos));
|
2007-05-10 07:53:00 +00:00
|
|
|
|
// Some slices of the iterator may not be
|
|
|
|
|
// reachable (e.g. closed collapsable inset)
|
|
|
|
|
// so the dociterator may need to be
|
|
|
|
|
// shortened. Otherwise, setCursor may crash
|
|
|
|
|
// lyx when the cursor can not be set to these
|
|
|
|
|
// insets.
|
2007-04-16 20:47:40 +00:00
|
|
|
|
size_t const n = dit.depth();
|
|
|
|
|
for (size_t i = 0; i < n; ++i)
|
2007-04-29 13:39:47 +00:00
|
|
|
|
if (dit[i].inset().editable() != Inset::HIGHLY_EDITABLE) {
|
2007-04-16 20:47:40 +00:00
|
|
|
|
dit.resize(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
setCursor(dit);
|
2007-04-16 19:01:32 +00:00
|
|
|
|
// Note: return bottom (document) level pit.
|
|
|
|
|
return boost::make_tuple(cursor_.bottom().pit(), cursor_.bottom().pos(), top_id);
|
2007-01-11 16:01:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-04-16 19:01:32 +00:00
|
|
|
|
// if top_id == 0, or searching through top_id failed
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// This is the case for a 'restored' bookmark when only bottom
|
2007-04-16 19:01:32 +00:00
|
|
|
|
// (document level) pit was saved. Because of this, bookmark
|
|
|
|
|
// restoration is inaccurate. If a bookmark was within an inset,
|
|
|
|
|
// it will be restored to the left of the outmost inset that contains
|
|
|
|
|
// the bookmark.
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (static_cast<size_t>(bottom_pit) < buffer_.paragraphs().size()) {
|
|
|
|
|
DocIterator it = doc_iterator_begin(buffer_.inset());
|
2007-05-10 07:53:00 +00:00
|
|
|
|
it.pit() = bottom_pit;
|
|
|
|
|
it.pos() = min(bottom_pos, it.paragraph().size());
|
|
|
|
|
setCursor(it);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
return boost::make_tuple(it.pit(), it.pos(),
|
2007-05-10 07:53:00 +00:00
|
|
|
|
it.paragraph().id());
|
2007-01-11 16:01:10 +00:00
|
|
|
|
}
|
|
|
|
|
// both methods fail
|
2007-04-16 19:01:32 +00:00
|
|
|
|
return boost::make_tuple(pit_type(0), pos_type(0), 0);
|
2000-06-05 15:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-06-11 22:05:44 +00:00
|
|
|
|
void BufferView::translateAndInsert(char_type c, Text * t, Cursor & cur)
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2007-06-13 06:27:33 +00:00
|
|
|
|
if (lyxrc.rtl_support) {
|
|
|
|
|
if (cursor_.innerText()->real_current_font.isRightToLeft()) {
|
|
|
|
|
if (intl_->keymap == Intl::PRIMARY)
|
|
|
|
|
intl_->keyMapSec();
|
|
|
|
|
} else {
|
|
|
|
|
if (intl_->keymap == Intl::SECONDARY)
|
|
|
|
|
intl_->keyMapPrim();
|
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2007-06-11 22:05:44 +00:00
|
|
|
|
|
|
|
|
|
intl_->getTransManager().translateAndInsert(c, t, cur);
|
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;
|
|
|
|
|
|
2007-06-10 15:07:21 +00:00
|
|
|
|
Cursor & cur = cursor_;
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_UNDO:
|
2007-08-21 07:33:46 +00:00
|
|
|
|
flag.enabled(!buffer_.undostack().empty());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_REDO:
|
2007-08-21 07:33:46 +00:00
|
|
|
|
flag.enabled(!buffer_.redostack().empty());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
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:
|
2007-04-29 23:33:02 +00:00
|
|
|
|
// FIXME: Actually, these LFUNS should be moved to Text
|
2007-06-10 15:07:21 +00:00
|
|
|
|
flag.enabled(cur.inTexted());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
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:
|
2007-06-19 21:48:04 +00:00
|
|
|
|
case LFUN_WORD_REPLACE:
|
2006-09-16 10:08:51 +00:00
|
|
|
|
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()
|
2007-06-10 15:07:21 +00:00
|
|
|
|
|| getInsetByCode<InsetRef>(cur, Inset::REF_CODE));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_CHANGES_TRACK:
|
|
|
|
|
flag.enabled(true);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
flag.setOnOff(buffer_.params().trackChanges);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-03-15 18:10:16 +00:00
|
|
|
|
case LFUN_CHANGES_OUTPUT:
|
2007-08-21 07:33:46 +00:00
|
|
|
|
flag.enabled(true);
|
|
|
|
|
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.
|
2007-08-21 07:33:46 +00:00
|
|
|
|
flag.enabled(true);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BUFFER_TOGGLE_COMPRESSION: {
|
2007-08-21 07:33:46 +00:00
|
|
|
|
flag.setOnOff(buffer_.params().compressed);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
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.
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::ACTION) << BOOST_CURRENT_FUNCTION
|
2006-09-16 10:08:51 +00:00
|
|
|
|
<< " 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-04-26 14:56:30 +00:00
|
|
|
|
Cursor & 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
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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_,
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset::REF_CODE);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
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
|
2007-03-29 03:41:55 +00:00
|
|
|
|
saveBookmark(0);
|
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;
|
2007-08-21 07:33:46 +00:00
|
|
|
|
for (Buffer * b = &buffer_; i == 0 || b != &buffer_;
|
|
|
|
|
b = theBufferList().next(b)) {
|
|
|
|
|
|
2006-11-13 16:53:49 +00:00
|
|
|
|
ParIterator par = b->getParFromID(id);
|
|
|
|
|
if (par == b->par_iterator_end()) {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::INFO)
|
2006-11-13 16:53:49 +00:00
|
|
|
|
<< "No matching paragraph found! ["
|
|
|
|
|
<< id << "]." << endl;
|
|
|
|
|
} else {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::INFO)
|
2006-11-13 16:53:49 +00:00
|
|
|
|
<< "Paragraph " << par->id()
|
|
|
|
|
<< " found in buffer `"
|
|
|
|
|
<< b->fileName() << "'." << endl;
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (b == &buffer_) {
|
2006-11-13 16:53:49 +00:00
|
|
|
|
// Set the cursor
|
|
|
|
|
setCursor(makeDocIterator(par, 0));
|
|
|
|
|
} 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);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
updateLabels(buffer_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
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);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
updateLabels(buffer_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_OUTLINE_IN:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
toc::outline(toc::In, cursor_);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
updateLabels(buffer_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_OUTLINE_OUT:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
toc::outline(toc::Out, cursor_);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
updateLabels(buffer_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_NOTE_NEXT:
|
2007-04-29 13:39:47 +00:00
|
|
|
|
bv_funcs::gotoInset(this, Inset::NOTE_CODE, false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_REFERENCE_NEXT: {
|
2007-04-29 13:39:47 +00:00
|
|
|
|
vector<Inset_code> tmp;
|
|
|
|
|
tmp.push_back(Inset::LABEL_CODE);
|
|
|
|
|
tmp.push_back(Inset::REF_CODE);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
bv_funcs::gotoInset(this, tmp, true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_CHANGES_TRACK:
|
2007-08-21 07:33:46 +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:
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.params().outputChanges = !buffer_.params().outputChanges;
|
|
|
|
|
if (buffer_.params().outputChanges) {
|
2007-05-13 15:17:57 +00:00
|
|
|
|
bool dvipost = LaTeXFeatures::isAvailable("dvipost");
|
|
|
|
|
bool xcolorsoul = LaTeXFeatures::isAvailable("soul") &&
|
2007-05-28 22:27:45 +00:00
|
|
|
|
LaTeXFeatures::isAvailable("xcolor");
|
|
|
|
|
|
2007-05-13 15:17:57 +00:00
|
|
|
|
if (!dvipost && !xcolorsoul) {
|
2007-05-08 17:46:03 +00:00
|
|
|
|
Alert::warning(_("Changes not shown in LaTeX output"),
|
2007-05-28 22:27:45 +00:00
|
|
|
|
_("Changes will not be highlighted in LaTeX output, "
|
|
|
|
|
"because neither dvipost nor xcolor/soul are installed.\n"
|
|
|
|
|
"Please install these packages or redefine "
|
|
|
|
|
"\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
|
2007-05-13 15:17:57 +00:00
|
|
|
|
} else if (!xcolorsoul) {
|
2007-05-08 17:46:03 +00:00
|
|
|
|
Alert::warning(_("Changes not shown in LaTeX output"),
|
2007-05-28 22:27:45 +00:00
|
|
|
|
_("Changes will not be highlighted in LaTeX output "
|
|
|
|
|
"when using pdflatex, because xcolor and soul are not installed.\n"
|
|
|
|
|
"Please install both packages or redefine "
|
|
|
|
|
"\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
|
2007-05-08 17:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
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;
|
|
|
|
|
|
2007-02-01 13:19:05 +00:00
|
|
|
|
case LFUN_ALL_CHANGES_ACCEPT:
|
|
|
|
|
// select complete document
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cursor_.reset(buffer_.inset());
|
2007-02-01 13:19:05 +00:00
|
|
|
|
cursor_.selHandle(true);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.text().cursorBottom(cursor_);
|
2007-02-01 13:19:05 +00:00
|
|
|
|
// accept everything in a single step to support atomic undo
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.text().acceptOrRejectChanges(cursor_, Text::ACCEPT);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-02-01 13:19:05 +00:00
|
|
|
|
case LFUN_ALL_CHANGES_REJECT:
|
|
|
|
|
// select complete document
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cursor_.reset(buffer_.inset());
|
2007-02-01 13:19:05 +00:00
|
|
|
|
cursor_.selHandle(true);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.text().cursorBottom(cursor_);
|
2007-02-01 13:19:05 +00:00
|
|
|
|
// reject everything in a single step to support atomic undo
|
|
|
|
|
// Note: reject does not work recursively; the user may have to repeat the operation
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.text().acceptOrRejectChanges(cursor_, Text::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;
|
|
|
|
|
|
2007-06-19 21:48:04 +00:00
|
|
|
|
case LFUN_WORD_REPLACE: {
|
|
|
|
|
bool has_deleted = false;
|
|
|
|
|
if (cur.selection()) {
|
|
|
|
|
DocIterator beg = cur.selectionBegin();
|
|
|
|
|
DocIterator end = cur.selectionEnd();
|
|
|
|
|
if (beg.pit() == end.pit()) {
|
|
|
|
|
for (pos_type p = beg.pos() ; p < end.pos() ; ++p) {
|
|
|
|
|
if (cur.paragraph().isDeleted(p))
|
|
|
|
|
has_deleted = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
replace(this, cmd, has_deleted);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
2007-06-19 21:48:04 +00:00
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
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: {
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor tmpcur = cursor_;
|
2007-04-29 13:39:47 +00:00
|
|
|
|
bv_funcs::findInset(tmpcur, Inset::BIBTEX_CODE, false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset::BIBTEX_CODE);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (inset) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (inset->addDatabase(to_utf8(cmd.argument())))
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.updateBibfilesCache();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_DEL: {
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor tmpcur = cursor_;
|
2007-04-29 13:39:47 +00:00
|
|
|
|
bv_funcs::findInset(tmpcur, Inset::BIBTEX_CODE, false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset::BIBTEX_CODE);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (inset) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (inset->delDatabase(to_utf8(cmd.argument())))
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.updateBibfilesCache();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_WORDS_COUNT: {
|
|
|
|
|
DocIterator from, to;
|
|
|
|
|
if (cur.selection()) {
|
|
|
|
|
from = cur.selectionBegin();
|
|
|
|
|
to = cur.selectionEnd();
|
|
|
|
|
} else {
|
2007-08-21 07:33:46 +00:00
|
|
|
|
from = doc_iterator_begin(buffer_.inset());
|
|
|
|
|
to = doc_iterator_end(buffer_.inset());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
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
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.params().compressed = !buffer_.params().compressed;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
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.
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * inset = cur.nextInset();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (inset && inset->isActive()) {
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor tmpcur = cur;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
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
|
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor & cur = cursor_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cursor_.clearSelection();
|
|
|
|
|
// Clear the selection buffer. Otherwise a subsequent
|
|
|
|
|
// middle-mouse-button paste would use the selection buffer,
|
|
|
|
|
// not the more current external selection.
|
|
|
|
|
cap::clearSelection();
|
|
|
|
|
xsel_cache_.set = false;
|
|
|
|
|
// The buffer did not really change, but this causes the
|
|
|
|
|
// redraw we need because we cleared the selection above.
|
|
|
|
|
buffer_.changed();
|
* 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();
|
2007-08-21 07:33:46 +00:00
|
|
|
|
updateMetrics(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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 23:33:02 +00:00
|
|
|
|
Inset const * BufferView::getCoveringInset(Text const & text, int x, int y)
|
2007-03-28 14:47:52 +00:00
|
|
|
|
{
|
|
|
|
|
pit_type pit = text.getPitNearY(*this, y);
|
|
|
|
|
BOOST_ASSERT(pit != -1);
|
|
|
|
|
Paragraph const & par = text.getPar(pit);
|
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::DEBUG)
|
2007-03-28 14:47:52 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": x: " << x
|
|
|
|
|
<< " y: " << y
|
|
|
|
|
<< " pit: " << pit
|
|
|
|
|
<< endl;
|
|
|
|
|
InsetList::const_iterator iit = par.insetlist.begin();
|
|
|
|
|
InsetList::const_iterator iend = par.insetlist.end();
|
|
|
|
|
for (; iit != iend; ++iit) {
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * const inset = iit->inset;
|
2007-03-28 14:47:52 +00:00
|
|
|
|
if (inset->covers(*this, x, y)) {
|
|
|
|
|
if (!inset->descendable())
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// No need to go further down if the inset is not
|
2007-03-28 14:47:52 +00:00
|
|
|
|
// descendable.
|
|
|
|
|
return inset;
|
|
|
|
|
|
|
|
|
|
size_t cell_number = inset->nargs();
|
|
|
|
|
// Check all the inner cell.
|
|
|
|
|
for (size_t i = 0; i != cell_number; ++i) {
|
2007-04-29 23:33:02 +00:00
|
|
|
|
Text const * inner_text = inset->getText(i);
|
2007-03-28 14:47:52 +00:00
|
|
|
|
if (inner_text) {
|
|
|
|
|
// Try deeper.
|
2007-05-28 22:27:45 +00:00
|
|
|
|
Inset const * inset_deeper =
|
2007-03-28 14:47:52 +00:00
|
|
|
|
getCoveringInset(*inner_text, x, y);
|
|
|
|
|
if (inset_deeper)
|
|
|
|
|
return inset_deeper;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::DEBUG)
|
2007-03-28 14:47:52 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": Hit inset: " << inset << endl;
|
|
|
|
|
return inset;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::DEBUG)
|
2007-03-28 14:47:52 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": No inset hit. " << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor cur(*this);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cur.push(buffer_.inset());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cur.selection() = cursor_.selection();
|
|
|
|
|
|
|
|
|
|
// Either the inset under the cursor or the
|
2007-04-29 23:33:02 +00:00
|
|
|
|
// surrounding Text will handle this event.
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-03-27 10:07:53 +00:00
|
|
|
|
// make sure we stay within the screen...
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cmd.y = min(max(cmd.y, -1), height_);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2006-12-04 04:31:18 +00:00
|
|
|
|
if (cmd.action == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::none) {
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-03-28 14:47:52 +00:00
|
|
|
|
// Get inset under mouse, if there is one.
|
2007-05-28 22:27:45 +00:00
|
|
|
|
Inset const * covering_inset =
|
2007-08-21 07:33:46 +00:00
|
|
|
|
getCoveringInset(buffer_.text(), cmd.x, cmd.y);
|
2007-03-28 14:47:52 +00:00
|
|
|
|
if (covering_inset == last_inset_)
|
|
|
|
|
// Same inset, no need to do anything...
|
|
|
|
|
return false;
|
2007-03-27 10:07:53 +00:00
|
|
|
|
|
2006-12-07 11:46:27 +00:00
|
|
|
|
bool need_redraw = false;
|
2007-03-28 14:47:52 +00:00
|
|
|
|
// const_cast because of setMouseHover().
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * inset = const_cast<Inset *>(covering_inset);
|
2007-03-28 14:47:52 +00:00
|
|
|
|
if (last_inset_)
|
|
|
|
|
// Remove the hint on the last hovered inset (if any).
|
|
|
|
|
need_redraw |= last_inset_->setMouseHover(false);
|
|
|
|
|
if (inset)
|
|
|
|
|
// Highlighted the newly hovered inset (if any).
|
|
|
|
|
need_redraw |= inset->setMouseHover(true);
|
|
|
|
|
last_inset_ = inset;
|
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-05-28 22:27:45 +00:00
|
|
|
|
if (need_redraw
|
2007-01-20 01:23:07 +00:00
|
|
|
|
&& metrics_info_.update_strategy == SingleParUpdate) {
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// FIXME: It should be possible to redraw only the area around
|
2006-12-07 11:46:27 +00:00
|
|
|
|
// the button by doing this:
|
|
|
|
|
//
|
|
|
|
|
//metrics_info_.singlepar = false;
|
|
|
|
|
//metrics_info_.y1 = ymin of button;
|
|
|
|
|
//metrics_info_.y2 = ymax of button;
|
|
|
|
|
//
|
2007-04-26 04:41:58 +00:00
|
|
|
|
// Unfortunately, rowpainter.cpp:paintText() does not distinguish
|
2006-12-07 11:46:27 +00:00
|
|
|
|
// 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
|
2007-04-29 23:33:02 +00:00
|
|
|
|
// at Text::getPitNearY() to see what I mean.
|
2006-12-07 11:46:27 +00:00
|
|
|
|
//
|
|
|
|
|
//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
|
|
|
|
}
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-03-27 10:07:53 +00:00
|
|
|
|
// Build temporary cursor.
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Inset * inset = buffer_.text().editXY(cur, cmd.x, cmd.y);
|
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);
|
|
|
|
|
|
2007-08-10 10:21:09 +00:00
|
|
|
|
//Do we have a selection?
|
|
|
|
|
theSelection().haveSelection(cursor().selection());
|
|
|
|
|
|
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
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
// Text const * t = buffer_.text();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// 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;
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.texrow().getIdFromRow(row, tmpid, tmppos);
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cursor_.reset(buffer_.inset());
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (tmpid == -1)
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.text().setCursor(cursor_, 0, 0);
|
2003-10-09 10:52:12 +00:00
|
|
|
|
else
|
2007-08-21 07:33:46 +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
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
for (InsetIterator it = inset_iterator_begin(buffer_.inset()); it; ++it) {
|
2006-10-12 10:50:45 +00:00
|
|
|
|
vector<docstring> labels;
|
2007-08-21 07:33:46 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 23:33:02 +00:00
|
|
|
|
TextMetrics const & BufferView::textMetrics(Text const * t) const
|
2006-12-29 23:54:48 +00:00
|
|
|
|
{
|
|
|
|
|
return const_cast<BufferView *>(this)->textMetrics(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 23:33:02 +00:00
|
|
|
|
TextMetrics & BufferView::textMetrics(Text const * t)
|
2006-12-29 23:54:48 +00:00
|
|
|
|
{
|
|
|
|
|
TextMetricsCache::iterator tmc_it = text_metrics_.find(t);
|
|
|
|
|
if (tmc_it == text_metrics_.end()) {
|
|
|
|
|
tmc_it = text_metrics_.insert(
|
2007-04-29 23:33:02 +00:00
|
|
|
|
make_pair(t, TextMetrics(this, const_cast<Text *>(t)))).first;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
}
|
2006-12-29 23:54:48 +00:00
|
|
|
|
return tmc_it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 23:33:02 +00:00
|
|
|
|
ParagraphMetrics const & BufferView::parMetrics(Text const * t,
|
2006-12-29 23:54:48 +00:00
|
|
|
|
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
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool BufferView::checkDepm(Cursor & cur, Cursor & old)
|
2006-12-30 15:05:15 +00:00
|
|
|
|
{
|
|
|
|
|
// 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();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2006-12-30 15:05:15 +00:00
|
|
|
|
if (!changed)
|
|
|
|
|
return false;
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
updateLabels(buffer_);
|
2007-01-31 14:07:37 +00:00
|
|
|
|
|
2006-12-30 15:05:15 +00:00
|
|
|
|
updateMetrics(false);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.changed();
|
2006-12-30 15:05:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool BufferView::mouseSetCursor(Cursor & cur)
|
2005-12-01 10:28:50 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(&cur.bv() == this);
|
|
|
|
|
|
2007-07-10 12:44:19 +00:00
|
|
|
|
// this event will clear selection so we save selection for
|
|
|
|
|
// persistent selection
|
|
|
|
|
cap::saveSelection(cursor());
|
|
|
|
|
|
2005-12-01 10:28:50 +00:00
|
|
|
|
// Has the cursor just left the inset?
|
2006-08-17 21:32:04 +00:00
|
|
|
|
bool badcursor = false;
|
2007-04-10 16:50:19 +00:00
|
|
|
|
bool leftinset = (&cursor_.inset() != &cur.inset());
|
|
|
|
|
if (leftinset)
|
2007-06-21 21:56:43 +00:00
|
|
|
|
badcursor = notifyCursorLeaves(cursor_, cur);
|
2005-12-01 10:28:50 +00:00
|
|
|
|
|
|
|
|
|
// do the dEPM magic if needed
|
2007-04-10 16:50:19 +00:00
|
|
|
|
// FIXME: (1) move this to InsetText::notifyCursorLeaves?
|
|
|
|
|
// FIXME: (2) if we had a working InsetText::notifyCursorLeaves,
|
|
|
|
|
// the leftinset bool would not be necessary (badcursor instead).
|
|
|
|
|
bool update = leftinset;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (!badcursor && cursor_.inTexted())
|
2007-04-10 16:50:19 +00:00
|
|
|
|
update |= 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.
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// For an example, see bug 2933:
|
|
|
|
|
// http://bugzilla.lyx.org/show_bug.cgi?id=2933
|
2007-01-17 15:32:43 +00:00
|
|
|
|
// 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);
|
2007-05-28 17:04:05 +00:00
|
|
|
|
cursor_.boundary(cur.boundary());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cursor_.clearSelection();
|
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);
|
2004-01-14 17:21:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-15 11:58:35 +00:00
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor & BufferView::cursor()
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return cursor_;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor 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
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Text & 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-05-28 22:27:45 +00:00
|
|
|
|
|
2007-06-21 06:41:55 +00:00
|
|
|
|
if (!singlepar) {
|
|
|
|
|
// Clear out the position cache in case of full screen redraw,
|
|
|
|
|
coord_cache_.clear();
|
|
|
|
|
|
|
|
|
|
// Clear out paragraph metrics to avoid having invalid metrics
|
|
|
|
|
// in the cache from paragraphs not relayouted below
|
|
|
|
|
tm.clear();
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2006-12-29 23:54:48 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::DEBUG)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " y1: " << y1
|
|
|
|
|
<< " y2: " << y2
|
|
|
|
|
<< " pit1: " << pit1
|
|
|
|
|
<< " pit2: " << pit2
|
|
|
|
|
<< " npit: " << npit
|
|
|
|
|
<< " singlepar: " << singlepar
|
|
|
|
|
<< "size: " << size
|
|
|
|
|
<< endl;
|
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
|
metrics_info_ = ViewMetricsInfo(pit1, pit2, y1, y2,
|
2007-01-20 01:23:07 +00:00
|
|
|
|
singlepar? SingleParUpdate: FullScreenUpdate, size);
|
2006-10-20 20:57:21 +00:00
|
|
|
|
|
|
|
|
|
if (lyxerr.debugging(Debug::WORKAREA)) {
|
2007-04-01 10:09:49 +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;
|
2007-08-21 07:33:46 +00:00
|
|
|
|
string const trypath = buffer_.filePath();
|
|
|
|
|
// If directory is writeable, use this as default.
|
|
|
|
|
if (isDirWriteable(FileName(trypath)))
|
|
|
|
|
initpath = trypath;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
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)),
|
2007-06-10 15:07:21 +00:00
|
|
|
|
make_pair(_("Examples|#E#e"),
|
|
|
|
|
from_utf8(addPath(package().system_support().absFilename(),
|
|
|
|
|
"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))) {
|
2007-08-21 07:33:46 +00:00
|
|
|
|
ErrorList & el = buffer_.errorList("Parse");
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// 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));
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.errors("Parse");
|
|
|
|
|
updateMetrics(false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|