Class: AG

Inherits:
Object
  • Object
show all
Defined in:
ext/ae-rad/ae-rad-libs.rb

Direct Known Subclasses

AGINTk, AGTk, AGTkMenu

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_ag_parent = nil, _object = nil) {|_self| ... } ⇒ AG

Returns a new instance of AG.

Yields:

  • (_self)

Yield Parameters:

  • _self (AG)

    the object that the method was called on



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# File 'ext/ae-rad/ae-rad-libs.rb', line 418

def initialize(_ag_parent = nil, _object = nil)
  @ag_parent = _ag_parent
  if _object == nil
    new_object
  else
    passed_object(_object)
  end

  @obj_class = self.class.near_class_wrapped(@obj)
  @sons = Array.new
  @renderer=self.class.class_renderer.new(self)
  @sniffer=self.class.class_sniffer.new(@obj)
  yield(self) if block_given?
  if !defined?(@i_name)
    @i_name = self.class.class_wrapped.to_s.gsub('::','_') + new_id
    @i_name = @i_name.sub(/^./) { $&.downcase}
  end
  @i_ag = 'ag' + @i_name
  @props = Hash.new
  @props_def = Hash.new
  @props_kinds = Hash.new
  @persistent = Hash.new
  @requires = Hash.new
  properties
  defaults(_object != nil )
  if _object != nil
    retrive_values
  else
    start_properties
  end
  self.register
end

Instance Attribute Details

#ag_parentObject (readonly)

Returns the value of attribute ag_parent.



410
411
412
# File 'ext/ae-rad/ae-rad-libs.rb', line 410

def ag_parent
  @ag_parent
end

#i_agObject

Returns the value of attribute i_ag.



410
411
412
# File 'ext/ae-rad/ae-rad-libs.rb', line 410

def i_ag
  @i_ag
end

#i_nameObject

Returns the value of attribute i_name.



410
411
412
# File 'ext/ae-rad/ae-rad-libs.rb', line 410

def i_name
  @i_name
end

#objObject (readonly)

Returns the value of attribute obj.



410
411
412
# File 'ext/ae-rad/ae-rad-libs.rb', line 410

def obj
  @obj
end

#obj_classObject (readonly)

Returns the value of attribute obj_class.



410
411
412
# File 'ext/ae-rad/ae-rad-libs.rb', line 410

def obj_class
  @obj_class
end

#persistentObject (readonly)

Returns the value of attribute persistent.



413
414
415
# File 'ext/ae-rad/ae-rad-libs.rb', line 413

def persistent
  @persistent
end

#propsObject

Returns the value of attribute props.



410
411
412
# File 'ext/ae-rad/ae-rad-libs.rb', line 410

def props
  @props
end

#props_defObject (readonly)

Returns the value of attribute props_def.



410
411
412
# File 'ext/ae-rad/ae-rad-libs.rb', line 410

def props_def
  @props_def
end

#props_kindsObject (readonly)

attr_reader :props_seq



415
416
417
# File 'ext/ae-rad/ae-rad-libs.rb', line 415

def props_kinds
  @props_kinds
end

#rendererObject (readonly)

Returns the value of attribute renderer.



411
412
413
# File 'ext/ae-rad/ae-rad-libs.rb', line 411

def renderer
  @renderer
end

#snifferObject (readonly)

Returns the value of attribute sniffer.



412
413
414
# File 'ext/ae-rad/ae-rad-libs.rb', line 412

def sniffer
  @sniffer
end

#sonsObject (readonly)

Returns the value of attribute sons.



411
412
413
# File 'ext/ae-rad/ae-rad-libs.rb', line 411

def sons
  @sons
end

Class Method Details

.activeObject



606
607
608
# File 'ext/ae-rad/ae-rad-libs.rb', line 606

def AG.active
  @@active
end

.class_rendererObject



598
599
600
# File 'ext/ae-rad/ae-rad-libs.rb', line 598

def AG.class_renderer
  AGRenderer
end

.class_snifferObject



602
603
604
# File 'ext/ae-rad/ae-rad-libs.rb', line 602

def AG.class_sniffer
  AGSniffer
end

.class_wrappedObject



594
595
596
# File 'ext/ae-rad/ae-rad-libs.rb', line 594

def AG.class_wrapped
  nil
end

.near_class_wrapped(_obj) ⇒ Object



637
638
639
640
641
642
643
# File 'ext/ae-rad/ae-rad-libs.rb', line 637

def AG.near_class_wrapped(_obj)
  clazz = _obj.class
  while (ArcadiaLibs.wrapper_class(clazz) == nil)&&(clazz!=nil)
    clazz = clazz.superclass
  end
  return clazz
end

.near_class_wrapper(_obj) ⇒ Object



645
646
647
# File 'ext/ae-rad/ae-rad-libs.rb', line 645

def AG.near_class_wrapper(_obj)
  ArcadiaLibs.wrapper_class(self.near_class_wrapped(_obj))
end

.publish_property(_name, args = nil) ⇒ Object



615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'ext/ae-rad/ae-rad-libs.rb', line 615

def AG.publish_property(_name, args = nil)
#        class_eval(%Q[
#          def #{_name}
#            @#{_name}
#						#{args('get').call}
#          end
#  
#          def #{_name}=(value)
#            @#{_name} = value
#						#{args('set').call(value)}
#          end
#        ])

end

Instance Method Details

#activateObject



472
473
474
# File 'ext/ae-rad/ae-rad-libs.rb', line 472

def activate
  @@active = self
end

#add_require(_require) ⇒ Object



451
452
453
454
455
456
457
# File 'ext/ae-rad/ae-rad-libs.rb', line 451

def add_require(_require)
  if @requires[_require] == nil
    @requires[_require] = 1
  else
    @requires[_require] += 1
  end
end

#build_sonsObject



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'ext/ae-rad/ae-rad-libs.rb', line 477

def build_sons
  iv = @obj.instance_variables
  if iv.length > 0
    cod = " class << @obj"+"\n"
    iv.each{|i|
      i.delete!('@')
      cod = cod + "  attr_reader  :"+i+"\n"
    }
    cod = cod +"end\n"
    eval(cod)
  end
  iv_obj = Hash.new
  iv.each{|i|
    iv_obj[i] = eval("@obj."+i)
  }
  i_name = nil
  self.sniffer.sons.each{|obj_son|
    clazz = self.class.near_class_wrapper(obj_son)
    if clazz != nil
      iv_obj.each{|key, value|
        if value == obj_son
          i_name=key
        end
      }
      if i_name == nil
        clazz.new(self,obj_son)
      else
        clazz.new(self,obj_son){|_self| _self.i_name = i_name}
      end
    end
  }
end

#defaults(_new = false) ⇒ Object



543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'ext/ae-rad/ae-rad-libs.rb', line 543

def defaults(_new=false)
  if !defined?(@@defaults_values)
    @@defaults_values = Hash.new
  end
  if (!defined?(@@defaults_values[self.class]))||(@@defaults_values[self.class] == nil)
    @@defaults_values[self.class] = Hash.new
    if _new
      _obj = @obj_class.new
      fill_defaults_value_from_agobj(_obj)
    else
      fill_defaults_value_from_agobj
    end
  end
end

#defaults_valuesObject



539
540
541
# File 'ext/ae-rad/ae-rad-libs.rb', line 539

def defaults_values
  @@defaults_values
end

#del_require(_require) ⇒ Object



459
460
461
462
463
464
# File 'ext/ae-rad/ae-rad-libs.rb', line 459

def del_require(_require)
  @requires[_require] -= 1
  if @requires[_require] == 0
    @requires[_require] = nil
  end
end

#deleteObject



590
591
592
# File 'ext/ae-rad/ae-rad-libs.rb', line 590

def delete
		InspectorContract.instance.delete_wrapper(self, 'wrapper'=>self)
end

#fill_defaults_value_from_agobj(_obj = nil) ⇒ Object



558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'ext/ae-rad/ae-rad-libs.rb', line 558

def fill_defaults_value_from_agobj(_obj=nil)
  #return if _obj == nil
  _obj_save = @obj
  if _obj
    @obj = _obj
  end
  begin
    @props.each{|_key,_family|
      #Tk.messageBox('message'=>_key)
      if @@defaults_values[self.class][_key] == nil
        @@defaults_values[self.class][_key] = Hash.new
      end
      _family.each_value{|value|
        if (value['name'] != nil) && @@defaults_values[self.class][_key][value['name']] == nil
          if (value['default'] != nil)
            @@defaults_values[self.class][_key][value['name']] = value['default']
          elsif (value['get'] != nil)
            @@defaults_values[self.class][_key][value['name']] = value['get'].call
          end
        end
      }
    }
  ensure
    if _obj
      @obj = _obj_save
      _obj.destroy
    end
  end

end

#get_implementation_blockObject



702
703
704
705
706
# File 'ext/ae-rad/ae-rad-libs.rb', line 702

def get_implementation_block
  result = result, "  @i_name = '", @i_name, "'\n"
  result = result, "  @i_ag = '", @i_ag, "'\n"
  result = result, "  @obj_class = '", getObjClass, "'\n"
end

#get_implementation_codeObject



708
709
710
711
712
713
714
715
716
# File 'ext/ae-rad/ae-rad-libs.rb', line 708

def get_implementation_code
  result = result, get_implementation_new, "{\n"
  result = result, get_implementation_block
  @requires.each_key do |key|
    result = result,"  @object_inspector.addRequire('#{key}')\n"
  end
  
  result = result,"}"
end

#get_implementation_new(_variable = false) ⇒ Object



695
696
697
698
699
700
# File 'ext/ae-rad/ae-rad-libs.rb', line 695

def get_implementation_new(_variable = false)
  if (ag_parent == nil)|| _variable
    result = '@',@i_name,' = ', getInstanceClass ,'.new(', '@',@ag_parent.i_name, ")\n"
  end
  result = result, self.class, '.new(', '@',@ag_parent.i_ag,", @",get_path_i_name,")"
end

#get_path_i_nameObject



685
686
687
688
689
690
691
692
693
# File 'ext/ae-rad/ae-rad-libs.rb', line 685

def get_path_i_name
  _return = @i_name
  _agstart = self
  while _agstart.ag_parent != nil
    _return = _agstart.ag_parent.i_name,'.',_return
    _agstart = _agstart.ag_parent
  end
  return _return
end

#getControlClassNameObject



676
677
678
# File 'ext/ae-rad/ae-rad-libs.rb', line 676

def getControlClassName
  return @i_name.capitalize
end

#getFileNameObject



611
612
613
# File 'ext/ae-rad/ae-rad-libs.rb', line 611

def getFileName
  __FILE__
end

#getInstanceClassObject



680
681
682
683
# File 'ext/ae-rad/ae-rad-libs.rb', line 680

def getInstanceClass
  return @i_name.capitalize
  #return 'C',@i_name
end

#getObjClassObject



719
720
721
722
723
724
725
# File 'ext/ae-rad/ae-rad-libs.rb', line 719

def getObjClass
  if defined? @obj_class
    return @obj_class
  else
    return @obj.class
  end
end

#getViewClassNameObject



672
673
674
# File 'ext/ae-rad/ae-rad-libs.rb', line 672

def getViewClassName
  return 'V',@i_name
end

#has_sonsObject



523
524
525
# File 'ext/ae-rad/ae-rad-libs.rb', line 523

def has_sons
  return (self.sons.length > 0)
end

#new_idObject



527
528
529
530
531
532
533
534
535
536
537
# File 'ext/ae-rad/ae-rad-libs.rb', line 527

def new_id
  if !defined?(@@ag_id)
    @@ag_id = Hash.new
  end
  if (@@ag_id[self.class]==nil)
    @@ag_id[self.class] = 1
  else
    @@ag_id[self.class] = @@ag_id[self.class] + 1
  end
  return @@ag_id[self.class].to_s
end

#new_objectObject



631
632
633
634
635
# File 'ext/ae-rad/ae-rad-libs.rb', line 631

def new_object
  if self.class.class_wrapped
    @obj = self.class.class_wrapped.new
  end
end

#passed_object(_obj) ⇒ Object



650
651
652
# File 'ext/ae-rad/ae-rad-libs.rb', line 650

def passed_object(_obj)
  @obj = _obj
end

#propertiesObject

def AG.publish_del(_family, _name=nil)

  if _name == nil
    @@props.delete(_family)
  else
    @@props[_family].delete(_name)
  end
end


802
803
804
805
806
807
808
809
# File 'ext/ae-rad/ae-rad-libs.rb', line 802

def properties
  publish( 'property',
  'name' => 'name',
  'get'=> proc{@i_name},
  'set'=> proc{|n| self.i_name = n},
  'def'=> 'nodef'
  )
end

#publish(_family, args = nil) ⇒ Object



737
738
739
740
741
742
743
744
745
746
747
748
749
750
# File 'ext/ae-rad/ae-rad-libs.rb', line 737

def publish(_family, args = nil)
  if @props[_family] == nil
    @props[_family] = Hash.new
  end
  @props[_family][args['name']]=args
  args['kind'] != nil ? kind = args['kind']:kind = 'default'
  if @props_kinds[_family] == nil
    @props_kinds[_family] = Hash.new
  end
  if @props_kinds[_family][kind] == nil
    @props_kinds[_family][kind] = Array.new
  end
  @props_kinds[_family][kind] << args['name']
end

#publish_def(_family, args = nil) ⇒ Object



727
728
729
# File 'ext/ae-rad/ae-rad-libs.rb', line 727

def publish_def(_family, args = nil)
  @props_def[_family]=args
end

#publish_del(_family, _name = nil) ⇒ Object



786
787
788
789
790
791
792
# File 'ext/ae-rad/ae-rad-libs.rb', line 786

def publish_del(_family, _name=nil)
  if _name == nil
    @props.delete(_family)
  else
    @props[_family].delete(_name)
  end
end

#publish_mod(_family, args = nil) ⇒ Object



773
774
775
776
777
# File 'ext/ae-rad/ae-rad-libs.rb', line 773

def publish_mod(_family, args = nil)
  args.each do |key, value|
    @props[_family][args['name']]["#{key}"] = value
  end
end

#register(_agobj = self) ⇒ Object



510
511
512
513
514
515
516
517
518
519
520
521
# File 'ext/ae-rad/ae-rad-libs.rb', line 510

def register(_agobj=self)
  @sons << _agobj if _agobj!=self && _agobj.ag_parent == self
  if @ag_parent
    return @ag_parent.register(_agobj)
  else
  		WrapperContract.instance.wrapper_created(self,'wrapper'=>_agobj)
#
#	    _tobj = InspectorActionContract::TInspectorActionObj.new(self)
# 		  _tobj.wrapper = _agobj
#    		InspectorActionContract.instance.register(_tobj)
  end
end

#retrive_valuesObject



664
665
666
667
668
669
670
# File 'ext/ae-rad/ae-rad-libs.rb', line 664

def retrive_values
  @props.each_value{|family|
    family.each_value{|prop|
      prop['value'] = prop['get'].call
    }
  }
end

#selectObject



466
467
468
469
# File 'ext/ae-rad/ae-rad-libs.rb', line 466

def select
  InspectorContract.instance.select(self, 'wrapper'=>self)
  self
end

#start_propertiesObject



654
655
656
657
658
659
660
661
662
# File 'ext/ae-rad/ae-rad-libs.rb', line 654

def start_properties
  @props.each_value{|family|
    family.each_value{|value|
      if value['start'] != nil
        value['set'].call(value['start'])
      end
    }
  }
end

#update_property(_sender, _family, _name, _value) ⇒ Object

def setp(_family, _name, _value)

  @props[_family][_name]['set'].call(_value)
  tobj = InspectorActionContract::TInspectorActionObj.new(self)
  tobj.wrapper = self
  tobj.property_family = _family
  tobj.property_name = _name
  tobj.property_value = _value
  InspectorActionContract.instance.update_property(tobj)
end


827
828
829
830
831
832
833
834
835
836
837
838
839
# File 'ext/ae-rad/ae-rad-libs.rb', line 827

def update_property(_sender, _family,_name,_value)
	 old_value = @props[_family][_name]['get'].call(_value)
	 if old_value != _value
  		@props[_family][_name]['set'].call(_value)
  end
		WrapperContract.instance.property_updated(self, 
					'wrapper'=>self,
					'property_name'=> _name,
					'property_family'=>_family,
					'property_old_value'=>old_value,
					'property_new_value'=>_value  				
		)
end