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
} else if (e.Key == Key.PageDown) { } else if (e.Key == Key.PageDown) {
e.Handled = true; e.Handled = true;
ChangeIndex((int)Math.Round(+listBox.ActualHeight / 20)); 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
if (text.Length == 1 && !char.IsDigit(text, 0)) { if (text.Length == 1 && !char.IsDigit(text, 0)) {
return; 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(','); 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
@ -154,8 +218,12 @@ namespace ICSharpCode.SharpDevelop.Gui
AddSourceFiles(file, lineNr); AddSourceFiles(file, lineNr);
} else { } else {
AddSourceFiles(text, 0); AddSourceFiles(text, 0);
foreach (IUnresolvedTypeDefinition c in SearchClasses(text)) { foreach (IUnresolvedTypeDefinition c in SearchClasses(needle)) {
AddItem(c, GetMatchType(text, c.Name), false); if (!String.IsNullOrEmpty(member)) {
AddAllMembersMatchingText(c, member, false);
} else {
AddItem(c, GetMatchType(needle, c.Name), false);
}
} }
AddAllMembersMatchingText(text); AddAllMembersMatchingText(text);
} }

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

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

Loading…
Cancel
Save