Mercurial > pidgin.yaz
annotate finch/libgnt/gnttextview.c @ 22337:a8c025929245
Add support for offline messages for AIM, thanks to some info from
Matthew Goldstein. The new protocol bits used for offline messaging
for AIM are very nice. It fits in with the rest of the oscar protocol
very well (the old, ICQ-style offline messages were a bit of a hack).
The offline messages arrive in the same way as every other message
(except that they have a timestamp), so we can use the same message
parsing that we use for all other IMs. This means that all our
encoding stuff works just as well with offline messages.
AND the new offline message stuff works for ICQ accounts, too. So I
switched ICQ over to use it, which fixes offline message timestamps
(if that was still a problem, I'm not sure) and offline message encoding
bugs.
Fixes #1229 (feature request for AIM offline messages)
Fixes #1761 (ICQ offline message timestamp is wrong)
Fixes #4300 (crash when receiving offline messages)
Fixes #4464 (can't send IMs to invisible users)
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 27 Feb 2008 09:18:06 +0000 |
parents | c38d72677c8a |
children | f10aba5592c6 |
rev | line source |
---|---|
17718
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19376
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
17718
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16124
diff
changeset
|
22 |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
23 #include "gntstyle.h" |
15818 | 24 #include "gnttextview.h" |
25 #include "gntutils.h" | |
26 | |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
27 #include <stdlib.h> |
15818 | 28 #include <string.h> |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18426
diff
changeset
|
29 #include <unistd.h> |
15818 | 30 |
31 enum | |
32 { | |
33 SIGS = 1, | |
34 }; | |
35 | |
36 typedef struct | |
37 { | |
38 GntTextFormatFlags tvflag; | |
39 chtype flags; | |
40 int start; | |
41 int end; /* This is the next byte of the last character of this segment */ | |
42 } GntTextSegment; | |
43 | |
44 typedef struct | |
45 { | |
46 GList *segments; /* A list of GntTextSegments */ | |
47 int length; /* The current length of the line so far (ie. onscreen width) */ | |
48 gboolean soft; /* TRUE if it's an overflow from prev. line */ | |
49 } GntTextLine; | |
50 | |
51 typedef struct | |
52 { | |
53 char *name; | |
54 int start; | |
55 int end; | |
56 } GntTextTag; | |
57 | |
58 static GntWidgetClass *parent_class = NULL; | |
59 | |
60 static gchar *select_start; | |
61 static gchar *select_end; | |
62 static gboolean double_click; | |
63 | |
21306
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
64 static void reset_text_view(GntTextView *view); |
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
65 |
15818 | 66 static void |
67 gnt_text_view_draw(GntWidget *widget) | |
68 { | |
69 GntTextView *view = GNT_TEXT_VIEW(widget); | |
70 int i = 0; | |
71 GList *lines; | |
72 int rows, scrcol; | |
18719
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
73 int comp = 0; /* Used for top-aligned text */ |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
74 gboolean has_scroll = !(view->flags & GNT_TEXT_VIEW_NO_SCROLL); |
15818 | 75 |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
76 wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 77 werase(widget->window); |
78 | |
18719
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
79 if ((view->flags & GNT_TEXT_VIEW_TOP_ALIGN) && |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
80 g_list_length(view->list) < widget->priv.height) { |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
81 GList *now = view->list; |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
82 comp = widget->priv.height - g_list_length(view->list); |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
83 view->list = g_list_nth_prev(view->list, comp); |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
84 if (!view->list) { |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
85 view->list = g_list_first(now); |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
86 comp = widget->priv.height - g_list_length(view->list); |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
87 } else { |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
88 comp = 0; |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
89 } |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
90 } |
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
91 |
15818 | 92 for (i = 0, lines = view->list; i < widget->priv.height && lines; i++, lines = lines->next) |
93 { | |
94 GList *iter; | |
95 GntTextLine *line = lines->data; | |
96 | |
18719
c3d0b51d6c60
New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18680
diff
changeset
|
97 wmove(widget->window, widget->priv.height - 1 - i - comp, 0); |
15818 | 98 |
99 for (iter = line->segments; iter; iter = iter->next) | |
100 { | |
101 GntTextSegment *seg = iter->data; | |
102 char *end = view->string->str + seg->end; | |
103 char back = *end; | |
104 chtype fl = seg->flags; | |
105 *end = '\0'; | |
106 if (select_start < view->string->str + seg->start && select_end > view->string->str + seg->end) { | |
107 fl |= A_REVERSE; | |
108 wattrset(widget->window, fl); | |
109 wprintw(widget->window, "%s", (view->string->str + seg->start)); | |
110 } else if (select_start && select_end && | |
111 ((select_start >= view->string->str + seg->start && select_start <= view->string->str + seg->end) || | |
112 (select_end <= view->string->str + seg->end && select_start <= view->string->str + seg->start))) { | |
113 char *cur = view->string->str + seg->start; | |
114 while (*cur != '\0') { | |
115 gchar *last = g_utf8_next_char(cur); | |
116 gchar *str; | |
117 if (cur >= select_start && cur <= select_end) | |
118 fl |= A_REVERSE; | |
119 else | |
120 fl = seg->flags; | |
121 str = g_strndup(cur, last - cur); | |
122 wattrset(widget->window, fl); | |
123 waddstr(widget->window, str); | |
124 g_free(str); | |
125 cur = g_utf8_next_char(cur); | |
126 } | |
127 } else { | |
128 wattrset(widget->window, fl); | |
129 wprintw(widget->window, "%s", (view->string->str + seg->start)); | |
130 } | |
131 *end = back; | |
132 } | |
133 wattroff(widget->window, A_UNDERLINE | A_BLINK | A_REVERSE); | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
134 whline(widget->window, ' ', widget->priv.width - line->length - has_scroll); |
15818 | 135 } |
136 | |
137 scrcol = widget->priv.width - 1; | |
138 rows = widget->priv.height - 2; | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
139 if (has_scroll && rows > 0) |
15818 | 140 { |
141 int total = g_list_length(g_list_first(view->list)); | |
142 int showing, position, up, down; | |
143 | |
144 showing = rows * rows / total + 1; | |
145 showing = MIN(rows, showing); | |
146 | |
147 total -= rows; | |
148 up = g_list_length(lines); | |
149 down = total - up; | |
150 | |
151 position = (rows - showing) * up / MAX(1, up + down); | |
152 position = MAX((lines != NULL), position); | |
153 | |
154 if (showing + position > rows) | |
155 position = rows - showing; | |
156 | |
157 if (showing + position == rows && view->list && view->list->prev) | |
158 position = MAX(1, rows - 1 - showing); | |
159 else if (showing + position < rows && view->list && !view->list->prev) | |
160 position = rows - showing; | |
161 | |
162 mvwvline(widget->window, position + 1, scrcol, | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
163 ACS_CKBOARD | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D), showing); |
15818 | 164 } |
165 | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
166 if (has_scroll) { |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
167 mvwaddch(widget->window, 0, scrcol, |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
168 (lines ? ACS_UARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
169 mvwaddch(widget->window, widget->priv.height - 1, scrcol, |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
170 ((view->list && view->list->prev) ? ACS_DARROW : ' ') | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
171 gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
172 } |
15818 | 173 |
174 GNTDEBUG; | |
175 } | |
176 | |
177 static void | |
178 gnt_text_view_size_request(GntWidget *widget) | |
179 { | |
180 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) | |
181 { | |
182 gnt_widget_set_size(widget, 64, 20); | |
183 } | |
184 } | |
185 | |
186 static void | |
187 gnt_text_view_map(GntWidget *widget) | |
188 { | |
189 if (widget->priv.width == 0 || widget->priv.height == 0) | |
190 gnt_widget_size_request(widget); | |
191 GNTDEBUG; | |
192 } | |
193 | |
194 static gboolean | |
195 gnt_text_view_key_pressed(GntWidget *widget, const char *text) | |
196 { | |
197 return FALSE; | |
198 } | |
199 | |
200 static void | |
201 free_text_segment(gpointer data, gpointer null) | |
202 { | |
203 GntTextSegment *seg = data; | |
204 g_free(seg); | |
205 } | |
206 | |
207 static void | |
208 free_text_line(gpointer data, gpointer null) | |
209 { | |
210 GntTextLine *line = data; | |
211 g_list_foreach(line->segments, free_text_segment, NULL); | |
212 g_list_free(line->segments); | |
213 g_free(line); | |
214 } | |
215 | |
216 static void | |
217 free_tag(gpointer data, gpointer null) | |
218 { | |
219 GntTextTag *tag = data; | |
220 g_free(tag->name); | |
221 g_free(tag); | |
222 } | |
223 | |
224 static void | |
225 gnt_text_view_destroy(GntWidget *widget) | |
226 { | |
227 GntTextView *view = GNT_TEXT_VIEW(widget); | |
228 view->list = g_list_first(view->list); | |
229 g_list_foreach(view->list, free_text_line, NULL); | |
230 g_list_free(view->list); | |
231 g_list_foreach(view->tags, free_tag, NULL); | |
232 g_list_free(view->tags); | |
233 g_string_free(view->string, TRUE); | |
234 } | |
235 | |
236 static char * | |
237 gnt_text_view_get_p(GntTextView *view, int x, int y) | |
238 { | |
239 int i = 0; | |
240 GntWidget *wid = GNT_WIDGET(view); | |
241 GntTextLine *line; | |
242 GList *lines; | |
243 GList *segs; | |
244 GntTextSegment *seg; | |
245 gchar *pos; | |
246 | |
247 y = wid->priv.height - y; | |
248 if (g_list_length(view->list) < y) { | |
249 x = 0; | |
250 y = g_list_length(view->list) - 1; | |
251 } | |
252 | |
253 lines = g_list_nth(view->list, y - 1); | |
254 if (!lines) | |
255 return NULL; | |
256 do { | |
257 line = lines->data; | |
258 lines = lines->next; | |
259 } while (line && !line->segments && lines); | |
260 | |
261 if (!line || !line->segments) /* no valid line */ | |
262 return NULL; | |
263 segs = line->segments; | |
264 seg = (GntTextSegment *)segs->data; | |
265 pos = view->string->str + seg->start; | |
266 x = MIN(x, line->length); | |
267 while (++i <= x) { | |
268 gunichar *u; | |
269 pos = g_utf8_next_char(pos); | |
270 u = g_utf8_to_ucs4(pos, -1, NULL, NULL, NULL); | |
271 if (u && g_unichar_iswide(*u)) | |
272 i++; | |
273 g_free(u); | |
274 } | |
275 return pos; | |
276 } | |
277 | |
278 static GString * | |
279 select_word_text(GntTextView *view, gchar *c) | |
280 { | |
281 gchar *start = c; | |
282 gchar *end = c; | |
283 gchar *t, *endsize; | |
284 while ((t = g_utf8_prev_char(start))) { | |
285 if (!g_ascii_isspace(*t)) { | |
286 if (start == view->string->str) | |
287 break; | |
288 start = t; | |
289 } else | |
290 break; | |
291 } | |
292 while ((t = g_utf8_next_char(end))) { | |
293 if (!g_ascii_isspace(*t)) | |
294 end = t; | |
295 else | |
296 break; | |
297 } | |
298 select_start = start; | |
299 select_end = end; | |
300 endsize = g_utf8_next_char(select_end); /* End at the correct byte */ | |
301 return g_string_new_len(start, endsize - start); | |
302 } | |
303 | |
304 static gboolean too_slow(gpointer n) | |
305 { | |
306 double_click = FALSE; | |
307 return FALSE; | |
308 } | |
309 | |
310 static gboolean | |
311 gnt_text_view_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
312 { | |
313 if (event == GNT_MOUSE_SCROLL_UP) { | |
314 gnt_text_view_scroll(GNT_TEXT_VIEW(widget), -1); | |
315 } else if (event == GNT_MOUSE_SCROLL_DOWN) { | |
316 gnt_text_view_scroll(GNT_TEXT_VIEW(widget), 1); | |
317 } else if (event == GNT_LEFT_MOUSE_DOWN) { | |
318 select_start = gnt_text_view_get_p(GNT_TEXT_VIEW(widget), x - widget->priv.x, y - widget->priv.y); | |
319 g_timeout_add(500, too_slow, NULL); | |
320 } else if (event == GNT_MOUSE_UP) { | |
321 if (select_start) { | |
322 GString *clip; | |
323 select_end = gnt_text_view_get_p(GNT_TEXT_VIEW(widget), x - widget->priv.x, y - widget->priv.y); | |
324 if (select_end < select_start) { | |
325 gchar *t = select_start; | |
326 select_start = select_end; | |
327 select_end = t; | |
328 } | |
329 if (select_start == select_end) { | |
330 if (double_click) { | |
331 clip = select_word_text(GNT_TEXT_VIEW(widget), select_start); | |
332 double_click = FALSE; | |
333 } else { | |
334 double_click = TRUE; | |
335 select_start = 0; | |
336 select_end = 0; | |
337 gnt_widget_draw(widget); | |
338 return TRUE; | |
339 } | |
340 } else { | |
341 gchar *endsize = g_utf8_next_char(select_end); /* End at the correct byte */ | |
342 clip = g_string_new_len(select_start, endsize - select_start); | |
343 } | |
344 gnt_widget_draw(widget); | |
345 gnt_set_clipboard_string(clip->str); | |
346 g_string_free(clip, TRUE); | |
347 } | |
348 } else | |
349 return FALSE; | |
350 return TRUE; | |
351 } | |
352 | |
353 static void | |
354 gnt_text_view_reflow(GntTextView *view) | |
355 { | |
356 /* This is pretty ugly, and inefficient. Someone do something about it. */ | |
357 GntTextLine *line; | |
358 GList *back, *iter, *list; | |
359 GString *string; | |
360 int pos = 0; /* no. of 'real' lines */ | |
361 | |
362 list = view->list; | |
363 while (list->prev) { | |
364 line = list->data; | |
365 if (!line->soft) | |
366 pos++; | |
367 list = list->prev; | |
368 } | |
369 | |
370 back = g_list_last(view->list); | |
371 view->list = NULL; | |
372 | |
373 string = view->string; | |
374 view->string = NULL; | |
21306
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
375 reset_text_view(view); |
15818 | 376 |
377 view->string = g_string_set_size(view->string, string->len); | |
378 view->string->len = 0; | |
379 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); | |
380 | |
381 for (; back; back = back->prev) { | |
382 line = back->data; | |
383 if (back->next && !line->soft) { | |
384 gnt_text_view_append_text_with_flags(view, "\n", GNT_TEXT_FLAG_NORMAL); | |
385 } | |
386 | |
387 for (iter = line->segments; iter; iter = iter->next) { | |
388 GntTextSegment *seg = iter->data; | |
389 char *start = string->str + seg->start; | |
390 char *end = string->str + seg->end; | |
391 char back = *end; | |
392 *end = '\0'; | |
393 gnt_text_view_append_text_with_flags(view, start, seg->tvflag); | |
394 *end = back; | |
395 } | |
396 free_text_line(line, NULL); | |
397 } | |
398 g_list_free(list); | |
399 | |
400 list = view->list = g_list_first(view->list); | |
401 /* Go back to the line that was in view before resizing started */ | |
402 while (pos--) { | |
403 while (((GntTextLine*)list->data)->soft) | |
404 list = list->next; | |
405 list = list->next; | |
406 } | |
407 view->list = list; | |
408 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); | |
409 if (GNT_WIDGET(view)->window) | |
410 gnt_widget_draw(GNT_WIDGET(view)); | |
411 g_string_free(string, TRUE); | |
412 } | |
413 | |
414 static void | |
415 gnt_text_view_size_changed(GntWidget *widget, int w, int h) | |
416 { | |
18680
fd01bac27b79
Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18539
diff
changeset
|
417 if (w != widget->priv.width && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) { |
15818 | 418 gnt_text_view_reflow(GNT_TEXT_VIEW(widget)); |
419 } | |
420 } | |
421 | |
422 static void | |
423 gnt_text_view_class_init(GntTextViewClass *klass) | |
424 { | |
425 parent_class = GNT_WIDGET_CLASS(klass); | |
426 parent_class->destroy = gnt_text_view_destroy; | |
427 parent_class->draw = gnt_text_view_draw; | |
428 parent_class->map = gnt_text_view_map; | |
429 parent_class->size_request = gnt_text_view_size_request; | |
430 parent_class->key_pressed = gnt_text_view_key_pressed; | |
431 parent_class->clicked = gnt_text_view_clicked; | |
432 parent_class->size_changed = gnt_text_view_size_changed; | |
433 | |
434 GNTDEBUG; | |
435 } | |
436 | |
437 static void | |
438 gnt_text_view_init(GTypeInstance *instance, gpointer class) | |
439 { | |
440 GntWidget *widget = GNT_WIDGET(instance); | |
18680
fd01bac27b79
Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18539
diff
changeset
|
441 GntTextView *view = GNT_TEXT_VIEW(widget); |
fd01bac27b79
Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18539
diff
changeset
|
442 GntTextLine *line = g_new0(GntTextLine, 1); |
15818 | 443 |
18680
fd01bac27b79
Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18539
diff
changeset
|
444 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW | |
fd01bac27b79
Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18539
diff
changeset
|
445 GNT_WIDGET_GROW_Y | GNT_WIDGET_GROW_X); |
15818 | 446 widget->priv.minw = 5; |
447 widget->priv.minh = 2; | |
18680
fd01bac27b79
Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18539
diff
changeset
|
448 view->string = g_string_new(NULL); |
fd01bac27b79
Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18539
diff
changeset
|
449 view->list = g_list_append(view->list, line); |
fd01bac27b79
Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18539
diff
changeset
|
450 |
15818 | 451 GNTDEBUG; |
452 } | |
453 | |
454 /****************************************************************************** | |
455 * GntTextView API | |
456 *****************************************************************************/ | |
457 GType | |
458 gnt_text_view_get_gtype(void) | |
459 { | |
460 static GType type = 0; | |
461 | |
462 if(type == 0) | |
463 { | |
464 static const GTypeInfo info = { | |
465 sizeof(GntTextViewClass), | |
466 NULL, /* base_init */ | |
467 NULL, /* base_finalize */ | |
468 (GClassInitFunc)gnt_text_view_class_init, | |
469 NULL, /* class_finalize */ | |
470 NULL, /* class_data */ | |
471 sizeof(GntTextView), | |
472 0, /* n_preallocs */ | |
473 gnt_text_view_init, /* instance_init */ | |
474 NULL /* value_table */ | |
475 }; | |
476 | |
477 type = g_type_register_static(GNT_TYPE_WIDGET, | |
478 "GntTextView", | |
479 &info, 0); | |
480 } | |
481 | |
482 return type; | |
483 } | |
484 | |
485 GntWidget *gnt_text_view_new() | |
486 { | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
487 GntWidget *widget = g_object_new(GNT_TYPE_TEXT_VIEW, NULL); |
15818 | 488 |
489 return widget; | |
490 } | |
491 | |
492 void gnt_text_view_append_text_with_flags(GntTextView *view, const char *text, GntTextFormatFlags flags) | |
493 { | |
494 gnt_text_view_append_text_with_tag(view, text, flags, NULL); | |
495 } | |
496 | |
497 void gnt_text_view_append_text_with_tag(GntTextView *view, const char *text, | |
498 GntTextFormatFlags flags, const char *tagname) | |
499 { | |
500 GntWidget *widget = GNT_WIDGET(view); | |
501 int fl = 0; | |
502 const char *start, *end; | |
503 GList *list = view->list; | |
504 GntTextLine *line; | |
505 int len; | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
506 gboolean has_scroll = !(view->flags & GNT_TEXT_VIEW_NO_SCROLL); |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
507 gboolean wrap_word = !(view->flags & GNT_TEXT_VIEW_WRAP_CHAR); |
15818 | 508 |
509 if (text == NULL || *text == '\0') | |
510 return; | |
511 | |
512 fl = gnt_text_format_flag_to_chtype(flags); | |
513 | |
514 len = view->string->len; | |
515 view->string = g_string_append(view->string, text); | |
516 | |
517 if (tagname) { | |
518 GntTextTag *tag = g_new0(GntTextTag, 1); | |
519 tag->name = g_strdup(tagname); | |
520 tag->start = len; | |
521 tag->end = view->string->len; | |
522 view->tags = g_list_append(view->tags, tag); | |
523 } | |
524 | |
525 view->list = g_list_first(view->list); | |
526 | |
527 start = end = view->string->str + len; | |
528 | |
529 while (*start) { | |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
530 GntTextLine *oldl; |
15818 | 531 GntTextSegment *seg = NULL; |
532 | |
533 if (*end == '\n' || *end == '\r') { | |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
534 if (!strncmp(end, "\r\n", 2)) |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
535 end++; |
15818 | 536 end++; |
537 start = end; | |
538 gnt_text_view_next_line(view); | |
539 view->list = g_list_first(view->list); | |
540 continue; | |
541 } | |
542 | |
543 line = view->list->data; | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
544 if (line->length == widget->priv.width - has_scroll) { |
15818 | 545 /* The last added line was exactly the same width as the widget */ |
546 line = g_new0(GntTextLine, 1); | |
547 line->soft = TRUE; | |
548 view->list = g_list_prepend(view->list, line); | |
549 } | |
550 | |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
551 if ((end = strchr(start, '\r')) != NULL || |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
552 (end = strchr(start, '\n')) != NULL) { |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
553 len = gnt_util_onscreen_width(start, end - has_scroll); |
19376
40c3e3857458
Fix #2642 (GntTextView Multiline append goes weird)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
554 if (widget->priv.width > 0 && |
40c3e3857458
Fix #2642 (GntTextView Multiline append goes weird)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
555 len >= widget->priv.width - line->length - has_scroll) { |
15818 | 556 end = NULL; |
557 } | |
558 } | |
559 | |
560 if (end == NULL) | |
561 end = gnt_util_onscreen_width_to_pointer(start, | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
562 widget->priv.width - line->length - has_scroll, &len); |
15818 | 563 |
564 /* Try to append to the previous segment if possible */ | |
565 if (line->segments) { | |
566 seg = g_list_last(line->segments)->data; | |
567 if (seg->flags != fl) | |
568 seg = NULL; | |
569 } | |
570 | |
571 if (seg == NULL) { | |
572 seg = g_new0(GntTextSegment, 1); | |
573 seg->start = start - view->string->str; | |
574 seg->tvflag = flags; | |
575 seg->flags = fl; | |
576 line->segments = g_list_append(line->segments, seg); | |
577 } | |
578 | |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
579 oldl = line; |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
580 if (wrap_word && *end && *end != '\n' && *end != '\r') { |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
581 const char *tmp = end; |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
582 while (end && *end != '\n' && *end != '\r' && !g_ascii_isspace(*end)) { |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
583 end = g_utf8_find_prev_char(seg->start + view->string->str, end); |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
584 } |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
585 if (!end || !g_ascii_isspace(*end)) |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
586 end = tmp; |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
587 else |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
588 end++; /* Remove the space */ |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
589 |
15818 | 590 line = g_new0(GntTextLine, 1); |
591 line->soft = TRUE; | |
592 view->list = g_list_prepend(view->list, line); | |
593 } | |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
594 seg->end = end - view->string->str; |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
595 oldl->length += len; |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
596 start = end; |
15818 | 597 } |
598 | |
599 view->list = list; | |
600 | |
601 gnt_widget_draw(widget); | |
602 } | |
603 | |
604 void gnt_text_view_scroll(GntTextView *view, int scroll) | |
605 { | |
606 if (scroll == 0) | |
607 { | |
608 view->list = g_list_first(view->list); | |
609 } | |
610 else if (scroll > 0) | |
611 { | |
612 GList *list = g_list_nth_prev(view->list, scroll); | |
613 if (list == NULL) | |
614 list = g_list_first(view->list); | |
615 view->list = list; | |
616 } | |
617 else if (scroll < 0) | |
618 { | |
619 GList *list = g_list_nth(view->list, -scroll); | |
620 if (list == NULL) | |
621 list = g_list_last(view->list); | |
622 view->list = list; | |
623 } | |
624 | |
625 gnt_widget_draw(GNT_WIDGET(view)); | |
626 } | |
627 | |
628 void gnt_text_view_next_line(GntTextView *view) | |
629 { | |
630 GntTextLine *line = g_new0(GntTextLine, 1); | |
631 GList *list = view->list; | |
632 | |
633 view->list = g_list_prepend(g_list_first(view->list), line); | |
634 view->list = list; | |
635 gnt_widget_draw(GNT_WIDGET(view)); | |
636 } | |
637 | |
638 chtype gnt_text_format_flag_to_chtype(GntTextFormatFlags flags) | |
639 { | |
640 chtype fl = 0; | |
641 | |
642 if (flags & GNT_TEXT_FLAG_BOLD) | |
643 fl |= A_BOLD; | |
644 if (flags & GNT_TEXT_FLAG_UNDERLINE) | |
645 fl |= A_UNDERLINE; | |
646 if (flags & GNT_TEXT_FLAG_BLINK) | |
647 fl |= A_BLINK; | |
648 | |
649 if (flags & GNT_TEXT_FLAG_DIM) | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
650 fl |= (A_DIM | gnt_color_pair(GNT_COLOR_DISABLED)); |
15818 | 651 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
652 fl |= (A_DIM | gnt_color_pair(GNT_COLOR_HIGHLIGHT)); |
21706
bc4afc8ea960
Do not reset the color if there's something already specified. This should
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21306
diff
changeset
|
653 else if ((flags & A_COLOR) == 0) |
bc4afc8ea960
Do not reset the color if there's something already specified. This should
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21306
diff
changeset
|
654 fl |= gnt_color_pair(GNT_COLOR_NORMAL); |
15818 | 655 else |
21706
bc4afc8ea960
Do not reset the color if there's something already specified. This should
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21306
diff
changeset
|
656 fl |= (flags & A_COLOR); |
15818 | 657 |
658 return fl; | |
659 } | |
660 | |
21306
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
661 static void reset_text_view(GntTextView *view) |
15818 | 662 { |
663 GntTextLine *line; | |
664 | |
665 g_list_foreach(view->list, free_text_line, NULL); | |
666 g_list_free(view->list); | |
667 view->list = NULL; | |
668 | |
669 line = g_new0(GntTextLine, 1); | |
670 view->list = g_list_append(view->list, line); | |
671 if (view->string) | |
672 g_string_free(view->string, TRUE); | |
673 view->string = g_string_new(NULL); | |
21306
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
674 } |
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
675 |
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
676 void gnt_text_view_clear(GntTextView *view) |
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
677 { |
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
678 reset_text_view(view); |
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
679 |
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
680 g_list_foreach(view->tags, free_tag, NULL); |
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
681 view->tags = NULL; |
15818 | 682 |
683 if (GNT_WIDGET(view)->window) | |
684 gnt_widget_draw(GNT_WIDGET(view)); | |
685 } | |
686 | |
687 int gnt_text_view_get_lines_below(GntTextView *view) | |
688 { | |
689 int below = 0; | |
690 GList *list = view->list; | |
691 while ((list = list->prev)) | |
692 ++below; | |
693 return below; | |
694 } | |
695 | |
696 int gnt_text_view_get_lines_above(GntTextView *view) | |
697 { | |
698 int above = 0; | |
699 GList *list = view->list; | |
700 list = g_list_nth(view->list, GNT_WIDGET(view)->priv.height); | |
701 if (!list) | |
702 return 0; | |
703 while ((list = list->next)) | |
704 ++above; | |
705 return above; | |
706 } | |
707 | |
708 /** | |
709 * XXX: There are quite possibly more than a few bugs here. | |
710 */ | |
711 int gnt_text_view_tag_change(GntTextView *view, const char *name, const char *text, gboolean all) | |
712 { | |
713 GList *alllines = g_list_first(view->list); | |
714 GList *list, *next, *iter, *inext; | |
715 const int text_length = text ? strlen(text) : 0; | |
716 int count = 0; | |
717 for (list = view->tags; list; list = next) { | |
718 GntTextTag *tag = list->data; | |
719 next = list->next; | |
720 if (strcmp(tag->name, name) == 0) { | |
721 int change; | |
722 char *before, *after; | |
723 | |
724 count++; | |
725 | |
726 before = g_strndup(view->string->str, tag->start); | |
727 after = g_strdup(view->string->str + tag->end); | |
728 change = (tag->end - tag->start) - text_length; | |
729 | |
730 g_string_printf(view->string, "%s%s%s", before, text ? text : "", after); | |
731 g_free(before); | |
732 g_free(after); | |
733 | |
734 /* Update the offsets of the next tags */ | |
735 for (iter = next; iter; iter = iter->next) { | |
736 GntTextTag *t = iter->data; | |
737 t->start -= change; | |
738 t->end -= change; | |
739 } | |
740 | |
741 /* Update the offsets of the segments */ | |
742 for (iter = alllines; iter; iter = inext) { | |
743 GList *segs, *snext; | |
744 GntTextLine *line = iter->data; | |
745 inext = iter->next; | |
746 for (segs = line->segments; segs; segs = snext) { | |
747 GntTextSegment *seg = segs->data; | |
748 snext = segs->next; | |
749 if (seg->start >= tag->end) { | |
750 /* The segment is somewhere after the tag */ | |
751 seg->start -= change; | |
752 seg->end -= change; | |
753 } else if (seg->end <= tag->start) { | |
754 /* This segment is somewhere in front of the tag */ | |
755 } else if (seg->start >= tag->start) { | |
756 /* This segment starts in the middle of the tag */ | |
757 if (text == NULL) { | |
758 free_text_segment(seg, NULL); | |
759 line->segments = g_list_delete_link(line->segments, segs); | |
760 if (line->segments == NULL) { | |
761 free_text_line(line, NULL); | |
762 if (view->list == iter) { | |
763 if (inext) | |
764 view->list = inext; | |
765 else | |
766 view->list = iter->prev; | |
767 } | |
768 alllines = g_list_delete_link(alllines, iter); | |
769 } | |
770 } else { | |
771 /* XXX: (null) */ | |
772 seg->start = tag->start; | |
773 seg->end = tag->end - change; | |
774 } | |
775 line->length -= change; | |
776 /* XXX: Make things work if the tagged text spans over several lines. */ | |
777 } else { | |
778 /* XXX: handle the rest of the conditions */ | |
779 g_printerr("WTF! This needs to be handled properly!!\n"); | |
780 } | |
781 } | |
782 } | |
783 if (text == NULL) { | |
784 /* Remove the tag */ | |
785 view->tags = g_list_delete_link(view->tags, list); | |
786 free_tag(tag, NULL); | |
787 } else { | |
788 tag->end -= change; | |
789 } | |
790 if (!all) | |
791 break; | |
792 } | |
793 } | |
794 return count; | |
795 } | |
796 | |
16124
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
797 static gboolean |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
798 scroll_tv(GntWidget *wid, const char *key, GntTextView *tv) |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
799 { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
800 if (strcmp(key, GNT_KEY_PGUP) == 0) { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
801 gnt_text_view_scroll(tv, -(GNT_WIDGET(tv)->priv.height - 2)); |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
802 } else if (strcmp(key, GNT_KEY_PGDOWN) == 0) { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
803 gnt_text_view_scroll(tv, GNT_WIDGET(tv)->priv.height - 2); |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
804 } else if (strcmp(key, GNT_KEY_DOWN) == 0) { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
805 gnt_text_view_scroll(tv, 1); |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
806 } else if (strcmp(key, GNT_KEY_UP) == 0) { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
807 gnt_text_view_scroll(tv, -1); |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
808 } else { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
809 return FALSE; |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
810 } |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
811 return TRUE; |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
812 } |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
813 |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
814 void gnt_text_view_attach_scroll_widget(GntTextView *view, GntWidget *widget) |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
815 { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
816 g_signal_connect(G_OBJECT(widget), "key_pressed", G_CALLBACK(scroll_tv), view); |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
817 } |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
818 |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
819 void gnt_text_view_set_flag(GntTextView *view, GntTextViewFlag flag) |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
820 { |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
821 view->flags |= flag; |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
822 } |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
823 |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
824 /* Pager and editor setups */ |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
825 struct |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
826 { |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
827 GntTextView *tv; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
828 char *file; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
829 } pageditor; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
830 |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
831 |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
832 static void |
22007
c38d72677c8a
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents:
21706
diff
changeset
|
833 cleanup_pageditor(void) |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
834 { |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
835 unlink(pageditor.file); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
836 g_free(pageditor.file); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
837 |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
838 pageditor.file = NULL; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
839 pageditor.tv = NULL; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
840 } |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
841 |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
842 static void |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
843 editor_end_cb(int status, gpointer data) |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
844 { |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
845 if (status == 0) { |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
846 char *text = NULL; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
847 if (g_file_get_contents(pageditor.file, &text, NULL, NULL)) { |
21306
14f06265d134
Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
848 reset_text_view(pageditor.tv); |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
849 gnt_text_view_append_text_with_flags(pageditor.tv, text, GNT_TEXT_FLAG_NORMAL); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
850 gnt_text_view_scroll(GNT_TEXT_VIEW(pageditor.tv), 0); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
851 g_free(text); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
852 } |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
853 } |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
854 cleanup_pageditor(); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
855 } |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
856 |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18426
diff
changeset
|
857 static void |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18426
diff
changeset
|
858 pager_end_cb(int status, gpointer data) |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18426
diff
changeset
|
859 { |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
860 cleanup_pageditor(); |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18426
diff
changeset
|
861 } |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18426
diff
changeset
|
862 |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
863 static gboolean |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
864 check_for_ext_cb(GntWidget *widget, const char *key, GntTextView *view) |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
865 { |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
866 static const char *pager = NULL; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
867 static const char *editor = NULL; |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
868 char *argv[] = {NULL, NULL, NULL}; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
869 static char path[1024]; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
870 static int len = -1; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
871 FILE *file; |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18426
diff
changeset
|
872 gboolean ret; |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
873 gboolean pg; |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
874 |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
875 if (pager == NULL) { |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
876 pager = gnt_key_translate(gnt_style_get_from_name("pager", "key")); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
877 if (pager == NULL) |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
878 pager = "\033" "v"; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
879 editor = gnt_key_translate(gnt_style_get_from_name("editor", "key")); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
880 if (editor == NULL) |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
881 editor = "\033" "e"; |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
882 len = g_snprintf(path, sizeof(path), "%s" G_DIR_SEPARATOR_S "gnt", g_get_tmp_dir()); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
883 } else { |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
884 g_snprintf(path + len, sizeof(path) - len, "XXXXXX"); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
885 } |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
886 |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
887 if (strcmp(key, pager) == 0) { |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
888 if (g_object_get_data(G_OBJECT(widget), "pager-for") != view) |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
889 return FALSE; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
890 pg = TRUE; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
891 } else if (strcmp(key, editor) == 0) { |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
892 if (g_object_get_data(G_OBJECT(widget), "editor-for") != view) |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
893 return FALSE; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
894 pg = FALSE; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
895 } else { |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
896 return FALSE; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
897 } |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
898 |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
899 file = fdopen(g_mkstemp(path), "wb"); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
900 if (!file) |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
901 return FALSE; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
902 fprintf(file, "%s", view->string->str); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
903 fclose(file); |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
904 |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
905 pageditor.tv = view; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
906 pageditor.file = g_strdup(path); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
907 |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
908 argv[0] = gnt_style_get_from_name(pg ? "pager" : "editor", "path"); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
909 argv[0] = argv[0] ? argv[0] : getenv(pg ? "PAGER" : "EDITOR"); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
910 argv[0] = argv[0] ? argv[0] : (pg ? "less" : "vim"); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
911 argv[1] = path; |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
912 ret = gnt_giveup_console(NULL, argv, NULL, NULL, NULL, NULL, pg ? pager_end_cb : editor_end_cb, NULL); |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18426
diff
changeset
|
913 return ret; |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
914 } |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
915 |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
916 void gnt_text_view_attach_pager_widget(GntTextView *view, GntWidget *pager) |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
917 { |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
918 g_signal_connect(pager, "key_pressed", G_CALLBACK(check_for_ext_cb), view); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
919 g_object_set_data(G_OBJECT(pager), "pager-for", view); |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
920 } |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
921 |
18539
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
922 void gnt_text_view_attach_editor_widget(GntTextView *view, GntWidget *wid) |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
923 { |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
924 g_signal_connect(wid, "key_pressed", G_CALLBACK(check_for_ext_cb), view); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
925 g_object_set_data(G_OBJECT(wid), "editor-for", view); |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
926 } |
1148da95ddeb
Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
927 |