Develop and Download Open Source Software

Browse CVS Repository

Annotation of /shiki/shiki/shiki.c

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


Revision 1.34 - (hide annotations) (download) (as text)
Fri Nov 17 13:04:08 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.33: +16 -13 lines
File MIME type: text/x-csrc
add independent scheme environment for each tabpage buffer

1 aloha 1.1 /* vim: set encoding=utf8:
2     *
3     * shiki.c
4     *
5     * Copyright(C)2006 WAKATSUKI toshihiro
6     *
7     * Permission is hereby granted, free of charge, to any person obtaining a
8     * copy of this software and associated documentation files (the "Software"),
9     * to deal in the Software without restriction, including without limitation
10     * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11     * and/or sell copies of the Software, and to permit persons to whom the
12     * Software is furnished to do so, subject to the following conditions:
13     *
14     * The above copyright notice and this permission notice shall be included in
15     * all copies or substantial portions of the Software.
16     *
17     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23     * SOFTWARE.
24     *
25 aloha 1.34 * $Id: shiki.c,v 1.33 2006/11/16 16:15:34 aloha Exp $
26 aloha 1.1 */
27    
28     #include<gauche.h>
29     #include<gtk/gtk.h>
30     #include<gdk/gdkkeysyms.h>
31    
32 aloha 1.6 static gint editor_indent_width = 2;
33 aloha 1.7
34 aloha 1.32 /* Undo/Redo ������������������ */
35     typedef enum {SHIKI_UNDO_INSERT, SHIKI_UNDO_DELETE} ShikiAction;
36    
37     typedef struct {
38     ShikiAction action;
39     gchar *str;
40     gint strlen;
41     gint start;
42     gint end;
43     } ShikiUndoInfo;
44    
45 aloha 1.17 /* ��������������������������������������������� */
46 aloha 1.16 typedef struct {
47 aloha 1.20 GtkScrolledWindow *tabpage; /* ������ */
48     gchar *tabpage_label; /* ��������� (���������������) ������ */
49     GtkTextView *text_view; /* ��������������� */
50     GtkTextBuffer *text_buffer; /* ��������������������������������� */
51     gchar *filename; /* ������������������������������ */
52 aloha 1.32 GList *undoInfoList; /* ��������������������������������������� */
53 aloha 1.20 ScmObj env; /* ��������������������������� Scheme ������ */
54     guint delete_handler_id; /* ��������������������������������������������� ID */
55 aloha 1.16 } ShikiTabInfo;
56    
57 aloha 1.17 /* ������������������������������������������������������������������������������������������������������������������������������ */
58 aloha 1.16 struct {
59 aloha 1.17 GtkWidget *editor_window;
60 aloha 1.31 GtkClipboard *clipboard;
61 aloha 1.26 GtkNotebook *notebook;
62 aloha 1.17 GtkWidget *statusbar;
63     GtkWidget *modeline_label;
64     GList *tabInfoList;
65     gint current_tabpage_num;
66     ShikiTabInfo *current_tabpage_info;
67 aloha 1.16 } shiki_editor;
68    
69 aloha 1.25 /* ��������������������������������������������� */
70 aloha 1.32 #define Shiki_EDITOR_WINDOW shiki_editor.editor_window
71     #define Shiki_EDITOR_CLIPBOARD shiki_editor.clipboard
72     #define Shiki_EDITOR_NOTEBOOK shiki_editor.notebook
73     #define Shiki_EDITOR_STATUSBAR shiki_editor.statusbar
74     #define Shiki_EDITOR_MODELINE_LABEL shiki_editor.modeline_label
75     #define Shiki_EDITOR_TAB_INFO_LIST shiki_editor.tabInfoList
76 aloha 1.25
77     /* ��������������������������������������������������������������������������������������� */
78 aloha 1.32 #define Shiki_CURRENT_TAB_NUM shiki_editor.current_tabpage_num
79     #define Shiki_CURRENT_TAB_INFO shiki_editor.current_tabpage_info
80     #define Shiki_CURRENT_UNDO_INFO_LIST (shiki_editor.current_tabpage_info)->undoInfoList
81     #define Shiki_CURRENT_TAB (shiki_editor.current_tabpage_info)->tabpage
82     #define Shiki_CURRENT_TAB_TITLE (shiki_editor.current_tabpage_info)->tabpage_label
83     #define Shiki_CURRENT_TEXT_VIEW (shiki_editor.current_tabpage_info)->text_view
84     #define Shiki_CURRENT_TEXT_BUFFER (shiki_editor.current_tabpage_info)->text_buffer
85     #define Shiki_CURRENT_FILENAME (shiki_editor.current_tabpage_info)->filename
86 aloha 1.34 #define Shiki_CURRENT_BUFFER_ENV (shiki_editor.current_tabpage_info)->env
87 aloha 1.10
88 aloha 1.17 /* ������������������ */
89 aloha 1.25
90 aloha 1.27 /* ������������������������ : ���������������ShikiTabInfo ������������������������������������������������������������������ 2 ������������������������������������������ (������������������) */
91     static void append_tabpage(gchar *filename);
92     static void remove_tabpage();
93    
94 aloha 1.33 /* foo_bar_handler() ������������������������������������������������������ */
95     static void append_default_tabpage_handler();
96    
97 aloha 1.25 /* ������������������ */
98 aloha 1.27 static void open_file(gchar *filename);
99     static void open_file_handler();
100     static void save_file();
101     static void save_file_as();
102 aloha 1.25 static gchar *get_filename_from_dialog(const gchar *msg);
103    
104     /* ������������������������������ */
105     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer);
106     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer);
107 aloha 1.17 static void clear_current_buffer();
108 aloha 1.33 static void undo();
109 aloha 1.25
110 aloha 1.32 static void insert_text_handler(GtkTextBuffer *buffer, GtkTextIter *p, gchar *str, gint len);
111     static void delete_range_handler(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end);
112    
113 aloha 1.25 /* ������������������ */
114 aloha 1.17 static gint get_current_line_number(GtkTextBuffer *buffer);
115     static void update_modeline_label();
116     static void text_buffer_cursor_moved_handler();
117 aloha 1.25
118     /* ������ */
119 aloha 1.17 static void really_quit_dialog_yes(GtkWidget *widget, gboolean *flag);
120     static void really_quit_dialog_no(GtkWidget *widget, gint *flag);
121     static gboolean not_yet_save_changes_really_quit(GtkTextBuffer *buffer);
122 aloha 1.27 static gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, GtkTextBuffer *buffer);
123 aloha 1.25
124     /* Gauche ��� S ��������������������������������� */
125 aloha 1.17 static gchar *eval_cstring_by_gauche(gchar *s);
126 aloha 1.25 static gchar *load_cstring_by_gauche(gchar *s);
127     static void load_buffer_by_gauche();
128 aloha 1.27 static void load_region_by_gauche();
129     static void load_scheme_file_by_gauche();
130 aloha 1.17 static gboolean is_kakko_or_kokka(gunichar ch, gpointer);
131 aloha 1.29 static gboolean is_kakko(gunichar ch, gpointer);
132 aloha 1.17 static gboolean is_kokka(gunichar ch, gpointer);
133 aloha 1.30 static gboolean search_sexp(GtkTextIter *start, GtkTextIter *end);
134     static gboolean search_sexp_kokka(GtkTextIter *end);
135     static gboolean search_last_sexp(GtkTextIter *start, GtkTextIter *end);
136 aloha 1.29 static gboolean search_last_sexp_kakko(GtkTextIter *start);
137 aloha 1.17 static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer);
138 aloha 1.25
139     /* ������ */
140     static void select_font();
141     static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog);
142 aloha 1.18 static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) ;
143 aloha 1.17 static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook);
144 aloha 1.27 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook);
145 aloha 1.25
146     /* ��������������� ������������ ������ */
147 aloha 1.17 static void forward_current_buffer();
148     static void backward_current_buffer();
149     static void line_forward_current_buffer();
150     static void line_backward_current_buffer();
151 aloha 1.25
152     /* ������������������������ */
153 aloha 1.22 static gboolean signal_key_press_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid);
154     static gboolean signal_key_release_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid);
155 aloha 1.25
156     /* ������������������ */
157 aloha 1.27 static void open_online_help();
158 aloha 1.25 static void about_this_application();
159    
160 aloha 1.27 /* ������������������������ */
161 aloha 1.21 static void shiki_editor_window_init(int argc, char **argv);
162 aloha 1.14
163 aloha 1.32 /* ��������������������������������������������� */
164     static void insert_text_handler(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *str, gint len) {
165     /* Undo ��������������������������� */
166     ShikiUndoInfo *undoInfo = g_malloc(sizeof(ShikiUndoInfo));
167     g_return_if_fail(undoInfo != NULL);
168     undoInfo->action = SHIKI_UNDO_INSERT;
169     undoInfo->str = g_strdup(str);
170     undoInfo->strlen = len;
171     undoInfo->start = gtk_text_iter_get_offset(iter);
172     undoInfo->end = undoInfo->start + undoInfo->strlen;
173     Shiki_CURRENT_UNDO_INFO_LIST = g_list_prepend(Shiki_CURRENT_UNDO_INFO_LIST, undoInfo);
174     g_print("insert : %s, len : %d, start : %d, end : %d\n", undoInfo->str, undoInfo->strlen, undoInfo->start, undoInfo->end);
175     }
176    
177     /* ������������������������������������������������ */
178     static void delete_range_handler(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end) {
179     /* Undo ��������������������������� */
180     ShikiUndoInfo *undoInfo = g_malloc(sizeof(ShikiUndoInfo));
181     g_return_if_fail(undoInfo != NULL);
182     undoInfo->action = SHIKI_UNDO_DELETE;
183     undoInfo->str = gtk_text_buffer_get_text(buffer, start, end, FALSE);
184     undoInfo->start = gtk_text_iter_get_offset(start);
185     undoInfo->end = gtk_text_iter_get_offset(end);
186     undoInfo->strlen = end - start;
187     Shiki_CURRENT_UNDO_INFO_LIST = g_list_prepend(Shiki_CURRENT_UNDO_INFO_LIST, undoInfo);
188     g_print("delete : %s %d\n", undoInfo->str, undoInfo->strlen);
189     }
190    
191     /* ������������������������������������������������������������ */
192     static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) {
193     /* ��������������������������������������������������������������������� */
194     Shiki_CURRENT_TAB_INFO = (ShikiTabInfo *)g_list_nth_data(Shiki_EDITOR_TAB_INFO_LIST, pagenum);
195    
196     /* ������������������������������������ */
197     Shiki_CURRENT_TAB_NUM = pagenum;
198    
199     /* ������������������������������������������������������ */
200     if(!Shiki_CURRENT_TAB_INFO) return;
201     gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), Shiki_CURRENT_FILENAME);
202    
203     update_modeline_label();
204     }
205    
206 aloha 1.33 static void undo() {
207     g_print("Undo\n");
208     GtkTextIter start, end;
209     ShikiUndoInfo *undoInfo = g_list_nth_data(Shiki_CURRENT_UNDO_INFO_LIST, 0);
210     if(!undoInfo) {
211     g_print("������������ Undo ���������������\n");
212     return;
213     }
214     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &start, undoInfo->start);
215     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &end, undoInfo->end);
216    
217     if(undoInfo->action == SHIKI_UNDO_INSERT) {
218     Shiki_CURRENT_UNDO_INFO_LIST = g_list_delete_link(Shiki_CURRENT_UNDO_INFO_LIST, g_list_first(Shiki_CURRENT_UNDO_INFO_LIST));
219     gtk_text_buffer_delete(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
220     g_free(undoInfo->str);
221     g_free(undoInfo);
222     } else if(undoInfo->action == SHIKI_UNDO_DELETE) {
223     Shiki_CURRENT_UNDO_INFO_LIST = g_list_delete_link(Shiki_CURRENT_UNDO_INFO_LIST, g_list_first(Shiki_CURRENT_UNDO_INFO_LIST));
224     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &start, undoInfo->str, -1);
225     g_free(undoInfo->str);
226     g_free(undoInfo);
227     }
228    
229     }
230    
231 aloha 1.32 /* ��������������������� */
232     static gboolean signal_key_press_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
233     GtkTextIter start, end;
234    
235     /* ������������������������������������ */
236     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &start);
237     gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &end);
238     gtk_text_buffer_remove_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
239    
240     if(event->state & GDK_CONTROL_MASK && event->state & GDK_MOD1_MASK) {
241     switch(event->keyval) {
242     case GDK_at : /* C-M-SPC */
243     { GtkTextIter start, end;
244     if(!search_sexp(&start, &end)) return FALSE;
245     gtk_text_buffer_select_range(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
246     }
247     break;
248     case GDK_space : /* C-M-SPC */
249     { GtkTextIter start, end;
250     if(!search_last_sexp(&start, &end)) return FALSE;
251     gtk_text_buffer_select_range(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
252     }
253     break;
254     }
255     } else if(event->state & GDK_CONTROL_MASK) {
256     switch(event->keyval) {
257     case GDK_f : /* Ctrl + f : forward */
258     forward_current_buffer();
259     break;
260     case GDK_b : /* Ctrl + b : backward */
261     backward_current_buffer();
262     break;
263     case GDK_n : /* Ctrl + n : next line */
264     line_forward_current_buffer();
265     break;
266     case GDK_p : /* Ctrl + p : previous line */
267     line_backward_current_buffer();
268     break;
269     case GDK_h :
270     { GtkTextIter p;
271     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
272     gtk_text_buffer_backspace(Shiki_CURRENT_TEXT_BUFFER, &p, FALSE, TRUE);
273     }
274     break;
275    
276     case GDK_e : /* Ctrl + e : eval-expression */
277     {
278     gchar *code;
279     GtkTextIter start, end;
280    
281     if(!search_sexp(&start, &end)) return FALSE;
282    
283     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
284     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, "\n\n", -1);
285     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, eval_cstring_by_gauche(code), -1);
286     g_free(code);
287     }
288     break;
289    
290     case GDK_j : /* Ctrl + j : eval-last-sexp */
291     {
292     gchar *code;
293     GtkTextIter start, end;
294    
295     if(!search_last_sexp(&start, &end)) return FALSE;
296    
297     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
298     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, "\n\n", -1);
299     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, eval_cstring_by_gauche(code), -1);
300     g_free(code);
301     }
302     break;
303    
304     case GDK_underscore : /* Ctrl + _ : Undo */
305 aloha 1.33 undo();
306 aloha 1.32 break;
307    
308     case GDK_t : /* Ctrl + t : ��������������� */
309 aloha 1.33 append_default_tabpage_handler();
310 aloha 1.32 break;
311    
312     case GDK_k : /* Ctrl + k : ������������������ */
313     remove_tabpage();
314     break;
315    
316     case GDK_w : /* Ctrl + w : ��������� */
317     gtk_text_buffer_cut_clipboard(Shiki_CURRENT_TEXT_BUFFER, Shiki_EDITOR_CLIPBOARD, TRUE);
318     break;
319    
320     case GDK_y : /* Ctrl + y : ��������� */
321     {GtkTextIter p;
322     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
323     gtk_text_buffer_paste_clipboard(Shiki_CURRENT_TEXT_BUFFER, Shiki_EDITOR_CLIPBOARD, &p, TRUE);
324     }
325     break;
326     }
327     }
328     return FALSE;
329     }
330    
331    
332 aloha 1.23 /* ��������������������������������������� (������������) ��������� */
333 aloha 1.27 static void append_tabpage(gchar *filename) {
334 aloha 1.24 /*-------------------- ������������������������ ----------------------------------*/
335     /* ShikiTabInfo ������������������������������������������������������������������ */
336 aloha 1.34 ShikiTabInfo *tabinfo = g_malloc(sizeof(ShikiTabInfo));
337     tabinfo->undoInfoList = NULL;
338     tabinfo->filename = filename;
339 aloha 1.23 tabinfo->tabpage_label = g_path_get_basename(filename);
340 aloha 1.34 tabinfo->env = Scm_MakeModule(NULL, FALSE);
341    
342     g_return_if_fail(tabinfo->env != SCM_FALSE);
343 aloha 1.24
344     /* ������������������������������ (������������������������) ��������� */
345     tabinfo->tabpage = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
346     gtk_scrolled_window_set_policy (tabinfo->tabpage, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
347    
348     /* ��������������������������������������������������������������������������������������� */
349     tabinfo->text_view = GTK_TEXT_VIEW(gtk_text_view_new());
350     tabinfo->text_buffer = gtk_text_view_get_buffer(tabinfo->text_view);
351 aloha 1.33
352 aloha 1.24 gtk_container_add(GTK_CONTAINER(tabinfo->tabpage), GTK_WIDGET(tabinfo->text_view));
353     gtk_widget_set_size_request(GTK_WIDGET(tabinfo->text_view), 500, 500);
354     g_signal_connect(tabinfo->text_buffer, "mark_set", G_CALLBACK(text_buffer_cursor_moved_handler), tabinfo->text_view);
355 aloha 1.32 g_signal_connect(tabinfo->text_buffer, "insert-text", G_CALLBACK(insert_text_handler), NULL);
356     g_signal_connect(tabinfo->text_buffer, "delete-range", G_CALLBACK(delete_range_handler), NULL);
357    
358 aloha 1.24 /* ������������������������������������������������������������������������������������������������������ */
359     tabinfo->delete_handler_id = g_signal_connect(Shiki_EDITOR_WINDOW, "delete_event", G_CALLBACK(delete_event_handler), tabinfo->text_buffer);
360 aloha 1.33
361 aloha 1.24 /* ������������������������ */
362     /* ������������������������������������������������ */
363     gtk_text_buffer_create_tag (tabinfo->text_buffer, "parent_emphasis_background", "background", "green", NULL);
364    
365     /* ������������������������������������������ */
366 aloha 1.27 gtk_notebook_append_page(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(tabinfo->tabpage), gtk_label_new(tabinfo->tabpage_label));
367 aloha 1.24 /* ������������������������������������������������������������������ */
368 aloha 1.23 Shiki_EDITOR_TAB_INFO_LIST = g_list_append(Shiki_EDITOR_TAB_INFO_LIST, tabinfo);
369 aloha 1.32
370 aloha 1.27 gtk_widget_show_all(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
371 aloha 1.24 /* ��������������������������������� */
372 aloha 1.27 gtk_notebook_set_current_page(Shiki_EDITOR_NOTEBOOK, g_list_length(Shiki_EDITOR_TAB_INFO_LIST) - 1);
373 aloha 1.23 }
374    
375 aloha 1.33 static void append_default_tabpage_handler() {
376     append_tabpage(g_strdup("*scratch*"));
377     }
378    
379 aloha 1.23 /* ������������������������������������������ (������������) ��������� */
380 aloha 1.27 static void remove_tabpage() {
381 aloha 1.23 /* ��������� 1 ��������������������������������������������������� */
382     if(g_list_length(Shiki_EDITOR_TAB_INFO_LIST) == 1)
383     return;
384     if(!not_yet_save_changes_really_quit(Shiki_CURRENT_TEXT_BUFFER)) {
385     /* ��������������������������������������������������������������������������������������������� */
386     g_signal_handler_disconnect(Shiki_EDITOR_WINDOW, (Shiki_CURRENT_TAB_INFO)->delete_handler_id);
387     /* ������������������������ */
388     gtk_widget_destroy(GTK_WIDGET(Shiki_CURRENT_TEXT_VIEW));
389     /* ������������������������������������������ */
390     g_free(Shiki_CURRENT_TAB_TITLE);
391     g_free(Shiki_CURRENT_FILENAME);
392     Shiki_EDITOR_TAB_INFO_LIST = g_list_delete_link(Shiki_EDITOR_TAB_INFO_LIST, g_list_nth(Shiki_EDITOR_TAB_INFO_LIST, Shiki_CURRENT_TAB_NUM));
393     g_free(Shiki_CURRENT_TAB_INFO);
394    
395     /* ������������������������������������ */
396     Shiki_CURRENT_TAB_INFO = g_list_nth_data(Shiki_EDITOR_TAB_INFO_LIST, Shiki_CURRENT_TAB_NUM);
397 aloha 1.27 gtk_notebook_remove_page(Shiki_EDITOR_NOTEBOOK, Shiki_CURRENT_TAB_NUM);
398 aloha 1.23 /* ��������������������������������������� */
399 aloha 1.27 gtk_widget_queue_draw(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
400 aloha 1.23 }
401     }
402    
403 aloha 1.15 /* ������������������������������ */
404     static void clear_current_buffer() {
405     GtkTextIter start, end;
406 aloha 1.16 gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &start);
407     gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &end);
408     gtk_text_buffer_delete(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
409 aloha 1.15 }
410    
411 aloha 1.14 /* ������������������������������������ */
412     static void load_buffer_by_gauche() {
413     GtkTextIter p;
414 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
415     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
416     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(get_all_buffer_contents(Shiki_CURRENT_TEXT_BUFFER)), -1);
417 aloha 1.14 }
418    
419     /* ������������������������ */
420 aloha 1.27 static void load_scheme_file_by_gauche() {
421 aloha 1.14 gchar *contents, *text;
422     gsize br, bw, len;
423     GError *err = NULL;
424     gchar *filename = get_filename_from_dialog("File Selection");
425     GtkTextIter p;
426    
427     if(!filename) return;
428 aloha 1.33
429 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
430     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
431 aloha 1.14
432     if(g_file_get_contents(filename, &contents, &len, NULL)) {
433     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
434 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(text), -1);
435 aloha 1.14 else
436 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(contents), -1);
437 aloha 1.14 }
438     g_free(text); g_free(contents); g_free(filename);
439     }
440    
441 aloha 1.13 /* gauche ������������������������������������ */
442     static gchar *load_cstring_by_gauche(gchar *s) {
443     gchar *msg;
444    
445     ScmObj result, error;
446     /* ��������������������������������� */
447     ScmObj is = Scm_MakeInputStringPort(SCM_STRING(SCM_MAKE_STR(s)), TRUE);
448     /* ������������������������������ */
449     ScmObj os = Scm_MakeOutputStringPort(TRUE);
450    
451 aloha 1.34 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*input*")), is);
452     Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
453 aloha 1.13 /* Scheme ��������������������������������������������������������������������������������� S ��������������������������������������������������������������������������� *error* ������������������ */
454 aloha 1.34 result = Scm_EvalCString("(guard (e (else (set! *error* e) #f)) (eval (load-from-port *input*) (current-module)))", SCM_OBJ(Shiki_CURRENT_BUFFER_ENV));
455 aloha 1.13
456 aloha 1.34 error = Scm_GlobalVariableRef(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
457 aloha 1.13
458     /* ��������������������������������������������������������� */
459     if (!SCM_FALSEP(error))
460     Scm_Write(error, os, SCM_WRITE_DISPLAY);
461     else
462     Scm_Write(result, os, SCM_WRITE_DISPLAY);
463    
464     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
465     /* ������������������ */
466     Scm_ClosePort(SCM_PORT(is));
467     Scm_ClosePort(SCM_PORT(os));
468    
469     return msg;
470     }
471    
472 aloha 1.12 static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog) {
473     gchar *font_name = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (font_dialog));
474     if(font_name) {
475     GtkRcStyle *style = gtk_rc_style_new ();
476     pango_font_description_free(style->font_desc);
477     style->font_desc = pango_font_description_from_string(font_name);
478 aloha 1.16 gtk_widget_modify_style (GTK_WIDGET(Shiki_CURRENT_TEXT_VIEW), style);
479 aloha 1.12 g_free (font_name);
480     }
481     }
482    
483 aloha 1.14 /* ������������������������������������������������������ */
484 aloha 1.12 static void select_font(){
485     GtkWidget *font_dialog = gtk_font_selection_dialog_new("Font Selection Dialog");
486     g_signal_connect (GTK_FONT_SELECTION_DIALOG (font_dialog)->ok_button, "clicked", G_CALLBACK(font_selection_ok), font_dialog);
487     gtk_dialog_run(GTK_DIALOG(font_dialog));
488     gtk_widget_destroy(font_dialog);
489     }
490    
491 aloha 1.11 /* ������������������������������������������ */
492     static void about_this_application() {
493     GtkAboutDialog *about = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
494     const gchar *authors[] = {
495 aloha 1.23 "������������ (���������) <alohakun@gmail.com>\n",
496     "Contribute : tkng ������",
497     "(http://d.hatena.ne.jp/tkng/20061113)", NULL
498 aloha 1.11 };
499     gtk_about_dialog_set_authors(about, authors);
500     gtk_about_dialog_set_copyright(about, "Copyright(C)2006 WAKATSUKI Toshihiro");
501     gtk_about_dialog_set_name(about, "��� (SHIKI)");
502     gtk_about_dialog_set_website_label(about, "���������30������������������������������������������������������������Blog");
503     gtk_about_dialog_set_website(about, "http://alohakun.blog7.fc2.com/blog-category-29.html");
504     gtk_dialog_run(GTK_DIALOG(about));
505     gtk_widget_destroy(GTK_WIDGET(about));
506     }
507    
508 aloha 1.10 /* ��������������������������������������������������������������� */
509     static gint get_current_line_number(GtkTextBuffer *b) {
510     GtkTextIter p;
511     gtk_text_buffer_get_iter_at_mark(b, &p, gtk_text_buffer_get_insert(b));
512     return gtk_text_iter_get_line(&p) + 1;
513     }
514    
515     /* ��������������������������������������������������������������� */
516     static void update_modeline_label() {
517 aloha 1.16 gchar* basename = g_path_get_basename(Shiki_CURRENT_TAB_TITLE);
518 aloha 1.11 gchar* l = g_strdup_printf("-E:%s %-10s (Gauche Interaction)--L%d--------------------------------------",
519 aloha 1.16 gtk_text_buffer_get_modified(Shiki_CURRENT_TEXT_BUFFER) ? "**" : "--",
520     basename, get_current_line_number(Shiki_CURRENT_TEXT_BUFFER));
521     gtk_label_set_text(GTK_LABEL(Shiki_EDITOR_MODELINE_LABEL), l);
522 aloha 1.10 g_free(l); g_free(basename);
523     }
524    
525     static void text_buffer_cursor_moved_handler(){
526     update_modeline_label();
527     }
528 aloha 1.1
529     /* ��������������������������������������������������������������� */
530     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer) {
531     GtkTextIter start, end;
532     gtk_text_buffer_get_start_iter(buffer, &start);
533     gtk_text_buffer_get_end_iter(buffer, &end);
534     return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
535     }
536    
537     /* buffer ������������������������ filename ��������� */
538     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer) {
539     gchar *contents, *text;
540     gsize br, bw;
541     GError *err = NULL;
542    
543     if(!filename) return FALSE;
544     contents = get_all_buffer_contents(buffer);
545     text = g_locale_from_utf8(contents, -1, &br, &bw, &err);
546     /* ��������������������������������� */
547     g_file_set_contents(filename, text, -1, NULL);
548     gtk_text_buffer_set_modified(buffer, FALSE);
549 aloha 1.10 update_modeline_label();
550 aloha 1.1 g_free(contents); g_free(text);
551     return TRUE;
552     }
553    
554     /* ������������������������������������������������������msg ������������������������������������ */
555     static gchar *get_filename_from_dialog(const gchar *msg) {
556    
557     GtkWidget *dialog = gtk_file_selection_new(msg);
558     int resp = gtk_dialog_run(GTK_DIALOG(dialog));
559     gchar *filename = NULL;
560    
561     /* gtk_file_selection_get_filename ������������������������������������������������������������������������������������������������������������������������������ */
562     if(resp == GTK_RESPONSE_OK)
563     filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog)));
564    
565     gtk_widget_destroy(dialog);
566     return filename;
567     }
568    
569     /* ��������������������������������������������������������������������� */
570 aloha 1.27 static void save_file() {
571 aloha 1.1
572 aloha 1.22 /* ��������������������������������������� */
573     if(g_ascii_strcasecmp("*help*", Shiki_CURRENT_TAB_TITLE) == 0) return;
574 aloha 1.33
575 aloha 1.1 /* ������������������������������������ */
576 aloha 1.16 if(!gtk_text_buffer_get_modified(Shiki_CURRENT_TEXT_BUFFER)) return;
577 aloha 1.1
578     /* ������������������������������������������������������������������������������������������������������ */
579 aloha 1.16 if(g_ascii_strcasecmp("*scratch*", Shiki_CURRENT_TAB_TITLE) == 0) {
580 aloha 1.7 gchar *filename = get_filename_from_dialog("Save File As ...");
581     if(!filename) return;
582 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
583 aloha 1.27 gtk_notebook_set_tab_label_text(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
584 aloha 1.16 gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), filename);
585 aloha 1.1 g_free(filename);
586     } else
587 aloha 1.16 save_text_buffer(Shiki_CURRENT_TAB_TITLE, Shiki_CURRENT_TEXT_BUFFER);
588 aloha 1.1 }
589    
590     /* ��������������������������������������������������������������������������� */
591 aloha 1.27 static void save_file_as() {
592 aloha 1.1 gchar *filename = get_filename_from_dialog("Save File As ...");
593    
594 aloha 1.7 if(!filename) return;
595 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
596 aloha 1.1
597 aloha 1.27 gtk_notebook_set_tab_label_text(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
598 aloha 1.16 gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
599 aloha 1.1
600     g_free(filename);
601     }
602    
603     /* YES ������������NO ������������������������������������ callback */
604 aloha 1.17 static void really_quit_dialog_yes(GtkWidget *widget, gboolean *flag){*flag = FALSE;}
605     static void really_quit_dialog_no(GtkWidget *widget, gint *flag){*flag = TRUE;}
606 aloha 1.1
607     /* ��������������������������������������������� ? */
608 aloha 1.17 static gboolean not_yet_save_changes_really_quit(GtkTextBuffer *buffer) {
609 aloha 1.1 GtkWidget *yes_button, *no_button;
610     static GtkWidget *dialog_window = NULL;
611    
612     /* ��������������������������������������� */
613     if(!gtk_text_buffer_get_modified(buffer)) return FALSE;
614    
615     if(dialog_window == NULL) {
616     gboolean flag = TRUE;
617     dialog_window = gtk_dialog_new ();
618    
619     /* ��������������������������������������������� ? ��������������������������� */
620     g_signal_connect(G_OBJECT(dialog_window), "delete_event", G_CALLBACK(gtk_false), NULL);
621     g_signal_connect(G_OBJECT(dialog_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
622 aloha 1.5 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->vbox),
623     gtk_label_new("������������������������������������������\n��������������������������������������� ?"), TRUE, TRUE, 0);
624 aloha 1.1 gtk_window_set_title(GTK_WINDOW (dialog_window), "Really Quit ?");
625     /* YES ������������ */
626 aloha 1.8 yes_button = gtk_button_new_with_mnemonic("������ (_Y)");
627 aloha 1.1 g_signal_connect(GTK_OBJECT(yes_button), "clicked", G_CALLBACK(really_quit_dialog_yes), &flag);
628     g_signal_connect_swapped(GTK_OBJECT(yes_button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(dialog_window));
629     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), yes_button, TRUE, TRUE, 0);
630    
631     /* NO ������������ */
632 aloha 1.8 no_button = gtk_button_new_with_mnemonic("��������� (_N)");
633 aloha 1.1 g_signal_connect(GTK_OBJECT(no_button), "clicked", G_CALLBACK(really_quit_dialog_no), &flag);
634     g_signal_connect_swapped(GTK_OBJECT(no_button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(dialog_window));
635     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), no_button, TRUE, TRUE, 0);
636    
637     gtk_window_set_modal(GTK_WINDOW(dialog_window), TRUE);
638 aloha 1.16 gtk_window_set_transient_for(GTK_WINDOW(dialog_window), GTK_WINDOW (Shiki_EDITOR_WINDOW));
639 aloha 1.1
640     gtk_widget_show_all(dialog_window);
641     gtk_main ();
642     dialog_window = NULL;
643    
644     /* "delete_event" ��������������� FALSE ���������"destory" ������������������window ������������������ */
645     return flag;
646     }
647     return TRUE;
648     }
649    
650     /* ������������������������������������������������������������������������������������������ */
651 aloha 1.27 static gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, GtkTextBuffer *buffer){
652     return not_yet_save_changes_really_quit(buffer);
653 aloha 1.1 }
654    
655     /* ��������������������� */
656 aloha 1.27 static void open_file(gchar *filename) {
657 aloha 1.1 gchar *contents, *text;
658     gsize br, bw, len;
659     GError *err = NULL;
660 aloha 1.33
661 aloha 1.27 g_return_if_fail(filename != NULL);
662 aloha 1.33
663 aloha 1.1 if(g_file_get_contents(filename, &contents, &len, NULL)) {
664     GtkTextIter p;
665 aloha 1.3
666 aloha 1.1 /* ������������������������������ */
667 aloha 1.27 append_tabpage(g_strdup(filename));
668 aloha 1.1
669     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
670 aloha 1.17 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER, contents, len);
671 aloha 1.1 else
672 aloha 1.17 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER, text, len);
673 aloha 1.1
674     /* ������������������������ */
675 aloha 1.17 gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
676 aloha 1.1 /* ������������������������������ */
677 aloha 1.17 gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
678     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
679 aloha 1.10 update_modeline_label();
680 aloha 1.16 gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
681 aloha 1.27 gtk_widget_show_all(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
682 aloha 1.1 g_free(contents); g_free(text); g_free(filename);
683     } else
684     g_printerr("Get file contents error !\n");
685     }
686    
687 aloha 1.21 /* ��������������������������������������������������� */
688 aloha 1.27 static void open_file_handler() {
689 aloha 1.21 gchar *filename = get_filename_from_dialog("File Selection");
690    
691     if(!filename) return;
692 aloha 1.27 open_file(filename);
693 aloha 1.1 }
694    
695     /* gauche ��������������������������������� */
696     static gchar *eval_cstring_by_gauche(gchar *s) {
697     gchar *msg;
698    
699     ScmObj result, error;
700     /* ������������������������������ */
701     ScmObj os = Scm_MakeOutputStringPort(TRUE);
702    
703     /* Scheme ��������������������������������������� */
704     /* http://alohakun.blog7.fc2.com/blog-entry-517.html */
705 aloha 1.34 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*input*")), SCM_MAKE_STR(s));
706     Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
707 aloha 1.1
708 aloha 1.34 result = Scm_EvalCString("(guard (e (else (set! *error* e) #f)) (eval (read-from-string *input*) (current-module)))", SCM_OBJ(Shiki_CURRENT_BUFFER_ENV));
709 aloha 1.1
710 aloha 1.34 error = Scm_GlobalVariableRef(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
711 aloha 1.1
712     /* ��������������������������������������������������������� */
713     if (!SCM_FALSEP(error))
714     Scm_Write(error, os, SCM_WRITE_DISPLAY);
715     else
716     Scm_Write(result, os, SCM_WRITE_DISPLAY);
717    
718     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
719     /* ������������������ */
720     Scm_ClosePort(SCM_PORT(os));
721    
722     return msg;
723     }
724    
725 aloha 1.13 /* ������������������������������������������������������������������ S ��������������� (������������) */
726 aloha 1.27 static void load_region_by_gauche() {
727 aloha 1.1
728     GtkTextIter start, end, p;
729     gchar *code;
730 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
731     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
732 aloha 1.1
733     /* ������������������������������������������������������������ */
734 aloha 1.16 if(gtk_text_buffer_get_selection_bounds(Shiki_CURRENT_TEXT_BUFFER, &start, &end)) {
735     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
736     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(code), -1);
737 aloha 1.1 g_free(code);
738     }
739     }
740    
741     // GtkTextCharPredicate
742     static gboolean is_kakko_or_kokka(gunichar ch, gpointer p) {
743     return ch == '(' || ch == ')';
744     }
745 aloha 1.29 static gboolean is_kakko(gunichar ch, gpointer p) {return ch == '(';}
746 aloha 1.1 static gboolean is_kokka(gunichar ch, gpointer p) {return ch == ')';}
747    
748 aloha 1.30 /* ��������������������� '(' ��������������� ')' ������������������ (S ���) ��������������� */
749     static gboolean search_sexp(GtkTextIter *start, GtkTextIter *end) {
750 aloha 1.33
751 aloha 1.30 /* ������������������������������ */
752     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, start, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
753    
754     if(gtk_text_iter_get_char(start) != '(')
755     gtk_text_iter_forward_find_char(start, is_kakko, NULL, NULL);
756    
757     *end = *start;
758    
759     /* ��������������������������������� S ������������������ */
760     if(!search_sexp_kokka(end)) return FALSE;
761     gtk_text_iter_forward_char(end);
762     return TRUE;
763     }
764    
765     static gboolean search_sexp_kokka(GtkTextIter *end) {
766 aloha 1.29 gint nest_level = 0;
767 aloha 1.33
768 aloha 1.30 /* ������������ ')' ��������� */
769 aloha 1.29 while(1) {
770 aloha 1.30 if(!gtk_text_iter_forward_find_char(end, is_kakko_or_kokka, NULL, NULL))
771 aloha 1.29 return FALSE;
772    
773 aloha 1.30 if(gtk_text_iter_get_char(end) == '(')
774 aloha 1.29 nest_level++;
775     else {
776     if(!nest_level)
777     break;
778     else
779     nest_level--;
780     }
781     }
782     return TRUE;
783     }
784 aloha 1.1
785 aloha 1.30 /* ��������������������� ')' ��������������� '(' ������������������ (S ���) ��������������� */
786     static gboolean search_last_sexp(GtkTextIter *start, GtkTextIter *end) {
787    
788     /* ������������������������������ */
789     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
790    
791     gtk_text_iter_backward_char(end);
792 aloha 1.33
793 aloha 1.30 if(gtk_text_iter_get_char(end) != ')')
794     gtk_text_iter_backward_find_char(end, is_kokka, NULL, NULL);
795     *start = *end;
796     gtk_text_iter_forward_char(end);
797    
798     /* ��������������������������������� S ������������������ */
799     if(!search_last_sexp_kakko(start)) return FALSE;
800    
801     return TRUE;
802     }
803    
804 aloha 1.1 /* ')' ��������������� '(' ������������������ (S ���) ��������������� */
805 aloha 1.29 static gboolean search_last_sexp_kakko(GtkTextIter *start) {
806 aloha 1.1 gint nest_level = 0;
807 aloha 1.30 /* ��������������������������������������� ')' ��������� */
808 aloha 1.1 while(1) {
809     if(!gtk_text_iter_backward_find_char(start, is_kakko_or_kokka, NULL, NULL))
810     return FALSE;
811    
812     if(gtk_text_iter_get_char(start) == ')')
813     nest_level++;
814     else {
815     if(!nest_level)
816     break;
817     else
818     nest_level--;
819     }
820     }
821     return TRUE;
822     }
823    
824     /* ������������������������������������������������ */
825     static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer) {
826     gint nest_level = 0;
827     GtkTextIter start, end;
828     gtk_text_buffer_get_start_iter(buffer, &start);
829     if(gtk_text_iter_get_char(&start) == '(') nest_level++;
830    
831     /* ��������������������� (= end) ��������� */
832     gtk_text_buffer_get_iter_at_mark(buffer,&end, gtk_text_buffer_get_insert(buffer));
833    
834     while(1) {
835     /* end ������ '(' ��� ')' ��������������������������������������������� */
836     if(!gtk_text_iter_forward_find_char(&start, is_kakko_or_kokka, NULL, &end))
837     return nest_level;
838    
839     if(gtk_text_iter_get_char(&start) == '(')
840     nest_level++;
841     else
842     nest_level--;
843     }
844     }
845    
846     /* ��������������������������������� on/off */
847     static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook) {
848     gint tval = FALSE;
849     gint bval = FALSE;
850     if(notebook->show_tabs == FALSE)
851     tval = TRUE;
852     if(notebook->show_border == FALSE)
853     bval = TRUE;
854    
855     gtk_notebook_set_show_tabs(notebook, tval);
856     gtk_notebook_set_show_border(notebook, bval);
857     }
858    
859     /* ������������������������ */
860 aloha 1.17 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook ) {
861 aloha 1.1 gtk_notebook_set_tab_pos(notebook, (notebook->tab_pos + 1) % 4);
862     }
863    
864     /* ������������������������������������������ */
865    
866 aloha 1.3 /* ��������������������� ^npfb */
867 aloha 1.7 static void forward_current_buffer() {
868 aloha 1.3 GtkTextIter p;
869 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
870 aloha 1.3 gtk_text_iter_forward_char(&p);
871 aloha 1.16 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
872 aloha 1.3 }
873 aloha 1.7 static void backward_current_buffer() {
874 aloha 1.3 GtkTextIter p;
875 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
876 aloha 1.3 gtk_text_iter_backward_char(&p);
877 aloha 1.16 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
878 aloha 1.3 }
879 aloha 1.7 static void line_forward_current_buffer() {
880 aloha 1.3 GtkTextIter p;
881 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
882     gtk_text_view_forward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
883     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
884 aloha 1.7 }
885     static void line_backward_current_buffer() {
886 aloha 1.3 GtkTextIter p;
887 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
888     gtk_text_view_backward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
889     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
890 aloha 1.3 }
891    
892 aloha 1.1 /* ��������������������� */
893 aloha 1.8 static gboolean signal_key_release_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
894     static gint metakey_pressed = 0;
895 aloha 1.6 static gint controlx_pressed = 0;
896 aloha 1.1
897     if(event->keyval == GDK_parenright && event->state & GDK_SHIFT_MASK) {
898     GtkTextIter start, end;
899    
900     /* ������������������������������ */
901 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
902 aloha 1.1
903     start = end;
904     gtk_text_iter_backward_char(&start);
905    
906     /* ��������������������������������� S ������������������ */
907 aloha 1.29 if(!search_last_sexp_kakko(&start)) return FALSE;
908 aloha 1.1
909 aloha 1.16 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
910 aloha 1.1 }
911    
912     /* ������������������������������������������������������������������������������������������������ (���������������) ������������������ */
913     if(event->keyval == GDK_Return) {
914 aloha 1.16 gint indentWidth = get_parent_nest_level_at_cursor(Shiki_CURRENT_TEXT_BUFFER) * editor_indent_width;
915 aloha 1.1 gchar *indent = g_strnfill(indentWidth, ' ');
916 aloha 1.16 gtk_text_buffer_insert_at_cursor(Shiki_CURRENT_TEXT_BUFFER, indent, -1);
917 aloha 1.1 g_free(indent);
918     }
919    
920 aloha 1.6 /* C-x */
921     if(event->keyval == GDK_x && event->state & GDK_CONTROL_MASK) {
922     controlx_pressed++;
923 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-x -");
924 aloha 1.6 } else if(event->state & GDK_CONTROL_MASK) {
925 aloha 1.8
926 aloha 1.6 if(controlx_pressed > 0) {
927     switch(event->keyval) {
928     case GDK_c :/* C-x C-c : ������ */
929 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-c");
930 aloha 1.6 {/* "delete-event" ��������������������������������������� �� ������������������������������������ */
931     GdkEvent ev;
932    
933     ev.any.type = GDK_DELETE;
934 aloha 1.16 ev.any.window = Shiki_EDITOR_WINDOW->window;
935 aloha 1.6 ev.any.send_event = FALSE;
936     gdk_event_put (&ev);
937     }
938     break;
939    
940     case GDK_f : /* C-x C-f : ������������������ */
941 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-f");
942 aloha 1.27 open_file_handler();
943 aloha 1.6 break;
944    
945     case GDK_s : /* C-x C-s : ������������������ */
946 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-s");
947 aloha 1.27 save_file();
948 aloha 1.6 break;
949    
950     case GDK_w : /* C-x C-w : ������������������������ */
951 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-w");
952 aloha 1.27 save_file_as();
953 aloha 1.6 break;
954     }
955     controlx_pressed = 0;
956     }
957 aloha 1.8
958     switch(event->keyval) {
959     case GDK_g :/* C-g : ��������������� */
960     metakey_pressed = 0;
961     controlx_pressed = 0;
962    
963 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "Quit");
964 aloha 1.8 break;
965     }
966    
967 aloha 1.6 }
968 aloha 1.1 return FALSE;
969     }
970 aloha 1.27 static void open_online_help() {
971 aloha 1.22 GtkTextIter p;
972 aloha 1.27 append_tabpage(g_strdup("*help*"));
973 aloha 1.22 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER,
974 aloha 1.30 "������\n"
975     "$ ./shiki [file1 file2 ....]\n\n"
976     "[���������������������������] ��������������������� (C-x C-f)\n"
977     "[������������������������������������������] ��������������������� (C-x C-s)\n"
978     "[���������������������������������������������] ��������������������������� (C-x C-w)\n"
979     "[���������������������] ��������������� gauche ������������ (region-compile)\n"
980     "[��������������� (���������) ���������������] ��������� on/off\n"
981     "[������ (���������) ���������������] ������������������������\n"
982 aloha 1.33 "[������ + ������������] ��������������������������� (C-t) (tab)\n"
983     "[���������������������������] ������������ (C-_)\n"
984 aloha 1.30 "[���������������������] ������������������������\n"
985 aloha 1.33 "[�� ������������] ������������������������ (C-k) (kill buffer)\n"
986 aloha 1.30 "[A ������������] ���������������������\n"
987     "[���������������������������] Scheme ������������������������\n"
988     "[���������������������������������] ���������������������������������������\n"
989     "[��������� (?) ������������] ���������������������������������������\n"
990 aloha 1.33 "[info ������������] ���������������������������������������������������\n"
991     "\n"
992 aloha 1.30 "C-f : ��� ��������� (forward)\n"
993     "C-b : ��� ��������� (backward)\n"
994     "C-n : ��� ��������� (next line)\n"
995 aloha 1.33 "C-p : ��� ��������� (previous line)\n"
996     "\n"
997     "C-h : ���������������������\n"
998 aloha 1.31 "C-w : ���������\n"
999 aloha 1.33 "C-y : ��������� (������������)\n"
1000     "\n"
1001 aloha 1.30 "C-e : ��������������������� S ������������ (eval-expression)\n"
1002     "C-j : ��������������������� S ������������ (eval-last-sexp)\n"
1003 aloha 1.33 "(emacs/xyzzy ��� *scratch* ���������������������)\n"
1004     "\n"
1005 aloha 1.31 "C-M-@ : ��������������������� S ������������ (mark-sexp)\n"
1006     "C-M-SPC : ��������������������� S ������������ (mark-last-sexp)\n"
1007 aloha 1.33 "C-x C-c : ��������������������������� �� ���������������������������������\n"
1008     "\n"
1009 aloha 1.30 "������������������������������������������������������������������Really Quit ?���������������������������������\n", -1);
1010     gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
1011     /* ������������������������������ */
1012     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
1013     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
1014 aloha 1.22 }
1015    
1016 aloha 1.1 /* ��������������������������������������� */
1017 aloha 1.21 static void shiki_editor_window_init(int argc, char **argv) {
1018 aloha 1.26 GtkWidget *vbox, *toolbar;
1019 aloha 1.1 GtkToolItem *icon;
1020     GtkIconSize iconsize;
1021 aloha 1.2 GtkTooltips *toolbar_tips = gtk_tooltips_new();
1022 aloha 1.1 /* ��������������������������������������������������������������������������������� */
1023     GtkToolItem *oicon, *sicon, *saicon, *eicon;
1024    
1025 aloha 1.8 gint contextid;
1026    
1027 aloha 1.1 /* ������������ */
1028 aloha 1.16 Shiki_EDITOR_WINDOW = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1029     g_signal_connect(G_OBJECT(Shiki_EDITOR_WINDOW), "destroy", G_CALLBACK(gtk_main_quit), NULL);
1030 aloha 1.1
1031 aloha 1.31 /* ������������������������������������������������������������ */
1032     Shiki_EDITOR_CLIPBOARD = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
1033    
1034 aloha 1.1 /* ������������������������������������ */
1035     vbox = gtk_vbox_new(FALSE, 0);
1036     /* ��������������������� */
1037     toolbar = gtk_toolbar_new();
1038     gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
1039    
1040 aloha 1.26 Shiki_EDITOR_NOTEBOOK = GTK_NOTEBOOK(gtk_notebook_new());
1041     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "switch-page", GTK_SIGNAL_FUNC(switch_tabpage_handler), NULL);
1042 aloha 1.1
1043     /* ������������������������������������������������ */
1044     gtk_toolbar_set_style(GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
1045     iconsize = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar));
1046    
1047     /* ������������������ */
1048    
1049     /* ������������������ */
1050     oicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-open", iconsize), "");
1051     /* ������������������������������������������������������������������������������������ */
1052 aloha 1.27 g_signal_connect(G_OBJECT(oicon), "clicked", G_CALLBACK(open_file_handler), NULL);
1053 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(oicon));
1054 aloha 1.2 gtk_tool_item_set_tooltip(oicon, toolbar_tips, "���������������������������",
1055     "���������������������������������������������������������������������������������������");
1056 aloha 1.1
1057     /* ������������������ */
1058     sicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-save", iconsize), "");
1059     /* ������������������������������������������������������������������������������������ */
1060 aloha 1.27 g_signal_connect(G_OBJECT(sicon), "clicked", G_CALLBACK(save_file), NULL);
1061 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(sicon));
1062 aloha 1.2 gtk_tool_item_set_tooltip(sicon, toolbar_tips, "������������������������������",
1063     "������������������������������������������������������������������������������������������������������������������������������������");
1064 aloha 1.1
1065     /* ��������������������������� */
1066     saicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-save-as", iconsize), "");
1067     /* ������������������������������������������������������������������������������������������������������������������ */
1068 aloha 1.27 g_signal_connect(G_OBJECT(saicon), "clicked", G_CALLBACK(save_file_as), NULL);
1069 aloha 1.2 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(saicon));
1070     gtk_tool_item_set_tooltip(saicon, toolbar_tips, "������������������������������������",
1071     "");
1072 aloha 1.1
1073     /* ������������������ */
1074     eicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-execute", iconsize), "");
1075 aloha 1.14 /* ������������������������������������������ libgauche ������������������ */
1076 aloha 1.27 g_signal_connect(G_OBJECT(eicon), "clicked", G_CALLBACK(load_region_by_gauche), NULL);
1077 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(eicon));
1078 aloha 1.14 gtk_tool_item_set_tooltip(eicon, toolbar_tips, "��������������� S ������������������������ (load-region-lisp)",
1079 aloha 1.2 "Scheme (gauche) ������������������ S ������������������������");
1080 aloha 1.1
1081 aloha 1.16 gtk_container_add(GTK_CONTAINER(Shiki_EDITOR_WINDOW), vbox);
1082 aloha 1.26 gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
1083 aloha 1.1
1084 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-apply", iconsize), "");
1085 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(tabsborder_on_off), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1086 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1087 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "��������� on/off", "");
1088 aloha 1.1
1089 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-preferences", iconsize), "");
1090 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(rotate_tab_position), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1091 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1092 aloha 1.14 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
1093 aloha 1.1
1094 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-add", iconsize), "");
1095 aloha 1.33 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(append_default_tabpage_handler), NULL);
1096 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1097 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������", "");
1098 aloha 1.1
1099 aloha 1.33 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-undo", iconsize), "");
1100     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(undo), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1101     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1102     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Undo","");
1103    
1104 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-delete", iconsize), "");
1105 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(clear_current_buffer), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1106 aloha 1.15 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1107     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������",
1108     "���������������������������������������������������������������������");
1109    
1110 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-close", iconsize), "");
1111 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(remove_tabpage), NULL);
1112 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1113 aloha 1.2 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������",
1114     "���������������������������������������������������������������");
1115 aloha 1.15
1116 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-bold", iconsize), "");
1117 aloha 1.12 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(select_font), NULL);
1118     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1119     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
1120 aloha 1.1
1121 aloha 1.18 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-connect", iconsize), "");
1122 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_scheme_file_by_gauche), NULL);
1123 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1124     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Scheme ������������������������", "");
1125    
1126 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-convert", iconsize), "");
1127 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_buffer_by_gauche), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1128 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1129     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������", "");
1130    
1131 aloha 1.22 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-dialog-question", iconsize), "");
1132 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(open_online_help), NULL);
1133 aloha 1.22 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1134     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������", "");
1135    
1136 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-dialog-info", iconsize), "");
1137 aloha 1.11 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(about_this_application), NULL);
1138     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1139     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
1140    
1141 aloha 1.16 gtk_box_pack_start(GTK_BOX(vbox), Shiki_EDITOR_MODELINE_LABEL = gtk_label_new("-E:** *scratch* (Gauche Interaction)--L1--All---------------------------------"), TRUE, TRUE, 0);
1142 aloha 1.12
1143 aloha 1.8 /* C-x C-s ��������������������������������������������������������������������������������������� */
1144 aloha 1.16 Shiki_EDITOR_STATUSBAR = gtk_statusbar_new();
1145     gtk_box_pack_start(GTK_BOX(vbox), Shiki_EDITOR_STATUSBAR, TRUE, TRUE, 0);
1146     contextid = gtk_statusbar_get_context_id(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), "");
1147 aloha 1.8
1148     /* ������������������������������������������������ */
1149 aloha 1.26 g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-press-event", G_CALLBACK (signal_key_press_handler), GINT_TO_POINTER(contextid));
1150     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-release-event", G_CALLBACK (signal_key_release_handler), GINT_TO_POINTER(contextid));
1151 aloha 1.12
1152 aloha 1.21 /* ��������������������������������������������� */
1153     if(argc >= 2) {
1154     int i;
1155     for(i = 1; i < argc; i++)
1156 aloha 1.27 open_file(g_strdup(argv[i]));
1157 aloha 1.21 } else /* ������������������������������������������������������������������ */
1158 aloha 1.26 open_online_help(Shiki_EDITOR_NOTEBOOK);
1159 aloha 1.8
1160 aloha 1.26 gtk_widget_grab_focus(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
1161 aloha 1.16 gtk_widget_show_all(Shiki_EDITOR_WINDOW);
1162 aloha 1.1 }
1163    
1164     int main(int argc, char *argv[]) {
1165     /* ������������������������������������ */
1166     gtk_set_locale();
1167     gtk_init(&argc, &argv);
1168     GC_INIT(); Scm_Init(GAUCHE_SIGNATURE);
1169 aloha 1.21 shiki_editor_window_init(argc, argv);
1170 aloha 1.1 gtk_main();
1171     Scm_Exit(0);
1172     return 0;
1173     }

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