public bool SelectObject(ISearchContext context,
                                 Action <Object, bool> selectHandler, Action <Object> trackingHandler)
        {
            var selectContext = (ObjectSelectorSearchContext)context;
            var viewFlags     = SearchFlags.OpenPicker;

            if (Utils.IsRunningTests())
            {
                viewFlags |= SearchFlags.Dockable;
            }
            SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchPickerOpens, "", "object", "ObjectSelectorEngine");
            var searchQuery = string.Join(" ", context.requiredTypeNames.Select(tn => tn == null ? "" : $"t:{tn.ToLowerInvariant()}"));

            if (string.IsNullOrEmpty(searchQuery))
            {
                searchQuery = "";
            }
            else
            {
                searchQuery += " ";
            }
            var viewstate = new SearchViewState(
                SearchService.CreateContext(GetObjectSelectorProviders(selectContext), searchQuery, viewFlags), selectHandler, trackingHandler,
                selectContext.requiredTypeNames.First(), selectContext.requiredTypes.First());

            qsWindow = SearchService.ShowPicker(viewstate) as QuickSearch;
            return(qsWindow != null);
        }
        public void UpdateColumnSettings(int columnIndex, MultiColumnHeaderState.Column columnSettings)
        {
            if (m_TableConfig == null || columnIndex >= m_TableConfig.columns.Length)
            {
                return;
            }

            var searchColumn = m_TableConfig.columns[columnIndex];

            searchColumn.width    = columnSettings.width;
            searchColumn.content  = columnSettings.headerContent;
            searchColumn.options &= ~SearchColumnFlags.TextAligmentMask;
            switch (columnSettings.headerTextAlignment)
            {
            case TextAlignment.Left: searchColumn.options |= SearchColumnFlags.TextAlignmentLeft; break;

            case TextAlignment.Center: searchColumn.options |= SearchColumnFlags.TextAlignmentCenter; break;

            case TextAlignment.Right: searchColumn.options |= SearchColumnFlags.TextAlignmentRight; break;
            }

            SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchTableEditColumn, searchColumn.name, searchColumn.provider, searchColumn.selector);

            SearchColumnSettings.Save(searchColumn);
            SetDirty();
        }
Beispiel #3
0
        public static string CreateTemplateIndex(string template, string path, string name = null, string settings = null)
        {
            if (settings == null && !SearchDatabaseTemplates.all.ContainsKey(template))
            {
                return(null);
            }

            var dirPath         = path;
            var templateContent = settings ?? SearchDatabaseTemplates.all[template];

            if (File.Exists(path))
            {
                dirPath = Path.GetDirectoryName(path);
                if (Selection.assetGUIDs.Length > 1)
                {
                    path = dirPath;
                }
            }

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            var indexFileName = string.IsNullOrEmpty(name) ? Path.GetFileNameWithoutExtension(path) : name;
            var indexPath     = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(dirPath, $"{indexFileName}.index")).Replace("\\", "/");

            SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.CreateIndexFromTemplate, template);

            File.WriteAllText(indexPath, templateContent);
            return(SearchDatabase.ImportAsset(indexPath)?.path ?? indexPath);
        }
        public void AddColumns(IEnumerable <SearchColumn> newColumns, int insertColumnAt)
        {
            if (m_TableConfig == null)
            {
                return;
            }

            var columns = new List <SearchColumn>(m_TableConfig.columns);

            if (insertColumnAt == -1)
            {
                insertColumnAt = columns.Count;
            }
            var columnCountBefore = columns.Count;

            columns.InsertRange(insertColumnAt, newColumns);

            var columnAdded = columns.Count - columnCountBefore;

            if (columnAdded > 0)
            {
                var firstColumn = newColumns.First();
                var e           = SearchAnalytics.GenericEvent.Create(null, SearchAnalytics.GenericEventType.QuickSearchTableAddColumn, firstColumn.name);
                e.intPayload1 = columnAdded;
                e.message     = firstColumn.provider;
                e.description = firstColumn.selector;
                SearchAnalytics.SendEvent(e);

                m_TableConfig.columns = columns.ToArray();
                UpdatePropertyTable();

                m_PropertyTable?.FrameColumn(insertColumnAt - 1);
            }
        }
Beispiel #5
0
 internal void SetProvider(string provider)
 {
     options      &= ~SearchColumnFlags.Volatile;
     this.provider = provider;
     SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchTableChangeColumnFormat, name, provider, selector);
     InitFunctors();
 }
Beispiel #6
0
        public static string Draw(SearchField searchField)
        {
            if (!enabled)
            {
                return(null);
            }

            var evt = Event.current;

            if (evt.type == EventType.MouseDown && !position.Contains(evt.mousePosition))
            {
                evt.Use();
                Clear();
                return(null);
            }

            var te         = searchField.GetTextEditor();
            var searchText = te.text;

            // Check if the cache filtered list should be updated
            if (evt.type == EventType.Repaint && !searchText.Equals(s_LastInput, StringComparison.Ordinal))
            {
                UpdateCompleteList(searchField.GetTextEditor());
            }

            if (s_FilteredList == null)
            {
                return(null);
            }

            var selected = DrawItems(evt, out var proposition);

            if (proposition.valid)
            {
                if (proposition.moveCursor == TextCursorPlacement.MoveLineEnd)
                {
                    te.text = proposition.replacement;
                    te.MoveLineEnd();
                    GUI.changed = true;
                }
                else if (!options.tokens.All(t => t.StartsWith(proposition.replacement, StringComparison.OrdinalIgnoreCase)))
                {
                    var insertion = ReplaceText(searchText, proposition.replacement, options.cursor, out var insertTokenPos);
                    SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchAutoCompleteInsertSuggestion, insertion);

                    te.text = insertion;
                    searchField.MoveCursor(proposition.moveCursor, insertTokenPos);
                    GUI.changed = true;
                }
            }

            if (selected)
            {
                // No more results
                Clear();
            }

            return(te.text);
        }
 public override void DrawTabsButtons()
 {
     if (EditorGUILayout.DropdownButton(Styles.resetSearchColumnsContent, FocusType.Keyboard, Styles.tabButton))
     {
         SetupColumns();
         SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchTableReset, context.searchQuery);
     }
     EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
 }
Beispiel #8
0
        internal void ShowObjectSelector()
        {
            SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchPickerOpens, searchContext.searchText, "object", "objectfield");
            m_OriginalObject = value;
            var searchViewState = new SearchViewState(searchContext, OnSelection, OnObjectChanged, objectType.ToString(), objectType)
            {
                title = $"{objectType.Name}"
            }.SetSearchViewFlags(searchViewFlags);

            SearchService.ShowPicker(searchViewState);
        }
Beispiel #9
0
        public bool SelectObject(ISearchContext context,
                                 Action <Object, bool> selectHandler, Action <Object> trackingHandler)
        {
            if (m_CurrentSelector == null)
            {
                return(false);
            }
            var selectorArgs = new AdvancedObjectSelectorParameters(context, selectHandler, trackingHandler);

            m_CurrentSelector.handler(AdvancedObjectSelectorEventType.OpenAndSearch, selectorArgs);
            SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchPickerOpens, m_CurrentSelector.id, "object", "ObjectSelectorEngine");
            return(true);
        }
        public void RemoveColumn(int removeColumnAt)
        {
            if (m_TableConfig == null || removeColumnAt == -1)
            {
                return;
            }

            var columns        = new List <SearchColumn>(m_TableConfig.columns);
            var columnToRemove = columns[removeColumnAt];

            SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchTableRemoveColumn, columnToRemove.name, columnToRemove.provider, columnToRemove.selector);
            columns.RemoveAt(removeColumnAt);
            m_TableConfig.columns = columns.ToArray();
            UpdatePropertyTable();
        }
        /// <summary>
        /// Use Quick Search to as an object picker to select any object based on the specified filter type.
        /// </summary>
        /// <param name="selectHandler">Callback to trigger when a user selects an item.</param>
        /// <param name="trackingHandler">Callback to trigger when the user is modifying QuickSearch selection (i.e. tracking the currently selected item)</param>
        /// <param name="searchText">Initial search text for QuickSearch.</param>
        /// <param name="typeName">Type name of the object to select. Can be used to replace filterType.</param>
        /// <param name="filterType">Type of the object to select.</param>
        /// <param name="defaultWidth">Initial width of the window.</param>
        /// <param name="defaultHeight">Initial height of the window.</param>
        /// <param name="flags">Options flags modifying how the Search window will be opened.</param>
        /// <returns>Returns the QuickSearch window.</returns>
        public static ISearchView ShowObjectPicker(
            Action <UnityEngine.Object, bool> selectHandler,
            Action <UnityEngine.Object> trackingHandler,
            string searchText, string typeName, Type filterType,
            float defaultWidth = 850, float defaultHeight = 539,
            SearchFlags flags  = SearchFlags.None)
        {
            var context = CreateContext(GetObjectProviders(), searchText, flags | SearchFlags.OpenPicker);

            SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchPickerOpens, searchText, "object", "api");
            return(ShowPicker(new SearchViewState(context, selectHandler, trackingHandler, typeName, filterType)
            {
                position = new Rect(0, 0, defaultWidth, defaultHeight)
            }.SetSearchViewFlags(SearchViewFlags.None)));
        }
        private bool BlockClicked(QueryBuilder builder, QueryBlock block, bool isDoubleClick)
        {
            if (builder != m_Areas)
            {
                return(false);
            }

            if (isDoubleClick)
            {
                SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchHelperWidgetExecuted, m_BlockMode ? "queryBuilder" : "text", "doubleClick");
                var query = CreateQuery(block.ToString());
                ExecuteQuery(query);
                return(true);
            }

            ChangeCurrentAreaFilter(GetAreaFilterId(block));
            RefreshSearches();
            return(true);
        }
Beispiel #13
0
        internal static void OpenWindow(string reportPath)
        {
            if (string.IsNullOrEmpty(reportPath))
                return;

            var window = CreateInstance<SearchReportWindow>();
            window.m_WindowId = GUID.Generate().ToString();
            try
            {
                window.InitializeReport(reportPath);
                window.position = Utils.GetMainWindowCenteredPosition(new Vector2(760f, 500f));
                window.Show();
                SearchAnalytics.SendEvent(window.m_WindowId, SearchAnalytics.GenericEventType.ReportViewOpen);
            }
            catch
            {
                Debug.LogError($"Failed to load search report <a>{reportPath}</a>. Make sure <a>{reportPath}</a> is a valid JSON search table report (*.{SearchReport.extension})");
                DestroyImmediate(window);
            }
        }
Beispiel #14
0
        public bool SelectObject(ISearchContext context,
                                 Action <Object, bool> selectHandler, Action <Object> trackingHandler)
        {
            var selectContext = (ObjectSelectorSearchContext)context;
            var viewFlags     = SearchFlags.OpenPicker;

            if (Utils.IsRunningTests())
            {
                viewFlags |= SearchFlags.Dockable;
            }
            SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchPickerOpens, "", "object", "ObjectSelectorEngine");
            var viewstate = new SearchViewState(
                SearchService.CreateContext("", viewFlags), selectHandler, trackingHandler,
                selectContext.requiredTypeNames.First(), selectContext.requiredTypes.First());


            qsWindow = SearchService.ShowPicker(viewstate) as QuickSearch;

            return(qsWindow != null);
        }
Beispiel #15
0
        static void ShowSearchPicker(SearchContext context, SearchViewFlags searchViewFlags, SerializedProperty property, Object originalObject, int id, Event evt, Type objType)
        {
            s_DelegateWindow = EditorWindow.focusedWindow;
            s_ModalUndoGroup = Undo.GetCurrentGroup();
            s_OriginalItem   = originalObject;
            var searchViewState = new SearchViewState(context,
                                                      (item, canceled) => SendSelectionEvent(item, canceled, id),
                                                      item => SendTrackingEvent(item, id), objType.ToString(), objType)
                                  .SetSearchViewFlags(searchViewFlags);

            if (property != null)
            {
                searchViewState.title = $"{property.displayName} ({objType.Name})";
            }
            SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchPickerOpens, context.searchText, "object", "objectfield");
            SearchService.ShowPicker(searchViewState);

            evt.Use();
            GUIUtility.ExitGUI();
        }
Beispiel #16
0
        public void Add(ISearchQuery query, bool select = true)
        {
            SearchQueryTreeViewItem item = null;

            if (query is SearchQueryAsset sqa)
            {
                item = new SearchQueryAssetTreeViewItem(this, sqa);
                m_ProjectQueries.AddChild(item);
                SetExpanded(m_ProjectQueries.id, true);
                SortBy(m_ProjectQueries, m_SortOrder);

                var evt = searchView.CreateEvent(SearchAnalytics.GenericEventType.QuickSearchCreateSearchQuery, query.searchText, query.filePath, "project");
                #if USE_SEARCH_MODULE
                evt.intPayload1 = query.GetResultViewState().tableConfig != null ? 1 : 0;
                #endif
                SearchAnalytics.SendEvent(evt);
            }
            else if (query is SearchQuery sq && SearchQuery.IsUserQuery(sq))
            {
                item = new SearchQueryUserTreeViewItem(this, sq);
                m_UserQueries.AddChild(item);
                SetExpanded(m_UserQueries.id, true);
                SortBy(m_UserQueries, m_SortOrder);

                var evt = searchView.CreateEvent(SearchAnalytics.GenericEventType.QuickSearchCreateSearchQuery, query.searchText, "", "user");
                #if USE_SEARCH_MODULE
                evt.intPayload1 = query.GetResultViewState().tableConfig != null ? 1 : 0;
                #endif
                SearchAnalytics.SendEvent(evt);
            }

            if (item != null)
            {
                BuildRows(rootItem);
                if (select)
                {
                    SetSelection(new int[] { item.id });
                }
            }
        }
 public static ISearchView ShowPicker(
     SearchContext context,
     Action <SearchItem, bool> selectHandler,
     Action <SearchItem> trackingHandler   = null,
     Func <SearchItem, bool> filterHandler = null,
     IEnumerable <SearchItem> subset       = null,
     string title = null, float itemSize = 64f, float defaultWidth = 850f, float defaultHeight = 539f, SearchFlags flags = SearchFlags.None)
 {
     if (subset != null)
     {
         context.subset = subset.ToList();
     }
     context.options |= flags | SearchFlags.OpenPicker;
     SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchPickerOpens, context.searchText, "item", "api");
     return(SearchPickerWindow.ShowPicker(new SearchViewState(context, selectHandler)
     {
         trackingHandler = trackingHandler,
         filterHandler = filterHandler,
         title = title,
         itemSize = itemSize,
         position = new Rect(0, 0, defaultWidth, defaultHeight)
     }.SetSearchViewFlags(SearchViewFlags.None)));
 }
Beispiel #18
0
        public static bool Show(SearchContext context, Rect parentRect, SearchField searchField)
        {
            var te = searchField.GetTextEditor();

            if (te.controlID != GUIUtility.keyboardControl)
            {
                return(false);
            }

            parent       = parentRect;
            options      = new SearchPropositionOptions(context, te.cursorIndex, te.text);
            propositions = SearchProposition.Fetch(context, options);

            enabled = propositions.Count > 0;
            if (!enabled)
            {
                return(false);
            }

            SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchAutoCompleteTab, string.Join(",", options.tokens));
            UpdateCompleteList(te, options);
            return(true);
        }
Beispiel #19
0
 private void ToggleColumnVisibility(int columnIndex)
 {
     ToggleVisibility(columnIndex);
     SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchTableToggleColumnVisibility);
 }
Beispiel #20
0
 private void ResetColumnLayout()
 {
     m_TableView.SetupColumns();
     SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchTableReset, m_TableView.context.searchQuery);
 }