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.21 - (hide annotations) (download) (as text)
Mon Nov 13 04:48:40 2006 UTC (17 years, 5 months ago) by aloha
Branch: MAIN
Changes since 1.20: +22 -11 lines
File MIME type: text/x-csrc
add open multifile feature on start-up time via command line option

ex) $ ./shiki foo.txt bar.scm hoge.c ....

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

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