Browse Source

Forms designer: Fixed removing and replacing field declarations in VB (the parser obviously specifies the field regions in a different way).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3789 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Christian Hornung 17 years ago
parent
commit
019db94649
  1. 38
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs
  2. 19
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/VBNetDesignerGenerator.cs

38
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs

@ -101,9 +101,7 @@ namespace ICSharpCode.FormsDesigner @@ -101,9 +101,7 @@ namespace ICSharpCode.FormsDesigner
Reparse();
IField field = GetField(formClass, fieldName);
if (field != null) {
int startOffset = this.ViewContent.DesignerCodeFileDocument.PositionToOffset(new TextLocation(0, field.Region.BeginLine - 1));
int endOffset = this.ViewContent.DesignerCodeFileDocument.PositionToOffset(new TextLocation(0, field.Region.EndLine));
this.ViewContent.DesignerCodeFileDocument.Remove(startOffset, endOffset - startOffset);
this.RemoveFieldDeclaration(this.ViewContent.DesignerCodeFileDocument, field);
} else if ((field = GetField(completeClass, fieldName)) != null) {
// TODO: Remove the field in the part where it is declared
LoggingService.Warn("Removing field declaration in non-designer part currently not supported");
@ -138,9 +136,7 @@ namespace ICSharpCode.FormsDesigner @@ -138,9 +136,7 @@ namespace ICSharpCode.FormsDesigner
Reparse();
IField oldField = GetField(formClass, newField.Name);
if (oldField != null) {
int startOffset = this.ViewContent.DesignerCodeFileDocument.PositionToOffset(new TextLocation(0, oldField.Region.BeginLine - 1));
int endOffset = this.ViewContent.DesignerCodeFileDocument.PositionToOffset(new TextLocation(0, oldField.Region.EndLine));
this.ViewContent.DesignerCodeFileDocument.Replace(startOffset, endOffset - startOffset, tabs + GenerateFieldDeclaration(domGenerator, newField) + Environment.NewLine);
this.ReplaceFieldDeclaration(this.ViewContent.DesignerCodeFileDocument, oldField, GenerateFieldDeclaration(domGenerator, newField));
} else {
if ((oldField = GetField(completeClass, newField.Name)) != null) {
// TODO: Replace the field in the part where it is declared
@ -159,6 +155,36 @@ namespace ICSharpCode.FormsDesigner @@ -159,6 +155,36 @@ namespace ICSharpCode.FormsDesigner
protected abstract DomRegion GetReplaceRegion(ICSharpCode.TextEditor.Document.IDocument document, IMethod method);
/// <summary>
/// Removes a field declaration from the source code document.
/// </summary>
/// <remarks>
/// The default implementation assumes that the field region starts at the very beginning
/// of the line of the field declaration and ends at the end of that line.
/// Override this method if that is not the case in a specific language.
/// </remarks>
protected virtual void RemoveFieldDeclaration(IDocument document, IField field)
{
int startOffset = document.PositionToOffset(new TextLocation(0, field.Region.BeginLine - 1));
int endOffset = document.PositionToOffset(new TextLocation(0, field.Region.EndLine));
document.Remove(startOffset, endOffset - startOffset);
}
/// <summary>
/// Replaces a field declaration in the source code document.
/// </summary>
/// <remarks>
/// The default implementation assumes that the field region starts at the very beginning
/// of the line of the field declaration and ends at the end of that line.
/// Override this method if that is not the case in a specific language.
/// </remarks>
protected virtual void ReplaceFieldDeclaration(IDocument document, IField oldField, string newFieldDeclaration)
{
int startOffset = document.PositionToOffset(new TextLocation(0, oldField.Region.BeginLine - 1));
int endOffset = document.PositionToOffset(new TextLocation(0, oldField.Region.EndLine));
document.Replace(startOffset, endOffset - startOffset, tabs + newFieldDeclaration + Environment.NewLine);
}
protected virtual void FixGeneratedCode(IClass formClass, CodeMemberMethod code)
{
}

19
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/VBNetDesignerGenerator.cs

@ -12,6 +12,7 @@ using System.Text; @@ -12,6 +12,7 @@ using System.Text;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.TextEditor;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.PrettyPrinter;
@ -30,6 +31,24 @@ namespace ICSharpCode.FormsDesigner @@ -30,6 +31,24 @@ namespace ICSharpCode.FormsDesigner
return new DomRegion(r.BeginLine + 1, 1, r.EndLine, 1);
}
protected override void RemoveFieldDeclaration(ICSharpCode.TextEditor.Document.IDocument document, IField field)
{
// In VB, the field region begins at the start of the declaration
// and ends on the first column of the line following the declaration.
int startOffset = document.PositionToOffset(new TextLocation(0, field.Region.BeginLine - 1));
int endOffset = document.PositionToOffset(new TextLocation(0, field.Region.EndLine - 1));
document.Remove(startOffset, endOffset - startOffset);
}
protected override void ReplaceFieldDeclaration(ICSharpCode.TextEditor.Document.IDocument document, IField oldField, string newFieldDeclaration)
{
// In VB, the field region begins at the start of the declaration
// and ends on the first column of the line following the declaration.
int startOffset = document.PositionToOffset(new TextLocation(0, oldField.Region.BeginLine - 1));
int endOffset = document.PositionToOffset(new TextLocation(0, oldField.Region.EndLine - 1));
document.Replace(startOffset, endOffset - startOffset, tabs + newFieldDeclaration + Environment.NewLine);
}
protected override string CreateEventHandler(Type eventType, string eventMethodName, string body, string indentation)
{
string param = GenerateParams(eventType);

Loading…
Cancel
Save