#include #include void run_test_dialog(gint max_len, gchar *orig_name); int main(int argc, char *argv[]) { gtk_init(&argc, &argv); run_test_dialog(-1, "filename.txt"); /* no maximum lenth, previous filename given */ run_test_dialog(25, "another filename"); /* maximum lenth and previous filename given */ run_test_dialog(25, NULL); /* maximum lenth but no previous filename given */ return 0; } void run_test_dialog(gint max_len, gchar *orig_name) { GtkWidget *dialog; gint response; XfceFilenameInput *filename_input; const gchar *filename; dialog = gtk_dialog_new_with_buttons ("Enter file name", NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, "Cancel", GTK_RESPONSE_CANCEL, "Submit", GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); gtk_window_set_default_size (GTK_WINDOW(dialog),250,-1); filename_input = g_object_new (XFCE_TYPE_FILENAME_INPUT,NULL); xfce_filename_input_set_max_length(filename_input,max_len); xfce_filename_input_set_original_filename(filename_input,orig_name); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),GTK_WIDGET(filename_input)); gtk_widget_show_all (GTK_WIDGET(filename_input)); g_signal_connect_swapped(filename_input,"text-invalid",G_CALLBACK(xfce_filename_input_desensitise_widget), gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog),GTK_RESPONSE_OK)); g_signal_connect_swapped(filename_input,"text-valid",G_CALLBACK(xfce_filename_input_sensitise_widget), gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog),GTK_RESPONSE_OK)); xfce_filename_input_check(filename_input); /* this call ensures that the "Submit" button has its sensitivity set correctly */ response = gtk_dialog_run (GTK_DIALOG (dialog)); filename = xfce_filename_input_get_text(filename_input); if (response == GTK_RESPONSE_OK) g_message("Filename: %s\n",filename); if (response == GTK_RESPONSE_CANCEL) g_message("Cancelled\n"); gtk_widget_destroy (dialog); }