From 4949c17065112dd38c3789fd1a2611a5af135073 Mon Sep 17 00:00:00 2001 From: Anton Kasyanov Date: Sun, 5 Jun 2016 01:34:44 +0300 Subject: [PATCH] Update layout management system to use JSON --- .../Configuration/ApplicationConfiguration.cs | 89 ++++- .../{WindowProperties.cs => ClientLayout.cs} | 2 +- .../IApplicationConfiguration.cs | 14 +- Eve-O-Preview/Eve-O-Preview.csproj | 6 +- .../Presentation/IThumbnailManager.cs | 1 + Eve-O-Preview/Presentation/MainPresenter.cs | 11 +- .../Presentation/ThumbnailManager.cs | 357 ++---------------- .../UI/Implementation/MainForm.Designer.cs | 22 +- Eve-O-Preview/UI/Implementation/MainForm.cs | 6 +- Eve-O-Preview/UI/Implementation/MainForm.resx | 4 +- Eve-O-Preview/UI/Interface/IMainView.cs | 2 +- 11 files changed, 162 insertions(+), 352 deletions(-) rename Eve-O-Preview/Configuration/{WindowProperties.cs => ClientLayout.cs} (80%) diff --git a/Eve-O-Preview/Configuration/ApplicationConfiguration.cs b/Eve-O-Preview/Configuration/ApplicationConfiguration.cs index a5dbeca..a022909 100644 --- a/Eve-O-Preview/Configuration/ApplicationConfiguration.cs +++ b/Eve-O-Preview/Configuration/ApplicationConfiguration.cs @@ -1,5 +1,10 @@ -namespace EveOPreview.Configuration +using System.Collections.Generic; +using System.Drawing; +using Newtonsoft.Json; + +namespace EveOPreview.Configuration { + // TODO Add Save and Load to this class public class ApplicationConfiguration : IApplicationConfiguration { public ApplicationConfiguration() @@ -10,11 +15,11 @@ this.ThumbnailsOpacity = 0.5; - this.EnableClientsLocationTracking = false; + this.EnableClientLayoutTracking = false; this.HideActiveClientThumbnail = false; this.ShowThumbnailsAlwaysOnTop = true; this.HideThumbnailsOnLostFocus = false; - this.EnablePerClientThumbnailsLayouts = false; + this.EnablePerClientThumbnailLayouts = false; this.SyncThumbnailsSize = true; this.ThumbnailsWidth = 250; @@ -26,6 +31,10 @@ this.ShowThumbnailOverlays = true; this.ShowThumbnailFrames = true; + + this.PerClientLayout = new Dictionary>(); + this.FlatLayout = new Dictionary(); + this.ClientLayout = new Dictionary(); } public bool MinimizeToTray { get; set; } @@ -33,11 +42,11 @@ public double ThumbnailsOpacity { get; set; } - public bool EnableClientsLocationTracking { get; set; } + public bool EnableClientLayoutTracking { get; set; } public bool HideActiveClientThumbnail { get; set; } public bool ShowThumbnailsAlwaysOnTop { get; set; } public bool HideThumbnailsOnLostFocus { get; set; } - public bool EnablePerClientThumbnailsLayouts { get; set; } + public bool EnablePerClientThumbnailLayouts { get; set; } public bool SyncThumbnailsSize { get; set; } public int ThumbnailsWidth { get; set; } @@ -49,5 +58,75 @@ public bool ShowThumbnailOverlays { get; set; } public bool ShowThumbnailFrames { get; set; } + + [JsonProperty] + private Dictionary> PerClientLayout { get; set; } + [JsonProperty] + private Dictionary FlatLayout { get; set; } + [JsonProperty] + private Dictionary ClientLayout { get; set; } + + public Point GetThumbnailLocation(string currentClient, string activeClient, Point defaultLocation) + { + Dictionary layoutSource = null; + + if (this.EnablePerClientThumbnailLayouts) + { + if (!string.IsNullOrEmpty(activeClient)) + { + this.PerClientLayout.TryGetValue(activeClient, out layoutSource); + } + } + else + { + layoutSource = this.FlatLayout; + } + + if (layoutSource == null) + { + return defaultLocation; + } + + Point location; + return layoutSource.TryGetValue(currentClient, out location) ? location : defaultLocation; + } + + public void SetThumbnailLocation(string currentClient, string activeClient, Point location) + { + Dictionary layoutSource; + + if (this.EnablePerClientThumbnailLayouts) + { + if (string.IsNullOrEmpty(activeClient)) + { + return; + } + + if (!this.PerClientLayout.TryGetValue(activeClient, out layoutSource)) + { + layoutSource = new Dictionary(); + this.PerClientLayout[activeClient] = layoutSource; + } + } + else + { + layoutSource = this.FlatLayout; + } + + layoutSource[currentClient] = location; + } + + public ClientLayout GetClientLayout(string currentClient) + { + ClientLayout layout; + this.ClientLayout.TryGetValue(currentClient, out layout); + + return layout; + } + + public void SetClientLayout(string currentClient, ClientLayout layout) + { + this.ClientLayout[currentClient] = layout; + } } } \ No newline at end of file diff --git a/Eve-O-Preview/Configuration/WindowProperties.cs b/Eve-O-Preview/Configuration/ClientLayout.cs similarity index 80% rename from Eve-O-Preview/Configuration/WindowProperties.cs rename to Eve-O-Preview/Configuration/ClientLayout.cs index 1f1034d..b3db46c 100644 --- a/Eve-O-Preview/Configuration/WindowProperties.cs +++ b/Eve-O-Preview/Configuration/ClientLayout.cs @@ -1,6 +1,6 @@ namespace EveOPreview.Configuration { - public class WindowProperties + public class ClientLayout { public int X { get; set; } public int Y { get; set; } diff --git a/Eve-O-Preview/Configuration/IApplicationConfiguration.cs b/Eve-O-Preview/Configuration/IApplicationConfiguration.cs index 759990b..f58df75 100644 --- a/Eve-O-Preview/Configuration/IApplicationConfiguration.cs +++ b/Eve-O-Preview/Configuration/IApplicationConfiguration.cs @@ -1,4 +1,6 @@ -namespace EveOPreview.Configuration +using System.Drawing; + +namespace EveOPreview.Configuration { public interface IApplicationConfiguration { @@ -7,11 +9,11 @@ double ThumbnailsOpacity { get; set; } - bool EnableClientsLocationTracking { get; set; } + bool EnableClientLayoutTracking { get; set; } bool HideActiveClientThumbnail { get; set; } bool ShowThumbnailsAlwaysOnTop { get; set; } bool HideThumbnailsOnLostFocus { get; set; } - bool EnablePerClientThumbnailsLayouts { get; set; } + bool EnablePerClientThumbnailLayouts { get; set; } bool SyncThumbnailsSize { get; set; } int ThumbnailsWidth { get; set; } @@ -23,5 +25,11 @@ bool ShowThumbnailOverlays { get; set; } bool ShowThumbnailFrames { get; set; } + + Point GetThumbnailLocation(string currentClient, string activeClient, Point defaultLocation); + void SetThumbnailLocation(string currentClient, string activeClient, Point location); + + ClientLayout GetClientLayout(string currentClient); + void SetClientLayout(string currentClient, ClientLayout layout); } } \ No newline at end of file diff --git a/Eve-O-Preview/Eve-O-Preview.csproj b/Eve-O-Preview/Eve-O-Preview.csproj index c4afe66..9fcdf29 100644 --- a/Eve-O-Preview/Eve-O-Preview.csproj +++ b/Eve-O-Preview/Eve-O-Preview.csproj @@ -123,7 +123,7 @@ - + @@ -219,9 +219,7 @@ - - - +