Skip to content

Commit

Permalink
0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Maple512 committed Oct 22, 2024
1 parent 60d6160 commit e8ac084
Show file tree
Hide file tree
Showing 24 changed files with 238 additions and 60 deletions.
29 changes: 0 additions & 29 deletions OneProject.Desktop.Theme/OneProject.Desktop.Theme.csproj

This file was deleted.

10 changes: 4 additions & 6 deletions OneProject.Desktop/App.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<Application x:Class="OneProject.Desktop.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:OneProject.Desktop"
StartupUri="MainWindow.xaml">
<Application x:Class="OneProject.Desktop.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml">

<Application.Resources>

</Application.Resources>

</Application>
2 changes: 1 addition & 1 deletion OneProject.Desktop/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OneProject.Desktop;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OneProject.Infrastructures;
using OneProject.Desktop.Infrastructures;
using Serilog;
using Serilog.Core;
using Serilog.Events;
Expand Down
19 changes: 19 additions & 0 deletions OneProject.Desktop/Converters/DoubleGridLengthConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace OneProject.Desktop.Converters;

using System;
using System.Globalization;

public class DoubleGridLengthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(value is double d)
{
return new GridLength(d);
}

return Binding.DoNothing;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}
16 changes: 16 additions & 0 deletions OneProject.Desktop/Converters/FileSizeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace OneProject.Desktop.Converters;

using Humanizer;

public class FileSizeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value switch
{
long l => l.Bytes().ToString(),
double d => d.Bytes().ToString(),
_ => Binding.DoNothing,
};

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
2 changes: 1 addition & 1 deletion OneProject.Desktop/GlobalSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OneProject;
namespace OneProject.Desktop;

using System;
using System.IO;
Expand Down
13 changes: 13 additions & 0 deletions OneProject.Desktop/Infrastructures/FontHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace OneProject.Desktop.Infrastructures;

using System;
using System.Collections.Generic;
using System.Linq;

public static class FontHelper
{
private static readonly Lazy<IEnumerable<FontFamily>> _fonts = new(
static () => Fonts.SystemFontFamilies.OrderBy(x => x.Source));

public static IEnumerable<FontFamily> SystemFonts => _fonts.Value;
}
3 changes: 2 additions & 1 deletion OneProject.Desktop/Infrastructures/VersionChecker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OneProject.Infrastructures;
namespace OneProject.Desktop.Infrastructures;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
Expand All @@ -9,6 +9,7 @@ namespace OneProject.Infrastructures;

public class VersionChecker
{
// api docs: https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#get-the-latest-release
private const string uri = "https://api.github.com/repos/maple512/oneproject/releases/latest";
private readonly IHttpClientFactory _httpClientFactory;
private readonly ILogger _logger;
Expand Down
20 changes: 10 additions & 10 deletions OneProject.Desktop/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Window x:Class="OneProject.Desktop.MainWindow"
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:local="clr-namespace:OneProject.Desktop"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>

<Window x:Class="OneProject.Desktop.MainWindow" 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:local="clr-namespace:OneProject.Desktop"
mc:Ignorable="d" Title="MainWindow" MinHeight="700" MinWidth="1000"
xmlns:models="clr-namespace:OneProject.Desktop.ViewModels" TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular" TextElement.FontSize="13" TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto" Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}" d:DataContext="{d:DesignInstance models:MainWindowModel}">
<Grid >
</Grid>
</Window>
40 changes: 40 additions & 0 deletions OneProject.Desktop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace OneProject.Desktop;

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using OneProject.Desktop.Infrastructures;
using OneProject.Desktop.Pages;
using OneProject.Desktop.ViewModels;

public partial class MainWindow : Window
{
Expand All @@ -10,6 +15,41 @@ public MainWindow()
InitializeComponent();
}

protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);

Title = nameof(OneProject);

WindowState = GlobalSettings.Instance.Windows.MainWindowState;
Height = GlobalSettings.Instance.Windows.MainWindowHeight;
Width = GlobalSettings.Instance.Windows.MainWindowWidth;
Top = GlobalSettings.Instance.Windows.MainWindowTop;
Left = GlobalSettings.Instance.Windows.MainWindowLeft;

var source = GlobalSettings.Instance.Windows.FontFamily;
if(source != null || FontFamily.Source != source)
{
var font = FontHelper.SystemFonts.FirstOrDefault(x => x.Source == source);

if(font != null)
{
FontFamily = font;
}
}

ObservableCollection<MenuItemModel> menus =
[
MenuItemModel.Create<Home>("首页"),
MenuItemModel.Create<WindowsReg>("注册表"),
];

DataContext = new MainWindowModel("OneProject", GlobalSettings.Version, menus);
}

//private void OnSelectedItemChanged(object sender, DependencyPropertyChangedEventArgs e)
// => MainScrollViewer.ScrollToHome();

protected override void OnClosing(CancelEventArgs e)
{
GlobalSettings.Instance.Windows.MainWindowState = WindowState;
Expand Down
4 changes: 2 additions & 2 deletions OneProject.Desktop/OneProject.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageIcon>logo_128.ico</PackageIcon>
<ApplicationIcon>assets\logo_128.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
Expand All @@ -33,6 +32,8 @@

<ItemGroup>
<PackageReference Include="CliWrap" />
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="Humanizer.Core" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" />
<PackageReference Include="Serilog.Extensions.Logging" />
Expand All @@ -41,7 +42,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OneProject.Desktop.Theme\OneProject.Desktop.Theme.csproj" />
<ProjectReference Include="..\OneProject\OneProject.csproj" />
</ItemGroup>

Expand Down
9 changes: 9 additions & 0 deletions OneProject.Desktop/Pages/Home.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<UserControl x:Class="OneProject.Desktop.Pages.Home" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:OneProject.Desktop.Pages" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" >

<Grid>
<TextBlock Text="首页" />
</Grid>
</UserControl>
21 changes: 21 additions & 0 deletions OneProject.Desktop/Pages/Home.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace OneProject.Desktop.Pages;

using System;

public partial class Home : UserControl
{
public Home()
{
InitializeComponent();
}

public override void BeginInit()
{
base.BeginInit();
}

protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
}
}
10 changes: 10 additions & 0 deletions OneProject.Desktop/Pages/WindowsReg.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<UserControl x:Class="OneProject.Desktop.Pages.WindowsReg" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:OneProject.Desktop.Pages" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">

<Grid>

<TextBlock Text="注册表" />
</Grid>
</UserControl>
11 changes: 11 additions & 0 deletions OneProject.Desktop/Pages/WindowsReg.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace OneProject.Desktop.Pages;

using System.Windows.Controls;

public partial class WindowsReg : UserControl
{
public WindowsReg()
{
InitializeComponent();
}
}
File renamed without changes.
7 changes: 7 additions & 0 deletions OneProject.Desktop/Theme/Generic.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/OneProject.Desktop;component/Theme/ThemeBase.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
<system:Double x:Key="Number.Pressed.Opacity" po:Freeze="true">.9</system:Double>
<system:Double x:Key="Number.IconSize" po:Freeze="true">15</system:Double>
<system:Double x:Key="Number.MenuWidth" po:Freeze="true">130</system:Double>

<GridLength x:Key="GridLength.MenuWidth" po:Freeze="true">130</GridLength>

</ResourceDictionary>
31 changes: 31 additions & 0 deletions OneProject.Desktop/ViewModels/MainWindowModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace OneProject.Desktop.ViewModels;

using System.Collections.ObjectModel;

public partial class MainWindowModel : ObservableObject
{
[ObservableProperty]
private int selectedIndex;

[ObservableProperty]
private MenuItemModel selectedItem;

public MainWindowModel(
string title,
string version,
ObservableCollection<MenuItemModel> pages,
int selectedIndex = 0)
{
Title = title;
Version = version;
Menus = pages;
SelectedItem = pages[selectedIndex];
SelectedIndex = selectedIndex;
}

public string Title { get; }

public string Version { get; }

public ObservableCollection<MenuItemModel> Menus { get; }
}
35 changes: 35 additions & 0 deletions OneProject.Desktop/ViewModels/MenuItemModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace OneProject.Desktop.ViewModels;

public class MenuItemModel
{
private object? _content;
private MenuItemModel(string name, Type contentType, object? data = null)
{
Title = name;
ContentType = contentType;
Data = data;
}
public Type ContentType { get; }

public string Title { get; }

public object? Data { get; }

public object? Content => _content ??= CreateContent();

public static MenuItemModel Create<T>(string name, object? dataContent = null)
=> new(name, typeof(T), dataContent);

private object? CreateContent()
{
var instance = Activator.CreateInstance(ContentType);

if(Data is not null
&& Content is FrameworkElement element)
{
element.DataContext = Data;
}

return instance;
}
}
7 changes: 0 additions & 7 deletions OneProject.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneProject.Desktop.Theme", "OneProject.Desktop.Theme\OneProject.Desktop.Theme.csproj", "{D67749D3-E195-4770-ADA9-D5A95E0708B3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneProject", "OneProject\OneProject.csproj", "{FEAECEE7-7397-44B0-BAA7-5704CF9423AE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneProject.Win32Native", "OneProject.Win32Native\OneProject.Win32Native.csproj", "{EC243AF2-CB2A-4D1C-8513-F93DE87291F4}"
Expand All @@ -45,10 +43,6 @@ Global
{1EC603BC-2A26-4CCC-AF77-68EC5C1C2F67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1EC603BC-2A26-4CCC-AF77-68EC5C1C2F67}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1EC603BC-2A26-4CCC-AF77-68EC5C1C2F67}.Release|Any CPU.Build.0 = Release|Any CPU
{D67749D3-E195-4770-ADA9-D5A95E0708B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D67749D3-E195-4770-ADA9-D5A95E0708B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D67749D3-E195-4770-ADA9-D5A95E0708B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D67749D3-E195-4770-ADA9-D5A95E0708B3}.Release|Any CPU.Build.0 = Release|Any CPU
{FEAECEE7-7397-44B0-BAA7-5704CF9423AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FEAECEE7-7397-44B0-BAA7-5704CF9423AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEAECEE7-7397-44B0-BAA7-5704CF9423AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -67,7 +61,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{1EC603BC-2A26-4CCC-AF77-68EC5C1C2F67} = {8516DC9F-795F-46E0-ADEF-4BBACF0D8FC6}
{D67749D3-E195-4770-ADA9-D5A95E0708B3} = {8516DC9F-795F-46E0-ADEF-4BBACF0D8FC6}
{E566BE25-A753-475B-A4A5-145D9027F8FC} = {21BBDE1A-D1F0-47BF-9C1F-6A0C54FF7DFF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
Loading

0 comments on commit e8ac084

Please sign in to comment.