Skip to content

Commit e802f3d

Browse files
committed
ControlExtensions cache dataitem reference
1 parent 69ecd42 commit e802f3d

4 files changed

Lines changed: 106 additions & 39 deletions

File tree

ControlExtensions/ControlExtensions.gcomp/ControlExtensions.gcomp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<SourceFile Checksum="1812DD6FC374F1566C87E389B2429A4781C63F57FDDE0EE8AF314636B894F3C0658BC3360005BFC395A0302306FCBAF92C6827FDD0B36CC3A7402100EE669509" Timestamp="1D810EB54098307" xmlns="http://www.ni.com/PlatformFramework">
2+
<SourceFile Checksum="9B8E83C533CDA331CB367B07AD87B3262B0299BD9905D496A7BB18C494891113663AB53B4BC07985FFA8F51372A1162DDCC6C1FD155C5FD08B2DBE8DDE98D7A2" Timestamp="1D81BAB8044BA15" xmlns="http://www.ni.com/PlatformFramework">
33
<SourceModelFeatureSet>
44
<ParsableNamespace AssemblyFileVersion="9.1.0.50238" FeatureSetName="GComponentFeatureSet" Name="http://www.ni.com/GComponent.xsd" OldestCompatibleVersion="9.0.0.0" Version="9.0.0.49152" />
55
<ParsableNamespace AssemblyFileVersion="9.1.0.50238" FeatureSetName="JavaScript Library" Name="http://www.ni.com/JavaScriptLibrary" OldestCompatibleVersion="6.4.0.49152" Version="6.4.0.49152" />
@@ -9,7 +9,15 @@
99
<ComponentDefinition DefaultConfigurationName="Configuration1" Id="ff4afffde9164b77b6f7a16980894ac2" RootNamespaceId="4072e95289a64408bdf084daa61499d7" xmlns="http://www.ni.com/GComponent.xsd">
1010
<Icon Id="1662d89a18404c96bd62ff103598eed7" ListViewIconCrop="0 0 40 40" xmlns="http://www.ni.com/PlatformFramework">
1111
<IconPanel Height="[float]40" Id="c74c6c5796c64edb90ada8881ff6e812" Left="[float]0" PanelSizeMode="Resize" Top="[float]0" Width="[float]40">
12-
<IconTemplate Height="[float]40" Id="1512e338d4d54ed98c72534a7f4c9ace" Left="[float]0" TemplateName="[string]Blank" Top="[float]0" Width="[float]40" />
12+
<IconTemplate ClipMargin="[SMThickness]3,3,3,3" Height="[float]40" HorizontalAlignment="[HorizontalAlignment]Stretch" Id="a52fe506c2d843e98968a84f1fc1ff43" Left="[float]0" TemplateName="[string]Banner" Top="[float]0" VerticalAlignment="[VerticalAlignment]Stretch" Width="[float]40">
13+
<Path Data="[PathGeometry]M 0,11 L 0,2 C 0,0.899999976 0.899999976,0 2,0 L 2,11 L 0,11 Z" Fill="[SMSolidColorBrush]#ffa35a13" Height="[float]11" HorizontalAlignment="[HorizontalAlignment]Left" Id="a34551bf284941d8b5e272f96d0c0d04" IsHitTestVisible="[bool]False" Left="[float]0" Margin="[SMThickness]2,2,2,2" MinHeight="[float]1" MinWidth="[float]1" Top="[float]0" VerticalAlignment="[VerticalAlignment]Top" Width="[float]2" />
14+
<Rectangle Fill="[SMSolidColorBrush]#ffa35a13" Height="[float]11" Id="39628edb376043a4a12cca591381a48c" IsHitTestVisible="[bool]False" Left="[float]0" Margin="[SMThickness]4,2,4,2" MinHeight="[float]1" MinWidth="[float]1" Top="[float]0" VerticalAlignment="[VerticalAlignment]Top" Width="[float]NaN" />
15+
<Path Data="[PathGeometry]M 2,11 L 2,2 C 2,0.899999976 1.10000002,0 0,0 L 0,11 L 2,11 Z" Fill="[SMSolidColorBrush]#ffa35a13" Height="[float]11" HorizontalAlignment="[HorizontalAlignment]Right" Id="941904fd3a7549b283a207804020067c" IsHitTestVisible="[bool]False" Left="[float]0" Margin="[SMThickness]2,2,2,2" MinHeight="[float]1" MinWidth="[float]1" Top="[float]0" VerticalAlignment="[VerticalAlignment]Top" Width="[float]2" />
16+
</IconTemplate>
17+
<Text Foreground="[SMColor]#ffffffff" Height="[float]11" Id="9b21998ccb94db486366937220b1efc" Left="[float]3" SizeMode="[TextModelSizeMode]Fixed" Text="[string]Control" TextAlignment="[TextAlignment]Left" TextWrapping="[TextWrapping]Wrap" Top="[float]2" VerticalScrollBarVisibility="[ScrollBarVisibility]Hidden" Width="[float]35">
18+
<FontSetting FontFamily="Segoe UI" FontSize="6" Id="1361b0f7b41d415290580c80be773bb8" />
19+
</Text>
20+
<Image BaseName="[string]Image" Height="[float]22" Id="e530e2f06c04d9586fcb770a8684d0d" Left="[float]23" Source="[EmbeddedDrawingImage]&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#xA;&lt;svg&#xA; height=&quot;24px&quot;&#xA; viewBox=&quot;0 0 24 24&quot;&#xA; width=&quot;24px&quot;&#xA; fill=&quot;#FFFFFF&quot;&#xA; version=&quot;1.1&quot;&#xA; id=&quot;svg6&quot;&#xA; sodipodi:docname=&quot;extension_white_24dp.svg&quot;&#xA; inkscape:version=&quot;1.1 (c68e22c387, 2021-05-23)&quot;&#xA; xmlns:inkscape=&quot;http://www.inkscape.org/namespaces/inkscape&quot;&#xA; xmlns:sodipodi=&quot;http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd&quot;&#xA; xmlns=&quot;http://www.w3.org/2000/svg&quot;&#xA; xmlns:svg=&quot;http://www.w3.org/2000/svg&quot;&gt;&#xA; &lt;defs&#xA; id=&quot;defs10&quot; /&gt;&#xA; &lt;sodipodi:namedview&#xA; id=&quot;namedview8&quot;&#xA; pagecolor=&quot;#ffffff&quot;&#xA; bordercolor=&quot;#666666&quot;&#xA; borderopacity=&quot;1.0&quot;&#xA; inkscape:pageshadow=&quot;2&quot;&#xA; inkscape:pageopacity=&quot;0.0&quot;&#xA; inkscape:pagecheckerboard=&quot;true&quot;&#xA; showgrid=&quot;false&quot;&#xA; inkscape:zoom=&quot;33.791667&quot;&#xA; inkscape:cx=&quot;8.567201&quot;&#xA; inkscape:cy=&quot;11.156597&quot;&#xA; inkscape:window-width=&quot;1920&quot;&#xA; inkscape:window-height=&quot;996&quot;&#xA; inkscape:window-x=&quot;-8&quot;&#xA; inkscape:window-y=&quot;-8&quot;&#xA; inkscape:window-maximized=&quot;1&quot;&#xA; inkscape:current-layer=&quot;svg6&quot; /&gt;&#xA; &lt;path&#xA; d=&quot;M 0,0 H 30 V 30 H 0 Z&quot;&#xA; fill=&quot;none&quot;&#xA; id=&quot;path2&quot;&#xA; style=&quot;stroke-width:1.25&quot; /&gt;&#xA; &lt;path&#xA; d=&quot;M 11.285714,8.857144 H 10.857143 V 7.714286 C 10.857143,7.399999 10.6,7.142857 10.285714,7.142857 H 9.142856 V 6.714286 C 9.142856,6.319999 8.822857,6 8.428571,6 8.034286,6 7.714286,6.319999 7.714286,6.714286 V 7.142857 H 6.571429 c -0.314287,0 -0.568573,0.257142 -0.568573,0.571429 V 8.8 H 6.42857 c 0.425716,0 0.771429,0.345715 0.771429,0.771429 0,0.425713 -0.345713,0.771429 -0.771429,0.771429 H 6 v 1.085713 C 6,11.742857 6.257142,12 6.571429,12 h 1.085713 v -0.428572 c 0,-0.425714 0.345716,-0.771429 0.771429,-0.771429 0.425714,0 0.771429,0.345715 0.771429,0.771429 V 12 h 1.085714 C 10.6,12 10.857143,11.742857 10.857143,11.428571 v -1.142857 h 0.428571 C 11.680001,10.285714 12,9.965714 12,9.571429 12,9.177143 11.680001,8.857144 11.285714,8.857144 Z&quot;&#xA; id=&quot;path4&quot;&#xA; style=&quot;stroke-width:0.285715&quot; /&gt;&#xA; &lt;rect&#xA; style=&quot;opacity:0;fill:#0000ff;fill-rule:evenodd;stroke-width:1.47807&quot;&#xA; id=&quot;rect335&quot;&#xA; width=&quot;18.75&quot;&#xA; height=&quot;18.75&quot;&#xA; x=&quot;0&quot;&#xA; y=&quot;0&quot; /&gt;&#xA;&lt;/svg&gt;&#xA;" Stretch="[SMStretch]Uniform" Top="[float]-3" Width="[float]22" />
1321
</IconPanel>
1422
</Icon>
1523
<CompilerSymbolTable Id="bf68540af73e4dedb2a68b647d2a5430" xmlns="http://www.ni.com/PlatformFramework" />
@@ -18,7 +26,6 @@
1826
<GLibraryProperties Id="38902c40f45448619c0731b2a0c34776" />
1927
<ComponentItemProperties AlwaysInclude="True" AssociatedEnvoyId="d53aefc799d54c8c8f6fed525bf4eb03" Id="413bb64a99e54fc695d4b4b5a1cf96a4" />
2028
<ComponentItemProperties AssociatedEnvoyId="fff5c37face74d2da1b733564457aebd" Exported="True" Id="a847c037b17c4befa29a34d451ae2a67" />
21-
<ComponentItemProperties AssociatedEnvoyId="6fab65d1d78c42528c7035b569fe4c97" Exported="True" Id="80244dd879e940bbb95ca6f605e82ff7" />
2229
</ComponentConfiguration>
2330
</ComponentDefinition>
2431
<EnvoyManagerFile Id="8fcaac3fb1a144e3919e1a53dddeeb1a" xmlns="http://www.ni.com/PlatformFramework">

ControlExtensions/ControlExtensions.gcomp/Support/ControlExtensions.js

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,55 @@
11
(function () {
22
'use strict';
33

4-
const obtainJavaScriptReferenceGObject = function () {
5-
// Find web application
6-
const webAppElements = document.querySelectorAll('ni-web-application');
7-
if (webAppElements.length !== 1) {
8-
throw new Error('Expected a single ni-web-application element in page.');
4+
class DataItem {
5+
constructor (viName, dataItemPath) {
6+
this._viName = viName;
7+
this._dataItemPath = dataItemPath;
8+
this._vireo = undefined;
9+
this._vireoHelpers = undefined;
10+
this._valueRef = undefined;
911
}
10-
const [webAppElement] = webAppElements;
1112

12-
const isSupported = webAppElement && webAppElement.vireoInstance && webAppElement.vireoHelpers;
13-
if (!isSupported) {
14-
throw new Error('ControlExtensions not supported in this version of G Web Development Software.');
13+
getValueRef () {
14+
if (this._valueRef === undefined) {
15+
// Find web application
16+
const webAppElements = document.querySelectorAll('ni-web-application');
17+
if (webAppElements.length !== 1) {
18+
throw new Error('Expected a single ni-web-application element in page.');
19+
}
20+
const [webAppElement] = webAppElements;
21+
22+
const isSupported = webAppElement && webAppElement.vireoInstance && webAppElement.vireoHelpers;
23+
if (!isSupported) {
24+
throw new Error('Not supported in this version of G Web Development Software.');
25+
}
26+
27+
// Find vireo instance
28+
const vireo = webAppElement.vireoInstance;
29+
const vireoHelpers = webAppElement.vireoHelpers;
30+
31+
// Read value from dataspace
32+
const viNameEncoded = vireoHelpers.staticHelpers.encodeIdentifier(this._viName);
33+
const valueRef = vireo.eggShell.findValueRef(viNameEncoded, this._dataItemPath);
34+
this._vireo = vireo;
35+
this._vireoHelpers = vireoHelpers;
36+
this._valueRef = valueRef;
37+
}
38+
return this._valueRef;
1539
}
40+
}
1641

17-
// Find vireo instance
18-
const vireo = webAppElement.vireoInstance;
19-
const vireoHelpers = webAppElement.vireoHelpers;
42+
class ReferenceDataItem extends DataItem {
43+
getValue () {
44+
const valueRef = this.getValueRef();
45+
return this._vireo.eggShell.readJavaScriptRefNum(valueRef);
46+
}
47+
}
48+
49+
const obtainJavaScriptReferenceGObjectDataItem = new ReferenceDataItem('ControlExtensions::Support::Obtain JavaScript Reference - GObject.gvi', 'dataItem_Referenceprobe');
2050

21-
// Read value from dataspace
22-
const viName = 'ControlExtensions::Support::Obtain JavaScript Reference - GObject.gvi';
23-
const viNameEncoded = vireoHelpers.staticHelpers.encodeIdentifier(viName);
24-
const valueRef = vireo.eggShell.findValueRef(viNameEncoded, 'dataItem_Referenceprobe');
25-
const value = vireo.eggShell.readJavaScriptRefNum(valueRef);
51+
const obtainJavaScriptReferenceGObject = function () {
52+
const value = obtainJavaScriptReferenceGObjectDataItem.getValue();
2653
if ((value && value.element instanceof HTMLElement) === false) {
2754
throw new Error('Expected reference to be an HTML control');
2855
}

0 commit comments

Comments
 (0)