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.45 - (hide annotations) (download) (as text)
Mon Nov 20 05:32:43 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.44: +21 -21 lines
File MIME type: text/x-csrc
refactoring (use GTK_STOCK_* predefined macros for gtk_image_new_from_stock())

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

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