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-10-23 00:45:48 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
|
2020-10-23 00:45:48 +08:00
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
2020-04-18 06:25:08 +08:00
|
|
|
|
{
|
|
|
|
|
public class PowerPreviewViewModel : Observable
|
|
|
|
|
{
|
2020-09-24 04:20:32 +08:00
|
|
|
|
private const string ModuleName = PowerPreviewSettings.ModuleName;
|
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
|
|
|
|
|
2020-10-10 05:45:30 +08:00
|
|
|
|
private GeneralSettings GeneralSettingsConfig { get; set; }
|
|
|
|
|
|
|
|
|
|
public PowerPreviewViewModel(ISettingsRepository<PowerPreviewSettings> moduleSettingsRepository, ISettingsRepository<GeneralSettings> generalSettingsRepository, 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-09-24 04:20:32 +08:00
|
|
|
|
|
2020-10-10 05:45:30 +08:00
|
|
|
|
// To obtain the general Settings configurations of PowerToys
|
2020-10-20 04:32:05 +08:00
|
|
|
|
if (generalSettingsRepository == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(generalSettingsRepository));
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 05:45:30 +08:00
|
|
|
|
GeneralSettingsConfig = generalSettingsRepository.SettingsConfig;
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
// To obtain the PowerPreview settings if it exists.
|
|
|
|
|
// If the file does not exist, to create a new one and return the default settings configurations.
|
2020-10-20 04:32:05 +08:00
|
|
|
|
if (moduleSettingsRepository == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
Settings = moduleSettingsRepository.SettingsConfig;
|
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;
|
2022-01-26 04:02:10 +08:00
|
|
|
|
_monacoRenderIsEnabled = Settings.Properties.EnableMonacoPreview;
|
2022-03-26 01:29:33 +08:00
|
|
|
|
_monacoWrapText = Settings.Properties.EnableMonacoPreviewWordWrap;
|
2022-08-24 19:08:10 +08:00
|
|
|
|
_monacoPreviewTryFormat = Settings.Properties.MonacoPreviewTryFormat;
|
2021-08-27 05:43:26 +08:00
|
|
|
|
_pdfRenderIsEnabled = Settings.Properties.EnablePdfPreview;
|
2021-12-10 19:53:01 +08:00
|
|
|
|
_gcodeRenderIsEnabled = Settings.Properties.EnableGcodePreview;
|
2021-09-15 00:01:45 +08:00
|
|
|
|
_pdfThumbnailIsEnabled = Settings.Properties.EnablePdfThumbnail;
|
2021-12-10 19:53:01 +08:00
|
|
|
|
_gcodeThumbnailIsEnabled = Settings.Properties.EnableGcodeThumbnail;
|
2022-01-25 19:51:37 +08:00
|
|
|
|
_stlThumbnailIsEnabled = Settings.Properties.EnableStlThumbnail;
|
2022-08-24 04:45:27 +08:00
|
|
|
|
_stlThumbnailColor = Settings.Properties.StlThumbnailColor.Value;
|
2020-04-18 06:25:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 08:58:52 +08:00
|
|
|
|
private bool _svgRenderIsEnabled;
|
|
|
|
|
private bool _mdRenderIsEnabled;
|
2022-01-26 04:02:10 +08:00
|
|
|
|
private bool _monacoRenderIsEnabled;
|
2022-03-26 01:29:33 +08:00
|
|
|
|
private bool _monacoWrapText;
|
2022-08-24 19:08:10 +08:00
|
|
|
|
private bool _monacoPreviewTryFormat;
|
2021-08-27 05:43:26 +08:00
|
|
|
|
private bool _pdfRenderIsEnabled;
|
2021-12-10 19:53:01 +08:00
|
|
|
|
private bool _gcodeRenderIsEnabled;
|
2020-10-10 08:58:52 +08:00
|
|
|
|
private bool _svgThumbnailIsEnabled;
|
2021-09-15 00:01:45 +08:00
|
|
|
|
private bool _pdfThumbnailIsEnabled;
|
2021-12-10 19:53:01 +08:00
|
|
|
|
private bool _gcodeThumbnailIsEnabled;
|
2022-01-25 19:51:37 +08:00
|
|
|
|
private bool _stlThumbnailIsEnabled;
|
2022-08-24 04:45:27 +08:00
|
|
|
|
private string _stlThumbnailColor;
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 04:02:10 +08:00
|
|
|
|
public bool MonacoRenderIsEnabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _monacoRenderIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _monacoRenderIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_monacoRenderIsEnabled = value;
|
|
|
|
|
Settings.Properties.EnableMonacoPreview = value;
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-26 01:29:33 +08:00
|
|
|
|
public bool MonacoWrapText
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _monacoWrapText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_monacoWrapText != value)
|
|
|
|
|
{
|
|
|
|
|
_monacoWrapText = value;
|
|
|
|
|
Settings.Properties.EnableMonacoPreviewWordWrap = value;
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-24 19:08:10 +08:00
|
|
|
|
public bool MonacoPreviewTryFormat
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _monacoPreviewTryFormat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_monacoPreviewTryFormat != value)
|
|
|
|
|
{
|
|
|
|
|
_monacoPreviewTryFormat = value;
|
|
|
|
|
Settings.Properties.MonacoPreviewTryFormat = value;
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 05:43:26 +08:00
|
|
|
|
public bool PDFRenderIsEnabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _pdfRenderIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _pdfRenderIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_pdfRenderIsEnabled = value;
|
|
|
|
|
Settings.Properties.EnablePdfPreview = value;
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-15 00:01:45 +08:00
|
|
|
|
public bool PDFThumbnailIsEnabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _pdfThumbnailIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _pdfThumbnailIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_pdfThumbnailIsEnabled = value;
|
|
|
|
|
Settings.Properties.EnablePdfThumbnail = value;
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 19:53:01 +08:00
|
|
|
|
public bool GCODERenderIsEnabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _gcodeRenderIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _gcodeRenderIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_gcodeRenderIsEnabled = value;
|
|
|
|
|
Settings.Properties.EnableGcodePreview = value;
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GCODEThumbnailIsEnabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _gcodeThumbnailIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _gcodeThumbnailIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_gcodeThumbnailIsEnabled = value;
|
|
|
|
|
Settings.Properties.EnableGcodeThumbnail = value;
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 19:51:37 +08:00
|
|
|
|
public bool STLThumbnailIsEnabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _stlThumbnailIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _stlThumbnailIsEnabled)
|
|
|
|
|
{
|
|
|
|
|
_stlThumbnailIsEnabled = value;
|
|
|
|
|
Settings.Properties.EnableStlThumbnail = value;
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-24 04:45:27 +08:00
|
|
|
|
public string STLThumbnailColor
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _stlThumbnailColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _stlThumbnailColor)
|
|
|
|
|
{
|
|
|
|
|
_stlThumbnailColor = value;
|
|
|
|
|
Settings.Properties.StlThumbnailColor.Value = value;
|
|
|
|
|
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-10-10 05:45:30 +08:00
|
|
|
|
public bool IsElevated
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return GeneralSettingsConfig.IsElevated;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|