From 5fcfe9be4e02d492d3f8ad1eca25d5a5c4895769 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 9 Mar 2007 16:14:46 +0000 Subject: [PATCH] When going to the definition of a CompoundClass, go to the shortest file name. This prevents going to the Designer.cs part instead of the main part. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2436 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../GapTextBufferStrategy.cs | 32 ++++++++++++++++--- .../Src/Implementations/CompoundClass.cs | 17 ++++++++-- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/TextBufferStrategy/GapTextBufferStrategy.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/TextBufferStrategy/GapTextBufferStrategy.cs index 6721b87a10..5dbf6981b5 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/TextBufferStrategy/GapTextBufferStrategy.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/TextBufferStrategy/GapTextBufferStrategy.cs @@ -42,7 +42,7 @@ namespace ICSharpCode.TextEditor.Document } } - public void SetContent(string text) + public void SetContent(string text) { if (text == null) { text = String.Empty; @@ -51,15 +51,27 @@ namespace ICSharpCode.TextEditor.Document gapBeginOffset = gapEndOffset = 0; } - public char GetCharAt(int offset) + public char GetCharAt(int offset) { + #if DEBUG + CheckThread(); + if (offset < 0 || offset >= Length) { + throw new ArgumentOutOfRangeException("offset", offset, "0 <= offset < " + Length.ToString()); + } + #endif return offset < gapBeginOffset ? buffer[offset] : buffer[offset + GapLength]; } - public string GetText(int offset, int length) + public string GetText(int offset, int length) { #if DEBUG CheckThread(); + if (offset < 0 || offset > Length) { + throw new ArgumentOutOfRangeException("offset", offset, "0 <= offset <= " + Length.ToString()); + } + if (length < 0 || offset + length > Length) { + throw new ArgumentOutOfRangeException("length", length, "0 <= length, offset+length <= " + Length.ToString()); + } #endif int end = offset + length; @@ -90,12 +102,22 @@ namespace ICSharpCode.TextEditor.Document Replace(offset, length, String.Empty); } - public void Replace(int offset, int length, string text) + public void Replace(int offset, int length, string text) { if (text == null) { text = String.Empty; } + #if DEBUG + CheckThread(); + if (offset < 0 || offset > Length) { + throw new ArgumentOutOfRangeException("offset", offset, "0 <= offset <= " + Length.ToString()); + } + if (length < 0 || offset + length > Length) { + throw new ArgumentOutOfRangeException("length", length, "0 <= length, offset+length <= " + Length.ToString()); + } + #endif + // Math.Max is used so that if we need to resize the array // the new array has enough space for all old chars PlaceGap(offset + length, Math.Max(text.Length - length, 0)); @@ -103,7 +125,7 @@ namespace ICSharpCode.TextEditor.Document gapBeginOffset += text.Length - length; } - void PlaceGap(int offset, int length) + void PlaceGap(int offset, int length) { int deltaLength = GapLength - length; // if the gap has the right length, move the chars between offset and gap diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/CompoundClass.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/CompoundClass.cs index a823ffd228..d4d1007dad 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/CompoundClass.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/CompoundClass.cs @@ -35,8 +35,10 @@ namespace ICSharpCode.SharpDevelop.Dom /// /// Creates a new CompoundClass with the specified class as first part. /// - public CompoundClass(IClass firstPart) : base(firstPart.CompilationUnit, firstPart.FullyQualifiedName) + public CompoundClass(IClass firstPart) : base(new DefaultCompilationUnit(firstPart.ProjectContent), firstPart.FullyQualifiedName) { + this.CompilationUnit.Classes.Add(this); + parts.Add(firstPart); UpdateInformationFromParts(); } @@ -48,15 +50,23 @@ namespace ICSharpCode.SharpDevelop.Dom { // Common for all parts: this.ClassType = parts[0].ClassType; - this.CompilationUnit.FileName = parts[0].CompilationUnit.FileName; - this.Region = parts[0].Region; ModifierEnum modifier = ModifierEnum.None; const ModifierEnum defaultClassVisibility = ModifierEnum.Internal; this.BaseTypes.Clear(); this.Attributes.Clear(); + + string shortestFileName = null; + foreach (IClass part in parts) { + if (!string.IsNullOrEmpty(part.CompilationUnit.FileName)) { + if (shortestFileName == null || part.CompilationUnit.FileName.Length < shortestFileName.Length) { + shortestFileName = part.CompilationUnit.FileName; + this.Region = part.Region; + } + } + if ((part.Modifiers & ModifierEnum.VisibilityMask) != defaultClassVisibility) { modifier |= part.Modifiers; } else { @@ -71,6 +81,7 @@ namespace ICSharpCode.SharpDevelop.Dom this.Attributes.Add(attribute); } } + this.CompilationUnit.FileName = shortestFileName; if ((modifier & ModifierEnum.VisibilityMask) == ModifierEnum.None) { modifier |= defaultClassVisibility; }