Skip to content

Commit

Permalink
Merged PR 77: Merge release3-bug-fixes to master
Browse files Browse the repository at this point in the history
* Add button (under Help) to show why 'chemistry' ribbon buttons are all disabled.
* Backup of document before conversion of legacy Content Controls.
* Better positioning of charges when implicit hydrogens present.
* Add support for legacy symbols for Elements 113 to 118.
* Trap errors during close of document.
* Fix Lazy Loading of Library Database.

Related work items: #305
  • Loading branch information
MikeWilliams-UK committed Mar 6, 2018
2 parents 295d482 + 83c1e9b commit b709c48
Show file tree
Hide file tree
Showing 48 changed files with 396 additions and 183 deletions.
1 change: 1 addition & 0 deletions src/Chem4Word.V3/Chem4Word.V3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@
<Content Include="Resources\Button Images\Home.png" />
<Content Include="Resources\Button Images\Import.png" />
<Content Include="Resources\Button Images\Information.png" />
<Content Include="Resources\Button Images\Locked.png" />
<Content Include="Resources\Button Images\Manual.png" />
<Content Include="Resources\Button Images\Navigation-32.png" />
<Content Include="Resources\Button Images\Office-2016\Edit-Labels.png" />
Expand Down
87 changes: 58 additions & 29 deletions src/Chem4Word.V3/Chem4WordV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ private void SetButtonStates(ButtonState state)
Ribbon.WebSearchMenu.Enabled = false;
Ribbon.SaveToLibrary.Enabled = false;
Ribbon.ArrangeMolecules.Enabled = false;
Ribbon.ButtonsDisabled.Enabled = true;
break;

case ButtonState.CanEdit:
Expand All @@ -782,6 +783,7 @@ private void SetButtonStates(ButtonState state)
Ribbon.WebSearchMenu.Enabled = false;
Ribbon.SaveToLibrary.Enabled = true;
Ribbon.ArrangeMolecules.Enabled = true;
Ribbon.ButtonsDisabled.Enabled = false;
break;

case ButtonState.CanInsert:
Expand All @@ -797,6 +799,7 @@ private void SetButtonStates(ButtonState state)
Ribbon.WebSearchMenu.Enabled = true;
Ribbon.SaveToLibrary.Enabled = false;
Ribbon.ArrangeMolecules.Enabled = false;
Ribbon.ButtonsDisabled.Enabled = false;
break;
}

Expand Down Expand Up @@ -961,6 +964,7 @@ private void OnCommandBarButtonClick(CommandBarButton ctrl, ref bool cancelDefau
{
LoadOptions();
}

new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
UpdateHelper.CheckForUpdates(SystemOptions.AutoUpdateFrequency);
Expand Down Expand Up @@ -1275,6 +1279,7 @@ private void OnNewDocument(Word.Document doc)
{
LoadOptions();
}

new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
UpdateHelper.CheckForUpdates(SystemOptions.AutoUpdateFrequency);
Expand Down Expand Up @@ -1467,13 +1472,13 @@ private void OnDocumentOpen(Word.Document doc)
}
catch (Exception ex)
{
new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
if (SystemOptions == null)
{
LoadOptions();
}

new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
UpdateHelper.CheckForUpdates(SystemOptions.AutoUpdateFrequency);
}
}
Expand Down Expand Up @@ -1519,13 +1524,13 @@ private void OnDocumentBeforeSave(Word.Document doc, ref bool saveAsUi, ref bool
}
catch (Exception ex)
{
new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
if (SystemOptions == null)
{
LoadOptions();
}

new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
UpdateHelper.CheckForUpdates(SystemOptions.AutoUpdateFrequency);
}
}
Expand Down Expand Up @@ -1559,25 +1564,39 @@ private void OnDocumentBeforeClose(Word.Document doc, ref bool cancel)

foreach (OfficeTools.CustomTaskPane taskPane in Globals.Chem4WordV3.CustomTaskPanes)
{
if (app.ActiveWindow == taskPane.Window)
try
{
custTaskPane = taskPane;
if (app.ActiveWindow == taskPane.Window)
{
custTaskPane = taskPane;
}
}
catch
{
// Nothing much we can do here!
}
}
if (custTaskPane != null)
{
Globals.Chem4WordV3.CustomTaskPanes.Remove(custTaskPane);
try
{
Globals.Chem4WordV3.CustomTaskPanes.Remove(custTaskPane);
}
catch
{
// Nothing much we can do here!
}
}
}
catch (Exception ex)
{
new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
if (SystemOptions == null)
{
LoadOptions();
}

new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
UpdateHelper.CheckForUpdates(SystemOptions.AutoUpdateFrequency);
}
}
Expand Down Expand Up @@ -1671,13 +1690,13 @@ public void EvaluateChemistryAllowed()
if (doc.CompatibilityMode < (int) Word.WdCompatibilityMode.wdWord2010)
{
allowed = false;
ChemistryProhibitedReason = "document is in compatability mode.";
ChemistryProhibitedReason = "document is in compatibility mode.";
}

Word.Selection sel = Application.Selection;
if (sel.OMaths.Count > 0)
{
ChemistryProhibitedReason = "selection is in Equation";
ChemistryProhibitedReason = "selection is in an Equation.";
allowed = false;
}

Expand All @@ -1687,7 +1706,7 @@ public void EvaluateChemistryAllowed()
{
if (sel.Cells.Count > 1)
{
ChemistryProhibitedReason = "selection contains more than one cell of a table";
ChemistryProhibitedReason = "selection contains more than one cell of a table.";
allowed = false;
}
}
Expand All @@ -1699,9 +1718,19 @@ public void EvaluateChemistryAllowed()

if (allowed)
{
if (sel.StoryType != Word.WdStoryType.wdMainTextStory)
try
{
Word.WdStoryType story = sel.StoryType;
if (story != Word.WdStoryType.wdMainTextStory)
{
ChemistryProhibitedReason = $"selection is in a '{DecodeStoryType(story)}' story.";
allowed = false;
}
}
catch
{
ChemistryProhibitedReason = $"selection is in {DecodeStoryType(sel.StoryType)} Story";
// ComException 0x80004005
ChemistryProhibitedReason = $"can't determine which part of the story the selection point is.";
allowed = false;
}
}
Expand Down Expand Up @@ -1729,7 +1758,7 @@ public void EvaluateChemistryAllowed()
{
allowed = false;
ChemistryProhibitedReason =
$"selection is in {DecodeContentControlType(contentControlType)} Content Control";
$"selection is in a '{DecodeContentControlType(contentControlType)}' Content Control.";
}
}
else
Expand All @@ -1738,7 +1767,7 @@ public void EvaluateChemistryAllowed()
{
allowed = false;
ChemistryProhibitedReason =
$"selection is in {DecodeContentControlType(contentControlType)} Content Control";
$"selection is in a '{DecodeContentControlType(contentControlType)}' Content Control";
}

// Test for Shape inside CC which is not ours
Expand All @@ -1749,7 +1778,7 @@ public void EvaluateChemistryAllowed()
if (sel.ShapeRange.Count > 0)
{
ChemistryProhibitedReason =
"selection contains shape(s) inside Content Control";
"selection contains shape(s) inside Content Control.";
allowed = false;
}
}
Expand All @@ -1769,7 +1798,7 @@ public void EvaluateChemistryAllowed()
{
if (sel.ShapeRange.Count > 0)
{
ChemistryProhibitedReason = "selection contains shape(s)";
ChemistryProhibitedReason = "selection contains shape(s).";
allowed = false;
}
}
Expand All @@ -1795,15 +1824,15 @@ public void EvaluateChemistryAllowed()
{
case "0x80004005":
ChemistryAllowed = false;
ChemistryProhibitedReason = "can't determine where the current selection is";
ChemistryProhibitedReason = "can't determine where the current selection is.";
break;
case "0x800A11FD":
ChemistryAllowed = false;
ChemistryProhibitedReason = "formatting changes are not permitted in the current selection";
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";
ChemistryProhibitedReason = "can't create a selection when a dialogue is active.";
break;
default:
// Keep exception hidden from end user.
Expand Down Expand Up @@ -2101,13 +2130,13 @@ private void OnContentControlAfterAdd(Word.ContentControl NewContentControl, boo
}
catch (Exception ex)
{
new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
if (SystemOptions == null)
{
LoadOptions();
}

new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
UpdateHelper.CheckForUpdates(SystemOptions.AutoUpdateFrequency);
}
}
Expand All @@ -2132,13 +2161,13 @@ private void OnContentControlBeforeDelete(Word.ContentControl contentControl, bo
}
catch (Exception ex)
{
new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
if (SystemOptions == null)
{
LoadOptions();
}

new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
UpdateHelper.CheckForUpdates(SystemOptions.AutoUpdateFrequency);
}
}
Expand Down Expand Up @@ -2171,13 +2200,13 @@ private void OnContentControlOnExit(Word.ContentControl contentControl, ref bool
}
catch (Exception ex)
{
new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
if (SystemOptions == null)
{
LoadOptions();
}

new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
UpdateHelper.CheckForUpdates(SystemOptions.AutoUpdateFrequency);
}
}
Expand Down Expand Up @@ -2212,13 +2241,13 @@ private void OnContentControlOnEnter(Word.ContentControl contentControl)
}
catch (Exception ex)
{
new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
if (SystemOptions == null)
{
LoadOptions();
}

new ReportError(Telemetry, WordTopLeft, module, ex).ShowDialog();
UpdateHelper.ClearSettings();
UpdateHelper.CheckForUpdates(SystemOptions.AutoUpdateFrequency);
}
}
Expand Down
18 changes: 16 additions & 2 deletions src/Chem4Word.V3/Data/Chem4Word-Versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@
<!-- 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.17 Release 4</Number>
<IsBeta>false</IsBeta>
<Released>06-Mar-2018</Released>
<Changes>
<Change>Add button (under Help) to show why 'chemistry' ribbon buttons are all disabled.</Change>
<Change>Backup of document before conversion of legacy Content Controls.</Change>
<Change>Better positioning of charges when implicit hydrogens present.</Change>
<Change>Add support for legacy symbols for Elements 113 to 118.</Change>
<Change>Trap errors during close of document.</Change>
<Change>Fix Lazy Loading of Library Database.</Change>
<Change>Please download Chem4Word-Setup.exe from https://github.com/Chem4Word/Version3/releases/latest if you encounter any difficulties updating.</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.17.Release.4.msi</Url>
</Version>
<Version>
<Number>3.0.16 Release 3</Number>
<IsBeta>false</IsBeta>
<Released>15-Feb-2018</Released>
<Changes>
<Change>Emergency Fix for Lazy Loading bug.</Change>
<Change>Please download Chem4Word-Setup.exe from https://github.com/Chem4Word/Version3/releases/latest if you encounter any difficulties updating.</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.16.Release.3.msi</Url>
</Version>
Expand Down Expand Up @@ -90,7 +104,7 @@
<IsBeta>true</IsBeta>
<Released>21-Nov-2017</Released>
<Changes>
<Change>Handle documents in compatability mode.</Change>
<Change>Handle documents in compatibility mode.</Change>
<Change>Handle error in setting text of 1D labels.</Change>
<Change>Make config files self healing, when options are added or removed.</Change>
</Changes>
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.16 Release 3</Number>
<Number>3.0.17 Release 4</Number>
<IsBeta>false</IsBeta>
<Released>15-Feb-2018</Released>
<Released>06-Mar-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.17 - Release 4</td>
<td><a href="/files3/Chem4Word-Setup.3.0.17.Release.4.msi">Chem4Word-Setup 3.0.17 Release 4</a></td>
</tr>
<tr>
<td>Version 3.0.16 - Release 3</td>
<td><a href="/files3/Chem4Word-Setup.3.0.16.Release.3.msi">Chem4Word-Setup 3.0.16 Release 3</a></td>
Expand Down
4 changes: 4 additions & 0 deletions src/Chem4Word.V3/Helpers/C4wAddInInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public C4wAddInInfo()
{
Directory.CreateDirectory(ProductAppDataPath);
}
if (!Directory.Exists($@"{ProductAppDataPath}\Backups"))
{
Directory.CreateDirectory($@"{ProductAppDataPath}\Backups");
}
if (!Directory.Exists($@"{ProductAppDataPath}\Telemetry"))
{
Directory.CreateDirectory($@"{ProductAppDataPath}\Telemetry");
Expand Down
Loading

0 comments on commit b709c48

Please sign in to comment.