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.51 - (hide annotations) (download) (as text)
Thu Nov 23 15:18:28 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.50: +42 -20 lines
File MIME type: text/x-csrc
add (clear-current-buffer) API

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

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