No need to explicitly initialize CString and use Empty() for clearing CString
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingsTBlame.cpp
blob63cf600ae6fcae3178bb6a411c8b315b16ebab9d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
4 // Copyright (C) 2011-2015 - 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_dwTabSize(4)
36 , m_dwDetectMovedOrCopiedLines(BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED)
37 , m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile(BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE_DEFAULT)
38 , m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles(BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES_DEFAULT)
39 , m_bIgnoreWhitespace(0)
40 , m_bShowCompleteLog(0)
41 , m_bFollowRenames(0)
43 m_regNewLinesColor = CRegDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), BLAMENEWCOLOR);
44 m_regOldLinesColor = CRegDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), BLAMEOLDCOLOR);
45 m_regFontName = CRegString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
46 m_regFontSize = CRegDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10);
47 m_regTabSize = CRegDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4);
48 m_regDetectMovedOrCopiedLines = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\DetectMovedOrCopiedLines"), BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
49 m_regDetectMovedOrCopiedLinesNumCharactersWithinFile = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\DetectMovedOrCopiedLinesNumCharactersWithinFile"), BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE_DEFAULT);
50 m_regDetectMovedOrCopiedLinesNumCharactersFromFiles = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\DetectMovedOrCopiedLinesNumCharactersFromFiles"), BLAME_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES_DEFAULT);
51 m_regIgnoreWhitespace = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\IgnoreWhitespace"), 0);
52 m_regShowCompleteLog = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\ShowCompleteLog"), 1);
53 m_regFollowRenames = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\FollowRenames"), 0);
56 CSettingsTBlame::~CSettingsTBlame()
60 void CSettingsTBlame::DoDataExchange(CDataExchange* pDX)
62 ISettingsPropPage::DoDataExchange(pDX);
63 DDX_Control(pDX, IDC_NEWLINESCOLOR, m_cNewLinesColor);
64 DDX_Control(pDX, IDC_OLDLINESCOLOR, m_cOldLinesColor);
65 DDX_Control(pDX, IDC_FONTSIZES, m_cFontSizes);
66 m_dwFontSize = (DWORD)m_cFontSizes.GetItemData(m_cFontSizes.GetCurSel());
67 if ((m_dwFontSize==0)||(m_dwFontSize == -1))
69 CString t;
70 m_cFontSizes.GetWindowText(t);
71 m_dwFontSize = _ttoi(t);
73 DDX_Control(pDX, IDC_FONTNAMES, m_cFontNames);
74 DDX_Text(pDX, IDC_TABSIZE, m_dwTabSize);
75 DDX_Control(pDX, IDC_DETECT_MOVED_OR_COPIED_LINES, m_cDetectMovedOrCopiedLines);
76 m_dwDetectMovedOrCopiedLines = (DWORD)m_cDetectMovedOrCopiedLines.GetItemData(m_cDetectMovedOrCopiedLines.GetCurSel());
77 if (m_dwDetectMovedOrCopiedLines == -1){
78 m_dwDetectMovedOrCopiedLines = BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED;
80 DDX_Text(pDX, IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE, m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile);
81 DDX_Text(pDX, IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES, m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles);
82 DDX_Check(pDX, IDC_IGNORE_WHITESPACE, m_bIgnoreWhitespace);
83 DDX_Check(pDX, IDC_SHOWCOMPLETELOG, m_bShowCompleteLog);
84 DDX_Check(pDX, IDC_FOLLOWRENAMES, m_bFollowRenames);
88 BEGIN_MESSAGE_MAP(CSettingsTBlame, ISettingsPropPage)
89 ON_BN_CLICKED(IDC_RESTORE, OnBnClickedRestore)
90 ON_CBN_SELCHANGE(IDC_FONTSIZES, OnChange)
91 ON_CBN_SELCHANGE(IDC_FONTNAMES, OnChange)
92 ON_EN_CHANGE(IDC_TABSIZE, OnChange)
93 ON_CBN_SELCHANGE(IDC_DETECT_MOVED_OR_COPIED_LINES, OnChange)
94 ON_EN_CHANGE(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE, OnChange)
95 ON_EN_CHANGE(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES, OnChange)
96 ON_BN_CLICKED(IDC_IGNORE_WHITESPACE, OnChange)
97 ON_BN_CLICKED(IDC_SHOWCOMPLETELOG, OnChange)
98 ON_BN_CLICKED(IDC_FOLLOWRENAMES, OnChange)
99 ON_BN_CLICKED(IDC_NEWLINESCOLOR, &CSettingsTBlame::OnBnClickedColor)
100 ON_BN_CLICKED(IDC_OLDLINESCOLOR, &CSettingsTBlame::OnBnClickedColor)
101 END_MESSAGE_MAP()
104 // CSettingsTBlame message handlers
106 BOOL CSettingsTBlame::OnInitDialog()
108 CMFCFontComboBox::m_bDrawUsingFont = true;
110 ISettingsPropPage::OnInitDialog();
112 AdjustControlSize(IDC_IGNORE_WHITESPACE);
113 AdjustControlSize(IDC_SHOWCOMPLETELOG);
114 AdjustControlSize(IDC_FOLLOWRENAMES);
116 m_cNewLinesColor.SetColor((DWORD)m_regNewLinesColor);
117 m_cOldLinesColor.SetColor((DWORD)m_regOldLinesColor);
119 CString sDefaultText, sCustomText;
120 sDefaultText.LoadString(IDS_COLOURPICKER_DEFAULTTEXT);
121 sCustomText.LoadString(IDS_COLOURPICKER_CUSTOMTEXT);
122 m_cNewLinesColor.EnableAutomaticButton(sDefaultText, BLAMENEWCOLOR);
123 m_cNewLinesColor.EnableOtherButton(sCustomText);
124 m_cOldLinesColor.EnableAutomaticButton(sDefaultText, BLAMEOLDCOLOR);
125 m_cOldLinesColor.EnableOtherButton(sCustomText);
127 m_dwTabSize = m_regTabSize;
128 m_sFontName = m_regFontName;
129 m_dwFontSize = m_regFontSize;
130 m_dwDetectMovedOrCopiedLines = m_regDetectMovedOrCopiedLines;
131 m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile = m_regDetectMovedOrCopiedLinesNumCharactersWithinFile;
132 m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles = m_regDetectMovedOrCopiedLinesNumCharactersFromFiles;
133 m_bIgnoreWhitespace = m_regIgnoreWhitespace;
134 m_bShowCompleteLog = m_regShowCompleteLog;
135 m_bFollowRenames = m_regFollowRenames;
136 int count = 0;
137 CString temp;
138 for (int i=6; i<32; i=i+2)
140 temp.Format(_T("%d"), i);
141 m_cFontSizes.AddString(temp);
142 m_cFontSizes.SetItemData(count++, i);
144 BOOL foundfont = FALSE;
145 for (int i=0; i<m_cFontSizes.GetCount(); i++)
147 if (m_cFontSizes.GetItemData(i) == m_dwFontSize)
149 m_cFontSizes.SetCurSel(i);
150 foundfont = TRUE;
153 if (!foundfont)
155 temp.Format(_T("%lu"), m_dwFontSize);
156 m_cFontSizes.SetWindowText(temp);
158 m_cFontNames.Setup(DEVICE_FONTTYPE|RASTER_FONTTYPE|TRUETYPE_FONTTYPE, 1, FIXED_PITCH);
159 m_cFontNames.SelectFont(m_sFontName);
161 CString sDetectMovedOrCopiedLinesDisabled;
162 CString sDetectMovedOrCopiedLinesWithinFile;
163 CString sDetectMovedOrCopiedLinesFromModifiedFiles;
164 CString sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation;
165 CString sDetectMovedOrCopiedLinesFromExistingFiles;
166 sDetectMovedOrCopiedLinesDisabled.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
167 sDetectMovedOrCopiedLinesWithinFile.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
168 sDetectMovedOrCopiedLinesFromModifiedFiles.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
169 sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
170 sDetectMovedOrCopiedLinesFromExistingFiles.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
172 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesDisabled);
173 m_cDetectMovedOrCopiedLines.SetItemData(0, BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
174 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesWithinFile);
175 m_cDetectMovedOrCopiedLines.SetItemData(1, BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
176 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromModifiedFiles);
177 m_cDetectMovedOrCopiedLines.SetItemData(2, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
178 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation);
179 m_cDetectMovedOrCopiedLines.SetItemData(3, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
180 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromExistingFiles);
181 m_cDetectMovedOrCopiedLines.SetItemData(4, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
182 for (int i = 0; i < m_cDetectMovedOrCopiedLines.GetCount(); ++i)
184 if (m_cDetectMovedOrCopiedLines.GetItemData(i) == m_dwDetectMovedOrCopiedLines)
186 m_cDetectMovedOrCopiedLines.SetCurSel(i);
187 break;
191 UpdateData(FALSE);
192 UpdateDependencies();
193 return TRUE;
196 void CSettingsTBlame::OnChange()
198 UpdateData();
199 UpdateDependencies();
200 SetModified();
203 void CSettingsTBlame::OnBnClickedRestore()
205 m_cOldLinesColor.SetColor(BLAMEOLDCOLOR);
206 m_cNewLinesColor.SetColor(BLAMENEWCOLOR);
207 SetModified(TRUE);
210 BOOL CSettingsTBlame::OnApply()
212 UpdateData();
213 if (m_cFontNames.GetSelFont())
214 m_sFontName = m_cFontNames.GetSelFont()->m_strName;
215 else
216 m_sFontName = m_regFontName;
218 Store((m_cNewLinesColor.GetColor() == -1 ? m_cNewLinesColor.GetAutomaticColor() : m_cNewLinesColor.GetColor()), m_regNewLinesColor);
219 Store((m_cOldLinesColor.GetColor() == -1 ? m_cOldLinesColor.GetAutomaticColor() : m_cOldLinesColor.GetColor()), m_regOldLinesColor);
220 Store((LPCTSTR)m_sFontName, m_regFontName);
221 Store(m_dwFontSize, m_regFontSize);
222 Store(m_dwTabSize, m_regTabSize);
223 Store(m_dwDetectMovedOrCopiedLines, m_regDetectMovedOrCopiedLines);
224 Store(m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile, m_regDetectMovedOrCopiedLinesNumCharactersWithinFile);
225 Store(m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles, m_regDetectMovedOrCopiedLinesNumCharactersFromFiles);
226 Store(m_bIgnoreWhitespace, m_regIgnoreWhitespace);
227 Store(m_bShowCompleteLog, m_regShowCompleteLog);
228 Store(m_bFollowRenames, m_regFollowRenames);
230 SetModified(FALSE);
231 return ISettingsPropPage::OnApply();
234 void CSettingsTBlame::OnBnClickedColor()
236 SetModified();
239 void CSettingsTBlame::UpdateDependencies()
241 BOOL enableDetectMovedOrCopiedLinesNumCharactersWithinFile = FALSE;
242 BOOL enableDetectMovedOrCopiedLinesNumCharactersFromFiles = FALSE;
243 if (m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE)
245 enableDetectMovedOrCopiedLinesNumCharactersWithinFile = TRUE;
247 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)
249 enableDetectMovedOrCopiedLinesNumCharactersFromFiles = TRUE;
251 BOOL enableShowCompleteLog = FALSE;
252 BOOL enableFollowRenames = FALSE;
253 if (BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines))
255 enableShowCompleteLog = TRUE;
256 if (m_bShowCompleteLog)
257 enableFollowRenames = TRUE;
258 else if (m_bFollowRenames)
260 m_bFollowRenames = FALSE;
261 UpdateData(FALSE);
264 else if (m_bShowCompleteLog || m_bFollowRenames)
266 m_bShowCompleteLog = FALSE;
267 m_bFollowRenames = FALSE;
268 UpdateData(FALSE);
270 GetDlgItem(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE)->EnableWindow(enableDetectMovedOrCopiedLinesNumCharactersWithinFile);
271 GetDlgItem(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES)->EnableWindow(enableDetectMovedOrCopiedLinesNumCharactersFromFiles);
272 GetDlgItem(IDC_SHOWCOMPLETELOG)->EnableWindow(enableShowCompleteLog);
273 GetDlgItem(IDC_FOLLOWRENAMES)->EnableWindow(enableFollowRenames);