Class: ArcadiaExtPlus

Inherits:
ArcadiaExt show all
Defined in:
lib/a-commons.rb

Direct Known Subclasses

AgMultiEditor, DirProjects, Term

Instance Attribute Summary collapse

Attributes inherited from ArcadiaExt

#arcadia, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ArcadiaExt

#add_to_conf_property, #array_conf, #conf, #conf_array, #conf_default, #del_from_conf_property, #destroy_frame, #exec, #float_frame, #frame_def_visible?, #frame_domain, #frame_domain_default, #frame_raised?, #frame_title, #frame_visible?, #hide_frame, #hinner_dialog, #hinner_splitted_dialog, #hinner_splitted_dialog_titled, #maximize, #maximized?, #resize, #restore_default_conf

Constructor Details

#initialize(_arcadia, _name = nil) ⇒ ArcadiaExtPlus

Returns a new instance of ArcadiaExtPlus.



430
431
432
433
434
435
436
437
438
439
440
# File 'lib/a-commons.rb', line 430

def initialize(_arcadia, _name=nil)
  @@instances = {} if !defined?(@@instances)
  @@main_instance = {} if !defined?(@@main_instance)
  @@active_instance = {} if !defined?(@@active_instance)
  @@instances[self.class] = [] if @@instances[self.class] == nil
  @@instances[self.class] << self
  @@main_instance[self.class] = self if @@main_instance[self.class] == nil
  Arcadia.attach_listener(self, ActivateInstanceEvent)
  super(_arcadia, _name)
  @@active_instance[self.class] = self if @@active_instance[self.class] == nil
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



428
429
430
# File 'lib/a-commons.rb', line 428

def index
  @index
end

Class Method Details

.instances(_class) ⇒ Object



468
469
470
# File 'lib/a-commons.rb', line 468

def ArcadiaExtPlus.instances(_class)
  @@instances[_class]
end

Instance Method Details

#activate(_obj = self, _raise_event = true) ⇒ Object



484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/a-commons.rb', line 484

def activate(_obj=self, _raise_event=true)
  return if @@active_instance[_obj.class] == _obj
  @@active_instance[_obj.class] = _obj #if @arcadia.initialized?
#    if _obj.frame_visible?
#      @@active_instance[_obj.class] = nil
#    else
#      @@active_instance[_obj.class] = _obj
#    end
  _obj.frame.root.shift_on if _obj.frame_visible?
  instances.each{|i|
    i.frame.root.shift_off if i != _obj  && i.frame != nil && i.frame.root != _obj.frame.root && i.frame_raised?
  }
  ActivateInstanceEvent.new(Arcadia.instance, 'name'=>_obj.name).go! if _raise_event
end

#activate_mainObject



499
500
501
# File 'lib/a-commons.rb', line 499

def activate_main
  activate(@@main_instance[self.class])
end

#active?Boolean

Returns:

  • (Boolean)


503
504
505
# File 'lib/a-commons.rb', line 503

def active?
  @@active_instance[self.class] == self
end

#active_instanceObject



472
473
474
# File 'lib/a-commons.rb', line 472

def active_instance
  @@active_instance[self.class]
end

#clean_instanceObject

def on_before_layout_raising_frame(_event)

  if _event.extension_name == @name
    activate
  end
end


577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
# File 'lib/a-commons.rb', line 577

def clean_instance
  if main_instance?
    @frames.each_index{|i| 
      LayoutChangedDomainEvent.new(self, 'old_domain'=>self.frame_domain(i), 'new_domain'=>nil).go!
      destroy_frame(i)
    }
    @frames.clear
    instances.each{|i| 
      if i != self
        activate(i)
        break
      end
    }
  else
    @@instances[self.class].delete(self) if @@instances[self.class]
    Arcadia.del_conf_group(Arcadia['conf'],@name)
    Arcadia.del_conf_group(Arcadia['pers'],@name)
    main_instance.del_from_conf_property("clones", @name)
    Arcadia.process_event(ClearCacheInstanceEvent.new(Arcadia.instance), [self])
    Arcadia.process_event(DestroyInstanceEvent.new(Arcadia.instance), [self])
    activate_main #if main_instance.frame_visible?
  end
end

#clone(_name, _dom = nil) ⇒ Object



553
554
555
556
557
558
559
560
561
# File 'lib/a-commons.rb', line 553

def clone(_name, _dom=nil)
  #create
  instance = self.class.new(Arcadia.instance, _name)
  #build
  Arcadia.process_event(BuildEvent.new(Arcadia.instance), [instance])
  Arcadia.attach_listener(instance, ClearCacheInstanceEvent)
  Arcadia.attach_listener(instance, DestroyInstanceEvent)
  instance
end

#deduplicateObject



601
602
603
604
605
606
607
608
609
610
611
# File 'lib/a-commons.rb', line 601

def deduplicate
  can_exit=true
  if @confirm_on_exit && (Arcadia.dialog(self, 'type'=>'yes_no',
    'msg'=>Arcadia.text('main.d.confirm_delete_ext_instance.msg', [@name]),
    'title' => Arcadia.text('main.d.confirm_delete_ext_instance.title', [@name]),
    'level' => 'question')=='yes')
    exit_query_event = Arcadia.process_event(ExitQueryEvent.new(self, 'can_exit'=>true))
    can_exit = exit_query_event.can_exit
  end
  clean_instance if can_exit
end

#duplicate(_name = nil, _dom = nil, _confirm_on_exit = true) ⇒ Object



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
# File 'lib/a-commons.rb', line 535

def duplicate(_name=nil, _dom=nil, _confirm_on_exit=true)
  _name = new_name if _name.nil?
  @confirm_on_exit = _confirm_on_exit
  #create conf properties
  Arcadia.conf_group_copy(@@main_instance[self.class].name, _name)
  if !_dom.nil?
    doms = Application.conf_array("#{_name}.frames")
    doms[0] = _dom
    Application.array_conf("#{_name}.frames", doms)
  end
  instance = clone(_name, _dom)
  #initialize
  Arcadia.process_event(InitializeEvent.new(Arcadia.instance), [instance])
  #add_to_conf_property("#{main_instance.name}.clones", _name)
  main_instance.add_to_conf_property("clones", _name)
  instance
end

#exist_name?(_name) ⇒ Boolean

Returns:

  • (Boolean)


526
527
528
529
530
531
532
533
# File 'lib/a-commons.rb', line 526

def exist_name?(_name)
  exist = false
  instances.each{|i|
    exist = exist || i.name == _name
    break if exist
  }
  exist
end

#frame(_n = 0, create_if_not_exist = true) ⇒ Object



442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/a-commons.rb', line 442

def frame(_n=0,create_if_not_exist=true)
  fr = super(_n, create_if_not_exist)
  if fr != nil && !@frame_initialize && fr.domain != nil && fr.domain != ArcadiaLayout::HIDDEN_DOMAIN
    @frame_initialize = true
    fr.hinner_frame.bind_append("Enter", proc{activate})
    if main_instance?
#        fr.root.add_state_button(
#        self.name,
#        'Duplicate',
#        proc{duplicate},
#        PLUS_EX_GIF,
#        'left')
#        activate(self, false)
    else
      fr.root.add_state_button(
      self.name,
      'Destroy',
      proc{deduplicate},
      MINUS_EX_GIF,
      'left')
      activate(self, false)
    end
  end
  fr 
end

#instance_indexObject



511
512
513
# File 'lib/a-commons.rb', line 511

def instance_index
  instances.index(self)
end

#instancesObject



507
508
509
# File 'lib/a-commons.rb', line 507

def instances
  @@instances[self.class]
end

#main_instanceObject



476
477
478
# File 'lib/a-commons.rb', line 476

def main_instance
  @@main_instance[self.class]
end

#main_instance?Boolean

Returns:

  • (Boolean)


480
481
482
# File 'lib/a-commons.rb', line 480

def main_instance?
  @@main_instance[self.class] == self
end

#new_nameObject



515
516
517
518
519
520
521
522
523
524
# File 'lib/a-commons.rb', line 515

def new_name
  #"#{main_instance.name}#{instances.length}"
  name = main_instance.name
  i=0
  while exist_name?(name) 
    i+=1
    name = "#{main_instance.name}#{i}"
  end
  name
end

#on_destroy_instance(_event) ⇒ Object



563
564
565
566
567
568
569
# File 'lib/a-commons.rb', line 563

def on_destroy_instance(_event)
  Arcadia.detach_listener(self)
  @arcadia.unregister(self)
#    @frames.each{|f| f.free }
  @frames.each_index{|i| destroy_frame(i)}
  @frames.clear
end