Skip to content

Instantly share code, notes, and snippets.

@kion-dgl
Created December 12, 2017 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kion-dgl/14b9824072085acd65ef71f567aef3da to your computer and use it in GitHub Desktop.
Save kion-dgl/14b9824072085acd65ef71f567aef3da to your computer and use it in GitHub Desktop.
Setting default name of an image using the GTK file chooser
static void open_export(GApplication *app, gpointer user_data) {
GtkWidget *dialog;
gint res;
dialog = gtk_file_chooser_dialog_new (
"Save Texture (.png)",
GTK_WINDOW(user_data),
GTK_FILE_CHOOSER_ACTION_SAVE,
"Cancel",
GTK_RESPONSE_CANCEL,
"Save",
GTK_RESPONSE_ACCEPT,
NULL
);
// Problem start: filename and folder are not set
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER(dialog), TRUE);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), "~/Pictures");
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(dialog), "texture.png");
res = gtk_dialog_run (GTK_DIALOG (dialog));
// Problem end
if(res == GTK_RESPONSE_ACCEPT) {
char *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog));
g_print("The user selected filename: %s\n", filename);
g_free (filename);
}
gtk_widget_destroy (dialog);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment