-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputBox.class
178 lines (152 loc) · 4.03 KB
/
InputBox.class
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
' Gambas class file
'''
' Name: InputBox
' Author: Timothy Marshal-Nichols
' Company: automationControls
' eMail: [email protected]
' Version: 1.0
' Version Date: Febuuary 2006
' Version History:
'
' TWEAKED BY JOE1962, easuter
'
'''
' Licence Information
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'
' http://www.gnu.org/licenses/gpl.html
'
'''
' Description:
'
' An text input box. A replacement for the Visual Basic InputBox.
'
'''
' Dependencies:
'
' gb - Gambas internal native classes
' gb.qt - Graphical QT toolkit component
'
'''
' External Dependencies:
'
' None
'
'''
' Class Usage:
'
' Call the static method Input
'
' InputBox.Input(Prompt [, Title] [, DefaultValue])
'
' Prompt
' A string message to display in the dialog box. This may contain HTML formatting.
'
' Title
' Optional title of the dialog box. If not set the the Application Title is used.
'
' DefaultValue
' Optional default string displayed in the text entry area. If not set then the text entry area is empty
'
' Returns
' Returns the string in the text entry area if the OK button is pressed.
' Returns an empty string (“”) if the Cancel button is pressed
'
' Examples:
'
' ' Setting just the prompt. HTML formatting is used for the prompt.
' DIM returnString AS String
' returnString = InputBox.Input("Input String: <b>Bold Value</b><br>Another line of text")
' IF returnString THEN
' ' Do something with returnString
' END IF
'
' ' Setting the prompt and dialog title.
' DIM returnString AS String
' returnString = InputBox.Input("Input Value", "Show a new title")
' IF returnString THEN
' ' Do something with returnString
' END IF
'
' ' Setting the prompt and default value.
' DIM returnString AS String
' returnString = InputBox.Input("Input Value", "", "Set a default value")
' IF returnString THEN
' ' Do something with returnString
' END IF
'
'''
STATIC returnValue AS String
'''
''' InputBox display method
'''
STATIC PUBLIC FUNCTION Input(Prompt AS String, OPTIONAL Title AS String, OPTIONAL DefaultValue AS String) AS String
DIM box AS NEW InputBox
' Set input box prompt
box.Prompt = Prompt
' Set input box title
IF Title THEN
box.Title = Title
ELSE
box.Title = Application.Title
END IF
' Set default value
IF DefaultValue THEN
box.DefaultValue = DefaultValue
ELSE
box.DefaultValue = ""
END IF
' Init return string
returnValue = ""
box.ShowDialog
RETURN returnValue
END
'''
''' Properties
'''
' Read/Write the prompt
PUBLIC PROPERTY Prompt AS String
PRIVATE SUB Prompt_Write(Value AS String)
TextLabelPrompt.Text = Value
END
PRIVATE FUNCTION Prompt_Read() AS String
RETURN TextLabelPrompt.Text
END
' Read/Write the default value
PUBLIC PROPERTY DefaultValue AS String
PRIVATE SUB DefaultValue_Write(Value AS String)
' We use Clear and Insert because this moves the
' cursor to the end of the default text
TextBox1.Clear()
TextBox1.Insert(Value)
' select default value string:
TextBox1.SelectAll
END
PRIVATE FUNCTION DefaultValue_Read() AS String
RETURN TextBox1.Text
END
PUBLIC SUB btnOK_Click()
' Set the value to be returned by the Input static method
returnValue = TextBox1.Text
ME.Close
END
PUBLIC SUB btnCancel_Click()
ME.Close
END
PUBLIC SUB TextBox1_KeyPress()
' Check for ENTER key and run OK button.
END
''' End of InputBox '''