[gtranslator] Show search dialog information in dialog
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator] Show search dialog information in dialog
- Date: Sat, 18 May 2019 19:20:26 +0000 (UTC)
commit 1d2b86745050d87aceae99a8fb6cb09d68843461
Author: Daniel GarcĂa Moreno <dani danigm net>
Date: Sat May 18 21:18:06 2019 +0200
Show search dialog information in dialog
The find and replace dialog was using the statusbar to show messages
like the "not found", we're not using the statubar anymore so we need to
find a new way to show this kind of information to the user.
This patch adds a new widget to the search dialog with a revealer and a
label that will be used to show erros and other information in this
dialog.
Fix #73
src/gtr-actions-search.c | 45 +++++++++++++++------------------------------
src/gtr-search-dialog.c | 37 +++++++++++++++++++++++++++++++++++++
src/gtr-search-dialog.h | 11 +++++++++++
src/gtr-search-dialog.ui | 26 +++++++++++++++++++++++++-
src/styles.css | 8 ++++++++
5 files changed, 96 insertions(+), 31 deletions(-)
---
diff --git a/src/gtr-actions-search.c b/src/gtr-actions-search.c
index 592e465d..084f4583 100644
--- a/src/gtr-actions-search.c
+++ b/src/gtr-actions-search.c
@@ -154,39 +154,24 @@ restore_last_searched_data (GtrSearchDialog * dialog, GtrTab * tab)
/* Use occurences only for Replace All */
static void
-phrase_found (GtrWindow * window, gint occurrences)
+phrase_found (GtrSearchDialog * dialog,
+ gint occurrences)
{
- GtrStatusbar *statusbar;
-
- statusbar = GTR_STATUSBAR (gtr_window_get_statusbar (window));
+ g_autofree char *message = NULL;
if (occurrences > 1)
- {
- gtr_statusbar_flash_message (statusbar,
- 0,
- ngettext
- ("Found and replaced %d occurrence",
- "Found and replaced %d occurrences",
- occurrences), occurrences);
- }
- else
- {
- if (occurrences == 1)
- gtr_statusbar_flash_message (statusbar,
- 0,
- _("Found and replaced one occurrence"));
- else
- gtr_statusbar_flash_message (statusbar, 0, " ");
- }
+ message = g_strdup_printf (_("Found and replaced %d occurrence"),
+ occurrences);
+ else if (occurrences == 1)
+ message = g_strdup_printf (_("Found and replaced one occurrence"));
+ gtr_search_dialog_show_message (dialog, message, GTR_SEARCH_DIALOG_MSG_INFO);
}
static void
-phrase_not_found (GtrWindow * window)
+phrase_not_found (GtrSearchDialog * dialog)
{
- GtrStatusbar *status;
-
- status = GTR_STATUSBAR (gtr_window_get_statusbar (window));
- gtr_statusbar_flash_message (status, 0, _("Phrase not found"));
+ gtr_search_dialog_show_message (dialog, _("Phrase not found"),
+ GTR_SEARCH_DIALOG_MSG_ERROR);
}
static gboolean
@@ -357,9 +342,9 @@ do_find (GtrSearchDialog * dialog, GtrWindow * window)
found = find_in_list (window, views, wrap_around, search_backwards);
if (found)
- phrase_found (window, 0);
+ phrase_found (dialog, 0);
else
- phrase_not_found (window);
+ phrase_not_found (dialog);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
GTR_SEARCH_DIALOG_REPLACE_RESPONSE,
@@ -512,11 +497,11 @@ do_replace_all (GtrSearchDialog * dialog, GtrWindow * window)
if (count > 0)
{
- phrase_found (window, count);
+ phrase_found (dialog, count);
}
else
{
- phrase_not_found (window);
+ phrase_not_found (dialog);
}
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
diff --git a/src/gtr-search-dialog.c b/src/gtr-search-dialog.c
index a3263285..d227a18d 100644
--- a/src/gtr-search-dialog.c
+++ b/src/gtr-search-dialog.c
@@ -71,6 +71,8 @@ typedef struct
GtkWidget *find_button;
GtkWidget *replace_button;
GtkWidget *replace_all_button;
+ GtkWidget *info_revealer;
+ GtkWidget *info_label;
gboolean glade_error;
} GtrSearchDialogPrivate;
@@ -410,8 +412,12 @@ gtr_search_dialog_init (GtrSearchDialog * dlg)
priv->entire_word_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "entire_word_checkbutton"));
priv->backwards_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder,
"search_backwards_checkbutton"));
priv->wrap_around_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "wrap_around_checkbutton"));
+ priv->info_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "info_revealer"));
+ priv->info_label = GTK_WIDGET (gtk_builder_get_object (builder, "info_label"));
g_object_unref (builder);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (priv->info_revealer), FALSE);
+
priv->search_entry = gtr_history_entry_new ("search-for-entry", TRUE);
gtk_widget_set_size_request (priv->search_entry, 300, -1);
gtr_history_entry_set_escape_func (GTR_HISTORY_ENTRY (priv->search_entry),
@@ -736,3 +742,34 @@ gtr_search_dialog_get_wrap_around (GtrSearchDialog * dialog)
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(priv->wrap_around_checkbutton));
}
+
+void
+gtr_search_dialog_show_message (GtrSearchDialog * dialog,
+ char *message,
+ GtrSearchDialogMsg info_type)
+{
+ GtrSearchDialogPrivate *priv = gtr_search_dialog_get_instance_private (dialog);
+ GtkStyleContext *ctx = gtk_widget_get_style_context (priv->info_label);
+
+ if (!message)
+ {
+ gtk_revealer_set_reveal_child (GTK_REVEALER (priv->info_revealer), FALSE);
+ return;
+ }
+
+ gtk_label_set_text (GTK_LABEL (priv->info_label), message);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (priv->info_revealer), TRUE);
+
+ switch (info_type)
+ {
+ case GTR_SEARCH_DIALOG_MSG_ERROR:
+ gtk_style_context_remove_class (ctx, "info");
+ gtk_style_context_add_class (ctx, "error");
+ break;
+ case GTR_SEARCH_DIALOG_MSG_INFO:
+ default:
+ gtk_style_context_remove_class (ctx, "error");
+ gtk_style_context_add_class (ctx, "info");
+ break;
+ }
+}
diff --git a/src/gtr-search-dialog.h b/src/gtr-search-dialog.h
index eb456dd5..816e8d7a 100644
--- a/src/gtr-search-dialog.h
+++ b/src/gtr-search-dialog.h
@@ -67,6 +67,12 @@ enum
GTR_SEARCH_DIALOG_REPLACE_ALL_RESPONSE
};
+typedef enum
+{
+ GTR_SEARCH_DIALOG_MSG_INFO,
+ GTR_SEARCH_DIALOG_MSG_ERROR
+} GtrSearchDialogMsg;
+
/*
* Public methods
*/
@@ -135,5 +141,10 @@ gtr_search_dialog_get_entire_word (GtrSearchDialog * dialog);
gboolean
gtr_search_dialog_get_wrap_around (GtrSearchDialog * dialog);
+void
+gtr_search_dialog_show_message (GtrSearchDialog * dialog,
+ char *message,
+ GtrSearchDialogMsg info_type);
+
G_END_DECLS
#endif /* __SEARCH_DIALOG_H__ */
diff --git a/src/gtr-search-dialog.ui b/src/gtr-search-dialog.ui
index 7e9efcea..a4ddb760 100644
--- a/src/gtr-search-dialog.ui
+++ b/src/gtr-search-dialog.ui
@@ -144,6 +144,30 @@
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkRevealer" id="info_revealer">
+ <property name="visible">True</property>
+ <property name="reveal_child">False</property>
+ <child>
+ <object class="GtkLabel" id="info_label">
+ <property name="name">info_label</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="no"></property>
+ <property name="xalign">0.5</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
<child>
<object class="GtkBox" id="vbox3">
<property name="visible">True</property>
@@ -279,7 +303,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
</object>
diff --git a/src/styles.css b/src/styles.css
index 71b41651..0abd42b3 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -31,3 +31,11 @@
.progress_untranslated {
color: @error_color;
}
+
+#info_label.error {
+ color: @error_color;
+}
+
+#info_label.info {
+ color: @theme_fg_color;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]