[gtranslator/merge-requests/61: 17/20] Modify existing functions for the new search_and_replace_bar widget in src/gtr-actions-search.c
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator/merge-requests/61: 17/20] Modify existing functions for the new search_and_replace_bar widget in src/gtr-actions-search.c
- Date: Fri, 14 Feb 2020 09:53:07 +0000 (UTC)
commit 2b415561c235487adc8aca516dda2b9950dd1667
Author: Priyanka Saggu <priyankasggu11929 gmail com>
Date: Tue Feb 11 13:26:47 2020 +0530
Modify existing functions for the new search_and_replace_bar widget in src/gtr-actions-search.c
src/gtr-actions-search.c | 223 +++++++++++++++++++++++------------------------
1 file changed, 107 insertions(+), 116 deletions(-)
---
diff --git a/src/gtr-actions-search.c b/src/gtr-actions-search.c
index 446aa07f..22b55f3f 100644
--- a/src/gtr-actions-search.c
+++ b/src/gtr-actions-search.c
@@ -38,99 +38,85 @@
#include "gtr-utils.h"
#include "gtr-view.h"
#include "gtr-window.h"
-#include "gtr-search-dialog.h"
+#include "gtr-search-bar.h"
-#define GTR_SEARCH_DIALOG_KEY "gtr-search-dialog-key"
+#define GTR_SEARCH_BAR_KEY "gtr-search-bar-key"
#define GTR_LAST_SEARCH_DATA_KEY "gtr-last-search-data-key"
/* data stored in the document
* to persist the last searched
* words and options
*/
-typedef struct _LastSearchData LastSearchData;
-struct _LastSearchData
-{
- gchar *find_text;
- gchar *replace_text;
-
- gint original_text:1;
- gint translated_text:1;
- gint fuzzy_messages:1;
- gint match_case:1;
- gint entire_word:1;
- gint backwards:1;
- gint wrap_around:1;
-};
static void
-last_search_data_free (LastSearchData * data)
+last_search_data_free (LastSearchData *data)
{
g_free (data->find_text);
g_free (data->replace_text);
g_free (data);
}
-static void
-last_search_data_set (LastSearchData * data, GtrSearchDialog * dialog)
+void
+last_search_data_set (LastSearchData * data, GtrSearchBar * dialog)
{
const gchar *str;
- str = gtr_search_dialog_get_search_text (dialog);
+ str = gtr_search_bar_get_search_text (dialog);
if (str != NULL && *str != '\0')
{
g_free (data->find_text);
data->find_text = gtr_utils_unescape_search_text (str);
}
- str = gtr_search_dialog_get_replace_text (dialog);
+ str = gtr_search_bar_get_replace_text (dialog);
if (str != NULL && *str != '\0')
{
g_free (data->replace_text);
data->replace_text = gtr_utils_unescape_search_text (str);
}
- data->original_text = gtr_search_dialog_get_original_text (dialog);
- data->translated_text = gtr_search_dialog_get_translated_text (dialog);
- data->match_case = gtr_search_dialog_get_match_case (dialog);
- data->entire_word = gtr_search_dialog_get_entire_word (dialog);
- data->backwards = gtr_search_dialog_get_backwards (dialog);
- data->wrap_around = gtr_search_dialog_get_wrap_around (dialog);
+ data->original_text = gtr_search_bar_get_original_text (dialog);
+ data->translated_text = gtr_search_bar_get_translated_text (dialog);
+ data->match_case = gtr_search_bar_get_match_case (dialog);
+ data->entire_word = gtr_search_bar_get_entire_word (dialog);
+ data->backwards = gtr_search_bar_get_backwards (dialog);
+ data->wrap_around = gtr_search_bar_get_wrap_around (dialog);
}
-static void
-search_dialog_set_last_find_text (GtrSearchDialog * dialog,
+void
+search_bar_set_last_find_text (GtrSearchBar * dialog,
LastSearchData * data)
{
if (data->find_text)
- gtr_search_dialog_set_search_text (dialog, data->find_text);
+ gtr_search_bar_set_search_text (dialog, data->find_text);
}
-static void
-search_dialog_set_last_replace_text (GtrSearchDialog * dialog,
- LastSearchData * data)
+void
+search_bar_set_last_replace_text (GtrSearchBar * dialog,
+ LastSearchData * data)
{
if (data->replace_text)
- gtr_search_dialog_set_replace_text (dialog, data->replace_text);
+ gtr_search_bar_set_replace_text (dialog, data->replace_text);
}
-static void
-search_dialog_set_last_options (GtrSearchDialog * dialog,
- LastSearchData * data)
+void
+search_bar_set_last_options (GtrSearchBar * dialog,
+ LastSearchData * data)
{
- gtr_search_dialog_set_original_text (dialog, data->original_text);
- gtr_search_dialog_set_translated_text (dialog, data->translated_text);
- gtr_search_dialog_set_match_case (dialog, data->match_case);
- gtr_search_dialog_set_entire_word (dialog, data->entire_word);
- gtr_search_dialog_set_backwards (dialog, data->backwards);
- gtr_search_dialog_set_wrap_around (dialog, data->wrap_around);
+ gtr_search_bar_set_original_text (dialog, data->original_text);
+ gtr_search_bar_set_translated_text (dialog, data->translated_text);
+ gtr_search_bar_set_match_case (dialog, data->match_case);
+ gtr_search_bar_set_entire_word (dialog, data->entire_word);
+ gtr_search_bar_set_backwards (dialog, data->backwards);
+ gtr_search_bar_set_wrap_around (dialog, data->wrap_around);
}
/*
* Used to get the old search data and store the new values.
*/
static void
-restore_last_searched_data (GtrSearchDialog * dialog, GtrTab * tab)
+restore_last_searched_data (GtrSearchBar * dialog, GtrTab * tab)
{
LastSearchData *data;
@@ -154,7 +140,7 @@ restore_last_searched_data (GtrSearchDialog * dialog, GtrTab * tab)
/* Use occurences only for Replace All */
static void
-phrase_found (GtrSearchDialog * dialog,
+phrase_found (GtrSearchBar * dialog,
gint occurrences)
{
g_autofree char *message = NULL;
@@ -164,17 +150,17 @@ phrase_found (GtrSearchDialog * dialog,
"Found and replaced %d occurrences",
occurrences), occurrences);
- gtr_search_dialog_show_message (dialog, message, GTR_SEARCH_DIALOG_MSG_INFO);
+ // gtr_search_bar_show_message (dialog, message, GTR_SEARCH_BAR_MSG_INFO);
}
static void
-phrase_not_found (GtrSearchDialog * dialog)
+phrase_not_found (GtrSearchBar * dialog)
{
- gtr_search_dialog_show_message (dialog, _("Phrase not found"),
- GTR_SEARCH_DIALOG_MSG_ERROR);
+ // gtr_search_bar_show_message (dialog, _("Phrase not found"),
+ // GTR_SEARCH_BAR_MSG_ERROR);
}
-static gboolean
+gboolean
run_search (GtrView * view, gboolean follow)
{
GtkSourceBuffer *doc;
@@ -213,10 +199,11 @@ run_search (GtrView * view, gboolean follow)
return found;
}
-static gboolean
+gboolean
find_in_list (GtrWindow * window,
GList * views,
- gboolean wrap_around, gboolean search_backwards)
+ gboolean wrap_around,
+ gboolean search_backwards)
{
GtrTab *tab = gtr_window_get_active_tab (window);
GtrPo *po = gtr_tab_get_po (tab);
@@ -279,8 +266,8 @@ find_in_list (GtrWindow * window,
return FALSE;
}
-static void
-do_find (GtrSearchDialog * dialog, GtrWindow * window)
+void
+do_find (GtrSearchBar * dialog, GtrWindow * window)
{
GtrTab *tab;
GList *views, *list;
@@ -299,17 +286,17 @@ do_find (GtrSearchDialog * dialog, GtrWindow * window)
/* Used to store search options */
tab = gtr_window_get_active_tab (window);
- entry_text = gtr_search_dialog_get_search_text (dialog);
+ entry_text = gtr_search_bar_get_search_text (dialog);
/* Views where find */
- original_text = gtr_search_dialog_get_original_text (dialog);
- translated_text = gtr_search_dialog_get_translated_text (dialog);
+ original_text = gtr_search_bar_get_original_text (dialog);
+ translated_text = gtr_search_bar_get_translated_text (dialog);
/* Flags */
- match_case = gtr_search_dialog_get_match_case (dialog);
- entire_word = gtr_search_dialog_get_entire_word (dialog);
- search_backwards = gtr_search_dialog_get_backwards (dialog);
- wrap_around = gtr_search_dialog_get_wrap_around (dialog);
+ match_case = gtr_search_bar_get_match_case (dialog);
+ entire_word = gtr_search_bar_get_entire_word (dialog);
+ search_backwards = gtr_search_bar_get_backwards (dialog);
+ wrap_around = gtr_search_bar_get_wrap_around (dialog);
if (!original_text && !translated_text)
return;
@@ -347,7 +334,7 @@ do_find (GtrSearchDialog * dialog, GtrWindow * window)
phrase_not_found (dialog);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
- GTR_SEARCH_DIALOG_REPLACE_RESPONSE,
+ GTR_SEARCH_BAR_REPLACE_RESPONSE,
found);
restore_last_searched_data (dialog, tab);
@@ -369,8 +356,8 @@ replace_selected_text (GtkTextBuffer * buffer, const gchar * replace)
gtk_text_buffer_end_user_action (buffer);
}
-static void
-do_replace (GtrSearchDialog * dialog, GtrWindow * window)
+void
+do_replace (GtrSearchBar * dialog, GtrWindow * window)
{
GtrView *view;
const gchar *search_entry_text;
@@ -388,19 +375,19 @@ do_replace (GtrSearchDialog * dialog, GtrWindow * window)
tab = gtr_window_get_active_tab (window);
gtr_tab_find_replace (tab, TRUE);
- search_entry_text = gtr_search_dialog_get_search_text (dialog);
+ search_entry_text = gtr_search_bar_get_search_text (dialog);
g_return_if_fail ((search_entry_text) != NULL);
g_return_if_fail ((*search_entry_text) != '\0');
/* replace text may be "", we just delete */
- replace_entry_text = gtr_search_dialog_get_replace_text (dialog);
+ replace_entry_text = gtr_search_bar_get_replace_text (dialog);
g_return_if_fail ((replace_entry_text) != NULL);
unescaped_search_text = gtr_utils_unescape_search_text (search_entry_text);
gtr_view_get_selected_text (view, &selected_text, NULL);
- match_case = gtr_search_dialog_get_match_case (dialog);
+ match_case = gtr_search_bar_get_match_case (dialog);
if ((selected_text == NULL) ||
(match_case && (strcmp (selected_text, unescaped_search_text) != 0)) ||
@@ -431,8 +418,8 @@ do_replace (GtrSearchDialog * dialog, GtrWindow * window)
gtr_tab_find_replace (tab, FALSE);
}
-static void
-do_replace_all (GtrSearchDialog * dialog, GtrWindow * window)
+void
+do_replace_all (GtrSearchBar * dialog, GtrWindow * window)
{
GtrTab *tab;
GList *views, *l;
@@ -458,16 +445,16 @@ do_replace_all (GtrSearchDialog * dialog, GtrWindow * window)
l = views;
aux = current_msg;
- search_entry_text = gtr_search_dialog_get_search_text (dialog);
+ search_entry_text = gtr_search_bar_get_search_text (dialog);
g_return_if_fail ((search_entry_text) != NULL);
g_return_if_fail ((*search_entry_text) != '\0');
/* replace text may be "", we just delete all occurrencies */
- replace_entry_text = gtr_search_dialog_get_replace_text (dialog);
+ replace_entry_text = gtr_search_bar_get_replace_text (dialog);
g_return_if_fail ((replace_entry_text) != NULL);
- match_case = gtr_search_dialog_get_match_case (dialog);
- entire_word = gtr_search_dialog_get_entire_word (dialog);
+ match_case = gtr_search_bar_get_match_case (dialog);
+ entire_word = gtr_search_bar_get_entire_word (dialog);
GTR_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
GTR_SEARCH_SET_ENTIRE_WORD (flags, entire_word);
@@ -505,26 +492,27 @@ do_replace_all (GtrSearchDialog * dialog, GtrWindow * window)
}
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
- GTR_SEARCH_DIALOG_REPLACE_RESPONSE,
+ GTR_SEARCH_BAR_REPLACE_RESPONSE,
FALSE);
restore_last_searched_data (dialog, tab);
gtr_tab_find_replace (tab, FALSE);
}
-static void
-search_dialog_response_cb (GtrSearchDialog * dialog,
- gint response_id, GtrWindow * window)
+void
+search_bar_response_cb (GtrSearchBar *dialog,
+ gint response_id,
+ GtrWindow *window)
{
switch (response_id)
{
- case GTR_SEARCH_DIALOG_FIND_RESPONSE:
+ case GTR_SEARCH_BAR_FIND_RESPONSE:
do_find (dialog, window);
break;
- case GTR_SEARCH_DIALOG_REPLACE_RESPONSE:
+ case GTR_SEARCH_BAR_REPLACE_RESPONSE:
do_replace (dialog, window);
break;
- case GTR_SEARCH_DIALOG_REPLACE_ALL_RESPONSE:
+ case GTR_SEARCH_BAR_REPLACE_ALL_RESPONSE:
do_replace_all (dialog, window);
break;
default:
@@ -532,17 +520,19 @@ search_dialog_response_cb (GtrSearchDialog * dialog,
}
}
-static void
-search_dialog_destroyed (GtrWindow * window, GtrSearchDialog * dialog)
+/*
+void
+search_bar_destroyed (GtrWindow * window, GtrSearchBar * dialog)
{
- g_object_set_data (G_OBJECT (window), GTR_SEARCH_DIALOG_KEY, NULL);
+ g_object_set_data (G_OBJECT (window), GTR_SEARCH_BAR_KEY, NULL);
}
+
void
_gtr_actions_search_find (GtkAction * action, GtrWindow * window)
{
gpointer data;
- GtkWidget *search_dialog;
+ GtkWidget *search_bar;
GtrTab *tab;
GtrView *view;
gboolean selection_exists;
@@ -550,28 +540,28 @@ _gtr_actions_search_find (GtkAction * action, GtrWindow * window)
gint sel_len;
LastSearchData *last_search_data;
- data = g_object_get_data (G_OBJECT (window), GTR_SEARCH_DIALOG_KEY);
+ data = g_object_get_data (G_OBJECT (window), GTR_SEARCH_BAR_KEY);
if (data != NULL)
{
- g_return_if_fail (GTR_IS_SEARCH_DIALOG (data));
+ g_return_if_fail (GTR_IS_SEARCH_BAR (data));
+
+ // note that we rise a search&replace dialog if
+ // it is already open
- /* note that we rise a search&replace dialog if
- * it is already open
- */
- gtr_search_dialog_present_with_time (GTR_SEARCH_DIALOG (data),
+ gtr_search_bar_present_with_time (GTR_SEARCH_BAR (data),
GDK_CURRENT_TIME);
return;
}
- search_dialog = gtr_search_dialog_new (GTK_WINDOW (window), FALSE);
+ // search_bar = gtr_search_dialog_new (GTK_WINDOW (window), FALSE);
- g_object_set_data (G_OBJECT (window), GTR_SEARCH_DIALOG_KEY, search_dialog);
+ g_object_set_data (G_OBJECT (window), GTR_SEARCH_BAR_KEY, search_bar);
- g_object_weak_ref (G_OBJECT (search_dialog),
- (GWeakNotify) search_dialog_destroyed, window);
+ g_object_weak_ref (G_OBJECT (search_bar),
+ (GWeakNotify) search_bar_destroyed, window);
tab = gtr_window_get_active_tab (window);
view = gtr_window_get_active_view (window);
@@ -585,8 +575,8 @@ _gtr_actions_search_find (GtkAction * action, GtrWindow * window)
if (selection_exists && find_text != NULL && sel_len < 80)
{
- gtr_search_dialog_set_search_text (GTR_SEARCH_DIALOG
- (search_dialog), find_text);
+ gtr_search_bar_set_search_text (GTR_SEARCH_BAR
+ (search_bar), find_text);
g_free (find_text);
}
else
@@ -594,23 +584,23 @@ _gtr_actions_search_find (GtkAction * action, GtrWindow * window)
g_free (find_text);
if (last_search_data != NULL)
- search_dialog_set_last_find_text (GTR_SEARCH_DIALOG (search_dialog),
+ search_bar_set_last_find_text (GTR_SEARCH_BAR (search_bar),
last_search_data);
}
if (last_search_data != NULL)
- search_dialog_set_last_replace_text (GTR_SEARCH_DIALOG (search_dialog),
+ search_bar_set_last_replace_text (GTR_SEARCH_BAR (search_bar),
last_search_data);
if (last_search_data != NULL)
- search_dialog_set_last_options (GTR_SEARCH_DIALOG (search_dialog),
+ search_bar_set_last_options (GTR_SEARCH_BAR (search_bar),
last_search_data);
- g_signal_connect (search_dialog,
+ g_signal_connect (search_bar,
"response",
- G_CALLBACK (search_dialog_response_cb), window);
+ G_CALLBACK (search_bar_response_cb), window);
- gtk_widget_show (search_dialog);
+ gtk_widget_show (search_bar);
}
void
@@ -625,29 +615,29 @@ _gtr_actions_search_replace (GtkAction * action, GtrWindow * window)
gint sel_len;
LastSearchData *last_search_data;
- data = g_object_get_data (G_OBJECT (window), GTR_SEARCH_DIALOG_KEY);
+ data = g_object_get_data (G_OBJECT (window), GTR_SEARCH_BAR_KEY);
if (data != NULL)
{
- g_return_if_fail (GTR_IS_SEARCH_DIALOG (data));
+ g_return_if_fail (GTR_IS_SEARCH_BAR (data));
- /* turn the dialog into a replace dialog if needed */
- if (!gtr_search_dialog_get_show_replace (GTR_SEARCH_DIALOG (data)))
- gtr_search_dialog_set_show_replace (GTR_SEARCH_DIALOG (data), TRUE);
+ // turn the dialog into a replace dialog if needed
+ // if (!gtr_search_bar_get_show_replace (GTR_SEARCH_BAR (data)))
+ // gtr_search_bar_set_show_replace (GTR_SEARCH_BAR (data), TRUE);
- gtr_search_dialog_present_with_time (GTR_SEARCH_DIALOG (data),
+ gtr_search_bar_present_with_time (GTR_SEARCH_BAR (data),
GDK_CURRENT_TIME);
return;
}
- replace_dialog = gtr_search_dialog_new (GTK_WINDOW (window), TRUE);
+// replace_dialog = gtr_search_dialog_new (GTK_WINDOW (window), TRUE);
g_object_set_data (G_OBJECT (window),
- GTR_SEARCH_DIALOG_KEY, replace_dialog);
+ GTR_SEARCH_BAR_KEY, replace_dialog);
g_object_weak_ref (G_OBJECT (replace_dialog),
- (GWeakNotify) search_dialog_destroyed, window);
+ (GWeakNotify) search_bar_destroyed, window);
tab = gtr_window_get_active_tab (window);
view = gtr_window_get_active_view (window);
@@ -661,7 +651,7 @@ _gtr_actions_search_replace (GtkAction * action, GtrWindow * window)
if (selection_exists && find_text != NULL && sel_len < 80)
{
- gtr_search_dialog_set_search_text (GTR_SEARCH_DIALOG
+ gtr_search_bar_set_search_text (GTR_SEARCH_BAR
(replace_dialog), find_text);
g_free (find_text);
}
@@ -670,21 +660,22 @@ _gtr_actions_search_replace (GtkAction * action, GtrWindow * window)
g_free (find_text);
if (last_search_data != NULL)
- search_dialog_set_last_find_text (GTR_SEARCH_DIALOG (replace_dialog),
+ search_bar_set_last_find_text (GTR_SEARCH_BAR (replace_dialog),
last_search_data);
}
if (last_search_data != NULL)
- search_dialog_set_last_replace_text (GTR_SEARCH_DIALOG (replace_dialog),
+ search_bar_set_last_replace_text (GTR_SEARCH_BAR (replace_dialog),
last_search_data);
if (last_search_data != NULL)
- search_dialog_set_last_options (GTR_SEARCH_DIALOG (replace_dialog),
+ search_bar_set_last_options (GTR_SEARCH_BAR (replace_dialog),
last_search_data);
g_signal_connect (replace_dialog,
"response",
- G_CALLBACK (search_dialog_response_cb), window);
+ G_CALLBACK (search_bar_response_cb), window);
gtk_widget_show (replace_dialog);
}
+*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]