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.18 - (hide annotations) (download) (as text)
Sun Nov 12 07:21:49 2006 UTC (17 years, 5 months ago) by aloha
Branch: MAIN
Changes since 1.17: +27 -24 lines
File MIME type: text/x-csrc
bug fixed (page switch related), and change page-add style prepend to append (again)

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

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