[latexila] utils: don't call gtk_show_uri() (deprecated)



commit 5a3b9df61dd86ccc7feca5fc25bccd7a647637a5
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jun 17 13:17:48 2017 +0200

    utils: don't call gtk_show_uri() (deprecated)
    
    Call gtk_show_uri_on_window() instead.

 README                                |    2 +-
 configure.ac                          |    2 +-
 src/file_browser.vala                 |    6 +++---
 src/liblatexila/latexila-build-tool.c |    2 +-
 src/liblatexila/latexila-utils.c      |   21 +++++++++++++++++----
 src/liblatexila/latexila-utils.h      |    2 +-
 src/structure.vala                    |    2 +-
 7 files changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/README b/README
index 620b570..5ecffbb 100644
--- a/README
+++ b/README
@@ -16,7 +16,7 @@ Dependencies
 ------------
 
 * GLib >= 2.50
-* GTK+ >= 3.20
+* GTK+ >= 3.22
 * GtkSourceView >= 3.24
 * Tepl >= 2.99.0 - https://wiki.gnome.org/Projects/Tepl
 * gspell >= 1.0
diff --git a/configure.ac b/configure.ac
index d0bd0c2..0101b7f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,7 +30,7 @@ LT_INIT
 # Required dependencies versions
 # Update also the --target-glib option in src/Makefile.am.
 GLIB_REQUIRED_VERSION="2.50"
-GTK_REQUIRED_VERSION="3.20"
+GTK_REQUIRED_VERSION="3.22"
 GTKSOURCEVIEW_REQUIRED_VERSION="3.24"
 TEPL_REQUIRED_VERSION="2.99.0"
 GSPELL_REQUIRED_VERSION="1.0"
diff --git a/src/file_browser.vala b/src/file_browser.vala
index be223e9..b4d96fc 100644
--- a/src/file_browser.vala
+++ b/src/file_browser.vala
@@ -187,7 +187,7 @@ public class FileBrowser : Grid
 
             try
             {
-                Latexila.utils_show_uri (this.get_screen (), file.get_uri (), Gdk.CURRENT_TIME);
+                Latexila.utils_show_uri (this, file.get_uri (), Gdk.CURRENT_TIME);
             }
             catch (Error e)
             {
@@ -310,8 +310,8 @@ public class FileBrowser : Grid
 
             try
             {
-                Latexila.utils_show_uri (this.get_screen (),
-                    _current_directory.get_uri (), Gdk.CURRENT_TIME);
+                Latexila.utils_show_uri (this, _current_directory.get_uri (),
+                    Gdk.CURRENT_TIME);
             }
             catch (Error error)
             {
diff --git a/src/liblatexila/latexila-build-tool.c b/src/liblatexila/latexila-build-tool.c
index dc6d53b..fa3c3c7 100644
--- a/src/liblatexila/latexila-build-tool.c
+++ b/src/liblatexila/latexila-build-tool.c
@@ -558,7 +558,7 @@ query_exists_cb (GFile        *file,
 
   /* Show URI */
 
-  latexila_utils_show_uri (gtk_widget_get_screen (GTK_WIDGET (data->build_view)),
+  latexila_utils_show_uri (GTK_WIDGET (data->build_view),
                            uri,
                            GDK_CURRENT_TIME,
                            &error);
diff --git a/src/liblatexila/latexila-utils.c b/src/liblatexila/latexila-utils.c
index 60ccf12..194fc31 100644
--- a/src/liblatexila/latexila-utils.c
+++ b/src/liblatexila/latexila-utils.c
@@ -6,7 +6,7 @@
  * Copyright (C) 2000, 2002 - Chema Celorio, Paolo Maggi
  * Copyright (C) 2003-2005 - Paolo Maggi
  *
- * Copyright (C) 2014-2015 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2014, 2015, 2017 - Sébastien Wilmet <swilmet gnome org>
  *
  * LaTeXila is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -304,7 +304,7 @@ default_document_viewer_is_evince (const gchar *uri)
 
 /**
  * latexila_utils_show_uri:
- * @screen: (nullable): a #GdkScreen, or %NULL.
+ * @widget: (nullable): the associated #GtkWidget, or %NULL.
  * @uri: the URI to show.
  * @timestamp: a timestamp.
  * @error: (out) (optional): a %NULL #GError, or %NULL.
@@ -314,15 +314,28 @@ default_document_viewer_is_evince (const gchar *uri)
  * backward search works (switch from the PDF to the source file).
  */
 void
-latexila_utils_show_uri (GdkScreen    *screen,
+latexila_utils_show_uri (GtkWidget    *widget,
                          const gchar  *uri,
                          guint32       timestamp,
                          GError      **error)
 {
+  GtkWindow *parent = NULL;
+
+  g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
   g_return_if_fail (uri != NULL);
   g_return_if_fail (error == NULL || *error == NULL);
 
-  if (gtk_show_uri (screen, uri, timestamp, error))
+  if (widget != NULL)
+    {
+      GtkWidget *toplevel;
+
+      toplevel = gtk_widget_get_toplevel (widget);
+      if (gtk_widget_is_toplevel (toplevel) &&
+          GTK_IS_WINDOW (toplevel))
+        parent = GTK_WINDOW (toplevel);
+    }
+
+  if (gtk_show_uri_on_window (parent, uri, timestamp, error))
     {
       gchar *extension = latexila_utils_get_extension (uri);
 
diff --git a/src/liblatexila/latexila-utils.h b/src/liblatexila/latexila-utils.h
index b2bccaf..809982c 100644
--- a/src/liblatexila/latexila-utils.h
+++ b/src/liblatexila/latexila-utils.h
@@ -43,7 +43,7 @@ gboolean        latexila_utils_file_query_exists_finish         (GFile        *f
 gboolean        latexila_utils_create_parent_directories        (GFile   *file,
                                                                  GError **error);
 
-void            latexila_utils_show_uri                         (GdkScreen    *screen,
+void            latexila_utils_show_uri                         (GtkWidget    *widget,
                                                                  const gchar  *uri,
                                                                  guint32       timestamp,
                                                                  GError      **error);
diff --git a/src/structure.vala b/src/structure.vala
index 47ce718..57b2a8f 100644
--- a/src/structure.vala
+++ b/src/structure.vala
@@ -713,7 +713,7 @@ public class Structure : Grid
     {
         try
         {
-            Latexila.utils_show_uri (get_screen (), referenced_file.get_uri (), Gdk.CURRENT_TIME);
+            Latexila.utils_show_uri (this, referenced_file.get_uri (), Gdk.CURRENT_TIME);
         }
         catch (Error e)
         {


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