Browse Source

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
9ce0d70a81
  1. 33
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/AbstractInlineRefactorDialog.cs
  2. 10
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CreateProperties.cs
  3. 10
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CreatePropertiesDialog.xaml.cs

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

@ -3,18 +3,21 @@ @@ -3,18 +3,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Snippets;
using ICSharpCode.Core.Presentation;
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;
@ -124,6 +127,29 @@ namespace CSharpBinding.Refactoring @@ -124,6 +127,29 @@ 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()
@ -139,6 +165,11 @@ namespace CSharpBinding.Refactoring @@ -139,6 +165,11 @@ 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);
@ -150,7 +181,7 @@ namespace CSharpBinding.Refactoring @@ -150,7 +181,7 @@ namespace CSharpBinding.Refactoring
bool deactivated;
void Deactivate()
protected void Deactivate()
{
if (Element == null)
throw new InvalidOperationException("no IInlineUIElement set!");

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

@ -35,13 +35,13 @@ namespace CSharpBinding.Refactoring @@ -35,13 +35,13 @@ namespace CSharpBinding.Refactoring
return null;
ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition);
anchor.MovementType = AnchorMovementType.AfterInsertion;
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++;
}
// if (context.StartPosition == context.InsertionPosition) {
// textEditor.Document.Insert(context.InsertionPosition, " ");
// context.InsertionPosition++;
// }
CreatePropertiesDialog dialog = new CreatePropertiesDialog(context, textEditor, anchor);

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

@ -56,6 +56,14 @@ namespace CSharpBinding.Refactoring @@ -56,6 +56,14 @@ 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;
@ -89,7 +97,6 @@ namespace CSharpBinding.Refactoring @@ -89,7 +97,6 @@ namespace CSharpBinding.Refactoring
if (!hasOnPropertyChanged) {
var nodes = new List<AstNode>();
if (!currentClass.GetAllBaseTypeDefinitions().Any(bt => bt.FullName == "System.ComponentModel.INotifyPropertyChanged")) {
// int insertion = editor.Document.GetOffset(currentClass.BodyRegion.BeginLine, currentClass.BodyRegion.BeginColumn);
AstNode nodeBeforeClassBlock = currentClassDeclaration.LBraceToken;
if (nodeBeforeClassBlock.PrevSibling is NewLineNode) {
// There's a new line before the brace, insert before it!
@ -99,7 +106,6 @@ namespace CSharpBinding.Refactoring @@ -99,7 +106,6 @@ namespace CSharpBinding.Refactoring
AstType interfaceTypeNode = refactoringContext.CreateShortType("System.ComponentModel", "INotifyPropertyChanged", 0);
var directBaseTypes = currentClass.DirectBaseTypes.Where(t => t.FullName != "System.Object");
// if ((directBaseTypes != null) && (directBaseTypes.Count() > 0)) {
if (currentClassDeclaration.BaseTypes.Count > 0) {
script.InsertText(insertion, ", " + interfaceTypeNode.GetText() + " ");
} else {

Loading…
Cancel
Save