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.35 - (hide annotations) (download) (as text)
Sat Nov 18 13:11:33 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.34: +119 -6 lines
File MIME type: text/x-csrc
add scheme r5rs keyword highlighting

1 aloha 1.1 /* vim: set encoding=utf8:
2     *
3     * shiki.c
4     *
5     * Copyright(C)2006 WAKATSUKI toshihiro
6     *
7     * Permission is hereby granted, free of charge, to any person obtaining a
8     * copy of this software and associated documentation files (the "Software"),
9     * to deal in the Software without restriction, including without limitation
10     * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11     * and/or sell copies of the Software, and to permit persons to whom the
12     * Software is furnished to do so, subject to the following conditions:
13     *
14     * The above copyright notice and this permission notice shall be included in
15     * all copies or substantial portions of the Software.
16     *
17     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23     * SOFTWARE.
24     *
25 aloha 1.35 * $Id: shiki.c,v 1.34 2006/11/17 13:04:08 aloha Exp $
26 aloha 1.1 */
27    
28     #include<gauche.h>
29     #include<gtk/gtk.h>
30     #include<gdk/gdkkeysyms.h>
31    
32 aloha 1.6 static gint editor_indent_width = 2;
33 aloha 1.7
34 aloha 1.32 /* Undo/Redo ������������������ */
35     typedef enum {SHIKI_UNDO_INSERT, SHIKI_UNDO_DELETE} ShikiAction;
36    
37     typedef struct {
38     ShikiAction action;
39     gchar *str;
40     gint strlen;
41     gint start;
42     gint end;
43     } ShikiUndoInfo;
44    
45 aloha 1.17 /* ��������������������������������������������� */
46 aloha 1.16 typedef struct {
47 aloha 1.20 GtkScrolledWindow *tabpage; /* ������ */
48     gchar *tabpage_label; /* ��������� (���������������) ������ */
49     GtkTextView *text_view; /* ��������������� */
50     GtkTextBuffer *text_buffer; /* ��������������������������������� */
51     gchar *filename; /* ������������������������������ */
52 aloha 1.32 GList *undoInfoList; /* ��������������������������������������� */
53 aloha 1.20 ScmObj env; /* ��������������������������� Scheme ������ */
54     guint delete_handler_id; /* ��������������������������������������������� ID */
55 aloha 1.16 } ShikiTabInfo;
56    
57 aloha 1.17 /* ������������������������������������������������������������������������������������������������������������������������������ */
58 aloha 1.35 static struct {
59 aloha 1.17 GtkWidget *editor_window;
60 aloha 1.31 GtkClipboard *clipboard;
61 aloha 1.26 GtkNotebook *notebook;
62 aloha 1.17 GtkWidget *statusbar;
63     GtkWidget *modeline_label;
64     GList *tabInfoList;
65     gint current_tabpage_num;
66     ShikiTabInfo *current_tabpage_info;
67 aloha 1.16 } shiki_editor;
68    
69 aloha 1.25 /* ��������������������������������������������� */
70 aloha 1.32 #define Shiki_EDITOR_WINDOW shiki_editor.editor_window
71     #define Shiki_EDITOR_CLIPBOARD shiki_editor.clipboard
72     #define Shiki_EDITOR_NOTEBOOK shiki_editor.notebook
73     #define Shiki_EDITOR_STATUSBAR shiki_editor.statusbar
74     #define Shiki_EDITOR_MODELINE_LABEL shiki_editor.modeline_label
75     #define Shiki_EDITOR_TAB_INFO_LIST shiki_editor.tabInfoList
76 aloha 1.25
77     /* ��������������������������������������������������������������������������������������� */
78 aloha 1.32 #define Shiki_CURRENT_TAB_NUM shiki_editor.current_tabpage_num
79     #define Shiki_CURRENT_TAB_INFO shiki_editor.current_tabpage_info
80     #define Shiki_CURRENT_UNDO_INFO_LIST (shiki_editor.current_tabpage_info)->undoInfoList
81     #define Shiki_CURRENT_TAB (shiki_editor.current_tabpage_info)->tabpage
82     #define Shiki_CURRENT_TAB_TITLE (shiki_editor.current_tabpage_info)->tabpage_label
83     #define Shiki_CURRENT_TEXT_VIEW (shiki_editor.current_tabpage_info)->text_view
84     #define Shiki_CURRENT_TEXT_BUFFER (shiki_editor.current_tabpage_info)->text_buffer
85     #define Shiki_CURRENT_FILENAME (shiki_editor.current_tabpage_info)->filename
86 aloha 1.34 #define Shiki_CURRENT_BUFFER_ENV (shiki_editor.current_tabpage_info)->env
87 aloha 1.10
88 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};
89    
90     static gchar *R5RS_functions[] = {
91     "*", "+", "-", "/", "<", ">", "<=", ">=", "?", "`", "=", "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};
92    
93     static GHashTable *keywords_hash = NULL;
94    
95     typedef enum {
96     R5RS_KEYWORD_COLOR = 1,
97     R5RS_FUNCTION_COLOR,
98     GAUCHE_KEYWORD_COLOR,
99     GAUCHE_FUNCTION_COLOR
100     } HIGHILIGHT_COLOR;
101    
102 aloha 1.17 /* ������������������ */
103 aloha 1.25
104 aloha 1.27 /* ������������������������ : ���������������ShikiTabInfo ������������������������������������������������������������������ 2 ������������������������������������������ (������������������) */
105     static void append_tabpage(gchar *filename);
106     static void remove_tabpage();
107    
108 aloha 1.33 /* foo_bar_handler() ������������������������������������������������������ */
109     static void append_default_tabpage_handler();
110    
111 aloha 1.25 /* ������������������ */
112 aloha 1.27 static void open_file(gchar *filename);
113     static void open_file_handler();
114     static void save_file();
115     static void save_file_as();
116 aloha 1.25 static gchar *get_filename_from_dialog(const gchar *msg);
117    
118     /* ������������������������������ */
119     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer);
120     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer);
121 aloha 1.17 static void clear_current_buffer();
122 aloha 1.33 static void undo();
123 aloha 1.25
124 aloha 1.32 static void insert_text_handler(GtkTextBuffer *buffer, GtkTextIter *p, gchar *str, gint len);
125     static void delete_range_handler(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end);
126    
127 aloha 1.25 /* ������������������ */
128 aloha 1.17 static gint get_current_line_number(GtkTextBuffer *buffer);
129     static void update_modeline_label();
130     static void text_buffer_cursor_moved_handler();
131 aloha 1.25
132     /* ������ */
133 aloha 1.17 static void really_quit_dialog_yes(GtkWidget *widget, gboolean *flag);
134     static void really_quit_dialog_no(GtkWidget *widget, gint *flag);
135     static gboolean not_yet_save_changes_really_quit(GtkTextBuffer *buffer);
136 aloha 1.27 static gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, GtkTextBuffer *buffer);
137 aloha 1.25
138     /* Gauche ��� S ��������������������������������� */
139 aloha 1.17 static gchar *eval_cstring_by_gauche(gchar *s);
140 aloha 1.25 static gchar *load_cstring_by_gauche(gchar *s);
141     static void load_buffer_by_gauche();
142 aloha 1.27 static void load_region_by_gauche();
143     static void load_scheme_file_by_gauche();
144 aloha 1.17 static gboolean is_kakko_or_kokka(gunichar ch, gpointer);
145 aloha 1.29 static gboolean is_kakko(gunichar ch, gpointer);
146 aloha 1.17 static gboolean is_kokka(gunichar ch, gpointer);
147 aloha 1.30 static gboolean search_sexp(GtkTextIter *start, GtkTextIter *end);
148     static gboolean search_sexp_kokka(GtkTextIter *end);
149     static gboolean search_last_sexp(GtkTextIter *start, GtkTextIter *end);
150 aloha 1.29 static gboolean search_last_sexp_kakko(GtkTextIter *start);
151 aloha 1.17 static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer);
152 aloha 1.25
153     /* ������ */
154     static void select_font();
155     static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog);
156 aloha 1.18 static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) ;
157 aloha 1.17 static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook);
158 aloha 1.27 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook);
159 aloha 1.25
160     /* ��������������� ������������ ������ */
161 aloha 1.17 static void forward_current_buffer();
162     static void backward_current_buffer();
163     static void line_forward_current_buffer();
164     static void line_backward_current_buffer();
165 aloha 1.25
166     /* ������������������������ */
167 aloha 1.22 static gboolean signal_key_press_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid);
168     static gboolean signal_key_release_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid);
169 aloha 1.25
170     /* ������������������ */
171 aloha 1.27 static void open_online_help();
172 aloha 1.25 static void about_this_application();
173    
174 aloha 1.27 /* ������������������������ */
175 aloha 1.21 static void shiki_editor_window_init(int argc, char **argv);
176 aloha 1.14
177 aloha 1.35 static gboolean is_not_scheme_delimita_p(gunichar ch, gpointer user_data) {
178     return ch != '(' && ch != ')' && !g_unichar_isspace(ch);
179     }
180    
181     static gboolean is_scheme_delimita_p(gunichar ch, gpointer user_data) {
182     return ch == ' ' || ch == '(' || ch == ')' || g_unichar_isspace(ch);
183     }
184    
185     /* ������������������������������ */
186     static void scheme_keyword_highlighting_current_buffer() {
187     GtkTextIter s, e;
188     HIGHILIGHT_COLOR c;
189     gchar *word;
190    
191     if(!keywords_hash) {
192     keywords_hash = g_hash_table_new(g_str_hash, g_str_equal);
193     int i = 0;
194     while(R5RS_keywords[i] != NULL)
195     g_hash_table_insert(keywords_hash, R5RS_keywords[i++], GINT_TO_POINTER(R5RS_KEYWORD_COLOR));
196     i = 0;
197     while(R5RS_functions[i] != NULL)
198     g_hash_table_insert(keywords_hash, R5RS_functions[i++], GINT_TO_POINTER(R5RS_FUNCTION_COLOR));
199     }
200     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &s);
201     gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &e);
202     gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "default_background", &s, &e);
203     gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "default_foreground", &s, &e);
204    
205     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &s);
206    
207     /* ��������� Scheme ������������������������������ */
208     while(TRUE) {
209     gboolean is_comment = FALSE;
210     if(gtk_text_iter_get_char(&s) != ';')
211     gtk_text_iter_forward_find_char(&s, is_not_scheme_delimita_p, NULL, NULL);
212     e = s;
213     if(gtk_text_iter_get_char(&s) == ';') {
214     gtk_text_iter_forward_line(&e);
215     gtk_text_iter_backward_char(&e);
216     is_comment = TRUE;
217     } else
218     gtk_text_iter_forward_find_char(&e, is_scheme_delimita_p, NULL, NULL);
219    
220     word = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &s, &e, FALSE);
221     if(is_comment)
222     gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "comment_highlighting", &s, &e);
223     /* ������������������������������������������������������������������ */
224     else if(R5RS_KEYWORD_COLOR == (c = GPOINTER_TO_INT(g_hash_table_lookup(keywords_hash, word))))
225     gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "keyword_highlighting", &s, &e);
226     else if(R5RS_FUNCTION_COLOR == c)
227     gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "function_highlighting", &s, &e);
228    
229     g_free(word);
230    
231     if(gtk_text_iter_is_end(&e)) break;
232     s = e;
233     }
234     /* XXX : ������������������������������������
235     static ScmRegexp *rx = NULL;
236     gchar *buf = get_all_buffer_contents(Shiki_CURRENT_TEXT_BUFFER);
237     ScmString *input = SCM_STRING(SCM_MAKE_STR(buf));
238     ScmRegMatch *regmatch;
239     ScmObj n, s, e;
240     GtkTextIter start, end;
241     if(!rx) {
242     rx = SCM_REGEXP(Scm_RegComp(SCM_STRING(SCM_MAKE_STR(";. - #[\x0d\x0a]*")), 0));
243     g_return_if_fail(SCM_REGEXPP(rx));
244     }
245     regmatch = SCM_REGMATCH(Scm_RegExec(rx, input));
246     if(!SCM_REGMATCHP(regmatch))
247     return;
248    
249     gtk_text_buffer_create_tag (Shiki_CURRENT_TEXT_BUFFER, "comment_highlighting", "foreground", "red", NULL);
250    
251     n = Scm_MakeInteger(0);
252     s = Scm_RegMatchStart(regmatch, n);
253     e = Scm_RegMatchEnd(regmatch, n);
254     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &start, SCM_INT_VALUE(s));
255     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &end, SCM_INT_VALUE(e));
256     gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "comment_highlighting", &start, &end);
257     //g_print("start : %ld, end : %ld", SCM_INT_VALUE(start), SCM_INT_VALUE(end));
258     Scm_RegMatchDump(regmatch);
259     g_free(buf);
260     */
261     }
262    
263 aloha 1.32 /* ��������������������������������������������� */
264     static void insert_text_handler(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *str, gint len) {
265     /* Undo ��������������������������� */
266     ShikiUndoInfo *undoInfo = g_malloc(sizeof(ShikiUndoInfo));
267     g_return_if_fail(undoInfo != NULL);
268     undoInfo->action = SHIKI_UNDO_INSERT;
269     undoInfo->str = g_strdup(str);
270     undoInfo->strlen = len;
271     undoInfo->start = gtk_text_iter_get_offset(iter);
272     undoInfo->end = undoInfo->start + undoInfo->strlen;
273     Shiki_CURRENT_UNDO_INFO_LIST = g_list_prepend(Shiki_CURRENT_UNDO_INFO_LIST, undoInfo);
274 aloha 1.35 /* g_print("insert : %s, len : %d, start : %d, end : %d\n", undoInfo->str, undoInfo->strlen, undoInfo->start, undoInfo->end); */
275 aloha 1.32 }
276    
277     /* ������������������������������������������������ */
278     static void delete_range_handler(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end) {
279     /* Undo ��������������������������� */
280     ShikiUndoInfo *undoInfo = g_malloc(sizeof(ShikiUndoInfo));
281     g_return_if_fail(undoInfo != NULL);
282     undoInfo->action = SHIKI_UNDO_DELETE;
283     undoInfo->str = gtk_text_buffer_get_text(buffer, start, end, FALSE);
284     undoInfo->start = gtk_text_iter_get_offset(start);
285     undoInfo->end = gtk_text_iter_get_offset(end);
286     undoInfo->strlen = end - start;
287     Shiki_CURRENT_UNDO_INFO_LIST = g_list_prepend(Shiki_CURRENT_UNDO_INFO_LIST, undoInfo);
288 aloha 1.35 /* g_print("delete : %s %d\n", undoInfo->str, undoInfo->strlen); */
289 aloha 1.32 }
290    
291     /* ������������������������������������������������������������ */
292     static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) {
293     /* ��������������������������������������������������������������������� */
294     Shiki_CURRENT_TAB_INFO = (ShikiTabInfo *)g_list_nth_data(Shiki_EDITOR_TAB_INFO_LIST, pagenum);
295    
296     /* ������������������������������������ */
297     Shiki_CURRENT_TAB_NUM = pagenum;
298    
299     /* ������������������������������������������������������ */
300     if(!Shiki_CURRENT_TAB_INFO) return;
301     gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), Shiki_CURRENT_FILENAME);
302    
303     update_modeline_label();
304     }
305    
306 aloha 1.33 static void undo() {
307     g_print("Undo\n");
308     GtkTextIter start, end;
309     ShikiUndoInfo *undoInfo = g_list_nth_data(Shiki_CURRENT_UNDO_INFO_LIST, 0);
310     if(!undoInfo) {
311     g_print("������������ Undo ���������������\n");
312     return;
313     }
314     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &start, undoInfo->start);
315     gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &end, undoInfo->end);
316    
317     if(undoInfo->action == SHIKI_UNDO_INSERT) {
318     Shiki_CURRENT_UNDO_INFO_LIST = g_list_delete_link(Shiki_CURRENT_UNDO_INFO_LIST, g_list_first(Shiki_CURRENT_UNDO_INFO_LIST));
319     gtk_text_buffer_delete(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
320     g_free(undoInfo->str);
321     g_free(undoInfo);
322     } else if(undoInfo->action == SHIKI_UNDO_DELETE) {
323     Shiki_CURRENT_UNDO_INFO_LIST = g_list_delete_link(Shiki_CURRENT_UNDO_INFO_LIST, g_list_first(Shiki_CURRENT_UNDO_INFO_LIST));
324     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &start, undoInfo->str, -1);
325     g_free(undoInfo->str);
326     g_free(undoInfo);
327     }
328    
329     }
330    
331 aloha 1.32 /* ��������������������� */
332     static gboolean signal_key_press_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
333     GtkTextIter start, end;
334    
335     /* ������������������������������������ */
336     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &start);
337     gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &end);
338     gtk_text_buffer_remove_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
339    
340     if(event->state & GDK_CONTROL_MASK && event->state & GDK_MOD1_MASK) {
341     switch(event->keyval) {
342     case GDK_at : /* C-M-SPC */
343     { GtkTextIter start, end;
344     if(!search_sexp(&start, &end)) return FALSE;
345     gtk_text_buffer_select_range(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
346     }
347     break;
348     case GDK_space : /* C-M-SPC */
349     { GtkTextIter start, end;
350     if(!search_last_sexp(&start, &end)) return FALSE;
351     gtk_text_buffer_select_range(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
352     }
353     break;
354     }
355     } else if(event->state & GDK_CONTROL_MASK) {
356     switch(event->keyval) {
357     case GDK_f : /* Ctrl + f : forward */
358     forward_current_buffer();
359     break;
360     case GDK_b : /* Ctrl + b : backward */
361     backward_current_buffer();
362     break;
363     case GDK_n : /* Ctrl + n : next line */
364     line_forward_current_buffer();
365     break;
366     case GDK_p : /* Ctrl + p : previous line */
367     line_backward_current_buffer();
368     break;
369     case GDK_h :
370     { GtkTextIter p;
371     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
372     gtk_text_buffer_backspace(Shiki_CURRENT_TEXT_BUFFER, &p, FALSE, TRUE);
373     }
374     break;
375    
376     case GDK_e : /* Ctrl + e : eval-expression */
377     {
378     gchar *code;
379     GtkTextIter start, end;
380    
381     if(!search_sexp(&start, &end)) return FALSE;
382    
383     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
384     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, "\n\n", -1);
385     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, eval_cstring_by_gauche(code), -1);
386     g_free(code);
387     }
388     break;
389    
390     case GDK_j : /* Ctrl + j : eval-last-sexp */
391     {
392     gchar *code;
393     GtkTextIter start, end;
394    
395     if(!search_last_sexp(&start, &end)) return FALSE;
396    
397     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
398     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, "\n\n", -1);
399     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, eval_cstring_by_gauche(code), -1);
400     g_free(code);
401     }
402     break;
403    
404     case GDK_underscore : /* Ctrl + _ : Undo */
405 aloha 1.33 undo();
406 aloha 1.32 break;
407    
408     case GDK_t : /* Ctrl + t : ��������������� */
409 aloha 1.33 append_default_tabpage_handler();
410 aloha 1.32 break;
411    
412     case GDK_k : /* Ctrl + k : ������������������ */
413     remove_tabpage();
414     break;
415    
416     case GDK_w : /* Ctrl + w : ��������� */
417     gtk_text_buffer_cut_clipboard(Shiki_CURRENT_TEXT_BUFFER, Shiki_EDITOR_CLIPBOARD, TRUE);
418     break;
419    
420     case GDK_y : /* Ctrl + y : ��������� */
421     {GtkTextIter p;
422     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
423     gtk_text_buffer_paste_clipboard(Shiki_CURRENT_TEXT_BUFFER, Shiki_EDITOR_CLIPBOARD, &p, TRUE);
424     }
425     break;
426     }
427     }
428     return FALSE;
429     }
430    
431    
432 aloha 1.23 /* ��������������������������������������� (������������) ��������� */
433 aloha 1.27 static void append_tabpage(gchar *filename) {
434 aloha 1.24 /*-------------------- ������������������������ ----------------------------------*/
435     /* ShikiTabInfo ������������������������������������������������������������������ */
436 aloha 1.34 ShikiTabInfo *tabinfo = g_malloc(sizeof(ShikiTabInfo));
437     tabinfo->undoInfoList = NULL;
438     tabinfo->filename = filename;
439 aloha 1.23 tabinfo->tabpage_label = g_path_get_basename(filename);
440 aloha 1.34 tabinfo->env = Scm_MakeModule(NULL, FALSE);
441 aloha 1.35
442 aloha 1.34 g_return_if_fail(tabinfo->env != SCM_FALSE);
443 aloha 1.24
444     /* ������������������������������ (������������������������) ��������� */
445     tabinfo->tabpage = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
446     gtk_scrolled_window_set_policy (tabinfo->tabpage, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
447    
448     /* ��������������������������������������������������������������������������������������� */
449     tabinfo->text_view = GTK_TEXT_VIEW(gtk_text_view_new());
450     tabinfo->text_buffer = gtk_text_view_get_buffer(tabinfo->text_view);
451 aloha 1.33
452 aloha 1.24 gtk_container_add(GTK_CONTAINER(tabinfo->tabpage), GTK_WIDGET(tabinfo->text_view));
453     gtk_widget_set_size_request(GTK_WIDGET(tabinfo->text_view), 500, 500);
454     g_signal_connect(tabinfo->text_buffer, "mark_set", G_CALLBACK(text_buffer_cursor_moved_handler), tabinfo->text_view);
455 aloha 1.32 g_signal_connect(tabinfo->text_buffer, "insert-text", G_CALLBACK(insert_text_handler), NULL);
456     g_signal_connect(tabinfo->text_buffer, "delete-range", G_CALLBACK(delete_range_handler), NULL);
457    
458 aloha 1.24 /* ������������������������������������������������������������������������������������������������������ */
459     tabinfo->delete_handler_id = g_signal_connect(Shiki_EDITOR_WINDOW, "delete_event", G_CALLBACK(delete_event_handler), tabinfo->text_buffer);
460 aloha 1.33
461 aloha 1.24 /* ������������������������ */
462 aloha 1.35 /* ������������������������������������������ */
463     gtk_text_buffer_create_tag(tabinfo->text_buffer, "default_background", "background", "black", NULL);
464     gtk_text_buffer_create_tag(tabinfo->text_buffer, "default_foreground", "foreground", "green", NULL);
465 aloha 1.24 /* ������������������������������������������������ */
466 aloha 1.35 gtk_text_buffer_create_tag(tabinfo->text_buffer, "parent_emphasis_background", "background", "pink", NULL);
467    
468     /* ��������������������������������������� */
469     gtk_text_buffer_create_tag(tabinfo->text_buffer, "keyword_highlighting", "foreground", "blue", NULL);
470     /* ������ */
471     gtk_text_buffer_create_tag(tabinfo->text_buffer, "function_highlighting", "foreground", "red", NULL);
472     /* ������������ */
473     gtk_text_buffer_create_tag (tabinfo->text_buffer, "comment_highlighting", "foreground", "orange", NULL);
474 aloha 1.24
475     /* ������������������������������������������ */
476 aloha 1.27 gtk_notebook_append_page(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(tabinfo->tabpage), gtk_label_new(tabinfo->tabpage_label));
477 aloha 1.24 /* ������������������������������������������������������������������ */
478 aloha 1.23 Shiki_EDITOR_TAB_INFO_LIST = g_list_append(Shiki_EDITOR_TAB_INFO_LIST, tabinfo);
479 aloha 1.32
480 aloha 1.27 gtk_widget_show_all(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
481 aloha 1.24 /* ��������������������������������� */
482 aloha 1.27 gtk_notebook_set_current_page(Shiki_EDITOR_NOTEBOOK, g_list_length(Shiki_EDITOR_TAB_INFO_LIST) - 1);
483 aloha 1.23 }
484    
485 aloha 1.33 static void append_default_tabpage_handler() {
486     append_tabpage(g_strdup("*scratch*"));
487     }
488    
489 aloha 1.23 /* ������������������������������������������ (������������) ��������� */
490 aloha 1.27 static void remove_tabpage() {
491 aloha 1.23 /* ��������� 1 ��������������������������������������������������� */
492     if(g_list_length(Shiki_EDITOR_TAB_INFO_LIST) == 1)
493     return;
494     if(!not_yet_save_changes_really_quit(Shiki_CURRENT_TEXT_BUFFER)) {
495     /* ��������������������������������������������������������������������������������������������� */
496     g_signal_handler_disconnect(Shiki_EDITOR_WINDOW, (Shiki_CURRENT_TAB_INFO)->delete_handler_id);
497     /* ������������������������ */
498     gtk_widget_destroy(GTK_WIDGET(Shiki_CURRENT_TEXT_VIEW));
499     /* ������������������������������������������ */
500     g_free(Shiki_CURRENT_TAB_TITLE);
501     g_free(Shiki_CURRENT_FILENAME);
502     Shiki_EDITOR_TAB_INFO_LIST = g_list_delete_link(Shiki_EDITOR_TAB_INFO_LIST, g_list_nth(Shiki_EDITOR_TAB_INFO_LIST, Shiki_CURRENT_TAB_NUM));
503     g_free(Shiki_CURRENT_TAB_INFO);
504    
505     /* ������������������������������������ */
506     Shiki_CURRENT_TAB_INFO = g_list_nth_data(Shiki_EDITOR_TAB_INFO_LIST, Shiki_CURRENT_TAB_NUM);
507 aloha 1.27 gtk_notebook_remove_page(Shiki_EDITOR_NOTEBOOK, Shiki_CURRENT_TAB_NUM);
508 aloha 1.23 /* ��������������������������������������� */
509 aloha 1.27 gtk_widget_queue_draw(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
510 aloha 1.23 }
511     }
512    
513 aloha 1.15 /* ������������������������������ */
514     static void clear_current_buffer() {
515     GtkTextIter start, end;
516 aloha 1.16 gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &start);
517     gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &end);
518     gtk_text_buffer_delete(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
519 aloha 1.15 }
520    
521 aloha 1.14 /* ������������������������������������ */
522     static void load_buffer_by_gauche() {
523     GtkTextIter p;
524 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
525     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
526     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(get_all_buffer_contents(Shiki_CURRENT_TEXT_BUFFER)), -1);
527 aloha 1.14 }
528    
529     /* ������������������������ */
530 aloha 1.27 static void load_scheme_file_by_gauche() {
531 aloha 1.14 gchar *contents, *text;
532     gsize br, bw, len;
533     GError *err = NULL;
534     gchar *filename = get_filename_from_dialog("File Selection");
535     GtkTextIter p;
536    
537     if(!filename) return;
538 aloha 1.33
539 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
540     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
541 aloha 1.14
542     if(g_file_get_contents(filename, &contents, &len, NULL)) {
543     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
544 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(text), -1);
545 aloha 1.14 else
546 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(contents), -1);
547 aloha 1.14 }
548     g_free(text); g_free(contents); g_free(filename);
549     }
550    
551 aloha 1.13 /* gauche ������������������������������������ */
552     static gchar *load_cstring_by_gauche(gchar *s) {
553     gchar *msg;
554    
555     ScmObj result, error;
556     /* ��������������������������������� */
557     ScmObj is = Scm_MakeInputStringPort(SCM_STRING(SCM_MAKE_STR(s)), TRUE);
558     /* ������������������������������ */
559     ScmObj os = Scm_MakeOutputStringPort(TRUE);
560    
561 aloha 1.34 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*input*")), is);
562     Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
563 aloha 1.13 /* Scheme ��������������������������������������������������������������������������������� S ��������������������������������������������������������������������������� *error* ������������������ */
564 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));
565 aloha 1.13
566 aloha 1.34 error = Scm_GlobalVariableRef(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
567 aloha 1.13
568     /* ��������������������������������������������������������� */
569     if (!SCM_FALSEP(error))
570     Scm_Write(error, os, SCM_WRITE_DISPLAY);
571     else
572     Scm_Write(result, os, SCM_WRITE_DISPLAY);
573    
574     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
575     /* ������������������ */
576     Scm_ClosePort(SCM_PORT(is));
577     Scm_ClosePort(SCM_PORT(os));
578    
579     return msg;
580     }
581    
582 aloha 1.12 static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog) {
583     gchar *font_name = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (font_dialog));
584     if(font_name) {
585     GtkRcStyle *style = gtk_rc_style_new ();
586     pango_font_description_free(style->font_desc);
587     style->font_desc = pango_font_description_from_string(font_name);
588 aloha 1.16 gtk_widget_modify_style (GTK_WIDGET(Shiki_CURRENT_TEXT_VIEW), style);
589 aloha 1.12 g_free (font_name);
590     }
591     }
592    
593 aloha 1.14 /* ������������������������������������������������������ */
594 aloha 1.12 static void select_font(){
595     GtkWidget *font_dialog = gtk_font_selection_dialog_new("Font Selection Dialog");
596     g_signal_connect (GTK_FONT_SELECTION_DIALOG (font_dialog)->ok_button, "clicked", G_CALLBACK(font_selection_ok), font_dialog);
597     gtk_dialog_run(GTK_DIALOG(font_dialog));
598     gtk_widget_destroy(font_dialog);
599     }
600    
601 aloha 1.11 /* ������������������������������������������ */
602     static void about_this_application() {
603     GtkAboutDialog *about = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
604     const gchar *authors[] = {
605 aloha 1.23 "������������ (���������) <alohakun@gmail.com>\n",
606     "Contribute : tkng ������",
607     "(http://d.hatena.ne.jp/tkng/20061113)", NULL
608 aloha 1.11 };
609     gtk_about_dialog_set_authors(about, authors);
610     gtk_about_dialog_set_copyright(about, "Copyright(C)2006 WAKATSUKI Toshihiro");
611     gtk_about_dialog_set_name(about, "��� (SHIKI)");
612     gtk_about_dialog_set_website_label(about, "���������30������������������������������������������������������������Blog");
613     gtk_about_dialog_set_website(about, "http://alohakun.blog7.fc2.com/blog-category-29.html");
614     gtk_dialog_run(GTK_DIALOG(about));
615     gtk_widget_destroy(GTK_WIDGET(about));
616     }
617    
618 aloha 1.10 /* ��������������������������������������������������������������� */
619     static gint get_current_line_number(GtkTextBuffer *b) {
620     GtkTextIter p;
621     gtk_text_buffer_get_iter_at_mark(b, &p, gtk_text_buffer_get_insert(b));
622     return gtk_text_iter_get_line(&p) + 1;
623     }
624    
625     /* ��������������������������������������������������������������� */
626     static void update_modeline_label() {
627 aloha 1.16 gchar* basename = g_path_get_basename(Shiki_CURRENT_TAB_TITLE);
628 aloha 1.11 gchar* l = g_strdup_printf("-E:%s %-10s (Gauche Interaction)--L%d--------------------------------------",
629 aloha 1.16 gtk_text_buffer_get_modified(Shiki_CURRENT_TEXT_BUFFER) ? "**" : "--",
630     basename, get_current_line_number(Shiki_CURRENT_TEXT_BUFFER));
631     gtk_label_set_text(GTK_LABEL(Shiki_EDITOR_MODELINE_LABEL), l);
632 aloha 1.10 g_free(l); g_free(basename);
633     }
634    
635     static void text_buffer_cursor_moved_handler(){
636     update_modeline_label();
637     }
638 aloha 1.1
639     /* ��������������������������������������������������������������� */
640     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer) {
641     GtkTextIter start, end;
642     gtk_text_buffer_get_start_iter(buffer, &start);
643     gtk_text_buffer_get_end_iter(buffer, &end);
644     return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
645     }
646    
647     /* buffer ������������������������ filename ��������� */
648     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer) {
649     gchar *contents, *text;
650     gsize br, bw;
651     GError *err = NULL;
652    
653     if(!filename) return FALSE;
654     contents = get_all_buffer_contents(buffer);
655     text = g_locale_from_utf8(contents, -1, &br, &bw, &err);
656     /* ��������������������������������� */
657     g_file_set_contents(filename, text, -1, NULL);
658     gtk_text_buffer_set_modified(buffer, FALSE);
659 aloha 1.10 update_modeline_label();
660 aloha 1.1 g_free(contents); g_free(text);
661     return TRUE;
662     }
663    
664     /* ������������������������������������������������������msg ������������������������������������ */
665     static gchar *get_filename_from_dialog(const gchar *msg) {
666    
667     GtkWidget *dialog = gtk_file_selection_new(msg);
668     int resp = gtk_dialog_run(GTK_DIALOG(dialog));
669     gchar *filename = NULL;
670    
671     /* gtk_file_selection_get_filename ������������������������������������������������������������������������������������������������������������������������������ */
672     if(resp == GTK_RESPONSE_OK)
673     filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog)));
674    
675     gtk_widget_destroy(dialog);
676     return filename;
677     }
678    
679     /* ��������������������������������������������������������������������� */
680 aloha 1.27 static void save_file() {
681 aloha 1.1
682 aloha 1.22 /* ��������������������������������������� */
683     if(g_ascii_strcasecmp("*help*", Shiki_CURRENT_TAB_TITLE) == 0) return;
684 aloha 1.33
685 aloha 1.1 /* ������������������������������������ */
686 aloha 1.16 if(!gtk_text_buffer_get_modified(Shiki_CURRENT_TEXT_BUFFER)) return;
687 aloha 1.1
688     /* ������������������������������������������������������������������������������������������������������ */
689 aloha 1.16 if(g_ascii_strcasecmp("*scratch*", Shiki_CURRENT_TAB_TITLE) == 0) {
690 aloha 1.7 gchar *filename = get_filename_from_dialog("Save File As ...");
691     if(!filename) return;
692 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
693 aloha 1.27 gtk_notebook_set_tab_label_text(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
694 aloha 1.16 gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), filename);
695 aloha 1.1 g_free(filename);
696     } else
697 aloha 1.16 save_text_buffer(Shiki_CURRENT_TAB_TITLE, Shiki_CURRENT_TEXT_BUFFER);
698 aloha 1.1 }
699    
700     /* ��������������������������������������������������������������������������� */
701 aloha 1.27 static void save_file_as() {
702 aloha 1.1 gchar *filename = get_filename_from_dialog("Save File As ...");
703    
704 aloha 1.7 if(!filename) return;
705 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
706 aloha 1.1
707 aloha 1.27 gtk_notebook_set_tab_label_text(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
708 aloha 1.16 gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
709 aloha 1.1
710     g_free(filename);
711     }
712    
713     /* YES ������������NO ������������������������������������ callback */
714 aloha 1.17 static void really_quit_dialog_yes(GtkWidget *widget, gboolean *flag){*flag = FALSE;}
715     static void really_quit_dialog_no(GtkWidget *widget, gint *flag){*flag = TRUE;}
716 aloha 1.1
717     /* ��������������������������������������������� ? */
718 aloha 1.17 static gboolean not_yet_save_changes_really_quit(GtkTextBuffer *buffer) {
719 aloha 1.1 GtkWidget *yes_button, *no_button;
720     static GtkWidget *dialog_window = NULL;
721    
722     /* ��������������������������������������� */
723     if(!gtk_text_buffer_get_modified(buffer)) return FALSE;
724    
725     if(dialog_window == NULL) {
726     gboolean flag = TRUE;
727     dialog_window = gtk_dialog_new ();
728    
729     /* ��������������������������������������������� ? ��������������������������� */
730     g_signal_connect(G_OBJECT(dialog_window), "delete_event", G_CALLBACK(gtk_false), NULL);
731     g_signal_connect(G_OBJECT(dialog_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
732 aloha 1.5 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->vbox),
733     gtk_label_new("������������������������������������������\n��������������������������������������� ?"), TRUE, TRUE, 0);
734 aloha 1.1 gtk_window_set_title(GTK_WINDOW (dialog_window), "Really Quit ?");
735     /* YES ������������ */
736 aloha 1.8 yes_button = gtk_button_new_with_mnemonic("������ (_Y)");
737 aloha 1.1 g_signal_connect(GTK_OBJECT(yes_button), "clicked", G_CALLBACK(really_quit_dialog_yes), &flag);
738     g_signal_connect_swapped(GTK_OBJECT(yes_button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(dialog_window));
739     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), yes_button, TRUE, TRUE, 0);
740    
741     /* NO ������������ */
742 aloha 1.8 no_button = gtk_button_new_with_mnemonic("��������� (_N)");
743 aloha 1.1 g_signal_connect(GTK_OBJECT(no_button), "clicked", G_CALLBACK(really_quit_dialog_no), &flag);
744     g_signal_connect_swapped(GTK_OBJECT(no_button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(dialog_window));
745     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), no_button, TRUE, TRUE, 0);
746    
747     gtk_window_set_modal(GTK_WINDOW(dialog_window), TRUE);
748 aloha 1.16 gtk_window_set_transient_for(GTK_WINDOW(dialog_window), GTK_WINDOW (Shiki_EDITOR_WINDOW));
749 aloha 1.1
750     gtk_widget_show_all(dialog_window);
751     gtk_main ();
752     dialog_window = NULL;
753    
754     /* "delete_event" ��������������� FALSE ���������"destory" ������������������window ������������������ */
755     return flag;
756     }
757     return TRUE;
758     }
759    
760     /* ������������������������������������������������������������������������������������������ */
761 aloha 1.27 static gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, GtkTextBuffer *buffer){
762     return not_yet_save_changes_really_quit(buffer);
763 aloha 1.1 }
764    
765     /* ��������������������� */
766 aloha 1.27 static void open_file(gchar *filename) {
767 aloha 1.1 gchar *contents, *text;
768     gsize br, bw, len;
769     GError *err = NULL;
770 aloha 1.33
771 aloha 1.27 g_return_if_fail(filename != NULL);
772 aloha 1.33
773 aloha 1.1 if(g_file_get_contents(filename, &contents, &len, NULL)) {
774     GtkTextIter p;
775 aloha 1.3
776 aloha 1.1 /* ������������������������������ */
777 aloha 1.27 append_tabpage(g_strdup(filename));
778 aloha 1.1
779     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
780 aloha 1.17 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER, contents, len);
781 aloha 1.1 else
782 aloha 1.17 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER, text, len);
783 aloha 1.1
784     /* ������������������������ */
785 aloha 1.17 gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
786 aloha 1.1 /* ������������������������������ */
787 aloha 1.17 gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
788     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
789 aloha 1.10 update_modeline_label();
790 aloha 1.16 gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
791 aloha 1.27 gtk_widget_show_all(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
792 aloha 1.1 g_free(contents); g_free(text); g_free(filename);
793 aloha 1.35
794     /* ��������������������������������� */
795     scheme_keyword_highlighting_current_buffer();
796 aloha 1.1 } else
797     g_printerr("Get file contents error !\n");
798     }
799    
800 aloha 1.21 /* ��������������������������������������������������� */
801 aloha 1.27 static void open_file_handler() {
802 aloha 1.21 gchar *filename = get_filename_from_dialog("File Selection");
803    
804     if(!filename) return;
805 aloha 1.27 open_file(filename);
806 aloha 1.1 }
807    
808     /* gauche ��������������������������������� */
809     static gchar *eval_cstring_by_gauche(gchar *s) {
810     gchar *msg;
811    
812     ScmObj result, error;
813     /* ������������������������������ */
814     ScmObj os = Scm_MakeOutputStringPort(TRUE);
815    
816     /* Scheme ��������������������������������������� */
817     /* http://alohakun.blog7.fc2.com/blog-entry-517.html */
818 aloha 1.34 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*input*")), SCM_MAKE_STR(s));
819     Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
820 aloha 1.1
821 aloha 1.34 result = Scm_EvalCString("(guard (e (else (set! *error* e) #f)) (eval (read-from-string *input*) (current-module)))", SCM_OBJ(Shiki_CURRENT_BUFFER_ENV));
822 aloha 1.1
823 aloha 1.34 error = Scm_GlobalVariableRef(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
824 aloha 1.1
825     /* ��������������������������������������������������������� */
826     if (!SCM_FALSEP(error))
827     Scm_Write(error, os, SCM_WRITE_DISPLAY);
828     else
829     Scm_Write(result, os, SCM_WRITE_DISPLAY);
830    
831     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
832     /* ������������������ */
833     Scm_ClosePort(SCM_PORT(os));
834    
835     return msg;
836     }
837    
838 aloha 1.13 /* ������������������������������������������������������������������ S ��������������� (������������) */
839 aloha 1.27 static void load_region_by_gauche() {
840 aloha 1.1
841     GtkTextIter start, end, p;
842     gchar *code;
843 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
844     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
845 aloha 1.1
846     /* ������������������������������������������������������������ */
847 aloha 1.16 if(gtk_text_buffer_get_selection_bounds(Shiki_CURRENT_TEXT_BUFFER, &start, &end)) {
848     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
849     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(code), -1);
850 aloha 1.1 g_free(code);
851     }
852     }
853    
854     // GtkTextCharPredicate
855     static gboolean is_kakko_or_kokka(gunichar ch, gpointer p) {
856     return ch == '(' || ch == ')';
857     }
858 aloha 1.29 static gboolean is_kakko(gunichar ch, gpointer p) {return ch == '(';}
859 aloha 1.1 static gboolean is_kokka(gunichar ch, gpointer p) {return ch == ')';}
860    
861 aloha 1.30 /* ��������������������� '(' ��������������� ')' ������������������ (S ���) ��������������� */
862     static gboolean search_sexp(GtkTextIter *start, GtkTextIter *end) {
863 aloha 1.33
864 aloha 1.30 /* ������������������������������ */
865     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, start, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
866    
867     if(gtk_text_iter_get_char(start) != '(')
868     gtk_text_iter_forward_find_char(start, is_kakko, NULL, NULL);
869    
870     *end = *start;
871    
872     /* ��������������������������������� S ������������������ */
873     if(!search_sexp_kokka(end)) return FALSE;
874     gtk_text_iter_forward_char(end);
875     return TRUE;
876     }
877    
878     static gboolean search_sexp_kokka(GtkTextIter *end) {
879 aloha 1.29 gint nest_level = 0;
880 aloha 1.33
881 aloha 1.30 /* ������������ ')' ��������� */
882 aloha 1.29 while(1) {
883 aloha 1.30 if(!gtk_text_iter_forward_find_char(end, is_kakko_or_kokka, NULL, NULL))
884 aloha 1.29 return FALSE;
885    
886 aloha 1.30 if(gtk_text_iter_get_char(end) == '(')
887 aloha 1.29 nest_level++;
888     else {
889     if(!nest_level)
890     break;
891     else
892     nest_level--;
893     }
894     }
895     return TRUE;
896     }
897 aloha 1.1
898 aloha 1.30 /* ��������������������� ')' ��������������� '(' ������������������ (S ���) ��������������� */
899     static gboolean search_last_sexp(GtkTextIter *start, GtkTextIter *end) {
900    
901     /* ������������������������������ */
902     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
903    
904     gtk_text_iter_backward_char(end);
905 aloha 1.33
906 aloha 1.30 if(gtk_text_iter_get_char(end) != ')')
907     gtk_text_iter_backward_find_char(end, is_kokka, NULL, NULL);
908     *start = *end;
909     gtk_text_iter_forward_char(end);
910    
911     /* ��������������������������������� S ������������������ */
912     if(!search_last_sexp_kakko(start)) return FALSE;
913    
914     return TRUE;
915     }
916    
917 aloha 1.1 /* ')' ��������������� '(' ������������������ (S ���) ��������������� */
918 aloha 1.29 static gboolean search_last_sexp_kakko(GtkTextIter *start) {
919 aloha 1.1 gint nest_level = 0;
920 aloha 1.30 /* ��������������������������������������� ')' ��������� */
921 aloha 1.1 while(1) {
922     if(!gtk_text_iter_backward_find_char(start, is_kakko_or_kokka, NULL, NULL))
923     return FALSE;
924    
925     if(gtk_text_iter_get_char(start) == ')')
926     nest_level++;
927     else {
928     if(!nest_level)
929     break;
930     else
931     nest_level--;
932     }
933     }
934     return TRUE;
935     }
936    
937     /* ������������������������������������������������ */
938     static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer) {
939     gint nest_level = 0;
940     GtkTextIter start, end;
941     gtk_text_buffer_get_start_iter(buffer, &start);
942     if(gtk_text_iter_get_char(&start) == '(') nest_level++;
943    
944     /* ��������������������� (= end) ��������� */
945     gtk_text_buffer_get_iter_at_mark(buffer,&end, gtk_text_buffer_get_insert(buffer));
946    
947     while(1) {
948     /* end ������ '(' ��� ')' ��������������������������������������������� */
949     if(!gtk_text_iter_forward_find_char(&start, is_kakko_or_kokka, NULL, &end))
950     return nest_level;
951    
952     if(gtk_text_iter_get_char(&start) == '(')
953     nest_level++;
954     else
955     nest_level--;
956     }
957     }
958    
959     /* ��������������������������������� on/off */
960     static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook) {
961     gint tval = FALSE;
962     gint bval = FALSE;
963     if(notebook->show_tabs == FALSE)
964     tval = TRUE;
965     if(notebook->show_border == FALSE)
966     bval = TRUE;
967    
968     gtk_notebook_set_show_tabs(notebook, tval);
969     gtk_notebook_set_show_border(notebook, bval);
970     }
971    
972     /* ������������������������ */
973 aloha 1.17 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook ) {
974 aloha 1.1 gtk_notebook_set_tab_pos(notebook, (notebook->tab_pos + 1) % 4);
975     }
976    
977     /* ������������������������������������������ */
978    
979 aloha 1.3 /* ��������������������� ^npfb */
980 aloha 1.7 static void forward_current_buffer() {
981 aloha 1.3 GtkTextIter p;
982 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
983 aloha 1.3 gtk_text_iter_forward_char(&p);
984 aloha 1.16 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
985 aloha 1.3 }
986 aloha 1.7 static void backward_current_buffer() {
987 aloha 1.3 GtkTextIter p;
988 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
989 aloha 1.3 gtk_text_iter_backward_char(&p);
990 aloha 1.16 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
991 aloha 1.3 }
992 aloha 1.7 static void line_forward_current_buffer() {
993 aloha 1.3 GtkTextIter p;
994 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
995     gtk_text_view_forward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
996     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
997 aloha 1.7 }
998     static void line_backward_current_buffer() {
999 aloha 1.3 GtkTextIter p;
1000 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
1001     gtk_text_view_backward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
1002     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
1003 aloha 1.3 }
1004    
1005 aloha 1.1 /* ��������������������� */
1006 aloha 1.8 static gboolean signal_key_release_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
1007     static gint metakey_pressed = 0;
1008 aloha 1.6 static gint controlx_pressed = 0;
1009 aloha 1.1
1010     if(event->keyval == GDK_parenright && event->state & GDK_SHIFT_MASK) {
1011     GtkTextIter start, end;
1012    
1013     /* ������������������������������ */
1014 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
1015 aloha 1.1
1016     start = end;
1017     gtk_text_iter_backward_char(&start);
1018    
1019     /* ��������������������������������� S ������������������ */
1020 aloha 1.29 if(!search_last_sexp_kakko(&start)) return FALSE;
1021 aloha 1.1
1022 aloha 1.16 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
1023 aloha 1.1 }
1024    
1025     /* ������������������������������������������������������������������������������������������������ (���������������) ������������������ */
1026     if(event->keyval == GDK_Return) {
1027 aloha 1.16 gint indentWidth = get_parent_nest_level_at_cursor(Shiki_CURRENT_TEXT_BUFFER) * editor_indent_width;
1028 aloha 1.1 gchar *indent = g_strnfill(indentWidth, ' ');
1029 aloha 1.16 gtk_text_buffer_insert_at_cursor(Shiki_CURRENT_TEXT_BUFFER, indent, -1);
1030 aloha 1.1 g_free(indent);
1031     }
1032    
1033 aloha 1.6 /* C-x */
1034     if(event->keyval == GDK_x && event->state & GDK_CONTROL_MASK) {
1035     controlx_pressed++;
1036 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-x -");
1037 aloha 1.6 } else if(event->state & GDK_CONTROL_MASK) {
1038 aloha 1.8
1039 aloha 1.6 if(controlx_pressed > 0) {
1040     switch(event->keyval) {
1041     case GDK_c :/* C-x C-c : ������ */
1042 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-c");
1043 aloha 1.6 {/* "delete-event" ��������������������������������������� �� ������������������������������������ */
1044     GdkEvent ev;
1045    
1046     ev.any.type = GDK_DELETE;
1047 aloha 1.16 ev.any.window = Shiki_EDITOR_WINDOW->window;
1048 aloha 1.6 ev.any.send_event = FALSE;
1049     gdk_event_put (&ev);
1050     }
1051     break;
1052    
1053     case GDK_f : /* C-x C-f : ������������������ */
1054 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-f");
1055 aloha 1.27 open_file_handler();
1056 aloha 1.6 break;
1057    
1058     case GDK_s : /* C-x C-s : ������������������ */
1059 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-s");
1060 aloha 1.27 save_file();
1061 aloha 1.6 break;
1062    
1063     case GDK_w : /* C-x C-w : ������������������������ */
1064 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-w");
1065 aloha 1.27 save_file_as();
1066 aloha 1.6 break;
1067     }
1068     controlx_pressed = 0;
1069     }
1070 aloha 1.8
1071     switch(event->keyval) {
1072     case GDK_g :/* C-g : ��������������� */
1073     metakey_pressed = 0;
1074     controlx_pressed = 0;
1075    
1076 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "Quit");
1077 aloha 1.8 break;
1078     }
1079    
1080 aloha 1.6 }
1081 aloha 1.1 return FALSE;
1082     }
1083 aloha 1.27 static void open_online_help() {
1084 aloha 1.22 GtkTextIter p;
1085 aloha 1.27 append_tabpage(g_strdup("*help*"));
1086 aloha 1.22 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER,
1087 aloha 1.30 "������\n"
1088     "$ ./shiki [file1 file2 ....]\n\n"
1089     "[���������������������������] ��������������������� (C-x C-f)\n"
1090     "[������������������������������������������] ��������������������� (C-x C-s)\n"
1091     "[���������������������������������������������] ��������������������������� (C-x C-w)\n"
1092     "[���������������������] ��������������� gauche ������������ (region-compile)\n"
1093     "[��������������� (���������) ���������������] ��������� on/off\n"
1094     "[������ (���������) ���������������] ������������������������\n"
1095 aloha 1.33 "[������ + ������������] ��������������������������� (C-t) (tab)\n"
1096     "[���������������������������] ������������ (C-_)\n"
1097 aloha 1.30 "[���������������������] ������������������������\n"
1098 aloha 1.33 "[�� ������������] ������������������������ (C-k) (kill buffer)\n"
1099 aloha 1.30 "[A ������������] ���������������������\n"
1100     "[���������������������������] Scheme ������������������������\n"
1101     "[���������������������������������] ���������������������������������������\n"
1102     "[��������� (?) ������������] ���������������������������������������\n"
1103 aloha 1.33 "[info ������������] ���������������������������������������������������\n"
1104     "\n"
1105 aloha 1.30 "C-f : ��� ��������� (forward)\n"
1106     "C-b : ��� ��������� (backward)\n"
1107     "C-n : ��� ��������� (next line)\n"
1108 aloha 1.33 "C-p : ��� ��������� (previous line)\n"
1109     "\n"
1110     "C-h : ���������������������\n"
1111 aloha 1.31 "C-w : ���������\n"
1112 aloha 1.33 "C-y : ��������� (������������)\n"
1113     "\n"
1114 aloha 1.30 "C-e : ��������������������� S ������������ (eval-expression)\n"
1115     "C-j : ��������������������� S ������������ (eval-last-sexp)\n"
1116 aloha 1.33 "(emacs/xyzzy ��� *scratch* ���������������������)\n"
1117     "\n"
1118 aloha 1.31 "C-M-@ : ��������������������� S ������������ (mark-sexp)\n"
1119     "C-M-SPC : ��������������������� S ������������ (mark-last-sexp)\n"
1120 aloha 1.33 "C-x C-c : ��������������������������� �� ���������������������������������\n"
1121     "\n"
1122 aloha 1.30 "������������������������������������������������������������������Really Quit ?���������������������������������\n", -1);
1123     gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
1124     /* ������������������������������ */
1125     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
1126     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
1127 aloha 1.22 }
1128    
1129 aloha 1.1 /* ��������������������������������������� */
1130 aloha 1.21 static void shiki_editor_window_init(int argc, char **argv) {
1131 aloha 1.26 GtkWidget *vbox, *toolbar;
1132 aloha 1.1 GtkToolItem *icon;
1133     GtkIconSize iconsize;
1134 aloha 1.2 GtkTooltips *toolbar_tips = gtk_tooltips_new();
1135 aloha 1.1 /* ��������������������������������������������������������������������������������� */
1136     GtkToolItem *oicon, *sicon, *saicon, *eicon;
1137    
1138 aloha 1.8 gint contextid;
1139    
1140 aloha 1.1 /* ������������ */
1141 aloha 1.16 Shiki_EDITOR_WINDOW = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1142     g_signal_connect(G_OBJECT(Shiki_EDITOR_WINDOW), "destroy", G_CALLBACK(gtk_main_quit), NULL);
1143 aloha 1.1
1144 aloha 1.31 /* ������������������������������������������������������������ */
1145     Shiki_EDITOR_CLIPBOARD = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
1146    
1147 aloha 1.1 /* ������������������������������������ */
1148     vbox = gtk_vbox_new(FALSE, 0);
1149     /* ��������������������� */
1150     toolbar = gtk_toolbar_new();
1151     gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
1152    
1153 aloha 1.26 Shiki_EDITOR_NOTEBOOK = GTK_NOTEBOOK(gtk_notebook_new());
1154     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "switch-page", GTK_SIGNAL_FUNC(switch_tabpage_handler), NULL);
1155 aloha 1.1
1156     /* ������������������������������������������������ */
1157     gtk_toolbar_set_style(GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
1158     iconsize = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar));
1159    
1160     /* ������������������ */
1161    
1162     /* ������������������ */
1163     oicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-open", iconsize), "");
1164     /* ������������������������������������������������������������������������������������ */
1165 aloha 1.27 g_signal_connect(G_OBJECT(oicon), "clicked", G_CALLBACK(open_file_handler), NULL);
1166 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(oicon));
1167 aloha 1.2 gtk_tool_item_set_tooltip(oicon, toolbar_tips, "���������������������������",
1168     "���������������������������������������������������������������������������������������");
1169 aloha 1.1
1170     /* ������������������ */
1171     sicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-save", iconsize), "");
1172     /* ������������������������������������������������������������������������������������ */
1173 aloha 1.27 g_signal_connect(G_OBJECT(sicon), "clicked", G_CALLBACK(save_file), NULL);
1174 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(sicon));
1175 aloha 1.2 gtk_tool_item_set_tooltip(sicon, toolbar_tips, "������������������������������",
1176     "������������������������������������������������������������������������������������������������������������������������������������");
1177 aloha 1.1
1178     /* ��������������������������� */
1179     saicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-save-as", iconsize), "");
1180     /* ������������������������������������������������������������������������������������������������������������������ */
1181 aloha 1.27 g_signal_connect(G_OBJECT(saicon), "clicked", G_CALLBACK(save_file_as), NULL);
1182 aloha 1.2 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(saicon));
1183     gtk_tool_item_set_tooltip(saicon, toolbar_tips, "������������������������������������",
1184     "");
1185 aloha 1.1
1186     /* ������������������ */
1187     eicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-execute", iconsize), "");
1188 aloha 1.14 /* ������������������������������������������ libgauche ������������������ */
1189 aloha 1.27 g_signal_connect(G_OBJECT(eicon), "clicked", G_CALLBACK(load_region_by_gauche), NULL);
1190 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(eicon));
1191 aloha 1.14 gtk_tool_item_set_tooltip(eicon, toolbar_tips, "��������������� S ������������������������ (load-region-lisp)",
1192 aloha 1.2 "Scheme (gauche) ������������������ S ������������������������");
1193 aloha 1.1
1194 aloha 1.16 gtk_container_add(GTK_CONTAINER(Shiki_EDITOR_WINDOW), vbox);
1195 aloha 1.26 gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
1196 aloha 1.1
1197 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-apply", iconsize), "");
1198 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(tabsborder_on_off), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1199 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1200 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "��������� on/off", "");
1201 aloha 1.1
1202 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-preferences", iconsize), "");
1203 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(rotate_tab_position), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1204 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1205 aloha 1.14 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
1206 aloha 1.1
1207 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-add", iconsize), "");
1208 aloha 1.33 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(append_default_tabpage_handler), NULL);
1209 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1210 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������", "");
1211 aloha 1.1
1212 aloha 1.33 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-undo", iconsize), "");
1213     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(undo), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1214     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1215     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Undo","");
1216    
1217 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-delete", iconsize), "");
1218 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(clear_current_buffer), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1219 aloha 1.15 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1220     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������",
1221     "���������������������������������������������������������������������");
1222    
1223 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-close", iconsize), "");
1224 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(remove_tabpage), NULL);
1225 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1226 aloha 1.2 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������",
1227     "���������������������������������������������������������������");
1228 aloha 1.15
1229 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-bold", iconsize), "");
1230 aloha 1.12 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(select_font), NULL);
1231     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1232     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
1233 aloha 1.1
1234 aloha 1.18 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-connect", iconsize), "");
1235 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_scheme_file_by_gauche), NULL);
1236 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1237     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Scheme ������������������������", "");
1238    
1239 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-convert", iconsize), "");
1240 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_buffer_by_gauche), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1241 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1242     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������", "");
1243    
1244 aloha 1.22 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-dialog-question", iconsize), "");
1245 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(open_online_help), NULL);
1246 aloha 1.22 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1247     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������", "");
1248    
1249 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-dialog-info", iconsize), "");
1250 aloha 1.11 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(about_this_application), NULL);
1251     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1252     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
1253    
1254 aloha 1.16 gtk_box_pack_start(GTK_BOX(vbox), Shiki_EDITOR_MODELINE_LABEL = gtk_label_new("-E:** *scratch* (Gauche Interaction)--L1--All---------------------------------"), TRUE, TRUE, 0);
1255 aloha 1.12
1256 aloha 1.8 /* C-x C-s ��������������������������������������������������������������������������������������� */
1257 aloha 1.16 Shiki_EDITOR_STATUSBAR = gtk_statusbar_new();
1258     gtk_box_pack_start(GTK_BOX(vbox), Shiki_EDITOR_STATUSBAR, TRUE, TRUE, 0);
1259     contextid = gtk_statusbar_get_context_id(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), "");
1260 aloha 1.8
1261     /* ������������������������������������������������ */
1262 aloha 1.26 g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-press-event", G_CALLBACK (signal_key_press_handler), GINT_TO_POINTER(contextid));
1263     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-release-event", G_CALLBACK (signal_key_release_handler), GINT_TO_POINTER(contextid));
1264 aloha 1.12
1265 aloha 1.21 /* ��������������������������������������������� */
1266     if(argc >= 2) {
1267     int i;
1268     for(i = 1; i < argc; i++)
1269 aloha 1.27 open_file(g_strdup(argv[i]));
1270 aloha 1.21 } else /* ������������������������������������������������������������������ */
1271 aloha 1.26 open_online_help(Shiki_EDITOR_NOTEBOOK);
1272 aloha 1.8
1273 aloha 1.26 gtk_widget_grab_focus(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
1274 aloha 1.16 gtk_widget_show_all(Shiki_EDITOR_WINDOW);
1275 aloha 1.1 }
1276    
1277     int main(int argc, char *argv[]) {
1278     /* ������������������������������������ */
1279     gtk_set_locale();
1280     gtk_init(&argc, &argv);
1281     GC_INIT(); Scm_Init(GAUCHE_SIGNATURE);
1282 aloha 1.21 shiki_editor_window_init(argc, argv);
1283 aloha 1.1 gtk_main();
1284     Scm_Exit(0);
1285     return 0;
1286     }

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