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.67 - (hide annotations) (download) (as text)
Sun Feb 18 09:59:14 2007 UTC (17 years, 1 month ago) by aloha
Branch: MAIN
CVS Tags: HEAD
Changes since 1.66: +5 -7 lines
File MIME type: text/x-csrc
buffer name uniformization even if same filename (ex. "filename", "filename<1>", "filename<2>", ...), and fixed double remove bugs in Shiki_delete_buffer() (but not complete ...)

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

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