It looks good, just a little comment. Can you please
change the const char array by a UT_String?
Good work!
Cheers,
--
Joaquin Cuenca Abela
[EMAIL PROTECTED]
--- Andrew Dunbar <[EMAIL PROTECTED]> wrote:
> This is my patch to store the encoding of a document
> between
> opening and saving so you don't have to use the
> encoding dialog
> every save.
>
> This fixes bug 1466.
>
> Andrew Dunbar.
>
> --
> http://linguaphile.sourceforge.net> Index:
src/af/xap/xp/xad_Document.cpp
>
===================================================================
> RCS file:
> /cvsroot/abi/src/af/xap/xp/xad_Document.cpp,v
> retrieving revision 1.17
> diff -u -r1.17 xad_Document.cpp
> --- src/af/xap/xp/xad_Document.cpp 2001/05/25
> 18:02:26 1.17
> +++ src/af/xap/xp/xad_Document.cpp 2001/06/08
> 23:31:56
> @@ -28,6 +28,7 @@
> {
> m_iRefCount = 1;
> m_szFilename = NULL;
> + *m_szEncodingName = '\0';
>
> // TODO do we need to auto-increase the bucket
> count,
> // TODO if the ignore list gets long?
> @@ -188,4 +189,22 @@
> UT_ASSERT(m_pIgnoreList);
>
> return true;
> +}
> +
> +// Document-wide Encoding name used for some file
> formats (Text, RTF, HTML)
> +
> +void AD_Document::setEncodingName(const char
> *szEncodingName)
> +{
> + if (szEncodingName == NULL)
> + szEncodingName = "";
> +
> + UT_ASSERT(strlen(szEncodingName) < 16);
> +
> + strncpy(m_szEncodingName,szEncodingName,16);
> + m_szEncodingName[15] = 0;
> +}
> +
> +const char * AD_Document::getEncodingName(void)
> const
> +{
> + return *m_szEncodingName ? m_szEncodingName : 0;
> }
> Index: src/af/xap/xp/xad_Document.h
>
===================================================================
> RCS file:
> /cvsroot/abi/src/af/xap/xp/xad_Document.h,v
> retrieving revision 1.17
> diff -u -r1.17 xad_Document.h
> --- src/af/xap/xp/xad_Document.h 2001/05/25 05:52:12
> 1.17
> +++ src/af/xap/xp/xad_Document.h 2001/06/08 23:31:56
> @@ -60,11 +60,15 @@
> bool enumIgnores(UT_uint32 k, const
> UT_UCSChar ** pszWord) const;
> bool clearIgnores(void);
>
> + void setEncodingName(const char *
> szEncodingName);
> + const char * getEncodingName(void) const;
> +
> protected:
> virtual ~AD_Document(); // Use unref() instead.
>
> int m_iRefCount;
> const char * m_szFilename;
> + char m_szEncodingName[16];
>
> UT_HashTable * m_pIgnoreList;
> };
> Index: src/wp/impexp/xp/ie_exp_Text.cpp
>
===================================================================
> RCS file:
> /cvsroot/abi/src/wp/impexp/xp/ie_exp_Text.cpp,v
> retrieving revision 1.25
> diff -u -r1.25 ie_exp_Text.cpp
> --- src/wp/impexp/xp/ie_exp_Text.cpp 2001/06/07
> 15:52:42 1.25
> +++ src/wp/impexp/xp/ie_exp_Text.cpp 2001/06/08
> 23:33:15
> @@ -104,11 +104,18 @@
> IE_Exp_Text::IE_Exp_Text(PD_Document * pDocument,
> bool bEncoded)
> : IE_Exp(pDocument)
> {
> + UT_ASSERT(pDocument);
> +
> + const char *szEncodingName =
> pDocument->getEncodingName();
> + if (!szEncodingName || !*szEncodingName)
> + szEncodingName =
>
XAP_EncodingManager::get_instance()->getNativeEncodingName();
> +
> m_error = 0;
> m_pListener = NULL;
> m_bIsEncoded = bEncoded;
> +
> // TODO Use persistent document encoding when it
> exists
> -
>
_setEncoding(XAP_EncodingManager::get_instance()->getNativeEncodingName());
> + _setEncoding(szEncodingName);
> }
>
> /*!
> @@ -255,6 +262,7 @@
>
> strcpy(szEnc,s);
> _setEncoding((const char *)szEnc);
> + m_pDocument->setEncodingName(szEnc);
> }
>
> pDialogFactory->releaseDialog(pDialog);
> Index: src/wp/impexp/xp/ie_imp_Text.cpp
>
===================================================================
> RCS file:
> /cvsroot/abi/src/wp/impexp/xp/ie_imp_Text.cpp,v
> retrieving revision 1.26
> diff -u -r1.26 ie_imp_Text.cpp
> --- src/wp/impexp/xp/ie_imp_Text.cpp 2001/06/07
> 15:52:42 1.26
> +++ src/wp/impexp/xp/ie_imp_Text.cpp 2001/06/08
> 23:33:38
> @@ -292,8 +292,9 @@
>
> UT_Error error;
>
> - // First we need to determine the encoding.
> - X_CleanupIfError(error,_recognizeEncoding(fp));
> + // First we try to determine the encoding.
> + if (_recognizeEncoding(fp) == UT_OK)
> + m_pDocument->setEncodingName(m_szEncoding);
> X_CleanupIfError(error,_writeHeader(fp));
> X_CleanupIfError(error,_parseFile(fp));
>
> @@ -319,9 +320,16 @@
> IE_Imp_Text::IE_Imp_Text(PD_Document * pDocument,
> bool bEncoded)
> : IE_Imp(pDocument)
> {
> + UT_ASSERT(pDocument);
> +
> + const char *szEncodingName =
> pDocument->getEncodingName();
> + if (!szEncodingName || !*szEncodingName)
> + szEncodingName =
>
XAP_EncodingManager::get_instance()->getNativeEncodingName();
> +
> m_bIsEncoded = bEncoded;
> +
> // TODO Use persistent document encoding when it
> exists
> -
>
_setEncoding(XAP_EncodingManager::get_instance()->getNativeEncodingName());
> + _setEncoding(szEncodingName);
> }
>
>
>
/*****************************************************************/
> @@ -491,6 +499,7 @@
>
> strcpy(szEnc,s);
> _setEncoding((const char *)szEnc);
> + m_pDocument->setEncodingName(szEnc);
> }
>
> pDialogFactory->releaseDialog(pDialog);
>
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/