diff options
Diffstat (limited to 'OpenSim/Tools/OpenSim.GUI/InputTextBoxControl.cs')
-rw-r--r-- | OpenSim/Tools/OpenSim.GUI/InputTextBoxControl.cs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/OpenSim/Tools/OpenSim.GUI/InputTextBoxControl.cs b/OpenSim/Tools/OpenSim.GUI/InputTextBoxControl.cs new file mode 100644 index 0000000..91b3f60 --- /dev/null +++ b/OpenSim/Tools/OpenSim.GUI/InputTextBoxControl.cs | |||
@@ -0,0 +1,88 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using System.Windows.Forms; | ||
5 | |||
6 | namespace OpenSim.GUI | ||
7 | { | ||
8 | class InputTextBoxControl:System.Windows.Forms.TextBox | ||
9 | { | ||
10 | public InputTextBoxControl() | ||
11 | { | ||
12 | this.KeyDown += new System.Windows.Forms.KeyEventHandler(TextInputControl_KeyDown); | ||
13 | } | ||
14 | |||
15 | |||
16 | private List<string> CommandHistory = new List<string>(); | ||
17 | private bool InHistory = false; | ||
18 | private int HistoryPosition = -1; | ||
19 | |||
20 | void TextInputControl_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) | ||
21 | { | ||
22 | |||
23 | |||
24 | if (e.KeyCode == Keys.Enter && InHistory == false) | ||
25 | { | ||
26 | CommandHistory.Add(this.Text); | ||
27 | } | ||
28 | |||
29 | |||
30 | if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) | ||
31 | { | ||
32 | // if not inside buffer, enter | ||
33 | // InBuffer = true | ||
34 | //Console.WriteLine("History: Check"); | ||
35 | if (InHistory == false) | ||
36 | { | ||
37 | if (this.Text != "") | ||
38 | { | ||
39 | //Console.WriteLine("History: Add"); | ||
40 | CommandHistory.Add(this.Text); | ||
41 | HistoryPosition = CommandHistory.Count; | ||
42 | } | ||
43 | else | ||
44 | { | ||
45 | //HistoryPosition = CommandHistory.Count + 1; | ||
46 | } | ||
47 | //Console.WriteLine("History: InHistory"); | ||
48 | InHistory = true; | ||
49 | } | ||
50 | |||
51 | if (e.KeyCode == Keys.Up) | ||
52 | HistoryPosition -= 1; | ||
53 | if (e.KeyCode == Keys.Down) | ||
54 | HistoryPosition += 1; | ||
55 | |||
56 | if (HistoryPosition > CommandHistory.Count - 1) | ||
57 | HistoryPosition = -1; | ||
58 | if (HistoryPosition < -1) | ||
59 | HistoryPosition = CommandHistory.Count - 1; | ||
60 | |||
61 | //Console.WriteLine("History: Pos: " + HistoryPosition); | ||
62 | //Console.WriteLine("History: HaveInHistCount: " + CommandHistory.Count); | ||
63 | if (CommandHistory.Count != 0) | ||
64 | { | ||
65 | if (HistoryPosition != -1) | ||
66 | { | ||
67 | //Console.WriteLine("History: Getting"); | ||
68 | //this.Text = CommandHistory.Item(HistoryPosition); | ||
69 | this.Text = CommandHistory[HistoryPosition]; | ||
70 | this.SelectionStart = this.Text.Length; | ||
71 | this.SelectionLength = 0; | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | //Console.WriteLine("History: Nothing"); | ||
76 | this.Text = ""; | ||
77 | } | ||
78 | } | ||
79 | e.Handled = true; | ||
80 | } else { | ||
81 | InHistory = false; | ||
82 | HistoryPosition = -1; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | |||
87 | } | ||
88 | } | ||