-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomRibbon.cs
105 lines (91 loc) · 3.1 KB
/
CustomRibbon.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using ExcelDna.Integration;
using ExcelDna.Integration.CustomUI;
using System;
using System.IO;
using System.Resources;
using System.Runtime.InteropServices;
using Application = Microsoft.Office.Interop.Excel.Application;
namespace Campagna
{
[ComVisible(true)]
public class CustomRibbon : ExcelRibbon
{
private readonly Application _excel = (Application)ExcelDnaUtil.Application;
private readonly IRibbonUI _thisRibbon;
private bool _isStartup = true;
private readonly ProgressBar _progressBar = new ProgressBar();
public override string GetCustomUI(string ribbonId)
{
string ribbonXml = GetCustomRibbonXML();
return ribbonXml;
}
private string GetCustomRibbonXML()
{
string ribbonXml;
var thisAssembly = typeof(CustomRibbon).Assembly;
var resourceName = typeof(CustomRibbon).Namespace + ".CustomRibbon.xml";
using (Stream stream = thisAssembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
ribbonXml = reader.ReadToEnd() ?? throw new MissingManifestResourceException(resourceName);
}
return ribbonXml;
}
public string GetSelectedItemID(IRibbonControl control)
{
if (_isStartup == false)
{
return control.Id;
}
else
{
_isStartup = false;
Globals._numberIterations = 1000;
return "ID1000";
}
}
public void GetEditBoxText(IRibbonControl control, string returnedVal)
{
try
{
Globals._randomSeed = int.Parse(returnedVal);
}
catch
{
Globals._randomSeed = 0;
}
}
public void OnActionButton(IRibbonControl control)
{
switch (control.Id)
{
case "generateResults":
using (var controller = new ExcelController(_excel, _thisRibbon, _progressBar))
{
if (Globals._numberIterations == 0)
return;
if (Globals._randomSeed != 0)
{
Globals._rand = new Random(Globals._randomSeed);
}
controller.GetResults();
Globals._rand = new Random();
}
break;
default:
break;
}
}
public void OnActionDropDown(IRibbonControl control, string selectedId, int index)
{
switch (control.Id)
{
case "dropDownIterations":
Globals._numberIterations = int.Parse(selectedId.Substring(2, selectedId.Length - 2));
break;
default:
break;
}
}
}
}