1 /*
2  * gedit-commands-edit.c
3  * This file is part of gedit
4  *
5  * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
6  * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
7  * Copyright (C) 2002-2005 Paolo Maggi
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "config.h"
24 
25 #include "gedit-commands.h"
26 #include "gedit-commands-private.h"
27 
28 #include <gtk/gtk.h>
29 
30 #include "gedit-window.h"
31 #include "gedit-debug.h"
32 #include "gedit-view.h"
33 #include "gedit-preferences-dialog.h"
34 
35 void
_gedit_cmd_edit_undo(GSimpleAction * action,GVariant * parameter,gpointer user_data)36 _gedit_cmd_edit_undo (GSimpleAction *action,
37                       GVariant      *parameter,
38                       gpointer       user_data)
39 {
40 	GeditWindow *window = GEDIT_WINDOW (user_data);
41 	GeditView *active_view;
42 	GtkSourceBuffer *active_document;
43 
44 	gedit_debug (DEBUG_COMMANDS);
45 
46 	active_view = gedit_window_get_active_view (window);
47 	g_return_if_fail (active_view != NULL);
48 
49 	active_document = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
50 
51 	gtk_source_buffer_undo (active_document);
52 
53 	tepl_view_scroll_to_cursor (TEPL_VIEW (active_view));
54 
55 	gtk_widget_grab_focus (GTK_WIDGET (active_view));
56 }
57 
58 void
_gedit_cmd_edit_redo(GSimpleAction * action,GVariant * parameter,gpointer user_data)59 _gedit_cmd_edit_redo (GSimpleAction *action,
60                       GVariant      *parameter,
61                       gpointer       user_data)
62 {
63 	GeditWindow *window = GEDIT_WINDOW (user_data);
64 	GeditView *active_view;
65 	GtkSourceBuffer *active_document;
66 
67 	gedit_debug (DEBUG_COMMANDS);
68 
69 	active_view = gedit_window_get_active_view (window);
70 	g_return_if_fail (active_view != NULL);
71 
72 	active_document = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
73 
74 	gtk_source_buffer_redo (active_document);
75 
76 	tepl_view_scroll_to_cursor (TEPL_VIEW (active_view));
77 
78 	gtk_widget_grab_focus (GTK_WIDGET (active_view));
79 }
80 
81 void
_gedit_cmd_edit_cut(GSimpleAction * action,GVariant * parameter,gpointer user_data)82 _gedit_cmd_edit_cut (GSimpleAction *action,
83                      GVariant      *parameter,
84                      gpointer       user_data)
85 {
86 	GeditWindow *window = GEDIT_WINDOW (user_data);
87 	GeditView *active_view;
88 
89 	gedit_debug (DEBUG_COMMANDS);
90 
91 	active_view = gedit_window_get_active_view (window);
92 	g_return_if_fail (active_view != NULL);
93 
94 	tepl_view_cut_clipboard (TEPL_VIEW (active_view));
95 
96 	gtk_widget_grab_focus (GTK_WIDGET (active_view));
97 }
98 
99 void
_gedit_cmd_edit_copy(GSimpleAction * action,GVariant * parameter,gpointer user_data)100 _gedit_cmd_edit_copy (GSimpleAction *action,
101                       GVariant      *parameter,
102                       gpointer       user_data)
103 {
104 	GeditWindow *window = GEDIT_WINDOW (user_data);
105 	GeditView *active_view;
106 
107 	gedit_debug (DEBUG_COMMANDS);
108 
109 	active_view = gedit_window_get_active_view (window);
110 	g_return_if_fail (active_view != NULL);
111 
112 	tepl_view_copy_clipboard (TEPL_VIEW (active_view));
113 
114 	gtk_widget_grab_focus (GTK_WIDGET (active_view));
115 }
116 
117 void
_gedit_cmd_edit_paste(GSimpleAction * action,GVariant * parameter,gpointer user_data)118 _gedit_cmd_edit_paste (GSimpleAction *action,
119                        GVariant      *parameter,
120                        gpointer       user_data)
121 {
122 	GeditWindow *window = GEDIT_WINDOW (user_data);
123 	GeditView *active_view;
124 
125 	gedit_debug (DEBUG_COMMANDS);
126 
127 	active_view = gedit_window_get_active_view (window);
128 	g_return_if_fail (active_view != NULL);
129 
130 	tepl_view_paste_clipboard (TEPL_VIEW (active_view));
131 
132 	gtk_widget_grab_focus (GTK_WIDGET (active_view));
133 }
134 
135 void
_gedit_cmd_edit_delete(GSimpleAction * action,GVariant * parameter,gpointer user_data)136 _gedit_cmd_edit_delete (GSimpleAction *action,
137                         GVariant      *parameter,
138                         gpointer       user_data)
139 {
140 	GeditWindow *window = GEDIT_WINDOW (user_data);
141 	GeditView *active_view;
142 
143 	gedit_debug (DEBUG_COMMANDS);
144 
145 	active_view = gedit_window_get_active_view (window);
146 	g_return_if_fail (active_view != NULL);
147 
148 	tepl_view_delete_selection (TEPL_VIEW (active_view));
149 
150 	gtk_widget_grab_focus (GTK_WIDGET (active_view));
151 }
152 
153 void
_gedit_cmd_edit_select_all(GSimpleAction * action,GVariant * parameter,gpointer user_data)154 _gedit_cmd_edit_select_all (GSimpleAction *action,
155                             GVariant      *parameter,
156                             gpointer       user_data)
157 {
158 	GeditWindow *window = GEDIT_WINDOW (user_data);
159 	GeditView *active_view;
160 
161 	gedit_debug (DEBUG_COMMANDS);
162 
163 	active_view = gedit_window_get_active_view (window);
164 	g_return_if_fail (active_view != NULL);
165 
166 	tepl_view_select_all (TEPL_VIEW (active_view));
167 
168 	gtk_widget_grab_focus (GTK_WIDGET (active_view));
169 }
170 
171 void
_gedit_cmd_edit_preferences(GSimpleAction * action,GVariant * parameter,gpointer user_data)172 _gedit_cmd_edit_preferences (GSimpleAction *action,
173                              GVariant      *parameter,
174                              gpointer       user_data)
175 {
176 	GeditWindow *window = GEDIT_WINDOW (user_data);
177 
178 	gedit_debug (DEBUG_COMMANDS);
179 
180 	gedit_show_preferences_dialog (window);
181 }
182 
183 void
_gedit_cmd_edit_overwrite_mode(GSimpleAction * action,GVariant * state,gpointer user_data)184 _gedit_cmd_edit_overwrite_mode (GSimpleAction *action,
185                                 GVariant      *state,
186                                 gpointer       user_data)
187 {
188 	GeditWindow *window = GEDIT_WINDOW (user_data);
189 	GeditView *active_view;
190 	gboolean overwrite;
191 
192 	gedit_debug (DEBUG_COMMANDS);
193 
194 	active_view = gedit_window_get_active_view (window);
195 	g_return_if_fail (active_view);
196 
197 	overwrite = g_variant_get_boolean (state);
198 	g_simple_action_set_state (action, state);
199 
200 	gtk_text_view_set_overwrite (GTK_TEXT_VIEW (active_view), overwrite);
201 	gtk_widget_grab_focus (GTK_WIDGET (active_view));
202 }
203 
204 
205 /* ex:set ts=8 noet: */
206