Use new constants everywhere
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingsTBlame.cpp
blob4f73434fe0622783fdf2aaa158a953883f415069
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
4 // Copyright (C) 2011-2013 - 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"
27 // CSettingsTBlame dialog
29 //IMPLEMENT_DYNAMIC(CSettingsTBlame, ISettingsPropPage)
31 CSettingsTBlame::CSettingsTBlame()
32 : ISettingsPropPage(CSettingsTBlame::IDD)
33 , m_dwFontSize(0)
34 , m_sFontName(_T(""))
35 , m_dwTabSize(4)
36 , m_bFollowRenames(0)
38 m_regNewLinesColor = CRegDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), BLAMENEWCOLOR);
39 m_regOldLinesColor = CRegDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), BLAMEOLDCOLOR);
40 m_regFontName = CRegString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
41 m_regFontSize = CRegDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10);
42 m_regTabSize = CRegDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4);
43 m_regFollowRenames = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseGitBlame\\Workspace\\FollowRenames"), 0);
46 CSettingsTBlame::~CSettingsTBlame()
50 void CSettingsTBlame::DoDataExchange(CDataExchange* pDX)
52 ISettingsPropPage::DoDataExchange(pDX);
53 DDX_Control(pDX, IDC_NEWLINESCOLOR, m_cNewLinesColor);
54 DDX_Control(pDX, IDC_OLDLINESCOLOR, m_cOldLinesColor);
55 DDX_Control(pDX, IDC_FONTSIZES, m_cFontSizes);
56 m_dwFontSize = (DWORD)m_cFontSizes.GetItemData(m_cFontSizes.GetCurSel());
57 if ((m_dwFontSize==0)||(m_dwFontSize == -1))
59 CString t;
60 m_cFontSizes.GetWindowText(t);
61 m_dwFontSize = _ttoi(t);
63 DDX_Control(pDX, IDC_FONTNAMES, m_cFontNames);
64 DDX_Text(pDX, IDC_TABSIZE, m_dwTabSize);
65 DDX_Check(pDX, IDC_FOLLOWRENAMES, m_bFollowRenames);
69 BEGIN_MESSAGE_MAP(CSettingsTBlame, ISettingsPropPage)
70 ON_BN_CLICKED(IDC_RESTORE, OnBnClickedRestore)
71 ON_CBN_SELCHANGE(IDC_FONTSIZES, OnChange)
72 ON_CBN_SELCHANGE(IDC_FONTNAMES, OnChange)
73 ON_EN_CHANGE(IDC_TABSIZE, OnChange)
74 ON_BN_CLICKED(IDC_FOLLOWRENAMES, OnChange)
75 ON_BN_CLICKED(IDC_NEWLINESCOLOR, &CSettingsTBlame::OnBnClickedColor)
76 ON_BN_CLICKED(IDC_OLDLINESCOLOR, &CSettingsTBlame::OnBnClickedColor)
77 END_MESSAGE_MAP()
80 // CSettingsTBlame message handlers
82 BOOL CSettingsTBlame::OnInitDialog()
84 CMFCFontComboBox::m_bDrawUsingFont = true;
86 ISettingsPropPage::OnInitDialog();
88 m_cNewLinesColor.SetColor((DWORD)m_regNewLinesColor);
89 m_cOldLinesColor.SetColor((DWORD)m_regOldLinesColor);
91 CString sDefaultText, sCustomText;
92 sDefaultText.LoadString(IDS_COLOURPICKER_DEFAULTTEXT);
93 sCustomText.LoadString(IDS_COLOURPICKER_CUSTOMTEXT);
94 m_cNewLinesColor.EnableAutomaticButton(sDefaultText, BLAMENEWCOLOR);
95 m_cNewLinesColor.EnableOtherButton(sCustomText);
96 m_cOldLinesColor.EnableAutomaticButton(sDefaultText, BLAMEOLDCOLOR);
97 m_cOldLinesColor.EnableOtherButton(sCustomText);
99 m_dwTabSize = m_regTabSize;
100 m_sFontName = m_regFontName;
101 m_dwFontSize = m_regFontSize;
102 m_bFollowRenames = m_regFollowRenames;
103 int count = 0;
104 CString temp;
105 for (int i=6; i<32; i=i+2)
107 temp.Format(_T("%d"), i);
108 m_cFontSizes.AddString(temp);
109 m_cFontSizes.SetItemData(count++, i);
111 BOOL foundfont = FALSE;
112 for (int i=0; i<m_cFontSizes.GetCount(); i++)
114 if (m_cFontSizes.GetItemData(i) == m_dwFontSize)
116 m_cFontSizes.SetCurSel(i);
117 foundfont = TRUE;
120 if (!foundfont)
122 temp.Format(_T("%d"), m_dwFontSize);
123 m_cFontSizes.SetWindowText(temp);
125 m_cFontNames.Setup(DEVICE_FONTTYPE|RASTER_FONTTYPE|TRUETYPE_FONTTYPE, 1, FIXED_PITCH);
126 m_cFontNames.SelectFont(m_sFontName);
128 UpdateData(FALSE);
129 return TRUE;
132 void CSettingsTBlame::OnChange()
134 SetModified();
137 void CSettingsTBlame::OnBnClickedRestore()
139 m_cOldLinesColor.SetColor(BLAMEOLDCOLOR);
140 m_cNewLinesColor.SetColor(BLAMENEWCOLOR);
141 SetModified(TRUE);
144 BOOL CSettingsTBlame::OnApply()
146 UpdateData();
147 if (m_cFontNames.GetSelFont())
148 m_sFontName = m_cFontNames.GetSelFont()->m_strName;
149 else
150 m_sFontName = m_regFontName;
152 Store ((m_cNewLinesColor.GetColor() == -1 ? m_cNewLinesColor.GetAutomaticColor() : m_cNewLinesColor.GetColor()), m_regNewLinesColor);
153 Store ((m_cOldLinesColor.GetColor() == -1 ? m_cOldLinesColor.GetAutomaticColor() : m_cOldLinesColor.GetColor()), m_regOldLinesColor);
154 Store ((LPCTSTR)m_sFontName, m_regFontName);
155 Store (m_dwFontSize, m_regFontSize);
156 Store (m_dwTabSize, m_regTabSize);
157 Store (m_bFollowRenames, m_regFollowRenames);
159 SetModified(FALSE);
160 return ISettingsPropPage::OnApply();
163 void CSettingsTBlame::OnBnClickedColor()
165 SetModified();