Skip to content

Commit

Permalink
🚧 ResourceDictionaryによる管理の基盤部分ほぼ完成
Browse files Browse the repository at this point in the history
  • Loading branch information
Hibi-10000 committed Dec 29, 2024
1 parent 61f51bf commit 4d72430
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Hash.Wpf/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Strings/ParentResource.xaml"/>

<!-- Contains all of the colours and brushes for a theme -->
<ResourceDictionary Source="Themes/ColourDictionaries/SoftDark.xaml"/>
<!-- Contains most of the control-specific brushes which reference -->
Expand Down
2 changes: 1 addition & 1 deletion src/Hash.Wpf/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</MenuItem>
</Menu>
<Grid Grid.Row="1" Margin="5">
<Label x:Name="hashAndVer" Content="HashCalculator" FontSize="35" BorderThickness="1" Padding="10,0" HorizontalAlignment="Left" FontWeight="Bold"
<Label x:Name="hashAndVer" Content="{StaticResource Title}" FontSize="35" BorderThickness="1" Padding="10,0" HorizontalAlignment="Left" FontWeight="Bold"
Foreground="Lime" BorderBrush="{DynamicResource ABrush.Foreground.Deeper}" Background="{DynamicResource ABrush.Tone2.Background.Static}"/>
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Top">
<TextBlock Text="CreatedBy : Hibi_10000"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Hash.Wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
}

Title = $"HashCalculator {App.SemVer}";
hashAndVer.Content = $"HashCalculator {App.SemVer}";
//hashAndVer.Content = $"HashCalculator {App.SemVer}";
HashVer.Content = $"HashCalculator {App.SemVer}";
CopyRight.Text = $"Copyright © 2021-{DateTime.Now.Year} Hibi_10000";
foreach (string hashTypeName in HashCalculate.GetHashTypeNames())
Expand Down
30 changes: 30 additions & 0 deletions src/Hash.Wpf/Strings/ParentResource.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
Copyright © 2021-2024 Hibi_10000
This file is part of HashCalculator program.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:str="clr-namespace:Hash.Wpf.Strings">
<sys:String x:Key="AppName">HashCalculator</sys:String>
<str:String x:Key="Version" Text="v0.7.0"/>
<str:Strings x:Key="Title" Format="{}{0} {1}">
<str:StringResource ResourceKey="AppName"/>
<str:StringResource ResourceKey="Version"/>
</str:Strings>
</ResourceDictionary>
41 changes: 41 additions & 0 deletions src/Hash.Wpf/Strings/StringExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright © 2021-2024 Hibi_10000
//
// This file is part of HashCalculator program.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.ComponentModel;
using System.Windows.Markup;

namespace Hash.Wpf.Strings;

[ContentProperty("Text")]
[MarkupExtensionReturnType(typeof(string))]
public class StringExtension : MarkupExtension
{
private string _string = string.Empty;

[ConstructorArgument("text")]
public string Text
{
get => _string;
set => _string = value;
}

public override object ProvideValue(IServiceProvider serviceProvider)
{
return _string;
}
}
39 changes: 39 additions & 0 deletions src/Hash.Wpf/Strings/StringResourceExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright © 2021-2024 Hibi_10000
//
// This file is part of HashCalculator program.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Windows;
using System.Windows.Markup;

namespace Hash.Wpf.Strings;

[MarkupExtensionReturnType(typeof(object))]
public class StringResourceExtension : StaticResourceExtension
{
//public StringResourceExtension() {}
//public StringResourceExtension(object resourceKey) : base(resourceKey) {}

//public override object? ProvideValue(IServiceProvider serviceProvider)
//{
// object? value = base.ProvideValue(serviceProvider);
// if (value is MarkupExtension me)
// {
// return me.ProvideValue(serviceProvider);
// }
// return value;
//}
}
56 changes: 56 additions & 0 deletions src/Hash.Wpf/Strings/StringsExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright © 2021-2024 Hibi_10000
//
// This file is part of HashCalculator program.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Windows.Markup;

namespace Hash.Wpf.Strings;

[ContentProperty("Strings")]
[MarkupExtensionReturnType(typeof(string))]
public class StringsExtension : MarkupExtension
{
private List<string> _strings = [];
private string? _formatString;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<string> Strings
{
get => _strings;
set => _strings = value;
}

[StringSyntax("CompositeFormat")]
public string? Format
{
get => _formatString;
set => _formatString = value;
}

public override object? ProvideValue(IServiceProvider serviceProvider)
{
if (_formatString is not null)
{
return string.Format(_formatString, _strings.ToArray<object>());
}
return string.Concat(_strings);
}
}

0 comments on commit 4d72430

Please sign in to comment.