Adjust checkbox and radio control widths to required size
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingsTBlame.cpp
blob410aef37721376cfc2bc8add2ad98469f4ba9a49
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
4 // Copyright (C) 2011-2014 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "MessageBox.h"
23 #include "SettingsTBlame.h"
24 #include "..\TortoiseGitBlame\BlameIndexColors.h"
25 #include "..\TortoiseGitBlame\BlameDetectMovedOrCopiedLines.h"
28 // CSettingsTBlame dialog
30 //IMPLEMENT_DYNAMIC(CSettingsTBlame, ISettingsPropPage)
32 CSettingsTBlame::CSettingsTBlame()
33 : ISettingsPropPage(CSettingsTBlame::IDD)
34 , m_dwFontSize(0)
35 , m_sFontName(_T(""))
36 , m_dwTabSize(4)
37 , m_dwDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED)
38 , m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile(BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE_DEFAULT)
39 , m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles(BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES_DEFAULT)
40 , m_bIgnoreWhitespace(0)
41 , m_bShowCompleteLog(0)
42 , m_bFollowRenames(0)
44 m_regNewLinesColor = CRegDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), BLAMENEWCOLOR);
45 m_regOldLinesColor = CRegDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), BLAMEOLDCOLOR);
46 m_regFontName = CRegString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
47 m_regFontSize = CRegDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10);
48 m_regTabSize = CRegDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4);
49 m_regDetectMovedOrCopiedLines = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\DetectMovedOrCopiedLines"), BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
50 m_regDetectMovedOrCopiedLinesNumCharactersWithinFile = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\DetectMovedOrCopiedLinesNumCharactersWithinFile"), BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE_DEFAULT);
51 m_regDetectMovedOrCopiedLinesNumCharactersFromFiles = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\DetectMovedOrCopiedLinesNumCharactersFromFiles"), BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES_DEFAULT);
52 m_regIgnoreWhitespace = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\IgnoreWhitespace"), 0);
53 m_regShowCompleteLog = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\ShowCompleteLog"), 1);
54 m_regFollowRenames = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\FollowRenames"), 0);
57 CSettingsTBlame::~CSettingsTBlame()
61 void CSettingsTBlame::DoDataExchange(CDataExchange* pDX)
63 ISettingsPropPage::DoDataExchange(pDX);
64 DDX_Control(pDX, IDC_NEWLINESCOLOR, m_cNewLinesColor);
65 DDX_Control(pDX, IDC_OLDLINESCOLOR, m_cOldLinesColor);
66 DDX_Control(pDX, IDC_FONTSIZES, m_cFontSizes);
67 m_dwFontSize = (DWORD)m_cFontSizes.GetItemData(m_cFontSizes.GetCurSel());
68 if ((m_dwFontSize==0)||(m_dwFontSize == -1))
70 CString t;
71 m_cFontSizes.GetWindowText(t);
72 m_dwFontSize = _ttoi(t);
74 DDX_Control(pDX, IDC_FONTNAMES, m_cFontNames);
75 DDX_Text(pDX, IDC_TABSIZE, m_dwTabSize);
76 DDX_Control(pDX, IDC_DETECT_MOVED_OR_COPIED_LINES, m_cDetectMovedOrCopiedLines);
77 m_dwDetectMovedOrCopiedLines = (DWORD)m_cDetectMovedOrCopiedLines.GetItemData(m_cDetectMovedOrCopiedLines.GetCurSel());
78 if (m_dwDetectMovedOrCopiedLines == -1){
79 m_dwDetectMovedOrCopiedLines = BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED;
81 DDX_Text(pDX, IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE, m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile);
82 DDX_Text(pDX, IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES, m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles);
83 DDX_Check(pDX, IDC_IGNORE_WHITESPACE, m_bIgnoreWhitespace);
84 DDX_Check(pDX, IDC_SHOWCOMPLETELOG, m_bShowCompleteLog);
85 DDX_Check(pDX, IDC_FOLLOWRENAMES, m_bFollowRenames);
89 BEGIN_MESSAGE_MAP(CSettingsTBlame, ISettingsPropPage)
90 ON_BN_CLICKED(IDC_RESTORE, OnBnClickedRestore)
91 ON_CBN_SELCHANGE(IDC_FONTSIZES, OnChange)
92 ON_CBN_SELCHANGE(IDC_FONTNAMES, OnChange)
93 ON_EN_CHANGE(IDC_TABSIZE, OnChange)
94 ON_CBN_SELCHANGE(IDC_DETECT_MOVED_OR_COPIED_LINES, OnChange)
95 ON_EN_CHANGE(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE, OnChange)
96 ON_EN_CHANGE(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES, OnChange)
97 ON_BN_CLICKED(IDC_IGNORE_WHITESPACE, OnChange)
98 ON_BN_CLICKED(IDC_SHOWCOMPLETELOG, OnChange)
99 ON_BN_CLICKED(IDC_FOLLOWRENAMES, OnChange)
100 ON_BN_CLICKED(IDC_NEWLINESCOLOR, &CSettingsTBlame::OnBnClickedColor)
101 ON_BN_CLICKED(IDC_OLDLINESCOLOR, &CSettingsTBlame::OnBnClickedColor)
102 END_MESSAGE_MAP()
105 // CSettingsTBlame message handlers
107 BOOL CSettingsTBlame::OnInitDialog()
109 CMFCFontComboBox::m_bDrawUsingFont = true;
111 ISettingsPropPage::OnInitDialog();
113 AdjustControlSize(IDC_IGNORE_WHITESPACE);
114 AdjustControlSize(IDC_SHOWCOMPLETELOG);
115 AdjustControlSize(IDC_FOLLOWRENAMES);
117 m_cNewLinesColor.SetColor((DWORD)m_regNewLinesColor);
118 m_cOldLinesColor.SetColor((DWORD)m_regOldLinesColor);
120 CString sDefaultText, sCustomText;
121 sDefaultText.LoadString(IDS_COLOURPICKER_DEFAULTTEXT);
122 sCustomText.LoadString(IDS_COLOURPICKER_CUSTOMTEXT);
123 m_cNewLinesColor.EnableAutomaticButton(sDefaultText, BLAMENEWCOLOR);
124 m_cNewLinesColor.EnableOtherButton(sCustomText);
125 m_cOldLinesColor.EnableAutomaticButton(sDefaultText, BLAMEOLDCOLOR);
126 m_cOldLinesColor.EnableOtherButton(sCustomText);
128 m_dwTabSize = m_regTabSize;
129 m_sFontName = m_regFontName;
130 m_dwFontSize = m_regFontSize;
131 m_dwDetectMovedOrCopiedLines = m_regDetectMovedOrCopiedLines;
132 m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile = m_regDetectMovedOrCopiedLinesNumCharactersWithinFile;
133 m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles = m_regDetectMovedOrCopiedLinesNumCharactersFromFiles;
134 m_bIgnoreWhitespace = m_regIgnoreWhitespace;
135 m_bShowCompleteLog = m_regShowCompleteLog;
136 m_bFollowRenames = m_regFollowRenames;
137 int count = 0;
138 CString temp;
139 for (int i=6; i<32; i=i+2)
141 temp.Format(_T("%d"), i);
142 m_cFontSizes.AddString(temp);
143 m_cFontSizes.SetItemData(count++, i);
145 BOOL foundfont = FALSE;
146 for (int i=0; i<m_cFontSizes.GetCount(); i++)
148 if (m_cFontSizes.GetItemData(i) == m_dwFontSize)
150 m_cFontSizes.SetCurSel(i);
151 foundfont = TRUE;
154 if (!foundfont)
156 temp.Format(_T("%lu"), m_dwFontSize);
157 m_cFontSizes.SetWindowText(temp);
159 m_cFontNames.Setup(DEVICE_FONTTYPE|RASTER_FONTTYPE|TRUETYPE_FONTTYPE, 1, FIXED_PITCH);
160 m_cFontNames.SelectFont(m_sFontName);
162 CString sDetectMovedOrCopiedLinesDisabled;
163 CString sDetectMovedOrCopiedLinesWithinFile;
164 CString sDetectMovedOrCopiedLinesFromModifiedFiles;
165 CString sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation;
166 CString sDetectMovedOrCopiedLinesFromExistingFiles;
167 sDetectMovedOrCopiedLinesDisabled.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
168 sDetectMovedOrCopiedLinesWithinFile.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
169 sDetectMovedOrCopiedLinesFromModifiedFiles.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
170 sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
171 sDetectMovedOrCopiedLinesFromExistingFiles.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
173 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesDisabled);
174 m_cDetectMovedOrCopiedLines.SetItemData(0, BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
175 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesWithinFile);
176 m_cDetectMovedOrCopiedLines.SetItemData(1, BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
177 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromModifiedFiles);
178 m_cDetectMovedOrCopiedLines.SetItemData(2, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
179 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation);
180 m_cDetectMovedOrCopiedLines.SetItemData(3, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
181 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromExistingFiles);
182 m_cDetectMovedOrCopiedLines.SetItemData(4, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
183 for (int i = 0; i < m_cDetectMovedOrCopiedLines.GetCount(); ++i)
185 if (m_cDetectMovedOrCopiedLines.GetItemData(i) == m_dwDetectMovedOrCopiedLines)
187 m_cDetectMovedOrCopiedLines.SetCurSel(i);
188 break;
192 UpdateData(FALSE);
193 UpdateDependencies();
194 return TRUE;
197 void CSettingsTBlame::OnChange()
199 UpdateData();
200 UpdateDependencies();
201 SetModified();
204 void CSettingsTBlame::OnBnClickedRestore()
206 m_cOldLinesColor.SetColor(BLAMEOLDCOLOR);
207 m_cNewLinesColor.SetColor(BLAMENEWCOLOR);
208 SetModified(TRUE);
211 BOOL CSettingsTBlame::OnApply()
213 UpdateData();
214 if (m_cFontNames.GetSelFont())
215 m_sFontName = m_cFontNames.GetSelFont()->m_strName;
216 else
217 m_sFontName = m_regFontName;
219 Store ((m_cNewLinesColor.GetColor() == -1 ? m_cNewLinesColor.GetAutomaticColor() : m_cNewLinesColor.GetColor()), m_regNewLinesColor);
220 Store ((m_cOldLinesColor.GetColor() == -1 ? m_cOldLinesColor.GetAutomaticColor() : m_cOldLinesColor.GetColor()), m_regOldLinesColor);
221 Store ((LPCTSTR)m_sFontName, m_regFontName);
222 Store (m_dwFontSize, m_regFontSize);
223 Store (m_dwTabSize, m_regTabSize);
224 Store (m_dwDetectMovedOrCopiedLines, m_regDetectMovedOrCopiedLines);
225 Store (m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile, m_regDetectMovedOrCopiedLinesNumCharactersWithinFile);
226 Store (m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles, m_regDetectMovedOrCopiedLinesNumCharactersFromFiles);
227 Store (m_bIgnoreWhitespace, m_regIgnoreWhitespace);
228 Store (m_bShowCompleteLog, m_regShowCompleteLog);
229 Store (m_bFollowRenames, m_regFollowRenames);
231 SetModified(FALSE);
232 return ISettingsPropPage::OnApply();
235 void CSettingsTBlame::OnBnClickedColor()
237 SetModified();
240 void CSettingsTBlame::UpdateDependencies()
242 BOOL enableDetectMovedOrCopiedLinesNumCharactersWithinFile = FALSE;
243 BOOL enableDetectMovedOrCopiedLinesNumCharactersFromFiles = FALSE;
244 if (m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE)
246 enableDetectMovedOrCopiedLinesNumCharactersWithinFile = TRUE;
248 if (m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES || m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION || m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES)
250 enableDetectMovedOrCopiedLinesNumCharactersFromFiles = TRUE;
252 BOOL enableShowCompleteLog = FALSE;
253 BOOL enableFollowRenames = FALSE;
254 if (BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines))
256 enableShowCompleteLog = TRUE;
257 if (m_bShowCompleteLog)
258 enableFollowRenames = TRUE;
259 else if (m_bFollowRenames)
261 m_bFollowRenames = FALSE;
262 UpdateData(FALSE);
265 else if (m_bShowCompleteLog || m_bFollowRenames)
267 m_bShowCompleteLog = FALSE;
268 m_bFollowRenames = FALSE;
269 UpdateData(FALSE);
271 GetDlgItem(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE)->EnableWindow(enableDetectMovedOrCopiedLinesNumCharactersWithinFile);
272 GetDlgItem(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES)->EnableWindow(enableDetectMovedOrCopiedLinesNumCharactersFromFiles);
273 GetDlgItem(IDC_SHOWCOMPLETELOG)->EnableWindow(enableShowCompleteLog);
274 GetDlgItem(IDC_FOLLOWRENAMES)->EnableWindow(enableFollowRenames);