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
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author John Levon
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
|
|
|
* \author Jürgen Vigna
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2008-05-28 16:02:09 +00:00
|
|
|
#include "BranchList.h"
|
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"
|
|
|
|
#include "CoordCache.h"
|
2007-10-11 09:59:01 +00:00
|
|
|
#include "Cursor.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
#include "CutAndPaste.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"
|
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"
|
2009-09-19 20:56:12 +00:00
|
|
|
#include "LayoutFile.h"
|
2009-09-19 17:56:53 +00:00
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyX.h"
|
2009-09-21 12:36:22 +00:00
|
|
|
#include "LyXAction.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
#include "lyxfind.h"
|
2007-04-29 18:58:28 +00:00
|
|
|
#include "Layout.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
2007-08-27 22:53:16 +00:00
|
|
|
#include "MetricsInfo.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Paragraph.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "ParIterator.h"
|
2007-08-27 22:53:16 +00:00
|
|
|
#include "Session.h"
|
|
|
|
#include "Text.h"
|
|
|
|
#include "TextClass.h"
|
2007-10-11 09:59:01 +00:00
|
|
|
#include "TextMetrics.h"
|
|
|
|
#include "TexRow.h"
|
2008-03-07 19:46:04 +00:00
|
|
|
#include "TocBackend.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "VSpace.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
#include "WordLangTuple.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
|
2008-03-24 04:27:43 +00:00
|
|
|
#include "insets/InsetExternal.h"
|
|
|
|
#include "insets/InsetGraphics.h"
|
2010-10-18 14:20:03 +00:00
|
|
|
#include "insets/InsetNote.h"
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetRef.h"
|
|
|
|
#include "insets/InsetText.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2014-03-22 11:09:18 +00:00
|
|
|
#include "mathed/MathData.h"
|
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
#include "frontends/alert.h"
|
2007-12-25 22:27:32 +00:00
|
|
|
#include "frontends/Application.h"
|
2007-10-02 18:27:20 +00:00
|
|
|
#include "frontends/Delegates.h"
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
2007-08-27 22:53:16 +00:00
|
|
|
#include "frontends/Painter.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"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2008-01-03 16:41:06 +00:00
|
|
|
#include "support/ExceptionMessage.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
#include "support/filetools.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/gettext.h"
|
|
|
|
#include "support/lstrings.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
|
|
|
|
2007-10-03 20:15:49 +00:00
|
|
|
#include <cerrno>
|
|
|
|
#include <fstream>
|
2006-09-16 10:08:51 +00:00
|
|
|
#include <functional>
|
2007-11-06 22:20:05 +00:00
|
|
|
#include <iterator>
|
2009-09-20 19:37:26 +00:00
|
|
|
#include <sstream>
|
2006-09-16 10:08:51 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-07-17 17:40:44 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
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-10-13 09:04:52 +00:00
|
|
|
T * getInsetByCode(Cursor const & cur, InsetCode code)
|
2006-09-16 10:08:51 +00:00
|
|
|
{
|
|
|
|
DocIterator it = cur;
|
2007-09-29 07:34:42 +00:00
|
|
|
Inset * inset = it.nextInset();
|
|
|
|
if (inset && inset->lyxCode() == code)
|
|
|
|
return static_cast<T*>(inset);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-27 00:42:43 +00:00
|
|
|
/// Note that comparing contents can only be used for InsetCommand
|
2007-10-13 09:04:52 +00:00
|
|
|
bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
|
2007-10-23 18:51:04 +00:00
|
|
|
docstring const & contents)
|
2007-09-29 07:34:42 +00:00
|
|
|
{
|
|
|
|
DocIterator tmpdit = dit;
|
|
|
|
|
|
|
|
while (tmpdit) {
|
|
|
|
Inset const * inset = tmpdit.nextInset();
|
2010-10-27 00:42:43 +00:00
|
|
|
if (inset) {
|
|
|
|
bool const valid_code = std::find(codes.begin(), codes.end(),
|
|
|
|
inset->lyxCode()) != codes.end();
|
|
|
|
InsetCommand const * ic = inset->asInsetCommand();
|
|
|
|
bool const same_or_no_contents = contents.empty()
|
|
|
|
|| (ic && (ic->getFirstNonOptParam() == contents));
|
|
|
|
|
|
|
|
if (valid_code && same_or_no_contents) {
|
|
|
|
dit = tmpdit;
|
|
|
|
return true;
|
|
|
|
}
|
2007-09-29 07:34:42 +00:00
|
|
|
}
|
|
|
|
tmpdit.forwardInset();
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
2007-09-29 07:34:42 +00:00
|
|
|
|
|
|
|
return false;
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-29 07:34:42 +00:00
|
|
|
|
2007-10-23 18:51:04 +00:00
|
|
|
/// Looks for next inset with one of the given codes.
|
2010-10-27 00:42:43 +00:00
|
|
|
/// Note that same_content can only be used for InsetCommand
|
2007-10-13 09:04:52 +00:00
|
|
|
bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
|
2007-09-29 07:34:42 +00:00
|
|
|
bool same_content)
|
|
|
|
{
|
2007-10-23 18:51:04 +00:00
|
|
|
docstring contents;
|
2007-09-29 07:34:42 +00:00
|
|
|
DocIterator tmpdit = dit;
|
|
|
|
tmpdit.forwardInset();
|
|
|
|
if (!tmpdit)
|
|
|
|
return false;
|
|
|
|
|
2010-10-27 00:42:43 +00:00
|
|
|
Inset const * inset = tmpdit.nextInset();
|
|
|
|
if (same_content && inset) {
|
|
|
|
InsetCommand const * ic = inset->asInsetCommand();
|
|
|
|
if (ic) {
|
|
|
|
bool const valid_code = std::find(codes.begin(), codes.end(),
|
|
|
|
ic->lyxCode()) != codes.end();
|
|
|
|
if (valid_code)
|
|
|
|
contents = ic->getFirstNonOptParam();
|
2007-09-29 07:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!findNextInset(tmpdit, codes, contents)) {
|
|
|
|
if (dit.depth() != 1 || dit.pit() != 0 || dit.pos() != 0) {
|
2008-11-17 11:46:07 +00:00
|
|
|
Inset * inset = &tmpdit.bottom().inset();
|
|
|
|
tmpdit = doc_iterator_begin(&inset->buffer(), inset);
|
2007-09-29 07:34:42 +00:00
|
|
|
if (!findNextInset(tmpdit, codes, contents))
|
|
|
|
return false;
|
2008-11-17 11:46:07 +00:00
|
|
|
} else {
|
2007-09-29 07:34:42 +00:00
|
|
|
return false;
|
2008-11-17 11:46:07 +00:00
|
|
|
}
|
2007-09-29 07:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dit = tmpdit;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Looks for next inset with the given code
|
2007-10-13 09:04:52 +00:00
|
|
|
void findInset(DocIterator & dit, InsetCode code, bool same_content)
|
2007-09-29 07:34:42 +00:00
|
|
|
{
|
2007-10-13 09:04:52 +00:00
|
|
|
findInset(dit, vector<InsetCode>(1, code), same_content);
|
2007-09-29 07:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Moves cursor to the next inset with one of the given codes.
|
2007-10-13 09:04:52 +00:00
|
|
|
void gotoInset(BufferView * bv, vector<InsetCode> const & codes,
|
2007-09-29 07:34:42 +00:00
|
|
|
bool same_content)
|
|
|
|
{
|
|
|
|
Cursor tmpcur = bv->cursor();
|
|
|
|
if (!findInset(tmpcur, codes, same_content)) {
|
|
|
|
bv->cursor().message(_("No more insets"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpcur.clearSelection();
|
|
|
|
bv->setCursor(tmpcur);
|
2007-12-22 10:19:26 +00:00
|
|
|
bv->showCursor();
|
2007-09-29 07:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Moves cursor to the next inset with given code.
|
2007-10-13 09:04:52 +00:00
|
|
|
void gotoInset(BufferView * bv, InsetCode code, bool same_content)
|
2007-09-29 07:34:42 +00:00
|
|
|
{
|
2007-10-13 09:04:52 +00:00
|
|
|
gotoInset(bv, vector<InsetCode>(1, code), same_content);
|
2007-09-29 07:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 09:59:01 +00:00
|
|
|
/// A map from a Text to the associated text metrics
|
2007-12-12 19:28:07 +00:00
|
|
|
typedef map<Text const *, TextMetrics> TextMetricsCache;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
enum ScreenUpdateStrategy {
|
|
|
|
NoScreenUpdate,
|
|
|
|
SingleParUpdate,
|
|
|
|
FullScreenUpdate,
|
|
|
|
DecorationUpdate
|
|
|
|
};
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
2007-09-29 20:25:50 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// BufferView
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
struct BufferView::Private
|
2007-10-11 09:59:01 +00:00
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
Private(BufferView & bv): wh_(0), cursor_(bv),
|
2007-12-21 08:28:18 +00:00
|
|
|
anchor_pit_(0), anchor_ypos_(0),
|
2008-04-16 21:23:45 +00:00
|
|
|
inlineCompletionUniqueChars_(0),
|
2010-10-24 21:41:47 +00:00
|
|
|
last_inset_(0), clickable_inset_(false),
|
|
|
|
mouse_position_cache_(),
|
2010-06-15 13:54:49 +00:00
|
|
|
bookmark_edit_position_(-1), gui_(0)
|
2007-10-11 09:59:01 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
///
|
|
|
|
ScrollbarParameters scrollbarParameters_;
|
|
|
|
///
|
2007-11-17 11:27:03 +00:00
|
|
|
ScreenUpdateStrategy update_strategy_;
|
2007-10-11 09:59:01 +00:00
|
|
|
///
|
|
|
|
CoordCache coord_cache_;
|
|
|
|
|
|
|
|
/// Estimated average par height for scrollbar.
|
|
|
|
int wh_;
|
|
|
|
/// this is used to handle XSelection events in the right manner.
|
|
|
|
struct {
|
|
|
|
CursorSlice cursor;
|
|
|
|
CursorSlice anchor;
|
|
|
|
bool set;
|
|
|
|
} xsel_cache_;
|
|
|
|
///
|
|
|
|
Cursor cursor_;
|
|
|
|
///
|
2007-12-21 08:28:18 +00:00
|
|
|
pit_type anchor_pit_;
|
2007-10-11 09:59:01 +00:00
|
|
|
///
|
2007-12-21 08:28:18 +00:00
|
|
|
int anchor_ypos_;
|
2007-10-11 09:59:01 +00:00
|
|
|
///
|
2007-12-21 08:28:18 +00:00
|
|
|
vector<int> par_height_;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
///
|
2008-04-16 20:43:30 +00:00
|
|
|
DocIterator inlineCompletionPos_;
|
2008-02-21 19:42:34 +00:00
|
|
|
///
|
2008-04-16 20:43:30 +00:00
|
|
|
docstring inlineCompletion_;
|
2008-02-21 19:42:34 +00:00
|
|
|
///
|
2008-04-16 20:43:30 +00:00
|
|
|
size_t inlineCompletionUniqueChars_;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
2007-10-11 09:59:01 +00:00
|
|
|
/// keyboard mapping object.
|
|
|
|
Intl intl_;
|
|
|
|
|
|
|
|
/// last visited inset.
|
|
|
|
/** kept to send setMouseHover(false).
|
|
|
|
* Not owned, so don't delete.
|
|
|
|
*/
|
2011-02-13 10:07:00 +00:00
|
|
|
Inset const * last_inset_;
|
2010-10-24 21:41:47 +00:00
|
|
|
/// are we hovering something that we can click
|
|
|
|
bool clickable_inset_;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
2010-03-29 15:21:10 +00:00
|
|
|
/// position of the mouse at the time of the last mouse move
|
|
|
|
/// This is used to update the hovering status of inset in
|
|
|
|
/// cases where the buffer is scrolled, but the mouse didn't move.
|
|
|
|
Point mouse_position_cache_;
|
|
|
|
|
2009-02-13 13:46:08 +00:00
|
|
|
// cache for id of the paragraph which was edited the last time
|
|
|
|
int bookmark_edit_position_;
|
|
|
|
|
2007-10-11 09:59:01 +00:00
|
|
|
mutable TextMetricsCache text_metrics_;
|
|
|
|
|
|
|
|
/// Whom to notify.
|
|
|
|
/** Not owned, so don't delete.
|
|
|
|
*/
|
|
|
|
frontend::GuiBufferViewDelegate * gui_;
|
2008-03-26 19:20:17 +00:00
|
|
|
|
|
|
|
/// Cache for Find Next
|
|
|
|
FuncRequest search_request_cache_;
|
2009-09-27 10:29:13 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
map<string, Inset *> edited_insets_;
|
2007-10-11 09:59:01 +00:00
|
|
|
};
|
|
|
|
|
2007-09-29 20:25:50 +00:00
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
BufferView::BufferView(Buffer & buf)
|
2008-11-17 11:46:07 +00:00
|
|
|
: width_(0), height_(0), full_screen_(false), buffer_(buf),
|
|
|
|
d(new Private(*this))
|
2006-09-16 10:08:51 +00:00
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
d->xsel_cache_.set = false;
|
|
|
|
d->intl_.initKeyMapper(lyxrc.use_kbmap);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2008-11-17 11:46:07 +00:00
|
|
|
d->cursor_.setBuffer(&buf);
|
2007-10-13 07:33:07 +00:00
|
|
|
d->cursor_.push(buffer_.inset());
|
|
|
|
d->cursor_.resetAnchor();
|
|
|
|
d->cursor_.setCurrentFont();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2010-10-29 20:00:51 +00:00
|
|
|
buffer_.updatePreviews();
|
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.
|
2007-11-02 19:59:08 +00:00
|
|
|
LastFilePosSection::FilePos fp;
|
|
|
|
fp.pit = d->cursor_.bottom().pit();
|
|
|
|
fp.pos = d->cursor_.bottom().pos();
|
2008-07-14 08:35:00 +00:00
|
|
|
theSession().lastFilePos().save(buffer_.fileName(), fp);
|
2010-05-03 23:04:51 +00:00
|
|
|
|
|
|
|
if (d->last_inset_)
|
|
|
|
d->last_inset_->setMouseHover(this, false);
|
2007-10-11 09:59:01 +00:00
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
delete d;
|
2007-10-11 09:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-09 17:20:23 +00:00
|
|
|
int BufferView::rightMargin() const
|
|
|
|
{
|
2008-02-19 21:51:55 +00:00
|
|
|
// The additional test for the case the outliner is opened.
|
|
|
|
if (!full_screen_ ||
|
|
|
|
!lyxrc.full_screen_limit ||
|
|
|
|
width_ < lyxrc.full_screen_width + 20)
|
|
|
|
return 10;
|
2008-02-10 10:01:16 +00:00
|
|
|
|
2008-02-19 21:51:55 +00:00
|
|
|
return (width_ - lyxrc.full_screen_width) / 2;
|
2008-02-09 17:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int BufferView::leftMargin() const
|
|
|
|
{
|
2008-02-10 10:01:16 +00:00
|
|
|
return rightMargin();
|
2008-02-09 17:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-06 12:41:38 +00:00
|
|
|
bool BufferView::isTopScreen() const
|
|
|
|
{
|
|
|
|
return d->scrollbarParameters_.position == d->scrollbarParameters_.min;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BufferView::isBottomScreen() const
|
|
|
|
{
|
|
|
|
return d->scrollbarParameters_.position == d->scrollbarParameters_.max;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 09:59:01 +00:00
|
|
|
Intl & BufferView::getIntl()
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
return d->intl_;
|
2007-10-11 09:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Intl const & BufferView::getIntl() const
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
return d->intl_;
|
2007-10-11 09:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CoordCache & BufferView::coordCache()
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
return d->coord_cache_;
|
2007-10-11 09:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CoordCache const & BufferView::coordCache() const
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
return d->coord_cache_;
|
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
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
if (cursorStatus(d->cursor_) == CUR_INSIDE) {
|
2006-10-21 00:16:43 +00:00
|
|
|
frontend::FontMetrics const & fm =
|
2007-10-28 18:51:54 +00:00
|
|
|
theFontMetrics(d->cursor_.getFont().fontInfo());
|
2006-10-07 16:15:06 +00:00
|
|
|
int const asc = fm.maxAscent();
|
|
|
|
int const des = fm.maxDescent();
|
2010-04-21 13:03:04 +00:00
|
|
|
Point const p = getPos(d->cursor_);
|
2006-09-16 10:08:51 +00:00
|
|
|
if (p.y_ - asc >= 0 && p.y_ + des < height_)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-10 08:52:55 +00:00
|
|
|
void BufferView::processUpdateFlags(Update::flags flags)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
// This is close to a hot-path.
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::DEBUG, "BufferView::processUpdateFlags()"
|
2007-04-01 15:09:08 +00:00
|
|
|
<< "[fitcursor = " << (flags & Update::FitCursor)
|
|
|
|
<< ", forceupdate = " << (flags & Update::Force)
|
|
|
|
<< ", singlepar = " << (flags & Update::SinglePar)
|
2007-11-15 20:04:51 +00:00
|
|
|
<< "] buffer: " << &buffer_);
|
2006-10-21 10:56:36 +00:00
|
|
|
|
2010-07-09 14:37:00 +00:00
|
|
|
// FIXME Does this really need doing here? It's done in updateBuffer, and
|
|
|
|
// if the Buffer doesn't need updating, then do the macros?
|
2007-12-21 20:42:46 +00:00
|
|
|
buffer_.updateMacros();
|
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-11-17 11:27:03 +00:00
|
|
|
d->update_strategy_ = NoScreenUpdate;
|
2007-10-10 08:52:55 +00:00
|
|
|
return;
|
2006-11-17 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-20 01:23:07 +00:00
|
|
|
if (flags == Update::Decoration) {
|
2007-11-17 11:27:03 +00:00
|
|
|
d->update_strategy_ = DecorationUpdate;
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(false);
|
2007-10-10 08:52:55 +00:00
|
|
|
return;
|
2007-01-20 01:23:07 +00:00
|
|
|
}
|
|
|
|
|
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-12-07 11:46:27 +00:00
|
|
|
// tell the frontend to update the screen if needed.
|
2007-12-21 08:28:18 +00:00
|
|
|
if (fitCursor()) {
|
2007-12-21 08:35:43 +00:00
|
|
|
showCursor();
|
2007-10-10 08:52:55 +00:00
|
|
|
return;
|
2007-01-20 01:23:07 +00:00
|
|
|
}
|
|
|
|
if (flags & Update::Decoration) {
|
2007-11-17 11:27:03 +00:00
|
|
|
d->update_strategy_ = DecorationUpdate;
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(false);
|
2007-10-10 08:52:55 +00:00
|
|
|
return;
|
2007-01-20 01:23:07 +00:00
|
|
|
}
|
|
|
|
// no screen update is needed.
|
2007-11-17 11:27:03 +00:00
|
|
|
d->update_strategy_ = NoScreenUpdate;
|
2007-10-10 08:52:55 +00:00
|
|
|
return;
|
2006-11-21 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
2007-12-21 09:45:04 +00:00
|
|
|
bool const full_metrics = flags & Update::Force || !singleParUpdate();
|
2006-11-20 14:42:18 +00:00
|
|
|
|
2007-12-21 09:45:04 +00:00
|
|
|
if (full_metrics)
|
2007-11-06 08:32:25 +00:00
|
|
|
// We have to update the full screen metrics.
|
|
|
|
updateMetrics();
|
2006-11-17 17:42:52 +00:00
|
|
|
|
2007-10-10 08:52:55 +00:00
|
|
|
if (!(flags & Update::FitCursor)) {
|
2007-12-21 09:45:04 +00:00
|
|
|
// Nothing to do anymore. Trigger a redraw and return
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(false);
|
2007-10-10 08:52:55 +00:00
|
|
|
return;
|
2007-09-26 21:27:17 +00:00
|
|
|
}
|
2006-11-17 17:42:52 +00:00
|
|
|
|
2007-12-21 09:45:04 +00:00
|
|
|
// updateMetrics() does not update paragraph position
|
2007-10-10 08:52:55 +00:00
|
|
|
// This is done at draw() time. So we need a redraw!
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(false);
|
2007-10-10 08:52:55 +00:00
|
|
|
|
2007-12-21 09:45:04 +00:00
|
|
|
if (fitCursor()) {
|
|
|
|
// The cursor is off screen so ensure it is visible.
|
|
|
|
// refresh it:
|
|
|
|
showCursor();
|
|
|
|
}
|
2010-03-29 15:21:10 +00:00
|
|
|
|
|
|
|
updateHoveredInset();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::updateScrollbar()
|
|
|
|
{
|
2008-06-19 13:10:25 +00:00
|
|
|
if (height_ == 0 && width_ == 0)
|
2007-12-21 08:28:18 +00:00
|
|
|
return;
|
2006-12-29 23:54:48 +00:00
|
|
|
|
2008-01-17 17:06:55 +00:00
|
|
|
// We prefer fixed size line scrolling.
|
|
|
|
d->scrollbarParameters_.single_step = defaultRowHeight();
|
|
|
|
// We prefer full screen page scrolling.
|
|
|
|
d->scrollbarParameters_.page_step = height_;
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
Text & t = buffer_.text();
|
|
|
|
TextMetrics & tm = d->text_metrics_[&t];
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR(Debug::GUI, " Updating scrollbar: height: "
|
|
|
|
<< t.paragraphs().size()
|
2007-10-13 07:33:07 +00:00
|
|
|
<< " curr par: " << d->cursor_.bottom().pit()
|
2007-11-15 20:04:51 +00:00
|
|
|
<< " default height " << defaultRowHeight());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2008-02-09 15:23:05 +00:00
|
|
|
size_t const parsize = t.paragraphs().size();
|
2007-12-21 08:28:18 +00:00
|
|
|
if (d->par_height_.size() != parsize) {
|
|
|
|
d->par_height_.clear();
|
2007-12-21 13:38:09 +00:00
|
|
|
// FIXME: We assume a default paragraph height of 2 rows. This
|
2007-12-21 08:28:18 +00:00
|
|
|
// should probably be pondered with the screen width.
|
2007-12-21 13:38:09 +00:00
|
|
|
d->par_height_.resize(parsize, defaultRowHeight() * 2);
|
2007-12-21 08:28:18 +00:00
|
|
|
}
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
// Look at paragraph heights on-screen
|
2007-12-21 08:28:18 +00:00
|
|
|
pair<pit_type, ParagraphMetrics const *> first = tm.first();
|
|
|
|
pair<pit_type, ParagraphMetrics const *> last = tm.last();
|
|
|
|
for (pit_type pit = first.first; pit <= last.first; ++pit) {
|
2008-01-16 09:06:36 +00:00
|
|
|
d->par_height_[pit] = tm.parMetrics(pit).height();
|
|
|
|
LYXERR(Debug::SCROLLING, "storing height for pit " << pit << " : "
|
|
|
|
<< d->par_height_[pit]);
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
2006-10-26 08:10:22 +00:00
|
|
|
|
2008-01-17 17:06:55 +00:00
|
|
|
int top_pos = first.second->position() - first.second->ascent();
|
|
|
|
int bottom_pos = last.second->position() + last.second->descent();
|
|
|
|
bool first_visible = first.first == 0 && top_pos >= 0;
|
2008-02-09 15:23:05 +00:00
|
|
|
bool last_visible = last.first + 1 == int(parsize) && bottom_pos <= height_;
|
2008-01-17 17:06:55 +00:00
|
|
|
if (first_visible && last_visible) {
|
|
|
|
d->scrollbarParameters_.min = 0;
|
|
|
|
d->scrollbarParameters_.max = 0;
|
|
|
|
return;
|
2007-12-21 08:28:18 +00:00
|
|
|
}
|
|
|
|
|
2008-01-17 17:06:55 +00:00
|
|
|
d->scrollbarParameters_.min = top_pos;
|
2008-02-09 15:23:05 +00:00
|
|
|
for (size_t i = 0; i != size_t(first.first); ++i)
|
2008-01-17 17:06:55 +00:00
|
|
|
d->scrollbarParameters_.min -= d->par_height_[i];
|
|
|
|
d->scrollbarParameters_.max = bottom_pos;
|
|
|
|
for (size_t i = last.first + 1; i != parsize; ++i)
|
|
|
|
d->scrollbarParameters_.max += d->par_height_[i];
|
|
|
|
|
|
|
|
d->scrollbarParameters_.position = 0;
|
|
|
|
// The reference is the top position so we remove one page.
|
2009-03-27 17:41:58 +00:00
|
|
|
if (lyxrc.scroll_below_document)
|
|
|
|
d->scrollbarParameters_.max -= minVisiblePart();
|
|
|
|
else
|
|
|
|
d->scrollbarParameters_.max -= d->scrollbarParameters_.page_step;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
ScrollbarParameters const & BufferView::scrollbarParameters() const
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
return d->scrollbarParameters_;
|
2006-06-26 16:55:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-25 18:53:38 +00:00
|
|
|
docstring BufferView::toolTip(int x, int y) const
|
|
|
|
{
|
|
|
|
// Get inset under mouse, if there is one.
|
|
|
|
Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
|
|
|
|
if (!covering_inset)
|
|
|
|
// No inset, no tooltip...
|
|
|
|
return docstring();
|
|
|
|
return covering_inset->toolTip(*this, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-26 12:40:58 +00:00
|
|
|
docstring BufferView::contextMenu(int x, int y) const
|
2007-12-25 20:12:07 +00:00
|
|
|
{
|
2008-08-14 09:45:42 +00:00
|
|
|
//If there is a selection, return the containing inset menu
|
|
|
|
if (d->cursor_.selection())
|
|
|
|
return d->cursor_.inset().contextMenu(*this, x, y);
|
|
|
|
|
2007-12-26 12:40:58 +00:00
|
|
|
// Get inset under mouse, if there is one.
|
|
|
|
Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
|
|
|
|
if (covering_inset)
|
|
|
|
return covering_inset->contextMenu(*this, x, y);
|
|
|
|
|
2008-03-08 22:57:22 +00:00
|
|
|
return buffer_.inset().contextMenu(*this, x, y);
|
2007-12-25 20:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-14 21:48:23 +00:00
|
|
|
void BufferView::scrollDocView(int value, bool update)
|
2001-02-19 16:01:31 +00:00
|
|
|
{
|
2008-01-29 13:34:18 +00:00
|
|
|
int const offset = value - d->scrollbarParameters_.position;
|
2008-11-15 18:17:20 +00:00
|
|
|
|
|
|
|
// No scrolling at all? No need to redraw anything
|
|
|
|
if (offset == 0)
|
|
|
|
return;
|
|
|
|
|
2008-01-29 13:34:18 +00:00
|
|
|
// If the offset is less than 2 screen height, prefer to scroll instead.
|
|
|
|
if (abs(offset) <= 2 * height_) {
|
2008-11-15 18:17:20 +00:00
|
|
|
d->anchor_ypos_ -= offset;
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(true);
|
2010-03-29 15:21:10 +00:00
|
|
|
updateHoveredInset();
|
2008-01-29 13:34:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-29 09:51:12 +00:00
|
|
|
// cut off at the top
|
|
|
|
if (value <= d->scrollbarParameters_.min) {
|
2008-11-17 11:46:07 +00:00
|
|
|
DocIterator dit = doc_iterator_begin(&buffer_);
|
2010-06-14 21:48:23 +00:00
|
|
|
showCursor(dit, false, update);
|
2008-01-29 09:51:12 +00:00
|
|
|
LYXERR(Debug::SCROLLING, "scroll to top");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-29 10:17:41 +00:00
|
|
|
// cut off at the bottom
|
2008-01-29 09:51:12 +00:00
|
|
|
if (value >= d->scrollbarParameters_.max) {
|
2008-11-17 11:46:07 +00:00
|
|
|
DocIterator dit = doc_iterator_end(&buffer_);
|
2008-01-29 09:51:12 +00:00
|
|
|
dit.backwardPos();
|
2010-06-14 21:48:23 +00:00
|
|
|
showCursor(dit, false, update);
|
2008-01-29 09:51:12 +00:00
|
|
|
LYXERR(Debug::SCROLLING, "scroll to bottom");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-29 10:17:41 +00:00
|
|
|
// find paragraph at target position
|
2008-01-26 00:47:22 +00:00
|
|
|
int par_pos = d->scrollbarParameters_.min;
|
2008-01-29 10:17:41 +00:00
|
|
|
pit_type i = 0;
|
2008-02-09 15:23:05 +00:00
|
|
|
for (; i != int(d->par_height_.size()); ++i) {
|
2007-12-21 08:28:18 +00:00
|
|
|
par_pos += d->par_height_[i];
|
2008-01-29 10:17:41 +00:00
|
|
|
if (par_pos >= value)
|
2007-12-21 08:28:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2008-01-29 10:17:41 +00:00
|
|
|
if (par_pos < value) {
|
|
|
|
// It seems we didn't find the correct pit so stay on the safe side and
|
|
|
|
// scroll to bottom.
|
|
|
|
LYXERR0("scrolling position not found!");
|
2010-06-14 21:48:23 +00:00
|
|
|
scrollDocView(d->scrollbarParameters_.max, update);
|
2008-01-29 10:17:41 +00:00
|
|
|
return;
|
2008-01-26 00:47:22 +00:00
|
|
|
}
|
|
|
|
|
2008-11-17 11:46:07 +00:00
|
|
|
DocIterator dit = doc_iterator_begin(&buffer_);
|
2008-01-29 10:17:41 +00:00
|
|
|
dit.pit() = i;
|
|
|
|
LYXERR(Debug::SCROLLING, "value = " << value << " -> scroll to pit " << i);
|
2010-06-14 21:48:23 +00:00
|
|
|
showCursor(dit, false, update);
|
2001-02-19 16:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
// FIXME: this method is not working well.
|
2006-08-16 15:24:38 +00:00
|
|
|
void BufferView::setCursorFromScrollbar()
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
TextMetrics & tm = d->text_metrics_[&buffer_.text()];
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
int const height = 2 * defaultRowHeight();
|
|
|
|
int const first = height;
|
|
|
|
int const last = height_ - height;
|
2008-08-14 09:59:04 +00:00
|
|
|
int newy = 0;
|
|
|
|
Cursor const & oldcur = d->cursor_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2008-08-14 09:59:04 +00:00
|
|
|
switch (cursorStatus(oldcur)) {
|
2007-09-29 08:02:37 +00:00
|
|
|
case CUR_ABOVE:
|
2008-08-14 09:59:04 +00:00
|
|
|
newy = first;
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
2007-09-29 08:02:37 +00:00
|
|
|
case CUR_BELOW:
|
2008-08-14 09:59:04 +00:00
|
|
|
newy = last;
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
2007-09-29 08:02:37 +00:00
|
|
|
case CUR_INSIDE:
|
2010-04-21 13:03:04 +00:00
|
|
|
int const y = getPos(oldcur).y_;
|
2008-08-14 09:59:04 +00:00
|
|
|
newy = min(last, max(y, first));
|
|
|
|
if (y == newy)
|
|
|
|
return;
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
2008-08-14 09:59:04 +00:00
|
|
|
// We reset the cursor because cursorStatus() does not
|
|
|
|
// work when the cursor is within mathed.
|
|
|
|
Cursor cur(*this);
|
2009-10-29 22:46:04 +00:00
|
|
|
cur.reset();
|
2008-08-14 09:59:04 +00:00
|
|
|
tm.setCursorFromCoordinates(cur, 0, newy);
|
2008-11-15 17:11:01 +00:00
|
|
|
|
|
|
|
// update the bufferview cursor and notify insets
|
|
|
|
// FIXME: Care about the d->cursor_ flags to redraw if needed
|
|
|
|
Cursor old = d->cursor_;
|
2008-08-14 09:59:04 +00:00
|
|
|
mouseSetCursor(cur);
|
2011-05-28 14:36:50 +00:00
|
|
|
// the DEPM call in mouseSetCursor() might have destroyed the
|
|
|
|
// paragraph the cursor is in.
|
|
|
|
bool badcursor = old.fixIfBroken();
|
|
|
|
badcursor |= notifyCursorLeavesOrEnters(old, d->cursor_);
|
2008-11-15 17:11:01 +00:00
|
|
|
if (badcursor)
|
|
|
|
d->cursor_.fixIfBroken();
|
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
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
if (!d->cursor_.selection())
|
2006-09-16 10:08:51 +00:00
|
|
|
return Change(Change::UNCHANGED);
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
DocIterator dit = d->cursor_.selectionBegin();
|
2014-03-23 08:52:32 +00:00
|
|
|
// The selected content might have been changed (see #7685)
|
|
|
|
while (dit.inMathed())
|
|
|
|
// Find enclosing text cursor
|
|
|
|
dit.pop_back();
|
2006-09-16 10:08:51 +00:00
|
|
|
return dit.paragraph().lookupChange(dit.pos());
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-09-29 08:02:37 +00:00
|
|
|
// this could be used elsewhere as well?
|
|
|
|
// FIXME: This does not work within mathed!
|
|
|
|
CursorStatus BufferView::cursorStatus(DocIterator const & dit) const
|
|
|
|
{
|
2010-04-21 13:03:04 +00:00
|
|
|
Point const p = getPos(dit);
|
2007-09-29 08:02:37 +00:00
|
|
|
if (p.y_ < 0)
|
|
|
|
return CUR_ABOVE;
|
|
|
|
if (p.y_ > workHeight())
|
|
|
|
return CUR_BELOW;
|
|
|
|
return CUR_INSIDE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-13 13:46:08 +00:00
|
|
|
void BufferView::bookmarkEditPosition()
|
|
|
|
{
|
|
|
|
// Don't eat cpu time for each keystroke
|
|
|
|
if (d->cursor_.paragraph().id() == d->bookmark_edit_position_)
|
|
|
|
return;
|
|
|
|
saveBookmark(0);
|
|
|
|
d->bookmark_edit_position_ = d->cursor_.paragraph().id();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-29 03:41:55 +00:00
|
|
|
void BufferView::saveBookmark(unsigned int idx)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2009-02-12 23:46:16 +00:00
|
|
|
// tentatively save bookmark, id and pos will be used to
|
2007-04-16 19:01:32 +00:00
|
|
|
// 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.
|
2010-03-23 00:45:37 +00:00
|
|
|
if (!buffer_.isInternal()) {
|
|
|
|
theSession().bookmarks().save(
|
|
|
|
buffer_.fileName(),
|
|
|
|
d->cursor_.bottom().pit(),
|
|
|
|
d->cursor_.bottom().pos(),
|
|
|
|
d->cursor_.paragraph().id(),
|
|
|
|
d->cursor_.pos(),
|
|
|
|
idx
|
|
|
|
);
|
|
|
|
if (idx)
|
|
|
|
// emit message signal.
|
|
|
|
message(_("Save bookmark"));
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-22 14:25:51 +00:00
|
|
|
bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
|
2007-04-16 19:01:32 +00:00
|
|
|
int top_id, pos_type top_pos)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2007-08-22 14:25:51 +00:00
|
|
|
bool success = false;
|
2008-02-09 15:23:05 +00:00
|
|
|
DocIterator dit;
|
2007-08-22 14:25:51 +00:00
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
d->cursor_.clearSelection();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
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) {
|
2008-02-09 15:23:05 +00:00
|
|
|
dit = buffer_.getParFromID(top_id);
|
|
|
|
if (!dit.atEnd()) {
|
|
|
|
dit.pos() = min(dit.paragraph().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.
|
2008-02-09 15:23:05 +00:00
|
|
|
size_t const n = dit.depth();
|
2007-04-16 20:47:40 +00:00
|
|
|
for (size_t i = 0; i < n; ++i)
|
2009-04-22 20:55:13 +00:00
|
|
|
if (!dit[i].inset().editable()) {
|
2008-02-09 15:23:05 +00:00
|
|
|
dit.resize(i);
|
2007-04-16 20:47:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-22 14:38:25 +00:00
|
|
|
success = true;
|
2007-01-11 16:01:10 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-22 14:25:51 +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.
|
2008-02-09 15:23:05 +00:00
|
|
|
if (bottom_pit < int(buffer_.paragraphs().size())) {
|
2008-11-17 11:46:07 +00:00
|
|
|
dit = doc_iterator_begin(&buffer_);
|
2008-02-09 15:23:05 +00:00
|
|
|
|
|
|
|
dit.pit() = bottom_pit;
|
|
|
|
dit.pos() = min(bottom_pos, dit.paragraph().size());
|
2007-08-22 14:25:51 +00:00
|
|
|
success = true;
|
2007-01-11 16:01:10 +00:00
|
|
|
}
|
2007-08-22 14:25:51 +00:00
|
|
|
|
|
|
|
if (success) {
|
|
|
|
// Note: only bottom (document) level pit is set.
|
2008-02-09 15:23:05 +00:00
|
|
|
setCursor(dit);
|
2007-08-22 14:25:51 +00:00
|
|
|
// set the current font.
|
2007-10-13 07:33:07 +00:00
|
|
|
d->cursor_.setCurrentFont();
|
2007-11-19 10:04:14 +00:00
|
|
|
// To center the screen on this new position we need the
|
|
|
|
// paragraph position which is computed at draw() time.
|
|
|
|
// So we need a redraw!
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(false);
|
2007-11-19 10:04:14 +00:00
|
|
|
if (fitCursor())
|
2007-12-21 08:35:43 +00:00
|
|
|
showCursor();
|
2007-08-22 14:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
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) {
|
2007-10-13 07:33:07 +00:00
|
|
|
if (d->cursor_.real_current_font.isRightToLeft()) {
|
|
|
|
if (d->intl_.keymap == Intl::PRIMARY)
|
|
|
|
d->intl_.keyMapSec();
|
2007-06-13 06:27:33 +00:00
|
|
|
} else {
|
2007-10-13 07:33:07 +00:00
|
|
|
if (d->intl_.keymap == Intl::SECONDARY)
|
|
|
|
d->intl_.keyMapPrim();
|
2007-06-13 06:27:33 +00:00
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
2007-09-16 10:38:25 +00:00
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
d->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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-26 00:09:16 +00:00
|
|
|
void BufferView::recenter()
|
|
|
|
{
|
2010-06-14 21:48:23 +00:00
|
|
|
showCursor(d->cursor_, true, true);
|
2009-03-26 00:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-21 08:35:43 +00:00
|
|
|
void BufferView::showCursor()
|
2008-01-29 09:51:12 +00:00
|
|
|
{
|
2010-06-14 21:48:23 +00:00
|
|
|
showCursor(d->cursor_, false, true);
|
2008-01-29 09:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-14 21:48:23 +00:00
|
|
|
void BufferView::showCursor(DocIterator const & dit,
|
|
|
|
bool recenter, bool update)
|
2009-03-27 17:27:38 +00:00
|
|
|
{
|
2010-06-14 21:48:23 +00:00
|
|
|
if (scrollToCursor(dit, recenter) && update) {
|
2010-03-29 15:29:26 +00:00
|
|
|
buffer_.changed(true);
|
2010-03-29 15:21:10 +00:00
|
|
|
updateHoveredInset();
|
|
|
|
}
|
2009-03-27 17:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::scrollToCursor()
|
|
|
|
{
|
2010-03-29 15:29:26 +00:00
|
|
|
if (scrollToCursor(d->cursor_, false)) {
|
|
|
|
buffer_.changed(true);
|
2010-03-29 15:21:10 +00:00
|
|
|
updateHoveredInset();
|
2010-03-29 15:29:26 +00:00
|
|
|
}
|
2009-03-27 17:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BufferView::scrollToCursor(DocIterator const & dit, bool recenter)
|
2000-02-17 19:59:08 +00:00
|
|
|
{
|
2007-08-22 14:44:34 +00:00
|
|
|
// We are not properly started yet, delay until resizing is
|
|
|
|
// done.
|
2007-08-22 14:14:52 +00:00
|
|
|
if (height_ == 0)
|
2009-03-27 17:27:38 +00:00
|
|
|
return false;
|
2007-08-22 14:14:52 +00:00
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
LYXERR(Debug::SCROLLING, "recentering!");
|
2007-12-19 07:47:03 +00:00
|
|
|
|
2008-01-29 09:51:12 +00:00
|
|
|
CursorSlice const & bot = dit.bottom();
|
2007-10-13 07:33:07 +00:00
|
|
|
TextMetrics & tm = d->text_metrics_[bot.text()];
|
2007-12-21 08:28:18 +00:00
|
|
|
|
2007-12-22 09:04:53 +00:00
|
|
|
pos_type const max_pit = pos_type(bot.text()->paragraphs().size() - 1);
|
2008-01-29 09:51:12 +00:00
|
|
|
int bot_pit = bot.pit();
|
2007-12-22 09:04:53 +00:00
|
|
|
if (bot_pit > max_pit) {
|
|
|
|
// FIXME: Why does this happen?
|
|
|
|
LYXERR0("bottom pit is greater that max pit: "
|
|
|
|
<< bot_pit << " > " << max_pit);
|
|
|
|
bot_pit = max_pit;
|
|
|
|
}
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
if (bot_pit == tm.first().first - 1)
|
|
|
|
tm.newParMetricsUp();
|
|
|
|
else if (bot_pit == tm.last().first + 1)
|
|
|
|
tm.newParMetricsDown();
|
|
|
|
|
2008-02-27 23:03:26 +00:00
|
|
|
if (tm.contains(bot_pit)) {
|
2007-12-21 08:28:18 +00:00
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(!pm.rows().empty(), /**/);
|
2008-01-29 09:51:12 +00:00
|
|
|
// FIXME: smooth scrolling doesn't work in mathed.
|
|
|
|
CursorSlice const & cs = dit.innerTextSlice();
|
2010-04-21 13:12:40 +00:00
|
|
|
int offset = coordOffset(dit).y_;
|
2007-12-21 08:28:18 +00:00
|
|
|
int ypos = pm.position() + offset;
|
2008-01-29 09:51:12 +00:00
|
|
|
Dimension const & row_dim =
|
|
|
|
pm.getRow(cs.pos(), dit.boundary()).dimension();
|
2008-07-04 11:33:28 +00:00
|
|
|
int scrolled = 0;
|
2009-03-26 00:09:16 +00:00
|
|
|
if (recenter)
|
|
|
|
scrolled = scroll(ypos - height_/2);
|
2010-04-26 14:57:27 +00:00
|
|
|
|
2011-10-26 13:35:49 +00:00
|
|
|
// We try to visualize the whole row, if the row height is larger than
|
|
|
|
// the screen height, we scroll to a heuristic value of height_ / 4.
|
|
|
|
// FIXME: This heuristic value should be replaced by a recursive search
|
|
|
|
// for a row in the inset that can be visualized completely.
|
|
|
|
else if (row_dim.height() > height_) {
|
|
|
|
if (ypos < defaultRowHeight())
|
|
|
|
scrolled = scroll(ypos - height_ / 4);
|
|
|
|
else if (ypos > height_ - defaultRowHeight())
|
|
|
|
scrolled = scroll(ypos - 3 * height_ / 4);
|
|
|
|
}
|
|
|
|
|
2010-04-26 14:57:27 +00:00
|
|
|
// If the top part of the row falls of the screen, we scroll
|
|
|
|
// up to align the top of the row with the top of the screen.
|
2011-10-26 13:35:47 +00:00
|
|
|
else if (ypos - row_dim.ascent() < 0 && ypos < height_) {
|
|
|
|
int ynew = row_dim.ascent();
|
2011-10-26 13:35:49 +00:00
|
|
|
scrolled = scrollUp(ynew - ypos);
|
2011-10-26 13:35:47 +00:00
|
|
|
}
|
2010-04-26 14:57:27 +00:00
|
|
|
|
|
|
|
// If the bottom of the row falls of the screen, we scroll down.
|
2011-10-26 13:35:47 +00:00
|
|
|
else if (ypos + row_dim.descent() > height_ && ypos > 0) {
|
2010-04-26 14:57:27 +00:00
|
|
|
int ynew = height_ - row_dim.descent();
|
2011-10-26 13:35:49 +00:00
|
|
|
scrolled = scrollDown(ypos - ynew);
|
2010-04-26 14:57:27 +00:00
|
|
|
}
|
2009-02-08 12:35:14 +00:00
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
// else, nothing to do, the cursor is already visible so we just return.
|
2010-03-29 15:29:26 +00:00
|
|
|
return scrolled != 0;
|
2007-12-19 07:47:03 +00:00
|
|
|
}
|
2007-08-22 14:14:52 +00:00
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
// fix inline completion position
|
2008-04-16 20:43:30 +00:00
|
|
|
if (d->inlineCompletionPos_.fixIfBroken())
|
|
|
|
d->inlineCompletionPos_ = DocIterator();
|
2008-02-21 19:42:34 +00:00
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
tm.redoParagraph(bot_pit);
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
|
2010-04-21 13:12:40 +00:00
|
|
|
int offset = coordOffset(dit).y_;
|
2007-08-22 14:14:52 +00:00
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
d->anchor_pit_ = bot_pit;
|
2008-01-29 09:51:12 +00:00
|
|
|
CursorSlice const & cs = dit.innerTextSlice();
|
|
|
|
Dimension const & row_dim =
|
|
|
|
pm.getRow(cs.pos(), dit.boundary()).dimension();
|
2007-12-21 08:28:18 +00:00
|
|
|
|
2009-03-26 00:09:16 +00:00
|
|
|
if (recenter)
|
|
|
|
d->anchor_ypos_ = height_/2;
|
|
|
|
else if (d->anchor_pit_ == 0)
|
2007-12-21 08:28:18 +00:00
|
|
|
d->anchor_ypos_ = offset + pm.ascent();
|
2007-12-22 09:04:53 +00:00
|
|
|
else if (d->anchor_pit_ == max_pit)
|
2007-12-21 10:11:32 +00:00
|
|
|
d->anchor_ypos_ = height_ - offset - row_dim.descent();
|
2009-02-08 12:35:14 +00:00
|
|
|
else if (offset > height_)
|
|
|
|
d->anchor_ypos_ = height_ - offset - defaultRowHeight();
|
2007-12-22 09:04:53 +00:00
|
|
|
else
|
2009-02-08 12:35:14 +00:00
|
|
|
d->anchor_ypos_ = defaultRowHeight() * 2;
|
2007-12-21 08:28:18 +00:00
|
|
|
|
2009-03-27 17:27:38 +00:00
|
|
|
return true;
|
2000-02-17 19:59:08 +00:00
|
|
|
}
|
2000-05-20 01:38:25 +00:00
|
|
|
|
|
|
|
|
2010-03-08 20:37:11 +00:00
|
|
|
void BufferView::updateDocumentClass(DocumentClass const * const olddc)
|
2009-09-19 20:56:12 +00:00
|
|
|
{
|
|
|
|
message(_("Converting document to new document class..."));
|
|
|
|
|
|
|
|
StableDocIterator backcur(d->cursor_);
|
|
|
|
ErrorList & el = buffer_.errorList("Class Switch");
|
|
|
|
cap::switchBetweenClasses(
|
2010-03-08 20:37:11 +00:00
|
|
|
olddc, buffer_.params().documentClassPtr(),
|
2009-09-19 20:56:12 +00:00
|
|
|
static_cast<InsetText &>(buffer_.inset()), el);
|
|
|
|
|
|
|
|
setCursor(backcur.asDocIterator(&buffer_));
|
|
|
|
|
|
|
|
buffer_.errors("Class Switch");
|
|
|
|
}
|
|
|
|
|
2009-09-23 09:07:24 +00:00
|
|
|
/** Return the change status at cursor position, taking in account the
|
|
|
|
* status at each level of the document iterator (a table in a deleted
|
|
|
|
* footnote is deleted).
|
|
|
|
* When \param outer is true, the top slice is not looked at.
|
|
|
|
*/
|
|
|
|
static Change::Type lookupChangeType(DocIterator const & dit, bool outer = false)
|
|
|
|
{
|
|
|
|
size_t const depth = dit.depth() - (outer ? 1 : 0);
|
|
|
|
|
|
|
|
for (size_t i = 0 ; i < depth ; ++i) {
|
|
|
|
CursorSlice const & slice = dit[i];
|
|
|
|
if (!slice.inset().inMathed()
|
|
|
|
&& slice.pos() < slice.paragraph().size()) {
|
|
|
|
Change::Type const ch = slice.paragraph().lookupChange(slice.pos()).type;
|
|
|
|
if (ch != Change::UNCHANGED)
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Change::UNCHANGED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-06 12:12:06 +00:00
|
|
|
bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
2004-04-01 08:58:45 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
FuncCode const act = cmd.action();
|
|
|
|
|
2009-09-23 09:07:24 +00:00
|
|
|
// Can we use a readonly buffer?
|
|
|
|
if (buffer_.isReadonly()
|
2010-04-09 19:00:42 +00:00
|
|
|
&& !lyxaction.funcHasFlag(act, LyXAction::ReadOnly)
|
|
|
|
&& !lyxaction.funcHasFlag(act, LyXAction::NoBuffer)) {
|
2009-09-23 09:07:24 +00:00
|
|
|
flag.message(from_utf8(N_("Document is read-only")));
|
|
|
|
flag.setEnabled(false);
|
|
|
|
return true;
|
|
|
|
}
|
2010-04-09 19:00:42 +00:00
|
|
|
|
2009-09-23 09:07:24 +00:00
|
|
|
// Are we in a DELETED change-tracking region?
|
|
|
|
if (lookupChangeType(d->cursor_, true) == Change::DELETED
|
2010-04-09 19:00:42 +00:00
|
|
|
&& !lyxaction.funcHasFlag(act, LyXAction::ReadOnly)
|
|
|
|
&& !lyxaction.funcHasFlag(act, LyXAction::NoBuffer)) {
|
2009-09-23 09:07:24 +00:00
|
|
|
flag.message(from_utf8(N_("This portion of the document is deleted.")));
|
|
|
|
flag.setEnabled(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
Cursor & cur = d->cursor_;
|
2007-06-10 15:07:21 +00:00
|
|
|
|
2009-11-13 14:32:51 +00:00
|
|
|
if (cur.getStatus(cmd, flag))
|
2009-09-23 09:07:24 +00:00
|
|
|
return true;
|
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (act) {
|
2009-09-19 20:56:12 +00:00
|
|
|
|
2010-04-08 09:17:00 +00:00
|
|
|
// FIXME: This is a bit problematic because we don't check if this is
|
2010-04-08 01:23:04 +00:00
|
|
|
// a document BufferView or not for these LFUNs. We probably have to
|
2009-09-19 20:56:12 +00:00
|
|
|
// dispatch both to currentBufferView() and, if that fails,
|
2010-08-06 23:54:04 +00:00
|
|
|
// to documentBufferView(); same as we do now for current Buffer and
|
|
|
|
// document Buffer. Ideally those LFUN should go to Buffer as they
|
2009-09-19 20:56:12 +00:00
|
|
|
// operate on the full Buffer and the cursor is only needed either for
|
|
|
|
// an Undo record or to restore a cursor position. But we don't know
|
|
|
|
// how to do that inside Buffer of course.
|
2009-09-19 17:56:53 +00:00
|
|
|
case LFUN_BUFFER_PARAMS_APPLY:
|
2009-09-19 20:56:12 +00:00
|
|
|
case LFUN_LAYOUT_MODULES_CLEAR:
|
|
|
|
case LFUN_LAYOUT_MODULE_ADD:
|
|
|
|
case LFUN_LAYOUT_RELOAD:
|
|
|
|
case LFUN_TEXTCLASS_APPLY:
|
|
|
|
case LFUN_TEXTCLASS_LOAD:
|
2009-09-19 17:56:53 +00:00
|
|
|
flag.setEnabled(!buffer_.isReadonly());
|
|
|
|
break;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
case LFUN_UNDO:
|
2010-08-06 23:54:04 +00:00
|
|
|
// We do not use the LyXAction flag for readonly because Undo sets the
|
|
|
|
// buffer clean/dirty status by itself.
|
|
|
|
flag.setEnabled(!buffer_.isReadonly() && buffer_.undo().hasUndoStack());
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
|
|
|
case LFUN_REDO:
|
2010-08-06 23:54:04 +00:00
|
|
|
// We do not use the LyXAction flag for readonly because Redo sets the
|
|
|
|
// buffer clean/dirty status by itself.
|
|
|
|
flag.setEnabled(!buffer_.isReadonly() && buffer_.undo().hasRedoStack());
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
2007-01-15 22:49:14 +00:00
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
|
2012-03-05 22:38:21 +00:00
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT: {
|
|
|
|
docstring const fname = cmd.argument();
|
|
|
|
if (!FileName::isAbsolute(to_utf8(fname))) {
|
|
|
|
flag.message(_("Absolute filename expected."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
flag.setEnabled(cur.inTexted());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LFUN_FILE_INSERT:
|
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
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(cur.inTexted());
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
2009-04-06 12:12:06 +00:00
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
case LFUN_FONT_STATE:
|
|
|
|
case LFUN_LABEL_INSERT:
|
2007-10-11 14:52:00 +00:00
|
|
|
case LFUN_INFO_INSERT:
|
2006-09-16 10:08:51 +00:00
|
|
|
case LFUN_PARAGRAPH_GOTO:
|
|
|
|
case LFUN_NOTE_NEXT:
|
|
|
|
case LFUN_REFERENCE_NEXT:
|
|
|
|
case LFUN_WORD_FIND:
|
2009-09-09 05:20:30 +00:00
|
|
|
case LFUN_WORD_FIND_FORWARD:
|
|
|
|
case LFUN_WORD_FIND_BACKWARD:
|
2008-11-16 00:12:21 +00:00
|
|
|
case LFUN_WORD_FINDADV:
|
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:
|
2009-03-26 00:09:16 +00:00
|
|
|
case LFUN_SCREEN_SHOW_CURSOR:
|
2006-09-16 10:08:51 +00:00
|
|
|
case LFUN_BIBTEX_DATABASE_ADD:
|
|
|
|
case LFUN_BIBTEX_DATABASE_DEL:
|
2008-01-08 15:18:00 +00:00
|
|
|
case LFUN_STATISTICS:
|
2009-07-11 09:38:31 +00:00
|
|
|
case LFUN_BRANCH_ADD_INSERT:
|
2009-09-19 16:59:36 +00:00
|
|
|
case LFUN_KEYMAP_OFF:
|
|
|
|
case LFUN_KEYMAP_PRIMARY:
|
|
|
|
case LFUN_KEYMAP_SECONDARY:
|
|
|
|
case LFUN_KEYMAP_TOGGLE:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
2008-11-16 00:12:21 +00:00
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
case LFUN_LABEL_GOTO: {
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(!cmd.argument().empty()
|
2007-10-13 09:04:52 +00:00
|
|
|
|| getInsetByCode<InsetRef>(cur, REF_CODE));
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_CHANGES_TRACK:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(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:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2007-08-21 07:33:46 +00:00
|
|
|
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:
|
2009-04-05 19:14:37 +00:00
|
|
|
case LFUN_CHANGE_PREVIOUS:
|
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.
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(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;
|
|
|
|
}
|
2010-05-25 11:36:02 +00:00
|
|
|
|
|
|
|
case LFUN_BUFFER_TOGGLE_OUTPUT_SYNC: {
|
|
|
|
flag.setOnOff(buffer_.params().output_sync);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-09-15 12:28:41 +00:00
|
|
|
case LFUN_SCREEN_UP:
|
|
|
|
case LFUN_SCREEN_DOWN:
|
2007-12-27 11:37:07 +00:00
|
|
|
case LFUN_SCROLL:
|
2007-09-15 12:28:41 +00:00
|
|
|
case LFUN_SCREEN_UP_SELECT:
|
|
|
|
case LFUN_SCREEN_DOWN_SELECT:
|
2010-01-07 15:47:58 +00:00
|
|
|
case LFUN_INSET_FORALL:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2007-09-15 12:28:41 +00:00
|
|
|
break;
|
|
|
|
|
2007-10-11 13:20:21 +00:00
|
|
|
case LFUN_LAYOUT_TABULAR:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(cur.innerInsetOfType(TABULAR_CODE));
|
2007-10-11 13:20:21 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_LAYOUT:
|
2008-07-10 17:41:52 +00:00
|
|
|
flag.setEnabled(!cur.inset().forcePlainLayout(cur.idx()));
|
2008-03-19 16:21:33 +00:00
|
|
|
break;
|
|
|
|
|
2007-10-11 13:20:21 +00:00
|
|
|
case LFUN_LAYOUT_PARAGRAPH:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(cur.inset().allowParagraphCustomization(cur.idx()));
|
2007-10-11 13:20:21 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_DIALOG_SHOW_NEW_INSET:
|
2009-07-16 10:08:13 +00:00
|
|
|
// FIXME: this is wrong, but I do not understand the
|
|
|
|
// intent (JMarc)
|
2009-04-06 12:12:06 +00:00
|
|
|
if (cur.inset().lyxCode() == CAPTION_CODE)
|
|
|
|
return cur.inset().getStatus(cur, cmd, flag);
|
2009-07-16 10:08:13 +00:00
|
|
|
// FIXME we should consider passthru paragraphs too.
|
2011-01-26 11:04:42 +00:00
|
|
|
flag.setEnabled(!(cur.inTexted() && cur.paragraph().isPassThru()));
|
2007-10-11 13:20:21 +00:00
|
|
|
break;
|
|
|
|
|
2009-09-26 17:30:29 +00:00
|
|
|
case LFUN_CITATION_INSERT: {
|
|
|
|
FuncRequest fr(LFUN_INSET_INSERT, "citation");
|
|
|
|
// FIXME: This could turn in a recursive hell.
|
|
|
|
// Shouldn't we use Buffer::getStatus() instead?
|
|
|
|
flag.setEnabled(lyx::getStatus(fr).enabled());
|
|
|
|
break;
|
|
|
|
}
|
2009-09-27 10:29:13 +00:00
|
|
|
case LFUN_INSET_APPLY: {
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
Inset * inset = editedInset(name);
|
|
|
|
if (inset) {
|
|
|
|
FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
|
2010-04-16 12:15:27 +00:00
|
|
|
if (!inset->getStatus(cur, fr, flag)) {
|
2009-09-27 10:29:13 +00:00
|
|
|
// Every inset is supposed to handle this
|
|
|
|
LASSERT(false, break);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
|
2010-04-16 12:15:27 +00:00
|
|
|
flag = lyx::getStatus(fr);
|
2009-09-27 10:29:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-09-26 17:30:29 +00:00
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
default:
|
2009-04-06 12:12:06 +00:00
|
|
|
return false;
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
|
|
|
|
2009-04-06 12:12:06 +00:00
|
|
|
return true;
|
2004-04-01 08:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-27 10:29:13 +00:00
|
|
|
Inset * BufferView::editedInset(string const & name) const
|
|
|
|
{
|
|
|
|
map<string, Inset *>::const_iterator it = d->edited_insets_.find(name);
|
|
|
|
return it == d->edited_insets_.end() ? 0 : it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::editInset(string const & name, Inset * inset)
|
|
|
|
{
|
|
|
|
d->edited_insets_[name] = inset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-25 15:14:41 +00:00
|
|
|
void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
2001-02-23 16:10:03 +00:00
|
|
|
{
|
2012-06-07 15:19:04 +00:00
|
|
|
LYXERR(Debug::ACTION, "BufferView::dispatch: cmd: " << cmd);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2009-09-19 20:56:12 +00:00
|
|
|
string const argument = to_utf8(cmd.argument());
|
2007-10-13 07:33:07 +00:00
|
|
|
Cursor & cur = d->cursor_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2009-09-21 12:36:22 +00:00
|
|
|
// Don't dispatch function that does not apply to internal buffers.
|
2009-11-13 14:32:51 +00:00
|
|
|
if (buffer_.isInternal()
|
2010-04-09 19:00:42 +00:00
|
|
|
&& lyxaction.funcHasFlag(cmd.action(), LyXAction::NoInternal))
|
2010-01-25 15:14:41 +00:00
|
|
|
return;
|
2009-09-21 12:36:22 +00:00
|
|
|
|
2009-10-03 19:12:21 +00:00
|
|
|
// We'll set this back to false if need be.
|
|
|
|
bool dispatched = true;
|
2009-11-06 13:32:58 +00:00
|
|
|
buffer_.undo().beginUndoGroup();
|
2009-10-03 19:12:21 +00:00
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
FuncCode const act = cmd.action();
|
|
|
|
switch (act) {
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2009-09-19 17:56:53 +00:00
|
|
|
case LFUN_BUFFER_PARAMS_APPLY: {
|
|
|
|
DocumentClass const * const oldClass = buffer_.params().documentClassPtr();
|
|
|
|
cur.recordUndoFullDocument();
|
|
|
|
istringstream ss(to_utf8(cmd.argument()));
|
|
|
|
Lexer lex;
|
|
|
|
lex.setStream(ss);
|
|
|
|
int const unknown_tokens = buffer_.readHeader(lex);
|
|
|
|
if (unknown_tokens != 0) {
|
|
|
|
LYXERR0("Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
|
|
|
|
<< unknown_tokens << " unknown token"
|
|
|
|
<< (unknown_tokens == 1 ? "" : "s"));
|
|
|
|
}
|
2010-03-08 20:37:11 +00:00
|
|
|
updateDocumentClass(oldClass);
|
2009-09-19 17:56:53 +00:00
|
|
|
|
|
|
|
// We are most certainly here because of a change in the document
|
|
|
|
// It is then better to make sure that all dialogs are in sync with
|
|
|
|
// current document settings.
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2009-09-19 17:56:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-19 20:56:12 +00:00
|
|
|
case LFUN_LAYOUT_MODULES_CLEAR: {
|
|
|
|
DocumentClass const * const oldClass =
|
|
|
|
buffer_.params().documentClassPtr();
|
|
|
|
cur.recordUndoFullDocument();
|
|
|
|
buffer_.params().clearLayoutModules();
|
|
|
|
buffer_.params().makeDocumentClass();
|
2010-03-08 20:37:11 +00:00
|
|
|
updateDocumentClass(oldClass);
|
2010-10-13 18:04:44 +00:00
|
|
|
dr.screenUpdate(Update::Force);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2009-09-19 20:56:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_LAYOUT_MODULE_ADD: {
|
|
|
|
BufferParams const & params = buffer_.params();
|
|
|
|
if (!params.moduleCanBeAdded(argument)) {
|
|
|
|
LYXERR0("Module `" << argument <<
|
|
|
|
"' cannot be added due to failed requirements or "
|
|
|
|
"conflicts with installed modules.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DocumentClass const * const oldClass = params.documentClassPtr();
|
|
|
|
cur.recordUndoFullDocument();
|
|
|
|
buffer_.params().addLayoutModule(argument);
|
|
|
|
buffer_.params().makeDocumentClass();
|
2010-03-08 20:37:11 +00:00
|
|
|
updateDocumentClass(oldClass);
|
2010-10-13 18:04:44 +00:00
|
|
|
dr.screenUpdate(Update::Force);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2009-09-19 20:56:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_TEXTCLASS_APPLY: {
|
2010-07-29 00:00:37 +00:00
|
|
|
// since this shortcircuits, the second call is made only if
|
|
|
|
// the first fails
|
|
|
|
bool const success =
|
|
|
|
LayoutFileList::get().load(argument, buffer_.temppath()) ||
|
|
|
|
LayoutFileList::get().load(argument, buffer_.filePath());
|
2010-07-28 21:03:27 +00:00
|
|
|
if (!success) {
|
|
|
|
docstring s = bformat(_("The document class `%1$s' "
|
|
|
|
"could not be loaded."), from_utf8(argument));
|
|
|
|
frontend::Alert::error(_("Could not load class"), s);
|
2009-09-19 20:56:12 +00:00
|
|
|
break;
|
2010-07-28 21:03:27 +00:00
|
|
|
}
|
2009-09-19 20:56:12 +00:00
|
|
|
|
|
|
|
LayoutFile const * old_layout = buffer_.params().baseClass();
|
|
|
|
LayoutFile const * new_layout = &(LayoutFileList::get()[argument]);
|
|
|
|
|
|
|
|
if (old_layout == new_layout)
|
|
|
|
// nothing to do
|
|
|
|
break;
|
|
|
|
|
2010-07-28 21:03:27 +00:00
|
|
|
// Save the old, possibly modular, layout for use in conversion.
|
2009-09-19 20:56:12 +00:00
|
|
|
DocumentClass const * const oldDocClass =
|
|
|
|
buffer_.params().documentClassPtr();
|
|
|
|
cur.recordUndoFullDocument();
|
|
|
|
buffer_.params().setBaseClass(argument);
|
|
|
|
buffer_.params().makeDocumentClass();
|
2010-03-08 20:37:11 +00:00
|
|
|
updateDocumentClass(oldDocClass);
|
2010-10-13 18:04:44 +00:00
|
|
|
dr.screenUpdate(Update::Force);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2009-09-19 20:56:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-07-28 21:03:27 +00:00
|
|
|
case LFUN_TEXTCLASS_LOAD: {
|
2010-07-29 00:00:37 +00:00
|
|
|
// since this shortcircuits, the second call is made only if
|
|
|
|
// the first fails
|
|
|
|
bool const success =
|
|
|
|
LayoutFileList::get().load(argument, buffer_.temppath()) ||
|
|
|
|
LayoutFileList::get().load(argument, buffer_.filePath());
|
2010-07-28 21:03:27 +00:00
|
|
|
if (!success) {
|
|
|
|
docstring s = bformat(_("The document class `%1$s' "
|
|
|
|
"could not be loaded."), from_utf8(argument));
|
|
|
|
frontend::Alert::error(_("Could not load class"), s);
|
|
|
|
}
|
2009-09-19 20:56:12 +00:00
|
|
|
break;
|
2010-07-28 21:03:27 +00:00
|
|
|
}
|
2009-09-19 20:56:12 +00:00
|
|
|
|
|
|
|
case LFUN_LAYOUT_RELOAD: {
|
|
|
|
DocumentClass const * const oldClass = buffer_.params().documentClassPtr();
|
|
|
|
LayoutFileIndex bc = buffer_.params().baseClassID();
|
|
|
|
LayoutFileList::get().reset(bc);
|
|
|
|
buffer_.params().setBaseClass(bc);
|
|
|
|
buffer_.params().makeDocumentClass();
|
2010-03-08 20:37:11 +00:00
|
|
|
updateDocumentClass(oldClass);
|
2010-10-13 18:04:44 +00:00
|
|
|
dr.screenUpdate(Update::Force);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2009-09-19 20:56:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
case LFUN_UNDO:
|
2010-01-25 15:14:41 +00:00
|
|
|
dr.setMessage(_("Undo"));
|
2007-01-24 23:10:03 +00:00
|
|
|
cur.clearSelection();
|
2007-12-21 10:42:59 +00:00
|
|
|
if (!cur.textUndo())
|
2010-01-25 15:14:41 +00:00
|
|
|
dr.setMessage(_("No further undo information"));
|
2007-12-26 14:10:24 +00:00
|
|
|
else
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_REDO:
|
2010-01-25 15:14:41 +00:00
|
|
|
dr.setMessage(_("Redo"));
|
2007-01-24 23:10:03 +00:00
|
|
|
cur.clearSelection();
|
2007-12-21 10:42:59 +00:00
|
|
|
if (!cur.textRedo())
|
2010-01-25 15:14:41 +00:00
|
|
|
dr.setMessage(_("No further redo information"));
|
2007-12-26 14:10:24 +00:00
|
|
|
else
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_FONT_STATE:
|
2010-01-25 15:14:41 +00:00
|
|
|
dr.setMessage(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 =
|
2009-04-06 18:25:23 +00:00
|
|
|
getInsetByCode<InsetRef>(cur, 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
|
|
|
}
|
|
|
|
}
|
2010-10-13 18:04:44 +00:00
|
|
|
if (!label.empty()) {
|
2006-09-16 10:08:51 +00:00
|
|
|
gotoLabel(label);
|
2010-10-13 18:04:44 +00:00
|
|
|
// at the moment, this is redundant, since gotoLabel will
|
|
|
|
// eventually call LFUN_PARAGRAPH_GOTO, but it seems best
|
|
|
|
// to have it here.
|
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-24 04:27:43 +00:00
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
case LFUN_PARAGRAPH_GOTO: {
|
2008-05-16 12:48:13 +00:00
|
|
|
int const id = convert<int>(cmd.getArg(0));
|
|
|
|
int const pos = convert<int>(cmd.getArg(1));
|
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)) {
|
|
|
|
|
2008-02-09 15:23:05 +00:00
|
|
|
DocIterator dit = b->getParFromID(id);
|
|
|
|
if (dit.atEnd()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::INFO, "No matching paragraph found! [" << id << "].");
|
2008-02-12 08:04:59 +00:00
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
LYXERR(Debug::INFO, "Paragraph " << dit.paragraph().id()
|
|
|
|
<< " found in buffer `"
|
|
|
|
<< b->absFileName() << "'.");
|
|
|
|
|
|
|
|
if (b == &buffer_) {
|
|
|
|
// Set the cursor
|
2008-05-16 12:48:13 +00:00
|
|
|
dit.pos() = pos;
|
2008-02-12 08:04:59 +00:00
|
|
|
setCursor(dit);
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2006-11-13 16:53:49 +00:00
|
|
|
} else {
|
2008-02-12 08:04:59 +00:00
|
|
|
// Switch to other buffer view and resend cmd
|
2010-02-09 14:26:59 +00:00
|
|
|
lyx::dispatch(FuncRequest(
|
2008-02-12 08:04:59 +00:00
|
|
|
LFUN_BUFFER_SWITCH, b->absFileName()));
|
2010-02-09 14:26:59 +00:00
|
|
|
lyx::dispatch(cmd);
|
2006-11-13 16:53:49 +00:00
|
|
|
}
|
2008-02-12 08:04:59 +00:00
|
|
|
break;
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_NOTE_NEXT:
|
2007-10-13 09:04:52 +00:00
|
|
|
gotoInset(this, NOTE_CODE, false);
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_REFERENCE_NEXT: {
|
2007-10-13 09:04:52 +00:00
|
|
|
vector<InsetCode> tmp;
|
|
|
|
tmp.push_back(LABEL_CODE);
|
|
|
|
tmp.push_back(REF_CODE);
|
2007-09-29 07:34:42 +00:00
|
|
|
gotoInset(this, tmp, true);
|
2006-09-16 10:08:51 +00:00
|
|
|
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");
|
2009-01-12 08:01:28 +00:00
|
|
|
bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
|
2007-05-28 22:27:45 +00:00
|
|
|
LaTeXFeatures::isAvailable("xcolor");
|
|
|
|
|
2009-01-12 08:01:28 +00:00
|
|
|
if (!dvipost && !xcolorulem) {
|
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, "
|
2009-01-12 08:01:28 +00:00
|
|
|
"because neither dvipost nor xcolor/ulem are installed.\n"
|
2007-05-28 22:27:45 +00:00
|
|
|
"Please install these packages or redefine "
|
|
|
|
"\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
|
2009-01-12 08:01:28 +00:00
|
|
|
} else if (!xcolorulem) {
|
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 "
|
2009-01-12 08:01:28 +00:00
|
|
|
"when using pdflatex, because xcolor and ulem are not installed.\n"
|
2007-05-28 22:27:45 +00:00
|
|
|
"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);
|
2008-10-24 15:46:44 +00:00
|
|
|
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2006-10-04 21:43:40 +00:00
|
|
|
break;
|
2009-04-05 19:14:37 +00:00
|
|
|
|
|
|
|
case LFUN_CHANGE_PREVIOUS:
|
|
|
|
findPreviousChange(this);
|
|
|
|
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2009-04-05 19:14:37 +00:00
|
|
|
break;
|
2006-10-04 21:43:40 +00:00
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
case LFUN_CHANGES_MERGE:
|
2009-04-05 19:26:26 +00:00
|
|
|
if (findNextChange(this) || findPreviousChange(this)) {
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2006-09-19 13:36:20 +00:00
|
|
|
showDialog("changes");
|
2008-10-24 15:46:44 +00:00
|
|
|
}
|
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
|
2009-10-29 22:46:04 +00:00
|
|
|
cur.reset();
|
2009-04-06 18:25:23 +00:00
|
|
|
cur.selHandle(true);
|
|
|
|
buffer_.text().cursorBottom(cur);
|
2007-02-01 13:19:05 +00:00
|
|
|
// accept everything in a single step to support atomic undo
|
2009-04-06 18:25:23 +00:00
|
|
|
buffer_.text().acceptOrRejectChanges(cur, Text::ACCEPT);
|
2011-04-15 02:01:28 +00:00
|
|
|
cur.resetAnchor();
|
2008-07-11 09:03:09 +00:00
|
|
|
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
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
|
2009-10-29 22:46:04 +00:00
|
|
|
cur.reset();
|
2009-04-06 18:25:23 +00:00
|
|
|
cur.selHandle(true);
|
|
|
|
buffer_.text().cursorBottom(cur);
|
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
|
2009-04-06 18:25:23 +00:00
|
|
|
buffer_.text().acceptOrRejectChanges(cur, Text::REJECT);
|
2011-04-15 02:01:28 +00:00
|
|
|
cur.resetAnchor();
|
2008-07-11 09:03:09 +00:00
|
|
|
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
|
|
|
|
2009-09-09 05:20:30 +00:00
|
|
|
case LFUN_WORD_FIND_FORWARD:
|
|
|
|
case LFUN_WORD_FIND_BACKWARD: {
|
|
|
|
static docstring last_search;
|
|
|
|
docstring searched_string;
|
|
|
|
|
|
|
|
if (!cmd.argument().empty()) {
|
|
|
|
last_search = cmd.argument();
|
|
|
|
searched_string = cmd.argument();
|
|
|
|
} else {
|
|
|
|
searched_string = last_search;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (searched_string.empty())
|
|
|
|
break;
|
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
bool const fw = act == LFUN_WORD_FIND_FORWARD;
|
2009-09-09 05:20:30 +00:00
|
|
|
docstring const data =
|
|
|
|
find2string(searched_string, true, false, fw);
|
2010-10-13 18:53:41 +00:00
|
|
|
bool found = lyxfind(this, FuncRequest(LFUN_WORD_FIND, data));
|
|
|
|
if (found)
|
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2009-09-09 05:20:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-03-26 19:20:17 +00:00
|
|
|
case LFUN_WORD_FIND: {
|
|
|
|
FuncRequest req = cmd;
|
|
|
|
if (cmd.argument().empty() && !d->search_request_cache_.argument().empty())
|
|
|
|
req = d->search_request_cache_;
|
2008-09-26 10:07:10 +00:00
|
|
|
if (req.argument().empty()) {
|
2010-02-09 14:26:59 +00:00
|
|
|
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
|
2008-09-26 10:07:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-10-13 18:53:41 +00:00
|
|
|
if (lyxfind(this, req))
|
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2008-02-10 18:52:32 +00:00
|
|
|
else
|
|
|
|
message(_("String not found!"));
|
2008-03-26 19:20:17 +00:00
|
|
|
d->search_request_cache_ = req;
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
2008-03-26 19:20:17 +00:00
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
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) {
|
2010-10-13 18:58:12 +00:00
|
|
|
if (!cur.inMathed() && cur.paragraph().isDeleted(p)) {
|
2007-06-19 21:48:04 +00:00
|
|
|
has_deleted = true;
|
2010-10-13 18:58:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-19 21:48:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-13 18:53:41 +00:00
|
|
|
if (lyxreplace(this, cmd, has_deleted)) {
|
|
|
|
dr.forceBufferUpdate();
|
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
|
|
|
}
|
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
|
|
|
|
2010-01-04 12:29:38 +00:00
|
|
|
case LFUN_WORD_FINDADV: {
|
|
|
|
FindAndReplaceOptions opt;
|
|
|
|
istringstream iss(to_utf8(cmd.argument()));
|
|
|
|
iss >> opt;
|
2010-11-13 12:02:04 +00:00
|
|
|
if (findAdv(this, opt)) {
|
2010-10-14 15:02:48 +00:00
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2010-11-13 12:02:04 +00:00
|
|
|
cur.dispatched();
|
|
|
|
dispatched = true;
|
|
|
|
} else {
|
|
|
|
cur.undispatched();
|
2010-11-13 11:35:37 +00:00
|
|
|
dispatched = false;
|
2010-11-13 12:02:04 +00:00
|
|
|
}
|
2008-11-16 00:12:21 +00:00
|
|
|
break;
|
2010-01-04 12:29:38 +00:00
|
|
|
}
|
2008-11-16 00:12:21 +00:00
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
case LFUN_MARK_OFF:
|
|
|
|
cur.clearSelection();
|
2010-01-25 15:14:41 +00:00
|
|
|
dr.setMessage(from_utf8(N_("Mark off")));
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_MARK_ON:
|
|
|
|
cur.clearSelection();
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setMark(true);
|
2010-01-25 15:14:41 +00:00
|
|
|
dr.setMessage(from_utf8(N_("Mark on")));
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_MARK_TOGGLE:
|
2009-04-06 18:25:23 +00:00
|
|
|
cur.setSelection(false);
|
2006-09-16 10:08:51 +00:00
|
|
|
if (cur.mark()) {
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setMark(false);
|
2010-01-25 15:14:41 +00:00
|
|
|
dr.setMessage(from_utf8(N_("Mark removed")));
|
2006-09-16 10:08:51 +00:00
|
|
|
} else {
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setMark(true);
|
2010-01-25 15:14:41 +00:00
|
|
|
dr.setMessage(from_utf8(N_("Mark set")));
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
2009-04-06 18:29:19 +00:00
|
|
|
cur.resetAnchor();
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
|
|
|
|
2009-03-26 00:09:16 +00:00
|
|
|
case LFUN_SCREEN_SHOW_CURSOR:
|
2007-12-21 08:35:43 +00:00
|
|
|
showCursor();
|
2006-09-16 10:08:51 +00:00
|
|
|
break;
|
2009-03-26 00:09:16 +00:00
|
|
|
|
|
|
|
case LFUN_SCREEN_RECENTER:
|
|
|
|
recenter();
|
|
|
|
break;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_ADD: {
|
2009-04-06 18:25:23 +00:00
|
|
|
Cursor tmpcur = cur;
|
2007-10-13 09:04:52 +00:00
|
|
|
findInset(tmpcur, BIBTEX_CODE, false);
|
2006-09-16 10:08:51 +00:00
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
2007-10-13 09:04:52 +00:00
|
|
|
BIBTEX_CODE);
|
2006-09-16 10:08:51 +00:00
|
|
|
if (inset) {
|
2010-08-09 17:01:51 +00:00
|
|
|
if (inset->addDatabase(cmd.argument())) {
|
|
|
|
buffer_.invalidateBibfileCache();
|
|
|
|
dr.forceBufferUpdate();
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_DEL: {
|
2009-04-06 18:25:23 +00:00
|
|
|
Cursor tmpcur = cur;
|
2007-10-13 09:04:52 +00:00
|
|
|
findInset(tmpcur, BIBTEX_CODE, false);
|
2006-09-16 10:08:51 +00:00
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
2007-10-13 09:04:52 +00:00
|
|
|
BIBTEX_CODE);
|
2006-09-16 10:08:51 +00:00
|
|
|
if (inset) {
|
2010-08-09 17:01:51 +00:00
|
|
|
if (inset->delDatabase(cmd.argument())) {
|
|
|
|
buffer_.invalidateBibfileCache();
|
|
|
|
dr.forceBufferUpdate();
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-01-08 15:18:00 +00:00
|
|
|
case LFUN_STATISTICS: {
|
2006-09-16 10:08:51 +00:00
|
|
|
DocIterator from, to;
|
|
|
|
if (cur.selection()) {
|
|
|
|
from = cur.selectionBegin();
|
|
|
|
to = cur.selectionEnd();
|
|
|
|
} else {
|
2008-11-17 11:46:07 +00:00
|
|
|
from = doc_iterator_begin(&buffer_);
|
|
|
|
to = doc_iterator_end(&buffer_);
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
2012-01-24 06:20:25 +00:00
|
|
|
buffer_.updateStatistics(from, to);
|
|
|
|
int const words = buffer_.wordCount();
|
|
|
|
int const chars = buffer_.charCount(false);
|
|
|
|
int const chars_blanks = buffer_.charCount(true);
|
2006-09-16 10:08:51 +00:00
|
|
|
docstring message;
|
2008-01-08 15:18:00 +00:00
|
|
|
if (cur.selection())
|
2008-01-18 22:50:19 +00:00
|
|
|
message = _("Statistics for the selection:");
|
2008-01-08 15:18:00 +00:00
|
|
|
else
|
2008-01-18 22:50:19 +00:00
|
|
|
message = _("Statistics for the document:");
|
|
|
|
message += "\n\n";
|
2008-01-08 15:18:00 +00:00
|
|
|
if (words != 1)
|
2008-01-18 22:50:19 +00:00
|
|
|
message += bformat(_("%1$d words"), words);
|
2008-01-08 15:18:00 +00:00
|
|
|
else
|
2008-01-18 22:50:19 +00:00
|
|
|
message += _("One word");
|
|
|
|
message += "\n";
|
2008-01-08 15:18:00 +00:00
|
|
|
if (chars_blanks != 1)
|
2008-01-18 22:50:19 +00:00
|
|
|
message += bformat(_("%1$d characters (including blanks)"),
|
2008-01-08 15:18:00 +00:00
|
|
|
chars_blanks);
|
|
|
|
else
|
2008-01-18 22:50:19 +00:00
|
|
|
message += _("One character (including blanks)");
|
|
|
|
message += "\n";
|
2008-01-08 15:18:00 +00:00
|
|
|
if (chars != 1)
|
2008-01-18 22:50:19 +00:00
|
|
|
message += bformat(_("%1$d characters (excluding blanks)"),
|
2008-01-08 15:18:00 +00:00
|
|
|
chars);
|
|
|
|
else
|
2008-01-18 22:50:19 +00:00
|
|
|
message += _("One character (excluding blanks)");
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2008-01-08 15:18:00 +00:00
|
|
|
Alert::information(_("Statistics"), message);
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
|
|
|
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;
|
2009-05-15 20:54:15 +00:00
|
|
|
|
2010-05-25 11:36:02 +00:00
|
|
|
case LFUN_BUFFER_TOGGLE_OUTPUT_SYNC:
|
|
|
|
buffer_.params().output_sync = !buffer_.params().output_sync;
|
|
|
|
break;
|
|
|
|
|
2007-09-15 12:28:41 +00:00
|
|
|
case LFUN_SCREEN_UP:
|
|
|
|
case LFUN_SCREEN_DOWN: {
|
2010-04-21 13:03:04 +00:00
|
|
|
Point p = getPos(cur);
|
2009-05-15 21:24:08 +00:00
|
|
|
// This code has been commented out to enable to scroll down a
|
|
|
|
// document, even if there are large insets in it (see bug #5465).
|
|
|
|
/*if (p.y_ < 0 || p.y_ > height_) {
|
2007-09-15 14:33:37 +00:00
|
|
|
// The cursor is off-screen so recenter before proceeding.
|
2007-12-21 08:35:43 +00:00
|
|
|
showCursor();
|
2010-04-21 13:03:04 +00:00
|
|
|
p = getPos(cur);
|
2009-05-15 21:24:08 +00:00
|
|
|
}*/
|
2010-04-09 19:00:42 +00:00
|
|
|
int const scrolled = scroll(act == LFUN_SCREEN_UP
|
2009-05-20 19:54:29 +00:00
|
|
|
? -height_ : height_);
|
2010-04-09 19:00:42 +00:00
|
|
|
if (act == LFUN_SCREEN_UP && scrolled > -height_)
|
2008-07-04 11:33:28 +00:00
|
|
|
p = Point(0, 0);
|
2010-04-09 19:00:42 +00:00
|
|
|
if (act == LFUN_SCREEN_DOWN && scrolled < height_)
|
2008-07-04 11:33:28 +00:00
|
|
|
p = Point(width_, height_);
|
2009-03-25 21:00:34 +00:00
|
|
|
Cursor old = cur;
|
2009-03-26 23:08:47 +00:00
|
|
|
bool const in_texted = cur.inTexted();
|
2011-12-16 14:13:31 +00:00
|
|
|
cur.setCursor(doc_iterator_begin(cur.buffer()));
|
|
|
|
cur.selHandle(false);
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(true);
|
2010-03-29 15:21:10 +00:00
|
|
|
updateHoveredInset();
|
|
|
|
|
2009-05-20 20:28:24 +00:00
|
|
|
d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_,
|
2010-04-09 19:00:42 +00:00
|
|
|
true, act == LFUN_SCREEN_UP);
|
2007-09-15 12:28:41 +00:00
|
|
|
//FIXME: what to do with cur.x_target()?
|
2009-03-26 23:08:47 +00:00
|
|
|
bool update = in_texted && cur.bv().checkDepm(cur, old);
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.finishUndo();
|
2011-12-23 09:44:44 +00:00
|
|
|
|
|
|
|
if (update || cur.mark())
|
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
|
|
|
if (update)
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2007-09-15 12:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-12-27 11:37:07 +00:00
|
|
|
case LFUN_SCROLL:
|
|
|
|
lfunScroll(cmd);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2007-12-27 11:37:07 +00:00
|
|
|
break;
|
|
|
|
|
2008-03-06 15:39:30 +00:00
|
|
|
case LFUN_SCREEN_UP_SELECT: {
|
2011-12-23 09:44:44 +00:00
|
|
|
// FIXME: why is the algorithm different from LFUN_SCREEN_UP?
|
2007-09-15 12:28:41 +00:00
|
|
|
cur.selHandle(true);
|
2008-03-06 15:39:30 +00:00
|
|
|
if (isTopScreen()) {
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_BUFFER_BEGIN_SELECT));
|
|
|
|
cur.finishUndo();
|
|
|
|
break;
|
|
|
|
}
|
2010-04-21 13:03:04 +00:00
|
|
|
int y = getPos(cur).y_;
|
2008-03-06 15:39:30 +00:00
|
|
|
int const ymin = y - height_ + defaultRowHeight();
|
|
|
|
while (y > ymin && cur.up())
|
2010-04-21 13:03:04 +00:00
|
|
|
y = getPos(cur).y_;
|
2008-03-06 15:39:30 +00:00
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.finishUndo();
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::SinglePar | Update::FitCursor);
|
2008-03-06 15:39:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_SCREEN_DOWN_SELECT: {
|
2011-12-23 09:44:44 +00:00
|
|
|
// FIXME: why is the algorithm different from LFUN_SCREEN_DOWN?
|
2008-03-06 15:39:30 +00:00
|
|
|
cur.selHandle(true);
|
|
|
|
if (isBottomScreen()) {
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_BUFFER_END_SELECT));
|
|
|
|
cur.finishUndo();
|
|
|
|
break;
|
2007-09-15 12:28:41 +00:00
|
|
|
}
|
2010-04-21 13:03:04 +00:00
|
|
|
int y = getPos(cur).y_;
|
2008-03-06 15:39:30 +00:00
|
|
|
int const ymax = y + height_ - defaultRowHeight();
|
|
|
|
while (y < ymax && cur.down())
|
2010-04-21 13:03:04 +00:00
|
|
|
y = getPos(cur).y_;
|
2008-03-06 15:39:30 +00:00
|
|
|
|
|
|
|
cur.finishUndo();
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::SinglePar | Update::FitCursor);
|
2007-09-15 12:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-07 15:47:58 +00:00
|
|
|
|
|
|
|
// This would be in Buffer class if only Cursor did not
|
|
|
|
// require a bufferview
|
|
|
|
case LFUN_INSET_FORALL: {
|
|
|
|
docstring const name = from_utf8(cmd.getArg(0));
|
|
|
|
string const commandstr = cmd.getLongArg(1);
|
|
|
|
FuncRequest const fr = lyxaction.lookupFunc(commandstr);
|
|
|
|
|
|
|
|
// an arbitrary number to limit number of iterations
|
2011-12-15 22:06:04 +00:00
|
|
|
const int max_iter = 100000;
|
2010-01-07 15:47:58 +00:00
|
|
|
int iterations = 0;
|
|
|
|
Cursor & cur = d->cursor_;
|
2010-01-08 15:57:25 +00:00
|
|
|
Cursor const savecur = cur;
|
2010-01-07 15:47:58 +00:00
|
|
|
cur.reset();
|
|
|
|
if (!cur.nextInset())
|
|
|
|
cur.forwardInset();
|
|
|
|
cur.beginUndoGroup();
|
|
|
|
while(cur && iterations < max_iter) {
|
2013-01-23 22:02:05 +00:00
|
|
|
Inset * const ins = cur.nextInset();
|
2010-01-07 15:47:58 +00:00
|
|
|
if (!ins)
|
|
|
|
break;
|
2011-03-28 22:33:04 +00:00
|
|
|
docstring insname = ins->layoutName();
|
2010-01-07 15:47:58 +00:00
|
|
|
while (!insname.empty()) {
|
|
|
|
if (insname == name || name == from_utf8("*")) {
|
|
|
|
cur.recordUndo();
|
2010-04-08 12:39:41 +00:00
|
|
|
lyx::dispatch(fr, dr);
|
2010-01-07 15:47:58 +00:00
|
|
|
++iterations;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
size_t const i = insname.rfind(':');
|
|
|
|
if (i == string::npos)
|
|
|
|
break;
|
|
|
|
insname = insname.substr(0, i);
|
|
|
|
}
|
2013-01-23 22:02:05 +00:00
|
|
|
// if we did not delete the inset, skip it
|
|
|
|
if (!cur.nextInset() || cur.nextInset() == ins)
|
|
|
|
cur.forwardInset();
|
2010-01-07 15:47:58 +00:00
|
|
|
}
|
|
|
|
cur.endUndoGroup();
|
2010-01-08 15:57:25 +00:00
|
|
|
cur = savecur;
|
|
|
|
cur.fixIfBroken();
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::Force);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2010-01-07 15:47:58 +00:00
|
|
|
|
2010-01-25 15:14:41 +00:00
|
|
|
if (iterations >= max_iter) {
|
|
|
|
dr.setError(true);
|
|
|
|
dr.setMessage(bformat(_("`inset-forall' interrupted because number of actions is larger than %1$d"), max_iter));
|
|
|
|
} else
|
|
|
|
dr.setMessage(bformat(_("Applied \"%1$s\" to %2$d insets"), from_utf8(commandstr), iterations));
|
2010-01-07 15:47:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-11 09:38:31 +00:00
|
|
|
case LFUN_BRANCH_ADD_INSERT: {
|
|
|
|
docstring branch_name = from_utf8(cmd.getArg(0));
|
|
|
|
if (branch_name.empty())
|
|
|
|
if (!Alert::askForText(branch_name, _("Branch name")) ||
|
|
|
|
branch_name.empty())
|
|
|
|
break;
|
|
|
|
|
|
|
|
DispatchResult drtmp;
|
|
|
|
buffer_.dispatch(FuncRequest(LFUN_BRANCH_ADD, branch_name), drtmp);
|
|
|
|
if (drtmp.error()) {
|
|
|
|
Alert::warning(_("Branch already exists"), drtmp.message());
|
|
|
|
break;
|
|
|
|
}
|
2010-06-14 13:39:08 +00:00
|
|
|
BranchList & branch_list = buffer_.params().branchlist();
|
|
|
|
vector<docstring> const branches =
|
|
|
|
getVectorFromString(branch_name, branch_list.separator());
|
|
|
|
for (vector<docstring>::const_iterator it = branches.begin();
|
|
|
|
it != branches.end(); ++it) {
|
|
|
|
branch_name = *it;
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_BRANCH_INSERT, branch_name));
|
|
|
|
}
|
2009-07-11 09:38:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-19 16:59:36 +00:00
|
|
|
case LFUN_KEYMAP_OFF:
|
|
|
|
getIntl().keyMapOn(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_KEYMAP_PRIMARY:
|
|
|
|
getIntl().keyMapPrim();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_KEYMAP_SECONDARY:
|
|
|
|
getIntl().keyMapSec();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_KEYMAP_TOGGLE:
|
|
|
|
getIntl().toggleKeyMap();
|
|
|
|
break;
|
2009-07-11 09:38:31 +00:00
|
|
|
|
2009-09-26 17:19:18 +00:00
|
|
|
case LFUN_DIALOG_SHOW_NEW_INSET: {
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
string data = trim(to_utf8(cmd.argument()).substr(name.size()));
|
|
|
|
if (decodeInsetParam(name, data, buffer_))
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
|
|
|
|
else
|
|
|
|
lyxerr << "Inset type '" << name <<
|
|
|
|
"' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-26 17:30:29 +00:00
|
|
|
case LFUN_CITATION_INSERT: {
|
|
|
|
if (argument.empty()) {
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// we can have one optional argument, delimited by '|'
|
|
|
|
// citation-insert <key>|<text_before>
|
|
|
|
// this should be enhanced to also support text_after
|
|
|
|
// and citation style
|
|
|
|
string arg = argument;
|
|
|
|
string opt1;
|
|
|
|
if (contains(argument, "|")) {
|
|
|
|
arg = token(argument, '|', 0);
|
|
|
|
opt1 = token(argument, '|', 1);
|
|
|
|
}
|
|
|
|
InsetCommandParams icp(CITE_CODE);
|
|
|
|
icp["key"] = from_utf8(arg);
|
|
|
|
if (!opt1.empty())
|
|
|
|
icp["before"] = from_utf8(opt1);
|
2010-10-29 00:25:28 +00:00
|
|
|
string icstr = InsetCommand::params2string(icp);
|
2009-09-26 17:30:29 +00:00
|
|
|
FuncRequest fr(LFUN_INSET_INSERT, icstr);
|
|
|
|
lyx::dispatch(fr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-27 10:29:13 +00:00
|
|
|
case LFUN_INSET_APPLY: {
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
Inset * inset = editedInset(name);
|
|
|
|
if (!inset) {
|
|
|
|
FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
|
|
|
|
lyx::dispatch(fr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// put cursor in front of inset.
|
2009-09-30 13:50:07 +00:00
|
|
|
if (!setCursorFromInset(inset)) {
|
2009-09-27 10:29:13 +00:00
|
|
|
LASSERT(false, break);
|
2009-09-30 13:50:07 +00:00
|
|
|
}
|
2009-09-27 10:29:13 +00:00
|
|
|
cur.recordUndo();
|
|
|
|
FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
|
|
|
|
inset->dispatch(cur, fr);
|
2010-10-13 18:06:01 +00:00
|
|
|
dr.screenUpdate(cur.result().screenUpdate());
|
|
|
|
if (cur.result().needBufferUpdate())
|
|
|
|
dr.forceBufferUpdate();
|
2009-09-27 10:29:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-05 18:41:39 +00:00
|
|
|
case LFUN_BUFFER_LANGUAGE: {
|
|
|
|
Language const * oldL = buffer_.params().language;
|
|
|
|
Language const * newL = languages.getLanguage(argument);
|
|
|
|
if (!newL || oldL == newL)
|
|
|
|
break;
|
2011-09-21 15:48:51 +00:00
|
|
|
if (oldL->rightToLeft() == newL->rightToLeft()) {
|
2011-09-05 18:41:39 +00:00
|
|
|
cur.recordUndoFullDocument();
|
|
|
|
buffer_.changeLanguage(oldL, newL);
|
2011-09-05 18:46:46 +00:00
|
|
|
cur.setCurrentFont();
|
2011-09-05 18:41:39 +00:00
|
|
|
dr.forceBufferUpdate();
|
|
|
|
}
|
2012-04-15 18:28:09 +00:00
|
|
|
break;
|
2012-03-05 22:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
|
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT: {
|
|
|
|
bool const as_paragraph = (act == LFUN_FILE_INSERT_PLAINTEXT_PARA);
|
|
|
|
string const fname = to_utf8(cmd.argument());
|
|
|
|
if (!FileName::isAbsolute(fname))
|
|
|
|
dr.setMessage(_("Absolute filename expected."));
|
|
|
|
else
|
|
|
|
insertPlaintextFile(FileName(fname), as_paragraph);
|
2011-09-05 18:41:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-02 21:30:40 +00:00
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
default:
|
2010-12-05 01:18:32 +00:00
|
|
|
// OK, so try the Buffer itself...
|
|
|
|
buffer_.dispatch(cmd, dr);
|
|
|
|
dispatched = dr.dispatched();
|
2009-10-03 19:12:21 +00:00
|
|
|
break;
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-06 13:32:58 +00:00
|
|
|
buffer_.undo().endUndoGroup();
|
2010-01-25 15:14:41 +00:00
|
|
|
dr.dispatched(dispatched);
|
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-10-13 07:33:07 +00:00
|
|
|
Cursor & cur = d->cursor_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2008-07-20 20:16:33 +00:00
|
|
|
LYXERR(Debug::SELECTION, "requestSelection: cur.selection: " << cur.selection());
|
2006-09-16 10:08:51 +00:00
|
|
|
if (!cur.selection()) {
|
2007-10-13 07:33:07 +00:00
|
|
|
d->xsel_cache_.set = false;
|
2006-09-17 08:35:12 +00:00
|
|
|
return docstring();
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
|
|
|
|
2008-07-15 00:33:37 +00:00
|
|
|
LYXERR(Debug::SELECTION, "requestSelection: xsel_cache.set: " << d->xsel_cache_.set);
|
2007-10-13 07:33:07 +00:00
|
|
|
if (!d->xsel_cache_.set ||
|
|
|
|
cur.top() != d->xsel_cache_.cursor ||
|
2010-04-15 18:16:07 +00:00
|
|
|
cur.realAnchor().top() != d->xsel_cache_.anchor)
|
2006-09-16 10:08:51 +00:00
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
d->xsel_cache_.cursor = cur.top();
|
2010-04-15 18:16:07 +00:00
|
|
|
d->xsel_cache_.anchor = cur.realAnchor().top();
|
2007-10-13 07:33:07 +00:00
|
|
|
d->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-10-13 07:33:07 +00:00
|
|
|
d->cursor_.clearSelection();
|
2007-08-21 07:33:46 +00:00
|
|
|
// Clear the selection buffer. Otherwise a subsequent
|
|
|
|
// middle-mouse-button paste would use the selection buffer,
|
|
|
|
// not the more current external selection.
|
|
|
|
cap::clearSelection();
|
2007-10-13 07:33:07 +00:00
|
|
|
d->xsel_cache_.set = false;
|
2007-08-21 07:33:46 +00:00
|
|
|
// The buffer did not really change, but this causes the
|
|
|
|
// redraw we need because we cleared the selection above.
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(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-08-24 07:05:19 +00:00
|
|
|
void BufferView::resize(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-12-21 08:28:18 +00:00
|
|
|
// Clear the paragraph height cache.
|
|
|
|
d->par_height_.clear();
|
2008-02-20 14:53:19 +00:00
|
|
|
// Redo the metrics.
|
2007-11-06 08:32:25 +00:00
|
|
|
updateMetrics();
|
* 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-12-25 18:53:38 +00:00
|
|
|
Inset const * BufferView::getCoveringInset(Text const & text,
|
|
|
|
int x, int y) const
|
2007-03-28 14:47:52 +00:00
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
TextMetrics & tm = d->text_metrics_[&text];
|
2007-09-21 20:39:47 +00:00
|
|
|
Inset * inset = tm.checkInsetHit(x, y);
|
|
|
|
if (!inset)
|
|
|
|
return 0;
|
|
|
|
|
2009-10-24 00:02:41 +00:00
|
|
|
if (!inset->descendable(*this))
|
2007-09-21 20:39:47 +00:00
|
|
|
// No need to go further down if the inset is not
|
|
|
|
// descendable.
|
|
|
|
return inset;
|
|
|
|
|
|
|
|
size_t cell_number = inset->nargs();
|
|
|
|
// Check all the inner cell.
|
|
|
|
for (size_t i = 0; i != cell_number; ++i) {
|
|
|
|
Text const * inner_text = inset->getText(i);
|
|
|
|
if (inner_text) {
|
|
|
|
// Try deeper.
|
|
|
|
Inset const * inset_deeper =
|
|
|
|
getCoveringInset(*inner_text, x, y);
|
|
|
|
if (inset_deeper)
|
|
|
|
return inset_deeper;
|
2007-03-28 14:47:52 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-21 20:39:47 +00:00
|
|
|
|
|
|
|
return inset;
|
2007-03-28 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-29 15:21:10 +00:00
|
|
|
void BufferView::updateHoveredInset() const
|
|
|
|
{
|
|
|
|
// Get inset under mouse, if there is one.
|
2010-10-24 21:41:47 +00:00
|
|
|
int const x = d->mouse_position_cache_.x_;
|
|
|
|
int const y = d->mouse_position_cache_.y_;
|
|
|
|
Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
|
|
|
|
|
|
|
|
d->clickable_inset_ = covering_inset && covering_inset->clickable(x, y);
|
|
|
|
|
2010-03-29 15:21:10 +00:00
|
|
|
if (covering_inset == d->last_inset_)
|
|
|
|
// Same inset, no need to do anything...
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool need_redraw = false;
|
2010-05-02 19:12:25 +00:00
|
|
|
if (d->last_inset_) {
|
2010-03-29 15:21:10 +00:00
|
|
|
// Remove the hint on the last hovered inset (if any).
|
2010-04-30 14:47:46 +00:00
|
|
|
need_redraw |= d->last_inset_->setMouseHover(this, false);
|
2010-05-02 19:12:25 +00:00
|
|
|
d->last_inset_ = 0;
|
|
|
|
}
|
2010-03-29 15:21:10 +00:00
|
|
|
|
2011-02-13 10:07:00 +00:00
|
|
|
if (covering_inset && covering_inset->setMouseHover(this, true)) {
|
2010-05-02 19:12:25 +00:00
|
|
|
need_redraw = true;
|
|
|
|
// Only the insets that accept the hover state, do
|
|
|
|
// clear the last_inset_, so only set the last_inset_
|
|
|
|
// member if the hovered setting is accepted.
|
2011-02-13 10:07:00 +00:00
|
|
|
d->last_inset_ = covering_inset;
|
2010-05-02 19:12:25 +00:00
|
|
|
}
|
2010-03-29 15:21:10 +00:00
|
|
|
|
|
|
|
if (need_redraw) {
|
|
|
|
LYXERR(Debug::PAINTING, "Mouse hover detected at: ("
|
|
|
|
<< d->mouse_position_cache_.x_ << ", "
|
|
|
|
<< d->mouse_position_cache_.y_ << ")");
|
|
|
|
|
|
|
|
d->update_strategy_ = DecorationUpdate;
|
|
|
|
|
|
|
|
// This event (moving without mouse click) is not passed further.
|
|
|
|
// This should be changed if it is further utilized.
|
|
|
|
buffer_.changed(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-30 14:55:37 +00:00
|
|
|
void BufferView::clearLastInset(Inset * inset) const
|
|
|
|
{
|
|
|
|
if (d->last_inset_ != inset) {
|
|
|
|
LYXERR0("Wrong last_inset!");
|
|
|
|
LASSERT(false, /**/);
|
|
|
|
}
|
|
|
|
d->last_inset_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 09:38:40 +00:00
|
|
|
void BufferView::mouseEventDispatch(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
|
|
|
{
|
2007-11-30 08:35:54 +00:00
|
|
|
//lyxerr << "[ cmd0 " << cmd0 << "]" << endl;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
// This is only called for mouse related events including
|
|
|
|
// LFUN_FILE_OPEN generated by drag-and-drop.
|
|
|
|
FuncRequest cmd = cmd0;
|
|
|
|
|
2008-02-22 20:45:18 +00:00
|
|
|
Cursor old = cursor();
|
2007-04-26 14:56:30 +00:00
|
|
|
Cursor cur(*this);
|
2007-08-21 07:33:46 +00:00
|
|
|
cur.push(buffer_.inset());
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setSelection(d->cursor_.selection());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
// 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...
|
2010-04-09 19:00:42 +00:00
|
|
|
cmd.set_y(min(max(cmd.y(), -1), height_));
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
d->mouse_position_cache_.x_ = cmd.x();
|
|
|
|
d->mouse_position_cache_.y_ = cmd.y();
|
2006-12-07 11:46:27 +00:00
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
if (cmd.action() == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::none) {
|
2010-03-29 15:21:10 +00:00
|
|
|
updateHoveredInset();
|
2007-10-05 09:38:40 +00:00
|
|
|
return;
|
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.
|
2010-04-09 19:00:42 +00:00
|
|
|
Inset * inset = d->text_metrics_[&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();
|
|
|
|
|
2008-09-18 13:44:54 +00:00
|
|
|
cur.beginUndoGroup();
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
// 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)
|
2007-10-05 09:38:40 +00:00
|
|
|
if (inset)
|
2006-09-16 10:08:51 +00:00
|
|
|
inset->dispatch(cur, cmd);
|
|
|
|
|
|
|
|
// Now dispatch to the temporary cursor. If the real cursor should
|
|
|
|
// be modified, the inset's dispatch has to do so explicitly.
|
2008-03-24 18:22:54 +00:00
|
|
|
if (!inset || !cur.result().dispatched())
|
2006-09-16 10:08:51 +00:00
|
|
|
cur.dispatch(cmd);
|
|
|
|
|
2008-09-18 13:44:54 +00:00
|
|
|
cur.endUndoGroup();
|
|
|
|
|
2008-02-22 20:45:18 +00:00
|
|
|
// Notify left insets
|
|
|
|
if (cur != old) {
|
2012-05-23 06:02:40 +00:00
|
|
|
bool badcursor = old.fixIfBroken() | cur.fixIfBroken();
|
|
|
|
badcursor |= notifyCursorLeavesOrEnters(old, cur);
|
2008-02-22 20:45:18 +00:00
|
|
|
if (badcursor)
|
|
|
|
cursor().fixIfBroken();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have a selection?
|
2007-08-10 10:21:09 +00:00
|
|
|
theSelection().haveSelection(cursor().selection());
|
|
|
|
|
2011-05-09 18:23:54 +00:00
|
|
|
if (cur.needBufferUpdate()) {
|
|
|
|
cur.clearBufferUpdate();
|
|
|
|
buffer().updateBuffer();
|
|
|
|
}
|
|
|
|
|
2007-10-05 09:38:40 +00:00
|
|
|
// If the command has been dispatched,
|
2010-10-13 17:28:55 +00:00
|
|
|
if (cur.result().dispatched() || cur.result().screenUpdate())
|
|
|
|
processUpdateFlags(cur.result().screenUpdate());
|
* 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-12-27 11:37:07 +00:00
|
|
|
void BufferView::lfunScroll(FuncRequest const & cmd)
|
|
|
|
{
|
|
|
|
string const scroll_type = cmd.getArg(0);
|
2010-03-29 15:32:45 +00:00
|
|
|
int scroll_step = 0;
|
|
|
|
if (scroll_type == "line")
|
|
|
|
scroll_step = d->scrollbarParameters_.single_step;
|
|
|
|
else if (scroll_type == "page")
|
|
|
|
scroll_step = d->scrollbarParameters_.page_step;
|
|
|
|
else
|
2007-12-27 11:37:07 +00:00
|
|
|
return;
|
|
|
|
string const scroll_quantity = cmd.getArg(1);
|
|
|
|
if (scroll_quantity == "up")
|
|
|
|
scrollUp(scroll_step);
|
|
|
|
else if (scroll_quantity == "down")
|
|
|
|
scrollDown(scroll_step);
|
|
|
|
else {
|
|
|
|
int const scroll_value = convert<int>(scroll_quantity);
|
|
|
|
if (scroll_value)
|
|
|
|
scroll(scroll_step * scroll_value);
|
|
|
|
}
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(true);
|
2010-03-29 15:21:10 +00:00
|
|
|
updateHoveredInset();
|
2007-12-27 11:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-27 17:41:58 +00:00
|
|
|
int BufferView::minVisiblePart()
|
|
|
|
{
|
|
|
|
return 2 * defaultRowHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-04 11:33:28 +00:00
|
|
|
int BufferView::scroll(int y)
|
2002-08-28 10:45:38 +00:00
|
|
|
{
|
2007-09-15 12:28:41 +00:00
|
|
|
if (y > 0)
|
2008-07-04 11:33:28 +00:00
|
|
|
return scrollDown(y);
|
|
|
|
if (y < 0)
|
|
|
|
return scrollUp(-y);
|
|
|
|
return 0;
|
2007-09-15 12:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-04 11:33:28 +00:00
|
|
|
int BufferView::scrollDown(int offset)
|
2007-09-15 12:28:41 +00:00
|
|
|
{
|
|
|
|
Text * text = &buffer_.text();
|
2007-10-13 07:33:07 +00:00
|
|
|
TextMetrics & tm = d->text_metrics_[text];
|
2009-03-27 17:41:58 +00:00
|
|
|
int const ymax = height_ + offset;
|
2007-09-15 12:28:41 +00:00
|
|
|
while (true) {
|
2007-12-12 19:28:07 +00:00
|
|
|
pair<pit_type, ParagraphMetrics const *> last = tm.last();
|
2007-09-20 08:48:28 +00:00
|
|
|
int bottom_pos = last.second->position() + last.second->descent();
|
2009-03-27 17:41:58 +00:00
|
|
|
if (lyxrc.scroll_below_document)
|
|
|
|
bottom_pos += height_ - minVisiblePart();
|
2007-09-29 07:34:42 +00:00
|
|
|
if (last.first + 1 == int(text->paragraphs().size())) {
|
2007-09-15 12:28:41 +00:00
|
|
|
if (bottom_pos <= height_)
|
2008-07-04 11:33:28 +00:00
|
|
|
return 0;
|
2007-09-15 12:28:41 +00:00
|
|
|
offset = min(offset, bottom_pos - height_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bottom_pos > ymax)
|
|
|
|
break;
|
|
|
|
tm.newParMetricsDown();
|
|
|
|
}
|
2007-12-21 08:28:18 +00:00
|
|
|
d->anchor_ypos_ -= offset;
|
2008-07-04 11:33:28 +00:00
|
|
|
return -offset;
|
2007-09-15 12:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-04 11:33:28 +00:00
|
|
|
int BufferView::scrollUp(int offset)
|
2007-09-15 12:28:41 +00:00
|
|
|
{
|
|
|
|
Text * text = &buffer_.text();
|
2007-10-13 07:33:07 +00:00
|
|
|
TextMetrics & tm = d->text_metrics_[text];
|
2007-09-15 12:28:41 +00:00
|
|
|
int ymin = - offset;
|
|
|
|
while (true) {
|
2007-12-12 19:28:07 +00:00
|
|
|
pair<pit_type, ParagraphMetrics const *> first = tm.first();
|
2007-09-20 08:48:28 +00:00
|
|
|
int top_pos = first.second->position() - first.second->ascent();
|
2007-09-15 12:28:41 +00:00
|
|
|
if (first.first == 0) {
|
|
|
|
if (top_pos >= 0)
|
2008-07-04 11:33:28 +00:00
|
|
|
return 0;
|
2007-09-15 12:28:41 +00:00
|
|
|
offset = min(offset, - top_pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (top_pos < ymin)
|
|
|
|
break;
|
|
|
|
tm.newParMetricsUp();
|
|
|
|
}
|
2007-12-21 08:28:18 +00:00
|
|
|
d->anchor_ypos_ += offset;
|
2008-07-04 11:33:28 +00:00
|
|
|
return offset;
|
2002-08-28 10:45:38 +00:00
|
|
|
}
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
void BufferView::setCursorFromRow(int row)
|
|
|
|
{
|
2011-05-27 20:40:43 +00:00
|
|
|
int tmpid;
|
|
|
|
int tmppos;
|
|
|
|
pit_type newpit = 0;
|
|
|
|
pos_type newpos = 0;
|
2002-08-29 13:05:55 +00:00
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
buffer_.texrow().getIdFromRow(row, tmpid, tmppos);
|
2002-08-29 13:05:55 +00:00
|
|
|
|
2011-05-27 20:40:43 +00:00
|
|
|
bool posvalid = (tmpid != -1);
|
|
|
|
if (posvalid) {
|
|
|
|
// we need to make sure that the row and position
|
|
|
|
// we got back are valid, because the buffer may well
|
|
|
|
// have changed since we last generated the LaTeX.
|
|
|
|
DocIterator const dit = buffer_.getParFromID(tmpid);
|
|
|
|
if (dit == doc_iterator_end(&buffer_))
|
|
|
|
posvalid = false;
|
|
|
|
else {
|
|
|
|
newpit = dit.pit();
|
|
|
|
// now have to check pos.
|
|
|
|
newpos = tmppos;
|
|
|
|
Paragraph const & par = buffer_.text().getPar(newpit);
|
|
|
|
if (newpos > par.size()) {
|
|
|
|
LYXERR0("Requested position no longer valid.");
|
|
|
|
newpos = par.size() - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!posvalid) {
|
|
|
|
frontend::Alert::error(_("Inverse Search Failed"),
|
|
|
|
_("Invalid position requested by inverse search.\n"
|
|
|
|
"You need to update the viewed document."));
|
|
|
|
return;
|
|
|
|
}
|
2009-10-29 22:46:04 +00:00
|
|
|
d->cursor_.reset();
|
2011-05-27 20:40:43 +00:00
|
|
|
buffer_.text().setCursor(d->cursor_, newpit, newpos);
|
2011-04-14 22:44:46 +00:00
|
|
|
d->cursor_.setSelection(false);
|
|
|
|
d->cursor_.resetAnchor();
|
2009-09-23 13:45:58 +00:00
|
|
|
recenter();
|
2002-08-29 13:05:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-17 14:51:27 +00:00
|
|
|
bool BufferView::setCursorFromInset(Inset const * inset)
|
|
|
|
{
|
|
|
|
// are we already there?
|
2008-09-30 13:47:16 +00:00
|
|
|
if (cursor().nextInset() == inset)
|
2008-09-17 14:51:27 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Inset is not at cursor position. Find it in the document.
|
|
|
|
Cursor cur(*this);
|
2009-10-29 22:46:04 +00:00
|
|
|
cur.reset();
|
2008-09-30 13:47:16 +00:00
|
|
|
while (cur && cur.nextInset() != inset)
|
2008-09-17 14:51:27 +00:00
|
|
|
cur.forwardInset();
|
|
|
|
|
|
|
|
if (cur) {
|
|
|
|
setCursor(cur);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-12 10:50:45 +00:00
|
|
|
void BufferView::gotoLabel(docstring const & label)
|
2002-08-29 13:05:55 +00:00
|
|
|
{
|
2010-09-29 11:55:10 +00:00
|
|
|
ListOfBuffers bufs = buffer().allRelatives();
|
|
|
|
ListOfBuffers::iterator it = bufs.begin();
|
2008-11-16 21:28:06 +00:00
|
|
|
for (; it != bufs.end(); ++it) {
|
|
|
|
Buffer const * buf = *it;
|
|
|
|
|
|
|
|
// find label
|
|
|
|
Toc & toc = buf->tocBackend().toc("label");
|
|
|
|
TocIterator toc_it = toc.begin();
|
|
|
|
TocIterator end = toc.end();
|
|
|
|
for (; toc_it != end; ++toc_it) {
|
|
|
|
if (label == toc_it->str()) {
|
2010-01-25 15:14:41 +00:00
|
|
|
lyx::dispatch(toc_it->action());
|
2008-11-16 21:28:06 +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
|
|
|
{
|
2011-03-13 16:26:57 +00:00
|
|
|
LASSERT(t, /**/);
|
2007-10-13 07:33:07 +00:00
|
|
|
TextMetricsCache::iterator tmc_it = d->text_metrics_.find(t);
|
|
|
|
if (tmc_it == d->text_metrics_.end()) {
|
|
|
|
tmc_it = d->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
|
|
|
{
|
2009-10-29 22:46:04 +00:00
|
|
|
d->cursor_.reset();
|
2005-02-22 11:41:22 +00:00
|
|
|
size_t const n = dit.depth();
|
|
|
|
for (size_t i = 0; i < n; ++i)
|
2007-10-13 07:33:07 +00:00
|
|
|
dit[i].inset().edit(d->cursor_, true);
|
2004-03-31 17:58:11 +00:00
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
d->cursor_.setCursor(dit);
|
2008-09-24 21:27:41 +00:00
|
|
|
d->cursor_.setSelection(false);
|
2011-04-15 02:26:22 +00:00
|
|
|
// FIXME
|
|
|
|
// It seems on general grounds as if this is probably needed, but
|
|
|
|
// it is not yet clear.
|
|
|
|
// See bug #7394 and r38388.
|
|
|
|
// d->cursor.resetAnchor();
|
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;
|
2007-10-13 07:33:07 +00:00
|
|
|
bool changed = d->cursor_.text()->deleteEmptyParagraphMechanism(cur, old,
|
2006-12-30 15:05:15 +00:00
|
|
|
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-12-27 10:39:25 +00:00
|
|
|
d->cursor_ = cur;
|
|
|
|
|
2011-12-03 22:43:12 +00:00
|
|
|
// we would rather not do this here, but it needs to be done before
|
|
|
|
// the changed() signal is sent. a riskier strategy has been tried
|
|
|
|
// in trunk (at r).
|
|
|
|
buffer_.updateBuffer();
|
|
|
|
// if it was requested, we've already done it
|
|
|
|
cur.clearBufferUpdate();
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(true);
|
2006-12-30 15:05:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 14:46:53 +00:00
|
|
|
bool BufferView::mouseSetCursor(Cursor & cur, bool select)
|
2005-12-01 10:28:50 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(&cur.bv() == this, /**/);
|
2005-12-01 10:28:50 +00:00
|
|
|
|
2007-10-11 14:46:53 +00:00
|
|
|
if (!select)
|
|
|
|
// this event will clear selection so we save selection for
|
|
|
|
// persistent selection
|
|
|
|
cap::saveSelection(cursor());
|
2007-07-10 12:44:19 +00:00
|
|
|
|
2009-10-27 00:11:56 +00:00
|
|
|
d->cursor_.macroModeClose();
|
2012-09-23 14:44:22 +00:00
|
|
|
// If a macro has been finalized, the cursor might have been broken
|
|
|
|
cur.fixIfBroken();
|
2009-10-27 00:11:56 +00:00
|
|
|
|
2005-12-01 10:28:50 +00:00
|
|
|
// Has the cursor just left the inset?
|
2011-04-14 20:34:18 +00:00
|
|
|
bool const leftinset = (&d->cursor_.inset() != &cur.inset());
|
2008-11-15 17:11:01 +00:00
|
|
|
if (leftinset)
|
2008-02-22 20:45:18 +00:00
|
|
|
d->cursor_.fixIfBroken();
|
2005-12-01 10:28:50 +00:00
|
|
|
|
2007-10-11 14:46:53 +00:00
|
|
|
// FIXME: shift-mouse selection doesn't work well across insets.
|
2011-04-14 20:34:18 +00:00
|
|
|
bool const do_selection =
|
|
|
|
select && &d->cursor_.normalAnchor().inset() == &cur.inset();
|
2007-10-11 14:46:53 +00:00
|
|
|
|
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;
|
2008-11-15 17:11:01 +00:00
|
|
|
if (!do_selection && d->cursor_.inTexted())
|
2007-10-13 07:33:07 +00:00
|
|
|
update |= checkDepm(cur, d->cursor_);
|
2005-12-01 10:28:50 +00:00
|
|
|
|
2009-12-18 12:08:32 +00:00
|
|
|
if (!do_selection)
|
|
|
|
d->cursor_.resetAnchor();
|
2008-02-22 20:45:18 +00:00
|
|
|
d->cursor_.setCursor(cur);
|
2007-10-13 07:33:07 +00:00
|
|
|
d->cursor_.boundary(cur.boundary());
|
2007-10-11 14:46:53 +00:00
|
|
|
if (do_selection)
|
2007-10-13 07:33:07 +00:00
|
|
|
d->cursor_.setSelection();
|
2007-10-11 14:46:53 +00:00
|
|
|
else
|
2007-10-13 07:33:07 +00:00
|
|
|
d->cursor_.clearSelection();
|
2007-10-11 14:46:53 +00:00
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
d->cursor_.finishUndo();
|
2007-10-29 18:57:56 +00:00
|
|
|
d->cursor_.setCurrentFont();
|
2010-07-09 14:37:00 +00:00
|
|
|
if (update)
|
|
|
|
cur.forceBufferUpdate();
|
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
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
d->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) {
|
2007-10-13 07:33:07 +00:00
|
|
|
d->cursor_.pos() += length;
|
|
|
|
d->cursor_.setSelection(d->cursor_, -length);
|
2004-03-31 17:58:11 +00:00
|
|
|
} else
|
2007-10-13 07:33:07 +00:00
|
|
|
d->cursor_.setSelection(d->cursor_, length);
|
2004-01-14 17:21:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-15 11:58:35 +00:00
|
|
|
|
2011-03-19 10:34:59 +00:00
|
|
|
bool BufferView::selectIfEmpty(DocIterator & cur)
|
|
|
|
{
|
2014-03-22 11:09:18 +00:00
|
|
|
if ((cur.inTexted() && !cur.paragraph().empty())
|
2014-03-22 11:22:41 +00:00
|
|
|
|| (cur.inMathed() && !cur.cell().empty()))
|
2011-03-19 10:34:59 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
pit_type const beg_pit = cur.pit();
|
|
|
|
if (beg_pit > 0) {
|
|
|
|
// The paragraph associated to this item isn't
|
|
|
|
// the first one, so it can be selected
|
|
|
|
cur.backwardPos();
|
|
|
|
} else {
|
|
|
|
// We have to resort to select the space between the
|
|
|
|
// end of this item and the begin of the next one
|
|
|
|
cur.forwardPos();
|
|
|
|
}
|
|
|
|
if (cur.empty()) {
|
|
|
|
// If it is the only item in the document,
|
|
|
|
// nothing can be selected
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pit_type const end_pit = cur.pit();
|
|
|
|
pos_type const end_pos = cur.pos();
|
|
|
|
d->cursor_.clearSelection();
|
|
|
|
d->cursor_.reset();
|
|
|
|
d->cursor_.setCursor(cur);
|
|
|
|
d->cursor_.pit() = beg_pit;
|
|
|
|
d->cursor_.pos() = 0;
|
|
|
|
d->cursor_.setSelection(false);
|
|
|
|
d->cursor_.resetAnchor();
|
|
|
|
d->cursor_.pit() = end_pit;
|
|
|
|
d->cursor_.pos() = end_pos;
|
|
|
|
d->cursor_.setSelection();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
Cursor & BufferView::cursor()
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
return d->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
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
return d->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
|
|
|
{
|
2007-12-21 08:28:18 +00:00
|
|
|
return d->anchor_pit_;
|
2004-11-30 01:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-28 09:11:24 +00:00
|
|
|
bool BufferView::singleParUpdate()
|
|
|
|
{
|
|
|
|
Text & buftext = buffer_.text();
|
2007-10-13 07:33:07 +00:00
|
|
|
pit_type const bottom_pit = d->cursor_.bottom().pit();
|
2007-09-28 09:11:24 +00:00
|
|
|
TextMetrics & tm = textMetrics(&buftext);
|
|
|
|
int old_height = tm.parMetrics(bottom_pit).height();
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
// make sure inline completion pointer is ok
|
2008-04-16 20:43:30 +00:00
|
|
|
if (d->inlineCompletionPos_.fixIfBroken())
|
|
|
|
d->inlineCompletionPos_ = DocIterator();
|
2008-02-21 19:42:34 +00:00
|
|
|
|
2007-09-28 09:11:24 +00:00
|
|
|
// 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(bottom_pit);
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(bottom_pit);
|
|
|
|
if (pm.height() != old_height)
|
|
|
|
// Paragraph height has changed so we cannot proceed to
|
|
|
|
// the singlePar optimisation.
|
|
|
|
return false;
|
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
d->update_strategy_ = SingleParUpdate;
|
|
|
|
|
2007-11-30 08:35:54 +00:00
|
|
|
LYXERR(Debug::PAINTING, "\ny1: " << pm.position() - pm.ascent()
|
2007-11-17 11:27:03 +00:00
|
|
|
<< " y2: " << pm.position() + pm.descent()
|
2007-09-28 09:11:24 +00:00
|
|
|
<< " pit: " << bottom_pit
|
2007-11-15 20:04:51 +00:00
|
|
|
<< " singlepar: 1");
|
2007-09-28 09:11:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-06 08:32:25 +00:00
|
|
|
void BufferView::updateMetrics()
|
2006-07-08 20:24:32 +00:00
|
|
|
{
|
2008-06-19 13:10:25 +00:00
|
|
|
if (height_ == 0 || width_ == 0)
|
|
|
|
return;
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
Text & buftext = buffer_.text();
|
2007-09-11 16:04:10 +00:00
|
|
|
pit_type const npit = int(buftext.paragraphs().size());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2007-09-28 09:11:24 +00:00
|
|
|
// Clear out the position cache in case of full screen redraw,
|
2007-10-13 07:33:07 +00:00
|
|
|
d->coord_cache_.clear();
|
2007-09-16 10:38:25 +00:00
|
|
|
|
2007-09-28 09:11:24 +00:00
|
|
|
// Clear out paragraph metrics to avoid having invalid metrics
|
|
|
|
// in the cache from paragraphs not relayouted below
|
|
|
|
// The complete text metrics will be redone.
|
2007-10-13 07:33:07 +00:00
|
|
|
d->text_metrics_.clear();
|
2007-08-30 16:48:47 +00:00
|
|
|
|
|
|
|
TextMetrics & tm = textMetrics(&buftext);
|
2007-06-21 06:41:55 +00:00
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
// make sure inline completion pointer is ok
|
2008-04-16 20:43:30 +00:00
|
|
|
if (d->inlineCompletionPos_.fixIfBroken())
|
|
|
|
d->inlineCompletionPos_ = DocIterator();
|
2008-02-21 19:42:34 +00:00
|
|
|
|
2008-03-02 19:07:15 +00:00
|
|
|
if (d->anchor_pit_ >= npit)
|
|
|
|
// The anchor pit must have been deleted...
|
|
|
|
d->anchor_pit_ = npit - 1;
|
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
// Rebreak anchor paragraph.
|
2007-12-21 08:28:18 +00:00
|
|
|
tm.redoParagraph(d->anchor_pit_);
|
|
|
|
ParagraphMetrics & anchor_pm = tm.par_metrics_[d->anchor_pit_];
|
2008-02-05 14:23:59 +00:00
|
|
|
|
|
|
|
// position anchor
|
|
|
|
if (d->anchor_pit_ == 0) {
|
|
|
|
int scrollRange = d->scrollbarParameters_.max - d->scrollbarParameters_.min;
|
|
|
|
|
|
|
|
// Complete buffer visible? Then it's easy.
|
|
|
|
if (scrollRange == 0)
|
|
|
|
d->anchor_ypos_ = anchor_pm.ascent();
|
|
|
|
|
|
|
|
// FIXME: Some clever handling needed to show
|
|
|
|
// the _first_ paragraph up to the top if the cursor is
|
|
|
|
// in the first line.
|
|
|
|
}
|
2007-12-21 08:28:18 +00:00
|
|
|
anchor_pm.setPosition(d->anchor_ypos_);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
LYXERR(Debug::PAINTING, "metrics: "
|
|
|
|
<< " anchor pit = " << d->anchor_pit_
|
|
|
|
<< " anchor ypos = " << d->anchor_ypos_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
// Redo paragraphs above anchor if necessary.
|
2007-12-21 08:28:18 +00:00
|
|
|
int y1 = d->anchor_ypos_ - anchor_pm.ascent();
|
|
|
|
// We are now just above the anchor paragraph.
|
|
|
|
pit_type pit1 = d->anchor_pit_ - 1;
|
2007-12-22 09:10:49 +00:00
|
|
|
for (; pit1 >= 0 && y1 >= 0; --pit1) {
|
2007-09-11 16:04:10 +00:00
|
|
|
tm.redoParagraph(pit1);
|
2007-12-21 08:28:18 +00:00
|
|
|
ParagraphMetrics & pm = tm.par_metrics_[pit1];
|
|
|
|
y1 -= pm.descent();
|
|
|
|
// Save the paragraph position in the cache.
|
|
|
|
pm.setPosition(y1);
|
|
|
|
y1 -= pm.ascent();
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
// Redo paragraphs below the anchor if necessary.
|
2007-12-21 08:28:18 +00:00
|
|
|
int y2 = d->anchor_ypos_ + anchor_pm.descent();
|
|
|
|
// We are now just below the anchor paragraph.
|
|
|
|
pit_type pit2 = d->anchor_pit_ + 1;
|
2007-12-22 09:04:53 +00:00
|
|
|
for (; pit2 < npit && y2 <= height_; ++pit2) {
|
2007-09-11 16:04:10 +00:00
|
|
|
tm.redoParagraph(pit2);
|
2007-12-21 08:28:18 +00:00
|
|
|
ParagraphMetrics & pm = tm.par_metrics_[pit2];
|
|
|
|
y2 += pm.ascent();
|
|
|
|
// Save the paragraph position in the cache.
|
|
|
|
pm.setPosition(y2);
|
|
|
|
y2 += pm.descent();
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
LYXERR(Debug::PAINTING, "Metrics: "
|
|
|
|
<< " anchor pit = " << d->anchor_pit_
|
|
|
|
<< " anchor ypos = " << d->anchor_ypos_
|
|
|
|
<< " y1 = " << y1
|
|
|
|
<< " y2 = " << y2
|
|
|
|
<< " pit1 = " << pit1
|
|
|
|
<< " pit2 = " << pit2);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
d->update_strategy_ = FullScreenUpdate;
|
2006-10-20 20:57:21 +00:00
|
|
|
|
|
|
|
if (lyxerr.debugging(Debug::WORKAREA)) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::WORKAREA, "BufferView::updateMetrics");
|
2007-10-13 07:33:07 +00:00
|
|
|
d->coord_cache_.dump();
|
2006-10-20 20:57:21 +00:00
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-02 17:50:08 +00:00
|
|
|
void BufferView::insertLyXFile(FileName const & fname)
|
2006-09-16 10:08:51 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(d->cursor_.inTexted(), /**/);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
// Get absolute path of file and add ".lyx"
|
|
|
|
// to the filename if necessary
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName filename = fileSearch(string(), fname.absFileName(), "lyx");
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2010-04-21 01:19:09 +00:00
|
|
|
docstring const disp_fn = makeDisplayPath(filename.absFileName());
|
2006-09-16 10:08:51 +00:00
|
|
|
// emit message signal.
|
|
|
|
message(bformat(_("Inserting document %1$s..."), disp_fn));
|
|
|
|
|
|
|
|
docstring res;
|
2010-11-05 21:21:01 +00:00
|
|
|
Buffer buf(filename.absFileName(), false);
|
|
|
|
if (buf.loadLyXFile() == Buffer::ReadSuccess) {
|
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");
|
2007-10-18 11:51:17 +00:00
|
|
|
buffer_.undo().recordUndo(d->cursor_);
|
2007-10-13 07:33:07 +00:00
|
|
|
cap::pasteParagraphList(d->cursor_, buf.paragraphs(),
|
2008-02-28 01:42:02 +00:00
|
|
|
buf.params().documentClassPtr(), el);
|
2006-09-16 10:08:51 +00:00
|
|
|
res = _("Document %1$s inserted.");
|
2007-10-21 10:50:56 +00:00
|
|
|
} else {
|
2006-09-16 10:08:51 +00:00
|
|
|
res = _("Could not insert document %1$s");
|
2007-10-21 10:50:56 +00:00
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(true);
|
2006-09-16 10:08:51 +00:00
|
|
|
// emit message signal.
|
|
|
|
message(bformat(res, disp_fn));
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-08-27 22:53:16 +00:00
|
|
|
|
2010-04-21 13:12:40 +00:00
|
|
|
Point BufferView::coordOffset(DocIterator const & dit) const
|
2007-09-29 09:22:17 +00:00
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
int lastw = 0;
|
|
|
|
|
|
|
|
// Addup contribution of nested insets, from inside to outside,
|
|
|
|
// keeping the outer paragraph for a special handling below
|
|
|
|
for (size_t i = dit.depth() - 1; i >= 1; --i) {
|
|
|
|
CursorSlice const & sl = dit[i];
|
|
|
|
int xx = 0;
|
|
|
|
int yy = 0;
|
|
|
|
|
|
|
|
// get relative position inside sl.inset()
|
2010-04-21 13:12:40 +00:00
|
|
|
sl.inset().cursorPos(*this, sl, dit.boundary() && (i + 1 == dit.depth()), xx, yy);
|
2007-09-29 09:22:17 +00:00
|
|
|
|
|
|
|
// Make relative position inside of the edited inset relative to sl.inset()
|
|
|
|
x += xx;
|
|
|
|
y += yy;
|
|
|
|
|
|
|
|
// In case of an RTL inset, the edited inset will be positioned to the left
|
|
|
|
// of xx:yy
|
|
|
|
if (sl.text()) {
|
2010-04-21 13:12:40 +00:00
|
|
|
bool boundary_i = dit.boundary() && i + 1 == dit.depth();
|
2007-09-29 09:22:17 +00:00
|
|
|
bool rtl = textMetrics(sl.text()).isRTL(sl, boundary_i);
|
|
|
|
if (rtl)
|
|
|
|
x -= lastw;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remember width for the case that sl.inset() is positioned in an RTL inset
|
|
|
|
if (i && dit[i - 1].text()) {
|
|
|
|
// If this Inset is inside a Text Inset, retrieve the Dimension
|
|
|
|
// from the containing text instead of using Inset::dimension() which
|
|
|
|
// might not be implemented.
|
|
|
|
// FIXME (Abdel 23/09/2007): this is a bit messy because of the
|
|
|
|
// elimination of Inset::dim_ cache. This coordOffset() method needs
|
|
|
|
// to be rewritten in light of the new design.
|
|
|
|
Dimension const & dim = parMetrics(dit[i - 1].text(),
|
|
|
|
dit[i - 1].pit()).insetDimension(&sl.inset());
|
|
|
|
lastw = dim.wid;
|
|
|
|
} else {
|
|
|
|
Dimension const dim = sl.inset().dimension(*this);
|
|
|
|
lastw = dim.wid;
|
|
|
|
}
|
|
|
|
|
|
|
|
//lyxerr << "Cursor::getPos, i: "
|
|
|
|
// << i << " x: " << xx << " y: " << y << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add contribution of initial rows of outermost paragraph
|
|
|
|
CursorSlice const & sl = dit[0];
|
|
|
|
TextMetrics const & tm = textMetrics(sl.text());
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(sl.pit());
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(!pm.rows().empty(), /**/);
|
2007-09-29 09:22:17 +00:00
|
|
|
y -= pm.rows()[0].ascent();
|
|
|
|
#if 1
|
|
|
|
// FIXME: document this mess
|
|
|
|
size_t rend;
|
|
|
|
if (sl.pos() > 0 && dit.depth() == 1) {
|
|
|
|
int pos = sl.pos();
|
2010-04-21 13:12:40 +00:00
|
|
|
if (pos && dit.boundary())
|
2007-09-29 09:22:17 +00:00
|
|
|
--pos;
|
2010-04-21 13:12:40 +00:00
|
|
|
// lyxerr << "coordOffset: boundary:" << dit.boundary() << " depth:" << dit.depth() << " pos:" << pos << " sl.pos:" << sl.pos() << endl;
|
2007-09-29 09:22:17 +00:00
|
|
|
rend = pm.pos2row(pos);
|
|
|
|
} else
|
|
|
|
rend = pm.pos2row(sl.pos());
|
|
|
|
#else
|
|
|
|
size_t rend = pm.pos2row(sl.pos());
|
|
|
|
#endif
|
|
|
|
for (size_t rit = 0; rit != rend; ++rit)
|
|
|
|
y += pm.rows()[rit].height();
|
|
|
|
y += pm.rows()[rend].ascent();
|
|
|
|
|
|
|
|
TextMetrics const & bottom_tm = textMetrics(dit.bottom().text());
|
|
|
|
|
|
|
|
// Make relative position from the nested inset now bufferview absolute.
|
2010-04-21 13:12:40 +00:00
|
|
|
int xx = bottom_tm.cursorX(dit.bottom(), dit.boundary() && dit.depth() == 1);
|
2007-09-29 09:22:17 +00:00
|
|
|
x += xx;
|
|
|
|
|
|
|
|
// In the RTL case place the nested inset at the left of the cursor in
|
|
|
|
// the outer paragraph
|
2010-04-21 13:12:40 +00:00
|
|
|
bool boundary_1 = dit.boundary() && 1 == dit.depth();
|
2007-09-29 09:22:17 +00:00
|
|
|
bool rtl = bottom_tm.isRTL(dit.bottom(), boundary_1);
|
|
|
|
if (rtl)
|
|
|
|
x -= lastw;
|
|
|
|
|
|
|
|
return Point(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-21 13:03:04 +00:00
|
|
|
Point BufferView::getPos(DocIterator const & dit) const
|
2007-09-29 09:22:17 +00:00
|
|
|
{
|
2008-11-18 23:57:26 +00:00
|
|
|
if (!paragraphVisible(dit))
|
|
|
|
return Point(-1, -1);
|
|
|
|
|
2007-09-29 09:22:17 +00:00
|
|
|
CursorSlice const & bot = dit.bottom();
|
|
|
|
TextMetrics const & tm = textMetrics(bot.text());
|
|
|
|
|
2010-04-21 13:12:40 +00:00
|
|
|
// offset from outer paragraph
|
|
|
|
Point p = coordOffset(dit);
|
2007-09-29 09:22:17 +00:00
|
|
|
p.y_ += tm.parMetrics(bot.pit()).position();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-18 23:57:26 +00:00
|
|
|
bool BufferView::paragraphVisible(DocIterator const & dit) const
|
|
|
|
{
|
|
|
|
CursorSlice const & bot = dit.bottom();
|
|
|
|
TextMetrics const & tm = textMetrics(bot.text());
|
|
|
|
|
|
|
|
return tm.contains(bot.pit());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-03 21:39:06 +00:00
|
|
|
void BufferView::cursorPosAndHeight(Point & p, int & h) const
|
|
|
|
{
|
|
|
|
Cursor const & cur = cursor();
|
|
|
|
Font const font = cur.getFont();
|
|
|
|
frontend::FontMetrics const & fm = theFontMetrics(font);
|
|
|
|
int const asc = fm.maxAscent();
|
|
|
|
int const des = fm.maxDescent();
|
|
|
|
h = asc + des;
|
2010-04-21 13:03:04 +00:00
|
|
|
p = getPos(cur);
|
2009-04-03 21:39:06 +00:00
|
|
|
p.y_ -= asc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BufferView::cursorInView(Point const & p, int h) const
|
|
|
|
{
|
|
|
|
Cursor const & cur = cursor();
|
|
|
|
// does the cursor touch the screen ?
|
|
|
|
if (p.y_ + h < 0 || p.y_ >= workHeight() || !paragraphVisible(cur))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-27 22:53:16 +00:00
|
|
|
void BufferView::draw(frontend::Painter & pain)
|
|
|
|
{
|
2008-06-19 13:10:25 +00:00
|
|
|
if (height_ == 0 || width_ == 0)
|
|
|
|
return;
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::PAINTING, "\t\t*** START DRAWING ***");
|
2008-11-15 18:17:20 +00:00
|
|
|
|
2007-11-06 14:07:49 +00:00
|
|
|
Text & text = buffer_.text();
|
|
|
|
TextMetrics const & tm = d->text_metrics_[&text];
|
2007-12-21 08:28:18 +00:00
|
|
|
int const y = tm.first().second->position();
|
2007-08-27 22:53:16 +00:00
|
|
|
PainterInfo pi(this, pain);
|
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
switch (d->update_strategy_) {
|
2007-11-06 14:07:49 +00:00
|
|
|
|
|
|
|
case NoScreenUpdate:
|
|
|
|
// If no screen painting is actually needed, only some the different
|
|
|
|
// coordinates of insets and paragraphs needs to be updated.
|
|
|
|
pi.full_repaint = true;
|
2007-11-06 14:18:09 +00:00
|
|
|
pi.pain.setDrawingEnabled(false);
|
|
|
|
tm.draw(pi, 0, y);
|
2007-11-06 14:07:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SingleParUpdate:
|
|
|
|
pi.full_repaint = false;
|
2007-11-17 11:27:03 +00:00
|
|
|
// In general, only the current row of the outermost paragraph
|
|
|
|
// will be redrawn. Particular cases where selection spans
|
|
|
|
// multiple paragraph are correctly detected in TextMetrics.
|
|
|
|
tm.draw(pi, 0, y);
|
2007-11-06 14:07:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DecorationUpdate:
|
|
|
|
// FIXME: We should also distinguish DecorationUpdate to avoid text
|
|
|
|
// drawing if possible. This is not possible to do easily right now
|
|
|
|
// because of the single backing pixmap.
|
|
|
|
|
|
|
|
case FullScreenUpdate:
|
|
|
|
// The whole screen, including insets, will be refreshed.
|
|
|
|
pi.full_repaint = true;
|
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
// Clear background.
|
|
|
|
pain.fillRectangle(0, 0, width_, height_,
|
2008-10-25 10:47:38 +00:00
|
|
|
pi.backgroundColor(&buffer_.inset()));
|
2007-12-21 08:28:18 +00:00
|
|
|
|
|
|
|
// Draw everything.
|
2007-09-09 20:21:43 +00:00
|
|
|
tm.draw(pi, 0, y);
|
2007-08-27 22:53:16 +00:00
|
|
|
|
2007-11-06 14:07:49 +00:00
|
|
|
// and possibly grey out below
|
2007-12-12 19:28:07 +00:00
|
|
|
pair<pit_type, ParagraphMetrics const *> lastpm = tm.last();
|
2007-11-17 11:27:03 +00:00
|
|
|
int const y2 = lastpm.second->position() + lastpm.second->descent();
|
2009-08-19 00:10:09 +00:00
|
|
|
|
|
|
|
if (y2 < height_) {
|
2009-09-09 04:58:48 +00:00
|
|
|
Color color = buffer().isInternal()
|
|
|
|
? Color_background : Color_bottomarea;
|
2009-08-19 00:10:09 +00:00
|
|
|
pain.fillRectangle(0, y2, width_, height_ - y2, color);
|
|
|
|
}
|
2007-11-06 14:07:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::PAINTING, "\n\t\t*** END DRAWING ***");
|
2007-12-21 08:28:18 +00:00
|
|
|
|
|
|
|
// The scrollbar needs an update.
|
|
|
|
updateScrollbar();
|
|
|
|
|
|
|
|
// Normalize anchor for next time
|
|
|
|
pair<pit_type, ParagraphMetrics const *> firstpm = tm.first();
|
|
|
|
pair<pit_type, ParagraphMetrics const *> lastpm = tm.last();
|
|
|
|
for (pit_type pit = firstpm.first; pit <= lastpm.first; ++pit) {
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(pit);
|
|
|
|
if (pm.position() + pm.descent() > 0) {
|
|
|
|
d->anchor_pit_ = pit;
|
|
|
|
d->anchor_ypos_ = pm.position();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LYXERR(Debug::PAINTING, "Found new anchor pit = " << d->anchor_pit_
|
|
|
|
<< " anchor ypos = " << d->anchor_ypos_);
|
2007-08-27 22:53:16 +00:00
|
|
|
}
|
|
|
|
|
2007-10-02 18:27:20 +00:00
|
|
|
|
|
|
|
void BufferView::message(docstring const & msg)
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
if (d->gui_)
|
|
|
|
d->gui_->message(msg);
|
2007-10-02 18:27:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
void BufferView::showDialog(string const & name)
|
2007-10-02 18:27:20 +00:00
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
if (d->gui_)
|
2007-11-18 00:39:15 +00:00
|
|
|
d->gui_->showDialog(name, string());
|
2007-10-02 18:27:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
void BufferView::showDialog(string const & name,
|
|
|
|
string const & data, Inset * inset)
|
2007-10-02 18:27:20 +00:00
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
if (d->gui_)
|
2007-11-18 00:39:15 +00:00
|
|
|
d->gui_->showDialog(name, data, inset);
|
2007-10-02 18:27:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
void BufferView::updateDialog(string const & name, string const & data)
|
2007-10-02 18:27:20 +00:00
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
if (d->gui_)
|
|
|
|
d->gui_->updateDialog(name, data);
|
2007-10-02 18:27:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::setGuiDelegate(frontend::GuiBufferViewDelegate * gui)
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
d->gui_ = gui;
|
2007-10-02 18:27:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-03 20:15:49 +00:00
|
|
|
// FIXME: Move this out of BufferView again
|
2007-12-02 20:05:17 +00:00
|
|
|
docstring BufferView::contentsOfPlaintextFile(FileName const & fname)
|
2007-10-03 18:56:37 +00:00
|
|
|
{
|
2007-11-25 11:18:16 +00:00
|
|
|
if (!fname.isReadableFile()) {
|
2007-10-03 18:56:37 +00:00
|
|
|
docstring const error = from_ascii(strerror(errno));
|
2010-04-21 01:19:09 +00:00
|
|
|
docstring const file = makeDisplayPath(fname.absFileName(), 50);
|
2007-10-03 18:56:37 +00:00
|
|
|
docstring const text =
|
|
|
|
bformat(_("Could not read the specified document\n"
|
|
|
|
"%1$s\ndue to the error: %2$s"), file, error);
|
|
|
|
Alert::error(_("Could not read file"), text);
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
2007-12-02 11:55:25 +00:00
|
|
|
if (!fname.isReadableFile()) {
|
2010-04-21 01:19:09 +00:00
|
|
|
docstring const file = makeDisplayPath(fname.absFileName(), 50);
|
2007-10-03 18:56:37 +00:00
|
|
|
docstring const text =
|
2007-12-02 11:55:25 +00:00
|
|
|
bformat(_("%1$s\n is not readable."), file);
|
2007-10-03 18:56:37 +00:00
|
|
|
Alert::error(_("Could not open file"), text);
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME UNICODE: We don't know the encoding of the file
|
2007-12-02 11:55:25 +00:00
|
|
|
docstring file_content = fname.fileContents("UTF-8");
|
2007-10-03 18:56:37 +00:00
|
|
|
if (file_content.empty()) {
|
|
|
|
Alert::error(_("Reading not UTF-8 encoded file"),
|
|
|
|
_("The file is not UTF-8 encoded.\n"
|
|
|
|
"It will be read as local 8Bit-encoded.\n"
|
|
|
|
"If this does not give the correct result\n"
|
|
|
|
"then please change the encoding of the file\n"
|
|
|
|
"to UTF-8 with a program other than LyX.\n"));
|
2007-12-02 11:55:25 +00:00
|
|
|
file_content = fname.fileContents("local8bit");
|
2007-10-03 18:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return normalize_c(file_content);
|
|
|
|
}
|
|
|
|
|
2007-10-03 20:15:49 +00:00
|
|
|
|
2007-12-02 11:55:25 +00:00
|
|
|
void BufferView::insertPlaintextFile(FileName const & f, bool asParagraph)
|
2007-10-03 18:56:37 +00:00
|
|
|
{
|
2007-12-02 20:05:17 +00:00
|
|
|
docstring const tmpstr = contentsOfPlaintextFile(f);
|
2007-10-03 18:56:37 +00:00
|
|
|
|
|
|
|
if (tmpstr.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Cursor & cur = cursor();
|
|
|
|
cap::replaceSelection(cur);
|
2007-10-18 11:51:17 +00:00
|
|
|
buffer_.undo().recordUndo(cur);
|
2007-10-03 18:56:37 +00:00
|
|
|
if (asParagraph)
|
2009-08-09 16:49:41 +00:00
|
|
|
cur.innerText()->insertStringAsParagraphs(cur, tmpstr, cur.current_font);
|
2007-10-03 18:56:37 +00:00
|
|
|
else
|
2009-08-09 16:49:41 +00:00
|
|
|
cur.innerText()->insertStringAsLines(cur, tmpstr, cur.current_font);
|
2007-12-02 20:05:17 +00:00
|
|
|
|
2010-01-08 02:03:54 +00:00
|
|
|
buffer_.changed(true);
|
2007-10-03 18:56:37 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
|
|
docstring const & BufferView::inlineCompletion() const
|
|
|
|
{
|
2008-04-16 20:43:30 +00:00
|
|
|
return d->inlineCompletion_;
|
2008-02-21 19:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t const & BufferView::inlineCompletionUniqueChars() const
|
|
|
|
{
|
2008-04-16 20:43:30 +00:00
|
|
|
return d->inlineCompletionUniqueChars_;
|
2008-02-21 19:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DocIterator const & BufferView::inlineCompletionPos() const
|
|
|
|
{
|
2008-04-16 20:43:30 +00:00
|
|
|
return d->inlineCompletionPos_;
|
2008-02-21 19:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 15:26:28 +00:00
|
|
|
void BufferView::resetInlineCompletionPos()
|
2010-11-30 03:54:29 +00:00
|
|
|
{
|
2011-02-21 15:26:28 +00:00
|
|
|
d->inlineCompletionPos_ = DocIterator();
|
2010-11-30 03:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-21 19:43:16 +00:00
|
|
|
bool samePar(DocIterator const & a, DocIterator const & b)
|
|
|
|
{
|
|
|
|
if (a.empty() && b.empty())
|
|
|
|
return true;
|
|
|
|
if (a.empty() || b.empty())
|
|
|
|
return false;
|
2009-02-25 00:39:55 +00:00
|
|
|
if (a.depth() != b.depth())
|
|
|
|
return false;
|
2008-02-21 19:43:16 +00:00
|
|
|
return &a.innerParagraph() == &b.innerParagraph();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::setInlineCompletion(Cursor & cur, DocIterator const & pos,
|
2008-02-21 19:42:34 +00:00
|
|
|
docstring const & completion, size_t uniqueChars)
|
|
|
|
{
|
2008-02-21 19:43:16 +00:00
|
|
|
uniqueChars = min(completion.size(), uniqueChars);
|
2008-04-16 20:43:30 +00:00
|
|
|
bool changed = d->inlineCompletion_ != completion
|
|
|
|
|| d->inlineCompletionUniqueChars_ != uniqueChars;
|
2008-02-21 19:43:16 +00:00
|
|
|
bool singlePar = true;
|
2008-04-16 20:43:30 +00:00
|
|
|
d->inlineCompletion_ = completion;
|
|
|
|
d->inlineCompletionUniqueChars_ = min(completion.size(), uniqueChars);
|
2008-02-21 19:43:16 +00:00
|
|
|
|
2008-02-23 03:13:54 +00:00
|
|
|
//lyxerr << "setInlineCompletion pos=" << pos << " completion=" << completion << " uniqueChars=" << uniqueChars << std::endl;
|
2008-02-21 19:43:16 +00:00
|
|
|
|
|
|
|
// at new position?
|
2008-04-16 20:43:30 +00:00
|
|
|
DocIterator const & old = d->inlineCompletionPos_;
|
2008-02-21 19:43:16 +00:00
|
|
|
if (old != pos) {
|
2008-02-23 03:13:54 +00:00
|
|
|
//lyxerr << "inlineCompletionPos changed" << std::endl;
|
2008-02-21 19:43:16 +00:00
|
|
|
// old or pos are in another paragraph?
|
|
|
|
if ((!samePar(cur, pos) && !pos.empty())
|
|
|
|
|| (!samePar(cur, old) && !old.empty())) {
|
|
|
|
singlePar = false;
|
2008-02-23 03:13:54 +00:00
|
|
|
//lyxerr << "different paragraph" << std::endl;
|
2008-02-21 19:43:16 +00:00
|
|
|
}
|
2008-04-16 20:43:30 +00:00
|
|
|
d->inlineCompletionPos_ = pos;
|
2008-02-21 19:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// set update flags
|
|
|
|
if (changed) {
|
2010-10-13 17:28:55 +00:00
|
|
|
if (singlePar && !(cur.result().screenUpdate() & Update::Force))
|
|
|
|
cur.screenUpdateFlags(cur.result().screenUpdate() | Update::SinglePar);
|
2008-02-26 14:22:56 +00:00
|
|
|
else
|
2010-10-13 17:28:55 +00:00
|
|
|
cur.screenUpdateFlags(cur.result().screenUpdate() | Update::Force);
|
2008-02-21 19:43:16 +00:00
|
|
|
}
|
2008-02-21 19:42:34 +00:00
|
|
|
}
|
|
|
|
|
2010-10-24 21:41:47 +00:00
|
|
|
|
|
|
|
bool BufferView::clickableInset() const
|
|
|
|
{
|
|
|
|
return d->clickable_inset_;
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|