Skip to content

Commit

Permalink
Merged PR 338: V3.1.6 Beta 6
Browse files Browse the repository at this point in the history
* 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
MikeWilliams-UK committed Mar 5, 2020
2 parents 663d480 + 1a8d448 commit 6d3f336
Show file tree
Hide file tree
Showing 260 changed files with 7,612 additions and 11,903 deletions.
Binary file modified docs/Chem4Word-Version3-1-User-Manual.docx
Binary file not shown.
File renamed without changes.
18 changes: 9 additions & 9 deletions src/Chem4Word.V3/Chem4Word.V3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,16 @@
<Compile Include="UI\WPF\EditLabelsHost.Designer.cs">
<DependentUpon>EditLabelsHost.cs</DependentUpon>
</Compile>
<Compile Include="UI\WPF\SettingsControl.xaml.cs">
<DependentUpon>SettingsControl.xaml</DependentUpon>
<Compile Include="UI\WPF\Chem4WordSettingsControl.xaml.cs">
<DependentUpon>Chem4WordSettingsControl.xaml</DependentUpon>
</Compile>
<Compile Include="UI\WPF\SettingsHost.cs">
<Compile Include="UI\WPF\Chem4WordSettingsHost.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\WPF\SettingsHost.Designer.cs">
<DependentUpon>SettingsHost.cs</DependentUpon>
<Compile Include="UI\WPF\Chem4WordSettingsHost.Designer.cs">
<DependentUpon>Chem4WordSettingsHost.cs</DependentUpon>
</Compile>
<Compile Include="Options.cs" />
<Compile Include="Chem4WordOptions.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
Expand Down Expand Up @@ -527,8 +527,8 @@
<EmbeddedResource Include="UI\WPF\EditLabelsHost.resx">
<DependentUpon>EditLabelsHost.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\WPF\SettingsHost.resx">
<DependentUpon>SettingsHost.cs</DependentUpon>
<EmbeddedResource Include="UI\WPF\Chem4WordSettingsHost.resx">
<DependentUpon>Chem4WordSettingsHost.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\XmlViewer.resx">
<DependentUpon>XmlViewer.cs</DependentUpon>
Expand Down Expand Up @@ -670,7 +670,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UI\WPF\SettingsControl.xaml">
<Page Include="UI\WPF\Chem4WordSettingsControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down
245 changes: 245 additions & 0 deletions src/Chem4Word.V3/Chem4WordOptions.cs
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);
}
}
}
}
Loading

0 comments on commit 6d3f336

Please sign in to comment.