require 'tk'
class Commander
$numrows = 5
		
	def load()
		$status.text = "loading..."
		begin
			aFile = File.new("Commander.ini","r")
			puts aFile
			$numrows.times { |j| $texts[j].value = aFile.gets.strip }
			aFile.close()
		rescue SystemCallError
			$stderr.print "no Commander.ini to read."
		end
		$status.text = "ready."
	end
	def save()
		aFile = File.new("Commander.ini","w")
		$numrows.times { |j|
		   aFile.puts $texts[j].value
		   puts "saving"+$texts[j].value
		}
		aFile.close()
	end
	def doIt(num) 
		$status.text = "working..."
		print $entries[num].get
		print system($entries[num].get)
		$status.text = "ready."
	end
	def doGui()
		root = TkRoot.new { title "Commander" }
		top = TkFrame.new(root)
		#menus
		bar = TkMenu.new()
		file = TkMenu.new(bar)
		file.add('command', 'label'=>"Load", 'command'=>proc { load() })
		file.add('command', 'label'=>"Save", 'command'=>proc { save() })
		file.add('command', 'label'=>"Exit", 'command'=>proc { exit })
		bar.add('cascade', 'menu'=>file, 'label'=>"File")
		root.menu(bar)
		#buttons
		TkGrid.grid(top, "columnspan"=>2 )
		$texts = Array(1..$numrows)
		$entries = Array(1..$numrows)
		$buttons = Array(1..$numrows)
		$numrows.times { |i| 
			$row = i+1
			$texts[i] = TkVariable.new
			$texts[i].value = "dir"
			$entries[i] = TkEntry.new(top, 'textvariable' => $texts[i])
			$entries[i].width = 120
			$buttons[i] = TkButton.new(top) {text 'DoIt'; command { $commander.doIt(i) } }
			$buttons[i].grid("row"=>$row, "column"=>1)
			$entries[i].grid("row"=>$row, "column"=>2)
		}
		$status = TkLabel.new() { text "status:" }
		$status.grid("row"=>$row, "column"=>1, "columnspan"=>2)
	end #doGui
end #class
$commander = Commander.new
$commander.doGui
$commander.load

Tk.mainloop


