Skip to content

Commit

Permalink
Update settings and states
Browse files Browse the repository at this point in the history
  • Loading branch information
dogzz9445 committed Jun 20, 2024
1 parent 279458d commit bfd9676
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 64 deletions.
32 changes: 6 additions & 26 deletions src/Apps/Corathing.Organizer/Services/AppStateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,9 @@ public async void UpdateProject(ProjectState project)
return;
}

if (_cachedAppDashboardState.Projects == null)
_cachedAppDashboardState.Projects = new Dictionary<Guid, ProjectState>();
_cachedAppDashboardState.UpdateProject(project);

_cachedAppDashboardState.Projects.ContainsKey(project.Id);
_cachedAppDashboardState.Projects[project.Id] = project;

await WrtieAppState();
await PendingWriteAppState();
}

public async void UpdateWorkflow(WorkflowState workflow)
Expand All @@ -186,13 +182,9 @@ public async void UpdateWorkflow(WorkflowState workflow)
return;
}

if (_cachedAppDashboardState.Workflows == null)
_cachedAppDashboardState.Workflows = new Dictionary<Guid, WorkflowState>();

_cachedAppDashboardState.Workflows.ContainsKey(workflow.Id);
_cachedAppDashboardState.Workflows[workflow.Id] = workflow;
_cachedAppDashboardState.UpdateWorkflow(workflow);

await WrtieAppState();
await PendingWriteAppState();
}

public async void UpdateWidget(WidgetState widget)
Expand All @@ -206,21 +198,9 @@ public async void UpdateWidget(WidgetState widget)
return;
}

if (_cachedAppDashboardState.Widgets == null)
_cachedAppDashboardState.Widgets = new Dictionary<Guid, WidgetState>();

_cachedAppDashboardState.Widgets.ContainsKey(widget.Id);
_cachedAppDashboardState.Widgets[widget.Id] = widget;

await WrtieAppState();
}

public void UpdateOrAdd(Guid id, object value)
{
}
_cachedAppDashboardState.UpdateWidget(widget);

public void UpdateOverwrite(Guid id, object value)
{
await PendingWriteAppState();
}

#region Private Methods
Expand Down
7 changes: 5 additions & 2 deletions src/Apps/Corathing.Organizer/ViewModels/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
using CommunityToolkit.Mvvm.Input;

using Corathing.Contracts.Bases;
using Corathing.Contracts.Bases.Interfaces;
using Corathing.Contracts.Entries;
using Corathing.Contracts.Services;

using Corathing.Dashboards.Bases;
using Corathing.Dashboards.WPF.Controls;
using Corathing.Organizer.Controls;
using Corathing.Organizer.Extensions;
Expand Down Expand Up @@ -270,7 +271,9 @@ public Task Start(IServiceProvider services)
Header = splitedMenuHeaders[i],
Command = new RelayCommand(() =>
{
SelectedProject.SelectedWorkflow.Widgets.Add(widget.CreateWidget());
var context = widget.CreateWidget();
context.Layout = WidgetLayoutUtils.Create(context);
SelectedProject.SelectedWorkflow.Widgets.Add(context);
}, () => true),
});
}
Expand Down
25 changes: 25 additions & 0 deletions src/Shared/Corathing.Contracts/Bases/AppDashboardState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,33 @@ public record StateRecord(string key, string value);

public class AppDashboardState
{
public Guid Id { get; set; }
public Dictionary<Guid, ProjectState> Projects { get; set; }
public Dictionary<Guid, WorkflowState> Workflows { get; set; }
public Dictionary<Guid, WidgetState> Widgets { get; set; }


public void UpdateProject(ProjectState project)
{
if (Projects == null)
Projects = new Dictionary<Guid, ProjectState>();

Projects[project.Id] = project;
}

public void UpdateWorkflow(WorkflowState workflow)
{
if (Workflows == null)
Workflows = new Dictionary<Guid, WorkflowState>();

Workflows[workflow.Id] = workflow;
}

public void UpdateWidget(WidgetState widget)
{
if (Widgets == null)
Widgets = new Dictionary<Guid, WidgetState>();

Widgets[widget.Id] = widget;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@

namespace Corathing.Contracts.Bases.Interfaces;

public interface IWidgetCoreState
{
}
18 changes: 16 additions & 2 deletions src/Shared/Corathing.Contracts/Bases/WidgetState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,31 @@

namespace Corathing.Contracts.Bases;

public interface IWidgetCoreState
{
string Name { get; }
string Title { get; }
bool VisibleTitle { get; }
}

public interface IWidgetState : IEntity
{
IWidgetCoreState CoreSettings { get; }
List<object> CustomSettings { get; }
object CustomSettings { get; }
WidgetContext Context { get; }
}

public class WidgetCoreState : IWidgetCoreState

Check failure on line 26 in src/Shared/Corathing.Contracts/Bases/WidgetState.cs

View workflow job for this annotation

GitHub Actions / build (x64)

The namespace 'Corathing.Contracts.Bases' already contains a definition for 'WidgetCoreState'

Check failure on line 26 in src/Shared/Corathing.Contracts/Bases/WidgetState.cs

View workflow job for this annotation

GitHub Actions / build (x64)

The namespace 'Corathing.Contracts.Bases' already contains a definition for 'WidgetCoreState'
{
public string Name { get; set; }
public string Title { get; set; }
public bool VisibleTitle { get; set; }
}

public class WidgetState : IWidgetState
{
public Guid Id { get; set; }
public IWidgetCoreState CoreSettings { get; set; }
public List<object> CustomSettings { get; set; }
public object CustomSettings { get; set; }
public WidgetContext Context { get; set; }
}
18 changes: 13 additions & 5 deletions src/Shared/Corathing.Contracts/DataContexts/WidgetContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public partial class WidgetContext : ObservableRecipient
private Guid _widgetId;
#endregion

#region 확정된 프로퍼티 건드리지 말기
[ObservableProperty]
private WidgetState? _state;
[ObservableProperty]
private WidgetLayout? _layout;
#endregion

#region 확정된 프로퍼티
[ObservableProperty]
private string _widgetTitle;
Expand All @@ -41,13 +48,9 @@ public partial class WidgetContext : ObservableRecipient
private bool? _isResizing;
[ObservableProperty]
private bool? _isEditing;
[ObservableProperty]
private WidgetLayout? _layout;

public WidgetContext()
{
WidgetTitle = "Widget";
VisibleTitle = true;
EditMode = true;

MinColumns = 2;
Expand All @@ -59,9 +62,14 @@ public WidgetContext()
IsEditing = false;
}

public WidgetContext(IServiceProvider services) : this()
public WidgetContext(IServiceProvider services, WidgetState state) : this()
{
_services = services;

WidgetId = state.Id;
State = state;
WidgetTitle = state.CoreSettings.Title;
VisibleTitle = state.CoreSettings.VisibleTitle;
}

public virtual void OnDestroy()
Expand Down
18 changes: 16 additions & 2 deletions src/Shared/Corathing.Contracts/Entries/CoraWidgetGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,23 @@ Type optionType
/// Creates the widget.
/// </summary>
/// <returns>WidgetBase.</returns>
public WidgetContext CreateWidget()
public WidgetContext CreateWidget(WidgetState? state = null)
{
return (WidgetContext)Activator.CreateInstance(ContextType, Services);
if (state == null)
{
state = CreateEmptyState();
}
var context = (WidgetContext)Activator.CreateInstance(ContextType, Services, state);
return context;
}

public WidgetState CreateEmptyState()
{
WidgetState state = new WidgetState();
state.Id = new Guid();
state.CoreSettings = new WidgetCoreState();
state.CustomSettings = Activator.CreateInstance(OptionType);
return state;
}

#endregion Public Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public static class AppDashboardStateFactory
public static AppDashboardState Create()
=> new AppDashboardState()
{
Id = new Guid(),
};
}
32 changes: 11 additions & 21 deletions src/Shared/Corathing.Dashboards.WPF/Controls/DashboardHost.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,27 +302,17 @@ protected override void PrepareContainerForItemOverride(DependencyObject element
// 여기서 WidgetHost의 Layout을 설정하고, WidgetHost의 위치를 설정해야 함
// 설정을 읽게 된다면 여기서 WidgetContext 의 정보는 설정으로부터 읽어져옴
var widgetLayout = widgetContext.Layout;
if (widgetLayout == null)
{
// 위젯이 처음 생성 됨
widgetContext.Layout = widgetLayout = WidgetLayoutUtils.Create(widgetHost.Id, widgetContext);

// 초기 위치 및 는
// Set min/max dimensions of host so it isn't allowed to grow any larger or smaller
widgetHost.MinHeight = (WidgetMinimumHeight * widgetLayout.H) - widgetHost.Margin.Top - widgetHost.Margin.Bottom;
widgetHost.MinWidth = (WidgetMinimumWidth * widgetLayout.W) - widgetHost.Margin.Left - widgetHost.Margin.Right;
widgetHost.Height = (_widgetSize.Height * widgetLayout.H) - widgetHost.Margin.Top - widgetHost.Margin.Bottom;
widgetHost.Width = (_widgetSize.Width * widgetLayout.W) - widgetHost.Margin.Left - widgetHost.Margin.Right;
}
else
{
// 위젯이 탭컨트롤 변경 혹은 설정에 의해서 읽어짐
widgetHost.Id = widgetLayout.WidgetStateId;
widgetHost.MinHeight = (WidgetMinimumHeight * widgetLayout.H) - widgetHost.Margin.Top - widgetHost.Margin.Bottom;
widgetHost.MinWidth = (WidgetMinimumWidth * widgetLayout.W) - widgetHost.Margin.Left - widgetHost.Margin.Right;
widgetHost.Height = (_widgetSize.Height * widgetLayout.H) - widgetHost.Margin.Top - widgetHost.Margin.Bottom;
widgetHost.Width = (_widgetSize.Width * widgetLayout.W) - widgetHost.Margin.Left - widgetHost.Margin.Right;
}

Debug.Assert(widgetLayout != null, nameof(widgetLayout) + " != null");

// 초기 위치
// 위젯이 탭컨트롤 변경 혹은 설정에 의해서 읽어짐
// Set min/max dimensions of host so it isn't allowed to grow any larger or smaller
widgetHost.Id = widgetLayout.WidgetStateId;
widgetHost.MinHeight = (WidgetMinimumHeight * widgetLayout.H) - widgetHost.Margin.Top - widgetHost.Margin.Bottom;
widgetHost.MinWidth = (WidgetMinimumWidth * widgetLayout.W) - widgetHost.Margin.Left - widgetHost.Margin.Right;
widgetHost.Height = (_widgetSize.Height * widgetLayout.H) - widgetHost.Margin.Top - widgetHost.Margin.Bottom;
widgetHost.Width = (_widgetSize.Width * widgetLayout.W) - widgetHost.Margin.Left - widgetHost.Margin.Right;

// Subscribe to the widgets drag started and add the widget
// to the _widgetHosts to keep tabs on it
Expand Down
15 changes: 15 additions & 0 deletions src/Shared/Corathing.Dashboards/Bases/WidgetLayoutUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ public static WidgetLayout Create(Guid hostId, WidgetContext context) =>
H = context.MinRows ?? 2,
}
};

public static WidgetLayout Create(WidgetContext context) =>
new WidgetLayout()
{
Id = Guid.NewGuid(),
WidgetStateId = context.WidgetId,
Rect = new WidgetLayoutRect()
{
X = 0,
Y = 0,
W = context.MinColumns ?? 2,
H = context.MinRows ?? 2,
}
};

#endregion

#region 02. Update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ public partial class FileOpenerWidgetViewModel : WidgetContext
/// Initializes a new instance of the <see cref="OneByOneViewModel"/> class.
/// </summary>
public FileOpenerWidgetViewModel(
IServiceProvider services)
: base(services)
IServiceProvider services, WidgetState state)
: base(services, state)
{
ILocalizationService localizationService = services.GetService<ILocalizationService>();
localizationService.Provide("Corathing.Widgets.Basics.FileOpenerName", value => WidgetTitle = value);
VisibleTitle = true;
}
}

Expand Down

0 comments on commit bfd9676

Please sign in to comment.