[gnome-builder] file: fix language loading when no language could be found



commit 05809a71f5b9248172c5f02b1c80c41115aa2a97
Author: Christian Hergert <christian hergert me>
Date:   Mon Jul 13 11:17:40 2015 -0700

    file: fix language loading when no language could be found

 libide/ide-file.c |   48 +++++++++++++++++++++++++-----------------------
 1 files changed, 25 insertions(+), 23 deletions(-)
---
diff --git a/libide/ide-file.c b/libide/ide-file.c
index 7eb7163..283755f 100644
--- a/libide/ide-file.c
+++ b/libide/ide-file.c
@@ -99,36 +99,33 @@ ide_file_equal (IdeFile *self,
   return g_file_equal (self->file, other->file);
 }
 
-static void
+static GtkSourceLanguage *
 ide_file_create_language (IdeFile *self)
 {
-  g_assert (IDE_IS_FILE (self));
+  GtkSourceLanguageManager *manager;
+  GtkSourceLanguage *srclang;
+  g_autofree gchar *content_type = NULL;
+  const gchar *filename;
+  gboolean uncertain = FALSE;
 
-  if (g_once_init_enter (&self->language))
-    {
-      GtkSourceLanguageManager *manager;
-      GtkSourceLanguage *srclang;
-      g_autofree gchar *content_type = NULL;
-      const gchar *filename;
-      gboolean uncertain = FALSE;
+  g_assert (IDE_IS_FILE (self));
 
-      filename = g_file_get_basename (self->file);
+  filename = g_file_get_basename (self->file);
 
-      if (self->content_type)
-        content_type = g_strdup (self->content_type);
-      else
-        content_type = g_content_type_guess (filename, NULL, 0, &uncertain);
+  if (self->content_type)
+    content_type = g_strdup (self->content_type);
+  else
+    content_type = g_content_type_guess (filename, NULL, 0, &uncertain);
 
-      if (uncertain)
-        g_clear_pointer (&content_type, g_free);
-      else if (self->content_type == NULL)
-        self->content_type = g_strdup (content_type);
+  if (uncertain)
+    g_clear_pointer (&content_type, g_free);
+  else if (self->content_type == NULL)
+    self->content_type = g_strdup (content_type);
 
-      manager = gtk_source_language_manager_get_default ();
-      srclang = gtk_source_language_manager_guess_language (manager, filename, content_type);
+  manager = gtk_source_language_manager_get_default ();
+  srclang = gtk_source_language_manager_guess_language (manager, filename, content_type);
 
-      g_once_init_leave (&self->language, srclang);
-    }
+  return srclang;
 }
 
 /**
@@ -144,7 +141,12 @@ ide_file_get_language (IdeFile *self)
   g_return_val_if_fail (IDE_IS_FILE (self), NULL);
 
   if (self->language == NULL)
-    ide_file_create_language (self);
+    {
+      GtkSourceLanguage *language;
+
+      language = ide_file_create_language (self);
+      self->language = language ? g_object_ref (language) : NULL;
+    }
 
   return self->language;
 }


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