[gnome-builder/file-monitor: 2/2] editor: dont allow editing when buffer is read only



commit 00615217b1f9dae37191bd95b2834ea5723453cf
Author: Christian Hergert <christian hergert me>
Date:   Thu Dec 11 18:31:39 2014 -0800

    editor: dont allow editing when buffer is read only

 src/editor/gb-editor-document.c |   12 ++++++++----
 src/editor/gb-editor-frame.c    |    7 +++++++
 2 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/src/editor/gb-editor-document.c b/src/editor/gb-editor-document.c
index c92e66c..914e5ae 100644
--- a/src/editor/gb-editor-document.c
+++ b/src/editor/gb-editor-document.c
@@ -100,6 +100,8 @@ static void
 gb_editor_document_set_read_only (GbEditorDocument *document,
                                   gboolean          read_only)
 {
+  ENTRY;
+
   g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
 
   if (document->priv->read_only != read_only)
@@ -108,6 +110,8 @@ gb_editor_document_set_read_only (GbEditorDocument *document,
       g_object_notify_by_pspec (G_OBJECT (document),
                                 gParamSpecs [PROP_READ_ONLY]);
     }
+
+  EXIT;
 }
 
 gboolean
@@ -153,8 +157,8 @@ gb_editor_document_check_modified_cb (GObject      *object,
         {
           gboolean read_only;
 
-          read_only = g_file_info_get_attribute_boolean (info,
-                                                         G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+          read_only = !g_file_info_get_attribute_boolean (info,
+                                                          G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
           gb_editor_document_set_read_only (document, read_only);
         }
 
@@ -690,8 +694,8 @@ gb_editor_document_load_info_cb (GObject      *object,
         {
           gboolean read_only;
 
-          read_only = g_file_info_get_attribute_boolean (info,
-                                                         G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+          read_only = !g_file_info_get_attribute_boolean (info,
+                                                          G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
           gb_editor_document_set_read_only (document, read_only);
         }
 
diff --git a/src/editor/gb-editor-frame.c b/src/editor/gb-editor-frame.c
index ad49990..7aa23a4 100644
--- a/src/editor/gb-editor-frame.c
+++ b/src/editor/gb-editor-frame.c
@@ -472,6 +472,13 @@ gb_editor_frame_connect (GbEditorFrame    *frame,
                           G_BINDING_SYNC_CREATE);
 
   /*
+   * Don't allow editing if the buffer is read-only.
+   */
+  g_object_bind_property (priv->document, "read-only",
+                          priv->source_view, "editable",
+                          G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
+
+  /*
    * Create search defaults for this frame.
    */
   priv->search_context = g_object_new (GTK_SOURCE_TYPE_SEARCH_CONTEXT,


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