Index: Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs =================================================================== diff -u -r4fa60849c29200e916800b84066f0fb2d583d116 -r0fe90cd590613f74567c85622bbd2235419a5d5f --- Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision 4fa60849c29200e916800b84066f0fb2d583d116) +++ Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision 0fe90cd590613f74567c85622bbd2235419a5d5f) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.IO; @@ -30,6 +31,7 @@ using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media.Imaging; +using Core.Common.Base.Data; using Core.Common.Controls.Views; using Core.Common.Util.Settings; using Core.Components.Chart.Forms; @@ -55,6 +57,8 @@ /// private readonly WindowInteropHelper windowInteropHelper; + private readonly IDictionary> stateToggleButtonLookup = new Dictionary>(); + private IViewController viewController; private ICommandsOwner commands; private ISettingsOwner settings; @@ -224,30 +228,47 @@ /// public void UpdateProjectExplorer() { - if (ProjectExplorer != null) + if (ProjectExplorer == null) { - ProjectExplorer.Data = gui.Project; + return; } + + ToggleButton checkedStateToggleButton = stateToggleButtonLookup.Keys.FirstOrDefault(stb => stb.IsChecked.HasValue && stb.IsChecked.Value); + + ProjectExplorer.Data = checkedStateToggleButton != null + ? stateToggleButtonLookup[checkedStateToggleButton](gui.Project) + : null; } /// /// Adds a state button to the . /// /// The text of the button. /// The symbol of the button. - public void AddStateButton(string text, string symbol) + /// The method for obtaining the root data of the state. + internal void AddStateButton(string text, string symbol, Func getRootData) { - MainButtonStackPanel.Children.Insert(MainButtonStackPanel.Children.Count - 1, - new ToggleButton - { - Tag = text, - Style = (Style) FindResource("MainButtonBarToggleButtonStyle"), - Content = new TextBlock - { - Style = (Style) FindResource("ButtonLargeIconStyle"), - Text = symbol - } - }); + var stateToggleButton = new ToggleButton + { + Tag = text, + Style = (Style) FindResource("MainButtonBarToggleButtonStyle"), + Content = new TextBlock + { + Style = (Style) FindResource("ButtonLargeIconStyle"), + Text = symbol + } + }; + + stateToggleButton.Click += (sender, e) => { HandleStateButtonClick((ToggleButton) sender); }; + + MainButtonStackPanel.Children.Insert(MainButtonStackPanel.Children.Count - 1, stateToggleButton); + + stateToggleButtonLookup.Add(stateToggleButton, getRootData); + + if (stateToggleButtonLookup.Count == 1) + { + HandleStateButtonClick(stateToggleButton); + } } public void Dispose() @@ -270,6 +291,26 @@ SetGui(null); } + private void HandleStateButtonClick(ToggleButton clickedStateToggleButton) + { + if (clickedStateToggleButton.IsChecked != null && !clickedStateToggleButton.IsChecked.Value) + { + clickedStateToggleButton.IsChecked = true; + + return; + } + + foreach (ToggleButton stateToggleButton in stateToggleButtonLookup.Keys.Except(new[] + { + clickedStateToggleButton + })) + { + stateToggleButton.IsChecked = false; + } + + UpdateProjectExplorer(); + } + #region OnClick events private void OnFileSaveClicked(object sender, RoutedEventArgs e) @@ -339,7 +380,7 @@ private void ToggleToolWindow(IView toolView, Action initializeToolWindowAction, ToggleButton toggleButton) { bool active = viewController.ViewHost.ToolViews.Contains(toolView); - + if (active) { viewController.ViewHost.Remove(toolView); @@ -455,11 +496,11 @@ private void InitProjectExplorerWindow() { - ProjectExplorer = new ProjectExplorer.ProjectExplorer(gui.ViewCommands, gui.GetTreeNodeInfos()) - { - Data = gui.Project - }; + ProjectExplorer = new ProjectExplorer.ProjectExplorer(gui.ViewCommands, gui.GetTreeNodeInfos()); + viewController.ViewHost.AddToolView(ProjectExplorer, ToolViewLocation.Left, "\uE95B"); + + UpdateProjectExplorer(); } private void InitMessagesWindow() Index: Core/Gui/src/Core.Gui/GuiCore.cs =================================================================== diff -u -r369400e3add949c344017f34f89620f095eac05a -r0fe90cd590613f74567c85622bbd2235419a5d5f --- Core/Gui/src/Core.Gui/GuiCore.cs (.../GuiCore.cs) (revision 369400e3add949c344017f34f89620f095eac05a) +++ Core/Gui/src/Core.Gui/GuiCore.cs (.../GuiCore.cs) (revision 0fe90cd590613f74567c85622bbd2235419a5d5f) @@ -492,7 +492,7 @@ foreach (StateInfo stateInfo in Plugins.SelectMany(p => p.GetStateInfos())) { - mainWindow.AddStateButton(stateInfo.Name, stateInfo.Symbol); + mainWindow.AddStateButton(stateInfo.Name, stateInfo.Symbol, stateInfo.GetRootData); } mainWindow.SubscribeToGui();