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