OSDN Git Service

Fix issue #2046: Folder compare omits unique folders from results if they contain...
[winmerge-jp/winmerge-jp.git] / Src / OptionsSyntaxColors.cpp
1 /** 
2  * @file  OptionsSyntaxColors.cpp
3  *
4  * @brief Implementation for OptionsSyntaxColors class.
5  */
6
7 #include "pch.h"
8 #include "OptionsSyntaxColors.h"
9 #include <vector>
10 #include "SyntaxColors.h"
11 #include "UnicodeString.h"
12 #include "OptionsDef.h"
13 #include "OptionsMgr.h"
14
15 using std::vector;
16
17 /** @brief Setting name for default colors. */
18 static const tchar_t DefColorsPath[] =_T("DefaultSyntaxColors");
19
20 namespace Options { namespace SyntaxColors {
21
22 void Init(COptionsMgr *pOptionsMgr, ::SyntaxColors *pSyntaxColors)
23 {
24         String valuename(DefColorsPath);
25
26         int count = COLORINDEX_COUNT;
27         valuename += _T("/Values");
28         pOptionsMgr->InitOption(valuename, count);
29
30         for (unsigned i = COLORINDEX_NONE; i < COLORINDEX_LAST; i++)
31         {
32                 // Since we want to initialize with default colors (already
33                 // set to array, we must first call OptionsMrg->InitOption()
34                 // with default value. And since InitOption() reads stored value
35                 // from storage we must set that valu1Ge to array we use.
36                 int color = 0;
37                 CEColor ref;
38                 color = pSyntaxColors->GetColor(i);
39
40                 // Special handling for themable colors
41                 // These are text colors which by default follow the current system colors
42                 // unless the user has overridden this behavior to specify them explicitly
43                 bool serializable = true;
44                 if (pSyntaxColors->IsThemeableColorIndex(i))
45                 {
46                         if (pOptionsMgr->GetBool(OPT_CLR_DEFAULT_TEXT_COLORING))
47                                 serializable = false;
48                 }
49                 valuename = strutils::format(_T("%s/Color%02u"), DefColorsPath, i);
50                 pOptionsMgr->InitOption(valuename, color, serializable);
51                 color = pOptionsMgr->GetInt(valuename);
52                 ref = color;
53                 pSyntaxColors->SetColor(i, ref);
54         
55                 valuename = strutils::format(_T("%s/Bold%02u"), DefColorsPath, i);
56                 pOptionsMgr->InitOption(valuename, pSyntaxColors->GetBold(i));
57                 pSyntaxColors->SetBold(i, pOptionsMgr->GetBool(valuename));
58         }
59 }
60
61 /**
62  * @brief Load color values from storage
63  * @param [out] pSyntaxColors pointer to SyntaxColors
64  */
65 void Load(COptionsMgr *pOptionsMgr, ::SyntaxColors *pSyntaxColors)
66 {
67         for (unsigned i = COLORINDEX_NONE; i < COLORINDEX_LAST; i++)
68         {
69                 String valuename = strutils::format(_T("%s/Color%02u"), DefColorsPath, i);
70                 int color = pOptionsMgr->GetInt(valuename);
71                 CEColor ref = color;
72                 pSyntaxColors->SetColor(i, ref);
73         
74                 valuename = strutils::format(_T("%s/Bold%02u"), DefColorsPath, i);
75                 pSyntaxColors->SetBold(i, pOptionsMgr->GetBool(valuename));
76         }
77 }
78
79 /**
80  * @brief Save color values to storage
81  * @param [in] pSyntaxColors pointer to SyntaxColors
82  */
83 void Save(COptionsMgr *pOptionsMgr, const ::SyntaxColors *pSyntaxColors)
84 {
85         String valuename(DefColorsPath);
86
87         int count = COLORINDEX_COUNT;
88         valuename += _T("/Values");
89         pOptionsMgr->SaveOption(valuename, count);
90
91         for (unsigned i = COLORINDEX_NONE; i < COLORINDEX_LAST; i++)
92         {
93                 int color = pSyntaxColors->GetColor(i);
94                 pOptionsMgr->SaveOption(strutils::format(_T("%s/Color%02u"), DefColorsPath, i), color);
95                 bool bold = pSyntaxColors->GetBold(i);
96                 pOptionsMgr->SaveOption(strutils::format(_T("%s/Bold%02u"), DefColorsPath, i), bold);
97         }
98 }
99
100 }}