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.64 - (hide annotations) (download) (as text)
Sun Dec 3 15:21:04 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.63: +10 -7 lines
File MIME type: text/x-csrc
add and refactoring Undo/Redo (but currently buggy yet...)

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.64 * $Id: shiki.c,v 1.63 2006/12/02 14:23:20 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 aloha 1.64 case GDK_backslash : /* Ctrl + \ : Undo */
322 aloha 1.62 Shiki_undo();
323 aloha 1.32 break;
324    
325 aloha 1.64 case GDK_underscore : /* Ctrl + _ : Redo */
326     Shiki_redo();
327     break;
328    
329 aloha 1.32 case GDK_t : /* Ctrl + t : ��������������� */
330 aloha 1.33 append_default_tabpage_handler();
331 aloha 1.32 break;
332    
333     case GDK_k : /* Ctrl + k : ������������������ */
334 aloha 1.58 kill_buffer_handler();
335 aloha 1.32 break;
336    
337     case GDK_w : /* Ctrl + w : ��������� */
338     gtk_text_buffer_cut_clipboard(Shiki_CURRENT_TEXT_BUFFER, Shiki_EDITOR_CLIPBOARD, TRUE);
339     break;
340    
341     case GDK_y : /* Ctrl + y : ��������� */
342     {GtkTextIter p;
343     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
344     gtk_text_buffer_paste_clipboard(Shiki_CURRENT_TEXT_BUFFER, Shiki_EDITOR_CLIPBOARD, &p, TRUE);
345     }
346     break;
347     }
348     }
349     return FALSE;
350     }
351    
352 aloha 1.33 static void append_default_tabpage_handler() {
353 aloha 1.57 Shiki_new_buffer_create(g_strdup("*scratch*"));
354 aloha 1.33 }
355    
356 aloha 1.23 /* ������������������������������������������ (������������) ��������� */
357 aloha 1.58 static void kill_buffer_handler() {
358     Shiki_kill_buffer(Shiki_CURRENT_TEXT_BUFFER);
359 aloha 1.23 }
360    
361 aloha 1.14 /* ������������������������������������ */
362     static void load_buffer_by_gauche() {
363     GtkTextIter p;
364 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
365     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
366     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(get_all_buffer_contents(Shiki_CURRENT_TEXT_BUFFER)), -1);
367 aloha 1.14 }
368    
369     /* ������������������������ */
370 aloha 1.27 static void load_scheme_file_by_gauche() {
371 aloha 1.58 gchar *contents, *text = NULL;
372 aloha 1.14 gsize br, bw, len;
373     GError *err = NULL;
374 aloha 1.57 const gchar *filename = Shiki_file_name_dialog("File Selection");
375 aloha 1.14 GtkTextIter p;
376    
377     if(!filename) return;
378 aloha 1.33
379 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
380     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
381 aloha 1.14
382     if(g_file_get_contents(filename, &contents, &len, NULL)) {
383     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
384 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(text), -1);
385 aloha 1.14 else
386 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(contents), -1);
387 aloha 1.14 }
388 aloha 1.57 g_free(text); g_free(contents);
389 aloha 1.14 }
390    
391 aloha 1.13 /* gauche ������������������������������������ */
392     static gchar *load_cstring_by_gauche(gchar *s) {
393     gchar *msg;
394    
395     ScmObj result, error;
396     /* ��������������������������������� */
397 aloha 1.50 ScmObj is = Scm_MakeInputStringPort(SCM_STRING(SCM_MAKE_STR_COPYING(s)), TRUE);
398 aloha 1.13 /* ������������������������������ */
399     ScmObj os = Scm_MakeOutputStringPort(TRUE);
400    
401 aloha 1.34 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*input*")), is);
402     Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
403 aloha 1.13 /* Scheme ��������������������������������������������������������������������������������� S ��������������������������������������������������������������������������� *error* ������������������ */
404 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));
405 aloha 1.13
406 aloha 1.34 error = Scm_GlobalVariableRef(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
407 aloha 1.13
408     /* ��������������������������������������������������������� */
409     if (!SCM_FALSEP(error))
410     Scm_Write(error, os, SCM_WRITE_DISPLAY);
411     else
412     Scm_Write(result, os, SCM_WRITE_DISPLAY);
413    
414     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
415     /* ������������������ */
416     Scm_ClosePort(SCM_PORT(is));
417     Scm_ClosePort(SCM_PORT(os));
418    
419     return msg;
420     }
421    
422 aloha 1.12 static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog) {
423     gchar *font_name = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (font_dialog));
424     if(font_name) {
425     GtkRcStyle *style = gtk_rc_style_new ();
426     pango_font_description_free(style->font_desc);
427     style->font_desc = pango_font_description_from_string(font_name);
428 aloha 1.16 gtk_widget_modify_style (GTK_WIDGET(Shiki_CURRENT_TEXT_VIEW), style);
429 aloha 1.44 gtk_rc_style_unref (style);
430 aloha 1.12 g_free (font_name);
431     }
432     }
433    
434 aloha 1.14 /* ������������������������������������������������������ */
435 aloha 1.12 static void select_font(){
436     GtkWidget *font_dialog = gtk_font_selection_dialog_new("Font Selection Dialog");
437     g_signal_connect (GTK_FONT_SELECTION_DIALOG (font_dialog)->ok_button, "clicked", G_CALLBACK(font_selection_ok), font_dialog);
438     gtk_dialog_run(GTK_DIALOG(font_dialog));
439     gtk_widget_destroy(font_dialog);
440     }
441    
442 aloha 1.11 /* ������������������������������������������ */
443     static void about_this_application() {
444     GtkAboutDialog *about = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
445     const gchar *authors[] = {
446 aloha 1.23 "������������ (���������) <alohakun@gmail.com>\n",
447     "Contribute : tkng ������",
448     "(http://d.hatena.ne.jp/tkng/20061113)", NULL
449 aloha 1.11 };
450     gtk_about_dialog_set_authors(about, authors);
451     gtk_about_dialog_set_copyright(about, "Copyright(C)2006 WAKATSUKI Toshihiro");
452     gtk_about_dialog_set_name(about, "��� (SHIKI)");
453     gtk_about_dialog_set_website_label(about, "���������30������������������������������������������������������������Blog");
454     gtk_about_dialog_set_website(about, "http://alohakun.blog7.fc2.com/blog-category-29.html");
455     gtk_dialog_run(GTK_DIALOG(about));
456     gtk_widget_destroy(GTK_WIDGET(about));
457     }
458    
459 aloha 1.37 /* ��������� */
460     static void dummy_handler() {
461 aloha 1.42 GtkWidget *dummy = gtk_message_dialog_new(GTK_WINDOW(Shiki_EDITOR_WINDOW),
462     GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
463     "Sorry... This Button is Dummy.");
464     gtk_dialog_run(GTK_DIALOG(dummy));
465     gtk_widget_destroy(dummy);
466 aloha 1.37 }
467    
468 aloha 1.1 /* ��������������������������������������������������������������� */
469     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer) {
470     GtkTextIter start, end;
471     gtk_text_buffer_get_start_iter(buffer, &start);
472     gtk_text_buffer_get_end_iter(buffer, &end);
473     return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
474     }
475    
476     /* buffer ������������������������ filename ��������� */
477     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer) {
478     gchar *contents, *text;
479     gsize br, bw;
480     GError *err = NULL;
481    
482     if(!filename) return FALSE;
483     contents = get_all_buffer_contents(buffer);
484     text = g_locale_from_utf8(contents, -1, &br, &bw, &err);
485     /* ��������������������������������� */
486     g_file_set_contents(filename, text, -1, NULL);
487     gtk_text_buffer_set_modified(buffer, FALSE);
488 aloha 1.61 Shiki_update_modeline(Shiki_CURRENT_TEXT_BUFFER);
489 aloha 1.1 g_free(contents); g_free(text);
490     return TRUE;
491     }
492    
493     /* ��������������������������������������������������������������������� */
494 aloha 1.27 static void save_file() {
495 aloha 1.1
496 aloha 1.22 /* ��������������������������������������� */
497 aloha 1.60 if(strcmp("*help*", Shiki_CURRENT_TAB_TITLE) == 0) return;
498 aloha 1.33
499 aloha 1.1 /* ������������������������������������ */
500 aloha 1.16 if(!gtk_text_buffer_get_modified(Shiki_CURRENT_TEXT_BUFFER)) return;
501 aloha 1.1
502     /* ������������������������������������������������������������������������������������������������������ */
503 aloha 1.60 if(strcmp("*scratch*", Shiki_CURRENT_FILENAME) == 0) {
504 aloha 1.57 const gchar *filename = Shiki_file_name_dialog("Save File As ...");
505 aloha 1.7 if(!filename) return;
506 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
507 aloha 1.27 gtk_notebook_set_tab_label_text(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
508 aloha 1.16 gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), filename);
509 aloha 1.1 } else
510 aloha 1.16 save_text_buffer(Shiki_CURRENT_TAB_TITLE, Shiki_CURRENT_TEXT_BUFFER);
511 aloha 1.1 }
512    
513     /* ��������������������������������������������������������������������������� */
514 aloha 1.27 static void save_file_as() {
515 aloha 1.57 const gchar *filename = Shiki_file_name_dialog("Save File As ...");
516 aloha 1.1
517 aloha 1.7 if(!filename) return;
518 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
519 aloha 1.1
520 aloha 1.27 gtk_notebook_set_tab_label_text(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
521 aloha 1.16 gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
522 aloha 1.1 }
523    
524 aloha 1.13 /* ������������������������������������������������������������������ S ��������������� (������������) */
525 aloha 1.27 static void load_region_by_gauche() {
526 aloha 1.1
527     GtkTextIter start, end, p;
528     gchar *code;
529 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
530     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
531 aloha 1.1
532     /* ������������������������������������������������������������ */
533 aloha 1.16 if(gtk_text_buffer_get_selection_bounds(Shiki_CURRENT_TEXT_BUFFER, &start, &end)) {
534     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
535     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(code), -1);
536 aloha 1.1 g_free(code);
537     }
538     }
539    
540     /* ������������������������������������������������ */
541     static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer) {
542     gint nest_level = 0;
543     GtkTextIter start, end;
544     gtk_text_buffer_get_start_iter(buffer, &start);
545     if(gtk_text_iter_get_char(&start) == '(') nest_level++;
546    
547     /* ��������������������� (= end) ��������� */
548     gtk_text_buffer_get_iter_at_mark(buffer,&end, gtk_text_buffer_get_insert(buffer));
549    
550     while(1) {
551     /* end ������ '(' ��� ')' ��������������������������������������������� */
552     if(!gtk_text_iter_forward_find_char(&start, is_kakko_or_kokka, NULL, &end))
553     return nest_level;
554    
555     if(gtk_text_iter_get_char(&start) == '(')
556     nest_level++;
557     else
558     nest_level--;
559     }
560     }
561    
562     /* ��������������������������������� on/off */
563     static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook) {
564     gint tval = FALSE;
565     gint bval = FALSE;
566     if(notebook->show_tabs == FALSE)
567     tval = TRUE;
568     if(notebook->show_border == FALSE)
569     bval = TRUE;
570    
571     gtk_notebook_set_show_tabs(notebook, tval);
572     gtk_notebook_set_show_border(notebook, bval);
573     }
574    
575     /* ������������������������ */
576 aloha 1.17 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook ) {
577 aloha 1.1 gtk_notebook_set_tab_pos(notebook, (notebook->tab_pos + 1) % 4);
578     }
579    
580     /* ��������������������� */
581 aloha 1.8 static gboolean signal_key_release_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
582     static gint metakey_pressed = 0;
583 aloha 1.6 static gint controlx_pressed = 0;
584 aloha 1.1
585     if(event->keyval == GDK_parenright && event->state & GDK_SHIFT_MASK) {
586     GtkTextIter start, end;
587    
588     /* ������������������������������ */
589 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
590 aloha 1.1
591     start = end;
592     gtk_text_iter_backward_char(&start);
593    
594     /* ��������������������������������� S ������������������ */
595 aloha 1.29 if(!search_last_sexp_kakko(&start)) return FALSE;
596 aloha 1.1
597 aloha 1.16 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
598 aloha 1.1 }
599    
600     /* ������������������������������������������������������������������������������������������������ (���������������) ������������������ */
601     if(event->keyval == GDK_Return) {
602 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;
603     static gchar *indent = " ";
604     for(i = 0; i < indentWidth; i++)
605     gtk_text_buffer_insert_at_cursor(Shiki_CURRENT_TEXT_BUFFER, indent, -1);
606 aloha 1.1 }
607    
608 aloha 1.6 /* C-x */
609     if(event->keyval == GDK_x && event->state & GDK_CONTROL_MASK) {
610     controlx_pressed++;
611 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-x -");
612 aloha 1.6 } else if(event->state & GDK_CONTROL_MASK) {
613 aloha 1.8
614 aloha 1.6 if(controlx_pressed > 0) {
615     switch(event->keyval) {
616     case GDK_c :/* C-x C-c : ������ */
617 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-c");
618 aloha 1.6 {/* "delete-event" ��������������������������������������� �� ������������������������������������ */
619     GdkEvent ev;
620    
621     ev.any.type = GDK_DELETE;
622 aloha 1.16 ev.any.window = Shiki_EDITOR_WINDOW->window;
623 aloha 1.6 ev.any.send_event = FALSE;
624     gdk_event_put (&ev);
625     }
626     break;
627    
628     case GDK_f : /* C-x C-f : ������������������ */
629 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-f");
630 aloha 1.60 Shiki_open_file_dialog();
631 aloha 1.6 break;
632    
633     case GDK_s : /* C-x C-s : ������������������ */
634 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-s");
635 aloha 1.27 save_file();
636 aloha 1.6 break;
637    
638     case GDK_w : /* C-x C-w : ������������������������ */
639 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-w");
640 aloha 1.27 save_file_as();
641 aloha 1.6 break;
642     }
643     controlx_pressed = 0;
644     }
645 aloha 1.8
646     switch(event->keyval) {
647     case GDK_g :/* C-g : ��������������� */
648     metakey_pressed = 0;
649     controlx_pressed = 0;
650    
651 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "Quit");
652 aloha 1.8 break;
653     }
654    
655 aloha 1.6 }
656 aloha 1.1 return FALSE;
657     }
658 aloha 1.27 static void open_online_help() {
659 aloha 1.22 GtkTextIter p;
660 aloha 1.57 Shiki_new_buffer_create(g_strdup("*help*"));
661 aloha 1.22 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER,
662 aloha 1.37 "������������������������������������������\n"
663 aloha 1.30 "$ ./shiki [file1 file2 ....]\n\n"
664     "[���������������������������] ��������������������� (C-x C-f)\n"
665     "[������������������������������������������] ��������������������� (C-x C-s)\n"
666     "[���������������������������������������������] ��������������������������� (C-x C-w)\n"
667 aloha 1.37 "[���������������������] ��������������� gauche ������������\n"
668 aloha 1.30 "[��������������� (���������) ���������������] ��������� on/off\n"
669     "[������ (���������) ���������������] ������������������������\n"
670 aloha 1.37 "[������������������] ��������������������������� (C-t)\n"
671 aloha 1.33 "[���������������������������] ������������ (C-_)\n"
672 aloha 1.30 "[���������������������] ������������������������\n"
673 aloha 1.44 "\n"
674     "(��� : ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ Undo ������������������)\n"
675     "\n"
676 aloha 1.37 "[�� ������������] ������������������������ (C-k)\n"
677 aloha 1.30 "[A ������������] ���������������������\n"
678     "[���������������������������] Scheme ������������������������\n"
679     "[���������������������������������] ���������������������������������������\n"
680     "[��������� (?) ������������] ���������������������������������������\n"
681 aloha 1.33 "[info ������������] ���������������������������������������������������\n"
682     "\n"
683 aloha 1.30 "C-f : ��� ��������� (forward)\n"
684     "C-b : ��� ��������� (backward)\n"
685     "C-n : ��� ��������� (next line)\n"
686 aloha 1.33 "C-p : ��� ��������� (previous line)\n"
687     "\n"
688     "C-h : ���������������������\n"
689 aloha 1.31 "C-w : ���������\n"
690 aloha 1.33 "C-y : ��������� (������������)\n"
691 aloha 1.64 "C-\\ : Undo\n"
692     "C-_ : Redo\n"
693 aloha 1.33 "\n"
694 aloha 1.30 "C-e : ��������������������� S ������������ (eval-expression)\n"
695     "C-j : ��������������������� S ������������ (eval-last-sexp)\n"
696 aloha 1.33 "(emacs/xyzzy ��� *scratch* ���������������������)\n"
697     "\n"
698 aloha 1.31 "C-M-@ : ��������������������� S ������������ (mark-sexp)\n"
699     "C-M-SPC : ��������������������� S ������������ (mark-last-sexp)\n"
700 aloha 1.33 "C-x C-c : ��������������������������� �� ���������������������������������\n"
701 aloha 1.44 , -1);
702 aloha 1.30 gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
703     /* ������������������������������ */
704     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
705     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
706 aloha 1.63 gtk_text_view_set_editable(Shiki_CURRENT_TEXT_VIEW, FALSE);
707 aloha 1.22 }
708    
709 aloha 1.1 /* ��������������������������������������� */
710 aloha 1.54 static void Shiki_editor_window_init(int argc, char **argv) {
711 aloha 1.39 GtkWidget *vbox, *toolbar, *modeline_bg = gtk_event_box_new();
712 aloha 1.1 GtkToolItem *icon;
713     GtkIconSize iconsize;
714 aloha 1.2 GtkTooltips *toolbar_tips = gtk_tooltips_new();
715 aloha 1.1 /* ��������������������������������������������������������������������������������� */
716     GtkToolItem *oicon, *sicon, *saicon, *eicon;
717    
718 aloha 1.36 gint contextid, i;
719    
720     /* ������������������������������������������������������������������������������ */
721     keywords_hash = g_hash_table_new(g_str_hash, g_str_equal);
722     i = 0;
723     while(R5RS_keywords[i] != NULL)
724     g_hash_table_insert(keywords_hash, R5RS_keywords[i++], GINT_TO_POINTER(R5RS_KEYWORD_COLOR));
725     i = 0;
726     while(R5RS_functions[i] != NULL)
727     g_hash_table_insert(keywords_hash, R5RS_functions[i++], GINT_TO_POINTER(R5RS_FUNCTION_COLOR));
728 aloha 1.8
729 aloha 1.1 /* ������������ */
730 aloha 1.16 Shiki_EDITOR_WINDOW = gtk_window_new(GTK_WINDOW_TOPLEVEL);
731     g_signal_connect(G_OBJECT(Shiki_EDITOR_WINDOW), "destroy", G_CALLBACK(gtk_main_quit), NULL);
732 aloha 1.1
733 aloha 1.31 /* ������������������������������������������������������������ */
734     Shiki_EDITOR_CLIPBOARD = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
735    
736 aloha 1.1 /* ������������������������������������ */
737     vbox = gtk_vbox_new(FALSE, 0);
738     /* ��������������������� */
739     toolbar = gtk_toolbar_new();
740     gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
741    
742 aloha 1.26 Shiki_EDITOR_NOTEBOOK = GTK_NOTEBOOK(gtk_notebook_new());
743     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "switch-page", GTK_SIGNAL_FUNC(switch_tabpage_handler), NULL);
744 aloha 1.1
745     /* ������������������������������������������������ */
746     gtk_toolbar_set_style(GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
747     iconsize = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar));
748    
749     /* ������������������ */
750    
751     /* ������������������ */
752 aloha 1.45 oicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_OPEN, iconsize), "");
753 aloha 1.1 /* ������������������������������������������������������������������������������������ */
754 aloha 1.60 g_signal_connect(G_OBJECT(oicon), "clicked", G_CALLBACK(Shiki_open_file_dialog), NULL);
755 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(oicon));
756 aloha 1.2 gtk_tool_item_set_tooltip(oicon, toolbar_tips, "���������������������������",
757     "���������������������������������������������������������������������������������������");
758 aloha 1.1
759     /* ������������������ */
760 aloha 1.45 sicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SAVE, iconsize), "");
761 aloha 1.1 /* ������������������������������������������������������������������������������������ */
762 aloha 1.27 g_signal_connect(G_OBJECT(sicon), "clicked", G_CALLBACK(save_file), NULL);
763 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(sicon));
764 aloha 1.2 gtk_tool_item_set_tooltip(sicon, toolbar_tips, "������������������������������",
765     "������������������������������������������������������������������������������������������������������������������������������������");
766 aloha 1.1
767     /* ��������������������������� */
768 aloha 1.45 saicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SAVE_AS, iconsize), "");
769 aloha 1.1 /* ������������������������������������������������������������������������������������������������������������������ */
770 aloha 1.27 g_signal_connect(G_OBJECT(saicon), "clicked", G_CALLBACK(save_file_as), NULL);
771 aloha 1.2 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(saicon));
772     gtk_tool_item_set_tooltip(saicon, toolbar_tips, "������������������������������������",
773     "");
774 aloha 1.1
775     /* ������������������ */
776 aloha 1.45 eicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_EXECUTE, iconsize), "");
777 aloha 1.14 /* ������������������������������������������ libgauche ������������������ */
778 aloha 1.27 g_signal_connect(G_OBJECT(eicon), "clicked", G_CALLBACK(load_region_by_gauche), NULL);
779 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(eicon));
780 aloha 1.14 gtk_tool_item_set_tooltip(eicon, toolbar_tips, "��������������� S ������������������������ (load-region-lisp)",
781 aloha 1.2 "Scheme (gauche) ������������������ S ������������������������");
782 aloha 1.1
783 aloha 1.16 gtk_container_add(GTK_CONTAINER(Shiki_EDITOR_WINDOW), vbox);
784 aloha 1.26 gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
785 aloha 1.1
786 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_NEW, iconsize), "");
787 aloha 1.33 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(append_default_tabpage_handler), NULL);
788 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
789 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������", "");
790 aloha 1.1
791 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_UNDO, iconsize), "");
792 aloha 1.62 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(Shiki_undo), NULL);
793 aloha 1.33 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
794     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Undo","");
795    
796 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_REDO, iconsize), "");
797 aloha 1.64 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(Shiki_redo), NULL);
798 aloha 1.38 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
799     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Redo", "");
800 aloha 1.37
801 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_FIND, iconsize), "");
802 aloha 1.63 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(Shiki_search_buffer), NULL);
803 aloha 1.37 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
804     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������", "");
805    
806    
807 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_FIND_AND_REPLACE, iconsize), "");
808 aloha 1.63 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(Shiki_replace_buffer), NULL);
809 aloha 1.37 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
810     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������", "");
811    
812 aloha 1.64 /* XXX : TODO */
813 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_REFRESH, iconsize), "");
814 aloha 1.37 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(dummy_handler), NULL);
815     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
816     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������", "");
817    
818     /* TODO ������������ */
819    
820 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DELETE, iconsize), "");
821 aloha 1.57 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(clear_current_buffer_handler), NULL);
822 aloha 1.15 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
823     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������",
824     "���������������������������������������������������������������������");
825    
826 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CLOSE, iconsize), "");
827 aloha 1.58 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(kill_buffer_handler), NULL);
828 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
829 aloha 1.2 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������",
830     "���������������������������������������������������������������");
831 aloha 1.15
832 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CONNECT, iconsize), "");
833 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_scheme_file_by_gauche), NULL);
834 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
835     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Scheme ������������������������", "");
836    
837 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CONVERT, iconsize), "");
838 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_buffer_by_gauche), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
839 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
840     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������", "");
841    
842 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SPELL_CHECK, iconsize), "");
843 aloha 1.37 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(scheme_keyword_highlighting_current_buffer), NULL);
844     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
845     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
846    
847    
848 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, iconsize), "");
849 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(open_online_help), NULL);
850 aloha 1.22 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
851     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������", "");
852 aloha 1.49
853 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_BOLD, iconsize), "");
854 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(select_font), NULL);
855     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
856     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
857    
858 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_APPLY, iconsize), "");
859 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(tabsborder_on_off), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
860     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
861     gtk_tool_item_set_tooltip(icon, toolbar_tips, "��������� on/off", "");
862    
863 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_PREFERENCES, iconsize), "");
864 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(rotate_tab_position), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
865     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
866     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
867 aloha 1.22
868 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, iconsize), "");
869 aloha 1.11 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(about_this_application), NULL);
870     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
871     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
872    
873 aloha 1.39 /* ������������������������ */
874     Shiki_EDITOR_MODELINE_LABEL = gtk_label_new(NULL);
875     gtk_container_add(GTK_CONTAINER (modeline_bg), Shiki_EDITOR_MODELINE_LABEL);
876 aloha 1.49
877 aloha 1.39 gdk_color_parse("black", &COLOR_BLACK);
878     gdk_color_parse("green", &COLOR_GREEN);
879 aloha 1.49
880 aloha 1.39 gtk_widget_modify_fg(Shiki_EDITOR_MODELINE_LABEL, GTK_STATE_NORMAL, &COLOR_GREEN);
881     gtk_widget_modify_bg(modeline_bg, GTK_STATE_NORMAL, &COLOR_BLACK);
882    
883     gtk_box_pack_start(GTK_BOX(vbox), modeline_bg, TRUE, TRUE, 0);
884 aloha 1.12
885 aloha 1.8 /* C-x C-s ��������������������������������������������������������������������������������������� */
886 aloha 1.16 Shiki_EDITOR_STATUSBAR = gtk_statusbar_new();
887     gtk_box_pack_start(GTK_BOX(vbox), Shiki_EDITOR_STATUSBAR, TRUE, TRUE, 0);
888     contextid = gtk_statusbar_get_context_id(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), "");
889 aloha 1.8
890     /* ������������������������������������������������ */
891 aloha 1.26 g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-press-event", G_CALLBACK (signal_key_press_handler), GINT_TO_POINTER(contextid));
892     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-release-event", G_CALLBACK (signal_key_release_handler), GINT_TO_POINTER(contextid));
893 aloha 1.12
894 aloha 1.21 /* ��������������������������������������������� */
895     if(argc >= 2) {
896     int i;
897     for(i = 1; i < argc; i++)
898 aloha 1.60 Shiki_create_file_buffer(argv[i]);
899 aloha 1.21 } else /* ������������������������������������������������������������������ */
900 aloha 1.26 open_online_help(Shiki_EDITOR_NOTEBOOK);
901 aloha 1.8
902 aloha 1.26 gtk_widget_grab_focus(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
903 aloha 1.16 gtk_widget_show_all(Shiki_EDITOR_WINDOW);
904 aloha 1.1 }
905    
906     int main(int argc, char *argv[]) {
907     /* ������������������������������������ */
908 aloha 1.39 Shiki_EDITOR_DEFAULT_LOCALE = g_locale_to_utf8(gtk_set_locale(), -1, NULL, NULL, NULL);
909 aloha 1.1 gtk_init(&argc, &argv);
910     GC_INIT(); Scm_Init(GAUCHE_SIGNATURE);
911 aloha 1.50 Scm_Load("gauche-init.scm", 0);
912 aloha 1.54 Shiki_editor_window_init(argc, argv);
913 aloha 1.1 gtk_main();
914     Scm_Exit(0);
915     return 0;
916     }

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