Skip to content

Commit 90804b1

Browse files
committed
Add Website Creator GUI Application
1 parent 01a89be commit 90804b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+5886
-0
lines changed

WebsiteCreator/App.xaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<Application x:Class="WebsiteCreator.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:WebsiteCreator"
5+
xmlns:view="clr-namespace:WebsiteCreator.MVVM.View"
6+
xmlns:vm="clr-namespace:WebsiteCreator.MVVM.ViewModel"
7+
xmlns:comicView="clr-namespace:WebsiteCreator.MVVM.View.Comic"
8+
xmlns:comicVM="clr-namespace:WebsiteCreator.MVVM.ViewModel.Comic">
9+
<Application.Resources>
10+
<ResourceDictionary>
11+
<ResourceDictionary.MergedDictionaries>
12+
<ResourceDictionary Source="/Style/ModernWindow.xaml" />
13+
<ResourceDictionary Source="/Style/ModernScrollBar.xaml" />
14+
<ResourceDictionary Source="/Style/InfoBorder.xaml" />
15+
<ResourceDictionary Source="/Style/ModernButton.xaml" />
16+
<ResourceDictionary Source="/Style/DarkRadioButton.xaml" />
17+
<ResourceDictionary Source="/Style/ModernTextBox.xaml" />
18+
</ResourceDictionary.MergedDictionaries>
19+
<DataTemplate DataType="{x:Type vm:HomeVM}">
20+
<view:HomeView />
21+
</DataTemplate>
22+
<DataTemplate DataType="{x:Type vm:InfoVM}">
23+
<view:InfoView />
24+
</DataTemplate>
25+
<DataTemplate DataType="{x:Type vm:SearchVM}">
26+
<view:SearchView />
27+
</DataTemplate>
28+
<DataTemplate DataType="{x:Type comicVM:ComicVM}">
29+
<comicView:ComicView />
30+
</DataTemplate>
31+
<DataTemplate DataType="{x:Type comicVM:ComicChapterVM}">
32+
<comicView:ComicChapterView />
33+
</DataTemplate>
34+
<DataTemplate DataType="{x:Type comicVM:ComicHomeVM}">
35+
<comicView:ComicHomeView />
36+
</DataTemplate>
37+
<DataTemplate DataType="{x:Type comicVM:ComicSearchVM}">
38+
<comicView:ComicSearchVM />
39+
</DataTemplate>
40+
<BooleanToVisibilityConverter x:Key="BoolToVis" />
41+
</ResourceDictionary>
42+
</Application.Resources>
43+
</Application>

WebsiteCreator/App.xaml.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using System;
3+
using System.Windows;
4+
using WebsiteCreator.Core;
5+
using WebsiteCreator.MVVM.ViewModel;
6+
using WebsiteCreator.MVVM.ViewModel.Comic;
7+
8+
namespace WebsiteCreator
9+
{
10+
/// <summary>
11+
/// Interaction logic for App.xaml
12+
/// </summary>
13+
public partial class App : Application
14+
{
15+
private readonly ServiceProvider _serviceProvider;
16+
public ServiceProvider ServiceProvider => _serviceProvider;
17+
internal static new App Current => (App)Application.Current;
18+
19+
public App()
20+
{
21+
IServiceCollection services = new ServiceCollection();
22+
services.AddSingleton(provider => new MainWindow { DataContext = provider.GetRequiredService<MainWindowVM>() });
23+
24+
AddViewModels(services);
25+
26+
services.AddSingleton<INavigationService, NavigationService>();
27+
services.AddSingleton<Func<Type, ViewModelObject>>(provider => viewModelType => (ViewModelObject)provider.GetRequiredService(viewModelType));
28+
29+
_serviceProvider = services.BuildServiceProvider();
30+
31+
_serviceProvider.GetRequiredService<INavigationService>().NavigateTo<HomeVM>();
32+
33+
}
34+
35+
private static void AddViewModels(IServiceCollection services)
36+
{
37+
services.AddSingleton<MainWindowVM>();
38+
services.AddSingleton<HomeVM>();
39+
services.AddSingleton<InfoVM>();
40+
services.AddSingleton<SearchVM>();
41+
services.AddSingleton<ComicVM>();
42+
services.AddSingleton<ComicChapterVM>();
43+
services.AddSingleton<ComicHomeVM>();
44+
services.AddSingleton<ComicSearchVM>();
45+
}
46+
47+
protected override void OnStartup(StartupEventArgs e)
48+
{
49+
base.OnStartup(e);
50+
_serviceProvider.GetRequiredService<MainWindow>().Show();
51+
}
52+
}
53+
}

WebsiteCreator/AssemblyInfo.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Windows;
2+
3+
namespace WebsiteCreator.Core
4+
{
5+
public class BindingProxy : Freezable
6+
{
7+
protected override Freezable CreateInstanceCore()
8+
{
9+
return new BindingProxy();
10+
}
11+
12+
public object Data
13+
{
14+
get { return GetValue(DataProperty); }
15+
set { SetValue(DataProperty, value); }
16+
}
17+
18+
public static readonly DependencyProperty DataProperty =
19+
DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null));
20+
}
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.ObjectModel;
3+
using System.Globalization;
4+
using System.Windows.Data;
5+
using WebsiteCreator.MVVM.ViewModel;
6+
7+
namespace WebsiteCreator.Core.Converter
8+
{
9+
public class GetIndexMultiConverter : IMultiValueConverter
10+
{
11+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
if (values[0] != null && values[1] is ObservableCollection<TagInfo> collection)
14+
{
15+
int itemIndex = collection.IndexOf((TagInfo)values[0]);
16+
return itemIndex.ToString();
17+
}
18+
else if (values[0] != null && values[1] is ObservableCollection<RadioTagInfo> collection1)
19+
{
20+
int itemIndex = collection1.IndexOf((RadioTagInfo)values[0]);
21+
return itemIndex.ToString();
22+
}
23+
return "0";
24+
}
25+
26+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
27+
{
28+
throw new NotImplementedException("GetIndexMultiConverter_ConvertBack");
29+
}
30+
}
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Linq;
4+
using System.Windows.Data;
5+
6+
namespace WebsiteCreator.Core.Converter
7+
{
8+
/// <summary>
9+
/// Compare two Values with each other and returns if equals
10+
/// </summary>
11+
public class MultiValueEqualityConverter : IMultiValueConverter
12+
{
13+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
14+
{
15+
return values?.All(o => o?.Equals(values[0]) == true) == true || values?.All(o => o == null) == true;
16+
}
17+
18+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
19+
{
20+
throw new NotImplementedException();
21+
}
22+
}
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
5+
namespace WebsiteCreator.Core.Converter
6+
{
7+
/// <summary>
8+
/// Compare two Values with each other and returns if equals
9+
/// </summary>
10+
public class WindowConverter : IMultiValueConverter
11+
{
12+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
13+
{
14+
if (values[1] is System.Windows.Window wnd)
15+
return wnd.Height == wnd.RestoreBounds.Height && wnd.Width == wnd.RestoreBounds.Width;
16+
return false;
17+
}
18+
19+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
20+
{
21+
throw new NotImplementedException();
22+
}
23+
}
24+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System.Windows;
2+
using System.Windows.Data;
3+
using System.Windows.Input;
4+
5+
namespace WebsiteCreator.Core
6+
{
7+
public static class InputBindingsManager
8+
{
9+
10+
public static readonly DependencyProperty UpdatePropertySourceWhenEnterPressedProperty = DependencyProperty.RegisterAttached(
11+
"UpdatePropertySourceWhenEnterPressed", typeof(DependencyProperty), typeof(InputBindingsManager), new PropertyMetadata(null, OnUpdatePropertySourceWhenEnterPressedPropertyChanged));
12+
13+
static InputBindingsManager()
14+
{
15+
16+
}
17+
18+
public static void SetUpdatePropertySourceWhenEnterPressed(DependencyObject dp, DependencyProperty value)
19+
{
20+
dp.SetValue(UpdatePropertySourceWhenEnterPressedProperty, value);
21+
}
22+
23+
public static DependencyProperty GetUpdatePropertySourceWhenEnterPressed(DependencyObject dp)
24+
{
25+
return (DependencyProperty)dp.GetValue(UpdatePropertySourceWhenEnterPressedProperty);
26+
}
27+
28+
private static void OnUpdatePropertySourceWhenEnterPressedPropertyChanged(DependencyObject dp, DependencyPropertyChangedEventArgs e)
29+
{
30+
if (dp is not UIElement element)
31+
{
32+
return;
33+
}
34+
35+
if (e.OldValue != null)
36+
{
37+
element.PreviewKeyDown -= HandlePreviewKeyDown;
38+
}
39+
40+
if (e.NewValue != null)
41+
{
42+
element.PreviewKeyDown += new KeyEventHandler(HandlePreviewKeyDown);
43+
}
44+
}
45+
46+
private static void HandlePreviewKeyDown(object sender, KeyEventArgs e)
47+
{
48+
if (e.Key == Key.Enter)
49+
{
50+
DoUpdateSource(e.Source);
51+
}
52+
}
53+
54+
private static void DoUpdateSource(object source)
55+
{
56+
DependencyProperty property =
57+
GetUpdatePropertySourceWhenEnterPressed((DependencyObject)source);
58+
59+
if (property == null)
60+
{
61+
return;
62+
}
63+
64+
65+
if (source is not UIElement elt)
66+
{
67+
return;
68+
}
69+
70+
BindingExpression binding = BindingOperations.GetBindingExpression(elt, property);
71+
72+
if (binding != null)
73+
{
74+
binding.UpdateSource();
75+
}
76+
}
77+
}
78+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Windows;
2+
3+
namespace Downloader.Core
4+
{
5+
internal class MarkupExtensions
6+
{
7+
public static readonly DependencyProperty IconProperty = DependencyProperty.RegisterAttached("Icon", typeof(string), typeof(MarkupExtensions), new PropertyMetadata(default(string)));
8+
9+
public static void SetIcon(UIElement element, string value) => element.SetValue(IconProperty, value);
10+
public static string GetIcon(UIElement element) => (string)element.GetValue(IconProperty);
11+
12+
}
13+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using System;
3+
using System.ComponentModel;
4+
5+
namespace WebsiteCreator.Core
6+
{
7+
public interface INavigationService : INotifyPropertyChanged
8+
{
9+
ViewModelObject CurrentView { get; }
10+
void NavigateTo<T>() where T : ViewModelObject;
11+
void NavigateTo(Type type);
12+
}
13+
14+
public partial class NavigationService : ObservableObject, INavigationService
15+
{
16+
[ObservableProperty]
17+
private ViewModelObject _currentView = null!;
18+
private readonly Func<Type, ViewModelObject> _viewModelFactory;
19+
20+
21+
public NavigationService(Func<Type, ViewModelObject> viewModelFactory)
22+
{
23+
_viewModelFactory = viewModelFactory;
24+
}
25+
26+
27+
public void NavigateTo<TViewModel>() where TViewModel : ViewModelObject
28+
{
29+
ViewModelObject vm = _viewModelFactory.Invoke(typeof(TViewModel));
30+
CurrentView = vm;
31+
OnPropertyChanged(nameof(INavigationService.CurrentView));
32+
}
33+
34+
public void NavigateTo(Type type)
35+
{
36+
if (!type.IsSubclassOf(typeof(ViewModelObject)))
37+
throw new NotSupportedException(type.FullName);
38+
ViewModelObject vm = _viewModelFactory.Invoke(type);
39+
CurrentView = vm;
40+
41+
OnPropertyChanged(nameof(INavigationService.CurrentView));
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)