Backport r35068 and r35075 to branch (bug #3733)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@35076 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2010-08-07 10:45:18 +00:00
parent be178afe7a
commit c94f8347d0
6 changed files with 42 additions and 11 deletions

View File

@ -1746,6 +1746,7 @@ void Buffer::markClean() const
// if the .lyx file has been saved, we don't need an
// autosave
d->bak_clean = true;
d->undo_.markDirty();
}

View File

@ -903,10 +903,14 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
switch (cmd.action) {
case LFUN_UNDO:
flag.setEnabled(buffer_.undo().hasUndoStack());
// 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());
break;
case LFUN_REDO:
flag.setEnabled(buffer_.undo().hasRedoStack());
// 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());
break;
case LFUN_FILE_INSERT:
case LFUN_FILE_INSERT_PLAINTEXT_PARA:

View File

@ -1138,14 +1138,14 @@ void LyXAction::init()
* \li Syntax: undo
* \endvar
*/
{ LFUN_UNDO, "undo", Noop, Edit },
{ LFUN_UNDO, "undo", ReadOnly, Edit },
/*!
* \var lyx::FuncCode lyx::LFUN_REDO
* \li Action: Redoes the last thing undone.
* \li Syntax: redo
* \endvar
*/
{ LFUN_REDO, "redo", Noop, Edit },
{ LFUN_REDO, "redo", ReadOnly, Edit },
/*!
* \var lyx::FuncCode lyx::LFUN_REPEAT
* \li Action: Repeat the given command.

View File

@ -71,9 +71,9 @@ struct UndoElement
StableDocIterator const & cel,
pit_type fro, pit_type en, ParagraphList * pl,
MathData * ar, BufferParams const & bp,
bool ifb, size_t gid) :
bool ifb, bool lc, size_t gid) :
kind(kin), cursor(cur), cell(cel), from(fro), end(en),
pars(pl), array(ar), bparams(0), isFullBuffer(ifb), group_id(gid)
pars(pl), array(ar), bparams(0), isFullBuffer(ifb), lyx_clean(lc), group_id(gid)
{
if (isFullBuffer)
bparams = new BufferParams(bp);
@ -91,6 +91,7 @@ struct UndoElement
bparams = ue.isFullBuffer
? new BufferParams(*ue.bparams) : ue.bparams;
isFullBuffer = ue.isFullBuffer;
lyx_clean = ue.lyx_clean;
group_id = ue.group_id;
}
///
@ -117,6 +118,8 @@ struct UndoElement
BufferParams const * bparams;
/// Only used in case of full backups
bool isFullBuffer;
/// Was the buffer clean at this point?
bool lyx_clean;
/// the element's group id
size_t group_id;
private:
@ -163,6 +166,12 @@ public:
}
}
/// Mark all the elements of the stack as dirty
void markDirty() {
for (size_t i = 0; i != c_.size(); ++i)
c_[i].lyx_clean = false;
}
private:
/// Internal contents.
std::deque<UndoElement> c_;
@ -242,11 +251,11 @@ bool Undo::hasRedoStack() const
}
static bool samePar(StableDocIterator const & i1, StableDocIterator const & i2)
void Undo::markDirty()
{
StableDocIterator tmpi2 = i2;
tmpi2.pos() = i1.pos();
return i1 == tmpi2;
d->undo_finished_ = true;
d->undostack_.markDirty();
d->redostack_.markDirty();
}
@ -256,6 +265,14 @@ static bool samePar(StableDocIterator const & i1, StableDocIterator const & i2)
//
///////////////////////////////////////////////////////////////////////
static bool samePar(StableDocIterator const & i1, StableDocIterator const & i2)
{
StableDocIterator tmpi2 = i2;
tmpi2.pos() = i1.pos();
return i1 == tmpi2;
}
void Undo::Private::doRecordUndo(UndoKind kind,
DocIterator const & cell,
pit_type first_pit, pit_type last_pit,
@ -291,7 +308,7 @@ void Undo::Private::doRecordUndo(UndoKind kind,
LYXERR(Debug::UNDO, "Create undo element of group " << group_id);
// create the position information of the Undo entry
UndoElement undo(kind, cur, cell, from, end, 0, 0,
buffer_.params(), isFullBuffer, group_id);
buffer_.params(), isFullBuffer, buffer_.isClean(), group_id);
// fill in the real data to be saved
if (cell.inMathed()) {
@ -406,6 +423,10 @@ void Undo::Private::doTextUndoOrRedo(DocIterator & cur, UndoElementStack & stack
LASSERT(undo.array == 0, /**/);
cur = undo.cursor.asDocIterator(&buffer_.inset());
if (undo.lyx_clean)
buffer_.markClean();
else
buffer_.markDirty();
// Now that we're done with undo, we pop it off the stack.
stack.pop();
}

View File

@ -67,6 +67,9 @@ public:
///
bool hasRedoStack() const;
/// Mark all the elements of the undo and redo stacks as dirty
void markDirty();
/// open a new group of undo operations.
/**
* Groups can be nested. Such a nested group e.g. { {} {} } is undone in

View File

@ -78,6 +78,8 @@ What's new
- Fix parsing of in-line math environments nested in (unknown to LyX)
text-mode user macros (bug 1337).
- When undo returns to a state where the file was saved, make sure to
reset the (changed) status (bug 3733).
* DOCUMENTATION AND LOCALIZATION