OSDN Git Service

Replace string_* with strutils::*
[winmerge-jp/winmerge-jp.git] / Src / PropEditor.cpp
1 /** 
2  * @file  PropEditor.cpp
3  *
4  * @brief Implementation of PropEditor propertysheet
5  */
6
7 #include "stdafx.h"
8 #include "PropEditor.h"
9 #include "OptionsDef.h"
10 #include "OptionsMgr.h"
11 #include "OptionsPanel.h"
12
13 #ifdef _DEBUG
14 #define new DEBUG_NEW
15 #endif
16
17 /** @brief Maximum size for tabs in spaces. */
18 static const int MAX_TABSIZE = 64;
19
20 /** 
21  * @brief Constructor.
22  * @param [in] optionsMgr Pointer to options manager for handling options.
23  */
24 PropEditor::PropEditor(COptionsMgr *optionsMgr) 
25 : OptionsPanel(optionsMgr, PropEditor::IDD)
26 , m_bHiliteSyntax(false)
27 , m_nTabType(-1)
28 , m_nTabSize(0)
29 , m_bAutomaticRescan(false)
30 , m_bAllowMixedEol(false)
31 , m_bViewLineDifferences(false)
32 , m_bBreakOnWords(false)
33 , m_nBreakType(0)
34 {
35 }
36
37 /** 
38  * @brief Function handling dialog data exchange between GUI and variables.
39  */
40 void PropEditor::DoDataExchange(CDataExchange* pDX)
41 {
42         CDialog::DoDataExchange(pDX);
43         //{{AFX_DATA_MAP(PropEditor)
44         DDX_Check(pDX, IDC_HILITE_CHECK, m_bHiliteSyntax);
45         DDX_Radio(pDX, IDC_PROP_INSERT_TABS, m_nTabType);
46         DDX_Text(pDX, IDC_TAB_EDIT, m_nTabSize);
47         DDV_MaxChars(pDX, std::to_string(m_nTabSize).c_str(), 2);
48         DDX_Check(pDX, IDC_AUTOMRESCAN_CHECK, m_bAutomaticRescan);
49         DDX_Check(pDX, IDC_MIXED_EOL, m_bAllowMixedEol);
50         DDX_Check(pDX, IDC_VIEW_LINE_DIFFERENCES, m_bViewLineDifferences);
51         DDX_Radio(pDX, IDC_EDITOR_CHARLEVEL, m_bBreakOnWords);
52         DDX_CBIndex(pDX, IDC_BREAK_TYPE, m_nBreakType);
53         DDX_Text(pDX, IDC_BREAK_CHARS, m_breakChars);
54         //}}AFX_DATA_MAP
55 }
56
57
58 BEGIN_MESSAGE_MAP(PropEditor, CDialog)
59         //{{AFX_MSG_MAP(PropEditor)
60         ON_BN_CLICKED(IDC_VIEW_LINE_DIFFERENCES, OnLineDiffControlClicked)
61         ON_BN_CLICKED(IDC_EDITOR_CHARLEVEL, OnLineDiffControlClicked)
62         ON_BN_CLICKED(IDC_EDITOR_WORDLEVEL, OnLineDiffControlClicked)
63         ON_EN_KILLFOCUS(IDC_TAB_EDIT, OnEnKillfocusTabEdit)
64         //}}AFX_MSG_MAP
65 END_MESSAGE_MAP()
66
67 /** 
68  * @brief Reads options values from storage to UI.
69  */
70 void PropEditor::ReadOptions()
71 {
72         m_nTabSize = GetOptionsMgr()->GetInt(OPT_TAB_SIZE);
73         m_nTabType = GetOptionsMgr()->GetInt(OPT_TAB_TYPE);
74         m_bAutomaticRescan = GetOptionsMgr()->GetBool(OPT_AUTOMATIC_RESCAN);
75         m_bHiliteSyntax = GetOptionsMgr()->GetBool(OPT_SYNTAX_HIGHLIGHT);
76         m_bAllowMixedEol = GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL);
77         m_bViewLineDifferences = GetOptionsMgr()->GetBool(OPT_WORDDIFF_HIGHLIGHT);
78         m_bBreakOnWords = GetOptionsMgr()->GetBool(OPT_BREAK_ON_WORDS);
79         m_nBreakType = GetOptionsMgr()->GetInt(OPT_BREAK_TYPE);
80         m_breakChars = GetOptionsMgr()->GetString(OPT_BREAK_SEPARATORS);
81 }
82
83 /** 
84  * @brief Writes options values from UI to storage.
85  */
86 void PropEditor::WriteOptions()
87 {
88         // Sanity check tabsize
89         if (m_nTabSize < 1)
90                 m_nTabSize = 1;
91         if (m_nTabSize > MAX_TABSIZE)
92                 m_nTabSize = MAX_TABSIZE;
93         GetOptionsMgr()->SaveOption(OPT_TAB_SIZE, (int)m_nTabSize);
94         GetOptionsMgr()->SaveOption(OPT_TAB_TYPE, (int)m_nTabType);
95         GetOptionsMgr()->SaveOption(OPT_AUTOMATIC_RESCAN, m_bAutomaticRescan);
96         GetOptionsMgr()->SaveOption(OPT_ALLOW_MIXED_EOL, m_bAllowMixedEol);
97         GetOptionsMgr()->SaveOption(OPT_SYNTAX_HIGHLIGHT, m_bHiliteSyntax);
98         GetOptionsMgr()->SaveOption(OPT_WORDDIFF_HIGHLIGHT, !!m_bViewLineDifferences);
99         GetOptionsMgr()->SaveOption(OPT_BREAK_ON_WORDS, !!m_bBreakOnWords);
100         GetOptionsMgr()->SaveOption(OPT_BREAK_TYPE, m_nBreakType);
101         GetOptionsMgr()->SaveOption(OPT_BREAK_SEPARATORS, String(m_breakChars));
102 }
103
104 /** 
105  * @brief Called before propertysheet is drawn.
106  */
107 BOOL PropEditor::OnInitDialog() 
108 {
109         OptionsPanel::OnInitDialog();
110
111         LoadBreakTypeStrings();
112         UpdateDataToWindow();
113         UpdateLineDiffControls();
114
115         return TRUE;  // return TRUE unless you set the focus to a control
116                       // EXCEPTION: OCX Property Pages should return FALSE
117 }
118
119 /**
120  * @brief Load strings (from resource) into combobox for break type
121  */
122 void PropEditor::LoadBreakTypeStrings()
123 {
124         CComboBox * cbo = (CComboBox *)GetDlgItem(IDC_BREAK_TYPE);
125         cbo->AddString(_("Break at whitespace").c_str());
126         cbo->AddString(_("Break at whitespace or punctuation").c_str());
127 }
128
129 /**
130  * @brief Handlers any clicks in any of the line differencing controls
131  */
132 void PropEditor::OnLineDiffControlClicked()
133 {
134         UpdateLineDiffControls();
135 }
136
137 /** 
138  * @brief Update availability of line difference controls
139  */
140 void PropEditor::UpdateLineDiffControls()
141 {
142         UpdateDataFromWindow();
143         // Can only choose char/word level if line differences are enabled
144         EnableDlgItem(IDC_EDITOR_CHARLEVEL, !!m_bViewLineDifferences);
145         EnableDlgItem(IDC_EDITOR_WORDLEVEL, !!m_bViewLineDifferences);
146         // Can only choose break type if line differences are enabled & we're breaking on words
147         EnableDlgItem(IDC_BREAK_TYPE, !!m_bViewLineDifferences);
148 }
149
150 /** 
151  * @brief Check tabsize value when control loses focus.
152  */
153 void PropEditor::OnEnKillfocusTabEdit()
154 {
155         unsigned value = GetDlgItemInt(IDC_TAB_EDIT);
156         if (value < 1 || value > MAX_TABSIZE)
157         {
158                 String msg = strutils::format_string1(
159                         _("Value in Tab size -field is not in range WinMerge accepts.\n\nPlease use values 1 - %1."),
160                         strutils::to_str(MAX_TABSIZE));
161                 AfxMessageBox(msg.c_str(), MB_ICONWARNING);
162         }
163 }