A bit better quick search

This commit is contained in:
Yevgen Muntyan 2006-04-05 01:22:26 -05:00
parent 4c2f4f18ee
commit 5d1b6d18f7
9 changed files with 348 additions and 45 deletions

View File

@ -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)

View File

@ -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 \

View File

@ -0,0 +1,203 @@
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<widget class="GtkWindow" id="window1">
<property name="visible">True</property>
<property name="title" translatable="yes">window1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkEventBox" id="evbox">
<property name="visible">True</property>
<property name="visible_window">True</property>
<property name="above_child">False</property>
<child>
<widget class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0.5</property>
<property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
<child>
<widget class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">1</property>
<property name="yscale">1</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkEntry" id="entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="case_sensitive">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Case sensitive</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">False</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="regex">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Regular expression</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">False</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkEventBox" id="eventbox1">
<property name="visible">True</property>
<property name="visible_window">True</property>
<property name="above_child">False</property>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
<child>
<placeholder/>
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -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)

View File

@ -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))

View File

@ -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"

View File

@ -22,6 +22,7 @@
#include "mooedit/mootextview.h"
#include "mooedit/mootextsearch.h"
#include "mooutils/moohistorylist.h"
#include <gtk/gtk.h>
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 {

View File

@ -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;

View File

@ -18,6 +18,7 @@
#include <gtk/gtktextview.h>
#include <mooedit/mooindenter.h>
#include <mooedit/moolang.h>
#include <mooedit/mootextsearch.h>
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