Esempio n. 1
0
        void ShowCore(Guid?guid, Window owner)
        {
            currentContextVM = new ContextVM {
                TreeViewNodeTextElementProvider = treeViewNodeTextElementProvider,
            };

            var allVMs = CreateSettingsPages();

            Debug.Assert(allVMs.Any(a => a.Page.Guid == rootGuid));
            var rootVM = CreateRootVM(allVMs);

            if (rootVM.Children.Count == 0)
            {
                return;
            }

            currentContextVM.TreeView = CreateTreeView(rootVM);

            if (guid == null)
            {
                guid = lastSelectedGuid;
            }
            var selectedItem = (guid != null ? allVMs.FirstOrDefault(a => a.Page.Guid == guid.Value) : null) ?? rootVM.Children.FirstOrDefault();

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

            var dlg = new AppSettingsDlg();

            dlg.treeViewContentPresenter.Content = currentContextVM.TreeView.UIObject;
            dlg.Owner = owner ?? appWindow.MainWindow;
            bool saveSettings = dlg.ShowDialog() == true;

            lastSelectedGuid = (currentContextVM.TreeView.SelectedItem as AppSettingsPageVM)?.Page.Guid;
            Debug.Assert(lastSelectedGuid != null);

            var appRefreshSettings = new AppRefreshSettings();

            foreach (var vm in allVMs)
            {
                vm.Page.OnClosed(saveSettings, appRefreshSettings);
            }
            if (saveSettings)
            {
                foreach (var listener in appSettingsModifiedListeners)
                {
                    listener.Value.OnSettingsModified(appRefreshSettings);
                }
            }
        }
Esempio n. 2
0
 public override void Execute(IMenuItemContext context)
 {
     var tabs = tabCreators.SelectMany(a => a.Value.Create()).OrderBy(a => a.Order).ToArray();
     var dlg = new AppSettingsDlg(tabs);
     dlg.Owner = appWindow.MainWindow;
     bool saveSettings = dlg.ShowDialog() == true;
     var appRefreshSettings = new AppRefreshSettings();
     foreach (var tab in tabs)
         tab.OnClosed(saveSettings, appRefreshSettings);
     if (saveSettings) {
         foreach (var listener in listeners)
             listener.Value.OnSettingsModified(appRefreshSettings);
     }
 }
Esempio n. 3
0
        public override void Execute(IMenuItemContext context)
        {
            var tabs = appSettingsTabProviders.SelectMany(a => a.Value.Create()).OrderBy(a => a.Order).ToArray();
            var dlg  = new AppSettingsDlg(tabs);

            dlg.Owner = appWindow.MainWindow;
            bool saveSettings       = dlg.ShowDialog() == true;
            var  appRefreshSettings = new AppRefreshSettings();

            foreach (var tab in tabs)
            {
                tab.OnClosed(saveSettings, appRefreshSettings);
            }
            if (saveSettings)
            {
                foreach (var listener in listeners)
                {
                    listener.Value.OnSettingsModified(appRefreshSettings);
                }
            }
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
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);
                }
            }
        }