Browse Source

Part II of: Closing of AbstractInlineRefactorDialog-based dialogs on Undo command is now handled without faking input.

addin-manager-package-subdirectories
Andreas Weizel 12 years ago
parent
commit
6a09d692de
  1. 75
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/AbstractInlineRefactorDialog.cs
  2. 13
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CreateProperties.cs
  3. 8
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CreatePropertiesDialog.xaml.cs

75
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/AbstractInlineRefactorDialog.cs

@ -3,7 +3,6 @@ @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
@ -17,7 +16,6 @@ using ICSharpCode.NRefactory.CSharp; @@ -17,7 +16,6 @@ using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using CSharpBinding.Refactoring;
using ICSharpCode.SharpDevelop.Editor;
@ -25,6 +23,36 @@ namespace CSharpBinding.Refactoring @@ -25,6 +23,36 @@ namespace CSharpBinding.Refactoring
{
public abstract class AbstractInlineRefactorDialog : GroupBox, IOptionBindingContainer, IActiveElement
{
private class UndoableInlineDialogCreation : IUndoableOperation
{
private AbstractInlineRefactorDialog _dialog;
public UndoableInlineDialogCreation(AbstractInlineRefactorDialog dialog)
{
_dialog = dialog;
}
public void Reset()
{
// Remove dialog reference
_dialog = null;
}
public void Undo()
{
if (_dialog != null) {
// Close the dialog
_dialog.Deactivate();
Reset();
}
}
public void Redo()
{
// We don't react to Redo command here...
}
}
protected ITextAnchor anchor;
protected ITextAnchor insertionEndAnchor;
protected ITextEditor editor;
@ -32,6 +60,8 @@ namespace CSharpBinding.Refactoring @@ -32,6 +60,8 @@ namespace CSharpBinding.Refactoring
protected SDRefactoringContext refactoringContext;
protected InsertionContext insertionContext;
private UndoableInlineDialogCreation undoableCreationOperation;
public IInlineUIElement Element { get; set; }
protected AbstractInlineRefactorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor)
@ -44,6 +74,16 @@ namespace CSharpBinding.Refactoring @@ -44,6 +74,16 @@ namespace CSharpBinding.Refactoring
this.insertionContext = context;
this.Background = SystemColors.ControlBrush;
undoableCreationOperation = new UndoableInlineDialogCreation(this);
}
public IUndoableOperation UndoableCreationOperation
{
get
{
return undoableCreationOperation;
}
}
protected virtual void FocusFirstElement()
@ -127,29 +167,6 @@ namespace CSharpBinding.Refactoring @@ -127,29 +167,6 @@ namespace CSharpBinding.Refactoring
protected virtual void Initialize()
{
this.refactoringContext = SDRefactoringContext.Create(editor, CancellationToken.None);
TextDocument textDocument = editor.Document as TextDocument;
if (textDocument != null) {
textDocument.UndoStack.PropertyChanged += UndoStackPropertyChanged;
}
}
void UndoStackPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "CanRedo") {
// Undo command has been triggered?
OnUndoTriggered();
// Unregister from event, again
TextDocument textDocument = editor.Document as TextDocument;
if (textDocument != null) {
textDocument.UndoStack.PropertyChanged -= UndoStackPropertyChanged;
}
}
}
protected virtual void OnUndoTriggered()
{
}
protected virtual void OnInsertionCompleted()
@ -165,11 +182,6 @@ namespace CSharpBinding.Refactoring @@ -165,11 +182,6 @@ namespace CSharpBinding.Refactoring
return;
}
TextDocument textDocument = editor.Document as TextDocument;
if (textDocument != null) {
textDocument.UndoStack.PropertyChanged -= UndoStackPropertyChanged;
}
if (e.Reason == DeactivateReason.ReturnPressed)
OKButtonClick(null, null);
@ -191,6 +203,9 @@ namespace CSharpBinding.Refactoring @@ -191,6 +203,9 @@ namespace CSharpBinding.Refactoring
deactivated = true;
Element.Remove();
// Cut connection with UndoableInlineDialogCreation
undoableCreationOperation.Reset();
insertionContext.Deactivate(null);
}

13
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CreateProperties.cs

@ -5,6 +5,7 @@ using System; @@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Snippets;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop.Editor;
@ -37,16 +38,16 @@ namespace CSharpBinding.Refactoring @@ -37,16 +38,16 @@ namespace CSharpBinding.Refactoring
ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition);
anchor.MovementType = AnchorMovementType.BeforeInsertion;
// Since this snippet doesn't insert anything, fake insertion of 1 character to allow proper Ctrl+Z reaction
// if (context.StartPosition == context.InsertionPosition) {
// textEditor.Document.Insert(context.InsertionPosition, " ");
// context.InsertionPosition++;
// }
CreatePropertiesDialog dialog = new CreatePropertiesDialog(context, textEditor, anchor);
dialog.Element = uiService.CreateInlineUIElement(anchor, dialog);
// Add creation of this inline dialog as undoable operation
TextDocument document = textEditor.Document as TextDocument;
if (document != null) {
document.UndoStack.Push(dialog.UndoableCreationOperation);
}
return dialog;
}

8
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CreatePropertiesDialog.xaml.cs

@ -56,14 +56,6 @@ namespace CSharpBinding.Refactoring @@ -56,14 +56,6 @@ namespace CSharpBinding.Refactoring
SelectAllUnchecked();
}
protected override void OnUndoTriggered()
{
base.OnUndoTriggered();
// Close this dialog on Undo
Deactivate();
}
static IEnumerable<FieldWrapper> FindFields(IType sourceClass)
{
int i = 0;

Loading…
Cancel
Save