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

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

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

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

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

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

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

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

@ -72,7 +72,7 @@ namespace ICSharpCode.TextEditor.Actions
} }
} }
if (redocounter > 0) { 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
} }
} }
if (redocounter > 0) { 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
} }
if (redocounter > 0) { 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
} }
if (redocounter > 0) { 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
} }
if (redocounter > 0) { 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
} }
if (redocounter > 0) { 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
} }
if (redocounter > 0) { 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
} }
if (redocounter > 0) { 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
{ {
document.Insert(offsetEnd, commentEnd); document.Insert(offsetEnd, commentEnd);
document.Insert(offsetStart, commentStart); document.Insert(offsetStart, commentStart);
document.UndoStack.UndoLast(2); document.UndoStack.CombineLast(2);
} }
void RemoveComment(IDocument document, BlockCommentRegion commentRegion) void RemoveComment(IDocument document, BlockCommentRegion commentRegion)
{ {
document.Remove(commentRegion.EndOffset, commentRegion.CommentEnd.Length); document.Remove(commentRegion.EndOffset, commentRegion.CommentEnd.Length);
document.Remove(commentRegion.StartOffset, commentRegion.CommentStart.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
} }
} }
if (redocounter > 0) { 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
++Caret.Column; ++Caret.Column;
if (removedText) { if (removedText) {
Document.UndoStack.UndoLast(2); Document.UndoStack.CombineLast(2);
} }
if (!updating) { if (!updating) {
@ -780,7 +780,7 @@ namespace ICSharpCode.TextEditor
Caret.Position = Document.OffsetToPosition(oldOffset + str.Length); Caret.Position = Document.OffsetToPosition(oldOffset + str.Length);
} }
if (removedText) { if (removedText) {
Document.UndoStack.UndoLast(2); Document.UndoStack.CombineLast(2);
} }
if (oldLine != Caret.Line) { if (oldLine != Caret.Line) {
UpdateToEnd(oldLine); UpdateToEnd(oldLine);

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

@ -184,7 +184,7 @@ namespace ICSharpCode.TextEditor
textArea.InsertString(text); textArea.InsertString(text);
} }
if (redocounter > 0) { 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
textArea.SelectionManager.ClearSelection(); textArea.SelectionManager.ClearSelection();
InsertString(offset, (string)e.Data.GetData(typeof(string))); InsertString(offset, (string)e.Data.GetData(typeof(string)));
if (two) { if (two) {
textArea.Document.UndoStack.UndoLast(2); textArea.Document.UndoStack.CombineLast(2);
} }
textArea.Document.UpdateQueue.Clear(); textArea.Document.UpdateQueue.Clear();
textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); 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
/// This class stacks the last x operations from the undostack and makes /// This class stacks the last x operations from the undostack and makes
/// one undo/redo operation from it. /// one undo/redo operation from it.
/// </summary> /// </summary>
public class UndoQueue : IUndoableOperation internal sealed class UndoQueue : IUndoableOperation
{ {
List<IUndoableOperation> undolist = new List<IUndoableOperation>(); List<IUndoableOperation> undolist = new List<IUndoableOperation>();
/// <summary> /// <summary>
/// </summary> /// </summary>
public UndoQueue(UndoStack stack, int numops) public UndoQueue(Stack<IUndoableOperation> stack, int numops)
{ {
if (stack == null) { if (stack == null) {
throw new ArgumentNullException("stack"); throw new ArgumentNullException("stack");
} }
Debug.Assert(numops > 0 , "ICSharpCode.TextEditor.Undo.UndoQueue : numops should be > 0"); 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) { for (int i = 0; i < numops; ++i) {
if (stack._UndoStack.Count > 0) { undolist.Add(stack.Pop());
undolist.Add(stack._UndoStack.Pop());
}
} }
} }
public void Undo() public void Undo()
@ -47,6 +48,6 @@ namespace ICSharpCode.TextEditor.Undo
for (int i = undolist.Count - 1 ; i >= 0 ; --i) { for (int i = undolist.Count - 1 ; i >= 0 ; --i) {
undolist[i].Redo(); undolist[i].Redo();
} }
} }
} }
} }

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

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

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

@ -14,7 +14,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Undo
/// This class stacks the last x operations from the undostack and makes /// This class stacks the last x operations from the undostack and makes
/// one undo/redo operation from it. /// one undo/redo operation from it.
/// </summary> /// </summary>
public class UndoQueue : IUndoableOperation internal class UndoQueue : IUndoableOperation
{ {
List<IUndoableOperation> undolist = new List<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
{ {
int undoCount = actionCount; int undoCount = actionCount;
actionCount = undoableActionCountStack.Pop(); actionCount = undoableActionCountStack.Pop();
doc.UndoStack.UndoLast(undoCount); doc.UndoStack.CombineLast(undoCount);
} }
public void UpdateView() public void UpdateView()

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

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

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

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

Loading…
Cancel
Save