-
Notifications
You must be signed in to change notification settings - Fork 6
/
GtkHistoryWidget.st
113 lines (85 loc) · 2.86 KB
/
GtkHistoryWidget.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
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
GtkConcreteWidget subclass: GtkHistoryWidget [
| browser model widget |
GtkHistoryWidget class >> new [
<category: 'instance creation'>
^ super new
initialize;
yourself
]
initialize [
<category: 'initialization'>
self mainWidget: self buildListView
]
browser: aBrowser [
<category: 'accessing'>
browser := aBrowser
]
buildListView [
<category: 'user interface'>
widget := (GTK.GtkTreeView createListWithModel: {{GtkColumnTextType title: 'History'}})
connectSignal: 'button-press-event' to: self selector: #'onPress:event:';
yourself.
widget getSelection setMode: GTK.Gtk gtkSelectionBrowse.
widget getSelection connectSignal: 'changed' to: self selector: #onSelectionChanged.
(model := GtkListModel on: widget getModel)
contentsBlock: [ :each | {each name displayString} ].
^ GTK.GtkScrolledWindow withChild: widget
]
refresh: historyStack [
<category: 'user interface'>
model
item: historyStack;
refresh.
widget selectNth: historyStack selectedIndex.
]
onPress: aGtkWidget event: aGdkEvent [
<category: 'button event'>
| menu aGdkButtonEvent |
aGdkButtonEvent := aGdkEvent castTo: GTK.GdkEventButton type.
aGdkButtonEvent button value = 3 ifFalse: [ ^ false ].
menu := GTK.GtkMenu new.
menu appendMenuItems: {{'Inspect a class'. self. #inspectClass}.
{'Open in new tab'. self. #browseTabbedClass}.
"{'Open in new window'. self. #browseClass}"}.
menu attachToWidget: widget detacher: nil.
menu popup: nil parentMenuItem: nil func: nil data: nil button: 3 activateTime: aGdkButtonEvent time value.
menu showAll.
^ true
]
targetObject [
<category: 'evaluation'>
^ widget selection
]
updateBrowser: aBrowser [
<category: 'event'>
aBrowser
selectANamespace: self targetObject environment;
selectAClass: self targetObject
]
inspectIt: anObject [
<category: 'smalltalk event'>
GtkInspector openOn: anObject
]
inspectClass [
<category: 'event'>
widget hasSelectedItem ifFalse: [ ^ self ].
InspectItCommand executeOn: self
]
onSelectionChanged [
<category: 'event'>
widget hasSelectedItem ifFalse: [ ^ self ].
model item selectedIndex = widget selectedIndex ifTrue: [^self].
model item selectItem: widget selectedIndex.
]
browseTabbedClass [
<category: 'event'>
"TODO: should reuse OpenTabbedBrowserCommand by giving a state to
GtkHistoryWidget."
widget hasSelectedItem ifFalse: [ ^ self ].
self updateBrowser: GtkLauncher uniqueInstance classBrowser
]
state [
<category: 'state'>
^model item current
]
]