Persist the 'Hide thumbnail' option value

This commit is contained in:
Anton Kasyanov
2018-02-25 22:22:52 +02:00
parent 37d14446a9
commit 295976a97b
10 changed files with 35 additions and 41 deletions

View File

@@ -3,9 +3,9 @@ using System.Drawing;
using System.Windows.Forms;
using Newtonsoft.Json;
namespace EveOPreview.Configuration
namespace EveOPreview.Configuration.Omplementation
{
class ThumbnailConfiguration : IThumbnailConfiguration
sealed class ThumbnailConfiguration : IThumbnailConfiguration
{
public ThumbnailConfiguration()
{
@@ -39,6 +39,7 @@ namespace EveOPreview.Configuration
this.FlatLayout = new Dictionary<string, Point>();
this.ClientLayout = new Dictionary<string, ClientLayout>();
this.ClientHotkey = new Dictionary<string, string>();
this.DisableThumbnail = new Dictionary<string, bool>();
}
public bool MinimizeToTray { get; set; }
@@ -79,6 +80,8 @@ namespace EveOPreview.Configuration
private Dictionary<string, ClientLayout> ClientLayout { get; set; }
[JsonProperty]
private Dictionary<string, string> ClientHotkey { get; set; }
[JsonProperty]
private Dictionary<string, bool> DisableThumbnail { get; set; }
public Point GetDefaultThumbnailLocation()
{
@@ -168,6 +171,16 @@ namespace EveOPreview.Configuration
this.ClientHotkey[currentClient] = (new KeysConverter()).ConvertToInvariantString(hotkey);
}
public bool IsThumbnailDisabled(string currentClient)
{
return this.DisableThumbnail.TryGetValue(currentClient, out bool isDisabled) && isDisabled;
}
public void ToggleThumbnail(string currentClient, bool isDisabled)
{
this.DisableThumbnail[currentClient] = isDisabled;
}
/// <summary>
/// Applies restrictions to different parameters of the config
/// </summary>

View File

@@ -41,6 +41,9 @@ namespace EveOPreview.Configuration
Keys GetClientHotkey(string currentClient);
void SetClientHotkey(string currentClient, Keys hotkey);
bool IsThumbnailDisabled(string currentClient);
void ToggleThumbnail(string currentClient, bool isDisabled);
void ApplyRestrictions();
}
}

View File

@@ -111,7 +111,7 @@
<Compile Include="Configuration\AppConfig.cs" />
<Compile Include="Configuration\ConfigurationStorage.cs" />
<Compile Include="Configuration\IAppConfig.cs" />
<Compile Include="Configuration\IThumbnailConfiguration.cs" />
<Compile Include="Configuration\Interface\IThumbnailConfiguration.cs" />
<Compile Include="Configuration\ZoomAnchor.cs" />
<Compile Include="Mediator\Handlers\Configuration\SaveConfigurationHandler.cs" />
<Compile Include="Mediator\Handlers\Thumbnails\ThumbnailFrameSettingsUpdatedHandler.cs" />
@@ -157,7 +157,7 @@
<Compile Include="ApplicationBase\IView.cs" />
<Compile Include="View\Interface\IThumbnailDescription.cs" />
<Compile Include="View\Interface\ViewZoomAnchor.cs" />
<Compile Include="Configuration\ThumbnailConfiguration.cs" />
<Compile Include="Configuration\Implementation\ThumbnailConfiguration.cs" />
<Compile Include="Hotkeys\HotkeyHandler.cs" />
<Compile Include="Hotkeys\HotkeyHandlerNativeMethods.cs" />
<Compile Include="View\Implementation\MainForm.cs">

View File

@@ -199,14 +199,16 @@ namespace EveOPreview.Presenters
private IThumbnailDescription CreateThumbnailDescription(string title)
{
// TODO Read here persisted value for the IsDisabled parameter
return new ThumbnailDescription(title, false);
bool isDisabled = this._configuration.IsThumbnailDisabled(title);
return new ThumbnailDescription(title, isDisabled);
}
private void UpdateThumbnailState(String title)
{
// TODO This setting doesn't work atm
//this._thumbnailManager.SetThumbnailState(thumbnailId, this._thumbnailDescriptionViews[thumbnailId].IsDisabled);
if (this._descriptionsCache.TryGetValue(title, out IThumbnailDescription description))
{
this._configuration.ToggleThumbnail(title, description.IsDisabled);
}
}
public void UpdateThumbnailSize(Size size)

View File

@@ -68,29 +68,12 @@ namespace EveOPreview.Services
this._thumbnailUpdateTimer.Stop();
}
public void SetThumbnailState(IntPtr thumbnailId, bool hideAlways)
{
if (!this._thumbnailViews.TryGetValue(thumbnailId, out IThumbnailView thumbnail))
{
return;
}
thumbnail.IsEnabled = !hideAlways;
}
public void UpdateThumbnailsSize()
{
this.InternalSetThumbnailsSize(this._configuration.ThumbnailSize);
this.SetThumbnailsSize(this._configuration.ThumbnailSize);
}
public async void SetThumbnailsSize(Size size)
{
this.InternalSetThumbnailsSize(size);
await this._mediator.Publish(new ThumbnailActiveSizeUpdated(size));
}
private void InternalSetThumbnailsSize(Size size)
private void SetThumbnailsSize(Size size)
{
this.DisableViewEvents();
@@ -115,7 +98,7 @@ namespace EveOPreview.Services
{
IThumbnailView view = entry.Value;
if (hideAllThumbnails || !view.IsEnabled)
if (hideAllThumbnails || this._configuration.IsThumbnailDisabled(view.Title))
{
if (view.IsActive)
{
@@ -204,7 +187,6 @@ namespace EveOPreview.Services
foreach (IProcessInfo process in addedProcesses)
{
IThumbnailView view = this._thumbnailViewFactory.Create(process.Handle, process.Title, this._configuration.ThumbnailSize);
view.IsEnabled = true;
view.IsOverlayEnabled = this._configuration.ShowThumbnailOverlays;
view.SetFrames(this._configuration.ShowThumbnailFrames);
// Max/Min size limitations should be set AFTER the frames are disabled
@@ -368,7 +350,7 @@ namespace EveOPreview.Services
this.RefreshThumbnails();
}
private void ThumbnailViewResized(IntPtr id)
private async void ThumbnailViewResized(IntPtr id)
{
if (this._ignoreViewEvents)
{
@@ -380,6 +362,8 @@ namespace EveOPreview.Services
this.SetThumbnailsSize(view.ThumbnailSize);
view.Refresh(false);
await this._mediator.Publish(new ThumbnailActiveSizeUpdated(view.ThumbnailSize));
}
private async void ThumbnailViewMoved(IntPtr id)

View File

@@ -1,15 +1,10 @@
using System;
using System.Drawing;
namespace EveOPreview.Services
namespace EveOPreview.Services
{
public interface IThumbnailManager
{
void Start();
void Stop();
void SetThumbnailState(IntPtr thumbnailId, bool hideAlways);
void SetThumbnailsSize(Size size);
void UpdateThumbnailsSize();
void UpdateThumbnailFrames();
}

View File

@@ -708,6 +708,7 @@ namespace EveOPreview.View
//
this.ThumbnailsList.BackColor = System.Drawing.SystemColors.Window;
this.ThumbnailsList.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ThumbnailsList.CheckOnClick = true;
this.ThumbnailsList.Dock = System.Windows.Forms.DockStyle.Bottom;
this.ThumbnailsList.FormattingEnabled = true;
this.ThumbnailsList.IntegralHeight = false;

View File

@@ -211,7 +211,7 @@ namespace EveOPreview.View
foreach (IThumbnailDescription view in thumbnails)
{
this.ThumbnailsList.Items.Add(view);
this.ThumbnailsList.SetItemChecked(this.ThumbnailsList.Items.Add(view), view.IsDisabled);
}
this.ThumbnailsList.EndUpdate();

View File

@@ -36,7 +36,6 @@ namespace EveOPreview.View
{
this._windowManager = windowManager;
this.IsEnabled = true;
this.IsActive = false;
this.IsOverlayEnabled = false;
@@ -68,8 +67,6 @@ namespace EveOPreview.View
}
}
public bool IsEnabled { get; set; }
public bool IsActive { get; set; }
public bool IsOverlayEnabled { get; set; }

View File

@@ -9,7 +9,6 @@ namespace EveOPreview.View
IntPtr Id { get; set; }
string Title { get; set; }
bool IsEnabled { get; set; }
bool IsActive { get; set; }
Point ThumbnailLocation { get; set; }
Size ThumbnailSize { get; set; }