Develop and Download Open Source Software

Browse CVS Repository

Annotation of /shiki/shiki/buffer.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.12 - (hide annotations) (download) (as text)
Thu Nov 30 14:45:49 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.11: +52 -1 lines
File MIME type: text/x-csrc
add undo API

1 aloha 1.1 /* vim: set encoding=utf8:
2     *
3     * buffer.c
4     *
5     * This file is part of Shiki.
6     *
7     * Copyright(C)2006 WAKATSUKI toshihiro
8     *
9     * Permission is hereby granted, free of charge, to any person obtaining a
10     * copy of this software and associated documentation files (the "Software"),
11     * to deal in the Software without restriction, including without limitation
12     * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13     * and/or sell copies of the Software, and to permit persons to whom the
14     * Software is furnished to do so, subject to the following conditions:
15     *
16     * The above copyright notice and this permission notice shall be included in
17     * all copies or substantial portions of the Software.
18     *
19     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25     * SOFTWARE.
26     *
27 aloha 1.12 * $Id: buffer.c,v 1.11 2006/11/29 14:58:27 aloha Exp $
28 aloha 1.1 */
29     #include"shiki.h"
30 aloha 1.2
31 aloha 1.9 ScmClass *ShikiBufferClass;
32     extern void Scm_Init_xyzzylisp(ScmModule *module);
33    
34 aloha 1.7 /* GtkTextBuffer ��������������������� ShikiBuffer ��������������������� */
35     static gint compBuffer(gconstpointer a, gconstpointer b) {
36     return ((ShikiBuffer *)a)->text_buffer == b ? 0 : b - a;
37     }
38 aloha 1.3
39 aloha 1.7 static GList *get_ShikiBufferListElement_By_GtkTextBuffer(GtkTextBuffer *b) {
40     return g_list_find_custom(Shiki_EDITOR_BUFFER_LIST, b, compBuffer);
41 aloha 1.3 }
42 aloha 1.4
43 aloha 1.9 static void buffer_print(ScmObj obj, ScmPort *out, ScmWriteContext *ctx) {
44     GtkTextBuffer *b = SHIKI_BUFFER_UNBOX(obj);
45     GList *l = g_list_find_custom(Shiki_EDITOR_BUFFER_LIST, b, compBuffer);
46     if(l)
47     Scm_Printf(out, "#<buffer: %s>", ((ShikiBuffer *)(l->data))->name);
48     else
49     Scm_Printf(out, "#<deleted buffer: %p>", b);
50     }
51    
52     static void buffer_cleanup(ScmObj obj)
53     {
54     g_object_unref(SHIKI_BUFFER_UNBOX(obj));
55     }
56    
57     /* ������������������������������������������������������������������������������������������ */
58     static gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, GtkTextBuffer *buffer){
59     /* delete-event ������������������������FALSE ��������������������������������������������� */
60     return Shiki_need_buffer_save_p(buffer) && !Shiki_yes_or_no_p("��������������������������������������������������������������������������� ?");
61     }
62    
63     /* ��������������������������������������������� */
64     static void insert_text_handler(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *str, gint len) {
65     /* Undo ��������������������������� */
66     ShikiUndoInfo *undoInfo = g_malloc(sizeof(ShikiUndoInfo));
67     g_return_if_fail(undoInfo != NULL);
68     undoInfo->action = SHIKI_UNDO_INSERT;
69     undoInfo->str = g_strdup(str);
70     undoInfo->strlen = len;
71     undoInfo->start = gtk_text_iter_get_offset(iter);
72     undoInfo->end = undoInfo->start + undoInfo->strlen;
73     Shiki_CURRENT_UNDO_INFO_LIST = g_list_prepend(Shiki_CURRENT_UNDO_INFO_LIST, undoInfo);
74     }
75    
76 aloha 1.12
77     void Shiki_undo() {
78     GtkTextIter start, end;
79     ShikiUndoInfo *undoInfo = g_list_nth_data(Shiki_CURRENT_UNDO_INFO_LIST, 0);
80     if(!undoInfo) {
81     Shiki_msgbox("������������ Undo ���������������");
82     return;
83     }
84     if(undoInfo->action == SHIKI_UNDO_UNDO) {
85     Shiki_CURRENT_UNDO_INFO_LIST = g_list_delete_link(Shiki_CURRENT_UNDO_INFO_LIST, g_list_first(Shiki_CURRENT_UNDO_INFO_LIST));
86     g_free(undoInfo);
87     undoInfo = g_list_nth_data(Shiki_CURRENT_UNDO_INFO_LIST, 0);
88     g_return_if_fail(undoInfo != NULL);
89     Shiki_CURRENT_UNDO_INFO_LIST = g_list_delete_link(Shiki_CURRENT_UNDO_INFO_LIST, g_list_first(Shiki_CURRENT_UNDO_INFO_LIST));
90     g_free(undoInfo->str);
91     g_free(undoInfo);
92     undoInfo = g_list_nth_data(Shiki_CURRENT_UNDO_INFO_LIST, 0);
93     }
94     if(!undoInfo) {
95     Shiki_msgbox("������������ Undo ���������������");
96     return;
97     }
98     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &start, undoInfo->start);
99     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &end, undoInfo->end);
100    
101     if(undoInfo->action == SHIKI_UNDO_INSERT) {
102     Shiki_CURRENT_UNDO_INFO_LIST = g_list_delete_link(Shiki_CURRENT_UNDO_INFO_LIST, g_list_first(Shiki_CURRENT_UNDO_INFO_LIST));
103     gtk_text_buffer_delete(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
104     g_free(undoInfo->str);
105     g_free(undoInfo);
106     undoInfo = g_malloc(sizeof(ShikiUndoInfo));
107     g_return_if_fail(undoInfo != NULL);
108     undoInfo->action = SHIKI_UNDO_UNDO;
109     Shiki_CURRENT_UNDO_INFO_LIST = g_list_prepend(Shiki_CURRENT_UNDO_INFO_LIST, undoInfo);
110     } else if(undoInfo->action == SHIKI_UNDO_DELETE) {
111     Shiki_CURRENT_UNDO_INFO_LIST = g_list_delete_link(Shiki_CURRENT_UNDO_INFO_LIST, g_list_first(Shiki_CURRENT_UNDO_INFO_LIST));
112     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &start, undoInfo->str, -1);
113     g_free(undoInfo->str);
114     g_free(undoInfo);
115     }
116     }
117    
118    
119 aloha 1.9 /* ��������������������������������������������������������������� */
120 aloha 1.11 void Shiki_update_modeline(GtkTextBuffer *buffer) {
121     gtk_label_set_text(GTK_LABEL(Shiki_EDITOR_MODELINE_LABEL), Scm_GetString(SCM_STRING(Scm_EvalCString("(if *mode-line-format* (*mode-line-format*) \"\")", Shiki_CURRENT_BUFFER_ENV))));
122 aloha 1.9 }
123    
124     /* ������������������������������������������������ */
125     static void delete_range_handler(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end) {
126     /* Undo ��������������������������� */
127     ShikiUndoInfo *undoInfo = g_malloc(sizeof(ShikiUndoInfo));
128     g_return_if_fail(undoInfo != NULL);
129     undoInfo->action = SHIKI_UNDO_DELETE;
130     undoInfo->str = gtk_text_buffer_get_text(buffer, start, end, FALSE);
131     undoInfo->start = gtk_text_iter_get_offset(start);
132     undoInfo->end = gtk_text_iter_get_offset(end);
133     undoInfo->strlen = end - start;
134     Shiki_CURRENT_UNDO_INFO_LIST = g_list_prepend(Shiki_CURRENT_UNDO_INFO_LIST, undoInfo);
135     }
136    
137 aloha 1.11 static void cursor_moved_handler() {
138     Shiki_update_modeline(Shiki_CURRENT_TEXT_BUFFER);
139     }
140    
141 aloha 1.9 /* ��������������������������������������� (������������) ��������� */
142     GtkTextBuffer *Shiki_new_buffer_create(gchar *filename) {
143     /*-------------------- ������������������������ ----------------------------------*/
144     /* ShikiBuffer ������������������������������������������������������������������ */
145     ShikiBuffer *tabinfo = g_malloc(sizeof(ShikiBuffer));
146     tabinfo->locale = "Gtk Default (utf8)";
147     tabinfo->undoInfoList = NULL;
148     tabinfo->filename = filename;
149     tabinfo->name = g_path_get_basename(filename);
150 aloha 1.10 tabinfo->tabpage_label = g_strndup(tabinfo->name, 10);
151 aloha 1.9 tabinfo->env = Scm_MakeModule(NULL, FALSE);
152    
153     ShikiBufferClass = Scm_MakeForeignPointerClass(SCM_MODULE(tabinfo->env),
154     "<buffer>", buffer_print, buffer_cleanup,
155     SCM_FOREIGN_POINTER_KEEP_IDENTITY
156     |
157     SCM_FOREIGN_POINTER_MAP_NULL);
158    
159     /* xyzzy lisp ��������������� */
160     Scm_Init_xyzzylisp(SCM_MODULE(tabinfo->env));
161    
162     /* ������������������������������ (������������������������) ��������� */
163     tabinfo->tabpage = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
164     gtk_scrolled_window_set_policy (tabinfo->tabpage, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
165    
166     /* ��������������������������������������������������������������������������������������� */
167     tabinfo->text_view = GTK_TEXT_VIEW(gtk_text_view_new());
168     gtk_text_view_set_wrap_mode(tabinfo->text_view, GTK_WRAP_WORD);
169     tabinfo->text_buffer = gtk_text_view_get_buffer(tabinfo->text_view);
170     gtk_widget_set_size_request(GTK_WIDGET(tabinfo->text_view), 680, 700);
171    
172     gtk_container_add(GTK_CONTAINER(tabinfo->tabpage), GTK_WIDGET(tabinfo->text_view));
173 aloha 1.11 g_signal_connect(tabinfo->text_buffer, "mark_set", G_CALLBACK(cursor_moved_handler), tabinfo->text_view);
174 aloha 1.9 g_signal_connect(tabinfo->text_buffer, "insert-text", G_CALLBACK(insert_text_handler), NULL);
175     g_signal_connect(tabinfo->text_buffer, "delete-range", G_CALLBACK(delete_range_handler), NULL);
176    
177     /* ������������������������������������������������������������������������������������������������������ */
178     tabinfo->delete_handler_id = g_signal_connect(Shiki_EDITOR_WINDOW, "delete_event", G_CALLBACK(delete_event_handler), tabinfo->text_buffer);
179    
180     /* ������������������������ */
181    
182     /* ������������������������������������������������ */
183     gtk_text_buffer_create_tag(tabinfo->text_buffer, "parent_emphasis_background", "background", "green", NULL);
184    
185     /* ������������������������������������������ */
186     gtk_text_buffer_create_tag(tabinfo->text_buffer, "keyword_highlighting", "foreground", "blue", NULL);
187     /* ������ */
188     gtk_text_buffer_create_tag(tabinfo->text_buffer, "function_highlighting", "foreground", "red", NULL);
189     /* ������������ */
190     gtk_text_buffer_create_tag (tabinfo->text_buffer, "comment_highlighting", "foreground", "purple", NULL);
191     /* ��������� */
192     gtk_text_buffer_create_tag (tabinfo->text_buffer, "string_highlighting", "foreground", "orange", NULL);
193     /* ������������������������������������������ */
194     gtk_notebook_append_page(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(tabinfo->tabpage), gtk_label_new(tabinfo->tabpage_label));
195     /* ������������������������������������������������������������������ */
196     Shiki_EDITOR_BUFFER_LIST = g_list_append(Shiki_EDITOR_BUFFER_LIST, tabinfo);
197    
198     gtk_widget_show_all(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
199     /* ��������������������������������� */
200     gtk_notebook_set_current_page(Shiki_EDITOR_NOTEBOOK, g_list_length(Shiki_EDITOR_BUFFER_LIST) - 1);
201     //Shiki_CURRENT_TAB_INFO = tabinfo;
202 aloha 1.11
203     Scm_EvalCString("(set! *mode-line-format* (lambda () (format #f \"--~A- ~A (Gauche Interaction) [GtkDefault (utf8)] L~S:~S \" (if (buffer-modified-p) \"--\" \"**\") (buffer-name (selected-buffer)) (current-line-number) (current-column))))", tabinfo->env);
204 aloha 1.9 return tabinfo->text_buffer;
205     }
206    
207 aloha 1.10 void Shiki_create_file_buffer(const gchar *filename) {
208     gchar *text;
209     gchar *utf8filename = g_locale_to_utf8(filename, -1, NULL, NULL, NULL);
210     GtkTextIter p;
211     ScmObj s;
212    
213     /* g_file_get_contents(filename, &contents, &len, NULL); */
214    
215     /* ������������������������������ */
216     Shiki_new_buffer_create(g_strdup(filename));
217     gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
218    
219     Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*filename*")), SCM_MAKE_STR_COPYING(utf8filename));
220     g_free(utf8filename);
221    
222     Scm_EvalCString("(use gauche.charconv)", Shiki_CURRENT_BUFFER_ENV);
223    
224     /* ������������������������������������������������������������������������������ */
225     s = Scm_EvalCString("(port->string (open-input-conversion-port (open-input-file *filename*) \"*jp\" :owner? #t))", Shiki_CURRENT_BUFFER_ENV);
226     text = Scm_GetString(SCM_STRING(s));
227     if(text)
228     gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER, text, -1);
229     else {
230     /* open-input-conversion-port ������������������������������������������������������
231     * ��������������������������������������������������������������������������� UTF8
232     */
233     gchar *contents;
234     gsize br, bw, len;
235     GError *err = NULL;
236    
237     if(g_file_get_contents(filename, &contents, &len, NULL)) {
238     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
239     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, text, -1);
240     else
241     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, contents, -1);
242     g_free(contents);
243     }
244     }
245    
246     /* ������������������������ */
247     gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
248     /* ������������������������������ */
249     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
250     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
251 aloha 1.11 Shiki_update_modeline(Shiki_CURRENT_TEXT_BUFFER);
252 aloha 1.10 gtk_widget_show_all(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
253     }
254    
255     void Shiki_open_file_dialog() {
256     const gchar *filename = Shiki_file_name_dialog("���������������������");
257    
258     if(!filename) return;
259     Shiki_create_file_buffer(filename);
260     }
261    
262 aloha 1.7 void Shiki_delete_buffer(GtkTextBuffer *buffer) {
263     /* ��������������������������������������������������������������������������������������������������� */
264     /* ���������������������Scheme ������������������������ Gtk ������������������������������������������������ */
265     GList *bufListElem = get_ShikiBufferListElement_By_GtkTextBuffer(buffer);
266     ShikiBuffer *tabInfo = bufListElem->data;
267     gint bufNum = g_list_position(Shiki_EDITOR_BUFFER_LIST, bufListElem);
268    
269     /* ��������� 1 ��������������������������������������������������� */
270     if(g_list_length(Shiki_EDITOR_BUFFER_LIST) == 1)
271 aloha 1.4 return;
272 aloha 1.7 /* ��������������������������������������������������������������������������������������������� */
273     g_signal_handler_disconnect(Shiki_EDITOR_WINDOW, tabInfo->delete_handler_id);
274     Shiki_EDITOR_BUFFER_LIST = g_list_delete_link(Shiki_EDITOR_BUFFER_LIST, bufListElem);
275     gtk_widget_destroy(GTK_WIDGET(tabInfo->tabpage));
276     g_free(tabInfo->tabpage_label);
277     g_free(tabInfo->name);
278     g_free(tabInfo->filename);
279     g_free(tabInfo);
280     gtk_notebook_remove_page(Shiki_EDITOR_NOTEBOOK, bufNum);
281     /* ��������������� */
282     gtk_widget_queue_draw(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
283     }
284    
285     GtkTextBuffer *Shiki_find_buffer(const gchar *name) {
286     GList *l;
287     for(l = Shiki_EDITOR_BUFFER_LIST; l != NULL; l = l->next)
288     if(strcmp(((ShikiBuffer *)l->data)->name, name) == 0)
289     return ((ShikiBuffer *)l->data)->text_buffer;
290     return NULL;
291     }
292    
293     gchar *Shiki_buffer_substring(gint start, gint end) {
294     if(start >= end)
295     return NULL;
296     else {
297     GtkTextIter s, e;
298     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &s, start);
299     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &e, end);
300    
301     return gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &s, &e, FALSE);
302     }
303     }
304    
305     void Shiki_delete_region(gint start, gint end) {
306     if(start >= end)
307     return;
308     else {
309     GtkTextIter s, e;
310     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &s, start);
311     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &e, end);
312 aloha 1.4
313 aloha 1.7 return gtk_text_buffer_delete(Shiki_CURRENT_TEXT_BUFFER, &s, &e);
314     }
315 aloha 1.4 }
316    
317     gint Shiki_point() {
318     GtkTextIter p;
319     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
320     return gtk_text_iter_get_offset(&p);
321     }
322    
323     gint Shiki_point_max() {
324     GtkTextIter p;
325     gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
326     return gtk_text_iter_get_offset(&p);
327     }
328    
329     gint Shiki_point_min() {
330     return 0;
331     }
332    
333     void Shiki_goto_char(gint offset) {
334     GtkTextIter p;
335     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &p, offset);
336     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
337     }
338    
339     void Shiki_forward_char() {
340     GtkTextIter p;
341     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
342     gtk_text_iter_forward_char(&p);
343     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
344     }
345    
346     void Shiki_backward_char() {
347     GtkTextIter p;
348     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
349     gtk_text_iter_backward_char(&p);
350     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
351     }
352    
353     void Shiki_goto_line(gint line) {
354     GtkTextIter p;
355     gtk_text_buffer_get_iter_at_line(Shiki_CURRENT_TEXT_BUFFER, &p, line);
356     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
357     }
358    
359     void Shiki_goto_bol() {
360     GtkTextIter p;
361     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
362     gtk_text_buffer_get_iter_at_line_offset(Shiki_CURRENT_TEXT_BUFFER, &p, gtk_text_iter_get_line(&p), 0);
363     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
364     }
365    
366     void Shiki_goto_eol() {
367     GtkTextIter p;
368     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
369     gtk_text_iter_forward_to_line_end(&p);
370     gtk_text_iter_backward_char(&p);
371     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
372     }
373 aloha 1.5
374 aloha 1.7 void Shiki_forward_line(gint count) {
375     GtkTextIter p;
376     gint i;
377     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
378    
379     if(count >= 0) {
380     for(i = count; i != 0; i--)
381     gtk_text_view_forward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
382     } else {
383     for(i = count; i != 0; i++)
384     gtk_text_view_backward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
385     }
386     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
387 aloha 1.5 }
388    
389     const char *Shiki_buffer_name(GtkTextBuffer *buffer) {
390     GList *l = get_ShikiBufferListElement_By_GtkTextBuffer(buffer);
391     if(l)
392     return ((ShikiBuffer *)(l->data))->name;
393     else
394     return NULL;
395     }
396    
397 aloha 1.6 gboolean Shiki_deleted_buffer_p(GtkTextBuffer *buffer) {
398     GList *l = get_ShikiBufferListElement_By_GtkTextBuffer(buffer);
399     if(l)
400     return FALSE;
401     else
402     return TRUE;
403     }
404    
405 aloha 1.5 GtkTextBuffer *Shiki_get_next_buffer(GtkTextBuffer *buffer) {
406     GList *l = get_ShikiBufferListElement_By_GtkTextBuffer(buffer);
407     if(l && l->next)
408     return ((ShikiBuffer *)(l->next->data))->text_buffer;
409     else
410     return NULL;
411     }
412    
413     GtkTextBuffer *Shiki_get_previous_buffer(GtkTextBuffer *buffer) {
414     GList *l = get_ShikiBufferListElement_By_GtkTextBuffer(buffer);
415     if(l && l->prev)
416     return ((ShikiBuffer *)(l->prev->data))->text_buffer;
417     else
418     return NULL;
419     }
420    
421     ScmObj Shiki_buffer_list() {
422     GList *l;
423     GtkTextBuffer *b;
424     ScmObj bl = SCM_NIL;
425    
426     for(l = Shiki_EDITOR_BUFFER_LIST; l != NULL; l = l->next) {
427     b= ((ShikiBuffer *)(l->data))->text_buffer;
428     bl = Scm_Cons(SHIKI_BUFFER_BOX(g_object_ref(b)), bl);
429     }
430     return bl;
431     }
432 aloha 1.7
433     void Shiki_erase_buffer(GtkTextBuffer *buffer) {
434     GtkTextIter start, end;
435     gtk_text_buffer_get_start_iter(buffer, &start);
436     gtk_text_buffer_get_end_iter(buffer, &end);
437     gtk_text_buffer_delete(buffer, &start, &end);
438     }
439    
440     const gchar *Shiki_file_name_dialog(const gchar *msg) {
441    
442     GtkWidget *dialog = gtk_file_selection_new(msg);
443     gint resp = gtk_dialog_run(GTK_DIALOG(dialog));
444     const gchar *filename = NULL;
445    
446     if(resp == GTK_RESPONSE_OK)
447     filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog));
448    
449     gtk_widget_destroy(dialog);
450     return filename;
451     }
452    
453     gboolean Shiki_yes_or_no_p(const gchar *msg) {
454     GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(Shiki_EDITOR_WINDOW),
455     GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION,
456     GTK_BUTTONS_YES_NO, msg);
457 aloha 1.9 gint resp;
458     gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
459     resp = gtk_dialog_run(GTK_DIALOG(dialog));
460     gtk_widget_destroy(dialog);
461     if(GTK_RESPONSE_YES == resp)
462     return TRUE;
463     return FALSE;
464     }
465    
466     gboolean Shiki_no_or_yes_p(const gchar *msg) {
467     GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(Shiki_EDITOR_WINDOW),
468     GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION,
469     GTK_BUTTONS_YES_NO, msg);
470     gint resp;
471     gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_NO);
472     resp = gtk_dialog_run(GTK_DIALOG(dialog));
473 aloha 1.7 gtk_widget_destroy(dialog);
474     if(GTK_RESPONSE_YES == resp)
475     return TRUE;
476     return FALSE;
477     }
478 aloha 1.8
479     gboolean Shiki_need_buffer_save_p(GtkTextBuffer *buffer) {
480     return gtk_text_buffer_get_modified(buffer);
481     }
482    
483     /* ������������ */
484     void Shiki_kill_buffer(GtkTextBuffer *buffer) {
485     if(!Shiki_need_buffer_save_p(buffer) || Shiki_yes_or_no_p("��������������������������������������������������������������������������� ?"))
486     Shiki_delete_buffer(buffer);
487     }
488 aloha 1.12
489     void Shiki_msgbox(const gchar *msg) {
490     GtkWidget *dialog;
491     dialog = gtk_message_dialog_new(GTK_WINDOW(Shiki_EDITOR_WINDOW),
492     GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,msg);
493     gtk_dialog_run(GTK_DIALOG(dialog));
494     gtk_widget_destroy(dialog);
495     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26