Skip to content

Commit

Permalink
Auto completion menu now suggests vocabulary files too
Browse files Browse the repository at this point in the history
  • Loading branch information
q55x8x committed Sep 23, 2015
1 parent b9f84cc commit 9010704
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
22 changes: 22 additions & 0 deletions Personality Creator/AutoCompleteItemManager.cs
Expand Up @@ -21,5 +21,27 @@ public static void load()

Items.Add("testItem");
}

public static List<string> getItemsWithVocabFiles(Personality persona)
{
List<string> items = new List<string>();

string[] itemsCopy = new string[Items.Count]; //Have to copy all items to not change "Items"
Items.CopyTo(itemsCopy);

items.AddRange(itemsCopy);

try
{
foreach (FileInfo file in new DirectoryInfo(persona.Directory.FullName + @"\Vocabulary\").GetFiles())
{
items.Add(file.Name.Replace("#", "").Replace(".txt", ""));
}
}
catch (DirectoryNotFoundException dirNotFoundEx)
{ }

return items;
}
}
}
9 changes: 4 additions & 5 deletions Personality Creator/PersonaFiles/Script.cs
Expand Up @@ -18,6 +18,7 @@ public class Script : PersonaFile
#region capsuled fields

private FastColoredTextBox editor;
public AutocompleteMenu autoMenu;

Style VocabStyle = new TextStyle(DataManager.settings.VocabStyle.ForeBrush, DataManager.settings.VocabStyle.BackgroundBrush, DataManager.settings.VocabStyle.FontStyle);
Style CommandStyle = new TextStyle(DataManager.settings.CommandStyle.ForeBrush, DataManager.settings.CommandStyle.BackgroundBrush, DataManager.settings.CommandStyle.FontStyle);
Expand Down Expand Up @@ -113,12 +114,10 @@ public override FATabStripItem CreateTab()
this.editor.TextChanged += this.Editor_TextChanged;
this.editor.KeyDown += this.Editor_KeyDown;
this.editor.MouseMove += this.Editor_MouseMove;
this.editor.MouseUp += Editor_MouseUp;
this.editor.MouseDown += Editor_MouseDown;
this.editor.DoubleClick += Editor_DblClick;
this.editor.MouseUp += this.Editor_MouseUp;
this.editor.MouseDown += this.Editor_MouseDown;

AutocompleteMenu autoMenu = new AutocompleteMenu(this.editor);
autoMenu.Items.SetAutocompleteItems(AutoCompleteItemManager.Items);
autoMenu = new AutocompleteMenu(this.editor); //Autocompletion items will be set upon tab selection to be able to include all vocab files
autoMenu.MinFragmentLength = 2;
autoMenu.TopLevel = true;
autoMenu.Items.MaximumSize = new System.Drawing.Size(200, 300);
Expand Down
5 changes: 5 additions & 0 deletions Personality Creator/frmMain.cs
Expand Up @@ -349,6 +349,11 @@ private List<FATabStripItem> copyTabCollectionAsList(FATabStripItemCollection ta
private void tbStrip_TabStripItemSelectionChanged(TabStripItemChangedEventArgs e)
{
this.CurrentTab = tbStrip.SelectedItem;

if (this.CurrentTab?.Tag.GetType().BaseType == typeof(Script))
{
((Script)this.CurrentTab.Tag).autoMenu.Items.SetAutocompleteItems(AutoCompleteItemManager.getItemsWithVocabFiles(((Script)this.CurrentTab.Tag).Persona));
}
}

private void tbStrip_TabStripItemClosing(TabStripItemClosingEventArgs e)
Expand Down

0 comments on commit 9010704

Please sign in to comment.