From 7fed115ac21ed4918bbd956a170e6862c3ae7a83 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 6 Oct 2010 22:42:13 +0000 Subject: [PATCH] Implemented "Edit->Select all" and "Edit->Unselect all" --- src/callbacks.c | 18 ++++++++++++++++++ src/callbacks.h | 2 ++ src/editor.c | 36 ++++++++++++++++++++++++++++++++++-- src/editor.h | 3 +++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/callbacks.c b/src/callbacks.c index dd78294..2bbc894 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -152,6 +152,24 @@ static void _preferences_on_ok(gpointer data) } +/* on_edit_select_all */ +void on_edit_select_all(gpointer data) +{ + Editor * editor = data; + + editor_select_all(editor); +} + + +/* on_edit_unselect_all */ +void on_edit_unselect_all(gpointer data) +{ + Editor * editor = data; + + editor_unselect_all(editor); +} + + /* on_file_close */ void on_file_close(gpointer data) { diff --git a/src/callbacks.h b/src/callbacks.h index 2633f20..d1af6a1 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -25,6 +25,8 @@ gboolean on_closex(gpointer data); void on_edit_find(gpointer data); void on_edit_preferences(gpointer data); +void on_edit_select_all(gpointer data); +void on_edit_unselect_all(gpointer data); void on_file_close(gpointer data); void on_file_new(gpointer data); void on_file_open(gpointer data); diff --git a/src/editor.c b/src/editor.c index 39ed528..d4c1a2e 100644 --- a/src/editor.c +++ b/src/editor.c @@ -73,14 +73,14 @@ static DesktopMenu _editor_menu_edit[] = { N_("_Copy"), NULL, GTK_STOCK_COPY, 0, 0 }, /* FIXME implement */ { N_("_Paste"), NULL, GTK_STOCK_PASTE, 0, 0 }, /* FIXME implement */ { "", NULL, NULL, 0, 0 }, - { N_("_Select all"), NULL, /* FIXME implement */ + { N_("_Select all"), G_CALLBACK(on_edit_select_all), #if GTK_CHECK_VERSION(2, 10, 0) GTK_STOCK_SELECT_ALL, #else "edit-select-all", #endif GDK_CONTROL_MASK, GDK_A }, - { N_("_Unselect all"), NULL, NULL, 0, 0 }, /* FIXME implement */ + { N_("_Unselect all"), G_CALLBACK(on_edit_unselect_all), NULL, 0, 0 }, { "", NULL, NULL, 0, 0 }, { N_("_Find"), G_CALLBACK(on_edit_find), GTK_STOCK_FIND, GDK_CONTROL_MASK, GDK_F }, @@ -585,6 +585,38 @@ gboolean editor_save_as_dialog(Editor * editor) } +/* editor_select_all */ +void editor_select_all(Editor * editor) +{ +#if GTK_CHECK_VERSION(2, 4, 0) + GtkTextBuffer * tbuf; + GtkTextIter start; + GtkTextIter end; + + tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(editor->view)); + gtk_text_buffer_get_start_iter(tbuf, &start); + gtk_text_buffer_get_end_iter(tbuf, &end); + gtk_text_buffer_select_range(tbuf, &start, &end); +#endif +} + + +/* editor_unselect_all */ +void editor_unselect_all(Editor * editor) +{ +#if GTK_CHECK_VERSION(2, 4, 0) + GtkTextBuffer * tbuf; + GtkTextMark * mark; + GtkTextIter iter; + + tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(editor->view)); + mark = gtk_text_buffer_get_mark(tbuf, "insert"); + gtk_text_buffer_get_iter_at_mark(tbuf, &iter, mark); + gtk_text_buffer_select_range(tbuf, &iter, &iter); +#endif +} + + /* private */ /* functions */ /* editor_find */ diff --git a/src/editor.h b/src/editor.h index 55fcce2..2b50c49 100644 --- a/src/editor.h +++ b/src/editor.h @@ -66,6 +66,9 @@ gboolean editor_save(Editor * editor); gboolean editor_save_as(Editor * editor, char const * filename); gboolean editor_save_as_dialog(Editor * editor); +void editor_select_all(Editor * editor); +void editor_unselect_all(Editor * editor); + void editor_find(Editor * editor, char const * text); #endif /* !EDITOR_EDITOR_H */