Skip to content

Commit 45aa2ef

Browse files
committed
HelpTopic improvements, including relative paths
1 parent f8f7ba3 commit 45aa2ef

File tree

4 files changed

+68
-14
lines changed

4 files changed

+68
-14
lines changed

Source/ExcelDna.IntelliSense/Providers/IIntelliSenseProvider.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Xml.Serialization;
45

56
namespace ExcelDna.IntelliSense
@@ -58,6 +59,28 @@ public class ArgumentInfo
5859
public List<ArgumentInfo> ArgumentList;
5960
[XmlIgnore]
6061
public string SourcePath; // XllPath for .xll, Workbook Name for Workbook, .xml file path for Xml file
62+
63+
// Not sure where to put this...
64+
internal static string ExpandHelpTopic(string path, string helpTopic)
65+
{
66+
if (string.IsNullOrEmpty(helpTopic))
67+
return helpTopic;
68+
69+
if (helpTopic.StartsWith("http://") || helpTopic.StartsWith("https://") || helpTopic.StartsWith("file://"))
70+
{
71+
if (helpTopic.EndsWith("!0"))
72+
{
73+
helpTopic = helpTopic.Substring(0, helpTopic.Length - 2);
74+
}
75+
}
76+
else if (!Path.IsPathRooted(helpTopic))
77+
{
78+
helpTopic = Path.Combine(path, helpTopic);
79+
}
80+
return helpTopic;
81+
}
82+
83+
6184
}
6285

6386
}

Source/ExcelDna.IntelliSense/Providers/WorkbookIntelliSenseProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class WorkbookRegistrationInfo
2626
readonly string _name;
2727
DateTime _lastUpdate; // Version indicator to enumerate from scratch
2828
object[,] _regInfo = null; // Default value
29+
string _path;
2930

3031
public WorkbookRegistrationInfo(string name)
3132
{
@@ -37,6 +38,7 @@ public void Refresh()
3738
{
3839
var app = (Application)ExcelDnaUtil.Application;
3940
var wb = app.Workbooks[_name];
41+
_path = wb.Path;
4042

4143
try
4244
{
@@ -97,6 +99,8 @@ public IEnumerable<FunctionInfo> GetFunctionInfos()
9799
}
98100
}
99101

102+
helpTopic = FunctionInfo.ExpandHelpTopic(_path, helpTopic);
103+
100104
yield return new FunctionInfo
101105
{
102106
Name = functionName,

Source/ExcelDna.IntelliSense/Providers/XmlIntelliSenseProvider.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ public class XmlRegistrationInfo
1919
string _fileName; // Might be .xml file or Workbook path. Use only if _xmlIntelliSense is null.
2020
string _xmlIntelliSense; // Might be null
2121
XmlIntelliSense _intelliSense; // Might be null - lazy parsed
22+
string _path; // Directory of file, used to expand HelpTopic
2223

2324
public XmlRegistrationInfo(string fileName, string xmlIntelliSense)
2425
{
2526
_fileName = fileName;
2627
_xmlIntelliSense = xmlIntelliSense;
28+
_path = Path.GetDirectoryName(fileName);
2729
}
2830

2931
// Called in a macro context
@@ -43,10 +45,11 @@ public void Refresh()
4345
_intelliSense = XmlIntelliSense.Parse(xml);
4446
if (_intelliSense?.XmlFunctionInfo?.FunctionsList != null)
4547
{
46-
// Fix up SourcePath (is this used?)
48+
// Fix up SourcePath (is this used?) and HelpTopic
4749
foreach (var func in _intelliSense.XmlFunctionInfo.FunctionsList)
4850
{
4951
func.SourcePath = _fileName;
52+
func.HelpTopic = FunctionInfo.ExpandHelpTopic(_path, func.HelpTopic);
5053
}
5154
}
5255
}
@@ -66,7 +69,6 @@ public IEnumerable<FunctionInfo> GetFunctionInfos()
6669
return _intelliSense.XmlFunctionInfo.FunctionsList;
6770
}
6871

69-
7072
}
7173

7274
ExcelSynchronizationContext _syncContextExcel;

Source/ExcelDna.IntelliSense/ToolTipForm.cs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Drawing;
55
using System.Drawing.Drawing2D;
6+
using System.IO;
67
using System.Linq;
78
using System.Windows.Forms;
89

@@ -246,25 +247,49 @@ void MouseButtonUp(Point screenLocation)
246247

247248
void LaunchLink(string address)
248249
{
249-
if (address.StartsWith("http", StringComparison.OrdinalIgnoreCase))
250-
{
251-
Process.Start(address);
252-
}
253-
else
250+
try
254251
{
255-
var parts = address.Split('!');
256-
if (parts.Length == 2)
252+
if (address.StartsWith("http", StringComparison.OrdinalIgnoreCase))
257253
{
258-
// (This is the expected case)
259-
// Assume we have a filename!topicid
260-
Help.ShowHelp(null, parts[0], HelpNavigator.TopicId, parts[1]);
254+
Process.Start(address);
261255
}
262256
else
263257
{
264-
// Just show the file ...?
265-
Help.ShowHelp(null, address);
258+
var parts = address.Split('!');
259+
if (parts.Length == 2)
260+
{
261+
// (This is the expected case)
262+
// Assume we have a filename!topicid
263+
var fileName = parts[0];
264+
var topicId = parts[1];
265+
if (File.Exists(fileName))
266+
{
267+
Help.ShowHelp(null, fileName, HelpNavigator.TopicId, topicId);
268+
}
269+
else
270+
{
271+
MessageBox.Show($"The help link could not be activated:\r\n\r\nThe file {fileName} could not be located.", "IntelliSense by Excel-DNA", MessageBoxButtons.OK, MessageBoxIcon.Error);
272+
}
273+
}
274+
else
275+
{
276+
// Just show the file ...?
277+
if (File.Exists(address))
278+
{
279+
Help.ShowHelp(null, address, HelpNavigator.TableOfContents);
280+
}
281+
else
282+
{
283+
MessageBox.Show($"The help link could not be activated:\r\n\r\nThe file {address} could not be located.", "IntelliSense by Excel-DNA", MessageBoxButtons.OK, MessageBoxIcon.Error);
284+
}
285+
}
266286
}
267287
}
288+
catch (Exception ex)
289+
{
290+
MessageBox.Show($"The help link could not be activated:\r\n\r\n{ex.Message}", "IntelliSense by Excel-DNA", MessageBoxButtons.OK, MessageBoxIcon.Error);
291+
// NOTE: In this case, the Excel process does not quit after closing Excel...
292+
}
268293
}
269294

270295
Point GetMouseLocation(IntPtr lParam)

0 commit comments

Comments
 (0)