mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
remove math cursor plus
* BufferView.C: * cursor.[Ch]: some additional asserts * undo.[Ch]: remove LyXText dependency in interface * lyxfunc.C: adjust * lyxtext.h (firstPar, lastPar): remove dead functions * text.C: * text2.C: * text3.C: * paragraph.[Ch]: adjust git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8386 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
905a6f6158
commit
22590a98b3
@ -333,7 +333,7 @@ void BufferView::undo()
|
||||
|
||||
owner()->message(_("Undo"));
|
||||
cursor().clearSelection();
|
||||
if (!textUndo(this))
|
||||
if (!textUndo(*this))
|
||||
owner()->message(_("No further undo information"));
|
||||
update();
|
||||
switchKeyMap();
|
||||
@ -347,7 +347,7 @@ void BufferView::redo()
|
||||
|
||||
owner()->message(_("Redo"));
|
||||
cursor().clearSelection();
|
||||
if (!textRedo(this))
|
||||
if (!textRedo(*this))
|
||||
owner()->message(_("No further redo information"));
|
||||
update();
|
||||
switchKeyMap();
|
||||
|
@ -1,3 +1,20 @@
|
||||
|
||||
2004-02-03 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
* BufferView.C:
|
||||
* cursor.[Ch]: some additional asserts
|
||||
|
||||
* undo.[Ch]: remove LyXText dependency in interface
|
||||
|
||||
* lyxfunc.C: adjust
|
||||
|
||||
* lyxtext.h (firstPar, lastPar): remove dead functions
|
||||
|
||||
* text.C:
|
||||
* text2.C:
|
||||
* text3.C:
|
||||
* paragraph.[Ch]: adjust
|
||||
|
||||
2004-02-03 Alfredo Braunstein <abraunst@lyx.org>
|
||||
|
||||
* lyxfind.C (find): fix argument order in call to ::find
|
||||
|
48
src/cursor.C
48
src/cursor.C
@ -482,16 +482,24 @@ LyXText * LCursor::text() const
|
||||
|
||||
Paragraph & LCursor::paragraph()
|
||||
{
|
||||
BOOST_ASSERT(!inMathed());
|
||||
return current_ ? current().paragraph() : *bv_->text()->getPar(par());
|
||||
}
|
||||
|
||||
|
||||
Paragraph const & LCursor::paragraph() const
|
||||
{
|
||||
BOOST_ASSERT(!inMathed());
|
||||
return current_ ? current().paragraph() : *bv_->text()->getPar(par());
|
||||
}
|
||||
|
||||
|
||||
LCursor::par_type LCursor::lastpar() const
|
||||
{
|
||||
return inMathed() ? 0 : text()->paragraphs().size() - 1;
|
||||
}
|
||||
|
||||
|
||||
LCursor::pos_type LCursor::lastpos() const
|
||||
{
|
||||
InsetBase * inset = current().inset();
|
||||
@ -499,6 +507,18 @@ LCursor::pos_type LCursor::lastpos() const
|
||||
}
|
||||
|
||||
|
||||
LCursor::row_type LCursor::crow() const
|
||||
{
|
||||
return paragraph().row(pos());
|
||||
}
|
||||
|
||||
|
||||
LCursor::row_type LCursor::lastcrow() const
|
||||
{
|
||||
return paragraph().rows.size();
|
||||
}
|
||||
|
||||
|
||||
size_t LCursor::nargs() const
|
||||
{
|
||||
// assume 1x1 grid for 'plain text'
|
||||
@ -1096,9 +1116,8 @@ bool LCursor::erase()
|
||||
}
|
||||
|
||||
// delete empty cells if possible
|
||||
#warning FIXME
|
||||
//if (cell().empty() && inset()->idxDelete(idx()))
|
||||
// return true;
|
||||
if (pos() == lastpos() && inset()->idxDelete(idx()))
|
||||
return true;
|
||||
|
||||
// special behaviour when in last position of cell
|
||||
if (pos() == lastpos()) {
|
||||
@ -1789,3 +1808,26 @@ bool LCursor::inMathed() const
|
||||
{
|
||||
return formula();
|
||||
}
|
||||
|
||||
|
||||
InsetBase * LCursor::nextInset()
|
||||
{
|
||||
if (pos() == lastpos())
|
||||
return 0;
|
||||
if (inMathed())
|
||||
return nextAtom().nucleus();
|
||||
Paragraph & par = paragraph();
|
||||
return par.isInset(pos()) ? par.getInset(pos()) : 0;
|
||||
}
|
||||
|
||||
|
||||
InsetBase * LCursor::prevInset()
|
||||
{
|
||||
if (pos() == 0)
|
||||
return 0;
|
||||
if (inMathed())
|
||||
return prevAtom().nucleus();
|
||||
Paragraph & par = paragraph();
|
||||
return par.isInset(pos() - 1) ? par.getInset(pos() - 1) : 0;
|
||||
}
|
||||
|
||||
|
13
src/cursor.h
13
src/cursor.h
@ -137,7 +137,7 @@ public:
|
||||
//
|
||||
// access to the 'current' cursor slice
|
||||
//
|
||||
/// the current inset
|
||||
/// the containing inset
|
||||
InsetBase * inset() const { return current().inset(); }
|
||||
/// return the cell of the inset this cursor is in
|
||||
idx_type idx() const { return current().idx(); }
|
||||
@ -149,12 +149,19 @@ public:
|
||||
par_type par() const { return current().par(); }
|
||||
/// return the paragraph this cursor is in
|
||||
par_type & par() { return current().par(); }
|
||||
/// return the last possible paragraph in this inset
|
||||
par_type lastpar() const;
|
||||
/// return the position within the paragraph
|
||||
pos_type pos() const { return current().pos(); }
|
||||
/// return the position within the paragraph
|
||||
pos_type & pos() { return current().pos(); }
|
||||
/// return the last position within the paragraph
|
||||
pos_type lastpos() const;
|
||||
/// return the display row of the cursor with in the current par
|
||||
row_type crow() const;
|
||||
/// return the display row of the cursor with in the current par
|
||||
row_type lastcrow() const;
|
||||
|
||||
/// return the number of embedded cells
|
||||
size_t nargs() const;
|
||||
/// return the number of embedded cells
|
||||
@ -165,6 +172,10 @@ public:
|
||||
row_type row() const;
|
||||
/// return the grid row of the current cell
|
||||
col_type col() const;
|
||||
/// the inset just behind the cursor
|
||||
InsetBase * nextInset();
|
||||
/// the inset just in front of the cursor
|
||||
InsetBase * prevInset();
|
||||
|
||||
//
|
||||
// math-specific part
|
||||
|
@ -330,7 +330,7 @@ int replaceAll(BufferView * bv,
|
||||
if (!searchAllowed(bv, searchstr) || buf.isReadonly())
|
||||
return 0;
|
||||
|
||||
recordUndo(Undo::ATOMIC, bv->text(), 0, buf.paragraphs().size() - 1);
|
||||
recordUndoFullDocument(bv->cursor());
|
||||
|
||||
PosIterator cur = buf.pos_iterator_begin();
|
||||
PosIterator const end = buf.pos_iterator_end();
|
||||
|
@ -685,7 +685,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
|
||||
code = InsetOld::SPACE_CODE;
|
||||
break;
|
||||
case LFUN_INSET_DIALOG_SHOW: {
|
||||
InsetBase * inset = view()->getLyXText()->getInset();
|
||||
InsetBase * inset = view()->cursor().nextInset();
|
||||
disable = !inset;
|
||||
if (inset) {
|
||||
code = inset->lyxCode();
|
||||
@ -835,14 +835,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
|
||||
// we have not done anything wrong yet.
|
||||
errorstat = false;
|
||||
dispatch_buffer.erase();
|
||||
|
||||
#ifdef NEW_DISPATCHER
|
||||
// We try do call the most specific dispatcher first:
|
||||
// 1. the lockinginset's dispatch
|
||||
// 2. the bufferview's dispatch
|
||||
// 3. the lyxview's dispatch
|
||||
#endif
|
||||
|
||||
selection_possible = false;
|
||||
|
||||
// We cannot use this function here
|
||||
@ -1284,7 +1276,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
|
||||
break;
|
||||
|
||||
case LFUN_INSET_DIALOG_SHOW: {
|
||||
InsetBase * inset = view()->getLyXText()->getInset();
|
||||
InsetBase * inset = view()->cursor().nextInset();
|
||||
if (inset)
|
||||
inset->dispatch(view()->cursor(), FuncRequest(LFUN_INSET_DIALOG_SHOW));
|
||||
break;
|
||||
@ -1443,7 +1435,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
|
||||
}
|
||||
}
|
||||
|
||||
view()->owner()->updateLayoutChoice();
|
||||
if (!view()->cursor().inMathed())
|
||||
view()->owner()->updateLayoutChoice();
|
||||
|
||||
if (view()->available()) {
|
||||
view()->fitCursor();
|
||||
@ -1456,7 +1449,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
|
||||
view()->buffer()->markDirty();
|
||||
}
|
||||
|
||||
sendDispatchMessage(getMessage(), cmd, verbose);
|
||||
if (!view()->cursor().inMathed())
|
||||
sendDispatchMessage(getMessage(), cmd, verbose);
|
||||
}
|
||||
|
||||
|
||||
|
@ -161,12 +161,9 @@ public:
|
||||
void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const);
|
||||
/// just selects the word the cursor is in
|
||||
void selectWord(lyx::word_location loc);
|
||||
/// returns the inset at cursor (if it exists), 0 otherwise
|
||||
InsetBase * getInset() const;
|
||||
|
||||
/// accept selected change
|
||||
void acceptChange();
|
||||
|
||||
/// reject selected change
|
||||
void rejectChange();
|
||||
|
||||
@ -322,12 +319,6 @@ public:
|
||||
ParagraphList & paragraphs() const;
|
||||
/// return true if this is owned by an inset.
|
||||
bool isInInset() const;
|
||||
/// the first of our paragraphs
|
||||
ParagraphList::iterator firstPar() const;
|
||||
/// the last of our paragraphs
|
||||
ParagraphList::iterator lastPar() const;
|
||||
/// one past the last of our paragraphs
|
||||
ParagraphList::iterator endPar() const;
|
||||
|
||||
/// return first row of text
|
||||
RowList::iterator firstRow() const;
|
||||
@ -387,9 +378,9 @@ public:
|
||||
///
|
||||
int cursorY(CursorSlice const & cursor) const;
|
||||
|
||||
/// the topmost cursor slice
|
||||
/// the current cursor slice
|
||||
CursorSlice & cursor();
|
||||
/// the topmost cursor slice
|
||||
/// the current cursor slice
|
||||
CursorSlice const & cursor() const;
|
||||
|
||||
friend class LyXScreen;
|
||||
@ -460,16 +451,10 @@ private:
|
||||
/// sets row.end to the pos value *after* which a row should break.
|
||||
/// for example, the pos after which isNewLine(pos) == true
|
||||
void rowBreakPoint(ParagraphList::iterator pit, Row & row) const;
|
||||
|
||||
/// sets row.witdh to the minimum space a row needs on the screen in pixel
|
||||
void fill(ParagraphList::iterator pit, Row & row, int workwidth) const;
|
||||
|
||||
/**
|
||||
* returns the minimum space a manual label needs on the
|
||||
* screen in pixels
|
||||
*/
|
||||
/// the minimum space a manual label needs on the screen in pixels
|
||||
int labelFill(ParagraphList::iterator pit, Row const & row) const;
|
||||
|
||||
/// FIXME
|
||||
int labelEnd(ParagraphList::iterator pit) const;
|
||||
|
||||
@ -482,7 +467,7 @@ private:
|
||||
};
|
||||
|
||||
/// return the default height of a row in pixels, considering font zoom
|
||||
extern int defaultRowHeight();
|
||||
int defaultRowHeight();
|
||||
|
||||
///
|
||||
std::string expandLabel(LyXTextClass const & textclass,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,209 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file math_cursor.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Alejandro Aguilar Sierra
|
||||
* \author André Pönitz
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef MATH_CURSOR
|
||||
#define MATH_CURSOR
|
||||
|
||||
#include "cursor.h"
|
||||
#include "math_inset.h"
|
||||
#include "math_data.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class InsetFormulaBase;
|
||||
class BufferView;
|
||||
class PainterInfo;
|
||||
class MathUnknownInset;
|
||||
|
||||
/**
|
||||
|
||||
[Have a look at math_inset.h first]
|
||||
|
||||
The MathCursor is different from the kind of cursor used in the Outer
|
||||
World. It contains a stack of CursorSlice, each of which is made
|
||||
up of a inset pointer, an index and a position offset, marking a path from
|
||||
this formula's MathHullInset to the current position.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
namespace mathcursor {
|
||||
/// short of anything else reasonable
|
||||
typedef size_t size_type;
|
||||
/// type for column numbers
|
||||
typedef ptrdiff_t difference_type;
|
||||
/// type for cursor positions within a cell
|
||||
typedef lyx::pos_type pos_type;
|
||||
/// type for cell indices
|
||||
typedef size_t idx_type;
|
||||
/// type for row numbers
|
||||
typedef size_t row_type;
|
||||
/// type for column numbers
|
||||
typedef size_t col_type;
|
||||
|
||||
///
|
||||
void insert(LCursor & cur, MathAtom const &);
|
||||
///
|
||||
void insert(LCursor & cur, MathArray const &);
|
||||
///
|
||||
void insert2(LCursor & cur, std::string const &);
|
||||
///
|
||||
void paste(LCursor & cur, std::string const & data);
|
||||
/// return false for empty math insets
|
||||
bool erase(LCursor & cur);
|
||||
/// return false for empty math insets
|
||||
bool backspace(LCursor & cur);
|
||||
/// called for LFUN_HOME etc
|
||||
bool home(LCursor & cur, bool sel = false);
|
||||
/// called for LFUN_END etc
|
||||
bool end(LCursor & cur, bool sel = false);
|
||||
/// called for LFUN_RIGHT and LFUN_RIGHTSEL
|
||||
bool right(LCursor & cur, bool sel = false);
|
||||
/// called for LFUN_LEFT etc
|
||||
bool left(LCursor & cur, bool sel = false);
|
||||
/// called for LFUN_UP etc
|
||||
bool up(LCursor & cur, bool sel = false);
|
||||
/// called for LFUN_DOWN etc
|
||||
bool down(LCursor & cur, bool sel = false);
|
||||
/// move to next cell in current inset
|
||||
void idxNext(LCursor & bv);
|
||||
/// move to previous cell in current inset
|
||||
void idxPrev(LCursor & bv);
|
||||
///
|
||||
void plainErase(LCursor & cur);
|
||||
///
|
||||
void plainInsert(LCursor & cur, MathAtom const & at);
|
||||
///
|
||||
void niceInsert(LCursor & cur, MathAtom const & at);
|
||||
///
|
||||
void niceInsert(LCursor & cur, std::string const & str);
|
||||
|
||||
/// in pixels from top of screen
|
||||
void setScreenPos(LCursor & cur, int x, int y);
|
||||
/// in pixels from top of screen
|
||||
void getScreenPos(LCursor & cur, int & x, int & y);
|
||||
/// in pixels from left of screen
|
||||
int targetX(LCursor & cur);
|
||||
/// return the next enclosing grid inset and the cursor's index in it
|
||||
MathGridInset * enclosingGrid(LCursor & cur, idx_type & idx);
|
||||
/// go up to enclosing grid
|
||||
void popToEnclosingGrid(LCursor & cur);
|
||||
/// go up to the hull inset
|
||||
void popToEnclosingHull(LCursor & cur);
|
||||
/// go up to the hull inset
|
||||
void popToHere(LCursor & cur, MathInset const * p);
|
||||
/// adjust anchor position after deletions/insertions
|
||||
void adjust(LCursor & cur, pos_type from, difference_type diff);
|
||||
///
|
||||
InsetFormulaBase * formula();
|
||||
/// current offset in the current cell
|
||||
///
|
||||
bool script(LCursor & cur, bool);
|
||||
///
|
||||
bool interpret(LCursor & cur, char);
|
||||
/// interpret name a name of a macro
|
||||
void macroModeClose(LCursor & cur);
|
||||
/// are we currently typing the name of a macro?
|
||||
bool inMacroMode(LCursor & cur);
|
||||
/// get access to the macro we are currently typing
|
||||
MathUnknownInset * activeMacro(LCursor & cur);
|
||||
/// are we currently typing '#1' or '#2' or...?
|
||||
bool inMacroArgMode(LCursor & cur);
|
||||
/// are we in math mode (1), text mode (-1) or unsure?
|
||||
MathInset::mode_type currentMode(LCursor & cur);
|
||||
|
||||
// Local selection methods
|
||||
///
|
||||
void selCopy(LCursor & cur);
|
||||
///
|
||||
void selCut(LCursor & cur);
|
||||
///
|
||||
void selDel(LCursor & cur);
|
||||
/// pastes n-th element of cut buffer
|
||||
void selPaste(LCursor & cur, size_t n);
|
||||
///
|
||||
void selHandle(LCursor & cur, bool);
|
||||
///
|
||||
void selStart(LCursor & cur);
|
||||
///
|
||||
void selClear(LCursor & cur);
|
||||
/// clears or deletes selection depending on lyxrc setting
|
||||
void selClearOrDel(LCursor & cur);
|
||||
/// draws light-blue selection background
|
||||
void drawSelection(PainterInfo & pi);
|
||||
/// replace selected stuff with at, placing the former
|
||||
// selection in given cell of atom
|
||||
void handleNest(LCursor & cur, MathAtom const & at, int cell = 0);
|
||||
/// remove this as soon as LyXFunc::getStatus is "localized"
|
||||
inline std::string getLastCode() { return "mathnormal"; }
|
||||
///
|
||||
bool isInside(MathInset const *);
|
||||
///
|
||||
char valign(LCursor & cur);
|
||||
///
|
||||
char halign(LCursor & cur);
|
||||
|
||||
/// make sure cursor position is valid
|
||||
void normalize(LCursor & cur);
|
||||
/// mark current cursor trace for redraw
|
||||
void touch();
|
||||
|
||||
/// enter a MathInset
|
||||
void push(LCursor & cur, MathAtom & par);
|
||||
/// enter a MathInset from the front
|
||||
void pushLeft(LCursor & cur, MathAtom & par);
|
||||
/// enter a MathInset from the back
|
||||
void pushRight(LCursor & cur, MathAtom & par);
|
||||
/// leave current MathInset to the left
|
||||
bool popLeft(LCursor & cur);
|
||||
/// leave current MathInset to the left
|
||||
bool popRight(LCursor & cur);
|
||||
|
||||
/// returns the normalized anchor of the selection
|
||||
CursorSlice normalAnchor(LCursor & cur);
|
||||
|
||||
/// dump selection information for debugging
|
||||
void seldump(char const * str);
|
||||
/// dump selection information for debugging
|
||||
void dump(char const * str);
|
||||
/// moves on
|
||||
void setSelection(LCursor & cur, CursorBase const & where, size_type n);
|
||||
/// grab selection marked by anchor and current cursor
|
||||
std::string grabSelection(LCursor & cur);
|
||||
/// guess what
|
||||
std::string grabAndEraseSelection(LCursor & cur);
|
||||
///
|
||||
void insert(LCursor & cur, char c);
|
||||
///
|
||||
void insert(LCursor & cur, std::string const & str);
|
||||
/// lock/unlock inset
|
||||
void insetToggle(LCursor & cur);
|
||||
|
||||
/// hack for reveal codes
|
||||
void markInsert(LCursor & cur);
|
||||
void markErase(LCursor & cur);
|
||||
/// injects content of a cell into parent
|
||||
void pullArg(LCursor & cur);
|
||||
/// split font inset etc
|
||||
void handleFont(LCursor & cur, std::string const & font);
|
||||
///
|
||||
DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
|
||||
|
||||
/// pointer to enclsing LyX inset
|
||||
extern InsetFormulaBase * formula_;
|
||||
}
|
||||
|
||||
void releaseMathCursor(LCursor & cur);
|
||||
|
||||
bool inMathed();
|
||||
|
||||
#endif
|
@ -1077,12 +1077,12 @@ MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
return DispatchResult(true, FINISHED);
|
||||
|
||||
case LFUN_CELL_SPLIT:
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
////recordUndo(cur, Undo::ATOMIC);
|
||||
splitCell(cur);
|
||||
return DispatchResult(true, FINISHED);
|
||||
|
||||
case LFUN_BREAKLINE: {
|
||||
//recordUndo(cur, Undo::INSERT);
|
||||
////recordUndo(cur, Undo::INSERT);
|
||||
row_type const r = cur.row();
|
||||
addRow(r);
|
||||
|
||||
|
@ -803,7 +803,7 @@ MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
case LFUN_MATH_NUMBER:
|
||||
//lyxerr << "toggling all numbers" << endl;
|
||||
if (display()) {
|
||||
//recordUndo(cur, Undo::INSERT);
|
||||
////recordUndo(cur, Undo::INSERT);
|
||||
bool old = numberedType();
|
||||
if (type_ == "multline")
|
||||
numbered(nrows() - 1, !old);
|
||||
@ -817,7 +817,7 @@ MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
case LFUN_MATH_NONUMBER:
|
||||
if (display()) {
|
||||
row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
|
||||
//recordUndo(cur, Undo::INSERT);
|
||||
////recordUndo(cur, Undo::INSERT);
|
||||
bool old = numbered(r);
|
||||
//cur.bv()->owner()->message(old ? _("No number") : _("Number"));
|
||||
numbered(r, !old);
|
||||
@ -969,7 +969,7 @@ void MathHullInset::handleFont
|
||||
{
|
||||
// this whole function is a hack and won't work for incremental font
|
||||
// changes...
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
|
||||
if (cur.inset()->asMathInset()->name() == font)
|
||||
cur.handleFont(font);
|
||||
@ -982,7 +982,7 @@ void MathHullInset::handleFont
|
||||
|
||||
void MathHullInset::handleFont2(LCursor & cur, string const & arg)
|
||||
{
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
LyXFont font;
|
||||
bool b;
|
||||
bv_funcs::string2font(arg, font, b);
|
||||
|
@ -318,7 +318,7 @@ void MathNestInset::handleFont
|
||||
{
|
||||
// this whole function is a hack and won't work for incremental font
|
||||
// changes...
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
|
||||
if (cur.inset()->asMathInset()->name() == font)
|
||||
cur.handleFont(font);
|
||||
@ -331,7 +331,7 @@ void MathNestInset::handleFont
|
||||
|
||||
void MathNestInset::handleFont2(LCursor & cur, string const & arg)
|
||||
{
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
LyXFont font;
|
||||
bool b;
|
||||
bv_funcs::string2font(arg, font, b);
|
||||
@ -370,7 +370,7 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
is >> n;
|
||||
if (was_macro)
|
||||
cur.macroModeClose();
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
cur.selPaste(n);
|
||||
return DispatchResult(true, true);
|
||||
}
|
||||
@ -462,13 +462,13 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
|
||||
case LFUN_DELETE_WORD_BACKWARD:
|
||||
case LFUN_BACKSPACE:
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
cur.backspace();
|
||||
return DispatchResult(true, true);
|
||||
|
||||
case LFUN_DELETE_WORD_FORWARD:
|
||||
case LFUN_DELETE:
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
cur.erase();
|
||||
return DispatchResult(true, FINISHED);
|
||||
|
||||
@ -484,7 +484,7 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
|
||||
case LFUN_SELFINSERT:
|
||||
if (!cmd.argument.empty()) {
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
if (cmd.argument.size() == 1) {
|
||||
if (cur.interpret(cmd.argument[0]))
|
||||
return DispatchResult(true, true);
|
||||
@ -535,7 +535,7 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
switch (cmd.action) {
|
||||
|
||||
case LFUN_MATH_LIMITS:
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
cur.dispatch(cmd);
|
||||
break;
|
||||
#endif
|
||||
@ -555,7 +555,7 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
}
|
||||
|
||||
case LFUN_CUT:
|
||||
recordUndo(cur, Undo::DELETE);
|
||||
//recordUndo(cur, Undo::DELETE);
|
||||
cur.selCut();
|
||||
return DispatchResult(true, true);
|
||||
|
||||
@ -570,7 +570,7 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
if (cmd.argument.empty()) {
|
||||
// do superscript if LyX handles
|
||||
// deadkeys
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
cur.script(true);
|
||||
}
|
||||
return DispatchResult(true, true);
|
||||
@ -634,7 +634,7 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
cur.selClearOrDel();
|
||||
cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv())));
|
||||
cur.posLeft();
|
||||
cur.pushLeft(cur.nextAtom().nucleus());
|
||||
cur.pushLeft(cur.nextInset());
|
||||
#else
|
||||
if (cur.currentMode() == InsetBase::TEXT_MODE)
|
||||
cur.niceInsert(MathAtom(new MathHullInset("simple")));
|
||||
@ -647,14 +647,14 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
case LFUN_MATH_SIZE:
|
||||
#if 0
|
||||
if (!arg.empty()) {
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
cur.setSize(arg);
|
||||
}
|
||||
#endif
|
||||
return DispatchResult(true, true);
|
||||
|
||||
case LFUN_INSERT_MATRIX: {
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
unsigned int m = 1;
|
||||
unsigned int n = 1;
|
||||
string v_align;
|
||||
@ -680,14 +680,14 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
ls = '(';
|
||||
if (rs.empty())
|
||||
rs = ')';
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
cur.handleNest(MathAtom(new MathDelimInset(ls, rs)));
|
||||
return DispatchResult(true, true);
|
||||
}
|
||||
|
||||
case LFUN_SPACE_INSERT:
|
||||
case LFUN_MATH_SPACE:
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
cur.insert(MathAtom(new MathSpaceInset(",")));
|
||||
return DispatchResult(true, true);
|
||||
|
||||
@ -698,7 +698,7 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
|
||||
case LFUN_INSET_ERT:
|
||||
// interpret this as if a backslash was typed
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
cur.interpret('\\');
|
||||
return DispatchResult(true, true);
|
||||
|
||||
@ -707,7 +707,7 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
|
||||
case LFUN_BREAKPARAGRAPH_SKIP:
|
||||
cmd.argument = "\n";
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
cur.niceInsert(argument);
|
||||
return DispatchResult(true, true);
|
||||
#endif
|
||||
@ -716,7 +716,7 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
// handling such that "self-insert" works on "arbitrary stuff" too, and
|
||||
// math-insert only handles special math things like "matrix".
|
||||
case LFUN_INSERT_MATH:
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
//recordUndo(cur, Undo::ATOMIC);
|
||||
cur.niceInsert(cmd.argument);
|
||||
return DispatchResult(true, true);
|
||||
|
||||
|
@ -1833,6 +1833,18 @@ RowList::iterator Paragraph::getRow(pos_type pos)
|
||||
}
|
||||
|
||||
|
||||
size_t Paragraph::row(pos_type pos) const
|
||||
{
|
||||
RowList::const_iterator rit = rows.end();
|
||||
RowList::const_iterator const begin = rows.begin();
|
||||
|
||||
for (--rit; rit != begin && rit->pos() > pos; --rit)
|
||||
;
|
||||
|
||||
return rit - begin;
|
||||
}
|
||||
|
||||
|
||||
unsigned char Paragraph::transformChar(unsigned char c, pos_type pos) const
|
||||
{
|
||||
if (!Encodings::is_arabic(c))
|
||||
|
@ -329,6 +329,8 @@ public:
|
||||
|
||||
///
|
||||
RowList::iterator getRow(lyx::pos_type pos);
|
||||
///
|
||||
size_t row(lyx::pos_type pos) const;
|
||||
|
||||
///
|
||||
InsetList insetlist;
|
||||
|
36
src/text.C
36
src/text.C
@ -845,7 +845,7 @@ void LyXText::redoParagraph()
|
||||
// same Paragraph one to the right and make a rebreak
|
||||
void LyXText::insertChar(char c)
|
||||
{
|
||||
recordUndo(Undo::INSERT, this, cursor().par(), cursor().par());
|
||||
recordUndo(bv()->cursor(), Undo::INSERT);
|
||||
|
||||
// When the free-spacing option is set for the current layout,
|
||||
// disable the double-space checking
|
||||
@ -1132,7 +1132,7 @@ void LyXText::acceptChange()
|
||||
if (cur.selBegin().par() == cur.par()) {
|
||||
CursorSlice const & startc = cur.selBegin();
|
||||
CursorSlice const & endc = cur.selEnd();
|
||||
recordUndo(Undo::INSERT, this, startc.par());
|
||||
recordUndo(cur, Undo::INSERT, cur.anchor().par());
|
||||
getPar(startc)->acceptChange(startc.pos(), endc.pos());
|
||||
finishUndo();
|
||||
cur.clearSelection();
|
||||
@ -1152,7 +1152,7 @@ void LyXText::rejectChange()
|
||||
if (cur.selBegin().par() == cur.selEnd().par()) {
|
||||
CursorSlice const & startc = cur.selBegin();
|
||||
CursorSlice const & endc = cur.selEnd();
|
||||
recordUndo(Undo::INSERT, this, startc.par());
|
||||
recordUndo(cur, Undo::INSERT, cur.anchor().par());
|
||||
getPar(startc)->rejectChange(startc.pos(), endc.pos());
|
||||
finishUndo();
|
||||
cur.clearSelection();
|
||||
@ -1240,7 +1240,7 @@ void LyXText::changeCase(LyXText::TextCase action)
|
||||
setCursor(to.par(), to.pos() + 1);
|
||||
}
|
||||
|
||||
recordUndo(Undo::ATOMIC, this, from.par(), to.par());
|
||||
recordUndo(cur, Undo::ATOMIC, cur.anchor().par());
|
||||
|
||||
pos_type pos = from.pos();
|
||||
int par = from.par();
|
||||
@ -1284,9 +1284,9 @@ void LyXText::Delete()
|
||||
cursorRight(true);
|
||||
|
||||
// if you had success make a backspace
|
||||
if (old_cursor.par() != cursor().par() || old_cursor.pos() !=
|
||||
cursor().pos()) {
|
||||
recordUndo(Undo::DELETE, this, old_cursor.par());
|
||||
if (old_cursor.par() != cursor().par()
|
||||
|| old_cursor.pos() != cursor().pos()) {
|
||||
recordUndo(bv()->cursor(), Undo::DELETE, old_cursor.par());
|
||||
backspace();
|
||||
}
|
||||
}
|
||||
@ -1325,7 +1325,7 @@ void LyXText::backspace()
|
||||
}
|
||||
|
||||
if (cursor().par() != 0)
|
||||
recordUndo(Undo::DELETE, this, cursor().par() - 1, cursor().par());
|
||||
recordUndo(bv()->cursor(), Undo::DELETE, cursor().par() - 1);
|
||||
|
||||
ParagraphList::iterator tmppit = cursorPar();
|
||||
// We used to do cursorLeftIntern() here, but it is
|
||||
@ -1364,7 +1364,7 @@ void LyXText::backspace()
|
||||
} else {
|
||||
// this is the code for a normal backspace, not pasting
|
||||
// any paragraphs
|
||||
recordUndo(Undo::DELETE, this, cursor().par());
|
||||
recordUndo(bv()->cursor(), Undo::DELETE);
|
||||
// We used to do cursorLeftIntern() here, but it is
|
||||
// not a good idea since it triggers the auto-delete
|
||||
// mechanism. So we do a cursorLeftIntern()-lite,
|
||||
@ -1457,36 +1457,18 @@ RowList::iterator LyXText::firstRow() const
|
||||
}
|
||||
|
||||
|
||||
ParagraphList::iterator LyXText::firstPar() const
|
||||
{
|
||||
return paragraphs().begin();
|
||||
}
|
||||
|
||||
|
||||
RowList::iterator LyXText::lastRow() const
|
||||
{
|
||||
return boost::prior(endRow());
|
||||
}
|
||||
|
||||
|
||||
ParagraphList::iterator LyXText::lastPar() const
|
||||
{
|
||||
return boost::prior(endPar());
|
||||
}
|
||||
|
||||
|
||||
RowList::iterator LyXText::endRow() const
|
||||
{
|
||||
return paragraphs().back().rows.end();
|
||||
}
|
||||
|
||||
|
||||
ParagraphList::iterator LyXText::endPar() const
|
||||
{
|
||||
return paragraphs().end();
|
||||
}
|
||||
|
||||
|
||||
void LyXText::nextRow(ParagraphList::iterator & pit,
|
||||
RowList::iterator & rit) const
|
||||
{
|
||||
|
66
src/text2.C
66
src/text2.C
@ -213,38 +213,6 @@ void LyXText::setCharFont(
|
||||
}
|
||||
|
||||
|
||||
InsetBase * LyXText::getInset() const
|
||||
{
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
pos_type const pos = cursor().pos();
|
||||
|
||||
if (pos < pit->size() && pit->isInset(pos)) {
|
||||
return pit->getInset(pos);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool LyXText::toggleInset()
|
||||
{
|
||||
InsetBase * inset = getInset();
|
||||
// is there an editable inset at cursor position?
|
||||
if (!isEditableInset(inset))
|
||||
return false;
|
||||
//bv()->owner()->message(inset->editMessage());
|
||||
|
||||
// do we want to keep this?? (JMarc)
|
||||
if (!isHighlyEditableInset(inset))
|
||||
recUndo(cursor().par());
|
||||
|
||||
if (inset->isOpen())
|
||||
inset->close();
|
||||
else
|
||||
inset->open();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// used in setLayout
|
||||
// Asger is not sure we want to do this...
|
||||
void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
|
||||
@ -1086,8 +1054,7 @@ void LyXText::insertStringAsLines(string const & str)
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
pos_type pos = cursor().pos();
|
||||
ParagraphList::iterator endpit = boost::next(cursorPar());
|
||||
|
||||
recUndo(cursor().par());
|
||||
recordUndo(cur, Undo::ATOMIC);
|
||||
|
||||
// only to be sure, should not be neccessary
|
||||
cur.clearSelection();
|
||||
@ -1457,10 +1424,11 @@ DispatchResult LyXText::moveLeftIntern(bool front,
|
||||
|
||||
DispatchResult LyXText::moveUp()
|
||||
{
|
||||
if (cursorPar() == firstPar() && cursorRow() == firstRow())
|
||||
LCursor & cur = bv()->cursor();
|
||||
if (cur.par() == 0 && cursorRow() == firstRow())
|
||||
return DispatchResult(false, FINISHED_UP);
|
||||
cursorUp(false);
|
||||
bv()->cursor().clearSelection();
|
||||
cur.clearSelection();
|
||||
return DispatchResult(true);
|
||||
}
|
||||
|
||||
@ -1468,7 +1436,7 @@ DispatchResult LyXText::moveUp()
|
||||
DispatchResult LyXText::moveDown()
|
||||
{
|
||||
LCursor & cur = bv()->cursor();
|
||||
if (cursorPar() == lastPar() && cursorRow() == lastRow())
|
||||
if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
|
||||
return DispatchResult(false, FINISHED_DOWN);
|
||||
cursorDown(false);
|
||||
cur.clearSelection();
|
||||
@ -1738,13 +1706,13 @@ ParagraphList & LyXText::paragraphs() const
|
||||
|
||||
void LyXText::recUndo(paroffset_type first, paroffset_type last) const
|
||||
{
|
||||
recordUndo(Undo::ATOMIC, this, first, last);
|
||||
recordUndo(bv()->cursor(), Undo::ATOMIC, first, last);
|
||||
}
|
||||
|
||||
|
||||
void LyXText::recUndo(lyx::paroffset_type par) const
|
||||
{
|
||||
recordUndo(Undo::ATOMIC, this, par, par);
|
||||
recordUndo(bv()->cursor(), Undo::ATOMIC, par, par);
|
||||
}
|
||||
|
||||
|
||||
@ -1754,6 +1722,26 @@ bool LyXText::isInInset() const
|
||||
}
|
||||
|
||||
|
||||
bool LyXText::toggleInset()
|
||||
{
|
||||
InsetBase * inset = bv()->cursor().nextInset();
|
||||
// is there an editable inset at cursor position?
|
||||
if (!isEditableInset(inset))
|
||||
return false;
|
||||
//bv()->owner()->message(inset->editMessage());
|
||||
|
||||
// do we want to keep this?? (JMarc)
|
||||
if (!isHighlyEditableInset(inset))
|
||||
recUndo(cursor().par());
|
||||
|
||||
if (inset->isOpen())
|
||||
inset->close();
|
||||
else
|
||||
inset->open();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int defaultRowHeight()
|
||||
{
|
||||
return int(font_metrics::maxHeight(LyXFont(LyXFont::ALL_SANE)) * 1.2);
|
||||
|
@ -670,7 +670,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
if (!cur.mark())
|
||||
cur.clearSelection();
|
||||
finishChange(bv, false);
|
||||
if (cursorPar() == firstPar() && cursorRow() == firstRow())
|
||||
if (cur.par() == 0 && cursorRow() == firstRow())
|
||||
return DispatchResult(false, FINISHED_UP);
|
||||
cursorPrevious();
|
||||
break;
|
||||
@ -679,7 +679,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
if (!cur.mark())
|
||||
cur.clearSelection();
|
||||
finishChange(bv, false);
|
||||
if (cursorPar() == lastPar() && cursorRow() == lastRow())
|
||||
if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
|
||||
return DispatchResult(false, FINISHED_DOWN);
|
||||
cursorNext();
|
||||
break;
|
||||
|
83
src/undo.C
83
src/undo.C
@ -24,8 +24,6 @@
|
||||
#include "lyxtext.h"
|
||||
#include "paragraph.h"
|
||||
|
||||
#include "insets/updatableinset.h" // for dynamic_cast<UpdatableInset *>
|
||||
|
||||
using lyx::paroffset_type;
|
||||
|
||||
|
||||
@ -96,12 +94,17 @@ ParIterator num2pit(Buffer & buf, int num)
|
||||
|
||||
|
||||
void recordUndo(Undo::undo_kind kind,
|
||||
LyXText * text, paroffset_type first_par, paroffset_type last_par,
|
||||
LCursor & cur, paroffset_type first_par, paroffset_type last_par,
|
||||
limited_stack<Undo> & stack)
|
||||
{
|
||||
Buffer & buf = *text->bv()->buffer();
|
||||
if (first_par > last_par) {
|
||||
paroffset_type t = first_par;
|
||||
first_par = last_par;
|
||||
last_par = t;
|
||||
}
|
||||
|
||||
int const end_par = text->paragraphs().size() - last_par;
|
||||
Buffer & buf = *cur.bv().buffer();
|
||||
int const end_par = cur.lastpar() + 1 - last_par;
|
||||
|
||||
// Undo::ATOMIC are always recorded (no overlapping there).
|
||||
// overlapping only with insert and delete inside one paragraph:
|
||||
@ -120,9 +123,11 @@ void recordUndo(Undo::undo_kind kind,
|
||||
|
||||
// make and push the Undo entry
|
||||
int textnum;
|
||||
LyXText * text = cur.text();
|
||||
BOOST_ASSERT(text); // not in mathed (yet)
|
||||
ParIterator pit = text2pit(buf, text, textnum);
|
||||
stack.push(Undo(kind, textnum, pit.index(),
|
||||
first_par, end_par, text->cursor().par(), text->cursor().pos()));
|
||||
first_par, end_par, cur.par(), cur.pos()));
|
||||
//lyxerr << "undo record: " << stack.top() << std::endl;
|
||||
|
||||
// record the relevant paragraphs
|
||||
@ -144,9 +149,9 @@ void recordUndo(Undo::undo_kind kind,
|
||||
|
||||
|
||||
// returns false if no undo possible
|
||||
bool performUndoOrRedo(BufferView * bv, Undo const & undo)
|
||||
bool performUndoOrRedo(BufferView & bv, Undo const & undo)
|
||||
{
|
||||
Buffer & buf = *bv->buffer();
|
||||
Buffer & buf = *bv.buffer();
|
||||
lyxerr << "undo, performing: " << undo << std::endl;
|
||||
ParIterator pit = num2pit(buf, undo.text);
|
||||
LyXText * text = pit.text(buf);
|
||||
@ -185,7 +190,7 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo)
|
||||
|
||||
ParIterator pit2 = num2pit(buf, undo.text);
|
||||
advance(pit2, undo.cursor_par);
|
||||
bv->setCursor(pit2, undo.cursor_pos);
|
||||
bv.setCursor(pit2, undo.cursor_pos);
|
||||
|
||||
finishUndo();
|
||||
return true;
|
||||
@ -193,10 +198,10 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo)
|
||||
|
||||
|
||||
// returns false if no undo possible
|
||||
bool textUndoOrRedo(BufferView * bv,
|
||||
bool textUndoOrRedo(BufferView & bv,
|
||||
limited_stack<Undo> & stack, limited_stack<Undo> & otherstack)
|
||||
{
|
||||
Buffer & buf = *bv->buffer();
|
||||
Buffer & buf = *bv.buffer();
|
||||
if (stack.empty()) {
|
||||
// nothing to do
|
||||
finishUndo();
|
||||
@ -219,8 +224,8 @@ bool textUndoOrRedo(BufferView * bv,
|
||||
advance(last, plist.size() - undo.end_par + 1);
|
||||
otherstack.top().pars.insert(otherstack.top().pars.begin(), first, last);
|
||||
}
|
||||
otherstack.top().cursor_pos = bv->cursor().pos();
|
||||
otherstack.top().cursor_par = bv->cursor().par();
|
||||
otherstack.top().cursor_pos = bv.cursor().pos();
|
||||
otherstack.top().cursor_par = bv.cursor().par();
|
||||
lyxerr << " undo other: " << otherstack.top() << std::endl;
|
||||
}
|
||||
|
||||
@ -254,44 +259,52 @@ void finishUndo()
|
||||
}
|
||||
|
||||
|
||||
bool textUndo(BufferView * bv)
|
||||
bool textUndo(BufferView & bv)
|
||||
{
|
||||
return textUndoOrRedo(bv, bv->buffer()->undostack(),
|
||||
bv->buffer()->redostack());
|
||||
return textUndoOrRedo(bv, bv.buffer()->undostack(),
|
||||
bv.buffer()->redostack());
|
||||
}
|
||||
|
||||
|
||||
bool textRedo(BufferView * bv)
|
||||
bool textRedo(BufferView & bv)
|
||||
{
|
||||
return textUndoOrRedo(bv, bv->buffer()->redostack(),
|
||||
bv->buffer()->undostack());
|
||||
return textUndoOrRedo(bv, bv.buffer()->redostack(),
|
||||
bv.buffer()->undostack());
|
||||
}
|
||||
|
||||
|
||||
void recordUndo(Undo::undo_kind kind,
|
||||
LyXText const * text, paroffset_type first, paroffset_type last)
|
||||
LCursor & cur, paroffset_type first, paroffset_type last)
|
||||
{
|
||||
if (undo_frozen)
|
||||
return;
|
||||
Buffer * buf = text->bv()->buffer();
|
||||
recordUndo(kind, const_cast<LyXText *>(text), first, last, buf->undostack());
|
||||
Buffer * buf = cur.bv().buffer();
|
||||
recordUndo(kind, cur, first, last, buf->undostack());
|
||||
buf->redostack().clear();
|
||||
}
|
||||
|
||||
|
||||
void recordUndo(Undo::undo_kind kind, LyXText const * text, paroffset_type par)
|
||||
{
|
||||
recordUndo(kind, text, par, par);
|
||||
}
|
||||
|
||||
|
||||
void recordUndo(BufferView * bv, Undo::undo_kind kind)
|
||||
{
|
||||
recordUndo(bv->cursor(), kind);
|
||||
}
|
||||
|
||||
|
||||
void recordUndo(LCursor & cur, Undo::undo_kind kind)
|
||||
{
|
||||
recordUndo(kind, cur.bv().text(), cur.bv().text()->cursor().par());
|
||||
recordUndo(kind, cur, cur.par(), cur.par());
|
||||
}
|
||||
|
||||
|
||||
void recordUndo(LCursor & cur, Undo::undo_kind kind, paroffset_type from)
|
||||
{
|
||||
recordUndo(kind, cur, cur.par(), from);
|
||||
}
|
||||
|
||||
|
||||
void recordUndo(LCursor & cur, Undo::undo_kind kind,
|
||||
paroffset_type from, paroffset_type to)
|
||||
{
|
||||
recordUndo(kind, cur, from, to);
|
||||
}
|
||||
|
||||
|
||||
void recordUndoFullDocument(LCursor &)
|
||||
{
|
||||
//recordUndo(Undo::ATOMIC,
|
||||
// cur, 0, cur.bv().text()->paragraphs().size() - 1);
|
||||
}
|
||||
|
49
src/undo.h
49
src/undo.h
@ -20,9 +20,9 @@
|
||||
#include "support/types.h"
|
||||
|
||||
class LCursor;
|
||||
class LyXText;
|
||||
class BufferView;
|
||||
|
||||
|
||||
/**
|
||||
* These are the elements put on the undo stack. Each object
|
||||
* contains complete paragraphs and sufficient information
|
||||
@ -30,61 +30,51 @@ class BufferView;
|
||||
*/
|
||||
class Undo {
|
||||
public:
|
||||
/**
|
||||
* The undo kinds are used to combine consecutive undo recordings
|
||||
* of the same kind.
|
||||
*/
|
||||
/// This is used to combine consecutive undo recordings of the same kind.
|
||||
enum undo_kind {
|
||||
/**
|
||||
* Insert something - these will combine to one big chunk
|
||||
* when many inserts come after each other.
|
||||
*/
|
||||
INSERT,
|
||||
|
||||
/**
|
||||
* Delete something - these will combine to one big chunk
|
||||
* when many deletes come after each other.
|
||||
*/
|
||||
DELETE,
|
||||
|
||||
/// Atomic - each of these will have its own entry in the stack
|
||||
ATOMIC
|
||||
};
|
||||
|
||||
/// constructor
|
||||
Undo(undo_kind kind, int text, int index,
|
||||
int first_par, int end_par, int cursor_par, int cursor_pos);
|
||||
|
||||
public:
|
||||
/// which kind of operation are we recording for?
|
||||
undo_kind kind;
|
||||
|
||||
/// hosting LyXText counted from buffer begin
|
||||
int text;
|
||||
|
||||
/// cell in a tabular or similar
|
||||
int index;
|
||||
|
||||
/// offset to the first paragraph in the paragraph list
|
||||
int first_par;
|
||||
|
||||
/// offset to the last paragraph from the end of parargraph list
|
||||
/// offset to the last paragraph from the end of paragraph list
|
||||
int end_par;
|
||||
|
||||
/// offset to the first paragraph in the paragraph list
|
||||
int cursor_par;
|
||||
|
||||
/// the position of the cursor in the hosting paragraph
|
||||
int cursor_pos;
|
||||
|
||||
/// the contents of the paragraphs saved
|
||||
ParagraphList pars;
|
||||
};
|
||||
|
||||
|
||||
/// this will undo the last action - returns false if no undo possible
|
||||
bool textUndo(BufferView *);
|
||||
bool textUndo(BufferView &);
|
||||
|
||||
/// this will redo the last undo - returns false if no redo possible
|
||||
bool textRedo(BufferView *);
|
||||
bool textRedo(BufferView &);
|
||||
|
||||
/// makes sure the next operation will be stored
|
||||
void finishUndo();
|
||||
@ -95,23 +85,26 @@ void freezeUndo();
|
||||
/// track undos again
|
||||
void unFreezeUndo();
|
||||
|
||||
|
||||
/**
|
||||
* Record undo information - call with the first paragraph that will be changed
|
||||
* and the last paragraph that will be changed. So we give an inclusive
|
||||
* range.
|
||||
* Record undo information - call with the current cursor and the 'other
|
||||
* end' of the range of changed paragraphs. So we give an inclusive range.
|
||||
* This is called before you make the changes to the paragraph, and it
|
||||
* will record the original information of the paragraphs in the undo stack.
|
||||
*/
|
||||
void recordUndo(Undo::undo_kind kind,
|
||||
LyXText const * text, lyx::paroffset_type first, lyx::paroffset_type last);
|
||||
|
||||
/// convienience: prepare undo when change in a single paragraph
|
||||
void recordUndo(Undo::undo_kind kind,
|
||||
LyXText const * text, lyx::paroffset_type par);
|
||||
/// the common case: prepare undo for an arbitrary range
|
||||
void recordUndo(LCursor & cur, Undo::undo_kind kind,
|
||||
lyx::paroffset_type from, lyx::paroffset_type to);
|
||||
|
||||
/// convienience: prepare undo for the paragraph that contains the cursor
|
||||
void recordUndo(BufferView *, Undo::undo_kind kind);
|
||||
void recordUndo(LCursor &, Undo::undo_kind kind);
|
||||
/// convienience: prepare undo for the range between 'from' and cursor.
|
||||
void recordUndo(LCursor & cur, Undo::undo_kind kind, lyx::paroffset_type from);
|
||||
|
||||
/// convienience: prepare undo for the single paragraph containing the cursor
|
||||
void recordUndo(LCursor & cur, Undo::undo_kind kind);
|
||||
|
||||
/// convienience: prepare undo for the single paragraph containing the cursor
|
||||
void recordUndoFullDocument(LCursor & cur);
|
||||
|
||||
/// are we avoiding tracking undos currently?
|
||||
extern bool undo_frozen;
|
||||
|
Loading…
Reference in New Issue
Block a user