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.43 - (hide annotations) (download) (as text)
Sun Nov 19 12:44:21 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.42: +14 -43 lines
File MIME type: text/x-csrc
refactoring Really Quit ? Dialog

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

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