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.63 - (hide annotations) (download) (as text)
Sat Dec 2 14:23:20 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.62: +89 -256 lines
File MIME type: text/x-csrc
add search-buffer/replace-buffer (interactive/all)

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

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