Redesigned sidebar

Removed dependency on Mahapps, ControlzEx and Dragablz
This commit is contained in:
Robert committed 2019-12-10 16:29:47 +01:00
1 parent b9471abdec
commit 146c545f02
27 files changed
+377 -474

No files matched your search

@@ -0,0 +1,31 @@
<UserControl x:Class="Artemis.UI.Screens.Sidebar.SidebarView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:sidebar="clr-namespace:Artemis.UI.Screens.Sidebar"
xmlns:controls="clr-namespace:MaterialDesignExtensions.Controls;assembly=MaterialDesignExtensions"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance sidebar:SidebarViewModel}">
<StackPanel>
<!-- Placeholder -->
<StackPanel Margin="15">
<materialDesign:PackIcon Kind="QuestionMarkCircle" Width="50" Height="50" />
<TextBlock Style="{StaticResource MaterialDesignTitleTextBlock}" Margin="0 15 0 0">
Active module
</TextBlock>
<ComboBox BorderThickness="0" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" materialDesign:HintAssist.Hint="Active profile">
<ComboBoxItem>Profile 1</ComboBoxItem>
<ComboBoxItem>Profile 2</ComboBoxItem>
<ComboBoxItem>Profile 3</ComboBoxItem>
<ComboBoxItem>Profile 4</ComboBoxItem>
</ComboBox>
</StackPanel>
<controls:SideNavigation Items="{Binding SidebarItems}" WillSelectNavigationItemCommand="{s:Action SelectItem}" />
</StackPanel>
</UserControl>
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis.UI.Screens.Sidebar
{
/// <summary>
/// Interaction logic for SidebarView.xaml
/// </summary>
public partial class SidebarView : UserControl
{
public SidebarView()
{
InitializeComponent();
}
}
}
@@ -0,0 +1,123 @@
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Events;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Ninject.Factories;
using MaterialDesignExtensions.Controls;
using MaterialDesignExtensions.Model;
using MaterialDesignThemes.Wpf;
using Stylet;
namespace Artemis.UI.Screens.Sidebar
{
public class SidebarViewModel : PropertyChangedBase
{
private readonly IModuleViewModelFactory _moduleViewModelFactory;
private readonly IPluginService _pluginService;
public SidebarViewModel(List<MainScreenViewModel> defaultSidebarItems, IModuleViewModelFactory moduleViewModelFactory, IPluginService pluginService)
{
_moduleViewModelFactory = moduleViewModelFactory;
_pluginService = pluginService;
DefaultSidebarItems = defaultSidebarItems;
SidebarItemObjects = new Dictionary<INavigationItem, object>();
SidebarItems = new BindableCollection<INavigationItem>();
SetupSidebar();
_pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
_pluginService.PluginDisabled += PluginServiceOnPluginDisabled;
}
public List<MainScreenViewModel> DefaultSidebarItems { get; set; }
public BindableCollection<INavigationItem> SidebarItems { get; set; }
public Dictionary<INavigationItem, object> SidebarItemObjects { get; set; }
public IScreen SelectedItem { get; set; }
public void SetupSidebar()
{
SidebarItems.Clear();
SidebarItemObjects.Clear();
// Add all default sidebar items
SidebarItems.Add(new DividerNavigationItem());
foreach (var screen in DefaultSidebarItems.OrderBy(d => d.DisplayOrder))
{
var sidebarItem = new FirstLevelNavigationItem {Icon = screen.DisplayIcon, Label = screen.DisplayName};
SidebarItems.Add(sidebarItem);
SidebarItemObjects.Add(sidebarItem, screen);
}
// Add all activated modules
SidebarItems.Add(new DividerNavigationItem());
SidebarItems.Add(new SubheaderNavigationItem {Subheader = "Modules"});
var modules = _pluginService.GetPluginsOfType<Core.Plugins.Abstract.Module>().ToList();
foreach (var module in modules)
AddModule(module);
// Select the top item, which will be one of the defaults
SidebarItems[1].IsSelected = true;
SelectedItem = (IScreen) SidebarItemObjects[SidebarItems[1]];
}
// ReSharper disable once UnusedMember.Global - Called by view
public void SelectItem(WillSelectNavigationItemEventArgs args)
{
if (args.NavigationItemToSelect == null)
{
SelectedItem = null;
return;
}
var sidebarItemObject = SidebarItemObjects[args.NavigationItemToSelect];
// The default items are singleton screens, simply set it as the selected item
if (sidebarItemObject is IScreen screen)
SelectedItem = screen;
// Modules have a VM that must be created, use a factory and set the result as the selected item
else if (sidebarItemObject is Core.Plugins.Abstract.Module module)
SelectedItem = _moduleViewModelFactory.Create(module);
}
public void AddModule(Core.Plugins.Abstract.Module module)
{
// Ensure the module is not already in the list
if (SidebarItemObjects.Any(io => io.Value == module))
return;
// Icon is provided as string to avoid having to reference MaterialDesignThemes
var parsedIcon = System.Enum.TryParse<PackIconKind>(module.DisplayIcon, true, out var iconEnum);
if (parsedIcon == false)
iconEnum = PackIconKind.QuestionMarkCircle;
var sidebarItem = new FirstLevelNavigationItem { Icon = iconEnum, Label = module.DisplayName };
SidebarItems.Add(sidebarItem);
SidebarItemObjects.Add(sidebarItem, module);
}
public void RemoveModule(Core.Plugins.Abstract.Module module)
{
// If not in the list there's nothing to do
if (SidebarItemObjects.All(io => io.Value != module))
return;
var existing = SidebarItemObjects.First(io => io.Value == module);
SidebarItems.Remove(existing.Key);
SidebarItemObjects.Remove(existing.Key);
}
#region Event handlers
private void PluginServiceOnPluginEnabled(object sender, PluginEventArgs e)
{
if (e.PluginInfo.Instance is Core.Plugins.Abstract.Module module)
AddModule(module);
}
private void PluginServiceOnPluginDisabled(object sender, PluginEventArgs e)
{
if (e.PluginInfo.Instance is Core.Plugins.Abstract.Module module)
RemoveModule(module);
}
#endregion
}
}