From 1c7b08ea20c87bdbbb5534666eaae4d8ae342f59 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 18 Apr 2009 23:15:02 +0000 Subject: [PATCH] Fixed build. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4000 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../PythonBinding/Test/Utils/MockMethod.cs | 13 ++++- .../AvalonEdit.AddIn/Src/CodeEditor.cs | 24 ++++++++- .../AvalonEdit.AddIn/Src/QuickClassBrowser.cs | 49 +++++++++++++++---- .../Misc/UnitTesting/Test/Utils/MockMember.cs | 11 +++++ .../Misc/UnitTesting/Test/Utils/MockMethod.cs | 11 +++++ src/Main/Base/Test/Utils/MockEntity.cs | 6 +++ src/Main/Base/Test/Utils/MockMethod.cs | 12 +++++ src/Main/Base/Test/Utils/MockProperty.cs | 11 +++++ 8 files changed, 125 insertions(+), 12 deletions(-) diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockMethod.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockMethod.cs index e35a706343..2c83cbeb51 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockMethod.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockMethod.cs @@ -271,6 +271,17 @@ namespace PythonBinding.Tests.Utils { throw new NotImplementedException(); } - + + public ICompilationUnit CompilationUnit { + get { + throw new NotImplementedException(); + } + } + + public IProjectContent ProjectContent { + get { + throw new NotImplementedException(); + } + } } } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs index 4f7da45e99..99935176c5 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs @@ -21,6 +21,7 @@ using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Bookmarks; using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Editor; +using System.Windows.Threading; namespace ICSharpCode.AvalonEdit.AddIn { @@ -101,7 +102,26 @@ namespace ICSharpCode.AvalonEdit.AddIn void caret_PositionChanged(object sender, EventArgs e) { - quickClassBrowser.SelectItemAtCaretPosition(textEditorAdapter.Caret.Position); + InvalidateQuickClassBrowserCaretPosition(); + } + + bool quickClassBrowserCaretPositionIsValid; + + /// + /// Only call 'SelectItemAtCaretPosition' once when the caret position + /// changes multiple times (e.g. running refactoring which causes lots of caret changes). + /// + void InvalidateQuickClassBrowserCaretPosition() + { + if (quickClassBrowserCaretPositionIsValid) { + quickClassBrowserCaretPositionIsValid = false; + Dispatcher.BeginInvoke( + DispatcherPriority.Normal, + new Action( + delegate { + quickClassBrowser.SelectItemAtCaretPosition(textEditorAdapter.Caret.Position); + })); + } } void quickClassBrowser_Jump(DomRegion region) @@ -249,7 +269,7 @@ namespace ICSharpCode.AvalonEdit.AddIn quickClassBrowser.Update(parseInfo.MostRecentCompilationUnit); else quickClassBrowser.Update(null); - quickClassBrowser.SelectItemAtCaretPosition(textEditorAdapter.Caret.Position); + InvalidateQuickClassBrowserCaretPosition(); } } } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/QuickClassBrowser.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/QuickClassBrowser.cs index 36be25c7e1..1332f23064 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/QuickClassBrowser.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/QuickClassBrowser.cs @@ -28,12 +28,15 @@ namespace ICSharpCode.AvalonEdit.AddIn const int TYPE_FIELD = 4; const int TYPE_EVENT = 5; + /// + /// ViewModel used for combobox items. + /// class EntityItem : IComparable { IEntity entity; IImage image; string text; - int typeCode; // type code is used for sorting by type + int typeCode; // type code is used for sorting entities by type public IEntity Entity { get { return entity; } @@ -53,16 +56,29 @@ namespace ICSharpCode.AvalonEdit.AddIn image = ClassBrowserIconService.GetIcon(entity); } + /// + /// Text to display in combo box. + /// public string Text { get { return text; } } + /// + /// Image to use in combox box + /// public ImageSource Image { get { return image.ImageSource; } } + /// + /// Gets/Sets whether the item is in the current file. + /// + /// + /// true: item is in current file; + /// false: item is in another part of the partial class + /// public bool IsInSamePart { get; set; } public int CompareTo(EntityItem other) @@ -80,12 +96,18 @@ namespace ICSharpCode.AvalonEdit.AddIn public QuickClassBrowser() { InitializeComponent(); - Update(null); } - List classItems; - List memberItems; + // The lists of items currently visible in the combo boxes. + // These should never be null. + List classItems = new List(); + List memberItems = new List(); + /// + /// Updates the list of available classes. + /// This causes the classes combo box to loose its current selected, + /// so the members combo box will be cleared. + /// public void Update(ICompilationUnit compilationUnit) { classItems = new List(); @@ -104,6 +126,9 @@ namespace ICSharpCode.AvalonEdit.AddIn } } + /// + /// Selects the class and member closest to the specified location. + /// public void SelectItemAtCaretPosition(Location location) { EntityItem matchInside = null; @@ -116,6 +141,9 @@ namespace ICSharpCode.AvalonEdit.AddIn matchInside = item; // when there are multiple matches inside (nested classes), use the last one } else { + // Not a perfect match? + // Try to first the nearest match. We want the classes combo box to always + // have a class selected if possible. int matchDistance = Math.Min(Math.Abs(location.Line - c.Region.BeginLine), Math.Abs(location.Line - c.Region.EndLine)); if (matchDistance < nearestMatchDistance) { @@ -153,6 +181,8 @@ namespace ICSharpCode.AvalonEdit.AddIn void classComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { + // The selected class was changed. + // Update the list of member items to be the list of members of the current class. EntityItem item = classComboBox.SelectedItem as EntityItem; IClass selectedClass = item != null ? item.Entity as IClass : null; memberItems = new List(); @@ -199,16 +229,17 @@ namespace ICSharpCode.AvalonEdit.AddIn { if (region.IsEmpty) return; - if (item.IsInSamePart) { - Action jumpAction = this.JumpAction; - if (jumpAction != null) { - jumpAction(region); - } + Action jumpAction = this.JumpAction; + if (item.IsInSamePart && jumpAction != null) { + jumpAction(region); } else { FileService.JumpToFilePosition(item.Entity.CompilationUnit.FileName, region.BeginLine, region.BeginColumn); } } + /// + /// Action used for jumping to a position inside the current file. + /// public Action JumpAction { get; set; } } } \ No newline at end of file diff --git a/src/AddIns/Misc/UnitTesting/Test/Utils/MockMember.cs b/src/AddIns/Misc/UnitTesting/Test/Utils/MockMember.cs index f8b16fb4ed..1d6a4ff4bf 100644 --- a/src/AddIns/Misc/UnitTesting/Test/Utils/MockMember.cs +++ b/src/AddIns/Misc/UnitTesting/Test/Utils/MockMember.cs @@ -255,5 +255,16 @@ namespace UnitTesting.Tests.Utils throw new NotImplementedException(); } + public ICompilationUnit CompilationUnit { + get { + throw new NotImplementedException(); + } + } + + public IProjectContent ProjectContent { + get { + throw new NotImplementedException(); + } + } } } diff --git a/src/AddIns/Misc/UnitTesting/Test/Utils/MockMethod.cs b/src/AddIns/Misc/UnitTesting/Test/Utils/MockMethod.cs index 6c4ead3911..a717fd82ba 100644 --- a/src/AddIns/Misc/UnitTesting/Test/Utils/MockMethod.cs +++ b/src/AddIns/Misc/UnitTesting/Test/Utils/MockMethod.cs @@ -302,5 +302,16 @@ namespace UnitTesting.Tests.Utils throw new NotImplementedException(); } + public ICompilationUnit CompilationUnit { + get { + return declaringType.CompilationUnit; + } + } + + public IProjectContent ProjectContent { + get { + return declaringType.ProjectContent; + } + } } } diff --git a/src/Main/Base/Test/Utils/MockEntity.cs b/src/Main/Base/Test/Utils/MockEntity.cs index d267e12d11..358edbe371 100644 --- a/src/Main/Base/Test/Utils/MockEntity.cs +++ b/src/Main/Base/Test/Utils/MockEntity.cs @@ -21,5 +21,11 @@ namespace ICSharpCode.SharpDevelop.Tests.Utils return String.Empty; } } + + public override ICompilationUnit CompilationUnit { + get { + throw new NotImplementedException(); + } + } } } diff --git a/src/Main/Base/Test/Utils/MockMethod.cs b/src/Main/Base/Test/Utils/MockMethod.cs index 113f63b15e..ba10e66f6c 100644 --- a/src/Main/Base/Test/Utils/MockMethod.cs +++ b/src/Main/Base/Test/Utils/MockMethod.cs @@ -256,5 +256,17 @@ namespace ICSharpCode.SharpDevelop.Tests.Utils { throw new NotImplementedException(); } + + public ICompilationUnit CompilationUnit { + get { + throw new NotImplementedException(); + } + } + + public IProjectContent ProjectContent { + get { + throw new NotImplementedException(); + } + } } } diff --git a/src/Main/Base/Test/Utils/MockProperty.cs b/src/Main/Base/Test/Utils/MockProperty.cs index 35789b36af..86ebc2a41f 100644 --- a/src/Main/Base/Test/Utils/MockProperty.cs +++ b/src/Main/Base/Test/Utils/MockProperty.cs @@ -281,5 +281,16 @@ namespace ICSharpCode.SharpDevelop.Tests.Utils throw new NotImplementedException(); } + public ICompilationUnit CompilationUnit { + get { + throw new NotImplementedException(); + } + } + + public IProjectContent ProjectContent { + get { + throw new NotImplementedException(); + } + } } }