Call GatherData after we loaded the conditions we want to show
[TortoiseGit.git] / src / TortoiseProc / ChangedDlg.cpp
blob9ea251e9862b590efc06cdb588129eef52a57a61
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
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 "ChangedDlg.h"
23 #include "MessageBox.h"
24 #include "cursor.h"
25 #include "AppUtils.h"
26 #include "ChangedDlg.h"
27 #include "IconMenu.h"
28 #include "RefLogDlg.h"
30 IMPLEMENT_DYNAMIC(CChangedDlg, CResizableStandAloneDialog)
31 CChangedDlg::CChangedDlg(CWnd* pParent /*=nullptr*/)
32 : CResizableStandAloneDialog(CChangedDlg::IDD, pParent)
33 , m_bShowUnversioned(FALSE)
34 , m_iShowUnmodified(0)
35 , m_bBlock(FALSE)
36 , m_bCanceled(false)
37 , m_bShowIgnored(FALSE)
38 , m_bShowLocalChangesIgnored(FALSE)
39 , m_bWholeProject(FALSE)
40 , m_bRemote(FALSE)
44 CChangedDlg::~CChangedDlg()
48 void CChangedDlg::DoDataExchange(CDataExchange* pDX)
50 CResizableStandAloneDialog::DoDataExchange(pDX);
51 DDX_Control(pDX, IDC_CHANGEDLIST, m_FileListCtrl);
52 DDX_Control(pDX, IDC_BUTTON_STASH, m_ctrlStash);
53 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
54 DDX_Check(pDX, IDC_SHOWUNMODIFIED, m_iShowUnmodified);
55 DDX_Check(pDX, IDC_SHOWIGNORED, m_bShowIgnored);
56 DDX_Check(pDX, IDC_SHOWLOCALCHANGESIGNORED, m_bShowLocalChangesIgnored);
57 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
61 BEGIN_MESSAGE_MAP(CChangedDlg, CResizableStandAloneDialog)
62 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
63 ON_BN_CLICKED(IDC_SHOWUNMODIFIED, OnBnClickedShowUnmodified)
64 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnSVNStatusListCtrlNeedsRefresh)
65 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED, OnSVNStatusListCtrlItemCountChanged)
66 ON_BN_CLICKED(IDC_SHOWIGNORED, &CChangedDlg::OnBnClickedShowignored)
67 ON_BN_CLICKED(IDC_REFRESH, &CChangedDlg::OnBnClickedRefresh)
68 ON_BN_CLICKED(IDC_COMMIT, &CChangedDlg::OnBnClickedCommit)
69 ON_BN_CLICKED(IDC_BUTTON_STASH, &CChangedDlg::OnBnClickedStash)
70 ON_BN_CLICKED(IDC_BUTTON_UNIFIEDDIFF, &CChangedDlg::OnBnClickedButtonUnifieddiff)
71 ON_BN_CLICKED(IDC_SHOWLOCALCHANGESIGNORED, &CChangedDlg::OnBnClickedShowlocalchangesignored)
72 ON_BN_CLICKED(IDC_WHOLE_PROJECT, OnBnClickedWholeProject)
73 END_MESSAGE_MAP()
75 BOOL CChangedDlg::OnInitDialog()
77 CResizableStandAloneDialog::OnInitDialog();
79 m_regAddBeforeCommit = CRegDWORD(L"Software\\TortoiseGit\\AddBeforeCommit", TRUE);
80 m_bShowUnversioned = m_regAddBeforeCommit;
82 CString regPath(g_Git.m_CurrentDir);
83 regPath.Replace(L':', L'_');
84 m_regShowWholeProject = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\ShowWholeProject\\" + regPath, FALSE);
85 m_bWholeProject = m_regShowWholeProject;
86 SetDlgTitle();
88 UpdateData(FALSE);
90 m_FileListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD| GITSLC_COLDEL | GITSLC_COLMODIFICATIONDATE, L"ChangedDlg", (GITSLC_POPALL ^ (GITSLC_POPSAVEAS | GITSLC_POPRESTORE | GITSLC_PREPAREDIFF)), false);
91 m_FileListCtrl.SetCancelBool(&m_bCanceled);
92 m_FileListCtrl.SetBackgroundImage(IDI_CFM_BKG);
93 m_FileListCtrl.SetEmptyString(IDS_REPOSTATUS_EMPTYFILELIST);
95 AdjustControlSize(IDC_SHOWUNVERSIONED);
96 AdjustControlSize(IDC_SHOWUNMODIFIED);
97 AdjustControlSize(IDC_SHOWLOCALCHANGESIGNORED);
98 AdjustControlSize(IDC_SHOWIGNORED);
99 AdjustControlSize(IDC_WHOLE_PROJECT);
101 AddAnchor(IDC_CHANGEDLIST, TOP_LEFT, BOTTOM_RIGHT);
102 AddAnchor(IDC_SUMMARYTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
103 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
104 AddAnchor(IDC_SHOWUNMODIFIED, BOTTOM_LEFT);
105 AddAnchor(IDC_SHOWLOCALCHANGESIGNORED, BOTTOM_LEFT);
106 AddAnchor(IDC_SHOWIGNORED, BOTTOM_LEFT);
107 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
108 AddAnchor(IDC_INFOLABEL, BOTTOM_RIGHT);
109 AddAnchor(IDC_BUTTON_STASH, BOTTOM_RIGHT);
110 AddAnchor(IDC_BUTTON_UNIFIEDDIFF, BOTTOM_RIGHT);
111 AddAnchor(IDC_COMMIT, BOTTOM_RIGHT);
112 AddAnchor(IDC_REFRESH, BOTTOM_RIGHT);
113 AddAnchor(IDOK, BOTTOM_RIGHT);
114 // SetPromptParentWindow(m_hWnd);
115 if (hWndExplorer)
116 CenterWindow(CWnd::FromHandle(hWndExplorer));
117 EnableSaveRestore(L"ChangedDlg");
119 m_ctrlStash.m_bAlwaysShowArrow = true;
121 m_bRemote = !!(DWORD)CRegDWORD(L"Software\\TortoiseGit\\CheckRepo", FALSE);
123 // first start a thread to obtain the status without
124 // blocking the dialog
125 if (!AfxBeginThread(ChangedStatusThreadEntry, this))
127 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
130 return TRUE;
133 UINT CChangedDlg::ChangedStatusThreadEntry(LPVOID pVoid)
135 return reinterpret_cast<CChangedDlg*>(pVoid)->ChangedStatusThread();
138 UINT CChangedDlg::ChangedStatusThread()
140 InterlockedExchange(&m_bBlock, TRUE);
142 g_Git.RefreshGitIndex();
144 m_bCanceled = false;
145 SetDlgItemText(IDOK, CString(MAKEINTRESOURCE(IDS_MSGBOX_CANCEL)));
146 DialogEnableWindow(IDC_REFRESH, FALSE);
147 DialogEnableWindow(IDC_SHOWUNVERSIONED, FALSE);
148 DialogEnableWindow(IDC_SHOWUNMODIFIED, FALSE);
149 DialogEnableWindow(IDC_SHOWIGNORED, FALSE);
150 DialogEnableWindow(IDC_SHOWLOCALCHANGESIGNORED, FALSE);
151 m_FileListCtrl.StoreScrollPos();
152 m_FileListCtrl.Clear();
153 if (!m_FileListCtrl.GetStatus(m_bWholeProject ? nullptr : &m_pathList, m_bRemote, m_bShowIgnored != FALSE, m_bShowUnversioned != FALSE, m_bShowLocalChangesIgnored != FALSE))
155 if (!m_FileListCtrl.GetLastErrorMessage().IsEmpty())
156 m_FileListCtrl.SetEmptyString(m_FileListCtrl.GetLastErrorMessage());
158 unsigned int dwShow = GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS | GITSLC_SHOWSWITCHED | GITSLC_SHOWINCHANGELIST;
159 dwShow |= m_bShowUnversioned ? GITSLC_SHOWUNVERSIONED : 0;
160 dwShow |= m_iShowUnmodified ? GITSLC_SHOWNORMAL : 0;
161 dwShow |= m_bShowIgnored ? GITSLC_SHOWIGNORED : 0;
162 dwShow |= m_bShowLocalChangesIgnored ? GITSLC_SHOWASSUMEVALID | GITSLC_SHOWSKIPWORKTREE : 0;
163 m_FileListCtrl.Show(dwShow);
164 UpdateStatistics();
166 SetDlgTitle();
167 bool bIsDirectory = false;
168 if (m_pathList.GetCount() == 1)
169 bIsDirectory = m_pathList[0].IsDirectory() || m_pathList[0].IsEmpty(); // if it is empty it is g_Git.m_CurrentDir which is a directory
171 SetDlgItemText(IDOK, CString(MAKEINTRESOURCE(IDS_MSGBOX_OK)));
172 DialogEnableWindow(IDC_REFRESH, TRUE);
173 DialogEnableWindow(IDC_SHOWUNVERSIONED, bIsDirectory);
174 //DialogEnableWindow(IDC_SHOWUNMODIFIED, bIsDirectory);
175 DialogEnableWindow(IDC_SHOWIGNORED, bIsDirectory);
176 DialogEnableWindow(IDC_SHOWLOCALCHANGESIGNORED, TRUE);
177 InterlockedExchange(&m_bBlock, FALSE);
178 // revert the remote flag back to the default
179 m_bRemote = !!(DWORD)CRegDWORD(L"Software\\TortoiseGit\\CheckRepo", FALSE);
180 RefreshCursor();
181 return 0;
184 void CChangedDlg::OnOK()
186 if (m_bBlock)
188 m_bCanceled = true;
189 return;
191 __super::OnOK();
194 void CChangedDlg::OnCancel()
196 if (m_bBlock)
198 m_bCanceled = true;
199 return;
201 __super::OnCancel();
204 DWORD CChangedDlg::UpdateShowFlags()
206 DWORD dwShow = m_FileListCtrl.GetShowFlags();
207 if (m_bShowUnversioned)
208 dwShow |= GITSLC_SHOWUNVERSIONED;
209 else
210 dwShow &= ~GITSLC_SHOWUNVERSIONED;
211 if (m_iShowUnmodified)
212 dwShow |= GITSLC_SHOWNORMAL;
213 else
214 dwShow &= ~GITSLC_SHOWNORMAL;
215 if (m_bShowIgnored)
216 dwShow |= GITSLC_SHOWIGNORED;
217 else
218 dwShow &= ~GITSLC_SHOWIGNORED;
219 if (m_bShowLocalChangesIgnored)
220 dwShow |= GITSLC_SHOWASSUMEVALID|GITSLC_SHOWSKIPWORKTREE;
221 else
222 dwShow &= ~(GITSLC_SHOWASSUMEVALID|GITSLC_SHOWSKIPWORKTREE);
224 // old bShowExternals:
225 dwShow &= ~(GITSLC_SHOWEXTERNAL | GITSLC_SHOWINEXTERNALS | GITSLC_SHOWEXTERNALFROMDIFFERENTREPO);
227 return dwShow;
230 void CChangedDlg::SetDlgTitle()
232 if (m_sTitle.IsEmpty())
233 GetWindowText(m_sTitle);
235 if (m_bWholeProject)
236 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
237 else
239 if (m_pathList.GetCount() == 1)
240 CAppUtils::SetWindowTitle(m_hWnd, g_Git.CombinePath(m_pathList[0].GetUIPathString()), m_sTitle);
241 else
242 CAppUtils::SetWindowTitle(m_hWnd, g_Git.CombinePath(m_FileListCtrl.GetCommonDirectory(false)), m_sTitle);
246 void CChangedDlg::OnBnClickedShowunversioned()
248 UpdateData();
249 m_regAddBeforeCommit = m_bShowUnversioned;
250 if(m_FileListCtrl.m_FileLoaded & CGitStatusListCtrl::FILELIST_UNVER)
252 m_FileListCtrl.StoreScrollPos();
253 m_FileListCtrl.Show(UpdateShowFlags());
255 else
257 if(m_bShowUnversioned)
259 if (!AfxBeginThread(ChangedStatusThreadEntry, this))
260 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
263 UpdateStatistics();
266 void CChangedDlg::OnBnClickedShowUnmodified()
268 UpdateData();
269 m_FileListCtrl.StoreScrollPos();
270 m_FileListCtrl.Show(UpdateShowFlags());
271 m_regAddBeforeCommit = m_bShowUnversioned;
272 UpdateStatistics();
275 void CChangedDlg::OnBnClickedShowignored()
277 UpdateData();
278 m_FileListCtrl.StoreScrollPos();
279 if (m_FileListCtrl.m_FileLoaded & CGitStatusListCtrl::FILELIST_IGNORE)
280 m_FileListCtrl.Show(UpdateShowFlags());
281 else if (m_bShowIgnored)
283 if (!AfxBeginThread(ChangedStatusThreadEntry, this))
284 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
286 UpdateStatistics();
289 void CChangedDlg::OnBnClickedShowlocalchangesignored()
291 UpdateData();
292 m_FileListCtrl.StoreScrollPos();
293 if (m_FileListCtrl.m_FileLoaded & CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED)
294 m_FileListCtrl.Show(UpdateShowFlags());
295 else if (m_bShowLocalChangesIgnored)
297 if (!AfxBeginThread(ChangedStatusThreadEntry, this))
298 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
300 UpdateStatistics();
303 LRESULT CChangedDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
305 if (!AfxBeginThread(ChangedStatusThreadEntry, this))
306 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
307 return 0;
310 LRESULT CChangedDlg::OnSVNStatusListCtrlItemCountChanged(WPARAM, LPARAM)
312 UpdateStatistics();
313 return 0;
316 BOOL CChangedDlg::PreTranslateMessage(MSG* pMsg)
318 if (pMsg->message == WM_KEYDOWN)
320 switch (pMsg->wParam)
322 case VK_F5:
324 if (m_bBlock)
325 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
326 if (!AfxBeginThread(ChangedStatusThreadEntry, this))
328 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
331 break;
335 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
338 void CChangedDlg::OnBnClickedRefresh()
340 if (!m_bBlock)
342 if (!AfxBeginThread(ChangedStatusThreadEntry, this))
343 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
347 void CChangedDlg::UpdateStatistics()
349 CString temp;
350 #if 0
351 LONG lMin, lMax;
353 m_FileListCtrl.GetMinMaxRevisions(lMin, lMax, true, false);
354 if (LONG(m_FileListCtrl.m_HeadRev) >= 0)
356 temp.Format(IDS_REPOSTATUS_HEADREV, lMin, lMax, LONG(m_FileListCtrl.m_HeadRev));
357 SetDlgItemText(IDC_SUMMARYTEXT, temp);
359 else
361 temp.Format(IDS_REPOSTATUS_WCINFO, lMin, lMax);
362 SetDlgItemText(IDC_SUMMARYTEXT, temp);
364 #endif
365 temp = m_FileListCtrl.GetStatisticsString();
366 temp.Replace(L" = ", L"=");
367 temp.Replace(L"\n", L", ");
368 SetDlgItemText(IDC_INFOLABEL, temp);
371 void CChangedDlg::OnBnClickedCommit()
373 CTGitPathList pathList;
374 bool bSingleFile = ((m_pathList.GetCount()==1)&&(!m_pathList[0].IsEmpty())&&(!m_pathList[0].IsDirectory()));
375 if (bSingleFile)
376 pathList.AddPath(m_pathList[0]);
377 else
378 pathList.AddPath(m_pathList.GetCommonRoot().GetDirectory());
380 bool bSelectFilesForCommit = !!DWORD(CRegStdDWORD(L"Software\\TortoiseGit\\SelectFilesForCommit", TRUE));
382 CString logmsg;
383 CTGitPathList selected;
384 CAppUtils::Commit(L"",
385 m_bWholeProject,
386 logmsg,
387 pathList,
388 selected,
389 bSelectFilesForCommit);
391 OnBnClickedRefresh();
394 void CChangedDlg::OnBnClickedStash()
396 CIconMenu popup;
398 if (popup.CreatePopupMenu())
400 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
402 CTGitPath root = g_Git.m_CurrentDir;
403 if (root.HasStashDir())
405 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
406 popup.AppendMenuIcon(ID_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
407 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
410 RECT rect;
411 GetDlgItem(IDC_BUTTON_STASH)->GetWindowRect(&rect);
412 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, rect.left, rect.top, this);
414 switch (cmd & 0xFFFF)
416 case ID_STASH_SAVE:
417 CAppUtils::StashSave();
418 break;
419 case ID_STASH_POP:
420 CAppUtils::StashPop(2);
421 break;
422 case ID_STASH_APPLY:
423 CAppUtils::StashApply(L"", false);
424 break;
425 case ID_STASH_LIST:
427 CRefLogDlg dlg;
428 dlg.m_CurrentBranch = L"refs/stash";
429 dlg.DoModal();
431 break;
432 default:
433 return;
435 OnBnClickedRefresh();
439 void CChangedDlg::OnBnClickedButtonUnifieddiff()
441 CTGitPath commonDirectory;
442 if (!m_bWholeProject)
443 commonDirectory = m_pathList.GetCommonRoot().GetDirectory();
444 bool bSingleFile = ((m_pathList.GetCount()==1)&&(!m_pathList[0].IsEmpty())&&(!m_pathList[0].IsDirectory()));
445 if (bSingleFile)
446 commonDirectory = m_pathList[0];
447 CString sCmd;
448 sCmd.Format(L"/command:showcompare /unified /path:\"%s\" /revision1:HEAD /revision2:%s", (LPCTSTR)g_Git.CombinePath(commonDirectory), (LPCTSTR)GitRev::GetWorkingCopy());
449 if (!!(GetAsyncKeyState(VK_SHIFT) & 0x8000))
450 sCmd += L" /alternative";
451 CAppUtils::RunTortoiseGitProc(sCmd);
454 void CChangedDlg::OnBnClickedWholeProject()
456 UpdateData();
457 m_regShowWholeProject = m_bWholeProject;
458 OnBnClickedRefresh();