Move MatterControl source code into a subdirectory
This commit is contained in:
parent
2c6e34243a
commit
70af2d9ae8
2007 changed files with 13 additions and 8 deletions
|
|
@ -0,0 +1,287 @@
|
|||
/*
|
||||
Copyright (c) 2020, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using MatterHackers.MatterControl.SettingsManagement;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public static class ApplicationSettingsKey
|
||||
{
|
||||
public const string ApplicationDisplayMode = nameof(ApplicationDisplayMode);
|
||||
public const string DesktopPosition = nameof(DesktopPosition);
|
||||
public const string HardwareHasCamera = nameof(HardwareHasCamera);
|
||||
public const string HideGCodeWarning = nameof(HideGCodeWarning);
|
||||
public const string MainWindowMaximized = nameof(MainWindowMaximized);
|
||||
public const string SuppressAuthPanel = nameof(SuppressAuthPanel);
|
||||
public const string WindowSize = nameof(WindowSize);
|
||||
}
|
||||
|
||||
public class ApplicationSettings
|
||||
{
|
||||
public static string ValidFileExtensions { get; } = ".stl,.obj,.3mf,.amf,.mcx";
|
||||
|
||||
public static string LibraryFilterFileExtensions { get; } = ValidFileExtensions + ",.gcode";
|
||||
|
||||
public static string OpenDesignFileParams { get; } = "STL, AMF, OBJ, 3MF, MCX, TTF, OTF|*.stl;*.amf;*.obj;*.mcx;*.ttf;*.otf";
|
||||
|
||||
private static ApplicationSettings globalInstance = null;
|
||||
|
||||
public Dictionary<string, SystemSetting> SettingsDictionary { get; set; }
|
||||
|
||||
public static ApplicationSettings Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (globalInstance == null)
|
||||
{
|
||||
globalInstance = new ApplicationSettings();
|
||||
globalInstance.LoadData();
|
||||
}
|
||||
|
||||
return globalInstance;
|
||||
}
|
||||
}
|
||||
|
||||
private string oemName = null;
|
||||
|
||||
public bool IsTouchScreen
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.get(ApplicationSettingsKey.ApplicationDisplayMode) == "touchscreen";
|
||||
}
|
||||
}
|
||||
|
||||
public string GetOEMName()
|
||||
{
|
||||
if (oemName == null)
|
||||
{
|
||||
string[] printerWhiteListStrings = OemSettings.Instance.PrinterWhiteList.ToArray();
|
||||
if (printerWhiteListStrings.Length == 0
|
||||
|| printerWhiteListStrings.Length > 1)
|
||||
{
|
||||
oemName = "MatterHackers";
|
||||
}
|
||||
else
|
||||
{
|
||||
oemName = printerWhiteListStrings[0];
|
||||
}
|
||||
}
|
||||
|
||||
return oemName;
|
||||
}
|
||||
|
||||
private string runningTokensKeyName = $"{ApplicationController.EnvironmentName}ClientToken_RunningTokens";
|
||||
|
||||
private string claimedClientToken = null;
|
||||
|
||||
public string GetClientToken()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(claimedClientToken))
|
||||
{
|
||||
return claimedClientToken;
|
||||
}
|
||||
|
||||
// This code should only run once per application and get cached in a local property (claimedClientToken)
|
||||
List<string> allocatedClientTokens = GetAllocatedClientTokens();
|
||||
HashSet<string> runningClientTokens = GetRunningClientTokens();
|
||||
|
||||
if (ApplicationController.ApplicationInstanceCount == 1
|
||||
&& !string.IsNullOrEmpty(AuthenticationData.Instance.ActiveClientToken))
|
||||
{
|
||||
claimedClientToken = AuthenticationData.Instance.ActiveClientToken;
|
||||
}
|
||||
else
|
||||
{
|
||||
var availableTokens = allocatedClientTokens.Except(runningClientTokens);
|
||||
claimedClientToken = availableTokens.FirstOrDefault();
|
||||
}
|
||||
|
||||
// Claim ClientToken
|
||||
if (!string.IsNullOrEmpty(claimedClientToken))
|
||||
{
|
||||
runningClientTokens.Add(claimedClientToken);
|
||||
}
|
||||
|
||||
SetRunningClientTokens(runningClientTokens);
|
||||
|
||||
return claimedClientToken;
|
||||
}
|
||||
|
||||
public void ReleaseClientToken()
|
||||
{
|
||||
// Release ClientToken
|
||||
HashSet<string> runningClientTokens = GetRunningClientTokens();
|
||||
runningClientTokens.Remove(claimedClientToken);
|
||||
|
||||
SetRunningClientTokens(runningClientTokens);
|
||||
}
|
||||
|
||||
private List<string> GetAllocatedClientTokens()
|
||||
{
|
||||
List<string> allocatedClientTokens = new List<string>();
|
||||
string clientToken;
|
||||
int allocatedCount = 0;
|
||||
do
|
||||
{
|
||||
string keyName = $"{ApplicationController.EnvironmentName}ClientToken";
|
||||
|
||||
if (allocatedCount > 0)
|
||||
{
|
||||
keyName += "_" + allocatedCount;
|
||||
}
|
||||
|
||||
clientToken = get(keyName);
|
||||
if (!string.IsNullOrEmpty(clientToken))
|
||||
{
|
||||
allocatedClientTokens.Add(clientToken);
|
||||
}
|
||||
|
||||
allocatedCount++;
|
||||
}
|
||||
while (!string.IsNullOrEmpty(clientToken));
|
||||
|
||||
return allocatedClientTokens;
|
||||
}
|
||||
|
||||
private HashSet<string> GetRunningClientTokens()
|
||||
{
|
||||
var runningClientTokens = new HashSet<string>();
|
||||
|
||||
// Only deserialize if greater than one
|
||||
if (ApplicationController.ApplicationInstanceCount > 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
string json = get(runningTokensKeyName);
|
||||
if (!string.IsNullOrEmpty(json))
|
||||
{
|
||||
runningClientTokens = JsonConvert.DeserializeObject<HashSet<string>>(json);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
return runningClientTokens;
|
||||
}
|
||||
|
||||
private void SetRunningClientTokens(HashSet<string> runningClientTokens)
|
||||
{
|
||||
set(runningTokensKeyName, JsonConvert.SerializeObject(runningClientTokens));
|
||||
}
|
||||
|
||||
public void SetClientToken(string clientToken)
|
||||
{
|
||||
// Clear credentials anytime we are allocated a new client token
|
||||
AuthenticationData.Instance.ClearActiveSession();
|
||||
|
||||
int allocatedCount = 0;
|
||||
|
||||
bool firstEmptySlot = false;
|
||||
|
||||
do
|
||||
{
|
||||
string keyName = $"{ApplicationController.EnvironmentName}ClientToken";
|
||||
|
||||
if (allocatedCount > 0)
|
||||
{
|
||||
keyName += "_" + allocatedCount;
|
||||
}
|
||||
|
||||
firstEmptySlot = string.IsNullOrEmpty(get(keyName));
|
||||
if (firstEmptySlot)
|
||||
{
|
||||
set(keyName, clientToken);
|
||||
}
|
||||
|
||||
allocatedCount++;
|
||||
|
||||
}
|
||||
while (!firstEmptySlot);
|
||||
}
|
||||
|
||||
public string get(string key)
|
||||
{
|
||||
string result;
|
||||
if (SettingsDictionary == null)
|
||||
{
|
||||
globalInstance.LoadData();
|
||||
}
|
||||
|
||||
if (SettingsDictionary.ContainsKey(key))
|
||||
{
|
||||
result = SettingsDictionary[key].Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void set(string key, string value)
|
||||
{
|
||||
SystemSetting setting;
|
||||
if (SettingsDictionary.ContainsKey(key))
|
||||
{
|
||||
setting = SettingsDictionary[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
setting = new SystemSetting();
|
||||
setting.Name = key;
|
||||
|
||||
SettingsDictionary[key] = setting;
|
||||
}
|
||||
|
||||
setting.Value = value;
|
||||
setting.Commit();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
SettingsDictionary = new Dictionary<string, SystemSetting>();
|
||||
foreach (SystemSetting s in GetApplicationSettings())
|
||||
{
|
||||
SettingsDictionary[s.Name] = s;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<SystemSetting> GetApplicationSettings()
|
||||
{
|
||||
// Retrieve SystemSettings from the Datastore
|
||||
return Datastore.Instance.dbSQLite.Query<SystemSetting>("SELECT * FROM SystemSetting;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,572 @@
|
|||
/*
|
||||
Copyright (c) 2018, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.ImageProcessing;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.ConfigurationPage;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public partial class ApplicationSettingsPage : DialogPage
|
||||
{
|
||||
public ApplicationSettingsPage()
|
||||
: base("Close".Localize())
|
||||
{
|
||||
this.AlwaysOnTopOfMain = true;
|
||||
this.WindowTitle = this.HeaderText = "MatterControl " + "Settings".Localize();
|
||||
this.WindowSize = new Vector2(700 * GuiWidget.DeviceScale, 600 * GuiWidget.DeviceScale);
|
||||
|
||||
contentRow.Padding = theme.DefaultContainerPadding;
|
||||
contentRow.Padding = 0;
|
||||
contentRow.BackgroundColor = Color.Transparent;
|
||||
GuiWidget settingsColumn;
|
||||
|
||||
{
|
||||
var settingsAreaScrollBox = new ScrollableWidget(true);
|
||||
settingsAreaScrollBox.ScrollArea.HAnchor |= HAnchor.Stretch;
|
||||
settingsAreaScrollBox.AnchorAll();
|
||||
settingsAreaScrollBox.BackgroundColor = theme.MinimalShade;
|
||||
contentRow.AddChild(settingsAreaScrollBox);
|
||||
|
||||
settingsColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
||||
{
|
||||
HAnchor = HAnchor.MaxFitOrStretch
|
||||
};
|
||||
|
||||
settingsAreaScrollBox.AddChild(settingsColumn);
|
||||
}
|
||||
|
||||
AddGeneralPanel(settingsColumn);
|
||||
|
||||
AddUsserOptionsPanel(settingsColumn);
|
||||
|
||||
AddAdvancedPanel(settingsColumn);
|
||||
|
||||
// Enforce consistent SectionWidget spacing and last child borders
|
||||
foreach (var section in settingsColumn.Children<SectionWidget>())
|
||||
{
|
||||
section.Margin = new BorderDouble(0, 10, 0, 0);
|
||||
|
||||
if (section.ContentPanel.Children.LastOrDefault() is SettingsItem lastRow)
|
||||
{
|
||||
// If we're in a contentPanel that has SettingsItems...
|
||||
|
||||
// Clear the last items bottom border
|
||||
lastRow.Border = lastRow.Border.Clone(bottom: 0);
|
||||
|
||||
// Set a common margin on the parent container
|
||||
section.ContentPanel.Margin = new BorderDouble(2, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddGeneralPanel(GuiWidget settingsColumn)
|
||||
{
|
||||
var generalPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Fit,
|
||||
};
|
||||
|
||||
var configureIcon = StaticData.Instance.LoadIcon("fa-cog_16.png", 16, 16).GrayToColor(theme.TextColor);
|
||||
|
||||
var generalSection = new SectionWidget("General".Localize(), generalPanel, theme, expandingContent: false)
|
||||
{
|
||||
Name = "General Section",
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Fit,
|
||||
};
|
||||
settingsColumn.AddChild(generalSection);
|
||||
|
||||
theme.ApplyBoxStyle(generalSection);
|
||||
|
||||
// Print Notifications
|
||||
var configureNotificationsButton = new ThemedIconButton(configureIcon, theme)
|
||||
{
|
||||
Name = "Configure Notification Settings Button",
|
||||
ToolTipText = "Configure Notifications".Localize(),
|
||||
Margin = new BorderDouble(left: 6),
|
||||
VAnchor = VAnchor.Center
|
||||
};
|
||||
configureNotificationsButton.Click += (s, e) =>
|
||||
{
|
||||
if (ApplicationController.ChangeToPrintNotification != null)
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
ApplicationController.ChangeToPrintNotification(this.DialogWindow);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.AddSettingsRow(
|
||||
new SettingsItem(
|
||||
"Notifications".Localize(),
|
||||
theme,
|
||||
new SettingsItem.ToggleSwitchConfig()
|
||||
{
|
||||
Checked = UserSettings.Instance.get(UserSettingsKey.PrintNotificationsEnabled) == "true",
|
||||
ToggleAction = (itemChecked) =>
|
||||
{
|
||||
UserSettings.Instance.set(UserSettingsKey.PrintNotificationsEnabled, itemChecked ? "true" : "false");
|
||||
}
|
||||
},
|
||||
configureNotificationsButton,
|
||||
StaticData.Instance.LoadIcon("notify-24x24.png", 16, 16).GrayToColor(theme.TextColor)),
|
||||
generalPanel);
|
||||
|
||||
// LanguageControl
|
||||
var languageSelector = new LanguageSelector(theme);
|
||||
languageSelector.SelectionChanged += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
string languageCode = languageSelector.SelectedValue;
|
||||
if (languageCode != UserSettings.Instance.get(UserSettingsKey.Language))
|
||||
{
|
||||
UserSettings.Instance.set(UserSettingsKey.Language, languageCode);
|
||||
|
||||
if (languageCode == "L10N")
|
||||
{
|
||||
#if DEBUG
|
||||
AppContext.Platform.GenerateLocalizationValidationFile();
|
||||
#endif
|
||||
}
|
||||
|
||||
ApplicationController.Instance.ResetTranslationMap();
|
||||
ApplicationController.Instance.ReloadAll().ConfigureAwait(false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.AddSettingsRow(new SettingsItem("Language".Localize(), languageSelector, theme), generalPanel);
|
||||
|
||||
// ThumbnailRendering
|
||||
var thumbnailsModeDropList = new MHDropDownList("", theme, maxHeight: 200 * GuiWidget.DeviceScale);
|
||||
thumbnailsModeDropList.AddItem("Flat".Localize(), "orthographic");
|
||||
thumbnailsModeDropList.AddItem("3D".Localize(), "raytraced");
|
||||
|
||||
thumbnailsModeDropList.SelectedValue = UserSettings.Instance.ThumbnailRenderingMode;
|
||||
thumbnailsModeDropList.SelectionChanged += (s, e) =>
|
||||
{
|
||||
string thumbnailRenderingMode = thumbnailsModeDropList.SelectedValue;
|
||||
if (thumbnailRenderingMode != UserSettings.Instance.ThumbnailRenderingMode)
|
||||
{
|
||||
UserSettings.Instance.ThumbnailRenderingMode = thumbnailRenderingMode;
|
||||
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
// Ask if the user they would like to rebuild their thumbnails
|
||||
StyledMessageBox.ShowMessageBox(
|
||||
(bool rebuildThumbnails) =>
|
||||
{
|
||||
if (rebuildThumbnails)
|
||||
{
|
||||
string[] thumbnails = new string[]
|
||||
{
|
||||
ApplicationController.CacheablePath(
|
||||
Path.Combine("Thumbnails", "Content"), ""),
|
||||
ApplicationController.CacheablePath(
|
||||
Path.Combine("Thumbnails", "Library"), "")
|
||||
};
|
||||
foreach (var directoryToRemove in thumbnails)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(directoryToRemove))
|
||||
{
|
||||
Directory.Delete(directoryToRemove, true);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
GuiWidget.BreakInDebugger();
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(directoryToRemove);
|
||||
}
|
||||
|
||||
ApplicationController.Instance.Library.NotifyContainerChanged();
|
||||
}
|
||||
},
|
||||
"You are switching to a different thumbnail rendering mode. If you want, your current thumbnails can be removed and recreated in the new style. You can switch back and forth at any time. There will be some processing overhead while the new thumbnails are created.\n\nDo you want to rebuild your existing thumbnails now?".Localize(),
|
||||
"Rebuild Thumbnails Now".Localize(),
|
||||
StyledMessageBox.MessageType.YES_NO,
|
||||
"Rebuild".Localize());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.AddSettingsRow(
|
||||
new SettingsItem(
|
||||
"Thumbnails".Localize(),
|
||||
thumbnailsModeDropList,
|
||||
theme),
|
||||
generalPanel);
|
||||
|
||||
// TextSize
|
||||
if (!double.TryParse(UserSettings.Instance.get(UserSettingsKey.ApplicationTextSize), out double currentTextSize))
|
||||
{
|
||||
currentTextSize = 1.0;
|
||||
}
|
||||
|
||||
double sliderThumbWidth = 10 * GuiWidget.DeviceScale;
|
||||
double sliderWidth = 100 * GuiWidget.DeviceScale;
|
||||
var textSizeSlider = new SolidSlider(default(Vector2), sliderThumbWidth, theme, .7, 2.5)
|
||||
{
|
||||
Name = "Text Size Slider",
|
||||
Margin = new BorderDouble(5, 0),
|
||||
Value = currentTextSize,
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Center,
|
||||
TotalWidthInPixels = sliderWidth,
|
||||
};
|
||||
theme.ApplySliderStyle(textSizeSlider);
|
||||
|
||||
var optionalContainer = new FlowLayoutWidget()
|
||||
{
|
||||
VAnchor = VAnchor.Center | VAnchor.Fit,
|
||||
HAnchor = HAnchor.Fit
|
||||
};
|
||||
|
||||
TextWidget sectionLabel = null;
|
||||
|
||||
var textSizeApplyButton = new ThemedTextButton("Apply".Localize(), theme)
|
||||
{
|
||||
VAnchor = VAnchor.Center,
|
||||
BackgroundColor = theme.SlightShade,
|
||||
Visible = false,
|
||||
Margin = new BorderDouble(right: 6)
|
||||
};
|
||||
textSizeApplyButton.Click += (s, e) => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
GuiWidget.DeviceScale = textSizeSlider.Value;
|
||||
ApplicationController.Instance.ReloadAll().ConfigureAwait(false);
|
||||
});
|
||||
optionalContainer.AddChild(textSizeApplyButton);
|
||||
|
||||
textSizeSlider.ValueChanged += (s, e) =>
|
||||
{
|
||||
double textSizeNew = textSizeSlider.Value;
|
||||
UserSettings.Instance.set(UserSettingsKey.ApplicationTextSize, textSizeNew.ToString("0.0"));
|
||||
sectionLabel.Text = "Text Size".Localize() + $" : {textSizeNew:0.0}";
|
||||
textSizeApplyButton.Visible = textSizeNew != currentTextSize;
|
||||
};
|
||||
|
||||
var textSizeRow = new SettingsItem(
|
||||
"Text Size".Localize() + $" : {currentTextSize:0.0}",
|
||||
textSizeSlider,
|
||||
theme,
|
||||
optionalContainer);
|
||||
|
||||
sectionLabel = textSizeRow.Children<TextWidget>().FirstOrDefault();
|
||||
|
||||
this.AddSettingsRow(textSizeRow, generalPanel);
|
||||
|
||||
var themeSection = CreateThemePanel(theme);
|
||||
settingsColumn.AddChild(themeSection);
|
||||
theme.ApplyBoxStyle(themeSection);
|
||||
}
|
||||
|
||||
private void AddAdvancedPanel(GuiWidget settingsColumn)
|
||||
{
|
||||
var advancedPanel = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
||||
|
||||
var advancedSection = new SectionWidget("Advanced".Localize(), advancedPanel, theme, serializationKey: "ApplicationSettings-Advanced", expanded: false)
|
||||
{
|
||||
Name = "Advanced Section",
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Fit,
|
||||
Margin = 0
|
||||
};
|
||||
settingsColumn.AddChild(advancedSection);
|
||||
|
||||
theme.ApplyBoxStyle(advancedSection);
|
||||
|
||||
// Touch Screen Mode
|
||||
this.AddSettingsRow(
|
||||
new SettingsItem(
|
||||
"Touch Screen Mode".Localize(),
|
||||
theme,
|
||||
new SettingsItem.ToggleSwitchConfig()
|
||||
{
|
||||
Checked = ApplicationSettings.Instance.get(ApplicationSettingsKey.ApplicationDisplayMode) == "touchscreen",
|
||||
ToggleAction = (itemChecked) =>
|
||||
{
|
||||
string displayMode = itemChecked ? "touchscreen" : "responsive";
|
||||
if (displayMode != ApplicationSettings.Instance.get(ApplicationSettingsKey.ApplicationDisplayMode))
|
||||
{
|
||||
ApplicationSettings.Instance.set(ApplicationSettingsKey.ApplicationDisplayMode, displayMode);
|
||||
UiThread.RunOnIdle(() => ApplicationController.Instance.ReloadAll().ConfigureAwait(false));
|
||||
}
|
||||
}
|
||||
}),
|
||||
advancedPanel);
|
||||
|
||||
AddUserBoolToggle(advancedPanel,
|
||||
"Enable Socketeer Client".Localize(),
|
||||
UserSettingsKey.ApplicationUseSocketeer,
|
||||
true,
|
||||
false);
|
||||
|
||||
AddUserBoolToggle(advancedPanel,
|
||||
"Utilize High Res Monitors".Localize(),
|
||||
UserSettingsKey.ApplicationUseHeigResDisplays,
|
||||
true,
|
||||
false);
|
||||
|
||||
var openCacheButton = new ThemedIconButton(StaticData.Instance.LoadIcon("fa-link_16.png", 16, 16).GrayToColor(theme.TextColor), theme)
|
||||
{
|
||||
ToolTipText = "Open Folder".Localize(),
|
||||
};
|
||||
openCacheButton.Click += (s, e) => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
Process.Start(ApplicationDataStorage.ApplicationUserDataPath);
|
||||
});
|
||||
|
||||
this.AddSettingsRow(
|
||||
new SettingsItem(
|
||||
"Application Storage".Localize(),
|
||||
openCacheButton,
|
||||
theme),
|
||||
advancedPanel);
|
||||
|
||||
var clearCacheButton = new ThemedHoverIconButton(StaticData.Instance.LoadIcon("remove.png", 16, 16).GrayToColor(theme.TextColor), theme)
|
||||
{
|
||||
ToolTipText = "Clear Cache".Localize(),
|
||||
};
|
||||
clearCacheButton.Click += (s, e) => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
CacheDirectory.DeleteCacheData();
|
||||
});
|
||||
|
||||
this.AddSettingsRow(
|
||||
new SettingsItem(
|
||||
"Application Cache".Localize(),
|
||||
clearCacheButton,
|
||||
theme),
|
||||
advancedPanel);
|
||||
|
||||
#if DEBUG
|
||||
var configureIcon = StaticData.Instance.LoadIcon("fa-cog_16.png", 16, 16).GrayToColor(theme.TextColor);
|
||||
|
||||
var configurePluginsButton = new ThemedIconButton(configureIcon, theme)
|
||||
{
|
||||
ToolTipText = "Configure Plugins".Localize(),
|
||||
Margin = 0
|
||||
};
|
||||
configurePluginsButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
DialogWindow.Show<PluginsPage>();
|
||||
});
|
||||
};
|
||||
|
||||
this.AddSettingsRow(
|
||||
new SettingsItem(
|
||||
"Plugins".Localize(),
|
||||
configurePluginsButton,
|
||||
theme),
|
||||
advancedPanel);
|
||||
#endif
|
||||
|
||||
var gitHubPat = UserSettings.Instance.get("GitHubPat");
|
||||
if (gitHubPat == null)
|
||||
{
|
||||
gitHubPat = "";
|
||||
}
|
||||
var accessToken = new ThemedTextEditWidget(gitHubPat, theme, pixelWidth: 350, messageWhenEmptyAndNotSelected: "Enter Person Access Token".Localize())
|
||||
{
|
||||
HAnchor = HAnchor.Absolute,
|
||||
Margin = new BorderDouble(5),
|
||||
Name = "GitHubPat Edit Field"
|
||||
};
|
||||
accessToken.ActualTextEditWidget.EnterPressed += (s, e) =>
|
||||
{
|
||||
UserSettings.Instance.set("GitHubPat", accessToken.ActualTextEditWidget.Text);
|
||||
};
|
||||
accessToken.Closed += (s, e) =>
|
||||
{
|
||||
UserSettings.Instance.set("GitHubPat", accessToken.ActualTextEditWidget.Text);
|
||||
};
|
||||
this.AddSettingsRow(
|
||||
new SettingsItem(
|
||||
"GitHub Personal Access Token".Localize(),
|
||||
accessToken,
|
||||
theme)
|
||||
{
|
||||
ToolTipText = "This is used to increase the number of downloads allowed when browsing GitHub repositories".Localize(),
|
||||
},
|
||||
advancedPanel);
|
||||
|
||||
advancedPanel.Children<SettingsItem>().First().Border = new BorderDouble(0, 1);
|
||||
}
|
||||
|
||||
private void AddUsserOptionsPanel(GuiWidget settingsColumn)
|
||||
{
|
||||
var optionsPanel = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
||||
|
||||
var optionsSection = new SectionWidget("Options".Localize(), optionsPanel, theme, serializationKey: "ApplicationSettings-Options", expanded: false)
|
||||
{
|
||||
Name = "Options Section",
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Fit,
|
||||
Margin = 0
|
||||
};
|
||||
settingsColumn.AddChild(optionsSection);
|
||||
|
||||
theme.ApplyBoxStyle(optionsSection);
|
||||
|
||||
AddUserBoolToggle(optionsPanel,
|
||||
"Show Ratings Dialog After Print".Localize(),
|
||||
UserSettingsKey.CollectPrintHistoryData,
|
||||
false,
|
||||
false);
|
||||
|
||||
AddUserBoolToggle(optionsPanel,
|
||||
"Show Welcome Message".Localize(),
|
||||
UserSettingsKey.ShownWelcomeMessage,
|
||||
false,
|
||||
false);
|
||||
|
||||
optionsPanel.Children<SettingsItem>().First().Border = new BorderDouble(0, 1);
|
||||
}
|
||||
|
||||
private void AddUserBoolToggle(FlowLayoutWidget panelToAddTo, string title, string boolKey, bool requiresRestart, bool reloadAll)
|
||||
{
|
||||
this.AddSettingsRow(
|
||||
new SettingsItem(
|
||||
title,
|
||||
theme,
|
||||
new SettingsItem.ToggleSwitchConfig()
|
||||
{
|
||||
Checked = UserSettings.Instance.get(boolKey) != "false",
|
||||
ToggleAction = (itemChecked) =>
|
||||
{
|
||||
string boolValue = itemChecked ? "true" : "false";
|
||||
if (boolValue != UserSettings.Instance.get(boolKey))
|
||||
{
|
||||
UserSettings.Instance.set(boolKey, boolValue);
|
||||
if (requiresRestart)
|
||||
{
|
||||
StyledMessageBox.ShowMessageBox(
|
||||
"To apply settings changes you need to restart MatterControl.".Localize(),
|
||||
"Restart Required".Localize());
|
||||
}
|
||||
|
||||
if (reloadAll)
|
||||
{
|
||||
UiThread.RunOnIdle(() => ApplicationController.Instance.ReloadAll().ConfigureAwait(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
panelToAddTo);
|
||||
}
|
||||
|
||||
private void AddApplicationBoolToggle(FlowLayoutWidget advancedPanel, string title, string boolKey, bool requiresRestart, bool reloadAll)
|
||||
{
|
||||
this.AddSettingsRow(
|
||||
new SettingsItem(
|
||||
title,
|
||||
theme,
|
||||
new SettingsItem.ToggleSwitchConfig()
|
||||
{
|
||||
Checked = ApplicationSettings.Instance.get(boolKey) == "true",
|
||||
ToggleAction = (itemChecked) =>
|
||||
{
|
||||
string boolValue = itemChecked ? "true" : "false";
|
||||
if (boolValue != UserSettings.Instance.get(boolKey))
|
||||
{
|
||||
ApplicationSettings.Instance.set(boolKey, boolValue);
|
||||
if (requiresRestart)
|
||||
{
|
||||
StyledMessageBox.ShowMessageBox(
|
||||
"To finish changing your monitor settings you need to restart MatterControl. If after changing your fonts are too small you can adjust Text Size.".Localize(),
|
||||
"Restart Required".Localize());
|
||||
}
|
||||
|
||||
if (reloadAll)
|
||||
{
|
||||
UiThread.RunOnIdle(() => ApplicationController.Instance.ReloadAll().ConfigureAwait(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
advancedPanel);
|
||||
}
|
||||
|
||||
public static SectionWidget CreateThemePanel(ThemeConfig theme)
|
||||
{
|
||||
var accentButtons = new ThemeColorPanel.AccentColorsWidget(AppContext.ThemeSet, 16)
|
||||
{
|
||||
HAnchor = HAnchor.Fit,
|
||||
VAnchor = VAnchor.Center | VAnchor.Fit,
|
||||
Margin = new BorderDouble(right: theme.DefaultContainerPadding)
|
||||
};
|
||||
|
||||
var themeColorPanel = new ThemeColorPanel(theme, accentButtons)
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
Margin = new BorderDouble(10, 10, 10, 2)
|
||||
};
|
||||
|
||||
accentButtons.ThemeColorPanel = themeColorPanel;
|
||||
|
||||
var themeSection = new SectionWidget("Theme".Localize(), themeColorPanel, theme, accentButtons, expanded: true, expandingContent: false)
|
||||
{
|
||||
Name = "Theme Section",
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Fit,
|
||||
Margin = 0
|
||||
};
|
||||
|
||||
themeSection.SetNonExpandableIcon(StaticData.Instance.LoadIcon("theme.png", 16, 16));
|
||||
|
||||
return themeSection;
|
||||
}
|
||||
|
||||
private void AddSettingsRow(GuiWidget widget, GuiWidget container)
|
||||
{
|
||||
container.AddChild(widget);
|
||||
widget.Padding = widget.Padding.Clone(right: 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
293
original/MatterControlLib/SettingsManagement/OemSettings.cs
Normal file
293
original/MatterControlLib/SettingsManagement/OemSettings.cs
Normal file
|
|
@ -0,0 +1,293 @@
|
|||
/*
|
||||
Copyright (c) 2019, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Agg.VertexSource;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MatterHackers.MatterControl.SettingsManagement
|
||||
{
|
||||
public class OemSettings
|
||||
{
|
||||
private static OemSettings instance = null;
|
||||
|
||||
public static OemSettings Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
string oemSettings = StaticData.Instance.ReadAllText(Path.Combine("OEMSettings", "Settings.json"));
|
||||
instance = JsonConvert.DeserializeObject<OemSettings>(oemSettings) as OemSettings;
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseSimpleModeByDefault = false;
|
||||
|
||||
public string ThemeColor = "";
|
||||
|
||||
public string AffiliateCode = "";
|
||||
|
||||
public string WindowTitleExtra = "";
|
||||
|
||||
public bool ShowShopButton = true;
|
||||
|
||||
public bool DesignToolsOnly = false;
|
||||
|
||||
public bool CheckForUpdatesOnFirstRun = false;
|
||||
|
||||
public string UnregisteredProductName { get; set; } = "MatterControl";
|
||||
public string RegisteredProductName { get; set; } = "MatterControl Pro";
|
||||
|
||||
public List<string> PrinterWhiteList { get; private set; } = new List<string>();
|
||||
|
||||
public List<ManufacturerNameMapping> ManufacturerNameMappings { get; set; }
|
||||
|
||||
public ImageBuffer GetIcon(string oemName, ThemeConfig theme)
|
||||
{
|
||||
var size = (int)(16 * GuiWidget.DeviceScale);
|
||||
var imageBuffer = new ImageBuffer(size, size);
|
||||
|
||||
string oemUrl = ApplicationController.Instance.GetFavIconUrl(oemName);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(oemUrl))
|
||||
{
|
||||
WebCache.RetrieveImageAsync(imageBuffer, oemUrl, scaleToImageX: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
var graphics = imageBuffer.NewGraphics2D();
|
||||
graphics.Clear(AppContext.Theme.SlightShade);
|
||||
}
|
||||
|
||||
if (theme.IsDarkTheme)
|
||||
{
|
||||
// put the icon on a light background
|
||||
var background = new ImageBuffer(size, size);
|
||||
background.NewGraphics2D().Render(new RoundedRect(background.GetBoundingRect(), 1), theme.TextColor);
|
||||
background.NewGraphics2D().Render(imageBuffer, 0, 0);
|
||||
imageBuffer.CopyFrom(background);
|
||||
}
|
||||
|
||||
return imageBuffer;
|
||||
}
|
||||
|
||||
internal void SetManufacturers(IEnumerable<KeyValuePair<string, string>> unorderedManufacturers, List<string> whitelist = null)
|
||||
{
|
||||
// Sort manufacturers by name
|
||||
var manufacturers = new List<KeyValuePair<string, string>>();
|
||||
var otherInfo = new KeyValuePair<string, string>(null, null);
|
||||
|
||||
foreach (var printer in unorderedManufacturers.OrderBy(k => k.Value))
|
||||
{
|
||||
if (printer.Value == "Other")
|
||||
{
|
||||
otherInfo = printer;
|
||||
}
|
||||
else
|
||||
{
|
||||
manufacturers.Add(printer);
|
||||
}
|
||||
}
|
||||
|
||||
if (otherInfo.Key != null)
|
||||
{
|
||||
// add it at the end
|
||||
manufacturers.Add(otherInfo);
|
||||
}
|
||||
|
||||
if (whitelist != null)
|
||||
{
|
||||
this.PrinterWhiteList = whitelist;
|
||||
}
|
||||
|
||||
// Apply whitelist
|
||||
var whiteListedItems = manufacturers?.Where(keyValue => PrinterWhiteList.Contains(keyValue.Key));
|
||||
|
||||
if (whiteListedItems == null
|
||||
|| whiteListedItems.Count() == 0)
|
||||
{
|
||||
// No whitelist means all items
|
||||
whiteListedItems = manufacturers;
|
||||
}
|
||||
|
||||
var newItems = new List<KeyValuePair<string, string>>();
|
||||
|
||||
// Apply manufacturer name mappings
|
||||
foreach (var keyValue in whiteListedItems)
|
||||
{
|
||||
string labelText = keyValue.Value;
|
||||
|
||||
// Override the manufacturer name if a manufacturerNameMappings exists
|
||||
string mappedName = ManufacturerNameMappings.Where(m => m.NameOnDisk == keyValue.Key).FirstOrDefault()?.NameOnDisk;
|
||||
if (!string.IsNullOrEmpty(mappedName))
|
||||
{
|
||||
labelText = mappedName;
|
||||
}
|
||||
|
||||
newItems.Add(new KeyValuePair<string, string>(keyValue.Key, labelText));
|
||||
}
|
||||
|
||||
AllOems = newItems;
|
||||
}
|
||||
|
||||
public List<KeyValuePair<string, string>> AllOems { get; private set; }
|
||||
|
||||
public OemProfileDictionary OemProfiles { get; set; }
|
||||
|
||||
public Dictionary<string, string> OemUrls { get; }
|
||||
|
||||
public Dictionary<string, StorePrinterID> OemPrinters { get; }
|
||||
|
||||
[OnDeserialized]
|
||||
private void Deserialized(StreamingContext context)
|
||||
{
|
||||
// Load local OemProfile content during initial startup
|
||||
OemProfiles = this.LoadOemProfiles();
|
||||
|
||||
var manufacturesList = OemProfiles.Keys.ToDictionary(oem => oem);
|
||||
SetManufacturers(manufacturesList);
|
||||
}
|
||||
|
||||
private OemProfileDictionary LoadOemProfiles()
|
||||
{
|
||||
string cachePath = ApplicationController.CacheablePath("public-profiles", "oemprofiles.json");
|
||||
|
||||
// Load data from cache or fall back to stale StaticData content
|
||||
string json = File.Exists(cachePath) ? File.ReadAllText(cachePath) : null;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
// If empty, purge the cache file and fall back to StaticData
|
||||
File.Delete(cachePath);
|
||||
|
||||
json = StaticData.Instance.ReadAllText(Path.Combine("Profiles", "oemprofiles.json"));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<OemProfileDictionary>(json);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// If json parse fails, purge the cache file and fall back to StaticData
|
||||
File.Delete(cachePath);
|
||||
|
||||
json = StaticData.Instance.ReadAllText(Path.Combine("Profiles", "oemprofiles.json"));
|
||||
return JsonConvert.DeserializeObject<OemProfileDictionary>(json);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ReloadOemProfiles()
|
||||
{
|
||||
// In public builds this won't be assigned to and we should exit
|
||||
if (ApplicationController.GetPublicProfileList == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await ApplicationController.LoadCacheableAsync<OemProfileDictionary>(
|
||||
"oemprofiles.json",
|
||||
"public-profiles",
|
||||
async () =>
|
||||
{
|
||||
var result = await ApplicationController.GetPublicProfileList();
|
||||
if (result != null)
|
||||
{
|
||||
// Refresh the in memory instance any time the server responds with updated content - caller will serialize
|
||||
OemProfiles = result;
|
||||
|
||||
SetManufacturers(result.Keys.ToDictionary(oem => oem));
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
await DownloadMissingProfiles();
|
||||
}
|
||||
|
||||
private async Task DownloadMissingProfiles()
|
||||
{
|
||||
int index = 0;
|
||||
foreach (string oem in OemProfiles.Keys)
|
||||
{
|
||||
string cacheScope = Path.Combine("public-profiles", oem);
|
||||
|
||||
index++;
|
||||
foreach (var model in OemProfiles[oem].Keys)
|
||||
{
|
||||
var publicDevice = OemProfiles[oem][model];
|
||||
string cachePath = ApplicationController.CacheablePath(cacheScope, publicDevice.CacheKey);
|
||||
if (!File.Exists(cachePath))
|
||||
{
|
||||
await Task.Delay(20000);
|
||||
await ProfileManager.LoadOemSettingsAsync(publicDevice, oem, model);
|
||||
|
||||
if (ApplicationController.Instance.ApplicationExiting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private OemSettings()
|
||||
{
|
||||
this.ManufacturerNameMappings = new List<ManufacturerNameMapping>();
|
||||
this.OemUrls = JsonConvert.DeserializeObject<Dictionary<string, string>>(StaticData.Instance.ReadAllText(Path.Combine("OEMSettings", "OEMUrls.json")));
|
||||
this.OemPrinters = JsonConvert.DeserializeObject<Dictionary<string, StorePrinterID>>(StaticData.Instance.ReadAllText(Path.Combine("OEMSettings", "Printers.json")));
|
||||
}
|
||||
}
|
||||
|
||||
public class StorePrinterID
|
||||
{
|
||||
public string SID { get; set; }
|
||||
|
||||
public string AltInfoUrl { get; set; }
|
||||
}
|
||||
|
||||
public class ManufacturerNameMapping
|
||||
{
|
||||
public string NameOnDisk { get; set; }
|
||||
|
||||
public string NameToDisplay { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,217 @@
|
|||
/*
|
||||
Copyright (c) 2018, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System.Linq;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.ConfigurationPage;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.SettingsManagement;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public partial class UpdateSettingsPage : DialogPage
|
||||
{
|
||||
private PrinterConfig printer;
|
||||
|
||||
public UpdateSettingsPage(PrinterConfig printer)
|
||||
: base("Close".Localize())
|
||||
{
|
||||
this.printer = printer;
|
||||
this.AlwaysOnTopOfMain = true;
|
||||
this.WindowTitle = this.HeaderText = "Update Settings".Localize();
|
||||
this.WindowSize = new Vector2(700 * GuiWidget.DeviceScale, 600 * GuiWidget.DeviceScale);
|
||||
|
||||
contentRow.Padding = theme.DefaultContainerPadding;
|
||||
contentRow.Padding = 0;
|
||||
contentRow.BackgroundColor = Color.Transparent;
|
||||
|
||||
AddAllContent();
|
||||
}
|
||||
|
||||
private void AddAllContent()
|
||||
{
|
||||
contentRow.CloseChildren();
|
||||
|
||||
GuiWidget settingsColumn;
|
||||
|
||||
var settingsAreaScrollBox = new ScrollableWidget(true);
|
||||
settingsAreaScrollBox.ScrollArea.HAnchor |= HAnchor.Stretch;
|
||||
settingsAreaScrollBox.AnchorAll();
|
||||
settingsAreaScrollBox.BackgroundColor = theme.MinimalShade;
|
||||
contentRow.AddChild(settingsAreaScrollBox);
|
||||
|
||||
settingsColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
||||
{
|
||||
HAnchor = HAnchor.MaxFitOrStretch
|
||||
};
|
||||
|
||||
settingsAreaScrollBox.AddChild(settingsColumn);
|
||||
|
||||
if (ProfileManager.GetOemSettingsNeedingUpdate(printer).Any())
|
||||
{
|
||||
AddUpgradeInfoPanel(settingsColumn);
|
||||
}
|
||||
else
|
||||
{
|
||||
settingsColumn.AddChild(new WrappedTextWidget("No setting currently need to be updated.".Localize(), pointSize: 11)
|
||||
{
|
||||
Margin = new BorderDouble(5),
|
||||
TextColor = theme.TextColor
|
||||
});
|
||||
}
|
||||
|
||||
// Enforce consistent SectionWidget spacing and last child borders
|
||||
foreach (var section in settingsColumn.Children<SectionWidget>())
|
||||
{
|
||||
section.Margin = new BorderDouble(0, 10, 0, 0);
|
||||
|
||||
if (section.ContentPanel.Children.LastOrDefault() is SettingsItem lastRow)
|
||||
{
|
||||
// If we're in a contentPanel that has SettingsItems...
|
||||
|
||||
// Clear the last items bottom border
|
||||
lastRow.Border = lastRow.Border.Clone(bottom: 0);
|
||||
|
||||
// Set a common margin on the parent container
|
||||
section.ContentPanel.Margin = new BorderDouble(2, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void AddUpgradeInfoPanel(GuiWidget generalPanel)
|
||||
{
|
||||
var make = printer.Settings.GetValue(SettingsKey.make);
|
||||
var model = printer.Settings.GetValue(SettingsKey.model);
|
||||
var message = $"The default settings for the {make} {model} have been updated.";
|
||||
message += "\n" + "Below you can find a list of each setting that has changed.".Localize();
|
||||
message += "\n" + "Updating a default setting will not change any override that you have applied.".Localize();
|
||||
generalPanel.AddChild(new WrappedTextWidget(message, pointSize: 11)
|
||||
{
|
||||
Margin = new BorderDouble(5, 15),
|
||||
TextColor = theme.TextColor
|
||||
});
|
||||
|
||||
int tabIndex = 0;
|
||||
|
||||
var serverOemSettings = await ProfileManager.LoadOemSettingsAsync(OemSettings.Instance.OemProfiles[make][model],
|
||||
make,
|
||||
model);
|
||||
|
||||
var oemPrinter = new PrinterConfig(serverOemSettings);
|
||||
|
||||
foreach (var setting in ProfileManager.GetOemSettingsNeedingUpdate(printer))
|
||||
{
|
||||
void AddSetting(PrinterConfig printer, string description, string key, Color overlay)
|
||||
{
|
||||
generalPanel.AddChild(new TextWidget(description, pointSize: 11)
|
||||
{
|
||||
// HAnchor = HAnchor.Center,
|
||||
Margin = new BorderDouble(5),
|
||||
TextColor = theme.TextColor
|
||||
});
|
||||
|
||||
var under = new GuiWidget()
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Fit
|
||||
};
|
||||
var topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
||||
{
|
||||
HAnchor = HAnchor.Stretch
|
||||
};
|
||||
|
||||
var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.OEMSettings);
|
||||
|
||||
topToBottom.AddChild(SliceSettingsTabView.CreateItemRow(
|
||||
PrinterSettings.SettingsData[key],
|
||||
settingsContext,
|
||||
printer,
|
||||
theme,
|
||||
ref tabIndex));
|
||||
var cover = new GuiWidget()
|
||||
{
|
||||
BackgroundColor = overlay,
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Stretch
|
||||
};
|
||||
generalPanel.AddChild(under).AddChild(topToBottom);
|
||||
under.AddChild(cover);
|
||||
}
|
||||
|
||||
if (PrinterSettings.SettingsData.ContainsKey(setting.key))
|
||||
{
|
||||
var settingData = PrinterSettings.SettingsData[setting.key];
|
||||
|
||||
var currentText = "Current Default".Localize();
|
||||
var group = settingData.OrganizerGroup;
|
||||
var category = group.Category;
|
||||
|
||||
currentText += ": " + category.Name + " > " + group.Name + " > " + settingData.PresentationName;
|
||||
|
||||
AddSetting(printer, currentText, setting.key, theme.SlightShade);
|
||||
AddSetting(oemPrinter, "Will be updated to:".Localize(), setting.key, Color.Transparent);
|
||||
|
||||
var buttonContainer = new FlowLayoutWidget(FlowDirection.RightToLeft)
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
Margin = new BorderDouble(0, 25, 0, 3),
|
||||
Border = new BorderDouble(0, 1, 0, 0),
|
||||
BorderColor = theme.MinimalShade,
|
||||
};
|
||||
|
||||
generalPanel.AddChild(buttonContainer);
|
||||
var updateButton = new ThemedTextButton("Update Setting".Localize(), theme)
|
||||
{
|
||||
Margin = new BorderDouble(0, 3, 20, 0),
|
||||
Name = setting.key + " Update",
|
||||
};
|
||||
|
||||
theme.ApplyPrimaryActionStyle(updateButton);
|
||||
|
||||
buttonContainer.AddChild(updateButton);
|
||||
|
||||
updateButton.Click += (s, e) =>
|
||||
{
|
||||
var scrollAmount = this.contentRow.Descendants<ScrollableWidget>().First().ScrollPositionFromTop;
|
||||
printer.Settings.SetValue(setting.key, setting.newValue, printer.Settings.OemLayer);
|
||||
AddAllContent();
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
this.contentRow.Descendants<ScrollableWidget>().First().ScrollPositionFromTop = scrollAmount;
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
309
original/MatterControlLib/SettingsManagement/UserSettings.cs
Normal file
309
original/MatterControlLib/SettingsManagement/UserSettings.cs
Normal file
|
|
@ -0,0 +1,309 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using g3;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public static class UserSettingsKey
|
||||
{
|
||||
public const string ActiveThemeName = nameof(ActiveThemeName);
|
||||
public const string AfterPrintFinishedPlaySound = nameof(AfterPrintFinishedPlaySound);
|
||||
public const string AfterPrintFinishedSendEmail = nameof(AfterPrintFinishedSendEmail);
|
||||
public const string AfterPrintFinishedSendTextMessage = nameof(AfterPrintFinishedSendTextMessage);
|
||||
public const string ApplicationUseHeigResDisplays = nameof(ApplicationUseHeigResDisplays);
|
||||
public const string ApplicationUseSocketeer = nameof(ApplicationUseSocketeer);
|
||||
public const string ApplicationTextSize = nameof(ApplicationTextSize);
|
||||
public const string ApplyLevelingDurringExport = nameof(ApplyLevelingDurringExport);
|
||||
public const string CollectPrintHistoryData = nameof(CollectPrintHistoryData);
|
||||
public const string ColorPanelExpanded = nameof(ColorPanelExpanded);
|
||||
public const string ConfigurePrinter_CurrentTab = nameof(ConfigurePrinter_CurrentTab);
|
||||
public const string ConfigurePrinterTabVisible = nameof(ConfigurePrinterTabVisible);
|
||||
public const string ControlsTabVisible = nameof(ControlsTabVisible);
|
||||
public const string CredentialsInvalid = nameof(CredentialsInvalid);
|
||||
public const string CredentialsInvalidReason = nameof(CredentialsInvalidReason);
|
||||
public const string defaultRenderSetting = nameof(defaultRenderSetting);
|
||||
public const string DisplayedTip_LoadFilament = nameof(DisplayedTip_LoadFilament);
|
||||
public const string EditorPanelExpanded = nameof(EditorPanelExpanded);
|
||||
public const string FavoritesBarExpansion= nameof(FavoritesBarExpansion);
|
||||
public const string GCodeLineColorStyle = nameof(GCodeLineColorStyle);
|
||||
public const string GcodeModelView = nameof(GcodeModelView);
|
||||
public const string GcodeViewerRenderGrid = nameof(GcodeViewerRenderGrid);
|
||||
public const string GcodeViewerRenderMoves = nameof(GcodeViewerRenderMoves);
|
||||
public const string GcodeViewerRenderRetractions = nameof(GcodeViewerRenderRetractions);
|
||||
public const string GcodeViewerSimulateExtrusion = nameof(GcodeViewerSimulateExtrusion);
|
||||
public const string GcodeViewerTransparentExtrusion = nameof(GcodeViewerTransparentExtrusion);
|
||||
public const string TerminalShowInputOutputMarks = nameof(TerminalShowInputOutputMarks);
|
||||
public const string TerminalShowChecksum = nameof(TerminalShowChecksum);
|
||||
public const string TerminalShowOks = nameof(TerminalShowOks);
|
||||
public const string TerminalShowMovementRequests = nameof(TerminalShowMovementRequests);
|
||||
public const string TerminalShowTempRequests = nameof(TerminalShowTempRequests);
|
||||
public const string TerminalShowTempResponse = nameof(TerminalShowTempResponse);
|
||||
public const string TerminalShowWaitResponse = nameof(TerminalShowWaitResponse);
|
||||
public const string Language = nameof(Language);
|
||||
public const string LayerViewDefault = nameof(LayerViewDefault);
|
||||
public const string LayerViewSyncToPrint = nameof(LayerViewSyncToPrint);
|
||||
public const string LibraryViewWidth = nameof(LibraryViewWidth);
|
||||
public const string MaterialsPanelExpanded = nameof(MaterialsPanelExpanded);
|
||||
public const string MirrorPanelExpanded = nameof(MirrorPanelExpanded);
|
||||
public const string NotificationEmailAddress = nameof(NotificationEmailAddress);
|
||||
public const string NotificationPhoneNumber = nameof(NotificationPhoneNumber);
|
||||
public const string OpenScadPath = nameof(OpenScadPath);
|
||||
public const string PerspectiveMode = nameof(PerspectiveMode);
|
||||
public const string SupportGenerationType = nameof(SupportGenerationType);
|
||||
public const string SupportMaxOverHangAngle = nameof(SupportMaxOverHangAngle);
|
||||
public const string SupportPillarSize = nameof(SupportPillarSize);
|
||||
public const string PopupLibraryWidth = nameof(PopupLibraryWidth);
|
||||
public const string PrintHistoryFilterShowCompleted = nameof(PrintHistoryFilterShowCompleted);
|
||||
public const string PrintNotificationsEnabled = nameof(PrintNotificationsEnabled);
|
||||
public const string PrintNotificationsIncludeImage = nameof(PrintNotificationsIncludeImage);
|
||||
public const string PublicProfilesSha = nameof(PublicProfilesSha);
|
||||
public const string ScalePanelExpanded = nameof(ScalePanelExpanded);
|
||||
public const string SceneTreeRatio = nameof(SceneTreeRatio);
|
||||
public const string SelectedObjectEditorHeight = nameof(SelectedObjectEditorHeight);
|
||||
public const string SelectedObjectPanelWidth = nameof(SelectedObjectPanelWidth);
|
||||
public const string SelectionTreeViewPanelExpanded = nameof(SelectionTreeViewPanelExpanded);
|
||||
public const string ShownWelcomeMessage = nameof(ShownWelcomeMessage);
|
||||
public const string SliceSettingsTabIndex = nameof(SliceSettingsTabIndex);
|
||||
public const string SliceSettingsTabPinned = nameof(SliceSettingsTabPinned);
|
||||
public const string SliceSettingsWidget_CurrentTab = nameof(SliceSettingsWidget_CurrentTab);
|
||||
public const string SliceSettingsWidth = nameof(SliceSettingsWidth);
|
||||
public const string SliceSettingsViewDetail = nameof(SliceSettingsViewDetail);
|
||||
public const string SliceSettingsMoreClicked = nameof(SliceSettingsMoreClicked);
|
||||
public const string SnapGridDistance = nameof(SnapGridDistance);
|
||||
public const string SoftwareLicenseAccepted = nameof(SoftwareLicenseAccepted);
|
||||
public const string TerminalAutoUppercase = nameof(TerminalAutoUppercase);
|
||||
public const string TerminalTabVisible = nameof(TerminalTabVisible);
|
||||
public const string ThemeName = nameof(ThemeName);
|
||||
public const string ThumbnailRenderingMode = nameof(ThumbnailRenderingMode);
|
||||
public const string TurntableMode = nameof(TurntableMode);
|
||||
public const string UpdateFeedType = nameof(UpdateFeedType);
|
||||
public const string MainTabKey = nameof(MainTabKey);
|
||||
}
|
||||
|
||||
public class UserSettings
|
||||
{
|
||||
private static UserSettings globalInstance = null;
|
||||
|
||||
private static readonly object SyncRoot = new object();
|
||||
|
||||
private Dictionary<string, UserSetting> settingsDictionary;
|
||||
|
||||
private UserSettings()
|
||||
{
|
||||
// Load the UserSettings from the database
|
||||
settingsDictionary = new Dictionary<string, UserSetting>();
|
||||
foreach (var userSetting in Datastore.Instance.dbSQLite.Query<UserSetting>("SELECT * FROM UserSetting;"))
|
||||
{
|
||||
// LastValueWins - allow for duplicate entries in the database with the same .Name value
|
||||
settingsDictionary[userSetting.Name] = userSetting;
|
||||
}
|
||||
|
||||
// Set English as default language if unset
|
||||
if (string.IsNullOrEmpty(this.get("Language")))
|
||||
{
|
||||
this.set("Language", "en");
|
||||
}
|
||||
|
||||
// Propagate Language to local property
|
||||
this.Language = this.get("Language");
|
||||
}
|
||||
|
||||
public event EventHandler<StringEventArgs> SettingChanged;
|
||||
|
||||
public static UserSettings Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (globalInstance == null)
|
||||
{
|
||||
lock (SyncRoot)
|
||||
{
|
||||
if (globalInstance == null)
|
||||
{
|
||||
globalInstance = new UserSettings();
|
||||
ToolTipManager.AllowToolTips = !GuiWidget.TouchScreenMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return globalInstance;
|
||||
}
|
||||
}
|
||||
|
||||
public string Language { get; private set; }
|
||||
|
||||
public UserSettingsFields Fields { get; private set; } = new UserSettingsFields();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the first matching value discovered while enumerating the settings layers
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of value being gotten</typeparam>
|
||||
/// <param name="settingsKey">The name of the value to get</param>
|
||||
/// <returns>The typed value</returns>
|
||||
public T GetValue<T>(string settingsKey, T defaultValue)
|
||||
{
|
||||
var settingValue = this.get(settingsKey);
|
||||
|
||||
if (settingValue == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
if (typeof(T) == typeof(string))
|
||||
{
|
||||
// this way we can use the common pattern without error
|
||||
return (T)(object)settingValue;
|
||||
}
|
||||
else if (typeof(T) == typeof(bool))
|
||||
{
|
||||
return (T)(object)(settingValue == "1");
|
||||
}
|
||||
else if (typeof(T) == typeof(int))
|
||||
{
|
||||
int result;
|
||||
int.TryParse(settingValue, out result);
|
||||
return (T)(object)result;
|
||||
}
|
||||
else if (typeof(T) == typeof(double))
|
||||
{
|
||||
double.TryParse(settingValue, out double result);
|
||||
return (T)(object)result;
|
||||
}
|
||||
else if (typeof(T) == typeof(Vector2))
|
||||
{
|
||||
var parts = settingValue.Split(new[] { 'X', ':', ',', 'Y', ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 2 && double.TryParse(parts[0].Trim(), out double x) && double.TryParse(parts[1].Trim(), out double y))
|
||||
{
|
||||
Vector2 result = new Vector2(x, y);
|
||||
return (T)(object)result;
|
||||
}
|
||||
// Else, handle the case when the parsing fails...
|
||||
}
|
||||
|
||||
return (T)default(T);
|
||||
}
|
||||
|
||||
public void SetValue<T>(string key, T value)
|
||||
{
|
||||
if (typeof(T) == typeof(bool))
|
||||
{
|
||||
set(key, ((bool)(object)value) ? "1" : "0");
|
||||
}
|
||||
else if (value is Vector2 vector)
|
||||
{
|
||||
set(key, $"X:{vector.X},Y:{vector.Y}");
|
||||
}
|
||||
else if (value is IConvertible convertible)
|
||||
{
|
||||
set(key, convertible.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
else
|
||||
{
|
||||
set(key, value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public string get(string key)
|
||||
{
|
||||
UserSetting userSetting;
|
||||
if (settingsDictionary.TryGetValue(key, out userSetting))
|
||||
{
|
||||
return userSetting.Value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void set(string key, string value)
|
||||
{
|
||||
UserSetting setting;
|
||||
|
||||
if (!settingsDictionary.TryGetValue(key, out setting))
|
||||
{
|
||||
// If the setting for the given key doesn't exist, create it
|
||||
setting = new UserSetting()
|
||||
{
|
||||
Name = key
|
||||
};
|
||||
settingsDictionary[key] = setting;
|
||||
}
|
||||
|
||||
// Special case to propagate Language to local property on assignment
|
||||
if (key == "Language")
|
||||
{
|
||||
this.Language = value;
|
||||
}
|
||||
|
||||
if (setting.Value != value)
|
||||
{
|
||||
setting.Value = value;
|
||||
setting.Commit();
|
||||
|
||||
SettingChanged?.Invoke(this, new StringEventArgs(key));
|
||||
}
|
||||
}
|
||||
|
||||
public double LibraryViewWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!double.TryParse(this.get(UserSettingsKey.LibraryViewWidth), out double controlWidth))
|
||||
{
|
||||
// Default to 254 if no UserSetting value exists
|
||||
controlWidth = 254 * GuiWidget.DeviceScale;
|
||||
}
|
||||
|
||||
return controlWidth;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.set(UserSettingsKey.LibraryViewWidth, value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public string ThumbnailRenderingMode
|
||||
{
|
||||
get
|
||||
{
|
||||
string renderingMode = this.get(UserSettingsKey.ThumbnailRenderingMode);
|
||||
if (string.IsNullOrWhiteSpace(renderingMode))
|
||||
{
|
||||
// If the current value is unset or invalid, use platform defaults
|
||||
return GuiWidget.TouchScreenMode ? "orthographic" : "raytraced";
|
||||
}
|
||||
|
||||
return renderingMode;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.set(UserSettingsKey.ThumbnailRenderingMode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public double SelectedObjectPanelWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
if (double.TryParse(UserSettings.Instance.get(UserSettingsKey.SelectedObjectPanelWidth), out double controlWidth))
|
||||
{
|
||||
return Math.Max(controlWidth, 150);
|
||||
}
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
var minimumValue = Math.Max(value, 150);
|
||||
UserSettings.Instance.set(UserSettingsKey.SelectedObjectPanelWidth, minimumValue.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
Copyright (c) 2014, Lars Brubaker
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using MatterHackers.MatterControl.SettingsManagement;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public class UserSettingsFields
|
||||
{
|
||||
private List<string> acceptableTrueFalseValues = new List<string>() { "true", "false" };
|
||||
|
||||
private string StartCountKey = "StartCount";
|
||||
private string StartCountDurringExitKey = "StartCountDurringExit";
|
||||
|
||||
public int StartCount
|
||||
{
|
||||
get { return GetInt(StartCountKey); }
|
||||
set { SetInt(StartCountKey, value); }
|
||||
}
|
||||
|
||||
public int StartCountDurringExit
|
||||
{
|
||||
get { return GetInt(StartCountDurringExitKey); }
|
||||
set { SetInt(StartCountDurringExitKey, value); }
|
||||
}
|
||||
|
||||
public void SetBool(string keyToSet, bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
UserSettings.Instance.set(keyToSet, "true");
|
||||
}
|
||||
else
|
||||
{
|
||||
UserSettings.Instance.set(keyToSet, "false");
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetBool(string keyToRead, bool defaultValue)
|
||||
{
|
||||
string currentValue = UserSettings.Instance.get(keyToRead);
|
||||
if (acceptableTrueFalseValues.IndexOf(currentValue) == -1)
|
||||
{
|
||||
if (defaultValue)
|
||||
{
|
||||
currentValue = "true";
|
||||
}
|
||||
else
|
||||
{
|
||||
currentValue = "false";
|
||||
}
|
||||
UserSettings.Instance.set(keyToRead, currentValue);
|
||||
}
|
||||
return currentValue == "true";
|
||||
}
|
||||
|
||||
public void SetInt(string keyToSet, int value)
|
||||
{
|
||||
UserSettings.Instance.set(keyToSet, value.ToString());
|
||||
}
|
||||
|
||||
public int GetInt(string keyToRead, int defaultValue = 0)
|
||||
{
|
||||
string currentValue = UserSettings.Instance.get(keyToRead);
|
||||
int result = 0;
|
||||
if (!int.TryParse(currentValue, out result))
|
||||
{
|
||||
result = defaultValue;
|
||||
UserSettings.Instance.set(keyToRead, currentValue);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetDouble(string keyToSet, double value)
|
||||
{
|
||||
UserSettings.Instance.set(keyToSet, value.ToString());
|
||||
}
|
||||
|
||||
public double GetDouble(string keyToRead, double defaultValue = 0)
|
||||
{
|
||||
string currentValue = UserSettings.Instance.get(keyToRead);
|
||||
double result = 0;
|
||||
if (!double.TryParse(currentValue, out result))
|
||||
{
|
||||
result = defaultValue;
|
||||
UserSettings.Instance.set(keyToRead, currentValue);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue