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.20 - (hide annotations) (download) (as text)
Sun Nov 12 12:46:34 2006 UTC (17 years, 5 months ago) by aloha
Branch: MAIN
Changes since 1.19: +17 -8 lines
File MIME type: text/x-csrc
fixed bug (to not be able to delete a last tab) and fixed warning (managed delete event handler for tab in decent way)

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.20 * $Id: shiki.c,v 1.19 2006/11/12 09:38:40 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.17 /* ��������������������������������������������� */
35 aloha 1.16 typedef struct {
36 aloha 1.20 GtkScrolledWindow *tabpage; /* ������ */
37     gchar *tabpage_label; /* ��������� (���������������) ������ */
38     GtkTextView *text_view; /* ��������������� */
39     GtkTextBuffer *text_buffer; /* ��������������������������������� */
40     gchar *filename; /* ������������������������������ */
41     ScmObj env; /* ��������������������������� Scheme ������ */
42     guint delete_handler_id; /* ��������������������������������������������� ID */
43 aloha 1.16 } ShikiTabInfo;
44    
45 aloha 1.17 /* ������������������������������������������������������������������������������������������������������������������������������ */
46 aloha 1.16 struct {
47 aloha 1.17 GtkWidget *editor_window;
48     GtkWidget *statusbar;
49     GtkWidget *modeline_label;
50     GList *tabInfoList;
51     gint current_tabpage_num;
52     ShikiTabInfo *current_tabpage_info;
53 aloha 1.16 } shiki_editor;
54    
55     #define Shiki_EDITOR_WINDOW shiki_editor.editor_window
56     #define Shiki_EDITOR_STATUSBAR shiki_editor.statusbar
57     #define Shiki_EDITOR_MODELINE_LABEL shiki_editor.modeline_label
58 aloha 1.17 #define Shiki_EDITOR_TAB_INFO_LIST shiki_editor.tabInfoList
59 aloha 1.16 #define Shiki_CURRENT_TAB_NUM shiki_editor.current_tabpage_num
60     #define Shiki_CURRENT_TAB_INFO shiki_editor.current_tabpage_info
61 aloha 1.17 #define Shiki_CURRENT_TAB (shiki_editor.current_tabpage_info)->tabpage
62     #define Shiki_CURRENT_TAB_TITLE (shiki_editor.current_tabpage_info)->tabpage_label
63     #define Shiki_CURRENT_TEXT_VIEW (shiki_editor.current_tabpage_info)->text_view
64     #define Shiki_CURRENT_TEXT_BUFFER (shiki_editor.current_tabpage_info)->text_buffer
65     #define Shiki_CURRENT_FILENAME (shiki_editor.current_tabpage_info)->filename
66 aloha 1.16 #define Shiki_CURRENT_SCHEME_ENV (shiki_editor.current_tabpage_info)->env
67 aloha 1.10
68 aloha 1.17 /* ������������������ */
69     static void clear_current_buffer();
70     static void load_buffer_by_gauche();
71     static void load_scheme_file_by_gauche(GtkNotebook *notebook);
72 aloha 1.14 static gchar *load_cstring_by_gauche(gchar *s);
73 aloha 1.17 static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog);
74     static void select_font();
75     static void about_this_application();
76     static gint get_current_line_number(GtkTextBuffer *buffer);
77     static void update_modeline_label();
78     static void text_buffer_cursor_moved_handler();
79     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer);
80     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer);
81     static gchar *get_filename_from_dialog(const gchar *msg);
82     static void save_file_from_notebook(GtkNotebook *notebook);
83     static void save_file_handler(GtkWidget *widget, GtkWidget *notebook);
84     static void save_file_as_from_notebook(GtkNotebook *notebook);
85     static void save_file_as_handler(GtkWidget *widget, GtkWidget *notebook);
86     static void really_quit_dialog_yes(GtkWidget *widget, gboolean *flag);
87     static void really_quit_dialog_no(GtkWidget *widget, gint *flag);
88     static gboolean not_yet_save_changes_really_quit(GtkTextBuffer *buffer);
89 aloha 1.18 static gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, GtkWidget *buffer);
90     static void append_tabpage(GtkNotebook *notebook, gchar *filename);
91 aloha 1.17 static GtkWidget *new_scrolled_text_buffer(ShikiTabInfo **tabinfo);
92     static void open_file_from_notebook(GtkNotebook *notebook);
93     static void open_file_handler(GtkWidget *widget, GtkWidget *notebook);
94     static gchar *eval_cstring_by_gauche(gchar *s);
95     static void load_region_handler(GtkWidget *widget, GtkWidget *notebook);
96     static gboolean is_kakko_or_kokka(gunichar ch, gpointer);
97     static gboolean is_kokka(gunichar ch, gpointer);
98     static gboolean search_sexp_string(GtkTextIter *start);
99     static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer);
100 aloha 1.18 static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) ;
101 aloha 1.17 static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook);
102     static void remove_tabpage(GtkNotebook *notebook);
103     static void remove_tabpage_handler(GtkButton *button, GtkWidget *notebook);
104 aloha 1.18 static void append_tabpage_handler(GtkButton *button, GtkNotebook *notebook);
105 aloha 1.17 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook);
106     static void forward_current_buffer();
107     static void backward_current_buffer();
108     static void line_forward_current_buffer();
109     static void line_backward_current_buffer();
110     static gboolean signal_key_press_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid);
111     static gboolean signal_key_release_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid);
112     static void shiki_editor_window_init();
113 aloha 1.14
114 aloha 1.15 /* ������������������������������ */
115     static void clear_current_buffer() {
116     GtkTextIter start, end;
117 aloha 1.16 gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &start);
118     gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &end);
119     gtk_text_buffer_delete(Shiki_CURRENT_TEXT_BUFFER, &start, &end);
120 aloha 1.15 }
121    
122 aloha 1.14 /* ������������������������������������ */
123     static void load_buffer_by_gauche() {
124     GtkTextIter p;
125 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
126     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
127     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(get_all_buffer_contents(Shiki_CURRENT_TEXT_BUFFER)), -1);
128 aloha 1.14 }
129    
130     /* ������������������������ */
131     static void load_scheme_file_by_gauche(GtkNotebook *notebook) {
132     gchar *contents, *text;
133     gsize br, bw, len;
134     GError *err = NULL;
135     gchar *filename = get_filename_from_dialog("File Selection");
136     GtkTextIter p;
137    
138     if(!filename) return;
139    
140 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
141     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
142 aloha 1.14
143     if(g_file_get_contents(filename, &contents, &len, NULL)) {
144     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
145 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(text), -1);
146 aloha 1.14 else
147 aloha 1.16 gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(contents), -1);
148 aloha 1.14 }
149     g_free(text); g_free(contents); g_free(filename);
150     }
151    
152 aloha 1.13 /* gauche ������������������������������������ */
153     static gchar *load_cstring_by_gauche(gchar *s) {
154     gchar *msg;
155    
156     ScmObj result, error;
157     /* ��������������������������������� */
158     ScmObj is = Scm_MakeInputStringPort(SCM_STRING(SCM_MAKE_STR(s)), TRUE);
159     /* ������������������������������ */
160     ScmObj os = Scm_MakeOutputStringPort(TRUE);
161    
162     Scm_Define(Scm_UserModule(), SCM_SYMBOL(SCM_INTERN("*input*")), is);
163     Scm_Define(Scm_UserModule(), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
164     /* Scheme ��������������������������������������������������������������������������������� S ��������������������������������������������������������������������������� *error* ������������������ */
165     result = Scm_EvalCString("(guard (e (else (set! *error* e) #f)) (eval (load-from-port *input*) (current-module)))", SCM_OBJ(Scm_UserModule()));
166    
167     error = Scm_GlobalVariableRef(Scm_UserModule(), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
168    
169     /* ��������������������������������������������������������� */
170     if (!SCM_FALSEP(error))
171     Scm_Write(error, os, SCM_WRITE_DISPLAY);
172     else
173     Scm_Write(result, os, SCM_WRITE_DISPLAY);
174    
175     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
176     /* ������������������ */
177     Scm_ClosePort(SCM_PORT(is));
178     Scm_ClosePort(SCM_PORT(os));
179    
180     return msg;
181     }
182    
183 aloha 1.12 static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog) {
184     gchar *font_name = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (font_dialog));
185     if(font_name) {
186     GtkRcStyle *style = gtk_rc_style_new ();
187     pango_font_description_free(style->font_desc);
188     style->font_desc = pango_font_description_from_string(font_name);
189 aloha 1.16 gtk_widget_modify_style (GTK_WIDGET(Shiki_CURRENT_TEXT_VIEW), style);
190 aloha 1.12 g_free (font_name);
191     }
192     }
193    
194 aloha 1.14 /* ������������������������������������������������������ */
195 aloha 1.12 static void select_font(){
196     GtkWidget *font_dialog = gtk_font_selection_dialog_new("Font Selection Dialog");
197     g_signal_connect (GTK_FONT_SELECTION_DIALOG (font_dialog)->ok_button, "clicked", G_CALLBACK(font_selection_ok), font_dialog);
198     gtk_dialog_run(GTK_DIALOG(font_dialog));
199     gtk_widget_destroy(font_dialog);
200     }
201    
202 aloha 1.11 /* ������������������������������������������ */
203     static void about_this_application() {
204     GtkAboutDialog *about = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
205     const gchar *authors[] = {
206     "������������ (���������) <alohakun@gmail.com>"
207     };
208     gtk_about_dialog_set_authors(about, authors);
209     gtk_about_dialog_set_copyright(about, "Copyright(C)2006 WAKATSUKI Toshihiro");
210     gtk_about_dialog_set_name(about, "��� (SHIKI)");
211     gtk_about_dialog_set_website_label(about, "���������30������������������������������������������������������������Blog");
212     gtk_about_dialog_set_website(about, "http://alohakun.blog7.fc2.com/blog-category-29.html");
213     gtk_dialog_run(GTK_DIALOG(about));
214     gtk_widget_destroy(GTK_WIDGET(about));
215     }
216    
217 aloha 1.10 /* ��������������������������������������������������������������� */
218     static gint get_current_line_number(GtkTextBuffer *b) {
219     GtkTextIter p;
220     gtk_text_buffer_get_iter_at_mark(b, &p, gtk_text_buffer_get_insert(b));
221     return gtk_text_iter_get_line(&p) + 1;
222     }
223    
224     /* ��������������������������������������������������������������� */
225     static void update_modeline_label() {
226 aloha 1.16 gchar* basename = g_path_get_basename(Shiki_CURRENT_TAB_TITLE);
227 aloha 1.11 gchar* l = g_strdup_printf("-E:%s %-10s (Gauche Interaction)--L%d--------------------------------------",
228 aloha 1.16 gtk_text_buffer_get_modified(Shiki_CURRENT_TEXT_BUFFER) ? "**" : "--",
229     basename, get_current_line_number(Shiki_CURRENT_TEXT_BUFFER));
230     gtk_label_set_text(GTK_LABEL(Shiki_EDITOR_MODELINE_LABEL), l);
231 aloha 1.10 g_free(l); g_free(basename);
232     }
233    
234     static void text_buffer_cursor_moved_handler(){
235     update_modeline_label();
236     }
237 aloha 1.1
238     /* ��������������������������������������������������������������� */
239     static gchar* get_all_buffer_contents(GtkTextBuffer *buffer) {
240     GtkTextIter start, end;
241     gtk_text_buffer_get_start_iter(buffer, &start);
242     gtk_text_buffer_get_end_iter(buffer, &end);
243     return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
244     }
245    
246     /* buffer ������������������������ filename ��������� */
247     static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer) {
248     gchar *contents, *text;
249     gsize br, bw;
250     GError *err = NULL;
251    
252     if(!filename) return FALSE;
253     contents = get_all_buffer_contents(buffer);
254     text = g_locale_from_utf8(contents, -1, &br, &bw, &err);
255     /* ��������������������������������� */
256     g_file_set_contents(filename, text, -1, NULL);
257     gtk_text_buffer_set_modified(buffer, FALSE);
258 aloha 1.10 update_modeline_label();
259 aloha 1.1 g_free(contents); g_free(text);
260     return TRUE;
261     }
262    
263     /* ������������������������������������������������������msg ������������������������������������ */
264     static gchar *get_filename_from_dialog(const gchar *msg) {
265    
266     GtkWidget *dialog = gtk_file_selection_new(msg);
267     int resp = gtk_dialog_run(GTK_DIALOG(dialog));
268     gchar *filename = NULL;
269    
270     /* gtk_file_selection_get_filename ������������������������������������������������������������������������������������������������������������������������������ */
271     if(resp == GTK_RESPONSE_OK)
272     filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog)));
273    
274     gtk_widget_destroy(dialog);
275     return filename;
276     }
277    
278     /* ��������������������������������������������������������������������� */
279     static void save_file_from_notebook(GtkNotebook *notebook) {
280    
281     /* ������������������������������������ */
282 aloha 1.16 if(!gtk_text_buffer_get_modified(Shiki_CURRENT_TEXT_BUFFER)) return;
283 aloha 1.1
284     /* ������������������������������������������������������������������������������������������������������ */
285 aloha 1.16 if(g_ascii_strcasecmp("*scratch*", Shiki_CURRENT_TAB_TITLE) == 0) {
286 aloha 1.7 gchar *filename = get_filename_from_dialog("Save File As ...");
287     if(!filename) return;
288 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
289     gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
290     gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), filename);
291 aloha 1.1 g_free(filename);
292     } else
293 aloha 1.16 save_text_buffer(Shiki_CURRENT_TAB_TITLE, Shiki_CURRENT_TEXT_BUFFER);
294 aloha 1.1 }
295    
296     /* ��������������������������������������������������� */
297     static void save_file_handler(GtkWidget *widget, GtkWidget *notebook) {
298     save_file_from_notebook(GTK_NOTEBOOK(notebook));
299     }
300    
301     /* ��������������������������������������������������������������������������� */
302     static void save_file_as_from_notebook(GtkNotebook *notebook) {
303     gchar *filename = get_filename_from_dialog("Save File As ...");
304    
305 aloha 1.7 if(!filename) return;
306 aloha 1.16 if(!save_text_buffer(filename, Shiki_CURRENT_TEXT_BUFFER)) return;
307 aloha 1.1
308 aloha 1.16 gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(Shiki_CURRENT_TAB), filename);
309     gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
310 aloha 1.1
311     g_free(filename);
312     }
313    
314     /* ��������������������������������������������������������� */
315     static void save_file_as_handler(GtkWidget *widget, GtkWidget *notebook) {
316     save_file_as_from_notebook(GTK_NOTEBOOK(notebook));
317     }
318    
319     /* YES ������������NO ������������������������������������ callback */
320 aloha 1.17 static void really_quit_dialog_yes(GtkWidget *widget, gboolean *flag){*flag = FALSE;}
321     static void really_quit_dialog_no(GtkWidget *widget, gint *flag){*flag = TRUE;}
322 aloha 1.1
323     /* ��������������������������������������������� ? */
324 aloha 1.17 static gboolean not_yet_save_changes_really_quit(GtkTextBuffer *buffer) {
325 aloha 1.1 GtkWidget *yes_button, *no_button;
326     static GtkWidget *dialog_window = NULL;
327    
328     /* ��������������������������������������� */
329     if(!gtk_text_buffer_get_modified(buffer)) return FALSE;
330    
331     if(dialog_window == NULL) {
332     gboolean flag = TRUE;
333     dialog_window = gtk_dialog_new ();
334    
335     /* ��������������������������������������������� ? ��������������������������� */
336     g_signal_connect(G_OBJECT(dialog_window), "delete_event", G_CALLBACK(gtk_false), NULL);
337     g_signal_connect(G_OBJECT(dialog_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
338 aloha 1.5 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->vbox),
339     gtk_label_new("������������������������������������������\n��������������������������������������� ?"), TRUE, TRUE, 0);
340 aloha 1.1 gtk_window_set_title(GTK_WINDOW (dialog_window), "Really Quit ?");
341     /* YES ������������ */
342 aloha 1.8 yes_button = gtk_button_new_with_mnemonic("������ (_Y)");
343 aloha 1.1 g_signal_connect(GTK_OBJECT(yes_button), "clicked", G_CALLBACK(really_quit_dialog_yes), &flag);
344     g_signal_connect_swapped(GTK_OBJECT(yes_button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(dialog_window));
345     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), yes_button, TRUE, TRUE, 0);
346    
347     /* NO ������������ */
348 aloha 1.8 no_button = gtk_button_new_with_mnemonic("��������� (_N)");
349 aloha 1.1 g_signal_connect(GTK_OBJECT(no_button), "clicked", G_CALLBACK(really_quit_dialog_no), &flag);
350     g_signal_connect_swapped(GTK_OBJECT(no_button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(dialog_window));
351     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), no_button, TRUE, TRUE, 0);
352    
353     gtk_window_set_modal(GTK_WINDOW(dialog_window), TRUE);
354 aloha 1.16 gtk_window_set_transient_for(GTK_WINDOW(dialog_window), GTK_WINDOW (Shiki_EDITOR_WINDOW));
355 aloha 1.1
356     gtk_widget_show_all(dialog_window);
357     gtk_main ();
358     dialog_window = NULL;
359    
360     /* "delete_event" ��������������� FALSE ���������"destory" ������������������window ������������������ */
361     return flag;
362     }
363     return TRUE;
364     }
365    
366     /* ������������������������������������������������������������������������������������������ */
367 aloha 1.18 static gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, GtkWidget *buffer){
368     return not_yet_save_changes_really_quit(GTK_TEXT_BUFFER(buffer));
369 aloha 1.1 }
370    
371 aloha 1.17 /* ������������������������ */
372     static GtkWidget *new_scrolled_text_buffer(ShikiTabInfo **tabinfo) {
373 aloha 1.1
374 aloha 1.17 /* ������������������������������������������ */
375     *tabinfo = g_malloc(sizeof(ShikiTabInfo));
376 aloha 1.1
377     /* ������������������������������������ */
378 aloha 1.17 (*tabinfo)->tabpage = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
379     gtk_scrolled_window_set_policy ((*tabinfo)->tabpage, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
380 aloha 1.1
381     /* ������������������������������������������������ */
382 aloha 1.17 (*tabinfo)->text_view = GTK_TEXT_VIEW(gtk_text_view_new());
383     (*tabinfo)->text_buffer = gtk_text_view_get_buffer((*tabinfo)->text_view);
384     gtk_container_add(GTK_CONTAINER((*tabinfo)->tabpage), GTK_WIDGET((*tabinfo)->text_view));
385     gtk_widget_set_size_request(GTK_WIDGET((*tabinfo)->text_view), 500, 600);
386     g_signal_connect((*tabinfo)->text_buffer, "mark_set", G_CALLBACK(text_buffer_cursor_moved_handler), (*tabinfo)->text_view);
387 aloha 1.20 /* ������������������������������������������������������������������������������������������������������ */
388     (*tabinfo)->delete_handler_id = g_signal_connect(Shiki_EDITOR_WINDOW, "delete_event", G_CALLBACK(delete_event_handler), (*tabinfo)->text_buffer);
389 aloha 1.1 /* ������������������������ */
390     /* ������������������������������������������������ */
391 aloha 1.17 gtk_text_buffer_create_tag ((*tabinfo)->text_buffer, "parent_emphasis_background", "background", "green", NULL);
392 aloha 1.1
393 aloha 1.17 return GTK_WIDGET((*tabinfo)->tabpage);
394 aloha 1.1 }
395    
396     /* ��������������������� */
397     static void open_file_from_notebook(GtkNotebook *notebook) {
398     gchar *contents, *text;
399     gsize br, bw, len;
400     GError *err = NULL;
401     gchar *filename = get_filename_from_dialog("File Selection");
402    
403     if(!filename) return;
404    
405     if(g_file_get_contents(filename, &contents, &len, NULL)) {
406     GtkTextIter p;
407 aloha 1.3
408 aloha 1.1 /* ������������������������������ */
409 aloha 1.18 append_tabpage(notebook, g_strdup(filename));
410 aloha 1.1
411     if(!(text = g_locale_to_utf8(contents, -1, &br, &bw, &err)))
412 aloha 1.17 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER, contents, len);
413 aloha 1.1 else
414 aloha 1.17 gtk_text_buffer_set_text(Shiki_CURRENT_TEXT_BUFFER, text, len);
415 aloha 1.1
416     /* ������������������������ */
417 aloha 1.17 gtk_text_buffer_set_modified(Shiki_CURRENT_TEXT_BUFFER, FALSE);
418 aloha 1.1 /* ������������������������������ */
419 aloha 1.17 gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
420     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
421 aloha 1.10 update_modeline_label();
422 aloha 1.16 gtk_window_set_title (GTK_WINDOW (Shiki_EDITOR_WINDOW), filename);
423 aloha 1.1 gtk_widget_show_all(GTK_WIDGET(notebook));
424     g_free(contents); g_free(text); g_free(filename);
425     } else
426     g_printerr("Get file contents error !\n");
427     }
428    
429     /* ��������������������������������������������� */
430     static void open_file_handler(GtkWidget *widget, GtkWidget *notebook) {
431     open_file_from_notebook(GTK_NOTEBOOK(notebook));
432     }
433    
434     /* gauche ��������������������������������� */
435     static gchar *eval_cstring_by_gauche(gchar *s) {
436     gchar *msg;
437    
438     ScmObj result, error;
439     /* ������������������������������ */
440     ScmObj os = Scm_MakeOutputStringPort(TRUE);
441    
442     /* Scheme ��������������������������������������� */
443     /* http://alohakun.blog7.fc2.com/blog-entry-517.html */
444     Scm_Define(Scm_UserModule(), SCM_SYMBOL(SCM_INTERN("*input*")), SCM_MAKE_STR(s));
445     Scm_Define(Scm_UserModule(), SCM_SYMBOL(SCM_INTERN("*error*")), SCM_FALSE);
446    
447     result = Scm_EvalCString("(guard (e (else (set! *error* e) #f)) (eval (read-from-string *input*) (current-module)))", SCM_OBJ(Scm_UserModule()));
448    
449     error = Scm_GlobalVariableRef(Scm_UserModule(), SCM_SYMBOL(SCM_INTERN("*error*")), 0);
450    
451     /* ��������������������������������������������������������� */
452     if (!SCM_FALSEP(error))
453     Scm_Write(error, os, SCM_WRITE_DISPLAY);
454     else
455     Scm_Write(result, os, SCM_WRITE_DISPLAY);
456    
457     msg = Scm_GetString(SCM_STRING(Scm_GetOutputString(SCM_PORT(os))));
458     /* ������������������ */
459     Scm_ClosePort(SCM_PORT(os));
460    
461     return msg;
462     }
463    
464 aloha 1.13 /* ������������������������������������������������������������������ S ��������������� (������������) */
465 aloha 1.14 static void load_region_handler(GtkWidget *widget, GtkWidget *notebook) {
466 aloha 1.1
467     GtkTextIter start, end, p;
468     gchar *code;
469 aloha 1.16 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
470     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, "\n\n", -1);
471 aloha 1.1
472     /* ������������������������������������������������������������ */
473 aloha 1.16 if(gtk_text_buffer_get_selection_bounds(Shiki_CURRENT_TEXT_BUFFER, &start, &end)) {
474     code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
475     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &p, load_cstring_by_gauche(code), -1);
476 aloha 1.1 g_free(code);
477     }
478     }
479    
480     // GtkTextCharPredicate
481     static gboolean is_kakko_or_kokka(gunichar ch, gpointer p) {
482     return ch == '(' || ch == ')';
483     }
484     static gboolean is_kokka(gunichar ch, gpointer p) {return ch == ')';}
485    
486    
487     /* ')' ��������������� '(' ������������������ (S ���) ��������������� */
488     static gboolean search_sexp_string(GtkTextIter *start) {
489     gint nest_level = 0;
490     /* ��������������������������������� S ������������������ */
491     while(1) {
492     if(!gtk_text_iter_backward_find_char(start, is_kakko_or_kokka, NULL, NULL))
493     return FALSE;
494    
495     if(gtk_text_iter_get_char(start) == ')')
496     nest_level++;
497     else {
498     if(!nest_level)
499     break;
500     else
501     nest_level--;
502     }
503     }
504     return TRUE;
505     }
506    
507     /* ������������������������������������������������ */
508     static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer) {
509     gint nest_level = 0;
510     GtkTextIter start, end;
511     gtk_text_buffer_get_start_iter(buffer, &start);
512     if(gtk_text_iter_get_char(&start) == '(') nest_level++;
513    
514     /* ��������������������� (= end) ��������� */
515     gtk_text_buffer_get_iter_at_mark(buffer,&end, gtk_text_buffer_get_insert(buffer));
516    
517     while(1) {
518     /* end ������ '(' ��� ')' ��������������������������������������������� */
519     if(!gtk_text_iter_forward_find_char(&start, is_kakko_or_kokka, NULL, &end))
520     return nest_level;
521    
522     if(gtk_text_iter_get_char(&start) == '(')
523     nest_level++;
524     else
525     nest_level--;
526     }
527     }
528    
529     /* ������������������������������������������������������������ */
530 aloha 1.18 static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) {
531 aloha 1.17 /* ��������������������������������������������������������������������� */
532     Shiki_CURRENT_TAB_INFO = (ShikiTabInfo *)g_list_nth_data(Shiki_EDITOR_TAB_INFO_LIST, pagenum);
533     /* ������������������������������������ */
534 aloha 1.16 Shiki_CURRENT_TAB_NUM = pagenum;
535 aloha 1.7
536 aloha 1.1 /* ������������������������������������������������������ */
537 aloha 1.17 if(!Shiki_CURRENT_TAB_INFO) return;
538     gtk_window_set_title (GTK_WINDOW(Shiki_EDITOR_WINDOW), Shiki_CURRENT_FILENAME);
539 aloha 1.10
540     update_modeline_label();
541 aloha 1.1 }
542    
543     /* ��������������������������������� on/off */
544     static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook) {
545     gint tval = FALSE;
546     gint bval = FALSE;
547     if(notebook->show_tabs == FALSE)
548     tval = TRUE;
549     if(notebook->show_border == FALSE)
550     bval = TRUE;
551    
552     gtk_notebook_set_show_tabs(notebook, tval);
553     gtk_notebook_set_show_border(notebook, bval);
554     }
555    
556     /* ������������������������������������������ */
557     static void remove_tabpage(GtkNotebook *notebook) {
558 aloha 1.20 /* ��������� 1 ��������������������������������������������������� */
559     if(g_list_length(Shiki_EDITOR_TAB_INFO_LIST) == 1)
560     return;
561 aloha 1.16 if(!not_yet_save_changes_really_quit(Shiki_CURRENT_TEXT_BUFFER)) {
562 aloha 1.20 /* ��������������������������������������������������������������������������������������������� */
563     g_signal_handler_disconnect(Shiki_EDITOR_WINDOW, (Shiki_CURRENT_TAB_INFO)->delete_handler_id);
564     /* ������������������������ */
565     gtk_widget_destroy(GTK_WIDGET(Shiki_CURRENT_TEXT_VIEW));
566 aloha 1.18 /* ������������������������������������������ */
567     g_free(Shiki_CURRENT_TAB_TITLE);
568     g_free(Shiki_CURRENT_FILENAME);
569 aloha 1.17 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));
570 aloha 1.18
571     /* ������������������������������������ */
572     Shiki_CURRENT_TAB_INFO = g_list_nth_data(Shiki_EDITOR_TAB_INFO_LIST, Shiki_CURRENT_TAB_NUM);
573 aloha 1.16 gtk_notebook_remove_page(notebook, Shiki_CURRENT_TAB_NUM);
574 aloha 1.1 /* ��������������������������������������� */
575     gtk_widget_queue_draw(GTK_WIDGET(notebook));
576     }
577     }
578    
579     static void remove_tabpage_handler(GtkButton *button, GtkWidget *notebook) {
580     remove_tabpage(GTK_NOTEBOOK(notebook));
581     }
582    
583 aloha 1.17 /* ��������������������������������������� */
584 aloha 1.18 static void append_tabpage(GtkNotebook *notebook, gchar *filename) {
585 aloha 1.17 ShikiTabInfo *tabinfo;
586     GtkWidget *tabpage = new_scrolled_text_buffer(&tabinfo);
587     tabinfo->filename = filename;
588     tabinfo->tabpage_label = g_path_get_basename(filename);
589 aloha 1.18 gtk_notebook_append_page(notebook, tabpage, gtk_label_new(tabinfo->tabpage_label));
590     Shiki_EDITOR_TAB_INFO_LIST = g_list_append(Shiki_EDITOR_TAB_INFO_LIST, tabinfo);
591     gtk_notebook_set_current_page(notebook, g_list_length(Shiki_EDITOR_TAB_INFO_LIST) - 1);
592 aloha 1.1 gtk_widget_show_all(GTK_WIDGET(notebook));
593 aloha 1.19 gtk_notebook_set_current_page(notebook, Shiki_CURRENT_TAB_NUM);
594 aloha 1.1 }
595    
596 aloha 1.18 static void append_tabpage_handler(GtkButton *button, GtkNotebook *notebook) {
597     append_tabpage(notebook, g_strdup("*scratch*"));
598 aloha 1.17 }
599    
600 aloha 1.1 /* ������������������������ */
601 aloha 1.17 static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook ) {
602 aloha 1.1 gtk_notebook_set_tab_pos(notebook, (notebook->tab_pos + 1) % 4);
603     }
604    
605     /* ������������������������������������������ */
606    
607 aloha 1.3 /* ��������������������� ^npfb */
608 aloha 1.7 static void forward_current_buffer() {
609 aloha 1.3 GtkTextIter p;
610 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
611 aloha 1.3 gtk_text_iter_forward_char(&p);
612 aloha 1.16 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
613 aloha 1.3 }
614 aloha 1.7 static void backward_current_buffer() {
615 aloha 1.3 GtkTextIter p;
616 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
617 aloha 1.3 gtk_text_iter_backward_char(&p);
618 aloha 1.16 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
619 aloha 1.3 }
620 aloha 1.7 static void line_forward_current_buffer() {
621 aloha 1.3 GtkTextIter p;
622 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
623     gtk_text_view_forward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
624     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
625 aloha 1.7 }
626     static void line_backward_current_buffer() {
627 aloha 1.3 GtkTextIter p;
628 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
629     gtk_text_view_backward_display_line(Shiki_CURRENT_TEXT_VIEW, &p);
630     gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
631 aloha 1.3 }
632    
633 aloha 1.1 /* ��������������������� */
634 aloha 1.8 static gboolean signal_key_press_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
635 aloha 1.1 GtkTextIter start, end;
636    
637     /* ������������������������������������ */
638 aloha 1.16 gtk_text_buffer_get_start_iter(Shiki_CURRENT_TEXT_BUFFER, &start);
639     gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &end);
640     gtk_text_buffer_remove_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
641 aloha 1.1
642 aloha 1.6 if(event->state & GDK_CONTROL_MASK) {
643     switch(event->keyval) {
644     case GDK_f : /* Ctrl + f : forward */
645 aloha 1.7 forward_current_buffer();
646 aloha 1.6 break;
647     case GDK_b : /* Ctrl + b : backward */
648 aloha 1.7 backward_current_buffer();
649 aloha 1.6 break;
650     case GDK_n : /* Ctrl + n : next line */
651 aloha 1.7 line_forward_current_buffer();
652 aloha 1.6 break;
653     case GDK_p : /* Ctrl + p : previous line */
654 aloha 1.7 line_backward_current_buffer();
655 aloha 1.6 break;
656 aloha 1.5
657 aloha 1.6 case GDK_j : /* Ctrl + j : ��������������������� S ������������ */
658     {
659     gchar *code;
660     GtkTextIter start, end;
661    
662     /* ������������������������������ */
663 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
664 aloha 1.6
665     gtk_text_iter_backward_find_char(&end, is_kokka, NULL, NULL);
666     start = end;
667     gtk_text_iter_forward_char(&end);
668    
669     /* ��������������������������������� S ������������������ */
670     if(!search_sexp_string(&start)) return FALSE;
671    
672 aloha 1.16 code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE);
673     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, "\n\n", -1);
674     gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, eval_cstring_by_gauche(code), -1);
675 aloha 1.6 g_free(code);
676     }
677     break;
678 aloha 1.5
679 aloha 1.6 case GDK_t : /* Ctrl + t : ��������������� */
680 aloha 1.18 append_tabpage(GTK_NOTEBOOK(notebook), g_strdup("*scratch*"));
681 aloha 1.6 break;
682 aloha 1.5
683 aloha 1.6 case GDK_k : /* Ctrl + k : ������������������ */
684     remove_tabpage(GTK_NOTEBOOK(notebook));
685     break;
686 aloha 1.4 }
687 aloha 1.1 }
688     return FALSE;
689     }
690    
691     /* ��������������������� */
692 aloha 1.8 static gboolean signal_key_release_handler (GtkWidget *notebook, GdkEventKey *event, gpointer contextid) {
693     static gint metakey_pressed = 0;
694 aloha 1.6 static gint controlx_pressed = 0;
695 aloha 1.1
696     if(event->keyval == GDK_parenright && event->state & GDK_SHIFT_MASK) {
697     GtkTextIter start, end;
698    
699     /* ������������������������������ */
700 aloha 1.16 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER, &end, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
701 aloha 1.1
702     start = end;
703     gtk_text_iter_backward_char(&start);
704    
705     /* ��������������������������������� S ������������������ */
706     if(!search_sexp_string(&start)) return FALSE;
707    
708 aloha 1.16 gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end);
709 aloha 1.1 }
710    
711     /* ������������������������������������������������������������������������������������������������ (���������������) ������������������ */
712     if(event->keyval == GDK_Return) {
713 aloha 1.16 gint indentWidth = get_parent_nest_level_at_cursor(Shiki_CURRENT_TEXT_BUFFER) * editor_indent_width;
714 aloha 1.1 gchar *indent = g_strnfill(indentWidth, ' ');
715 aloha 1.16 gtk_text_buffer_insert_at_cursor(Shiki_CURRENT_TEXT_BUFFER, indent, -1);
716 aloha 1.1 g_free(indent);
717     }
718    
719 aloha 1.6 /* C-x */
720     if(event->keyval == GDK_x && event->state & GDK_CONTROL_MASK) {
721     controlx_pressed++;
722 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-x -");
723 aloha 1.6 } else if(event->state & GDK_CONTROL_MASK) {
724 aloha 1.8
725 aloha 1.6 if(controlx_pressed > 0) {
726     switch(event->keyval) {
727     case GDK_c :/* C-x C-c : ������ */
728 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-c");
729 aloha 1.6 {/* "delete-event" ��������������������������������������� �� ������������������������������������ */
730     GdkEvent ev;
731    
732     ev.any.type = GDK_DELETE;
733 aloha 1.16 ev.any.window = Shiki_EDITOR_WINDOW->window;
734 aloha 1.6 ev.any.send_event = FALSE;
735     gdk_event_put (&ev);
736     }
737     break;
738    
739     case GDK_f : /* C-x C-f : ������������������ */
740 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-f");
741 aloha 1.6 open_file_from_notebook(GTK_NOTEBOOK(notebook));
742     break;
743    
744     case GDK_s : /* C-x C-s : ������������������ */
745 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-s");
746 aloha 1.6 save_file_from_notebook(GTK_NOTEBOOK(notebook));
747     break;
748    
749     case GDK_w : /* C-x C-w : ������������������������ */
750 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "C-w");
751 aloha 1.6 save_file_as_from_notebook(GTK_NOTEBOOK(notebook));
752     break;
753     }
754     controlx_pressed = 0;
755     }
756 aloha 1.8
757     switch(event->keyval) {
758     case GDK_g :/* C-g : ��������������� */
759     metakey_pressed = 0;
760     controlx_pressed = 0;
761    
762 aloha 1.16 gtk_statusbar_push(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), GPOINTER_TO_INT(contextid), "Quit");
763 aloha 1.8 break;
764     }
765    
766 aloha 1.6 }
767 aloha 1.1 return FALSE;
768     }
769    
770     /* ��������������������������������������� */
771 aloha 1.16 static void shiki_editor_window_init() {
772 aloha 1.1 GtkWidget *vbox, *toolbar, *notebook;
773     GtkToolItem *icon;
774     GtkIconSize iconsize;
775 aloha 1.2 GtkTooltips *toolbar_tips = gtk_tooltips_new();
776 aloha 1.1 /* ��������������������������������������������������������������������������������� */
777     GtkToolItem *oicon, *sicon, *saicon, *eicon;
778    
779 aloha 1.8 gint contextid;
780    
781 aloha 1.1 /* ������������ */
782 aloha 1.16 Shiki_EDITOR_WINDOW = gtk_window_new(GTK_WINDOW_TOPLEVEL);
783     g_signal_connect(G_OBJECT(Shiki_EDITOR_WINDOW), "destroy", G_CALLBACK(gtk_main_quit), NULL);
784 aloha 1.1
785     /* ������������������������������������ */
786     vbox = gtk_vbox_new(FALSE, 0);
787     /* ��������������������� */
788     toolbar = gtk_toolbar_new();
789     gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
790    
791     notebook = gtk_notebook_new();
792 aloha 1.18 g_signal_connect(G_OBJECT(notebook), "switch-page", GTK_SIGNAL_FUNC(switch_tabpage_handler), NULL);
793 aloha 1.1
794     /* ������������������������������������������������ */
795     gtk_toolbar_set_style(GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
796     iconsize = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar));
797    
798     /* ������������������ */
799    
800     /* ������������������ */
801     oicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-open", iconsize), "");
802     /* ������������������������������������������������������������������������������������ */
803     g_signal_connect(G_OBJECT(oicon), "clicked", G_CALLBACK(open_file_handler), G_OBJECT(notebook));
804     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(oicon));
805 aloha 1.2 gtk_tool_item_set_tooltip(oicon, toolbar_tips, "���������������������������",
806     "���������������������������������������������������������������������������������������");
807 aloha 1.1
808     /* ������������������ */
809     sicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-save", iconsize), "");
810     /* ������������������������������������������������������������������������������������ */
811     g_signal_connect(G_OBJECT(sicon), "clicked", G_CALLBACK(save_file_handler), G_OBJECT(notebook));
812     gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(sicon));
813 aloha 1.2 gtk_tool_item_set_tooltip(sicon, toolbar_tips, "������������������������������",
814     "������������������������������������������������������������������������������������������������������������������������������������");
815 aloha 1.1
816     /* ��������������������������� */
817     saicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-save-as", iconsize), "");
818     /* ������������������������������������������������������������������������������������������������������������������ */
819     g_signal_connect(G_OBJECT(saicon), "clicked", G_CALLBACK(save_file_as_handler), G_OBJECT(notebook));
820 aloha 1.2 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(saicon));
821     gtk_tool_item_set_tooltip(saicon, toolbar_tips, "������������������������������������",
822     "");
823 aloha 1.1
824     /* ������������������ */
825     eicon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-execute", iconsize), "");
826 aloha 1.14 /* ������������������������������������������ libgauche ������������������ */
827     g_signal_connect(G_OBJECT(eicon), "clicked", G_CALLBACK(load_region_handler), G_OBJECT(notebook));
828 aloha 1.1 gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET(eicon));
829 aloha 1.14 gtk_tool_item_set_tooltip(eicon, toolbar_tips, "��������������� S ������������������������ (load-region-lisp)",
830 aloha 1.2 "Scheme (gauche) ������������������ S ������������������������");
831 aloha 1.1
832 aloha 1.16 gtk_container_add(GTK_CONTAINER(Shiki_EDITOR_WINDOW), vbox);
833 aloha 1.1 gtk_container_add(GTK_CONTAINER(vbox), notebook);
834    
835 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-apply", iconsize), "");
836 aloha 1.1 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(tabsborder_on_off), G_OBJECT(notebook));
837     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
838 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "��������� on/off", "");
839 aloha 1.1
840 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-preferences", iconsize), "");
841 aloha 1.15 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(rotate_tab_position), G_OBJECT(notebook));
842 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
843 aloha 1.14 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
844 aloha 1.1
845 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-add", iconsize), "");
846 aloha 1.18 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(append_tabpage_handler), G_OBJECT(notebook));
847 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
848 aloha 1.6 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������", "");
849 aloha 1.1
850 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-delete", iconsize), "");
851 aloha 1.15 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(clear_current_buffer), G_OBJECT(notebook));
852     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
853     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������������",
854     "���������������������������������������������������������������������");
855    
856 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-close", iconsize), "");
857 aloha 1.15 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(remove_tabpage_handler), G_OBJECT(notebook));
858 aloha 1.1 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
859 aloha 1.2 gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������������",
860     "���������������������������������������������������������������");
861 aloha 1.15
862 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-bold", iconsize), "");
863 aloha 1.12 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(select_font), NULL);
864     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
865     gtk_tool_item_set_tooltip(icon, toolbar_tips, "���������������������", "");
866 aloha 1.1
867 aloha 1.18 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-connect", iconsize), "");
868 aloha 1.15 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_scheme_file_by_gauche), G_OBJECT(notebook));
869 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
870     gtk_tool_item_set_tooltip(icon, toolbar_tips, "Scheme ������������������������", "");
871    
872 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-convert", iconsize), "");
873 aloha 1.15 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(load_buffer_by_gauche), G_OBJECT(notebook));
874 aloha 1.14 gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
875     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������", "");
876    
877 aloha 1.17 icon = gtk_tool_button_new(gtk_image_new_from_stock ("gtk-dialog-info", iconsize), "");
878 aloha 1.11 g_signal_connect(G_OBJECT(icon), "clicked", G_CALLBACK(about_this_application), NULL);
879     gtk_container_add(GTK_CONTAINER (toolbar), GTK_WIDGET(icon));
880     gtk_tool_item_set_tooltip(icon, toolbar_tips, "������������������������������������������", "");
881    
882 aloha 1.16 gtk_box_pack_start(GTK_BOX(vbox), Shiki_EDITOR_MODELINE_LABEL = gtk_label_new("-E:** *scratch* (Gauche Interaction)--L1--All---------------------------------"), TRUE, TRUE, 0);
883 aloha 1.12
884 aloha 1.8 /* C-x C-s ��������������������������������������������������������������������������������������� */
885 aloha 1.16 Shiki_EDITOR_STATUSBAR = gtk_statusbar_new();
886     gtk_box_pack_start(GTK_BOX(vbox), Shiki_EDITOR_STATUSBAR, TRUE, TRUE, 0);
887     contextid = gtk_statusbar_get_context_id(GTK_STATUSBAR(Shiki_EDITOR_STATUSBAR), "");
888 aloha 1.8
889     /* ������������������������������������������������ */
890     g_signal_connect(G_OBJECT(notebook), "key-press-event", G_CALLBACK (signal_key_press_handler), GINT_TO_POINTER(contextid));
891     g_signal_connect(G_OBJECT(notebook), "key-release-event", G_CALLBACK (signal_key_release_handler), GINT_TO_POINTER(contextid));
892 aloha 1.12
893 aloha 1.10 /* ������������������������������������ */
894 aloha 1.18 append_tabpage(GTK_NOTEBOOK(notebook), g_strdup("*scratch*"));
895 aloha 1.8
896 aloha 1.5 gtk_widget_grab_focus(notebook);
897 aloha 1.16 gtk_widget_show_all(Shiki_EDITOR_WINDOW);
898 aloha 1.1 }
899    
900     int main(int argc, char *argv[]) {
901     /* ������������������������������������ */
902     gtk_set_locale();
903     gtk_init(&argc, &argv);
904     GC_INIT(); Scm_Init(GAUCHE_SIGNATURE);
905 aloha 1.16 shiki_editor_window_init();
906 aloha 1.1 gtk_main();
907     Scm_Exit(0);
908     return 0;
909     }

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