/* folderChooserButton.c */

#include "gnocl.h"
#include <string.h>
#include <assert.h>

static GnoclOption buttonOptions[] =
{
	{ "-directory", GNOCL_OBJ, NULL },        /* 0 */
	{ "-fileTypes", GNOCL_OBJ, NULL },        /* 1 */
};


static int configure( Tcl_Interp *interp, GtkWidget *button, GnoclOption options[] )
{
	/* set the location to the user's home director */
	gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(button), g_get_home_dir() ) ;

	printf( "Element 0 contains %s\n", options[0]);
	printf( "Element 0 contains %s\n", options[1]);

	return TCL_OK;
}

static int cget( Tcl_Interp *interp, GtkButton *button, GnoclOption options[], int idx )
{
	return TCL_OK;
}


/* a function to manage changes and events occuring to the widget during runtime */
static int buttonFunc( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{
	return TCL_OK;
}


int gnoclFolderChooserButtonCmd( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{
	int       ret;
	GtkWidget *button;

	/* create and show the button */
	button = gtk_file_chooser_button_new("Choose a folder", GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
	gtk_widget_show( GTK_WIDGET( button ) );




	/* intitalise options, and clear memory when done, return error initialisation fails */
	ret = gnoclSetOptions( interp, buttonOptions, G_OBJECT( button ), -1 );
	if( ret == TCL_OK ) {
		ret = configure( interp, button, buttonOptions );
		}
	gnoclClearOptions( buttonOptions );

	if( ret != TCL_OK ) {
		gtk_widget_destroy( GTK_WIDGET( button ) );
		return TCL_ERROR;
		}

	/* register the new widget for use with the Tcl interpretor */
	return gnoclRegisterWidget( interp, GTK_WIDGET( button ), buttonFunc );
}

