/* Finish up the user's Release command by choosing a location to store the project. This is a callback and the GDK lock is held when entering this function. */ void i7_story_save_compiler_output(I7Story *story, const gchar *dialog_title) { I7_STORY_USE_PRIVATE(story, priv); GFile *file = NULL; if(priv->copy_blorb_dest_file == NULL) { /* ask the user for a release file name if cBlorb didn't provide one */ /* Create a file chooser */ GtkFileFilter *filter = gtk_file_filter_new(); if(i7_story_get_story_format(story) == I7_STORY_FORMAT_GLULX) { gtk_file_filter_set_name(filter, _("Glulx games (.ulx,.gblorb)")); gtk_file_filter_add_pattern(filter, "*.ulx"); gtk_file_filter_add_pattern(filter, "*.gblorb"); } else { gtk_file_filter_set_name(filter, _("Z-code games (.z?,.zblorb)")); gtk_file_filter_add_pattern(filter, "*.z?"); gtk_file_filter_add_pattern(filter, "*.zblorb"); } GtkWidget *dialog = gtk_file_chooser_dialog_new(dialog_title, GTK_WINDOW(story), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); char *curfilename = g_file_get_basename(priv->compiler_output_file); gchar *title = i7_document_get_display_name(I7_DOCUMENT(story)); char *extension = strrchr(curfilename, '.'); /* not allocated */ char *suggestname; if(title != NULL) { *(strrchr(title, '.')) = '\0'; suggestname = g_strconcat(title, extension, NULL); g_free(title); } else { suggestname = g_strconcat("Untitled", extension, NULL); } g_free(curfilename); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), suggestname); g_free(suggestname); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog)); gtk_widget_destroy(dialog); } else { file = g_object_ref(priv->copy_blorb_dest_file); } if(file) { /* Move the finished file to the release location */ GError *err = NULL; if(!g_file_move(priv->compiler_output_file, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &err)) { IO_ERROR_DIALOG(GTK_WINDOW(story), file, err, _("copying compiler output")); } g_object_unref(file); } }
static void location_data_func(GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, I7SearchWindow *self) { I7_SEARCH_WINDOW_USE_PRIVATE(self, priv); I7ResultType type; guint lineno; GFile *file; char *text = NULL, *filename, *location; gtk_tree_model_get(model, iter, I7_RESULT_RESULT_TYPE_COLUMN, &type, I7_RESULT_LINE_NUMBER_COLUMN, &lineno, I7_RESULT_FILE_COLUMN, &file, I7_RESULT_LOCATION_COLUMN, &location, -1); switch(type) { case I7_RESULT_TYPE_PROJECT: if(I7_IS_STORY(priv->document)) text = g_strdup_printf(_("Story, line %d"), lineno); else { gchar *displayname = i7_document_get_display_name(priv->document); if(displayname == NULL) { text = g_strdup_printf(_("Untitled story, line %d"), lineno); } else { text = g_strdup_printf(_("%s, line %d"), displayname, lineno); g_free(displayname); } } break; case I7_RESULT_TYPE_EXTENSION: { /* Get the file's display name */ filename = file_get_display_name(file); text = g_strdup_printf( /* TRANSLATORS: EXTENSION_NAME, line NUMBER */ _("%s, line %d"), filename, lineno); g_free(filename); } break; case I7_RESULT_TYPE_DOCUMENTATION: case I7_RESULT_TYPE_RECIPE_BOOK: text = g_strdup(location); default: ; } g_object_set(cell, "text", text, NULL); g_object_unref(file); g_free(text); }
/* Finish up the user's Export iFiction Record command. This is a callback and the GDK lock is held when entering this function. */ void i7_story_save_ifiction(I7Story *story) { /* Work out where the file should be */ GFile *project_file = i7_document_get_file(I7_DOCUMENT(story)); if(project_file == NULL) { g_warning("Tried to save iFiction record of story without associated file"); return; /* This shouldn't happen because the file is saved before compilation */ } GFile *ifiction_file = g_file_get_child(project_file, "Metadata.iFiction"); /* Prompt user to save iFiction file if it exists */ if(g_file_query_exists(ifiction_file, NULL)) { /* Make a file filter */ GtkFileFilter *filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, _("iFiction records (.iFiction)")); gtk_file_filter_add_pattern(filter, "*.iFiction"); /* Make up a default file name */ gchar *name = i7_document_get_display_name(I7_DOCUMENT(story)); /* project_file is not NULL so neither is name */ *(strrchr(name, '.')) = '\0'; gchar *filename = g_strconcat(name, ".iFiction", NULL); g_free(name); /* Create a file chooser */ GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Save iFiction record"), GTK_WINDOW(story), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename); g_free(filename); GFile *parent_file = g_file_get_parent(project_file); /* Ignore error */ gtk_file_chooser_set_current_folder_file(GTK_FILE_CHOOSER(dialog), parent_file, NULL); g_object_unref(parent_file); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); /* Copy the finished file to the chosen location */ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { GFile *dest_file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog)); GError *error = NULL; if(!g_file_copy(ifiction_file, dest_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error)) { IO_ERROR_DIALOG(GTK_WINDOW(story), dest_file, error, _("copying iFiction record")); } g_object_unref(dest_file); } gtk_widget_destroy(dialog); } else error_dialog(GTK_WINDOW(story), NULL, _("The compiler failed to create an iFiction record; check the " "results page to see why.")); g_object_unref(ifiction_file); g_object_unref(project_file); }