Skip to content

Commit

Permalink
Editing Widget Context...
Browse files Browse the repository at this point in the history
  • Loading branch information
dogzz9445 committed Jun 16, 2024
1 parent 19e5d96 commit 6afcc27
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 66 deletions.
4 changes: 3 additions & 1 deletion src/Apps/Corathing.Organizer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using System.Diagnostics;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
Expand Down Expand Up @@ -32,6 +33,7 @@ public MainWindow()

MouseDown += Window_MouseDown;
MouseDoubleClick += Window_MouseDoubleClick;

}

private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
Expand Down
18 changes: 14 additions & 4 deletions src/Apps/Corathing.Organizer/Services/PackageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class PackageService : IPackageService
/// Gets or sets the available widgets.
/// </summary>
/// <value>The available widgets.</value>
private readonly List<CoraWidgetGenerator> _availableWidgets = new List<CoraWidgetGenerator>();
private readonly Dictionary<Type, CoraWidgetGenerator> _widgetGenerators = new Dictionary<Type, CoraWidgetGenerator>();

private readonly IServiceProvider _services;

private NuGet.Common.ILogger _nugetLogger;
Expand All @@ -61,11 +62,20 @@ public PackageService(IServiceProvider services)

public void RegisterWidgets(List<CoraWidgetGenerator> widgets)
{
_availableWidgets.AddRange(widgets);
widgets.ForEach(widget =>
{
_widgetGenerators.Add(widget.ContextType, widget);
});
}

public List<CoraWidgetGenerator> 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)
Expand All @@ -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()
Expand Down
35 changes: 35 additions & 0 deletions src/Apps/Corathing.Organizer/ViewModels/WidgetSettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

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<IPackageService>();
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)
{
Expand Down
18 changes: 1 addition & 17 deletions src/Apps/Corathing.Organizer/Views/OrganizerSettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -370,23 +370,7 @@
</ComboBox>
</ui:CardControl>

<ui:CardControl Margin="0,0,0,12"
Icon="{ui:SymbolIcon AlignSpaceEvenlyVertical20}">
<ui:CardControl.Header>
<ui:TextBlock Grid.Row="0"
FontTypography="Body"
Text="Navigation style" />
</ui:CardControl.Header>
<!--<ComboBox Grid.Column="1"
MinWidth="200"
SelectedIndex="{Binding CurrentApplicationNavigationStyle, Converter={StaticResource PaneDisplayModeToIndexConverter}, Mode=TwoWay}">
<ComboBoxItem Content="Left compact" />
<ComboBoxItem Content="Fluent" />
<ComboBoxItem Content="Top" />
<ComboBoxItem Content="Bottom" />
</ComboBox>-->
</ui:CardControl>

<!-- About -->
<ui:TextBlock Margin="0,16,0,8"
FontTypography="BodyStrong"
Text="About" />
Expand Down
164 changes: 161 additions & 3 deletions src/Apps/Corathing.Organizer/Views/WidgetSettingsView.xaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<Page x:Class="Corathing.Organizer.Views.WidgetSettingsView"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Corathing.Organizer.Views"
xmlns:viewmodels="clr-namespace:Corathing.Organizer.ViewModels"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:hosts="clr-namespace:Corathing.Dashboards.WPF.Controls;assembly=Corathing.Dashboards.WPF"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800"
Margin="16"
Title="WidgetSettingsView">
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Corathing.Organizer;component/Styles/CustomStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>

<DockPanel LastChildFill="True">
<StackPanel DockPanel.Dock="Top"
Expand All @@ -29,14 +37,164 @@
<ui:TextBlock Margin="16,0,0,0"
VerticalAlignment="Top"
FontTypography="Title"
Text="Manage Projects" />
Text="Setting Widget" />
</StackPanel>
<Separator DockPanel.Dock="Top" />

<DockPanel DockPanel.Dock="Left"
Margin="8"
Width="300">
<Border BorderThickness="1"
Background="#24242424"
BorderBrush="Black">
<hosts:WidgetHost Width="256"
Height="256"/>
</Border>
</DockPanel>

<ScrollViewer FocusVisualStyle="{x:Null}">

<StackPanel Margin="0,8,0,8"
<StackPanel Margin="24,8,16,8"
FocusVisualStyle="{x:Null}">

<!-- 기본 위젯 설정 -->
<!-- 1. 설정 버튼 숨기기 -->
<!-- 2. 유저 인증 -->

<ui:TextBlock Margin="0,16,0,8"
FontTypography="BodyStrong"
Text="기본 위젯 설정" />
<ui:CardExpander Margin="0,0,0,8"
Icon="{ui:SymbolIcon Folder24}"
ContentPadding="0">
<ui:CardExpander.Header>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:TextBlock Grid.Row="0"
Grid.Column="0"
FontTypography="Body"
Text="AAA" />
<ui:TextBlock Grid.Row="1"
Grid.Column="0"
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}"
Text="bbb" />
<TextBlock Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
Margin="0,0,16,0"
VerticalAlignment="Center"
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}"
Text="{Binding AppVersion, Mode=OneWay}" />
</Grid>
</ui:CardExpander.Header>
<StackPanel>

<ui:Anchor Margin="0"
Padding="16"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Background="Transparent"
BorderThickness="0,1,0,0"
CornerRadius="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:TextBlock Grid.Row="0"
Grid.Column="0"
FontTypography="Body"
Text="ccc" />
<ui:TextBlock Grid.Row="1"
Grid.Column="0"
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}"
Text="ddd" />
<CheckBox Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
IsChecked="{Binding UseGlobalConfiguration}" />
</Grid>
</ui:Anchor>

<ui:Anchor Margin="0"
Padding="16"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Background="Transparent"
BorderThickness="0,1,0,0"
CornerRadius="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:TextBlock Grid.Row="0"
Grid.Column="0"
FontTypography="Body"
Text="eee" />
<ui:TextBlock Grid.Row="1"
Grid.Column="0"
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}"
Text="fff" />
<!--<CheckBox Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
IsChecked="{Binding UseAppPathConfiguration}" />-->
</Grid>
</ui:Anchor>

<ui:Anchor Margin="0"
Padding="16"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Background="Transparent"
BorderThickness="0,1,0,0"
CornerRadius="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:TextBlock Grid.Row="0"
Grid.Column="0"
FontTypography="Body"
Text="ggg" />
<ui:TextBlock Grid.Row="1"
Grid.Column="0"
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}"
Text="hhh" />
<ui:Button Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
Style="{StaticResource IconButton24}"
Icon="{ui:SymbolIcon FolderOpen24}" />
</Grid>
</ui:Anchor>
</StackPanel>
</ui:CardExpander>




</StackPanel>
</ScrollViewer>
</DockPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public WidgetSettingsView(WidgetHost widgetHost)
InitializeComponent();

DataContext = ViewModel = App.Current.Services.GetService<WidgetSettingsViewModel>();
ViewModel.RegisterWidget(widgetHost);

Loaded += (s, e) =>
{
Expand Down
7 changes: 7 additions & 0 deletions src/Shared/Corathing.Contracts/Bases/WidgetContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Shared/Corathing.Contracts/Services/IPackageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public interface IPackageService
{
void RegisterWidgets(List<CoraWidgetGenerator> widgets);
List<CoraWidgetGenerator> GetAvailableWidgets();
bool TryGetWidgetGenerator(Type viewType, out CoraWidgetGenerator generator);

void LoadWidgetsFromDLL(string pathDLL);
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ protected override void ClearContainerForItemOverride(DependencyObject element,
/// <returns>The element that is used to display the given item.</returns>
protected override DependencyObject GetContainerForItemOverride()
{
return new WidgetHost { Id = Guid.NewGuid() };
return new WidgetHost { Id = Guid.NewGuid(), EditMode = EditMode };
}

/// <summary>
Expand Down
Loading

0 comments on commit 6afcc27

Please sign in to comment.