[Glade-users] Save As
- From: john at jcoppens.com (John Coppens)
- Subject: [Glade-users] Save As
- Date: Wed, 21 Jun 2006 15:48:23 -0300
On Wed, 21 Jun 2006 14:18:43 -0400
"Kevin Hobby" <khobby at gmail.com> wrote:
John would you write out an example of what you mean using my code?
Here's an example from a program I'm doing:
void
save_file_as_activate(void)
{
if (!run_filedialog("Save source file", &pref.lastfn, "*.pfc"))
return;
printf("Save file as: %s\n", pref.lastfn);
src_bff_save_file(pref.lastfn);
}
This function is called from the 'Save as...' item in the menu-bar or
from a button, as you wish.
gboolean
run_filedialog(char *title, char **fn, char *filter)
{
GtkWidget *fs = gtk_file_selection_new(title);
GtkWidget *selbtn = GTK_FILE_SELECTION(fs)->ok_button;
const char *p;
int result;
if (*fn)
gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs), *fn);
gtk_window_set_modal(GTK_WINDOW(fs), TRUE);
result = gtk_dialog_run(GTK_DIALOG(fs));
if (result == GTK_RESPONSE_OK) {
p = gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs));
*fn = realloc(*fn, strlen(p)+1);
strcpy(*fn, p);
} else
fn = NULL;
gtk_widget_destroy(fs);
}
This is the function that does the dirty work of showing the file dialog,
running it, and destroying it. Note that the 'filter' parameter doesn't
work.
John
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]