remove igit and libiconv2.dll at install script
[TortoiseGit.git] / src / Git / GitStatusListCtrl.cpp
blob9575b35ca251f600732278b65f3a0718f247177e
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"));
65 const UINT CGitStatusListCtrl::SVNSLNM_ITEMCHANGED
66 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCHANGED"));
71 BEGIN_MESSAGE_MAP(CGitStatusListCtrl, CListCtrl)
72 ON_NOTIFY(HDN_ITEMCLICKA, 0, OnHdnItemclick)
73 ON_NOTIFY(HDN_ITEMCLICKW, 0, OnHdnItemclick)
74 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
75 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
76 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, OnLvnItemchanged)
77 ON_WM_CONTEXTMENU()
78 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk)
79 ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnLvnGetInfoTip)
80 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
81 ON_WM_SETCURSOR()
82 ON_WM_GETDLGCODE()
83 ON_NOTIFY_REFLECT(NM_RETURN, OnNMReturn)
84 ON_WM_KEYDOWN()
85 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
86 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
87 ON_WM_PAINT()
88 ON_NOTIFY(HDN_BEGINTRACKA, 0, &CGitStatusListCtrl::OnHdnBegintrack)
89 ON_NOTIFY(HDN_BEGINTRACKW, 0, &CGitStatusListCtrl::OnHdnBegintrack)
90 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, &CGitStatusListCtrl::OnHdnItemchanging)
91 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, &CGitStatusListCtrl::OnHdnItemchanging)
92 ON_WM_DESTROY()
93 ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBeginDrag)
94 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING, &CGitStatusListCtrl::OnLvnItemchanging)
95 END_MESSAGE_MAP()
99 CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl()
100 //, m_HeadRev(GitRev::REV_HEAD)
101 , m_pbCanceled(NULL)
102 , m_pStatLabel(NULL)
103 , m_pSelectButton(NULL)
104 , m_pConfirmButton(NULL)
105 , m_bBusy(false)
106 , m_bEmpty(false)
107 , m_bUnversionedRecurse(true)
108 , m_bShowIgnores(false)
109 , m_pDropTarget(NULL)
110 , m_bIgnoreRemoveOnly(false)
111 , m_bCheckChildrenWithParent(false)
112 , m_bUnversionedLast(true)
113 , m_bHasChangeLists(false)
114 , m_bHasLocks(false)
115 , m_bBlock(false)
116 , m_bBlockUI(false)
117 , m_bHasCheckboxes(false)
118 , m_bCheckIfGroupsExist(true)
119 , m_bFileDropsEnabled(false)
120 , m_bOwnDrag(false)
121 , m_dwDefaultColumns(0)
122 , m_ColumnManager(this)
123 , m_bAscending(false)
124 , m_nSortedColumn(-1)
125 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE))
127 m_FileLoaded=0;
128 m_critSec.Init();
129 m_bIsRevertTheirMy = false;
132 CGitStatusListCtrl::~CGitStatusListCtrl()
134 // if (m_pDropTarget)
135 // delete m_pDropTarget;
136 ClearStatusArray();
139 void CGitStatusListCtrl::ClearStatusArray()
141 #if 0
142 Locker lock(m_critSec);
143 for (size_t i=0; i < m_arStatusArray.size(); i++)
145 delete m_arStatusArray[i];
147 m_arStatusArray.clear();
148 #endif
150 #if 0
151 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(UINT_PTR index)
154 if (index >= (UINT_PTR)m_arListArray.size())
155 return NULL;
156 if (m_arListArray[index] >= m_arStatusArray.size())
157 return NULL;
158 return m_arStatusArray[m_arListArray[index]];
160 return NULL;
162 #endif
163 #if 0
164 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetVisibleListEntry(const CTGitPath& path)
166 int itemCount = GetItemCount();
167 for (int i=0; i < itemCount; i++)
169 FileEntry * entry = GetListEntry(i);
170 if (entry->GetPath().IsEquivalentTo(path))
171 return entry;
173 return NULL;
175 #endif
176 #if 0
177 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(const CTGitPath& path)
180 for (size_t i=0; i < m_arStatusArray.size(); i++)
182 FileEntry * entry = m_arStatusArray[i];
183 if (entry->GetPath().IsEquivalentTo(path))
184 return entry;
187 return NULL;
189 #endif
191 #if 0
192 int CGitStatusListCtrl::GetIndex(const CTGitPath& path)
194 int itemCount = GetItemCount();
195 for (int i=0; i < itemCount; i++)
197 FileEntry * entry = GetListEntry(i);
198 if (entry->GetPath().IsEquivalentTo(path))
199 return i;
201 return -1;
203 #endif
205 void CGitStatusListCtrl::Init(DWORD dwColumns, const CString& sColumnInfoContainer, unsigned __int64 dwContextMenus /* = GitSLC_POPALL */, bool bHasCheckboxes /* = true */)
207 Locker lock(m_critSec);
209 m_dwDefaultColumns = dwColumns | 1;
210 m_dwContextMenus = dwContextMenus;
211 m_bHasCheckboxes = bHasCheckboxes;
213 // set the extended style of the listcontrol
214 // 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.
215 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
216 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
217 if (DWORD(regFullRowSelect))
218 exStyle |= LVS_EX_FULLROWSELECT;
219 exStyle |= (bHasCheckboxes ? LVS_EX_CHECKBOXES : 0);
220 SetRedraw(false);
221 SetExtendedStyle(exStyle);
223 CXPTheme theme;
224 theme.SetWindowTheme(m_hWnd, L"Explorer", NULL);
226 m_nIconFolder = SYS_IMAGE_LIST().GetDirIconIndex();
227 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL);
229 m_ColumnManager.ReadSettings (m_dwDefaultColumns, sColumnInfoContainer);
231 // enable file drops
232 #if 0
233 if (m_pDropTarget == NULL)
235 m_pDropTarget = new CGitStatusListCtrlDropTarget(this);
236 RegisterDragDrop(m_hWnd,m_pDropTarget);
237 // create the supported formats:
238 FORMATETC ftetc={0};
239 ftetc.dwAspect = DVASPECT_CONTENT;
240 ftetc.lindex = -1;
241 ftetc.tymed = TYMED_HGLOBAL;
242 ftetc.cfFormat=CF_HDROP;
243 m_pDropTarget->AddSuportedFormat(ftetc);
245 #endif
247 SetRedraw(true);
249 m_bUnversionedRecurse = !!((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE));
252 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID)
254 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID);
257 BOOL CGitStatusListCtrl::GetStatus ( const CTGitPathList* pathList
258 , bool bUpdate /* = FALSE */
259 , bool bShowIgnores /* = false */
260 , bool bShowUnRev
261 , bool bShowUserProps /* = false */)
263 Locker lock(m_critSec);
264 int mask= CGitStatusListCtrl::FILELIST_MODIFY;
265 if(bShowIgnores)
266 mask|= CGitStatusListCtrl::FILELIST_IGNORE;
267 if(bShowUnRev)
268 mask|= CGitStatusListCtrl::FILELIST_UNVER;
269 this->UpdateFileList(mask,bUpdate,(CTGitPathList*)pathList);
272 #if 0
274 int refetchcounter = 0;
275 BOOL bRet = TRUE;
276 Invalidate();
277 // force the cursor to change
278 POINT pt;
279 GetCursorPos(&pt);
280 SetCursorPos(pt.x, pt.y);
282 m_mapFilenameToChecked.clear();
283 //m_StatusUrlList.Clear();
284 bool bHasChangelists = (m_changelists.size()>1 || (m_changelists.size()>0 && !m_bHasIgnoreGroup));
285 m_changelists.clear();
286 for (size_t i=0; i < m_arStatusArray.size(); i++)
288 FileEntry * entry = m_arStatusArray[i];
289 if ( bHasChangelists && entry->checked)
291 // If change lists are present, remember all checked entries
292 CString path = entry->GetPath().GetGitPathString();
293 m_mapFilenameToChecked[path] = true;
295 if ( (entry->status==git_wc_status_unversioned || entry->status==git_wc_status_missing ) && entry->checked )
297 // The user manually selected an unversioned or missing file. We remember
298 // this so that the selection can be restored when refreshing.
299 CString path = entry->GetPath().GetGitPathString();
300 m_mapFilenameToChecked[path] = true;
302 else if ( entry->status > git_wc_status_normal && !entry->checked )
304 // The user manually deselected a versioned file. We remember
305 // this so that the deselection can be restored when refreshing.
306 CString path = entry->GetPath().GetGitPathString();
307 m_mapFilenameToChecked[path] = false;
311 // use a sorted path list to make sure we fetch the status of
312 // parent items first, *then* the child items (if any)
313 CTGitPathList sortedPathList = pathList;
314 sortedPathList.SortByPathname();
317 bRet = TRUE;
318 m_nTargetCount = 0;
319 m_bHasExternalsFromDifferentRepos = FALSE;
320 m_bHasExternals = FALSE;
321 m_bHasUnversionedItems = FALSE;
322 m_bHasLocks = false;
323 m_bHasChangeLists = false;
324 m_bShowIgnores = bShowIgnores;
325 m_nSortedColumn = 0;
326 m_bBlock = TRUE;
327 m_bBusy = true;
328 m_bEmpty = false;
329 Invalidate();
331 // first clear possible status data left from
332 // previous GetStatus() calls
333 ClearStatusArray();
335 m_StatusFileList = sortedPathList;
337 // Since Git_client_status() returns all files, even those in
338 // folders included with Git:externals we need to check if all
339 // files we get here belongs to the same repository.
340 // It is possible to commit changes in an external folder, as long
341 // as the folder belongs to the same repository (but another path),
342 // but it is not possible to commit all files if the externals are
343 // from a different repository.
345 // To check if all files belong to the same repository, we compare the
346 // UUID's - if they're identical then the files belong to the same
347 // repository and can be committed. But if they're different, then
348 // tell the user to commit all changes in the external folders
349 // first and exit.
350 CStringA sUUID; // holds the repo UUID
351 CTGitPathList arExtPaths; // list of Git:external paths
353 GitConfig config;
355 m_sURL.Empty();
357 m_nTargetCount = sortedPathList.GetCount();
359 GitStatus status(m_pbCanceled);
360 if(m_nTargetCount > 1 && sortedPathList.AreAllPathsFilesInOneDirectory())
362 // This is a special case, where we've been given a list of files
363 // all from one folder
364 // We handle them by setting a status filter, then requesting the Git status of
365 // all the files in the directory, filtering for the ones we're interested in
366 status.SetFilter(sortedPathList);
368 // if all selected entries are files, we don't do a recursive status
369 // fetching. But if only one is a directory, we have to recurse.
370 git_depth_t depth = git_depth_files;
371 // We have set a filter. If all selected items were files or we fetch
372 // the status not recursively, then we have to include
373 // ignored items too - the user has selected them
374 bool bShowIgnoresRight = true;
375 for (int fcindex=0; fcindex<sortedPathList.GetCount(); ++fcindex)
377 if (sortedPathList[fcindex].IsDirectory())
379 depth = git_depth_infinity;
380 bShowIgnoresRight = false;
381 break;
384 if(!FetchStatusForSingleTarget(config, status, sortedPathList.GetCommonDirectory(), bUpdate, sUUID, arExtPaths, true, depth, bShowIgnoresRight))
386 bRet = FALSE;
389 else
391 for(int nTarget = 0; nTarget < m_nTargetCount; nTarget++)
393 // check whether the path we want the status for is already fetched due to status-fetching
394 // of a parent path.
395 // this check is only done for file paths, because folder paths could be included already
396 // but not recursively
397 if (sortedPathList[nTarget].IsDirectory() || GetListEntry(sortedPathList[nTarget]) == NULL)
399 if(!FetchStatusForSingleTarget(config, status, sortedPathList[nTarget], bUpdate, sUUID,
400 arExtPaths, false, git_depth_infinity, bShowIgnores))
402 bRet = FALSE;
408 // remove the 'helper' files of conflicted items from the list.
409 // otherwise they would appear as unversioned files.
410 for (INT_PTR cind = 0; cind < m_ConflictFileList.GetCount(); ++cind)
412 for (size_t i=0; i < m_arStatusArray.size(); i++)
414 if (m_arStatusArray[i]->GetPath().IsEquivalentTo(m_ConflictFileList[cind]))
416 delete m_arStatusArray[i];
417 m_arStatusArray.erase(m_arStatusArray.begin()+i);
418 break;
422 refetchcounter++;
423 } while(!BuildStatistics() && (refetchcounter < 2) && (*m_pbCanceled==false));
425 if (bShowUserProps)
426 FetchUserProperties();
428 m_ColumnManager.UpdateUserPropList (m_arStatusArray);
430 m_bBlock = FALSE;
431 m_bBusy = false;
432 GetCursorPos(&pt);
433 SetCursorPos(pt.x, pt.y);
434 return bRet;
435 #endif
436 BuildStatistics();
437 return TRUE;
441 // Fetch all local properties for all elements in the status array
443 void CGitStatusListCtrl::FetchUserProperties()
445 #if 0
446 GitPool globalPool;
448 for (size_t i = 0, count = m_arStatusArray.size(); i < count; ++i)
450 // local / temp pool to hold parameters and props for a single item
452 GitPool localPool ((apr_pool_t*)globalPool);
454 // open working copy for this path
456 const char* path = m_arStatusArray[i]->path.GetGitApiPath (localPool);
458 Git_wc_adm_access_t *adm_access = NULL;
459 Git_error_t * error = Git_wc_adm_probe_open3 ( &adm_access
460 , NULL
461 , path
462 , FALSE // no write lock
463 , 0 // lock just the directory/file itself
464 , NULL
465 , NULL
466 , localPool);
467 if (error == NULL)
469 // get the props and add them to the status info
471 apr_hash_t* props = NULL;
472 Git_error_t * error = Git_wc_prop_list ( &props
473 , path
474 , adm_access
475 , localPool);
476 if (error == NULL)
478 for ( apr_hash_index_t *index
479 = apr_hash_first (localPool, props)
480 ; index != NULL
481 ; index = apr_hash_next (index))
483 // extract next entry from hash
485 const char* key = NULL;
486 ptrdiff_t keyLen;
487 const char** val = NULL;
489 apr_hash_this ( index
490 , reinterpret_cast<const void**>(&key)
491 , &keyLen
492 , reinterpret_cast<void**>(&val));
494 // decode / dispatch it
496 CString name = CUnicodeUtils::GetUnicode (key);
497 CString value = CUnicodeUtils::GetUnicode (*val);
499 // store in property container (truncate it after ~100 chars)
501 m_arStatusArray[i]->present_props[name]
502 = value.Left (GitSLC_MAXUSERPROPLENGTH);
505 error = Git_wc_adm_close2 (adm_access, localPool);
507 Git_error_clear (error);
509 #endif
514 // Work on a single item from the list of paths which is provided to us
516 bool CGitStatusListCtrl::FetchStatusForSingleTarget(
517 GitConfig& config,
518 GitStatus& status,
519 const CTGitPath& target,
520 bool bFetchStatusFromRepository,
521 CStringA& strCurrentRepositoryUUID,
522 CTGitPathList& arExtPaths,
523 bool bAllDirect,
524 git_depth_t depth,
525 bool bShowIgnores
528 #if 0
529 config.GetDefaultIgnores();
531 CTGitPath workingTarget(target);
533 git_wc_status2_t * s;
534 CTGitPath GitPath;
535 s = status.GetFirstFileStatus(workingTarget, GitPath, bFetchStatusFromRepository, depth, bShowIgnores);
537 m_HeadRev = SVNRev(status.headrev);
538 if (s!=0)
540 Git_wc_status_kind wcFileStatus = GitStatus::GetMoreImportant(s->text_status, s->prop_status);
542 // This one fixes a problem with externals:
543 // If a strLine is a file, Git:externals and its parent directory
544 // will also be returned by GetXXXFileStatus. Hence, we skip all
545 // status info until we find the one matching workingTarget.
546 if (!workingTarget.IsDirectory())
548 if (!workingTarget.IsEquivalentTo(GitPath))
550 while (s != 0)
552 s = status.GetNextFileStatus(GitPath);
553 if(workingTarget.IsEquivalentTo(GitPath))
555 break;
558 if (s == 0)
560 m_sLastError = status.GetLastErrorMsg();
561 return false;
563 // Now, set working target to be the base folder of this item
564 workingTarget = workingTarget.GetDirectory();
567 bool bEntryFromDifferentRepo = false;
568 // Is this a versioned item with an associated repos UUID?
569 if ((s->entry)&&(s->entry->uuid))
571 // Have we seen a repos UUID yet?
572 if (strCurrentRepositoryUUID.IsEmpty())
574 // This is the first repos UUID we've seen - record it
575 strCurrentRepositoryUUID = s->entry->uuid;
576 m_sUUID = strCurrentRepositoryUUID;
578 else
580 if (strCurrentRepositoryUUID.Compare(s->entry->uuid)!=0)
582 // This item comes from a different repository than our main one
583 m_bHasExternalsFromDifferentRepos = TRUE;
584 bEntryFromDifferentRepo = true;
585 if (s->entry->kind == Git_node_dir)
586 arExtPaths.AddPath(workingTarget);
590 else if (strCurrentRepositoryUUID.IsEmpty() && (s->text_status == Git_wc_status_added))
592 // An added entry doesn't have an UUID assigned to it yet.
593 // So we fetch the status of the parent directory instead and
594 // check if that one has an UUID assigned to it.
595 Git_wc_status2_t * sparent;
596 CTGitPath path = workingTarget;
599 CTGitPath GitParentPath;
600 GitStatus tempstatus;
601 sparent = tempstatus.GetFirstFileStatus(path.GetContainingDirectory(), GitParentPath, false, Git_depth_empty, false);
602 path = GitParentPath;
603 } while ( (sparent) && (sparent->entry) && (!sparent->entry->uuid) && (sparent->text_status==Git_wc_status_added) );
604 if (sparent && sparent->entry && sparent->entry->uuid)
606 strCurrentRepositoryUUID = sparent->entry->uuid;
607 m_sUUID = strCurrentRepositoryUUID;
611 if ((wcFileStatus == Git_wc_status_unversioned)&& GitPath.IsDirectory())
613 // check if the unversioned folder is maybe versioned. This
614 // could happen with nested layouts
615 Git_wc_status_kind st = GitStatus::GetAllStatus(workingTarget);
616 if ((st != Git_wc_status_unversioned)&&(st != Git_wc_status_none))
618 return true; // ignore nested layouts
621 if (status.IsExternal(GitPath))
623 m_bHasExternals = TRUE;
626 AddNewFileEntry(s, GitPath, workingTarget, true, m_bHasExternals, bEntryFromDifferentRepo);
628 if (((wcFileStatus == Git_wc_status_unversioned)||(wcFileStatus == Git_wc_status_none)||((wcFileStatus == Git_wc_status_ignored)&&(m_bShowIgnores))) && GitPath.IsDirectory())
630 // we have an unversioned folder -> get all files in it recursively!
631 AddUnversionedFolder(GitPath, workingTarget.GetContainingDirectory(), &config);
634 // for folders, get all statuses inside it too
635 if(workingTarget.IsDirectory())
637 ReadRemainingItemsStatus(status, workingTarget, strCurrentRepositoryUUID, arExtPaths, &config, bAllDirect);
640 } // if (s!=0)
641 else
643 m_sLastError = status.GetLastErrorMsg();
644 return false;
646 #endif
647 return true;
649 #if 0
650 const CGitStatusListCtrl::FileEntry*
651 CGitStatusListCtrl::AddNewFileEntry(
652 const git_wc_status2_t* pGitStatus, // The return from the Git GetStatus functions
653 const CTGitPath& path, // The path of the item we're adding
654 const CTGitPath& basePath, // The base directory for this status build
655 bool bDirectItem, // Was this item the first found by GetFirstFileStatus or by a subsequent GetNextFileStatus call
656 bool bInExternal, // Are we in an 'external' folder
657 bool bEntryfromDifferentRepo // if the entry is from a different repository
660 FileEntry * entry = new FileEntry();
663 entry->path = path;
664 entry->basepath = basePath;
665 entry->status = GitStatus::GetMoreImportant(pGitStatus->text_status, pGitStatus->prop_status);
666 entry->textstatus = pGitStatus->text_status;
667 entry->propstatus = pGitStatus->prop_status;
668 // entry->remotestatus = GitStatus::GetMoreImportant(pGitStatus->repos_text_status, pGitStatus->repos_prop_status);
669 // entry->remotetextstatus = pGitStatus->repos_text_status;
670 // entry->remotepropstatus = pGitStatus->repos_prop_status;
671 entry->inexternal = bInExternal;
672 entry->differentrepo = bEntryfromDifferentRepo;
673 entry->direct = bDirectItem;
674 // entry->copied = !!pGitStatus->copied;
675 // entry->switched = !!pGitStatus->switched;
677 entry->last_commit_date = pGitStatus->ood_last_cmt_date;
678 if ((entry->last_commit_date == NULL)&&(pGitStatus->entry))
679 entry->last_commit_date = pGitStatus->entry->cmt_date;
680 entry->remoterev = pGitStatus->ood_last_cmt_rev;
681 if (pGitStatus->entry)
682 entry->last_commit_rev = pGitStatus->entry->cmt_rev;
683 if (pGitStatus->ood_last_cmt_author)
684 entry->last_commit_author = CUnicodeUtils::GetUnicode(pGitStatus->ood_last_cmt_author);
685 if ((entry->last_commit_author.IsEmpty())&&(pGitStatus->entry)&&(pGitStatus->entry->cmt_author))
686 entry->last_commit_author = CUnicodeUtils::GetUnicode(pGitStatus->entry->cmt_author);
688 if (pGitStatus->entry)
689 entry->isConflicted = (pGitStatus->entry->conflict_wrk && PathFileExists(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_wrk))) ? true : false;
691 if ((entry->status == Git_wc_status_conflicted)||(entry->isConflicted))
693 entry->isConflicted = true;
694 if (pGitStatus->entry)
696 CTGitPath cpath;
697 if (pGitStatus->entry->conflict_wrk)
699 cpath = path.GetDirectory();
700 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_wrk));
701 m_ConflictFileList.AddPath(cpath);
703 if (pGitStatus->entry->conflict_old)
705 cpath = path.GetDirectory();
706 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_old));
707 m_ConflictFileList.AddPath(cpath);
709 if (pGitStatus->entry->conflict_new)
711 cpath = path.GetDirectory();
712 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_new));
713 m_ConflictFileList.AddPath(cpath);
715 if (pGitStatus->entry->prejfile)
717 cpath = path.GetDirectory();
718 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->prejfile));
719 m_ConflictFileList.AddPath(cpath);
724 if (pGitStatus->entry)
726 entry->isfolder = (pGitStatus->entry->kind == Git_node_dir);
727 entry->Revision = pGitStatus->entry->revision;
728 entry->keeplocal = !!pGitStatus->entry->keep_local;
729 entry->working_size = pGitStatus->entry->working_size;
730 entry->depth = pGitStatus->entry->depth;
732 if (pGitStatus->entry->url)
734 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(pGitStatus->entry->url));
736 if (pGitStatus->entry->copyfrom_url)
738 entry->copyfrom_url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(pGitStatus->entry->copyfrom_url));
739 entry->copyfrom_rev = pGitStatus->entry->copyfrom_rev;
741 else
742 entry->copyfrom_rev = 0;
744 if(bDirectItem)
746 if (m_sURL.IsEmpty())
747 m_sURL = entry->url;
748 else
749 m_sURL.LoadString(IDS_STATUSLIST_MULTIPLETARGETS);
750 m_StatusUrlList.AddPath(CTGitPath(entry->url));
752 if (pGitStatus->entry->lock_owner)
753 entry->lock_owner = CUnicodeUtils::GetUnicode(pGitStatus->entry->lock_owner);
754 if (pGitStatus->entry->lock_token)
756 entry->lock_token = CUnicodeUtils::GetUnicode(pGitStatus->entry->lock_token);
757 m_bHasLocks = true;
759 if (pGitStatus->entry->lock_comment)
760 entry->lock_comment = CUnicodeUtils::GetUnicode(pGitStatus->entry->lock_comment);
762 if (pGitStatus->entry->present_props)
764 entry->present_props = pGitStatus->entry->present_props;
767 if (pGitStatus->entry->changelist)
769 entry->changelist = CUnicodeUtils::GetUnicode(pGitStatus->entry->changelist);
770 m_changelists[entry->changelist] = -1;
771 m_bHasChangeLists = true;
773 entry->needslock = (pGitStatus->entry->present_props && (strstr(pGitStatus->entry->present_props, "Git:needs-lock")!=NULL) );
775 else
777 if (pGitStatus->ood_kind == Git_node_none)
778 entry->isfolder = path.IsDirectory();
779 else
780 entry->isfolder = (pGitStatus->ood_kind == Git_node_dir);
782 if (pGitStatus->repos_lock)
784 if (pGitStatus->repos_lock->owner)
785 entry->lock_remoteowner = CUnicodeUtils::GetUnicode(pGitStatus->repos_lock->owner);
786 if (pGitStatus->repos_lock->token)
787 entry->lock_remotetoken = CUnicodeUtils::GetUnicode(pGitStatus->repos_lock->token);
788 if (pGitStatus->repos_lock->comment)
789 entry->lock_comment = CUnicodeUtils::GetUnicode(pGitStatus->repos_lock->comment);
792 // Pass ownership of the entry to the array
793 m_arStatusArray.push_back(entry);
795 return entry;
797 #endif
799 void CGitStatusListCtrl::AddUnversionedFolder(const CTGitPath& folderName,
800 const CTGitPath& basePath,
801 GitConfig * config)
803 #if 0
804 if (!m_bUnversionedRecurse)
805 return;
806 CSimpleFileFind filefinder(folderName.GetWinPathString());
808 CTGitPath filename;
809 m_bHasUnversionedItems = TRUE;
810 while (filefinder.FindNextFileNoDots())
812 filename.SetFromWin(filefinder.GetFilePath(), filefinder.IsDirectory());
814 bool bMatchIgnore = !!config->MatchIgnorePattern(filename.GetFileOrDirectoryName());
815 bMatchIgnore = bMatchIgnore || config->MatchIgnorePattern(filename.GetGitPathString());
816 if (((bMatchIgnore)&&(m_bShowIgnores))||(!bMatchIgnore))
818 FileEntry * entry = new FileEntry();
819 entry->path = filename;
820 entry->basepath = basePath;
821 entry->inunversionedfolder = true;
822 entry->isfolder = filefinder.IsDirectory();
824 m_arStatusArray.push_back(entry);
825 if (entry->isfolder)
827 if (!g_GitAdminDir.HasAdminDir(entry->path.GetWinPathString(), true))
828 AddUnversionedFolder(entry->path, basePath, config);
832 #endif
836 void CGitStatusListCtrl::ReadRemainingItemsStatus(GitStatus& status, const CTGitPath& basePath,
837 CStringA& strCurrentRepositoryUUID,
838 CTGitPathList& arExtPaths, GitConfig * config, bool bAllDirect)
840 #if 0
841 git_wc_status2_t * s;
843 CTGitPath lastexternalpath;
844 CTGitPath GitPath;
845 while ((s = status.GetNextFileStatus(GitPath)) != NULL)
847 Git_wc_status_kind wcFileStatus = GitStatus::GetMoreImportant(s->text_status, s->prop_status);
848 if ((wcFileStatus == Git_wc_status_unversioned) && (GitPath.IsDirectory()))
850 // check if the unversioned folder is maybe versioned. This
851 // could happen with nested layouts
852 Git_wc_status_kind st = GitStatus::GetAllStatus(GitPath);
853 if ((st != Git_wc_status_unversioned)&&(st != Git_wc_status_none))
855 FileEntry * entry = new FileEntry();
856 entry->path = GitPath;
857 entry->basepath = basePath;
858 entry->inunversionedfolder = true;
859 entry->isfolder = true;
860 entry->isNested = true;
861 m_arStatusArray.push_back(entry);
862 continue;
865 bool bDirectoryIsExternal = false;
866 bool bEntryfromDifferentRepo = false;
867 if (s->entry)
869 if (s->entry->uuid)
871 if (strCurrentRepositoryUUID.IsEmpty())
872 strCurrentRepositoryUUID = s->entry->uuid;
873 else
875 if (strCurrentRepositoryUUID.Compare(s->entry->uuid)!=0)
877 bEntryfromDifferentRepo = true;
878 if (GitStatus::IsImportant(wcFileStatus))
879 m_bHasExternalsFromDifferentRepos = TRUE;
880 if (s->entry->kind == Git_node_dir)
882 if ((lastexternalpath.IsEmpty())||(!lastexternalpath.IsAncestorOf(GitPath)))
884 arExtPaths.AddPath(GitPath);
885 lastexternalpath = GitPath;
891 else
893 // we don't have an UUID - maybe an added file/folder
894 if (!strCurrentRepositoryUUID.IsEmpty())
896 if ((!lastexternalpath.IsEmpty())&&
897 (lastexternalpath.IsAncestorOf(GitPath)))
899 bEntryfromDifferentRepo = true;
900 m_bHasExternalsFromDifferentRepos = TRUE;
905 else
907 // if unversioned items lie around in external
908 // directories from different repos, we have to mark them
909 // as such too.
910 if (!strCurrentRepositoryUUID.IsEmpty())
912 if ((!lastexternalpath.IsEmpty())&&
913 (lastexternalpath.IsAncestorOf(GitPath)))
915 bEntryfromDifferentRepo = true;
919 if (status.IsExternal(GitPath))
921 arExtPaths.AddPath(GitPath);
922 m_bHasExternals = TRUE;
924 if ((!bEntryfromDifferentRepo)&&(status.IsInExternal(GitPath)))
926 // if the externals are inside an unversioned folder (this happens if
927 // the externals are specified with e.g. "ext\folder url" instead of just
928 // "folder url"), then a commit won't succeed.
929 // therefore, we treat those as if the externals come from a different
930 // repository
931 CTGitPath extpath = GitPath;
932 while (basePath.IsAncestorOf(extpath))
934 if (!extpath.HasAdminDir())
936 bEntryfromDifferentRepo = true;
937 break;
939 extpath = extpath.GetContainingDirectory();
942 // Do we have any external paths?
943 if(arExtPaths.GetCount() > 0)
945 // If do have external paths, we need to check if the current item belongs
946 // to one of them
947 for (int ix=0; ix<arExtPaths.GetCount(); ix++)
949 if (arExtPaths[ix].IsAncestorOf(GitPath))
951 bDirectoryIsExternal = true;
952 break;
957 if ((wcFileStatus == Git_wc_status_unversioned)&&(!bDirectoryIsExternal))
958 m_bHasUnversionedItems = TRUE;
960 const FileEntry* entry = AddNewFileEntry(s, GitPath, basePath, bAllDirect, bDirectoryIsExternal, bEntryfromDifferentRepo);
962 bool bMatchIgnore = !!config->MatchIgnorePattern(entry->path.GetFileOrDirectoryName());
963 bMatchIgnore = bMatchIgnore || config->MatchIgnorePattern(entry->path.GetGitPathString());
964 if ((((wcFileStatus == Git_wc_status_unversioned)||(wcFileStatus == Git_wc_status_none))&&(!bMatchIgnore))||
965 ((wcFileStatus == Git_wc_status_ignored)&&(m_bShowIgnores))||
966 (((wcFileStatus == Git_wc_status_unversioned)||(wcFileStatus == Git_wc_status_none))&&(bMatchIgnore)&&(m_bShowIgnores)))
968 if (entry->isfolder)
970 // we have an unversioned folder -> get all files in it recursively!
971 AddUnversionedFolder(GitPath, basePath, config);
974 } // while ((s = status.GetNextFileStatus(GitPath)) != NULL)
975 #endif
978 // Get the show-flags bitmap value which corresponds to a particular Git status
979 DWORD CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status)
981 switch (status)
983 case git_wc_status_none:
984 case git_wc_status_unversioned:
985 return SVNSLC_SHOWUNVERSIONED;
986 case git_wc_status_ignored:
987 if (!m_bShowIgnores)
988 return SVNSLC_SHOWDIRECTS;
989 return SVNSLC_SHOWDIRECTS|SVNSLC_SHOWIGNORED;
990 case git_wc_status_incomplete:
991 return SVNSLC_SHOWINCOMPLETE;
992 case git_wc_status_normal:
993 return SVNSLC_SHOWNORMAL;
994 case git_wc_status_external:
995 return SVNSLC_SHOWEXTERNAL;
996 case git_wc_status_added:
997 return SVNSLC_SHOWADDED;
998 case git_wc_status_missing:
999 return SVNSLC_SHOWMISSING;
1000 case git_wc_status_deleted:
1001 return SVNSLC_SHOWREMOVED;
1002 case git_wc_status_replaced:
1003 return SVNSLC_SHOWREPLACED;
1004 case git_wc_status_modified:
1005 return SVNSLC_SHOWMODIFIED;
1006 case git_wc_status_merged:
1007 return SVNSLC_SHOWMERGED;
1008 case git_wc_status_conflicted:
1009 return SVNSLC_SHOWCONFLICTED;
1010 case git_wc_status_obstructed:
1011 return SVNSLC_SHOWOBSTRUCTED;
1012 default:
1013 // we should NEVER get here!
1014 ASSERT(FALSE);
1015 break;
1017 return 0;
1020 void CGitStatusListCtrl::Show(DWORD dwShow, DWORD dwCheck /*=0*/, bool bShowFolders /* = true */,BOOL UpdateStatusList)
1022 CWinApp * pApp = AfxGetApp();
1023 if (pApp)
1024 pApp->DoWaitCursor(1);
1026 Locker lock(m_critSec);
1027 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1029 //SetItemCount(listIndex);
1030 SetRedraw(FALSE);
1031 DeleteAllItems();
1032 PrepareGroups();
1033 m_nSelected = 0;
1035 if(UpdateStatusList)
1037 m_arStatusArray.clear();
1038 for(int i=0;i<this->m_StatusFileList.GetCount();i++)
1040 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
1043 for(int i=0;i<this->m_UnRevFileList.GetCount();i++)
1045 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
1048 for(int i=0;i<this->m_IgnoreFileList.GetCount();i++)
1050 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
1054 if( m_nSortedColumn )
1056 CSorter predicate (&m_ColumnManager, m_nSortedColumn, m_bAscending);
1057 std::sort(m_arStatusArray.begin(), m_arStatusArray.end(), predicate);
1060 int index =0;
1061 for(int i=0;i<this->m_arStatusArray.size();i++)
1063 //set default checkbox status
1064 if(((CTGitPath*)m_arStatusArray[i])->m_Action & dwCheck)
1065 ((CTGitPath*)m_arStatusArray[i])->m_Checked=true;
1066 else
1067 ((CTGitPath*)m_arStatusArray[i])->m_Checked=false;
1069 if(((CTGitPath*)m_arStatusArray[i])->m_Action & dwShow)
1071 AddEntry((CTGitPath*)m_arStatusArray[i],langID,index);
1072 index++;
1076 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
1077 for (int col = 0; col <= maxcol; col++)
1078 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
1080 SetRedraw(TRUE);
1081 GetStatisticsString();
1083 CHeaderCtrl * pHeader = GetHeaderCtrl();
1084 HDITEM HeaderItem = {0};
1085 HeaderItem.mask = HDI_FORMAT;
1086 for (int i=0; i<pHeader->GetItemCount(); ++i)
1088 pHeader->GetItem(i, &HeaderItem);
1089 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1090 pHeader->SetItem(i, &HeaderItem);
1092 if (m_nSortedColumn)
1094 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1095 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1096 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1099 #if 0
1100 if (nSelectedEntry)
1102 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
1103 EnsureVisible(nSelectedEntry, false);
1105 else
1107 // Restore the item at the top of the list.
1108 for (int i=0;GetTopIndex() != nTopIndex;i++)
1110 if ( !EnsureVisible(nTopIndex+i,false) )
1112 break;
1116 #endif
1117 if (pApp)
1118 pApp->DoWaitCursor(-1);
1120 Invalidate();
1122 m_dwShow = dwShow;
1124 #if 0
1126 CWinApp * pApp = AfxGetApp();
1127 if (pApp)
1128 pApp->DoWaitCursor(1);
1130 m_bShowFolders = bShowFolders;
1132 int nTopIndex = GetTopIndex();
1133 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
1134 int nSelectedEntry = 0;
1135 if (posSelectedEntry)
1136 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
1137 SetRedraw(FALSE);
1138 DeleteAllItems();
1140 PrepareGroups();
1142 m_arListArray.clear();
1144 m_arListArray.reserve(m_arStatusArray.size());
1145 SetItemCount (static_cast<int>(m_arStatusArray.size()));
1147 int listIndex = 0;
1148 for (size_t i=0; i < m_arStatusArray.size(); ++i)
1150 FileEntry * entry = m_arStatusArray[i];
1151 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
1152 continue;
1153 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
1154 continue;
1155 if (entry->IsFolder() && (!bShowFolders))
1156 continue; // don't show folders if they're not wanted.
1158 #if 0
1159 git_wc_status_kind status = GitStatus::GetMoreImportant(entry->status, entry->remotestatus);
1160 DWORD showFlags = GetShowFlagsFromGitStatus(status);
1161 if (entry->IsLocked())
1162 showFlags |= SVNSLC_SHOWLOCKS;
1163 if (entry->switched)
1164 showFlags |= SVNSLC_SHOWSWITCHED;
1165 if (!entry->changelist.IsEmpty())
1166 showFlags |= SVNSLC_SHOWINCHANGELIST;
1167 #endif
1168 bool bAllowCheck = ((entry->changelist.Compare(SVNSLC_IGNORECHANGELIST) != 0)
1169 && (m_bCheckIfGroupsExist || (m_changelists.size()==0 || (m_changelists.size()==1 && m_bHasIgnoreGroup))));
1171 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
1172 #if 0
1173 if (status != Git_wc_status_ignored || (entry->direct) || (dwShow & GitSLC_SHOWIGNORED))
1175 if ((!entry->IsFolder()) && (status == Git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
1177 if (PathFileExists(entry->GetPath().GetWinPath()))
1179 m_arListArray.push_back(i);
1180 if ((dwCheck & SVNSLC_SHOWREMOVEDANDPRESENT)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
1182 if (bAllowCheck)
1183 entry->checked = true;
1185 AddEntry(entry, langID, listIndex++);
1188 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
1190 m_arListArray.push_back(i);
1191 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
1193 if (bAllowCheck)
1194 entry->checked = true;
1196 AddEntry(entry, langID, listIndex++);
1198 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
1200 m_arListArray.push_back(i);
1201 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
1203 if (bAllowCheck)
1204 entry->checked = true;
1206 AddEntry(entry, langID, listIndex++);
1209 #endif
1212 SetItemCount(listIndex);
1214 m_ColumnManager.UpdateRelevance (m_arStatusArray, m_arListArray);
1216 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
1217 for (int col = 0; col <= maxcol; col++)
1218 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
1220 SetRedraw(TRUE);
1221 GetStatisticsString();
1223 CHeaderCtrl * pHeader = GetHeaderCtrl();
1224 HDITEM HeaderItem = {0};
1225 HeaderItem.mask = HDI_FORMAT;
1226 for (int i=0; i<pHeader->GetItemCount(); ++i)
1228 pHeader->GetItem(i, &HeaderItem);
1229 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1230 pHeader->SetItem(i, &HeaderItem);
1232 if (m_nSortedColumn)
1234 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1235 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1236 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1239 if (nSelectedEntry)
1241 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
1242 EnsureVisible(nSelectedEntry, false);
1244 else
1246 // Restore the item at the top of the list.
1247 for (int i=0;GetTopIndex() != nTopIndex;i++)
1249 if ( !EnsureVisible(nTopIndex+i,false) )
1251 break;
1256 if (pApp)
1257 pApp->DoWaitCursor(-1);
1259 m_bEmpty = (GetItemCount() == 0);
1260 Invalidate();
1261 #endif
1265 void CGitStatusListCtrl::Show(DWORD dwShow, const CTGitPathList& checkedList, bool bShowFolders /* = true */)
1267 DeleteAllItems();
1268 for(int i=0;i<checkedList.GetCount();i++)
1269 this->AddEntry((CTGitPath *)&checkedList[i],0,i);
1270 return ;
1271 #if 0
1273 Locker lock(m_critSec);
1274 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1276 CWinApp * pApp = AfxGetApp();
1277 if (pApp)
1278 pApp->DoWaitCursor(1);
1279 m_dwShow = dwShow;
1280 m_bShowFolders = bShowFolders;
1281 m_nSelected = 0;
1282 int nTopIndex = GetTopIndex();
1283 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
1284 int nSelectedEntry = 0;
1285 if (posSelectedEntry)
1286 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
1287 SetRedraw(FALSE);
1288 DeleteAllItems();
1290 PrepareGroups();
1292 m_arListArray.clear();
1294 m_arListArray.reserve(m_arStatusArray.size());
1295 SetItemCount (static_cast<int>(m_arStatusArray.size()));
1297 int listIndex = 0;
1298 for (size_t i=0; i < m_arStatusArray.size(); ++i)
1300 FileEntry * entry = m_arStatusArray[i];
1301 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
1302 continue;
1303 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
1304 continue;
1305 if (entry->IsFolder() && (!bShowFolders))
1306 continue; // don't show folders if they're not wanted.
1307 #if 0
1308 git_wc_status_kind status = SVNStatus::GetMoreImportant(entry->status, entry->remotestatus);
1309 DWORD showFlags = GetShowFlagsFromSVNStatus(status);
1310 if (entry->IsLocked())
1311 showFlags |= SVNSLC_SHOWLOCKS;
1312 if (!entry->changelist.IsEmpty())
1313 showFlags |= SVNSLC_SHOWINCHANGELIST;
1315 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
1316 if (status != git_wc_status_ignored || (entry->direct) || (dwShow & SVNSLC_SHOWIGNORED))
1318 for (int npath = 0; npath < checkedList.GetCount(); ++npath)
1320 if (entry->GetPath().IsEquivalentTo(checkedList[npath]))
1322 entry->checked = true;
1323 break;
1326 if ((!entry->IsFolder()) && (status == git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
1328 if (PathFileExists(entry->GetPath().GetWinPath()))
1330 m_arListArray.push_back(i);
1331 AddEntry(entry, langID, listIndex++);
1334 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
1336 m_arListArray.push_back(i);
1337 AddEntry(entry, langID, listIndex++);
1339 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
1341 m_arListArray.push_back(i);
1342 AddEntry(entry, langID, listIndex++);
1344 else if (entry->switched)
1346 m_arListArray.push_back(i);
1347 AddEntry(entry, langID, listIndex++);
1350 #endif
1353 SetItemCount(listIndex);
1355 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
1356 for (int col = 0; col <= maxcol; col++)
1357 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
1359 SetRedraw(TRUE);
1360 GetStatisticsString();
1362 CHeaderCtrl * pHeader = GetHeaderCtrl();
1363 HDITEM HeaderItem = {0};
1364 HeaderItem.mask = HDI_FORMAT;
1365 for (int i=0; i<pHeader->GetItemCount(); ++i)
1367 pHeader->GetItem(i, &HeaderItem);
1368 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1369 pHeader->SetItem(i, &HeaderItem);
1371 if (m_nSortedColumn)
1373 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1374 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1375 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1378 if (nSelectedEntry)
1380 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
1381 EnsureVisible(nSelectedEntry, false);
1383 else
1385 // Restore the item at the top of the list.
1386 for (int i=0;GetTopIndex() != nTopIndex;i++)
1388 if ( !EnsureVisible(nTopIndex+i,false) )
1390 break;
1395 if (pApp)
1396 pApp->DoWaitCursor(-1);
1398 m_bEmpty = (GetItemCount() == 0);
1399 Invalidate();
1400 #endif
1403 int CGitStatusListCtrl::GetColumnIndex(int mask)
1405 int i=0;
1406 for(i=0;i<32;i++)
1407 if(mask&0x1)
1408 return i;
1409 else
1410 mask=mask>>1;
1411 return -1;
1413 void CGitStatusListCtrl::AddEntry(CTGitPath * GitPath, WORD langID, int listIndex)
1415 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
1416 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
1418 CString path = GitPath->GetGitPathString();
1420 m_bBlock = TRUE;
1421 TCHAR buf[100];
1422 int index = listIndex;
1423 int nCol = 1;
1424 CString entryname = GitPath->GetGitPathString();
1425 int icon_idx = 0;
1426 if (GitPath->IsDirectory())
1427 icon_idx = m_nIconFolder;
1428 else
1430 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath);
1432 // relative path
1433 CString rename;
1434 rename.Format(_T("(from %s)"),GitPath->GetGitOldPathString());
1435 if(GitPath->m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
1436 entryname+=rename;
1438 InsertItem(index, entryname, icon_idx);
1440 this->SetItemData(index, (DWORD_PTR)GitPath);
1441 // SVNSLC_COLFILENAME
1442 SetItemText(index, nCol++, GitPath->GetFileOrDirectoryName());
1443 // SVNSLC_COLEXT
1444 SetItemText(index, nCol++, GitPath->GetFileExtension());
1445 // SVNSLC_COLSTATUS
1446 SetItemText(index, nCol++, GitPath->GetActionName());
1448 SetItemText(index, GetColumnIndex(SVNSLC_COLADD),GitPath->m_StatAdd);
1449 SetItemText(index, GetColumnIndex(SVNSLC_COLDEL),GitPath->m_StatDel);
1452 SetCheck(index, GitPath->m_Checked);
1453 if (GitPath->m_Checked)
1454 m_nSelected++;
1457 if( GitPath->m_Action & CTGitPath::LOGACTIONS_IGNORE)
1458 SetItemGroup(index, 2);
1459 else if( GitPath->m_Action & CTGitPath::LOGACTIONS_UNVER)
1460 SetItemGroup(index,1);
1461 else
1462 SetItemGroup(index,0);
1463 m_bBlock = FALSE;
1467 #if 0
1468 void CGitStatusListCtrl::AddEntry(FileEntry * entry, WORD langID, int listIndex)
1470 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
1471 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
1473 CString path = entry->GetPath().GetGitPathString();
1474 if ( m_mapFilenameToChecked.size()!=0 && m_mapFilenameToChecked.find(path) != m_mapFilenameToChecked.end() )
1476 // The user manually de-/selected an item. We now restore this status
1477 // when refreshing.
1478 entry->checked = m_mapFilenameToChecked[path];
1481 m_bBlock = TRUE;
1482 TCHAR buf[100];
1483 int index = listIndex;
1484 int nCol = 1;
1485 CString entryname = entry->GetDisplayName();
1486 int icon_idx = 0;
1487 if (entry->isfolder)
1488 icon_idx = m_nIconFolder;
1489 else
1491 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(entry->path);
1493 // relative path
1494 InsertItem(index, entryname, icon_idx);
1495 // SVNSLC_COLFILENAME
1496 SetItemText(index, nCol++, entry->path.GetFileOrDirectoryName());
1497 // SVNSLC_COLEXT
1498 SetItemText(index, nCol++, entry->path.GetFileExtension());
1499 // SVNSLC_COLSTATUS
1500 if (entry->isNested)
1502 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1503 SetItemText(index, nCol++, sTemp);
1505 else
1507 GitStatus::GetStatusString(hResourceHandle, entry->status, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1508 if ((entry->copied)&&(_tcslen(buf)>1))
1509 _tcscat_s(buf, 100, _T(" (+)"));
1510 if ((entry->switched)&&(_tcslen(buf)>1))
1511 _tcscat_s(buf, 100, _T(" (s)"));
1512 #if 0
1513 if ((entry->status == entry->propstatus)&&
1514 (entry->status != git_wc_status_normal)&&
1515 (entry->status != git_wc_status_unversioned)&&
1516 (!GitStatus::IsImportant(entry->textstatus)))
1517 _tcscat_s(buf, 100, ponly);
1518 #endif
1519 SetItemText(index, nCol++, buf);
1521 // SVNSLC_COLREMOTESTATUS
1522 if (entry->isNested)
1524 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1525 SetItemText(index, nCol++, sTemp);
1527 else
1529 #if 0
1530 SVNStatus::GetStatusString(hResourceHandle, entry->remotestatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1531 if ((entry->copied)&&(_tcslen(buf)>1))
1532 _tcscat_s(buf, 100, _T(" (+)"));
1533 if ((entry->switched)&&(_tcslen(buf)>1))
1534 _tcscat_s(buf, 100, _T(" (s)"));
1535 if ((entry->remotestatus == entry->remotepropstatus)&&
1536 (entry->remotestatus != git_wc_status_none)&&
1537 (entry->remotestatus != git_wc_status_normal)&&
1538 (entry->remotestatus != git_wc_status_unversioned)&&
1539 (!SVNStatus::IsImportant(entry->remotetextstatus)))
1540 _tcscat_s(buf, 100, ponly);
1541 #endif
1542 SetItemText(index, nCol++, buf);
1544 // SVNSLC_COLTEXTSTATUS
1545 if (entry->isNested)
1547 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1548 SetItemText(index, nCol++, sTemp);
1550 else
1552 #if 0
1553 SVNStatus::GetStatusString(hResourceHandle, entry->textstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1554 if ((entry->copied)&&(_tcslen(buf)>1))
1555 _tcscat_s(buf, 100, _T(" (+)"));
1556 if ((entry->switched)&&(_tcslen(buf)>1))
1557 _tcscat_s(buf, 100, _T(" (s)"));
1558 #endif
1559 SetItemText(index, nCol++, buf);
1561 // SVNSLC_COLPROPSTATUS
1562 if (entry->isNested)
1564 SetItemText(index, nCol++, _T(""));
1566 else
1568 #if 0
1569 SVNStatus::GetStatusString(hResourceHandle, entry->propstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1570 if ((entry->copied)&&(_tcslen(buf)>1))
1571 _tcscat_s(buf, 100, _T(" (+)"));
1572 if ((entry->switched)&&(_tcslen(buf)>1))
1573 _tcscat_s(buf, 100, _T(" (s)"));
1574 #endif
1575 SetItemText(index, nCol++, buf);
1577 // SVNSLC_COLREMOTETEXT
1578 if (entry->isNested)
1580 SetItemText(index, nCol++, _T(""));
1582 else
1584 #if 0
1585 SVNStatus::GetStatusString(hResourceHandle, entry->remotetextstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1586 SetItemText(index, nCol++, buf);
1587 #endif
1589 // SVNSLC_COLREMOTEPROP
1590 if (entry->isNested)
1592 SetItemText(index, nCol++, _T(""));
1594 else
1596 // SVNStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1597 SetItemText(index, nCol++, buf);
1599 // SVNSLC_COLURL
1600 // SetItemText(index, nCol++, entry->url);
1601 // SVNSLC_COLLOCK
1602 #if 0
1603 if (!m_HeadRev.IsHead())
1605 // we have contacted the repository
1607 // decision-matrix
1608 // wc repository text
1609 // "" "" ""
1610 // "" UID1 owner
1611 // UID1 UID1 owner
1612 // UID1 "" lock has been broken
1613 // UID1 UID2 lock has been stolen
1614 if (entry->lock_token.IsEmpty() || (entry->lock_token.Compare(entry->lock_remotetoken)==0))
1616 if (entry->lock_owner.IsEmpty())
1617 SetItemText(index, nCol++, entry->lock_remoteowner);
1618 else
1619 SetItemText(index, nCol++, entry->lock_owner);
1621 else if (entry->lock_remotetoken.IsEmpty())
1623 // broken lock
1624 CString temp(MAKEINTRESOURCE(IDS_STATUSLIST_LOCKBROKEN));
1625 SetItemText(index, nCol++, temp);
1627 else
1629 // stolen lock
1630 CString temp;
1631 temp.Format(IDS_STATUSLIST_LOCKSTOLEN, (LPCTSTR)entry->lock_remoteowner);
1632 SetItemText(index, nCol++, temp);
1635 else
1636 SetItemText(index, nCol++, entry->lock_owner);
1637 // SVNSLC_COLLOCKCOMMENT
1638 SetItemText(index, nCol++, entry->lock_comment);
1639 // SVNSLC_COLAUTHOR
1640 SetItemText(index, nCol++, entry->last_commit_author);
1641 // SVNSLC_COLREVISION
1642 CString temp;
1643 temp.Format(_T("%ld"), entry->last_commit_rev);
1644 if (entry->last_commit_rev > 0)
1645 SetItemText(index, nCol++, temp);
1646 else
1647 SetItemText(index, nCol++, _T(""));
1648 // SVNSLC_COLREMOTEREVISION
1649 temp.Format(_T("%ld"), entry->remoterev);
1650 if (entry->remoterev > 0)
1651 SetItemText(index, nCol++, temp);
1652 else
1653 SetItemText(index, nCol++, _T(""));
1654 // SVNSLC_COLDATE
1655 TCHAR datebuf[SVN_DATE_BUFFER];
1656 apr_time_t date = entry->last_commit_date;
1657 SVN::formatDate(datebuf, date, true);
1658 if (date)
1659 SetItemText(index, nCol++, datebuf);
1660 else
1661 SetItemText(index, nCol++, _T(""));
1662 // SVNSLC_COLSVNNEEDSLOCK
1663 BOOL bFoundSVNNeedsLock = entry->present_props.IsNeedsLockSet();
1664 CString strSVNNeedsLock = (bFoundSVNNeedsLock) ? _T("*") : _T("");
1665 SetItemText(index, nCol++, strSVNNeedsLock);
1666 // SVNSLC_COLCOPYFROM
1667 if (m_sURL.Compare(entry->copyfrom_url.Left(m_sURL.GetLength()))==0)
1668 temp = entry->copyfrom_url.Mid(m_sURL.GetLength());
1669 else
1670 temp = entry->copyfrom_url;
1671 SetItemText(index, nCol++, temp);
1672 // SVNSLC_COLMODIFICATIONDATE
1673 __int64 filetime = entry->GetPath().GetLastWriteTime();
1674 if ( (filetime) && (entry->status!=git_wc_status_deleted) )
1676 FILETIME* f = (FILETIME*)(__int64*)&filetime;
1677 TCHAR datebuf[SVN_DATE_BUFFER];
1678 SVN::formatDate(datebuf,*f,true);
1679 SetItemText(index, nCol++, datebuf);
1681 else
1683 SetItemText(index, nCol++, _T(""));
1686 // user-defined properties
1687 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
1688 ; i < count
1689 ; ++i)
1691 assert (i == nCol++);
1692 assert (m_ColumnManager.IsUserProp (i));
1694 CString name = m_ColumnManager.GetName(i);
1695 if (entry->present_props.HasProperty (name))
1697 const CString& propVal = entry->present_props [name];
1698 if (propVal.IsEmpty())
1699 SetItemText(index, i, m_sNoPropValueText);
1700 else
1701 SetItemText(index, i, propVal);
1703 else
1704 SetItemText(index, i, _T(""));
1707 SetCheck(index, entry->checked);
1708 if (entry->checked)
1709 m_nSelected++;
1710 if (m_changelists.find(entry->changelist) != m_changelists.end())
1711 SetItemGroup(index, m_changelists[entry->changelist]);
1712 else
1713 SetItemGroup(index, 0);
1714 m_bBlock = FALSE;
1715 #endif
1717 #endif
1718 bool CGitStatusListCtrl::SetItemGroup(int item, int groupindex)
1720 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1721 // return false;
1722 if (groupindex < 0)
1723 return false;
1724 LVITEM i = {0};
1725 i.mask = LVIF_GROUPID;
1726 i.iItem = item;
1727 i.iSubItem = 0;
1728 i.iGroupId = groupindex;
1730 return !!SetItem(&i);
1733 void CGitStatusListCtrl::Sort()
1735 Locker lock(m_critSec);
1737 CSorter predicate (&m_ColumnManager, m_nSortedColumn, m_bAscending);
1739 std::sort(m_arStatusArray.begin(), m_arStatusArray.end(), predicate);
1740 SaveColumnWidths();
1741 Show(m_dwShow, 0, m_bShowFolders);
1745 void CGitStatusListCtrl::OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult)
1747 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1748 *pResult = 0;
1749 if (m_bBlock)
1750 return;
1751 m_bBlock = TRUE;
1752 if (m_nSortedColumn == phdr->iItem)
1753 m_bAscending = !m_bAscending;
1754 else
1755 m_bAscending = TRUE;
1756 m_nSortedColumn = phdr->iItem;
1757 m_mapFilenameToChecked.clear();
1758 Sort();
1760 CHeaderCtrl * pHeader = GetHeaderCtrl();
1761 HDITEM HeaderItem = {0};
1762 HeaderItem.mask = HDI_FORMAT;
1763 for (int i=0; i<pHeader->GetItemCount(); ++i)
1765 pHeader->GetItem(i, &HeaderItem);
1766 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1767 pHeader->SetItem(i, &HeaderItem);
1769 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1770 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1771 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1773 // the checked state of the list control items must be restored
1775 for (int i=0; i<GetItemCount(); ++i)
1777 CTGitPath * entry = (CTGitPath*)GetItemData(i);
1778 ASSERT(entry);
1779 if(entry)
1780 SetCheck(i, entry->m_Checked);
1783 m_bBlock = FALSE;
1786 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
1788 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1789 *pResult = 0;
1791 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1792 if ((m_bBlock)&&(m_bBlockUI))
1794 // if we're blocked, prevent changing of the check state
1795 if ((!ISCHECKED(pNMLV->uOldState) && ISCHECKED(pNMLV->uNewState))||
1796 (ISCHECKED(pNMLV->uOldState) && !ISCHECKED(pNMLV->uNewState)))
1797 *pResult = TRUE;
1801 BOOL CGitStatusListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
1803 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1804 *pResult = 0;
1805 CWnd* pParent = GetParent();
1806 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
1808 pParent->SendMessage(SVNSLNM_ITEMCHANGED, pNMLV->iItem);
1811 if ((pNMLV->uNewState==0)||(pNMLV->uNewState & LVIS_SELECTED)||(pNMLV->uNewState & LVIS_FOCUSED))
1812 return FALSE;
1814 if (m_bBlock)
1815 return FALSE;
1817 bool bSelected = !!(ListView_GetItemState(m_hWnd, pNMLV->iItem, LVIS_SELECTED) & LVIS_SELECTED);
1818 int nListItems = GetItemCount();
1820 m_bBlock = TRUE;
1821 // was the item checked?
1823 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1824 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1826 if (GetCheck(pNMLV->iItem))
1828 CheckEntry(pNMLV->iItem, nListItems);
1829 if (bSelected)
1831 POSITION pos = GetFirstSelectedItemPosition();
1832 int index;
1833 while ((index = GetNextSelectedItem(pos)) >= 0)
1835 if (index != pNMLV->iItem)
1836 CheckEntry(index, nListItems);
1840 else
1842 UncheckEntry(pNMLV->iItem, nListItems);
1843 if (bSelected)
1845 POSITION pos = GetFirstSelectedItemPosition();
1846 int index;
1847 while ((index = GetNextSelectedItem(pos)) >= 0)
1849 if (index != pNMLV->iItem)
1850 UncheckEntry(index, nListItems);
1855 GetStatisticsString();
1856 m_bBlock = FALSE;
1857 NotifyCheck();
1859 return FALSE;
1862 void CGitStatusListCtrl::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
1864 LPNMHEADER header = reinterpret_cast<LPNMHEADER>(pNMHDR);
1865 if ( (header != NULL)
1866 && (header->iItem >= 0)
1867 && (header->iItem < m_ColumnManager.GetColumnCount()))
1869 m_ColumnManager.ColumnResized (header->iItem);
1872 *pResult = FALSE;
1875 void CGitStatusListCtrl::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
1877 LPNMHEADER header = reinterpret_cast<LPNMHEADER>(pNMHDR);
1878 *pResult = TRUE;
1879 if ( (header != NULL)
1880 && (header->iItem >= 0)
1881 && (header->iItem < m_ColumnManager.GetColumnCount())
1882 // only allow the reordering if the column was not moved left of the first
1883 // visible item - otherwise the 'invisible' columns are not at the far left
1884 // anymore and we get all kinds of redrawing problems.
1885 && (header->pitem)
1886 && (header->pitem->iOrder > m_ColumnManager.GetInvisibleCount()))
1888 m_ColumnManager.ColumnMoved (header->iItem, header->pitem->iOrder);
1889 *pResult = FALSE;
1892 Invalidate(FALSE);
1895 void CGitStatusListCtrl::CheckEntry(int index, int nListItems)
1897 Locker lock(m_critSec);
1898 //FileEntry * entry = GetListEntry(index);
1899 CTGitPath *path=(CTGitPath*)GetItemData(index);
1900 ASSERT(path != NULL);
1901 if (path == NULL)
1902 return;
1903 SetCheck(index, TRUE);
1904 //entry = GetListEntry(index);
1905 // if an unversioned item was checked, then we need to check if
1906 // the parent folders are unversioned too. If the parent folders actually
1907 // are unversioned, then check those too.
1908 #if 0
1909 if (entry->status == git_wc_status_unversioned)
1911 // we need to check the parent folder too
1912 const CTGitPath& folderpath = entry->path;
1913 for (int i=0; i< nListItems; ++i)
1915 FileEntry * testEntry = GetListEntry(i);
1916 ASSERT(testEntry != NULL);
1917 if (testEntry == NULL)
1918 continue;
1919 if (!testEntry->checked)
1921 if (testEntry->path.IsAncestorOf(folderpath) && (!testEntry->path.IsEquivalentTo(folderpath)))
1923 SetEntryCheck(testEntry,i,true);
1924 m_nSelected++;
1929 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1930 if ( (entry->status == git_wc_status_deleted) || (m_bCheckChildrenWithParent) || (bShift) )
1932 // if a deleted folder gets checked, we have to check all
1933 // children of that folder too.
1934 if (entry->path.IsDirectory())
1936 SetCheckOnAllDescendentsOf(entry, true);
1939 // if a deleted file or folder gets checked, we have to
1940 // check all parents of this item too.
1941 for (int i=0; i<nListItems; ++i)
1943 FileEntry * testEntry = GetListEntry(i);
1944 ASSERT(testEntry != NULL);
1945 if (testEntry == NULL)
1946 continue;
1947 if (!testEntry->checked)
1949 if (testEntry->path.IsAncestorOf(entry->path) && (!testEntry->path.IsEquivalentTo(entry->path)))
1951 if ((testEntry->status == git_wc_status_deleted)||(m_bCheckChildrenWithParent))
1953 SetEntryCheck(testEntry,i,true);
1954 m_nSelected++;
1955 // now we need to check all children of this parent folder
1956 SetCheckOnAllDescendentsOf(testEntry, true);
1962 #endif
1963 if ( !path->m_Checked )
1965 path->m_Checked = TRUE;
1966 m_nSelected++;
1970 void CGitStatusListCtrl::UncheckEntry(int index, int nListItems)
1972 Locker lock(m_critSec);
1973 CTGitPath *path=(CTGitPath*)GetItemData(index);
1974 ASSERT(path != NULL);
1975 if (path == NULL)
1976 return;
1977 SetCheck(index, FALSE);
1978 //entry = GetListEntry(index);
1979 // item was unchecked
1980 #if 0
1981 if (entry->path.IsDirectory())
1983 // disable all files within an unselected folder, except when unchecking a folder with property changes
1984 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1985 if ( (entry->status != git_wc_status_modified) || (bShift) )
1987 SetCheckOnAllDescendentsOf(entry, false);
1990 else if (entry->status == git_wc_status_deleted)
1992 // a "deleted" file was unchecked, so uncheck all parent folders
1993 // and all children of those parents
1994 for (int i=0; i<nListItems; i++)
1996 FileEntry * testEntry = GetListEntry(i);
1997 ASSERT(testEntry != NULL);
1998 if (testEntry == NULL)
1999 continue;
2000 if (testEntry->checked)
2002 if (testEntry->path.IsAncestorOf(entry->path))
2004 if (testEntry->status == git_wc_status_deleted)
2006 SetEntryCheck(testEntry,i,false);
2007 m_nSelected--;
2009 SetCheckOnAllDescendentsOf(testEntry, false);
2015 #endif
2016 if ( path->m_Checked )
2018 path->m_Checked = FALSE;
2019 m_nSelected--;
2022 #if 0
2023 bool CGitStatusListCtrl::EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2)
2025 return pEntry1->path < pEntry2->path;
2028 bool CGitStatusListCtrl::IsEntryVersioned(const FileEntry* pEntry1)
2030 return pEntry1->status != git_wc_status_unversioned;
2032 #endif
2033 bool CGitStatusListCtrl::BuildStatistics()
2036 bool bRefetchStatus = false;
2038 // now gather some statistics
2039 m_nUnversioned = 0;
2040 m_nNormal = 0;
2041 m_nModified = 0;
2042 m_nAdded = 0;
2043 m_nDeleted = 0;
2044 m_nConflicted = 0;
2045 m_nTotal = 0;
2046 m_nSelected = 0;
2048 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
2050 int status=((CTGitPath*)m_arStatusArray[i])->m_Action;
2052 if(status&(CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
2053 m_nAdded++;
2055 if(status&CTGitPath::LOGACTIONS_DELETED)
2056 m_nDeleted++;
2058 if(status&(CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_MODIFIED))
2059 m_nModified++;
2061 if(status&CTGitPath::LOGACTIONS_UNMERGED)
2062 m_nConflicted++;
2064 if(status&(CTGitPath::LOGACTIONS_IGNORE|CTGitPath::LOGACTIONS_UNVER))
2065 m_nUnversioned++;
2069 // } // switch (entry->status)
2070 // } // if (entry)
2071 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
2072 return !bRefetchStatus;
2074 return FALSE;
2077 void CGitStatusListCtrl::GetMinMaxRevisions(git_revnum_t& rMin, git_revnum_t& rMax, bool bShownOnly, bool bCheckedOnly)
2079 #if 0
2080 Locker lock(m_critSec);
2081 rMin = LONG_MAX;
2082 rMax = 0;
2084 if ((bShownOnly)||(bCheckedOnly))
2086 for (int i=0; i<GetItemCount(); ++i)
2088 const FileEntry * entry = GetListEntry(i);
2090 if ((entry)&&(entry->last_commit_rev))
2092 if ((!bCheckedOnly)||(entry->IsChecked()))
2094 if (entry->last_commit_rev >= 0)
2096 rMin = min(rMin, entry->last_commit_rev);
2097 rMax = max(rMax, entry->last_commit_rev);
2103 else
2105 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
2107 const FileEntry * entry = m_arStatusArray[i];
2108 if ((entry)&&(entry->last_commit_rev))
2110 if (entry->last_commit_rev >= 0)
2112 rMin = min(rMin, entry->last_commit_rev);
2113 rMax = max(rMax, entry->last_commit_rev);
2118 if (rMin == LONG_MAX)
2119 rMin = 0;
2120 #endif
2123 int CGitStatusListCtrl::GetGroupFromPoint(POINT * ppt)
2125 // the point must be relative to the upper left corner of the control
2127 if (ppt == NULL)
2128 return -1;
2129 if (!IsGroupViewEnabled())
2130 return -1;
2132 POINT pt = *ppt;
2133 pt.x = 10;
2134 UINT flags = 0;
2135 int nItem = -1;
2136 RECT rc;
2137 GetWindowRect(&rc);
2138 while (((flags & LVHT_BELOW) == 0)&&(pt.y < rc.bottom))
2140 nItem = HitTest(pt, &flags);
2141 if ((flags & LVHT_ONITEM)||(flags & LVHT_EX_GROUP_HEADER))
2143 // the first item below the point
2145 // check if the point is too much right (i.e. if the point
2146 // is farther to the right than the width of the item)
2147 RECT r;
2148 GetItemRect(nItem, &r, LVIR_LABEL);
2149 if (ppt->x > r.right)
2150 return -1;
2152 LVITEM lv = {0};
2153 lv.mask = LVIF_GROUPID;
2154 lv.iItem = nItem;
2155 GetItem(&lv);
2156 int groupID = lv.iGroupId;
2157 // now we search upwards and check if the item above this one
2158 // belongs to another group. If it belongs to the same group,
2159 // we're not over a group header
2160 while (pt.y >= 0)
2162 pt.y -= 2;
2163 nItem = HitTest(pt, &flags);
2164 if ((flags & LVHT_ONITEM)&&(nItem >= 0))
2166 // the first item below the point
2167 LVITEM lv = {0};
2168 lv.mask = LVIF_GROUPID;
2169 lv.iItem = nItem;
2170 GetItem(&lv);
2171 if (lv.iGroupId != groupID)
2172 return groupID;
2173 else
2174 return -1;
2177 if (pt.y < 0)
2178 return groupID;
2179 return -1;
2181 pt.y += 2;
2183 return -1;
2186 void CGitStatusListCtrl::OnContextMenuGroup(CWnd * /*pWnd*/, CPoint point)
2188 POINT clientpoint = point;
2189 ScreenToClient(&clientpoint);
2190 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint) >= 0))
2192 CMenu popup;
2193 if (popup.CreatePopupMenu())
2195 CString temp;
2196 temp.LoadString(IDS_STATUSLIST_CHECKGROUP);
2197 popup.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CHECKGROUP, temp);
2198 temp.LoadString(IDS_STATUSLIST_UNCHECKGROUP);
2199 popup.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_UNCHECKGROUP, temp);
2200 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2201 bool bCheck = false;
2202 switch (cmd)
2204 case IDSVNLC_CHECKGROUP:
2205 bCheck = true;
2206 // fall through here
2207 case IDSVNLC_UNCHECKGROUP:
2209 int group = GetGroupFromPoint(&clientpoint);
2210 // go through all items and check/uncheck those assigned to the group
2211 // but block the OnLvnItemChanged handler
2212 m_bBlock = true;
2213 LVITEM lv;
2214 for (int i=0; i<GetItemCount(); ++i)
2216 SecureZeroMemory(&lv, sizeof(LVITEM));
2217 lv.mask = LVIF_GROUPID;
2218 lv.iItem = i;
2219 GetItem(&lv);
2221 if (lv.iGroupId == group)
2223 CTGitPath * entry = (CTGitPath*)GetItemData(i);
2224 if (entry)
2226 bool bOldCheck = entry->m_Checked;
2227 SetEntryCheck(entry, i, bCheck);
2228 if (bCheck != bOldCheck)
2230 if (bCheck)
2231 m_nSelected++;
2232 else
2233 m_nSelected--;
2239 GetStatisticsString();
2240 NotifyCheck();
2241 m_bBlock = false;
2243 break;
2249 void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point)
2252 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
2254 bool XPorLater = false;
2255 OSVERSIONINFOEX inf;
2256 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
2257 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
2258 GetVersionEx((OSVERSIONINFO *)&inf);
2259 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
2260 if (fullver >= 0x0501)
2261 XPorLater = true;
2262 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
2263 CTGitPath * filepath;
2265 int selIndex = GetSelectionMark();
2266 if ((point.x == -1) && (point.y == -1))
2268 CRect rect;
2269 GetItemRect(selIndex, &rect, LVIR_LABEL);
2270 ClientToScreen(&rect);
2271 point = rect.CenterPoint();
2273 if ((GetSelectedCount() == 0)&&(XPorLater)&&(m_bHasCheckboxes))
2275 // nothing selected could mean the context menu is requested for
2276 // a group header
2277 OnContextMenuGroup(pWnd, point);
2279 else if (selIndex >= 0)
2281 //FileEntry * entry = GetListEntry(selIndex);
2283 filepath = (CTGitPath * )GetItemData(selIndex);
2285 ASSERT(filepath != NULL);
2286 if (filepath == NULL)
2287 return;
2289 //const CTGitPath& filepath = entry->path;
2290 int wcStatus = filepath->m_Action;
2291 // entry is selected, now show the popup menu
2292 Locker lock(m_critSec);
2293 CIconMenu popup;
2294 CMenu changelistSubMenu;
2295 CMenu ignoreSubMenu;
2296 if (popup.CreatePopupMenu())
2298 //Add Menu for verion controled file
2300 if (wcStatus & CTGitPath::LOGACTIONS_UNMERGED)
2302 if ((m_dwContextMenus & SVNSLC_POPCONFLICT)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
2304 popup.AppendMenuIcon(IDSVNLC_EDITCONFLICT, IDS_MENUCONFLICT, IDI_CONFLICT);
2306 if (m_dwContextMenus & SVNSLC_POPRESOLVE)
2308 popup.AppendMenuIcon(IDSVNLC_RESOLVECONFLICT, IDS_STATUSLIST_CONTEXT_RESOLVED, IDI_RESOLVE);
2310 if ((m_dwContextMenus & SVNSLC_POPRESOLVE)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
2312 popup.AppendMenuIcon(IDSVNLC_RESOLVETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS, IDI_RESOLVE);
2313 popup.AppendMenuIcon(IDSVNLC_RESOLVEMINE, IDS_SVNPROGRESS_MENUUSEMINE, IDI_RESOLVE);
2315 if ((m_dwContextMenus & SVNSLC_POPCONFLICT)||(m_dwContextMenus & SVNSLC_POPRESOLVE))
2316 popup.AppendMenu(MF_SEPARATOR);
2319 if (!(wcStatus &CTGitPath::LOGACTIONS_UNVER))
2321 if (m_dwContextMenus & SVNSLC_POPCOMPAREWITHBASE)
2323 popup.AppendMenuIcon(IDSVNLC_COMPARE, IDS_LOG_COMPAREWITHBASE, IDI_DIFF);
2324 popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
2327 if (m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_COMPAREWC))
2329 if( (!m_CurrentVersion.IsEmpty()) && m_CurrentVersion != GIT_REV_ZERO)
2330 popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
2332 //Select one items
2333 if (GetSelectedCount() == 1)
2335 bool bEntryAdded = false;
2336 //if (entry->remotestatus <= git_wc_status_normal)
2338 // if (wcStatus > git_wc_status_normal)
2339 // {
2340 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
2341 // {
2342 if(!g_Git.IsInitRepos() && (m_dwContextMenus&SVNSLC_POPGNUDIFF))
2344 popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2346 bEntryAdded = true;
2348 // }
2349 // }
2352 //else if (wcStatus != git_wc_status_deleted)
2354 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
2355 // {
2356 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
2357 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
2358 // bEntryAdded = true;
2359 // }
2360 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
2361 // {
2362 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2363 // bEntryAdded = true;
2364 // }
2366 if (bEntryAdded)
2367 popup.AppendMenu(MF_SEPARATOR);
2369 //else if (GetSelectedCount() > 1)
2371 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
2372 // {
2373 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
2374 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
2375 // }
2379 if( (!this->m_Rev1.IsEmpty()) || (!this->m_Rev1.IsEmpty()) )
2381 if(GetSelectedCount() == 1)
2383 if (m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_COMPARETWO))
2385 popup.AppendMenuIcon(IDSVNLC_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2386 popup.SetDefaultItem(IDSVNLC_COMPARETWO, FALSE);
2388 if (m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_GNUDIFF2))
2390 popup.AppendMenuIcon(IDSVNLC_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2395 ///Select Multi item
2396 //if (GetSelectedCount() > 0)
2398 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
2399 // {
2400 // POSITION pos = GetFirstSelectedItemPosition();
2401 // int index = GetNextSelectedItem(pos);
2402 // if (index >= 0)
2403 // {
2404 // FileEntry * entry = GetListEntry(index);
2405 // git_wc_status_kind status1 = git_wc_status_none;
2406 // git_wc_status_kind status2 = git_wc_status_none;
2407 // if (entry)
2408 // status1 = entry->status;
2409 // index = GetNextSelectedItem(pos);
2410 // if (index >= 0)
2411 // {
2412 // entry = GetListEntry(index);
2413 // if (entry)
2414 // status2 = entry->status;
2415 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
2416 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
2417 // {
2418 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
2419 // }
2420 // }
2421 // }
2422 // }
2423 // if (wcStatus > git_wc_status_normal)
2424 // {
2425 // if (m_dwContextMenus & SVNSLC_POPREVERT)
2426 // {
2427 // // reverting missing folders is not possible
2428 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
2429 // {
2430 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
2431 // }
2432 // }
2433 // }
2434 // if (entry->remotestatus > git_wc_status_normal)
2435 // {
2436 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
2437 // {
2438 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
2439 // }
2440 // }
2443 if ( (GetSelectedCount() >0 ) && (!(wcStatus & CTGitPath::LOGACTIONS_UNVER)))
2445 if (m_dwContextMenus & SVNSLC_POPREVERT)
2447 popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
2450 if ((m_dwContextMenus & GetContextMenuBit(IDSVNLC_REVERTTOREV)) && ( !this->m_CurrentVersion.IsEmpty() )
2451 && this->m_CurrentVersion != GIT_REV_ZERO)
2453 popup.AppendMenuIcon(IDSVNLC_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2457 if ((GetSelectedCount() == 1)&&(!(wcStatus & CTGitPath::LOGACTIONS_UNVER))
2458 &&(!(wcStatus & CTGitPath::LOGACTIONS_IGNORE)))
2460 if (m_dwContextMenus & SVNSLC_POPSHOWLOG)
2462 popup.AppendMenuIcon(IDSVNLC_LOG, IDS_REPOBROWSE_SHOWLOG, IDI_LOG);
2464 if (m_dwContextMenus & SVNSLC_POPBLAME)
2466 popup.AppendMenuIcon(IDSVNLC_BLAME, IDS_MENUBLAME, IDI_BLAME);
2469 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
2470 if ( (GetSelectedCount() == 1) )
2472 if (m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_SAVEAS) )
2474 popup.AppendMenuIcon(IDSVNLC_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2477 if (m_dwContextMenus & SVNSLC_POPOPEN)
2479 popup.AppendMenuIcon(IDSVNLC_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2480 popup.AppendMenuIcon(IDSVNLC_OPEN, IDS_REPOBROWSE_OPEN, IDI_OPEN);
2481 popup.AppendMenuIcon(IDSVNLC_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2484 if (m_dwContextMenus & SVNSLC_POPEXPLORE)
2486 popup.AppendMenuIcon(IDSVNLC_EXPLORE, IDS_STATUSLIST_CONTEXT_EXPLORE, IDI_EXPLORER);
2490 if (GetSelectedCount() > 0)
2492 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
2493 // {
2494 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2495 // }
2496 // 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))
2497 // {
2498 // if (bShift)
2499 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
2500 // else
2501 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
2502 // }
2503 if ((wcStatus & CTGitPath::LOGACTIONS_UNVER)/*||(wcStatus == git_wc_status_deleted)*/)
2505 if (m_dwContextMenus & SVNSLC_POPADD)
2507 //if ( entry->IsFolder() )
2509 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
2511 //else
2513 popup.AppendMenuIcon(IDSVNLC_ADD, IDS_STATUSLIST_CONTEXT_ADD, IDI_ADD);
2517 if (m_dwContextMenus & SVNSLC_POPDELETE)
2519 popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2522 //if ( (wcStatus == git_wc_status_unversioned) || (wcStatus == git_wc_status_deleted) )
2524 if (m_dwContextMenus & SVNSLC_POPIGNORE)
2527 CTGitPathList ignorelist;
2528 FillListOfSelectedItemPaths(ignorelist);
2529 //check if all selected entries have the same extension
2530 bool bSameExt = true;
2531 CString sExt;
2532 for (int i=0; i<ignorelist.GetCount(); ++i)
2534 if (sExt.IsEmpty() && (i==0))
2535 sExt = ignorelist[i].GetFileExtension();
2536 else if (sExt.CompareNoCase(ignorelist[i].GetFileExtension())!=0)
2537 bSameExt = false;
2539 if (bSameExt)
2541 if (ignoreSubMenu.CreateMenu())
2543 CString ignorepath;
2544 if (ignorelist.GetCount()==1)
2545 ignorepath = ignorelist[0].GetFileOrDirectoryName();
2546 else
2547 ignorepath.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2548 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_IGNORE, ignorepath);
2549 ignorepath = _T("*")+sExt;
2550 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_IGNOREMASK, ignorepath);
2551 CString temp;
2552 temp.LoadString(IDS_MENUIGNORE);
2553 popup.InsertMenu((UINT)-1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)ignoreSubMenu.m_hMenu, temp);
2556 else
2558 CString temp;
2559 if (ignorelist.GetCount()==1)
2561 temp.LoadString(IDS_MENUIGNORE);
2563 else
2565 temp.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2567 popup.AppendMenuIcon(IDSVNLC_IGNORE, temp, IDI_IGNORE);
2575 if (GetSelectedCount() > 0)
2577 #if 0
2578 if ((!entry->IsFolder())&&(wcStatus >= git_wc_status_normal)
2579 &&(wcStatus!=git_wc_status_missing)&&(wcStatus!=git_wc_status_deleted)
2580 &&(wcStatus!=git_wc_status_added))
2582 popup.AppendMenu(MF_SEPARATOR);
2583 if ((entry->lock_token.IsEmpty())&&(!entry->IsFolder()))
2585 if (m_dwContextMenus & SVNSLC_POPLOCK)
2587 popup.AppendMenuIcon(IDSVNLC_LOCK, IDS_MENU_LOCK, IDI_LOCK);
2590 if ((!entry->lock_token.IsEmpty())&&(!entry->IsFolder()))
2592 if (m_dwContextMenus & SVNSLC_POPUNLOCK)
2594 popup.AppendMenuIcon(IDSVNLC_UNLOCK, IDS_MENU_UNLOCK, IDI_UNLOCK);
2599 if ((!entry->IsFolder())&&((!entry->lock_token.IsEmpty())||(!entry->lock_remotetoken.IsEmpty())))
2601 if (m_dwContextMenus & SVNSLC_POPUNLOCKFORCE)
2603 popup.AppendMenuIcon(IDSVNLC_UNLOCKFORCE, IDS_MENU_UNLOCKFORCE, IDI_UNLOCK);
2607 if (wcStatus != git_wc_status_missing && wcStatus != git_wc_status_deleted &&wcStatus!=git_wc_status_unversioned)
2609 popup.AppendMenu(MF_SEPARATOR);
2610 popup.AppendMenuIcon(IDSVNLC_PROPERTIES, IDS_STATUSLIST_CONTEXT_PROPERTIES, IDI_PROPERTIES);
2612 #endif
2613 popup.AppendMenu(MF_SEPARATOR);
2614 popup.AppendMenuIcon(IDSVNLC_COPY, IDS_STATUSLIST_CONTEXT_COPY, IDI_COPYCLIP);
2615 popup.AppendMenuIcon(IDSVNLC_COPYEXT, IDS_STATUSLIST_CONTEXT_COPYEXT, IDI_COPYCLIP);
2616 #if 0
2617 if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS)&&(XPorLater)
2618 &&(wcStatus != git_wc_status_unversioned)&&(wcStatus != git_wc_status_none))
2620 popup.AppendMenu(MF_SEPARATOR);
2621 // changelist commands
2622 size_t numChangelists = GetNumberOfChangelistsInSelection();
2623 if (numChangelists > 0)
2625 popup.AppendMenuIcon(IDSVNLC_REMOVEFROMCS, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS);
2627 if ((!entry->IsFolder())&&(changelistSubMenu.CreateMenu()))
2629 CString temp;
2630 temp.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS);
2631 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATECS, temp);
2633 if (entry->changelist.Compare(SVNSLC_IGNORECHANGELIST))
2635 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2636 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATEIGNORECS, SVNSLC_IGNORECHANGELIST);
2639 if (m_changelists.size() > 0)
2641 // find the changelist names
2642 bool bNeedSeparator = true;
2643 int cmdID = IDSVNLC_MOVETOCS;
2644 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
2646 if ((entry->changelist.Compare(it->first))&&(it->first.Compare(SVNSLC_IGNORECHANGELIST)))
2648 if (bNeedSeparator)
2650 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2651 bNeedSeparator = false;
2653 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, cmdID, it->first);
2654 cmdID++;
2658 temp.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS);
2659 popup.AppendMenu(MF_POPUP|MF_STRING, (UINT_PTR)changelistSubMenu.GetSafeHmenu(), temp);
2662 #endif
2665 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2667 m_bBlock = TRUE;
2668 AfxGetApp()->DoWaitCursor(1);
2669 int iItemCountBeforeMenuCmd = GetItemCount();
2670 bool bForce = false;
2671 switch (cmd)
2673 case IDSVNLC_VIEWREV:
2674 OpenFile(filepath,NOTEPAD2);
2675 break;
2676 case IDSVNLC_OPEN:
2677 OpenFile(filepath,OPEN);
2678 break;
2679 case IDSVNLC_OPENWITH:
2680 OpenFile(filepath,OPEN_WITH);
2681 break;
2682 case IDSVNLC_EXPLORE:
2684 ShellExecute(this->m_hWnd, _T("explore"), filepath->GetDirectory().GetWinPath(), NULL, NULL, SW_SHOW);
2686 break;
2688 // Compare current version and work copy.
2689 case IDSVNLC_COMPAREWC:
2691 POSITION pos = GetFirstSelectedItemPosition();
2692 while ( pos )
2694 int index = GetNextSelectedItem(pos);
2695 StartDiffWC(index);
2698 break;
2699 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2700 case IDSVNLC_COMPARE:
2702 POSITION pos = GetFirstSelectedItemPosition();
2703 while ( pos )
2705 int index = GetNextSelectedItem(pos);
2706 StartDiff(index);
2709 break;
2710 case IDSVNLC_COMPARETWO:
2712 POSITION pos = GetFirstSelectedItemPosition();
2713 while ( pos )
2715 int index = GetNextSelectedItem(pos);
2716 StartDiffTwo(index);
2719 break;
2720 case IDSVNLC_GNUDIFF1:
2722 // SVNDiff diff(NULL, this->m_hWnd, true);
2724 // if (entry->remotestatus <= git_wc_status_normal)
2725 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2726 // else
2727 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2728 if(m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
2729 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,GitRev::GetWorkingCopy(),
2730 *filepath,GitRev::GetHead());
2731 else
2732 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_CurrentVersion,
2733 *filepath,m_CurrentVersion+_T("~1"));
2735 break;
2736 case IDSVNLC_GNUDIFF2:
2738 // SVNDiff diff(NULL, this->m_hWnd, true);
2740 // if (entry->remotestatus <= git_wc_status_normal)
2741 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2742 // else
2743 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2745 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_Rev1,
2746 *filepath,m_Rev2);
2748 break;
2750 case IDSVNLC_ADD:
2751 { // The add went ok, but we now need to run through the selected items again
2752 // and update their status
2753 std::vector<int> selectIndex;
2755 POSITION pos = GetFirstSelectedItemPosition();
2756 int index;
2757 while ((index = GetNextSelectedItem(pos)) >= 0)
2759 selectIndex.push_back(index);
2761 for(int i=0;i<selectIndex.size();i++)
2763 index=selectIndex[i];
2765 CTGitPath * path=(CTGitPath*)GetItemData(index);
2766 ASSERT(path);
2767 if(path == NULL)
2768 continue;
2769 CString cmd;
2770 cmd.Format(_T("git.exe add -- \"%s\""),path->GetGitPathString());
2771 CString output;
2772 if(!g_Git.Run(cmd,&output,CP_ACP))
2774 path->m_Action = CTGitPath::LOGACTIONS_ADDED;
2775 SetEntryCheck(path,index,true);
2776 SetItemGroup(index,0);
2777 this->m_StatusFileList.AddPath(*path);
2778 this->m_UnRevFileList.RemoveItem(*path);
2779 this->m_IgnoreFileList.RemoveItem(*path);
2780 Show(this->m_dwShow,0,true,true);
2785 break;
2787 case IDSVNLC_DELETE:
2789 //Collect paths
2790 std::vector<int> selectIndex;
2792 POSITION pos = GetFirstSelectedItemPosition();
2793 int index;
2794 while ((index = GetNextSelectedItem(pos)) >= 0)
2796 selectIndex.push_back(index);
2799 //Create file-list ('\0' separated) for SHFileOperation
2800 CString filelist;
2801 for(int i=0;i<selectIndex.size();i++)
2803 index=selectIndex[i];
2805 CTGitPath * path=(CTGitPath*)GetItemData(index);
2806 ASSERT(path);
2807 if(path == NULL)
2808 continue;
2810 filelist += path->GetWinPathString();
2811 filelist += _T("|");
2813 filelist += _T("|");
2814 int len = filelist.GetLength();
2815 TCHAR * buf = new TCHAR[len+2];
2816 _tcscpy_s(buf, len+2, filelist);
2817 for (int i=0; i<len; ++i)
2818 if (buf[i] == '|')
2819 buf[i] = 0;
2820 SHFILEOPSTRUCT fileop;
2821 fileop.hwnd = this->m_hWnd;
2822 fileop.wFunc = FO_DELETE;
2823 fileop.pFrom = buf;
2824 fileop.pTo = NULL;
2825 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
2826 fileop.lpszProgressTitle = _T("deleting file");
2827 int result = SHFileOperation(&fileop);
2828 delete [] buf;
2830 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
2832 SetRedraw(FALSE);
2833 POSITION pos = NULL;
2834 while ((pos = GetFirstSelectedItemPosition()) != 0)
2836 int index = GetNextSelectedItem(pos);
2837 if (GetCheck(index))
2838 m_nSelected--;
2839 m_nTotal--;
2841 RemoveListEntry(index);
2843 SetRedraw(TRUE);
2846 break;
2848 case IDSVNLC_BLAME:
2850 CString sCmd;
2851 sCmd.Format(_T("\"%s\" /command:blame /path:\"%s\""),
2852 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath());
2854 CAppUtils::LaunchApplication(sCmd, NULL, false);
2856 break;
2858 case IDSVNLC_LOG:
2860 CString sCmd;
2861 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\""),
2862 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath());
2864 CAppUtils::LaunchApplication(sCmd, NULL, false);
2866 break;
2868 case IDSVNLC_EDITCONFLICT:
2870 CAppUtils::ConflictEdit(*filepath,false,this->m_bIsRevertTheirMy);
2871 break;
2873 case IDSVNLC_RESOLVETHEIRS: //follow up
2874 case IDSVNLC_RESOLVEMINE: //follow up
2875 case IDSVNLC_RESOLVECONFLICT:
2877 if (CMessageBox::Show(m_hWnd, IDS_PROC_RESOLVE, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO)==IDYES)
2879 POSITION pos = GetFirstSelectedItemPosition();
2880 while (pos != 0)
2882 int index;
2883 index = GetNextSelectedItem(pos);
2884 CTGitPath * fentry =(CTGitPath*) this->GetItemData(index);
2885 if(fentry == NULL)
2886 continue;
2887 CString gitcmd,output;
2888 output.Empty();
2889 int stage=0;
2891 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDSVNLC_RESOLVETHEIRS) ||
2892 ((this->m_bIsRevertTheirMy)&&cmd == IDSVNLC_RESOLVEMINE) )
2894 gitcmd.Format(_T("git.exe cat-file blob \":3:%s\""),fentry->GetGitPathString());
2895 if(g_Git.RunLogFile(gitcmd,(CString&)fentry->GetWinPathString()))
2897 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2898 continue;
2901 output.Empty();
2902 if ( ((!this->m_bIsRevertTheirMy)&&cmd == IDSVNLC_RESOLVEMINE) ||
2903 ((this->m_bIsRevertTheirMy)&&cmd == IDSVNLC_RESOLVETHEIRS) )
2905 gitcmd.Format(_T("git.exe cat-file blob \":2:%s\""),fentry->GetGitPathString());
2906 if(g_Git.RunLogFile(gitcmd,(CString&)fentry->GetWinPathString()))
2908 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2909 continue;
2913 output.Empty();
2914 if ( fentry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
2916 gitcmd.Format(_T("git.exe add -- \"%s\""),fentry->GetGitPathString());
2917 if(g_Git.Run(gitcmd,&output,CP_ACP))
2919 CMessageBox::Show(m_hWnd, output, _T("TortoiseGit"), MB_ICONERROR);
2920 }else
2922 fentry->m_Action |= CTGitPath::LOGACTIONS_MODIFIED;
2923 fentry->m_Action &=~CTGitPath::LOGACTIONS_UNMERGED;
2928 Show(m_dwShow, 0, m_bShowFolders);
2931 break;
2933 case IDSVNLC_IGNORE:
2935 CTGitPathList ignorelist;
2936 //std::vector<CString> toremove;
2937 FillListOfSelectedItemPaths(ignorelist, true);
2938 SetRedraw(FALSE);
2940 if(!CAppUtils::IgnoreFile(ignorelist,false))
2941 break;
2943 for(int i=0;i<ignorelist.GetCount();i++)
2945 int nListboxEntries = GetItemCount();
2946 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2948 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2949 if (path->GetGitPathString()==ignorelist[i].GetGitPathString())
2951 RemoveListEntry(nItem);
2952 break;
2956 SetRedraw(TRUE);
2958 #if 0
2959 CTSVNPathList ignorelist;
2960 std::vector<CString> toremove;
2961 FillListOfSelectedItemPaths(ignorelist, true);
2962 SetRedraw(FALSE);
2963 for (int j=0; j<ignorelist.GetCount(); ++j)
2965 int nListboxEntries = GetItemCount();
2966 for (int i=0; i<nListboxEntries; ++i)
2968 if (GetListEntry(i)->GetPath().IsEquivalentTo(ignorelist[j]))
2970 selIndex = i;
2971 break;
2974 CString name = CPathUtils::PathPatternEscape(ignorelist[j].GetFileOrDirectoryName());
2975 CTSVNPath parentfolder = ignorelist[j].GetContainingDirectory();
2976 SVNProperties props(parentfolder, SVNRev::REV_WC, false);
2977 CStringA value;
2978 for (int i=0; i<props.GetCount(); i++)
2980 CString propname(props.GetItemName(i).c_str());
2981 if (propname.CompareNoCase(_T("git:ignore"))==0)
2983 stdstring stemp;
2984 // treat values as normal text even if they're not
2985 value = (char *)props.GetItemValue(i).c_str();
2988 if (value.IsEmpty())
2989 value = name;
2990 else
2992 value = value.Trim("\n\r");
2993 value += "\n";
2994 value += name;
2995 value.Remove('\r');
2997 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
2999 CString temp;
3000 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
3001 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3002 break;
3004 if (GetCheck(selIndex))
3005 m_nSelected--;
3006 m_nTotal--;
3008 // now, if we ignored a folder, remove all its children
3009 if (ignorelist[j].IsDirectory())
3011 for (int i=0; i<(int)m_arListArray.size(); ++i)
3013 FileEntry * entry = GetListEntry(i);
3014 if (entry->status == git_wc_status_unversioned)
3016 if (!ignorelist[j].IsEquivalentTo(entry->GetPath())&&(ignorelist[j].IsAncestorOf(entry->GetPath())))
3018 entry->status = git_wc_status_ignored;
3019 entry->textstatus = git_wc_status_ignored;
3020 if (GetCheck(i))
3021 m_nSelected--;
3022 toremove.push_back(entry->GetPath().GetSVNPathString());
3028 CTSVNPath basepath = m_arStatusArray[m_arListArray[selIndex]]->basepath;
3030 FileEntry * entry = m_arStatusArray[m_arListArray[selIndex]];
3031 if ( entry->status == git_wc_status_unversioned ) // keep "deleted" items
3032 toremove.push_back(entry->GetPath().GetSVNPathString());
3034 if (!m_bIgnoreRemoveOnly)
3036 SVNStatus status;
3037 git_wc_status2_t * s;
3038 CTSVNPath gitPath;
3039 s = status.GetFirstFileStatus(parentfolder, gitPath, false, git_depth_empty);
3040 // first check if the folder isn't already present in the list
3041 bool bFound = false;
3042 nListboxEntries = GetItemCount();
3043 for (int i=0; i<nListboxEntries; ++i)
3045 FileEntry * entry = GetListEntry(i);
3046 if (entry->path.IsEquivalentTo(gitPath))
3048 bFound = true;
3049 break;
3052 if (!bFound)
3054 if (s!=0)
3056 FileEntry * entry = new FileEntry();
3057 entry->path = gitPath;
3058 entry->basepath = basepath;
3059 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
3060 entry->textstatus = s->text_status;
3061 entry->propstatus = s->prop_status;
3062 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
3063 entry->remotetextstatus = s->repos_text_status;
3064 entry->remotepropstatus = s->repos_prop_status;
3065 entry->inunversionedfolder = FALSE;
3066 entry->checked = true;
3067 entry->inexternal = false;
3068 entry->direct = false;
3069 entry->isfolder = true;
3070 entry->last_commit_date = 0;
3071 entry->last_commit_rev = 0;
3072 entry->remoterev = 0;
3073 if (s->entry)
3075 if (s->entry->url)
3077 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
3080 if (s->entry && s->entry->present_props)
3082 entry->present_props = s->entry->present_props;
3084 m_arStatusArray.push_back(entry);
3085 m_arListArray.push_back(m_arStatusArray.size()-1);
3086 AddEntry(entry, langID, GetItemCount());
3091 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
3093 int nListboxEntries = GetItemCount();
3094 for (int i=0; i<nListboxEntries; ++i)
3096 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
3098 RemoveListEntry(i);
3099 break;
3103 SetRedraw(TRUE);
3105 #endif
3106 break;
3107 case IDSVNLC_IGNOREMASK:
3109 CString common;
3110 CString ext=filepath->GetFileExtension();
3111 CTGitPathList ignorelist;
3112 FillListOfSelectedItemPaths(ignorelist, true);
3113 SetRedraw(FALSE);
3115 CAppUtils::IgnoreFile(ignorelist,true);
3116 common=ignorelist.GetCommonRoot().GetGitPathString();
3118 for (int i=0; i< GetItemCount(); ++i)
3120 CTGitPath *path=(CTGitPath*)GetItemData(i);
3121 if(!( path->m_Action & CTGitPath::LOGACTIONS_UNVER))
3122 continue;
3123 if( path->GetGitPathString().Left(common.GetLength()) == common )
3125 if (path->GetFileExtension()==ext)
3127 RemoveListEntry(i);
3128 i--; // remove index i at item, new one will replace.
3133 SetRedraw(TRUE);
3135 #if 0
3136 std::set<CTSVNPath> parentlist;
3137 for (int i=0; i<ignorelist.GetCount(); ++i)
3139 parentlist.insert(ignorelist[i].GetContainingDirectory());
3141 std::set<CTSVNPath>::iterator it;
3142 std::vector<CString> toremove;
3144 for (it = parentlist.begin(); it != parentlist.end(); ++it)
3146 CTSVNPath parentFolder = (*it).GetDirectory();
3147 SVNProperties props(parentFolder, SVNRev::REV_WC, false);
3148 CStringA value;
3149 for (int i=0; i<props.GetCount(); i++)
3151 CString propname(props.GetItemName(i).c_str());
3152 if (propname.CompareNoCase(_T("git:ignore"))==0)
3154 stdstring stemp;
3155 // treat values as normal text even if they're not
3156 value = (char *)props.GetItemValue(i).c_str();
3159 if (value.IsEmpty())
3160 value = name;
3161 else
3163 value = value.Trim("\n\r");
3164 value += "\n";
3165 value += name;
3166 value.Remove('\r');
3168 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
3170 CString temp;
3171 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
3172 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3174 else
3176 CTSVNPath basepath;
3177 int nListboxEntries = GetItemCount();
3178 for (int i=0; i<nListboxEntries; ++i)
3180 FileEntry * entry = GetListEntry(i);
3181 ASSERT(entry != NULL);
3182 if (entry == NULL)
3183 continue;
3184 if (basepath.IsEmpty())
3185 basepath = entry->basepath;
3186 // since we ignored files with a mask (e.g. *.exe)
3187 // we have to find find all files in the same
3188 // folder (IsAncestorOf() returns TRUE for _all_ children,
3189 // not just the immediate ones) which match the
3190 // mask and remove them from the list too.
3191 if ((entry->status == git_wc_status_unversioned)&&(parentFolder.IsAncestorOf(entry->path)))
3193 CString f = entry->path.GetSVNPathString();
3194 if (f.Mid(parentFolder.GetSVNPathString().GetLength()).Find('/')<=0)
3196 if (CStringUtils::WildCardMatch(name, f))
3198 if (GetCheck(i))
3199 m_nSelected--;
3200 m_nTotal--;
3201 toremove.push_back(f);
3206 if (!m_bIgnoreRemoveOnly)
3208 SVNStatus status;
3209 git_wc_status2_t * s;
3210 CTSVNPath gitPath;
3211 s = status.GetFirstFileStatus(parentFolder, gitPath, false, git_depth_empty);
3212 if (s!=0)
3214 // first check if the folder isn't already present in the list
3215 bool bFound = false;
3216 for (int i=0; i<nListboxEntries; ++i)
3218 FileEntry * entry = GetListEntry(i);
3219 if (entry->path.IsEquivalentTo(gitPath))
3221 bFound = true;
3222 break;
3225 if (!bFound)
3227 FileEntry * entry = new FileEntry();
3228 entry->path = gitPath;
3229 entry->basepath = basepath;
3230 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
3231 entry->textstatus = s->text_status;
3232 entry->propstatus = s->prop_status;
3233 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
3234 entry->remotetextstatus = s->repos_text_status;
3235 entry->remotepropstatus = s->repos_prop_status;
3236 entry->inunversionedfolder = false;
3237 entry->checked = true;
3238 entry->inexternal = false;
3239 entry->direct = false;
3240 entry->isfolder = true;
3241 entry->last_commit_date = 0;
3242 entry->last_commit_rev = 0;
3243 entry->remoterev = 0;
3244 if (s->entry)
3246 if (s->entry->url)
3248 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
3251 if (s->entry && s->entry->present_props)
3253 entry->present_props = s->entry->present_props;
3255 m_arStatusArray.push_back(entry);
3256 m_arListArray.push_back(m_arStatusArray.size()-1);
3257 AddEntry(entry, langID, GetItemCount());
3263 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
3265 int nListboxEntries = GetItemCount();
3266 for (int i=0; i<nListboxEntries; ++i)
3268 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
3270 RemoveListEntry(i);
3271 break;
3275 SetRedraw(TRUE);
3277 #endif
3278 break;
3280 case IDSVNLC_REVERT:
3282 // If at least one item is not in the status "added"
3283 // we ask for a confirmation
3284 BOOL bConfirm = FALSE;
3285 POSITION pos = GetFirstSelectedItemPosition();
3286 int index;
3287 while ((index = GetNextSelectedItem(pos)) >= 0)
3289 //FileEntry * fentry = GetListEntry(index);
3290 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
3291 if(fentry && fentry->m_Action &CTGitPath::LOGACTIONS_MODIFIED )
3293 bConfirm = TRUE;
3294 break;
3298 CString str;
3299 str.Format(IDS_PROC_WARNREVERT,GetSelectedCount());
3301 if (!bConfirm || CMessageBox::Show(this->m_hWnd, str, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION)==IDYES)
3303 CTGitPathList targetList;
3304 FillListOfSelectedItemPaths(targetList);
3306 // make sure that the list is reverse sorted, so that
3307 // children are removed before any parents
3308 targetList.SortByPathname(true);
3310 // put all reverted files in the trashbin, except the ones with 'added'
3311 // status because they are not restored by the revert.
3312 CTGitPathList delList;
3313 POSITION pos = GetFirstSelectedItemPosition();
3314 int index;
3315 while ((index = GetNextSelectedItem(pos)) >= 0)
3317 CTGitPath *entry=(CTGitPath *)GetItemData(index);
3318 if (entry&&(!(entry->m_Action& CTGitPath::LOGACTIONS_ADDED)))
3319 delList.AddPath(*entry);
3321 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
3322 delList.DeleteAllFiles(true);
3324 if (g_Git.Revert(targetList))
3326 CMessageBox::Show(this->m_hWnd, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR);
3328 else
3330 for(int i=0;i<targetList.GetCount();i++)
3332 int nListboxEntries = GetItemCount();
3333 for (int nItem=0; nItem<nListboxEntries; ++nItem)
3335 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
3336 if (path->GetGitPathString()==targetList[i].GetGitPathString())
3338 if(path->m_Action & CTGitPath::LOGACTIONS_ADDED)
3340 path->m_Action = CTGitPath::LOGACTIONS_UNVER;
3341 SetEntryCheck(path,nItem,false);
3342 PrepareGroups(true);
3343 SetItemGroup(nItem,1);
3344 this->m_StatusFileList.RemoveItem(*path);
3345 this->m_UnRevFileList.AddPath(*path);
3346 //this->m_IgnoreFileList.RemoveItem(*path);
3348 }else
3350 RemoveListEntry(nItem);
3352 break;
3356 SetRedraw(TRUE);
3357 SaveColumnWidths();
3358 Show(m_dwShow, 0, m_bShowFolders);
3359 NotifyCheck();
3363 break;
3365 case IDSVNLC_COPY:
3366 CopySelectedEntriesToClipboard(0);
3367 break;
3368 case IDSVNLC_COPYEXT:
3369 CopySelectedEntriesToClipboard((DWORD)-1);
3370 break;
3372 case IDSVNLC_SAVEAS:
3373 FileSaveAs(filepath);
3374 break;
3376 case IDSVNLC_REVERTTOREV:
3377 RevertSelectedItemToVersion();
3378 break;
3379 #if 0
3380 case IDSVNLC_PROPERTIES:
3382 CTSVNPathList targetList;
3383 FillListOfSelectedItemPaths(targetList);
3384 CEditPropertiesDlg dlg;
3385 dlg.SetPathList(targetList);
3386 dlg.DoModal();
3387 if (dlg.HasChanged())
3389 // since the user might have changed/removed/added
3390 // properties recursively, we don't really know
3391 // which items have changed their status.
3392 // So tell the parent to do a refresh.
3393 CWnd* pParent = GetParent();
3394 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3396 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3400 break;
3401 case IDSVNLC_COMMIT:
3403 CTSVNPathList targetList;
3404 FillListOfSelectedItemPaths(targetList);
3405 CTSVNPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
3406 VERIFY(targetList.WriteToFile(tempFile.GetWinPathString()));
3407 CString commandline = CPathUtils::GetAppDirectory();
3408 commandline += _T("TortoiseProc.exe /command:commit /pathfile:\"");
3409 commandline += tempFile.GetWinPathString();
3410 commandline += _T("\"");
3411 commandline += _T(" /deletepathfile");
3412 CAppUtils::LaunchApplication(commandline, NULL, false);
3414 break;
3416 case IDSVNLC_COMPAREWC:
3418 POSITION pos = GetFirstSelectedItemPosition();
3419 while ( pos )
3421 int index = GetNextSelectedItem(pos);
3422 FileEntry * entry = GetListEntry(index);
3423 ASSERT(entry != NULL);
3424 if (entry == NULL)
3425 continue;
3426 SVNDiff diff(NULL, m_hWnd, true);
3427 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
3428 git_revnum_t baseRev = entry->Revision;
3429 diff.DiffFileAgainstBase(
3430 entry->path, baseRev, entry->textstatus, entry->propstatus);
3433 break;
3434 case IDSVNLC_GNUDIFF1:
3436 SVNDiff diff(NULL, this->m_hWnd, true);
3438 if (entry->remotestatus <= git_wc_status_normal)
3439 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
3440 else
3441 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
3443 break;
3444 case IDSVNLC_UPDATE:
3446 CTSVNPathList targetList;
3447 FillListOfSelectedItemPaths(targetList);
3448 bool bAllExist = true;
3449 for (int i=0; i<targetList.GetCount(); ++i)
3451 if (!targetList[i].Exists())
3453 bAllExist = false;
3454 break;
3457 if (bAllExist)
3459 CSVNProgressDlg dlg;
3460 dlg.SetCommand(CSVNProgressDlg::SVNProgress_Update);
3461 dlg.SetPathList(targetList);
3462 dlg.SetRevision(SVNRev::REV_HEAD);
3463 dlg.DoModal();
3465 else
3467 CString sTempFile = CTempFiles::Instance().GetTempFilePath(false).GetWinPathString();
3468 targetList.WriteToFile(sTempFile, false);
3469 CString sCmd;
3470 sCmd.Format(_T("\"%s\" /command:update /rev /pathfile:\"%s\" /deletepathfile"),
3471 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)sTempFile);
3473 CAppUtils::LaunchApplication(sCmd, NULL, false);
3476 break;
3478 case IDSVNLC_REMOVE:
3480 SVN git;
3481 CTSVNPathList itemsToRemove;
3482 FillListOfSelectedItemPaths(itemsToRemove);
3484 // We must sort items before removing, so that files are always removed
3485 // *before* their parents
3486 itemsToRemove.SortByPathname(true);
3488 bool bSuccess = false;
3489 if (git.Remove(itemsToRemove, FALSE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3491 bSuccess = true;
3493 else
3495 if ((git.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE) ||
3496 (git.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))
3498 CString msg, yes, no, yestoall;
3499 msg.Format(IDS_PROC_REMOVEFORCE, (LPCTSTR)git.GetLastErrorMessage());
3500 yes.LoadString(IDS_MSGBOX_YES);
3501 no.LoadString(IDS_MSGBOX_NO);
3502 yestoall.LoadString(IDS_PROC_YESTOALL);
3503 UINT ret = CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_ERROR, yes, no, yestoall);
3504 if ((ret == 1)||(ret==3))
3506 if (!git.Remove(itemsToRemove, TRUE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3508 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3510 else
3511 bSuccess = true;
3514 else
3515 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3517 if (bSuccess)
3519 // The remove went ok, but we now need to run through the selected items again
3520 // and update their status
3521 POSITION pos = GetFirstSelectedItemPosition();
3522 int index;
3523 std::vector<int> entriesToRemove;
3524 while ((index = GetNextSelectedItem(pos)) >= 0)
3526 FileEntry * e = GetListEntry(index);
3527 if (!bShift &&
3528 ((e->textstatus == git_wc_status_unversioned)||
3529 (e->textstatus == git_wc_status_none)||
3530 (e->textstatus == git_wc_status_ignored)))
3532 if (GetCheck(index))
3533 m_nSelected--;
3534 m_nTotal--;
3535 entriesToRemove.push_back(index);
3537 else
3539 e->textstatus = git_wc_status_deleted;
3540 e->status = git_wc_status_deleted;
3541 SetEntryCheck(e,index,true);
3544 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3546 RemoveListEntry(*it);
3549 SaveColumnWidths();
3550 Show(m_dwShow, 0, m_bShowFolders);
3551 NotifyCheck();
3553 break;
3554 case IDSVNLC_DELETE:
3556 CTSVNPathList pathlist;
3557 FillListOfSelectedItemPaths(pathlist);
3558 pathlist.RemoveChildren();
3559 CString filelist;
3560 for (INT_PTR i=0; i<pathlist.GetCount(); ++i)
3562 filelist += pathlist[i].GetWinPathString();
3563 filelist += _T("|");
3565 filelist += _T("|");
3566 int len = filelist.GetLength();
3567 TCHAR * buf = new TCHAR[len+2];
3568 _tcscpy_s(buf, len+2, filelist);
3569 for (int i=0; i<len; ++i)
3570 if (buf[i] == '|')
3571 buf[i] = 0;
3572 SHFILEOPSTRUCT fileop;
3573 fileop.hwnd = this->m_hWnd;
3574 fileop.wFunc = FO_DELETE;
3575 fileop.pFrom = buf;
3576 fileop.pTo = NULL;
3577 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
3578 fileop.lpszProgressTitle = _T("deleting file");
3579 int result = SHFileOperation(&fileop);
3580 delete [] buf;
3582 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
3584 SetRedraw(FALSE);
3585 POSITION pos = NULL;
3586 CTSVNPathList deletedlist; // to store list of deleted folders
3587 while ((pos = GetFirstSelectedItemPosition()) != 0)
3589 int index = GetNextSelectedItem(pos);
3590 if (GetCheck(index))
3591 m_nSelected--;
3592 m_nTotal--;
3593 FileEntry * fentry = GetListEntry(index);
3594 if ((fentry)&&(fentry->isfolder))
3595 deletedlist.AddPath(fentry->path);
3596 RemoveListEntry(index);
3598 // now go through the list of deleted folders
3599 // and remove all their children from the list too!
3600 int nListboxEntries = GetItemCount();
3601 for (int folderindex = 0; folderindex < deletedlist.GetCount(); ++folderindex)
3603 CTSVNPath folderpath = deletedlist[folderindex];
3604 for (int i=0; i<nListboxEntries; ++i)
3606 FileEntry * entry = GetListEntry(i);
3607 if (folderpath.IsAncestorOf(entry->path))
3609 RemoveListEntry(i--);
3610 nListboxEntries--;
3614 SetRedraw(TRUE);
3617 break;
3620 case IDSVNLC_ADD:
3622 SVN git;
3623 CTSVNPathList itemsToAdd;
3624 FillListOfSelectedItemPaths(itemsToAdd);
3626 // We must sort items before adding, so that folders are always added
3627 // *before* any of their children
3628 itemsToAdd.SortByPathname();
3630 ProjectProperties props;
3631 props.ReadPropsPathList(itemsToAdd);
3632 if (git.Add(itemsToAdd, &props, git_depth_empty, TRUE, TRUE, TRUE))
3634 // The add went ok, but we now need to run through the selected items again
3635 // and update their status
3636 POSITION pos = GetFirstSelectedItemPosition();
3637 int index;
3638 while ((index = GetNextSelectedItem(pos)) >= 0)
3640 FileEntry * e = GetListEntry(index);
3641 e->textstatus = git_wc_status_added;
3642 e->propstatus = git_wc_status_none;
3643 e->status = git_wc_status_added;
3644 SetEntryCheck(e,index,true);
3647 else
3649 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3651 SaveColumnWidths();
3652 Show(m_dwShow, 0, m_bShowFolders);
3653 NotifyCheck();
3655 break;
3656 case IDSVNLC_ADD_RECURSIVE:
3658 CTSVNPathList itemsToAdd;
3659 FillListOfSelectedItemPaths(itemsToAdd);
3661 CAddDlg dlg;
3662 dlg.m_pathList = itemsToAdd;
3663 if (dlg.DoModal() == IDOK)
3665 if (dlg.m_pathList.GetCount() == 0)
3666 break;
3667 CSVNProgressDlg progDlg;
3668 progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Add);
3669 progDlg.SetPathList(dlg.m_pathList);
3670 ProjectProperties props;
3671 props.ReadPropsPathList(dlg.m_pathList);
3672 progDlg.SetProjectProperties(props);
3673 progDlg.SetItemCount(dlg.m_pathList.GetCount());
3674 progDlg.DoModal();
3676 // refresh!
3677 CWnd* pParent = GetParent();
3678 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3680 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3684 break;
3686 case IDSVNLC_REPAIRMOVE:
3688 POSITION pos = GetFirstSelectedItemPosition();
3689 int index = GetNextSelectedItem(pos);
3690 FileEntry * entry1 = NULL;
3691 FileEntry * entry2 = NULL;
3692 if (index >= 0)
3694 entry1 = GetListEntry(index);
3695 git_wc_status_kind status1 = git_wc_status_none;
3696 git_wc_status_kind status2 = git_wc_status_none;
3697 if (entry1)
3699 status1 = entry1->status;
3700 index = GetNextSelectedItem(pos);
3701 if (index >= 0)
3703 entry2 = GetListEntry(index);
3704 if (entry2)
3706 status2 = entry2->status;
3707 if (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned)
3709 FileEntry * tempentry = entry1;
3710 entry1 = entry2;
3711 entry2 = tempentry;
3713 // entry1 was renamed to entry2 but outside of Subversion
3714 // fix this by moving entry2 back to entry1 first,
3715 // then do an git-move from entry1 to entry2
3716 if (MoveFile(entry2->GetPath().GetWinPath(), entry1->GetPath().GetWinPath()))
3718 SVN git;
3719 if (!git.Move(CTSVNPathList(entry1->GetPath()), entry2->GetPath(), TRUE))
3721 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3723 else
3725 // check the previously unversioned item
3726 entry1->checked = true;
3727 // fixing the move was successful. We have to adjust the new status of the
3728 // files.
3729 // Since we don't know if the moved/renamed file had local modifications or not,
3730 // we can't guess the new status. That means we have to refresh...
3731 CWnd* pParent = GetParent();
3732 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3734 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3738 else
3740 LPVOID lpMsgBuf;
3741 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
3742 FORMAT_MESSAGE_FROM_SYSTEM |
3743 FORMAT_MESSAGE_IGNORE_INSERTS,
3744 NULL,
3745 GetLastError(),
3746 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
3747 (LPTSTR) &lpMsgBuf,
3749 NULL
3751 MessageBox((LPCTSTR)lpMsgBuf, _T("Error"), MB_OK | MB_ICONINFORMATION );
3752 LocalFree( lpMsgBuf );
3759 break;
3760 case IDSVNLC_REMOVEFROMCS:
3762 CTSVNPathList changelistItems;
3763 FillListOfSelectedItemPaths(changelistItems);
3764 SVN git;
3765 SetRedraw(FALSE);
3766 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
3768 // The changelists were removed, but we now need to run through the selected items again
3769 // and update their changelist
3770 POSITION pos = GetFirstSelectedItemPosition();
3771 int index;
3772 std::vector<int> entriesToRemove;
3773 while ((index = GetNextSelectedItem(pos)) >= 0)
3775 FileEntry * e = GetListEntry(index);
3776 if (e)
3778 e->changelist.Empty();
3779 if (e->status == git_wc_status_normal)
3781 // remove the entry completely
3782 entriesToRemove.push_back(index);
3784 else
3785 SetItemGroup(index, 0);
3788 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3790 RemoveListEntry(*it);
3792 // TODO: Should we go through all entries here and check if we also could
3793 // remove the changelist from m_changelists ?
3795 else
3797 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3799 SetRedraw(TRUE);
3801 break;
3802 case IDSVNLC_CREATEIGNORECS:
3803 CreateChangeList(SVNSLC_IGNORECHANGELIST);
3804 break;
3805 case IDSVNLC_CREATECS:
3807 CCreateChangelistDlg dlg;
3808 if (dlg.DoModal() == IDOK)
3810 CreateChangeList(dlg.m_sName);
3813 break;
3814 default:
3816 if (cmd < IDSVNLC_MOVETOCS)
3817 break;
3818 CTSVNPathList changelistItems;
3819 FillListOfSelectedItemPaths(changelistItems);
3821 // find the changelist name
3822 CString sChangelist;
3823 int cmdID = IDSVNLC_MOVETOCS;
3824 SetRedraw(FALSE);
3825 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
3827 if ((it->first.Compare(SVNSLC_IGNORECHANGELIST))&&(entry->changelist.Compare(it->first)))
3829 if (cmd == cmdID)
3831 sChangelist = it->first;
3833 cmdID++;
3836 if (!sChangelist.IsEmpty())
3838 SVN git;
3839 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
3841 // The changelists were moved, but we now need to run through the selected items again
3842 // and update their changelist
3843 POSITION pos = GetFirstSelectedItemPosition();
3844 int index;
3845 while ((index = GetNextSelectedItem(pos)) >= 0)
3847 FileEntry * e = GetListEntry(index);
3848 e->changelist = sChangelist;
3849 if (!e->IsFolder())
3851 if (m_changelists.find(e->changelist)!=m_changelists.end())
3852 SetItemGroup(index, m_changelists[e->changelist]);
3853 else
3854 SetItemGroup(index, 0);
3858 else
3860 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3863 SetRedraw(TRUE);
3865 break;
3866 #endif
3868 } // switch (cmd)
3869 m_bBlock = FALSE;
3870 AfxGetApp()->DoWaitCursor(-1);
3871 GetStatisticsString();
3872 int iItemCountAfterMenuCmd = GetItemCount();
3873 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
3875 // CWnd* pParent = GetParent();
3876 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3877 // {
3878 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
3879 // }
3881 } // if (popup.CreatePopupMenu())
3882 } // if (selIndex >= 0)
3886 void CGitStatusListCtrl::OnContextMenuHeader(CWnd * pWnd, CPoint point)
3888 bool XPorLater = false;
3889 OSVERSIONINFOEX inf;
3890 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
3891 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
3892 GetVersionEx((OSVERSIONINFO *)&inf);
3893 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
3894 if (fullver >= 0x0501)
3895 XPorLater = true;
3897 CHeaderCtrl * pHeaderCtrl = (CHeaderCtrl *)pWnd;
3898 if ((point.x == -1) && (point.y == -1))
3900 CRect rect;
3901 pHeaderCtrl->GetItemRect(0, &rect);
3902 ClientToScreen(&rect);
3903 point = rect.CenterPoint();
3905 Locker lock(m_critSec);
3906 CMenu popup;
3907 if (popup.CreatePopupMenu())
3909 int columnCount = m_ColumnManager.GetColumnCount();
3911 CString temp;
3912 UINT uCheckedFlags = MF_STRING | MF_ENABLED | MF_CHECKED;
3913 UINT uUnCheckedFlags = MF_STRING | MF_ENABLED;
3915 // build control menu
3917 if (XPorLater)
3919 temp.LoadString(IDS_STATUSLIST_SHOWGROUPS);
3920 popup.AppendMenu(IsGroupViewEnabled() ? uCheckedFlags : uUnCheckedFlags, columnCount, temp);
3923 if (m_ColumnManager.AnyUnusedProperties())
3925 temp.LoadString(IDS_STATUSLIST_REMOVEUNUSEDPROPS);
3926 popup.AppendMenu(uUnCheckedFlags, columnCount+1, temp);
3929 temp.LoadString(IDS_STATUSLIST_RESETCOLUMNORDER);
3930 popup.AppendMenu(uUnCheckedFlags, columnCount+2, temp);
3931 popup.AppendMenu(MF_SEPARATOR);
3933 // standard columns
3935 for (int i = 1; i < SVNSLC_NUMCOLUMNS; ++i)
3937 popup.AppendMenu ( m_ColumnManager.IsVisible(i)
3938 ? uCheckedFlags
3939 : uUnCheckedFlags
3941 , m_ColumnManager.GetName(i));
3944 // user-prop columns:
3945 // find relevant ones and sort 'em
3947 std::map<CString, int> sortedProps;
3948 for (int i = SVNSLC_NUMCOLUMNS; i < columnCount; ++i)
3949 if (m_ColumnManager.IsRelevant(i))
3950 sortedProps[m_ColumnManager.GetName(i)] = i;
3952 if (!sortedProps.empty())
3954 // add 'em to the menu
3956 popup.AppendMenu(MF_SEPARATOR);
3958 typedef std::map<CString, int>::const_iterator CIT;
3959 for ( CIT iter = sortedProps.begin(), end = sortedProps.end()
3960 ; iter != end
3961 ; ++iter)
3963 popup.AppendMenu ( m_ColumnManager.IsVisible(iter->second)
3964 ? uCheckedFlags
3965 : uUnCheckedFlags
3966 , iter->second
3967 , iter->first);
3971 // show menu & let user pick an entry
3973 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
3974 if ((cmd >= 1)&&(cmd < columnCount))
3976 m_ColumnManager.SetVisible (cmd, !m_ColumnManager.IsVisible(cmd));
3978 else if (cmd == columnCount)
3980 EnableGroupView(!IsGroupViewEnabled());
3982 else if (cmd == columnCount+1)
3984 m_ColumnManager.RemoveUnusedProps();
3986 else if (cmd == columnCount+2)
3988 m_ColumnManager.ResetColumns (m_dwDefaultColumns);
3993 void CGitStatusListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
3996 if (pWnd == this)
3998 OnContextMenuList(pWnd, point);
3999 } // if (pWnd == this)
4000 else if (pWnd == GetHeaderCtrl())
4002 OnContextMenuHeader(pWnd, point);
4006 void CGitStatusListCtrl::CreateChangeList(const CString& name)
4008 #if 0
4009 CTGitPathList changelistItems;
4010 FillListOfSelectedItemPaths(changelistItems);
4011 Git git;
4012 if (git.AddToChangeList(changelistItems, name, git_depth_empty))
4014 TCHAR groupname[1024];
4015 LVGROUP grp = {0};
4016 grp.cbSize = sizeof(LVGROUP);
4017 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
4018 _tcsncpy_s(groupname, 1024, name, 1023);
4019 grp.pszHeader = groupname;
4020 grp.iGroupId = (int)m_changelists.size();
4021 grp.uAlign = LVGA_HEADER_LEFT;
4022 m_changelists[name] = InsertGroup(-1, &grp);
4024 PrepareGroups(true);
4026 POSITION pos = GetFirstSelectedItemPosition();
4027 int index;
4028 while ((index = GetNextSelectedItem(pos)) >= 0)
4030 FileEntry * e = GetListEntry(index);
4031 e->changelist = name;
4032 SetEntryCheck(e, index, FALSE);
4035 for (index = 0; index < GetItemCount(); ++index)
4037 FileEntry * e = GetListEntry(index);
4038 if (m_changelists.find(e->changelist)!=m_changelists.end())
4039 SetItemGroup(index, m_changelists[e->changelist]);
4040 else
4041 SetItemGroup(index, 0);
4044 else
4046 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("Tortoisegit"), MB_ICONERROR);
4048 #endif
4051 void CGitStatusListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
4054 Locker lock(m_critSec);
4055 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
4056 *pResult = 0;
4057 if (m_bBlock)
4058 return;
4060 if (pNMLV->iItem < 0)
4062 if (!IsGroupViewEnabled())
4063 return;
4064 POINT pt;
4065 DWORD ptW = GetMessagePos();
4066 pt.x = GET_X_LPARAM(ptW);
4067 pt.y = GET_Y_LPARAM(ptW);
4068 ScreenToClient(&pt);
4069 int group = GetGroupFromPoint(&pt);
4070 if (group < 0)
4071 return;
4072 // check/uncheck the whole group depending on the check-state
4073 // of the first item in the group
4074 m_bBlock = true;
4075 bool bCheck = false;
4076 bool bFirst = false;
4077 LVITEM lv;
4078 for (int i=0; i<GetItemCount(); ++i)
4080 SecureZeroMemory(&lv, sizeof(LVITEM));
4081 lv.mask = LVIF_GROUPID;
4082 lv.iItem = i;
4083 GetItem(&lv);
4084 if (lv.iGroupId == group)
4086 CTGitPath *entry=(CTGitPath*)GetItemData(i);
4088 if (!bFirst)
4090 bCheck = !GetCheck(i);
4091 bFirst = true;
4093 if (entry)
4095 bool bOldCheck = !!GetCheck(i);
4096 SetEntryCheck(entry, i, bCheck);
4097 if (bCheck != bOldCheck)
4099 if (bCheck)
4100 m_nSelected++;
4101 else
4102 m_nSelected--;
4107 GetStatisticsString();
4108 m_bBlock = false;
4109 NotifyCheck();
4110 return;
4113 CTGitPath *file=(CTGitPath*)GetItemData(pNMLV->iItem);
4115 if( file->m_Action&CTGitPath::LOGACTIONS_UNMERGED )
4117 CAppUtils::ConflictEdit(*file,false,m_bIsRevertTheirMy);
4119 }else
4121 if( (!m_Rev1.IsEmpty()) || (!m_Rev1.IsEmpty()))
4122 StartDiffTwo(pNMLV->iItem);
4123 else
4124 StartDiff(pNMLV->iItem);
4128 void CGitStatusListCtrl::StartDiffTwo(int fileindex)
4130 if(fileindex<0)
4131 return;
4133 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
4135 CGitDiff::Diff(&file1,&file1,
4136 m_Rev1,
4137 m_Rev2);
4140 void CGitStatusListCtrl::StartDiffWC(int fileindex)
4142 if(fileindex<0)
4143 return;
4145 CString Ver;
4146 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
4147 return;
4149 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
4151 CGitDiff::Diff(&file1,&file1,
4152 CString(GIT_REV_ZERO),
4153 m_CurrentVersion);
4157 void CGitStatusListCtrl::StartDiff(int fileindex)
4159 if(fileindex<0)
4160 return;
4162 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
4163 CTGitPath file2;
4164 if(file1.m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
4166 file2.SetFromGit(file1.GetGitOldPathString());
4167 }else
4169 file2=file1;
4172 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
4174 if( g_Git.IsInitRepos())
4175 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
4176 CString(GIT_REV_ZERO));
4177 else if( file1.m_Action&CTGitPath::LOGACTIONS_DELETED )
4178 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
4179 GitRev::GetHead(),false);
4180 else
4181 CGitDiff::Diff(&file1,&file2,
4182 CString(GIT_REV_ZERO),
4183 GitRev::GetHead());
4184 }else
4186 CGitDiff::Diff(&file1,&file2,
4187 m_CurrentVersion,
4188 m_CurrentVersion+_T("~1"));
4190 #if 0
4191 if (fileindex < 0)
4192 return;
4193 FileEntry * entry = GetListEntry(fileindex);
4194 ASSERT(entry != NULL);
4195 if (entry == NULL)
4196 return;
4197 if (((entry->status == git_wc_status_normal)&&(entry->remotestatus <= git_wc_status_normal))||
4198 (entry->status == git_wc_status_unversioned)||(entry->status == git_wc_status_none))
4200 int ret = (int)ShellExecute(this->m_hWnd, NULL, entry->path.GetWinPath(), NULL, NULL, SW_SHOW);
4201 if (ret <= HINSTANCE_ERROR)
4203 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
4204 cmd += entry->path.GetWinPathString();
4205 CAppUtils::LaunchApplication(cmd, NULL, false);
4207 return;
4210 GitDiff diff(NULL, m_hWnd, true);
4211 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
4212 diff.DiffWCFile(
4213 entry->path, entry->textstatus, entry->propstatus,
4214 entry->remotetextstatus, entry->remotepropstatus);
4215 #endif
4218 CString CGitStatusListCtrl::GetStatisticsString()
4221 CString sNormal, sAdded, sDeleted, sModified, sConflicted, sUnversioned;
4222 WORD langID = (WORD)(DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4223 TCHAR buf[MAX_STATUS_STRING_LENGTH];
4224 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal, buf, sizeof(buf)/sizeof(TCHAR), langID);
4225 sNormal = buf;
4226 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added, buf, sizeof(buf)/sizeof(TCHAR), langID);
4227 sAdded = buf;
4228 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted, buf, sizeof(buf)/sizeof(TCHAR), langID);
4229 sDeleted = buf;
4230 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified, buf, sizeof(buf)/sizeof(TCHAR), langID);
4231 sModified = buf;
4232 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted, buf, sizeof(buf)/sizeof(TCHAR), langID);
4233 sConflicted = buf;
4234 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned, buf, sizeof(buf)/sizeof(TCHAR), langID);
4235 sUnversioned = buf;
4236 CString sToolTip;
4237 sToolTip.Format(_T("%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d"),
4238 (LPCTSTR)sNormal, m_nNormal,
4239 (LPCTSTR)sUnversioned, m_nUnversioned,
4240 (LPCTSTR)sModified, m_nModified,
4241 (LPCTSTR)sAdded, m_nAdded,
4242 (LPCTSTR)sDeleted, m_nDeleted,
4243 (LPCTSTR)sConflicted, m_nConflicted
4245 CString sStats;
4246 sStats.Format(IDS_COMMITDLG_STATISTICSFORMAT, m_nSelected, GetItemCount());
4247 if (m_pStatLabel)
4249 m_pStatLabel->SetWindowText(sStats);
4252 if (m_pSelectButton)
4254 if (m_nSelected == 0)
4255 m_pSelectButton->SetCheck(BST_UNCHECKED);
4256 else if (m_nSelected != GetItemCount())
4257 m_pSelectButton->SetCheck(BST_INDETERMINATE);
4258 else
4259 m_pSelectButton->SetCheck(BST_CHECKED);
4262 if (m_pConfirmButton)
4264 m_pConfirmButton->EnableWindow(m_nSelected>0);
4267 return sToolTip;
4272 CString CGitStatusListCtrl::GetCommonDirectory(bool bStrict)
4274 if (!bStrict)
4276 // not strict means that the selected folder has priority
4277 if (!m_StatusFileList.GetCommonDirectory().IsEmpty())
4278 return m_StatusFileList.GetCommonDirectory().GetWinPath();
4281 CTGitPath commonBaseDirectory;
4282 int nListItems = GetItemCount();
4283 for (int i=0; i<nListItems; ++i)
4285 CTGitPath baseDirectory,*p= (CTGitPath*)this->GetItemData(i);
4286 ASSERT(p);
4287 if(p==NULL)
4288 continue;
4289 baseDirectory = p->GetDirectory();
4291 if(commonBaseDirectory.IsEmpty())
4293 commonBaseDirectory = baseDirectory;
4295 else
4297 if (commonBaseDirectory.GetWinPathString().GetLength() > baseDirectory.GetWinPathString().GetLength())
4299 if (baseDirectory.IsAncestorOf(commonBaseDirectory))
4300 commonBaseDirectory = baseDirectory;
4304 return g_Git.m_CurrentDir+CString(_T("\\"))+commonBaseDirectory.GetWinPath();
4307 CTGitPath CGitStatusListCtrl::GetCommonURL(bool bStrict)
4309 CTGitPath commonBaseURL;
4310 #if 0
4312 if (!bStrict)
4314 // not strict means that the selected folder has priority
4315 if (!m_StatusUrlList.GetCommonDirectory().IsEmpty())
4316 return m_StatusUrlList.GetCommonDirectory();
4319 int nListItems = GetItemCount();
4320 for (int i=0; i<nListItems; ++i)
4322 const CTGitPath& baseURL = CTGitPath(GetListEntry(i)->GetURL());
4323 if (baseURL.IsEmpty())
4324 continue; // item has no url
4325 if(commonBaseURL.IsEmpty())
4327 commonBaseURL = baseURL;
4329 else
4331 if (commonBaseURL.GetGitPathString().GetLength() > baseURL.GetGitPathString().GetLength())
4333 if (baseURL.IsAncestorOf(commonBaseURL))
4334 commonBaseURL = baseURL;
4339 #endif
4340 return commonBaseURL;
4343 void CGitStatusListCtrl::SelectAll(bool bSelect, bool bIncludeNoCommits)
4345 CWaitCursor waitCursor;
4346 // block here so the LVN_ITEMCHANGED messages
4347 // get ignored
4348 m_bBlock = TRUE;
4349 SetRedraw(FALSE);
4351 int nListItems = GetItemCount();
4352 if (bSelect)
4353 m_nSelected = nListItems;
4354 else
4355 m_nSelected = 0;
4357 for (int i=0; i<nListItems; ++i)
4359 //FileEntry * entry = GetListEntry(i);
4360 //ASSERT(entry != NULL);
4361 CTGitPath *path = (CTGitPath *) GetItemData(i);
4362 if (path == NULL)
4363 continue;
4364 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
4365 SetEntryCheck(path,i,bSelect);
4368 // unblock before redrawing
4369 m_bBlock = FALSE;
4370 SetRedraw(TRUE);
4371 GetStatisticsString();
4372 NotifyCheck();
4375 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)
4377 LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);
4378 *pResult = 0;
4379 if (m_bBlock)
4380 return;
4381 #if 0
4382 if (GetListEntry(pGetInfoTip->iItem >= 0))
4383 if (pGetInfoTip->cchTextMax > GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString().GetLength())
4385 if (GetListEntry(pGetInfoTip->iItem)->GetRelativeGitPath().Compare(GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString())!= 0)
4386 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString(), pGetInfoTip->cchTextMax);
4387 else if (GetStringWidth(GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString()) > GetColumnWidth(pGetInfoTip->iItem))
4388 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString(), pGetInfoTip->cchTextMax);
4390 #endif
4393 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
4395 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
4397 // Take the default processing unless we set this to something else below.
4398 *pResult = CDRF_DODEFAULT;
4400 // First thing - check the draw stage. If it's the control's prepaint
4401 // stage, then tell Windows we want messages for every item.
4403 switch (pLVCD->nmcd.dwDrawStage)
4405 case CDDS_PREPAINT:
4406 *pResult = CDRF_NOTIFYITEMDRAW;
4407 break;
4408 case CDDS_ITEMPREPAINT:
4410 // This is the prepaint stage for an item. Here's where we set the
4411 // item's text color. Our return value will tell Windows to draw the
4412 // item itself, but it will use the new color we set here.
4414 // Tell Windows to paint the control itself.
4415 *pResult = CDRF_DODEFAULT;
4416 if (m_bBlock)
4417 return;
4419 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
4421 if (m_arStatusArray.size() > (DWORD_PTR)pLVCD->nmcd.dwItemSpec)
4424 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
4425 CTGitPath *entry=(CTGitPath *)GetItemData((int)pLVCD->nmcd.dwItemSpec);
4426 if (entry == NULL)
4427 return;
4429 // coloring
4430 // ========
4431 // black : unversioned, normal
4432 // purple : added
4433 // blue : modified
4434 // brown : missing, deleted, replaced
4435 // green : merged (or potential merges)
4436 // red : conflicts or sure conflicts
4437 if(entry->m_Action & CTGitPath::LOGACTIONS_GRAY)
4439 crText = RGB(128,128,128);
4441 }else if(entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
4443 crText = m_Colors.GetColor(CColors::Conflict);
4445 }else if(entry->m_Action & (CTGitPath::LOGACTIONS_MODIFIED))
4447 crText = m_Colors.GetColor(CColors::Modified);
4449 }else if(entry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
4451 crText = m_Colors.GetColor(CColors::Added);
4453 else if(entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
4455 crText = m_Colors.GetColor(CColors::DeletedNode);
4457 else if(entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
4459 crText = m_Colors.GetColor(CColors::RenamedNode);
4460 }else
4462 crText = GetSysColor(COLOR_WINDOWTEXT);
4464 // Store the color back in the NMLVCUSTOMDRAW struct.
4465 pLVCD->clrText = crText;
4468 break;
4472 BOOL CGitStatusListCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
4474 if (pWnd != this)
4475 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
4476 if (!m_bBlock)
4478 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
4479 SetCursor(hCur);
4480 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
4482 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
4483 SetCursor(hCur);
4484 return TRUE;
4487 void CGitStatusListCtrl::RemoveListEntry(int index)
4490 Locker lock(m_critSec);
4491 DeleteItem(index);
4493 m_arStatusArray.erase(m_arStatusArray.begin()+index);
4495 #if 0
4496 delete m_arStatusArray[m_arListArray[index]];
4497 m_arStatusArray.erase(m_arStatusArray.begin()+m_arListArray[index]);
4498 m_arListArray.erase(m_arListArray.begin()+index);
4499 for (int i=index; i< (int)m_arListArray.size(); ++i)
4501 m_arListArray[i]--;
4503 #endif
4506 ///< Set a checkbox on an entry in the listbox
4507 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
4508 void CGitStatusListCtrl::SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck)
4510 pEntry->m_Checked = bCheck;
4511 SetCheck(listboxIndex, bCheck);
4514 #if 0
4515 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck)
4518 int nListItems = GetItemCount();
4519 for (int j=0; j< nListItems ; ++j)
4521 FileEntry * childEntry = GetListEntry(j);
4522 ASSERT(childEntry != NULL);
4523 if (childEntry == NULL || childEntry == parentEntry)
4524 continue;
4525 if (childEntry->checked != bCheck)
4527 if (parentEntry->path.IsAncestorOf(childEntry->path))
4529 SetEntryCheck(childEntry,j,bCheck);
4530 if(bCheck)
4532 m_nSelected++;
4534 else
4536 m_nSelected--;
4543 #endif
4545 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList& pathList)
4548 pathList.Clear();
4549 int nListItems = GetItemCount();
4550 for (int i=0; i< nListItems; i++)
4552 CTGitPath * entry = (CTGitPath*)GetItemData(i);
4553 ASSERT(entry != NULL);
4554 if (entry->m_Checked)
4556 pathList.AddPath(*entry);
4559 pathList.SortByPathname();
4564 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
4565 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList& pathList, bool bNoIgnored)
4567 pathList.Clear();
4569 POSITION pos = GetFirstSelectedItemPosition();
4570 int index;
4571 while ((index = GetNextSelectedItem(pos)) >= 0)
4573 CTGitPath * entry = (CTGitPath*)GetItemData(index);
4574 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
4575 // continue;
4576 pathList.AddPath(*entry);
4580 UINT CGitStatusListCtrl::OnGetDlgCode()
4582 // we want to process the return key and not have that one
4583 // routed to the default pushbutton
4584 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS;
4587 void CGitStatusListCtrl::OnNMReturn(NMHDR * /*pNMHDR*/, LRESULT *pResult)
4589 *pResult = 0;
4590 if (m_bBlock)
4591 return;
4592 POSITION pos = GetFirstSelectedItemPosition();
4593 while ( pos )
4595 int index = GetNextSelectedItem(pos);
4596 StartDiff(index);
4600 void CGitStatusListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
4602 // Since we catch all keystrokes (to have the enter key processed here instead
4603 // of routed to the default pushbutton) we have to make sure that other
4604 // keys like Tab and Esc still do what they're supposed to do
4605 // Tab = change focus to next/previous control
4606 // Esc = quit the dialog
4607 switch (nChar)
4609 case (VK_TAB):
4611 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL, GetKeyState(VK_SHIFT)&0x8000, 0);
4612 return;
4614 break;
4615 case (VK_ESCAPE):
4617 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE, 0, 0);
4619 break;
4622 CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
4625 void CGitStatusListCtrl::PreSubclassWindow()
4627 CListCtrl::PreSubclassWindow();
4628 EnableToolTips(TRUE);
4629 m_Theme.SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);
4632 INT_PTR CGitStatusListCtrl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
4634 int row, col;
4635 RECT cellrect;
4636 row = CellRectFromPoint(point, &cellrect, &col );
4638 if (row == -1)
4639 return -1;
4642 pTI->hwnd = m_hWnd;
4643 pTI->uId = (UINT)((row<<10)+(col&0x3ff)+1);
4644 pTI->lpszText = LPSTR_TEXTCALLBACK;
4646 pTI->rect = cellrect;
4648 return pTI->uId;
4651 int CGitStatusListCtrl::CellRectFromPoint(CPoint& point, RECT *cellrect, int *col) const
4653 int colnum;
4655 // Make sure that the ListView is in LVS_REPORT
4656 if ((GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
4657 return -1;
4659 // Get the top and bottom row visible
4660 int row = GetTopIndex();
4661 int bottom = row + GetCountPerPage();
4662 if (bottom > GetItemCount())
4663 bottom = GetItemCount();
4665 // Get the number of columns
4666 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
4667 int nColumnCount = pHeader->GetItemCount();
4669 // Loop through the visible rows
4670 for ( ;row <=bottom;row++)
4672 // Get bounding rect of item and check whether point falls in it.
4673 CRect rect;
4674 GetItemRect(row, &rect, LVIR_BOUNDS);
4675 if (rect.PtInRect(point))
4677 // Now find the column
4678 for (colnum = 0; colnum < nColumnCount; colnum++)
4680 int colwidth = GetColumnWidth(colnum);
4681 if (point.x >= rect.left && point.x <= (rect.left + colwidth))
4683 RECT rectClient;
4684 GetClientRect(&rectClient);
4685 if (col)
4686 *col = colnum;
4687 rect.right = rect.left + colwidth;
4689 // Make sure that the right extent does not exceed
4690 // the client area
4691 if (rect.right > rectClient.right)
4692 rect.right = rectClient.right;
4693 *cellrect = rect;
4694 return row;
4696 rect.left += colwidth;
4700 return -1;
4703 BOOL CGitStatusListCtrl::OnToolTipText(UINT /*id*/, NMHDR *pNMHDR, LRESULT *pResult)
4705 #if 0
4706 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4707 CString strTipText;
4708 UINT_PTR nID = pNMHDR->idFrom;
4710 if (nID == 0)
4711 return FALSE;
4713 UINT_PTR row = ((nID-1) >> 10) & 0x3fffff;
4714 UINT_PTR col = (nID-1) & 0x3ff;
4716 if (col == 0)
4717 return FALSE; // no custom tooltip for the path, we use the infotip there!
4719 // get the internal column from the visible columns
4720 int internalcol = 0;
4721 UINT_PTR currentcol = 0;
4722 for (; (currentcol != col)
4723 && (internalcol < m_ColumnManager.GetColumnCount()-1)
4724 ; ++internalcol)
4726 if (m_ColumnManager.IsVisible (internalcol))
4727 currentcol++;
4730 AFX_MODULE_THREAD_STATE* pModuleThreadState = AfxGetModuleThreadState();
4731 CToolTipCtrl* pToolTip = pModuleThreadState->m_pToolTip;
4732 pToolTip->SendMessage(TTM_SETMAXTIPWIDTH, 0, 300);
4734 *pResult = 0;
4735 if ((internalcol == 2)||(internalcol == 4))
4737 FileEntry *fentry = GetListEntry(row);
4738 if (fentry)
4740 if (fentry->copied)
4742 CString url;
4743 url.Format(IDS_STATUSLIST_COPYFROM, (LPCTSTR)CPathUtils::PathUnescape(fentry->copyfrom_url), (LONG)fentry->copyfrom_rev);
4744 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4745 return TRUE;
4747 if (fentry->switched)
4749 CString url;
4750 url.Format(IDS_STATUSLIST_SWITCHEDTO, (LPCTSTR)CPathUtils::PathUnescape(fentry->url));
4751 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4752 return TRUE;
4754 if (fentry->keeplocal)
4756 lstrcpyn(pTTTW->szText, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_KEEPLOCAL)), 80);
4757 return TRUE;
4761 #endif
4762 return FALSE;
4765 void CGitStatusListCtrl::OnPaint()
4767 Default();
4768 if ((m_bBusy)||(m_bEmpty))
4770 CString str;
4771 if (m_bBusy)
4773 if (m_sBusy.IsEmpty())
4774 str.LoadString(IDS_STATUSLIST_BUSYMSG);
4775 else
4776 str = m_sBusy;
4778 else
4780 if (m_sEmpty.IsEmpty())
4781 str.LoadString(IDS_STATUSLIST_EMPTYMSG);
4782 else
4783 str = m_sEmpty;
4785 COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
4786 COLORREF clrTextBk;
4787 if (IsWindowEnabled())
4788 clrTextBk = ::GetSysColor(COLOR_WINDOW);
4789 else
4790 clrTextBk = ::GetSysColor(COLOR_3DFACE);
4792 CRect rc;
4793 GetClientRect(&rc);
4794 CHeaderCtrl* pHC;
4795 pHC = GetHeaderCtrl();
4796 if (pHC != NULL)
4798 CRect rcH;
4799 pHC->GetItemRect(0, &rcH);
4800 rc.top += rcH.bottom;
4802 CDC* pDC = GetDC();
4804 CMyMemDC memDC(pDC, &rc);
4806 memDC.SetTextColor(clrText);
4807 memDC.SetBkColor(clrTextBk);
4808 memDC.FillSolidRect(rc, clrTextBk);
4809 rc.top += 10;
4810 CGdiObject * oldfont = memDC.SelectStockObject(DEFAULT_GUI_FONT);
4811 memDC.DrawText(str, rc, DT_CENTER | DT_VCENTER |
4812 DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
4813 memDC.SelectObject(oldfont);
4815 ReleaseDC(pDC);
4819 // prevent users from extending our hidden (size 0) columns
4820 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
4822 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
4823 *pResult = 0;
4824 if ((phdr->iItem < 0)||(phdr->iItem >= SVNSLC_NUMCOLUMNS))
4825 return;
4827 if (m_ColumnManager.IsVisible (phdr->iItem))
4829 return;
4831 *pResult = 1;
4834 // prevent any function from extending our hidden (size 0) columns
4835 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
4837 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
4838 *pResult = 0;
4839 if ((phdr->iItem < 0)||(phdr->iItem >= m_ColumnManager.GetColumnCount()))
4841 Default();
4842 return;
4845 // visible columns may be modified
4847 if (m_ColumnManager.IsVisible (phdr->iItem))
4849 Default();
4850 return;
4853 // columns already marked as "invisible" internally may be (re-)sized to 0
4855 if ( (phdr->pitem != NULL)
4856 && (phdr->pitem->mask == HDI_WIDTH)
4857 && (phdr->pitem->cxy == 0))
4859 Default();
4860 return;
4863 if ( (phdr->pitem != NULL)
4864 && (phdr->pitem->mask != HDI_WIDTH))
4866 Default();
4867 return;
4870 *pResult = 1;
4873 void CGitStatusListCtrl::OnDestroy()
4875 SaveColumnWidths(true);
4876 CListCtrl::OnDestroy();
4879 void CGitStatusListCtrl::OnBeginDrag(NMHDR* /*pNMHDR*/, LRESULT* pResult)
4881 #if 0
4882 Locker lock(m_critSec);
4883 CDropFiles dropFiles; // class for creating DROPFILES struct
4885 int index;
4886 POSITION pos = GetFirstSelectedItemPosition();
4887 while ( (index = GetNextSelectedItem(pos)) >= 0 )
4889 FileEntry * fentry = m_arStatusArray[m_arListArray[index]];
4890 CTGitPath path = fentry->GetPath();
4891 dropFiles.AddFile( path.GetWinPathString() );
4894 if ( dropFiles.GetCount()>0 )
4896 m_bOwnDrag = true;
4897 dropFiles.CreateStructure();
4898 m_bOwnDrag = false;
4900 #endif
4901 *pResult = 0;
4904 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry /* = false */)
4906 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
4907 for (int col = 0; col <= maxcol; col++)
4908 if (m_ColumnManager.IsVisible (col))
4909 m_ColumnManager.ColumnResized (col);
4911 if (bSaveToRegistry)
4912 m_ColumnManager.WriteSettings();
4915 bool CGitStatusListCtrl::EnableFileDrop()
4917 m_bFileDropsEnabled = true;
4918 return true;
4921 bool CGitStatusListCtrl::HasPath(const CTGitPath& path)
4923 #if 0
4924 for (size_t i=0; i < m_arStatusArray.size(); i++)
4926 FileEntry * entry = m_arStatusArray[i];
4927 if (entry->GetPath().IsEquivalentTo(path))
4928 return true;
4930 #endif
4931 return false;
4934 bool CGitStatusListCtrl::IsPathShown(const CTGitPath& path)
4936 #if 0
4937 int itemCount = GetItemCount();
4938 for (int i=0; i < itemCount; i++)
4940 FileEntry * entry = GetListEntry(i);
4941 if (entry->GetPath().IsEquivalentTo(path))
4942 return true;
4944 #endif
4945 return false;
4948 BOOL CGitStatusListCtrl::PreTranslateMessage(MSG* pMsg)
4950 if (pMsg->message == WM_KEYDOWN)
4952 switch (pMsg->wParam)
4954 case 'A':
4956 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4958 // select all entries
4959 for (int i=0; i<GetItemCount(); ++i)
4961 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
4963 return TRUE;
4966 break;
4967 case 'C':
4968 case VK_INSERT:
4970 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4972 // copy all selected paths to the clipboard
4973 if (GetAsyncKeyState(VK_SHIFT)&0x8000)
4974 CopySelectedEntriesToClipboard(SVNSLC_COLSTATUS);
4975 else
4976 CopySelectedEntriesToClipboard(0);
4977 return TRUE;
4980 break;
4984 return CListCtrl::PreTranslateMessage(pMsg);
4987 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols)
4990 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
4991 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
4992 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4994 CString sClipboard;
4995 CString temp;
4996 TCHAR buf[100];
4997 if (GetSelectedCount() == 0)
4998 return false;
4999 // first add the column titles as the first line
5000 temp.LoadString(IDS_STATUSLIST_COLFILE);
5001 sClipboard = temp;
5003 DWORD selection = 0;
5004 for (int i = 0, count = m_ColumnManager.GetColumnCount(); i < count; ++i)
5005 if ( ((dwCols == -1) && m_ColumnManager.IsVisible (i))
5006 || ((dwCols != 1) && (i < 32) && ((dwCols & (1 << i)) != 0)))
5008 sClipboard += _T("\t") + m_ColumnManager.GetName(i);
5010 if (i < 32)
5011 selection += 1 << i;
5014 sClipboard += _T("\r\n");
5016 POSITION pos = GetFirstSelectedItemPosition();
5017 int index;
5018 while ((index = GetNextSelectedItem(pos)) >= 0)
5020 CTGitPath * entry = (CTGitPath*)GetItemData(index);
5021 if(entry == NULL)
5022 continue;
5024 sClipboard += entry->GetWinPathString();
5025 if (selection & SVNSLC_COLFILENAME)
5027 sClipboard += _T("\t")+entry->GetFileOrDirectoryName();
5029 if (selection & SVNSLC_COLEXT)
5031 sClipboard += _T("\t")+entry->GetFileExtension();
5034 if (selection & SVNSLC_COLSTATUS)
5036 #if 0
5037 if (entry->isNested)
5039 temp.LoadString(IDS_STATUSLIST_NESTED);
5041 else
5043 GitStatus::GetStatusString(hResourceHandle, entry->status, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
5044 if ((entry->copied)&&(_tcslen(buf)>1))
5045 _tcscat_s(buf, 100, _T(" (+)"));
5046 if ((entry->switched)&&(_tcslen(buf)>1))
5047 _tcscat_s(buf, 100, _T(" (s)"));
5048 if ((entry->status == entry->propstatus)&&
5049 (entry->status != git_wc_status_normal)&&
5050 (entry->status != git_wc_status_unversioned)&&
5051 (!GitStatus::IsImportant(entry->textstatus)))
5052 _tcscat_s(buf, 100, ponly);
5053 temp = buf;
5055 #endif
5056 sClipboard += _T("\t")+entry->GetActionName();
5058 #if 0
5059 if (selection & SVNSLC_COLTEXTSTATUS)
5062 if (entry->isNested)
5064 temp.LoadString(IDS_STATUSLIST_NESTED);
5066 else
5068 GitStatus::GetStatusString(hResourceHandle, entry->textstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
5069 if ((entry->copied)&&(_tcslen(buf)>1))
5070 _tcscat_s(buf, 100, _T(" (+)"));
5071 if ((entry->switched)&&(_tcslen(buf)>1))
5072 _tcscat_s(buf, 100, _T(" (s)"));
5073 temp = buf;
5075 sClipboard += _T("\t")+temp;
5077 #endif
5078 #if 0
5079 if (selection & SVNSLC_COLREMOTESTATUS)
5081 if (entry->isNested)
5083 temp.LoadString(IDS_STATUSLIST_NESTED);
5085 else
5087 GitStatus::GetStatusString(hResourceHandle, entry->remotestatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
5088 if ((entry->copied)&&(_tcslen(buf)>1))
5089 _tcscat_s(buf, 100, _T(" (+)"));
5090 if ((entry->switched)&&(_tcslen(buf)>1))
5091 _tcscat_s(buf, 100, _T(" (s)"));
5092 if ((entry->remotestatus == entry->remotepropstatus)&&
5093 (entry->remotestatus != git_wc_status_none)&&
5094 (entry->remotestatus != git_wc_status_normal)&&
5095 (entry->remotestatus != git_wc_status_unversioned)&&
5096 (!SVNStatus::IsImportant(entry->remotetextstatus)))
5097 _tcscat_s(buf, 100, ponly);
5098 temp = buf;
5100 sClipboard += _T("\t")+temp;
5102 if (selection & GitSLC_COLPROPSTATUS)
5104 if (entry->isNested)
5106 temp.Empty();
5108 else
5110 GitStatus::GetStatusString(hResourceHandle, entry->propstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
5111 if ((entry->copied)&&(_tcslen(buf)>1))
5112 _tcscat_s(buf, 100, _T(" (+)"));
5113 if ((entry->switched)&&(_tcslen(buf)>1))
5114 _tcscat_s(buf, 100, _T(" (s)"));
5115 temp = buf;
5117 sClipboard += _T("\t")+temp;
5119 if (selection & SVNSLC_COLREMOTETEXT)
5121 if (entry->isNested)
5123 temp.Empty();
5125 else
5127 GitStatus::GetStatusString(hResourceHandle, entry->remotetextstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
5128 temp = buf;
5130 sClipboard += _T("\t")+temp;
5132 if (selection & SVNSLC_COLREMOTEPROP)
5134 // SVNSLC_COLREMOTEPROP
5135 if (entry->isNested)
5137 temp.Empty();
5139 else
5141 GitStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
5142 temp = buf;
5144 sClipboard += _T("\t")+temp;
5146 if (selection & SVNSLC_COLURL)
5147 sClipboard += _T("\t")+entry->url;
5148 if (selection & SVNSLC_COLLOCK)
5150 if (!m_HeadRev.IsHead())
5152 // we have contacted the repository
5154 // decision-matrix
5155 // wc repository text
5156 // "" "" ""
5157 // "" UID1 owner
5158 // UID1 UID1 owner
5159 // UID1 "" lock has been broken
5160 // UID1 UID2 lock has been stolen
5161 if (entry->lock_token.IsEmpty() || (entry->lock_token.Compare(entry->lock_remotetoken)==0))
5163 if (entry->lock_owner.IsEmpty())
5164 temp = entry->lock_remoteowner;
5165 else
5166 temp = entry->lock_owner;
5168 else if (entry->lock_remotetoken.IsEmpty())
5170 // broken lock
5171 temp.LoadString(IDS_STATUSLIST_LOCKBROKEN);
5173 else
5175 // stolen lock
5176 temp.Format(IDS_STATUSLIST_LOCKSTOLEN, (LPCTSTR)entry->lock_remoteowner);
5179 else
5180 temp = entry->lock_owner;
5181 sClipboard += _T("\t")+temp;
5183 if (selection & SVNSLC_COLLOCKCOMMENT)
5184 sClipboard += _T("\t")+entry->lock_comment;
5185 if (selection & SVNSLC_COLAUTHOR)
5186 sClipboard += _T("\t")+entry->last_commit_author;
5187 if (selection & SVNSLC_COLREVISION)
5189 temp.Format(_T("%ld"), entry->last_commit_rev);
5190 if (entry->last_commit_rev == 0)
5191 temp.Empty();
5192 sClipboard += _T("\t")+temp;
5194 if (selection & SVNSLC_COLREMOTEREVISION)
5196 temp.Format(_T("%ld"), entry->remoterev);
5197 if (entry->remoterev == 0)
5198 temp.Empty();
5199 sClipboard += _T("\t")+temp;
5202 if (selection & SVNSLC_COLDATE)
5204 TCHAR datebuf[SVN_DATE_BUFFER];
5205 apr_time_t date = entry->last_commit_date;
5206 SVN::formatDate(datebuf, date, true);
5207 if (date)
5208 temp = datebuf;
5209 else
5210 temp.Empty();
5211 sClipboard += _T("\t")+temp;
5213 if (selection & SVNSLC_COLCOPYFROM)
5215 if (m_sURL.Compare(entry->copyfrom_url.Left(m_sURL.GetLength()))==0)
5216 temp = entry->copyfrom_url.Mid(m_sURL.GetLength());
5217 else
5218 temp = entry->copyfrom_url;
5219 sClipboard += _T("\t")+temp;
5222 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
5223 ; i < count
5224 ; ++i)
5226 if ((dwCols == -1) && m_ColumnManager.IsVisible (i))
5228 CString value
5229 = entry->present_props[m_ColumnManager.GetName(i)];
5230 sClipboard += _T("\t") + value;
5233 #endif
5234 if (selection & SVNSLC_COLADD)
5236 sClipboard += _T("\t")+entry->m_StatAdd;
5238 if (selection & SVNSLC_COLDEL)
5240 sClipboard += _T("\t")+entry->m_StatDel;
5243 sClipboard += _T("\r\n");
5246 return CStringUtils::WriteAsciiStringToClipboard(sClipboard);
5248 return TRUE;
5252 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
5254 #if 0
5255 std::set<CString> changelists;
5256 POSITION pos = GetFirstSelectedItemPosition();
5257 int index;
5258 while ((index = GetNextSelectedItem(pos)) >= 0)
5260 FileEntry * entry = GetListEntry(index);
5261 if (!entry->changelist.IsEmpty())
5262 changelists.insert(entry->changelist);
5264 return changelists.size();
5265 #endif
5266 return 0;
5269 bool CGitStatusListCtrl::PrepareGroups(bool bForce /* = false */)
5272 bool bHasGroups=false;
5273 if ( this->m_UnRevFileList.GetCount()>0 ||
5274 this->m_IgnoreFileList.GetCount()>0 || bForce)
5276 bHasGroups = true;
5279 RemoveAllGroups();
5280 EnableGroupView(bHasGroups);
5282 TCHAR groupname[1024];
5283 int groupindex = 0;
5285 if(bHasGroups)
5287 LVGROUP grp = {0};
5288 grp.cbSize = sizeof(LVGROUP);
5289 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5290 CString sUnassignedName(_T("Modified File"));
5291 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
5292 grp.pszHeader = groupname;
5293 grp.iGroupId = groupindex;
5294 grp.uAlign = LVGA_HEADER_LEFT;
5295 InsertGroup(groupindex++, &grp);
5297 //if(m_UnRevFileList.GetCount()>0)
5299 _tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Not Versioned"), 1023);
5300 grp.pszHeader = groupname;
5301 grp.iGroupId = groupindex;
5302 grp.uAlign = LVGA_HEADER_LEFT;
5303 InsertGroup(groupindex++, &grp);
5306 //if(m_IgnoreFileList.GetCount()>0)
5308 _tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Ignored"), 1023);
5309 grp.pszHeader = groupname;
5310 grp.iGroupId = groupindex;
5311 grp.uAlign = LVGA_HEADER_LEFT;
5312 InsertGroup(groupindex++, &grp);
5317 #if 0
5318 m_bHasIgnoreGroup = false;
5320 // now add the items which don't belong to a group
5321 LVGROUP grp = {0};
5322 grp.cbSize = sizeof(LVGROUP);
5323 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5324 CString sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET));
5325 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
5326 grp.pszHeader = groupname;
5327 grp.iGroupId = groupindex;
5328 grp.uAlign = LVGA_HEADER_LEFT;
5329 InsertGroup(groupindex++, &grp);
5331 for (std::map<CString,int>::iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
5333 if (it->first.Compare(SVNSLC_IGNORECHANGELIST)!=0)
5335 LVGROUP grp = {0};
5336 grp.cbSize = sizeof(LVGROUP);
5337 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5338 _tcsncpy_s(groupname, 1024, it->first, 1023);
5339 grp.pszHeader = groupname;
5340 grp.iGroupId = groupindex;
5341 grp.uAlign = LVGA_HEADER_LEFT;
5342 it->second = InsertGroup(groupindex++, &grp);
5344 else
5345 m_bHasIgnoreGroup = true;
5348 if (m_bHasIgnoreGroup)
5350 // and now add the group 'ignore-on-commit'
5351 std::map<CString,int>::iterator it = m_changelists.find(SVNSLC_IGNORECHANGELIST);
5352 if (it != m_changelists.end())
5354 grp.cbSize = sizeof(LVGROUP);
5355 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5356 _tcsncpy_s(groupname, 1024, SVNSLC_IGNORECHANGELIST, 1023);
5357 grp.pszHeader = groupname;
5358 grp.iGroupId = groupindex;
5359 grp.uAlign = LVGA_HEADER_LEFT;
5360 it->second = InsertGroup(groupindex, &grp);
5363 #endif
5364 return bHasGroups;
5367 void CGitStatusListCtrl::NotifyCheck()
5369 CWnd* pParent = GetParent();
5370 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
5372 pParent->SendMessage(SVNSLNM_CHECKCHANGED, m_nSelected);
5376 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash,CTGitPathList *list)
5378 BYTE_VECTOR out;
5379 this->m_bBusy=TRUE;
5380 m_CurrentVersion=hash;
5382 int count = 0;
5383 if(list == NULL)
5384 count = 1;
5385 else
5386 count = list->GetCount();
5388 if(hash == GIT_REV_ZERO)
5390 for(int i=0;i<count;i++)
5392 BYTE_VECTOR cmdout;
5393 cmdout.clear();
5394 CString cmd;
5395 if(!g_Git.IsInitRepos())
5397 if(list == NULL)
5398 cmd=(_T("git.exe diff-index --raw HEAD --numstat -C -M -z"));
5399 else
5400 cmd.Format(_T("git.exe diff-index --raw HEAD --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
5402 if(g_Git.Run(cmd,&cmdout))
5404 cmdout.clear();
5405 CString strout;
5406 if(g_Git.Run(_T("git.exe rev-parse --revs-only HEAD"),&strout,CP_UTF8))
5408 CMessageBox::Show(NULL,strout,_T("TortoiseGit"),MB_OK);
5409 return -1;
5411 if(strout.IsEmpty())
5412 break; //this is initial repositoyr, there are no any history
5414 CMessageBox::Show(NULL,strout,_T("TortoiseGit"),MB_OK);
5415 return -1;
5419 if(list == NULL)
5420 cmd=(_T("git.exe diff-index --cached --raw HEAD --numstat -C -M -z"));
5421 else
5422 cmd.Format(_T("git.exe diff-index --cached --raw HEAD --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
5424 g_Git.Run(cmd,&cmdout);
5425 //out+=cmdout;
5426 out.append(cmdout,0);
5428 else // Init Repository
5430 if(list == NULL)
5431 cmd=_T("git.exe ls-files -s -t -z");
5432 else
5433 cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
5435 g_Git.Run(cmd,&cmdout);
5436 //out+=cmdout;
5437 out.append(cmdout,0);
5441 if(g_Git.IsInitRepos())
5443 m_StatusFileList.ParserFromLsFile(out);
5444 for(int i=0;i<m_StatusFileList.GetCount();i++)
5445 ((CTGitPath&)(m_StatusFileList[i])).m_Action=CTGitPath::LOGACTIONS_ADDED;
5447 else
5448 this->m_StatusFileList.ParserFromLog(out);
5450 //handle delete conflict case, when remote : modified, local : deleted.
5451 for(int i=0;i<count;i++)
5453 BYTE_VECTOR cmdout;
5454 CString cmd;
5456 if(list == NULL)
5457 cmd=_T("git.exe ls-files -u -t -z");
5458 else
5459 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list)[i].GetGitPathString());
5461 g_Git.Run(cmd,&cmdout);
5463 CTGitPathList conflictlist;
5464 conflictlist.ParserFromLog(cmdout);
5465 for(int i=0;i<conflictlist.GetCount();i++)
5467 CTGitPath *p=m_StatusFileList.LookForGitPath(conflictlist[i].GetGitPathString());
5468 if(p)
5469 p->m_Action|=CTGitPath::LOGACTIONS_UNMERGED;
5470 else
5471 m_StatusFileList.AddPath(conflictlist[i]);
5475 }else
5477 int count = 0;
5478 if(list == NULL)
5479 count = 1;
5480 else
5481 count = list->GetCount();
5483 for(int i=0;i<count;i++)
5485 BYTE_VECTOR cmdout;
5486 CString cmd;
5487 if(list == NULL)
5488 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash);
5489 else
5490 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash,(*list)[i].GetGitPathString());
5492 g_Git.Run(cmd,&cmdout);
5494 out.append(cmdout);
5496 this->m_StatusFileList.ParserFromLog(out);
5500 for(int i=0;i<m_StatusFileList.GetCount();i++)
5502 CTGitPath * gitpatch=(CTGitPath*)&m_StatusFileList[i];
5503 gitpatch->m_Checked = TRUE;
5504 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
5507 this->m_bBusy=FALSE;
5508 return 0;
5511 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList &list)
5513 m_arStatusArray.clear();
5514 for(int i=0;i<list.GetCount();i++)
5516 CTGitPath * gitpath=(CTGitPath*)&list[i];
5518 if(gitpath ->m_Action & CTGitPath::LOGACTIONS_HIDE)
5519 continue;
5521 gitpath->m_Checked = TRUE;
5522 m_arStatusArray.push_back((CTGitPath*)&list[i]);
5524 return 0;
5527 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList *List)
5529 this->m_UnRevFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER,List);
5530 for(int i=0;i<m_UnRevFileList.GetCount();i++)
5532 CTGitPath * gitpatch=(CTGitPath*)&m_UnRevFileList[i];
5533 gitpatch->m_Checked = FALSE;
5534 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
5536 return 0;
5539 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList *List)
5541 this->m_IgnoreFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER|CTGitPath::LOGACTIONS_IGNORE,List);
5542 for(int i=0;i<m_IgnoreFileList.GetCount();i++)
5544 CTGitPath * gitpatch=(CTGitPath*)&m_IgnoreFileList[i];
5545 gitpatch->m_Checked = FALSE;
5546 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
5548 return 0;
5550 int CGitStatusListCtrl::UpdateFileList(int mask,bool once,CTGitPathList *List)
5552 if(mask&CGitStatusListCtrl::FILELIST_MODIFY)
5554 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_MODIFY)))
5556 UpdateFileList(git_revnum_t(GIT_REV_ZERO),List);
5557 m_FileLoaded|=CGitStatusListCtrl::FILELIST_MODIFY;
5560 if(mask&CGitStatusListCtrl::FILELIST_UNVER)
5562 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_UNVER)))
5564 UpdateUnRevFileList(List);
5565 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
5568 return 0;
5571 void CGitStatusListCtrl::Clear()
5573 m_FileLoaded=0;
5574 this->DeleteAllItems();
5575 this->m_arListArray.clear();
5576 this->m_arStatusArray.clear();
5577 this->m_changelists.clear();
5579 //////////////////////////////////////////////////////////////////////////
5580 #if 0
5581 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD * /*pdwEffect*/, POINTL pt)
5583 if(pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
5585 HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
5586 if(hDrop != NULL)
5588 TCHAR szFileName[MAX_PATH];
5590 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
5592 POINT clientpoint;
5593 clientpoint.x = pt.x;
5594 clientpoint.y = pt.y;
5595 ScreenToClient(m_hTargetWnd, &clientpoint);
5596 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5598 CTSVNPathList changelistItems;
5599 for(UINT i = 0; i < cFiles; ++i)
5601 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5602 changelistItems.AddPath(CTSVNPath(szFileName));
5604 // find the changelist name
5605 CString sChangelist;
5606 LONG_PTR nGroup = m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint);
5607 for (std::map<CString, int>::iterator it = m_pSVNStatusListCtrl->m_changelists.begin(); it != m_pSVNStatusListCtrl->m_changelists.end(); ++it)
5608 if (it->second == nGroup)
5609 sChangelist = it->first;
5610 if (!sChangelist.IsEmpty())
5612 SVN git;
5613 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
5615 for (int l=0; l<changelistItems.GetCount(); ++l)
5617 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5618 if (index >= 0)
5620 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5621 if (e)
5623 e->changelist = sChangelist;
5624 if (!e->IsFolder())
5626 if (m_pSVNStatusListCtrl->m_changelists.find(e->changelist)!=m_pSVNStatusListCtrl->m_changelists.end())
5627 m_pSVNStatusListCtrl->SetItemGroup(index, m_pSVNStatusListCtrl->m_changelists[e->changelist]);
5628 else
5629 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5633 else
5635 HWND hParentWnd = GetParent(m_hTargetWnd);
5636 if (hParentWnd != NULL)
5637 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5641 else
5643 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
5646 else
5648 SVN git;
5649 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
5651 for (int l=0; l<changelistItems.GetCount(); ++l)
5653 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5654 if (index >= 0)
5656 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5657 if (e)
5659 e->changelist = sChangelist;
5660 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5663 else
5665 HWND hParentWnd = GetParent(m_hTargetWnd);
5666 if (hParentWnd != NULL)
5667 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5671 else
5673 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
5677 else
5679 for(UINT i = 0; i < cFiles; ++i)
5681 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5682 HWND hParentWnd = GetParent(m_hTargetWnd);
5683 if (hParentWnd != NULL)
5684 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)szFileName);
5688 GlobalUnlock(medium.hGlobal);
5690 return true; //let base free the medium
5692 HRESULT STDMETHODCALLTYPE CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)
5694 CIDropTarget::DragOver(grfKeyState, pt, pdwEffect);
5695 *pdwEffect = DROPEFFECT_COPY;
5696 if (m_pSVNStatusListCtrl)
5698 POINT clientpoint;
5699 clientpoint.x = pt.x;
5700 clientpoint.y = pt.y;
5701 ScreenToClient(m_hTargetWnd, &clientpoint);
5702 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5704 *pdwEffect = DROPEFFECT_MOVE;
5706 else if ((!m_pSVNStatusListCtrl->m_bFileDropsEnabled)||(m_pSVNStatusListCtrl->m_bOwnDrag))
5708 *pdwEffect = DROPEFFECT_NONE;
5711 return S_OK;
5714 #endif
5716 void CGitStatusListCtrl::FileSaveAs(CTGitPath *path)
5718 CString filename;
5719 filename.Format(_T("%s-%s%s"),path->GetBaseFilename(),this->m_CurrentVersion.Left(6),path->GetFileExtension());
5720 CFileDialog dlg(FALSE,NULL,
5721 filename,
5722 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
5723 NULL);
5724 CString currentpath;
5725 currentpath=g_Git.m_CurrentDir+_T("\\");
5726 currentpath+=path->GetWinPathString();
5728 dlg.m_ofn.lpstrInitialDir=currentpath.GetBuffer();
5730 CString cmd,out;
5731 if(dlg.DoModal()==IDOK)
5733 filename = dlg.GetFileName();
5734 if(m_CurrentVersion == GIT_REV_ZERO)
5736 cmd.Format(_T("copy /Y \"%s\" \"%s\""),path->GetWinPath(),filename);
5737 if(g_Git.Run(cmd,&out,CP_ACP))
5739 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5740 return;
5743 }else
5745 cmd.Format(_T("git.exe cat-file -p %s:\"%s\""),m_CurrentVersion,path->GetGitPathString());
5746 if(g_Git.RunLogFile(cmd,filename))
5748 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5749 return;
5756 int CGitStatusListCtrl::RevertSelectedItemToVersion()
5758 if(this->m_CurrentVersion.IsEmpty())
5759 return 0;
5760 if(this->m_CurrentVersion == GIT_REV_ZERO)
5761 return 0;
5763 POSITION pos = GetFirstSelectedItemPosition();
5764 int index;
5765 CString cmd,out;
5766 int count =0;
5767 while ((index = GetNextSelectedItem(pos)) >= 0)
5769 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
5770 cmd.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion,fentry->GetGitPathString());
5771 out.Empty();
5772 if(g_Git.Run(cmd,&out,CP_ACP))
5774 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5776 count++;
5779 out.Format(_T("%d files revert to %s"),count,m_CurrentVersion.Left(6));
5780 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5781 return 0;
5784 void CGitStatusListCtrl::OpenFile(CTGitPath*filepath,int mode)
5786 CString file;
5787 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
5789 file= filepath->GetWinPath();
5790 }else
5792 CString temppath;
5793 GetTempPath(temppath);
5794 file.Format(_T("%s%s_%s%s"),
5795 temppath,
5796 filepath->GetBaseFilename(),
5797 m_CurrentVersion.Left(6),
5798 filepath->GetFileExtension());
5799 CString cmd,out;
5800 cmd.Format(_T("git.exe cat-file -p %s:\"%s\""),m_CurrentVersion,filepath->GetGitPathString());
5801 if(g_Git.RunLogFile(cmd,file))
5803 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5804 return;
5808 if(mode == NOTEPAD2)
5810 CString sCmd;
5811 sCmd.Format(_T("\"%s\" \"%s\""),
5812 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("notepad2.exe")), file);
5814 CAppUtils::LaunchApplication(sCmd, NULL, false);
5815 return ;
5817 int ret = HINSTANCE_ERROR;
5819 if(mode == OPEN )
5821 ret = (int)ShellExecute(this->m_hWnd, NULL,file, NULL, NULL, SW_SHOW);
5823 if (ret > HINSTANCE_ERROR)
5825 return;
5830 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
5831 cmd += file;
5832 CAppUtils::LaunchApplication(cmd, NULL, false);