[gnome-builder] GbDocument: add misc helper functions to document
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] GbDocument: add misc helper functions to document
- Date: Sat, 13 Dec 2014 00:35:00 +0000 (UTC)
commit 359a98f7cea09d9adac9601f2b022292f2688540
Author: Christian Hergert <christian hergert me>
Date: Fri Dec 12 16:27:32 2014 -0800
GbDocument: add misc helper functions to document
Adds get_mtime(), get_read_only(), and is_untitled() interface functions.
src/documents/gb-document.c | 56 +++++++++++++++++++++++++++++++++++++++++++
src/documents/gb-document.h | 34 ++++++++++++++++----------
2 files changed, 77 insertions(+), 13 deletions(-)
---
diff --git a/src/documents/gb-document.c b/src/documents/gb-document.c
index 7d3b42b..013b117 100644
--- a/src/documents/gb-document.c
+++ b/src/documents/gb-document.c
@@ -26,6 +26,7 @@ G_DEFINE_INTERFACE (GbDocument, gb_document, G_TYPE_OBJECT)
enum {
PROP_0,
PROP_MODIFIED,
+ PROP_READ_ONLY,
PROP_TITLE,
LAST_PROP
};
@@ -39,6 +40,43 @@ static GParamSpec *gParamSpecs [LAST_PROP];
static guint gSignals [LAST_SIGNAL];
gboolean
+gb_document_is_untitled (GbDocument *document)
+{
+ g_return_val_if_fail (GB_IS_DOCUMENT (document), FALSE);
+
+ if (GB_DOCUMENT_GET_INTERFACE (document)->is_untitled)
+ return GB_DOCUMENT_GET_INTERFACE (document)->is_untitled (document);
+ return FALSE;
+}
+
+gboolean
+gb_document_get_mtime (GbDocument *document,
+ GTimeVal *mtime)
+{
+ g_return_val_if_fail (GB_IS_DOCUMENT (document), FALSE);
+ g_return_val_if_fail (mtime, FALSE);
+
+ if (GB_DOCUMENT_GET_INTERFACE (document)->get_mtime)
+ return GB_DOCUMENT_GET_INTERFACE (document)->get_mtime (document, mtime);
+ return FALSE;
+}
+
+glong
+_gb_document_get_seconds_since_last_save_or_load (GbDocument *document)
+{
+ GTimeVal now;
+ GTimeVal tv;
+
+ if (!gb_document_get_mtime (document, &tv))
+ return 0;
+
+ g_get_current_time (&now);
+
+ /* not totally precise, but whatever */
+ return now.tv_sec - tv.tv_sec;
+}
+
+gboolean
gb_document_get_modified (GbDocument *document)
{
g_return_val_if_fail (GB_IS_DOCUMENT (document), FALSE);
@@ -46,6 +84,16 @@ gb_document_get_modified (GbDocument *document)
return GB_DOCUMENT_GET_INTERFACE (document)->get_modified (document);
}
+gboolean
+gb_document_get_read_only (GbDocument *document)
+{
+ g_return_val_if_fail (GB_IS_DOCUMENT (document), FALSE);
+
+ if (GB_DOCUMENT_GET_INTERFACE (document)->get_read_only)
+ return GB_DOCUMENT_GET_INTERFACE (document)->get_read_only (document);
+ return FALSE;
+}
+
const gchar *
gb_document_get_title (GbDocument *document)
{
@@ -108,6 +156,14 @@ gb_document_default_init (GbDocumentInterface *iface)
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_interface_install_property (iface, gParamSpecs [PROP_TITLE]);
+ gParamSpecs [PROP_READ_ONLY] =
+ g_param_spec_boolean ("read-only",
+ _("Read Only"),
+ _("If the document is read only."),
+ FALSE,
+ (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+ g_object_interface_install_property (iface, gParamSpecs [PROP_READ_ONLY]);
+
gSignals [CREATE_VIEW] =
g_signal_new ("create-view",
GB_TYPE_DOCUMENT,
diff --git a/src/documents/gb-document.h b/src/documents/gb-document.h
index c6974bc..55886aa 100644
--- a/src/documents/gb-document.h
+++ b/src/documents/gb-document.h
@@ -35,21 +35,29 @@ struct _GbDocumentInterface
{
GTypeInterface parent;
- gboolean (*get_modified) (GbDocument *document);
- const gchar *(*get_title) (GbDocument *document);
- GtkWidget *(*create_view) (GbDocument *document);
- void (*save) (GbDocument *document);
- void (*save_as) (GbDocument *document,
- GtkWidget *toplevel);
+ GtkWidget *(*create_view) (GbDocument *document);
+ gboolean (*get_modified) (GbDocument *document);
+ gboolean (*get_mtime) (GbDocument *document,
+ GTimeVal *mtime);
+ gboolean (*get_read_only) (GbDocument *document);
+ const gchar *(*get_title) (GbDocument *document);
+ gboolean (*is_untitled) (GbDocument *document);
+ void (*save) (GbDocument *document);
+ void (*save_as) (GbDocument *document,
+ GtkWidget *toplevel);
};
-GType gb_document_get_type (void) G_GNUC_CONST;
-gboolean gb_document_get_modified (GbDocument *document);
-const gchar *gb_document_get_title (GbDocument *document);
-GtkWidget *gb_document_create_view (GbDocument *document);
-void gb_document_save (GbDocument *document);
-void gb_document_save_as (GbDocument *document,
- GtkWidget *toplevel);
+GtkWidget *gb_document_create_view (GbDocument *document);
+gboolean gb_document_get_modified (GbDocument *document);
+gboolean gb_document_get_mtime (GbDocument *document,
+ GTimeVal *mtime);
+gboolean gb_document_get_read_only (GbDocument *document);
+const gchar *gb_document_get_title (GbDocument *document);
+GType gb_document_get_type (void);
+gboolean gb_document_is_untitled (GbDocument *document);
+void gb_document_save (GbDocument *document);
+void gb_document_save_as (GbDocument *document,
+ GtkWidget *toplevel);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]