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.65 - (hide annotations) (download) (as text)
Thu Dec 28 05:04:45 2006 UTC (17 years, 3 months ago) by aloha
Branch: MAIN
Changes since 1.64: +59 -23 lines
File MIME type: text/x-csrc
impl load-(file | buffer) related funtion (but currently very buggy ... for exam, SEGV while using load-file and then select other tab. It's not known exactly why...)

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

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