$:.push( File::dirname($0) )

module ApRBBR

  @@msg = {}
  @@msg['name'] = 'Name'
  @@msg['value'] = 'Arity or Value'
  @@msg['public_methods'] = 'Public Instance Methods'
  @@msg['protected_methods'] = 'Protected Instance Methods' 
  @@msg['private_methods'] = 'Private Instance Methods'
  @@msg['singleton_methods'] = 'Singleton Methods'
  @@msg['contants'] = 'Constants'

  def self.Message
    @@msg
  end

end

require 'phi'
require 'phi-tree'
require 'browselist'

module ApRBBR

  class BrowseEdit < Phi::Edit

    def initialize(form, com_name)
      super(form, com_name)
#     self.align = Phi::AL_CLIENT
#     self.height = 23
      self.text = ''
      self.read_only = true
    end

    def update(modul)
      message = 
	if Class === modul
	  "class #{modul.name}"
	else # Module
	  "module #{modul.name}"
	end
      if Class === modul and Object != modul
	message << " < #{modul.superclass.name}"
      end
      included_modules_at = modul.included_modules_at
      unless included_modules_at.empty?
	message << "; include " << included_modules_at.join(", ")
      end
      self.text = message
    end

  end

  class MiNiBrowser < Phi::Form
    
    def initialize
      super
      msg = ApRBBR.Message
      self.caption = "MiNi Ruby Browser for Apollo"
      self.width = 600
      self.height = 500
      self.position = Phi::PO_SCREEN_CENTER

      page_control = Phi::PageControl.new(self, :page_control1)
      page_control.align = Phi::AL_CLIENT

      class_tab = Phi::TabSheet.new(page_control, :class_tab1, 'class')
      module_tab = Phi::TabSheet.new(page_control, :module_tab1, 'module')

      @class_index = ApRBBR::ClassTree.new(class_tab, :class_index1)
      class_splitter = Phi::Splitter.new(class_tab)
      class_splitter.align = Phi::AL_RIGHT
      class_splitter.align = Phi::AL_LEFT
      class_list = BrowseList.new(class_tab, :class_list1)

      @module_index = ApRBBR::ModuleTree.new(module_tab, :module_index1)
      module_splitter = Phi::Splitter.new(module_tab)
      #module_splitter.left = @module_index.width + 1
      #module_splitter.align = Phi::AL_RIGHT
      module_splitter.align = Phi::AL_LEFT
      module_list = BrowseList.new(module_tab, :module_list1)

      edit = BrowseEdit.new(self, :edit1)
      edit.align = Phi::AL_TOP

      # updateを実行させるオブジェクトの設定
      @class_index.add_observer(edit)
      @module_index.add_observer(edit)
      @class_index.add_observer(class_list)
      @module_index.add_observer(module_list)

      # 初めてモジュールタブがアクティブになったときに
      # ノードを付加する。
      module_tab.on_show = proc do 
	if @module_index.items.count == 0
	  @module_index.update
	  @module_index.width = @class_index.width
	  module_splitter.left = @module_index.left + @module_index.width + 1
	end
      end

    end

  end

  def self.main
    window = MiNiBrowser.new
    window.show
    Phi.mainloop
  end

end

if $0 == __FILE__
  ApRBBR.main
end

