refactored
[TortoiseGit.git] / src / Git / GitStatusListCtrl.cpp
blob09c758c8b100de52d6615b3494129ac4a5b41a87
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 "XPTheme.h"
55 #include "CommonResource.h"
56 #include "AppUtils.h"
58 const UINT CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED
59 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
60 const UINT CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH
61 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
62 const UINT CGitStatusListCtrl::SVNSLNM_ADDFILE
63 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
64 const UINT CGitStatusListCtrl::SVNSLNM_CHECKCHANGED
65 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
66 const UINT CGitStatusListCtrl::SVNSLNM_ITEMCHANGED
67 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCHANGED"));
72 BEGIN_MESSAGE_MAP(CGitStatusListCtrl, CListCtrl)
73 ON_NOTIFY(HDN_ITEMCLICKA, 0, OnHdnItemclick)
74 ON_NOTIFY(HDN_ITEMCLICKW, 0, OnHdnItemclick)
75 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
76 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
77 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, OnLvnItemchanged)
78 ON_WM_CONTEXTMENU()
79 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk)
80 ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnLvnGetInfoTip)
81 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
82 ON_WM_SETCURSOR()
83 ON_WM_GETDLGCODE()
84 ON_NOTIFY_REFLECT(NM_RETURN, OnNMReturn)
85 ON_WM_KEYDOWN()
86 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
87 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
88 ON_WM_PAINT()
89 ON_NOTIFY(HDN_BEGINTRACKA, 0, &CGitStatusListCtrl::OnHdnBegintrack)
90 ON_NOTIFY(HDN_BEGINTRACKW, 0, &CGitStatusListCtrl::OnHdnBegintrack)
91 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, &CGitStatusListCtrl::OnHdnItemchanging)
92 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, &CGitStatusListCtrl::OnHdnItemchanging)
93 ON_WM_DESTROY()
94 ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBeginDrag)
95 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING, &CGitStatusListCtrl::OnLvnItemchanging)
96 END_MESSAGE_MAP()
100 CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl()
101 //, m_HeadRev(GitRev::REV_HEAD)
102 , m_pbCanceled(NULL)
103 , m_pStatLabel(NULL)
104 , m_pSelectButton(NULL)
105 , m_pConfirmButton(NULL)
106 , m_bBusy(false)
107 , m_bEmpty(false)
108 , m_bUnversionedRecurse(true)
109 , m_bShowIgnores(false)
110 , m_pDropTarget(NULL)
111 , m_bIgnoreRemoveOnly(false)
112 , m_bCheckChildrenWithParent(false)
113 , m_bUnversionedLast(true)
114 , m_bHasChangeLists(false)
115 , m_bHasLocks(false)
116 , m_bBlock(false)
117 , m_bBlockUI(false)
118 , m_bHasCheckboxes(false)
119 , m_bCheckIfGroupsExist(true)
120 , m_bFileDropsEnabled(false)
121 , m_bOwnDrag(false)
122 , m_dwDefaultColumns(0)
123 , m_ColumnManager(this)
124 , m_bAscending(false)
125 , m_nSortedColumn(-1)
126 , m_bHasExternalsFromDifferentRepos(false)
127 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE))
128 , m_amend(false)
129 , m_bDoNotAutoselectSubmodules(false)
131 m_FileLoaded=0;
132 m_critSec.Init();
133 m_bIsRevertTheirMy = false;
134 this->m_nLineAdded =this->m_nLineDeleted =0;
137 CGitStatusListCtrl::~CGitStatusListCtrl()
139 // if (m_pDropTarget)
140 // delete m_pDropTarget;
141 ClearStatusArray();
144 void CGitStatusListCtrl::ClearStatusArray()
146 #if 0
147 Locker lock(m_critSec);
148 for (size_t i=0; i < m_arStatusArray.size(); i++)
150 delete m_arStatusArray[i];
152 m_arStatusArray.clear();
153 #endif
155 #if 0
156 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(UINT_PTR index)
159 if (index >= (UINT_PTR)m_arListArray.size())
160 return NULL;
161 if (m_arListArray[index] >= m_arStatusArray.size())
162 return NULL;
163 return m_arStatusArray[m_arListArray[index]];
165 return NULL;
167 #endif
168 #if 0
169 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetVisibleListEntry(const CTGitPath& path)
171 int itemCount = GetItemCount();
172 for (int i=0; i < itemCount; i++)
174 FileEntry * entry = GetListEntry(i);
175 if (entry->GetPath().IsEquivalentTo(path))
176 return entry;
178 return NULL;
180 #endif
181 #if 0
182 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(const CTGitPath& path)
185 for (size_t i=0; i < m_arStatusArray.size(); i++)
187 FileEntry * entry = m_arStatusArray[i];
188 if (entry->GetPath().IsEquivalentTo(path))
189 return entry;
192 return NULL;
194 #endif
196 #if 0
197 int CGitStatusListCtrl::GetIndex(const CTGitPath& path)
199 int itemCount = GetItemCount();
200 for (int i=0; i < itemCount; i++)
202 FileEntry * entry = GetListEntry(i);
203 if (entry->GetPath().IsEquivalentTo(path))
204 return i;
206 return -1;
208 #endif
210 void CGitStatusListCtrl::Init(DWORD dwColumns, const CString& sColumnInfoContainer, unsigned __int64 dwContextMenus /* = GitSLC_POPALL */, bool bHasCheckboxes /* = true */)
212 Locker lock(m_critSec);
214 m_dwDefaultColumns = dwColumns | 1;
215 m_dwContextMenus = dwContextMenus;
216 m_bHasCheckboxes = bHasCheckboxes;
218 // set the extended style of the listcontrol
219 // 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.
220 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
221 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
222 if (DWORD(regFullRowSelect))
223 exStyle |= LVS_EX_FULLROWSELECT;
224 exStyle |= (bHasCheckboxes ? LVS_EX_CHECKBOXES : 0);
225 SetRedraw(false);
226 SetExtendedStyle(exStyle);
228 CXPTheme theme;
229 theme.SetWindowTheme(m_hWnd, L"Explorer", NULL);
231 m_nIconFolder = SYS_IMAGE_LIST().GetDirIconIndex();
232 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL);
234 static UINT standardColumnNames[SVNSLC_NUMCOLUMNS]
235 = { IDS_STATUSLIST_COLFILE
236 , IDS_STATUSLIST_COLFILENAME
237 , IDS_STATUSLIST_COLEXT
238 , IDS_STATUSLIST_COLSTATUS
239 , IDS_STATUSLIST_COLADD
240 , IDS_STATUSLIST_COLDEL
243 m_ColumnManager.SetNames(standardColumnNames,SVNSLC_NUMCOLUMNS);
244 m_ColumnManager.ReadSettings (m_dwDefaultColumns, 0, sColumnInfoContainer, SVNSLC_NUMCOLUMNS);
246 // enable file drops
247 #if 0
248 if (m_pDropTarget == NULL)
250 m_pDropTarget = new CGitStatusListCtrlDropTarget(this);
251 RegisterDragDrop(m_hWnd,m_pDropTarget);
252 // create the supported formats:
253 FORMATETC ftetc={0};
254 ftetc.dwAspect = DVASPECT_CONTENT;
255 ftetc.lindex = -1;
256 ftetc.tymed = TYMED_HGLOBAL;
257 ftetc.cfFormat=CF_HDROP;
258 m_pDropTarget->AddSuportedFormat(ftetc);
260 #endif
262 SetRedraw(true);
264 m_bUnversionedRecurse = !!((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE));
267 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID)
269 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID);
272 BOOL CGitStatusListCtrl::GetStatus ( const CTGitPathList* pathList
273 , bool bUpdate /* = FALSE */
274 , bool bShowIgnores /* = false */
275 , bool bShowUnRev
276 , bool /*bShowUserProps*/ /* = false */)
278 Locker lock(m_critSec);
279 int mask= CGitStatusListCtrl::FILELIST_MODIFY;
280 if(bShowIgnores)
281 mask|= CGitStatusListCtrl::FILELIST_IGNORE;
282 if(bShowUnRev)
283 mask|= CGitStatusListCtrl::FILELIST_UNVER;
284 this->UpdateFileList(mask,bUpdate,(CTGitPathList*)pathList);
287 #if 0
288 int refetchcounter = 0;
289 BOOL bRet = TRUE;
290 Invalidate();
291 // force the cursor to change
292 POINT pt;
293 GetCursorPos(&pt);
294 SetCursorPos(pt.x, pt.y);
296 m_mapFilenameToChecked.clear();
297 //m_StatusUrlList.Clear();
298 bool bHasChangelists = (m_changelists.size()>1 || (m_changelists.size()>0 && !m_bHasIgnoreGroup));
299 m_changelists.clear();
300 for (size_t i=0; i < m_arStatusArray.size(); i++)
302 FileEntry * entry = m_arStatusArray[i];
303 if ( bHasChangelists && entry->checked)
305 // If change lists are present, remember all checked entries
306 CString path = entry->GetPath().GetGitPathString();
307 m_mapFilenameToChecked[path] = true;
309 if ( (entry->status==git_wc_status_unversioned || entry->status==git_wc_status_missing ) && entry->checked )
311 // The user manually selected an unversioned or missing file. We remember
312 // this so that the selection can be restored when refreshing.
313 CString path = entry->GetPath().GetGitPathString();
314 m_mapFilenameToChecked[path] = true;
316 else if ( entry->status > git_wc_status_normal && !entry->checked )
318 // The user manually deselected a versioned file. We remember
319 // this so that the deselection can be restored when refreshing.
320 CString path = entry->GetPath().GetGitPathString();
321 m_mapFilenameToChecked[path] = false;
325 // use a sorted path list to make sure we fetch the status of
326 // parent items first, *then* the child items (if any)
327 CTGitPathList sortedPathList = pathList;
328 sortedPathList.SortByPathname();
331 bRet = TRUE;
332 m_nTargetCount = 0;
333 m_bHasExternalsFromDifferentRepos = FALSE;
334 m_bHasExternals = FALSE;
335 m_bHasUnversionedItems = FALSE;
336 m_bHasLocks = false;
337 m_bHasChangeLists = false;
338 m_bShowIgnores = bShowIgnores;
339 m_nSortedColumn = 0;
340 m_bBlock = TRUE;
341 m_bBusy = true;
342 m_bEmpty = false;
343 Invalidate();
345 // first clear possible status data left from
346 // previous GetStatus() calls
347 ClearStatusArray();
349 m_StatusFileList = sortedPathList;
351 // Since Git_client_status() returns all files, even those in
352 // folders included with Git:externals we need to check if all
353 // files we get here belongs to the same repository.
354 // It is possible to commit changes in an external folder, as long
355 // as the folder belongs to the same repository (but another path),
356 // but it is not possible to commit all files if the externals are
357 // from a different repository.
359 // To check if all files belong to the same repository, we compare the
360 // UUID's - if they're identical then the files belong to the same
361 // repository and can be committed. But if they're different, then
362 // tell the user to commit all changes in the external folders
363 // first and exit.
364 CStringA sUUID; // holds the repo UUID
365 CTGitPathList arExtPaths; // list of Git:external paths
367 GitConfig config;
369 m_sURL.Empty();
371 m_nTargetCount = sortedPathList.GetCount();
373 GitStatus status(m_pbCanceled);
374 if(m_nTargetCount > 1 && sortedPathList.AreAllPathsFilesInOneDirectory())
376 // This is a special case, where we've been given a list of files
377 // all from one folder
378 // We handle them by setting a status filter, then requesting the Git status of
379 // all the files in the directory, filtering for the ones we're interested in
380 status.SetFilter(sortedPathList);
382 // if all selected entries are files, we don't do a recursive status
383 // fetching. But if only one is a directory, we have to recurse.
384 git_depth_t depth = git_depth_files;
385 // We have set a filter. If all selected items were files or we fetch
386 // the status not recursively, then we have to include
387 // ignored items too - the user has selected them
388 bool bShowIgnoresRight = true;
389 for (int fcindex=0; fcindex<sortedPathList.GetCount(); ++fcindex)
391 if (sortedPathList[fcindex].IsDirectory())
393 depth = git_depth_infinity;
394 bShowIgnoresRight = false;
395 break;
398 if(!FetchStatusForSingleTarget(config, status, sortedPathList.GetCommonDirectory(), bUpdate, sUUID, arExtPaths, true, depth, bShowIgnoresRight))
400 bRet = FALSE;
403 else
405 for(int nTarget = 0; nTarget < m_nTargetCount; nTarget++)
407 // check whether the path we want the status for is already fetched due to status-fetching
408 // of a parent path.
409 // this check is only done for file paths, because folder paths could be included already
410 // but not recursively
411 if (sortedPathList[nTarget].IsDirectory() || GetListEntry(sortedPathList[nTarget]) == NULL)
413 if(!FetchStatusForSingleTarget(config, status, sortedPathList[nTarget], bUpdate, sUUID,
414 arExtPaths, false, git_depth_infinity, bShowIgnores))
416 bRet = FALSE;
422 // remove the 'helper' files of conflicted items from the list.
423 // otherwise they would appear as unversioned files.
424 for (INT_PTR cind = 0; cind < m_ConflictFileList.GetCount(); ++cind)
426 for (size_t i=0; i < m_arStatusArray.size(); i++)
428 if (m_arStatusArray[i]->GetPath().IsEquivalentTo(m_ConflictFileList[cind]))
430 delete m_arStatusArray[i];
431 m_arStatusArray.erase(m_arStatusArray.begin()+i);
432 break;
436 refetchcounter++;
437 } while(!BuildStatistics() && (refetchcounter < 2) && (*m_pbCanceled==false));
439 if (bShowUserProps)
440 FetchUserProperties();
442 m_ColumnManager.UpdateUserPropList (m_arStatusArray);
444 m_bBlock = FALSE;
445 m_bBusy = false;
446 GetCursorPos(&pt);
447 SetCursorPos(pt.x, pt.y);
448 return bRet;
449 #endif
450 BuildStatistics();
451 return TRUE;
455 // Fetch all local properties for all elements in the status array
457 void CGitStatusListCtrl::FetchUserProperties()
459 #if 0
460 GitPool globalPool;
462 for (size_t i = 0, count = m_arStatusArray.size(); i < count; ++i)
464 // local / temp pool to hold parameters and props for a single item
466 GitPool localPool ((apr_pool_t*)globalPool);
468 // open working copy for this path
470 const char* path = m_arStatusArray[i]->path.GetGitApiPath (localPool);
472 Git_wc_adm_access_t *adm_access = NULL;
473 Git_error_t * error = Git_wc_adm_probe_open3 ( &adm_access
474 , NULL
475 , path
476 , FALSE // no write lock
477 , 0 // lock just the directory/file itself
478 , NULL
479 , NULL
480 , localPool);
481 if (error == NULL)
483 // get the props and add them to the status info
485 apr_hash_t* props = NULL;
486 Git_error_t * error = Git_wc_prop_list ( &props
487 , path
488 , adm_access
489 , localPool);
490 if (error == NULL)
492 for ( apr_hash_index_t *index
493 = apr_hash_first (localPool, props)
494 ; index != NULL
495 ; index = apr_hash_next (index))
497 // extract next entry from hash
499 const char* key = NULL;
500 ptrdiff_t keyLen;
501 const char** val = NULL;
503 apr_hash_this ( index
504 , reinterpret_cast<const void**>(&key)
505 , &keyLen
506 , reinterpret_cast<void**>(&val));
508 // decode / dispatch it
510 CString name = CUnicodeUtils::GetUnicode (key);
511 CString value = CUnicodeUtils::GetUnicode (*val);
513 // store in property container (truncate it after ~100 chars)
515 m_arStatusArray[i]->present_props[name]
516 = value.Left (GitSLC_MAXUSERPROPLENGTH);
519 error = Git_wc_adm_close2 (adm_access, localPool);
521 Git_error_clear (error);
523 #endif
526 // Get the show-flags bitmap value which corresponds to a particular Git status
527 DWORD CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status)
529 switch (status)
531 case git_wc_status_none:
532 case git_wc_status_unversioned:
533 return SVNSLC_SHOWUNVERSIONED;
534 case git_wc_status_ignored:
535 if (!m_bShowIgnores)
536 return SVNSLC_SHOWDIRECTS;
537 return SVNSLC_SHOWDIRECTS|SVNSLC_SHOWIGNORED;
538 case git_wc_status_incomplete:
539 return SVNSLC_SHOWINCOMPLETE;
540 case git_wc_status_normal:
541 return SVNSLC_SHOWNORMAL;
542 case git_wc_status_external:
543 return SVNSLC_SHOWEXTERNAL;
544 case git_wc_status_added:
545 return SVNSLC_SHOWADDED;
546 case git_wc_status_missing:
547 return SVNSLC_SHOWMISSING;
548 case git_wc_status_deleted:
549 return SVNSLC_SHOWREMOVED;
550 case git_wc_status_replaced:
551 return SVNSLC_SHOWREPLACED;
552 case git_wc_status_modified:
553 return SVNSLC_SHOWMODIFIED;
554 case git_wc_status_merged:
555 return SVNSLC_SHOWMERGED;
556 case git_wc_status_conflicted:
557 return SVNSLC_SHOWCONFLICTED;
558 case git_wc_status_obstructed:
559 return SVNSLC_SHOWOBSTRUCTED;
560 default:
561 // we should NEVER get here!
562 ASSERT(FALSE);
563 break;
565 return 0;
568 void CGitStatusListCtrl::Show(DWORD dwShow, DWORD dwCheck /*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList,bool UseStoredCheckStatus)
570 CWinApp * pApp = AfxGetApp();
571 if (pApp)
572 pApp->DoWaitCursor(1);
574 Locker lock(m_critSec);
575 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
577 //SetItemCount(listIndex);
578 SetRedraw(FALSE);
579 DeleteAllItems();
580 m_nSelected = 0;
582 if(UpdateStatusList)
584 m_arStatusArray.clear();
585 for(int i=0;i<this->m_StatusFileList.GetCount();i++)
587 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
590 for(int i=0;i<this->m_UnRevFileList.GetCount();i++)
592 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
595 for(int i=0;i<this->m_IgnoreFileList.GetCount();i++)
597 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
600 PrepareGroups();
601 if( m_nSortedColumn )
603 CSorter predicate (&m_ColumnManager, m_nSortedColumn, m_bAscending);
604 std::sort(m_arStatusArray.begin(), m_arStatusArray.end(), predicate);
607 int index =0;
608 for(int i=0;i<this->m_arStatusArray.size();i++)
610 //set default checkbox status
611 CTGitPath* entry = ((CTGitPath*)m_arStatusArray[i]);
612 CString path = entry->GetGitPathString();
613 if (m_mapFilenameToChecked.size()!=0 && m_mapFilenameToChecked.find(path) != m_mapFilenameToChecked.end())
615 entry->m_Checked=m_mapFilenameToChecked[path];
617 else
619 bool autoSelectSubmodules = !(entry->IsDirectory() && m_bDoNotAutoselectSubmodules);
620 if(entry->m_Action & dwCheck && autoSelectSubmodules)
621 entry->m_Checked=true;
622 else
623 entry->m_Checked=false;
626 if(entry->m_Action & dwShow)
628 AddEntry(entry,langID,index);
629 index++;
633 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
634 for (int col = 0; col <= maxcol; col++)
635 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
637 SetRedraw(TRUE);
638 GetStatisticsString();
640 CHeaderCtrl * pHeader = GetHeaderCtrl();
641 HDITEM HeaderItem = {0};
642 HeaderItem.mask = HDI_FORMAT;
643 for (int i=0; i<pHeader->GetItemCount(); ++i)
645 pHeader->GetItem(i, &HeaderItem);
646 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
647 pHeader->SetItem(i, &HeaderItem);
649 if (m_nSortedColumn)
651 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
652 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
653 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
656 #if 0
657 if (nSelectedEntry)
659 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
660 EnsureVisible(nSelectedEntry, false);
662 else
664 // Restore the item at the top of the list.
665 for (int i=0;GetTopIndex() != nTopIndex;i++)
667 if ( !EnsureVisible(nTopIndex+i,false) )
669 break;
673 #endif
674 if (pApp)
675 pApp->DoWaitCursor(-1);
677 Invalidate();
679 m_dwShow = dwShow;
681 this->BuildStatistics();
683 #if 0
685 CWinApp * pApp = AfxGetApp();
686 if (pApp)
687 pApp->DoWaitCursor(1);
689 m_bShowFolders = bShowFolders;
691 int nTopIndex = GetTopIndex();
692 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
693 int nSelectedEntry = 0;
694 if (posSelectedEntry)
695 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
696 SetRedraw(FALSE);
697 DeleteAllItems();
699 PrepareGroups();
701 m_arListArray.clear();
703 m_arListArray.reserve(m_arStatusArray.size());
704 SetItemCount (static_cast<int>(m_arStatusArray.size()));
706 int listIndex = 0;
707 for (size_t i=0; i < m_arStatusArray.size(); ++i)
709 FileEntry * entry = m_arStatusArray[i];
710 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
711 continue;
712 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
713 continue;
714 if (entry->IsFolder() && (!bShowFolders))
715 continue; // don't show folders if they're not wanted.
717 #if 0
718 git_wc_status_kind status = GitStatus::GetMoreImportant(entry->status, entry->remotestatus);
719 DWORD showFlags = GetShowFlagsFromGitStatus(status);
720 if (entry->IsLocked())
721 showFlags |= SVNSLC_SHOWLOCKS;
722 if (entry->switched)
723 showFlags |= SVNSLC_SHOWSWITCHED;
724 if (!entry->changelist.IsEmpty())
725 showFlags |= SVNSLC_SHOWINCHANGELIST;
726 #endif
727 bool bAllowCheck = ((entry->changelist.Compare(SVNSLC_IGNORECHANGELIST) != 0)
728 && (m_bCheckIfGroupsExist || (m_changelists.size()==0 || (m_changelists.size()==1 && m_bHasIgnoreGroup))));
730 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
731 #if 0
732 if (status != Git_wc_status_ignored || (entry->direct) || (dwShow & GitSLC_SHOWIGNORED))
734 if ((!entry->IsFolder()) && (status == Git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
736 if (PathFileExists(entry->GetPath().GetWinPath()))
738 m_arListArray.push_back(i);
739 if ((dwCheck & SVNSLC_SHOWREMOVEDANDPRESENT)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
741 if (bAllowCheck)
742 entry->checked = true;
744 AddEntry(entry, langID, listIndex++);
747 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
749 m_arListArray.push_back(i);
750 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
752 if (bAllowCheck)
753 entry->checked = true;
755 AddEntry(entry, langID, listIndex++);
757 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
759 m_arListArray.push_back(i);
760 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
762 if (bAllowCheck)
763 entry->checked = true;
765 AddEntry(entry, langID, listIndex++);
768 #endif
771 SetItemCount(listIndex);
773 m_ColumnManager.UpdateRelevance (m_arStatusArray, m_arListArray);
775 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
776 for (int col = 0; col <= maxcol; col++)
777 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
779 SetRedraw(TRUE);
780 GetStatisticsString();
782 CHeaderCtrl * pHeader = GetHeaderCtrl();
783 HDITEM HeaderItem = {0};
784 HeaderItem.mask = HDI_FORMAT;
785 for (int i=0; i<pHeader->GetItemCount(); ++i)
787 pHeader->GetItem(i, &HeaderItem);
788 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
789 pHeader->SetItem(i, &HeaderItem);
791 if (m_nSortedColumn)
793 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
794 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
795 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
798 if (nSelectedEntry)
800 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
801 EnsureVisible(nSelectedEntry, false);
803 else
805 // Restore the item at the top of the list.
806 for (int i=0;GetTopIndex() != nTopIndex;i++)
808 if ( !EnsureVisible(nTopIndex+i,false) )
810 break;
815 if (pApp)
816 pApp->DoWaitCursor(-1);
818 m_bEmpty = (GetItemCount() == 0);
819 Invalidate();
820 #endif
824 void CGitStatusListCtrl::Show(DWORD /*dwShow*/, const CTGitPathList& checkedList, bool /*bShowFolders*/ /* = true */)
826 DeleteAllItems();
827 for(int i=0;i<checkedList.GetCount();i++)
828 this->AddEntry((CTGitPath *)&checkedList[i],0,i);
829 return ;
830 #if 0
832 Locker lock(m_critSec);
833 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
835 CWinApp * pApp = AfxGetApp();
836 if (pApp)
837 pApp->DoWaitCursor(1);
838 m_dwShow = dwShow;
839 m_bShowFolders = bShowFolders;
840 m_nSelected = 0;
841 int nTopIndex = GetTopIndex();
842 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
843 int nSelectedEntry = 0;
844 if (posSelectedEntry)
845 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
846 SetRedraw(FALSE);
847 DeleteAllItems();
849 PrepareGroups();
851 m_arListArray.clear();
853 m_arListArray.reserve(m_arStatusArray.size());
854 SetItemCount (static_cast<int>(m_arStatusArray.size()));
856 int listIndex = 0;
857 for (size_t i=0; i < m_arStatusArray.size(); ++i)
859 FileEntry * entry = m_arStatusArray[i];
860 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
861 continue;
862 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
863 continue;
864 if (entry->IsFolder() && (!bShowFolders))
865 continue; // don't show folders if they're not wanted.
866 #if 0
867 git_wc_status_kind status = SVNStatus::GetMoreImportant(entry->status, entry->remotestatus);
868 DWORD showFlags = GetShowFlagsFromSVNStatus(status);
869 if (entry->IsLocked())
870 showFlags |= SVNSLC_SHOWLOCKS;
871 if (!entry->changelist.IsEmpty())
872 showFlags |= SVNSLC_SHOWINCHANGELIST;
874 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
875 if (status != git_wc_status_ignored || (entry->direct) || (dwShow & SVNSLC_SHOWIGNORED))
877 for (int npath = 0; npath < checkedList.GetCount(); ++npath)
879 if (entry->GetPath().IsEquivalentTo(checkedList[npath]))
881 entry->checked = true;
882 break;
885 if ((!entry->IsFolder()) && (status == git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
887 if (PathFileExists(entry->GetPath().GetWinPath()))
889 m_arListArray.push_back(i);
890 AddEntry(entry, langID, listIndex++);
893 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
895 m_arListArray.push_back(i);
896 AddEntry(entry, langID, listIndex++);
898 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
900 m_arListArray.push_back(i);
901 AddEntry(entry, langID, listIndex++);
903 else if (entry->switched)
905 m_arListArray.push_back(i);
906 AddEntry(entry, langID, listIndex++);
909 #endif
912 SetItemCount(listIndex);
914 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
915 for (int col = 0; col <= maxcol; col++)
916 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
918 SetRedraw(TRUE);
919 GetStatisticsString();
921 CHeaderCtrl * pHeader = GetHeaderCtrl();
922 HDITEM HeaderItem = {0};
923 HeaderItem.mask = HDI_FORMAT;
924 for (int i=0; i<pHeader->GetItemCount(); ++i)
926 pHeader->GetItem(i, &HeaderItem);
927 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
928 pHeader->SetItem(i, &HeaderItem);
930 if (m_nSortedColumn)
932 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
933 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
934 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
937 if (nSelectedEntry)
939 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
940 EnsureVisible(nSelectedEntry, false);
942 else
944 // Restore the item at the top of the list.
945 for (int i=0;GetTopIndex() != nTopIndex;i++)
947 if ( !EnsureVisible(nTopIndex+i,false) )
949 break;
954 if (pApp)
955 pApp->DoWaitCursor(-1);
957 m_bEmpty = (GetItemCount() == 0);
958 Invalidate();
959 #endif
962 int CGitStatusListCtrl::GetColumnIndex(int mask)
964 int i=0;
965 for(i=0;i<32;i++)
966 if(mask&0x1)
967 return i;
968 else
969 mask=mask>>1;
970 return -1;
972 void CGitStatusListCtrl::AddEntry(CTGitPath * GitPath, WORD /*langID*/, int listIndex)
974 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
975 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
977 CString path = GitPath->GetGitPathString();
979 m_bBlock = TRUE;
980 int index = listIndex;
981 int nCol = 1;
982 CString entryname = GitPath->GetGitPathString();
983 int icon_idx = 0;
984 if (GitPath->IsDirectory())
985 icon_idx = m_nIconFolder;
986 else
988 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath);
990 // relative path
991 CString rename;
992 rename.Format(_T(" (from %s)"),GitPath->GetGitOldPathString());
993 if(GitPath->m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
994 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(SVNSLC_COLADD),GitPath->m_StatAdd);
1007 SetItemText(index, GetColumnIndex(SVNSLC_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, sizeof(buf)/sizeof(TCHAR), (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, sizeof(buf)/sizeof(TCHAR), (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, sizeof(buf)/sizeof(TCHAR), (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, sizeof(buf)/sizeof(TCHAR), (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, sizeof(buf)/sizeof(TCHAR), (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, sizeof(buf)/sizeof(TCHAR), (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::Sort()
1296 Locker lock(m_critSec);
1298 CSorter predicate (&m_ColumnManager, m_nSortedColumn, m_bAscending);
1300 std::sort(m_arStatusArray.begin(), m_arStatusArray.end(), predicate);
1301 SaveColumnWidths();
1302 Show(m_dwShow, 0, m_bShowFolders,false,true);
1306 void CGitStatusListCtrl::OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult)
1308 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1309 *pResult = 0;
1310 if (m_bBlock)
1311 return;
1312 m_bBlock = TRUE;
1313 if (m_nSortedColumn == phdr->iItem)
1314 m_bAscending = !m_bAscending;
1315 else
1316 m_bAscending = TRUE;
1317 m_nSortedColumn = phdr->iItem;
1318 m_mapFilenameToChecked.clear();
1319 Sort();
1321 CHeaderCtrl * pHeader = GetHeaderCtrl();
1322 HDITEM HeaderItem = {0};
1323 HeaderItem.mask = HDI_FORMAT;
1324 for (int i=0; i<pHeader->GetItemCount(); ++i)
1326 pHeader->GetItem(i, &HeaderItem);
1327 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1328 pHeader->SetItem(i, &HeaderItem);
1330 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1331 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1332 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1334 // the checked state of the list control items must be restored
1336 for (int i=0; i<GetItemCount(); ++i)
1338 CTGitPath * entry = (CTGitPath*)GetItemData(i);
1339 ASSERT(entry);
1340 if(entry)
1341 SetCheck(i, entry->m_Checked);
1344 m_bBlock = FALSE;
1347 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
1349 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1350 *pResult = 0;
1352 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1353 if ((m_bBlock)&&(m_bBlockUI))
1355 // if we're blocked, prevent changing of the check state
1356 if ((!ISCHECKED(pNMLV->uOldState) && ISCHECKED(pNMLV->uNewState))||
1357 (ISCHECKED(pNMLV->uOldState) && !ISCHECKED(pNMLV->uNewState)))
1358 *pResult = TRUE;
1362 BOOL CGitStatusListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
1364 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1365 *pResult = 0;
1366 CWnd* pParent = GetParent();
1367 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
1369 pParent->SendMessage(SVNSLNM_ITEMCHANGED, pNMLV->iItem);
1372 if ((pNMLV->uNewState==0)||(pNMLV->uNewState & LVIS_SELECTED)||(pNMLV->uNewState & LVIS_FOCUSED))
1373 return FALSE;
1375 if (m_bBlock)
1376 return FALSE;
1378 bool bSelected = !!(ListView_GetItemState(m_hWnd, pNMLV->iItem, LVIS_SELECTED) & LVIS_SELECTED);
1379 int nListItems = GetItemCount();
1381 m_bBlock = TRUE;
1382 // was the item checked?
1384 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1385 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1387 if (GetCheck(pNMLV->iItem))
1389 CheckEntry(pNMLV->iItem, nListItems);
1390 if (bSelected)
1392 POSITION pos = GetFirstSelectedItemPosition();
1393 int index;
1394 while ((index = GetNextSelectedItem(pos)) >= 0)
1396 if (index != pNMLV->iItem)
1397 CheckEntry(index, nListItems);
1401 else
1403 UncheckEntry(pNMLV->iItem, nListItems);
1404 if (bSelected)
1406 POSITION pos = GetFirstSelectedItemPosition();
1407 int index;
1408 while ((index = GetNextSelectedItem(pos)) >= 0)
1410 if (index != pNMLV->iItem)
1411 UncheckEntry(index, nListItems);
1416 GetStatisticsString();
1417 m_bBlock = FALSE;
1418 NotifyCheck();
1420 return FALSE;
1423 void CGitStatusListCtrl::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
1425 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
1427 *pResult = FALSE;
1430 void CGitStatusListCtrl::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
1432 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
1434 Invalidate(FALSE);
1437 void CGitStatusListCtrl::CheckEntry(int index, int /*nListItems*/)
1439 Locker lock(m_critSec);
1440 //FileEntry * entry = GetListEntry(index);
1441 CTGitPath *path=(CTGitPath*)GetItemData(index);
1442 ASSERT(path != NULL);
1443 if (path == NULL)
1444 return;
1445 m_mapFilenameToChecked[path->GetGitPathString()] = true;
1446 SetCheck(index, TRUE);
1447 //entry = GetListEntry(index);
1448 // if an unversioned item was checked, then we need to check if
1449 // the parent folders are unversioned too. If the parent folders actually
1450 // are unversioned, then check those too.
1451 #if 0
1452 if (entry->status == git_wc_status_unversioned)
1454 // we need to check the parent folder too
1455 const CTGitPath& folderpath = entry->path;
1456 for (int i=0; i< nListItems; ++i)
1458 FileEntry * testEntry = GetListEntry(i);
1459 ASSERT(testEntry != NULL);
1460 if (testEntry == NULL)
1461 continue;
1462 if (!testEntry->checked)
1464 if (testEntry->path.IsAncestorOf(folderpath) && (!testEntry->path.IsEquivalentTo(folderpath)))
1466 SetEntryCheck(testEntry,i,true);
1467 m_nSelected++;
1472 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1473 if ( (entry->status == git_wc_status_deleted) || (m_bCheckChildrenWithParent) || (bShift) )
1475 // if a deleted folder gets checked, we have to check all
1476 // children of that folder too.
1477 if (entry->path.IsDirectory())
1479 SetCheckOnAllDescendentsOf(entry, true);
1482 // if a deleted file or folder gets checked, we have to
1483 // check all parents of this item too.
1484 for (int i=0; i<nListItems; ++i)
1486 FileEntry * testEntry = GetListEntry(i);
1487 ASSERT(testEntry != NULL);
1488 if (testEntry == NULL)
1489 continue;
1490 if (!testEntry->checked)
1492 if (testEntry->path.IsAncestorOf(entry->path) && (!testEntry->path.IsEquivalentTo(entry->path)))
1494 if ((testEntry->status == git_wc_status_deleted)||(m_bCheckChildrenWithParent))
1496 SetEntryCheck(testEntry,i,true);
1497 m_nSelected++;
1498 // now we need to check all children of this parent folder
1499 SetCheckOnAllDescendentsOf(testEntry, true);
1505 #endif
1506 if ( !path->m_Checked )
1508 path->m_Checked = TRUE;
1509 m_nSelected++;
1513 void CGitStatusListCtrl::UncheckEntry(int index, int /*nListItems*/)
1515 Locker lock(m_critSec);
1516 CTGitPath *path=(CTGitPath*)GetItemData(index);
1517 ASSERT(path != NULL);
1518 if (path == NULL)
1519 return;
1520 SetCheck(index, FALSE);
1521 m_mapFilenameToChecked[path->GetGitPathString()] = false;
1522 //entry = GetListEntry(index);
1523 // item was unchecked
1524 #if 0
1525 if (entry->path.IsDirectory())
1527 // disable all files within an unselected folder, except when unchecking a folder with property changes
1528 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1529 if ( (entry->status != git_wc_status_modified) || (bShift) )
1531 SetCheckOnAllDescendentsOf(entry, false);
1534 else if (entry->status == git_wc_status_deleted)
1536 // a "deleted" file was unchecked, so uncheck all parent folders
1537 // and all children of those parents
1538 for (int i=0; i<nListItems; i++)
1540 FileEntry * testEntry = GetListEntry(i);
1541 ASSERT(testEntry != NULL);
1542 if (testEntry == NULL)
1543 continue;
1544 if (testEntry->checked)
1546 if (testEntry->path.IsAncestorOf(entry->path))
1548 if (testEntry->status == git_wc_status_deleted)
1550 SetEntryCheck(testEntry,i,false);
1551 m_nSelected--;
1553 SetCheckOnAllDescendentsOf(testEntry, false);
1559 #endif
1560 if ( path->m_Checked )
1562 path->m_Checked = FALSE;
1563 m_nSelected--;
1566 #if 0
1567 bool CGitStatusListCtrl::EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2)
1569 return pEntry1->path < pEntry2->path;
1572 bool CGitStatusListCtrl::IsEntryVersioned(const FileEntry* pEntry1)
1574 return pEntry1->status != git_wc_status_unversioned;
1576 #endif
1577 bool CGitStatusListCtrl::BuildStatistics()
1580 bool bRefetchStatus = false;
1582 // now gather some statistics
1583 m_nUnversioned = 0;
1584 m_nNormal = 0;
1585 m_nModified = 0;
1586 m_nAdded = 0;
1587 m_nDeleted = 0;
1588 m_nConflicted = 0;
1589 m_nTotal = 0;
1590 m_nSelected = 0;
1591 m_nLineAdded = 0;
1592 m_nLineDeleted = 0;
1593 m_nRenamed = 0;
1595 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1597 int status=((CTGitPath*)m_arStatusArray[i])->m_Action;
1599 m_nLineAdded += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatAdd);
1600 m_nLineDeleted += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatDel);
1602 if(status&(CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
1603 m_nAdded++;
1605 if(status&CTGitPath::LOGACTIONS_DELETED)
1606 m_nDeleted++;
1608 if(status&(CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_MODIFIED))
1609 m_nModified++;
1611 if(status&CTGitPath::LOGACTIONS_UNMERGED)
1612 m_nConflicted++;
1614 if(status&(CTGitPath::LOGACTIONS_IGNORE|CTGitPath::LOGACTIONS_UNVER))
1615 m_nUnversioned++;
1617 if(status&(CTGitPath::LOGACTIONS_REPLACED))
1618 m_nRenamed++;
1620 if(((CTGitPath*)m_arStatusArray[i])->m_Checked)
1621 m_nSelected++;
1623 // } // switch (entry->status)
1624 // } // if (entry)
1625 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1626 return !bRefetchStatus;
1628 return FALSE;
1632 int CGitStatusListCtrl::GetGroupFromPoint(POINT * ppt)
1634 // the point must be relative to the upper left corner of the control
1636 if (ppt == NULL)
1637 return -1;
1638 if (!IsGroupViewEnabled())
1639 return -1;
1641 POINT pt = *ppt;
1642 pt.x = 10;
1643 UINT flags = 0;
1644 int nItem = -1;
1645 RECT rc;
1646 GetWindowRect(&rc);
1647 while (((flags & LVHT_BELOW) == 0)&&(pt.y < rc.bottom))
1649 nItem = HitTest(pt, &flags);
1650 if ((flags & LVHT_ONITEM)||(flags & LVHT_EX_GROUP_HEADER))
1652 // the first item below the point
1654 // check if the point is too much right (i.e. if the point
1655 // is farther to the right than the width of the item)
1656 RECT r;
1657 GetItemRect(nItem, &r, LVIR_LABEL);
1658 if (ppt->x > r.right)
1659 return -1;
1661 LVITEM lv = {0};
1662 lv.mask = LVIF_GROUPID;
1663 lv.iItem = nItem;
1664 GetItem(&lv);
1665 int groupID = lv.iGroupId;
1666 // now we search upwards and check if the item above this one
1667 // belongs to another group. If it belongs to the same group,
1668 // we're not over a group header
1669 while (pt.y >= 0)
1671 pt.y -= 2;
1672 nItem = HitTest(pt, &flags);
1673 if ((flags & LVHT_ONITEM)&&(nItem >= 0))
1675 // the first item below the point
1676 LVITEM lv = {0};
1677 lv.mask = LVIF_GROUPID;
1678 lv.iItem = nItem;
1679 GetItem(&lv);
1680 if (lv.iGroupId != groupID)
1681 return groupID;
1682 else
1683 return -1;
1686 if (pt.y < 0)
1687 return groupID;
1688 return -1;
1690 pt.y += 2;
1692 return -1;
1695 void CGitStatusListCtrl::OnContextMenuGroup(CWnd * /*pWnd*/, CPoint point)
1697 POINT clientpoint = point;
1698 ScreenToClient(&clientpoint);
1699 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint) >= 0))
1701 CMenu popup;
1702 if (popup.CreatePopupMenu())
1704 CString temp;
1705 temp.LoadString(IDS_STATUSLIST_CHECKGROUP);
1706 popup.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CHECKGROUP, temp);
1707 temp.LoadString(IDS_STATUSLIST_UNCHECKGROUP);
1708 popup.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_UNCHECKGROUP, temp);
1709 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1710 bool bCheck = false;
1711 switch (cmd)
1713 case IDSVNLC_CHECKGROUP:
1714 bCheck = true;
1715 // fall through here
1716 case IDSVNLC_UNCHECKGROUP:
1718 int group = GetGroupFromPoint(&clientpoint);
1719 // go through all items and check/uncheck those assigned to the group
1720 // but block the OnLvnItemChanged handler
1721 m_bBlock = true;
1722 LVITEM lv;
1723 for (int i=0; i<GetItemCount(); ++i)
1725 SecureZeroMemory(&lv, sizeof(LVITEM));
1726 lv.mask = LVIF_GROUPID;
1727 lv.iItem = i;
1728 GetItem(&lv);
1730 if (lv.iGroupId == group)
1732 CTGitPath * entry = (CTGitPath*)GetItemData(i);
1733 if (entry)
1735 bool bOldCheck = entry->m_Checked;
1736 SetEntryCheck(entry, i, bCheck);
1737 if (bCheck != bOldCheck)
1739 if (bCheck)
1740 m_nSelected++;
1741 else
1742 m_nSelected--;
1748 GetStatisticsString();
1749 NotifyCheck();
1750 m_bBlock = false;
1752 break;
1758 void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point)
1761 //WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1763 bool XPorLater = false;
1764 OSVERSIONINFOEX inf;
1765 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
1766 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
1767 GetVersionEx((OSVERSIONINFO *)&inf);
1768 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
1769 if (fullver >= 0x0501)
1770 XPorLater = true;
1771 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1772 CTGitPath * filepath;
1774 int selIndex = GetSelectionMark();
1775 if ((point.x == -1) && (point.y == -1))
1777 CRect rect;
1778 GetItemRect(selIndex, &rect, LVIR_LABEL);
1779 ClientToScreen(&rect);
1780 point = rect.CenterPoint();
1782 if ((GetSelectedCount() == 0)&&(XPorLater)&&(m_bHasCheckboxes))
1784 // nothing selected could mean the context menu is requested for
1785 // a group header
1786 OnContextMenuGroup(pWnd, point);
1788 else if (selIndex >= 0)
1790 //FileEntry * entry = GetListEntry(selIndex);
1792 filepath = (CTGitPath * )GetItemData(selIndex);
1794 ASSERT(filepath != NULL);
1795 if (filepath == NULL)
1796 return;
1798 //const CTGitPath& filepath = entry->path;
1799 int wcStatus = filepath->m_Action;
1800 // entry is selected, now show the popup menu
1801 Locker lock(m_critSec);
1802 CIconMenu popup;
1803 CMenu changelistSubMenu;
1804 CMenu ignoreSubMenu;
1805 if (popup.CreatePopupMenu())
1807 //Add Menu for verion controled file
1809 if (wcStatus & CTGitPath::LOGACTIONS_UNMERGED)
1811 if ((m_dwContextMenus & SVNSLC_POPCONFLICT)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1813 popup.AppendMenuIcon(IDSVNLC_EDITCONFLICT, IDS_MENUCONFLICT, IDI_CONFLICT);
1815 if (m_dwContextMenus & SVNSLC_POPRESOLVE)
1817 popup.AppendMenuIcon(IDSVNLC_RESOLVECONFLICT, IDS_STATUSLIST_CONTEXT_RESOLVED, IDI_RESOLVE);
1819 if ((m_dwContextMenus & SVNSLC_POPRESOLVE)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1821 popup.AppendMenuIcon(IDSVNLC_RESOLVETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS, IDI_RESOLVE);
1822 popup.AppendMenuIcon(IDSVNLC_RESOLVEMINE, IDS_SVNPROGRESS_MENUUSEMINE, IDI_RESOLVE);
1824 if ((m_dwContextMenus & SVNSLC_POPCONFLICT)||(m_dwContextMenus & SVNSLC_POPRESOLVE))
1825 popup.AppendMenu(MF_SEPARATOR);
1828 if (GetSelectedCount() > 0)
1830 if (wcStatus & CTGitPath::LOGACTIONS_UNVER)
1831 if (m_dwContextMenus & SVNSLC_POPADD)
1833 //if ( entry->IsFolder() )
1835 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1837 //else
1839 popup.AppendMenuIcon(IDSVNLC_ADD, IDS_STATUSLIST_CONTEXT_ADD, IDI_ADD);
1844 if (!(wcStatus &CTGitPath::LOGACTIONS_UNVER))
1846 if ( (m_dwContextMenus & SVNSLC_POPCOMPAREWITHBASE) && GetSelectedCount()>0)
1848 if(filepath->m_ParentNo & MERGE_MASK)
1849 popup.AppendMenuIcon(IDSVNLC_COMPARE, IDS_TREE_DIFF, IDI_DIFF);
1850 else
1851 popup.AppendMenuIcon(IDSVNLC_COMPARE, IDS_LOG_COMPAREWITHBASE, IDI_DIFF);
1853 popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1856 if ((m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_COMPAREWC)) && GetSelectedCount()>0)
1858 if( (!m_CurrentVersion.IsEmpty()) && m_CurrentVersion != GIT_REV_ZERO)
1859 popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1861 //Select one items
1862 if (GetSelectedCount() == 1)
1864 bool bEntryAdded = false;
1865 //if (entry->remotestatus <= git_wc_status_normal)
1867 // if (wcStatus > git_wc_status_normal)
1868 // {
1869 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
1870 // {
1871 if(!g_Git.IsInitRepos() && (m_dwContextMenus&SVNSLC_POPGNUDIFF))
1873 popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1875 bEntryAdded = true;
1877 // }
1878 // }
1881 //else if (wcStatus != git_wc_status_deleted)
1883 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
1884 // {
1885 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1886 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1887 // bEntryAdded = true;
1888 // }
1889 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
1890 // {
1891 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1892 // bEntryAdded = true;
1893 // }
1895 if (bEntryAdded)
1896 popup.AppendMenu(MF_SEPARATOR);
1898 //else if (GetSelectedCount() > 1)
1900 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1901 // {
1902 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1903 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1904 // }
1908 if( (!this->m_Rev1.IsEmpty()) || (!this->m_Rev1.IsEmpty()) )
1910 if(GetSelectedCount() == 1)
1912 if (m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_COMPARETWO))
1914 popup.AppendMenuIcon(IDSVNLC_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1915 popup.SetDefaultItem(IDSVNLC_COMPARETWO, FALSE);
1917 if (m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_GNUDIFF2))
1919 popup.AppendMenuIcon(IDSVNLC_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1924 ///Select Multi item
1925 //if (GetSelectedCount() > 0)
1927 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
1928 // {
1929 // POSITION pos = GetFirstSelectedItemPosition();
1930 // int index = GetNextSelectedItem(pos);
1931 // if (index >= 0)
1932 // {
1933 // FileEntry * entry = GetListEntry(index);
1934 // git_wc_status_kind status1 = git_wc_status_none;
1935 // git_wc_status_kind status2 = git_wc_status_none;
1936 // if (entry)
1937 // status1 = entry->status;
1938 // index = GetNextSelectedItem(pos);
1939 // if (index >= 0)
1940 // {
1941 // entry = GetListEntry(index);
1942 // if (entry)
1943 // status2 = entry->status;
1944 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
1945 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
1946 // {
1947 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
1948 // }
1949 // }
1950 // }
1951 // }
1952 // if (wcStatus > git_wc_status_normal)
1953 // {
1954 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1955 // {
1956 // // reverting missing folders is not possible
1957 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1958 // {
1959 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1960 // }
1961 // }
1962 // }
1963 // if (entry->remotestatus > git_wc_status_normal)
1964 // {
1965 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1966 // {
1967 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1968 // }
1969 // }
1972 if ( (GetSelectedCount() >0 ) && (!(wcStatus & CTGitPath::LOGACTIONS_UNVER)))
1974 if ((m_dwContextMenus & SVNSLC_POPREVERT) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO))
1976 popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1979 if ((m_dwContextMenus & GetContextMenuBit(IDSVNLC_REVERTTOREV)) && ( !this->m_CurrentVersion.IsEmpty() )
1980 && this->m_CurrentVersion != GIT_REV_ZERO && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1982 popup.AppendMenuIcon(IDSVNLC_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1986 if ((GetSelectedCount() == 1)&&(!(wcStatus & CTGitPath::LOGACTIONS_UNVER))
1987 &&(!(wcStatus & CTGitPath::LOGACTIONS_IGNORE)))
1989 if (m_dwContextMenus & SVNSLC_POPSHOWLOG)
1991 popup.AppendMenuIcon(IDSVNLC_LOG, IDS_REPOBROWSE_SHOWLOG, IDI_LOG);
1993 if (m_dwContextMenus & SVNSLC_POPBLAME && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1995 popup.AppendMenuIcon(IDSVNLC_BLAME, IDS_MENUBLAME, IDI_BLAME);
1998 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1999 if ( (GetSelectedCount() == 1) )
2001 if (m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_SAVEAS) && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
2003 popup.AppendMenuIcon(IDSVNLC_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2006 if (m_dwContextMenus & SVNSLC_POPOPEN && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
2008 popup.AppendMenuIcon(IDSVNLC_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2009 popup.AppendMenuIcon(IDSVNLC_OPEN, IDS_REPOBROWSE_OPEN, IDI_OPEN);
2010 popup.AppendMenuIcon(IDSVNLC_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2011 if (wcStatus &CTGitPath::LOGACTIONS_UNVER) {
2012 popup.SetDefaultItem(IDSVNLC_OPEN, FALSE);
2016 if (m_dwContextMenus & SVNSLC_POPEXPLORE && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
2018 popup.AppendMenuIcon(IDSVNLC_EXPLORE, IDS_STATUSLIST_CONTEXT_EXPLORE, IDI_EXPLORER);
2022 if (GetSelectedCount() > 0)
2024 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
2025 // {
2026 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2027 // }
2028 // 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))
2029 // {
2030 // if (bShift)
2031 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
2032 // else
2033 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
2034 // }
2035 if ((wcStatus & CTGitPath::LOGACTIONS_UNVER)/*||(wcStatus == git_wc_status_deleted)*/)
2037 if (m_dwContextMenus & SVNSLC_POPDELETE)
2039 popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2042 if ( (wcStatus & CTGitPath::LOGACTIONS_UNVER || wcStatus & CTGitPath::LOGACTIONS_DELETED) )
2044 if (m_dwContextMenus & SVNSLC_POPIGNORE)
2047 CTGitPathList ignorelist;
2048 FillListOfSelectedItemPaths(ignorelist);
2049 //check if all selected entries have the same extension
2050 bool bSameExt = true;
2051 CString sExt;
2052 for (int i=0; i<ignorelist.GetCount(); ++i)
2054 if (sExt.IsEmpty() && (i==0))
2055 sExt = ignorelist[i].GetFileExtension();
2056 else if (sExt.CompareNoCase(ignorelist[i].GetFileExtension())!=0)
2057 bSameExt = false;
2059 if (bSameExt)
2061 if (ignoreSubMenu.CreateMenu())
2063 CString ignorepath;
2064 if (ignorelist.GetCount()==1)
2065 ignorepath = ignorelist[0].GetFileOrDirectoryName();
2066 else
2067 ignorepath.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2068 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_IGNORE, ignorepath);
2069 ignorepath = _T("*")+sExt;
2070 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_IGNOREMASK, ignorepath);
2071 CString temp;
2072 temp.LoadString(IDS_MENUIGNORE);
2073 popup.InsertMenu((UINT)-1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)ignoreSubMenu.m_hMenu, temp);
2076 else
2078 CString temp;
2079 if (ignorelist.GetCount()==1)
2081 temp.LoadString(IDS_MENUIGNORE);
2083 else
2085 temp.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2087 popup.AppendMenuIcon(IDSVNLC_IGNORE, temp, IDI_IGNORE);
2095 if (GetSelectedCount() > 0)
2097 #if 0
2098 if ((!entry->IsFolder())&&(wcStatus >= git_wc_status_normal)
2099 &&(wcStatus!=git_wc_status_missing)&&(wcStatus!=git_wc_status_deleted)
2100 &&(wcStatus!=git_wc_status_added))
2102 popup.AppendMenu(MF_SEPARATOR);
2103 if ((entry->lock_token.IsEmpty())&&(!entry->IsFolder()))
2105 if (m_dwContextMenus & SVNSLC_POPLOCK)
2107 popup.AppendMenuIcon(IDSVNLC_LOCK, IDS_MENU_LOCK, IDI_LOCK);
2110 if ((!entry->lock_token.IsEmpty())&&(!entry->IsFolder()))
2112 if (m_dwContextMenus & SVNSLC_POPUNLOCK)
2114 popup.AppendMenuIcon(IDSVNLC_UNLOCK, IDS_MENU_UNLOCK, IDI_UNLOCK);
2119 if ((!entry->IsFolder())&&((!entry->lock_token.IsEmpty())||(!entry->lock_remotetoken.IsEmpty())))
2121 if (m_dwContextMenus & SVNSLC_POPUNLOCKFORCE)
2123 popup.AppendMenuIcon(IDSVNLC_UNLOCKFORCE, IDS_MENU_UNLOCKFORCE, IDI_UNLOCK);
2127 if (wcStatus != git_wc_status_missing && wcStatus != git_wc_status_deleted &&wcStatus!=git_wc_status_unversioned)
2129 popup.AppendMenu(MF_SEPARATOR);
2130 popup.AppendMenuIcon(IDSVNLC_PROPERTIES, IDS_STATUSLIST_CONTEXT_PROPERTIES, IDI_PROPERTIES);
2132 #endif
2133 popup.AppendMenu(MF_SEPARATOR);
2134 popup.AppendMenuIcon(IDSVNLC_COPY, IDS_STATUSLIST_CONTEXT_COPY, IDI_COPYCLIP);
2135 popup.AppendMenuIcon(IDSVNLC_COPYEXT, IDS_STATUSLIST_CONTEXT_COPYEXT, IDI_COPYCLIP);
2136 #if 0
2137 if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS)&&(XPorLater)
2138 &&(wcStatus != git_wc_status_unversioned)&&(wcStatus != git_wc_status_none))
2140 popup.AppendMenu(MF_SEPARATOR);
2141 // changelist commands
2142 size_t numChangelists = GetNumberOfChangelistsInSelection();
2143 if (numChangelists > 0)
2145 popup.AppendMenuIcon(IDSVNLC_REMOVEFROMCS, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS);
2147 if ((!entry->IsFolder())&&(changelistSubMenu.CreateMenu()))
2149 CString temp;
2150 temp.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS);
2151 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATECS, temp);
2153 if (entry->changelist.Compare(SVNSLC_IGNORECHANGELIST))
2155 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2156 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATEIGNORECS, SVNSLC_IGNORECHANGELIST);
2159 if (m_changelists.size() > 0)
2161 // find the changelist names
2162 bool bNeedSeparator = true;
2163 int cmdID = IDSVNLC_MOVETOCS;
2164 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
2166 if ((entry->changelist.Compare(it->first))&&(it->first.Compare(SVNSLC_IGNORECHANGELIST)))
2168 if (bNeedSeparator)
2170 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2171 bNeedSeparator = false;
2173 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, cmdID, it->first);
2174 cmdID++;
2178 temp.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS);
2179 popup.AppendMenu(MF_POPUP|MF_STRING, (UINT_PTR)changelistSubMenu.GetSafeHmenu(), temp);
2182 #endif
2185 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2187 m_bBlock = TRUE;
2188 AfxGetApp()->DoWaitCursor(1);
2189 //int iItemCountBeforeMenuCmd = GetItemCount();
2190 //bool bForce = false;
2191 switch (cmd)
2193 case IDSVNLC_VIEWREV:
2194 OpenFile(filepath, ALTERNATIVEEDITOR);
2195 break;
2196 case IDSVNLC_OPEN:
2197 OpenFile(filepath,OPEN);
2198 break;
2199 case IDSVNLC_OPENWITH:
2200 OpenFile(filepath,OPEN_WITH);
2201 break;
2202 case IDSVNLC_EXPLORE:
2204 ShellExecute(this->m_hWnd, _T("explore"), filepath->GetDirectory().GetWinPath(), NULL, NULL, SW_SHOW);
2206 break;
2208 // Compare current version and work copy.
2209 case IDSVNLC_COMPAREWC:
2211 POSITION pos = GetFirstSelectedItemPosition();
2212 while ( pos )
2214 int index = GetNextSelectedItem(pos);
2215 StartDiffWC(index);
2218 break;
2219 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2220 case IDSVNLC_COMPARE:
2222 POSITION pos = GetFirstSelectedItemPosition();
2223 while ( pos )
2225 int index = GetNextSelectedItem(pos);
2226 StartDiff(index);
2229 break;
2230 case IDSVNLC_COMPARETWO:
2232 POSITION pos = GetFirstSelectedItemPosition();
2233 while ( pos )
2235 int index = GetNextSelectedItem(pos);
2236 StartDiffTwo(index);
2239 break;
2240 case IDSVNLC_GNUDIFF1:
2242 // SVNDiff diff(NULL, this->m_hWnd, true);
2244 // if (entry->remotestatus <= git_wc_status_normal)
2245 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2246 // else
2247 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2248 if(m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
2250 CString fromwhere;
2251 if(m_amend)
2252 fromwhere = _T("~1");
2253 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,GitRev::GetWorkingCopy(),
2254 *filepath,GitRev::GetHead()+fromwhere);
2256 else
2258 if((filepath->m_ParentNo&(PARENT_MASK|MERGE_MASK)) ==0)
2259 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_CurrentVersion,
2260 *filepath,m_CurrentVersion+_T("~1"));
2261 else
2263 CString str;
2264 if(filepath->m_ParentNo & MERGE_MASK)
2266 }else
2268 str.Format(_T("%s^%d"),m_CurrentVersion,(filepath->m_ParentNo&PARENT_MASK)+1);
2271 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_CurrentVersion,
2272 *filepath,str, false,false,false,
2273 !!(filepath->m_ParentNo & MERGE_MASK));
2277 break;
2278 case IDSVNLC_GNUDIFF2:
2280 // SVNDiff diff(NULL, this->m_hWnd, true);
2282 // if (entry->remotestatus <= git_wc_status_normal)
2283 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2284 // else
2285 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2287 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_Rev1,
2288 *filepath,m_Rev2);
2290 break;
2292 case IDSVNLC_ADD:
2293 { // The add went ok, but we now need to run through the selected items again
2294 // and update their status
2295 std::vector<int> selectIndex;
2297 POSITION pos = GetFirstSelectedItemPosition();
2298 int index;
2299 while ((index = GetNextSelectedItem(pos)) >= 0)
2301 selectIndex.push_back(index);
2303 for(int i=0;i<selectIndex.size();i++)
2305 index=selectIndex[i];
2307 CTGitPath * path=(CTGitPath*)GetItemData(index);
2308 ASSERT(path);
2309 if(path == NULL)
2310 continue;
2311 CString cmd;
2312 cmd.Format(_T("git.exe add -- \"%s\""),path->GetGitPathString());
2313 CString output;
2314 if(!g_Git.Run(cmd,&output,CP_ACP))
2316 path->m_Action = CTGitPath::LOGACTIONS_ADDED;
2317 SetEntryCheck(path,index,true);
2319 SetItemGroup(index,0);
2320 this->m_StatusFileList.AddPath(*path);
2321 this->m_UnRevFileList.RemoveItem(*path);
2322 this->m_IgnoreFileList.RemoveItem(*path);
2324 Show(this->m_dwShow,0,true,true,true);
2329 break;
2331 case IDSVNLC_DELETE:
2333 //Collect paths
2334 std::vector<int> selectIndex;
2336 POSITION pos = GetFirstSelectedItemPosition();
2337 int index;
2338 while ((index = GetNextSelectedItem(pos)) >= 0)
2340 selectIndex.push_back(index);
2343 //Create file-list ('\0' separated) for SHFileOperation
2344 CString filelist;
2345 for(int i=0;i<selectIndex.size();i++)
2347 index=selectIndex[i];
2349 CTGitPath * path=(CTGitPath*)GetItemData(index);
2350 ASSERT(path);
2351 if(path == NULL)
2352 continue;
2354 filelist += path->GetWinPathString();
2355 filelist += _T("|");
2357 filelist += _T("|");
2358 int len = filelist.GetLength();
2359 TCHAR * buf = new TCHAR[len+2];
2360 _tcscpy_s(buf, len+2, filelist);
2361 for (int i=0; i<len; ++i)
2362 if (buf[i] == '|')
2363 buf[i] = 0;
2364 SHFILEOPSTRUCT fileop;
2365 fileop.hwnd = this->m_hWnd;
2366 fileop.wFunc = FO_DELETE;
2367 fileop.pFrom = buf;
2368 fileop.pTo = NULL;
2369 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
2370 fileop.lpszProgressTitle = _T("deleting file");
2371 int result = SHFileOperation(&fileop);
2372 delete [] buf;
2374 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
2376 SetRedraw(FALSE);
2377 POSITION pos = NULL;
2378 while ((pos = GetFirstSelectedItemPosition()) != 0)
2380 int index = GetNextSelectedItem(pos);
2381 if (GetCheck(index))
2382 m_nSelected--;
2383 m_nTotal--;
2385 RemoveListEntry(index);
2387 SetRedraw(TRUE);
2390 break;
2392 case IDSVNLC_BLAME:
2394 CAppUtils::LaunchTortoiseBlame(g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath(), m_CurrentVersion);
2396 break;
2398 case IDSVNLC_LOG:
2400 CString sCmd;
2401 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\""),
2402 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath());
2404 CAppUtils::LaunchApplication(sCmd, NULL, false);
2406 break;
2408 case IDSVNLC_EDITCONFLICT:
2410 CAppUtils::ConflictEdit(*filepath,false,this->m_bIsRevertTheirMy);
2411 break;
2413 case IDSVNLC_RESOLVETHEIRS: //follow up
2414 case IDSVNLC_RESOLVEMINE: //follow up
2415 case IDSVNLC_RESOLVECONFLICT:
2417 if (CMessageBox::Show(m_hWnd, IDS_PROC_RESOLVE, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO)==IDYES)
2419 POSITION pos = GetFirstSelectedItemPosition();
2420 while (pos != 0)
2422 int index;
2423 index = GetNextSelectedItem(pos);
2424 CTGitPath * fentry =(CTGitPath*) this->GetItemData(index);
2425 if(fentry == NULL)
2426 continue;
2427 CString gitcmd,output;
2428 output.Empty();
2430 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDSVNLC_RESOLVETHEIRS) ||
2431 ((this->m_bIsRevertTheirMy)&&cmd == IDSVNLC_RESOLVEMINE) )
2433 gitcmd.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry->GetGitPathString());
2434 if(g_Git.Run(gitcmd,&output,CP_ACP))
2436 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2437 continue;
2440 output.Empty();
2441 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDSVNLC_RESOLVEMINE) ||
2442 ((this->m_bIsRevertTheirMy)&&cmd == IDSVNLC_RESOLVETHEIRS) )
2444 gitcmd.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry->GetGitPathString());
2445 if(g_Git.Run(gitcmd,&output,CP_ACP))
2447 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2448 continue;
2452 output.Empty();
2453 if ( fentry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
2455 gitcmd.Format(_T("git.exe add -- \"%s\""),fentry->GetGitPathString());
2456 if(g_Git.Run(gitcmd,&output,CP_ACP))
2458 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2459 }else
2461 fentry->m_Action |= CTGitPath::LOGACTIONS_MODIFIED;
2462 fentry->m_Action &=~CTGitPath::LOGACTIONS_UNMERGED;
2466 CAppUtils::RemoveTempMergeFile(*fentry);
2469 Show(m_dwShow, 0, m_bShowFolders,0,true);
2472 break;
2474 case IDSVNLC_IGNORE:
2476 CTGitPathList ignorelist;
2477 //std::vector<CString> toremove;
2478 FillListOfSelectedItemPaths(ignorelist, true);
2479 SetRedraw(FALSE);
2481 if(!CAppUtils::IgnoreFile(ignorelist,false))
2482 break;
2484 for(int i=0;i<ignorelist.GetCount();i++)
2486 int nListboxEntries = GetItemCount();
2487 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2489 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2490 if (path->GetGitPathString()==ignorelist[i].GetGitPathString())
2492 RemoveListEntry(nItem);
2493 break;
2497 SetRedraw(TRUE);
2499 #if 0
2500 CTSVNPathList ignorelist;
2501 std::vector<CString> toremove;
2502 FillListOfSelectedItemPaths(ignorelist, true);
2503 SetRedraw(FALSE);
2504 for (int j=0; j<ignorelist.GetCount(); ++j)
2506 int nListboxEntries = GetItemCount();
2507 for (int i=0; i<nListboxEntries; ++i)
2509 if (GetListEntry(i)->GetPath().IsEquivalentTo(ignorelist[j]))
2511 selIndex = i;
2512 break;
2515 CString name = CPathUtils::PathPatternEscape(ignorelist[j].GetFileOrDirectoryName());
2516 CTSVNPath parentfolder = ignorelist[j].GetContainingDirectory();
2517 SVNProperties props(parentfolder, SVNRev::REV_WC, false);
2518 CStringA value;
2519 for (int i=0; i<props.GetCount(); i++)
2521 CString propname(props.GetItemName(i).c_str());
2522 if (propname.CompareNoCase(_T("git:ignore"))==0)
2524 stdstring stemp;
2525 // treat values as normal text even if they're not
2526 value = (char *)props.GetItemValue(i).c_str();
2529 if (value.IsEmpty())
2530 value = name;
2531 else
2533 value = value.Trim("\n\r");
2534 value += "\n";
2535 value += name;
2536 value.Remove('\r');
2538 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
2540 CString temp;
2541 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
2542 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2543 break;
2545 if (GetCheck(selIndex))
2546 m_nSelected--;
2547 m_nTotal--;
2549 // now, if we ignored a folder, remove all its children
2550 if (ignorelist[j].IsDirectory())
2552 for (int i=0; i<(int)m_arListArray.size(); ++i)
2554 FileEntry * entry = GetListEntry(i);
2555 if (entry->status == git_wc_status_unversioned)
2557 if (!ignorelist[j].IsEquivalentTo(entry->GetPath())&&(ignorelist[j].IsAncestorOf(entry->GetPath())))
2559 entry->status = git_wc_status_ignored;
2560 entry->textstatus = git_wc_status_ignored;
2561 if (GetCheck(i))
2562 m_nSelected--;
2563 toremove.push_back(entry->GetPath().GetSVNPathString());
2569 CTSVNPath basepath = m_arStatusArray[m_arListArray[selIndex]]->basepath;
2571 FileEntry * entry = m_arStatusArray[m_arListArray[selIndex]];
2572 if ( entry->status == git_wc_status_unversioned ) // keep "deleted" items
2573 toremove.push_back(entry->GetPath().GetSVNPathString());
2575 if (!m_bIgnoreRemoveOnly)
2577 SVNStatus status;
2578 git_wc_status2_t * s;
2579 CTSVNPath gitPath;
2580 s = status.GetFirstFileStatus(parentfolder, gitPath, false, git_depth_empty);
2581 // first check if the folder isn't already present in the list
2582 bool bFound = false;
2583 nListboxEntries = GetItemCount();
2584 for (int i=0; i<nListboxEntries; ++i)
2586 FileEntry * entry = GetListEntry(i);
2587 if (entry->path.IsEquivalentTo(gitPath))
2589 bFound = true;
2590 break;
2593 if (!bFound)
2595 if (s!=0)
2597 FileEntry * entry = new FileEntry();
2598 entry->path = gitPath;
2599 entry->basepath = basepath;
2600 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
2601 entry->textstatus = s->text_status;
2602 entry->propstatus = s->prop_status;
2603 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
2604 entry->remotetextstatus = s->repos_text_status;
2605 entry->remotepropstatus = s->repos_prop_status;
2606 entry->inunversionedfolder = FALSE;
2607 entry->checked = true;
2608 entry->inexternal = false;
2609 entry->direct = false;
2610 entry->isfolder = true;
2611 entry->last_commit_date = 0;
2612 entry->last_commit_rev = 0;
2613 entry->remoterev = 0;
2614 if (s->entry)
2616 if (s->entry->url)
2618 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
2621 if (s->entry && s->entry->present_props)
2623 entry->present_props = s->entry->present_props;
2625 m_arStatusArray.push_back(entry);
2626 m_arListArray.push_back(m_arStatusArray.size()-1);
2627 AddEntry(entry, langID, GetItemCount());
2632 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
2634 int nListboxEntries = GetItemCount();
2635 for (int i=0; i<nListboxEntries; ++i)
2637 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
2639 RemoveListEntry(i);
2640 break;
2644 SetRedraw(TRUE);
2646 #endif
2647 break;
2648 case IDSVNLC_IGNOREMASK:
2650 CString common;
2651 CString ext=filepath->GetFileExtension();
2652 CTGitPathList ignorelist;
2653 FillListOfSelectedItemPaths(ignorelist, true);
2654 SetRedraw(FALSE);
2656 CAppUtils::IgnoreFile(ignorelist,true);
2658 common=ignorelist.GetCommonRoot().GetGitPathString();
2660 for (int i=0; i< GetItemCount(); ++i)
2662 CTGitPath *path=(CTGitPath*)GetItemData(i);
2663 if(!( path->m_Action & CTGitPath::LOGACTIONS_UNVER))
2664 continue;
2665 if( path->GetGitPathString().Left(common.GetLength()) == common )
2667 if (path->GetFileExtension()==ext)
2669 RemoveListEntry(i);
2670 i--; // remove index i at item, new one will replace.
2675 CWnd* pParent = GetParent();
2676 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2678 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
2681 SetRedraw(TRUE);
2683 #if 0
2684 std::set<CTSVNPath> parentlist;
2685 for (int i=0; i<ignorelist.GetCount(); ++i)
2687 parentlist.insert(ignorelist[i].GetContainingDirectory());
2689 std::set<CTSVNPath>::iterator it;
2690 std::vector<CString> toremove;
2692 for (it = parentlist.begin(); it != parentlist.end(); ++it)
2694 CTSVNPath parentFolder = (*it).GetDirectory();
2695 SVNProperties props(parentFolder, SVNRev::REV_WC, false);
2696 CStringA value;
2697 for (int i=0; i<props.GetCount(); i++)
2699 CString propname(props.GetItemName(i).c_str());
2700 if (propname.CompareNoCase(_T("git:ignore"))==0)
2702 stdstring stemp;
2703 // treat values as normal text even if they're not
2704 value = (char *)props.GetItemValue(i).c_str();
2707 if (value.IsEmpty())
2708 value = name;
2709 else
2711 value = value.Trim("\n\r");
2712 value += "\n";
2713 value += name;
2714 value.Remove('\r');
2716 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
2718 CString temp;
2719 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
2720 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2722 else
2724 CTSVNPath basepath;
2725 int nListboxEntries = GetItemCount();
2726 for (int i=0; i<nListboxEntries; ++i)
2728 FileEntry * entry = GetListEntry(i);
2729 ASSERT(entry != NULL);
2730 if (entry == NULL)
2731 continue;
2732 if (basepath.IsEmpty())
2733 basepath = entry->basepath;
2734 // since we ignored files with a mask (e.g. *.exe)
2735 // we have to find find all files in the same
2736 // folder (IsAncestorOf() returns TRUE for _all_ children,
2737 // not just the immediate ones) which match the
2738 // mask and remove them from the list too.
2739 if ((entry->status == git_wc_status_unversioned)&&(parentFolder.IsAncestorOf(entry->path)))
2741 CString f = entry->path.GetSVNPathString();
2742 if (f.Mid(parentFolder.GetSVNPathString().GetLength()).Find('/')<=0)
2744 if (CStringUtils::WildCardMatch(name, f))
2746 if (GetCheck(i))
2747 m_nSelected--;
2748 m_nTotal--;
2749 toremove.push_back(f);
2754 if (!m_bIgnoreRemoveOnly)
2756 SVNStatus status;
2757 git_wc_status2_t * s;
2758 CTSVNPath gitPath;
2759 s = status.GetFirstFileStatus(parentFolder, gitPath, false, git_depth_empty);
2760 if (s!=0)
2762 // first check if the folder isn't already present in the list
2763 bool bFound = false;
2764 for (int i=0; i<nListboxEntries; ++i)
2766 FileEntry * entry = GetListEntry(i);
2767 if (entry->path.IsEquivalentTo(gitPath))
2769 bFound = true;
2770 break;
2773 if (!bFound)
2775 FileEntry * entry = new FileEntry();
2776 entry->path = gitPath;
2777 entry->basepath = basepath;
2778 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
2779 entry->textstatus = s->text_status;
2780 entry->propstatus = s->prop_status;
2781 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
2782 entry->remotetextstatus = s->repos_text_status;
2783 entry->remotepropstatus = s->repos_prop_status;
2784 entry->inunversionedfolder = false;
2785 entry->checked = true;
2786 entry->inexternal = false;
2787 entry->direct = false;
2788 entry->isfolder = true;
2789 entry->last_commit_date = 0;
2790 entry->last_commit_rev = 0;
2791 entry->remoterev = 0;
2792 if (s->entry)
2794 if (s->entry->url)
2796 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
2799 if (s->entry && s->entry->present_props)
2801 entry->present_props = s->entry->present_props;
2803 m_arStatusArray.push_back(entry);
2804 m_arListArray.push_back(m_arStatusArray.size()-1);
2805 AddEntry(entry, langID, GetItemCount());
2811 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
2813 int nListboxEntries = GetItemCount();
2814 for (int i=0; i<nListboxEntries; ++i)
2816 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
2818 RemoveListEntry(i);
2819 break;
2823 SetRedraw(TRUE);
2825 #endif
2826 break;
2828 case IDSVNLC_REVERT:
2830 // If at least one item is not in the status "added"
2831 // we ask for a confirmation
2832 BOOL bConfirm = FALSE;
2833 POSITION pos = GetFirstSelectedItemPosition();
2834 int index;
2835 while ((index = GetNextSelectedItem(pos)) >= 0)
2837 //FileEntry * fentry = GetListEntry(index);
2838 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
2839 if(fentry && fentry->m_Action &CTGitPath::LOGACTIONS_MODIFIED )
2841 bConfirm = TRUE;
2842 break;
2846 CString str;
2847 str.Format(IDS_PROC_WARNREVERT,GetSelectedCount());
2849 if (!bConfirm || CMessageBox::Show(this->m_hWnd, str, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION)==IDYES)
2851 CTGitPathList targetList;
2852 FillListOfSelectedItemPaths(targetList);
2854 // make sure that the list is reverse sorted, so that
2855 // children are removed before any parents
2856 targetList.SortByPathname(true);
2858 // put all reverted files in the trashbin, except the ones with 'added'
2859 // status because they are not restored by the revert.
2860 CTGitPathList delList;
2861 POSITION pos = GetFirstSelectedItemPosition();
2862 int index;
2863 while ((index = GetNextSelectedItem(pos)) >= 0)
2865 CTGitPath *entry=(CTGitPath *)GetItemData(index);
2866 if (entry&&(!(entry->m_Action& CTGitPath::LOGACTIONS_ADDED))
2867 && (!(entry->m_Action& CTGitPath::LOGACTIONS_REPLACED)))
2869 CTGitPath fullpath;
2870 fullpath.SetFromWin(g_Git.m_CurrentDir+_T("\\")+entry->GetWinPath());
2871 delList.AddPath(fullpath);
2874 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2875 delList.DeleteAllFiles(true);
2877 if (g_Git.Revert(targetList))
2879 CMessageBox::Show(this->m_hWnd, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR);
2881 else
2883 bool updateStatusList = false;
2884 for(int i=0;i<targetList.GetCount();i++)
2886 int nListboxEntries = GetItemCount();
2887 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2889 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2890 if (path->GetGitPathString()==targetList[i].GetGitPathString())
2892 if(path->m_Action & CTGitPath::LOGACTIONS_ADDED)
2894 path->m_Action = CTGitPath::LOGACTIONS_UNVER;
2895 SetEntryCheck(path,nItem,false);
2896 updateStatusList = true;
2897 SetItemGroup(nItem,1);
2898 this->m_StatusFileList.RemoveItem(*path);
2899 this->m_UnRevFileList.AddPath(*path);
2900 //this->m_IgnoreFileList.RemoveItem(*path);
2902 }else
2904 RemoveListEntry(nItem);
2906 break;
2910 SetRedraw(TRUE);
2911 SaveColumnWidths();
2912 Show(m_dwShow, 0, m_bShowFolders,updateStatusList,true);
2913 NotifyCheck();
2917 break;
2919 case IDSVNLC_COPY:
2920 CopySelectedEntriesToClipboard(0);
2921 break;
2922 case IDSVNLC_COPYEXT:
2923 CopySelectedEntriesToClipboard((DWORD)-1);
2924 break;
2926 case IDSVNLC_SAVEAS:
2927 FileSaveAs(filepath);
2928 break;
2930 case IDSVNLC_REVERTTOREV:
2931 RevertSelectedItemToVersion();
2932 break;
2933 #if 0
2934 case IDSVNLC_PROPERTIES:
2936 CTSVNPathList targetList;
2937 FillListOfSelectedItemPaths(targetList);
2938 CEditPropertiesDlg dlg;
2939 dlg.SetPathList(targetList);
2940 dlg.DoModal();
2941 if (dlg.HasChanged())
2943 // since the user might have changed/removed/added
2944 // properties recursively, we don't really know
2945 // which items have changed their status.
2946 // So tell the parent to do a refresh.
2947 CWnd* pParent = GetParent();
2948 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2950 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
2954 break;
2955 case IDSVNLC_COMMIT:
2957 CTSVNPathList targetList;
2958 FillListOfSelectedItemPaths(targetList);
2959 CTSVNPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
2960 VERIFY(targetList.WriteToFile(tempFile.GetWinPathString()));
2961 CString commandline = CPathUtils::GetAppDirectory();
2962 commandline += _T("TortoiseProc.exe /command:commit /pathfile:\"");
2963 commandline += tempFile.GetWinPathString();
2964 commandline += _T("\"");
2965 commandline += _T(" /deletepathfile");
2966 CAppUtils::LaunchApplication(commandline, NULL, false);
2968 break;
2970 case IDSVNLC_COMPAREWC:
2972 POSITION pos = GetFirstSelectedItemPosition();
2973 while ( pos )
2975 int index = GetNextSelectedItem(pos);
2976 FileEntry * entry = GetListEntry(index);
2977 ASSERT(entry != NULL);
2978 if (entry == NULL)
2979 continue;
2980 SVNDiff diff(NULL, m_hWnd, true);
2981 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2982 git_revnum_t baseRev = entry->Revision;
2983 diff.DiffFileAgainstBase(
2984 entry->path, baseRev, entry->textstatus, entry->propstatus);
2987 break;
2988 case IDSVNLC_GNUDIFF1:
2990 SVNDiff diff(NULL, this->m_hWnd, true);
2992 if (entry->remotestatus <= git_wc_status_normal)
2993 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2994 else
2995 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2997 break;
2998 case IDSVNLC_UPDATE:
3000 CTSVNPathList targetList;
3001 FillListOfSelectedItemPaths(targetList);
3002 bool bAllExist = true;
3003 for (int i=0; i<targetList.GetCount(); ++i)
3005 if (!targetList[i].Exists())
3007 bAllExist = false;
3008 break;
3011 if (bAllExist)
3013 CSVNProgressDlg dlg;
3014 dlg.SetCommand(CSVNProgressDlg::SVNProgress_Update);
3015 dlg.SetPathList(targetList);
3016 dlg.SetRevision(SVNRev::REV_HEAD);
3017 dlg.DoModal();
3019 else
3021 CString sTempFile = CTempFiles::Instance().GetTempFilePath(false).GetWinPathString();
3022 targetList.WriteToFile(sTempFile, false);
3023 CString sCmd;
3024 sCmd.Format(_T("\"%s\" /command:update /rev /pathfile:\"%s\" /deletepathfile"),
3025 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)sTempFile);
3027 CAppUtils::LaunchApplication(sCmd, NULL, false);
3030 break;
3032 case IDSVNLC_REMOVE:
3034 SVN git;
3035 CTSVNPathList itemsToRemove;
3036 FillListOfSelectedItemPaths(itemsToRemove);
3038 // We must sort items before removing, so that files are always removed
3039 // *before* their parents
3040 itemsToRemove.SortByPathname(true);
3042 bool bSuccess = false;
3043 if (git.Remove(itemsToRemove, FALSE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3045 bSuccess = true;
3047 else
3049 if ((git.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE) ||
3050 (git.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))
3052 CString msg, yes, no, yestoall;
3053 msg.Format(IDS_PROC_REMOVEFORCE, (LPCTSTR)git.GetLastErrorMessage());
3054 yes.LoadString(IDS_MSGBOX_YES);
3055 no.LoadString(IDS_MSGBOX_NO);
3056 yestoall.LoadString(IDS_PROC_YESTOALL);
3057 UINT ret = CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_ERROR, yes, no, yestoall);
3058 if ((ret == 1)||(ret==3))
3060 if (!git.Remove(itemsToRemove, TRUE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3062 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3064 else
3065 bSuccess = true;
3068 else
3069 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3071 if (bSuccess)
3073 // The remove went ok, but we now need to run through the selected items again
3074 // and update their status
3075 POSITION pos = GetFirstSelectedItemPosition();
3076 int index;
3077 std::vector<int> entriesToRemove;
3078 while ((index = GetNextSelectedItem(pos)) >= 0)
3080 FileEntry * e = GetListEntry(index);
3081 if (!bShift &&
3082 ((e->textstatus == git_wc_status_unversioned)||
3083 (e->textstatus == git_wc_status_none)||
3084 (e->textstatus == git_wc_status_ignored)))
3086 if (GetCheck(index))
3087 m_nSelected--;
3088 m_nTotal--;
3089 entriesToRemove.push_back(index);
3091 else
3093 e->textstatus = git_wc_status_deleted;
3094 e->status = git_wc_status_deleted;
3095 SetEntryCheck(e,index,true);
3098 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3100 RemoveListEntry(*it);
3103 SaveColumnWidths();
3104 Show(m_dwShow, 0, m_bShowFolders);
3105 NotifyCheck();
3107 break;
3108 case IDSVNLC_DELETE:
3110 CTSVNPathList pathlist;
3111 FillListOfSelectedItemPaths(pathlist);
3112 pathlist.RemoveChildren();
3113 CString filelist;
3114 for (INT_PTR i=0; i<pathlist.GetCount(); ++i)
3116 filelist += pathlist[i].GetWinPathString();
3117 filelist += _T("|");
3119 filelist += _T("|");
3120 int len = filelist.GetLength();
3121 TCHAR * buf = new TCHAR[len+2];
3122 _tcscpy_s(buf, len+2, filelist);
3123 for (int i=0; i<len; ++i)
3124 if (buf[i] == '|')
3125 buf[i] = 0;
3126 SHFILEOPSTRUCT fileop;
3127 fileop.hwnd = this->m_hWnd;
3128 fileop.wFunc = FO_DELETE;
3129 fileop.pFrom = buf;
3130 fileop.pTo = NULL;
3131 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
3132 fileop.lpszProgressTitle = _T("deleting file");
3133 int result = SHFileOperation(&fileop);
3134 delete [] buf;
3136 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
3138 SetRedraw(FALSE);
3139 POSITION pos = NULL;
3140 CTSVNPathList deletedlist; // to store list of deleted folders
3141 while ((pos = GetFirstSelectedItemPosition()) != 0)
3143 int index = GetNextSelectedItem(pos);
3144 if (GetCheck(index))
3145 m_nSelected--;
3146 m_nTotal--;
3147 FileEntry * fentry = GetListEntry(index);
3148 if ((fentry)&&(fentry->isfolder))
3149 deletedlist.AddPath(fentry->path);
3150 RemoveListEntry(index);
3152 // now go through the list of deleted folders
3153 // and remove all their children from the list too!
3154 int nListboxEntries = GetItemCount();
3155 for (int folderindex = 0; folderindex < deletedlist.GetCount(); ++folderindex)
3157 CTSVNPath folderpath = deletedlist[folderindex];
3158 for (int i=0; i<nListboxEntries; ++i)
3160 FileEntry * entry = GetListEntry(i);
3161 if (folderpath.IsAncestorOf(entry->path))
3163 RemoveListEntry(i--);
3164 nListboxEntries--;
3168 SetRedraw(TRUE);
3171 break;
3174 case IDSVNLC_ADD:
3176 SVN git;
3177 CTSVNPathList itemsToAdd;
3178 FillListOfSelectedItemPaths(itemsToAdd);
3180 // We must sort items before adding, so that folders are always added
3181 // *before* any of their children
3182 itemsToAdd.SortByPathname();
3184 ProjectProperties props;
3185 props.ReadPropsPathList(itemsToAdd);
3186 if (git.Add(itemsToAdd, &props, git_depth_empty, TRUE, TRUE, TRUE))
3188 // The add went ok, but we now need to run through the selected items again
3189 // and update their status
3190 POSITION pos = GetFirstSelectedItemPosition();
3191 int index;
3192 while ((index = GetNextSelectedItem(pos)) >= 0)
3194 FileEntry * e = GetListEntry(index);
3195 e->textstatus = git_wc_status_added;
3196 e->propstatus = git_wc_status_none;
3197 e->status = git_wc_status_added;
3198 SetEntryCheck(e,index,true);
3201 else
3203 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3205 SaveColumnWidths();
3206 Show(m_dwShow, 0, m_bShowFolders);
3207 NotifyCheck();
3209 break;
3210 case IDSVNLC_ADD_RECURSIVE:
3212 CTSVNPathList itemsToAdd;
3213 FillListOfSelectedItemPaths(itemsToAdd);
3215 CAddDlg dlg;
3216 dlg.m_pathList = itemsToAdd;
3217 if (dlg.DoModal() == IDOK)
3219 if (dlg.m_pathList.GetCount() == 0)
3220 break;
3221 CSVNProgressDlg progDlg;
3222 progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Add);
3223 progDlg.SetPathList(dlg.m_pathList);
3224 ProjectProperties props;
3225 props.ReadPropsPathList(dlg.m_pathList);
3226 progDlg.SetProjectProperties(props);
3227 progDlg.SetItemCount(dlg.m_pathList.GetCount());
3228 progDlg.DoModal();
3230 // refresh!
3231 CWnd* pParent = GetParent();
3232 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3234 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3238 break;
3240 case IDSVNLC_REPAIRMOVE:
3242 POSITION pos = GetFirstSelectedItemPosition();
3243 int index = GetNextSelectedItem(pos);
3244 FileEntry * entry1 = NULL;
3245 FileEntry * entry2 = NULL;
3246 if (index >= 0)
3248 entry1 = GetListEntry(index);
3249 git_wc_status_kind status1 = git_wc_status_none;
3250 git_wc_status_kind status2 = git_wc_status_none;
3251 if (entry1)
3253 status1 = entry1->status;
3254 index = GetNextSelectedItem(pos);
3255 if (index >= 0)
3257 entry2 = GetListEntry(index);
3258 if (entry2)
3260 status2 = entry2->status;
3261 if (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned)
3263 FileEntry * tempentry = entry1;
3264 entry1 = entry2;
3265 entry2 = tempentry;
3267 // entry1 was renamed to entry2 but outside of Subversion
3268 // fix this by moving entry2 back to entry1 first,
3269 // then do an git-move from entry1 to entry2
3270 if (MoveFile(entry2->GetPath().GetWinPath(), entry1->GetPath().GetWinPath()))
3272 SVN git;
3273 if (!git.Move(CTSVNPathList(entry1->GetPath()), entry2->GetPath(), TRUE))
3275 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3277 else
3279 // check the previously unversioned item
3280 entry1->checked = true;
3281 // fixing the move was successful. We have to adjust the new status of the
3282 // files.
3283 // Since we don't know if the moved/renamed file had local modifications or not,
3284 // we can't guess the new status. That means we have to refresh...
3285 CWnd* pParent = GetParent();
3286 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3288 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3292 else
3294 LPVOID lpMsgBuf;
3295 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
3296 FORMAT_MESSAGE_FROM_SYSTEM |
3297 FORMAT_MESSAGE_IGNORE_INSERTS,
3298 NULL,
3299 GetLastError(),
3300 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
3301 (LPTSTR) &lpMsgBuf,
3303 NULL
3305 MessageBox((LPCTSTR)lpMsgBuf, _T("Error"), MB_OK | MB_ICONINFORMATION );
3306 LocalFree( lpMsgBuf );
3313 break;
3314 case IDSVNLC_REMOVEFROMCS:
3316 CTSVNPathList changelistItems;
3317 FillListOfSelectedItemPaths(changelistItems);
3318 SVN git;
3319 SetRedraw(FALSE);
3320 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
3322 // The changelists were removed, but we now need to run through the selected items again
3323 // and update their changelist
3324 POSITION pos = GetFirstSelectedItemPosition();
3325 int index;
3326 std::vector<int> entriesToRemove;
3327 while ((index = GetNextSelectedItem(pos)) >= 0)
3329 FileEntry * e = GetListEntry(index);
3330 if (e)
3332 e->changelist.Empty();
3333 if (e->status == git_wc_status_normal)
3335 // remove the entry completely
3336 entriesToRemove.push_back(index);
3338 else
3339 SetItemGroup(index, 0);
3342 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3344 RemoveListEntry(*it);
3346 // TODO: Should we go through all entries here and check if we also could
3347 // remove the changelist from m_changelists ?
3349 else
3351 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3353 SetRedraw(TRUE);
3355 break;
3356 case IDSVNLC_CREATEIGNORECS:
3357 CreateChangeList(SVNSLC_IGNORECHANGELIST);
3358 break;
3359 case IDSVNLC_CREATECS:
3361 CCreateChangelistDlg dlg;
3362 if (dlg.DoModal() == IDOK)
3364 CreateChangeList(dlg.m_sName);
3367 break;
3368 default:
3370 if (cmd < IDSVNLC_MOVETOCS)
3371 break;
3372 CTSVNPathList changelistItems;
3373 FillListOfSelectedItemPaths(changelistItems);
3375 // find the changelist name
3376 CString sChangelist;
3377 int cmdID = IDSVNLC_MOVETOCS;
3378 SetRedraw(FALSE);
3379 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
3381 if ((it->first.Compare(SVNSLC_IGNORECHANGELIST))&&(entry->changelist.Compare(it->first)))
3383 if (cmd == cmdID)
3385 sChangelist = it->first;
3387 cmdID++;
3390 if (!sChangelist.IsEmpty())
3392 SVN git;
3393 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
3395 // The changelists were moved, but we now need to run through the selected items again
3396 // and update their changelist
3397 POSITION pos = GetFirstSelectedItemPosition();
3398 int index;
3399 while ((index = GetNextSelectedItem(pos)) >= 0)
3401 FileEntry * e = GetListEntry(index);
3402 e->changelist = sChangelist;
3403 if (!e->IsFolder())
3405 if (m_changelists.find(e->changelist)!=m_changelists.end())
3406 SetItemGroup(index, m_changelists[e->changelist]);
3407 else
3408 SetItemGroup(index, 0);
3412 else
3414 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3417 SetRedraw(TRUE);
3419 break;
3420 #endif
3422 } // switch (cmd)
3423 m_bBlock = FALSE;
3424 AfxGetApp()->DoWaitCursor(-1);
3425 GetStatisticsString();
3426 //int iItemCountAfterMenuCmd = GetItemCount();
3427 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
3429 // CWnd* pParent = GetParent();
3430 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3431 // {
3432 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
3433 // }
3435 } // if (popup.CreatePopupMenu())
3436 } // if (selIndex >= 0)
3440 void CGitStatusListCtrl::OnContextMenuHeader(CWnd * pWnd, CPoint point)
3442 Locker lock(m_critSec);
3443 m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
3446 void CGitStatusListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
3449 if (pWnd == this)
3451 OnContextMenuList(pWnd, point);
3452 } // if (pWnd == this)
3453 else if (pWnd == GetHeaderCtrl())
3455 OnContextMenuHeader(pWnd, point);
3459 void CGitStatusListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
3462 Locker lock(m_critSec);
3463 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
3464 *pResult = 0;
3465 if (m_bBlock)
3466 return;
3468 if (pNMLV->iItem < 0)
3470 if (!IsGroupViewEnabled())
3471 return;
3472 POINT pt;
3473 DWORD ptW = GetMessagePos();
3474 pt.x = GET_X_LPARAM(ptW);
3475 pt.y = GET_Y_LPARAM(ptW);
3476 ScreenToClient(&pt);
3477 int group = GetGroupFromPoint(&pt);
3478 if (group < 0)
3479 return;
3480 // check/uncheck the whole group depending on the check-state
3481 // of the first item in the group
3482 m_bBlock = true;
3483 bool bCheck = false;
3484 bool bFirst = false;
3485 LVITEM lv;
3486 for (int i=0; i<GetItemCount(); ++i)
3488 SecureZeroMemory(&lv, sizeof(LVITEM));
3489 lv.mask = LVIF_GROUPID;
3490 lv.iItem = i;
3491 GetItem(&lv);
3492 if (lv.iGroupId == group)
3494 CTGitPath *entry=(CTGitPath*)GetItemData(i);
3496 if (!bFirst)
3498 bCheck = !GetCheck(i);
3499 bFirst = true;
3501 if (entry)
3503 bool bOldCheck = !!GetCheck(i);
3504 SetEntryCheck(entry, i, bCheck);
3505 if (bCheck != bOldCheck)
3507 if (bCheck)
3508 m_nSelected++;
3509 else
3510 m_nSelected--;
3515 GetStatisticsString();
3516 m_bBlock = false;
3517 NotifyCheck();
3518 return;
3521 CTGitPath *file=(CTGitPath*)GetItemData(pNMLV->iItem);
3523 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER) {
3524 OpenFile(file, OPEN);
3525 return;
3527 if( file->m_Action&CTGitPath::LOGACTIONS_UNMERGED )
3529 CAppUtils::ConflictEdit(*file,false,m_bIsRevertTheirMy);
3531 }else
3533 if( (!m_Rev1.IsEmpty()) || (!m_Rev1.IsEmpty())) // m_Rev1 twice???
3534 StartDiffTwo(pNMLV->iItem);
3535 else
3536 StartDiff(pNMLV->iItem);
3540 void CGitStatusListCtrl::StartDiffTwo(int fileindex)
3542 if(fileindex<0)
3543 return;
3545 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3547 CGitDiff::Diff(&file1,&file1,
3548 m_Rev1,
3549 m_Rev2);
3552 void CGitStatusListCtrl::StartDiffWC(int fileindex)
3554 if(fileindex<0)
3555 return;
3557 CString Ver;
3558 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
3559 return;
3561 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3563 CGitDiff::Diff(&file1,&file1, GIT_REV_ZERO, m_CurrentVersion);
3567 void CGitStatusListCtrl::StartDiff(int fileindex)
3569 if(fileindex<0)
3570 return;
3572 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3573 CTGitPath file2;
3574 if(file1.m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
3576 file2.SetFromGit(file1.GetGitOldPathString());
3577 }else
3579 file2=file1;
3582 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
3584 CString fromwhere;
3585 if(m_amend)
3586 fromwhere = _T("~1");
3587 if( g_Git.IsInitRepos())
3588 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
3589 GIT_REV_ZERO);
3590 else if( file1.m_Action&CTGitPath::LOGACTIONS_ADDED )
3591 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
3592 m_CurrentVersion+fromwhere,true);
3593 else if( file1.m_Action&CTGitPath::LOGACTIONS_DELETED )
3594 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
3595 GitRev::GetHead()+fromwhere,false);
3596 else
3597 CGitDiff::Diff(&file1,&file2,
3598 CString(GIT_REV_ZERO),
3599 GitRev::GetHead()+fromwhere);
3600 }else
3602 GitRev rev;
3603 CString fromwhere = m_CurrentVersion+_T("~1");
3604 if(m_amend)
3605 fromwhere = m_CurrentVersion+_T("~2");
3606 if(rev.GetCommit(fromwhere) || (file1.m_Action == file1.LOGACTIONS_ADDED))
3608 CGitDiff::DiffNull(&file1,m_CurrentVersion,true);
3610 } else if (file1.m_Action == file1.LOGACTIONS_DELETED) {
3611 CGitDiff::DiffNull(&file1,fromwhere,false);
3612 }else
3614 if( file1.m_ParentNo & MERGE_MASK)
3617 CTGitPath base,theirs, mine;
3619 CTGitPath merge=file1;
3620 CTGitPath directory = merge.GetDirectory();
3622 mine.SetFromGit(CAppUtils::GetMergeTempFile(_T("LOCAL"),merge));
3623 theirs.SetFromGit(CAppUtils::GetMergeTempFile(_T("REMOTE"),merge));
3624 base.SetFromGit(CAppUtils::GetMergeTempFile(_T("BASE"),merge));
3626 CFile tempfile;
3627 //create a empty file, incase stage is not three
3628 tempfile.Open(mine.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
3629 tempfile.Close();
3630 tempfile.Open(theirs.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
3631 tempfile.Close();
3632 tempfile.Open(base.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
3633 tempfile.Close();
3635 merge.SetFromGit(merge.GetGitPathString()+_T("Merged"));
3637 int parent1=-1, parent2 =-1;
3638 for(int i=0;i<this->m_arStatusArray.size();i++)
3640 if(m_arStatusArray[i]->GetGitPathString() == file1.GetGitPathString())
3642 if(m_arStatusArray[i]->m_ParentNo & MERGE_MASK)
3644 }else
3646 if(parent1<0)
3648 parent1 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
3649 }else if (parent2 <0)
3651 parent2 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
3657 if(g_Git.GetOneFile(m_CurrentVersion, file1, (CString&)merge.GetWinPathString()))
3659 CMessageBox::Show(NULL, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
3662 if(parent1>=0)
3664 CString str;
3665 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent1+1);
3667 if(g_Git.GetOneFile(str, file1, (CString&)mine.GetWinPathString()))
3669 CMessageBox::Show(NULL, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
3673 if(parent2>=0)
3675 CString str;
3676 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent2+1);
3678 if(g_Git.GetOneFile(str, file1, (CString&)theirs.GetWinPathString()))
3680 CMessageBox::Show(NULL, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
3684 if(parent1>=0 && parent2>=0)
3686 CString cmd,output;
3687 cmd.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion, parent1+1,
3688 this->m_CurrentVersion,parent2+1);
3690 if(g_Git.Run(cmd,&output, CP_ACP))
3692 }else
3694 if(g_Git.GetOneFile(output.Left(40), file1, (CString&)base.GetWinPathString()))
3696 CMessageBox::Show(NULL, _T("Fail to get base file"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
3700 CAppUtils::StartExtMerge(base, theirs, mine, merge,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
3702 }else
3704 CString str;
3705 if( (file1.m_ParentNo&PARENT_MASK) == 0)
3707 str = _T("~1");
3708 }else
3710 str.Format(_T("^%d"), (file1.m_ParentNo&PARENT_MASK)+1);
3712 CGitDiff::Diff(&file1,&file2,
3713 m_CurrentVersion,
3714 m_CurrentVersion+str);
3718 #if 0
3719 if (fileindex < 0)
3720 return;
3721 FileEntry * entry = GetListEntry(fileindex);
3722 ASSERT(entry != NULL);
3723 if (entry == NULL)
3724 return;
3725 if (((entry->status == git_wc_status_normal)&&(entry->remotestatus <= git_wc_status_normal))||
3726 (entry->status == git_wc_status_unversioned)||(entry->status == git_wc_status_none))
3728 int ret = (int)ShellExecute(this->m_hWnd, NULL, entry->path.GetWinPath(), NULL, NULL, SW_SHOW);
3729 if (ret <= HINSTANCE_ERROR)
3731 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
3732 cmd += entry->path.GetWinPathString();
3733 CAppUtils::LaunchApplication(cmd, NULL, false);
3735 return;
3738 GitDiff diff(NULL, m_hWnd, true);
3739 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
3740 diff.DiffWCFile(
3741 entry->path, entry->textstatus, entry->propstatus,
3742 entry->remotetextstatus, entry->remotepropstatus);
3743 #endif
3746 CString CGitStatusListCtrl::GetStatisticsString(bool simple)
3749 CString sNormal, sAdded, sDeleted, sModified, sConflicted, sUnversioned, sRenamed;
3750 WORD langID = (WORD)(DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3751 TCHAR buf[MAX_STATUS_STRING_LENGTH];
3752 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal, buf, sizeof(buf)/sizeof(TCHAR), langID);
3753 sNormal = buf;
3754 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added, buf, sizeof(buf)/sizeof(TCHAR), langID);
3755 sAdded = buf;
3756 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted, buf, sizeof(buf)/sizeof(TCHAR), langID);
3757 sDeleted = buf;
3758 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified, buf, sizeof(buf)/sizeof(TCHAR), langID);
3759 sModified = buf;
3760 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted, buf, sizeof(buf)/sizeof(TCHAR), langID);
3761 sConflicted = buf;
3762 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned, buf, sizeof(buf)/sizeof(TCHAR), langID);
3763 sUnversioned = buf;
3764 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced, buf, sizeof(buf)/sizeof(TCHAR), langID);
3765 sRenamed = buf;
3766 CString sToolTip;
3767 if(simple)
3769 sToolTip.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d"),
3770 this->m_nLineAdded,this->m_nLineDeleted,
3771 (LPCTSTR)sModified, m_nModified,
3772 (LPCTSTR)sAdded, m_nAdded,
3773 (LPCTSTR)sDeleted, m_nDeleted,
3774 (LPCTSTR)sRenamed, m_nRenamed
3776 }else
3778 sToolTip.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d"),
3779 this->m_nLineAdded,this->m_nLineDeleted,
3780 (LPCTSTR)sNormal, m_nNormal,
3781 (LPCTSTR)sUnversioned, m_nUnversioned,
3782 (LPCTSTR)sModified, m_nModified,
3783 (LPCTSTR)sAdded, m_nAdded,
3784 (LPCTSTR)sDeleted, m_nDeleted,
3785 (LPCTSTR)sConflicted, m_nConflicted
3788 CString sStats;
3789 sStats.Format(IDS_COMMITDLG_STATISTICSFORMAT, m_nSelected, GetItemCount());
3790 if (m_pStatLabel)
3792 m_pStatLabel->SetWindowText(sStats);
3795 if (m_pSelectButton)
3797 if (m_nSelected == 0)
3798 m_pSelectButton->SetCheck(BST_UNCHECKED);
3799 else if (m_nSelected != GetItemCount())
3800 m_pSelectButton->SetCheck(BST_INDETERMINATE);
3801 else
3802 m_pSelectButton->SetCheck(BST_CHECKED);
3805 if (m_pConfirmButton)
3807 m_pConfirmButton->EnableWindow(m_nSelected>0);
3810 return sToolTip;
3815 CString CGitStatusListCtrl::GetCommonDirectory(bool bStrict)
3817 if (!bStrict)
3819 // not strict means that the selected folder has priority
3820 if (!m_StatusFileList.GetCommonDirectory().IsEmpty())
3821 return m_StatusFileList.GetCommonDirectory().GetWinPath();
3824 CTGitPath commonBaseDirectory;
3825 int nListItems = GetItemCount();
3826 for (int i=0; i<nListItems; ++i)
3828 CTGitPath baseDirectory,*p= (CTGitPath*)this->GetItemData(i);
3829 ASSERT(p);
3830 if(p==NULL)
3831 continue;
3832 baseDirectory = p->GetDirectory();
3834 if(commonBaseDirectory.IsEmpty())
3836 commonBaseDirectory = baseDirectory;
3838 else
3840 if (commonBaseDirectory.GetWinPathString().GetLength() > baseDirectory.GetWinPathString().GetLength())
3842 if (baseDirectory.IsAncestorOf(commonBaseDirectory))
3843 commonBaseDirectory = baseDirectory;
3847 return g_Git.m_CurrentDir+CString(_T("\\"))+commonBaseDirectory.GetWinPath();
3851 void CGitStatusListCtrl::SelectAll(bool bSelect, bool /*bIncludeNoCommits*/)
3853 CWaitCursor waitCursor;
3854 // block here so the LVN_ITEMCHANGED messages
3855 // get ignored
3856 m_bBlock = TRUE;
3857 SetRedraw(FALSE);
3859 int nListItems = GetItemCount();
3860 if (bSelect)
3861 m_nSelected = nListItems;
3862 else
3863 m_nSelected = 0;
3865 for (int i=0; i<nListItems; ++i)
3867 //FileEntry * entry = GetListEntry(i);
3868 //ASSERT(entry != NULL);
3869 CTGitPath *path = (CTGitPath *) GetItemData(i);
3870 if (path == NULL)
3871 continue;
3872 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
3873 SetEntryCheck(path,i,bSelect);
3876 // unblock before redrawing
3877 m_bBlock = FALSE;
3878 SetRedraw(TRUE);
3879 GetStatisticsString();
3880 NotifyCheck();
3883 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)
3885 LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);
3886 *pResult = 0;
3887 if (m_bBlock)
3888 return;
3890 CTGitPath *entry=(CTGitPath *)GetItemData(pGetInfoTip->iItem);
3892 if (entry)
3893 if (pGetInfoTip->cchTextMax > entry->GetGitPathString().GetLength() + g_Git.m_CurrentDir.GetLength())
3895 CString str;
3896 str += g_Git.m_CurrentDir;
3897 str += _T("\\");
3898 str += entry->GetWinPathString();
3900 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, str.GetBuffer(), str.GetLength());
3904 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
3906 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
3908 // Take the default processing unless we set this to something else below.
3909 *pResult = CDRF_DODEFAULT;
3911 // First thing - check the draw stage. If it's the control's prepaint
3912 // stage, then tell Windows we want messages for every item.
3914 switch (pLVCD->nmcd.dwDrawStage)
3916 case CDDS_PREPAINT:
3917 *pResult = CDRF_NOTIFYITEMDRAW;
3918 break;
3919 case CDDS_ITEMPREPAINT:
3921 // This is the prepaint stage for an item. Here's where we set the
3922 // item's text color. Our return value will tell Windows to draw the
3923 // item itself, but it will use the new color we set here.
3925 // Tell Windows to paint the control itself.
3926 *pResult = CDRF_DODEFAULT;
3927 if (m_bBlock)
3928 return;
3930 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
3932 if (m_arStatusArray.size() > (DWORD_PTR)pLVCD->nmcd.dwItemSpec)
3935 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3936 CTGitPath *entry=(CTGitPath *)GetItemData((int)pLVCD->nmcd.dwItemSpec);
3937 if (entry == NULL)
3938 return;
3940 // coloring
3941 // ========
3942 // black : unversioned, normal
3943 // purple : added
3944 // blue : modified
3945 // brown : missing, deleted, replaced
3946 // green : merged (or potential merges)
3947 // red : conflicts or sure conflicts
3948 if(entry->m_Action & CTGitPath::LOGACTIONS_GRAY)
3950 crText = RGB(128,128,128);
3952 }else if(entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
3954 crText = m_Colors.GetColor(CColors::Conflict);
3956 }else if(entry->m_Action & (CTGitPath::LOGACTIONS_MODIFIED))
3958 crText = m_Colors.GetColor(CColors::Modified);
3960 }else if(entry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
3962 crText = m_Colors.GetColor(CColors::Added);
3964 else if(entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
3966 crText = m_Colors.GetColor(CColors::DeletedNode);
3968 else if(entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
3970 crText = m_Colors.GetColor(CColors::RenamedNode);
3971 }else if(entry->m_Action & CTGitPath::LOGACTIONS_MERGED)
3973 crText = m_Colors.GetColor(CColors::Merged);
3974 }else
3976 crText = GetSysColor(COLOR_WINDOWTEXT);
3978 // Store the color back in the NMLVCUSTOMDRAW struct.
3979 pLVCD->clrText = crText;
3982 break;
3986 BOOL CGitStatusListCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
3988 if (pWnd != this)
3989 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
3990 if (!m_bBlock)
3992 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
3993 SetCursor(hCur);
3994 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
3996 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
3997 SetCursor(hCur);
3998 return TRUE;
4001 void CGitStatusListCtrl::RemoveListEntry(int index)
4004 Locker lock(m_critSec);
4005 DeleteItem(index);
4007 m_arStatusArray.erase(m_arStatusArray.begin()+index);
4009 #if 0
4010 delete m_arStatusArray[m_arListArray[index]];
4011 m_arStatusArray.erase(m_arStatusArray.begin()+m_arListArray[index]);
4012 m_arListArray.erase(m_arListArray.begin()+index);
4013 for (int i=index; i< (int)m_arListArray.size(); ++i)
4015 m_arListArray[i]--;
4017 #endif
4020 ///< Set a checkbox on an entry in the listbox
4021 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
4022 void CGitStatusListCtrl::SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck)
4024 pEntry->m_Checked = bCheck;
4025 SetCheck(listboxIndex, bCheck);
4028 #if 0
4029 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck)
4032 int nListItems = GetItemCount();
4033 for (int j=0; j< nListItems ; ++j)
4035 FileEntry * childEntry = GetListEntry(j);
4036 ASSERT(childEntry != NULL);
4037 if (childEntry == NULL || childEntry == parentEntry)
4038 continue;
4039 if (childEntry->checked != bCheck)
4041 if (parentEntry->path.IsAncestorOf(childEntry->path))
4043 SetEntryCheck(childEntry,j,bCheck);
4044 if(bCheck)
4046 m_nSelected++;
4048 else
4050 m_nSelected--;
4057 #endif
4059 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList& pathList)
4062 pathList.Clear();
4063 int nListItems = GetItemCount();
4064 for (int i=0; i< nListItems; i++)
4066 CTGitPath * entry = (CTGitPath*)GetItemData(i);
4067 ASSERT(entry != NULL);
4068 if (entry->m_Checked)
4070 pathList.AddPath(*entry);
4073 pathList.SortByPathname();
4078 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
4079 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList& pathList, bool /*bNoIgnored*/)
4081 pathList.Clear();
4083 POSITION pos = GetFirstSelectedItemPosition();
4084 int index;
4085 while ((index = GetNextSelectedItem(pos)) >= 0)
4087 CTGitPath * entry = (CTGitPath*)GetItemData(index);
4088 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
4089 // continue;
4090 pathList.AddPath(*entry);
4094 UINT CGitStatusListCtrl::OnGetDlgCode()
4096 // we want to process the return key and not have that one
4097 // routed to the default pushbutton
4098 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS;
4101 void CGitStatusListCtrl::OnNMReturn(NMHDR * /*pNMHDR*/, LRESULT *pResult)
4103 *pResult = 0;
4104 if (m_bBlock)
4105 return;
4106 POSITION pos = GetFirstSelectedItemPosition();
4107 while ( pos )
4109 int index = GetNextSelectedItem(pos);
4110 CTGitPath *file=(CTGitPath*)GetItemData(index);
4111 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER) {
4112 OpenFile(file, OPEN);
4113 } else {
4114 StartDiff(index);
4119 void CGitStatusListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
4121 // Since we catch all keystrokes (to have the enter key processed here instead
4122 // of routed to the default pushbutton) we have to make sure that other
4123 // keys like Tab and Esc still do what they're supposed to do
4124 // Tab = change focus to next/previous control
4125 // Esc = quit the dialog
4126 switch (nChar)
4128 case (VK_TAB):
4130 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL, GetKeyState(VK_SHIFT)&0x8000, 0);
4131 return;
4133 break;
4134 case (VK_ESCAPE):
4136 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE, 0, 0);
4138 break;
4141 CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
4144 void CGitStatusListCtrl::PreSubclassWindow()
4146 CListCtrl::PreSubclassWindow();
4147 EnableToolTips(TRUE);
4148 m_Theme.SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);
4151 INT_PTR CGitStatusListCtrl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
4153 int row, col;
4154 RECT cellrect;
4155 row = CellRectFromPoint(point, &cellrect, &col );
4157 if (row == -1)
4158 return -1;
4161 pTI->hwnd = m_hWnd;
4162 pTI->uId = (UINT)((row<<10)+(col&0x3ff)+1);
4163 pTI->lpszText = LPSTR_TEXTCALLBACK;
4165 pTI->rect = cellrect;
4167 return pTI->uId;
4170 int CGitStatusListCtrl::CellRectFromPoint(CPoint& point, RECT *cellrect, int *col) const
4172 int colnum;
4174 // Make sure that the ListView is in LVS_REPORT
4175 if ((GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
4176 return -1;
4178 // Get the top and bottom row visible
4179 int row = GetTopIndex();
4180 int bottom = row + GetCountPerPage();
4181 if (bottom > GetItemCount())
4182 bottom = GetItemCount();
4184 // Get the number of columns
4185 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
4186 int nColumnCount = pHeader->GetItemCount();
4188 // Loop through the visible rows
4189 for ( ;row <=bottom;row++)
4191 // Get bounding rect of item and check whether point falls in it.
4192 CRect rect;
4193 GetItemRect(row, &rect, LVIR_BOUNDS);
4194 if (rect.PtInRect(point))
4196 // Now find the column
4197 for (colnum = 0; colnum < nColumnCount; colnum++)
4199 int colwidth = GetColumnWidth(colnum);
4200 if (point.x >= rect.left && point.x <= (rect.left + colwidth))
4202 RECT rectClient;
4203 GetClientRect(&rectClient);
4204 if (col)
4205 *col = colnum;
4206 rect.right = rect.left + colwidth;
4208 // Make sure that the right extent does not exceed
4209 // the client area
4210 if (rect.right > rectClient.right)
4211 rect.right = rectClient.right;
4212 *cellrect = rect;
4213 return row;
4215 rect.left += colwidth;
4219 return -1;
4222 BOOL CGitStatusListCtrl::OnToolTipText(UINT /*id*/, NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
4224 #if 0
4225 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4226 CString strTipText;
4227 UINT_PTR nID = pNMHDR->idFrom;
4229 if (nID == 0)
4230 return FALSE;
4232 UINT_PTR row = ((nID-1) >> 10) & 0x3fffff;
4233 UINT_PTR col = (nID-1) & 0x3ff;
4235 if (col == 0)
4236 return FALSE; // no custom tooltip for the path, we use the infotip there!
4238 // get the internal column from the visible columns
4239 int internalcol = 0;
4240 UINT_PTR currentcol = 0;
4241 for (; (currentcol != col)
4242 && (internalcol < m_ColumnManager.GetColumnCount()-1)
4243 ; ++internalcol)
4245 if (m_ColumnManager.IsVisible (internalcol))
4246 currentcol++;
4249 AFX_MODULE_THREAD_STATE* pModuleThreadState = AfxGetModuleThreadState();
4250 CToolTipCtrl* pToolTip = pModuleThreadState->m_pToolTip;
4251 pToolTip->SendMessage(TTM_SETMAXTIPWIDTH, 0, 300);
4253 *pResult = 0;
4254 if ((internalcol == 2)||(internalcol == 4))
4256 FileEntry *fentry = GetListEntry(row);
4257 if (fentry)
4259 if (fentry->copied)
4261 CString url;
4262 url.Format(IDS_STATUSLIST_COPYFROM, (LPCTSTR)CPathUtils::PathUnescape(fentry->copyfrom_url), (LONG)fentry->copyfrom_rev);
4263 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4264 return TRUE;
4266 if (fentry->switched)
4268 CString url;
4269 url.Format(IDS_STATUSLIST_SWITCHEDTO, (LPCTSTR)CPathUtils::PathUnescape(fentry->url));
4270 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4271 return TRUE;
4273 if (fentry->keeplocal)
4275 lstrcpyn(pTTTW->szText, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_KEEPLOCAL)), 80);
4276 return TRUE;
4280 #endif
4281 return FALSE;
4284 void CGitStatusListCtrl::OnPaint()
4286 Default();
4287 if ((m_bBusy)||(m_bEmpty))
4289 CString str;
4290 if (m_bBusy)
4292 if (m_sBusy.IsEmpty())
4293 str.LoadString(IDS_STATUSLIST_BUSYMSG);
4294 else
4295 str = m_sBusy;
4297 else
4299 if (m_sEmpty.IsEmpty())
4300 str.LoadString(IDS_STATUSLIST_EMPTYMSG);
4301 else
4302 str = m_sEmpty;
4304 COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
4305 COLORREF clrTextBk;
4306 if (IsWindowEnabled())
4307 clrTextBk = ::GetSysColor(COLOR_WINDOW);
4308 else
4309 clrTextBk = ::GetSysColor(COLOR_3DFACE);
4311 CRect rc;
4312 GetClientRect(&rc);
4313 CHeaderCtrl* pHC;
4314 pHC = GetHeaderCtrl();
4315 if (pHC != NULL)
4317 CRect rcH;
4318 pHC->GetItemRect(0, &rcH);
4319 rc.top += rcH.bottom;
4321 CDC* pDC = GetDC();
4323 CMyMemDC memDC(pDC, &rc);
4325 memDC.SetTextColor(clrText);
4326 memDC.SetBkColor(clrTextBk);
4327 memDC.FillSolidRect(rc, clrTextBk);
4328 rc.top += 10;
4329 CGdiObject * oldfont = memDC.SelectStockObject(DEFAULT_GUI_FONT);
4330 memDC.DrawText(str, rc, DT_CENTER | DT_VCENTER |
4331 DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
4332 memDC.SelectObject(oldfont);
4334 ReleaseDC(pDC);
4338 // prevent users from extending our hidden (size 0) columns
4339 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
4341 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
4344 // prevent any function from extending our hidden (size 0) columns
4345 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
4347 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
4348 Default();
4351 void CGitStatusListCtrl::OnDestroy()
4353 SaveColumnWidths(true);
4354 CListCtrl::OnDestroy();
4357 void CGitStatusListCtrl::OnBeginDrag(NMHDR* /*pNMHDR*/, LRESULT* pResult)
4359 #if 0
4360 Locker lock(m_critSec);
4361 CDropFiles dropFiles; // class for creating DROPFILES struct
4363 int index;
4364 POSITION pos = GetFirstSelectedItemPosition();
4365 while ( (index = GetNextSelectedItem(pos)) >= 0 )
4367 FileEntry * fentry = m_arStatusArray[m_arListArray[index]];
4368 CTGitPath path = fentry->GetPath();
4369 dropFiles.AddFile( path.GetWinPathString() );
4372 if ( dropFiles.GetCount()>0 )
4374 m_bOwnDrag = true;
4375 dropFiles.CreateStructure();
4376 m_bOwnDrag = false;
4378 #endif
4379 *pResult = 0;
4382 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry /* = false */)
4384 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
4385 for (int col = 0; col <= maxcol; col++)
4386 if (m_ColumnManager.IsVisible (col))
4387 m_ColumnManager.ColumnResized (col);
4389 if (bSaveToRegistry)
4390 m_ColumnManager.WriteSettings();
4393 bool CGitStatusListCtrl::EnableFileDrop()
4395 m_bFileDropsEnabled = true;
4396 return true;
4399 bool CGitStatusListCtrl::HasPath(const CTGitPath& path)
4401 for (size_t i=0; i < m_arStatusArray.size(); i++)
4403 if (m_arStatusArray[i]->IsEquivalentTo(path))
4404 return true;
4407 return false;
4410 BOOL CGitStatusListCtrl::PreTranslateMessage(MSG* pMsg)
4412 if (pMsg->message == WM_KEYDOWN)
4414 switch (pMsg->wParam)
4416 case 'A':
4418 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4420 // select all entries
4421 for (int i=0; i<GetItemCount(); ++i)
4423 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
4425 return TRUE;
4428 break;
4429 case 'C':
4430 case VK_INSERT:
4432 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4434 // copy all selected paths to the clipboard
4435 if (GetAsyncKeyState(VK_SHIFT)&0x8000)
4436 CopySelectedEntriesToClipboard(SVNSLC_COLSTATUS);
4437 else
4438 CopySelectedEntriesToClipboard(0);
4439 return TRUE;
4442 break;
4446 return CListCtrl::PreTranslateMessage(pMsg);
4449 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols)
4452 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
4453 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
4454 // WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4456 CString sClipboard;
4457 CString temp;
4458 //TCHAR buf[100];
4459 if (GetSelectedCount() == 0)
4460 return false;
4462 // first add the column titles as the first line
4463 // We needn't head when only path copy
4464 //temp.LoadString(IDS_STATUSLIST_COLFILE);
4465 //sClipboard = temp;
4467 DWORD selection = 0;
4468 for (int i = 0, count = m_ColumnManager.GetColumnCount(); i < count; ++i)
4469 if ( ((dwCols == -1) && m_ColumnManager.IsVisible (i))
4470 || ((dwCols != 1) && (i < 32) && ((dwCols & (1 << i)) != 0)))
4472 sClipboard += _T("\t") + m_ColumnManager.GetName(i);
4474 if (i < 32)
4475 selection += 1 << i;
4478 if(dwCols)
4479 sClipboard += _T("\r\n");
4481 POSITION pos = GetFirstSelectedItemPosition();
4482 int index;
4483 while ((index = GetNextSelectedItem(pos)) >= 0)
4485 CTGitPath * entry = (CTGitPath*)GetItemData(index);
4486 if(entry == NULL)
4487 continue;
4489 sClipboard += entry->GetWinPathString();
4490 if (selection & SVNSLC_COLFILENAME)
4492 sClipboard += _T("\t")+entry->GetFileOrDirectoryName();
4494 if (selection & SVNSLC_COLEXT)
4496 sClipboard += _T("\t")+entry->GetFileExtension();
4499 if (selection & SVNSLC_COLSTATUS)
4501 #if 0
4502 if (entry->isNested)
4504 temp.LoadString(IDS_STATUSLIST_NESTED);
4506 else
4508 GitStatus::GetStatusString(hResourceHandle, entry->status, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4509 if ((entry->copied)&&(_tcslen(buf)>1))
4510 _tcscat_s(buf, 100, _T(" (+)"));
4511 if ((entry->switched)&&(_tcslen(buf)>1))
4512 _tcscat_s(buf, 100, _T(" (s)"));
4513 if ((entry->status == entry->propstatus)&&
4514 (entry->status != git_wc_status_normal)&&
4515 (entry->status != git_wc_status_unversioned)&&
4516 (!GitStatus::IsImportant(entry->textstatus)))
4517 _tcscat_s(buf, 100, ponly);
4518 temp = buf;
4520 #endif
4521 sClipboard += _T("\t")+entry->GetActionName();
4523 #if 0
4524 if (selection & SVNSLC_COLTEXTSTATUS)
4527 if (entry->isNested)
4529 temp.LoadString(IDS_STATUSLIST_NESTED);
4531 else
4533 GitStatus::GetStatusString(hResourceHandle, entry->textstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4534 if ((entry->copied)&&(_tcslen(buf)>1))
4535 _tcscat_s(buf, 100, _T(" (+)"));
4536 if ((entry->switched)&&(_tcslen(buf)>1))
4537 _tcscat_s(buf, 100, _T(" (s)"));
4538 temp = buf;
4540 sClipboard += _T("\t")+temp;
4542 #endif
4543 #if 0
4544 if (selection & SVNSLC_COLREMOTESTATUS)
4546 if (entry->isNested)
4548 temp.LoadString(IDS_STATUSLIST_NESTED);
4550 else
4552 GitStatus::GetStatusString(hResourceHandle, entry->remotestatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4553 if ((entry->copied)&&(_tcslen(buf)>1))
4554 _tcscat_s(buf, 100, _T(" (+)"));
4555 if ((entry->switched)&&(_tcslen(buf)>1))
4556 _tcscat_s(buf, 100, _T(" (s)"));
4557 if ((entry->remotestatus == entry->remotepropstatus)&&
4558 (entry->remotestatus != git_wc_status_none)&&
4559 (entry->remotestatus != git_wc_status_normal)&&
4560 (entry->remotestatus != git_wc_status_unversioned)&&
4561 (!SVNStatus::IsImportant(entry->remotetextstatus)))
4562 _tcscat_s(buf, 100, ponly);
4563 temp = buf;
4565 sClipboard += _T("\t")+temp;
4567 if (selection & GitSLC_COLPROPSTATUS)
4569 if (entry->isNested)
4571 temp.Empty();
4573 else
4575 GitStatus::GetStatusString(hResourceHandle, entry->propstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4576 if ((entry->copied)&&(_tcslen(buf)>1))
4577 _tcscat_s(buf, 100, _T(" (+)"));
4578 if ((entry->switched)&&(_tcslen(buf)>1))
4579 _tcscat_s(buf, 100, _T(" (s)"));
4580 temp = buf;
4582 sClipboard += _T("\t")+temp;
4584 if (selection & SVNSLC_COLREMOTETEXT)
4586 if (entry->isNested)
4588 temp.Empty();
4590 else
4592 GitStatus::GetStatusString(hResourceHandle, entry->remotetextstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4593 temp = buf;
4595 sClipboard += _T("\t")+temp;
4597 if (selection & SVNSLC_COLREMOTEPROP)
4599 // SVNSLC_COLREMOTEPROP
4600 if (entry->isNested)
4602 temp.Empty();
4604 else
4606 GitStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4607 temp = buf;
4609 sClipboard += _T("\t")+temp;
4611 if (selection & SVNSLC_COLURL)
4612 sClipboard += _T("\t")+entry->url;
4613 if (selection & SVNSLC_COLLOCK)
4615 if (!m_HeadRev.IsHead())
4617 // we have contacted the repository
4619 // decision-matrix
4620 // wc repository text
4621 // "" "" ""
4622 // "" UID1 owner
4623 // UID1 UID1 owner
4624 // UID1 "" lock has been broken
4625 // UID1 UID2 lock has been stolen
4626 if (entry->lock_token.IsEmpty() || (entry->lock_token.Compare(entry->lock_remotetoken)==0))
4628 if (entry->lock_owner.IsEmpty())
4629 temp = entry->lock_remoteowner;
4630 else
4631 temp = entry->lock_owner;
4633 else if (entry->lock_remotetoken.IsEmpty())
4635 // broken lock
4636 temp.LoadString(IDS_STATUSLIST_LOCKBROKEN);
4638 else
4640 // stolen lock
4641 temp.Format(IDS_STATUSLIST_LOCKSTOLEN, (LPCTSTR)entry->lock_remoteowner);
4644 else
4645 temp = entry->lock_owner;
4646 sClipboard += _T("\t")+temp;
4648 if (selection & SVNSLC_COLLOCKCOMMENT)
4649 sClipboard += _T("\t")+entry->lock_comment;
4650 if (selection & SVNSLC_COLAUTHOR)
4651 sClipboard += _T("\t")+entry->last_commit_author;
4652 if (selection & SVNSLC_COLREVISION)
4654 temp.Format(_T("%ld"), entry->last_commit_rev);
4655 if (entry->last_commit_rev == 0)
4656 temp.Empty();
4657 sClipboard += _T("\t")+temp;
4659 if (selection & SVNSLC_COLREMOTEREVISION)
4661 temp.Format(_T("%ld"), entry->remoterev);
4662 if (entry->remoterev == 0)
4663 temp.Empty();
4664 sClipboard += _T("\t")+temp;
4667 if (selection & SVNSLC_COLDATE)
4669 TCHAR datebuf[SVN_DATE_BUFFER];
4670 apr_time_t date = entry->last_commit_date;
4671 SVN::formatDate(datebuf, date, true);
4672 if (date)
4673 temp = datebuf;
4674 else
4675 temp.Empty();
4676 sClipboard += _T("\t")+temp;
4678 if (selection & SVNSLC_COLCOPYFROM)
4680 if (m_sURL.Compare(entry->copyfrom_url.Left(m_sURL.GetLength()))==0)
4681 temp = entry->copyfrom_url.Mid(m_sURL.GetLength());
4682 else
4683 temp = entry->copyfrom_url;
4684 sClipboard += _T("\t")+temp;
4687 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
4688 ; i < count
4689 ; ++i)
4691 if ((dwCols == -1) && m_ColumnManager.IsVisible (i))
4693 CString value
4694 = entry->present_props[m_ColumnManager.GetName(i)];
4695 sClipboard += _T("\t") + value;
4698 #endif
4699 if (selection & SVNSLC_COLADD)
4701 sClipboard += _T("\t")+entry->m_StatAdd;
4703 if (selection & SVNSLC_COLDEL)
4705 sClipboard += _T("\t")+entry->m_StatDel;
4708 sClipboard += _T("\r\n");
4711 return CStringUtils::WriteAsciiStringToClipboard(sClipboard);
4713 return TRUE;
4717 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
4719 #if 0
4720 std::set<CString> changelists;
4721 POSITION pos = GetFirstSelectedItemPosition();
4722 int index;
4723 while ((index = GetNextSelectedItem(pos)) >= 0)
4725 FileEntry * entry = GetListEntry(index);
4726 if (!entry->changelist.IsEmpty())
4727 changelists.insert(entry->changelist);
4729 return changelists.size();
4730 #endif
4731 return 0;
4734 bool CGitStatusListCtrl::PrepareGroups(bool bForce /* = false */)
4737 bool bHasGroups=false;
4738 int max =0;
4740 for(int i=0;i< this->m_arStatusArray.size(); i++)
4742 int ParentNo = m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
4743 if( ParentNo > max)
4744 max=m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
4747 if ( this->m_UnRevFileList.GetCount()>0 ||
4748 this->m_IgnoreFileList.GetCount()>0 ||
4749 max>0 || bForce)
4751 bHasGroups = true;
4754 RemoveAllGroups();
4755 EnableGroupView(bHasGroups);
4757 TCHAR groupname[1024];
4758 int groupindex = 0;
4760 if(bHasGroups)
4762 LVGROUP grp = {0};
4763 grp.cbSize = sizeof(LVGROUP);
4764 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4765 groupindex=0;
4767 //if(m_UnRevFileList.GetCount()>0)
4768 if(max >0)
4770 grp.pszHeader = _T("Merged Files");
4771 grp.iGroupId = MERGE_MASK;
4772 grp.uAlign = LVGA_HEADER_LEFT;
4773 InsertGroup(0, &grp);
4775 for(int i=0;i<=max;i++)
4777 CString str;
4778 str.Format(_T("Diff with %d Parent"), i+1);
4779 //_tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Not Versioned"), 1023);
4780 grp.pszHeader = str.GetBuffer();
4781 grp.iGroupId = i;
4782 grp.uAlign = LVGA_HEADER_LEFT;
4783 InsertGroup(i+1, &grp);
4785 }else
4787 CString sUnassignedName(_T("Modified File"));
4788 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
4789 grp.pszHeader = groupname;
4790 grp.iGroupId = groupindex;
4791 grp.uAlign = LVGA_HEADER_LEFT;
4792 InsertGroup(groupindex++, &grp);
4796 _tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Not Versioned"), 1023);
4797 grp.pszHeader = groupname;
4798 grp.iGroupId = groupindex;
4799 grp.uAlign = LVGA_HEADER_LEFT;
4800 InsertGroup(groupindex++, &grp);
4803 //if(m_IgnoreFileList.GetCount()>0)
4805 _tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Ignored"), 1023);
4806 grp.pszHeader = groupname;
4807 grp.iGroupId = groupindex;
4808 grp.uAlign = LVGA_HEADER_LEFT;
4809 InsertGroup(groupindex++, &grp);
4814 #if 0
4815 m_bHasIgnoreGroup = false;
4817 // now add the items which don't belong to a group
4818 LVGROUP grp = {0};
4819 grp.cbSize = sizeof(LVGROUP);
4820 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4821 CString sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET));
4822 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
4823 grp.pszHeader = groupname;
4824 grp.iGroupId = groupindex;
4825 grp.uAlign = LVGA_HEADER_LEFT;
4826 InsertGroup(groupindex++, &grp);
4828 for (std::map<CString,int>::iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
4830 if (it->first.Compare(SVNSLC_IGNORECHANGELIST)!=0)
4832 LVGROUP grp = {0};
4833 grp.cbSize = sizeof(LVGROUP);
4834 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4835 _tcsncpy_s(groupname, 1024, it->first, 1023);
4836 grp.pszHeader = groupname;
4837 grp.iGroupId = groupindex;
4838 grp.uAlign = LVGA_HEADER_LEFT;
4839 it->second = InsertGroup(groupindex++, &grp);
4841 else
4842 m_bHasIgnoreGroup = true;
4845 if (m_bHasIgnoreGroup)
4847 // and now add the group 'ignore-on-commit'
4848 std::map<CString,int>::iterator it = m_changelists.find(SVNSLC_IGNORECHANGELIST);
4849 if (it != m_changelists.end())
4851 grp.cbSize = sizeof(LVGROUP);
4852 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4853 _tcsncpy_s(groupname, 1024, SVNSLC_IGNORECHANGELIST, 1023);
4854 grp.pszHeader = groupname;
4855 grp.iGroupId = groupindex;
4856 grp.uAlign = LVGA_HEADER_LEFT;
4857 it->second = InsertGroup(groupindex, &grp);
4860 #endif
4861 return bHasGroups;
4864 void CGitStatusListCtrl::NotifyCheck()
4866 CWnd* pParent = GetParent();
4867 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
4869 pParent->SendMessage(SVNSLNM_CHECKCHANGED, m_nSelected);
4873 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash,CTGitPathList *list)
4875 BYTE_VECTOR out;
4876 this->m_bBusy=TRUE;
4877 m_CurrentVersion=hash;
4879 int count = 0;
4880 if(list == NULL)
4881 count = 1;
4882 else
4883 count = list->GetCount();
4885 CString head = _T("HEAD");
4886 if(m_amend)
4887 head = _T("HEAD~1");
4889 if(hash == GIT_REV_ZERO)
4891 for(int i=0;i<count;i++)
4893 BYTE_VECTOR cmdout;
4894 cmdout.clear();
4895 CString cmd;
4896 if(!g_Git.IsInitRepos())
4898 if(list == NULL)
4899 cmd=(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z"));
4900 else
4901 cmd.Format(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
4903 if(g_Git.Run(cmd,&cmdout))
4905 int last = cmdout.RevertFind(0,-1);
4906 if(last >0)
4908 CString str;
4909 g_Git.StringAppend(&str, &cmdout[last+1], CP_ACP,cmdout.size()-last -1);
4910 CMessageBox::Show(NULL,str, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
4911 cmdout.resize(last+1);
4913 }else
4915 cmdout.clear();
4916 CString strout;
4917 if(g_Git.Run(_T("git.exe rev-parse --revs-only ") + head,&strout,CP_UTF8))
4919 CMessageBox::Show(NULL,strout,_T("TortoiseGit"),MB_OK);
4920 return -1;
4922 if(strout.IsEmpty())
4923 break; //this is initial repositoyr, there are no any history
4925 CMessageBox::Show(NULL,strout,_T("TortoiseGit"),MB_OK);
4926 return -1;
4930 //if(list == NULL)
4931 //We will list all stage file anyway because commit will commit thats
4932 cmd=(_T("git.exe diff-index --cached --raw ") + head + _T(" --numstat -C -M -z"));
4933 //else
4934 // cmd.Format(_T("git.exe diff-index --cached --raw ") + head + _T(" --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
4936 g_Git.Run(cmd,&cmdout);
4937 //out+=cmdout;
4938 out.append(cmdout,0);
4940 else // Init Repository
4942 //We will list all added file for init repository because commit will comit these
4943 //if(list == NULL)
4944 cmd=_T("git.exe ls-files -s -t -z");
4945 //else
4946 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
4948 g_Git.Run(cmd,&cmdout);
4949 //out+=cmdout;
4950 out.append(cmdout,0);
4954 if(g_Git.IsInitRepos())
4956 m_StatusFileList.ParserFromLsFile(out);
4957 for(int i=0;i<m_StatusFileList.GetCount();i++)
4958 ((CTGitPath&)(m_StatusFileList[i])).m_Action=CTGitPath::LOGACTIONS_ADDED;
4960 else
4961 this->m_StatusFileList.ParserFromLog(out);
4963 //handle delete conflict case, when remote : modified, local : deleted.
4964 for(int i=0;i<count;i++)
4966 BYTE_VECTOR cmdout;
4967 CString cmd;
4969 if(list == NULL)
4970 cmd=_T("git.exe ls-files -u -t -z");
4971 else
4972 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list)[i].GetGitPathString());
4974 g_Git.Run(cmd,&cmdout);
4976 CTGitPathList conflictlist;
4977 conflictlist.ParserFromLog(cmdout);
4978 for(int i=0;i<conflictlist.GetCount();i++)
4980 CTGitPath *p=m_StatusFileList.LookForGitPath(conflictlist[i].GetGitPathString());
4981 if(p)
4982 p->m_Action|=CTGitPath::LOGACTIONS_UNMERGED;
4983 else
4984 m_StatusFileList.AddPath(conflictlist[i]);
4988 }else
4990 int count = 0;
4991 if(list == NULL)
4992 count = 1;
4993 else
4994 count = list->GetCount();
4996 for(int i=0;i<count;i++)
4998 BYTE_VECTOR cmdout;
4999 CString cmd;
5000 if(list == NULL)
5001 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash);
5002 else
5003 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash,(*list)[i].GetGitPathString());
5005 g_Git.Run(cmd,&cmdout);
5007 out.append(cmdout);
5009 this->m_StatusFileList.ParserFromLog(out);
5013 for(int i=0;i<m_StatusFileList.GetCount();i++)
5015 CTGitPath * gitpatch=(CTGitPath*)&m_StatusFileList[i];
5016 gitpatch->m_Checked = TRUE;
5017 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
5020 this->m_bBusy=FALSE;
5021 return 0;
5024 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList &list)
5026 m_arStatusArray.clear();
5027 for(int i=0;i<list.GetCount();i++)
5029 CTGitPath * gitpath=(CTGitPath*)&list[i];
5031 if(gitpath ->m_Action & CTGitPath::LOGACTIONS_HIDE)
5032 continue;
5034 gitpath->m_Checked = TRUE;
5035 m_arStatusArray.push_back((CTGitPath*)&list[i]);
5037 return 0;
5040 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList *List)
5042 this->m_UnRevFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER,List);
5043 for(int i=0;i<m_UnRevFileList.GetCount();i++)
5045 CTGitPath * gitpatch=(CTGitPath*)&m_UnRevFileList[i];
5046 gitpatch->m_Checked = FALSE;
5047 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
5049 return 0;
5052 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList *List)
5054 this->m_IgnoreFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER|CTGitPath::LOGACTIONS_IGNORE,List);
5055 for(int i=0;i<m_IgnoreFileList.GetCount();i++)
5057 CTGitPath * gitpatch=(CTGitPath*)&m_IgnoreFileList[i];
5058 gitpatch->m_Checked = FALSE;
5059 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
5061 return 0;
5063 int CGitStatusListCtrl::UpdateFileList(int mask,bool once,CTGitPathList *List)
5065 if(mask&CGitStatusListCtrl::FILELIST_MODIFY)
5067 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_MODIFY)))
5069 UpdateFileList(git_revnum_t(GIT_REV_ZERO),List);
5070 m_FileLoaded|=CGitStatusListCtrl::FILELIST_MODIFY;
5073 if(mask&CGitStatusListCtrl::FILELIST_UNVER)
5075 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_UNVER)))
5077 UpdateUnRevFileList(List);
5078 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
5081 return 0;
5084 void CGitStatusListCtrl::Clear()
5086 m_FileLoaded=0;
5087 this->DeleteAllItems();
5088 this->m_arListArray.clear();
5089 this->m_arStatusArray.clear();
5090 this->m_changelists.clear();
5092 //////////////////////////////////////////////////////////////////////////
5093 #if 0
5094 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD * /*pdwEffect*/, POINTL pt)
5096 if(pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
5098 HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
5099 if(hDrop != NULL)
5101 TCHAR szFileName[MAX_PATH];
5103 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
5105 POINT clientpoint;
5106 clientpoint.x = pt.x;
5107 clientpoint.y = pt.y;
5108 ScreenToClient(m_hTargetWnd, &clientpoint);
5109 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5111 CTSVNPathList changelistItems;
5112 for(UINT i = 0; i < cFiles; ++i)
5114 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5115 changelistItems.AddPath(CTSVNPath(szFileName));
5117 // find the changelist name
5118 CString sChangelist;
5119 LONG_PTR nGroup = m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint);
5120 for (std::map<CString, int>::iterator it = m_pSVNStatusListCtrl->m_changelists.begin(); it != m_pSVNStatusListCtrl->m_changelists.end(); ++it)
5121 if (it->second == nGroup)
5122 sChangelist = it->first;
5123 if (!sChangelist.IsEmpty())
5125 SVN git;
5126 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
5128 for (int l=0; l<changelistItems.GetCount(); ++l)
5130 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5131 if (index >= 0)
5133 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5134 if (e)
5136 e->changelist = sChangelist;
5137 if (!e->IsFolder())
5139 if (m_pSVNStatusListCtrl->m_changelists.find(e->changelist)!=m_pSVNStatusListCtrl->m_changelists.end())
5140 m_pSVNStatusListCtrl->SetItemGroup(index, m_pSVNStatusListCtrl->m_changelists[e->changelist]);
5141 else
5142 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5146 else
5148 HWND hParentWnd = GetParent(m_hTargetWnd);
5149 if (hParentWnd != NULL)
5150 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5154 else
5156 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
5159 else
5161 SVN git;
5162 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
5164 for (int l=0; l<changelistItems.GetCount(); ++l)
5166 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5167 if (index >= 0)
5169 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5170 if (e)
5172 e->changelist = sChangelist;
5173 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5176 else
5178 HWND hParentWnd = GetParent(m_hTargetWnd);
5179 if (hParentWnd != NULL)
5180 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5184 else
5186 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
5190 else
5192 for(UINT i = 0; i < cFiles; ++i)
5194 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5195 HWND hParentWnd = GetParent(m_hTargetWnd);
5196 if (hParentWnd != NULL)
5197 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)szFileName);
5201 GlobalUnlock(medium.hGlobal);
5203 return true; //let base free the medium
5205 HRESULT STDMETHODCALLTYPE CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)
5207 CIDropTarget::DragOver(grfKeyState, pt, pdwEffect);
5208 *pdwEffect = DROPEFFECT_COPY;
5209 if (m_pSVNStatusListCtrl)
5211 POINT clientpoint;
5212 clientpoint.x = pt.x;
5213 clientpoint.y = pt.y;
5214 ScreenToClient(m_hTargetWnd, &clientpoint);
5215 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5217 *pdwEffect = DROPEFFECT_MOVE;
5219 else if ((!m_pSVNStatusListCtrl->m_bFileDropsEnabled)||(m_pSVNStatusListCtrl->m_bOwnDrag))
5221 *pdwEffect = DROPEFFECT_NONE;
5224 return S_OK;
5227 #endif
5229 void CGitStatusListCtrl::FileSaveAs(CTGitPath *path)
5231 CString filename;
5232 filename.Format(_T("%s-%s%s"),path->GetBaseFilename(),this->m_CurrentVersion.Left(6),path->GetFileExtension());
5233 CFileDialog dlg(FALSE,NULL,
5234 filename,
5235 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
5236 NULL);
5237 CString currentpath;
5238 currentpath=g_Git.m_CurrentDir+_T("\\");
5239 currentpath+=path->GetWinPathString();
5241 dlg.m_ofn.lpstrInitialDir=currentpath.GetBuffer();
5243 CString cmd,out;
5244 if(dlg.DoModal()==IDOK)
5246 filename = dlg.GetPathName();
5247 if(m_CurrentVersion == GIT_REV_ZERO)
5249 if(!CopyFile(g_Git.m_CurrentDir +_T("\\") + path->GetWinPath(),filename,false))
5251 LPVOID lpMsgBuf=NULL;
5252 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
5253 NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
5254 (LPTSTR)&lpMsgBuf,
5255 0,NULL);
5256 CMessageBox::Show(NULL,(TCHAR *)lpMsgBuf,_T("TortoiseGit"),MB_OK);
5257 LocalFree(lpMsgBuf);
5258 return;
5261 }else
5263 if(g_Git.GetOneFile(m_CurrentVersion,*path,filename))
5265 out.Format(_T("Fail checkout one file %s;%s"),m_CurrentVersion, path->GetWinPath());
5266 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5267 return;
5274 int CGitStatusListCtrl::RevertSelectedItemToVersion()
5276 if(this->m_CurrentVersion.IsEmpty())
5277 return 0;
5278 if(this->m_CurrentVersion == GIT_REV_ZERO)
5279 return 0;
5281 POSITION pos = GetFirstSelectedItemPosition();
5282 int index;
5283 CString cmd,out;
5284 int count =0;
5285 while ((index = GetNextSelectedItem(pos)) >= 0)
5287 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
5288 cmd.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion,fentry->GetGitPathString());
5289 out.Empty();
5290 if(g_Git.Run(cmd,&out,CP_ACP))
5292 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5294 count++;
5297 out.Format(_T("%d files revert to %s"),count,m_CurrentVersion.Left(6));
5298 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5299 return 0;
5302 void CGitStatusListCtrl::OpenFile(CTGitPath*filepath,int mode)
5304 CString file;
5305 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
5307 file= filepath->GetWinPath();
5308 }else
5310 CString temppath;
5311 GetTempPath(temppath);
5312 file.Format(_T("%s%s_%s%s"),
5313 temppath,
5314 filepath->GetBaseFilename(),
5315 m_CurrentVersion.Left(6),
5316 filepath->GetFileExtension());
5317 CString cmd,out;
5318 if(g_Git.GetOneFile(m_CurrentVersion, *filepath, file))
5320 out.Format(_T("Fail checkout file %s to %s\n"), filepath->GetGitPathString(), file);
5321 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5322 return;
5326 if(mode == ALTERNATIVEEDITOR)
5328 CAppUtils::LaunchAlternativeEditor(file);
5329 return;
5331 int ret = HINSTANCE_ERROR;
5333 if(mode == OPEN )
5335 ret = (int)ShellExecute(this->m_hWnd, NULL,file, NULL, NULL, SW_SHOW);
5337 if (ret > HINSTANCE_ERROR)
5339 return;
5344 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
5345 cmd += file;
5346 CAppUtils::LaunchApplication(cmd, NULL, false);