Commit 9f0e2730 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: change filename in gimp_text_buffer_load() and _save() to GFile

parent 3687e1b3
......@@ -145,25 +145,25 @@ error_console_save_response (GtkWidget *dialog,
{
if (response_id == GTK_RESPONSE_OK)
{
GFile *file;
GError *error = NULL;
gchar *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
if (! gimp_text_buffer_save (GIMP_TEXT_BUFFER (console->text_buffer),
filename,
file,
console->save_selection, &error))
{
gimp_message (console->gimp, G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
_("Error writing file '%s':\n%s"),
gimp_filename_to_utf8 (filename),
gimp_file_get_utf8_name (file),
error->message);
g_clear_error (&error);
g_free (filename);
g_object_unref (file);
return;
}
g_free (filename);
g_object_unref (file);
}
gtk_widget_destroy (dialog);
......
......@@ -131,25 +131,25 @@ text_editor_load_response (GtkWidget *dialog,
if (response_id == GTK_RESPONSE_OK)
{
GtkTextBuffer *buffer;
gchar *filename;
GFile *file;
GError *error = NULL;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->view));
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->view));
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
if (! gimp_text_buffer_load (GIMP_TEXT_BUFFER (buffer), filename, &error))
if (! gimp_text_buffer_load (GIMP_TEXT_BUFFER (buffer), file, &error))
{
gimp_message (editor->ui_manager->gimp, G_OBJECT (dialog),
GIMP_MESSAGE_ERROR,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename),
gimp_file_get_utf8_name (file),
error->message);
g_clear_error (&error);
g_free (filename);
g_object_unref (file);
return;
}
g_free (filename);
g_object_unref (file);
}
gtk_widget_hide (dialog);
......
......@@ -1400,21 +1400,24 @@ gimp_text_buffer_get_iter_at_index (GimpTextBuffer *buffer,
gboolean
gimp_text_buffer_load (GimpTextBuffer *buffer,
const gchar *filename,
GFile *file,
GError **error)
{
FILE *file;
gchar *path;
FILE *f;
gchar buf[2048];
gint remaining = 0;
GtkTextIter iter;
g_return_val_if_fail (GIMP_IS_TEXT_BUFFER (buffer), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
file = g_fopen (filename, "r");
path = g_file_get_path (file);
f = g_fopen (path, "r");
g_free (file);
if (! file)
if (! f)
{
g_set_error_literal (error, G_FILE_ERROR,
g_file_error_from_errno (errno),
......@@ -1427,13 +1430,13 @@ gimp_text_buffer_load (GimpTextBuffer *buffer,
gimp_text_buffer_set_text (buffer, NULL);
gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (buffer), &iter);
while (! feof (file))
while (! feof (f))
{
const char *leftover;
gint count;
gint to_read = sizeof (buf) - remaining - 1;
count = fread (buf + remaining, 1, to_read, file);
count = fread (buf + remaining, 1, to_read, f);
buf[count + remaining] = '\0';
g_utf8_validate (buf, count + remaining, &leftover);
......@@ -1451,9 +1454,9 @@ gimp_text_buffer_load (GimpTextBuffer *buffer,
if (remaining)
g_message (_("Invalid UTF-8 data in file '%s'."),
gimp_filename_to_utf8 (filename));
gimp_file_get_utf8_name (file));
fclose (file);
fclose (f);
gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
......@@ -1462,20 +1465,23 @@ gimp_text_buffer_load (GimpTextBuffer *buffer,
gboolean
gimp_text_buffer_save (GimpTextBuffer *buffer,
const gchar *filename,
GFile *file,
gboolean selection_only,
GError **error)
{
GtkTextIter start_iter;
GtkTextIter end_iter;
gchar *path;
gint fd;
gchar *text_contents;
g_return_val_if_fail (GIMP_IS_TEXT_BUFFER (buffer), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
fd = g_open (filename, O_WRONLY | O_CREAT | O_APPEND, 0666);
path = g_file_get_path (file);
fd = g_open (path, O_WRONLY | O_CREAT | O_APPEND, 0666);
g_free (path);
if (fd == -1)
{
......
......@@ -156,10 +156,10 @@ void gimp_text_buffer_get_iter_at_index (GimpTextBuffer *buffer,
gboolean layout_index);
gboolean gimp_text_buffer_load (GimpTextBuffer *buffer,
const gchar *filename,
GFile *file,
GError **error);
gboolean gimp_text_buffer_save (GimpTextBuffer *buffer,
const gchar *filename,
GFile *file,
gboolean selection_only,
GError **error);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment