From ac080aa8c8aa2625fe31741803933fa46c8d090d Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Sun, 22 Dec 2024 15:35:03 +0530
Subject: [PATCH 1/3] Fix: open folder and highlight file

---
 thunar/thunar-location-entry.c | 50 +++++++++++++++++++++++++---------
 1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/thunar/thunar-location-entry.c b/thunar/thunar-location-entry.c
index 0893b03e9..18bf7d7ad 100644
--- a/thunar/thunar-location-entry.c
+++ b/thunar/thunar-location-entry.c
@@ -312,18 +312,20 @@ thunar_location_entry_accept_focus (ThunarLocationEntry *location_entry,
 
 
 static void
-thunar_location_entry_open_or_launch (ThunarLocationEntry *location_entry,
-                                      ThunarFile          *file)
+thunar_location_entry_open_or_highlight (ThunarLocationEntry *location_entry,
+                                         ThunarFile          *file)
 {
   GError *error = NULL;
 
   _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry));
   _thunar_return_if_fail (THUNAR_IS_FILE (file));
 
+  GFile *gfile = thunar_file_get_file(file);
+
   /* check if the file is mounted */
   if (thunar_file_is_mounted (file))
     {
-      /* check if we have a new directory or a file to launch */
+      /* check if we have a new directory or a file to highlight */
       if (thunar_file_is_directory (file))
         {
           /* open the new directory */
@@ -331,15 +333,35 @@ thunar_location_entry_open_or_launch (ThunarLocationEntry *location_entry,
         }
       else
         {
-          /* try to launch the selected file */
-          thunar_file_launch (file, location_entry->path_entry, NULL, &error);
-
-          /* be sure to reset the current file of the path entry */
-          if (G_LIKELY (location_entry->current_directory != NULL))
-            {
-              thunar_path_entry_set_current_file (THUNAR_PATH_ENTRY (location_entry->path_entry),
-                                                  location_entry->current_directory);
-            }
+          /* check if the file has a parent to which we can navigate to */
+          ThunarFile *parent = thunar_file_get_parent(file, &error);
+          if (parent != NULL)
+          {
+              // get the parent window first
+              GtkWidget *window = gtk_widget_get_toplevel(GTK_WIDGET(location_entry));
+
+              /* change to the parent directory */
+              thunar_navigator_change_directory(THUNAR_NAVIGATOR(location_entry), parent);
+
+              if (GTK_IS_WINDOW(window) && gtk_window_has_toplevel_focus(GTK_WINDOW(window)) == TRUE)
+              {
+                  GList *selected = NULL;
+
+                  /* ensure gfile is not NULL and is a valid GFile before appending */
+                  if (gfile != NULL && G_IS_FILE(gfile))
+                  {
+                      selected = g_list_append(selected, gfile);
+
+                      if (selected != NULL)
+                      {
+                          thunar_window_show_and_select_files(THUNAR_WINDOW(window), selected);
+                          g_list_free(selected); 
+                      }
+                  }
+              }
+
+              g_object_unref(parent);
+          }
         }
     }
   else
@@ -360,6 +382,8 @@ thunar_location_entry_open_or_launch (ThunarLocationEntry *location_entry,
       /* add opened file to `recent:///` */
       thunar_file_add_to_recent (file);
     }
+
+  // g_object_unref(gfile);
 }
 
 
@@ -377,7 +401,7 @@ thunar_location_entry_poke_file_finish (ThunarBrowser *browser,
   if (error == NULL)
     {
       /* try to open or launch the target file */
-      thunar_location_entry_open_or_launch (THUNAR_LOCATION_ENTRY (browser),
+      thunar_location_entry_open_or_highlight (THUNAR_LOCATION_ENTRY (browser),
                                             target_file);
     }
   else
-- 
GitLab


From 630d99872861e6d494dfc6789d487cc71c1ee5af Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Sun, 22 Dec 2024 17:17:16 +0530
Subject: [PATCH 2/3] Remove debug comments

---
 thunar/thunar-location-entry.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/thunar/thunar-location-entry.c b/thunar/thunar-location-entry.c
index 18bf7d7ad..0b417ec77 100644
--- a/thunar/thunar-location-entry.c
+++ b/thunar/thunar-location-entry.c
@@ -382,8 +382,6 @@ thunar_location_entry_open_or_highlight (ThunarLocationEntry *location_entry,
       /* add opened file to `recent:///` */
       thunar_file_add_to_recent (file);
     }
-
-  // g_object_unref(gfile);
 }
 
 
-- 
GitLab


From c60df18066d43ba7a1f46f628ca41e91e2591a0e Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Sun, 22 Dec 2024 18:20:13 +0530
Subject: [PATCH 3/3] Fixed formatting

---
 thunar/thunar-location-entry.c | 40 +++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/thunar/thunar-location-entry.c b/thunar/thunar-location-entry.c
index 0b417ec77..dd885944c 100644
--- a/thunar/thunar-location-entry.c
+++ b/thunar/thunar-location-entry.c
@@ -320,7 +320,7 @@ thunar_location_entry_open_or_highlight (ThunarLocationEntry *location_entry,
   _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry));
   _thunar_return_if_fail (THUNAR_IS_FILE (file));
 
-  GFile *gfile = thunar_file_get_file(file);
+  GFile *gfile = thunar_file_get_file (file);
 
   /* check if the file is mounted */
   if (thunar_file_is_mounted (file))
@@ -334,34 +334,34 @@ thunar_location_entry_open_or_highlight (ThunarLocationEntry *location_entry,
       else
         {
           /* check if the file has a parent to which we can navigate to */
-          ThunarFile *parent = thunar_file_get_parent(file, &error);
+          ThunarFile *parent = thunar_file_get_parent (file, &error);
           if (parent != NULL)
-          {
+            {
               // get the parent window first
-              GtkWidget *window = gtk_widget_get_toplevel(GTK_WIDGET(location_entry));
+              GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET (location_entry));
 
               /* change to the parent directory */
-              thunar_navigator_change_directory(THUNAR_NAVIGATOR(location_entry), parent);
+              thunar_navigator_change_directory (THUNAR_NAVIGATOR (location_entry), parent);
 
-              if (GTK_IS_WINDOW(window) && gtk_window_has_toplevel_focus(GTK_WINDOW(window)) == TRUE)
-              {
+              if (GTK_IS_WINDOW (window) && gtk_window_has_toplevel_focus (GTK_WINDOW (window)) == TRUE)
+                {
                   GList *selected = NULL;
 
                   /* ensure gfile is not NULL and is a valid GFile before appending */
-                  if (gfile != NULL && G_IS_FILE(gfile))
-                  {
-                      selected = g_list_append(selected, gfile);
+                  if (gfile != NULL && G_IS_FILE (gfile))
+                    {
+                      selected = g_list_append (selected, gfile);
 
                       if (selected != NULL)
-                      {
-                          thunar_window_show_and_select_files(THUNAR_WINDOW(window), selected);
-                          g_list_free(selected); 
-                      }
-                  }
-              }
-
-              g_object_unref(parent);
-          }
+                        {
+                          thunar_window_show_and_select_files (THUNAR_WINDOW (window), selected);
+                          g_list_free (selected);
+                        }
+                    }
+                }
+
+              g_object_unref (parent);
+            }
         }
     }
   else
@@ -400,7 +400,7 @@ thunar_location_entry_poke_file_finish (ThunarBrowser *browser,
     {
       /* try to open or launch the target file */
       thunar_location_entry_open_or_highlight (THUNAR_LOCATION_ENTRY (browser),
-                                            target_file);
+                                               target_file);
     }
   else
     {
-- 
GitLab