Fixed issue #1620: Apply Patch serial can't open file dialog on WinXP
[TortoiseGit.git] / src / Git / GitStatusListCtrl.cpp
blob98e18688b1850cae39764a5ecee19e4c91b7411e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
5 // Copyright (C) 2010-2012 Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "stdafx.h"
23 #include "resource.h"
24 #include "..\\TortoiseShell\resource.h"
25 #include "GitStatusListCtrl.h"
26 #include "MessageBox.h"
27 #include "MyMemDC.h"
28 #include "UnicodeUtils.h"
29 #include "AppUtils.h"
30 #include "PathUtils.h"
31 #include "TempFile.h"
32 #include "StringUtils.h"
33 #include "DirFileEnum.h"
34 #include "GitConfig.h"
35 #include "LoglistUtils.h"
36 //#include "SVNProperties.h"
37 #include "Git.h"
38 #include "GitDiff.h"
39 //#include "LogDlg.h"
40 #include "GitProgressDlg.h"
41 #include "SysImageList.h"
42 //#include "Svnstatuslistctrl.h"
43 #include "TGitPath.h"
44 #include "registry.h"
45 #include "GitStatus.h"
46 //#include "SVNHelpers.h"
47 #include "InputDlg.h"
48 #include "ShellUpdater.h"
49 #include "GitAdminDir.h"
50 //#include "DropFiles.h"
51 #include "IconMenu.h"
52 //#include "AddDlg.h"
53 //#include "EditPropertiesDlg.h"
54 //#include "CreateChangelistDlg.h"
55 #include "FormatMessageWrapper.h"
56 #include "BrowseFolder.h"
58 const UINT CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
59 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
60 const UINT CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
61 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
62 const UINT CGitStatusListCtrl::GITSLNM_ADDFILE
63 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
64 const UINT CGitStatusListCtrl::GITSLNM_CHECKCHANGED
65 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
66 const UINT CGitStatusListCtrl::GITSLNM_ITEMCHANGED
67 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCHANGED"));
72 BEGIN_MESSAGE_MAP(CGitStatusListCtrl, CListCtrl)
73 ON_NOTIFY(HDN_ITEMCLICKA, 0, OnHdnItemclick)
74 ON_NOTIFY(HDN_ITEMCLICKW, 0, OnHdnItemclick)
75 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
76 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
77 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, OnLvnItemchanged)
78 ON_WM_CONTEXTMENU()
79 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk)
80 ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnLvnGetInfoTip)
81 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
82 ON_WM_SETCURSOR()
83 ON_WM_GETDLGCODE()
84 ON_NOTIFY_REFLECT(NM_RETURN, OnNMReturn)
85 ON_WM_KEYDOWN()
86 ON_WM_PAINT()
87 ON_NOTIFY(HDN_BEGINTRACKA, 0, &CGitStatusListCtrl::OnHdnBegintrack)
88 ON_NOTIFY(HDN_BEGINTRACKW, 0, &CGitStatusListCtrl::OnHdnBegintrack)
89 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, &CGitStatusListCtrl::OnHdnItemchanging)
90 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, &CGitStatusListCtrl::OnHdnItemchanging)
91 ON_WM_DESTROY()
92 ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBeginDrag)
93 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING, &CGitStatusListCtrl::OnLvnItemchanging)
94 END_MESSAGE_MAP()
98 CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl()
99 //, m_HeadRev(GitRev::REV_HEAD)
100 , m_pbCanceled(NULL)
101 , m_pStatLabel(NULL)
102 , m_pSelectButton(NULL)
103 , m_pConfirmButton(NULL)
104 , m_bBusy(false)
105 , m_bEmpty(false)
106 , m_bShowIgnores(false)
107 , m_pDropTarget(NULL)
108 , m_bIgnoreRemoveOnly(false)
109 , m_bCheckChildrenWithParent(false)
110 , m_bUnversionedLast(true)
111 , m_bHasChangeLists(false)
112 , m_bHasLocks(false)
113 , m_bBlock(false)
114 , m_bBlockUI(false)
115 , m_bHasCheckboxes(false)
116 , m_bCheckIfGroupsExist(true)
117 , m_bFileDropsEnabled(false)
118 , m_bOwnDrag(false)
119 , m_dwDefaultColumns(0)
120 , m_ColumnManager(this)
121 , m_bAscending(false)
122 , m_nSortedColumn(-1)
123 , m_bHasExternalsFromDifferentRepos(false)
124 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE))
125 , m_amend(false)
126 , m_bDoNotAutoselectSubmodules(false)
127 , m_bHasWC(true)
128 , m_hwndLogicalParent(NULL)
129 , m_bHasUnversionedItems(FALSE)
131 m_FileLoaded=0;
132 m_dwDefaultColumns = 0;
133 m_critSec.Init();
134 m_bIsRevertTheirMy = false;
135 this->m_nLineAdded =this->m_nLineDeleted =0;
138 CGitStatusListCtrl::~CGitStatusListCtrl()
140 // if (m_pDropTarget)
141 // delete m_pDropTarget;
142 ClearStatusArray();
145 void CGitStatusListCtrl::ClearStatusArray()
147 #if 0
148 Locker lock(m_critSec);
149 for (size_t i=0; i < m_arStatusArray.size(); i++)
151 delete m_arStatusArray[i];
153 m_arStatusArray.clear();
154 #endif
157 void CGitStatusListCtrl::Init(DWORD dwColumns, const CString& sColumnInfoContainer, unsigned __int64 dwContextMenus /* = GitSLC_POPALL */, bool bHasCheckboxes /* = true */, bool bHasWC /* = true */, DWORD allowedColumns /* = 0xffffffff */)
159 Locker lock(m_critSec);
161 m_dwDefaultColumns = dwColumns | 1;
162 m_dwContextMenus = dwContextMenus;
163 m_bHasCheckboxes = bHasCheckboxes;
164 m_bHasWC = bHasWC;
166 // set the extended style of the listcontrol
167 // the style LVS_EX_FULLROWSELECT interferes with the background watermark image but it's more important to be able to select in the whole row.
168 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
169 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
170 if (DWORD(regFullRowSelect))
171 exStyle |= LVS_EX_FULLROWSELECT;
172 exStyle |= (bHasCheckboxes ? LVS_EX_CHECKBOXES : 0);
173 SetRedraw(false);
174 SetExtendedStyle(exStyle);
176 SetWindowTheme(m_hWnd, L"Explorer", NULL);
178 m_nIconFolder = SYS_IMAGE_LIST().GetDirIconIndex();
179 m_nRestoreOvl = SYS_IMAGE_LIST().AddIcon((HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_RESTOREOVL), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));
180 SYS_IMAGE_LIST().SetOverlayImage(m_nRestoreOvl, OVL_RESTORE);
181 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL);
183 // keep CSorter::operator() in sync!!
184 static UINT standardColumnNames[GITSLC_NUMCOLUMNS]
185 = { IDS_STATUSLIST_COLFILE
186 , IDS_STATUSLIST_COLFILENAME
187 , IDS_STATUSLIST_COLEXT
188 , IDS_STATUSLIST_COLSTATUS
189 , IDS_STATUSLIST_COLADD
190 , IDS_STATUSLIST_COLDEL
191 , IDS_STATUSLIST_COLLASTMODIFIED
192 , IDS_STATUSLIST_COLSIZE
195 m_ColumnManager.SetNames(standardColumnNames,GITSLC_NUMCOLUMNS);
196 m_ColumnManager.ReadSettings(m_dwDefaultColumns, 0xffffffff & ~(allowedColumns | m_dwDefaultColumns), sColumnInfoContainer, GITSLC_NUMCOLUMNS);
198 // enable file drops
199 #if 0
200 if (m_pDropTarget == NULL)
202 m_pDropTarget = new CGitStatusListCtrlDropTarget(this);
203 RegisterDragDrop(m_hWnd,m_pDropTarget);
204 // create the supported formats:
205 FORMATETC ftetc={0};
206 ftetc.dwAspect = DVASPECT_CONTENT;
207 ftetc.lindex = -1;
208 ftetc.tymed = TYMED_HGLOBAL;
209 ftetc.cfFormat=CF_HDROP;
210 m_pDropTarget->AddSuportedFormat(ftetc);
212 #endif
214 SetRedraw(true);
217 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID)
219 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID);
222 BOOL CGitStatusListCtrl::GetStatus ( const CTGitPathList* pathList
223 , bool bUpdate /* = FALSE */
224 , bool bShowIgnores /* = false */
225 , bool bShowUnRev)
227 Locker lock(m_critSec);
228 int mask= CGitStatusListCtrl::FILELIST_MODIFY;
229 if(bShowIgnores)
230 mask|= CGitStatusListCtrl::FILELIST_IGNORE;
231 if(bShowUnRev)
232 mask|= CGitStatusListCtrl::FILELIST_UNVER;
233 this->UpdateFileList(mask,bUpdate,(CTGitPathList*)pathList);
236 #if 0
237 int refetchcounter = 0;
238 BOOL bRet = TRUE;
239 Invalidate();
240 // force the cursor to change
241 POINT pt;
242 GetCursorPos(&pt);
243 SetCursorPos(pt.x, pt.y);
245 m_mapFilenameToChecked.clear();
246 //m_StatusUrlList.Clear();
247 bool bHasChangelists = (m_changelists.size() > 1 || (!m_changelists.empty() && !m_bHasIgnoreGroup));
248 m_changelists.clear();
249 for (size_t i=0; i < m_arStatusArray.size(); i++)
251 FileEntry * entry = m_arStatusArray[i];
252 if ( bHasChangelists && entry->checked)
254 // If change lists are present, remember all checked entries
255 CString path = entry->GetPath().GetGitPathString();
256 m_mapFilenameToChecked[path] = true;
258 if ( (entry->status==git_wc_status_unversioned || entry->status==git_wc_status_missing ) && entry->checked )
260 // The user manually selected an unversioned or missing file. We remember
261 // this so that the selection can be restored when refreshing.
262 CString path = entry->GetPath().GetGitPathString();
263 m_mapFilenameToChecked[path] = true;
265 else if ( entry->status > git_wc_status_normal && !entry->checked )
267 // The user manually deselected a versioned file. We remember
268 // this so that the deselection can be restored when refreshing.
269 CString path = entry->GetPath().GetGitPathString();
270 m_mapFilenameToChecked[path] = false;
274 // use a sorted path list to make sure we fetch the status of
275 // parent items first, *then* the child items (if any)
276 CTGitPathList sortedPathList = pathList;
277 sortedPathList.SortByPathname();
280 bRet = TRUE;
281 m_nTargetCount = 0;
282 m_bHasExternalsFromDifferentRepos = FALSE;
283 m_bHasExternals = FALSE;
284 m_bHasUnversionedItems = FALSE;
285 m_bHasLocks = false;
286 m_bHasChangeLists = false;
287 m_bShowIgnores = bShowIgnores;
288 m_nSortedColumn = 0;
289 m_bBlock = TRUE;
290 m_bBusy = true;
291 m_bEmpty = false;
292 Invalidate();
294 // first clear possible status data left from
295 // previous GetStatus() calls
296 ClearStatusArray();
298 m_StatusFileList = sortedPathList;
300 // Since Git_client_status() returns all files, even those in
301 // folders included with Git:externals we need to check if all
302 // files we get here belongs to the same repository.
303 // It is possible to commit changes in an external folder, as long
304 // as the folder belongs to the same repository (but another path),
305 // but it is not possible to commit all files if the externals are
306 // from a different repository.
308 // To check if all files belong to the same repository, we compare the
309 // UUID's - if they're identical then the files belong to the same
310 // repository and can be committed. But if they're different, then
311 // tell the user to commit all changes in the external folders
312 // first and exit.
313 CStringA sUUID; // holds the repo UUID
314 CTGitPathList arExtPaths; // list of Git:external paths
316 GitConfig config;
318 m_sURL.Empty();
320 m_nTargetCount = sortedPathList.GetCount();
322 GitStatus status(m_pbCanceled);
323 if(m_nTargetCount > 1 && sortedPathList.AreAllPathsFilesInOneDirectory())
325 // This is a special case, where we've been given a list of files
326 // all from one folder
327 // We handle them by setting a status filter, then requesting the Git status of
328 // all the files in the directory, filtering for the ones we're interested in
329 status.SetFilter(sortedPathList);
331 // if all selected entries are files, we don't do a recursive status
332 // fetching. But if only one is a directory, we have to recurse.
333 git_depth_t depth = git_depth_files;
334 // We have set a filter. If all selected items were files or we fetch
335 // the status not recursively, then we have to include
336 // ignored items too - the user has selected them
337 bool bShowIgnoresRight = true;
338 for (int fcindex=0; fcindex<sortedPathList.GetCount(); ++fcindex)
340 if (sortedPathList[fcindex].IsDirectory())
342 depth = git_depth_infinity;
343 bShowIgnoresRight = false;
344 break;
347 if(!FetchStatusForSingleTarget(config, status, sortedPathList.GetCommonDirectory(), bUpdate, sUUID, arExtPaths, true, depth, bShowIgnoresRight))
349 bRet = FALSE;
352 else
354 for(int nTarget = 0; nTarget < m_nTargetCount; nTarget++)
356 // check whether the path we want the status for is already fetched due to status-fetching
357 // of a parent path.
358 // this check is only done for file paths, because folder paths could be included already
359 // but not recursively
360 if (sortedPathList[nTarget].IsDirectory() || GetListEntry(sortedPathList[nTarget]) == NULL)
362 if(!FetchStatusForSingleTarget(config, status, sortedPathList[nTarget], bUpdate, sUUID,
363 arExtPaths, false, git_depth_infinity, bShowIgnores))
365 bRet = FALSE;
371 // remove the 'helper' files of conflicted items from the list.
372 // otherwise they would appear as unversioned files.
373 for (INT_PTR cind = 0; cind < m_ConflictFileList.GetCount(); ++cind)
375 for (size_t i=0; i < m_arStatusArray.size(); i++)
377 if (m_arStatusArray[i]->GetPath().IsEquivalentTo(m_ConflictFileList[cind]))
379 delete m_arStatusArray[i];
380 m_arStatusArray.erase(m_arStatusArray.begin()+i);
381 break;
385 refetchcounter++;
386 } while(!BuildStatistics() && (refetchcounter < 2) && (*m_pbCanceled==false));
388 m_bBlock = FALSE;
389 m_bBusy = false;
390 GetCursorPos(&pt);
391 SetCursorPos(pt.x, pt.y);
392 return bRet;
393 #endif
394 BuildStatistics();
395 return TRUE;
398 // Get the show-flags bitmap value which corresponds to a particular Git status
399 DWORD CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status)
401 switch (status)
403 case git_wc_status_none:
404 case git_wc_status_unversioned:
405 return GITSLC_SHOWUNVERSIONED;
406 case git_wc_status_ignored:
407 if (!m_bShowIgnores)
408 return GITSLC_SHOWDIRECTS;
409 return GITSLC_SHOWDIRECTS|GITSLC_SHOWIGNORED;
410 case git_wc_status_incomplete:
411 return GITSLC_SHOWINCOMPLETE;
412 case git_wc_status_normal:
413 return GITSLC_SHOWNORMAL;
414 case git_wc_status_external:
415 return GITSLC_SHOWEXTERNAL;
416 case git_wc_status_added:
417 return GITSLC_SHOWADDED;
418 case git_wc_status_missing:
419 return GITSLC_SHOWMISSING;
420 case git_wc_status_deleted:
421 return GITSLC_SHOWREMOVED;
422 case git_wc_status_replaced:
423 return GITSLC_SHOWREPLACED;
424 case git_wc_status_modified:
425 return GITSLC_SHOWMODIFIED;
426 case git_wc_status_merged:
427 return GITSLC_SHOWMERGED;
428 case git_wc_status_conflicted:
429 return GITSLC_SHOWCONFLICTED;
430 case git_wc_status_obstructed:
431 return GITSLC_SHOWOBSTRUCTED;
432 default:
433 // we should NEVER get here!
434 ASSERT(FALSE);
435 break;
437 return 0;
440 void CGitStatusListCtrl::Show(unsigned int dwShow, unsigned int dwCheck /*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList,bool UseStoredCheckStatus)
442 CWinApp * pApp = AfxGetApp();
443 if (pApp)
444 pApp->DoWaitCursor(1);
446 Locker lock(m_critSec);
447 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
449 //SetItemCount(listIndex);
450 SetRedraw(FALSE);
451 DeleteAllItems();
452 m_nSelected = 0;
454 m_nShownUnversioned = 0;
455 m_nShownModified = 0;
456 m_nShownAdded = 0;
457 m_nShownDeleted = 0;
458 m_nShownConflicted = 0;
459 m_nShownFiles = 0;
460 m_nShownSubmodules = 0;
462 if(UpdateStatusList)
464 m_arStatusArray.clear();
465 for(int i=0;i<this->m_StatusFileList.GetCount();i++)
467 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
470 for(int i=0;i<this->m_UnRevFileList.GetCount();i++)
472 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
475 for(int i=0;i<this->m_IgnoreFileList.GetCount();i++)
477 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
480 PrepareGroups();
481 if (m_nSortedColumn >= 0)
483 CSorter predicate (&m_ColumnManager, m_nSortedColumn, m_bAscending);
484 std::sort(m_arStatusArray.begin(), m_arStatusArray.end(), predicate);
487 int index =0;
488 for(int i=0;i<this->m_arStatusArray.size();i++)
490 //set default checkbox status
491 CTGitPath* entry = ((CTGitPath*)m_arStatusArray[i]);
492 CString path = entry->GetGitPathString();
493 if (!m_mapFilenameToChecked.empty() && m_mapFilenameToChecked.find(path) != m_mapFilenameToChecked.end())
495 entry->m_Checked=m_mapFilenameToChecked[path];
497 else if (!UseStoredCheckStatus)
499 bool autoSelectSubmodules = !(entry->IsDirectory() && m_bDoNotAutoselectSubmodules);
500 if(entry->m_Action & dwCheck && autoSelectSubmodules)
501 entry->m_Checked=true;
502 else
503 entry->m_Checked=false;
504 m_mapFilenameToChecked[path] = entry->m_Checked;
507 if(entry->m_Action & dwShow)
509 AddEntry(entry,langID,index);
510 index++;
514 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
515 for (int col = 0; col <= maxcol; col++)
516 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
518 SetRedraw(TRUE);
519 GetStatisticsString();
521 CHeaderCtrl * pHeader = GetHeaderCtrl();
522 HDITEM HeaderItem = {0};
523 HeaderItem.mask = HDI_FORMAT;
524 for (int i=0; i<pHeader->GetItemCount(); ++i)
526 pHeader->GetItem(i, &HeaderItem);
527 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
528 pHeader->SetItem(i, &HeaderItem);
530 if (m_nSortedColumn >= 0)
532 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
533 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
534 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
537 #if 0
538 if (nSelectedEntry)
540 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
541 EnsureVisible(nSelectedEntry, false);
543 else
545 // Restore the item at the top of the list.
546 for (int i=0;GetTopIndex() != nTopIndex;i++)
548 if ( !EnsureVisible(nTopIndex+i,false) )
550 break;
554 #endif
555 if (pApp)
556 pApp->DoWaitCursor(-1);
558 Invalidate();
560 m_dwShow = dwShow;
562 this->BuildStatistics();
564 #if 0
566 CWinApp * pApp = AfxGetApp();
567 if (pApp)
568 pApp->DoWaitCursor(1);
570 m_bShowFolders = bShowFolders;
572 int nTopIndex = GetTopIndex();
573 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
574 int nSelectedEntry = 0;
575 if (posSelectedEntry)
576 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
577 SetRedraw(FALSE);
578 DeleteAllItems();
580 PrepareGroups();
582 m_arListArray.clear();
584 m_arListArray.reserve(m_arStatusArray.size());
585 SetItemCount (static_cast<int>(m_arStatusArray.size()));
587 int listIndex = 0;
588 for (size_t i=0; i < m_arStatusArray.size(); ++i)
590 FileEntry * entry = m_arStatusArray[i];
591 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
592 continue;
593 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
594 continue;
595 if (entry->IsFolder() && (!bShowFolders))
596 continue; // don't show folders if they're not wanted.
598 #if 0
599 git_wc_status_kind status = GitStatus::GetMoreImportant(entry->status, entry->remotestatus);
600 DWORD showFlags = GetShowFlagsFromGitStatus(status);
601 if (entry->IsLocked())
602 showFlags |= SVNSLC_SHOWLOCKS;
603 if (entry->switched)
604 showFlags |= SVNSLC_SHOWSWITCHED;
605 if (!entry->changelist.IsEmpty())
606 showFlags |= SVNSLC_SHOWINCHANGELIST;
607 #endif
608 bool bAllowCheck = ((entry->changelist.Compare(GITSLC_IGNORECHANGELIST) != 0)
609 && (m_bCheckIfGroupsExist || (m_changelists.empty() || (m_changelists.size() == 1 && m_bHasIgnoreGroup))));
611 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
612 #if 0
613 if (status != Git_wc_status_ignored || (entry->direct) || (dwShow & GitSLC_SHOWIGNORED))
615 if ((!entry->IsFolder()) && (status == Git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
617 if (PathFileExists(entry->GetPath().GetWinPath()))
619 m_arListArray.push_back(i);
620 if ((dwCheck & SVNSLC_SHOWREMOVEDANDPRESENT)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
622 if (bAllowCheck)
623 entry->checked = true;
625 AddEntry(entry, langID, listIndex++);
628 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
630 m_arListArray.push_back(i);
631 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
633 if (bAllowCheck)
634 entry->checked = true;
636 AddEntry(entry, langID, listIndex++);
638 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
640 m_arListArray.push_back(i);
641 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
643 if (bAllowCheck)
644 entry->checked = true;
646 AddEntry(entry, langID, listIndex++);
649 #endif
652 SetItemCount(listIndex);
654 m_ColumnManager.UpdateRelevance (m_arStatusArray, m_arListArray);
656 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
657 for (int col = 0; col <= maxcol; col++)
658 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
660 SetRedraw(TRUE);
661 GetStatisticsString();
663 CHeaderCtrl * pHeader = GetHeaderCtrl();
664 HDITEM HeaderItem = {0};
665 HeaderItem.mask = HDI_FORMAT;
666 for (int i=0; i<pHeader->GetItemCount(); ++i)
668 pHeader->GetItem(i, &HeaderItem);
669 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
670 pHeader->SetItem(i, &HeaderItem);
672 if (m_nSortedColumn)
674 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
675 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
676 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
679 if (nSelectedEntry)
681 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
682 EnsureVisible(nSelectedEntry, false);
684 else
686 // Restore the item at the top of the list.
687 for (int i=0;GetTopIndex() != nTopIndex;i++)
689 if ( !EnsureVisible(nTopIndex+i,false) )
691 break;
696 if (pApp)
697 pApp->DoWaitCursor(-1);
699 m_bEmpty = (GetItemCount() == 0);
700 Invalidate();
701 #endif
705 void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList& checkedList, bool /*bShowFolders*/ /* = true */)
707 DeleteAllItems();
708 for(int i=0;i<checkedList.GetCount();i++)
709 this->AddEntry((CTGitPath *)&checkedList[i],0,i);
710 return ;
711 #if 0
713 Locker lock(m_critSec);
714 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
716 CWinApp * pApp = AfxGetApp();
717 if (pApp)
718 pApp->DoWaitCursor(1);
719 m_dwShow = dwShow;
720 m_bShowFolders = bShowFolders;
721 m_nSelected = 0;
722 int nTopIndex = GetTopIndex();
723 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
724 int nSelectedEntry = 0;
725 if (posSelectedEntry)
726 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
727 SetRedraw(FALSE);
728 DeleteAllItems();
730 PrepareGroups();
732 m_arListArray.clear();
734 m_arListArray.reserve(m_arStatusArray.size());
735 SetItemCount (static_cast<int>(m_arStatusArray.size()));
737 int listIndex = 0;
738 for (size_t i=0; i < m_arStatusArray.size(); ++i)
740 FileEntry * entry = m_arStatusArray[i];
741 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
742 continue;
743 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
744 continue;
745 if (entry->IsFolder() && (!bShowFolders))
746 continue; // don't show folders if they're not wanted.
747 #if 0
748 git_wc_status_kind status = SVNStatus::GetMoreImportant(entry->status, entry->remotestatus);
749 DWORD showFlags = GetShowFlagsFromSVNStatus(status);
750 if (entry->IsLocked())
751 showFlags |= SVNSLC_SHOWLOCKS;
752 if (!entry->changelist.IsEmpty())
753 showFlags |= SVNSLC_SHOWINCHANGELIST;
755 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
756 if (status != git_wc_status_ignored || (entry->direct) || (dwShow & SVNSLC_SHOWIGNORED))
758 for (int npath = 0; npath < checkedList.GetCount(); ++npath)
760 if (entry->GetPath().IsEquivalentTo(checkedList[npath]))
762 entry->checked = true;
763 break;
766 if ((!entry->IsFolder()) && (status == git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
768 if (PathFileExists(entry->GetPath().GetWinPath()))
770 m_arListArray.push_back(i);
771 AddEntry(entry, langID, listIndex++);
774 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
776 m_arListArray.push_back(i);
777 AddEntry(entry, langID, listIndex++);
779 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
781 m_arListArray.push_back(i);
782 AddEntry(entry, langID, listIndex++);
784 else if (entry->switched)
786 m_arListArray.push_back(i);
787 AddEntry(entry, langID, listIndex++);
790 #endif
793 SetItemCount(listIndex);
795 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
796 for (int col = 0; col <= maxcol; col++)
797 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
799 SetRedraw(TRUE);
800 GetStatisticsString();
802 CHeaderCtrl * pHeader = GetHeaderCtrl();
803 HDITEM HeaderItem = {0};
804 HeaderItem.mask = HDI_FORMAT;
805 for (int i=0; i<pHeader->GetItemCount(); ++i)
807 pHeader->GetItem(i, &HeaderItem);
808 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
809 pHeader->SetItem(i, &HeaderItem);
811 if (m_nSortedColumn)
813 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
814 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
815 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
818 if (nSelectedEntry)
820 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
821 EnsureVisible(nSelectedEntry, false);
823 else
825 // Restore the item at the top of the list.
826 for (int i=0;GetTopIndex() != nTopIndex;i++)
828 if ( !EnsureVisible(nTopIndex+i,false) )
830 break;
835 if (pApp)
836 pApp->DoWaitCursor(-1);
838 m_bEmpty = (GetItemCount() == 0);
839 Invalidate();
840 #endif
843 int CGitStatusListCtrl::GetColumnIndex(int mask)
845 int i=0;
846 for(i=0;i<32;i++)
847 if(mask&0x1)
848 return i;
849 else
850 mask=mask>>1;
851 return -1;
853 void CGitStatusListCtrl::AddEntry(CTGitPath * GitPath, WORD /*langID*/, int listIndex)
855 static CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
856 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
857 static bool abbreviateRenamings(((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\AbbreviateRenamings"), FALSE)) == TRUE);
858 static bool relativeTimes = (CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE) != FALSE);
860 CString path = GitPath->GetGitPathString();
862 m_bBlock = TRUE;
863 int index = listIndex;
864 int nCol = 1;
865 CString entryname = GitPath->GetGitPathString();
866 int icon_idx = 0;
867 if (GitPath->IsDirectory())
869 icon_idx = m_nIconFolder;
870 m_nShownSubmodules++;
872 else
874 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath);
875 m_nShownFiles++;
877 switch (GitPath->m_Action)
879 case CTGitPath::LOGACTIONS_ADDED:
880 case CTGitPath::LOGACTIONS_COPY:
881 m_nShownAdded++;
882 break;
883 case CTGitPath::LOGACTIONS_DELETED:
884 m_nShownDeleted++;
885 break;
886 case CTGitPath::LOGACTIONS_REPLACED:
887 case CTGitPath::LOGACTIONS_MODIFIED:
888 case CTGitPath::LOGACTIONS_MERGED:
889 m_nShownModified++;
890 break;
891 case CTGitPath::LOGACTIONS_UNMERGED:
892 m_nShownConflicted++;
893 break;
894 case CTGitPath::LOGACTIONS_UNVER:
895 m_nShownUnversioned++;
896 break;
897 default:
898 m_nShownUnversioned++;
899 break;
901 if(GitPath->m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !GitPath->GetGitOldPathString().IsEmpty())
903 if (!abbreviateRenamings)
905 // relative path
906 CString rename;
907 rename.Format(from, GitPath->GetGitOldPathString());
908 entryname += _T(" ") + rename;
910 else
912 CTGitPathList tgpl;
913 tgpl.AddPath(*GitPath);
914 CTGitPath old(GitPath->GetGitOldPathString());
915 tgpl.AddPath(old);
916 CString commonRoot = tgpl.GetCommonRoot().GetGitPathString();
917 if (!commonRoot.IsEmpty())
918 commonRoot += _T("/");
919 if (old.GetFileOrDirectoryName() == GitPath->GetFileOrDirectoryName() && old.GetContainingDirectory().GetGitPathString() != "" && GitPath->GetContainingDirectory().GetGitPathString())
921 entryname = commonRoot + _T("{") + GitPath->GetGitOldPathString().Mid(commonRoot.GetLength(), old.GetGitPathString().GetLength() - commonRoot.GetLength() - old.GetFileOrDirectoryName().GetLength() - 1) + _T(" => ") + GitPath->GetGitPathString().Mid(commonRoot.GetLength(), GitPath->GetGitPathString().GetLength() - commonRoot.GetLength() - old.GetFileOrDirectoryName().GetLength() - 1) + _T("}/") + old.GetFileOrDirectoryName();
923 else if (!commonRoot.IsEmpty())
925 entryname = commonRoot + _T("{") + GitPath->GetGitOldPathString().Mid(commonRoot.GetLength()) + _T(" => ") + GitPath->GetGitPathString().Mid(commonRoot.GetLength()) + _T("}");
927 else
929 entryname = GitPath->GetGitOldPathString().Mid(commonRoot.GetLength()) + _T(" => ") + GitPath->GetGitPathString().Mid(commonRoot.GetLength());
934 InsertItem(index, entryname, icon_idx);
935 if (m_restorepaths.find(GitPath->GetWinPathString()) != m_restorepaths.end())
936 SetItemState(index, INDEXTOOVERLAYMASK(OVL_RESTORE), TVIS_OVERLAYMASK);
938 this->SetItemData(index, (DWORD_PTR)GitPath);
939 // SVNSLC_COLFILENAME
940 SetItemText(index, nCol++, GitPath->GetFileOrDirectoryName());
941 // SVNSLC_COLEXT
942 SetItemText(index, nCol++, GitPath->GetFileExtension());
943 // SVNSLC_COLSTATUS
944 SetItemText(index, nCol++, GitPath->GetActionName());
946 SetItemText(index, GetColumnIndex(GITSLC_COLADD),GitPath->m_StatAdd);
947 SetItemText(index, GetColumnIndex(GITSLC_COLDEL),GitPath->m_StatDel);
950 CString modificationDate;
951 __int64 filetime = GitPath->GetLastWriteTime();
952 if (filetime && (GitPath->m_Action != CTGitPath::LOGACTIONS_DELETED))
954 FILETIME* f = (FILETIME*)(__int64*)&filetime;
955 modificationDate = CLoglistUtils::FormatDateAndTime(CTime(g_Git.filetime_to_time_t(f)), DATE_SHORTDATE, true, relativeTimes);
957 SetItemText(index, GetColumnIndex(GITSLC_COLMODIFICATIONDATE), modificationDate);
959 // SVNSLC_COLSIZE
960 if (GitPath->IsDirectory())
961 SetItemText(index, GetColumnIndex(GITSLC_COLSIZE), _T(""));
962 else
964 TCHAR buf[100];
965 StrFormatByteSize64(GitPath->GetFileSize(), buf, 100);
966 SetItemText(index, GetColumnIndex(GITSLC_COLSIZE), buf);
969 SetCheck(index, GitPath->m_Checked);
970 if (GitPath->m_Checked)
971 m_nSelected++;
974 if( GitPath->m_Action & CTGitPath::LOGACTIONS_IGNORE)
975 SetItemGroup(index, 2);
976 else if( GitPath->m_Action & CTGitPath::LOGACTIONS_UNVER)
977 SetItemGroup(index,1);
978 else
980 SetItemGroup(index, GitPath->m_ParentNo&(PARENT_MASK|MERGE_MASK));
983 m_bBlock = FALSE;
988 bool CGitStatusListCtrl::SetItemGroup(int item, int groupindex)
990 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
991 // return false;
992 if (groupindex < 0)
993 return false;
994 LVITEM i = {0};
995 i.mask = LVIF_GROUPID;
996 i.iItem = item;
997 i.iSubItem = 0;
998 i.iGroupId = groupindex;
1000 return !!SetItem(&i);
1003 void CGitStatusListCtrl::OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult)
1005 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1006 *pResult = 0;
1007 if (m_bBlock || m_arStatusArray.empty())
1008 return;
1009 m_bBlock = TRUE;
1010 if (m_nSortedColumn == phdr->iItem)
1011 m_bAscending = !m_bAscending;
1012 else
1013 m_bAscending = TRUE;
1014 m_nSortedColumn = phdr->iItem;
1015 Show(m_dwShow, 0, m_bShowFolders,false,true);
1017 m_bBlock = FALSE;
1020 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
1022 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1023 *pResult = 0;
1025 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1026 if ((m_bBlock)&&(m_bBlockUI))
1028 // if we're blocked, prevent changing of the check state
1029 if ((!ISCHECKED(pNMLV->uOldState) && ISCHECKED(pNMLV->uNewState))||
1030 (ISCHECKED(pNMLV->uOldState) && !ISCHECKED(pNMLV->uNewState)))
1031 *pResult = TRUE;
1035 BOOL CGitStatusListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
1037 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1038 *pResult = 0;
1039 CWnd* pParent = GetLogicalParent();
1040 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
1042 pParent->SendMessage(GITSLNM_ITEMCHANGED, pNMLV->iItem);
1045 if ((pNMLV->uNewState==0)||(pNMLV->uNewState & LVIS_SELECTED)||(pNMLV->uNewState & LVIS_FOCUSED))
1046 return FALSE;
1048 if (m_bBlock)
1049 return FALSE;
1051 bool bSelected = !!(ListView_GetItemState(m_hWnd, pNMLV->iItem, LVIS_SELECTED) & LVIS_SELECTED);
1052 int nListItems = GetItemCount();
1054 m_bBlock = TRUE;
1055 // was the item checked?
1057 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1058 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1060 if (GetCheck(pNMLV->iItem))
1062 CheckEntry(pNMLV->iItem, nListItems);
1063 if (bSelected)
1065 POSITION pos = GetFirstSelectedItemPosition();
1066 int index;
1067 while ((index = GetNextSelectedItem(pos)) >= 0)
1069 if (index != pNMLV->iItem)
1070 CheckEntry(index, nListItems);
1074 else
1076 UncheckEntry(pNMLV->iItem, nListItems);
1077 if (bSelected)
1079 POSITION pos = GetFirstSelectedItemPosition();
1080 int index;
1081 while ((index = GetNextSelectedItem(pos)) >= 0)
1083 if (index != pNMLV->iItem)
1084 UncheckEntry(index, nListItems);
1089 GetStatisticsString();
1090 m_bBlock = FALSE;
1091 NotifyCheck();
1093 return FALSE;
1096 void CGitStatusListCtrl::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
1098 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
1100 *pResult = FALSE;
1103 void CGitStatusListCtrl::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
1105 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
1107 Invalidate(FALSE);
1110 void CGitStatusListCtrl::CheckEntry(int index, int /*nListItems*/)
1112 Locker lock(m_critSec);
1113 //FileEntry * entry = GetListEntry(index);
1114 CTGitPath *path=(CTGitPath*)GetItemData(index);
1115 ASSERT(path != NULL);
1116 if (path == NULL)
1117 return;
1118 m_mapFilenameToChecked[path->GetGitPathString()] = true;
1119 SetCheck(index, TRUE);
1120 //entry = GetListEntry(index);
1121 // if an unversioned item was checked, then we need to check if
1122 // the parent folders are unversioned too. If the parent folders actually
1123 // are unversioned, then check those too.
1124 #if 0
1125 if (entry->status == git_wc_status_unversioned)
1127 // we need to check the parent folder too
1128 const CTGitPath& folderpath = entry->path;
1129 for (int i=0; i< nListItems; ++i)
1131 FileEntry * testEntry = GetListEntry(i);
1132 ASSERT(testEntry != NULL);
1133 if (testEntry == NULL)
1134 continue;
1135 if (!testEntry->checked)
1137 if (testEntry->path.IsAncestorOf(folderpath) && (!testEntry->path.IsEquivalentTo(folderpath)))
1139 SetEntryCheck(testEntry,i,true);
1140 m_nSelected++;
1145 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1146 if ( (entry->status == git_wc_status_deleted) || (m_bCheckChildrenWithParent) || (bShift) )
1148 // if a deleted folder gets checked, we have to check all
1149 // children of that folder too.
1150 if (entry->path.IsDirectory())
1152 SetCheckOnAllDescendentsOf(entry, true);
1155 // if a deleted file or folder gets checked, we have to
1156 // check all parents of this item too.
1157 for (int i=0; i<nListItems; ++i)
1159 FileEntry * testEntry = GetListEntry(i);
1160 ASSERT(testEntry != NULL);
1161 if (testEntry == NULL)
1162 continue;
1163 if (!testEntry->checked)
1165 if (testEntry->path.IsAncestorOf(entry->path) && (!testEntry->path.IsEquivalentTo(entry->path)))
1167 if ((testEntry->status == git_wc_status_deleted)||(m_bCheckChildrenWithParent))
1169 SetEntryCheck(testEntry,i,true);
1170 m_nSelected++;
1171 // now we need to check all children of this parent folder
1172 SetCheckOnAllDescendentsOf(testEntry, true);
1178 #endif
1179 if ( !path->m_Checked )
1181 path->m_Checked = TRUE;
1182 m_nSelected++;
1186 void CGitStatusListCtrl::UncheckEntry(int index, int /*nListItems*/)
1188 Locker lock(m_critSec);
1189 CTGitPath *path=(CTGitPath*)GetItemData(index);
1190 ASSERT(path != NULL);
1191 if (path == NULL)
1192 return;
1193 SetCheck(index, FALSE);
1194 m_mapFilenameToChecked[path->GetGitPathString()] = false;
1195 //entry = GetListEntry(index);
1196 // item was unchecked
1197 #if 0
1198 if (entry->path.IsDirectory())
1200 // disable all files within an unselected folder, except when unchecking a folder with property changes
1201 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1202 if ( (entry->status != git_wc_status_modified) || (bShift) )
1204 SetCheckOnAllDescendentsOf(entry, false);
1207 else if (entry->status == git_wc_status_deleted)
1209 // a "deleted" file was unchecked, so uncheck all parent folders
1210 // and all children of those parents
1211 for (int i=0; i<nListItems; i++)
1213 FileEntry * testEntry = GetListEntry(i);
1214 ASSERT(testEntry != NULL);
1215 if (testEntry == NULL)
1216 continue;
1217 if (testEntry->checked)
1219 if (testEntry->path.IsAncestorOf(entry->path))
1221 if (testEntry->status == git_wc_status_deleted)
1223 SetEntryCheck(testEntry,i,false);
1224 m_nSelected--;
1226 SetCheckOnAllDescendentsOf(testEntry, false);
1232 #endif
1233 if ( path->m_Checked )
1235 path->m_Checked = FALSE;
1236 m_nSelected--;
1239 bool CGitStatusListCtrl::BuildStatistics()
1242 bool bRefetchStatus = false;
1244 // now gather some statistics
1245 m_nUnversioned = 0;
1246 m_nNormal = 0;
1247 m_nModified = 0;
1248 m_nAdded = 0;
1249 m_nDeleted = 0;
1250 m_nConflicted = 0;
1251 m_nTotal = 0;
1252 m_nSelected = 0;
1253 m_nLineAdded = 0;
1254 m_nLineDeleted = 0;
1255 m_nRenamed = 0;
1257 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1259 int status=((CTGitPath*)m_arStatusArray[i])->m_Action;
1261 m_nLineAdded += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatAdd);
1262 m_nLineDeleted += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatDel);
1264 if(status&(CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
1265 m_nAdded++;
1267 if(status&CTGitPath::LOGACTIONS_DELETED)
1268 m_nDeleted++;
1270 if(status&(CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_MODIFIED))
1271 m_nModified++;
1273 if(status&CTGitPath::LOGACTIONS_UNMERGED)
1274 m_nConflicted++;
1276 if(status&(CTGitPath::LOGACTIONS_IGNORE|CTGitPath::LOGACTIONS_UNVER))
1277 m_nUnversioned++;
1279 if(status&(CTGitPath::LOGACTIONS_REPLACED))
1280 m_nRenamed++;
1282 if(((CTGitPath*)m_arStatusArray[i])->m_Checked)
1283 m_nSelected++;
1285 // } // switch (entry->status)
1286 // } // if (entry)
1287 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1288 return !bRefetchStatus;
1292 int CGitStatusListCtrl::GetGroupFromPoint(POINT * ppt)
1294 // the point must be relative to the upper left corner of the control
1296 if (ppt == NULL)
1297 return -1;
1298 if (!IsGroupViewEnabled())
1299 return -1;
1301 POINT pt = *ppt;
1302 pt.x = 10;
1303 UINT flags = 0;
1304 int nItem = -1;
1305 RECT rc;
1306 GetWindowRect(&rc);
1307 while (((flags & LVHT_BELOW) == 0)&&(pt.y < rc.bottom))
1309 nItem = HitTest(pt, &flags);
1310 if ((flags & LVHT_ONITEM)||(flags & LVHT_EX_GROUP_HEADER))
1312 // the first item below the point
1314 // check if the point is too much right (i.e. if the point
1315 // is farther to the right than the width of the item)
1316 RECT r;
1317 GetItemRect(nItem, &r, LVIR_LABEL);
1318 if (ppt->x > r.right)
1319 return -1;
1321 LVITEM lv = {0};
1322 lv.mask = LVIF_GROUPID;
1323 lv.iItem = nItem;
1324 GetItem(&lv);
1325 int groupID = lv.iGroupId;
1326 // now we search upwards and check if the item above this one
1327 // belongs to another group. If it belongs to the same group,
1328 // we're not over a group header
1329 while (pt.y >= 0)
1331 pt.y -= 2;
1332 nItem = HitTest(pt, &flags);
1333 if ((flags & LVHT_ONITEM)&&(nItem >= 0))
1335 // the first item below the point
1336 LVITEM lv = {0};
1337 lv.mask = LVIF_GROUPID;
1338 lv.iItem = nItem;
1339 GetItem(&lv);
1340 if (lv.iGroupId != groupID)
1341 return groupID;
1342 else
1343 return -1;
1346 if (pt.y < 0)
1347 return groupID;
1348 return -1;
1350 pt.y += 2;
1352 return -1;
1355 void CGitStatusListCtrl::OnContextMenuGroup(CWnd * /*pWnd*/, CPoint point)
1357 POINT clientpoint = point;
1358 ScreenToClient(&clientpoint);
1359 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint) >= 0))
1361 CMenu popup;
1362 if (popup.CreatePopupMenu())
1364 CString temp;
1365 temp.LoadString(IDS_STATUSLIST_CHECKGROUP);
1366 popup.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_CHECKGROUP, temp);
1367 temp.LoadString(IDS_STATUSLIST_UNCHECKGROUP);
1368 popup.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_UNCHECKGROUP, temp);
1369 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1370 bool bCheck = false;
1371 switch (cmd)
1373 case IDGITLC_CHECKGROUP:
1374 bCheck = true;
1375 // fall through here
1376 case IDGITLC_UNCHECKGROUP:
1378 int group = GetGroupFromPoint(&clientpoint);
1379 // go through all items and check/uncheck those assigned to the group
1380 // but block the OnLvnItemChanged handler
1381 m_bBlock = true;
1382 LVITEM lv;
1383 for (int i=0; i<GetItemCount(); ++i)
1385 SecureZeroMemory(&lv, sizeof(LVITEM));
1386 lv.mask = LVIF_GROUPID;
1387 lv.iItem = i;
1388 GetItem(&lv);
1390 if (lv.iGroupId == group)
1392 CTGitPath * entry = (CTGitPath*)GetItemData(i);
1393 if (entry)
1395 bool bOldCheck = entry->m_Checked;
1396 SetEntryCheck(entry, i, bCheck);
1397 if (bCheck != bOldCheck)
1399 if (bCheck)
1400 m_nSelected++;
1401 else
1402 m_nSelected--;
1408 GetStatisticsString();
1409 NotifyCheck();
1410 m_bBlock = false;
1412 break;
1418 void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point)
1421 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1423 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1424 CTGitPath * filepath;
1426 int selIndex = GetSelectionMark();
1427 if ((point.x == -1) && (point.y == -1))
1429 CRect rect;
1430 GetItemRect(selIndex, &rect, LVIR_LABEL);
1431 ClientToScreen(&rect);
1432 point = rect.CenterPoint();
1434 if ((GetSelectedCount() == 0) && (m_bHasCheckboxes))
1436 // nothing selected could mean the context menu is requested for
1437 // a group header
1438 OnContextMenuGroup(pWnd, point);
1440 else if (selIndex >= 0)
1442 //FileEntry * entry = GetListEntry(selIndex);
1444 filepath = (CTGitPath * )GetItemData(selIndex);
1446 ASSERT(filepath != NULL);
1447 if (filepath == NULL)
1448 return;
1450 //const CTGitPath& filepath = entry->path;
1451 int wcStatus = filepath->m_Action;
1452 // entry is selected, now show the popup menu
1453 Locker lock(m_critSec);
1454 CIconMenu popup;
1455 CMenu changelistSubMenu;
1456 CMenu ignoreSubMenu;
1457 if (popup.CreatePopupMenu())
1459 //Add Menu for version controlled file
1461 if (GetSelectedCount() > 0 && wcStatus & CTGitPath::LOGACTIONS_UNMERGED)
1463 if (GetSelectedCount() == 1 && (m_dwContextMenus & GITSLC_POPCONFLICT)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1465 popup.AppendMenuIcon(IDGITLC_EDITCONFLICT, IDS_MENUCONFLICT, IDI_CONFLICT);
1467 if (m_dwContextMenus & GITSLC_POPRESOLVE)
1469 popup.AppendMenuIcon(IDGITLC_RESOLVECONFLICT, IDS_STATUSLIST_CONTEXT_RESOLVED, IDI_RESOLVE);
1471 if ((m_dwContextMenus & GITSLC_POPRESOLVE)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1473 popup.AppendMenuIcon(IDGITLC_RESOLVETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS, IDI_RESOLVE);
1474 popup.AppendMenuIcon(IDGITLC_RESOLVEMINE, IDS_SVNPROGRESS_MENUUSEMINE, IDI_RESOLVE);
1476 if ((m_dwContextMenus & GITSLC_POPCONFLICT)||(m_dwContextMenus & GITSLC_POPRESOLVE))
1477 popup.AppendMenu(MF_SEPARATOR);
1480 if (GetSelectedCount() > 0)
1482 if (wcStatus & CTGitPath::LOGACTIONS_UNVER)
1483 if (m_dwContextMenus & GITSLC_POPADD)
1485 //if ( entry->IsFolder() )
1487 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1489 //else
1491 popup.AppendMenuIcon(IDGITLC_ADD, IDS_STATUSLIST_CONTEXT_ADD, IDI_ADD);
1496 if (!(wcStatus & CTGitPath::LOGACTIONS_UNVER) && GetSelectedCount() > 0)
1498 bool bEntryAdded = false;
1499 if (m_dwContextMenus & GITSLC_POPCOMPAREWITHBASE)
1501 if(filepath->m_ParentNo & MERGE_MASK)
1502 popup.AppendMenuIcon(IDGITLC_COMPARE, IDS_TREE_DIFF, IDI_DIFF);
1503 else
1504 popup.AppendMenuIcon(IDGITLC_COMPARE, IDS_LOG_COMPAREWITHBASE, IDI_DIFF);
1506 popup.SetDefaultItem(IDGITLC_COMPARE, FALSE);
1507 bEntryAdded = true;
1510 if (!g_Git.IsInitRepos() && (m_dwContextMenus & GITSLC_POPGNUDIFF))
1512 popup.AppendMenuIcon(IDGITLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1513 bEntryAdded = true;
1516 if ((m_dwContextMenus & this->GetContextMenuBit(IDGITLC_COMPAREWC)) && m_bHasWC)
1518 if ((!m_CurrentVersion.IsEmpty()) && m_CurrentVersion != GIT_REV_ZERO)
1520 popup.AppendMenuIcon(IDGITLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1521 bEntryAdded = true;
1525 //else if (GetSelectedCount() > 1)
1527 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1528 // {
1529 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1530 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1531 // }
1534 if (bEntryAdded)
1535 popup.AppendMenu(MF_SEPARATOR);
1538 if( (!this->m_Rev1.IsEmpty()) || (!this->m_Rev1.IsEmpty()) )
1540 if(GetSelectedCount() == 1)
1542 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_COMPARETWO))
1544 popup.AppendMenuIcon(IDGITLC_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1545 popup.SetDefaultItem(IDGITLC_COMPARETWO, FALSE);
1547 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_GNUDIFF2))
1549 popup.AppendMenuIcon(IDGITLC_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1554 //Select Multi item
1555 if (GetSelectedCount() > 0)
1557 if ((GetSelectedCount() == 2) && (m_dwContextMenus & GITSLC_POPCOMPARETWOFILES) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO))
1559 POSITION pos = GetFirstSelectedItemPosition();
1560 int index = GetNextSelectedItem(pos);
1561 if (index >= 0)
1563 CTGitPath * entry2 = NULL;
1564 bool bothItemsAreExistingFiles = true;
1565 entry2 = (CTGitPath * )GetItemData(index);
1566 if (entry2)
1567 bothItemsAreExistingFiles = !entry2->IsDirectory() && entry2->Exists();
1568 index = GetNextSelectedItem(pos);
1569 if (index >= 0)
1571 entry2 = (CTGitPath * )GetItemData(index);
1572 if (entry2)
1573 bothItemsAreExistingFiles = bothItemsAreExistingFiles && !entry2->IsDirectory() && entry2->Exists();
1574 if (bothItemsAreExistingFiles)
1575 popup.AppendMenuIcon(IDGITLC_COMPARETWOFILES, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES, IDI_DIFF);
1579 // if (wcStatus > git_wc_status_normal)
1580 // {
1581 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1582 // {
1583 // // reverting missing folders is not possible
1584 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1585 // {
1586 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1587 // }
1588 // }
1589 // }
1590 // if (entry->remotestatus > git_wc_status_normal)
1591 // {
1592 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1593 // {
1594 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1595 // }
1596 // }
1599 if ( (GetSelectedCount() >0 ) && (!(wcStatus & CTGitPath::LOGACTIONS_UNVER)) && m_bHasWC)
1601 if ((m_dwContextMenus & GITSLC_POPREVERT) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO))
1603 popup.AppendMenuIcon(IDGITLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1606 if ((m_dwContextMenus & GITSLC_POPSKIPWORKTREE) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO) && !(wcStatus & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_DELETED | CTGitPath::LOGACTIONS_UNMERGED)) && !filepath->IsDirectory())
1608 popup.AppendMenuIcon(IDGITLC_SKIPWORKTREE, IDS_STATUSLIST_SKIPWORKTREE);
1611 if ((m_dwContextMenus & GITSLC_POPASSUMEVALID) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO) && !(wcStatus & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_DELETED | CTGitPath::LOGACTIONS_UNMERGED)) && !filepath->IsDirectory())
1613 popup.AppendMenuIcon(IDGITLC_ASSUMEVALID, IDS_MENUASSUMEVALID);
1616 if (m_dwContextMenus & GITSLC_POPRESTORE && !filepath->IsDirectory())
1618 if (m_restorepaths.find(filepath->GetWinPathString()) == m_restorepaths.end())
1619 popup.AppendMenuIcon(IDGITLC_CREATERESTORE, IDS_MENUCREATERESTORE, IDI_RESTORE);
1620 else
1621 popup.AppendMenuIcon(IDGITLC_RESTOREPATH, IDS_MENURESTORE, IDI_RESTORE);
1624 if ((m_dwContextMenus & GetContextMenuBit(IDGITLC_REVERTTOREV)) && ( !this->m_CurrentVersion.IsEmpty() )
1625 && this->m_CurrentVersion != GIT_REV_ZERO && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1627 popup.AppendMenuIcon(IDGITLC_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1631 if ((GetSelectedCount() == 1)&&(!(wcStatus & CTGitPath::LOGACTIONS_UNVER))
1632 &&(!(wcStatus & CTGitPath::LOGACTIONS_IGNORE)))
1634 if (m_dwContextMenus & GITSLC_POPSHOWLOG)
1636 popup.AppendMenuIcon(IDGITLC_LOG, IDS_REPOBROWSE_SHOWLOG, IDI_LOG);
1638 if (m_dwContextMenus & GITSLC_POPSHOWLOGSUBMODULE && filepath->IsDirectory())
1640 popup.AppendMenuIcon(IDGITLC_LOGSUBMODULE, IDS_LOG_SUBMODULE, IDI_LOG);
1642 if (m_dwContextMenus & GITSLC_POPSHOWLOGOLDNAME && (wcStatus & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !filepath->GetGitOldPathString().IsEmpty()))
1644 popup.AppendMenuIcon(IDGITLC_LOGOLDNAME, IDS_STATUSLIST_SHOWLOGOLDNAME, IDI_LOG);
1646 if (m_dwContextMenus & GITSLC_POPBLAME && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED) && m_bHasWC)
1648 popup.AppendMenuIcon(IDGITLC_BLAME, IDS_MENUBLAME, IDI_BLAME);
1652 if (GetSelectedCount() > 0)
1654 if ((m_dwContextMenus & GetContextMenuBit(IDGITLC_EXPORT)) && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1655 popup.AppendMenuIcon(IDGITLC_EXPORT, IDS_LOG_POPUP_EXPORT, IDI_EXPORT);
1658 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1659 if ( (GetSelectedCount() == 1) )
1661 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_SAVEAS) && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1663 popup.AppendMenuIcon(IDGITLC_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
1666 if (m_dwContextMenus & GITSLC_POPOPEN && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1668 popup.AppendMenuIcon(IDGITLC_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1669 popup.AppendMenuIcon(IDGITLC_OPEN, IDS_REPOBROWSE_OPEN, IDI_OPEN);
1670 popup.AppendMenuIcon(IDGITLC_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1671 if (wcStatus &CTGitPath::LOGACTIONS_UNVER) {
1672 popup.SetDefaultItem(IDGITLC_OPEN, FALSE);
1676 if (m_dwContextMenus & GITSLC_POPEXPLORE && !(wcStatus & CTGitPath::LOGACTIONS_DELETED) && m_bHasWC)
1678 popup.AppendMenuIcon(IDGITLC_EXPLORE, IDS_STATUSLIST_CONTEXT_EXPLORE, IDI_EXPLORER);
1682 if (GetSelectedCount() > 0)
1684 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
1685 // {
1686 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1687 // }
1688 // if ((wcStatus != Git_wc_status_unversioned)&&(wcStatus != git_wc_status_ignored)&&(wcStatus != Git_wc_status_deleted)&&(wcStatus != Git_wc_status_added)&&(m_dwContextMenus & GitSLC_POPDELETE))
1689 // {
1690 // if (bShift)
1691 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
1692 // else
1693 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
1694 // }
1695 if ((wcStatus & CTGitPath::LOGACTIONS_UNVER)/*||(wcStatus == git_wc_status_deleted)*/)
1697 if (m_dwContextMenus & GITSLC_POPDELETE)
1699 popup.AppendMenuIcon(IDGITLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1702 if ( (wcStatus & CTGitPath::LOGACTIONS_UNVER || wcStatus & CTGitPath::LOGACTIONS_DELETED) )
1704 if (m_dwContextMenus & GITSLC_POPIGNORE)
1707 CTGitPathList ignorelist;
1708 FillListOfSelectedItemPaths(ignorelist);
1709 //check if all selected entries have the same extension
1710 bool bSameExt = true;
1711 CString sExt;
1712 for (int i=0; i<ignorelist.GetCount(); ++i)
1714 if (sExt.IsEmpty() && (i==0))
1715 sExt = ignorelist[i].GetFileExtension();
1716 else if (sExt.CompareNoCase(ignorelist[i].GetFileExtension())!=0)
1717 bSameExt = false;
1719 if (bSameExt)
1721 if (ignoreSubMenu.CreateMenu())
1723 CString ignorepath;
1724 if (ignorelist.GetCount()==1)
1725 ignorepath = ignorelist[0].GetFileOrDirectoryName();
1726 else
1727 ignorepath.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
1728 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_IGNORE, ignorepath);
1729 ignorepath = _T("*")+sExt;
1730 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_IGNOREMASK, ignorepath);
1731 CString temp;
1732 temp.LoadString(IDS_MENUIGNORE);
1733 popup.InsertMenu((UINT)-1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)ignoreSubMenu.m_hMenu, temp);
1736 else
1738 CString temp;
1739 if (ignorelist.GetCount()==1)
1741 temp.LoadString(IDS_MENUIGNORE);
1743 else
1745 temp.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
1747 popup.AppendMenuIcon(IDGITLC_IGNORE, temp, IDI_IGNORE);
1755 if (GetSelectedCount() > 0)
1757 popup.AppendMenu(MF_SEPARATOR);
1758 popup.AppendMenuIcon(IDGITLC_COPY, IDS_STATUSLIST_CONTEXT_COPY, IDI_COPYCLIP);
1759 popup.AppendMenuIcon(IDGITLC_COPYEXT, IDS_STATUSLIST_CONTEXT_COPYEXT, IDI_COPYCLIP);
1760 #if 0
1761 if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS))
1762 &&(wcStatus != git_wc_status_unversioned)&&(wcStatus != git_wc_status_none))
1764 popup.AppendMenu(MF_SEPARATOR);
1765 // changelist commands
1766 size_t numChangelists = GetNumberOfChangelistsInSelection();
1767 if (numChangelists > 0)
1769 popup.AppendMenuIcon(IDSVNLC_REMOVEFROMCS, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS);
1771 if ((!entry->IsFolder())&&(changelistSubMenu.CreateMenu()))
1773 CString temp;
1774 temp.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS);
1775 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATECS, temp);
1777 if (entry->changelist.Compare(SVNSLC_IGNORECHANGELIST))
1779 changelistSubMenu.AppendMenu(MF_SEPARATOR);
1780 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATEIGNORECS, SVNSLC_IGNORECHANGELIST);
1783 if (!m_changelists.empty())
1785 // find the changelist names
1786 bool bNeedSeparator = true;
1787 int cmdID = IDSVNLC_MOVETOCS;
1788 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
1790 if ((entry->changelist.Compare(it->first))&&(it->first.Compare(SVNSLC_IGNORECHANGELIST)))
1792 if (bNeedSeparator)
1794 changelistSubMenu.AppendMenu(MF_SEPARATOR);
1795 bNeedSeparator = false;
1797 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, cmdID, it->first);
1798 cmdID++;
1802 temp.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS);
1803 popup.AppendMenu(MF_POPUP|MF_STRING, (UINT_PTR)changelistSubMenu.GetSafeHmenu(), temp);
1806 #endif
1809 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1811 m_bBlock = TRUE;
1812 AfxGetApp()->DoWaitCursor(1);
1813 //int iItemCountBeforeMenuCmd = GetItemCount();
1814 //bool bForce = false;
1815 switch (cmd)
1817 case IDGITLC_VIEWREV:
1818 OpenFile(filepath, ALTERNATIVEEDITOR);
1819 break;
1820 case IDGITLC_OPEN:
1821 OpenFile(filepath,OPEN);
1822 break;
1823 case IDGITLC_OPENWITH:
1824 OpenFile(filepath,OPEN_WITH);
1825 break;
1826 case IDGITLC_EXPLORE:
1828 ShellExecute(this->m_hWnd, _T("explore"), filepath->GetDirectory().GetWinPath(), NULL, NULL, SW_SHOW);
1830 break;
1831 case IDGITLC_CREATERESTORE:
1833 POSITION pos = GetFirstSelectedItemPosition();
1834 while (pos)
1836 int index = GetNextSelectedItem(pos);
1837 CTGitPath * entry2 = (CTGitPath * )GetItemData(index);
1838 ASSERT(entry2 != NULL);
1839 if (entry2 == NULL || entry2->IsDirectory())
1840 continue;
1841 if (m_restorepaths.find(entry2->GetWinPathString()) != m_restorepaths.end())
1842 continue;
1843 CTGitPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
1844 if (CopyFile(g_Git.m_CurrentDir + _T("\\") + entry2->GetWinPathString(), tempFile.GetWinPath(), FALSE))
1846 m_restorepaths[entry2->GetWinPathString()] = tempFile.GetWinPathString();
1847 SetItemState(index, INDEXTOOVERLAYMASK(OVL_RESTORE), LVIS_OVERLAYMASK);
1850 Invalidate();
1852 break;
1853 case IDGITLC_RESTOREPATH:
1855 if (CMessageBox::Show(m_hWnd, IDS_STATUSLIST_RESTOREPATH, IDS_APPNAME, 2, IDI_QUESTION, IDS_RESTOREBUTTON, IDS_ABORTBUTTON) == 2)
1856 break;
1857 POSITION pos = GetFirstSelectedItemPosition();
1858 while (pos)
1860 int index = GetNextSelectedItem(pos);
1861 CTGitPath * entry2 = (CTGitPath * )GetItemData(index);
1862 ASSERT(entry2 != NULL);
1863 if (entry2 == NULL)
1864 continue;
1865 if (m_restorepaths.find(entry2->GetWinPathString()) == m_restorepaths.end())
1866 continue;
1867 if (CopyFile(m_restorepaths[entry2->GetWinPathString()], g_Git.m_CurrentDir + _T("\\") + entry2->GetWinPathString(), FALSE))
1869 m_restorepaths.erase(entry2->GetWinPathString());
1870 SetItemState(index, 0, LVIS_OVERLAYMASK);
1873 Invalidate();
1875 break;
1876 // Compare current version and work copy.
1877 case IDGITLC_COMPAREWC:
1879 POSITION pos = GetFirstSelectedItemPosition();
1880 while ( pos )
1882 int index = GetNextSelectedItem(pos);
1883 StartDiffWC(index);
1886 break;
1887 // Compare with base version. when current version is zero, compare workcopy and HEAD.
1888 case IDGITLC_COMPARE:
1890 POSITION pos = GetFirstSelectedItemPosition();
1891 while ( pos )
1893 int index = GetNextSelectedItem(pos);
1894 StartDiff(index);
1897 break;
1898 case IDGITLC_COMPARETWO:
1900 POSITION pos = GetFirstSelectedItemPosition();
1901 while ( pos )
1903 int index = GetNextSelectedItem(pos);
1904 StartDiffTwo(index);
1907 break;
1908 case IDGITLC_COMPARETWOFILES:
1910 POSITION pos = GetFirstSelectedItemPosition();
1911 CTGitPath * firstfilepath = NULL, * secondfilepath = NULL;
1912 if (pos)
1914 firstfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
1915 ASSERT(firstfilepath != NULL);
1916 if (firstfilepath == NULL)
1917 break;
1919 secondfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
1920 ASSERT(secondfilepath != NULL);
1921 if (secondfilepath == NULL)
1922 break;
1924 CString sCmd;
1925 sCmd.Format(_T("/command:diff /path:\"%s\" /path2:\"%s\" /hwnd:%ld"), firstfilepath->GetWinPath(), secondfilepath->GetWinPath(), (unsigned long)m_hWnd);
1926 CAppUtils::RunTortoiseGitProc(sCmd);
1929 break;
1930 case IDGITLC_GNUDIFF1:
1932 POSITION pos = GetFirstSelectedItemPosition();
1933 while (pos)
1935 CTGitPath * selectedFilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
1936 if (m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
1938 CString fromwhere;
1939 if (m_amend)
1940 fromwhere = _T("~1");
1941 CAppUtils::StartShowUnifiedDiff(m_hWnd, *selectedFilepath, GitRev::GetHead() + fromwhere, *selectedFilepath, GitRev::GetWorkingCopy());
1943 else
1945 if ((selectedFilepath->m_ParentNo & (PARENT_MASK | MERGE_MASK)) == 0)
1946 CAppUtils::StartShowUnifiedDiff(m_hWnd, *selectedFilepath, m_CurrentVersion + _T("~1"), *selectedFilepath, m_CurrentVersion);
1947 else
1949 CString str;
1950 if (!(selectedFilepath->m_ParentNo & MERGE_MASK))
1951 str.Format(_T("%s^%d"), m_CurrentVersion, (selectedFilepath->m_ParentNo & PARENT_MASK) + 1);
1953 CAppUtils::StartShowUnifiedDiff(m_hWnd, *selectedFilepath, str, *selectedFilepath, m_CurrentVersion, false, false, false, !!(selectedFilepath->m_ParentNo & MERGE_MASK));
1958 break;
1959 case IDGITLC_GNUDIFF2:
1961 CAppUtils::StartShowUnifiedDiff(m_hWnd, *filepath, m_Rev2, *filepath, m_Rev1);
1963 break;
1965 case IDGITLC_ADD:
1967 CTGitPathList paths;
1968 FillListOfSelectedItemPaths(paths, true);
1970 CGitProgressDlg progDlg;
1971 progDlg.SetCommand(CGitProgressDlg::GitProgress_Add);
1972 progDlg.SetPathList(paths);
1973 progDlg.SetItemCount(paths.GetCount());
1974 progDlg.DoModal();
1976 // reset unchecked status
1977 POSITION pos = GetFirstSelectedItemPosition();
1978 int index;
1979 while ((index = GetNextSelectedItem(pos)) >= 0)
1981 m_mapFilenameToChecked.erase(((CTGitPath*)GetItemData(index))->GetGitPathString());
1984 if (NULL != GetLogicalParent() && NULL != GetLogicalParent()->GetSafeHwnd())
1985 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH);
1987 SetRedraw(TRUE);
1989 break;
1991 case IDGITLC_DELETE:
1993 //Collect paths
1994 std::vector<int> selectIndex;
1996 POSITION pos = GetFirstSelectedItemPosition();
1997 int index;
1998 while ((index = GetNextSelectedItem(pos)) >= 0)
2000 selectIndex.push_back(index);
2003 //Create file-list ('\0' separated) for SHFileOperation
2004 CString filelist;
2005 for(int i=0;i<selectIndex.size();i++)
2007 index=selectIndex[i];
2009 CTGitPath * path=(CTGitPath*)GetItemData(index);
2010 ASSERT(path);
2011 if(path == NULL)
2012 continue;
2014 filelist += path->GetWinPathString();
2015 filelist += _T("|");
2017 filelist += _T("|");
2018 int len = filelist.GetLength();
2019 std::unique_ptr<TCHAR[]> buf(new TCHAR[len + 2]);
2020 _tcscpy_s(buf.get(), len + 2, filelist);
2021 for (int i=0; i<len; ++i)
2022 if (buf.get()[i] == '|')
2023 buf.get()[i] = 0;
2024 SHFILEOPSTRUCT fileop;
2025 fileop.hwnd = this->m_hWnd;
2026 fileop.wFunc = FO_DELETE;
2027 fileop.pFrom = buf.get();
2028 fileop.pTo = NULL;
2029 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
2030 fileop.lpszProgressTitle = _T("deleting file");
2031 int result = SHFileOperation(&fileop);
2033 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
2035 SetRedraw(FALSE);
2036 POSITION pos = NULL;
2037 while ((pos = GetFirstSelectedItemPosition()) != 0)
2039 int index = GetNextSelectedItem(pos);
2040 if (GetCheck(index))
2041 m_nSelected--;
2042 m_nTotal--;
2044 RemoveListEntry(index);
2046 SetRedraw(TRUE);
2049 break;
2051 case IDGITLC_BLAME:
2053 CAppUtils::LaunchTortoiseBlame(g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath(), m_CurrentVersion);
2055 break;
2057 case IDGITLC_LOG:
2058 case IDGITLC_LOGSUBMODULE:
2060 CString sCmd;
2061 sCmd.Format(_T("/command:log /path:\"%s\""), g_Git.m_CurrentDir + _T("\\") + filepath->GetWinPath());
2062 if (cmd == IDGITLC_LOG && filepath->IsDirectory())
2063 sCmd += _T(" /submodule");
2064 CAppUtils::RunTortoiseGitProc(sCmd);
2066 break;
2068 case IDGITLC_LOGOLDNAME:
2070 CTGitPath oldName(filepath->GetGitOldPathString());
2071 CString sCmd;
2072 sCmd.Format(_T("/command:log /path:\"%s\""), g_Git.m_CurrentDir + _T("\\") + oldName.GetWinPath());
2073 CAppUtils::RunTortoiseGitProc(sCmd);
2075 break;
2078 case IDGITLC_EDITCONFLICT:
2080 if (CAppUtils::ConflictEdit(*filepath, false, this->m_bIsRevertTheirMy))
2082 CString conflictedFile = g_Git.m_CurrentDir + _T("\\") + filepath->GetWinPathString();
2083 if (!PathFileExists(conflictedFile) && NULL != GetLogicalParent() && NULL != GetLogicalParent()->GetSafeHwnd())
2084 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2086 break;
2088 case IDGITLC_RESOLVETHEIRS: //follow up
2089 case IDGITLC_RESOLVEMINE: //follow up
2090 case IDGITLC_RESOLVECONFLICT:
2092 if (CMessageBox::Show(m_hWnd, IDS_PROC_RESOLVE, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO)==IDYES)
2094 POSITION pos = GetFirstSelectedItemPosition();
2095 while (pos != 0)
2097 int index;
2098 index = GetNextSelectedItem(pos);
2099 CTGitPath * fentry =(CTGitPath*) this->GetItemData(index);
2100 if(fentry == NULL)
2101 continue;
2102 CString gitcmd,output;
2103 output.Empty();
2105 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVETHEIRS) ||
2106 ((this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVEMINE) )
2108 gitcmd.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry->GetGitPathString());
2109 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2111 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2112 continue;
2115 output.Empty();
2116 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVEMINE) ||
2117 ((this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVETHEIRS) )
2119 gitcmd.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry->GetGitPathString());
2120 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2122 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2123 continue;
2127 output.Empty();
2128 if ( fentry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
2130 gitcmd.Format(_T("git.exe add -f -- \"%s\""),fentry->GetGitPathString());
2131 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2133 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2135 else
2137 fentry->m_Action |= CTGitPath::LOGACTIONS_MODIFIED;
2138 fentry->m_Action &=~CTGitPath::LOGACTIONS_UNMERGED;
2142 CAppUtils::RemoveTempMergeFile(*fentry);
2145 Show(m_dwShow, 0, m_bShowFolders,0,true);
2148 break;
2150 case IDGITLC_IGNORE:
2152 CTGitPathList ignorelist;
2153 //std::vector<CString> toremove;
2154 FillListOfSelectedItemPaths(ignorelist, true);
2155 SetRedraw(FALSE);
2157 if(!CAppUtils::IgnoreFile(ignorelist,false))
2158 break;
2160 CWnd* pParent = GetLogicalParent();
2161 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2163 pParent->SendMessage(GITSLNM_NEEDSREFRESH);
2165 SetRedraw(TRUE);
2167 break;
2168 case IDGITLC_IGNOREMASK:
2170 CString common;
2171 CString ext=filepath->GetFileExtension();
2172 CTGitPathList ignorelist;
2173 FillListOfSelectedItemPaths(ignorelist, true);
2174 SetRedraw(FALSE);
2176 if (!CAppUtils::IgnoreFile(ignorelist,true))
2177 break;
2179 CWnd* pParent = GetLogicalParent();
2180 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2182 pParent->SendMessage(GITSLNM_NEEDSREFRESH);
2185 SetRedraw(TRUE);
2187 break;
2189 case IDGITLC_REVERT:
2191 // If at least one item is not in the status "added"
2192 // we ask for a confirmation
2193 BOOL bConfirm = FALSE;
2194 POSITION pos = GetFirstSelectedItemPosition();
2195 int index;
2196 while ((index = GetNextSelectedItem(pos)) >= 0)
2198 //FileEntry * fentry = GetListEntry(index);
2199 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
2200 if(fentry && fentry->m_Action &CTGitPath::LOGACTIONS_MODIFIED && !fentry->IsDirectory())
2202 bConfirm = TRUE;
2203 break;
2207 CString str;
2208 str.Format(IDS_PROC_WARNREVERT,GetSelectedCount());
2210 if (!bConfirm || CMessageBox::Show(this->m_hWnd, str, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION)==IDYES)
2212 CTGitPathList targetList;
2213 FillListOfSelectedItemPaths(targetList);
2215 // make sure that the list is reverse sorted, so that
2216 // children are removed before any parents
2217 targetList.SortByPathname(true);
2219 // put all reverted files in the trashbin, except the ones with 'added'
2220 // status because they are not restored by the revert.
2221 CTGitPathList delList;
2222 POSITION pos = GetFirstSelectedItemPosition();
2223 int index;
2224 while ((index = GetNextSelectedItem(pos)) >= 0)
2226 CTGitPath *entry=(CTGitPath *)GetItemData(index);
2227 if (entry&&(!(entry->m_Action& CTGitPath::LOGACTIONS_ADDED))
2228 && (!(entry->m_Action& CTGitPath::LOGACTIONS_REPLACED)) && !entry->IsDirectory())
2230 CTGitPath fullpath;
2231 fullpath.SetFromWin(g_Git.m_CurrentDir+_T("\\")+entry->GetWinPath());
2232 delList.AddPath(fullpath);
2235 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2236 delList.DeleteAllFiles(true);
2238 CString revertToCommit = _T("HEAD");
2239 if (m_amend)
2240 revertToCommit = _T("HEAD~1");
2241 if (g_Git.Revert(revertToCommit, targetList))
2243 CMessageBox::Show(this->m_hWnd, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR);
2245 else
2247 bool updateStatusList = false;
2248 for(int i=0;i<targetList.GetCount();i++)
2250 int nListboxEntries = GetItemCount();
2251 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2253 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2254 if (path->GetGitPathString()==targetList[i].GetGitPathString() && !path->IsDirectory())
2256 if(path->m_Action & CTGitPath::LOGACTIONS_ADDED)
2258 path->m_Action = CTGitPath::LOGACTIONS_UNVER;
2259 SetEntryCheck(path,nItem,false);
2260 updateStatusList = true;
2261 SetItemGroup(nItem,1);
2262 this->m_StatusFileList.RemoveItem(*path);
2263 this->m_UnRevFileList.AddPath(*path);
2264 //this->m_IgnoreFileList.RemoveItem(*path);
2267 else
2269 RemoveListEntry(nItem);
2271 break;
2273 else if (path->GetGitPathString()==targetList[i].GetGitPathString() && path->IsDirectory() && path->IsWCRoot())
2275 CString sCmd;
2276 sCmd.Format(_T("/command:revert /path:\"%s\""), path->GetGitPathString());
2277 CCommonAppUtils::RunTortoiseGitProc(sCmd);
2281 SetRedraw(TRUE);
2282 SaveColumnWidths();
2283 Show(m_dwShow, 0, m_bShowFolders,updateStatusList,true);
2284 NotifyCheck();
2288 break;
2290 case IDGITLC_ASSUMEVALID:
2292 CString cmdTemplate;
2293 cmdTemplate = _T("git.exe update-index --assume-unchanged \"%s\"");
2294 POSITION pos = GetFirstSelectedItemPosition();
2295 int index = -1;
2296 while ((index = GetNextSelectedItem(pos)) >= 0)
2298 CTGitPath * path = (CTGitPath *)GetItemData(index);
2299 ASSERT(path);
2300 if(path == NULL)
2301 continue;
2303 CString cmd, output;
2304 cmd.Format(cmdTemplate, path->GetGitPathString());
2305 if (g_Git.Run(cmd, &output, CP_UTF8))
2307 MessageBox(output, _T("TortoiseGit"), MB_ICONERROR);
2310 if (NULL != GetLogicalParent() && NULL != GetLogicalParent()->GetSafeHwnd())
2311 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2313 SetRedraw(TRUE);
2315 break;
2316 case IDGITLC_SKIPWORKTREE:
2318 CString cmdTemplate;
2319 cmdTemplate = _T("git.exe update-index --skip-worktree \"%s\"");
2320 POSITION pos = GetFirstSelectedItemPosition();
2321 int index = -1;
2322 while ((index = GetNextSelectedItem(pos)) >= 0)
2324 CTGitPath * path = (CTGitPath *)GetItemData(index);
2325 ASSERT(path);
2326 if(path == NULL)
2327 continue;
2329 CString cmd, output;
2330 cmd.Format(cmdTemplate, path->GetGitPathString());
2331 if (g_Git.Run(cmd, &output, CP_UTF8))
2333 MessageBox(output, _T("TortoiseGit"), MB_ICONERROR);
2336 if (NULL != GetLogicalParent() && NULL != GetLogicalParent()->GetSafeHwnd())
2337 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2339 SetRedraw(TRUE);
2341 break;
2342 case IDGITLC_COPY:
2343 CopySelectedEntriesToClipboard(0);
2344 break;
2345 case IDGITLC_COPYEXT:
2346 CopySelectedEntriesToClipboard((DWORD)-1);
2347 break;
2348 case IDGITLC_EXPORT:
2349 FilesExport();
2350 break;
2351 case IDGITLC_SAVEAS:
2352 FileSaveAs(filepath);
2353 break;
2355 case IDGITLC_REVERTTOREV:
2356 RevertSelectedItemToVersion();
2357 break;
2358 #if 0
2359 case IDSVNLC_COMMIT:
2361 CTSVNPathList targetList;
2362 FillListOfSelectedItemPaths(targetList);
2363 CTSVNPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
2364 VERIFY(targetList.WriteToFile(tempFile.GetWinPathString()));
2365 CString commandline = CPathUtils::GetAppDirectory();
2366 commandline += _T("TortoiseGitProc.exe /command:commit /pathfile:\"");
2367 commandline += tempFile.GetWinPathString();
2368 commandline += _T("\"");
2369 commandline += _T(" /deletepathfile");
2370 CAppUtils::LaunchApplication(commandline, NULL, false);
2372 break;
2373 case IDSVNLC_CREATEIGNORECS:
2374 CreateChangeList(SVNSLC_IGNORECHANGELIST);
2375 break;
2376 case IDSVNLC_CREATECS:
2378 CCreateChangelistDlg dlg;
2379 if (dlg.DoModal() == IDOK)
2381 CreateChangeList(dlg.m_sName);
2384 break;
2385 default:
2387 if (cmd < IDSVNLC_MOVETOCS)
2388 break;
2389 CTSVNPathList changelistItems;
2390 FillListOfSelectedItemPaths(changelistItems);
2392 // find the changelist name
2393 CString sChangelist;
2394 int cmdID = IDSVNLC_MOVETOCS;
2395 SetRedraw(FALSE);
2396 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
2398 if ((it->first.Compare(SVNSLC_IGNORECHANGELIST))&&(entry->changelist.Compare(it->first)))
2400 if (cmd == cmdID)
2402 sChangelist = it->first;
2404 cmdID++;
2407 if (!sChangelist.IsEmpty())
2409 SVN git;
2410 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
2412 // The changelists were moved, but we now need to run through the selected items again
2413 // and update their changelist
2414 POSITION pos = GetFirstSelectedItemPosition();
2415 int index;
2416 while ((index = GetNextSelectedItem(pos)) >= 0)
2418 FileEntry * e = GetListEntry(index);
2419 e->changelist = sChangelist;
2420 if (!e->IsFolder())
2422 if (m_changelists.find(e->changelist)!=m_changelists.end())
2423 SetItemGroup(index, m_changelists[e->changelist]);
2424 else
2425 SetItemGroup(index, 0);
2429 else
2431 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
2434 SetRedraw(TRUE);
2436 break;
2437 #endif
2439 } // switch (cmd)
2440 m_bBlock = FALSE;
2441 AfxGetApp()->DoWaitCursor(-1);
2442 GetStatisticsString();
2443 //int iItemCountAfterMenuCmd = GetItemCount();
2444 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
2446 // CWnd* pParent = GetParent();
2447 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2448 // {
2449 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
2450 // }
2452 } // if (popup.CreatePopupMenu())
2453 } // if (selIndex >= 0)
2457 void CGitStatusListCtrl::OnContextMenuHeader(CWnd * pWnd, CPoint point)
2459 Locker lock(m_critSec);
2460 m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
2463 void CGitStatusListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
2466 if (pWnd == this)
2468 OnContextMenuList(pWnd, point);
2469 } // if (pWnd == this)
2470 else if (pWnd == GetHeaderCtrl())
2472 OnContextMenuHeader(pWnd, point);
2476 void CGitStatusListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
2479 Locker lock(m_critSec);
2480 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2481 *pResult = 0;
2482 if (m_bBlock)
2483 return;
2485 if (pNMLV->iItem < 0)
2487 if (!IsGroupViewEnabled())
2488 return;
2489 POINT pt;
2490 DWORD ptW = GetMessagePos();
2491 pt.x = GET_X_LPARAM(ptW);
2492 pt.y = GET_Y_LPARAM(ptW);
2493 ScreenToClient(&pt);
2494 int group = GetGroupFromPoint(&pt);
2495 if (group < 0)
2496 return;
2497 // check/uncheck the whole group depending on the check-state
2498 // of the first item in the group
2499 m_bBlock = true;
2500 bool bCheck = false;
2501 bool bFirst = false;
2502 LVITEM lv;
2503 for (int i=0; i<GetItemCount(); ++i)
2505 SecureZeroMemory(&lv, sizeof(LVITEM));
2506 lv.mask = LVIF_GROUPID;
2507 lv.iItem = i;
2508 GetItem(&lv);
2509 if (lv.iGroupId == group)
2511 CTGitPath *entry=(CTGitPath*)GetItemData(i);
2513 if (!bFirst)
2515 bCheck = !GetCheck(i);
2516 bFirst = true;
2518 if (entry)
2520 bool bOldCheck = !!GetCheck(i);
2521 SetEntryCheck(entry, i, bCheck);
2522 if (bCheck != bOldCheck)
2524 if (bCheck)
2525 m_nSelected++;
2526 else
2527 m_nSelected--;
2532 GetStatisticsString();
2533 m_bBlock = false;
2534 NotifyCheck();
2535 return;
2538 CTGitPath *file=(CTGitPath*)GetItemData(pNMLV->iItem);
2540 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER) {
2541 OpenFile(file, OPEN);
2542 return;
2544 if( file->m_Action&CTGitPath::LOGACTIONS_UNMERGED )
2546 if (CAppUtils::ConflictEdit(*file, false, m_bIsRevertTheirMy))
2548 CString conflictedFile = g_Git.m_CurrentDir + _T("\\") + file->GetWinPathString();
2549 if (!PathFileExists(conflictedFile) && NULL != GetLogicalParent() && NULL != GetLogicalParent()->GetSafeHwnd())
2550 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2553 else
2555 if( (!m_Rev1.IsEmpty()) || (!m_Rev1.IsEmpty())) // m_Rev1 twice???
2556 StartDiffTwo(pNMLV->iItem);
2557 else
2558 StartDiff(pNMLV->iItem);
2562 void CGitStatusListCtrl::StartDiffTwo(int fileindex)
2564 if(fileindex<0)
2565 return;
2567 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
2569 CGitDiff::Diff(&file1,&file1,
2570 m_Rev1,
2571 m_Rev2);
2574 void CGitStatusListCtrl::StartDiffWC(int fileindex)
2576 if(fileindex<0)
2577 return;
2579 CString Ver;
2580 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
2581 return;
2583 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
2585 CGitDiff::Diff(&file1,&file1, GIT_REV_ZERO, m_CurrentVersion);
2589 void CGitStatusListCtrl::StartDiff(int fileindex)
2591 if(fileindex<0)
2592 return;
2594 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
2595 CTGitPath file2;
2596 if(file1.m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
2598 file2.SetFromGit(file1.GetGitOldPathString());
2600 else
2602 file2=file1;
2605 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
2607 CString fromwhere;
2608 if(m_amend && (file1.m_Action & CTGitPath::LOGACTIONS_ADDED) == 0)
2609 fromwhere = _T("~1");
2610 if( g_Git.IsInitRepos())
2611 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
2612 GIT_REV_ZERO);
2613 else if( file1.m_Action&CTGitPath::LOGACTIONS_ADDED )
2614 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
2615 m_CurrentVersion+fromwhere,true);
2616 else if( file1.m_Action&CTGitPath::LOGACTIONS_DELETED )
2617 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
2618 GitRev::GetHead()+fromwhere,false);
2619 else
2620 CGitDiff::Diff(&file1,&file2,
2621 CString(GIT_REV_ZERO),
2622 GitRev::GetHead()+fromwhere);
2624 else
2626 GitRev rev;
2627 CString fromwhere = m_CurrentVersion+_T("~1");
2628 if(m_amend)
2629 fromwhere = m_CurrentVersion+_T("~2");
2630 if (rev.GetCommit(fromwhere) || (file1.m_Action & file1.LOGACTIONS_ADDED))
2632 CGitDiff::DiffNull(&file1,m_CurrentVersion,true);
2635 else if (file1.m_Action & file1.LOGACTIONS_DELETED)
2637 if (file1.m_ParentNo > 0)
2638 fromwhere.Format(_T("%s^%d"), m_CurrentVersion, file1.m_ParentNo + 1);
2640 CGitDiff::DiffNull(&file1,fromwhere,false);
2642 else
2644 if( file1.m_ParentNo & MERGE_MASK)
2647 CTGitPath base, theirs, mine, merge;
2649 CString temppath;
2650 GetTempPath(temppath);
2651 temppath.TrimRight(_T("\\"));
2653 mine.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".LOCAL") + file1.GetFileExtension());
2654 theirs.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".REMOTE") + file1.GetFileExtension());
2655 base.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".BASE") + file1.GetFileExtension());
2657 CFile tempfile;
2658 //create a empty file, incase stage is not three
2659 tempfile.Open(mine.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
2660 tempfile.Close();
2661 tempfile.Open(theirs.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
2662 tempfile.Close();
2663 tempfile.Open(base.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
2664 tempfile.Close();
2666 merge.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".Merged") + file1.GetFileExtension());
2668 int parent1=-1, parent2 =-1;
2669 for(int i=0;i<this->m_arStatusArray.size();i++)
2671 if(m_arStatusArray[i]->GetGitPathString() == file1.GetGitPathString())
2673 if(m_arStatusArray[i]->m_ParentNo & MERGE_MASK)
2676 else
2678 if(parent1<0)
2680 parent1 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
2682 else if (parent2 <0)
2684 parent2 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
2690 if(g_Git.GetOneFile(m_CurrentVersion, file1, (CString&)merge.GetWinPathString()))
2692 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2695 if(parent1>=0)
2697 CString str;
2698 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent1+1);
2700 if(g_Git.GetOneFile(str, file1, (CString&)mine.GetWinPathString()))
2702 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2706 if(parent2>=0)
2708 CString str;
2709 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent2+1);
2711 if(g_Git.GetOneFile(str, file1, (CString&)theirs.GetWinPathString()))
2713 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2717 if(parent1>=0 && parent2>=0)
2719 CString cmd, output;
2720 cmd.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion, parent1+1,
2721 this->m_CurrentVersion,parent2+1);
2723 if (g_Git.Run(cmd, &output, NULL, CP_UTF8))
2726 else
2728 if(g_Git.GetOneFile(output.Left(40), file1, (CString&)base.GetWinPathString()))
2730 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETBASEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2734 CAppUtils::StartExtMerge(base, theirs, mine, merge,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
2737 else
2739 CString str;
2740 if( (file1.m_ParentNo&PARENT_MASK) == 0)
2742 str = _T("~1");
2744 else
2746 str.Format(_T("^%d"), (file1.m_ParentNo&PARENT_MASK)+1);
2748 CGitDiff::Diff(&file1,&file2,
2749 m_CurrentVersion,
2750 m_CurrentVersion+str);
2756 CString CGitStatusListCtrl::GetStatisticsString(bool simple)
2759 CString sNormal, sAdded, sDeleted, sModified, sConflicted, sUnversioned, sRenamed;
2760 WORD langID = (WORD)(DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
2761 TCHAR buf[MAX_STATUS_STRING_LENGTH];
2762 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal, buf, _countof(buf), langID);
2763 sNormal = buf;
2764 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added, buf, _countof(buf), langID);
2765 sAdded = buf;
2766 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted, buf, _countof(buf), langID);
2767 sDeleted = buf;
2768 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified, buf, _countof(buf), langID);
2769 sModified = buf;
2770 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted, buf, _countof(buf), langID);
2771 sConflicted = buf;
2772 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned, buf, _countof(buf), langID);
2773 sUnversioned = buf;
2774 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced, buf, _countof(buf), langID);
2775 sRenamed = buf;
2776 CString sToolTip;
2777 if(simple)
2779 sToolTip.Format(IDS_STATUSLIST_STATUSLINE1,
2780 this->m_nLineAdded,this->m_nLineDeleted,
2781 (LPCTSTR)sModified, m_nModified,
2782 (LPCTSTR)sAdded, m_nAdded,
2783 (LPCTSTR)sDeleted, m_nDeleted,
2784 (LPCTSTR)sRenamed, m_nRenamed
2787 else
2789 sToolTip.Format(IDS_STATUSLIST_STATUSLINE2,
2790 this->m_nLineAdded,this->m_nLineDeleted,
2791 (LPCTSTR)sNormal, m_nNormal,
2792 (LPCTSTR)sUnversioned, m_nUnversioned,
2793 (LPCTSTR)sModified, m_nModified,
2794 (LPCTSTR)sAdded, m_nAdded,
2795 (LPCTSTR)sDeleted, m_nDeleted,
2796 (LPCTSTR)sConflicted, m_nConflicted
2799 CString sStats;
2800 sStats.Format(IDS_COMMITDLG_STATISTICSFORMAT, m_nSelected, GetItemCount());
2801 if (m_pStatLabel)
2803 m_pStatLabel->SetWindowText(sStats);
2806 if (m_pSelectButton)
2808 if (m_nSelected == 0)
2809 m_pSelectButton->SetCheck(BST_UNCHECKED);
2810 else if (m_nSelected != GetItemCount())
2811 m_pSelectButton->SetCheck(BST_INDETERMINATE);
2812 else
2813 m_pSelectButton->SetCheck(BST_CHECKED);
2816 if (m_pConfirmButton)
2818 m_pConfirmButton->EnableWindow(m_nSelected>0);
2821 return sToolTip;
2826 CString CGitStatusListCtrl::GetCommonDirectory(bool bStrict)
2828 if (!bStrict)
2830 // not strict means that the selected folder has priority
2831 if (!m_StatusFileList.GetCommonDirectory().IsEmpty())
2832 return m_StatusFileList.GetCommonDirectory().GetWinPath();
2835 CTGitPath commonBaseDirectory;
2836 int nListItems = GetItemCount();
2837 for (int i=0; i<nListItems; ++i)
2839 CTGitPath baseDirectory,*p= (CTGitPath*)this->GetItemData(i);
2840 ASSERT(p);
2841 if(p==NULL)
2842 continue;
2843 baseDirectory = p->GetDirectory();
2845 if(commonBaseDirectory.IsEmpty())
2847 commonBaseDirectory = baseDirectory;
2849 else
2851 if (commonBaseDirectory.GetWinPathString().GetLength() > baseDirectory.GetWinPathString().GetLength())
2853 if (baseDirectory.IsAncestorOf(commonBaseDirectory))
2854 commonBaseDirectory = baseDirectory;
2858 return g_Git.m_CurrentDir+CString(_T("\\"))+commonBaseDirectory.GetWinPath();
2862 void CGitStatusListCtrl::SelectAll(bool bSelect, bool /*bIncludeNoCommits*/)
2864 CWaitCursor waitCursor;
2865 // block here so the LVN_ITEMCHANGED messages
2866 // get ignored
2867 m_bBlock = TRUE;
2868 SetRedraw(FALSE);
2870 int nListItems = GetItemCount();
2871 if (bSelect)
2872 m_nSelected = nListItems;
2873 else
2874 m_nSelected = 0;
2876 for (int i=0; i<nListItems; ++i)
2878 //FileEntry * entry = GetListEntry(i);
2879 //ASSERT(entry != NULL);
2880 CTGitPath *path = (CTGitPath *) GetItemData(i);
2881 if (path == NULL)
2882 continue;
2883 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
2884 SetEntryCheck(path,i,bSelect);
2887 // unblock before redrawing
2888 m_bBlock = FALSE;
2889 SetRedraw(TRUE);
2890 GetStatisticsString();
2891 NotifyCheck();
2894 void CGitStatusListCtrl::Check(DWORD dwCheck, bool check)
2896 CWaitCursor waitCursor;
2897 // block here so the LVN_ITEMCHANGED messages
2898 // get ignored
2899 m_bBlock = TRUE;
2900 SetRedraw(FALSE);
2902 int nListItems = GetItemCount();
2904 for (int i = 0; i < nListItems; ++i)
2906 CTGitPath *entry = (CTGitPath *) GetItemData(i);
2907 if (entry == NULL)
2908 continue;
2910 DWORD showFlags = entry->m_Action;
2911 if (entry->IsDirectory())
2912 showFlags |= GITSLC_SHOWSUBMODULES;
2913 else
2914 showFlags |= GITSLC_SHOWFILES;
2916 if (check && (showFlags & dwCheck) && !GetCheck(i) && !(entry->IsDirectory() && m_bDoNotAutoselectSubmodules && !(dwCheck & GITSLC_SHOWSUBMODULES)))
2918 SetEntryCheck(entry, i, true);
2919 m_nSelected++;
2921 else if (!check && (showFlags & dwCheck) && GetCheck(i))
2923 SetEntryCheck(entry, i, false);
2924 m_nSelected--;
2927 // unblock before redrawing
2928 m_bBlock = FALSE;
2929 SetRedraw(TRUE);
2930 GetStatisticsString();
2931 NotifyCheck();
2934 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)
2936 LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);
2937 *pResult = 0;
2938 if (m_bBlock)
2939 return;
2941 CTGitPath *entry=(CTGitPath *)GetItemData(pGetInfoTip->iItem);
2943 if (entry)
2944 if (pGetInfoTip->cchTextMax > entry->GetGitPathString().GetLength() + g_Git.m_CurrentDir.GetLength())
2946 CString str;
2947 str += g_Git.m_CurrentDir;
2948 str += _T("\\");
2949 str += entry->GetWinPathString();
2951 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, str.GetBuffer(), str.GetLength());
2955 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
2957 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
2959 // Take the default processing unless we set this to something else below.
2960 *pResult = CDRF_DODEFAULT;
2962 // First thing - check the draw stage. If it's the control's prepaint
2963 // stage, then tell Windows we want messages for every item.
2965 switch (pLVCD->nmcd.dwDrawStage)
2967 case CDDS_PREPAINT:
2968 *pResult = CDRF_NOTIFYITEMDRAW;
2969 break;
2970 case CDDS_ITEMPREPAINT:
2972 // This is the prepaint stage for an item. Here's where we set the
2973 // item's text color. Our return value will tell Windows to draw the
2974 // item itself, but it will use the new color we set here.
2976 // Tell Windows to paint the control itself.
2977 *pResult = CDRF_DODEFAULT;
2978 if (m_bBlock)
2979 return;
2981 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
2983 if (m_arStatusArray.size() > (DWORD_PTR)pLVCD->nmcd.dwItemSpec)
2986 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
2987 CTGitPath *entry=(CTGitPath *)GetItemData((int)pLVCD->nmcd.dwItemSpec);
2988 if (entry == NULL)
2989 return;
2991 // coloring
2992 // ========
2993 // black : unversioned, normal
2994 // purple : added
2995 // blue : modified
2996 // brown : missing, deleted, replaced
2997 // green : merged (or potential merges)
2998 // red : conflicts or sure conflicts
2999 if(entry->m_Action & CTGitPath::LOGACTIONS_GRAY)
3001 crText = RGB(128,128,128);
3004 else if(entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
3006 crText = m_Colors.GetColor(CColors::Conflict);
3009 else if(entry->m_Action & (CTGitPath::LOGACTIONS_MODIFIED))
3011 crText = m_Colors.GetColor(CColors::Modified);
3014 else if(entry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
3016 crText = m_Colors.GetColor(CColors::Added);
3018 else if(entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
3020 crText = m_Colors.GetColor(CColors::DeletedNode);
3022 else if(entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
3024 crText = m_Colors.GetColor(CColors::RenamedNode);
3026 else if(entry->m_Action & CTGitPath::LOGACTIONS_MERGED)
3028 crText = m_Colors.GetColor(CColors::Merged);
3030 else
3032 crText = GetSysColor(COLOR_WINDOWTEXT);
3034 // Store the color back in the NMLVCUSTOMDRAW struct.
3035 pLVCD->clrText = crText;
3038 break;
3042 BOOL CGitStatusListCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
3044 if (pWnd != this)
3045 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
3046 if (!m_bBlock)
3048 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
3049 SetCursor(hCur);
3050 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
3052 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
3053 SetCursor(hCur);
3054 return TRUE;
3057 void CGitStatusListCtrl::RemoveListEntry(int index)
3060 Locker lock(m_critSec);
3061 DeleteItem(index);
3063 m_arStatusArray.erase(m_arStatusArray.begin()+index);
3065 #if 0
3066 delete m_arStatusArray[m_arListArray[index]];
3067 m_arStatusArray.erase(m_arStatusArray.begin()+m_arListArray[index]);
3068 m_arListArray.erase(m_arListArray.begin()+index);
3069 for (int i=index; i< (int)m_arListArray.size(); ++i)
3071 m_arListArray[i]--;
3073 #endif
3076 ///< Set a checkbox on an entry in the listbox
3077 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
3078 void CGitStatusListCtrl::SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck)
3080 pEntry->m_Checked = bCheck;
3081 m_mapFilenameToChecked[pEntry->GetGitPathString()] = bCheck;
3082 SetCheck(listboxIndex, bCheck);
3085 #if 0
3086 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck)
3089 int nListItems = GetItemCount();
3090 for (int j=0; j< nListItems ; ++j)
3092 FileEntry * childEntry = GetListEntry(j);
3093 ASSERT(childEntry != NULL);
3094 if (childEntry == NULL || childEntry == parentEntry)
3095 continue;
3096 if (childEntry->checked != bCheck)
3098 if (parentEntry->path.IsAncestorOf(childEntry->path))
3100 SetEntryCheck(childEntry,j,bCheck);
3101 if(bCheck)
3103 m_nSelected++;
3105 else
3107 m_nSelected--;
3114 #endif
3116 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList& pathList)
3119 pathList.Clear();
3120 int nListItems = GetItemCount();
3121 for (int i=0; i< nListItems; i++)
3123 CTGitPath * entry = (CTGitPath*)GetItemData(i);
3124 ASSERT(entry != NULL);
3125 if (entry->m_Checked)
3127 pathList.AddPath(*entry);
3130 pathList.SortByPathname();
3135 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
3136 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList& pathList, bool /*bNoIgnored*/)
3138 pathList.Clear();
3140 POSITION pos = GetFirstSelectedItemPosition();
3141 int index;
3142 while ((index = GetNextSelectedItem(pos)) >= 0)
3144 CTGitPath * entry = (CTGitPath*)GetItemData(index);
3145 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
3146 // continue;
3147 pathList.AddPath(*entry);
3151 UINT CGitStatusListCtrl::OnGetDlgCode()
3153 // we want to process the return key and not have that one
3154 // routed to the default pushbutton
3155 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS;
3158 void CGitStatusListCtrl::OnNMReturn(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3160 *pResult = 0;
3161 if (m_bBlock)
3162 return;
3163 POSITION pos = GetFirstSelectedItemPosition();
3164 while ( pos )
3166 int index = GetNextSelectedItem(pos);
3167 CTGitPath *file=(CTGitPath*)GetItemData(index);
3168 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER)
3170 OpenFile(file, OPEN);
3172 else
3174 if( (!m_Rev1.IsEmpty()) || (!m_Rev1.IsEmpty())) // m_Rev1 twice???
3175 StartDiffTwo(index);
3176 else
3177 StartDiff(index);
3182 void CGitStatusListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
3184 // Since we catch all keystrokes (to have the enter key processed here instead
3185 // of routed to the default pushbutton) we have to make sure that other
3186 // keys like Tab and Esc still do what they're supposed to do
3187 // Tab = change focus to next/previous control
3188 // Esc = quit the dialog
3189 switch (nChar)
3191 case (VK_TAB):
3193 ::PostMessage(GetLogicalParent()->GetSafeHwnd(), WM_NEXTDLGCTL, GetKeyState(VK_SHIFT)&0x8000, 0);
3194 return;
3196 break;
3197 case (VK_ESCAPE):
3199 ::SendMessage(GetLogicalParent()->GetSafeHwnd(), WM_CLOSE, 0, 0);
3201 break;
3204 CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
3207 void CGitStatusListCtrl::PreSubclassWindow()
3209 CListCtrl::PreSubclassWindow();
3210 EnableToolTips(TRUE);
3211 SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);
3214 INT_PTR CGitStatusListCtrl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
3216 int row, col;
3217 RECT cellrect;
3218 row = CellRectFromPoint(point, &cellrect, &col );
3220 if (row == -1)
3221 return -1;
3224 pTI->hwnd = m_hWnd;
3225 pTI->uId = (UINT)((row<<10)+(col&0x3ff)+1);
3226 pTI->lpszText = LPSTR_TEXTCALLBACK;
3228 pTI->rect = cellrect;
3230 return pTI->uId;
3233 int CGitStatusListCtrl::CellRectFromPoint(CPoint& point, RECT *cellrect, int *col) const
3235 int colnum;
3237 // Make sure that the ListView is in LVS_REPORT
3238 if ((GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
3239 return -1;
3241 // Get the top and bottom row visible
3242 int row = GetTopIndex();
3243 int bottom = row + GetCountPerPage();
3244 if (bottom > GetItemCount())
3245 bottom = GetItemCount();
3247 // Get the number of columns
3248 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
3249 int nColumnCount = pHeader->GetItemCount();
3251 // Loop through the visible rows
3252 for ( ;row <=bottom;row++)
3254 // Get bounding rect of item and check whether point falls in it.
3255 CRect rect;
3256 GetItemRect(row, &rect, LVIR_BOUNDS);
3257 if (rect.PtInRect(point))
3259 // Now find the column
3260 for (colnum = 0; colnum < nColumnCount; colnum++)
3262 int colwidth = GetColumnWidth(colnum);
3263 if (point.x >= rect.left && point.x <= (rect.left + colwidth))
3265 RECT rectClient;
3266 GetClientRect(&rectClient);
3267 if (col)
3268 *col = colnum;
3269 rect.right = rect.left + colwidth;
3271 // Make sure that the right extent does not exceed
3272 // the client area
3273 if (rect.right > rectClient.right)
3274 rect.right = rectClient.right;
3275 *cellrect = rect;
3276 return row;
3278 rect.left += colwidth;
3282 return -1;
3285 void CGitStatusListCtrl::OnPaint()
3287 Default();
3288 if ((m_bBusy)||(m_bEmpty))
3290 CString str;
3291 if (m_bBusy)
3293 if (m_sBusy.IsEmpty())
3294 str.LoadString(IDS_STATUSLIST_BUSYMSG);
3295 else
3296 str = m_sBusy;
3298 else
3300 if (m_sEmpty.IsEmpty())
3301 str.LoadString(IDS_STATUSLIST_EMPTYMSG);
3302 else
3303 str = m_sEmpty;
3305 COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
3306 COLORREF clrTextBk;
3307 if (IsWindowEnabled())
3308 clrTextBk = ::GetSysColor(COLOR_WINDOW);
3309 else
3310 clrTextBk = ::GetSysColor(COLOR_3DFACE);
3312 CRect rc;
3313 GetClientRect(&rc);
3314 CHeaderCtrl* pHC;
3315 pHC = GetHeaderCtrl();
3316 if (pHC != NULL)
3318 CRect rcH;
3319 pHC->GetItemRect(0, &rcH);
3320 rc.top += rcH.bottom;
3322 CDC* pDC = GetDC();
3324 CMyMemDC memDC(pDC, &rc);
3326 memDC.SetTextColor(clrText);
3327 memDC.SetBkColor(clrTextBk);
3328 memDC.FillSolidRect(rc, clrTextBk);
3329 rc.top += 10;
3330 CGdiObject * oldfont = memDC.SelectStockObject(DEFAULT_GUI_FONT);
3331 memDC.DrawText(str, rc, DT_CENTER | DT_VCENTER |
3332 DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
3333 memDC.SelectObject(oldfont);
3335 ReleaseDC(pDC);
3339 // prevent users from extending our hidden (size 0) columns
3340 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3342 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3345 // prevent any function from extending our hidden (size 0) columns
3346 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3348 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3349 Default();
3352 void CGitStatusListCtrl::OnDestroy()
3354 SaveColumnWidths(true);
3355 CListCtrl::OnDestroy();
3358 void CGitStatusListCtrl::OnBeginDrag(NMHDR* /*pNMHDR*/, LRESULT* pResult)
3360 #if 0
3361 Locker lock(m_critSec);
3362 CDropFiles dropFiles; // class for creating DROPFILES struct
3364 int index;
3365 POSITION pos = GetFirstSelectedItemPosition();
3366 while ( (index = GetNextSelectedItem(pos)) >= 0 )
3368 FileEntry * fentry = m_arStatusArray[m_arListArray[index]];
3369 CTGitPath path = fentry->GetPath();
3370 dropFiles.AddFile( path.GetWinPathString() );
3373 if ( dropFiles.GetCount()>0 )
3375 m_bOwnDrag = true;
3376 dropFiles.CreateStructure();
3377 m_bOwnDrag = false;
3379 #endif
3380 *pResult = 0;
3383 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry /* = false */)
3385 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
3386 for (int col = 0; col <= maxcol; col++)
3387 if (m_ColumnManager.IsVisible (col))
3388 m_ColumnManager.ColumnResized (col);
3390 if (bSaveToRegistry)
3391 m_ColumnManager.WriteSettings();
3394 bool CGitStatusListCtrl::EnableFileDrop()
3396 m_bFileDropsEnabled = true;
3397 return true;
3400 bool CGitStatusListCtrl::HasPath(const CTGitPath& path)
3402 for (size_t i=0; i < m_arStatusArray.size(); i++)
3404 if (m_arStatusArray[i]->IsEquivalentTo(path))
3405 return true;
3408 return false;
3411 BOOL CGitStatusListCtrl::PreTranslateMessage(MSG* pMsg)
3413 if (pMsg->message == WM_KEYDOWN)
3415 switch (pMsg->wParam)
3417 case 'A':
3419 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
3421 // select all entries
3422 for (int i=0; i<GetItemCount(); ++i)
3424 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3426 return TRUE;
3429 break;
3430 case 'C':
3431 case VK_INSERT:
3433 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
3435 // copy all selected paths to the clipboard
3436 if (GetAsyncKeyState(VK_SHIFT)&0x8000)
3437 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS);
3438 else
3439 CopySelectedEntriesToClipboard(0);
3440 return TRUE;
3443 break;
3447 return CListCtrl::PreTranslateMessage(pMsg);
3450 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols)
3453 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
3454 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3456 CString sClipboard;
3457 CString temp;
3458 //TCHAR buf[100];
3459 if (GetSelectedCount() == 0)
3460 return false;
3462 // first add the column titles as the first line
3463 // We needn't head when only path copy
3464 //temp.LoadString(IDS_STATUSLIST_COLFILE);
3465 //sClipboard = temp;
3467 DWORD selection = 0;
3468 for (int i = 0, count = m_ColumnManager.GetColumnCount(); i < count; ++i)
3469 if ( ((dwCols == -1) && m_ColumnManager.IsVisible (i))
3470 || ((dwCols != 1) && (i < 32) && ((dwCols & (1 << i)) != 0)))
3472 sClipboard += _T("\t") + m_ColumnManager.GetName(i);
3474 if (i < 32)
3475 selection += 1 << i;
3478 if(dwCols)
3479 sClipboard += _T("\r\n");
3481 POSITION pos = GetFirstSelectedItemPosition();
3482 int index;
3483 while ((index = GetNextSelectedItem(pos)) >= 0)
3485 CTGitPath * entry = (CTGitPath*)GetItemData(index);
3486 if(entry == NULL)
3487 continue;
3489 sClipboard += entry->GetWinPathString();
3490 if (selection & GITSLC_COLFILENAME)
3492 sClipboard += _T("\t")+entry->GetFileOrDirectoryName();
3494 if (selection & GITSLC_COLEXT)
3496 sClipboard += _T("\t")+entry->GetFileExtension();
3499 if (selection & GITSLC_COLSTATUS)
3501 sClipboard += _T("\t")+entry->GetActionName();
3503 #if 0
3504 if (selection & SVNSLC_COLDATE)
3506 TCHAR datebuf[SVN_DATE_BUFFER];
3507 apr_time_t date = entry->last_commit_date;
3508 SVN::formatDate(datebuf, date, true);
3509 if (date)
3510 temp = datebuf;
3511 else
3512 temp.Empty();
3513 sClipboard += _T("\t")+temp;
3515 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
3516 ; i < count
3517 ; ++i)
3519 if ((dwCols == -1) && m_ColumnManager.IsVisible (i))
3521 CString value
3522 = entry->present_props[m_ColumnManager.GetName(i)];
3523 sClipboard += _T("\t") + value;
3526 #endif
3527 if (selection & GITSLC_COLADD)
3529 sClipboard += _T("\t")+entry->m_StatAdd;
3531 if (selection & GITSLC_COLDEL)
3533 sClipboard += _T("\t")+entry->m_StatDel;
3536 sClipboard += _T("\r\n");
3539 return CStringUtils::WriteAsciiStringToClipboard(sClipboard);
3542 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
3544 #if 0
3545 std::set<CString> changelists;
3546 POSITION pos = GetFirstSelectedItemPosition();
3547 int index;
3548 while ((index = GetNextSelectedItem(pos)) >= 0)
3550 FileEntry * entry = GetListEntry(index);
3551 if (!entry->changelist.IsEmpty())
3552 changelists.insert(entry->changelist);
3554 return changelists.size();
3555 #endif
3556 return 0;
3559 bool CGitStatusListCtrl::PrepareGroups(bool bForce /* = false */)
3562 bool bHasGroups=false;
3563 int max =0;
3565 for(int i=0;i< this->m_arStatusArray.size(); i++)
3567 int ParentNo = m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
3568 if( ParentNo > max)
3569 max=m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
3572 if ( this->m_UnRevFileList.GetCount()>0 ||
3573 this->m_IgnoreFileList.GetCount()>0 ||
3574 max>0 || bForce)
3576 bHasGroups = true;
3579 RemoveAllGroups();
3580 EnableGroupView(bHasGroups);
3582 TCHAR groupname[1024];
3583 int groupindex = 0;
3585 if(bHasGroups)
3587 LVGROUP grp = {0};
3588 grp.cbSize = sizeof(LVGROUP);
3589 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3590 groupindex=0;
3592 //if(m_UnRevFileList.GetCount()>0)
3593 if(max >0)
3595 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MERGEDFILES)), 1023);
3596 grp.pszHeader = groupname;
3597 grp.iGroupId = MERGE_MASK;
3598 grp.uAlign = LVGA_HEADER_LEFT;
3599 InsertGroup(0, &grp);
3601 for(int i=0;i<=max;i++)
3603 CString str;
3604 str.Format(IDS_STATUSLIST_GROUP_DIFFWITHPARENT, i+1);
3605 grp.pszHeader = str.GetBuffer();
3606 str.ReleaseBuffer();
3607 grp.iGroupId = i;
3608 grp.uAlign = LVGA_HEADER_LEFT;
3609 InsertGroup(i+1, &grp);
3612 else
3614 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MODIFIEDFILES)), 1023);
3615 grp.pszHeader = groupname;
3616 grp.iGroupId = groupindex;
3617 grp.uAlign = LVGA_HEADER_LEFT;
3618 InsertGroup(groupindex++, &grp);
3622 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_NOTVERSIONEDFILES)), 1023);
3623 grp.pszHeader = groupname;
3624 grp.iGroupId = groupindex;
3625 grp.uAlign = LVGA_HEADER_LEFT;
3626 InsertGroup(groupindex++, &grp);
3629 //if(m_IgnoreFileList.GetCount()>0)
3631 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNOREDFILES)), 1023);
3632 grp.pszHeader = groupname;
3633 grp.iGroupId = groupindex;
3634 grp.uAlign = LVGA_HEADER_LEFT;
3635 InsertGroup(groupindex++, &grp);
3640 #if 0
3641 m_bHasIgnoreGroup = false;
3643 // now add the items which don't belong to a group
3644 LVGROUP grp = {0};
3645 grp.cbSize = sizeof(LVGROUP);
3646 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3647 CString sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET));
3648 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
3649 grp.pszHeader = groupname;
3650 grp.iGroupId = groupindex;
3651 grp.uAlign = LVGA_HEADER_LEFT;
3652 InsertGroup(groupindex++, &grp);
3654 for (std::map<CString,int>::iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
3656 if (it->first.Compare(SVNSLC_IGNORECHANGELIST)!=0)
3658 LVGROUP grp = {0};
3659 grp.cbSize = sizeof(LVGROUP);
3660 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3661 _tcsncpy_s(groupname, 1024, it->first, 1023);
3662 grp.pszHeader = groupname;
3663 grp.iGroupId = groupindex;
3664 grp.uAlign = LVGA_HEADER_LEFT;
3665 it->second = InsertGroup(groupindex++, &grp);
3667 else
3668 m_bHasIgnoreGroup = true;
3671 if (m_bHasIgnoreGroup)
3673 // and now add the group 'ignore-on-commit'
3674 std::map<CString,int>::iterator it = m_changelists.find(SVNSLC_IGNORECHANGELIST);
3675 if (it != m_changelists.end())
3677 grp.cbSize = sizeof(LVGROUP);
3678 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3679 _tcsncpy_s(groupname, 1024, SVNSLC_IGNORECHANGELIST, 1023);
3680 grp.pszHeader = groupname;
3681 grp.iGroupId = groupindex;
3682 grp.uAlign = LVGA_HEADER_LEFT;
3683 it->second = InsertGroup(groupindex, &grp);
3686 #endif
3687 return bHasGroups;
3690 void CGitStatusListCtrl::NotifyCheck()
3692 CWnd* pParent = GetLogicalParent();
3693 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3695 pParent->SendMessage(GITSLNM_CHECKCHANGED, m_nSelected);
3699 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash,CTGitPathList *list)
3701 BYTE_VECTOR out;
3702 this->m_bBusy=TRUE;
3703 m_CurrentVersion=hash;
3705 int count = 0;
3706 if(list == NULL)
3707 count = 1;
3708 else
3709 count = list->GetCount();
3711 CString head = _T("HEAD");
3712 if(m_amend)
3713 head = _T("HEAD~1");
3715 if(hash == GIT_REV_ZERO)
3717 for(int i=0;i<count;i++)
3719 BYTE_VECTOR cmdout;
3720 cmdout.clear();
3721 CString cmd;
3722 if(!g_Git.IsInitRepos())
3724 // also list staged files which will be in the commit
3725 cmd=(_T("git.exe diff-index --cached --raw ") + head + _T(" --numstat -C -M -z"));
3726 g_Git.Run(cmd, &cmdout);
3728 if(list == NULL)
3729 cmd=(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z"));
3730 else
3731 cmd.Format(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
3733 BYTE_VECTOR cmdErr;
3734 if(g_Git.Run(cmd, &cmdout, &cmdErr))
3736 int last = cmdErr.RevertFind(0,-1);
3737 CString str;
3738 g_Git.StringAppend(&str, &cmdErr[last + 1], CP_UTF8, (int)cmdErr.size() - last -1);
3739 CMessageBox::Show(NULL, str, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
3742 out.append(cmdout, 0);
3744 else // Init Repository
3746 //We will list all added file for init repository because commit will comit these
3747 //if(list == NULL)
3748 cmd=_T("git.exe ls-files -s -t -z");
3749 //else
3750 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
3752 g_Git.Run(cmd, &cmdout);
3753 //out+=cmdout;
3754 out.append(cmdout,0);
3758 if(g_Git.IsInitRepos())
3760 m_StatusFileList.ParserFromLsFile(out);
3761 for(int i=0;i<m_StatusFileList.GetCount();i++)
3762 ((CTGitPath&)(m_StatusFileList[i])).m_Action=CTGitPath::LOGACTIONS_ADDED;
3764 else
3765 this->m_StatusFileList.ParserFromLog(out);
3767 //handle delete conflict case, when remote : modified, local : deleted.
3768 for(int i=0;i<count;i++)
3770 BYTE_VECTOR cmdout;
3771 CString cmd;
3773 if(list == NULL)
3774 cmd=_T("git.exe ls-files -u -t -z");
3775 else
3776 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list)[i].GetGitPathString());
3778 g_Git.Run(cmd, &cmdout);
3780 CTGitPathList conflictlist;
3781 conflictlist.ParserFromLog(cmdout);
3782 for(int i=0;i<conflictlist.GetCount();i++)
3784 CTGitPath *p=m_StatusFileList.LookForGitPath(conflictlist[i].GetGitPathString());
3785 if(p)
3786 p->m_Action|=CTGitPath::LOGACTIONS_UNMERGED;
3787 else
3788 m_StatusFileList.AddPath(conflictlist[i]);
3792 // handle source files of file renames/moves (issue #860)
3793 // if a file gets renamed and the new file "git add"ed, diff-index doesn't list the source file anymore
3794 for(int i = 0; i < count; i++)
3796 BYTE_VECTOR cmdout;
3797 CString cmd;
3799 if(list == NULL)
3800 cmd = _T("git.exe ls-files -d -z");
3801 else
3802 cmd.Format(_T("git.exe ls-files -d -z -- \"%s\""),(*list)[i].GetGitPathString());
3804 g_Git.Run(cmd, &cmdout);
3806 CTGitPathList deletelist;
3807 deletelist.ParserFromLog(cmdout, true);
3808 for(int i = 0; i < deletelist.GetCount(); i++)
3810 CTGitPath *p = m_StatusFileList.LookForGitPath(deletelist[i].GetGitPathString());
3811 if(!p)
3812 m_StatusFileList.AddPath(deletelist[i]);
3813 else if ((p->m_Action == CTGitPath::LOGACTIONS_ADDED || p->m_Action == CTGitPath::LOGACTIONS_REPLACED) && !p->Exists())
3815 if (CMessageBox::Show(m_hWnd, _T("TortoiseGit detected that the file \"") + p->GetWinPathString() +_T("\" does not exist, but is staged as \"Added\".\nThe commit dialog cannot handle this.\n\nDo you want to remove it from the index?"), _T("TortoiseGit"), 1, IDI_EXCLAMATION, _T("&Remove file from index"), _T("&Ignore")) == 1)
3817 g_Git.Run(_T("git.exe rm -f --cache -- \"") + p->GetWinPathString() + _T("\""), &cmdout);
3818 m_StatusFileList.RemoveItem(*p);
3824 else
3826 int count = 0;
3827 if(list == NULL)
3828 count = 1;
3829 else
3830 count = list->GetCount();
3832 for(int i=0;i<count;i++)
3834 BYTE_VECTOR cmdout;
3835 CString cmd;
3836 if(list == NULL)
3837 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash);
3838 else
3839 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash,(*list)[i].GetGitPathString());
3841 g_Git.Run(cmd, &cmdout, NULL);
3843 out.append(cmdout);
3845 this->m_StatusFileList.ParserFromLog(out);
3849 for(int i=0;i<m_StatusFileList.GetCount();i++)
3851 CTGitPath * gitpatch=(CTGitPath*)&m_StatusFileList[i];
3852 gitpatch->m_Checked = TRUE;
3853 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
3856 this->m_bBusy=FALSE;
3857 return 0;
3860 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList &list)
3862 m_arStatusArray.clear();
3863 for(int i=0;i<list.GetCount();i++)
3865 CTGitPath * gitpath=(CTGitPath*)&list[i];
3867 if(gitpath ->m_Action & CTGitPath::LOGACTIONS_HIDE)
3868 continue;
3870 gitpath->m_Checked = TRUE;
3871 m_arStatusArray.push_back((CTGitPath*)&list[i]);
3873 return 0;
3876 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList &list)
3878 m_UnRevFileList = list;
3879 for(int i=0;i<m_UnRevFileList.GetCount();i++)
3881 CTGitPath * gitpatch=(CTGitPath*)&m_UnRevFileList[i];
3882 gitpatch->m_Checked = FALSE;
3883 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
3885 return 0;
3888 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList *List)
3890 this->m_UnRevFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER,List);
3891 for(int i=0;i<m_UnRevFileList.GetCount();i++)
3893 CTGitPath * gitpatch=(CTGitPath*)&m_UnRevFileList[i];
3894 gitpatch->m_Checked = FALSE;
3895 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
3897 return 0;
3900 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList *List)
3902 this->m_IgnoreFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER|CTGitPath::LOGACTIONS_IGNORE,List);
3903 for(int i=0;i<m_IgnoreFileList.GetCount();i++)
3905 CTGitPath * gitpatch=(CTGitPath*)&m_IgnoreFileList[i];
3906 gitpatch->m_Checked = FALSE;
3907 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
3909 return 0;
3911 int CGitStatusListCtrl::UpdateFileList(int mask,bool once,CTGitPathList *List)
3913 if(mask&CGitStatusListCtrl::FILELIST_MODIFY)
3915 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_MODIFY)))
3917 UpdateFileList(git_revnum_t(GIT_REV_ZERO),List);
3918 m_FileLoaded|=CGitStatusListCtrl::FILELIST_MODIFY;
3921 if(mask&CGitStatusListCtrl::FILELIST_UNVER)
3923 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_UNVER)))
3925 UpdateUnRevFileList(List);
3926 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
3928 if(mask&CGitStatusListCtrl::FILELIST_IGNORE && (once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_IGNORE))))
3930 UpdateIgnoreFileList(List);
3931 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
3934 return 0;
3937 void CGitStatusListCtrl::Clear()
3939 m_FileLoaded=0;
3940 this->DeleteAllItems();
3941 this->m_arListArray.clear();
3942 this->m_arStatusArray.clear();
3943 this->m_changelists.clear();
3945 //////////////////////////////////////////////////////////////////////////
3946 #if 0
3947 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD * /*pdwEffect*/, POINTL pt)
3949 if(pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
3951 HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
3952 if(hDrop != NULL)
3954 TCHAR szFileName[MAX_PATH];
3956 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
3958 POINT clientpoint;
3959 clientpoint.x = pt.x;
3960 clientpoint.y = pt.y;
3961 ScreenToClient(m_hTargetWnd, &clientpoint);
3962 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
3964 CTSVNPathList changelistItems;
3965 for(UINT i = 0; i < cFiles; ++i)
3967 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
3968 changelistItems.AddPath(CTSVNPath(szFileName));
3970 // find the changelist name
3971 CString sChangelist;
3972 LONG_PTR nGroup = m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint);
3973 for (std::map<CString, int>::iterator it = m_pSVNStatusListCtrl->m_changelists.begin(); it != m_pSVNStatusListCtrl->m_changelists.end(); ++it)
3974 if (it->second == nGroup)
3975 sChangelist = it->first;
3976 if (!sChangelist.IsEmpty())
3978 SVN git;
3979 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
3981 for (int l=0; l<changelistItems.GetCount(); ++l)
3983 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
3984 if (index >= 0)
3986 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
3987 if (e)
3989 e->changelist = sChangelist;
3990 if (!e->IsFolder())
3992 if (m_pSVNStatusListCtrl->m_changelists.find(e->changelist)!=m_pSVNStatusListCtrl->m_changelists.end())
3993 m_pSVNStatusListCtrl->SetItemGroup(index, m_pSVNStatusListCtrl->m_changelists[e->changelist]);
3994 else
3995 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
3999 else
4001 HWND hParentWnd = GetParent(m_hTargetWnd);
4002 if (hParentWnd != NULL)
4003 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
4007 else
4009 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
4012 else
4014 SVN git;
4015 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
4017 for (int l=0; l<changelistItems.GetCount(); ++l)
4019 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
4020 if (index >= 0)
4022 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
4023 if (e)
4025 e->changelist = sChangelist;
4026 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
4029 else
4031 HWND hParentWnd = GetParent(m_hTargetWnd);
4032 if (hParentWnd != NULL)
4033 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
4037 else
4039 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
4043 else
4045 for(UINT i = 0; i < cFiles; ++i)
4047 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
4048 HWND hParentWnd = GetParent(m_hTargetWnd);
4049 if (hParentWnd != NULL)
4050 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)szFileName);
4054 GlobalUnlock(medium.hGlobal);
4056 return true; //let base free the medium
4058 HRESULT STDMETHODCALLTYPE CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)
4060 CIDropTarget::DragOver(grfKeyState, pt, pdwEffect);
4061 *pdwEffect = DROPEFFECT_COPY;
4062 if (m_pSVNStatusListCtrl)
4064 POINT clientpoint;
4065 clientpoint.x = pt.x;
4066 clientpoint.y = pt.y;
4067 ScreenToClient(m_hTargetWnd, &clientpoint);
4068 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
4070 *pdwEffect = DROPEFFECT_MOVE;
4072 else if ((!m_pSVNStatusListCtrl->m_bFileDropsEnabled)||(m_pSVNStatusListCtrl->m_bOwnDrag))
4074 *pdwEffect = DROPEFFECT_NONE;
4077 return S_OK;
4080 #endif
4082 void CGitStatusListCtrl::FilesExport()
4084 CString exportDir;
4085 // export all changed files to a folder
4086 CBrowseFolder browseFolder;
4087 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
4088 if (browseFolder.Show(GetSafeHwnd(), exportDir) != CBrowseFolder::OK)
4089 return;
4091 POSITION pos = GetFirstSelectedItemPosition();
4092 int index;
4093 while ((index = GetNextSelectedItem(pos)) >= 0)
4095 CTGitPath *fd = (CTGitPath*)GetItemData(index);
4096 // we cannot export directories or folders
4097 if (fd->m_Action == CTGitPath::LOGACTIONS_DELETED || fd->IsDirectory())
4098 continue;
4100 CAppUtils::CreateMultipleDirectory(exportDir + _T("\\") + fd->GetDirectory().GetWinPathString());
4101 CString filename = exportDir + _T("\\") + fd->GetWinPathString();
4102 if (m_CurrentVersion == GIT_REV_ZERO)
4104 if (!CopyFile(g_Git.m_CurrentDir + _T("\\") + fd->GetWinPath(), filename, false))
4106 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
4107 return;
4110 else
4112 if (g_Git.GetOneFile(m_CurrentVersion, *fd, filename))
4114 CString out;
4115 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, fd->GetGitPathString(), m_CurrentVersion, filename);
4116 if (CMessageBox::Show(NULL, out, _T("TortoiseGit"), 2, IDI_WARNING, CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
4117 return;
4123 void CGitStatusListCtrl::FileSaveAs(CTGitPath *path)
4125 CString filename;
4126 filename.Format(_T("%s-%s%s"), path->GetBaseFilename(), this->m_CurrentVersion.Left(g_Git.GetShortHASHLength()), path->GetFileExtension());
4127 CFileDialog dlg(FALSE,NULL,
4128 filename,
4129 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
4130 NULL);
4131 CString currentpath;
4132 currentpath=g_Git.m_CurrentDir+_T("\\");
4133 currentpath+=path->GetWinPathString();
4135 dlg.m_ofn.lpstrInitialDir=currentpath.GetBuffer();
4137 CString cmd,out;
4138 INT_PTR ret = dlg.DoModal();
4139 SetCurrentDirectory(g_Git.m_CurrentDir);
4140 if (ret == IDOK)
4142 filename = dlg.GetPathName();
4143 if(m_CurrentVersion == GIT_REV_ZERO)
4145 if(!CopyFile(g_Git.m_CurrentDir +_T("\\") + path->GetWinPath(),filename,false))
4147 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
4148 return;
4152 else
4154 if(g_Git.GetOneFile(m_CurrentVersion,*path,filename))
4156 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path->GetGitPathString(), m_CurrentVersion, filename);
4157 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
4158 return;
4165 int CGitStatusListCtrl::RevertSelectedItemToVersion()
4167 if(this->m_CurrentVersion.IsEmpty())
4168 return 0;
4169 if(this->m_CurrentVersion == GIT_REV_ZERO)
4170 return 0;
4172 POSITION pos = GetFirstSelectedItemPosition();
4173 int index;
4174 CString cmd,out;
4175 int count =0;
4176 while ((index = GetNextSelectedItem(pos)) >= 0)
4178 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
4179 cmd.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion,fentry->GetGitPathString());
4180 out.Empty();
4181 if (g_Git.Run(cmd, &out, CP_UTF8))
4183 if (MessageBox(out, _T("TortoiseGit"), MB_ICONEXCLAMATION | MB_OKCANCEL) == IDCANCEL)
4184 break;
4186 else
4187 count++;
4190 out.Format(IDS_STATUSLIST_FILESREVERTED, count, m_CurrentVersion);
4191 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
4192 return 0;
4195 void CGitStatusListCtrl::OpenFile(CTGitPath*filepath,int mode)
4197 CString file;
4198 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
4200 file = g_Git.m_CurrentDir + _T("\\") + filepath->GetWinPath();
4202 else
4204 CString temppath;
4205 GetTempPath(temppath);
4206 TCHAR szTempName[MAX_PATH];
4207 GetTempFileName(temppath, filepath->GetBaseFilename(), 0, szTempName);
4208 CString temp(szTempName);
4209 DeleteFile(szTempName);
4210 CreateDirectory(szTempName, NULL);
4211 file.Format(_T("%s\\%s_%s%s"),
4212 temp,
4213 filepath->GetBaseFilename(),
4214 m_CurrentVersion.Left(g_Git.GetShortHASHLength()),
4215 filepath->GetFileExtension());
4216 CString cmd,out;
4217 if(g_Git.GetOneFile(m_CurrentVersion, *filepath, file))
4219 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, filepath->GetGitPathString(), m_CurrentVersion, file);
4220 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
4221 return;
4223 SetFileAttributes(file, FILE_ATTRIBUTE_READONLY);
4225 if(mode == ALTERNATIVEEDITOR)
4227 CAppUtils::LaunchAlternativeEditor(file);
4228 return;
4230 int ret = HINSTANCE_ERROR;
4232 if(mode == OPEN )
4234 ret = (int)ShellExecute(this->m_hWnd, NULL,file, NULL, NULL, SW_SHOW);
4236 if (ret > HINSTANCE_ERROR)
4238 return;
4243 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
4244 cmd += file;
4245 CAppUtils::LaunchApplication(cmd, NULL, false);