arcadia 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. data/README +69 -77
  2. data/arcadia.rb +1097 -770
  3. data/base/a-commons.rb +480 -0
  4. data/base/a-contracts.rb +207 -322
  5. data/base/{a-utils.rb → a-tkcommons.rb} +933 -993
  6. data/conf/arcadia.conf +130 -203
  7. data/conf/arcadia.res.rb +1332 -1325
  8. data/ext/ae-action-dispatcher/ae-action-dispatcher.conf +6 -0
  9. data/ext/ae-action-dispatcher/ae-action-dispatcher.rb +22 -0
  10. data/ext/ae-complete-code/ae-complete-code.conf +2 -2
  11. data/ext/ae-complete-code/ae-complete-code.rb +82 -80
  12. data/ext/ae-doc-code/ae-doc-code.conf +2 -2
  13. data/ext/ae-doc-code/ae-doc-code.rb +114 -111
  14. data/ext/ae-editor/ae-editor.conf +110 -105
  15. data/ext/ae-editor/ae-editor.rb +2501 -2287
  16. data/ext/ae-editor/langs/conf.lang +15 -0
  17. data/ext/ae-editor/langs/lang.lang.bind +1 -0
  18. data/ext/ae-editor/langs/rb.lang +67 -0
  19. data/ext/ae-editor/langs/rbw.lang.bind +1 -0
  20. data/ext/ae-event-log/ae-event-log.rb +45 -52
  21. data/ext/ae-file-history/ae-file-history.conf +4 -4
  22. data/ext/ae-file-history/ae-file-history.rb +298 -286
  23. data/ext/ae-flag/ae-flag.conf +6 -6
  24. data/ext/ae-flag/ae-flag.rb +12 -12
  25. data/ext/ae-inspector/ae-inspector.conf +3 -3
  26. data/ext/ae-inspector/ae-inspector.rb +2 -2
  27. data/ext/ae-output-event/ae-output-event.conf +15 -15
  28. data/ext/ae-output/ae-output.conf +5 -3
  29. data/ext/ae-output/ae-output.rb +62 -33
  30. data/ext/ae-palette/ae-palette.conf +3 -3
  31. data/ext/ae-palette/ae-palette.rb +265 -306
  32. data/ext/ae-rad/ae-rad-inspector.rb +1534 -0
  33. data/{base/a-libs.rb → ext/ae-rad/ae-rad-libs.rb} +1118 -846
  34. data/ext/ae-rad/ae-rad-palette.rb +273 -0
  35. data/ext/ae-rad/ae-rad.conf +71 -0
  36. data/ext/ae-rad/ae-rad.rb +56 -0
  37. data/{lib → ext/ae-rad/lib}/tk/al-tk.rb +21 -110
  38. data/{lib → ext/ae-rad/lib}/tk/al-tk.res.rb +0 -0
  39. data/{lib → ext/ae-rad/lib}/tk/al-tkarcadia.rb +26 -26
  40. data/{lib → ext/ae-rad/lib}/tk/al-tkcustom.rb +70 -70
  41. data/{lib → ext/ae-rad/lib}/tkext/al-bwidget.rb +194 -194
  42. data/{lib → ext/ae-rad/lib}/tkext/al-iwidgets.rb +25 -25
  43. data/{lib → ext/ae-rad/lib}/tkext/al-tile.rb +173 -173
  44. data/{lib → ext/ae-rad/lib}/tkext/al-tktable.rb +0 -0
  45. data/ext/ae-ruby-debug/ae-ruby-debug.conf +7 -4
  46. data/ext/ae-ruby-debug/ae-ruby-debug.rb +278 -142
  47. data/ext/ae-search-in-files/ae-search-in-files.conf +15 -0
  48. data/ext/ae-search-in-files/ae-search-in-files.rb +284 -0
  49. data/ext/ae-shell/ae-shell.rb +88 -8
  50. data/ext/ae-shell/sh.rb +7 -0
  51. metadata +93 -79
  52. data/base/a-contracts-work.rb +0 -219
  53. data/base/a-ext.rb +0 -280
  54. data/ext/ae-debug/ae-debug.conf +0 -7
  55. data/ext/ae-debug/ae-debug.rb +0 -601
  56. data/ext/ae-debug/debug1.57.rb +0 -998
@@ -1,846 +1,1118 @@
1
- #
2
- # a-libs.rb - Arcadia Ruby ide
3
- # by Antonio Galeone <antonio-galeone@rubyforge.org>
4
- #
5
-
6
- class ArcadiaLib
7
- attr_reader :arcadia_lib_params
8
- attr_reader :classes
9
-
10
- def initialize(_arcadia, _arcadia_lib_params)
11
- @arcadia = _arcadia
12
- @arcadia_lib_params = _arcadia_lib_params
13
- @classes = Array.new
14
- @requires = Array.new
15
- @require4class = Hash.new
16
- register_classes
17
- end
18
-
19
- def add_class(arcadia_class=nil, _is_top=false)
20
- _self = self
21
- if arcadia_class
22
- class << arcadia_class
23
- def library=(lib)
24
- @library = lib
25
- end
26
- def library
27
- @library
28
- end
29
-
30
- end
31
- arcadia_class.library = self
32
- if _is_top
33
- class << arcadia_class
34
- def is_top
35
- true
36
- end
37
- end
38
- else
39
- class << arcadia_class
40
- def is_top
41
- false
42
- end
43
- end
44
- end
45
- @classes << arcadia_class
46
- end
47
- end
48
-
49
- protected :add_class
50
- def register_classes
51
- end
52
- protected :register_classes
53
-
54
- end
55
-
56
-
57
- class ArcadiaLibs
58
- attr_reader :arcadia
59
- ArcadiaLibParams = Struct.new( "ArcadiaLibParams",
60
- :name,
61
- :source,
62
- :require,
63
- :classLib
64
- )
65
-
66
- def initialize(_arcadia)
67
- @arcadia = _arcadia
68
- @@libs = Array.new
69
- end
70
-
71
- def list
72
- @@libs
73
- end
74
-
75
- def add_lib(arcadia_lib_params=nil)
76
- if arcadia_lib_params
77
- @@libs << arcadia_lib_params.classLib.new(@arcadia,arcadia_lib_params)
78
- end
79
- end
80
-
81
- def ArcadiaLibs.check_dictionary
82
- if !defined?(@@wrappers_for_classes)
83
- @@wrappers_for_classes = Hash.new
84
- @@libs.each{|_lib|
85
- _lib.classes.each{|_class|
86
- @@wrappers_for_classes[_class.class_wrapped]=_class
87
- }
88
- }
89
- end
90
- end
91
-
92
- def ArcadiaLibs.wrapper_class(_class)
93
- check_dictionary
94
- return @@wrappers_for_classes[_class]
95
- end
96
-
97
- def ArcadiaLibs.copy_wrapper_of_class_to_class(_of_class, _to_class)
98
- check_dictionary
99
- @@wrappers_for_classes[_to_class] = @@wrappers_for_classes[_of_class]
100
- end
101
-
102
- end
103
-
104
- class PropType
105
- def initialize
106
- end
107
- end
108
-
109
- class StringType < PropType
110
- def initialize
111
- end
112
- end
113
-
114
- class NumberType < PropType
115
- def initialize
116
- end
117
- end
118
-
119
- class ProcType < PropType
120
- def initialize(_proc)
121
- @p = _proc
122
- end
123
- def procReturn
124
- @p.call
125
- end
126
- end
127
-
128
- class EnumType < PropType
129
- attr_reader :values
130
- def initialize(*args)
131
- if args.class == Array
132
- @values = *args
133
- else
134
- @values = [*args]
135
- end
136
- end
137
- end
138
-
139
- class EnumProcType < EnumType
140
- def initialize(_proc, *args)
141
- @p = _proc
142
- super(*args)
143
- end
144
- def procReturn
145
- @p.call
146
- end
147
- end
148
-
149
- class ObjEnumProcType < EnumProcType
150
- attr_reader :it
151
- def initialize(_obj, _proc, *args)
152
- @it = me
153
- super(_proc, *args)
154
- end
155
- end
156
-
157
- class AGSniffer
158
- attr_reader :sons
159
- def initialize(_obj)
160
- @obj = _obj
161
- @sons = Array.new
162
- find_sons
163
- end
164
- def find_sons
165
-
166
- end
167
- def has_sons?
168
- @sons.length > 0
169
- end
170
- end
171
-
172
- class AGRenderer
173
- #INDENT_UNIT = "\t"
174
- INDENT_UNIT = "\s"*2
175
- def initialize(_agobj=nil)
176
- if _agobj
177
- @agobj = _agobj
178
- else
179
- exit
180
- end
181
- end
182
-
183
- def class_code(_ind=0, _args=nil)
184
- args = render_on_create_properties(_args)
185
- return class_begin(_ind, args), class_hinner_begin(_ind+1), class_hinner_end(_ind+1), class_end(_ind)
186
- end
187
-
188
- def class_begin(_ind=0, _args=nil)
189
- code = INDENT_UNIT*_ind,'class ', @agobj.getInstanceClass, ' < ', @agobj.getObjClass
190
- code_attr=''
191
- code_hinner_class=''
192
- @agobj.sons.each {|value|
193
- if (value.sons.length > 0)
194
- code_hinner_class = code_hinner_class,"\n", value.renderer.class_code(_ind+1)
195
- end
196
- code_attr = code_attr,"\n",INDENT_UNIT*(_ind+1),'attr_reader :', value.i_name
197
- }
198
- code = code,code_attr if (code_attr.length >0)
199
- code = code,code_hinner_class,"\n" if (code_hinner_class.length >0)
200
- code = code,"\n", INDENT_UNIT*(_ind+1),"def initialize(parent=nil, *args)\n"
201
- if _args
202
- code = code, INDENT_UNIT*(_ind+2),"super(parent, "+_args+")\n"
203
- else
204
- code = code, INDENT_UNIT*(_ind+2),"super(parent, *args)\n"
205
- end
206
- end
207
-
208
- def class_hinner_begin(_ind=0)
209
- return render_family(_ind+1,'property','default')
210
- end
211
-
212
- def class_hinner_end(_ind=0)
213
- code = ''
214
- @agobj.sons.each {|value|
215
- if (value.sons.length > 0)
216
- code = code, value.renderer.obj_begin(_ind+1),"\n"
217
- else
218
- code = code, value.renderer.obj_code(_ind+1),"\n"
219
- end
220
- }
221
- return code.to_s
222
- end
223
-
224
- def class_end(_ind=0)
225
- code = code, "\n", INDENT_UNIT*(_ind+1),"end\n",INDENT_UNIT*(_ind),"end"
226
- return code.to_s
227
- end
228
-
229
- def obj_code(_ind=0)
230
- return obj_begin(_ind), "{ ",obj_hinner_begin(_ind+1), obj_hinner_end(_ind+1), obj_end(_ind),"}"
231
- end
232
-
233
- def obj_begin(_ind=0)
234
- _s_ind = INDENT_UNIT*_ind
235
- if _s_ind == nil
236
- _s_ind = ''
237
- end
238
- if @agobj.sons.length > 0
239
- _class = @agobj.getInstanceClass
240
- else
241
- _class = @agobj.class.class_wrapped.to_s
242
- end
243
- return "\n",_s_ind+'@'+@agobj.i_name+' = '+_class+'.new(self)'
244
- end
245
-
246
- def obj_hinner_begin(_ind=0)
247
- return class_hinner_begin(_ind)
248
- end
249
-
250
- def obj_hinner_end(_ind=0)
251
- code = ''
252
- _s_attr_reader = ''
253
- _s_ind = INDENT_UNIT*_ind
254
- _s_attr_reader = ''
255
- @agobj.sons.each{|son|
256
- code = code , "\n", son.renderer.obj_code(_ind)
257
- _s_attr_reader = _s_attr_reader, "\n", _s_ind,INDENT_UNIT*2 ,':',son.i_name
258
- }
259
- if code.length > 0 then
260
- code = code , "\n",_s_ind,"class << self"
261
- code = code , "\n",_s_ind," attr_reader",_s_attr_reader
262
- code = code , "\n",_s_ind,"end"
263
- end
264
- return code
265
- end
266
-
267
- def obj_end(_ind=0)
268
- _s_ind = INDENT_UNIT*_ind
269
- if _s_ind == nil
270
- _s_ind = ''
271
- end
272
- _s_ind
273
- end
274
-
275
- def render_on_create_properties(_args = nil)
276
- ret = nil
277
- if _args
278
- ret = ''
279
- _args.each{|k,v|
280
- if ret.strip.length > 0
281
- ret = ret + ', '
282
- end
283
- ret = ret + "'"+k+"' => '"+v+"'"
284
- }
285
- end
286
- aprop = @agobj.props_kinds['property']['on-create']
287
- if aprop
288
- ret = '' if ret == nil
289
- aprop.each{|name|
290
- next if _args && _args.has_key?(name)
291
- prop = @agobj.props['property'][name]
292
- _val = render_value(prop, 'property')
293
- if _val == nil
294
- next
295
- end
296
- if ret.strip.length > 0
297
- ret = ret +', '
298
- end
299
- #Tk.messageBox('message'=>_val.to_s)
300
- if (prop['def'] == '')||(prop['def'] == nil) #significa che possiamo inserire nel blocco come chiave,valore
301
- ret = ret + "'"+ prop['name'] +"' => "+ _val.to_s
302
- elsif (prop['def'] != nil)&&(prop['def'] != 'nodef')
303
- ret = ret + prop['def'].call(_val.to_s)
304
- end
305
- }
306
- end
307
- ret = nil if ret != nil && ret.strip.length == 0
308
- return ret
309
- end
310
-
311
- def render_value(_prop, _family)
312
- #Tk.messageBox('message'=>_prop['name'])
313
- return nil if _prop == nil
314
- _val = _prop['get'].call
315
-
316
- if @agobj.defaults_values[@agobj.class][_family][_prop['name']]==_val
317
- return nil
318
- end
319
-
320
- _prop['def_string'] != nil && !_prop['def_string'] ? is_string = false: is_string = true
321
-
322
- if _val.kind_of?(String) && is_string
323
- _val = "'",_val,"'"
324
- elsif _val != nil
325
- _val = _val.to_s
326
- end
327
- #Tk.messageBox('message'=>_val)
328
- return _val
329
- end
330
-
331
- def render_value_default(_prop, _family)
332
- return nil if _prop == nil
333
- _val = _prop['value']
334
- _prop['def_string'] != nil && !_prop['def_string'] ? is_string = false: is_string = true
335
- if _val.kind_of?(String) && is_string
336
- _val = "'",_val,"'"
337
- elsif _val != nil
338
- _val = _val.to_s
339
- end
340
- return _val
341
- end
342
-
343
-
344
-
345
- def render_family(_ind=0, _family='', _kind=nil, _default=false)
346
- if @agobj.props[_family] == nil
347
- return ''
348
- end
349
- _s_block = ''
350
- _s_ind = INDENT_UNIT*_ind
351
-
352
- render_group = @agobj.props_def[_family] != nil
353
- if render_group
354
- @agobj.props_def[_family]['sep'] != nil ? render_group_sep = @agobj.props_def[_family]['sep']:render_group_sep = ''
355
- @agobj.props_def[_family]['default'] != nil ? render_group_default = @agobj.props_def[_family]['default']:render_group_default = proc{|nome,x| "'#{nome}' #{x}"}
356
- end
357
- if _kind == nil
358
- properties_list = Array.new
359
- @agobj.props_kinds[_family].each_value{|p|
360
- properties_list.concat(p)
361
- }
362
- else
363
- properties_list = @agobj.props_kinds[_family][_kind]
364
- end
365
- properties_list.each{|name|
366
- value = @agobj.props[_family][name]
367
- if _default
368
- _val = render_value_default(value, _family)
369
- else
370
- _val = render_value(value, _family)
371
- end
372
- if _val == nil
373
- next
374
- end
375
-
376
- if render_group
377
- if _s_block.length > 0
378
- _s_block = _s_block, render_group_sep
379
- end
380
- _s_block = _s_block,"\n",_s_ind, INDENT_UNIT
381
- if (value['def'] == '')||(value['def'] == nil) #significa che possiamo inserire nel blocco come chiave,valore
382
- _s_block = _s_block, render_group_default.call(value['name'] , _val)
383
- elsif (value['def'] != nil)&&(value['def'] != 'nodef')
384
- _s_block = _s_block, value['def'].call(_val)
385
- end
386
- else
387
- if (value['def'] == '')||(value['def'] == nil) #significa che possiamo inserire nel blocco come chiave,valore
388
- _s_block = _s_block, "\n",_s_ind , value['name'] ,INDENT_UNIT , _val
389
- elsif (value['def'] != nil)&&(value['def'] != 'nodef')
390
- _s_block = _s_block , "\n", _s_ind ,value['def'].call(_val)
391
- end
392
- end
393
- }
394
-
395
- if render_group
396
- _ss_block = "\n",_s_ind
397
- if @agobj.props_def[_family]['path'] != nil
398
- _ss_block = _ss_block, @agobj.props_def[_family]['path']
399
- end
400
- _ss_block = _ss_block, @agobj.props_def[_family]['before'], _s_block, "\n",_s_ind, @agobj.props_def[_family]['after']
401
- else
402
- _ss_block = _s_block
403
- end
404
- #p _ss_block.to_s
405
- return _ss_block
406
- end
407
- end
408
-
409
- class AG
410
- attr_reader :props, :props_def, :i_name, :i_ag, :ag_parent, :obj_class, :obj
411
- attr_reader :sons, :renderer
412
- attr_reader :sniffer
413
- attr_reader :persistent
414
- #attr_reader :props_seq
415
- attr_reader :props_kinds
416
- attr_writer :props, :i_name, :i_ag
417
-
418
- def initialize(_ag_parent = nil, _object = nil)
419
- @ag_parent = _ag_parent
420
- if _object == nil
421
- new_object
422
- else
423
- passed_object(_object)
424
- end
425
-
426
- @obj_class = self.class.near_class_wrapped(@obj)
427
- @sons = Array.new
428
- @renderer=self.class.class_renderer.new(self)
429
- @sniffer=self.class.class_sniffer.new(@obj)
430
- yield(self) if block_given?
431
- if !defined?(@i_name)
432
- @i_name = self.class.class_wrapped.to_s.gsub('::','_') + new_id
433
- @i_name = @i_name.sub(/^./) { $&.downcase}
434
- end
435
- @i_ag = 'ag' + @i_name
436
- @props = Hash.new
437
- @props_def = Hash.new
438
- @props_kinds = Hash.new
439
- @persistent = Hash.new
440
- @requires = Hash.new
441
- properties
442
- defaults(_object != nil )
443
- if _object != nil
444
- retrive_values
445
- else
446
- start_properties
447
- end
448
- self.register
449
- end
450
-
451
- def add_require(_require)
452
- if @requires[_require] == nil
453
- @requires[_require] = 1
454
- else
455
- @requires[_require] += 1
456
- end
457
- end
458
-
459
- def del_require(_require)
460
- @requires[_require] -= 1
461
- if @requires[_require] == 0
462
- @requires[_require] = nil
463
- end
464
- end
465
-
466
- def select
467
- InspectorContract.instance.select(self, 'wrapper'=>self)
468
- self
469
- end
470
-
471
-
472
- def activate
473
- @@active = self
474
- end
475
-
476
-
477
- def build_sons
478
- iv = @obj.instance_variables
479
- if iv.length > 0
480
- cod = " class << @obj"+"\n"
481
- iv.each{|i|
482
- i.delete!('@')
483
- cod = cod + " attr_reader :"+i+"\n"
484
- }
485
- cod = cod +"end\n"
486
- eval(cod)
487
- end
488
- iv_obj = Hash.new
489
- iv.each{|i|
490
- iv_obj[i] = eval("@obj."+i)
491
- }
492
- i_name = nil
493
- self.sniffer.sons.each{|obj_son|
494
- clazz = self.class.near_class_wrapper(obj_son)
495
- if clazz != nil
496
- iv_obj.each{|key, value|
497
- if value == obj_son
498
- i_name=key
499
- end
500
- }
501
- if i_name == nil
502
- clazz.new(self,obj_son)
503
- else
504
- clazz.new(self,obj_son){|_self| _self.i_name = i_name}
505
- end
506
- end
507
- }
508
- end
509
-
510
- def register(_agobj=self)
511
- @sons << _agobj if _agobj!=self && _agobj.ag_parent == self
512
- if @ag_parent
513
- return @ag_parent.register(_agobj)
514
- else
515
- WrapperContract.instance.wrapper_created(self,'wrapper'=>_agobj)
516
- #
517
- # _tobj = InspectorActionContract::TInspectorActionObj.new(self)
518
- # _tobj.wrapper = _agobj
519
- # InspectorActionContract.instance.register(_tobj)
520
- end
521
- end
522
-
523
- def has_sons
524
- return (self.sons.length > 0)
525
- end
526
-
527
- def new_id
528
- if !defined?(@@ag_id)
529
- @@ag_id = Hash.new
530
- end
531
- if (@@ag_id[self.class]==nil)
532
- @@ag_id[self.class] = 1
533
- else
534
- @@ag_id[self.class] = @@ag_id[self.class] + 1
535
- end
536
- return @@ag_id[self.class].to_s
537
- end
538
-
539
- def defaults_values
540
- @@defaults_values
541
- end
542
-
543
- def defaults(_new=false)
544
- if !defined?(@@defaults_values)
545
- @@defaults_values = Hash.new
546
- end
547
- if (!defined?(@@defaults_values[self.class]))||(@@defaults_values[self.class] == nil)
548
- @@defaults_values[self.class] = Hash.new
549
- if _new
550
- _obj = @obj_class.new
551
- fill_defaults_value_from_agobj(_obj)
552
- else
553
- fill_defaults_value_from_agobj
554
- end
555
- end
556
- end
557
-
558
- def fill_defaults_value_from_agobj(_obj=nil)
559
- #return if _obj == nil
560
- _obj_save = @obj
561
- if _obj
562
- @obj = _obj
563
- end
564
- begin
565
- @props.each{|_key,_family|
566
- #Tk.messageBox('message'=>_key)
567
- if @@defaults_values[self.class][_key] == nil
568
- @@defaults_values[self.class][_key] = Hash.new
569
- end
570
- _family.each_value{|value|
571
- if (value['name'] != nil) && @@defaults_values[self.class][_key][value['name']] == nil
572
- if (value['default'] != nil)
573
- @@defaults_values[self.class][_key][value['name']] = value['default']
574
- elsif (value['get'] != nil)
575
- @@defaults_values[self.class][_key][value['name']] = value['get'].call
576
- end
577
- end
578
- }
579
- }
580
- ensure
581
- if _obj
582
- @obj = _obj_save
583
- _obj.destroy
584
- end
585
- end
586
-
587
- end
588
-
589
-
590
- def delete
591
- InspectorContract.instance.delete_wrapper(self, 'wrapper'=>self)
592
- end
593
-
594
- def AG.class_wrapped
595
- nil
596
- end
597
-
598
- def AG.class_renderer
599
- AGRenderer
600
- end
601
-
602
- def AG.class_sniffer
603
- AGSniffer
604
- end
605
-
606
- def AG.active
607
- @@active
608
- end
609
-
610
-
611
- def getFileName
612
- __FILE__
613
- end
614
-
615
- def AG.publish_property(_name, args = nil)
616
- # class_eval(%Q[
617
- # def #{_name}
618
- # @#{_name}
619
- # #{args('get').call}
620
- # end
621
- #
622
- # def #{_name}=(value)
623
- # @#{_name} = value
624
- # #{args('set').call(value)}
625
- # end
626
- # ])
627
-
628
- end
629
-
630
-
631
- def new_object
632
- if self.class.class_wrapped
633
- @obj = self.class.class_wrapped.new
634
- end
635
- end
636
-
637
- def AG.near_class_wrapped(_obj)
638
- clazz = _obj.class
639
- while (ArcadiaLibs.wrapper_class(clazz) == nil)&&(clazz!=nil)
640
- clazz = clazz.superclass
641
- end
642
- return clazz
643
- end
644
-
645
- def AG.near_class_wrapper(_obj)
646
- ArcadiaLibs.wrapper_class(self.near_class_wrapped(_obj))
647
- end
648
-
649
-
650
- def passed_object(_obj)
651
- @obj = _obj
652
- end
653
-
654
- def start_properties
655
- @props.each_value{|family|
656
- family.each_value{|value|
657
- if value['start'] != nil
658
- value['set'].call(value['start'])
659
- end
660
- }
661
- }
662
- end
663
-
664
- def retrive_values
665
- @props.each_value{|family|
666
- family.each_value{|prop|
667
- prop['value'] = prop['get'].call
668
- }
669
- }
670
- end
671
-
672
- def getViewClassName
673
- return 'V',@i_name
674
- end
675
-
676
- def getControlClassName
677
- return @i_name.capitalize
678
- end
679
-
680
- def getInstanceClass
681
- return @i_name.capitalize
682
- #return 'C',@i_name
683
- end
684
-
685
- def get_path_i_name
686
- _return = @i_name
687
- _agstart = self
688
- while _agstart.ag_parent != nil
689
- _return = _agstart.ag_parent.i_name,'.',_return
690
- _agstart = _agstart.ag_parent
691
- end
692
- return _return
693
- end
694
-
695
- def get_implementation_new(_variable = false)
696
- if (ag_parent == nil)|| _variable
697
- result = '@',@i_name,' = ', getInstanceClass ,'.new(', '@',@ag_parent.i_name, ")\n"
698
- end
699
- result = result, self.class, '.new(', '@',@ag_parent.i_ag,", @",get_path_i_name,")"
700
- end
701
-
702
- def get_implementation_block
703
- result = result, " @i_name = '", @i_name, "'\n"
704
- result = result, " @i_ag = '", @i_ag, "'\n"
705
- result = result, " @obj_class = '", getObjClass, "'\n"
706
- end
707
-
708
- def get_implementation_code
709
- result = result, get_implementation_new, "{\n"
710
- result = result, get_implementation_block
711
- @requires.each_key do |key|
712
- result = result," @object_inspector.addRequire('#{key}')\n"
713
- end
714
-
715
- result = result,"}"
716
- end
717
-
718
-
719
- def getObjClass
720
- if defined? @obj_class
721
- return @obj_class
722
- else
723
- return @obj.class
724
- end
725
- end
726
-
727
- def publish_def(_family, args = nil)
728
- @props_def[_family]=args
729
- end
730
-
731
- # def AG.publish_def(_family, args = nil)
732
- # @@props_def = Hash.new if !defined?(@@props_def)
733
- # @@props_def[_family]=args
734
- # end
735
-
736
-
737
- def publish(_family, args = nil)
738
- if @props[_family] == nil
739
- @props[_family] = Hash.new
740
- end
741
- @props[_family][args['name']]=args
742
- args['kind'] != nil ? kind = args['kind']:kind = 'default'
743
- if @props_kinds[_family] == nil
744
- @props_kinds[_family] = Hash.new
745
- end
746
- if @props_kinds[_family][kind] == nil
747
- @props_kinds[_family][kind] = Array.new
748
- end
749
- @props_kinds[_family][kind] << args['name']
750
- end
751
-
752
-
753
-
754
-
755
- # def AG.publish(_family, args = nil)
756
- # @@props = Hash.new if !defined?(@@props)
757
- # if @@props[_family] == nil
758
- # @@props[_family] = Hash.new
759
- # end
760
- # @@props[_family][args['name']]=args
761
- # args['kind'] != nil ? kind = args['kind']:kind = 'default'
762
- # @@props_kinds = Hash.new if !defined?(@props_kinds)
763
- # if @@props_kinds[_family] == nil
764
- # @@props_kinds[_family] = Hash.new
765
- # end
766
- # if @@props_kinds[_family][kind] == nil
767
- # @@props_kinds[_family][kind] = Array.new
768
- # end
769
- # @@props_kinds[_family][kind] << args['name']
770
- # end
771
-
772
-
773
- def publish_mod(_family, args = nil)
774
- args.each do |key, value|
775
- @props[_family][args['name']]["#{key}"] = value
776
- end
777
- end
778
-
779
- # def AG.publish_mod(_family, args = nil)
780
- # args.each do |key, value|
781
- # @@props[_family][args['name']]["#{key}"] = value if !defined?(@@props)
782
- # end
783
- # end
784
-
785
-
786
- def publish_del(_family, _name=nil)
787
- if _name == nil
788
- @props.delete(_family)
789
- else
790
- @props[_family].delete(_name)
791
- end
792
- end
793
-
794
- # def AG.publish_del(_family, _name=nil)
795
- # if _name == nil
796
- # @@props.delete(_family)
797
- # else
798
- # @@props[_family].delete(_name)
799
- # end
800
- # end
801
-
802
- def properties
803
- publish( 'property',
804
- 'name' => 'name',
805
- 'get'=> proc{@i_name},
806
- 'set'=> proc{|n| self.i_name = n},
807
- 'def'=> 'nodef'
808
- )
809
- end
810
-
811
-
812
-
813
- # def delete
814
- # @obj.destroy
815
- # end
816
-
817
- # def setp(_family, _name, _value)
818
- # @props[_family][_name]['set'].call(_value)
819
- # tobj = InspectorActionContract::TInspectorActionObj.new(self)
820
- # tobj.wrapper = self
821
- # tobj.property_family = _family
822
- # tobj.property_name = _name
823
- # tobj.property_value = _value
824
- # InspectorActionContract.instance.update_property(tobj)
825
- # end
826
-
827
- def update_property(_sender, _family,_name,_value)
828
- old_value = @props[_family][_name]['get'].call(_value)
829
- if old_value != _value
830
- @props[_family][_name]['set'].call(_value)
831
- end
832
- WrapperContract.instance.property_updated(self,
833
- 'wrapper'=>self,
834
- 'property_name'=> _name,
835
- 'property_family'=>_family,
836
- 'property_old_value'=>old_value,
837
- 'property_new_value'=>_value
838
- )
839
- end
840
-
841
- # def updatep(_family, prop, value, _call_from_inspector=false)
842
- # @props[_family][prop]['set'].call(value)
843
- # end
844
-
845
- end
846
-
1
+ #
2
+ # ae-rad-libs.rb - Arcadia Ruby ide
3
+ # by Antonio Galeone <antonio-galeone@rubyforge.org>
4
+ #
5
+
6
+ class ArcadiaLib
7
+ attr_reader :arcadia_lib_params
8
+ attr_reader :classes
9
+
10
+ def initialize(_arcadia, _arcadia_lib_params)
11
+ @arcadia = _arcadia
12
+ @arcadia_lib_params = _arcadia_lib_params
13
+ @classes = Array.new
14
+ @requires = Array.new
15
+ @require4class = Hash.new
16
+ register_classes
17
+ end
18
+
19
+ def add_class(arcadia_class=nil, _is_top=false)
20
+ _self = self
21
+ if arcadia_class
22
+ class << arcadia_class
23
+ def library=(lib)
24
+ @library = lib
25
+ end
26
+ def library
27
+ @library
28
+ end
29
+
30
+ end
31
+ arcadia_class.library = self
32
+ if _is_top
33
+ class << arcadia_class
34
+ def is_top
35
+ true
36
+ end
37
+ end
38
+ else
39
+ class << arcadia_class
40
+ def is_top
41
+ false
42
+ end
43
+ end
44
+ end
45
+ @classes << arcadia_class
46
+ end
47
+ end
48
+
49
+ protected :add_class
50
+ def register_classes
51
+ end
52
+ protected :register_classes
53
+
54
+ end
55
+
56
+
57
+ class ArcadiaLibs
58
+ attr_reader :arcadia
59
+ ArcadiaLibParams = Struct.new( "ArcadiaLibParams",
60
+ :name,
61
+ :source,
62
+ :require,
63
+ :classLib
64
+ )
65
+
66
+ def initialize(_arcadia)
67
+ @arcadia = _arcadia
68
+ @@libs = Array.new
69
+ end
70
+
71
+ def list
72
+ @@libs
73
+ end
74
+
75
+ def add_lib(arcadia_lib_params=nil)
76
+ if arcadia_lib_params
77
+ @@libs << arcadia_lib_params.classLib.new(@arcadia,arcadia_lib_params)
78
+ end
79
+ end
80
+
81
+ def ArcadiaLibs.check_dictionary
82
+ if !defined?(@@wrappers_for_classes)
83
+ @@wrappers_for_classes = Hash.new
84
+ @@libs.each{|_lib|
85
+ _lib.classes.each{|_class|
86
+ @@wrappers_for_classes[_class.class_wrapped]=_class
87
+ }
88
+ }
89
+ end
90
+ end
91
+
92
+ def ArcadiaLibs.wrapper_class(_class)
93
+ check_dictionary
94
+ return @@wrappers_for_classes[_class]
95
+ end
96
+
97
+ def ArcadiaLibs.copy_wrapper_of_class_to_class(_of_class, _to_class)
98
+ check_dictionary
99
+ @@wrappers_for_classes[_to_class] = @@wrappers_for_classes[_of_class]
100
+ end
101
+
102
+ end
103
+
104
+ class PropType
105
+ def initialize
106
+ end
107
+ end
108
+
109
+ class StringType < PropType
110
+ def initialize
111
+ end
112
+ end
113
+
114
+ class NumberType < PropType
115
+ def initialize
116
+ end
117
+ end
118
+
119
+ class ProcType < PropType
120
+ def initialize(_proc)
121
+ @p = _proc
122
+ end
123
+ def procReturn
124
+ @p.call
125
+ end
126
+ end
127
+
128
+ class EnumType < PropType
129
+ attr_reader :values
130
+ def initialize(*args)
131
+ if args.class == Array
132
+ @values = *args
133
+ else
134
+ @values = [*args]
135
+ end
136
+ end
137
+ end
138
+
139
+ class EnumProcType < EnumType
140
+ def initialize(_proc, *args)
141
+ @p = _proc
142
+ super(*args)
143
+ end
144
+ def procReturn
145
+ @p.call
146
+ end
147
+ end
148
+
149
+ class ObjEnumProcType < EnumProcType
150
+ attr_reader :it
151
+ def initialize(_obj, _proc, *args)
152
+ @it = me
153
+ super(_proc, *args)
154
+ end
155
+ end
156
+
157
+ class AGSniffer
158
+ attr_reader :sons
159
+ def initialize(_obj)
160
+ @obj = _obj
161
+ @sons = Array.new
162
+ find_sons
163
+ end
164
+ def find_sons
165
+
166
+ end
167
+ def has_sons?
168
+ @sons.length > 0
169
+ end
170
+ end
171
+
172
+ class AGRenderer
173
+ #INDENT_UNIT = "\t"
174
+ INDENT_UNIT = "\s"*2
175
+ def initialize(_agobj=nil)
176
+ if _agobj
177
+ @agobj = _agobj
178
+ else
179
+ exit
180
+ end
181
+ end
182
+
183
+ def class_code(_ind=0, _args=nil)
184
+ args = render_on_create_properties(_args)
185
+ return class_begin(_ind, args), class_hinner_begin(_ind+1), class_hinner_end(_ind+1), class_end(_ind)
186
+ end
187
+
188
+ def class_begin(_ind=0, _args=nil)
189
+ code = INDENT_UNIT*_ind,'class ', @agobj.getInstanceClass, ' < ', @agobj.getObjClass
190
+ code_attr=''
191
+ code_hinner_class=''
192
+ @agobj.sons.each {|value|
193
+ if (value.sons.length > 0)
194
+ code_hinner_class = code_hinner_class,"\n", value.renderer.class_code(_ind+1)
195
+ end
196
+ code_attr = code_attr,"\n",INDENT_UNIT*(_ind+1),'attr_reader :', value.i_name
197
+ }
198
+ code = code,code_attr if (code_attr.length >0)
199
+ code = code,code_hinner_class,"\n" if (code_hinner_class.length >0)
200
+ code = code,"\n", INDENT_UNIT*(_ind+1),"def initialize(parent=nil, *args)\n"
201
+ if _args
202
+ code = code, INDENT_UNIT*(_ind+2),"super(parent, "+_args+")\n"
203
+ else
204
+ code = code, INDENT_UNIT*(_ind+2),"super(parent, *args)\n"
205
+ end
206
+ end
207
+
208
+ def class_hinner_begin(_ind=0)
209
+ return render_family(_ind+1,'property','default')
210
+ end
211
+
212
+ def class_hinner_end(_ind=0)
213
+ code = ''
214
+ @agobj.sons.each {|value|
215
+ if (value.sons.length > 0)
216
+ code = code, value.renderer.obj_begin(_ind+1),"\n"
217
+ else
218
+ code = code, value.renderer.obj_code(_ind+1),"\n"
219
+ end
220
+ }
221
+ return code.to_s
222
+ end
223
+
224
+ def class_end(_ind=0)
225
+ code = code, "\n", INDENT_UNIT*(_ind+1),"end\n",INDENT_UNIT*(_ind),"end"
226
+ return code.to_s
227
+ end
228
+
229
+ def obj_code(_ind=0)
230
+ return obj_begin(_ind), "{ ",obj_hinner_begin(_ind+1), obj_hinner_end(_ind+1), obj_end(_ind),"}"
231
+ end
232
+
233
+ def obj_begin(_ind=0)
234
+ _s_ind = INDENT_UNIT*_ind
235
+ if _s_ind == nil
236
+ _s_ind = ''
237
+ end
238
+ if @agobj.sons.length > 0
239
+ _class = @agobj.getInstanceClass
240
+ else
241
+ _class = @agobj.class.class_wrapped.to_s
242
+ end
243
+ return "\n",_s_ind+'@'+@agobj.i_name+' = '+_class+'.new(self)'
244
+ end
245
+
246
+ def obj_hinner_begin(_ind=0)
247
+ return class_hinner_begin(_ind)
248
+ end
249
+
250
+ def obj_hinner_end(_ind=0)
251
+ code = ''
252
+ _s_attr_reader = ''
253
+ _s_ind = INDENT_UNIT*_ind
254
+ _s_attr_reader = ''
255
+ @agobj.sons.each{|son|
256
+ code = code , "\n", son.renderer.obj_code(_ind)
257
+ _s_attr_reader = _s_attr_reader, "\n", _s_ind,INDENT_UNIT*2 ,':',son.i_name
258
+ }
259
+ if code.length > 0 then
260
+ code = code , "\n",_s_ind,"class << self"
261
+ code = code , "\n",_s_ind," attr_reader",_s_attr_reader
262
+ code = code , "\n",_s_ind,"end"
263
+ end
264
+ return code
265
+ end
266
+
267
+ def obj_end(_ind=0)
268
+ _s_ind = INDENT_UNIT*_ind
269
+ if _s_ind == nil
270
+ _s_ind = ''
271
+ end
272
+ _s_ind
273
+ end
274
+
275
+ def render_on_create_properties(_args = nil)
276
+ ret = nil
277
+ if _args
278
+ ret = ''
279
+ _args.each{|k,v|
280
+ if ret.strip.length > 0
281
+ ret = ret + ', '
282
+ end
283
+ ret = ret + "'"+k+"' => '"+v+"'"
284
+ }
285
+ end
286
+ aprop = @agobj.props_kinds['property']['on-create']
287
+ if aprop
288
+ ret = '' if ret == nil
289
+ aprop.each{|name|
290
+ next if _args && _args.has_key?(name)
291
+ prop = @agobj.props['property'][name]
292
+ _val = render_value(prop, 'property')
293
+ if _val == nil
294
+ next
295
+ end
296
+ if ret.strip.length > 0
297
+ ret = ret +', '
298
+ end
299
+ #Tk.messageBox('message'=>_val.to_s)
300
+ if (prop['def'] == '')||(prop['def'] == nil) #significa che possiamo inserire nel blocco come chiave,valore
301
+ ret = ret + "'"+ prop['name'] +"' => "+ _val.to_s
302
+ elsif (prop['def'] != nil)&&(prop['def'] != 'nodef')
303
+ ret = ret + prop['def'].call(_val.to_s)
304
+ end
305
+ }
306
+ end
307
+ ret = nil if ret != nil && ret.strip.length == 0
308
+ return ret
309
+ end
310
+
311
+ def render_value(_prop, _family)
312
+ #Tk.messageBox('message'=>_prop['name'])
313
+ return nil if _prop == nil
314
+ _val = _prop['get'].call
315
+
316
+ if @agobj.defaults_values[@agobj.class][_family][_prop['name']]==_val
317
+ return nil
318
+ end
319
+
320
+ _prop['def_string'] != nil && !_prop['def_string'] ? is_string = false: is_string = true
321
+
322
+ if _val.kind_of?(String) && is_string
323
+ _val = "'",_val,"'"
324
+ elsif _val != nil
325
+ _val = _val.to_s
326
+ end
327
+ #Tk.messageBox('message'=>_val)
328
+ return _val
329
+ end
330
+
331
+ def render_value_default(_prop, _family)
332
+ return nil if _prop == nil
333
+ _val = _prop['value']
334
+ _prop['def_string'] != nil && !_prop['def_string'] ? is_string = false: is_string = true
335
+ if _val.kind_of?(String) && is_string
336
+ _val = "'",_val,"'"
337
+ elsif _val != nil
338
+ _val = _val.to_s
339
+ end
340
+ return _val
341
+ end
342
+
343
+
344
+
345
+ def render_family(_ind=0, _family='', _kind=nil, _default=false)
346
+ if @agobj.props[_family] == nil
347
+ return ''
348
+ end
349
+ _s_block = ''
350
+ _s_ind = INDENT_UNIT*_ind
351
+
352
+ render_group = @agobj.props_def[_family] != nil
353
+ if render_group
354
+ @agobj.props_def[_family]['sep'] != nil ? render_group_sep = @agobj.props_def[_family]['sep']:render_group_sep = ''
355
+ @agobj.props_def[_family]['default'] != nil ? render_group_default = @agobj.props_def[_family]['default']:render_group_default = proc{|nome,x| "'#{nome}' #{x}"}
356
+ end
357
+ if _kind == nil
358
+ properties_list = Array.new
359
+ @agobj.props_kinds[_family].each_value{|p|
360
+ properties_list.concat(p)
361
+ }
362
+ else
363
+ properties_list = @agobj.props_kinds[_family][_kind]
364
+ end
365
+ properties_list.each{|name|
366
+ value = @agobj.props[_family][name]
367
+ if _default
368
+ _val = render_value_default(value, _family)
369
+ else
370
+ _val = render_value(value, _family)
371
+ end
372
+ if _val == nil
373
+ next
374
+ end
375
+
376
+ if render_group
377
+ if _s_block.length > 0
378
+ _s_block = _s_block, render_group_sep
379
+ end
380
+ _s_block = _s_block,"\n",_s_ind, INDENT_UNIT
381
+ if (value['def'] == '')||(value['def'] == nil) #significa che possiamo inserire nel blocco come chiave,valore
382
+ _s_block = _s_block, render_group_default.call(value['name'] , _val)
383
+ elsif (value['def'] != nil)&&(value['def'] != 'nodef')
384
+ _s_block = _s_block, value['def'].call(_val)
385
+ end
386
+ else
387
+ if (value['def'] == '')||(value['def'] == nil) #significa che possiamo inserire nel blocco come chiave,valore
388
+ _s_block = _s_block, "\n",_s_ind , value['name'] ,INDENT_UNIT , _val
389
+ elsif (value['def'] != nil)&&(value['def'] != 'nodef')
390
+ _s_block = _s_block , "\n", _s_ind ,value['def'].call(_val)
391
+ end
392
+ end
393
+ }
394
+
395
+ if render_group
396
+ _ss_block = "\n",_s_ind
397
+ if @agobj.props_def[_family]['path'] != nil
398
+ _ss_block = _ss_block, @agobj.props_def[_family]['path']
399
+ end
400
+ _ss_block = _ss_block, @agobj.props_def[_family]['before'], _s_block, "\n",_s_ind, @agobj.props_def[_family]['after']
401
+ else
402
+ _ss_block = _s_block
403
+ end
404
+ #p _ss_block.to_s
405
+ return _ss_block
406
+ end
407
+ end
408
+
409
+ class AG
410
+ attr_reader :props, :props_def, :i_name, :i_ag, :ag_parent, :obj_class, :obj
411
+ attr_reader :sons, :renderer
412
+ attr_reader :sniffer
413
+ attr_reader :persistent
414
+ #attr_reader :props_seq
415
+ attr_reader :props_kinds
416
+ attr_writer :props, :i_name, :i_ag
417
+
418
+ def initialize(_ag_parent = nil, _object = nil)
419
+ @ag_parent = _ag_parent
420
+ if _object == nil
421
+ new_object
422
+ else
423
+ passed_object(_object)
424
+ end
425
+
426
+ @obj_class = self.class.near_class_wrapped(@obj)
427
+ @sons = Array.new
428
+ @renderer=self.class.class_renderer.new(self)
429
+ @sniffer=self.class.class_sniffer.new(@obj)
430
+ yield(self) if block_given?
431
+ if !defined?(@i_name)
432
+ @i_name = self.class.class_wrapped.to_s.gsub('::','_') + new_id
433
+ @i_name = @i_name.sub(/^./) { $&.downcase}
434
+ end
435
+ @i_ag = 'ag' + @i_name
436
+ @props = Hash.new
437
+ @props_def = Hash.new
438
+ @props_kinds = Hash.new
439
+ @persistent = Hash.new
440
+ @requires = Hash.new
441
+ properties
442
+ defaults(_object != nil )
443
+ if _object != nil
444
+ retrive_values
445
+ else
446
+ start_properties
447
+ end
448
+ self.register
449
+ end
450
+
451
+ def add_require(_require)
452
+ if @requires[_require] == nil
453
+ @requires[_require] = 1
454
+ else
455
+ @requires[_require] += 1
456
+ end
457
+ end
458
+
459
+ def del_require(_require)
460
+ @requires[_require] -= 1
461
+ if @requires[_require] == 0
462
+ @requires[_require] = nil
463
+ end
464
+ end
465
+
466
+ def select
467
+ InspectorContract.instance.select(self, 'wrapper'=>self)
468
+ self
469
+ end
470
+
471
+
472
+ def activate
473
+ @@active = self
474
+ end
475
+
476
+
477
+ def build_sons
478
+ iv = @obj.instance_variables
479
+ if iv.length > 0
480
+ cod = " class << @obj"+"\n"
481
+ iv.each{|i|
482
+ i.delete!('@')
483
+ cod = cod + " attr_reader :"+i+"\n"
484
+ }
485
+ cod = cod +"end\n"
486
+ eval(cod)
487
+ end
488
+ iv_obj = Hash.new
489
+ iv.each{|i|
490
+ iv_obj[i] = eval("@obj."+i)
491
+ }
492
+ i_name = nil
493
+ self.sniffer.sons.each{|obj_son|
494
+ clazz = self.class.near_class_wrapper(obj_son)
495
+ if clazz != nil
496
+ iv_obj.each{|key, value|
497
+ if value == obj_son
498
+ i_name=key
499
+ end
500
+ }
501
+ if i_name == nil
502
+ clazz.new(self,obj_son)
503
+ else
504
+ clazz.new(self,obj_son){|_self| _self.i_name = i_name}
505
+ end
506
+ end
507
+ }
508
+ end
509
+
510
+ def register(_agobj=self)
511
+ @sons << _agobj if _agobj!=self && _agobj.ag_parent == self
512
+ if @ag_parent
513
+ return @ag_parent.register(_agobj)
514
+ else
515
+ WrapperContract.instance.wrapper_created(self,'wrapper'=>_agobj)
516
+ #
517
+ # _tobj = InspectorActionContract::TInspectorActionObj.new(self)
518
+ # _tobj.wrapper = _agobj
519
+ # InspectorActionContract.instance.register(_tobj)
520
+ end
521
+ end
522
+
523
+ def has_sons
524
+ return (self.sons.length > 0)
525
+ end
526
+
527
+ def new_id
528
+ if !defined?(@@ag_id)
529
+ @@ag_id = Hash.new
530
+ end
531
+ if (@@ag_id[self.class]==nil)
532
+ @@ag_id[self.class] = 1
533
+ else
534
+ @@ag_id[self.class] = @@ag_id[self.class] + 1
535
+ end
536
+ return @@ag_id[self.class].to_s
537
+ end
538
+
539
+ def defaults_values
540
+ @@defaults_values
541
+ end
542
+
543
+ def defaults(_new=false)
544
+ if !defined?(@@defaults_values)
545
+ @@defaults_values = Hash.new
546
+ end
547
+ if (!defined?(@@defaults_values[self.class]))||(@@defaults_values[self.class] == nil)
548
+ @@defaults_values[self.class] = Hash.new
549
+ if _new
550
+ _obj = @obj_class.new
551
+ fill_defaults_value_from_agobj(_obj)
552
+ else
553
+ fill_defaults_value_from_agobj
554
+ end
555
+ end
556
+ end
557
+
558
+ def fill_defaults_value_from_agobj(_obj=nil)
559
+ #return if _obj == nil
560
+ _obj_save = @obj
561
+ if _obj
562
+ @obj = _obj
563
+ end
564
+ begin
565
+ @props.each{|_key,_family|
566
+ #Tk.messageBox('message'=>_key)
567
+ if @@defaults_values[self.class][_key] == nil
568
+ @@defaults_values[self.class][_key] = Hash.new
569
+ end
570
+ _family.each_value{|value|
571
+ if (value['name'] != nil) && @@defaults_values[self.class][_key][value['name']] == nil
572
+ if (value['default'] != nil)
573
+ @@defaults_values[self.class][_key][value['name']] = value['default']
574
+ elsif (value['get'] != nil)
575
+ @@defaults_values[self.class][_key][value['name']] = value['get'].call
576
+ end
577
+ end
578
+ }
579
+ }
580
+ ensure
581
+ if _obj
582
+ @obj = _obj_save
583
+ _obj.destroy
584
+ end
585
+ end
586
+
587
+ end
588
+
589
+
590
+ def delete
591
+ InspectorContract.instance.delete_wrapper(self, 'wrapper'=>self)
592
+ end
593
+
594
+ def AG.class_wrapped
595
+ nil
596
+ end
597
+
598
+ def AG.class_renderer
599
+ AGRenderer
600
+ end
601
+
602
+ def AG.class_sniffer
603
+ AGSniffer
604
+ end
605
+
606
+ def AG.active
607
+ @@active
608
+ end
609
+
610
+
611
+ def getFileName
612
+ __FILE__
613
+ end
614
+
615
+ def AG.publish_property(_name, args = nil)
616
+ # class_eval(%Q[
617
+ # def #{_name}
618
+ # @#{_name}
619
+ # #{args('get').call}
620
+ # end
621
+ #
622
+ # def #{_name}=(value)
623
+ # @#{_name} = value
624
+ # #{args('set').call(value)}
625
+ # end
626
+ # ])
627
+
628
+ end
629
+
630
+
631
+ def new_object
632
+ if self.class.class_wrapped
633
+ @obj = self.class.class_wrapped.new
634
+ end
635
+ end
636
+
637
+ def AG.near_class_wrapped(_obj)
638
+ clazz = _obj.class
639
+ while (ArcadiaLibs.wrapper_class(clazz) == nil)&&(clazz!=nil)
640
+ clazz = clazz.superclass
641
+ end
642
+ return clazz
643
+ end
644
+
645
+ def AG.near_class_wrapper(_obj)
646
+ ArcadiaLibs.wrapper_class(self.near_class_wrapped(_obj))
647
+ end
648
+
649
+
650
+ def passed_object(_obj)
651
+ @obj = _obj
652
+ end
653
+
654
+ def start_properties
655
+ @props.each_value{|family|
656
+ family.each_value{|value|
657
+ if value['start'] != nil
658
+ value['set'].call(value['start'])
659
+ end
660
+ }
661
+ }
662
+ end
663
+
664
+ def retrive_values
665
+ @props.each_value{|family|
666
+ family.each_value{|prop|
667
+ prop['value'] = prop['get'].call
668
+ }
669
+ }
670
+ end
671
+
672
+ def getViewClassName
673
+ return 'V',@i_name
674
+ end
675
+
676
+ def getControlClassName
677
+ return @i_name.capitalize
678
+ end
679
+
680
+ def getInstanceClass
681
+ return @i_name.capitalize
682
+ #return 'C',@i_name
683
+ end
684
+
685
+ def get_path_i_name
686
+ _return = @i_name
687
+ _agstart = self
688
+ while _agstart.ag_parent != nil
689
+ _return = _agstart.ag_parent.i_name,'.',_return
690
+ _agstart = _agstart.ag_parent
691
+ end
692
+ return _return
693
+ end
694
+
695
+ def get_implementation_new(_variable = false)
696
+ if (ag_parent == nil)|| _variable
697
+ result = '@',@i_name,' = ', getInstanceClass ,'.new(', '@',@ag_parent.i_name, ")\n"
698
+ end
699
+ result = result, self.class, '.new(', '@',@ag_parent.i_ag,", @",get_path_i_name,")"
700
+ end
701
+
702
+ def get_implementation_block
703
+ result = result, " @i_name = '", @i_name, "'\n"
704
+ result = result, " @i_ag = '", @i_ag, "'\n"
705
+ result = result, " @obj_class = '", getObjClass, "'\n"
706
+ end
707
+
708
+ def get_implementation_code
709
+ result = result, get_implementation_new, "{\n"
710
+ result = result, get_implementation_block
711
+ @requires.each_key do |key|
712
+ result = result," @object_inspector.addRequire('#{key}')\n"
713
+ end
714
+
715
+ result = result,"}"
716
+ end
717
+
718
+
719
+ def getObjClass
720
+ if defined? @obj_class
721
+ return @obj_class
722
+ else
723
+ return @obj.class
724
+ end
725
+ end
726
+
727
+ def publish_def(_family, args = nil)
728
+ @props_def[_family]=args
729
+ end
730
+
731
+ # def AG.publish_def(_family, args = nil)
732
+ # @@props_def = Hash.new if !defined?(@@props_def)
733
+ # @@props_def[_family]=args
734
+ # end
735
+
736
+
737
+ def publish(_family, args = nil)
738
+ if @props[_family] == nil
739
+ @props[_family] = Hash.new
740
+ end
741
+ @props[_family][args['name']]=args
742
+ args['kind'] != nil ? kind = args['kind']:kind = 'default'
743
+ if @props_kinds[_family] == nil
744
+ @props_kinds[_family] = Hash.new
745
+ end
746
+ if @props_kinds[_family][kind] == nil
747
+ @props_kinds[_family][kind] = Array.new
748
+ end
749
+ @props_kinds[_family][kind] << args['name']
750
+ end
751
+
752
+
753
+
754
+
755
+ # def AG.publish(_family, args = nil)
756
+ # @@props = Hash.new if !defined?(@@props)
757
+ # if @@props[_family] == nil
758
+ # @@props[_family] = Hash.new
759
+ # end
760
+ # @@props[_family][args['name']]=args
761
+ # args['kind'] != nil ? kind = args['kind']:kind = 'default'
762
+ # @@props_kinds = Hash.new if !defined?(@props_kinds)
763
+ # if @@props_kinds[_family] == nil
764
+ # @@props_kinds[_family] = Hash.new
765
+ # end
766
+ # if @@props_kinds[_family][kind] == nil
767
+ # @@props_kinds[_family][kind] = Array.new
768
+ # end
769
+ # @@props_kinds[_family][kind] << args['name']
770
+ # end
771
+
772
+
773
+ def publish_mod(_family, args = nil)
774
+ args.each do |key, value|
775
+ @props[_family][args['name']]["#{key}"] = value
776
+ end
777
+ end
778
+
779
+ # def AG.publish_mod(_family, args = nil)
780
+ # args.each do |key, value|
781
+ # @@props[_family][args['name']]["#{key}"] = value if !defined?(@@props)
782
+ # end
783
+ # end
784
+
785
+
786
+ def publish_del(_family, _name=nil)
787
+ if _name == nil
788
+ @props.delete(_family)
789
+ else
790
+ @props[_family].delete(_name)
791
+ end
792
+ end
793
+
794
+ # def AG.publish_del(_family, _name=nil)
795
+ # if _name == nil
796
+ # @@props.delete(_family)
797
+ # else
798
+ # @@props[_family].delete(_name)
799
+ # end
800
+ # end
801
+
802
+ def properties
803
+ publish( 'property',
804
+ 'name' => 'name',
805
+ 'get'=> proc{@i_name},
806
+ 'set'=> proc{|n| self.i_name = n},
807
+ 'def'=> 'nodef'
808
+ )
809
+ end
810
+
811
+
812
+
813
+ # def delete
814
+ # @obj.destroy
815
+ # end
816
+
817
+ # def setp(_family, _name, _value)
818
+ # @props[_family][_name]['set'].call(_value)
819
+ # tobj = InspectorActionContract::TInspectorActionObj.new(self)
820
+ # tobj.wrapper = self
821
+ # tobj.property_family = _family
822
+ # tobj.property_name = _name
823
+ # tobj.property_value = _value
824
+ # InspectorActionContract.instance.update_property(tobj)
825
+ # end
826
+
827
+ def update_property(_sender, _family,_name,_value)
828
+ old_value = @props[_family][_name]['get'].call(_value)
829
+ if old_value != _value
830
+ @props[_family][_name]['set'].call(_value)
831
+ end
832
+ WrapperContract.instance.property_updated(self,
833
+ 'wrapper'=>self,
834
+ 'property_name'=> _name,
835
+ 'property_family'=>_family,
836
+ 'property_old_value'=>old_value,
837
+ 'property_new_value'=>_value
838
+ )
839
+ end
840
+
841
+ # def updatep(_family, prop, value, _call_from_inspector=false)
842
+ # @props[_family][prop]['set'].call(value)
843
+ # end
844
+
845
+ end
846
+
847
+
848
+ class ObserverCallbackContract < ObserverCallback
849
+ def initialize(_publisher, _subscriber, _method_update_to_call=:update, _channel=nil)
850
+ super(_publisher, _subscriber, _method_update_to_call)
851
+ @channel = _channel
852
+ @channel_conf = @subscriber.conf(@publisher.class.to_s+'.channel') if @subscriber.respond_to?(:conf)
853
+ end
854
+
855
+ def filter(_event)
856
+ @channel_conf != nil && @channel_conf != _event.channel
857
+ end
858
+
859
+ def update(_event, *args)
860
+ super(_event, *args) if !filter(_event)
861
+ end
862
+ end
863
+
864
+
865
+ class ObserverCallbackContractThread < ObserverCallbackContract
866
+ def update(*args)
867
+ Thread.new do
868
+ super(*args)
869
+ end
870
+ end
871
+
872
+ end
873
+
874
+
875
+
876
+ # The contract define the interface beetwhen extension
877
+ # in particulare define method than raise event to observers client
878
+ # and a way to retreive state from client
879
+
880
+ class ArcadiaContract
881
+ include Observable
882
+ include Singleton
883
+ class ContractEvent
884
+ attr_reader :contract
885
+ attr_reader :signature
886
+ attr_reader :context
887
+ attr_reader :channel
888
+ attr_reader :time
889
+ attr_writer :action
890
+
891
+ SIGNATURE = "NOT_DEFINED"
892
+ def initialize(_contract, _signature=SIGNATURE, _context=nil)
893
+ @contract = _contract
894
+ @signature = _signature
895
+ @context = _context
896
+ _context.channel != nil ?@channel=_context.channel: @channel='0'
897
+ @time = Time.new
898
+ @action = false
899
+ end
900
+
901
+ def handled(_from)
902
+ MainContract.instance.event_handled(_from,'caused_by'=>self)
903
+ end
904
+
905
+ def is_action?
906
+ @action
907
+ end
908
+ end
909
+
910
+ class TObj
911
+ attr_reader :sender
912
+ attr_accessor :caused_by
913
+ attr_accessor :channel
914
+ DEFAULT_CHANNEL='0'
915
+ def initialize(_sender, _args=nil)
916
+ @sender=_sender
917
+ @channel = DEFAULT_CHANNEL
918
+ if _args
919
+ _args.each do |key, value|
920
+ self.send(key+'=', value)
921
+ end
922
+ end
923
+
924
+ end
925
+
926
+ # properties.each do |prop|
927
+ # define_method(prop) {
928
+ # instance_variable_get("@#{prop}")
929
+ # }
930
+ # define_method("#{prop}=") do |value|
931
+ # instance_variable_set("@#{prop}", value)
932
+ # end
933
+ # end
934
+
935
+ # define_method(prop)
936
+ # attr_reader prop.to_sym # prop by itself also worked for me
937
+ # # code snip ? setter method
938
+ # end
939
+
940
+
941
+ # def TObj.property(*properties)
942
+ # properties.each { |property|
943
+ # class_eval(%Q[
944
+ # def #{property}
945
+ # @#{property}
946
+ # end
947
+ #
948
+ # def #{property}=(value)
949
+ # @#{property} = value
950
+ # end
951
+ # ])
952
+ # }
953
+ # end
954
+ end
955
+
956
+ class EventInfo
957
+ attr_reader :method
958
+ attr_reader :label
959
+ attr_reader :icon
960
+ def initialize(_method)
961
+ @method = @method
962
+ end
963
+ end
964
+
965
+ SObj = Struct.new("GenericState",
966
+ :caller
967
+ )
968
+
969
+ def _event_forge(_event_signature, _tobj)
970
+ ContractEvent.new(self, _event_signature, _tobj)
971
+ end
972
+ private :_event_forge
973
+
974
+
975
+ def raise_event(_event_signature, _tobj, *args)
976
+ _raise_event(_event_forge(_event_signature, _tobj),*args)
977
+ end
978
+
979
+ def _raise_event(_event, *args)
980
+ changed
981
+ notify_observers(_event, *args)
982
+ if self.class != ArcadiaContract
983
+ self.class.superclass.instance._raise_event(_event, *args)
984
+ end
985
+ end
986
+ #protected :_raise_event
987
+
988
+ def raise_action(_event_signature, _tobj, *args)
989
+ _raise_action(_event_forge(_event_signature, _tobj),*args)
990
+ end
991
+
992
+ def _raise_action(_event, *args)
993
+ _event.action = true
994
+ _raise_event(_event, *args)
995
+ end
996
+ private :_raise_action
997
+
998
+ def ArcadiaContract.publish_action(_method)
999
+ _info = EventInfo.new(_method)
1000
+ @@actions = Array.new if !defined?(@@actions)
1001
+ @@actions << _info
1002
+ end
1003
+
1004
+ end
1005
+
1006
+ class ArcadiaContractListener
1007
+ def initialize(_subscriber, _class, _method, _channel=nil)
1008
+ @subscriber = _subscriber
1009
+ @class = _class
1010
+ @method = _method
1011
+ @channel = _channel
1012
+ create_callback(_class.instance)
1013
+ end
1014
+
1015
+ def create_callback(_contract)
1016
+ ObserverCallbackContract.new(_contract, @subscriber, @method, @channel)
1017
+ end
1018
+
1019
+ end
1020
+
1021
+ class ArcadiaContractListenerThread < ArcadiaContractListener
1022
+
1023
+ def create_callback(_contract)
1024
+ #Thread.new do super(_contract, _subscriber, _method) end
1025
+ ObserverCallbackContractThread.new(_contract, @subscriber, @method, @channel)
1026
+ end
1027
+
1028
+ end
1029
+
1030
+
1031
+ #---------------- contracts ----------------------
1032
+ class InspectorContract < ArcadiaContract
1033
+ SObj = Struct.new("InspectorActionState"
1034
+ )
1035
+ class TInspectorObj < TObj
1036
+ attr_accessor :wrapper, :requires, :property_family,:property_name,:property_value
1037
+ end
1038
+
1039
+ SELECT_WRAPPER = "SELECT_WRAPPER"
1040
+ #ACTIVATE_WRAPPER = "ACTIVATE_WRAPPER"
1041
+ DELETE_WRAPPER = "DELETE_WRAPPER"
1042
+ ADD_REQUIRE = "ADD_REQUIRE"
1043
+ REGISTER_WRAPPER = "REGISTER_WRAPPER"
1044
+ # UPDATE_PROPERTY = "UPDATE_PROPERTY"
1045
+ DELETE_INSPECTOR = "DELETE_INSPECTOR"
1046
+ RAISE_LAST_WIDGET = "RAISE_LAST_WIDGET"
1047
+ RAISE_ACTIVE_TOPLEVEL = "RAISE_ACTIVE_TOPLEVEL"
1048
+
1049
+ def delete_wrapper(_sender, *args)
1050
+ raise_action(DELETE_WRAPPER, TInspectorObj.new(_sender, *args))
1051
+ end
1052
+
1053
+ def raise_last_widget(_sender, *args)
1054
+ raise_action(RAISE_LAST_WIDGET, TInspectorObj.new(_sender, *args))
1055
+ end
1056
+
1057
+ def raise_active_toplevel(_sender, *args)
1058
+ raise_action(RAISE_ACTIVE_TOPLEVEL, TInspectorObj.new(_sender, *args))
1059
+ end
1060
+
1061
+ def select(_sender, *args)
1062
+ raise_action(SELECT_WRAPPER, TInspectorObj.new(_sender, *args))
1063
+ end
1064
+
1065
+ def add_require(_sender, *args)
1066
+ raise_action(ADD_REQUIRE, TInspectorObj.new(_sender, *args))
1067
+ end
1068
+
1069
+ def register(_sender, *args)
1070
+ raise_action(REGISTER_WRAPPER, TInspectorObj.new(_sender, *args))
1071
+ end
1072
+
1073
+ def delete_inspector(_sender, *args)
1074
+ raise_action(DELETE_INSPECTOR, TInspectorObj.new(_sender, *args))
1075
+ end
1076
+
1077
+ publish_action :raise_active_object
1078
+ end
1079
+
1080
+ class WrapperContract < ArcadiaContract
1081
+ class TWrapperObj < TObj
1082
+ attr_accessor :wrapper, :property_name, :property_family, :property_old_value, :property_new_value
1083
+ end
1084
+ WRAPPER_AFTER_CREATE="WRAPPER_AFTER_CREATE"
1085
+ PROPERTY_AFTER_UPDATE="PROPERTY_AFTER_UPDATE"
1086
+ UPDATE_PROPERTY="UPDATE_PROPERTY"
1087
+ def update_property(_sender, *args)
1088
+ raise_action(UPDATE_PROPERTY, TWrapperObj.new(_sender, *args))
1089
+ end
1090
+ def property_updated(_sender, *args)
1091
+ raise_event(PROPERTY_AFTER_UPDATE, TWrapperObj.new(_sender, *args))
1092
+ end
1093
+ def wrapper_created(_sender, *args)
1094
+ raise_event(WRAPPER_AFTER_CREATE, TWrapperObj.new(_sender, *args))
1095
+ end
1096
+ end
1097
+
1098
+ class PaletteContract < ArcadiaContract
1099
+ class TPaletteObj < TObj
1100
+ attr_accessor :parent, :x, :y
1101
+ end
1102
+ MAKE_SELECTED_WRAPPER = "MAKE_SELECTED_WRAPPER"
1103
+ def make_selected(_sender, *args)
1104
+ raise_action(MAKE_SELECTED_WRAPPER, TPaletteObj.new(_sender, *args))
1105
+ end
1106
+ end
1107
+
1108
+
1109
+
1110
+ #class AeContractListener
1111
+ # def initialize(_arcadia)
1112
+ #
1113
+ # end
1114
+ # def listen_on(_aeclip_name, _method_update_to_call=:update)
1115
+ # end
1116
+ # def update(_tobj)
1117
+ # end
1118
+ #end