~denim2x/gtksourceview/gtksourceview

« back to all changes in this revision

Viewing changes to gtksourceview/gtksourcefile.c

  • Committer: Sébastien Wilmet
  • Date: 2015-06-11 15:39:39 UTC
  • Revision ID: git-v1:9da23808cfb3c2c1d7a18fb58483f3ac2384d686
file: add the read-only property

The code comes from GeditDocument.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        PROP_LOCATION,
46
46
        PROP_ENCODING,
47
47
        PROP_NEWLINE_TYPE,
48
 
        PROP_COMPRESSION_TYPE
 
48
        PROP_COMPRESSION_TYPE,
 
49
        PROP_READ_ONLY
49
50
};
50
51
 
51
52
struct _GtkSourceFilePrivate
68
69
 
69
70
        guint externally_modified : 1;
70
71
        guint deleted : 1;
 
72
        guint readonly : 1;
71
73
};
72
74
 
73
75
G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceFile, gtk_source_file, G_TYPE_OBJECT)
102
104
                        g_value_set_enum (value, file->priv->compression_type);
103
105
                        break;
104
106
 
 
107
                case PROP_READ_ONLY:
 
108
                        g_value_set_boolean (value, file->priv->readonly);
 
109
                        break;
 
110
 
105
111
                default:
106
112
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
107
113
                        break;
224
230
                                                            GTK_SOURCE_COMPRESSION_TYPE_NONE,
225
231
                                                            G_PARAM_READABLE |
226
232
                                                            G_PARAM_STATIC_STRINGS));
 
233
 
 
234
        /**
 
235
         * GtkSourceFile:read-only:
 
236
         *
 
237
         * Whether the file is read-only or not. The value of this property is
 
238
         * not updated automatically (there is no file monitors).
 
239
         *
 
240
         * Since: 3.18
 
241
         */
 
242
        g_object_class_install_property (object_class,
 
243
                                         PROP_READ_ONLY,
 
244
                                         g_param_spec_boolean ("read-only",
 
245
                                                               "Read Only",
 
246
                                                               "",
 
247
                                                               FALSE,
 
248
                                                               G_PARAM_READABLE |
 
249
                                                               G_PARAM_STATIC_STRINGS));
227
250
}
228
251
 
229
252
static void
467
490
        }
468
491
 
469
492
        info = g_file_query_info (file->priv->location,
470
 
                                  G_FILE_ATTRIBUTE_TIME_MODIFIED,
 
493
                                  G_FILE_ATTRIBUTE_TIME_MODIFIED ","
 
494
                                  G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
471
495
                                  G_FILE_QUERY_INFO_NONE,
472
496
                                  NULL,
473
497
                                  NULL);
475
499
        if (info == NULL)
476
500
        {
477
501
                file->priv->deleted = TRUE;
 
502
                return;
478
503
        }
479
 
        else if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED) &&
480
 
                 file->priv->modification_time_set)
 
504
 
 
505
        if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED) &&
 
506
            file->priv->modification_time_set)
481
507
        {
482
508
                GTimeVal timeval;
483
509
 
493
519
                }
494
520
        }
495
521
 
496
 
        g_clear_object (&info);
 
522
        if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
 
523
        {
 
524
                gboolean readonly;
 
525
 
 
526
                readonly = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
 
527
 
 
528
                _gtk_source_file_set_readonly (file, readonly);
 
529
        }
 
530
 
 
531
        g_object_unref (info);
497
532
}
498
533
 
499
534
void
559
594
 
560
595
        return file->priv->deleted;
561
596
}
 
597
 
 
598
void
 
599
_gtk_source_file_set_readonly (GtkSourceFile *file,
 
600
                               gboolean       readonly)
 
601
{
 
602
        g_return_if_fail (GTK_SOURCE_IS_FILE (file));
 
603
 
 
604
        readonly = readonly != FALSE;
 
605
 
 
606
        if (file->priv->readonly != readonly)
 
607
        {
 
608
                file->priv->readonly = readonly;
 
609
                g_object_notify (G_OBJECT (file), "read-only");
 
610
        }
 
611
}
 
612
 
 
613
/**
 
614
 * gtk_source_file_is_readonly:
 
615
 * @file: a #GtkSourceFile.
 
616
 *
 
617
 * Checks synchronously whether the file is read-only. If the
 
618
 * #GtkSourceFile:location is %NULL, returns FALSE.
 
619
 *
 
620
 * Returns: whether the file is read-only.
 
621
 * Since: 3.18
 
622
 */
 
623
gboolean
 
624
gtk_source_file_is_readonly (GtkSourceFile *file)
 
625
{
 
626
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
 
627
 
 
628
        check_file_on_disk (file);
 
629
 
 
630
        return file->priv->readonly;
 
631
}