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.49 - (hide annotations) (download) (as text)
Wed Nov 22 05:23:29 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.48: +36 -36 lines
File MIME type: text/x-csrc
use gauche.charconv for ces guess when open file (but, at least currently, ... maybe wrong)

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.49 * $Id: shiki.c,v 1.48 2006/11/21 01:28:00 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     ScmObj is = Scm_MakeInputStringPort(SCM_STRING(SCM_MAKE_STR(s)), TRUE);
653     /* ������������������������������ */
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     ScmObj s, ces;
847    
848     /* ������������������������������ */
849     append_tabpage(g_strdup(filename));
850 aloha 1.33
851 aloha 1.49 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*filename*")), SCM_MAKE_STR(utf8filename));
852     Scm_Load("gauche-init.scm", 0);
853     Scm_EvalCString("(use gauche.interactive)", Shiki_CURRENT_BUFFER_ENV);
854     Scm_EvalCString("(use gauche.charconv)", Shiki_CURRENT_BUFFER_ENV);
855     Scm_EvalCString("(define contents (call-with-input-file *filename* port->string))", Shiki_CURRENT_BUFFER_ENV);
856     Scm_EvalCString("(define ces (ces-guess-from-string contents \"*JP\"))", Shiki_CURRENT_BUFFER_ENV);
857     ces = Scm_EvalCString("ces", Shiki_CURRENT_BUFFER_ENV);
858     Shiki_CURRENT_CES = Scm_GetString(SCM_STRING(ces));
859     s = Scm_EvalCString("(ces-convert contents ces)", Shiki_CURRENT_BUFFER_ENV);
860     text = Scm_GetString(SCM_STRING(s));
861     gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER, text, -1);
862     /* ������������������������ */
863     gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
864     /* ������������������������������ */
865     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
866     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
867     update_modeline_label();
868     gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
869     gtk_widget_show_all(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
870 aloha 1.33
871 aloha 1.49 g_free(utf8filename);
872     g_free(filename);
873 aloha 1.1
874 aloha 1.49 /* ��������������������������������� */
875     scheme_keyword_highlighting_current_buffer();
876 aloha 1.1 }
877    
878 aloha 1.21 /* ��������������������������������������������������� */
879 aloha 1.27 static void open_file_handler() {
880 aloha 1.21 gchar *filename = get_filename_from_dialog("File Selection");
881    
882     if(!filename) return;
883 aloha 1.27 open_file(filename);
884 aloha 1.1 }
885    
886     /* gauche ��������������������������������� */
887     static gchar *eval_cstring_by_gauche(gchar *s) {
888     gchar *msg;
889    
890     ScmObj result, error;
891     /* ������������������������������ */
892     ScmObj os = Scm_MakeOutputStringPort(TRUE);
893    
894     /* Scheme ��������������������������������������� */
895     /* http://alohakun.blog7.fc2.com/blog-entry-517.html */
896 aloha 1.34 Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*input*")), SCM_MAKE_STR(s));
897     Scm_Define(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
898 aloha 1.1
899 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));
900 aloha 1.1
901 aloha 1.34 error = Scm_GlobalVariableRef(SCM_MODULE(Shiki_CURRENT_BUFFER_ENV), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
902 aloha 1.1
903     /* ��������������������������������������������������������� */
904     if (!SCM_FALSEP(error))
905     Scm_Write(error, os, SCM_WRITE_DISPLAY);
906     else
907     Scm_Write(result, os, SCM_WRITE_DISPLAY);
908    
909     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
910     /* ������������������ */
911     Scm_ClosePort(SCM_PORT(os));
912    
913     return msg;
914     }
915    
916 aloha 1.13 /* ������������������������������������������������������������������ S ��������������� (������������) */
917 aloha 1.27 static void load_region_by_gauche() {
918 aloha 1.1
919     GtkTextIter start, end, p;
920     gchar *code;
921 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
922     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
923 aloha 1.1
924     /* ������������������������������������������������������������ */
925 aloha 1.16 if(gtk_text_buffer_get_selection_bounds(Shiki_CURRENT_TEXT_BUFFER, &start, &end)) {
926     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
927     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(code), -1);
928 aloha 1.1 g_free(code);
929     }
930     }
931    
932     // GtkTextCharPredicate
933     static gboolean is_kakko_or_kokka(gunichar ch, gpointer p) {
934     return ch == '(' || ch == ')';
935     }
936 aloha 1.29 static gboolean is_kakko(gunichar ch, gpointer p) {return ch == '(';}
937 aloha 1.1 static gboolean is_kokka(gunichar ch, gpointer p) {return ch == ')';}
938    
939 aloha 1.30 /* ��������������������� '(' ��������������� ')' ������������������ (S ���) ��������������� */
940     static gboolean search_sexp(GtkTextIter *start, GtkTextIter *end) {
941 aloha 1.33
942 aloha 1.30 /* ������������������������������ */
943     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, start, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
944    
945     if(gtk_text_iter_get_char(start) != '(')
946     gtk_text_iter_forward_find_char(start, is_kakko, NULL, NULL);
947    
948     *end = *start;
949    
950     /* ��������������������������������� S ������������������ */
951     if(!search_sexp_kokka(end)) return FALSE;
952     gtk_text_iter_forward_char(end);
953     return TRUE;
954     }
955    
956     static gboolean search_sexp_kokka(GtkTextIter *end) {
957 aloha 1.29 gint nest_level = 0;
958 aloha 1.33
959 aloha 1.30 /* ������������ ')' ��������� */
960 aloha 1.29 while(1) {
961 aloha 1.30 if(!gtk_text_iter_forward_find_char(end, is_kakko_or_kokka, NULL, NULL))
962 aloha 1.29 return FALSE;
963    
964 aloha 1.30 if(gtk_text_iter_get_char(end) == '(')
965 aloha 1.29 nest_level++;
966     else {
967     if(!nest_level)
968     break;
969     else
970     nest_level--;
971     }
972     }
973     return TRUE;
974     }
975 aloha 1.1
976 aloha 1.30 /* ��������������������� ')' ��������������� '(' ������������������ (S ���) ��������������� */
977     static gboolean search_last_sexp(GtkTextIter *start, GtkTextIter *end) {
978    
979     /* ������������������������������ */
980     gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
981    
982     gtk_text_iter_backward_char(end);
983 aloha 1.33
984 aloha 1.30 if(gtk_text_iter_get_char(end) != ')')
985     gtk_text_iter_backward_find_char(end, is_kokka, NULL, NULL);
986     *start = *end;
987     gtk_text_iter_forward_char(end);
988    
989     /* ��������������������������������� S ������������������ */
990     if(!search_last_sexp_kakko(start)) return FALSE;
991    
992     return TRUE;
993     }
994    
995 aloha 1.1 /* ')' ��������������� '(' ������������������ (S ���) ��������������� */
996 aloha 1.29 static gboolean search_last_sexp_kakko(GtkTextIter *start) {
997 aloha 1.1 gint nest_level = 0;
998 aloha 1.30 /* ��������������������������������������� ')' ��������� */
999 aloha 1.1 while(1) {
1000     if(!gtk_text_iter_backward_find_char(start, is_kakko_or_kokka, NULL, NULL))
1001     return FALSE;
1002    
1003     if(gtk_text_iter_get_char(start) == ')')
1004     nest_level++;
1005     else {
1006     if(!nest_level)
1007     break;
1008     else
1009     nest_level--;
1010     }
1011     }
1012     return TRUE;
1013     }
1014    
1015     /* ������������������������������������������������ */
1016     static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer) {
1017     gint nest_level = 0;
1018     GtkTextIter start, end;
1019     gtk_text_buffer_get_start_iter(buffer, &start);
1020     if(gtk_text_iter_get_char(&start) == '(') nest_level++;
1021    
1022     /* ��������������������� (= end) ��������� */
1023     gtk_text_buffer_get_iter_at_mark(buffer,&end, gtk_text_buffer_get_insert(buffer));
1024    
1025     while(1) {
1026     /* end ������ '(' ��� ')' ��������������������������������������������� */
1027     if(!gtk_text_iter_forward_find_char(&start, is_kakko_or_kokka, NULL, &end))
1028     return nest_level;
1029    
1030     if(gtk_text_iter_get_char(&start) == '(')
1031     nest_level++;
1032     else
1033     nest_level--;
1034     }
1035     }
1036    
1037     /* ��������������������������������� on/off */
1038     static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook) {
1039     gint tval = FALSE;
1040     gint bval = FALSE;
1041     if(notebook->show_tabs == FALSE)
1042     tval = TRUE;
1043     if(notebook->show_border == FALSE)
1044     bval = TRUE;
1045    
1046     gtk_notebook_set_show_tabs(notebook, tval);
1047     gtk_notebook_set_show_border(notebook, bval);
1048     }
1049    
1050     /* ������������������������ */
1051 aloha 1.17 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook ) {
1052 aloha 1.1 gtk_notebook_set_tab_pos(notebook, (notebook->tab_pos + 1) % 4);
1053     }
1054    
1055     /* ������������������������������������������ */
1056    
1057 aloha 1.3 /* ��������������������� ^npfb */
1058 aloha 1.7 static void forward_current_buffer() {
1059 aloha 1.3 GtkTextIter p;
1060 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
1061 aloha 1.3 gtk_text_iter_forward_char(&p);
1062 aloha 1.16 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
1063 aloha 1.3 }
1064 aloha 1.7 static void backward_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_backward_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 line_forward_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     gtk_text_view_forward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
1074     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
1075 aloha 1.7 }
1076     static void line_backward_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_backward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
1080     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
1081 aloha 1.3 }
1082    
1083 aloha 1.1 /* ��������������������� */
1084 aloha 1.8 static gboolean signal_key_release_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
1085     static gint metakey_pressed = 0;
1086 aloha 1.6 static gint controlx_pressed = 0;
1087 aloha 1.1
1088     if(event->keyval == GDK_parenright && event->state & GDK_SHIFT_MASK) {
1089     GtkTextIter start, end;
1090    
1091     /* ������������������������������ */
1092 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
1093 aloha 1.1
1094     start = end;
1095     gtk_text_iter_backward_char(&start);
1096    
1097     /* ��������������������������������� S ������������������ */
1098 aloha 1.29 if(!search_last_sexp_kakko(&start)) return FALSE;
1099 aloha 1.1
1100 aloha 1.16 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
1101 aloha 1.1 }
1102    
1103     /* ������������������������������������������������������������������������������������������������ (���������������) ������������������ */
1104     if(event->keyval == GDK_Return) {
1105 aloha 1.16 gint indentWidth = get_parent_nest_level_at_cursor(Shiki_CURRENT_TEXT_BUFFER) * editor_indent_width;
1106 aloha 1.1 gchar *indent = g_strnfill(indentWidth, ' ');
1107 aloha 1.16 gtk_text_buffer_insert_at_cursor(Shiki_CURRENT_TEXT_BUFFER, indent, -1);
1108 aloha 1.1 g_free(indent);
1109     }
1110    
1111 aloha 1.6 /* C-x */
1112     if(event->keyval == GDK_x && event->state & GDK_CONTROL_MASK) {
1113     controlx_pressed++;
1114 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-x -");
1115 aloha 1.6 } else if(event->state & GDK_CONTROL_MASK) {
1116 aloha 1.8
1117 aloha 1.6 if(controlx_pressed > 0) {
1118     switch(event->keyval) {
1119     case GDK_c :/* C-x C-c : ������ */
1120 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-c");
1121 aloha 1.6 {/* "delete-event" ��������������������������������������� �� ������������������������������������ */
1122     GdkEvent ev;
1123    
1124     ev.any.type = GDK_DELETE;
1125 aloha 1.16 ev.any.window = Shiki_EDITOR_WINDOW->window;
1126 aloha 1.6 ev.any.send_event = FALSE;
1127     gdk_event_put (&ev);
1128     }
1129     break;
1130    
1131     case GDK_f : /* C-x C-f : ������������������ */
1132 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-f");
1133 aloha 1.27 open_file_handler();
1134 aloha 1.6 break;
1135    
1136     case GDK_s : /* C-x C-s : ������������������ */
1137 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-s");
1138 aloha 1.27 save_file();
1139 aloha 1.6 break;
1140    
1141     case GDK_w : /* C-x C-w : ������������������������ */
1142 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-w");
1143 aloha 1.27 save_file_as();
1144 aloha 1.6 break;
1145     }
1146     controlx_pressed = 0;
1147     }
1148 aloha 1.8
1149     switch(event->keyval) {
1150     case GDK_g :/* C-g : ��������������� */
1151     metakey_pressed = 0;
1152     controlx_pressed = 0;
1153    
1154 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "Quit");
1155 aloha 1.8 break;
1156     }
1157    
1158 aloha 1.6 }
1159 aloha 1.1 return FALSE;
1160     }
1161 aloha 1.27 static void open_online_help() {
1162 aloha 1.22 GtkTextIter p;
1163 aloha 1.27 append_tabpage(g_strdup("*help*"));
1164 aloha 1.22 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER,
1165 aloha 1.37 "������������������������������������������\n"
1166 aloha 1.30 "$ ./shiki [file1 file2 ....]\n\n"
1167     "[���������������������������] ��������������������� (C-x C-f)\n"
1168     "[������������������������������������������] ��������������������� (C-x C-s)\n"
1169     "[���������������������������������������������] ��������������������������� (C-x C-w)\n"
1170 aloha 1.37 "[���������������������] ��������������� gauche ������������\n"
1171 aloha 1.30 "[��������������� (���������) ���������������] ��������� on/off\n"
1172     "[������ (���������) ���������������] ������������������������\n"
1173 aloha 1.37 "[������������������] ��������������������������� (C-t)\n"
1174 aloha 1.33 "[���������������������������] ������������ (C-_)\n"
1175 aloha 1.30 "[���������������������] ������������������������\n"
1176 aloha 1.44 "\n"
1177     "(��� : ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ Undo ������������������)\n"
1178     "\n"
1179 aloha 1.37 "[�� ������������] ������������������������ (C-k)\n"
1180 aloha 1.30 "[A ������������] ���������������������\n"
1181     "[���������������������������] Scheme ������������������������\n"
1182     "[���������������������������������] ���������������������������������������\n"
1183     "[��������� (?) ������������] ���������������������������������������\n"
1184 aloha 1.33 "[info ������������] ���������������������������������������������������\n"
1185     "\n"
1186 aloha 1.30 "C-f : ��� ��������� (forward)\n"
1187     "C-b : ��� ��������� (backward)\n"
1188     "C-n : ��� ��������� (next line)\n"
1189 aloha 1.33 "C-p : ��� ��������� (previous line)\n"
1190     "\n"
1191     "C-h : ���������������������\n"
1192 aloha 1.31 "C-w : ���������\n"
1193 aloha 1.33 "C-y : ��������� (������������)\n"
1194     "\n"
1195 aloha 1.30 "C-e : ��������������������� S ������������ (eval-expression)\n"
1196     "C-j : ��������������������� S ������������ (eval-last-sexp)\n"
1197 aloha 1.33 "(emacs/xyzzy ��� *scratch* ���������������������)\n"
1198     "\n"
1199 aloha 1.31 "C-M-@ : ��������������������� S ������������ (mark-sexp)\n"
1200     "C-M-SPC : ��������������������� S ������������ (mark-last-sexp)\n"
1201 aloha 1.33 "C-x C-c : ��������������������������� �� ���������������������������������\n"
1202 aloha 1.44 , -1);
1203 aloha 1.30 gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
1204     /* ������������������������������ */
1205     gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
1206     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
1207 aloha 1.22 }
1208    
1209 aloha 1.1 /* ��������������������������������������� */
1210 aloha 1.21 static void shiki_editor_window_init(int argc, char **argv) {
1211 aloha 1.39 GtkWidget *vbox, *toolbar, *modeline_bg = gtk_event_box_new();
1212 aloha 1.1 GtkToolItem *icon;
1213     GtkIconSize iconsize;
1214 aloha 1.2 GtkTooltips *toolbar_tips = gtk_tooltips_new();
1215 aloha 1.1 /* ��������������������������������������������������������������������������������� */
1216     GtkToolItem *oicon, *sicon, *saicon, *eicon;
1217    
1218 aloha 1.36 gint contextid, i;
1219    
1220     /* ������������������������������������������������������������������������������ */
1221     keywords_hash = g_hash_table_new(g_str_hash, g_str_equal);
1222     i = 0;
1223     while(R5RS_keywords[i] != NULL)
1224     g_hash_table_insert(keywords_hash, R5RS_keywords[i++], GINT_TO_POINTER(R5RS_KEYWORD_COLOR));
1225     i = 0;
1226     while(R5RS_functions[i] != NULL)
1227     g_hash_table_insert(keywords_hash, R5RS_functions[i++], GINT_TO_POINTER(R5RS_FUNCTION_COLOR));
1228 aloha 1.8
1229 aloha 1.1 /* ������������ */
1230 aloha 1.16 Shiki_EDITOR_WINDOW = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1231     g_signal_connect(G_OBJECT(Shiki_EDITOR_WINDOW), "destroy", G_CALLBACK(gtk_main_quit), NULL);
1232 aloha 1.1
1233 aloha 1.31 /* ������������������������������������������������������������ */
1234     Shiki_EDITOR_CLIPBOARD = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
1235    
1236 aloha 1.1 /* ������������������������������������ */
1237     vbox = gtk_vbox_new(FALSE, 0);
1238     /* ��������������������� */
1239     toolbar = gtk_toolbar_new();
1240     gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
1241    
1242 aloha 1.26 Shiki_EDITOR_NOTEBOOK = GTK_NOTEBOOK(gtk_notebook_new());
1243     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "switch-page", GTK_SIGNAL_FUNC(switch_tabpage_handler), NULL);
1244 aloha 1.1
1245     /* ������������������������������������������������ */
1246     gtk_toolbar_set_style(GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
1247     iconsize = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar));
1248    
1249     /* ������������������ */
1250    
1251     /* ������������������ */
1252 aloha 1.45 oicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_OPEN, iconsize), "");
1253 aloha 1.1 /* ������������������������������������������������������������������������������������ */
1254 aloha 1.27 g_signal_connect(G_OBJECT(oicon), "clicked", G_CALLBACK(open_file_handler), NULL);
1255 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(oicon));
1256 aloha 1.2 gtk_tool_item_set_tooltip(oicon, toolbar_tips, "���������������������������",
1257     "���������������������������������������������������������������������������������������");
1258 aloha 1.1
1259     /* ������������������ */
1260 aloha 1.45 sicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SAVE, iconsize), "");
1261 aloha 1.1 /* ������������������������������������������������������������������������������������ */
1262 aloha 1.27 g_signal_connect(G_OBJECT(sicon), "clicked", G_CALLBACK(save_file), NULL);
1263 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(sicon));
1264 aloha 1.2 gtk_tool_item_set_tooltip(sicon, toolbar_tips, "������������������������������",
1265     "������������������������������������������������������������������������������������������������������������������������������������");
1266 aloha 1.1
1267     /* ��������������������������� */
1268 aloha 1.45 saicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SAVE_AS, iconsize), "");
1269 aloha 1.1 /* ������������������������������������������������������������������������������������������������������������������ */
1270 aloha 1.27 g_signal_connect(G_OBJECT(saicon), "clicked", G_CALLBACK(save_file_as), NULL);
1271 aloha 1.2 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(saicon));
1272     gtk_tool_item_set_tooltip(saicon, toolbar_tips, "������������������������������������",
1273     "");
1274 aloha 1.1
1275     /* ������������������ */
1276 aloha 1.45 eicon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_EXECUTE, iconsize), "");
1277 aloha 1.14 /* ������������������������������������������ libgauche ������������������ */
1278 aloha 1.27 g_signal_connect(G_OBJECT(eicon), "clicked", G_CALLBACK(load_region_by_gauche), NULL);
1279 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(eicon));
1280 aloha 1.14 gtk_tool_item_set_tooltip(eicon, toolbar_tips, "��������������� S ������������������������ (load-region-lisp)",
1281 aloha 1.2 "Scheme (gauche) ������������������ S ������������������������");
1282 aloha 1.1
1283 aloha 1.16 gtk_container_add(GTK_CONTAINER(Shiki_EDITOR_WINDOW), vbox);
1284 aloha 1.26 gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
1285 aloha 1.1
1286 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_NEW, iconsize), "");
1287 aloha 1.33 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(append_default_tabpage_handler), NULL);
1288 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1289 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������", "");
1290 aloha 1.1
1291 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_UNDO, iconsize), "");
1292 aloha 1.33 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(undo), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1293     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1294     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Undo","");
1295    
1296 aloha 1.37 /* XXX : TODO */
1297 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_REDO, iconsize), "");
1298 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(dummy_handler), NULL);
1299     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1300     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Redo", "");
1301 aloha 1.37
1302 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_FIND, iconsize), "");
1303 aloha 1.46 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(search_current_buffer), NULL);
1304 aloha 1.37 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1305     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������", "");
1306    
1307    
1308 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_FIND_AND_REPLACE, iconsize), "");
1309 aloha 1.47 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(replace_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 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_REFRESH, iconsize), "");
1314 aloha 1.37 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(dummy_handler), NULL);
1315     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1316     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������", "");
1317    
1318     /* TODO ������������ */
1319    
1320 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DELETE, iconsize), "");
1321 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(clear_current_buffer), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1322 aloha 1.15 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1323     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������",
1324     "���������������������������������������������������������������������");
1325    
1326 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CLOSE, iconsize), "");
1327 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(remove_tabpage), NULL);
1328 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1329 aloha 1.2 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������",
1330     "���������������������������������������������������������������");
1331 aloha 1.15
1332 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CONNECT, iconsize), "");
1333 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_scheme_file_by_gauche), NULL);
1334 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1335     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Scheme ������������������������", "");
1336    
1337 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_CONVERT, iconsize), "");
1338 aloha 1.26 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_buffer_by_gauche), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1339 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1340     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������", "");
1341    
1342 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_SPELL_CHECK, iconsize), "");
1343 aloha 1.37 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(scheme_keyword_highlighting_current_buffer), NULL);
1344     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1345     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
1346    
1347    
1348 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, iconsize), "");
1349 aloha 1.27 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(open_online_help), NULL);
1350 aloha 1.22 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1351     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������", "");
1352 aloha 1.49
1353 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_BOLD, iconsize), "");
1354 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(select_font), NULL);
1355     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1356     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
1357    
1358 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_APPLY, iconsize), "");
1359 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(tabsborder_on_off), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1360     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1361     gtk_tool_item_set_tooltip(icon, toolbar_tips, "��������� on/off", "");
1362    
1363 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_PREFERENCES, iconsize), "");
1364 aloha 1.38 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(rotate_tab_position), G_OBJECT(Shiki_EDITOR_NOTEBOOK));
1365     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1366     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
1367 aloha 1.22
1368 aloha 1.45 icon = gtk_tool_button_new(gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, iconsize), "");
1369 aloha 1.11 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(about_this_application), NULL);
1370     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
1371     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
1372    
1373 aloha 1.39 /* ������������������������ */
1374     Shiki_EDITOR_MODELINE_LABEL = gtk_label_new(NULL);
1375     gtk_container_add(GTK_CONTAINER (modeline_bg), Shiki_EDITOR_MODELINE_LABEL);
1376 aloha 1.49
1377 aloha 1.39 gdk_color_parse("black", &COLOR_BLACK);
1378     gdk_color_parse("green", &COLOR_GREEN);
1379 aloha 1.49
1380 aloha 1.39 gtk_widget_modify_fg(Shiki_EDITOR_MODELINE_LABEL, GTK_STATE_NORMAL, &COLOR_GREEN);
1381     gtk_widget_modify_bg(modeline_bg, GTK_STATE_NORMAL, &COLOR_BLACK);
1382    
1383     gtk_box_pack_start(GTK_BOX(vbox), modeline_bg, TRUE, TRUE, 0);
1384 aloha 1.12
1385 aloha 1.8 /* C-x C-s ��������������������������������������������������������������������������������������� */
1386 aloha 1.16 Shiki_EDITOR_STATUSBAR = gtk_statusbar_new();
1387     gtk_box_pack_start(GTK_BOX(vbox), Shiki_EDITOR_STATUSBAR, TRUE, TRUE, 0);
1388     contextid = gtk_statusbar_get_context_id(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), "");
1389 aloha 1.8
1390     /* ������������������������������������������������ */
1391 aloha 1.26 g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-press-event", G_CALLBACK (signal_key_press_handler), GINT_TO_POINTER(contextid));
1392     g_signal_connect(G_OBJECT(Shiki_EDITOR_NOTEBOOK), "key-release-event", G_CALLBACK (signal_key_release_handler), GINT_TO_POINTER(contextid));
1393 aloha 1.12
1394 aloha 1.21 /* ��������������������������������������������� */
1395     if(argc >= 2) {
1396     int i;
1397     for(i = 1; i < argc; i++)
1398 aloha 1.27 open_file(g_strdup(argv[i]));
1399 aloha 1.21 } else /* ������������������������������������������������������������������ */
1400 aloha 1.26 open_online_help(Shiki_EDITOR_NOTEBOOK);
1401 aloha 1.8
1402 aloha 1.26 gtk_widget_grab_focus(GTK_WIDGET(Shiki_EDITOR_NOTEBOOK));
1403 aloha 1.16 gtk_widget_show_all(Shiki_EDITOR_WINDOW);
1404 aloha 1.1 }
1405    
1406     int main(int argc, char *argv[]) {
1407     /* ������������������������������������ */
1408 aloha 1.39 Shiki_EDITOR_DEFAULT_LOCALE = g_locale_to_utf8(gtk_set_locale(), -1, NULL, NULL, NULL);
1409 aloha 1.1 gtk_init(&argc, &argv);
1410     GC_INIT(); Scm_Init(GAUCHE_SIGNATURE);
1411 aloha 1.21 shiki_editor_window_init(argc, argv);
1412 aloha 1.1 gtk_main();
1413     Scm_Exit(0);
1414     return 0;
1415     }

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