Browse Source

reimplement automated rename of fields in Windows Forms Designer

pull/315/head
Siegfried Pammer 12 years ago
parent
commit
b9280c1e8f
  1. 26
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/CSharpDesignerLoader.cs
  2. 12
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs
  3. 19
      src/Main/Base/Project/Src/Services/RefactoringService/FindReferenceService.cs

26
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/CSharpDesignerLoader.cs

@ -15,6 +15,7 @@ using ICSharpCode.NRefactory.CSharp.Resolver; @@ -15,6 +15,7 @@ using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Refactoring;
using Microsoft.CSharp;
using CSharpBinding.Parser;
using CSharpBinding.Refactoring;
@ -205,5 +206,30 @@ namespace CSharpBinding.FormsDesigner @@ -205,5 +206,30 @@ namespace CSharpBinding.FormsDesigner
base.VisitMemberReferenceExpression(memberReferenceExpression);
}
}
protected override void OnComponentRename(object component, string oldName, string newName)
{
base.OnComponentRename(component, oldName, newName);
if (oldName != newName) {
var primaryParseInfo = context.GetPrimaryFileParseInformation();
var compilation = context.GetCompilation();
// Find designer class
ITypeDefinition designerClass = FormsDesignerSecondaryDisplayBinding.GetDesignableClass(primaryParseInfo.UnresolvedFile, compilation, out primaryPart);
ISymbol controlSymbol = designerClass.GetFields(f => f.Name == oldName, GetMemberOptions.IgnoreInheritedMembers)
.SingleOrDefault();
if (controlSymbol != null) {
FindReferenceService.RenameSymbol(controlSymbol, newName, new DummyProgressMonitor())
.ObserveOnUIThread()
.Subscribe(error => SD.MessageService.ShowError(error.Message), // onNext
ex => SD.MessageService.ShowException(ex), // onError
// onCompleted - force refresh of the DesignerCodeFile's parse info, because the code generator
// seems to work with an outdated version, when the document is saved.
() => SD.ParserService.Parse(new FileName(context.DesignerCodeFileDocument.FileName), context.DesignerCodeFileDocument)
);
}
}
}
}
}

12
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs

@ -368,16 +368,10 @@ namespace ICSharpCode.FormsDesigner @@ -368,16 +368,10 @@ namespace ICSharpCode.FormsDesigner
void ComponentChanged(object sender, ComponentChangedEventArgs e)
{
bool loading = this.loader != null && this.loader.Loading;
LoggingService.Debug("Forms designer: ComponentChanged: " + (e.Component == null ? "<null>" : e.Component.ToString()) + ", Member=" + (e.Member == null ? "<null>" : e.Member.Name) + ", OldValue=" + (e.OldValue == null ? "<null>" : e.OldValue.ToString()) + ", NewValue=" + (e.NewValue == null ? "<null>" : e.NewValue.ToString()) + "; Loading=" + loading + "; Unloading=" + this.unloading);
bool loading = loader != null && loader.Loading;
LoggingService.Debug("Forms designer: ComponentChanged: " + (e.Component == null ? "<null>" : e.Component.ToString()) + ", Member=" + (e.Member == null ? "<null>" : e.Member.Name) + ", OldValue=" + (e.OldValue == null ? "<null>" : e.OldValue.ToString()) + ", NewValue=" + (e.NewValue == null ? "<null>" : e.NewValue.ToString()) + "; Loading=" + loading + "; Unloading=" + unloading);
if (!loading && !unloading) {
this.MakeDirty();
#warning Reimplement designer component rename
// if (e.Component != null && e.Member != null && e.Member.Name == "Name" &&
// e.NewValue is string && !object.Equals(e.OldValue, e.NewValue)) {
// // changing the name of the component
// generator.NotifyComponentRenamed(e.Component, (string)e.NewValue, (string)e.OldValue);
// }
MakeDirty();
}
}

19
src/Main/Base/Project/Src/Services/RefactoringService/FindReferenceService.cs

@ -237,11 +237,20 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -237,11 +237,20 @@ namespace ICSharpCode.SharpDevelop.Refactoring
static void ApplyChanges(PatchedFile file)
{
var view = SD.FileService.OpenFile(file.FileName, false);
ITextEditor editor = view.GetService(typeof(ITextEditor)) as ITextEditor;
if (editor == null)
throw new InvalidOperationException("Editor/document not found!");
file.Apply(editor.Document);
var openedFile = SD.FileService.GetOpenedFile(file.FileName);
if (openedFile == null) {
SD.FileService.OpenFile(file.FileName, false);
openedFile = SD.FileService.GetOpenedFile(file.FileName); //?
}
var provider = openedFile.CurrentView.GetService<IFileDocumentProvider>();
if (provider != null) {
var document = provider.GetDocumentForFile(openedFile);
if (document == null)
throw new InvalidOperationException("Editor/document not found!");
file.Apply(document);
openedFile.MakeDirty();
}
}
}

Loading…
Cancel
Save