Line 0
Link Here
|
|
|
1 |
From 1362bbc140d6853307a7127aead766b001b613b6 Mon Sep 17 00:00:00 2001 |
2 |
From: Andy Spencer <andy753421@gmail.com> |
3 |
Date: Sun, 27 Feb 2011 01:52:06 +0000 |
4 |
Subject: [PATCH 1/1] Add "paste-selection" keybind signal |
5 |
|
6 |
This allows (re)binding a key to paste the PRIMARY and/or SECONDARY |
7 |
selections under X11. |
8 |
--- |
9 |
gtk/gtkentry.c | 42 ++++++++++++++++++++++++++++++++++++++++++ |
10 |
gtk/gtkentry.h | 4 +++- |
11 |
gtk/gtktextview.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ |
12 |
gtk/gtktextview.h | 4 +++- |
13 |
4 files changed, 96 insertions(+), 2 deletions(-) |
14 |
|
15 |
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c |
16 |
index dd509c2..2066952 100644 |
17 |
--- gtk/gtkentry.c |
18 |
+++ gtk/gtkentry.c |
19 |
@@ -168,6 +168,7 @@ enum { |
20 |
CUT_CLIPBOARD, |
21 |
COPY_CLIPBOARD, |
22 |
PASTE_CLIPBOARD, |
23 |
+ PASTE_SELECTION, |
24 |
TOGGLE_OVERWRITE, |
25 |
ICON_PRESS, |
26 |
ICON_RELEASE, |
27 |
@@ -382,6 +383,8 @@ static void gtk_entry_backspace (GtkEntry *entry); |
28 |
static void gtk_entry_cut_clipboard (GtkEntry *entry); |
29 |
static void gtk_entry_copy_clipboard (GtkEntry *entry); |
30 |
static void gtk_entry_paste_clipboard (GtkEntry *entry); |
31 |
+static void gtk_entry_paste_selection (GtkEntry *entry, |
32 |
+ const gchar *which); |
33 |
static void gtk_entry_toggle_overwrite (GtkEntry *entry); |
34 |
static void gtk_entry_select_all (GtkEntry *entry); |
35 |
static void gtk_entry_real_activate (GtkEntry *entry); |
36 |
@@ -615,6 +618,7 @@ gtk_entry_class_init (GtkEntryClass *class) |
37 |
class->cut_clipboard = gtk_entry_cut_clipboard; |
38 |
class->copy_clipboard = gtk_entry_copy_clipboard; |
39 |
class->paste_clipboard = gtk_entry_paste_clipboard; |
40 |
+ class->paste_selection = gtk_entry_paste_selection; |
41 |
class->toggle_overwrite = gtk_entry_toggle_overwrite; |
42 |
class->activate = gtk_entry_real_activate; |
43 |
class->get_text_area_size = gtk_entry_get_text_area_size; |
44 |
@@ -1489,6 +1493,25 @@ gtk_entry_class_init (GtkEntryClass *class) |
45 |
G_TYPE_NONE, 0); |
46 |
|
47 |
/** |
48 |
+ * GtkEntry::paste-selection: |
49 |
+ * @entry: the object which received the signal |
50 |
+ * |
51 |
+ * The ::paste-selection signal is a |
52 |
+ * <link linkend="keybinding-signals">keybinding signal</link> |
53 |
+ * which gets emitted to paste the contents of the given selection |
54 |
+ * into the entry. |
55 |
+ */ |
56 |
+ signals[PASTE_SELECTION] = |
57 |
+ g_signal_new (I_("paste-selection"), |
58 |
+ G_OBJECT_CLASS_TYPE (gobject_class), |
59 |
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, |
60 |
+ G_STRUCT_OFFSET (GtkEntryClass, paste_selection), |
61 |
+ NULL, NULL, |
62 |
+ _gtk_marshal_VOID__STRING, |
63 |
+ G_TYPE_NONE, 1, |
64 |
+ G_TYPE_STRING); |
65 |
+ |
66 |
+ /** |
67 |
* GtkEntry::toggle-overwrite: |
68 |
* @entry: the object which received the signal |
69 |
* |
70 |
@@ -5094,6 +5117,25 @@ gtk_entry_paste_clipboard (GtkEntry *entry) |
71 |
} |
72 |
|
73 |
static void |
74 |
+gtk_entry_paste_selection (GtkEntry *entry, |
75 |
+ const gchar *which) |
76 |
+{ |
77 |
+ if (entry->editable) |
78 |
+ { |
79 |
+ if (g_str_equal(which, "primary")) |
80 |
+ gtk_entry_paste (entry, GDK_SELECTION_PRIMARY); |
81 |
+ else if (g_str_equal(which, "secondary")) |
82 |
+ gtk_entry_paste (entry, GDK_SELECTION_SECONDARY); |
83 |
+ else if (g_str_equal(which, "clipboard")) |
84 |
+ gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD); |
85 |
+ else |
86 |
+ gtk_widget_error_bell (GTK_WIDGET (entry)); |
87 |
+ } |
88 |
+ else |
89 |
+ gtk_widget_error_bell (GTK_WIDGET (entry)); |
90 |
+} |
91 |
+ |
92 |
+static void |
93 |
gtk_entry_delete_cb (GtkEntry *entry) |
94 |
{ |
95 |
GtkEditable *editable = GTK_EDITABLE (entry); |
96 |
diff --git a/gtk/gtkentry.h b/gtk/gtkentry.h |
97 |
index 9bbba0b..21c0ca4 100644 |
98 |
--- gtk/gtkentry.h |
99 |
+++ gtk/gtkentry.h |
100 |
@@ -158,9 +158,11 @@ struct _GtkEntryClass |
101 |
gint *width, |
102 |
gint *height); |
103 |
|
104 |
+ void (* paste_selection) (GtkEntry *entry, |
105 |
+ const gchar *which); |
106 |
+ |
107 |
/* Padding for future expansion */ |
108 |
void (*_gtk_reserved1) (void); |
109 |
- void (*_gtk_reserved2) (void); |
110 |
}; |
111 |
|
112 |
GType gtk_entry_get_type (void) G_GNUC_CONST; |
113 |
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c |
114 |
index 9a2edc0..c9cd014 100644 |
115 |
--- gtk/gtktextview.c |
116 |
+++ gtk/gtktextview.c |
117 |
@@ -135,6 +135,7 @@ enum |
118 |
CUT_CLIPBOARD, |
119 |
COPY_CLIPBOARD, |
120 |
PASTE_CLIPBOARD, |
121 |
+ PASTE_SELECTION, |
122 |
TOGGLE_OVERWRITE, |
123 |
MOVE_VIEWPORT, |
124 |
SELECT_ALL, |
125 |
@@ -281,6 +282,8 @@ static void gtk_text_view_backspace (GtkTextView *text_view); |
126 |
static void gtk_text_view_cut_clipboard (GtkTextView *text_view); |
127 |
static void gtk_text_view_copy_clipboard (GtkTextView *text_view); |
128 |
static void gtk_text_view_paste_clipboard (GtkTextView *text_view); |
129 |
+static void gtk_text_view_paste_selection (GtkTextView *text_view, |
130 |
+ const gchar *which); |
131 |
static void gtk_text_view_toggle_overwrite (GtkTextView *text_view); |
132 |
static void gtk_text_view_toggle_cursor_visible (GtkTextView *text_view); |
133 |
static void gtk_text_view_compat_move_focus(GtkTextView *text_view, |
134 |
@@ -532,6 +535,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass) |
135 |
klass->cut_clipboard = gtk_text_view_cut_clipboard; |
136 |
klass->copy_clipboard = gtk_text_view_copy_clipboard; |
137 |
klass->paste_clipboard = gtk_text_view_paste_clipboard; |
138 |
+ klass->paste_selection = gtk_text_view_paste_selection; |
139 |
klass->toggle_overwrite = gtk_text_view_toggle_overwrite; |
140 |
klass->move_focus = gtk_text_view_compat_move_focus; |
141 |
klass->set_scroll_adjustments = gtk_text_view_set_scroll_adjustments; |
142 |
@@ -947,6 +951,25 @@ gtk_text_view_class_init (GtkTextViewClass *klass) |
143 |
G_TYPE_NONE, 0); |
144 |
|
145 |
/** |
146 |
+ * GtkTextView::paste-selection: |
147 |
+ * @text_view: the object which received the signal |
148 |
+ * |
149 |
+ * The ::paste-selection signal is a |
150 |
+ * <link linkend="keybinding-signals">keybinding signal</link> |
151 |
+ * which gets emitted to paste the contents of the given selection |
152 |
+ * into the text view. |
153 |
+ */ |
154 |
+ signals[PASTE_SELECTION] = |
155 |
+ g_signal_new (I_("paste-selection"), |
156 |
+ G_OBJECT_CLASS_TYPE (gobject_class), |
157 |
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, |
158 |
+ G_STRUCT_OFFSET (GtkTextViewClass, paste_selection), |
159 |
+ NULL, NULL, |
160 |
+ _gtk_marshal_VOID__STRING, |
161 |
+ G_TYPE_NONE, 1, |
162 |
+ G_TYPE_STRING); |
163 |
+ |
164 |
+ /** |
165 |
* GtkTextView::toggle-overwrite: |
166 |
* @text_view: the object which received the signal |
167 |
* |
168 |
@@ -5818,6 +5841,31 @@ gtk_text_view_paste_clipboard (GtkTextView *text_view) |
169 |
} |
170 |
|
171 |
static void |
172 |
+gtk_text_view_paste_selection (GtkTextView *text_view, |
173 |
+ const gchar *which) |
174 |
+{ |
175 |
+ GtkClipboard *clipboard = NULL; |
176 |
+ |
177 |
+ if (g_str_equal (which, "primary")) |
178 |
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view), |
179 |
+ GDK_SELECTION_PRIMARY); |
180 |
+ else if (g_str_equal (which, "secondary")) |
181 |
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view), |
182 |
+ GDK_SELECTION_SECONDARY); |
183 |
+ else if (g_str_equal (which, "clipboard")) |
184 |
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view), |
185 |
+ GDK_SELECTION_CLIPBOARD); |
186 |
+ |
187 |
+ if (clipboard) |
188 |
+ gtk_text_buffer_paste_clipboard (get_buffer (text_view), |
189 |
+ clipboard, |
190 |
+ NULL, |
191 |
+ text_view->editable); |
192 |
+ else |
193 |
+ gtk_widget_error_bell (GTK_WIDGET (text_view)); |
194 |
+} |
195 |
+ |
196 |
+static void |
197 |
gtk_text_view_paste_done_handler (GtkTextBuffer *buffer, |
198 |
GtkClipboard *clipboard, |
199 |
gpointer data) |
200 |
diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h |
201 |
index c3fa802..eacd734 100644 |
202 |
--- gtk/gtktextview.h |
203 |
+++ gtk/gtktextview.h |
204 |
@@ -204,6 +204,9 @@ struct _GtkTextViewClass |
205 |
void (* move_focus) (GtkTextView *text_view, |
206 |
GtkDirectionType direction); |
207 |
|
208 |
+ void (* paste_selection) (GtkTextView *text_view, |
209 |
+ const gchar *which); |
210 |
+ |
211 |
/* Padding for future expansion */ |
212 |
void (*_gtk_reserved1) (void); |
213 |
void (*_gtk_reserved2) (void); |
214 |
@@ -211,7 +214,6 @@ struct _GtkTextViewClass |
215 |
void (*_gtk_reserved4) (void); |
216 |
void (*_gtk_reserved5) (void); |
217 |
void (*_gtk_reserved6) (void); |
218 |
- void (*_gtk_reserved7) (void); |
219 |
}; |
220 |
|
221 |
GType gtk_text_view_get_type (void) G_GNUC_CONST; |
222 |
-- |
223 |
1.7.3.4 |
224 |
|