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.61 - (hide annotations) (download) (as text)
Wed Nov 29 14:58:27 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.60: +4 -21 lines
File MIME type: text/x-csrc
add customization feature of modeline (and add related some API)

1 aloha 1.1 /* vim: set encoding=utf8:
2     *
3     * shiki.c
4     *
5 aloha 1.54 * This file is main file of Shiki.
6     *
7 aloha 1.1 * 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.61 * $Id: shiki.c,v 1.60 2006/11/29 05:08:46 aloha Exp $
28 aloha 1.1 */
29    
30 aloha 1.54 #include"shiki.h"
31 aloha 1.1
32 aloha 1.17 /* ������������������������������������������������������������������������������������������������������������������������������ */
33 aloha 1.54 ShikiEditorType Shiki_editor;
34 aloha 1.10
35 aloha 1.35 static gchar *R5RS_keywords[] = {"and", "begin", "case", "cond-expand", "cond", "define-accessor", "define-class", "defined?", "define-generic", "define", "define-macro", "define-method", "define-module", "define-private", "define-public", "define-reader-ctor", "define-syntax", "define-syntax-macro", "defmacro", "defmacro*-public", "delay", "do", "else", "fluid-let", "if", "lambda", "let", "let*", "letrec", "letrec-syntax", "let-syntax", "or", "quasiquote", "quote", "set!", "syntax-rules", "unquote", NULL};
36    
37 aloha 1.36 static gchar *R5RS_functions[] = {"*", "+", "-", "/", "<", ">", "<=", ">=", "?", "`", "=", "abs", "acos", "angle", "append", "apply", "asin", "assoc", "assq", "assv", "atan", "boolean?", "caaar", "caadr", "caar", "cadar", "caddr", "cadr", "call/cc", "call-with-current-continuation", "call-with-input-file", "call-with-output-file", "call-with-values", "car", "catch", "cdaar", "cdadr", "cdar", "cddar", "cdddr", "cddr", "cdr", "ceiling", "char-alphabetic?", "char-ci>=?", "char-ci>?", "char-ci=?", "char-ci<=?", "char-ci<?", "char-downcase", "char->integer", "char>=?", "char>?", "char=?", "char?", "char-lower-case?", "char<=?", "char<?", "char-numeric?", "char-ready?", "char-upcase", "char-upper-case?", "char-whitespace?", "close-input-port", "close-output-port", "complex?", "cons", "cos", "current-input-port", "current-output-port", "delete-file", "display", "dynamic-wind", "eof-object?", "eq?", "equal?", "eqv?", "eval", "even?", "exact->inexact", "exact?", "exit", "exp", "expt", "file-exists?", "file-or-directory-modify-seconds", "floor", "force", "for-each", "gcd", "gensym", "getenv", "get-output-string", "imag-part", "inexact?", "input-port?", "integer->char", "integer?", "lcm", "length", "list->string", "list->vector", "list", "list?", "list-ref", "list-tail", "load", "log", "magnitude", "make-polar", "make-rectangular", "make-string", "make-vector", "map", "max", "member", "memq", "memv", "min", "modulo", "negative?", "newline", "nil", "not", "null?", "number->string", "number?", "odd?", "open-input-file", "open-input-string", "open-output-file", "open-output-string", "output-port?", "pair?", "peek-char", "port?", "positive?", "procedure?", "quotient", "rational?", "read-char", "read", "read-line", "real?", "real-part", "remainder", "reverse", "reverse!", "round", "set-car!", "set-cdr!", "sin", "sqrt", "string-append", "string-ci>=?", "string-ci>?", "string-ci=?", "string-ci<=?", "string-ci<?", "string-copy", "string-fill!", "string>=?", "string>?", "string->list", "string->number", "string->symbol", "string", "string=?", "string?", "string-length", "string<=?", "string<?", "string-ref", "string-set!", "substring", "symbol->string", "symbol?", "system", "tan", "truncate", "values", "vector-fill!", "vector->list", "vector", "vector?", "vector-length", "vector-ref", "vector-set!", "with-input-from-file", "with-output-to-file", "write-char", "write", "zero", NULL};
38 aloha 1.35
39     static GHashTable *keywords_hash = NULL;
40    
41     typedef enum {
42     R5RS_KEYWORD_COLOR = 1,
43     R5RS_FUNCTION_COLOR,
44     GAUCHE_KEYWORD_COLOR,
45     GAUCHE_FUNCTION_COLOR
46     } HIGHILIGHT_COLOR;
47    
48 aloha 1.39 GdkColor COLOR_BLACK;
49     GdkColor COLOR_GREEN;
50    
51 aloha 1.17 /* ������������������ */
52 aloha 1.25
53 aloha 1.33 /* foo_bar_handler() ������������������������������������������������������ */
54 aloha 1.58 static void kill_buffer_handler();
55 aloha 1.33 static void append_default_tabpage_handler();
56    
57 aloha 1.25 /* ������������������ */
58 aloha 1.27 static void save_file();
59     static void save_file_as();
60 aloha 1.25
61     /* ������������������������������ */
62     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer);
63     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer);
64 aloha 1.57 static void clear_current_buffer_handler();
65 aloha 1.33 static void undo();
66 aloha 1.46 static void search_current_buffer();
67 aloha 1.25
68 aloha 1.46 /* Gauche ��� S ��������������������������������������������������������������������������� */
69 aloha 1.17 static gchar *eval_cstring_by_gauche(gchar *s);
70 aloha 1.25 static gchar *load_cstring_by_gauche(gchar *s);
71     static void load_buffer_by_gauche();
72 aloha 1.27 static void load_region_by_gauche();
73     static void load_scheme_file_by_gauche();
74 aloha 1.17 static gboolean is_kakko_or_kokka(gunichar ch, gpointer);
75 aloha 1.29 static gboolean is_kakko(gunichar ch, gpointer);
76 aloha 1.17 static gboolean is_kokka(gunichar ch, gpointer);
77 aloha 1.30 static gboolean search_sexp(GtkTextIter *start, GtkTextIter *end);
78     static gboolean search_sexp_kokka(GtkTextIter *end);
79     static gboolean search_last_sexp(GtkTextIter *start, GtkTextIter *end);
80 aloha 1.29 static gboolean search_last_sexp_kakko(GtkTextIter *start);
81 aloha 1.17 static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer);
82 aloha 1.46 static gboolean is_not_scheme_delimita_p(gunichar ch, gpointer user_data);
83     static gboolean is_double_quote(gunichar ch, gpointer user_data);
84     static gboolean is_scheme_delimita_p(gunichar ch, gpointer user_data);
85     static void scheme_keyword_highlighting_current_buffer();
86 aloha 1.25
87     /* ������ */
88     static void select_font();
89     static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog);
90 aloha 1.18 static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) ;
91 aloha 1.17 static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook);
92 aloha 1.27 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook);
93 aloha 1.25
94     /* ������������������������ */
95 aloha 1.22 static gboolean signal_key_press_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid);
96     static gboolean signal_key_release_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid);
97 aloha 1.25
98     /* ������������������ */
99 aloha 1.27 static void open_online_help();
100 aloha 1.25 static void about_this_application();
101    
102 aloha 1.27 /* ������������������������ */
103 aloha 1.54 static void Shiki_editor_window_init(int argc, char **argv);
104 aloha 1.52
105 aloha 1.51 /* ������������������������������ */
106 aloha 1.57 static void clear_current_buffer_handler() {
107     Shiki_erase_buffer(Shiki_CURRENT_TEXT_BUFFER);
108 aloha 1.51 }
109    
110 aloha 1.46 static void destroy_handler(GtkWidget *button, GtkWidget *widget) {gtk_widget_destroy(widget);}
111    
112 aloha 1.48 static void toggled_handler(GtkToggleButton *togglebutton, gboolean *flag) {
113     *flag = !*flag;
114     }
115    
116 aloha 1.47 static void replace_current_buffer() {
117     GtkWidget *dialog = gtk_dialog_new_with_buttons ("������������������", GTK_WINDOW(Shiki_EDITOR_WINDOW), GTK_DIALOG_DESTROY_WITH_PARENT, NULL);
118 aloha 1.48 GtkWidget *table = gtk_table_new(7, 3, FALSE);
119 aloha 1.47 GtkWidget *find_label = gtk_label_new("������ : ");
120     GtkWidget *find = gtk_entry_new();
121 aloha 1.48 GtkWidget *rep_label = gtk_label_new("������ : ");
122     GtkWidget *replace = gtk_entry_new();
123     GtkWidget *check1 = gtk_check_button_new_with_label("���������������������������������");
124     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check1), TRUE);
125 aloha 1.47 GtkWidget *check2 = gtk_check_button_new_with_label("���������������������������");
126     GtkWidget *check3 = gtk_check_button_new_with_label("������������");
127     GtkWidget *check4 = gtk_check_button_new_with_label("���������������������������������������������");
128     GtkWidget *check5 = gtk_check_button_new_with_label("���������������������������");
129     GtkWidget *interactive = gtk_button_new_with_label ("������������");
130     GtkWidget *all = gtk_button_new_with_label ("������������");
131     GtkWidget *cancel = gtk_button_new_with_label ("���������������");
132 aloha 1.48 gboolean f1 = TRUE, f2, f3, f4, f5;
133     f2 = f3 = f4 = f5 = FALSE;
134     g_signal_connect (check1, "toggled", G_CALLBACK (toggled_handler), &f1);
135     g_signal_connect (check2, "toggled", G_CALLBACK (toggled_handler), &f2);
136     g_signal_connect (check3, "toggled", G_CALLBACK (toggled_handler), &f3);
137     g_signal_connect (check4, "toggled", G_CALLBACK (toggled_handler), &f4);
138     g_signal_connect (check5, "toggled", G_CALLBACK (toggled_handler), &f5);
139 aloha 1.47
140     g_signal_connect (G_OBJECT(dialog), "delete_event", G_CALLBACK(gtk_widget_destroy), NULL);
141     g_signal_connect (G_OBJECT(cancel), "clicked", G_CALLBACK(destroy_handler), dialog);
142     gtk_table_set_row_spacings(GTK_TABLE(table), 10);
143     gtk_table_set_col_spacings(GTK_TABLE(table), 10);
144     gtk_container_border_width (GTK_CONTAINER (dialog), 10);
145    
146     gtk_table_attach_defaults (GTK_TABLE(table), find_label, 0, 1, 0, 1);
147     gtk_table_attach_defaults (GTK_TABLE(table), find, 1, 2, 0, 1);
148     gtk_table_attach_defaults (GTK_TABLE(table), interactive, 2, 3, 0, 1);
149    
150     gtk_table_attach_defaults (GTK_TABLE(table), rep_label, 0, 1, 1, 2);
151     gtk_table_attach_defaults (GTK_TABLE(table), replace, 1, 2, 1, 2);
152     gtk_table_attach_defaults (GTK_TABLE(table), all, 2, 3, 1, 2);
153    
154     gtk_table_attach_defaults (GTK_TABLE(table), check1, 1, 2, 2, 3);
155     gtk_table_attach_defaults (GTK_TABLE(table), cancel, 2, 3, 2, 3);
156    
157     gtk_table_attach_defaults (GTK_TABLE(table), check2, 1, 2, 3, 4);
158     gtk_table_attach_defaults (GTK_TABLE(table), check3, 1, 2, 4, 5);
159     gtk_table_attach_defaults (GTK_TABLE(table), check4, 1, 2, 5, 6);
160     gtk_table_attach_defaults (GTK_TABLE(table), check5, 1, 2, 6, 7);
161    
162     gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table);
163     gtk_widget_show_all(table);
164     gtk_dialog_run(GTK_DIALOG(dialog));
165     }
166    
167 aloha 1.46 static void search_current_buffer() {
168     GtkWidget *dialog = gtk_dialog_new_with_buttons ("������������������", GTK_WINDOW(Shiki_EDITOR_WINDOW), GTK_DIALOG_DESTROY_WITH_PARENT, NULL);
169     GtkWidget *table = gtk_table_new(6, 3, FALSE);
170     GtkWidget *label = gtk_label_new("������ : ");
171     GtkWidget *input = gtk_entry_new();
172     GtkWidget *check1 = gtk_check_button_new_with_label("���������������������������������");
173 aloha 1.48 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check1), TRUE);
174 aloha 1.46 GtkWidget *check2 = gtk_check_button_new_with_label("���������������������������");
175     GtkWidget *check3 = gtk_check_button_new_with_label("������������");
176     GtkWidget *check4 = gtk_check_button_new_with_label("���������������������������������������������");
177     GtkWidget *check5 = gtk_check_button_new_with_label("���������������������������������");
178     GtkWidget *prev = gtk_button_new_with_label ("���������");
179     GtkWidget *next = gtk_button_new_with_label ("���������");
180     GtkWidget *cancel = gtk_button_new_with_label ("���������������");
181 aloha 1.48 gboolean f1 = TRUE, f2, f3, f4, f5;
182     f2 = f3 = f4 = f5 = FALSE;
183     g_signal_connect (check1, "toggled", G_CALLBACK (toggled_handler), &f1);
184     g_signal_connect (check2, "toggled", G_CALLBACK (toggled_handler), &f2);
185     g_signal_connect (check3, "toggled", G_CALLBACK (toggled_handler), &f3);
186     g_signal_connect (check4, "toggled", G_CALLBACK (toggled_handler), &f4);
187     g_signal_connect (check5, "toggled", G_CALLBACK (toggled_handler), &f5);
188 aloha 1.46
189     g_signal_connect (G_OBJECT(dialog), "delete_event", G_CALLBACK(gtk_widget_destroy), NULL);
190     g_signal_connect (G_OBJECT(cancel), "clicked", G_CALLBACK(destroy_handler), dialog);
191     gtk_table_set_row_spacings(GTK_TABLE(table), 10);
192     gtk_table_set_col_spacings(GTK_TABLE(table), 10);
193     gtk_container_border_width (GTK_CONTAINER (dialog), 10);
194     gtk_table_attach_defaults (GTK_TABLE(table), label, 0, 1, 0, 1);
195     gtk_table_attach_defaults (GTK_TABLE(table), input, 1, 2, 0, 1);
196     gtk_table_attach_defaults (GTK_TABLE(table), prev, 2, 3, 0, 1);
197     gtk_table_attach_defaults (GTK_TABLE(table), check1, 1, 2, 1, 2);
198     gtk_table_attach_defaults (GTK_TABLE(table), check2, 1, 2, 2, 3);
199     gtk_table_attach_defaults (GTK_TABLE(table), check3, 1, 2, 3, 4);
200     gtk_table_attach_defaults (GTK_TABLE(table), check4, 1, 2, 4, 5);
201     gtk_table_attach_defaults (GTK_TABLE(table), check5, 1, 2, 5, 6);
202     gtk_table_attach_defaults (GTK_TABLE(table), next, 2, 3, 1, 2);
203     gtk_table_attach_defaults (GTK_TABLE(table), cancel, 2, 3, 2, 3);
204     gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table);
205     gtk_widget_show_all(table);
206     gtk_dialog_run(GTK_DIALOG(dialog));
207     }
208    
209 aloha 1.35 static gboolean is_not_scheme_delimita_p(gunichar ch, gpointer user_data) {
210 aloha 1.36 return ch != '(' && ch != ')' && !g_unichar_isspace(ch);
211     }
212    
213     static gboolean is_double_quote(gunichar ch, gpointer user_data) {
214     return ch == '\"';
215 aloha 1.35 }
216    
217     static gboolean is_scheme_delimita_p(gunichar ch, gpointer user_data) {
218 aloha 1.36 return ch == ' ' || ch == '(' || ch == ')' || ch == '\"' || g_unichar_isspace(ch);
219 aloha 1.35 }
220    
221     /* ������������������������������ */
222     static void scheme_keyword_highlighting_current_buffer() {
223     GtkTextIter s, e;
224     HIGHILIGHT_COLOR c;
225     gchar *word;
226 aloha 1.36 gboolean is_comment, is_string;
227     gunichar ch;
228 aloha 1.35
229     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &s);
230    
231     /* ��������� Scheme ������������������������������ */
232     while(TRUE) {
233 aloha 1.36 is_comment = FALSE;
234     is_string = FALSE;
235     if((ch = gtk_text_iter_get_char(&s)) != ';' && ch != '\"')
236 aloha 1.35 gtk_text_iter_forward_find_char(&s, is_not_scheme_delimita_p, NULL, NULL);
237     e = s;
238     if(gtk_text_iter_get_char(&s) == ';') {
239     gtk_text_iter_forward_line(&e);
240     gtk_text_iter_backward_char(&e);
241     is_comment = TRUE;
242 aloha 1.36 } else if(gtk_text_iter_get_char(&s) == '\"') {
243     while(TRUE) {
244     gtk_text_iter_forward_find_char(&e, is_double_quote, NULL, NULL);
245     gtk_text_iter_backward_char(&e);
246     if(gtk_text_iter_get_char(&e) != '\\') {
247     is_string = TRUE;
248     gtk_text_iter_forward_char(&e);
249     gtk_text_iter_forward_char(&e);
250     break;
251     }
252     gtk_text_iter_forward_char(&e);
253     gtk_text_iter_forward_char(&e);
254     }
255    
256 aloha 1.35 } else
257     gtk_text_iter_forward_find_char(&e, is_scheme_delimita_p, NULL, NULL);
258    
259     word = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &s, &e, FALSE);
260 aloha 1.36
261     /* ������������������������������������������������������������ */
262     if(is_comment) /* ������������ */
263 aloha 1.35 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "comment_highlighting", &s, &e);
264 aloha 1.36 else if(is_string) /* ��������� */
265     gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "string_highlighting", &s, &e);
266     else if(R5RS_KEYWORD_COLOR == (c = GPOINTER_TO_INT(g_hash_table_lookup(keywords_hash, word)))) /* R5RS ��������������� */
267 aloha 1.35 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "keyword_highlighting", &s, &e);
268 aloha 1.36 else if(R5RS_FUNCTION_COLOR == c) /* R5RS ������ */
269 aloha 1.35 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "function_highlighting", &s, &e);
270    
271 aloha 1.36 /* XXX : get_text() ������������������������������������������������������������������������������������������������������ GtkTextBuffer ������ const gchar * ������������������������������ */
272     g_free(word);
273 aloha 1.35
274     if(gtk_text_iter_is_end(&e)) break;
275     s = e;
276     }
277     }
278    
279 aloha 1.32 /* ������������������������������������������������������������ */
280     static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) {
281     /* ��������������������������������������������������������������������� */
282 aloha 1.55 Shiki_CURRENT_TAB_INFO = (ShikiBuffer *)g_list_nth_data(Shiki_EDITOR_BUFFER_LIST, pagenum);
283 aloha 1.32
284     /* ������������������������������������ */
285     Shiki_CURRENT_TAB_NUM = pagenum;
286    
287     /* ������������������������������������������������������ */
288     if(!Shiki_CURRENT_TAB_INFO) return;
289     gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), Shiki_CURRENT_FILENAME);
290    
291 aloha 1.61 Shiki_update_modeline(Shiki_CURRENT_TEXT_BUFFER);
292 aloha 1.32 }
293    
294 aloha 1.33 static void undo() {
295     g_print("Undo\n");
296     GtkTextIter start, end;
297     ShikiUndoInfo *undoInfo = g_list_nth_data(Shiki_CURRENT_UNDO_INFO_LIST, 0);
298     if(!undoInfo) {
299     g_print("������������ Undo ���������������\n");
300     return;
301     }
302     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &start, undoInfo->start);
303     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &end, undoInfo->end);
304    
305     if(undoInfo->action == SHIKI_UNDO_INSERT) {
306     Shiki_CURRENT_UNDO_INFO_LIST = g_list_delete_link(Shiki_CURRENT_UNDO_INFO_LIST, g_list_first(Shiki_CURRENT_UNDO_INFO_LIST));
307     gtk_text_buffer_delete(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
308     g_free(undoInfo->str);
309     g_free(undoInfo);
310     } else if(undoInfo->action == SHIKI_UNDO_DELETE) {
311     Shiki_CURRENT_UNDO_INFO_LIST = g_list_delete_link(Shiki_CURRENT_UNDO_INFO_LIST, g_list_first(Shiki_CURRENT_UNDO_INFO_LIST));
312     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &start, undoInfo->str, -1);
313     g_free(undoInfo->str);
314     g_free(undoInfo);
315     }
316    
317     }
318    
319 aloha 1.32 /* ��������������������� */
320     static gboolean signal_key_press_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
321     GtkTextIter start, end;
322    
323     /* ������������������������������������ */
324     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &start);
325     gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &end);
326     gtk_text_buffer_remove_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
327    
328     if(event->state & GDK_CONTROL_MASK && event->state & GDK_MOD1_MASK) {
329     switch(event->keyval) {
330     case GDK_at : /* C-M-SPC */
331     { GtkTextIter start, end;
332     if(!search_sexp(&start, &end)) return FALSE;
333     gtk_text_buffer_select_range(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
334     }
335     break;
336     case GDK_space : /* C-M-SPC */
337     { GtkTextIter start, end;
338     if(!search_last_sexp(&start, &end)) return FALSE;
339     gtk_text_buffer_select_range(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
340     }
341     break;
342     }
343     } else if(event->state & GDK_CONTROL_MASK) {
344     switch(event->keyval) {
345     case GDK_f : /* Ctrl + f : forward */
346 aloha 1.57 Shiki_forward_char();
347 aloha 1.32 break;
348     case GDK_b : /* Ctrl + b : backward */
349 aloha 1.57 Shiki_backward_char();
350 aloha 1.32 break;
351     case GDK_n : /* Ctrl + n : next line */
352 aloha 1.57 Shiki_forward_line(1);
353 aloha 1.32 break;
354     case GDK_p : /* Ctrl + p : previous line */
355 aloha 1.57 Shiki_forward_line(-1);
356 aloha 1.32 break;
357     case GDK_h :
358     { GtkTextIter p;
359     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
360     gtk_text_buffer_backspace(Shiki_CURRENT_TEXT_BUFFER, &p, FALSE, TRUE);
361     }
362     break;
363    
364     case GDK_e : /* Ctrl + e : eval-expression */
365     {
366 aloha 1.51 gchar *code, *result;
367 aloha 1.32 GtkTextIter start, end;
368    
369     if(!search_sexp(&start, &end)) return FALSE;
370    
371     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
372 aloha 1.51 result = eval_cstring_by_gauche(code);
373     g_free(code);
374    
375     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
376    
377 aloha 1.52 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, "\n", -1);
378 aloha 1.51 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, result, -1);
379 aloha 1.52 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, "\n", -1);
380 aloha 1.32 }
381     break;
382    
383     case GDK_j : /* Ctrl + j : eval-last-sexp */
384     {
385 aloha 1.51 gchar *code, *result;
386 aloha 1.32 GtkTextIter start, end;
387    
388     if(!search_last_sexp(&start, &end)) return FALSE;
389    
390     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
391 aloha 1.51 result = eval_cstring_by_gauche(code);
392     g_free(code);
393    
394     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
395    
396 aloha 1.52 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, "\n", -1);
397 aloha 1.51 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, result, -1);
398 aloha 1.52 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, "\n", -1);
399 aloha 1.32 }
400     break;
401    
402     case GDK_underscore : /* Ctrl + _ : Undo */
403 aloha 1.33 undo();
404 aloha 1.32 break;
405    
406     case GDK_t : /* Ctrl + t : ��������������� */
407 aloha 1.33 append_default_tabpage_handler();
408 aloha 1.32 break;
409    
410     case GDK_k : /* Ctrl + k : ������������������ */
411 aloha 1.58 kill_buffer_handler();
412 aloha 1.32 break;
413    
414     case GDK_w : /* Ctrl + w : ��������� */
415     gtk_text_buffer_cut_clipboard(Shiki_CURRENT_TEXT_BUFFER, Shiki_EDITOR_CLIPBOARD, TRUE);
416     break;
417    
418     case GDK_y : /* Ctrl + y : ��������� */
419     {GtkTextIter p;
420     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
421     gtk_text_buffer_paste_clipboard(Shiki_CURRENT_TEXT_BUFFER, Shiki_EDITOR_CLIPBOARD, &p, TRUE);
422     }
423     break;
424     }
425     }
426     return FALSE;
427     }
428    
429 aloha 1.33 static void append_default_tabpage_handler() {
430 aloha 1.57 Shiki_new_buffer_create(g_strdup("*scratch*"));
431 aloha 1.33 }
432    
433 aloha 1.23 /* ������������������������������������������ (������������) ��������� */
434 aloha 1.58 static void kill_buffer_handler() {
435     Shiki_kill_buffer(Shiki_CURRENT_TEXT_BUFFER);
436 aloha 1.23 }
437    
438 aloha 1.14 /* ������������������������������������ */
439     static void load_buffer_by_gauche() {
440     GtkTextIter p;
441 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
442     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
443     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(get_all_buffer_contents(Shiki_CURRENT_TEXT_BUFFER)), -1);
444 aloha 1.14 }
445    
446     /* ������������������������ */
447 aloha 1.27 static void load_scheme_file_by_gauche() {
448 aloha 1.58 gchar *contents, *text = NULL;
449 aloha 1.14 gsize br, bw, len;
450     GError *err = NULL;
451 aloha 1.57 const gchar *filename = Shiki_file_name_dialog("File Selection");
452 aloha 1.14 GtkTextIter p;
453    
454     if(!filename) return;
455 aloha 1.33
456 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
457     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
458 aloha 1.14
459     if(g_file_get_contents(filename, &contents, &len, NULL)) {
460     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
461 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(text), -1);
462 aloha 1.14 else
463 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(contents), -1);
464 aloha 1.14 }
465 aloha 1.57 g_free(text); g_free(contents);
466 aloha 1.14 }
467    
468 aloha 1.13 /* gauche ������������������������������������ */
469     static gchar *load_cstring_by_gauche(gchar *s) {
470     gchar *msg;
471    
472     ScmObj result, error;
473     /* ��������������������������������� */
474 aloha 1.50 ScmObj is = Scm_MakeInputStringPort(SCM_STRING(SCM_MAKE_STR_COPYING(s)), TRUE);
475 aloha 1.13 /* ������������������������������ */
476     ScmObj os = Scm_MakeOutputStringPort(TRUE);
477    
478 aloha 1.34 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*input*")), is);
479     Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
480 aloha 1.13 /* Scheme ��������������������������������������������������������������������������������� S ��������������������������������������������������������������������������� *error* ������������������ */
481 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));
482 aloha 1.13
483 aloha 1.34 error = Scm_GlobalVariableRef(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
484 aloha 1.13
485     /* ��������������������������������������������������������� */
486     if (!SCM_FALSEP(error))
487     Scm_Write(error, os, SCM_WRITE_DISPLAY);
488     else
489     Scm_Write(result, os, SCM_WRITE_DISPLAY);
490    
491     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
492     /* ������������������ */
493     Scm_ClosePort(SCM_PORT(is));
494     Scm_ClosePort(SCM_PORT(os));
495    
496     return msg;
497     }
498    
499 aloha 1.12 static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog) {
500     gchar *font_name = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (font_dialog));
501     if(font_name) {
502     GtkRcStyle *style = gtk_rc_style_new ();
503     pango_font_description_free(style->font_desc);
504     style->font_desc = pango_font_description_from_string(font_name);
505 aloha 1.16 gtk_widget_modify_style (GTK_WIDGET(Shiki_CURRENT_TEXT_VIEW), style);
506 aloha 1.44 gtk_rc_style_unref (style);
507 aloha 1.12 g_free (font_name);
508     }
509     }
510    
511 aloha 1.14 /* ������������������������������������������������������ */
512 aloha 1.12 static void select_font(){
513     GtkWidget *font_dialog = gtk_font_selection_dialog_new("Font Selection Dialog");
514     g_signal_connect (GTK_FONT_SELECTION_DIALOG (font_dialog)->ok_button, "clicked", G_CALLBACK(font_selection_ok), font_dialog);
515     gtk_dialog_run(GTK_DIALOG(font_dialog));
516     gtk_widget_destroy(font_dialog);
517     }
518    
519 aloha 1.11 /* ������������������������������������������ */
520     static void about_this_application() {
521     GtkAboutDialog *about = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
522     const gchar *authors[] = {
523 aloha 1.23 "������������ (���������) <alohakun@gmail.com>\n",
524     "Contribute : tkng ������",
525     "(http://d.hatena.ne.jp/tkng/20061113)", NULL
526 aloha 1.11 };
527     gtk_about_dialog_set_authors(about, authors);
528     gtk_about_dialog_set_copyright(about, "Copyright(C)2006 WAKATSUKI Toshihiro");
529     gtk_about_dialog_set_name(about, "��� (SHIKI)");
530     gtk_about_dialog_set_website_label(about, "���������30������������������������������������������������������������Blog");
531     gtk_about_dialog_set_website(about, "http://alohakun.blog7.fc2.com/blog-category-29.html");
532     gtk_dialog_run(GTK_DIALOG(about));
533     gtk_widget_destroy(GTK_WIDGET(about));
534     }
535    
536 aloha 1.37 /* ��������� */
537     static void dummy_handler() {
538 aloha 1.42 GtkWidget *dummy = gtk_message_dialog_new(GTK_WINDOW(Shiki_EDITOR_WINDOW),
539     GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
540     "Sorry... This Button is Dummy.");
541     gtk_dialog_run(GTK_DIALOG(dummy));
542     gtk_widget_destroy(dummy);
543 aloha 1.37 }
544    
545 aloha 1.1 /* ��������������������������������������������������������������� */
546     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer) {
547     GtkTextIter start, end;
548     gtk_text_buffer_get_start_iter(buffer, &start);
549     gtk_text_buffer_get_end_iter(buffer, &end);
550     return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
551     }
552    
553     /* buffer ������������������������ filename ��������� */
554     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer) {
555     gchar *contents, *text;
556     gsize br, bw;
557     GError *err = NULL;
558    
559     if(!filename) return FALSE;
560     contents = get_all_buffer_contents(buffer);
561     text = g_locale_from_utf8(contents, -1, &br, &bw, &err);
562     /* ��������������������������������� */
563     g_file_set_contents(filename, text, -1, NULL);
564     gtk_text_buffer_set_modified(buffer, FALSE);
565 aloha 1.61 Shiki_update_modeline(Shiki_CURRENT_TEXT_BUFFER);
566 aloha 1.1 g_free(contents); g_free(text);
567     return TRUE;
568     }
569    
570     /* ��������������������������������������������������������������������� */
571 aloha 1.27 static void save_file() {
572 aloha 1.1
573 aloha 1.22 /* ��������������������������������������� */
574 aloha 1.60 if(strcmp("*help*", Shiki_CURRENT_TAB_TITLE) == 0) return;
575 aloha 1.33
576 aloha 1.1 /* ������������������������������������ */
577 aloha 1.16 if(!gtk_text_buffer_get_modified(Shiki_CURRENT_TEXT_BUFFER)) return;
578 aloha 1.1
579     /* ������������������������������������������������������������������������������������������������������ */
580 aloha 1.60 if(strcmp("*scratch*", Shiki_CURRENT_FILENAME) == 0) {
581 aloha 1.57 const gchar *filename = Shiki_file_name_dialog("Save File As ...");
582 aloha 1.7 if(!filename) return;
583 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
584 aloha 1.27 gtk_notebook_set_tab_label_text(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
585 aloha 1.16 gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), filename);
586 aloha 1.1 } 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.57 const gchar *filename = Shiki_file_name_dialog("Save File As ...");
593 aloha 1.1
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    
601     /* gauche ��������������������������������� */
602     static gchar *eval_cstring_by_gauche(gchar *s) {
603     gchar *msg;
604    
605     ScmObj result, error;
606     /* ������������������������������ */
607     ScmObj os = Scm_MakeOutputStringPort(TRUE);
608    
609     /* Scheme ��������������������������������������� */
610     /* http://alohakun.blog7.fc2.com/blog-entry-517.html */
611 aloha 1.50 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*input*")), SCM_MAKE_STR_COPYING(s));
612 aloha 1.34 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
613 aloha 1.1
614 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));
615 aloha 1.1
616 aloha 1.34 error = Scm_GlobalVariableRef(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
617 aloha 1.1
618     /* ��������������������������������������������������������� */
619     if (!SCM_FALSEP(error))
620     Scm_Write(error, os, SCM_WRITE_DISPLAY);
621     else
622     Scm_Write(result, os, SCM_WRITE_DISPLAY);
623    
624     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
625     /* ������������������ */
626     Scm_ClosePort(SCM_PORT(os));
627    
628     return msg;
629     }
630    
631 aloha 1.13 /* ������������������������������������������������������������������ S ��������������� (������������) */
632 aloha 1.27 static void load_region_by_gauche() {
633 aloha 1.1
634     GtkTextIter start, end, p;
635     gchar *code;
636 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
637     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
638 aloha 1.1
639     /* ������������������������������������������������������������ */
640 aloha 1.16 if(gtk_text_buffer_get_selection_bounds(Shiki_CURRENT_TEXT_BUFFER, &start, &end)) {
641     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
642     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(code), -1);
643 aloha 1.1 g_free(code);
644     }
645     }
646    
647     // GtkTextCharPredicate
648     static gboolean is_kakko_or_kokka(gunichar ch, gpointer p) {
649     return ch == '(' || ch == ')';
650     }
651 aloha 1.29 static gboolean is_kakko(gunichar ch, gpointer p) {return ch == '(';}
652 aloha 1.1 static gboolean is_kokka(gunichar ch, gpointer p) {return ch == ')';}
653    
654 aloha 1.30 /* ��������������������� '(' ��������������� ')' ������������������ (S ���) ��������������� */
655     static gboolean search_sexp(GtkTextIter *start, GtkTextIter *end) {
656 aloha 1.33
657 aloha 1.30 /* ������������������������������ */
658     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, start, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
659    
660     if(gtk_text_iter_get_char(start) != '(')
661     gtk_text_iter_forward_find_char(start, is_kakko, NULL, NULL);
662    
663     *end = *start;
664    
665     /* ��������������������������������� S ������������������ */
666     if(!search_sexp_kokka(end)) return FALSE;
667     gtk_text_iter_forward_char(end);
668     return TRUE;
669     }
670    
671     static gboolean search_sexp_kokka(GtkTextIter *end) {
672 aloha 1.29 gint nest_level = 0;
673 aloha 1.33
674 aloha 1.30 /* ������������ ')' ��������� */
675 aloha 1.29 while(1) {
676 aloha 1.30 if(!gtk_text_iter_forward_find_char(end, is_kakko_or_kokka, NULL, NULL))
677 aloha 1.29 return FALSE;
678    
679 aloha 1.30 if(gtk_text_iter_get_char(end) == '(')
680 aloha 1.29 nest_level++;
681     else {
682     if(!nest_level)
683     break;
684     else
685     nest_level--;
686     }
687     }
688     return TRUE;
689     }
690 aloha 1.1
691 aloha 1.30 /* ��������������������� ')' ��������������� '(' ������������������ (S ���) ��������������� */
692     static gboolean search_last_sexp(GtkTextIter *start, GtkTextIter *end) {
693    
694     /* ������������������������������ */
695     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
696    
697     gtk_text_iter_backward_char(end);
698 aloha 1.33
699 aloha 1.30 if(gtk_text_iter_get_char(end) != ')')
700     gtk_text_iter_backward_find_char(end, is_kokka, NULL, NULL);
701     *start = *end;
702     gtk_text_iter_forward_char(end);
703    
704     /* ��������������������������������� S ������������������ */
705     if(!search_last_sexp_kakko(start)) return FALSE;
706    
707     return TRUE;
708     }
709    
710 aloha 1.1 /* ')' ��������������� '(' ������������������ (S ���) ��������������� */
711 aloha 1.29 static gboolean search_last_sexp_kakko(GtkTextIter *start) {
712 aloha 1.1 gint nest_level = 0;
713 aloha 1.30 /* ��������������������������������������� ')' ��������� */
714 aloha 1.1 while(1) {
715     if(!gtk_text_iter_backward_find_char(start, is_kakko_or_kokka, NULL, NULL))
716     return FALSE;
717    
718     if(gtk_text_iter_get_char(start) == ')')
719     nest_level++;
720     else {
721     if(!nest_level)
722     break;
723     else
724     nest_level--;
725     }
726     }
727     return TRUE;
728     }
729    
730     /* ������������������������������������������������ */
731     static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer) {
732     gint nest_level = 0;
733     GtkTextIter start, end;
734     gtk_text_buffer_get_start_iter(buffer, &start);
735     if(gtk_text_iter_get_char(&start) == '(') nest_level++;
736    
737     /* ��������������������� (= end) ��������� */
738     gtk_text_buffer_get_iter_at_mark(buffer,&end, gtk_text_buffer_get_insert(buffer));
739    
740     while(1) {
741     /* end ������ '(' ��� ')' ��������������������������������������������� */
742     if(!gtk_text_iter_forward_find_char(&start, is_kakko_or_kokka, NULL, &end))
743     return nest_level;
744    
745     if(gtk_text_iter_get_char(&start) == '(')
746     nest_level++;
747     else
748     nest_level--;
749     }
750     }
751    
752     /* ��������������������������������� on/off */
753     static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook) {
754     gint tval = FALSE;
755     gint bval = FALSE;
756     if(notebook->show_tabs == FALSE)
757     tval = TRUE;
758     if(notebook->show_border == FALSE)
759     bval = TRUE;
760    
761     gtk_notebook_set_show_tabs(notebook, tval);
762     gtk_notebook_set_show_border(notebook, bval);
763     }
764    
765     /* ������������������������ */
766 aloha 1.17 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook ) {
767 aloha 1.1 gtk_notebook_set_tab_pos(notebook, (notebook->tab_pos + 1) % 4);
768     }
769    
770     /* ��������������������� */
771 aloha 1.8 static gboolean signal_key_release_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
772     static gint metakey_pressed = 0;
773 aloha 1.6 static gint controlx_pressed = 0;
774 aloha 1.1
775     if(event->keyval == GDK_parenright && event->state & GDK_SHIFT_MASK) {
776     GtkTextIter start, end;
777    
778     /* ������������������������������ */
779 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
780 aloha 1.1
781     start = end;
782     gtk_text_iter_backward_char(&start);
783    
784     /* ��������������������������������� S ������������������ */
785 aloha 1.29 if(!search_last_sexp_kakko(&start)) return FALSE;
786 aloha 1.1
787 aloha 1.16 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
788 aloha 1.1 }
789    
790     /* ������������������������������������������������������������������������������������������������ (���������������) ������������������ */
791     if(event->keyval == GDK_Return) {
792 aloha 1.61 gint indentWidth = get_parent_nest_level_at_cursor(Shiki_CURRENT_TEXT_BUFFER) * SCM_INT_VALUE(Scm_EvalCString("*indent-width*", Shiki_CURRENT_BUFFER_ENV));
793 aloha 1.1 gchar *indent = g_strnfill(indentWidth, ' ');
794 aloha 1.16 gtk_text_buffer_insert_at_cursor(Shiki_CURRENT_TEXT_BUFFER, indent, -1);
795 aloha 1.1 g_free(indent);
796     }
797    
798 aloha 1.6 /* C-x */
799     if(event->keyval == GDK_x && event->state & GDK_CONTROL_MASK) {
800     controlx_pressed++;
801 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-x -");
802 aloha 1.6 } else if(event->state & GDK_CONTROL_MASK) {
803 aloha 1.8
804 aloha 1.6 if(controlx_pressed > 0) {
805     switch(event->keyval) {
806     case GDK_c :/* C-x C-c : ������ */
807 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-c");
808 aloha 1.6 {/* "delete-event" ��������������������������������������� �� ������������������������������������ */
809     GdkEvent ev;
810    
811     ev.any.type = GDK_DELETE;
812 aloha 1.16 ev.any.window = Shiki_EDITOR_WINDOW->window;
813 aloha 1.6 ev.any.send_event = FALSE;
814     gdk_event_put (&ev);
815     }
816     break;
817    
818     case GDK_f : /* C-x C-f : ������������������ */
819 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-f");
820 aloha 1.60 Shiki_open_file_dialog();
821 aloha 1.6 break;
822    
823     case GDK_s : /* C-x C-s : ������������������ */
824 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-s");
825 aloha 1.27 save_file();
826 aloha 1.6 break;
827    
828     case GDK_w : /* C-x C-w : ������������������������ */
829 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-w");
830 aloha 1.27 save_file_as();
831 aloha 1.6 break;
832     }
833     controlx_pressed = 0;
834     }
835 aloha 1.8
836     switch(event->keyval) {
837     case GDK_g :/* C-g : ��������������� */
838     metakey_pressed = 0;
839     controlx_pressed = 0;
840    
841 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "Quit");
842 aloha 1.8 break;
843     }
844    
845 aloha 1.6 }
846 aloha 1.1 return FALSE;
847     }
848 aloha 1.27 static void open_online_help() {
849 aloha 1.22 GtkTextIter p;
850 aloha 1.57 Shiki_new_buffer_create(g_strdup("*help*"));
851 aloha 1.22 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER,
852 aloha 1.37 "������������������������������������������\n"
853 aloha 1.30 "$ ./shiki [file1 file2 ....]\n\n"
854     "[���������������������������] ��������������������� (C-x C-f)\n"
855     "[������������������������������������������] ��������������������� (C-x C-s)\n"
856     "[���������������������������������������������] ��������������������������� (C-x C-w)\n"
857 aloha 1.37 "[���������������������] ��������������� gauche ������������\n"
858 aloha 1.30 "[��������������� (���������) ���������������] ��������� on/off\n"
859     "[������ (���������) ���������������] ������������������������\n"
860 aloha 1.37 "[������������������] ��������������������������� (C-t)\n"
861 aloha 1.33 "[���������������������������] ������������ (C-_)\n"
862 aloha 1.30 "[���������������������] ������������������������\n"
863 aloha 1.44 "\n"
864     "(��� : ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ Undo ������������������)\n"
865     "\n"
866 aloha 1.37 "[�� ������������] ������������������������ (C-k)\n"
867 aloha 1.30 "[A ������������] ���������������������\n"
868     "[���������������������������] Scheme ������������������������\n"
869     "[���������������������������������] ���������������������������������������\n"
870     "[��������� (?) ������������] ���������������������������������������\n"
871 aloha 1.33 "[info ������������] ���������������������������������������������������\n"
872     "\n"
873 aloha 1.30 "C-f : ��� ��������� (forward)\n"
874     "C-b : ��� ��������� (backward)\n"
875     "C-n : ��� ��������� (next line)\n"
876 aloha 1.33 "C-p : ��� ��������� (previous line)\n"
877     "\n"
878     "C-h : ���������������������\n"
879 aloha 1.31 "C-w : ���������\n"
880 aloha 1.33 "C-y : ��������� (������������)\n"
881     "\n"
882 aloha 1.30 "C-e : ��������������������� S ������������ (eval-expression)\n"
883     "C-j : ��������������������� S ������������ (eval-last-sexp)\n"
884 aloha 1.33 "(emacs/xyzzy ��� *scratch* ���������������������)\n"
885     "\n"
886 aloha 1.31 "C-M-@ : ��������������������� S ������������ (mark-sexp)\n"
887     "C-M-SPC : ��������������������� S ������������ (mark-last-sexp)\n"
888 aloha 1.33 "C-x C-c : ��������������������������� �� ���������������������������������\n"
889 aloha 1.51 "\n"
890     "������������ API\n"
891     "(clear-current-buffer) : ��������������������������������� (������������)\n"
892 aloha 1.44 , -1);
893 aloha 1.30 gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
894     /* ������������������������������ */
895     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
896     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
897 aloha 1.22 }
898    
899 aloha 1.1 /* ��������������������������������������� */
900 aloha 1.54 static void Shiki_editor_window_init(int argc, char **argv) {
901 aloha 1.39 GtkWidget *vbox, *toolbar, *modeline_bg = gtk_event_box_new();
902 aloha 1.1 GtkToolItem *icon;
903     GtkIconSize iconsize;
904 aloha 1.2 GtkTooltips *toolbar_tips = gtk_tooltips_new();
905 aloha 1.1 /* ��������������������������������������������������������������������������������� */
906     GtkToolItem *oicon, *sicon, *saicon, *eicon;
907    
908 aloha 1.36 gint contextid, i;
909    
910     /* ������������������������������������������������������������������������������ */
911     keywords_hash = g_hash_table_new(g_str_hash, g_str_equal);
912     i = 0;
913     while(R5RS_keywords[i] != NULL)
914     g_hash_table_insert(keywords_hash, R5RS_keywords[i++], GINT_TO_POINTER(R5RS_KEYWORD_COLOR));
915     i = 0;
916     while(R5RS_functions[i] != NULL)
917     g_hash_table_insert(keywords_hash, R5RS_functions[i++], GINT_TO_POINTER(R5RS_FUNCTION_COLOR));
918 aloha 1.8
919 aloha 1.1 /* ������������ */
920 aloha 1.16 Shiki_EDITOR_WINDOW = gtk_window_new(GTK_WINDOW_TOPLEVEL);
921     g_signal_connect(G_OBJECT(Shiki_EDITOR_WINDOW), "destroy", G_CALLBACK(gtk_main_quit), NULL);
922 aloha 1.1
923 aloha 1.31 /* ������������������������������������������������������������ */
924     Shiki_EDITOR_CLIPBOARD = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
925    
926 aloha 1.1 /* ������������������������������������ */
927     vbox = gtk_vbox_new(FALSE, 0);
928     /* ��������������������� */
929     toolbar = gtk_toolbar_new();
930     gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
931    
932 aloha 1.26 Shiki_EDITOR_NOTEBOOK = GTK_NOTEBOOK(gtk_notebook_new());
933     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "switch-page", GTK_SIGNAL_FUNC(switch_tabpage_handler), NULL);
934 aloha 1.1
935     /* ������������������������������������������������ */
936     gtk_toolbar_set_style(GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
937     iconsize = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar));
938    
939     /* ������������������ */
940    
941     /* ������������������ */
942 aloha 1.45 oicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_OPEN, iconsize), "");
943 aloha 1.1 /* ������������������������������������������������������������������������������������ */
944 aloha 1.60 g_signal_connect(G_OBJECT(oicon), "clicked", G_CALLBACK(Shiki_open_file_dialog), NULL);
945 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(oicon));
946 aloha 1.2 gtk_tool_item_set_tooltip(oicon, toolbar_tips, "���������������������������",
947     "���������������������������������������������������������������������������������������");
948 aloha 1.1
949     /* ������������������ */
950 aloha 1.45 sicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SAVE, iconsize), "");
951 aloha 1.1 /* ������������������������������������������������������������������������������������ */
952 aloha 1.27 g_signal_connect(G_OBJECT(sicon), "clicked", G_CALLBACK(save_file), NULL);
953 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(sicon));
954 aloha 1.2 gtk_tool_item_set_tooltip(sicon, toolbar_tips, "������������������������������",
955     "������������������������������������������������������������������������������������������������������������������������������������");
956 aloha 1.1
957     /* ��������������������������� */
958 aloha 1.45 saicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SAVE_AS, iconsize), "");
959 aloha 1.1 /* ������������������������������������������������������������������������������������������������������������������ */
960 aloha 1.27 g_signal_connect(G_OBJECT(saicon), "clicked", G_CALLBACK(save_file_as), NULL);
961 aloha 1.2 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(saicon));
962     gtk_tool_item_set_tooltip(saicon, toolbar_tips, "������������������������������������",
963     "");
964 aloha 1.1
965     /* ������������������ */
966 aloha 1.45 eicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_EXECUTE, iconsize), "");
967 aloha 1.14 /* ������������������������������������������ libgauche ������������������ */
968 aloha 1.27 g_signal_connect(G_OBJECT(eicon), "clicked", G_CALLBACK(load_region_by_gauche), NULL);
969 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(eicon));
970 aloha 1.14 gtk_tool_item_set_tooltip(eicon, toolbar_tips, "��������������� S ������������������������ (load-region-lisp)",
971 aloha 1.2 "Scheme (gauche) ������������������ S ������������������������");
972 aloha 1.1
973 aloha 1.16 gtk_container_add(GTK_CONTAINER(Shiki_EDITOR_WINDOW), vbox);
974 aloha 1.26 gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
975 aloha 1.1
976 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_NEW, iconsize), "");
977 aloha 1.33 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(append_default_tabpage_handler), NULL);
978 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
979 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������", "");
980 aloha 1.1
981 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_UNDO, iconsize), "");
982 aloha 1.33 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(undo), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
983     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
984     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Undo","");
985    
986 aloha 1.37 /* XXX : TODO */
987 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_REDO, iconsize), "");
988 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(dummy_handler), NULL);
989     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
990     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Redo", "");
991 aloha 1.37
992 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_FIND, iconsize), "");
993 aloha 1.46 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(search_current_buffer), NULL);
994 aloha 1.37 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
995     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������", "");
996    
997    
998 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_FIND_AND_REPLACE, iconsize), "");
999 aloha 1.47 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(replace_current_buffer), NULL);
1000 aloha 1.37 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1001     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������", "");
1002    
1003 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_REFRESH, iconsize), "");
1004 aloha 1.37 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(dummy_handler), NULL);
1005     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1006     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������", "");
1007    
1008     /* TODO ������������ */
1009    
1010 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DELETE, iconsize), "");
1011 aloha 1.57 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(clear_current_buffer_handler), NULL);
1012 aloha 1.15 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1013     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������",
1014     "���������������������������������������������������������������������");
1015    
1016 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CLOSE, iconsize), "");
1017 aloha 1.58 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(kill_buffer_handler), NULL);
1018 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1019 aloha 1.2 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������",
1020     "���������������������������������������������������������������");
1021 aloha 1.15
1022 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CONNECT, iconsize), "");
1023 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_scheme_file_by_gauche), NULL);
1024 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1025     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Scheme ������������������������", "");
1026    
1027 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CONVERT, iconsize), "");
1028 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_buffer_by_gauche), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1029 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1030     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������", "");
1031    
1032 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SPELL_CHECK, iconsize), "");
1033 aloha 1.37 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(scheme_keyword_highlighting_current_buffer), NULL);
1034     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1035     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
1036    
1037    
1038 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, iconsize), "");
1039 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(open_online_help), NULL);
1040 aloha 1.22 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1041     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������", "");
1042 aloha 1.49
1043 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_BOLD, iconsize), "");
1044 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(select_font), NULL);
1045     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1046     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
1047    
1048 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_APPLY, iconsize), "");
1049 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(tabsborder_on_off), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1050     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1051     gtk_tool_item_set_tooltip(icon, toolbar_tips, "��������� on/off", "");
1052    
1053 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_PREFERENCES, iconsize), "");
1054 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(rotate_tab_position), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1055     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1056     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
1057 aloha 1.22
1058 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, iconsize), "");
1059 aloha 1.11 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(about_this_application), NULL);
1060     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1061     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
1062    
1063 aloha 1.39 /* ������������������������ */
1064     Shiki_EDITOR_MODELINE_LABEL = gtk_label_new(NULL);
1065     gtk_container_add(GTK_CONTAINER (modeline_bg), Shiki_EDITOR_MODELINE_LABEL);
1066 aloha 1.49
1067 aloha 1.39 gdk_color_parse("black", &COLOR_BLACK);
1068     gdk_color_parse("green", &COLOR_GREEN);
1069 aloha 1.49
1070 aloha 1.39 gtk_widget_modify_fg(Shiki_EDITOR_MODELINE_LABEL, GTK_STATE_NORMAL, &COLOR_GREEN);
1071     gtk_widget_modify_bg(modeline_bg, GTK_STATE_NORMAL, &COLOR_BLACK);
1072    
1073     gtk_box_pack_start(GTK_BOX(vbox), modeline_bg, TRUE, TRUE, 0);
1074 aloha 1.12
1075 aloha 1.8 /* C-x C-s ��������������������������������������������������������������������������������������� */
1076 aloha 1.16 Shiki_EDITOR_STATUSBAR = gtk_statusbar_new();
1077     gtk_box_pack_start(GTK_BOX(vbox), Shiki_EDITOR_STATUSBAR, TRUE, TRUE, 0);
1078     contextid = gtk_statusbar_get_context_id(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), "");
1079 aloha 1.8
1080     /* ������������������������������������������������ */
1081 aloha 1.26 g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-press-event", G_CALLBACK (signal_key_press_handler), GINT_TO_POINTER(contextid));
1082     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-release-event", G_CALLBACK (signal_key_release_handler), GINT_TO_POINTER(contextid));
1083 aloha 1.12
1084 aloha 1.21 /* ��������������������������������������������� */
1085     if(argc >= 2) {
1086     int i;
1087     for(i = 1; i < argc; i++)
1088 aloha 1.60 Shiki_create_file_buffer(argv[i]);
1089 aloha 1.21 } else /* ������������������������������������������������������������������ */
1090 aloha 1.26 open_online_help(Shiki_EDITOR_NOTEBOOK);
1091 aloha 1.8
1092 aloha 1.26 gtk_widget_grab_focus(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
1093 aloha 1.16 gtk_widget_show_all(Shiki_EDITOR_WINDOW);
1094 aloha 1.1 }
1095    
1096     int main(int argc, char *argv[]) {
1097     /* ������������������������������������ */
1098 aloha 1.39 Shiki_EDITOR_DEFAULT_LOCALE = g_locale_to_utf8(gtk_set_locale(), -1, NULL, NULL, NULL);
1099 aloha 1.1 gtk_init(&argc, &argv);
1100     GC_INIT(); Scm_Init(GAUCHE_SIGNATURE);
1101 aloha 1.50 Scm_Load("gauche-init.scm", 0);
1102 aloha 1.54 Shiki_editor_window_init(argc, argv);
1103 aloha 1.1 gtk_main();
1104     Scm_Exit(0);
1105     return 0;
1106     }

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