[gucharmap] charmap: Start search for string given on command line
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gucharmap] charmap: Start search for string given on command line
- Date: Sun, 14 Feb 2016 10:47:27 +0000 (UTC)
commit a778484f29d4cd492e451ed24852f283b9798d17
Author: Christian Persch <chpe gnome org>
Date: Sun Feb 14 11:47:12 2016 +0100
charmap: Start search for string given on command line
https://bugzilla.gnome.org/show_bug.cgi?id=753581
gucharmap/gucharmap-search-dialog.c | 25 ++++++++++++++++++++-----
gucharmap/gucharmap-search-dialog.h | 2 ++
gucharmap/gucharmap-window.c | 32 ++++++++++++++++++++++++++------
gucharmap/gucharmap-window.h | 3 +++
gucharmap/main.c | 7 +++++++
5 files changed, 58 insertions(+), 11 deletions(-)
---
diff --git a/gucharmap/gucharmap-search-dialog.c b/gucharmap/gucharmap-search-dialog.c
index 685e994..1ee7692 100644
--- a/gucharmap/gucharmap-search-dialog.c
+++ b/gucharmap/gucharmap-search-dialog.c
@@ -587,7 +587,8 @@ search_completed (GucharmapSearchDialog *search_dialog)
gtk_widget_set_sensitive (priv->next_button, FALSE);
}
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (search_dialog)), NULL);
+ if (gtk_widget_get_realized (GTK_WIDGET (search_dialog)))
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (search_dialog)), NULL);
}
static gboolean
@@ -616,9 +617,11 @@ _gucharmap_search_dialog_fire_search (GucharmapSearchDialog *search_dialog,
if (priv->search_state && priv->search_state->searching) /* Already searching */
return;
- cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (search_dialog)), GDK_WATCH);
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (search_dialog)), cursor);
- g_object_unref (cursor);
+ if (gtk_widget_get_realized (GTK_WIDGET (search_dialog))) {
+ cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (search_dialog)), GDK_WATCH);
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (search_dialog)), cursor);
+ g_object_unref (cursor);
+ }
list = gucharmap_charmap_get_book_codepoint_list (priv->guw->charmap);
if (!list)
@@ -663,7 +666,7 @@ gucharmap_search_dialog_start_search (GucharmapSearchDialog *search_dialog,
{
GucharmapSearchDialogPrivate *priv = GUCHARMAP_SEARCH_DIALOG_GET_PRIVATE (search_dialog);
- if (priv->search_state != NULL && !_entry_is_empty (GTK_ENTRY (priv->entry)))
+ if (!_entry_is_empty (GTK_ENTRY (priv->entry)))
_gucharmap_search_dialog_fire_search (search_dialog, direction);
else
gtk_window_present (GTK_WINDOW (search_dialog));
@@ -853,6 +856,18 @@ gucharmap_search_dialog_present (GucharmapSearchDialog *search_dialog)
gtk_window_present (GTK_WINDOW (search_dialog));
}
+void
+gucharmap_search_dialog_set_search (GucharmapSearchDialog *search_dialog,
+ const char *search_string)
+{
+ GucharmapSearchDialogPrivate *priv;
+ g_return_if_fail (GUCHARMAP_IS_SEARCH_DIALOG (search_dialog));
+ g_return_if_fail (search_string != NULL);
+
+ priv = GUCHARMAP_SEARCH_DIALOG_GET_PRIVATE (search_dialog);
+ gtk_entry_set_text (GTK_ENTRY (priv->entry), search_string);
+}
+
gdouble
gucharmap_search_dialog_get_completed (GucharmapSearchDialog *search_dialog)
{
diff --git a/gucharmap/gucharmap-search-dialog.h b/gucharmap/gucharmap-search-dialog.h
index 2cb9476..345c886 100644
--- a/gucharmap/gucharmap-search-dialog.h
+++ b/gucharmap/gucharmap-search-dialog.h
@@ -61,6 +61,8 @@ GucharmapDirection;
GType gucharmap_search_dialog_get_type (void);
GtkWidget * gucharmap_search_dialog_new (GucharmapWindow *parent);
void gucharmap_search_dialog_present (GucharmapSearchDialog *search_dialog);
+void gucharmap_search_dialog_set_search (GucharmapSearchDialog *search_dialog,
+ const char *search_string);
void gucharmap_search_dialog_start_search (GucharmapSearchDialog *search_dialog,
GucharmapDirection direction);
gdouble gucharmap_search_dialog_get_completed (GucharmapSearchDialog *search_dialog);
diff --git a/gucharmap/gucharmap-window.c b/gucharmap/gucharmap-window.c
index c834cdb..eb42413 100644
--- a/gucharmap/gucharmap-window.c
+++ b/gucharmap/gucharmap-window.c
@@ -192,6 +192,17 @@ search_finish (GucharmapSearchDialog *search_dialog,
}
static void
+ensure_search_dialog (GucharmapWindow *guw)
+{
+ if (guw->search_dialog == NULL)
+ {
+ guw->search_dialog = gucharmap_search_dialog_new (guw);
+ g_signal_connect (guw->search_dialog, "search-start", G_CALLBACK (search_start), guw);
+ g_signal_connect (guw->search_dialog, "search-finish", G_CALLBACK (search_finish), guw);
+ }
+}
+
+static void
search_find (GSimpleAction *action,
GVariant *parameter,
gpointer data)
@@ -200,16 +211,12 @@ search_find (GSimpleAction *action,
g_assert (GUCHARMAP_IS_WINDOW (guw));
- if (guw->search_dialog == NULL)
- {
- guw->search_dialog = gucharmap_search_dialog_new (guw);
- g_signal_connect (guw->search_dialog, "search-start", G_CALLBACK (search_start), guw);
- g_signal_connect (guw->search_dialog, "search-finish", G_CALLBACK (search_finish), guw);
- }
+ ensure_search_dialog (guw);
gucharmap_search_dialog_present (GUCHARMAP_SEARCH_DIALOG (guw->search_dialog));
}
+
static void
search_find_next (GSimpleAction *action,
GVariant *parameter,
@@ -909,3 +916,16 @@ gucharmap_window_set_font (GucharmapWindow *guw,
gucharmap_charmap_set_font_desc (guw->charmap, font_desc);
pango_font_description_free (font_desc);
}
+
+void
+gucharmap_window_search (GucharmapWindow *guw,
+ const char *str)
+{
+ g_return_if_fail (GUCHARMAP_IS_WINDOW (guw));
+ g_return_if_fail (str != NULL);
+
+ ensure_search_dialog (guw);
+ gucharmap_search_dialog_set_search (GUCHARMAP_SEARCH_DIALOG (guw->search_dialog), str);
+ gucharmap_search_dialog_start_search (GUCHARMAP_SEARCH_DIALOG (guw->search_dialog),
+ GUCHARMAP_DIRECTION_FORWARD);
+}
diff --git a/gucharmap/gucharmap-window.h b/gucharmap/gucharmap-window.h
index f613b0c..b483296 100644
--- a/gucharmap/gucharmap-window.h
+++ b/gucharmap/gucharmap-window.h
@@ -69,6 +69,9 @@ GtkWidget * gucharmap_window_new (GtkApplication *application);
void gucharmap_window_set_font (GucharmapWindow *guw,
const char *font);
+void gucharmap_window_search (GucharmapWindow *guw,
+ const char *str);
+
G_END_DECLS
#endif /* #ifndef GUCHARMAP_WINDOW_H */
diff --git a/gucharmap/main.c b/gucharmap/main.c
index 0cd83c7..f8d44b0 100644
--- a/gucharmap/main.c
+++ b/gucharmap/main.c
@@ -268,6 +268,13 @@ main (int argc, char **argv)
gtk_window_present (GTK_WINDOW (window));
+ if (remaining) {
+ char *str = g_strjoinv (" ", remaining);
+ gucharmap_window_search (GUCHARMAP_WINDOW (window), str);
+ g_free (str);
+ g_strfreev (remaining);
+ }
+
status = g_application_run (G_APPLICATION (application), argc, argv);
g_object_unref (application);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]