internal static SearchProvider CreateProvider() { List <string> itemNames = new List <string>(); List <string> shortcuts = new List <string>(); GetMenuInfo(itemNames, shortcuts); System.Threading.Tasks.Task.Run(() => BuildMenus(itemNames)); queryEngine = new QueryEngine <MenuData>(k_QueryEngineOptions); queryEngine.SetFilter("id", m => m.path) .AddOrUpdatePropositionData(label: "Menu Path", replacement: "id:create/", help: "Filter by menu path.", priority: 9999); queryEngine.SetSearchDataCallback(m => m.words, s => Utils.FastToLower(s), StringComparison.Ordinal); debounce = Delayer.Debounce(_ => TriggerBackgroundUpdate(itemNames, shortcuts)); Menu.menuChanged -= OnMenuChanged; Menu.menuChanged += OnMenuChanged; return(new SearchProvider(type, displayName) { priority = 80, filterId = "m:", showDetailsOptions = ShowDetailsOptions.ListView | ShowDetailsOptions.Actions, onEnable = () => shortcutIds = ShortcutManager.instance.GetAvailableShortcutIds().ToArray(), onDisable = () => shortcutIds = new string[0], fetchItems = FetchItems, fetchLabel = (item, context) => { if (item.label == null) { var menuName = Utils.GetNameFromPath(item.id); var enabled = Menu.GetEnabled(item.id); var @checked = Menu.GetChecked(item.id); item.label = $"{menuName}{(enabled ? "" : " (disabled)")} {(@checked ? "\u2611" : "")}"; } return item.label; }, fetchDescription = (item, context) => { if (string.IsNullOrEmpty(item.description)) { item.description = GetMenuDescription(item.id); } return item.description; }, fetchThumbnail = (item, context) => Icons.shortcut, fetchPropositions = (context, options) => FetchPropositions(context, options) }); }
public PropertyDatabase(string filePath, bool autoBackgroundUpdate, double backgroundUpdateDebounceInSeconds = k_DefaultBackgroundUpdateDebounceInSeconds) { this.filePath = filePath; stringTableFilePath = GetStringTablePath(filePath); m_LocalVolatileStore = new PropertyDatabaseVolatileMemoryStore(); m_LocalStore = new PropertyDatabaseMemoryStore(); m_FileStore = new PropertyDatabaseFileStore(filePath); m_StringTable = new PropertyStringTable(stringTableFilePath, 30); // Do not allow automatic background updates while running tests. The writing of the file // causes an assembly leak during the test Unity.IntegrationTests.Scripting.AssemblyReloadTest.AssemblyReloadDoesntLeakAssemblies // on MacOs. I haven't found out why exactly does the writing of a file causes an assembly to be held, so instead I deactivate // the automatic update during tests. this.autoBackgroundUpdate = autoBackgroundUpdate && !Utils.IsRunningTests(); m_Debounce = Delayer.Debounce(_ => TriggerPropertyDatabaseBackgroundUpdate(), backgroundUpdateDebounceInSeconds); }