Add retry button when fetch failed
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingsTBlame.cpp
blob8d07003cb570ea470d9eba2c50204659f3daddba
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 m_cNewLinesColor.SetColor((DWORD)m_regNewLinesColor);
114 m_cOldLinesColor.SetColor((DWORD)m_regOldLinesColor);
116 CString sDefaultText, sCustomText;
117 sDefaultText.LoadString(IDS_COLOURPICKER_DEFAULTTEXT);
118 sCustomText.LoadString(IDS_COLOURPICKER_CUSTOMTEXT);
119 m_cNewLinesColor.EnableAutomaticButton(sDefaultText, BLAMENEWCOLOR);
120 m_cNewLinesColor.EnableOtherButton(sCustomText);
121 m_cOldLinesColor.EnableAutomaticButton(sDefaultText, BLAMEOLDCOLOR);
122 m_cOldLinesColor.EnableOtherButton(sCustomText);
124 m_dwTabSize = m_regTabSize;
125 m_sFontName = m_regFontName;
126 m_dwFontSize = m_regFontSize;
127 m_dwDetectMovedOrCopiedLines = m_regDetectMovedOrCopiedLines;
128 m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile = m_regDetectMovedOrCopiedLinesNumCharactersWithinFile;
129 m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles = m_regDetectMovedOrCopiedLinesNumCharactersFromFiles;
130 m_bIgnoreWhitespace = m_regIgnoreWhitespace;
131 m_bShowCompleteLog = m_regShowCompleteLog;
132 m_bFollowRenames = m_regFollowRenames;
133 int count = 0;
134 CString temp;
135 for (int i=6; i<32; i=i+2)
137 temp.Format(_T("%d"), i);
138 m_cFontSizes.AddString(temp);
139 m_cFontSizes.SetItemData(count++, i);
141 BOOL foundfont = FALSE;
142 for (int i=0; i<m_cFontSizes.GetCount(); i++)
144 if (m_cFontSizes.GetItemData(i) == m_dwFontSize)
146 m_cFontSizes.SetCurSel(i);
147 foundfont = TRUE;
150 if (!foundfont)
152 temp.Format(_T("%lu"), m_dwFontSize);
153 m_cFontSizes.SetWindowText(temp);
155 m_cFontNames.Setup(DEVICE_FONTTYPE|RASTER_FONTTYPE|TRUETYPE_FONTTYPE, 1, FIXED_PITCH);
156 m_cFontNames.SelectFont(m_sFontName);
158 CString sDetectMovedOrCopiedLinesDisabled;
159 CString sDetectMovedOrCopiedLinesWithinFile;
160 CString sDetectMovedOrCopiedLinesFromModifiedFiles;
161 CString sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation;
162 CString sDetectMovedOrCopiedLinesFromExistingFiles;
163 sDetectMovedOrCopiedLinesDisabled.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
164 sDetectMovedOrCopiedLinesWithinFile.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
165 sDetectMovedOrCopiedLinesFromModifiedFiles.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
166 sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
167 sDetectMovedOrCopiedLinesFromExistingFiles.LoadString(IDS_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
169 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesDisabled);
170 m_cDetectMovedOrCopiedLines.SetItemData(0, BLAME_DETECT_MOVED_OR_COPIED_LINES_DISABLED);
171 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesWithinFile);
172 m_cDetectMovedOrCopiedLines.SetItemData(1, BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE);
173 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromModifiedFiles);
174 m_cDetectMovedOrCopiedLines.SetItemData(2, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_MODIFIED_FILES);
175 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromExistingFilesAtFileCreation);
176 m_cDetectMovedOrCopiedLines.SetItemData(3, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES_AT_FILE_CREATION);
177 m_cDetectMovedOrCopiedLines.AddString(sDetectMovedOrCopiedLinesFromExistingFiles);
178 m_cDetectMovedOrCopiedLines.SetItemData(4, BLAME_DETECT_MOVED_OR_COPIED_LINES_FROM_EXISTING_FILES);
179 for (int i = 0; i < m_cDetectMovedOrCopiedLines.GetCount(); ++i)
181 if (m_cDetectMovedOrCopiedLines.GetItemData(i) == m_dwDetectMovedOrCopiedLines)
183 m_cDetectMovedOrCopiedLines.SetCurSel(i);
184 break;
188 UpdateData(FALSE);
189 UpdateDependencies();
190 return TRUE;
193 void CSettingsTBlame::OnChange()
195 UpdateData();
196 UpdateDependencies();
197 SetModified();
200 void CSettingsTBlame::OnBnClickedRestore()
202 m_cOldLinesColor.SetColor(BLAMEOLDCOLOR);
203 m_cNewLinesColor.SetColor(BLAMENEWCOLOR);
204 SetModified(TRUE);
207 BOOL CSettingsTBlame::OnApply()
209 UpdateData();
210 if (m_cFontNames.GetSelFont())
211 m_sFontName = m_cFontNames.GetSelFont()->m_strName;
212 else
213 m_sFontName = m_regFontName;
215 Store ((m_cNewLinesColor.GetColor() == -1 ? m_cNewLinesColor.GetAutomaticColor() : m_cNewLinesColor.GetColor()), m_regNewLinesColor);
216 Store ((m_cOldLinesColor.GetColor() == -1 ? m_cOldLinesColor.GetAutomaticColor() : m_cOldLinesColor.GetColor()), m_regOldLinesColor);
217 Store ((LPCTSTR)m_sFontName, m_regFontName);
218 Store (m_dwFontSize, m_regFontSize);
219 Store (m_dwTabSize, m_regTabSize);
220 Store (m_dwDetectMovedOrCopiedLines, m_regDetectMovedOrCopiedLines);
221 Store (m_dwDetectMovedOrCopiedLinesNumCharactersWithinFile, m_regDetectMovedOrCopiedLinesNumCharactersWithinFile);
222 Store (m_dwDetectMovedOrCopiedLinesNumCharactersFromFiles, m_regDetectMovedOrCopiedLinesNumCharactersFromFiles);
223 Store (m_bIgnoreWhitespace, m_regIgnoreWhitespace);
224 Store (m_bShowCompleteLog, m_regShowCompleteLog);
225 Store (m_bFollowRenames, m_regFollowRenames);
227 SetModified(FALSE);
228 return ISettingsPropPage::OnApply();
231 void CSettingsTBlame::OnBnClickedColor()
233 SetModified();
236 void CSettingsTBlame::UpdateDependencies()
238 BOOL enableDetectMovedOrCopiedLinesNumCharactersWithinFile = FALSE;
239 BOOL enableDetectMovedOrCopiedLinesNumCharactersFromFiles = FALSE;
240 if (m_dwDetectMovedOrCopiedLines == BLAME_DETECT_MOVED_OR_COPIED_LINES_WITHIN_FILE)
242 enableDetectMovedOrCopiedLinesNumCharactersWithinFile = TRUE;
244 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)
246 enableDetectMovedOrCopiedLinesNumCharactersFromFiles = TRUE;
248 BOOL enableShowCompleteLog = FALSE;
249 BOOL enableFollowRenames = FALSE;
250 if (BlameIsLimitedToOneFilename(m_dwDetectMovedOrCopiedLines))
252 enableShowCompleteLog = TRUE;
253 if (m_bShowCompleteLog)
254 enableFollowRenames = TRUE;
255 else if (m_bFollowRenames)
257 m_bFollowRenames = FALSE;
258 UpdateData(FALSE);
261 else if (m_bShowCompleteLog || m_bFollowRenames)
263 m_bShowCompleteLog = FALSE;
264 m_bFollowRenames = FALSE;
265 UpdateData(FALSE);
267 GetDlgItem(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_WITHIN_FILE)->EnableWindow(enableDetectMovedOrCopiedLinesNumCharactersWithinFile);
268 GetDlgItem(IDC_DETECT_MOVED_OR_COPIED_LINES_NUM_CHARACTERS_FROM_FILES)->EnableWindow(enableDetectMovedOrCopiedLinesNumCharactersFromFiles);
269 GetDlgItem(IDC_SHOWCOMPLETELOG)->EnableWindow(enableShowCompleteLog);
270 GetDlgItem(IDC_FOLLOWRENAMES)->EnableWindow(enableFollowRenames);