Skip to content

Commit 0a799aa

Browse files
committed
Refactor IntelliSenseProviders
1 parent 23b1607 commit 0a799aa

12 files changed

+808
-548
lines changed

Source/ExcelDna.IntelliSense.Host/MyFunctions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace ExcelDna.CustomAddin
88
// These functions - are just here for testing...
99
public class MyFunctions
1010
{
11-
[ExcelFunction(Description = "Returns the sum of two particular numbers that are given")]
11+
[ExcelFunction(Description = "Returns the sum of two particular numbers that are given\r\n(As a test, of course)")]
1212
public static double AddThem(
1313
[ExcelArgument(Name = "Augend", Description = "is the first number, to which will be added")] double v1,
1414
[ExcelArgument(Name = "Addend", Description = "is the second number that will be added")] double v2)
@@ -18,7 +18,7 @@ public static double AddThem(
1818

1919
[ExcelFunction(Description = "--------------------")]
2020
public static double AdxThem(
21-
[ExcelArgument(Name = "Augend", Description = "is the first number, to which will be added")] double v1,
21+
[ExcelArgument(Name = "tag", Description = "is the first number, to which will be added")] double v1,
2222
[ExcelArgument(Name = "Addend", Description = "is the second number that will be added")] double v2)
2323
{
2424
return v1 + v2;

Source/ExcelDna.IntelliSense/ExcelDna.IntelliSense.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@
7272
</ItemGroup>
7373
<ItemGroup>
7474
<Compile Include="FormattedText.cs" />
75+
<Compile Include="Providers\ExcelDnaIntelliSenseProvider.cs" />
76+
<Compile Include="Providers\WorkbookIntelliSenseProvider.cs" />
77+
<Compile Include="Providers\XmlIntelliSenseProvider.cs" />
7578
<Compile Include="UIMonitor\FormulaEditWatcher.cs" />
7679
<Compile Include="UIMonitor\FormulaParser.cs" />
7780
<Compile Include="IntelliSenseDisplay.cs" />
7881
<Compile Include="IntelliSenseHelper.cs" />
79-
<Compile Include="IntelliSenseProvider.cs" />
82+
<Compile Include="Providers\IIntelliSenseProvider.cs" />
8083
<Compile Include="IntelliSenseServer.cs" />
8184
<Compile Include="Logging.cs" />
8285
<Compile Include="UIMonitor\PopupListWatcher.cs" />
@@ -88,7 +91,7 @@
8891
<Compile Include="UIMonitor\UIMonitor.cs" />
8992
<Compile Include="UIMonitor\WindowWatcher.cs" />
9093
<Compile Include="Win32Helper.cs" />
91-
<Compile Include="LoaderNotification.cs" />
94+
<Compile Include="Providers\LoaderNotification.cs" />
9295
<Compile Include="WindowResizer.cs" />
9396
<Compile Include="UIMonitor\WinEvents.cs" />
9497
<Compile Include="UIMonitor\XlCall.cs" />

Source/ExcelDna.IntelliSense/IntelliSenseDisplay.cs

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@
77

88
namespace ExcelDna.IntelliSense
99
{
10-
class IntelliSenseFunctionInfo
11-
{
12-
public class ArgumentInfo
13-
{
14-
public string ArgumentName;
15-
public string Description;
16-
}
17-
public string FunctionName;
18-
public string Description;
19-
public List<ArgumentInfo> ArgumentList;
20-
public string SourcePath; // XllPath for .xll, Workbook Name for Workbook
21-
}
22-
2310
// CONSIDER: Revisit UI Automation Threading: http://msdn.microsoft.com/en-us/library/windows/desktop/ee671692(v=vs.85).aspx
2411
// And this threading sample using tlbimp version of Windows 7 native UIA: http://code.msdn.microsoft.com/Windows-7-UI-Automation-6390614a/sourcecode?fileId=21469&pathId=715901329
2512
// NOTE: TrackFocus example shows how to do a window 'natively'.
@@ -33,8 +20,8 @@ class IntelliSenseDisplay : IDisposable
3320
SynchronizationContext _syncContextMain;
3421
readonly UIMonitor _uiMonitor;
3522

36-
readonly Dictionary<string, IntelliSenseFunctionInfo> _functionInfoMap =
37-
new Dictionary<string, IntelliSenseFunctionInfo>(StringComparer.CurrentCultureIgnoreCase);
23+
readonly Dictionary<string, FunctionInfo> _functionInfoMap =
24+
new Dictionary<string, FunctionInfo>(StringComparer.CurrentCultureIgnoreCase);
3825

3926
// Need to make these late ...?
4027
ToolTipForm _descriptionToolTip;
@@ -58,7 +45,7 @@ public IntelliSenseDisplay(SynchronizationContext syncContextMain, UIMonitor uiM
5845
}
5946

6047
// TODO: Still not sure how to delete / unregister...
61-
internal void UpdateFunctionInfos(IEnumerable<IntelliSenseFunctionInfo> functionInfos)
48+
internal void UpdateFunctionInfos(IEnumerable<FunctionInfo> functionInfos)
6249
{
6350
foreach (var fi in functionInfos)
6451
{
@@ -262,7 +249,7 @@ void FormulaEditTextChange(string formulaPrefix, Rect editWindowBounds, Rect exc
262249
int currentArgIndex;
263250
if (FormulaParser.TryGetFormulaInfo(formulaPrefix, out functionName, out currentArgIndex))
264251
{
265-
IntelliSenseFunctionInfo functionInfo;
252+
FunctionInfo functionInfo;
266253
if (_functionInfoMap.TryGetValue(functionName, out functionInfo))
267254
{
268255
if (_argumentsToolTip != null)
@@ -312,7 +299,7 @@ void FunctionListSelectedItemChange(string selectedItemText, Rect selectedItemBo
312299
{
313300
Logger.Display.Verbose($"IntelliSenseDisplay - PopupListSelectedItemChanged - {selectedItemText} List/Item Bounds: {listBounds} / {selectedItemBounds}");
314301

315-
IntelliSenseFunctionInfo functionInfo;
302+
FunctionInfo functionInfo;
316303
if (_functionInfoMap.TryGetValue(selectedItemText, out functionInfo))
317304
{
318305
// It's ours!
@@ -339,7 +326,7 @@ void FunctionListMove(Rect selectedItemBounds, Rect listBounds)
339326
// TODO: Performance / efficiency - cache these somehow
340327
// TODO: Probably not a good place for LINQ !?
341328
static readonly string[] s_newLineStringArray = new string[] { Environment.NewLine };
342-
IEnumerable<TextLine> GetFunctionDescriptionOrNull(IntelliSenseFunctionInfo functionInfo)
329+
IEnumerable<TextLine> GetFunctionDescriptionOrNull(FunctionInfo functionInfo)
343330
{
344331
var description = functionInfo.Description;
345332
if (string.IsNullOrEmpty(description))
@@ -355,12 +342,12 @@ IEnumerable<TextLine> GetFunctionDescriptionOrNull(IntelliSenseFunctionInfo func
355342
}});
356343
}
357344

358-
FormattedText GetFunctionIntelliSense(IntelliSenseFunctionInfo functionInfo, int currentArgIndex)
345+
FormattedText GetFunctionIntelliSense(FunctionInfo functionInfo, int currentArgIndex)
359346
{
360-
var nameLine = new TextLine { new TextRun { Text = functionInfo.FunctionName + "(" } };
347+
var nameLine = new TextLine { new TextRun { Text = functionInfo.Name + "(" } };
361348
if (functionInfo.ArgumentList.Count > 0)
362349
{
363-
var argNames = functionInfo.ArgumentList.Take(currentArgIndex).Select(arg => arg.ArgumentName).ToArray();
350+
var argNames = functionInfo.ArgumentList.Take(currentArgIndex).Select(arg => arg.Name).ToArray();
364351
if (argNames.Length >= 1)
365352
{
366353
nameLine.Add(new TextRun { Text = string.Join(", ", argNames) });
@@ -378,11 +365,11 @@ FormattedText GetFunctionIntelliSense(IntelliSenseFunctionInfo functionInfo, int
378365

379366
nameLine.Add(new TextRun
380367
{
381-
Text = functionInfo.ArgumentList[currentArgIndex].ArgumentName,
368+
Text = functionInfo.ArgumentList[currentArgIndex].Name,
382369
Style = System.Drawing.FontStyle.Bold
383370
});
384371

385-
argNames = functionInfo.ArgumentList.Skip(currentArgIndex + 1).Select(arg => arg.ArgumentName).ToArray();
372+
argNames = functionInfo.ArgumentList.Skip(currentArgIndex + 1).Select(arg => arg.Name).ToArray();
386373
if (argNames.Length >= 1)
387374
{
388375
nameLine.Add(new TextRun {Text = ", " + string.Join(", ", argNames)});
@@ -403,13 +390,13 @@ FormattedText GetFunctionIntelliSense(IntelliSenseFunctionInfo functionInfo, int
403390
return formattedText;
404391
}
405392

406-
TextLine GetArgumentDescription(IntelliSenseFunctionInfo.ArgumentInfo argumentInfo)
393+
TextLine GetArgumentDescription(FunctionInfo.ArgumentInfo argumentInfo)
407394
{
408395
return new TextLine {
409396
new TextRun
410397
{
411398
Style = System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic,
412-
Text = argumentInfo.ArgumentName + ": "
399+
Text = argumentInfo.Name + ": "
413400
},
414401
new TextRun
415402
{
@@ -442,24 +429,24 @@ public void Dispose()
442429

443430
// TODO: Think about case again
444431
// TODO: Consider locking...
445-
public void RegisterFunctionInfo(IntelliSenseFunctionInfo functionInfo)
432+
public void RegisterFunctionInfo(FunctionInfo functionInfo)
446433
{
447434
// TODO : Dictionary from KeyLookup
448-
IntelliSenseFunctionInfo oldFunctionInfo;
449-
if (!_functionInfoMap.TryGetValue(functionInfo.FunctionName, out oldFunctionInfo))
435+
FunctionInfo oldFunctionInfo;
436+
if (!_functionInfoMap.TryGetValue(functionInfo.Name, out oldFunctionInfo))
450437
{
451-
_functionInfoMap.Add(functionInfo.FunctionName, functionInfo);
438+
_functionInfoMap.Add(functionInfo.Name, functionInfo);
452439
}
453440
else
454441
{
455442
// Update against the function name
456-
_functionInfoMap[functionInfo.FunctionName] = functionInfo;
443+
_functionInfoMap[functionInfo.Name] = functionInfo;
457444
}
458445
}
459446

460-
public void UnregisterFunctionInfo(IntelliSenseFunctionInfo functionInfo)
447+
public void UnregisterFunctionInfo(FunctionInfo functionInfo)
461448
{
462-
_functionInfoMap.Remove(functionInfo.FunctionName);
449+
_functionInfoMap.Remove(functionInfo.Name);
463450
}
464451
}
465452
}

0 commit comments

Comments
 (0)