Browse Source

Show results of partial match

-requires case independance and a way to actually confirm it
master
desktop-maesty/steve 8 years ago
parent
commit
285b229446
  1. 58
      Assets/Fungus/Scripts/Editor/BlockEditor.cs

58
Assets/Fungus/Scripts/Editor/BlockEditor.cs

@ -331,6 +331,37 @@ namespace Fungus.EditorUtils
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
if(!string.IsNullOrEmpty(commandTextFieldContents))
ShowPartialMatches();
}
private void ShowPartialMatches()
{
var block = target as Block;
var flowchart = (Flowchart)block.GetFlowchart();
var filteredAttributes = GetFilteredSupportedCommands(flowchart);
filteredAttributes = filteredAttributes.Where((x) => {
return x.Value.Category.Contains(commandTextFieldContents) || x.Value.CommandName.Contains(commandTextFieldContents);
}).ToList();
if (filteredAttributes == null || filteredAttributes.Count == 0)
return;
//show results
GUILayout.Space(5);
GUILayout.BeginHorizontal();
GUILayout.TextArea(string.Join("\n", filteredAttributes.Select(x => x.Value.Category + "/" + x.Value.CommandName).ToArray()));
GUILayout.EndHorizontal();
GUILayout.Space(5);
} }
protected virtual void DrawEventHandlerGUI(Flowchart flowchart) protected virtual void DrawEventHandlerGUI(Flowchart flowchart)
@ -685,18 +716,10 @@ namespace Fungus.EditorUtils
GenericMenu commandMenu = new GenericMenu(); GenericMenu commandMenu = new GenericMenu();
// Build menu list // Build menu list
List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(commandTypes); var filteredAttributes = GetFilteredSupportedCommands(flowchart);
filteredAttributes.Sort(CompareCommandAttributes);
foreach (var keyPair in filteredAttributes) foreach (var keyPair in filteredAttributes)
{ {
// Skip command type if the Flowchart doesn't support it
if (!flowchart.IsCommandSupported(keyPair.Value))
{
continue;
}
AddCommandOperation commandOperation = new AddCommandOperation(); AddCommandOperation commandOperation = new AddCommandOperation();
commandOperation.block = block; commandOperation.block = block;
@ -719,6 +742,17 @@ namespace Fungus.EditorUtils
commandMenu.ShowAsContext(); commandMenu.ShowAsContext();
} }
protected static List<KeyValuePair<System.Type, CommandInfoAttribute>> GetFilteredSupportedCommands(Flowchart flowchart)
{
List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(commandTypes);
filteredAttributes.Sort(CompareCommandAttributes);
filteredAttributes = filteredAttributes.Where(x => flowchart.IsCommandSupported(x.Value)).ToList();
return filteredAttributes;
}
protected static List<KeyValuePair<System.Type, CommandInfoAttribute>> GetFilteredCommandInfoAttribute(List<System.Type> menuTypes) protected static List<KeyValuePair<System.Type, CommandInfoAttribute>> GetFilteredCommandInfoAttribute(List<System.Type> menuTypes)
{ {
Dictionary<string, KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = new Dictionary<string, KeyValuePair<System.Type, CommandInfoAttribute>>(); Dictionary<string, KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = new Dictionary<string, KeyValuePair<System.Type, CommandInfoAttribute>>();
@ -751,7 +785,7 @@ namespace Fungus.EditorUtils
} }
//Used by GenericMenu Delegate //Used by GenericMenu Delegate
protected static void AddCommandCallback(object obj) protected void AddCommandCallback(object obj)
{ {
AddCommandOperation commandOperation = obj as AddCommandOperation; AddCommandOperation commandOperation = obj as AddCommandOperation;
if (commandOperation != null) if (commandOperation != null)
@ -760,7 +794,7 @@ namespace Fungus.EditorUtils
} }
} }
protected static void AddCommandCallback(AddCommandOperation commandOperation) protected void AddCommandCallback(AddCommandOperation commandOperation)
{ {
var block = commandOperation.block; var block = commandOperation.block;
if (block == null) if (block == null)
@ -792,6 +826,8 @@ namespace Fungus.EditorUtils
// Because this is an async call, we need to force prefab instances to record changes // Because this is an async call, we need to force prefab instances to record changes
PrefabUtility.RecordPrefabInstancePropertyModifications(block); PrefabUtility.RecordPrefabInstancePropertyModifications(block);
commandTextFieldContents = string.Empty;
} }
public virtual void ShowContextMenu() public virtual void ShowContextMenu()

Loading…
Cancel
Save