diff --git a/src/Apps/Corathing.Organizer/MainWindow.xaml.cs b/src/Apps/Corathing.Organizer/MainWindow.xaml.cs index 0b32927..d4929bf 100644 --- a/src/Apps/Corathing.Organizer/MainWindow.xaml.cs +++ b/src/Apps/Corathing.Organizer/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using System.Text; +using System.Diagnostics; +using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -32,6 +33,7 @@ public MainWindow() MouseDown += Window_MouseDown; MouseDoubleClick += Window_MouseDoubleClick; + } private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e) diff --git a/src/Apps/Corathing.Organizer/Services/PackageService.cs b/src/Apps/Corathing.Organizer/Services/PackageService.cs index 38b359d..124d8f6 100644 --- a/src/Apps/Corathing.Organizer/Services/PackageService.cs +++ b/src/Apps/Corathing.Organizer/Services/PackageService.cs @@ -45,7 +45,8 @@ public class PackageService : IPackageService /// Gets or sets the available widgets. /// /// The available widgets. - private readonly List _availableWidgets = new List(); + private readonly Dictionary _widgetGenerators = new Dictionary(); + private readonly IServiceProvider _services; private NuGet.Common.ILogger _nugetLogger; @@ -61,11 +62,20 @@ public PackageService(IServiceProvider services) public void RegisterWidgets(List widgets) { - _availableWidgets.AddRange(widgets); + widgets.ForEach(widget => + { + _widgetGenerators.Add(widget.ContextType, widget); + }); } + public List GetAvailableWidgets() { - return _availableWidgets; + return _widgetGenerators.Values.ToList(); + } + + public bool TryGetWidgetGenerator(Type viewType, out CoraWidgetGenerator generator) + { + return _widgetGenerators.TryGetValue(viewType, out generator); } public void LoadAssembly(Assembly assembly) @@ -91,7 +101,7 @@ public void LoadAssembly(Assembly assembly) var attribute = ((EntryCoraWidgetAttribute)attributes[i]); attribute.Configure(_services); - _availableWidgets.Add(attribute.Generator); + _widgetGenerators.Add(attribute.Generator.ContextType, attribute.Generator); App.Current.Resources.MergedDictionaries.Add( new ResourceDictionary() diff --git a/src/Apps/Corathing.Organizer/ViewModels/WidgetSettingsViewModel.cs b/src/Apps/Corathing.Organizer/ViewModels/WidgetSettingsViewModel.cs index 9a293f8..9b3c0b8 100644 --- a/src/Apps/Corathing.Organizer/ViewModels/WidgetSettingsViewModel.cs +++ b/src/Apps/Corathing.Organizer/ViewModels/WidgetSettingsViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -8,14 +9,48 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using Corathing.Contracts.Bases; +using Corathing.Contracts.Services; +using Corathing.Dashboards.WPF.Controls; + +using Microsoft.Extensions.DependencyInjection; + namespace Corathing.Organizer.ViewModels; public partial class WidgetSettingsViewModel : ObservableObject { + private IServiceProvider _services; + + private WidgetHost _originalWidget; + private WidgetContext _originalContext; + private WidgetContext _tempWidgetContext; + public WidgetSettingsViewModel(IServiceProvider services) { + _services = services; + } + + public void RegisterWidget(WidgetHost widgetHost) + { + _originalWidget = widgetHost; + + _originalContext = _originalWidget.DataContext as WidgetContext; + + var packageService = _services.GetService(); + packageService.TryGetWidgetGenerator(_originalContext.WidgetType, out var generator); + + // TODO: + // 24-06-16: + // 1. Create a new instance of the widget context + // 2. Copy the properties of the original widget context to the new widget context + // 3. Set the new widget context as the data context of the widget host + // 4. Set the new widget context as the temporary widget context + // 5. Set the original widget context as the original widget context + + //(WidgetContext)Activator.CreateInstance(ContextType, _services); } + [RelayCommand] public void Close(Window window) { diff --git a/src/Apps/Corathing.Organizer/Views/OrganizerSettingsView.xaml b/src/Apps/Corathing.Organizer/Views/OrganizerSettingsView.xaml index 2bdb1a5..ac4bf0a 100644 --- a/src/Apps/Corathing.Organizer/Views/OrganizerSettingsView.xaml +++ b/src/Apps/Corathing.Organizer/Views/OrganizerSettingsView.xaml @@ -370,23 +370,7 @@ - - - - - - - + diff --git a/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml b/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml index 7edd92e..ae13e0b 100644 --- a/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml +++ b/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml @@ -1,16 +1,24 @@  + + + + + + + + Text="Setting Widget" /> + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml.cs b/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml.cs index 5b67bfa..97b3b43 100644 --- a/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml.cs +++ b/src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml.cs @@ -33,6 +33,7 @@ public WidgetSettingsView(WidgetHost widgetHost) InitializeComponent(); DataContext = ViewModel = App.Current.Services.GetService(); + ViewModel.RegisterWidget(widgetHost); Loaded += (s, e) => { diff --git a/src/Shared/Corathing.Contracts/Bases/WidgetContext.cs b/src/Shared/Corathing.Contracts/Bases/WidgetContext.cs index 0ff6d84..9520314 100644 --- a/src/Shared/Corathing.Contracts/Bases/WidgetContext.cs +++ b/src/Shared/Corathing.Contracts/Bases/WidgetContext.cs @@ -13,6 +13,13 @@ public partial class WidgetContext : ObservableRecipient { protected readonly IServiceProvider _services; + #region 숨겨진 프로퍼티 + [ObservableProperty] + private Type _widgetType; + [ObservableProperty] + private Guid _widgetId; + #endregion + #region 확정된 프로퍼티 [ObservableProperty] private string _widgetTitle; diff --git a/src/Shared/Corathing.Contracts/Services/IPackageService.cs b/src/Shared/Corathing.Contracts/Services/IPackageService.cs index f440ed5..99363de 100644 --- a/src/Shared/Corathing.Contracts/Services/IPackageService.cs +++ b/src/Shared/Corathing.Contracts/Services/IPackageService.cs @@ -12,5 +12,7 @@ public interface IPackageService { void RegisterWidgets(List widgets); List GetAvailableWidgets(); + bool TryGetWidgetGenerator(Type viewType, out CoraWidgetGenerator generator); + void LoadWidgetsFromDLL(string pathDLL); } diff --git a/src/Shared/Corathing.Dashboards.WPF/Controls/DashboardHost.xaml.cs b/src/Shared/Corathing.Dashboards.WPF/Controls/DashboardHost.xaml.cs index 4ad7e63..46f060e 100644 --- a/src/Shared/Corathing.Dashboards.WPF/Controls/DashboardHost.xaml.cs +++ b/src/Shared/Corathing.Dashboards.WPF/Controls/DashboardHost.xaml.cs @@ -258,7 +258,7 @@ protected override void ClearContainerForItemOverride(DependencyObject element, /// The element that is used to display the given item. protected override DependencyObject GetContainerForItemOverride() { - return new WidgetHost { Id = Guid.NewGuid() }; + return new WidgetHost { Id = Guid.NewGuid(), EditMode = EditMode }; } /// diff --git a/src/Shared/Corathing.Dashboards.WPF/Controls/WidgetHost.xaml b/src/Shared/Corathing.Dashboards.WPF/Controls/WidgetHost.xaml index 3be153d..0764015 100644 --- a/src/Shared/Corathing.Dashboards.WPF/Controls/WidgetHost.xaml +++ b/src/Shared/Corathing.Dashboards.WPF/Controls/WidgetHost.xaml @@ -19,12 +19,6 @@ - --> - @@ -80,7 +74,7 @@ - @@ -122,7 +116,7 @@ - diff --git a/src/Shared/Corathing.Dashboards.WPF/Controls/WidgetHost.xaml.cs b/src/Shared/Corathing.Dashboards.WPF/Controls/WidgetHost.xaml.cs index 274718f..4afd159 100644 --- a/src/Shared/Corathing.Dashboards.WPF/Controls/WidgetHost.xaml.cs +++ b/src/Shared/Corathing.Dashboards.WPF/Controls/WidgetHost.xaml.cs @@ -35,6 +35,19 @@ namespace Corathing.Dashboards.WPF.Controls public partial class WidgetHost : ContentControl { #region Public Fields + + public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( + nameof(Title), + typeof(string), + typeof(WidgetHost), + new PropertyMetadata(default(string))); + + public string Title + { + get => (string)GetValue(TitleProperty); + set => SetValue(TitleProperty, value); + } + /// /// The edit mode property /// @@ -69,20 +82,6 @@ public CornerRadius CornerRadius } - //public static readonly DependencyProperty TemplateButtonCommandProperty = DependencyProperty.Register( - // nameof(TemplateButtonCommand), - // typeof(IRelayCommand), - // typeof(BreadcrumbBar), - // new PropertyMetadata(null) - //); - - //public static readonly DependencyProperty TemplateButtonCommandProperty = DependencyProperty.Register( - // nameof(TemplateButtonCommand), - // typeof(IRelayCommand), - // typeof(BreadcrumbBar), - // new PropertyMetadata(null) - //); - #endregion #region Private Fields diff --git a/src/Shared/Corathing.UI.WPF/Controls/AutoIcon/AutoIcon.xaml.cs b/src/Shared/Corathing.UI.WPF/Controls/AutoIcon/AutoIcon.xaml.cs index 23ff829..246aaac 100644 --- a/src/Shared/Corathing.UI.WPF/Controls/AutoIcon/AutoIcon.xaml.cs +++ b/src/Shared/Corathing.UI.WPF/Controls/AutoIcon/AutoIcon.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -20,6 +21,35 @@ namespace Corathing.UI.WPF.Controls.AutoIcon; /// public partial class AutoIcon : UserControl { + #region Public Properties + + public static readonly DependencyProperty MaxSizeProperty = DependencyProperty.Register( + nameof(MaxSize), + typeof(double), + typeof(AutoIcon), + new PropertyMetadata(null)); + + public double MaxSize + { + get => (double)GetValue(MaxSizeProperty); + set => SetValue(MaxSizeProperty, value); + } + + public static readonly DependencyProperty IconProperty = DependencyProperty.Register( + nameof(Icon), + typeof(string), + typeof(AutoIcon), + new PropertyMetadata(null)); + + public string Icon + { + get => (string)GetValue(IconProperty); + set => SetValue(IconProperty, value); + } + + + #endregion + static AutoIcon() { @@ -29,4 +59,28 @@ public AutoIcon() { InitializeComponent(); } + + + #region Private Methods + /// + /// Get DPI of the screen from Visual + /// + /// + private double GetDpi() + { + var dpi = VisualTreeHelper.GetDpi(this); + return Math.Min(dpi.PixelsPerInchX, dpi.PixelsPerInchY); + } + + public double ConvertFontSizeToPixels(double fontSize) + { + return fontSize * GetDpi() / 72; + } + + public double ConvertPixelsToFontSize(double pixels) + { + return pixels * 72 / GetDpi(); + } + + #endregion } diff --git a/src/Widgets/Corathing.Widgets.Basics/Resources/BasicWidgetStringResources.Designer.cs b/src/Widgets/Corathing.Widgets.Basics/Resources/BasicWidgetStringResources.Designer.cs index 9a2f50e..04f1f3e 100644 --- a/src/Widgets/Corathing.Widgets.Basics/Resources/BasicWidgetStringResources.Designer.cs +++ b/src/Widgets/Corathing.Widgets.Basics/Resources/BasicWidgetStringResources.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// 이 코드는 도구를 사용하여 생성되었습니다. +// 런타임 버전:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면 +// 이러한 변경 내용이 손실됩니다. // //------------------------------------------------------------------------------ @@ -13,16 +13,16 @@ namespace Corathing.Widgets.Basics.Resources { /// - /// A strongly-typed resource class, for looking up localized strings, etc. + /// 지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다. /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. + // 이 클래스는 ResGen 또는 Visual Studio와 같은 도구를 통해 StronglyTypedResourceBuilder + // 클래스에서 자동으로 생성되었습니다. + // 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여 ResGen을 + // 다시 실행하거나 VS 프로젝트를 다시 빌드하십시오. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class BasicWidgetStringResources { + public class BasicWidgetStringResources { private static global::System.Resources.ResourceManager resourceMan; @@ -33,10 +33,10 @@ internal BasicWidgetStringResources() { } /// - /// Returns the cached ResourceManager instance used by this class. + /// 이 클래스에서 사용하는 캐시된 ResourceManager 인스턴스를 반환합니다. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + public static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Corathing.Widgets.Basics.Resources.BasicWidgetStringResources", typeof(BasicWidgetStringResources).Assembly); @@ -47,11 +47,11 @@ internal BasicWidgetStringResources() { } /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. + /// 이 강력한 형식의 리소스 클래스를 사용하여 모든 리소스 조회에 대해 현재 스레드의 CurrentUICulture 속성을 + /// 재정의합니다. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + public static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -61,12 +61,93 @@ internal BasicWidgetStringResources() { } /// - /// Looks up a localized string similar to . + /// 과(와) 유사한 지역화된 문자열을 찾습니다. /// - internal static string Corathing_Widgets_Basics_FileOpenerName { + public static string Corathing_Widgets_Basics_CalendarName { + get { + return ResourceManager.GetString("Corathing.Widgets.Basics.CalendarName", resourceCulture); + } + } + + /// + /// 과(와) 유사한 지역화된 문자열을 찾습니다. + /// + public static string Corathing_Widgets_Basics_CommanderName { + get { + return ResourceManager.GetString("Corathing.Widgets.Basics.CommanderName", resourceCulture); + } + } + + /// + /// 과(와) 유사한 지역화된 문자열을 찾습니다. + /// + public static string Corathing_Widgets_Basics_FileOpenerName { get { return ResourceManager.GetString("Corathing.Widgets.Basics.FileOpenerName", resourceCulture); } } + + /// + /// 과(와) 유사한 지역화된 문자열을 찾습니다. + /// + public static string Corathing_Widgets_Basics_LinkOpenerName { + get { + return ResourceManager.GetString("Corathing.Widgets.Basics.LinkOpenerName", resourceCulture); + } + } + + /// + /// 과(와) 유사한 지역화된 문자열을 찾습니다. + /// + public static string Corathing_Widgets_Basics_NoteName { + get { + return ResourceManager.GetString("Corathing.Widgets.Basics.NoteName", resourceCulture); + } + } + + /// + /// 과(와) 유사한 지역화된 문자열을 찾습니다. + /// + public static string Corathing_Widgets_Basics_TextEditorName { + get { + return ResourceManager.GetString("Corathing.Widgets.Basics.TextEditorName", resourceCulture); + } + } + + /// + /// 과(와) 유사한 지역화된 문자열을 찾습니다. + /// + public static string Corathing_Widgets_Basics_TimerName { + get { + return ResourceManager.GetString("Corathing.Widgets.Basics.TimerName", resourceCulture); + } + } + + /// + /// 과(와) 유사한 지역화된 문자열을 찾습니다. + /// + public static string Corathing_Widgets_Basics_ToDoListName { + get { + return ResourceManager.GetString("Corathing.Widgets.Basics.ToDoListName", resourceCulture); + } + } + + /// + /// 과(와) 유사한 지역화된 문자열을 찾습니다. + /// + public static string Corathing_Widgets_Basics_WebPageName { + get { + return ResourceManager.GetString("Corathing.Widgets.Basics.WebPageName", resourceCulture); + } + } + + /// + /// 과(와) 유사한 지역화된 문자열을 찾습니다. + /// + public static string Corathing_Widgets_Basics_WebQueryName { + get { + return ResourceManager.GetString("Corathing.Widgets.Basics.WebQueryName", resourceCulture); + } + } } }