#!/usr/bin/wish -f
#
#   "ragmaan.tcl" - part of "RAGMAAN, een anagrammengenerator" 
#
#            Copyright (C) 1999 Raymond Zandbergen
#
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#    The maintainer of this program is Raymond Zandbergen (ray@wirehub.nl)
#

# ------------process command line args------------

foreach i $argv {

	if {$i == "-explicit_resources"} {
		option readfile [file join $env(RM_DB_PATH) ragmaan-defaults]
		set user_defaults [file join $env(HOME) .ragmaan-defaults]
		if {[file exists $user_defaults]} {
			catch { option readfile $user_defaults } 
		}
	} else {
		puts "parameter \"$i\" ignored"
	}
}
set version 1.0.3

# ------------load libs------------

source [file join $env(RM_LIB_PATH) gui.tcl]
source [file join $env(RM_LIB_PATH) glue.tcl]
source [file join $env(RM_LIB_PATH) info_panel.tcl]
source [file join $env(RM_LIB_PATH) view_gpl.tcl]
load $env(RM_LIB)
set server_pid  [rm_server_create $env(RM_SERVER)]
if {$server_pid == 0} {
	set status_text {De server kon niet worden gestart.}
	tk_dialog .dlg "Oeps" $status_text error "" OK
	exit
}

set database ""
set database [get_db_file_name]
write_db_file_name $database
set sort_results 0
set reverse_results 0

# ------------fill in GUI bindings------------

bind	.f_searchlist.lb <1> {
    if [winfo exists %W] {
	cmd_select_anagram [%W index @%x,%y]
    }
}

bind .f_searchlist.lb <3> {do_popup %X %Y}
.f_buttons.up configure -command cmd_up_tree
.f_search.b configure -command { cmd_search $user_entry }
.f_searchlist.lb configure -yscrollcommand {rm_expand_and_show}
.f_buttons.keep configure -command cmd_keep
bind .f_search.e <Return> { .f_search.b invoke }
bind .f_mask.e   <Return> { .f_mask.c deselect; .f_mask.c invoke }
set info_command { cmd_display_info [rm_server_status] "" }
set file_command { cmd_query_and_load_database }
set save_command { cmd_save_results }
set exit_command { cmd_exit_ragmaan }
set user_entry {test een twee drie vier}

# ------------load database------------

set status_text [list bezig met laden '[file tail $database]' ... ]
. configure -cursor "" 
update 
cmd_display_info "" 1
update 
rm_server_load $database

# ------------start application------------

set use_filter 0
set unsaved_changes 0
set save_file {geen_naam.txt}
trace variable unsaved_changes w { tr_unsaved_changes }
trace variable stack_depth w     { tr_stack_depth }
set unsaved_changes 0

# push the search button ...

.f_search.b invoke
destroy .info
