

def show_game(id)
#puts " id: #{id}"
$console.send_command("review wantto_observe #{id}")
end

def cmd_menu(cmd,player)

case cmd
when "stats"
	$console.send_command("stats #{player}")
when "chat"
	 $chatobserver.new_chat(player) unless $chatobserver.nil?
when "match"
	GoMatch.new('match '+ player,player)
end
"" # called from tcl: must return a string
end

class Wlist
 attr_reader :not_opened, :list

 def initialize
    @not_opened= false

 open_win if Defaults.get_default_value('auto_start_Wlist').value == '1'
end

 def open_win
  if @top
      @top.deiconify
    else

  @top= GoWindow.new(self)
   @top.protocol('WM_DELETE_WINDOW', proc { close })

#  @top.help_add('command','label'=>'The reviews list','command'=>proc { TkHtml.new("file://#{$current_path}/../help/client.html#reviews") })


  tools= HTexturedPane.new(@top,Defaults::DEFS['CommonBackground'],10,5,4,0).pack('fill'=>'x')

	opts=TkDefaults::GUI['Console.button.players'].update('command'=>proc {$igsClient.send('user')   })
    b=TkButton.new(tools,opts)
    b.pack('side'=> 'left','padx'=>5,'pady'=>3)

	opts=TkDefaults::GUI['Console.button.games'].update('command'=>proc {$igsClient.send('games') })
    b=TkButton.new(tools,opts)
    b.pack('side'=> 'left','padx'=>5,'pady'=>3)

	opts=TkDefaults::GUI['Console.button.reviews'].update('command'=>proc {$igsClient.send('review games') })
    b=TkButton.new(tools,opts)
    b.pack('side'=> 'left','padx'=>5,'pady'=>3)

  @list= List.new(@top)
  
@current=''
 end	

     Defaults.set_default_value('auto_start_Wlist', '1')
	@list.show('User')
end

 def close
    if @top
      @top.withdraw 
    end
    @not_opened= true
     Defaults.set_default_value('auto_start_Wlist', '0')
  end

  def quit
    @top.destroy if @top
  end

def refresh
	return unless @list
	@list.refresh 
@current=''
end

def rec_review(toks)
	return unless @list
	if @current != 'Reviews'
		@list.show('Reviews')
		@current= 'Reviews'
	end
	id=toks[0]
	@list.add(toks.join(' '),"{$console.send_command('review wantto_observe #{id}')}")
end

def rec_game(line)
	return unless @list

	if @current != 'Games'
		@list.show('Games')
		@current= 'Games'
	end

  id,l=GameInfo.to_s(line)
if id
	@list.add(l,"{$console.send_command('observe #{id}')}")
end
end

#  ginga999  <None>          Japan     3k* 106/ 117  -   24   7s    Q- default"
#   cml1234  <none>          Taiwan    3k* 685/ 473  -   -   40s    -- default "
#USER=[0,12,28,38,42,52,56,62,67,70,77]

def rec_players(lines)
	return unless @list
	 line = lines.shift
		 @userinfos = []
		lines.each { |line|
			@userinfos.push( UserInfo.new(line)) if line[1..5] != 'guest'
			}
			
    @list.show('User')
	@current='User'
	return unless @list
	 return if @top.nil? or @not_opened
	@userinfos.sort.each {|uinf|
		@list.add(uinf.to_s,"#{uinf.name} match stats chat" )
 	}
	@list.refresh
end

end

class List

# wrapper class

def initialize( parent)
@parent=parent
$ip._eval("
	source #{$current_path}/tcl/list.tcl
	List::create #{parent.path} #{$current_path} #{Defaults::DEFS['IGSList_background'].path}
	")
end

def show(name)
	$ip._eval("List::clear
List::set_title #{@parent.path} {#{TkDefaults::Titlebar[name].join(' ')}} {#{TkDefaults::Titlesize[name].join(' ')}}")
end

def clear
	$ip._eval("List::clear")
end

def add(line,cmd)
	#$ip._eval("List::add {#{line.tr('^!-~',' ').tr('"\'{}[]',' ')}}")
	$ip._eval("List::add {#{line}} {#{cmd}}")
end

def refresh
	$ip._eval("List::refresh")
end
end


