| 52 |
ShikiTabInfo *current_tabpage_info; |
ShikiTabInfo *current_tabpage_info; |
| 53 |
} shiki_editor; |
} shiki_editor; |
| 54 |
|
|
| 55 |
|
/* シングルトンオブジェクトの定義 */ |
| 56 |
|
/* TODO : GtkNoteBook もここに入れるのが望ましいと思う… |
| 57 |
|
* ノートブックは,どう考えても,一つのプロセスに一つだよなぁ… |
| 58 |
|
* そもそも TAB_INFO_LIST が入っちゃってるのに |
| 59 |
|
* そうすれば,一気に全体的に API が簡素になるはず */ |
| 60 |
#define Shiki_EDITOR_WINDOW shiki_editor.editor_window |
#define Shiki_EDITOR_WINDOW shiki_editor.editor_window |
| 61 |
#define Shiki_EDITOR_STATUSBAR shiki_editor.statusbar |
#define Shiki_EDITOR_STATUSBAR shiki_editor.statusbar |
| 62 |
#define Shiki_EDITOR_MODELINE_LABEL shiki_editor.modeline_label |
#define Shiki_EDITOR_MODELINE_LABEL shiki_editor.modeline_label |
| 63 |
#define Shiki_EDITOR_TAB_INFO_LIST shiki_editor.tabInfoList |
#define Shiki_EDITOR_TAB_INFO_LIST shiki_editor.tabInfoList |
| 64 |
|
|
| 65 |
|
/* 現在表示されているタブに対するアクセス用各種キャッシュ情報 */ |
| 66 |
#define Shiki_CURRENT_TAB_NUM shiki_editor.current_tabpage_num |
#define Shiki_CURRENT_TAB_NUM shiki_editor.current_tabpage_num |
| 67 |
#define Shiki_CURRENT_TAB_INFO shiki_editor.current_tabpage_info |
#define Shiki_CURRENT_TAB_INFO shiki_editor.current_tabpage_info |
| 68 |
#define Shiki_CURRENT_TAB (shiki_editor.current_tabpage_info)->tabpage |
#define Shiki_CURRENT_TAB (shiki_editor.current_tabpage_info)->tabpage |
| 73 |
#define Shiki_CURRENT_SCHEME_ENV (shiki_editor.current_tabpage_info)->env |
#define Shiki_CURRENT_SCHEME_ENV (shiki_editor.current_tabpage_info)->env |
| 74 |
|
|
| 75 |
/* プロトタイプ */ |
/* プロトタイプ */ |
| 76 |
static void clear_current_buffer(); |
|
| 77 |
static void load_buffer_by_gauche(); |
/* ファイル関係 */ |
| 78 |
static void load_scheme_file_by_gauche(GtkNotebook *notebook); |
static void open_file(GtkNotebook *notebook, gchar *filename); |
| 79 |
static gchar *load_cstring_by_gauche(gchar *s); |
static void open_file_from_notebook(GtkNotebook *notebook); |
| 80 |
static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog); |
static void open_file_handler(GtkWidget *widget, GtkWidget *notebook); |
|
static void select_font(); |
|
|
static void about_this_application(); |
|
|
static gint get_current_line_number(GtkTextBuffer *buffer); |
|
|
static void update_modeline_label(); |
|
|
static void text_buffer_cursor_moved_handler(); |
|
|
static gchar* get_all_buffer_contents(GtkTextBuffer *buffer); |
|
|
static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer); |
|
|
static gchar *get_filename_from_dialog(const gchar *msg); |
|
| 81 |
static void save_file_from_notebook(GtkNotebook *notebook); |
static void save_file_from_notebook(GtkNotebook *notebook); |
| 82 |
static void save_file_handler(GtkWidget *widget, GtkWidget *notebook); |
static void save_file_handler(GtkWidget *widget, GtkWidget *notebook); |
| 83 |
static void save_file_as_from_notebook(GtkNotebook *notebook); |
static void save_file_as_from_notebook(GtkNotebook *notebook); |
| 84 |
static void save_file_as_handler(GtkWidget *widget, GtkWidget *notebook); |
static void save_file_as_handler(GtkWidget *widget, GtkWidget *notebook); |
| 85 |
|
static gchar *get_filename_from_dialog(const gchar *msg); |
| 86 |
|
|
| 87 |
|
/* テキストバッファ関係 */ |
| 88 |
|
static gchar* get_all_buffer_contents(GtkTextBuffer *buffer); |
| 89 |
|
static gboolean save_text_buffer(const gchar *filename, GtkTextBuffer *buffer); |
| 90 |
|
static void clear_current_buffer(); |
| 91 |
|
|
| 92 |
|
/* モードライン */ |
| 93 |
|
static gint get_current_line_number(GtkTextBuffer *buffer); |
| 94 |
|
static void update_modeline_label(); |
| 95 |
|
static void text_buffer_cursor_moved_handler(); |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
/* 確認 */ |
| 99 |
static void really_quit_dialog_yes(GtkWidget *widget, gboolean *flag); |
static void really_quit_dialog_yes(GtkWidget *widget, gboolean *flag); |
| 100 |
static void really_quit_dialog_no(GtkWidget *widget, gint *flag); |
static void really_quit_dialog_no(GtkWidget *widget, gint *flag); |
| 101 |
static gboolean not_yet_save_changes_really_quit(GtkTextBuffer *buffer); |
static gboolean not_yet_save_changes_really_quit(GtkTextBuffer *buffer); |
| 102 |
static gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, GtkWidget *buffer); |
static gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, GtkWidget *buffer); |
| 103 |
static void open_file(GtkNotebook *notebook, gchar *filename); |
|
| 104 |
static void open_file_from_notebook(GtkNotebook *notebook); |
/* Gauche と S 式操作やインデント関連 */ |
|
static void open_file_handler(GtkWidget *widget, GtkWidget *notebook); |
|
| 105 |
static gchar *eval_cstring_by_gauche(gchar *s); |
static gchar *eval_cstring_by_gauche(gchar *s); |
| 106 |
|
static gchar *load_cstring_by_gauche(gchar *s); |
| 107 |
|
static void load_buffer_by_gauche(); |
| 108 |
static void load_region_handler(GtkWidget *widget, GtkWidget *notebook); |
static void load_region_handler(GtkWidget *widget, GtkWidget *notebook); |
| 109 |
|
static void load_scheme_file_by_gauche(GtkNotebook *notebook); |
| 110 |
static gboolean is_kakko_or_kokka(gunichar ch, gpointer); |
static gboolean is_kakko_or_kokka(gunichar ch, gpointer); |
| 111 |
static gboolean is_kokka(gunichar ch, gpointer); |
static gboolean is_kokka(gunichar ch, gpointer); |
| 112 |
static gboolean search_sexp_string(GtkTextIter *start); |
static gboolean search_last_sexp_string(GtkTextIter *start); |
| 113 |
static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer); |
static gint get_parent_nest_level_at_cursor(GtkTextBuffer *buffer); |
| 114 |
|
|
| 115 |
|
/* 設定 */ |
| 116 |
|
static void select_font(); |
| 117 |
|
static void font_selection_ok(GtkWidget *button, GtkWidget *font_dialog); |
| 118 |
static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) ; |
static void switch_tabpage_handler(GtkNotebook *notebook, GtkNotebookPage *page, guint pagenum) ; |
| 119 |
static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook); |
static void tabsborder_on_off(GtkButton *button, GtkNotebook *notebook); |
|
static void remove_tabpage_handler(GtkButton *button, GtkWidget *notebook); |
|
|
static void append_tabpage_handler(GtkButton *button, GtkNotebook *notebook); |
|
| 120 |
static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook); |
static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook); |
| 121 |
|
|
| 122 |
|
/* バッファ内 ↑↓←→ 移動 */ |
| 123 |
static void forward_current_buffer(); |
static void forward_current_buffer(); |
| 124 |
static void backward_current_buffer(); |
static void backward_current_buffer(); |
| 125 |
static void line_forward_current_buffer(); |
static void line_forward_current_buffer(); |
| 126 |
static void line_backward_current_buffer(); |
static void line_backward_current_buffer(); |
| 127 |
|
|
| 128 |
|
/* キーバインド全般 */ |
| 129 |
static gboolean signal_key_press_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid); |
static gboolean signal_key_press_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid); |
| 130 |
static gboolean signal_key_release_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid); |
static gboolean signal_key_release_handler(GtkWidget *notebook, GdkEventKey *event, gpointer contextid); |
| 131 |
|
|
| 132 |
|
/* ヘルプや情報 */ |
| 133 |
static void open_online_help(GtkNotebook *notebook); |
static void open_online_help(GtkNotebook *notebook); |
| 134 |
static void online_help_handler(GtkWidget *button, GtkNotebook *notebook); |
static void online_help_handler(GtkWidget *button, GtkNotebook *notebook); |
| 135 |
|
static void about_this_application(); |
| 136 |
|
|
| 137 |
|
/* 初期化 */ |
| 138 |
static void shiki_editor_window_init(int argc, char **argv); |
static void shiki_editor_window_init(int argc, char **argv); |
| 139 |
|
|
| 140 |
|
|
| 142 |
static void append_tabpage(GtkNotebook *notebook, gchar *filename); |
static void append_tabpage(GtkNotebook *notebook, gchar *filename); |
| 143 |
static void remove_tabpage(GtkNotebook *notebook); |
static void remove_tabpage(GtkNotebook *notebook); |
| 144 |
|
|
| 145 |
|
/* 基本的に *_handler は,上記したような関数を呼び出すだけのイベントハンドラのためのラッパー */ |
| 146 |
|
static void append_tabpage_handler(GtkButton *button, GtkNotebook *notebook); |
| 147 |
|
static void remove_tabpage_handler(GtkButton *button, GtkNotebook *notebook); |
| 148 |
|
|
| 149 |
/* ノートブックにタブとページ (バッファ) を追加 */ |
/* ノートブックにタブとページ (バッファ) を追加 */ |
| 150 |
static void append_tabpage(GtkNotebook *notebook, gchar *filename) { |
static void append_tabpage(GtkNotebook *notebook, gchar *filename) { |
| 151 |
/*-------------------- 新しいタブを作る ----------------------------------*/ |
/*-------------------- 新しいタブを作る ----------------------------------*/ |
| 161 |
/* 枠の中に格納するテキストビューワと,テキストバッファを作る */ |
/* 枠の中に格納するテキストビューワと,テキストバッファを作る */ |
| 162 |
tabinfo->text_view = GTK_TEXT_VIEW(gtk_text_view_new()); |
tabinfo->text_view = GTK_TEXT_VIEW(gtk_text_view_new()); |
| 163 |
tabinfo->text_buffer = gtk_text_view_get_buffer(tabinfo->text_view); |
tabinfo->text_buffer = gtk_text_view_get_buffer(tabinfo->text_view); |
| 164 |
|
|
| 165 |
gtk_container_add(GTK_CONTAINER(tabinfo->tabpage), GTK_WIDGET(tabinfo->text_view)); |
gtk_container_add(GTK_CONTAINER(tabinfo->tabpage), GTK_WIDGET(tabinfo->text_view)); |
| 166 |
gtk_widget_set_size_request(GTK_WIDGET(tabinfo->text_view), 500, 500); |
gtk_widget_set_size_request(GTK_WIDGET(tabinfo->text_view), 500, 500); |
| 167 |
g_signal_connect(tabinfo->text_buffer, "mark_set", G_CALLBACK(text_buffer_cursor_moved_handler), tabinfo->text_view); |
g_signal_connect(tabinfo->text_buffer, "mark_set", G_CALLBACK(text_buffer_cursor_moved_handler), tabinfo->text_view); |
| 168 |
|
|
| 169 |
/* タブを削除する際,デリートハンドラを削除しておかないと警告が出るから */ |
/* タブを削除する際,デリートハンドラを削除しておかないと警告が出るから */ |
| 170 |
tabinfo->delete_handler_id = g_signal_connect(Shiki_EDITOR_WINDOW, "delete_event", G_CALLBACK(delete_event_handler), tabinfo->text_buffer); |
tabinfo->delete_handler_id = g_signal_connect(Shiki_EDITOR_WINDOW, "delete_event", G_CALLBACK(delete_event_handler), tabinfo->text_buffer); |
| 171 |
|
|
| 172 |
/* 様々な初期化処理 */ |
/* 様々な初期化処理 */ |
| 173 |
/* 括弧の強調表示のためのタグを作る */ |
/* 括弧の強調表示のためのタグを作る */ |
| 174 |
gtk_text_buffer_create_tag (tabinfo->text_buffer, "parent_emphasis_background", "background", "green", NULL); |
gtk_text_buffer_create_tag (tabinfo->text_buffer, "parent_emphasis_background", "background", "green", NULL); |
| 206 |
} |
} |
| 207 |
} |
} |
| 208 |
|
|
| 209 |
|
static void remove_tabpage_handler(GtkButton *button, GtkNotebook *notebook) { |
| 210 |
|
remove_tabpage(notebook); |
| 211 |
|
} |
| 212 |
|
|
| 213 |
|
static void append_tabpage_handler(GtkButton *button, GtkNotebook *notebook) { |
| 214 |
|
append_tabpage(notebook, g_strdup("*scratch*")); |
| 215 |
|
} |
| 216 |
|
|
| 217 |
/* バッファの内容を消去 */ |
/* バッファの内容を消去 */ |
| 218 |
static void clear_current_buffer() { |
static void clear_current_buffer() { |
| 573 |
|
|
| 574 |
|
|
| 575 |
/* ')' に対応する '(' までの文字列 (S 式) を切り出す */ |
/* ')' に対応する '(' までの文字列 (S 式) を切り出す */ |
| 576 |
static gboolean search_sexp_string(GtkTextIter *start) { |
static gboolean search_last_sexp_string(GtkTextIter *start) { |
| 577 |
gint nest_level = 0; |
gint nest_level = 0; |
| 578 |
/* カーソル位置の前にある S 式を切り出す */ |
/* カーソル位置の前にある S 式を切り出す */ |
| 579 |
while(1) { |
while(1) { |
| 641 |
gtk_notebook_set_show_border(notebook, bval); |
gtk_notebook_set_show_border(notebook, bval); |
| 642 |
} |
} |
| 643 |
|
|
|
static void remove_tabpage_handler(GtkButton *button, GtkWidget *notebook) { |
|
|
remove_tabpage(GTK_NOTEBOOK(notebook)); |
|
|
} |
|
|
|
|
|
static void append_tabpage_handler(GtkButton *button, GtkNotebook *notebook) { |
|
|
append_tabpage(notebook, g_strdup("*scratch*")); |
|
|
} |
|
|
|
|
| 644 |
/* タブの位置を調整 */ |
/* タブの位置を調整 */ |
| 645 |
static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook ) { |
static void rotate_tab_position(GtkButton *button, GtkNotebook *notebook ) { |
| 646 |
gtk_notebook_set_tab_pos(notebook, (notebook->tab_pos + 1) % 4); |
gtk_notebook_set_tab_pos(notebook, (notebook->tab_pos + 1) % 4); |
| 711 |
gtk_text_iter_forward_char(&end); |
gtk_text_iter_forward_char(&end); |
| 712 |
|
|
| 713 |
/* カーソル位置の前にある S 式を切り出す */ |
/* カーソル位置の前にある S 式を切り出す */ |
| 714 |
if(!search_sexp_string(&start)) return FALSE; |
if(!search_last_sexp_string(&start)) return FALSE; |
| 715 |
|
|
| 716 |
code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE); |
code = gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &start, &end, FALSE); |
| 717 |
gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, "\n\n", -1); |
gtk_text_buffer_insert(Shiki_CURRENT_TEXT_BUFFER, &end, "\n\n", -1); |
| 747 |
gtk_text_iter_backward_char(&start); |
gtk_text_iter_backward_char(&start); |
| 748 |
|
|
| 749 |
/* カーソル位置の前にある S 式を切り出す */ |
/* カーソル位置の前にある S 式を切り出す */ |
| 750 |
if(!search_sexp_string(&start)) return FALSE; |
if(!search_last_sexp_string(&start)) return FALSE; |
| 751 |
|
|
| 752 |
gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end); |
gtk_text_buffer_apply_tag_by_name(Shiki_CURRENT_TEXT_BUFFER, "parent_emphasis_background", &start, &end); |
| 753 |
} |
} |