Fixed issue #4126: Capitalize the first letter in the Push dialog
[TortoiseGit.git] / src / TortoiseProc / FirstStartWizardGit.cpp
blobb102c5a77580acc5c80f7d03d3a36aa08c46caff
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016-2020 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "FirstStartWizard.h"
22 #include "FirstStartWizardGit.h"
23 #include "Git.h"
24 #include "MessageBox.h"
25 #include "GitForWindows.h"
26 #include "../../TGitCache/CacheInterface.h"
27 #include "Theme.h"
29 IMPLEMENT_DYNAMIC(CFirstStartWizardGit, CFirstStartWizardBasePage)
31 #define CHECK_NEWGIT_TIMER 100
33 CFirstStartWizardGit::CFirstStartWizardGit() : CFirstStartWizardBasePage(CFirstStartWizardGit::IDD)
34 , m_dwMsysGitVersion(CRegDWORD(L"Software\\TortoiseGit\\git_cached_version", 0))
36 m_psp.dwFlags |= PSP_DEFAULT | PSP_USEHEADERTITLE;
37 m_psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_FIRSTSTART_GITTITLE);
39 g_Git.CheckMsysGitDir(TRUE);
40 m_regMsysGitPath = CRegString(REG_MSYSGIT_PATH);
42 m_regMsysGitExtranPath = CRegString(REG_MSYSGIT_EXTRA_PATH);
44 m_sMsysGitPath = m_regMsysGitPath;
45 m_sMsysGitExtranPath = m_regMsysGitExtranPath;
47 m_bEnableHacks = (CGit::ms_bCygwinGit || CGit::ms_bMsys2Git);
50 CFirstStartWizardGit::~CFirstStartWizardGit()
54 void CFirstStartWizardGit::DoDataExchange(CDataExchange* pDX)
56 CFirstStartWizardBasePage::DoDataExchange(pDX);
57 DDX_Text(pDX, IDC_MSYSGIT_PATH, m_sMsysGitPath);
58 DDX_Text(pDX, IDC_MSYSGIT_EXTERN_PATH, m_sMsysGitExtranPath);
59 DDX_Control(pDX, IDC_LINK, m_link);
60 DDX_Check(pDX, IDC_WORKAROUNDS, m_bEnableHacks);
63 BEGIN_MESSAGE_MAP(CFirstStartWizardGit, CFirstStartWizardBasePage)
64 ON_BN_CLICKED(IDC_MSYSGIT_BROWSE, OnBrowseDir)
65 ON_BN_CLICKED(IDC_MSYSGIT_CHECK, OnCheck)
66 ON_BN_CLICKED(IDC_WORKAROUNDS, OnClickedWorkarounds)
67 ON_WM_TIMER()
68 END_MESSAGE_MAP()
70 LRESULT CFirstStartWizardGit::OnWizardNext()
72 UpdateData();
74 PerformCommonGitPathCleanup(m_sMsysGitPath);
75 UpdateData(FALSE);
77 SetGitHacks();
79 bool needsRestart = false;
80 if (m_sMsysGitPath.Compare(CString(m_regMsysGitPath)) || m_sMsysGitExtranPath.Compare(CString(m_regMsysGitExtranPath)) || CGit::ms_bCygwinGit != (m_regCygwinHack == TRUE) || CGit::ms_bMsys2Git != (m_regMsys2Hack == TRUE))
82 StoreSetting(GetSafeHwnd(), m_sMsysGitPath, m_regMsysGitPath);
83 StoreSetting(GetSafeHwnd(), m_sMsysGitExtranPath, m_regMsysGitExtranPath);
84 StoreSetting(GetSafeHwnd(), CGit::ms_bCygwinGit, m_regCygwinHack);
85 StoreSetting(GetSafeHwnd(), CGit::ms_bMsys2Git, m_regMsys2Hack);
86 needsRestart = true;
89 // only complete if the msysgit directory is ok
90 bool needWorkarounds = (GetDlgItem(IDC_WORKAROUNDS)->IsWindowVisible() == TRUE);
91 if (!CheckGitExe(GetSafeHwnd(), m_sMsysGitPath, m_sMsysGitExtranPath, IDC_MSYSGIT_VER, [&](UINT helpid) { HtmlHelp(0x20000 + helpid); }, &needWorkarounds))
93 if (needWorkarounds)
94 ShowWorkarounds(true);
95 return -1;
98 if (needsRestart || g_Git.ms_LastMsysGitVersion != static_cast<int>(m_dwMsysGitVersion))
100 if (HWND hWnd = ::FindWindow(TGIT_CACHE_WINDOW_NAME, TGIT_CACHE_WINDOW_NAME); hWnd)
101 ::PostMessage(hWnd, WM_CLOSE, reinterpret_cast<WPARAM>(nullptr), reinterpret_cast<LPARAM>(nullptr));
103 CAppUtils::RunTortoiseGitProc(L"/command:firststart /page:3", false, false);
105 EndDialog(0);
107 return -1;
110 return __super::OnWizardNext();
113 void CFirstStartWizardGit::ShowWorkarounds(bool show)
115 if (!(CGit::ms_bCygwinGit || CGit::ms_bMsys2Git || show))
116 return;
118 GetDlgItem(IDC_WORKAROUNDS)->EnableWindow(TRUE);
119 GetDlgItem(IDC_WORKAROUNDS)->ShowWindow(SW_SHOW);
121 GetDlgItem(IDC_GITHACKS1)->EnableWindow(m_bEnableHacks);
122 GetDlgItem(IDC_GITHACKS1)->ShowWindow(m_bEnableHacks ? SW_SHOW : SW_HIDE);
123 GetDlgItem(IDC_GITHACKS2)->EnableWindow(m_bEnableHacks);
124 GetDlgItem(IDC_GITHACKS2)->ShowWindow(m_bEnableHacks ? SW_SHOW : SW_HIDE);
126 if (CGit::ms_bCygwinGit)
127 CheckRadioButton(IDC_GITHACKS1, IDC_GITHACKS2, IDC_GITHACKS1);
128 else if (CGit::ms_bMsys2Git)
129 CheckRadioButton(IDC_GITHACKS1, IDC_GITHACKS2, IDC_GITHACKS2);
132 BOOL CFirstStartWizardGit::OnInitDialog()
134 CFirstStartWizardBasePage::OnInitDialog();
136 SHAutoComplete(GetDlgItem(IDC_MSYSGIT_PATH)->m_hWnd, SHACF_FILESYSTEM);
138 m_tooltips.Create(this);
139 m_tooltips.AddTool(IDC_MSYSGIT_EXTERN_PATH, IDS_EXTRAPATH_TT);
141 GetDlgItem(IDC_LINK)->SetWindowText(GIT_FOR_WINDOWS_URL);
142 m_link.SetURL(GIT_FOR_WINDOWS_URL);
144 CTheme::Instance().SetThemeForDialog(GetSafeHwnd(), CTheme::Instance().IsDarkTheme());
146 AdjustControlSize(IDC_LINK, false);
147 AdjustControlSize(IDC_WORKAROUNDS);
148 AdjustControlSize(IDC_GITHACKS1);
149 AdjustControlSize(IDC_GITHACKS2);
151 CheckRadioButton(IDC_GITHACKS1, IDC_GITHACKS2, IDC_GITHACKS1);
152 ShowWorkarounds();
154 if (m_sMsysGitPath.IsEmpty())
155 SetTimer(CHECK_NEWGIT_TIMER, 1000, nullptr);
157 return TRUE;
160 void CFirstStartWizardGit::OnTimer(UINT_PTR nIDEvent)
162 if (nIDEvent == CHECK_NEWGIT_TIMER)
164 KillTimer(CHECK_NEWGIT_TIMER);
165 UpdateData();
166 if (m_sMsysGitPath.IsEmpty())
168 if (FindGitForWindows(m_sMsysGitPath))
170 UpdateData(FALSE);
171 return;
173 SetTimer(CHECK_NEWGIT_TIMER, 1000, nullptr);
175 return;
177 __super::OnTimer(nIDEvent);
180 BOOL CFirstStartWizardGit::OnSetActive()
182 auto wiz = static_cast<CFirstStartWizard*>(GetParent());
184 wiz->SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);
186 return CFirstStartWizardBasePage::OnSetActive();
189 void CFirstStartWizardGit::OnMsysGitPathModify()
191 UpdateData();
192 if (GuessExtraPath(m_sMsysGitPath, m_sMsysGitExtranPath))
193 UpdateData(FALSE);
196 void CFirstStartWizardGit::OnBrowseDir()
198 UpdateData(TRUE);
200 if (!SelectFolder(GetSafeHwnd(), m_sMsysGitPath, m_sMsysGitExtranPath))
201 return;
203 UpdateData(FALSE);
206 void CFirstStartWizardGit::SetGitHacks()
208 CGit::ms_bCygwinGit = false;
209 CGit::ms_bMsys2Git = false;
210 if (m_bEnableHacks)
212 int id = GetCheckedRadioButton(IDC_GITHACKS1, IDC_GITHACKS2);
213 CGit::ms_bCygwinGit = (id == IDC_GITHACKS1);
214 CGit::ms_bMsys2Git = (id == IDC_GITHACKS2);
218 void CFirstStartWizardGit::OnCheck()
220 UpdateData();
221 bool oldCygwinGit = CGit::ms_bCygwinGit;
222 bool oldMsys2Git = CGit::ms_bMsys2Git;
223 SCOPE_EXIT
225 CGit::ms_bCygwinGit = oldCygwinGit;
226 CGit::ms_bMsys2Git = oldMsys2Git;
229 SetGitHacks();
231 bool needWorkarounds = (GetDlgItem(IDC_WORKAROUNDS)->IsWindowVisible() == TRUE);
232 CheckGitExe(GetSafeHwnd(), m_sMsysGitPath, m_sMsysGitExtranPath, IDC_MSYSGIT_VER, [&](UINT helpid) { HtmlHelp(0x20000 + helpid); }, &needWorkarounds);
233 if (needWorkarounds)
234 ShowWorkarounds(true);
237 BOOL CFirstStartWizardGit::PreTranslateMessage(MSG* pMsg)
239 m_tooltips.RelayEvent(pMsg);
240 return __super::PreTranslateMessage(pMsg);
243 void CFirstStartWizardGit::OnClickedWorkarounds()
245 UpdateData();
246 ShowWorkarounds(true);