From 0780d98b270c5a2b15d2c7e2a8f6a5624d6d3d81 Mon Sep 17 00:00:00 2001 From: Fernando <2480661+fernandreu@users.noreply.github.com> Date: Fri, 21 Jun 2019 20:04:57 +0100 Subject: [PATCH] Finish implementing new dialog approach --- OfficeRibbonXEditor/App.xaml.cs | 2 +- OfficeRibbonXEditor/Controls/DialogControl.cs | 77 +++++++++++++ .../Interfaces/IContentDialog.cs | 8 -- .../Interfaces/IDialogService.cs | 12 --- .../OfficeRibbonXEditor.csproj | 15 ++- OfficeRibbonXEditor/Services/DialogService.cs | 13 --- .../ViewModels/AboutDialogViewModel.cs | 5 - .../ViewModels/CallbackDialogViewModel.cs | 46 ++++++++ OfficeRibbonXEditor/ViewModels/DialogBase.cs | 14 +-- .../ViewModels/MainWindowViewModel.cs | 4 +- .../ViewModels/SettingsDialogViewModel.cs | 3 - OfficeRibbonXEditor/Views/AboutDialog.xaml | 14 +-- OfficeRibbonXEditor/Views/AboutDialog.xaml.cs | 4 +- ...allbackWindow.xaml => CallbackDialog.xaml} | 21 ++-- ...kWindow.xaml.cs => CallbackDialog.xaml.cs} | 28 +++-- OfficeRibbonXEditor/Views/DialogHost.xaml | 28 ++--- OfficeRibbonXEditor/Views/DialogHost.xaml.cs | 2 +- OfficeRibbonXEditor/Views/DialogHostBase.cs | 101 ++++++++++++++++++ OfficeRibbonXEditor/Views/MainWindow.xaml.cs | 6 -- OfficeRibbonXEditor/Views/SettingsDialog.xaml | 7 +- .../Views/SettingsDialog.xaml.cs | 4 +- .../ViewModels/MainWindowViewModelTests.cs | 11 +- 22 files changed, 300 insertions(+), 125 deletions(-) create mode 100644 OfficeRibbonXEditor/Controls/DialogControl.cs delete mode 100644 OfficeRibbonXEditor/Interfaces/IDialogService.cs delete mode 100644 OfficeRibbonXEditor/Services/DialogService.cs create mode 100644 OfficeRibbonXEditor/ViewModels/CallbackDialogViewModel.cs rename OfficeRibbonXEditor/Views/{CallbackWindow.xaml => CallbackDialog.xaml} (62%) rename OfficeRibbonXEditor/Views/{CallbackWindow.xaml.cs => CallbackDialog.xaml.cs} (51%) create mode 100644 OfficeRibbonXEditor/Views/DialogHostBase.cs diff --git a/OfficeRibbonXEditor/App.xaml.cs b/OfficeRibbonXEditor/App.xaml.cs index 339d0158..e3329289 100644 --- a/OfficeRibbonXEditor/App.xaml.cs +++ b/OfficeRibbonXEditor/App.xaml.cs @@ -34,13 +34,13 @@ public App() builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); - builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType(); builder.RegisterType(); builder.RegisterType(); builder.RegisterType(); + builder.RegisterType(); this.container = builder.Build(); } diff --git a/OfficeRibbonXEditor/Controls/DialogControl.cs b/OfficeRibbonXEditor/Controls/DialogControl.cs new file mode 100644 index 00000000..7b69a63d --- /dev/null +++ b/OfficeRibbonXEditor/Controls/DialogControl.cs @@ -0,0 +1,77 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; + +namespace OfficeRibbonXEditor.Controls +{ + public class DialogControl : UserControl + { + public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( + nameof(Title), + typeof(string), + typeof(DialogControl)); + + public string Title + { + get => (string) this.GetValue(TitleProperty); + set => this.SetValue(TitleProperty, value); + } + + public static readonly DependencyProperty IconProperty = DependencyProperty.Register( + nameof(Icon), + typeof(ImageSource), + typeof(DialogControl)); + + public ImageSource Icon + { + get => (ImageSource) this.GetValue(IconProperty); + set => this.SetValue(IconProperty, value); + } + + public static readonly DependencyProperty PreferredWidthProperty = DependencyProperty.Register( + nameof(PreferredWidth), + typeof(double), + typeof(DialogControl)); + + public double PreferredWidth + { + get => (double) this.GetValue(PreferredWidthProperty); + set => this.SetValue(PreferredWidthProperty, value); + } + + public static readonly DependencyProperty PreferredHeightProperty = DependencyProperty.Register( + nameof(PreferredHeight), + typeof(double), + typeof(DialogControl)); + + public double PreferredHeight + { + get => (double) this.GetValue(PreferredHeightProperty); + set => this.SetValue(PreferredHeightProperty, value); + } + + public static readonly DependencyProperty SizeToContentProperty = DependencyProperty.Register( + nameof(SizeToContent), + typeof(SizeToContent), + typeof(DialogControl), + new FrameworkPropertyMetadata(SizeToContent.WidthAndHeight)); + + public SizeToContent SizeToContent + { + get => (SizeToContent) this.GetValue(SizeToContentProperty); + set => this.SetValue(SizeToContentProperty, value); + } + + public static readonly DependencyProperty ResizeModeProperty = DependencyProperty.Register( + nameof(ResizeMode), + typeof(ResizeMode), + typeof(DialogControl), + new FrameworkPropertyMetadata(ResizeMode.NoResize)); + + public ResizeMode ResizeMode + { + get => (ResizeMode) this.GetValue(ResizeModeProperty); + set => this.SetValue(ResizeModeProperty, value); + } + } +} diff --git a/OfficeRibbonXEditor/Interfaces/IContentDialog.cs b/OfficeRibbonXEditor/Interfaces/IContentDialog.cs index b1ba7d4d..dddf02bd 100644 --- a/OfficeRibbonXEditor/Interfaces/IContentDialog.cs +++ b/OfficeRibbonXEditor/Interfaces/IContentDialog.cs @@ -2,20 +2,12 @@ { using System; using System.ComponentModel; - using System.Windows; - using System.Windows.Media; using GalaSoft.MvvmLight.Command; public interface IContentDialogBase { bool Cancelled { get; } - string Title { get; } - - ImageSource Icon { get; } - - ResizeMode ResizeMode { get; } - RelayCommand ClosingCommand { get; } event EventHandler Closed; diff --git a/OfficeRibbonXEditor/Interfaces/IDialogService.cs b/OfficeRibbonXEditor/Interfaces/IDialogService.cs deleted file mode 100644 index 37b5e66d..00000000 --- a/OfficeRibbonXEditor/Interfaces/IDialogService.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace OfficeRibbonXEditor.Interfaces -{ - using System.Threading.Tasks; - - /// - /// Defines how UI view models should launch dialogs by referencing their corresponding view models - /// - public interface IDialogService - { - void ShowDialog(TPayload payload) where TDialog : IContentDialog; - } -} diff --git a/OfficeRibbonXEditor/OfficeRibbonXEditor.csproj b/OfficeRibbonXEditor/OfficeRibbonXEditor.csproj index c0c27b74..7ebbc4f5 100644 --- a/OfficeRibbonXEditor/OfficeRibbonXEditor.csproj +++ b/OfficeRibbonXEditor/OfficeRibbonXEditor.csproj @@ -152,12 +152,14 @@ Properties\SharedAssemblyInfo.cs + + @@ -186,9 +188,7 @@ SchemasResource.resx - - @@ -202,8 +202,8 @@ AboutDialog.xaml - - CallbackWindow.xaml + + CallbackDialog.xaml @@ -212,6 +212,7 @@ + SettingsDialog.xaml @@ -231,7 +232,7 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile @@ -350,9 +351,7 @@ - - - + diff --git a/OfficeRibbonXEditor/Services/DialogService.cs b/OfficeRibbonXEditor/Services/DialogService.cs deleted file mode 100644 index e3f69dc4..00000000 --- a/OfficeRibbonXEditor/Services/DialogService.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace OfficeRibbonXEditor.Services -{ - using System.Threading.Tasks; - using OfficeRibbonXEditor.Interfaces; - - public class DialogService : IDialogService - { - public void ShowDialog(TPayload payload) where TDialog : IContentDialog - { - throw new System.NotImplementedException(); - } - } -} diff --git a/OfficeRibbonXEditor/ViewModels/AboutDialogViewModel.cs b/OfficeRibbonXEditor/ViewModels/AboutDialogViewModel.cs index acea52f3..b79fd1d2 100644 --- a/OfficeRibbonXEditor/ViewModels/AboutDialogViewModel.cs +++ b/OfficeRibbonXEditor/ViewModels/AboutDialogViewModel.cs @@ -5,11 +5,6 @@ namespace OfficeRibbonXEditor.ViewModels public class AboutDialogViewModel : DialogBase { - public AboutDialogViewModel() - : base("About Office RibbonX Editor") - { - } - public string AssemblyTitle { get diff --git a/OfficeRibbonXEditor/ViewModels/CallbackDialogViewModel.cs b/OfficeRibbonXEditor/ViewModels/CallbackDialogViewModel.cs new file mode 100644 index 00000000..27d3abf8 --- /dev/null +++ b/OfficeRibbonXEditor/ViewModels/CallbackDialogViewModel.cs @@ -0,0 +1,46 @@ +using OfficeRibbonXEditor.Interfaces; +using OfficeRibbonXEditor.Models; + +namespace OfficeRibbonXEditor.ViewModels +{ + + public class CallbackDialogViewModel : DialogBase, IContentDialog + { + private VbaLexer lexer; + + private string code; + + public VbaLexer Lexer + { + get => this.lexer; + set + { + if (!this.Set(ref this.lexer, value) || this.Code == null) + { + return; + } + + this.Lexer.Editor.Text = this.Code; + } + } + + public string Code + { + get => this.code; + set + { + if (!this.Set(ref this.code, value) || this.Lexer == null) + { + return; + } + + this.Lexer.Editor.Text = this.Code; + } + } + + public void OnLoaded(string payload) + { + this.Code = payload; + } + } +} diff --git a/OfficeRibbonXEditor/ViewModels/DialogBase.cs b/OfficeRibbonXEditor/ViewModels/DialogBase.cs index 74e21d52..fe2b34ed 100644 --- a/OfficeRibbonXEditor/ViewModels/DialogBase.cs +++ b/OfficeRibbonXEditor/ViewModels/DialogBase.cs @@ -1,33 +1,21 @@ using System; using System.ComponentModel; -using System.Drawing; -using System.Windows; -using System.Windows.Media; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; -using OfficeRibbonXEditor.Extensions; using OfficeRibbonXEditor.Interfaces; namespace OfficeRibbonXEditor.ViewModels { public class DialogBase : ViewModelBase, IContentDialogBase { - public DialogBase(string title, Bitmap icon = null) + public DialogBase() { - this.Title = title; - this.Icon = icon?.AsBitmapImage(); this.ClosingCommand = new RelayCommand(this.ExecuteClosingCommand); this.CloseCommand = new RelayCommand(this.Close); } public bool Cancelled { get; protected set; } = true; - public virtual ResizeMode ResizeMode => ResizeMode.NoResize; - - public string Title { get; } - - public ImageSource Icon { get; } - public RelayCommand ClosingCommand { get; } public RelayCommand CloseCommand { get; } diff --git a/OfficeRibbonXEditor/ViewModels/MainWindowViewModel.cs b/OfficeRibbonXEditor/ViewModels/MainWindowViewModel.cs index 8aaf82ac..d0281de1 100644 --- a/OfficeRibbonXEditor/ViewModels/MainWindowViewModel.cs +++ b/OfficeRibbonXEditor/ViewModels/MainWindowViewModel.cs @@ -120,8 +120,6 @@ public MainWindowViewModel(IMessageBoxService messageBoxService, IFileDialogServ public event EventHandler> LaunchingDialog; - public event EventHandler> ShowCallbacks; - /// /// This event will be fired when the contents of the editor need to be updated /// @@ -864,7 +862,7 @@ private void ExecuteGenerateCallbacksCommand() return; } - this.ShowCallbacks?.Invoke(this, new DataEventArgs { Data = callbacks.ToString() }); + this.LaunchDialog(callbacks.ToString()); } catch (Exception ex) { diff --git a/OfficeRibbonXEditor/ViewModels/SettingsDialogViewModel.cs b/OfficeRibbonXEditor/ViewModels/SettingsDialogViewModel.cs index 3d6caf01..7aecb8b4 100644 --- a/OfficeRibbonXEditor/ViewModels/SettingsDialogViewModel.cs +++ b/OfficeRibbonXEditor/ViewModels/SettingsDialogViewModel.cs @@ -1,8 +1,6 @@ using System.Collections.Generic; using System.ComponentModel; -using System.Windows.Media; using GalaSoft.MvvmLight.Command; -using OfficeRibbonXEditor.Extensions; using OfficeRibbonXEditor.Interfaces; using OfficeRibbonXEditor.Models; @@ -28,7 +26,6 @@ public class SettingsDialogViewModel : DialogBase, IContentDialog currentValues = new Dictionary(); public SettingsDialogViewModel() - : base("Settings", Resources.ImagesResource.settings) { this.ResetCommand = new RelayCommand(this.ResetToDefault); this.ApplyCommand = new RelayCommand(this.ApplySettings); diff --git a/OfficeRibbonXEditor/Views/AboutDialog.xaml b/OfficeRibbonXEditor/Views/AboutDialog.xaml index 80fcd90d..d377eb6f 100644 --- a/OfficeRibbonXEditor/Views/AboutDialog.xaml +++ b/OfficeRibbonXEditor/Views/AboutDialog.xaml @@ -1,4 +1,4 @@ - - + - + Author: Fernando Andreu @@ -41,4 +43,4 @@