[gedit] small refactoring in guess_language
- From: Paolo Borelli <pborelli src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gedit] small refactoring in guess_language
- Date: Sat, 28 Nov 2009 10:44:16 +0000 (UTC)
commit 6f9d6b6c1c1a4f274c2e9bba48695a0e9a8500f8
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Nov 28 11:10:42 2009 +0100
small refactoring in guess_language
gedit/gedit-document-loader.c | 2 +-
gedit/gedit-document.c | 31 ++++++++++++++++++-------------
2 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/gedit/gedit-document-loader.c b/gedit/gedit-document-loader.c
index 94c544f..09ab744 100644
--- a/gedit/gedit-document-loader.c
+++ b/gedit/gedit-document-loader.c
@@ -231,8 +231,8 @@ insert_text_in_document (GeditDocumentLoader *loader,
static const GeditEncoding *
get_metadata_encoding (const gchar *uri)
{
- const GeditEncoding *enc;
gchar *charset;
+ const GeditEncoding *enc;
charset = gedit_metadata_manager_get (uri, "encoding");
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 13729ed..cdfcd11 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -690,14 +690,15 @@ get_default_style_scheme (void)
}
static GtkSourceLanguage *
-guess_language (const gchar *uri,
+guess_language (GeditDocument *doc,
const gchar *content_type)
{
- gchar *data;
+ gchar *data = NULL;
GtkSourceLanguage *language = NULL;
- data = gedit_metadata_manager_get (uri, "language");
+ if (doc->priv->uri != NULL)
+ data = gedit_metadata_manager_get (doc->priv->uri, "language");
if (data != NULL)
{
@@ -717,18 +718,22 @@ guess_language (const gchar *uri,
GFile *file;
gchar *basename;
- gedit_debug_message (DEBUG_DOCUMENT, "Sniffing Language");
+ file = gedit_document_get_location (doc);
- file = g_file_new_for_uri (uri);
- basename = g_file_get_basename (file);
+ if (file)
+ {
+ gedit_debug_message (DEBUG_DOCUMENT, "Sniffing Language");
+
+ basename = g_file_get_basename (file);
- language = gtk_source_language_manager_guess_language (
- gedit_get_language_manager (),
- basename,
- content_type);
+ language = gtk_source_language_manager_guess_language (
+ gedit_get_language_manager (),
+ basename,
+ content_type);
- g_free (basename);
- g_object_unref (file);
+ g_free (basename);
+ g_object_unref (file);
+ }
}
return language;
@@ -743,7 +748,7 @@ on_content_type_changed (GeditDocument *doc,
{
GtkSourceLanguage *language;
- language = guess_language (doc->priv->uri, doc->priv->content_type);
+ language = guess_language (doc, doc->priv->content_type);
gedit_debug_message (DEBUG_DOCUMENT, "Language: %s",
language != NULL ? gtk_source_language_get_name (language) : "None");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]