-
Notifications
You must be signed in to change notification settings - Fork 6
/
GtkEntryDialog.st
66 lines (52 loc) · 1.7 KB
/
GtkEntryDialog.st
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
Object subclass: GtkEntryDialog [
| dialog labelWidget entryWidget hasPressedOk buttons defaultButton |
GtkEntryDialog class >> title: aTitle text: aDescription [
<category: 'instance creation'>
^ (self new)
title: aTitle text: aDescription;
yourself
]
beOkCancel [
buttons := #( ('Ok' #gtkResponseOk) ('Cancel' #gtkResponseCancel))
]
beYesNo [
buttons := #( ('Yes' #gtkResponseYes) ('No' #gtkResponseNo))
]
title: aTitle text: aDescription [
<category: 'initialization'>
hasPressedOk := false.
dialog := GTK.GtkDialog newWithButtons: aTitle parent: nil flags: 0 varargs: {nil}.
self buildCentralWidget: aDescription on: dialog.
"dialog showModalOnAnswer: [ :dlg :res |
res = GTK.Gtk gtkResponseYes ifTrue: [ hasPressedOk := true ].
dlg destroy ]"
]
hasPressedOk: aBlock [
<category: 'testing'>
dialog showModalOnAnswer: [ :dlg :res |
res = defaultButton ifTrue: [ aBlock value ].
dlg destroy ]
]
result [
<category: 'accessing'>
^ entryWidget getText
]
buildCentralWidget: aString on: aGtkDialog [
<category: 'user interface'>
| hbox |
buttons isNil ifTrue: [ self beOkCancel ].
buttons do: [ :each |
aGtkDialog addButton: each first responseId: (GTK.Gtk perform: each second) ].
defaultButton := GTK.Gtk perform: buttons first second.
aGtkDialog setDefaultResponse: defaultButton.
hbox := GTK.GtkHBox new: true spacing: 0.
labelWidget := GTK.GtkLabel new: aString.
entryWidget := GTK.GtkEntry new.
entryWidget setActivatesDefault: true.
hbox
add: labelWidget;
add: entryWidget;
showAll.
aGtkDialog getVBox add: hbox
]
]