This repository has been archived by the owner on Nov 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
VariableChooser.cs
98 lines (81 loc) · 2.65 KB
/
VariableChooser.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
using Microsoft.SqlServer.Dts.Runtime;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
#if LINQ_SUPPORTED
using System.Linq;
#endif
namespace com.webkingsoft.JSONSource_Common
{
public partial class VariableChooser : Form
{
private Variables _vars;
private Variable _result;
public VariableChooser(Variables vars) : this(vars, null, null) { }
public VariableChooser(Variables vars, IEnumerable<TypeCode> validCodes, IEnumerable<string> validScopes)
{
if (vars == null)
throw new ArgumentException("Passed a null variables object to variable chooser.");
_vars = vars;
InitializeComponent();
DialogResult = DialogResult.Cancel;
varList.Items.Clear();
foreach (Variable v in _vars)
{
// Filter by valid codes and validScopes
if (validCodes != null && !validCodes.Contains<TypeCode>(v.DataType))
{
continue;
}
if (validScopes!=null && !validScopes.Contains(v.Namespace)) {
continue;
}
varList.Items.Add(v.QualifiedName);
}
if (varList.Items.Count > 0)
varList.SelectedIndex = 0;
}
public void FilterByTypes(IEnumerable<TypeCode> validCodes)
{
foreach (Variable v in _vars)
{
if (v.DataType == TypeCode.String)
{
varList.Items.Add(v.QualifiedName);
}
}
}
private void VariableChooser_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult = System.Windows.Forms.DialogResult.Cancel;
_result = null;
}
private void button1_Click(object sender, EventArgs e)
{
if (varList.SelectedIndex != -1)
{
string cur = varList.Items[varList.SelectedIndex].ToString();
foreach (Variable v in _vars)
if (v.QualifiedName == cur)
{
_result = v;
DialogResult = DialogResult.OK;
return;
}
}
DialogResult = DialogResult.Cancel;
_result = null;
}
public Variable GetResult()
{
return _result;
}
}
}