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.39 - (hide annotations) (download) (as text)
Sun Nov 19 10:18:37 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.38: +37 -20 lines
File MIME type: text/x-csrc
modified modeline (to more xyzzy like)

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.39 * $Id: shiki.c,v 1.38 2006/11/18 19:28:55 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     gchar *tabpage_label; /* ��������� (���������������) ������ */
50     GtkTextView *text_view; /* ��������������� */
51     GtkTextBuffer *text_buffer; /* ��������������������������������� */
52     gchar *filename; /* ������������������������������ */
53 aloha 1.32 GList *undoInfoList; /* ��������������������������������������� */
54 aloha 1.20 ScmObj env; /* ��������������������������� Scheme ������ */
55     guint delete_handler_id; /* ��������������������������������������������� ID */
56 aloha 1.16 } ShikiTabInfo;
57    
58 aloha 1.17 /* ������������������������������������������������������������������������������������������������������������������������������ */
59 aloha 1.35 static struct {
60 aloha 1.39 const gchar *default_locale;
61 aloha 1.17 GtkWidget *editor_window;
62 aloha 1.31 GtkClipboard *clipboard;
63 aloha 1.26 GtkNotebook *notebook;
64 aloha 1.17 GtkWidget *statusbar;
65     GtkWidget *modeline_label;
66     GList *tabInfoList;
67     gint current_tabpage_num;
68     ShikiTabInfo *current_tabpage_info;
69 aloha 1.16 } shiki_editor;
70    
71 aloha 1.25 /* ��������������������������������������������� */
72 aloha 1.39 #define Shiki_EDITOR_DEFAULT_LOCALE shiki_editor.default_locale
73 aloha 1.32 #define Shiki_EDITOR_WINDOW shiki_editor.editor_window
74     #define Shiki_EDITOR_CLIPBOARD shiki_editor.clipboard
75     #define Shiki_EDITOR_NOTEBOOK shiki_editor.notebook
76     #define Shiki_EDITOR_STATUSBAR shiki_editor.statusbar
77     #define Shiki_EDITOR_MODELINE_LABEL shiki_editor.modeline_label
78     #define Shiki_EDITOR_TAB_INFO_LIST shiki_editor.tabInfoList
79 aloha 1.25
80     /* ��������������������������������������������������������������������������������������� */
81 aloha 1.32 #define Shiki_CURRENT_TAB_NUM shiki_editor.current_tabpage_num
82     #define Shiki_CURRENT_TAB_INFO shiki_editor.current_tabpage_info
83 aloha 1.39 #define Shiki_CURRENT_LOCALE (shiki_editor.current_tabpage_info)->locale
84 aloha 1.32 #define Shiki_CURRENT_UNDO_INFO_LIST (shiki_editor.current_tabpage_info)->undoInfoList
85     #define Shiki_CURRENT_TAB (shiki_editor.current_tabpage_info)->tabpage
86     #define Shiki_CURRENT_TAB_TITLE (shiki_editor.current_tabpage_info)->tabpage_label
87     #define Shiki_CURRENT_TEXT_VIEW (shiki_editor.current_tabpage_info)->text_view
88     #define Shiki_CURRENT_TEXT_BUFFER (shiki_editor.current_tabpage_info)->text_buffer
89     #define Shiki_CURRENT_FILENAME (shiki_editor.current_tabpage_info)->filename
90 aloha 1.34 #define Shiki_CURRENT_BUFFER_ENV (shiki_editor.current_tabpage_info)->env
91 aloha 1.10
92 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};
93    
94 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};
95 aloha 1.35
96     static GHashTable *keywords_hash = NULL;
97    
98     typedef enum {
99     R5RS_KEYWORD_COLOR = 1,
100     R5RS_FUNCTION_COLOR,
101     GAUCHE_KEYWORD_COLOR,
102     GAUCHE_FUNCTION_COLOR
103     } HIGHILIGHT_COLOR;
104    
105 aloha 1.39 GdkColor COLOR_BLACK;
106     GdkColor COLOR_GREEN;
107    
108 aloha 1.17 /* ������������������ */
109 aloha 1.25
110 aloha 1.27 /* ������������������������ : ���������������ShikiTabInfo ������������������������������������������������������������������ 2 ������������������������������������������ (������������������) */
111     static void append_tabpage(gchar *filename);
112     static void remove_tabpage();
113    
114 aloha 1.33 /* foo_bar_handler() ������������������������������������������������������ */
115     static void append_default_tabpage_handler();
116    
117 aloha 1.25 /* ������������������ */
118 aloha 1.27 static void open_file(gchar *filename);
119     static void open_file_handler();
120     static void save_file();
121     static void save_file_as();
122 aloha 1.25 static gchar *get_filename_from_dialog(const gchar *msg);
123    
124     /* ������������������������������ */
125     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer);
126     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer);
127 aloha 1.17 static void clear_current_buffer();
128 aloha 1.33 static void undo();
129 aloha 1.25
130 aloha 1.32 static void insert_text_handler(GtkTextBuffer *buffer, GtkTextIter *p, gchar *str, gint len);
131     static void delete_range_handler(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end);
132    
133 aloha 1.25 /* ������������������ */
134 aloha 1.17 static void update_modeline_label();
135     static void text_buffer_cursor_moved_handler();
136 aloha 1.25
137     /* ������ */
138 aloha 1.17 static void really_quit_dialog_yes(GtkWidget *widget, gboolean *flag);
139     static void really_quit_dialog_no(GtkWidget *widget, gint *flag);
140     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.23 tabinfo->tabpage_label = g_path_get_basename(filename);
430 aloha 1.34 tabinfo->env = Scm_MakeModule(NULL, FALSE);
431 aloha 1.35
432 aloha 1.34 g_return_if_fail(tabinfo->env != SCM_FALSE);
433 aloha 1.24
434     /* ������������������������������ (������������������������) ��������� */
435     tabinfo->tabpage = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
436     gtk_scrolled_window_set_policy (tabinfo->tabpage, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
437    
438     /* ��������������������������������������������������������������������������������������� */
439     tabinfo->text_view = GTK_TEXT_VIEW(gtk_text_view_new());
440     tabinfo->text_buffer = gtk_text_view_get_buffer(tabinfo->text_view);
441 aloha 1.33
442 aloha 1.24 gtk_container_add(GTK_CONTAINER(tabinfo->tabpage), GTK_WIDGET(tabinfo->text_view));
443     gtk_widget_set_size_request(GTK_WIDGET(tabinfo->text_view), 500, 500);
444     g_signal_connect(tabinfo->text_buffer, "mark_set", G_CALLBACK(text_buffer_cursor_moved_handler), tabinfo->text_view);
445 aloha 1.32 g_signal_connect(tabinfo->text_buffer, "insert-text", G_CALLBACK(insert_text_handler), NULL);
446     g_signal_connect(tabinfo->text_buffer, "delete-range", G_CALLBACK(delete_range_handler), NULL);
447    
448 aloha 1.24 /* ������������������������������������������������������������������������������������������������������ */
449     tabinfo->delete_handler_id = g_signal_connect(Shiki_EDITOR_WINDOW, "delete_event", G_CALLBACK(delete_event_handler), tabinfo->text_buffer);
450 aloha 1.33
451 aloha 1.24 /* ������������������������ */
452 aloha 1.36
453 aloha 1.24 /* ������������������������������������������������ */
454 aloha 1.39 gtk_text_buffer_create_tag(tabinfo->text_buffer, "parent_emphasis_background", "background", "green", NULL);
455 aloha 1.35
456     /* ��������������������������������������� */
457     gtk_text_buffer_create_tag(tabinfo->text_buffer, "keyword_highlighting", "foreground", "blue", NULL);
458     /* ������ */
459     gtk_text_buffer_create_tag(tabinfo->text_buffer, "function_highlighting", "foreground", "red", NULL);
460     /* ������������ */
461 aloha 1.36 gtk_text_buffer_create_tag (tabinfo->text_buffer, "comment_highlighting", "foreground", "purple", NULL);
462     /* ��������� */
463     gtk_text_buffer_create_tag (tabinfo->text_buffer, "string_highlighting", "foreground", "orange", NULL);
464 aloha 1.24 /* ������������������������������������������ */
465 aloha 1.27 gtk_notebook_append_page(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(tabinfo->tabpage), gtk_label_new(tabinfo->tabpage_label));
466 aloha 1.24 /* ������������������������������������������������������������������ */
467 aloha 1.23 Shiki_EDITOR_TAB_INFO_LIST = g_list_append(Shiki_EDITOR_TAB_INFO_LIST, tabinfo);
468 aloha 1.32
469 aloha 1.27 gtk_widget_show_all(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
470 aloha 1.24 /* ��������������������������������� */
471 aloha 1.27 gtk_notebook_set_current_page(Shiki_EDITOR_NOTEBOOK, g_list_length(Shiki_EDITOR_TAB_INFO_LIST) - 1);
472 aloha 1.23 }
473    
474 aloha 1.33 static void append_default_tabpage_handler() {
475     append_tabpage(g_strdup("*scratch*"));
476     }
477    
478 aloha 1.23 /* ������������������������������������������ (������������) ��������� */
479 aloha 1.27 static void remove_tabpage() {
480 aloha 1.23 /* ��������� 1 ��������������������������������������������������� */
481     if(g_list_length(Shiki_EDITOR_TAB_INFO_LIST) == 1)
482     return;
483     if(!not_yet_save_changes_really_quit(Shiki_CURRENT_TEXT_BUFFER)) {
484     /* ��������������������������������������������������������������������������������������������� */
485     g_signal_handler_disconnect(Shiki_EDITOR_WINDOW, (Shiki_CURRENT_TAB_INFO)->delete_handler_id);
486     /* ������������������������ */
487     gtk_widget_destroy(GTK_WIDGET(Shiki_CURRENT_TEXT_VIEW));
488     /* ������������������������������������������ */
489     g_free(Shiki_CURRENT_TAB_TITLE);
490     g_free(Shiki_CURRENT_FILENAME);
491     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));
492     g_free(Shiki_CURRENT_TAB_INFO);
493    
494     /* ������������������������������������ */
495     Shiki_CURRENT_TAB_INFO = g_list_nth_data(Shiki_EDITOR_TAB_INFO_LIST, Shiki_CURRENT_TAB_NUM);
496 aloha 1.27 gtk_notebook_remove_page(Shiki_EDITOR_NOTEBOOK, Shiki_CURRENT_TAB_NUM);
497 aloha 1.23 /* ��������������������������������������� */
498 aloha 1.27 gtk_widget_queue_draw(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
499 aloha 1.23 }
500     }
501    
502 aloha 1.15 /* ������������������������������ */
503     static void clear_current_buffer() {
504     GtkTextIter start, end;
505 aloha 1.16 gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &start);
506     gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &end);
507     gtk_text_buffer_delete(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
508 aloha 1.15 }
509    
510 aloha 1.14 /* ������������������������������������ */
511     static void load_buffer_by_gauche() {
512     GtkTextIter p;
513 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
514     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
515     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(get_all_buffer_contents(Shiki_CURRENT_TEXT_BUFFER)), -1);
516 aloha 1.14 }
517    
518     /* ������������������������ */
519 aloha 1.27 static void load_scheme_file_by_gauche() {
520 aloha 1.14 gchar *contents, *text;
521     gsize br, bw, len;
522     GError *err = NULL;
523     gchar *filename = get_filename_from_dialog("File Selection");
524     GtkTextIter p;
525    
526     if(!filename) return;
527 aloha 1.33
528 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
529     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
530 aloha 1.14
531     if(g_file_get_contents(filename, &contents, &len, NULL)) {
532     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
533 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(text), -1);
534 aloha 1.14 else
535 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(contents), -1);
536 aloha 1.14 }
537     g_free(text); g_free(contents); g_free(filename);
538     }
539    
540 aloha 1.13 /* gauche ������������������������������������ */
541     static gchar *load_cstring_by_gauche(gchar *s) {
542     gchar *msg;
543    
544     ScmObj result, error;
545     /* ��������������������������������� */
546     ScmObj is = Scm_MakeInputStringPort(SCM_STRING(SCM_MAKE_STR(s)), TRUE);
547     /* ������������������������������ */
548     ScmObj os = Scm_MakeOutputStringPort(TRUE);
549    
550 aloha 1.34 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*input*")), is);
551     Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
552 aloha 1.13 /* Scheme ��������������������������������������������������������������������������������� S ��������������������������������������������������������������������������� *error* ������������������ */
553 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));
554 aloha 1.13
555 aloha 1.34 error = Scm_GlobalVariableRef(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
556 aloha 1.13
557     /* ��������������������������������������������������������� */
558     if (!SCM_FALSEP(error))
559     Scm_Write(error, os, SCM_WRITE_DISPLAY);
560     else
561     Scm_Write(result, os, SCM_WRITE_DISPLAY);
562    
563     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
564     /* ������������������ */
565     Scm_ClosePort(SCM_PORT(is));
566     Scm_ClosePort(SCM_PORT(os));
567    
568     return msg;
569     }
570    
571 aloha 1.12 static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog) {
572     gchar *font_name = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (font_dialog));
573     if(font_name) {
574     GtkRcStyle *style = gtk_rc_style_new ();
575     pango_font_description_free(style->font_desc);
576     style->font_desc = pango_font_description_from_string(font_name);
577 aloha 1.16 gtk_widget_modify_style (GTK_WIDGET(Shiki_CURRENT_TEXT_VIEW), style);
578 aloha 1.12 g_free (font_name);
579     }
580     }
581    
582 aloha 1.14 /* ������������������������������������������������������ */
583 aloha 1.12 static void select_font(){
584     GtkWidget *font_dialog = gtk_font_selection_dialog_new("Font Selection Dialog");
585     g_signal_connect (GTK_FONT_SELECTION_DIALOG (font_dialog)->ok_button, "clicked", G_CALLBACK(font_selection_ok), font_dialog);
586     gtk_dialog_run(GTK_DIALOG(font_dialog));
587     gtk_widget_destroy(font_dialog);
588     }
589    
590 aloha 1.11 /* ������������������������������������������ */
591     static void about_this_application() {
592     GtkAboutDialog *about = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
593     const gchar *authors[] = {
594 aloha 1.23 "������������ (���������) <alohakun@gmail.com>\n",
595     "Contribute : tkng ������",
596     "(http://d.hatena.ne.jp/tkng/20061113)", NULL
597 aloha 1.11 };
598     gtk_about_dialog_set_authors(about, authors);
599     gtk_about_dialog_set_copyright(about, "Copyright(C)2006 WAKATSUKI Toshihiro");
600     gtk_about_dialog_set_name(about, "��� (SHIKI)");
601     gtk_about_dialog_set_website_label(about, "���������30������������������������������������������������������������Blog");
602     gtk_about_dialog_set_website(about, "http://alohakun.blog7.fc2.com/blog-category-29.html");
603     gtk_dialog_run(GTK_DIALOG(about));
604     gtk_widget_destroy(GTK_WIDGET(about));
605     }
606    
607 aloha 1.37 /* ��������� */
608     static void dummy_handler() {
609     GtkAboutDialog *about = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
610     gtk_about_dialog_set_name(about, "Sorry... This Button is Dummy.");
611     gtk_dialog_run(GTK_DIALOG(about));
612     gtk_widget_destroy(GTK_WIDGET(about));
613     }
614    
615 aloha 1.39 /* ��������������������������������������������������������������� */
616     static void update_modeline_label() {
617     static gchar label[1024];
618 aloha 1.10 GtkTextIter p;
619 aloha 1.39 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
620 aloha 1.10
621 aloha 1.39 g_snprintf(label, 1024, "--%s- %-10s (Gauche Interaction) [%s] L%d:%d ",
622 aloha 1.16 gtk_text_buffer_get_modified(Shiki_CURRENT_TEXT_BUFFER) ? "**" : "--",
623 aloha 1.39 Shiki_CURRENT_TAB_TITLE,
624     Shiki_CURRENT_LOCALE,
625     gtk_text_iter_get_line(&p) + 1,
626     gtk_text_iter_get_line_offset (&p) + 1);
627     gtk_label_set_text(GTK_LABEL(Shiki_EDITOR_MODELINE_LABEL), label);
628 aloha 1.10 }
629    
630     static void text_buffer_cursor_moved_handler(){
631     update_modeline_label();
632     }
633 aloha 1.1
634     /* ��������������������������������������������������������������� */
635     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer) {
636     GtkTextIter start, end;
637     gtk_text_buffer_get_start_iter(buffer, &start);
638     gtk_text_buffer_get_end_iter(buffer, &end);
639     return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
640     }
641    
642     /* buffer ������������������������ filename ��������� */
643     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer) {
644     gchar *contents, *text;
645     gsize br, bw;
646     GError *err = NULL;
647    
648     if(!filename) return FALSE;
649     contents = get_all_buffer_contents(buffer);
650     text = g_locale_from_utf8(contents, -1, &br, &bw, &err);
651     /* ��������������������������������� */
652     g_file_set_contents(filename, text, -1, NULL);
653     gtk_text_buffer_set_modified(buffer, FALSE);
654 aloha 1.10 update_modeline_label();
655 aloha 1.1 g_free(contents); g_free(text);
656     return TRUE;
657     }
658    
659     /* ������������������������������������������������������msg ������������������������������������ */
660     static gchar *get_filename_from_dialog(const gchar *msg) {
661    
662     GtkWidget *dialog = gtk_file_selection_new(msg);
663     int resp = gtk_dialog_run(GTK_DIALOG(dialog));
664     gchar *filename = NULL;
665    
666     /* gtk_file_selection_get_filename ������������������������������������������������������������������������������������������������������������������������������ */
667     if(resp == GTK_RESPONSE_OK)
668     filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog)));
669    
670     gtk_widget_destroy(dialog);
671     return filename;
672     }
673    
674     /* ��������������������������������������������������������������������� */
675 aloha 1.27 static void save_file() {
676 aloha 1.1
677 aloha 1.22 /* ��������������������������������������� */
678     if(g_ascii_strcasecmp("*help*", Shiki_CURRENT_TAB_TITLE) == 0) return;
679 aloha 1.33
680 aloha 1.1 /* ������������������������������������ */
681 aloha 1.16 if(!gtk_text_buffer_get_modified(Shiki_CURRENT_TEXT_BUFFER)) return;
682 aloha 1.1
683     /* ������������������������������������������������������������������������������������������������������ */
684 aloha 1.16 if(g_ascii_strcasecmp("*scratch*", Shiki_CURRENT_TAB_TITLE) == 0) {
685 aloha 1.7 gchar *filename = get_filename_from_dialog("Save File As ...");
686     if(!filename) return;
687 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
688 aloha 1.27 gtk_notebook_set_tab_label_text(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
689 aloha 1.16 gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), filename);
690 aloha 1.1 g_free(filename);
691     } else
692 aloha 1.16 save_text_buffer(Shiki_CURRENT_TAB_TITLE, Shiki_CURRENT_TEXT_BUFFER);
693 aloha 1.1 }
694    
695     /* ��������������������������������������������������������������������������� */
696 aloha 1.27 static void save_file_as() {
697 aloha 1.1 gchar *filename = get_filename_from_dialog("Save File As ...");
698    
699 aloha 1.7 if(!filename) return;
700 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
701 aloha 1.1
702 aloha 1.27 gtk_notebook_set_tab_label_text(Shiki_EDITOR_NOTEBOOK, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
703 aloha 1.16 gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
704 aloha 1.1
705     g_free(filename);
706     }
707    
708     /* YES ������������NO ������������������������������������ callback */
709 aloha 1.17 static void really_quit_dialog_yes(GtkWidget *widget, gboolean *flag){*flag = FALSE;}
710     static void really_quit_dialog_no(GtkWidget *widget, gint *flag){*flag = TRUE;}
711 aloha 1.1
712     /* ��������������������������������������������� ? */
713 aloha 1.17 static gboolean not_yet_save_changes_really_quit(GtkTextBuffer *buffer) {
714 aloha 1.1 GtkWidget *yes_button, *no_button;
715     static GtkWidget *dialog_window = NULL;
716    
717     /* ��������������������������������������� */
718     if(!gtk_text_buffer_get_modified(buffer)) return FALSE;
719    
720     if(dialog_window == NULL) {
721     gboolean flag = TRUE;
722     dialog_window = gtk_dialog_new ();
723    
724     /* ��������������������������������������������� ? ��������������������������� */
725     g_signal_connect(G_OBJECT(dialog_window), "delete_event", G_CALLBACK(gtk_false), NULL);
726     g_signal_connect(G_OBJECT(dialog_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
727 aloha 1.5 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->vbox),
728     gtk_label_new("������������������������������������������\n��������������������������������������� ?"), TRUE, TRUE, 0);
729 aloha 1.1 gtk_window_set_title(GTK_WINDOW (dialog_window), "Really Quit ?");
730     /* YES ������������ */
731 aloha 1.8 yes_button = gtk_button_new_with_mnemonic("������ (_Y)");
732 aloha 1.1 g_signal_connect(GTK_OBJECT(yes_button), "clicked", G_CALLBACK(really_quit_dialog_yes), &flag);
733     g_signal_connect_swapped(GTK_OBJECT(yes_button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(dialog_window));
734     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), yes_button, TRUE, TRUE, 0);
735    
736     /* NO ������������ */
737 aloha 1.8 no_button = gtk_button_new_with_mnemonic("��������� (_N)");
738 aloha 1.1 g_signal_connect(GTK_OBJECT(no_button), "clicked", G_CALLBACK(really_quit_dialog_no), &flag);
739     g_signal_connect_swapped(GTK_OBJECT(no_button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(dialog_window));
740     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), no_button, TRUE, TRUE, 0);
741    
742     gtk_window_set_modal(GTK_WINDOW(dialog_window), TRUE);
743 aloha 1.16 gtk_window_set_transient_for(GTK_WINDOW(dialog_window), GTK_WINDOW (Shiki_EDITOR_WINDOW));
744 aloha 1.1
745     gtk_widget_show_all(dialog_window);
746     gtk_main ();
747     dialog_window = NULL;
748    
749     /* "delete_event" ��������������� FALSE ���������"destory" ������������������window ������������������ */
750     return flag;
751     }
752     return TRUE;
753     }
754    
755     /* ������������������������������������������������������������������������������������������ */
756 aloha 1.27 static gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, GtkTextBuffer *buffer){
757     return not_yet_save_changes_really_quit(buffer);
758 aloha 1.1 }
759    
760     /* ��������������������� */
761 aloha 1.27 static void open_file(gchar *filename) {
762 aloha 1.39 gchar *contents, *text = NULL;
763 aloha 1.1 gsize br, bw, len;
764     GError *err = NULL;
765 aloha 1.33
766 aloha 1.27 g_return_if_fail(filename != NULL);
767 aloha 1.33
768 aloha 1.1 if(g_file_get_contents(filename, &contents, &len, NULL)) {
769     GtkTextIter p;
770 aloha 1.3
771 aloha 1.1 /* ������������������������������ */
772 aloha 1.27 append_tabpage(g_strdup(filename));
773 aloha 1.1
774     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
775 aloha 1.17 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER, contents, len);
776 aloha 1.39 else {
777 aloha 1.17 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER, text, len);
778 aloha 1.39 Shiki_CURRENT_LOCALE = Shiki_EDITOR_DEFAULT_LOCALE;
779     }
780 aloha 1.1
781     /* ������������������������ */
782 aloha 1.17 gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
783 aloha 1.1 /* ������������������������������ */
784 aloha 1.17 gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
785     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
786 aloha 1.10 update_modeline_label();
787 aloha 1.16 gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
788 aloha 1.27 gtk_widget_show_all(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
789 aloha 1.1 g_free(contents); g_free(text); g_free(filename);
790 aloha 1.35
791     /* ��������������������������������� */
792     scheme_keyword_highlighting_current_buffer();
793 aloha 1.1 } else
794     g_printerr("Get file contents error !\n");
795     }
796    
797 aloha 1.21 /* ��������������������������������������������������� */
798 aloha 1.27 static void open_file_handler() {
799 aloha 1.21 gchar *filename = get_filename_from_dialog("File Selection");
800    
801     if(!filename) return;
802 aloha 1.27 open_file(filename);
803 aloha 1.1 }
804    
805     /* gauche ��������������������������������� */
806     static gchar *eval_cstring_by_gauche(gchar *s) {
807     gchar *msg;
808    
809     ScmObj result, error;
810     /* ������������������������������ */
811     ScmObj os = Scm_MakeOutputStringPort(TRUE);
812    
813     /* Scheme ��������������������������������������� */
814     /* http://alohakun.blog7.fc2.com/blog-entry-517.html */
815 aloha 1.34 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*input*")), SCM_MAKE_STR(s));
816     Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
817 aloha 1.1
818 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));
819 aloha 1.1
820 aloha 1.34 error = Scm_GlobalVariableRef(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
821 aloha 1.1
822     /* ��������������������������������������������������������� */
823     if (!SCM_FALSEP(error))
824     Scm_Write(error, os, SCM_WRITE_DISPLAY);
825     else
826     Scm_Write(result, os, SCM_WRITE_DISPLAY);
827    
828     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
829     /* ������������������ */
830     Scm_ClosePort(SCM_PORT(os));
831    
832     return msg;
833     }
834    
835 aloha 1.13 /* ������������������������������������������������������������������ S ��������������� (������������) */
836 aloha 1.27 static void load_region_by_gauche() {
837 aloha 1.1
838     GtkTextIter start, end, p;
839     gchar *code;
840 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
841     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
842 aloha 1.1
843     /* ������������������������������������������������������������ */
844 aloha 1.16 if(gtk_text_buffer_get_selection_bounds(Shiki_CURRENT_TEXT_BUFFER, &start, &end)) {
845     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
846     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(code), -1);
847 aloha 1.1 g_free(code);
848     }
849     }
850    
851     // GtkTextCharPredicate
852     static gboolean is_kakko_or_kokka(gunichar ch, gpointer p) {
853     return ch == '(' || ch == ')';
854     }
855 aloha 1.29 static gboolean is_kakko(gunichar ch, gpointer p) {return ch == '(';}
856 aloha 1.1 static gboolean is_kokka(gunichar ch, gpointer p) {return ch == ')';}
857    
858 aloha 1.30 /* ��������������������� '(' ��������������� ')' ������������������ (S ���) ��������������� */
859     static gboolean search_sexp(GtkTextIter *start, GtkTextIter *end) {
860 aloha 1.33
861 aloha 1.30 /* ������������������������������ */
862     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, start, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
863    
864     if(gtk_text_iter_get_char(start) != '(')
865     gtk_text_iter_forward_find_char(start, is_kakko, NULL, NULL);
866    
867     *end = *start;
868    
869     /* ��������������������������������� S ������������������ */
870     if(!search_sexp_kokka(end)) return FALSE;
871     gtk_text_iter_forward_char(end);
872     return TRUE;
873     }
874    
875     static gboolean search_sexp_kokka(GtkTextIter *end) {
876 aloha 1.29 gint nest_level = 0;
877 aloha 1.33
878 aloha 1.30 /* ������������ ')' ��������� */
879 aloha 1.29 while(1) {
880 aloha 1.30 if(!gtk_text_iter_forward_find_char(end, is_kakko_or_kokka, NULL, NULL))
881 aloha 1.29 return FALSE;
882    
883 aloha 1.30 if(gtk_text_iter_get_char(end) == '(')
884 aloha 1.29 nest_level++;
885     else {
886     if(!nest_level)
887     break;
888     else
889     nest_level--;
890     }
891     }
892     return TRUE;
893     }
894 aloha 1.1
895 aloha 1.30 /* ��������������������� ')' ��������������� '(' ������������������ (S ���) ��������������� */
896     static gboolean search_last_sexp(GtkTextIter *start, GtkTextIter *end) {
897    
898     /* ������������������������������ */
899     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
900    
901     gtk_text_iter_backward_char(end);
902 aloha 1.33
903 aloha 1.30 if(gtk_text_iter_get_char(end) != ')')
904     gtk_text_iter_backward_find_char(end, is_kokka, NULL, NULL);
905     *start = *end;
906     gtk_text_iter_forward_char(end);
907    
908     /* ��������������������������������� S ������������������ */
909     if(!search_last_sexp_kakko(start)) return FALSE;
910    
911     return TRUE;
912     }
913    
914 aloha 1.1 /* ')' ��������������� '(' ������������������ (S ���) ��������������� */
915 aloha 1.29 static gboolean search_last_sexp_kakko(GtkTextIter *start) {
916 aloha 1.1 gint nest_level = 0;
917 aloha 1.30 /* ��������������������������������������� ')' ��������� */
918 aloha 1.1 while(1) {
919     if(!gtk_text_iter_backward_find_char(start, is_kakko_or_kokka, NULL, NULL))
920     return FALSE;
921    
922     if(gtk_text_iter_get_char(start) == ')')
923     nest_level++;
924     else {
925     if(!nest_level)
926     break;
927     else
928     nest_level--;
929     }
930     }
931     return TRUE;
932     }
933    
934     /* ������������������������������������������������ */
935     static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer) {
936     gint nest_level = 0;
937     GtkTextIter start, end;
938     gtk_text_buffer_get_start_iter(buffer, &start);
939     if(gtk_text_iter_get_char(&start) == '(') nest_level++;
940    
941     /* ��������������������� (= end) ��������� */
942     gtk_text_buffer_get_iter_at_mark(buffer,&end, gtk_text_buffer_get_insert(buffer));
943    
944     while(1) {
945     /* end ������ '(' ��� ')' ��������������������������������������������� */
946     if(!gtk_text_iter_forward_find_char(&start, is_kakko_or_kokka, NULL, &end))
947     return nest_level;
948    
949     if(gtk_text_iter_get_char(&start) == '(')
950     nest_level++;
951     else
952     nest_level--;
953     }
954     }
955    
956     /* ��������������������������������� on/off */
957     static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook) {
958     gint tval = FALSE;
959     gint bval = FALSE;
960     if(notebook->show_tabs == FALSE)
961     tval = TRUE;
962     if(notebook->show_border == FALSE)
963     bval = TRUE;
964    
965     gtk_notebook_set_show_tabs(notebook, tval);
966     gtk_notebook_set_show_border(notebook, bval);
967     }
968    
969     /* ������������������������ */
970 aloha 1.17 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook ) {
971 aloha 1.1 gtk_notebook_set_tab_pos(notebook, (notebook->tab_pos + 1) % 4);
972     }
973    
974     /* ������������������������������������������ */
975    
976 aloha 1.3 /* ��������������������� ^npfb */
977 aloha 1.7 static void forward_current_buffer() {
978 aloha 1.3 GtkTextIter p;
979 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
980 aloha 1.3 gtk_text_iter_forward_char(&p);
981 aloha 1.16 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
982 aloha 1.3 }
983 aloha 1.7 static void backward_current_buffer() {
984 aloha 1.3 GtkTextIter p;
985 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
986 aloha 1.3 gtk_text_iter_backward_char(&p);
987 aloha 1.16 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
988 aloha 1.3 }
989 aloha 1.7 static void line_forward_current_buffer() {
990 aloha 1.3 GtkTextIter p;
991 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
992     gtk_text_view_forward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
993     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
994 aloha 1.7 }
995     static void line_backward_current_buffer() {
996 aloha 1.3 GtkTextIter p;
997 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
998     gtk_text_view_backward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
999     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
1000 aloha 1.3 }
1001    
1002 aloha 1.1 /* ��������������������� */
1003 aloha 1.8 static gboolean signal_key_release_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
1004     static gint metakey_pressed = 0;
1005 aloha 1.6 static gint controlx_pressed = 0;
1006 aloha 1.1
1007     if(event->keyval == GDK_parenright && event->state & GDK_SHIFT_MASK) {
1008     GtkTextIter start, end;
1009    
1010     /* ������������������������������ */
1011 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
1012 aloha 1.1
1013     start = end;
1014     gtk_text_iter_backward_char(&start);
1015    
1016     /* ��������������������������������� S ������������������ */
1017 aloha 1.29 if(!search_last_sexp_kakko(&start)) return FALSE;
1018 aloha 1.1
1019 aloha 1.16 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
1020 aloha 1.1 }
1021    
1022     /* ������������������������������������������������������������������������������������������������ (���������������) ������������������ */
1023     if(event->keyval == GDK_Return) {
1024 aloha 1.16 gint indentWidth = get_parent_nest_level_at_cursor(Shiki_CURRENT_TEXT_BUFFER) * editor_indent_width;
1025 aloha 1.1 gchar *indent = g_strnfill(indentWidth, ' ');
1026 aloha 1.16 gtk_text_buffer_insert_at_cursor(Shiki_CURRENT_TEXT_BUFFER, indent, -1);
1027 aloha 1.1 g_free(indent);
1028     }
1029    
1030 aloha 1.6 /* C-x */
1031     if(event->keyval == GDK_x && event->state & GDK_CONTROL_MASK) {
1032     controlx_pressed++;
1033 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-x -");
1034 aloha 1.6 } else if(event->state & GDK_CONTROL_MASK) {
1035 aloha 1.8
1036 aloha 1.6 if(controlx_pressed > 0) {
1037     switch(event->keyval) {
1038     case GDK_c :/* C-x C-c : ������ */
1039 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-c");
1040 aloha 1.6 {/* "delete-event" ��������������������������������������� �� ������������������������������������ */
1041     GdkEvent ev;
1042    
1043     ev.any.type = GDK_DELETE;
1044 aloha 1.16 ev.any.window = Shiki_EDITOR_WINDOW->window;
1045 aloha 1.6 ev.any.send_event = FALSE;
1046     gdk_event_put (&ev);
1047     }
1048     break;
1049    
1050     case GDK_f : /* C-x C-f : ������������������ */
1051 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-f");
1052 aloha 1.27 open_file_handler();
1053 aloha 1.6 break;
1054    
1055     case GDK_s : /* C-x C-s : ������������������ */
1056 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-s");
1057 aloha 1.27 save_file();
1058 aloha 1.6 break;
1059    
1060     case GDK_w : /* C-x C-w : ������������������������ */
1061 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-w");
1062 aloha 1.27 save_file_as();
1063 aloha 1.6 break;
1064     }
1065     controlx_pressed = 0;
1066     }
1067 aloha 1.8
1068     switch(event->keyval) {
1069     case GDK_g :/* C-g : ��������������� */
1070     metakey_pressed = 0;
1071     controlx_pressed = 0;
1072    
1073 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "Quit");
1074 aloha 1.8 break;
1075     }
1076    
1077 aloha 1.6 }
1078 aloha 1.1 return FALSE;
1079     }
1080 aloha 1.27 static void open_online_help() {
1081 aloha 1.22 GtkTextIter p;
1082 aloha 1.27 append_tabpage(g_strdup("*help*"));
1083 aloha 1.22 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER,
1084 aloha 1.37 "������������������������������������������\n"
1085 aloha 1.30 "$ ./shiki [file1 file2 ....]\n\n"
1086     "[���������������������������] ��������������������� (C-x C-f)\n"
1087     "[������������������������������������������] ��������������������� (C-x C-s)\n"
1088     "[���������������������������������������������] ��������������������������� (C-x C-w)\n"
1089 aloha 1.37 "[���������������������] ��������������� gauche ������������\n"
1090 aloha 1.30 "[��������������� (���������) ���������������] ��������� on/off\n"
1091     "[������ (���������) ���������������] ������������������������\n"
1092 aloha 1.37 "[������������������] ��������������������������� (C-t)\n"
1093 aloha 1.33 "[���������������������������] ������������ (C-_)\n"
1094 aloha 1.30 "[���������������������] ������������������������\n"
1095 aloha 1.37 "[�� ������������] ������������������������ (C-k)\n"
1096 aloha 1.30 "[A ������������] ���������������������\n"
1097     "[���������������������������] Scheme ������������������������\n"
1098     "[���������������������������������] ���������������������������������������\n"
1099     "[��������� (?) ������������] ���������������������������������������\n"
1100 aloha 1.33 "[info ������������] ���������������������������������������������������\n"
1101     "\n"
1102 aloha 1.30 "C-f : ��� ��������� (forward)\n"
1103     "C-b : ��� ��������� (backward)\n"
1104     "C-n : ��� ��������� (next line)\n"
1105 aloha 1.33 "C-p : ��� ��������� (previous line)\n"
1106     "\n"
1107     "C-h : ���������������������\n"
1108 aloha 1.31 "C-w : ���������\n"
1109 aloha 1.33 "C-y : ��������� (������������)\n"
1110     "\n"
1111 aloha 1.30 "C-e : ��������������������� S ������������ (eval-expression)\n"
1112     "C-j : ��������������������� S ������������ (eval-last-sexp)\n"
1113 aloha 1.33 "(emacs/xyzzy ��� *scratch* ���������������������)\n"
1114     "\n"
1115 aloha 1.31 "C-M-@ : ��������������������� S ������������ (mark-sexp)\n"
1116     "C-M-SPC : ��������������������� S ������������ (mark-last-sexp)\n"
1117 aloha 1.33 "C-x C-c : ��������������������������� �� ���������������������������������\n"
1118     "\n"
1119 aloha 1.37 "���������������������������������������������������������Really Quit ?���������������������������������\n", -1);
1120 aloha 1.30 gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
1121     /* ������������������������������ */
1122     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
1123     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
1124 aloha 1.22 }
1125    
1126 aloha 1.1 /* ��������������������������������������� */
1127 aloha 1.21 static void shiki_editor_window_init(int argc, char **argv) {
1128 aloha 1.39 GtkWidget *vbox, *toolbar, *modeline_bg = gtk_event_box_new();
1129 aloha 1.1 GtkToolItem *icon;
1130     GtkIconSize iconsize;
1131 aloha 1.2 GtkTooltips *toolbar_tips = gtk_tooltips_new();
1132 aloha 1.1 /* ��������������������������������������������������������������������������������� */
1133     GtkToolItem *oicon, *sicon, *saicon, *eicon;
1134    
1135 aloha 1.36 gint contextid, i;
1136    
1137     /* ������������������������������������������������������������������������������ */
1138     keywords_hash = g_hash_table_new(g_str_hash, g_str_equal);
1139     i = 0;
1140     while(R5RS_keywords[i] != NULL)
1141     g_hash_table_insert(keywords_hash, R5RS_keywords[i++], GINT_TO_POINTER(R5RS_KEYWORD_COLOR));
1142     i = 0;
1143     while(R5RS_functions[i] != NULL)
1144     g_hash_table_insert(keywords_hash, R5RS_functions[i++], GINT_TO_POINTER(R5RS_FUNCTION_COLOR));
1145 aloha 1.8
1146 aloha 1.1 /* ������������ */
1147 aloha 1.16 Shiki_EDITOR_WINDOW = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1148     g_signal_connect(G_OBJECT(Shiki_EDITOR_WINDOW), "destroy", G_CALLBACK(gtk_main_quit), NULL);
1149 aloha 1.1
1150 aloha 1.31 /* ������������������������������������������������������������ */
1151     Shiki_EDITOR_CLIPBOARD = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
1152    
1153 aloha 1.1 /* ������������������������������������ */
1154     vbox = gtk_vbox_new(FALSE, 0);
1155     /* ��������������������� */
1156     toolbar = gtk_toolbar_new();
1157     gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
1158    
1159 aloha 1.26 Shiki_EDITOR_NOTEBOOK = GTK_NOTEBOOK(gtk_notebook_new());
1160     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "switch-page", GTK_SIGNAL_FUNC(switch_tabpage_handler), NULL);
1161 aloha 1.1
1162     /* ������������������������������������������������ */
1163     gtk_toolbar_set_style(GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
1164     iconsize = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar));
1165    
1166     /* ������������������ */
1167    
1168     /* ������������������ */
1169     oicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-open", iconsize), "");
1170     /* ������������������������������������������������������������������������������������ */
1171 aloha 1.27 g_signal_connect(G_OBJECT(oicon), "clicked", G_CALLBACK(open_file_handler), NULL);
1172 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(oicon));
1173 aloha 1.2 gtk_tool_item_set_tooltip(oicon, toolbar_tips, "���������������������������",
1174     "���������������������������������������������������������������������������������������");
1175 aloha 1.1
1176     /* ������������������ */
1177     sicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-save", iconsize), "");
1178     /* ������������������������������������������������������������������������������������ */
1179 aloha 1.27 g_signal_connect(G_OBJECT(sicon), "clicked", G_CALLBACK(save_file), NULL);
1180 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(sicon));
1181 aloha 1.2 gtk_tool_item_set_tooltip(sicon, toolbar_tips, "������������������������������",
1182     "������������������������������������������������������������������������������������������������������������������������������������");
1183 aloha 1.1
1184     /* ��������������������������� */
1185     saicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-save-as", iconsize), "");
1186     /* ������������������������������������������������������������������������������������������������������������������ */
1187 aloha 1.27 g_signal_connect(G_OBJECT(saicon), "clicked", G_CALLBACK(save_file_as), NULL);
1188 aloha 1.2 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(saicon));
1189     gtk_tool_item_set_tooltip(saicon, toolbar_tips, "������������������������������������",
1190     "");
1191 aloha 1.1
1192     /* ������������������ */
1193     eicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-execute", iconsize), "");
1194 aloha 1.14 /* ������������������������������������������ libgauche ������������������ */
1195 aloha 1.27 g_signal_connect(G_OBJECT(eicon), "clicked", G_CALLBACK(load_region_by_gauche), NULL);
1196 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(eicon));
1197 aloha 1.14 gtk_tool_item_set_tooltip(eicon, toolbar_tips, "��������������� S ������������������������ (load-region-lisp)",
1198 aloha 1.2 "Scheme (gauche) ������������������ S ������������������������");
1199 aloha 1.1
1200 aloha 1.16 gtk_container_add(GTK_CONTAINER(Shiki_EDITOR_WINDOW), vbox);
1201 aloha 1.26 gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
1202 aloha 1.1
1203 aloha 1.37 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-new", iconsize), "");
1204 aloha 1.33 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(append_default_tabpage_handler), NULL);
1205 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1206 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������", "");
1207 aloha 1.1
1208 aloha 1.33 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-undo", iconsize), "");
1209     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(undo), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1210     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1211     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Undo","");
1212    
1213 aloha 1.37 /* XXX : TODO */
1214 aloha 1.38 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-redo", iconsize), "");
1215     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(dummy_handler), NULL);
1216     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1217     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Redo", "");
1218 aloha 1.37
1219     icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-find", 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, "������", "");
1223    
1224    
1225     icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-find-and-replace", iconsize), "");
1226     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(dummy_handler), NULL);
1227     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1228     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������", "");
1229    
1230     icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-refresh", 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     /* TODO ������������ */
1236    
1237 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-delete", iconsize), "");
1238 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(clear_current_buffer), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1239 aloha 1.15 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1240     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������",
1241     "���������������������������������������������������������������������");
1242    
1243 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-close", iconsize), "");
1244 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(remove_tabpage), NULL);
1245 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1246 aloha 1.2 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������",
1247     "���������������������������������������������������������������");
1248 aloha 1.15
1249 aloha 1.18 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-connect", iconsize), "");
1250 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_scheme_file_by_gauche), NULL);
1251 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1252     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Scheme ������������������������", "");
1253    
1254 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-convert", iconsize), "");
1255 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_buffer_by_gauche), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1256 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1257     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������", "");
1258    
1259 aloha 1.37 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-spell-check", iconsize), "");
1260     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(scheme_keyword_highlighting_current_buffer), NULL);
1261     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1262     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
1263    
1264    
1265 aloha 1.22 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-dialog-question", iconsize), "");
1266 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(open_online_help), NULL);
1267 aloha 1.22 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1268     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������", "");
1269 aloha 1.38
1270     icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-bold", iconsize), "");
1271     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(select_font), NULL);
1272     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1273     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
1274     icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-apply", iconsize), "");
1275    
1276     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(tabsborder_on_off), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1277     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1278     gtk_tool_item_set_tooltip(icon, toolbar_tips, "��������� on/off", "");
1279    
1280     icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-preferences", iconsize), "");
1281     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(rotate_tab_position), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1282     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1283     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
1284 aloha 1.22
1285 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-dialog-info", iconsize), "");
1286 aloha 1.11 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(about_this_application), NULL);
1287     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1288     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
1289    
1290 aloha 1.39 /* ������������������������ */
1291     Shiki_EDITOR_MODELINE_LABEL = gtk_label_new(NULL);
1292     gtk_container_add(GTK_CONTAINER (modeline_bg), Shiki_EDITOR_MODELINE_LABEL);
1293    
1294     gdk_color_parse("black", &COLOR_BLACK);
1295     gdk_color_parse("green", &COLOR_GREEN);
1296    
1297     gtk_widget_modify_fg(Shiki_EDITOR_MODELINE_LABEL, GTK_STATE_NORMAL, &COLOR_GREEN);
1298     gtk_widget_modify_bg(modeline_bg, GTK_STATE_NORMAL, &COLOR_BLACK);
1299    
1300     gtk_box_pack_start(GTK_BOX(vbox), modeline_bg, TRUE, TRUE, 0);
1301 aloha 1.12
1302 aloha 1.8 /* C-x C-s ��������������������������������������������������������������������������������������� */
1303 aloha 1.16 Shiki_EDITOR_STATUSBAR = gtk_statusbar_new();
1304     gtk_box_pack_start(GTK_BOX(vbox), Shiki_EDITOR_STATUSBAR, TRUE, TRUE, 0);
1305     contextid = gtk_statusbar_get_context_id(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), "");
1306 aloha 1.8
1307     /* ������������������������������������������������ */
1308 aloha 1.26 g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-press-event", G_CALLBACK (signal_key_press_handler), GINT_TO_POINTER(contextid));
1309     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-release-event", G_CALLBACK (signal_key_release_handler), GINT_TO_POINTER(contextid));
1310 aloha 1.12
1311 aloha 1.21 /* ��������������������������������������������� */
1312     if(argc >= 2) {
1313     int i;
1314     for(i = 1; i < argc; i++)
1315 aloha 1.27 open_file(g_strdup(argv[i]));
1316 aloha 1.21 } else /* ������������������������������������������������������������������ */
1317 aloha 1.26 open_online_help(Shiki_EDITOR_NOTEBOOK);
1318 aloha 1.8
1319 aloha 1.26 gtk_widget_grab_focus(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
1320 aloha 1.16 gtk_widget_show_all(Shiki_EDITOR_WINDOW);
1321 aloha 1.1 }
1322    
1323     int main(int argc, char *argv[]) {
1324     /* ������������������������������������ */
1325 aloha 1.39 Shiki_EDITOR_DEFAULT_LOCALE = g_locale_to_utf8(gtk_set_locale(), -1, NULL, NULL, NULL);
1326 aloha 1.1 gtk_init(&argc, &argv);
1327     GC_INIT(); Scm_Init(GAUCHE_SIGNATURE);
1328 aloha 1.21 shiki_editor_window_init(argc, argv);
1329 aloha 1.1 gtk_main();
1330     Scm_Exit(0);
1331     return 0;
1332     }

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