forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataClasses.cs
More file actions
216 lines (185 loc) · 5.25 KB
/
DataClasses.cs
File metadata and controls
216 lines (185 loc) · 5.25 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.IO;
using Ookii.Dialogs;
namespace PluginCore
{
#region Data Objects
/// <summary>
/// Menus items
/// </summary>
public class ItemData
{
public String Id = String.Empty;
public String Tag = String.Empty;
public String Flags = String.Empty;
public ItemData(String id, String tag, String flags)
{
if (id != null) this.Id = id;
if (tag != null) this.Tag = tag;
if (flags != null) this.Flags = flags;
}
}
/// <summary>
/// User custom arguments
/// </summary>
[Serializable]
public class Argument
{
private String key = String.Empty;
private String value = String.Empty;
public Argument() { }
public Argument(String key, String value)
{
this.key = key;
this.value = value;
}
/// <summary>
/// Gets and sets the key
/// </summary>
public String Key
{
get { return this.key; }
set { this.key = value; }
}
/// <summary>
/// Gets and sets the value
/// </summary>
public String Value
{
get { return this.value; }
set { this.value = value; }
}
public override string ToString()
{
return String.IsNullOrEmpty(this.key) ? "New argument" : "$(" + this.key + ")";
}
}
#endregion
#region SDK Management
/// <summary>
/// A SDK should be associated to an object able to provide custom validation
/// </summary>
public interface InstalledSDKOwner
{
/// <summary>
/// Control that sdk.Path points to a valid path location
/// and update sdk.Name and sdk.Version accordingly
/// (invoked when creating a new InstalledSDK object)
/// </summary>
bool ValidateSDK(InstalledSDK sdk);
}
/// <summary>
/// Holds compiler location/version information
/// </summary>
[Serializable]
public class InstalledSDK
{
static public readonly InstalledSDK INVALID_SDK = new InstalledSDK(null);
private String path;
private String name;
private String version;
private bool isValid;
[field: NonSerialized]
private InstalledSDKOwner owner;
[Category("Location")]
[Editor(typeof(VistaFolderNameEditor), typeof(UITypeEditor))]
public String Path
{
get { return this.path; }
set
{
this.path = value;
Validate();
}
}
[Category("Properties")]
public String Name
{
get { return this.name; }
set { this.name = value; }
}
[Category("Properties")]
public String Version
{
get { return this.version; }
set { this.version = value; }
}
[Browsable(false)]
public bool IsValid
{
get
{
if (!isValid) return false;
try
{
if (System.IO.Path.IsPathRooted(path)
&& !Directory.Exists(path) && !File.Exists(path))
return false;
}
catch { return false; }
return true;
}
}
[Browsable(false)]
public InstalledSDKOwner Owner
{
get { return owner; }
set { owner = value; }
}
public InstalledSDK(InstalledSDKOwner owner) { this.owner = owner; }
public InstalledSDK() { this.owner = InstalledSDKContext.Current; }
public int Compare(InstalledSDK sdk)
{
return 0;
}
public override string ToString()
{
return String.IsNullOrEmpty(this.name) ? "New SDK" : this.name;
}
public string ToPreferredSDK()
{
if (!String.IsNullOrEmpty(this.version))
return (this.name ?? "") + ";" + (this.version ?? "") + ";";
else
return (this.name ?? "") + ";" + (this.version ?? "") + ";" + (this.path ?? "");
}
public void Validate()
{
if (owner != null)
{
InstalledSDKOwner o = owner;
owner = null;
isValid = o.ValidateSDK(this);
owner = o;
}
else isValid = true;
}
}
/// <summary>
/// Set InstalledSDK default owner temporarily
///
/// Usage:
/// using(new InstalledSDKContext(owner)) { ... }
/// or
/// InstalledSDKContext isc = new InstalledSDKContext(owner);
/// ...
/// isc.Dispose();
/// </summary>
public class InstalledSDKContext: IDisposable
{
static public InstalledSDKOwner Current;
public InstalledSDKOwner owner;
public InstalledSDKContext(InstalledSDKOwner owner)
{
this.owner = owner;
Current = owner;
}
public void Dispose()
{
if (Current == owner) Current = null;
}
}
#endregion
}