2005-03-05 12:19:14 +01:00
|
|
|
/*
|
|
|
|
* RichEdit - functions dealing with editor object
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-05 12:19:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "editor.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
|
|
|
|
|
|
|
void ME_EmptyUndoStack(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *p, *pNext;
|
|
|
|
|
2005-03-11 11:24:56 +01:00
|
|
|
if (editor->nUndoMode == umIgnore)
|
|
|
|
return;
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
TRACE("Emptying undo stack\n");
|
|
|
|
|
|
|
|
p = editor->pUndoStack;
|
2006-05-15 20:00:15 +02:00
|
|
|
editor->pUndoStack = editor->pUndoStackBottom = NULL;
|
|
|
|
editor->nUndoStackSize = 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
while(p) {
|
|
|
|
pNext = p->next;
|
|
|
|
ME_DestroyDisplayItem(p);
|
|
|
|
p = pNext;
|
|
|
|
}
|
|
|
|
p = editor->pRedoStack;
|
|
|
|
editor->pRedoStack = NULL;
|
|
|
|
while(p) {
|
|
|
|
pNext = p->next;
|
|
|
|
ME_DestroyDisplayItem(p);
|
|
|
|
p = pNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-16 22:57:12 +02:00
|
|
|
ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_DisplayItem *pdi) {
|
2005-03-05 12:19:14 +01:00
|
|
|
if (editor->nUndoMode == umIgnore)
|
|
|
|
return NULL;
|
2006-05-15 20:00:15 +02:00
|
|
|
else if (editor->nUndoLimit == 0)
|
|
|
|
return NULL;
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
|
|
|
{
|
2009-01-30 10:40:02 +01:00
|
|
|
ME_DisplayItem *pItem = ALLOC_OBJ(ME_UndoItem);
|
2005-03-05 12:19:14 +01:00
|
|
|
switch(type)
|
|
|
|
{
|
2008-06-25 16:29:19 +02:00
|
|
|
case diUndoPotentialEndTransaction:
|
|
|
|
/* only should be added for manually typed chars, not undos or redos */
|
|
|
|
assert(editor->nUndoMode == umAddToUndo);
|
|
|
|
/* intentional fall-through to next case */
|
2005-03-05 12:19:14 +01:00
|
|
|
case diUndoEndTransaction:
|
|
|
|
break;
|
|
|
|
case diUndoSetParagraphFormat:
|
|
|
|
assert(pdi);
|
2008-03-16 21:47:01 +01:00
|
|
|
pItem->member.para = pdi->member.para;
|
2005-03-05 12:19:14 +01:00
|
|
|
pItem->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2);
|
2008-03-16 21:47:01 +01:00
|
|
|
*pItem->member.para.pFmt = *pdi->member.para.pFmt;
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
case diUndoInsertRun:
|
|
|
|
assert(pdi);
|
2008-03-16 21:47:01 +01:00
|
|
|
pItem->member.run = pdi->member.run;
|
2005-03-05 12:19:14 +01:00
|
|
|
pItem->member.run.strText = ME_StrDup(pItem->member.run.strText);
|
|
|
|
ME_AddRefStyle(pItem->member.run.style);
|
2008-01-27 19:01:41 +01:00
|
|
|
if (pdi->member.run.ole_obj)
|
|
|
|
{
|
|
|
|
pItem->member.run.ole_obj = ALLOC_OBJ(*pItem->member.run.ole_obj);
|
|
|
|
ME_CopyReObject(pItem->member.run.ole_obj, pdi->member.run.ole_obj);
|
|
|
|
}
|
|
|
|
else pItem->member.run.ole_obj = NULL;
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
case diUndoSetCharFormat:
|
|
|
|
break;
|
|
|
|
case diUndoDeleteRun:
|
|
|
|
case diUndoJoinParagraphs:
|
|
|
|
break;
|
|
|
|
case diUndoSplitParagraph:
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
|
|
|
ME_DisplayItem *prev_para = pdi->member.para.prev_para;
|
2008-08-05 01:19:01 +02:00
|
|
|
assert(pdi->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
|
2005-03-05 12:19:14 +01:00
|
|
|
pItem->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2);
|
2008-08-07 18:31:41 +02:00
|
|
|
pItem->member.para.pFmt->cbSize = sizeof(PARAFORMAT2);
|
|
|
|
pItem->member.para.pFmt->dwMask = 0;
|
2008-08-05 01:19:01 +02:00
|
|
|
*pItem->member.para.pFmt = *pdi->member.para.pFmt;
|
2008-09-30 23:11:19 +02:00
|
|
|
pItem->member.para.border = pdi->member.para.border;
|
2008-08-07 18:31:41 +02:00
|
|
|
pItem->member.para.nFlags = prev_para->member.para.nFlags & ~MEPF_CELL;
|
|
|
|
pItem->member.para.pCell = NULL;
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
default:
|
|
|
|
assert(0 == "AddUndoItem, unsupported item type");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
pItem->type = type;
|
|
|
|
pItem->prev = NULL;
|
|
|
|
if (editor->nUndoMode == umAddToUndo || editor->nUndoMode == umAddBackToUndo)
|
|
|
|
{
|
2008-07-06 21:27:40 +02:00
|
|
|
if (editor->pUndoStack
|
|
|
|
&& editor->pUndoStack->type == diUndoPotentialEndTransaction)
|
|
|
|
{
|
|
|
|
editor->pUndoStack->type = diUndoEndTransaction;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
if (editor->nUndoMode == umAddToUndo)
|
|
|
|
TRACE("Pushing id=%s to undo stack, deleting redo stack\n", ME_GetDITypeName(type));
|
|
|
|
else
|
|
|
|
TRACE("Pushing id=%s to undo stack\n", ME_GetDITypeName(type));
|
2006-05-15 20:00:15 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
pItem->next = editor->pUndoStack;
|
2008-06-25 16:29:19 +02:00
|
|
|
if (type == diUndoEndTransaction || type == diUndoPotentialEndTransaction)
|
2006-05-15 20:00:15 +02:00
|
|
|
editor->nUndoStackSize++;
|
2005-03-05 12:19:14 +01:00
|
|
|
if (editor->pUndoStack)
|
|
|
|
editor->pUndoStack->prev = pItem;
|
2006-05-15 20:00:15 +02:00
|
|
|
else
|
|
|
|
editor->pUndoStackBottom = pItem;
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->pUndoStack = pItem;
|
2006-05-15 20:00:15 +02:00
|
|
|
|
|
|
|
if (editor->nUndoStackSize > editor->nUndoLimit)
|
|
|
|
{ /* remove oldest undo from stack */
|
|
|
|
ME_DisplayItem *p = editor->pUndoStackBottom;
|
|
|
|
while (p->type !=diUndoEndTransaction)
|
|
|
|
p = p->prev; /*find new stack bottom */
|
|
|
|
editor->pUndoStackBottom = p->prev;
|
|
|
|
editor->pUndoStackBottom->next = NULL;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pp = p->next;
|
|
|
|
ME_DestroyDisplayItem(p);
|
|
|
|
p = pp;
|
|
|
|
} while (p);
|
|
|
|
editor->nUndoStackSize--;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
/* any new operation (not redo) clears the redo stack */
|
|
|
|
if (editor->nUndoMode == umAddToUndo) {
|
|
|
|
ME_DisplayItem *p = editor->pRedoStack;
|
|
|
|
while(p)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pp = p->next;
|
|
|
|
ME_DestroyDisplayItem(p);
|
|
|
|
p = pp;
|
|
|
|
}
|
|
|
|
editor->pRedoStack = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (editor->nUndoMode == umAddToRedo)
|
|
|
|
{
|
|
|
|
TRACE("Pushing id=%s to redo stack\n", ME_GetDITypeName(type));
|
|
|
|
pItem->next = editor->pRedoStack;
|
|
|
|
if (editor->pRedoStack)
|
|
|
|
editor->pRedoStack->prev = pItem;
|
|
|
|
editor->pRedoStack = pItem;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
assert(0);
|
|
|
|
return (ME_UndoItem *)pItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-25 16:29:19 +02:00
|
|
|
/**
|
|
|
|
* Commits preceding changes into a transaction that can be undone together.
|
|
|
|
*
|
|
|
|
* This should be called after all the changes occur associated with an event
|
|
|
|
* so that the group of changes can be undone atomically as a transaction.
|
|
|
|
*
|
|
|
|
* This will have no effect the undo mode is set to ignore changes, or if no
|
|
|
|
* changes preceded calling this function before the last time it was called.
|
|
|
|
*
|
|
|
|
* This can also be used to conclude a coalescing transaction (used for grouping
|
|
|
|
* typed characters).
|
|
|
|
*/
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_CommitUndo(ME_TextEditor *editor) {
|
2005-03-11 11:24:56 +01:00
|
|
|
if (editor->nUndoMode == umIgnore)
|
|
|
|
return;
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(editor->nUndoMode == umAddToUndo);
|
|
|
|
|
|
|
|
/* no transactions, no need to commit */
|
|
|
|
if (!editor->pUndoStack)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* no need to commit empty transactions */
|
|
|
|
if (editor->pUndoStack->type == diUndoEndTransaction)
|
|
|
|
return;
|
|
|
|
|
2008-06-25 16:29:19 +02:00
|
|
|
if (editor->pUndoStack->type == diUndoPotentialEndTransaction)
|
|
|
|
{
|
|
|
|
/* Previous transaction was as a result of characters typed,
|
|
|
|
* so the end of this transaction is confirmed. */
|
|
|
|
editor->pUndoStack->type = diUndoEndTransaction;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_AddUndoItem(editor, diUndoEndTransaction, NULL);
|
|
|
|
}
|
|
|
|
|
2008-06-25 16:29:19 +02:00
|
|
|
/**
|
|
|
|
* Groups supsequent changes with previous ones for an undo if coalescing.
|
|
|
|
*
|
|
|
|
* Has no effect if the previous changes were followed by a ME_CommitUndo. This
|
|
|
|
* function will only have an affect if the previous changes were followed by
|
|
|
|
* a call to ME_CommitCoalescingUndo, which allows the transaction to be
|
|
|
|
* continued.
|
|
|
|
*
|
|
|
|
* This allows multiple consecutively typed characters to be grouped together
|
|
|
|
* to be undone by a single undo operation.
|
|
|
|
*/
|
|
|
|
void ME_ContinueCoalescingTransaction(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
ME_DisplayItem* p;
|
|
|
|
|
|
|
|
if (editor->nUndoMode == umIgnore)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(editor->nUndoMode == umAddToUndo);
|
|
|
|
|
|
|
|
p = editor->pUndoStack;
|
|
|
|
|
|
|
|
if (p && p->type == diUndoPotentialEndTransaction) {
|
|
|
|
assert(p->next); /* EndTransactions shouldn't be at bottom of undo stack */
|
|
|
|
editor->pUndoStack = p->next;
|
|
|
|
editor->pUndoStack->prev = NULL;
|
|
|
|
editor->nUndoStackSize--;
|
|
|
|
ME_DestroyDisplayItem(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Commits preceding changes into a undo transaction that can be expanded.
|
|
|
|
*
|
|
|
|
* This function allows the transaction to be reopened with
|
|
|
|
* ME_ContinueCoalescingTransaction in order to continue the transaction. If an
|
|
|
|
* undo item is added to the undo stack as a result of a change without the
|
|
|
|
* transaction being reopened, then the transaction will be ended, and the
|
|
|
|
* changes will become a part of the next transaction.
|
|
|
|
*
|
|
|
|
* This is used to allow typed characters to be grouped together since each
|
|
|
|
* typed character results in a single event, and each event adding undo items
|
|
|
|
* must be committed. Using this function as opposed to ME_CommitUndo allows
|
|
|
|
* multiple events to be grouped, and undone together.
|
|
|
|
*/
|
|
|
|
void ME_CommitCoalescingUndo(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
if (editor->nUndoMode == umIgnore)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(editor->nUndoMode == umAddToUndo);
|
|
|
|
|
|
|
|
/* no transactions, no need to commit */
|
|
|
|
if (!editor->pUndoStack)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* no need to commit empty transactions */
|
|
|
|
if (editor->pUndoStack->type == diUndoEndTransaction)
|
|
|
|
return;
|
|
|
|
if (editor->pUndoStack->type == diUndoPotentialEndTransaction)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ME_AddUndoItem(editor, diUndoPotentialEndTransaction, NULL);
|
|
|
|
}
|
|
|
|
|
2007-01-23 22:00:27 +01:00
|
|
|
static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_UndoItem *pUItem = (ME_UndoItem *)pItem;
|
|
|
|
|
2005-03-11 11:24:56 +01:00
|
|
|
if (editor->nUndoMode == umIgnore)
|
|
|
|
return;
|
2005-03-05 12:19:14 +01:00
|
|
|
TRACE("Playing undo/redo item, id=%s\n", ME_GetDITypeName(pItem->type));
|
|
|
|
|
|
|
|
switch(pItem->type)
|
|
|
|
{
|
2008-06-25 16:29:19 +02:00
|
|
|
case diUndoPotentialEndTransaction:
|
2005-03-05 12:19:14 +01:00
|
|
|
case diUndoEndTransaction:
|
|
|
|
assert(0);
|
|
|
|
case diUndoSetParagraphFormat:
|
|
|
|
{
|
|
|
|
ME_Cursor tmp;
|
2008-08-05 01:19:01 +02:00
|
|
|
ME_DisplayItem *para;
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CursorFromCharOfs(editor, pItem->member.para.nCharOfs, &tmp);
|
2008-08-05 01:19:01 +02:00
|
|
|
para = ME_FindItemBack(tmp.pRun, diParagraph);
|
|
|
|
ME_AddUndoItem(editor, diUndoSetParagraphFormat, para);
|
|
|
|
*para->member.para.pFmt = *pItem->member.para.pFmt;
|
2008-09-30 23:11:19 +02:00
|
|
|
para->member.para.border = pItem->member.para.border;
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case diUndoSetCharFormat:
|
|
|
|
{
|
2009-08-12 15:06:13 +02:00
|
|
|
ME_Cursor start, end;
|
|
|
|
ME_CursorFromCharOfs(editor, pUItem->nStart, &start);
|
2009-08-13 14:43:57 +02:00
|
|
|
end = start;
|
|
|
|
ME_MoveCursorChars(editor, &end, pUItem->nLen);
|
2009-08-12 15:06:13 +02:00
|
|
|
ME_SetCharFormat(editor, &start, &end, &pItem->member.ustyle->fmt);
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case diUndoInsertRun:
|
|
|
|
{
|
2009-08-13 14:44:13 +02:00
|
|
|
ME_Cursor tmp;
|
|
|
|
ME_CursorFromCharOfs(editor, pItem->member.run.nCharOfs, &tmp);
|
|
|
|
ME_InsertRunAtCursor(editor, &tmp, pItem->member.run.style,
|
|
|
|
pItem->member.run.strText->szData,
|
|
|
|
pItem->member.run.strText->nLen,
|
|
|
|
pItem->member.run.nFlags);
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case diUndoDeleteRun:
|
|
|
|
{
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_Cursor tmp;
|
|
|
|
ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp);
|
|
|
|
ME_InternalDeleteText(editor, &tmp, pUItem->nLen, TRUE);
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case diUndoJoinParagraphs:
|
|
|
|
{
|
|
|
|
ME_Cursor tmp;
|
|
|
|
ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp);
|
|
|
|
/* the only thing that's needed is paragraph offset, so no need to split runs */
|
2009-02-09 18:01:35 +01:00
|
|
|
ME_JoinParagraphs(editor, tmp.pPara, TRUE);
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case diUndoSplitParagraph:
|
|
|
|
{
|
|
|
|
ME_Cursor tmp;
|
2008-08-07 18:31:41 +02:00
|
|
|
ME_DisplayItem *this_para, *new_para;
|
|
|
|
BOOL bFixRowStart;
|
|
|
|
int paraFlags = pItem->member.para.nFlags & (MEPF_ROWSTART|MEPF_CELL|MEPF_ROWEND);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp);
|
|
|
|
if (tmp.nOffset)
|
|
|
|
tmp.pRun = ME_SplitRunSimple(editor, tmp.pRun, tmp.nOffset);
|
2009-01-28 07:34:56 +01:00
|
|
|
assert(pUItem->eol_str);
|
2009-02-09 18:01:35 +01:00
|
|
|
this_para = tmp.pPara;
|
2008-08-07 18:31:41 +02:00
|
|
|
bFixRowStart = this_para->member.para.nFlags & MEPF_ROWSTART;
|
|
|
|
if (bFixRowStart)
|
|
|
|
{
|
|
|
|
/* Re-insert the paragraph before the table, making sure the nFlag value
|
|
|
|
* is correct. */
|
|
|
|
this_para->member.para.nFlags &= ~MEPF_ROWSTART;
|
|
|
|
}
|
2008-04-26 20:29:53 +02:00
|
|
|
new_para = ME_SplitParagraph(editor, tmp.pRun, tmp.pRun->member.run.style,
|
2009-01-28 07:34:56 +01:00
|
|
|
pUItem->eol_str, paraFlags);
|
2008-08-07 18:31:41 +02:00
|
|
|
if (bFixRowStart)
|
|
|
|
new_para->member.para.nFlags |= MEPF_ROWSTART;
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(pItem->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
|
2008-03-16 21:47:01 +01:00
|
|
|
*new_para->member.para.pFmt = *pItem->member.para.pFmt;
|
2008-09-30 23:11:19 +02:00
|
|
|
new_para->member.para.border = pItem->member.para.border;
|
2008-08-07 18:31:41 +02:00
|
|
|
if (pItem->member.para.pCell)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pItemCell, *pCell;
|
|
|
|
pItemCell = pItem->member.para.pCell;
|
|
|
|
pCell = new_para->member.para.pCell;
|
|
|
|
pCell->member.cell.nRightBoundary = pItemCell->member.cell.nRightBoundary;
|
2008-09-30 23:11:19 +02:00
|
|
|
pCell->member.cell.border = pItemCell->member.cell.border;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
assert(0 == "PlayUndoItem, unexpected type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-25 16:29:19 +02:00
|
|
|
BOOL ME_Undo(ME_TextEditor *editor) {
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_DisplayItem *p;
|
|
|
|
ME_UndoMode nMode = editor->nUndoMode;
|
|
|
|
|
2005-03-11 11:24:56 +01:00
|
|
|
if (editor->nUndoMode == umIgnore)
|
2008-06-25 16:29:19 +02:00
|
|
|
return FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(nMode == umAddToUndo || nMode == umIgnore);
|
|
|
|
|
|
|
|
/* no undo items ? */
|
|
|
|
if (!editor->pUndoStack)
|
2008-06-25 16:29:19 +02:00
|
|
|
return FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2008-04-11 04:17:14 +02:00
|
|
|
/* watch out for uncommitted transactions ! */
|
2008-06-25 16:29:19 +02:00
|
|
|
assert(editor->pUndoStack->type == diUndoEndTransaction
|
|
|
|
|| editor->pUndoStack->type == diUndoPotentialEndTransaction);
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
editor->nUndoMode = umAddToRedo;
|
|
|
|
p = editor->pUndoStack->next;
|
|
|
|
ME_DestroyDisplayItem(editor->pUndoStack);
|
2008-07-06 21:27:40 +02:00
|
|
|
editor->pUndoStack = p;
|
2005-03-05 12:19:14 +01:00
|
|
|
do {
|
2008-07-06 21:27:40 +02:00
|
|
|
p->prev = NULL;
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_PlayUndoItem(editor, p);
|
2008-07-06 21:27:40 +02:00
|
|
|
editor->pUndoStack = p->next;
|
|
|
|
ME_DestroyDisplayItem(p);
|
|
|
|
p = editor->pUndoStack;
|
2005-03-05 12:19:14 +01:00
|
|
|
} while(p && p->type != diUndoEndTransaction);
|
|
|
|
if (p)
|
|
|
|
p->prev = NULL;
|
2008-09-11 18:45:36 +02:00
|
|
|
ME_MoveCursorFromTableRowStartParagraph(editor);
|
2008-07-06 21:27:40 +02:00
|
|
|
ME_AddUndoItem(editor, diUndoEndTransaction, NULL);
|
2008-08-07 18:31:41 +02:00
|
|
|
ME_CheckTablesForCorruption(editor);
|
2008-07-06 21:27:40 +02:00
|
|
|
editor->nUndoStackSize--;
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->nUndoMode = nMode;
|
|
|
|
ME_UpdateRepaint(editor);
|
2008-06-25 16:29:19 +02:00
|
|
|
return TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2008-06-25 16:29:19 +02:00
|
|
|
BOOL ME_Redo(ME_TextEditor *editor) {
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_DisplayItem *p;
|
|
|
|
ME_UndoMode nMode = editor->nUndoMode;
|
|
|
|
|
|
|
|
assert(nMode == umAddToUndo || nMode == umIgnore);
|
|
|
|
|
2005-03-11 11:24:56 +01:00
|
|
|
if (editor->nUndoMode == umIgnore)
|
2008-06-25 16:29:19 +02:00
|
|
|
return FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
/* no redo items ? */
|
|
|
|
if (!editor->pRedoStack)
|
2008-06-25 16:29:19 +02:00
|
|
|
return FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2008-04-11 04:17:14 +02:00
|
|
|
/* watch out for uncommitted transactions ! */
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(editor->pRedoStack->type == diUndoEndTransaction);
|
|
|
|
|
|
|
|
editor->nUndoMode = umAddBackToUndo;
|
|
|
|
p = editor->pRedoStack->next;
|
|
|
|
ME_DestroyDisplayItem(editor->pRedoStack);
|
2008-07-06 21:27:40 +02:00
|
|
|
editor->pRedoStack = p;
|
2005-03-05 12:19:14 +01:00
|
|
|
do {
|
2008-07-06 21:27:40 +02:00
|
|
|
p->prev = NULL;
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_PlayUndoItem(editor, p);
|
2008-07-06 21:27:40 +02:00
|
|
|
editor->pRedoStack = p->next;
|
|
|
|
ME_DestroyDisplayItem(p);
|
|
|
|
p = editor->pRedoStack;
|
2005-03-05 12:19:14 +01:00
|
|
|
} while(p && p->type != diUndoEndTransaction);
|
|
|
|
if (p)
|
|
|
|
p->prev = NULL;
|
2008-09-11 18:45:36 +02:00
|
|
|
ME_MoveCursorFromTableRowStartParagraph(editor);
|
2008-07-06 21:27:40 +02:00
|
|
|
ME_AddUndoItem(editor, diUndoEndTransaction, NULL);
|
2008-08-07 18:31:41 +02:00
|
|
|
ME_CheckTablesForCorruption(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->nUndoMode = nMode;
|
|
|
|
ME_UpdateRepaint(editor);
|
2008-06-25 16:29:19 +02:00
|
|
|
return TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|