Exemple #1
0
        private void LoadSelection(PageEntry element)
        {
            var pageList        = rootVisualElement.Q("page-list");
            var pageView        = rootVisualElement.Q("page-view");
            var selectedElement = pageList.Q(className: SelectedClass);

            selectedElement?.RemoveFromClassList(SelectedClass);
            element.AddToClassList(SelectedClass);

            pageView.Clear();
            LoadTemplateInstance(element.PagePath, pageView);
        }
Exemple #2
0
        public override void OnEnable()
        {
            base.OnEnable();

            var pageList  = rootVisualElement.Q("page-list");
            var pageFiles = Directory.EnumerateFiles($"{DocumentationRoot}/topics", "*.uxml", SearchOption.AllDirectories)
                            .OrderBy(dir => Path.GetDirectoryName(dir))
                            .ThenBy(path => Path.GetFileNameWithoutExtension(path))
                            .ToArray();

            pageList.RegisterCallback <KeyDownEvent>(OnNavigate);
            pageList.Clear();

            var       pages       = new Dictionary <string, PageEntry>();
            PageEntry defaultPage = null;

            foreach (var pagePath in pageFiles)
            {
                var fileName            = Path.GetFileNameWithoutExtension(pagePath);
                var containingDirectory = Path.GetDirectoryName(pagePath);
                var pageNamePath        = Path.Combine(containingDirectory, fileName);

                var fullParentPageName = GetPageName(containingDirectory);
                var fullPageName       = GetPageName(pageNamePath);
                var parentPage         = pages.ContainsKey(fullParentPageName) ? pages[fullParentPageName] : null;

                int pageDepth = 0;
                if (parentPage != null)
                {
                    pageDepth = parentPage.depth + 1;
                }

                var pageEntry = new PageEntry(fileName, fullPageName, pagePath, pageDepth);
                pageEntry.FoldOut.RegisterCallback <ChangeEvent <bool> >(OnToggle);
                pageEntry.AddManipulator(new Clickable(OnSelect));
                if (fullPageName.Equals("topics-1st_read_me!"))
                {
                    defaultPage = pageEntry;
                }
                if (parentPage != null)
                {
                    var parentIndex = pageList.IndexOf(parentPage);
                    pageEntry.AddToClassList(HiddenClass);
                    pageEntry.AddToClassList(MinimizeClass);
                    pageList.Insert(parentIndex + parentPage.ChildPageCount + 1, pageEntry);
                    parentPage.FoldOut.RemoveFromClassList(HiddenClass);
                    parentPage.ChildPageCount++;
                }
                else
                {
                    pageList.Add(pageEntry);
                }
#if UNITY_2019_1_OR_NEWER
                rootVisualElement.RegisterCallback <CustomStyleResolvedEvent>(OnStyleResolved);
#endif
                pages.Add(fullPageName, pageEntry);
            }
            if (defaultPage != null)
            {
                LoadSelection(defaultPage);
            }
        }
        public override void OnEnable()
        {
            base.OnEnable();

            var pageList        = rootVisualElement.Q("page-list");
            var topicsFileGuids = AssetDatabase.FindAssets($"t:{nameof(VisualTreeAsset)}", new string[] { $"{DocumentationRoot}/topics" });
            var topicsFilePaths = topicsFileGuids.Select(AssetDatabase.GUIDToAssetPath).ToArray();
            var uxmlTopics      = topicsFilePaths.Distinct().ToArray();
            var pageFiles       = uxmlTopics
                                  .OrderBy(dir => Path.GetDirectoryName(dir))
                                  .ThenBy(path => Path.GetFileNameWithoutExtension(path))
                                  .ToArray();

            pageList.RegisterCallback <KeyDownEvent>(OnNavigate);
            pageList.Clear();

            var       pages       = new Dictionary <string, PageEntry>();
            PageEntry defaultPage = null;

            foreach (var pagePath in pageFiles)
            {
                var fileName            = Path.GetFileNameWithoutExtension(pagePath);
                var containingDirectory = Path.GetDirectoryName(pagePath);
                var pageNamePath        = Path.Combine(containingDirectory, fileName);

                var fullParentPageName = GetPageName(containingDirectory);
                var fullPageName       = GetPageName(pageNamePath);
                var parentPage         = pages.TryGetValue(fullParentPageName, out var tempPage) ? tempPage : null;

                int pageDepth = 0;
                if (parentPage != null)
                {
                    pageDepth = parentPage.Depth + 1;
                }

                var pageEntry = new PageEntry(fileName, fullPageName, pagePath, pageDepth);
                pageEntry.FoldOut.RegisterCallback <ChangeEvent <bool> >(OnToggle);
                pageEntry.AddManipulator(new Clickable(OnSelect));
                if (fullPageName.Equals("topics-1st_read_me!"))
                {
                    defaultPage = pageEntry;
                }
                if (parentPage != null)
                {
                    var parentIndex = pageList.IndexOf(parentPage);
                    pageEntry.AddToClassList(HiddenClass);
                    pageEntry.AddToClassList(MinimizeClass);
                    pageList.Insert(parentIndex + parentPage.ChildPageCount + 1, pageEntry);
                    parentPage.FoldOut.RemoveFromClassList(HiddenClass);
                    parentPage.ChildPageCount++;
                }
                else
                {
                    pageList.Add(pageEntry);
                }
#if UNITY_2019_1_OR_NEWER
                rootVisualElement.RegisterCallback <CustomStyleResolvedEvent>(OnStyleResolved);
#endif
                pages.Add(fullPageName, pageEntry);
            }
            if (defaultPage != null)
            {
                LoadSelection(defaultPage);
            }
        }