Skip to content

Commit

Permalink
Finish implementing new dialog approach
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandreu committed Jun 21, 2019
1 parent 742d754 commit 0780d98
Show file tree
Hide file tree
Showing 22 changed files with 300 additions and 125 deletions.
2 changes: 1 addition & 1 deletion OfficeRibbonXEditor/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public App()
builder.RegisterType<MessageBoxService>().As<IMessageBoxService>();
builder.RegisterType<FileDialogService>().As<IFileDialogService>();
builder.RegisterType<VersionChecker>().As<IVersionChecker>();
builder.RegisterType<DialogService>().As<IDialogService>();
builder.RegisterType<DialogProvider>().As<IDialogProvider>();

builder.RegisterType<MainWindowViewModel>();
builder.RegisterType<DialogHostViewModel>();
builder.RegisterType<SettingsDialogViewModel>();
builder.RegisterType<AboutDialogViewModel>();
builder.RegisterType<CallbackDialogViewModel>();

this.container = builder.Build();
}
Expand Down
77 changes: 77 additions & 0 deletions OfficeRibbonXEditor/Controls/DialogControl.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
8 changes: 0 additions & 8 deletions OfficeRibbonXEditor/Interfaces/IContentDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CancelEventArgs> ClosingCommand { get; }

event EventHandler Closed;
Expand Down
12 changes: 0 additions & 12 deletions OfficeRibbonXEditor/Interfaces/IDialogService.cs

This file was deleted.

15 changes: 7 additions & 8 deletions OfficeRibbonXEditor/OfficeRibbonXEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@
<Compile Include="..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Controls\DialogControl.cs" />
<Compile Include="Controls\ExternalHyperlink.cs" />
<Compile Include="Converters\InverseBooleanToVisibilityConverter.cs" />
<Compile Include="Converters\IsNotNullConverter.cs" />
<Compile Include="Converters\MethodToCommandConverter.cs" />
<Compile Include="Converters\StringToVisibilityConverter.cs" />
<Compile Include="Converters\ValueConverterGroup.cs" />
<Compile Include="ViewModels\CallbackDialogViewModel.cs" />
<Compile Include="ViewModels\DialogBase.cs" />
<Compile Include="ViewModels\AboutDialogViewModel.cs" />
<Compile Include="Views\DialogHost.xaml.cs">
Expand Down Expand Up @@ -186,9 +188,7 @@
<DependentUpon>SchemasResource.resx</DependentUpon>
</Compile>
<Compile Include="Services\DialogProvider.cs" />
<Compile Include="Services\DialogService.cs" />
<Compile Include="Services\FileDialogService.cs" />
<Compile Include="Interfaces\IDialogService.cs" />
<Compile Include="Interfaces\IFileDialogService.cs" />
<Compile Include="Interfaces\IMessageBoxService.cs" />
<Compile Include="Interfaces\IVersionChecker.cs" />
Expand All @@ -202,8 +202,8 @@
<Compile Include="Views\AboutDialog.xaml.cs">
<DependentUpon>AboutDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Views\CallbackWindow.xaml.cs">
<DependentUpon>CallbackWindow.xaml</DependentUpon>
<Compile Include="Views\CallbackDialog.xaml.cs">
<DependentUpon>CallbackDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\ColorConverter.cs" />
<Compile Include="Converters\DataTypeConverter.cs" />
Expand All @@ -212,6 +212,7 @@
<Compile Include="ViewModels\OfficeDocumentViewModel.cs" />
<Compile Include="ViewModels\TreeViewItemViewModel.cs" />
<Compile Include="Models\OfficeDocument.cs" />
<Compile Include="Views\DialogHostBase.cs" />
<Compile Include="Views\SettingsDialog.xaml.cs">
<DependentUpon>SettingsDialog.xaml</DependentUpon>
</Compile>
Expand All @@ -231,7 +232,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\CallbackWindow.xaml">
<Page Include="Views\CallbackDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down Expand Up @@ -350,9 +351,7 @@
<Resource Include="Resources\Images\find_previous.png" />
<Resource Include="Resources\Images\go_to.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Dialogs\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
13 changes: 0 additions & 13 deletions OfficeRibbonXEditor/Services/DialogService.cs

This file was deleted.

5 changes: 0 additions & 5 deletions OfficeRibbonXEditor/ViewModels/AboutDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ namespace OfficeRibbonXEditor.ViewModels

public class AboutDialogViewModel : DialogBase
{
public AboutDialogViewModel()
: base("About Office RibbonX Editor")
{
}

public string AssemblyTitle
{
get
Expand Down
46 changes: 46 additions & 0 deletions OfficeRibbonXEditor/ViewModels/CallbackDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using OfficeRibbonXEditor.Interfaces;
using OfficeRibbonXEditor.Models;

namespace OfficeRibbonXEditor.ViewModels
{

public class CallbackDialogViewModel : DialogBase, IContentDialog<string>
{
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;
}
}
}
14 changes: 1 addition & 13 deletions OfficeRibbonXEditor/ViewModels/DialogBase.cs
Original file line number Diff line number Diff line change
@@ -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<CancelEventArgs>(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<CancelEventArgs> ClosingCommand { get; }

public RelayCommand CloseCommand { get; }
Expand Down
4 changes: 1 addition & 3 deletions OfficeRibbonXEditor/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ public MainWindowViewModel(IMessageBoxService messageBoxService, IFileDialogServ

public event EventHandler<DataEventArgs<IContentDialogBase>> LaunchingDialog;

public event EventHandler<DataEventArgs<string>> ShowCallbacks;

/// <summary>
/// This event will be fired when the contents of the editor need to be updated
/// </summary>
Expand Down Expand Up @@ -864,7 +862,7 @@ private void ExecuteGenerateCallbacksCommand()
return;
}

this.ShowCallbacks?.Invoke(this, new DataEventArgs<string> { Data = callbacks.ToString() });
this.LaunchDialog<CallbackDialogViewModel, string>(callbacks.ToString());
}
catch (Exception ex)
{
Expand Down
3 changes: 0 additions & 3 deletions OfficeRibbonXEditor/ViewModels/SettingsDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -28,7 +26,6 @@ public class SettingsDialogViewModel : DialogBase, IContentDialog<ScintillaLexer
private readonly Dictionary<string, object> currentValues = new Dictionary<string, object>();

public SettingsDialogViewModel()
: base("Settings", Resources.ImagesResource.settings)
{
this.ResetCommand = new RelayCommand(this.ResetToDefault);
this.ApplyCommand = new RelayCommand(this.ApplySettings);
Expand Down
14 changes: 8 additions & 6 deletions OfficeRibbonXEditor/Views/AboutDialog.xaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<UserControl x:Class="OfficeRibbonXEditor.Views.AboutDialog"
<controls:DialogControl x:Class="OfficeRibbonXEditor.Views.AboutDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:OfficeRibbonXEditor.Controls"
xmlns:viewModels="clr-namespace:OfficeRibbonXEditor.ViewModels"
mc:Ignorable="d"
Width="431.296"
Height="374.47"
Title="About Office RibbonX Editor"
PreferredWidth="450"
SizeToContent="Height"
d:DesignWidth="{Binding PreferredWidth, RelativeSource={RelativeSource Self}}"
d:DataContext="{d:DesignInstance viewModels:AboutDialogViewModel}">
<UserControl.Resources>
<controls:DialogControl.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="12"/>
</Style>
</UserControl.Resources>
</controls:DialogControl.Resources>
<DockPanel LastChildFill="False" Margin="12">
<TextBlock DockPanel.Dock="Top" TextWrapping="Wrap" Margin="0,2">
<TextBlock FontWeight="Bold">Author:</TextBlock> Fernando Andreu
Expand Down Expand Up @@ -41,4 +43,4 @@
<Button Content="Close" Padding="10,2" Margin="8,0,0,0" Command="{Binding CloseCommand}"/>
</StackPanel>
</DockPanel>
</UserControl>
</controls:DialogControl>
4 changes: 2 additions & 2 deletions OfficeRibbonXEditor/Views/AboutDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System.Windows.Controls;
using OfficeRibbonXEditor.Controls;

namespace OfficeRibbonXEditor.Views
{
/// <summary>
/// About dialog for the tool
/// </summary>
public partial class AboutDialog : UserControl
public partial class AboutDialog : DialogControl
{
public AboutDialog()
{
Expand Down
Loading

0 comments on commit 0780d98

Please sign in to comment.