From 62d31d6c92a085818065ab99f0b9ed0bcaec2c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Thu, 18 Oct 2007 18:03:28 +0000 Subject: [PATCH] Add encoding related functions to the plugin API. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1958 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 6 ++++++ src/document.c | 2 +- src/plugindata.h | 13 ++++++++++++- src/plugins.c | 13 +++++++++++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 21fe7dce..219a3813 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-10-18 Enrico Tröger + + * src/plugindata.h, src/plugins.c: + Add encoding related functions to the plugin API. + + 2007-10-18 Nick Treleaven * src/vte.c: diff --git a/src/document.c b/src/document.c index 1cb963d5..63c5a4ea 100644 --- a/src/document.c +++ b/src/document.c @@ -520,7 +520,7 @@ static void store_saved_encoding(gint idx) * filename is either the UTF-8 file name, or NULL. * If ft is NULL and filename is not NULL, then the filetype will be guessed * from the given filename. - * text is the contents of the new file, or NULL. + * text is the contents of the new file in valid UTF-8 encoding, or NULL. * Returns: idx of new file in doc_list. */ gint document_new_file(const gchar *filename, filetype *ft, const gchar *text) { diff --git a/src/plugindata.h b/src/plugindata.h index 3f544aa6..a2b0f9cd 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -71,7 +71,7 @@ /* The API version should be incremented whenever any plugin data types below are * modified or appended to. */ -static const gint api_version = 24; +static const gint api_version = 25; /* The ABI version should be incremented whenever existing fields in the plugin * data types below have to be changed or reordered. It should stay the same if fields @@ -158,6 +158,7 @@ typedef struct GeanyData struct SupportFuncs *support; struct DialogFuncs *dialogs; struct MsgWinFuncs *msgwindow; + struct EncodingFuncs *encoding; } GeanyData; @@ -181,6 +182,7 @@ typedef struct DocumentFuncs const gchar *forced_enc); gboolean (*remove)(guint page_num); gboolean (*reload_file)(gint idx, const gchar *forced_enc); + void (*set_encoding)(gint idx, const gchar *new_encoding); } DocumentFuncs; @@ -278,6 +280,15 @@ typedef struct MsgWinFuncs MsgWinFuncs; +typedef struct EncodingFuncs +{ + gchar* (*convert_to_utf8) (const gchar *buffer, gsize size, gchar **used_encoding); + gchar* (*convert_to_utf8_from_charset) (const gchar *buffer, gsize size, + const gchar *charset, gboolean fast); +} +EncodingFuncs; + + typedef struct GeanyCallback { gchar *signal_name; diff --git a/src/plugins.c b/src/plugins.c index f2b3f258..91326782 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -48,6 +48,7 @@ #include "prefs.h" #include "geanyobject.h" #include "build.h" +#include "encodings.h" #ifdef G_OS_WIN32 @@ -82,7 +83,8 @@ static DocumentFuncs doc_funcs = { &document_open_file, &document_open_files, &document_remove, - &document_reload_file + &document_reload_file, + &document_set_encoding }; static ScintillaFuncs sci_funcs = { @@ -177,6 +179,12 @@ static MsgWinFuncs msgwin_funcs = { }; +static EncodingFuncs encoding_funcs = { + &encodings_convert_to_utf8, + &encodings_convert_to_utf8_from_charset +}; + + static GeanyData geany_data = { NULL, NULL, @@ -193,7 +201,8 @@ static GeanyData geany_data = { &uiutils_funcs, &support_funcs, &dialog_funcs, - &msgwin_funcs + &msgwin_funcs, + &encoding_funcs };