# Purpose: Setup and initialize the core gui interfaces for the Dock panels
#
# $Id: outputpane.rb,v 1.1.1.1 2002/12/20 17:27:31 richkilmer Exp $
#
# Authors:  Laurent Julliard <laurent AT moldus DOT org>
# Contributors:
#
# This file is part of the FreeRIDE project
#
# This application is free software; you can redistribute it and/or
# modify it under the terms of the Ruby license defined in the
# COPYING file.
#
# Copyright (c) 200 Laurent Julliard. All rights reserved.
#

require 'rubyide_gui/component_manager'
require 'rubyide_gui/component'

module FreeRIDE
  module GUI

    ##
    # This is the manager class for dockpane components.
    #
    class OutputPane < Component
      extend FreeBASE::StandardPlugin
      
      def self.start(plugin)
        base_slot = plugin["/system/ui/components/OutputPane"]
        ComponentManager.new(plugin, base_slot, OutputPane, 1)
        output = base_slot.manager.add
        plugin['/system/ui/current'].link("OutputPane", output)
        
        viewmenu = plugin["/system/ui/components/MenuPane/View_menu"].manager
        viewmenu.add_command("App/View/Output")
        viewmenu.uncheck("App/View/Output")
        
        plugin["/system/state/all_plugins_loaded"].subscribe do |event, slot|
          if slot.data == true
            if plugin.properties["Open"]
              output.manager.toggle
            end
          end
        end
        
        plugin.transition(FreeBASE::RUNNING)
      end
      
      def initialize(plugin, base_slot)
        setup(plugin, base_slot, nil)
        @viewmenu = plugin["/system/ui/components/MenuPane/View_menu"].manager
        @shown = false
      end
      
      def show
        return if @shown
        @actions['show'].invoke
        @viewmenu.check("App/View/Output")
        @plugin.properties["Open"] = true
        @shown = true
      end
      
      def hide
        return unless @shown
        @actions['hide'].invoke
        @viewmenu.uncheck("App/View/Output")
        @plugin.properties["Open"] = false
        @shown = false
      end
      
      def set(name, text)
        @actions['set'].invoke(name, text)
      end
      
      def append(name, text)
        @actions['append'].invoke(name, text)
      end
      
      def clear(name)
        @actions['clear'].invoke(name)
      end
      
      def toggle
        if @shown
          hide
        else
          show
        end
      end
      
    end
    
  end
end
