Exemplo n.º 1
0
 public static void Show(
     EditorWindow host,
     IList <SearcherItem> items,
     ISearcherAdapter adapter,
     Func <SearcherItem, bool> itemSelectedDelegate,
     Vector2 displayPosition,
     Action <Searcher.AnalyticsEvent> analyticsDataDelegate,
     Alignment align = default)
 {
     Show(host, items, adapter, Application.dataPath + k_DatabaseDirectory, itemSelectedDelegate,
          displayPosition, analyticsDataDelegate, align);
 }
Exemplo n.º 2
0
        // Used to display data that is not meant to be persisted. The database will be overwritten after each call to SearcherWindow.Show(...).
        internal static void ShowTransientData(EditorWindow host, IEnumerable <SearcherItem> items,
                                               ISearcherAdapter adapter, Action <SearcherItem> selectionDelegate, Vector2 pos)
        {
            var database = SearcherDatabase.Create(items.ToList(), "", false);
            var searcher = new Searcher.Searcher(database, adapter);

            SearcherWindow.Show(host, searcher, x =>
            {
                host.Focus();
                selectionDelegate(x);

                return(!(Event.current?.modifiers.HasFlag(EventModifiers.Control)).GetValueOrDefault());
            }, pos, null);
        }
Exemplo n.º 3
0
        Searcher(IEnumerable <SearcherDatabaseBase> databases, string title, ISearcherAdapter adapter)
        {
            m_Databases = new List <SearcherDatabaseBase>();
            var databaseId = 0;

            foreach (var database in databases)
            {
                // This is needed for sorting items between databases.
                database.OverwriteId(databaseId);
                databaseId++;

                m_Databases.Add(database);
            }

            Adapter = adapter ?? new SearcherAdapter(title);
        }
Exemplo n.º 4
0
        public static void Show(
            EditorWindow host,
            IEnumerable <SearcherItem> items,
            ISearcherAdapter adapter,
            string directoryPath,
            Func <SearcherItem, bool> itemSelectedDelegate,
            Vector2 displayPosition,
            Action <Searcher.AnalyticsEvent> analyticsDataDelegate,
            Alignment align = default)
        {
            s_Items = items;
            var databaseDir = directoryPath;
            var database    = SearcherDatabase.Create(s_Items.ToList(), databaseDir);

            s_Searcher = new Searcher(database, adapter);

            Show(host, s_Searcher, itemSelectedDelegate, displayPosition, analyticsDataDelegate, align);
        }
Exemplo n.º 5
0
        static void PromptSearcherPopup <T>(List <SearcherDatabaseBase> databases, SearcherFilter filter,
                                            ISearcherAdapter adapter, Rect rect, Action <T> callback) where T : ISearcherItemDataProvider
        {
            var searcher = new Searcher.Searcher(databases, adapter, filter)
            {
                SortComparison = k_GraphElementSort
            };

            Searcher.SearcherWindow.Show(EditorWindow.focusedWindow, searcher, item =>
            {
                if (item is T dataProvider)
                {
                    callback(dataProvider);
                    return(true);
                }

                return(false);
            }, null, rect);
        }
Exemplo n.º 6
0
        static void PromptSearcher <T>(List <SearcherDatabase> databases, SearcherFilter filter,
                                       ISearcherAdapter adapter, Vector2 position, Action <T> callback) where T : ISearcherItemDataProvider
        {
            ApplyDatabasesFilter <T>(databases, filter);
            var searcher = new Searcher.Searcher(databases, adapter)
            {
                SortComparison = k_GraphElementSort
            };
            var ctx = typeof(T) == typeof(GraphNodeModelSearcherItem) ? SearcherContext.Graph : SearcherContext.Stack;

            SearcherWindow.Show(EditorWindow.focusedWindow, searcher, item =>
            {
                if (item is T dataProvider)
                {
                    callback(dataProvider);
                    return(true);
                }

                return(false);
            }, position, e => AnalyticsDataDelegate(e, ctx));
        }
Exemplo n.º 7
0
        static EditorWindow PromptSearcherInOwnWindow <T>(List <SearcherDatabaseBase> databases, SearcherFilter filter,
                                                          ISearcherAdapter adapter, Action <T> callback, Rect rect) where T : ISearcherItemDataProvider
        {
            var searcher = new Searcher.Searcher(databases, adapter, filter)
            {
                SortComparison = k_GraphElementSort
            };

            Type searcherControlType = Type.GetType("UnityEditor.Searcher.SearcherControl, Unity.Searcher.Editor");
            bool windowExists        = EditorWindow.HasOpenInstances <SearcherWindow>();
            var  window = EditorWindow.GetWindow <SearcherWindow>();

            if (!windowExists)
            {
                window.position = rect;
            }

            var searcherControl = Activator.CreateInstance(searcherControlType) as VisualElement;

            Action <SearcherItem> action = item =>
            {
                if (item is T dataProvider)
                {
                    callback(dataProvider);
                }
            };

            var setupMethod = searcherControlType.GetMethod("Setup");

            setupMethod?.Invoke(searcherControl, new object[]
            {
                searcher, action, null
            });

            window.rootVisualElement.Add(searcherControl);

            return(window);
        }
Exemplo n.º 8
0
        internal static void ShowStackNodes(State state, IStackModel stackModel, Vector2 position,
                                            Action <StackNodeModelSearcherItem> callback, ISearcherAdapter searcherAdapter = null)
        {
            var stencil    = state.CurrentGraphModel.Stencil;
            var filter     = stencil.GetSearcherFilterProvider()?.GetStackSearcherFilter(stackModel);
            var adapter    = searcherAdapter ?? new StackNodeSearcherAdapter(stackModel, "Add a stack node");
            var dbProvider = stencil.GetSearcherDatabaseProvider();
            var dbs        = dbProvider.GetGraphElementsSearcherDatabases()
                             .Concat(dbProvider.GetReferenceItemsSearcherDatabases())
                             .ToList();

            PromptSearcher(dbs, filter, adapter, position, callback);
        }
Exemplo n.º 9
0
 public Searcher(IEnumerable <SearcherDatabaseBase> databases, ISearcherAdapter adapter = null)
     : this(databases, string.Empty, adapter)
 {
 }
Exemplo n.º 10
0
 public Searcher(SearcherDatabaseBase database, ISearcherAdapter adapter = null)
     : this(new List <SearcherDatabaseBase> {
     database
 }, adapter)
 {
 }