[evince/outline_search_improvements: 26/28] Explicitly enable Outline search




commit e4a851f7c41afbd4b0ad382fa63d26741f3e57fc
Author: Nelson Benítez León <nbenitezl gmail com>
Date:   Fri Jun 24 16:02:49 2022 +0100

    Explicitly enable Outline search
    
    when clicking the corresponding context menu item
    (instead of always being active) because otherwise
    it can interfer with the normal role of inputting
    page numbers.
    
    Fixes #1759

 libmisc/ev-page-action-widget.c | 22 ++++++++++++++++++++++
 libmisc/ev-page-action-widget.h |  1 +
 shell/ev-window.c               |  5 +++++
 3 files changed, 28 insertions(+)
---
diff --git a/libmisc/ev-page-action-widget.c b/libmisc/ev-page-action-widget.c
index 28296497f..d7db2a28d 100644
--- a/libmisc/ev-page-action-widget.c
+++ b/libmisc/ev-page-action-widget.c
@@ -53,6 +53,7 @@ struct _EvPageActionWidget
        gulong notify_document_signal_id;
        GtkTreeModel *filter_model;
        GtkTreeModel *model;
+       GtkEntryCompletion *completion;
 };
 
 static guint widget_signals[WIDGET_N_SIGNALS] = {0, };
@@ -200,6 +201,13 @@ activate_cb (EvPageActionWidget *action_widget)
                ev_page_action_widget_set_current_page (action_widget, current_page);
 }
 
+static gboolean
+disable_completion_search (EvPageActionWidget *action_widget)
+{
+       ev_page_action_widget_enable_completion_search (action_widget, FALSE);
+       return G_SOURCE_REMOVE;
+}
+
 static gboolean
 focus_out_cb (EvPageActionWidget *action_widget)
 {
@@ -207,6 +215,8 @@ focus_out_cb (EvPageActionWidget *action_widget)
                                                 ev_document_model_get_page (action_widget->doc_model));
         g_object_set (action_widget->entry, "xalign", 1.0, NULL);
         ev_page_action_widget_update_max_width (action_widget);
+        g_idle_add ((GSourceFunc)disable_completion_search, action_widget);
+
         return FALSE;
 }
 
@@ -343,6 +353,8 @@ ev_page_action_widget_finalize (GObject *object)
                action_widget->doc_model = NULL;
        }
 
+       g_clear_object (&action_widget->completion);
+
         ev_page_action_widget_set_document (action_widget, NULL);
 
        G_OBJECT_CLASS (ev_page_action_widget_parent_class)->finalize (object);
@@ -568,6 +580,8 @@ ev_page_action_widget_update_links_model (EvPageActionWidget *proxy, GtkTreeMode
        filter_model = get_filter_model_from_model (model);
 
        completion = gtk_entry_completion_new ();
+       g_clear_object (&proxy->completion);
+       proxy->completion = completion;
        g_object_set (G_OBJECT (completion),
                      "popup-set-width", FALSE,
                      "model", filter_model,
@@ -615,3 +629,11 @@ ev_page_action_widget_set_temporary_entry_width (EvPageActionWidget *proxy, gint
        /* xalign will also be restablished on focus_out */
        g_object_set (proxy->entry, "xalign", 0., NULL);
 }
+
+/* Enables or disables the completion search on @proxy according to @enable */
+void
+ev_page_action_widget_enable_completion_search (EvPageActionWidget *proxy, gboolean enable)
+{
+       GtkEntryCompletion *completion = enable ? proxy->completion : NULL;
+       gtk_entry_set_completion (GTK_ENTRY (proxy->entry), completion);
+}
\ No newline at end of file
diff --git a/libmisc/ev-page-action-widget.h b/libmisc/ev-page-action-widget.h
index f50055d25..0c89a8bfb 100644
--- a/libmisc/ev-page-action-widget.h
+++ b/libmisc/ev-page-action-widget.h
@@ -50,5 +50,6 @@ void ev_page_action_widget_set_model          (EvPageActionWidget *action_widget
 void ev_page_action_widget_grab_focus         (EvPageActionWidget *proxy);
 void ev_page_action_widget_clear              (EvPageActionWidget *proxy);
 void ev_page_action_widget_set_temporary_entry_width (EvPageActionWidget *proxy, gint width);
+void ev_page_action_widget_enable_completion_search (EvPageActionWidget *proxy, gboolean enable);
 
 G_END_DECLS
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 0c8f71ba0..b946eb643 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -4258,6 +4258,7 @@ ev_window_focus_page_selector (EvWindow *window)
  *    - Gives focus to the page selector entry
  *    - Clears the text in it.
  *    - Makes the text entry wider.
+ *    - Enables the completion search.
  *
  * All these changes will be restablished once the search
  * it's finished by means of the entry focus_out event.
@@ -4281,6 +4282,7 @@ ev_window_start_page_selector_search (EvWindow *window)
        ev_window_focus_page_selector (window);
        ev_page_action_widget_clear (action_widget);
        ev_page_action_widget_set_temporary_entry_width (action_widget, 15);
+       ev_page_action_widget_enable_completion_search (action_widget, TRUE);
 }
 
 static void
@@ -4605,6 +4607,9 @@ ev_window_update_links_model (EvWindow *window)
 
        page_selector = ev_toolbar_get_page_selector (EV_TOOLBAR (priv->toolbar));
        ev_page_action_widget_update_links_model (EV_PAGE_ACTION_WIDGET (page_selector), model);
+       /* Let's disable initially the completion search so it does not misfire when the user
+        * is entering page numbers. Fixes issue #1759 */
+       ev_page_action_widget_enable_completion_search (EV_PAGE_ACTION_WIDGET (page_selector), FALSE);
        g_object_unref (model);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]