error-console-commands.c 6.36 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20
#include <gegl.h>
21 22
#include <gtk/gtk.h>

23
#include "libgimpbase/gimpbase.h"
24 25
#include "libgimpwidgets/gimpwidgets.h"

Michael Natterer's avatar
Michael Natterer committed
26
#include "actions-types.h"
27

28 29
#include "core/gimp.h"

30
#include "widgets/gimperrorconsole.h"
31
#include "widgets/gimphelp-ids.h"
32
#include "widgets/gimptextbuffer.h"
33 34 35

#include "error-console-commands.h"

36 37 38 39 40 41 42 43 44
#include "gimp-intl.h"


/*  local function prototypes  */

static void   error_console_save_response (GtkWidget        *dialog,
                                           gint              response_id,
                                           GimpErrorConsole *console);

45 46 47 48

/*  public functions  */

void
49
error_console_clear_cmd_callback (GtkAction *action,
50
                                  gpointer   data)
51 52
{
  GimpErrorConsole *console = GIMP_ERROR_CONSOLE (data);
53 54
  GtkTextIter       start_iter;
  GtkTextIter       end_iter;
55

56 57
  gtk_text_buffer_get_bounds (console->text_buffer, &start_iter, &end_iter);
  gtk_text_buffer_delete (console->text_buffer, &start_iter, &end_iter);
58 59
}

60 61 62 63 64 65 66 67 68 69 70 71
void
error_console_select_all_cmd_callback (GtkAction *action,
                                       gpointer   data)
{
  GimpErrorConsole *console = GIMP_ERROR_CONSOLE (data);
  GtkTextIter       start_iter;
  GtkTextIter       end_iter;

  gtk_text_buffer_get_bounds (console->text_buffer, &start_iter, &end_iter);
  gtk_text_buffer_select_range (console->text_buffer, &start_iter, &end_iter);
}

72
void
73 74 75
error_console_save_cmd_callback (GtkAction *action,
                                 gint       value,
                                 gpointer   data)
76 77
{
  GimpErrorConsole *console = GIMP_ERROR_CONSOLE (data);
78 79 80 81

  if (value && ! gtk_text_buffer_get_selection_bounds (console->text_buffer,
                                                       NULL, NULL))
    {
82
      gimp_message_literal (console->gimp,
83 84
                            G_OBJECT (console), GIMP_MESSAGE_WARNING,
                            _("Cannot save. Nothing is selected."));
85 86 87
      return;
    }

88
  if (! console->file_dialog)
89
    {
90
      GtkWidget *dialog;
91

92 93 94
      dialog = console->file_dialog =
        gtk_file_chooser_dialog_new (_("Save Error Log to File"), NULL,
                                     GTK_FILE_CHOOSER_ACTION_SAVE,
95

96 97
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                                     _("_Save"),   GTK_RESPONSE_OK,
98

99
                                     NULL);
100

101
      gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
102
      gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
103 104 105
                                               GTK_RESPONSE_OK,
                                               GTK_RESPONSE_CANCEL,
                                               -1);
106

107
      console->save_selection = value;
108

109 110
      g_object_add_weak_pointer (G_OBJECT (dialog),
                                 (gpointer) &console->file_dialog);
111

112 113 114 115
      gtk_window_set_screen (GTK_WINDOW (dialog),
                             gtk_widget_get_screen (GTK_WIDGET (console)));
      gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
      gtk_window_set_role (GTK_WINDOW (dialog), "gimp-save-errors");
116

117 118
      gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
                                                      TRUE);
119

120 121 122 123 124 125
      g_signal_connect (dialog, "response",
                        G_CALLBACK (error_console_save_response),
                        console);
      g_signal_connect (dialog, "delete-event",
                        G_CALLBACK (gtk_true),
                        NULL);
126

127 128 129
      gimp_help_connect (dialog, gimp_standard_help_func,
                         GIMP_HELP_ERRORS_DIALOG, NULL);
    }
130

131
  gtk_window_present (GTK_WINDOW (console->file_dialog));
132 133
}

134 135 136 137 138 139 140 141 142
void
error_console_highlight_error_cmd_callback (GtkAction *action,
                                            gpointer   data)
{
  GimpErrorConsole *console = GIMP_ERROR_CONSOLE (data);
  gboolean          active;

  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

143
  console->highlight[GIMP_MESSAGE_ERROR] = active;
144 145 146 147 148 149 150 151 152 153 154
}

void
error_console_highlight_warning_cmd_callback (GtkAction *action,
                                              gpointer   data)
{
  GimpErrorConsole *console = GIMP_ERROR_CONSOLE (data);
  gboolean          active;

  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

155
  console->highlight[GIMP_MESSAGE_WARNING] = active;
156 157 158 159 160 161 162 163 164 165 166
}

void
error_console_highlight_info_cmd_callback (GtkAction *action,
                                           gpointer   data)
{
  GimpErrorConsole *console = GIMP_ERROR_CONSOLE (data);
  gboolean          active;

  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

167
  console->highlight[GIMP_MESSAGE_INFO] = active;
168 169
}

170 171 172 173 174 175 176

/*  private functions  */

static void
error_console_save_response (GtkWidget        *dialog,
                             gint              response_id,
                             GimpErrorConsole *console)
177
{
178 179
  if (response_id == GTK_RESPONSE_OK)
    {
180
      GFile  *file  = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
181 182
      GError *error = NULL;

183
      if (! gimp_text_buffer_save (GIMP_TEXT_BUFFER (console->text_buffer),
184
                                   file,
185 186
                                   console->save_selection, &error))
        {
187 188
          gimp_message (console->gimp, G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
                        _("Error writing file '%s':\n%s"),
189
                        gimp_file_get_utf8_name (file),
190
                        error->message);
191
          g_clear_error (&error);
192
          g_object_unref (file);
193 194 195
          return;
        }

196
      g_object_unref (file);
197
    }
198

199
  gtk_widget_destroy (dialog);
200
}