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.38 - (hide annotations) (download) (as text)
Sat Nov 18 19:28:55 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.37: +20 -16 lines
File MIME type: text/x-csrc
add various icon and refactoring icon location

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

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