Browse Source

PInvoke form now uses the .NET framework's built-in combo box auto-complete, instead of implementing its own.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1173 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 20 years ago
parent
commit
caa6fbc70c
  1. 75
      src/AddIns/Misc/PInvokeAddIn/Project/Src/InsertPInvokeSignaturesForm.cs

75
src/AddIns/Misc/PInvokeAddIn/Project/Src/InsertPInvokeSignaturesForm.cs

@ -35,7 +35,6 @@ namespace ICSharpCode.PInvokeAddIn
ComboBox languageComboBox; ComboBox languageComboBox;
LinkLabel moreInfoLinkLabel; LinkLabel moreInfoLinkLabel;
const char BackspaceCharacter = (char)0x08;
SignatureInfo[] signatures; SignatureInfo[] signatures;
string allLanguages = StringParser.Parse("${res:ICSharpCode.PInvokeAddIn.InsertPInvokeSignaturesForm.AllLanguages}"); string allLanguages = StringParser.Parse("${res:ICSharpCode.PInvokeAddIn.InsertPInvokeSignaturesForm.AllLanguages}");
@ -61,11 +60,13 @@ namespace ICSharpCode.PInvokeAddIn
findButton.Click += new EventHandler(FindButtonClick); findButton.Click += new EventHandler(FindButtonClick);
functionNameComboBox = ((ComboBox)ControlDictionary["FunctionNameComboBox"]); functionNameComboBox = ((ComboBox)ControlDictionary["FunctionNameComboBox"]);
functionNameComboBox.KeyPress += new KeyPressEventHandler(FunctionNameComboBoxKeyPress); functionNameComboBox.AutoCompleteMode = AutoCompleteMode.Suggest;
functionNameComboBox.AutoCompleteSource = AutoCompleteSource.ListItems;
moduleNameComboBox = ((ComboBox)ControlDictionary["ModuleNameComboBox"]); moduleNameComboBox = ((ComboBox)ControlDictionary["ModuleNameComboBox"]);
moduleNameComboBox.KeyPress += new KeyPressEventHandler(ModuleNameComboBoxKeyPress); moduleNameComboBox.AutoCompleteMode = AutoCompleteMode.Suggest;
moduleNameComboBox.AutoCompleteSource = AutoCompleteSource.ListItems;
moreInfoLinkLabel = ((LinkLabel)ControlDictionary["MoreInfoLinkLabel"]); moreInfoLinkLabel = ((LinkLabel)ControlDictionary["MoreInfoLinkLabel"]);
moreInfoLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(MoreInfoLinkClicked); moreInfoLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(MoreInfoLinkClicked);
@ -242,71 +243,7 @@ namespace ICSharpCode.PInvokeAddIn
string GetSignature(SignatureInfo info) string GetSignature(SignatureInfo info)
{ {
return info.Signature.Replace("|", "\r\n"); return info.Signature.Replace("|", "\r\n");
} }
void FunctionNameComboBoxKeyPress(object sender, KeyPressEventArgs e)
{
Autocomplete(functionNameComboBox, e);
}
void ModuleNameComboBoxKeyPress(object sender, KeyPressEventArgs e)
{
Autocomplete(moduleNameComboBox, e);
}
void Autocomplete(ComboBox comboBox, KeyPressEventArgs e)
{
e.Handled = true;
string searchText = String.Empty;
if (e.KeyChar == BackspaceCharacter) {
if ((comboBox.SelectionStart == 1) || (comboBox.SelectionStart == 0)) {
comboBox.Text = String.Empty;
comboBox.SelectionStart = 0;
} else {
comboBox.Text = comboBox.Text.Substring(0, comboBox.SelectionStart - 1);
comboBox.SelectionStart = comboBox.Text.Length;
searchText = GetComboBoxText(comboBox);
}
} else {
searchText = String.Concat(GetComboBoxText(comboBox), e.KeyChar);
comboBox.Text = searchText;
comboBox.SelectionStart = comboBox.Text.Length;
}
if (searchText.Length > 0) {
int index = comboBox.FindString(searchText);
if (index != -1) {
comboBox.SelectedIndex = index;
comboBox.Text = (string)comboBox.Items[index];
comboBox.Select(searchText.Length, comboBox.Text.Length - (searchText.Length));
} else {
comboBox.Text = searchText;
comboBox.SelectionStart = comboBox.Text.Length;
}
}
}
/// <summary>
/// Gets the combo box text that has been typed in by the user
/// ignoring any autocomplete text.
/// </summary>
/// <param name="comboBox">A combo box control.</param>
/// <returns>
/// The combo box text that has been typed in by the user.
/// </returns>
string GetComboBoxText(ComboBox comboBox)
{
string comboBoxText = String.Empty;
if (comboBox.SelectionStart > 0) {
comboBoxText = comboBox.Text.Substring(0, comboBox.SelectionStart);
}
return comboBoxText;
}
string GetSourceFileLanguage() string GetSourceFileLanguage()
{ {

Loading…
Cancel
Save