TortoiseGitPLink: Announce as TortoiseGitPLink instead of PuTTY
[TortoiseGit.git] / src / Git / GitStatusListCtrl.cpp
blob539d6d85b918885d84377dca7e781f335de052e8
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2003-2008, 2013 - 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);
235 if (pathList && m_mapDirectFiles.empty())
237 // remember files which are selected by users so that those can be preselected
238 for (int i = 0; i < pathList->GetCount(); ++i)
239 if (!(*pathList)[i].IsDirectory())
240 m_mapDirectFiles[(*pathList)[i].GetGitPathString()] = true;
243 #if 0
244 int refetchcounter = 0;
245 BOOL bRet = TRUE;
246 Invalidate();
247 // force the cursor to change
248 POINT pt;
249 GetCursorPos(&pt);
250 SetCursorPos(pt.x, pt.y);
252 m_mapFilenameToChecked.clear();
253 //m_StatusUrlList.Clear();
254 bool bHasChangelists = (m_changelists.size() > 1 || (!m_changelists.empty() && !m_bHasIgnoreGroup));
255 m_changelists.clear();
256 for (size_t i=0; i < m_arStatusArray.size(); i++)
258 FileEntry * entry = m_arStatusArray[i];
259 if ( bHasChangelists && entry->checked)
261 // If change lists are present, remember all checked entries
262 CString path = entry->GetPath().GetGitPathString();
263 m_mapFilenameToChecked[path] = true;
265 if ( (entry->status==git_wc_status_unversioned || entry->status==git_wc_status_missing ) && entry->checked )
267 // The user manually selected an unversioned or missing file. We remember
268 // this so that the selection can be restored when refreshing.
269 CString path = entry->GetPath().GetGitPathString();
270 m_mapFilenameToChecked[path] = true;
272 else if ( entry->status > git_wc_status_normal && !entry->checked )
274 // The user manually deselected a versioned file. We remember
275 // this so that the deselection can be restored when refreshing.
276 CString path = entry->GetPath().GetGitPathString();
277 m_mapFilenameToChecked[path] = false;
281 // use a sorted path list to make sure we fetch the status of
282 // parent items first, *then* the child items (if any)
283 CTGitPathList sortedPathList = pathList;
284 sortedPathList.SortByPathname();
287 bRet = TRUE;
288 m_nTargetCount = 0;
289 m_bHasExternalsFromDifferentRepos = FALSE;
290 m_bHasExternals = FALSE;
291 m_bHasUnversionedItems = FALSE;
292 m_bHasLocks = false;
293 m_bHasChangeLists = false;
294 m_bShowIgnores = bShowIgnores;
295 m_nSortedColumn = 0;
296 m_bBlock = TRUE;
297 m_bBusy = true;
298 m_bEmpty = false;
299 Invalidate();
301 // first clear possible status data left from
302 // previous GetStatus() calls
303 ClearStatusArray();
305 m_StatusFileList = sortedPathList;
307 // Since Git_client_status() returns all files, even those in
308 // folders included with Git:externals we need to check if all
309 // files we get here belongs to the same repository.
310 // It is possible to commit changes in an external folder, as long
311 // as the folder belongs to the same repository (but another path),
312 // but it is not possible to commit all files if the externals are
313 // from a different repository.
315 // To check if all files belong to the same repository, we compare the
316 // UUID's - if they're identical then the files belong to the same
317 // repository and can be committed. But if they're different, then
318 // tell the user to commit all changes in the external folders
319 // first and exit.
320 CStringA sUUID; // holds the repo UUID
321 CTGitPathList arExtPaths; // list of Git:external paths
323 GitConfig config;
325 m_sURL.Empty();
327 m_nTargetCount = sortedPathList.GetCount();
329 GitStatus status(m_pbCanceled);
330 if(m_nTargetCount > 1 && sortedPathList.AreAllPathsFilesInOneDirectory())
332 // This is a special case, where we've been given a list of files
333 // all from one folder
334 // We handle them by setting a status filter, then requesting the Git status of
335 // all the files in the directory, filtering for the ones we're interested in
336 status.SetFilter(sortedPathList);
338 // if all selected entries are files, we don't do a recursive status
339 // fetching. But if only one is a directory, we have to recurse.
340 git_depth_t depth = git_depth_files;
341 // We have set a filter. If all selected items were files or we fetch
342 // the status not recursively, then we have to include
343 // ignored items too - the user has selected them
344 bool bShowIgnoresRight = true;
345 for (int fcindex=0; fcindex<sortedPathList.GetCount(); ++fcindex)
347 if (sortedPathList[fcindex].IsDirectory())
349 depth = git_depth_infinity;
350 bShowIgnoresRight = false;
351 break;
354 if(!FetchStatusForSingleTarget(config, status, sortedPathList.GetCommonDirectory(), bUpdate, sUUID, arExtPaths, true, depth, bShowIgnoresRight))
356 bRet = FALSE;
359 else
361 for(int nTarget = 0; nTarget < m_nTargetCount; nTarget++)
363 // check whether the path we want the status for is already fetched due to status-fetching
364 // of a parent path.
365 // this check is only done for file paths, because folder paths could be included already
366 // but not recursively
367 if (sortedPathList[nTarget].IsDirectory() || GetListEntry(sortedPathList[nTarget]) == NULL)
369 if(!FetchStatusForSingleTarget(config, status, sortedPathList[nTarget], bUpdate, sUUID,
370 arExtPaths, false, git_depth_infinity, bShowIgnores))
372 bRet = FALSE;
378 // remove the 'helper' files of conflicted items from the list.
379 // otherwise they would appear as unversioned files.
380 for (INT_PTR cind = 0; cind < m_ConflictFileList.GetCount(); ++cind)
382 for (size_t i=0; i < m_arStatusArray.size(); i++)
384 if (m_arStatusArray[i]->GetPath().IsEquivalentTo(m_ConflictFileList[cind]))
386 delete m_arStatusArray[i];
387 m_arStatusArray.erase(m_arStatusArray.begin()+i);
388 break;
392 refetchcounter++;
393 } while(!BuildStatistics() && (refetchcounter < 2) && (*m_pbCanceled==false));
395 m_bBlock = FALSE;
396 m_bBusy = false;
397 GetCursorPos(&pt);
398 SetCursorPos(pt.x, pt.y);
399 return bRet;
400 #endif
401 BuildStatistics();
402 return TRUE;
405 // Get the show-flags bitmap value which corresponds to a particular Git status
406 DWORD CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status)
408 switch (status)
410 case git_wc_status_none:
411 case git_wc_status_unversioned:
412 return GITSLC_SHOWUNVERSIONED;
413 case git_wc_status_ignored:
414 if (!m_bShowIgnores)
415 return GITSLC_SHOWDIRECTS;
416 return GITSLC_SHOWDIRECTS|GITSLC_SHOWIGNORED;
417 case git_wc_status_incomplete:
418 return GITSLC_SHOWINCOMPLETE;
419 case git_wc_status_normal:
420 return GITSLC_SHOWNORMAL;
421 case git_wc_status_external:
422 return GITSLC_SHOWEXTERNAL;
423 case git_wc_status_added:
424 return GITSLC_SHOWADDED;
425 case git_wc_status_missing:
426 return GITSLC_SHOWMISSING;
427 case git_wc_status_deleted:
428 return GITSLC_SHOWREMOVED;
429 case git_wc_status_replaced:
430 return GITSLC_SHOWREPLACED;
431 case git_wc_status_modified:
432 return GITSLC_SHOWMODIFIED;
433 case git_wc_status_merged:
434 return GITSLC_SHOWMERGED;
435 case git_wc_status_conflicted:
436 return GITSLC_SHOWCONFLICTED;
437 case git_wc_status_obstructed:
438 return GITSLC_SHOWOBSTRUCTED;
439 default:
440 // we should NEVER get here!
441 ASSERT(FALSE);
442 break;
444 return 0;
447 void CGitStatusListCtrl::Show(unsigned int dwShow, unsigned int dwCheck /*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList,bool UseStoredCheckStatus)
449 CWinApp * pApp = AfxGetApp();
450 if (pApp)
451 pApp->DoWaitCursor(1);
453 Locker lock(m_critSec);
454 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
456 //SetItemCount(listIndex);
457 SetRedraw(FALSE);
458 DeleteAllItems();
459 m_nSelected = 0;
461 m_nShownUnversioned = 0;
462 m_nShownModified = 0;
463 m_nShownAdded = 0;
464 m_nShownDeleted = 0;
465 m_nShownConflicted = 0;
466 m_nShownFiles = 0;
467 m_nShownSubmodules = 0;
469 if(UpdateStatusList)
471 m_arStatusArray.clear();
472 for(int i=0;i<this->m_StatusFileList.GetCount();i++)
474 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
477 for(int i=0;i<this->m_UnRevFileList.GetCount();i++)
479 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
482 for(int i=0;i<this->m_IgnoreFileList.GetCount();i++)
484 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
487 PrepareGroups();
488 if (m_nSortedColumn >= 0)
490 CSorter predicate (&m_ColumnManager, m_nSortedColumn, m_bAscending);
491 std::sort(m_arStatusArray.begin(), m_arStatusArray.end(), predicate);
494 int index =0;
495 for(int i=0;i<this->m_arStatusArray.size();i++)
497 //set default checkbox status
498 CTGitPath* entry = ((CTGitPath*)m_arStatusArray[i]);
499 CString path = entry->GetGitPathString();
500 if (!m_mapFilenameToChecked.empty() && m_mapFilenameToChecked.find(path) != m_mapFilenameToChecked.end())
502 entry->m_Checked=m_mapFilenameToChecked[path];
504 else if (!UseStoredCheckStatus)
506 bool autoSelectSubmodules = !(entry->IsDirectory() && m_bDoNotAutoselectSubmodules);
507 if ((entry->m_Action & dwCheck || dwShow & GITSLC_SHOWDIRECTFILES && m_mapDirectFiles.find(path) != m_mapDirectFiles.end()) && autoSelectSubmodules)
508 entry->m_Checked=true;
509 else
510 entry->m_Checked=false;
511 m_mapFilenameToChecked[path] = entry->m_Checked;
514 if(entry->m_Action & dwShow)
516 AddEntry(entry,langID,index);
517 index++;
521 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
522 for (int col = 0; col <= maxcol; col++)
523 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
525 SetRedraw(TRUE);
526 GetStatisticsString();
528 CHeaderCtrl * pHeader = GetHeaderCtrl();
529 HDITEM HeaderItem = {0};
530 HeaderItem.mask = HDI_FORMAT;
531 for (int i=0; i<pHeader->GetItemCount(); ++i)
533 pHeader->GetItem(i, &HeaderItem);
534 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
535 pHeader->SetItem(i, &HeaderItem);
537 if (m_nSortedColumn >= 0)
539 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
540 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
541 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
544 #if 0
545 if (nSelectedEntry)
547 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
548 EnsureVisible(nSelectedEntry, false);
550 else
552 // Restore the item at the top of the list.
553 for (int i=0;GetTopIndex() != nTopIndex;i++)
555 if ( !EnsureVisible(nTopIndex+i,false) )
557 break;
561 #endif
562 if (pApp)
563 pApp->DoWaitCursor(-1);
565 Invalidate();
567 m_dwShow = dwShow;
569 this->BuildStatistics();
571 #if 0
573 CWinApp * pApp = AfxGetApp();
574 if (pApp)
575 pApp->DoWaitCursor(1);
577 m_bShowFolders = bShowFolders;
579 int nTopIndex = GetTopIndex();
580 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
581 int nSelectedEntry = 0;
582 if (posSelectedEntry)
583 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
584 SetRedraw(FALSE);
585 DeleteAllItems();
587 PrepareGroups();
589 m_arListArray.clear();
591 m_arListArray.reserve(m_arStatusArray.size());
592 SetItemCount (static_cast<int>(m_arStatusArray.size()));
594 int listIndex = 0;
595 for (size_t i=0; i < m_arStatusArray.size(); ++i)
597 FileEntry * entry = m_arStatusArray[i];
598 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
599 continue;
600 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
601 continue;
602 if (entry->IsFolder() && (!bShowFolders))
603 continue; // don't show folders if they're not wanted.
605 #if 0
606 git_wc_status_kind status = GitStatus::GetMoreImportant(entry->status, entry->remotestatus);
607 DWORD showFlags = GetShowFlagsFromGitStatus(status);
608 if (entry->IsLocked())
609 showFlags |= SVNSLC_SHOWLOCKS;
610 if (entry->switched)
611 showFlags |= SVNSLC_SHOWSWITCHED;
612 if (!entry->changelist.IsEmpty())
613 showFlags |= SVNSLC_SHOWINCHANGELIST;
614 #endif
615 bool bAllowCheck = ((entry->changelist.Compare(GITSLC_IGNORECHANGELIST) != 0)
616 && (m_bCheckIfGroupsExist || (m_changelists.empty() || (m_changelists.size() == 1 && m_bHasIgnoreGroup))));
618 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
619 #if 0
620 if (status != Git_wc_status_ignored || (entry->direct) || (dwShow & GitSLC_SHOWIGNORED))
622 if ((!entry->IsFolder()) && (status == Git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
624 if (PathFileExists(entry->GetPath().GetWinPath()))
626 m_arListArray.push_back(i);
627 if ((dwCheck & SVNSLC_SHOWREMOVEDANDPRESENT)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
629 if (bAllowCheck)
630 entry->checked = true;
632 AddEntry(entry, langID, listIndex++);
635 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
637 m_arListArray.push_back(i);
638 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
640 if (bAllowCheck)
641 entry->checked = true;
643 AddEntry(entry, langID, listIndex++);
645 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
647 m_arListArray.push_back(i);
648 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
650 if (bAllowCheck)
651 entry->checked = true;
653 AddEntry(entry, langID, listIndex++);
656 #endif
659 SetItemCount(listIndex);
661 m_ColumnManager.UpdateRelevance (m_arStatusArray, m_arListArray);
663 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
664 for (int col = 0; col <= maxcol; col++)
665 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
667 SetRedraw(TRUE);
668 GetStatisticsString();
670 CHeaderCtrl * pHeader = GetHeaderCtrl();
671 HDITEM HeaderItem = {0};
672 HeaderItem.mask = HDI_FORMAT;
673 for (int i=0; i<pHeader->GetItemCount(); ++i)
675 pHeader->GetItem(i, &HeaderItem);
676 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
677 pHeader->SetItem(i, &HeaderItem);
679 if (m_nSortedColumn)
681 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
682 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
683 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
686 if (nSelectedEntry)
688 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
689 EnsureVisible(nSelectedEntry, false);
691 else
693 // Restore the item at the top of the list.
694 for (int i=0;GetTopIndex() != nTopIndex;i++)
696 if ( !EnsureVisible(nTopIndex+i,false) )
698 break;
703 if (pApp)
704 pApp->DoWaitCursor(-1);
706 m_bEmpty = (GetItemCount() == 0);
707 Invalidate();
708 #endif
712 void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList& checkedList, bool /*bShowFolders*/ /* = true */)
714 DeleteAllItems();
715 for(int i=0;i<checkedList.GetCount();i++)
716 this->AddEntry((CTGitPath *)&checkedList[i],0,i);
717 return ;
718 #if 0
720 Locker lock(m_critSec);
721 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
723 CWinApp * pApp = AfxGetApp();
724 if (pApp)
725 pApp->DoWaitCursor(1);
726 m_dwShow = dwShow;
727 m_bShowFolders = bShowFolders;
728 m_nSelected = 0;
729 int nTopIndex = GetTopIndex();
730 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
731 int nSelectedEntry = 0;
732 if (posSelectedEntry)
733 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
734 SetRedraw(FALSE);
735 DeleteAllItems();
737 PrepareGroups();
739 m_arListArray.clear();
741 m_arListArray.reserve(m_arStatusArray.size());
742 SetItemCount (static_cast<int>(m_arStatusArray.size()));
744 int listIndex = 0;
745 for (size_t i=0; i < m_arStatusArray.size(); ++i)
747 FileEntry * entry = m_arStatusArray[i];
748 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
749 continue;
750 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
751 continue;
752 if (entry->IsFolder() && (!bShowFolders))
753 continue; // don't show folders if they're not wanted.
754 #if 0
755 git_wc_status_kind status = SVNStatus::GetMoreImportant(entry->status, entry->remotestatus);
756 DWORD showFlags = GetShowFlagsFromSVNStatus(status);
757 if (entry->IsLocked())
758 showFlags |= SVNSLC_SHOWLOCKS;
759 if (!entry->changelist.IsEmpty())
760 showFlags |= SVNSLC_SHOWINCHANGELIST;
762 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
763 if (status != git_wc_status_ignored || (entry->direct) || (dwShow & SVNSLC_SHOWIGNORED))
765 for (int npath = 0; npath < checkedList.GetCount(); ++npath)
767 if (entry->GetPath().IsEquivalentTo(checkedList[npath]))
769 entry->checked = true;
770 break;
773 if ((!entry->IsFolder()) && (status == git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
775 if (PathFileExists(entry->GetPath().GetWinPath()))
777 m_arListArray.push_back(i);
778 AddEntry(entry, langID, listIndex++);
781 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
783 m_arListArray.push_back(i);
784 AddEntry(entry, langID, listIndex++);
786 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
788 m_arListArray.push_back(i);
789 AddEntry(entry, langID, listIndex++);
791 else if (entry->switched)
793 m_arListArray.push_back(i);
794 AddEntry(entry, langID, listIndex++);
797 #endif
800 SetItemCount(listIndex);
802 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
803 for (int col = 0; col <= maxcol; col++)
804 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
806 SetRedraw(TRUE);
807 GetStatisticsString();
809 CHeaderCtrl * pHeader = GetHeaderCtrl();
810 HDITEM HeaderItem = {0};
811 HeaderItem.mask = HDI_FORMAT;
812 for (int i=0; i<pHeader->GetItemCount(); ++i)
814 pHeader->GetItem(i, &HeaderItem);
815 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
816 pHeader->SetItem(i, &HeaderItem);
818 if (m_nSortedColumn)
820 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
821 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
822 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
825 if (nSelectedEntry)
827 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
828 EnsureVisible(nSelectedEntry, false);
830 else
832 // Restore the item at the top of the list.
833 for (int i=0;GetTopIndex() != nTopIndex;i++)
835 if ( !EnsureVisible(nTopIndex+i,false) )
837 break;
842 if (pApp)
843 pApp->DoWaitCursor(-1);
845 m_bEmpty = (GetItemCount() == 0);
846 Invalidate();
847 #endif
850 int CGitStatusListCtrl::GetColumnIndex(int mask)
852 int i=0;
853 for(i=0;i<32;i++)
854 if(mask&0x1)
855 return i;
856 else
857 mask=mask>>1;
858 return -1;
860 void CGitStatusListCtrl::AddEntry(CTGitPath * GitPath, WORD /*langID*/, int listIndex)
862 static CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
863 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
864 static bool abbreviateRenamings(((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\AbbreviateRenamings"), FALSE)) == TRUE);
865 static bool relativeTimes = (CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE) != FALSE);
867 CString path = GitPath->GetGitPathString();
869 m_bBlock = TRUE;
870 int index = listIndex;
871 int nCol = 1;
872 CString entryname = GitPath->GetGitPathString();
873 int icon_idx = 0;
874 if (GitPath->IsDirectory())
876 icon_idx = m_nIconFolder;
877 m_nShownSubmodules++;
879 else
881 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath);
882 m_nShownFiles++;
884 switch (GitPath->m_Action)
886 case CTGitPath::LOGACTIONS_ADDED:
887 case CTGitPath::LOGACTIONS_COPY:
888 m_nShownAdded++;
889 break;
890 case CTGitPath::LOGACTIONS_DELETED:
891 m_nShownDeleted++;
892 break;
893 case CTGitPath::LOGACTIONS_REPLACED:
894 case CTGitPath::LOGACTIONS_MODIFIED:
895 case CTGitPath::LOGACTIONS_MERGED:
896 m_nShownModified++;
897 break;
898 case CTGitPath::LOGACTIONS_UNMERGED:
899 m_nShownConflicted++;
900 break;
901 case CTGitPath::LOGACTIONS_UNVER:
902 m_nShownUnversioned++;
903 break;
904 default:
905 m_nShownUnversioned++;
906 break;
908 if(GitPath->m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !GitPath->GetGitOldPathString().IsEmpty())
910 if (!abbreviateRenamings)
912 // relative path
913 CString rename;
914 rename.Format(from, GitPath->GetGitOldPathString());
915 entryname += _T(" ") + rename;
917 else
919 CTGitPathList tgpl;
920 tgpl.AddPath(*GitPath);
921 CTGitPath old(GitPath->GetGitOldPathString());
922 tgpl.AddPath(old);
923 CString commonRoot = tgpl.GetCommonRoot().GetGitPathString();
924 if (!commonRoot.IsEmpty())
925 commonRoot += _T("/");
926 if (old.GetFileOrDirectoryName() == GitPath->GetFileOrDirectoryName() && old.GetContainingDirectory().GetGitPathString() != "" && GitPath->GetContainingDirectory().GetGitPathString())
928 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();
930 else if (!commonRoot.IsEmpty())
932 entryname = commonRoot + _T("{") + GitPath->GetGitOldPathString().Mid(commonRoot.GetLength()) + _T(" => ") + GitPath->GetGitPathString().Mid(commonRoot.GetLength()) + _T("}");
934 else
936 entryname = GitPath->GetGitOldPathString().Mid(commonRoot.GetLength()) + _T(" => ") + GitPath->GetGitPathString().Mid(commonRoot.GetLength());
941 InsertItem(index, entryname, icon_idx);
942 if (m_restorepaths.find(GitPath->GetWinPathString()) != m_restorepaths.end())
943 SetItemState(index, INDEXTOOVERLAYMASK(OVL_RESTORE), TVIS_OVERLAYMASK);
945 this->SetItemData(index, (DWORD_PTR)GitPath);
946 // SVNSLC_COLFILENAME
947 SetItemText(index, nCol++, GitPath->GetFileOrDirectoryName());
948 // SVNSLC_COLEXT
949 SetItemText(index, nCol++, GitPath->GetFileExtension());
950 // SVNSLC_COLSTATUS
951 SetItemText(index, nCol++, GitPath->GetActionName());
953 SetItemText(index, GetColumnIndex(GITSLC_COLADD),GitPath->m_StatAdd);
954 SetItemText(index, GetColumnIndex(GITSLC_COLDEL),GitPath->m_StatDel);
957 CString modificationDate;
958 __int64 filetime = GitPath->GetLastWriteTime();
959 if (filetime && (GitPath->m_Action != CTGitPath::LOGACTIONS_DELETED))
961 FILETIME* f = (FILETIME*)(__int64*)&filetime;
962 modificationDate = CLoglistUtils::FormatDateAndTime(CTime(g_Git.filetime_to_time_t(f)), DATE_SHORTDATE, true, relativeTimes);
964 SetItemText(index, GetColumnIndex(GITSLC_COLMODIFICATIONDATE), modificationDate);
966 // SVNSLC_COLSIZE
967 if (GitPath->IsDirectory())
968 SetItemText(index, GetColumnIndex(GITSLC_COLSIZE), _T(""));
969 else
971 TCHAR buf[100];
972 StrFormatByteSize64(GitPath->GetFileSize(), buf, 100);
973 SetItemText(index, GetColumnIndex(GITSLC_COLSIZE), buf);
976 SetCheck(index, GitPath->m_Checked);
977 if (GitPath->m_Checked)
978 m_nSelected++;
981 if( GitPath->m_Action & CTGitPath::LOGACTIONS_IGNORE)
982 SetItemGroup(index, 2);
983 else if( GitPath->m_Action & CTGitPath::LOGACTIONS_UNVER)
984 SetItemGroup(index,1);
985 else
987 SetItemGroup(index, GitPath->m_ParentNo&(PARENT_MASK|MERGE_MASK));
990 m_bBlock = FALSE;
995 bool CGitStatusListCtrl::SetItemGroup(int item, int groupindex)
997 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
998 // return false;
999 if (groupindex < 0)
1000 return false;
1001 LVITEM i = {0};
1002 i.mask = LVIF_GROUPID;
1003 i.iItem = item;
1004 i.iSubItem = 0;
1005 i.iGroupId = groupindex;
1007 return !!SetItem(&i);
1010 void CGitStatusListCtrl::OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult)
1012 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1013 *pResult = 0;
1014 if (m_bBlock || m_arStatusArray.empty())
1015 return;
1016 m_bBlock = TRUE;
1017 if (m_nSortedColumn == phdr->iItem)
1018 m_bAscending = !m_bAscending;
1019 else
1020 m_bAscending = TRUE;
1021 m_nSortedColumn = phdr->iItem;
1022 Show(m_dwShow, 0, m_bShowFolders,false,true);
1024 m_bBlock = FALSE;
1027 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
1029 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1030 *pResult = 0;
1032 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1033 if ((m_bBlock)&&(m_bBlockUI))
1035 // if we're blocked, prevent changing of the check state
1036 if ((!ISCHECKED(pNMLV->uOldState) && ISCHECKED(pNMLV->uNewState))||
1037 (ISCHECKED(pNMLV->uOldState) && !ISCHECKED(pNMLV->uNewState)))
1038 *pResult = TRUE;
1042 BOOL CGitStatusListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
1044 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1045 *pResult = 0;
1046 CWnd* pParent = GetLogicalParent();
1047 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
1049 pParent->SendMessage(GITSLNM_ITEMCHANGED, pNMLV->iItem);
1052 if ((pNMLV->uNewState==0)||(pNMLV->uNewState & LVIS_SELECTED)||(pNMLV->uNewState & LVIS_FOCUSED))
1053 return FALSE;
1055 if (m_bBlock)
1056 return FALSE;
1058 bool bSelected = !!(ListView_GetItemState(m_hWnd, pNMLV->iItem, LVIS_SELECTED) & LVIS_SELECTED);
1059 int nListItems = GetItemCount();
1061 m_bBlock = TRUE;
1062 // was the item checked?
1064 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1065 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1067 if (GetCheck(pNMLV->iItem))
1069 CheckEntry(pNMLV->iItem, nListItems);
1070 if (bSelected)
1072 POSITION pos = GetFirstSelectedItemPosition();
1073 int index;
1074 while ((index = GetNextSelectedItem(pos)) >= 0)
1076 if (index != pNMLV->iItem)
1077 CheckEntry(index, nListItems);
1081 else
1083 UncheckEntry(pNMLV->iItem, nListItems);
1084 if (bSelected)
1086 POSITION pos = GetFirstSelectedItemPosition();
1087 int index;
1088 while ((index = GetNextSelectedItem(pos)) >= 0)
1090 if (index != pNMLV->iItem)
1091 UncheckEntry(index, nListItems);
1096 GetStatisticsString();
1097 m_bBlock = FALSE;
1098 NotifyCheck();
1100 return FALSE;
1103 void CGitStatusListCtrl::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
1105 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
1107 *pResult = FALSE;
1110 void CGitStatusListCtrl::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
1112 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
1114 Invalidate(FALSE);
1117 void CGitStatusListCtrl::CheckEntry(int index, int /*nListItems*/)
1119 Locker lock(m_critSec);
1120 //FileEntry * entry = GetListEntry(index);
1121 CTGitPath *path=(CTGitPath*)GetItemData(index);
1122 ASSERT(path != NULL);
1123 if (path == NULL)
1124 return;
1125 m_mapFilenameToChecked[path->GetGitPathString()] = true;
1126 SetCheck(index, TRUE);
1127 //entry = GetListEntry(index);
1128 // if an unversioned item was checked, then we need to check if
1129 // the parent folders are unversioned too. If the parent folders actually
1130 // are unversioned, then check those too.
1131 #if 0
1132 if (entry->status == git_wc_status_unversioned)
1134 // we need to check the parent folder too
1135 const CTGitPath& folderpath = entry->path;
1136 for (int i=0; i< nListItems; ++i)
1138 FileEntry * testEntry = GetListEntry(i);
1139 ASSERT(testEntry != NULL);
1140 if (testEntry == NULL)
1141 continue;
1142 if (!testEntry->checked)
1144 if (testEntry->path.IsAncestorOf(folderpath) && (!testEntry->path.IsEquivalentTo(folderpath)))
1146 SetEntryCheck(testEntry,i,true);
1147 m_nSelected++;
1152 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1153 if ( (entry->status == git_wc_status_deleted) || (m_bCheckChildrenWithParent) || (bShift) )
1155 // if a deleted folder gets checked, we have to check all
1156 // children of that folder too.
1157 if (entry->path.IsDirectory())
1159 SetCheckOnAllDescendentsOf(entry, true);
1162 // if a deleted file or folder gets checked, we have to
1163 // check all parents of this item too.
1164 for (int i=0; i<nListItems; ++i)
1166 FileEntry * testEntry = GetListEntry(i);
1167 ASSERT(testEntry != NULL);
1168 if (testEntry == NULL)
1169 continue;
1170 if (!testEntry->checked)
1172 if (testEntry->path.IsAncestorOf(entry->path) && (!testEntry->path.IsEquivalentTo(entry->path)))
1174 if ((testEntry->status == git_wc_status_deleted)||(m_bCheckChildrenWithParent))
1176 SetEntryCheck(testEntry,i,true);
1177 m_nSelected++;
1178 // now we need to check all children of this parent folder
1179 SetCheckOnAllDescendentsOf(testEntry, true);
1185 #endif
1186 if ( !path->m_Checked )
1188 path->m_Checked = TRUE;
1189 m_nSelected++;
1193 void CGitStatusListCtrl::UncheckEntry(int index, int /*nListItems*/)
1195 Locker lock(m_critSec);
1196 CTGitPath *path=(CTGitPath*)GetItemData(index);
1197 ASSERT(path != NULL);
1198 if (path == NULL)
1199 return;
1200 SetCheck(index, FALSE);
1201 m_mapFilenameToChecked[path->GetGitPathString()] = false;
1202 //entry = GetListEntry(index);
1203 // item was unchecked
1204 #if 0
1205 if (entry->path.IsDirectory())
1207 // disable all files within an unselected folder, except when unchecking a folder with property changes
1208 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1209 if ( (entry->status != git_wc_status_modified) || (bShift) )
1211 SetCheckOnAllDescendentsOf(entry, false);
1214 else if (entry->status == git_wc_status_deleted)
1216 // a "deleted" file was unchecked, so uncheck all parent folders
1217 // and all children of those parents
1218 for (int i=0; i<nListItems; i++)
1220 FileEntry * testEntry = GetListEntry(i);
1221 ASSERT(testEntry != NULL);
1222 if (testEntry == NULL)
1223 continue;
1224 if (testEntry->checked)
1226 if (testEntry->path.IsAncestorOf(entry->path))
1228 if (testEntry->status == git_wc_status_deleted)
1230 SetEntryCheck(testEntry,i,false);
1231 m_nSelected--;
1233 SetCheckOnAllDescendentsOf(testEntry, false);
1239 #endif
1240 if ( path->m_Checked )
1242 path->m_Checked = FALSE;
1243 m_nSelected--;
1246 bool CGitStatusListCtrl::BuildStatistics()
1249 bool bRefetchStatus = false;
1251 // now gather some statistics
1252 m_nUnversioned = 0;
1253 m_nNormal = 0;
1254 m_nModified = 0;
1255 m_nAdded = 0;
1256 m_nDeleted = 0;
1257 m_nConflicted = 0;
1258 m_nTotal = 0;
1259 m_nSelected = 0;
1260 m_nLineAdded = 0;
1261 m_nLineDeleted = 0;
1262 m_nRenamed = 0;
1264 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1266 int status=((CTGitPath*)m_arStatusArray[i])->m_Action;
1268 m_nLineAdded += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatAdd);
1269 m_nLineDeleted += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatDel);
1271 if(status&(CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
1272 m_nAdded++;
1274 if(status&CTGitPath::LOGACTIONS_DELETED)
1275 m_nDeleted++;
1277 if(status&(CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_MODIFIED))
1278 m_nModified++;
1280 if(status&CTGitPath::LOGACTIONS_UNMERGED)
1281 m_nConflicted++;
1283 if(status&(CTGitPath::LOGACTIONS_IGNORE|CTGitPath::LOGACTIONS_UNVER))
1284 m_nUnversioned++;
1286 if(status&(CTGitPath::LOGACTIONS_REPLACED))
1287 m_nRenamed++;
1289 if(((CTGitPath*)m_arStatusArray[i])->m_Checked)
1290 m_nSelected++;
1292 // } // switch (entry->status)
1293 // } // if (entry)
1294 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1295 return !bRefetchStatus;
1299 int CGitStatusListCtrl::GetGroupFromPoint(POINT * ppt)
1301 // the point must be relative to the upper left corner of the control
1303 if (ppt == NULL)
1304 return -1;
1305 if (!IsGroupViewEnabled())
1306 return -1;
1308 POINT pt = *ppt;
1309 pt.x = 10;
1310 UINT flags = 0;
1311 int nItem = -1;
1312 RECT rc;
1313 GetWindowRect(&rc);
1314 while (((flags & LVHT_BELOW) == 0)&&(pt.y < rc.bottom))
1316 nItem = HitTest(pt, &flags);
1317 if ((flags & LVHT_ONITEM)||(flags & LVHT_EX_GROUP_HEADER))
1319 // the first item below the point
1321 // check if the point is too much right (i.e. if the point
1322 // is farther to the right than the width of the item)
1323 RECT r;
1324 GetItemRect(nItem, &r, LVIR_LABEL);
1325 if (ppt->x > r.right)
1326 return -1;
1328 LVITEM lv = {0};
1329 lv.mask = LVIF_GROUPID;
1330 lv.iItem = nItem;
1331 GetItem(&lv);
1332 int groupID = lv.iGroupId;
1333 // now we search upwards and check if the item above this one
1334 // belongs to another group. If it belongs to the same group,
1335 // we're not over a group header
1336 while (pt.y >= 0)
1338 pt.y -= 2;
1339 nItem = HitTest(pt, &flags);
1340 if ((flags & LVHT_ONITEM)&&(nItem >= 0))
1342 // the first item below the point
1343 LVITEM lv = {0};
1344 lv.mask = LVIF_GROUPID;
1345 lv.iItem = nItem;
1346 GetItem(&lv);
1347 if (lv.iGroupId != groupID)
1348 return groupID;
1349 else
1350 return -1;
1353 if (pt.y < 0)
1354 return groupID;
1355 return -1;
1357 pt.y += 2;
1359 return -1;
1362 void CGitStatusListCtrl::OnContextMenuGroup(CWnd * /*pWnd*/, CPoint point)
1364 POINT clientpoint = point;
1365 ScreenToClient(&clientpoint);
1366 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint) >= 0))
1368 CMenu popup;
1369 if (popup.CreatePopupMenu())
1371 CString temp;
1372 temp.LoadString(IDS_STATUSLIST_CHECKGROUP);
1373 popup.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_CHECKGROUP, temp);
1374 temp.LoadString(IDS_STATUSLIST_UNCHECKGROUP);
1375 popup.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_UNCHECKGROUP, temp);
1376 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1377 bool bCheck = false;
1378 switch (cmd)
1380 case IDGITLC_CHECKGROUP:
1381 bCheck = true;
1382 // fall through here
1383 case IDGITLC_UNCHECKGROUP:
1385 int group = GetGroupFromPoint(&clientpoint);
1386 // go through all items and check/uncheck those assigned to the group
1387 // but block the OnLvnItemChanged handler
1388 m_bBlock = true;
1389 LVITEM lv;
1390 for (int i=0; i<GetItemCount(); ++i)
1392 SecureZeroMemory(&lv, sizeof(LVITEM));
1393 lv.mask = LVIF_GROUPID;
1394 lv.iItem = i;
1395 GetItem(&lv);
1397 if (lv.iGroupId == group)
1399 CTGitPath * entry = (CTGitPath*)GetItemData(i);
1400 if (entry)
1402 bool bOldCheck = entry->m_Checked;
1403 SetEntryCheck(entry, i, bCheck);
1404 if (bCheck != bOldCheck)
1406 if (bCheck)
1407 m_nSelected++;
1408 else
1409 m_nSelected--;
1415 GetStatisticsString();
1416 NotifyCheck();
1417 m_bBlock = false;
1419 break;
1425 void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point)
1428 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1430 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1431 CTGitPath * filepath;
1433 int selIndex = GetSelectionMark();
1434 if ((point.x == -1) && (point.y == -1))
1436 CRect rect;
1437 GetItemRect(selIndex, &rect, LVIR_LABEL);
1438 ClientToScreen(&rect);
1439 point = rect.CenterPoint();
1441 if ((GetSelectedCount() == 0) && (m_bHasCheckboxes))
1443 // nothing selected could mean the context menu is requested for
1444 // a group header
1445 OnContextMenuGroup(pWnd, point);
1447 else if (selIndex >= 0)
1449 //FileEntry * entry = GetListEntry(selIndex);
1451 filepath = (CTGitPath * )GetItemData(selIndex);
1453 ASSERT(filepath != NULL);
1454 if (filepath == NULL)
1455 return;
1457 //const CTGitPath& filepath = entry->path;
1458 int wcStatus = filepath->m_Action;
1459 // entry is selected, now show the popup menu
1460 Locker lock(m_critSec);
1461 CIconMenu popup;
1462 CMenu changelistSubMenu;
1463 CMenu ignoreSubMenu;
1464 if (popup.CreatePopupMenu())
1466 //Add Menu for version controlled file
1468 if (GetSelectedCount() > 0 && wcStatus & CTGitPath::LOGACTIONS_UNMERGED)
1470 if (GetSelectedCount() == 1 && (m_dwContextMenus & GITSLC_POPCONFLICT)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1472 popup.AppendMenuIcon(IDGITLC_EDITCONFLICT, IDS_MENUCONFLICT, IDI_CONFLICT);
1474 if (m_dwContextMenus & GITSLC_POPRESOLVE)
1476 popup.AppendMenuIcon(IDGITLC_RESOLVECONFLICT, IDS_STATUSLIST_CONTEXT_RESOLVED, IDI_RESOLVE);
1478 if ((m_dwContextMenus & GITSLC_POPRESOLVE)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1480 popup.AppendMenuIcon(IDGITLC_RESOLVETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS, IDI_RESOLVE);
1481 popup.AppendMenuIcon(IDGITLC_RESOLVEMINE, IDS_SVNPROGRESS_MENUUSEMINE, IDI_RESOLVE);
1483 if ((m_dwContextMenus & GITSLC_POPCONFLICT)||(m_dwContextMenus & GITSLC_POPRESOLVE))
1484 popup.AppendMenu(MF_SEPARATOR);
1487 if (GetSelectedCount() > 0)
1489 if (wcStatus & CTGitPath::LOGACTIONS_UNVER)
1490 if (m_dwContextMenus & GITSLC_POPADD)
1492 //if ( entry->IsFolder() )
1494 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1496 //else
1498 popup.AppendMenuIcon(IDGITLC_ADD, IDS_STATUSLIST_CONTEXT_ADD, IDI_ADD);
1503 if (!(wcStatus & CTGitPath::LOGACTIONS_UNVER) && GetSelectedCount() > 0)
1505 bool bEntryAdded = false;
1506 if (m_dwContextMenus & GITSLC_POPCOMPAREWITHBASE)
1508 if(filepath->m_ParentNo & MERGE_MASK)
1509 popup.AppendMenuIcon(IDGITLC_COMPARE, IDS_TREE_DIFF, IDI_DIFF);
1510 else
1511 popup.AppendMenuIcon(IDGITLC_COMPARE, IDS_LOG_COMPAREWITHBASE, IDI_DIFF);
1513 popup.SetDefaultItem(IDGITLC_COMPARE, FALSE);
1514 bEntryAdded = true;
1517 if (!g_Git.IsInitRepos() && (m_dwContextMenus & GITSLC_POPGNUDIFF))
1519 popup.AppendMenuIcon(IDGITLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1520 bEntryAdded = true;
1523 if ((m_dwContextMenus & this->GetContextMenuBit(IDGITLC_COMPAREWC)) && m_bHasWC)
1525 if ((!m_CurrentVersion.IsEmpty()) && m_CurrentVersion != GIT_REV_ZERO)
1527 popup.AppendMenuIcon(IDGITLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1528 bEntryAdded = true;
1532 //else if (GetSelectedCount() > 1)
1534 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1535 // {
1536 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1537 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1538 // }
1541 if (bEntryAdded)
1542 popup.AppendMenu(MF_SEPARATOR);
1545 if( (!this->m_Rev1.IsEmpty()) || (!this->m_Rev1.IsEmpty()) )
1547 if(GetSelectedCount() == 1)
1549 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_COMPARETWO))
1551 popup.AppendMenuIcon(IDGITLC_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1552 popup.SetDefaultItem(IDGITLC_COMPARETWO, FALSE);
1554 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_GNUDIFF2))
1556 popup.AppendMenuIcon(IDGITLC_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1561 //Select Multi item
1562 if (GetSelectedCount() > 0)
1564 if ((GetSelectedCount() == 2) && (m_dwContextMenus & GITSLC_POPCOMPARETWOFILES) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO))
1566 POSITION pos = GetFirstSelectedItemPosition();
1567 int index = GetNextSelectedItem(pos);
1568 if (index >= 0)
1570 CTGitPath * entry2 = NULL;
1571 bool bothItemsAreExistingFiles = true;
1572 entry2 = (CTGitPath * )GetItemData(index);
1573 if (entry2)
1574 bothItemsAreExistingFiles = !entry2->IsDirectory() && entry2->Exists();
1575 index = GetNextSelectedItem(pos);
1576 if (index >= 0)
1578 entry2 = (CTGitPath * )GetItemData(index);
1579 if (entry2)
1580 bothItemsAreExistingFiles = bothItemsAreExistingFiles && !entry2->IsDirectory() && entry2->Exists();
1581 if (bothItemsAreExistingFiles)
1582 popup.AppendMenuIcon(IDGITLC_COMPARETWOFILES, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES, IDI_DIFF);
1586 // if (wcStatus > git_wc_status_normal)
1587 // {
1588 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1589 // {
1590 // // reverting missing folders is not possible
1591 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1592 // {
1593 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1594 // }
1595 // }
1596 // }
1597 // if (entry->remotestatus > git_wc_status_normal)
1598 // {
1599 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1600 // {
1601 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1602 // }
1603 // }
1606 if ( (GetSelectedCount() >0 ) && (!(wcStatus & CTGitPath::LOGACTIONS_UNVER)) && m_bHasWC)
1608 if ((m_dwContextMenus & GITSLC_POPREVERT) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO))
1610 popup.AppendMenuIcon(IDGITLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1613 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())
1615 popup.AppendMenuIcon(IDGITLC_SKIPWORKTREE, IDS_STATUSLIST_SKIPWORKTREE);
1618 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())
1620 popup.AppendMenuIcon(IDGITLC_ASSUMEVALID, IDS_MENUASSUMEVALID);
1623 if (m_dwContextMenus & GITSLC_POPRESTORE && !filepath->IsDirectory())
1625 if (m_restorepaths.find(filepath->GetWinPathString()) == m_restorepaths.end())
1626 popup.AppendMenuIcon(IDGITLC_CREATERESTORE, IDS_MENUCREATERESTORE, IDI_RESTORE);
1627 else
1628 popup.AppendMenuIcon(IDGITLC_RESTOREPATH, IDS_MENURESTORE, IDI_RESTORE);
1631 if ((m_dwContextMenus & GetContextMenuBit(IDGITLC_REVERTTOREV)) && ( !this->m_CurrentVersion.IsEmpty() )
1632 && this->m_CurrentVersion != GIT_REV_ZERO && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1634 popup.AppendMenuIcon(IDGITLC_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1637 if ((m_dwContextMenus & GetContextMenuBit(IDGITLC_REVERTTOPARENT)) && ( !this->m_CurrentVersion.IsEmpty() )
1638 && this->m_CurrentVersion != GIT_REV_ZERO && !(wcStatus & CTGitPath::LOGACTIONS_ADDED))
1640 popup.AppendMenuIcon(IDGITLC_REVERTTOPARENT, IDS_LOG_POPUP_REVERTTOPARENT, IDI_REVERT);
1644 if ((GetSelectedCount() == 1)&&(!(wcStatus & CTGitPath::LOGACTIONS_UNVER))
1645 &&(!(wcStatus & CTGitPath::LOGACTIONS_IGNORE)))
1647 if (m_dwContextMenus & GITSLC_POPSHOWLOG)
1649 popup.AppendMenuIcon(IDGITLC_LOG, IDS_REPOBROWSE_SHOWLOG, IDI_LOG);
1651 if (m_dwContextMenus & GITSLC_POPSHOWLOGSUBMODULE && filepath->IsDirectory())
1653 popup.AppendMenuIcon(IDGITLC_LOGSUBMODULE, IDS_LOG_SUBMODULE, IDI_LOG);
1655 if (m_dwContextMenus & GITSLC_POPSHOWLOGOLDNAME && (wcStatus & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !filepath->GetGitOldPathString().IsEmpty()))
1657 popup.AppendMenuIcon(IDGITLC_LOGOLDNAME, IDS_STATUSLIST_SHOWLOGOLDNAME, IDI_LOG);
1659 if (m_dwContextMenus & GITSLC_POPBLAME && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED) && m_bHasWC)
1661 popup.AppendMenuIcon(IDGITLC_BLAME, IDS_MENUBLAME, IDI_BLAME);
1665 if (GetSelectedCount() > 0)
1667 if ((m_dwContextMenus & GetContextMenuBit(IDGITLC_EXPORT)) && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1668 popup.AppendMenuIcon(IDGITLC_EXPORT, IDS_LOG_POPUP_EXPORT, IDI_EXPORT);
1671 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1672 if ( (GetSelectedCount() == 1) )
1674 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_SAVEAS) && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1676 popup.AppendMenuIcon(IDGITLC_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
1679 if (m_dwContextMenus & GITSLC_POPOPEN && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1681 popup.AppendMenuIcon(IDGITLC_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1682 popup.AppendMenuIcon(IDGITLC_OPEN, IDS_REPOBROWSE_OPEN, IDI_OPEN);
1683 popup.AppendMenuIcon(IDGITLC_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1684 if (wcStatus &CTGitPath::LOGACTIONS_UNVER) {
1685 popup.SetDefaultItem(IDGITLC_OPEN, FALSE);
1689 if (m_dwContextMenus & GITSLC_POPEXPLORE && !(wcStatus & CTGitPath::LOGACTIONS_DELETED) && m_bHasWC)
1691 popup.AppendMenuIcon(IDGITLC_EXPLORE, IDS_STATUSLIST_CONTEXT_EXPLORE, IDI_EXPLORER);
1695 if (GetSelectedCount() > 0)
1697 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
1698 // {
1699 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1700 // }
1701 // 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))
1702 // {
1703 // if (bShift)
1704 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
1705 // else
1706 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
1707 // }
1708 if ((wcStatus & CTGitPath::LOGACTIONS_UNVER)/*||(wcStatus == git_wc_status_deleted)*/)
1710 if (m_dwContextMenus & GITSLC_POPDELETE)
1712 popup.AppendMenuIcon(IDGITLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1715 if ( (wcStatus & CTGitPath::LOGACTIONS_UNVER || wcStatus & CTGitPath::LOGACTIONS_DELETED) )
1717 if (m_dwContextMenus & GITSLC_POPIGNORE)
1720 CTGitPathList ignorelist;
1721 FillListOfSelectedItemPaths(ignorelist);
1722 //check if all selected entries have the same extension
1723 bool bSameExt = true;
1724 CString sExt;
1725 for (int i=0; i<ignorelist.GetCount(); ++i)
1727 if (sExt.IsEmpty() && (i==0))
1728 sExt = ignorelist[i].GetFileExtension();
1729 else if (sExt.CompareNoCase(ignorelist[i].GetFileExtension())!=0)
1730 bSameExt = false;
1732 if (bSameExt)
1734 if (ignoreSubMenu.CreateMenu())
1736 CString ignorepath;
1737 if (ignorelist.GetCount()==1)
1738 ignorepath = ignorelist[0].GetFileOrDirectoryName();
1739 else
1740 ignorepath.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
1741 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_IGNORE, ignorepath);
1742 ignorepath = _T("*")+sExt;
1743 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_IGNOREMASK, ignorepath);
1744 if (ignorelist.GetCount() == 1)
1745 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_IGNOREFOLDER, ignorelist[0].GetContainingDirectory().GetGitPathString());
1746 CString temp;
1747 temp.LoadString(IDS_MENUIGNORE);
1748 popup.InsertMenu((UINT)-1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)ignoreSubMenu.m_hMenu, temp);
1751 else
1753 CString temp;
1754 if (ignorelist.GetCount()==1)
1756 temp.LoadString(IDS_MENUIGNORE);
1758 else
1760 temp.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
1762 popup.AppendMenuIcon(IDGITLC_IGNORE, temp, IDI_IGNORE);
1770 if (GetSelectedCount() > 0)
1772 popup.AppendMenu(MF_SEPARATOR);
1773 popup.AppendMenuIcon(IDGITLC_COPY, IDS_STATUSLIST_CONTEXT_COPY, IDI_COPYCLIP);
1774 popup.AppendMenuIcon(IDGITLC_COPYEXT, IDS_STATUSLIST_CONTEXT_COPYEXT, IDI_COPYCLIP);
1775 #if 0
1776 if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS))
1777 &&(wcStatus != git_wc_status_unversioned)&&(wcStatus != git_wc_status_none))
1779 popup.AppendMenu(MF_SEPARATOR);
1780 // changelist commands
1781 size_t numChangelists = GetNumberOfChangelistsInSelection();
1782 if (numChangelists > 0)
1784 popup.AppendMenuIcon(IDSVNLC_REMOVEFROMCS, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS);
1786 if ((!entry->IsFolder())&&(changelistSubMenu.CreateMenu()))
1788 CString temp;
1789 temp.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS);
1790 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATECS, temp);
1792 if (entry->changelist.Compare(SVNSLC_IGNORECHANGELIST))
1794 changelistSubMenu.AppendMenu(MF_SEPARATOR);
1795 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATEIGNORECS, SVNSLC_IGNORECHANGELIST);
1798 if (!m_changelists.empty())
1800 // find the changelist names
1801 bool bNeedSeparator = true;
1802 int cmdID = IDSVNLC_MOVETOCS;
1803 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
1805 if ((entry->changelist.Compare(it->first))&&(it->first.Compare(SVNSLC_IGNORECHANGELIST)))
1807 if (bNeedSeparator)
1809 changelistSubMenu.AppendMenu(MF_SEPARATOR);
1810 bNeedSeparator = false;
1812 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, cmdID, it->first);
1813 cmdID++;
1817 temp.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS);
1818 popup.AppendMenu(MF_POPUP|MF_STRING, (UINT_PTR)changelistSubMenu.GetSafeHmenu(), temp);
1821 #endif
1824 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1826 m_bBlock = TRUE;
1827 AfxGetApp()->DoWaitCursor(1);
1828 //int iItemCountBeforeMenuCmd = GetItemCount();
1829 //bool bForce = false;
1830 switch (cmd)
1832 case IDGITLC_VIEWREV:
1833 OpenFile(filepath, ALTERNATIVEEDITOR);
1834 break;
1836 case IDGITLC_OPEN:
1837 OpenFile(filepath,OPEN);
1838 break;
1840 case IDGITLC_OPENWITH:
1841 OpenFile(filepath,OPEN_WITH);
1842 break;
1844 case IDGITLC_EXPLORE:
1846 ShellExecute(this->m_hWnd, _T("explore"), filepath->GetDirectory().GetWinPath(), NULL, NULL, SW_SHOW);
1848 break;
1850 case IDGITLC_CREATERESTORE:
1852 POSITION pos = GetFirstSelectedItemPosition();
1853 while (pos)
1855 int index = GetNextSelectedItem(pos);
1856 CTGitPath * entry2 = (CTGitPath * )GetItemData(index);
1857 ASSERT(entry2 != NULL);
1858 if (entry2 == NULL || entry2->IsDirectory())
1859 continue;
1860 if (m_restorepaths.find(entry2->GetWinPathString()) != m_restorepaths.end())
1861 continue;
1862 CTGitPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
1863 if (CopyFile(g_Git.m_CurrentDir + _T("\\") + entry2->GetWinPathString(), tempFile.GetWinPath(), FALSE))
1865 m_restorepaths[entry2->GetWinPathString()] = tempFile.GetWinPathString();
1866 SetItemState(index, INDEXTOOVERLAYMASK(OVL_RESTORE), LVIS_OVERLAYMASK);
1869 Invalidate();
1871 break;
1873 case IDGITLC_RESTOREPATH:
1875 if (CMessageBox::Show(m_hWnd, IDS_STATUSLIST_RESTOREPATH, IDS_APPNAME, 2, IDI_QUESTION, IDS_RESTOREBUTTON, IDS_ABORTBUTTON) == 2)
1876 break;
1877 POSITION pos = GetFirstSelectedItemPosition();
1878 while (pos)
1880 int index = GetNextSelectedItem(pos);
1881 CTGitPath * entry2 = (CTGitPath * )GetItemData(index);
1882 ASSERT(entry2 != NULL);
1883 if (entry2 == NULL)
1884 continue;
1885 if (m_restorepaths.find(entry2->GetWinPathString()) == m_restorepaths.end())
1886 continue;
1887 if (CopyFile(m_restorepaths[entry2->GetWinPathString()], g_Git.m_CurrentDir + _T("\\") + entry2->GetWinPathString(), FALSE))
1889 m_restorepaths.erase(entry2->GetWinPathString());
1890 SetItemState(index, 0, LVIS_OVERLAYMASK);
1893 Invalidate();
1895 break;
1897 // Compare current version and work copy.
1898 case IDGITLC_COMPAREWC:
1900 if (!CheckMultipleDiffs())
1901 break;
1902 POSITION pos = GetFirstSelectedItemPosition();
1903 while ( pos )
1905 int index = GetNextSelectedItem(pos);
1906 StartDiffWC(index);
1909 break;
1911 // Compare with base version. when current version is zero, compare workcopy and HEAD.
1912 case IDGITLC_COMPARE:
1914 if (!CheckMultipleDiffs())
1915 break;
1916 POSITION pos = GetFirstSelectedItemPosition();
1917 while ( pos )
1919 int index = GetNextSelectedItem(pos);
1920 StartDiff(index);
1923 break;
1925 case IDGITLC_COMPARETWO:
1927 POSITION pos = GetFirstSelectedItemPosition();
1928 while ( pos )
1930 int index = GetNextSelectedItem(pos);
1931 StartDiffTwo(index);
1934 break;
1936 case IDGITLC_COMPARETWOFILES:
1938 POSITION pos = GetFirstSelectedItemPosition();
1939 CTGitPath * firstfilepath = NULL, * secondfilepath = NULL;
1940 if (pos)
1942 firstfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
1943 ASSERT(firstfilepath != NULL);
1944 if (firstfilepath == NULL)
1945 break;
1947 secondfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
1948 ASSERT(secondfilepath != NULL);
1949 if (secondfilepath == NULL)
1950 break;
1952 CString sCmd;
1953 sCmd.Format(_T("/command:diff /path:\"%s\" /path2:\"%s\" /hwnd:%ld"), firstfilepath->GetWinPath(), secondfilepath->GetWinPath(), (unsigned long)m_hWnd);
1954 CAppUtils::RunTortoiseGitProc(sCmd);
1957 break;
1959 case IDGITLC_GNUDIFF1:
1961 POSITION pos = GetFirstSelectedItemPosition();
1962 while (pos)
1964 CTGitPath * selectedFilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
1965 if (m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
1967 CString fromwhere;
1968 if (m_amend)
1969 fromwhere = _T("~1");
1970 CAppUtils::StartShowUnifiedDiff(m_hWnd, *selectedFilepath, GitRev::GetHead() + fromwhere, *selectedFilepath, GitRev::GetWorkingCopy());
1972 else
1974 if ((selectedFilepath->m_ParentNo & (PARENT_MASK | MERGE_MASK)) == 0)
1975 CAppUtils::StartShowUnifiedDiff(m_hWnd, *selectedFilepath, m_CurrentVersion + _T("~1"), *selectedFilepath, m_CurrentVersion);
1976 else
1978 CString str;
1979 if (!(selectedFilepath->m_ParentNo & MERGE_MASK))
1980 str.Format(_T("%s^%d"), m_CurrentVersion, (selectedFilepath->m_ParentNo & PARENT_MASK) + 1);
1982 CAppUtils::StartShowUnifiedDiff(m_hWnd, *selectedFilepath, str, *selectedFilepath, m_CurrentVersion, false, false, false, !!(selectedFilepath->m_ParentNo & MERGE_MASK));
1987 break;
1989 case IDGITLC_GNUDIFF2:
1991 CAppUtils::StartShowUnifiedDiff(m_hWnd, *filepath, m_Rev2, *filepath, m_Rev1);
1993 break;
1995 case IDGITLC_ADD:
1997 CTGitPathList paths;
1998 FillListOfSelectedItemPaths(paths, true);
2000 CGitProgressDlg progDlg;
2001 progDlg.SetCommand(CGitProgressList::GitProgress_Add);
2002 progDlg.SetPathList(paths);
2003 progDlg.SetItemCount(paths.GetCount());
2004 progDlg.DoModal();
2006 // reset unchecked status
2007 POSITION pos = GetFirstSelectedItemPosition();
2008 int index;
2009 while ((index = GetNextSelectedItem(pos)) >= 0)
2011 m_mapFilenameToChecked.erase(((CTGitPath*)GetItemData(index))->GetGitPathString());
2014 if (NULL != GetLogicalParent() && NULL != GetLogicalParent()->GetSafeHwnd())
2015 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2017 SetRedraw(TRUE);
2019 break;
2021 case IDGITLC_DELETE:
2023 //Collect paths
2024 std::vector<int> selectIndex;
2026 POSITION pos = GetFirstSelectedItemPosition();
2027 int index;
2028 while ((index = GetNextSelectedItem(pos)) >= 0)
2030 selectIndex.push_back(index);
2033 //Create file-list ('\0' separated) for SHFileOperation
2034 CString filelist;
2035 for(int i=0;i<selectIndex.size();i++)
2037 index=selectIndex[i];
2039 CTGitPath * path=(CTGitPath*)GetItemData(index);
2040 ASSERT(path);
2041 if(path == NULL)
2042 continue;
2044 filelist += path->GetWinPathString();
2045 filelist += _T("|");
2047 filelist += _T("|");
2048 int len = filelist.GetLength();
2049 std::unique_ptr<TCHAR[]> buf(new TCHAR[len + 2]);
2050 _tcscpy_s(buf.get(), len + 2, filelist);
2051 for (int i=0; i<len; ++i)
2052 if (buf.get()[i] == '|')
2053 buf.get()[i] = 0;
2054 SHFILEOPSTRUCT fileop;
2055 fileop.hwnd = this->m_hWnd;
2056 fileop.wFunc = FO_DELETE;
2057 fileop.pFrom = buf.get();
2058 fileop.pTo = NULL;
2059 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
2060 fileop.lpszProgressTitle = _T("deleting file");
2061 int result = SHFileOperation(&fileop);
2063 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
2065 SetRedraw(FALSE);
2066 POSITION pos = NULL;
2067 while ((pos = GetFirstSelectedItemPosition()) != 0)
2069 int index = GetNextSelectedItem(pos);
2070 if (GetCheck(index))
2071 m_nSelected--;
2072 m_nTotal--;
2074 RemoveListEntry(index);
2076 SetRedraw(TRUE);
2079 break;
2081 case IDGITLC_BLAME:
2083 CAppUtils::LaunchTortoiseBlame(g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath(), m_CurrentVersion);
2085 break;
2087 case IDGITLC_LOG:
2088 case IDGITLC_LOGSUBMODULE:
2090 CString sCmd;
2091 sCmd.Format(_T("/command:log /path:\"%s\""), g_Git.m_CurrentDir + _T("\\") + filepath->GetWinPath());
2092 if (cmd == IDGITLC_LOG && filepath->IsDirectory())
2093 sCmd += _T(" /submodule");
2094 CAppUtils::RunTortoiseGitProc(sCmd, false, !(cmd == IDGITLC_LOGSUBMODULE));
2096 break;
2098 case IDGITLC_LOGOLDNAME:
2100 CTGitPath oldName(filepath->GetGitOldPathString());
2101 CString sCmd;
2102 sCmd.Format(_T("/command:log /path:\"%s\""), g_Git.m_CurrentDir + _T("\\") + oldName.GetWinPath());
2103 CAppUtils::RunTortoiseGitProc(sCmd);
2105 break;
2107 case IDGITLC_EDITCONFLICT:
2109 if (CAppUtils::ConflictEdit(*filepath, false, this->m_bIsRevertTheirMy))
2111 CString conflictedFile = g_Git.m_CurrentDir + _T("\\") + filepath->GetWinPathString();
2112 if (!PathFileExists(conflictedFile) && NULL != GetLogicalParent() && NULL != GetLogicalParent()->GetSafeHwnd())
2113 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2116 break;
2118 case IDGITLC_RESOLVETHEIRS: //follow up
2119 case IDGITLC_RESOLVEMINE: //follow up
2120 case IDGITLC_RESOLVECONFLICT:
2122 if (CMessageBox::Show(m_hWnd, IDS_PROC_RESOLVE, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO)==IDYES)
2124 POSITION pos = GetFirstSelectedItemPosition();
2125 while (pos != 0)
2127 int index;
2128 index = GetNextSelectedItem(pos);
2129 CTGitPath * fentry =(CTGitPath*) this->GetItemData(index);
2130 if(fentry == NULL)
2131 continue;
2132 CString gitcmd,output;
2133 output.Empty();
2135 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVETHEIRS) ||
2136 ((this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVEMINE) )
2138 gitcmd.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry->GetGitPathString());
2139 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2141 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2142 continue;
2145 output.Empty();
2146 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVEMINE) ||
2147 ((this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVETHEIRS) )
2149 gitcmd.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry->GetGitPathString());
2150 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2152 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2153 continue;
2157 output.Empty();
2158 if ( fentry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
2160 gitcmd.Format(_T("git.exe add -f -- \"%s\""),fentry->GetGitPathString());
2161 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2163 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2165 else
2167 fentry->m_Action |= CTGitPath::LOGACTIONS_MODIFIED;
2168 fentry->m_Action &=~CTGitPath::LOGACTIONS_UNMERGED;
2172 CAppUtils::RemoveTempMergeFile(*fentry);
2175 Show(m_dwShow, 0, m_bShowFolders,0,true);
2178 break;
2180 case IDGITLC_IGNORE:
2182 CTGitPathList ignorelist;
2183 //std::vector<CString> toremove;
2184 FillListOfSelectedItemPaths(ignorelist, true);
2186 if(!CAppUtils::IgnoreFile(ignorelist,false))
2187 break;
2189 SetRedraw(FALSE);
2190 CWnd* pParent = GetLogicalParent();
2191 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2193 pParent->SendMessage(GITSLNM_NEEDSREFRESH);
2195 SetRedraw(TRUE);
2197 break;
2199 case IDGITLC_IGNOREMASK:
2201 CString common;
2202 CString ext=filepath->GetFileExtension();
2203 CTGitPathList ignorelist;
2204 FillListOfSelectedItemPaths(ignorelist, true);
2206 if (!CAppUtils::IgnoreFile(ignorelist,true))
2207 break;
2209 SetRedraw(FALSE);
2210 CWnd* pParent = GetLogicalParent();
2211 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2213 pParent->SendMessage(GITSLNM_NEEDSREFRESH);
2216 SetRedraw(TRUE);
2218 break;
2220 case IDGITLC_IGNOREFOLDER:
2222 CTGitPathList ignorelist;
2223 ignorelist.AddPath(filepath->GetContainingDirectory());
2225 if (!CAppUtils::IgnoreFile(ignorelist, false))
2226 break;
2228 SetRedraw(FALSE);
2229 CWnd *pParent = GetLogicalParent();
2230 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2231 pParent->SendMessage(GITSLNM_NEEDSREFRESH);
2233 SetRedraw(TRUE);
2235 break;
2237 case IDGITLC_REVERT:
2239 // If at least one item is not in the status "added"
2240 // we ask for a confirmation
2241 BOOL bConfirm = FALSE;
2242 POSITION pos = GetFirstSelectedItemPosition();
2243 int index;
2244 while ((index = GetNextSelectedItem(pos)) >= 0)
2246 //FileEntry * fentry = GetListEntry(index);
2247 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
2248 if(fentry && fentry->m_Action &CTGitPath::LOGACTIONS_MODIFIED && !fentry->IsDirectory())
2250 bConfirm = TRUE;
2251 break;
2255 CString str;
2256 str.Format(IDS_PROC_WARNREVERT,GetSelectedCount());
2258 if (!bConfirm || CMessageBox::Show(this->m_hWnd, str, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION)==IDYES)
2260 CTGitPathList targetList;
2261 FillListOfSelectedItemPaths(targetList);
2263 // make sure that the list is reverse sorted, so that
2264 // children are removed before any parents
2265 targetList.SortByPathname(true);
2267 // put all reverted files in the trashbin, except the ones with 'added'
2268 // status because they are not restored by the revert.
2269 CTGitPathList delList;
2270 POSITION pos = GetFirstSelectedItemPosition();
2271 int index;
2272 while ((index = GetNextSelectedItem(pos)) >= 0)
2274 CTGitPath *entry=(CTGitPath *)GetItemData(index);
2275 if (entry&&(!(entry->m_Action& CTGitPath::LOGACTIONS_ADDED))
2276 && (!(entry->m_Action& CTGitPath::LOGACTIONS_REPLACED)) && !entry->IsDirectory())
2278 CTGitPath fullpath;
2279 fullpath.SetFromWin(g_Git.m_CurrentDir+_T("\\")+entry->GetWinPath());
2280 delList.AddPath(fullpath);
2283 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2284 delList.DeleteAllFiles(true);
2286 CString revertToCommit = _T("HEAD");
2287 if (m_amend)
2288 revertToCommit = _T("HEAD~1");
2289 if (g_Git.Revert(revertToCommit, targetList))
2291 CMessageBox::Show(this->m_hWnd, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR);
2293 else
2295 bool updateStatusList = false;
2296 for(int i=0;i<targetList.GetCount();i++)
2298 int nListboxEntries = GetItemCount();
2299 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2301 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2302 if (path->GetGitPathString()==targetList[i].GetGitPathString() && !path->IsDirectory())
2304 if(path->m_Action & CTGitPath::LOGACTIONS_ADDED)
2306 path->m_Action = CTGitPath::LOGACTIONS_UNVER;
2307 SetEntryCheck(path,nItem,false);
2308 updateStatusList = true;
2309 SetItemGroup(nItem,1);
2310 this->m_StatusFileList.RemoveItem(*path);
2311 this->m_UnRevFileList.AddPath(*path);
2312 //this->m_IgnoreFileList.RemoveItem(*path);
2315 else
2317 RemoveListEntry(nItem);
2319 break;
2321 else if (path->GetGitPathString()==targetList[i].GetGitPathString() && path->IsDirectory() && path->IsWCRoot())
2323 CString sCmd;
2324 sCmd.Format(_T("/command:revert /path:\"%s\""), path->GetGitPathString());
2325 CCommonAppUtils::RunTortoiseGitProc(sCmd);
2329 SetRedraw(TRUE);
2330 SaveColumnWidths();
2331 Show(m_dwShow, 0, m_bShowFolders,updateStatusList,true);
2332 NotifyCheck();
2336 break;
2338 case IDGITLC_ASSUMEVALID:
2340 if (CMessageBox::Show(GetSafeHwnd(), IDS_PROC_MARK_ASSUMEVALID, IDS_APPNAME, MB_YESNO | MB_DEFBUTTON2 | MB_ICONQUESTION) == IDNO)
2341 break;
2342 CString cmdTemplate;
2343 cmdTemplate = _T("git.exe update-index --assume-unchanged \"%s\"");
2344 POSITION pos = GetFirstSelectedItemPosition();
2345 int index = -1;
2346 while ((index = GetNextSelectedItem(pos)) >= 0)
2348 CTGitPath * path = (CTGitPath *)GetItemData(index);
2349 ASSERT(path);
2350 if(path == NULL)
2351 continue;
2353 CString cmd, output;
2354 cmd.Format(cmdTemplate, path->GetGitPathString());
2355 if (g_Git.Run(cmd, &output, CP_UTF8))
2357 MessageBox(output, _T("TortoiseGit"), MB_ICONERROR);
2360 if (NULL != GetLogicalParent() && NULL != GetLogicalParent()->GetSafeHwnd())
2361 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2363 SetRedraw(TRUE);
2365 break;
2366 case IDGITLC_SKIPWORKTREE:
2368 if (CMessageBox::Show(GetSafeHwnd(), IDS_PROC_MARK_SKIPWORKTREE, IDS_APPNAME, MB_YESNO | MB_DEFBUTTON2 | MB_ICONQUESTION) == IDNO)
2369 break;
2370 CString cmdTemplate;
2371 cmdTemplate = _T("git.exe update-index --skip-worktree \"%s\"");
2372 POSITION pos = GetFirstSelectedItemPosition();
2373 int index = -1;
2374 while ((index = GetNextSelectedItem(pos)) >= 0)
2376 CTGitPath * path = (CTGitPath *)GetItemData(index);
2377 ASSERT(path);
2378 if(path == NULL)
2379 continue;
2381 CString cmd, output;
2382 cmd.Format(cmdTemplate, path->GetGitPathString());
2383 if (g_Git.Run(cmd, &output, CP_UTF8))
2385 MessageBox(output, _T("TortoiseGit"), MB_ICONERROR);
2388 if (NULL != GetLogicalParent() && NULL != GetLogicalParent()->GetSafeHwnd())
2389 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2391 SetRedraw(TRUE);
2393 break;
2394 case IDGITLC_COPY:
2395 CopySelectedEntriesToClipboard(0);
2396 break;
2397 case IDGITLC_COPYEXT:
2398 CopySelectedEntriesToClipboard((DWORD)-1);
2399 break;
2400 case IDGITLC_EXPORT:
2401 FilesExport();
2402 break;
2403 case IDGITLC_SAVEAS:
2404 FileSaveAs(filepath);
2405 break;
2407 case IDGITLC_REVERTTOREV:
2408 RevertSelectedItemToVersion();
2409 break;
2410 case IDGITLC_REVERTTOPARENT:
2411 RevertSelectedItemToVersion(true);
2412 break;
2413 #if 0
2414 case IDSVNLC_COMMIT:
2416 CTSVNPathList targetList;
2417 FillListOfSelectedItemPaths(targetList);
2418 CTSVNPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
2419 VERIFY(targetList.WriteToFile(tempFile.GetWinPathString()));
2420 CString commandline = CPathUtils::GetAppDirectory();
2421 commandline += _T("TortoiseGitProc.exe /command:commit /pathfile:\"");
2422 commandline += tempFile.GetWinPathString();
2423 commandline += _T("\"");
2424 commandline += _T(" /deletepathfile");
2425 CAppUtils::LaunchApplication(commandline, NULL, false);
2427 break;
2428 case IDSVNLC_CREATEIGNORECS:
2429 CreateChangeList(SVNSLC_IGNORECHANGELIST);
2430 break;
2431 case IDSVNLC_CREATECS:
2433 CCreateChangelistDlg dlg;
2434 if (dlg.DoModal() == IDOK)
2436 CreateChangeList(dlg.m_sName);
2439 break;
2440 default:
2442 if (cmd < IDSVNLC_MOVETOCS)
2443 break;
2444 CTSVNPathList changelistItems;
2445 FillListOfSelectedItemPaths(changelistItems);
2447 // find the changelist name
2448 CString sChangelist;
2449 int cmdID = IDSVNLC_MOVETOCS;
2450 SetRedraw(FALSE);
2451 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
2453 if ((it->first.Compare(SVNSLC_IGNORECHANGELIST))&&(entry->changelist.Compare(it->first)))
2455 if (cmd == cmdID)
2457 sChangelist = it->first;
2459 cmdID++;
2462 if (!sChangelist.IsEmpty())
2464 SVN git;
2465 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
2467 // The changelists were moved, but we now need to run through the selected items again
2468 // and update their changelist
2469 POSITION pos = GetFirstSelectedItemPosition();
2470 int index;
2471 while ((index = GetNextSelectedItem(pos)) >= 0)
2473 FileEntry * e = GetListEntry(index);
2474 e->changelist = sChangelist;
2475 if (!e->IsFolder())
2477 if (m_changelists.find(e->changelist)!=m_changelists.end())
2478 SetItemGroup(index, m_changelists[e->changelist]);
2479 else
2480 SetItemGroup(index, 0);
2484 else
2486 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
2489 SetRedraw(TRUE);
2491 break;
2492 #endif
2494 } // switch (cmd)
2495 m_bBlock = FALSE;
2496 AfxGetApp()->DoWaitCursor(-1);
2497 GetStatisticsString();
2498 //int iItemCountAfterMenuCmd = GetItemCount();
2499 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
2501 // CWnd* pParent = GetParent();
2502 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2503 // {
2504 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
2505 // }
2507 } // if (popup.CreatePopupMenu())
2508 } // if (selIndex >= 0)
2512 void CGitStatusListCtrl::OnContextMenuHeader(CWnd * pWnd, CPoint point)
2514 Locker lock(m_critSec);
2515 m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
2518 void CGitStatusListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
2521 if (pWnd == this)
2523 OnContextMenuList(pWnd, point);
2524 } // if (pWnd == this)
2525 else if (pWnd == GetHeaderCtrl())
2527 OnContextMenuHeader(pWnd, point);
2531 void CGitStatusListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
2534 Locker lock(m_critSec);
2535 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2536 *pResult = 0;
2537 if (m_bBlock)
2538 return;
2540 if (pNMLV->iItem < 0)
2542 if (!IsGroupViewEnabled())
2543 return;
2544 POINT pt;
2545 DWORD ptW = GetMessagePos();
2546 pt.x = GET_X_LPARAM(ptW);
2547 pt.y = GET_Y_LPARAM(ptW);
2548 ScreenToClient(&pt);
2549 int group = GetGroupFromPoint(&pt);
2550 if (group < 0)
2551 return;
2552 // check/uncheck the whole group depending on the check-state
2553 // of the first item in the group
2554 m_bBlock = true;
2555 bool bCheck = false;
2556 bool bFirst = false;
2557 LVITEM lv;
2558 for (int i=0; i<GetItemCount(); ++i)
2560 SecureZeroMemory(&lv, sizeof(LVITEM));
2561 lv.mask = LVIF_GROUPID;
2562 lv.iItem = i;
2563 GetItem(&lv);
2564 if (lv.iGroupId == group)
2566 CTGitPath *entry=(CTGitPath*)GetItemData(i);
2568 if (!bFirst)
2570 bCheck = !GetCheck(i);
2571 bFirst = true;
2573 if (entry)
2575 bool bOldCheck = !!GetCheck(i);
2576 SetEntryCheck(entry, i, bCheck);
2577 if (bCheck != bOldCheck)
2579 if (bCheck)
2580 m_nSelected++;
2581 else
2582 m_nSelected--;
2587 GetStatisticsString();
2588 m_bBlock = false;
2589 NotifyCheck();
2590 return;
2593 CTGitPath *file=(CTGitPath*)GetItemData(pNMLV->iItem);
2595 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER) {
2596 OpenFile(file, OPEN);
2597 return;
2599 if( file->m_Action&CTGitPath::LOGACTIONS_UNMERGED )
2601 if (CAppUtils::ConflictEdit(*file, false, m_bIsRevertTheirMy))
2603 CString conflictedFile = g_Git.m_CurrentDir + _T("\\") + file->GetWinPathString();
2604 if (!PathFileExists(conflictedFile) && NULL != GetLogicalParent() && NULL != GetLogicalParent()->GetSafeHwnd())
2605 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2608 else
2610 if( (!m_Rev1.IsEmpty()) || (!m_Rev1.IsEmpty())) // m_Rev1 twice???
2611 StartDiffTwo(pNMLV->iItem);
2612 else
2613 StartDiff(pNMLV->iItem);
2617 void CGitStatusListCtrl::StartDiffTwo(int fileindex)
2619 if(fileindex<0)
2620 return;
2622 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
2624 CGitDiff::Diff(&file1,&file1,
2625 m_Rev1,
2626 m_Rev2);
2629 void CGitStatusListCtrl::StartDiffWC(int fileindex)
2631 if(fileindex<0)
2632 return;
2634 CString Ver;
2635 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
2636 return;
2638 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
2640 CGitDiff::Diff(&file1,&file1, GIT_REV_ZERO, m_CurrentVersion);
2644 void CGitStatusListCtrl::StartDiff(int fileindex)
2646 if(fileindex<0)
2647 return;
2649 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
2650 CTGitPath file2;
2651 if(file1.m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
2653 file2.SetFromGit(file1.GetGitOldPathString());
2655 else
2657 file2=file1;
2660 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
2662 CString fromwhere;
2663 if(m_amend && (file1.m_Action & CTGitPath::LOGACTIONS_ADDED) == 0)
2664 fromwhere = _T("~1");
2665 if( g_Git.IsInitRepos())
2666 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
2667 GIT_REV_ZERO);
2668 else if( file1.m_Action&CTGitPath::LOGACTIONS_ADDED )
2669 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
2670 m_CurrentVersion+fromwhere,true);
2671 else if( file1.m_Action&CTGitPath::LOGACTIONS_DELETED )
2672 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
2673 GitRev::GetHead()+fromwhere,false);
2674 else
2675 CGitDiff::Diff(&file1,&file2,
2676 CString(GIT_REV_ZERO),
2677 GitRev::GetHead()+fromwhere);
2679 else
2681 GitRev rev;
2682 CString fromwhere = m_CurrentVersion+_T("~1");
2683 if(m_amend)
2684 fromwhere = m_CurrentVersion+_T("~2");
2685 if (rev.GetCommit(fromwhere) || (file1.m_Action & file1.LOGACTIONS_ADDED))
2687 CGitDiff::DiffNull(&file1,m_CurrentVersion,true);
2690 else if (file1.m_Action & file1.LOGACTIONS_DELETED)
2692 if (file1.m_ParentNo > 0)
2693 fromwhere.Format(_T("%s^%d"), m_CurrentVersion, file1.m_ParentNo + 1);
2695 CGitDiff::DiffNull(&file1,fromwhere,false);
2697 else
2699 if( file1.m_ParentNo & MERGE_MASK)
2702 CTGitPath base, theirs, mine, merge;
2704 CString temppath;
2705 GetTempPath(temppath);
2706 temppath.TrimRight(_T("\\"));
2708 mine.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".LOCAL") + file1.GetFileExtension());
2709 theirs.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".REMOTE") + file1.GetFileExtension());
2710 base.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".BASE") + file1.GetFileExtension());
2712 CFile tempfile;
2713 //create a empty file, incase stage is not three
2714 tempfile.Open(mine.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
2715 tempfile.Close();
2716 tempfile.Open(theirs.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
2717 tempfile.Close();
2718 tempfile.Open(base.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
2719 tempfile.Close();
2721 merge.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".Merged") + file1.GetFileExtension());
2723 int parent1=-1, parent2 =-1;
2724 for(int i=0;i<this->m_arStatusArray.size();i++)
2726 if(m_arStatusArray[i]->GetGitPathString() == file1.GetGitPathString())
2728 if(m_arStatusArray[i]->m_ParentNo & MERGE_MASK)
2731 else
2733 if(parent1<0)
2735 parent1 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
2737 else if (parent2 <0)
2739 parent2 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
2745 if(g_Git.GetOneFile(m_CurrentVersion, file1, (CString&)merge.GetWinPathString()))
2747 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2750 if(parent1>=0)
2752 CString str;
2753 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent1+1);
2755 if(g_Git.GetOneFile(str, file1, (CString&)mine.GetWinPathString()))
2757 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2761 if(parent2>=0)
2763 CString str;
2764 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent2+1);
2766 if(g_Git.GetOneFile(str, file1, (CString&)theirs.GetWinPathString()))
2768 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2772 if(parent1>=0 && parent2>=0)
2774 CString cmd, output;
2775 cmd.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion, parent1+1,
2776 this->m_CurrentVersion,parent2+1);
2778 if (g_Git.Run(cmd, &output, NULL, CP_UTF8))
2781 else
2783 if(g_Git.GetOneFile(output.Left(40), file1, (CString&)base.GetWinPathString()))
2785 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETBASEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2789 CAppUtils::StartExtMerge(base, theirs, mine, merge,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
2792 else
2794 CString str;
2795 if( (file1.m_ParentNo&PARENT_MASK) == 0)
2797 str = _T("~1");
2799 else
2801 str.Format(_T("^%d"), (file1.m_ParentNo&PARENT_MASK)+1);
2803 CGitDiff::Diff(&file1,&file2,
2804 m_CurrentVersion,
2805 m_CurrentVersion+str);
2811 CString CGitStatusListCtrl::GetStatisticsString(bool simple)
2814 CString sNormal, sAdded, sDeleted, sModified, sConflicted, sUnversioned, sRenamed;
2815 WORD langID = (WORD)(DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
2816 TCHAR buf[MAX_STATUS_STRING_LENGTH];
2817 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal, buf, _countof(buf), langID);
2818 sNormal = buf;
2819 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added, buf, _countof(buf), langID);
2820 sAdded = buf;
2821 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted, buf, _countof(buf), langID);
2822 sDeleted = buf;
2823 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified, buf, _countof(buf), langID);
2824 sModified = buf;
2825 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted, buf, _countof(buf), langID);
2826 sConflicted = buf;
2827 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned, buf, _countof(buf), langID);
2828 sUnversioned = buf;
2829 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced, buf, _countof(buf), langID);
2830 sRenamed = buf;
2831 CString sToolTip;
2832 if(simple)
2834 sToolTip.Format(IDS_STATUSLIST_STATUSLINE1,
2835 this->m_nLineAdded,this->m_nLineDeleted,
2836 (LPCTSTR)sModified, m_nModified,
2837 (LPCTSTR)sAdded, m_nAdded,
2838 (LPCTSTR)sDeleted, m_nDeleted,
2839 (LPCTSTR)sRenamed, m_nRenamed
2842 else
2844 sToolTip.Format(IDS_STATUSLIST_STATUSLINE2,
2845 this->m_nLineAdded,this->m_nLineDeleted,
2846 (LPCTSTR)sNormal, m_nNormal,
2847 (LPCTSTR)sUnversioned, m_nUnversioned,
2848 (LPCTSTR)sModified, m_nModified,
2849 (LPCTSTR)sAdded, m_nAdded,
2850 (LPCTSTR)sDeleted, m_nDeleted,
2851 (LPCTSTR)sConflicted, m_nConflicted
2854 CString sStats;
2855 sStats.Format(IDS_COMMITDLG_STATISTICSFORMAT, m_nSelected, GetItemCount());
2856 if (m_pStatLabel)
2858 m_pStatLabel->SetWindowText(sStats);
2861 if (m_pSelectButton)
2863 if (m_nSelected == 0)
2864 m_pSelectButton->SetCheck(BST_UNCHECKED);
2865 else if (m_nSelected != GetItemCount())
2866 m_pSelectButton->SetCheck(BST_INDETERMINATE);
2867 else
2868 m_pSelectButton->SetCheck(BST_CHECKED);
2871 if (m_pConfirmButton)
2873 m_pConfirmButton->EnableWindow(m_nSelected>0);
2876 return sToolTip;
2881 CString CGitStatusListCtrl::GetCommonDirectory(bool bStrict)
2883 if (!bStrict)
2885 // not strict means that the selected folder has priority
2886 if (!m_StatusFileList.GetCommonDirectory().IsEmpty())
2887 return m_StatusFileList.GetCommonDirectory().GetWinPath();
2890 CTGitPath commonBaseDirectory;
2891 int nListItems = GetItemCount();
2892 for (int i=0; i<nListItems; ++i)
2894 CTGitPath baseDirectory,*p= (CTGitPath*)this->GetItemData(i);
2895 ASSERT(p);
2896 if(p==NULL)
2897 continue;
2898 baseDirectory = p->GetDirectory();
2900 if(commonBaseDirectory.IsEmpty())
2902 commonBaseDirectory = baseDirectory;
2904 else
2906 if (commonBaseDirectory.GetWinPathString().GetLength() > baseDirectory.GetWinPathString().GetLength())
2908 if (baseDirectory.IsAncestorOf(commonBaseDirectory))
2909 commonBaseDirectory = baseDirectory;
2913 return g_Git.m_CurrentDir+CString(_T("\\"))+commonBaseDirectory.GetWinPath();
2917 void CGitStatusListCtrl::SelectAll(bool bSelect, bool /*bIncludeNoCommits*/)
2919 CWaitCursor waitCursor;
2920 // block here so the LVN_ITEMCHANGED messages
2921 // get ignored
2922 m_bBlock = TRUE;
2923 SetRedraw(FALSE);
2925 int nListItems = GetItemCount();
2926 if (bSelect)
2927 m_nSelected = nListItems;
2928 else
2929 m_nSelected = 0;
2931 for (int i=0; i<nListItems; ++i)
2933 //FileEntry * entry = GetListEntry(i);
2934 //ASSERT(entry != NULL);
2935 CTGitPath *path = (CTGitPath *) GetItemData(i);
2936 if (path == NULL)
2937 continue;
2938 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
2939 SetEntryCheck(path,i,bSelect);
2942 // unblock before redrawing
2943 m_bBlock = FALSE;
2944 SetRedraw(TRUE);
2945 GetStatisticsString();
2946 NotifyCheck();
2949 void CGitStatusListCtrl::Check(DWORD dwCheck, bool check)
2951 CWaitCursor waitCursor;
2952 // block here so the LVN_ITEMCHANGED messages
2953 // get ignored
2954 m_bBlock = TRUE;
2955 SetRedraw(FALSE);
2957 int nListItems = GetItemCount();
2959 for (int i = 0; i < nListItems; ++i)
2961 CTGitPath *entry = (CTGitPath *) GetItemData(i);
2962 if (entry == NULL)
2963 continue;
2965 DWORD showFlags = entry->m_Action;
2966 if (entry->IsDirectory())
2967 showFlags |= GITSLC_SHOWSUBMODULES;
2968 else
2969 showFlags |= GITSLC_SHOWFILES;
2971 if (check && (showFlags & dwCheck) && !GetCheck(i) && !(entry->IsDirectory() && m_bDoNotAutoselectSubmodules && !(dwCheck & GITSLC_SHOWSUBMODULES)))
2973 SetEntryCheck(entry, i, true);
2974 m_nSelected++;
2976 else if (!check && (showFlags & dwCheck) && GetCheck(i))
2978 SetEntryCheck(entry, i, false);
2979 m_nSelected--;
2982 // unblock before redrawing
2983 m_bBlock = FALSE;
2984 SetRedraw(TRUE);
2985 GetStatisticsString();
2986 NotifyCheck();
2989 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)
2991 LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);
2992 *pResult = 0;
2993 if (m_bBlock)
2994 return;
2996 CTGitPath *entry=(CTGitPath *)GetItemData(pGetInfoTip->iItem);
2998 if (entry)
2999 if (pGetInfoTip->cchTextMax > entry->GetGitPathString().GetLength() + g_Git.m_CurrentDir.GetLength())
3001 CString str;
3002 str += g_Git.m_CurrentDir;
3003 str += _T("\\");
3004 str += entry->GetWinPathString();
3006 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, str.GetBuffer(), str.GetLength());
3010 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
3012 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
3014 // Take the default processing unless we set this to something else below.
3015 *pResult = CDRF_DODEFAULT;
3017 // First thing - check the draw stage. If it's the control's prepaint
3018 // stage, then tell Windows we want messages for every item.
3020 switch (pLVCD->nmcd.dwDrawStage)
3022 case CDDS_PREPAINT:
3023 *pResult = CDRF_NOTIFYITEMDRAW;
3024 break;
3025 case CDDS_ITEMPREPAINT:
3027 // This is the prepaint stage for an item. Here's where we set the
3028 // item's text color. Our return value will tell Windows to draw the
3029 // item itself, but it will use the new color we set here.
3031 // Tell Windows to paint the control itself.
3032 *pResult = CDRF_DODEFAULT;
3033 if (m_bBlock)
3034 return;
3036 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
3038 if (m_arStatusArray.size() > (DWORD_PTR)pLVCD->nmcd.dwItemSpec)
3041 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3042 CTGitPath *entry=(CTGitPath *)GetItemData((int)pLVCD->nmcd.dwItemSpec);
3043 if (entry == NULL)
3044 return;
3046 // coloring
3047 // ========
3048 // black : unversioned, normal
3049 // purple : added
3050 // blue : modified
3051 // brown : missing, deleted, replaced
3052 // green : merged (or potential merges)
3053 // red : conflicts or sure conflicts
3054 if(entry->m_Action & CTGitPath::LOGACTIONS_GRAY)
3056 crText = RGB(128,128,128);
3059 else if(entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
3061 crText = m_Colors.GetColor(CColors::Conflict);
3064 else if(entry->m_Action & (CTGitPath::LOGACTIONS_MODIFIED))
3066 crText = m_Colors.GetColor(CColors::Modified);
3069 else if(entry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
3071 crText = m_Colors.GetColor(CColors::Added);
3073 else if(entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
3075 crText = m_Colors.GetColor(CColors::DeletedNode);
3077 else if(entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
3079 crText = m_Colors.GetColor(CColors::RenamedNode);
3081 else if(entry->m_Action & CTGitPath::LOGACTIONS_MERGED)
3083 crText = m_Colors.GetColor(CColors::Merged);
3085 else
3087 crText = GetSysColor(COLOR_WINDOWTEXT);
3089 // Store the color back in the NMLVCUSTOMDRAW struct.
3090 pLVCD->clrText = crText;
3093 break;
3097 BOOL CGitStatusListCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
3099 if (pWnd != this)
3100 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
3101 if (!m_bBlock)
3103 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
3104 SetCursor(hCur);
3105 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
3107 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
3108 SetCursor(hCur);
3109 return TRUE;
3112 void CGitStatusListCtrl::RemoveListEntry(int index)
3115 Locker lock(m_critSec);
3116 DeleteItem(index);
3118 m_arStatusArray.erase(m_arStatusArray.begin()+index);
3120 #if 0
3121 delete m_arStatusArray[m_arListArray[index]];
3122 m_arStatusArray.erase(m_arStatusArray.begin()+m_arListArray[index]);
3123 m_arListArray.erase(m_arListArray.begin()+index);
3124 for (int i=index; i< (int)m_arListArray.size(); ++i)
3126 m_arListArray[i]--;
3128 #endif
3131 ///< Set a checkbox on an entry in the listbox
3132 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
3133 void CGitStatusListCtrl::SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck)
3135 pEntry->m_Checked = bCheck;
3136 m_mapFilenameToChecked[pEntry->GetGitPathString()] = bCheck;
3137 SetCheck(listboxIndex, bCheck);
3140 #if 0
3141 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck)
3144 int nListItems = GetItemCount();
3145 for (int j=0; j< nListItems ; ++j)
3147 FileEntry * childEntry = GetListEntry(j);
3148 ASSERT(childEntry != NULL);
3149 if (childEntry == NULL || childEntry == parentEntry)
3150 continue;
3151 if (childEntry->checked != bCheck)
3153 if (parentEntry->path.IsAncestorOf(childEntry->path))
3155 SetEntryCheck(childEntry,j,bCheck);
3156 if(bCheck)
3158 m_nSelected++;
3160 else
3162 m_nSelected--;
3169 #endif
3171 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList& pathList)
3174 pathList.Clear();
3175 int nListItems = GetItemCount();
3176 for (int i=0; i< nListItems; i++)
3178 CTGitPath * entry = (CTGitPath*)GetItemData(i);
3179 ASSERT(entry != NULL);
3180 if (entry->m_Checked)
3182 pathList.AddPath(*entry);
3185 pathList.SortByPathname();
3190 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
3191 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList& pathList, bool /*bNoIgnored*/)
3193 pathList.Clear();
3195 POSITION pos = GetFirstSelectedItemPosition();
3196 int index;
3197 while ((index = GetNextSelectedItem(pos)) >= 0)
3199 CTGitPath * entry = (CTGitPath*)GetItemData(index);
3200 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
3201 // continue;
3202 pathList.AddPath(*entry);
3206 UINT CGitStatusListCtrl::OnGetDlgCode()
3208 // we want to process the return key and not have that one
3209 // routed to the default pushbutton
3210 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS;
3213 void CGitStatusListCtrl::OnNMReturn(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3215 *pResult = 0;
3216 if (m_bBlock)
3217 return;
3218 if (!CheckMultipleDiffs())
3219 return;
3220 POSITION pos = GetFirstSelectedItemPosition();
3221 while ( pos )
3223 int index = GetNextSelectedItem(pos);
3224 CTGitPath *file=(CTGitPath*)GetItemData(index);
3225 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER)
3227 OpenFile(file, OPEN);
3229 else
3231 if( (!m_Rev1.IsEmpty()) || (!m_Rev1.IsEmpty())) // m_Rev1 twice???
3232 StartDiffTwo(index);
3233 else
3234 StartDiff(index);
3239 void CGitStatusListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
3241 // Since we catch all keystrokes (to have the enter key processed here instead
3242 // of routed to the default pushbutton) we have to make sure that other
3243 // keys like Tab and Esc still do what they're supposed to do
3244 // Tab = change focus to next/previous control
3245 // Esc = quit the dialog
3246 switch (nChar)
3248 case (VK_TAB):
3250 ::PostMessage(GetLogicalParent()->GetSafeHwnd(), WM_NEXTDLGCTL, GetKeyState(VK_SHIFT)&0x8000, 0);
3251 return;
3253 break;
3254 case (VK_ESCAPE):
3256 ::SendMessage(GetLogicalParent()->GetSafeHwnd(), WM_CLOSE, 0, 0);
3258 break;
3261 CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
3264 void CGitStatusListCtrl::PreSubclassWindow()
3266 CListCtrl::PreSubclassWindow();
3267 EnableToolTips(TRUE);
3268 SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);
3271 INT_PTR CGitStatusListCtrl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
3273 int row, col;
3274 RECT cellrect;
3275 row = CellRectFromPoint(point, &cellrect, &col );
3277 if (row == -1)
3278 return -1;
3281 pTI->hwnd = m_hWnd;
3282 pTI->uId = (UINT)((row<<10)+(col&0x3ff)+1);
3283 pTI->lpszText = LPSTR_TEXTCALLBACK;
3285 pTI->rect = cellrect;
3287 return pTI->uId;
3290 int CGitStatusListCtrl::CellRectFromPoint(CPoint& point, RECT *cellrect, int *col) const
3292 int colnum;
3294 // Make sure that the ListView is in LVS_REPORT
3295 if ((GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
3296 return -1;
3298 // Get the top and bottom row visible
3299 int row = GetTopIndex();
3300 int bottom = row + GetCountPerPage();
3301 if (bottom > GetItemCount())
3302 bottom = GetItemCount();
3304 // Get the number of columns
3305 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
3306 int nColumnCount = pHeader->GetItemCount();
3308 // Loop through the visible rows
3309 for ( ;row <=bottom;row++)
3311 // Get bounding rect of item and check whether point falls in it.
3312 CRect rect;
3313 GetItemRect(row, &rect, LVIR_BOUNDS);
3314 if (rect.PtInRect(point))
3316 // Now find the column
3317 for (colnum = 0; colnum < nColumnCount; colnum++)
3319 int colwidth = GetColumnWidth(colnum);
3320 if (point.x >= rect.left && point.x <= (rect.left + colwidth))
3322 RECT rectClient;
3323 GetClientRect(&rectClient);
3324 if (col)
3325 *col = colnum;
3326 rect.right = rect.left + colwidth;
3328 // Make sure that the right extent does not exceed
3329 // the client area
3330 if (rect.right > rectClient.right)
3331 rect.right = rectClient.right;
3332 *cellrect = rect;
3333 return row;
3335 rect.left += colwidth;
3339 return -1;
3342 void CGitStatusListCtrl::OnPaint()
3344 Default();
3345 if ((m_bBusy)||(m_bEmpty))
3347 CString str;
3348 if (m_bBusy)
3350 if (m_sBusy.IsEmpty())
3351 str.LoadString(IDS_STATUSLIST_BUSYMSG);
3352 else
3353 str = m_sBusy;
3355 else
3357 if (m_sEmpty.IsEmpty())
3358 str.LoadString(IDS_STATUSLIST_EMPTYMSG);
3359 else
3360 str = m_sEmpty;
3362 COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
3363 COLORREF clrTextBk;
3364 if (IsWindowEnabled())
3365 clrTextBk = ::GetSysColor(COLOR_WINDOW);
3366 else
3367 clrTextBk = ::GetSysColor(COLOR_3DFACE);
3369 CRect rc;
3370 GetClientRect(&rc);
3371 CHeaderCtrl* pHC;
3372 pHC = GetHeaderCtrl();
3373 if (pHC != NULL)
3375 CRect rcH;
3376 pHC->GetItemRect(0, &rcH);
3377 rc.top += rcH.bottom;
3379 CDC* pDC = GetDC();
3381 CMyMemDC memDC(pDC, &rc);
3383 memDC.SetTextColor(clrText);
3384 memDC.SetBkColor(clrTextBk);
3385 memDC.FillSolidRect(rc, clrTextBk);
3386 rc.top += 10;
3387 CGdiObject * oldfont = memDC.SelectStockObject(DEFAULT_GUI_FONT);
3388 memDC.DrawText(str, rc, DT_CENTER | DT_VCENTER |
3389 DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
3390 memDC.SelectObject(oldfont);
3392 ReleaseDC(pDC);
3394 ValidateRect(NULL);
3397 // prevent users from extending our hidden (size 0) columns
3398 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3400 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3403 // prevent any function from extending our hidden (size 0) columns
3404 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3406 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3407 Default();
3410 void CGitStatusListCtrl::OnDestroy()
3412 SaveColumnWidths(true);
3413 CListCtrl::OnDestroy();
3416 void CGitStatusListCtrl::OnBeginDrag(NMHDR* /*pNMHDR*/, LRESULT* pResult)
3418 #if 0
3419 Locker lock(m_critSec);
3420 CDropFiles dropFiles; // class for creating DROPFILES struct
3422 int index;
3423 POSITION pos = GetFirstSelectedItemPosition();
3424 while ( (index = GetNextSelectedItem(pos)) >= 0 )
3426 FileEntry * fentry = m_arStatusArray[m_arListArray[index]];
3427 CTGitPath path = fentry->GetPath();
3428 dropFiles.AddFile( path.GetWinPathString() );
3431 if ( dropFiles.GetCount()>0 )
3433 m_bOwnDrag = true;
3434 dropFiles.CreateStructure();
3435 m_bOwnDrag = false;
3437 #endif
3438 *pResult = 0;
3441 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry /* = false */)
3443 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
3444 for (int col = 0; col <= maxcol; col++)
3445 if (m_ColumnManager.IsVisible (col))
3446 m_ColumnManager.ColumnResized (col);
3448 if (bSaveToRegistry)
3449 m_ColumnManager.WriteSettings();
3452 bool CGitStatusListCtrl::EnableFileDrop()
3454 m_bFileDropsEnabled = true;
3455 return true;
3458 bool CGitStatusListCtrl::HasPath(const CTGitPath& path)
3460 for (size_t i=0; i < m_arStatusArray.size(); i++)
3462 if (m_arStatusArray[i]->IsEquivalentTo(path))
3463 return true;
3466 return false;
3469 BOOL CGitStatusListCtrl::PreTranslateMessage(MSG* pMsg)
3471 if (pMsg->message == WM_KEYDOWN)
3473 switch (pMsg->wParam)
3475 case 'A':
3477 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
3479 // select all entries
3480 for (int i=0; i<GetItemCount(); ++i)
3482 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3484 return TRUE;
3487 break;
3488 case 'C':
3489 case VK_INSERT:
3491 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
3493 // copy all selected paths to the clipboard
3494 if (GetAsyncKeyState(VK_SHIFT)&0x8000)
3495 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS);
3496 else
3497 CopySelectedEntriesToClipboard(0);
3498 return TRUE;
3501 break;
3505 return CListCtrl::PreTranslateMessage(pMsg);
3508 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols)
3511 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
3512 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3514 CString sClipboard;
3515 CString temp;
3516 //TCHAR buf[100];
3517 if (GetSelectedCount() == 0)
3518 return false;
3520 // first add the column titles as the first line
3521 // We needn't head when only path copy
3522 //temp.LoadString(IDS_STATUSLIST_COLFILE);
3523 //sClipboard = temp;
3525 DWORD selection = 0;
3526 for (int i = 0, count = m_ColumnManager.GetColumnCount(); i < count; ++i)
3527 if ( ((dwCols == -1) && m_ColumnManager.IsVisible (i))
3528 || ((dwCols != 1) && (i < 32) && ((dwCols & (1 << i)) != 0)))
3530 sClipboard += _T("\t") + m_ColumnManager.GetName(i);
3532 if (i < 32)
3533 selection += 1 << i;
3536 if(dwCols)
3537 sClipboard += _T("\r\n");
3539 POSITION pos = GetFirstSelectedItemPosition();
3540 int index;
3541 while ((index = GetNextSelectedItem(pos)) >= 0)
3543 CTGitPath * entry = (CTGitPath*)GetItemData(index);
3544 if(entry == NULL)
3545 continue;
3547 sClipboard += entry->GetWinPathString();
3548 if (selection & GITSLC_COLFILENAME)
3550 sClipboard += _T("\t")+entry->GetFileOrDirectoryName();
3552 if (selection & GITSLC_COLEXT)
3554 sClipboard += _T("\t")+entry->GetFileExtension();
3557 if (selection & GITSLC_COLSTATUS)
3559 sClipboard += _T("\t")+entry->GetActionName();
3561 #if 0
3562 if (selection & SVNSLC_COLDATE)
3564 TCHAR datebuf[SVN_DATE_BUFFER];
3565 apr_time_t date = entry->last_commit_date;
3566 SVN::formatDate(datebuf, date, true);
3567 if (date)
3568 temp = datebuf;
3569 else
3570 temp.Empty();
3571 sClipboard += _T("\t")+temp;
3573 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
3574 ; i < count
3575 ; ++i)
3577 if ((dwCols == -1) && m_ColumnManager.IsVisible (i))
3579 CString value
3580 = entry->present_props[m_ColumnManager.GetName(i)];
3581 sClipboard += _T("\t") + value;
3584 #endif
3585 if (selection & GITSLC_COLADD)
3587 sClipboard += _T("\t")+entry->m_StatAdd;
3589 if (selection & GITSLC_COLDEL)
3591 sClipboard += _T("\t")+entry->m_StatDel;
3594 sClipboard += _T("\r\n");
3597 return CStringUtils::WriteAsciiStringToClipboard(sClipboard);
3600 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
3602 #if 0
3603 std::set<CString> changelists;
3604 POSITION pos = GetFirstSelectedItemPosition();
3605 int index;
3606 while ((index = GetNextSelectedItem(pos)) >= 0)
3608 FileEntry * entry = GetListEntry(index);
3609 if (!entry->changelist.IsEmpty())
3610 changelists.insert(entry->changelist);
3612 return changelists.size();
3613 #endif
3614 return 0;
3617 bool CGitStatusListCtrl::PrepareGroups(bool bForce /* = false */)
3620 bool bHasGroups=false;
3621 int max =0;
3623 for(int i=0;i< this->m_arStatusArray.size(); i++)
3625 int ParentNo = m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
3626 if( ParentNo > max)
3627 max=m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
3630 if ( this->m_UnRevFileList.GetCount()>0 ||
3631 this->m_IgnoreFileList.GetCount()>0 ||
3632 max>0 || bForce)
3634 bHasGroups = true;
3637 RemoveAllGroups();
3638 EnableGroupView(bHasGroups);
3640 TCHAR groupname[1024];
3641 int groupindex = 0;
3643 if(bHasGroups)
3645 LVGROUP grp = {0};
3646 grp.cbSize = sizeof(LVGROUP);
3647 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3648 groupindex=0;
3650 //if(m_UnRevFileList.GetCount()>0)
3651 if(max >0)
3653 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MERGEDFILES)), 1023);
3654 grp.pszHeader = groupname;
3655 grp.iGroupId = MERGE_MASK;
3656 grp.uAlign = LVGA_HEADER_LEFT;
3657 InsertGroup(0, &grp);
3659 for(int i=0;i<=max;i++)
3661 CString str;
3662 str.Format(IDS_STATUSLIST_GROUP_DIFFWITHPARENT, i+1);
3663 grp.pszHeader = str.GetBuffer();
3664 str.ReleaseBuffer();
3665 grp.iGroupId = i;
3666 grp.uAlign = LVGA_HEADER_LEFT;
3667 InsertGroup(i+1, &grp);
3670 else
3672 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MODIFIEDFILES)), 1023);
3673 grp.pszHeader = groupname;
3674 grp.iGroupId = groupindex;
3675 grp.uAlign = LVGA_HEADER_LEFT;
3676 InsertGroup(groupindex++, &grp);
3680 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_NOTVERSIONEDFILES)), 1023);
3681 grp.pszHeader = groupname;
3682 grp.iGroupId = groupindex;
3683 grp.uAlign = LVGA_HEADER_LEFT;
3684 InsertGroup(groupindex++, &grp);
3687 //if(m_IgnoreFileList.GetCount()>0)
3689 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNOREDFILES)), 1023);
3690 grp.pszHeader = groupname;
3691 grp.iGroupId = groupindex;
3692 grp.uAlign = LVGA_HEADER_LEFT;
3693 InsertGroup(groupindex++, &grp);
3698 #if 0
3699 m_bHasIgnoreGroup = false;
3701 // now add the items which don't belong to a group
3702 LVGROUP grp = {0};
3703 grp.cbSize = sizeof(LVGROUP);
3704 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3705 CString sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET));
3706 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
3707 grp.pszHeader = groupname;
3708 grp.iGroupId = groupindex;
3709 grp.uAlign = LVGA_HEADER_LEFT;
3710 InsertGroup(groupindex++, &grp);
3712 for (std::map<CString,int>::iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
3714 if (it->first.Compare(SVNSLC_IGNORECHANGELIST)!=0)
3716 LVGROUP grp = {0};
3717 grp.cbSize = sizeof(LVGROUP);
3718 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3719 _tcsncpy_s(groupname, 1024, it->first, 1023);
3720 grp.pszHeader = groupname;
3721 grp.iGroupId = groupindex;
3722 grp.uAlign = LVGA_HEADER_LEFT;
3723 it->second = InsertGroup(groupindex++, &grp);
3725 else
3726 m_bHasIgnoreGroup = true;
3729 if (m_bHasIgnoreGroup)
3731 // and now add the group 'ignore-on-commit'
3732 std::map<CString,int>::iterator it = m_changelists.find(SVNSLC_IGNORECHANGELIST);
3733 if (it != m_changelists.end())
3735 grp.cbSize = sizeof(LVGROUP);
3736 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3737 _tcsncpy_s(groupname, 1024, SVNSLC_IGNORECHANGELIST, 1023);
3738 grp.pszHeader = groupname;
3739 grp.iGroupId = groupindex;
3740 grp.uAlign = LVGA_HEADER_LEFT;
3741 it->second = InsertGroup(groupindex, &grp);
3744 #endif
3745 return bHasGroups;
3748 void CGitStatusListCtrl::NotifyCheck()
3750 CWnd* pParent = GetLogicalParent();
3751 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3753 pParent->SendMessage(GITSLNM_CHECKCHANGED, m_nSelected);
3757 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash,CTGitPathList *list)
3759 BYTE_VECTOR out;
3760 this->m_bBusy=TRUE;
3761 m_CurrentVersion=hash;
3763 int count = 0;
3764 if(list == NULL)
3765 count = 1;
3766 else
3767 count = list->GetCount();
3769 CString head = _T("HEAD");
3770 if(m_amend)
3771 head = _T("HEAD~1");
3773 if(hash == GIT_REV_ZERO)
3775 for(int i=0;i<count;i++)
3777 BYTE_VECTOR cmdout;
3778 cmdout.clear();
3779 CString cmd;
3780 if(!g_Git.IsInitRepos())
3782 // also list staged files which will be in the commit
3783 cmd=(_T("git.exe diff-index --cached --raw ") + head + _T(" --numstat -C -M -z"));
3784 g_Git.Run(cmd, &cmdout);
3786 if(list == NULL)
3787 cmd=(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z"));
3788 else
3789 cmd.Format(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
3791 BYTE_VECTOR cmdErr;
3792 if(g_Git.Run(cmd, &cmdout, &cmdErr))
3794 int last = cmdErr.RevertFind(0,-1);
3795 CString str;
3796 g_Git.StringAppend(&str, &cmdErr[last + 1], CP_UTF8, (int)cmdErr.size() - last -1);
3797 CMessageBox::Show(NULL, str, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
3800 out.append(cmdout, 0);
3802 else // Init Repository
3804 //We will list all added file for init repository because commit will comit these
3805 //if(list == NULL)
3806 cmd=_T("git.exe ls-files -s -t -z");
3807 //else
3808 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
3810 g_Git.Run(cmd, &cmdout);
3811 //out+=cmdout;
3812 out.append(cmdout,0);
3816 if(g_Git.IsInitRepos())
3818 m_StatusFileList.ParserFromLsFile(out);
3819 for(int i=0;i<m_StatusFileList.GetCount();i++)
3820 ((CTGitPath&)(m_StatusFileList[i])).m_Action=CTGitPath::LOGACTIONS_ADDED;
3822 else
3823 this->m_StatusFileList.ParserFromLog(out);
3825 //handle delete conflict case, when remote : modified, local : deleted.
3826 for(int i=0;i<count;i++)
3828 BYTE_VECTOR cmdout;
3829 CString cmd;
3831 if(list == NULL)
3832 cmd=_T("git.exe ls-files -u -t -z");
3833 else
3834 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list)[i].GetGitPathString());
3836 g_Git.Run(cmd, &cmdout);
3838 CTGitPathList conflictlist;
3839 conflictlist.ParserFromLog(cmdout);
3840 for(int i=0;i<conflictlist.GetCount();i++)
3842 CTGitPath *p=m_StatusFileList.LookForGitPath(conflictlist[i].GetGitPathString());
3843 if(p)
3844 p->m_Action|=CTGitPath::LOGACTIONS_UNMERGED;
3845 else
3846 m_StatusFileList.AddPath(conflictlist[i]);
3850 // handle source files of file renames/moves (issue #860)
3851 // if a file gets renamed and the new file "git add"ed, diff-index doesn't list the source file anymore
3852 for(int i = 0; i < count; i++)
3854 BYTE_VECTOR cmdout;
3855 CString cmd;
3857 if(list == NULL)
3858 cmd = _T("git.exe ls-files -d -z");
3859 else
3860 cmd.Format(_T("git.exe ls-files -d -z -- \"%s\""),(*list)[i].GetGitPathString());
3862 g_Git.Run(cmd, &cmdout);
3864 CTGitPathList deletelist;
3865 deletelist.ParserFromLog(cmdout, true);
3866 for(int i = 0; i < deletelist.GetCount(); i++)
3868 CTGitPath *p = m_StatusFileList.LookForGitPath(deletelist[i].GetGitPathString());
3869 if(!p)
3870 m_StatusFileList.AddPath(deletelist[i]);
3871 else if ((p->m_Action == CTGitPath::LOGACTIONS_ADDED || p->m_Action == CTGitPath::LOGACTIONS_REPLACED) && !p->Exists())
3873 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)
3875 g_Git.Run(_T("git.exe rm -f --cache -- \"") + p->GetWinPathString() + _T("\""), &cmdout);
3876 m_StatusFileList.RemoveItem(*p);
3882 else
3884 int count = 0;
3885 if(list == NULL)
3886 count = 1;
3887 else
3888 count = list->GetCount();
3890 for(int i=0;i<count;i++)
3892 BYTE_VECTOR cmdout;
3893 CString cmd;
3894 if(list == NULL)
3895 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash);
3896 else
3897 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash,(*list)[i].GetGitPathString());
3899 g_Git.Run(cmd, &cmdout, NULL);
3901 out.append(cmdout);
3903 this->m_StatusFileList.ParserFromLog(out);
3907 for(int i=0;i<m_StatusFileList.GetCount();i++)
3909 CTGitPath * gitpatch=(CTGitPath*)&m_StatusFileList[i];
3910 gitpatch->m_Checked = TRUE;
3911 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
3914 this->m_bBusy=FALSE;
3915 return 0;
3918 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList &list)
3920 m_arStatusArray.clear();
3921 for(int i=0;i<list.GetCount();i++)
3923 CTGitPath * gitpath=(CTGitPath*)&list[i];
3925 if(gitpath ->m_Action & CTGitPath::LOGACTIONS_HIDE)
3926 continue;
3928 gitpath->m_Checked = TRUE;
3929 m_arStatusArray.push_back((CTGitPath*)&list[i]);
3931 return 0;
3934 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList &list)
3936 m_UnRevFileList = list;
3937 for(int i=0;i<m_UnRevFileList.GetCount();i++)
3939 CTGitPath * gitpatch=(CTGitPath*)&m_UnRevFileList[i];
3940 gitpatch->m_Checked = FALSE;
3941 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
3943 return 0;
3946 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList *List)
3948 this->m_UnRevFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER,List);
3949 for(int i=0;i<m_UnRevFileList.GetCount();i++)
3951 CTGitPath * gitpatch=(CTGitPath*)&m_UnRevFileList[i];
3952 gitpatch->m_Checked = FALSE;
3953 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
3955 return 0;
3958 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList *List)
3960 this->m_IgnoreFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER|CTGitPath::LOGACTIONS_IGNORE,List);
3961 for(int i=0;i<m_IgnoreFileList.GetCount();i++)
3963 CTGitPath * gitpatch=(CTGitPath*)&m_IgnoreFileList[i];
3964 gitpatch->m_Checked = FALSE;
3965 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
3967 return 0;
3969 int CGitStatusListCtrl::UpdateFileList(int mask,bool once,CTGitPathList *List)
3971 if(mask&CGitStatusListCtrl::FILELIST_MODIFY)
3973 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_MODIFY)))
3975 UpdateFileList(git_revnum_t(GIT_REV_ZERO),List);
3976 m_FileLoaded|=CGitStatusListCtrl::FILELIST_MODIFY;
3979 if(mask&CGitStatusListCtrl::FILELIST_UNVER)
3981 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_UNVER)))
3983 UpdateUnRevFileList(List);
3984 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
3986 if(mask&CGitStatusListCtrl::FILELIST_IGNORE && (once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_IGNORE))))
3988 UpdateIgnoreFileList(List);
3989 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
3992 return 0;
3995 void CGitStatusListCtrl::Clear()
3997 m_FileLoaded=0;
3998 this->DeleteAllItems();
3999 this->m_arListArray.clear();
4000 this->m_arStatusArray.clear();
4001 this->m_changelists.clear();
4004 bool CGitStatusListCtrl::CheckMultipleDiffs()
4006 UINT selCount = GetSelectedCount();
4007 if (selCount > max(3, (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\NumDiffWarning"), 10)))
4009 CString message;
4010 message.Format(CString(MAKEINTRESOURCE(IDS_STATUSLIST_WARN_MAXDIFF)), selCount);
4011 return ::MessageBox(GetSafeHwnd(), message, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES;
4013 return true;
4015 //////////////////////////////////////////////////////////////////////////
4016 #if 0
4017 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD * /*pdwEffect*/, POINTL pt)
4019 if(pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
4021 HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
4022 if(hDrop != NULL)
4024 TCHAR szFileName[MAX_PATH];
4026 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
4028 POINT clientpoint;
4029 clientpoint.x = pt.x;
4030 clientpoint.y = pt.y;
4031 ScreenToClient(m_hTargetWnd, &clientpoint);
4032 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
4034 CTSVNPathList changelistItems;
4035 for(UINT i = 0; i < cFiles; ++i)
4037 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
4038 changelistItems.AddPath(CTSVNPath(szFileName));
4040 // find the changelist name
4041 CString sChangelist;
4042 LONG_PTR nGroup = m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint);
4043 for (std::map<CString, int>::iterator it = m_pSVNStatusListCtrl->m_changelists.begin(); it != m_pSVNStatusListCtrl->m_changelists.end(); ++it)
4044 if (it->second == nGroup)
4045 sChangelist = it->first;
4046 if (!sChangelist.IsEmpty())
4048 SVN git;
4049 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
4051 for (int l=0; l<changelistItems.GetCount(); ++l)
4053 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
4054 if (index >= 0)
4056 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
4057 if (e)
4059 e->changelist = sChangelist;
4060 if (!e->IsFolder())
4062 if (m_pSVNStatusListCtrl->m_changelists.find(e->changelist)!=m_pSVNStatusListCtrl->m_changelists.end())
4063 m_pSVNStatusListCtrl->SetItemGroup(index, m_pSVNStatusListCtrl->m_changelists[e->changelist]);
4064 else
4065 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
4069 else
4071 HWND hParentWnd = GetParent(m_hTargetWnd);
4072 if (hParentWnd != NULL)
4073 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
4077 else
4079 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
4082 else
4084 SVN git;
4085 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
4087 for (int l=0; l<changelistItems.GetCount(); ++l)
4089 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
4090 if (index >= 0)
4092 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
4093 if (e)
4095 e->changelist = sChangelist;
4096 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
4099 else
4101 HWND hParentWnd = GetParent(m_hTargetWnd);
4102 if (hParentWnd != NULL)
4103 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
4107 else
4109 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
4113 else
4115 for(UINT i = 0; i < cFiles; ++i)
4117 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
4118 HWND hParentWnd = GetParent(m_hTargetWnd);
4119 if (hParentWnd != NULL)
4120 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)szFileName);
4124 GlobalUnlock(medium.hGlobal);
4126 return true; //let base free the medium
4128 HRESULT STDMETHODCALLTYPE CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)
4130 CIDropTarget::DragOver(grfKeyState, pt, pdwEffect);
4131 *pdwEffect = DROPEFFECT_COPY;
4132 if (m_pSVNStatusListCtrl)
4134 POINT clientpoint;
4135 clientpoint.x = pt.x;
4136 clientpoint.y = pt.y;
4137 ScreenToClient(m_hTargetWnd, &clientpoint);
4138 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
4140 *pdwEffect = DROPEFFECT_MOVE;
4142 else if ((!m_pSVNStatusListCtrl->m_bFileDropsEnabled)||(m_pSVNStatusListCtrl->m_bOwnDrag))
4144 *pdwEffect = DROPEFFECT_NONE;
4147 return S_OK;
4150 #endif
4152 void CGitStatusListCtrl::FilesExport()
4154 CString exportDir;
4155 // export all changed files to a folder
4156 CBrowseFolder browseFolder;
4157 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
4158 if (browseFolder.Show(GetSafeHwnd(), exportDir) != CBrowseFolder::OK)
4159 return;
4161 POSITION pos = GetFirstSelectedItemPosition();
4162 int index;
4163 while ((index = GetNextSelectedItem(pos)) >= 0)
4165 CTGitPath *fd = (CTGitPath*)GetItemData(index);
4166 // we cannot export directories or folders
4167 if (fd->m_Action == CTGitPath::LOGACTIONS_DELETED || fd->IsDirectory())
4168 continue;
4170 CAppUtils::CreateMultipleDirectory(exportDir + _T("\\") + fd->GetDirectory().GetWinPathString());
4171 CString filename = exportDir + _T("\\") + fd->GetWinPathString();
4172 if (m_CurrentVersion == GIT_REV_ZERO)
4174 if (!CopyFile(g_Git.m_CurrentDir + _T("\\") + fd->GetWinPath(), filename, false))
4176 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
4177 return;
4180 else
4182 if (g_Git.GetOneFile(m_CurrentVersion, *fd, filename))
4184 CString out;
4185 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, fd->GetGitPathString(), m_CurrentVersion, filename);
4186 if (CMessageBox::Show(NULL, out, _T("TortoiseGit"), 2, IDI_WARNING, CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
4187 return;
4193 void CGitStatusListCtrl::FileSaveAs(CTGitPath *path)
4195 CString filename;
4196 filename.Format(_T("%s-%s%s"), path->GetBaseFilename(), this->m_CurrentVersion.Left(g_Git.GetShortHASHLength()), path->GetFileExtension());
4197 CFileDialog dlg(FALSE,NULL,
4198 filename,
4199 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
4200 NULL);
4201 CString currentpath;
4202 currentpath=g_Git.m_CurrentDir+_T("\\");
4203 currentpath+=path->GetWinPathString();
4205 dlg.m_ofn.lpstrInitialDir=currentpath.GetBuffer();
4207 CString cmd,out;
4208 INT_PTR ret = dlg.DoModal();
4209 SetCurrentDirectory(g_Git.m_CurrentDir);
4210 if (ret == IDOK)
4212 filename = dlg.GetPathName();
4213 if(m_CurrentVersion == GIT_REV_ZERO)
4215 if(!CopyFile(g_Git.m_CurrentDir +_T("\\") + path->GetWinPath(),filename,false))
4217 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
4218 return;
4222 else
4224 if(g_Git.GetOneFile(m_CurrentVersion,*path,filename))
4226 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path->GetGitPathString(), m_CurrentVersion, filename);
4227 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
4228 return;
4235 int CGitStatusListCtrl::RevertSelectedItemToVersion(bool parent)
4237 if(this->m_CurrentVersion.IsEmpty())
4238 return 0;
4239 if(this->m_CurrentVersion == GIT_REV_ZERO)
4240 return 0;
4242 POSITION pos = GetFirstSelectedItemPosition();
4243 int index;
4244 CString cmd,out;
4245 std::map<CString, int> versionMap;
4246 while ((index = GetNextSelectedItem(pos)) >= 0)
4248 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
4249 CString version;
4250 if (parent)
4252 int parentNo = fentry->m_ParentNo & PARENT_MASK;
4253 CString ref;
4254 ref.Format(_T("%s^%d"), m_CurrentVersion, parentNo + 1);
4255 CGitHash hash;
4256 if (g_Git.GetHash(hash, ref))
4258 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + ref + _T("\".")), _T("TortoiseGit"), MB_ICONERROR);
4259 continue;
4262 version = hash.ToString();
4264 else
4265 version = m_CurrentVersion;
4267 cmd.Format(_T("git.exe checkout %s -- \"%s\""), version, fentry->GetGitPathString());
4268 out.Empty();
4269 if (g_Git.Run(cmd, &out, CP_UTF8))
4271 if (MessageBox(out, _T("TortoiseGit"), MB_ICONEXCLAMATION | MB_OKCANCEL) == IDCANCEL)
4272 continue;
4274 else
4275 versionMap[version]++;
4278 out.Empty();
4279 for (auto it = versionMap.begin(); it != versionMap.end(); ++it)
4281 CString versionEntry;
4282 versionEntry.Format(IDS_STATUSLIST_FILESREVERTED, it->second, it->first);
4283 out += versionEntry + _T("\r\n");
4285 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
4286 return 0;
4289 void CGitStatusListCtrl::OpenFile(CTGitPath*filepath,int mode)
4291 CString file;
4292 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
4294 file = g_Git.m_CurrentDir + _T("\\") + filepath->GetWinPath();
4296 else
4298 CString temppath;
4299 GetTempPath(temppath);
4300 TCHAR szTempName[MAX_PATH];
4301 GetTempFileName(temppath, filepath->GetBaseFilename(), 0, szTempName);
4302 CString temp(szTempName);
4303 DeleteFile(szTempName);
4304 CreateDirectory(szTempName, NULL);
4305 file.Format(_T("%s\\%s_%s%s"),
4306 temp,
4307 filepath->GetBaseFilename(),
4308 m_CurrentVersion.Left(g_Git.GetShortHASHLength()),
4309 filepath->GetFileExtension());
4310 CString cmd,out;
4311 if(g_Git.GetOneFile(m_CurrentVersion, *filepath, file))
4313 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, filepath->GetGitPathString(), m_CurrentVersion, file);
4314 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
4315 return;
4317 SetFileAttributes(file, FILE_ATTRIBUTE_READONLY);
4319 if(mode == ALTERNATIVEEDITOR)
4321 CAppUtils::LaunchAlternativeEditor(file);
4322 return;
4324 int ret = HINSTANCE_ERROR;
4326 if(mode == OPEN )
4328 ret = (int)ShellExecute(this->m_hWnd, NULL,file, NULL, NULL, SW_SHOW);
4330 if (ret > HINSTANCE_ERROR)
4332 return;
4337 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
4338 cmd += file;
4339 CAppUtils::LaunchApplication(cmd, NULL, false);