diff options
author | 2008-11-11 16:45:14 -0500 | |
---|---|---|
committer | 2008-11-11 16:45:14 -0500 | |
commit | 03cb710af3c9c6c75656e34cea1df16b65b80acf (patch) | |
tree | 14bbb287326927af446fdda4d2ffe911bca2e82a /src | |
parent | ced55dc1815dc522b5d562edd451b1ca36ea31c4 (diff) | |
download | textadept-03cb710af3c9c6c75656e34cea1df16b65b80acf.tar.gz textadept-03cb710af3c9c6c75656e34cea1df16b65b80acf.zip |
Find functionality is mostly handled by Lua now.
Diffstat (limited to 'src')
-rw-r--r-- | src/lua_interface.c | 24 | ||||
-rw-r--r-- | src/textadept.c | 52 | ||||
-rw-r--r-- | src/textadept.h | 7 |
3 files changed, 29 insertions, 54 deletions
diff --git a/src/lua_interface.c b/src/lua_interface.c index 79f27916..c332e5bd 100644 --- a/src/lua_interface.c +++ b/src/lua_interface.c @@ -900,12 +900,11 @@ void l_pm_perform_menu_action(const char *menu_item) { * @param next Flag indicating whether or not to find next. If false, finds * previous matches. */ -void l_find(const char *ftext, int flags, bool next) { +void l_find(const char *ftext, bool next) { if (!l_is_ta_table_function("find", "find")) return; lua_pushstring(lua, ftext); - lua_pushinteger(lua, flags); lua_pushboolean(lua, next); - l_call_function(3); + l_call_function(2); } /** @@ -924,12 +923,11 @@ void l_find_replace(const char *rtext) { * @param rtext The text to replace the found text with. * @param flags Integer flags for the find. */ -void l_find_replace_all(const char *ftext, const char *rtext, int flags) { +void l_find_replace_all(const char *ftext, const char *rtext) { if (!l_is_ta_table_function("find", "replace_all")) return; lua_pushstring(lua, ftext); lua_pushstring(lua, rtext); - lua_pushinteger(lua, flags); - l_call_function(3); + l_call_function(2); } // Lua functions (stack maintenence is unnecessary) @@ -1179,22 +1177,36 @@ LF l_pm_mt_newindex(LS *lua) { return 0; } +#define toggled(w) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)) LF l_find_mt_index(LS *lua) { const char *key = lua_tostring(lua, 2); if (streq(key, "find_entry_text")) lua_pushstring(lua, gtk_entry_get_text(GTK_ENTRY(find_entry))); else if (streq(key, "replace_entry_text")) lua_pushstring(lua, gtk_entry_get_text(GTK_ENTRY(replace_entry))); + else if (streq(key, "match_case")) + lua_pushboolean(lua, toggled(match_case_opt)); + else if (streq(key, "whole_word")) + lua_pushboolean(lua, toggled(whole_word_opt)); + else if (streq(key, "lua")) + lua_pushboolean(lua, toggled(lua_opt)); else lua_rawget(lua, 1); return 1; } +#define toggle(w, b) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b) LF l_find_mt_newindex(LS *lua) { const char *key = lua_tostring(lua, 2); if (streq(key, "find_entry_text")) gtk_entry_set_text(GTK_ENTRY(find_entry), lua_tostring(lua, 3)); else if (streq(key, "replace_entry_text")) gtk_entry_set_text(GTK_ENTRY(replace_entry), lua_tostring(lua, 3)); + else if (streq(key, "match_case")) + toggle(match_case_opt, lua_toboolean(lua, -1) ? TRUE : FALSE); + else if (streq(key, "whole_word")) + toggle(whole_word_opt, lua_toboolean(lua, -1) ? TRUE : FALSE); + else if (streq(key, "lua")) + toggle(lua_opt, lua_toboolean(lua, -1) ? TRUE : FALSE); else lua_rawset(lua, 1); return 0; } diff --git a/src/textadept.c b/src/textadept.c index 4f5a510a..017165a3 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -62,8 +62,6 @@ GtkAttachOptions ao_normal = static_cast<GtkAttachOptions>(GTK_SHRINK | GTK_FILL), ao_expand = static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL); -static gbool fe_keypress(GtkWidget*, GdkEventKey *event, gpointer); -static gbool re_keypress(GtkWidget*, GdkEventKey *event, gpointer); static void button_clicked(GtkWidget *button, gpointer); #if WIN32 || MAC @@ -882,7 +880,6 @@ static void pm_menu_activate(GtkWidget *menu_item, gpointer) { gtk_table_attach(GTK_TABLE(findbox), w, x1, x2, y1, y2, xo, yo, xp, yp) #define find_text gtk_entry_get_text(GTK_ENTRY(find_entry)) #define repl_text gtk_entry_get_text(GTK_ENTRY(replace_entry)) -#define toggled(w) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)) /** * Creates the Find/Replace text frame. @@ -894,8 +891,10 @@ GtkWidget *find_create_ui() { GtkWidget *rlabel = gtk_label_new_with_mnemonic("R_eplace:"); find_entry = gtk_entry_new(); gtk_widget_set_name(find_entry, "textadept-find-entry"); + gtk_entry_set_activates_default(GTK_ENTRY(find_entry), TRUE); replace_entry = gtk_entry_new(); gtk_widget_set_name(replace_entry, "textadept-replace-entry"); + gtk_entry_set_activates_default(GTK_ENTRY(replace_entry), TRUE); fnext_button = gtk_button_new_with_mnemonic("Find _Next"); fprev_button = gtk_button_new_with_mnemonic("Find _Prev"); r_button = gtk_button_new_with_mnemonic("_Replace"); @@ -922,13 +921,12 @@ GtkWidget *find_create_ui() { //attach(incremental_opt, 5, 6, 0, 1, ao_normal, ao_normal, 5, 0); attach(lua_opt, 5, 6, 0, 1, ao_normal, ao_normal, 5, 0); - signal(find_entry, "key_press_event", fe_keypress); - signal(replace_entry, "key_press_event", re_keypress); signal(fnext_button, "clicked", button_clicked); signal(fprev_button, "clicked", button_clicked); signal(r_button, "clicked", button_clicked); signal(ra_button, "clicked", button_clicked); + GTK_WIDGET_SET_FLAGS(fnext_button, GTK_CAN_DEFAULT); GTK_WIDGET_UNSET_FLAGS(fnext_button, GTK_CAN_FOCUS); GTK_WIDGET_UNSET_FLAGS(fprev_button, GTK_CAN_FOCUS); GTK_WIDGET_UNSET_FLAGS(r_button, GTK_CAN_FOCUS); @@ -949,6 +947,7 @@ void find_toggle_focus() { if (!GTK_WIDGET_HAS_FOCUS(findbox)) { gtk_widget_show(findbox); gtk_widget_grab_focus(find_entry); + gtk_widget_grab_default(fnext_button); } else { gtk_widget_grab_focus(focused_editor); gtk_widget_hide(findbox); @@ -956,51 +955,14 @@ void find_toggle_focus() { } /** - * Builds the integer flags for a Find/Replace depending on the options that are - * checked. - */ -static int get_flags() { - int flags = 0; - if (toggled(match_case_opt)) flags |= SCFIND_MATCHCASE; // 2 - if (toggled(whole_word_opt)) flags |= SCFIND_WHOLEWORD; // 4 - if (toggled(lua_opt)) flags |= 8; - return flags; -} - -/** - * Signal for a Find entry keypress. - * Currently handled keypresses: - * - Enter - Find next or previous. - */ -static gbool fe_keypress(GtkWidget *, GdkEventKey *event, gpointer) { - // TODO: if incremental, call l_find() - if (event->keyval == 0xff0d) { - l_find(find_text, get_flags(), true); - return TRUE; - } else return FALSE; -} - -/** - * Signal for a Replace entry keypress. - * Currently handled keypresses: - * - Enter - Find next or previous. - */ -static gbool re_keypress(GtkWidget *, GdkEventKey *event, gpointer) { - if (event->keyval == 0xff0d) { - l_find(find_text, get_flags(), true); - return TRUE; - } else return FALSE; -} - -/** * Signal for a button click. * Performs the appropriate action depending on the button clicked. */ static void button_clicked(GtkWidget *button, gpointer) { if (button == ra_button) - l_find_replace_all(find_text, repl_text, get_flags()); + l_find_replace_all(find_text, repl_text); else if (button == r_button) { l_find_replace(repl_text); - l_find(find_text, get_flags(), true); - } else l_find(find_text, get_flags(), button == fnext_button); + l_find(find_text, true); + } else l_find(find_text, button == fnext_button); } diff --git a/src/textadept.h b/src/textadept.h index d2ef9376..9521a102 100644 --- a/src/textadept.h +++ b/src/textadept.h @@ -34,7 +34,8 @@ extern GtkWidget *window, *focused_editor, *command_entry, *pm_container, *pm_entry, *pm_view, *findbox, *find_entry, *replace_entry, - *fnext_button, *fprev_button, *r_button, *ra_button; + *fnext_button, *fprev_button, *r_button, *ra_button, + *match_case_opt, *whole_word_opt, /**incremental_opt,*/ *lua_opt; extern GtkEntryCompletion *command_entry_completion; extern GtkTreeStore *cec_store, *pm_store; extern lua_State *lua; @@ -101,8 +102,8 @@ void l_pm_perform_action(); void l_pm_popup_context_menu(GdkEventButton *event, GCallback callback); void l_pm_perform_menu_action(const char *menu_item); -void l_find(const char *ftext, int flags, bool next); +void l_find(const char *ftext, bool next); void l_find_replace(const char *rtext); -void l_find_replace_all(const char *ftext, const char *rtext, int flags); +void l_find_replace_all(const char *ftext, const char *rtext); #endif |