Skip to content

Commit

Permalink
Merged PR 284: Produce V3.0.28 R16
Browse files Browse the repository at this point in the history
* Bug Fix; Series does not contain a matching element in OoXml rendering [#15]
* Bug Fix; Sequence contains no elements in CustomRibbon Edit [#9]
* Bug Fix; System.NullReferenceException in Editor.ChemDoodleWeb800 [#13]
* Bug Fix; HandleRightClick(); The requested member of the collection does not exist. [#10]

Related work items: #563
  • Loading branch information
MikeWilliams-UK committed Oct 2, 2019
1 parent 8674d34 commit ebca6ae
Show file tree
Hide file tree
Showing 156 changed files with 3,546 additions and 2,263 deletions.
86 changes: 48 additions & 38 deletions src/Chem4Word.V3/Chem4WordV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using Chem4Word.Core;
using Chem4Word.Core.Helpers;
using Chem4Word.Core.UI.Forms;
using Chem4Word.Helpers;
using Chem4Word.Library;
using Chem4Word.Model.Converters.CML;
using Chem4Word.Navigator;
using Chem4Word.Telemetry;
using IChem4Word.Contracts;
using Microsoft.Office.Core;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -30,6 +19,17 @@
using System.Windows.Forms;
using System.Windows.Threading;
using System.Xml.Linq;
using Chem4Word.Core;
using Chem4Word.Core.Helpers;
using Chem4Word.Core.UI.Forms;
using Chem4Word.Helpers;
using Chem4Word.Library;
using Chem4Word.Model.Converters.CML;
using Chem4Word.Navigator;
using Chem4Word.Telemetry;
using IChem4Word.Contracts;
using Microsoft.Office.Core;
using Newtonsoft.Json;
using Extensions = Microsoft.Office.Tools.Word.Extensions;
using OfficeTools = Microsoft.Office.Tools;
using Word = Microsoft.Office.Interop.Word;
Expand Down Expand Up @@ -237,8 +237,8 @@ private void PerformStartUpActions()

if (app.Documents.Count > 0)
{
EnableDocumentEvents(app.Documents[1]);
if (app.Documents[1].CompatibilityMode >= (int)Word.WdCompatibilityMode.wdWord2010)
EnableDocumentEvents(app.ActiveDocument);
if (app.ActiveDocument.CompatibilityMode >= (int)Word.WdCompatibilityMode.wdWord2010)
{
SetButtonStates(ButtonState.CanInsert);
}
Expand Down Expand Up @@ -1007,7 +1007,7 @@ public void SelectChemistry(Word.Selection sel)
//Debug.WriteLine($"CC '{cc.Tag}' Range from {cc.Range.Start} to {cc.Range.End}");

// Already Selected
if (sel.Range.Start == cc.Range.Start -1 && sel.Range.End == cc.Range.End + 1)
if (sel.Range.Start == cc.Range.Start - 1 && sel.Range.End == cc.Range.End + 1)
{
if (cc.Title != null && cc.Title.Equals(Constants.ContentControlTitle))
{
Expand Down Expand Up @@ -1243,47 +1243,57 @@ private void HandleRightClick(Word.Selection sel)
if (LibraryNames != null && LibraryNames.Any())
{
// Limit to selections which have less than 5 sentences
if (sel.Sentences.Count <= 5)
if (sel != null && sel.Sentences != null && sel.Sentences.Count <= 5)
{
Word.Document doc = Application.ActiveDocument;
if (doc != null)
{
int last = doc.Range().End;
int sentenceCount = sel.Sentences.Count;
// Handling the selected text sentence by sentence should make us immune to return character sizing.
for (int i = 1; i <= sel.Sentences.Count; i++)
for (int i = 1; i <= sentenceCount; i++)
{
var sentence = sel.Sentences[i];
int start = Math.Max(sentence.Start, sel.Start);
start = Math.Max(0, start);
int end = Math.Min(sel.End, sentence.End);
end = Math.Min(end, last);
if (start < end)
// GitHub: Issue #10 https://github.com/Chem4Word/Version3/issues/10
try
{
var range = doc.Range(start, end);
//Exclude any ranges which contain content controls
if (range.ContentControls.Count == 0)
var sentence = sel.Sentences[i];
int start = Math.Max(sentence.Start, sel.Start);
start = Math.Max(0, start);
int end = Math.Min(sel.End, sentence.End);
end = Math.Min(end, last);
if (start < end)
{
string sentenceText = range.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;
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
});
}
}
}
}
}
}
catch (Exception e)
{
Telemetry.Write(module, "Exception", $"Handled; Sentences[{i}] of {sentenceCount} not found");
Telemetry.Write(module, "Exception", e.Message);
Telemetry.Write(module, "Exception", e.ToString());
}
}
}
}
Expand Down Expand Up @@ -1567,7 +1577,6 @@ private void OnDocumentChange()
{
SetButtonStates(ButtonState.NoDocument);
}

}
}
}
Expand Down Expand Up @@ -2254,6 +2263,7 @@ private void OnContentControlAfterAdd(Word.ContentControl NewContentControl, boo

if (!InUndoRedo && !string.IsNullOrEmpty(ccTag))
{
// Check that tag looks like it might be a C4W Tag
var regex = @"^[0-9a-fmn.:]+$";
Match match = Regex.Match(ccTag, regex, RegexOptions.IgnoreCase);
if (match.Success)
Expand Down
16 changes: 14 additions & 2 deletions src/Chem4Word.V3/Data/Chem4Word-Versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
<!-- 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.28 Release 16</Number>
<IsBeta>false</IsBeta>
<Released>07-Jul-2019</Released>
<Changes>
<Change>Bug Fix; Series does not contain a matching element in OoXml rendering [https://github.com/Chem4Word/Version3/issues/15]</Change>
<Change>Bug Fix; Sequence contains no elements in CustomRibbon Edit [https://github.com/Chem4Word/Version3/issues/9]</Change>
<Change>Bug Fix; System.NullReferenceException in Editor.ChemDoodleWeb800 [https://github.com/Chem4Word/Version3/issues/13]</Change>
<Change>Bug Fix; HandleRightClick(); The requested member of the collection does not exist. [https://github.com/Chem4Word/Version3/issues/10]</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.28.Release.16.msi</Url>
</Version>
<Version>
<Number>3.0.27 Release 15</Number>
<IsBeta>false</IsBeta>
Expand All @@ -10,9 +23,8 @@
<Change>Fix bounding box for subscript characters</Change>
<Change>Fix bug in CDW702 editor always setting bond length to 20</Change>
<Change>Implement clipping of bond lines using ConvexHull of atom characters</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.26.Release.14.msi</Url>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.27.Release.15.msi</Url>
</Version>
<Version>
<Number>3.0.26 Release 14</Number>
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.27 Release 15</Number>
<Number>3.0.28 Release 16</Number>
<IsBeta>false</IsBeta>
<Released>06-Jul-2019</Released>
<Released>02-Oct-2019</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.28 - Release 16</td>
<td><a href="/files3/Chem4Word-Setup.3.0.28.Release.16.msi">Chem4Word-Setup 3.0.28 Release 16</a></td>
</tr>
<tr>
<td>Version 3.0.27 - Release 15</td>
<td><a href="/files3/Chem4Word-Setup.3.0.27.Release.15.msi">Chem4Word-Setup 3.0.27 Release 15</a></td>
Expand Down
6 changes: 3 additions & 3 deletions src/Chem4Word.V3/Database/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using Chem4Word.Core.Helpers;
using Chem4Word.Core.UI.Forms;
using Chem4Word.Model.Converters.CML;
using System;
using System.Collections.Generic;
using System.Data;
Expand All @@ -16,6 +13,9 @@
using System.IO;
using System.Reflection;
using System.Text;
using Chem4Word.Core.Helpers;
using Chem4Word.Core.UI.Forms;
using Chem4Word.Model.Converters.CML;

namespace Chem4Word.Database
{
Expand Down
10 changes: 5 additions & 5 deletions src/Chem4Word.V3/Helpers/ChemistryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using Chem4Word.Core.Helpers;
using Chem4Word.Model;
using Chem4Word.Model.Converters.CML;
using IChem4Word.Contracts;
using Microsoft.Office.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Chem4Word.Core.Helpers;
using Chem4Word.Model;
using Chem4Word.Model.Converters.CML;
using IChem4Word.Contracts;
using Microsoft.Office.Core;
using Word = Microsoft.Office.Interop.Word;

namespace Chem4Word.Helpers
Expand Down
4 changes: 2 additions & 2 deletions src/Chem4Word.V3/Helpers/ConfigWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Chem4Word.Helpers
{
Expand Down
4 changes: 2 additions & 2 deletions src/Chem4Word.V3/Helpers/CustomXMLPartHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using Chem4Word.Core.Helpers;
using Microsoft.Office.Core;
using System.Collections.Generic;
using System.Diagnostics;
using System.Xml;
using Chem4Word.Core.Helpers;
using Microsoft.Office.Core;
using Word = Microsoft.Office.Interop.Word;

namespace Chem4Word.Helpers
Expand Down
4 changes: 2 additions & 2 deletions src/Chem4Word.V3/Helpers/RegistryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using Chem4Word.Core.Helpers;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Chem4Word.Core.Helpers;
using Microsoft.Win32;

namespace Chem4Word.Helpers
{
Expand Down
4 changes: 2 additions & 2 deletions src/Chem4Word.V3/Helpers/TaskPaneHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using System;
using System.Reflection;
using Chem4Word.Controls;
using Chem4Word.Core;
using Chem4Word.Core.Helpers;
using Chem4Word.Core.UI.Forms;
using Microsoft.Office.Interop.Word;
using System;
using System.Reflection;

namespace Chem4Word.Helpers
{
Expand Down
10 changes: 5 additions & 5 deletions src/Chem4Word.V3/Helpers/UpdateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using Chem4Word.Core.Helpers;
using Chem4Word.Core.UI.Forms;
using Chem4Word.UI;
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Globalization;
Expand All @@ -18,6 +14,10 @@
using System.Windows.Forms;
using System.Xml.Linq;
using System.Xml.XPath;
using Chem4Word.Core.Helpers;
using Chem4Word.Core.UI.Forms;
using Chem4Word.UI;
using Microsoft.Win32;

namespace Chem4Word.Helpers
{
Expand Down Expand Up @@ -209,7 +209,7 @@ private static string GetVersionsXmlFile()
{
Globals.Chem4WordV3.Telemetry.Write(module, "Information", $"Looking for Chem4Word-Versions.xml at {domain}");

client.DefaultRequestHeaders.Add("user-agent", "Chem4Word Bootstrapper");
client.DefaultRequestHeaders.Add("user-agent", "Chem4Word VersionChecker");
client.BaseAddress = new Uri(domain);
var response = client.GetAsync(VersionsFile).Result;
response.EnsureSuccessStatusCode();
Expand Down
10 changes: 5 additions & 5 deletions src/Chem4Word.V3/Helpers/Upgrader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using Chem4Word.Core;
using Chem4Word.Core.Helpers;
using Chem4Word.Model;
using Chem4Word.Model.Converters.CML;
using Microsoft.Office.Core;
using System;
using System.Collections;
using System.Collections.Generic;
Expand All @@ -23,6 +18,11 @@
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using Chem4Word.Core;
using Chem4Word.Core.Helpers;
using Chem4Word.Model;
using Chem4Word.Model.Converters.CML;
using Microsoft.Office.Core;
using Word = Microsoft.Office.Interop.Word;

namespace Chem4Word.Helpers
Expand Down
2 changes: 1 addition & 1 deletion src/Chem4Word.V3/Library/LibraryHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using Chem4Word.Core.UI.Forms;
using System;
using System.Reflection;
using System.Windows.Forms;
using Chem4Word.Core.UI.Forms;
using Word = Microsoft.Office.Interop.Word;

namespace Chem4Word.Library
Expand Down
4 changes: 2 additions & 2 deletions src/Chem4Word.V3/Library/LibraryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using Chem4Word.Controls.Annotations;
using Chem4Word.Core.UI.Forms;
using System;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.CompilerServices;
using Chem4Word.Controls.Annotations;
using Chem4Word.Core.UI.Forms;

namespace Chem4Word.Library
{
Expand Down
Loading

0 comments on commit ebca6ae

Please sign in to comment.