Skip to content

Commit 215c13b

Browse files
author
Gwenael Casaccio
committed
new model
1 parent a36219e commit 215c13b

11 files changed

+442
-100
lines changed

Extensions.st

+111-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ Behavior extend [
271271
debuggerClass [
272272
<category: '*VisualGST'>
273273

274-
^ VisualGST.GtkDebugger
274+
"^ VisualGST.GtkDebugger"
275+
^ nil
275276
]
276277
]
277278

@@ -415,3 +416,112 @@ STInST.RBParser class extend [
415416
]
416417
]
417418

419+
GTK.GtkTreeView class extend [
420+
421+
createViewWith: anArray [
422+
<category: '*VisualGST'>
423+
424+
| model |
425+
model := OrderedCollection new.
426+
anArray do: [ :each | model addAll: (each collect: [ :elem | elem kind ]) ].
427+
model add: VisualGST.GtkColumnOOPType kind.
428+
^ self newWithModel: (GtkTreeStore new: model size varargs: model asArray)
429+
]
430+
431+
createListViewWith: anArray [
432+
<category: '*VisualGST'>
433+
434+
| model |
435+
model := OrderedCollection new.
436+
anArray do: [ :each | model addAll: (each collect: [ :elem | elem kind ]) ].
437+
model add: VisualGST.GtkColumnOOPType kind.
438+
^ self newWithModel: (GtkListStore new: model size varargs: model asArray)
439+
]
440+
441+
createListWithModel: anArray [
442+
<category: '*VisualGST'>
443+
444+
| colView i render view |
445+
view := self createListViewWith: anArray.
446+
anArray do: [ :each |
447+
colView := GtkTreeViewColumn new.
448+
i := 0.
449+
each do: [ :column |
450+
column isVisible ifTrue: [
451+
colView
452+
packStart: (render := column cellRenderer new) expand: false;
453+
addAttribute: render attribute: column kindName column: i.
454+
column hasTitle ifTrue: [ colView setTitle: column title ].
455+
i := i + 1 ] ].
456+
view insertColumn: colView position: -1 ].
457+
^ view
458+
]
459+
460+
createWithModel: anArray [
461+
<category: '*VisualGST'>
462+
463+
| colView i render view |
464+
view := self createViewWith: anArray.
465+
anArray do: [ :each |
466+
colView := GtkTreeViewColumn new.
467+
i := 0.
468+
each do: [ :column |
469+
column isVisible ifTrue: [
470+
colView
471+
packStart: (render := column cellRenderer new) expand: false;
472+
addAttribute: render attribute: column kindName column: i.
473+
column hasTitle ifTrue: [ colView setTitle: column title ].
474+
i := i + 1 ] ].
475+
view insertColumn: colView position: -1 ].
476+
^ view
477+
]
478+
]
479+
480+
GTK.GtkTreeStore extend [
481+
"| childrenBlock contentBlock root |
482+
483+
root: anObject [
484+
<category: 'accessing'>
485+
486+
root := anObject
487+
]
488+
489+
root [
490+
<category: 'accessing'>
491+
492+
root
493+
]
494+
495+
childrenBlock: aOneArgBlock [
496+
<category: 'accessing'>
497+
498+
childrenBlock := aOneArgBlock
499+
]
500+
501+
childrenBlock [
502+
<category: 'accessing'>
503+
504+
^ childrenBlock
505+
]
506+
507+
contentBlock: aOneArgBlock [
508+
<category: 'accessing'>
509+
510+
^ contentBlock := aOneArgBlock
511+
]
512+
513+
contentBlock [
514+
<category: 'accessing'>
515+
516+
^ contentBlock
517+
]
518+
519+
refresh [
520+
<category: '*VisualGST'>
521+
522+
self clear.
523+
self root do: [ :each |
524+
self appendItem: { self contentBlock value: each. each } ]
525+
]"
526+
]
527+

GtkListModel.st

+18-31
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
Object subclass: GtkListModel [
22

3-
GtkListModel class >> new [
3+
GtkListModel class >> on: aGtkListStore [
44
<category: 'instance creation'>
55

66
^ super new
77
initialize;
8+
gtkModel: aGtkListStore;
89
yourself
910
]
1011

11-
| columns contentsBlock item model |
12+
| contentsBlock item model |
1213

1314
initialize [
1415
<category: 'initialization'>
1516

1617
]
1718

18-
columns: anInteger [
19+
gtkModel: aGtkListStore [
1920
<category: 'accessing'>
2021

21-
columns := anInteger
22-
]
23-
24-
columns [
25-
<category:' accessing'>
26-
27-
^ columns
22+
model := aGtkListStore
2823
]
2924

3025
item: anObject [
@@ -51,46 +46,45 @@ Object subclass: GtkListModel [
5146
^ contentsBlock
5247
]
5348

54-
gtkModel [
55-
<category: 'accessing'>
56-
57-
^ model ifNil: [
58-
model := GTK.GtkListStore new: self columns size varargs: self columns ]
59-
]
60-
61-
append: anArray [
49+
append: anItem [
6250
<category:' model'>
6351

64-
self gtkModel appendItem: anArray
52+
model appendItem: ((self contentsBlock value: anItem) copyWith: anItem)
6553
]
6654

6755
remove: anObject [
6856
<category: 'model'>
6957

7058
| iter |
7159
(iter := self findIter: anObject) ifNil: [ self error: 'item not found' ].
72-
self gtkModel remove: iter
60+
model remove: iter
7361
]
7462

7563
clear [
7664
<category: 'model'>
7765

78-
self gtkModel clear
66+
model clear
7967
]
8068

8169
refresh [
8270
<category: 'model'>
8371

8472
self clear.
8573
self item ifNil: [ ^ self ].
86-
(self contentsBlock value: self item) do: [ :each | self append: each ].
87-
"self item do: [ :each | self append: (self contentsBlock value: each) ]"
74+
self item do: [ :each | self append: each ]
75+
]
76+
77+
hasItem: anObject [
78+
<category: 'item selection'>
79+
80+
self findIter: anObject ifAbsent: [ ^ false ].
81+
^ true
8882
]
8983

9084
findIter: anObject ifAbsent: aBlock [
9185
<category: 'item selection'>
9286

93-
self gtkModel do: [ :elem :iter |
87+
model do: [ :elem :iter |
9488
elem first = anObject ifTrue: [ ^ iter ] ].
9589
aBlock value
9690
]
@@ -100,12 +94,5 @@ Object subclass: GtkListModel [
10094

10195
^ self findIter: anObject ifAbsent: [ self error: 'Item not found' ]
10296
]
103-
104-
hasItem: anObject [
105-
<category: 'item selection'>
106-
107-
self findIter: anObject ifAbsent: [ ^ false ].
108-
^ true
109-
]
11097
]
11198

GtkMethodModel.st

+4-30
Original file line numberDiff line numberDiff line change
@@ -64,50 +64,24 @@ Object subclass: GtkMethodModel [
6464
self category: aString
6565
]
6666

67-
gtkModel [
67+
gtkModel: aModel [
6868
<category: 'accessing'>
6969

70-
^ model ifNil: [
71-
model := GTK.GtkListStore new: 1 varargs: {GTK.GValue gTypeString} ]
72-
]
73-
74-
emptyModel [
75-
<category: 'accessing'>
76-
77-
^ GTK.GtkListStore new: 1 varargs: {GTK.GValue gTypeString}
70+
model := aModel
7871
]
7972

8073
refreshModel [
8174
<category: 'events'>
8275

83-
self classOrMeta ifNil: [ ^ model := self emptyModel ].
76+
self classOrMeta ifNil: [ ^ self ].
8477

8578
self gtkModel clear.
8679

8780
self classOrMeta selectors do: [ :each |
88-
(((self classOrMeta compiledMethodAt: each) methodCategory = self category) or: [ self category = '*'])
81+
(self category = '*' or: [ ((self classOrMeta compiledMethodAt: each) methodCategory = self category) ])
8982
ifTrue: [ self appendMethod: each asString ] ]
9083
]
9184

92-
buildCategory [
93-
<category: 'model builder'>
94-
95-
| category set |
96-
set := Set new.
97-
self classOrMeta selectors do: [ :each |
98-
category := (self classOrMeta compiledMethodAt: each) methodCategory.
99-
set add: category ].
100-
^ set
101-
]
102-
103-
findIterInAMethod: aString [
104-
<category: 'item selection'>
105-
106-
self gtkModel do: [ :elem :iter |
107-
elem first = aString ifTrue: [ ^ iter ] ].
108-
^nil
109-
]
110-
11185
appendMethod: aString [
11286
<category: 'model builder'>
11387

0 commit comments

Comments
 (0)