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.40 - (hide annotations) (download) (as text)
Sun Nov 19 10:29:42 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.39: +8 -4 lines
File MIME type: text/x-csrc
misc change (related tab title)

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

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