text-tool-commands.c 6.28 KB
Newer Older
1 2 3
/* GIMP - The GNU Image Manipulation Program
 * 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 23 24 25 26 27
#include <gtk/gtk.h>

#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"

#include "actions-types.h"

28
#include "core/gimp.h"
Sven Neumann's avatar
Sven Neumann committed
29
#include "core/gimptoolinfo.h"
30 31

#include "widgets/gimphelp-ids.h"
32
#include "widgets/gimptextbuffer.h"
33 34 35
#include "widgets/gimpuimanager.h"
#include "widgets/gimpwidgets-utils.h"

Sven Neumann's avatar
Sven Neumann committed
36 37
#include "display/gimpdisplay.h"

38 39
#include "tools/gimptexttool.h"

40 41
#include "dialogs/dialogs.h"

42 43 44 45 46 47 48
#include "text-tool-commands.h"

#include "gimp-intl.h"


/*  local function prototypes  */

49 50 51
static void   text_tool_load_dialog_response (GtkWidget    *dialog,
                                              gint          response_id,
                                              GimpTextTool *tool);
52 53 54 55 56 57 58 59 60 61


/*  public functions  */

void
text_tool_cut_cmd_callback (GtkAction *action,
                            gpointer   data)
{
  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data);

62
  gimp_text_tool_cut_clipboard (text_tool);
63 64 65 66 67 68 69 70
}

void
text_tool_copy_cmd_callback (GtkAction *action,
                             gpointer   data)
{
  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data);

71
  gimp_text_tool_copy_clipboard (text_tool);
72 73 74 75 76 77 78 79
}

void
text_tool_paste_cmd_callback (GtkAction *action,
                              gpointer   data)
{
  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data);

80
  gimp_text_tool_paste_clipboard (text_tool);
81 82 83 84 85 86 87 88
}

void
text_tool_delete_cmd_callback (GtkAction *action,
                               gpointer   data)
{
  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data);

89
  gimp_text_tool_delete_selection (text_tool);
90 91 92 93 94 95
}

void
text_tool_load_cmd_callback (GtkAction *action,
                             gpointer   data)
{
96 97
  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data);
  GtkWidget    *dialog;
98

99
  dialog = dialogs_get_dialog (G_OBJECT (text_tool), "gimp-text-file-dialog");
Sven Neumann's avatar
Sven Neumann committed
100

101
  if (! dialog)
102
    {
103
      GtkWidget *parent = NULL;
104

105 106 107
      if (GIMP_TOOL (text_tool)->display)
        {
          GimpDisplayShell *shell;
Sven Neumann's avatar
Sven Neumann committed
108

109
          shell = gimp_display_get_shell (GIMP_TOOL (text_tool)->display);
110

111 112
          parent = gtk_widget_get_toplevel (GTK_WIDGET (shell));
        }
113

114 115 116
      dialog = gtk_file_chooser_dialog_new (_("Open Text File (UTF-8)"),
                                            parent ? GTK_WINDOW (parent) : NULL,
                                            GTK_FILE_CHOOSER_ACTION_OPEN,
117

118 119
                                            _("_Cancel"), GTK_RESPONSE_CANCEL,
                                            _("_Open"),   GTK_RESPONSE_OK,
120

121
                                            NULL);
122

123
      gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
124
      gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
125 126 127
                                               GTK_RESPONSE_OK,
                                               GTK_RESPONSE_CANCEL,
                                               -1);
128

129 130
      gtk_window_set_role (GTK_WINDOW (dialog), "gimp-text-load-file");
      gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
131

132 133 134 135 136 137
      g_signal_connect (dialog, "response",
                        G_CALLBACK (text_tool_load_dialog_response),
                        text_tool);
      g_signal_connect (dialog, "delete-event",
                        G_CALLBACK (gtk_true),
                        NULL);
138

139 140 141
      dialogs_attach_dialog (G_OBJECT (text_tool),
                             "gimp-text-file-dialog", dialog);
    }
142

143
  gtk_window_present (GTK_WINDOW (dialog));
144 145 146 147 148 149
}

void
text_tool_clear_cmd_callback (GtkAction *action,
                              gpointer   data)
{
150
  GimpTextTool  *text_tool = GIMP_TEXT_TOOL (data);
151
  GtkTextBuffer *buffer    = GTK_TEXT_BUFFER (text_tool->buffer);
152
  GtkTextIter    start, end;
153

154 155
  gtk_text_buffer_get_bounds (buffer, &start, &end);
  gtk_text_buffer_select_range (buffer, &start, &end);
156
  gimp_text_tool_delete_selection (text_tool);
157 158 159
}

void
160 161
text_tool_text_to_path_cmd_callback (GtkAction *action,
                                     gpointer   data)
162 163 164 165 166 167
{
  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data);

  gimp_text_tool_create_vectors (text_tool);
}

168 169 170 171 172 173 174 175 176
void
text_tool_text_along_path_cmd_callback (GtkAction *action,
                                        gpointer   data)
{
  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data);

  gimp_text_tool_create_vectors_warped (text_tool);
}

177 178 179 180 181
void
text_tool_direction_cmd_callback (GtkAction *action,
                                  GtkAction *current,
                                  gpointer   data)
{
Sven Neumann's avatar
Sven Neumann committed
182 183
  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data);
  gint          value;
184 185 186

  value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));

Sven Neumann's avatar
Sven Neumann committed
187
  g_object_set (text_tool->proxy,
Jehan's avatar
Jehan committed
188 189
                "base-direction", (GimpTextDirection) value,
                NULL);
190 191 192 193 194
}


/*  private functions  */

Sven Neumann's avatar
Sven Neumann committed
195 196
static void
text_tool_load_dialog_response (GtkWidget    *dialog,
Jehan's avatar
Jehan committed
197 198
                                gint          response_id,
                                GimpTextTool *tool)
199 200 201
{
  if (response_id == GTK_RESPONSE_OK)
    {
202
      GFile  *file  = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
203
      GError *error = NULL;
204

205
      if (! gimp_text_buffer_load (tool->buffer, file, &error))
206
        {
Sven Neumann's avatar
Sven Neumann committed
207
          gimp_message (GIMP_TOOL (tool)->tool_info->gimp, G_OBJECT (dialog),
208 209
                        GIMP_MESSAGE_ERROR,
                        _("Could not open '%s' for reading: %s"),
210
                        gimp_file_get_utf8_name (file),
211 212
                        error->message);
          g_clear_error (&error);
213
          g_object_unref (file);
214 215 216
          return;
        }

217
      g_object_unref (file);
218 219
    }

Sven Neumann's avatar
Sven Neumann committed
220
  gtk_widget_hide (dialog);
221
}