-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ACME displays warning circles when valence violations occur #31 * ACME keyboard focus now returns to the editor #30 * Add ACME Option to render in Monochrome #11 * Add ACME Option to show/hide Implicit Hydrogens #17 * Fix flipping of functional groups #35 * Fix crash when using Create PDF button on Adobe Acrobat Word Add-In #40 * Correct rendering of double bond of norbornene #34 * Correct rendering of terminal double bonds #25 * Silently handle COMException in OnDocumentBeforeSave #42 Related work items: #677, #678, #681, #690, #697, #698, #700, #701
- Loading branch information
Showing
260 changed files
with
7,612 additions
and
11,903 deletions.
There are no files selected for viewing
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
// --------------------------------------------------------------------------- | ||
// Copyright (c) 2020, The .NET Foundation. | ||
// This software is released under the Apache License, Version 2.0. | ||
// The license and further copyright text can be found in the file LICENSE.md | ||
// at the root directory of the distribution. | ||
// --------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Windows; | ||
using Chem4Word.Core.Helpers; | ||
using Newtonsoft.Json; | ||
|
||
namespace Chem4Word | ||
{ | ||
[JsonObject(MemberSerialization.OptIn)] | ||
public class Chem4WordOptions | ||
{ | ||
private static string _product = Assembly.GetExecutingAssembly().FullName.Split(',')[0]; | ||
|
||
#region Telemetry | ||
|
||
[JsonProperty] | ||
public bool TelemetryEnabled { get; set; } | ||
|
||
#endregion Telemetry | ||
|
||
#region Automatic Updates - Not Serialised | ||
|
||
public bool AutoUpdateEnabled { get; set; } | ||
|
||
public int AutoUpdateFrequency { get; set; } | ||
|
||
#endregion Automatic Updates - Not Serialised | ||
|
||
#region Selected Plug Ins | ||
|
||
[JsonProperty] | ||
public string SelectedEditorPlugIn { get; set; } | ||
|
||
[JsonProperty] | ||
public string SelectedRendererPlugIn { get; set; } | ||
|
||
#endregion Selected Plug Ins | ||
|
||
#region General | ||
|
||
[JsonProperty] | ||
public int BondLength { get; set; } | ||
|
||
[JsonProperty] | ||
public bool RemoveExplicitHydrogensOnImportFromFile { get; set; } | ||
|
||
[JsonProperty] | ||
public bool RemoveExplicitHydrogensOnImportFromSearch { get; set; } | ||
|
||
[JsonProperty] | ||
public bool RemoveExplicitHydrogensOnImportFromLibrary { get; set; } | ||
|
||
[JsonProperty] | ||
public bool SetBondLengthOnImportFromFile { get; set; } | ||
|
||
[JsonProperty] | ||
public bool SetBondLengthOnImportFromSearch { get; set; } | ||
|
||
[JsonProperty] | ||
public bool SetBondLengthOnImportFromLibrary { get; set; } | ||
|
||
#endregion General | ||
|
||
// Not serialised | ||
public Point WordTopLeft { get; set; } | ||
|
||
public string SettingsPath { get; set; } | ||
|
||
public List<string> Errors { get; set; } | ||
|
||
/// <summary> | ||
/// Load clean set of Chem4Word Options with default values | ||
/// </summary> | ||
public Chem4WordOptions() | ||
{ | ||
Errors = new List<string>(); | ||
RestoreDefaults(); | ||
} | ||
|
||
/// <summary> | ||
/// Load set of Chem4Word options | ||
/// </summary> | ||
/// <param name="path">Folder where the Chem4Word options are to reside - pass null to load from default path</param> | ||
public Chem4WordOptions(string path) | ||
{ | ||
SettingsPath = path; | ||
Errors = new List<string>(); | ||
Load(); | ||
} | ||
|
||
public void RestoreDefaults() | ||
{ | ||
TelemetryEnabled = true; | ||
|
||
SelectedEditorPlugIn = Constants.DefaultEditorPlugIn; | ||
SelectedRendererPlugIn = Constants.DefaultRendererPlugIn; | ||
|
||
BondLength = (int)Constants.StandardBondLength; | ||
|
||
SetBondLengthOnImportFromFile = true; | ||
SetBondLengthOnImportFromSearch = true; | ||
SetBondLengthOnImportFromLibrary = true; | ||
|
||
RemoveExplicitHydrogensOnImportFromFile = false; | ||
RemoveExplicitHydrogensOnImportFromSearch = false; | ||
RemoveExplicitHydrogensOnImportFromLibrary = false; | ||
|
||
// Non serialised | ||
AutoUpdateEnabled = true; | ||
AutoUpdateFrequency = 7; | ||
} | ||
|
||
public Chem4WordOptions Clone() | ||
{ | ||
Chem4WordOptions clone = new Chem4WordOptions(); | ||
|
||
// Copy serialised properties | ||
clone.SetValuesFromCopy(this); | ||
|
||
clone.AutoUpdateEnabled = AutoUpdateEnabled; | ||
clone.AutoUpdateFrequency = AutoUpdateFrequency; | ||
|
||
clone.SettingsPath = SettingsPath; | ||
clone.WordTopLeft = WordTopLeft; | ||
|
||
return clone; | ||
} | ||
|
||
private string GetFileName(string path) | ||
{ | ||
string fileName = $"{_product}.json"; | ||
string optionsFile = Path.Combine(path, fileName); | ||
return optionsFile; | ||
} | ||
|
||
/// <summary> | ||
/// Load the Chem4Word Options from the path defined in SettingsPath using defaults if this is null or empty string | ||
/// </summary> | ||
public void Load() | ||
{ | ||
try | ||
{ | ||
string path = FileSystemHelper.GetWritablePath(SettingsPath); | ||
|
||
if (!string.IsNullOrEmpty(path)) | ||
{ | ||
string optionsFile = GetFileName(path); | ||
|
||
if (File.Exists(optionsFile)) | ||
{ | ||
try | ||
{ | ||
Debug.WriteLine($"Reading Chem4Word Options from {optionsFile}"); | ||
string contents = File.ReadAllText(optionsFile); | ||
var options = JsonConvert.DeserializeObject<Chem4WordOptions>(contents); | ||
SetValuesFromCopy(options); | ||
|
||
string temp = JsonConvert.SerializeObject(options, Formatting.Indented); | ||
if (!contents.Equals(temp)) | ||
{ | ||
// Auto fix the file if required | ||
PersistOptions(optionsFile); | ||
} | ||
} | ||
catch (Exception exception) | ||
{ | ||
Debug.WriteLine(exception.Message); | ||
Errors.Add(exception.Message); | ||
Errors.Add(exception.StackTrace); | ||
|
||
RestoreDefaults(); | ||
PersistOptions(optionsFile); | ||
} | ||
} | ||
else | ||
{ | ||
RestoreDefaults(); | ||
PersistOptions(optionsFile); | ||
} | ||
} | ||
} | ||
catch (Exception exception) | ||
{ | ||
Errors.Add(exception.Message); | ||
Errors.Add(exception.StackTrace); | ||
} | ||
} | ||
|
||
private void SetValuesFromCopy(Chem4WordOptions copy) | ||
{ | ||
TelemetryEnabled = copy.TelemetryEnabled; | ||
|
||
SelectedEditorPlugIn = copy.SelectedEditorPlugIn; | ||
SelectedRendererPlugIn = copy.SelectedRendererPlugIn; | ||
|
||
BondLength = copy.BondLength; | ||
|
||
SetBondLengthOnImportFromFile = copy.SetBondLengthOnImportFromFile; | ||
SetBondLengthOnImportFromSearch = copy.SetBondLengthOnImportFromSearch; | ||
SetBondLengthOnImportFromLibrary = copy.SetBondLengthOnImportFromLibrary; | ||
|
||
RemoveExplicitHydrogensOnImportFromFile = copy.RemoveExplicitHydrogensOnImportFromFile; | ||
RemoveExplicitHydrogensOnImportFromSearch = copy.RemoveExplicitHydrogensOnImportFromSearch; | ||
RemoveExplicitHydrogensOnImportFromLibrary = copy.RemoveExplicitHydrogensOnImportFromLibrary; | ||
} | ||
|
||
private void PersistOptions(string optionsFile) | ||
{ | ||
try | ||
{ | ||
Debug.WriteLine($"Saving Chem4Word Options to {optionsFile}"); | ||
string contents = JsonConvert.SerializeObject(this, Formatting.Indented); | ||
File.WriteAllText(optionsFile, contents); | ||
} | ||
catch (Exception exception) | ||
{ | ||
Errors.Add(exception.Message); | ||
Errors.Add(exception.StackTrace); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Save the Chem4Word Options to the path defined in SettingsPath using defaults if this is null or empty string | ||
/// </summary> | ||
public void Save() | ||
{ | ||
string path = FileSystemHelper.GetWritablePath(SettingsPath); | ||
if (!string.IsNullOrEmpty(path)) | ||
{ | ||
string optionsFile = GetFileName(path); | ||
PersistOptions(optionsFile); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.