* l3afpad-0.8.18.1.7
This commit is contained in:
@@ -31,6 +31,10 @@
|
||||
#define ENABLE_PRINT 1
|
||||
#endif
|
||||
|
||||
#ifndef SEARCH_HISTORY
|
||||
#define SEARCH_HISTORY 1
|
||||
#endif
|
||||
|
||||
#ifndef ENABLE_STATISTICS
|
||||
#define ENABLE_STATISTICS 1
|
||||
#endif
|
||||
|
||||
74
src/search.c
74
src/search.c
@@ -22,6 +22,10 @@
|
||||
#include "l3afpad.h"
|
||||
#include "gtksourceiter.h"
|
||||
|
||||
#if SEARCH_HISTORY
|
||||
static GList *find_history;
|
||||
static GList *replace_history;
|
||||
#endif
|
||||
static gchar *string_find = NULL;
|
||||
static gchar *string_replace = NULL;
|
||||
static gboolean match_case, replace_all;//, replace_mode = FALSE;
|
||||
@@ -246,6 +250,7 @@ static gint document_replace_real(GtkWidget *textview)
|
||||
}
|
||||
|
||||
|
||||
#if !SEARCH_HISTORY
|
||||
static gint entry_len;
|
||||
|
||||
static void toggle_sensitivity(GtkWidget *w, gint pos1, gint pos2, gint *pos3)
|
||||
@@ -263,6 +268,17 @@ static void toggle_sensitivity(GtkWidget *w, gint pos1, gint pos2, gint *pos3)
|
||||
GTK_RESPONSE_OK, FALSE);
|
||||
}
|
||||
}
|
||||
#endif /* !SEARCH_HISTORY */
|
||||
|
||||
#if SEARCH_HISTORY
|
||||
static void toggle_sensitivity(GtkWidget *entry)
|
||||
{
|
||||
gboolean has_text = *(gtk_entry_get_text(GTK_ENTRY(entry))) != '\0';
|
||||
gtk_dialog_set_response_sensitive(
|
||||
GTK_DIALOG(gtk_widget_get_toplevel(entry)), GTK_RESPONSE_OK,
|
||||
(has_text) ? TRUE : FALSE);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void toggle_check_case(GtkWidget *widget)
|
||||
{
|
||||
@@ -279,6 +295,11 @@ gint run_dialog_search(GtkWidget *textview, gint mode)
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *table;
|
||||
GtkWidget *label_find, *label_replace;
|
||||
#if SEARCH_HISTORY
|
||||
GtkWidget *combo_find, *combo_replace = NULL;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextIter start_iter, end_iter;
|
||||
#endif
|
||||
GtkWidget *entry_find, *entry_replace = NULL;
|
||||
GtkWidget *check_case, *check_all;
|
||||
gint res;
|
||||
@@ -306,9 +327,16 @@ gint run_dialog_search(GtkWidget *textview, gint mode)
|
||||
label_find = gtk_label_new_with_mnemonic(_("Fi_nd what:"));
|
||||
gtk_misc_set_alignment(GTK_MISC(label_find), 0, 0.5);
|
||||
gtk_table_attach_defaults(GTK_TABLE(table), label_find, 0, 1, 0, 1);
|
||||
#if SEARCH_HISTORY
|
||||
combo_find = create_combo_with_history (&find_history);
|
||||
gtk_table_attach_defaults(GTK_TABLE(table), combo_find, 1, 2, 0, 1);
|
||||
entry_find = gtk_bin_get_child(GTK_BIN(combo_find));
|
||||
#else
|
||||
entry_find = gtk_entry_new();
|
||||
gtk_table_attach_defaults(GTK_TABLE(table), entry_find, 1, 2, 0, 1);
|
||||
#endif
|
||||
gtk_label_set_mnemonic_widget(GTK_LABEL(label_find), entry_find);
|
||||
#if !SEARCH_HISTORY
|
||||
gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog),
|
||||
GTK_RESPONSE_OK, FALSE);
|
||||
entry_len = 0;
|
||||
@@ -321,10 +349,37 @@ gint run_dialog_search(GtkWidget *textview, gint mode)
|
||||
gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog),
|
||||
GTK_RESPONSE_OK, TRUE);
|
||||
}
|
||||
#endif
|
||||
#if SEARCH_HISTORY
|
||||
gtk_entry_set_activates_default(GTK_ENTRY(entry_find), TRUE);
|
||||
g_signal_connect_after(G_OBJECT(entry_find), "insert-text",
|
||||
G_CALLBACK(toggle_sensitivity), NULL);
|
||||
g_signal_connect_after(G_OBJECT(entry_find), "delete-text",
|
||||
G_CALLBACK(toggle_sensitivity), NULL);
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
|
||||
if (gtk_text_buffer_get_selection_bounds (buffer, &start_iter, &end_iter)) {
|
||||
if (string_find != NULL)
|
||||
g_free(string_find);
|
||||
string_find = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter,
|
||||
FALSE);
|
||||
gtk_entry_set_text(GTK_ENTRY(entry_find), string_find);
|
||||
gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog),
|
||||
GTK_RESPONSE_OK, TRUE);
|
||||
}
|
||||
else
|
||||
gtk_entry_set_text(GTK_ENTRY(entry_find), "");
|
||||
#endif
|
||||
if (mode) {
|
||||
label_replace = gtk_label_new_with_mnemonic(_("Re_place with:"));
|
||||
gtk_misc_set_alignment(GTK_MISC(label_replace), 0, 0.5);
|
||||
gtk_table_attach_defaults(GTK_TABLE(table), label_replace, 0, 1, 1, 2);
|
||||
#if SEARCH_HISTORY
|
||||
combo_replace = create_combo_with_history (&replace_history);
|
||||
gtk_table_attach_defaults(GTK_TABLE(table), combo_replace, 1, 2, 1, 2);
|
||||
entry_replace = gtk_bin_get_child(GTK_BIN(combo_replace));
|
||||
gtk_label_set_mnemonic_widget(GTK_LABEL(label_replace), entry_replace);
|
||||
gtk_entry_set_text(GTK_ENTRY(entry_replace), "");
|
||||
#else
|
||||
entry_replace = gtk_entry_new();
|
||||
gtk_table_attach_defaults(GTK_TABLE(table), entry_replace, 1, 2, 1, 2);
|
||||
gtk_label_set_mnemonic_widget(GTK_LABEL(label_replace), entry_replace);
|
||||
@@ -334,26 +389,45 @@ gint run_dialog_search(GtkWidget *textview, gint mode)
|
||||
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
|
||||
gtk_entry_set_activates_default(GTK_ENTRY(entry_find), TRUE);
|
||||
if (mode)
|
||||
#endif
|
||||
gtk_entry_set_activates_default(GTK_ENTRY(entry_replace), TRUE);
|
||||
|
||||
#if !SEARCH_HISTORY
|
||||
check_case = gtk_check_button_new_with_mnemonic(_("_Match case"));
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_case), match_case);
|
||||
g_signal_connect(check_case, "toggled", G_CALLBACK(toggle_check_case), NULL);
|
||||
gtk_table_attach_defaults (GTK_TABLE(table), check_case, 0, 2, 1 + mode, 2 + mode);
|
||||
if (mode) {
|
||||
#endif
|
||||
check_all = gtk_check_button_new_with_mnemonic(_("Replace _all at once"));
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_all), replace_all);
|
||||
g_signal_connect(check_all, "toggled", G_CALLBACK(toggle_check_all), NULL);
|
||||
gtk_table_attach_defaults(GTK_TABLE(table), check_all, 0, 2, 2 + mode, 3 + mode);
|
||||
}
|
||||
#if SEARCH_HISTORY
|
||||
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
|
||||
toggle_sensitivity (entry_find);
|
||||
check_case = gtk_check_button_new_with_mnemonic(_("_Match case"));
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_case), match_case);
|
||||
g_signal_connect(check_case, "toggled", G_CALLBACK(toggle_check_case), NULL);
|
||||
gtk_table_attach_defaults (GTK_TABLE(table), check_case, 0, 2, 1 + mode, 2 + mode);
|
||||
#endif
|
||||
gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
|
||||
gtk_widget_show_all(table);
|
||||
|
||||
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
if (res == GTK_RESPONSE_OK) {
|
||||
#if SEARCH_HISTORY
|
||||
update_combo_data (entry_find, &find_history);
|
||||
if (string_find != NULL)
|
||||
#endif
|
||||
g_free(string_find);
|
||||
string_find = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_find)));
|
||||
if (mode) {
|
||||
#if SEARCH_HISTORY
|
||||
update_combo_data (entry_replace, &replace_history);
|
||||
if (string_replace != NULL)
|
||||
#endif
|
||||
g_free(string_replace);
|
||||
string_replace = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_replace)));
|
||||
}
|
||||
|
||||
59
src/utils.c
59
src/utils.c
@@ -104,3 +104,62 @@ GtkWidget *create_button_with_stock_image(const gchar *text, const gchar *stock_
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
#if SEARCH_HISTORY
|
||||
void update_combo_data (GtkWidget *entry, GList **history)
|
||||
{
|
||||
const gchar *text;
|
||||
GList *node;
|
||||
|
||||
text = gtk_entry_get_text (GTK_ENTRY (entry));
|
||||
if (*text == '\0')
|
||||
return;
|
||||
for (node = *history; node != NULL; node = g_list_next (node))
|
||||
{
|
||||
if (g_str_equal ((gchar *)node->data, text))
|
||||
{
|
||||
g_free (node->data);
|
||||
*history = g_list_delete_link (*history, node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*history = g_list_prepend (*history, g_strdup (text));
|
||||
}
|
||||
|
||||
GtkWidget *create_combo_with_history (GList **history)
|
||||
{
|
||||
GtkWidget *combo;
|
||||
GList *node;
|
||||
|
||||
combo = gtk_combo_box_text_new_with_entry ();
|
||||
//work around gtk silliness -
|
||||
//'appears-as-list' is a read-only style property instead of a widget property
|
||||
gtk_rc_parse_string (
|
||||
"style \"list-style-style\" { GtkComboBox::appears-as-list = 1 } "
|
||||
"widget \"*.list-style\" style \"list-style-style\"");
|
||||
gtk_widget_set_name (combo, "list-style");
|
||||
|
||||
for (node = *history; node != NULL; node = g_list_next (node))
|
||||
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), node->data);
|
||||
|
||||
gtk_widget_show (combo);
|
||||
return combo;
|
||||
}
|
||||
|
||||
#if 0 /* if we want to cleanup before exit ... */
|
||||
void clear_combo_history (GList *history)
|
||||
{
|
||||
GList *node;
|
||||
if (history != NULL)
|
||||
{
|
||||
for (node = history; node != NULL; node = g_list_next (node))
|
||||
{
|
||||
if (node->data != NULL)
|
||||
g_free (node->data);
|
||||
}
|
||||
g_list_free (history);
|
||||
history = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -24,5 +24,9 @@
|
||||
gchar *gedit_utils_get_stdin(void);
|
||||
#endif
|
||||
GtkWidget *create_button_with_stock_image(const gchar *text, const gchar *stock_id);
|
||||
#if SEARCH_HISTORY
|
||||
void update_combo_data(GtkWidget *entry, GList **history);
|
||||
GtkWidget *create_combo_with_history(GList **history);
|
||||
#endif
|
||||
|
||||
#endif /* _UTILS_H */
|
||||
|
||||
Reference in New Issue
Block a user