Skip to content

Commit

Permalink
Merged PR 146: V3.0.21 Release 8
Browse files Browse the repository at this point in the history
* Fix horizontal scrolling of structure in Task Panes.
* Handle error when WPF Browser does not load ChemDoodle Web.

Related work items: #377
  • Loading branch information
MikeWilliams-UK committed Oct 17, 2018
2 parents d6f062a + 57cb0e6 commit 58287a6
Show file tree
Hide file tree
Showing 73 changed files with 1,276 additions and 1,121 deletions.
4 changes: 2 additions & 2 deletions src/Chem4Word.V3.sln
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{EAD5
Scripts\DeepClean.ps1 = Scripts\DeepClean.ps1
Scripts\Install-Dev-Certificate.ps1 = Scripts\Install-Dev-Certificate.ps1
SetAssemblyVersion.ps1 = SetAssemblyVersion.ps1
Scripts\SignAssembly.ps1 = Scripts\SignAssembly.ps1
SignFiles.cmd = SignFiles.cmd
Scripts\SetAssemblyVersion.ps1 = Scripts\SetAssemblyVersion.ps1
Scripts\SignFiles.cmd = Scripts\SignFiles.cmd
EndProjectSection
EndProject
Global
Expand Down
3 changes: 2 additions & 1 deletion src/Chem4Word.V3/Chem4Word.V3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
<Compile Include="AssemblyReflectionManager.cs" />
<Compile Include="Database\Library.cs" />
<Compile Include="Helpers\ConfigWatcher.cs" />
<Compile Include="Helpers\ChemistryHelper.cs" />
<Compile Include="Helpers\ReferenceKeeper.cs" />
<Compile Include="Helpers\RegistryHelper.cs" />
<Compile Include="Helpers\TargetWord.cs" />
Expand All @@ -290,7 +291,7 @@
<Compile Include="Library\TagBlock.xaml.cs">
<DependentUpon>TagBlock.xaml</DependentUpon>
</Compile>
<Compile Include="Navigator\NavigatorSupport.cs" />
<Compile Include="Helpers\TaskPaneHelper.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down
143 changes: 106 additions & 37 deletions src/Chem4Word.V3/Chem4WordV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,24 @@
using Chem4Word.Core.UI.Forms;
using Chem4Word.Helpers;
using Chem4Word.Library;
using Chem4Word.Model.Converters;
using Chem4Word.Model.Converters.CML;
using Chem4Word.Telemetry;
using IChem4Word.Contracts;
using Microsoft.Office.Core;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Threading;
using System.Xml.Linq;
using Chem4Word.Model.Converters.CML;
using Extensions = Microsoft.Office.Tools.Word.Extensions;
using OfficeTools = Microsoft.Office.Tools;
using Word = Microsoft.Office.Interop.Word;
Expand All @@ -42,6 +39,7 @@ public partial class Chem4WordV3
{
// Internal variables for class
private static string _product = Assembly.GetExecutingAssembly().FullName.Split(',')[0];

private static string _class = MethodBase.GetCurrentMethod().DeclaringType?.Name;

public static CustomRibbon Ribbon;
Expand Down Expand Up @@ -287,15 +285,6 @@ public void LoadNamesFromLibrary()
string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";
try
{
// ToDo: Remove before check in
//string libraryTarget = Path.Combine(Globals.Chem4WordV3.AddInInfo.ProgramDataPath, Constants.LibraryFileName);
//if (!File.Exists(libraryTarget))
//{
// Globals.Chem4WordV3.Telemetry.Write(module, "Information", "Copying initial Library database");
// ResourceHelper.WriteResource(Assembly.GetExecutingAssembly(), "Data.Library.db", libraryTarget);
//}

//Globals.Chem4WordV3.Telemetry.Write(module, "Information", "Reading Library database");
var lib = new Database.Library();
LibraryNames = lib.GetLibraryNames();
}
Expand Down Expand Up @@ -961,16 +950,90 @@ private void OnCommandBarButtonClick(CommandBarButton ctrl, ref bool cancelDefau
var lib = new Database.Library();
string cml = lib.GetChemistryByID(tw.ChemistryId);


if (cml == null)
{
UserInteractions.WarnUser($"No match for '{tw.ChemicalName}' was found in your library");
}
else
{
Application.ActiveDocument.Range(tw.Start, tw.End).Select();
Insert1DChemistry(cml, tw.ChemicalName, false, true);
Telemetry.Write(module, "Information", $"Inserted 1D version of {tw.ChemicalName} from library");
Word.Application app = Globals.Chem4WordV3.Application;
Word.Document doc = app.ActiveDocument;

// Generate new CustomXmlPartGuid
CMLConverter converter = new CMLConverter();
var model = converter.Import(cml);
model.CustomXmlPartGuid = Guid.NewGuid().ToString("N");
cml = converter.Export(model);

#region Find Id of name

string tagPrefix = "";
foreach (var mol in model.Molecules)
{
foreach (var name in mol.ChemicalNames)
{
if (tw.ChemicalName.ToLower().Equals(name.Name.ToLower()))
{
tagPrefix = name.Id;
break;
}
}

if (!string.IsNullOrEmpty(tagPrefix))
{
break;
}
}

if (string.IsNullOrEmpty(tagPrefix))
{
tagPrefix = "c0";
}

#endregion Find Id of name

// Test phrases (ensure benzene is in your library)
// This is benzene, this is not.
// This is benzene. This is not.

Word.ContentControl cc = null;
bool previousState = app.Options.SmartCutPaste;

try
{
app.ScreenUpdating = false;
Globals.Chem4WordV3.DisableDocumentEvents(doc);

//Debug.WriteLine($"'{tw.ChemicalName}' {tw.Start} > {tw.End}");

app.Options.SmartCutPaste = false;
int insertionPoint = tw.Start;
doc.Range(tw.Start, tw.Start + tw.ChemicalName.Length).Delete();

app.Selection.SetRange(insertionPoint, insertionPoint);

string tag = $"{tagPrefix}:{model.CustomXmlPartGuid}";
cc = ChemistryHelper.Insert1DChemistry(doc, tw.ChemicalName, true, tag);

Telemetry.Write(module, "Information", $"Inserted 1D version of {tw.ChemicalName} from library");
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
finally
{
Globals.Chem4WordV3.EnableDocumentEvents(doc);
app.ScreenUpdating = true;
app.Options.SmartCutPaste = previousState;
}

if (cc != null)
{
doc.CustomXMLParts.Add(cml);
app.Selection.SetRange(cc.Range.Start, cc.Range.End);
}
}

_markAsChemistryHandled = true;
Expand Down Expand Up @@ -1000,9 +1063,6 @@ private void HandleRightClick(Word.Selection sel)
_markAsChemistryHandled = false;
_rightClickEvents = 0;

//Debug.WriteLine(sel.Text);
//Debug.WriteLine(sel.Sentences.Count);

List<TargetWord> selectedWords = new List<TargetWord>();

try
Expand Down Expand Up @@ -1030,22 +1090,27 @@ private void HandleRightClick(Word.Selection sel)
end = Math.Min(end, last);
if (start < end)
{
string sentenceText = doc.Range(start, end).Text;
Debug.WriteLine($"Sentences[{i}] --> {sentenceText}");
if (!string.IsNullOrEmpty(sentenceText))
var range = doc.Range(start, end);
//Exclude any ranges which contain content controls
if (range.ContentControls.Count == 0)
{
foreach (var kvp in LibraryNames)
string sentenceText = range.Text;
//Debug.WriteLine($"Sentences[{i}] --> {sentenceText}");
if (!string.IsNullOrEmpty(sentenceText))
{
int idx = sentenceText.IndexOf(kvp.Key, StringComparison.InvariantCultureIgnoreCase);
if (idx > 0)
foreach (var kvp in LibraryNames)
{
selectedWords.Add(new TargetWord
int idx = sentenceText.IndexOf(kvp.Key, StringComparison.InvariantCultureIgnoreCase);
if (idx > 0)
{
ChemicalName = kvp.Key,
Start = start + idx,
ChemistryId = kvp.Value,
End = start + idx + kvp.Key.Length
});
selectedWords.Add(new TargetWord
{
ChemicalName = kvp.Key,
Start = start + idx,
ChemistryId = kvp.Value,
End = start + idx + kvp.Key.Length
});
}
}
}
}
Expand All @@ -1064,6 +1129,7 @@ private void HandleRightClick(Word.Selection sel)
ChemistryAllowed = false;
ChemistryProhibitedReason = "can't create a selection object";
break;

default:
// Keep exception hidden from end user.
Telemetry.Write(module, "Exception", $"ErrorCode: {comCode}");
Expand Down Expand Up @@ -1149,6 +1215,7 @@ private void ClearChemistryContextMenus()
((Word.Template)doc.AttachedTemplate).Saved = true;
}

[Obsolete]
public static void Insert1DChemistry(string xml, string text, bool is2D, bool isCopy)
{
string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";
Expand Down Expand Up @@ -1190,7 +1257,6 @@ public static void Insert1DChemistry(string xml, string text, bool is2D, bool is
}

string guidString = chem.CustomXmlPartGuid;
string bookmarkName = "C4W_" + guidString;

// Export just incase the CustomXmlPartGuid has been changed
string cml = cmlConverter.Export(chem);
Expand Down Expand Up @@ -1221,7 +1287,8 @@ public static void Insert1DChemistry(string xml, string text, bool is2D, bool is
string tempfileName = renderer.Render();
if (File.Exists(tempfileName))
{
cc = CustomRibbon.Insert2D(doc, tempfileName, bookmarkName, guidString);
//cc = CustomRibbon.Insert2D(doc, tempfileName, bookmarkName, guidString);
ChemistryHelper.Insert2D(cc, tempfileName, guidString);

try
{
Expand Down Expand Up @@ -1259,7 +1326,7 @@ public static void Insert1DChemistry(string xml, string text, bool is2D, bool is
break;
}
}
cc = CustomRibbon.Insert1D(app, doc, text, false, tag);
ChemistryHelper.Insert1D(cc, text, false, tag);
}

if (isCopy)
Expand Down Expand Up @@ -1705,13 +1772,12 @@ public void EvaluateChemistryAllowed()

if (doc != null)
{
if (doc.CompatibilityMode < (int) Word.WdCompatibilityMode.wdWord2010)
if (doc.CompatibilityMode < (int)Word.WdCompatibilityMode.wdWord2010)
{
allowed = false;
ChemistryProhibitedReason = "document is in compatibility mode.";
}


try
{
//if (doc.CoAuthoring.Conflicts.Count > 0) // <-- This clears current selection ???
Expand Down Expand Up @@ -1859,14 +1925,17 @@ public void EvaluateChemistryAllowed()
ChemistryAllowed = false;
ChemistryProhibitedReason = "can't determine where the current selection is.";
break;

case "0x800A11FD":
ChemistryAllowed = false;
ChemistryProhibitedReason = "changes are not permitted in the current selection.";
break;

case "0x800A1759":
ChemistryAllowed = false;
ChemistryProhibitedReason = "can't create a selection when a dialogue is active.";
break;

default:
// Keep exception hidden from end user.
Telemetry.Write(module, "Exception", $"ErrorCode: {comCode}");
Expand Down
15 changes: 12 additions & 3 deletions src/Chem4Word.V3/Data/Chem4Word-Versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,34 @@
<!-- This file must be uploaded to https://www.chem4word.co.uk/files3/ folder as Chem4Word-Versions.xml -->
<ChangeLog>
<Id>f3c4f4db-2fff-46db-b14a-feb8e09f7742</Id>
<Version>
<Number>3.0.21 Release 8</Number>
<IsBeta>false</IsBeta>
<Released>17-Oct-2018</Released>
<Changes>
<Change>Fix horizontal scrolling of structure in Task Panes.</Change>
<Change>Handle error when WPF Browser does not load ChemDoodle Web.</Change>
<Change>Please download Chem4Word-Setup.exe from https://www.chem4word.co.uk/download/ if you encounter any difficulties updating.</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.21.Release.8.msi</Url>
</Version>
<Version>
<Number>3.0.20 Release 7</Number>
<IsBeta>false</IsBeta>
<Released>26-Sep-2018</Released>
<Changes>
<Change>New resolution independent ChemDoodle Web Editor (8.0.0).</Change>
<Change>Please download Chem4Word-Setup.exe from https://www.chem4word.co.uk/download/ if you encounter any difficulties updating.</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.20.Release.7.msi</Url>
</Version>
<Version>
<Number>3.0.19 Release 6</Number>
<IsBeta>false</IsBeta>
<Released>08-Sep-2018</Released>
<Released>05-Sep-2018</Released>
<Changes>
<Change>Change method of opening files for import to improve handling of locked files.</Change>
<Change>Change to using our own InchiKey resolver, ChemSpider is no longer working.</Change>
<Change>Update SQLite to latest version.</Change>
<Change>Please download Chem4Word-Setup.exe from https://www.chem4word.co.uk/download/ if you encounter any difficulties updating.</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.19.Release.6.msi</Url>
</Version>
Expand Down
4 changes: 2 additions & 2 deletions src/Chem4Word.V3/Data/This-Version.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Version>
<Number>3.0.20 Release 7</Number>
<Number>3.0.21 Release 8</Number>
<IsBeta>false</IsBeta>
<Released>26-Sep-2018</Released>
<Released>17-Oct-2018</Released>
</Version>
4 changes: 4 additions & 0 deletions src/Chem4Word.V3/Data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ <h1>Chemistry for Word Add-In V3</h1>
<td>Setup Bootstrapper</td>
<td><a href="/files3/Chem4Word-Setup.exe">Chem4Word-Setup</a></td>
</tr>
<tr>
<td>Version 3.0.21 - Release 8</td>
<td><a href="/files3/Chem4Word-Setup.3.0.21.Release.8.msi">Chem4Word-Setup 3.0.21 Release 8</a></td>
</tr>
<tr>
<td>Version 3.0.20 - Release 7</td>
<td><a href="/files3/Chem4Word-Setup.3.0.20.Release.7.msi">Chem4Word-Setup 3.0.20 Release 7</a></td>
Expand Down
Loading

0 comments on commit 58287a6

Please sign in to comment.