Fix typos
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingsTBlame.cpp
blob207860168c385227ce59adea694e083efb487cf3
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008, 2018 - TortoiseSVN
4 // Copyright (C) 2011-2019 - 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 "SettingsTBlame.h"
23 #include "../TortoiseGitBlame/BlameIndexColors.h"
24 #include "../TortoiseGitBlame/BlameDetectMovedOrCopiedLines.h"
27 // CSettingsTBlame dialog
29 //IMPLEMENT_DYNAMIC(CSettingsTBlame, ISettingsPropPage)
31 CSettingsTBlame::CSettingsTBlame()
32 : ISettingsPropPage(CSettingsTBlame::IDD)
33 , m_dwFontSize(0)
34 , m_dwTabSize(4)
35 , m_dwDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED)
36 , m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile(BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE_DEFAULT)
37 , m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles(BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES_DEFAULT)
38 , m_bIgnoreWhitespace(0)
39 , m_bShowCompleteLog(0)
40 , m_bFirstParent(0)
41 , m_bFollowRenames(0)
43 m_regNewLinesColor = CRegDWORD(L"Software\\TortoiseGit\\BlameNewColor", BLAMENEWCOLOR);
44 m_regOldLinesColor = CRegDWORD(L"Software\\TortoiseGit\\BlameOldColor", BLAMEOLDCOLOR);
45 m_regFontName = CRegString(L"Software\\TortoiseGit\\BlameFontName", L"Consolas");
46 m_regFontSize = CRegDWORD(L"Software\\TortoiseGit\\BlameFontSize", 10);
47 m_regTabSize = CRegDWORD(L"Software\\TortoiseGit\\BlameTabSize", 4);
48 m_regDetectMovedOrCopiedLines = CRegDWORD(L"Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\DetectMovedOrCopiedLines", BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
49 m_regDetectMovedOrCopiedLinesNumCharactersWithinFile = CRegDWORD(L"Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\DetectMovedOrCopiedLinesNumCharactersWithinFile", BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE_DEFAULT);
50 m_regDetectMovedOrCopiedLinesNumCharactersFromFiles = CRegDWORD(L"Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\DetectMovedOrCopiedLinesNumCharactersFromFiles", BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES_DEFAULT);
51 m_regIgnoreWhitespace = CRegDWORD(L"Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\IgnoreWhitespace", 0);
52 m_regShowCompleteLog = CRegDWORD(L"Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\ShowCompleteLog", 1);
53 m_regFirstParent = CRegDWORD(L"Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\OnlyFirstParent", 0);
54 m_regFollowRenames = CRegDWORD(L"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 = static_cast<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 = _wtoi(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 = static_cast<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_BLAME_ONLYFIRSTPARENT, m_bFirstParent);
86 DDX_Check(pDX, IDC_FOLLOWRENAMES, m_bFollowRenames);
90 BEGIN_MESSAGE_MAP(CSettingsTBlame, ISettingsPropPage)
91 ON_BN_CLICKED(IDC_RESTORE, OnBnClickedRestore)
92 ON_CBN_SELCHANGE(IDC_FONTSIZES, OnChange)
93 ON_CBN_SELCHANGE(IDC_FONTNAMES, OnChange)
94 ON_EN_CHANGE(IDC_TABSIZE, OnChange)
95 ON_CBN_SELCHANGE(IDC_DETECT_MOVED_OR_COPIED_LINES, OnChange)
96 ON_EN_CHANGE(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE, OnChange)
97 ON_EN_CHANGE(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES, OnChange)
98 ON_BN_CLICKED(IDC_IGNORE_WHITESPACE, OnChange)
99 ON_BN_CLICKED(IDC_SHOWCOMPLETELOG, OnChange)
100 ON_BN_CLICKED(IDC_BLAME_ONLYFIRSTPARENT, OnChange)
101 ON_BN_CLICKED(IDC_FOLLOWRENAMES, OnChange)
102 ON_BN_CLICKED(IDC_NEWLINESCOLOR, &CSettingsTBlame::OnBnClickedColor)
103 ON_BN_CLICKED(IDC_OLDLINESCOLOR, &CSettingsTBlame::OnBnClickedColor)
104 ON_WM_MEASUREITEM()
105 END_MESSAGE_MAP()
108 // CSettingsTBlame message handlers
110 BOOL CSettingsTBlame::OnInitDialog()
112 CMFCFontComboBox::m_bDrawUsingFont = true;
114 ISettingsPropPage::OnInitDialog();
116 AdjustControlSize(IDC_IGNORE_WHITESPACE);
117 AdjustControlSize(IDC_SHOWCOMPLETELOG);
118 AdjustControlSize(IDC_BLAME_ONLYFIRSTPARENT);
119 AdjustControlSize(IDC_FOLLOWRENAMES);
121 m_cNewLinesColor.SetColor(m_regNewLinesColor);
122 m_cOldLinesColor.SetColor(m_regOldLinesColor);
124 CString sDefaultText, sCustomText;
125 sDefaultText.LoadString(IDS_COLOURPICKER_DEFAULTTEXT);
126 sCustomText.LoadString(IDS_COLOURPICKER_CUSTOMTEXT);
127 m_cNewLinesColor.EnableAutomaticButton(sDefaultText, BLAMENEWCOLOR);
128 m_cNewLinesColor.EnableOtherButton(sCustomText);
129 m_cOldLinesColor.EnableAutomaticButton(sDefaultText, BLAMEOLDCOLOR);
130 m_cOldLinesColor.EnableOtherButton(sCustomText);
132 m_dwTabSize = m_regTabSize;
133 m_sFontName = m_regFontName;
134 m_dwFontSize = m_regFontSize;
135 m_dwDetectMovedOrCopiedLines = m_regDetectMovedOrCopiedLines;
136 m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile = m_regDetectMovedOrCopiedLinesNumCharactersWithinFile;
137 m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles = m_regDetectMovedOrCopiedLinesNumCharactersFromFiles;
138 m_bIgnoreWhitespace = m_regIgnoreWhitespace;
139 m_bShowCompleteLog = m_regShowCompleteLog;
140 m_bFirstParent = m_regFirstParent;
141 m_bFollowRenames = m_regFollowRenames;
142 int count = 0;
143 CString temp;
144 for (int i=6; i<32; i=i+2)
146 temp.Format(L"%d", i);
147 m_cFontSizes.AddString(temp);
148 m_cFontSizes.SetItemData(count++, i);
150 BOOL foundfont = FALSE;
151 for (int i=0; i<m_cFontSizes.GetCount(); i++)
153 if (m_cFontSizes.GetItemData(i) == m_dwFontSize)
155 m_cFontSizes.SetCurSel(i);
156 foundfont = TRUE;
159 if (!foundfont)
161 temp.Format(L"%lu", m_dwFontSize);
162 m_cFontSizes.SetWindowText(temp);
164 m_cFontNames.Setup(DEVICE_FONTTYPE|RASTER_FONTTYPE|TRUETYPE_FONTTYPE, 1, FIXED_PITCH);
165 m_cFontNames.SelectFont(m_sFontName);
166 m_cFontNames.SendMessage(CB_SETITEMHEIGHT, static_cast<WPARAM>(-1), m_cFontSizes.GetItemHeight(-1));
168 CString sDetectMovedOrCopiedLinesDisabled;
169 CString sDetectMovedOrCopiedLinesWithinFile;
170 CString sDetectMovedOrCopiedLinesFromModifiedFiles;
171 CString sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation;
172 CString sDetectMovedOrCopiedLinesFromExistingFiles;
173 sDetectMovedOrCopiedLinesDisabled.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
174 sDetectMovedOrCopiedLinesWithinFile.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
175 sDetectMovedOrCopiedLinesFromModifiedFiles.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
176 sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
177 sDetectMovedOrCopiedLinesFromExistingFiles.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
179 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesDisabled);
180 m_cDetectMovedOrCopiedLines.SetItemData(0, BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
181 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesWithinFile);
182 m_cDetectMovedOrCopiedLines.SetItemData(1, BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
183 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromModifiedFiles);
184 m_cDetectMovedOrCopiedLines.SetItemData(2, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
185 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation);
186 m_cDetectMovedOrCopiedLines.SetItemData(3, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
187 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromExistingFiles);
188 m_cDetectMovedOrCopiedLines.SetItemData(4, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
189 for (int i = 0; i < m_cDetectMovedOrCopiedLines.GetCount(); ++i)
191 if (m_cDetectMovedOrCopiedLines.GetItemData(i) == m_dwDetectMovedOrCopiedLines)
193 m_cDetectMovedOrCopiedLines.SetCurSel(i);
194 break;
198 UpdateData(FALSE);
199 UpdateDependencies();
200 return TRUE;
203 void CSettingsTBlame::OnChange()
205 UpdateData();
206 UpdateDependencies();
207 SetModified();
210 void CSettingsTBlame::OnBnClickedRestore()
212 m_cOldLinesColor.SetColor(BLAMEOLDCOLOR);
213 m_cNewLinesColor.SetColor(BLAMENEWCOLOR);
214 SetModified(TRUE);
217 BOOL CSettingsTBlame::OnApply()
219 UpdateData();
220 if (m_cFontNames.GetSelFont())
221 m_sFontName = m_cFontNames.GetSelFont()->m_strName;
222 else
223 m_sFontName = m_regFontName;
225 Store((m_cNewLinesColor.GetColor() == -1 ? m_cNewLinesColor.GetAutomaticColor() : m_cNewLinesColor.GetColor()), m_regNewLinesColor);
226 Store((m_cOldLinesColor.GetColor() == -1 ? m_cOldLinesColor.GetAutomaticColor() : m_cOldLinesColor.GetColor()), m_regOldLinesColor);
227 Store(static_cast<LPCWSTR>(m_sFontName), m_regFontName);
228 Store(m_dwFontSize, m_regFontSize);
229 Store(m_dwTabSize, m_regTabSize);
230 Store(m_dwDetectMovedOrCopiedLines, m_regDetectMovedOrCopiedLines);
231 Store(m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile, m_regDetectMovedOrCopiedLinesNumCharactersWithinFile);
232 Store(m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles, m_regDetectMovedOrCopiedLinesNumCharactersFromFiles);
233 Store(m_bIgnoreWhitespace, m_regIgnoreWhitespace);
234 Store(m_bShowCompleteLog, m_regShowCompleteLog);
235 Store(m_bFirstParent, m_regFirstParent);
236 Store(m_bFollowRenames, m_regFollowRenames);
238 SetModified(FALSE);
239 return ISettingsPropPage::OnApply();
242 void CSettingsTBlame::OnBnClickedColor()
244 SetModified();
247 void CSettingsTBlame::UpdateDependencies()
249 BOOL enableDetectMovedOrCopiedLinesNumCharactersWithinFile = FALSE;
250 BOOL enableDetectMovedOrCopiedLinesNumCharactersFromFiles = FALSE;
251 if (m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE)
252 enableDetectMovedOrCopiedLinesNumCharactersWithinFile = TRUE;
253 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)
254 enableDetectMovedOrCopiedLinesNumCharactersFromFiles = TRUE;
255 BOOL enableShowCompleteLog = FALSE;
256 BOOL enableFollowRenames = FALSE;
257 if (BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines) && !m_bFirstParent)
259 enableShowCompleteLog = TRUE;
260 if (m_bShowCompleteLog)
261 enableFollowRenames = TRUE;
262 else if (m_bFollowRenames)
264 m_bFollowRenames = FALSE;
265 UpdateData(FALSE);
268 else if (m_bShowCompleteLog || m_bFollowRenames)
270 m_bShowCompleteLog = FALSE;
271 m_bFollowRenames = FALSE;
272 UpdateData(FALSE);
274 GetDlgItem(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE)->EnableWindow(enableDetectMovedOrCopiedLinesNumCharactersWithinFile);
275 GetDlgItem(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES)->EnableWindow(enableDetectMovedOrCopiedLinesNumCharactersFromFiles);
276 GetDlgItem(IDC_SHOWCOMPLETELOG)->EnableWindow(enableShowCompleteLog);
277 GetDlgItem(IDC_FOLLOWRENAMES)->EnableWindow(enableFollowRenames);
280 void CSettingsTBlame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
282 CFont* pFont = GetFont();
283 if (pFont)
285 CDC* pDC = GetDC();
286 CFont* pFontPrev = pDC->SelectObject(pFont);
287 int iborder = ::GetSystemMetrics(SM_CYBORDER);
288 CSize sz = pDC->GetTextExtent(L"0");
289 lpMeasureItemStruct->itemHeight = sz.cy + 2 * iborder;
290 pDC->SelectObject(pFontPrev);
291 ReleaseDC(pDC);
293 ISettingsPropPage::OnMeasureItem(nIDCtl, lpMeasureItemStruct);