Fix add fail when file name include space at commit dialog.
[TortoiseGit.git] / src / Git / GitStatusListCtrl.cpp
blob330c7754d4f9fbfb0a38c205ebd121f85ecdeda6
3 // TortoiseSVN - a Windows shell extension for easy version control
5 // Copyright (C) 2003-2008 - TortoiseSVN
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 "GitStatusListCtrl.h"
24 #include "resource.h"
25 #include "..\\TortoiseShell\resource.h"
26 #include "MessageBox.h"
27 #include "MyMemDC.h"
28 #include "UnicodeUtils.h"
29 #include "AppUtils.h"
30 #include "PathUtils.h"
31 #include "TempFile.h"
32 #include "StringUtils.h"
33 #include "DirFileEnum.h"
34 #include "GitConfig.h"
35 //#include "SVNProperties.h"
36 #include "Git.h"
37 #include "GitDiff.h"
38 //#include "LogDlg.h"
39 //#include "SVNProgressDlg.h"
40 #include "SysImageList.h"
41 //#include "Svnstatuslistctrl.h"
42 #include "TGitPath.h"
43 #include "Registry.h"
44 #include "GitStatus.h"
45 //#include "SVNHelpers.h"
46 #include "InputDlg.h"
47 #include "ShellUpdater.h"
48 #include "GitAdminDir.h"
49 //#include "DropFiles.h"
50 #include "IconMenu.h"
51 //#include "AddDlg.h"
52 //#include "EditPropertiesDlg.h"
53 //#include "CreateChangelistDlg.h"
54 #include "XPTheme.h"
55 #include "CommonResource.h"
57 const UINT CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED
58 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
59 const UINT CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH
60 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
61 const UINT CGitStatusListCtrl::SVNSLNM_ADDFILE
62 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
63 const UINT CGitStatusListCtrl::SVNSLNM_CHECKCHANGED
64 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
69 BEGIN_MESSAGE_MAP(CGitStatusListCtrl, CListCtrl)
70 ON_NOTIFY(HDN_ITEMCLICKA, 0, OnHdnItemclick)
71 ON_NOTIFY(HDN_ITEMCLICKW, 0, OnHdnItemclick)
72 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
73 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
74 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, OnLvnItemchanged)
75 ON_WM_CONTEXTMENU()
76 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk)
77 ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnLvnGetInfoTip)
78 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
79 ON_WM_SETCURSOR()
80 ON_WM_GETDLGCODE()
81 ON_NOTIFY_REFLECT(NM_RETURN, OnNMReturn)
82 ON_WM_KEYDOWN()
83 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
84 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
85 ON_WM_PAINT()
86 ON_NOTIFY(HDN_BEGINTRACKA, 0, &CGitStatusListCtrl::OnHdnBegintrack)
87 ON_NOTIFY(HDN_BEGINTRACKW, 0, &CGitStatusListCtrl::OnHdnBegintrack)
88 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, &CGitStatusListCtrl::OnHdnItemchanging)
89 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, &CGitStatusListCtrl::OnHdnItemchanging)
90 ON_WM_DESTROY()
91 ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBeginDrag)
92 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING, &CGitStatusListCtrl::OnLvnItemchanging)
93 END_MESSAGE_MAP()
97 CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl()
98 //, m_HeadRev(GitRev::REV_HEAD)
99 , m_pbCanceled(NULL)
100 , m_pStatLabel(NULL)
101 , m_pSelectButton(NULL)
102 , m_pConfirmButton(NULL)
103 , m_bBusy(false)
104 , m_bEmpty(false)
105 , m_bUnversionedRecurse(true)
106 , m_bShowIgnores(false)
107 , m_pDropTarget(NULL)
108 , m_bIgnoreRemoveOnly(false)
109 , m_bCheckChildrenWithParent(false)
110 , m_bUnversionedLast(true)
111 , m_bHasChangeLists(false)
112 , m_bHasLocks(false)
113 , m_bBlock(false)
114 , m_bBlockUI(false)
115 , m_bHasCheckboxes(false)
116 , m_bCheckIfGroupsExist(true)
117 , m_bFileDropsEnabled(false)
118 , m_bOwnDrag(false)
119 , m_dwDefaultColumns(0)
120 , m_ColumnManager(this)
121 , m_bAscending(false)
122 , m_nSortedColumn(-1)
123 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE))
125 m_FileLoaded=0;
126 m_critSec.Init();
129 CGitStatusListCtrl::~CGitStatusListCtrl()
131 // if (m_pDropTarget)
132 // delete m_pDropTarget;
133 ClearStatusArray();
136 void CGitStatusListCtrl::ClearStatusArray()
138 #if 0
139 Locker lock(m_critSec);
140 for (size_t i=0; i < m_arStatusArray.size(); i++)
142 delete m_arStatusArray[i];
144 m_arStatusArray.clear();
145 #endif
147 #if 0
148 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(UINT_PTR index)
151 if (index >= (UINT_PTR)m_arListArray.size())
152 return NULL;
153 if (m_arListArray[index] >= m_arStatusArray.size())
154 return NULL;
155 return m_arStatusArray[m_arListArray[index]];
157 return NULL;
159 #endif
160 #if 0
161 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetVisibleListEntry(const CTGitPath& path)
163 int itemCount = GetItemCount();
164 for (int i=0; i < itemCount; i++)
166 FileEntry * entry = GetListEntry(i);
167 if (entry->GetPath().IsEquivalentTo(path))
168 return entry;
170 return NULL;
172 #endif
173 #if 0
174 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(const CTGitPath& path)
177 for (size_t i=0; i < m_arStatusArray.size(); i++)
179 FileEntry * entry = m_arStatusArray[i];
180 if (entry->GetPath().IsEquivalentTo(path))
181 return entry;
184 return NULL;
186 #endif
188 #if 0
189 int CGitStatusListCtrl::GetIndex(const CTGitPath& path)
191 int itemCount = GetItemCount();
192 for (int i=0; i < itemCount; i++)
194 FileEntry * entry = GetListEntry(i);
195 if (entry->GetPath().IsEquivalentTo(path))
196 return i;
198 return -1;
200 #endif
202 void CGitStatusListCtrl::Init(DWORD dwColumns, const CString& sColumnInfoContainer, unsigned __int64 dwContextMenus /* = GitSLC_POPALL */, bool bHasCheckboxes /* = true */)
204 Locker lock(m_critSec);
206 m_dwDefaultColumns = dwColumns | 1;
207 m_dwContextMenus = dwContextMenus;
208 m_bHasCheckboxes = bHasCheckboxes;
210 // set the extended style of the listcontrol
211 // 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.
212 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
213 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
214 if (DWORD(regFullRowSelect))
215 exStyle |= LVS_EX_FULLROWSELECT;
216 exStyle |= (bHasCheckboxes ? LVS_EX_CHECKBOXES : 0);
217 SetRedraw(false);
218 SetExtendedStyle(exStyle);
220 CXPTheme theme;
221 theme.SetWindowTheme(m_hWnd, L"Explorer", NULL);
223 m_nIconFolder = SYS_IMAGE_LIST().GetDirIconIndex();
224 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL);
226 m_ColumnManager.ReadSettings (m_dwDefaultColumns, sColumnInfoContainer);
228 // enable file drops
229 #if 0
230 if (m_pDropTarget == NULL)
232 m_pDropTarget = new CGitStatusListCtrlDropTarget(this);
233 RegisterDragDrop(m_hWnd,m_pDropTarget);
234 // create the supported formats:
235 FORMATETC ftetc={0};
236 ftetc.dwAspect = DVASPECT_CONTENT;
237 ftetc.lindex = -1;
238 ftetc.tymed = TYMED_HGLOBAL;
239 ftetc.cfFormat=CF_HDROP;
240 m_pDropTarget->AddSuportedFormat(ftetc);
242 #endif
244 SetRedraw(true);
246 m_bUnversionedRecurse = !!((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE));
249 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID)
251 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID);
254 BOOL CGitStatusListCtrl::GetStatus ( const CTGitPathList* pathList
255 , bool bUpdate /* = FALSE */
256 , bool bShowIgnores /* = false */
257 , bool bShowUnRev
258 , bool bShowUserProps /* = false */)
260 Locker lock(m_critSec);
261 int mask= CGitStatusListCtrl::FILELIST_MODIFY;
262 if(bShowIgnores)
263 mask|= CGitStatusListCtrl::FILELIST_IGNORE;
264 if(bShowUnRev)
265 mask|= CGitStatusListCtrl::FILELIST_UNVER;
266 this->UpdateFileList(mask,bUpdate,(CTGitPathList*)pathList);
269 #if 0
271 int refetchcounter = 0;
272 BOOL bRet = TRUE;
273 Invalidate();
274 // force the cursor to change
275 POINT pt;
276 GetCursorPos(&pt);
277 SetCursorPos(pt.x, pt.y);
279 m_mapFilenameToChecked.clear();
280 //m_StatusUrlList.Clear();
281 bool bHasChangelists = (m_changelists.size()>1 || (m_changelists.size()>0 && !m_bHasIgnoreGroup));
282 m_changelists.clear();
283 for (size_t i=0; i < m_arStatusArray.size(); i++)
285 FileEntry * entry = m_arStatusArray[i];
286 if ( bHasChangelists && entry->checked)
288 // If change lists are present, remember all checked entries
289 CString path = entry->GetPath().GetGitPathString();
290 m_mapFilenameToChecked[path] = true;
292 if ( (entry->status==git_wc_status_unversioned || entry->status==git_wc_status_missing ) && entry->checked )
294 // The user manually selected an unversioned or missing file. We remember
295 // this so that the selection can be restored when refreshing.
296 CString path = entry->GetPath().GetGitPathString();
297 m_mapFilenameToChecked[path] = true;
299 else if ( entry->status > git_wc_status_normal && !entry->checked )
301 // The user manually deselected a versioned file. We remember
302 // this so that the deselection can be restored when refreshing.
303 CString path = entry->GetPath().GetGitPathString();
304 m_mapFilenameToChecked[path] = false;
308 // use a sorted path list to make sure we fetch the status of
309 // parent items first, *then* the child items (if any)
310 CTGitPathList sortedPathList = pathList;
311 sortedPathList.SortByPathname();
314 bRet = TRUE;
315 m_nTargetCount = 0;
316 m_bHasExternalsFromDifferentRepos = FALSE;
317 m_bHasExternals = FALSE;
318 m_bHasUnversionedItems = FALSE;
319 m_bHasLocks = false;
320 m_bHasChangeLists = false;
321 m_bShowIgnores = bShowIgnores;
322 m_nSortedColumn = 0;
323 m_bBlock = TRUE;
324 m_bBusy = true;
325 m_bEmpty = false;
326 Invalidate();
328 // first clear possible status data left from
329 // previous GetStatus() calls
330 ClearStatusArray();
332 m_StatusFileList = sortedPathList;
334 // Since Git_client_status() returns all files, even those in
335 // folders included with Git:externals we need to check if all
336 // files we get here belongs to the same repository.
337 // It is possible to commit changes in an external folder, as long
338 // as the folder belongs to the same repository (but another path),
339 // but it is not possible to commit all files if the externals are
340 // from a different repository.
342 // To check if all files belong to the same repository, we compare the
343 // UUID's - if they're identical then the files belong to the same
344 // repository and can be committed. But if they're different, then
345 // tell the user to commit all changes in the external folders
346 // first and exit.
347 CStringA sUUID; // holds the repo UUID
348 CTGitPathList arExtPaths; // list of Git:external paths
350 GitConfig config;
352 m_sURL.Empty();
354 m_nTargetCount = sortedPathList.GetCount();
356 GitStatus status(m_pbCanceled);
357 if(m_nTargetCount > 1 && sortedPathList.AreAllPathsFilesInOneDirectory())
359 // This is a special case, where we've been given a list of files
360 // all from one folder
361 // We handle them by setting a status filter, then requesting the Git status of
362 // all the files in the directory, filtering for the ones we're interested in
363 status.SetFilter(sortedPathList);
365 // if all selected entries are files, we don't do a recursive status
366 // fetching. But if only one is a directory, we have to recurse.
367 git_depth_t depth = git_depth_files;
368 // We have set a filter. If all selected items were files or we fetch
369 // the status not recursively, then we have to include
370 // ignored items too - the user has selected them
371 bool bShowIgnoresRight = true;
372 for (int fcindex=0; fcindex<sortedPathList.GetCount(); ++fcindex)
374 if (sortedPathList[fcindex].IsDirectory())
376 depth = git_depth_infinity;
377 bShowIgnoresRight = false;
378 break;
381 if(!FetchStatusForSingleTarget(config, status, sortedPathList.GetCommonDirectory(), bUpdate, sUUID, arExtPaths, true, depth, bShowIgnoresRight))
383 bRet = FALSE;
386 else
388 for(int nTarget = 0; nTarget < m_nTargetCount; nTarget++)
390 // check whether the path we want the status for is already fetched due to status-fetching
391 // of a parent path.
392 // this check is only done for file paths, because folder paths could be included already
393 // but not recursively
394 if (sortedPathList[nTarget].IsDirectory() || GetListEntry(sortedPathList[nTarget]) == NULL)
396 if(!FetchStatusForSingleTarget(config, status, sortedPathList[nTarget], bUpdate, sUUID,
397 arExtPaths, false, git_depth_infinity, bShowIgnores))
399 bRet = FALSE;
405 // remove the 'helper' files of conflicted items from the list.
406 // otherwise they would appear as unversioned files.
407 for (INT_PTR cind = 0; cind < m_ConflictFileList.GetCount(); ++cind)
409 for (size_t i=0; i < m_arStatusArray.size(); i++)
411 if (m_arStatusArray[i]->GetPath().IsEquivalentTo(m_ConflictFileList[cind]))
413 delete m_arStatusArray[i];
414 m_arStatusArray.erase(m_arStatusArray.begin()+i);
415 break;
419 refetchcounter++;
420 } while(!BuildStatistics() && (refetchcounter < 2) && (*m_pbCanceled==false));
422 if (bShowUserProps)
423 FetchUserProperties();
425 m_ColumnManager.UpdateUserPropList (m_arStatusArray);
427 m_bBlock = FALSE;
428 m_bBusy = false;
429 GetCursorPos(&pt);
430 SetCursorPos(pt.x, pt.y);
431 return bRet;
432 #endif
433 BuildStatistics();
434 return TRUE;
438 // Fetch all local properties for all elements in the status array
440 void CGitStatusListCtrl::FetchUserProperties()
442 #if 0
443 GitPool globalPool;
445 for (size_t i = 0, count = m_arStatusArray.size(); i < count; ++i)
447 // local / temp pool to hold parameters and props for a single item
449 GitPool localPool ((apr_pool_t*)globalPool);
451 // open working copy for this path
453 const char* path = m_arStatusArray[i]->path.GetGitApiPath (localPool);
455 Git_wc_adm_access_t *adm_access = NULL;
456 Git_error_t * error = Git_wc_adm_probe_open3 ( &adm_access
457 , NULL
458 , path
459 , FALSE // no write lock
460 , 0 // lock just the directory/file itself
461 , NULL
462 , NULL
463 , localPool);
464 if (error == NULL)
466 // get the props and add them to the status info
468 apr_hash_t* props = NULL;
469 Git_error_t * error = Git_wc_prop_list ( &props
470 , path
471 , adm_access
472 , localPool);
473 if (error == NULL)
475 for ( apr_hash_index_t *index
476 = apr_hash_first (localPool, props)
477 ; index != NULL
478 ; index = apr_hash_next (index))
480 // extract next entry from hash
482 const char* key = NULL;
483 ptrdiff_t keyLen;
484 const char** val = NULL;
486 apr_hash_this ( index
487 , reinterpret_cast<const void**>(&key)
488 , &keyLen
489 , reinterpret_cast<void**>(&val));
491 // decode / dispatch it
493 CString name = CUnicodeUtils::GetUnicode (key);
494 CString value = CUnicodeUtils::GetUnicode (*val);
496 // store in property container (truncate it after ~100 chars)
498 m_arStatusArray[i]->present_props[name]
499 = value.Left (GitSLC_MAXUSERPROPLENGTH);
502 error = Git_wc_adm_close2 (adm_access, localPool);
504 Git_error_clear (error);
506 #endif
511 // Work on a single item from the list of paths which is provided to us
513 bool CGitStatusListCtrl::FetchStatusForSingleTarget(
514 GitConfig& config,
515 GitStatus& status,
516 const CTGitPath& target,
517 bool bFetchStatusFromRepository,
518 CStringA& strCurrentRepositoryUUID,
519 CTGitPathList& arExtPaths,
520 bool bAllDirect,
521 git_depth_t depth,
522 bool bShowIgnores
525 #if 0
526 config.GetDefaultIgnores();
528 CTGitPath workingTarget(target);
530 git_wc_status2_t * s;
531 CTGitPath GitPath;
532 s = status.GetFirstFileStatus(workingTarget, GitPath, bFetchStatusFromRepository, depth, bShowIgnores);
534 m_HeadRev = SVNRev(status.headrev);
535 if (s!=0)
537 Git_wc_status_kind wcFileStatus = GitStatus::GetMoreImportant(s->text_status, s->prop_status);
539 // This one fixes a problem with externals:
540 // If a strLine is a file, Git:externals and its parent directory
541 // will also be returned by GetXXXFileStatus. Hence, we skip all
542 // status info until we find the one matching workingTarget.
543 if (!workingTarget.IsDirectory())
545 if (!workingTarget.IsEquivalentTo(GitPath))
547 while (s != 0)
549 s = status.GetNextFileStatus(GitPath);
550 if(workingTarget.IsEquivalentTo(GitPath))
552 break;
555 if (s == 0)
557 m_sLastError = status.GetLastErrorMsg();
558 return false;
560 // Now, set working target to be the base folder of this item
561 workingTarget = workingTarget.GetDirectory();
564 bool bEntryFromDifferentRepo = false;
565 // Is this a versioned item with an associated repos UUID?
566 if ((s->entry)&&(s->entry->uuid))
568 // Have we seen a repos UUID yet?
569 if (strCurrentRepositoryUUID.IsEmpty())
571 // This is the first repos UUID we've seen - record it
572 strCurrentRepositoryUUID = s->entry->uuid;
573 m_sUUID = strCurrentRepositoryUUID;
575 else
577 if (strCurrentRepositoryUUID.Compare(s->entry->uuid)!=0)
579 // This item comes from a different repository than our main one
580 m_bHasExternalsFromDifferentRepos = TRUE;
581 bEntryFromDifferentRepo = true;
582 if (s->entry->kind == Git_node_dir)
583 arExtPaths.AddPath(workingTarget);
587 else if (strCurrentRepositoryUUID.IsEmpty() && (s->text_status == Git_wc_status_added))
589 // An added entry doesn't have an UUID assigned to it yet.
590 // So we fetch the status of the parent directory instead and
591 // check if that one has an UUID assigned to it.
592 Git_wc_status2_t * sparent;
593 CTGitPath path = workingTarget;
596 CTGitPath GitParentPath;
597 GitStatus tempstatus;
598 sparent = tempstatus.GetFirstFileStatus(path.GetContainingDirectory(), GitParentPath, false, Git_depth_empty, false);
599 path = GitParentPath;
600 } while ( (sparent) && (sparent->entry) && (!sparent->entry->uuid) && (sparent->text_status==Git_wc_status_added) );
601 if (sparent && sparent->entry && sparent->entry->uuid)
603 strCurrentRepositoryUUID = sparent->entry->uuid;
604 m_sUUID = strCurrentRepositoryUUID;
608 if ((wcFileStatus == Git_wc_status_unversioned)&& GitPath.IsDirectory())
610 // check if the unversioned folder is maybe versioned. This
611 // could happen with nested layouts
612 Git_wc_status_kind st = GitStatus::GetAllStatus(workingTarget);
613 if ((st != Git_wc_status_unversioned)&&(st != Git_wc_status_none))
615 return true; // ignore nested layouts
618 if (status.IsExternal(GitPath))
620 m_bHasExternals = TRUE;
623 AddNewFileEntry(s, GitPath, workingTarget, true, m_bHasExternals, bEntryFromDifferentRepo);
625 if (((wcFileStatus == Git_wc_status_unversioned)||(wcFileStatus == Git_wc_status_none)||((wcFileStatus == Git_wc_status_ignored)&&(m_bShowIgnores))) && GitPath.IsDirectory())
627 // we have an unversioned folder -> get all files in it recursively!
628 AddUnversionedFolder(GitPath, workingTarget.GetContainingDirectory(), &config);
631 // for folders, get all statuses inside it too
632 if(workingTarget.IsDirectory())
634 ReadRemainingItemsStatus(status, workingTarget, strCurrentRepositoryUUID, arExtPaths, &config, bAllDirect);
637 } // if (s!=0)
638 else
640 m_sLastError = status.GetLastErrorMsg();
641 return false;
643 #endif
644 return true;
646 #if 0
647 const CGitStatusListCtrl::FileEntry*
648 CGitStatusListCtrl::AddNewFileEntry(
649 const git_wc_status2_t* pGitStatus, // The return from the Git GetStatus functions
650 const CTGitPath& path, // The path of the item we're adding
651 const CTGitPath& basePath, // The base directory for this status build
652 bool bDirectItem, // Was this item the first found by GetFirstFileStatus or by a subsequent GetNextFileStatus call
653 bool bInExternal, // Are we in an 'external' folder
654 bool bEntryfromDifferentRepo // if the entry is from a different repository
657 FileEntry * entry = new FileEntry();
660 entry->path = path;
661 entry->basepath = basePath;
662 entry->status = GitStatus::GetMoreImportant(pGitStatus->text_status, pGitStatus->prop_status);
663 entry->textstatus = pGitStatus->text_status;
664 entry->propstatus = pGitStatus->prop_status;
665 // entry->remotestatus = GitStatus::GetMoreImportant(pGitStatus->repos_text_status, pGitStatus->repos_prop_status);
666 // entry->remotetextstatus = pGitStatus->repos_text_status;
667 // entry->remotepropstatus = pGitStatus->repos_prop_status;
668 entry->inexternal = bInExternal;
669 entry->differentrepo = bEntryfromDifferentRepo;
670 entry->direct = bDirectItem;
671 // entry->copied = !!pGitStatus->copied;
672 // entry->switched = !!pGitStatus->switched;
674 entry->last_commit_date = pGitStatus->ood_last_cmt_date;
675 if ((entry->last_commit_date == NULL)&&(pGitStatus->entry))
676 entry->last_commit_date = pGitStatus->entry->cmt_date;
677 entry->remoterev = pGitStatus->ood_last_cmt_rev;
678 if (pGitStatus->entry)
679 entry->last_commit_rev = pGitStatus->entry->cmt_rev;
680 if (pGitStatus->ood_last_cmt_author)
681 entry->last_commit_author = CUnicodeUtils::GetUnicode(pGitStatus->ood_last_cmt_author);
682 if ((entry->last_commit_author.IsEmpty())&&(pGitStatus->entry)&&(pGitStatus->entry->cmt_author))
683 entry->last_commit_author = CUnicodeUtils::GetUnicode(pGitStatus->entry->cmt_author);
685 if (pGitStatus->entry)
686 entry->isConflicted = (pGitStatus->entry->conflict_wrk && PathFileExists(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_wrk))) ? true : false;
688 if ((entry->status == Git_wc_status_conflicted)||(entry->isConflicted))
690 entry->isConflicted = true;
691 if (pGitStatus->entry)
693 CTGitPath cpath;
694 if (pGitStatus->entry->conflict_wrk)
696 cpath = path.GetDirectory();
697 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_wrk));
698 m_ConflictFileList.AddPath(cpath);
700 if (pGitStatus->entry->conflict_old)
702 cpath = path.GetDirectory();
703 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_old));
704 m_ConflictFileList.AddPath(cpath);
706 if (pGitStatus->entry->conflict_new)
708 cpath = path.GetDirectory();
709 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_new));
710 m_ConflictFileList.AddPath(cpath);
712 if (pGitStatus->entry->prejfile)
714 cpath = path.GetDirectory();
715 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->prejfile));
716 m_ConflictFileList.AddPath(cpath);
721 if (pGitStatus->entry)
723 entry->isfolder = (pGitStatus->entry->kind == Git_node_dir);
724 entry->Revision = pGitStatus->entry->revision;
725 entry->keeplocal = !!pGitStatus->entry->keep_local;
726 entry->working_size = pGitStatus->entry->working_size;
727 entry->depth = pGitStatus->entry->depth;
729 if (pGitStatus->entry->url)
731 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(pGitStatus->entry->url));
733 if (pGitStatus->entry->copyfrom_url)
735 entry->copyfrom_url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(pGitStatus->entry->copyfrom_url));
736 entry->copyfrom_rev = pGitStatus->entry->copyfrom_rev;
738 else
739 entry->copyfrom_rev = 0;
741 if(bDirectItem)
743 if (m_sURL.IsEmpty())
744 m_sURL = entry->url;
745 else
746 m_sURL.LoadString(IDS_STATUSLIST_MULTIPLETARGETS);
747 m_StatusUrlList.AddPath(CTGitPath(entry->url));
749 if (pGitStatus->entry->lock_owner)
750 entry->lock_owner = CUnicodeUtils::GetUnicode(pGitStatus->entry->lock_owner);
751 if (pGitStatus->entry->lock_token)
753 entry->lock_token = CUnicodeUtils::GetUnicode(pGitStatus->entry->lock_token);
754 m_bHasLocks = true;
756 if (pGitStatus->entry->lock_comment)
757 entry->lock_comment = CUnicodeUtils::GetUnicode(pGitStatus->entry->lock_comment);
759 if (pGitStatus->entry->present_props)
761 entry->present_props = pGitStatus->entry->present_props;
764 if (pGitStatus->entry->changelist)
766 entry->changelist = CUnicodeUtils::GetUnicode(pGitStatus->entry->changelist);
767 m_changelists[entry->changelist] = -1;
768 m_bHasChangeLists = true;
770 entry->needslock = (pGitStatus->entry->present_props && (strstr(pGitStatus->entry->present_props, "Git:needs-lock")!=NULL) );
772 else
774 if (pGitStatus->ood_kind == Git_node_none)
775 entry->isfolder = path.IsDirectory();
776 else
777 entry->isfolder = (pGitStatus->ood_kind == Git_node_dir);
779 if (pGitStatus->repos_lock)
781 if (pGitStatus->repos_lock->owner)
782 entry->lock_remoteowner = CUnicodeUtils::GetUnicode(pGitStatus->repos_lock->owner);
783 if (pGitStatus->repos_lock->token)
784 entry->lock_remotetoken = CUnicodeUtils::GetUnicode(pGitStatus->repos_lock->token);
785 if (pGitStatus->repos_lock->comment)
786 entry->lock_comment = CUnicodeUtils::GetUnicode(pGitStatus->repos_lock->comment);
789 // Pass ownership of the entry to the array
790 m_arStatusArray.push_back(entry);
792 return entry;
794 #endif
796 void CGitStatusListCtrl::AddUnversionedFolder(const CTGitPath& folderName,
797 const CTGitPath& basePath,
798 GitConfig * config)
800 #if 0
801 if (!m_bUnversionedRecurse)
802 return;
803 CSimpleFileFind filefinder(folderName.GetWinPathString());
805 CTGitPath filename;
806 m_bHasUnversionedItems = TRUE;
807 while (filefinder.FindNextFileNoDots())
809 filename.SetFromWin(filefinder.GetFilePath(), filefinder.IsDirectory());
811 bool bMatchIgnore = !!config->MatchIgnorePattern(filename.GetFileOrDirectoryName());
812 bMatchIgnore = bMatchIgnore || config->MatchIgnorePattern(filename.GetGitPathString());
813 if (((bMatchIgnore)&&(m_bShowIgnores))||(!bMatchIgnore))
815 FileEntry * entry = new FileEntry();
816 entry->path = filename;
817 entry->basepath = basePath;
818 entry->inunversionedfolder = true;
819 entry->isfolder = filefinder.IsDirectory();
821 m_arStatusArray.push_back(entry);
822 if (entry->isfolder)
824 if (!g_GitAdminDir.HasAdminDir(entry->path.GetWinPathString(), true))
825 AddUnversionedFolder(entry->path, basePath, config);
829 #endif
833 void CGitStatusListCtrl::ReadRemainingItemsStatus(GitStatus& status, const CTGitPath& basePath,
834 CStringA& strCurrentRepositoryUUID,
835 CTGitPathList& arExtPaths, GitConfig * config, bool bAllDirect)
837 #if 0
838 git_wc_status2_t * s;
840 CTGitPath lastexternalpath;
841 CTGitPath GitPath;
842 while ((s = status.GetNextFileStatus(GitPath)) != NULL)
844 Git_wc_status_kind wcFileStatus = GitStatus::GetMoreImportant(s->text_status, s->prop_status);
845 if ((wcFileStatus == Git_wc_status_unversioned) && (GitPath.IsDirectory()))
847 // check if the unversioned folder is maybe versioned. This
848 // could happen with nested layouts
849 Git_wc_status_kind st = GitStatus::GetAllStatus(GitPath);
850 if ((st != Git_wc_status_unversioned)&&(st != Git_wc_status_none))
852 FileEntry * entry = new FileEntry();
853 entry->path = GitPath;
854 entry->basepath = basePath;
855 entry->inunversionedfolder = true;
856 entry->isfolder = true;
857 entry->isNested = true;
858 m_arStatusArray.push_back(entry);
859 continue;
862 bool bDirectoryIsExternal = false;
863 bool bEntryfromDifferentRepo = false;
864 if (s->entry)
866 if (s->entry->uuid)
868 if (strCurrentRepositoryUUID.IsEmpty())
869 strCurrentRepositoryUUID = s->entry->uuid;
870 else
872 if (strCurrentRepositoryUUID.Compare(s->entry->uuid)!=0)
874 bEntryfromDifferentRepo = true;
875 if (GitStatus::IsImportant(wcFileStatus))
876 m_bHasExternalsFromDifferentRepos = TRUE;
877 if (s->entry->kind == Git_node_dir)
879 if ((lastexternalpath.IsEmpty())||(!lastexternalpath.IsAncestorOf(GitPath)))
881 arExtPaths.AddPath(GitPath);
882 lastexternalpath = GitPath;
888 else
890 // we don't have an UUID - maybe an added file/folder
891 if (!strCurrentRepositoryUUID.IsEmpty())
893 if ((!lastexternalpath.IsEmpty())&&
894 (lastexternalpath.IsAncestorOf(GitPath)))
896 bEntryfromDifferentRepo = true;
897 m_bHasExternalsFromDifferentRepos = TRUE;
902 else
904 // if unversioned items lie around in external
905 // directories from different repos, we have to mark them
906 // as such too.
907 if (!strCurrentRepositoryUUID.IsEmpty())
909 if ((!lastexternalpath.IsEmpty())&&
910 (lastexternalpath.IsAncestorOf(GitPath)))
912 bEntryfromDifferentRepo = true;
916 if (status.IsExternal(GitPath))
918 arExtPaths.AddPath(GitPath);
919 m_bHasExternals = TRUE;
921 if ((!bEntryfromDifferentRepo)&&(status.IsInExternal(GitPath)))
923 // if the externals are inside an unversioned folder (this happens if
924 // the externals are specified with e.g. "ext\folder url" instead of just
925 // "folder url"), then a commit won't succeed.
926 // therefore, we treat those as if the externals come from a different
927 // repository
928 CTGitPath extpath = GitPath;
929 while (basePath.IsAncestorOf(extpath))
931 if (!extpath.HasAdminDir())
933 bEntryfromDifferentRepo = true;
934 break;
936 extpath = extpath.GetContainingDirectory();
939 // Do we have any external paths?
940 if(arExtPaths.GetCount() > 0)
942 // If do have external paths, we need to check if the current item belongs
943 // to one of them
944 for (int ix=0; ix<arExtPaths.GetCount(); ix++)
946 if (arExtPaths[ix].IsAncestorOf(GitPath))
948 bDirectoryIsExternal = true;
949 break;
954 if ((wcFileStatus == Git_wc_status_unversioned)&&(!bDirectoryIsExternal))
955 m_bHasUnversionedItems = TRUE;
957 const FileEntry* entry = AddNewFileEntry(s, GitPath, basePath, bAllDirect, bDirectoryIsExternal, bEntryfromDifferentRepo);
959 bool bMatchIgnore = !!config->MatchIgnorePattern(entry->path.GetFileOrDirectoryName());
960 bMatchIgnore = bMatchIgnore || config->MatchIgnorePattern(entry->path.GetGitPathString());
961 if ((((wcFileStatus == Git_wc_status_unversioned)||(wcFileStatus == Git_wc_status_none))&&(!bMatchIgnore))||
962 ((wcFileStatus == Git_wc_status_ignored)&&(m_bShowIgnores))||
963 (((wcFileStatus == Git_wc_status_unversioned)||(wcFileStatus == Git_wc_status_none))&&(bMatchIgnore)&&(m_bShowIgnores)))
965 if (entry->isfolder)
967 // we have an unversioned folder -> get all files in it recursively!
968 AddUnversionedFolder(GitPath, basePath, config);
971 } // while ((s = status.GetNextFileStatus(GitPath)) != NULL)
972 #endif
975 // Get the show-flags bitmap value which corresponds to a particular Git status
976 DWORD CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status)
978 switch (status)
980 case git_wc_status_none:
981 case git_wc_status_unversioned:
982 return SVNSLC_SHOWUNVERSIONED;
983 case git_wc_status_ignored:
984 if (!m_bShowIgnores)
985 return SVNSLC_SHOWDIRECTS;
986 return SVNSLC_SHOWDIRECTS|SVNSLC_SHOWIGNORED;
987 case git_wc_status_incomplete:
988 return SVNSLC_SHOWINCOMPLETE;
989 case git_wc_status_normal:
990 return SVNSLC_SHOWNORMAL;
991 case git_wc_status_external:
992 return SVNSLC_SHOWEXTERNAL;
993 case git_wc_status_added:
994 return SVNSLC_SHOWADDED;
995 case git_wc_status_missing:
996 return SVNSLC_SHOWMISSING;
997 case git_wc_status_deleted:
998 return SVNSLC_SHOWREMOVED;
999 case git_wc_status_replaced:
1000 return SVNSLC_SHOWREPLACED;
1001 case git_wc_status_modified:
1002 return SVNSLC_SHOWMODIFIED;
1003 case git_wc_status_merged:
1004 return SVNSLC_SHOWMERGED;
1005 case git_wc_status_conflicted:
1006 return SVNSLC_SHOWCONFLICTED;
1007 case git_wc_status_obstructed:
1008 return SVNSLC_SHOWOBSTRUCTED;
1009 default:
1010 // we should NEVER get here!
1011 ASSERT(FALSE);
1012 break;
1014 return 0;
1017 void CGitStatusListCtrl::Show(DWORD dwShow, DWORD dwCheck /*=0*/, bool bShowFolders /* = true */,BOOL UpdateStatusList)
1019 CWinApp * pApp = AfxGetApp();
1020 if (pApp)
1021 pApp->DoWaitCursor(1);
1023 Locker lock(m_critSec);
1024 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1026 //SetItemCount(listIndex);
1027 SetRedraw(FALSE);
1028 DeleteAllItems();
1029 PrepareGroups();
1030 m_nSelected = 0;
1032 if(UpdateStatusList)
1034 m_arStatusArray.clear();
1035 for(int i=0;i<this->m_StatusFileList.GetCount();i++)
1037 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
1040 for(int i=0;i<this->m_UnRevFileList.GetCount();i++)
1042 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
1045 for(int i=0;i<this->m_IgnoreFileList.GetCount();i++)
1047 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
1050 int index =0;
1051 for(int i=0;i<this->m_arStatusArray.size();i++)
1053 //set default checkbox status
1054 if(((CTGitPath*)m_arStatusArray[i])->m_Action & dwCheck)
1055 ((CTGitPath*)m_arStatusArray[i])->m_Checked=true;
1057 if(((CTGitPath*)m_arStatusArray[i])->m_Action & dwShow)
1059 AddEntry((CTGitPath*)m_arStatusArray[i],langID,index);
1060 index++;
1064 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
1065 for (int col = 0; col <= maxcol; col++)
1066 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
1068 SetRedraw(TRUE);
1069 GetStatisticsString();
1071 CHeaderCtrl * pHeader = GetHeaderCtrl();
1072 HDITEM HeaderItem = {0};
1073 HeaderItem.mask = HDI_FORMAT;
1074 for (int i=0; i<pHeader->GetItemCount(); ++i)
1076 pHeader->GetItem(i, &HeaderItem);
1077 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1078 pHeader->SetItem(i, &HeaderItem);
1080 if (m_nSortedColumn)
1082 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1083 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1084 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1087 #if 0
1088 if (nSelectedEntry)
1090 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
1091 EnsureVisible(nSelectedEntry, false);
1093 else
1095 // Restore the item at the top of the list.
1096 for (int i=0;GetTopIndex() != nTopIndex;i++)
1098 if ( !EnsureVisible(nTopIndex+i,false) )
1100 break;
1104 #endif
1105 if (pApp)
1106 pApp->DoWaitCursor(-1);
1108 Invalidate();
1110 m_dwShow = dwShow;
1112 #if 0
1114 CWinApp * pApp = AfxGetApp();
1115 if (pApp)
1116 pApp->DoWaitCursor(1);
1118 m_bShowFolders = bShowFolders;
1120 int nTopIndex = GetTopIndex();
1121 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
1122 int nSelectedEntry = 0;
1123 if (posSelectedEntry)
1124 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
1125 SetRedraw(FALSE);
1126 DeleteAllItems();
1128 PrepareGroups();
1130 m_arListArray.clear();
1132 m_arListArray.reserve(m_arStatusArray.size());
1133 SetItemCount (static_cast<int>(m_arStatusArray.size()));
1135 int listIndex = 0;
1136 for (size_t i=0; i < m_arStatusArray.size(); ++i)
1138 FileEntry * entry = m_arStatusArray[i];
1139 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
1140 continue;
1141 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
1142 continue;
1143 if (entry->IsFolder() && (!bShowFolders))
1144 continue; // don't show folders if they're not wanted.
1146 #if 0
1147 git_wc_status_kind status = GitStatus::GetMoreImportant(entry->status, entry->remotestatus);
1148 DWORD showFlags = GetShowFlagsFromGitStatus(status);
1149 if (entry->IsLocked())
1150 showFlags |= SVNSLC_SHOWLOCKS;
1151 if (entry->switched)
1152 showFlags |= SVNSLC_SHOWSWITCHED;
1153 if (!entry->changelist.IsEmpty())
1154 showFlags |= SVNSLC_SHOWINCHANGELIST;
1155 #endif
1156 bool bAllowCheck = ((entry->changelist.Compare(SVNSLC_IGNORECHANGELIST) != 0)
1157 && (m_bCheckIfGroupsExist || (m_changelists.size()==0 || (m_changelists.size()==1 && m_bHasIgnoreGroup))));
1159 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
1160 #if 0
1161 if (status != Git_wc_status_ignored || (entry->direct) || (dwShow & GitSLC_SHOWIGNORED))
1163 if ((!entry->IsFolder()) && (status == Git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
1165 if (PathFileExists(entry->GetPath().GetWinPath()))
1167 m_arListArray.push_back(i);
1168 if ((dwCheck & SVNSLC_SHOWREMOVEDANDPRESENT)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
1170 if (bAllowCheck)
1171 entry->checked = true;
1173 AddEntry(entry, langID, listIndex++);
1176 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
1178 m_arListArray.push_back(i);
1179 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
1181 if (bAllowCheck)
1182 entry->checked = true;
1184 AddEntry(entry, langID, listIndex++);
1186 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
1188 m_arListArray.push_back(i);
1189 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
1191 if (bAllowCheck)
1192 entry->checked = true;
1194 AddEntry(entry, langID, listIndex++);
1197 #endif
1200 SetItemCount(listIndex);
1202 m_ColumnManager.UpdateRelevance (m_arStatusArray, m_arListArray);
1204 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
1205 for (int col = 0; col <= maxcol; col++)
1206 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
1208 SetRedraw(TRUE);
1209 GetStatisticsString();
1211 CHeaderCtrl * pHeader = GetHeaderCtrl();
1212 HDITEM HeaderItem = {0};
1213 HeaderItem.mask = HDI_FORMAT;
1214 for (int i=0; i<pHeader->GetItemCount(); ++i)
1216 pHeader->GetItem(i, &HeaderItem);
1217 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1218 pHeader->SetItem(i, &HeaderItem);
1220 if (m_nSortedColumn)
1222 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1223 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1224 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1227 if (nSelectedEntry)
1229 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
1230 EnsureVisible(nSelectedEntry, false);
1232 else
1234 // Restore the item at the top of the list.
1235 for (int i=0;GetTopIndex() != nTopIndex;i++)
1237 if ( !EnsureVisible(nTopIndex+i,false) )
1239 break;
1244 if (pApp)
1245 pApp->DoWaitCursor(-1);
1247 m_bEmpty = (GetItemCount() == 0);
1248 Invalidate();
1249 #endif
1253 void CGitStatusListCtrl::Show(DWORD dwShow, const CTGitPathList& checkedList, bool bShowFolders /* = true */)
1255 return ;
1256 #if 0
1258 Locker lock(m_critSec);
1259 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1261 CWinApp * pApp = AfxGetApp();
1262 if (pApp)
1263 pApp->DoWaitCursor(1);
1264 m_dwShow = dwShow;
1265 m_bShowFolders = bShowFolders;
1266 m_nSelected = 0;
1267 int nTopIndex = GetTopIndex();
1268 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
1269 int nSelectedEntry = 0;
1270 if (posSelectedEntry)
1271 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
1272 SetRedraw(FALSE);
1273 DeleteAllItems();
1275 PrepareGroups();
1277 m_arListArray.clear();
1279 m_arListArray.reserve(m_arStatusArray.size());
1280 SetItemCount (static_cast<int>(m_arStatusArray.size()));
1282 int listIndex = 0;
1283 for (size_t i=0; i < m_arStatusArray.size(); ++i)
1285 FileEntry * entry = m_arStatusArray[i];
1286 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
1287 continue;
1288 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
1289 continue;
1290 if (entry->IsFolder() && (!bShowFolders))
1291 continue; // don't show folders if they're not wanted.
1292 #if 0
1293 git_wc_status_kind status = SVNStatus::GetMoreImportant(entry->status, entry->remotestatus);
1294 DWORD showFlags = GetShowFlagsFromSVNStatus(status);
1295 if (entry->IsLocked())
1296 showFlags |= SVNSLC_SHOWLOCKS;
1297 if (!entry->changelist.IsEmpty())
1298 showFlags |= SVNSLC_SHOWINCHANGELIST;
1300 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
1301 if (status != git_wc_status_ignored || (entry->direct) || (dwShow & SVNSLC_SHOWIGNORED))
1303 for (int npath = 0; npath < checkedList.GetCount(); ++npath)
1305 if (entry->GetPath().IsEquivalentTo(checkedList[npath]))
1307 entry->checked = true;
1308 break;
1311 if ((!entry->IsFolder()) && (status == git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
1313 if (PathFileExists(entry->GetPath().GetWinPath()))
1315 m_arListArray.push_back(i);
1316 AddEntry(entry, langID, listIndex++);
1319 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
1321 m_arListArray.push_back(i);
1322 AddEntry(entry, langID, listIndex++);
1324 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
1326 m_arListArray.push_back(i);
1327 AddEntry(entry, langID, listIndex++);
1329 else if (entry->switched)
1331 m_arListArray.push_back(i);
1332 AddEntry(entry, langID, listIndex++);
1335 #endif
1338 SetItemCount(listIndex);
1340 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
1341 for (int col = 0; col <= maxcol; col++)
1342 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
1344 SetRedraw(TRUE);
1345 GetStatisticsString();
1347 CHeaderCtrl * pHeader = GetHeaderCtrl();
1348 HDITEM HeaderItem = {0};
1349 HeaderItem.mask = HDI_FORMAT;
1350 for (int i=0; i<pHeader->GetItemCount(); ++i)
1352 pHeader->GetItem(i, &HeaderItem);
1353 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1354 pHeader->SetItem(i, &HeaderItem);
1356 if (m_nSortedColumn)
1358 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1359 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1360 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1363 if (nSelectedEntry)
1365 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
1366 EnsureVisible(nSelectedEntry, false);
1368 else
1370 // Restore the item at the top of the list.
1371 for (int i=0;GetTopIndex() != nTopIndex;i++)
1373 if ( !EnsureVisible(nTopIndex+i,false) )
1375 break;
1380 if (pApp)
1381 pApp->DoWaitCursor(-1);
1383 m_bEmpty = (GetItemCount() == 0);
1384 Invalidate();
1385 #endif
1388 int CGitStatusListCtrl::GetColumnIndex(int mask)
1390 int i=0;
1391 for(i=0;i<32;i++)
1392 if(mask&0x1)
1393 return i;
1394 else
1395 mask=mask>>1;
1396 return -1;
1398 void CGitStatusListCtrl::AddEntry(CTGitPath * GitPath, WORD langID, int listIndex)
1400 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
1401 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
1403 CString path = GitPath->GetGitPathString();
1405 m_bBlock = TRUE;
1406 TCHAR buf[100];
1407 int index = listIndex;
1408 int nCol = 1;
1409 CString entryname = GitPath->GetGitPathString();
1410 int icon_idx = 0;
1411 // if (entry->isfolder)
1412 // icon_idx = m_nIconFolder;
1413 // else
1415 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath);
1417 // relative path
1418 CString rename;
1419 rename.Format(_T("(from %s)"),GitPath->GetGitOldPathString());
1420 if(GitPath->m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
1421 entryname+=rename;
1423 InsertItem(index, entryname, icon_idx);
1425 this->SetItemData(index, (DWORD_PTR)GitPath);
1426 // SVNSLC_COLFILENAME
1427 SetItemText(index, nCol++, GitPath->GetFileOrDirectoryName());
1428 // SVNSLC_COLEXT
1429 SetItemText(index, nCol++, GitPath->GetFileExtension());
1430 // SVNSLC_COLSTATUS
1431 SetItemText(index, nCol++, GitPath->GetActionName());
1433 SetItemText(index, GetColumnIndex(SVNSLC_COLADD),GitPath->m_StatAdd);
1434 SetItemText(index, GetColumnIndex(SVNSLC_COLDEL),GitPath->m_StatDel);
1437 SetCheck(index, GitPath->m_Checked);
1438 if (GitPath->m_Checked)
1439 m_nSelected++;
1442 if( GitPath->m_Action & CTGitPath::LOGACTIONS_IGNORE)
1443 SetItemGroup(index, 2);
1444 else if( GitPath->m_Action & CTGitPath::LOGACTIONS_UNVER)
1445 SetItemGroup(index,1);
1446 else
1447 SetItemGroup(index,0);
1448 m_bBlock = FALSE;
1452 #if 0
1453 void CGitStatusListCtrl::AddEntry(FileEntry * entry, WORD langID, int listIndex)
1455 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
1456 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
1458 CString path = entry->GetPath().GetGitPathString();
1459 if ( m_mapFilenameToChecked.size()!=0 && m_mapFilenameToChecked.find(path) != m_mapFilenameToChecked.end() )
1461 // The user manually de-/selected an item. We now restore this status
1462 // when refreshing.
1463 entry->checked = m_mapFilenameToChecked[path];
1466 m_bBlock = TRUE;
1467 TCHAR buf[100];
1468 int index = listIndex;
1469 int nCol = 1;
1470 CString entryname = entry->GetDisplayName();
1471 int icon_idx = 0;
1472 if (entry->isfolder)
1473 icon_idx = m_nIconFolder;
1474 else
1476 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(entry->path);
1478 // relative path
1479 InsertItem(index, entryname, icon_idx);
1480 // SVNSLC_COLFILENAME
1481 SetItemText(index, nCol++, entry->path.GetFileOrDirectoryName());
1482 // SVNSLC_COLEXT
1483 SetItemText(index, nCol++, entry->path.GetFileExtension());
1484 // SVNSLC_COLSTATUS
1485 if (entry->isNested)
1487 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1488 SetItemText(index, nCol++, sTemp);
1490 else
1492 GitStatus::GetStatusString(hResourceHandle, entry->status, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1493 if ((entry->copied)&&(_tcslen(buf)>1))
1494 _tcscat_s(buf, 100, _T(" (+)"));
1495 if ((entry->switched)&&(_tcslen(buf)>1))
1496 _tcscat_s(buf, 100, _T(" (s)"));
1497 #if 0
1498 if ((entry->status == entry->propstatus)&&
1499 (entry->status != git_wc_status_normal)&&
1500 (entry->status != git_wc_status_unversioned)&&
1501 (!GitStatus::IsImportant(entry->textstatus)))
1502 _tcscat_s(buf, 100, ponly);
1503 #endif
1504 SetItemText(index, nCol++, buf);
1506 // SVNSLC_COLREMOTESTATUS
1507 if (entry->isNested)
1509 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1510 SetItemText(index, nCol++, sTemp);
1512 else
1514 #if 0
1515 SVNStatus::GetStatusString(hResourceHandle, entry->remotestatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1516 if ((entry->copied)&&(_tcslen(buf)>1))
1517 _tcscat_s(buf, 100, _T(" (+)"));
1518 if ((entry->switched)&&(_tcslen(buf)>1))
1519 _tcscat_s(buf, 100, _T(" (s)"));
1520 if ((entry->remotestatus == entry->remotepropstatus)&&
1521 (entry->remotestatus != git_wc_status_none)&&
1522 (entry->remotestatus != git_wc_status_normal)&&
1523 (entry->remotestatus != git_wc_status_unversioned)&&
1524 (!SVNStatus::IsImportant(entry->remotetextstatus)))
1525 _tcscat_s(buf, 100, ponly);
1526 #endif
1527 SetItemText(index, nCol++, buf);
1529 // SVNSLC_COLTEXTSTATUS
1530 if (entry->isNested)
1532 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1533 SetItemText(index, nCol++, sTemp);
1535 else
1537 #if 0
1538 SVNStatus::GetStatusString(hResourceHandle, entry->textstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1539 if ((entry->copied)&&(_tcslen(buf)>1))
1540 _tcscat_s(buf, 100, _T(" (+)"));
1541 if ((entry->switched)&&(_tcslen(buf)>1))
1542 _tcscat_s(buf, 100, _T(" (s)"));
1543 #endif
1544 SetItemText(index, nCol++, buf);
1546 // SVNSLC_COLPROPSTATUS
1547 if (entry->isNested)
1549 SetItemText(index, nCol++, _T(""));
1551 else
1553 #if 0
1554 SVNStatus::GetStatusString(hResourceHandle, entry->propstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1555 if ((entry->copied)&&(_tcslen(buf)>1))
1556 _tcscat_s(buf, 100, _T(" (+)"));
1557 if ((entry->switched)&&(_tcslen(buf)>1))
1558 _tcscat_s(buf, 100, _T(" (s)"));
1559 #endif
1560 SetItemText(index, nCol++, buf);
1562 // SVNSLC_COLREMOTETEXT
1563 if (entry->isNested)
1565 SetItemText(index, nCol++, _T(""));
1567 else
1569 #if 0
1570 SVNStatus::GetStatusString(hResourceHandle, entry->remotetextstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1571 SetItemText(index, nCol++, buf);
1572 #endif
1574 // SVNSLC_COLREMOTEPROP
1575 if (entry->isNested)
1577 SetItemText(index, nCol++, _T(""));
1579 else
1581 // SVNStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1582 SetItemText(index, nCol++, buf);
1584 // SVNSLC_COLURL
1585 // SetItemText(index, nCol++, entry->url);
1586 // SVNSLC_COLLOCK
1587 #if 0
1588 if (!m_HeadRev.IsHead())
1590 // we have contacted the repository
1592 // decision-matrix
1593 // wc repository text
1594 // "" "" ""
1595 // "" UID1 owner
1596 // UID1 UID1 owner
1597 // UID1 "" lock has been broken
1598 // UID1 UID2 lock has been stolen
1599 if (entry->lock_token.IsEmpty() || (entry->lock_token.Compare(entry->lock_remotetoken)==0))
1601 if (entry->lock_owner.IsEmpty())
1602 SetItemText(index, nCol++, entry->lock_remoteowner);
1603 else
1604 SetItemText(index, nCol++, entry->lock_owner);
1606 else if (entry->lock_remotetoken.IsEmpty())
1608 // broken lock
1609 CString temp(MAKEINTRESOURCE(IDS_STATUSLIST_LOCKBROKEN));
1610 SetItemText(index, nCol++, temp);
1612 else
1614 // stolen lock
1615 CString temp;
1616 temp.Format(IDS_STATUSLIST_LOCKSTOLEN, (LPCTSTR)entry->lock_remoteowner);
1617 SetItemText(index, nCol++, temp);
1620 else
1621 SetItemText(index, nCol++, entry->lock_owner);
1622 // SVNSLC_COLLOCKCOMMENT
1623 SetItemText(index, nCol++, entry->lock_comment);
1624 // SVNSLC_COLAUTHOR
1625 SetItemText(index, nCol++, entry->last_commit_author);
1626 // SVNSLC_COLREVISION
1627 CString temp;
1628 temp.Format(_T("%ld"), entry->last_commit_rev);
1629 if (entry->last_commit_rev > 0)
1630 SetItemText(index, nCol++, temp);
1631 else
1632 SetItemText(index, nCol++, _T(""));
1633 // SVNSLC_COLREMOTEREVISION
1634 temp.Format(_T("%ld"), entry->remoterev);
1635 if (entry->remoterev > 0)
1636 SetItemText(index, nCol++, temp);
1637 else
1638 SetItemText(index, nCol++, _T(""));
1639 // SVNSLC_COLDATE
1640 TCHAR datebuf[SVN_DATE_BUFFER];
1641 apr_time_t date = entry->last_commit_date;
1642 SVN::formatDate(datebuf, date, true);
1643 if (date)
1644 SetItemText(index, nCol++, datebuf);
1645 else
1646 SetItemText(index, nCol++, _T(""));
1647 // SVNSLC_COLSVNNEEDSLOCK
1648 BOOL bFoundSVNNeedsLock = entry->present_props.IsNeedsLockSet();
1649 CString strSVNNeedsLock = (bFoundSVNNeedsLock) ? _T("*") : _T("");
1650 SetItemText(index, nCol++, strSVNNeedsLock);
1651 // SVNSLC_COLCOPYFROM
1652 if (m_sURL.Compare(entry->copyfrom_url.Left(m_sURL.GetLength()))==0)
1653 temp = entry->copyfrom_url.Mid(m_sURL.GetLength());
1654 else
1655 temp = entry->copyfrom_url;
1656 SetItemText(index, nCol++, temp);
1657 // SVNSLC_COLMODIFICATIONDATE
1658 __int64 filetime = entry->GetPath().GetLastWriteTime();
1659 if ( (filetime) && (entry->status!=git_wc_status_deleted) )
1661 FILETIME* f = (FILETIME*)(__int64*)&filetime;
1662 TCHAR datebuf[SVN_DATE_BUFFER];
1663 SVN::formatDate(datebuf,*f,true);
1664 SetItemText(index, nCol++, datebuf);
1666 else
1668 SetItemText(index, nCol++, _T(""));
1671 // user-defined properties
1672 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
1673 ; i < count
1674 ; ++i)
1676 assert (i == nCol++);
1677 assert (m_ColumnManager.IsUserProp (i));
1679 CString name = m_ColumnManager.GetName(i);
1680 if (entry->present_props.HasProperty (name))
1682 const CString& propVal = entry->present_props [name];
1683 if (propVal.IsEmpty())
1684 SetItemText(index, i, m_sNoPropValueText);
1685 else
1686 SetItemText(index, i, propVal);
1688 else
1689 SetItemText(index, i, _T(""));
1692 SetCheck(index, entry->checked);
1693 if (entry->checked)
1694 m_nSelected++;
1695 if (m_changelists.find(entry->changelist) != m_changelists.end())
1696 SetItemGroup(index, m_changelists[entry->changelist]);
1697 else
1698 SetItemGroup(index, 0);
1699 m_bBlock = FALSE;
1700 #endif
1702 #endif
1703 bool CGitStatusListCtrl::SetItemGroup(int item, int groupindex)
1705 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1706 // return false;
1707 if (groupindex < 0)
1708 return false;
1709 LVITEM i = {0};
1710 i.mask = LVIF_GROUPID;
1711 i.iItem = item;
1712 i.iSubItem = 0;
1713 i.iGroupId = groupindex;
1715 return !!SetItem(&i);
1718 void CGitStatusListCtrl::Sort()
1720 Locker lock(m_critSec);
1722 CSorter predicate (&m_ColumnManager, m_nSortedColumn, m_bAscending);
1724 std::sort(m_arStatusArray.begin(), m_arStatusArray.end(), predicate);
1725 SaveColumnWidths();
1726 Show(m_dwShow, 0, m_bShowFolders);
1730 void CGitStatusListCtrl::OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult)
1732 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1733 *pResult = 0;
1734 if (m_bBlock)
1735 return;
1736 m_bBlock = TRUE;
1737 if (m_nSortedColumn == phdr->iItem)
1738 m_bAscending = !m_bAscending;
1739 else
1740 m_bAscending = TRUE;
1741 m_nSortedColumn = phdr->iItem;
1742 m_mapFilenameToChecked.clear();
1743 Sort();
1745 CHeaderCtrl * pHeader = GetHeaderCtrl();
1746 HDITEM HeaderItem = {0};
1747 HeaderItem.mask = HDI_FORMAT;
1748 for (int i=0; i<pHeader->GetItemCount(); ++i)
1750 pHeader->GetItem(i, &HeaderItem);
1751 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1752 pHeader->SetItem(i, &HeaderItem);
1754 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1755 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1756 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1758 // the checked state of the list control items must be restored
1760 for (int i=0; i<GetItemCount(); ++i)
1762 CTGitPath * entry = (CTGitPath*)GetItemData(i);
1763 ASSERT(entry);
1764 if(entry)
1765 SetCheck(i, entry->m_Checked);
1768 m_bBlock = FALSE;
1771 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
1773 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1774 *pResult = 0;
1776 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1777 if ((m_bBlock)&&(m_bBlockUI))
1779 // if we're blocked, prevent changing of the check state
1780 if ((!ISCHECKED(pNMLV->uOldState) && ISCHECKED(pNMLV->uNewState))||
1781 (ISCHECKED(pNMLV->uOldState) && !ISCHECKED(pNMLV->uNewState)))
1782 *pResult = TRUE;
1786 BOOL CGitStatusListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
1788 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1789 *pResult = 0;
1790 if ((pNMLV->uNewState==0)||(pNMLV->uNewState & LVIS_SELECTED)||(pNMLV->uNewState & LVIS_FOCUSED))
1791 return FALSE;
1793 if (m_bBlock)
1794 return FALSE;
1796 bool bSelected = !!(ListView_GetItemState(m_hWnd, pNMLV->iItem, LVIS_SELECTED) & LVIS_SELECTED);
1797 int nListItems = GetItemCount();
1799 m_bBlock = TRUE;
1800 // was the item checked?
1802 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1803 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1805 if (GetCheck(pNMLV->iItem))
1807 CheckEntry(pNMLV->iItem, nListItems);
1808 if (bSelected)
1810 POSITION pos = GetFirstSelectedItemPosition();
1811 int index;
1812 while ((index = GetNextSelectedItem(pos)) >= 0)
1814 if (index != pNMLV->iItem)
1815 CheckEntry(index, nListItems);
1819 else
1821 UncheckEntry(pNMLV->iItem, nListItems);
1822 if (bSelected)
1824 POSITION pos = GetFirstSelectedItemPosition();
1825 int index;
1826 while ((index = GetNextSelectedItem(pos)) >= 0)
1828 if (index != pNMLV->iItem)
1829 UncheckEntry(index, nListItems);
1834 GetStatisticsString();
1835 m_bBlock = FALSE;
1836 NotifyCheck();
1838 return FALSE;
1841 void CGitStatusListCtrl::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
1843 LPNMHEADER header = reinterpret_cast<LPNMHEADER>(pNMHDR);
1844 if ( (header != NULL)
1845 && (header->iItem >= 0)
1846 && (header->iItem < m_ColumnManager.GetColumnCount()))
1848 m_ColumnManager.ColumnResized (header->iItem);
1851 *pResult = FALSE;
1854 void CGitStatusListCtrl::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
1856 LPNMHEADER header = reinterpret_cast<LPNMHEADER>(pNMHDR);
1857 *pResult = TRUE;
1858 if ( (header != NULL)
1859 && (header->iItem >= 0)
1860 && (header->iItem < m_ColumnManager.GetColumnCount())
1861 // only allow the reordering if the column was not moved left of the first
1862 // visible item - otherwise the 'invisible' columns are not at the far left
1863 // anymore and we get all kinds of redrawing problems.
1864 && (header->pitem)
1865 && (header->pitem->iOrder > m_ColumnManager.GetInvisibleCount()))
1867 m_ColumnManager.ColumnMoved (header->iItem, header->pitem->iOrder);
1868 *pResult = FALSE;
1871 Invalidate(FALSE);
1874 void CGitStatusListCtrl::CheckEntry(int index, int nListItems)
1876 Locker lock(m_critSec);
1877 //FileEntry * entry = GetListEntry(index);
1878 CTGitPath *path=(CTGitPath*)GetItemData(index);
1879 ASSERT(path != NULL);
1880 if (path == NULL)
1881 return;
1882 SetCheck(index, TRUE);
1883 //entry = GetListEntry(index);
1884 // if an unversioned item was checked, then we need to check if
1885 // the parent folders are unversioned too. If the parent folders actually
1886 // are unversioned, then check those too.
1887 #if 0
1888 if (entry->status == git_wc_status_unversioned)
1890 // we need to check the parent folder too
1891 const CTGitPath& folderpath = entry->path;
1892 for (int i=0; i< nListItems; ++i)
1894 FileEntry * testEntry = GetListEntry(i);
1895 ASSERT(testEntry != NULL);
1896 if (testEntry == NULL)
1897 continue;
1898 if (!testEntry->checked)
1900 if (testEntry->path.IsAncestorOf(folderpath) && (!testEntry->path.IsEquivalentTo(folderpath)))
1902 SetEntryCheck(testEntry,i,true);
1903 m_nSelected++;
1908 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1909 if ( (entry->status == git_wc_status_deleted) || (m_bCheckChildrenWithParent) || (bShift) )
1911 // if a deleted folder gets checked, we have to check all
1912 // children of that folder too.
1913 if (entry->path.IsDirectory())
1915 SetCheckOnAllDescendentsOf(entry, true);
1918 // if a deleted file or folder gets checked, we have to
1919 // check all parents of this item too.
1920 for (int i=0; i<nListItems; ++i)
1922 FileEntry * testEntry = GetListEntry(i);
1923 ASSERT(testEntry != NULL);
1924 if (testEntry == NULL)
1925 continue;
1926 if (!testEntry->checked)
1928 if (testEntry->path.IsAncestorOf(entry->path) && (!testEntry->path.IsEquivalentTo(entry->path)))
1930 if ((testEntry->status == git_wc_status_deleted)||(m_bCheckChildrenWithParent))
1932 SetEntryCheck(testEntry,i,true);
1933 m_nSelected++;
1934 // now we need to check all children of this parent folder
1935 SetCheckOnAllDescendentsOf(testEntry, true);
1941 #endif
1942 if ( !path->m_Checked )
1944 path->m_Checked = TRUE;
1945 m_nSelected++;
1949 void CGitStatusListCtrl::UncheckEntry(int index, int nListItems)
1951 Locker lock(m_critSec);
1952 CTGitPath *path=(CTGitPath*)GetItemData(index);
1953 ASSERT(path != NULL);
1954 if (path == NULL)
1955 return;
1956 SetCheck(index, FALSE);
1957 //entry = GetListEntry(index);
1958 // item was unchecked
1959 #if 0
1960 if (entry->path.IsDirectory())
1962 // disable all files within an unselected folder, except when unchecking a folder with property changes
1963 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1964 if ( (entry->status != git_wc_status_modified) || (bShift) )
1966 SetCheckOnAllDescendentsOf(entry, false);
1969 else if (entry->status == git_wc_status_deleted)
1971 // a "deleted" file was unchecked, so uncheck all parent folders
1972 // and all children of those parents
1973 for (int i=0; i<nListItems; i++)
1975 FileEntry * testEntry = GetListEntry(i);
1976 ASSERT(testEntry != NULL);
1977 if (testEntry == NULL)
1978 continue;
1979 if (testEntry->checked)
1981 if (testEntry->path.IsAncestorOf(entry->path))
1983 if (testEntry->status == git_wc_status_deleted)
1985 SetEntryCheck(testEntry,i,false);
1986 m_nSelected--;
1988 SetCheckOnAllDescendentsOf(testEntry, false);
1994 #endif
1995 if ( path->m_Checked )
1997 path->m_Checked = FALSE;
1998 m_nSelected--;
2001 #if 0
2002 bool CGitStatusListCtrl::EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2)
2004 return pEntry1->path < pEntry2->path;
2007 bool CGitStatusListCtrl::IsEntryVersioned(const FileEntry* pEntry1)
2009 return pEntry1->status != git_wc_status_unversioned;
2011 #endif
2012 bool CGitStatusListCtrl::BuildStatistics()
2015 bool bRefetchStatus = false;
2017 // now gather some statistics
2018 m_nUnversioned = 0;
2019 m_nNormal = 0;
2020 m_nModified = 0;
2021 m_nAdded = 0;
2022 m_nDeleted = 0;
2023 m_nConflicted = 0;
2024 m_nTotal = 0;
2025 m_nSelected = 0;
2027 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
2029 int status=((CTGitPath*)m_arStatusArray[i])->m_Action;
2031 if(status&(CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
2032 m_nAdded++;
2034 if(status&CTGitPath::LOGACTIONS_DELETED)
2035 m_nDeleted++;
2037 if(status&(CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_MODIFIED))
2038 m_nModified++;
2040 if(status&CTGitPath::LOGACTIONS_UNMERGED)
2041 m_nConflicted++;
2043 if(status&(CTGitPath::LOGACTIONS_IGNORE|CTGitPath::LOGACTIONS_UNVER))
2044 m_nUnversioned++;
2048 // } // switch (entry->status)
2049 // } // if (entry)
2050 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
2051 return !bRefetchStatus;
2053 return FALSE;
2056 void CGitStatusListCtrl::GetMinMaxRevisions(git_revnum_t& rMin, git_revnum_t& rMax, bool bShownOnly, bool bCheckedOnly)
2058 #if 0
2059 Locker lock(m_critSec);
2060 rMin = LONG_MAX;
2061 rMax = 0;
2063 if ((bShownOnly)||(bCheckedOnly))
2065 for (int i=0; i<GetItemCount(); ++i)
2067 const FileEntry * entry = GetListEntry(i);
2069 if ((entry)&&(entry->last_commit_rev))
2071 if ((!bCheckedOnly)||(entry->IsChecked()))
2073 if (entry->last_commit_rev >= 0)
2075 rMin = min(rMin, entry->last_commit_rev);
2076 rMax = max(rMax, entry->last_commit_rev);
2082 else
2084 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
2086 const FileEntry * entry = m_arStatusArray[i];
2087 if ((entry)&&(entry->last_commit_rev))
2089 if (entry->last_commit_rev >= 0)
2091 rMin = min(rMin, entry->last_commit_rev);
2092 rMax = max(rMax, entry->last_commit_rev);
2097 if (rMin == LONG_MAX)
2098 rMin = 0;
2099 #endif
2102 int CGitStatusListCtrl::GetGroupFromPoint(POINT * ppt)
2104 // the point must be relative to the upper left corner of the control
2106 if (ppt == NULL)
2107 return -1;
2108 if (!IsGroupViewEnabled())
2109 return -1;
2111 POINT pt = *ppt;
2112 pt.x = 10;
2113 UINT flags = 0;
2114 int nItem = -1;
2115 RECT rc;
2116 GetWindowRect(&rc);
2117 while (((flags & LVHT_BELOW) == 0)&&(pt.y < rc.bottom))
2119 nItem = HitTest(pt, &flags);
2120 if ((flags & LVHT_ONITEM)||(flags & LVHT_EX_GROUP_HEADER))
2122 // the first item below the point
2124 // check if the point is too much right (i.e. if the point
2125 // is farther to the right than the width of the item)
2126 RECT r;
2127 GetItemRect(nItem, &r, LVIR_LABEL);
2128 if (ppt->x > r.right)
2129 return -1;
2131 LVITEM lv = {0};
2132 lv.mask = LVIF_GROUPID;
2133 lv.iItem = nItem;
2134 GetItem(&lv);
2135 int groupID = lv.iGroupId;
2136 // now we search upwards and check if the item above this one
2137 // belongs to another group. If it belongs to the same group,
2138 // we're not over a group header
2139 while (pt.y >= 0)
2141 pt.y -= 2;
2142 nItem = HitTest(pt, &flags);
2143 if ((flags & LVHT_ONITEM)&&(nItem >= 0))
2145 // the first item below the point
2146 LVITEM lv = {0};
2147 lv.mask = LVIF_GROUPID;
2148 lv.iItem = nItem;
2149 GetItem(&lv);
2150 if (lv.iGroupId != groupID)
2151 return groupID;
2152 else
2153 return -1;
2156 if (pt.y < 0)
2157 return groupID;
2158 return -1;
2160 pt.y += 2;
2162 return -1;
2165 void CGitStatusListCtrl::OnContextMenuGroup(CWnd * /*pWnd*/, CPoint point)
2167 POINT clientpoint = point;
2168 ScreenToClient(&clientpoint);
2169 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint) >= 0))
2171 CMenu popup;
2172 if (popup.CreatePopupMenu())
2174 CString temp;
2175 temp.LoadString(IDS_STATUSLIST_CHECKGROUP);
2176 popup.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CHECKGROUP, temp);
2177 temp.LoadString(IDS_STATUSLIST_UNCHECKGROUP);
2178 popup.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_UNCHECKGROUP, temp);
2179 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2180 bool bCheck = false;
2181 switch (cmd)
2183 case IDSVNLC_CHECKGROUP:
2184 bCheck = true;
2185 // fall through here
2186 case IDSVNLC_UNCHECKGROUP:
2188 int group = GetGroupFromPoint(&clientpoint);
2189 // go through all items and check/uncheck those assigned to the group
2190 // but block the OnLvnItemChanged handler
2191 m_bBlock = true;
2192 LVITEM lv;
2193 for (int i=0; i<GetItemCount(); ++i)
2195 SecureZeroMemory(&lv, sizeof(LVITEM));
2196 lv.mask = LVIF_GROUPID;
2197 lv.iItem = i;
2198 GetItem(&lv);
2200 if (lv.iGroupId == group)
2202 CTGitPath * entry = (CTGitPath*)GetItemData(i);
2203 if (entry)
2205 bool bOldCheck = entry->m_Checked;
2206 SetEntryCheck(entry, i, bCheck);
2207 if (bCheck != bOldCheck)
2209 if (bCheck)
2210 m_nSelected++;
2211 else
2212 m_nSelected--;
2218 GetStatisticsString();
2219 NotifyCheck();
2220 m_bBlock = false;
2222 break;
2228 void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point)
2231 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
2233 bool XPorLater = false;
2234 OSVERSIONINFOEX inf;
2235 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
2236 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
2237 GetVersionEx((OSVERSIONINFO *)&inf);
2238 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
2239 if (fullver >= 0x0501)
2240 XPorLater = true;
2241 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
2242 CTGitPath * filepath;
2244 int selIndex = GetSelectionMark();
2245 if ((point.x == -1) && (point.y == -1))
2247 CRect rect;
2248 GetItemRect(selIndex, &rect, LVIR_LABEL);
2249 ClientToScreen(&rect);
2250 point = rect.CenterPoint();
2252 if ((GetSelectedCount() == 0)&&(XPorLater)&&(m_bHasCheckboxes))
2254 // nothing selected could mean the context menu is requested for
2255 // a group header
2256 OnContextMenuGroup(pWnd, point);
2258 else if (selIndex >= 0)
2260 //FileEntry * entry = GetListEntry(selIndex);
2262 filepath = (CTGitPath * )GetItemData(selIndex);
2264 ASSERT(filepath != NULL);
2265 if (filepath == NULL)
2266 return;
2268 //const CTGitPath& filepath = entry->path;
2269 int wcStatus = filepath->m_Action;
2270 // entry is selected, now show the popup menu
2271 Locker lock(m_critSec);
2272 CIconMenu popup;
2273 CMenu changelistSubMenu;
2274 CMenu ignoreSubMenu;
2275 if (popup.CreatePopupMenu())
2277 //Add Menu for verion controled file
2279 if (wcStatus & CTGitPath::LOGACTIONS_UNMERGED)
2281 if ((m_dwContextMenus & SVNSLC_POPCONFLICT)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
2283 popup.AppendMenuIcon(IDSVNLC_EDITCONFLICT, IDS_MENUCONFLICT, IDI_CONFLICT);
2285 if (m_dwContextMenus & SVNSLC_POPRESOLVE)
2287 popup.AppendMenuIcon(IDSVNLC_RESOLVECONFLICT, IDS_STATUSLIST_CONTEXT_RESOLVED, IDI_RESOLVE);
2289 if ((m_dwContextMenus & SVNSLC_POPRESOLVE)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
2291 //popup.AppendMenuIcon(IDSVNLC_RESOLVETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS, IDI_RESOLVE);
2292 //popup.AppendMenuIcon(IDSVNLC_RESOLVEMINE, IDS_SVNPROGRESS_MENUUSEMINE, IDI_RESOLVE);
2294 if ((m_dwContextMenus & SVNSLC_POPCONFLICT)||(m_dwContextMenus & SVNSLC_POPRESOLVE))
2295 popup.AppendMenu(MF_SEPARATOR);
2298 if (!(wcStatus &CTGitPath::LOGACTIONS_UNVER))
2300 if (m_dwContextMenus & SVNSLC_POPCOMPAREWITHBASE)
2302 popup.AppendMenuIcon(IDSVNLC_COMPARE, IDS_LOG_COMPAREWITHBASE, IDI_DIFF);
2303 popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
2306 if (m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_COMPAREWC))
2308 if( (!m_CurrentVersion.IsEmpty()) && m_CurrentVersion != GIT_REV_ZERO)
2309 popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
2311 //Select one items
2312 if (GetSelectedCount() == 1)
2314 bool bEntryAdded = false;
2315 //if (entry->remotestatus <= git_wc_status_normal)
2317 // if (wcStatus > git_wc_status_normal)
2318 // {
2319 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
2320 // {
2321 if(!g_Git.IsInitRepos())
2322 popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2324 bEntryAdded = true;
2325 // }
2326 // }
2329 //else if (wcStatus != git_wc_status_deleted)
2331 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
2332 // {
2333 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
2334 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
2335 // bEntryAdded = true;
2336 // }
2337 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
2338 // {
2339 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2340 // bEntryAdded = true;
2341 // }
2343 if (bEntryAdded)
2344 popup.AppendMenu(MF_SEPARATOR);
2346 //else if (GetSelectedCount() > 1)
2348 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
2349 // {
2350 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
2351 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
2352 // }
2357 ///Select Multi item
2358 //if (GetSelectedCount() > 0)
2360 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
2361 // {
2362 // POSITION pos = GetFirstSelectedItemPosition();
2363 // int index = GetNextSelectedItem(pos);
2364 // if (index >= 0)
2365 // {
2366 // FileEntry * entry = GetListEntry(index);
2367 // git_wc_status_kind status1 = git_wc_status_none;
2368 // git_wc_status_kind status2 = git_wc_status_none;
2369 // if (entry)
2370 // status1 = entry->status;
2371 // index = GetNextSelectedItem(pos);
2372 // if (index >= 0)
2373 // {
2374 // entry = GetListEntry(index);
2375 // if (entry)
2376 // status2 = entry->status;
2377 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
2378 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
2379 // {
2380 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
2381 // }
2382 // }
2383 // }
2384 // }
2385 // if (wcStatus > git_wc_status_normal)
2386 // {
2387 // if (m_dwContextMenus & SVNSLC_POPREVERT)
2388 // {
2389 // // reverting missing folders is not possible
2390 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
2391 // {
2392 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
2393 // }
2394 // }
2395 // }
2396 // if (entry->remotestatus > git_wc_status_normal)
2397 // {
2398 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
2399 // {
2400 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
2401 // }
2402 // }
2405 if ( (GetSelectedCount() >0 ) && (!(wcStatus & CTGitPath::LOGACTIONS_UNVER)))
2407 if (m_dwContextMenus & SVNSLC_POPREVERT)
2409 popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
2412 if ((m_dwContextMenus & GetContextMenuBit(IDSVNLC_REVERTTOREV)) && ( !this->m_CurrentVersion.IsEmpty() )
2413 && this->m_CurrentVersion != GIT_REV_ZERO)
2415 popup.AppendMenuIcon(IDSVNLC_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2419 if ((GetSelectedCount() == 1)&&(!(wcStatus & CTGitPath::LOGACTIONS_UNVER))
2420 &&(!(wcStatus & CTGitPath::LOGACTIONS_IGNORE)))
2422 if (m_dwContextMenus & SVNSLC_POPSHOWLOG)
2424 popup.AppendMenuIcon(IDSVNLC_LOG, IDS_REPOBROWSE_SHOWLOG, IDI_LOG);
2426 if (m_dwContextMenus & SVNSLC_POPBLAME)
2428 popup.AppendMenuIcon(IDSVNLC_BLAME, IDS_MENUBLAME, IDI_BLAME);
2431 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
2432 if ( (GetSelectedCount() == 1) )
2434 if (m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_SAVEAS) )
2436 popup.AppendMenuIcon(IDSVNLC_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2439 if (m_dwContextMenus & SVNSLC_POPOPEN)
2441 popup.AppendMenuIcon(IDSVNLC_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2442 popup.AppendMenuIcon(IDSVNLC_OPEN, IDS_REPOBROWSE_OPEN, IDI_OPEN);
2443 popup.AppendMenuIcon(IDSVNLC_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2446 if (m_dwContextMenus & SVNSLC_POPEXPLORE)
2448 popup.AppendMenuIcon(IDSVNLC_EXPLORE, IDS_STATUSLIST_CONTEXT_EXPLORE, IDI_EXPLORER);
2452 if (GetSelectedCount() > 0)
2454 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
2455 // {
2456 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2457 // }
2458 // 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))
2459 // {
2460 // if (bShift)
2461 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
2462 // else
2463 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
2464 // }
2465 if ((wcStatus & CTGitPath::LOGACTIONS_UNVER)/*||(wcStatus == git_wc_status_deleted)*/)
2467 if (m_dwContextMenus & SVNSLC_POPADD)
2469 //if ( entry->IsFolder() )
2471 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
2473 //else
2475 popup.AppendMenuIcon(IDSVNLC_ADD, IDS_STATUSLIST_CONTEXT_ADD, IDI_ADD);
2479 //if ( (wcStatus == git_wc_status_unversioned) || (wcStatus == git_wc_status_deleted) )
2481 if (m_dwContextMenus & SVNSLC_POPIGNORE)
2484 CTGitPathList ignorelist;
2485 FillListOfSelectedItemPaths(ignorelist);
2486 //check if all selected entries have the same extension
2487 bool bSameExt = true;
2488 CString sExt;
2489 for (int i=0; i<ignorelist.GetCount(); ++i)
2491 if (sExt.IsEmpty() && (i==0))
2492 sExt = ignorelist[i].GetFileExtension();
2493 else if (sExt.CompareNoCase(ignorelist[i].GetFileExtension())!=0)
2494 bSameExt = false;
2496 if (bSameExt)
2498 if (ignoreSubMenu.CreateMenu())
2500 CString ignorepath;
2501 if (ignorelist.GetCount()==1)
2502 ignorepath = ignorelist[0].GetFileOrDirectoryName();
2503 else
2504 ignorepath.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2505 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_IGNORE, ignorepath);
2506 ignorepath = _T("*")+sExt;
2507 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_IGNOREMASK, ignorepath);
2508 CString temp;
2509 temp.LoadString(IDS_MENUIGNORE);
2510 popup.InsertMenu((UINT)-1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)ignoreSubMenu.m_hMenu, temp);
2513 else
2515 CString temp;
2516 if (ignorelist.GetCount()==1)
2518 temp.LoadString(IDS_MENUIGNORE);
2520 else
2522 temp.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2524 popup.AppendMenuIcon(IDSVNLC_IGNORE, temp, IDI_IGNORE);
2532 if (GetSelectedCount() > 0)
2534 #if 0
2535 if ((!entry->IsFolder())&&(wcStatus >= git_wc_status_normal)
2536 &&(wcStatus!=git_wc_status_missing)&&(wcStatus!=git_wc_status_deleted)
2537 &&(wcStatus!=git_wc_status_added))
2539 popup.AppendMenu(MF_SEPARATOR);
2540 if ((entry->lock_token.IsEmpty())&&(!entry->IsFolder()))
2542 if (m_dwContextMenus & SVNSLC_POPLOCK)
2544 popup.AppendMenuIcon(IDSVNLC_LOCK, IDS_MENU_LOCK, IDI_LOCK);
2547 if ((!entry->lock_token.IsEmpty())&&(!entry->IsFolder()))
2549 if (m_dwContextMenus & SVNSLC_POPUNLOCK)
2551 popup.AppendMenuIcon(IDSVNLC_UNLOCK, IDS_MENU_UNLOCK, IDI_UNLOCK);
2556 if ((!entry->IsFolder())&&((!entry->lock_token.IsEmpty())||(!entry->lock_remotetoken.IsEmpty())))
2558 if (m_dwContextMenus & SVNSLC_POPUNLOCKFORCE)
2560 popup.AppendMenuIcon(IDSVNLC_UNLOCKFORCE, IDS_MENU_UNLOCKFORCE, IDI_UNLOCK);
2564 if (wcStatus != git_wc_status_missing && wcStatus != git_wc_status_deleted &&wcStatus!=git_wc_status_unversioned)
2566 popup.AppendMenu(MF_SEPARATOR);
2567 popup.AppendMenuIcon(IDSVNLC_PROPERTIES, IDS_STATUSLIST_CONTEXT_PROPERTIES, IDI_PROPERTIES);
2569 #endif
2570 popup.AppendMenu(MF_SEPARATOR);
2571 popup.AppendMenuIcon(IDSVNLC_COPY, IDS_STATUSLIST_CONTEXT_COPY, IDI_COPYCLIP);
2572 popup.AppendMenuIcon(IDSVNLC_COPYEXT, IDS_STATUSLIST_CONTEXT_COPYEXT, IDI_COPYCLIP);
2573 #if 0
2574 if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS)&&(XPorLater)
2575 &&(wcStatus != git_wc_status_unversioned)&&(wcStatus != git_wc_status_none))
2577 popup.AppendMenu(MF_SEPARATOR);
2578 // changelist commands
2579 size_t numChangelists = GetNumberOfChangelistsInSelection();
2580 if (numChangelists > 0)
2582 popup.AppendMenuIcon(IDSVNLC_REMOVEFROMCS, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS);
2584 if ((!entry->IsFolder())&&(changelistSubMenu.CreateMenu()))
2586 CString temp;
2587 temp.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS);
2588 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATECS, temp);
2590 if (entry->changelist.Compare(SVNSLC_IGNORECHANGELIST))
2592 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2593 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATEIGNORECS, SVNSLC_IGNORECHANGELIST);
2596 if (m_changelists.size() > 0)
2598 // find the changelist names
2599 bool bNeedSeparator = true;
2600 int cmdID = IDSVNLC_MOVETOCS;
2601 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
2603 if ((entry->changelist.Compare(it->first))&&(it->first.Compare(SVNSLC_IGNORECHANGELIST)))
2605 if (bNeedSeparator)
2607 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2608 bNeedSeparator = false;
2610 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, cmdID, it->first);
2611 cmdID++;
2615 temp.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS);
2616 popup.AppendMenu(MF_POPUP|MF_STRING, (UINT_PTR)changelistSubMenu.GetSafeHmenu(), temp);
2619 #endif
2622 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2624 m_bBlock = TRUE;
2625 AfxGetApp()->DoWaitCursor(1);
2626 int iItemCountBeforeMenuCmd = GetItemCount();
2627 bool bForce = false;
2628 switch (cmd)
2630 case IDSVNLC_VIEWREV:
2631 OpenFile(filepath,NOTEPAD2);
2632 break;
2633 case IDSVNLC_OPEN:
2634 OpenFile(filepath,OPEN);
2635 break;
2636 case IDSVNLC_OPENWITH:
2637 OpenFile(filepath,OPEN_WITH);
2638 break;
2639 case IDSVNLC_EXPLORE:
2641 ShellExecute(this->m_hWnd, _T("explore"), filepath->GetDirectory().GetWinPath(), NULL, NULL, SW_SHOW);
2643 break;
2645 // Compare current version and work copy.
2646 case IDSVNLC_COMPAREWC:
2648 POSITION pos = GetFirstSelectedItemPosition();
2649 while ( pos )
2651 int index = GetNextSelectedItem(pos);
2652 StartDiffWC(index);
2655 break;
2656 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2657 case IDSVNLC_COMPARE:
2659 POSITION pos = GetFirstSelectedItemPosition();
2660 while ( pos )
2662 int index = GetNextSelectedItem(pos);
2663 StartDiff(index);
2666 break;
2667 case IDSVNLC_GNUDIFF1:
2669 // SVNDiff diff(NULL, this->m_hWnd, true);
2671 // if (entry->remotestatus <= git_wc_status_normal)
2672 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2673 // else
2674 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2675 if(m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
2676 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,GitRev::GetWorkingCopy(),
2677 *filepath,GitRev::GetHead());
2678 else
2679 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_CurrentVersion,
2680 *filepath,m_CurrentVersion+_T("~1"));
2682 break;
2683 case IDSVNLC_ADD:
2684 { // The add went ok, but we now need to run through the selected items again
2685 // and update their status
2686 POSITION pos = GetFirstSelectedItemPosition();
2687 int index;
2688 while ((index = GetNextSelectedItem(pos)) >= 0)
2690 CTGitPath * path=(CTGitPath*)GetItemData(index);
2691 ASSERT(path);
2692 if(path == NULL)
2693 continue;
2694 CString cmd;
2695 cmd.Format(_T("git.exe add \"%s\""),path->GetGitPathString());
2696 CString output;
2697 if(!g_Git.Run(cmd,&output,CP_ACP))
2699 path->m_Action = CTGitPath::LOGACTIONS_ADDED;
2700 SetEntryCheck(path,index,true);
2701 SetItemGroup(index,0);
2702 this->m_StatusFileList.AddPath(*path);
2703 this->m_UnRevFileList.RemoveItem(*path);
2704 this->m_IgnoreFileList.RemoveItem(*path);
2705 Show(this->m_dwShow,0,true,true);
2710 break;
2712 case IDSVNLC_BLAME:
2714 CString sCmd;
2715 sCmd.Format(_T("\"%s\" /command:blame /path:\"%s\""),
2716 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath());
2718 CAppUtils::LaunchApplication(sCmd, NULL, false);
2720 break;
2722 case IDSVNLC_LOG:
2724 CString sCmd;
2725 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\""),
2726 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath());
2728 CAppUtils::LaunchApplication(sCmd, NULL, false);
2730 break;
2732 case IDSVNLC_EDITCONFLICT:
2734 CAppUtils::ConflictEdit(*filepath);
2735 break;
2737 case IDSVNLC_RESOLVECONFLICT:
2739 if (CMessageBox::Show(m_hWnd, IDS_PROC_RESOLVE, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO)==IDYES)
2741 POSITION pos = GetFirstSelectedItemPosition();
2742 while (pos != 0)
2744 int index;
2745 index = GetNextSelectedItem(pos);
2746 CTGitPath * fentry =(CTGitPath*) this->GetItemData(index);
2747 if(fentry == NULL)
2748 continue;
2750 if ( fentry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
2752 CString cmd,output;
2753 cmd.Format(_T("git.exe add \"%s\""),fentry->GetGitPathString());
2754 if(g_Git.Run(cmd,&output,CP_ACP))
2756 CMessageBox::Show(m_hWnd, output, _T("TortoiseSVN"), MB_ICONERROR);
2757 }else
2759 fentry->m_Action |= CTGitPath::LOGACTIONS_MODIFIED;
2760 fentry->m_Action &=~CTGitPath::LOGACTIONS_UNMERGED;
2765 Show(m_dwShow, 0, m_bShowFolders);
2768 break;
2770 case IDSVNLC_IGNORE:
2772 CTGitPathList ignorelist;
2773 //std::vector<CString> toremove;
2774 FillListOfSelectedItemPaths(ignorelist, true);
2775 SetRedraw(FALSE);
2777 if(!CAppUtils::IgnoreFile(ignorelist,false))
2778 break;
2780 for(int i=0;i<ignorelist.GetCount();i++)
2782 int nListboxEntries = GetItemCount();
2783 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2785 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2786 if (path->GetGitPathString()==ignorelist[i].GetGitPathString())
2788 RemoveListEntry(nItem);
2789 break;
2793 SetRedraw(TRUE);
2795 #if 0
2796 CTSVNPathList ignorelist;
2797 std::vector<CString> toremove;
2798 FillListOfSelectedItemPaths(ignorelist, true);
2799 SetRedraw(FALSE);
2800 for (int j=0; j<ignorelist.GetCount(); ++j)
2802 int nListboxEntries = GetItemCount();
2803 for (int i=0; i<nListboxEntries; ++i)
2805 if (GetListEntry(i)->GetPath().IsEquivalentTo(ignorelist[j]))
2807 selIndex = i;
2808 break;
2811 CString name = CPathUtils::PathPatternEscape(ignorelist[j].GetFileOrDirectoryName());
2812 CTSVNPath parentfolder = ignorelist[j].GetContainingDirectory();
2813 SVNProperties props(parentfolder, SVNRev::REV_WC, false);
2814 CStringA value;
2815 for (int i=0; i<props.GetCount(); i++)
2817 CString propname(props.GetItemName(i).c_str());
2818 if (propname.CompareNoCase(_T("git:ignore"))==0)
2820 stdstring stemp;
2821 // treat values as normal text even if they're not
2822 value = (char *)props.GetItemValue(i).c_str();
2825 if (value.IsEmpty())
2826 value = name;
2827 else
2829 value = value.Trim("\n\r");
2830 value += "\n";
2831 value += name;
2832 value.Remove('\r');
2834 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
2836 CString temp;
2837 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
2838 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseSVN"), MB_ICONERROR);
2839 break;
2841 if (GetCheck(selIndex))
2842 m_nSelected--;
2843 m_nTotal--;
2845 // now, if we ignored a folder, remove all its children
2846 if (ignorelist[j].IsDirectory())
2848 for (int i=0; i<(int)m_arListArray.size(); ++i)
2850 FileEntry * entry = GetListEntry(i);
2851 if (entry->status == git_wc_status_unversioned)
2853 if (!ignorelist[j].IsEquivalentTo(entry->GetPath())&&(ignorelist[j].IsAncestorOf(entry->GetPath())))
2855 entry->status = git_wc_status_ignored;
2856 entry->textstatus = git_wc_status_ignored;
2857 if (GetCheck(i))
2858 m_nSelected--;
2859 toremove.push_back(entry->GetPath().GetSVNPathString());
2865 CTSVNPath basepath = m_arStatusArray[m_arListArray[selIndex]]->basepath;
2867 FileEntry * entry = m_arStatusArray[m_arListArray[selIndex]];
2868 if ( entry->status == git_wc_status_unversioned ) // keep "deleted" items
2869 toremove.push_back(entry->GetPath().GetSVNPathString());
2871 if (!m_bIgnoreRemoveOnly)
2873 SVNStatus status;
2874 git_wc_status2_t * s;
2875 CTSVNPath gitPath;
2876 s = status.GetFirstFileStatus(parentfolder, gitPath, false, git_depth_empty);
2877 // first check if the folder isn't already present in the list
2878 bool bFound = false;
2879 nListboxEntries = GetItemCount();
2880 for (int i=0; i<nListboxEntries; ++i)
2882 FileEntry * entry = GetListEntry(i);
2883 if (entry->path.IsEquivalentTo(gitPath))
2885 bFound = true;
2886 break;
2889 if (!bFound)
2891 if (s!=0)
2893 FileEntry * entry = new FileEntry();
2894 entry->path = gitPath;
2895 entry->basepath = basepath;
2896 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
2897 entry->textstatus = s->text_status;
2898 entry->propstatus = s->prop_status;
2899 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
2900 entry->remotetextstatus = s->repos_text_status;
2901 entry->remotepropstatus = s->repos_prop_status;
2902 entry->inunversionedfolder = FALSE;
2903 entry->checked = true;
2904 entry->inexternal = false;
2905 entry->direct = false;
2906 entry->isfolder = true;
2907 entry->last_commit_date = 0;
2908 entry->last_commit_rev = 0;
2909 entry->remoterev = 0;
2910 if (s->entry)
2912 if (s->entry->url)
2914 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
2917 if (s->entry && s->entry->present_props)
2919 entry->present_props = s->entry->present_props;
2921 m_arStatusArray.push_back(entry);
2922 m_arListArray.push_back(m_arStatusArray.size()-1);
2923 AddEntry(entry, langID, GetItemCount());
2928 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
2930 int nListboxEntries = GetItemCount();
2931 for (int i=0; i<nListboxEntries; ++i)
2933 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
2935 RemoveListEntry(i);
2936 break;
2940 SetRedraw(TRUE);
2942 #endif
2943 break;
2944 case IDSVNLC_IGNOREMASK:
2946 CString common;
2947 CString ext=filepath->GetFileExtension();
2948 CTGitPathList ignorelist;
2949 FillListOfSelectedItemPaths(ignorelist, true);
2950 SetRedraw(FALSE);
2952 CAppUtils::IgnoreFile(ignorelist,true);
2953 common=ignorelist.GetCommonRoot().GetGitPathString();
2955 for (int i=0; i< GetItemCount(); ++i)
2957 CTGitPath *path=(CTGitPath*)GetItemData(i);
2958 if(!( path->m_Action & CTGitPath::LOGACTIONS_UNVER))
2959 continue;
2960 if( path->GetGitPathString().Left(common.GetLength()) == common )
2962 if (path->GetFileExtension()==ext)
2964 RemoveListEntry(i);
2965 i--; // remove index i at item, new one will replace.
2970 SetRedraw(TRUE);
2972 #if 0
2973 std::set<CTSVNPath> parentlist;
2974 for (int i=0; i<ignorelist.GetCount(); ++i)
2976 parentlist.insert(ignorelist[i].GetContainingDirectory());
2978 std::set<CTSVNPath>::iterator it;
2979 std::vector<CString> toremove;
2981 for (it = parentlist.begin(); it != parentlist.end(); ++it)
2983 CTSVNPath parentFolder = (*it).GetDirectory();
2984 SVNProperties props(parentFolder, SVNRev::REV_WC, false);
2985 CStringA value;
2986 for (int i=0; i<props.GetCount(); i++)
2988 CString propname(props.GetItemName(i).c_str());
2989 if (propname.CompareNoCase(_T("git:ignore"))==0)
2991 stdstring stemp;
2992 // treat values as normal text even if they're not
2993 value = (char *)props.GetItemValue(i).c_str();
2996 if (value.IsEmpty())
2997 value = name;
2998 else
3000 value = value.Trim("\n\r");
3001 value += "\n";
3002 value += name;
3003 value.Remove('\r');
3005 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
3007 CString temp;
3008 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
3009 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseSVN"), MB_ICONERROR);
3011 else
3013 CTSVNPath basepath;
3014 int nListboxEntries = GetItemCount();
3015 for (int i=0; i<nListboxEntries; ++i)
3017 FileEntry * entry = GetListEntry(i);
3018 ASSERT(entry != NULL);
3019 if (entry == NULL)
3020 continue;
3021 if (basepath.IsEmpty())
3022 basepath = entry->basepath;
3023 // since we ignored files with a mask (e.g. *.exe)
3024 // we have to find find all files in the same
3025 // folder (IsAncestorOf() returns TRUE for _all_ children,
3026 // not just the immediate ones) which match the
3027 // mask and remove them from the list too.
3028 if ((entry->status == git_wc_status_unversioned)&&(parentFolder.IsAncestorOf(entry->path)))
3030 CString f = entry->path.GetSVNPathString();
3031 if (f.Mid(parentFolder.GetSVNPathString().GetLength()).Find('/')<=0)
3033 if (CStringUtils::WildCardMatch(name, f))
3035 if (GetCheck(i))
3036 m_nSelected--;
3037 m_nTotal--;
3038 toremove.push_back(f);
3043 if (!m_bIgnoreRemoveOnly)
3045 SVNStatus status;
3046 git_wc_status2_t * s;
3047 CTSVNPath gitPath;
3048 s = status.GetFirstFileStatus(parentFolder, gitPath, false, git_depth_empty);
3049 if (s!=0)
3051 // first check if the folder isn't already present in the list
3052 bool bFound = false;
3053 for (int i=0; i<nListboxEntries; ++i)
3055 FileEntry * entry = GetListEntry(i);
3056 if (entry->path.IsEquivalentTo(gitPath))
3058 bFound = true;
3059 break;
3062 if (!bFound)
3064 FileEntry * entry = new FileEntry();
3065 entry->path = gitPath;
3066 entry->basepath = basepath;
3067 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
3068 entry->textstatus = s->text_status;
3069 entry->propstatus = s->prop_status;
3070 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
3071 entry->remotetextstatus = s->repos_text_status;
3072 entry->remotepropstatus = s->repos_prop_status;
3073 entry->inunversionedfolder = false;
3074 entry->checked = true;
3075 entry->inexternal = false;
3076 entry->direct = false;
3077 entry->isfolder = true;
3078 entry->last_commit_date = 0;
3079 entry->last_commit_rev = 0;
3080 entry->remoterev = 0;
3081 if (s->entry)
3083 if (s->entry->url)
3085 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
3088 if (s->entry && s->entry->present_props)
3090 entry->present_props = s->entry->present_props;
3092 m_arStatusArray.push_back(entry);
3093 m_arListArray.push_back(m_arStatusArray.size()-1);
3094 AddEntry(entry, langID, GetItemCount());
3100 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
3102 int nListboxEntries = GetItemCount();
3103 for (int i=0; i<nListboxEntries; ++i)
3105 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
3107 RemoveListEntry(i);
3108 break;
3112 SetRedraw(TRUE);
3114 #endif
3115 break;
3117 case IDSVNLC_REVERT:
3119 // If at least one item is not in the status "added"
3120 // we ask for a confirmation
3121 BOOL bConfirm = FALSE;
3122 POSITION pos = GetFirstSelectedItemPosition();
3123 int index;
3124 while ((index = GetNextSelectedItem(pos)) >= 0)
3126 //FileEntry * fentry = GetListEntry(index);
3127 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
3128 if(fentry && fentry->m_Action &CTGitPath::LOGACTIONS_MODIFIED )
3130 bConfirm = TRUE;
3131 break;
3135 CString str;
3136 str.Format(IDS_PROC_WARNREVERT,GetSelectedCount());
3138 if (!bConfirm || CMessageBox::Show(this->m_hWnd, str, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION)==IDYES)
3140 CTGitPathList targetList;
3141 FillListOfSelectedItemPaths(targetList);
3143 // make sure that the list is reverse sorted, so that
3144 // children are removed before any parents
3145 targetList.SortByPathname(true);
3147 // put all reverted files in the trashbin, except the ones with 'added'
3148 // status because they are not restored by the revert.
3149 CTGitPathList delList;
3150 POSITION pos = GetFirstSelectedItemPosition();
3151 int index;
3152 while ((index = GetNextSelectedItem(pos)) >= 0)
3154 CTGitPath *entry=(CTGitPath *)GetItemData(index);
3155 if (entry&&(!(entry->m_Action& CTGitPath::LOGACTIONS_ADDED)))
3156 delList.AddPath(*entry);
3158 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
3159 delList.DeleteAllFiles(true);
3161 if (g_Git.Revert(targetList))
3163 CMessageBox::Show(this->m_hWnd, _T("Revert Fail"), _T("TortoiseSVN"), MB_ICONERROR);
3165 else
3167 for(int i=0;i<targetList.GetCount();i++)
3169 int nListboxEntries = GetItemCount();
3170 for (int nItem=0; nItem<nListboxEntries; ++nItem)
3172 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
3173 if (path->GetGitPathString()==targetList[i].GetGitPathString())
3175 RemoveListEntry(nItem);
3176 break;
3180 SetRedraw(TRUE);
3181 SaveColumnWidths();
3182 Show(m_dwShow, 0, m_bShowFolders);
3183 NotifyCheck();
3187 break;
3189 case IDSVNLC_COPY:
3190 CopySelectedEntriesToClipboard(0);
3191 break;
3192 case IDSVNLC_COPYEXT:
3193 CopySelectedEntriesToClipboard((DWORD)-1);
3194 break;
3196 case IDSVNLC_SAVEAS:
3197 FileSaveAs(filepath);
3198 break;
3200 case IDSVNLC_REVERTTOREV:
3201 RevertSelectedItemToVersion();
3202 break;
3203 #if 0
3204 case IDSVNLC_PROPERTIES:
3206 CTSVNPathList targetList;
3207 FillListOfSelectedItemPaths(targetList);
3208 CEditPropertiesDlg dlg;
3209 dlg.SetPathList(targetList);
3210 dlg.DoModal();
3211 if (dlg.HasChanged())
3213 // since the user might have changed/removed/added
3214 // properties recursively, we don't really know
3215 // which items have changed their status.
3216 // So tell the parent to do a refresh.
3217 CWnd* pParent = GetParent();
3218 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3220 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3224 break;
3225 case IDSVNLC_COMMIT:
3227 CTSVNPathList targetList;
3228 FillListOfSelectedItemPaths(targetList);
3229 CTSVNPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
3230 VERIFY(targetList.WriteToFile(tempFile.GetWinPathString()));
3231 CString commandline = CPathUtils::GetAppDirectory();
3232 commandline += _T("TortoiseProc.exe /command:commit /pathfile:\"");
3233 commandline += tempFile.GetWinPathString();
3234 commandline += _T("\"");
3235 commandline += _T(" /deletepathfile");
3236 CAppUtils::LaunchApplication(commandline, NULL, false);
3238 break;
3240 case IDSVNLC_COMPAREWC:
3242 POSITION pos = GetFirstSelectedItemPosition();
3243 while ( pos )
3245 int index = GetNextSelectedItem(pos);
3246 FileEntry * entry = GetListEntry(index);
3247 ASSERT(entry != NULL);
3248 if (entry == NULL)
3249 continue;
3250 SVNDiff diff(NULL, m_hWnd, true);
3251 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
3252 git_revnum_t baseRev = entry->Revision;
3253 diff.DiffFileAgainstBase(
3254 entry->path, baseRev, entry->textstatus, entry->propstatus);
3257 break;
3258 case IDSVNLC_GNUDIFF1:
3260 SVNDiff diff(NULL, this->m_hWnd, true);
3262 if (entry->remotestatus <= git_wc_status_normal)
3263 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
3264 else
3265 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
3267 break;
3268 case IDSVNLC_UPDATE:
3270 CTSVNPathList targetList;
3271 FillListOfSelectedItemPaths(targetList);
3272 bool bAllExist = true;
3273 for (int i=0; i<targetList.GetCount(); ++i)
3275 if (!targetList[i].Exists())
3277 bAllExist = false;
3278 break;
3281 if (bAllExist)
3283 CSVNProgressDlg dlg;
3284 dlg.SetCommand(CSVNProgressDlg::SVNProgress_Update);
3285 dlg.SetPathList(targetList);
3286 dlg.SetRevision(SVNRev::REV_HEAD);
3287 dlg.DoModal();
3289 else
3291 CString sTempFile = CTempFiles::Instance().GetTempFilePath(false).GetWinPathString();
3292 targetList.WriteToFile(sTempFile, false);
3293 CString sCmd;
3294 sCmd.Format(_T("\"%s\" /command:update /rev /pathfile:\"%s\" /deletepathfile"),
3295 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)sTempFile);
3297 CAppUtils::LaunchApplication(sCmd, NULL, false);
3300 break;
3302 case IDSVNLC_REMOVE:
3304 SVN git;
3305 CTSVNPathList itemsToRemove;
3306 FillListOfSelectedItemPaths(itemsToRemove);
3308 // We must sort items before removing, so that files are always removed
3309 // *before* their parents
3310 itemsToRemove.SortByPathname(true);
3312 bool bSuccess = false;
3313 if (git.Remove(itemsToRemove, FALSE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3315 bSuccess = true;
3317 else
3319 if ((git.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE) ||
3320 (git.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))
3322 CString msg, yes, no, yestoall;
3323 msg.Format(IDS_PROC_REMOVEFORCE, (LPCTSTR)git.GetLastErrorMessage());
3324 yes.LoadString(IDS_MSGBOX_YES);
3325 no.LoadString(IDS_MSGBOX_NO);
3326 yestoall.LoadString(IDS_PROC_YESTOALL);
3327 UINT ret = CMessageBox::Show(m_hWnd, msg, _T("TortoiseSVN"), 2, IDI_ERROR, yes, no, yestoall);
3328 if ((ret == 1)||(ret==3))
3330 if (!git.Remove(itemsToRemove, TRUE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3332 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3334 else
3335 bSuccess = true;
3338 else
3339 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3341 if (bSuccess)
3343 // The remove went ok, but we now need to run through the selected items again
3344 // and update their status
3345 POSITION pos = GetFirstSelectedItemPosition();
3346 int index;
3347 std::vector<int> entriesToRemove;
3348 while ((index = GetNextSelectedItem(pos)) >= 0)
3350 FileEntry * e = GetListEntry(index);
3351 if (!bShift &&
3352 ((e->textstatus == git_wc_status_unversioned)||
3353 (e->textstatus == git_wc_status_none)||
3354 (e->textstatus == git_wc_status_ignored)))
3356 if (GetCheck(index))
3357 m_nSelected--;
3358 m_nTotal--;
3359 entriesToRemove.push_back(index);
3361 else
3363 e->textstatus = git_wc_status_deleted;
3364 e->status = git_wc_status_deleted;
3365 SetEntryCheck(e,index,true);
3368 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3370 RemoveListEntry(*it);
3373 SaveColumnWidths();
3374 Show(m_dwShow, 0, m_bShowFolders);
3375 NotifyCheck();
3377 break;
3378 case IDSVNLC_DELETE:
3380 CTSVNPathList pathlist;
3381 FillListOfSelectedItemPaths(pathlist);
3382 pathlist.RemoveChildren();
3383 CString filelist;
3384 for (INT_PTR i=0; i<pathlist.GetCount(); ++i)
3386 filelist += pathlist[i].GetWinPathString();
3387 filelist += _T("|");
3389 filelist += _T("|");
3390 int len = filelist.GetLength();
3391 TCHAR * buf = new TCHAR[len+2];
3392 _tcscpy_s(buf, len+2, filelist);
3393 for (int i=0; i<len; ++i)
3394 if (buf[i] == '|')
3395 buf[i] = 0;
3396 SHFILEOPSTRUCT fileop;
3397 fileop.hwnd = this->m_hWnd;
3398 fileop.wFunc = FO_DELETE;
3399 fileop.pFrom = buf;
3400 fileop.pTo = NULL;
3401 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
3402 fileop.lpszProgressTitle = _T("deleting file");
3403 int result = SHFileOperation(&fileop);
3404 delete [] buf;
3406 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
3408 SetRedraw(FALSE);
3409 POSITION pos = NULL;
3410 CTSVNPathList deletedlist; // to store list of deleted folders
3411 while ((pos = GetFirstSelectedItemPosition()) != 0)
3413 int index = GetNextSelectedItem(pos);
3414 if (GetCheck(index))
3415 m_nSelected--;
3416 m_nTotal--;
3417 FileEntry * fentry = GetListEntry(index);
3418 if ((fentry)&&(fentry->isfolder))
3419 deletedlist.AddPath(fentry->path);
3420 RemoveListEntry(index);
3422 // now go through the list of deleted folders
3423 // and remove all their children from the list too!
3424 int nListboxEntries = GetItemCount();
3425 for (int folderindex = 0; folderindex < deletedlist.GetCount(); ++folderindex)
3427 CTSVNPath folderpath = deletedlist[folderindex];
3428 for (int i=0; i<nListboxEntries; ++i)
3430 FileEntry * entry = GetListEntry(i);
3431 if (folderpath.IsAncestorOf(entry->path))
3433 RemoveListEntry(i--);
3434 nListboxEntries--;
3438 SetRedraw(TRUE);
3441 break;
3444 case IDSVNLC_ADD:
3446 SVN git;
3447 CTSVNPathList itemsToAdd;
3448 FillListOfSelectedItemPaths(itemsToAdd);
3450 // We must sort items before adding, so that folders are always added
3451 // *before* any of their children
3452 itemsToAdd.SortByPathname();
3454 ProjectProperties props;
3455 props.ReadPropsPathList(itemsToAdd);
3456 if (git.Add(itemsToAdd, &props, git_depth_empty, TRUE, TRUE, TRUE))
3458 // The add went ok, but we now need to run through the selected items again
3459 // and update their status
3460 POSITION pos = GetFirstSelectedItemPosition();
3461 int index;
3462 while ((index = GetNextSelectedItem(pos)) >= 0)
3464 FileEntry * e = GetListEntry(index);
3465 e->textstatus = git_wc_status_added;
3466 e->propstatus = git_wc_status_none;
3467 e->status = git_wc_status_added;
3468 SetEntryCheck(e,index,true);
3471 else
3473 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3475 SaveColumnWidths();
3476 Show(m_dwShow, 0, m_bShowFolders);
3477 NotifyCheck();
3479 break;
3480 case IDSVNLC_ADD_RECURSIVE:
3482 CTSVNPathList itemsToAdd;
3483 FillListOfSelectedItemPaths(itemsToAdd);
3485 CAddDlg dlg;
3486 dlg.m_pathList = itemsToAdd;
3487 if (dlg.DoModal() == IDOK)
3489 if (dlg.m_pathList.GetCount() == 0)
3490 break;
3491 CSVNProgressDlg progDlg;
3492 progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Add);
3493 progDlg.SetPathList(dlg.m_pathList);
3494 ProjectProperties props;
3495 props.ReadPropsPathList(dlg.m_pathList);
3496 progDlg.SetProjectProperties(props);
3497 progDlg.SetItemCount(dlg.m_pathList.GetCount());
3498 progDlg.DoModal();
3500 // refresh!
3501 CWnd* pParent = GetParent();
3502 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3504 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3508 break;
3510 case IDSVNLC_REPAIRMOVE:
3512 POSITION pos = GetFirstSelectedItemPosition();
3513 int index = GetNextSelectedItem(pos);
3514 FileEntry * entry1 = NULL;
3515 FileEntry * entry2 = NULL;
3516 if (index >= 0)
3518 entry1 = GetListEntry(index);
3519 git_wc_status_kind status1 = git_wc_status_none;
3520 git_wc_status_kind status2 = git_wc_status_none;
3521 if (entry1)
3523 status1 = entry1->status;
3524 index = GetNextSelectedItem(pos);
3525 if (index >= 0)
3527 entry2 = GetListEntry(index);
3528 if (entry2)
3530 status2 = entry2->status;
3531 if (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned)
3533 FileEntry * tempentry = entry1;
3534 entry1 = entry2;
3535 entry2 = tempentry;
3537 // entry1 was renamed to entry2 but outside of Subversion
3538 // fix this by moving entry2 back to entry1 first,
3539 // then do an git-move from entry1 to entry2
3540 if (MoveFile(entry2->GetPath().GetWinPath(), entry1->GetPath().GetWinPath()))
3542 SVN git;
3543 if (!git.Move(CTSVNPathList(entry1->GetPath()), entry2->GetPath(), TRUE))
3545 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3547 else
3549 // check the previously unversioned item
3550 entry1->checked = true;
3551 // fixing the move was successful. We have to adjust the new status of the
3552 // files.
3553 // Since we don't know if the moved/renamed file had local modifications or not,
3554 // we can't guess the new status. That means we have to refresh...
3555 CWnd* pParent = GetParent();
3556 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3558 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3562 else
3564 LPVOID lpMsgBuf;
3565 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
3566 FORMAT_MESSAGE_FROM_SYSTEM |
3567 FORMAT_MESSAGE_IGNORE_INSERTS,
3568 NULL,
3569 GetLastError(),
3570 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
3571 (LPTSTR) &lpMsgBuf,
3573 NULL
3575 MessageBox((LPCTSTR)lpMsgBuf, _T("Error"), MB_OK | MB_ICONINFORMATION );
3576 LocalFree( lpMsgBuf );
3583 break;
3584 case IDSVNLC_REMOVEFROMCS:
3586 CTSVNPathList changelistItems;
3587 FillListOfSelectedItemPaths(changelistItems);
3588 SVN git;
3589 SetRedraw(FALSE);
3590 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
3592 // The changelists were removed, but we now need to run through the selected items again
3593 // and update their changelist
3594 POSITION pos = GetFirstSelectedItemPosition();
3595 int index;
3596 std::vector<int> entriesToRemove;
3597 while ((index = GetNextSelectedItem(pos)) >= 0)
3599 FileEntry * e = GetListEntry(index);
3600 if (e)
3602 e->changelist.Empty();
3603 if (e->status == git_wc_status_normal)
3605 // remove the entry completely
3606 entriesToRemove.push_back(index);
3608 else
3609 SetItemGroup(index, 0);
3612 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3614 RemoveListEntry(*it);
3616 // TODO: Should we go through all entries here and check if we also could
3617 // remove the changelist from m_changelists ?
3619 else
3621 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3623 SetRedraw(TRUE);
3625 break;
3626 case IDSVNLC_CREATEIGNORECS:
3627 CreateChangeList(SVNSLC_IGNORECHANGELIST);
3628 break;
3629 case IDSVNLC_CREATECS:
3631 CCreateChangelistDlg dlg;
3632 if (dlg.DoModal() == IDOK)
3634 CreateChangeList(dlg.m_sName);
3637 break;
3638 default:
3640 if (cmd < IDSVNLC_MOVETOCS)
3641 break;
3642 CTSVNPathList changelistItems;
3643 FillListOfSelectedItemPaths(changelistItems);
3645 // find the changelist name
3646 CString sChangelist;
3647 int cmdID = IDSVNLC_MOVETOCS;
3648 SetRedraw(FALSE);
3649 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
3651 if ((it->first.Compare(SVNSLC_IGNORECHANGELIST))&&(entry->changelist.Compare(it->first)))
3653 if (cmd == cmdID)
3655 sChangelist = it->first;
3657 cmdID++;
3660 if (!sChangelist.IsEmpty())
3662 SVN git;
3663 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
3665 // The changelists were moved, but we now need to run through the selected items again
3666 // and update their changelist
3667 POSITION pos = GetFirstSelectedItemPosition();
3668 int index;
3669 while ((index = GetNextSelectedItem(pos)) >= 0)
3671 FileEntry * e = GetListEntry(index);
3672 e->changelist = sChangelist;
3673 if (!e->IsFolder())
3675 if (m_changelists.find(e->changelist)!=m_changelists.end())
3676 SetItemGroup(index, m_changelists[e->changelist]);
3677 else
3678 SetItemGroup(index, 0);
3682 else
3684 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3687 SetRedraw(TRUE);
3689 break;
3690 #endif
3692 } // switch (cmd)
3693 m_bBlock = FALSE;
3694 AfxGetApp()->DoWaitCursor(-1);
3695 GetStatisticsString();
3696 int iItemCountAfterMenuCmd = GetItemCount();
3697 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
3699 // CWnd* pParent = GetParent();
3700 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3701 // {
3702 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
3703 // }
3705 } // if (popup.CreatePopupMenu())
3706 } // if (selIndex >= 0)
3710 void CGitStatusListCtrl::OnContextMenuHeader(CWnd * pWnd, CPoint point)
3712 bool XPorLater = false;
3713 OSVERSIONINFOEX inf;
3714 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
3715 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
3716 GetVersionEx((OSVERSIONINFO *)&inf);
3717 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
3718 if (fullver >= 0x0501)
3719 XPorLater = true;
3721 CHeaderCtrl * pHeaderCtrl = (CHeaderCtrl *)pWnd;
3722 if ((point.x == -1) && (point.y == -1))
3724 CRect rect;
3725 pHeaderCtrl->GetItemRect(0, &rect);
3726 ClientToScreen(&rect);
3727 point = rect.CenterPoint();
3729 Locker lock(m_critSec);
3730 CMenu popup;
3731 if (popup.CreatePopupMenu())
3733 int columnCount = m_ColumnManager.GetColumnCount();
3735 CString temp;
3736 UINT uCheckedFlags = MF_STRING | MF_ENABLED | MF_CHECKED;
3737 UINT uUnCheckedFlags = MF_STRING | MF_ENABLED;
3739 // build control menu
3741 if (XPorLater)
3743 temp.LoadString(IDS_STATUSLIST_SHOWGROUPS);
3744 popup.AppendMenu(IsGroupViewEnabled() ? uCheckedFlags : uUnCheckedFlags, columnCount, temp);
3747 if (m_ColumnManager.AnyUnusedProperties())
3749 temp.LoadString(IDS_STATUSLIST_REMOVEUNUSEDPROPS);
3750 popup.AppendMenu(uUnCheckedFlags, columnCount+1, temp);
3753 temp.LoadString(IDS_STATUSLIST_RESETCOLUMNORDER);
3754 popup.AppendMenu(uUnCheckedFlags, columnCount+2, temp);
3755 popup.AppendMenu(MF_SEPARATOR);
3757 // standard columns
3759 for (int i = 1; i < SVNSLC_NUMCOLUMNS; ++i)
3761 popup.AppendMenu ( m_ColumnManager.IsVisible(i)
3762 ? uCheckedFlags
3763 : uUnCheckedFlags
3765 , m_ColumnManager.GetName(i));
3768 // user-prop columns:
3769 // find relevant ones and sort 'em
3771 std::map<CString, int> sortedProps;
3772 for (int i = SVNSLC_NUMCOLUMNS; i < columnCount; ++i)
3773 if (m_ColumnManager.IsRelevant(i))
3774 sortedProps[m_ColumnManager.GetName(i)] = i;
3776 if (!sortedProps.empty())
3778 // add 'em to the menu
3780 popup.AppendMenu(MF_SEPARATOR);
3782 typedef std::map<CString, int>::const_iterator CIT;
3783 for ( CIT iter = sortedProps.begin(), end = sortedProps.end()
3784 ; iter != end
3785 ; ++iter)
3787 popup.AppendMenu ( m_ColumnManager.IsVisible(iter->second)
3788 ? uCheckedFlags
3789 : uUnCheckedFlags
3790 , iter->second
3791 , iter->first);
3795 // show menu & let user pick an entry
3797 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
3798 if ((cmd >= 1)&&(cmd < columnCount))
3800 m_ColumnManager.SetVisible (cmd, !m_ColumnManager.IsVisible(cmd));
3802 else if (cmd == columnCount)
3804 EnableGroupView(!IsGroupViewEnabled());
3806 else if (cmd == columnCount+1)
3808 m_ColumnManager.RemoveUnusedProps();
3810 else if (cmd == columnCount+2)
3812 m_ColumnManager.ResetColumns (m_dwDefaultColumns);
3817 void CGitStatusListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
3820 if (pWnd == this)
3822 OnContextMenuList(pWnd, point);
3823 } // if (pWnd == this)
3824 else if (pWnd == GetHeaderCtrl())
3826 OnContextMenuHeader(pWnd, point);
3830 void CGitStatusListCtrl::CreateChangeList(const CString& name)
3832 #if 0
3833 CTGitPathList changelistItems;
3834 FillListOfSelectedItemPaths(changelistItems);
3835 Git git;
3836 if (git.AddToChangeList(changelistItems, name, git_depth_empty))
3838 TCHAR groupname[1024];
3839 LVGROUP grp = {0};
3840 grp.cbSize = sizeof(LVGROUP);
3841 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3842 _tcsncpy_s(groupname, 1024, name, 1023);
3843 grp.pszHeader = groupname;
3844 grp.iGroupId = (int)m_changelists.size();
3845 grp.uAlign = LVGA_HEADER_LEFT;
3846 m_changelists[name] = InsertGroup(-1, &grp);
3848 PrepareGroups(true);
3850 POSITION pos = GetFirstSelectedItemPosition();
3851 int index;
3852 while ((index = GetNextSelectedItem(pos)) >= 0)
3854 FileEntry * e = GetListEntry(index);
3855 e->changelist = name;
3856 SetEntryCheck(e, index, FALSE);
3859 for (index = 0; index < GetItemCount(); ++index)
3861 FileEntry * e = GetListEntry(index);
3862 if (m_changelists.find(e->changelist)!=m_changelists.end())
3863 SetItemGroup(index, m_changelists[e->changelist]);
3864 else
3865 SetItemGroup(index, 0);
3868 else
3870 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("Tortoisegit"), MB_ICONERROR);
3872 #endif
3875 void CGitStatusListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
3878 Locker lock(m_critSec);
3879 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
3880 *pResult = 0;
3881 if (m_bBlock)
3882 return;
3883 #if 0
3884 if (pNMLV->iItem < 0)
3886 if (!IsGroupViewEnabled())
3887 return;
3888 POINT pt;
3889 DWORD ptW = GetMessagePos();
3890 pt.x = GET_X_LPARAM(ptW);
3891 pt.y = GET_Y_LPARAM(ptW);
3892 ScreenToClient(&pt);
3893 int group = GetGroupFromPoint(&pt);
3894 if (group < 0)
3895 return;
3896 // check/uncheck the whole group depending on the check-state
3897 // of the first item in the group
3898 m_bBlock = true;
3899 bool bCheck = false;
3900 bool bFirst = false;
3901 LVITEM lv;
3902 for (int i=0; i<GetItemCount(); ++i)
3904 SecureZeroMemory(&lv, sizeof(LVITEM));
3905 lv.mask = LVIF_GROUPID;
3906 lv.iItem = i;
3907 GetItem(&lv);
3908 if (lv.iGroupId == group)
3910 FileEntry * entry = GetListEntry(i);
3911 if (!bFirst)
3913 bCheck = !GetCheck(i);
3914 bFirst = true;
3916 if (entry)
3918 bool bOldCheck = !!GetCheck(i);
3919 SetEntryCheck(entry, i, bCheck);
3920 if (bCheck != bOldCheck)
3922 if (bCheck)
3923 m_nSelected++;
3924 else
3925 m_nSelected--;
3930 GetStatisticsString();
3931 m_bBlock = false;
3932 NotifyCheck();
3933 return;
3935 #endif
3936 // FileEntry * entry = GetListEntry(pNMLV->iItem);
3937 // if (entry)
3939 // if (entry->isConflicted)
3940 // {
3941 // gitDiff::StartConflictEditor(entry->GetPath());
3942 // }
3943 // else
3945 StartDiff(pNMLV->iItem);
3950 void CGitStatusListCtrl::StartDiffWC(int fileindex)
3952 if(fileindex<0)
3953 return;
3955 CString Ver;
3956 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
3957 return;
3959 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3961 CGitDiff::Diff(&file1,&file1,
3962 CString(GIT_REV_ZERO),
3963 m_CurrentVersion);
3967 void CGitStatusListCtrl::StartDiff(int fileindex)
3969 if(fileindex<0)
3970 return;
3972 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3973 CTGitPath file2;
3974 if(file1.m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
3976 file2.SetFromGit(file1.GetGitOldPathString());
3977 }else
3979 file2=file1;
3982 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
3984 if(!g_Git.IsInitRepos())
3985 CGitDiff::Diff(&file1,&file2,
3986 CString(GIT_REV_ZERO),
3987 GitRev::GetHead());
3988 else
3989 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
3990 CString(GIT_REV_ZERO));
3991 }else
3993 CGitDiff::Diff(&file1,&file2,
3994 m_CurrentVersion,
3995 m_CurrentVersion+_T("~1"));
3997 #if 0
3998 if (fileindex < 0)
3999 return;
4000 FileEntry * entry = GetListEntry(fileindex);
4001 ASSERT(entry != NULL);
4002 if (entry == NULL)
4003 return;
4004 if (((entry->status == git_wc_status_normal)&&(entry->remotestatus <= git_wc_status_normal))||
4005 (entry->status == git_wc_status_unversioned)||(entry->status == git_wc_status_none))
4007 int ret = (int)ShellExecute(this->m_hWnd, NULL, entry->path.GetWinPath(), NULL, NULL, SW_SHOW);
4008 if (ret <= HINSTANCE_ERROR)
4010 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
4011 cmd += entry->path.GetWinPathString();
4012 CAppUtils::LaunchApplication(cmd, NULL, false);
4014 return;
4017 GitDiff diff(NULL, m_hWnd, true);
4018 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
4019 diff.DiffWCFile(
4020 entry->path, entry->textstatus, entry->propstatus,
4021 entry->remotetextstatus, entry->remotepropstatus);
4022 #endif
4025 CString CGitStatusListCtrl::GetStatisticsString()
4028 CString sNormal, sAdded, sDeleted, sModified, sConflicted, sUnversioned;
4029 WORD langID = (WORD)(DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4030 TCHAR buf[MAX_STATUS_STRING_LENGTH];
4031 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal, buf, sizeof(buf)/sizeof(TCHAR), langID);
4032 sNormal = buf;
4033 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added, buf, sizeof(buf)/sizeof(TCHAR), langID);
4034 sAdded = buf;
4035 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted, buf, sizeof(buf)/sizeof(TCHAR), langID);
4036 sDeleted = buf;
4037 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified, buf, sizeof(buf)/sizeof(TCHAR), langID);
4038 sModified = buf;
4039 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted, buf, sizeof(buf)/sizeof(TCHAR), langID);
4040 sConflicted = buf;
4041 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned, buf, sizeof(buf)/sizeof(TCHAR), langID);
4042 sUnversioned = buf;
4043 CString sToolTip;
4044 sToolTip.Format(_T("%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d"),
4045 (LPCTSTR)sNormal, m_nNormal,
4046 (LPCTSTR)sUnversioned, m_nUnversioned,
4047 (LPCTSTR)sModified, m_nModified,
4048 (LPCTSTR)sAdded, m_nAdded,
4049 (LPCTSTR)sDeleted, m_nDeleted,
4050 (LPCTSTR)sConflicted, m_nConflicted
4052 CString sStats;
4053 sStats.Format(IDS_COMMITDLG_STATISTICSFORMAT, m_nSelected, GetItemCount());
4054 if (m_pStatLabel)
4056 m_pStatLabel->SetWindowText(sStats);
4059 if (m_pSelectButton)
4061 if (m_nSelected == 0)
4062 m_pSelectButton->SetCheck(BST_UNCHECKED);
4063 else if (m_nSelected != GetItemCount())
4064 m_pSelectButton->SetCheck(BST_INDETERMINATE);
4065 else
4066 m_pSelectButton->SetCheck(BST_CHECKED);
4069 if (m_pConfirmButton)
4071 m_pConfirmButton->EnableWindow(m_nSelected>0);
4074 return sToolTip;
4079 CString CGitStatusListCtrl::GetCommonDirectory(bool bStrict)
4081 if (!bStrict)
4083 // not strict means that the selected folder has priority
4084 if (!m_StatusFileList.GetCommonDirectory().IsEmpty())
4085 return m_StatusFileList.GetCommonDirectory().GetWinPath();
4088 CTGitPath commonBaseDirectory;
4089 int nListItems = GetItemCount();
4090 for (int i=0; i<nListItems; ++i)
4092 CTGitPath baseDirectory,*p= (CTGitPath*)this->GetItemData(i);
4093 ASSERT(p);
4094 if(p==NULL)
4095 continue;
4096 baseDirectory = p->GetDirectory();
4098 if(commonBaseDirectory.IsEmpty())
4100 commonBaseDirectory = baseDirectory;
4102 else
4104 if (commonBaseDirectory.GetWinPathString().GetLength() > baseDirectory.GetWinPathString().GetLength())
4106 if (baseDirectory.IsAncestorOf(commonBaseDirectory))
4107 commonBaseDirectory = baseDirectory;
4111 return g_Git.m_CurrentDir+CString(_T("\\"))+commonBaseDirectory.GetWinPath();
4114 CTGitPath CGitStatusListCtrl::GetCommonURL(bool bStrict)
4116 CTGitPath commonBaseURL;
4117 #if 0
4119 if (!bStrict)
4121 // not strict means that the selected folder has priority
4122 if (!m_StatusUrlList.GetCommonDirectory().IsEmpty())
4123 return m_StatusUrlList.GetCommonDirectory();
4126 int nListItems = GetItemCount();
4127 for (int i=0; i<nListItems; ++i)
4129 const CTGitPath& baseURL = CTGitPath(GetListEntry(i)->GetURL());
4130 if (baseURL.IsEmpty())
4131 continue; // item has no url
4132 if(commonBaseURL.IsEmpty())
4134 commonBaseURL = baseURL;
4136 else
4138 if (commonBaseURL.GetGitPathString().GetLength() > baseURL.GetGitPathString().GetLength())
4140 if (baseURL.IsAncestorOf(commonBaseURL))
4141 commonBaseURL = baseURL;
4146 #endif
4147 return commonBaseURL;
4150 void CGitStatusListCtrl::SelectAll(bool bSelect, bool bIncludeNoCommits)
4152 CWaitCursor waitCursor;
4153 // block here so the LVN_ITEMCHANGED messages
4154 // get ignored
4155 m_bBlock = TRUE;
4156 SetRedraw(FALSE);
4158 int nListItems = GetItemCount();
4159 if (bSelect)
4160 m_nSelected = nListItems;
4161 else
4162 m_nSelected = 0;
4164 for (int i=0; i<nListItems; ++i)
4166 //FileEntry * entry = GetListEntry(i);
4167 //ASSERT(entry != NULL);
4168 CTGitPath *path = (CTGitPath *) GetItemData(i);
4169 if (path == NULL)
4170 continue;
4171 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
4172 SetEntryCheck(path,i,bSelect);
4175 // unblock before redrawing
4176 m_bBlock = FALSE;
4177 SetRedraw(TRUE);
4178 GetStatisticsString();
4179 NotifyCheck();
4182 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)
4184 LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);
4185 *pResult = 0;
4186 if (m_bBlock)
4187 return;
4188 #if 0
4189 if (GetListEntry(pGetInfoTip->iItem >= 0))
4190 if (pGetInfoTip->cchTextMax > GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString().GetLength())
4192 if (GetListEntry(pGetInfoTip->iItem)->GetRelativeGitPath().Compare(GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString())!= 0)
4193 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString(), pGetInfoTip->cchTextMax);
4194 else if (GetStringWidth(GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString()) > GetColumnWidth(pGetInfoTip->iItem))
4195 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString(), pGetInfoTip->cchTextMax);
4197 #endif
4200 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
4202 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
4204 // Take the default processing unless we set this to something else below.
4205 *pResult = CDRF_DODEFAULT;
4207 // First thing - check the draw stage. If it's the control's prepaint
4208 // stage, then tell Windows we want messages for every item.
4210 switch (pLVCD->nmcd.dwDrawStage)
4212 case CDDS_PREPAINT:
4213 *pResult = CDRF_NOTIFYITEMDRAW;
4214 break;
4215 case CDDS_ITEMPREPAINT:
4217 // This is the prepaint stage for an item. Here's where we set the
4218 // item's text color. Our return value will tell Windows to draw the
4219 // item itself, but it will use the new color we set here.
4221 // Tell Windows to paint the control itself.
4222 *pResult = CDRF_DODEFAULT;
4223 if (m_bBlock)
4224 return;
4226 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
4228 if (m_arStatusArray.size() > (DWORD_PTR)pLVCD->nmcd.dwItemSpec)
4231 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
4232 CTGitPath *entry=(CTGitPath *)GetItemData((int)pLVCD->nmcd.dwItemSpec);
4233 if (entry == NULL)
4234 return;
4236 // coloring
4237 // ========
4238 // black : unversioned, normal
4239 // purple : added
4240 // blue : modified
4241 // brown : missing, deleted, replaced
4242 // green : merged (or potential merges)
4243 // red : conflicts or sure conflicts
4244 if(entry->m_Action & CTGitPath::LOGACTIONS_GRAY)
4246 crText = RGB(128,128,128);
4248 }else if(entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
4250 crText = m_Colors.GetColor(CColors::Conflict);
4252 }else if(entry->m_Action & (CTGitPath::LOGACTIONS_MODIFIED))
4254 crText = m_Colors.GetColor(CColors::Modified);
4256 }else if(entry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
4258 crText = m_Colors.GetColor(CColors::Added);
4260 else if(entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
4262 crText = m_Colors.GetColor(CColors::DeletedNode);
4264 else if(entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
4266 crText = m_Colors.GetColor(CColors::RenamedNode);
4267 }else
4269 crText = GetSysColor(COLOR_WINDOWTEXT);
4271 // Store the color back in the NMLVCUSTOMDRAW struct.
4272 pLVCD->clrText = crText;
4275 break;
4279 BOOL CGitStatusListCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
4281 if (pWnd != this)
4282 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
4283 if (!m_bBlock)
4285 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
4286 SetCursor(hCur);
4287 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
4289 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
4290 SetCursor(hCur);
4291 return TRUE;
4294 void CGitStatusListCtrl::RemoveListEntry(int index)
4297 Locker lock(m_critSec);
4298 DeleteItem(index);
4300 m_arStatusArray.erase(m_arStatusArray.begin()+index);
4302 #if 0
4303 delete m_arStatusArray[m_arListArray[index]];
4304 m_arStatusArray.erase(m_arStatusArray.begin()+m_arListArray[index]);
4305 m_arListArray.erase(m_arListArray.begin()+index);
4306 for (int i=index; i< (int)m_arListArray.size(); ++i)
4308 m_arListArray[i]--;
4310 #endif
4313 ///< Set a checkbox on an entry in the listbox
4314 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
4315 void CGitStatusListCtrl::SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck)
4317 pEntry->m_Checked = bCheck;
4318 SetCheck(listboxIndex, bCheck);
4321 #if 0
4322 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck)
4325 int nListItems = GetItemCount();
4326 for (int j=0; j< nListItems ; ++j)
4328 FileEntry * childEntry = GetListEntry(j);
4329 ASSERT(childEntry != NULL);
4330 if (childEntry == NULL || childEntry == parentEntry)
4331 continue;
4332 if (childEntry->checked != bCheck)
4334 if (parentEntry->path.IsAncestorOf(childEntry->path))
4336 SetEntryCheck(childEntry,j,bCheck);
4337 if(bCheck)
4339 m_nSelected++;
4341 else
4343 m_nSelected--;
4350 #endif
4352 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList& pathList)
4355 pathList.Clear();
4356 int nListItems = GetItemCount();
4357 for (int i=0; i< nListItems; i++)
4359 CTGitPath * entry = (CTGitPath*)GetItemData(i);
4360 ASSERT(entry != NULL);
4361 if (entry->m_Checked)
4363 pathList.AddPath(*entry);
4366 pathList.SortByPathname();
4371 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
4372 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList& pathList, bool bNoIgnored)
4374 pathList.Clear();
4376 POSITION pos = GetFirstSelectedItemPosition();
4377 int index;
4378 while ((index = GetNextSelectedItem(pos)) >= 0)
4380 CTGitPath * entry = (CTGitPath*)GetItemData(index);
4381 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
4382 // continue;
4383 pathList.AddPath(*entry);
4387 UINT CGitStatusListCtrl::OnGetDlgCode()
4389 // we want to process the return key and not have that one
4390 // routed to the default pushbutton
4391 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS;
4394 void CGitStatusListCtrl::OnNMReturn(NMHDR * /*pNMHDR*/, LRESULT *pResult)
4396 *pResult = 0;
4397 if (m_bBlock)
4398 return;
4399 POSITION pos = GetFirstSelectedItemPosition();
4400 while ( pos )
4402 int index = GetNextSelectedItem(pos);
4403 StartDiff(index);
4407 void CGitStatusListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
4409 // Since we catch all keystrokes (to have the enter key processed here instead
4410 // of routed to the default pushbutton) we have to make sure that other
4411 // keys like Tab and Esc still do what they're supposed to do
4412 // Tab = change focus to next/previous control
4413 // Esc = quit the dialog
4414 switch (nChar)
4416 case (VK_TAB):
4418 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL, GetKeyState(VK_SHIFT)&0x8000, 0);
4419 return;
4421 break;
4422 case (VK_ESCAPE):
4424 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE, 0, 0);
4426 break;
4429 CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
4432 void CGitStatusListCtrl::PreSubclassWindow()
4434 CListCtrl::PreSubclassWindow();
4435 EnableToolTips(TRUE);
4436 m_Theme.SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);
4439 INT_PTR CGitStatusListCtrl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
4441 int row, col;
4442 RECT cellrect;
4443 row = CellRectFromPoint(point, &cellrect, &col );
4445 if (row == -1)
4446 return -1;
4449 pTI->hwnd = m_hWnd;
4450 pTI->uId = (UINT)((row<<10)+(col&0x3ff)+1);
4451 pTI->lpszText = LPSTR_TEXTCALLBACK;
4453 pTI->rect = cellrect;
4455 return pTI->uId;
4458 int CGitStatusListCtrl::CellRectFromPoint(CPoint& point, RECT *cellrect, int *col) const
4460 int colnum;
4462 // Make sure that the ListView is in LVS_REPORT
4463 if ((GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
4464 return -1;
4466 // Get the top and bottom row visible
4467 int row = GetTopIndex();
4468 int bottom = row + GetCountPerPage();
4469 if (bottom > GetItemCount())
4470 bottom = GetItemCount();
4472 // Get the number of columns
4473 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
4474 int nColumnCount = pHeader->GetItemCount();
4476 // Loop through the visible rows
4477 for ( ;row <=bottom;row++)
4479 // Get bounding rect of item and check whether point falls in it.
4480 CRect rect;
4481 GetItemRect(row, &rect, LVIR_BOUNDS);
4482 if (rect.PtInRect(point))
4484 // Now find the column
4485 for (colnum = 0; colnum < nColumnCount; colnum++)
4487 int colwidth = GetColumnWidth(colnum);
4488 if (point.x >= rect.left && point.x <= (rect.left + colwidth))
4490 RECT rectClient;
4491 GetClientRect(&rectClient);
4492 if (col)
4493 *col = colnum;
4494 rect.right = rect.left + colwidth;
4496 // Make sure that the right extent does not exceed
4497 // the client area
4498 if (rect.right > rectClient.right)
4499 rect.right = rectClient.right;
4500 *cellrect = rect;
4501 return row;
4503 rect.left += colwidth;
4507 return -1;
4510 BOOL CGitStatusListCtrl::OnToolTipText(UINT /*id*/, NMHDR *pNMHDR, LRESULT *pResult)
4512 #if 0
4513 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4514 CString strTipText;
4515 UINT_PTR nID = pNMHDR->idFrom;
4517 if (nID == 0)
4518 return FALSE;
4520 UINT_PTR row = ((nID-1) >> 10) & 0x3fffff;
4521 UINT_PTR col = (nID-1) & 0x3ff;
4523 if (col == 0)
4524 return FALSE; // no custom tooltip for the path, we use the infotip there!
4526 // get the internal column from the visible columns
4527 int internalcol = 0;
4528 UINT_PTR currentcol = 0;
4529 for (; (currentcol != col)
4530 && (internalcol < m_ColumnManager.GetColumnCount()-1)
4531 ; ++internalcol)
4533 if (m_ColumnManager.IsVisible (internalcol))
4534 currentcol++;
4537 AFX_MODULE_THREAD_STATE* pModuleThreadState = AfxGetModuleThreadState();
4538 CToolTipCtrl* pToolTip = pModuleThreadState->m_pToolTip;
4539 pToolTip->SendMessage(TTM_SETMAXTIPWIDTH, 0, 300);
4541 *pResult = 0;
4542 if ((internalcol == 2)||(internalcol == 4))
4544 FileEntry *fentry = GetListEntry(row);
4545 if (fentry)
4547 if (fentry->copied)
4549 CString url;
4550 url.Format(IDS_STATUSLIST_COPYFROM, (LPCTSTR)CPathUtils::PathUnescape(fentry->copyfrom_url), (LONG)fentry->copyfrom_rev);
4551 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4552 return TRUE;
4554 if (fentry->switched)
4556 CString url;
4557 url.Format(IDS_STATUSLIST_SWITCHEDTO, (LPCTSTR)CPathUtils::PathUnescape(fentry->url));
4558 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4559 return TRUE;
4561 if (fentry->keeplocal)
4563 lstrcpyn(pTTTW->szText, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_KEEPLOCAL)), 80);
4564 return TRUE;
4568 #endif
4569 return FALSE;
4572 void CGitStatusListCtrl::OnPaint()
4574 Default();
4575 if ((m_bBusy)||(m_bEmpty))
4577 CString str;
4578 if (m_bBusy)
4580 if (m_sBusy.IsEmpty())
4581 str.LoadString(IDS_STATUSLIST_BUSYMSG);
4582 else
4583 str = m_sBusy;
4585 else
4587 if (m_sEmpty.IsEmpty())
4588 str.LoadString(IDS_STATUSLIST_EMPTYMSG);
4589 else
4590 str = m_sEmpty;
4592 COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
4593 COLORREF clrTextBk;
4594 if (IsWindowEnabled())
4595 clrTextBk = ::GetSysColor(COLOR_WINDOW);
4596 else
4597 clrTextBk = ::GetSysColor(COLOR_3DFACE);
4599 CRect rc;
4600 GetClientRect(&rc);
4601 CHeaderCtrl* pHC;
4602 pHC = GetHeaderCtrl();
4603 if (pHC != NULL)
4605 CRect rcH;
4606 pHC->GetItemRect(0, &rcH);
4607 rc.top += rcH.bottom;
4609 CDC* pDC = GetDC();
4611 CMyMemDC memDC(pDC, &rc);
4613 memDC.SetTextColor(clrText);
4614 memDC.SetBkColor(clrTextBk);
4615 memDC.FillSolidRect(rc, clrTextBk);
4616 rc.top += 10;
4617 CGdiObject * oldfont = memDC.SelectStockObject(DEFAULT_GUI_FONT);
4618 memDC.DrawText(str, rc, DT_CENTER | DT_VCENTER |
4619 DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
4620 memDC.SelectObject(oldfont);
4622 ReleaseDC(pDC);
4626 // prevent users from extending our hidden (size 0) columns
4627 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
4629 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
4630 *pResult = 0;
4631 if ((phdr->iItem < 0)||(phdr->iItem >= SVNSLC_NUMCOLUMNS))
4632 return;
4634 if (m_ColumnManager.IsVisible (phdr->iItem))
4636 return;
4638 *pResult = 1;
4641 // prevent any function from extending our hidden (size 0) columns
4642 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
4644 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
4645 *pResult = 0;
4646 if ((phdr->iItem < 0)||(phdr->iItem >= m_ColumnManager.GetColumnCount()))
4648 Default();
4649 return;
4652 // visible columns may be modified
4654 if (m_ColumnManager.IsVisible (phdr->iItem))
4656 Default();
4657 return;
4660 // columns already marked as "invisible" internally may be (re-)sized to 0
4662 if ( (phdr->pitem != NULL)
4663 && (phdr->pitem->mask == HDI_WIDTH)
4664 && (phdr->pitem->cxy == 0))
4666 Default();
4667 return;
4670 if ( (phdr->pitem != NULL)
4671 && (phdr->pitem->mask != HDI_WIDTH))
4673 Default();
4674 return;
4677 *pResult = 1;
4680 void CGitStatusListCtrl::OnDestroy()
4682 SaveColumnWidths(true);
4683 CListCtrl::OnDestroy();
4686 void CGitStatusListCtrl::OnBeginDrag(NMHDR* /*pNMHDR*/, LRESULT* pResult)
4688 #if 0
4689 Locker lock(m_critSec);
4690 CDropFiles dropFiles; // class for creating DROPFILES struct
4692 int index;
4693 POSITION pos = GetFirstSelectedItemPosition();
4694 while ( (index = GetNextSelectedItem(pos)) >= 0 )
4696 FileEntry * fentry = m_arStatusArray[m_arListArray[index]];
4697 CTGitPath path = fentry->GetPath();
4698 dropFiles.AddFile( path.GetWinPathString() );
4701 if ( dropFiles.GetCount()>0 )
4703 m_bOwnDrag = true;
4704 dropFiles.CreateStructure();
4705 m_bOwnDrag = false;
4707 #endif
4708 *pResult = 0;
4711 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry /* = false */)
4713 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
4714 for (int col = 0; col <= maxcol; col++)
4715 if (m_ColumnManager.IsVisible (col))
4716 m_ColumnManager.ColumnResized (col);
4718 if (bSaveToRegistry)
4719 m_ColumnManager.WriteSettings();
4722 bool CGitStatusListCtrl::EnableFileDrop()
4724 m_bFileDropsEnabled = true;
4725 return true;
4728 bool CGitStatusListCtrl::HasPath(const CTGitPath& path)
4730 #if 0
4731 for (size_t i=0; i < m_arStatusArray.size(); i++)
4733 FileEntry * entry = m_arStatusArray[i];
4734 if (entry->GetPath().IsEquivalentTo(path))
4735 return true;
4737 #endif
4738 return false;
4741 bool CGitStatusListCtrl::IsPathShown(const CTGitPath& path)
4743 #if 0
4744 int itemCount = GetItemCount();
4745 for (int i=0; i < itemCount; i++)
4747 FileEntry * entry = GetListEntry(i);
4748 if (entry->GetPath().IsEquivalentTo(path))
4749 return true;
4751 #endif
4752 return false;
4755 BOOL CGitStatusListCtrl::PreTranslateMessage(MSG* pMsg)
4757 if (pMsg->message == WM_KEYDOWN)
4759 switch (pMsg->wParam)
4761 case 'A':
4763 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4765 // select all entries
4766 for (int i=0; i<GetItemCount(); ++i)
4768 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
4770 return TRUE;
4773 break;
4774 case 'C':
4775 case VK_INSERT:
4777 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4779 // copy all selected paths to the clipboard
4780 if (GetAsyncKeyState(VK_SHIFT)&0x8000)
4781 CopySelectedEntriesToClipboard(SVNSLC_COLSTATUS);
4782 else
4783 CopySelectedEntriesToClipboard(0);
4784 return TRUE;
4787 break;
4791 return CListCtrl::PreTranslateMessage(pMsg);
4794 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols)
4797 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
4798 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
4799 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4801 CString sClipboard;
4802 CString temp;
4803 TCHAR buf[100];
4804 if (GetSelectedCount() == 0)
4805 return false;
4806 // first add the column titles as the first line
4807 temp.LoadString(IDS_STATUSLIST_COLFILE);
4808 sClipboard = temp;
4810 DWORD selection = 0;
4811 for (int i = 0, count = m_ColumnManager.GetColumnCount(); i < count; ++i)
4812 if ( ((dwCols == -1) && m_ColumnManager.IsVisible (i))
4813 || ((dwCols != 1) && (i < 32) && ((dwCols & (1 << i)) != 0)))
4815 sClipboard += _T("\t") + m_ColumnManager.GetName(i);
4817 if (i < 32)
4818 selection += 1 << i;
4821 sClipboard += _T("\r\n");
4823 POSITION pos = GetFirstSelectedItemPosition();
4824 int index;
4825 while ((index = GetNextSelectedItem(pos)) >= 0)
4827 CTGitPath * entry = (CTGitPath*)GetItemData(index);
4828 if(entry == NULL)
4829 continue;
4831 sClipboard += entry->GetWinPathString();
4832 if (selection & SVNSLC_COLFILENAME)
4834 sClipboard += _T("\t")+entry->GetFileOrDirectoryName();
4836 if (selection & SVNSLC_COLEXT)
4838 sClipboard += _T("\t")+entry->GetFileExtension();
4841 if (selection & SVNSLC_COLSTATUS)
4843 #if 0
4844 if (entry->isNested)
4846 temp.LoadString(IDS_STATUSLIST_NESTED);
4848 else
4850 GitStatus::GetStatusString(hResourceHandle, entry->status, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4851 if ((entry->copied)&&(_tcslen(buf)>1))
4852 _tcscat_s(buf, 100, _T(" (+)"));
4853 if ((entry->switched)&&(_tcslen(buf)>1))
4854 _tcscat_s(buf, 100, _T(" (s)"));
4855 if ((entry->status == entry->propstatus)&&
4856 (entry->status != git_wc_status_normal)&&
4857 (entry->status != git_wc_status_unversioned)&&
4858 (!GitStatus::IsImportant(entry->textstatus)))
4859 _tcscat_s(buf, 100, ponly);
4860 temp = buf;
4862 #endif
4863 sClipboard += _T("\t")+entry->GetActionName();
4865 #if 0
4866 if (selection & SVNSLC_COLTEXTSTATUS)
4869 if (entry->isNested)
4871 temp.LoadString(IDS_STATUSLIST_NESTED);
4873 else
4875 GitStatus::GetStatusString(hResourceHandle, entry->textstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4876 if ((entry->copied)&&(_tcslen(buf)>1))
4877 _tcscat_s(buf, 100, _T(" (+)"));
4878 if ((entry->switched)&&(_tcslen(buf)>1))
4879 _tcscat_s(buf, 100, _T(" (s)"));
4880 temp = buf;
4882 sClipboard += _T("\t")+temp;
4884 #endif
4885 #if 0
4886 if (selection & SVNSLC_COLREMOTESTATUS)
4888 if (entry->isNested)
4890 temp.LoadString(IDS_STATUSLIST_NESTED);
4892 else
4894 GitStatus::GetStatusString(hResourceHandle, entry->remotestatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4895 if ((entry->copied)&&(_tcslen(buf)>1))
4896 _tcscat_s(buf, 100, _T(" (+)"));
4897 if ((entry->switched)&&(_tcslen(buf)>1))
4898 _tcscat_s(buf, 100, _T(" (s)"));
4899 if ((entry->remotestatus == entry->remotepropstatus)&&
4900 (entry->remotestatus != git_wc_status_none)&&
4901 (entry->remotestatus != git_wc_status_normal)&&
4902 (entry->remotestatus != git_wc_status_unversioned)&&
4903 (!SVNStatus::IsImportant(entry->remotetextstatus)))
4904 _tcscat_s(buf, 100, ponly);
4905 temp = buf;
4907 sClipboard += _T("\t")+temp;
4909 if (selection & GitSLC_COLPROPSTATUS)
4911 if (entry->isNested)
4913 temp.Empty();
4915 else
4917 GitStatus::GetStatusString(hResourceHandle, entry->propstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4918 if ((entry->copied)&&(_tcslen(buf)>1))
4919 _tcscat_s(buf, 100, _T(" (+)"));
4920 if ((entry->switched)&&(_tcslen(buf)>1))
4921 _tcscat_s(buf, 100, _T(" (s)"));
4922 temp = buf;
4924 sClipboard += _T("\t")+temp;
4926 if (selection & SVNSLC_COLREMOTETEXT)
4928 if (entry->isNested)
4930 temp.Empty();
4932 else
4934 GitStatus::GetStatusString(hResourceHandle, entry->remotetextstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4935 temp = buf;
4937 sClipboard += _T("\t")+temp;
4939 if (selection & SVNSLC_COLREMOTEPROP)
4941 // SVNSLC_COLREMOTEPROP
4942 if (entry->isNested)
4944 temp.Empty();
4946 else
4948 GitStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4949 temp = buf;
4951 sClipboard += _T("\t")+temp;
4953 if (selection & SVNSLC_COLURL)
4954 sClipboard += _T("\t")+entry->url;
4955 if (selection & SVNSLC_COLLOCK)
4957 if (!m_HeadRev.IsHead())
4959 // we have contacted the repository
4961 // decision-matrix
4962 // wc repository text
4963 // "" "" ""
4964 // "" UID1 owner
4965 // UID1 UID1 owner
4966 // UID1 "" lock has been broken
4967 // UID1 UID2 lock has been stolen
4968 if (entry->lock_token.IsEmpty() || (entry->lock_token.Compare(entry->lock_remotetoken)==0))
4970 if (entry->lock_owner.IsEmpty())
4971 temp = entry->lock_remoteowner;
4972 else
4973 temp = entry->lock_owner;
4975 else if (entry->lock_remotetoken.IsEmpty())
4977 // broken lock
4978 temp.LoadString(IDS_STATUSLIST_LOCKBROKEN);
4980 else
4982 // stolen lock
4983 temp.Format(IDS_STATUSLIST_LOCKSTOLEN, (LPCTSTR)entry->lock_remoteowner);
4986 else
4987 temp = entry->lock_owner;
4988 sClipboard += _T("\t")+temp;
4990 if (selection & SVNSLC_COLLOCKCOMMENT)
4991 sClipboard += _T("\t")+entry->lock_comment;
4992 if (selection & SVNSLC_COLAUTHOR)
4993 sClipboard += _T("\t")+entry->last_commit_author;
4994 if (selection & SVNSLC_COLREVISION)
4996 temp.Format(_T("%ld"), entry->last_commit_rev);
4997 if (entry->last_commit_rev == 0)
4998 temp.Empty();
4999 sClipboard += _T("\t")+temp;
5001 if (selection & SVNSLC_COLREMOTEREVISION)
5003 temp.Format(_T("%ld"), entry->remoterev);
5004 if (entry->remoterev == 0)
5005 temp.Empty();
5006 sClipboard += _T("\t")+temp;
5009 if (selection & SVNSLC_COLDATE)
5011 TCHAR datebuf[SVN_DATE_BUFFER];
5012 apr_time_t date = entry->last_commit_date;
5013 SVN::formatDate(datebuf, date, true);
5014 if (date)
5015 temp = datebuf;
5016 else
5017 temp.Empty();
5018 sClipboard += _T("\t")+temp;
5020 if (selection & SVNSLC_COLCOPYFROM)
5022 if (m_sURL.Compare(entry->copyfrom_url.Left(m_sURL.GetLength()))==0)
5023 temp = entry->copyfrom_url.Mid(m_sURL.GetLength());
5024 else
5025 temp = entry->copyfrom_url;
5026 sClipboard += _T("\t")+temp;
5029 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
5030 ; i < count
5031 ; ++i)
5033 if ((dwCols == -1) && m_ColumnManager.IsVisible (i))
5035 CString value
5036 = entry->present_props[m_ColumnManager.GetName(i)];
5037 sClipboard += _T("\t") + value;
5040 #endif
5041 if (selection & SVNSLC_COLADD)
5043 sClipboard += _T("\t")+entry->m_StatAdd;
5045 if (selection & SVNSLC_COLDEL)
5047 sClipboard += _T("\t")+entry->m_StatDel;
5050 sClipboard += _T("\r\n");
5053 return CStringUtils::WriteAsciiStringToClipboard(sClipboard);
5055 return TRUE;
5059 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
5061 #if 0
5062 std::set<CString> changelists;
5063 POSITION pos = GetFirstSelectedItemPosition();
5064 int index;
5065 while ((index = GetNextSelectedItem(pos)) >= 0)
5067 FileEntry * entry = GetListEntry(index);
5068 if (!entry->changelist.IsEmpty())
5069 changelists.insert(entry->changelist);
5071 return changelists.size();
5072 #endif
5073 return 0;
5076 bool CGitStatusListCtrl::PrepareGroups(bool bForce /* = false */)
5079 bool bHasGroups=false;
5080 if ( this->m_UnRevFileList.GetCount()>0 ||
5081 this->m_IgnoreFileList.GetCount()>0 || bForce)
5083 bHasGroups = true;
5086 RemoveAllGroups();
5087 EnableGroupView(bHasGroups);
5089 TCHAR groupname[1024];
5090 int groupindex = 0;
5092 if(bHasGroups)
5094 LVGROUP grp = {0};
5095 grp.cbSize = sizeof(LVGROUP);
5096 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5097 CString sUnassignedName(_T("Modified File"));
5098 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
5099 grp.pszHeader = groupname;
5100 grp.iGroupId = groupindex;
5101 grp.uAlign = LVGA_HEADER_LEFT;
5102 InsertGroup(groupindex++, &grp);
5104 //if(m_UnRevFileList.GetCount()>0)
5106 _tcsncpy_s(groupname, 1024, (LPCTSTR)_T("No Version Control"), 1023);
5107 grp.pszHeader = groupname;
5108 grp.iGroupId = groupindex;
5109 grp.uAlign = LVGA_HEADER_LEFT;
5110 InsertGroup(groupindex++, &grp);
5113 //if(m_IgnoreFileList.GetCount()>0)
5115 _tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Ignored File"), 1023);
5116 grp.pszHeader = groupname;
5117 grp.iGroupId = groupindex;
5118 grp.uAlign = LVGA_HEADER_LEFT;
5119 InsertGroup(groupindex++, &grp);
5124 #if 0
5125 m_bHasIgnoreGroup = false;
5127 // now add the items which don't belong to a group
5128 LVGROUP grp = {0};
5129 grp.cbSize = sizeof(LVGROUP);
5130 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5131 CString sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET));
5132 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
5133 grp.pszHeader = groupname;
5134 grp.iGroupId = groupindex;
5135 grp.uAlign = LVGA_HEADER_LEFT;
5136 InsertGroup(groupindex++, &grp);
5138 for (std::map<CString,int>::iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
5140 if (it->first.Compare(SVNSLC_IGNORECHANGELIST)!=0)
5142 LVGROUP grp = {0};
5143 grp.cbSize = sizeof(LVGROUP);
5144 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5145 _tcsncpy_s(groupname, 1024, it->first, 1023);
5146 grp.pszHeader = groupname;
5147 grp.iGroupId = groupindex;
5148 grp.uAlign = LVGA_HEADER_LEFT;
5149 it->second = InsertGroup(groupindex++, &grp);
5151 else
5152 m_bHasIgnoreGroup = true;
5155 if (m_bHasIgnoreGroup)
5157 // and now add the group 'ignore-on-commit'
5158 std::map<CString,int>::iterator it = m_changelists.find(SVNSLC_IGNORECHANGELIST);
5159 if (it != m_changelists.end())
5161 grp.cbSize = sizeof(LVGROUP);
5162 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5163 _tcsncpy_s(groupname, 1024, SVNSLC_IGNORECHANGELIST, 1023);
5164 grp.pszHeader = groupname;
5165 grp.iGroupId = groupindex;
5166 grp.uAlign = LVGA_HEADER_LEFT;
5167 it->second = InsertGroup(groupindex, &grp);
5170 #endif
5171 return bHasGroups;
5174 void CGitStatusListCtrl::NotifyCheck()
5176 CWnd* pParent = GetParent();
5177 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
5179 pParent->SendMessage(SVNSLNM_CHECKCHANGED, m_nSelected);
5183 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash,CTGitPathList *list)
5185 BYTE_VECTOR out;
5186 this->m_bBusy=TRUE;
5187 m_CurrentVersion=hash;
5189 int count = 0;
5190 if(list == NULL)
5191 count = 1;
5192 else
5193 count = list->GetCount();
5195 if(hash == GIT_REV_ZERO)
5197 for(int i=0;i<count;i++)
5199 BYTE_VECTOR cmdout;
5200 cmdout.clear();
5201 CString cmd;
5202 if(!g_Git.IsInitRepos())
5204 if(list == NULL)
5205 cmd=(_T("git.exe diff-index --raw HEAD --numstat -C -M -z"));
5206 else
5207 cmd.Format(_T("git.exe diff-index --raw HEAD --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
5209 if(g_Git.Run(cmd,&cmdout))
5211 cmdout.clear();
5212 CString strout;
5213 if(g_Git.Run(_T("git.exe rev-parse --revs-only HEAD"),&strout,CP_UTF8))
5215 CMessageBox::Show(NULL,strout,_T("TortoiseGit"),MB_OK);
5216 return -1;
5218 if(strout.IsEmpty())
5219 break; //this is initial repositoyr, there are no any history
5221 CMessageBox::Show(NULL,strout,_T("TortoiseGit"),MB_OK);
5222 return -1;
5226 if(list == NULL)
5227 cmd=(_T("git.exe diff-index --cached --raw HEAD --numstat -C -M -z"));
5228 else
5229 cmd.Format(_T("git.exe diff-index --cached --raw HEAD --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
5231 g_Git.Run(cmd,&cmdout);
5232 //out+=cmdout;
5233 out.append(cmdout,0);
5235 else // Init Repository
5237 if(list == NULL)
5238 cmd=_T("git.exe ls-files -s -t -z");
5239 else
5240 cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
5242 g_Git.Run(cmd,&cmdout);
5243 //out+=cmdout;
5244 out.append(cmdout,0);
5248 if(g_Git.IsInitRepos())
5250 m_StatusFileList.ParserFromLsFile(out);
5251 for(int i=0;i<m_StatusFileList.GetCount();i++)
5252 ((CTGitPath&)(m_StatusFileList[i])).m_Action=CTGitPath::LOGACTIONS_ADDED;
5254 else
5255 this->m_StatusFileList.ParserFromLog(out);
5257 //handle delete conflict case, when remote : modified, local : deleted.
5258 for(int i=0;i<count;i++)
5260 BYTE_VECTOR cmdout;
5261 CString cmd;
5263 if(list == NULL)
5264 cmd=_T("git.exe ls-files -u -t -z");
5265 else
5266 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list)[i].GetGitPathString());
5268 g_Git.Run(cmd,&cmdout);
5270 CTGitPathList conflictlist;
5271 conflictlist.ParserFromLog(cmdout);
5272 for(int i=0;i<conflictlist.GetCount();i++)
5274 CTGitPath *p=m_StatusFileList.LookForGitPath(conflictlist[i].GetGitPathString());
5275 if(p)
5276 p->m_Action|=CTGitPath::LOGACTIONS_UNMERGED;
5277 else
5278 m_StatusFileList.AddPath(conflictlist[i]);
5282 }else
5284 int count = 0;
5285 if(list == NULL)
5286 count = 1;
5287 else
5288 count = list->GetCount();
5290 for(int i=0;i<count;i++)
5292 BYTE_VECTOR cmdout;
5293 CString cmd;
5294 if(list == NULL)
5295 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash);
5296 else
5297 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash,(*list)[i].GetGitPathString());
5299 g_Git.Run(cmd,&cmdout);
5301 out.append(cmdout);
5303 this->m_StatusFileList.ParserFromLog(out);
5307 for(int i=0;i<m_StatusFileList.GetCount();i++)
5309 CTGitPath * gitpatch=(CTGitPath*)&m_StatusFileList[i];
5310 gitpatch->m_Checked = TRUE;
5311 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
5314 this->m_bBusy=FALSE;
5315 return 0;
5318 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList &list)
5320 m_arStatusArray.clear();
5321 for(int i=0;i<list.GetCount();i++)
5323 CTGitPath * gitpath=(CTGitPath*)&list[i];
5325 if(gitpath ->m_Action & CTGitPath::LOGACTIONS_HIDE)
5326 continue;
5328 gitpath->m_Checked = TRUE;
5329 m_arStatusArray.push_back((CTGitPath*)&list[i]);
5331 return 0;
5334 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList *List)
5336 this->m_UnRevFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER,List);
5337 for(int i=0;i<m_UnRevFileList.GetCount();i++)
5339 CTGitPath * gitpatch=(CTGitPath*)&m_UnRevFileList[i];
5340 gitpatch->m_Checked = FALSE;
5341 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
5343 return 0;
5346 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList *List)
5348 this->m_IgnoreFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER|CTGitPath::LOGACTIONS_IGNORE,List);
5349 for(int i=0;i<m_IgnoreFileList.GetCount();i++)
5351 CTGitPath * gitpatch=(CTGitPath*)&m_IgnoreFileList[i];
5352 gitpatch->m_Checked = FALSE;
5353 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
5355 return 0;
5357 int CGitStatusListCtrl::UpdateFileList(int mask,bool once,CTGitPathList *List)
5359 if(mask&CGitStatusListCtrl::FILELIST_MODIFY)
5361 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_MODIFY)))
5363 UpdateFileList(git_revnum_t(GIT_REV_ZERO),List);
5364 m_FileLoaded|=CGitStatusListCtrl::FILELIST_MODIFY;
5367 if(mask&CGitStatusListCtrl::FILELIST_UNVER)
5369 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_UNVER)))
5371 UpdateUnRevFileList(List);
5372 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
5375 return 0;
5378 void CGitStatusListCtrl::Clear()
5380 m_FileLoaded=0;
5381 this->DeleteAllItems();
5382 this->m_arListArray.clear();
5383 this->m_arStatusArray.clear();
5384 this->m_changelists.clear();
5386 //////////////////////////////////////////////////////////////////////////
5387 #if 0
5388 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD * /*pdwEffect*/, POINTL pt)
5390 if(pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
5392 HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
5393 if(hDrop != NULL)
5395 TCHAR szFileName[MAX_PATH];
5397 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
5399 POINT clientpoint;
5400 clientpoint.x = pt.x;
5401 clientpoint.y = pt.y;
5402 ScreenToClient(m_hTargetWnd, &clientpoint);
5403 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5405 CTSVNPathList changelistItems;
5406 for(UINT i = 0; i < cFiles; ++i)
5408 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5409 changelistItems.AddPath(CTSVNPath(szFileName));
5411 // find the changelist name
5412 CString sChangelist;
5413 LONG_PTR nGroup = m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint);
5414 for (std::map<CString, int>::iterator it = m_pSVNStatusListCtrl->m_changelists.begin(); it != m_pSVNStatusListCtrl->m_changelists.end(); ++it)
5415 if (it->second == nGroup)
5416 sChangelist = it->first;
5417 if (!sChangelist.IsEmpty())
5419 SVN git;
5420 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
5422 for (int l=0; l<changelistItems.GetCount(); ++l)
5424 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5425 if (index >= 0)
5427 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5428 if (e)
5430 e->changelist = sChangelist;
5431 if (!e->IsFolder())
5433 if (m_pSVNStatusListCtrl->m_changelists.find(e->changelist)!=m_pSVNStatusListCtrl->m_changelists.end())
5434 m_pSVNStatusListCtrl->SetItemGroup(index, m_pSVNStatusListCtrl->m_changelists[e->changelist]);
5435 else
5436 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5440 else
5442 HWND hParentWnd = GetParent(m_hTargetWnd);
5443 if (hParentWnd != NULL)
5444 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5448 else
5450 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
5453 else
5455 SVN git;
5456 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
5458 for (int l=0; l<changelistItems.GetCount(); ++l)
5460 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5461 if (index >= 0)
5463 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5464 if (e)
5466 e->changelist = sChangelist;
5467 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5470 else
5472 HWND hParentWnd = GetParent(m_hTargetWnd);
5473 if (hParentWnd != NULL)
5474 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5478 else
5480 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
5484 else
5486 for(UINT i = 0; i < cFiles; ++i)
5488 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5489 HWND hParentWnd = GetParent(m_hTargetWnd);
5490 if (hParentWnd != NULL)
5491 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)szFileName);
5495 GlobalUnlock(medium.hGlobal);
5497 return true; //let base free the medium
5499 HRESULT STDMETHODCALLTYPE CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)
5501 CIDropTarget::DragOver(grfKeyState, pt, pdwEffect);
5502 *pdwEffect = DROPEFFECT_COPY;
5503 if (m_pSVNStatusListCtrl)
5505 POINT clientpoint;
5506 clientpoint.x = pt.x;
5507 clientpoint.y = pt.y;
5508 ScreenToClient(m_hTargetWnd, &clientpoint);
5509 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5511 *pdwEffect = DROPEFFECT_MOVE;
5513 else if ((!m_pSVNStatusListCtrl->m_bFileDropsEnabled)||(m_pSVNStatusListCtrl->m_bOwnDrag))
5515 *pdwEffect = DROPEFFECT_NONE;
5518 return S_OK;
5521 #endif
5523 void CGitStatusListCtrl::FileSaveAs(CTGitPath *path)
5525 CString filename;
5526 filename.Format(_T("%s-%s%s"),path->GetBaseFilename(),this->m_CurrentVersion.Left(6),path->GetFileExtension());
5527 CFileDialog dlg(FALSE,NULL,
5528 filename,
5529 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
5530 NULL);
5531 CString currentpath;
5532 currentpath=g_Git.m_CurrentDir+_T("\\");
5533 currentpath+=path->GetWinPathString();
5535 dlg.m_ofn.lpstrInitialDir=currentpath.GetBuffer();
5537 CString cmd,out;
5538 if(dlg.DoModal()==IDOK)
5540 filename = dlg.GetFileName();
5541 if(m_CurrentVersion == GIT_REV_ZERO)
5543 cmd.Format(_T("copy /Y \"%s\" \"%s\""),path->GetWinPath(),filename);
5544 if(g_Git.Run(cmd,&out,CP_ACP))
5546 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5547 return;
5550 }else
5552 cmd.Format(_T("git.exe cat-file -p %s:\"%s\""),m_CurrentVersion,path->GetGitPathString());
5553 if(g_Git.RunLogFile(cmd,filename))
5555 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5556 return;
5563 int CGitStatusListCtrl::RevertSelectedItemToVersion()
5565 if(this->m_CurrentVersion.IsEmpty())
5566 return 0;
5567 if(this->m_CurrentVersion == GIT_REV_ZERO)
5568 return 0;
5570 POSITION pos = GetFirstSelectedItemPosition();
5571 int index;
5572 CString cmd,out;
5573 int count =0;
5574 while ((index = GetNextSelectedItem(pos)) >= 0)
5576 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
5577 cmd.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion,fentry->GetGitPathString());
5578 out.Empty();
5579 if(g_Git.Run(cmd,&out,CP_ACP))
5581 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5583 count++;
5586 out.Format(_T("%d files revert to %s"),count,m_CurrentVersion.Left(6));
5587 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5590 void CGitStatusListCtrl::OpenFile(CTGitPath*filepath,int mode)
5592 CString file;
5593 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
5595 file= filepath->GetWinPath();
5596 }else
5598 CString temppath;
5599 GetTempPath(temppath);
5600 file.Format(_T("%s%s_%s%s"),
5601 temppath,
5602 filepath->GetBaseFilename(),
5603 m_CurrentVersion.Left(6),
5604 filepath->GetFileExtension());
5605 CString cmd,out;
5606 cmd.Format(_T("git.exe cat-file -p %s:\"%s\""),m_CurrentVersion,filepath->GetGitPathString());
5607 if(g_Git.RunLogFile(cmd,file))
5609 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5610 return;
5614 if(mode == NOTEPAD2)
5616 CString sCmd;
5617 sCmd.Format(_T("\"%s\" \"%s\""),
5618 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("notepad2.exe")), file);
5620 CAppUtils::LaunchApplication(sCmd, NULL, false);
5621 return ;
5623 int ret = HINSTANCE_ERROR;
5625 if(mode == OPEN )
5627 ret = (int)ShellExecute(this->m_hWnd, NULL,file, NULL, NULL, SW_SHOW);
5629 if (ret > HINSTANCE_ERROR)
5631 return;
5636 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
5637 cmd += file;
5638 CAppUtils::LaunchApplication(cmd, NULL, false);