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.52 - (hide annotations) (download) (as text)
Thu Nov 23 16:58:36 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.51: +29 -3 lines
File MIME type: text/x-csrc
add xyzzy API (buffer-substring start end)

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

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