forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommsBase.cs
69 lines (52 loc) · 1.94 KB
/
CommsBase.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
using System.Collections;
namespace MissionPlanner.Comms
{
public delegate string SettingsOption(string name, string value, bool set = false);
public delegate void ApplyThemeTo(object control);
public enum inputboxreturn
{
OK,
Cancel,
NotSet
}
public delegate inputboxreturn InputBoxShow(string title, string prompttext, ref string text);
public abstract class CommsBase
{
private readonly Hashtable cache = new Hashtable();
public static event InputBoxShow InputBoxShow;
public static event SettingsOption Settings;
public static event ApplyThemeTo ApplyTheme;
protected virtual void ApplyThemeTo(object control)
{
if (ApplyTheme != null) ApplyTheme(control);
}
protected virtual inputboxreturn OnInputBoxShow(string title, string prompttext, ref string text)
{
if (InputBoxShow == null)
return inputboxreturn.NotSet;
return InputBoxShow(title, prompttext, ref text);
}
protected virtual string OnSettings(string name, string value, bool set = false)
{
// answer using external function
if (Settings != null)
{
// get the external saved value
var answer = Settings(name, value, set);
// return value if its a bad answer
if (answer == "")
return value;
// return external value
return answer;
}
// save it if we dont have a config
if (set)
cache[name] = value;
// return it if we have seen it
if (cache.ContainsKey(name))
return cache[name].ToString();
// return what was passed in if no answer
return value;
}
}
}