Skip to content

Commit

Permalink
dokončení přepisu do viewmodelu
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Feb 7, 2024
1 parent 0434d8c commit 016dd4f
Show file tree
Hide file tree
Showing 19 changed files with 398 additions and 164 deletions.
9 changes: 8 additions & 1 deletion ZZZO/ZZZO.Common/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using ZZZO.Common.Properties;

namespace ZZZO.Common
{
Expand All @@ -15,6 +17,8 @@ public static class Names
public const string Freepik = "www.freepik.com";
public static string AppAuthor;
public static string AppVersion;
public static DateTime AppBuildDate;
public static string AppBuildRevision;

#endregion

Expand All @@ -26,6 +30,9 @@ static Names()

AppVersion = vi.ProductVersion;
AppAuthor = vi.CompanyName;

AppBuildDate = DateTime.Parse(Resources.build_date);
AppBuildRevision = Resources.build_commit;
}

#endregion
Expand Down
6 changes: 3 additions & 3 deletions ZZZO/ZZZO.Common/MVVMHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ObservableObject : INotifyPropertyChanged
/// <summary>
/// Occurs when property changed.
/// </summary>
public event PropertyChangedEventHandler? PropertyChanged;
public event PropertyChangedEventHandler PropertyChanged;

#endregion

Expand Down Expand Up @@ -43,8 +43,8 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
protected virtual bool SetProperty<T>(
ref T backingStore, T value,
[CallerMemberName] string propertyName = "",
Action? onChanged = null,
Func<T, T, bool>? validateValue = null)
Action onChanged = null,
Func<T, T, bool> validateValue = null)
{
//if value didn't change
if (EqualityComparer<T>.Default.Equals(backingStore, value))
Expand Down
51 changes: 48 additions & 3 deletions ZZZO/ZZZO.Common/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions ZZZO/ZZZO.Common/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="build_commit" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\build-commit.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="build_date" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\build-date.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="style.css" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\style.css;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions ZZZO/ZZZO.Common/Resources/build-commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
devbuild-15-g0434d8c
1 change: 1 addition & 0 deletions ZZZO/ZZZO.Common/Resources/build-date.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-02-07T10:56:22.6948149+01:00
6 changes: 6 additions & 0 deletions ZZZO/ZZZO.Common/ZZZO.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="Resources\build-commit.txt" />
<None Include="Resources\build-date.txt" />
<Content Include="Resources\style.css" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>powershell -Comman "Get-Date -Format "o"" &gt; "$(ProjectDir)\Resources\build-date.txt"
git describe &gt; "$(ProjectDir)\Resources\build-commit.txt"</PreBuildEvent>
</PropertyGroup>
</Project>
14 changes: 8 additions & 6 deletions ZZZO/ZZZO/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public App()
{
Current = this;

CultureInfo.CurrentCulture = new CultureInfo("cs-CZ");
CultureInfo.CurrentUICulture = new CultureInfo("cs-CZ");
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("cs-CZ");
Thread.CurrentThread.CurrentCulture = new CultureInfo("cs-CZ");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("cs-CZ");
var ci = new CultureInfo("cs-CZ");

CultureInfo.CurrentCulture = ci;
CultureInfo.CurrentUICulture = ci;
CultureInfo.DefaultThreadCurrentCulture = ci;
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}

#endregion
Expand All @@ -48,7 +50,7 @@ public void SetDataContexts(MainWindow window)
window.DataContext = new MainWindowViewModel(window, Current, Core);
window.UcBasicInfo.DataContext = new BasicInfoViewModel(Core);
window.UcProgram.DataContext = new ProgramViewModel(Core);
window.UcGenerator.DataContext = new GeneratorViewModel(window.UcGenerator, Core);
window.UcGenerator.DataContext = new GeneratorViewModel(Core);
}

protected override void OnExit(ExitEventArgs e)
Expand Down
46 changes: 46 additions & 0 deletions ZZZO/ZZZO/Assists/ChromiumWebBrowserAssist.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Windows;
using CefSharp;
using CefSharp.Wpf;
using ZZZO.Common;

namespace ZZZO.Assists
{
public class ChromiumWebBrowserAssist : DependencyObject
{
#region Statické prvky

public static readonly DependencyProperty HtmlProperty =
DependencyProperty.RegisterAttached(
"Html",
typeof(string),
typeof(ChromiumWebBrowserAssist),
new PropertyMetadata
{
PropertyChangedCallback = OnHtmlChanged
});

#endregion

#region Metody

public static string GetHtml(DependencyObject obj)
{
return (string)obj.GetValue(HtmlProperty);
}

public static void SetHtml(DependencyObject obj, string value)
{
obj.SetValue(HtmlProperty, value);
}

private static void OnHtmlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.Property.Name == HtmlProperty.Name && d is ChromiumWebBrowser browser)
{
browser.LoadHtml(e.NewValue as string, Constants.Uris.Document);
}
}

#endregion
}
}
80 changes: 80 additions & 0 deletions ZZZO/ZZZO/Commands/RelayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,86 @@

namespace ZZZO.Commands
{
public class RelayCommand<T> : ICommand
{
#region Proměnné

private readonly Func<T, bool> canExecute;
private readonly Action<T> execute;

#endregion

#region Konstruktory

public RelayCommand(Action<T> execute, Func<T, bool> canExecute = null)
{
this.execute = execute;
this.canExecute = canExecute;
}

#endregion

#region Implementace rozhraní

public bool CanExecute(object parameter)
{
return canExecute == null || canExecute((T)parameter);
}

public event EventHandler CanExecuteChanged
{
add => CommandManager.RequerySuggested += value;
remove => CommandManager.RequerySuggested -= value;
}

public void Execute(object parameter)
{
execute((T)parameter);
}

#endregion
}

public class RelayCommandEmpty : ICommand
{
#region Proměnné

private readonly Func<bool> canExecute;
private readonly Action execute;

#endregion

#region Konstruktory

public RelayCommandEmpty(Action execute, Func<bool> canExecute = null)
{
this.execute = execute;
this.canExecute = canExecute;
}

#endregion

#region Implementace rozhraní

public bool CanExecute(object parameter)
{
return canExecute == null || canExecute();
}

public event EventHandler CanExecuteChanged
{
add => CommandManager.RequerySuggested += value;
remove => CommandManager.RequerySuggested -= value;
}

public void Execute(object parameter)
{
execute();
}

#endregion
}

public class RelayCommand : ICommand
{
#region Proměnné
Expand Down
14 changes: 13 additions & 1 deletion ZZZO/ZZZO/Controls/BasicInfo.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,19 @@
Source="{Binding Core.Zasedani.LogoObce, UpdateSourceTrigger=PropertyChanged}" />
</Border>
<Button VerticalAlignment="Center"
Command="{Binding UpdateVillageLogoCmd}">Nastavit znak obce</Button>
Command="{Binding UpdateVillageLogoCmd}">
<WrapPanel>
<materialDesign:PackIcon VerticalAlignment="Center" Kind="Badge" />
<TextBlock Margin="5,0,0,0">Vybrat znak obce</TextBlock>
</WrapPanel>
</Button>
<Button VerticalAlignment="Center"
Command="{Binding RemoveVillageLogoCmd}">
<WrapPanel>
<materialDesign:PackIcon VerticalAlignment="Center" Kind="Delete" />
<TextBlock Margin="5,0,0,0">Smazat znak obce</TextBlock>
</WrapPanel>
</Button>
</WrapPanel>

<WrapPanel Margin="0">
Expand Down
18 changes: 10 additions & 8 deletions ZZZO/ZZZO/Controls/Generator.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:converters="clr-namespace:ZZZO.Converters"
xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
xmlns:viewmodels="clr-namespace:ZZZO.ViewModels"
xmlns:assists="clr-namespace:ZZZO.Assists"
d:DataContext="{d:DesignInstance Type=viewmodels:GeneratorViewModel}"
mc:Ignorable="d"
d:DesignHeight="450"
Expand All @@ -22,19 +23,18 @@
Command="{Binding GenerateDocumentCmd}" />
<Button Style="{StaticResource MaterialDesignRaisedSecondaryLightButton}"
Margin="{StaticResource FormMargin}"
IsEnabled="{Binding GeneratedData, Converter={StaticResource NotNullConverter}}"
Content="Exportovat do HTML"
Click="ExportHtml" />
Command="{Binding ExportHtmlCmd}"
Content="Exportovat do HTML" />
<Button Style="{StaticResource MaterialDesignRaisedSecondaryLightButton}"
Margin="{StaticResource FormMargin}"
IsEnabled="{Binding GeneratedData, Converter={StaticResource NotNullConverter}}"
Content="Exportovat do PDF"
Click="ExportPdf" />
Command="{Binding ExportPdfCmd}"
CommandParameter="{Binding ElementName=WebBrowser}" />
<Button Style="{StaticResource MaterialDesignRaisedSecondaryLightButton}"
Margin="{StaticResource FormMargin}"
IsEnabled="{Binding GeneratedData, Converter={StaticResource NotNullConverter}}"
Content="Tisknout"
Click="PrintOnPrinter" />
Command="{Binding PrintCmd}"
CommandParameter="{Binding ElementName=WebBrowser}" />
<ProgressBar Style="{StaticResource MaterialDesignCircularProgressBar}"
Name="PbGenerator"
Width="40"
Expand All @@ -43,7 +43,9 @@
Maximum="100"
Value="{Binding GenerateProgress}" />
</WrapPanel>
<wpf:ChromiumWebBrowser Name="WebBrowser" />
<wpf:ChromiumWebBrowser
assists:ChromiumWebBrowserAssist.Html="{Binding GeneratedHtml, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
Name="WebBrowser" />
</DockPanel>
</GroupBox>
</UserControl>
Loading

0 comments on commit 016dd4f

Please sign in to comment.