[gnome-text-editor] page: use "Document Portal" when directory is unknown



commit febeb2d509d863bd679bcfd0dcc5c17a599545bb
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jan 18 14:19:19 2022 -0800

    page: use "Document Portal" when directory is unknown
    
    If we don't know where the directory is on the host filesystem, then tell
    the user that by showing "Document Portal" for the page subtitle as well
    as the file subtitle in the open popover.
    
    Fixes #153

 src/editor-page.c         | 12 +++++++++++-
 src/editor-sidebar-item.c | 22 +++++++++++++++++++---
 2 files changed, 30 insertions(+), 4 deletions(-)
---
diff --git a/src/editor-page.c b/src/editor-page.c
index 4440034..307a171 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -24,6 +24,7 @@
 
 #include <adwaita.h>
 #include <glib/gi18n.h>
+#include <unistd.h>
 
 #include "editor-application-private.h"
 #include "editor-info-bar-private.h"
@@ -965,12 +966,17 @@ editor_page_dup_title (EditorPage *self)
 gchar *
 editor_page_dup_subtitle (EditorPage *self)
 {
+  static char *docportal = NULL;
   g_autoptr(GFile) dir = NULL;
+  const char *peek;
   GFile *file;
 
   g_return_val_if_fail (EDITOR_IS_PAGE (self), NULL);
   g_return_val_if_fail (EDITOR_IS_DOCUMENT (self->document), NULL);
 
+  if (docportal == NULL)
+    docportal = g_strdup_printf ("/run/user/%u/doc/", getuid ());
+
   file = editor_document_get_file (self->document);
 
   if (file == NULL || !(dir = g_file_get_parent (file)))
@@ -992,7 +998,11 @@ editor_page_dup_subtitle (EditorPage *self)
       return g_steal_pointer (&uri);
     }
 
-  return _editor_path_collapse (g_file_peek_path (dir));
+  peek = g_file_peek_path (dir);
+  if (g_str_has_prefix (peek, docportal))
+    return g_strdup (_("Document Portal"));
+
+  return _editor_path_collapse (peek);
 }
 
 void
diff --git a/src/editor-sidebar-item.c b/src/editor-sidebar-item.c
index 8d449b5..2b2cd30 100644
--- a/src/editor-sidebar-item.c
+++ b/src/editor-sidebar-item.c
@@ -23,6 +23,7 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
+#include <unistd.h>
 
 #include "editor-application.h"
 #include "editor-document-private.h"
@@ -68,10 +69,14 @@ static GParamSpec *properties [N_PROPS];
 static void
 editor_sidebar_item_update_subtitle (EditorSidebarItem *self)
 {
+  static char *docportal = NULL;
   g_autoptr(GFile) dir = NULL;
 
   g_assert (EDITOR_IS_SIDEBAR_ITEM (self));
 
+  if (docportal == NULL)
+    docportal = g_strdup_printf ("/run/user/%u/doc/", getuid ());
+
   g_free (self->subtitle);
 
   if (self->file == NULL)
@@ -82,11 +87,22 @@ editor_sidebar_item_update_subtitle (EditorSidebarItem *self)
 
   /* Can happen, but implausible since someone tried to open "/" */
   if (!(dir = g_file_get_parent (self->file)))
-    self->subtitle = g_strdup ("");
+    {
+      self->subtitle = g_strdup ("");
+    }
   else if (g_file_is_native (dir))
-    self->subtitle = _editor_path_collapse (g_file_peek_path (dir));
+    {
+      const char *peek = g_file_peek_path (dir);
+
+      if (g_str_has_prefix (peek, docportal))
+        self->subtitle = g_strdup (_("Document Portal"));
+      else
+        self->subtitle = _editor_path_collapse (g_file_peek_path (dir));
+    }
   else
-    self->subtitle = g_file_get_uri (dir);
+    {
+      self->subtitle = g_file_get_uri (dir);
+    }
 }
 
 static void


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