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.50 - (hide annotations) (download) (as text)
Thu Nov 23 05:27:13 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.49: +22 -15 lines
File MIME type: text/x-csrc
fixed buf (for open_file()) and memory leak (SCM_MAKE_STR() -> SCM_MAKE_STR_COPYING() + g_free())

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

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