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.7 - (hide annotations) (download) (as text)
Sat Nov 4 05:56:31 2006 UTC (17 years, 5 months ago) by aloha
Branch: MAIN
Changes since 1.6: +65 -94 lines
File MIME type: text/x-csrc
key press event handler and so on ... refectoring. More detail : add current_* static global variable for efficiency (cache).

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.7 * $Id: shiki.c,v 1.6 2006/11/03 18:54:30 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.1 static GtkWidget *editor_window;
35 aloha 1.7 static GtkScrolledWindow *current_tabpage;
36     static gint current_tabpage_num;
37     static const gchar *current_tabpage_label;
38     static GtkTextView *current_text_view;
39     static GtkTextBuffer *current_text_buffer;
40    
41 aloha 1.1
42     /* ��������������������������������������������������������������� */
43     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer) {
44     GtkTextIter start, end;
45     gtk_text_buffer_get_start_iter(buffer, &start);
46     gtk_text_buffer_get_end_iter(buffer, &end);
47     return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
48     }
49    
50     /* buffer ������������������������ filename ��������� */
51     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer) {
52     gchar *contents, *text;
53     gsize br, bw;
54     GError *err = NULL;
55    
56     if(!filename) return FALSE;
57     contents = get_all_buffer_contents(buffer);
58     text = g_locale_from_utf8(contents, -1, &br, &bw, &err);
59     /* ��������������������������������� */
60     g_file_set_contents(filename, text, -1, NULL);
61     gtk_text_buffer_set_modified(buffer, FALSE);
62     g_free(contents); g_free(text);
63     return TRUE;
64     }
65    
66     /* ������������������������������������������������������msg ������������������������������������ */
67     static gchar *get_filename_from_dialog(const gchar *msg) {
68    
69     GtkWidget *dialog = gtk_file_selection_new(msg);
70     int resp = gtk_dialog_run(GTK_DIALOG(dialog));
71     gchar *filename = NULL;
72    
73     /* gtk_file_selection_get_filename ������������������������������������������������������������������������������������������������������������������������������ */
74     if(resp == GTK_RESPONSE_OK)
75     filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog)));
76    
77     gtk_widget_destroy(dialog);
78     return filename;
79     }
80    
81     /* ��������������������������������������������������������������������� */
82     static void save_file_from_notebook(GtkNotebook *notebook) {
83    
84     /* ������������������������������������ */
85 aloha 1.7 if(!gtk_text_buffer_get_modified(current_text_buffer)) return;
86 aloha 1.1
87     /* ������������������������������������������������������������������������������������������������������ */
88 aloha 1.7 if(g_ascii_strcasecmp("*scratch*", current_tabpage_label) == 0) {
89     gchar *filename = get_filename_from_dialog("Save File As ...");
90     if(!filename) return;
91     if(!save_text_buffer(filename, current_text_buffer)) return;
92     gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(current_tabpage), filename);
93     gtk_window_set_title (GTK_WINDOW(editor_window), filename);
94 aloha 1.1 g_free(filename);
95     } else
96 aloha 1.7 save_text_buffer(current_tabpage_label, current_text_buffer);
97 aloha 1.1 }
98    
99     /* ��������������������������������������������������� */
100     static void save_file_handler(GtkWidget *widget, GtkWidget *notebook) {
101     save_file_from_notebook(GTK_NOTEBOOK(notebook));
102     }
103    
104     /* ��������������������������������������������������������������������������� */
105     static void save_file_as_from_notebook(GtkNotebook *notebook) {
106     gchar *filename = get_filename_from_dialog("Save File As ...");
107    
108 aloha 1.7 if(!filename) return;
109     if(!save_text_buffer(filename, current_text_buffer)) return;
110 aloha 1.1
111 aloha 1.7 gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(current_tabpage), filename);
112 aloha 1.1 gtk_window_set_title (GTK_WINDOW (editor_window), filename);
113    
114     g_free(filename);
115     }
116    
117     /* ��������������������������������������������������������� */
118     static void save_file_as_handler(GtkWidget *widget, GtkWidget *notebook) {
119     save_file_as_from_notebook(GTK_NOTEBOOK(notebook));
120     }
121    
122     /* YES ������������NO ������������������������������������ callback */
123     void really_quit_dialog_yes(GtkWidget *widget, gboolean *flag){*flag = FALSE;}
124     void really_quit_dialog_no(GtkWidget *widget, gint *flag){*flag = TRUE;}
125    
126     /* ��������������������������������������������� ? */
127     gboolean not_yet_save_changes_really_quit(GtkTextBuffer *buffer) {
128     GtkWidget *yes_button, *no_button;
129     static GtkWidget *dialog_window = NULL;
130    
131     /* ��������������������������������������� */
132     if(!gtk_text_buffer_get_modified(buffer)) return FALSE;
133    
134     if(dialog_window == NULL) {
135     gboolean flag = TRUE;
136     dialog_window = gtk_dialog_new ();
137    
138     /* ��������������������������������������������� ? ��������������������������� */
139     g_signal_connect(G_OBJECT(dialog_window), "delete_event", G_CALLBACK(gtk_false), NULL);
140     g_signal_connect(G_OBJECT(dialog_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
141 aloha 1.5 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->vbox),
142     gtk_label_new("������������������������������������������\n��������������������������������������� ?"), TRUE, TRUE, 0);
143 aloha 1.1 gtk_window_set_title(GTK_WINDOW (dialog_window), "Really Quit ?");
144     /* YES ������������ */
145 aloha 1.5 yes_button = gtk_button_new_with_label("������ (Y)");
146 aloha 1.1 g_signal_connect(GTK_OBJECT(yes_button), "clicked", G_CALLBACK(really_quit_dialog_yes), &flag);
147     g_signal_connect_swapped(GTK_OBJECT(yes_button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(dialog_window));
148     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), yes_button, TRUE, TRUE, 0);
149    
150     /* NO ������������ */
151 aloha 1.5 no_button = gtk_button_new_with_label("��������� (N)");
152 aloha 1.1 g_signal_connect(GTK_OBJECT(no_button), "clicked", G_CALLBACK(really_quit_dialog_no), &flag);
153     g_signal_connect_swapped(GTK_OBJECT(no_button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(dialog_window));
154     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), no_button, TRUE, TRUE, 0);
155    
156     gtk_window_set_modal(GTK_WINDOW(dialog_window), TRUE);
157     gtk_window_set_transient_for(GTK_WINDOW(dialog_window), GTK_WINDOW (editor_window));
158    
159     gtk_widget_show_all(dialog_window);
160     gtk_main ();
161     dialog_window = NULL;
162    
163     /* "delete_event" ��������������� FALSE ���������"destory" ������������������window ������������������ */
164     return flag;
165     }
166     return TRUE;
167     }
168    
169     /* ������������������������������������������������������������������������������������������ */
170     gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, GtkWidget *buffer){
171     return not_yet_save_changes_really_quit(GTK_TEXT_BUFFER(buffer));
172     }
173    
174     /* ������������������������������ */
175     static GtkWidget *new_scrolled_text_buffer() {
176    
177     GtkWidget *scrolledwindow, *view;
178     GtkTextBuffer *buffer;
179    
180     /* ������������������������������������ */
181     scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
182     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
183    
184     /* ������������������������������������������������ */
185     view = gtk_text_view_new();
186     buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
187     gtk_container_add(GTK_CONTAINER(scrolledwindow), view);
188     g_signal_connect(G_OBJECT(editor_window), "delete_event", G_CALLBACK(delete_event_handler), buffer);
189     gtk_widget_set_size_request(GTK_WIDGET(view), 500, 500);
190    
191     /* ������������������������ */
192     /* ������������������������������������������������ */
193     gtk_text_buffer_create_tag (buffer, "parent_emphasis_background", "background", "green", NULL);
194    
195     return scrolledwindow;
196     }
197    
198     /* ��������������������� */
199     static void open_file_from_notebook(GtkNotebook *notebook) {
200     gchar *contents, *text;
201     gsize br, bw, len;
202     GError *err = NULL;
203     gchar *filename = get_filename_from_dialog("File Selection");
204    
205     if(!filename) return;
206    
207     if(g_file_get_contents(filename, &contents, &len, NULL)) {
208     GtkTextBuffer *buffer;
209     GtkWidget *scrolledwindow;
210     GtkTextIter p;
211 aloha 1.3
212 aloha 1.1 /* ������������������������������ */
213     gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
214 aloha 1.3 scrolledwindow = new_scrolled_text_buffer(),
215     gtk_label_new(filename));
216 aloha 1.1 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtk_bin_get_child(GTK_BIN(scrolledwindow))));
217    
218     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
219     gtk_text_buffer_set_text(buffer, contents, len);
220     else
221     gtk_text_buffer_set_text(buffer, text, len);
222    
223     /* ������������������������ */
224     gtk_text_buffer_set_modified(buffer, FALSE);
225     /* ������������������������������ */
226     gtk_text_buffer_get_start_iter(buffer, &p);
227     gtk_text_buffer_place_cursor(buffer, &p);
228     gtk_window_set_title (GTK_WINDOW (editor_window), filename);
229     gtk_widget_show_all(GTK_WIDGET(notebook));
230     g_free(contents); g_free(text); g_free(filename);
231     } else
232     g_printerr("Get file contents error !\n");
233     }
234    
235     /* ��������������������������������������������� */
236     static void open_file_handler(GtkWidget *widget, GtkWidget *notebook) {
237     open_file_from_notebook(GTK_NOTEBOOK(notebook));
238     }
239    
240     /* gauche ��������������������������������� */
241     static gchar *eval_cstring_by_gauche(gchar *s) {
242     gchar *msg;
243    
244     ScmObj result, error;
245     /* ������������������������������ */
246     ScmObj os = Scm_MakeOutputStringPort(TRUE);
247    
248     /* Scheme ��������������������������������������� */
249     /* http://alohakun.blog7.fc2.com/blog-entry-517.html */
250     Scm_Define(Scm_UserModule(), SCM_SYMBOL(SCM_INTERN("*input*")), SCM_MAKE_STR(s));
251     Scm_Define(Scm_UserModule(), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
252    
253     result = Scm_EvalCString("(guard (e (else (set! *error* e) #f)) (eval (read-from-string *input*) (current-module)))", SCM_OBJ(Scm_UserModule()));
254    
255     error = Scm_GlobalVariableRef(Scm_UserModule(), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
256    
257     /* ��������������������������������������������������������� */
258     if (!SCM_FALSEP(error))
259     Scm_Write(error, os, SCM_WRITE_DISPLAY);
260     else
261     Scm_Write(result, os, SCM_WRITE_DISPLAY);
262    
263     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
264     /* ������������������ */
265     Scm_ClosePort(SCM_PORT(os));
266    
267     return msg;
268     }
269    
270     /* ������������������������������������������������������������������������ S ������������ */
271     static void buffer_exec_handler(GtkWidget *widget, GtkWidget *notebook) {
272    
273     GtkTextIter start, end, p;
274     gchar *code;
275 aloha 1.7 gtk_text_buffer_get_end_iter(current_text_buffer, &p);
276     gtk_text_buffer_insert(current_text_buffer, &p, "\n\n", -1);
277 aloha 1.1
278     /* ������������������������������������������������������������ */
279 aloha 1.7 if(gtk_text_buffer_get_selection_bounds(current_text_buffer, &start, &end)) {
280     code = gtk_text_buffer_get_text(current_text_buffer, &start, &end, FALSE);
281     gtk_text_buffer_insert(current_text_buffer, &p, eval_cstring_by_gauche(code), -1);
282 aloha 1.1 g_free(code);
283     }
284     }
285    
286     // GtkTextCharPredicate
287     static gboolean is_kakko_or_kokka(gunichar ch, gpointer p) {
288     return ch == '(' || ch == ')';
289     }
290     static gboolean is_kokka(gunichar ch, gpointer p) {return ch == ')';}
291    
292    
293     /* ')' ��������������� '(' ������������������ (S ���) ��������������� */
294     static gboolean search_sexp_string(GtkTextIter *start) {
295     gint nest_level = 0;
296     /* ��������������������������������� S ������������������ */
297     while(1) {
298     if(!gtk_text_iter_backward_find_char(start, is_kakko_or_kokka, NULL, NULL))
299     return FALSE;
300    
301     if(gtk_text_iter_get_char(start) == ')')
302     nest_level++;
303     else {
304     if(!nest_level)
305     break;
306     else
307     nest_level--;
308     }
309     }
310     return TRUE;
311     }
312    
313     /* ������������������������������������������������ */
314     static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer) {
315     gint nest_level = 0;
316     GtkTextIter start, end;
317     gtk_text_buffer_get_start_iter(buffer, &start);
318     if(gtk_text_iter_get_char(&start) == '(') nest_level++;
319    
320     /* ��������������������� (= end) ��������� */
321     gtk_text_buffer_get_iter_at_mark(buffer,&end, gtk_text_buffer_get_insert(buffer));
322    
323     while(1) {
324     /* end ������ '(' ��� ')' ��������������������������������������������� */
325     if(!gtk_text_iter_forward_find_char(&start, is_kakko_or_kokka, NULL, &end))
326     return nest_level;
327    
328     if(gtk_text_iter_get_char(&start) == '(')
329     nest_level++;
330     else
331     nest_level--;
332     }
333     }
334    
335     /* ������������������������������������������������������������ */
336     static void switch_page(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum, gpointer p) {
337 aloha 1.7
338     /* ������������������������������������������������������������ */
339     current_tabpage = GTK_SCROLLED_WINDOW(gtk_notebook_get_nth_page(notebook, pagenum));
340     current_tabpage_num = pagenum;
341     /* GtkBin ������������������������������������������������������������ */
342     current_text_view = GTK_TEXT_VIEW(gtk_bin_get_child(GTK_BIN(current_tabpage)));
343     current_text_buffer = gtk_text_view_get_buffer(current_text_view);
344    
345 aloha 1.1 /* ������������������������������������������������������ */
346 aloha 1.7 gtk_window_set_title (GTK_WINDOW(editor_window), current_tabpage_label = gtk_notebook_get_tab_label_text(notebook, GTK_WIDGET(current_tabpage)));
347 aloha 1.1 }
348    
349     /* ��������������������������������� on/off */
350     static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook) {
351     gint tval = FALSE;
352     gint bval = FALSE;
353     if(notebook->show_tabs == FALSE)
354     tval = TRUE;
355     if(notebook->show_border == FALSE)
356     bval = TRUE;
357    
358     gtk_notebook_set_show_tabs(notebook, tval);
359     gtk_notebook_set_show_border(notebook, bval);
360     }
361    
362     /* ������������������������������������������ */
363     static void remove_tabpage(GtkNotebook *notebook) {
364 aloha 1.7 if(!not_yet_save_changes_really_quit(current_text_buffer)) {
365     gtk_notebook_remove_page(notebook, current_tabpage_num);
366 aloha 1.1 /* ��������������������������������������� */
367     gtk_widget_queue_draw(GTK_WIDGET(notebook));
368     }
369     }
370    
371     static void remove_tabpage_handler(GtkButton *button, GtkWidget *notebook) {
372     remove_tabpage(GTK_NOTEBOOK(notebook));
373     }
374    
375     /* ������������������������������������������������ */
376     static void append_tabpage(GtkButton *button, GtkNotebook *notebook) {
377     gtk_notebook_append_page(notebook, new_scrolled_text_buffer(), gtk_label_new("*scratch*"));
378     gtk_widget_show_all(GTK_WIDGET(notebook));
379     }
380    
381     /* ������������������������ */
382     static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook ) {
383     gtk_notebook_set_tab_pos(notebook, (notebook->tab_pos + 1) % 4);
384     }
385    
386     /* ������������������������������������������ */
387    
388 aloha 1.3 /* ��������������������� ^npfb */
389 aloha 1.7 static void forward_current_buffer() {
390 aloha 1.3 GtkTextIter p;
391 aloha 1.7 gtk_text_buffer_get_iter_at_mark(current_text_buffer,&p, gtk_text_buffer_get_insert(current_text_buffer));
392 aloha 1.3 gtk_text_iter_forward_char(&p);
393 aloha 1.7 gtk_text_buffer_place_cursor(current_text_buffer, &p);
394 aloha 1.3 }
395 aloha 1.7 static void backward_current_buffer() {
396 aloha 1.3 GtkTextIter p;
397 aloha 1.7 gtk_text_buffer_get_iter_at_mark(current_text_buffer,&p, gtk_text_buffer_get_insert(current_text_buffer));
398 aloha 1.3 gtk_text_iter_backward_char(&p);
399 aloha 1.7 gtk_text_buffer_place_cursor(current_text_buffer, &p);
400 aloha 1.3 }
401 aloha 1.7 static void line_forward_current_buffer() {
402 aloha 1.3 GtkTextIter p;
403 aloha 1.7 gtk_text_buffer_get_iter_at_mark(current_text_buffer, &p, gtk_text_buffer_get_insert(current_text_buffer));
404     gtk_text_view_forward_display_line(current_text_view, &p);
405     gtk_text_buffer_place_cursor(current_text_buffer, &p);
406     }
407     static void line_backward_current_buffer() {
408 aloha 1.3 GtkTextIter p;
409 aloha 1.7 gtk_text_buffer_get_iter_at_mark(current_text_buffer,&p, gtk_text_buffer_get_insert(current_text_buffer));
410     gtk_text_view_backward_display_line(current_text_view, &p);
411     gtk_text_buffer_place_cursor(current_text_buffer, &p);
412 aloha 1.3 }
413    
414 aloha 1.1 /* ��������������������� */
415     static gboolean signal_key_press_handler (GtkWidget *notebook, GdkEventKey *event, gpointer p) {
416     GtkTextIter start, end;
417    
418     /* ������������������������������������ */
419 aloha 1.7 gtk_text_buffer_get_start_iter(current_text_buffer, &start);
420     gtk_text_buffer_get_end_iter(current_text_buffer, &end);
421     gtk_text_buffer_remove_tag_by_name(current_text_buffer, "parent_emphasis_background", &start, &end);
422 aloha 1.1
423 aloha 1.6 if(event->state & GDK_CONTROL_MASK) {
424     switch(event->keyval) {
425     case GDK_f : /* Ctrl + f : forward */
426 aloha 1.7 forward_current_buffer();
427 aloha 1.6 break;
428     case GDK_b : /* Ctrl + b : backward */
429 aloha 1.7 backward_current_buffer();
430 aloha 1.6 break;
431     case GDK_n : /* Ctrl + n : next line */
432 aloha 1.7 line_forward_current_buffer();
433 aloha 1.6 break;
434     case GDK_p : /* Ctrl + p : previous line */
435 aloha 1.7 line_backward_current_buffer();
436 aloha 1.6 break;
437 aloha 1.5
438 aloha 1.6 case GDK_j : /* Ctrl + j : ��������������������� S ������������ */
439     {
440     gchar *code;
441     GtkTextIter start, end;
442    
443     /* ������������������������������ */
444 aloha 1.7 gtk_text_buffer_get_iter_at_mark(current_text_buffer, &end, gtk_text_buffer_get_insert(current_text_buffer));
445 aloha 1.6
446     gtk_text_iter_backward_find_char(&end, is_kokka, NULL, NULL);
447     start = end;
448     gtk_text_iter_forward_char(&end);
449    
450     /* ��������������������������������� S ������������������ */
451     if(!search_sexp_string(&start)) return FALSE;
452    
453 aloha 1.7 code = gtk_text_buffer_get_text(current_text_buffer, &start, &end, FALSE);
454     gtk_text_buffer_insert(current_text_buffer, &end, "\n\n", -1);
455     gtk_text_buffer_insert(current_text_buffer, &end, eval_cstring_by_gauche(code), -1);
456 aloha 1.6 g_free(code);
457     }
458     break;
459 aloha 1.5
460 aloha 1.6 case GDK_t : /* Ctrl + t : ��������������� */
461     gtk_notebook_append_page(GTK_NOTEBOOK(notebook), new_scrolled_text_buffer(), gtk_label_new("*scratch*"));
462     gtk_widget_show_all(GTK_WIDGET(notebook));
463     break;
464 aloha 1.5
465 aloha 1.6 case GDK_k : /* Ctrl + k : ������������������ */
466     remove_tabpage(GTK_NOTEBOOK(notebook));
467     break;
468 aloha 1.4 }
469 aloha 1.1 }
470     return FALSE;
471     }
472    
473     /* ��������������������� */
474     static gboolean signal_key_release_handler (GtkWidget *notebook, GdkEventKey *event, gpointer p) {
475 aloha 1.6 //static gint metakey_pressed = 0;
476     static gint controlx_pressed = 0;
477 aloha 1.1
478     if(event->keyval == GDK_parenright && event->state & GDK_SHIFT_MASK) {
479     GtkTextIter start, end;
480    
481     /* ������������������������������ */
482 aloha 1.7 gtk_text_buffer_get_iter_at_mark(current_text_buffer, &end, gtk_text_buffer_get_insert(current_text_buffer));
483 aloha 1.1
484     start = end;
485     gtk_text_iter_backward_char(&start);
486    
487     /* ��������������������������������� S ������������������ */
488     if(!search_sexp_string(&start)) return FALSE;
489    
490 aloha 1.7 gtk_text_buffer_apply_tag_by_name(current_text_buffer, "parent_emphasis_background", &start, &end);
491 aloha 1.1 }
492    
493     /* ������������������������������������������������������������������������������������������������ (���������������) ������������������ */
494     if(event->keyval == GDK_Return) {
495 aloha 1.7 gint indentWidth = get_parent_nest_level_at_cursor(current_text_buffer) * editor_indent_width;
496 aloha 1.1 gchar *indent = g_strnfill(indentWidth, ' ');
497 aloha 1.7 gtk_text_buffer_insert_at_cursor(current_text_buffer, indent, -1);
498 aloha 1.1 g_free(indent);
499     }
500    
501 aloha 1.6 /* C-x */
502     if(event->keyval == GDK_x && event->state & GDK_CONTROL_MASK) {
503     controlx_pressed++;
504     g_print("C-x ");
505     } else if(event->state & GDK_CONTROL_MASK) {
506     if(controlx_pressed > 0) {
507     switch(event->keyval) {
508     case GDK_c :/* C-x C-c : ������ */
509     g_print("C-c\n");
510     {/* "delete-event" ��������������������������������������� �� ������������������������������������ */
511     GdkEvent ev;
512    
513     ev.any.type = GDK_DELETE;
514     ev.any.window = editor_window->window;
515     ev.any.send_event = FALSE;
516     gdk_event_put (&ev);
517     }
518     break;
519    
520     case GDK_f : /* C-x C-f : ������������������ */
521     g_print("C-f\n");
522     open_file_from_notebook(GTK_NOTEBOOK(notebook));
523     break;
524    
525     case GDK_s : /* C-x C-s : ������������������ */
526     g_print("C-s\n");
527     save_file_from_notebook(GTK_NOTEBOOK(notebook));
528     break;
529    
530     case GDK_w : /* C-x C-w : ������������������������ */
531     g_print("C-w\n");
532     save_file_as_from_notebook(GTK_NOTEBOOK(notebook));
533     break;
534     }
535     controlx_pressed = 0;
536     }
537     }
538 aloha 1.1 return FALSE;
539     }
540    
541     /* ��������������������������������������� */
542     static void editor_window_init() {
543     GtkWidget *vbox, *toolbar, *notebook;
544     GtkToolItem *icon;
545     GtkIconSize iconsize;
546 aloha 1.2 GtkTooltips *toolbar_tips = gtk_tooltips_new();
547 aloha 1.1 /* ��������������������������������������������������������������������������������� */
548     GtkToolItem *oicon, *sicon, *saicon, *eicon;
549    
550     /* ������������ */
551     editor_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
552     g_signal_connect(G_OBJECT(editor_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
553    
554     /* ������������������������������������ */
555     vbox = gtk_vbox_new(FALSE, 0);
556     /* ��������������������� */
557     toolbar = gtk_toolbar_new();
558     gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
559    
560     notebook = gtk_notebook_new();
561     g_signal_connect(G_OBJECT(notebook), "switch-page", GTK_SIGNAL_FUNC(switch_page), NULL);
562    
563     /* ������������������������������������������������ */
564     gtk_toolbar_set_style(GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
565     iconsize = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar));
566    
567     /* ������������������ */
568    
569     /* ������������������ */
570     oicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-open", iconsize), "");
571     /* ������������������������������������������������������������������������������������ */
572     g_signal_connect(G_OBJECT(oicon), "clicked", G_CALLBACK(open_file_handler), G_OBJECT(notebook));
573     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(oicon));
574 aloha 1.2 gtk_tool_item_set_tooltip(oicon, toolbar_tips, "���������������������������",
575     "���������������������������������������������������������������������������������������");
576 aloha 1.1
577     /* ������������������ */
578     sicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-save", iconsize), "");
579     /* ������������������������������������������������������������������������������������ */
580     g_signal_connect(G_OBJECT(sicon), "clicked", G_CALLBACK(save_file_handler), G_OBJECT(notebook));
581     gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(sicon));
582 aloha 1.2 gtk_tool_item_set_tooltip(sicon, toolbar_tips, "������������������������������",
583     "������������������������������������������������������������������������������������������������������������������������������������");
584 aloha 1.1
585     /* ��������������������������� */
586     saicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-save-as", iconsize), "");
587     /* ������������������������������������������������������������������������������������������������������������������ */
588     g_signal_connect(G_OBJECT(saicon), "clicked", G_CALLBACK(save_file_as_handler), G_OBJECT(notebook));
589 aloha 1.2 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(saicon));
590     gtk_tool_item_set_tooltip(saicon, toolbar_tips, "������������������������������������",
591     "");
592 aloha 1.1
593     /* ������������������ */
594     eicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-execute", iconsize), "");
595     /* ��������������������������������� libgauche ������������������ */
596     g_signal_connect(G_OBJECT(eicon), "clicked", G_CALLBACK(buffer_exec_handler), G_OBJECT(notebook));
597     gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(eicon));
598 aloha 1.2 gtk_tool_item_set_tooltip(eicon, toolbar_tips, "��������������� S ���������������������",
599     "Scheme (gauche) ������������������ S ������������������������");
600 aloha 1.1
601     /* ������������������������������������������������ */
602     g_signal_connect(G_OBJECT(notebook), "key-press-event", G_CALLBACK (signal_key_press_handler), NULL);
603     g_signal_connect(G_OBJECT(notebook), "key-release-event", G_CALLBACK (signal_key_release_handler), NULL);
604     gtk_container_add(GTK_CONTAINER(editor_window), vbox);
605     gtk_container_add(GTK_CONTAINER(vbox), notebook);
606    
607     /* ������������������������������������ */
608     gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),
609     new_scrolled_text_buffer(),
610     gtk_label_new("*scratch*"));
611    
612     icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-apply", iconsize), "append");
613     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(tabsborder_on_off), G_OBJECT(notebook));
614     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
615 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "��������� on/off", "");
616 aloha 1.1
617     icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-preferences", iconsize), "append");
618     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(rotate_tab_position), G_OBJECT( notebook));
619     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
620 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������", "");
621 aloha 1.1
622     icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-add", iconsize), "append");
623     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(append_tabpage), G_OBJECT( notebook));
624     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
625 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������", "");
626 aloha 1.1
627     icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-close", iconsize), "remove");
628     g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(remove_tabpage_handler), G_OBJECT( notebook));
629     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
630 aloha 1.2 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������",
631     "���������������������������������������������������������������");
632 aloha 1.1
633 aloha 1.5 gtk_widget_grab_focus(notebook);
634 aloha 1.1 gtk_widget_show_all(editor_window);
635     }
636    
637     int main(int argc, char *argv[]) {
638     /* ������������������������������������ */
639     gtk_set_locale();
640     gtk_init(&argc, &argv);
641     GC_INIT(); Scm_Init(GAUCHE_SIGNATURE);
642     editor_window_init();
643     gtk_main();
644     Scm_Exit(0);
645     return 0;
646     }

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