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

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