29a30 > #include 336,338c337,347 < /* Ought to use filename+extension here */ < gtk_entry_set_text(GTK_ENTRY(ofile), "output.ps"); < persistence_register_string_entry("printer-file", ofile); --- > > /* Work out diagram filename and use this as default .ps file */ > char *filename = g_path_get_basename(dia->filename); > char *printer_filename = g_malloc(strlen(filename) + 4); > printer_filename = strcpy(printer_filename, filename); > char *dot = strrchr(printer_filename, '.'); > if ((dot != NULL) && (strcmp(dot, ".dia") == 0)) > *dot = '\0'; > printer_filename = strcat(printer_filename, ".ps"); > gtk_entry_set_text(GTK_ENTRY(ofile), printer_filename); > g_free(printer_filename); 346,351c355,365 < gtk_main(); < < if(!dia) { < gtk_widget_destroy(dialog); < return; < } --- > gboolean done = FALSE; > gboolean write_file = TRUE; /* Used in prompt to overwrite existing file */ > do { > cont = FALSE; > write_file = TRUE; > gtk_main(); > > if(!dia) { > gtk_widget_destroy(dialog); > return; > } 353,360c367,373 < if (!cont) { < persistence_change_string_entry("printer-command", orig_command, cmd); < persistence_change_string_entry("printer-file", orig_file, ofile); < gtk_widget_destroy(dialog); < g_free(orig_command); < g_free(orig_file); < return; < } --- > if (!cont) { > persistence_change_string_entry("printer-command", orig_command, cmd); > gtk_widget_destroy(dialog); > g_free(orig_command); > g_free(orig_file); > return; > } 362,363c375,376 < if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(iscmd))) { < printcmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(cmd))); --- > if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(iscmd))) { > printcmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(cmd))); 365c378 < file = win32_printer_open (printcmd); --- > file = win32_printer_open (printcmd); 367c380 < file = popen(printcmd, "w"); --- > file = popen(printcmd, "w"); 369,380c382 < is_pipe = TRUE; < } else { < const gchar *filename = gtk_entry_get_text(GTK_ENTRY(ofile)); < if (!g_path_is_absolute(filename)) { < char *dirname; < char *full_filename; < < dirname = g_path_get_dirname(dia->filename); < full_filename = g_build_filename(dirname, filename, NULL); < file = fopen(full_filename, "w"); < g_free(full_filename); < g_free(dirname); --- > is_pipe = TRUE; 382c384,439 < file = fopen(filename, "w"); --- > const gchar *filename = gtk_entry_get_text(GTK_ENTRY(ofile)); > struct stat statbuf; > > if (stat(filename, &statbuf) == 0) { /* Output file exists */ > GtkWidget *confirm_overwrite_dialog = NULL; > char buffer[300]; > char *utf8filename = NULL; > > if (!g_utf8_validate(filename, -1, NULL)) { > utf8filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); > > if (utf8filename == NULL) { > message_warning(_("Some characters in the filename are neither " > "UTF-8\nnor your local encoding.\nSome things will break.")); > } > } > > if (utf8filename == NULL) utf8filename = g_strdup(filename); > g_snprintf(buffer, 300, > _("The file '%s' already exists.\n" > "Do you want to overwrite it?"), utf8filename); > g_free(utf8filename); > confirm_overwrite_dialog = gtk_message_dialog_new(GTK_WINDOW (dialog), > GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, > GTK_BUTTONS_YES_NO, > buffer); > gtk_window_set_title(GTK_WINDOW (confirm_overwrite_dialog), > _("File already exists")); > gtk_dialog_set_default_response (GTK_DIALOG (confirm_overwrite_dialog), > GTK_RESPONSE_NO); > > if (gtk_dialog_run(GTK_DIALOG(confirm_overwrite_dialog)) > != GTK_RESPONSE_YES) { > write_file = FALSE; > file = 0; > } > > gtk_widget_destroy(confirm_overwrite_dialog); > } > > if (write_file) { > if (!g_path_is_absolute(filename)) { > char *dirname; > char *full_filename; > > dirname = g_path_get_dirname(dia->filename); > full_filename = g_build_filename(dirname, filename, NULL); > file = fopen(full_filename, "w"); > g_free(full_filename); > g_free(dirname); > } else { > file = fopen(filename, "w"); > } > } > > is_pipe = FALSE; 384,385d440 < is_pipe = FALSE; < } 387,390c442,443 < /* Store dialog values */ < g_free(orig_command); < g_free(orig_file); < last_print_options.printer = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(iscmd)); --- > /* Store dialog values */ > last_print_options.printer = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(iscmd)); 392,397c445,451 < if (!file) { < if (is_pipe) { < message_warning(_("Could not run command '%s': %s"), printcmd, strerror(errno)); < g_free(printcmd); < } else < message_warning(_("Could not open '%s' for writing: %s"), --- > if (write_file) { > if (!file) { > if (is_pipe) { > message_warning(_("Could not run command '%s': %s"), printcmd, strerror(errno)); > g_free(printcmd); > } else > message_warning(_("Could not open '%s' for writing: %s"), 399,401c453,456 < gtk_widget_destroy(dialog); < return; < } --- > } else > done = TRUE; > } > } while(!done); 402a458,459 > g_free(orig_command); > g_free(orig_file);