Browse Source

Performance improvements in GotoDialog.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4854 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
39f8dfdd06
  1. 66
      src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.cs
  2. 12
      src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.xaml

66
src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.cs

@ -5,7 +5,6 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -15,11 +14,14 @@ using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.Core.Presentation; using ICSharpCode.Core.Presentation;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using System.Windows.Media;
namespace ICSharpCode.SharpDevelop.Gui namespace ICSharpCode.SharpDevelop.Gui
{ {
@ -61,26 +63,23 @@ namespace ICSharpCode.SharpDevelop.Gui
new Action(delegate { textBoxTextChanged(null, null); })); new Action(delegate { textBoxTextChanged(null, null); }));
} }
class MyListBoxItem : ListBoxItem, IComparable<MyListBoxItem> class GotoEntry : IComparable<GotoEntry>
{ {
public readonly string Text; public object Tag;
public string Text { get; private set; }
IImage image;
public ImageSource ImageSource {
get { return image.ImageSource; }
}
public MyListBoxItem(string text, IImage image) public GotoEntry(string text, IImage image)
{ {
this.Text = text; this.Text = text;
this.Content = new StackPanel { this.image = image;
Orientation = Orientation.Horizontal,
Children = {
image.CreatePixelSnappedImage(),
new TextBlock {
Text = text,
Margin = new Thickness(4, 0, 0, 0)
}
}
};
} }
public int CompareTo(MyListBoxItem other) public int CompareTo(GotoEntry other)
{ {
return Text.CompareTo(other.Text); return Text.CompareTo(other.Text);
} }
@ -98,10 +97,10 @@ namespace ICSharpCode.SharpDevelop.Gui
ChangeIndex(+1); ChangeIndex(+1);
} else if (e.Key == Key.PageUp) { } else if (e.Key == Key.PageUp) {
e.Handled = true; e.Handled = true;
ChangeIndex((int)Math.Round(-listBox.ActualHeight / ((ListBoxItem)listBox.SelectedItem).ActualHeight)); ChangeIndex((int)Math.Round(-listBox.ActualHeight / 20));
} else if (e.Key == Key.PageDown) { } else if (e.Key == Key.PageDown) {
e.Handled = true; e.Handled = true;
ChangeIndex((int)Math.Round(+listBox.ActualHeight / ((ListBoxItem)listBox.SelectedItem).ActualHeight)); ChangeIndex((int)Math.Round(+listBox.ActualHeight / 20));
} }
} }
@ -109,20 +108,20 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
int index = listBox.SelectedIndex; int index = listBox.SelectedIndex;
index = Math.Max(0, Math.Min(listBox.Items.Count - 1, index + increment)); index = Math.Max(0, Math.Min(listBox.Items.Count - 1, index + increment));
((ListBoxItem)listBox.Items[index]).IsSelected = true; listBox.SelectedIndex = index;
listBox.ScrollIntoView(listBox.Items[index]); listBox.ScrollIntoView(listBox.Items[index]);
} }
Dictionary<string, object> visibleEntries = new Dictionary<string, object>(); Dictionary<string, object> visibleEntries = new Dictionary<string, object>();
int bestMatchType; int bestMatchType;
double bestPriority; double bestPriority;
List<MyListBoxItem> newItems = new List<MyListBoxItem>(); List<GotoEntry> newItems = new List<GotoEntry>();
ListBoxItem bestItem; GotoEntry bestItem;
void textBoxTextChanged(object sender, TextChangedEventArgs e) void textBoxTextChanged(object sender, TextChangedEventArgs e)
{ {
string text = textBox.Text.Trim(); string text = textBox.Text.Trim();
listBox.Items.Clear(); listBox.ItemsSource = null;
newItems.Clear(); newItems.Clear();
visibleEntries.Clear(); visibleEntries.Clear();
bestItem = null; bestItem = null;
@ -159,10 +158,9 @@ namespace ICSharpCode.SharpDevelop.Gui
AddAllMembersMatchingText(text); AddAllMembersMatchingText(text);
} }
newItems.Sort(); newItems.Sort();
foreach (MyListBoxItem item in newItems) listBox.ItemsSource = newItems;
listBox.Items.Add(item);
if (bestItem != null) { if (bestItem != null) {
bestItem.IsSelected = true; listBox.SelectedItem = bestItem;
listBox.ScrollIntoView(bestItem); listBox.ScrollIntoView(bestItem);
} }
} }
@ -258,29 +256,28 @@ namespace ICSharpCode.SharpDevelop.Gui
ArrayList SearchClasses(string text) ArrayList SearchClasses(string text)
{ {
string lowerText = text.ToLowerInvariant();
ArrayList list = new ArrayList(); ArrayList list = new ArrayList();
if (ProjectService.OpenSolution != null) { if (ProjectService.OpenSolution != null) {
foreach (IProject project in ProjectService.OpenSolution.Projects) { foreach (IProject project in ProjectService.OpenSolution.Projects) {
IProjectContent projectContent = ParserService.GetProjectContent(project); IProjectContent projectContent = ParserService.GetProjectContent(project);
if (projectContent != null) { if (projectContent != null) {
AddClasses(lowerText, list, projectContent.Classes); AddClasses(text, list, projectContent.Classes);
} }
} }
} }
return list; return list;
} }
void AddClasses(string lowerText, ArrayList list, IEnumerable<IClass> classes) void AddClasses(string text, ArrayList list, IEnumerable<IClass> classes)
{ {
foreach (IClass c in classes) { foreach (IClass c in classes) {
string className = c.Name; string className = c.Name;
if (className.Length >= lowerText.Length) { if (className.Length >= text.Length) {
if (className.ToLowerInvariant().IndexOf(lowerText) >= 0) { if (className.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0) {
list.Add(c); list.Add(c);
} }
} }
AddClasses(lowerText, list, c.InnerClasses); AddClasses(text, list, c.InnerClasses);
} }
} }
@ -296,11 +293,11 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
if (itemText.Length < searchText.Length) if (itemText.Length < searchText.Length)
return MatchType_NoMatch; return MatchType_NoMatch;
int indexInsensitive = itemText.IndexOf(searchText, StringComparison.InvariantCultureIgnoreCase); int indexInsensitive = itemText.IndexOf(searchText, StringComparison.OrdinalIgnoreCase);
if (indexInsensitive < 0) if (indexInsensitive < 0)
return MatchType_NoMatch; return MatchType_NoMatch;
// This is a case insensitive match // This is a case insensitive match
int indexSensitive = itemText.IndexOf(searchText, StringComparison.InvariantCulture); int indexSensitive = itemText.IndexOf(searchText, StringComparison.Ordinal);
if (itemText.Length == searchText.Length) { if (itemText.Length == searchText.Length) {
// this is a full match // this is a full match
if (indexSensitive == 0) if (indexSensitive == 0)
@ -326,8 +323,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (visibleEntries.ContainsKey(text)) if (visibleEntries.ContainsKey(text))
return; return;
visibleEntries.Add(text, null); visibleEntries.Add(text, null);
MyListBoxItem item = new MyListBoxItem(text, image); GotoEntry item = new GotoEntry(text, image);
item.MouseDoubleClick += okButtonClick;
item.Tag = tag; item.Tag = tag;
if (bestItem == null if (bestItem == null
|| (tag is IMember && bestItem.Tag is IClass) || (tag is IMember && bestItem.Tag is IClass)
@ -386,7 +382,7 @@ namespace ICSharpCode.SharpDevelop.Gui
try { try {
if (listBox.SelectedItem == null) if (listBox.SelectedItem == null)
return; return;
object tag = ((ListBoxItem)listBox.SelectedItem).Tag; object tag = ((GotoEntry)listBox.SelectedItem).Tag;
if (tag is int) { if (tag is int) {
ITextEditor editor = GetEditor(); ITextEditor editor = GetEditor();
if (editor != null) { if (editor != null) {

12
src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.xaml

@ -30,7 +30,17 @@
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
Margin="8,4,8,4" Margin="8,4,8,4"
Name="listBox" /> Name="listBox"
MouseDoubleClick="okButtonClick">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ImageSource}"/>
<TextBlock Text="{Binding Text}" Margin="4,0,0,0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button <Button
Content="{core:Localize Global.OKButtonText}" Content="{core:Localize Global.OKButtonText}"
Grid.Column="0" Grid.Column="0"

Loading…
Cancel
Save