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.26 - (hide annotations) (download) (as text)
Tue Nov 14 03:27:35 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.25: +24 -22 lines
File MIME type: text/x-csrc
refactoring : notebook -> singleton Shiki_EDITOR_NOTEBOOK

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

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