[Xfce4-commits] <thunar:master> Add support for tabs in session saving.

Nick Schermer noreply at xfce.org
Sat Nov 10 19:50:02 CET 2012


Updating branch refs/heads/master
         to 8a0a47f026a37508f3d0d3d4e11ec3a60411ce41 (commit)
       from 3033ee89afff7a94561ec639910128fd17aabf69 (commit)

commit 8a0a47f026a37508f3d0d3d4e11ec3a60411ce41
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Nov 10 20:48:09 2012 +0100

    Add support for tabs in session saving.

 thunar/thunar-session-client.c |   66 ++++++++++++++++++---------------
 thunar/thunar-standard-view.c  |    1 +
 thunar/thunar-window.c         |   78 ++++++++++++++++++++++++++++++++++++++++
 thunar/thunar-window.h         |    6 +++
 4 files changed, 121 insertions(+), 30 deletions(-)

diff --git a/thunar/thunar-session-client.c b/thunar/thunar-session-client.c
index 7c59921..965f6a0 100644
--- a/thunar/thunar-session-client.c
+++ b/thunar/thunar-session-client.c
@@ -269,12 +269,12 @@ static void
 thunar_session_client_restore (ThunarSessionClient *session_client)
 {
   ThunarApplication *application;
-  const gchar       *uri;
-  ThunarFile        *directory;
+  gchar            **uris;
   GtkWidget         *window;
   XfceRc            *rc;
   gchar            **roles;
   guint              n;
+  gint               active_tab;
 
   /* try to open the session file */
   rc = xfce_rc_simple_open (session_client->path, TRUE);
@@ -288,33 +288,33 @@ thunar_session_client_restore (ThunarSessionClient *session_client)
   roles = xfce_rc_get_groups (rc);
   for (n = 0; roles[n] != NULL; ++n)
     {
+      /* skip the null group */
+      if (strcmp (roles[n], "[NULL]") == 0)
+        continue;
+
       /* enter the group */
       xfce_rc_set_group (rc, roles[n]);
 
       /* determine the URI for the new window */
-      uri = xfce_rc_read_entry (rc, "URI", NULL);
-      if (G_UNLIKELY (uri == NULL))
+      uris = xfce_rc_read_list_entry (rc, "URI", ";");
+      g_message ("%d uris", uris ? g_strv_length (uris) : 0);
+      if (G_UNLIKELY (uris == NULL))
         continue;
 
-      /* determine the directory for the new window */
-      directory = thunar_file_get_for_uri (uri, NULL);
-      if (G_UNLIKELY (directory == NULL))
-        continue;
+      /* active tab */
+      active_tab = xfce_rc_read_int_entry (rc, "PAGE", -1);
 
-      /* verify that we have a directory */
-      if (thunar_file_is_directory (directory))
-        {
-          /* open the new window */
-          window = g_object_new (THUNAR_TYPE_WINDOW,
-                                 "current-directory", directory,
-                                 "role", roles[n],
-                                 NULL);
-          thunar_application_take_window (application, GTK_WINDOW (window));
-          gtk_widget_show (window);
-        }
+      /* open the new window */
+      window = g_object_new (THUNAR_TYPE_WINDOW, "role", roles[n], NULL);
+      thunar_application_take_window (application, GTK_WINDOW (window));
+      gtk_widget_show (window);
+
+      /* open tabs */
+      if (!thunar_window_set_directories (THUNAR_WINDOW (window), uris, active_tab))
+        gtk_widget_destroy (window);
 
       /* cleanup */
-      g_object_unref (G_OBJECT (directory));
+      g_strfreev (uris);
     }
 
   /* cleanup */
@@ -358,11 +358,12 @@ thunar_session_client_save_yourself (SmcConn              connection,
 {
   ThunarApplication *application;
   const gchar       *role;
-  ThunarFile        *directory;
+  gchar            **uris;
   GList             *windows;
   GList             *lp;
-  gchar             *uri;
+  guint              n;
   FILE              *fp;
+  gint               active_page;
 
   _thunar_return_if_fail (THUNAR_IS_SESSION_CLIENT (session_client));
   _thunar_return_if_fail (session_client->connection == connection);
@@ -382,21 +383,26 @@ thunar_session_client_save_yourself (SmcConn              connection,
             {
               for (lp = windows; lp != NULL; lp = lp->next)
                 {
-                  /* determine the directory for the window */
-                  directory = thunar_window_get_current_directory (lp->data);
-                  if (G_UNLIKELY (directory == NULL))
-                    continue;
-
                   /* determine the role for the window */
                   role = gtk_window_get_role (lp->data);
                   if (G_UNLIKELY (role == NULL))
                     continue;
 
+                  /* determine the directories for the window */
+                  uris = thunar_window_get_directories (lp->data, &active_page);
+                  if (G_UNLIKELY (uris == NULL))
+                    continue;
+
                   /* save the window */
-                  uri = thunar_file_dup_uri (directory);
                   fprintf (fp, "[%s]\n", role);
-                  fprintf (fp, "URI=%s\n\n", uri);
-                  g_free (uri);
+                  fprintf (fp, "PAGE=%d\n", active_page);
+                  fprintf (fp, "URI=");
+                  for (n = 0; uris[n] != NULL; n++)
+                    fprintf (fp, "%s;", uris[n]);
+                  fprintf (fp, "\n\n");
+
+                  /* cleanup */
+                  g_strfreev (uris);
                 }
 
               /* cleanup */
diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c
index e2050eb..4f24a1e 100644
--- a/thunar/thunar-standard-view.c
+++ b/thunar/thunar-standard-view.c
@@ -3816,6 +3816,7 @@ thunar_standard_view_request_thumbnails_real (ThunarStandardView *standard_view,
   GList       *visible_files = NULL;
 
   _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view), FALSE);
+  _thunar_return_val_if_fail (THUNAR_IS_ICON_FACTORY (standard_view->icon_factory), FALSE);
 
   /* determine whether the user wants us to create thumbnails */
   g_object_get (standard_view->icon_factory, "show-thumbnails", &show_thumbnails, NULL);
diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index 1761f2b..9ff29aa 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -3585,3 +3585,81 @@ thunar_window_scroll_to_file (ThunarWindow *window,
 }
 
 
+
+gchar **
+thunar_window_get_directories (ThunarWindow *window,
+                               gint         *active_page)
+{
+  gint         n;
+  gint         n_pages;
+  gchar      **uris;
+  GtkWidget   *view;
+  ThunarFile  *directory;
+
+  _thunar_return_val_if_fail (THUNAR_IS_WINDOW (window), NULL);
+
+  n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook));
+  if (G_UNLIKELY (n_pages == 0))
+    return NULL;
+
+  /* create array of uris */
+  uris = g_new0 (gchar *, n_pages + 1);
+  for (n = 0; n < n_pages; n++)
+    {
+      /* get the view */
+      view = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), n);
+      _thunar_return_val_if_fail (THUNAR_IS_NAVIGATOR (view), FALSE);
+
+      /* get the directory of the view */
+      directory = thunar_navigator_get_current_directory (THUNAR_NAVIGATOR (view));
+      _thunar_return_val_if_fail (THUNAR_IS_FILE (directory), FALSE);
+
+      /* add to array */
+      uris[n] = thunar_file_dup_uri (directory);
+    }
+
+  /* selected tab */
+  if (active_page != NULL)
+    *active_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (window->notebook));
+
+  return uris;
+}
+
+
+
+gboolean
+thunar_window_set_directories (ThunarWindow   *window,
+                               gchar         **uris,
+                               gint            active_page)
+{
+  ThunarFile *directory;
+  guint       n;
+
+  _thunar_return_val_if_fail (THUNAR_IS_WINDOW (window), FALSE);
+  _thunar_return_val_if_fail (uris != NULL, FALSE);
+
+  for (n = 0; uris[n] != NULL; n++)
+    {
+      /* get the file for the uri */
+      directory = thunar_file_get_for_uri (uris[n], NULL);
+      if (G_UNLIKELY (directory == NULL))
+        continue;
+
+      /* open the directory in a new notebook */
+      if (thunar_file_is_directory (directory))
+        {
+          if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook)) == 0)
+            thunar_window_set_current_directory (window, directory);
+          else
+            thunar_window_notebook_insert (window, directory);
+        }
+
+      g_object_unref (G_OBJECT (directory));
+    }
+
+  /* select the page */
+  gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), active_page);
+
+  /* we succeeded if new pages have been opened */
+  return gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook)) > 0;
+}
diff --git a/thunar/thunar-window.h b/thunar/thunar-window.h
index d78c6e8..095efa0 100644
--- a/thunar/thunar-window.h
+++ b/thunar/thunar-window.h
@@ -48,6 +48,12 @@ void            thunar_window_scroll_to_file        (ThunarWindow   *window,
                                                      gfloat          row_align,
                                                      gfloat          col_align);
 
+gchar         **thunar_window_get_directories       (ThunarWindow   *window,
+                                                     gint           *active_page);
+gboolean        thunar_window_set_directories       (ThunarWindow   *window,
+                                                     gchar         **uris,
+                                                     gint            active_page);
+
 G_END_DECLS;
 
 #endif /* !__THUNAR_WINDOW_H__ */


More information about the Xfce4-commits mailing list