Fixed unified diff order
[TortoiseGit.git] / src / Git / GitStatusListCtrl.cpp
blob090de70759ab3b1a2695d87f9b7e938803ad36c7
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
5 // Copyright (C) 2010-2012 Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "StdAfx.h"
23 #include "resource.h"
24 #include "..\\TortoiseShell\resource.h"
25 #include "GitStatusListCtrl.h"
26 #include "MessageBox.h"
27 #include "MyMemDC.h"
28 #include "UnicodeUtils.h"
29 #include "AppUtils.h"
30 #include "PathUtils.h"
31 #include "TempFile.h"
32 #include "StringUtils.h"
33 #include "DirFileEnum.h"
34 #include "GitConfig.h"
35 //#include "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 "FormatMessageWrapper.h"
55 #include "MassiveGitTask.h"
57 const UINT CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
58 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
59 const UINT CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
60 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
61 const UINT CGitStatusListCtrl::GITSLNM_ADDFILE
62 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
63 const UINT CGitStatusListCtrl::GITSLNM_CHECKCHANGED
64 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
65 const UINT CGitStatusListCtrl::GITSLNM_ITEMCHANGED
66 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCHANGED"));
71 BEGIN_MESSAGE_MAP(CGitStatusListCtrl, CListCtrl)
72 ON_NOTIFY(HDN_ITEMCLICKA, 0, OnHdnItemclick)
73 ON_NOTIFY(HDN_ITEMCLICKW, 0, OnHdnItemclick)
74 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
75 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
76 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, OnLvnItemchanged)
77 ON_WM_CONTEXTMENU()
78 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk)
79 ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnLvnGetInfoTip)
80 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
81 ON_WM_SETCURSOR()
82 ON_WM_GETDLGCODE()
83 ON_NOTIFY_REFLECT(NM_RETURN, OnNMReturn)
84 ON_WM_KEYDOWN()
85 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
86 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
87 ON_WM_PAINT()
88 ON_NOTIFY(HDN_BEGINTRACKA, 0, &CGitStatusListCtrl::OnHdnBegintrack)
89 ON_NOTIFY(HDN_BEGINTRACKW, 0, &CGitStatusListCtrl::OnHdnBegintrack)
90 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, &CGitStatusListCtrl::OnHdnItemchanging)
91 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, &CGitStatusListCtrl::OnHdnItemchanging)
92 ON_WM_DESTROY()
93 ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBeginDrag)
94 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING, &CGitStatusListCtrl::OnLvnItemchanging)
95 END_MESSAGE_MAP()
99 CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl()
100 //, m_HeadRev(GitRev::REV_HEAD)
101 , m_pbCanceled(NULL)
102 , m_pStatLabel(NULL)
103 , m_pSelectButton(NULL)
104 , m_pConfirmButton(NULL)
105 , m_bBusy(false)
106 , m_bEmpty(false)
107 , m_bShowIgnores(false)
108 , m_pDropTarget(NULL)
109 , m_bIgnoreRemoveOnly(false)
110 , m_bCheckChildrenWithParent(false)
111 , m_bUnversionedLast(true)
112 , m_bHasChangeLists(false)
113 , m_bHasLocks(false)
114 , m_bBlock(false)
115 , m_bBlockUI(false)
116 , m_bHasCheckboxes(false)
117 , m_bCheckIfGroupsExist(true)
118 , m_bFileDropsEnabled(false)
119 , m_bOwnDrag(false)
120 , m_dwDefaultColumns(0)
121 , m_ColumnManager(this)
122 , m_bAscending(false)
123 , m_nSortedColumn(-1)
124 , m_bHasExternalsFromDifferentRepos(false)
125 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE))
126 , m_amend(false)
127 , m_bDoNotAutoselectSubmodules(false)
128 , m_bHasWC(true)
130 m_FileLoaded=0;
131 m_critSec.Init();
132 m_bIsRevertTheirMy = false;
133 this->m_nLineAdded =this->m_nLineDeleted =0;
136 CGitStatusListCtrl::~CGitStatusListCtrl()
138 // if (m_pDropTarget)
139 // delete m_pDropTarget;
140 ClearStatusArray();
143 void CGitStatusListCtrl::ClearStatusArray()
145 #if 0
146 Locker lock(m_critSec);
147 for (size_t i=0; i < m_arStatusArray.size(); i++)
149 delete m_arStatusArray[i];
151 m_arStatusArray.clear();
152 #endif
154 #if 0
155 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(UINT_PTR index)
158 if (index >= (UINT_PTR)m_arListArray.size())
159 return NULL;
160 if (m_arListArray[index] >= m_arStatusArray.size())
161 return NULL;
162 return m_arStatusArray[m_arListArray[index]];
164 return NULL;
166 #endif
167 #if 0
168 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetVisibleListEntry(const CTGitPath& path)
170 int itemCount = GetItemCount();
171 for (int i=0; i < itemCount; i++)
173 FileEntry * entry = GetListEntry(i);
174 if (entry->GetPath().IsEquivalentTo(path))
175 return entry;
177 return NULL;
179 #endif
180 #if 0
181 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(const CTGitPath& path)
184 for (size_t i=0; i < m_arStatusArray.size(); i++)
186 FileEntry * entry = m_arStatusArray[i];
187 if (entry->GetPath().IsEquivalentTo(path))
188 return entry;
191 return NULL;
193 #endif
195 #if 0
196 int CGitStatusListCtrl::GetIndex(const CTGitPath& path)
198 int itemCount = GetItemCount();
199 for (int i=0; i < itemCount; i++)
201 FileEntry * entry = GetListEntry(i);
202 if (entry->GetPath().IsEquivalentTo(path))
203 return i;
205 return -1;
207 #endif
209 void CGitStatusListCtrl::Init(DWORD dwColumns, const CString& sColumnInfoContainer, unsigned __int64 dwContextMenus /* = GitSLC_POPALL */, bool bHasCheckboxes /* = true */, bool bHasWC /* = true */)
211 Locker lock(m_critSec);
213 m_dwDefaultColumns = dwColumns | 1;
214 m_dwContextMenus = dwContextMenus;
215 m_bHasCheckboxes = bHasCheckboxes;
216 m_bHasWC = bHasWC;
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 SetWindowTheme(m_hWnd, L"Explorer", NULL);
230 m_nIconFolder = SYS_IMAGE_LIST().GetDirIconIndex();
231 m_nRestoreOvl = SYS_IMAGE_LIST().AddIcon((HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_RESTOREOVL), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));
232 SYS_IMAGE_LIST().SetOverlayImage(m_nRestoreOvl, OVL_RESTORE);
233 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL);
235 // keep CSorter::operator() in sync!!
236 static UINT standardColumnNames[GITSLC_NUMCOLUMNS]
237 = { IDS_STATUSLIST_COLFILE
238 , IDS_STATUSLIST_COLFILENAME
239 , IDS_STATUSLIST_COLEXT
240 , IDS_STATUSLIST_COLSTATUS
241 , IDS_STATUSLIST_COLADD
242 , IDS_STATUSLIST_COLDEL
245 m_ColumnManager.SetNames(standardColumnNames,GITSLC_NUMCOLUMNS);
246 m_ColumnManager.ReadSettings (m_dwDefaultColumns, 0, sColumnInfoContainer, GITSLC_NUMCOLUMNS);
248 // enable file drops
249 #if 0
250 if (m_pDropTarget == NULL)
252 m_pDropTarget = new CGitStatusListCtrlDropTarget(this);
253 RegisterDragDrop(m_hWnd,m_pDropTarget);
254 // create the supported formats:
255 FORMATETC ftetc={0};
256 ftetc.dwAspect = DVASPECT_CONTENT;
257 ftetc.lindex = -1;
258 ftetc.tymed = TYMED_HGLOBAL;
259 ftetc.cfFormat=CF_HDROP;
260 m_pDropTarget->AddSuportedFormat(ftetc);
262 #endif
264 SetRedraw(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 GITSLC_SHOWUNVERSIONED;
534 case git_wc_status_ignored:
535 if (!m_bShowIgnores)
536 return GITSLC_SHOWDIRECTS;
537 return GITSLC_SHOWDIRECTS|GITSLC_SHOWIGNORED;
538 case git_wc_status_incomplete:
539 return GITSLC_SHOWINCOMPLETE;
540 case git_wc_status_normal:
541 return GITSLC_SHOWNORMAL;
542 case git_wc_status_external:
543 return GITSLC_SHOWEXTERNAL;
544 case git_wc_status_added:
545 return GITSLC_SHOWADDED;
546 case git_wc_status_missing:
547 return GITSLC_SHOWMISSING;
548 case git_wc_status_deleted:
549 return GITSLC_SHOWREMOVED;
550 case git_wc_status_replaced:
551 return GITSLC_SHOWREPLACED;
552 case git_wc_status_modified:
553 return GITSLC_SHOWMODIFIED;
554 case git_wc_status_merged:
555 return GITSLC_SHOWMERGED;
556 case git_wc_status_conflicted:
557 return GITSLC_SHOWCONFLICTED;
558 case git_wc_status_obstructed:
559 return GITSLC_SHOWOBSTRUCTED;
560 default:
561 // we should NEVER get here!
562 ASSERT(FALSE);
563 break;
565 return 0;
568 void CGitStatusListCtrl::Show(unsigned int dwShow, unsigned int 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)CRegStdDWORD(_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 >= 0)
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 if (!UseStoredCheckStatus)
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 >= 0)
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(GITSLC_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(unsigned int /*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)CRegStdDWORD(_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 from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
975 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
976 static bool abbreviateRenamings(((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\AbbreviateRenamings"), FALSE)) == TRUE);
978 CString path = GitPath->GetGitPathString();
980 m_bBlock = TRUE;
981 int index = listIndex;
982 int nCol = 1;
983 CString entryname = GitPath->GetGitPathString();
984 int icon_idx = 0;
985 if (GitPath->IsDirectory())
986 icon_idx = m_nIconFolder;
987 else
989 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath);
991 if(GitPath->m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !GitPath->GetGitOldPathString().IsEmpty())
993 if (!abbreviateRenamings)
995 // relative path
996 CString rename;
997 rename.Format(from, GitPath->GetGitOldPathString());
998 entryname += _T(" ") + rename;
1000 else
1002 CTGitPathList tgpl;
1003 tgpl.AddPath(*GitPath);
1004 CTGitPath old(GitPath->GetGitOldPathString());
1005 tgpl.AddPath(old);
1006 CString commonRoot = tgpl.GetCommonRoot().GetGitPathString();
1007 if (!commonRoot.IsEmpty())
1008 commonRoot += _T("/");
1009 if (old.GetFileOrDirectoryName() == GitPath->GetFileOrDirectoryName() && old.GetContainingDirectory().GetGitPathString() != "" && GitPath->GetContainingDirectory().GetGitPathString())
1011 entryname = commonRoot + _T("{") + GitPath->GetGitOldPathString().Mid(commonRoot.GetLength(), old.GetGitPathString().GetLength() - commonRoot.GetLength() - old.GetFileOrDirectoryName().GetLength() - 1) + _T(" => ") + GitPath->GetGitPathString().Mid(commonRoot.GetLength(), GitPath->GetGitPathString().GetLength() - commonRoot.GetLength() - old.GetFileOrDirectoryName().GetLength() - 1) + _T("}/") + old.GetFileOrDirectoryName();
1013 else if (!commonRoot.IsEmpty())
1015 entryname = commonRoot + _T("{") + GitPath->GetGitOldPathString().Mid(commonRoot.GetLength()) + _T(" => ") + GitPath->GetGitPathString().Mid(commonRoot.GetLength()) + _T("}");
1017 else
1019 entryname = GitPath->GetGitOldPathString().Mid(commonRoot.GetLength()) + _T(" => ") + GitPath->GetGitPathString().Mid(commonRoot.GetLength());
1024 InsertItem(index, entryname, icon_idx);
1025 if (m_restorepaths.find(GitPath->GetWinPathString()) != m_restorepaths.end())
1026 SetItemState(index, INDEXTOOVERLAYMASK(OVL_RESTORE), TVIS_OVERLAYMASK);
1028 this->SetItemData(index, (DWORD_PTR)GitPath);
1029 // SVNSLC_COLFILENAME
1030 SetItemText(index, nCol++, GitPath->GetFileOrDirectoryName());
1031 // SVNSLC_COLEXT
1032 SetItemText(index, nCol++, GitPath->GetFileExtension());
1033 // SVNSLC_COLSTATUS
1034 SetItemText(index, nCol++, GitPath->GetActionName());
1036 SetItemText(index, GetColumnIndex(GITSLC_COLADD),GitPath->m_StatAdd);
1037 SetItemText(index, GetColumnIndex(GITSLC_COLDEL),GitPath->m_StatDel);
1040 SetCheck(index, GitPath->m_Checked);
1041 if (GitPath->m_Checked)
1042 m_nSelected++;
1045 if( GitPath->m_Action & CTGitPath::LOGACTIONS_IGNORE)
1046 SetItemGroup(index, 2);
1047 else if( GitPath->m_Action & CTGitPath::LOGACTIONS_UNVER)
1048 SetItemGroup(index,1);
1049 else
1051 SetItemGroup(index, GitPath->m_ParentNo&(PARENT_MASK|MERGE_MASK));
1054 m_bBlock = FALSE;
1058 #if 0
1059 void CGitStatusListCtrl::AddEntry(FileEntry * entry, WORD langID, int listIndex)
1061 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
1063 CString path = entry->GetPath().GetGitPathString();
1064 if ( m_mapFilenameToChecked.size()!=0 && m_mapFilenameToChecked.find(path) != m_mapFilenameToChecked.end() )
1066 // The user manually de-/selected an item. We now restore this status
1067 // when refreshing.
1068 entry->checked = m_mapFilenameToChecked[path];
1071 m_bBlock = TRUE;
1072 TCHAR buf[100];
1073 int index = listIndex;
1074 int nCol = 1;
1075 CString entryname = entry->GetDisplayName();
1076 int icon_idx = 0;
1077 if (entry->isfolder)
1078 icon_idx = m_nIconFolder;
1079 else
1081 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(entry->path);
1083 // relative path
1084 InsertItem(index, entryname, icon_idx);
1085 // SVNSLC_COLFILENAME
1086 SetItemText(index, nCol++, entry->path.GetFileOrDirectoryName());
1087 // SVNSLC_COLEXT
1088 SetItemText(index, nCol++, entry->path.GetFileExtension());
1089 // SVNSLC_COLSTATUS
1090 if (entry->isNested)
1092 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1093 SetItemText(index, nCol++, sTemp);
1095 else
1097 GitStatus::GetStatusString(hResourceHandle, entry->status, buf, _countof(buf), (WORD)langID);
1098 if ((entry->copied)&&(_tcslen(buf)>1))
1099 _tcscat_s(buf, 100, _T(" (+)"));
1100 if ((entry->switched)&&(_tcslen(buf)>1))
1101 _tcscat_s(buf, 100, _T(" (s)"));
1102 SetItemText(index, nCol++, buf);
1104 // SVNSLC_COLREMOTESTATUS
1105 if (entry->isNested)
1107 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1108 SetItemText(index, nCol++, sTemp);
1110 else
1112 #if 0
1113 SVNStatus::GetStatusString(hResourceHandle, entry->remotestatus, buf, _countof(buf), (WORD)langID);
1114 if ((entry->copied)&&(_tcslen(buf)>1))
1115 _tcscat_s(buf, 100, _T(" (+)"));
1116 if ((entry->switched)&&(_tcslen(buf)>1))
1117 _tcscat_s(buf, 100, _T(" (s)"));
1118 #endif
1119 SetItemText(index, nCol++, buf);
1121 // SVNSLC_COLTEXTSTATUS
1122 if (entry->isNested)
1124 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1125 SetItemText(index, nCol++, sTemp);
1127 else
1129 #if 0
1130 SVNStatus::GetStatusString(hResourceHandle, entry->textstatus, buf, _countof(buf), (WORD)langID);
1131 if ((entry->copied)&&(_tcslen(buf)>1))
1132 _tcscat_s(buf, 100, _T(" (+)"));
1133 if ((entry->switched)&&(_tcslen(buf)>1))
1134 _tcscat_s(buf, 100, _T(" (s)"));
1135 #endif
1136 SetItemText(index, nCol++, buf);
1138 // SVNSLC_COLPROPSTATUS
1139 if (entry->isNested)
1141 SetItemText(index, nCol++, _T(""));
1143 else
1145 #if 0
1146 SVNStatus::GetStatusString(hResourceHandle, entry->propstatus, buf, _countof(buf), (WORD)langID);
1147 if ((entry->copied)&&(_tcslen(buf)>1))
1148 _tcscat_s(buf, 100, _T(" (+)"));
1149 if ((entry->switched)&&(_tcslen(buf)>1))
1150 _tcscat_s(buf, 100, _T(" (s)"));
1151 #endif
1152 SetItemText(index, nCol++, buf);
1154 // SVNSLC_COLREMOTETEXT
1155 if (entry->isNested)
1157 SetItemText(index, nCol++, _T(""));
1159 else
1161 #if 0
1162 SVNStatus::GetStatusString(hResourceHandle, entry->remotetextstatus, buf, _countof(buf), (WORD)langID);
1163 SetItemText(index, nCol++, buf);
1164 #endif
1166 // SVNSLC_COLREMOTEPROP
1167 if (entry->isNested)
1169 SetItemText(index, nCol++, _T(""));
1171 else
1173 // SVNStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, _countof(buf), (WORD)langID);
1174 SetItemText(index, nCol++, buf);
1176 // SVNSLC_COLURL
1177 // SetItemText(index, nCol++, entry->url);
1178 // SVNSLC_COLLOCK
1179 #if 0
1180 if (!m_HeadRev.IsHead())
1182 // we have contacted the repository
1184 // decision-matrix
1185 // wc repository text
1186 // "" "" ""
1187 // "" UID1 owner
1188 // UID1 UID1 owner
1189 // UID1 "" lock has been broken
1190 // UID1 UID2 lock has been stolen
1191 if (entry->lock_token.IsEmpty() || (entry->lock_token.Compare(entry->lock_remotetoken)==0))
1193 if (entry->lock_owner.IsEmpty())
1194 SetItemText(index, nCol++, entry->lock_remoteowner);
1195 else
1196 SetItemText(index, nCol++, entry->lock_owner);
1198 else if (entry->lock_remotetoken.IsEmpty())
1200 // broken lock
1201 CString temp(MAKEINTRESOURCE(IDS_STATUSLIST_LOCKBROKEN));
1202 SetItemText(index, nCol++, temp);
1204 else
1206 // stolen lock
1207 CString temp;
1208 temp.Format(IDS_STATUSLIST_LOCKSTOLEN, (LPCTSTR)entry->lock_remoteowner);
1209 SetItemText(index, nCol++, temp);
1212 else
1213 SetItemText(index, nCol++, entry->lock_owner);
1214 // SVNSLC_COLLOCKCOMMENT
1215 SetItemText(index, nCol++, entry->lock_comment);
1216 // SVNSLC_COLAUTHOR
1217 SetItemText(index, nCol++, entry->last_commit_author);
1218 // SVNSLC_COLREVISION
1219 CString temp;
1220 temp.Format(_T("%ld"), entry->last_commit_rev);
1221 if (entry->last_commit_rev > 0)
1222 SetItemText(index, nCol++, temp);
1223 else
1224 SetItemText(index, nCol++, _T(""));
1225 // SVNSLC_COLREMOTEREVISION
1226 temp.Format(_T("%ld"), entry->remoterev);
1227 if (entry->remoterev > 0)
1228 SetItemText(index, nCol++, temp);
1229 else
1230 SetItemText(index, nCol++, _T(""));
1231 // SVNSLC_COLDATE
1232 TCHAR datebuf[SVN_DATE_BUFFER];
1233 apr_time_t date = entry->last_commit_date;
1234 SVN::formatDate(datebuf, date, true);
1235 if (date)
1236 SetItemText(index, nCol++, datebuf);
1237 else
1238 SetItemText(index, nCol++, _T(""));
1239 // SVNSLC_COLSVNNEEDSLOCK
1240 BOOL bFoundSVNNeedsLock = entry->present_props.IsNeedsLockSet();
1241 CString strSVNNeedsLock = (bFoundSVNNeedsLock) ? _T("*") : _T("");
1242 SetItemText(index, nCol++, strSVNNeedsLock);
1243 // SVNSLC_COLCOPYFROM
1244 if (m_sURL.Compare(entry->copyfrom_url.Left(m_sURL.GetLength()))==0)
1245 temp = entry->copyfrom_url.Mid(m_sURL.GetLength());
1246 else
1247 temp = entry->copyfrom_url;
1248 SetItemText(index, nCol++, temp);
1249 // SVNSLC_COLMODIFICATIONDATE
1250 __int64 filetime = entry->GetPath().GetLastWriteTime();
1251 if ( (filetime) && (entry->status!=git_wc_status_deleted) )
1253 FILETIME* f = (FILETIME*)(__int64*)&filetime;
1254 TCHAR datebuf[SVN_DATE_BUFFER];
1255 SVN::formatDate(datebuf,*f,true);
1256 SetItemText(index, nCol++, datebuf);
1258 else
1260 SetItemText(index, nCol++, _T(""));
1263 // user-defined properties
1264 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
1265 ; i < count
1266 ; ++i)
1268 assert (i == nCol++);
1269 assert (m_ColumnManager.IsUserProp (i));
1271 CString name = m_ColumnManager.GetName(i);
1272 if (entry->present_props.HasProperty (name))
1274 const CString& propVal = entry->present_props [name];
1275 if (propVal.IsEmpty())
1276 SetItemText(index, i, m_sNoPropValueText);
1277 else
1278 SetItemText(index, i, propVal);
1280 else
1281 SetItemText(index, i, _T(""));
1284 SetCheck(index, entry->checked);
1285 if (entry->checked)
1286 m_nSelected++;
1287 if (m_changelists.find(entry->changelist) != m_changelists.end())
1288 SetItemGroup(index, m_changelists[entry->changelist]);
1289 else
1290 SetItemGroup(index, 0);
1291 m_bBlock = FALSE;
1292 #endif
1294 #endif
1295 bool CGitStatusListCtrl::SetItemGroup(int item, int groupindex)
1297 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1298 // return false;
1299 if (groupindex < 0)
1300 return false;
1301 LVITEM i = {0};
1302 i.mask = LVIF_GROUPID;
1303 i.iItem = item;
1304 i.iSubItem = 0;
1305 i.iGroupId = groupindex;
1307 return !!SetItem(&i);
1310 void CGitStatusListCtrl::OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult)
1312 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1313 *pResult = 0;
1314 if (m_bBlock)
1315 return;
1316 m_bBlock = TRUE;
1317 if (m_nSortedColumn == phdr->iItem)
1318 m_bAscending = !m_bAscending;
1319 else
1320 m_bAscending = TRUE;
1321 m_nSortedColumn = phdr->iItem;
1322 Show(m_dwShow, 0, m_bShowFolders,false,true);
1324 m_bBlock = FALSE;
1327 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
1329 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1330 *pResult = 0;
1332 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1333 if ((m_bBlock)&&(m_bBlockUI))
1335 // if we're blocked, prevent changing of the check state
1336 if ((!ISCHECKED(pNMLV->uOldState) && ISCHECKED(pNMLV->uNewState))||
1337 (ISCHECKED(pNMLV->uOldState) && !ISCHECKED(pNMLV->uNewState)))
1338 *pResult = TRUE;
1342 BOOL CGitStatusListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
1344 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1345 *pResult = 0;
1346 CWnd* pParent = GetParent();
1347 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
1349 pParent->SendMessage(GITSLNM_ITEMCHANGED, pNMLV->iItem);
1352 if ((pNMLV->uNewState==0)||(pNMLV->uNewState & LVIS_SELECTED)||(pNMLV->uNewState & LVIS_FOCUSED))
1353 return FALSE;
1355 if (m_bBlock)
1356 return FALSE;
1358 bool bSelected = !!(ListView_GetItemState(m_hWnd, pNMLV->iItem, LVIS_SELECTED) & LVIS_SELECTED);
1359 int nListItems = GetItemCount();
1361 m_bBlock = TRUE;
1362 // was the item checked?
1364 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1365 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1367 if (GetCheck(pNMLV->iItem))
1369 CheckEntry(pNMLV->iItem, nListItems);
1370 if (bSelected)
1372 POSITION pos = GetFirstSelectedItemPosition();
1373 int index;
1374 while ((index = GetNextSelectedItem(pos)) >= 0)
1376 if (index != pNMLV->iItem)
1377 CheckEntry(index, nListItems);
1381 else
1383 UncheckEntry(pNMLV->iItem, nListItems);
1384 if (bSelected)
1386 POSITION pos = GetFirstSelectedItemPosition();
1387 int index;
1388 while ((index = GetNextSelectedItem(pos)) >= 0)
1390 if (index != pNMLV->iItem)
1391 UncheckEntry(index, nListItems);
1396 GetStatisticsString();
1397 m_bBlock = FALSE;
1398 NotifyCheck();
1400 return FALSE;
1403 void CGitStatusListCtrl::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
1405 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
1407 *pResult = FALSE;
1410 void CGitStatusListCtrl::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
1412 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
1414 Invalidate(FALSE);
1417 void CGitStatusListCtrl::CheckEntry(int index, int /*nListItems*/)
1419 Locker lock(m_critSec);
1420 //FileEntry * entry = GetListEntry(index);
1421 CTGitPath *path=(CTGitPath*)GetItemData(index);
1422 ASSERT(path != NULL);
1423 if (path == NULL)
1424 return;
1425 m_mapFilenameToChecked[path->GetGitPathString()] = true;
1426 SetCheck(index, TRUE);
1427 //entry = GetListEntry(index);
1428 // if an unversioned item was checked, then we need to check if
1429 // the parent folders are unversioned too. If the parent folders actually
1430 // are unversioned, then check those too.
1431 #if 0
1432 if (entry->status == git_wc_status_unversioned)
1434 // we need to check the parent folder too
1435 const CTGitPath& folderpath = entry->path;
1436 for (int i=0; i< nListItems; ++i)
1438 FileEntry * testEntry = GetListEntry(i);
1439 ASSERT(testEntry != NULL);
1440 if (testEntry == NULL)
1441 continue;
1442 if (!testEntry->checked)
1444 if (testEntry->path.IsAncestorOf(folderpath) && (!testEntry->path.IsEquivalentTo(folderpath)))
1446 SetEntryCheck(testEntry,i,true);
1447 m_nSelected++;
1452 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1453 if ( (entry->status == git_wc_status_deleted) || (m_bCheckChildrenWithParent) || (bShift) )
1455 // if a deleted folder gets checked, we have to check all
1456 // children of that folder too.
1457 if (entry->path.IsDirectory())
1459 SetCheckOnAllDescendentsOf(entry, true);
1462 // if a deleted file or folder gets checked, we have to
1463 // check all parents of this item too.
1464 for (int i=0; i<nListItems; ++i)
1466 FileEntry * testEntry = GetListEntry(i);
1467 ASSERT(testEntry != NULL);
1468 if (testEntry == NULL)
1469 continue;
1470 if (!testEntry->checked)
1472 if (testEntry->path.IsAncestorOf(entry->path) && (!testEntry->path.IsEquivalentTo(entry->path)))
1474 if ((testEntry->status == git_wc_status_deleted)||(m_bCheckChildrenWithParent))
1476 SetEntryCheck(testEntry,i,true);
1477 m_nSelected++;
1478 // now we need to check all children of this parent folder
1479 SetCheckOnAllDescendentsOf(testEntry, true);
1485 #endif
1486 if ( !path->m_Checked )
1488 path->m_Checked = TRUE;
1489 m_nSelected++;
1493 void CGitStatusListCtrl::UncheckEntry(int index, int /*nListItems*/)
1495 Locker lock(m_critSec);
1496 CTGitPath *path=(CTGitPath*)GetItemData(index);
1497 ASSERT(path != NULL);
1498 if (path == NULL)
1499 return;
1500 SetCheck(index, FALSE);
1501 m_mapFilenameToChecked[path->GetGitPathString()] = false;
1502 //entry = GetListEntry(index);
1503 // item was unchecked
1504 #if 0
1505 if (entry->path.IsDirectory())
1507 // disable all files within an unselected folder, except when unchecking a folder with property changes
1508 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1509 if ( (entry->status != git_wc_status_modified) || (bShift) )
1511 SetCheckOnAllDescendentsOf(entry, false);
1514 else if (entry->status == git_wc_status_deleted)
1516 // a "deleted" file was unchecked, so uncheck all parent folders
1517 // and all children of those parents
1518 for (int i=0; i<nListItems; i++)
1520 FileEntry * testEntry = GetListEntry(i);
1521 ASSERT(testEntry != NULL);
1522 if (testEntry == NULL)
1523 continue;
1524 if (testEntry->checked)
1526 if (testEntry->path.IsAncestorOf(entry->path))
1528 if (testEntry->status == git_wc_status_deleted)
1530 SetEntryCheck(testEntry,i,false);
1531 m_nSelected--;
1533 SetCheckOnAllDescendentsOf(testEntry, false);
1539 #endif
1540 if ( path->m_Checked )
1542 path->m_Checked = FALSE;
1543 m_nSelected--;
1546 #if 0
1547 bool CGitStatusListCtrl::EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2)
1549 return pEntry1->path < pEntry2->path;
1552 bool CGitStatusListCtrl::IsEntryVersioned(const FileEntry* pEntry1)
1554 return pEntry1->status != git_wc_status_unversioned;
1556 #endif
1557 bool CGitStatusListCtrl::BuildStatistics()
1560 bool bRefetchStatus = false;
1562 // now gather some statistics
1563 m_nUnversioned = 0;
1564 m_nNormal = 0;
1565 m_nModified = 0;
1566 m_nAdded = 0;
1567 m_nDeleted = 0;
1568 m_nConflicted = 0;
1569 m_nTotal = 0;
1570 m_nSelected = 0;
1571 m_nLineAdded = 0;
1572 m_nLineDeleted = 0;
1573 m_nRenamed = 0;
1575 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1577 int status=((CTGitPath*)m_arStatusArray[i])->m_Action;
1579 m_nLineAdded += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatAdd);
1580 m_nLineDeleted += _tstol(((CTGitPath*)m_arStatusArray[i])->m_StatDel);
1582 if(status&(CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
1583 m_nAdded++;
1585 if(status&CTGitPath::LOGACTIONS_DELETED)
1586 m_nDeleted++;
1588 if(status&(CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_MODIFIED))
1589 m_nModified++;
1591 if(status&CTGitPath::LOGACTIONS_UNMERGED)
1592 m_nConflicted++;
1594 if(status&(CTGitPath::LOGACTIONS_IGNORE|CTGitPath::LOGACTIONS_UNVER))
1595 m_nUnversioned++;
1597 if(status&(CTGitPath::LOGACTIONS_REPLACED))
1598 m_nRenamed++;
1600 if(((CTGitPath*)m_arStatusArray[i])->m_Checked)
1601 m_nSelected++;
1603 // } // switch (entry->status)
1604 // } // if (entry)
1605 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1606 return !bRefetchStatus;
1608 return FALSE;
1612 int CGitStatusListCtrl::GetGroupFromPoint(POINT * ppt)
1614 // the point must be relative to the upper left corner of the control
1616 if (ppt == NULL)
1617 return -1;
1618 if (!IsGroupViewEnabled())
1619 return -1;
1621 POINT pt = *ppt;
1622 pt.x = 10;
1623 UINT flags = 0;
1624 int nItem = -1;
1625 RECT rc;
1626 GetWindowRect(&rc);
1627 while (((flags & LVHT_BELOW) == 0)&&(pt.y < rc.bottom))
1629 nItem = HitTest(pt, &flags);
1630 if ((flags & LVHT_ONITEM)||(flags & LVHT_EX_GROUP_HEADER))
1632 // the first item below the point
1634 // check if the point is too much right (i.e. if the point
1635 // is farther to the right than the width of the item)
1636 RECT r;
1637 GetItemRect(nItem, &r, LVIR_LABEL);
1638 if (ppt->x > r.right)
1639 return -1;
1641 LVITEM lv = {0};
1642 lv.mask = LVIF_GROUPID;
1643 lv.iItem = nItem;
1644 GetItem(&lv);
1645 int groupID = lv.iGroupId;
1646 // now we search upwards and check if the item above this one
1647 // belongs to another group. If it belongs to the same group,
1648 // we're not over a group header
1649 while (pt.y >= 0)
1651 pt.y -= 2;
1652 nItem = HitTest(pt, &flags);
1653 if ((flags & LVHT_ONITEM)&&(nItem >= 0))
1655 // the first item below the point
1656 LVITEM lv = {0};
1657 lv.mask = LVIF_GROUPID;
1658 lv.iItem = nItem;
1659 GetItem(&lv);
1660 if (lv.iGroupId != groupID)
1661 return groupID;
1662 else
1663 return -1;
1666 if (pt.y < 0)
1667 return groupID;
1668 return -1;
1670 pt.y += 2;
1672 return -1;
1675 void CGitStatusListCtrl::OnContextMenuGroup(CWnd * /*pWnd*/, CPoint point)
1677 POINT clientpoint = point;
1678 ScreenToClient(&clientpoint);
1679 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint) >= 0))
1681 CMenu popup;
1682 if (popup.CreatePopupMenu())
1684 CString temp;
1685 temp.LoadString(IDS_STATUSLIST_CHECKGROUP);
1686 popup.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_CHECKGROUP, temp);
1687 temp.LoadString(IDS_STATUSLIST_UNCHECKGROUP);
1688 popup.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_UNCHECKGROUP, temp);
1689 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1690 bool bCheck = false;
1691 switch (cmd)
1693 case IDGITLC_CHECKGROUP:
1694 bCheck = true;
1695 // fall through here
1696 case IDGITLC_UNCHECKGROUP:
1698 int group = GetGroupFromPoint(&clientpoint);
1699 // go through all items and check/uncheck those assigned to the group
1700 // but block the OnLvnItemChanged handler
1701 m_bBlock = true;
1702 LVITEM lv;
1703 for (int i=0; i<GetItemCount(); ++i)
1705 SecureZeroMemory(&lv, sizeof(LVITEM));
1706 lv.mask = LVIF_GROUPID;
1707 lv.iItem = i;
1708 GetItem(&lv);
1710 if (lv.iGroupId == group)
1712 CTGitPath * entry = (CTGitPath*)GetItemData(i);
1713 if (entry)
1715 bool bOldCheck = entry->m_Checked;
1716 SetEntryCheck(entry, i, bCheck);
1717 if (bCheck != bOldCheck)
1719 if (bCheck)
1720 m_nSelected++;
1721 else
1722 m_nSelected--;
1728 GetStatisticsString();
1729 NotifyCheck();
1730 m_bBlock = false;
1732 break;
1738 void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point)
1741 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1743 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1744 CTGitPath * filepath;
1746 int selIndex = GetSelectionMark();
1747 if ((point.x == -1) && (point.y == -1))
1749 CRect rect;
1750 GetItemRect(selIndex, &rect, LVIR_LABEL);
1751 ClientToScreen(&rect);
1752 point = rect.CenterPoint();
1754 if ((GetSelectedCount() == 0) && (m_bHasCheckboxes))
1756 // nothing selected could mean the context menu is requested for
1757 // a group header
1758 OnContextMenuGroup(pWnd, point);
1760 else if (selIndex >= 0)
1762 //FileEntry * entry = GetListEntry(selIndex);
1764 filepath = (CTGitPath * )GetItemData(selIndex);
1766 ASSERT(filepath != NULL);
1767 if (filepath == NULL)
1768 return;
1770 //const CTGitPath& filepath = entry->path;
1771 int wcStatus = filepath->m_Action;
1772 // entry is selected, now show the popup menu
1773 Locker lock(m_critSec);
1774 CIconMenu popup;
1775 CMenu changelistSubMenu;
1776 CMenu ignoreSubMenu;
1777 if (popup.CreatePopupMenu())
1779 //Add Menu for version controlled file
1781 if (GetSelectedCount() > 0 && wcStatus & CTGitPath::LOGACTIONS_UNMERGED)
1783 if (GetSelectedCount() == 1 && (m_dwContextMenus & GITSLC_POPCONFLICT)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1785 popup.AppendMenuIcon(IDGITLC_EDITCONFLICT, IDS_MENUCONFLICT, IDI_CONFLICT);
1787 if (m_dwContextMenus & GITSLC_POPRESOLVE)
1789 popup.AppendMenuIcon(IDGITLC_RESOLVECONFLICT, IDS_STATUSLIST_CONTEXT_RESOLVED, IDI_RESOLVE);
1791 if ((m_dwContextMenus & GITSLC_POPRESOLVE)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1793 popup.AppendMenuIcon(IDGITLC_RESOLVETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS, IDI_RESOLVE);
1794 popup.AppendMenuIcon(IDGITLC_RESOLVEMINE, IDS_SVNPROGRESS_MENUUSEMINE, IDI_RESOLVE);
1796 if ((m_dwContextMenus & GITSLC_POPCONFLICT)||(m_dwContextMenus & GITSLC_POPRESOLVE))
1797 popup.AppendMenu(MF_SEPARATOR);
1800 if (GetSelectedCount() > 0)
1802 if (wcStatus & CTGitPath::LOGACTIONS_UNVER)
1803 if (m_dwContextMenus & GITSLC_POPADD)
1805 //if ( entry->IsFolder() )
1807 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1809 //else
1811 popup.AppendMenuIcon(IDGITLC_ADD, IDS_STATUSLIST_CONTEXT_ADD, IDI_ADD);
1816 if (!(wcStatus &CTGitPath::LOGACTIONS_UNVER))
1818 if ( (m_dwContextMenus & GITSLC_POPCOMPAREWITHBASE) && GetSelectedCount()>0)
1820 if(filepath->m_ParentNo & MERGE_MASK)
1821 popup.AppendMenuIcon(IDGITLC_COMPARE, IDS_TREE_DIFF, IDI_DIFF);
1822 else
1823 popup.AppendMenuIcon(IDGITLC_COMPARE, IDS_LOG_COMPAREWITHBASE, IDI_DIFF);
1825 popup.SetDefaultItem(IDGITLC_COMPARE, FALSE);
1828 if ((m_dwContextMenus & this->GetContextMenuBit(IDGITLC_COMPAREWC)) && GetSelectedCount()>0 && m_bHasWC)
1830 if( (!m_CurrentVersion.IsEmpty()) && m_CurrentVersion != GIT_REV_ZERO)
1831 popup.AppendMenuIcon(IDGITLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1833 //Select one items
1834 if (GetSelectedCount() == 1)
1836 bool bEntryAdded = false;
1837 //if (entry->remotestatus <= git_wc_status_normal)
1839 // if (wcStatus > git_wc_status_normal)
1840 // {
1841 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
1842 // {
1843 if(!g_Git.IsInitRepos() && (m_dwContextMenus&GITSLC_POPGNUDIFF))
1845 popup.AppendMenuIcon(IDGITLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1847 bEntryAdded = true;
1849 // }
1850 // }
1853 //else if (wcStatus != git_wc_status_deleted)
1855 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
1856 // {
1857 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1858 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1859 // bEntryAdded = true;
1860 // }
1861 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
1862 // {
1863 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1864 // bEntryAdded = true;
1865 // }
1867 if (bEntryAdded)
1868 popup.AppendMenu(MF_SEPARATOR);
1870 //else if (GetSelectedCount() > 1)
1872 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1873 // {
1874 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1875 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1876 // }
1880 if( (!this->m_Rev1.IsEmpty()) || (!this->m_Rev1.IsEmpty()) )
1882 if(GetSelectedCount() == 1)
1884 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_COMPARETWO))
1886 popup.AppendMenuIcon(IDGITLC_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1887 popup.SetDefaultItem(IDGITLC_COMPARETWO, FALSE);
1889 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_GNUDIFF2))
1891 popup.AppendMenuIcon(IDGITLC_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1896 //Select Multi item
1897 if (GetSelectedCount() > 0)
1899 if ((GetSelectedCount() == 2) && (m_dwContextMenus & this->GetContextMenuBit(GITSLC_POPCOMPARETWOFILES)) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO))
1901 POSITION pos = GetFirstSelectedItemPosition();
1902 int index = GetNextSelectedItem(pos);
1903 if (index >= 0)
1905 CTGitPath * entry2 = NULL;
1906 bool bothItemsAreExistingFiles = true;
1907 entry2 = (CTGitPath * )GetItemData(index);
1908 if (entry2)
1909 bothItemsAreExistingFiles = !entry2->IsDirectory() && entry2->Exists();
1910 index = GetNextSelectedItem(pos);
1911 if (index >= 0)
1913 entry2 = (CTGitPath * )GetItemData(index);
1914 if (entry2)
1915 bothItemsAreExistingFiles = bothItemsAreExistingFiles && !entry2->IsDirectory() && entry2->Exists();
1916 if (bothItemsAreExistingFiles)
1917 popup.AppendMenuIcon(IDGITLC_COMPARETWOFILES, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES, IDI_DIFF);
1921 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
1922 // {
1923 // POSITION pos = GetFirstSelectedItemPosition();
1924 // int index = GetNextSelectedItem(pos);
1925 // if (index >= 0)
1926 // {
1927 // FileEntry * entry = GetListEntry(index);
1928 // git_wc_status_kind status1 = git_wc_status_none;
1929 // git_wc_status_kind status2 = git_wc_status_none;
1930 // if (entry)
1931 // status1 = entry->status;
1932 // index = GetNextSelectedItem(pos);
1933 // if (index >= 0)
1934 // {
1935 // entry = GetListEntry(index);
1936 // if (entry)
1937 // status2 = entry->status;
1938 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
1939 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
1940 // {
1941 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
1942 // }
1943 // }
1944 // }
1945 // }
1946 // if (wcStatus > git_wc_status_normal)
1947 // {
1948 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1949 // {
1950 // // reverting missing folders is not possible
1951 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1952 // {
1953 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1954 // }
1955 // }
1956 // }
1957 // if (entry->remotestatus > git_wc_status_normal)
1958 // {
1959 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1960 // {
1961 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1962 // }
1963 // }
1966 if ( (GetSelectedCount() >0 ) && (!(wcStatus & CTGitPath::LOGACTIONS_UNVER)) && m_bHasWC)
1968 if ((m_dwContextMenus & GITSLC_POPREVERT) && (this->m_CurrentVersion.IsEmpty() || this->m_CurrentVersion == GIT_REV_ZERO))
1970 popup.AppendMenuIcon(IDGITLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1973 if (m_dwContextMenus & GITSLC_POPRESTORE && !filepath->IsDirectory())
1975 if (m_restorepaths.find(filepath->GetWinPathString()) == m_restorepaths.end())
1976 popup.AppendMenuIcon(IDGITLC_CREATERESTORE, IDS_MENUCREATERESTORE, IDI_RESTORE);
1977 else
1978 popup.AppendMenuIcon(IDGITLC_RESTOREPATH, IDS_MENURESTORE, IDI_RESTORE);
1981 if ((m_dwContextMenus & GetContextMenuBit(IDGITLC_REVERTTOREV)) && ( !this->m_CurrentVersion.IsEmpty() )
1982 && this->m_CurrentVersion != GIT_REV_ZERO && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
1984 popup.AppendMenuIcon(IDGITLC_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1988 if ((GetSelectedCount() == 1)&&(!(wcStatus & CTGitPath::LOGACTIONS_UNVER))
1989 &&(!(wcStatus & CTGitPath::LOGACTIONS_IGNORE)))
1991 if (m_dwContextMenus & GITSLC_POPSHOWLOG)
1993 popup.AppendMenuIcon(IDGITLC_LOG, IDS_REPOBROWSE_SHOWLOG, IDI_LOG);
1995 if (m_dwContextMenus & GITSLC_POPSHOWLOGOLDNAME && (wcStatus & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !filepath->GetGitOldPathString().IsEmpty()))
1997 popup.AppendMenuIcon(IDGITLC_LOGOLDNAME, IDS_STATUSLIST_SHOWLOGOLDNAME, IDI_LOG);
1999 if (m_dwContextMenus & GITSLC_POPBLAME && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED) && m_bHasWC)
2001 popup.AppendMenuIcon(IDGITLC_BLAME, IDS_MENUBLAME, IDI_BLAME);
2004 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
2005 if ( (GetSelectedCount() == 1) )
2007 if (m_dwContextMenus & this->GetContextMenuBit(IDGITLC_SAVEAS) && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
2009 popup.AppendMenuIcon(IDGITLC_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2012 if (m_dwContextMenus & GITSLC_POPOPEN && ! filepath->IsDirectory() && !(wcStatus & CTGitPath::LOGACTIONS_DELETED))
2014 popup.AppendMenuIcon(IDGITLC_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2015 popup.AppendMenuIcon(IDGITLC_OPEN, IDS_REPOBROWSE_OPEN, IDI_OPEN);
2016 popup.AppendMenuIcon(IDGITLC_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2017 if (wcStatus &CTGitPath::LOGACTIONS_UNVER) {
2018 popup.SetDefaultItem(IDGITLC_OPEN, FALSE);
2022 if (m_dwContextMenus & GITSLC_POPEXPLORE && !(wcStatus & CTGitPath::LOGACTIONS_DELETED) && m_bHasWC)
2024 popup.AppendMenuIcon(IDGITLC_EXPLORE, IDS_STATUSLIST_CONTEXT_EXPLORE, IDI_EXPLORER);
2028 if (GetSelectedCount() > 0)
2030 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
2031 // {
2032 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2033 // }
2034 // 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))
2035 // {
2036 // if (bShift)
2037 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
2038 // else
2039 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
2040 // }
2041 if ((wcStatus & CTGitPath::LOGACTIONS_UNVER)/*||(wcStatus == git_wc_status_deleted)*/)
2043 if (m_dwContextMenus & GITSLC_POPDELETE)
2045 popup.AppendMenuIcon(IDGITLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2048 if ( (wcStatus & CTGitPath::LOGACTIONS_UNVER || wcStatus & CTGitPath::LOGACTIONS_DELETED) )
2050 if (m_dwContextMenus & GITSLC_POPIGNORE)
2053 CTGitPathList ignorelist;
2054 FillListOfSelectedItemPaths(ignorelist);
2055 //check if all selected entries have the same extension
2056 bool bSameExt = true;
2057 CString sExt;
2058 for (int i=0; i<ignorelist.GetCount(); ++i)
2060 if (sExt.IsEmpty() && (i==0))
2061 sExt = ignorelist[i].GetFileExtension();
2062 else if (sExt.CompareNoCase(ignorelist[i].GetFileExtension())!=0)
2063 bSameExt = false;
2065 if (bSameExt)
2067 if (ignoreSubMenu.CreateMenu())
2069 CString ignorepath;
2070 if (ignorelist.GetCount()==1)
2071 ignorepath = ignorelist[0].GetFileOrDirectoryName();
2072 else
2073 ignorepath.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2074 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_IGNORE, ignorepath);
2075 ignorepath = _T("*")+sExt;
2076 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDGITLC_IGNOREMASK, ignorepath);
2077 CString temp;
2078 temp.LoadString(IDS_MENUIGNORE);
2079 popup.InsertMenu((UINT)-1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)ignoreSubMenu.m_hMenu, temp);
2082 else
2084 CString temp;
2085 if (ignorelist.GetCount()==1)
2087 temp.LoadString(IDS_MENUIGNORE);
2089 else
2091 temp.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2093 popup.AppendMenuIcon(IDGITLC_IGNORE, temp, IDI_IGNORE);
2101 if (GetSelectedCount() > 0)
2103 popup.AppendMenu(MF_SEPARATOR);
2104 popup.AppendMenuIcon(IDGITLC_COPY, IDS_STATUSLIST_CONTEXT_COPY, IDI_COPYCLIP);
2105 popup.AppendMenuIcon(IDGITLC_COPYEXT, IDS_STATUSLIST_CONTEXT_COPYEXT, IDI_COPYCLIP);
2106 #if 0
2107 if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS))
2108 &&(wcStatus != git_wc_status_unversioned)&&(wcStatus != git_wc_status_none))
2110 popup.AppendMenu(MF_SEPARATOR);
2111 // changelist commands
2112 size_t numChangelists = GetNumberOfChangelistsInSelection();
2113 if (numChangelists > 0)
2115 popup.AppendMenuIcon(IDSVNLC_REMOVEFROMCS, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS);
2117 if ((!entry->IsFolder())&&(changelistSubMenu.CreateMenu()))
2119 CString temp;
2120 temp.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS);
2121 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATECS, temp);
2123 if (entry->changelist.Compare(SVNSLC_IGNORECHANGELIST))
2125 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2126 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATEIGNORECS, SVNSLC_IGNORECHANGELIST);
2129 if (m_changelists.size() > 0)
2131 // find the changelist names
2132 bool bNeedSeparator = true;
2133 int cmdID = IDSVNLC_MOVETOCS;
2134 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
2136 if ((entry->changelist.Compare(it->first))&&(it->first.Compare(SVNSLC_IGNORECHANGELIST)))
2138 if (bNeedSeparator)
2140 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2141 bNeedSeparator = false;
2143 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, cmdID, it->first);
2144 cmdID++;
2148 temp.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS);
2149 popup.AppendMenu(MF_POPUP|MF_STRING, (UINT_PTR)changelistSubMenu.GetSafeHmenu(), temp);
2152 #endif
2155 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2157 m_bBlock = TRUE;
2158 AfxGetApp()->DoWaitCursor(1);
2159 //int iItemCountBeforeMenuCmd = GetItemCount();
2160 //bool bForce = false;
2161 switch (cmd)
2163 case IDGITLC_VIEWREV:
2164 OpenFile(filepath, ALTERNATIVEEDITOR);
2165 break;
2166 case IDGITLC_OPEN:
2167 OpenFile(filepath,OPEN);
2168 break;
2169 case IDGITLC_OPENWITH:
2170 OpenFile(filepath,OPEN_WITH);
2171 break;
2172 case IDGITLC_EXPLORE:
2174 ShellExecute(this->m_hWnd, _T("explore"), filepath->GetDirectory().GetWinPath(), NULL, NULL, SW_SHOW);
2176 break;
2177 case IDGITLC_CREATERESTORE:
2179 POSITION pos = GetFirstSelectedItemPosition();
2180 while (pos)
2182 int index = GetNextSelectedItem(pos);
2183 CTGitPath * entry2 = (CTGitPath * )GetItemData(index);
2184 ASSERT(entry2 != NULL);
2185 if (entry2 == NULL)
2186 continue;
2187 if (m_restorepaths.find(entry2->GetWinPathString()) != m_restorepaths.end())
2188 continue;
2189 CTGitPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
2190 if (CopyFile(g_Git.m_CurrentDir + _T("\\") + entry2->GetWinPathString(), tempFile.GetWinPath(), FALSE))
2192 m_restorepaths[entry2->GetWinPathString()] = tempFile.GetWinPathString();
2193 SetItemState(index, INDEXTOOVERLAYMASK(OVL_RESTORE), LVIS_OVERLAYMASK);
2196 Invalidate();
2198 break;
2199 case IDGITLC_RESTOREPATH:
2201 if (CMessageBox::Show(m_hWnd, IDS_STATUSLIST_RESTOREPATH, IDS_APPNAME, 2, IDI_QUESTION, IDS_RESTOREBUTTON, IDS_ABORTBUTTON) == 2)
2202 break;
2203 POSITION pos = GetFirstSelectedItemPosition();
2204 while (pos)
2206 int index = GetNextSelectedItem(pos);
2207 CTGitPath * entry2 = (CTGitPath * )GetItemData(index);
2208 ASSERT(entry2 != NULL);
2209 if (entry2 == NULL)
2210 continue;
2211 if (m_restorepaths.find(entry2->GetWinPathString()) == m_restorepaths.end())
2212 continue;
2213 if (CopyFile(m_restorepaths[entry2->GetWinPathString()], g_Git.m_CurrentDir + _T("\\") + entry2->GetWinPathString(), FALSE))
2215 m_restorepaths.erase(entry2->GetWinPathString());
2216 SetItemState(index, 0, LVIS_OVERLAYMASK);
2219 Invalidate();
2221 break;
2222 // Compare current version and work copy.
2223 case IDGITLC_COMPAREWC:
2225 POSITION pos = GetFirstSelectedItemPosition();
2226 while ( pos )
2228 int index = GetNextSelectedItem(pos);
2229 StartDiffWC(index);
2232 break;
2233 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2234 case IDGITLC_COMPARE:
2236 POSITION pos = GetFirstSelectedItemPosition();
2237 while ( pos )
2239 int index = GetNextSelectedItem(pos);
2240 StartDiff(index);
2243 break;
2244 case IDGITLC_COMPARETWO:
2246 POSITION pos = GetFirstSelectedItemPosition();
2247 while ( pos )
2249 int index = GetNextSelectedItem(pos);
2250 StartDiffTwo(index);
2253 break;
2254 case IDGITLC_COMPARETWOFILES:
2256 POSITION pos = GetFirstSelectedItemPosition();
2257 CTGitPath * firstfilepath = NULL, * secondfilepath = NULL;
2258 if (pos)
2260 firstfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
2261 ASSERT(firstfilepath != NULL);
2262 if (firstfilepath == NULL)
2263 break;
2265 secondfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos));
2266 ASSERT(secondfilepath != NULL);
2267 if (secondfilepath == NULL)
2268 break;
2270 CString sCmd;
2271 sCmd.Format(_T("/command:diff /path:\"%s\" /path2:\"%s\" /hwnd:%ld"), firstfilepath->GetWinPath(), secondfilepath->GetWinPath(), (unsigned long)m_hWnd);
2272 CAppUtils::RunTortoiseProc(sCmd);
2275 break;
2276 case IDGITLC_GNUDIFF1:
2278 // SVNDiff diff(NULL, this->m_hWnd, true);
2280 // if (entry->remotestatus <= git_wc_status_normal)
2281 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2282 // else
2283 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2284 if(m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
2286 CString fromwhere;
2287 if(m_amend)
2288 fromwhere = _T("~1");
2289 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,GitRev::GetHead()+fromwhere,
2290 *filepath,GitRev::GetWorkingCopy());
2292 else
2294 if((filepath->m_ParentNo&(PARENT_MASK|MERGE_MASK)) ==0)
2295 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_CurrentVersion+_T("~1"),
2296 *filepath,m_CurrentVersion);
2297 else
2299 CString str;
2300 if(filepath->m_ParentNo & MERGE_MASK)
2303 else
2305 str.Format(_T("%s^%d"),m_CurrentVersion,(filepath->m_ParentNo&PARENT_MASK)+1);
2308 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath, str,
2309 *filepath, m_CurrentVersion, false, false, false,
2310 !!(filepath->m_ParentNo & MERGE_MASK));
2314 break;
2315 case IDGITLC_GNUDIFF2:
2317 CAppUtils::StartShowUnifiedDiff(m_hWnd, *filepath, m_Rev2, *filepath, m_Rev1);
2319 break;
2321 case IDGITLC_ADD:
2322 { // The add went ok, but we now need to run through the selected items again
2323 // and update their status
2324 std::vector<int> selectIndex;
2326 POSITION pos = GetFirstSelectedItemPosition();
2327 int index;
2328 CMassiveGitTask mgt(L"add -f");
2329 while ((index = GetNextSelectedItem(pos)) >= 0)
2331 CTGitPath * path = (CTGitPath *)GetItemData(index);
2332 ASSERT(path);
2333 if(path == NULL)
2334 continue;
2336 selectIndex.push_back(index);
2337 mgt.AddFile(*path);
2339 BOOL cancel = FALSE;
2340 mgt.Execute(cancel);
2342 if (NULL != GetParent() && NULL != GetParent()->GetSafeHwnd())
2343 GetParent()->SendMessage(GITSLNM_NEEDSREFRESH);
2345 SetRedraw(TRUE);
2347 break;
2349 case IDGITLC_DELETE:
2351 //Collect paths
2352 std::vector<int> selectIndex;
2354 POSITION pos = GetFirstSelectedItemPosition();
2355 int index;
2356 while ((index = GetNextSelectedItem(pos)) >= 0)
2358 selectIndex.push_back(index);
2361 //Create file-list ('\0' separated) for SHFileOperation
2362 CString filelist;
2363 for(int i=0;i<selectIndex.size();i++)
2365 index=selectIndex[i];
2367 CTGitPath * path=(CTGitPath*)GetItemData(index);
2368 ASSERT(path);
2369 if(path == NULL)
2370 continue;
2372 filelist += path->GetWinPathString();
2373 filelist += _T("|");
2375 filelist += _T("|");
2376 int len = filelist.GetLength();
2377 TCHAR * buf = new TCHAR[len+2];
2378 _tcscpy_s(buf, len+2, filelist);
2379 for (int i=0; i<len; ++i)
2380 if (buf[i] == '|')
2381 buf[i] = 0;
2382 SHFILEOPSTRUCT fileop;
2383 fileop.hwnd = this->m_hWnd;
2384 fileop.wFunc = FO_DELETE;
2385 fileop.pFrom = buf;
2386 fileop.pTo = NULL;
2387 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
2388 fileop.lpszProgressTitle = _T("deleting file");
2389 int result = SHFileOperation(&fileop);
2390 delete [] buf;
2392 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
2394 SetRedraw(FALSE);
2395 POSITION pos = NULL;
2396 while ((pos = GetFirstSelectedItemPosition()) != 0)
2398 int index = GetNextSelectedItem(pos);
2399 if (GetCheck(index))
2400 m_nSelected--;
2401 m_nTotal--;
2403 RemoveListEntry(index);
2405 SetRedraw(TRUE);
2408 break;
2410 case IDGITLC_BLAME:
2412 CAppUtils::LaunchTortoiseBlame(g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath(), m_CurrentVersion);
2414 break;
2416 case IDGITLC_LOG:
2418 CString sCmd;
2419 sCmd.Format(_T("/command:log /path:\"%s\""), g_Git.m_CurrentDir + _T("\\") + filepath->GetWinPath());
2420 CAppUtils::RunTortoiseProc(sCmd);
2422 break;
2424 case IDGITLC_LOGOLDNAME:
2426 CTGitPath oldName(filepath->GetGitOldPathString());
2427 CString sCmd;
2428 sCmd.Format(_T("/command:log /path:\"%s\""), g_Git.m_CurrentDir + _T("\\") + oldName.GetWinPath());
2429 CAppUtils::RunTortoiseProc(sCmd);
2431 break;
2434 case IDGITLC_EDITCONFLICT:
2436 CAppUtils::ConflictEdit(*filepath,false,this->m_bIsRevertTheirMy);
2437 break;
2439 case IDGITLC_RESOLVETHEIRS: //follow up
2440 case IDGITLC_RESOLVEMINE: //follow up
2441 case IDGITLC_RESOLVECONFLICT:
2443 if (CMessageBox::Show(m_hWnd, IDS_PROC_RESOLVE, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO)==IDYES)
2445 POSITION pos = GetFirstSelectedItemPosition();
2446 while (pos != 0)
2448 int index;
2449 index = GetNextSelectedItem(pos);
2450 CTGitPath * fentry =(CTGitPath*) this->GetItemData(index);
2451 if(fentry == NULL)
2452 continue;
2453 CString gitcmd,output;
2454 output.Empty();
2456 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVETHEIRS) ||
2457 ((this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVEMINE) )
2459 gitcmd.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry->GetGitPathString());
2460 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2462 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2463 continue;
2466 output.Empty();
2467 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVEMINE) ||
2468 ((this->m_bIsRevertTheirMy)&&cmd == IDGITLC_RESOLVETHEIRS) )
2470 gitcmd.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry->GetGitPathString());
2471 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2473 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2474 continue;
2478 output.Empty();
2479 if ( fentry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
2481 gitcmd.Format(_T("git.exe add -f -- \"%s\""),fentry->GetGitPathString());
2482 if (g_Git.Run(gitcmd, &output,CP_UTF8))
2484 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2486 else
2488 fentry->m_Action |= CTGitPath::LOGACTIONS_MODIFIED;
2489 fentry->m_Action &=~CTGitPath::LOGACTIONS_UNMERGED;
2493 CAppUtils::RemoveTempMergeFile(*fentry);
2496 Show(m_dwShow, 0, m_bShowFolders,0,true);
2499 break;
2501 case IDGITLC_IGNORE:
2503 CTGitPathList ignorelist;
2504 //std::vector<CString> toremove;
2505 FillListOfSelectedItemPaths(ignorelist, true);
2506 SetRedraw(FALSE);
2508 if(!CAppUtils::IgnoreFile(ignorelist,false))
2509 break;
2511 for(int i=0;i<ignorelist.GetCount();i++)
2513 int nListboxEntries = GetItemCount();
2514 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2516 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2517 if (path->GetGitPathString()==ignorelist[i].GetGitPathString())
2519 RemoveListEntry(nItem);
2520 break;
2524 SetRedraw(TRUE);
2526 #if 0
2527 CTSVNPathList ignorelist;
2528 std::vector<CString> toremove;
2529 FillListOfSelectedItemPaths(ignorelist, true);
2530 SetRedraw(FALSE);
2531 for (int j=0; j<ignorelist.GetCount(); ++j)
2533 int nListboxEntries = GetItemCount();
2534 for (int i=0; i<nListboxEntries; ++i)
2536 if (GetListEntry(i)->GetPath().IsEquivalentTo(ignorelist[j]))
2538 selIndex = i;
2539 break;
2542 CString name = CPathUtils::PathPatternEscape(ignorelist[j].GetFileOrDirectoryName());
2543 CTSVNPath parentfolder = ignorelist[j].GetContainingDirectory();
2544 SVNProperties props(parentfolder, SVNRev::REV_WC, false);
2545 CStringA value;
2546 for (int i=0; i<props.GetCount(); i++)
2548 CString propname(props.GetItemName(i).c_str());
2549 if (propname.CompareNoCase(_T("git:ignore"))==0)
2551 stdstring stemp;
2552 // treat values as normal text even if they're not
2553 value = (char *)props.GetItemValue(i).c_str();
2556 if (value.IsEmpty())
2557 value = name;
2558 else
2560 value = value.Trim("\n\r");
2561 value += "\n";
2562 value += name;
2563 value.Remove('\r');
2565 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
2567 CString temp;
2568 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
2569 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2570 break;
2572 if (GetCheck(selIndex))
2573 m_nSelected--;
2574 m_nTotal--;
2576 // now, if we ignored a folder, remove all its children
2577 if (ignorelist[j].IsDirectory())
2579 for (int i=0; i<(int)m_arListArray.size(); ++i)
2581 FileEntry * entry = GetListEntry(i);
2582 if (entry->status == git_wc_status_unversioned)
2584 if (!ignorelist[j].IsEquivalentTo(entry->GetPath())&&(ignorelist[j].IsAncestorOf(entry->GetPath())))
2586 entry->status = git_wc_status_ignored;
2587 entry->textstatus = git_wc_status_ignored;
2588 if (GetCheck(i))
2589 m_nSelected--;
2590 toremove.push_back(entry->GetPath().GetSVNPathString());
2596 CTSVNPath basepath = m_arStatusArray[m_arListArray[selIndex]]->basepath;
2598 FileEntry * entry = m_arStatusArray[m_arListArray[selIndex]];
2599 if ( entry->status == git_wc_status_unversioned ) // keep "deleted" items
2600 toremove.push_back(entry->GetPath().GetSVNPathString());
2602 if (!m_bIgnoreRemoveOnly)
2604 SVNStatus status;
2605 git_wc_status2_t * s;
2606 CTSVNPath gitPath;
2607 s = status.GetFirstFileStatus(parentfolder, gitPath, false, git_depth_empty);
2608 // first check if the folder isn't already present in the list
2609 bool bFound = false;
2610 nListboxEntries = GetItemCount();
2611 for (int i=0; i<nListboxEntries; ++i)
2613 FileEntry * entry = GetListEntry(i);
2614 if (entry->path.IsEquivalentTo(gitPath))
2616 bFound = true;
2617 break;
2620 if (!bFound)
2622 if (s!=0)
2624 FileEntry * entry = new FileEntry();
2625 entry->path = gitPath;
2626 entry->basepath = basepath;
2627 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
2628 entry->textstatus = s->text_status;
2629 entry->propstatus = s->prop_status;
2630 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
2631 entry->remotetextstatus = s->repos_text_status;
2632 entry->remotepropstatus = s->repos_prop_status;
2633 entry->inunversionedfolder = FALSE;
2634 entry->checked = true;
2635 entry->inexternal = false;
2636 entry->direct = false;
2637 entry->isfolder = true;
2638 entry->last_commit_date = 0;
2639 entry->last_commit_rev = 0;
2640 entry->remoterev = 0;
2641 if (s->entry)
2643 if (s->entry->url)
2645 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
2648 if (s->entry && s->entry->present_props)
2650 entry->present_props = s->entry->present_props;
2652 m_arStatusArray.push_back(entry);
2653 m_arListArray.push_back(m_arStatusArray.size()-1);
2654 AddEntry(entry, langID, GetItemCount());
2659 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
2661 int nListboxEntries = GetItemCount();
2662 for (int i=0; i<nListboxEntries; ++i)
2664 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
2666 RemoveListEntry(i);
2667 break;
2671 SetRedraw(TRUE);
2673 #endif
2674 break;
2675 case IDGITLC_IGNOREMASK:
2677 CString common;
2678 CString ext=filepath->GetFileExtension();
2679 CTGitPathList ignorelist;
2680 FillListOfSelectedItemPaths(ignorelist, true);
2681 SetRedraw(FALSE);
2683 CAppUtils::IgnoreFile(ignorelist,true);
2685 common=ignorelist.GetCommonRoot().GetGitPathString();
2687 for (int i=0; i< GetItemCount(); ++i)
2689 CTGitPath *path=(CTGitPath*)GetItemData(i);
2690 if(!( path->m_Action & CTGitPath::LOGACTIONS_UNVER))
2691 continue;
2692 if( path->GetGitPathString().Left(common.GetLength()) == common )
2694 if (path->GetFileExtension()==ext)
2696 RemoveListEntry(i);
2697 i--; // remove index i at item, new one will replace.
2702 CWnd* pParent = GetParent();
2703 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2705 pParent->SendMessage(GITSLNM_NEEDSREFRESH);
2708 SetRedraw(TRUE);
2710 #if 0
2711 std::set<CTSVNPath> parentlist;
2712 for (int i=0; i<ignorelist.GetCount(); ++i)
2714 parentlist.insert(ignorelist[i].GetContainingDirectory());
2716 std::set<CTSVNPath>::iterator it;
2717 std::vector<CString> toremove;
2719 for (it = parentlist.begin(); it != parentlist.end(); ++it)
2721 CTSVNPath parentFolder = (*it).GetDirectory();
2722 SVNProperties props(parentFolder, SVNRev::REV_WC, false);
2723 CStringA value;
2724 for (int i=0; i<props.GetCount(); i++)
2726 CString propname(props.GetItemName(i).c_str());
2727 if (propname.CompareNoCase(_T("git:ignore"))==0)
2729 stdstring stemp;
2730 // treat values as normal text even if they're not
2731 value = (char *)props.GetItemValue(i).c_str();
2734 if (value.IsEmpty())
2735 value = name;
2736 else
2738 value = value.Trim("\n\r");
2739 value += "\n";
2740 value += name;
2741 value.Remove('\r');
2743 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
2745 CString temp;
2746 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
2747 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2749 else
2751 CTSVNPath basepath;
2752 int nListboxEntries = GetItemCount();
2753 for (int i=0; i<nListboxEntries; ++i)
2755 FileEntry * entry = GetListEntry(i);
2756 ASSERT(entry != NULL);
2757 if (entry == NULL)
2758 continue;
2759 if (basepath.IsEmpty())
2760 basepath = entry->basepath;
2761 // since we ignored files with a mask (e.g. *.exe)
2762 // we have to find find all files in the same
2763 // folder (IsAncestorOf() returns TRUE for _all_ children,
2764 // not just the immediate ones) which match the
2765 // mask and remove them from the list too.
2766 if ((entry->status == git_wc_status_unversioned)&&(parentFolder.IsAncestorOf(entry->path)))
2768 CString f = entry->path.GetSVNPathString();
2769 if (f.Mid(parentFolder.GetSVNPathString().GetLength()).Find('/')<=0)
2771 if (CStringUtils::WildCardMatch(name, f))
2773 if (GetCheck(i))
2774 m_nSelected--;
2775 m_nTotal--;
2776 toremove.push_back(f);
2781 if (!m_bIgnoreRemoveOnly)
2783 SVNStatus status;
2784 git_wc_status2_t * s;
2785 CTSVNPath gitPath;
2786 s = status.GetFirstFileStatus(parentFolder, gitPath, false, git_depth_empty);
2787 if (s!=0)
2789 // first check if the folder isn't already present in the list
2790 bool bFound = false;
2791 for (int i=0; i<nListboxEntries; ++i)
2793 FileEntry * entry = GetListEntry(i);
2794 if (entry->path.IsEquivalentTo(gitPath))
2796 bFound = true;
2797 break;
2800 if (!bFound)
2802 FileEntry * entry = new FileEntry();
2803 entry->path = gitPath;
2804 entry->basepath = basepath;
2805 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
2806 entry->textstatus = s->text_status;
2807 entry->propstatus = s->prop_status;
2808 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
2809 entry->remotetextstatus = s->repos_text_status;
2810 entry->remotepropstatus = s->repos_prop_status;
2811 entry->inunversionedfolder = false;
2812 entry->checked = true;
2813 entry->inexternal = false;
2814 entry->direct = false;
2815 entry->isfolder = true;
2816 entry->last_commit_date = 0;
2817 entry->last_commit_rev = 0;
2818 entry->remoterev = 0;
2819 if (s->entry)
2821 if (s->entry->url)
2823 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
2826 if (s->entry && s->entry->present_props)
2828 entry->present_props = s->entry->present_props;
2830 m_arStatusArray.push_back(entry);
2831 m_arListArray.push_back(m_arStatusArray.size()-1);
2832 AddEntry(entry, langID, GetItemCount());
2838 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
2840 int nListboxEntries = GetItemCount();
2841 for (int i=0; i<nListboxEntries; ++i)
2843 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
2845 RemoveListEntry(i);
2846 break;
2850 SetRedraw(TRUE);
2852 #endif
2853 break;
2855 case IDGITLC_REVERT:
2857 // If at least one item is not in the status "added"
2858 // we ask for a confirmation
2859 BOOL bConfirm = FALSE;
2860 POSITION pos = GetFirstSelectedItemPosition();
2861 int index;
2862 while ((index = GetNextSelectedItem(pos)) >= 0)
2864 //FileEntry * fentry = GetListEntry(index);
2865 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
2866 if(fentry && fentry->m_Action &CTGitPath::LOGACTIONS_MODIFIED )
2868 bConfirm = TRUE;
2869 break;
2873 CString str;
2874 str.Format(IDS_PROC_WARNREVERT,GetSelectedCount());
2876 if (!bConfirm || CMessageBox::Show(this->m_hWnd, str, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION)==IDYES)
2878 CTGitPathList targetList;
2879 FillListOfSelectedItemPaths(targetList);
2881 // make sure that the list is reverse sorted, so that
2882 // children are removed before any parents
2883 targetList.SortByPathname(true);
2885 // put all reverted files in the trashbin, except the ones with 'added'
2886 // status because they are not restored by the revert.
2887 CTGitPathList delList;
2888 POSITION pos = GetFirstSelectedItemPosition();
2889 int index;
2890 while ((index = GetNextSelectedItem(pos)) >= 0)
2892 CTGitPath *entry=(CTGitPath *)GetItemData(index);
2893 if (entry&&(!(entry->m_Action& CTGitPath::LOGACTIONS_ADDED))
2894 && (!(entry->m_Action& CTGitPath::LOGACTIONS_REPLACED)))
2896 CTGitPath fullpath;
2897 fullpath.SetFromWin(g_Git.m_CurrentDir+_T("\\")+entry->GetWinPath());
2898 delList.AddPath(fullpath);
2901 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2902 delList.DeleteAllFiles(true);
2904 CString revertToCommit = _T("HEAD");
2905 if (m_amend)
2906 revertToCommit = _T("HEAD~1");
2907 if (g_Git.Revert(revertToCommit, targetList))
2909 CMessageBox::Show(this->m_hWnd, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR);
2911 else
2913 bool updateStatusList = false;
2914 for(int i=0;i<targetList.GetCount();i++)
2916 int nListboxEntries = GetItemCount();
2917 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2919 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2920 if (path->GetGitPathString()==targetList[i].GetGitPathString())
2922 if(path->m_Action & CTGitPath::LOGACTIONS_ADDED)
2924 path->m_Action = CTGitPath::LOGACTIONS_UNVER;
2925 SetEntryCheck(path,nItem,false);
2926 updateStatusList = true;
2927 SetItemGroup(nItem,1);
2928 this->m_StatusFileList.RemoveItem(*path);
2929 this->m_UnRevFileList.AddPath(*path);
2930 //this->m_IgnoreFileList.RemoveItem(*path);
2933 else
2935 RemoveListEntry(nItem);
2937 break;
2941 SetRedraw(TRUE);
2942 SaveColumnWidths();
2943 Show(m_dwShow, 0, m_bShowFolders,updateStatusList,true);
2944 NotifyCheck();
2948 break;
2950 case IDGITLC_COPY:
2951 CopySelectedEntriesToClipboard(0);
2952 break;
2953 case IDGITLC_COPYEXT:
2954 CopySelectedEntriesToClipboard((DWORD)-1);
2955 break;
2957 case IDGITLC_SAVEAS:
2958 FileSaveAs(filepath);
2959 break;
2961 case IDGITLC_REVERTTOREV:
2962 RevertSelectedItemToVersion();
2963 break;
2964 #if 0
2965 case IDSVNLC_PROPERTIES:
2967 CTSVNPathList targetList;
2968 FillListOfSelectedItemPaths(targetList);
2969 CEditPropertiesDlg dlg;
2970 dlg.SetPathList(targetList);
2971 dlg.DoModal();
2972 if (dlg.HasChanged())
2974 // since the user might have changed/removed/added
2975 // properties recursively, we don't really know
2976 // which items have changed their status.
2977 // So tell the parent to do a refresh.
2978 CWnd* pParent = GetParent();
2979 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2981 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
2985 break;
2986 case IDSVNLC_COMMIT:
2988 CTSVNPathList targetList;
2989 FillListOfSelectedItemPaths(targetList);
2990 CTSVNPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
2991 VERIFY(targetList.WriteToFile(tempFile.GetWinPathString()));
2992 CString commandline = CPathUtils::GetAppDirectory();
2993 commandline += _T("TortoiseProc.exe /command:commit /pathfile:\"");
2994 commandline += tempFile.GetWinPathString();
2995 commandline += _T("\"");
2996 commandline += _T(" /deletepathfile");
2997 CAppUtils::LaunchApplication(commandline, NULL, false);
2999 break;
3001 case IDSVNLC_COMPAREWC:
3003 POSITION pos = GetFirstSelectedItemPosition();
3004 while ( pos )
3006 int index = GetNextSelectedItem(pos);
3007 FileEntry * entry = GetListEntry(index);
3008 ASSERT(entry != NULL);
3009 if (entry == NULL)
3010 continue;
3011 SVNDiff diff(NULL, m_hWnd, true);
3012 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
3013 git_revnum_t baseRev = entry->Revision;
3014 diff.DiffFileAgainstBase(
3015 entry->path, baseRev, entry->textstatus, entry->propstatus);
3018 break;
3019 case IDSVNLC_GNUDIFF1:
3021 SVNDiff diff(NULL, this->m_hWnd, true);
3023 if (entry->remotestatus <= git_wc_status_normal)
3024 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
3025 else
3026 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
3028 break;
3029 case IDSVNLC_UPDATE:
3031 CTSVNPathList targetList;
3032 FillListOfSelectedItemPaths(targetList);
3033 bool bAllExist = true;
3034 for (int i=0; i<targetList.GetCount(); ++i)
3036 if (!targetList[i].Exists())
3038 bAllExist = false;
3039 break;
3042 if (bAllExist)
3044 CSVNProgressDlg dlg;
3045 dlg.SetCommand(CSVNProgressDlg::SVNProgress_Update);
3046 dlg.SetPathList(targetList);
3047 dlg.SetRevision(SVNRev::REV_HEAD);
3048 dlg.DoModal();
3050 else
3052 CString sTempFile = CTempFiles::Instance().GetTempFilePath(false).GetWinPathString();
3053 targetList.WriteToFile(sTempFile, false);
3054 CString sCmd;
3055 sCmd.Format(_T("\"%s\" /command:update /rev /pathfile:\"%s\" /deletepathfile"),
3056 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)sTempFile);
3058 CAppUtils::LaunchApplication(sCmd, NULL, false);
3061 break;
3063 case IDSVNLC_REMOVE:
3065 SVN git;
3066 CTSVNPathList itemsToRemove;
3067 FillListOfSelectedItemPaths(itemsToRemove);
3069 // We must sort items before removing, so that files are always removed
3070 // *before* their parents
3071 itemsToRemove.SortByPathname(true);
3073 bool bSuccess = false;
3074 if (git.Remove(itemsToRemove, FALSE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3076 bSuccess = true;
3078 else
3080 if ((git.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE) ||
3081 (git.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))
3083 CString msg, yes, no, yestoall;
3084 msg.Format(IDS_PROC_REMOVEFORCE, (LPCTSTR)git.GetLastErrorMessage());
3085 yes.LoadString(IDS_MSGBOX_YES);
3086 no.LoadString(IDS_MSGBOX_NO);
3087 yestoall.LoadString(IDS_PROC_YESTOALL);
3088 UINT ret = CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_ERROR, yes, no, yestoall);
3089 if ((ret == 1)||(ret==3))
3091 if (!git.Remove(itemsToRemove, TRUE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3093 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3095 else
3096 bSuccess = true;
3099 else
3100 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3102 if (bSuccess)
3104 // The remove went ok, but we now need to run through the selected items again
3105 // and update their status
3106 POSITION pos = GetFirstSelectedItemPosition();
3107 int index;
3108 std::vector<int> entriesToRemove;
3109 while ((index = GetNextSelectedItem(pos)) >= 0)
3111 FileEntry * e = GetListEntry(index);
3112 if (!bShift &&
3113 ((e->textstatus == git_wc_status_unversioned)||
3114 (e->textstatus == git_wc_status_none)||
3115 (e->textstatus == git_wc_status_ignored)))
3117 if (GetCheck(index))
3118 m_nSelected--;
3119 m_nTotal--;
3120 entriesToRemove.push_back(index);
3122 else
3124 e->textstatus = git_wc_status_deleted;
3125 e->status = git_wc_status_deleted;
3126 SetEntryCheck(e,index,true);
3129 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3131 RemoveListEntry(*it);
3134 SaveColumnWidths();
3135 Show(m_dwShow, 0, m_bShowFolders);
3136 NotifyCheck();
3138 break;
3139 case IDSVNLC_DELETE:
3141 CTSVNPathList pathlist;
3142 FillListOfSelectedItemPaths(pathlist);
3143 pathlist.RemoveChildren();
3144 CString filelist;
3145 for (INT_PTR i=0; i<pathlist.GetCount(); ++i)
3147 filelist += pathlist[i].GetWinPathString();
3148 filelist += _T("|");
3150 filelist += _T("|");
3151 int len = filelist.GetLength();
3152 TCHAR * buf = new TCHAR[len+2];
3153 _tcscpy_s(buf, len+2, filelist);
3154 for (int i=0; i<len; ++i)
3155 if (buf[i] == '|')
3156 buf[i] = 0;
3157 SHFILEOPSTRUCT fileop;
3158 fileop.hwnd = this->m_hWnd;
3159 fileop.wFunc = FO_DELETE;
3160 fileop.pFrom = buf;
3161 fileop.pTo = NULL;
3162 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
3163 fileop.lpszProgressTitle = _T("deleting file");
3164 int result = SHFileOperation(&fileop);
3165 delete [] buf;
3167 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
3169 SetRedraw(FALSE);
3170 POSITION pos = NULL;
3171 CTSVNPathList deletedlist; // to store list of deleted folders
3172 while ((pos = GetFirstSelectedItemPosition()) != 0)
3174 int index = GetNextSelectedItem(pos);
3175 if (GetCheck(index))
3176 m_nSelected--;
3177 m_nTotal--;
3178 FileEntry * fentry = GetListEntry(index);
3179 if ((fentry)&&(fentry->isfolder))
3180 deletedlist.AddPath(fentry->path);
3181 RemoveListEntry(index);
3183 // now go through the list of deleted folders
3184 // and remove all their children from the list too!
3185 int nListboxEntries = GetItemCount();
3186 for (int folderindex = 0; folderindex < deletedlist.GetCount(); ++folderindex)
3188 CTSVNPath folderpath = deletedlist[folderindex];
3189 for (int i=0; i<nListboxEntries; ++i)
3191 FileEntry * entry = GetListEntry(i);
3192 if (folderpath.IsAncestorOf(entry->path))
3194 RemoveListEntry(i--);
3195 nListboxEntries--;
3199 SetRedraw(TRUE);
3202 break;
3205 case IDSVNLC_ADD:
3207 SVN git;
3208 CTSVNPathList itemsToAdd;
3209 FillListOfSelectedItemPaths(itemsToAdd);
3211 // We must sort items before adding, so that folders are always added
3212 // *before* any of their children
3213 itemsToAdd.SortByPathname();
3215 ProjectProperties props;
3216 props.ReadPropsPathList(itemsToAdd);
3217 if (git.Add(itemsToAdd, &props, git_depth_empty, TRUE, TRUE, TRUE))
3219 // The add went ok, but we now need to run through the selected items again
3220 // and update their status
3221 POSITION pos = GetFirstSelectedItemPosition();
3222 int index;
3223 while ((index = GetNextSelectedItem(pos)) >= 0)
3225 FileEntry * e = GetListEntry(index);
3226 e->textstatus = git_wc_status_added;
3227 e->propstatus = git_wc_status_none;
3228 e->status = git_wc_status_added;
3229 SetEntryCheck(e,index,true);
3232 else
3234 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3236 SaveColumnWidths();
3237 Show(m_dwShow, 0, m_bShowFolders);
3238 NotifyCheck();
3240 break;
3241 case IDSVNLC_ADD_RECURSIVE:
3243 CTSVNPathList itemsToAdd;
3244 FillListOfSelectedItemPaths(itemsToAdd);
3246 CAddDlg dlg;
3247 dlg.m_pathList = itemsToAdd;
3248 if (dlg.DoModal() == IDOK)
3250 if (dlg.m_pathList.GetCount() == 0)
3251 break;
3252 CSVNProgressDlg progDlg;
3253 progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Add);
3254 progDlg.SetPathList(dlg.m_pathList);
3255 ProjectProperties props;
3256 props.ReadPropsPathList(dlg.m_pathList);
3257 progDlg.SetProjectProperties(props);
3258 progDlg.SetItemCount(dlg.m_pathList.GetCount());
3259 progDlg.DoModal();
3261 // refresh!
3262 CWnd* pParent = GetParent();
3263 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3265 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3269 break;
3271 case IDSVNLC_REPAIRMOVE:
3273 POSITION pos = GetFirstSelectedItemPosition();
3274 int index = GetNextSelectedItem(pos);
3275 FileEntry * entry1 = NULL;
3276 FileEntry * entry2 = NULL;
3277 if (index >= 0)
3279 entry1 = GetListEntry(index);
3280 git_wc_status_kind status1 = git_wc_status_none;
3281 git_wc_status_kind status2 = git_wc_status_none;
3282 if (entry1)
3284 status1 = entry1->status;
3285 index = GetNextSelectedItem(pos);
3286 if (index >= 0)
3288 entry2 = GetListEntry(index);
3289 if (entry2)
3291 status2 = entry2->status;
3292 if (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned)
3294 FileEntry * tempentry = entry1;
3295 entry1 = entry2;
3296 entry2 = tempentry;
3298 // entry1 was renamed to entry2 but outside of Subversion
3299 // fix this by moving entry2 back to entry1 first,
3300 // then do an git-move from entry1 to entry2
3301 if (MoveFile(entry2->GetPath().GetWinPath(), entry1->GetPath().GetWinPath()))
3303 SVN git;
3304 if (!git.Move(CTSVNPathList(entry1->GetPath()), entry2->GetPath(), TRUE))
3306 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3308 else
3310 // check the previously unversioned item
3311 entry1->checked = true;
3312 // fixing the move was successful. We have to adjust the new status of the
3313 // files.
3314 // Since we don't know if the moved/renamed file had local modifications or not,
3315 // we can't guess the new status. That means we have to refresh...
3316 CWnd* pParent = GetParent();
3317 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3319 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3323 else
3325 LPVOID lpMsgBuf;
3326 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
3327 FORMAT_MESSAGE_FROM_SYSTEM |
3328 FORMAT_MESSAGE_IGNORE_INSERTS,
3329 NULL,
3330 GetLastError(),
3331 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
3332 (LPTSTR) &lpMsgBuf,
3334 NULL
3336 MessageBox((LPCTSTR)lpMsgBuf, _T("Error"), MB_OK | MB_ICONINFORMATION );
3337 LocalFree( lpMsgBuf );
3344 break;
3345 case IDSVNLC_REMOVEFROMCS:
3347 CTSVNPathList changelistItems;
3348 FillListOfSelectedItemPaths(changelistItems);
3349 SVN git;
3350 SetRedraw(FALSE);
3351 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
3353 // The changelists were removed, but we now need to run through the selected items again
3354 // and update their changelist
3355 POSITION pos = GetFirstSelectedItemPosition();
3356 int index;
3357 std::vector<int> entriesToRemove;
3358 while ((index = GetNextSelectedItem(pos)) >= 0)
3360 FileEntry * e = GetListEntry(index);
3361 if (e)
3363 e->changelist.Empty();
3364 if (e->status == git_wc_status_normal)
3366 // remove the entry completely
3367 entriesToRemove.push_back(index);
3369 else
3370 SetItemGroup(index, 0);
3373 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3375 RemoveListEntry(*it);
3377 // TODO: Should we go through all entries here and check if we also could
3378 // remove the changelist from m_changelists ?
3380 else
3382 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3384 SetRedraw(TRUE);
3386 break;
3387 case IDSVNLC_CREATEIGNORECS:
3388 CreateChangeList(SVNSLC_IGNORECHANGELIST);
3389 break;
3390 case IDSVNLC_CREATECS:
3392 CCreateChangelistDlg dlg;
3393 if (dlg.DoModal() == IDOK)
3395 CreateChangeList(dlg.m_sName);
3398 break;
3399 default:
3401 if (cmd < IDSVNLC_MOVETOCS)
3402 break;
3403 CTSVNPathList changelistItems;
3404 FillListOfSelectedItemPaths(changelistItems);
3406 // find the changelist name
3407 CString sChangelist;
3408 int cmdID = IDSVNLC_MOVETOCS;
3409 SetRedraw(FALSE);
3410 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
3412 if ((it->first.Compare(SVNSLC_IGNORECHANGELIST))&&(entry->changelist.Compare(it->first)))
3414 if (cmd == cmdID)
3416 sChangelist = it->first;
3418 cmdID++;
3421 if (!sChangelist.IsEmpty())
3423 SVN git;
3424 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
3426 // The changelists were moved, but we now need to run through the selected items again
3427 // and update their changelist
3428 POSITION pos = GetFirstSelectedItemPosition();
3429 int index;
3430 while ((index = GetNextSelectedItem(pos)) >= 0)
3432 FileEntry * e = GetListEntry(index);
3433 e->changelist = sChangelist;
3434 if (!e->IsFolder())
3436 if (m_changelists.find(e->changelist)!=m_changelists.end())
3437 SetItemGroup(index, m_changelists[e->changelist]);
3438 else
3439 SetItemGroup(index, 0);
3443 else
3445 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3448 SetRedraw(TRUE);
3450 break;
3451 #endif
3453 } // switch (cmd)
3454 m_bBlock = FALSE;
3455 AfxGetApp()->DoWaitCursor(-1);
3456 GetStatisticsString();
3457 //int iItemCountAfterMenuCmd = GetItemCount();
3458 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
3460 // CWnd* pParent = GetParent();
3461 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3462 // {
3463 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
3464 // }
3466 } // if (popup.CreatePopupMenu())
3467 } // if (selIndex >= 0)
3471 void CGitStatusListCtrl::OnContextMenuHeader(CWnd * pWnd, CPoint point)
3473 Locker lock(m_critSec);
3474 m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
3477 void CGitStatusListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
3480 if (pWnd == this)
3482 OnContextMenuList(pWnd, point);
3483 } // if (pWnd == this)
3484 else if (pWnd == GetHeaderCtrl())
3486 OnContextMenuHeader(pWnd, point);
3490 void CGitStatusListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
3493 Locker lock(m_critSec);
3494 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
3495 *pResult = 0;
3496 if (m_bBlock)
3497 return;
3499 if (pNMLV->iItem < 0)
3501 if (!IsGroupViewEnabled())
3502 return;
3503 POINT pt;
3504 DWORD ptW = GetMessagePos();
3505 pt.x = GET_X_LPARAM(ptW);
3506 pt.y = GET_Y_LPARAM(ptW);
3507 ScreenToClient(&pt);
3508 int group = GetGroupFromPoint(&pt);
3509 if (group < 0)
3510 return;
3511 // check/uncheck the whole group depending on the check-state
3512 // of the first item in the group
3513 m_bBlock = true;
3514 bool bCheck = false;
3515 bool bFirst = false;
3516 LVITEM lv;
3517 for (int i=0; i<GetItemCount(); ++i)
3519 SecureZeroMemory(&lv, sizeof(LVITEM));
3520 lv.mask = LVIF_GROUPID;
3521 lv.iItem = i;
3522 GetItem(&lv);
3523 if (lv.iGroupId == group)
3525 CTGitPath *entry=(CTGitPath*)GetItemData(i);
3527 if (!bFirst)
3529 bCheck = !GetCheck(i);
3530 bFirst = true;
3532 if (entry)
3534 bool bOldCheck = !!GetCheck(i);
3535 SetEntryCheck(entry, i, bCheck);
3536 if (bCheck != bOldCheck)
3538 if (bCheck)
3539 m_nSelected++;
3540 else
3541 m_nSelected--;
3546 GetStatisticsString();
3547 m_bBlock = false;
3548 NotifyCheck();
3549 return;
3552 CTGitPath *file=(CTGitPath*)GetItemData(pNMLV->iItem);
3554 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER) {
3555 OpenFile(file, OPEN);
3556 return;
3558 if( file->m_Action&CTGitPath::LOGACTIONS_UNMERGED )
3560 CAppUtils::ConflictEdit(*file,false,m_bIsRevertTheirMy);
3563 else
3565 if( (!m_Rev1.IsEmpty()) || (!m_Rev1.IsEmpty())) // m_Rev1 twice???
3566 StartDiffTwo(pNMLV->iItem);
3567 else
3568 StartDiff(pNMLV->iItem);
3572 void CGitStatusListCtrl::StartDiffTwo(int fileindex)
3574 if(fileindex<0)
3575 return;
3577 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3579 CGitDiff::Diff(&file1,&file1,
3580 m_Rev1,
3581 m_Rev2);
3584 void CGitStatusListCtrl::StartDiffWC(int fileindex)
3586 if(fileindex<0)
3587 return;
3589 CString Ver;
3590 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
3591 return;
3593 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3595 CGitDiff::Diff(&file1,&file1, GIT_REV_ZERO, m_CurrentVersion);
3599 void CGitStatusListCtrl::StartDiff(int fileindex)
3601 if(fileindex<0)
3602 return;
3604 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3605 CTGitPath file2;
3606 if(file1.m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
3608 file2.SetFromGit(file1.GetGitOldPathString());
3610 else
3612 file2=file1;
3615 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
3617 CString fromwhere;
3618 if(m_amend && (file1.m_Action & CTGitPath::LOGACTIONS_ADDED) == 0)
3619 fromwhere = _T("~1");
3620 if( g_Git.IsInitRepos())
3621 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
3622 GIT_REV_ZERO);
3623 else if( file1.m_Action&CTGitPath::LOGACTIONS_ADDED )
3624 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
3625 m_CurrentVersion+fromwhere,true);
3626 else if( file1.m_Action&CTGitPath::LOGACTIONS_DELETED )
3627 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
3628 GitRev::GetHead()+fromwhere,false);
3629 else
3630 CGitDiff::Diff(&file1,&file2,
3631 CString(GIT_REV_ZERO),
3632 GitRev::GetHead()+fromwhere);
3634 else
3636 GitRev rev;
3637 CString fromwhere = m_CurrentVersion+_T("~1");
3638 if(m_amend)
3639 fromwhere = m_CurrentVersion+_T("~2");
3640 if(rev.GetCommit(fromwhere) || (file1.m_Action == file1.LOGACTIONS_ADDED))
3642 CGitDiff::DiffNull(&file1,m_CurrentVersion,true);
3645 else if (file1.m_Action == file1.LOGACTIONS_DELETED)
3647 if (file1.m_ParentNo > 0)
3648 fromwhere.Format(_T("%s^%d"), m_CurrentVersion, file1.m_ParentNo + 1);
3650 CGitDiff::DiffNull(&file1,fromwhere,false);
3652 else
3654 if( file1.m_ParentNo & MERGE_MASK)
3657 CTGitPath base, theirs, mine, merge;
3659 CString temppath;
3660 GetTempPath(temppath);
3661 temppath.TrimRight(_T("\\"));
3663 mine.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".LOCAL") + file1.GetFileExtension());
3664 theirs.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".REMOTE") + file1.GetFileExtension());
3665 base.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".BASE") + file1.GetFileExtension());
3667 CFile tempfile;
3668 //create a empty file, incase stage is not three
3669 tempfile.Open(mine.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
3670 tempfile.Close();
3671 tempfile.Open(theirs.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
3672 tempfile.Close();
3673 tempfile.Open(base.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
3674 tempfile.Close();
3676 merge.SetFromGit(temppath + _T("\\") + file1.GetFileOrDirectoryName() + _T(".Merged") + file1.GetFileExtension());
3678 int parent1=-1, parent2 =-1;
3679 for(int i=0;i<this->m_arStatusArray.size();i++)
3681 if(m_arStatusArray[i]->GetGitPathString() == file1.GetGitPathString())
3683 if(m_arStatusArray[i]->m_ParentNo & MERGE_MASK)
3686 else
3688 if(parent1<0)
3690 parent1 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
3692 else if (parent2 <0)
3694 parent2 = m_arStatusArray[i]->m_ParentNo & PARENT_MASK;
3700 if(g_Git.GetOneFile(m_CurrentVersion, file1, (CString&)merge.GetWinPathString()))
3702 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
3705 if(parent1>=0)
3707 CString str;
3708 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent1+1);
3710 if(g_Git.GetOneFile(str, file1, (CString&)mine.GetWinPathString()))
3712 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
3716 if(parent2>=0)
3718 CString str;
3719 str.Format(_T("%s^%d"),this->m_CurrentVersion, parent2+1);
3721 if(g_Git.GetOneFile(str, file1, (CString&)theirs.GetWinPathString()))
3723 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETMERGEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
3727 if(parent1>=0 && parent2>=0)
3729 CString cmd, output;
3730 cmd.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion, parent1+1,
3731 this->m_CurrentVersion,parent2+1);
3733 if (g_Git.Run(cmd, &output, NULL, CP_UTF8))
3736 else
3738 if(g_Git.GetOneFile(output.Left(40), file1, (CString&)base.GetWinPathString()))
3740 CMessageBox::Show(NULL, IDS_STATUSLIST_FAILEDGETBASEFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
3744 CAppUtils::StartExtMerge(base, theirs, mine, merge,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
3747 else
3749 CString str;
3750 if( (file1.m_ParentNo&PARENT_MASK) == 0)
3752 str = _T("~1");
3754 else
3756 str.Format(_T("^%d"), (file1.m_ParentNo&PARENT_MASK)+1);
3758 CGitDiff::Diff(&file1,&file2,
3759 m_CurrentVersion,
3760 m_CurrentVersion+str);
3764 #if 0
3765 if (fileindex < 0)
3766 return;
3767 FileEntry * entry = GetListEntry(fileindex);
3768 ASSERT(entry != NULL);
3769 if (entry == NULL)
3770 return;
3771 if (((entry->status == git_wc_status_normal)&&(entry->remotestatus <= git_wc_status_normal))||
3772 (entry->status == git_wc_status_unversioned)||(entry->status == git_wc_status_none))
3774 int ret = (int)ShellExecute(this->m_hWnd, NULL, entry->path.GetWinPath(), NULL, NULL, SW_SHOW);
3775 if (ret <= HINSTANCE_ERROR)
3777 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
3778 cmd += entry->path.GetWinPathString();
3779 CAppUtils::LaunchApplication(cmd, NULL, false);
3781 return;
3784 GitDiff diff(NULL, m_hWnd, true);
3785 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
3786 diff.DiffWCFile(
3787 entry->path, entry->textstatus, entry->propstatus,
3788 entry->remotetextstatus, entry->remotepropstatus);
3789 #endif
3792 CString CGitStatusListCtrl::GetStatisticsString(bool simple)
3795 CString sNormal, sAdded, sDeleted, sModified, sConflicted, sUnversioned, sRenamed;
3796 WORD langID = (WORD)(DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3797 TCHAR buf[MAX_STATUS_STRING_LENGTH];
3798 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal, buf, _countof(buf), langID);
3799 sNormal = buf;
3800 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added, buf, _countof(buf), langID);
3801 sAdded = buf;
3802 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted, buf, _countof(buf), langID);
3803 sDeleted = buf;
3804 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified, buf, _countof(buf), langID);
3805 sModified = buf;
3806 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted, buf, _countof(buf), langID);
3807 sConflicted = buf;
3808 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned, buf, _countof(buf), langID);
3809 sUnversioned = buf;
3810 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced, buf, _countof(buf), langID);
3811 sRenamed = buf;
3812 CString sToolTip;
3813 if(simple)
3815 sToolTip.Format(IDS_STATUSLIST_STATUSLINE1,
3816 this->m_nLineAdded,this->m_nLineDeleted,
3817 (LPCTSTR)sModified, m_nModified,
3818 (LPCTSTR)sAdded, m_nAdded,
3819 (LPCTSTR)sDeleted, m_nDeleted,
3820 (LPCTSTR)sRenamed, m_nRenamed
3823 else
3825 sToolTip.Format(IDS_STATUSLIST_STATUSLINE2,
3826 this->m_nLineAdded,this->m_nLineDeleted,
3827 (LPCTSTR)sNormal, m_nNormal,
3828 (LPCTSTR)sUnversioned, m_nUnversioned,
3829 (LPCTSTR)sModified, m_nModified,
3830 (LPCTSTR)sAdded, m_nAdded,
3831 (LPCTSTR)sDeleted, m_nDeleted,
3832 (LPCTSTR)sConflicted, m_nConflicted
3835 CString sStats;
3836 sStats.Format(IDS_COMMITDLG_STATISTICSFORMAT, m_nSelected, GetItemCount());
3837 if (m_pStatLabel)
3839 m_pStatLabel->SetWindowText(sStats);
3842 if (m_pSelectButton)
3844 if (m_nSelected == 0)
3845 m_pSelectButton->SetCheck(BST_UNCHECKED);
3846 else if (m_nSelected != GetItemCount())
3847 m_pSelectButton->SetCheck(BST_INDETERMINATE);
3848 else
3849 m_pSelectButton->SetCheck(BST_CHECKED);
3852 if (m_pConfirmButton)
3854 m_pConfirmButton->EnableWindow(m_nSelected>0);
3857 return sToolTip;
3862 CString CGitStatusListCtrl::GetCommonDirectory(bool bStrict)
3864 if (!bStrict)
3866 // not strict means that the selected folder has priority
3867 if (!m_StatusFileList.GetCommonDirectory().IsEmpty())
3868 return m_StatusFileList.GetCommonDirectory().GetWinPath();
3871 CTGitPath commonBaseDirectory;
3872 int nListItems = GetItemCount();
3873 for (int i=0; i<nListItems; ++i)
3875 CTGitPath baseDirectory,*p= (CTGitPath*)this->GetItemData(i);
3876 ASSERT(p);
3877 if(p==NULL)
3878 continue;
3879 baseDirectory = p->GetDirectory();
3881 if(commonBaseDirectory.IsEmpty())
3883 commonBaseDirectory = baseDirectory;
3885 else
3887 if (commonBaseDirectory.GetWinPathString().GetLength() > baseDirectory.GetWinPathString().GetLength())
3889 if (baseDirectory.IsAncestorOf(commonBaseDirectory))
3890 commonBaseDirectory = baseDirectory;
3894 return g_Git.m_CurrentDir+CString(_T("\\"))+commonBaseDirectory.GetWinPath();
3898 void CGitStatusListCtrl::SelectAll(bool bSelect, bool /*bIncludeNoCommits*/)
3900 CWaitCursor waitCursor;
3901 // block here so the LVN_ITEMCHANGED messages
3902 // get ignored
3903 m_bBlock = TRUE;
3904 SetRedraw(FALSE);
3906 int nListItems = GetItemCount();
3907 if (bSelect)
3908 m_nSelected = nListItems;
3909 else
3910 m_nSelected = 0;
3912 for (int i=0; i<nListItems; ++i)
3914 //FileEntry * entry = GetListEntry(i);
3915 //ASSERT(entry != NULL);
3916 CTGitPath *path = (CTGitPath *) GetItemData(i);
3917 if (path == NULL)
3918 continue;
3919 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
3920 SetEntryCheck(path,i,bSelect);
3923 // unblock before redrawing
3924 m_bBlock = FALSE;
3925 SetRedraw(TRUE);
3926 GetStatisticsString();
3927 NotifyCheck();
3930 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)
3932 LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);
3933 *pResult = 0;
3934 if (m_bBlock)
3935 return;
3937 CTGitPath *entry=(CTGitPath *)GetItemData(pGetInfoTip->iItem);
3939 if (entry)
3940 if (pGetInfoTip->cchTextMax > entry->GetGitPathString().GetLength() + g_Git.m_CurrentDir.GetLength())
3942 CString str;
3943 str += g_Git.m_CurrentDir;
3944 str += _T("\\");
3945 str += entry->GetWinPathString();
3947 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, str.GetBuffer(), str.GetLength());
3951 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
3953 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
3955 // Take the default processing unless we set this to something else below.
3956 *pResult = CDRF_DODEFAULT;
3958 // First thing - check the draw stage. If it's the control's prepaint
3959 // stage, then tell Windows we want messages for every item.
3961 switch (pLVCD->nmcd.dwDrawStage)
3963 case CDDS_PREPAINT:
3964 *pResult = CDRF_NOTIFYITEMDRAW;
3965 break;
3966 case CDDS_ITEMPREPAINT:
3968 // This is the prepaint stage for an item. Here's where we set the
3969 // item's text color. Our return value will tell Windows to draw the
3970 // item itself, but it will use the new color we set here.
3972 // Tell Windows to paint the control itself.
3973 *pResult = CDRF_DODEFAULT;
3974 if (m_bBlock)
3975 return;
3977 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
3979 if (m_arStatusArray.size() > (DWORD_PTR)pLVCD->nmcd.dwItemSpec)
3982 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3983 CTGitPath *entry=(CTGitPath *)GetItemData((int)pLVCD->nmcd.dwItemSpec);
3984 if (entry == NULL)
3985 return;
3987 // coloring
3988 // ========
3989 // black : unversioned, normal
3990 // purple : added
3991 // blue : modified
3992 // brown : missing, deleted, replaced
3993 // green : merged (or potential merges)
3994 // red : conflicts or sure conflicts
3995 if(entry->m_Action & CTGitPath::LOGACTIONS_GRAY)
3997 crText = RGB(128,128,128);
4000 else if(entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
4002 crText = m_Colors.GetColor(CColors::Conflict);
4005 else if(entry->m_Action & (CTGitPath::LOGACTIONS_MODIFIED))
4007 crText = m_Colors.GetColor(CColors::Modified);
4010 else if(entry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
4012 crText = m_Colors.GetColor(CColors::Added);
4014 else if(entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
4016 crText = m_Colors.GetColor(CColors::DeletedNode);
4018 else if(entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
4020 crText = m_Colors.GetColor(CColors::RenamedNode);
4022 else if(entry->m_Action & CTGitPath::LOGACTIONS_MERGED)
4024 crText = m_Colors.GetColor(CColors::Merged);
4026 else
4028 crText = GetSysColor(COLOR_WINDOWTEXT);
4030 // Store the color back in the NMLVCUSTOMDRAW struct.
4031 pLVCD->clrText = crText;
4034 break;
4038 BOOL CGitStatusListCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
4040 if (pWnd != this)
4041 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
4042 if (!m_bBlock)
4044 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
4045 SetCursor(hCur);
4046 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
4048 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
4049 SetCursor(hCur);
4050 return TRUE;
4053 void CGitStatusListCtrl::RemoveListEntry(int index)
4056 Locker lock(m_critSec);
4057 DeleteItem(index);
4059 m_arStatusArray.erase(m_arStatusArray.begin()+index);
4061 #if 0
4062 delete m_arStatusArray[m_arListArray[index]];
4063 m_arStatusArray.erase(m_arStatusArray.begin()+m_arListArray[index]);
4064 m_arListArray.erase(m_arListArray.begin()+index);
4065 for (int i=index; i< (int)m_arListArray.size(); ++i)
4067 m_arListArray[i]--;
4069 #endif
4072 ///< Set a checkbox on an entry in the listbox
4073 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
4074 void CGitStatusListCtrl::SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck)
4076 pEntry->m_Checked = bCheck;
4077 SetCheck(listboxIndex, bCheck);
4080 #if 0
4081 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck)
4084 int nListItems = GetItemCount();
4085 for (int j=0; j< nListItems ; ++j)
4087 FileEntry * childEntry = GetListEntry(j);
4088 ASSERT(childEntry != NULL);
4089 if (childEntry == NULL || childEntry == parentEntry)
4090 continue;
4091 if (childEntry->checked != bCheck)
4093 if (parentEntry->path.IsAncestorOf(childEntry->path))
4095 SetEntryCheck(childEntry,j,bCheck);
4096 if(bCheck)
4098 m_nSelected++;
4100 else
4102 m_nSelected--;
4109 #endif
4111 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList& pathList)
4114 pathList.Clear();
4115 int nListItems = GetItemCount();
4116 for (int i=0; i< nListItems; i++)
4118 CTGitPath * entry = (CTGitPath*)GetItemData(i);
4119 ASSERT(entry != NULL);
4120 if (entry->m_Checked)
4122 pathList.AddPath(*entry);
4125 pathList.SortByPathname();
4130 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
4131 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList& pathList, bool /*bNoIgnored*/)
4133 pathList.Clear();
4135 POSITION pos = GetFirstSelectedItemPosition();
4136 int index;
4137 while ((index = GetNextSelectedItem(pos)) >= 0)
4139 CTGitPath * entry = (CTGitPath*)GetItemData(index);
4140 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
4141 // continue;
4142 pathList.AddPath(*entry);
4146 UINT CGitStatusListCtrl::OnGetDlgCode()
4148 // we want to process the return key and not have that one
4149 // routed to the default pushbutton
4150 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS;
4153 void CGitStatusListCtrl::OnNMReturn(NMHDR * /*pNMHDR*/, LRESULT *pResult)
4155 *pResult = 0;
4156 if (m_bBlock)
4157 return;
4158 POSITION pos = GetFirstSelectedItemPosition();
4159 while ( pos )
4161 int index = GetNextSelectedItem(pos);
4162 CTGitPath *file=(CTGitPath*)GetItemData(index);
4163 if (file->m_Action == CTGitPath::LOGACTIONS_UNVER)
4165 OpenFile(file, OPEN);
4167 else
4169 StartDiff(index);
4174 void CGitStatusListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
4176 // Since we catch all keystrokes (to have the enter key processed here instead
4177 // of routed to the default pushbutton) we have to make sure that other
4178 // keys like Tab and Esc still do what they're supposed to do
4179 // Tab = change focus to next/previous control
4180 // Esc = quit the dialog
4181 switch (nChar)
4183 case (VK_TAB):
4185 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL, GetKeyState(VK_SHIFT)&0x8000, 0);
4186 return;
4188 break;
4189 case (VK_ESCAPE):
4191 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE, 0, 0);
4193 break;
4196 CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
4199 void CGitStatusListCtrl::PreSubclassWindow()
4201 CListCtrl::PreSubclassWindow();
4202 EnableToolTips(TRUE);
4203 SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);
4206 INT_PTR CGitStatusListCtrl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
4208 int row, col;
4209 RECT cellrect;
4210 row = CellRectFromPoint(point, &cellrect, &col );
4212 if (row == -1)
4213 return -1;
4216 pTI->hwnd = m_hWnd;
4217 pTI->uId = (UINT)((row<<10)+(col&0x3ff)+1);
4218 pTI->lpszText = LPSTR_TEXTCALLBACK;
4220 pTI->rect = cellrect;
4222 return pTI->uId;
4225 int CGitStatusListCtrl::CellRectFromPoint(CPoint& point, RECT *cellrect, int *col) const
4227 int colnum;
4229 // Make sure that the ListView is in LVS_REPORT
4230 if ((GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
4231 return -1;
4233 // Get the top and bottom row visible
4234 int row = GetTopIndex();
4235 int bottom = row + GetCountPerPage();
4236 if (bottom > GetItemCount())
4237 bottom = GetItemCount();
4239 // Get the number of columns
4240 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
4241 int nColumnCount = pHeader->GetItemCount();
4243 // Loop through the visible rows
4244 for ( ;row <=bottom;row++)
4246 // Get bounding rect of item and check whether point falls in it.
4247 CRect rect;
4248 GetItemRect(row, &rect, LVIR_BOUNDS);
4249 if (rect.PtInRect(point))
4251 // Now find the column
4252 for (colnum = 0; colnum < nColumnCount; colnum++)
4254 int colwidth = GetColumnWidth(colnum);
4255 if (point.x >= rect.left && point.x <= (rect.left + colwidth))
4257 RECT rectClient;
4258 GetClientRect(&rectClient);
4259 if (col)
4260 *col = colnum;
4261 rect.right = rect.left + colwidth;
4263 // Make sure that the right extent does not exceed
4264 // the client area
4265 if (rect.right > rectClient.right)
4266 rect.right = rectClient.right;
4267 *cellrect = rect;
4268 return row;
4270 rect.left += colwidth;
4274 return -1;
4277 BOOL CGitStatusListCtrl::OnToolTipText(UINT /*id*/, NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
4279 #if 0
4280 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4281 CString strTipText;
4282 UINT_PTR nID = pNMHDR->idFrom;
4284 if (nID == 0)
4285 return FALSE;
4287 UINT_PTR row = ((nID-1) >> 10) & 0x3fffff;
4288 UINT_PTR col = (nID-1) & 0x3ff;
4290 if (col == 0)
4291 return FALSE; // no custom tooltip for the path, we use the infotip there!
4293 // get the internal column from the visible columns
4294 int internalcol = 0;
4295 UINT_PTR currentcol = 0;
4296 for (; (currentcol != col)
4297 && (internalcol < m_ColumnManager.GetColumnCount()-1)
4298 ; ++internalcol)
4300 if (m_ColumnManager.IsVisible (internalcol))
4301 currentcol++;
4304 AFX_MODULE_THREAD_STATE* pModuleThreadState = AfxGetModuleThreadState();
4305 CToolTipCtrl* pToolTip = pModuleThreadState->m_pToolTip;
4306 pToolTip->SendMessage(TTM_SETMAXTIPWIDTH, 0, 300);
4308 *pResult = 0;
4309 if ((internalcol == 2)||(internalcol == 4))
4311 FileEntry *fentry = GetListEntry(row);
4312 if (fentry)
4314 if (fentry->copied)
4316 CString url;
4317 url.Format(IDS_STATUSLIST_COPYFROM, (LPCTSTR)CPathUtils::PathUnescape(fentry->copyfrom_url), (LONG)fentry->copyfrom_rev);
4318 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4319 return TRUE;
4321 if (fentry->switched)
4323 CString url;
4324 url.Format(IDS_STATUSLIST_SWITCHEDTO, (LPCTSTR)CPathUtils::PathUnescape(fentry->url));
4325 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4326 return TRUE;
4328 if (fentry->keeplocal)
4330 lstrcpyn(pTTTW->szText, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_KEEPLOCAL)), 80);
4331 return TRUE;
4335 #endif
4336 return FALSE;
4339 void CGitStatusListCtrl::OnPaint()
4341 Default();
4342 if ((m_bBusy)||(m_bEmpty))
4344 CString str;
4345 if (m_bBusy)
4347 if (m_sBusy.IsEmpty())
4348 str.LoadString(IDS_STATUSLIST_BUSYMSG);
4349 else
4350 str = m_sBusy;
4352 else
4354 if (m_sEmpty.IsEmpty())
4355 str.LoadString(IDS_STATUSLIST_EMPTYMSG);
4356 else
4357 str = m_sEmpty;
4359 COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
4360 COLORREF clrTextBk;
4361 if (IsWindowEnabled())
4362 clrTextBk = ::GetSysColor(COLOR_WINDOW);
4363 else
4364 clrTextBk = ::GetSysColor(COLOR_3DFACE);
4366 CRect rc;
4367 GetClientRect(&rc);
4368 CHeaderCtrl* pHC;
4369 pHC = GetHeaderCtrl();
4370 if (pHC != NULL)
4372 CRect rcH;
4373 pHC->GetItemRect(0, &rcH);
4374 rc.top += rcH.bottom;
4376 CDC* pDC = GetDC();
4378 CMyMemDC memDC(pDC, &rc);
4380 memDC.SetTextColor(clrText);
4381 memDC.SetBkColor(clrTextBk);
4382 memDC.FillSolidRect(rc, clrTextBk);
4383 rc.top += 10;
4384 CGdiObject * oldfont = memDC.SelectStockObject(DEFAULT_GUI_FONT);
4385 memDC.DrawText(str, rc, DT_CENTER | DT_VCENTER |
4386 DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
4387 memDC.SelectObject(oldfont);
4389 ReleaseDC(pDC);
4393 // prevent users from extending our hidden (size 0) columns
4394 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
4396 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
4399 // prevent any function from extending our hidden (size 0) columns
4400 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
4402 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
4403 Default();
4406 void CGitStatusListCtrl::OnDestroy()
4408 SaveColumnWidths(true);
4409 CListCtrl::OnDestroy();
4412 void CGitStatusListCtrl::OnBeginDrag(NMHDR* /*pNMHDR*/, LRESULT* pResult)
4414 #if 0
4415 Locker lock(m_critSec);
4416 CDropFiles dropFiles; // class for creating DROPFILES struct
4418 int index;
4419 POSITION pos = GetFirstSelectedItemPosition();
4420 while ( (index = GetNextSelectedItem(pos)) >= 0 )
4422 FileEntry * fentry = m_arStatusArray[m_arListArray[index]];
4423 CTGitPath path = fentry->GetPath();
4424 dropFiles.AddFile( path.GetWinPathString() );
4427 if ( dropFiles.GetCount()>0 )
4429 m_bOwnDrag = true;
4430 dropFiles.CreateStructure();
4431 m_bOwnDrag = false;
4433 #endif
4434 *pResult = 0;
4437 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry /* = false */)
4439 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
4440 for (int col = 0; col <= maxcol; col++)
4441 if (m_ColumnManager.IsVisible (col))
4442 m_ColumnManager.ColumnResized (col);
4444 if (bSaveToRegistry)
4445 m_ColumnManager.WriteSettings();
4448 bool CGitStatusListCtrl::EnableFileDrop()
4450 m_bFileDropsEnabled = true;
4451 return true;
4454 bool CGitStatusListCtrl::HasPath(const CTGitPath& path)
4456 for (size_t i=0; i < m_arStatusArray.size(); i++)
4458 if (m_arStatusArray[i]->IsEquivalentTo(path))
4459 return true;
4462 return false;
4465 BOOL CGitStatusListCtrl::PreTranslateMessage(MSG* pMsg)
4467 if (pMsg->message == WM_KEYDOWN)
4469 switch (pMsg->wParam)
4471 case 'A':
4473 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4475 // select all entries
4476 for (int i=0; i<GetItemCount(); ++i)
4478 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
4480 return TRUE;
4483 break;
4484 case 'C':
4485 case VK_INSERT:
4487 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4489 // copy all selected paths to the clipboard
4490 if (GetAsyncKeyState(VK_SHIFT)&0x8000)
4491 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS);
4492 else
4493 CopySelectedEntriesToClipboard(0);
4494 return TRUE;
4497 break;
4501 return CListCtrl::PreTranslateMessage(pMsg);
4504 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols)
4507 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
4508 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4510 CString sClipboard;
4511 CString temp;
4512 //TCHAR buf[100];
4513 if (GetSelectedCount() == 0)
4514 return false;
4516 // first add the column titles as the first line
4517 // We needn't head when only path copy
4518 //temp.LoadString(IDS_STATUSLIST_COLFILE);
4519 //sClipboard = temp;
4521 DWORD selection = 0;
4522 for (int i = 0, count = m_ColumnManager.GetColumnCount(); i < count; ++i)
4523 if ( ((dwCols == -1) && m_ColumnManager.IsVisible (i))
4524 || ((dwCols != 1) && (i < 32) && ((dwCols & (1 << i)) != 0)))
4526 sClipboard += _T("\t") + m_ColumnManager.GetName(i);
4528 if (i < 32)
4529 selection += 1 << i;
4532 if(dwCols)
4533 sClipboard += _T("\r\n");
4535 POSITION pos = GetFirstSelectedItemPosition();
4536 int index;
4537 while ((index = GetNextSelectedItem(pos)) >= 0)
4539 CTGitPath * entry = (CTGitPath*)GetItemData(index);
4540 if(entry == NULL)
4541 continue;
4543 sClipboard += entry->GetWinPathString();
4544 if (selection & GITSLC_COLFILENAME)
4546 sClipboard += _T("\t")+entry->GetFileOrDirectoryName();
4548 if (selection & GITSLC_COLEXT)
4550 sClipboard += _T("\t")+entry->GetFileExtension();
4553 if (selection & GITSLC_COLSTATUS)
4555 #if 0
4556 if (entry->isNested)
4558 temp.LoadString(IDS_STATUSLIST_NESTED);
4560 else
4562 GitStatus::GetStatusString(hResourceHandle, entry->status, buf, _countof(buf), (WORD)langID);
4563 if ((entry->copied)&&(_tcslen(buf)>1))
4564 _tcscat_s(buf, 100, _T(" (+)"));
4565 if ((entry->switched)&&(_tcslen(buf)>1))
4566 _tcscat_s(buf, 100, _T(" (s)"));
4567 temp = buf;
4569 #endif
4570 sClipboard += _T("\t")+entry->GetActionName();
4572 #if 0
4573 if (selection & SVNSLC_COLTEXTSTATUS)
4576 if (entry->isNested)
4578 temp.LoadString(IDS_STATUSLIST_NESTED);
4580 else
4582 GitStatus::GetStatusString(hResourceHandle, entry->textstatus, buf, _countof(buf), (WORD)langID);
4583 if ((entry->copied)&&(_tcslen(buf)>1))
4584 _tcscat_s(buf, 100, _T(" (+)"));
4585 if ((entry->switched)&&(_tcslen(buf)>1))
4586 _tcscat_s(buf, 100, _T(" (s)"));
4587 temp = buf;
4589 sClipboard += _T("\t")+temp;
4591 #endif
4592 #if 0
4593 if (selection & SVNSLC_COLREMOTESTATUS)
4595 if (entry->isNested)
4597 temp.LoadString(IDS_STATUSLIST_NESTED);
4599 else
4601 GitStatus::GetStatusString(hResourceHandle, entry->remotestatus, buf, _countof(buf), (WORD)langID);
4602 if ((entry->copied)&&(_tcslen(buf)>1))
4603 _tcscat_s(buf, 100, _T(" (+)"));
4604 if ((entry->switched)&&(_tcslen(buf)>1))
4605 _tcscat_s(buf, 100, _T(" (s)"));
4606 temp = buf;
4608 sClipboard += _T("\t")+temp;
4610 if (selection & GitSLC_COLPROPSTATUS)
4612 if (entry->isNested)
4614 temp.Empty();
4616 else
4618 GitStatus::GetStatusString(hResourceHandle, entry->propstatus, buf, _countof(buf), (WORD)langID);
4619 if ((entry->copied)&&(_tcslen(buf)>1))
4620 _tcscat_s(buf, 100, _T(" (+)"));
4621 if ((entry->switched)&&(_tcslen(buf)>1))
4622 _tcscat_s(buf, 100, _T(" (s)"));
4623 temp = buf;
4625 sClipboard += _T("\t")+temp;
4627 if (selection & SVNSLC_COLREMOTETEXT)
4629 if (entry->isNested)
4631 temp.Empty();
4633 else
4635 GitStatus::GetStatusString(hResourceHandle, entry->remotetextstatus, buf, _countof(buf), (WORD)langID);
4636 temp = buf;
4638 sClipboard += _T("\t")+temp;
4640 if (selection & SVNSLC_COLREMOTEPROP)
4642 // SVNSLC_COLREMOTEPROP
4643 if (entry->isNested)
4645 temp.Empty();
4647 else
4649 GitStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, _countof(buf), (WORD)langID);
4650 temp = buf;
4652 sClipboard += _T("\t")+temp;
4654 if (selection & SVNSLC_COLURL)
4655 sClipboard += _T("\t")+entry->url;
4656 if (selection & SVNSLC_COLLOCK)
4658 if (!m_HeadRev.IsHead())
4660 // we have contacted the repository
4662 // decision-matrix
4663 // wc repository text
4664 // "" "" ""
4665 // "" UID1 owner
4666 // UID1 UID1 owner
4667 // UID1 "" lock has been broken
4668 // UID1 UID2 lock has been stolen
4669 if (entry->lock_token.IsEmpty() || (entry->lock_token.Compare(entry->lock_remotetoken)==0))
4671 if (entry->lock_owner.IsEmpty())
4672 temp = entry->lock_remoteowner;
4673 else
4674 temp = entry->lock_owner;
4676 else if (entry->lock_remotetoken.IsEmpty())
4678 // broken lock
4679 temp.LoadString(IDS_STATUSLIST_LOCKBROKEN);
4681 else
4683 // stolen lock
4684 temp.Format(IDS_STATUSLIST_LOCKSTOLEN, (LPCTSTR)entry->lock_remoteowner);
4687 else
4688 temp = entry->lock_owner;
4689 sClipboard += _T("\t")+temp;
4691 if (selection & SVNSLC_COLLOCKCOMMENT)
4692 sClipboard += _T("\t")+entry->lock_comment;
4693 if (selection & SVNSLC_COLAUTHOR)
4694 sClipboard += _T("\t")+entry->last_commit_author;
4695 if (selection & SVNSLC_COLREVISION)
4697 temp.Format(_T("%ld"), entry->last_commit_rev);
4698 if (entry->last_commit_rev == 0)
4699 temp.Empty();
4700 sClipboard += _T("\t")+temp;
4702 if (selection & SVNSLC_COLREMOTEREVISION)
4704 temp.Format(_T("%ld"), entry->remoterev);
4705 if (entry->remoterev == 0)
4706 temp.Empty();
4707 sClipboard += _T("\t")+temp;
4710 if (selection & SVNSLC_COLDATE)
4712 TCHAR datebuf[SVN_DATE_BUFFER];
4713 apr_time_t date = entry->last_commit_date;
4714 SVN::formatDate(datebuf, date, true);
4715 if (date)
4716 temp = datebuf;
4717 else
4718 temp.Empty();
4719 sClipboard += _T("\t")+temp;
4721 if (selection & SVNSLC_COLCOPYFROM)
4723 if (m_sURL.Compare(entry->copyfrom_url.Left(m_sURL.GetLength()))==0)
4724 temp = entry->copyfrom_url.Mid(m_sURL.GetLength());
4725 else
4726 temp = entry->copyfrom_url;
4727 sClipboard += _T("\t")+temp;
4730 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
4731 ; i < count
4732 ; ++i)
4734 if ((dwCols == -1) && m_ColumnManager.IsVisible (i))
4736 CString value
4737 = entry->present_props[m_ColumnManager.GetName(i)];
4738 sClipboard += _T("\t") + value;
4741 #endif
4742 if (selection & GITSLC_COLADD)
4744 sClipboard += _T("\t")+entry->m_StatAdd;
4746 if (selection & GITSLC_COLDEL)
4748 sClipboard += _T("\t")+entry->m_StatDel;
4751 sClipboard += _T("\r\n");
4754 return CStringUtils::WriteAsciiStringToClipboard(sClipboard);
4756 return TRUE;
4760 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
4762 #if 0
4763 std::set<CString> changelists;
4764 POSITION pos = GetFirstSelectedItemPosition();
4765 int index;
4766 while ((index = GetNextSelectedItem(pos)) >= 0)
4768 FileEntry * entry = GetListEntry(index);
4769 if (!entry->changelist.IsEmpty())
4770 changelists.insert(entry->changelist);
4772 return changelists.size();
4773 #endif
4774 return 0;
4777 bool CGitStatusListCtrl::PrepareGroups(bool bForce /* = false */)
4780 bool bHasGroups=false;
4781 int max =0;
4783 for(int i=0;i< this->m_arStatusArray.size(); i++)
4785 int ParentNo = m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
4786 if( ParentNo > max)
4787 max=m_arStatusArray[i]->m_ParentNo&PARENT_MASK;
4790 if ( this->m_UnRevFileList.GetCount()>0 ||
4791 this->m_IgnoreFileList.GetCount()>0 ||
4792 max>0 || bForce)
4794 bHasGroups = true;
4797 RemoveAllGroups();
4798 EnableGroupView(bHasGroups);
4800 TCHAR groupname[1024];
4801 int groupindex = 0;
4803 if(bHasGroups)
4805 LVGROUP grp = {0};
4806 grp.cbSize = sizeof(LVGROUP);
4807 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4808 groupindex=0;
4810 //if(m_UnRevFileList.GetCount()>0)
4811 if(max >0)
4813 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MERGEDFILES)), 1023);
4814 grp.pszHeader = groupname;
4815 grp.iGroupId = MERGE_MASK;
4816 grp.uAlign = LVGA_HEADER_LEFT;
4817 InsertGroup(0, &grp);
4819 for(int i=0;i<=max;i++)
4821 CString str;
4822 str.Format(IDS_STATUSLIST_GROUP_DIFFWITHPARENT, i+1);
4823 grp.pszHeader = str.GetBuffer();
4824 str.ReleaseBuffer();
4825 grp.iGroupId = i;
4826 grp.uAlign = LVGA_HEADER_LEFT;
4827 InsertGroup(i+1, &grp);
4830 else
4832 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MODIFIEDFILES)), 1023);
4833 grp.pszHeader = groupname;
4834 grp.iGroupId = groupindex;
4835 grp.uAlign = LVGA_HEADER_LEFT;
4836 InsertGroup(groupindex++, &grp);
4840 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_NOTVERSIONEDFILES)), 1023);
4841 grp.pszHeader = groupname;
4842 grp.iGroupId = groupindex;
4843 grp.uAlign = LVGA_HEADER_LEFT;
4844 InsertGroup(groupindex++, &grp);
4847 //if(m_IgnoreFileList.GetCount()>0)
4849 _tcsncpy_s(groupname, 1024, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNOREDFILES)), 1023);
4850 grp.pszHeader = groupname;
4851 grp.iGroupId = groupindex;
4852 grp.uAlign = LVGA_HEADER_LEFT;
4853 InsertGroup(groupindex++, &grp);
4858 #if 0
4859 m_bHasIgnoreGroup = false;
4861 // now add the items which don't belong to a group
4862 LVGROUP grp = {0};
4863 grp.cbSize = sizeof(LVGROUP);
4864 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4865 CString sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET));
4866 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
4867 grp.pszHeader = groupname;
4868 grp.iGroupId = groupindex;
4869 grp.uAlign = LVGA_HEADER_LEFT;
4870 InsertGroup(groupindex++, &grp);
4872 for (std::map<CString,int>::iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
4874 if (it->first.Compare(SVNSLC_IGNORECHANGELIST)!=0)
4876 LVGROUP grp = {0};
4877 grp.cbSize = sizeof(LVGROUP);
4878 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4879 _tcsncpy_s(groupname, 1024, it->first, 1023);
4880 grp.pszHeader = groupname;
4881 grp.iGroupId = groupindex;
4882 grp.uAlign = LVGA_HEADER_LEFT;
4883 it->second = InsertGroup(groupindex++, &grp);
4885 else
4886 m_bHasIgnoreGroup = true;
4889 if (m_bHasIgnoreGroup)
4891 // and now add the group 'ignore-on-commit'
4892 std::map<CString,int>::iterator it = m_changelists.find(SVNSLC_IGNORECHANGELIST);
4893 if (it != m_changelists.end())
4895 grp.cbSize = sizeof(LVGROUP);
4896 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4897 _tcsncpy_s(groupname, 1024, SVNSLC_IGNORECHANGELIST, 1023);
4898 grp.pszHeader = groupname;
4899 grp.iGroupId = groupindex;
4900 grp.uAlign = LVGA_HEADER_LEFT;
4901 it->second = InsertGroup(groupindex, &grp);
4904 #endif
4905 return bHasGroups;
4908 void CGitStatusListCtrl::NotifyCheck()
4910 CWnd* pParent = GetParent();
4911 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
4913 pParent->SendMessage(GITSLNM_CHECKCHANGED, m_nSelected);
4917 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash,CTGitPathList *list)
4919 BYTE_VECTOR out;
4920 this->m_bBusy=TRUE;
4921 m_CurrentVersion=hash;
4923 int count = 0;
4924 if(list == NULL)
4925 count = 1;
4926 else
4927 count = list->GetCount();
4929 CString head = _T("HEAD");
4930 if(m_amend)
4931 head = _T("HEAD~1");
4933 if(hash == GIT_REV_ZERO)
4935 for(int i=0;i<count;i++)
4937 BYTE_VECTOR cmdout;
4938 cmdout.clear();
4939 CString cmd;
4940 if(!g_Git.IsInitRepos())
4942 // also list staged files which will be in the commit
4943 cmd=(_T("git.exe diff-index --cached --raw ") + head + _T(" --numstat -C -M -z"));
4944 g_Git.Run(cmd, &cmdout);
4946 if(list == NULL)
4947 cmd=(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z"));
4948 else
4949 cmd.Format(_T("git.exe diff-index --raw ") + head + _T(" --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
4951 BYTE_VECTOR cmdErr;
4952 if(g_Git.Run(cmd, &cmdout, &cmdErr))
4954 int last = cmdErr.RevertFind(0,-1);
4955 CString str;
4956 g_Git.StringAppend(&str, &cmdErr[last + 1], CP_UTF8, cmdErr.size() - last -1);
4957 CMessageBox::Show(NULL, str, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
4960 out.append(cmdout, 0);
4962 else // Init Repository
4964 //We will list all added file for init repository because commit will comit these
4965 //if(list == NULL)
4966 cmd=_T("git.exe ls-files -s -t -z");
4967 //else
4968 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
4970 g_Git.Run(cmd, &cmdout);
4971 //out+=cmdout;
4972 out.append(cmdout,0);
4976 if(g_Git.IsInitRepos())
4978 m_StatusFileList.ParserFromLsFile(out);
4979 for(int i=0;i<m_StatusFileList.GetCount();i++)
4980 ((CTGitPath&)(m_StatusFileList[i])).m_Action=CTGitPath::LOGACTIONS_ADDED;
4982 else
4983 this->m_StatusFileList.ParserFromLog(out);
4985 //handle delete conflict case, when remote : modified, local : deleted.
4986 for(int i=0;i<count;i++)
4988 BYTE_VECTOR cmdout;
4989 CString cmd;
4991 if(list == NULL)
4992 cmd=_T("git.exe ls-files -u -t -z");
4993 else
4994 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list)[i].GetGitPathString());
4996 g_Git.Run(cmd, &cmdout);
4998 CTGitPathList conflictlist;
4999 conflictlist.ParserFromLog(cmdout);
5000 for(int i=0;i<conflictlist.GetCount();i++)
5002 CTGitPath *p=m_StatusFileList.LookForGitPath(conflictlist[i].GetGitPathString());
5003 if(p)
5004 p->m_Action|=CTGitPath::LOGACTIONS_UNMERGED;
5005 else
5006 m_StatusFileList.AddPath(conflictlist[i]);
5010 // handle source files of file renames/moves (issue #860)
5011 // if a file gets renamed and the new file "git add"ed, diff-index doesn't list the source file anymore
5012 for(int i = 0; i < count; i++)
5014 BYTE_VECTOR cmdout;
5015 CString cmd;
5017 if(list == NULL)
5018 cmd = _T("git.exe ls-files -d -z");
5019 else
5020 cmd.Format(_T("git.exe ls-files -d -z -- \"%s\""),(*list)[i].GetGitPathString());
5022 g_Git.Run(cmd, &cmdout);
5024 CTGitPathList deletelist;
5025 deletelist.ParserFromLog(cmdout, true);
5026 for(int i = 0; i < deletelist.GetCount(); i++)
5028 CTGitPath *p = m_StatusFileList.LookForGitPath(deletelist[i].GetGitPathString());
5029 if(!p)
5030 m_StatusFileList.AddPath(deletelist[i]);
5031 else if ((p->m_Action == CTGitPath::LOGACTIONS_ADDED || p->m_Action == CTGitPath::LOGACTIONS_REPLACED) && !p->Exists())
5033 if (CMessageBox::Show(m_hWnd, _T("TortoiseGit detected that the file \"") + p->GetWinPathString() +_T("\" does not exist, but is staged as \"Added\".\nThe commit dialog cannot handle this.\n\nDo you want to remove it from the index?"), _T("TortoiseGit"), 1, IDI_EXCLAMATION, _T("&Remove file from index"), _T("&Ignore")) == 1)
5035 g_Git.Run(_T("git.exe rm -f --cache -- \"") + p->GetWinPathString() + _T("\""), &cmdout);
5036 m_StatusFileList.RemoveItem(*p);
5042 else
5044 int count = 0;
5045 if(list == NULL)
5046 count = 1;
5047 else
5048 count = list->GetCount();
5050 for(int i=0;i<count;i++)
5052 BYTE_VECTOR cmdout;
5053 CString cmd;
5054 if(list == NULL)
5055 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash);
5056 else
5057 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash,(*list)[i].GetGitPathString());
5059 g_Git.Run(cmd, &cmdout, NULL);
5061 out.append(cmdout);
5063 this->m_StatusFileList.ParserFromLog(out);
5067 for(int i=0;i<m_StatusFileList.GetCount();i++)
5069 CTGitPath * gitpatch=(CTGitPath*)&m_StatusFileList[i];
5070 gitpatch->m_Checked = TRUE;
5071 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
5074 this->m_bBusy=FALSE;
5075 return 0;
5078 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList &list)
5080 m_arStatusArray.clear();
5081 for(int i=0;i<list.GetCount();i++)
5083 CTGitPath * gitpath=(CTGitPath*)&list[i];
5085 if(gitpath ->m_Action & CTGitPath::LOGACTIONS_HIDE)
5086 continue;
5088 gitpath->m_Checked = TRUE;
5089 m_arStatusArray.push_back((CTGitPath*)&list[i]);
5091 return 0;
5094 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList *List)
5096 this->m_UnRevFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER,List);
5097 for(int i=0;i<m_UnRevFileList.GetCount();i++)
5099 CTGitPath * gitpatch=(CTGitPath*)&m_UnRevFileList[i];
5100 gitpatch->m_Checked = FALSE;
5101 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
5103 return 0;
5106 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList *List)
5108 this->m_IgnoreFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER|CTGitPath::LOGACTIONS_IGNORE,List);
5109 for(int i=0;i<m_IgnoreFileList.GetCount();i++)
5111 CTGitPath * gitpatch=(CTGitPath*)&m_IgnoreFileList[i];
5112 gitpatch->m_Checked = FALSE;
5113 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
5115 return 0;
5117 int CGitStatusListCtrl::UpdateFileList(int mask,bool once,CTGitPathList *List)
5119 if(mask&CGitStatusListCtrl::FILELIST_MODIFY)
5121 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_MODIFY)))
5123 UpdateFileList(git_revnum_t(GIT_REV_ZERO),List);
5124 m_FileLoaded|=CGitStatusListCtrl::FILELIST_MODIFY;
5127 if(mask&CGitStatusListCtrl::FILELIST_UNVER)
5129 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_UNVER)))
5131 UpdateUnRevFileList(List);
5132 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
5134 if(mask&CGitStatusListCtrl::FILELIST_IGNORE && (once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_IGNORE))))
5136 UpdateIgnoreFileList(List);
5137 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
5140 return 0;
5143 void CGitStatusListCtrl::Clear()
5145 m_FileLoaded=0;
5146 this->DeleteAllItems();
5147 this->m_arListArray.clear();
5148 this->m_arStatusArray.clear();
5149 this->m_changelists.clear();
5151 //////////////////////////////////////////////////////////////////////////
5152 #if 0
5153 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD * /*pdwEffect*/, POINTL pt)
5155 if(pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
5157 HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
5158 if(hDrop != NULL)
5160 TCHAR szFileName[MAX_PATH];
5162 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
5164 POINT clientpoint;
5165 clientpoint.x = pt.x;
5166 clientpoint.y = pt.y;
5167 ScreenToClient(m_hTargetWnd, &clientpoint);
5168 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5170 CTSVNPathList changelistItems;
5171 for(UINT i = 0; i < cFiles; ++i)
5173 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5174 changelistItems.AddPath(CTSVNPath(szFileName));
5176 // find the changelist name
5177 CString sChangelist;
5178 LONG_PTR nGroup = m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint);
5179 for (std::map<CString, int>::iterator it = m_pSVNStatusListCtrl->m_changelists.begin(); it != m_pSVNStatusListCtrl->m_changelists.end(); ++it)
5180 if (it->second == nGroup)
5181 sChangelist = it->first;
5182 if (!sChangelist.IsEmpty())
5184 SVN git;
5185 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
5187 for (int l=0; l<changelistItems.GetCount(); ++l)
5189 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5190 if (index >= 0)
5192 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5193 if (e)
5195 e->changelist = sChangelist;
5196 if (!e->IsFolder())
5198 if (m_pSVNStatusListCtrl->m_changelists.find(e->changelist)!=m_pSVNStatusListCtrl->m_changelists.end())
5199 m_pSVNStatusListCtrl->SetItemGroup(index, m_pSVNStatusListCtrl->m_changelists[e->changelist]);
5200 else
5201 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5205 else
5207 HWND hParentWnd = GetParent(m_hTargetWnd);
5208 if (hParentWnd != NULL)
5209 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5213 else
5215 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
5218 else
5220 SVN git;
5221 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
5223 for (int l=0; l<changelistItems.GetCount(); ++l)
5225 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5226 if (index >= 0)
5228 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5229 if (e)
5231 e->changelist = sChangelist;
5232 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5235 else
5237 HWND hParentWnd = GetParent(m_hTargetWnd);
5238 if (hParentWnd != NULL)
5239 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5243 else
5245 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
5249 else
5251 for(UINT i = 0; i < cFiles; ++i)
5253 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5254 HWND hParentWnd = GetParent(m_hTargetWnd);
5255 if (hParentWnd != NULL)
5256 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)szFileName);
5260 GlobalUnlock(medium.hGlobal);
5262 return true; //let base free the medium
5264 HRESULT STDMETHODCALLTYPE CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)
5266 CIDropTarget::DragOver(grfKeyState, pt, pdwEffect);
5267 *pdwEffect = DROPEFFECT_COPY;
5268 if (m_pSVNStatusListCtrl)
5270 POINT clientpoint;
5271 clientpoint.x = pt.x;
5272 clientpoint.y = pt.y;
5273 ScreenToClient(m_hTargetWnd, &clientpoint);
5274 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5276 *pdwEffect = DROPEFFECT_MOVE;
5278 else if ((!m_pSVNStatusListCtrl->m_bFileDropsEnabled)||(m_pSVNStatusListCtrl->m_bOwnDrag))
5280 *pdwEffect = DROPEFFECT_NONE;
5283 return S_OK;
5286 #endif
5288 void CGitStatusListCtrl::FileSaveAs(CTGitPath *path)
5290 CString filename;
5291 filename.Format(_T("%s-%s%s"), path->GetBaseFilename(), this->m_CurrentVersion.Left(g_Git.GetShortHASHLength()), path->GetFileExtension());
5292 CFileDialog dlg(FALSE,NULL,
5293 filename,
5294 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
5295 NULL);
5296 CString currentpath;
5297 currentpath=g_Git.m_CurrentDir+_T("\\");
5298 currentpath+=path->GetWinPathString();
5300 dlg.m_ofn.lpstrInitialDir=currentpath.GetBuffer();
5302 CString cmd,out;
5303 if(dlg.DoModal()==IDOK)
5305 filename = dlg.GetPathName();
5306 if(m_CurrentVersion == GIT_REV_ZERO)
5308 if(!CopyFile(g_Git.m_CurrentDir +_T("\\") + path->GetWinPath(),filename,false))
5310 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
5311 return;
5315 else
5317 if(g_Git.GetOneFile(m_CurrentVersion,*path,filename))
5319 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path->GetGitPathString(), m_CurrentVersion, filename);
5320 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5321 return;
5328 int CGitStatusListCtrl::RevertSelectedItemToVersion()
5330 if(this->m_CurrentVersion.IsEmpty())
5331 return 0;
5332 if(this->m_CurrentVersion == GIT_REV_ZERO)
5333 return 0;
5335 POSITION pos = GetFirstSelectedItemPosition();
5336 int index;
5337 CString cmd,out;
5338 int count =0;
5339 while ((index = GetNextSelectedItem(pos)) >= 0)
5341 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
5342 cmd.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion,fentry->GetGitPathString());
5343 out.Empty();
5344 if (g_Git.Run(cmd, &out, CP_UTF8))
5346 if (MessageBox(out, _T("TortoiseGit"), MB_ICONEXCLAMATION | MB_OKCANCEL) == IDCANCEL)
5347 break;
5349 else
5350 count++;
5353 out.Format(IDS_STATUSLIST_FILESREVERTED, count, m_CurrentVersion);
5354 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5355 return 0;
5358 void CGitStatusListCtrl::OpenFile(CTGitPath*filepath,int mode)
5360 CString file;
5361 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
5363 file= filepath->GetWinPath();
5365 else
5367 CString temppath;
5368 GetTempPath(temppath);
5369 file.Format(_T("%s%s_%s%s"),
5370 temppath,
5371 filepath->GetBaseFilename(),
5372 m_CurrentVersion.Left(g_Git.GetShortHASHLength()),
5373 filepath->GetFileExtension());
5374 CString cmd,out;
5375 if(g_Git.GetOneFile(m_CurrentVersion, *filepath, file))
5377 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, filepath->GetGitPathString(), m_CurrentVersion, file);
5378 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5379 return;
5383 if(mode == ALTERNATIVEEDITOR)
5385 CAppUtils::LaunchAlternativeEditor(file);
5386 return;
5388 int ret = HINSTANCE_ERROR;
5390 if(mode == OPEN )
5392 ret = (int)ShellExecute(this->m_hWnd, NULL,file, NULL, NULL, SW_SHOW);
5394 if (ret > HINSTANCE_ERROR)
5396 return;
5401 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
5402 cmd += file;
5403 CAppUtils::LaunchApplication(cmd, NULL, false);