コード例 #1
0
ファイル: ShowAppSettingsDialog.cs プロジェクト: xon00z/dnSpy
 void SortChildren(AppSettingsPageVM page)
 {
     page.Children.Sort(AppSettingsPageVMSorter.Instance);
     foreach (var child in page.Children)
     {
         SortChildren(child);
     }
 }
コード例 #2
0
 void SortChildren(AppSettingsPageVM vm)
 {
     vm.Children.Sort(AppSettingsPageVMSorter.Instance);
     foreach (var child in vm.Children)
     {
         SortChildren(child);
     }
 }
コード例 #3
0
ファイル: ShowAppSettingsDialog.cs プロジェクト: xon00z/dnSpy
 void RemoveEmptyNodes(AppSettingsPageVM page)
 {
     for (int i = page.Children.Count - 1; i >= 0; i--)
     {
         var child = page.Children[i];
         RemoveEmptyNodes(child);
         if (child.Children.Count == 0 && child.Page is AppSettingsPageContainer)
         {
             page.Children.RemoveAt(i);
         }
     }
 }
コード例 #4
0
ファイル: ShowAppSettingsDialog.cs プロジェクト: xon00z/dnSpy
        void FilterChildren(AppSettingsPageVM page, SearchMatcher matcher)
        {
            bool atLeastOneChildVisible = false;

            foreach (var child in page.Children)
            {
                FilterChildren(child, matcher);
                atLeastOneChildVisible |= !child.TreeNode.IsHidden;
            }
            bool isVisible = atLeastOneChildVisible || IsVisible(page, matcher);

            page.TreeNode.IsHidden = !isVisible;
            if (isVisible)
            {
                page.TreeNode.IsExpanded = true;
            }
        }
コード例 #5
0
ファイル: ShowAppSettingsDialog.cs プロジェクト: xon00z/dnSpy
        ITreeView CreateTreeView(AppSettingsPageVM rootVM)
        {
            var options = new TreeViewOptions {
                CanDragAndDrop             = false,
                SelectionMode              = SelectionMode.Single,
                ForegroundBrushResourceKey = "AppSettingsTreeViewForeground",
                RootNode = rootVM,
            };
            var treeView = treeViewService.Create(new Guid("99334011-E467-456F-A0DF-BD4DBD0F0519"), options);

            treeView.UIObject.Padding         = new Thickness(0, 2, 0, 2);
            treeView.UIObject.BorderThickness = new Thickness(1);
            treeView.UIObject.SetResourceReference(Control.BorderBrushProperty, "AppSettingsTreeViewBorder");
            treeView.UIObject.SetResourceReference(Control.ForegroundProperty, "AppSettingsTreeViewForeground");
            treeView.UIObject.SetResourceReference(Control.BackgroundProperty, "AppSettingsTreeViewBackground");

            return(treeView);
        }
コード例 #6
0
        bool IsVisible(AppSettingsPageVM page, SearchMatcher matcher)
        {
            matchList.Clear();
            var p = page;

            // Don't include the root
            while (p.Parent != null)
            {
                matchList.Add(p.Page.Title);
                p = p.Parent;
            }
            foreach (var s in page.GetSearchableStrings(appSettingsDlg))
            {
                matchList.Add(s);
            }
            bool res = matcher.IsMatchAll(matchList);

            matchList.Clear();
            return(res);
        }
コード例 #7
0
ファイル: ShowAppSettingsDialog.cs プロジェクト: xon00z/dnSpy
        AppSettingsPageVM[] CreateSettingsPages()
        {
            var dict = new Dictionary <Guid, AppSettingsPageVM>();

            dict.Add(rootGuid, new AppSettingsPageVM(new AppSettingsPageContainer(string.Empty, 0, rootGuid, rootGuid, ImageReference.None), pageContext));

            foreach (var lz in appSettingsPageContainers)
            {
                var page = TryCreate(lz.Value, lz.Metadata, pageContext);
                if (page == null)
                {
                    continue;
                }
                Debug.Assert(!dict.ContainsKey(page.Page.Guid));
                if (!dict.ContainsKey(page.Page.Guid))
                {
                    dict.Add(page.Page.Guid, page);
                }
            }

            foreach (var lz in appSettingsPageProviders)
            {
                foreach (var page in lz.Value.Create())
                {
                    Debug.Assert(page != null);
                    if (page == null)
                    {
                        continue;
                    }
                    var vm = new AppSettingsPageVM(page, pageContext);
                    Debug.Assert(!dict.ContainsKey(vm.Page.Guid));
                    if (!dict.ContainsKey(vm.Page.Guid))
                    {
                        dict.Add(vm.Page.Guid, vm);
                    }
                }
            }

            return(dict.Values.ToArray());
        }
コード例 #8
0
 public PageAndUIObject(AppSettingsPageVM page, object uiObject)
 {
     Page     = page;
     UIObject = uiObject;
 }
コード例 #9
0
ファイル: ShowAppSettingsDialog.cs プロジェクト: xon00z/dnSpy
        public void Show(Guid?guid, Window ownerWindow)
        {
            LastSelectedGuid = guid;

            allPages = CreateSettingsPages();
            Debug.Assert(allPages.Any(a => a.Page.Guid == rootGuid));
            rootVM = CreateRootVM(allPages);
            if (rootVM.Children.Count == 0)
            {
                return;
            }

            pageContext.TreeView = CreateTreeView(rootVM);

            appSettingsDlg             = new AppSettingsDlg();
            appSettingsDlg.DataContext = this;
            InitializeKeyboardBindings();

            ContentConverterProperties.SetContentConverter(appSettingsDlg, this);
            ContentConverterProperties.SetContentConverterVersion(appSettingsDlg, converterVersion);
            appSettingsDlg.Owner = ownerWindow ?? throw new ArgumentNullException(nameof(ownerWindow));

            AppSettingsPageVM selectedItem = null;

            if (guid != null)
            {
                selectedItem = allPages.FirstOrDefault(a => a.Page.Guid == guid.Value);
            }
            if (selectedItem == null)
            {
                selectedItem = rootVM.Children.FirstOrDefault();
            }
            if (guid == null && selectedItem != null)
            {
                selectedItem = selectedItem.VisiblePage;
            }
            if (selectedItem != null)
            {
                pageContext.TreeView.SelectItems(new[] { selectedItem });
            }

            bool saveSettings = appSettingsDlg.ShowDialog() == true;

            LastSelectedGuid = (pageContext.TreeView.SelectedItem as AppSettingsPageVM)?.VisiblePage.Page.Guid;

            var appRefreshSettings = new AppRefreshSettings();

            if (saveSettings)
            {
                foreach (var page in allPages)
                {
                    if (page.Page is IAppSettingsPage2 page2)
                    {
                        page2.OnApply(appRefreshSettings);
                    }
                    else
                    {
                        page.Page.OnApply();
                    }
                }
            }

            foreach (var page in allPages)
            {
                page.Page.OnClosed();
            }

            if (saveSettings)
            {
                foreach (var listener in appSettingsModifiedListeners)
                {
                    listener.Value.OnSettingsModified(appRefreshSettings);
                }
            }

            // Prevent a memory leak in SharpTreeNodeProxy. This will remove all bindings and
            // remove the ValueChanged handlers from the instance stored in a static field.
            pageContext.TreeView.Root.Children.Clear();
        }
コード例 #10
0
        public void Show(Guid?guid, Window ownerWindow)
        {
            if (ownerWindow == null)
            {
                throw new ArgumentNullException(nameof(ownerWindow));
            }
            LastSelectedGuid = guid;

            allPages = CreateSettingsPages();
            Debug.Assert(allPages.Any(a => a.Page.Guid == rootGuid));
            rootVM = CreateRootVM(allPages);
            if (rootVM.Children.Count == 0)
            {
                return;
            }

            currentContextVM.TreeView = CreateTreeView(rootVM);

            var selectedItem = (guid != null ? allPages.FirstOrDefault(a => a.Page.Guid == guid.Value) : null) ?? rootVM.Children.FirstOrDefault();

            if (selectedItem != null)
            {
                currentContextVM.TreeView.SelectItems(new[] { selectedItem });
            }

            appSettingsDlg             = new AppSettingsDlg();
            appSettingsDlg.DataContext = this;
            InitializeKeyboardBindings();

            ContentConverterProperties.SetContentConverter(appSettingsDlg, this);
            ContentConverterProperties.SetContentConverterVersion(appSettingsDlg, converterVersion);
            appSettingsDlg.Owner = ownerWindow;
            bool saveSettings = appSettingsDlg.ShowDialog() == true;

            LastSelectedGuid = (currentContextVM.TreeView.SelectedItem as AppSettingsPageVM)?.Page.Guid;

            var appRefreshSettings = new AppRefreshSettings();

            if (saveSettings)
            {
                foreach (var page in allPages)
                {
                    var page2 = page.Page as IAppSettingsPage2;
                    if (page2 != null)
                    {
                        page2.OnApply(appRefreshSettings);
                    }
                    else
                    {
                        page.Page.OnApply();
                    }
                }
            }

            foreach (var page in allPages)
            {
                page.Page.OnClosed();
            }

            if (saveSettings)
            {
                foreach (var listener in appSettingsModifiedListeners)
                {
                    listener.Value.OnSettingsModified(appRefreshSettings);
                }
            }
        }