Cleanup: Dropped unused code
[TortoiseGit.git] / src / Git / GitStatusListCtrl.cpp
blobb811a8834498a256ec26fea8ba9d3d7a305e51ed
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
5 // Copyright (C) 2010-2012 Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "StdAfx.h"
23 #include "resource.h"
24 #include "..\\TortoiseShell\resource.h"
25 #include "GitStatusListCtrl.h"
26 #include "MessageBox.h"
27 #include "MyMemDC.h"
28 #include "UnicodeUtils.h"
29 #include "AppUtils.h"
30 #include "PathUtils.h"
31 #include "TempFile.h"
32 #include "StringUtils.h"
33 #include "DirFileEnum.h"
34 #include "GitConfig.h"
35 #include "LoglistUtils.h"
36 //#include "SVNProperties.h"
37 #include "Git.h"
38 #include "GitDiff.h"
39 //#include "LogDlg.h"
40 //#include "SVNProgressDlg.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 "MassiveGitTask.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)
129 m_FileLoaded=0;
130 m_critSec.Init();
131 m_bIsRevertTheirMy = false;
132 this->m_nLineAdded =this->m_nLineDeleted =0;
135 CGitStatusListCtrl::~CGitStatusListCtrl()
137 // if (m_pDropTarget)
138 // delete m_pDropTarget;
139 ClearStatusArray();
142 void CGitStatusListCtrl::ClearStatusArray()
144 #if 0
145 Locker lock(m_critSec);
146 for (size_t i=0; i < m_arStatusArray.size(); i++)
148 delete m_arStatusArray[i];
150 m_arStatusArray.clear();
151 #endif
154 void CGitStatusListCtrl::Init(DWORD dwColumns, const CString& sColumnInfoContainer, unsigned __int64 dwContextMenus /* = GitSLC_POPALL */, bool bHasCheckboxes /* = true */, bool bHasWC /* = true */, DWORD allowedColumns /* = 0xffffffff */)
156 Locker lock(m_critSec);
158 m_dwDefaultColumns = dwColumns | 1;
159 m_dwContextMenus = dwContextMenus;
160 m_bHasCheckboxes = bHasCheckboxes;
161 m_bHasWC = bHasWC;
163 // set the extended style of the listcontrol
164 // 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.
165 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
166 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
167 if (DWORD(regFullRowSelect))
168 exStyle |= LVS_EX_FULLROWSELECT;
169 exStyle |= (bHasCheckboxes ? LVS_EX_CHECKBOXES : 0);
170 SetRedraw(false);
171 SetExtendedStyle(exStyle);
173 SetWindowTheme(m_hWnd, L"Explorer", NULL);
175 m_nIconFolder = SYS_IMAGE_LIST().GetDirIconIndex();
176 m_nRestoreOvl = SYS_IMAGE_LIST().AddIcon((HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_RESTOREOVL), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));
177 SYS_IMAGE_LIST().SetOverlayImage(m_nRestoreOvl, OVL_RESTORE);
178 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL);
180 // keep CSorter::operator() in sync!!
181 static UINT standardColumnNames[GITSLC_NUMCOLUMNS]
182 = { IDS_STATUSLIST_COLFILE
183 , IDS_STATUSLIST_COLFILENAME
184 , IDS_STATUSLIST_COLEXT
185 , IDS_STATUSLIST_COLSTATUS
186 , IDS_STATUSLIST_COLADD
187 , IDS_STATUSLIST_COLDEL
188 , IDS_STATUSLIST_COLLASTMODIFIED
189 , IDS_STATUSLIST_COLSIZE
192 m_ColumnManager.SetNames(standardColumnNames,GITSLC_NUMCOLUMNS);
193 m_ColumnManager.ReadSettings(m_dwDefaultColumns, 0xffffffff & ~(allowedColumns | m_dwDefaultColumns), sColumnInfoContainer, GITSLC_NUMCOLUMNS);
195 // enable file drops
196 #if 0
197 if (m_pDropTarget == NULL)
199 m_pDropTarget = new CGitStatusListCtrlDropTarget(this);
200 RegisterDragDrop(m_hWnd,m_pDropTarget);
201 // create the supported formats:
202 FORMATETC ftetc={0};
203 ftetc.dwAspect = DVASPECT_CONTENT;
204 ftetc.lindex = -1;
205 ftetc.tymed = TYMED_HGLOBAL;
206 ftetc.cfFormat=CF_HDROP;
207 m_pDropTarget->AddSuportedFormat(ftetc);
209 #endif
211 SetRedraw(true);
214 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID)
216 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID);
219 BOOL CGitStatusListCtrl::GetStatus ( const CTGitPathList* pathList
220 , bool bUpdate /* = FALSE */
221 , bool bShowIgnores /* = false */
222 , bool bShowUnRev)
224 Locker lock(m_critSec);
225 int mask= CGitStatusListCtrl::FILELIST_MODIFY;
226 if(bShowIgnores)
227 mask|= CGitStatusListCtrl::FILELIST_IGNORE;
228 if(bShowUnRev)
229 mask|= CGitStatusListCtrl::FILELIST_UNVER;
230 this->UpdateFileList(mask,bUpdate,(CTGitPathList*)pathList);
233 #if 0
234 int refetchcounter = 0;
235 BOOL bRet = TRUE;
236 Invalidate();
237 // force the cursor to change
238 POINT pt;
239 GetCursorPos(&pt);
240 SetCursorPos(pt.x, pt.y);
242 m_mapFilenameToChecked.clear();
243 //m_StatusUrlList.Clear();
244 bool bHasChangelists = (m_changelists.size()>1 || (m_changelists.size()>0 && !m_bHasIgnoreGroup));
245 m_changelists.clear();
246 for (size_t i=0; i < m_arStatusArray.size(); i++)
248 FileEntry * entry = m_arStatusArray[i];
249 if ( bHasChangelists && entry->checked)
251 // If change lists are present, remember all checked entries
252 CString path = entry->GetPath().GetGitPathString();
253 m_mapFilenameToChecked[path] = true;
255 if ( (entry->status==git_wc_status_unversioned || entry->status==git_wc_status_missing ) && entry->checked )
257 // The user manually selected an unversioned or missing file. We remember
258 // this so that the selection can be restored when refreshing.
259 CString path = entry->GetPath().GetGitPathString();
260 m_mapFilenameToChecked[path] = true;
262 else if ( entry->status > git_wc_status_normal && !entry->checked )
264 // The user manually deselected a versioned file. We remember
265 // this so that the deselection can be restored when refreshing.
266 CString path = entry->GetPath().GetGitPathString();
267 m_mapFilenameToChecked[path] = false;
271 // use a sorted path list to make sure we fetch the status of
272 // parent items first, *then* the child items (if any)
273 CTGitPathList sortedPathList = pathList;
274 sortedPathList.SortByPathname();
277 bRet = TRUE;
278 m_nTargetCount = 0;
279 m_bHasExternalsFromDifferentRepos = FALSE;
280 m_bHasExternals = FALSE;
281 m_bHasUnversionedItems = FALSE;
282 m_bHasLocks = false;
283 m_bHasChangeLists = false;
284 m_bShowIgnores = bShowIgnores;
285 m_nSortedColumn = 0;
286 m_bBlock = TRUE;
287 m_bBusy = true;
288 m_bEmpty = false;
289 Invalidate();
291 // first clear possible status data left from
292 // previous GetStatus() calls
293 ClearStatusArray();
295 m_StatusFileList = sortedPathList;
297 // Since Git_client_status() returns all files, even those in
298 // folders included with Git:externals we need to check if all
299 // files we get here belongs to the same repository.
300 // It is possible to commit changes in an external folder, as long
301 // as the folder belongs to the same repository (but another path),
302 // but it is not possible to commit all files if the externals are
303 // from a different repository.
305 // To check if all files belong to the same repository, we compare the
306 // UUID's - if they're identical then the files belong to the same
307 // repository and can be committed. But if they're different, then
308 // tell the user to commit all changes in the external folders
309 // first and exit.
310 CStringA sUUID; // holds the repo UUID
311 CTGitPathList arExtPaths; // list of Git:external paths
313 GitConfig config;
315 m_sURL.Empty();
317 m_nTargetCount = sortedPathList.GetCount();
319 GitStatus status(m_pbCanceled);
320 if(m_nTargetCount > 1 && sortedPathList.AreAllPathsFilesInOneDirectory())
322 // This is a special case, where we've been given a list of files
323 // all from one folder
324 // We handle them by setting a status filter, then requesting the Git status of
325 // all the files in the directory, filtering for the ones we're interested in
326 status.SetFilter(sortedPathList);
328 // if all selected entries are files, we don't do a recursive status
329 // fetching. But if only one is a directory, we have to recurse.
330 git_depth_t depth = git_depth_files;
331 // We have set a filter. If all selected items were files or we fetch
332 // the status not recursively, then we have to include
333 // ignored items too - the user has selected them
334 bool bShowIgnoresRight = true;
335 for (int fcindex=0; fcindex<sortedPathList.GetCount(); ++fcindex)
337 if (sortedPathList[fcindex].IsDirectory())
339 depth = git_depth_infinity;
340 bShowIgnoresRight = false;
341 break;
344 if(!FetchStatusForSingleTarget(config, status, sortedPathList.GetCommonDirectory(), bUpdate, sUUID, arExtPaths, true, depth, bShowIgnoresRight))
346 bRet = FALSE;
349 else
351 for(int nTarget = 0; nTarget < m_nTargetCount; nTarget++)
353 // check whether the path we want the status for is already fetched due to status-fetching
354 // of a parent path.
355 // this check is only done for file paths, because folder paths could be included already
356 // but not recursively
357 if (sortedPathList[nTarget].IsDirectory() || GetListEntry(sortedPathList[nTarget]) == NULL)
359 if(!FetchStatusForSingleTarget(config, status, sortedPathList[nTarget], bUpdate, sUUID,
360 arExtPaths, false, git_depth_infinity, bShowIgnores))
362 bRet = FALSE;
368 // remove the 'helper' files of conflicted items from the list.
369 // otherwise they would appear as unversioned files.
370 for (INT_PTR cind = 0; cind < m_ConflictFileList.GetCount(); ++cind)
372 for (size_t i=0; i < m_arStatusArray.size(); i++)
374 if (m_arStatusArray[i]->GetPath().IsEquivalentTo(m_ConflictFileList[cind]))
376 delete m_arStatusArray[i];
377 m_arStatusArray.erase(m_arStatusArray.begin()+i);
378 break;
382 refetchcounter++;
383 } while(!BuildStatistics() && (refetchcounter < 2) && (*m_pbCanceled==false));
385 m_bBlock = FALSE;
386 m_bBusy = false;
387 GetCursorPos(&pt);
388 SetCursorPos(pt.x, pt.y);
389 return bRet;
390 #endif
391 BuildStatistics();
392 return TRUE;
395 // Get the show-flags bitmap value which corresponds to a particular Git status
396 DWORD CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status)
398 switch (status)
400 case git_wc_status_none:
401 case git_wc_status_unversioned:
402 return GITSLC_SHOWUNVERSIONED;
403 case git_wc_status_ignored:
404 if (!m_bShowIgnores)
405 return GITSLC_SHOWDIRECTS;
406 return GITSLC_SHOWDIRECTS|GITSLC_SHOWIGNORED;
407 case git_wc_status_incomplete:
408 return GITSLC_SHOWINCOMPLETE;
409 case git_wc_status_normal:
410 return GITSLC_SHOWNORMAL;
411 case git_wc_status_external:
412 return GITSLC_SHOWEXTERNAL;
413 case git_wc_status_added:
414 return GITSLC_SHOWADDED;
415 case git_wc_status_missing:
416 return GITSLC_SHOWMISSING;
417 case git_wc_status_deleted:
418 return GITSLC_SHOWREMOVED;
419 case git_wc_status_replaced:
420 return GITSLC_SHOWREPLACED;
421 case git_wc_status_modified:
422 return GITSLC_SHOWMODIFIED;
423 case git_wc_status_merged:
424 return GITSLC_SHOWMERGED;
425 case git_wc_status_conflicted:
426 return GITSLC_SHOWCONFLICTED;
427 case git_wc_status_obstructed:
428 return GITSLC_SHOWOBSTRUCTED;
429 default:
430 // we should NEVER get here!
431 ASSERT(FALSE);
432 break;
434 return 0;
437 void CGitStatusListCtrl::Show(unsigned int dwShow, unsigned int dwCheck /*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList,bool UseStoredCheckStatus)
439 CWinApp * pApp = AfxGetApp();
440 if (pApp)
441 pApp->DoWaitCursor(1);
443 Locker lock(m_critSec);
444 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
446 //SetItemCount(listIndex);
447 SetRedraw(FALSE);
448 DeleteAllItems();
449 m_nSelected = 0;
451 m_nShownUnversioned = 0;
452 m_nShownModified = 0;
453 m_nShownAdded = 0;
454 m_nShownDeleted = 0;
455 m_nShownConflicted = 0;
456 m_nShownFiles = 0;
457 m_nShownSubmodules = 0;
459 if(UpdateStatusList)
461 m_arStatusArray.clear();
462 for(int i=0;i<this->m_StatusFileList.GetCount();i++)
464 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
467 for(int i=0;i<this->m_UnRevFileList.GetCount();i++)
469 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
472 for(int i=0;i<this->m_IgnoreFileList.GetCount();i++)
474 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
477 PrepareGroups();
478 if (m_nSortedColumn >= 0)
480 CSorter predicate (&m_ColumnManager, m_nSortedColumn, m_bAscending);
481 std::sort(m_arStatusArray.begin(), m_arStatusArray.end(), predicate);
484 int index =0;
485 for(int i=0;i<this->m_arStatusArray.size();i++)
487 //set default checkbox status
488 CTGitPath* entry = ((CTGitPath*)m_arStatusArray[i]);
489 CString path = entry->GetGitPathString();
490 if (m_mapFilenameToChecked.size()!=0 && m_mapFilenameToChecked.find(path) != m_mapFilenameToChecked.end())
492 entry->m_Checked=m_mapFilenameToChecked[path];
494 else if (!UseStoredCheckStatus)
496 bool autoSelectSubmodules = !(entry->IsDirectory() && m_bDoNotAutoselectSubmodules);
497 if(entry->m_Action & dwCheck && autoSelectSubmodules)
498 entry->m_Checked=true;
499 else
500 entry->m_Checked=false;
501 m_mapFilenameToChecked[path] = entry->m_Checked;
504 if(entry->m_Action & dwShow)
506 AddEntry(entry,langID,index);
507 index++;
511 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
512 for (int col = 0; col <= maxcol; col++)
513 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
515 SetRedraw(TRUE);
516 GetStatisticsString();
518 CHeaderCtrl * pHeader = GetHeaderCtrl();
519 HDITEM HeaderItem = {0};
520 HeaderItem.mask = HDI_FORMAT;
521 for (int i=0; i<pHeader->GetItemCount(); ++i)
523 pHeader->GetItem(i, &HeaderItem);
524 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
525 pHeader->SetItem(i, &HeaderItem);
527 if (m_nSortedColumn >= 0)
529 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
530 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
531 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
534 #if 0
535 if (nSelectedEntry)
537 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
538 EnsureVisible(nSelectedEntry, false);
540 else
542 // Restore the item at the top of the list.
543 for (int i=0;GetTopIndex() != nTopIndex;i++)
545 if ( !EnsureVisible(nTopIndex+i,false) )
547 break;
551 #endif
552 if (pApp)
553 pApp->DoWaitCursor(-1);
555 Invalidate();
557 m_dwShow = dwShow;
559 this->BuildStatistics();
561 #if 0
563 CWinApp * pApp = AfxGetApp();
564 if (pApp)
565 pApp->DoWaitCursor(1);
567 m_bShowFolders = bShowFolders;
569 int nTopIndex = GetTopIndex();
570 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
571 int nSelectedEntry = 0;
572 if (posSelectedEntry)
573 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
574 SetRedraw(FALSE);
575 DeleteAllItems();
577 PrepareGroups();
579 m_arListArray.clear();
581 m_arListArray.reserve(m_arStatusArray.size());
582 SetItemCount (static_cast<int>(m_arStatusArray.size()));
584 int listIndex = 0;
585 for (size_t i=0; i < m_arStatusArray.size(); ++i)
587 FileEntry * entry = m_arStatusArray[i];
588 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
589 continue;
590 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
591 continue;
592 if (entry->IsFolder() && (!bShowFolders))
593 continue; // don't show folders if they're not wanted.
595 #if 0
596 git_wc_status_kind status = GitStatus::GetMoreImportant(entry->status, entry->remotestatus);
597 DWORD showFlags = GetShowFlagsFromGitStatus(status);
598 if (entry->IsLocked())
599 showFlags |= SVNSLC_SHOWLOCKS;
600 if (entry->switched)
601 showFlags |= SVNSLC_SHOWSWITCHED;
602 if (!entry->changelist.IsEmpty())
603 showFlags |= SVNSLC_SHOWINCHANGELIST;
604 #endif
605 bool bAllowCheck = ((entry->changelist.Compare(GITSLC_IGNORECHANGELIST) != 0)
606 && (m_bCheckIfGroupsExist || (m_changelists.size()==0 || (m_changelists.size()==1 && m_bHasIgnoreGroup))));
608 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
609 #if 0
610 if (status != Git_wc_status_ignored || (entry->direct) || (dwShow & GitSLC_SHOWIGNORED))
612 if ((!entry->IsFolder()) && (status == Git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
614 if (PathFileExists(entry->GetPath().GetWinPath()))
616 m_arListArray.push_back(i);
617 if ((dwCheck & SVNSLC_SHOWREMOVEDANDPRESENT)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
619 if (bAllowCheck)
620 entry->checked = true;
622 AddEntry(entry, langID, listIndex++);
625 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
627 m_arListArray.push_back(i);
628 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
630 if (bAllowCheck)
631 entry->checked = true;
633 AddEntry(entry, langID, listIndex++);
635 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(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++);
646 #endif
649 SetItemCount(listIndex);
651 m_ColumnManager.UpdateRelevance (m_arStatusArray, m_arListArray);
653 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
654 for (int col = 0; col <= maxcol; col++)
655 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
657 SetRedraw(TRUE);
658 GetStatisticsString();
660 CHeaderCtrl * pHeader = GetHeaderCtrl();
661 HDITEM HeaderItem = {0};
662 HeaderItem.mask = HDI_FORMAT;
663 for (int i=0; i<pHeader->GetItemCount(); ++i)
665 pHeader->GetItem(i, &HeaderItem);
666 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
667 pHeader->SetItem(i, &HeaderItem);
669 if (m_nSortedColumn)
671 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
672 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
673 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
676 if (nSelectedEntry)
678 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
679 EnsureVisible(nSelectedEntry, false);
681 else
683 // Restore the item at the top of the list.
684 for (int i=0;GetTopIndex() != nTopIndex;i++)
686 if ( !EnsureVisible(nTopIndex+i,false) )
688 break;
693 if (pApp)
694 pApp->DoWaitCursor(-1);
696 m_bEmpty = (GetItemCount() == 0);
697 Invalidate();
698 #endif
702 void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList& checkedList, bool /*bShowFolders*/ /* = true */)
704 DeleteAllItems();
705 for(int i=0;i<checkedList.GetCount();i++)
706 this->AddEntry((CTGitPath *)&checkedList[i],0,i);
707 return ;
708 #if 0
710 Locker lock(m_critSec);
711 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
713 CWinApp * pApp = AfxGetApp();
714 if (pApp)
715 pApp->DoWaitCursor(1);
716 m_dwShow = dwShow;
717 m_bShowFolders = bShowFolders;
718 m_nSelected = 0;
719 int nTopIndex = GetTopIndex();
720 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
721 int nSelectedEntry = 0;
722 if (posSelectedEntry)
723 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
724 SetRedraw(FALSE);
725 DeleteAllItems();
727 PrepareGroups();
729 m_arListArray.clear();
731 m_arListArray.reserve(m_arStatusArray.size());
732 SetItemCount (static_cast<int>(m_arStatusArray.size()));
734 int listIndex = 0;
735 for (size_t i=0; i < m_arStatusArray.size(); ++i)
737 FileEntry * entry = m_arStatusArray[i];
738 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
739 continue;
740 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
741 continue;
742 if (entry->IsFolder() && (!bShowFolders))
743 continue; // don't show folders if they're not wanted.
744 #if 0
745 git_wc_status_kind status = SVNStatus::GetMoreImportant(entry->status, entry->remotestatus);
746 DWORD showFlags = GetShowFlagsFromSVNStatus(status);
747 if (entry->IsLocked())
748 showFlags |= SVNSLC_SHOWLOCKS;
749 if (!entry->changelist.IsEmpty())
750 showFlags |= SVNSLC_SHOWINCHANGELIST;
752 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
753 if (status != git_wc_status_ignored || (entry->direct) || (dwShow & SVNSLC_SHOWIGNORED))
755 for (int npath = 0; npath < checkedList.GetCount(); ++npath)
757 if (entry->GetPath().IsEquivalentTo(checkedList[npath]))
759 entry->checked = true;
760 break;
763 if ((!entry->IsFolder()) && (status == git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
765 if (PathFileExists(entry->GetPath().GetWinPath()))
767 m_arListArray.push_back(i);
768 AddEntry(entry, langID, listIndex++);
771 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
773 m_arListArray.push_back(i);
774 AddEntry(entry, langID, listIndex++);
776 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
778 m_arListArray.push_back(i);
779 AddEntry(entry, langID, listIndex++);
781 else if (entry->switched)
783 m_arListArray.push_back(i);
784 AddEntry(entry, langID, listIndex++);
787 #endif
790 SetItemCount(listIndex);
792 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
793 for (int col = 0; col <= maxcol; col++)
794 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
796 SetRedraw(TRUE);
797 GetStatisticsString();
799 CHeaderCtrl * pHeader = GetHeaderCtrl();
800 HDITEM HeaderItem = {0};
801 HeaderItem.mask = HDI_FORMAT;
802 for (int i=0; i<pHeader->GetItemCount(); ++i)
804 pHeader->GetItem(i, &HeaderItem);
805 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
806 pHeader->SetItem(i, &HeaderItem);
808 if (m_nSortedColumn)
810 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
811 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
812 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
815 if (nSelectedEntry)
817 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
818 EnsureVisible(nSelectedEntry, false);
820 else
822 // Restore the item at the top of the list.
823 for (int i=0;GetTopIndex() != nTopIndex;i++)
825 if ( !EnsureVisible(nTopIndex+i,false) )
827 break;
832 if (pApp)
833 pApp->DoWaitCursor(-1);
835 m_bEmpty = (GetItemCount() == 0);
836 Invalidate();
837 #endif
840 int CGitStatusListCtrl::GetColumnIndex(int mask)
842 int i=0;
843 for(i=0;i<32;i++)
844 if(mask&0x1)
845 return i;
846 else
847 mask=mask>>1;
848 return -1;
850 void CGitStatusListCtrl::AddEntry(CTGitPath * GitPath, WORD /*langID*/, int listIndex)
852 static CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
853 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
854 static bool abbreviateRenamings(((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\AbbreviateRenamings"), FALSE)) == TRUE);
855 static bool relativeTimes = (CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE) != FALSE);
857 CString path = GitPath->GetGitPathString();
859 m_bBlock = TRUE;
860 int index = listIndex;
861 int nCol = 1;
862 CString entryname = GitPath->GetGitPathString();
863 int icon_idx = 0;
864 if (GitPath->IsDirectory())
866 icon_idx = m_nIconFolder;
867 m_nShownSubmodules++;
869 else
871 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath);
872 m_nShownFiles++;
874 switch (GitPath->m_Action)
876 case CTGitPath::LOGACTIONS_ADDED:
877 case CTGitPath::LOGACTIONS_COPY:
878 m_nShownAdded++;
879 break;
880 case CTGitPath::LOGACTIONS_DELETED:
881 m_nShownDeleted++;
882 break;
883 case CTGitPath::LOGACTIONS_REPLACED:
884 case CTGitPath::LOGACTIONS_MODIFIED:
885 case CTGitPath::LOGACTIONS_MERGED:
886 m_nShownModified++;
887 break;
888 case CTGitPath::LOGACTIONS_UNMERGED:
889 m_nShownConflicted++;
890 break;
891 case CTGitPath::LOGACTIONS_UNVER:
892 m_nShownUnversioned++;
893 break;
894 default:
895 m_nShownUnversioned++;
896 break;
898 if(GitPath->m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !GitPath->GetGitOldPathString().IsEmpty())
900 if (!abbreviateRenamings)
902 // relative path
903 CString rename;
904 rename.Format(from, GitPath->GetGitOldPathString());
905 entryname += _T(" ") + rename;
907 else
909 CTGitPathList tgpl;
910 tgpl.AddPath(*GitPath);
911 CTGitPath old(GitPath->GetGitOldPathString());
912 tgpl.AddPath(old);
913 CString commonRoot = tgpl.GetCommonRoot().GetGitPathString();
914 if (!commonRoot.IsEmpty())
915 commonRoot += _T("/");
916 if (old.GetFileOrDirectoryName() == GitPath->GetFileOrDirectoryName() && old.GetContainingDirectory().GetGitPathString() != "" && GitPath->GetContainingDirectory().GetGitPathString())
918 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();
920 else if (!commonRoot.IsEmpty())
922 entryname = commonRoot + _T("{") + GitPath->GetGitOldPathString().Mid(commonRoot.GetLength()) + _T(" => ") + GitPath->GetGitPathString().Mid(commonRoot.GetLength()) + _T("}");
924 else
926 entryname = GitPath->GetGitOldPathString().Mid(commonRoot.GetLength()) + _T(" => ") + GitPath->GetGitPathString().Mid(commonRoot.GetLength());
931 InsertItem(index, entryname, icon_idx);
932 if (m_restorepaths.find(GitPath->GetWinPathString()) != m_restorepaths.end())
933 SetItemState(index, INDEXTOOVERLAYMASK(OVL_RESTORE), TVIS_OVERLAYMASK);
935 this->SetItemData(index, (DWORD_PTR)GitPath);
936 // SVNSLC_COLFILENAME
937 SetItemText(index, nCol++, GitPath->GetFileOrDirectoryName());
938 // SVNSLC_COLEXT
939 SetItemText(index, nCol++, GitPath->GetFileExtension());
940 // SVNSLC_COLSTATUS
941 SetItemText(index, nCol++, GitPath->GetActionName());
943 SetItemText(index, GetColumnIndex(GITSLC_COLADD),GitPath->m_StatAdd);
944 SetItemText(index, GetColumnIndex(GITSLC_COLDEL),GitPath->m_StatDel);
947 CString modificationDate;
948 __int64 filetime = GitPath->GetLastWriteTime();
949 if (filetime && (GitPath->m_Action != CTGitPath::LOGACTIONS_DELETED))
951 FILETIME* f = (FILETIME*)(__int64*)&filetime;
952 modificationDate = CLoglistUtils::FormatDateAndTime(CTime(g_Git.filetime_to_time_t(f)), DATE_SHORTDATE, true, relativeTimes);
954 SetItemText(index, GetColumnIndex(GITSLC_COLMODIFICATIONDATE), modificationDate);
956 // SVNSLC_COLSIZE
957 if (GitPath->IsDirectory())
958 SetItemText(index, GetColumnIndex(GITSLC_COLSIZE), _T(""));
959 else
961 TCHAR buf[100];
962 StrFormatByteSize64(GitPath->GetFileSize(), buf, 100);
963 SetItemText(index, GetColumnIndex(GITSLC_COLSIZE), buf);
966 SetCheck(index, GitPath->m_Checked);
967 if (GitPath->m_Checked)
968 m_nSelected++;
971 if( GitPath->m_Action & CTGitPath::LOGACTIONS_IGNORE)
972 SetItemGroup(index, 2);
973 else if( GitPath->m_Action & CTGitPath::LOGACTIONS_UNVER)
974 SetItemGroup(index,1);
975 else
977 SetItemGroup(index, GitPath->m_ParentNo&(PARENT_MASK|MERGE_MASK));
980 m_bBlock = FALSE;
985 bool CGitStatusListCtrl::SetItemGroup(int item, int groupindex)
987 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
988 // return false;
989 if (groupindex < 0)
990 return false;
991 LVITEM i = {0};
992 i.mask = LVIF_GROUPID;
993 i.iItem = item;
994 i.iSubItem = 0;
995 i.iGroupId = groupindex;
997 return !!SetItem(&i);
1000 void CGitStatusListCtrl::OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult)
1002 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1003 *pResult = 0;
1004 if (m_bBlock)
1005 return;
1006 m_bBlock = TRUE;
1007 if (m_nSortedColumn == phdr->iItem)
1008 m_bAscending = !m_bAscending;
1009 else
1010 m_bAscending = TRUE;
1011 m_nSortedColumn = phdr->iItem;
1012 Show(m_dwShow, 0, m_bShowFolders,false,true);
1014 m_bBlock = FALSE;
1017 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
1019 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1020 *pResult = 0;
1022 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1023 if ((m_bBlock)&&(m_bBlockUI))
1025 // if we're blocked, prevent changing of the check state
1026 if ((!ISCHECKED(pNMLV->uOldState) && ISCHECKED(pNMLV->uNewState))||
1027 (ISCHECKED(pNMLV->uOldState) && !ISCHECKED(pNMLV->uNewState)))
1028 *pResult = TRUE;
1032 BOOL CGitStatusListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
1034 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1035 *pResult = 0;
1036 CWnd* pParent = GetParent();
1037 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
1039 pParent->SendMessage(GITSLNM_ITEMCHANGED, pNMLV->iItem);
1042 if ((pNMLV->uNewState==0)||(pNMLV->uNewState & LVIS_SELECTED)||(pNMLV->uNewState & LVIS_FOCUSED))
1043 return FALSE;
1045 if (m_bBlock)
1046 return FALSE;
1048 bool bSelected = !!(ListView_GetItemState(m_hWnd, pNMLV->iItem, LVIS_SELECTED) & LVIS_SELECTED);
1049 int nListItems = GetItemCount();
1051 m_bBlock = TRUE;
1052 // was the item checked?
1054 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1055 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1057 if (GetCheck(pNMLV->iItem))
1059 CheckEntry(pNMLV->iItem, nListItems);
1060 if (bSelected)
1062 POSITION pos = GetFirstSelectedItemPosition();
1063 int index;
1064 while ((index = GetNextSelectedItem(pos)) >= 0)
1066 if (index != pNMLV->iItem)
1067 CheckEntry(index, nListItems);
1071 else
1073 UncheckEntry(pNMLV->iItem, nListItems);
1074 if (bSelected)
1076 POSITION pos = GetFirstSelectedItemPosition();
1077 int index;
1078 while ((index = GetNextSelectedItem(pos)) >= 0)
1080 if (index != pNMLV->iItem)
1081 UncheckEntry(index, nListItems);
1086 GetStatisticsString();
1087 m_bBlock = FALSE;
1088 NotifyCheck();
1090 return FALSE;
1093 void CGitStatusListCtrl::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
1095 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
1097 *pResult = FALSE;
1100 void CGitStatusListCtrl::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
1102 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
1104 Invalidate(FALSE);
1107 void CGitStatusListCtrl::CheckEntry(int index, int /*nListItems*/)
1109 Locker lock(m_critSec);
1110 //FileEntry * entry = GetListEntry(index);
1111 CTGitPath *path=(CTGitPath*)GetItemData(index);
1112 ASSERT(path != NULL);
1113 if (path == NULL)
1114 return;
1115 m_mapFilenameToChecked[path->GetGitPathString()] = true;
1116 SetCheck(index, TRUE);
1117 //entry = GetListEntry(index);
1118 // if an unversioned item was checked, then we need to check if
1119 // the parent folders are unversioned too. If the parent folders actually
1120 // are unversioned, then check those too.
1121 #if 0
1122 if (entry->status == git_wc_status_unversioned)
1124 // we need to check the parent folder too
1125 const CTGitPath& folderpath = entry->path;
1126 for (int i=0; i< nListItems; ++i)
1128 FileEntry * testEntry = GetListEntry(i);
1129 ASSERT(testEntry != NULL);
1130 if (testEntry == NULL)
1131 continue;
1132 if (!testEntry->checked)
1134 if (testEntry->path.IsAncestorOf(folderpath) && (!testEntry->path.IsEquivalentTo(folderpath)))
1136 SetEntryCheck(testEntry,i,true);
1137 m_nSelected++;
1142 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1143 if ( (entry->status == git_wc_status_deleted) || (m_bCheckChildrenWithParent) || (bShift) )
1145 // if a deleted folder gets checked, we have to check all
1146 // children of that folder too.
1147 if (entry->path.IsDirectory())
1149 SetCheckOnAllDescendentsOf(entry, true);
1152 // if a deleted file or folder gets checked, we have to
1153 // check all parents of this item too.
1154 for (int i=0; i<nListItems; ++i)
1156 FileEntry * testEntry = GetListEntry(i);
1157 ASSERT(testEntry != NULL);
1158 if (testEntry == NULL)
1159 continue;
1160 if (!testEntry->checked)
1162 if (testEntry->path.IsAncestorOf(entry->path) && (!testEntry->path.IsEquivalentTo(entry->path)))
1164 if ((testEntry->status == git_wc_status_deleted)||(m_bCheckChildrenWithParent))
1166 SetEntryCheck(testEntry,i,true);
1167 m_nSelected++;
1168 // now we need to check all children of this parent folder
1169 SetCheckOnAllDescendentsOf(testEntry, true);
1175 #endif
1176 if ( !path->m_Checked )
1178 path->m_Checked = TRUE;
1179 m_nSelected++;
1183 void CGitStatusListCtrl::UncheckEntry(int index, int /*nListItems*/)
1185 Locker lock(m_critSec);
1186 CTGitPath *path=(CTGitPath*)GetItemData(index);
1187 ASSERT(path != NULL);
1188 if (path == NULL)
1189 return;
1190 SetCheck(index, FALSE);
1191 m_mapFilenameToChecked[path->GetGitPathString()] = false;
1192 //entry = GetListEntry(index);
1193 // item was unchecked
1194 #if 0
1195 if (entry->path.IsDirectory())
1197 // disable all files within an unselected folder, except when unchecking a folder with property changes
1198 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1199 if ( (entry->status != git_wc_status_modified) || (bShift) )
1201 SetCheckOnAllDescendentsOf(entry, false);
1204 else if (entry->status == git_wc_status_deleted)
1206 // a "deleted" file was unchecked, so uncheck all parent folders
1207 // and all children of those parents
1208 for (int i=0; i<nListItems; i++)
1210 FileEntry * testEntry = GetListEntry(i);
1211 ASSERT(testEntry != NULL);
1212 if (testEntry == NULL)
1213 continue;
1214 if (testEntry->checked)
1216 if (testEntry->path.IsAncestorOf(entry->path))
1218 if (testEntry->status == git_wc_status_deleted)
1220 SetEntryCheck(testEntry,i,false);
1221 m_nSelected--;
1223 SetCheckOnAllDescendentsOf(testEntry, false);
1229 #endif
1230 if ( path->m_Checked )
1232 path->m_Checked = FALSE;
1233 m_nSelected--;
1236 bool CGitStatusListCtrl::BuildStatistics()
1239 bool bRefetchStatus = false;
1241 // now gather some statistics
1242 m_nUnversioned = 0;
1243 m_nNormal = 0;
1244 m_nModified = 0;
1245 m_nAdded = 0;
1246 m_nDeleted = 0;
1247 m_nConflicted = 0;
1248 m_nTotal = 0;
1249 m_nSelected = 0;
1250 m_nLineAdded = 0;
1251 m_nLineDeleted = 0;
1252 m_nRenamed = 0;
1254 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1256 int status=((CTGitPath*)m_arStatusArray[i])->m_Action;
1258 m_nLineAdded += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatAdd);
1259 m_nLineDeleted += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatDel);
1261 if(status&(CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
1262 m_nAdded++;
1264 if(status&CTGitPath::LOGACTIONS_DELETED)
1265 m_nDeleted++;
1267 if(status&(CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_MODIFIED))
1268 m_nModified++;
1270 if(status&CTGitPath::LOGACTIONS_UNMERGED)
1271 m_nConflicted++;
1273 if(status&(CTGitPath::LOGACTIONS_IGNORE|CTGitPath::LOGACTIONS_UNVER))
1274 m_nUnversioned++;
1276 if(status&(CTGitPath::LOGACTIONS_REPLACED))
1277 m_nRenamed++;
1279 if(((CTGitPath*)m_arStatusArray[i])->m_Checked)
1280 m_nSelected++;
1282 // } // switch (entry->status)
1283 // } // if (entry)
1284 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1285 return !bRefetchStatus;
1287 return FALSE;
1291 int CGitStatusListCtrl::GetGroupFromPoint(POINT * ppt)
1293 // the point must be relative to the upper left corner of the control
1295 if (ppt == NULL)
1296 return -1;
1297 if (!IsGroupViewEnabled())
1298 return -1;
1300 POINT pt = *ppt;
1301 pt.x = 10;
1302 UINT flags = 0;
1303 int nItem = -1;
1304 RECT rc;
1305 GetWindowRect(&rc);
1306 while (((flags & LVHT_BELOW) == 0)&&(pt.y < rc.bottom))
1308 nItem = HitTest(pt, &flags);
1309 if ((flags & LVHT_ONITEM)||(flags & LVHT_EX_GROUP_HEADER))
1311 // the first item below the point
1313 // check if the point is too much right (i.e. if the point
1314 // is farther to the right than the width of the item)
1315 RECT r;
1316 GetItemRect(nItem, &r, LVIR_LABEL);
1317 if (ppt->x > r.right)
1318 return -1;
1320 LVITEM lv = {0};
1321 lv.mask = LVIF_GROUPID;
1322 lv.iItem = nItem;
1323 GetItem(&lv);
1324 int groupID = lv.iGroupId;
1325 // now we search upwards and check if the item above this one
1326 // belongs to another group. If it belongs to the same group,
1327 // we're not over a group header
1328 while (pt.y >= 0)
1330 pt.y -= 2;
1331 nItem = HitTest(pt, &flags);
1332 if ((flags & LVHT_ONITEM)&&(nItem >= 0))
1334 // the first item below the point
1335 LVITEM lv = {0};
1336 lv.mask = LVIF_GROUPID;
1337 lv.iItem = nItem;
1338 GetItem(&lv);
1339 if (lv.iGroupId != groupID)
1340 return groupID;
1341 else
1342 return -1;
1345 if (pt.y < 0)
1346 return groupID;
1347 return -1;
1349 pt.y += 2;
1351 return -1;
1354 void CGitStatusListCtrl::OnContextMenuGroup(CWnd * /*pWnd*/, CPoint point)
1356 POINT clientpoint = point;
1357 ScreenToClient(&clientpoint);
1358 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint) >= 0))
1360 CMenu popup;
1361 if (popup.CreatePopupMenu())
1363 CString temp;
1364 temp.LoadString(IDS_STATUSLIST_CHECKGROUP);
1365 popup.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_CHECKGROUP, temp);
1366 temp.LoadString(IDS_STATUSLIST_UNCHECKGROUP);
1367 popup.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_UNCHECKGROUP, temp);
1368 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1369 bool bCheck = false;
1370 switch (cmd)
1372 case IDGITLC_CHECKGROUP:
1373 bCheck = true;
1374 // fall through here
1375 case IDGITLC_UNCHECKGROUP:
1377 int group = GetGroupFromPoint(&clientpoint);
1378 // go through all items and check/uncheck those assigned to the group
1379 // but block the OnLvnItemChanged handler
1380 m_bBlock = true;
1381 LVITEM lv;
1382 for (int i=0; i<GetItemCount(); ++i)
1384 SecureZeroMemory(&lv, sizeof(LVITEM));
1385 lv.mask = LVIF_GROUPID;
1386 lv.iItem = i;
1387 GetItem(&lv);
1389 if (lv.iGroupId == group)
1391 CTGitPath * entry = (CTGitPath*)GetItemData(i);
1392 if (entry)
1394 bool bOldCheck = entry->m_Checked;
1395 SetEntryCheck(entry, i, bCheck);
1396 if (bCheck != bOldCheck)
1398 if (bCheck)
1399 m_nSelected++;
1400 else
1401 m_nSelected--;
1407 GetStatisticsString();
1408 NotifyCheck();
1409 m_bBlock = false;
1411 break;
1417 void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point)
1420 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1422 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1423 CTGitPath * filepath;
1425 int selIndex = GetSelectionMark();
1426 if ((point.x == -1) && (point.y == -1))
1428 CRect rect;
1429 GetItemRect(selIndex, &rect, LVIR_LABEL);
1430 ClientToScreen(&rect);
1431 point = rect.CenterPoint();
1433 if ((GetSelectedCount() == 0) && (m_bHasCheckboxes))
1435 // nothing selected could mean the context menu is requested for
1436 // a group header
1437 OnContextMenuGroup(pWnd, point);
1439 else if (selIndex >= 0)
1441 //FileEntry * entry = GetListEntry(selIndex);
1443 filepath = (CTGitPath * )GetItemData(selIndex);
1445 ASSERT(filepath != NULL);
1446 if (filepath == NULL)
1447 return;
1449 //const CTGitPath& filepath = entry->path;
1450 int wcStatus = filepath->m_Action;
1451 // entry is selected, now show the popup menu
1452 Locker lock(m_critSec);
1453 CIconMenu popup;
1454 CMenu changelistSubMenu;
1455 CMenu ignoreSubMenu;
1456 if (popup.CreatePopupMenu())
1458 //Add Menu for version controlled file
1460 if (GetSelectedCount() > 0 && wcStatus & CTGitPath::LOGACTIONS_UNMERGED)
1462 if (GetSelectedCount() == 1 && (m_dwContextMenus & GITSLC_POPCONFLICT)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1464 popup.AppendMenuIcon(IDGITLC_EDITCONFLICT, IDS_MENUCONFLICT, IDI_CONFLICT);
1466 if (m_dwContextMenus & GITSLC_POPRESOLVE)
1468 popup.AppendMenuIcon(IDGITLC_RESOLVECONFLICT, IDS_STATUSLIST_CONTEXT_RESOLVED, IDI_RESOLVE);
1470 if ((m_dwContextMenus & GITSLC_POPRESOLVE)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1472 popup.AppendMenuIcon(IDGITLC_RESOLVETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS, IDI_RESOLVE);
1473 popup.AppendMenuIcon(IDGITLC_RESOLVEMINE, IDS_SVNPROGRESS_MENUUSEMINE, IDI_RESOLVE);
1475 if ((m_dwContextMenus & GITSLC_POPCONFLICT)||(m_dwContextMenus & GITSLC_POPRESOLVE))
1476 popup.AppendMenu(MF_SEPARATOR);
1479 if (GetSelectedCount() > 0)
1481 if (wcStatus & CTGitPath::LOGACTIONS_UNVER)
1482 if (m_dwContextMenus & GITSLC_POPADD)
1484 //if ( entry->IsFolder() )
1486 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1488 //else
1490 popup.AppendMenuIcon(IDGITLC_ADD, IDS_STATUSLIST_CONTEXT_ADD, IDI_ADD);
1495 if (!(wcStatus &CTGitPath::LOGACTIONS_UNVER))
1497 if ( (m_dwContextMenus & GITSLC_POPCOMPAREWITHBASE) && GetSelectedCount()>0)
1499 if(filepath->m_ParentNo & MERGE_MASK)
1500 popup.AppendMenuIcon(IDGITLC_COMPARE, IDS_TREE_DIFF, IDI_DIFF);
1501 else
1502 popup.AppendMenuIcon(IDGITLC_COMPARE, IDS_LOG_COMPAREWITHBASE, IDI_DIFF);
1504 popup.SetDefaultItem(IDGITLC_COMPARE, FALSE);
1507 if ((m_dwContextMenus & this->GetContextMenuBit(IDGITLC_COMPAREWC)) && GetSelectedCount()>0 && m_bHasWC)
1509 if( (!m_CurrentVersion.IsEmpty()) && m_CurrentVersion != GIT_REV_ZERO)
1510 popup.AppendMenuIcon(IDGITLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1512 //Select one items
1513 if (GetSelectedCount() == 1)
1515 bool bEntryAdded = false;
1516 //if (entry->remotestatus <= git_wc_status_normal)
1518 // if (wcStatus > git_wc_status_normal)
1519 // {
1520 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
1521 // {
1522 if(!g_Git.IsInitRepos() && (m_dwContextMenus&GITSLC_POPGNUDIFF))
1524 popup.AppendMenuIcon(IDGITLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1526 bEntryAdded = true;
1528 // }
1529 // }
1532 //else if (wcStatus != git_wc_status_deleted)
1534 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
1535 // {
1536 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1537 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1538 // bEntryAdded = true;
1539 // }
1540 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
1541 // {
1542 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1543 // bEntryAdded = true;
1544 // }
1546 if (bEntryAdded)
1547 popup.AppendMenu(MF_SEPARATOR);
1549 //else if (GetSelectedCount() > 1)
1551 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1552 // {
1553 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1554 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1555 // }
1559 if( (!this->m_Rev1.IsEmpty()) || (!this->m_Rev1.IsEmpty()) )
1561 if(GetSelectedCount() == 1)
1563 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_COMPARETWO))
1565 popup.AppendMenuIcon(IDGITLC_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1566 popup.SetDefaultItem(IDGITLC_COMPARETWO, FALSE);
1568 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_GNUDIFF2))
1570 popup.AppendMenuIcon(IDGITLC_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1575 //Select Multi item
1576 if (GetSelectedCount() > 0)
1578 if ((GetSelectedCount() == 2) && (m_dwContextMenus & this->GetContextMenuBit(GITSLC_POPCOMPARETWOFILES)) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO))
1580 POSITION pos = GetFirstSelectedItemPosition();
1581 int index = GetNextSelectedItem(pos);
1582 if (index >= 0)
1584 CTGitPath * entry2 = NULL;
1585 bool bothItemsAreExistingFiles = true;
1586 entry2 = (CTGitPath * )GetItemData(index);
1587 if (entry2)
1588 bothItemsAreExistingFiles = !entry2->IsDirectory() && entry2->Exists();
1589 index = GetNextSelectedItem(pos);
1590 if (index >= 0)
1592 entry2 = (CTGitPath * )GetItemData(index);
1593 if (entry2)
1594 bothItemsAreExistingFiles = bothItemsAreExistingFiles && !entry2->IsDirectory() && entry2->Exists();
1595 if (bothItemsAreExistingFiles)
1596 popup.AppendMenuIcon(IDGITLC_COMPARETWOFILES, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES, IDI_DIFF);
1600 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
1601 // {
1602 // POSITION pos = GetFirstSelectedItemPosition();
1603 // int index = GetNextSelectedItem(pos);
1604 // if (index >= 0)
1605 // {
1606 // FileEntry * entry = GetListEntry(index);
1607 // git_wc_status_kind status1 = git_wc_status_none;
1608 // git_wc_status_kind status2 = git_wc_status_none;
1609 // if (entry)
1610 // status1 = entry->status;
1611 // index = GetNextSelectedItem(pos);
1612 // if (index >= 0)
1613 // {
1614 // entry = GetListEntry(index);
1615 // if (entry)
1616 // status2 = entry->status;
1617 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
1618 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
1619 // {
1620 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
1621 // }
1622 // }
1623 // }
1624 // }
1625 // if (wcStatus > git_wc_status_normal)
1626 // {
1627 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1628 // {
1629 // // reverting missing folders is not possible
1630 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1631 // {
1632 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1633 // }
1634 // }
1635 // }
1636 // if (entry->remotestatus > git_wc_status_normal)
1637 // {
1638 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1639 // {
1640 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1641 // }
1642 // }
1645 if ( (GetSelectedCount() >0 ) && (!(wcStatus & CTGitPath::LOGACTIONS_UNVER)) && m_bHasWC)
1647 if ((m_dwContextMenus & GITSLC_POPREVERT) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO))
1649 popup.AppendMenuIcon(IDGITLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1652 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())
1654 popup.AppendMenuIcon(IDGITLC_ASSUMEVALID, IDS_MENUASSUMEVALID);
1657 if (m_dwContextMenus & GITSLC_POPRESTORE && !filepath->IsDirectory())
1659 if (m_restorepaths.find(filepath->GetWinPathString()) == m_restorepaths.end())
1660 popup.AppendMenuIcon(IDGITLC_CREATERESTORE, IDS_MENUCREATERESTORE, IDI_RESTORE);
1661 else
1662 popup.AppendMenuIcon(IDGITLC_RESTOREPATH, IDS_MENURESTORE, IDI_RESTORE);
1665 if ((m_dwContextMenus & GetContextMenuBit(IDGITLC_REVERTTOREV)) && ( !this->m_CurrentVersion.IsEmpty() )
1666 && this->m_CurrentVersion != GIT_REV_ZERO && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1668 popup.AppendMenuIcon(IDGITLC_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1672 if ((GetSelectedCount() == 1)&&(!(wcStatus & CTGitPath::LOGACTIONS_UNVER))
1673 &&(!(wcStatus & CTGitPath::LOGACTIONS_IGNORE)))
1675 if (m_dwContextMenus & GITSLC_POPSHOWLOG)
1677 popup.AppendMenuIcon(IDGITLC_LOG, IDS_REPOBROWSE_SHOWLOG, IDI_LOG);
1679 if (m_dwContextMenus & GITSLC_POPSHOWLOGOLDNAME && (wcStatus & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !filepath->GetGitOldPathString().IsEmpty()))
1681 popup.AppendMenuIcon(IDGITLC_LOGOLDNAME, IDS_STATUSLIST_SHOWLOGOLDNAME, IDI_LOG);
1683 if (m_dwContextMenus & GITSLC_POPBLAME && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED) && m_bHasWC)
1685 popup.AppendMenuIcon(IDGITLC_BLAME, IDS_MENUBLAME, IDI_BLAME);
1688 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1689 if ( (GetSelectedCount() == 1) )
1691 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_SAVEAS) && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1693 popup.AppendMenuIcon(IDGITLC_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
1696 if (m_dwContextMenus & GITSLC_POPOPEN && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1698 popup.AppendMenuIcon(IDGITLC_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1699 popup.AppendMenuIcon(IDGITLC_OPEN, IDS_REPOBROWSE_OPEN, IDI_OPEN);
1700 popup.AppendMenuIcon(IDGITLC_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1701 if (wcStatus &CTGitPath::LOGACTIONS_UNVER) {
1702 popup.SetDefaultItem(IDGITLC_OPEN, FALSE);
1706 if (m_dwContextMenus & GITSLC_POPEXPLORE && !(wcStatus & CTGitPath::LOGACTIONS_DELETED) && m_bHasWC)
1708 popup.AppendMenuIcon(IDGITLC_EXPLORE, IDS_STATUSLIST_CONTEXT_EXPLORE, IDI_EXPLORER);
1712 if (GetSelectedCount() > 0)
1714 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
1715 // {
1716 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1717 // }
1718 // 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))
1719 // {
1720 // if (bShift)
1721 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
1722 // else
1723 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
1724 // }
1725 if ((wcStatus & CTGitPath::LOGACTIONS_UNVER)/*||(wcStatus == git_wc_status_deleted)*/)
1727 if (m_dwContextMenus & GITSLC_POPDELETE)
1729 popup.AppendMenuIcon(IDGITLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1732 if ( (wcStatus & CTGitPath::LOGACTIONS_UNVER || wcStatus & CTGitPath::LOGACTIONS_DELETED) )
1734 if (m_dwContextMenus & GITSLC_POPIGNORE)
1737 CTGitPathList ignorelist;
1738 FillListOfSelectedItemPaths(ignorelist);
1739 //check if all selected entries have the same extension
1740 bool bSameExt = true;
1741 CString sExt;
1742 for (int i=0; i<ignorelist.GetCount(); ++i)
1744 if (sExt.IsEmpty() && (i==0))
1745 sExt = ignorelist[i].GetFileExtension();
1746 else if (sExt.CompareNoCase(ignorelist[i].GetFileExtension())!=0)
1747 bSameExt = false;
1749 if (bSameExt)
1751 if (ignoreSubMenu.CreateMenu())
1753 CString ignorepath;
1754 if (ignorelist.GetCount()==1)
1755 ignorepath = ignorelist[0].GetFileOrDirectoryName();
1756 else
1757 ignorepath.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
1758 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_IGNORE, ignorepath);
1759 ignorepath = _T("*")+sExt;
1760 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_IGNOREMASK, ignorepath);
1761 CString temp;
1762 temp.LoadString(IDS_MENUIGNORE);
1763 popup.InsertMenu((UINT)-1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)ignoreSubMenu.m_hMenu, temp);
1766 else
1768 CString temp;
1769 if (ignorelist.GetCount()==1)
1771 temp.LoadString(IDS_MENUIGNORE);
1773 else
1775 temp.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
1777 popup.AppendMenuIcon(IDGITLC_IGNORE, temp, IDI_IGNORE);
1785 if (GetSelectedCount() > 0)
1787 popup.AppendMenu(MF_SEPARATOR);
1788 popup.AppendMenuIcon(IDGITLC_COPY, IDS_STATUSLIST_CONTEXT_COPY, IDI_COPYCLIP);
1789 popup.AppendMenuIcon(IDGITLC_COPYEXT, IDS_STATUSLIST_CONTEXT_COPYEXT, IDI_COPYCLIP);
1790 #if 0
1791 if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS))
1792 &&(wcStatus != git_wc_status_unversioned)&&(wcStatus != git_wc_status_none))
1794 popup.AppendMenu(MF_SEPARATOR);
1795 // changelist commands
1796 size_t numChangelists = GetNumberOfChangelistsInSelection();
1797 if (numChangelists > 0)
1799 popup.AppendMenuIcon(IDSVNLC_REMOVEFROMCS, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS);
1801 if ((!entry->IsFolder())&&(changelistSubMenu.CreateMenu()))
1803 CString temp;
1804 temp.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS);
1805 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATECS, temp);
1807 if (entry->changelist.Compare(SVNSLC_IGNORECHANGELIST))
1809 changelistSubMenu.AppendMenu(MF_SEPARATOR);
1810 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATEIGNORECS, SVNSLC_IGNORECHANGELIST);
1813 if (m_changelists.size() > 0)
1815 // find the changelist names
1816 bool bNeedSeparator = true;
1817 int cmdID = IDSVNLC_MOVETOCS;
1818 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
1820 if ((entry->changelist.Compare(it->first))&&(it->first.Compare(SVNSLC_IGNORECHANGELIST)))
1822 if (bNeedSeparator)
1824 changelistSubMenu.AppendMenu(MF_SEPARATOR);
1825 bNeedSeparator = false;
1827 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, cmdID, it->first);
1828 cmdID++;
1832 temp.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS);
1833 popup.AppendMenu(MF_POPUP|MF_STRING, (UINT_PTR)changelistSubMenu.GetSafeHmenu(), temp);
1836 #endif
1839 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1841 m_bBlock = TRUE;
1842 AfxGetApp()->DoWaitCursor(1);
1843 //int iItemCountBeforeMenuCmd = GetItemCount();
1844 //bool bForce = false;
1845 switch (cmd)
1847 case IDGITLC_VIEWREV:
1848 OpenFile(filepath, ALTERNATIVEEDITOR);
1849 break;
1850 case IDGITLC_OPEN:
1851 OpenFile(filepath,OPEN);
1852 break;
1853 case IDGITLC_OPENWITH:
1854 OpenFile(filepath,OPEN_WITH);
1855 break;
1856 case IDGITLC_EXPLORE:
1858 ShellExecute(this->m_hWnd, _T("explore"), filepath->GetDirectory().GetWinPath(), NULL, NULL, SW_SHOW);
1860 break;
1861 case IDGITLC_CREATERESTORE:
1863 POSITION pos = GetFirstSelectedItemPosition();
1864 while (pos)
1866 int index = GetNextSelectedItem(pos);
1867 CTGitPath * entry2 = (CTGitPath * )GetItemData(index);
1868 ASSERT(entry2 != NULL);
1869 if (entry2 == NULL || entry2->IsDirectory())
1870 continue;
1871 if (m_restorepaths.find(entry2->GetWinPathString()) != m_restorepaths.end())
1872 continue;
1873 CTGitPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
1874 if (CopyFile(g_Git.m_CurrentDir + _T("\\") + entry2->GetWinPathString(), tempFile.GetWinPath(), FALSE))
1876 m_restorepaths[entry2->GetWinPathString()] = tempFile.GetWinPathString();
1877 SetItemState(index, INDEXTOOVERLAYMASK(OVL_RESTORE), LVIS_OVERLAYMASK);
1880 Invalidate();
1882 break;
1883 case IDGITLC_RESTOREPATH:
1885 if (CMessageBox::Show(m_hWnd, IDS_STATUSLIST_RESTOREPATH, IDS_APPNAME, 2, IDI_QUESTION, IDS_RESTOREBUTTON, IDS_ABORTBUTTON) == 2)
1886 break;
1887 POSITION pos = GetFirstSelectedItemPosition();
1888 while (pos)
1890 int index = GetNextSelectedItem(pos);
1891 CTGitPath * entry2 = (CTGitPath * )GetItemData(index);
1892 ASSERT(entry2 != NULL);
1893 if (entry2 == NULL)
1894 continue;
1895 if (m_restorepaths.find(entry2->GetWinPathString()) == m_restorepaths.end())
1896 continue;
1897 if (CopyFile(m_restorepaths[entry2->GetWinPathString()], g_Git.m_CurrentDir + _T("\\") + entry2->GetWinPathString(), FALSE))
1899 m_restorepaths.erase(entry2->GetWinPathString());
1900 SetItemState(index, 0, LVIS_OVERLAYMASK);
1903 Invalidate();
1905 break;
1906 // Compare current version and work copy.
1907 case IDGITLC_COMPAREWC:
1909 POSITION pos = GetFirstSelectedItemPosition();
1910 while ( pos )
1912 int index = GetNextSelectedItem(pos);
1913 StartDiffWC(index);
1916 break;
1917 // Compare with base version. when current version is zero, compare workcopy and HEAD.
1918 case IDGITLC_COMPARE:
1920 POSITION pos = GetFirstSelectedItemPosition();
1921 while ( pos )
1923 int index = GetNextSelectedItem(pos);
1924 StartDiff(index);
1927 break;
1928 case IDGITLC_COMPARETWO:
1930 POSITION pos = GetFirstSelectedItemPosition();
1931 while ( pos )
1933 int index = GetNextSelectedItem(pos);
1934 StartDiffTwo(index);
1937 break;
1938 case IDGITLC_COMPARETWOFILES:
1940 POSITION pos = GetFirstSelectedItemPosition();
1941 CTGitPath * firstfilepath = NULL, * secondfilepath = NULL;
1942 if (pos)
1944 firstfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
1945 ASSERT(firstfilepath != NULL);
1946 if (firstfilepath == NULL)
1947 break;
1949 secondfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
1950 ASSERT(secondfilepath != NULL);
1951 if (secondfilepath == NULL)
1952 break;
1954 CString sCmd;
1955 sCmd.Format(_T("/command:diff /path:\"%s\" /path2:\"%s\" /hwnd:%ld"), firstfilepath->GetWinPath(), secondfilepath->GetWinPath(), (unsigned long)m_hWnd);
1956 CAppUtils::RunTortoiseProc(sCmd);
1959 break;
1960 case IDGITLC_GNUDIFF1:
1962 // SVNDiff diff(NULL, this->m_hWnd, true);
1964 // if (entry->remotestatus <= git_wc_status_normal)
1965 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
1966 // else
1967 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
1968 if(m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
1970 CString fromwhere;
1971 if(m_amend)
1972 fromwhere = _T("~1");
1973 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,GitRev::GetHead()+fromwhere,
1974 *filepath,GitRev::GetWorkingCopy());
1976 else
1978 if((filepath->m_ParentNo&(PARENT_MASK|MERGE_MASK)) ==0)
1979 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_CurrentVersion+_T("~1"),
1980 *filepath,m_CurrentVersion);
1981 else
1983 CString str;
1984 if(filepath->m_ParentNo & MERGE_MASK)
1987 else
1989 str.Format(_T("%s^%d"),m_CurrentVersion,(filepath->m_ParentNo&PARENT_MASK)+1);
1992 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath, str,
1993 *filepath, m_CurrentVersion, false, false, false,
1994 !!(filepath->m_ParentNo & MERGE_MASK));
1998 break;
1999 case IDGITLC_GNUDIFF2:
2001 CAppUtils::StartShowUnifiedDiff(m_hWnd, *filepath, m_Rev2, *filepath, m_Rev1);
2003 break;
2005 case IDGITLC_ADD:
2006 { // The add went ok, but we now need to run through the selected items again
2007 // and update their status
2008 std::vector<int> selectIndex;
2010 POSITION pos = GetFirstSelectedItemPosition();
2011 int index;
2012 CMassiveGitTask mgt(L"add -f");
2013 while ((index = GetNextSelectedItem(pos)) >= 0)
2015 CTGitPath * path = (CTGitPath *)GetItemData(index);
2016 ASSERT(path);
2017 if(path == NULL)
2018 continue;
2020 selectIndex.push_back(index);
2021 mgt.AddFile(*path);
2023 BOOL cancel = FALSE;
2024 mgt.Execute(cancel);
2026 if (NULL != GetParent() && NULL != GetParent()->GetSafeHwnd())
2027 GetParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2029 SetRedraw(TRUE);
2031 break;
2033 case IDGITLC_DELETE:
2035 //Collect paths
2036 std::vector<int> selectIndex;
2038 POSITION pos = GetFirstSelectedItemPosition();
2039 int index;
2040 while ((index = GetNextSelectedItem(pos)) >= 0)
2042 selectIndex.push_back(index);
2045 //Create file-list ('\0' separated) for SHFileOperation
2046 CString filelist;
2047 for(int i=0;i<selectIndex.size();i++)
2049 index=selectIndex[i];
2051 CTGitPath * path=(CTGitPath*)GetItemData(index);
2052 ASSERT(path);
2053 if(path == NULL)
2054 continue;
2056 filelist += path->GetWinPathString();
2057 filelist += _T("|");
2059 filelist += _T("|");
2060 int len = filelist.GetLength();
2061 TCHAR * buf = new TCHAR[len+2];
2062 _tcscpy_s(buf, len+2, filelist);
2063 for (int i=0; i<len; ++i)
2064 if (buf[i] == '|')
2065 buf[i] = 0;
2066 SHFILEOPSTRUCT fileop;
2067 fileop.hwnd = this->m_hWnd;
2068 fileop.wFunc = FO_DELETE;
2069 fileop.pFrom = buf;
2070 fileop.pTo = NULL;
2071 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
2072 fileop.lpszProgressTitle = _T("deleting file");
2073 int result = SHFileOperation(&fileop);
2074 delete [] buf;
2076 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
2078 SetRedraw(FALSE);
2079 POSITION pos = NULL;
2080 while ((pos = GetFirstSelectedItemPosition()) != 0)
2082 int index = GetNextSelectedItem(pos);
2083 if (GetCheck(index))
2084 m_nSelected--;
2085 m_nTotal--;
2087 RemoveListEntry(index);
2089 SetRedraw(TRUE);
2092 break;
2094 case IDGITLC_BLAME:
2096 CAppUtils::LaunchTortoiseBlame(g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath(), m_CurrentVersion);
2098 break;
2100 case IDGITLC_LOG:
2102 CString sCmd;
2103 sCmd.Format(_T("/command:log /path:\"%s\""), g_Git.m_CurrentDir + _T("\\") + filepath->GetWinPath());
2104 CAppUtils::RunTortoiseProc(sCmd);
2106 break;
2108 case IDGITLC_LOGOLDNAME:
2110 CTGitPath oldName(filepath->GetGitOldPathString());
2111 CString sCmd;
2112 sCmd.Format(_T("/command:log /path:\"%s\""), g_Git.m_CurrentDir + _T("\\") + oldName.GetWinPath());
2113 CAppUtils::RunTortoiseProc(sCmd);
2115 break;
2118 case IDGITLC_EDITCONFLICT:
2120 CAppUtils::ConflictEdit(*filepath,false,this->m_bIsRevertTheirMy);
2121 break;
2123 case IDGITLC_RESOLVETHEIRS: //follow up
2124 case IDGITLC_RESOLVEMINE: //follow up
2125 case IDGITLC_RESOLVECONFLICT:
2127 if (CMessageBox::Show(m_hWnd, IDS_PROC_RESOLVE, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO)==IDYES)
2129 POSITION pos = GetFirstSelectedItemPosition();
2130 while (pos != 0)
2132 int index;
2133 index = GetNextSelectedItem(pos);
2134 CTGitPath * fentry =(CTGitPath*) this->GetItemData(index);
2135 if(fentry == NULL)
2136 continue;
2137 CString gitcmd,output;
2138 output.Empty();
2140 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVETHEIRS) ||
2141 ((this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVEMINE) )
2143 gitcmd.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry->GetGitPathString());
2144 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2146 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2147 continue;
2150 output.Empty();
2151 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVEMINE) ||
2152 ((this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVETHEIRS) )
2154 gitcmd.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry->GetGitPathString());
2155 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2157 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2158 continue;
2162 output.Empty();
2163 if ( fentry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
2165 gitcmd.Format(_T("git.exe add -f -- \"%s\""),fentry->GetGitPathString());
2166 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2168 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2170 else
2172 fentry->m_Action |= CTGitPath::LOGACTIONS_MODIFIED;
2173 fentry->m_Action &=~CTGitPath::LOGACTIONS_UNMERGED;
2177 CAppUtils::RemoveTempMergeFile(*fentry);
2180 Show(m_dwShow, 0, m_bShowFolders,0,true);
2183 break;
2185 case IDGITLC_IGNORE:
2187 CTGitPathList ignorelist;
2188 //std::vector<CString> toremove;
2189 FillListOfSelectedItemPaths(ignorelist, true);
2190 SetRedraw(FALSE);
2192 if(!CAppUtils::IgnoreFile(ignorelist,false))
2193 break;
2195 for(int i=0;i<ignorelist.GetCount();i++)
2197 int nListboxEntries = GetItemCount();
2198 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2200 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2201 if (path->GetGitPathString()==ignorelist[i].GetGitPathString())
2203 RemoveListEntry(nItem);
2204 break;
2208 SetRedraw(TRUE);
2210 break;
2211 case IDGITLC_IGNOREMASK:
2213 CString common;
2214 CString ext=filepath->GetFileExtension();
2215 CTGitPathList ignorelist;
2216 FillListOfSelectedItemPaths(ignorelist, true);
2217 SetRedraw(FALSE);
2219 CAppUtils::IgnoreFile(ignorelist,true);
2221 common=ignorelist.GetCommonRoot().GetGitPathString();
2223 for (int i=0; i< GetItemCount(); ++i)
2225 CTGitPath *path=(CTGitPath*)GetItemData(i);
2226 if(!( path->m_Action & CTGitPath::LOGACTIONS_UNVER))
2227 continue;
2228 if( path->GetGitPathString().Left(common.GetLength()) == common )
2230 if (path->GetFileExtension()==ext)
2232 RemoveListEntry(i);
2233 i--; // remove index i at item, new one will replace.
2238 CWnd* pParent = GetParent();
2239 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2241 pParent->SendMessage(GITSLNM_NEEDSREFRESH);
2244 SetRedraw(TRUE);
2246 break;
2248 case IDGITLC_REVERT:
2250 // If at least one item is not in the status "added"
2251 // we ask for a confirmation
2252 BOOL bConfirm = FALSE;
2253 POSITION pos = GetFirstSelectedItemPosition();
2254 int index;
2255 while ((index = GetNextSelectedItem(pos)) >= 0)
2257 //FileEntry * fentry = GetListEntry(index);
2258 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
2259 if(fentry && fentry->m_Action &CTGitPath::LOGACTIONS_MODIFIED && !fentry->IsDirectory())
2261 bConfirm = TRUE;
2262 break;
2266 CString str;
2267 str.Format(IDS_PROC_WARNREVERT,GetSelectedCount());
2269 if (!bConfirm || CMessageBox::Show(this->m_hWnd, str, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION)==IDYES)
2271 CTGitPathList targetList;
2272 FillListOfSelectedItemPaths(targetList);
2274 // make sure that the list is reverse sorted, so that
2275 // children are removed before any parents
2276 targetList.SortByPathname(true);
2278 // put all reverted files in the trashbin, except the ones with 'added'
2279 // status because they are not restored by the revert.
2280 CTGitPathList delList;
2281 POSITION pos = GetFirstSelectedItemPosition();
2282 int index;
2283 while ((index = GetNextSelectedItem(pos)) >= 0)
2285 CTGitPath *entry=(CTGitPath *)GetItemData(index);
2286 if (entry&&(!(entry->m_Action& CTGitPath::LOGACTIONS_ADDED))
2287 && (!(entry->m_Action& CTGitPath::LOGACTIONS_REPLACED)) && !entry->IsDirectory())
2289 CTGitPath fullpath;
2290 fullpath.SetFromWin(g_Git.m_CurrentDir+_T("\\")+entry->GetWinPath());
2291 delList.AddPath(fullpath);
2294 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2295 delList.DeleteAllFiles(true);
2297 CString revertToCommit = _T("HEAD");
2298 if (m_amend)
2299 revertToCommit = _T("HEAD~1");
2300 if (g_Git.Revert(revertToCommit, targetList))
2302 CMessageBox::Show(this->m_hWnd, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR);
2304 else
2306 bool updateStatusList = false;
2307 for(int i=0;i<targetList.GetCount();i++)
2309 int nListboxEntries = GetItemCount();
2310 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2312 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2313 if (path->GetGitPathString()==targetList[i].GetGitPathString() && !path->IsDirectory())
2315 if(path->m_Action & CTGitPath::LOGACTIONS_ADDED)
2317 path->m_Action = CTGitPath::LOGACTIONS_UNVER;
2318 SetEntryCheck(path,nItem,false);
2319 updateStatusList = true;
2320 SetItemGroup(nItem,1);
2321 this->m_StatusFileList.RemoveItem(*path);
2322 this->m_UnRevFileList.AddPath(*path);
2323 //this->m_IgnoreFileList.RemoveItem(*path);
2326 else
2328 RemoveListEntry(nItem);
2330 break;
2332 else if (path->GetGitPathString()==targetList[i].GetGitPathString() && path->IsDirectory() && path->IsWCRoot())
2334 CString sCmd;
2335 sCmd.Format(_T("/command:revert /path:\"%s\""), path->GetGitPathString());
2336 CCommonAppUtils::RunTortoiseProc(sCmd);
2340 SetRedraw(TRUE);
2341 SaveColumnWidths();
2342 Show(m_dwShow, 0, m_bShowFolders,updateStatusList,true);
2343 NotifyCheck();
2347 break;
2349 case IDGITLC_ASSUMEVALID:
2351 CString cmdTemplate;
2352 cmdTemplate = _T("git.exe update-index --assume-unchanged \"%s\"");
2353 POSITION pos = GetFirstSelectedItemPosition();
2354 int index = -1;
2355 while ((index = GetNextSelectedItem(pos)) >= 0)
2357 CTGitPath * path = (CTGitPath *)GetItemData(index);
2358 ASSERT(path);
2359 if(path == NULL)
2360 continue;
2362 CString cmd, output;
2363 cmd.Format(cmdTemplate, path->GetGitPathString());
2364 if (g_Git.Run(cmd, &output, CP_UTF8))
2366 MessageBox(output, _T("TortoiseGit"), MB_ICONERROR);
2369 if (NULL != GetParent() && NULL != GetParent()->GetSafeHwnd())
2370 GetParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2372 SetRedraw(TRUE);
2374 break;
2376 case IDGITLC_COPY:
2377 CopySelectedEntriesToClipboard(0);
2378 break;
2379 case IDGITLC_COPYEXT:
2380 CopySelectedEntriesToClipboard((DWORD)-1);
2381 break;
2383 case IDGITLC_SAVEAS:
2384 FileSaveAs(filepath);
2385 break;
2387 case IDGITLC_REVERTTOREV:
2388 RevertSelectedItemToVersion();
2389 break;
2390 #if 0
2391 case IDSVNLC_COMMIT:
2393 CTSVNPathList targetList;
2394 FillListOfSelectedItemPaths(targetList);
2395 CTSVNPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
2396 VERIFY(targetList.WriteToFile(tempFile.GetWinPathString()));
2397 CString commandline = CPathUtils::GetAppDirectory();
2398 commandline += _T("TortoiseProc.exe /command:commit /pathfile:\"");
2399 commandline += tempFile.GetWinPathString();
2400 commandline += _T("\"");
2401 commandline += _T(" /deletepathfile");
2402 CAppUtils::LaunchApplication(commandline, NULL, false);
2404 break;
2405 case IDSVNLC_CREATEIGNORECS:
2406 CreateChangeList(SVNSLC_IGNORECHANGELIST);
2407 break;
2408 case IDSVNLC_CREATECS:
2410 CCreateChangelistDlg dlg;
2411 if (dlg.DoModal() == IDOK)
2413 CreateChangeList(dlg.m_sName);
2416 break;
2417 default:
2419 if (cmd < IDSVNLC_MOVETOCS)
2420 break;
2421 CTSVNPathList changelistItems;
2422 FillListOfSelectedItemPaths(changelistItems);
2424 // find the changelist name
2425 CString sChangelist;
2426 int cmdID = IDSVNLC_MOVETOCS;
2427 SetRedraw(FALSE);
2428 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
2430 if ((it->first.Compare(SVNSLC_IGNORECHANGELIST))&&(entry->changelist.Compare(it->first)))
2432 if (cmd == cmdID)
2434 sChangelist = it->first;
2436 cmdID++;
2439 if (!sChangelist.IsEmpty())
2441 SVN git;
2442 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
2444 // The changelists were moved, but we now need to run through the selected items again
2445 // and update their changelist
2446 POSITION pos = GetFirstSelectedItemPosition();
2447 int index;
2448 while ((index = GetNextSelectedItem(pos)) >= 0)
2450 FileEntry * e = GetListEntry(index);
2451 e->changelist = sChangelist;
2452 if (!e->IsFolder())
2454 if (m_changelists.find(e->changelist)!=m_changelists.end())
2455 SetItemGroup(index, m_changelists[e->changelist]);
2456 else
2457 SetItemGroup(index, 0);
2461 else
2463 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
2466 SetRedraw(TRUE);
2468 break;
2469 #endif
2471 } // switch (cmd)
2472 m_bBlock = FALSE;
2473 AfxGetApp()->DoWaitCursor(-1);
2474 GetStatisticsString();
2475 //int iItemCountAfterMenuCmd = GetItemCount();
2476 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
2478 // CWnd* pParent = GetParent();
2479 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2480 // {
2481 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
2482 // }
2484 } // if (popup.CreatePopupMenu())
2485 } // if (selIndex >= 0)
2489 void CGitStatusListCtrl::OnContextMenuHeader(CWnd * pWnd, CPoint point)
2491 Locker lock(m_critSec);
2492 m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
2495 void CGitStatusListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
2498 if (pWnd == this)
2500 OnContextMenuList(pWnd, point);
2501 } // if (pWnd == this)
2502 else if (pWnd == GetHeaderCtrl())
2504 OnContextMenuHeader(pWnd, point);
2508 void CGitStatusListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
2511 Locker lock(m_critSec);
2512 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2513 *pResult = 0;
2514 if (m_bBlock)
2515 return;
2517 if (pNMLV->iItem < 0)
2519 if (!IsGroupViewEnabled())
2520 return;
2521 POINT pt;
2522 DWORD ptW = GetMessagePos();
2523 pt.x = GET_X_LPARAM(ptW);
2524 pt.y = GET_Y_LPARAM(ptW);
2525 ScreenToClient(&pt);
2526 int group = GetGroupFromPoint(&pt);
2527 if (group < 0)
2528 return;
2529 // check/uncheck the whole group depending on the check-state
2530 // of the first item in the group
2531 m_bBlock = true;
2532 bool bCheck = false;
2533 bool bFirst = false;
2534 LVITEM lv;
2535 for (int i=0; i<GetItemCount(); ++i)
2537 SecureZeroMemory(&lv, sizeof(LVITEM));
2538 lv.mask = LVIF_GROUPID;
2539 lv.iItem = i;
2540 GetItem(&lv);
2541 if (lv.iGroupId == group)
2543 CTGitPath *entry=(CTGitPath*)GetItemData(i);
2545 if (!bFirst)
2547 bCheck = !GetCheck(i);
2548 bFirst = true;
2550 if (entry)
2552 bool bOldCheck = !!GetCheck(i);
2553 SetEntryCheck(entry, i, bCheck);
2554 if (bCheck != bOldCheck)
2556 if (bCheck)
2557 m_nSelected++;
2558 else
2559 m_nSelected--;
2564 GetStatisticsString();
2565 m_bBlock = false;
2566 NotifyCheck();
2567 return;
2570 CTGitPath *file=(CTGitPath*)GetItemData(pNMLV->iItem);
2572 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER) {
2573 OpenFile(file, OPEN);
2574 return;
2576 if( file->m_Action&CTGitPath::LOGACTIONS_UNMERGED )
2578 CAppUtils::ConflictEdit(*file,false,m_bIsRevertTheirMy);
2581 else
2583 if( (!m_Rev1.IsEmpty()) || (!m_Rev1.IsEmpty())) // m_Rev1 twice???
2584 StartDiffTwo(pNMLV->iItem);
2585 else
2586 StartDiff(pNMLV->iItem);
2590 void CGitStatusListCtrl::StartDiffTwo(int fileindex)
2592 if(fileindex<0)
2593 return;
2595 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
2597 CGitDiff::Diff(&file1,&file1,
2598 m_Rev1,
2599 m_Rev2);
2602 void CGitStatusListCtrl::StartDiffWC(int fileindex)
2604 if(fileindex<0)
2605 return;
2607 CString Ver;
2608 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
2609 return;
2611 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
2613 CGitDiff::Diff(&file1,&file1, GIT_REV_ZERO, m_CurrentVersion);
2617 void CGitStatusListCtrl::StartDiff(int fileindex)
2619 if(fileindex<0)
2620 return;
2622 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
2623 CTGitPath file2;
2624 if(file1.m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
2626 file2.SetFromGit(file1.GetGitOldPathString());
2628 else
2630 file2=file1;
2633 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
2635 CString fromwhere;
2636 if(m_amend && (file1.m_Action & CTGitPath::LOGACTIONS_ADDED) == 0)
2637 fromwhere = _T("~1");
2638 if( g_Git.IsInitRepos())
2639 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
2640 GIT_REV_ZERO);
2641 else if( file1.m_Action&CTGitPath::LOGACTIONS_ADDED )
2642 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
2643 m_CurrentVersion+fromwhere,true);
2644 else if( file1.m_Action&CTGitPath::LOGACTIONS_DELETED )
2645 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
2646 GitRev::GetHead()+fromwhere,false);
2647 else
2648 CGitDiff::Diff(&file1,&file2,
2649 CString(GIT_REV_ZERO),
2650 GitRev::GetHead()+fromwhere);
2652 else
2654 GitRev rev;
2655 CString fromwhere = m_CurrentVersion+_T("~1");
2656 if(m_amend)
2657 fromwhere = m_CurrentVersion+_T("~2");
2658 if(rev.GetCommit(fromwhere) || (file1.m_Action == file1.LOGACTIONS_ADDED))
2660 CGitDiff::DiffNull(&file1,m_CurrentVersion,true);
2663 else if (file1.m_Action == file1.LOGACTIONS_DELETED)
2665 if (file1.m_ParentNo > 0)
2666 fromwhere.Format(_T("%s^%d"), m_CurrentVersion, file1.m_ParentNo + 1);
2668 CGitDiff::DiffNull(&file1,fromwhere,false);
2670 else
2672 if( file1.m_ParentNo & MERGE_MASK)
2675 CTGitPath base, theirs, mine, merge;
2677 CString temppath;
2678 GetTempPath(temppath);
2679 temppath.TrimRight(_T("\\"));
2681 mine.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".LOCAL") + file1.GetFileExtension());
2682 theirs.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".REMOTE") + file1.GetFileExtension());
2683 base.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".BASE") + file1.GetFileExtension());
2685 CFile tempfile;
2686 //create a empty file, incase stage is not three
2687 tempfile.Open(mine.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
2688 tempfile.Close();
2689 tempfile.Open(theirs.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
2690 tempfile.Close();
2691 tempfile.Open(base.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
2692 tempfile.Close();
2694 merge.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".Merged") + file1.GetFileExtension());
2696 int parent1=-1, parent2 =-1;
2697 for(int i=0;i<this->m_arStatusArray.size();i++)
2699 if(m_arStatusArray[i]->GetGitPathString() == file1.GetGitPathString())
2701 if(m_arStatusArray[i]->m_ParentNo & MERGE_MASK)
2704 else
2706 if(parent1<0)
2708 parent1 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
2710 else if (parent2 <0)
2712 parent2 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
2718 if(g_Git.GetOneFile(m_CurrentVersion, file1, (CString&)merge.GetWinPathString()))
2720 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2723 if(parent1>=0)
2725 CString str;
2726 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent1+1);
2728 if(g_Git.GetOneFile(str, file1, (CString&)mine.GetWinPathString()))
2730 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2734 if(parent2>=0)
2736 CString str;
2737 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent2+1);
2739 if(g_Git.GetOneFile(str, file1, (CString&)theirs.GetWinPathString()))
2741 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2745 if(parent1>=0 && parent2>=0)
2747 CString cmd, output;
2748 cmd.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion, parent1+1,
2749 this->m_CurrentVersion,parent2+1);
2751 if (g_Git.Run(cmd, &output, NULL, CP_UTF8))
2754 else
2756 if(g_Git.GetOneFile(output.Left(40), file1, (CString&)base.GetWinPathString()))
2758 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETBASEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
2762 CAppUtils::StartExtMerge(base, theirs, mine, merge,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
2765 else
2767 CString str;
2768 if( (file1.m_ParentNo&PARENT_MASK) == 0)
2770 str = _T("~1");
2772 else
2774 str.Format(_T("^%d"), (file1.m_ParentNo&PARENT_MASK)+1);
2776 CGitDiff::Diff(&file1,&file2,
2777 m_CurrentVersion,
2778 m_CurrentVersion+str);
2784 CString CGitStatusListCtrl::GetStatisticsString(bool simple)
2787 CString sNormal, sAdded, sDeleted, sModified, sConflicted, sUnversioned, sRenamed;
2788 WORD langID = (WORD)(DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
2789 TCHAR buf[MAX_STATUS_STRING_LENGTH];
2790 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal, buf, _countof(buf), langID);
2791 sNormal = buf;
2792 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added, buf, _countof(buf), langID);
2793 sAdded = buf;
2794 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted, buf, _countof(buf), langID);
2795 sDeleted = buf;
2796 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified, buf, _countof(buf), langID);
2797 sModified = buf;
2798 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted, buf, _countof(buf), langID);
2799 sConflicted = buf;
2800 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned, buf, _countof(buf), langID);
2801 sUnversioned = buf;
2802 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced, buf, _countof(buf), langID);
2803 sRenamed = buf;
2804 CString sToolTip;
2805 if(simple)
2807 sToolTip.Format(IDS_STATUSLIST_STATUSLINE1,
2808 this->m_nLineAdded,this->m_nLineDeleted,
2809 (LPCTSTR)sModified, m_nModified,
2810 (LPCTSTR)sAdded, m_nAdded,
2811 (LPCTSTR)sDeleted, m_nDeleted,
2812 (LPCTSTR)sRenamed, m_nRenamed
2815 else
2817 sToolTip.Format(IDS_STATUSLIST_STATUSLINE2,
2818 this->m_nLineAdded,this->m_nLineDeleted,
2819 (LPCTSTR)sNormal, m_nNormal,
2820 (LPCTSTR)sUnversioned, m_nUnversioned,
2821 (LPCTSTR)sModified, m_nModified,
2822 (LPCTSTR)sAdded, m_nAdded,
2823 (LPCTSTR)sDeleted, m_nDeleted,
2824 (LPCTSTR)sConflicted, m_nConflicted
2827 CString sStats;
2828 sStats.Format(IDS_COMMITDLG_STATISTICSFORMAT, m_nSelected, GetItemCount());
2829 if (m_pStatLabel)
2831 m_pStatLabel->SetWindowText(sStats);
2834 if (m_pSelectButton)
2836 if (m_nSelected == 0)
2837 m_pSelectButton->SetCheck(BST_UNCHECKED);
2838 else if (m_nSelected != GetItemCount())
2839 m_pSelectButton->SetCheck(BST_INDETERMINATE);
2840 else
2841 m_pSelectButton->SetCheck(BST_CHECKED);
2844 if (m_pConfirmButton)
2846 m_pConfirmButton->EnableWindow(m_nSelected>0);
2849 return sToolTip;
2854 CString CGitStatusListCtrl::GetCommonDirectory(bool bStrict)
2856 if (!bStrict)
2858 // not strict means that the selected folder has priority
2859 if (!m_StatusFileList.GetCommonDirectory().IsEmpty())
2860 return m_StatusFileList.GetCommonDirectory().GetWinPath();
2863 CTGitPath commonBaseDirectory;
2864 int nListItems = GetItemCount();
2865 for (int i=0; i<nListItems; ++i)
2867 CTGitPath baseDirectory,*p= (CTGitPath*)this->GetItemData(i);
2868 ASSERT(p);
2869 if(p==NULL)
2870 continue;
2871 baseDirectory = p->GetDirectory();
2873 if(commonBaseDirectory.IsEmpty())
2875 commonBaseDirectory = baseDirectory;
2877 else
2879 if (commonBaseDirectory.GetWinPathString().GetLength() > baseDirectory.GetWinPathString().GetLength())
2881 if (baseDirectory.IsAncestorOf(commonBaseDirectory))
2882 commonBaseDirectory = baseDirectory;
2886 return g_Git.m_CurrentDir+CString(_T("\\"))+commonBaseDirectory.GetWinPath();
2890 void CGitStatusListCtrl::SelectAll(bool bSelect, bool /*bIncludeNoCommits*/)
2892 CWaitCursor waitCursor;
2893 // block here so the LVN_ITEMCHANGED messages
2894 // get ignored
2895 m_bBlock = TRUE;
2896 SetRedraw(FALSE);
2898 int nListItems = GetItemCount();
2899 if (bSelect)
2900 m_nSelected = nListItems;
2901 else
2902 m_nSelected = 0;
2904 for (int i=0; i<nListItems; ++i)
2906 //FileEntry * entry = GetListEntry(i);
2907 //ASSERT(entry != NULL);
2908 CTGitPath *path = (CTGitPath *) GetItemData(i);
2909 if (path == NULL)
2910 continue;
2911 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
2912 SetEntryCheck(path,i,bSelect);
2915 // unblock before redrawing
2916 m_bBlock = FALSE;
2917 SetRedraw(TRUE);
2918 GetStatisticsString();
2919 NotifyCheck();
2922 void CGitStatusListCtrl::Check(DWORD dwCheck, bool uncheckNonMatches)
2924 CWaitCursor waitCursor;
2925 // block here so the LVN_ITEMCHANGED messages
2926 // get ignored
2927 m_bBlock = TRUE;
2928 SetRedraw(FALSE);
2930 int nListItems = GetItemCount();
2931 m_nSelected = 0;
2933 for (int i = 0; i < nListItems; ++i)
2935 CTGitPath *entry = (CTGitPath *) GetItemData(i);
2936 if (entry == NULL)
2937 continue;
2939 DWORD showFlags = entry->m_Action;
2940 if (entry->IsDirectory())
2941 showFlags |= GITSLC_SHOWSUBMODULES;
2942 else
2943 showFlags |= GITSLC_SHOWFILES;
2945 if (showFlags & dwCheck && !(entry->IsDirectory() && m_bDoNotAutoselectSubmodules && !(dwCheck & GITSLC_SHOWSUBMODULES)))
2947 SetEntryCheck(entry, i, true);
2948 m_nSelected++;
2950 else if (uncheckNonMatches)
2951 SetEntryCheck(entry, i, false);
2953 // unblock before redrawing
2954 m_bBlock = FALSE;
2955 SetRedraw(TRUE);
2956 GetStatisticsString();
2957 NotifyCheck();
2960 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)
2962 LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);
2963 *pResult = 0;
2964 if (m_bBlock)
2965 return;
2967 CTGitPath *entry=(CTGitPath *)GetItemData(pGetInfoTip->iItem);
2969 if (entry)
2970 if (pGetInfoTip->cchTextMax > entry->GetGitPathString().GetLength() + g_Git.m_CurrentDir.GetLength())
2972 CString str;
2973 str += g_Git.m_CurrentDir;
2974 str += _T("\\");
2975 str += entry->GetWinPathString();
2977 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, str.GetBuffer(), str.GetLength());
2981 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
2983 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
2985 // Take the default processing unless we set this to something else below.
2986 *pResult = CDRF_DODEFAULT;
2988 // First thing - check the draw stage. If it's the control's prepaint
2989 // stage, then tell Windows we want messages for every item.
2991 switch (pLVCD->nmcd.dwDrawStage)
2993 case CDDS_PREPAINT:
2994 *pResult = CDRF_NOTIFYITEMDRAW;
2995 break;
2996 case CDDS_ITEMPREPAINT:
2998 // This is the prepaint stage for an item. Here's where we set the
2999 // item's text color. Our return value will tell Windows to draw the
3000 // item itself, but it will use the new color we set here.
3002 // Tell Windows to paint the control itself.
3003 *pResult = CDRF_DODEFAULT;
3004 if (m_bBlock)
3005 return;
3007 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
3009 if (m_arStatusArray.size() > (DWORD_PTR)pLVCD->nmcd.dwItemSpec)
3012 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3013 CTGitPath *entry=(CTGitPath *)GetItemData((int)pLVCD->nmcd.dwItemSpec);
3014 if (entry == NULL)
3015 return;
3017 // coloring
3018 // ========
3019 // black : unversioned, normal
3020 // purple : added
3021 // blue : modified
3022 // brown : missing, deleted, replaced
3023 // green : merged (or potential merges)
3024 // red : conflicts or sure conflicts
3025 if(entry->m_Action & CTGitPath::LOGACTIONS_GRAY)
3027 crText = RGB(128,128,128);
3030 else if(entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
3032 crText = m_Colors.GetColor(CColors::Conflict);
3035 else if(entry->m_Action & (CTGitPath::LOGACTIONS_MODIFIED))
3037 crText = m_Colors.GetColor(CColors::Modified);
3040 else if(entry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
3042 crText = m_Colors.GetColor(CColors::Added);
3044 else if(entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
3046 crText = m_Colors.GetColor(CColors::DeletedNode);
3048 else if(entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
3050 crText = m_Colors.GetColor(CColors::RenamedNode);
3052 else if(entry->m_Action & CTGitPath::LOGACTIONS_MERGED)
3054 crText = m_Colors.GetColor(CColors::Merged);
3056 else
3058 crText = GetSysColor(COLOR_WINDOWTEXT);
3060 // Store the color back in the NMLVCUSTOMDRAW struct.
3061 pLVCD->clrText = crText;
3064 break;
3068 BOOL CGitStatusListCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
3070 if (pWnd != this)
3071 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
3072 if (!m_bBlock)
3074 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
3075 SetCursor(hCur);
3076 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
3078 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
3079 SetCursor(hCur);
3080 return TRUE;
3083 void CGitStatusListCtrl::RemoveListEntry(int index)
3086 Locker lock(m_critSec);
3087 DeleteItem(index);
3089 m_arStatusArray.erase(m_arStatusArray.begin()+index);
3091 #if 0
3092 delete m_arStatusArray[m_arListArray[index]];
3093 m_arStatusArray.erase(m_arStatusArray.begin()+m_arListArray[index]);
3094 m_arListArray.erase(m_arListArray.begin()+index);
3095 for (int i=index; i< (int)m_arListArray.size(); ++i)
3097 m_arListArray[i]--;
3099 #endif
3102 ///< Set a checkbox on an entry in the listbox
3103 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
3104 void CGitStatusListCtrl::SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck)
3106 pEntry->m_Checked = bCheck;
3107 m_mapFilenameToChecked[pEntry->GetGitPathString()] = bCheck;
3108 SetCheck(listboxIndex, bCheck);
3111 #if 0
3112 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck)
3115 int nListItems = GetItemCount();
3116 for (int j=0; j< nListItems ; ++j)
3118 FileEntry * childEntry = GetListEntry(j);
3119 ASSERT(childEntry != NULL);
3120 if (childEntry == NULL || childEntry == parentEntry)
3121 continue;
3122 if (childEntry->checked != bCheck)
3124 if (parentEntry->path.IsAncestorOf(childEntry->path))
3126 SetEntryCheck(childEntry,j,bCheck);
3127 if(bCheck)
3129 m_nSelected++;
3131 else
3133 m_nSelected--;
3140 #endif
3142 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList& pathList)
3145 pathList.Clear();
3146 int nListItems = GetItemCount();
3147 for (int i=0; i< nListItems; i++)
3149 CTGitPath * entry = (CTGitPath*)GetItemData(i);
3150 ASSERT(entry != NULL);
3151 if (entry->m_Checked)
3153 pathList.AddPath(*entry);
3156 pathList.SortByPathname();
3161 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
3162 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList& pathList, bool /*bNoIgnored*/)
3164 pathList.Clear();
3166 POSITION pos = GetFirstSelectedItemPosition();
3167 int index;
3168 while ((index = GetNextSelectedItem(pos)) >= 0)
3170 CTGitPath * entry = (CTGitPath*)GetItemData(index);
3171 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
3172 // continue;
3173 pathList.AddPath(*entry);
3177 UINT CGitStatusListCtrl::OnGetDlgCode()
3179 // we want to process the return key and not have that one
3180 // routed to the default pushbutton
3181 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS;
3184 void CGitStatusListCtrl::OnNMReturn(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3186 *pResult = 0;
3187 if (m_bBlock)
3188 return;
3189 POSITION pos = GetFirstSelectedItemPosition();
3190 while ( pos )
3192 int index = GetNextSelectedItem(pos);
3193 CTGitPath *file=(CTGitPath*)GetItemData(index);
3194 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER)
3196 OpenFile(file, OPEN);
3198 else
3200 StartDiff(index);
3205 void CGitStatusListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
3207 // Since we catch all keystrokes (to have the enter key processed here instead
3208 // of routed to the default pushbutton) we have to make sure that other
3209 // keys like Tab and Esc still do what they're supposed to do
3210 // Tab = change focus to next/previous control
3211 // Esc = quit the dialog
3212 switch (nChar)
3214 case (VK_TAB):
3216 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL, GetKeyState(VK_SHIFT)&0x8000, 0);
3217 return;
3219 break;
3220 case (VK_ESCAPE):
3222 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE, 0, 0);
3224 break;
3227 CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
3230 void CGitStatusListCtrl::PreSubclassWindow()
3232 CListCtrl::PreSubclassWindow();
3233 EnableToolTips(TRUE);
3234 SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);
3237 INT_PTR CGitStatusListCtrl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
3239 int row, col;
3240 RECT cellrect;
3241 row = CellRectFromPoint(point, &cellrect, &col );
3243 if (row == -1)
3244 return -1;
3247 pTI->hwnd = m_hWnd;
3248 pTI->uId = (UINT)((row<<10)+(col&0x3ff)+1);
3249 pTI->lpszText = LPSTR_TEXTCALLBACK;
3251 pTI->rect = cellrect;
3253 return pTI->uId;
3256 int CGitStatusListCtrl::CellRectFromPoint(CPoint& point, RECT *cellrect, int *col) const
3258 int colnum;
3260 // Make sure that the ListView is in LVS_REPORT
3261 if ((GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
3262 return -1;
3264 // Get the top and bottom row visible
3265 int row = GetTopIndex();
3266 int bottom = row + GetCountPerPage();
3267 if (bottom > GetItemCount())
3268 bottom = GetItemCount();
3270 // Get the number of columns
3271 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
3272 int nColumnCount = pHeader->GetItemCount();
3274 // Loop through the visible rows
3275 for ( ;row <=bottom;row++)
3277 // Get bounding rect of item and check whether point falls in it.
3278 CRect rect;
3279 GetItemRect(row, &rect, LVIR_BOUNDS);
3280 if (rect.PtInRect(point))
3282 // Now find the column
3283 for (colnum = 0; colnum < nColumnCount; colnum++)
3285 int colwidth = GetColumnWidth(colnum);
3286 if (point.x >= rect.left && point.x <= (rect.left + colwidth))
3288 RECT rectClient;
3289 GetClientRect(&rectClient);
3290 if (col)
3291 *col = colnum;
3292 rect.right = rect.left + colwidth;
3294 // Make sure that the right extent does not exceed
3295 // the client area
3296 if (rect.right > rectClient.right)
3297 rect.right = rectClient.right;
3298 *cellrect = rect;
3299 return row;
3301 rect.left += colwidth;
3305 return -1;
3308 void CGitStatusListCtrl::OnPaint()
3310 Default();
3311 if ((m_bBusy)||(m_bEmpty))
3313 CString str;
3314 if (m_bBusy)
3316 if (m_sBusy.IsEmpty())
3317 str.LoadString(IDS_STATUSLIST_BUSYMSG);
3318 else
3319 str = m_sBusy;
3321 else
3323 if (m_sEmpty.IsEmpty())
3324 str.LoadString(IDS_STATUSLIST_EMPTYMSG);
3325 else
3326 str = m_sEmpty;
3328 COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
3329 COLORREF clrTextBk;
3330 if (IsWindowEnabled())
3331 clrTextBk = ::GetSysColor(COLOR_WINDOW);
3332 else
3333 clrTextBk = ::GetSysColor(COLOR_3DFACE);
3335 CRect rc;
3336 GetClientRect(&rc);
3337 CHeaderCtrl* pHC;
3338 pHC = GetHeaderCtrl();
3339 if (pHC != NULL)
3341 CRect rcH;
3342 pHC->GetItemRect(0, &rcH);
3343 rc.top += rcH.bottom;
3345 CDC* pDC = GetDC();
3347 CMyMemDC memDC(pDC, &rc);
3349 memDC.SetTextColor(clrText);
3350 memDC.SetBkColor(clrTextBk);
3351 memDC.FillSolidRect(rc, clrTextBk);
3352 rc.top += 10;
3353 CGdiObject * oldfont = memDC.SelectStockObject(DEFAULT_GUI_FONT);
3354 memDC.DrawText(str, rc, DT_CENTER | DT_VCENTER |
3355 DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
3356 memDC.SelectObject(oldfont);
3358 ReleaseDC(pDC);
3362 // prevent users from extending our hidden (size 0) columns
3363 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3365 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3368 // prevent any function from extending our hidden (size 0) columns
3369 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3371 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3372 Default();
3375 void CGitStatusListCtrl::OnDestroy()
3377 SaveColumnWidths(true);
3378 CListCtrl::OnDestroy();
3381 void CGitStatusListCtrl::OnBeginDrag(NMHDR* /*pNMHDR*/, LRESULT* pResult)
3383 #if 0
3384 Locker lock(m_critSec);
3385 CDropFiles dropFiles; // class for creating DROPFILES struct
3387 int index;
3388 POSITION pos = GetFirstSelectedItemPosition();
3389 while ( (index = GetNextSelectedItem(pos)) >= 0 )
3391 FileEntry * fentry = m_arStatusArray[m_arListArray[index]];
3392 CTGitPath path = fentry->GetPath();
3393 dropFiles.AddFile( path.GetWinPathString() );
3396 if ( dropFiles.GetCount()>0 )
3398 m_bOwnDrag = true;
3399 dropFiles.CreateStructure();
3400 m_bOwnDrag = false;
3402 #endif
3403 *pResult = 0;
3406 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry /* = false */)
3408 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
3409 for (int col = 0; col <= maxcol; col++)
3410 if (m_ColumnManager.IsVisible (col))
3411 m_ColumnManager.ColumnResized (col);
3413 if (bSaveToRegistry)
3414 m_ColumnManager.WriteSettings();
3417 bool CGitStatusListCtrl::EnableFileDrop()
3419 m_bFileDropsEnabled = true;
3420 return true;
3423 bool CGitStatusListCtrl::HasPath(const CTGitPath& path)
3425 for (size_t i=0; i < m_arStatusArray.size(); i++)
3427 if (m_arStatusArray[i]->IsEquivalentTo(path))
3428 return true;
3431 return false;
3434 BOOL CGitStatusListCtrl::PreTranslateMessage(MSG* pMsg)
3436 if (pMsg->message == WM_KEYDOWN)
3438 switch (pMsg->wParam)
3440 case 'A':
3442 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
3444 // select all entries
3445 for (int i=0; i<GetItemCount(); ++i)
3447 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3449 return TRUE;
3452 break;
3453 case 'C':
3454 case VK_INSERT:
3456 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
3458 // copy all selected paths to the clipboard
3459 if (GetAsyncKeyState(VK_SHIFT)&0x8000)
3460 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS);
3461 else
3462 CopySelectedEntriesToClipboard(0);
3463 return TRUE;
3466 break;
3470 return CListCtrl::PreTranslateMessage(pMsg);
3473 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols)
3476 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
3477 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3479 CString sClipboard;
3480 CString temp;
3481 //TCHAR buf[100];
3482 if (GetSelectedCount() == 0)
3483 return false;
3485 // first add the column titles as the first line
3486 // We needn't head when only path copy
3487 //temp.LoadString(IDS_STATUSLIST_COLFILE);
3488 //sClipboard = temp;
3490 DWORD selection = 0;
3491 for (int i = 0, count = m_ColumnManager.GetColumnCount(); i < count; ++i)
3492 if ( ((dwCols == -1) && m_ColumnManager.IsVisible (i))
3493 || ((dwCols != 1) && (i < 32) && ((dwCols & (1 << i)) != 0)))
3495 sClipboard += _T("\t") + m_ColumnManager.GetName(i);
3497 if (i < 32)
3498 selection += 1 << i;
3501 if(dwCols)
3502 sClipboard += _T("\r\n");
3504 POSITION pos = GetFirstSelectedItemPosition();
3505 int index;
3506 while ((index = GetNextSelectedItem(pos)) >= 0)
3508 CTGitPath * entry = (CTGitPath*)GetItemData(index);
3509 if(entry == NULL)
3510 continue;
3512 sClipboard += entry->GetWinPathString();
3513 if (selection & GITSLC_COLFILENAME)
3515 sClipboard += _T("\t")+entry->GetFileOrDirectoryName();
3517 if (selection & GITSLC_COLEXT)
3519 sClipboard += _T("\t")+entry->GetFileExtension();
3522 if (selection & GITSLC_COLSTATUS)
3524 sClipboard += _T("\t")+entry->GetActionName();
3526 #if 0
3527 if (selection & SVNSLC_COLDATE)
3529 TCHAR datebuf[SVN_DATE_BUFFER];
3530 apr_time_t date = entry->last_commit_date;
3531 SVN::formatDate(datebuf, date, true);
3532 if (date)
3533 temp = datebuf;
3534 else
3535 temp.Empty();
3536 sClipboard += _T("\t")+temp;
3538 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
3539 ; i < count
3540 ; ++i)
3542 if ((dwCols == -1) && m_ColumnManager.IsVisible (i))
3544 CString value
3545 = entry->present_props[m_ColumnManager.GetName(i)];
3546 sClipboard += _T("\t") + value;
3549 #endif
3550 if (selection & GITSLC_COLADD)
3552 sClipboard += _T("\t")+entry->m_StatAdd;
3554 if (selection & GITSLC_COLDEL)
3556 sClipboard += _T("\t")+entry->m_StatDel;
3559 sClipboard += _T("\r\n");
3562 return CStringUtils::WriteAsciiStringToClipboard(sClipboard);
3564 return TRUE;
3568 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
3570 #if 0
3571 std::set<CString> changelists;
3572 POSITION pos = GetFirstSelectedItemPosition();
3573 int index;
3574 while ((index = GetNextSelectedItem(pos)) >= 0)
3576 FileEntry * entry = GetListEntry(index);
3577 if (!entry->changelist.IsEmpty())
3578 changelists.insert(entry->changelist);
3580 return changelists.size();
3581 #endif
3582 return 0;
3585 bool CGitStatusListCtrl::PrepareGroups(bool bForce /* = false */)
3588 bool bHasGroups=false;
3589 int max =0;
3591 for(int i=0;i< this->m_arStatusArray.size(); i++)
3593 int ParentNo = m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
3594 if( ParentNo > max)
3595 max=m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
3598 if ( this->m_UnRevFileList.GetCount()>0 ||
3599 this->m_IgnoreFileList.GetCount()>0 ||
3600 max>0 || bForce)
3602 bHasGroups = true;
3605 RemoveAllGroups();
3606 EnableGroupView(bHasGroups);
3608 TCHAR groupname[1024];
3609 int groupindex = 0;
3611 if(bHasGroups)
3613 LVGROUP grp = {0};
3614 grp.cbSize = sizeof(LVGROUP);
3615 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3616 groupindex=0;
3618 //if(m_UnRevFileList.GetCount()>0)
3619 if(max >0)
3621 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MERGEDFILES)), 1023);
3622 grp.pszHeader = groupname;
3623 grp.iGroupId = MERGE_MASK;
3624 grp.uAlign = LVGA_HEADER_LEFT;
3625 InsertGroup(0, &grp);
3627 for(int i=0;i<=max;i++)
3629 CString str;
3630 str.Format(IDS_STATUSLIST_GROUP_DIFFWITHPARENT, i+1);
3631 grp.pszHeader = str.GetBuffer();
3632 str.ReleaseBuffer();
3633 grp.iGroupId = i;
3634 grp.uAlign = LVGA_HEADER_LEFT;
3635 InsertGroup(i+1, &grp);
3638 else
3640 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MODIFIEDFILES)), 1023);
3641 grp.pszHeader = groupname;
3642 grp.iGroupId = groupindex;
3643 grp.uAlign = LVGA_HEADER_LEFT;
3644 InsertGroup(groupindex++, &grp);
3648 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_NOTVERSIONEDFILES)), 1023);
3649 grp.pszHeader = groupname;
3650 grp.iGroupId = groupindex;
3651 grp.uAlign = LVGA_HEADER_LEFT;
3652 InsertGroup(groupindex++, &grp);
3655 //if(m_IgnoreFileList.GetCount()>0)
3657 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNOREDFILES)), 1023);
3658 grp.pszHeader = groupname;
3659 grp.iGroupId = groupindex;
3660 grp.uAlign = LVGA_HEADER_LEFT;
3661 InsertGroup(groupindex++, &grp);
3666 #if 0
3667 m_bHasIgnoreGroup = false;
3669 // now add the items which don't belong to a group
3670 LVGROUP grp = {0};
3671 grp.cbSize = sizeof(LVGROUP);
3672 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3673 CString sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET));
3674 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
3675 grp.pszHeader = groupname;
3676 grp.iGroupId = groupindex;
3677 grp.uAlign = LVGA_HEADER_LEFT;
3678 InsertGroup(groupindex++, &grp);
3680 for (std::map<CString,int>::iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
3682 if (it->first.Compare(SVNSLC_IGNORECHANGELIST)!=0)
3684 LVGROUP grp = {0};
3685 grp.cbSize = sizeof(LVGROUP);
3686 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3687 _tcsncpy_s(groupname, 1024, it->first, 1023);
3688 grp.pszHeader = groupname;
3689 grp.iGroupId = groupindex;
3690 grp.uAlign = LVGA_HEADER_LEFT;
3691 it->second = InsertGroup(groupindex++, &grp);
3693 else
3694 m_bHasIgnoreGroup = true;
3697 if (m_bHasIgnoreGroup)
3699 // and now add the group 'ignore-on-commit'
3700 std::map<CString,int>::iterator it = m_changelists.find(SVNSLC_IGNORECHANGELIST);
3701 if (it != m_changelists.end())
3703 grp.cbSize = sizeof(LVGROUP);
3704 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3705 _tcsncpy_s(groupname, 1024, SVNSLC_IGNORECHANGELIST, 1023);
3706 grp.pszHeader = groupname;
3707 grp.iGroupId = groupindex;
3708 grp.uAlign = LVGA_HEADER_LEFT;
3709 it->second = InsertGroup(groupindex, &grp);
3712 #endif
3713 return bHasGroups;
3716 void CGitStatusListCtrl::NotifyCheck()
3718 CWnd* pParent = GetParent();
3719 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3721 pParent->SendMessage(GITSLNM_CHECKCHANGED, m_nSelected);
3725 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash,CTGitPathList *list)
3727 BYTE_VECTOR out;
3728 this->m_bBusy=TRUE;
3729 m_CurrentVersion=hash;
3731 int count = 0;
3732 if(list == NULL)
3733 count = 1;
3734 else
3735 count = list->GetCount();
3737 CString head = _T("HEAD");
3738 if(m_amend)
3739 head = _T("HEAD~1");
3741 if(hash == GIT_REV_ZERO)
3743 for(int i=0;i<count;i++)
3745 BYTE_VECTOR cmdout;
3746 cmdout.clear();
3747 CString cmd;
3748 if(!g_Git.IsInitRepos())
3750 // also list staged files which will be in the commit
3751 cmd=(_T("git.exe diff-index --cached --raw ") + head + _T(" --numstat -C -M -z"));
3752 g_Git.Run(cmd, &cmdout);
3754 if(list == NULL)
3755 cmd=(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z"));
3756 else
3757 cmd.Format(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
3759 BYTE_VECTOR cmdErr;
3760 if(g_Git.Run(cmd, &cmdout, &cmdErr))
3762 int last = cmdErr.RevertFind(0,-1);
3763 CString str;
3764 g_Git.StringAppend(&str, &cmdErr[last + 1], CP_UTF8, cmdErr.size() - last -1);
3765 CMessageBox::Show(NULL, str, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
3768 out.append(cmdout, 0);
3770 else // Init Repository
3772 //We will list all added file for init repository because commit will comit these
3773 //if(list == NULL)
3774 cmd=_T("git.exe ls-files -s -t -z");
3775 //else
3776 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
3778 g_Git.Run(cmd, &cmdout);
3779 //out+=cmdout;
3780 out.append(cmdout,0);
3784 if(g_Git.IsInitRepos())
3786 m_StatusFileList.ParserFromLsFile(out);
3787 for(int i=0;i<m_StatusFileList.GetCount();i++)
3788 ((CTGitPath&)(m_StatusFileList[i])).m_Action=CTGitPath::LOGACTIONS_ADDED;
3790 else
3791 this->m_StatusFileList.ParserFromLog(out);
3793 //handle delete conflict case, when remote : modified, local : deleted.
3794 for(int i=0;i<count;i++)
3796 BYTE_VECTOR cmdout;
3797 CString cmd;
3799 if(list == NULL)
3800 cmd=_T("git.exe ls-files -u -t -z");
3801 else
3802 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list)[i].GetGitPathString());
3804 g_Git.Run(cmd, &cmdout);
3806 CTGitPathList conflictlist;
3807 conflictlist.ParserFromLog(cmdout);
3808 for(int i=0;i<conflictlist.GetCount();i++)
3810 CTGitPath *p=m_StatusFileList.LookForGitPath(conflictlist[i].GetGitPathString());
3811 if(p)
3812 p->m_Action|=CTGitPath::LOGACTIONS_UNMERGED;
3813 else
3814 m_StatusFileList.AddPath(conflictlist[i]);
3818 // handle source files of file renames/moves (issue #860)
3819 // if a file gets renamed and the new file "git add"ed, diff-index doesn't list the source file anymore
3820 for(int i = 0; i < count; i++)
3822 BYTE_VECTOR cmdout;
3823 CString cmd;
3825 if(list == NULL)
3826 cmd = _T("git.exe ls-files -d -z");
3827 else
3828 cmd.Format(_T("git.exe ls-files -d -z -- \"%s\""),(*list)[i].GetGitPathString());
3830 g_Git.Run(cmd, &cmdout);
3832 CTGitPathList deletelist;
3833 deletelist.ParserFromLog(cmdout, true);
3834 for(int i = 0; i < deletelist.GetCount(); i++)
3836 CTGitPath *p = m_StatusFileList.LookForGitPath(deletelist[i].GetGitPathString());
3837 if(!p)
3838 m_StatusFileList.AddPath(deletelist[i]);
3839 else if ((p->m_Action == CTGitPath::LOGACTIONS_ADDED || p->m_Action == CTGitPath::LOGACTIONS_REPLACED) && !p->Exists())
3841 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)
3843 g_Git.Run(_T("git.exe rm -f --cache -- \"") + p->GetWinPathString() + _T("\""), &cmdout);
3844 m_StatusFileList.RemoveItem(*p);
3850 else
3852 int count = 0;
3853 if(list == NULL)
3854 count = 1;
3855 else
3856 count = list->GetCount();
3858 for(int i=0;i<count;i++)
3860 BYTE_VECTOR cmdout;
3861 CString cmd;
3862 if(list == NULL)
3863 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash);
3864 else
3865 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash,(*list)[i].GetGitPathString());
3867 g_Git.Run(cmd, &cmdout, NULL);
3869 out.append(cmdout);
3871 this->m_StatusFileList.ParserFromLog(out);
3875 for(int i=0;i<m_StatusFileList.GetCount();i++)
3877 CTGitPath * gitpatch=(CTGitPath*)&m_StatusFileList[i];
3878 gitpatch->m_Checked = TRUE;
3879 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
3882 this->m_bBusy=FALSE;
3883 return 0;
3886 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList &list)
3888 m_arStatusArray.clear();
3889 for(int i=0;i<list.GetCount();i++)
3891 CTGitPath * gitpath=(CTGitPath*)&list[i];
3893 if(gitpath ->m_Action & CTGitPath::LOGACTIONS_HIDE)
3894 continue;
3896 gitpath->m_Checked = TRUE;
3897 m_arStatusArray.push_back((CTGitPath*)&list[i]);
3899 return 0;
3902 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList *List)
3904 this->m_UnRevFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER,List);
3905 for(int i=0;i<m_UnRevFileList.GetCount();i++)
3907 CTGitPath * gitpatch=(CTGitPath*)&m_UnRevFileList[i];
3908 gitpatch->m_Checked = FALSE;
3909 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
3911 return 0;
3914 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList *List)
3916 this->m_IgnoreFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER|CTGitPath::LOGACTIONS_IGNORE,List);
3917 for(int i=0;i<m_IgnoreFileList.GetCount();i++)
3919 CTGitPath * gitpatch=(CTGitPath*)&m_IgnoreFileList[i];
3920 gitpatch->m_Checked = FALSE;
3921 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
3923 return 0;
3925 int CGitStatusListCtrl::UpdateFileList(int mask,bool once,CTGitPathList *List)
3927 if(mask&CGitStatusListCtrl::FILELIST_MODIFY)
3929 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_MODIFY)))
3931 UpdateFileList(git_revnum_t(GIT_REV_ZERO),List);
3932 m_FileLoaded|=CGitStatusListCtrl::FILELIST_MODIFY;
3935 if(mask&CGitStatusListCtrl::FILELIST_UNVER)
3937 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_UNVER)))
3939 UpdateUnRevFileList(List);
3940 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
3942 if(mask&CGitStatusListCtrl::FILELIST_IGNORE && (once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_IGNORE))))
3944 UpdateIgnoreFileList(List);
3945 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
3948 return 0;
3951 void CGitStatusListCtrl::Clear()
3953 m_FileLoaded=0;
3954 this->DeleteAllItems();
3955 this->m_arListArray.clear();
3956 this->m_arStatusArray.clear();
3957 this->m_changelists.clear();
3959 //////////////////////////////////////////////////////////////////////////
3960 #if 0
3961 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD * /*pdwEffect*/, POINTL pt)
3963 if(pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
3965 HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
3966 if(hDrop != NULL)
3968 TCHAR szFileName[MAX_PATH];
3970 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
3972 POINT clientpoint;
3973 clientpoint.x = pt.x;
3974 clientpoint.y = pt.y;
3975 ScreenToClient(m_hTargetWnd, &clientpoint);
3976 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
3978 CTSVNPathList changelistItems;
3979 for(UINT i = 0; i < cFiles; ++i)
3981 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
3982 changelistItems.AddPath(CTSVNPath(szFileName));
3984 // find the changelist name
3985 CString sChangelist;
3986 LONG_PTR nGroup = m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint);
3987 for (std::map<CString, int>::iterator it = m_pSVNStatusListCtrl->m_changelists.begin(); it != m_pSVNStatusListCtrl->m_changelists.end(); ++it)
3988 if (it->second == nGroup)
3989 sChangelist = it->first;
3990 if (!sChangelist.IsEmpty())
3992 SVN git;
3993 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
3995 for (int l=0; l<changelistItems.GetCount(); ++l)
3997 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
3998 if (index >= 0)
4000 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
4001 if (e)
4003 e->changelist = sChangelist;
4004 if (!e->IsFolder())
4006 if (m_pSVNStatusListCtrl->m_changelists.find(e->changelist)!=m_pSVNStatusListCtrl->m_changelists.end())
4007 m_pSVNStatusListCtrl->SetItemGroup(index, m_pSVNStatusListCtrl->m_changelists[e->changelist]);
4008 else
4009 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
4013 else
4015 HWND hParentWnd = GetParent(m_hTargetWnd);
4016 if (hParentWnd != NULL)
4017 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
4021 else
4023 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
4026 else
4028 SVN git;
4029 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
4031 for (int l=0; l<changelistItems.GetCount(); ++l)
4033 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
4034 if (index >= 0)
4036 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
4037 if (e)
4039 e->changelist = sChangelist;
4040 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
4043 else
4045 HWND hParentWnd = GetParent(m_hTargetWnd);
4046 if (hParentWnd != NULL)
4047 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
4051 else
4053 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
4057 else
4059 for(UINT i = 0; i < cFiles; ++i)
4061 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
4062 HWND hParentWnd = GetParent(m_hTargetWnd);
4063 if (hParentWnd != NULL)
4064 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)szFileName);
4068 GlobalUnlock(medium.hGlobal);
4070 return true; //let base free the medium
4072 HRESULT STDMETHODCALLTYPE CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)
4074 CIDropTarget::DragOver(grfKeyState, pt, pdwEffect);
4075 *pdwEffect = DROPEFFECT_COPY;
4076 if (m_pSVNStatusListCtrl)
4078 POINT clientpoint;
4079 clientpoint.x = pt.x;
4080 clientpoint.y = pt.y;
4081 ScreenToClient(m_hTargetWnd, &clientpoint);
4082 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
4084 *pdwEffect = DROPEFFECT_MOVE;
4086 else if ((!m_pSVNStatusListCtrl->m_bFileDropsEnabled)||(m_pSVNStatusListCtrl->m_bOwnDrag))
4088 *pdwEffect = DROPEFFECT_NONE;
4091 return S_OK;
4094 #endif
4096 void CGitStatusListCtrl::FileSaveAs(CTGitPath *path)
4098 CString filename;
4099 filename.Format(_T("%s-%s%s"), path->GetBaseFilename(), this->m_CurrentVersion.Left(g_Git.GetShortHASHLength()), path->GetFileExtension());
4100 CFileDialog dlg(FALSE,NULL,
4101 filename,
4102 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
4103 NULL);
4104 CString currentpath;
4105 currentpath=g_Git.m_CurrentDir+_T("\\");
4106 currentpath+=path->GetWinPathString();
4108 dlg.m_ofn.lpstrInitialDir=currentpath.GetBuffer();
4110 CString cmd,out;
4111 if(dlg.DoModal()==IDOK)
4113 filename = dlg.GetPathName();
4114 if(m_CurrentVersion == GIT_REV_ZERO)
4116 if(!CopyFile(g_Git.m_CurrentDir +_T("\\") + path->GetWinPath(),filename,false))
4118 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
4119 return;
4123 else
4125 if(g_Git.GetOneFile(m_CurrentVersion,*path,filename))
4127 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path->GetGitPathString(), m_CurrentVersion, filename);
4128 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
4129 return;
4136 int CGitStatusListCtrl::RevertSelectedItemToVersion()
4138 if(this->m_CurrentVersion.IsEmpty())
4139 return 0;
4140 if(this->m_CurrentVersion == GIT_REV_ZERO)
4141 return 0;
4143 POSITION pos = GetFirstSelectedItemPosition();
4144 int index;
4145 CString cmd,out;
4146 int count =0;
4147 while ((index = GetNextSelectedItem(pos)) >= 0)
4149 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
4150 cmd.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion,fentry->GetGitPathString());
4151 out.Empty();
4152 if (g_Git.Run(cmd, &out, CP_UTF8))
4154 if (MessageBox(out, _T("TortoiseGit"), MB_ICONEXCLAMATION | MB_OKCANCEL) == IDCANCEL)
4155 break;
4157 else
4158 count++;
4161 out.Format(IDS_STATUSLIST_FILESREVERTED, count, m_CurrentVersion);
4162 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
4163 return 0;
4166 void CGitStatusListCtrl::OpenFile(CTGitPath*filepath,int mode)
4168 CString file;
4169 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
4171 file= filepath->GetWinPath();
4173 else
4175 CString temppath;
4176 GetTempPath(temppath);
4177 file.Format(_T("%s%s_%s%s"),
4178 temppath,
4179 filepath->GetBaseFilename(),
4180 m_CurrentVersion.Left(g_Git.GetShortHASHLength()),
4181 filepath->GetFileExtension());
4182 CString cmd,out;
4183 if(g_Git.GetOneFile(m_CurrentVersion, *filepath, file))
4185 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, filepath->GetGitPathString(), m_CurrentVersion, file);
4186 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
4187 return;
4191 if(mode == ALTERNATIVEEDITOR)
4193 CAppUtils::LaunchAlternativeEditor(file);
4194 return;
4196 int ret = HINSTANCE_ERROR;
4198 if(mode == OPEN )
4200 ret = (int)ShellExecute(this->m_hWnd, NULL,file, NULL, NULL, SW_SHOW);
4202 if (ret > HINSTANCE_ERROR)
4204 return;
4209 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
4210 cmd += file;
4211 CAppUtils::LaunchApplication(cmd, NULL, false);