public override void OpenContextualMenu() { var menu = new GenericMenu(); if (treeView.GetCurrentQuery() == m_Query) { menu.AddItem(new GUIContent("Save"), false, () => treeView.searchView.SaveActiveSearchQuery()); menu.AddSeparator(""); } menu.AddItem(new GUIContent("Open in new window"), false, () => { SearchQuery.Open(m_Query, SearchFlags.None); }); menu.AddSeparator(""); menu.AddItem(new GUIContent("Rename"), false, () => treeView.BeginRename(this, 0f)); menu.AddItem(new GUIContent("Set Icon..."), false, () => SearchUtils.ShowIconPicker((newIcon, canceled) => { if (canceled) { return; } m_Query.thumbnail = newIcon; SearchQuery.SaveSearchQuery(m_Query); })); menu.AddItem(new GUIContent("Search Template"), m_Query.isSearchTemplate, () => m_Query.isSearchTemplate = !m_Query.isSearchTemplate); menu.AddItem(new GUIContent(Utils.GetRevealInFinderLabel()), false, () => EditorUtility.RevealInFinder(m_Query.filePath)); menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete"), false, () => { SearchQuery.RemoveSearchQuery(m_Query); treeView.RemoveItem(this); }); menu.ShowAsContext(); }
public override void OpenContextualMenu() { var menu = new GenericMenu(); if (treeView.GetCurrentQuery() == (ISearchQuery)m_Query) { menu.AddItem(new GUIContent("Save"), false, () => treeView.searchView.SaveActiveSearchQuery()); menu.AddSeparator(""); } menu.AddItem(new GUIContent("Open in new window"), false, () => { SearchQuery.Open(m_Query, SearchFlags.None); }); menu.AddSeparator(""); menu.AddItem(new GUIContent("Rename"), false, () => treeView.BeginRename(this, 0f)); menu.AddItem(new GUIContent("Set Icon..."), false, () => SearchUtils.ShowIconPicker((newIcon, canceled) => { if (canceled) { return; } m_Query.icon = newIcon; EditorUtility.SetDirty(m_Query); })); menu.AddItem(new GUIContent("Search Template"), m_Query.isSearchTemplate, () => m_Query.isSearchTemplate = !m_Query.isSearchTemplate); menu.AddItem(new GUIContent("Edit in Inspector"), false, () => Selection.activeObject = m_Query); menu.AddItem(new GUIContent(Utils.GetRevealInFinderLabel()), false, () => EditorUtility.RevealInFinder(AssetDatabase.GetAssetPath(m_Query))); menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete"), false, () => { if (!EditorUtility.DisplayDialog($"Deleting search query {m_Query.name}?", $"You are about to delete the search query {m_Query.name}, are you sure?", "Yes", "No")) { return; } AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(m_Query)); treeView.RemoveItem(this); }); menu.ShowAsContext(); }
public void ObjectIconDropDown(Rect position, SerializedProperty iconProperty) { const float kDropDownArrowMargin = 2; const float kDropDownArrowWidth = 12; const float kDropDownArrowHeight = 12; if (s_IconTextureInactive == null) { s_IconTextureInactive = (Material)EditorGUIUtility.LoadRequired("Inspectors/InactiveGUI.mat"); } if (s_IconButtonStyle == null) { s_IconButtonStyle = new GUIStyle("IconButton") { fixedWidth = 0, fixedHeight = 0 } } ; void SelectIcon(UnityEngine.Object obj, bool isCanceled) { if (!isCanceled) { iconProperty.objectReferenceValue = obj; iconProperty.serializedObject.ApplyModifiedProperties(); SearchService.RefreshWindows(); } } if (EditorGUI.DropdownButton(position, GUIContent.none, FocusType.Passive, s_IconButtonStyle)) { SearchUtils.ShowIconPicker(SelectIcon); GUIUtility.ExitGUI(); } if (Event.current.type == EventType.Repaint) { var contentPosition = position; contentPosition.xMin += kDropDownArrowMargin; contentPosition.xMax -= kDropDownArrowMargin + kDropDownArrowWidth / 2; contentPosition.yMin += kDropDownArrowMargin; contentPosition.yMax -= kDropDownArrowMargin + kDropDownArrowWidth / 2; Rect arrowRect = new Rect( contentPosition.x + contentPosition.width - kDropDownArrowWidth / 2, contentPosition.y + contentPosition.height - kDropDownArrowHeight / 2, kDropDownArrowWidth, kDropDownArrowHeight); Texture2D icon = null; if (!iconProperty.hasMultipleDifferentValues) { icon = iconProperty.objectReferenceValue as Texture2D ?? AssetPreview.GetMiniThumbnail(targets[0]); } if (icon == null) { icon = Icons.favorite; } Vector2 iconSize = contentPosition.size; if (icon) { iconSize.x = Mathf.Min(icon.width, iconSize.x); iconSize.y = Mathf.Min(icon.height, iconSize.y); } Rect iconRect = new Rect( contentPosition.x + contentPosition.width / 2 - iconSize.x / 2, contentPosition.y + contentPosition.height / 2 - iconSize.y / 2, iconSize.x, iconSize.y); GUI.DrawTexture(iconRect, icon, ScaleMode.ScaleToFit); if (s_IconDropDown == null) { s_IconDropDown = EditorGUIUtility.IconContent("Icon Dropdown"); } GUIStyle.none.Draw(arrowRect, s_IconDropDown, false, false, false, false); } } void AddProvider(ReorderableList list) { var menu = new GenericMenu(); var disabledProviders = GetDisabledProviders().ToList(); for (var i = 0; i < disabledProviders.Count; ++i) { var provider = disabledProviders[i]; menu.AddItem(new GUIContent(provider.name), false, AddProvider, provider); if (!provider.isExplicitProvider && i + 1 < disabledProviders.Count && disabledProviders[i + 1].isExplicitProvider) { menu.AddSeparator(string.Empty); } } menu.ShowAsContext(); } void AddProvider(object providerObj) { if (providerObj is SearchProvider provider && !m_EnabledProviderIds.Contains(provider.id)) { m_EnabledProviderIds.Add(provider.id); UpdateEnabledProviders(); } } void RemoveProvider(ReorderableList list) { var index = list.index; if (index != -1 && index < m_EnabledProviderIds.Count) { var toRemove = SearchService.GetProvider(m_EnabledProviderIds[index]); if (toRemove == null) { return; } m_EnabledProviderIds.Remove(toRemove.id); UpdateEnabledProviders(); if (index >= list.count) { list.index = list.count - 1; } } } void UpdateEnabledProviders() { m_ProvidersProperty.arraySize = m_EnabledProviderIds.Count; for (var i = 0; i < m_EnabledProviderIds.Count; ++i) { m_ProvidersProperty.GetArrayElementAtIndex(i).stringValue = m_EnabledProviderIds[i]; } serializedObject.ApplyModifiedProperties(); SetupContext(); } void DrawProviderElement(Rect rect, int index, bool selected, bool focused) { if (index >= 0 && index < m_EnabledProviderIds.Count) { GUI.Label(rect, SearchService.GetProvider(m_EnabledProviderIds[index])?.name ?? "<unknown>"); } } void CheckContext() { if (m_SearchContext.searchText != m_TextProperty.stringValue) { SetupContext(); } } }