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


426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'ext/ae-rad/ae-rad-libs.rb', line 426

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


418
419
420
# File 'ext/ae-rad/ae-rad-libs.rb', line 418

def ag_parent
  @ag_parent
end

#i_agObject

Returns the value of attribute i_ag


418
419
420
# File 'ext/ae-rad/ae-rad-libs.rb', line 418

def i_ag
  @i_ag
end

#i_nameObject

Returns the value of attribute i_name


418
419
420
# File 'ext/ae-rad/ae-rad-libs.rb', line 418

def i_name
  @i_name
end

#objObject (readonly)

Returns the value of attribute obj


418
419
420
# File 'ext/ae-rad/ae-rad-libs.rb', line 418

def obj
  @obj
end

#obj_classObject (readonly)

Returns the value of attribute obj_class


418
419
420
# File 'ext/ae-rad/ae-rad-libs.rb', line 418

def obj_class
  @obj_class
end

#persistentObject (readonly)

Returns the value of attribute persistent


421
422
423
# File 'ext/ae-rad/ae-rad-libs.rb', line 421

def persistent
  @persistent
end

#propsObject

Returns the value of attribute props


418
419
420
# File 'ext/ae-rad/ae-rad-libs.rb', line 418

def props
  @props
end

#props_defObject (readonly)

Returns the value of attribute props_def


418
419
420
# File 'ext/ae-rad/ae-rad-libs.rb', line 418

def props_def
  @props_def
end

#props_kindsObject (readonly)

attr_reader :props_seq


423
424
425
# File 'ext/ae-rad/ae-rad-libs.rb', line 423

def props_kinds
  @props_kinds
end

#rendererObject (readonly)

Returns the value of attribute renderer


419
420
421
# File 'ext/ae-rad/ae-rad-libs.rb', line 419

def renderer
  @renderer
end

#snifferObject (readonly)

Returns the value of attribute sniffer


420
421
422
# File 'ext/ae-rad/ae-rad-libs.rb', line 420

def sniffer
  @sniffer
end

#sonsObject (readonly)

Returns the value of attribute sons


419
420
421
# File 'ext/ae-rad/ae-rad-libs.rb', line 419

def sons
  @sons
end

Class Method Details

.activeObject


614
615
616
# File 'ext/ae-rad/ae-rad-libs.rb', line 614

def AG.active
  @@active
end

.class_rendererObject


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

def AG.class_renderer
  AGRenderer
end

.class_snifferObject


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

def AG.class_sniffer
  AGSniffer
end

.class_wrappedObject


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

def AG.class_wrapped
  nil
end

.near_class_wrapped(_obj) ⇒ Object


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

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


653
654
655
# File 'ext/ae-rad/ae-rad-libs.rb', line 653

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

.publish_property(_name, args = nil) ⇒ Object


623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'ext/ae-rad/ae-rad-libs.rb', line 623

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


480
481
482
# File 'ext/ae-rad/ae-rad-libs.rb', line 480

def activate
  @@active = self
end

#add_require(_require) ⇒ Object


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

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

#build_sonsObject


485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'ext/ae-rad/ae-rad-libs.rb', line 485

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


551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'ext/ae-rad/ae-rad-libs.rb', line 551

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


547
548
549
# File 'ext/ae-rad/ae-rad-libs.rb', line 547

def defaults_values
  @@defaults_values
end

#del_require(_require) ⇒ Object


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

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

#deleteObject


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

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

#fill_defaults_value_from_agobj(_obj = nil) ⇒ Object


566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'ext/ae-rad/ae-rad-libs.rb', line 566

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


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

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


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

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


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

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


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

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


684
685
686
# File 'ext/ae-rad/ae-rad-libs.rb', line 684

def getControlClassName
  return @i_name.capitalize
end

#getFileNameObject


619
620
621
# File 'ext/ae-rad/ae-rad-libs.rb', line 619

def getFileName
  __FILE__
end

#getInstanceClassObject


688
689
690
691
# File 'ext/ae-rad/ae-rad-libs.rb', line 688

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

#getObjClassObject


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

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

#getViewClassNameObject


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

def getViewClassName
  return 'V',@i_name
end

#has_sonsObject


531
532
533
# File 'ext/ae-rad/ae-rad-libs.rb', line 531

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

#new_idObject


535
536
537
538
539
540
541
542
543
544
545
# File 'ext/ae-rad/ae-rad-libs.rb', line 535

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


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

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

#passed_object(_obj) ⇒ Object


658
659
660
# File 'ext/ae-rad/ae-rad-libs.rb', line 658

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

810
811
812
813
814
815
816
817
# File 'ext/ae-rad/ae-rad-libs.rb', line 810

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


745
746
747
748
749
750
751
752
753
754
755
756
757
758
# File 'ext/ae-rad/ae-rad-libs.rb', line 745

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


735
736
737
# File 'ext/ae-rad/ae-rad-libs.rb', line 735

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

#publish_del(_family, _name = nil) ⇒ Object


794
795
796
797
798
799
800
# File 'ext/ae-rad/ae-rad-libs.rb', line 794

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


781
782
783
784
785
# File 'ext/ae-rad/ae-rad-libs.rb', line 781

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

#register(_agobj = self) ⇒ Object


518
519
520
521
522
523
524
525
526
527
528
529
# File 'ext/ae-rad/ae-rad-libs.rb', line 518

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


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

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

#selectObject


474
475
476
477
# File 'ext/ae-rad/ae-rad-libs.rb', line 474

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

#start_propertiesObject


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

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

835
836
837
838
839
840
841
842
843
844
845
846
847
# File 'ext/ae-rad/ae-rad-libs.rb', line 835

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