Browse Source

Fixed SD2-931: Undo after inserting code template

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2161 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
ca45c905f3
  1. 8
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs
  2. 8
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs
  3. 2
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs
  4. 2
      src/AddIns/Misc/PInvokeAddIn/Project/Src/PInvokeCodeGenerator.cs
  5. 8
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/FormatActions.cs
  6. 12
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/MiscActions.cs
  7. 2
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/FormattingStrategy/DefaultFormattingStrategy.cs
  8. 4
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs
  9. 2
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaClipboardHandler.cs
  10. 2
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaDragDropHandler.cs
  11. 13
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Undo/UndoQueue.cs
  12. 42
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Undo/UndoStack.cs
  13. 2
      src/Main/Base/Project/Src/Internal/Undo/UndoQueue.cs
  14. 2
      src/Main/Base/Project/Src/Services/RefactoringService/TextEditorDocument.cs
  15. 6
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs
  16. 2
      src/Main/Base/Project/Src/TextEditor/XmlFormattingStrategy.cs

8
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs

@ -51,7 +51,7 @@ namespace CSharpBinding.FormattingStrategy @@ -51,7 +51,7 @@ namespace CSharpBinding.FormattingStrategy
r.Reformat(acc, set);
if (acc.ChangedLines > 0)
textArea.Document.UndoStack.UndoLast(2);
textArea.Document.UndoStack.CombineLast(2);
string t = acc.Text;
if (t.Length == 0) {
@ -100,7 +100,7 @@ namespace CSharpBinding.FormattingStrategy @@ -100,7 +100,7 @@ namespace CSharpBinding.FormattingStrategy
}
if (acc.ChangedLines > 0)
textArea.Document.UndoStack.UndoLast(acc.ChangedLines);
textArea.Document.UndoStack.CombineLast(acc.ChangedLines);
}
#endregion
@ -450,7 +450,7 @@ namespace CSharpBinding.FormattingStrategy @@ -450,7 +450,7 @@ namespace CSharpBinding.FormattingStrategy
}
//// adding curline text if present
textArea.Document.Replace(curLine.Offset, curLine.Length, indentation.ToString() + "/// " + curLineText);
textArea.Document.UndoStack.UndoLast(2);
textArea.Document.UndoStack.CombineLast(2);
return indentation.Length + 4 /*+ curLineText.Length*/;
}
@ -459,7 +459,7 @@ namespace CSharpBinding.FormattingStrategy @@ -459,7 +459,7 @@ namespace CSharpBinding.FormattingStrategy
"\" +");
curLine = textArea.Document.GetLineSegment(lineNr);
textArea.Document.Insert(curLine.Offset, "\"");
textArea.Document.UndoStack.UndoLast(3);
textArea.Document.UndoStack.CombineLast(3);
addCursorOffset = 1;
}
}

8
src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs

@ -359,7 +359,7 @@ namespace VBNetBinding.FormattingStrategy @@ -359,7 +359,7 @@ namespace VBNetBinding.FormattingStrategy
}
textArea.Document.Replace(curLine.Offset, curLine.Length, indentation + curLineText.Trim());
textArea.Document.UndoStack.UndoLast(undoCount + 1);
textArea.Document.UndoStack.CombineLast(undoCount + 1);
return indentation.Length;
}
}
@ -376,7 +376,7 @@ namespace VBNetBinding.FormattingStrategy @@ -376,7 +376,7 @@ namespace VBNetBinding.FormattingStrategy
if (IsElseConstruct(lineAboveText))
SmartIndentLine(textArea, lineNr - 1);
int result = SmartIndentLine(textArea, lineNr) + 1;
textArea.Document.UndoStack.UndoLast(undoCount + 3);
textArea.Document.UndoStack.CombineLast(undoCount + 3);
return result;
} else {
textArea.Document.Insert(lineAbove.Offset + lineAbove.Length,
@ -384,7 +384,7 @@ namespace VBNetBinding.FormattingStrategy @@ -384,7 +384,7 @@ namespace VBNetBinding.FormattingStrategy
if (IsElseConstruct(lineAboveText))
SmartIndentLine(textArea, lineNr - 1);
int result = SmartIndentLine(textArea, lineNr);
textArea.Document.UndoStack.UndoLast(undoCount + 2);
textArea.Document.UndoStack.CombineLast(undoCount + 2);
return result;
}
}
@ -399,7 +399,7 @@ namespace VBNetBinding.FormattingStrategy @@ -399,7 +399,7 @@ namespace VBNetBinding.FormattingStrategy
}
if (IsElseConstruct(lineAboveText))
SmartIndentLine(textArea, lineNr - 1);
textArea.Document.UndoStack.UndoLast(undoCount);
textArea.Document.UndoStack.CombineLast(undoCount);
return indent.Length;
}
}

2
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs

@ -102,7 +102,7 @@ namespace ICSharpCode.WixBinding @@ -102,7 +102,7 @@ namespace ICSharpCode.WixBinding
totalInsertedCharacters += insertedCharacterCount;
}
if (redoCount > 0) {
textArea.Document.UndoStack.UndoLast(redoCount);
textArea.Document.UndoStack.CombineLast(redoCount);
}
return totalInsertedCharacters;

2
src/AddIns/Misc/PInvokeAddIn/Project/Src/PInvokeCodeGenerator.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.PInvokeAddIn @@ -56,7 +56,7 @@ namespace ICSharpCode.PInvokeAddIn
}
if (numOperations > 0) {
textArea.Document.UndoStack.UndoLast(numOperations);
textArea.Document.UndoStack.CombineLast(numOperations);
}
} finally {

8
src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/FormatActions.cs

@ -72,7 +72,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -72,7 +72,7 @@ namespace ICSharpCode.TextEditor.Actions
}
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
document.UndoStack.CombineLast(redocounter); // redo the whole operation (not the single deletes)
}
}
}
@ -94,7 +94,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -94,7 +94,7 @@ namespace ICSharpCode.TextEditor.Actions
}
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
document.UndoStack.CombineLast(redocounter); // redo the whole operation (not the single deletes)
}
}
}
@ -192,7 +192,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -192,7 +192,7 @@ namespace ICSharpCode.TextEditor.Actions
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
document.UndoStack.CombineLast(redocounter); // redo the whole operation (not the single deletes)
}
}
}
@ -215,7 +215,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -215,7 +215,7 @@ namespace ICSharpCode.TextEditor.Actions
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
document.UndoStack.CombineLast(redocounter); // redo the whole operation (not the single deletes)
}
}
}

12
src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/MiscActions.cs

@ -59,7 +59,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -59,7 +59,7 @@ namespace ICSharpCode.TextEditor.Actions
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
document.UndoStack.CombineLast(redocounter); // redo the whole operation (not the single deletes)
}
}
@ -176,7 +176,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -176,7 +176,7 @@ namespace ICSharpCode.TextEditor.Actions
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
document.UndoStack.CombineLast(redocounter); // redo the whole operation (not the single deletes)
}
}
@ -264,7 +264,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -264,7 +264,7 @@ namespace ICSharpCode.TextEditor.Actions
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
document.UndoStack.CombineLast(redocounter); // redo the whole operation (not the single deletes)
}
}
@ -287,7 +287,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -287,7 +287,7 @@ namespace ICSharpCode.TextEditor.Actions
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
document.UndoStack.CombineLast(redocounter); // redo the whole operation (not the single deletes)
}
}
@ -477,14 +477,14 @@ namespace ICSharpCode.TextEditor.Actions @@ -477,14 +477,14 @@ namespace ICSharpCode.TextEditor.Actions
{
document.Insert(offsetEnd, commentEnd);
document.Insert(offsetStart, commentStart);
document.UndoStack.UndoLast(2);
document.UndoStack.CombineLast(2);
}
void RemoveComment(IDocument document, BlockCommentRegion commentRegion)
{
document.Remove(commentRegion.EndOffset, commentRegion.CommentEnd.Length);
document.Remove(commentRegion.StartOffset, commentRegion.CommentStart.Length);
document.UndoStack.UndoLast(2);
document.UndoStack.CombineLast(2);
}
}

2
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/FormattingStrategy/DefaultFormattingStrategy.cs

@ -115,7 +115,7 @@ namespace ICSharpCode.TextEditor.Document @@ -115,7 +115,7 @@ namespace ICSharpCode.TextEditor.Document
}
}
if (redocounter > 0) {
textArea.Document.UndoStack.UndoLast(redocounter);
textArea.Document.UndoStack.CombineLast(redocounter);
}
}

4
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs

@ -738,7 +738,7 @@ namespace ICSharpCode.TextEditor @@ -738,7 +738,7 @@ namespace ICSharpCode.TextEditor
++Caret.Column;
if (removedText) {
Document.UndoStack.UndoLast(2);
Document.UndoStack.CombineLast(2);
}
if (!updating) {
@ -780,7 +780,7 @@ namespace ICSharpCode.TextEditor @@ -780,7 +780,7 @@ namespace ICSharpCode.TextEditor
Caret.Position = Document.OffsetToPosition(oldOffset + str.Length);
}
if (removedText) {
Document.UndoStack.UndoLast(2);
Document.UndoStack.CombineLast(2);
}
if (oldLine != Caret.Line) {
UpdateToEnd(oldLine);

2
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaClipboardHandler.cs

@ -184,7 +184,7 @@ namespace ICSharpCode.TextEditor @@ -184,7 +184,7 @@ namespace ICSharpCode.TextEditor
textArea.InsertString(text);
}
if (redocounter > 0) {
textArea.Document.UndoStack.UndoLast(redocounter + 1); // redo the whole operation
textArea.Document.UndoStack.CombineLast(redocounter + 1); // redo the whole operation
}
}
}

2
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaDragDropHandler.cs

@ -97,7 +97,7 @@ namespace ICSharpCode.TextEditor @@ -97,7 +97,7 @@ namespace ICSharpCode.TextEditor
textArea.SelectionManager.ClearSelection();
InsertString(offset, (string)e.Data.GetData(typeof(string)));
if (two) {
textArea.Document.UndoStack.UndoLast(2);
textArea.Document.UndoStack.CombineLast(2);
}
textArea.Document.UpdateQueue.Clear();
textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));

13
src/Libraries/ICSharpCode.TextEditor/Project/Src/Undo/UndoQueue.cs

@ -15,24 +15,25 @@ namespace ICSharpCode.TextEditor.Undo @@ -15,24 +15,25 @@ namespace ICSharpCode.TextEditor.Undo
/// This class stacks the last x operations from the undostack and makes
/// one undo/redo operation from it.
/// </summary>
public class UndoQueue : IUndoableOperation
internal sealed class UndoQueue : IUndoableOperation
{
List<IUndoableOperation> undolist = new List<IUndoableOperation>();
/// <summary>
/// </summary>
public UndoQueue(UndoStack stack, int numops)
public UndoQueue(Stack<IUndoableOperation> stack, int numops)
{
if (stack == null) {
throw new ArgumentNullException("stack");
}
Debug.Assert(numops > 0 , "ICSharpCode.TextEditor.Undo.UndoQueue : numops should be > 0");
if (numops > stack.Count) {
numops = stack.Count;
}
for (int i = 0; i < numops; ++i) {
if (stack._UndoStack.Count > 0) {
undolist.Add(stack._UndoStack.Pop());
}
undolist.Add(stack.Pop());
}
}
public void Undo()
@ -47,6 +48,6 @@ namespace ICSharpCode.TextEditor.Undo @@ -47,6 +48,6 @@ namespace ICSharpCode.TextEditor.Undo
for (int i = undolist.Count - 1 ; i >= 0 ; --i) {
undolist[i].Redo();
}
}
}
}
}

42
src/Libraries/ICSharpCode.TextEditor/Project/Src/Undo/UndoStack.cs

@ -29,31 +29,44 @@ namespace ICSharpCode.TextEditor.Undo @@ -29,31 +29,44 @@ namespace ICSharpCode.TextEditor.Undo
public event EventHandler ActionRedone;
/// <summary>
/// Gets/Sets if changes to the document are protocolled by the undo stack.
/// Used internally to disable the undo stack temporarily while undoing an action.
/// </summary>
public bool AcceptChanges = true;
internal bool AcceptChanges = true;
/// <summary>
/// This property is EXCLUSIVELY for the UndoQueue class, don't USE it
/// Gets if there are actions on the undo stack.
/// </summary>
internal Stack<IUndoableOperation> _UndoStack {
public bool CanUndo {
get {
return undostack;
return undostack.Count > 0;
}
}
/// <summary>
/// Gets if there are actions on the redo stack.
/// </summary>
public bool CanUndo {
public bool CanRedo {
get {
return undostack.Count > 0;
return redostack.Count > 0;
}
}
/// <summary>
/// Gets the number of actions on the undo stack.
/// </summary>
public bool CanRedo {
public int UndoItemCount {
get {
return redostack.Count > 0;
return undostack.Count;
}
}
/// <summary>
/// Gets the number of actions on the redo stack.
/// </summary>
public int RedoItemCount {
get {
return redostack.Count;
}
}
@ -61,9 +74,15 @@ namespace ICSharpCode.TextEditor.Undo @@ -61,9 +74,15 @@ namespace ICSharpCode.TextEditor.Undo
/// You call this method to pool the last x operations from the undo stack
/// to make 1 operation from it.
/// </summary>
public void CombineLast(int actionCount)
{
undostack.Push(new UndoQueue(undostack, actionCount));
}
[Obsolete("Use CombineLast(int x) instead!")]
public void UndoLast(int x)
{
undostack.Push(new UndoQueue(this, x));
CombineLast(x);
}
/// <summary>
@ -96,7 +115,7 @@ namespace ICSharpCode.TextEditor.Undo @@ -96,7 +115,7 @@ namespace ICSharpCode.TextEditor.Undo
/// Call this method to push an UndoableOperation on the undostack, the redostack
/// will be cleared, if you use this method.
/// </summary>
public void Push(IUndoableOperation operation)
public void Push(IUndoableOperation operation)
{
if (operation == null) {
throw new ArgumentNullException("UndoStack.Push(UndoableOperation operation) : operation can't be null");
@ -106,7 +125,7 @@ namespace ICSharpCode.TextEditor.Undo @@ -106,7 +125,7 @@ namespace ICSharpCode.TextEditor.Undo
undostack.Push(operation);
if (TextEditorControl != null) {
undostack.Push(new UndoableSetCaretPosition(this, TextEditorControl.ActiveTextAreaControl.Caret.Position));
UndoLast(2);
CombineLast(2);
}
ClearRedoStack();
}
@ -121,6 +140,7 @@ namespace ICSharpCode.TextEditor.Undo @@ -121,6 +140,7 @@ namespace ICSharpCode.TextEditor.Undo
}
/// <summary>
/// Clears both the undo and redo stack.
/// </summary>
public void ClearAll()
{

2
src/Main/Base/Project/Src/Internal/Undo/UndoQueue.cs

@ -14,7 +14,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Undo @@ -14,7 +14,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Undo
/// This class stacks the last x operations from the undostack and makes
/// one undo/redo operation from it.
/// </summary>
public class UndoQueue : IUndoableOperation
internal class UndoQueue : IUndoableOperation
{
List<IUndoableOperation> undolist = new List<IUndoableOperation>();

2
src/Main/Base/Project/Src/Services/RefactoringService/TextEditorDocument.cs

@ -105,7 +105,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -105,7 +105,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
{
int undoCount = actionCount;
actionCount = undoableActionCountStack.Pop();
doc.UndoStack.UndoLast(undoCount);
doc.UndoStack.CombineLast(undoCount);
}
public void UpdateView()

6
src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs

@ -369,6 +369,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -369,6 +369,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
public void InsertTemplate(CodeTemplate template)
{
string selectedText = String.Empty;
int undoActionCount = Document.UndoStack.UndoItemCount;
Console.WriteLine("undoActionCount before " + undoActionCount);
if (base.ActiveTextAreaControl.TextArea.SelectionManager.HasSomethingSelected) {
selectedText = base.ActiveTextAreaControl.TextArea.SelectionManager.SelectedText;
ActiveTextAreaControl.TextArea.Caret.Position = ActiveTextAreaControl.TextArea.SelectionManager.SelectionCollection[0].StartPosition;
@ -397,7 +399,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -397,7 +399,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
IndentStyle save1 = TextEditorProperties.IndentStyle;
TextEditorProperties.IndentStyle = IndentStyle.Smart;
Console.WriteLine("Indent between {0} and {1}", beginLine, endLine);
Document.FormattingStrategy.IndentLines(ActiveTextAreaControl.TextArea, beginLine, endLine);
Console.WriteLine("UndoItemCount after " + Document.UndoStack.UndoItemCount);
Document.UndoStack.CombineLast(Document.UndoStack.UndoItemCount - undoActionCount);
EndUpdate();
Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
Document.CommitUpdate();

2
src/Main/Base/Project/Src/TextEditor/XmlFormattingStrategy.cs

@ -186,7 +186,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor @@ -186,7 +186,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor
r.Close();
}
if (changedLines > 1)
document.UndoStack.UndoLast(changedLines);
document.UndoStack.CombineLast(changedLines);
}
#endregion
}

Loading…
Cancel
Save