Fixed issue #451: rebase (maybe be for any conflicts) select multiple files to mark
[TortoiseGit.git] / src / Git / GitStatusListCtrl.cpp
blobae6aa9ecaf69348775ea4fc8906599c48b84e62a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
5 // Copyright (C) 2010-2011 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 "SVNProperties.h"
36 #include "Git.h"
37 #include "GitDiff.h"
38 //#include "LogDlg.h"
39 //#include "SVNProgressDlg.h"
40 #include "SysImageList.h"
41 //#include "Svnstatuslistctrl.h"
42 #include "TGitPath.h"
43 #include "Registry.h"
44 #include "GitStatus.h"
45 //#include "SVNHelpers.h"
46 #include "InputDlg.h"
47 #include "ShellUpdater.h"
48 #include "GitAdminDir.h"
49 //#include "DropFiles.h"
50 #include "IconMenu.h"
51 //#include "AddDlg.h"
52 //#include "EditPropertiesDlg.h"
53 //#include "CreateChangelistDlg.h"
54 #include "CommonResource.h"
56 const UINT CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
57 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
58 const UINT CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
59 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
60 const UINT CGitStatusListCtrl::GITSLNM_ADDFILE
61 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
62 const UINT CGitStatusListCtrl::GITSLNM_CHECKCHANGED
63 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
64 const UINT CGitStatusListCtrl::GITSLNM_ITEMCHANGED
65 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCHANGED"));
70 BEGIN_MESSAGE_MAP(CGitStatusListCtrl, CListCtrl)
71 ON_NOTIFY(HDN_ITEMCLICKA, 0, OnHdnItemclick)
72 ON_NOTIFY(HDN_ITEMCLICKW, 0, OnHdnItemclick)
73 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
74 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
75 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, OnLvnItemchanged)
76 ON_WM_CONTEXTMENU()
77 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk)
78 ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnLvnGetInfoTip)
79 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
80 ON_WM_SETCURSOR()
81 ON_WM_GETDLGCODE()
82 ON_NOTIFY_REFLECT(NM_RETURN, OnNMReturn)
83 ON_WM_KEYDOWN()
84 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
85 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
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_bUnversionedRecurse(true)
107 , m_bShowIgnores(false)
108 , m_pDropTarget(NULL)
109 , m_bIgnoreRemoveOnly(false)
110 , m_bCheckChildrenWithParent(false)
111 , m_bUnversionedLast(true)
112 , m_bHasChangeLists(false)
113 , m_bHasLocks(false)
114 , m_bBlock(false)
115 , m_bBlockUI(false)
116 , m_bHasCheckboxes(false)
117 , m_bCheckIfGroupsExist(true)
118 , m_bFileDropsEnabled(false)
119 , m_bOwnDrag(false)
120 , m_dwDefaultColumns(0)
121 , m_ColumnManager(this)
122 , m_bAscending(false)
123 , m_nSortedColumn(-1)
124 , m_bHasExternalsFromDifferentRepos(false)
125 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE))
126 , m_amend(false)
127 , m_bDoNotAutoselectSubmodules(false)
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
153 #if 0
154 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(UINT_PTR index)
157 if (index >= (UINT_PTR)m_arListArray.size())
158 return NULL;
159 if (m_arListArray[index] >= m_arStatusArray.size())
160 return NULL;
161 return m_arStatusArray[m_arListArray[index]];
163 return NULL;
165 #endif
166 #if 0
167 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetVisibleListEntry(const CTGitPath& path)
169 int itemCount = GetItemCount();
170 for (int i=0; i < itemCount; i++)
172 FileEntry * entry = GetListEntry(i);
173 if (entry->GetPath().IsEquivalentTo(path))
174 return entry;
176 return NULL;
178 #endif
179 #if 0
180 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(const CTGitPath& path)
183 for (size_t i=0; i < m_arStatusArray.size(); i++)
185 FileEntry * entry = m_arStatusArray[i];
186 if (entry->GetPath().IsEquivalentTo(path))
187 return entry;
190 return NULL;
192 #endif
194 #if 0
195 int CGitStatusListCtrl::GetIndex(const CTGitPath& path)
197 int itemCount = GetItemCount();
198 for (int i=0; i < itemCount; i++)
200 FileEntry * entry = GetListEntry(i);
201 if (entry->GetPath().IsEquivalentTo(path))
202 return i;
204 return -1;
206 #endif
208 void CGitStatusListCtrl::Init(DWORD dwColumns, const CString& sColumnInfoContainer, unsigned __int64 dwContextMenus /* = GitSLC_POPALL */, bool bHasCheckboxes /* = true */)
210 Locker lock(m_critSec);
212 m_dwDefaultColumns = dwColumns | 1;
213 m_dwContextMenus = dwContextMenus;
214 m_bHasCheckboxes = bHasCheckboxes;
216 // set the extended style of the listcontrol
217 // 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.
218 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
219 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
220 if (DWORD(regFullRowSelect))
221 exStyle |= LVS_EX_FULLROWSELECT;
222 exStyle |= (bHasCheckboxes ? LVS_EX_CHECKBOXES : 0);
223 SetRedraw(false);
224 SetExtendedStyle(exStyle);
226 SetWindowTheme(m_hWnd, L"Explorer", NULL);
228 m_nIconFolder = SYS_IMAGE_LIST().GetDirIconIndex();
229 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL);
231 // keep CSorter::operator() in sync!!
232 static UINT standardColumnNames[GITSLC_NUMCOLUMNS]
233 = { IDS_STATUSLIST_COLFILE
234 , IDS_STATUSLIST_COLFILENAME
235 , IDS_STATUSLIST_COLEXT
236 , IDS_STATUSLIST_COLSTATUS
237 , IDS_STATUSLIST_COLADD
238 , IDS_STATUSLIST_COLDEL
241 m_ColumnManager.SetNames(standardColumnNames,GITSLC_NUMCOLUMNS);
242 m_ColumnManager.ReadSettings (m_dwDefaultColumns, 0, sColumnInfoContainer, GITSLC_NUMCOLUMNS);
244 // enable file drops
245 #if 0
246 if (m_pDropTarget == NULL)
248 m_pDropTarget = new CGitStatusListCtrlDropTarget(this);
249 RegisterDragDrop(m_hWnd,m_pDropTarget);
250 // create the supported formats:
251 FORMATETC ftetc={0};
252 ftetc.dwAspect = DVASPECT_CONTENT;
253 ftetc.lindex = -1;
254 ftetc.tymed = TYMED_HGLOBAL;
255 ftetc.cfFormat=CF_HDROP;
256 m_pDropTarget->AddSuportedFormat(ftetc);
258 #endif
260 SetRedraw(true);
262 m_bUnversionedRecurse = !!((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE));
265 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID)
267 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID);
270 BOOL CGitStatusListCtrl::GetStatus ( const CTGitPathList* pathList
271 , bool bUpdate /* = FALSE */
272 , bool bShowIgnores /* = false */
273 , bool bShowUnRev
274 , bool /*bShowUserProps*/ /* = false */)
276 Locker lock(m_critSec);
277 int mask= CGitStatusListCtrl::FILELIST_MODIFY;
278 if(bShowIgnores)
279 mask|= CGitStatusListCtrl::FILELIST_IGNORE;
280 if(bShowUnRev)
281 mask|= CGitStatusListCtrl::FILELIST_UNVER;
282 this->UpdateFileList(mask,bUpdate,(CTGitPathList*)pathList);
285 #if 0
286 int refetchcounter = 0;
287 BOOL bRet = TRUE;
288 Invalidate();
289 // force the cursor to change
290 POINT pt;
291 GetCursorPos(&pt);
292 SetCursorPos(pt.x, pt.y);
294 m_mapFilenameToChecked.clear();
295 //m_StatusUrlList.Clear();
296 bool bHasChangelists = (m_changelists.size()>1 || (m_changelists.size()>0 && !m_bHasIgnoreGroup));
297 m_changelists.clear();
298 for (size_t i=0; i < m_arStatusArray.size(); i++)
300 FileEntry * entry = m_arStatusArray[i];
301 if ( bHasChangelists && entry->checked)
303 // If change lists are present, remember all checked entries
304 CString path = entry->GetPath().GetGitPathString();
305 m_mapFilenameToChecked[path] = true;
307 if ( (entry->status==git_wc_status_unversioned || entry->status==git_wc_status_missing ) && entry->checked )
309 // The user manually selected an unversioned or missing file. We remember
310 // this so that the selection can be restored when refreshing.
311 CString path = entry->GetPath().GetGitPathString();
312 m_mapFilenameToChecked[path] = true;
314 else if ( entry->status > git_wc_status_normal && !entry->checked )
316 // The user manually deselected a versioned file. We remember
317 // this so that the deselection can be restored when refreshing.
318 CString path = entry->GetPath().GetGitPathString();
319 m_mapFilenameToChecked[path] = false;
323 // use a sorted path list to make sure we fetch the status of
324 // parent items first, *then* the child items (if any)
325 CTGitPathList sortedPathList = pathList;
326 sortedPathList.SortByPathname();
329 bRet = TRUE;
330 m_nTargetCount = 0;
331 m_bHasExternalsFromDifferentRepos = FALSE;
332 m_bHasExternals = FALSE;
333 m_bHasUnversionedItems = FALSE;
334 m_bHasLocks = false;
335 m_bHasChangeLists = false;
336 m_bShowIgnores = bShowIgnores;
337 m_nSortedColumn = 0;
338 m_bBlock = TRUE;
339 m_bBusy = true;
340 m_bEmpty = false;
341 Invalidate();
343 // first clear possible status data left from
344 // previous GetStatus() calls
345 ClearStatusArray();
347 m_StatusFileList = sortedPathList;
349 // Since Git_client_status() returns all files, even those in
350 // folders included with Git:externals we need to check if all
351 // files we get here belongs to the same repository.
352 // It is possible to commit changes in an external folder, as long
353 // as the folder belongs to the same repository (but another path),
354 // but it is not possible to commit all files if the externals are
355 // from a different repository.
357 // To check if all files belong to the same repository, we compare the
358 // UUID's - if they're identical then the files belong to the same
359 // repository and can be committed. But if they're different, then
360 // tell the user to commit all changes in the external folders
361 // first and exit.
362 CStringA sUUID; // holds the repo UUID
363 CTGitPathList arExtPaths; // list of Git:external paths
365 GitConfig config;
367 m_sURL.Empty();
369 m_nTargetCount = sortedPathList.GetCount();
371 GitStatus status(m_pbCanceled);
372 if(m_nTargetCount > 1 && sortedPathList.AreAllPathsFilesInOneDirectory())
374 // This is a special case, where we've been given a list of files
375 // all from one folder
376 // We handle them by setting a status filter, then requesting the Git status of
377 // all the files in the directory, filtering for the ones we're interested in
378 status.SetFilter(sortedPathList);
380 // if all selected entries are files, we don't do a recursive status
381 // fetching. But if only one is a directory, we have to recurse.
382 git_depth_t depth = git_depth_files;
383 // We have set a filter. If all selected items were files or we fetch
384 // the status not recursively, then we have to include
385 // ignored items too - the user has selected them
386 bool bShowIgnoresRight = true;
387 for (int fcindex=0; fcindex<sortedPathList.GetCount(); ++fcindex)
389 if (sortedPathList[fcindex].IsDirectory())
391 depth = git_depth_infinity;
392 bShowIgnoresRight = false;
393 break;
396 if(!FetchStatusForSingleTarget(config, status, sortedPathList.GetCommonDirectory(), bUpdate, sUUID, arExtPaths, true, depth, bShowIgnoresRight))
398 bRet = FALSE;
401 else
403 for(int nTarget = 0; nTarget < m_nTargetCount; nTarget++)
405 // check whether the path we want the status for is already fetched due to status-fetching
406 // of a parent path.
407 // this check is only done for file paths, because folder paths could be included already
408 // but not recursively
409 if (sortedPathList[nTarget].IsDirectory() || GetListEntry(sortedPathList[nTarget]) == NULL)
411 if(!FetchStatusForSingleTarget(config, status, sortedPathList[nTarget], bUpdate, sUUID,
412 arExtPaths, false, git_depth_infinity, bShowIgnores))
414 bRet = FALSE;
420 // remove the 'helper' files of conflicted items from the list.
421 // otherwise they would appear as unversioned files.
422 for (INT_PTR cind = 0; cind < m_ConflictFileList.GetCount(); ++cind)
424 for (size_t i=0; i < m_arStatusArray.size(); i++)
426 if (m_arStatusArray[i]->GetPath().IsEquivalentTo(m_ConflictFileList[cind]))
428 delete m_arStatusArray[i];
429 m_arStatusArray.erase(m_arStatusArray.begin()+i);
430 break;
434 refetchcounter++;
435 } while(!BuildStatistics() && (refetchcounter < 2) && (*m_pbCanceled==false));
437 if (bShowUserProps)
438 FetchUserProperties();
440 m_ColumnManager.UpdateUserPropList (m_arStatusArray);
442 m_bBlock = FALSE;
443 m_bBusy = false;
444 GetCursorPos(&pt);
445 SetCursorPos(pt.x, pt.y);
446 return bRet;
447 #endif
448 BuildStatistics();
449 return TRUE;
453 // Fetch all local properties for all elements in the status array
455 void CGitStatusListCtrl::FetchUserProperties()
457 #if 0
458 GitPool globalPool;
460 for (size_t i = 0, count = m_arStatusArray.size(); i < count; ++i)
462 // local / temp pool to hold parameters and props for a single item
464 GitPool localPool ((apr_pool_t*)globalPool);
466 // open working copy for this path
468 const char* path = m_arStatusArray[i]->path.GetGitApiPath (localPool);
470 Git_wc_adm_access_t *adm_access = NULL;
471 Git_error_t * error = Git_wc_adm_probe_open3 ( &adm_access
472 , NULL
473 , path
474 , FALSE // no write lock
475 , 0 // lock just the directory/file itself
476 , NULL
477 , NULL
478 , localPool);
479 if (error == NULL)
481 // get the props and add them to the status info
483 apr_hash_t* props = NULL;
484 Git_error_t * error = Git_wc_prop_list ( &props
485 , path
486 , adm_access
487 , localPool);
488 if (error == NULL)
490 for ( apr_hash_index_t *index
491 = apr_hash_first (localPool, props)
492 ; index != NULL
493 ; index = apr_hash_next (index))
495 // extract next entry from hash
497 const char* key = NULL;
498 ptrdiff_t keyLen;
499 const char** val = NULL;
501 apr_hash_this ( index
502 , reinterpret_cast<const void**>(&key)
503 , &keyLen
504 , reinterpret_cast<void**>(&val));
506 // decode / dispatch it
508 CString name = CUnicodeUtils::GetUnicode (key);
509 CString value = CUnicodeUtils::GetUnicode (*val);
511 // store in property container (truncate it after ~100 chars)
513 m_arStatusArray[i]->present_props[name]
514 = value.Left (GitSLC_MAXUSERPROPLENGTH);
517 error = Git_wc_adm_close2 (adm_access, localPool);
519 Git_error_clear (error);
521 #endif
524 // Get the show-flags bitmap value which corresponds to a particular Git status
525 DWORD CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status)
527 switch (status)
529 case git_wc_status_none:
530 case git_wc_status_unversioned:
531 return GITSLC_SHOWUNVERSIONED;
532 case git_wc_status_ignored:
533 if (!m_bShowIgnores)
534 return GITSLC_SHOWDIRECTS;
535 return GITSLC_SHOWDIRECTS|GITSLC_SHOWIGNORED;
536 case git_wc_status_incomplete:
537 return GITSLC_SHOWINCOMPLETE;
538 case git_wc_status_normal:
539 return GITSLC_SHOWNORMAL;
540 case git_wc_status_external:
541 return GITSLC_SHOWEXTERNAL;
542 case git_wc_status_added:
543 return GITSLC_SHOWADDED;
544 case git_wc_status_missing:
545 return GITSLC_SHOWMISSING;
546 case git_wc_status_deleted:
547 return GITSLC_SHOWREMOVED;
548 case git_wc_status_replaced:
549 return GITSLC_SHOWREPLACED;
550 case git_wc_status_modified:
551 return GITSLC_SHOWMODIFIED;
552 case git_wc_status_merged:
553 return GITSLC_SHOWMERGED;
554 case git_wc_status_conflicted:
555 return GITSLC_SHOWCONFLICTED;
556 case git_wc_status_obstructed:
557 return GITSLC_SHOWOBSTRUCTED;
558 default:
559 // we should NEVER get here!
560 ASSERT(FALSE);
561 break;
563 return 0;
566 void CGitStatusListCtrl::Show(unsigned int dwShow, unsigned int dwCheck /*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList,bool UseStoredCheckStatus)
568 CWinApp * pApp = AfxGetApp();
569 if (pApp)
570 pApp->DoWaitCursor(1);
572 Locker lock(m_critSec);
573 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
575 //SetItemCount(listIndex);
576 SetRedraw(FALSE);
577 DeleteAllItems();
578 m_nSelected = 0;
580 if(UpdateStatusList)
582 m_arStatusArray.clear();
583 for(int i=0;i<this->m_StatusFileList.GetCount();i++)
585 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
588 for(int i=0;i<this->m_UnRevFileList.GetCount();i++)
590 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
593 for(int i=0;i<this->m_IgnoreFileList.GetCount();i++)
595 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
598 PrepareGroups();
599 if (m_nSortedColumn >= 0)
601 CSorter predicate (&m_ColumnManager, m_nSortedColumn, m_bAscending);
602 std::sort(m_arStatusArray.begin(), m_arStatusArray.end(), predicate);
605 int index =0;
606 for(int i=0;i<this->m_arStatusArray.size();i++)
608 //set default checkbox status
609 CTGitPath* entry = ((CTGitPath*)m_arStatusArray[i]);
610 CString path = entry->GetGitPathString();
611 if (m_mapFilenameToChecked.size()!=0 && m_mapFilenameToChecked.find(path) != m_mapFilenameToChecked.end())
613 entry->m_Checked=m_mapFilenameToChecked[path];
615 else if (!UseStoredCheckStatus)
617 bool autoSelectSubmodules = !(entry->IsDirectory() && m_bDoNotAutoselectSubmodules);
618 if(entry->m_Action & dwCheck && autoSelectSubmodules)
619 entry->m_Checked=true;
620 else
621 entry->m_Checked=false;
624 if(entry->m_Action & dwShow)
626 AddEntry(entry,langID,index);
627 index++;
631 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
632 for (int col = 0; col <= maxcol; col++)
633 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
635 SetRedraw(TRUE);
636 GetStatisticsString();
638 CHeaderCtrl * pHeader = GetHeaderCtrl();
639 HDITEM HeaderItem = {0};
640 HeaderItem.mask = HDI_FORMAT;
641 for (int i=0; i<pHeader->GetItemCount(); ++i)
643 pHeader->GetItem(i, &HeaderItem);
644 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
645 pHeader->SetItem(i, &HeaderItem);
647 if (m_nSortedColumn >= 0)
649 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
650 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
651 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
654 #if 0
655 if (nSelectedEntry)
657 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
658 EnsureVisible(nSelectedEntry, false);
660 else
662 // Restore the item at the top of the list.
663 for (int i=0;GetTopIndex() != nTopIndex;i++)
665 if ( !EnsureVisible(nTopIndex+i,false) )
667 break;
671 #endif
672 if (pApp)
673 pApp->DoWaitCursor(-1);
675 Invalidate();
677 m_dwShow = dwShow;
679 this->BuildStatistics();
681 #if 0
683 CWinApp * pApp = AfxGetApp();
684 if (pApp)
685 pApp->DoWaitCursor(1);
687 m_bShowFolders = bShowFolders;
689 int nTopIndex = GetTopIndex();
690 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
691 int nSelectedEntry = 0;
692 if (posSelectedEntry)
693 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
694 SetRedraw(FALSE);
695 DeleteAllItems();
697 PrepareGroups();
699 m_arListArray.clear();
701 m_arListArray.reserve(m_arStatusArray.size());
702 SetItemCount (static_cast<int>(m_arStatusArray.size()));
704 int listIndex = 0;
705 for (size_t i=0; i < m_arStatusArray.size(); ++i)
707 FileEntry * entry = m_arStatusArray[i];
708 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
709 continue;
710 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
711 continue;
712 if (entry->IsFolder() && (!bShowFolders))
713 continue; // don't show folders if they're not wanted.
715 #if 0
716 git_wc_status_kind status = GitStatus::GetMoreImportant(entry->status, entry->remotestatus);
717 DWORD showFlags = GetShowFlagsFromGitStatus(status);
718 if (entry->IsLocked())
719 showFlags |= SVNSLC_SHOWLOCKS;
720 if (entry->switched)
721 showFlags |= SVNSLC_SHOWSWITCHED;
722 if (!entry->changelist.IsEmpty())
723 showFlags |= SVNSLC_SHOWINCHANGELIST;
724 #endif
725 bool bAllowCheck = ((entry->changelist.Compare(GITSLC_IGNORECHANGELIST) != 0)
726 && (m_bCheckIfGroupsExist || (m_changelists.size()==0 || (m_changelists.size()==1 && m_bHasIgnoreGroup))));
728 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
729 #if 0
730 if (status != Git_wc_status_ignored || (entry->direct) || (dwShow & GitSLC_SHOWIGNORED))
732 if ((!entry->IsFolder()) && (status == Git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
734 if (PathFileExists(entry->GetPath().GetWinPath()))
736 m_arListArray.push_back(i);
737 if ((dwCheck & SVNSLC_SHOWREMOVEDANDPRESENT)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
739 if (bAllowCheck)
740 entry->checked = true;
742 AddEntry(entry, langID, listIndex++);
745 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
747 m_arListArray.push_back(i);
748 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
750 if (bAllowCheck)
751 entry->checked = true;
753 AddEntry(entry, langID, listIndex++);
755 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
757 m_arListArray.push_back(i);
758 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
760 if (bAllowCheck)
761 entry->checked = true;
763 AddEntry(entry, langID, listIndex++);
766 #endif
769 SetItemCount(listIndex);
771 m_ColumnManager.UpdateRelevance (m_arStatusArray, m_arListArray);
773 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
774 for (int col = 0; col <= maxcol; col++)
775 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
777 SetRedraw(TRUE);
778 GetStatisticsString();
780 CHeaderCtrl * pHeader = GetHeaderCtrl();
781 HDITEM HeaderItem = {0};
782 HeaderItem.mask = HDI_FORMAT;
783 for (int i=0; i<pHeader->GetItemCount(); ++i)
785 pHeader->GetItem(i, &HeaderItem);
786 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
787 pHeader->SetItem(i, &HeaderItem);
789 if (m_nSortedColumn)
791 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
792 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
793 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
796 if (nSelectedEntry)
798 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
799 EnsureVisible(nSelectedEntry, false);
801 else
803 // Restore the item at the top of the list.
804 for (int i=0;GetTopIndex() != nTopIndex;i++)
806 if ( !EnsureVisible(nTopIndex+i,false) )
808 break;
813 if (pApp)
814 pApp->DoWaitCursor(-1);
816 m_bEmpty = (GetItemCount() == 0);
817 Invalidate();
818 #endif
822 void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList& checkedList, bool /*bShowFolders*/ /* = true */)
824 DeleteAllItems();
825 for(int i=0;i<checkedList.GetCount();i++)
826 this->AddEntry((CTGitPath *)&checkedList[i],0,i);
827 return ;
828 #if 0
830 Locker lock(m_critSec);
831 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
833 CWinApp * pApp = AfxGetApp();
834 if (pApp)
835 pApp->DoWaitCursor(1);
836 m_dwShow = dwShow;
837 m_bShowFolders = bShowFolders;
838 m_nSelected = 0;
839 int nTopIndex = GetTopIndex();
840 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
841 int nSelectedEntry = 0;
842 if (posSelectedEntry)
843 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
844 SetRedraw(FALSE);
845 DeleteAllItems();
847 PrepareGroups();
849 m_arListArray.clear();
851 m_arListArray.reserve(m_arStatusArray.size());
852 SetItemCount (static_cast<int>(m_arStatusArray.size()));
854 int listIndex = 0;
855 for (size_t i=0; i < m_arStatusArray.size(); ++i)
857 FileEntry * entry = m_arStatusArray[i];
858 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
859 continue;
860 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
861 continue;
862 if (entry->IsFolder() && (!bShowFolders))
863 continue; // don't show folders if they're not wanted.
864 #if 0
865 git_wc_status_kind status = SVNStatus::GetMoreImportant(entry->status, entry->remotestatus);
866 DWORD showFlags = GetShowFlagsFromSVNStatus(status);
867 if (entry->IsLocked())
868 showFlags |= SVNSLC_SHOWLOCKS;
869 if (!entry->changelist.IsEmpty())
870 showFlags |= SVNSLC_SHOWINCHANGELIST;
872 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
873 if (status != git_wc_status_ignored || (entry->direct) || (dwShow & SVNSLC_SHOWIGNORED))
875 for (int npath = 0; npath < checkedList.GetCount(); ++npath)
877 if (entry->GetPath().IsEquivalentTo(checkedList[npath]))
879 entry->checked = true;
880 break;
883 if ((!entry->IsFolder()) && (status == git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
885 if (PathFileExists(entry->GetPath().GetWinPath()))
887 m_arListArray.push_back(i);
888 AddEntry(entry, langID, listIndex++);
891 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
893 m_arListArray.push_back(i);
894 AddEntry(entry, langID, listIndex++);
896 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
898 m_arListArray.push_back(i);
899 AddEntry(entry, langID, listIndex++);
901 else if (entry->switched)
903 m_arListArray.push_back(i);
904 AddEntry(entry, langID, listIndex++);
907 #endif
910 SetItemCount(listIndex);
912 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
913 for (int col = 0; col <= maxcol; col++)
914 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
916 SetRedraw(TRUE);
917 GetStatisticsString();
919 CHeaderCtrl * pHeader = GetHeaderCtrl();
920 HDITEM HeaderItem = {0};
921 HeaderItem.mask = HDI_FORMAT;
922 for (int i=0; i<pHeader->GetItemCount(); ++i)
924 pHeader->GetItem(i, &HeaderItem);
925 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
926 pHeader->SetItem(i, &HeaderItem);
928 if (m_nSortedColumn)
930 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
931 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
932 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
935 if (nSelectedEntry)
937 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
938 EnsureVisible(nSelectedEntry, false);
940 else
942 // Restore the item at the top of the list.
943 for (int i=0;GetTopIndex() != nTopIndex;i++)
945 if ( !EnsureVisible(nTopIndex+i,false) )
947 break;
952 if (pApp)
953 pApp->DoWaitCursor(-1);
955 m_bEmpty = (GetItemCount() == 0);
956 Invalidate();
957 #endif
960 int CGitStatusListCtrl::GetColumnIndex(int mask)
962 int i=0;
963 for(i=0;i<32;i++)
964 if(mask&0x1)
965 return i;
966 else
967 mask=mask>>1;
968 return -1;
970 void CGitStatusListCtrl::AddEntry(CTGitPath * GitPath, WORD /*langID*/, int listIndex)
972 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
973 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
975 CString path = GitPath->GetGitPathString();
977 m_bBlock = TRUE;
978 int index = listIndex;
979 int nCol = 1;
980 CString entryname = GitPath->GetGitPathString();
981 int icon_idx = 0;
982 if (GitPath->IsDirectory())
983 icon_idx = m_nIconFolder;
984 else
986 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath);
988 if(GitPath->m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !GitPath->GetGitOldPathString().IsEmpty())
990 // relative path
991 CString rename;
992 rename.Format(_T(" (from %s)"), GitPath->GetGitOldPathString());
993 entryname += rename;
996 InsertItem(index, entryname, icon_idx);
998 this->SetItemData(index, (DWORD_PTR)GitPath);
999 // SVNSLC_COLFILENAME
1000 SetItemText(index, nCol++, GitPath->GetFileOrDirectoryName());
1001 // SVNSLC_COLEXT
1002 SetItemText(index, nCol++, GitPath->GetFileExtension());
1003 // SVNSLC_COLSTATUS
1004 SetItemText(index, nCol++, GitPath->GetActionName());
1006 SetItemText(index, GetColumnIndex(GITSLC_COLADD),GitPath->m_StatAdd);
1007 SetItemText(index, GetColumnIndex(GITSLC_COLDEL),GitPath->m_StatDel);
1010 SetCheck(index, GitPath->m_Checked);
1011 if (GitPath->m_Checked)
1012 m_nSelected++;
1015 if( GitPath->m_Action & CTGitPath::LOGACTIONS_IGNORE)
1016 SetItemGroup(index, 2);
1017 else if( GitPath->m_Action & CTGitPath::LOGACTIONS_UNVER)
1018 SetItemGroup(index,1);
1019 else
1021 SetItemGroup(index, GitPath->m_ParentNo&(PARENT_MASK|MERGE_MASK));
1024 m_bBlock = FALSE;
1028 #if 0
1029 void CGitStatusListCtrl::AddEntry(FileEntry * entry, WORD langID, int listIndex)
1031 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
1032 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
1034 CString path = entry->GetPath().GetGitPathString();
1035 if ( m_mapFilenameToChecked.size()!=0 && m_mapFilenameToChecked.find(path) != m_mapFilenameToChecked.end() )
1037 // The user manually de-/selected an item. We now restore this status
1038 // when refreshing.
1039 entry->checked = m_mapFilenameToChecked[path];
1042 m_bBlock = TRUE;
1043 TCHAR buf[100];
1044 int index = listIndex;
1045 int nCol = 1;
1046 CString entryname = entry->GetDisplayName();
1047 int icon_idx = 0;
1048 if (entry->isfolder)
1049 icon_idx = m_nIconFolder;
1050 else
1052 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(entry->path);
1054 // relative path
1055 InsertItem(index, entryname, icon_idx);
1056 // SVNSLC_COLFILENAME
1057 SetItemText(index, nCol++, entry->path.GetFileOrDirectoryName());
1058 // SVNSLC_COLEXT
1059 SetItemText(index, nCol++, entry->path.GetFileExtension());
1060 // SVNSLC_COLSTATUS
1061 if (entry->isNested)
1063 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1064 SetItemText(index, nCol++, sTemp);
1066 else
1068 GitStatus::GetStatusString(hResourceHandle, entry->status, buf, _countof(buf), (WORD)langID);
1069 if ((entry->copied)&&(_tcslen(buf)>1))
1070 _tcscat_s(buf, 100, _T(" (+)"));
1071 if ((entry->switched)&&(_tcslen(buf)>1))
1072 _tcscat_s(buf, 100, _T(" (s)"));
1073 #if 0
1074 if ((entry->status == entry->propstatus)&&
1075 (entry->status != git_wc_status_normal)&&
1076 (entry->status != git_wc_status_unversioned)&&
1077 (!GitStatus::IsImportant(entry->textstatus)))
1078 _tcscat_s(buf, 100, ponly);
1079 #endif
1080 SetItemText(index, nCol++, buf);
1082 // SVNSLC_COLREMOTESTATUS
1083 if (entry->isNested)
1085 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1086 SetItemText(index, nCol++, sTemp);
1088 else
1090 #if 0
1091 SVNStatus::GetStatusString(hResourceHandle, entry->remotestatus, buf, _countof(buf), (WORD)langID);
1092 if ((entry->copied)&&(_tcslen(buf)>1))
1093 _tcscat_s(buf, 100, _T(" (+)"));
1094 if ((entry->switched)&&(_tcslen(buf)>1))
1095 _tcscat_s(buf, 100, _T(" (s)"));
1096 if ((entry->remotestatus == entry->remotepropstatus)&&
1097 (entry->remotestatus != git_wc_status_none)&&
1098 (entry->remotestatus != git_wc_status_normal)&&
1099 (entry->remotestatus != git_wc_status_unversioned)&&
1100 (!SVNStatus::IsImportant(entry->remotetextstatus)))
1101 _tcscat_s(buf, 100, ponly);
1102 #endif
1103 SetItemText(index, nCol++, buf);
1105 // SVNSLC_COLTEXTSTATUS
1106 if (entry->isNested)
1108 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1109 SetItemText(index, nCol++, sTemp);
1111 else
1113 #if 0
1114 SVNStatus::GetStatusString(hResourceHandle, entry->textstatus, buf, _countof(buf), (WORD)langID);
1115 if ((entry->copied)&&(_tcslen(buf)>1))
1116 _tcscat_s(buf, 100, _T(" (+)"));
1117 if ((entry->switched)&&(_tcslen(buf)>1))
1118 _tcscat_s(buf, 100, _T(" (s)"));
1119 #endif
1120 SetItemText(index, nCol++, buf);
1122 // SVNSLC_COLPROPSTATUS
1123 if (entry->isNested)
1125 SetItemText(index, nCol++, _T(""));
1127 else
1129 #if 0
1130 SVNStatus::GetStatusString(hResourceHandle, entry->propstatus, buf, _countof(buf), (WORD)langID);
1131 if ((entry->copied)&&(_tcslen(buf)>1))
1132 _tcscat_s(buf, 100, _T(" (+)"));
1133 if ((entry->switched)&&(_tcslen(buf)>1))
1134 _tcscat_s(buf, 100, _T(" (s)"));
1135 #endif
1136 SetItemText(index, nCol++, buf);
1138 // SVNSLC_COLREMOTETEXT
1139 if (entry->isNested)
1141 SetItemText(index, nCol++, _T(""));
1143 else
1145 #if 0
1146 SVNStatus::GetStatusString(hResourceHandle, entry->remotetextstatus, buf, _countof(buf), (WORD)langID);
1147 SetItemText(index, nCol++, buf);
1148 #endif
1150 // SVNSLC_COLREMOTEPROP
1151 if (entry->isNested)
1153 SetItemText(index, nCol++, _T(""));
1155 else
1157 // SVNStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, _countof(buf), (WORD)langID);
1158 SetItemText(index, nCol++, buf);
1160 // SVNSLC_COLURL
1161 // SetItemText(index, nCol++, entry->url);
1162 // SVNSLC_COLLOCK
1163 #if 0
1164 if (!m_HeadRev.IsHead())
1166 // we have contacted the repository
1168 // decision-matrix
1169 // wc repository text
1170 // "" "" ""
1171 // "" UID1 owner
1172 // UID1 UID1 owner
1173 // UID1 "" lock has been broken
1174 // UID1 UID2 lock has been stolen
1175 if (entry->lock_token.IsEmpty() || (entry->lock_token.Compare(entry->lock_remotetoken)==0))
1177 if (entry->lock_owner.IsEmpty())
1178 SetItemText(index, nCol++, entry->lock_remoteowner);
1179 else
1180 SetItemText(index, nCol++, entry->lock_owner);
1182 else if (entry->lock_remotetoken.IsEmpty())
1184 // broken lock
1185 CString temp(MAKEINTRESOURCE(IDS_STATUSLIST_LOCKBROKEN));
1186 SetItemText(index, nCol++, temp);
1188 else
1190 // stolen lock
1191 CString temp;
1192 temp.Format(IDS_STATUSLIST_LOCKSTOLEN, (LPCTSTR)entry->lock_remoteowner);
1193 SetItemText(index, nCol++, temp);
1196 else
1197 SetItemText(index, nCol++, entry->lock_owner);
1198 // SVNSLC_COLLOCKCOMMENT
1199 SetItemText(index, nCol++, entry->lock_comment);
1200 // SVNSLC_COLAUTHOR
1201 SetItemText(index, nCol++, entry->last_commit_author);
1202 // SVNSLC_COLREVISION
1203 CString temp;
1204 temp.Format(_T("%ld"), entry->last_commit_rev);
1205 if (entry->last_commit_rev > 0)
1206 SetItemText(index, nCol++, temp);
1207 else
1208 SetItemText(index, nCol++, _T(""));
1209 // SVNSLC_COLREMOTEREVISION
1210 temp.Format(_T("%ld"), entry->remoterev);
1211 if (entry->remoterev > 0)
1212 SetItemText(index, nCol++, temp);
1213 else
1214 SetItemText(index, nCol++, _T(""));
1215 // SVNSLC_COLDATE
1216 TCHAR datebuf[SVN_DATE_BUFFER];
1217 apr_time_t date = entry->last_commit_date;
1218 SVN::formatDate(datebuf, date, true);
1219 if (date)
1220 SetItemText(index, nCol++, datebuf);
1221 else
1222 SetItemText(index, nCol++, _T(""));
1223 // SVNSLC_COLSVNNEEDSLOCK
1224 BOOL bFoundSVNNeedsLock = entry->present_props.IsNeedsLockSet();
1225 CString strSVNNeedsLock = (bFoundSVNNeedsLock) ? _T("*") : _T("");
1226 SetItemText(index, nCol++, strSVNNeedsLock);
1227 // SVNSLC_COLCOPYFROM
1228 if (m_sURL.Compare(entry->copyfrom_url.Left(m_sURL.GetLength()))==0)
1229 temp = entry->copyfrom_url.Mid(m_sURL.GetLength());
1230 else
1231 temp = entry->copyfrom_url;
1232 SetItemText(index, nCol++, temp);
1233 // SVNSLC_COLMODIFICATIONDATE
1234 __int64 filetime = entry->GetPath().GetLastWriteTime();
1235 if ( (filetime) && (entry->status!=git_wc_status_deleted) )
1237 FILETIME* f = (FILETIME*)(__int64*)&filetime;
1238 TCHAR datebuf[SVN_DATE_BUFFER];
1239 SVN::formatDate(datebuf,*f,true);
1240 SetItemText(index, nCol++, datebuf);
1242 else
1244 SetItemText(index, nCol++, _T(""));
1247 // user-defined properties
1248 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
1249 ; i < count
1250 ; ++i)
1252 assert (i == nCol++);
1253 assert (m_ColumnManager.IsUserProp (i));
1255 CString name = m_ColumnManager.GetName(i);
1256 if (entry->present_props.HasProperty (name))
1258 const CString& propVal = entry->present_props [name];
1259 if (propVal.IsEmpty())
1260 SetItemText(index, i, m_sNoPropValueText);
1261 else
1262 SetItemText(index, i, propVal);
1264 else
1265 SetItemText(index, i, _T(""));
1268 SetCheck(index, entry->checked);
1269 if (entry->checked)
1270 m_nSelected++;
1271 if (m_changelists.find(entry->changelist) != m_changelists.end())
1272 SetItemGroup(index, m_changelists[entry->changelist]);
1273 else
1274 SetItemGroup(index, 0);
1275 m_bBlock = FALSE;
1276 #endif
1278 #endif
1279 bool CGitStatusListCtrl::SetItemGroup(int item, int groupindex)
1281 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1282 // return false;
1283 if (groupindex < 0)
1284 return false;
1285 LVITEM i = {0};
1286 i.mask = LVIF_GROUPID;
1287 i.iItem = item;
1288 i.iSubItem = 0;
1289 i.iGroupId = groupindex;
1291 return !!SetItem(&i);
1294 void CGitStatusListCtrl::OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult)
1296 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1297 *pResult = 0;
1298 if (m_bBlock)
1299 return;
1300 m_bBlock = TRUE;
1301 if (m_nSortedColumn == phdr->iItem)
1302 m_bAscending = !m_bAscending;
1303 else
1304 m_bAscending = TRUE;
1305 m_nSortedColumn = phdr->iItem;
1306 Show(m_dwShow, 0, m_bShowFolders,false,true);
1308 m_bBlock = FALSE;
1311 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
1313 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1314 *pResult = 0;
1316 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1317 if ((m_bBlock)&&(m_bBlockUI))
1319 // if we're blocked, prevent changing of the check state
1320 if ((!ISCHECKED(pNMLV->uOldState) && ISCHECKED(pNMLV->uNewState))||
1321 (ISCHECKED(pNMLV->uOldState) && !ISCHECKED(pNMLV->uNewState)))
1322 *pResult = TRUE;
1326 BOOL CGitStatusListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
1328 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1329 *pResult = 0;
1330 CWnd* pParent = GetParent();
1331 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
1333 pParent->SendMessage(GITSLNM_ITEMCHANGED, pNMLV->iItem);
1336 if ((pNMLV->uNewState==0)||(pNMLV->uNewState & LVIS_SELECTED)||(pNMLV->uNewState & LVIS_FOCUSED))
1337 return FALSE;
1339 if (m_bBlock)
1340 return FALSE;
1342 bool bSelected = !!(ListView_GetItemState(m_hWnd, pNMLV->iItem, LVIS_SELECTED) & LVIS_SELECTED);
1343 int nListItems = GetItemCount();
1345 m_bBlock = TRUE;
1346 // was the item checked?
1348 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1349 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1351 if (GetCheck(pNMLV->iItem))
1353 CheckEntry(pNMLV->iItem, nListItems);
1354 if (bSelected)
1356 POSITION pos = GetFirstSelectedItemPosition();
1357 int index;
1358 while ((index = GetNextSelectedItem(pos)) >= 0)
1360 if (index != pNMLV->iItem)
1361 CheckEntry(index, nListItems);
1365 else
1367 UncheckEntry(pNMLV->iItem, nListItems);
1368 if (bSelected)
1370 POSITION pos = GetFirstSelectedItemPosition();
1371 int index;
1372 while ((index = GetNextSelectedItem(pos)) >= 0)
1374 if (index != pNMLV->iItem)
1375 UncheckEntry(index, nListItems);
1380 GetStatisticsString();
1381 m_bBlock = FALSE;
1382 NotifyCheck();
1384 return FALSE;
1387 void CGitStatusListCtrl::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
1389 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
1391 *pResult = FALSE;
1394 void CGitStatusListCtrl::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
1396 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
1398 Invalidate(FALSE);
1401 void CGitStatusListCtrl::CheckEntry(int index, int /*nListItems*/)
1403 Locker lock(m_critSec);
1404 //FileEntry * entry = GetListEntry(index);
1405 CTGitPath *path=(CTGitPath*)GetItemData(index);
1406 ASSERT(path != NULL);
1407 if (path == NULL)
1408 return;
1409 m_mapFilenameToChecked[path->GetGitPathString()] = true;
1410 SetCheck(index, TRUE);
1411 //entry = GetListEntry(index);
1412 // if an unversioned item was checked, then we need to check if
1413 // the parent folders are unversioned too. If the parent folders actually
1414 // are unversioned, then check those too.
1415 #if 0
1416 if (entry->status == git_wc_status_unversioned)
1418 // we need to check the parent folder too
1419 const CTGitPath& folderpath = entry->path;
1420 for (int i=0; i< nListItems; ++i)
1422 FileEntry * testEntry = GetListEntry(i);
1423 ASSERT(testEntry != NULL);
1424 if (testEntry == NULL)
1425 continue;
1426 if (!testEntry->checked)
1428 if (testEntry->path.IsAncestorOf(folderpath) && (!testEntry->path.IsEquivalentTo(folderpath)))
1430 SetEntryCheck(testEntry,i,true);
1431 m_nSelected++;
1436 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1437 if ( (entry->status == git_wc_status_deleted) || (m_bCheckChildrenWithParent) || (bShift) )
1439 // if a deleted folder gets checked, we have to check all
1440 // children of that folder too.
1441 if (entry->path.IsDirectory())
1443 SetCheckOnAllDescendentsOf(entry, true);
1446 // if a deleted file or folder gets checked, we have to
1447 // check all parents of this item too.
1448 for (int i=0; i<nListItems; ++i)
1450 FileEntry * testEntry = GetListEntry(i);
1451 ASSERT(testEntry != NULL);
1452 if (testEntry == NULL)
1453 continue;
1454 if (!testEntry->checked)
1456 if (testEntry->path.IsAncestorOf(entry->path) && (!testEntry->path.IsEquivalentTo(entry->path)))
1458 if ((testEntry->status == git_wc_status_deleted)||(m_bCheckChildrenWithParent))
1460 SetEntryCheck(testEntry,i,true);
1461 m_nSelected++;
1462 // now we need to check all children of this parent folder
1463 SetCheckOnAllDescendentsOf(testEntry, true);
1469 #endif
1470 if ( !path->m_Checked )
1472 path->m_Checked = TRUE;
1473 m_nSelected++;
1477 void CGitStatusListCtrl::UncheckEntry(int index, int /*nListItems*/)
1479 Locker lock(m_critSec);
1480 CTGitPath *path=(CTGitPath*)GetItemData(index);
1481 ASSERT(path != NULL);
1482 if (path == NULL)
1483 return;
1484 SetCheck(index, FALSE);
1485 m_mapFilenameToChecked[path->GetGitPathString()] = false;
1486 //entry = GetListEntry(index);
1487 // item was unchecked
1488 #if 0
1489 if (entry->path.IsDirectory())
1491 // disable all files within an unselected folder, except when unchecking a folder with property changes
1492 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1493 if ( (entry->status != git_wc_status_modified) || (bShift) )
1495 SetCheckOnAllDescendentsOf(entry, false);
1498 else if (entry->status == git_wc_status_deleted)
1500 // a "deleted" file was unchecked, so uncheck all parent folders
1501 // and all children of those parents
1502 for (int i=0; i<nListItems; i++)
1504 FileEntry * testEntry = GetListEntry(i);
1505 ASSERT(testEntry != NULL);
1506 if (testEntry == NULL)
1507 continue;
1508 if (testEntry->checked)
1510 if (testEntry->path.IsAncestorOf(entry->path))
1512 if (testEntry->status == git_wc_status_deleted)
1514 SetEntryCheck(testEntry,i,false);
1515 m_nSelected--;
1517 SetCheckOnAllDescendentsOf(testEntry, false);
1523 #endif
1524 if ( path->m_Checked )
1526 path->m_Checked = FALSE;
1527 m_nSelected--;
1530 #if 0
1531 bool CGitStatusListCtrl::EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2)
1533 return pEntry1->path < pEntry2->path;
1536 bool CGitStatusListCtrl::IsEntryVersioned(const FileEntry* pEntry1)
1538 return pEntry1->status != git_wc_status_unversioned;
1540 #endif
1541 bool CGitStatusListCtrl::BuildStatistics()
1544 bool bRefetchStatus = false;
1546 // now gather some statistics
1547 m_nUnversioned = 0;
1548 m_nNormal = 0;
1549 m_nModified = 0;
1550 m_nAdded = 0;
1551 m_nDeleted = 0;
1552 m_nConflicted = 0;
1553 m_nTotal = 0;
1554 m_nSelected = 0;
1555 m_nLineAdded = 0;
1556 m_nLineDeleted = 0;
1557 m_nRenamed = 0;
1559 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1561 int status=((CTGitPath*)m_arStatusArray[i])->m_Action;
1563 m_nLineAdded += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatAdd);
1564 m_nLineDeleted += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatDel);
1566 if(status&(CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
1567 m_nAdded++;
1569 if(status&CTGitPath::LOGACTIONS_DELETED)
1570 m_nDeleted++;
1572 if(status&(CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_MODIFIED))
1573 m_nModified++;
1575 if(status&CTGitPath::LOGACTIONS_UNMERGED)
1576 m_nConflicted++;
1578 if(status&(CTGitPath::LOGACTIONS_IGNORE|CTGitPath::LOGACTIONS_UNVER))
1579 m_nUnversioned++;
1581 if(status&(CTGitPath::LOGACTIONS_REPLACED))
1582 m_nRenamed++;
1584 if(((CTGitPath*)m_arStatusArray[i])->m_Checked)
1585 m_nSelected++;
1587 // } // switch (entry->status)
1588 // } // if (entry)
1589 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1590 return !bRefetchStatus;
1592 return FALSE;
1596 int CGitStatusListCtrl::GetGroupFromPoint(POINT * ppt)
1598 // the point must be relative to the upper left corner of the control
1600 if (ppt == NULL)
1601 return -1;
1602 if (!IsGroupViewEnabled())
1603 return -1;
1605 POINT pt = *ppt;
1606 pt.x = 10;
1607 UINT flags = 0;
1608 int nItem = -1;
1609 RECT rc;
1610 GetWindowRect(&rc);
1611 while (((flags & LVHT_BELOW) == 0)&&(pt.y < rc.bottom))
1613 nItem = HitTest(pt, &flags);
1614 if ((flags & LVHT_ONITEM)||(flags & LVHT_EX_GROUP_HEADER))
1616 // the first item below the point
1618 // check if the point is too much right (i.e. if the point
1619 // is farther to the right than the width of the item)
1620 RECT r;
1621 GetItemRect(nItem, &r, LVIR_LABEL);
1622 if (ppt->x > r.right)
1623 return -1;
1625 LVITEM lv = {0};
1626 lv.mask = LVIF_GROUPID;
1627 lv.iItem = nItem;
1628 GetItem(&lv);
1629 int groupID = lv.iGroupId;
1630 // now we search upwards and check if the item above this one
1631 // belongs to another group. If it belongs to the same group,
1632 // we're not over a group header
1633 while (pt.y >= 0)
1635 pt.y -= 2;
1636 nItem = HitTest(pt, &flags);
1637 if ((flags & LVHT_ONITEM)&&(nItem >= 0))
1639 // the first item below the point
1640 LVITEM lv = {0};
1641 lv.mask = LVIF_GROUPID;
1642 lv.iItem = nItem;
1643 GetItem(&lv);
1644 if (lv.iGroupId != groupID)
1645 return groupID;
1646 else
1647 return -1;
1650 if (pt.y < 0)
1651 return groupID;
1652 return -1;
1654 pt.y += 2;
1656 return -1;
1659 void CGitStatusListCtrl::OnContextMenuGroup(CWnd * /*pWnd*/, CPoint point)
1661 POINT clientpoint = point;
1662 ScreenToClient(&clientpoint);
1663 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint) >= 0))
1665 CMenu popup;
1666 if (popup.CreatePopupMenu())
1668 CString temp;
1669 temp.LoadString(IDS_STATUSLIST_CHECKGROUP);
1670 popup.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_CHECKGROUP, temp);
1671 temp.LoadString(IDS_STATUSLIST_UNCHECKGROUP);
1672 popup.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_UNCHECKGROUP, temp);
1673 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1674 bool bCheck = false;
1675 switch (cmd)
1677 case IDGITLC_CHECKGROUP:
1678 bCheck = true;
1679 // fall through here
1680 case IDGITLC_UNCHECKGROUP:
1682 int group = GetGroupFromPoint(&clientpoint);
1683 // go through all items and check/uncheck those assigned to the group
1684 // but block the OnLvnItemChanged handler
1685 m_bBlock = true;
1686 LVITEM lv;
1687 for (int i=0; i<GetItemCount(); ++i)
1689 SecureZeroMemory(&lv, sizeof(LVITEM));
1690 lv.mask = LVIF_GROUPID;
1691 lv.iItem = i;
1692 GetItem(&lv);
1694 if (lv.iGroupId == group)
1696 CTGitPath * entry = (CTGitPath*)GetItemData(i);
1697 if (entry)
1699 bool bOldCheck = entry->m_Checked;
1700 SetEntryCheck(entry, i, bCheck);
1701 if (bCheck != bOldCheck)
1703 if (bCheck)
1704 m_nSelected++;
1705 else
1706 m_nSelected--;
1712 GetStatisticsString();
1713 NotifyCheck();
1714 m_bBlock = false;
1716 break;
1722 void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point)
1725 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1727 bool XPorLater = false;
1728 OSVERSIONINFOEX inf;
1729 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
1730 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
1731 GetVersionEx((OSVERSIONINFO *)&inf);
1732 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
1733 if (fullver >= 0x0501)
1734 XPorLater = true;
1735 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1736 CTGitPath * filepath;
1738 int selIndex = GetSelectionMark();
1739 if ((point.x == -1) && (point.y == -1))
1741 CRect rect;
1742 GetItemRect(selIndex, &rect, LVIR_LABEL);
1743 ClientToScreen(&rect);
1744 point = rect.CenterPoint();
1746 if ((GetSelectedCount() == 0)&&(XPorLater)&&(m_bHasCheckboxes))
1748 // nothing selected could mean the context menu is requested for
1749 // a group header
1750 OnContextMenuGroup(pWnd, point);
1752 else if (selIndex >= 0)
1754 //FileEntry * entry = GetListEntry(selIndex);
1756 filepath = (CTGitPath * )GetItemData(selIndex);
1758 ASSERT(filepath != NULL);
1759 if (filepath == NULL)
1760 return;
1762 //const CTGitPath& filepath = entry->path;
1763 int wcStatus = filepath->m_Action;
1764 // entry is selected, now show the popup menu
1765 Locker lock(m_critSec);
1766 CIconMenu popup;
1767 CMenu changelistSubMenu;
1768 CMenu ignoreSubMenu;
1769 if (popup.CreatePopupMenu())
1771 //Add Menu for version controlled file
1773 if (GetSelectedCount() > 0 && wcStatus & CTGitPath::LOGACTIONS_UNMERGED)
1775 if (GetSelectedCount() == 1 && (m_dwContextMenus & GITSLC_POPCONFLICT)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1777 popup.AppendMenuIcon(IDGITLC_EDITCONFLICT, IDS_MENUCONFLICT, IDI_CONFLICT);
1779 if (m_dwContextMenus & GITSLC_POPRESOLVE)
1781 popup.AppendMenuIcon(IDGITLC_RESOLVECONFLICT, IDS_STATUSLIST_CONTEXT_RESOLVED, IDI_RESOLVE);
1783 if ((m_dwContextMenus & GITSLC_POPRESOLVE)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1785 popup.AppendMenuIcon(IDGITLC_RESOLVETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS, IDI_RESOLVE);
1786 popup.AppendMenuIcon(IDGITLC_RESOLVEMINE, IDS_SVNPROGRESS_MENUUSEMINE, IDI_RESOLVE);
1788 if ((m_dwContextMenus & GITSLC_POPCONFLICT)||(m_dwContextMenus & GITSLC_POPRESOLVE))
1789 popup.AppendMenu(MF_SEPARATOR);
1792 if (GetSelectedCount() > 0)
1794 if (wcStatus & CTGitPath::LOGACTIONS_UNVER)
1795 if (m_dwContextMenus & GITSLC_POPADD)
1797 //if ( entry->IsFolder() )
1799 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1801 //else
1803 popup.AppendMenuIcon(IDGITLC_ADD, IDS_STATUSLIST_CONTEXT_ADD, IDI_ADD);
1808 if (!(wcStatus &CTGitPath::LOGACTIONS_UNVER))
1810 if ( (m_dwContextMenus & GITSLC_POPCOMPAREWITHBASE) && GetSelectedCount()>0)
1812 if(filepath->m_ParentNo & MERGE_MASK)
1813 popup.AppendMenuIcon(IDGITLC_COMPARE, IDS_TREE_DIFF, IDI_DIFF);
1814 else
1815 popup.AppendMenuIcon(IDGITLC_COMPARE, IDS_LOG_COMPAREWITHBASE, IDI_DIFF);
1817 popup.SetDefaultItem(IDGITLC_COMPARE, FALSE);
1820 if ((m_dwContextMenus & this->GetContextMenuBit(IDGITLC_COMPAREWC)) && GetSelectedCount()>0)
1822 if( (!m_CurrentVersion.IsEmpty()) && m_CurrentVersion != GIT_REV_ZERO)
1823 popup.AppendMenuIcon(IDGITLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1825 //Select one items
1826 if (GetSelectedCount() == 1)
1828 bool bEntryAdded = false;
1829 //if (entry->remotestatus <= git_wc_status_normal)
1831 // if (wcStatus > git_wc_status_normal)
1832 // {
1833 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
1834 // {
1835 if(!g_Git.IsInitRepos() && (m_dwContextMenus&GITSLC_POPGNUDIFF))
1837 popup.AppendMenuIcon(IDGITLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1839 bEntryAdded = true;
1841 // }
1842 // }
1845 //else if (wcStatus != git_wc_status_deleted)
1847 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
1848 // {
1849 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1850 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1851 // bEntryAdded = true;
1852 // }
1853 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
1854 // {
1855 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1856 // bEntryAdded = true;
1857 // }
1859 if (bEntryAdded)
1860 popup.AppendMenu(MF_SEPARATOR);
1862 //else if (GetSelectedCount() > 1)
1864 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1865 // {
1866 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1867 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1868 // }
1872 if( (!this->m_Rev1.IsEmpty()) || (!this->m_Rev1.IsEmpty()) )
1874 if(GetSelectedCount() == 1)
1876 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_COMPARETWO))
1878 popup.AppendMenuIcon(IDGITLC_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1879 popup.SetDefaultItem(IDGITLC_COMPARETWO, FALSE);
1881 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_GNUDIFF2))
1883 popup.AppendMenuIcon(IDGITLC_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1888 //Select Multi item
1889 if (GetSelectedCount() > 0)
1891 if ((GetSelectedCount() == 2) && (m_dwContextMenus & this->GetContextMenuBit(GITSLC_POPCOMPARETWOFILES)))
1893 POSITION pos = GetFirstSelectedItemPosition();
1894 int index = GetNextSelectedItem(pos);
1895 if (index >= 0)
1897 CTGitPath * entry2 = NULL;
1898 bool bothItemsAreFiles = true;
1899 entry2 = (CTGitPath * )GetItemData(index);
1900 if (entry2)
1901 bothItemsAreFiles = !entry2->IsDirectory();
1902 index = GetNextSelectedItem(pos);
1903 if (index >= 0)
1905 entry2 = (CTGitPath * )GetItemData(index);
1906 if (entry2)
1907 bothItemsAreFiles = bothItemsAreFiles && !entry2->IsDirectory();
1908 if (bothItemsAreFiles)
1909 popup.AppendMenuIcon(IDGITLC_COMPARETWOFILES, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES, IDI_DIFF);
1913 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
1914 // {
1915 // POSITION pos = GetFirstSelectedItemPosition();
1916 // int index = GetNextSelectedItem(pos);
1917 // if (index >= 0)
1918 // {
1919 // FileEntry * entry = GetListEntry(index);
1920 // git_wc_status_kind status1 = git_wc_status_none;
1921 // git_wc_status_kind status2 = git_wc_status_none;
1922 // if (entry)
1923 // status1 = entry->status;
1924 // index = GetNextSelectedItem(pos);
1925 // if (index >= 0)
1926 // {
1927 // entry = GetListEntry(index);
1928 // if (entry)
1929 // status2 = entry->status;
1930 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
1931 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
1932 // {
1933 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
1934 // }
1935 // }
1936 // }
1937 // }
1938 // if (wcStatus > git_wc_status_normal)
1939 // {
1940 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1941 // {
1942 // // reverting missing folders is not possible
1943 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1944 // {
1945 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1946 // }
1947 // }
1948 // }
1949 // if (entry->remotestatus > git_wc_status_normal)
1950 // {
1951 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1952 // {
1953 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1954 // }
1955 // }
1958 if ( (GetSelectedCount() >0 ) && (!(wcStatus & CTGitPath::LOGACTIONS_UNVER)))
1960 if ((m_dwContextMenus & GITSLC_POPREVERT) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO))
1962 popup.AppendMenuIcon(IDGITLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1965 if ((m_dwContextMenus & GetContextMenuBit(IDGITLC_REVERTTOREV)) && ( !this->m_CurrentVersion.IsEmpty() )
1966 && this->m_CurrentVersion != GIT_REV_ZERO && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1968 popup.AppendMenuIcon(IDGITLC_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1972 if ((GetSelectedCount() == 1)&&(!(wcStatus & CTGitPath::LOGACTIONS_UNVER))
1973 &&(!(wcStatus & CTGitPath::LOGACTIONS_IGNORE)))
1975 if (m_dwContextMenus & GITSLC_POPSHOWLOG)
1977 popup.AppendMenuIcon(IDGITLC_LOG, IDS_REPOBROWSE_SHOWLOG, IDI_LOG);
1979 if (m_dwContextMenus & GITSLC_POPBLAME && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1981 popup.AppendMenuIcon(IDGITLC_BLAME, IDS_MENUBLAME, IDI_BLAME);
1984 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1985 if ( (GetSelectedCount() == 1) )
1987 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_SAVEAS) && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1989 popup.AppendMenuIcon(IDGITLC_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
1992 if (m_dwContextMenus & GITSLC_POPOPEN && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1994 popup.AppendMenuIcon(IDGITLC_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1995 popup.AppendMenuIcon(IDGITLC_OPEN, IDS_REPOBROWSE_OPEN, IDI_OPEN);
1996 popup.AppendMenuIcon(IDGITLC_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1997 if (wcStatus &CTGitPath::LOGACTIONS_UNVER) {
1998 popup.SetDefaultItem(IDGITLC_OPEN, FALSE);
2002 if (m_dwContextMenus & GITSLC_POPEXPLORE && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
2004 popup.AppendMenuIcon(IDGITLC_EXPLORE, IDS_STATUSLIST_CONTEXT_EXPLORE, IDI_EXPLORER);
2008 if (GetSelectedCount() > 0)
2010 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
2011 // {
2012 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2013 // }
2014 // 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))
2015 // {
2016 // if (bShift)
2017 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
2018 // else
2019 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
2020 // }
2021 if ((wcStatus & CTGitPath::LOGACTIONS_UNVER)/*||(wcStatus == git_wc_status_deleted)*/)
2023 if (m_dwContextMenus & GITSLC_POPDELETE)
2025 popup.AppendMenuIcon(IDGITLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2028 if ( (wcStatus & CTGitPath::LOGACTIONS_UNVER || wcStatus & CTGitPath::LOGACTIONS_DELETED) )
2030 if (m_dwContextMenus & GITSLC_POPIGNORE)
2033 CTGitPathList ignorelist;
2034 FillListOfSelectedItemPaths(ignorelist);
2035 //check if all selected entries have the same extension
2036 bool bSameExt = true;
2037 CString sExt;
2038 for (int i=0; i<ignorelist.GetCount(); ++i)
2040 if (sExt.IsEmpty() && (i==0))
2041 sExt = ignorelist[i].GetFileExtension();
2042 else if (sExt.CompareNoCase(ignorelist[i].GetFileExtension())!=0)
2043 bSameExt = false;
2045 if (bSameExt)
2047 if (ignoreSubMenu.CreateMenu())
2049 CString ignorepath;
2050 if (ignorelist.GetCount()==1)
2051 ignorepath = ignorelist[0].GetFileOrDirectoryName();
2052 else
2053 ignorepath.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2054 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_IGNORE, ignorepath);
2055 ignorepath = _T("*")+sExt;
2056 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_IGNOREMASK, ignorepath);
2057 CString temp;
2058 temp.LoadString(IDS_MENUIGNORE);
2059 popup.InsertMenu((UINT)-1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)ignoreSubMenu.m_hMenu, temp);
2062 else
2064 CString temp;
2065 if (ignorelist.GetCount()==1)
2067 temp.LoadString(IDS_MENUIGNORE);
2069 else
2071 temp.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2073 popup.AppendMenuIcon(IDGITLC_IGNORE, temp, IDI_IGNORE);
2081 if (GetSelectedCount() > 0)
2083 #if 0
2084 if ((!entry->IsFolder())&&(wcStatus >= git_wc_status_normal)
2085 &&(wcStatus!=git_wc_status_missing)&&(wcStatus!=git_wc_status_deleted)
2086 &&(wcStatus!=git_wc_status_added))
2088 popup.AppendMenu(MF_SEPARATOR);
2089 if ((entry->lock_token.IsEmpty())&&(!entry->IsFolder()))
2091 if (m_dwContextMenus & SVNSLC_POPLOCK)
2093 popup.AppendMenuIcon(IDSVNLC_LOCK, IDS_MENU_LOCK, IDI_LOCK);
2096 if ((!entry->lock_token.IsEmpty())&&(!entry->IsFolder()))
2098 if (m_dwContextMenus & SVNSLC_POPUNLOCK)
2100 popup.AppendMenuIcon(IDSVNLC_UNLOCK, IDS_MENU_UNLOCK, IDI_UNLOCK);
2105 if ((!entry->IsFolder())&&((!entry->lock_token.IsEmpty())||(!entry->lock_remotetoken.IsEmpty())))
2107 if (m_dwContextMenus & SVNSLC_POPUNLOCKFORCE)
2109 popup.AppendMenuIcon(IDSVNLC_UNLOCKFORCE, IDS_MENU_UNLOCKFORCE, IDI_UNLOCK);
2113 if (wcStatus != git_wc_status_missing && wcStatus != git_wc_status_deleted &&wcStatus!=git_wc_status_unversioned)
2115 popup.AppendMenu(MF_SEPARATOR);
2116 popup.AppendMenuIcon(IDSVNLC_PROPERTIES, IDS_STATUSLIST_CONTEXT_PROPERTIES, IDI_PROPERTIES);
2118 #endif
2119 popup.AppendMenu(MF_SEPARATOR);
2120 popup.AppendMenuIcon(IDGITLC_COPY, IDS_STATUSLIST_CONTEXT_COPY, IDI_COPYCLIP);
2121 popup.AppendMenuIcon(IDGITLC_COPYEXT, IDS_STATUSLIST_CONTEXT_COPYEXT, IDI_COPYCLIP);
2122 #if 0
2123 if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS)&&(XPorLater)
2124 &&(wcStatus != git_wc_status_unversioned)&&(wcStatus != git_wc_status_none))
2126 popup.AppendMenu(MF_SEPARATOR);
2127 // changelist commands
2128 size_t numChangelists = GetNumberOfChangelistsInSelection();
2129 if (numChangelists > 0)
2131 popup.AppendMenuIcon(IDSVNLC_REMOVEFROMCS, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS);
2133 if ((!entry->IsFolder())&&(changelistSubMenu.CreateMenu()))
2135 CString temp;
2136 temp.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS);
2137 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATECS, temp);
2139 if (entry->changelist.Compare(SVNSLC_IGNORECHANGELIST))
2141 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2142 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATEIGNORECS, SVNSLC_IGNORECHANGELIST);
2145 if (m_changelists.size() > 0)
2147 // find the changelist names
2148 bool bNeedSeparator = true;
2149 int cmdID = IDSVNLC_MOVETOCS;
2150 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
2152 if ((entry->changelist.Compare(it->first))&&(it->first.Compare(SVNSLC_IGNORECHANGELIST)))
2154 if (bNeedSeparator)
2156 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2157 bNeedSeparator = false;
2159 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, cmdID, it->first);
2160 cmdID++;
2164 temp.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS);
2165 popup.AppendMenu(MF_POPUP|MF_STRING, (UINT_PTR)changelistSubMenu.GetSafeHmenu(), temp);
2168 #endif
2171 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2173 m_bBlock = TRUE;
2174 AfxGetApp()->DoWaitCursor(1);
2175 //int iItemCountBeforeMenuCmd = GetItemCount();
2176 //bool bForce = false;
2177 switch (cmd)
2179 case IDGITLC_VIEWREV:
2180 OpenFile(filepath, ALTERNATIVEEDITOR);
2181 break;
2182 case IDGITLC_OPEN:
2183 OpenFile(filepath,OPEN);
2184 break;
2185 case IDGITLC_OPENWITH:
2186 OpenFile(filepath,OPEN_WITH);
2187 break;
2188 case IDGITLC_EXPLORE:
2190 ShellExecute(this->m_hWnd, _T("explore"), filepath->GetDirectory().GetWinPath(), NULL, NULL, SW_SHOW);
2192 break;
2194 // Compare current version and work copy.
2195 case IDGITLC_COMPAREWC:
2197 POSITION pos = GetFirstSelectedItemPosition();
2198 while ( pos )
2200 int index = GetNextSelectedItem(pos);
2201 StartDiffWC(index);
2204 break;
2205 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2206 case IDGITLC_COMPARE:
2208 POSITION pos = GetFirstSelectedItemPosition();
2209 while ( pos )
2211 int index = GetNextSelectedItem(pos);
2212 StartDiff(index);
2215 break;
2216 case IDGITLC_COMPARETWO:
2218 POSITION pos = GetFirstSelectedItemPosition();
2219 while ( pos )
2221 int index = GetNextSelectedItem(pos);
2222 StartDiffTwo(index);
2225 break;
2226 case IDGITLC_COMPARETWOFILES:
2228 POSITION pos = GetFirstSelectedItemPosition();
2229 CTGitPath * firstfilepath, * secondfilepath;
2230 if (pos)
2232 firstfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
2233 secondfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
2235 ASSERT(firstfilepath != NULL && secondfilepath != NULL);
2236 CString sCmd;
2237 sCmd.Format(_T("\"%s\" /command:diff /path:\"%s\" /path2:\"%s\" /hwnd:%ld"), (LPCTSTR)(CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe")), firstfilepath->GetWinPath(), secondfilepath->GetWinPath(), (unsigned long)m_hWnd);
2238 CAppUtils::LaunchApplication(sCmd, NULL, false);
2240 break;
2241 case IDGITLC_GNUDIFF1:
2243 // SVNDiff diff(NULL, this->m_hWnd, true);
2245 // if (entry->remotestatus <= git_wc_status_normal)
2246 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2247 // else
2248 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2249 if(m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
2251 CString fromwhere;
2252 if(m_amend)
2253 fromwhere = _T("~1");
2254 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,GitRev::GetWorkingCopy(),
2255 *filepath,GitRev::GetHead()+fromwhere);
2257 else
2259 if((filepath->m_ParentNo&(PARENT_MASK|MERGE_MASK)) ==0)
2260 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_CurrentVersion+_T("~1"),
2261 *filepath,m_CurrentVersion);
2262 else
2264 CString str;
2265 if(filepath->m_ParentNo & MERGE_MASK)
2268 else
2270 str.Format(_T("%s^%d"),m_CurrentVersion,(filepath->m_ParentNo&PARENT_MASK)+1);
2273 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_CurrentVersion,
2274 *filepath,str, false,false,false,
2275 !!(filepath->m_ParentNo & MERGE_MASK));
2279 break;
2280 case IDGITLC_GNUDIFF2:
2282 // SVNDiff diff(NULL, this->m_hWnd, true);
2284 // if (entry->remotestatus <= git_wc_status_normal)
2285 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2286 // else
2287 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2289 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_Rev1,
2290 *filepath,m_Rev2);
2292 break;
2294 case IDGITLC_ADD:
2295 { // The add went ok, but we now need to run through the selected items again
2296 // and update their status
2297 std::vector<int> selectIndex;
2299 POSITION pos = GetFirstSelectedItemPosition();
2300 int index;
2301 while ((index = GetNextSelectedItem(pos)) >= 0)
2303 selectIndex.push_back(index);
2305 for(int i=0;i<selectIndex.size();i++)
2307 index=selectIndex[i];
2309 CTGitPath * path=(CTGitPath*)GetItemData(index);
2310 ASSERT(path);
2311 if(path == NULL)
2312 continue;
2313 CString cmd;
2314 cmd.Format(_T("git.exe add -f -- \"%s\""), path->GetGitPathString());
2315 CString output;
2316 if (!g_Git.Run(cmd, &output, NULL, CP_ACP))
2318 path->m_Action = CTGitPath::LOGACTIONS_ADDED;
2319 SetEntryCheck(path,index,true);
2321 SetItemGroup(index,0);
2322 this->m_StatusFileList.AddPath(*path);
2323 this->m_UnRevFileList.RemoveItem(*path);
2324 this->m_IgnoreFileList.RemoveItem(*path);
2326 Show(this->m_dwShow,0,true,true,true);
2331 break;
2333 case IDGITLC_DELETE:
2335 //Collect paths
2336 std::vector<int> selectIndex;
2338 POSITION pos = GetFirstSelectedItemPosition();
2339 int index;
2340 while ((index = GetNextSelectedItem(pos)) >= 0)
2342 selectIndex.push_back(index);
2345 //Create file-list ('\0' separated) for SHFileOperation
2346 CString filelist;
2347 for(int i=0;i<selectIndex.size();i++)
2349 index=selectIndex[i];
2351 CTGitPath * path=(CTGitPath*)GetItemData(index);
2352 ASSERT(path);
2353 if(path == NULL)
2354 continue;
2356 filelist += path->GetWinPathString();
2357 filelist += _T("|");
2359 filelist += _T("|");
2360 int len = filelist.GetLength();
2361 TCHAR * buf = new TCHAR[len+2];
2362 _tcscpy_s(buf, len+2, filelist);
2363 for (int i=0; i<len; ++i)
2364 if (buf[i] == '|')
2365 buf[i] = 0;
2366 SHFILEOPSTRUCT fileop;
2367 fileop.hwnd = this->m_hWnd;
2368 fileop.wFunc = FO_DELETE;
2369 fileop.pFrom = buf;
2370 fileop.pTo = NULL;
2371 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
2372 fileop.lpszProgressTitle = _T("deleting file");
2373 int result = SHFileOperation(&fileop);
2374 delete [] buf;
2376 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
2378 SetRedraw(FALSE);
2379 POSITION pos = NULL;
2380 while ((pos = GetFirstSelectedItemPosition()) != 0)
2382 int index = GetNextSelectedItem(pos);
2383 if (GetCheck(index))
2384 m_nSelected--;
2385 m_nTotal--;
2387 RemoveListEntry(index);
2389 SetRedraw(TRUE);
2392 break;
2394 case IDGITLC_BLAME:
2396 CAppUtils::LaunchTortoiseBlame(g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath(), m_CurrentVersion);
2398 break;
2400 case IDGITLC_LOG:
2402 CString sCmd;
2403 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\""),
2404 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath());
2406 CAppUtils::LaunchApplication(sCmd, NULL, false);
2408 break;
2410 case IDGITLC_EDITCONFLICT:
2412 CAppUtils::ConflictEdit(*filepath,false,this->m_bIsRevertTheirMy);
2413 break;
2415 case IDGITLC_RESOLVETHEIRS: //follow up
2416 case IDGITLC_RESOLVEMINE: //follow up
2417 case IDGITLC_RESOLVECONFLICT:
2419 if (CMessageBox::Show(m_hWnd, IDS_PROC_RESOLVE, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO)==IDYES)
2421 POSITION pos = GetFirstSelectedItemPosition();
2422 while (pos != 0)
2424 int index;
2425 index = GetNextSelectedItem(pos);
2426 CTGitPath * fentry =(CTGitPath*) this->GetItemData(index);
2427 if(fentry == NULL)
2428 continue;
2429 CString gitcmd,output;
2430 output.Empty();
2432 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVETHEIRS) ||
2433 ((this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVEMINE) )
2435 gitcmd.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry->GetGitPathString());
2436 if(g_Git.Run(gitcmd,&output,CP_ACP))
2438 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2439 continue;
2442 output.Empty();
2443 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVEMINE) ||
2444 ((this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVETHEIRS) )
2446 gitcmd.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry->GetGitPathString());
2447 if(g_Git.Run(gitcmd,&output,CP_ACP))
2449 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2450 continue;
2454 output.Empty();
2455 if ( fentry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
2457 gitcmd.Format(_T("git.exe add -f -- \"%s\""),fentry->GetGitPathString());
2458 if(g_Git.Run(gitcmd,&output,CP_ACP))
2460 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2462 else
2464 fentry->m_Action |= CTGitPath::LOGACTIONS_MODIFIED;
2465 fentry->m_Action &=~CTGitPath::LOGACTIONS_UNMERGED;
2469 CAppUtils::RemoveTempMergeFile(*fentry);
2472 Show(m_dwShow, 0, m_bShowFolders,0,true);
2475 break;
2477 case IDGITLC_IGNORE:
2479 CTGitPathList ignorelist;
2480 //std::vector<CString> toremove;
2481 FillListOfSelectedItemPaths(ignorelist, true);
2482 SetRedraw(FALSE);
2484 if(!CAppUtils::IgnoreFile(ignorelist,false))
2485 break;
2487 for(int i=0;i<ignorelist.GetCount();i++)
2489 int nListboxEntries = GetItemCount();
2490 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2492 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2493 if (path->GetGitPathString()==ignorelist[i].GetGitPathString())
2495 RemoveListEntry(nItem);
2496 break;
2500 SetRedraw(TRUE);
2502 #if 0
2503 CTSVNPathList ignorelist;
2504 std::vector<CString> toremove;
2505 FillListOfSelectedItemPaths(ignorelist, true);
2506 SetRedraw(FALSE);
2507 for (int j=0; j<ignorelist.GetCount(); ++j)
2509 int nListboxEntries = GetItemCount();
2510 for (int i=0; i<nListboxEntries; ++i)
2512 if (GetListEntry(i)->GetPath().IsEquivalentTo(ignorelist[j]))
2514 selIndex = i;
2515 break;
2518 CString name = CPathUtils::PathPatternEscape(ignorelist[j].GetFileOrDirectoryName());
2519 CTSVNPath parentfolder = ignorelist[j].GetContainingDirectory();
2520 SVNProperties props(parentfolder, SVNRev::REV_WC, false);
2521 CStringA value;
2522 for (int i=0; i<props.GetCount(); i++)
2524 CString propname(props.GetItemName(i).c_str());
2525 if (propname.CompareNoCase(_T("git:ignore"))==0)
2527 stdstring stemp;
2528 // treat values as normal text even if they're not
2529 value = (char *)props.GetItemValue(i).c_str();
2532 if (value.IsEmpty())
2533 value = name;
2534 else
2536 value = value.Trim("\n\r");
2537 value += "\n";
2538 value += name;
2539 value.Remove('\r');
2541 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
2543 CString temp;
2544 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
2545 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2546 break;
2548 if (GetCheck(selIndex))
2549 m_nSelected--;
2550 m_nTotal--;
2552 // now, if we ignored a folder, remove all its children
2553 if (ignorelist[j].IsDirectory())
2555 for (int i=0; i<(int)m_arListArray.size(); ++i)
2557 FileEntry * entry = GetListEntry(i);
2558 if (entry->status == git_wc_status_unversioned)
2560 if (!ignorelist[j].IsEquivalentTo(entry->GetPath())&&(ignorelist[j].IsAncestorOf(entry->GetPath())))
2562 entry->status = git_wc_status_ignored;
2563 entry->textstatus = git_wc_status_ignored;
2564 if (GetCheck(i))
2565 m_nSelected--;
2566 toremove.push_back(entry->GetPath().GetSVNPathString());
2572 CTSVNPath basepath = m_arStatusArray[m_arListArray[selIndex]]->basepath;
2574 FileEntry * entry = m_arStatusArray[m_arListArray[selIndex]];
2575 if ( entry->status == git_wc_status_unversioned ) // keep "deleted" items
2576 toremove.push_back(entry->GetPath().GetSVNPathString());
2578 if (!m_bIgnoreRemoveOnly)
2580 SVNStatus status;
2581 git_wc_status2_t * s;
2582 CTSVNPath gitPath;
2583 s = status.GetFirstFileStatus(parentfolder, gitPath, false, git_depth_empty);
2584 // first check if the folder isn't already present in the list
2585 bool bFound = false;
2586 nListboxEntries = GetItemCount();
2587 for (int i=0; i<nListboxEntries; ++i)
2589 FileEntry * entry = GetListEntry(i);
2590 if (entry->path.IsEquivalentTo(gitPath))
2592 bFound = true;
2593 break;
2596 if (!bFound)
2598 if (s!=0)
2600 FileEntry * entry = new FileEntry();
2601 entry->path = gitPath;
2602 entry->basepath = basepath;
2603 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
2604 entry->textstatus = s->text_status;
2605 entry->propstatus = s->prop_status;
2606 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
2607 entry->remotetextstatus = s->repos_text_status;
2608 entry->remotepropstatus = s->repos_prop_status;
2609 entry->inunversionedfolder = FALSE;
2610 entry->checked = true;
2611 entry->inexternal = false;
2612 entry->direct = false;
2613 entry->isfolder = true;
2614 entry->last_commit_date = 0;
2615 entry->last_commit_rev = 0;
2616 entry->remoterev = 0;
2617 if (s->entry)
2619 if (s->entry->url)
2621 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
2624 if (s->entry && s->entry->present_props)
2626 entry->present_props = s->entry->present_props;
2628 m_arStatusArray.push_back(entry);
2629 m_arListArray.push_back(m_arStatusArray.size()-1);
2630 AddEntry(entry, langID, GetItemCount());
2635 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
2637 int nListboxEntries = GetItemCount();
2638 for (int i=0; i<nListboxEntries; ++i)
2640 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
2642 RemoveListEntry(i);
2643 break;
2647 SetRedraw(TRUE);
2649 #endif
2650 break;
2651 case IDGITLC_IGNOREMASK:
2653 CString common;
2654 CString ext=filepath->GetFileExtension();
2655 CTGitPathList ignorelist;
2656 FillListOfSelectedItemPaths(ignorelist, true);
2657 SetRedraw(FALSE);
2659 CAppUtils::IgnoreFile(ignorelist,true);
2661 common=ignorelist.GetCommonRoot().GetGitPathString();
2663 for (int i=0; i< GetItemCount(); ++i)
2665 CTGitPath *path=(CTGitPath*)GetItemData(i);
2666 if(!( path->m_Action & CTGitPath::LOGACTIONS_UNVER))
2667 continue;
2668 if( path->GetGitPathString().Left(common.GetLength()) == common )
2670 if (path->GetFileExtension()==ext)
2672 RemoveListEntry(i);
2673 i--; // remove index i at item, new one will replace.
2678 CWnd* pParent = GetParent();
2679 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2681 pParent->SendMessage(GITSLNM_NEEDSREFRESH);
2684 SetRedraw(TRUE);
2686 #if 0
2687 std::set<CTSVNPath> parentlist;
2688 for (int i=0; i<ignorelist.GetCount(); ++i)
2690 parentlist.insert(ignorelist[i].GetContainingDirectory());
2692 std::set<CTSVNPath>::iterator it;
2693 std::vector<CString> toremove;
2695 for (it = parentlist.begin(); it != parentlist.end(); ++it)
2697 CTSVNPath parentFolder = (*it).GetDirectory();
2698 SVNProperties props(parentFolder, SVNRev::REV_WC, false);
2699 CStringA value;
2700 for (int i=0; i<props.GetCount(); i++)
2702 CString propname(props.GetItemName(i).c_str());
2703 if (propname.CompareNoCase(_T("git:ignore"))==0)
2705 stdstring stemp;
2706 // treat values as normal text even if they're not
2707 value = (char *)props.GetItemValue(i).c_str();
2710 if (value.IsEmpty())
2711 value = name;
2712 else
2714 value = value.Trim("\n\r");
2715 value += "\n";
2716 value += name;
2717 value.Remove('\r');
2719 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
2721 CString temp;
2722 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
2723 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2725 else
2727 CTSVNPath basepath;
2728 int nListboxEntries = GetItemCount();
2729 for (int i=0; i<nListboxEntries; ++i)
2731 FileEntry * entry = GetListEntry(i);
2732 ASSERT(entry != NULL);
2733 if (entry == NULL)
2734 continue;
2735 if (basepath.IsEmpty())
2736 basepath = entry->basepath;
2737 // since we ignored files with a mask (e.g. *.exe)
2738 // we have to find find all files in the same
2739 // folder (IsAncestorOf() returns TRUE for _all_ children,
2740 // not just the immediate ones) which match the
2741 // mask and remove them from the list too.
2742 if ((entry->status == git_wc_status_unversioned)&&(parentFolder.IsAncestorOf(entry->path)))
2744 CString f = entry->path.GetSVNPathString();
2745 if (f.Mid(parentFolder.GetSVNPathString().GetLength()).Find('/')<=0)
2747 if (CStringUtils::WildCardMatch(name, f))
2749 if (GetCheck(i))
2750 m_nSelected--;
2751 m_nTotal--;
2752 toremove.push_back(f);
2757 if (!m_bIgnoreRemoveOnly)
2759 SVNStatus status;
2760 git_wc_status2_t * s;
2761 CTSVNPath gitPath;
2762 s = status.GetFirstFileStatus(parentFolder, gitPath, false, git_depth_empty);
2763 if (s!=0)
2765 // first check if the folder isn't already present in the list
2766 bool bFound = false;
2767 for (int i=0; i<nListboxEntries; ++i)
2769 FileEntry * entry = GetListEntry(i);
2770 if (entry->path.IsEquivalentTo(gitPath))
2772 bFound = true;
2773 break;
2776 if (!bFound)
2778 FileEntry * entry = new FileEntry();
2779 entry->path = gitPath;
2780 entry->basepath = basepath;
2781 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
2782 entry->textstatus = s->text_status;
2783 entry->propstatus = s->prop_status;
2784 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
2785 entry->remotetextstatus = s->repos_text_status;
2786 entry->remotepropstatus = s->repos_prop_status;
2787 entry->inunversionedfolder = false;
2788 entry->checked = true;
2789 entry->inexternal = false;
2790 entry->direct = false;
2791 entry->isfolder = true;
2792 entry->last_commit_date = 0;
2793 entry->last_commit_rev = 0;
2794 entry->remoterev = 0;
2795 if (s->entry)
2797 if (s->entry->url)
2799 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
2802 if (s->entry && s->entry->present_props)
2804 entry->present_props = s->entry->present_props;
2806 m_arStatusArray.push_back(entry);
2807 m_arListArray.push_back(m_arStatusArray.size()-1);
2808 AddEntry(entry, langID, GetItemCount());
2814 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
2816 int nListboxEntries = GetItemCount();
2817 for (int i=0; i<nListboxEntries; ++i)
2819 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
2821 RemoveListEntry(i);
2822 break;
2826 SetRedraw(TRUE);
2828 #endif
2829 break;
2831 case IDGITLC_REVERT:
2833 // If at least one item is not in the status "added"
2834 // we ask for a confirmation
2835 BOOL bConfirm = FALSE;
2836 POSITION pos = GetFirstSelectedItemPosition();
2837 int index;
2838 while ((index = GetNextSelectedItem(pos)) >= 0)
2840 //FileEntry * fentry = GetListEntry(index);
2841 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
2842 if(fentry && fentry->m_Action &CTGitPath::LOGACTIONS_MODIFIED )
2844 bConfirm = TRUE;
2845 break;
2849 CString str;
2850 str.Format(IDS_PROC_WARNREVERT,GetSelectedCount());
2852 if (!bConfirm || CMessageBox::Show(this->m_hWnd, str, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION)==IDYES)
2854 CTGitPathList targetList;
2855 FillListOfSelectedItemPaths(targetList);
2857 // make sure that the list is reverse sorted, so that
2858 // children are removed before any parents
2859 targetList.SortByPathname(true);
2861 // put all reverted files in the trashbin, except the ones with 'added'
2862 // status because they are not restored by the revert.
2863 CTGitPathList delList;
2864 POSITION pos = GetFirstSelectedItemPosition();
2865 int index;
2866 while ((index = GetNextSelectedItem(pos)) >= 0)
2868 CTGitPath *entry=(CTGitPath *)GetItemData(index);
2869 if (entry&&(!(entry->m_Action& CTGitPath::LOGACTIONS_ADDED))
2870 && (!(entry->m_Action& CTGitPath::LOGACTIONS_REPLACED)))
2872 CTGitPath fullpath;
2873 fullpath.SetFromWin(g_Git.m_CurrentDir+_T("\\")+entry->GetWinPath());
2874 delList.AddPath(fullpath);
2877 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2878 delList.DeleteAllFiles(true);
2880 CString revertToCommit = _T("HEAD");
2881 if (m_amend)
2882 revertToCommit = _T("HEAD~1");
2883 if (g_Git.Revert(revertToCommit, targetList))
2885 CMessageBox::Show(this->m_hWnd, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR);
2887 else
2889 bool updateStatusList = false;
2890 for(int i=0;i<targetList.GetCount();i++)
2892 int nListboxEntries = GetItemCount();
2893 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2895 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2896 if (path->GetGitPathString()==targetList[i].GetGitPathString())
2898 if(path->m_Action & CTGitPath::LOGACTIONS_ADDED)
2900 path->m_Action = CTGitPath::LOGACTIONS_UNVER;
2901 SetEntryCheck(path,nItem,false);
2902 updateStatusList = true;
2903 SetItemGroup(nItem,1);
2904 this->m_StatusFileList.RemoveItem(*path);
2905 this->m_UnRevFileList.AddPath(*path);
2906 //this->m_IgnoreFileList.RemoveItem(*path);
2909 else
2911 RemoveListEntry(nItem);
2913 break;
2917 SetRedraw(TRUE);
2918 SaveColumnWidths();
2919 Show(m_dwShow, 0, m_bShowFolders,updateStatusList,true);
2920 NotifyCheck();
2924 break;
2926 case IDGITLC_COPY:
2927 CopySelectedEntriesToClipboard(0);
2928 break;
2929 case IDGITLC_COPYEXT:
2930 CopySelectedEntriesToClipboard((DWORD)-1);
2931 break;
2933 case IDGITLC_SAVEAS:
2934 FileSaveAs(filepath);
2935 break;
2937 case IDGITLC_REVERTTOREV:
2938 RevertSelectedItemToVersion();
2939 break;
2940 #if 0
2941 case IDSVNLC_PROPERTIES:
2943 CTSVNPathList targetList;
2944 FillListOfSelectedItemPaths(targetList);
2945 CEditPropertiesDlg dlg;
2946 dlg.SetPathList(targetList);
2947 dlg.DoModal();
2948 if (dlg.HasChanged())
2950 // since the user might have changed/removed/added
2951 // properties recursively, we don't really know
2952 // which items have changed their status.
2953 // So tell the parent to do a refresh.
2954 CWnd* pParent = GetParent();
2955 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2957 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
2961 break;
2962 case IDSVNLC_COMMIT:
2964 CTSVNPathList targetList;
2965 FillListOfSelectedItemPaths(targetList);
2966 CTSVNPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
2967 VERIFY(targetList.WriteToFile(tempFile.GetWinPathString()));
2968 CString commandline = CPathUtils::GetAppDirectory();
2969 commandline += _T("TortoiseProc.exe /command:commit /pathfile:\"");
2970 commandline += tempFile.GetWinPathString();
2971 commandline += _T("\"");
2972 commandline += _T(" /deletepathfile");
2973 CAppUtils::LaunchApplication(commandline, NULL, false);
2975 break;
2977 case IDSVNLC_COMPAREWC:
2979 POSITION pos = GetFirstSelectedItemPosition();
2980 while ( pos )
2982 int index = GetNextSelectedItem(pos);
2983 FileEntry * entry = GetListEntry(index);
2984 ASSERT(entry != NULL);
2985 if (entry == NULL)
2986 continue;
2987 SVNDiff diff(NULL, m_hWnd, true);
2988 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2989 git_revnum_t baseRev = entry->Revision;
2990 diff.DiffFileAgainstBase(
2991 entry->path, baseRev, entry->textstatus, entry->propstatus);
2994 break;
2995 case IDSVNLC_GNUDIFF1:
2997 SVNDiff diff(NULL, this->m_hWnd, true);
2999 if (entry->remotestatus <= git_wc_status_normal)
3000 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
3001 else
3002 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
3004 break;
3005 case IDSVNLC_UPDATE:
3007 CTSVNPathList targetList;
3008 FillListOfSelectedItemPaths(targetList);
3009 bool bAllExist = true;
3010 for (int i=0; i<targetList.GetCount(); ++i)
3012 if (!targetList[i].Exists())
3014 bAllExist = false;
3015 break;
3018 if (bAllExist)
3020 CSVNProgressDlg dlg;
3021 dlg.SetCommand(CSVNProgressDlg::SVNProgress_Update);
3022 dlg.SetPathList(targetList);
3023 dlg.SetRevision(SVNRev::REV_HEAD);
3024 dlg.DoModal();
3026 else
3028 CString sTempFile = CTempFiles::Instance().GetTempFilePath(false).GetWinPathString();
3029 targetList.WriteToFile(sTempFile, false);
3030 CString sCmd;
3031 sCmd.Format(_T("\"%s\" /command:update /rev /pathfile:\"%s\" /deletepathfile"),
3032 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)sTempFile);
3034 CAppUtils::LaunchApplication(sCmd, NULL, false);
3037 break;
3039 case IDSVNLC_REMOVE:
3041 SVN git;
3042 CTSVNPathList itemsToRemove;
3043 FillListOfSelectedItemPaths(itemsToRemove);
3045 // We must sort items before removing, so that files are always removed
3046 // *before* their parents
3047 itemsToRemove.SortByPathname(true);
3049 bool bSuccess = false;
3050 if (git.Remove(itemsToRemove, FALSE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3052 bSuccess = true;
3054 else
3056 if ((git.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE) ||
3057 (git.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))
3059 CString msg, yes, no, yestoall;
3060 msg.Format(IDS_PROC_REMOVEFORCE, (LPCTSTR)git.GetLastErrorMessage());
3061 yes.LoadString(IDS_MSGBOX_YES);
3062 no.LoadString(IDS_MSGBOX_NO);
3063 yestoall.LoadString(IDS_PROC_YESTOALL);
3064 UINT ret = CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_ERROR, yes, no, yestoall);
3065 if ((ret == 1)||(ret==3))
3067 if (!git.Remove(itemsToRemove, TRUE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3069 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3071 else
3072 bSuccess = true;
3075 else
3076 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3078 if (bSuccess)
3080 // The remove went ok, but we now need to run through the selected items again
3081 // and update their status
3082 POSITION pos = GetFirstSelectedItemPosition();
3083 int index;
3084 std::vector<int> entriesToRemove;
3085 while ((index = GetNextSelectedItem(pos)) >= 0)
3087 FileEntry * e = GetListEntry(index);
3088 if (!bShift &&
3089 ((e->textstatus == git_wc_status_unversioned)||
3090 (e->textstatus == git_wc_status_none)||
3091 (e->textstatus == git_wc_status_ignored)))
3093 if (GetCheck(index))
3094 m_nSelected--;
3095 m_nTotal--;
3096 entriesToRemove.push_back(index);
3098 else
3100 e->textstatus = git_wc_status_deleted;
3101 e->status = git_wc_status_deleted;
3102 SetEntryCheck(e,index,true);
3105 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3107 RemoveListEntry(*it);
3110 SaveColumnWidths();
3111 Show(m_dwShow, 0, m_bShowFolders);
3112 NotifyCheck();
3114 break;
3115 case IDSVNLC_DELETE:
3117 CTSVNPathList pathlist;
3118 FillListOfSelectedItemPaths(pathlist);
3119 pathlist.RemoveChildren();
3120 CString filelist;
3121 for (INT_PTR i=0; i<pathlist.GetCount(); ++i)
3123 filelist += pathlist[i].GetWinPathString();
3124 filelist += _T("|");
3126 filelist += _T("|");
3127 int len = filelist.GetLength();
3128 TCHAR * buf = new TCHAR[len+2];
3129 _tcscpy_s(buf, len+2, filelist);
3130 for (int i=0; i<len; ++i)
3131 if (buf[i] == '|')
3132 buf[i] = 0;
3133 SHFILEOPSTRUCT fileop;
3134 fileop.hwnd = this->m_hWnd;
3135 fileop.wFunc = FO_DELETE;
3136 fileop.pFrom = buf;
3137 fileop.pTo = NULL;
3138 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
3139 fileop.lpszProgressTitle = _T("deleting file");
3140 int result = SHFileOperation(&fileop);
3141 delete [] buf;
3143 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
3145 SetRedraw(FALSE);
3146 POSITION pos = NULL;
3147 CTSVNPathList deletedlist; // to store list of deleted folders
3148 while ((pos = GetFirstSelectedItemPosition()) != 0)
3150 int index = GetNextSelectedItem(pos);
3151 if (GetCheck(index))
3152 m_nSelected--;
3153 m_nTotal--;
3154 FileEntry * fentry = GetListEntry(index);
3155 if ((fentry)&&(fentry->isfolder))
3156 deletedlist.AddPath(fentry->path);
3157 RemoveListEntry(index);
3159 // now go through the list of deleted folders
3160 // and remove all their children from the list too!
3161 int nListboxEntries = GetItemCount();
3162 for (int folderindex = 0; folderindex < deletedlist.GetCount(); ++folderindex)
3164 CTSVNPath folderpath = deletedlist[folderindex];
3165 for (int i=0; i<nListboxEntries; ++i)
3167 FileEntry * entry = GetListEntry(i);
3168 if (folderpath.IsAncestorOf(entry->path))
3170 RemoveListEntry(i--);
3171 nListboxEntries--;
3175 SetRedraw(TRUE);
3178 break;
3181 case IDSVNLC_ADD:
3183 SVN git;
3184 CTSVNPathList itemsToAdd;
3185 FillListOfSelectedItemPaths(itemsToAdd);
3187 // We must sort items before adding, so that folders are always added
3188 // *before* any of their children
3189 itemsToAdd.SortByPathname();
3191 ProjectProperties props;
3192 props.ReadPropsPathList(itemsToAdd);
3193 if (git.Add(itemsToAdd, &props, git_depth_empty, TRUE, TRUE, TRUE))
3195 // The add went ok, but we now need to run through the selected items again
3196 // and update their status
3197 POSITION pos = GetFirstSelectedItemPosition();
3198 int index;
3199 while ((index = GetNextSelectedItem(pos)) >= 0)
3201 FileEntry * e = GetListEntry(index);
3202 e->textstatus = git_wc_status_added;
3203 e->propstatus = git_wc_status_none;
3204 e->status = git_wc_status_added;
3205 SetEntryCheck(e,index,true);
3208 else
3210 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3212 SaveColumnWidths();
3213 Show(m_dwShow, 0, m_bShowFolders);
3214 NotifyCheck();
3216 break;
3217 case IDSVNLC_ADD_RECURSIVE:
3219 CTSVNPathList itemsToAdd;
3220 FillListOfSelectedItemPaths(itemsToAdd);
3222 CAddDlg dlg;
3223 dlg.m_pathList = itemsToAdd;
3224 if (dlg.DoModal() == IDOK)
3226 if (dlg.m_pathList.GetCount() == 0)
3227 break;
3228 CSVNProgressDlg progDlg;
3229 progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Add);
3230 progDlg.SetPathList(dlg.m_pathList);
3231 ProjectProperties props;
3232 props.ReadPropsPathList(dlg.m_pathList);
3233 progDlg.SetProjectProperties(props);
3234 progDlg.SetItemCount(dlg.m_pathList.GetCount());
3235 progDlg.DoModal();
3237 // refresh!
3238 CWnd* pParent = GetParent();
3239 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3241 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3245 break;
3247 case IDSVNLC_REPAIRMOVE:
3249 POSITION pos = GetFirstSelectedItemPosition();
3250 int index = GetNextSelectedItem(pos);
3251 FileEntry * entry1 = NULL;
3252 FileEntry * entry2 = NULL;
3253 if (index >= 0)
3255 entry1 = GetListEntry(index);
3256 git_wc_status_kind status1 = git_wc_status_none;
3257 git_wc_status_kind status2 = git_wc_status_none;
3258 if (entry1)
3260 status1 = entry1->status;
3261 index = GetNextSelectedItem(pos);
3262 if (index >= 0)
3264 entry2 = GetListEntry(index);
3265 if (entry2)
3267 status2 = entry2->status;
3268 if (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned)
3270 FileEntry * tempentry = entry1;
3271 entry1 = entry2;
3272 entry2 = tempentry;
3274 // entry1 was renamed to entry2 but outside of Subversion
3275 // fix this by moving entry2 back to entry1 first,
3276 // then do an git-move from entry1 to entry2
3277 if (MoveFile(entry2->GetPath().GetWinPath(), entry1->GetPath().GetWinPath()))
3279 SVN git;
3280 if (!git.Move(CTSVNPathList(entry1->GetPath()), entry2->GetPath(), TRUE))
3282 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3284 else
3286 // check the previously unversioned item
3287 entry1->checked = true;
3288 // fixing the move was successful. We have to adjust the new status of the
3289 // files.
3290 // Since we don't know if the moved/renamed file had local modifications or not,
3291 // we can't guess the new status. That means we have to refresh...
3292 CWnd* pParent = GetParent();
3293 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3295 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3299 else
3301 LPVOID lpMsgBuf;
3302 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
3303 FORMAT_MESSAGE_FROM_SYSTEM |
3304 FORMAT_MESSAGE_IGNORE_INSERTS,
3305 NULL,
3306 GetLastError(),
3307 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
3308 (LPTSTR) &lpMsgBuf,
3310 NULL
3312 MessageBox((LPCTSTR)lpMsgBuf, _T("Error"), MB_OK | MB_ICONINFORMATION );
3313 LocalFree( lpMsgBuf );
3320 break;
3321 case IDSVNLC_REMOVEFROMCS:
3323 CTSVNPathList changelistItems;
3324 FillListOfSelectedItemPaths(changelistItems);
3325 SVN git;
3326 SetRedraw(FALSE);
3327 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
3329 // The changelists were removed, but we now need to run through the selected items again
3330 // and update their changelist
3331 POSITION pos = GetFirstSelectedItemPosition();
3332 int index;
3333 std::vector<int> entriesToRemove;
3334 while ((index = GetNextSelectedItem(pos)) >= 0)
3336 FileEntry * e = GetListEntry(index);
3337 if (e)
3339 e->changelist.Empty();
3340 if (e->status == git_wc_status_normal)
3342 // remove the entry completely
3343 entriesToRemove.push_back(index);
3345 else
3346 SetItemGroup(index, 0);
3349 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3351 RemoveListEntry(*it);
3353 // TODO: Should we go through all entries here and check if we also could
3354 // remove the changelist from m_changelists ?
3356 else
3358 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3360 SetRedraw(TRUE);
3362 break;
3363 case IDSVNLC_CREATEIGNORECS:
3364 CreateChangeList(SVNSLC_IGNORECHANGELIST);
3365 break;
3366 case IDSVNLC_CREATECS:
3368 CCreateChangelistDlg dlg;
3369 if (dlg.DoModal() == IDOK)
3371 CreateChangeList(dlg.m_sName);
3374 break;
3375 default:
3377 if (cmd < IDSVNLC_MOVETOCS)
3378 break;
3379 CTSVNPathList changelistItems;
3380 FillListOfSelectedItemPaths(changelistItems);
3382 // find the changelist name
3383 CString sChangelist;
3384 int cmdID = IDSVNLC_MOVETOCS;
3385 SetRedraw(FALSE);
3386 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
3388 if ((it->first.Compare(SVNSLC_IGNORECHANGELIST))&&(entry->changelist.Compare(it->first)))
3390 if (cmd == cmdID)
3392 sChangelist = it->first;
3394 cmdID++;
3397 if (!sChangelist.IsEmpty())
3399 SVN git;
3400 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
3402 // The changelists were moved, but we now need to run through the selected items again
3403 // and update their changelist
3404 POSITION pos = GetFirstSelectedItemPosition();
3405 int index;
3406 while ((index = GetNextSelectedItem(pos)) >= 0)
3408 FileEntry * e = GetListEntry(index);
3409 e->changelist = sChangelist;
3410 if (!e->IsFolder())
3412 if (m_changelists.find(e->changelist)!=m_changelists.end())
3413 SetItemGroup(index, m_changelists[e->changelist]);
3414 else
3415 SetItemGroup(index, 0);
3419 else
3421 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3424 SetRedraw(TRUE);
3426 break;
3427 #endif
3429 } // switch (cmd)
3430 m_bBlock = FALSE;
3431 AfxGetApp()->DoWaitCursor(-1);
3432 GetStatisticsString();
3433 //int iItemCountAfterMenuCmd = GetItemCount();
3434 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
3436 // CWnd* pParent = GetParent();
3437 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3438 // {
3439 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
3440 // }
3442 } // if (popup.CreatePopupMenu())
3443 } // if (selIndex >= 0)
3447 void CGitStatusListCtrl::OnContextMenuHeader(CWnd * pWnd, CPoint point)
3449 Locker lock(m_critSec);
3450 m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
3453 void CGitStatusListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
3456 if (pWnd == this)
3458 OnContextMenuList(pWnd, point);
3459 } // if (pWnd == this)
3460 else if (pWnd == GetHeaderCtrl())
3462 OnContextMenuHeader(pWnd, point);
3466 void CGitStatusListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
3469 Locker lock(m_critSec);
3470 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
3471 *pResult = 0;
3472 if (m_bBlock)
3473 return;
3475 if (pNMLV->iItem < 0)
3477 if (!IsGroupViewEnabled())
3478 return;
3479 POINT pt;
3480 DWORD ptW = GetMessagePos();
3481 pt.x = GET_X_LPARAM(ptW);
3482 pt.y = GET_Y_LPARAM(ptW);
3483 ScreenToClient(&pt);
3484 int group = GetGroupFromPoint(&pt);
3485 if (group < 0)
3486 return;
3487 // check/uncheck the whole group depending on the check-state
3488 // of the first item in the group
3489 m_bBlock = true;
3490 bool bCheck = false;
3491 bool bFirst = false;
3492 LVITEM lv;
3493 for (int i=0; i<GetItemCount(); ++i)
3495 SecureZeroMemory(&lv, sizeof(LVITEM));
3496 lv.mask = LVIF_GROUPID;
3497 lv.iItem = i;
3498 GetItem(&lv);
3499 if (lv.iGroupId == group)
3501 CTGitPath *entry=(CTGitPath*)GetItemData(i);
3503 if (!bFirst)
3505 bCheck = !GetCheck(i);
3506 bFirst = true;
3508 if (entry)
3510 bool bOldCheck = !!GetCheck(i);
3511 SetEntryCheck(entry, i, bCheck);
3512 if (bCheck != bOldCheck)
3514 if (bCheck)
3515 m_nSelected++;
3516 else
3517 m_nSelected--;
3522 GetStatisticsString();
3523 m_bBlock = false;
3524 NotifyCheck();
3525 return;
3528 CTGitPath *file=(CTGitPath*)GetItemData(pNMLV->iItem);
3530 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER) {
3531 OpenFile(file, OPEN);
3532 return;
3534 if( file->m_Action&CTGitPath::LOGACTIONS_UNMERGED )
3536 CAppUtils::ConflictEdit(*file,false,m_bIsRevertTheirMy);
3539 else
3541 if( (!m_Rev1.IsEmpty()) || (!m_Rev1.IsEmpty())) // m_Rev1 twice???
3542 StartDiffTwo(pNMLV->iItem);
3543 else
3544 StartDiff(pNMLV->iItem);
3548 void CGitStatusListCtrl::StartDiffTwo(int fileindex)
3550 if(fileindex<0)
3551 return;
3553 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3555 CGitDiff::Diff(&file1,&file1,
3556 m_Rev1,
3557 m_Rev2);
3560 void CGitStatusListCtrl::StartDiffWC(int fileindex)
3562 if(fileindex<0)
3563 return;
3565 CString Ver;
3566 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
3567 return;
3569 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3571 CGitDiff::Diff(&file1,&file1, GIT_REV_ZERO, m_CurrentVersion);
3575 void CGitStatusListCtrl::StartDiff(int fileindex)
3577 if(fileindex<0)
3578 return;
3580 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3581 CTGitPath file2;
3582 if(file1.m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
3584 file2.SetFromGit(file1.GetGitOldPathString());
3586 else
3588 file2=file1;
3591 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
3593 CString fromwhere;
3594 if(m_amend && (file1.m_Action & CTGitPath::LOGACTIONS_ADDED) == 0)
3595 fromwhere = _T("~1");
3596 if( g_Git.IsInitRepos())
3597 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
3598 GIT_REV_ZERO);
3599 else if( file1.m_Action&CTGitPath::LOGACTIONS_ADDED )
3600 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
3601 m_CurrentVersion+fromwhere,true);
3602 else if( file1.m_Action&CTGitPath::LOGACTIONS_DELETED )
3603 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
3604 GitRev::GetHead()+fromwhere,false);
3605 else
3606 CGitDiff::Diff(&file1,&file2,
3607 CString(GIT_REV_ZERO),
3608 GitRev::GetHead()+fromwhere);
3610 else
3612 GitRev rev;
3613 CString fromwhere = m_CurrentVersion+_T("~1");
3614 if(m_amend)
3615 fromwhere = m_CurrentVersion+_T("~2");
3616 if(rev.GetCommit(fromwhere) || (file1.m_Action == file1.LOGACTIONS_ADDED))
3618 CGitDiff::DiffNull(&file1,m_CurrentVersion,true);
3621 else if (file1.m_Action == file1.LOGACTIONS_DELETED)
3623 CGitDiff::DiffNull(&file1,fromwhere,false);
3625 else
3627 if( file1.m_ParentNo & MERGE_MASK)
3630 CTGitPath base,theirs, mine;
3632 CTGitPath merge=file1;
3633 CTGitPath directory = merge.GetDirectory();
3635 mine.SetFromGit(CAppUtils::GetMergeTempFile(_T("LOCAL"),merge));
3636 theirs.SetFromGit(CAppUtils::GetMergeTempFile(_T("REMOTE"),merge));
3637 base.SetFromGit(CAppUtils::GetMergeTempFile(_T("BASE"),merge));
3639 CFile tempfile;
3640 //create a empty file, incase stage is not three
3641 tempfile.Open(mine.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
3642 tempfile.Close();
3643 tempfile.Open(theirs.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
3644 tempfile.Close();
3645 tempfile.Open(base.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
3646 tempfile.Close();
3648 merge.SetFromGit(merge.GetGitPathString()+_T("Merged"));
3650 int parent1=-1, parent2 =-1;
3651 for(int i=0;i<this->m_arStatusArray.size();i++)
3653 if(m_arStatusArray[i]->GetGitPathString() == file1.GetGitPathString())
3655 if(m_arStatusArray[i]->m_ParentNo & MERGE_MASK)
3658 else
3660 if(parent1<0)
3662 parent1 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
3664 else if (parent2 <0)
3666 parent2 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
3672 if(g_Git.GetOneFile(m_CurrentVersion, file1, (CString&)merge.GetWinPathString()))
3674 CMessageBox::Show(NULL, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
3677 if(parent1>=0)
3679 CString str;
3680 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent1+1);
3682 if(g_Git.GetOneFile(str, file1, (CString&)mine.GetWinPathString()))
3684 CMessageBox::Show(NULL, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
3688 if(parent2>=0)
3690 CString str;
3691 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent2+1);
3693 if(g_Git.GetOneFile(str, file1, (CString&)theirs.GetWinPathString()))
3695 CMessageBox::Show(NULL, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
3699 if(parent1>=0 && parent2>=0)
3701 CString cmd, output;
3702 cmd.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion, parent1+1,
3703 this->m_CurrentVersion,parent2+1);
3705 if(g_Git.Run(cmd, &output, NULL, CP_ACP))
3708 else
3710 if(g_Git.GetOneFile(output.Left(40), file1, (CString&)base.GetWinPathString()))
3712 CMessageBox::Show(NULL, _T("Fail to get base file"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
3716 CAppUtils::StartExtMerge(base, theirs, mine, merge,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
3719 else
3721 CString str;
3722 if( (file1.m_ParentNo&PARENT_MASK) == 0)
3724 str = _T("~1");
3726 else
3728 str.Format(_T("^%d"), (file1.m_ParentNo&PARENT_MASK)+1);
3730 CGitDiff::Diff(&file1,&file2,
3731 m_CurrentVersion,
3732 m_CurrentVersion+str);
3736 #if 0
3737 if (fileindex < 0)
3738 return;
3739 FileEntry * entry = GetListEntry(fileindex);
3740 ASSERT(entry != NULL);
3741 if (entry == NULL)
3742 return;
3743 if (((entry->status == git_wc_status_normal)&&(entry->remotestatus <= git_wc_status_normal))||
3744 (entry->status == git_wc_status_unversioned)||(entry->status == git_wc_status_none))
3746 int ret = (int)ShellExecute(this->m_hWnd, NULL, entry->path.GetWinPath(), NULL, NULL, SW_SHOW);
3747 if (ret <= HINSTANCE_ERROR)
3749 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
3750 cmd += entry->path.GetWinPathString();
3751 CAppUtils::LaunchApplication(cmd, NULL, false);
3753 return;
3756 GitDiff diff(NULL, m_hWnd, true);
3757 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
3758 diff.DiffWCFile(
3759 entry->path, entry->textstatus, entry->propstatus,
3760 entry->remotetextstatus, entry->remotepropstatus);
3761 #endif
3764 CString CGitStatusListCtrl::GetStatisticsString(bool simple)
3767 CString sNormal, sAdded, sDeleted, sModified, sConflicted, sUnversioned, sRenamed;
3768 WORD langID = (WORD)(DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3769 TCHAR buf[MAX_STATUS_STRING_LENGTH];
3770 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal, buf, _countof(buf), langID);
3771 sNormal = buf;
3772 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added, buf, _countof(buf), langID);
3773 sAdded = buf;
3774 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted, buf, _countof(buf), langID);
3775 sDeleted = buf;
3776 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified, buf, _countof(buf), langID);
3777 sModified = buf;
3778 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted, buf, _countof(buf), langID);
3779 sConflicted = buf;
3780 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned, buf, _countof(buf), langID);
3781 sUnversioned = buf;
3782 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced, buf, _countof(buf), langID);
3783 sRenamed = buf;
3784 CString sToolTip;
3785 if(simple)
3787 sToolTip.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d"),
3788 this->m_nLineAdded,this->m_nLineDeleted,
3789 (LPCTSTR)sModified, m_nModified,
3790 (LPCTSTR)sAdded, m_nAdded,
3791 (LPCTSTR)sDeleted, m_nDeleted,
3792 (LPCTSTR)sRenamed, m_nRenamed
3795 else
3797 sToolTip.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d"),
3798 this->m_nLineAdded,this->m_nLineDeleted,
3799 (LPCTSTR)sNormal, m_nNormal,
3800 (LPCTSTR)sUnversioned, m_nUnversioned,
3801 (LPCTSTR)sModified, m_nModified,
3802 (LPCTSTR)sAdded, m_nAdded,
3803 (LPCTSTR)sDeleted, m_nDeleted,
3804 (LPCTSTR)sConflicted, m_nConflicted
3807 CString sStats;
3808 sStats.Format(IDS_COMMITDLG_STATISTICSFORMAT, m_nSelected, GetItemCount());
3809 if (m_pStatLabel)
3811 m_pStatLabel->SetWindowText(sStats);
3814 if (m_pSelectButton)
3816 if (m_nSelected == 0)
3817 m_pSelectButton->SetCheck(BST_UNCHECKED);
3818 else if (m_nSelected != GetItemCount())
3819 m_pSelectButton->SetCheck(BST_INDETERMINATE);
3820 else
3821 m_pSelectButton->SetCheck(BST_CHECKED);
3824 if (m_pConfirmButton)
3826 m_pConfirmButton->EnableWindow(m_nSelected>0);
3829 return sToolTip;
3834 CString CGitStatusListCtrl::GetCommonDirectory(bool bStrict)
3836 if (!bStrict)
3838 // not strict means that the selected folder has priority
3839 if (!m_StatusFileList.GetCommonDirectory().IsEmpty())
3840 return m_StatusFileList.GetCommonDirectory().GetWinPath();
3843 CTGitPath commonBaseDirectory;
3844 int nListItems = GetItemCount();
3845 for (int i=0; i<nListItems; ++i)
3847 CTGitPath baseDirectory,*p= (CTGitPath*)this->GetItemData(i);
3848 ASSERT(p);
3849 if(p==NULL)
3850 continue;
3851 baseDirectory = p->GetDirectory();
3853 if(commonBaseDirectory.IsEmpty())
3855 commonBaseDirectory = baseDirectory;
3857 else
3859 if (commonBaseDirectory.GetWinPathString().GetLength() > baseDirectory.GetWinPathString().GetLength())
3861 if (baseDirectory.IsAncestorOf(commonBaseDirectory))
3862 commonBaseDirectory = baseDirectory;
3866 return g_Git.m_CurrentDir+CString(_T("\\"))+commonBaseDirectory.GetWinPath();
3870 void CGitStatusListCtrl::SelectAll(bool bSelect, bool /*bIncludeNoCommits*/)
3872 CWaitCursor waitCursor;
3873 // block here so the LVN_ITEMCHANGED messages
3874 // get ignored
3875 m_bBlock = TRUE;
3876 SetRedraw(FALSE);
3878 int nListItems = GetItemCount();
3879 if (bSelect)
3880 m_nSelected = nListItems;
3881 else
3882 m_nSelected = 0;
3884 for (int i=0; i<nListItems; ++i)
3886 //FileEntry * entry = GetListEntry(i);
3887 //ASSERT(entry != NULL);
3888 CTGitPath *path = (CTGitPath *) GetItemData(i);
3889 if (path == NULL)
3890 continue;
3891 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
3892 SetEntryCheck(path,i,bSelect);
3895 // unblock before redrawing
3896 m_bBlock = FALSE;
3897 SetRedraw(TRUE);
3898 GetStatisticsString();
3899 NotifyCheck();
3902 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)
3904 LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);
3905 *pResult = 0;
3906 if (m_bBlock)
3907 return;
3909 CTGitPath *entry=(CTGitPath *)GetItemData(pGetInfoTip->iItem);
3911 if (entry)
3912 if (pGetInfoTip->cchTextMax > entry->GetGitPathString().GetLength() + g_Git.m_CurrentDir.GetLength())
3914 CString str;
3915 str += g_Git.m_CurrentDir;
3916 str += _T("\\");
3917 str += entry->GetWinPathString();
3919 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, str.GetBuffer(), str.GetLength());
3923 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
3925 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
3927 // Take the default processing unless we set this to something else below.
3928 *pResult = CDRF_DODEFAULT;
3930 // First thing - check the draw stage. If it's the control's prepaint
3931 // stage, then tell Windows we want messages for every item.
3933 switch (pLVCD->nmcd.dwDrawStage)
3935 case CDDS_PREPAINT:
3936 *pResult = CDRF_NOTIFYITEMDRAW;
3937 break;
3938 case CDDS_ITEMPREPAINT:
3940 // This is the prepaint stage for an item. Here's where we set the
3941 // item's text color. Our return value will tell Windows to draw the
3942 // item itself, but it will use the new color we set here.
3944 // Tell Windows to paint the control itself.
3945 *pResult = CDRF_DODEFAULT;
3946 if (m_bBlock)
3947 return;
3949 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
3951 if (m_arStatusArray.size() > (DWORD_PTR)pLVCD->nmcd.dwItemSpec)
3954 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3955 CTGitPath *entry=(CTGitPath *)GetItemData((int)pLVCD->nmcd.dwItemSpec);
3956 if (entry == NULL)
3957 return;
3959 // coloring
3960 // ========
3961 // black : unversioned, normal
3962 // purple : added
3963 // blue : modified
3964 // brown : missing, deleted, replaced
3965 // green : merged (or potential merges)
3966 // red : conflicts or sure conflicts
3967 if(entry->m_Action & CTGitPath::LOGACTIONS_GRAY)
3969 crText = RGB(128,128,128);
3972 else if(entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
3974 crText = m_Colors.GetColor(CColors::Conflict);
3977 else if(entry->m_Action & (CTGitPath::LOGACTIONS_MODIFIED))
3979 crText = m_Colors.GetColor(CColors::Modified);
3982 else if(entry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
3984 crText = m_Colors.GetColor(CColors::Added);
3986 else if(entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
3988 crText = m_Colors.GetColor(CColors::DeletedNode);
3990 else if(entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
3992 crText = m_Colors.GetColor(CColors::RenamedNode);
3994 else if(entry->m_Action & CTGitPath::LOGACTIONS_MERGED)
3996 crText = m_Colors.GetColor(CColors::Merged);
3998 else
4000 crText = GetSysColor(COLOR_WINDOWTEXT);
4002 // Store the color back in the NMLVCUSTOMDRAW struct.
4003 pLVCD->clrText = crText;
4006 break;
4010 BOOL CGitStatusListCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
4012 if (pWnd != this)
4013 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
4014 if (!m_bBlock)
4016 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
4017 SetCursor(hCur);
4018 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
4020 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
4021 SetCursor(hCur);
4022 return TRUE;
4025 void CGitStatusListCtrl::RemoveListEntry(int index)
4028 Locker lock(m_critSec);
4029 DeleteItem(index);
4031 m_arStatusArray.erase(m_arStatusArray.begin()+index);
4033 #if 0
4034 delete m_arStatusArray[m_arListArray[index]];
4035 m_arStatusArray.erase(m_arStatusArray.begin()+m_arListArray[index]);
4036 m_arListArray.erase(m_arListArray.begin()+index);
4037 for (int i=index; i< (int)m_arListArray.size(); ++i)
4039 m_arListArray[i]--;
4041 #endif
4044 ///< Set a checkbox on an entry in the listbox
4045 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
4046 void CGitStatusListCtrl::SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck)
4048 pEntry->m_Checked = bCheck;
4049 SetCheck(listboxIndex, bCheck);
4052 #if 0
4053 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck)
4056 int nListItems = GetItemCount();
4057 for (int j=0; j< nListItems ; ++j)
4059 FileEntry * childEntry = GetListEntry(j);
4060 ASSERT(childEntry != NULL);
4061 if (childEntry == NULL || childEntry == parentEntry)
4062 continue;
4063 if (childEntry->checked != bCheck)
4065 if (parentEntry->path.IsAncestorOf(childEntry->path))
4067 SetEntryCheck(childEntry,j,bCheck);
4068 if(bCheck)
4070 m_nSelected++;
4072 else
4074 m_nSelected--;
4081 #endif
4083 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList& pathList)
4086 pathList.Clear();
4087 int nListItems = GetItemCount();
4088 for (int i=0; i< nListItems; i++)
4090 CTGitPath * entry = (CTGitPath*)GetItemData(i);
4091 ASSERT(entry != NULL);
4092 if (entry->m_Checked)
4094 pathList.AddPath(*entry);
4097 pathList.SortByPathname();
4102 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
4103 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList& pathList, bool /*bNoIgnored*/)
4105 pathList.Clear();
4107 POSITION pos = GetFirstSelectedItemPosition();
4108 int index;
4109 while ((index = GetNextSelectedItem(pos)) >= 0)
4111 CTGitPath * entry = (CTGitPath*)GetItemData(index);
4112 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
4113 // continue;
4114 pathList.AddPath(*entry);
4118 UINT CGitStatusListCtrl::OnGetDlgCode()
4120 // we want to process the return key and not have that one
4121 // routed to the default pushbutton
4122 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS;
4125 void CGitStatusListCtrl::OnNMReturn(NMHDR * /*pNMHDR*/, LRESULT *pResult)
4127 *pResult = 0;
4128 if (m_bBlock)
4129 return;
4130 POSITION pos = GetFirstSelectedItemPosition();
4131 while ( pos )
4133 int index = GetNextSelectedItem(pos);
4134 CTGitPath *file=(CTGitPath*)GetItemData(index);
4135 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER)
4137 OpenFile(file, OPEN);
4139 else
4141 StartDiff(index);
4146 void CGitStatusListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
4148 // Since we catch all keystrokes (to have the enter key processed here instead
4149 // of routed to the default pushbutton) we have to make sure that other
4150 // keys like Tab and Esc still do what they're supposed to do
4151 // Tab = change focus to next/previous control
4152 // Esc = quit the dialog
4153 switch (nChar)
4155 case (VK_TAB):
4157 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL, GetKeyState(VK_SHIFT)&0x8000, 0);
4158 return;
4160 break;
4161 case (VK_ESCAPE):
4163 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE, 0, 0);
4165 break;
4168 CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
4171 void CGitStatusListCtrl::PreSubclassWindow()
4173 CListCtrl::PreSubclassWindow();
4174 EnableToolTips(TRUE);
4175 SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);
4178 INT_PTR CGitStatusListCtrl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
4180 int row, col;
4181 RECT cellrect;
4182 row = CellRectFromPoint(point, &cellrect, &col );
4184 if (row == -1)
4185 return -1;
4188 pTI->hwnd = m_hWnd;
4189 pTI->uId = (UINT)((row<<10)+(col&0x3ff)+1);
4190 pTI->lpszText = LPSTR_TEXTCALLBACK;
4192 pTI->rect = cellrect;
4194 return pTI->uId;
4197 int CGitStatusListCtrl::CellRectFromPoint(CPoint& point, RECT *cellrect, int *col) const
4199 int colnum;
4201 // Make sure that the ListView is in LVS_REPORT
4202 if ((GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
4203 return -1;
4205 // Get the top and bottom row visible
4206 int row = GetTopIndex();
4207 int bottom = row + GetCountPerPage();
4208 if (bottom > GetItemCount())
4209 bottom = GetItemCount();
4211 // Get the number of columns
4212 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
4213 int nColumnCount = pHeader->GetItemCount();
4215 // Loop through the visible rows
4216 for ( ;row <=bottom;row++)
4218 // Get bounding rect of item and check whether point falls in it.
4219 CRect rect;
4220 GetItemRect(row, &rect, LVIR_BOUNDS);
4221 if (rect.PtInRect(point))
4223 // Now find the column
4224 for (colnum = 0; colnum < nColumnCount; colnum++)
4226 int colwidth = GetColumnWidth(colnum);
4227 if (point.x >= rect.left && point.x <= (rect.left + colwidth))
4229 RECT rectClient;
4230 GetClientRect(&rectClient);
4231 if (col)
4232 *col = colnum;
4233 rect.right = rect.left + colwidth;
4235 // Make sure that the right extent does not exceed
4236 // the client area
4237 if (rect.right > rectClient.right)
4238 rect.right = rectClient.right;
4239 *cellrect = rect;
4240 return row;
4242 rect.left += colwidth;
4246 return -1;
4249 BOOL CGitStatusListCtrl::OnToolTipText(UINT /*id*/, NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
4251 #if 0
4252 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4253 CString strTipText;
4254 UINT_PTR nID = pNMHDR->idFrom;
4256 if (nID == 0)
4257 return FALSE;
4259 UINT_PTR row = ((nID-1) >> 10) & 0x3fffff;
4260 UINT_PTR col = (nID-1) & 0x3ff;
4262 if (col == 0)
4263 return FALSE; // no custom tooltip for the path, we use the infotip there!
4265 // get the internal column from the visible columns
4266 int internalcol = 0;
4267 UINT_PTR currentcol = 0;
4268 for (; (currentcol != col)
4269 && (internalcol < m_ColumnManager.GetColumnCount()-1)
4270 ; ++internalcol)
4272 if (m_ColumnManager.IsVisible (internalcol))
4273 currentcol++;
4276 AFX_MODULE_THREAD_STATE* pModuleThreadState = AfxGetModuleThreadState();
4277 CToolTipCtrl* pToolTip = pModuleThreadState->m_pToolTip;
4278 pToolTip->SendMessage(TTM_SETMAXTIPWIDTH, 0, 300);
4280 *pResult = 0;
4281 if ((internalcol == 2)||(internalcol == 4))
4283 FileEntry *fentry = GetListEntry(row);
4284 if (fentry)
4286 if (fentry->copied)
4288 CString url;
4289 url.Format(IDS_STATUSLIST_COPYFROM, (LPCTSTR)CPathUtils::PathUnescape(fentry->copyfrom_url), (LONG)fentry->copyfrom_rev);
4290 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4291 return TRUE;
4293 if (fentry->switched)
4295 CString url;
4296 url.Format(IDS_STATUSLIST_SWITCHEDTO, (LPCTSTR)CPathUtils::PathUnescape(fentry->url));
4297 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4298 return TRUE;
4300 if (fentry->keeplocal)
4302 lstrcpyn(pTTTW->szText, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_KEEPLOCAL)), 80);
4303 return TRUE;
4307 #endif
4308 return FALSE;
4311 void CGitStatusListCtrl::OnPaint()
4313 Default();
4314 if ((m_bBusy)||(m_bEmpty))
4316 CString str;
4317 if (m_bBusy)
4319 if (m_sBusy.IsEmpty())
4320 str.LoadString(IDS_STATUSLIST_BUSYMSG);
4321 else
4322 str = m_sBusy;
4324 else
4326 if (m_sEmpty.IsEmpty())
4327 str.LoadString(IDS_STATUSLIST_EMPTYMSG);
4328 else
4329 str = m_sEmpty;
4331 COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
4332 COLORREF clrTextBk;
4333 if (IsWindowEnabled())
4334 clrTextBk = ::GetSysColor(COLOR_WINDOW);
4335 else
4336 clrTextBk = ::GetSysColor(COLOR_3DFACE);
4338 CRect rc;
4339 GetClientRect(&rc);
4340 CHeaderCtrl* pHC;
4341 pHC = GetHeaderCtrl();
4342 if (pHC != NULL)
4344 CRect rcH;
4345 pHC->GetItemRect(0, &rcH);
4346 rc.top += rcH.bottom;
4348 CDC* pDC = GetDC();
4350 CMyMemDC memDC(pDC, &rc);
4352 memDC.SetTextColor(clrText);
4353 memDC.SetBkColor(clrTextBk);
4354 memDC.FillSolidRect(rc, clrTextBk);
4355 rc.top += 10;
4356 CGdiObject * oldfont = memDC.SelectStockObject(DEFAULT_GUI_FONT);
4357 memDC.DrawText(str, rc, DT_CENTER | DT_VCENTER |
4358 DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
4359 memDC.SelectObject(oldfont);
4361 ReleaseDC(pDC);
4365 // prevent users from extending our hidden (size 0) columns
4366 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
4368 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
4371 // prevent any function from extending our hidden (size 0) columns
4372 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
4374 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
4375 Default();
4378 void CGitStatusListCtrl::OnDestroy()
4380 SaveColumnWidths(true);
4381 CListCtrl::OnDestroy();
4384 void CGitStatusListCtrl::OnBeginDrag(NMHDR* /*pNMHDR*/, LRESULT* pResult)
4386 #if 0
4387 Locker lock(m_critSec);
4388 CDropFiles dropFiles; // class for creating DROPFILES struct
4390 int index;
4391 POSITION pos = GetFirstSelectedItemPosition();
4392 while ( (index = GetNextSelectedItem(pos)) >= 0 )
4394 FileEntry * fentry = m_arStatusArray[m_arListArray[index]];
4395 CTGitPath path = fentry->GetPath();
4396 dropFiles.AddFile( path.GetWinPathString() );
4399 if ( dropFiles.GetCount()>0 )
4401 m_bOwnDrag = true;
4402 dropFiles.CreateStructure();
4403 m_bOwnDrag = false;
4405 #endif
4406 *pResult = 0;
4409 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry /* = false */)
4411 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
4412 for (int col = 0; col <= maxcol; col++)
4413 if (m_ColumnManager.IsVisible (col))
4414 m_ColumnManager.ColumnResized (col);
4416 if (bSaveToRegistry)
4417 m_ColumnManager.WriteSettings();
4420 bool CGitStatusListCtrl::EnableFileDrop()
4422 m_bFileDropsEnabled = true;
4423 return true;
4426 bool CGitStatusListCtrl::HasPath(const CTGitPath& path)
4428 for (size_t i=0; i < m_arStatusArray.size(); i++)
4430 if (m_arStatusArray[i]->IsEquivalentTo(path))
4431 return true;
4434 return false;
4437 BOOL CGitStatusListCtrl::PreTranslateMessage(MSG* pMsg)
4439 if (pMsg->message == WM_KEYDOWN)
4441 switch (pMsg->wParam)
4443 case 'A':
4445 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4447 // select all entries
4448 for (int i=0; i<GetItemCount(); ++i)
4450 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
4452 return TRUE;
4455 break;
4456 case 'C':
4457 case VK_INSERT:
4459 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4461 // copy all selected paths to the clipboard
4462 if (GetAsyncKeyState(VK_SHIFT)&0x8000)
4463 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS);
4464 else
4465 CopySelectedEntriesToClipboard(0);
4466 return TRUE;
4469 break;
4473 return CListCtrl::PreTranslateMessage(pMsg);
4476 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols)
4479 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
4480 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
4481 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4483 CString sClipboard;
4484 CString temp;
4485 //TCHAR buf[100];
4486 if (GetSelectedCount() == 0)
4487 return false;
4489 // first add the column titles as the first line
4490 // We needn't head when only path copy
4491 //temp.LoadString(IDS_STATUSLIST_COLFILE);
4492 //sClipboard = temp;
4494 DWORD selection = 0;
4495 for (int i = 0, count = m_ColumnManager.GetColumnCount(); i < count; ++i)
4496 if ( ((dwCols == -1) && m_ColumnManager.IsVisible (i))
4497 || ((dwCols != 1) && (i < 32) && ((dwCols & (1 << i)) != 0)))
4499 sClipboard += _T("\t") + m_ColumnManager.GetName(i);
4501 if (i < 32)
4502 selection += 1 << i;
4505 if(dwCols)
4506 sClipboard += _T("\r\n");
4508 POSITION pos = GetFirstSelectedItemPosition();
4509 int index;
4510 while ((index = GetNextSelectedItem(pos)) >= 0)
4512 CTGitPath * entry = (CTGitPath*)GetItemData(index);
4513 if(entry == NULL)
4514 continue;
4516 sClipboard += entry->GetWinPathString();
4517 if (selection & GITSLC_COLFILENAME)
4519 sClipboard += _T("\t")+entry->GetFileOrDirectoryName();
4521 if (selection & GITSLC_COLEXT)
4523 sClipboard += _T("\t")+entry->GetFileExtension();
4526 if (selection & GITSLC_COLSTATUS)
4528 #if 0
4529 if (entry->isNested)
4531 temp.LoadString(IDS_STATUSLIST_NESTED);
4533 else
4535 GitStatus::GetStatusString(hResourceHandle, entry->status, buf, _countof(buf), (WORD)langID);
4536 if ((entry->copied)&&(_tcslen(buf)>1))
4537 _tcscat_s(buf, 100, _T(" (+)"));
4538 if ((entry->switched)&&(_tcslen(buf)>1))
4539 _tcscat_s(buf, 100, _T(" (s)"));
4540 if ((entry->status == entry->propstatus)&&
4541 (entry->status != git_wc_status_normal)&&
4542 (entry->status != git_wc_status_unversioned)&&
4543 (!GitStatus::IsImportant(entry->textstatus)))
4544 _tcscat_s(buf, 100, ponly);
4545 temp = buf;
4547 #endif
4548 sClipboard += _T("\t")+entry->GetActionName();
4550 #if 0
4551 if (selection & SVNSLC_COLTEXTSTATUS)
4554 if (entry->isNested)
4556 temp.LoadString(IDS_STATUSLIST_NESTED);
4558 else
4560 GitStatus::GetStatusString(hResourceHandle, entry->textstatus, buf, _countof(buf), (WORD)langID);
4561 if ((entry->copied)&&(_tcslen(buf)>1))
4562 _tcscat_s(buf, 100, _T(" (+)"));
4563 if ((entry->switched)&&(_tcslen(buf)>1))
4564 _tcscat_s(buf, 100, _T(" (s)"));
4565 temp = buf;
4567 sClipboard += _T("\t")+temp;
4569 #endif
4570 #if 0
4571 if (selection & SVNSLC_COLREMOTESTATUS)
4573 if (entry->isNested)
4575 temp.LoadString(IDS_STATUSLIST_NESTED);
4577 else
4579 GitStatus::GetStatusString(hResourceHandle, entry->remotestatus, buf, _countof(buf), (WORD)langID);
4580 if ((entry->copied)&&(_tcslen(buf)>1))
4581 _tcscat_s(buf, 100, _T(" (+)"));
4582 if ((entry->switched)&&(_tcslen(buf)>1))
4583 _tcscat_s(buf, 100, _T(" (s)"));
4584 if ((entry->remotestatus == entry->remotepropstatus)&&
4585 (entry->remotestatus != git_wc_status_none)&&
4586 (entry->remotestatus != git_wc_status_normal)&&
4587 (entry->remotestatus != git_wc_status_unversioned)&&
4588 (!SVNStatus::IsImportant(entry->remotetextstatus)))
4589 _tcscat_s(buf, 100, ponly);
4590 temp = buf;
4592 sClipboard += _T("\t")+temp;
4594 if (selection & GitSLC_COLPROPSTATUS)
4596 if (entry->isNested)
4598 temp.Empty();
4600 else
4602 GitStatus::GetStatusString(hResourceHandle, entry->propstatus, buf, _countof(buf), (WORD)langID);
4603 if ((entry->copied)&&(_tcslen(buf)>1))
4604 _tcscat_s(buf, 100, _T(" (+)"));
4605 if ((entry->switched)&&(_tcslen(buf)>1))
4606 _tcscat_s(buf, 100, _T(" (s)"));
4607 temp = buf;
4609 sClipboard += _T("\t")+temp;
4611 if (selection & SVNSLC_COLREMOTETEXT)
4613 if (entry->isNested)
4615 temp.Empty();
4617 else
4619 GitStatus::GetStatusString(hResourceHandle, entry->remotetextstatus, buf, _countof(buf), (WORD)langID);
4620 temp = buf;
4622 sClipboard += _T("\t")+temp;
4624 if (selection & SVNSLC_COLREMOTEPROP)
4626 // SVNSLC_COLREMOTEPROP
4627 if (entry->isNested)
4629 temp.Empty();
4631 else
4633 GitStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, _countof(buf), (WORD)langID);
4634 temp = buf;
4636 sClipboard += _T("\t")+temp;
4638 if (selection & SVNSLC_COLURL)
4639 sClipboard += _T("\t")+entry->url;
4640 if (selection & SVNSLC_COLLOCK)
4642 if (!m_HeadRev.IsHead())
4644 // we have contacted the repository
4646 // decision-matrix
4647 // wc repository text
4648 // "" "" ""
4649 // "" UID1 owner
4650 // UID1 UID1 owner
4651 // UID1 "" lock has been broken
4652 // UID1 UID2 lock has been stolen
4653 if (entry->lock_token.IsEmpty() || (entry->lock_token.Compare(entry->lock_remotetoken)==0))
4655 if (entry->lock_owner.IsEmpty())
4656 temp = entry->lock_remoteowner;
4657 else
4658 temp = entry->lock_owner;
4660 else if (entry->lock_remotetoken.IsEmpty())
4662 // broken lock
4663 temp.LoadString(IDS_STATUSLIST_LOCKBROKEN);
4665 else
4667 // stolen lock
4668 temp.Format(IDS_STATUSLIST_LOCKSTOLEN, (LPCTSTR)entry->lock_remoteowner);
4671 else
4672 temp = entry->lock_owner;
4673 sClipboard += _T("\t")+temp;
4675 if (selection & SVNSLC_COLLOCKCOMMENT)
4676 sClipboard += _T("\t")+entry->lock_comment;
4677 if (selection & SVNSLC_COLAUTHOR)
4678 sClipboard += _T("\t")+entry->last_commit_author;
4679 if (selection & SVNSLC_COLREVISION)
4681 temp.Format(_T("%ld"), entry->last_commit_rev);
4682 if (entry->last_commit_rev == 0)
4683 temp.Empty();
4684 sClipboard += _T("\t")+temp;
4686 if (selection & SVNSLC_COLREMOTEREVISION)
4688 temp.Format(_T("%ld"), entry->remoterev);
4689 if (entry->remoterev == 0)
4690 temp.Empty();
4691 sClipboard += _T("\t")+temp;
4694 if (selection & SVNSLC_COLDATE)
4696 TCHAR datebuf[SVN_DATE_BUFFER];
4697 apr_time_t date = entry->last_commit_date;
4698 SVN::formatDate(datebuf, date, true);
4699 if (date)
4700 temp = datebuf;
4701 else
4702 temp.Empty();
4703 sClipboard += _T("\t")+temp;
4705 if (selection & SVNSLC_COLCOPYFROM)
4707 if (m_sURL.Compare(entry->copyfrom_url.Left(m_sURL.GetLength()))==0)
4708 temp = entry->copyfrom_url.Mid(m_sURL.GetLength());
4709 else
4710 temp = entry->copyfrom_url;
4711 sClipboard += _T("\t")+temp;
4714 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
4715 ; i < count
4716 ; ++i)
4718 if ((dwCols == -1) && m_ColumnManager.IsVisible (i))
4720 CString value
4721 = entry->present_props[m_ColumnManager.GetName(i)];
4722 sClipboard += _T("\t") + value;
4725 #endif
4726 if (selection & GITSLC_COLADD)
4728 sClipboard += _T("\t")+entry->m_StatAdd;
4730 if (selection & GITSLC_COLDEL)
4732 sClipboard += _T("\t")+entry->m_StatDel;
4735 sClipboard += _T("\r\n");
4738 return CStringUtils::WriteAsciiStringToClipboard(sClipboard);
4740 return TRUE;
4744 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
4746 #if 0
4747 std::set<CString> changelists;
4748 POSITION pos = GetFirstSelectedItemPosition();
4749 int index;
4750 while ((index = GetNextSelectedItem(pos)) >= 0)
4752 FileEntry * entry = GetListEntry(index);
4753 if (!entry->changelist.IsEmpty())
4754 changelists.insert(entry->changelist);
4756 return changelists.size();
4757 #endif
4758 return 0;
4761 bool CGitStatusListCtrl::PrepareGroups(bool bForce /* = false */)
4764 bool bHasGroups=false;
4765 int max =0;
4767 for(int i=0;i< this->m_arStatusArray.size(); i++)
4769 int ParentNo = m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
4770 if( ParentNo > max)
4771 max=m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
4774 if ( this->m_UnRevFileList.GetCount()>0 ||
4775 this->m_IgnoreFileList.GetCount()>0 ||
4776 max>0 || bForce)
4778 bHasGroups = true;
4781 RemoveAllGroups();
4782 EnableGroupView(bHasGroups);
4784 TCHAR groupname[1024];
4785 int groupindex = 0;
4787 if(bHasGroups)
4789 LVGROUP grp = {0};
4790 grp.cbSize = sizeof(LVGROUP);
4791 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4792 groupindex=0;
4794 //if(m_UnRevFileList.GetCount()>0)
4795 if(max >0)
4797 grp.pszHeader = _T("Merged Files");
4798 grp.iGroupId = MERGE_MASK;
4799 grp.uAlign = LVGA_HEADER_LEFT;
4800 InsertGroup(0, &grp);
4802 for(int i=0;i<=max;i++)
4804 CString str;
4805 str.Format(_T("Diff with parent %d"), i+1);
4806 //_tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Not Versioned"), 1023);
4807 grp.pszHeader = str.GetBuffer();
4808 grp.iGroupId = i;
4809 grp.uAlign = LVGA_HEADER_LEFT;
4810 InsertGroup(i+1, &grp);
4813 else
4815 CString sUnassignedName(_T("Modified File"));
4816 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
4817 grp.pszHeader = groupname;
4818 grp.iGroupId = groupindex;
4819 grp.uAlign = LVGA_HEADER_LEFT;
4820 InsertGroup(groupindex++, &grp);
4824 _tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Not Versioned"), 1023);
4825 grp.pszHeader = groupname;
4826 grp.iGroupId = groupindex;
4827 grp.uAlign = LVGA_HEADER_LEFT;
4828 InsertGroup(groupindex++, &grp);
4831 //if(m_IgnoreFileList.GetCount()>0)
4833 _tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Ignored"), 1023);
4834 grp.pszHeader = groupname;
4835 grp.iGroupId = groupindex;
4836 grp.uAlign = LVGA_HEADER_LEFT;
4837 InsertGroup(groupindex++, &grp);
4842 #if 0
4843 m_bHasIgnoreGroup = false;
4845 // now add the items which don't belong to a group
4846 LVGROUP grp = {0};
4847 grp.cbSize = sizeof(LVGROUP);
4848 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4849 CString sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET));
4850 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
4851 grp.pszHeader = groupname;
4852 grp.iGroupId = groupindex;
4853 grp.uAlign = LVGA_HEADER_LEFT;
4854 InsertGroup(groupindex++, &grp);
4856 for (std::map<CString,int>::iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
4858 if (it->first.Compare(SVNSLC_IGNORECHANGELIST)!=0)
4860 LVGROUP grp = {0};
4861 grp.cbSize = sizeof(LVGROUP);
4862 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4863 _tcsncpy_s(groupname, 1024, it->first, 1023);
4864 grp.pszHeader = groupname;
4865 grp.iGroupId = groupindex;
4866 grp.uAlign = LVGA_HEADER_LEFT;
4867 it->second = InsertGroup(groupindex++, &grp);
4869 else
4870 m_bHasIgnoreGroup = true;
4873 if (m_bHasIgnoreGroup)
4875 // and now add the group 'ignore-on-commit'
4876 std::map<CString,int>::iterator it = m_changelists.find(SVNSLC_IGNORECHANGELIST);
4877 if (it != m_changelists.end())
4879 grp.cbSize = sizeof(LVGROUP);
4880 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4881 _tcsncpy_s(groupname, 1024, SVNSLC_IGNORECHANGELIST, 1023);
4882 grp.pszHeader = groupname;
4883 grp.iGroupId = groupindex;
4884 grp.uAlign = LVGA_HEADER_LEFT;
4885 it->second = InsertGroup(groupindex, &grp);
4888 #endif
4889 return bHasGroups;
4892 void CGitStatusListCtrl::NotifyCheck()
4894 CWnd* pParent = GetParent();
4895 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
4897 pParent->SendMessage(GITSLNM_CHECKCHANGED, m_nSelected);
4901 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash,CTGitPathList *list)
4903 BYTE_VECTOR out;
4904 this->m_bBusy=TRUE;
4905 m_CurrentVersion=hash;
4907 int count = 0;
4908 if(list == NULL)
4909 count = 1;
4910 else
4911 count = list->GetCount();
4913 CString head = _T("HEAD");
4914 if(m_amend)
4915 head = _T("HEAD~1");
4917 if(hash == GIT_REV_ZERO)
4919 for(int i=0;i<count;i++)
4921 BYTE_VECTOR cmdout;
4922 cmdout.clear();
4923 CString cmd;
4924 if(!g_Git.IsInitRepos())
4926 // also list staged files which will be in the commit
4927 cmd=(_T("git.exe diff-index --cached --raw ") + head + _T(" --numstat -C -M -z"));
4928 g_Git.Run(cmd, &cmdout);
4930 if(list == NULL)
4931 cmd=(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z"));
4932 else
4933 cmd.Format(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
4935 BYTE_VECTOR cmdErr;
4936 if(g_Git.Run(cmd, &cmdout, &cmdErr))
4938 int last = cmdErr.RevertFind(0,-1);
4939 if(last > 0)
4941 CString str;
4942 g_Git.StringAppend(&str, &cmdErr[last+1], CP_ACP, cmdErr.size() - last -1);
4943 CMessageBox::Show(NULL,str, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
4945 else
4947 cmdout.clear();
4948 CString strout, err;
4949 if (g_Git.Run(_T("git.exe rev-parse --revs-only ") + head, &strout, &err, CP_UTF8))
4951 CMessageBox::Show(NULL, strout + L"\n" + err, _T("TortoiseGit"), MB_OK);
4952 return -1;
4954 if(strout.IsEmpty() && err.IsEmpty())
4955 break; //this is initial repository, there are no any history
4957 CMessageBox::Show(NULL, strout + L"\n" + err, _T("TortoiseGit"), MB_OK);
4958 return -1;
4962 out.append(cmdout, 0);
4964 else // Init Repository
4966 //We will list all added file for init repository because commit will comit these
4967 //if(list == NULL)
4968 cmd=_T("git.exe ls-files -s -t -z");
4969 //else
4970 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
4972 g_Git.Run(cmd, &cmdout);
4973 //out+=cmdout;
4974 out.append(cmdout,0);
4978 if(g_Git.IsInitRepos())
4980 m_StatusFileList.ParserFromLsFile(out);
4981 for(int i=0;i<m_StatusFileList.GetCount();i++)
4982 ((CTGitPath&)(m_StatusFileList[i])).m_Action=CTGitPath::LOGACTIONS_ADDED;
4984 else
4985 this->m_StatusFileList.ParserFromLog(out);
4987 //handle delete conflict case, when remote : modified, local : deleted.
4988 for(int i=0;i<count;i++)
4990 BYTE_VECTOR cmdout;
4991 CString cmd;
4993 if(list == NULL)
4994 cmd=_T("git.exe ls-files -u -t -z");
4995 else
4996 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list)[i].GetGitPathString());
4998 g_Git.Run(cmd, &cmdout);
5000 CTGitPathList conflictlist;
5001 conflictlist.ParserFromLog(cmdout);
5002 for(int i=0;i<conflictlist.GetCount();i++)
5004 CTGitPath *p=m_StatusFileList.LookForGitPath(conflictlist[i].GetGitPathString());
5005 if(p)
5006 p->m_Action|=CTGitPath::LOGACTIONS_UNMERGED;
5007 else
5008 m_StatusFileList.AddPath(conflictlist[i]);
5012 // handle source files of file renames/moves (issue #860)
5013 // if a file gets renamed and the new file "git add"ed, diff-index doesn't list the source file anymore
5014 for(int i = 0; i < count; i++)
5016 BYTE_VECTOR cmdout;
5017 CString cmd;
5019 if(list == NULL)
5020 cmd = _T("git.exe ls-files -d -z");
5021 else
5022 cmd.Format(_T("git.exe ls-files -d -z -- \"%s\""),(*list)[i].GetGitPathString());
5024 g_Git.Run(cmd, &cmdout);
5026 CTGitPathList deletelist;
5027 deletelist.ParserFromLog(cmdout, true);
5028 for(int i = 0; i < deletelist.GetCount(); i++)
5030 CTGitPath *p = m_StatusFileList.LookForGitPath(deletelist[i].GetGitPathString());
5031 if(!p)
5032 m_StatusFileList.AddPath(deletelist[i]);
5036 else
5038 int count = 0;
5039 if(list == NULL)
5040 count = 1;
5041 else
5042 count = list->GetCount();
5044 for(int i=0;i<count;i++)
5046 BYTE_VECTOR cmdout;
5047 CString cmd;
5048 if(list == NULL)
5049 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash);
5050 else
5051 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash,(*list)[i].GetGitPathString());
5053 g_Git.Run(cmd, &cmdout, NULL);
5055 out.append(cmdout);
5057 this->m_StatusFileList.ParserFromLog(out);
5061 for(int i=0;i<m_StatusFileList.GetCount();i++)
5063 CTGitPath * gitpatch=(CTGitPath*)&m_StatusFileList[i];
5064 gitpatch->m_Checked = TRUE;
5065 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
5068 this->m_bBusy=FALSE;
5069 return 0;
5072 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList &list)
5074 m_arStatusArray.clear();
5075 for(int i=0;i<list.GetCount();i++)
5077 CTGitPath * gitpath=(CTGitPath*)&list[i];
5079 if(gitpath ->m_Action & CTGitPath::LOGACTIONS_HIDE)
5080 continue;
5082 gitpath->m_Checked = TRUE;
5083 m_arStatusArray.push_back((CTGitPath*)&list[i]);
5085 return 0;
5088 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList *List)
5090 this->m_UnRevFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER,List);
5091 for(int i=0;i<m_UnRevFileList.GetCount();i++)
5093 CTGitPath * gitpatch=(CTGitPath*)&m_UnRevFileList[i];
5094 gitpatch->m_Checked = FALSE;
5095 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
5097 return 0;
5100 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList *List)
5102 this->m_IgnoreFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER|CTGitPath::LOGACTIONS_IGNORE,List);
5103 for(int i=0;i<m_IgnoreFileList.GetCount();i++)
5105 CTGitPath * gitpatch=(CTGitPath*)&m_IgnoreFileList[i];
5106 gitpatch->m_Checked = FALSE;
5107 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
5109 return 0;
5111 int CGitStatusListCtrl::UpdateFileList(int mask,bool once,CTGitPathList *List)
5113 if(mask&CGitStatusListCtrl::FILELIST_MODIFY)
5115 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_MODIFY)))
5117 UpdateFileList(git_revnum_t(GIT_REV_ZERO),List);
5118 m_FileLoaded|=CGitStatusListCtrl::FILELIST_MODIFY;
5121 if(mask&CGitStatusListCtrl::FILELIST_UNVER)
5123 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_UNVER)))
5125 UpdateUnRevFileList(List);
5126 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
5128 if(mask&CGitStatusListCtrl::FILELIST_IGNORE && (once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_IGNORE))))
5130 UpdateIgnoreFileList(List);
5131 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
5134 return 0;
5137 void CGitStatusListCtrl::Clear()
5139 m_FileLoaded=0;
5140 this->DeleteAllItems();
5141 this->m_arListArray.clear();
5142 this->m_arStatusArray.clear();
5143 this->m_changelists.clear();
5145 //////////////////////////////////////////////////////////////////////////
5146 #if 0
5147 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD * /*pdwEffect*/, POINTL pt)
5149 if(pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
5151 HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
5152 if(hDrop != NULL)
5154 TCHAR szFileName[MAX_PATH];
5156 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
5158 POINT clientpoint;
5159 clientpoint.x = pt.x;
5160 clientpoint.y = pt.y;
5161 ScreenToClient(m_hTargetWnd, &clientpoint);
5162 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5164 CTSVNPathList changelistItems;
5165 for(UINT i = 0; i < cFiles; ++i)
5167 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5168 changelistItems.AddPath(CTSVNPath(szFileName));
5170 // find the changelist name
5171 CString sChangelist;
5172 LONG_PTR nGroup = m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint);
5173 for (std::map<CString, int>::iterator it = m_pSVNStatusListCtrl->m_changelists.begin(); it != m_pSVNStatusListCtrl->m_changelists.end(); ++it)
5174 if (it->second == nGroup)
5175 sChangelist = it->first;
5176 if (!sChangelist.IsEmpty())
5178 SVN git;
5179 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
5181 for (int l=0; l<changelistItems.GetCount(); ++l)
5183 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5184 if (index >= 0)
5186 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5187 if (e)
5189 e->changelist = sChangelist;
5190 if (!e->IsFolder())
5192 if (m_pSVNStatusListCtrl->m_changelists.find(e->changelist)!=m_pSVNStatusListCtrl->m_changelists.end())
5193 m_pSVNStatusListCtrl->SetItemGroup(index, m_pSVNStatusListCtrl->m_changelists[e->changelist]);
5194 else
5195 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5199 else
5201 HWND hParentWnd = GetParent(m_hTargetWnd);
5202 if (hParentWnd != NULL)
5203 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5207 else
5209 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
5212 else
5214 SVN git;
5215 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
5217 for (int l=0; l<changelistItems.GetCount(); ++l)
5219 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5220 if (index >= 0)
5222 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5223 if (e)
5225 e->changelist = sChangelist;
5226 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5229 else
5231 HWND hParentWnd = GetParent(m_hTargetWnd);
5232 if (hParentWnd != NULL)
5233 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5237 else
5239 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
5243 else
5245 for(UINT i = 0; i < cFiles; ++i)
5247 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5248 HWND hParentWnd = GetParent(m_hTargetWnd);
5249 if (hParentWnd != NULL)
5250 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)szFileName);
5254 GlobalUnlock(medium.hGlobal);
5256 return true; //let base free the medium
5258 HRESULT STDMETHODCALLTYPE CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)
5260 CIDropTarget::DragOver(grfKeyState, pt, pdwEffect);
5261 *pdwEffect = DROPEFFECT_COPY;
5262 if (m_pSVNStatusListCtrl)
5264 POINT clientpoint;
5265 clientpoint.x = pt.x;
5266 clientpoint.y = pt.y;
5267 ScreenToClient(m_hTargetWnd, &clientpoint);
5268 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5270 *pdwEffect = DROPEFFECT_MOVE;
5272 else if ((!m_pSVNStatusListCtrl->m_bFileDropsEnabled)||(m_pSVNStatusListCtrl->m_bOwnDrag))
5274 *pdwEffect = DROPEFFECT_NONE;
5277 return S_OK;
5280 #endif
5282 void CGitStatusListCtrl::FileSaveAs(CTGitPath *path)
5284 CString filename;
5285 filename.Format(_T("%s-%s%s"),path->GetBaseFilename(),this->m_CurrentVersion.Left(6),path->GetFileExtension());
5286 CFileDialog dlg(FALSE,NULL,
5287 filename,
5288 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
5289 NULL);
5290 CString currentpath;
5291 currentpath=g_Git.m_CurrentDir+_T("\\");
5292 currentpath+=path->GetWinPathString();
5294 dlg.m_ofn.lpstrInitialDir=currentpath.GetBuffer();
5296 CString cmd,out;
5297 if(dlg.DoModal()==IDOK)
5299 filename = dlg.GetPathName();
5300 if(m_CurrentVersion == GIT_REV_ZERO)
5302 if(!CopyFile(g_Git.m_CurrentDir +_T("\\") + path->GetWinPath(),filename,false))
5304 LPVOID lpMsgBuf=NULL;
5305 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
5306 NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
5307 (LPTSTR)&lpMsgBuf,
5308 0,NULL);
5309 CMessageBox::Show(NULL,(TCHAR *)lpMsgBuf,_T("TortoiseGit"),MB_OK);
5310 LocalFree(lpMsgBuf);
5311 return;
5315 else
5317 if(g_Git.GetOneFile(m_CurrentVersion,*path,filename))
5319 out.Format(_T("Fail checkout one file %s;%s"),m_CurrentVersion, path->GetWinPath());
5320 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5321 return;
5328 int CGitStatusListCtrl::RevertSelectedItemToVersion()
5330 if(this->m_CurrentVersion.IsEmpty())
5331 return 0;
5332 if(this->m_CurrentVersion == GIT_REV_ZERO)
5333 return 0;
5335 POSITION pos = GetFirstSelectedItemPosition();
5336 int index;
5337 CString cmd,out;
5338 int count =0;
5339 while ((index = GetNextSelectedItem(pos)) >= 0)
5341 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
5342 cmd.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion,fentry->GetGitPathString());
5343 out.Empty();
5344 if(g_Git.Run(cmd,&out,CP_ACP))
5346 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5348 count++;
5351 out.Format(_T("%d files revert to %s"),count,m_CurrentVersion.Left(6));
5352 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5353 return 0;
5356 void CGitStatusListCtrl::OpenFile(CTGitPath*filepath,int mode)
5358 CString file;
5359 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
5361 file= filepath->GetWinPath();
5363 else
5365 CString temppath;
5366 GetTempPath(temppath);
5367 file.Format(_T("%s%s_%s%s"),
5368 temppath,
5369 filepath->GetBaseFilename(),
5370 m_CurrentVersion.Left(6),
5371 filepath->GetFileExtension());
5372 CString cmd,out;
5373 if(g_Git.GetOneFile(m_CurrentVersion, *filepath, file))
5375 out.Format(_T("Fail checkout file %s to %s\n"), filepath->GetGitPathString(), file);
5376 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5377 return;
5381 if(mode == ALTERNATIVEEDITOR)
5383 CAppUtils::LaunchAlternativeEditor(file);
5384 return;
5386 int ret = HINSTANCE_ERROR;
5388 if(mode == OPEN )
5390 ret = (int)ShellExecute(this->m_hWnd, NULL,file, NULL, NULL, SW_SHOW);
5392 if (ret > HINSTANCE_ERROR)
5394 return;
5399 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
5400 cmd += file;
5401 CAppUtils::LaunchApplication(cmd, NULL, false);