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.66 - (hide annotations) (download) (as text)
Sat Feb 3 09:48:01 2007 UTC (17 years, 2 months ago) by aloha
Branch: MAIN
Changes since 1.65: +9 -14 lines
File MIME type: text/x-csrc
response Gauche 0.8.8 (so require gauche and gauche-dev >= 0.8.8)

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.66 * $Id: shiki.c,v 1.65 2006/12/28 05:04:45 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.25
66 aloha 1.65
67     /* FIXME !!!!!! : ��������������������������� SEGV ������������ !!!!!!!!!!!!!!!!!!!!!! */
68    
69    
70 aloha 1.46 /* Gauche ��� S ��������������������������������������������������������������������������� */
71 aloha 1.25 static gchar *load_cstring_by_gauche(gchar *s);
72     static void load_buffer_by_gauche();
73 aloha 1.27 static void load_region_by_gauche();
74     static void load_scheme_file_by_gauche();
75 aloha 1.17 static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer);
76 aloha 1.46 static gboolean is_not_scheme_delimita_p(gunichar ch, gpointer user_data);
77     static gboolean is_double_quote(gunichar ch, gpointer user_data);
78     static gboolean is_scheme_delimita_p(gunichar ch, gpointer user_data);
79     static void scheme_keyword_highlighting_current_buffer();
80 aloha 1.25
81     /* ������ */
82     static void select_font();
83     static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog);
84 aloha 1.18 static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) ;
85 aloha 1.17 static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook);
86 aloha 1.27 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook);
87 aloha 1.25
88     /* ������������������������ */
89 aloha 1.22 static gboolean signal_key_press_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid);
90     static gboolean signal_key_release_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid);
91 aloha 1.25
92     /* ������������������ */
93 aloha 1.27 static void open_online_help();
94 aloha 1.25 static void about_this_application();
95    
96 aloha 1.27 /* ������������������������ */
97 aloha 1.54 static void Shiki_editor_window_init(int argc, char **argv);
98 aloha 1.52
99 aloha 1.51 /* ������������������������������ */
100 aloha 1.57 static void clear_current_buffer_handler() {
101     Shiki_erase_buffer(Shiki_CURRENT_TEXT_BUFFER);
102 aloha 1.51 }
103    
104 aloha 1.35 static gboolean is_not_scheme_delimita_p(gunichar ch, gpointer user_data) {
105 aloha 1.36 return ch != '(' && ch != ')' && !g_unichar_isspace(ch);
106     }
107    
108     static gboolean is_double_quote(gunichar ch, gpointer user_data) {
109     return ch == '\"';
110 aloha 1.35 }
111    
112     static gboolean is_scheme_delimita_p(gunichar ch, gpointer user_data) {
113 aloha 1.36 return ch == ' ' || ch == '(' || ch == ')' || ch == '\"' || g_unichar_isspace(ch);
114 aloha 1.35 }
115    
116     /* ������������������������������ */
117     static void scheme_keyword_highlighting_current_buffer() {
118     GtkTextIter s, e;
119     HIGHILIGHT_COLOR c;
120     gchar *word;
121 aloha 1.36 gboolean is_comment, is_string;
122     gunichar ch;
123 aloha 1.35
124     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &s);
125    
126     /* ��������� Scheme ������������������������������ */
127     while(TRUE) {
128 aloha 1.36 is_comment = FALSE;
129     is_string = FALSE;
130     if((ch = gtk_text_iter_get_char(&s)) != ';' && ch != '\"')
131 aloha 1.35 gtk_text_iter_forward_find_char(&s, is_not_scheme_delimita_p, NULL, NULL);
132     e = s;
133     if(gtk_text_iter_get_char(&s) == ';') {
134     gtk_text_iter_forward_line(&e);
135     gtk_text_iter_backward_char(&e);
136     is_comment = TRUE;
137 aloha 1.36 } else if(gtk_text_iter_get_char(&s) == '\"') {
138     while(TRUE) {
139     gtk_text_iter_forward_find_char(&e, is_double_quote, NULL, NULL);
140     gtk_text_iter_backward_char(&e);
141     if(gtk_text_iter_get_char(&e) != '\\') {
142     is_string = TRUE;
143     gtk_text_iter_forward_char(&e);
144     gtk_text_iter_forward_char(&e);
145     break;
146     }
147     gtk_text_iter_forward_char(&e);
148     gtk_text_iter_forward_char(&e);
149     }
150    
151 aloha 1.35 } else
152     gtk_text_iter_forward_find_char(&e, is_scheme_delimita_p, NULL, NULL);
153    
154     word = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &s, &e, FALSE);
155 aloha 1.36
156     /* ������������������������������������������������������������ */
157     if(is_comment) /* ������������ */
158 aloha 1.35 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "comment_highlighting", &s, &e);
159 aloha 1.36 else if(is_string) /* ��������� */
160     gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "string_highlighting", &s, &e);
161     else if(R5RS_KEYWORD_COLOR == (c = GPOINTER_TO_INT(g_hash_table_lookup(keywords_hash, word)))) /* R5RS ��������������� */
162 aloha 1.35 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "keyword_highlighting", &s, &e);
163 aloha 1.36 else if(R5RS_FUNCTION_COLOR == c) /* R5RS ������ */
164 aloha 1.35 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "function_highlighting", &s, &e);
165    
166 aloha 1.36 /* XXX : get_text() ������������������������������������������������������������������������������������������������������ GtkTextBuffer ������ const gchar * ������������������������������ */
167     g_free(word);
168 aloha 1.35
169     if(gtk_text_iter_is_end(&e)) break;
170     s = e;
171     }
172     }
173    
174 aloha 1.32 /* ������������������������������������������������������������ */
175     static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) {
176     /* ��������������������������������������������������������������������� */
177 aloha 1.55 Shiki_CURRENT_TAB_INFO = (ShikiBuffer *)g_list_nth_data(Shiki_EDITOR_BUFFER_LIST, pagenum);
178 aloha 1.32
179     /* ������������������������������������ */
180     Shiki_CURRENT_TAB_NUM = pagenum;
181    
182     /* ������������������������������������������������������ */
183     if(!Shiki_CURRENT_TAB_INFO) return;
184     gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), Shiki_CURRENT_FILENAME);
185    
186 aloha 1.61 Shiki_update_modeline(Shiki_CURRENT_TEXT_BUFFER);
187 aloha 1.32 }
188    
189 aloha 1.63 /* GtkTextCharPredicate */
190     static gboolean is_kakko_or_kokka(gunichar ch, gpointer p) {
191     return ch == '(' || ch == ')';
192     }
193     static gboolean is_kakko(gunichar ch, gpointer p) {return ch == '(';}
194     static gboolean is_kokka(gunichar ch, gpointer p) {return ch == ')';}
195    
196     static gboolean search_sexp_kokka(GtkTextIter *end) {
197     gint nest_level = 0;
198    
199     /* ������������ ')' ��������� */
200     while(1) {
201     if(!gtk_text_iter_forward_find_char(end, is_kakko_or_kokka, NULL, NULL))
202     return FALSE;
203    
204     if(gtk_text_iter_get_char(end) == '(')
205     nest_level++;
206     else {
207     if(!nest_level)
208     break;
209     else
210     nest_level--;
211     }
212     }
213     return TRUE;
214     }
215    
216     /* ��������������������� '(' ��������������� ')' ������������������ (S ���) ��������������� */
217     static gboolean search_sexp(GtkTextIter *start, GtkTextIter *end) {
218    
219     /* ������������������������������ */
220     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, start, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
221    
222     if(gtk_text_iter_get_char(start) != '(')
223     gtk_text_iter_forward_find_char(start, is_kakko, NULL, NULL);
224    
225     *end = *start;
226    
227     /* ��������������������������������� S ������������������ */
228     if(!search_sexp_kokka(end)) return FALSE;
229     gtk_text_iter_forward_char(end);
230     return TRUE;
231     }
232    
233     /* ')' ��������������� '(' ������������������ (S ���) ��������������� */
234     static gboolean search_last_sexp_kakko(GtkTextIter *start) {
235     gint nest_level = 0;
236     /* ��������������������������������������� ')' ��������� */
237     while(1) {
238     if(!gtk_text_iter_backward_find_char(start, is_kakko_or_kokka, NULL, NULL))
239     return FALSE;
240    
241     if(gtk_text_iter_get_char(start) == ')')
242     nest_level++;
243     else {
244     if(!nest_level)
245     break;
246     else
247     nest_level--;
248     }
249     }
250     return TRUE;
251     }
252    
253     /* ��������������������� ')' ��������������� '(' ������������������ (S ���) ��������������� */
254     static gboolean search_last_sexp(GtkTextIter *start, GtkTextIter *end) {
255    
256     /* ������������������������������ */
257     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
258    
259     gtk_text_iter_backward_char(end);
260    
261     if(gtk_text_iter_get_char(end) != ')')
262     gtk_text_iter_backward_find_char(end, is_kokka, NULL, NULL);
263     *start = *end;
264     gtk_text_iter_forward_char(end);
265    
266     /* ��������������������������������� S ������������������ */
267     if(!search_last_sexp_kakko(start)) return FALSE;
268    
269     return TRUE;
270     }
271    
272 aloha 1.32 /* ��������������������� */
273     static gboolean signal_key_press_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
274     GtkTextIter start, end;
275    
276     /* ������������������������������������ */
277     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &start);
278     gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &end);
279     gtk_text_buffer_remove_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
280    
281     if(event->state & GDK_CONTROL_MASK && event->state & GDK_MOD1_MASK) {
282     switch(event->keyval) {
283     case GDK_at : /* C-M-SPC */
284     { GtkTextIter start, end;
285     if(!search_sexp(&start, &end)) return FALSE;
286     gtk_text_buffer_select_range(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
287     }
288     break;
289     case GDK_space : /* C-M-SPC */
290     { GtkTextIter start, end;
291     if(!search_last_sexp(&start, &end)) return FALSE;
292     gtk_text_buffer_select_range(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
293     }
294     break;
295     }
296     } else if(event->state & GDK_CONTROL_MASK) {
297     switch(event->keyval) {
298     case GDK_f : /* Ctrl + f : forward */
299 aloha 1.57 Shiki_forward_char();
300 aloha 1.32 break;
301     case GDK_b : /* Ctrl + b : backward */
302 aloha 1.57 Shiki_backward_char();
303 aloha 1.32 break;
304     case GDK_n : /* Ctrl + n : next line */
305 aloha 1.57 Shiki_forward_line(1);
306 aloha 1.32 break;
307     case GDK_p : /* Ctrl + p : previous line */
308 aloha 1.57 Shiki_forward_line(-1);
309 aloha 1.32 break;
310     case GDK_h :
311     { GtkTextIter p;
312     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
313     gtk_text_buffer_backspace(Shiki_CURRENT_TEXT_BUFFER, &p, FALSE, TRUE);
314     }
315     break;
316    
317     case GDK_e : /* Ctrl + e : eval-expression */
318 aloha 1.63 Shiki_eval_expression();
319 aloha 1.32 break;
320    
321     case GDK_j : /* Ctrl + j : eval-last-sexp */
322 aloha 1.63 Shiki_eval_last_sexp();
323 aloha 1.32 break;
324    
325 aloha 1.64 case GDK_backslash : /* Ctrl + \ : Undo */
326 aloha 1.62 Shiki_undo();
327 aloha 1.32 break;
328    
329 aloha 1.64 case GDK_underscore : /* Ctrl + _ : Redo */
330     Shiki_redo();
331     break;
332    
333 aloha 1.32 case GDK_t : /* Ctrl + t : ��������������� */
334 aloha 1.33 append_default_tabpage_handler();
335 aloha 1.32 break;
336    
337     case GDK_k : /* Ctrl + k : ������������������ */
338 aloha 1.58 kill_buffer_handler();
339 aloha 1.32 break;
340    
341     case GDK_w : /* Ctrl + w : ��������� */
342     gtk_text_buffer_cut_clipboard(Shiki_CURRENT_TEXT_BUFFER, Shiki_EDITOR_CLIPBOARD, TRUE);
343     break;
344    
345     case GDK_y : /* Ctrl + y : ��������� */
346     {GtkTextIter p;
347     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
348     gtk_text_buffer_paste_clipboard(Shiki_CURRENT_TEXT_BUFFER, Shiki_EDITOR_CLIPBOARD, &p, TRUE);
349     }
350     break;
351     }
352     }
353     return FALSE;
354     }
355    
356 aloha 1.33 static void append_default_tabpage_handler() {
357 aloha 1.57 Shiki_new_buffer_create(g_strdup("*scratch*"));
358 aloha 1.33 }
359    
360 aloha 1.23 /* ������������������������������������������ (������������) ��������� */
361 aloha 1.58 static void kill_buffer_handler() {
362     Shiki_kill_buffer(Shiki_CURRENT_TEXT_BUFFER);
363 aloha 1.23 }
364    
365 aloha 1.14 /* ������������������������������������ */
366     static void load_buffer_by_gauche() {
367     GtkTextIter p;
368 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
369     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
370     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(get_all_buffer_contents(Shiki_CURRENT_TEXT_BUFFER)), -1);
371 aloha 1.14 }
372    
373 aloha 1.65
374    
375 aloha 1.14 /* ������������������������ */
376 aloha 1.27 static void load_scheme_file_by_gauche() {
377 aloha 1.57 const gchar *filename = Shiki_file_name_dialog("File Selection");
378 aloha 1.14
379     if(!filename) return;
380 aloha 1.65 Shiki_load_file(filename);
381     }
382    
383     static gint compBuffer(gconstpointer a, gconstpointer b) {
384     return ((ShikiBuffer *)a)->text_buffer == b ? 0 : b - a;
385     }
386 aloha 1.33
387 aloha 1.65 /* ��������������������������������������������������������������������������������������������� */
388     static void reload_buffer() {
389     #if 0
390     Shiki_CURRENT_BUFFER_ENV = Scm_MakeModule(NULL, FALSE);
391    
392     /* xyzzy lisp ��������������� */
393     Scm_Init_xyzzylisp(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV));
394     Scm_EvalCString("(set! *mode-line-format* (lambda () (format #f \"--~A- ~A (Gauche Interaction) [GtkDefault (utf8)] L~S:~S \" (if (buffer-modified-p) \"--\" \"**\") (buffer-name (selected-buffer)) (current-line-number) (current-column))))", Shiki_CURRENT_BUFFER_ENV);
395     #endif
396 aloha 1.14
397 aloha 1.65 Shiki_load_file(Shiki_CURRENT_FILENAME);
398 aloha 1.14 }
399    
400 aloha 1.65
401 aloha 1.13 /* gauche ������������������������������������ */
402     static gchar *load_cstring_by_gauche(gchar *s) {
403     gchar *msg;
404 aloha 1.66 gint result, i;
405     ScmEvalPacket packet;
406 aloha 1.13 /* ��������������������������������� */
407 aloha 1.50 ScmObj is = Scm_MakeInputStringPort(SCM_STRING(SCM_MAKE_STR_COPYING(s)), TRUE);
408 aloha 1.13 /* ������������������������������ */
409     ScmObj os = Scm_MakeOutputStringPort(TRUE);
410    
411 aloha 1.34 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*input*")), is);
412 aloha 1.66 result = Scm_EvalCString("(load-from-port *input*)", SCM_OBJ(Shiki_CURRENT_BUFFER_ENV), &packet);
413    
414     if(result == -1)
415     Scm_Write(packet.exception, os, SCM_WRITE_DISPLAY);
416 aloha 1.13 else
417 aloha 1.66 for(i = 0; i < packet.numResults; i++)
418     Scm_Printf(SCM_PORT(os), "%S\n", packet.results[i]);
419 aloha 1.13
420     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
421     /* ������������������ */
422     Scm_ClosePort(SCM_PORT(is));
423     Scm_ClosePort(SCM_PORT(os));
424    
425     return msg;
426     }
427    
428 aloha 1.12 static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog) {
429     gchar *font_name = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (font_dialog));
430     if(font_name) {
431     GtkRcStyle *style = gtk_rc_style_new ();
432     pango_font_description_free(style->font_desc);
433     style->font_desc = pango_font_description_from_string(font_name);
434 aloha 1.16 gtk_widget_modify_style (GTK_WIDGET(Shiki_CURRENT_TEXT_VIEW), style);
435 aloha 1.44 gtk_rc_style_unref (style);
436 aloha 1.12 g_free (font_name);
437     }
438     }
439    
440 aloha 1.14 /* ������������������������������������������������������ */
441 aloha 1.12 static void select_font(){
442     GtkWidget *font_dialog = gtk_font_selection_dialog_new("Font Selection Dialog");
443     g_signal_connect (GTK_FONT_SELECTION_DIALOG (font_dialog)->ok_button, "clicked", G_CALLBACK(font_selection_ok), font_dialog);
444     gtk_dialog_run(GTK_DIALOG(font_dialog));
445     gtk_widget_destroy(font_dialog);
446     }
447    
448 aloha 1.11 /* ������������������������������������������ */
449     static void about_this_application() {
450     GtkAboutDialog *about = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
451     const gchar *authors[] = {
452 aloha 1.23 "������������ (���������) <alohakun@gmail.com>\n",
453     "Contribute : tkng ������",
454     "(http://d.hatena.ne.jp/tkng/20061113)", NULL
455 aloha 1.11 };
456     gtk_about_dialog_set_authors(about, authors);
457     gtk_about_dialog_set_copyright(about, "Copyright(C)2006 WAKATSUKI Toshihiro");
458     gtk_about_dialog_set_name(about, "��� (SHIKI)");
459     gtk_about_dialog_set_website_label(about, "���������30������������������������������������������������������������Blog");
460     gtk_about_dialog_set_website(about, "http://alohakun.blog7.fc2.com/blog-category-29.html");
461     gtk_dialog_run(GTK_DIALOG(about));
462     gtk_widget_destroy(GTK_WIDGET(about));
463     }
464    
465 aloha 1.65 #if 0
466     /* ��������������������������������������������������������������� */
467 aloha 1.37 static void dummy_handler() {
468 aloha 1.42 GtkWidget *dummy = gtk_message_dialog_new(GTK_WINDOW(Shiki_EDITOR_WINDOW),
469     GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
470     "Sorry... This Button is Dummy.");
471     gtk_dialog_run(GTK_DIALOG(dummy));
472     gtk_widget_destroy(dummy);
473 aloha 1.37 }
474 aloha 1.65 #endif
475 aloha 1.37
476 aloha 1.1 /* ��������������������������������������������������������������� */
477     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer) {
478     GtkTextIter start, end;
479     gtk_text_buffer_get_start_iter(buffer, &start);
480     gtk_text_buffer_get_end_iter(buffer, &end);
481     return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
482     }
483    
484     /* buffer ������������������������ filename ��������� */
485     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer) {
486     gchar *contents, *text;
487     gsize br, bw;
488     GError *err = NULL;
489    
490     if(!filename) return FALSE;
491     contents = get_all_buffer_contents(buffer);
492     text = g_locale_from_utf8(contents, -1, &br, &bw, &err);
493     /* ��������������������������������� */
494     g_file_set_contents(filename, text, -1, NULL);
495     gtk_text_buffer_set_modified(buffer, FALSE);
496 aloha 1.61 Shiki_update_modeline(Shiki_CURRENT_TEXT_BUFFER);
497 aloha 1.1 g_free(contents); g_free(text);
498     return TRUE;
499     }
500    
501     /* ��������������������������������������������������������������������� */
502 aloha 1.27 static void save_file() {
503 aloha 1.1
504 aloha 1.22 /* ��������������������������������������� */
505 aloha 1.60 if(strcmp("*help*", Shiki_CURRENT_TAB_TITLE) == 0) return;
506 aloha 1.33
507 aloha 1.1 /* ������������������������������������ */
508 aloha 1.16 if(!gtk_text_buffer_get_modified(Shiki_CURRENT_TEXT_BUFFER)) return;
509 aloha 1.1
510     /* ������������������������������������������������������������������������������������������������������ */
511 aloha 1.60 if(strcmp("*scratch*", Shiki_CURRENT_FILENAME) == 0) {
512 aloha 1.57 const gchar *filename = Shiki_file_name_dialog("Save File As ...");
513 aloha 1.7 if(!filename) return;
514 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
515 aloha 1.27 gtk_notebook_set_tab_label_text(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
516 aloha 1.16 gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), filename);
517 aloha 1.1 } else
518 aloha 1.16 save_text_buffer(Shiki_CURRENT_TAB_TITLE, Shiki_CURRENT_TEXT_BUFFER);
519 aloha 1.1 }
520    
521     /* ��������������������������������������������������������������������������� */
522 aloha 1.27 static void save_file_as() {
523 aloha 1.57 const gchar *filename = Shiki_file_name_dialog("Save File As ...");
524 aloha 1.1
525 aloha 1.7 if(!filename) return;
526 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
527 aloha 1.1
528 aloha 1.27 gtk_notebook_set_tab_label_text(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
529 aloha 1.16 gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
530 aloha 1.1 }
531    
532 aloha 1.13 /* ������������������������������������������������������������������ S ��������������� (������������) */
533 aloha 1.27 static void load_region_by_gauche() {
534 aloha 1.1
535     GtkTextIter start, end, p;
536     gchar *code;
537 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
538     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
539 aloha 1.1
540     /* ������������������������������������������������������������ */
541 aloha 1.16 if(gtk_text_buffer_get_selection_bounds(Shiki_CURRENT_TEXT_BUFFER, &start, &end)) {
542     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
543     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(code), -1);
544 aloha 1.1 g_free(code);
545     }
546     }
547    
548     /* ������������������������������������������������ */
549     static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer) {
550     gint nest_level = 0;
551     GtkTextIter start, end;
552     gtk_text_buffer_get_start_iter(buffer, &start);
553     if(gtk_text_iter_get_char(&start) == '(') nest_level++;
554    
555     /* ��������������������� (= end) ��������� */
556     gtk_text_buffer_get_iter_at_mark(buffer,&end, gtk_text_buffer_get_insert(buffer));
557    
558     while(1) {
559     /* end ������ '(' ��� ')' ��������������������������������������������� */
560     if(!gtk_text_iter_forward_find_char(&start, is_kakko_or_kokka, NULL, &end))
561     return nest_level;
562    
563     if(gtk_text_iter_get_char(&start) == '(')
564     nest_level++;
565     else
566     nest_level--;
567     }
568     }
569    
570     /* ��������������������������������� on/off */
571     static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook) {
572     gint tval = FALSE;
573     gint bval = FALSE;
574     if(notebook->show_tabs == FALSE)
575     tval = TRUE;
576     if(notebook->show_border == FALSE)
577     bval = TRUE;
578    
579     gtk_notebook_set_show_tabs(notebook, tval);
580     gtk_notebook_set_show_border(notebook, bval);
581     }
582    
583     /* ������������������������ */
584 aloha 1.17 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook ) {
585 aloha 1.1 gtk_notebook_set_tab_pos(notebook, (notebook->tab_pos + 1) % 4);
586     }
587    
588     /* ��������������������� */
589 aloha 1.8 static gboolean signal_key_release_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
590     static gint metakey_pressed = 0;
591 aloha 1.6 static gint controlx_pressed = 0;
592 aloha 1.1
593     if(event->keyval == GDK_parenright && event->state & GDK_SHIFT_MASK) {
594     GtkTextIter start, end;
595    
596     /* ������������������������������ */
597 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
598 aloha 1.1
599     start = end;
600     gtk_text_iter_backward_char(&start);
601    
602     /* ��������������������������������� S ������������������ */
603 aloha 1.29 if(!search_last_sexp_kakko(&start)) return FALSE;
604 aloha 1.1
605 aloha 1.16 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
606 aloha 1.1 }
607    
608     /* ������������������������������������������������������������������������������������������������ (���������������) ������������������ */
609     if(event->keyval == GDK_Return) {
610 aloha 1.62 gint indentWidth = get_parent_nest_level_at_cursor(Shiki_CURRENT_TEXT_BUFFER) * SCM_INT_VALUE(Scm_GlobalVariableRef(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*indent-width*")), 0)), i;
611     static gchar *indent = " ";
612     for(i = 0; i < indentWidth; i++)
613     gtk_text_buffer_insert_at_cursor(Shiki_CURRENT_TEXT_BUFFER, indent, -1);
614 aloha 1.1 }
615    
616 aloha 1.6 /* C-x */
617     if(event->keyval == GDK_x && event->state & GDK_CONTROL_MASK) {
618     controlx_pressed++;
619 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-x -");
620 aloha 1.6 } else if(event->state & GDK_CONTROL_MASK) {
621 aloha 1.8
622 aloha 1.6 if(controlx_pressed > 0) {
623     switch(event->keyval) {
624     case GDK_c :/* C-x C-c : ������ */
625 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-c");
626 aloha 1.6 {/* "delete-event" ��������������������������������������� �� ������������������������������������ */
627     GdkEvent ev;
628    
629     ev.any.type = GDK_DELETE;
630 aloha 1.16 ev.any.window = Shiki_EDITOR_WINDOW->window;
631 aloha 1.6 ev.any.send_event = FALSE;
632     gdk_event_put (&ev);
633     }
634     break;
635    
636     case GDK_f : /* C-x C-f : ������������������ */
637 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-f");
638 aloha 1.60 Shiki_open_file_dialog();
639 aloha 1.6 break;
640    
641     case GDK_s : /* C-x C-s : ������������������ */
642 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-s");
643 aloha 1.27 save_file();
644 aloha 1.6 break;
645    
646     case GDK_w : /* C-x C-w : ������������������������ */
647 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-w");
648 aloha 1.27 save_file_as();
649 aloha 1.6 break;
650     }
651     controlx_pressed = 0;
652     }
653 aloha 1.8
654     switch(event->keyval) {
655     case GDK_g :/* C-g : ��������������� */
656     metakey_pressed = 0;
657     controlx_pressed = 0;
658    
659 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "Quit");
660 aloha 1.8 break;
661     }
662    
663 aloha 1.6 }
664 aloha 1.1 return FALSE;
665     }
666 aloha 1.27 static void open_online_help() {
667 aloha 1.22 GtkTextIter p;
668 aloha 1.57 Shiki_new_buffer_create(g_strdup("*help*"));
669 aloha 1.22 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER,
670 aloha 1.37 "������������������������������������������\n"
671 aloha 1.30 "$ ./shiki [file1 file2 ....]\n\n"
672     "[���������������������������] ��������������������� (C-x C-f)\n"
673     "[������������������������������������������] ��������������������� (C-x C-s)\n"
674     "[���������������������������������������������] ��������������������������� (C-x C-w)\n"
675 aloha 1.37 "[���������������������] ��������������� gauche ������������\n"
676     "[������������������] ��������������������������� (C-t)\n"
677 aloha 1.65 "[���������������������������] ������������ (Undo) (C-\\)\n"
678     "[���������������������������] ��������� (Redo) (C-_)\n"
679     "[���������] ������\n"
680     "[������������������] ������\n"
681 aloha 1.30 "[���������������������] ������������������������\n"
682 aloha 1.44 "\n"
683     "(��� : ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ Undo ������������������)\n"
684     "\n"
685 aloha 1.37 "[�� ������������] ������������������������ (C-k)\n"
686 aloha 1.30 "[A ������������] ���������������������\n"
687     "[���������������������������] Scheme ������������������������\n"
688     "[���������������������������������] ���������������������������������������\n"
689 aloha 1.65 "[Abc] ������������������������������������������\n"
690 aloha 1.30 "[��������� (?) ������������] ���������������������������������������\n"
691 aloha 1.65 "[A] ���������������������\n"
692     "[��������������� (���������) ���������������] ��������� on/off\n"
693     "[������ (���������) ���������������] ������������������������\n"
694 aloha 1.33 "[info ������������] ���������������������������������������������������\n"
695     "\n"
696 aloha 1.30 "C-f : ��� ��������� (forward)\n"
697     "C-b : ��� ��������� (backward)\n"
698     "C-n : ��� ��������� (next line)\n"
699 aloha 1.33 "C-p : ��� ��������� (previous line)\n"
700     "\n"
701     "C-h : ���������������������\n"
702 aloha 1.31 "C-w : ���������\n"
703 aloha 1.33 "C-y : ��������� (������������)\n"
704 aloha 1.64 "C-\\ : Undo\n"
705     "C-_ : Redo\n"
706 aloha 1.33 "\n"
707 aloha 1.30 "C-e : ��������������������� S ������������ (eval-expression)\n"
708     "C-j : ��������������������� S ������������ (eval-last-sexp)\n"
709 aloha 1.33 "(emacs/xyzzy ��� *scratch* ���������������������)\n"
710     "\n"
711 aloha 1.31 "C-M-@ : ��������������������� S ������������ (mark-sexp)\n"
712     "C-M-SPC : ��������������������� S ������������ (mark-last-sexp)\n"
713 aloha 1.33 "C-x C-c : ��������������������������� �� ���������������������������������\n"
714 aloha 1.44 , -1);
715 aloha 1.30 gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
716     /* ������������������������������ */
717     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
718     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
719 aloha 1.63 gtk_text_view_set_editable(Shiki_CURRENT_TEXT_VIEW, FALSE);
720 aloha 1.22 }
721    
722 aloha 1.1 /* ��������������������������������������� */
723 aloha 1.54 static void Shiki_editor_window_init(int argc, char **argv) {
724 aloha 1.39 GtkWidget *vbox, *toolbar, *modeline_bg = gtk_event_box_new();
725 aloha 1.1 GtkToolItem *icon;
726     GtkIconSize iconsize;
727 aloha 1.2 GtkTooltips *toolbar_tips = gtk_tooltips_new();
728 aloha 1.1 /* ��������������������������������������������������������������������������������� */
729     GtkToolItem *oicon, *sicon, *saicon, *eicon;
730    
731 aloha 1.36 gint contextid, i;
732    
733     /* ������������������������������������������������������������������������������ */
734     keywords_hash = g_hash_table_new(g_str_hash, g_str_equal);
735     i = 0;
736     while(R5RS_keywords[i] != NULL)
737     g_hash_table_insert(keywords_hash, R5RS_keywords[i++], GINT_TO_POINTER(R5RS_KEYWORD_COLOR));
738     i = 0;
739     while(R5RS_functions[i] != NULL)
740     g_hash_table_insert(keywords_hash, R5RS_functions[i++], GINT_TO_POINTER(R5RS_FUNCTION_COLOR));
741 aloha 1.8
742 aloha 1.1 /* ������������ */
743 aloha 1.16 Shiki_EDITOR_WINDOW = gtk_window_new(GTK_WINDOW_TOPLEVEL);
744     g_signal_connect(G_OBJECT(Shiki_EDITOR_WINDOW), "destroy", G_CALLBACK(gtk_main_quit), NULL);
745 aloha 1.1
746 aloha 1.31 /* ������������������������������������������������������������ */
747     Shiki_EDITOR_CLIPBOARD = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
748    
749 aloha 1.1 /* ������������������������������������ */
750     vbox = gtk_vbox_new(FALSE, 0);
751     /* ��������������������� */
752     toolbar = gtk_toolbar_new();
753     gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
754    
755 aloha 1.26 Shiki_EDITOR_NOTEBOOK = GTK_NOTEBOOK(gtk_notebook_new());
756     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "switch-page", GTK_SIGNAL_FUNC(switch_tabpage_handler), NULL);
757 aloha 1.1
758     /* ������������������������������������������������ */
759     gtk_toolbar_set_style(GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
760     iconsize = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar));
761    
762     /* ������������������ */
763    
764     /* ������������������ */
765 aloha 1.45 oicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_OPEN, iconsize), "");
766 aloha 1.1 /* ������������������������������������������������������������������������������������ */
767 aloha 1.60 g_signal_connect(G_OBJECT(oicon), "clicked", G_CALLBACK(Shiki_open_file_dialog), NULL);
768 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(oicon));
769 aloha 1.2 gtk_tool_item_set_tooltip(oicon, toolbar_tips, "���������������������������",
770     "���������������������������������������������������������������������������������������");
771 aloha 1.1
772     /* ������������������ */
773 aloha 1.45 sicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SAVE, iconsize), "");
774 aloha 1.1 /* ������������������������������������������������������������������������������������ */
775 aloha 1.27 g_signal_connect(G_OBJECT(sicon), "clicked", G_CALLBACK(save_file), NULL);
776 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(sicon));
777 aloha 1.2 gtk_tool_item_set_tooltip(sicon, toolbar_tips, "������������������������������",
778     "������������������������������������������������������������������������������������������������������������������������������������");
779 aloha 1.1
780     /* ��������������������������� */
781 aloha 1.45 saicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SAVE_AS, iconsize), "");
782 aloha 1.1 /* ������������������������������������������������������������������������������������������������������������������ */
783 aloha 1.27 g_signal_connect(G_OBJECT(saicon), "clicked", G_CALLBACK(save_file_as), NULL);
784 aloha 1.2 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(saicon));
785     gtk_tool_item_set_tooltip(saicon, toolbar_tips, "������������������������������������",
786     "");
787 aloha 1.1
788     /* ������������������ */
789 aloha 1.45 eicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_EXECUTE, iconsize), "");
790 aloha 1.14 /* ������������������������������������������ libgauche ������������������ */
791 aloha 1.27 g_signal_connect(G_OBJECT(eicon), "clicked", G_CALLBACK(load_region_by_gauche), NULL);
792 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(eicon));
793 aloha 1.14 gtk_tool_item_set_tooltip(eicon, toolbar_tips, "��������������� S ������������������������ (load-region-lisp)",
794 aloha 1.2 "Scheme (gauche) ������������������ S ������������������������");
795 aloha 1.1
796 aloha 1.16 gtk_container_add(GTK_CONTAINER(Shiki_EDITOR_WINDOW), vbox);
797 aloha 1.26 gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
798 aloha 1.1
799 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_NEW, iconsize), "");
800 aloha 1.33 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(append_default_tabpage_handler), NULL);
801 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
802 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������", "");
803 aloha 1.1
804 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_UNDO, iconsize), "");
805 aloha 1.62 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(Shiki_undo), NULL);
806 aloha 1.33 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
807     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Undo","");
808    
809 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_REDO, iconsize), "");
810 aloha 1.64 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(Shiki_redo), NULL);
811 aloha 1.38 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
812     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Redo", "");
813 aloha 1.37
814 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_FIND, iconsize), "");
815 aloha 1.63 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(Shiki_search_buffer), NULL);
816 aloha 1.37 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
817     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������", "");
818    
819    
820 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_FIND_AND_REPLACE, iconsize), "");
821 aloha 1.63 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(Shiki_replace_buffer), NULL);
822 aloha 1.37 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
823     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������", "");
824    
825 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_REFRESH, iconsize), "");
826 aloha 1.65 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(reload_buffer), NULL);
827 aloha 1.37 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
828 aloha 1.65 gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������", "������������������������������");
829 aloha 1.37
830 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DELETE, iconsize), "");
831 aloha 1.57 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(clear_current_buffer_handler), NULL);
832 aloha 1.15 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
833     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������",
834     "���������������������������������������������������������������������");
835    
836 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CLOSE, iconsize), "");
837 aloha 1.58 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(kill_buffer_handler), NULL);
838 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
839 aloha 1.2 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������",
840     "���������������������������������������������������������������");
841 aloha 1.15
842 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CONNECT, iconsize), "");
843 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_scheme_file_by_gauche), NULL);
844 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
845     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Scheme ������������������������", "");
846    
847 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CONVERT, iconsize), "");
848 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_buffer_by_gauche), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
849 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
850     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������", "");
851    
852 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SPELL_CHECK, iconsize), "");
853 aloha 1.37 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(scheme_keyword_highlighting_current_buffer), NULL);
854     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
855     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
856    
857    
858 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, iconsize), "");
859 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(open_online_help), NULL);
860 aloha 1.22 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
861     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������", "");
862 aloha 1.49
863 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_BOLD, iconsize), "");
864 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(select_font), NULL);
865     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
866     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
867    
868 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_APPLY, iconsize), "");
869 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(tabsborder_on_off), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
870     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
871     gtk_tool_item_set_tooltip(icon, toolbar_tips, "��������� on/off", "");
872    
873 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_PREFERENCES, iconsize), "");
874 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(rotate_tab_position), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
875     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
876     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
877 aloha 1.22
878 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, iconsize), "");
879 aloha 1.11 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(about_this_application), NULL);
880     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
881     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
882    
883 aloha 1.39 /* ������������������������ */
884     Shiki_EDITOR_MODELINE_LABEL = gtk_label_new(NULL);
885     gtk_container_add(GTK_CONTAINER (modeline_bg), Shiki_EDITOR_MODELINE_LABEL);
886 aloha 1.49
887 aloha 1.39 gdk_color_parse("black", &COLOR_BLACK);
888     gdk_color_parse("green", &COLOR_GREEN);
889 aloha 1.49
890 aloha 1.39 gtk_widget_modify_fg(Shiki_EDITOR_MODELINE_LABEL, GTK_STATE_NORMAL, &COLOR_GREEN);
891     gtk_widget_modify_bg(modeline_bg, GTK_STATE_NORMAL, &COLOR_BLACK);
892    
893     gtk_box_pack_start(GTK_BOX(vbox), modeline_bg, TRUE, TRUE, 0);
894 aloha 1.12
895 aloha 1.8 /* C-x C-s ��������������������������������������������������������������������������������������� */
896 aloha 1.16 Shiki_EDITOR_STATUSBAR = gtk_statusbar_new();
897     gtk_box_pack_start(GTK_BOX(vbox), Shiki_EDITOR_STATUSBAR, TRUE, TRUE, 0);
898     contextid = gtk_statusbar_get_context_id(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), "");
899 aloha 1.8
900     /* ������������������������������������������������ */
901 aloha 1.26 g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-press-event", G_CALLBACK (signal_key_press_handler), GINT_TO_POINTER(contextid));
902     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-release-event", G_CALLBACK (signal_key_release_handler), GINT_TO_POINTER(contextid));
903 aloha 1.12
904 aloha 1.21 /* ��������������������������������������������� */
905     if(argc >= 2) {
906     int i;
907     for(i = 1; i < argc; i++)
908 aloha 1.60 Shiki_create_file_buffer(argv[i]);
909 aloha 1.21 } else /* ������������������������������������������������������������������ */
910 aloha 1.26 open_online_help(Shiki_EDITOR_NOTEBOOK);
911 aloha 1.8
912 aloha 1.26 gtk_widget_grab_focus(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
913 aloha 1.16 gtk_widget_show_all(Shiki_EDITOR_WINDOW);
914 aloha 1.1 }
915    
916 aloha 1.65 ScmClass *ShikiBufferClass = NULL;
917    
918     static void buffer_print(ScmObj obj, ScmPort *out, ScmWriteContext *ctx) {
919     GtkTextBuffer *b = SHIKI_BUFFER_UNBOX(obj);
920     GList *l = g_list_find_custom(Shiki_EDITOR_BUFFER_LIST, b, compBuffer);
921     if(l)
922     Scm_Printf(out, "#<buffer: %s>", ((ShikiBuffer *)(l->data))->name);
923     else
924     Scm_Printf(out, "#<deleted buffer: %p>", b);
925     }
926    
927     static void buffer_cleanup(ScmObj obj)
928     {
929     g_object_unref(SHIKI_BUFFER_UNBOX(obj));
930     }
931    
932 aloha 1.1 int main(int argc, char *argv[]) {
933     /* ������������������������������������ */
934 aloha 1.39 Shiki_EDITOR_DEFAULT_LOCALE = g_locale_to_utf8(gtk_set_locale(), -1, NULL, NULL, NULL);
935 aloha 1.1 gtk_init(&argc, &argv);
936     GC_INIT(); Scm_Init(GAUCHE_SIGNATURE);
937 aloha 1.50 Scm_Load("gauche-init.scm", 0);
938 aloha 1.65 ShikiBufferClass = Scm_MakeForeignPointerClass(SCM_CURRENT_MODULE(),
939     "<buffer>", buffer_print, buffer_cleanup,
940     SCM_FOREIGN_POINTER_KEEP_IDENTITY
941     |
942     SCM_FOREIGN_POINTER_MAP_NULL);
943 aloha 1.54 Shiki_editor_window_init(argc, argv);
944 aloha 1.1 gtk_main();
945     Scm_Exit(0);
946     return 0;
947     }

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