2020-04-18 06:25:08 +08:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
using System;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2020-08-18 04:10:56 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
|
2020-04-18 06:25:08 +08:00
|
|
|
|
{
|
|
|
|
|
public class PowerPreviewViewModel : Observable
|
|
|
|
|
{
|
2020-04-27 08:34:03 +08:00
|
|
|
|
private const string ModuleName = "File Explorer";
|
2020-04-18 06:25:08 +08:00
|
|
|
|
|
|
|
|
|
private PowerPreviewSettings Settings { get; set; }
|
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
private Func<string, int> SendConfigMSG { get; }
|
|
|
|
|
|
2020-08-20 06:59:10 +08:00
|
|
|
|
private string _settingsConfigFileFolder = string.Empty;
|
2020-08-18 04:10:56 +08:00
|
|
|
|
|
|
|
|
|
public PowerPreviewViewModel(Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
2020-04-18 06:25:08 +08:00
|
|
|
|
{
|
2020-08-18 04:10:56 +08:00
|
|
|
|
// Update Settings file folder:
|
2020-08-20 06:59:10 +08:00
|
|
|
|
_settingsConfigFileFolder = configFileSubfolder;
|
2020-08-18 04:10:56 +08:00
|
|
|
|
|
2020-04-18 06:25:08 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-08-18 04:10:56 +08:00
|
|
|
|
Settings = SettingsUtils.GetSettings<PowerPreviewSettings>(GetSettingsSubPath());
|
2020-04-18 06:25:08 +08:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
Settings = new PowerPreviewSettings();
|
2020-08-18 04:10:56 +08:00
|
|
|
|
SettingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
|
2020-04-18 06:25:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
// set the callback functions value to hangle outgoing IPC message.
|
|
|
|
|
SendConfigMSG = ipcMSGCallBackFunc;
|
|
|
|
|
|
2020-08-20 06:59:10 +08:00
|
|
|
|
_svgRenderIsEnabled = Settings.Properties.EnableSvgPreview;
|
|
|
|
|
_svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
|
|
|
|
|
_mdRenderIsEnabled = Settings.Properties.EnableMdPreview;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _svgRenderIsEnabled = false;
|
|
|
|
|
private bool _mdRenderIsEnabled = false;
|
2020-07-22 07:27:12 +08:00
|
|
|
|
private bool _svgThumbnailIsEnabled = false;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
|
2020-05-03 18:17:06 +08:00
|
|
|
|
public bool SVGRenderIsEnabled
|
2020-04-18 06:25:08 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _svgRenderIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _svgRenderIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_svgRenderIsEnabled = value;
|
2020-07-24 02:01:49 +08:00
|
|
|
|
Settings.Properties.EnableSvgPreview = value;
|
2020-07-22 07:27:12 +08:00
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SVGThumbnailIsEnabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _svgThumbnailIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _svgThumbnailIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_svgThumbnailIsEnabled = value;
|
2020-07-24 02:01:49 +08:00
|
|
|
|
Settings.Properties.EnableSvgThumbnail = value;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 18:17:06 +08:00
|
|
|
|
public bool MDRenderIsEnabled
|
2020-04-18 06:25:08 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _mdRenderIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _mdRenderIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_mdRenderIsEnabled = value;
|
2020-07-24 02:01:49 +08:00
|
|
|
|
Settings.Properties.EnableMdPreview = value;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
public string GetSettingsSubPath()
|
|
|
|
|
{
|
2020-08-20 06:59:10 +08:00
|
|
|
|
return _settingsConfigFileFolder + "\\" + ModuleName;
|
2020-08-18 04:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-18 06:25:08 +08:00
|
|
|
|
private void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
|
|
{
|
|
|
|
|
// Notify UI of property change
|
|
|
|
|
OnPropertyChanged(propertyName);
|
|
|
|
|
|
2020-08-18 04:10:56 +08:00
|
|
|
|
if (SendConfigMSG != null)
|
2020-04-18 06:25:08 +08:00
|
|
|
|
{
|
|
|
|
|
SndPowerPreviewSettings snd = new SndPowerPreviewSettings(Settings);
|
|
|
|
|
SndModuleSettings<SndPowerPreviewSettings> ipcMessage = new SndModuleSettings<SndPowerPreviewSettings>(snd);
|
2020-08-18 04:10:56 +08:00
|
|
|
|
SendConfigMSG(ipcMessage.ToJsonString());
|
2020-04-18 06:25:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|