Skip to content

Commit

Permalink
Add localization and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dogzz9445 committed Jun 7, 2024
1 parent 05098f3 commit 0c81dfa
Show file tree
Hide file tree
Showing 43 changed files with 2,278 additions and 455 deletions.
24 changes: 23 additions & 1 deletion src/Apps/Corathing.Organizer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

using Corathing.Contracts.Services;
using Corathing.Dashboards.Services;
using Corathing.Dashboards.WPF.Services;
using Corathing.Organizer.Resources;
using Corathing.Organizer.Services;
using Corathing.Organizer.Utils;
using Corathing.Organizer.ViewModels;
Expand Down Expand Up @@ -57,6 +59,9 @@ protected override void OnStartup(StartupEventArgs e)

Services = ConfigureServices(e.Args);

var appStateService = Services.GetService<IAppStateService>();
var appSettings = appStateService.GetAppSettings();

// Set the theme
var theme = System.Configuration.ConfigurationManager.AppSettings["Theme"];
var themeService = Services.GetService<IThemeService>();
Expand Down Expand Up @@ -104,6 +109,19 @@ protected override void OnStartup(StartupEventArgs e)
//widgetService.RegisterWidgets(new List<WidgetGenerator> { new WidgetGenerator() });


IAuthService authService = App.Current.Services.GetService<IAuthService>();
if (authService != null && authService.UseAuthService)
{
//var loginWindow = new BaseWindow();
//loginWindow.Content = new LoginView();
//loginWindow.Owner = Window.GetWindow(this);
//loginWindow.ShowDialog();
//if (loginWindow.DialogResult == false)
//{
// // System.Shutdown
//}
}

// Create a new MainWindow and set its DataContext to a new MainWindowViewModel which binds the view to the viewmodel
new MainWindow().Show();
}
Expand Down Expand Up @@ -136,11 +154,15 @@ private static IServiceProvider ConfigureServices(string[] args)
serviceCollection.AddSingleton<IAppStateService, AppStateService>();
serviceCollection.AddSingleton<IPackageService, PackageService>();
serviceCollection.AddSingleton<IThemeService, ThemeService>();
//serviceCollection.AddSingleton<IWidgetSystemService, WidgetSystemService>();
serviceCollection.AddSingleton<ILocalizationService>(LocalizationService.Instance);

LocalizationService.Instance.RegisterStringResourceManager("Corathing.Organizer",
CorathingOrganizerLocalizationStringResources.ResourceManager);

// Register viewmodels
serviceCollection.AddScoped<OrganizerSettingsViewModel>();
serviceCollection.AddScoped<WidgetSettingsViewModel>();
serviceCollection.AddScoped<ProjectSettingsViewModel>();

//Logger.Configure(configuration);
//serviceCollection.AddSingleton<SettingsController>();
Expand Down
28 changes: 28 additions & 0 deletions src/Apps/Corathing.Organizer/Behaviors/DataTemplateSelector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows;

namespace Corathing.Organizer.Behaviors;

public class TemplateSelector : DataTemplateSelector
{
public DataTemplate ItemTemplate { get; set; }
public DataTemplate NewButtonTemplate { get; set; }

public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item == CollectionView.NewItemPlaceholder)
{
return NewButtonTemplate;
}
else
{
return ItemTemplate;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

using Corathing.Contracts.Services;
using Corathing.Dashboards.WPF.Bindings;

namespace Corathing.Organizer.Converters;

[ValueConversion(typeof(ApplicationLanguage), typeof(CultureInfo))]
public class ApplicationLanguageToCultureInfoConverter : IValueConverter
{
public object? Convert(object value, Type targetType,
object parameter, CultureInfo culture)
=> value is ApplicationLanguage language ? language switch
{
ApplicationLanguage.en_US => 0,
ApplicationLanguage.ko_KR => 1,
_ => 0,
} : 0;

public object? ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
=> value is int index ? index switch
{
0 => ApplicationLanguage.en_US,
1 => ApplicationLanguage.ko_KR,
_ => ApplicationLanguage.en_US,
} : ApplicationLanguage.en_US;

//public object? Convert(object value, Type targetType,
// object parameter, CultureInfo culture)
//{
// if (value == null)
// return null;
// if (value is not AvailableCulture)
// return null;
// return Convert((AvailableCulture)value);
//}

//public object? ConvertBack(object value, Type targetType,
// object parameter, CultureInfo culture)
//{
// if (value == null)
// return null;
// if (value is not CultureInfo)
// return null;
// return ConvertBack((CultureInfo)value);
//}

//public static CultureInfo Convert(AvailableCulture culture)
//{
// return CultureInfo.GetCultureInfo(
// StringToAvailableCultureConverter.
// ConvertBack(culture));
//}

//public static AvailableCulture ConvertBack(CultureInfo culture)
//{
// return StringToAvailableCultureConverter.Convert(culture.Name);
//}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Globalization;
using System.Windows.Data;

using Corathing.Contracts.Services;

namespace Corathing.Organizer.Converters;

[ValueConversion(typeof(ApplicationLanguage), typeof(int))]
public class ApplicationLanguageToIndexConverter : IValueConverter
{
public object? Convert(object value, Type targetType,
object parameter, CultureInfo culture)
=> value is ApplicationLanguage language ? language switch
{
ApplicationLanguage.en_US => 0,
ApplicationLanguage.ko_KR => 1,
_ => 0,
} : 0;

public object? ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
=> value is int index ? index switch
{
0 => ApplicationLanguage.en_US,
1 => ApplicationLanguage.ko_KR,
_ => ApplicationLanguage.en_US,
} : ApplicationLanguage.en_US;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

using Corathing.Contracts.Services;

namespace Corathing.Organizer.Converters;

public class UILanguageToIndexConverter : IValueConverter
{
public object? Convert(object value, Type targetType,
object parameter, CultureInfo culture)
=> value is string languageName ? languageName switch
{
"English" => 0,
"한국어" => 1,
_ => 0,
} : 0;

public object? ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
=> value is int index ? index switch
{
0 => "English",
1 => "한국어",
_ => "English",
} : "English";
}
21 changes: 21 additions & 0 deletions src/Apps/Corathing.Organizer/Corathing.Organizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,25 @@
<Resource Include="Assets\logo_256.png" />
</ItemGroup>

<ItemGroup>
<Compile Update="Resources\CorathingOrganizerLocalizationStringResources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>CorathingOrganizerLocalizationStringResources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources\CorathingOrganizerLocalizationStringResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>CorathingOrganizerLocalizationStringResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
11 changes: 10 additions & 1 deletion src/Apps/Corathing.Organizer/Extensions/WindowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static void MinimizeWindow(this MetroWindow window)
window.WindowState = WindowState.Minimized;
}

public static void CenterWindowToParent(this MetroWindow window)
public static void CenterWindowToParent(this Window window)
{
if (window.Owner == null)
return;
Expand All @@ -165,6 +165,15 @@ public static void CenterWindowToParent(this MetroWindow window)
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;

if (window.IsLoaded)
{
window.WindowState = WindowState.Normal;

if (window.Owner != null)
{
Window parent = window.Owner;
window.Left = parent.Left + (parent.ActualWidth - window.ActualWidth) / 2;
window.Top = parent.Top + (parent.ActualHeight - window.ActualHeight) / 2;
}
}
}
}
1 change: 1 addition & 0 deletions src/Apps/Corathing.Organizer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ShowMaxRestoreButton="False"
ShowCloseButton="False"
IsWindowDraggable="True"
WindowStartupLocation="CenterScreen"
Height="1000"
Width="1600">

Expand Down
51 changes: 48 additions & 3 deletions src/Apps/Corathing.Organizer/Models/ProjectContext.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace Corathing.Organizer.Models;

Expand All @@ -19,16 +22,58 @@ public partial class ProjectContext : ObservableObject
[ObservableProperty]
private string _title;

[DefaultValue(false)]
[ObservableProperty]
private bool? _editMode;

/// <summary>
/// Gets or sets the workflows.
/// Gets or sets the dashboards.
/// </summary>
/// <value>The widgets.</value>
/// <value>The dashboards.</value>
private ObservableCollection<WorkflowContext>? _workflows;
public ObservableCollection<WorkflowContext> Workflows
{
get => _workflows;
set
{
if (EqualityComparer<ObservableCollection<WorkflowContext>?>.Default.Equals(_workflows, value))
return;
OnPropertyChanging(nameof(Workflows));
_workflows = value;
var itemsView = (IEditableCollectionView)CollectionViewSource.GetDefaultView(_workflows);
itemsView.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd;
OnPropertyChanged(nameof(Workflows));
}
}

[ObservableProperty]
private ObservableCollection<WorkflowContext> _workflows;
private WorkflowContext _selectedWorkflow;

[RelayCommand]
public void AddWorkflow()
{
var newWorkflow = new WorkflowContext();
Workflows.Add(newWorkflow);
SelectedWorkflow = newWorkflow;
}

#endregion

public ProjectContext()
{
Workflows = new ObservableCollection<WorkflowContext>();
}

protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);

if (Workflows != null)
{
foreach (var workflow in Workflows)
{
workflow.EditMode = EditMode;
}
}
}
}
Loading

0 comments on commit 0c81dfa

Please sign in to comment.