[gnome-text-editor] page: add "lock" icon for admin:// documents



commit e22d08c172b7410f5263511632774d9a09a584f0
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jan 10 14:18:34 2022 -0800

    page: add "lock" icon for admin:// documents
    
    If we are opening a priveleged file with admin:/// access via GVFS, then
    we want to show an icon for that to the user.
    
    Related #262

 .../scalable/actions/document-admin-symbolic.svg   |  2 ++
 src/editor-page.c                                  | 37 ++++++++++++++++++++++
 src/editor-window.c                                |  1 +
 3 files changed, 40 insertions(+)
---
diff --git a/data/icons/hicolor/scalable/actions/document-admin-symbolic.svg 
b/data/icons/hicolor/scalable/actions/document-admin-symbolic.svg
new file mode 100644
index 0000000..22f7378
--- /dev/null
+++ b/data/icons/hicolor/scalable/actions/document-admin-symbolic.svg
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg"; xmlns:xlink="http://www.w3.org/1999/xlink"; height="16px" viewBox="0 
0 16 16" width="16px"><filter id="a" height="100%" width="100%" x="0%" y="0%"><feColorMatrix 
in="SourceGraphic" type="matrix" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/></filter><mask id="b"><g 
filter="url(#a)"><path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.3"/></g></mask><clipPath id="c"><path d="m 
0 0 h 1600 v 1200 h -1600 z"/></clipPath><mask id="d"><g filter="url(#a)"><path d="m 0 0 h 16 v 16 h -16 z" 
fill-opacity="0.05"/></g></mask><clipPath id="e"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><mask 
id="f"><g filter="url(#a)"><path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.05"/></g></mask><clipPath 
id="g"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><mask id="h"><g filter="url(#a)"><path d="m 0 0 h 
16 v 16 h -16 z" fill-opacity="0.05"/></g></mask><clipPath id="i"><path d="m 0 0 h 1600 v 1200 h -1600 
z"/></clipPath><mask id="j"><g filter="url(#a)">
 <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.05"/></g></mask><clipPath id="k"><path d="m 0 0 h 1600 v 
1200 h -1600 z"/></clipPath><mask id="l"><g filter="url(#a)"><path d="m 0 0 h 16 v 16 h -16 z" 
fill-opacity="0.05"/></g></mask><clipPath id="m"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><mask 
id="n"><g filter="url(#a)"><path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.05"/></g></mask><clipPath 
id="o"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><mask id="p"><g filter="url(#a)"><path d="m 0 0 h 
16 v 16 h -16 z" fill-opacity="0.3"/></g></mask><clipPath id="q"><path d="m 0 0 h 1600 v 1200 h -1600 
z"/></clipPath><mask id="r"><g filter="url(#a)"><path d="m 0 0 h 16 v 16 h -16 z" 
fill-opacity="0.5"/></g></mask><clipPath id="s"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><g 
clip-path="url(#c)" mask="url(#b)" transform="matrix(1 0 0 1 -40 -356)"><path d="m 562.460938 212.058594 h 
10.449218 c -1.183594 0.492187 -1.296875 2.460937 0 3 h -10.449218 z m 0 0" fill="
 #2e3436"/></g><g clip-path="url(#e)" mask="url(#d)" transform="matrix(1 0 0 1 -40 -356)"><path d="m 16 748 h 
1 v 1 h -1 z m 0 0" fill="#2e3436" fill-rule="evenodd"/></g><g clip-path="url(#g)" mask="url(#f)" 
transform="matrix(1 0 0 1 -40 -356)"><path d="m 17 747 h 1 v 1 h -1 z m 0 0" fill="#2e3436" 
fill-rule="evenodd"/></g><g clip-path="url(#i)" mask="url(#h)" transform="matrix(1 0 0 1 -40 -356)"><path 
d="m 18 750 h 1 v 1 h -1 z m 0 0" fill="#2e3436" fill-rule="evenodd"/></g><g clip-path="url(#k)" 
mask="url(#j)" transform="matrix(1 0 0 1 -40 -356)"><path d="m 16 750 h 1 v 1 h -1 z m 0 0" fill="#2e3436" 
fill-rule="evenodd"/></g><g clip-path="url(#m)" mask="url(#l)" transform="matrix(1 0 0 1 -40 -356)"><path 
d="m 17 751 h 1 v 1 h -1 z m 0 0" fill="#2e3436" fill-rule="evenodd"/></g><g clip-path="url(#o)" 
mask="url(#n)" transform="matrix(1 0 0 1 -40 -356)"><path d="m 19 751 h 1 v 1 h -1 z m 0 0" fill="#2e3436" 
fill-rule="evenodd"/></g><g clip-path="url(#q)" mask="url(#p)" transform="matr
 ix(1 0 0 1 -40 -356)"><path d="m 136 776 v 7 h 7 v -7 z m 0 0" fill="#2e3436"/></g><g clip-path="url(#s)" 
mask="url(#r)" transform="matrix(1 0 0 1 -40 -356)"><path d="m 219 758 h 3 v 12 h -3 z m 0 0" 
fill="#2e3436"/></g><path d="m 6 1 c -1.644531 0 -3 1.355469 -3 3 v 2.976562 h -1 c -0.554688 0 -1 0.445313 
-1 1 v 7.023438 h 14 v -7.023438 c 0 -0.554687 -0.445312 -0.988281 -1 -1 h -1 v -2.976562 c 0 -1.644531 
-1.355469 -3 -3 -3 z m 0 2 h 4 c 0.570312 0 1 0.429688 1 1 v 2.976562 h -6 v -2.976562 c 0 -0.570312 0.429688 
-1 1 -1 z m 0 0" fill="#2e3436"/></svg>
diff --git a/src/editor-page.c b/src/editor-page.c
index 27e29e9..bfe4bd9 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -38,6 +38,7 @@ enum {
   PROP_BUSY,
   PROP_CAN_SAVE,
   PROP_DOCUMENT,
+  PROP_INDICATOR,
   PROP_IS_MODIFIED,
   PROP_LANGUAGE_NAME,
   PROP_POSITION_LABEL,
@@ -198,6 +199,7 @@ editor_page_document_notify_file_cb (EditorPage     *self,
   g_assert (EDITOR_IS_PAGE (self));
   g_assert (EDITOR_IS_DOCUMENT (document));
 
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INDICATOR]);
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TITLE]);
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SUBTITLE]);
 }
@@ -558,6 +560,30 @@ editor_page_get_language_name (EditorPage *self)
   return NULL;
 }
 
+static GIcon *
+editor_page_get_indicator (EditorPage *self)
+{
+  static GIcon *icon;
+  g_autofree char *uri = NULL;
+  EditorDocument *document;
+  GFile *file;
+
+  document = editor_page_get_document (self);
+  file = editor_document_get_file (document);
+
+  if (file == NULL)
+    return NULL;
+
+  uri = g_file_get_uri (file);
+  if (!g_str_has_prefix (uri, "admin://"))
+    return NULL;
+
+  if (icon == NULL)
+    icon = g_themed_icon_new ("document-admin-symbolic");
+
+  return icon;
+}
+
 static void
 editor_page_dispose (GObject *object)
 {
@@ -605,6 +631,10 @@ editor_page_get_property (GObject    *object,
       g_value_set_object (value, editor_page_get_document (self));
       break;
 
+    case PROP_INDICATOR:
+      g_value_set_object (value, editor_page_get_indicator (self));
+      break;
+
     case PROP_IS_MODIFIED:
       g_value_set_boolean (value, editor_page_get_is_modified (self));
       break;
@@ -690,6 +720,13 @@ editor_page_class_init (EditorPageClass *klass)
                          EDITOR_TYPE_DOCUMENT,
                          (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_INDICATOR] =
+    g_param_spec_object ("indicator",
+                         "Indicator",
+                         "The document indicator if any",
+                         G_TYPE_ICON,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_LANGUAGE_NAME] =
     g_param_spec_string ("language-name",
                          "Language Name",
diff --git a/src/editor-window.c b/src/editor-window.c
index 56e89c7..4e5e44b 100644
--- a/src/editor-window.c
+++ b/src/editor-window.c
@@ -1073,6 +1073,7 @@ _editor_window_add_page (EditorWindow *self,
 
   g_object_bind_property (page, "title", tab_page, "title", G_BINDING_SYNC_CREATE);
   g_object_bind_property (page, "busy", tab_page, "loading", G_BINDING_SYNC_CREATE);
+  g_object_bind_property (page, "indicator", tab_page, "indicator-icon", G_BINDING_SYNC_CREATE);
   g_object_bind_property_full (page, "is-modified",
                                tab_page, "icon",
                                G_BINDING_SYNC_CREATE,


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