Browse Source

GotoDialog: sort by relevance, then alphabetically

AvalonEdit: bugfixes in folding and highlighting

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4932 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
e364a29697
  1. 1
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs
  2. 22
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs
  3. 2
      src/Libraries/AvalonDock/ManagedContent.cs
  4. 3
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingManager.cs
  5. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/NewFolding.cs
  6. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V1Loader.cs
  7. 69
      src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.cs

1
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs

@ -226,6 +226,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (e.ChangedButton == MouseButton.Left && Keyboard.Modifiers == ModifierKeys.Control) { if (e.ChangedButton == MouseButton.Left && Keyboard.Modifiers == ModifierKeys.Control) {
var position = GetPositionFromPoint(e.GetPosition(this)); var position = GetPositionFromPoint(e.GetPosition(this));
if (position != null) { if (position != null) {
Core.AnalyticsMonitorService.TrackFeature(typeof(GoToDefinition).FullName, "Ctrl+Click");
GoToDefinition.Run(this.Adapter, this.Document.GetOffset(position.Value)); GoToDefinition.Run(this.Adapter, this.Document.GetOffset(position.Value));
e.Handled = true; e.Handled = true;
} }

22
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs

@ -55,8 +55,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
AddClassMembers(c, newFoldMarkers); AddClassMembers(c, newFoldMarkers);
} }
foreach (FoldingRegion foldingRegion in parseInfo.CompilationUnit.FoldingRegions) { foreach (FoldingRegion foldingRegion in parseInfo.CompilationUnit.FoldingRegions) {
NewFolding f = new NewFolding(textArea.Document.GetOffset(foldingRegion.Region.BeginLine, foldingRegion.Region.BeginColumn), NewFolding f = new NewFolding(GetOffset(foldingRegion.Region.BeginLine, foldingRegion.Region.BeginColumn),
textArea.Document.GetOffset(foldingRegion.Region.EndLine, foldingRegion.Region.EndColumn)); GetOffset(foldingRegion.Region.EndLine, foldingRegion.Region.EndColumn));
f.DefaultClosed = isFirstUpdate; f.DefaultClosed = isFirstUpdate;
f.Name = foldingRegion.Name; f.Name = foldingRegion.Name;
newFoldMarkers.Add(f); newFoldMarkers.Add(f);
@ -74,8 +74,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (cRegion.IsEmpty) if (cRegion.IsEmpty)
cRegion = c.Region; cRegion = c.Region;
if (cRegion.BeginLine < cRegion.EndLine) { if (cRegion.BeginLine < cRegion.EndLine) {
newFoldMarkers.Add(new NewFolding(textArea.Document.GetOffset(cRegion.BeginLine, cRegion.BeginColumn), newFoldMarkers.Add(new NewFolding(GetOffset(cRegion.BeginLine, cRegion.BeginColumn),
textArea.Document.GetOffset(cRegion.EndLine, cRegion.EndColumn))); GetOffset(cRegion.EndLine, cRegion.EndColumn)));
} }
foreach (IClass innerClass in c.InnerClasses) { foreach (IClass innerClass in c.InnerClasses) {
AddClassMembers(innerClass, newFoldMarkers); AddClassMembers(innerClass, newFoldMarkers);
@ -83,10 +83,20 @@ namespace ICSharpCode.AvalonEdit.AddIn
foreach (IMember m in c.AllMembers) { foreach (IMember m in c.AllMembers) {
if (m.Region.EndLine < m.BodyRegion.EndLine) { if (m.Region.EndLine < m.BodyRegion.EndLine) {
newFoldMarkers.Add(new NewFolding(textArea.Document.GetOffset(m.Region.EndLine, m.Region.EndColumn), newFoldMarkers.Add(new NewFolding(GetOffset(m.Region.EndLine, m.Region.EndColumn),
textArea.Document.GetOffset(m.BodyRegion.EndLine, m.BodyRegion.EndColumn))); GetOffset(m.BodyRegion.EndLine, m.BodyRegion.EndColumn)));
} }
} }
} }
int GetOffset(int line, int column)
{
if (line < 1)
return 0;
var document = textArea.Document;
if (line > document.LineCount)
return document.TextLength;
return document.GetOffset(line, column);
}
} }
} }

2
src/Libraries/AvalonDock/ManagedContent.cs

@ -172,8 +172,6 @@ namespace AvalonDock
_dragEnabledArea.MouseMove += new MouseEventHandler(OnDragMouseMove); _dragEnabledArea.MouseMove += new MouseEventHandler(OnDragMouseMove);
_dragEnabledArea.MouseUp += new MouseButtonEventHandler(OnDragMouseUp); _dragEnabledArea.MouseUp += new MouseButtonEventHandler(OnDragMouseUp);
_dragEnabledArea.MouseLeave += new MouseEventHandler(OnDragMouseLeave); _dragEnabledArea.MouseLeave += new MouseEventHandler(OnDragMouseLeave);
_dragEnabledArea.InputBindings.Add(new InputBinding(ApplicationCommands.Close, new MouseGesture(MouseAction.MiddleClick)));
} }
} }

3
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingManager.cs

@ -201,6 +201,9 @@ namespace ICSharpCode.AvalonEdit.Folding
throw new ArgumentException("newFoldings must be sorted by start offset"); throw new ArgumentException("newFoldings must be sorted by start offset");
previousStartOffset = newFolding.StartOffset; previousStartOffset = newFolding.StartOffset;
if (newFolding.StartOffset == newFolding.EndOffset)
continue; // ignore zero-length foldings
// remove old foldings that were skipped // remove old foldings that were skipped
while (oldFoldingIndex < oldFoldings.Length && newFolding.StartOffset > oldFoldings[oldFoldingIndex].StartOffset) { while (oldFoldingIndex < oldFoldings.Length && newFolding.StartOffset > oldFoldings[oldFoldingIndex].StartOffset) {
this.RemoveFolding(oldFoldings[oldFoldingIndex++]); this.RemoveFolding(oldFoldings[oldFoldingIndex++]);

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/NewFolding.cs

@ -55,7 +55,7 @@ namespace ICSharpCode.AvalonEdit.Folding
/// </summary> /// </summary>
public NewFolding(int start, int end) public NewFolding(int start, int end)
{ {
if (!(start < end)) if (!(start <= end))
throw new ArgumentException("'start' must be less than 'end'"); throw new ArgumentException("'start' must be less than 'end'");
this.StartOffset = start; this.StartOffset = start;
this.EndOffset = end; this.EndOffset = end;

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V1Loader.cs

@ -283,7 +283,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
throw new HighlightingDefinitionInvalidException("Unexpected end of @ sequence, use @@ to look for a single @."); throw new HighlightingDefinitionInvalidException("Unexpected end of @ sequence, use @@ to look for a single @.");
switch (expr[i]) { switch (expr[i]) {
case 'C': // match whitespace or punctuation case 'C': // match whitespace or punctuation
b.Append(@"^[\w\d_]"); b.Append(@"[^\w\d_]");
break; break;
case '!': // negative lookahead case '!': // negative lookahead
{ {

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

@ -11,9 +11,11 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.Core.Presentation; using ICSharpCode.Core.Presentation;
@ -21,7 +23,6 @@ using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; 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
{ {
@ -68,19 +69,24 @@ namespace ICSharpCode.SharpDevelop.Gui
public object Tag; public object Tag;
public string Text { get; private set; } public string Text { get; private set; }
IImage image; IImage image;
int matchType;
public ImageSource ImageSource { public ImageSource ImageSource {
get { return image.ImageSource; } get { return image.ImageSource; }
} }
public GotoEntry(string text, IImage image) public GotoEntry(string text, IImage image, int matchType)
{ {
this.Text = text; this.Text = text;
this.image = image; this.image = image;
this.matchType = matchType;
} }
public int CompareTo(GotoEntry other) public int CompareTo(GotoEntry other)
{ {
int r = matchType.CompareTo(other.matchType);
if (r != 0)
return -r;
return Text.CompareTo(other.Text); return Text.CompareTo(other.Text);
} }
} }
@ -112,11 +118,8 @@ namespace ICSharpCode.SharpDevelop.Gui
listBox.ScrollIntoView(listBox.Items[index]); listBox.ScrollIntoView(listBox.Items[index]);
} }
Dictionary<string, object> visibleEntries = new Dictionary<string, object>(); HashSet<string> visibleEntries = new HashSet<string>();
int bestMatchType;
double bestPriority;
List<GotoEntry> newItems = new List<GotoEntry>(); List<GotoEntry> newItems = new List<GotoEntry>();
GotoEntry bestItem;
void textBoxTextChanged(object sender, TextChangedEventArgs e) void textBoxTextChanged(object sender, TextChangedEventArgs e)
{ {
@ -124,14 +127,12 @@ namespace ICSharpCode.SharpDevelop.Gui
listBox.ItemsSource = null; listBox.ItemsSource = null;
newItems.Clear(); newItems.Clear();
visibleEntries.Clear(); visibleEntries.Clear();
bestItem = null;
if (text.Length == 0) { if (text.Length == 0) {
return; return;
} }
if (text.Length == 1 && !char.IsDigit(text, 0)) { if (text.Length == 1 && !char.IsDigit(text, 0)) {
return; return;
} }
int dotPos = text.IndexOf('.');
int commaPos = text.IndexOf(','); int commaPos = text.IndexOf(',');
if (commaPos < 0) { if (commaPos < 0) {
// use "File, ##" or "File: ##" syntax for line numbers // use "File, ##" or "File: ##" syntax for line numbers
@ -142,9 +143,10 @@ namespace ICSharpCode.SharpDevelop.Gui
} else if (commaPos > 0) { } else if (commaPos > 0) {
string file = text.Substring(0, commaPos).Trim(); string file = text.Substring(0, commaPos).Trim();
string line = text.Substring(commaPos + 1).Trim(); string line = text.Substring(commaPos + 1).Trim();
if (line.StartsWith("line")) { Match m = Regex.Match(line, @"^\w+ (\d+)$");
// remove the word "line" if (m.Success) {
line = line.Substring(4).Trim(); // remove the word "line" (or some localized version of it)
line = m.Groups[1].Value;
} }
int lineNr; int lineNr;
if (!int.TryParse(line, out lineNr)) if (!int.TryParse(line, out lineNr))
@ -159,9 +161,8 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
newItems.Sort(); newItems.Sort();
listBox.ItemsSource = newItems; listBox.ItemsSource = newItems;
if (bestItem != null) { if (newItems.Count > 0) {
listBox.SelectedItem = bestItem; listBox.SelectedItem = newItems[0];
listBox.ScrollIntoView(bestItem);
} }
} }
@ -225,7 +226,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (item.Project != null) { if (item.Project != null) {
display += StringParser.Parse(" ${res:MainWindow.Windows.SearchResultPanel.In} ") + item.Project.Name; display += StringParser.Parse(" ${res:MainWindow.Windows.SearchResultPanel.In} ") + item.Project.Name;
} }
AddItem(display, ClassBrowserIconService.GotoArrow, new FileLineReference(fileName, lineNumber), 0.5, matchType); AddItem(display, ClassBrowserIconService.GotoArrow, new FileLineReference(fileName, lineNumber), matchType);
} }
} }
} }
@ -237,19 +238,7 @@ namespace ICSharpCode.SharpDevelop.Gui
ITextEditor editor = GetEditor(); ITextEditor editor = GetEditor();
if (editor != null) { if (editor != null) {
num = Math.Min(editor.Document.TotalNumberOfLines, Math.Max(1, num)); num = Math.Min(editor.Document.TotalNumberOfLines, Math.Max(1, num));
AddItem(StringParser.Parse("${res:Dialog.Goto.GotoLine} ") + num, ClassBrowserIconService.GotoArrow, num, 0, int.MaxValue); AddItem(StringParser.Parse("${res:Dialog.Goto.GotoLine} ") + num, ClassBrowserIconService.GotoArrow, num, int.MaxValue);
}
}
}
void ShowCompletionData(IList<ICompletionItem> dataList, string text)
{
string lowerText = text.ToLowerInvariant();
foreach (CodeCompletionItem data in dataList.OfType<CodeCompletionItem>()) {
string dataText = data.Text;
int matchType = GetMatchType(text, dataText);
if (matchType >= 0) {
AddItem(data.Entity, data.Image, data.Priority, matchType);
} }
} }
} }
@ -318,28 +307,18 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
void AddItem(string text, IImage image, object tag, double priority, int matchType) void AddItem(string text, IImage image, object tag, int matchType)
{ {
if (visibleEntries.ContainsKey(text)) if (!visibleEntries.Add(text))
return; return;
visibleEntries.Add(text, null); GotoEntry item = new GotoEntry(text, image, matchType);
GotoEntry item = new GotoEntry(text, image);
item.Tag = tag; item.Tag = tag;
if (bestItem == null
|| (tag is IMember && bestItem.Tag is IClass)
|| (!(tag is IClass && bestItem.Tag is IMember)
&& (matchType > bestMatchType || matchType == bestMatchType && priority > bestPriority)))
{
bestItem = item;
bestPriority = priority;
bestMatchType = matchType;
}
newItems.Add(item); newItems.Add(item);
} }
void AddItem(IClass c, int matchType) void AddItem(IClass c, int matchType)
{ {
AddItem(c, ClassBrowserIconService.GetIcon(c), CodeCompletionDataUsageCache.GetPriority(c.DotNetName, true), matchType); AddItem(c, ClassBrowserIconService.GetIcon(c), matchType);
} }
void AddItemIfMatchText(string text, IMember member, IImage image) void AddItemIfMatchText(string text, IMember member, IImage image)
@ -347,13 +326,13 @@ namespace ICSharpCode.SharpDevelop.Gui
string name = member.Name; string name = member.Name;
int matchType = GetMatchType(text, name); int matchType = GetMatchType(text, name);
if (matchType >= 0) { if (matchType >= 0) {
AddItem(member, image, CodeCompletionDataUsageCache.GetPriority(member.DotNetName, true), matchType); AddItem(member, image, matchType);
} }
} }
void AddItem(IEntity e, IImage image, double priority, int matchType) void AddItem(IEntity e, IImage image, int matchType)
{ {
AddItem(e.Name + " (" + e.FullyQualifiedName + ")", image, e, priority, matchType); AddItem(e.Name + " (" + e.FullyQualifiedName + ")", image, e, matchType);
} }
void cancelButtonClick(object sender, RoutedEventArgs e) void cancelButtonClick(object sender, RoutedEventArgs e)

Loading…
Cancel
Save