From 0f79ad4b87d62a3da2ff09e45c03e6708df2a3f3 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 11 Jun 2017 16:04:47 +0200 Subject: [PATCH] Refactored and added more basic stuff --- Arge/Arge.csproj | 33 +++++-- Arge/Attached/ListBoxExtension.cs | 59 +++++++++++ Arge/Bootstrapper/ArgeBootstrapper.cs | 19 +--- Arge/Bootstrapper/NavigationManager.cs | 90 ----------------- Arge/Bootstrapper/UnityBootstrapper.cs | 14 +-- Arge/Resources/Arge.xaml | 4 +- Arge/Resources/Fonts.cs | 71 ++++++++++++++ Arge/Resources/ImageSources.cs | 12 +-- Arge/Styles/BlurredDecorationWindow.xaml | 2 + Arge/Styles/ImageButton.xaml | 8 +- Arge/Styles/Navigation.xaml | 108 +++++++++++++++++++++ Arge/Styles/ToolTip.xaml | 11 ++- Arge/Themes/Default/Theme.xaml | 15 +++ Arge/Themes/Default/default.ttf | Bin 0 -> 56228 bytes Arge/Themes/Default/navigation.ttf | Bin 0 -> 62448 bytes Arge/Themes/ThemeManager.cs | 1 + Arge/ViewModels/AbstractViewModel.cs | 15 ++- Arge/ViewModels/LightingLayoutViewModel.cs | 23 +++++ Arge/ViewModels/NavigationViewModel.cs | 7 -- Arge/ViewModels/SettingsLayoutViewModel.cs | 23 +++++ Arge/ViewModels/ShellViewModel.cs | 52 +++++++--- Arge/Views/LightingLayoutView.xaml | 12 +++ Arge/Views/LightingLayoutView.xaml.cs | 15 +++ Arge/Views/NavigationView.xaml | 14 --- Arge/Views/NavigationView.xaml.cs | 18 ---- Arge/Views/SettingsLayoutView.xaml | 12 +++ Arge/Views/SettingsLayoutView.xaml.cs | 15 +++ Arge/Views/ShellView.xaml | 30 ++++-- Arge/Views/ShellView.xaml.cs | 35 +++++-- 29 files changed, 522 insertions(+), 196 deletions(-) create mode 100644 Arge/Attached/ListBoxExtension.cs delete mode 100644 Arge/Bootstrapper/NavigationManager.cs create mode 100644 Arge/Resources/Fonts.cs create mode 100644 Arge/Styles/Navigation.xaml create mode 100644 Arge/Themes/Default/default.ttf create mode 100644 Arge/Themes/Default/navigation.ttf create mode 100644 Arge/ViewModels/LightingLayoutViewModel.cs delete mode 100644 Arge/ViewModels/NavigationViewModel.cs create mode 100644 Arge/ViewModels/SettingsLayoutViewModel.cs create mode 100644 Arge/Views/LightingLayoutView.xaml create mode 100644 Arge/Views/LightingLayoutView.xaml.cs delete mode 100644 Arge/Views/NavigationView.xaml delete mode 100644 Arge/Views/NavigationView.xaml.cs create mode 100644 Arge/Views/SettingsLayoutView.xaml create mode 100644 Arge/Views/SettingsLayoutView.xaml.cs diff --git a/Arge/Arge.csproj b/Arge/Arge.csproj index d565bee..366b35b 100644 --- a/Arge/Arge.csproj +++ b/Arge/Arge.csproj @@ -102,8 +102,8 @@ App.xaml Code + - @@ -113,15 +113,20 @@ + - + + - - NavigationView.xaml + + SettingsLayoutView.xaml + + + LightingLayoutView.xaml ShellView.xaml @@ -155,9 +160,7 @@ - - - + MSBuild:Compile @@ -171,6 +174,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -183,11 +190,21 @@ MSBuild:Compile Designer + + PreserveNewest + + + PreserveNewest + Designer Always - + + MSBuild:Compile + Designer + + Designer MSBuild:Compile diff --git a/Arge/Attached/ListBoxExtension.cs b/Arge/Attached/ListBoxExtension.cs new file mode 100644 index 0000000..b6255d6 --- /dev/null +++ b/Arge/Attached/ListBoxExtension.cs @@ -0,0 +1,59 @@ +using System; +using System.Windows; +using System.Windows.Controls; + +namespace Arge.Attached +{ + public class ListBoxExtension + { + #region AttachedProperties + + // ReSharper disable once InconsistentNaming + public static readonly DependencyProperty AlwaysSelectItemProperty = DependencyProperty.RegisterAttached( + "AlwaysSelectItem", typeof(bool), typeof(ListBoxExtension), new PropertyMetadata(default(bool), AlwaysSelectItemChanged)); + + public static void SetAlwaysSelectItem(DependencyObject element, bool value) => element.SetValue(AlwaysSelectItemProperty, value); + public static bool GetAlwaysSelectItem(DependencyObject element) => (bool)element.GetValue(AlwaysSelectItemProperty); + + #endregion + + #region Methods + + private static void AlwaysSelectItemChanged(DependencyObject dependencyObject, + DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) + { + ListBox listBox = dependencyObject as ListBox; + if (listBox == null) return; + + if (dependencyPropertyChangedEventArgs.NewValue as bool? == true) + listBox.SelectionChanged += AlwaysSelectItemSelectionChanged; + else + listBox.SelectionChanged -= AlwaysSelectItemSelectionChanged; + } + + private static void AlwaysSelectItemSelectionChanged(object sender, + SelectionChangedEventArgs selectionChangedEventArgs) + { + ListBox listBox = sender as ListBox; + if (listBox == null) return; + + if (listBox.SelectedItem != null) return; + + object selectionTarget = null; + if (selectionChangedEventArgs.RemovedItems.Count > 0) + { + object unselectedItem = selectionChangedEventArgs.RemovedItems[0]; + if (listBox.Items.Contains(unselectedItem)) + selectionTarget = unselectedItem; + } + + if ((selectionTarget == null) && (listBox.Items.Count > 0)) + selectionTarget = listBox.Items[0]; + + if (selectionTarget != null) + listBox.Dispatcher.BeginInvoke(new Action(() => listBox.SelectedItem = selectionTarget)); + } + + #endregion + } +} diff --git a/Arge/Bootstrapper/ArgeBootstrapper.cs b/Arge/Bootstrapper/ArgeBootstrapper.cs index 6aeb276..e3274ae 100644 --- a/Arge/Bootstrapper/ArgeBootstrapper.cs +++ b/Arge/Bootstrapper/ArgeBootstrapper.cs @@ -1,9 +1,5 @@ -using System; -using System.Diagnostics; -using System.Windows; -using System.Windows.Media.Imaging; +using System.Windows; using Arge.Configuration; -using Arge.Controls.Window; using Arge.Themes; using Arge.ViewModels; using Arge.Views; @@ -30,7 +26,8 @@ namespace Arge.Bootstrapper private void RegisterViews() { RegisterView(); - RegisterView(); + RegisterView(); + RegisterView(); } protected override void InitializeHandlers() @@ -42,14 +39,8 @@ namespace Arge.Bootstrapper Config.Instance.Load(); Container.Resolve().LoadTheme(Config.Instance[ConfigEntryType.Theme]); - BlurredDecorationWindow window = new BlurredDecorationWindow - { - Width = 1280, - Height = 720, - Icon = new BitmapImage(new Uri("pack://application:,,,/Arge;component/Resources/ArgeBee.ico")), - IconCommand = ReactiveCommand.Create(() => Process.Start("http://arge.be")), - Content = Container.Resolve() - }; + ShellView window = Container.Resolve(); + RegisterSingleton(typeof(IScreen), window.ViewModel); Application.Current.MainWindow = window; window.Show(); } diff --git a/Arge/Bootstrapper/NavigationManager.cs b/Arge/Bootstrapper/NavigationManager.cs deleted file mode 100644 index 2b47fe3..0000000 --- a/Arge/Bootstrapper/NavigationManager.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Collections.Generic; -using Arge.Enums; -using Microsoft.Practices.Unity; - -namespace Arge.Bootstrapper -{ - //TODO DarthAffe 21.05.2017: This allows some sort of fake VM-first - One day I should make this cleaner ... - public class NavigationManager - { - #region Properties & Fields - - public static NavigationManager Instance { get; private set; } - - private readonly Dictionary _viewTypeMapping = new Dictionary(); - - private readonly IUnityContainer _container; - - public object Navigation { get; private set; } - public object Layers { get; private set; } - public object Selection { get; private set; } - public object Action { get; private set; } - public object Surface { get; private set; } - - #endregion - - #region Constructors - - private NavigationManager(IUnityContainer container) - { - this._container = container; - } - - #endregion - - #region Methods - - public static void Initialize(IUnityContainer container) - { - Instance = new NavigationManager(container); - } - - public void RegisterViewTypes(Type viewType, Type viewModelType) - { - _viewTypeMapping[viewModelType] = viewType; - } - - public void Navigate(NavigationTargets target) - { - Navigate(target, typeof(TTarget)); - } - - public void Navigate(NavigationTargets target, Type targetType) - { - Type viewType; - if (!_viewTypeMapping.TryGetValue(targetType, out viewType)) - viewType = targetType; - - Navigate(target, _container.Resolve(viewType)); - } - - public void Navigate(NavigationTargets target, object view) - { - switch (target) - { - case NavigationTargets.Navigation: - Navigation = view; - break; - - case NavigationTargets.Layers: - Layers = view; - break; - - case NavigationTargets.Selection: - Selection = view; - break; - - case NavigationTargets.Action: - Action = view; - break; - - case NavigationTargets.Surface: - Surface = view; - break; - } - } - - #endregion - } -} diff --git a/Arge/Bootstrapper/UnityBootstrapper.cs b/Arge/Bootstrapper/UnityBootstrapper.cs index 13397bb..d6862bb 100644 --- a/Arge/Bootstrapper/UnityBootstrapper.cs +++ b/Arge/Bootstrapper/UnityBootstrapper.cs @@ -34,7 +34,6 @@ namespace Arge.Bootstrapper RegisterSingleton(Container); Locator.Current = new UnityDependencyResolver(Container); - NavigationManager.Initialize(Container); } protected abstract void RegisterTypes(); @@ -45,12 +44,10 @@ namespace Arge.Bootstrapper #region Container-Registration - protected void RegisterService(bool registerTypeToo = true, bool registerAsSingleton = true, string uniqueName = null) + protected void RegisterService(bool registerAsSingleton = true, string uniqueName = null) where TImplementation : TInterface { RegisterTypeIfMissing(typeof(TInterface), typeof(TImplementation), registerAsSingleton, uniqueName); - if (registerTypeToo) - RegisterTypeIfMissing(typeof(TImplementation), typeof(TImplementation), registerAsSingleton, uniqueName); } protected void RegisterView() @@ -59,8 +56,6 @@ namespace Arge.Bootstrapper { RegisterTypeIfMissing(typeof(TView), typeof(TView), false); RegisterTypeIfMissing(typeof(TViewModel), typeof(TViewModel), false); - - NavigationManager.Instance.RegisterViewTypes(typeof(TView), typeof(TViewModel)); } protected void RegisterSingleton() @@ -70,7 +65,12 @@ namespace Arge.Bootstrapper protected void RegisterSingleton(T instance) { - Container.RegisterInstance(typeof(T), instance, new ContainerControlledLifetimeManager()); + RegisterSingleton(typeof(T), instance); + } + + protected void RegisterSingleton(Type t, object instance) + { + Container.RegisterInstance(t, instance, new ContainerControlledLifetimeManager()); } protected void RegisterTypeIfMissing(Type fromType, Type toType, bool registerAsSingleton, string uniqueName = null) diff --git a/Arge/Resources/Arge.xaml b/Arge/Resources/Arge.xaml index 69d731f..c4005d3 100644 --- a/Arge/Resources/Arge.xaml +++ b/Arge/Resources/Arge.xaml @@ -2,7 +2,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:resources="clr-namespace:Arge.Resources" xmlns:buttons="clr-namespace:Arge.Controls.Buttons" - xmlns:window="clr-namespace:Arge.Controls.Window"> + xmlns:window="clr-namespace:Arge.Controls.Window" + xmlns:views="clr-namespace:Arge.Views"> @@ -11,6 +12,7 @@ - + \ No newline at end of file diff --git a/Arge/Styles/Navigation.xaml b/Arge/Styles/Navigation.xaml new file mode 100644 index 0000000..b69b22d --- /dev/null +++ b/Arge/Styles/Navigation.xaml @@ -0,0 +1,108 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Arge/Styles/ToolTip.xaml b/Arge/Styles/ToolTip.xaml index ae30986..e0d8dfb 100644 --- a/Arge/Styles/ToolTip.xaml +++ b/Arge/Styles/ToolTip.xaml @@ -1,10 +1,19 @@  + + + + -