|
From: Emilien K. <cur...@us...> - 2005-02-14 15:26:51
|
Update of /cvsroot/wxdevcenter/StdPlugin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5635/src Modified Files: SimpleTextDocView.cpp Log Message: Utilisation du nouveau mécanisme de configuration pour la sauvegarde des styles des textes. Index: SimpleTextDocView.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/StdPlugin/src/SimpleTextDocView.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SimpleTextDocView.cpp 15 Jan 2005 15:55:08 -0000 1.4 --- SimpleTextDocView.cpp 14 Feb 2005 15:26:37 -0000 1.5 *************** *** 31,34 **** --- 31,37 ---- #include <wx/fdrepdlg.h> #include <wx/notebook.h> + #include <wx/confbase.h> + #include <wx/gdicmn.h> + #include <stdio.h> using namespace wxDevCenter; *************** *** 69,73 **** for(i=0; i<wxSTC_KEYWORDSET_MAX+1; i++) { ! strKeywords[i] = ""; } --- 72,77 ---- for(i=0; i<wxSTC_KEYWORDSET_MAX+1; i++) { ! Keywords[i].strKeys = wxT(""); ! Keywords[i].strName = wxT(""); } *************** *** 211,223 **** }; ! #define COLOR_TO_LONG(col) ((unsigned int) (col.Red()<<16)|(col.Green()<<8)|(col.Blue())) ! #define LONG_TO_COLOR(l) wxColour(l>>16, (l>>8)%256, l%256) /** Fonction de lecture des préférences.*/ void LoadPreferences() { ! int iLang; ! wxString strRoot, strLabel, str; ! int NumStyle; LanguageProperty *pLang; LanguageProperty::LangagePropertyStyle* pCurStyle; --- 215,291 ---- }; ! ! /** Traduction d'une couleur vers sa forme de sauvegarde de config. ! * @param col Couleur à sauvegarder. ! * @return Chaine de configuration. ! */ ! wxString ColourToString(wxColour col) ! { ! wxString str = wxTheColourDatabase->FindName(col); ! if(str.IsEmpty()) ! str.Printf(wxT("#%02d%02d%02d"), col.Red(), col.Green(), col.Blue()); ! return str; ! } ! ! /** Traduction d'une couleur depuis sa forme de sauvegarde de config. ! * @param Chaine de configuration. ! * @return Couleur. ! */ ! wxColour StringToColour(wxString str) ! { ! wxColour col = wxTheColourDatabase->Find(str); ! if(!col.Ok()) ! { ! unsigned short r, g, b; ! str.Replace(wxT("#"), wxT("")); ! str.UpperCase(); ! sscanf(str.GetData(), wxT("%02hX%02hX%02hX"), &r, &g, &b); ! col.Set((unsigned char)r, (unsigned char)g, (unsigned char)b); ! } ! return col; ! } ! ! /** Traduction d'un style de police vers sa forme de sauvegarde de config. ! * @param FontStyle Style à sauvegarder. ! * @return Chaine de configuration. ! */ ! wxString FontStyleToString(long FontStyle) ! { ! wxString str; ! if((FontStyle&WXDC_STC_STYLE_ITALIC)!=0) ! str << "I"; ! if((FontStyle&WXDC_STC_STYLE_BOLD)!=0) ! str << "B"; ! if((FontStyle&WXDC_STC_STYLE_UNDERL)!=0) ! str << "U"; ! if((FontStyle&WXDC_STC_STYLE_HIDDEN)!=0) ! str << "H"; ! return str; ! } ! ! /** Traduction d'un style de police depuis sa forme de sauvegarde de config. ! * @param str Chaine de configuration. ! * @return Style de police. ! */ ! long StringToFontStyle(wxString str) ! { ! long l = 0; ! if(str.Find(wxT("I"))!=-1) ! l |= WXDC_STC_STYLE_ITALIC; ! if(str.Find(wxT("B"))!=-1) ! l |= WXDC_STC_STYLE_BOLD; ! if(str.Find(wxT("U"))!=-1) ! l |= WXDC_STC_STYLE_UNDERL; ! if(str.Find(wxT("H"))!=-1) ! l |= WXDC_STC_STYLE_HIDDEN; ! return l; ! } ! /** Fonction de lecture des préférences.*/ void LoadPreferences() { ! int iLang, NumStyle, NumKeyword; ! wxString strLabel, strRoot, str; LanguageProperty *pLang; LanguageProperty::LangagePropertyStyle* pCurStyle; *************** *** 225,244 **** InitPreferences(); for(iLang=0; iLang<WXDC_NB_LEX; iLang++) { pLang = &g_LangagePropertyArray[iLang]; ! strRoot = wxString(WXDC_SIMPLETEXT_VIEWCONFIGROOT) + pLang->strShortName + "/"; for(NumStyle = 0; NumStyle<wxSTC_STYLE_DEFAULT; NumStyle++) { pCurStyle = &(pLang->Styles[NumStyle]); - /** @todo Ajouter la vérification de l'utilisation du style.*/ - strLabel.Printf("%d", NumStyle); ! str = strRoot + wxString(WXDC_SIMPLETEXT_VIEWCONFIGSTYLE) + strLabel; ! pCurStyle->iFontStyle = wxGetApp().ReadConfig(str, pCurStyle->iFontStyle); ! str = strRoot + wxString(WXDC_SIMPLETEXT_VIEWCONFIGFORE) + strLabel; ! pCurStyle->colForeground = LONG_TO_COLOR(wxGetApp().ReadConfig(str, COLOR_TO_LONG(pCurStyle->colForeground))); ! str = strRoot + wxString(WXDC_SIMPLETEXT_VIEWCONFIGBACK) + strLabel; ! pCurStyle->colBackground = LONG_TO_COLOR(wxGetApp().ReadConfig(str, COLOR_TO_LONG(pCurStyle->colBackground))); } } --- 293,333 ---- InitPreferences(); + wxConfigBase& GlobalConfig = wxGetApp().GetConfig()[WXDC_SIMPLETEXT_CONFIG_ROOT]; + GlobalConfig.SetPath(wxT("/")); + for(iLang=0; iLang<WXDC_NB_LEX; iLang++) { pLang = &g_LangagePropertyArray[iLang]; ! pLang->strShortName = GlobalConfig.Read(wxString::Format(wxT("%s%02d"), WXDC_SIMPLETEXT_VIEWCONFIGNAME, iLang), pLang->strShortName); ! ! strRoot.Empty(); ! strRoot << WXDC_SIMPLETEXT_CONFIG_ROOT << wxT("/") << pLang->strShortName; ! wxConfigBase& Config = wxGetApp().GetConfig()[strRoot]; ! ! Config.SetPath(wxT("/")); ! pLang->iFolds = Config.Read(WXDC_SIMPLETEXT_VIEWCONFIGFOLDS, pLang->iFolds); ! pLang->strName = Config.Read(WXDC_SIMPLETEXT_VIEWCONFIGNAME, pLang->strName); ! ! for(NumKeyword = 0; NumKeyword<=wxSTC_KEYWORDSET_MAX; NumKeyword++) ! { ! Config.SetPath(wxString::Format(wxT("/%s%02d"), WXDC_SIMPLETEXT_VIEWCONFIGKEYWORD, NumKeyword)); ! pLang->Keywords[NumKeyword].strKeys = Config.Read(WXDC_SIMPLETEXT_VIEWCONFIGKEYWORD, pLang->Keywords[NumKeyword].strKeys); ! pLang->Keywords[NumKeyword].strName = Config.Read(WXDC_SIMPLETEXT_VIEWCONFIGKEYNAME, pLang->Keywords[NumKeyword].strName); ! } ! for(NumStyle = 0; NumStyle<wxSTC_STYLE_DEFAULT; NumStyle++) { + str.Printf(wxT("/style%02d"), NumStyle); + Config.SetPath(str); + pCurStyle = &(pLang->Styles[NumStyle]); ! pCurStyle->bUsed = Config.Read(WXDC_SIMPLETEXT_VIEWCONFIGUSED, pCurStyle->bUsed); ! pCurStyle->strLabel = Config.Read(WXDC_SIMPLETEXT_VIEWCONFIGLABEL, pCurStyle->strLabel); ! pCurStyle->iFontSize = Config.Read(WXDC_SIMPLETEXT_VIEWCONFIGFONTSIZE, pCurStyle->iFontSize); ! pCurStyle->iFontStyle = StringToFontStyle(Config.Read(WXDC_SIMPLETEXT_VIEWCONFIGFONTSTYLE, FontStyleToString(pCurStyle->iFontStyle))); ! pCurStyle->colForeground = StringToColour(Config.Read(WXDC_SIMPLETEXT_VIEWCONFIGFORE, ColourToString(pCurStyle->colForeground))); ! pCurStyle->colBackground = StringToColour(Config.Read(WXDC_SIMPLETEXT_VIEWCONFIGBACK, ColourToString(pCurStyle->colBackground))); ! } } *************** *** 248,275 **** void SavePreferences() { ! int iLang; ! wxString strRoot, strLabel, str; ! int NumStyle; LanguageProperty *pLang; LanguageProperty::LangagePropertyStyle* pCurStyle; for(iLang=0; iLang<WXDC_NB_LEX; iLang++) { pLang = &g_LangagePropertyArray[iLang]; ! strRoot = wxString(WXDC_SIMPLETEXT_VIEWCONFIGROOT) + pLang->strShortName + "/"; /** @todo : ajouter la suppression de la clef de configuration.*/ for(NumStyle = 0; NumStyle<wxSTC_STYLE_DEFAULT; NumStyle++) { pCurStyle = &(pLang->Styles[NumStyle]); if(pCurStyle->bUsed) { ! strLabel.Printf("%d", NumStyle); ! ! str = strRoot + wxString(WXDC_SIMPLETEXT_VIEWCONFIGSTYLE) + strLabel; ! wxGetApp().WriteConfig(str, pCurStyle->iFontStyle); ! str = strRoot + wxString(WXDC_SIMPLETEXT_VIEWCONFIGFORE) + strLabel; ! wxGetApp().WriteConfig(str, COLOR_TO_LONG(pCurStyle->colForeground)); ! str = strRoot + wxString(WXDC_SIMPLETEXT_VIEWCONFIGBACK) + strLabel; ! wxGetApp().WriteConfig(str, COLOR_TO_LONG(pCurStyle->colBackground)); } } --- 337,383 ---- void SavePreferences() { ! int iLang, NumStyle, NumKeyword; ! wxString strLabel, str, strRoot; LanguageProperty *pLang; LanguageProperty::LangagePropertyStyle* pCurStyle; + wxConfigBase& GlobalConfig = wxGetApp().GetConfig()[WXDC_SIMPLETEXT_CONFIG_ROOT]; + GlobalConfig.SetPath(wxT("/")); + for(iLang=0; iLang<WXDC_NB_LEX; iLang++) { pLang = &g_LangagePropertyArray[iLang]; ! GlobalConfig.Write(wxString::Format(wxT("%s%02d"), WXDC_SIMPLETEXT_VIEWCONFIGNAME, iLang), pLang->strShortName); ! ! strRoot.Empty(); ! strRoot << WXDC_SIMPLETEXT_CONFIG_ROOT << wxT("/") << pLang->strShortName; ! wxConfigBase& Config = wxGetApp().GetConfig()[strRoot]; ! ! Config.SetPath(wxT("/")); ! Config.Write(WXDC_SIMPLETEXT_VIEWCONFIGFOLDS, pLang->iFolds); ! Config.Write(WXDC_SIMPLETEXT_VIEWCONFIGNAME, pLang->strName); ! ! for(NumKeyword = 0; NumKeyword<=wxSTC_KEYWORDSET_MAX; NumKeyword++) ! { ! Config.SetPath(wxString::Format(wxT("/%s%02d"), WXDC_SIMPLETEXT_VIEWCONFIGKEYWORD, NumKeyword)); ! Config.Write(WXDC_SIMPLETEXT_VIEWCONFIGKEYWORD, pLang->Keywords[NumKeyword].strKeys); ! Config.Write(WXDC_SIMPLETEXT_VIEWCONFIGKEYNAME, pLang->Keywords[NumKeyword].strName); ! } ! /** @todo : ajouter la suppression de la clef de configuration.*/ for(NumStyle = 0; NumStyle<wxSTC_STYLE_DEFAULT; NumStyle++) { + str.Printf(wxT("/style%02d"), NumStyle); + Config.SetPath(str); + pCurStyle = &(pLang->Styles[NumStyle]); if(pCurStyle->bUsed) { ! Config.Write(WXDC_SIMPLETEXT_VIEWCONFIGUSED, pCurStyle->bUsed); ! Config.Write(WXDC_SIMPLETEXT_VIEWCONFIGLABEL, pCurStyle->strLabel); ! Config.Write(WXDC_SIMPLETEXT_VIEWCONFIGFONTSIZE, pCurStyle->iFontSize); ! Config.Write(WXDC_SIMPLETEXT_VIEWCONFIGFONTSTYLE, FontStyleToString(pCurStyle->iFontStyle)); ! Config.Write(WXDC_SIMPLETEXT_VIEWCONFIGFORE, ColourToString(pCurStyle->colForeground)); ! Config.Write(WXDC_SIMPLETEXT_VIEWCONFIGBACK, ColourToString(pCurStyle->colBackground)); } } *************** *** 317,321 **** pLang->iFolds = WXDC_STC_FOLD_COMMENT | WXDC_STC_FOLD_COMPACT | WXDC_STC_FOLD_PREPROC; /** Lexemes.*/ ! pLang->strKeywords[0] = _T("asm auto bool break case catch char class const const_cast \ continue default delete do double dynamic_cast else enum explicit \ export extern false float for friend goto if inline int long \ --- 425,429 ---- pLang->iFolds = WXDC_STC_FOLD_COMMENT | WXDC_STC_FOLD_COMPACT | WXDC_STC_FOLD_PREPROC; /** Lexemes.*/ ! pLang->Keywords[0].strKeys = _T("asm auto bool break case catch char class const const_cast \ continue default delete do double dynamic_cast else enum explicit \ export extern false float for friend goto if inline int long \ *************** *** 325,330 **** typename union unsigned using virtual void volatile wchar_t \ while"); ! pLang->strKeywords[1] = _T("file class"); ! pLang->strKeywords[2] = _T("a addindex addtogroup anchor arg attention author b brief bug c \ class code date def defgroup deprecated dontinclude e em endcode \ endhtmlonly endif endlatexonly endlink endverbatim enum example \ --- 433,438 ---- typename union unsigned using virtual void volatile wchar_t \ while"); ! pLang->Keywords[2].strKeys = _T("file class"); ! pLang->Keywords[3].strKeys = _T("a addindex addtogroup anchor arg attention author b brief bug c \ class code date def defgroup deprecated dontinclude e em endcode \ endhtmlonly endif endlatexonly endlink endverbatim enum example \ *************** *** 379,385 **** pLang->iFolds = WXDC_STC_FOLD_COMMENT | WXDC_STC_FOLD_COMPACT | WXDC_STC_FOLD_PREPROC; /** Lexemes.*/ ! pLang->strKeywords[0] = _T("and break do else elseif end false for function if \ in local nil not or repeat return then true until while"); ! pLang->strKeywords[1] = _T("_VERSION assert collectgarbage dofile error gcinfo loadfile loadstring \ print tonumber tostring type unpack \ _ALERT _ERRORMESSAGE _INPUT _PROMPT _OUTPUT \ --- 487,493 ---- pLang->iFolds = WXDC_STC_FOLD_COMMENT | WXDC_STC_FOLD_COMPACT | WXDC_STC_FOLD_PREPROC; /** Lexemes.*/ ! pLang->Keywords[0].strKeys = _T("and break do else elseif end false for function if \ in local nil not or repeat return then true until while"); ! pLang->Keywords[1].strKeys = _T("_VERSION assert collectgarbage dofile error gcinfo loadfile loadstring \ print tonumber tostring type unpack \ _ALERT _ERRORMESSAGE _INPUT _PROMPT _OUTPUT \ *************** *** 389,393 **** rawegal rawget rawset require setfenv setmetatable xpcall \ string table math coroutine io os debug"); ! pLang->strKeywords[2] = _T("abs acos asin atan atan2 ceil cos deg exp \ floor format frexp gsub ldexp log log10 max min mod rad random randomseed \ sin sqrt strbyte strchar strfind strlen strlower strrep strsub strupper tan\ --- 497,501 ---- rawegal rawget rawset require setfenv setmetatable xpcall \ string table math coroutine io os debug"); ! pLang->Keywords[2].strKeys = _T("abs acos asin atan atan2 ceil cos deg exp \ floor format frexp gsub ldexp log log10 max min mod rad random randomseed \ sin sqrt strbyte strchar strfind strlen strlower strrep strsub strupper tan\ *************** *** 398,402 **** math.floor math.frexp math.ldexp math.log math.log10 math.max math.min math.mod \ math.pi math.rad math.random math.randomseed math.sin math.sqrt math.tan"); ! pLang->strKeywords[3] = _T("openfile closefile readfrom writeto appendto \ remove rename flush seek tmpfile tmpname read write \ clock date difftime execute exit getenv setlocale time \ --- 506,510 ---- math.floor math.frexp math.ldexp math.log math.log10 math.max math.min math.mod \ math.pi math.rad math.random math.randomseed math.sin math.sqrt math.tan"); ! pLang->Keywords[3].strKeys = _T("openfile closefile readfrom writeto appendto \ remove rename flush seek tmpfile tmpname read write \ clock date difftime execute exit getenv setlocale time \ *************** *** 1312,1316 **** /** Lexemes.*/ for(NumStyle = 0; NumStyle<=wxSTC_KEYWORDSET_MAX; NumStyle++) ! m_pText->SetKeyWords(NumStyle, pLang->strKeywords[NumStyle]); // set spaces and indention --- 1420,1424 ---- /** Lexemes.*/ for(NumStyle = 0; NumStyle<=wxSTC_KEYWORDSET_MAX; NumStyle++) ! m_pText->SetKeyWords(NumStyle, pLang->Keywords[NumStyle].strKeys); // set spaces and indention |