From 56af28d63c7f277a24f7c045ef69582789649ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dongmin=20Jang=20=28=EC=9E=A5=EB=8F=99=EB=AF=BC=29?= Date: Mon, 15 Jul 2024 11:22:24 +0900 Subject: [PATCH] Update websession --- README.md | 6 +- .../app.manifest | 18 ++++ src/Apps/Corathing.Organizer.WPF/App.xaml.cs | 1 + .../ViewModels/DataSourceSettingsViewModel.cs | 26 +---- .../ViewModels/WidgetManagementViewModel.cs | 14 +++ .../ViewModels/WidgetSettingsViewModel.cs | 1 + .../Services/DataSourceService.cs | 100 +++++++++++++++--- .../Services/PackageService.cs | 26 +++-- .../DataContexts/DataSourceSelector.cs | 31 ++++-- .../DataContexts/WidgetContext.cs | 11 +- .../Services/IDataSourceService.cs | 11 +- .../Services/IPackageService.cs | 12 +-- .../WebSessionDataSourceDataTemplates.xaml | 3 +- .../WebSessionDataSourceSelector.cs | 10 +- .../FileOpenTypeToVisibleConverter.cs | 61 +++++++++++ .../FileOpeners/FileOpenerDataTemplates.xaml | 70 +++++++++++- .../FileOpeners/FileOpenerWidgetContext.cs | 13 +++ .../Widgets/ToDoLists/ToDoListWidget.xaml | 2 + .../WebPages/WebPageOptionViewModel.cs | 6 +- .../Widgets/WebPages/WebPageWidgetContext.cs | 65 ++++++------ 20 files changed, 383 insertions(+), 104 deletions(-) create mode 100644 src/Apps/Corathing.Organizer.AvaloniaUI.Desktop/app.manifest create mode 100644 src/Apps/Corathing.Organizer.WPF/ViewModels/WidgetManagementViewModel.cs create mode 100644 src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenTypeToVisibleConverter.cs diff --git a/README.md b/README.md index 1c686a6..8b685eb 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ Corathing is Customizable Widget Organizer. It is a WPF application that allows you to organize anything with customizable widget dashboards. You can create your own widgets or use the default widgets provided by Corathing. -| Wiki |Readme | Readme | -| --- | --- | --- | -| [Wiki](https://github.com/dogzz9445/Corathing/wiki/Home) | [English](README.md) | [한국어](README_KR.md) | +| Homepage | Wiki |Readme | Readme | +| --- | --- | --- | --- | +| [Homepage](https://corathing.com) | [Wiki](https://github.com/dogzz9445/Corathing/wiki/Home) | [English](README.md) | [한국어](README_KR.md) | ![sample](docs/images/version0.0.9.gif) diff --git a/src/Apps/Corathing.Organizer.AvaloniaUI.Desktop/app.manifest b/src/Apps/Corathing.Organizer.AvaloniaUI.Desktop/app.manifest new file mode 100644 index 0000000..e0ce8d0 --- /dev/null +++ b/src/Apps/Corathing.Organizer.AvaloniaUI.Desktop/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/src/Apps/Corathing.Organizer.WPF/App.xaml.cs b/src/Apps/Corathing.Organizer.WPF/App.xaml.cs index a01e877..32be9d8 100644 --- a/src/Apps/Corathing.Organizer.WPF/App.xaml.cs +++ b/src/Apps/Corathing.Organizer.WPF/App.xaml.cs @@ -210,6 +210,7 @@ private static IServiceProvider ConfigureServices(string[] args) serviceCollection.AddScoped(); serviceCollection.AddScoped(); serviceCollection.AddScoped(); + serviceCollection.AddScoped(); serviceCollection.AddTransient(); serviceCollection.AddTransient(); serviceCollection.AddTransient(); diff --git a/src/Apps/Corathing.Organizer.WPF/ViewModels/DataSourceSettingsViewModel.cs b/src/Apps/Corathing.Organizer.WPF/ViewModels/DataSourceSettingsViewModel.cs index 04c0709..3d8ffc9 100644 --- a/src/Apps/Corathing.Organizer.WPF/ViewModels/DataSourceSettingsViewModel.cs +++ b/src/Apps/Corathing.Organizer.WPF/ViewModels/DataSourceSettingsViewModel.cs @@ -90,19 +90,8 @@ public void AddDataSource() if (_dataSourceType == null) return; - var packageService = _services.GetRequiredService(); - var dataContext = packageService.CreateDataSourceContext(_dataSourceType.FullName); - - var appStateService = _services.GetRequiredService(); - appStateService.UpdateDataSource(dataContext.State); - var dataSourceService = _services.GetRequiredService(); - dataSourceService.AddDataSourceContext(dataContext); - - WeakReferenceMessenger.Default.Send( - new DataSourceStateChangedMessage(EntityStateChangedType.Added, dataContext), - dataContext.GetType().FullName - ); + var dataContext = dataSourceService.CreateDataSourceContext(_dataSourceType); DataSourceContexts.Add(dataContext); Select(dataContext); @@ -111,19 +100,8 @@ public void AddDataSource() [RelayCommand] public void RemoveDataSource(DataSourceContext context) { - // TODO: - // 모든 위젯에서 해당 연결 끊기 - //WeakReferenceMessenger.Default.Send(new DataSourceRemovedMessage(context.State.Id)); - - var appStateService = _services.GetRequiredService(); var dataSourceService = _services.GetRequiredService(); - appStateService.RemovePackage(context.State.Id); - dataSourceService.RemoveDataSourceContext(context); - - WeakReferenceMessenger.Default.Send( - new DataSourceStateChangedMessage(EntityStateChangedType.Removed, context), - context.GetType().FullName - ); + dataSourceService.DestroyDataSourceContext(context); } public void OnSelectedContext(DataSourceContext? selectedContext) diff --git a/src/Apps/Corathing.Organizer.WPF/ViewModels/WidgetManagementViewModel.cs b/src/Apps/Corathing.Organizer.WPF/ViewModels/WidgetManagementViewModel.cs new file mode 100644 index 0000000..40ae8d0 --- /dev/null +++ b/src/Apps/Corathing.Organizer.WPF/ViewModels/WidgetManagementViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using CommunityToolkit.Mvvm.ComponentModel; + +namespace Corathing.Organizer.WPF.ViewModels; + +public class WidgetManagementViewModel : ObservableRecipient +{ +} diff --git a/src/Apps/Corathing.Organizer.WPF/ViewModels/WidgetSettingsViewModel.cs b/src/Apps/Corathing.Organizer.WPF/ViewModels/WidgetSettingsViewModel.cs index 8885b80..6c7cfe9 100644 --- a/src/Apps/Corathing.Organizer.WPF/ViewModels/WidgetSettingsViewModel.cs +++ b/src/Apps/Corathing.Organizer.WPF/ViewModels/WidgetSettingsViewModel.cs @@ -65,6 +65,7 @@ public void Initialize(WidgetContext originalContext, WidgetHost settingsWidgetH var packageService = _services.GetService(); TempWidgetContext = packageService.CreateWidgetContext(_originalContext.GetType().FullName); + TempWidgetContext.IsTemporal = true; _optionType = packageService.GetWidgetCustomSettingsType(_originalContext.GetType().FullName); _originalContext.CopyTo(TempWidgetContext, _optionType); _settingsWidgetHost.Content = TempWidgetContext; diff --git a/src/Apps/Corathing.Organizer/Services/DataSourceService.cs b/src/Apps/Corathing.Organizer/Services/DataSourceService.cs index ab38264..4db7f55 100644 --- a/src/Apps/Corathing.Organizer/Services/DataSourceService.cs +++ b/src/Apps/Corathing.Organizer/Services/DataSourceService.cs @@ -4,9 +4,14 @@ using System.Text; using System.Threading.Tasks; +using CommunityToolkit.Mvvm.Messaging; + using Corathing.Contracts.DataContexts; +using Corathing.Contracts.Messages; using Corathing.Contracts.Services; +using Microsoft.Extensions.DependencyInjection; + using NuGet.Packaging; namespace Corathing.Organizer.Services; @@ -15,6 +20,88 @@ public class DataSourceService(IServiceProvider services) : IDataSourceService { public Dictionary DataSourceContexts { get; } = new(); + public T? GetOrFirstOrCreateDataSourceContext(Guid? guid) where T : DataSourceContext + { + var dataContext = GetDataSourceContext(guid); + if (dataContext != null) + return dataContext; + + return FirstOrCreateDataSourceContext(); + } + + public T? FirstOrCreateDataSourceContext() where T : DataSourceContext + { + var pair = DataSourceContexts.FirstOrDefault(); + if (pair.Value != null) + return pair.Value as T; + + return CreateDataSourceContext(); + } + + public T? CreateDataSourceContext() where T : DataSourceContext + { + return CreateDataSourceContext(typeof(T).FullName) as T; + } + + public DataSourceContext? CreateDataSourceContext(Type type) + { + return CreateDataSourceContext(type.FullName); + } + + public DataSourceContext? CreateDataSourceContext(string? contextFullName) + { + var packageService = services.GetRequiredService(); + var dataContext = packageService.CreateDataSourceContext(contextFullName); + + var appStateService = services.GetRequiredService(); + appStateService.UpdateDataSource(dataContext.State); + + AddDataSourceContext(dataContext); + + WeakReferenceMessenger.Default?.Send( + new DataSourceStateChangedMessage(EntityStateChangedType.Added, dataContext), + dataContext.GetType().FullName + ); + + return dataContext; + } + + public T? GetDataSourceContext(Guid? dataSourceStateId) where T : DataSourceContext + { + if (dataSourceStateId == null) + { + return null; + } + if (DataSourceContexts.TryGetValue(dataSourceStateId.Value, out var dataSourceContext)) + { + return dataSourceContext as T; + } + return null; + } + + public void DestroyDataSourceContext(DataSourceContext? dataSourceContext) + { + // TODO: + // 모든 위젯에서 해당 연결 끊기 + //WeakReferenceMessenger.Default.Send(new DataSourceRemovedMessage(context.State.Id)); + + var appStateService = services.GetRequiredService(); + appStateService.RemoveDataSource(dataSourceContext.State.Id); + RemoveDataSourceContext(dataSourceContext); + + WeakReferenceMessenger.Default?.Send( + new DataSourceStateChangedMessage(EntityStateChangedType.Removed, dataSourceContext), + dataSourceContext.GetType().FullName + ); + } + + public void DestroyDataSourceContext(Guid? guid) + { + var dataContext = GetDataSourceContext(guid); + + DestroyDataSourceContext(dataContext); + } + public void AddDataSourceContext(Guid dataSourceStateId, DataSourceContext dataSourceContext) { DataSourceContexts.Add(dataSourceStateId, dataSourceContext); @@ -59,17 +146,4 @@ public IEnumerable GetDataSourceContexts() { return DataSourceContexts.Values.OfType(); } - - public T? GetDataSourceContext(Guid? dataSourceStateId) where T : DataSourceContext - { - if (dataSourceStateId == null) - { - return null; - } - if (DataSourceContexts.TryGetValue(dataSourceStateId.Value, out var dataSourceContext)) - { - return dataSourceContext as T; - } - return null; - } } diff --git a/src/Apps/Corathing.Organizer/Services/PackageService.cs b/src/Apps/Corathing.Organizer/Services/PackageService.cs index 10575af..7c1b881 100644 --- a/src/Apps/Corathing.Organizer/Services/PackageService.cs +++ b/src/Apps/Corathing.Organizer/Services/PackageService.cs @@ -146,8 +146,10 @@ public List GetAvailableDataSources() /// /// /// - public DataSourceContext? CreateDataSourceContext(string contextTypeFullName) + public DataSourceContext? CreateDataSourceContext(string? contextTypeFullName) { + if (string.IsNullOrEmpty(contextTypeFullName)) + return null; if (!_dataSourceGenerator.TryGetValue(contextTypeFullName, out var dataSourceGenerator)) return null; return dataSourceGenerator.CreateDataSource(); @@ -156,8 +158,10 @@ public List GetAvailableDataSources() /// /// /// - public Type? GetDataSourceCustomSettingsType(string contextTypeFullName) + public Type? GetDataSourceCustomSettingsType(string? contextTypeFullName) { + if (string.IsNullOrEmpty(contextTypeFullName)) + return null; if (!_dataSourceGenerator.TryGetValue(contextTypeFullName, out var dataSourceGenerator)) return null; return dataSourceGenerator.Info.OptionType; @@ -166,8 +170,10 @@ public List GetAvailableDataSources() /// /// /// - public CustomSettingsContext? CreateDataSourceSettingsContext(string contextTypeFullName) + public CustomSettingsContext? CreateDataSourceSettingsContext(string? contextTypeFullName) { + if (string.IsNullOrEmpty(contextTypeFullName)) + return null; if (!_dataSourceGenerator.TryGetValue(contextTypeFullName, out var dataSourceGenerator)) return null; return dataSourceGenerator.CreateSettingsContext(); @@ -175,6 +181,8 @@ public List GetAvailableDataSources() public Type? GetDataSourceSettingsContextType(string? contextTypeFullName) { + if (string.IsNullOrEmpty(contextTypeFullName)) + return null; if (!_dataSourceGenerator.TryGetValue(contextTypeFullName, out var dataSourceGenerator)) return null; return dataSourceGenerator.Info.SettingsContextType; @@ -200,8 +208,10 @@ public List GetWidgetGenerators() /// /// /// - public WidgetContext? CreateWidgetContext(string contextTypeFullName, WidgetState? state = null) + public WidgetContext? CreateWidgetContext(string? contextTypeFullName, WidgetState? state = null) { + if (string.IsNullOrEmpty(contextTypeFullName)) + return null; if (!_widgetGenerators.TryGetValue(contextTypeFullName, out var widgetContext)) return null; return widgetContext.CreateWidget(state); @@ -210,8 +220,10 @@ public List GetWidgetGenerators() /// /// /// - public Type? GetWidgetCustomSettingsType(string contextTypeFullName) + public Type? GetWidgetCustomSettingsType(string? contextTypeFullName) { + if (string.IsNullOrEmpty(contextTypeFullName)) + return null; if (!_widgetGenerators.TryGetValue(contextTypeFullName, out var widgetContext)) return null; return widgetContext.Info.WidgetCustomSettingsType; @@ -220,8 +232,10 @@ public List GetWidgetGenerators() /// /// /// - public CustomSettingsContext? CreateWidgetSettingsContext(string contextTypeFullName) + public CustomSettingsContext? CreateWidgetSettingsContext(string? contextTypeFullName) { + if (string.IsNullOrEmpty(contextTypeFullName)) + return null; if (!_widgetGenerators.TryGetValue(contextTypeFullName, out var widgetContext)) return null; return widgetContext.CreateSettingsContext(); diff --git a/src/Shared/Corathing.Contracts/DataContexts/DataSourceSelector.cs b/src/Shared/Corathing.Contracts/DataContexts/DataSourceSelector.cs index 2cfe195..aa6f64e 100644 --- a/src/Shared/Corathing.Contracts/DataContexts/DataSourceSelector.cs +++ b/src/Shared/Corathing.Contracts/DataContexts/DataSourceSelector.cs @@ -30,13 +30,17 @@ public partial class DataSourceSelector : [ObservableProperty] private string? _hintSelectionText; + private bool _selectDefaultCreateIfEmpty; + public DataSourceSelector( IServiceProvider services, - Guid? guid = null) + Guid? guid = null, + bool selectDefaultCreateIfEmpty = false) { _services = services; DataSourceContexts = new ObservableCollection(); HintSelectionText = "Default DataSource"; + _selectDefaultCreateIfEmpty = selectDefaultCreateIfEmpty; var dataSourceService = _services.GetService(); @@ -44,12 +48,9 @@ public DataSourceSelector( dataSourceService.GetAllDataSourceContexts() ); - if (guid != null) - { - SelectedDataSourceContext = dataSourceService.GetDataSourceContext(guid); - } + Select(guid); - WeakReferenceMessenger.Default.Register( + WeakReferenceMessenger.Default?.Register( this, typeof(T).FullName, OnDataSourceStateChanged); @@ -85,6 +86,22 @@ private void OnDataSourceStateChanged(object recipient, DataSourceStateChangedMe public void Select(Guid? guid) { - SelectedDataSourceContext = DataSourceContexts.FirstOrDefault(c => c.DataSourceId == guid); + if (guid != null) + { + SelectedDataSourceContext = DataSourceContexts.FirstOrDefault(c => c.DataSourceId == guid); + } + + if (SelectedDataSourceContext == null && _selectDefaultCreateIfEmpty) + { + var dataSourceService = _services.GetRequiredService(); + + if (DataSourceContexts.Count == 0) + { + var dataContext = dataSourceService.CreateDataSourceContext(); + + DataSourceContexts.Add(dataContext); + } + SelectedDataSourceContext = DataSourceContexts.FirstOrDefault(); + } } } diff --git a/src/Shared/Corathing.Contracts/DataContexts/WidgetContext.cs b/src/Shared/Corathing.Contracts/DataContexts/WidgetContext.cs index 97a9c2e..027ebdf 100644 --- a/src/Shared/Corathing.Contracts/DataContexts/WidgetContext.cs +++ b/src/Shared/Corathing.Contracts/DataContexts/WidgetContext.cs @@ -16,7 +16,8 @@ namespace Corathing.Contracts.Bases; public partial class WidgetContext : ObservableRecipient { - protected IServiceProvider _services; + protected IServiceProvider? _services; + protected IAppStateService? _appStateService; #region 숨겨진 프로퍼티 public Guid WidgetId; @@ -43,11 +44,15 @@ public partial class WidgetContext : ObservableRecipient #region Only Used Properties in Context [ObservableProperty] private bool? _editMode; + [ObservableProperty] + private bool? _isTemporal; #endregion public void Initialize(IServiceProvider services, WidgetState state) { _services = services; + _appStateService = _services.GetRequiredService(); + IsTemporal = false; State = state; WidgetId = state.Id; @@ -87,8 +92,8 @@ public void ApplyState(WidgetState state) public void Destroy() { OnDestroy(); - var appState = _services.GetService(); - appState.RemoveWidget(WidgetId); + + _appStateService?.RemoveWidget(WidgetId); } public virtual void OnCreate(IServiceProvider services, WidgetState state) diff --git a/src/Shared/Corathing.Contracts/Services/IDataSourceService.cs b/src/Shared/Corathing.Contracts/Services/IDataSourceService.cs index 6f2b3b3..12ee9b1 100644 --- a/src/Shared/Corathing.Contracts/Services/IDataSourceService.cs +++ b/src/Shared/Corathing.Contracts/Services/IDataSourceService.cs @@ -10,6 +10,14 @@ namespace Corathing.Contracts.Services; public interface IDataSourceService { + T? GetOrFirstOrCreateDataSourceContext(Guid? guid) where T : DataSourceContext; + T? FirstOrCreateDataSourceContext() where T : DataSourceContext; + T? CreateDataSourceContext() where T : DataSourceContext; + DataSourceContext? CreateDataSourceContext(Type type); + T? GetDataSourceContext(Guid? dataSourceStateId) where T : DataSourceContext; + void DestroyDataSourceContext(DataSourceContext? dataSourceContext); + void DestroyDataSourceContext(Guid? guid); + void AddDataSourceContext(Guid dataSourceStateId, DataSourceContext dataSourceContext); void AddDataSourceContext(DataSourceContext dataSourceContext); @@ -18,7 +26,4 @@ public interface IDataSourceService IEnumerable GetAllDataSourceContexts(Type? dataSourceContext); IEnumerable GetAllDataSourceContexts(); - - // Data Sources - T? GetDataSourceContext(Guid? dataSourceStateId) where T : DataSourceContext; } diff --git a/src/Shared/Corathing.Contracts/Services/IPackageService.cs b/src/Shared/Corathing.Contracts/Services/IPackageService.cs index 46c6676..673c32f 100644 --- a/src/Shared/Corathing.Contracts/Services/IPackageService.cs +++ b/src/Shared/Corathing.Contracts/Services/IPackageService.cs @@ -36,16 +36,16 @@ public interface IPackageService // Data Sources // -------------------------------------------------------------------- List GetAvailableDataSources(); - DataSourceContext? CreateDataSourceContext(string contextTypeFullName); - Type? GetDataSourceCustomSettingsType(string contextTypeFullName); - CustomSettingsContext? CreateDataSourceSettingsContext(string contextTypeFullName); + DataSourceContext? CreateDataSourceContext(string? contextTypeFullName); + Type? GetDataSourceCustomSettingsType(string? contextTypeFullName); + CustomSettingsContext? CreateDataSourceSettingsContext(string? contextTypeFullName); Type? GetDataSourceSettingsContextType(string? contextTypeFullName); // -------------------------------------------------------------------- // Widgets // -------------------------------------------------------------------- List GetAvailableWidgets(); - WidgetContext? CreateWidgetContext(string contextTypeFullName, WidgetState? state = null); - Type? GetWidgetCustomSettingsType(string contextTypeFullName); - CustomSettingsContext? CreateWidgetSettingsContext(string contextTypeFullName); + WidgetContext? CreateWidgetContext(string? contextTypeFullName, WidgetState? state = null); + Type? GetWidgetCustomSettingsType(string? contextTypeFullName); + CustomSettingsContext? CreateWidgetSettingsContext(string? contextTypeFullName); } diff --git a/src/Widgets/Corathing.Widgets.Basics/DataSources/WebSessions/WebSessionDataSourceDataTemplates.xaml b/src/Widgets/Corathing.Widgets.Basics/DataSources/WebSessions/WebSessionDataSourceDataTemplates.xaml index bd70593..6b4b8d7 100644 --- a/src/Widgets/Corathing.Widgets.Basics/DataSources/WebSessions/WebSessionDataSourceDataTemplates.xaml +++ b/src/Widgets/Corathing.Widgets.Basics/DataSources/WebSessions/WebSessionDataSourceDataTemplates.xaml @@ -63,8 +63,7 @@ - + diff --git a/src/Widgets/Corathing.Widgets.Basics/DataSources/WebSessions/WebSessionDataSourceSelector.cs b/src/Widgets/Corathing.Widgets.Basics/DataSources/WebSessions/WebSessionDataSourceSelector.cs index da64fdb..6af3fa3 100644 --- a/src/Widgets/Corathing.Widgets.Basics/DataSources/WebSessions/WebSessionDataSourceSelector.cs +++ b/src/Widgets/Corathing.Widgets.Basics/DataSources/WebSessions/WebSessionDataSourceSelector.cs @@ -5,12 +5,20 @@ using System.Threading.Tasks; using Corathing.Contracts.DataContexts; +using Corathing.Contracts.Services; + +using Microsoft.Extensions.DependencyInjection; namespace Corathing.Widgets.Basics.DataSources.WebSessions; public partial class WebSessionDataSourceSelector : DataSourceSelector { - public WebSessionDataSourceSelector(IServiceProvider services, Guid? guid = null) : base(services, guid) + public WebSessionDataSourceSelector(IServiceProvider services, Guid? guid = null) : + base( + services: services, + guid: guid, + selectDefaultCreateIfEmpty: true + ) { } } diff --git a/src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenTypeToVisibleConverter.cs b/src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenTypeToVisibleConverter.cs new file mode 100644 index 0000000..3a16282 --- /dev/null +++ b/src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenTypeToVisibleConverter.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace Corathing.Widgets.Basics.Widgets.FileOpeners; + +/// +/// One way converter from to . +/// +[ValueConversion(typeof(FileOpenType), typeof(Visibility))] +public class FileOpenTypeFileToVisibleConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is FileOpenType fileOpenType) + { + return fileOpenType switch + { + FileOpenType.Files => Visibility.Visible, + FileOpenType.Folders => Visibility.Collapsed, + _ => Visibility.Collapsed, + }; + } + + return Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} + +[ValueConversion(typeof(FileOpenType), typeof(Visibility))] +public class FileOpenTypeFolderToVisibleConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is FileOpenType fileOpenType) + { + return fileOpenType switch + { + FileOpenType.Files => Visibility.Collapsed, + FileOpenType.Folders => Visibility.Visible, + _ => Visibility.Collapsed, + }; + } + + return Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} diff --git a/src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenerDataTemplates.xaml b/src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenerDataTemplates.xaml index f2719ff..cd2f4dd 100644 --- a/src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenerDataTemplates.xaml +++ b/src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenerDataTemplates.xaml @@ -13,6 +13,8 @@ + + @@ -20,7 +22,7 @@ Command="{Binding ExecuteCommand}"> - + @@ -35,7 +37,7 @@ + Header="Type of Open File or Folder"> @@ -45,7 +47,8 @@ + Visibility="{Binding OpenType, Converter={StaticResource FileOpenTypeFileToVisibleConverter}, Mode=OneWay}" + Header="Files"> @@ -90,13 +93,72 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenerWidgetContext.cs b/src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenerWidgetContext.cs index 2275f6e..b61f5f1 100644 --- a/src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenerWidgetContext.cs +++ b/src/Widgets/Corathing.Widgets.Basics/Widgets/FileOpeners/FileOpenerWidgetContext.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; @@ -37,6 +38,9 @@ public partial class FileOpenerWidgetContext : WidgetContext [ObservableProperty] private FileOpenType _openType = FileOpenType.Files; + [ObservableProperty] + private string _icon; + [ObservableProperty] private ObservableCollection? _filePaths; @@ -50,6 +54,7 @@ public override void OnCreate(IServiceProvider services, WidgetState state) { FilePaths = new ObservableCollection(); FolderPaths = new ObservableCollection(); + Icon = "Document24"; ILocalizationService localizationService = _services.GetService(); localizationService.Provide("Corathing.Widgets.Basics.FileOpenerName", value => @@ -69,6 +74,14 @@ public override void OnStateChanged(WidgetState state) return; } OpenType = option.OpenType; + if (OpenType == FileOpenType.Files) + { + Icon = "Document24"; + } + else if (OpenType == FileOpenType.Folders) + { + Icon = "Folder24"; + } FilePaths.Clear(); if (option.Files != null) diff --git a/src/Widgets/Corathing.Widgets.Basics/Widgets/ToDoLists/ToDoListWidget.xaml b/src/Widgets/Corathing.Widgets.Basics/Widgets/ToDoLists/ToDoListWidget.xaml index 99ac80b..b75d907 100644 --- a/src/Widgets/Corathing.Widgets.Basics/Widgets/ToDoLists/ToDoListWidget.xaml +++ b/src/Widgets/Corathing.Widgets.Basics/Widgets/ToDoLists/ToDoListWidget.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Corathing.Widgets.Basics.Widgets.ToDoLists" xmlns:models="clr-namespace:Corathing.Widgets.Basics.Widgets.ToDoLists.Models" + xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" xmlns:behaviors="clr-namespace:Corathing.UI.WPF.Behaviors;assembly=Corathing.UI.WPF" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:i="http://schemas.microsoft.com/xaml/behaviors" @@ -170,6 +171,7 @@ diff --git a/src/Widgets/Corathing.Widgets.Basics/Widgets/WebPages/WebPageOptionViewModel.cs b/src/Widgets/Corathing.Widgets.Basics/Widgets/WebPages/WebPageOptionViewModel.cs index 4541978..338c94a 100644 --- a/src/Widgets/Corathing.Widgets.Basics/Widgets/WebPages/WebPageOptionViewModel.cs +++ b/src/Widgets/Corathing.Widgets.Basics/Widgets/WebPages/WebPageOptionViewModel.cs @@ -35,12 +35,16 @@ protected override void OnCreate(object? defaultOption) { throw new ArgumentException($"Not a valid type for CustomSettings {nameof(WebPageOption)}"); } - CustomSettings = webPageOption; WebSessionDataSourceSelector = new WebSessionDataSourceSelector(Services); WebSessionDataSourceSelector.PropertyChanged += (sender, args) => { OnPropertyChanged(new PropertyChangedEventArgs(nameof(WebSessionDataSourceSelector))); }; + if (WebSessionDataSourceSelector.SelectedDataSourceContext != null) + { + webPageOption.WebSessionDataSourceId = WebSessionDataSourceSelector.SelectedDataSourceContext.DataSourceId; + } + CustomSettings = webPageOption; } /// diff --git a/src/Widgets/Corathing.Widgets.Basics/Widgets/WebPages/WebPageWidgetContext.cs b/src/Widgets/Corathing.Widgets.Basics/Widgets/WebPages/WebPageWidgetContext.cs index d9551e7..e5965fb 100644 --- a/src/Widgets/Corathing.Widgets.Basics/Widgets/WebPages/WebPageWidgetContext.cs +++ b/src/Widgets/Corathing.Widgets.Basics/Widgets/WebPages/WebPageWidgetContext.cs @@ -69,41 +69,32 @@ public async override void OnStateChanged(WidgetState state) SetAutoReloadInterval(option.AutoReloadInterval); SetUrl(option.Url ?? WebPageOption.DefaultUrl); - if (option.WebSessionDataSourceId != null && option.WebSessionDataSourceId != Guid.Empty) + var dataSourceService = _services.GetRequiredService(); + var dataSource = dataSourceService.GetOrFirstOrCreateDataSourceContext(option.WebSessionDataSourceId); + + if (WebSessionDataSource == null || dataSource.DataSourceId != WebSessionDataSource.DataSourceId) { - var dataSourceService = _services.GetRequiredService(); - var dataSource = dataSourceService.GetDataSourceContext(option.WebSessionDataSourceId); - if (WebSessionDataSource == null || dataSource.DataSourceId != WebSessionDataSource.DataSourceId) + WebSessionDataSource = dataSource; + if (WebView != null) { - WebSessionDataSource = dataSource; - if (WebView != null) - { - //WebView.Loaded -= WebView_Loaded; - WebView.Dispose(); - WebView = null; - } + //WebView.Loaded -= WebView_Loaded; + WebView.Dispose(); WebView = null; - if (WebSessionDataSource != null) - { - WebView = WebSessionDataSource.CreateWebView(); - await WebView.EnsureCoreWebView2Async(); - themeService.ProvideApplicationTheme(theme => SetTheme(theme)); - WebView.Source = new Uri(option.Url ?? WebPageOption.DefaultUrl); - //WebView.Loaded += WebView_Loaded; - //WebView.Loaded += (s, e) => - //{ - // SetWebView(WebView); - //}; - //WebView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted; - //WebView.Loaded += (s, e) => - //{ - // WebView.NavigationCompleted += OnWebViewNavigationCompleted; - // WebView.SetCurrentValue(FrameworkElement.UseLayoutRoundingProperty, true); - // WebView.SetCurrentValue(WebView2.DefaultBackgroundColorProperty, System.Drawing.Color.Transparent); - - //}; - } } + WebView = null; + if (WebSessionDataSource != null) + { + WebView = WebSessionDataSource.CreateWebView(); + await WebView.EnsureCoreWebView2Async(); + themeService.ProvideApplicationTheme(theme => SetTheme(theme)); + WebView.Source = new Uri(option.Url ?? WebPageOption.DefaultUrl); + } + } + + if (IsTemporal == false) + { + option.WebSessionDataSourceId = dataSource.DataSourceId; + _appStateService?.UpdateWidget(state); } } @@ -129,6 +120,18 @@ public override void OnDestroy() private void WebView_Loaded(object? sender, RoutedEventArgs e) { SetWebView(); + //WebView.Loaded += WebView_Loaded; + //WebView.Loaded += (s, e) => + //{ + // SetWebView(WebView); + //}; + //WebView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted; + //WebView.Loaded += (s, e) => + //{ + // WebView.NavigationCompleted += OnWebViewNavigationCompleted; + // WebView.SetCurrentValue(FrameworkElement.UseLayoutRoundingProperty, true); + // WebView.SetCurrentValue(WebView2.DefaultBackgroundColorProperty, System.Drawing.Color.Transparent); + //}; } private async Task ReloadRoutine(CancellationToken token)