Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit f54083f

Browse files
fix #525: WinForms designer does not properly jump to code when double-clicking a control or event.
1 parent 5ad6289 commit f54083f

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/CSharpEventBindingService.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
using System.Windows.Threading;
2525
using ICSharpCode.Core;
2626
using ICSharpCode.FormsDesigner.Gui.OptionPanels;
27+
using ICSharpCode.NRefactory;
2728
using ICSharpCode.NRefactory.CSharp;
29+
using ICSharpCode.NRefactory.Editor;
2830
using ICSharpCode.NRefactory.TypeSystem;
2931
using ICSharpCode.SharpDevelop;
30-
using ICSharpCode.SharpDevelop.Gui;
32+
using ICSharpCode.SharpDevelop.Editor;
33+
using ICSharpCode.SharpDevelop.Project;
3134
using CSharpBinding.Refactoring;
3235

3336
namespace CSharpBinding.FormsDesigner
@@ -145,17 +148,26 @@ void InsertEventHandlerInternal(string methodName, IEvent evt)
145148
var evtHandler = primary.GetMethods(m => m.Name == methodName, GetMemberOptions.IgnoreInheritedMembers).FirstOrDefault();
146149
if (evtHandler == null) {
147150
generator.InsertEventHandler(primary, methodName, evt, true);
148-
}
149-
else {
151+
} else {
150152
CSharpBinding.Parser.CSharpFullParseInformation parseInfo;
151153
var node = evtHandler.GetDeclaration(out parseInfo) as MethodDeclaration;
154+
var fileName = new FileName(evtHandler.Region.FileName);
155+
var fileContentFinder = new ParseableFileContentFinder();
156+
152157
if (node != null && !node.Body.IsNull) {
153158
var location = node.Body.FirstChild.StartLocation;
154159
var firstStatement = node.Body.Children.OfType<Statement>().FirstOrDefault();
155-
if (firstStatement != null)
160+
161+
if (firstStatement == null) {
162+
var fileContent = fileContentFinder.Create(fileName);
163+
var document = new ReadOnlyDocument(fileContent);
164+
var offset = document.GetOffset(new TextLocation(location.Line + 1, 1));
165+
var length = DocumentUtilities.GetWhitespaceAfter(fileContent, offset).Length;
166+
location = new TextLocation(location.Line + 1, length + 1);
167+
} else {
156168
location = firstStatement.StartLocation;
157-
// TODO : does not jump correctly...
158-
SD.FileService.JumpToFilePosition(new FileName(evtHandler.Region.FileName), location.Line, location.Column);
169+
}
170+
SD.FileService.JumpToFilePosition(fileName, location.Line, location.Column);
159171
}
160172
}
161173
}

src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/ICSharpDesignerLoaderContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public interface ICSharpDesignerLoaderContext
3131
CSharpFullParseInformation GetPrimaryFileParseInformation();
3232
ICompilation GetCompilation();
3333
IDocument GetDocument(FileName fileName);
34+
/// <remarks>if lineNumber = 0 no jump is performed, but the active view content changes.</remarks>
3435
void ShowSourceCode(int lineNumber = 0);
3536
}
3637
}

src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpCodeGenerator.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,10 @@ public override void InsertEventHandler(ITypeDefinition target, string name, IEv
105105
using (Script script = context.StartScript()) {
106106
// FIXME : will not work properly if there are no members.
107107
if (last == match) {
108-
throw new NotImplementedException();
109-
// TODO InsertWithCursor not implemented!
110-
//script.InsertWithCursor("Insert event handler", Script.InsertPosition.End, decl).RunSynchronously();
108+
script.InsertWithCursor("Insert event handler", Script.InsertPosition.End, decl).FireAndForget();
111109
} else {
112-
// TODO does not jump correctly...
113110
script.InsertAfter(node, decl);
114-
editor.JumpTo(throwStmt.StartLocation.Line, throwStmt.StartLocation.Column);
111+
script.Select(throwStmt);
115112
}
116113
}
117114
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,11 @@ public virtual void MergeFormChanges()
662662
this.DesignerCodeFile.IsDirty = isDirty;
663663
}
664664

665+
/// <remarks>if lineNumber = 0 no jump is performed, but the active view content changes.</remarks>
665666
public void ShowSourceCode(int lineNumber = 0)
666667
{
667668
this.WorkbenchWindow.ActiveViewContent = this.PrimaryViewContent;
669+
if (lineNumber <= 0) return;
668670
ITextEditor editor = this.primaryViewContent.GetService<ITextEditor>();
669671
if (editor != null) {
670672
editor.JumpTo(lineNumber, 1);

0 commit comments

Comments
 (0)