#include ONCE "window9.bi"

function SaveFileRequester(sTitle as string , sCurDir as string, sPattern as string = "All files (*.*)"+Chr(0)+"*.*"+Chr(0), iDefaultSetPattern as Long = 0, sTemplateFileName as string = "",  hParentWin as HWND = 0) as string export
	
	dim as GtkWidget ptr dialog
	
	dim as GtkFileChooser ptr chooser
	
	dim as Long iAction = GTK_FILE_CHOOSER_ACTION_SAVE
	
	dim as gint res
	
	dialog = gtk_file_chooser_dialog_new(sTitle, cast(any ptr, hParentWin) , iAction, "Cancel",_
	GTK_RESPONSE_CANCEL, "Save", GTK_RESPONSE_ACCEPT, NULL)
	
	chooser = GTK_FILE_CHOOSER(dialog)
	
	gtk_file_chooser_set_do_overwrite_confirmation (chooser, 1)
	
	if sCurDir <> "" then
		
		gtk_file_chooser_set_current_folder(chooser , sCurDir)
		
	EndIf
	
	if sTemplateFileName <> "" then
	
		gtk_file_chooser_set_current_name(chooser , sTemplateFileName)

	EndIf								   
	
	SetFilterRequester( sPattern , chooser)
	
	res = gtk_dialog_run(GTK_DIALOG(dialog))
	
	if res = GTK_RESPONSE_ACCEPT then	
		
		dim as zstring ptr psRet = gtk_file_chooser_get_filename (chooser)
		
		dim as string sRet = *psRet
		
		g_free (psRet)	
		
		gtk_widget_destroy(dialog)
		
		return sRet
		
	EndIf
	
	gtk_widget_destroy(dialog)
	
End Function