Browse Source

Merge pull request #38 from Rpinski/GotoDialog

GotoDialog: Restored search in type members with dot "." in SD 5 + input completion by TAB
pull/40/merge
Andreas Weizel 12 years ago
parent
commit
d471550e27
  1. 72
      src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs
  2. 7
      src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.xaml

72
src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs

@ -107,6 +107,61 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -107,6 +107,61 @@ namespace ICSharpCode.SharpDevelop.Gui
} else if (e.Key == Key.PageDown) {
e.Handled = true;
ChangeIndex((int)Math.Round(+listBox.ActualHeight / 20));
} else if (e.Key == Key.Tab) {
e.Handled = true;
CompleteSelectedEntry();
}
}
private void CompleteSelectedEntry()
{
if (listBox.SelectedItem == null) {
return;
}
string completed = null;
bool partlyComplete = false;
object tag = ((GotoEntry) listBox.SelectedItem).Tag;
if (tag is IUnresolvedEntity) {
IUnresolvedEntity c = tag as IUnresolvedEntity;
completed = c.Name;
partlyComplete = (tag is IUnresolvedMember);
} else if (tag is IEntity) {
IEntity m = tag as IEntity;
completed = m.Name;
partlyComplete = (tag is IMember);
} else if (tag is FileLineReference) {
FileLineReference flref = tag as FileLineReference;
// Only complete if we are not matching with a concrete number
if (flref.Line == 0) {
completed = Path.GetFileName(flref.FileName);
} else {
return;
}
} else {
// Unsupported list item, do nothing
return;
}
if (completed != null) {
string currentText = textBox.Text;
int dotPos = currentText.IndexOf('.');
string needle = currentText;
string member = null;
if (dotPos > 0) {
needle = currentText.Substring(0, dotPos).Trim();
member = currentText.Substring(dotPos + 1).Trim();
}
// Replace the text, set caret to end, so user can continue typing
if (partlyComplete && (member != null)) {
// Only replace the part after the dot
textBox.Text = needle + "." + completed;
} else {
textBox.Text = completed;
}
textBox.CaretIndex = textBox.Text.Length;
}
}
@ -133,6 +188,15 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -133,6 +188,15 @@ namespace ICSharpCode.SharpDevelop.Gui
if (text.Length == 1 && !char.IsDigit(text, 0)) {
return;
}
int dotPos = text.IndexOf('.');
string needle = text;
string member = null;
if (dotPos > 0) {
needle = text.Substring(0, dotPos).Trim();
member = text.Substring(dotPos + 1).Trim();
}
int commaPos = text.IndexOf(',');
if (commaPos < 0) {
// use "File, ##" or "File: ##" syntax for line numbers
@ -154,8 +218,12 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -154,8 +218,12 @@ namespace ICSharpCode.SharpDevelop.Gui
AddSourceFiles(file, lineNr);
} else {
AddSourceFiles(text, 0);
foreach (IUnresolvedTypeDefinition c in SearchClasses(text)) {
AddItem(c, GetMatchType(text, c.Name), false);
foreach (IUnresolvedTypeDefinition c in SearchClasses(needle)) {
if (!String.IsNullOrEmpty(member)) {
AddAllMembersMatchingText(c, member, false);
} else {
AddItem(c, GetMatchType(needle, c.Name), false);
}
}
AddAllMembersMatchingText(text);
}

7
src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.xaml

@ -15,6 +15,11 @@ @@ -15,6 +15,11 @@
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="ListItemImageStyle" TargetType="{x:Type Image}">
<Setter Property="Width" Value="16" />
<Setter Property="Height" Value="16" />
</Style>
</Window.Resources>
<Grid>
@ -46,7 +51,7 @@ @@ -46,7 +51,7 @@
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ImageSource}"/>
<Image Source="{Binding ImageSource}" Style="{StaticResource ListItemImageStyle}"/>
<TextBlock Text="{Binding Text}" Margin="4,0,0,0" Style="{StaticResource ListItemTextStyle}"/>
</StackPanel>
</DataTemplate>

Loading…
Cancel
Save