Example #1
0
/**
 * gedit_document_get_encoding:
 * @doc: a #GeditDocument.
 *
 * Returns: the encoding.
 * Deprecated: 3.14: use gtk_source_file_get_encoding() instead.
 */
const GtkSourceEncoding *
gedit_document_get_encoding (GeditDocument *doc)
{
	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);

	return gtk_source_file_get_encoding (doc->priv->file);
}
Example #2
0
/**
 * gedit_document_get_encoding:
 * @doc: a #GeditDocument.
 *
 * Returns: the encoding.
 * Deprecated: 3.14: use gtk_source_file_get_encoding() instead.
 */
const GtkSourceEncoding *
gedit_document_get_encoding (GeditDocument *doc)
{
	GeditDocumentPrivate *priv;

	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);

	priv = gedit_document_get_instance_private (doc);

	return gtk_source_file_get_encoding (priv->file);
}
static void
set_default_candidate_encodings (GtkSourceFileLoader *loader)
{
	GSList *list;
	GSList *l;
	const GtkSourceEncoding *file_encoding;

	/* Get first the default candidates from GtkSourceEncoding. If the
	 * GtkSourceFile's encoding has been set by a FileLoader or FileSaver,
	 * put it at the beginning of the list.
	 */
	list = gtk_source_encoding_get_default_candidates ();

	if (loader->priv->file == NULL)
	{
		goto end;
	}

	file_encoding = gtk_source_file_get_encoding (loader->priv->file);

	if (file_encoding == NULL)
	{
		goto end;
	}

	/* Remove file_encoding from the list, if already present, and prepend
	 * it to the list.
	 */
	for (l = list; l != NULL; l = l->next)
	{
		const GtkSourceEncoding *cur_encoding = l->data;

		if (cur_encoding == file_encoding)
		{
			list = g_slist_delete_link (list, l);

			/* The list doesn't contain duplicates, normally. */
			break;
		}
	}

	list = g_slist_prepend (list, (gpointer) file_encoding);

end:
	g_slist_free (loader->priv->candidate_encodings);
	loader->priv->candidate_encodings = list;
}
Example #4
0
static void
save_encoding_metadata (GeditDocument *doc)
{
	const GtkSourceEncoding *encoding;
	const gchar *charset;

	gedit_debug (DEBUG_DOCUMENT);

	encoding = gtk_source_file_get_encoding (doc->priv->file);

	if (encoding == NULL)
	{
		encoding = gtk_source_encoding_get_utf8 ();
	}

	charset = gtk_source_encoding_get_charset (encoding);

	gedit_document_set_metadata (doc,
				     GEDIT_METADATA_ATTRIBUTE_ENCODING, charset,
				     NULL);
}
static void
gtk_source_file_saver_constructed (GObject *object)
{
	GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);

	if (saver->priv->file != NULL)
	{
		const GtkSourceEncoding *encoding;
		GtkSourceNewlineType newline_type;
		GtkSourceCompressionType compression_type;

		encoding = gtk_source_file_get_encoding (saver->priv->file);
		gtk_source_file_saver_set_encoding (saver, encoding);

		newline_type = gtk_source_file_get_newline_type (saver->priv->file);
		gtk_source_file_saver_set_newline_type (saver, newline_type);

		compression_type = gtk_source_file_get_compression_type (saver->priv->file);
		gtk_source_file_saver_set_compression_type (saver, compression_type);

		if (saver->priv->location == NULL)
		{
			saver->priv->location = gtk_source_file_get_location (saver->priv->file);

			if (saver->priv->location != NULL)
			{
				g_object_ref (saver->priv->location);
			}
			else
			{
				g_warning ("GtkSourceFileSaver: the GtkSourceFile's location is NULL. "
					   "Use gtk_source_file_saver_new_with_target().");
			}
		}
	}

	G_OBJECT_CLASS (gtk_source_file_saver_parent_class)->constructed (object);
}