void UpdateSuggestionList()
{
//find suggestion words
_currentLocalText = null;
_sgBox.ClearItems();
if (_textbox.CurrentTextSpan == null)
{
_sgBox.Hide();
return;
}
//-------------------------------------------------------------------------
//sample parse ...
//In this example all country name start with Captial letter so ...
string currentTextSpanText = _textbox.CurrentTextSpan.GetText().ToUpper();
//analyze content
var textBuffer = currentTextSpanText.ToCharArray();
var results = new List <LayoutFarm.Composers.TextSplitBounds>();
results.AddRange(_textbox.TextSplitter.ParseWordContent(textBuffer, 0, textBuffer.Length));
//get last part of splited text
int m = results.Count;
if (m < 1)
{
return;
}
Composers.TextSplitBounds lastSplitPart = results[m - 1];
_currentLocalText = GetString(textBuffer, lastSplitPart);
//char firstChar = currentTextSpanText[0];
char firstChar = _currentLocalText[0];
if (_words.TryGetValue(firstChar, out List <string> keywords))
{
int j = keywords.Count;
int listViewWidth = _sgBox.Width;
for (int i = 0; i < j; ++i)
{
string choice = keywords[i].ToUpper();
if (StringStartsWithChars(choice, _currentLocalText))
{
CustomWidgets.ListItem item = new CustomWidgets.ListItem(listViewWidth, 17);
item.BackColor = KnownColors.LightGray;
item.Tag = item.Text = keywords[i];
_sgBox.AddItem(item);
}
}
}
if (_sgBox.ItemCount > 0)
{
//TODO: implement selectedIndex suggestion hint here
_sgBox.SelectedIndex = 0;
//move listview under caret position
Point caretPos = _textbox.CaretPosition;
//temp fixed
//TODO: review here
if (!_alreadyHasTextBoxGlobalOffset)
{
_textBoxGlobalOffset = _textbox.GetGlobalLocation();
_alreadyHasTextBoxGlobalOffset = true;
}
_sgBox.SetLocation(_textBoxGlobalOffset.X + caretPos.X, caretPos.Y + 70);
_sgBox.Show();
_sgBox.EnsureSelectedItemVisible();
}
else
{
_sgBox.Hide();
}
}