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.41 - (hide annotations) (download) (as text)
Sun Nov 19 11:25:04 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.40: +3 -2 lines
File MIME type: text/x-csrc
add gtk_text_view_set_wrap_mode(..., GTK_WRAP_WORD);

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

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