diff --git a/moo/mooedit/Makefile.incl b/moo/mooedit/Makefile.incl index cc6c42c6..25dbb7e9 100644 --- a/moo/mooedit/Makefile.incl +++ b/moo/mooedit/Makefile.incl @@ -47,7 +47,8 @@ mooedit_noinst_headers = \ $(mooedit)/mootextfind.h \ $(mooedit)/mootextgotoline-glade.h \ $(mooedit)/mootextbtree.h \ - $(mooedit)/mootextview-private.h + $(mooedit)/mootextview-private.h \ + $(mooedit)/quicksearch-glade.h mooedit_sources = \ $(mooedit_include_headers) \ @@ -87,6 +88,7 @@ mooedit_gtk_2_10_sources = \ $(mooedit)/mootextprint.h mooedit_built_sources = \ + $(mooedit)/quicksearch-glade.h \ $(mooedit)/mootextgotoline-glade.h \ $(mooedit)/mootextfind-glade.h \ $(mooedit)/moopluginprefs-glade.h \ @@ -99,31 +101,30 @@ $(mooedit)/mootextgotoline-glade.h: $(mooedit_srcdir)/glade/mootextgotoline.glad mkdir -p $(mooedit) sh $(XML2H) MOO_TEXT_GOTO_LINE_GLADE_UI $(mooedit_srcdir)/glade/mootextgotoline.glade \ > $(mooedit)/mootextgotoline-glade.h - $(mooedit)/mootextfind-glade.h: $(mooedit_srcdir)/glade/mootextfind.glade $(XML2H) mkdir -p $(mooedit) sh $(XML2H) MOO_TEXT_FIND_GLADE_UI $(mooedit_srcdir)/glade/mootextfind.glade \ > $(mooedit)/mootextfind-glade.h - $(mooedit)/mooeditprefs-glade.h: $(mooedit_srcdir)/glade/mooeditprefs.glade $(XML2H) mkdir -p $(mooedit) sh $(XML2H) MOO_EDIT_PREFS_GLADE_UI $(mooedit_srcdir)/glade/mooeditprefs.glade \ > $(mooedit)/mooeditprefs-glade.h - $(mooedit)/mooeditcolorsprefs-glade.h: $(mooedit_srcdir)/glade/mooeditcolorsprefs.glade $(XML2H) mkdir -p $(mooedit) sh $(XML2H) MOO_EDIT_COLORS_PREFS_GLADE_UI $(mooedit_srcdir)/glade/mooeditcolorsprefs.glade \ > $(mooedit)/mooeditcolorsprefs-glade.h - $(mooedit)/moopluginprefs-glade.h: $(mooedit_srcdir)/glade/moopluginprefs.glade $(XML2H) mkdir -p $(mooedit) sh $(XML2H) MOO_PLUGIN_PREFS_GLADE_UI $(mooedit_srcdir)/glade/moopluginprefs.glade \ > $(mooedit)/moopluginprefs-glade.h - $(mooedit)/mooeditsavemultiple-glade.h: $(mooedit_srcdir)/glade/mooeditsavemult.glade $(XML2H) mkdir -p $(mooedit) sh $(XML2H) MOO_EDIT_SAVE_MULTIPLE_GLADE_UI $(mooedit_srcdir)/glade/mooeditsavemult.glade \ > $(mooedit)/mooeditsavemultiple-glade.h +$(mooedit)/quicksearch-glade.h: $(mooedit_srcdir)/glade/quicksearch.glade $(XML2H) + mkdir -p $(mooedit) + sh $(XML2H) QUICK_SEARCH_GLADE_XML $(mooedit_srcdir)/glade/quicksearch.glade \ + > $(mooedit)/quicksearch-glade.h if GTK_2_10 mooedit_sources += $(mooedit_gtk_2_10_sources) diff --git a/moo/mooedit/glade/Makefile.incl b/moo/mooedit/glade/Makefile.incl index 0d90caa6..554a5819 100644 --- a/moo/mooedit/glade/Makefile.incl +++ b/moo/mooedit/glade/Makefile.incl @@ -5,6 +5,7 @@ mooedit_glade = $(mooedit)/glade moo_extra_dist += \ + $(mooedit_glade)/quicksearch.glade \ $(mooedit_glade)/mootextgotoline.glade \ $(mooedit_glade)/mootextfind.glade \ $(mooedit_glade)/mooeditprefs.glade \ diff --git a/moo/mooedit/glade/quicksearch.glade b/moo/mooedit/glade/quicksearch.glade new file mode 100644 index 00000000..a2c8f53f --- /dev/null +++ b/moo/mooedit/glade/quicksearch.glade @@ -0,0 +1,203 @@ + + + + + + + True + window1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + + + + True + False + 0 + + + + True + False + 0 + + + + + + + + + + + + + + + 0 + True + True + + + + + + True + True + False + + + + True + 0 + 0.5 + GTK_SHADOW_ETCHED_IN + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 0 + 0 + + + + True + False + 0 + + + + True + True + True + True + 0 + + True + * + False + + + 0 + True + True + + + + + + True + True + _Case sensitive + True + GTK_RELIEF_NORMAL + False + False + False + True + + + 0 + False + False + + + + + + True + True + _Regular expression + True + GTK_RELIEF_NORMAL + False + False + False + True + + + 0 + False + False + + + + + + True + True + False + + + + + + + 0 + True + True + GTK_PACK_END + + + + + + + + + + + + + + + 0 + False + False + + + + + + True + False + 0 + + + + + + + + + + + + + + + 0 + True + True + + + + + + + diff --git a/moo/mooedit/mooeditinput.c b/moo/mooedit/mooeditinput.c index 204aaff2..e0fd3508 100644 --- a/moo/mooedit/mooeditinput.c +++ b/moo/mooedit/mooeditinput.c @@ -951,7 +951,7 @@ _moo_text_view_key_press_event (GtkWidget *widget, buffer = MOO_TEXT_BUFFER (gtk_text_view_get_buffer (text_view)); /* ignore key events from the search entry */ - if (view->priv->in_search) + if (view->priv->qs.in_search) return FALSE; if (!mods) diff --git a/moo/mooedit/mooeditprefs.c b/moo/mooedit/mooeditprefs.c index 951af6f1..07f7833d 100644 --- a/moo/mooedit/mooeditprefs.c +++ b/moo/mooedit/mooeditprefs.c @@ -43,11 +43,12 @@ const char *moo_edit_setting (const char *setting_name) } -#define NEW_KEY_BOOL(s,v) moo_prefs_new_key_bool (MOO_EDIT_PREFS_PREFIX "/" s, v) -#define NEW_KEY_INT(s,v) moo_prefs_new_key_int (MOO_EDIT_PREFS_PREFIX "/" s, v) -#define NEW_KEY_STRING(s,v) moo_prefs_new_key_string (MOO_EDIT_PREFS_PREFIX "/" s, v) -#define NEW_KEY_COLOR(s,v) moo_prefs_new_key_color (MOO_EDIT_PREFS_PREFIX "/" s, v) -#define NEW_KEY_ENUM(s,t,v) moo_prefs_new_key_enum (MOO_EDIT_PREFS_PREFIX "/" s, t, v) +#define NEW_KEY_BOOL(s,v) moo_prefs_new_key_bool (MOO_EDIT_PREFS_PREFIX "/" s, v) +#define NEW_KEY_INT(s,v) moo_prefs_new_key_int (MOO_EDIT_PREFS_PREFIX "/" s, v) +#define NEW_KEY_STRING(s,v) moo_prefs_new_key_string (MOO_EDIT_PREFS_PREFIX "/" s, v) +#define NEW_KEY_COLOR(s,v) moo_prefs_new_key_color (MOO_EDIT_PREFS_PREFIX "/" s, v) +#define NEW_KEY_ENUM(s,t,v) moo_prefs_new_key_enum (MOO_EDIT_PREFS_PREFIX "/" s, t, v) +#define NEW_KEY_FLAGS(s,t,v) moo_prefs_new_key_flags (MOO_EDIT_PREFS_PREFIX "/" s, t, v) void _moo_edit_init_settings (void) @@ -81,6 +82,9 @@ _moo_edit_init_settings (void) NEW_KEY_BOOL (MOO_EDIT_PREFS_SHOW_TRAILING_SPACES, FALSE); /* XXX does it work? */ NEW_KEY_BOOL (MOO_EDIT_PREFS_USE_DEFAULT_FONT, TRUE); NEW_KEY_STRING (MOO_EDIT_PREFS_FONT, "Monospace 12"); + NEW_KEY_FLAGS (MOO_EDIT_PREFS_QUICK_SEARCH_FLAGS, + MOO_TYPE_TEXT_SEARCH_FLAGS, + MOO_TEXT_SEARCH_CASELESS); // NEW_KEY_BOOL (MOO_EDIT_PREFS_SEARCH_SELECTED, FALSE); // NEW_KEY_BOOL (MOO_EDIT_PREFS_AUTO_INDENT, FALSE); @@ -97,6 +101,7 @@ _moo_edit_init_settings (void) #define get_int(key) moo_prefs_get_int (MOO_EDIT_PREFS_PREFIX "/" key) #define get_color(key) moo_prefs_get_color (MOO_EDIT_PREFS_PREFIX "/" key) #define get_enum(key) moo_prefs_get_enum (MOO_EDIT_PREFS_PREFIX "/" key) +#define get_flags(key) moo_prefs_get_flags (MOO_EDIT_PREFS_PREFIX "/" key) void _moo_edit_apply_settings (MooEdit *edit) @@ -118,6 +123,7 @@ _moo_edit_apply_settings (MooEdit *edit) "show-line-numbers", get_bool (MOO_EDIT_PREFS_SHOW_LINE_NUMBERS), "draw-tabs", get_bool (MOO_EDIT_PREFS_SHOW_TABS), "draw-trailing-spaces", get_bool (MOO_EDIT_PREFS_SHOW_TRAILING_SPACES), + "quick-search-flags", get_flags (MOO_EDIT_PREFS_QUICK_SEARCH_FLAGS), NULL); if (get_bool (MOO_EDIT_PREFS_WRAP_ENABLE)) diff --git a/moo/mooedit/mooeditprefs.h b/moo/mooedit/mooeditprefs.h index b1f09942..619579a8 100644 --- a/moo/mooedit/mooeditprefs.h +++ b/moo/mooedit/mooeditprefs.h @@ -56,6 +56,8 @@ const char *moo_edit_setting (const char *setting_name); #define MOO_EDIT_PREFS_DIALOGS_OPEN "dialogs/open" // #define MOO_EDIT_PREFS_SEARCH_SELECTED "search/search_selected" +#define MOO_EDIT_PREFS_QUICK_SEARCH_FLAGS "quick_search_flags" + // // #define MOO_EDIT_PREFS_ON_EXTERNAL_CHANGES "on_external_changes" // #define MOO_EDIT_PREFS_TABS_WIDTH "tabs_width" diff --git a/moo/mooedit/mootextview-private.h b/moo/mooedit/mootextview-private.h index ec0efda8..cb607c6d 100644 --- a/moo/mooedit/mootextview-private.h +++ b/moo/mooedit/mootextview-private.h @@ -22,6 +22,7 @@ #include "mooedit/mootextview.h" #include "mooedit/mootextsearch.h" #include "mooutils/moohistorylist.h" +#include G_BEGIN_DECLS @@ -194,10 +195,15 @@ struct _MooTextViewPrivate { /***********************************************************************/ /* Search /*/ - gboolean enable_quick_search; - gboolean in_search; - GtkWidget *entry; - MooTextSearchFlags search_flags; + struct { + gboolean enable; + gboolean in_search; + GtkWidget *evbox; + GtkWidget *entry; + GtkToggleButton *case_sensitive; + GtkToggleButton *regex; + MooTextSearchFlags flags; + } qs; }; enum { diff --git a/moo/mooedit/mootextview.c b/moo/mooedit/mootextview.c index 2456e5d8..495e6400 100644 --- a/moo/mooedit/mootextview.c +++ b/moo/mooedit/mootextview.c @@ -18,6 +18,8 @@ #include "mooedit/mootextbuffer.h" #include "mooedit/mootextfind.h" #include "mooedit/mootext-private.h" +#include "mooedit/quicksearch-glade.h" +#include "mooedit/mooeditprefs.h" #include "mooutils/moomarshals.h" #include "mooutils/mooutils-gobject.h" #include "mooutils/mooundomanager.h" @@ -610,7 +612,7 @@ static void moo_text_view_init (MooTextView *view) view->priv->bold_current_line_number = TRUE; - view->priv->search_flags = MOO_TEXT_SEARCH_CASELESS; + view->priv->qs.flags = MOO_TEXT_SEARCH_CASELESS; #if 0 gtk_drag_dest_unset (GTK_WIDGET (view)); @@ -1001,12 +1003,12 @@ moo_text_view_set_property (GObject *object, break; case PROP_ENABLE_QUICK_SEARCH: - view->priv->enable_quick_search = g_value_get_boolean (value) != 0; + view->priv->qs.enable = g_value_get_boolean (value) != 0; g_object_notify (object, "enable-quick-search"); break; case PROP_QUICK_SEARCH_FLAGS: - view->priv->search_flags = g_value_get_flags (value); + view->priv->qs.flags = g_value_get_flags (value); g_object_notify (object, "quick-search-flags"); break; @@ -1105,11 +1107,11 @@ moo_text_view_get_property (GObject *object, break; case PROP_ENABLE_QUICK_SEARCH: - g_value_set_boolean (value, view->priv->enable_quick_search); + g_value_set_boolean (value, view->priv->qs.enable); break; case PROP_QUICK_SEARCH_FLAGS: - g_value_set_flags (value, view->priv->search_flags); + g_value_set_flags (value, view->priv->qs.flags); break; default: @@ -3535,10 +3537,13 @@ moo_text_view_remove (GtkContainer *container, guint i; MooTextView *view = MOO_TEXT_VIEW (container); - if (widget == view->priv->entry) + if (widget == view->priv->qs.evbox) { - view->priv->in_search = FALSE; - view->priv->entry = NULL; + view->priv->qs.in_search = FALSE; + view->priv->qs.evbox = NULL; + view->priv->qs.entry = NULL; + view->priv->qs.case_sensitive = NULL; + view->priv->qs.regex = NULL; } for (i = 0; i < 4; ++i) @@ -3561,6 +3566,61 @@ moo_text_view_remove (GtkContainer *container, /* Search */ +static void +quick_search_option_toggled (MooTextView *view) +{ + MooTextSearchFlags flags = 0; + + if (!gtk_toggle_button_get_active (view->priv->qs.case_sensitive)) + flags |= MOO_TEXT_SEARCH_CASELESS; + if (gtk_toggle_button_get_active (view->priv->qs.regex)) + flags |= MOO_TEXT_SEARCH_REGEX; + + moo_text_view_set_quick_search_flags (view, flags); + + if (MOO_IS_EDIT (view)) + moo_prefs_set_flags (moo_edit_setting (MOO_EDIT_PREFS_QUICK_SEARCH_FLAGS), flags); +} + + +static void +quick_search_set_widgets_from_flags (MooTextView *view) +{ + g_signal_handlers_block_by_func (view->priv->qs.case_sensitive, + quick_search_option_toggled, view); + g_signal_handlers_block_by_func (view->priv->qs.regex, + quick_search_option_toggled, view); + + gtk_toggle_button_set_active (view->priv->qs.case_sensitive, + !(view->priv->qs.flags & MOO_TEXT_SEARCH_CASELESS)); + gtk_toggle_button_set_active (view->priv->qs.regex, + view->priv->qs.flags & MOO_TEXT_SEARCH_REGEX); + + g_signal_handlers_unblock_by_func (view->priv->qs.case_sensitive, + quick_search_option_toggled, view); + g_signal_handlers_unblock_by_func (view->priv->qs.regex, + quick_search_option_toggled, view); +} + + +void +moo_text_view_set_quick_search_flags (MooTextView *view, + MooTextSearchFlags flags) +{ + g_return_if_fail (MOO_IS_TEXT_VIEW (view)); + + if (flags != view->priv->qs.flags) + { + view->priv->qs.flags = flags; + + if (view->priv->qs.evbox) + quick_search_set_widgets_from_flags (view); + + g_object_notify (G_OBJECT (view), "quick-search-flags"); + } +} + + static void scroll_selection_onscreen (GtkTextView *text_view) { @@ -3596,7 +3656,7 @@ quick_search_find_from (MooTextView *view, GtkTextBuffer *buffer; buffer = get_buffer (view); - found = moo_text_search_forward (start, text, view->priv->search_flags, + found = moo_text_search_forward (start, text, view->priv->qs.flags, &match_start, &match_end, NULL); if (!found) @@ -3606,7 +3666,7 @@ quick_search_find_from (MooTextView *view, gtk_text_buffer_get_start_iter (buffer, &iter); if (!gtk_text_iter_equal (start, &iter)) - found = moo_text_search_forward (&iter, text, view->priv->search_flags, + found = moo_text_search_forward (&iter, text, view->priv->qs.flags, &match_start, &match_end, NULL); } @@ -3672,7 +3732,7 @@ search_entry_changed (MooTextView *view, { const char *text; - if (!view->priv->in_search) + if (!view->priv->qs.in_search) return; text = gtk_entry_get_text (entry); @@ -3682,10 +3742,11 @@ search_entry_changed (MooTextView *view, } -static void +static gboolean search_entry_focus_out (MooTextView *view) { moo_text_view_stop_quick_search (view); + return FALSE; } @@ -3694,7 +3755,7 @@ search_entry_key_press (MooTextView *view, GdkEventKey *event, GtkEntry *entry) { - if (!view->priv->in_search) + if (!view->priv->qs.in_search) return FALSE; switch (event->keyval) @@ -3723,20 +3784,41 @@ moo_text_view_start_quick_search (MooTextView *view) g_return_if_fail (MOO_IS_TEXT_VIEW (view)); - if (view->priv->in_search) + if (view->priv->qs.in_search) return; - if (!view->priv->entry) + if (!view->priv->qs.entry) { - view->priv->entry = moo_entry_new (); - g_signal_connect_swapped (view->priv->entry, "changed", + MooGladeXML *xml; + + xml = moo_glade_xml_new_empty (); + moo_glade_xml_map_class (xml, "GtkEntry", MOO_TYPE_ENTRY); + moo_glade_xml_parse_memory (xml, QUICK_SEARCH_GLADE_XML, -1, "evbox"); + + view->priv->qs.evbox = moo_glade_xml_get_widget (xml, "evbox"); + g_return_if_fail (view->priv->qs.evbox != NULL); + + view->priv->qs.entry = moo_glade_xml_get_widget (xml, "entry"); + view->priv->qs.case_sensitive = moo_glade_xml_get_widget (xml, "case_sensitive"); + view->priv->qs.regex = moo_glade_xml_get_widget (xml, "regex"); + + g_signal_connect_swapped (view->priv->qs.entry, "changed", G_CALLBACK (search_entry_changed), view); - g_signal_connect_swapped (view->priv->entry, "focus-out-event", + g_signal_connect_swapped (view->priv->qs.entry, "focus-out-event", G_CALLBACK (search_entry_focus_out), view); - g_signal_connect_swapped (view->priv->entry, "key-press-event", + g_signal_connect_swapped (view->priv->qs.entry, "key-press-event", G_CALLBACK (search_entry_key_press), view); - moo_text_view_add_child_in_border (view, view->priv->entry, + + g_signal_connect_swapped (view->priv->qs.case_sensitive, "toggled", + G_CALLBACK (quick_search_option_toggled), view); + g_signal_connect_swapped (view->priv->qs.regex, "toggled", + G_CALLBACK (quick_search_option_toggled), view); + quick_search_set_widgets_from_flags (view); + + moo_text_view_add_child_in_border (view, view->priv->qs.evbox, GTK_TEXT_WINDOW_BOTTOM); + + g_object_unref (xml); } buffer = get_buffer (view); @@ -3748,13 +3830,12 @@ moo_text_view_start_quick_search (MooTextView *view) } if (text) - gtk_entry_set_text (GTK_ENTRY (view->priv->entry), text); + gtk_entry_set_text (GTK_ENTRY (view->priv->qs.entry), text); - gtk_widget_show (view->priv->entry); - gtk_widget_grab_focus (view->priv->entry); - gtk_widget_queue_draw (view->priv->entry); + gtk_widget_show (view->priv->qs.evbox); + gtk_widget_grab_focus (view->priv->qs.entry); - view->priv->in_search = TRUE; + view->priv->qs.in_search = TRUE; g_free (text); } @@ -3765,10 +3846,10 @@ moo_text_view_stop_quick_search (MooTextView *view) { g_return_if_fail (MOO_IS_TEXT_VIEW (view)); - if (view->priv->in_search) + if (view->priv->qs.in_search) { - view->priv->in_search = FALSE; - gtk_widget_hide (view->priv->entry); + view->priv->qs.in_search = FALSE; + gtk_widget_hide (view->priv->qs.evbox); gtk_widget_grab_focus (GTK_WIDGET (view)); } } @@ -3777,7 +3858,7 @@ moo_text_view_stop_quick_search (MooTextView *view) static gboolean start_quick_search (MooTextView *view) { - if (view->priv->enable_quick_search) + if (view->priv->qs.enable) { moo_text_view_start_quick_search (view); return TRUE; diff --git a/moo/mooedit/mootextview.h b/moo/mooedit/mootextview.h index 15e62197..49a7a6da 100644 --- a/moo/mooedit/mootextview.h +++ b/moo/mooedit/mootextview.h @@ -18,6 +18,7 @@ #include #include #include +#include G_BEGIN_DECLS @@ -158,6 +159,8 @@ void moo_text_view_add_child_in_border (MooTextView *view, void moo_text_view_start_quick_search (MooTextView *view); void moo_text_view_stop_quick_search (MooTextView *view); +void moo_text_view_set_quick_search_flags (MooTextView *view, + MooTextSearchFlags flags); G_END_DECLS