Update version number
[TortoiseGit.git] / src / Git / GitStatusListCtrl.cpp
blobe538bac4a3a6ab1570671634432cc9e8ad965403
3 // TortoiseSVN - a Windows shell extension for easy version control
5 // Copyright (C) 2003-2008 - TortoiseSVN
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "StdAfx.h"
23 #include "GitStatusListCtrl.h"
24 #include "resource.h"
25 #include "..\\TortoiseShell\resource.h"
26 #include "MessageBox.h"
27 #include "MyMemDC.h"
28 #include "UnicodeUtils.h"
29 #include "AppUtils.h"
30 #include "PathUtils.h"
31 #include "TempFile.h"
32 #include "StringUtils.h"
33 #include "DirFileEnum.h"
34 #include "GitConfig.h"
35 //#include "SVNProperties.h"
36 #include "Git.h"
37 #include "GitDiff.h"
38 //#include "LogDlg.h"
39 //#include "SVNProgressDlg.h"
40 #include "SysImageList.h"
41 //#include "Svnstatuslistctrl.h"
42 #include "TGitPath.h"
43 #include "Registry.h"
44 #include "GitStatus.h"
45 //#include "SVNHelpers.h"
46 #include "InputDlg.h"
47 #include "ShellUpdater.h"
48 #include "GitAdminDir.h"
49 //#include "DropFiles.h"
50 #include "IconMenu.h"
51 //#include "AddDlg.h"
52 //#include "EditPropertiesDlg.h"
53 //#include "CreateChangelistDlg.h"
54 #include "XPTheme.h"
55 #include "CommonResource.h"
57 const UINT CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED
58 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
59 const UINT CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH
60 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
61 const UINT CGitStatusListCtrl::SVNSLNM_ADDFILE
62 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
63 const UINT CGitStatusListCtrl::SVNSLNM_CHECKCHANGED
64 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
69 BEGIN_MESSAGE_MAP(CGitStatusListCtrl, CListCtrl)
70 ON_NOTIFY(HDN_ITEMCLICKA, 0, OnHdnItemclick)
71 ON_NOTIFY(HDN_ITEMCLICKW, 0, OnHdnItemclick)
72 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
73 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
74 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, OnLvnItemchanged)
75 ON_WM_CONTEXTMENU()
76 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk)
77 ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnLvnGetInfoTip)
78 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
79 ON_WM_SETCURSOR()
80 ON_WM_GETDLGCODE()
81 ON_NOTIFY_REFLECT(NM_RETURN, OnNMReturn)
82 ON_WM_KEYDOWN()
83 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
84 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
85 ON_WM_PAINT()
86 ON_NOTIFY(HDN_BEGINTRACKA, 0, &CGitStatusListCtrl::OnHdnBegintrack)
87 ON_NOTIFY(HDN_BEGINTRACKW, 0, &CGitStatusListCtrl::OnHdnBegintrack)
88 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, &CGitStatusListCtrl::OnHdnItemchanging)
89 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, &CGitStatusListCtrl::OnHdnItemchanging)
90 ON_WM_DESTROY()
91 ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBeginDrag)
92 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING, &CGitStatusListCtrl::OnLvnItemchanging)
93 END_MESSAGE_MAP()
97 CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl()
98 //, m_HeadRev(GitRev::REV_HEAD)
99 , m_pbCanceled(NULL)
100 , m_pStatLabel(NULL)
101 , m_pSelectButton(NULL)
102 , m_pConfirmButton(NULL)
103 , m_bBusy(false)
104 , m_bEmpty(false)
105 , m_bUnversionedRecurse(true)
106 , m_bShowIgnores(false)
107 , m_pDropTarget(NULL)
108 , m_bIgnoreRemoveOnly(false)
109 , m_bCheckChildrenWithParent(false)
110 , m_bUnversionedLast(true)
111 , m_bHasChangeLists(false)
112 , m_bHasLocks(false)
113 , m_bBlock(false)
114 , m_bBlockUI(false)
115 , m_bHasCheckboxes(false)
116 , m_bCheckIfGroupsExist(true)
117 , m_bFileDropsEnabled(false)
118 , m_bOwnDrag(false)
119 , m_dwDefaultColumns(0)
120 , m_ColumnManager(this)
121 , m_bAscending(false)
122 , m_nSortedColumn(-1)
123 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE))
125 m_FileLoaded=0;
126 m_critSec.Init();
129 CGitStatusListCtrl::~CGitStatusListCtrl()
131 // if (m_pDropTarget)
132 // delete m_pDropTarget;
133 ClearStatusArray();
136 void CGitStatusListCtrl::ClearStatusArray()
138 #if 0
139 Locker lock(m_critSec);
140 for (size_t i=0; i < m_arStatusArray.size(); i++)
142 delete m_arStatusArray[i];
144 m_arStatusArray.clear();
145 #endif
147 #if 0
148 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(UINT_PTR index)
151 if (index >= (UINT_PTR)m_arListArray.size())
152 return NULL;
153 if (m_arListArray[index] >= m_arStatusArray.size())
154 return NULL;
155 return m_arStatusArray[m_arListArray[index]];
157 return NULL;
159 #endif
160 #if 0
161 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetVisibleListEntry(const CTGitPath& path)
163 int itemCount = GetItemCount();
164 for (int i=0; i < itemCount; i++)
166 FileEntry * entry = GetListEntry(i);
167 if (entry->GetPath().IsEquivalentTo(path))
168 return entry;
170 return NULL;
172 #endif
173 #if 0
174 CGitStatusListCtrl::FileEntry * CGitStatusListCtrl::GetListEntry(const CTGitPath& path)
177 for (size_t i=0; i < m_arStatusArray.size(); i++)
179 FileEntry * entry = m_arStatusArray[i];
180 if (entry->GetPath().IsEquivalentTo(path))
181 return entry;
184 return NULL;
186 #endif
188 #if 0
189 int CGitStatusListCtrl::GetIndex(const CTGitPath& path)
191 int itemCount = GetItemCount();
192 for (int i=0; i < itemCount; i++)
194 FileEntry * entry = GetListEntry(i);
195 if (entry->GetPath().IsEquivalentTo(path))
196 return i;
198 return -1;
200 #endif
202 void CGitStatusListCtrl::Init(DWORD dwColumns, const CString& sColumnInfoContainer, unsigned __int64 dwContextMenus /* = GitSLC_POPALL */, bool bHasCheckboxes /* = true */)
204 Locker lock(m_critSec);
206 m_dwDefaultColumns = dwColumns | 1;
207 m_dwContextMenus = dwContextMenus;
208 m_bHasCheckboxes = bHasCheckboxes;
210 // set the extended style of the listcontrol
211 // the style LVS_EX_FULLROWSELECT interferes with the background watermark image but it's more important to be able to select in the whole row.
212 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
213 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
214 if (DWORD(regFullRowSelect))
215 exStyle |= LVS_EX_FULLROWSELECT;
216 exStyle |= (bHasCheckboxes ? LVS_EX_CHECKBOXES : 0);
217 SetRedraw(false);
218 SetExtendedStyle(exStyle);
220 CXPTheme theme;
221 theme.SetWindowTheme(m_hWnd, L"Explorer", NULL);
223 m_nIconFolder = SYS_IMAGE_LIST().GetDirIconIndex();
224 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL);
226 m_ColumnManager.ReadSettings (m_dwDefaultColumns, sColumnInfoContainer);
228 // enable file drops
229 #if 0
230 if (m_pDropTarget == NULL)
232 m_pDropTarget = new CGitStatusListCtrlDropTarget(this);
233 RegisterDragDrop(m_hWnd,m_pDropTarget);
234 // create the supported formats:
235 FORMATETC ftetc={0};
236 ftetc.dwAspect = DVASPECT_CONTENT;
237 ftetc.lindex = -1;
238 ftetc.tymed = TYMED_HGLOBAL;
239 ftetc.cfFormat=CF_HDROP;
240 m_pDropTarget->AddSuportedFormat(ftetc);
242 #endif
244 SetRedraw(true);
246 m_bUnversionedRecurse = !!((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE));
249 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID)
251 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID);
254 BOOL CGitStatusListCtrl::GetStatus ( const CTGitPathList* pathList
255 , bool bUpdate /* = FALSE */
256 , bool bShowIgnores /* = false */
257 , bool bShowUnRev
258 , bool bShowUserProps /* = false */)
260 Locker lock(m_critSec);
261 int mask= CGitStatusListCtrl::FILELIST_MODIFY;
262 if(bShowIgnores)
263 mask|= CGitStatusListCtrl::FILELIST_IGNORE;
264 if(bShowUnRev)
265 mask|= CGitStatusListCtrl::FILELIST_UNVER;
266 this->UpdateFileList(mask,bUpdate,(CTGitPathList*)pathList);
269 #if 0
271 int refetchcounter = 0;
272 BOOL bRet = TRUE;
273 Invalidate();
274 // force the cursor to change
275 POINT pt;
276 GetCursorPos(&pt);
277 SetCursorPos(pt.x, pt.y);
279 m_mapFilenameToChecked.clear();
280 //m_StatusUrlList.Clear();
281 bool bHasChangelists = (m_changelists.size()>1 || (m_changelists.size()>0 && !m_bHasIgnoreGroup));
282 m_changelists.clear();
283 for (size_t i=0; i < m_arStatusArray.size(); i++)
285 FileEntry * entry = m_arStatusArray[i];
286 if ( bHasChangelists && entry->checked)
288 // If change lists are present, remember all checked entries
289 CString path = entry->GetPath().GetGitPathString();
290 m_mapFilenameToChecked[path] = true;
292 if ( (entry->status==git_wc_status_unversioned || entry->status==git_wc_status_missing ) && entry->checked )
294 // The user manually selected an unversioned or missing file. We remember
295 // this so that the selection can be restored when refreshing.
296 CString path = entry->GetPath().GetGitPathString();
297 m_mapFilenameToChecked[path] = true;
299 else if ( entry->status > git_wc_status_normal && !entry->checked )
301 // The user manually deselected a versioned file. We remember
302 // this so that the deselection can be restored when refreshing.
303 CString path = entry->GetPath().GetGitPathString();
304 m_mapFilenameToChecked[path] = false;
308 // use a sorted path list to make sure we fetch the status of
309 // parent items first, *then* the child items (if any)
310 CTGitPathList sortedPathList = pathList;
311 sortedPathList.SortByPathname();
314 bRet = TRUE;
315 m_nTargetCount = 0;
316 m_bHasExternalsFromDifferentRepos = FALSE;
317 m_bHasExternals = FALSE;
318 m_bHasUnversionedItems = FALSE;
319 m_bHasLocks = false;
320 m_bHasChangeLists = false;
321 m_bShowIgnores = bShowIgnores;
322 m_nSortedColumn = 0;
323 m_bBlock = TRUE;
324 m_bBusy = true;
325 m_bEmpty = false;
326 Invalidate();
328 // first clear possible status data left from
329 // previous GetStatus() calls
330 ClearStatusArray();
332 m_StatusFileList = sortedPathList;
334 // Since Git_client_status() returns all files, even those in
335 // folders included with Git:externals we need to check if all
336 // files we get here belongs to the same repository.
337 // It is possible to commit changes in an external folder, as long
338 // as the folder belongs to the same repository (but another path),
339 // but it is not possible to commit all files if the externals are
340 // from a different repository.
342 // To check if all files belong to the same repository, we compare the
343 // UUID's - if they're identical then the files belong to the same
344 // repository and can be committed. But if they're different, then
345 // tell the user to commit all changes in the external folders
346 // first and exit.
347 CStringA sUUID; // holds the repo UUID
348 CTGitPathList arExtPaths; // list of Git:external paths
350 GitConfig config;
352 m_sURL.Empty();
354 m_nTargetCount = sortedPathList.GetCount();
356 GitStatus status(m_pbCanceled);
357 if(m_nTargetCount > 1 && sortedPathList.AreAllPathsFilesInOneDirectory())
359 // This is a special case, where we've been given a list of files
360 // all from one folder
361 // We handle them by setting a status filter, then requesting the Git status of
362 // all the files in the directory, filtering for the ones we're interested in
363 status.SetFilter(sortedPathList);
365 // if all selected entries are files, we don't do a recursive status
366 // fetching. But if only one is a directory, we have to recurse.
367 git_depth_t depth = git_depth_files;
368 // We have set a filter. If all selected items were files or we fetch
369 // the status not recursively, then we have to include
370 // ignored items too - the user has selected them
371 bool bShowIgnoresRight = true;
372 for (int fcindex=0; fcindex<sortedPathList.GetCount(); ++fcindex)
374 if (sortedPathList[fcindex].IsDirectory())
376 depth = git_depth_infinity;
377 bShowIgnoresRight = false;
378 break;
381 if(!FetchStatusForSingleTarget(config, status, sortedPathList.GetCommonDirectory(), bUpdate, sUUID, arExtPaths, true, depth, bShowIgnoresRight))
383 bRet = FALSE;
386 else
388 for(int nTarget = 0; nTarget < m_nTargetCount; nTarget++)
390 // check whether the path we want the status for is already fetched due to status-fetching
391 // of a parent path.
392 // this check is only done for file paths, because folder paths could be included already
393 // but not recursively
394 if (sortedPathList[nTarget].IsDirectory() || GetListEntry(sortedPathList[nTarget]) == NULL)
396 if(!FetchStatusForSingleTarget(config, status, sortedPathList[nTarget], bUpdate, sUUID,
397 arExtPaths, false, git_depth_infinity, bShowIgnores))
399 bRet = FALSE;
405 // remove the 'helper' files of conflicted items from the list.
406 // otherwise they would appear as unversioned files.
407 for (INT_PTR cind = 0; cind < m_ConflictFileList.GetCount(); ++cind)
409 for (size_t i=0; i < m_arStatusArray.size(); i++)
411 if (m_arStatusArray[i]->GetPath().IsEquivalentTo(m_ConflictFileList[cind]))
413 delete m_arStatusArray[i];
414 m_arStatusArray.erase(m_arStatusArray.begin()+i);
415 break;
419 refetchcounter++;
420 } while(!BuildStatistics() && (refetchcounter < 2) && (*m_pbCanceled==false));
422 if (bShowUserProps)
423 FetchUserProperties();
425 m_ColumnManager.UpdateUserPropList (m_arStatusArray);
427 m_bBlock = FALSE;
428 m_bBusy = false;
429 GetCursorPos(&pt);
430 SetCursorPos(pt.x, pt.y);
431 return bRet;
432 #endif
433 BuildStatistics();
434 return TRUE;
438 // Fetch all local properties for all elements in the status array
440 void CGitStatusListCtrl::FetchUserProperties()
442 #if 0
443 GitPool globalPool;
445 for (size_t i = 0, count = m_arStatusArray.size(); i < count; ++i)
447 // local / temp pool to hold parameters and props for a single item
449 GitPool localPool ((apr_pool_t*)globalPool);
451 // open working copy for this path
453 const char* path = m_arStatusArray[i]->path.GetGitApiPath (localPool);
455 Git_wc_adm_access_t *adm_access = NULL;
456 Git_error_t * error = Git_wc_adm_probe_open3 ( &adm_access
457 , NULL
458 , path
459 , FALSE // no write lock
460 , 0 // lock just the directory/file itself
461 , NULL
462 , NULL
463 , localPool);
464 if (error == NULL)
466 // get the props and add them to the status info
468 apr_hash_t* props = NULL;
469 Git_error_t * error = Git_wc_prop_list ( &props
470 , path
471 , adm_access
472 , localPool);
473 if (error == NULL)
475 for ( apr_hash_index_t *index
476 = apr_hash_first (localPool, props)
477 ; index != NULL
478 ; index = apr_hash_next (index))
480 // extract next entry from hash
482 const char* key = NULL;
483 ptrdiff_t keyLen;
484 const char** val = NULL;
486 apr_hash_this ( index
487 , reinterpret_cast<const void**>(&key)
488 , &keyLen
489 , reinterpret_cast<void**>(&val));
491 // decode / dispatch it
493 CString name = CUnicodeUtils::GetUnicode (key);
494 CString value = CUnicodeUtils::GetUnicode (*val);
496 // store in property container (truncate it after ~100 chars)
498 m_arStatusArray[i]->present_props[name]
499 = value.Left (GitSLC_MAXUSERPROPLENGTH);
502 error = Git_wc_adm_close2 (adm_access, localPool);
504 Git_error_clear (error);
506 #endif
511 // Work on a single item from the list of paths which is provided to us
513 bool CGitStatusListCtrl::FetchStatusForSingleTarget(
514 GitConfig& config,
515 GitStatus& status,
516 const CTGitPath& target,
517 bool bFetchStatusFromRepository,
518 CStringA& strCurrentRepositoryUUID,
519 CTGitPathList& arExtPaths,
520 bool bAllDirect,
521 git_depth_t depth,
522 bool bShowIgnores
525 #if 0
526 config.GetDefaultIgnores();
528 CTGitPath workingTarget(target);
530 git_wc_status2_t * s;
531 CTGitPath GitPath;
532 s = status.GetFirstFileStatus(workingTarget, GitPath, bFetchStatusFromRepository, depth, bShowIgnores);
534 m_HeadRev = SVNRev(status.headrev);
535 if (s!=0)
537 Git_wc_status_kind wcFileStatus = GitStatus::GetMoreImportant(s->text_status, s->prop_status);
539 // This one fixes a problem with externals:
540 // If a strLine is a file, Git:externals and its parent directory
541 // will also be returned by GetXXXFileStatus. Hence, we skip all
542 // status info until we find the one matching workingTarget.
543 if (!workingTarget.IsDirectory())
545 if (!workingTarget.IsEquivalentTo(GitPath))
547 while (s != 0)
549 s = status.GetNextFileStatus(GitPath);
550 if(workingTarget.IsEquivalentTo(GitPath))
552 break;
555 if (s == 0)
557 m_sLastError = status.GetLastErrorMsg();
558 return false;
560 // Now, set working target to be the base folder of this item
561 workingTarget = workingTarget.GetDirectory();
564 bool bEntryFromDifferentRepo = false;
565 // Is this a versioned item with an associated repos UUID?
566 if ((s->entry)&&(s->entry->uuid))
568 // Have we seen a repos UUID yet?
569 if (strCurrentRepositoryUUID.IsEmpty())
571 // This is the first repos UUID we've seen - record it
572 strCurrentRepositoryUUID = s->entry->uuid;
573 m_sUUID = strCurrentRepositoryUUID;
575 else
577 if (strCurrentRepositoryUUID.Compare(s->entry->uuid)!=0)
579 // This item comes from a different repository than our main one
580 m_bHasExternalsFromDifferentRepos = TRUE;
581 bEntryFromDifferentRepo = true;
582 if (s->entry->kind == Git_node_dir)
583 arExtPaths.AddPath(workingTarget);
587 else if (strCurrentRepositoryUUID.IsEmpty() && (s->text_status == Git_wc_status_added))
589 // An added entry doesn't have an UUID assigned to it yet.
590 // So we fetch the status of the parent directory instead and
591 // check if that one has an UUID assigned to it.
592 Git_wc_status2_t * sparent;
593 CTGitPath path = workingTarget;
596 CTGitPath GitParentPath;
597 GitStatus tempstatus;
598 sparent = tempstatus.GetFirstFileStatus(path.GetContainingDirectory(), GitParentPath, false, Git_depth_empty, false);
599 path = GitParentPath;
600 } while ( (sparent) && (sparent->entry) && (!sparent->entry->uuid) && (sparent->text_status==Git_wc_status_added) );
601 if (sparent && sparent->entry && sparent->entry->uuid)
603 strCurrentRepositoryUUID = sparent->entry->uuid;
604 m_sUUID = strCurrentRepositoryUUID;
608 if ((wcFileStatus == Git_wc_status_unversioned)&& GitPath.IsDirectory())
610 // check if the unversioned folder is maybe versioned. This
611 // could happen with nested layouts
612 Git_wc_status_kind st = GitStatus::GetAllStatus(workingTarget);
613 if ((st != Git_wc_status_unversioned)&&(st != Git_wc_status_none))
615 return true; // ignore nested layouts
618 if (status.IsExternal(GitPath))
620 m_bHasExternals = TRUE;
623 AddNewFileEntry(s, GitPath, workingTarget, true, m_bHasExternals, bEntryFromDifferentRepo);
625 if (((wcFileStatus == Git_wc_status_unversioned)||(wcFileStatus == Git_wc_status_none)||((wcFileStatus == Git_wc_status_ignored)&&(m_bShowIgnores))) && GitPath.IsDirectory())
627 // we have an unversioned folder -> get all files in it recursively!
628 AddUnversionedFolder(GitPath, workingTarget.GetContainingDirectory(), &config);
631 // for folders, get all statuses inside it too
632 if(workingTarget.IsDirectory())
634 ReadRemainingItemsStatus(status, workingTarget, strCurrentRepositoryUUID, arExtPaths, &config, bAllDirect);
637 } // if (s!=0)
638 else
640 m_sLastError = status.GetLastErrorMsg();
641 return false;
643 #endif
644 return true;
646 #if 0
647 const CGitStatusListCtrl::FileEntry*
648 CGitStatusListCtrl::AddNewFileEntry(
649 const git_wc_status2_t* pGitStatus, // The return from the Git GetStatus functions
650 const CTGitPath& path, // The path of the item we're adding
651 const CTGitPath& basePath, // The base directory for this status build
652 bool bDirectItem, // Was this item the first found by GetFirstFileStatus or by a subsequent GetNextFileStatus call
653 bool bInExternal, // Are we in an 'external' folder
654 bool bEntryfromDifferentRepo // if the entry is from a different repository
657 FileEntry * entry = new FileEntry();
660 entry->path = path;
661 entry->basepath = basePath;
662 entry->status = GitStatus::GetMoreImportant(pGitStatus->text_status, pGitStatus->prop_status);
663 entry->textstatus = pGitStatus->text_status;
664 entry->propstatus = pGitStatus->prop_status;
665 // entry->remotestatus = GitStatus::GetMoreImportant(pGitStatus->repos_text_status, pGitStatus->repos_prop_status);
666 // entry->remotetextstatus = pGitStatus->repos_text_status;
667 // entry->remotepropstatus = pGitStatus->repos_prop_status;
668 entry->inexternal = bInExternal;
669 entry->differentrepo = bEntryfromDifferentRepo;
670 entry->direct = bDirectItem;
671 // entry->copied = !!pGitStatus->copied;
672 // entry->switched = !!pGitStatus->switched;
674 entry->last_commit_date = pGitStatus->ood_last_cmt_date;
675 if ((entry->last_commit_date == NULL)&&(pGitStatus->entry))
676 entry->last_commit_date = pGitStatus->entry->cmt_date;
677 entry->remoterev = pGitStatus->ood_last_cmt_rev;
678 if (pGitStatus->entry)
679 entry->last_commit_rev = pGitStatus->entry->cmt_rev;
680 if (pGitStatus->ood_last_cmt_author)
681 entry->last_commit_author = CUnicodeUtils::GetUnicode(pGitStatus->ood_last_cmt_author);
682 if ((entry->last_commit_author.IsEmpty())&&(pGitStatus->entry)&&(pGitStatus->entry->cmt_author))
683 entry->last_commit_author = CUnicodeUtils::GetUnicode(pGitStatus->entry->cmt_author);
685 if (pGitStatus->entry)
686 entry->isConflicted = (pGitStatus->entry->conflict_wrk && PathFileExists(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_wrk))) ? true : false;
688 if ((entry->status == Git_wc_status_conflicted)||(entry->isConflicted))
690 entry->isConflicted = true;
691 if (pGitStatus->entry)
693 CTGitPath cpath;
694 if (pGitStatus->entry->conflict_wrk)
696 cpath = path.GetDirectory();
697 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_wrk));
698 m_ConflictFileList.AddPath(cpath);
700 if (pGitStatus->entry->conflict_old)
702 cpath = path.GetDirectory();
703 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_old));
704 m_ConflictFileList.AddPath(cpath);
706 if (pGitStatus->entry->conflict_new)
708 cpath = path.GetDirectory();
709 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->conflict_new));
710 m_ConflictFileList.AddPath(cpath);
712 if (pGitStatus->entry->prejfile)
714 cpath = path.GetDirectory();
715 cpath.AppendPathString(CUnicodeUtils::GetUnicode(pGitStatus->entry->prejfile));
716 m_ConflictFileList.AddPath(cpath);
721 if (pGitStatus->entry)
723 entry->isfolder = (pGitStatus->entry->kind == Git_node_dir);
724 entry->Revision = pGitStatus->entry->revision;
725 entry->keeplocal = !!pGitStatus->entry->keep_local;
726 entry->working_size = pGitStatus->entry->working_size;
727 entry->depth = pGitStatus->entry->depth;
729 if (pGitStatus->entry->url)
731 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(pGitStatus->entry->url));
733 if (pGitStatus->entry->copyfrom_url)
735 entry->copyfrom_url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(pGitStatus->entry->copyfrom_url));
736 entry->copyfrom_rev = pGitStatus->entry->copyfrom_rev;
738 else
739 entry->copyfrom_rev = 0;
741 if(bDirectItem)
743 if (m_sURL.IsEmpty())
744 m_sURL = entry->url;
745 else
746 m_sURL.LoadString(IDS_STATUSLIST_MULTIPLETARGETS);
747 m_StatusUrlList.AddPath(CTGitPath(entry->url));
749 if (pGitStatus->entry->lock_owner)
750 entry->lock_owner = CUnicodeUtils::GetUnicode(pGitStatus->entry->lock_owner);
751 if (pGitStatus->entry->lock_token)
753 entry->lock_token = CUnicodeUtils::GetUnicode(pGitStatus->entry->lock_token);
754 m_bHasLocks = true;
756 if (pGitStatus->entry->lock_comment)
757 entry->lock_comment = CUnicodeUtils::GetUnicode(pGitStatus->entry->lock_comment);
759 if (pGitStatus->entry->present_props)
761 entry->present_props = pGitStatus->entry->present_props;
764 if (pGitStatus->entry->changelist)
766 entry->changelist = CUnicodeUtils::GetUnicode(pGitStatus->entry->changelist);
767 m_changelists[entry->changelist] = -1;
768 m_bHasChangeLists = true;
770 entry->needslock = (pGitStatus->entry->present_props && (strstr(pGitStatus->entry->present_props, "Git:needs-lock")!=NULL) );
772 else
774 if (pGitStatus->ood_kind == Git_node_none)
775 entry->isfolder = path.IsDirectory();
776 else
777 entry->isfolder = (pGitStatus->ood_kind == Git_node_dir);
779 if (pGitStatus->repos_lock)
781 if (pGitStatus->repos_lock->owner)
782 entry->lock_remoteowner = CUnicodeUtils::GetUnicode(pGitStatus->repos_lock->owner);
783 if (pGitStatus->repos_lock->token)
784 entry->lock_remotetoken = CUnicodeUtils::GetUnicode(pGitStatus->repos_lock->token);
785 if (pGitStatus->repos_lock->comment)
786 entry->lock_comment = CUnicodeUtils::GetUnicode(pGitStatus->repos_lock->comment);
789 // Pass ownership of the entry to the array
790 m_arStatusArray.push_back(entry);
792 return entry;
794 #endif
796 void CGitStatusListCtrl::AddUnversionedFolder(const CTGitPath& folderName,
797 const CTGitPath& basePath,
798 GitConfig * config)
800 #if 0
801 if (!m_bUnversionedRecurse)
802 return;
803 CSimpleFileFind filefinder(folderName.GetWinPathString());
805 CTGitPath filename;
806 m_bHasUnversionedItems = TRUE;
807 while (filefinder.FindNextFileNoDots())
809 filename.SetFromWin(filefinder.GetFilePath(), filefinder.IsDirectory());
811 bool bMatchIgnore = !!config->MatchIgnorePattern(filename.GetFileOrDirectoryName());
812 bMatchIgnore = bMatchIgnore || config->MatchIgnorePattern(filename.GetGitPathString());
813 if (((bMatchIgnore)&&(m_bShowIgnores))||(!bMatchIgnore))
815 FileEntry * entry = new FileEntry();
816 entry->path = filename;
817 entry->basepath = basePath;
818 entry->inunversionedfolder = true;
819 entry->isfolder = filefinder.IsDirectory();
821 m_arStatusArray.push_back(entry);
822 if (entry->isfolder)
824 if (!g_GitAdminDir.HasAdminDir(entry->path.GetWinPathString(), true))
825 AddUnversionedFolder(entry->path, basePath, config);
829 #endif
833 void CGitStatusListCtrl::ReadRemainingItemsStatus(GitStatus& status, const CTGitPath& basePath,
834 CStringA& strCurrentRepositoryUUID,
835 CTGitPathList& arExtPaths, GitConfig * config, bool bAllDirect)
837 #if 0
838 git_wc_status2_t * s;
840 CTGitPath lastexternalpath;
841 CTGitPath GitPath;
842 while ((s = status.GetNextFileStatus(GitPath)) != NULL)
844 Git_wc_status_kind wcFileStatus = GitStatus::GetMoreImportant(s->text_status, s->prop_status);
845 if ((wcFileStatus == Git_wc_status_unversioned) && (GitPath.IsDirectory()))
847 // check if the unversioned folder is maybe versioned. This
848 // could happen with nested layouts
849 Git_wc_status_kind st = GitStatus::GetAllStatus(GitPath);
850 if ((st != Git_wc_status_unversioned)&&(st != Git_wc_status_none))
852 FileEntry * entry = new FileEntry();
853 entry->path = GitPath;
854 entry->basepath = basePath;
855 entry->inunversionedfolder = true;
856 entry->isfolder = true;
857 entry->isNested = true;
858 m_arStatusArray.push_back(entry);
859 continue;
862 bool bDirectoryIsExternal = false;
863 bool bEntryfromDifferentRepo = false;
864 if (s->entry)
866 if (s->entry->uuid)
868 if (strCurrentRepositoryUUID.IsEmpty())
869 strCurrentRepositoryUUID = s->entry->uuid;
870 else
872 if (strCurrentRepositoryUUID.Compare(s->entry->uuid)!=0)
874 bEntryfromDifferentRepo = true;
875 if (GitStatus::IsImportant(wcFileStatus))
876 m_bHasExternalsFromDifferentRepos = TRUE;
877 if (s->entry->kind == Git_node_dir)
879 if ((lastexternalpath.IsEmpty())||(!lastexternalpath.IsAncestorOf(GitPath)))
881 arExtPaths.AddPath(GitPath);
882 lastexternalpath = GitPath;
888 else
890 // we don't have an UUID - maybe an added file/folder
891 if (!strCurrentRepositoryUUID.IsEmpty())
893 if ((!lastexternalpath.IsEmpty())&&
894 (lastexternalpath.IsAncestorOf(GitPath)))
896 bEntryfromDifferentRepo = true;
897 m_bHasExternalsFromDifferentRepos = TRUE;
902 else
904 // if unversioned items lie around in external
905 // directories from different repos, we have to mark them
906 // as such too.
907 if (!strCurrentRepositoryUUID.IsEmpty())
909 if ((!lastexternalpath.IsEmpty())&&
910 (lastexternalpath.IsAncestorOf(GitPath)))
912 bEntryfromDifferentRepo = true;
916 if (status.IsExternal(GitPath))
918 arExtPaths.AddPath(GitPath);
919 m_bHasExternals = TRUE;
921 if ((!bEntryfromDifferentRepo)&&(status.IsInExternal(GitPath)))
923 // if the externals are inside an unversioned folder (this happens if
924 // the externals are specified with e.g. "ext\folder url" instead of just
925 // "folder url"), then a commit won't succeed.
926 // therefore, we treat those as if the externals come from a different
927 // repository
928 CTGitPath extpath = GitPath;
929 while (basePath.IsAncestorOf(extpath))
931 if (!extpath.HasAdminDir())
933 bEntryfromDifferentRepo = true;
934 break;
936 extpath = extpath.GetContainingDirectory();
939 // Do we have any external paths?
940 if(arExtPaths.GetCount() > 0)
942 // If do have external paths, we need to check if the current item belongs
943 // to one of them
944 for (int ix=0; ix<arExtPaths.GetCount(); ix++)
946 if (arExtPaths[ix].IsAncestorOf(GitPath))
948 bDirectoryIsExternal = true;
949 break;
954 if ((wcFileStatus == Git_wc_status_unversioned)&&(!bDirectoryIsExternal))
955 m_bHasUnversionedItems = TRUE;
957 const FileEntry* entry = AddNewFileEntry(s, GitPath, basePath, bAllDirect, bDirectoryIsExternal, bEntryfromDifferentRepo);
959 bool bMatchIgnore = !!config->MatchIgnorePattern(entry->path.GetFileOrDirectoryName());
960 bMatchIgnore = bMatchIgnore || config->MatchIgnorePattern(entry->path.GetGitPathString());
961 if ((((wcFileStatus == Git_wc_status_unversioned)||(wcFileStatus == Git_wc_status_none))&&(!bMatchIgnore))||
962 ((wcFileStatus == Git_wc_status_ignored)&&(m_bShowIgnores))||
963 (((wcFileStatus == Git_wc_status_unversioned)||(wcFileStatus == Git_wc_status_none))&&(bMatchIgnore)&&(m_bShowIgnores)))
965 if (entry->isfolder)
967 // we have an unversioned folder -> get all files in it recursively!
968 AddUnversionedFolder(GitPath, basePath, config);
971 } // while ((s = status.GetNextFileStatus(GitPath)) != NULL)
972 #endif
975 // Get the show-flags bitmap value which corresponds to a particular Git status
976 DWORD CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status)
978 switch (status)
980 case git_wc_status_none:
981 case git_wc_status_unversioned:
982 return SVNSLC_SHOWUNVERSIONED;
983 case git_wc_status_ignored:
984 if (!m_bShowIgnores)
985 return SVNSLC_SHOWDIRECTS;
986 return SVNSLC_SHOWDIRECTS|SVNSLC_SHOWIGNORED;
987 case git_wc_status_incomplete:
988 return SVNSLC_SHOWINCOMPLETE;
989 case git_wc_status_normal:
990 return SVNSLC_SHOWNORMAL;
991 case git_wc_status_external:
992 return SVNSLC_SHOWEXTERNAL;
993 case git_wc_status_added:
994 return SVNSLC_SHOWADDED;
995 case git_wc_status_missing:
996 return SVNSLC_SHOWMISSING;
997 case git_wc_status_deleted:
998 return SVNSLC_SHOWREMOVED;
999 case git_wc_status_replaced:
1000 return SVNSLC_SHOWREPLACED;
1001 case git_wc_status_modified:
1002 return SVNSLC_SHOWMODIFIED;
1003 case git_wc_status_merged:
1004 return SVNSLC_SHOWMERGED;
1005 case git_wc_status_conflicted:
1006 return SVNSLC_SHOWCONFLICTED;
1007 case git_wc_status_obstructed:
1008 return SVNSLC_SHOWOBSTRUCTED;
1009 default:
1010 // we should NEVER get here!
1011 ASSERT(FALSE);
1012 break;
1014 return 0;
1017 void CGitStatusListCtrl::Show(DWORD dwShow, DWORD dwCheck /*=0*/, bool bShowFolders /* = true */,BOOL UpdateStatusList)
1019 CWinApp * pApp = AfxGetApp();
1020 if (pApp)
1021 pApp->DoWaitCursor(1);
1023 Locker lock(m_critSec);
1024 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1026 //SetItemCount(listIndex);
1027 SetRedraw(FALSE);
1028 DeleteAllItems();
1029 PrepareGroups();
1030 m_nSelected = 0;
1032 if(UpdateStatusList)
1034 m_arStatusArray.clear();
1035 for(int i=0;i<this->m_StatusFileList.GetCount();i++)
1037 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
1040 for(int i=0;i<this->m_UnRevFileList.GetCount();i++)
1042 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
1045 for(int i=0;i<this->m_IgnoreFileList.GetCount();i++)
1047 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
1050 int index =0;
1051 for(int i=0;i<this->m_arStatusArray.size();i++)
1053 //set default checkbox status
1054 if(((CTGitPath*)m_arStatusArray[i])->m_Action & dwCheck)
1055 ((CTGitPath*)m_arStatusArray[i])->m_Checked=true;
1057 if(((CTGitPath*)m_arStatusArray[i])->m_Action & dwShow)
1059 AddEntry((CTGitPath*)m_arStatusArray[i],langID,index);
1060 index++;
1064 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
1065 for (int col = 0; col <= maxcol; col++)
1066 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
1068 SetRedraw(TRUE);
1069 GetStatisticsString();
1071 CHeaderCtrl * pHeader = GetHeaderCtrl();
1072 HDITEM HeaderItem = {0};
1073 HeaderItem.mask = HDI_FORMAT;
1074 for (int i=0; i<pHeader->GetItemCount(); ++i)
1076 pHeader->GetItem(i, &HeaderItem);
1077 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1078 pHeader->SetItem(i, &HeaderItem);
1080 if (m_nSortedColumn)
1082 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1083 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1084 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1087 #if 0
1088 if (nSelectedEntry)
1090 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
1091 EnsureVisible(nSelectedEntry, false);
1093 else
1095 // Restore the item at the top of the list.
1096 for (int i=0;GetTopIndex() != nTopIndex;i++)
1098 if ( !EnsureVisible(nTopIndex+i,false) )
1100 break;
1104 #endif
1105 if (pApp)
1106 pApp->DoWaitCursor(-1);
1108 Invalidate();
1110 m_dwShow = dwShow;
1112 #if 0
1114 CWinApp * pApp = AfxGetApp();
1115 if (pApp)
1116 pApp->DoWaitCursor(1);
1118 m_bShowFolders = bShowFolders;
1120 int nTopIndex = GetTopIndex();
1121 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
1122 int nSelectedEntry = 0;
1123 if (posSelectedEntry)
1124 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
1125 SetRedraw(FALSE);
1126 DeleteAllItems();
1128 PrepareGroups();
1130 m_arListArray.clear();
1132 m_arListArray.reserve(m_arStatusArray.size());
1133 SetItemCount (static_cast<int>(m_arStatusArray.size()));
1135 int listIndex = 0;
1136 for (size_t i=0; i < m_arStatusArray.size(); ++i)
1138 FileEntry * entry = m_arStatusArray[i];
1139 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
1140 continue;
1141 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
1142 continue;
1143 if (entry->IsFolder() && (!bShowFolders))
1144 continue; // don't show folders if they're not wanted.
1146 #if 0
1147 git_wc_status_kind status = GitStatus::GetMoreImportant(entry->status, entry->remotestatus);
1148 DWORD showFlags = GetShowFlagsFromGitStatus(status);
1149 if (entry->IsLocked())
1150 showFlags |= SVNSLC_SHOWLOCKS;
1151 if (entry->switched)
1152 showFlags |= SVNSLC_SHOWSWITCHED;
1153 if (!entry->changelist.IsEmpty())
1154 showFlags |= SVNSLC_SHOWINCHANGELIST;
1155 #endif
1156 bool bAllowCheck = ((entry->changelist.Compare(SVNSLC_IGNORECHANGELIST) != 0)
1157 && (m_bCheckIfGroupsExist || (m_changelists.size()==0 || (m_changelists.size()==1 && m_bHasIgnoreGroup))));
1159 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
1160 #if 0
1161 if (status != Git_wc_status_ignored || (entry->direct) || (dwShow & GitSLC_SHOWIGNORED))
1163 if ((!entry->IsFolder()) && (status == Git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
1165 if (PathFileExists(entry->GetPath().GetWinPath()))
1167 m_arListArray.push_back(i);
1168 if ((dwCheck & SVNSLC_SHOWREMOVEDANDPRESENT)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
1170 if (bAllowCheck)
1171 entry->checked = true;
1173 AddEntry(entry, langID, listIndex++);
1176 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
1178 m_arListArray.push_back(i);
1179 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
1181 if (bAllowCheck)
1182 entry->checked = true;
1184 AddEntry(entry, langID, listIndex++);
1186 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
1188 m_arListArray.push_back(i);
1189 if ((dwCheck & showFlags)||((dwCheck & SVNSLC_SHOWDIRECTS)&&(entry->direct)))
1191 if (bAllowCheck)
1192 entry->checked = true;
1194 AddEntry(entry, langID, listIndex++);
1197 #endif
1200 SetItemCount(listIndex);
1202 m_ColumnManager.UpdateRelevance (m_arStatusArray, m_arListArray);
1204 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
1205 for (int col = 0; col <= maxcol; col++)
1206 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
1208 SetRedraw(TRUE);
1209 GetStatisticsString();
1211 CHeaderCtrl * pHeader = GetHeaderCtrl();
1212 HDITEM HeaderItem = {0};
1213 HeaderItem.mask = HDI_FORMAT;
1214 for (int i=0; i<pHeader->GetItemCount(); ++i)
1216 pHeader->GetItem(i, &HeaderItem);
1217 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1218 pHeader->SetItem(i, &HeaderItem);
1220 if (m_nSortedColumn)
1222 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1223 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1224 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1227 if (nSelectedEntry)
1229 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
1230 EnsureVisible(nSelectedEntry, false);
1232 else
1234 // Restore the item at the top of the list.
1235 for (int i=0;GetTopIndex() != nTopIndex;i++)
1237 if ( !EnsureVisible(nTopIndex+i,false) )
1239 break;
1244 if (pApp)
1245 pApp->DoWaitCursor(-1);
1247 m_bEmpty = (GetItemCount() == 0);
1248 Invalidate();
1249 #endif
1253 void CGitStatusListCtrl::Show(DWORD dwShow, const CTGitPathList& checkedList, bool bShowFolders /* = true */)
1255 return ;
1256 #if 0
1258 Locker lock(m_critSec);
1259 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1261 CWinApp * pApp = AfxGetApp();
1262 if (pApp)
1263 pApp->DoWaitCursor(1);
1264 m_dwShow = dwShow;
1265 m_bShowFolders = bShowFolders;
1266 m_nSelected = 0;
1267 int nTopIndex = GetTopIndex();
1268 POSITION posSelectedEntry = GetFirstSelectedItemPosition();
1269 int nSelectedEntry = 0;
1270 if (posSelectedEntry)
1271 nSelectedEntry = GetNextSelectedItem(posSelectedEntry);
1272 SetRedraw(FALSE);
1273 DeleteAllItems();
1275 PrepareGroups();
1277 m_arListArray.clear();
1279 m_arListArray.reserve(m_arStatusArray.size());
1280 SetItemCount (static_cast<int>(m_arStatusArray.size()));
1282 int listIndex = 0;
1283 for (size_t i=0; i < m_arStatusArray.size(); ++i)
1285 FileEntry * entry = m_arStatusArray[i];
1286 if ((entry->inexternal) && (!(dwShow & SVNSLC_SHOWINEXTERNALS)))
1287 continue;
1288 if ((entry->differentrepo || entry->isNested) && (! (dwShow & SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)))
1289 continue;
1290 if (entry->IsFolder() && (!bShowFolders))
1291 continue; // don't show folders if they're not wanted.
1292 #if 0
1293 git_wc_status_kind status = SVNStatus::GetMoreImportant(entry->status, entry->remotestatus);
1294 DWORD showFlags = GetShowFlagsFromSVNStatus(status);
1295 if (entry->IsLocked())
1296 showFlags |= SVNSLC_SHOWLOCKS;
1297 if (!entry->changelist.IsEmpty())
1298 showFlags |= SVNSLC_SHOWINCHANGELIST;
1300 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
1301 if (status != git_wc_status_ignored || (entry->direct) || (dwShow & SVNSLC_SHOWIGNORED))
1303 for (int npath = 0; npath < checkedList.GetCount(); ++npath)
1305 if (entry->GetPath().IsEquivalentTo(checkedList[npath]))
1307 entry->checked = true;
1308 break;
1311 if ((!entry->IsFolder()) && (status == git_wc_status_deleted) && (dwShow & SVNSLC_SHOWREMOVEDANDPRESENT))
1313 if (PathFileExists(entry->GetPath().GetWinPath()))
1315 m_arListArray.push_back(i);
1316 AddEntry(entry, langID, listIndex++);
1319 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFILES)&&(entry->direct)&&(!entry->IsFolder())))
1321 m_arListArray.push_back(i);
1322 AddEntry(entry, langID, listIndex++);
1324 else if ((dwShow & showFlags)||((dwShow & SVNSLC_SHOWDIRECTFOLDER)&&(entry->direct)&&entry->IsFolder()))
1326 m_arListArray.push_back(i);
1327 AddEntry(entry, langID, listIndex++);
1329 else if (entry->switched)
1331 m_arListArray.push_back(i);
1332 AddEntry(entry, langID, listIndex++);
1335 #endif
1338 SetItemCount(listIndex);
1340 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
1341 for (int col = 0; col <= maxcol; col++)
1342 SetColumnWidth (col, m_ColumnManager.GetWidth (col, true));
1344 SetRedraw(TRUE);
1345 GetStatisticsString();
1347 CHeaderCtrl * pHeader = GetHeaderCtrl();
1348 HDITEM HeaderItem = {0};
1349 HeaderItem.mask = HDI_FORMAT;
1350 for (int i=0; i<pHeader->GetItemCount(); ++i)
1352 pHeader->GetItem(i, &HeaderItem);
1353 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1354 pHeader->SetItem(i, &HeaderItem);
1356 if (m_nSortedColumn)
1358 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1359 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1360 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1363 if (nSelectedEntry)
1365 SetItemState(nSelectedEntry, LVIS_SELECTED, LVIS_SELECTED);
1366 EnsureVisible(nSelectedEntry, false);
1368 else
1370 // Restore the item at the top of the list.
1371 for (int i=0;GetTopIndex() != nTopIndex;i++)
1373 if ( !EnsureVisible(nTopIndex+i,false) )
1375 break;
1380 if (pApp)
1381 pApp->DoWaitCursor(-1);
1383 m_bEmpty = (GetItemCount() == 0);
1384 Invalidate();
1385 #endif
1388 int CGitStatusListCtrl::GetColumnIndex(int mask)
1390 int i=0;
1391 for(i=0;i<32;i++)
1392 if(mask&0x1)
1393 return i;
1394 else
1395 mask=mask>>1;
1396 return -1;
1398 void CGitStatusListCtrl::AddEntry(CTGitPath * GitPath, WORD langID, int listIndex)
1400 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
1401 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
1403 CString path = GitPath->GetGitPathString();
1405 m_bBlock = TRUE;
1406 TCHAR buf[100];
1407 int index = listIndex;
1408 int nCol = 1;
1409 CString entryname = GitPath->GetGitPathString();
1410 int icon_idx = 0;
1411 if (GitPath->IsDirectory())
1412 icon_idx = m_nIconFolder;
1413 else
1415 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath);
1417 // relative path
1418 CString rename;
1419 rename.Format(_T("(from %s)"),GitPath->GetGitOldPathString());
1420 if(GitPath->m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
1421 entryname+=rename;
1423 InsertItem(index, entryname, icon_idx);
1425 this->SetItemData(index, (DWORD_PTR)GitPath);
1426 // SVNSLC_COLFILENAME
1427 SetItemText(index, nCol++, GitPath->GetFileOrDirectoryName());
1428 // SVNSLC_COLEXT
1429 SetItemText(index, nCol++, GitPath->GetFileExtension());
1430 // SVNSLC_COLSTATUS
1431 SetItemText(index, nCol++, GitPath->GetActionName());
1433 SetItemText(index, GetColumnIndex(SVNSLC_COLADD),GitPath->m_StatAdd);
1434 SetItemText(index, GetColumnIndex(SVNSLC_COLDEL),GitPath->m_StatDel);
1437 SetCheck(index, GitPath->m_Checked);
1438 if (GitPath->m_Checked)
1439 m_nSelected++;
1442 if( GitPath->m_Action & CTGitPath::LOGACTIONS_IGNORE)
1443 SetItemGroup(index, 2);
1444 else if( GitPath->m_Action & CTGitPath::LOGACTIONS_UNVER)
1445 SetItemGroup(index,1);
1446 else
1447 SetItemGroup(index,0);
1448 m_bBlock = FALSE;
1452 #if 0
1453 void CGitStatusListCtrl::AddEntry(FileEntry * entry, WORD langID, int listIndex)
1455 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
1456 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
1458 CString path = entry->GetPath().GetGitPathString();
1459 if ( m_mapFilenameToChecked.size()!=0 && m_mapFilenameToChecked.find(path) != m_mapFilenameToChecked.end() )
1461 // The user manually de-/selected an item. We now restore this status
1462 // when refreshing.
1463 entry->checked = m_mapFilenameToChecked[path];
1466 m_bBlock = TRUE;
1467 TCHAR buf[100];
1468 int index = listIndex;
1469 int nCol = 1;
1470 CString entryname = entry->GetDisplayName();
1471 int icon_idx = 0;
1472 if (entry->isfolder)
1473 icon_idx = m_nIconFolder;
1474 else
1476 icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(entry->path);
1478 // relative path
1479 InsertItem(index, entryname, icon_idx);
1480 // SVNSLC_COLFILENAME
1481 SetItemText(index, nCol++, entry->path.GetFileOrDirectoryName());
1482 // SVNSLC_COLEXT
1483 SetItemText(index, nCol++, entry->path.GetFileExtension());
1484 // SVNSLC_COLSTATUS
1485 if (entry->isNested)
1487 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1488 SetItemText(index, nCol++, sTemp);
1490 else
1492 GitStatus::GetStatusString(hResourceHandle, entry->status, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1493 if ((entry->copied)&&(_tcslen(buf)>1))
1494 _tcscat_s(buf, 100, _T(" (+)"));
1495 if ((entry->switched)&&(_tcslen(buf)>1))
1496 _tcscat_s(buf, 100, _T(" (s)"));
1497 #if 0
1498 if ((entry->status == entry->propstatus)&&
1499 (entry->status != git_wc_status_normal)&&
1500 (entry->status != git_wc_status_unversioned)&&
1501 (!GitStatus::IsImportant(entry->textstatus)))
1502 _tcscat_s(buf, 100, ponly);
1503 #endif
1504 SetItemText(index, nCol++, buf);
1506 // SVNSLC_COLREMOTESTATUS
1507 if (entry->isNested)
1509 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1510 SetItemText(index, nCol++, sTemp);
1512 else
1514 #if 0
1515 SVNStatus::GetStatusString(hResourceHandle, entry->remotestatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1516 if ((entry->copied)&&(_tcslen(buf)>1))
1517 _tcscat_s(buf, 100, _T(" (+)"));
1518 if ((entry->switched)&&(_tcslen(buf)>1))
1519 _tcscat_s(buf, 100, _T(" (s)"));
1520 if ((entry->remotestatus == entry->remotepropstatus)&&
1521 (entry->remotestatus != git_wc_status_none)&&
1522 (entry->remotestatus != git_wc_status_normal)&&
1523 (entry->remotestatus != git_wc_status_unversioned)&&
1524 (!SVNStatus::IsImportant(entry->remotetextstatus)))
1525 _tcscat_s(buf, 100, ponly);
1526 #endif
1527 SetItemText(index, nCol++, buf);
1529 // SVNSLC_COLTEXTSTATUS
1530 if (entry->isNested)
1532 CString sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED));
1533 SetItemText(index, nCol++, sTemp);
1535 else
1537 #if 0
1538 SVNStatus::GetStatusString(hResourceHandle, entry->textstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1539 if ((entry->copied)&&(_tcslen(buf)>1))
1540 _tcscat_s(buf, 100, _T(" (+)"));
1541 if ((entry->switched)&&(_tcslen(buf)>1))
1542 _tcscat_s(buf, 100, _T(" (s)"));
1543 #endif
1544 SetItemText(index, nCol++, buf);
1546 // SVNSLC_COLPROPSTATUS
1547 if (entry->isNested)
1549 SetItemText(index, nCol++, _T(""));
1551 else
1553 #if 0
1554 SVNStatus::GetStatusString(hResourceHandle, entry->propstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1555 if ((entry->copied)&&(_tcslen(buf)>1))
1556 _tcscat_s(buf, 100, _T(" (+)"));
1557 if ((entry->switched)&&(_tcslen(buf)>1))
1558 _tcscat_s(buf, 100, _T(" (s)"));
1559 #endif
1560 SetItemText(index, nCol++, buf);
1562 // SVNSLC_COLREMOTETEXT
1563 if (entry->isNested)
1565 SetItemText(index, nCol++, _T(""));
1567 else
1569 #if 0
1570 SVNStatus::GetStatusString(hResourceHandle, entry->remotetextstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1571 SetItemText(index, nCol++, buf);
1572 #endif
1574 // SVNSLC_COLREMOTEPROP
1575 if (entry->isNested)
1577 SetItemText(index, nCol++, _T(""));
1579 else
1581 // SVNStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1582 SetItemText(index, nCol++, buf);
1584 // SVNSLC_COLURL
1585 // SetItemText(index, nCol++, entry->url);
1586 // SVNSLC_COLLOCK
1587 #if 0
1588 if (!m_HeadRev.IsHead())
1590 // we have contacted the repository
1592 // decision-matrix
1593 // wc repository text
1594 // "" "" ""
1595 // "" UID1 owner
1596 // UID1 UID1 owner
1597 // UID1 "" lock has been broken
1598 // UID1 UID2 lock has been stolen
1599 if (entry->lock_token.IsEmpty() || (entry->lock_token.Compare(entry->lock_remotetoken)==0))
1601 if (entry->lock_owner.IsEmpty())
1602 SetItemText(index, nCol++, entry->lock_remoteowner);
1603 else
1604 SetItemText(index, nCol++, entry->lock_owner);
1606 else if (entry->lock_remotetoken.IsEmpty())
1608 // broken lock
1609 CString temp(MAKEINTRESOURCE(IDS_STATUSLIST_LOCKBROKEN));
1610 SetItemText(index, nCol++, temp);
1612 else
1614 // stolen lock
1615 CString temp;
1616 temp.Format(IDS_STATUSLIST_LOCKSTOLEN, (LPCTSTR)entry->lock_remoteowner);
1617 SetItemText(index, nCol++, temp);
1620 else
1621 SetItemText(index, nCol++, entry->lock_owner);
1622 // SVNSLC_COLLOCKCOMMENT
1623 SetItemText(index, nCol++, entry->lock_comment);
1624 // SVNSLC_COLAUTHOR
1625 SetItemText(index, nCol++, entry->last_commit_author);
1626 // SVNSLC_COLREVISION
1627 CString temp;
1628 temp.Format(_T("%ld"), entry->last_commit_rev);
1629 if (entry->last_commit_rev > 0)
1630 SetItemText(index, nCol++, temp);
1631 else
1632 SetItemText(index, nCol++, _T(""));
1633 // SVNSLC_COLREMOTEREVISION
1634 temp.Format(_T("%ld"), entry->remoterev);
1635 if (entry->remoterev > 0)
1636 SetItemText(index, nCol++, temp);
1637 else
1638 SetItemText(index, nCol++, _T(""));
1639 // SVNSLC_COLDATE
1640 TCHAR datebuf[SVN_DATE_BUFFER];
1641 apr_time_t date = entry->last_commit_date;
1642 SVN::formatDate(datebuf, date, true);
1643 if (date)
1644 SetItemText(index, nCol++, datebuf);
1645 else
1646 SetItemText(index, nCol++, _T(""));
1647 // SVNSLC_COLSVNNEEDSLOCK
1648 BOOL bFoundSVNNeedsLock = entry->present_props.IsNeedsLockSet();
1649 CString strSVNNeedsLock = (bFoundSVNNeedsLock) ? _T("*") : _T("");
1650 SetItemText(index, nCol++, strSVNNeedsLock);
1651 // SVNSLC_COLCOPYFROM
1652 if (m_sURL.Compare(entry->copyfrom_url.Left(m_sURL.GetLength()))==0)
1653 temp = entry->copyfrom_url.Mid(m_sURL.GetLength());
1654 else
1655 temp = entry->copyfrom_url;
1656 SetItemText(index, nCol++, temp);
1657 // SVNSLC_COLMODIFICATIONDATE
1658 __int64 filetime = entry->GetPath().GetLastWriteTime();
1659 if ( (filetime) && (entry->status!=git_wc_status_deleted) )
1661 FILETIME* f = (FILETIME*)(__int64*)&filetime;
1662 TCHAR datebuf[SVN_DATE_BUFFER];
1663 SVN::formatDate(datebuf,*f,true);
1664 SetItemText(index, nCol++, datebuf);
1666 else
1668 SetItemText(index, nCol++, _T(""));
1671 // user-defined properties
1672 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
1673 ; i < count
1674 ; ++i)
1676 assert (i == nCol++);
1677 assert (m_ColumnManager.IsUserProp (i));
1679 CString name = m_ColumnManager.GetName(i);
1680 if (entry->present_props.HasProperty (name))
1682 const CString& propVal = entry->present_props [name];
1683 if (propVal.IsEmpty())
1684 SetItemText(index, i, m_sNoPropValueText);
1685 else
1686 SetItemText(index, i, propVal);
1688 else
1689 SetItemText(index, i, _T(""));
1692 SetCheck(index, entry->checked);
1693 if (entry->checked)
1694 m_nSelected++;
1695 if (m_changelists.find(entry->changelist) != m_changelists.end())
1696 SetItemGroup(index, m_changelists[entry->changelist]);
1697 else
1698 SetItemGroup(index, 0);
1699 m_bBlock = FALSE;
1700 #endif
1702 #endif
1703 bool CGitStatusListCtrl::SetItemGroup(int item, int groupindex)
1705 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1706 // return false;
1707 if (groupindex < 0)
1708 return false;
1709 LVITEM i = {0};
1710 i.mask = LVIF_GROUPID;
1711 i.iItem = item;
1712 i.iSubItem = 0;
1713 i.iGroupId = groupindex;
1715 return !!SetItem(&i);
1718 void CGitStatusListCtrl::Sort()
1720 Locker lock(m_critSec);
1722 CSorter predicate (&m_ColumnManager, m_nSortedColumn, m_bAscending);
1724 std::sort(m_arStatusArray.begin(), m_arStatusArray.end(), predicate);
1725 SaveColumnWidths();
1726 Show(m_dwShow, 0, m_bShowFolders);
1730 void CGitStatusListCtrl::OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult)
1732 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1733 *pResult = 0;
1734 if (m_bBlock)
1735 return;
1736 m_bBlock = TRUE;
1737 if (m_nSortedColumn == phdr->iItem)
1738 m_bAscending = !m_bAscending;
1739 else
1740 m_bAscending = TRUE;
1741 m_nSortedColumn = phdr->iItem;
1742 m_mapFilenameToChecked.clear();
1743 Sort();
1745 CHeaderCtrl * pHeader = GetHeaderCtrl();
1746 HDITEM HeaderItem = {0};
1747 HeaderItem.mask = HDI_FORMAT;
1748 for (int i=0; i<pHeader->GetItemCount(); ++i)
1750 pHeader->GetItem(i, &HeaderItem);
1751 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
1752 pHeader->SetItem(i, &HeaderItem);
1754 pHeader->GetItem(m_nSortedColumn, &HeaderItem);
1755 HeaderItem.fmt |= (m_bAscending ? HDF_SORTUP : HDF_SORTDOWN);
1756 pHeader->SetItem(m_nSortedColumn, &HeaderItem);
1758 // the checked state of the list control items must be restored
1760 for (int i=0; i<GetItemCount(); ++i)
1762 CTGitPath * entry = (CTGitPath*)GetItemData(i);
1763 ASSERT(entry);
1764 if(entry)
1765 SetCheck(i, entry->m_Checked);
1768 m_bBlock = FALSE;
1771 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
1773 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1774 *pResult = 0;
1776 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1777 if ((m_bBlock)&&(m_bBlockUI))
1779 // if we're blocked, prevent changing of the check state
1780 if ((!ISCHECKED(pNMLV->uOldState) && ISCHECKED(pNMLV->uNewState))||
1781 (ISCHECKED(pNMLV->uOldState) && !ISCHECKED(pNMLV->uNewState)))
1782 *pResult = TRUE;
1786 BOOL CGitStatusListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
1788 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1789 *pResult = 0;
1790 if ((pNMLV->uNewState==0)||(pNMLV->uNewState & LVIS_SELECTED)||(pNMLV->uNewState & LVIS_FOCUSED))
1791 return FALSE;
1793 if (m_bBlock)
1794 return FALSE;
1796 bool bSelected = !!(ListView_GetItemState(m_hWnd, pNMLV->iItem, LVIS_SELECTED) & LVIS_SELECTED);
1797 int nListItems = GetItemCount();
1799 m_bBlock = TRUE;
1800 // was the item checked?
1802 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1803 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1805 if (GetCheck(pNMLV->iItem))
1807 CheckEntry(pNMLV->iItem, nListItems);
1808 if (bSelected)
1810 POSITION pos = GetFirstSelectedItemPosition();
1811 int index;
1812 while ((index = GetNextSelectedItem(pos)) >= 0)
1814 if (index != pNMLV->iItem)
1815 CheckEntry(index, nListItems);
1819 else
1821 UncheckEntry(pNMLV->iItem, nListItems);
1822 if (bSelected)
1824 POSITION pos = GetFirstSelectedItemPosition();
1825 int index;
1826 while ((index = GetNextSelectedItem(pos)) >= 0)
1828 if (index != pNMLV->iItem)
1829 UncheckEntry(index, nListItems);
1834 GetStatisticsString();
1835 m_bBlock = FALSE;
1836 NotifyCheck();
1838 return FALSE;
1841 void CGitStatusListCtrl::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
1843 LPNMHEADER header = reinterpret_cast<LPNMHEADER>(pNMHDR);
1844 if ( (header != NULL)
1845 && (header->iItem >= 0)
1846 && (header->iItem < m_ColumnManager.GetColumnCount()))
1848 m_ColumnManager.ColumnResized (header->iItem);
1851 *pResult = FALSE;
1854 void CGitStatusListCtrl::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
1856 LPNMHEADER header = reinterpret_cast<LPNMHEADER>(pNMHDR);
1857 *pResult = TRUE;
1858 if ( (header != NULL)
1859 && (header->iItem >= 0)
1860 && (header->iItem < m_ColumnManager.GetColumnCount())
1861 // only allow the reordering if the column was not moved left of the first
1862 // visible item - otherwise the 'invisible' columns are not at the far left
1863 // anymore and we get all kinds of redrawing problems.
1864 && (header->pitem)
1865 && (header->pitem->iOrder > m_ColumnManager.GetInvisibleCount()))
1867 m_ColumnManager.ColumnMoved (header->iItem, header->pitem->iOrder);
1868 *pResult = FALSE;
1871 Invalidate(FALSE);
1874 void CGitStatusListCtrl::CheckEntry(int index, int nListItems)
1876 Locker lock(m_critSec);
1877 //FileEntry * entry = GetListEntry(index);
1878 CTGitPath *path=(CTGitPath*)GetItemData(index);
1879 ASSERT(path != NULL);
1880 if (path == NULL)
1881 return;
1882 SetCheck(index, TRUE);
1883 //entry = GetListEntry(index);
1884 // if an unversioned item was checked, then we need to check if
1885 // the parent folders are unversioned too. If the parent folders actually
1886 // are unversioned, then check those too.
1887 #if 0
1888 if (entry->status == git_wc_status_unversioned)
1890 // we need to check the parent folder too
1891 const CTGitPath& folderpath = entry->path;
1892 for (int i=0; i< nListItems; ++i)
1894 FileEntry * testEntry = GetListEntry(i);
1895 ASSERT(testEntry != NULL);
1896 if (testEntry == NULL)
1897 continue;
1898 if (!testEntry->checked)
1900 if (testEntry->path.IsAncestorOf(folderpath) && (!testEntry->path.IsEquivalentTo(folderpath)))
1902 SetEntryCheck(testEntry,i,true);
1903 m_nSelected++;
1908 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1909 if ( (entry->status == git_wc_status_deleted) || (m_bCheckChildrenWithParent) || (bShift) )
1911 // if a deleted folder gets checked, we have to check all
1912 // children of that folder too.
1913 if (entry->path.IsDirectory())
1915 SetCheckOnAllDescendentsOf(entry, true);
1918 // if a deleted file or folder gets checked, we have to
1919 // check all parents of this item too.
1920 for (int i=0; i<nListItems; ++i)
1922 FileEntry * testEntry = GetListEntry(i);
1923 ASSERT(testEntry != NULL);
1924 if (testEntry == NULL)
1925 continue;
1926 if (!testEntry->checked)
1928 if (testEntry->path.IsAncestorOf(entry->path) && (!testEntry->path.IsEquivalentTo(entry->path)))
1930 if ((testEntry->status == git_wc_status_deleted)||(m_bCheckChildrenWithParent))
1932 SetEntryCheck(testEntry,i,true);
1933 m_nSelected++;
1934 // now we need to check all children of this parent folder
1935 SetCheckOnAllDescendentsOf(testEntry, true);
1941 #endif
1942 if ( !path->m_Checked )
1944 path->m_Checked = TRUE;
1945 m_nSelected++;
1949 void CGitStatusListCtrl::UncheckEntry(int index, int nListItems)
1951 Locker lock(m_critSec);
1952 CTGitPath *path=(CTGitPath*)GetItemData(index);
1953 ASSERT(path != NULL);
1954 if (path == NULL)
1955 return;
1956 SetCheck(index, FALSE);
1957 //entry = GetListEntry(index);
1958 // item was unchecked
1959 #if 0
1960 if (entry->path.IsDirectory())
1962 // disable all files within an unselected folder, except when unchecking a folder with property changes
1963 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1964 if ( (entry->status != git_wc_status_modified) || (bShift) )
1966 SetCheckOnAllDescendentsOf(entry, false);
1969 else if (entry->status == git_wc_status_deleted)
1971 // a "deleted" file was unchecked, so uncheck all parent folders
1972 // and all children of those parents
1973 for (int i=0; i<nListItems; i++)
1975 FileEntry * testEntry = GetListEntry(i);
1976 ASSERT(testEntry != NULL);
1977 if (testEntry == NULL)
1978 continue;
1979 if (testEntry->checked)
1981 if (testEntry->path.IsAncestorOf(entry->path))
1983 if (testEntry->status == git_wc_status_deleted)
1985 SetEntryCheck(testEntry,i,false);
1986 m_nSelected--;
1988 SetCheckOnAllDescendentsOf(testEntry, false);
1994 #endif
1995 if ( path->m_Checked )
1997 path->m_Checked = FALSE;
1998 m_nSelected--;
2001 #if 0
2002 bool CGitStatusListCtrl::EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2)
2004 return pEntry1->path < pEntry2->path;
2007 bool CGitStatusListCtrl::IsEntryVersioned(const FileEntry* pEntry1)
2009 return pEntry1->status != git_wc_status_unversioned;
2011 #endif
2012 bool CGitStatusListCtrl::BuildStatistics()
2015 bool bRefetchStatus = false;
2017 // now gather some statistics
2018 m_nUnversioned = 0;
2019 m_nNormal = 0;
2020 m_nModified = 0;
2021 m_nAdded = 0;
2022 m_nDeleted = 0;
2023 m_nConflicted = 0;
2024 m_nTotal = 0;
2025 m_nSelected = 0;
2027 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
2029 int status=((CTGitPath*)m_arStatusArray[i])->m_Action;
2031 if(status&(CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
2032 m_nAdded++;
2034 if(status&CTGitPath::LOGACTIONS_DELETED)
2035 m_nDeleted++;
2037 if(status&(CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_MODIFIED))
2038 m_nModified++;
2040 if(status&CTGitPath::LOGACTIONS_UNMERGED)
2041 m_nConflicted++;
2043 if(status&(CTGitPath::LOGACTIONS_IGNORE|CTGitPath::LOGACTIONS_UNVER))
2044 m_nUnversioned++;
2048 // } // switch (entry->status)
2049 // } // if (entry)
2050 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
2051 return !bRefetchStatus;
2053 return FALSE;
2056 void CGitStatusListCtrl::GetMinMaxRevisions(git_revnum_t& rMin, git_revnum_t& rMax, bool bShownOnly, bool bCheckedOnly)
2058 #if 0
2059 Locker lock(m_critSec);
2060 rMin = LONG_MAX;
2061 rMax = 0;
2063 if ((bShownOnly)||(bCheckedOnly))
2065 for (int i=0; i<GetItemCount(); ++i)
2067 const FileEntry * entry = GetListEntry(i);
2069 if ((entry)&&(entry->last_commit_rev))
2071 if ((!bCheckedOnly)||(entry->IsChecked()))
2073 if (entry->last_commit_rev >= 0)
2075 rMin = min(rMin, entry->last_commit_rev);
2076 rMax = max(rMax, entry->last_commit_rev);
2082 else
2084 for (int i=0; i < (int)m_arStatusArray.size(); ++i)
2086 const FileEntry * entry = m_arStatusArray[i];
2087 if ((entry)&&(entry->last_commit_rev))
2089 if (entry->last_commit_rev >= 0)
2091 rMin = min(rMin, entry->last_commit_rev);
2092 rMax = max(rMax, entry->last_commit_rev);
2097 if (rMin == LONG_MAX)
2098 rMin = 0;
2099 #endif
2102 int CGitStatusListCtrl::GetGroupFromPoint(POINT * ppt)
2104 // the point must be relative to the upper left corner of the control
2106 if (ppt == NULL)
2107 return -1;
2108 if (!IsGroupViewEnabled())
2109 return -1;
2111 POINT pt = *ppt;
2112 pt.x = 10;
2113 UINT flags = 0;
2114 int nItem = -1;
2115 RECT rc;
2116 GetWindowRect(&rc);
2117 while (((flags & LVHT_BELOW) == 0)&&(pt.y < rc.bottom))
2119 nItem = HitTest(pt, &flags);
2120 if ((flags & LVHT_ONITEM)||(flags & LVHT_EX_GROUP_HEADER))
2122 // the first item below the point
2124 // check if the point is too much right (i.e. if the point
2125 // is farther to the right than the width of the item)
2126 RECT r;
2127 GetItemRect(nItem, &r, LVIR_LABEL);
2128 if (ppt->x > r.right)
2129 return -1;
2131 LVITEM lv = {0};
2132 lv.mask = LVIF_GROUPID;
2133 lv.iItem = nItem;
2134 GetItem(&lv);
2135 int groupID = lv.iGroupId;
2136 // now we search upwards and check if the item above this one
2137 // belongs to another group. If it belongs to the same group,
2138 // we're not over a group header
2139 while (pt.y >= 0)
2141 pt.y -= 2;
2142 nItem = HitTest(pt, &flags);
2143 if ((flags & LVHT_ONITEM)&&(nItem >= 0))
2145 // the first item below the point
2146 LVITEM lv = {0};
2147 lv.mask = LVIF_GROUPID;
2148 lv.iItem = nItem;
2149 GetItem(&lv);
2150 if (lv.iGroupId != groupID)
2151 return groupID;
2152 else
2153 return -1;
2156 if (pt.y < 0)
2157 return groupID;
2158 return -1;
2160 pt.y += 2;
2162 return -1;
2165 void CGitStatusListCtrl::OnContextMenuGroup(CWnd * /*pWnd*/, CPoint point)
2167 POINT clientpoint = point;
2168 ScreenToClient(&clientpoint);
2169 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint) >= 0))
2171 CMenu popup;
2172 if (popup.CreatePopupMenu())
2174 CString temp;
2175 temp.LoadString(IDS_STATUSLIST_CHECKGROUP);
2176 popup.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CHECKGROUP, temp);
2177 temp.LoadString(IDS_STATUSLIST_UNCHECKGROUP);
2178 popup.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_UNCHECKGROUP, temp);
2179 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2180 bool bCheck = false;
2181 switch (cmd)
2183 case IDSVNLC_CHECKGROUP:
2184 bCheck = true;
2185 // fall through here
2186 case IDSVNLC_UNCHECKGROUP:
2188 int group = GetGroupFromPoint(&clientpoint);
2189 // go through all items and check/uncheck those assigned to the group
2190 // but block the OnLvnItemChanged handler
2191 m_bBlock = true;
2192 LVITEM lv;
2193 for (int i=0; i<GetItemCount(); ++i)
2195 SecureZeroMemory(&lv, sizeof(LVITEM));
2196 lv.mask = LVIF_GROUPID;
2197 lv.iItem = i;
2198 GetItem(&lv);
2200 if (lv.iGroupId == group)
2202 CTGitPath * entry = (CTGitPath*)GetItemData(i);
2203 if (entry)
2205 bool bOldCheck = entry->m_Checked;
2206 SetEntryCheck(entry, i, bCheck);
2207 if (bCheck != bOldCheck)
2209 if (bCheck)
2210 m_nSelected++;
2211 else
2212 m_nSelected--;
2218 GetStatisticsString();
2219 NotifyCheck();
2220 m_bBlock = false;
2222 break;
2228 void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point)
2231 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
2233 bool XPorLater = false;
2234 OSVERSIONINFOEX inf;
2235 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
2236 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
2237 GetVersionEx((OSVERSIONINFO *)&inf);
2238 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
2239 if (fullver >= 0x0501)
2240 XPorLater = true;
2241 bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
2242 CTGitPath * filepath;
2244 int selIndex = GetSelectionMark();
2245 if ((point.x == -1) && (point.y == -1))
2247 CRect rect;
2248 GetItemRect(selIndex, &rect, LVIR_LABEL);
2249 ClientToScreen(&rect);
2250 point = rect.CenterPoint();
2252 if ((GetSelectedCount() == 0)&&(XPorLater)&&(m_bHasCheckboxes))
2254 // nothing selected could mean the context menu is requested for
2255 // a group header
2256 OnContextMenuGroup(pWnd, point);
2258 else if (selIndex >= 0)
2260 //FileEntry * entry = GetListEntry(selIndex);
2262 filepath = (CTGitPath * )GetItemData(selIndex);
2264 ASSERT(filepath != NULL);
2265 if (filepath == NULL)
2266 return;
2268 //const CTGitPath& filepath = entry->path;
2269 int wcStatus = filepath->m_Action;
2270 // entry is selected, now show the popup menu
2271 Locker lock(m_critSec);
2272 CIconMenu popup;
2273 CMenu changelistSubMenu;
2274 CMenu ignoreSubMenu;
2275 if (popup.CreatePopupMenu())
2277 //Add Menu for verion controled file
2279 if (wcStatus & CTGitPath::LOGACTIONS_UNMERGED)
2281 if ((m_dwContextMenus & SVNSLC_POPCONFLICT)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
2283 popup.AppendMenuIcon(IDSVNLC_EDITCONFLICT, IDS_MENUCONFLICT, IDI_CONFLICT);
2285 if (m_dwContextMenus & SVNSLC_POPRESOLVE)
2287 popup.AppendMenuIcon(IDSVNLC_RESOLVECONFLICT, IDS_STATUSLIST_CONTEXT_RESOLVED, IDI_RESOLVE);
2289 if ((m_dwContextMenus & SVNSLC_POPRESOLVE)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
2291 //popup.AppendMenuIcon(IDSVNLC_RESOLVETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS, IDI_RESOLVE);
2292 //popup.AppendMenuIcon(IDSVNLC_RESOLVEMINE, IDS_SVNPROGRESS_MENUUSEMINE, IDI_RESOLVE);
2294 if ((m_dwContextMenus & SVNSLC_POPCONFLICT)||(m_dwContextMenus & SVNSLC_POPRESOLVE))
2295 popup.AppendMenu(MF_SEPARATOR);
2298 if (!(wcStatus &CTGitPath::LOGACTIONS_UNVER))
2300 if (m_dwContextMenus & SVNSLC_POPCOMPAREWITHBASE)
2302 popup.AppendMenuIcon(IDSVNLC_COMPARE, IDS_LOG_COMPAREWITHBASE, IDI_DIFF);
2303 popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
2306 if (m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_COMPAREWC))
2308 if( (!m_CurrentVersion.IsEmpty()) && m_CurrentVersion != GIT_REV_ZERO)
2309 popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
2311 //Select one items
2312 if (GetSelectedCount() == 1)
2314 bool bEntryAdded = false;
2315 //if (entry->remotestatus <= git_wc_status_normal)
2317 // if (wcStatus > git_wc_status_normal)
2318 // {
2319 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
2320 // {
2321 if(!g_Git.IsInitRepos())
2322 popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2324 bEntryAdded = true;
2325 // }
2326 // }
2329 //else if (wcStatus != git_wc_status_deleted)
2331 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
2332 // {
2333 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
2334 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
2335 // bEntryAdded = true;
2336 // }
2337 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
2338 // {
2339 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2340 // bEntryAdded = true;
2341 // }
2343 if (bEntryAdded)
2344 popup.AppendMenu(MF_SEPARATOR);
2346 //else if (GetSelectedCount() > 1)
2348 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
2349 // {
2350 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
2351 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
2352 // }
2357 ///Select Multi item
2358 //if (GetSelectedCount() > 0)
2360 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
2361 // {
2362 // POSITION pos = GetFirstSelectedItemPosition();
2363 // int index = GetNextSelectedItem(pos);
2364 // if (index >= 0)
2365 // {
2366 // FileEntry * entry = GetListEntry(index);
2367 // git_wc_status_kind status1 = git_wc_status_none;
2368 // git_wc_status_kind status2 = git_wc_status_none;
2369 // if (entry)
2370 // status1 = entry->status;
2371 // index = GetNextSelectedItem(pos);
2372 // if (index >= 0)
2373 // {
2374 // entry = GetListEntry(index);
2375 // if (entry)
2376 // status2 = entry->status;
2377 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
2378 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
2379 // {
2380 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
2381 // }
2382 // }
2383 // }
2384 // }
2385 // if (wcStatus > git_wc_status_normal)
2386 // {
2387 // if (m_dwContextMenus & SVNSLC_POPREVERT)
2388 // {
2389 // // reverting missing folders is not possible
2390 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
2391 // {
2392 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
2393 // }
2394 // }
2395 // }
2396 // if (entry->remotestatus > git_wc_status_normal)
2397 // {
2398 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
2399 // {
2400 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
2401 // }
2402 // }
2405 if ( (GetSelectedCount() >0 ) && (!(wcStatus & CTGitPath::LOGACTIONS_UNVER)))
2407 if (m_dwContextMenus & SVNSLC_POPREVERT)
2409 popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
2412 if ((m_dwContextMenus & GetContextMenuBit(IDSVNLC_REVERTTOREV)) && ( !this->m_CurrentVersion.IsEmpty() )
2413 && this->m_CurrentVersion != GIT_REV_ZERO)
2415 popup.AppendMenuIcon(IDSVNLC_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2419 if ((GetSelectedCount() == 1)&&(!(wcStatus & CTGitPath::LOGACTIONS_UNVER))
2420 &&(!(wcStatus & CTGitPath::LOGACTIONS_IGNORE)))
2422 if (m_dwContextMenus & SVNSLC_POPSHOWLOG)
2424 popup.AppendMenuIcon(IDSVNLC_LOG, IDS_REPOBROWSE_SHOWLOG, IDI_LOG);
2426 if (m_dwContextMenus & SVNSLC_POPBLAME)
2428 popup.AppendMenuIcon(IDSVNLC_BLAME, IDS_MENUBLAME, IDI_BLAME);
2431 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
2432 if ( (GetSelectedCount() == 1) )
2434 if (m_dwContextMenus & this->GetContextMenuBit(IDSVNLC_SAVEAS) )
2436 popup.AppendMenuIcon(IDSVNLC_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2439 if (m_dwContextMenus & SVNSLC_POPOPEN)
2441 popup.AppendMenuIcon(IDSVNLC_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2442 popup.AppendMenuIcon(IDSVNLC_OPEN, IDS_REPOBROWSE_OPEN, IDI_OPEN);
2443 popup.AppendMenuIcon(IDSVNLC_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2446 if (m_dwContextMenus & SVNSLC_POPEXPLORE)
2448 popup.AppendMenuIcon(IDSVNLC_EXPLORE, IDS_STATUSLIST_CONTEXT_EXPLORE, IDI_EXPLORER);
2452 if (GetSelectedCount() > 0)
2454 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
2455 // {
2456 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2457 // }
2458 // if ((wcStatus != Git_wc_status_unversioned)&&(wcStatus != git_wc_status_ignored)&&(wcStatus != Git_wc_status_deleted)&&(wcStatus != Git_wc_status_added)&&(m_dwContextMenus & GitSLC_POPDELETE))
2459 // {
2460 // if (bShift)
2461 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
2462 // else
2463 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
2464 // }
2465 if ((wcStatus & CTGitPath::LOGACTIONS_UNVER)/*||(wcStatus == git_wc_status_deleted)*/)
2467 if (m_dwContextMenus & SVNSLC_POPADD)
2469 //if ( entry->IsFolder() )
2471 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
2473 //else
2475 popup.AppendMenuIcon(IDSVNLC_ADD, IDS_STATUSLIST_CONTEXT_ADD, IDI_ADD);
2479 //if ( (wcStatus == git_wc_status_unversioned) || (wcStatus == git_wc_status_deleted) )
2481 if (m_dwContextMenus & SVNSLC_POPIGNORE)
2484 CTGitPathList ignorelist;
2485 FillListOfSelectedItemPaths(ignorelist);
2486 //check if all selected entries have the same extension
2487 bool bSameExt = true;
2488 CString sExt;
2489 for (int i=0; i<ignorelist.GetCount(); ++i)
2491 if (sExt.IsEmpty() && (i==0))
2492 sExt = ignorelist[i].GetFileExtension();
2493 else if (sExt.CompareNoCase(ignorelist[i].GetFileExtension())!=0)
2494 bSameExt = false;
2496 if (bSameExt)
2498 if (ignoreSubMenu.CreateMenu())
2500 CString ignorepath;
2501 if (ignorelist.GetCount()==1)
2502 ignorepath = ignorelist[0].GetFileOrDirectoryName();
2503 else
2504 ignorepath.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2505 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_IGNORE, ignorepath);
2506 ignorepath = _T("*")+sExt;
2507 ignoreSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_IGNOREMASK, ignorepath);
2508 CString temp;
2509 temp.LoadString(IDS_MENUIGNORE);
2510 popup.InsertMenu((UINT)-1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)ignoreSubMenu.m_hMenu, temp);
2513 else
2515 CString temp;
2516 if (ignorelist.GetCount()==1)
2518 temp.LoadString(IDS_MENUIGNORE);
2520 else
2522 temp.Format(IDS_MENUIGNOREMULTIPLE, ignorelist.GetCount());
2524 popup.AppendMenuIcon(IDSVNLC_IGNORE, temp, IDI_IGNORE);
2532 if (GetSelectedCount() > 0)
2534 #if 0
2535 if ((!entry->IsFolder())&&(wcStatus >= git_wc_status_normal)
2536 &&(wcStatus!=git_wc_status_missing)&&(wcStatus!=git_wc_status_deleted)
2537 &&(wcStatus!=git_wc_status_added))
2539 popup.AppendMenu(MF_SEPARATOR);
2540 if ((entry->lock_token.IsEmpty())&&(!entry->IsFolder()))
2542 if (m_dwContextMenus & SVNSLC_POPLOCK)
2544 popup.AppendMenuIcon(IDSVNLC_LOCK, IDS_MENU_LOCK, IDI_LOCK);
2547 if ((!entry->lock_token.IsEmpty())&&(!entry->IsFolder()))
2549 if (m_dwContextMenus & SVNSLC_POPUNLOCK)
2551 popup.AppendMenuIcon(IDSVNLC_UNLOCK, IDS_MENU_UNLOCK, IDI_UNLOCK);
2556 if ((!entry->IsFolder())&&((!entry->lock_token.IsEmpty())||(!entry->lock_remotetoken.IsEmpty())))
2558 if (m_dwContextMenus & SVNSLC_POPUNLOCKFORCE)
2560 popup.AppendMenuIcon(IDSVNLC_UNLOCKFORCE, IDS_MENU_UNLOCKFORCE, IDI_UNLOCK);
2564 if (wcStatus != git_wc_status_missing && wcStatus != git_wc_status_deleted &&wcStatus!=git_wc_status_unversioned)
2566 popup.AppendMenu(MF_SEPARATOR);
2567 popup.AppendMenuIcon(IDSVNLC_PROPERTIES, IDS_STATUSLIST_CONTEXT_PROPERTIES, IDI_PROPERTIES);
2569 #endif
2570 popup.AppendMenu(MF_SEPARATOR);
2571 popup.AppendMenuIcon(IDSVNLC_COPY, IDS_STATUSLIST_CONTEXT_COPY, IDI_COPYCLIP);
2572 popup.AppendMenuIcon(IDSVNLC_COPYEXT, IDS_STATUSLIST_CONTEXT_COPYEXT, IDI_COPYCLIP);
2573 #if 0
2574 if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS)&&(XPorLater)
2575 &&(wcStatus != git_wc_status_unversioned)&&(wcStatus != git_wc_status_none))
2577 popup.AppendMenu(MF_SEPARATOR);
2578 // changelist commands
2579 size_t numChangelists = GetNumberOfChangelistsInSelection();
2580 if (numChangelists > 0)
2582 popup.AppendMenuIcon(IDSVNLC_REMOVEFROMCS, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS);
2584 if ((!entry->IsFolder())&&(changelistSubMenu.CreateMenu()))
2586 CString temp;
2587 temp.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS);
2588 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATECS, temp);
2590 if (entry->changelist.Compare(SVNSLC_IGNORECHANGELIST))
2592 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2593 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, IDSVNLC_CREATEIGNORECS, SVNSLC_IGNORECHANGELIST);
2596 if (m_changelists.size() > 0)
2598 // find the changelist names
2599 bool bNeedSeparator = true;
2600 int cmdID = IDSVNLC_MOVETOCS;
2601 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
2603 if ((entry->changelist.Compare(it->first))&&(it->first.Compare(SVNSLC_IGNORECHANGELIST)))
2605 if (bNeedSeparator)
2607 changelistSubMenu.AppendMenu(MF_SEPARATOR);
2608 bNeedSeparator = false;
2610 changelistSubMenu.AppendMenu(MF_STRING | MF_ENABLED, cmdID, it->first);
2611 cmdID++;
2615 temp.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS);
2616 popup.AppendMenu(MF_POPUP|MF_STRING, (UINT_PTR)changelistSubMenu.GetSafeHmenu(), temp);
2619 #endif
2622 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2624 m_bBlock = TRUE;
2625 AfxGetApp()->DoWaitCursor(1);
2626 int iItemCountBeforeMenuCmd = GetItemCount();
2627 bool bForce = false;
2628 switch (cmd)
2630 case IDSVNLC_VIEWREV:
2631 OpenFile(filepath,NOTEPAD2);
2632 break;
2633 case IDSVNLC_OPEN:
2634 OpenFile(filepath,OPEN);
2635 break;
2636 case IDSVNLC_OPENWITH:
2637 OpenFile(filepath,OPEN_WITH);
2638 break;
2639 case IDSVNLC_EXPLORE:
2641 ShellExecute(this->m_hWnd, _T("explore"), filepath->GetDirectory().GetWinPath(), NULL, NULL, SW_SHOW);
2643 break;
2645 // Compare current version and work copy.
2646 case IDSVNLC_COMPAREWC:
2648 POSITION pos = GetFirstSelectedItemPosition();
2649 while ( pos )
2651 int index = GetNextSelectedItem(pos);
2652 StartDiffWC(index);
2655 break;
2656 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2657 case IDSVNLC_COMPARE:
2659 POSITION pos = GetFirstSelectedItemPosition();
2660 while ( pos )
2662 int index = GetNextSelectedItem(pos);
2663 StartDiff(index);
2666 break;
2667 case IDSVNLC_GNUDIFF1:
2669 // SVNDiff diff(NULL, this->m_hWnd, true);
2671 // if (entry->remotestatus <= git_wc_status_normal)
2672 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2673 // else
2674 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2675 if(m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
2676 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,GitRev::GetWorkingCopy(),
2677 *filepath,GitRev::GetHead());
2678 else
2679 CAppUtils::StartShowUnifiedDiff(m_hWnd,*filepath,m_CurrentVersion,
2680 *filepath,m_CurrentVersion+_T("~1"));
2682 break;
2683 case IDSVNLC_ADD:
2684 { // The add went ok, but we now need to run through the selected items again
2685 // and update their status
2686 std::vector<int> selectIndex;
2688 POSITION pos = GetFirstSelectedItemPosition();
2689 int index;
2690 while ((index = GetNextSelectedItem(pos)) >= 0)
2692 selectIndex.push_back(index);
2694 for(int i=0;i<selectIndex.size();i++)
2696 index=selectIndex[i];
2698 CTGitPath * path=(CTGitPath*)GetItemData(index);
2699 ASSERT(path);
2700 if(path == NULL)
2701 continue;
2702 CString cmd;
2703 cmd.Format(_T("git.exe add \"%s\""),path->GetGitPathString());
2704 CString output;
2705 if(!g_Git.Run(cmd,&output,CP_ACP))
2707 path->m_Action = CTGitPath::LOGACTIONS_ADDED;
2708 SetEntryCheck(path,index,true);
2709 SetItemGroup(index,0);
2710 this->m_StatusFileList.AddPath(*path);
2711 this->m_UnRevFileList.RemoveItem(*path);
2712 this->m_IgnoreFileList.RemoveItem(*path);
2713 Show(this->m_dwShow,0,true,true);
2718 break;
2720 case IDSVNLC_BLAME:
2722 CString sCmd;
2723 sCmd.Format(_T("\"%s\" /command:blame /path:\"%s\""),
2724 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath());
2726 CAppUtils::LaunchApplication(sCmd, NULL, false);
2728 break;
2730 case IDSVNLC_LOG:
2732 CString sCmd;
2733 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\""),
2734 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git.m_CurrentDir+_T("\\")+filepath->GetWinPath());
2736 CAppUtils::LaunchApplication(sCmd, NULL, false);
2738 break;
2740 case IDSVNLC_EDITCONFLICT:
2742 CAppUtils::ConflictEdit(*filepath);
2743 break;
2745 case IDSVNLC_RESOLVECONFLICT:
2747 if (CMessageBox::Show(m_hWnd, IDS_PROC_RESOLVE, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO)==IDYES)
2749 POSITION pos = GetFirstSelectedItemPosition();
2750 while (pos != 0)
2752 int index;
2753 index = GetNextSelectedItem(pos);
2754 CTGitPath * fentry =(CTGitPath*) this->GetItemData(index);
2755 if(fentry == NULL)
2756 continue;
2758 if ( fentry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
2760 CString cmd,output;
2761 cmd.Format(_T("git.exe add \"%s\""),fentry->GetGitPathString());
2762 if(g_Git.Run(cmd,&output,CP_ACP))
2764 CMessageBox::Show(m_hWnd, output, _T("TortoiseSVN"), MB_ICONERROR);
2765 }else
2767 fentry->m_Action |= CTGitPath::LOGACTIONS_MODIFIED;
2768 fentry->m_Action &=~CTGitPath::LOGACTIONS_UNMERGED;
2773 Show(m_dwShow, 0, m_bShowFolders);
2776 break;
2778 case IDSVNLC_IGNORE:
2780 CTGitPathList ignorelist;
2781 //std::vector<CString> toremove;
2782 FillListOfSelectedItemPaths(ignorelist, true);
2783 SetRedraw(FALSE);
2785 if(!CAppUtils::IgnoreFile(ignorelist,false))
2786 break;
2788 for(int i=0;i<ignorelist.GetCount();i++)
2790 int nListboxEntries = GetItemCount();
2791 for (int nItem=0; nItem<nListboxEntries; ++nItem)
2793 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
2794 if (path->GetGitPathString()==ignorelist[i].GetGitPathString())
2796 RemoveListEntry(nItem);
2797 break;
2801 SetRedraw(TRUE);
2803 #if 0
2804 CTSVNPathList ignorelist;
2805 std::vector<CString> toremove;
2806 FillListOfSelectedItemPaths(ignorelist, true);
2807 SetRedraw(FALSE);
2808 for (int j=0; j<ignorelist.GetCount(); ++j)
2810 int nListboxEntries = GetItemCount();
2811 for (int i=0; i<nListboxEntries; ++i)
2813 if (GetListEntry(i)->GetPath().IsEquivalentTo(ignorelist[j]))
2815 selIndex = i;
2816 break;
2819 CString name = CPathUtils::PathPatternEscape(ignorelist[j].GetFileOrDirectoryName());
2820 CTSVNPath parentfolder = ignorelist[j].GetContainingDirectory();
2821 SVNProperties props(parentfolder, SVNRev::REV_WC, false);
2822 CStringA value;
2823 for (int i=0; i<props.GetCount(); i++)
2825 CString propname(props.GetItemName(i).c_str());
2826 if (propname.CompareNoCase(_T("git:ignore"))==0)
2828 stdstring stemp;
2829 // treat values as normal text even if they're not
2830 value = (char *)props.GetItemValue(i).c_str();
2833 if (value.IsEmpty())
2834 value = name;
2835 else
2837 value = value.Trim("\n\r");
2838 value += "\n";
2839 value += name;
2840 value.Remove('\r');
2842 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
2844 CString temp;
2845 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
2846 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseSVN"), MB_ICONERROR);
2847 break;
2849 if (GetCheck(selIndex))
2850 m_nSelected--;
2851 m_nTotal--;
2853 // now, if we ignored a folder, remove all its children
2854 if (ignorelist[j].IsDirectory())
2856 for (int i=0; i<(int)m_arListArray.size(); ++i)
2858 FileEntry * entry = GetListEntry(i);
2859 if (entry->status == git_wc_status_unversioned)
2861 if (!ignorelist[j].IsEquivalentTo(entry->GetPath())&&(ignorelist[j].IsAncestorOf(entry->GetPath())))
2863 entry->status = git_wc_status_ignored;
2864 entry->textstatus = git_wc_status_ignored;
2865 if (GetCheck(i))
2866 m_nSelected--;
2867 toremove.push_back(entry->GetPath().GetSVNPathString());
2873 CTSVNPath basepath = m_arStatusArray[m_arListArray[selIndex]]->basepath;
2875 FileEntry * entry = m_arStatusArray[m_arListArray[selIndex]];
2876 if ( entry->status == git_wc_status_unversioned ) // keep "deleted" items
2877 toremove.push_back(entry->GetPath().GetSVNPathString());
2879 if (!m_bIgnoreRemoveOnly)
2881 SVNStatus status;
2882 git_wc_status2_t * s;
2883 CTSVNPath gitPath;
2884 s = status.GetFirstFileStatus(parentfolder, gitPath, false, git_depth_empty);
2885 // first check if the folder isn't already present in the list
2886 bool bFound = false;
2887 nListboxEntries = GetItemCount();
2888 for (int i=0; i<nListboxEntries; ++i)
2890 FileEntry * entry = GetListEntry(i);
2891 if (entry->path.IsEquivalentTo(gitPath))
2893 bFound = true;
2894 break;
2897 if (!bFound)
2899 if (s!=0)
2901 FileEntry * entry = new FileEntry();
2902 entry->path = gitPath;
2903 entry->basepath = basepath;
2904 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
2905 entry->textstatus = s->text_status;
2906 entry->propstatus = s->prop_status;
2907 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
2908 entry->remotetextstatus = s->repos_text_status;
2909 entry->remotepropstatus = s->repos_prop_status;
2910 entry->inunversionedfolder = FALSE;
2911 entry->checked = true;
2912 entry->inexternal = false;
2913 entry->direct = false;
2914 entry->isfolder = true;
2915 entry->last_commit_date = 0;
2916 entry->last_commit_rev = 0;
2917 entry->remoterev = 0;
2918 if (s->entry)
2920 if (s->entry->url)
2922 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
2925 if (s->entry && s->entry->present_props)
2927 entry->present_props = s->entry->present_props;
2929 m_arStatusArray.push_back(entry);
2930 m_arListArray.push_back(m_arStatusArray.size()-1);
2931 AddEntry(entry, langID, GetItemCount());
2936 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
2938 int nListboxEntries = GetItemCount();
2939 for (int i=0; i<nListboxEntries; ++i)
2941 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
2943 RemoveListEntry(i);
2944 break;
2948 SetRedraw(TRUE);
2950 #endif
2951 break;
2952 case IDSVNLC_IGNOREMASK:
2954 CString common;
2955 CString ext=filepath->GetFileExtension();
2956 CTGitPathList ignorelist;
2957 FillListOfSelectedItemPaths(ignorelist, true);
2958 SetRedraw(FALSE);
2960 CAppUtils::IgnoreFile(ignorelist,true);
2961 common=ignorelist.GetCommonRoot().GetGitPathString();
2963 for (int i=0; i< GetItemCount(); ++i)
2965 CTGitPath *path=(CTGitPath*)GetItemData(i);
2966 if(!( path->m_Action & CTGitPath::LOGACTIONS_UNVER))
2967 continue;
2968 if( path->GetGitPathString().Left(common.GetLength()) == common )
2970 if (path->GetFileExtension()==ext)
2972 RemoveListEntry(i);
2973 i--; // remove index i at item, new one will replace.
2978 SetRedraw(TRUE);
2980 #if 0
2981 std::set<CTSVNPath> parentlist;
2982 for (int i=0; i<ignorelist.GetCount(); ++i)
2984 parentlist.insert(ignorelist[i].GetContainingDirectory());
2986 std::set<CTSVNPath>::iterator it;
2987 std::vector<CString> toremove;
2989 for (it = parentlist.begin(); it != parentlist.end(); ++it)
2991 CTSVNPath parentFolder = (*it).GetDirectory();
2992 SVNProperties props(parentFolder, SVNRev::REV_WC, false);
2993 CStringA value;
2994 for (int i=0; i<props.GetCount(); i++)
2996 CString propname(props.GetItemName(i).c_str());
2997 if (propname.CompareNoCase(_T("git:ignore"))==0)
2999 stdstring stemp;
3000 // treat values as normal text even if they're not
3001 value = (char *)props.GetItemValue(i).c_str();
3004 if (value.IsEmpty())
3005 value = name;
3006 else
3008 value = value.Trim("\n\r");
3009 value += "\n";
3010 value += name;
3011 value.Remove('\r');
3013 if (!props.Add(_T("git:ignore"), (LPCSTR)value))
3015 CString temp;
3016 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
3017 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseSVN"), MB_ICONERROR);
3019 else
3021 CTSVNPath basepath;
3022 int nListboxEntries = GetItemCount();
3023 for (int i=0; i<nListboxEntries; ++i)
3025 FileEntry * entry = GetListEntry(i);
3026 ASSERT(entry != NULL);
3027 if (entry == NULL)
3028 continue;
3029 if (basepath.IsEmpty())
3030 basepath = entry->basepath;
3031 // since we ignored files with a mask (e.g. *.exe)
3032 // we have to find find all files in the same
3033 // folder (IsAncestorOf() returns TRUE for _all_ children,
3034 // not just the immediate ones) which match the
3035 // mask and remove them from the list too.
3036 if ((entry->status == git_wc_status_unversioned)&&(parentFolder.IsAncestorOf(entry->path)))
3038 CString f = entry->path.GetSVNPathString();
3039 if (f.Mid(parentFolder.GetSVNPathString().GetLength()).Find('/')<=0)
3041 if (CStringUtils::WildCardMatch(name, f))
3043 if (GetCheck(i))
3044 m_nSelected--;
3045 m_nTotal--;
3046 toremove.push_back(f);
3051 if (!m_bIgnoreRemoveOnly)
3053 SVNStatus status;
3054 git_wc_status2_t * s;
3055 CTSVNPath gitPath;
3056 s = status.GetFirstFileStatus(parentFolder, gitPath, false, git_depth_empty);
3057 if (s!=0)
3059 // first check if the folder isn't already present in the list
3060 bool bFound = false;
3061 for (int i=0; i<nListboxEntries; ++i)
3063 FileEntry * entry = GetListEntry(i);
3064 if (entry->path.IsEquivalentTo(gitPath))
3066 bFound = true;
3067 break;
3070 if (!bFound)
3072 FileEntry * entry = new FileEntry();
3073 entry->path = gitPath;
3074 entry->basepath = basepath;
3075 entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);
3076 entry->textstatus = s->text_status;
3077 entry->propstatus = s->prop_status;
3078 entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);
3079 entry->remotetextstatus = s->repos_text_status;
3080 entry->remotepropstatus = s->repos_prop_status;
3081 entry->inunversionedfolder = false;
3082 entry->checked = true;
3083 entry->inexternal = false;
3084 entry->direct = false;
3085 entry->isfolder = true;
3086 entry->last_commit_date = 0;
3087 entry->last_commit_rev = 0;
3088 entry->remoterev = 0;
3089 if (s->entry)
3091 if (s->entry->url)
3093 entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));
3096 if (s->entry && s->entry->present_props)
3098 entry->present_props = s->entry->present_props;
3100 m_arStatusArray.push_back(entry);
3101 m_arListArray.push_back(m_arStatusArray.size()-1);
3102 AddEntry(entry, langID, GetItemCount());
3108 for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)
3110 int nListboxEntries = GetItemCount();
3111 for (int i=0; i<nListboxEntries; ++i)
3113 if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)
3115 RemoveListEntry(i);
3116 break;
3120 SetRedraw(TRUE);
3122 #endif
3123 break;
3125 case IDSVNLC_REVERT:
3127 // If at least one item is not in the status "added"
3128 // we ask for a confirmation
3129 BOOL bConfirm = FALSE;
3130 POSITION pos = GetFirstSelectedItemPosition();
3131 int index;
3132 while ((index = GetNextSelectedItem(pos)) >= 0)
3134 //FileEntry * fentry = GetListEntry(index);
3135 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
3136 if(fentry && fentry->m_Action &CTGitPath::LOGACTIONS_MODIFIED )
3138 bConfirm = TRUE;
3139 break;
3143 CString str;
3144 str.Format(IDS_PROC_WARNREVERT,GetSelectedCount());
3146 if (!bConfirm || CMessageBox::Show(this->m_hWnd, str, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION)==IDYES)
3148 CTGitPathList targetList;
3149 FillListOfSelectedItemPaths(targetList);
3151 // make sure that the list is reverse sorted, so that
3152 // children are removed before any parents
3153 targetList.SortByPathname(true);
3155 // put all reverted files in the trashbin, except the ones with 'added'
3156 // status because they are not restored by the revert.
3157 CTGitPathList delList;
3158 POSITION pos = GetFirstSelectedItemPosition();
3159 int index;
3160 while ((index = GetNextSelectedItem(pos)) >= 0)
3162 CTGitPath *entry=(CTGitPath *)GetItemData(index);
3163 if (entry&&(!(entry->m_Action& CTGitPath::LOGACTIONS_ADDED)))
3164 delList.AddPath(*entry);
3166 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
3167 delList.DeleteAllFiles(true);
3169 if (g_Git.Revert(targetList))
3171 CMessageBox::Show(this->m_hWnd, _T("Revert Fail"), _T("TortoiseSVN"), MB_ICONERROR);
3173 else
3175 for(int i=0;i<targetList.GetCount();i++)
3177 int nListboxEntries = GetItemCount();
3178 for (int nItem=0; nItem<nListboxEntries; ++nItem)
3180 CTGitPath *path=(CTGitPath*)GetItemData(nItem);
3181 if (path->GetGitPathString()==targetList[i].GetGitPathString())
3183 if(path->m_Action & CTGitPath::LOGACTIONS_ADDED)
3185 path->m_Action = CTGitPath::LOGACTIONS_UNVER;
3186 SetEntryCheck(path,nItem,false);
3187 SetItemGroup(nItem,1);
3188 this->m_StatusFileList.RemoveItem(*path);
3189 this->m_UnRevFileList.AddPath(*path);
3190 //this->m_IgnoreFileList.RemoveItem(*path);
3192 }else
3194 RemoveListEntry(nItem);
3196 break;
3200 SetRedraw(TRUE);
3201 SaveColumnWidths();
3202 Show(m_dwShow, 0, m_bShowFolders);
3203 NotifyCheck();
3207 break;
3209 case IDSVNLC_COPY:
3210 CopySelectedEntriesToClipboard(0);
3211 break;
3212 case IDSVNLC_COPYEXT:
3213 CopySelectedEntriesToClipboard((DWORD)-1);
3214 break;
3216 case IDSVNLC_SAVEAS:
3217 FileSaveAs(filepath);
3218 break;
3220 case IDSVNLC_REVERTTOREV:
3221 RevertSelectedItemToVersion();
3222 break;
3223 #if 0
3224 case IDSVNLC_PROPERTIES:
3226 CTSVNPathList targetList;
3227 FillListOfSelectedItemPaths(targetList);
3228 CEditPropertiesDlg dlg;
3229 dlg.SetPathList(targetList);
3230 dlg.DoModal();
3231 if (dlg.HasChanged())
3233 // since the user might have changed/removed/added
3234 // properties recursively, we don't really know
3235 // which items have changed their status.
3236 // So tell the parent to do a refresh.
3237 CWnd* pParent = GetParent();
3238 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3240 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3244 break;
3245 case IDSVNLC_COMMIT:
3247 CTSVNPathList targetList;
3248 FillListOfSelectedItemPaths(targetList);
3249 CTSVNPath tempFile = CTempFiles::Instance().GetTempFilePath(false);
3250 VERIFY(targetList.WriteToFile(tempFile.GetWinPathString()));
3251 CString commandline = CPathUtils::GetAppDirectory();
3252 commandline += _T("TortoiseProc.exe /command:commit /pathfile:\"");
3253 commandline += tempFile.GetWinPathString();
3254 commandline += _T("\"");
3255 commandline += _T(" /deletepathfile");
3256 CAppUtils::LaunchApplication(commandline, NULL, false);
3258 break;
3260 case IDSVNLC_COMPAREWC:
3262 POSITION pos = GetFirstSelectedItemPosition();
3263 while ( pos )
3265 int index = GetNextSelectedItem(pos);
3266 FileEntry * entry = GetListEntry(index);
3267 ASSERT(entry != NULL);
3268 if (entry == NULL)
3269 continue;
3270 SVNDiff diff(NULL, m_hWnd, true);
3271 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
3272 git_revnum_t baseRev = entry->Revision;
3273 diff.DiffFileAgainstBase(
3274 entry->path, baseRev, entry->textstatus, entry->propstatus);
3277 break;
3278 case IDSVNLC_GNUDIFF1:
3280 SVNDiff diff(NULL, this->m_hWnd, true);
3282 if (entry->remotestatus <= git_wc_status_normal)
3283 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
3284 else
3285 CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
3287 break;
3288 case IDSVNLC_UPDATE:
3290 CTSVNPathList targetList;
3291 FillListOfSelectedItemPaths(targetList);
3292 bool bAllExist = true;
3293 for (int i=0; i<targetList.GetCount(); ++i)
3295 if (!targetList[i].Exists())
3297 bAllExist = false;
3298 break;
3301 if (bAllExist)
3303 CSVNProgressDlg dlg;
3304 dlg.SetCommand(CSVNProgressDlg::SVNProgress_Update);
3305 dlg.SetPathList(targetList);
3306 dlg.SetRevision(SVNRev::REV_HEAD);
3307 dlg.DoModal();
3309 else
3311 CString sTempFile = CTempFiles::Instance().GetTempFilePath(false).GetWinPathString();
3312 targetList.WriteToFile(sTempFile, false);
3313 CString sCmd;
3314 sCmd.Format(_T("\"%s\" /command:update /rev /pathfile:\"%s\" /deletepathfile"),
3315 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)sTempFile);
3317 CAppUtils::LaunchApplication(sCmd, NULL, false);
3320 break;
3322 case IDSVNLC_REMOVE:
3324 SVN git;
3325 CTSVNPathList itemsToRemove;
3326 FillListOfSelectedItemPaths(itemsToRemove);
3328 // We must sort items before removing, so that files are always removed
3329 // *before* their parents
3330 itemsToRemove.SortByPathname(true);
3332 bool bSuccess = false;
3333 if (git.Remove(itemsToRemove, FALSE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3335 bSuccess = true;
3337 else
3339 if ((git.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE) ||
3340 (git.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))
3342 CString msg, yes, no, yestoall;
3343 msg.Format(IDS_PROC_REMOVEFORCE, (LPCTSTR)git.GetLastErrorMessage());
3344 yes.LoadString(IDS_MSGBOX_YES);
3345 no.LoadString(IDS_MSGBOX_NO);
3346 yestoall.LoadString(IDS_PROC_YESTOALL);
3347 UINT ret = CMessageBox::Show(m_hWnd, msg, _T("TortoiseSVN"), 2, IDI_ERROR, yes, no, yestoall);
3348 if ((ret == 1)||(ret==3))
3350 if (!git.Remove(itemsToRemove, TRUE, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)))
3352 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3354 else
3355 bSuccess = true;
3358 else
3359 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3361 if (bSuccess)
3363 // The remove went ok, but we now need to run through the selected items again
3364 // and update their status
3365 POSITION pos = GetFirstSelectedItemPosition();
3366 int index;
3367 std::vector<int> entriesToRemove;
3368 while ((index = GetNextSelectedItem(pos)) >= 0)
3370 FileEntry * e = GetListEntry(index);
3371 if (!bShift &&
3372 ((e->textstatus == git_wc_status_unversioned)||
3373 (e->textstatus == git_wc_status_none)||
3374 (e->textstatus == git_wc_status_ignored)))
3376 if (GetCheck(index))
3377 m_nSelected--;
3378 m_nTotal--;
3379 entriesToRemove.push_back(index);
3381 else
3383 e->textstatus = git_wc_status_deleted;
3384 e->status = git_wc_status_deleted;
3385 SetEntryCheck(e,index,true);
3388 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3390 RemoveListEntry(*it);
3393 SaveColumnWidths();
3394 Show(m_dwShow, 0, m_bShowFolders);
3395 NotifyCheck();
3397 break;
3398 case IDSVNLC_DELETE:
3400 CTSVNPathList pathlist;
3401 FillListOfSelectedItemPaths(pathlist);
3402 pathlist.RemoveChildren();
3403 CString filelist;
3404 for (INT_PTR i=0; i<pathlist.GetCount(); ++i)
3406 filelist += pathlist[i].GetWinPathString();
3407 filelist += _T("|");
3409 filelist += _T("|");
3410 int len = filelist.GetLength();
3411 TCHAR * buf = new TCHAR[len+2];
3412 _tcscpy_s(buf, len+2, filelist);
3413 for (int i=0; i<len; ++i)
3414 if (buf[i] == '|')
3415 buf[i] = 0;
3416 SHFILEOPSTRUCT fileop;
3417 fileop.hwnd = this->m_hWnd;
3418 fileop.wFunc = FO_DELETE;
3419 fileop.pFrom = buf;
3420 fileop.pTo = NULL;
3421 fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | ((GetAsyncKeyState(VK_SHIFT) & 0x8000) ? 0 : FOF_ALLOWUNDO);
3422 fileop.lpszProgressTitle = _T("deleting file");
3423 int result = SHFileOperation(&fileop);
3424 delete [] buf;
3426 if ( (result==0) && (!fileop.fAnyOperationsAborted) )
3428 SetRedraw(FALSE);
3429 POSITION pos = NULL;
3430 CTSVNPathList deletedlist; // to store list of deleted folders
3431 while ((pos = GetFirstSelectedItemPosition()) != 0)
3433 int index = GetNextSelectedItem(pos);
3434 if (GetCheck(index))
3435 m_nSelected--;
3436 m_nTotal--;
3437 FileEntry * fentry = GetListEntry(index);
3438 if ((fentry)&&(fentry->isfolder))
3439 deletedlist.AddPath(fentry->path);
3440 RemoveListEntry(index);
3442 // now go through the list of deleted folders
3443 // and remove all their children from the list too!
3444 int nListboxEntries = GetItemCount();
3445 for (int folderindex = 0; folderindex < deletedlist.GetCount(); ++folderindex)
3447 CTSVNPath folderpath = deletedlist[folderindex];
3448 for (int i=0; i<nListboxEntries; ++i)
3450 FileEntry * entry = GetListEntry(i);
3451 if (folderpath.IsAncestorOf(entry->path))
3453 RemoveListEntry(i--);
3454 nListboxEntries--;
3458 SetRedraw(TRUE);
3461 break;
3464 case IDSVNLC_ADD:
3466 SVN git;
3467 CTSVNPathList itemsToAdd;
3468 FillListOfSelectedItemPaths(itemsToAdd);
3470 // We must sort items before adding, so that folders are always added
3471 // *before* any of their children
3472 itemsToAdd.SortByPathname();
3474 ProjectProperties props;
3475 props.ReadPropsPathList(itemsToAdd);
3476 if (git.Add(itemsToAdd, &props, git_depth_empty, TRUE, TRUE, TRUE))
3478 // The add went ok, but we now need to run through the selected items again
3479 // and update their status
3480 POSITION pos = GetFirstSelectedItemPosition();
3481 int index;
3482 while ((index = GetNextSelectedItem(pos)) >= 0)
3484 FileEntry * e = GetListEntry(index);
3485 e->textstatus = git_wc_status_added;
3486 e->propstatus = git_wc_status_none;
3487 e->status = git_wc_status_added;
3488 SetEntryCheck(e,index,true);
3491 else
3493 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3495 SaveColumnWidths();
3496 Show(m_dwShow, 0, m_bShowFolders);
3497 NotifyCheck();
3499 break;
3500 case IDSVNLC_ADD_RECURSIVE:
3502 CTSVNPathList itemsToAdd;
3503 FillListOfSelectedItemPaths(itemsToAdd);
3505 CAddDlg dlg;
3506 dlg.m_pathList = itemsToAdd;
3507 if (dlg.DoModal() == IDOK)
3509 if (dlg.m_pathList.GetCount() == 0)
3510 break;
3511 CSVNProgressDlg progDlg;
3512 progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Add);
3513 progDlg.SetPathList(dlg.m_pathList);
3514 ProjectProperties props;
3515 props.ReadPropsPathList(dlg.m_pathList);
3516 progDlg.SetProjectProperties(props);
3517 progDlg.SetItemCount(dlg.m_pathList.GetCount());
3518 progDlg.DoModal();
3520 // refresh!
3521 CWnd* pParent = GetParent();
3522 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3524 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3528 break;
3530 case IDSVNLC_REPAIRMOVE:
3532 POSITION pos = GetFirstSelectedItemPosition();
3533 int index = GetNextSelectedItem(pos);
3534 FileEntry * entry1 = NULL;
3535 FileEntry * entry2 = NULL;
3536 if (index >= 0)
3538 entry1 = GetListEntry(index);
3539 git_wc_status_kind status1 = git_wc_status_none;
3540 git_wc_status_kind status2 = git_wc_status_none;
3541 if (entry1)
3543 status1 = entry1->status;
3544 index = GetNextSelectedItem(pos);
3545 if (index >= 0)
3547 entry2 = GetListEntry(index);
3548 if (entry2)
3550 status2 = entry2->status;
3551 if (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned)
3553 FileEntry * tempentry = entry1;
3554 entry1 = entry2;
3555 entry2 = tempentry;
3557 // entry1 was renamed to entry2 but outside of Subversion
3558 // fix this by moving entry2 back to entry1 first,
3559 // then do an git-move from entry1 to entry2
3560 if (MoveFile(entry2->GetPath().GetWinPath(), entry1->GetPath().GetWinPath()))
3562 SVN git;
3563 if (!git.Move(CTSVNPathList(entry1->GetPath()), entry2->GetPath(), TRUE))
3565 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3567 else
3569 // check the previously unversioned item
3570 entry1->checked = true;
3571 // fixing the move was successful. We have to adjust the new status of the
3572 // files.
3573 // Since we don't know if the moved/renamed file had local modifications or not,
3574 // we can't guess the new status. That means we have to refresh...
3575 CWnd* pParent = GetParent();
3576 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3578 pParent->SendMessage(SVNSLNM_NEEDSREFRESH);
3582 else
3584 LPVOID lpMsgBuf;
3585 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
3586 FORMAT_MESSAGE_FROM_SYSTEM |
3587 FORMAT_MESSAGE_IGNORE_INSERTS,
3588 NULL,
3589 GetLastError(),
3590 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
3591 (LPTSTR) &lpMsgBuf,
3593 NULL
3595 MessageBox((LPCTSTR)lpMsgBuf, _T("Error"), MB_OK | MB_ICONINFORMATION );
3596 LocalFree( lpMsgBuf );
3603 break;
3604 case IDSVNLC_REMOVEFROMCS:
3606 CTSVNPathList changelistItems;
3607 FillListOfSelectedItemPaths(changelistItems);
3608 SVN git;
3609 SetRedraw(FALSE);
3610 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
3612 // The changelists were removed, but we now need to run through the selected items again
3613 // and update their changelist
3614 POSITION pos = GetFirstSelectedItemPosition();
3615 int index;
3616 std::vector<int> entriesToRemove;
3617 while ((index = GetNextSelectedItem(pos)) >= 0)
3619 FileEntry * e = GetListEntry(index);
3620 if (e)
3622 e->changelist.Empty();
3623 if (e->status == git_wc_status_normal)
3625 // remove the entry completely
3626 entriesToRemove.push_back(index);
3628 else
3629 SetItemGroup(index, 0);
3632 for (std::vector<int>::reverse_iterator it = entriesToRemove.rbegin(); it != entriesToRemove.rend(); ++it)
3634 RemoveListEntry(*it);
3636 // TODO: Should we go through all entries here and check if we also could
3637 // remove the changelist from m_changelists ?
3639 else
3641 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3643 SetRedraw(TRUE);
3645 break;
3646 case IDSVNLC_CREATEIGNORECS:
3647 CreateChangeList(SVNSLC_IGNORECHANGELIST);
3648 break;
3649 case IDSVNLC_CREATECS:
3651 CCreateChangelistDlg dlg;
3652 if (dlg.DoModal() == IDOK)
3654 CreateChangeList(dlg.m_sName);
3657 break;
3658 default:
3660 if (cmd < IDSVNLC_MOVETOCS)
3661 break;
3662 CTSVNPathList changelistItems;
3663 FillListOfSelectedItemPaths(changelistItems);
3665 // find the changelist name
3666 CString sChangelist;
3667 int cmdID = IDSVNLC_MOVETOCS;
3668 SetRedraw(FALSE);
3669 for (std::map<CString, int>::const_iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
3671 if ((it->first.Compare(SVNSLC_IGNORECHANGELIST))&&(entry->changelist.Compare(it->first)))
3673 if (cmd == cmdID)
3675 sChangelist = it->first;
3677 cmdID++;
3680 if (!sChangelist.IsEmpty())
3682 SVN git;
3683 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
3685 // The changelists were moved, but we now need to run through the selected items again
3686 // and update their changelist
3687 POSITION pos = GetFirstSelectedItemPosition();
3688 int index;
3689 while ((index = GetNextSelectedItem(pos)) >= 0)
3691 FileEntry * e = GetListEntry(index);
3692 e->changelist = sChangelist;
3693 if (!e->IsFolder())
3695 if (m_changelists.find(e->changelist)!=m_changelists.end())
3696 SetItemGroup(index, m_changelists[e->changelist]);
3697 else
3698 SetItemGroup(index, 0);
3702 else
3704 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
3707 SetRedraw(TRUE);
3709 break;
3710 #endif
3712 } // switch (cmd)
3713 m_bBlock = FALSE;
3714 AfxGetApp()->DoWaitCursor(-1);
3715 GetStatisticsString();
3716 int iItemCountAfterMenuCmd = GetItemCount();
3717 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
3719 // CWnd* pParent = GetParent();
3720 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3721 // {
3722 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
3723 // }
3725 } // if (popup.CreatePopupMenu())
3726 } // if (selIndex >= 0)
3730 void CGitStatusListCtrl::OnContextMenuHeader(CWnd * pWnd, CPoint point)
3732 bool XPorLater = false;
3733 OSVERSIONINFOEX inf;
3734 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
3735 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
3736 GetVersionEx((OSVERSIONINFO *)&inf);
3737 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
3738 if (fullver >= 0x0501)
3739 XPorLater = true;
3741 CHeaderCtrl * pHeaderCtrl = (CHeaderCtrl *)pWnd;
3742 if ((point.x == -1) && (point.y == -1))
3744 CRect rect;
3745 pHeaderCtrl->GetItemRect(0, &rect);
3746 ClientToScreen(&rect);
3747 point = rect.CenterPoint();
3749 Locker lock(m_critSec);
3750 CMenu popup;
3751 if (popup.CreatePopupMenu())
3753 int columnCount = m_ColumnManager.GetColumnCount();
3755 CString temp;
3756 UINT uCheckedFlags = MF_STRING | MF_ENABLED | MF_CHECKED;
3757 UINT uUnCheckedFlags = MF_STRING | MF_ENABLED;
3759 // build control menu
3761 if (XPorLater)
3763 temp.LoadString(IDS_STATUSLIST_SHOWGROUPS);
3764 popup.AppendMenu(IsGroupViewEnabled() ? uCheckedFlags : uUnCheckedFlags, columnCount, temp);
3767 if (m_ColumnManager.AnyUnusedProperties())
3769 temp.LoadString(IDS_STATUSLIST_REMOVEUNUSEDPROPS);
3770 popup.AppendMenu(uUnCheckedFlags, columnCount+1, temp);
3773 temp.LoadString(IDS_STATUSLIST_RESETCOLUMNORDER);
3774 popup.AppendMenu(uUnCheckedFlags, columnCount+2, temp);
3775 popup.AppendMenu(MF_SEPARATOR);
3777 // standard columns
3779 for (int i = 1; i < SVNSLC_NUMCOLUMNS; ++i)
3781 popup.AppendMenu ( m_ColumnManager.IsVisible(i)
3782 ? uCheckedFlags
3783 : uUnCheckedFlags
3785 , m_ColumnManager.GetName(i));
3788 // user-prop columns:
3789 // find relevant ones and sort 'em
3791 std::map<CString, int> sortedProps;
3792 for (int i = SVNSLC_NUMCOLUMNS; i < columnCount; ++i)
3793 if (m_ColumnManager.IsRelevant(i))
3794 sortedProps[m_ColumnManager.GetName(i)] = i;
3796 if (!sortedProps.empty())
3798 // add 'em to the menu
3800 popup.AppendMenu(MF_SEPARATOR);
3802 typedef std::map<CString, int>::const_iterator CIT;
3803 for ( CIT iter = sortedProps.begin(), end = sortedProps.end()
3804 ; iter != end
3805 ; ++iter)
3807 popup.AppendMenu ( m_ColumnManager.IsVisible(iter->second)
3808 ? uCheckedFlags
3809 : uUnCheckedFlags
3810 , iter->second
3811 , iter->first);
3815 // show menu & let user pick an entry
3817 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
3818 if ((cmd >= 1)&&(cmd < columnCount))
3820 m_ColumnManager.SetVisible (cmd, !m_ColumnManager.IsVisible(cmd));
3822 else if (cmd == columnCount)
3824 EnableGroupView(!IsGroupViewEnabled());
3826 else if (cmd == columnCount+1)
3828 m_ColumnManager.RemoveUnusedProps();
3830 else if (cmd == columnCount+2)
3832 m_ColumnManager.ResetColumns (m_dwDefaultColumns);
3837 void CGitStatusListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
3840 if (pWnd == this)
3842 OnContextMenuList(pWnd, point);
3843 } // if (pWnd == this)
3844 else if (pWnd == GetHeaderCtrl())
3846 OnContextMenuHeader(pWnd, point);
3850 void CGitStatusListCtrl::CreateChangeList(const CString& name)
3852 #if 0
3853 CTGitPathList changelistItems;
3854 FillListOfSelectedItemPaths(changelistItems);
3855 Git git;
3856 if (git.AddToChangeList(changelistItems, name, git_depth_empty))
3858 TCHAR groupname[1024];
3859 LVGROUP grp = {0};
3860 grp.cbSize = sizeof(LVGROUP);
3861 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
3862 _tcsncpy_s(groupname, 1024, name, 1023);
3863 grp.pszHeader = groupname;
3864 grp.iGroupId = (int)m_changelists.size();
3865 grp.uAlign = LVGA_HEADER_LEFT;
3866 m_changelists[name] = InsertGroup(-1, &grp);
3868 PrepareGroups(true);
3870 POSITION pos = GetFirstSelectedItemPosition();
3871 int index;
3872 while ((index = GetNextSelectedItem(pos)) >= 0)
3874 FileEntry * e = GetListEntry(index);
3875 e->changelist = name;
3876 SetEntryCheck(e, index, FALSE);
3879 for (index = 0; index < GetItemCount(); ++index)
3881 FileEntry * e = GetListEntry(index);
3882 if (m_changelists.find(e->changelist)!=m_changelists.end())
3883 SetItemGroup(index, m_changelists[e->changelist]);
3884 else
3885 SetItemGroup(index, 0);
3888 else
3890 CMessageBox::Show(m_hWnd, git.GetLastErrorMessage(), _T("Tortoisegit"), MB_ICONERROR);
3892 #endif
3895 void CGitStatusListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
3898 Locker lock(m_critSec);
3899 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
3900 *pResult = 0;
3901 if (m_bBlock)
3902 return;
3904 if (pNMLV->iItem < 0)
3906 if (!IsGroupViewEnabled())
3907 return;
3908 POINT pt;
3909 DWORD ptW = GetMessagePos();
3910 pt.x = GET_X_LPARAM(ptW);
3911 pt.y = GET_Y_LPARAM(ptW);
3912 ScreenToClient(&pt);
3913 int group = GetGroupFromPoint(&pt);
3914 if (group < 0)
3915 return;
3916 // check/uncheck the whole group depending on the check-state
3917 // of the first item in the group
3918 m_bBlock = true;
3919 bool bCheck = false;
3920 bool bFirst = false;
3921 LVITEM lv;
3922 for (int i=0; i<GetItemCount(); ++i)
3924 SecureZeroMemory(&lv, sizeof(LVITEM));
3925 lv.mask = LVIF_GROUPID;
3926 lv.iItem = i;
3927 GetItem(&lv);
3928 if (lv.iGroupId == group)
3930 CTGitPath *entry=(CTGitPath*)GetItemData(i);
3932 if (!bFirst)
3934 bCheck = !GetCheck(i);
3935 bFirst = true;
3937 if (entry)
3939 bool bOldCheck = !!GetCheck(i);
3940 SetEntryCheck(entry, i, bCheck);
3941 if (bCheck != bOldCheck)
3943 if (bCheck)
3944 m_nSelected++;
3945 else
3946 m_nSelected--;
3951 GetStatisticsString();
3952 m_bBlock = false;
3953 NotifyCheck();
3954 return;
3957 CTGitPath *file=(CTGitPath*)GetItemData(pNMLV->iItem);
3959 if( file->m_Action&CTGitPath::LOGACTIONS_UNMERGED )
3961 CAppUtils::ConflictEdit(*file,false);
3963 }else
3965 StartDiff(pNMLV->iItem);
3969 void CGitStatusListCtrl::StartDiffWC(int fileindex)
3971 if(fileindex<0)
3972 return;
3974 CString Ver;
3975 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
3976 return;
3978 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3980 CGitDiff::Diff(&file1,&file1,
3981 CString(GIT_REV_ZERO),
3982 m_CurrentVersion);
3986 void CGitStatusListCtrl::StartDiff(int fileindex)
3988 if(fileindex<0)
3989 return;
3991 CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);
3992 CTGitPath file2;
3993 if(file1.m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY))
3995 file2.SetFromGit(file1.GetGitOldPathString());
3996 }else
3998 file2=file1;
4001 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)
4003 if( g_Git.IsInitRepos())
4004 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
4005 CString(GIT_REV_ZERO));
4006 else if( file1.m_Action&CTGitPath::LOGACTIONS_DELETED )
4007 CGitDiff::DiffNull((CTGitPath*)GetItemData(fileindex),
4008 GitRev::GetHead(),false);
4009 else
4010 CGitDiff::Diff(&file1,&file2,
4011 CString(GIT_REV_ZERO),
4012 GitRev::GetHead());
4013 }else
4015 CGitDiff::Diff(&file1,&file2,
4016 m_CurrentVersion,
4017 m_CurrentVersion+_T("~1"));
4019 #if 0
4020 if (fileindex < 0)
4021 return;
4022 FileEntry * entry = GetListEntry(fileindex);
4023 ASSERT(entry != NULL);
4024 if (entry == NULL)
4025 return;
4026 if (((entry->status == git_wc_status_normal)&&(entry->remotestatus <= git_wc_status_normal))||
4027 (entry->status == git_wc_status_unversioned)||(entry->status == git_wc_status_none))
4029 int ret = (int)ShellExecute(this->m_hWnd, NULL, entry->path.GetWinPath(), NULL, NULL, SW_SHOW);
4030 if (ret <= HINSTANCE_ERROR)
4032 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
4033 cmd += entry->path.GetWinPathString();
4034 CAppUtils::LaunchApplication(cmd, NULL, false);
4036 return;
4039 GitDiff diff(NULL, m_hWnd, true);
4040 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
4041 diff.DiffWCFile(
4042 entry->path, entry->textstatus, entry->propstatus,
4043 entry->remotetextstatus, entry->remotepropstatus);
4044 #endif
4047 CString CGitStatusListCtrl::GetStatisticsString()
4050 CString sNormal, sAdded, sDeleted, sModified, sConflicted, sUnversioned;
4051 WORD langID = (WORD)(DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4052 TCHAR buf[MAX_STATUS_STRING_LENGTH];
4053 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal, buf, sizeof(buf)/sizeof(TCHAR), langID);
4054 sNormal = buf;
4055 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added, buf, sizeof(buf)/sizeof(TCHAR), langID);
4056 sAdded = buf;
4057 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted, buf, sizeof(buf)/sizeof(TCHAR), langID);
4058 sDeleted = buf;
4059 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified, buf, sizeof(buf)/sizeof(TCHAR), langID);
4060 sModified = buf;
4061 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted, buf, sizeof(buf)/sizeof(TCHAR), langID);
4062 sConflicted = buf;
4063 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned, buf, sizeof(buf)/sizeof(TCHAR), langID);
4064 sUnversioned = buf;
4065 CString sToolTip;
4066 sToolTip.Format(_T("%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d"),
4067 (LPCTSTR)sNormal, m_nNormal,
4068 (LPCTSTR)sUnversioned, m_nUnversioned,
4069 (LPCTSTR)sModified, m_nModified,
4070 (LPCTSTR)sAdded, m_nAdded,
4071 (LPCTSTR)sDeleted, m_nDeleted,
4072 (LPCTSTR)sConflicted, m_nConflicted
4074 CString sStats;
4075 sStats.Format(IDS_COMMITDLG_STATISTICSFORMAT, m_nSelected, GetItemCount());
4076 if (m_pStatLabel)
4078 m_pStatLabel->SetWindowText(sStats);
4081 if (m_pSelectButton)
4083 if (m_nSelected == 0)
4084 m_pSelectButton->SetCheck(BST_UNCHECKED);
4085 else if (m_nSelected != GetItemCount())
4086 m_pSelectButton->SetCheck(BST_INDETERMINATE);
4087 else
4088 m_pSelectButton->SetCheck(BST_CHECKED);
4091 if (m_pConfirmButton)
4093 m_pConfirmButton->EnableWindow(m_nSelected>0);
4096 return sToolTip;
4101 CString CGitStatusListCtrl::GetCommonDirectory(bool bStrict)
4103 if (!bStrict)
4105 // not strict means that the selected folder has priority
4106 if (!m_StatusFileList.GetCommonDirectory().IsEmpty())
4107 return m_StatusFileList.GetCommonDirectory().GetWinPath();
4110 CTGitPath commonBaseDirectory;
4111 int nListItems = GetItemCount();
4112 for (int i=0; i<nListItems; ++i)
4114 CTGitPath baseDirectory,*p= (CTGitPath*)this->GetItemData(i);
4115 ASSERT(p);
4116 if(p==NULL)
4117 continue;
4118 baseDirectory = p->GetDirectory();
4120 if(commonBaseDirectory.IsEmpty())
4122 commonBaseDirectory = baseDirectory;
4124 else
4126 if (commonBaseDirectory.GetWinPathString().GetLength() > baseDirectory.GetWinPathString().GetLength())
4128 if (baseDirectory.IsAncestorOf(commonBaseDirectory))
4129 commonBaseDirectory = baseDirectory;
4133 return g_Git.m_CurrentDir+CString(_T("\\"))+commonBaseDirectory.GetWinPath();
4136 CTGitPath CGitStatusListCtrl::GetCommonURL(bool bStrict)
4138 CTGitPath commonBaseURL;
4139 #if 0
4141 if (!bStrict)
4143 // not strict means that the selected folder has priority
4144 if (!m_StatusUrlList.GetCommonDirectory().IsEmpty())
4145 return m_StatusUrlList.GetCommonDirectory();
4148 int nListItems = GetItemCount();
4149 for (int i=0; i<nListItems; ++i)
4151 const CTGitPath& baseURL = CTGitPath(GetListEntry(i)->GetURL());
4152 if (baseURL.IsEmpty())
4153 continue; // item has no url
4154 if(commonBaseURL.IsEmpty())
4156 commonBaseURL = baseURL;
4158 else
4160 if (commonBaseURL.GetGitPathString().GetLength() > baseURL.GetGitPathString().GetLength())
4162 if (baseURL.IsAncestorOf(commonBaseURL))
4163 commonBaseURL = baseURL;
4168 #endif
4169 return commonBaseURL;
4172 void CGitStatusListCtrl::SelectAll(bool bSelect, bool bIncludeNoCommits)
4174 CWaitCursor waitCursor;
4175 // block here so the LVN_ITEMCHANGED messages
4176 // get ignored
4177 m_bBlock = TRUE;
4178 SetRedraw(FALSE);
4180 int nListItems = GetItemCount();
4181 if (bSelect)
4182 m_nSelected = nListItems;
4183 else
4184 m_nSelected = 0;
4186 for (int i=0; i<nListItems; ++i)
4188 //FileEntry * entry = GetListEntry(i);
4189 //ASSERT(entry != NULL);
4190 CTGitPath *path = (CTGitPath *) GetItemData(i);
4191 if (path == NULL)
4192 continue;
4193 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
4194 SetEntryCheck(path,i,bSelect);
4197 // unblock before redrawing
4198 m_bBlock = FALSE;
4199 SetRedraw(TRUE);
4200 GetStatisticsString();
4201 NotifyCheck();
4204 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)
4206 LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);
4207 *pResult = 0;
4208 if (m_bBlock)
4209 return;
4210 #if 0
4211 if (GetListEntry(pGetInfoTip->iItem >= 0))
4212 if (pGetInfoTip->cchTextMax > GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString().GetLength())
4214 if (GetListEntry(pGetInfoTip->iItem)->GetRelativeGitPath().Compare(GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString())!= 0)
4215 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString(), pGetInfoTip->cchTextMax);
4216 else if (GetStringWidth(GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString()) > GetColumnWidth(pGetInfoTip->iItem))
4217 _tcsncpy_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, GetListEntry(pGetInfoTip->iItem)->path.GetGitPathString(), pGetInfoTip->cchTextMax);
4219 #endif
4222 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
4224 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
4226 // Take the default processing unless we set this to something else below.
4227 *pResult = CDRF_DODEFAULT;
4229 // First thing - check the draw stage. If it's the control's prepaint
4230 // stage, then tell Windows we want messages for every item.
4232 switch (pLVCD->nmcd.dwDrawStage)
4234 case CDDS_PREPAINT:
4235 *pResult = CDRF_NOTIFYITEMDRAW;
4236 break;
4237 case CDDS_ITEMPREPAINT:
4239 // This is the prepaint stage for an item. Here's where we set the
4240 // item's text color. Our return value will tell Windows to draw the
4241 // item itself, but it will use the new color we set here.
4243 // Tell Windows to paint the control itself.
4244 *pResult = CDRF_DODEFAULT;
4245 if (m_bBlock)
4246 return;
4248 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
4250 if (m_arStatusArray.size() > (DWORD_PTR)pLVCD->nmcd.dwItemSpec)
4253 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
4254 CTGitPath *entry=(CTGitPath *)GetItemData((int)pLVCD->nmcd.dwItemSpec);
4255 if (entry == NULL)
4256 return;
4258 // coloring
4259 // ========
4260 // black : unversioned, normal
4261 // purple : added
4262 // blue : modified
4263 // brown : missing, deleted, replaced
4264 // green : merged (or potential merges)
4265 // red : conflicts or sure conflicts
4266 if(entry->m_Action & CTGitPath::LOGACTIONS_GRAY)
4268 crText = RGB(128,128,128);
4270 }else if(entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
4272 crText = m_Colors.GetColor(CColors::Conflict);
4274 }else if(entry->m_Action & (CTGitPath::LOGACTIONS_MODIFIED))
4276 crText = m_Colors.GetColor(CColors::Modified);
4278 }else if(entry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY))
4280 crText = m_Colors.GetColor(CColors::Added);
4282 else if(entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
4284 crText = m_Colors.GetColor(CColors::DeletedNode);
4286 else if(entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
4288 crText = m_Colors.GetColor(CColors::RenamedNode);
4289 }else
4291 crText = GetSysColor(COLOR_WINDOWTEXT);
4293 // Store the color back in the NMLVCUSTOMDRAW struct.
4294 pLVCD->clrText = crText;
4297 break;
4301 BOOL CGitStatusListCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
4303 if (pWnd != this)
4304 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
4305 if (!m_bBlock)
4307 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
4308 SetCursor(hCur);
4309 return CListCtrl::OnSetCursor(pWnd, nHitTest, message);
4311 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
4312 SetCursor(hCur);
4313 return TRUE;
4316 void CGitStatusListCtrl::RemoveListEntry(int index)
4319 Locker lock(m_critSec);
4320 DeleteItem(index);
4322 m_arStatusArray.erase(m_arStatusArray.begin()+index);
4324 #if 0
4325 delete m_arStatusArray[m_arListArray[index]];
4326 m_arStatusArray.erase(m_arStatusArray.begin()+m_arListArray[index]);
4327 m_arListArray.erase(m_arListArray.begin()+index);
4328 for (int i=index; i< (int)m_arListArray.size(); ++i)
4330 m_arListArray[i]--;
4332 #endif
4335 ///< Set a checkbox on an entry in the listbox
4336 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
4337 void CGitStatusListCtrl::SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck)
4339 pEntry->m_Checked = bCheck;
4340 SetCheck(listboxIndex, bCheck);
4343 #if 0
4344 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck)
4347 int nListItems = GetItemCount();
4348 for (int j=0; j< nListItems ; ++j)
4350 FileEntry * childEntry = GetListEntry(j);
4351 ASSERT(childEntry != NULL);
4352 if (childEntry == NULL || childEntry == parentEntry)
4353 continue;
4354 if (childEntry->checked != bCheck)
4356 if (parentEntry->path.IsAncestorOf(childEntry->path))
4358 SetEntryCheck(childEntry,j,bCheck);
4359 if(bCheck)
4361 m_nSelected++;
4363 else
4365 m_nSelected--;
4372 #endif
4374 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList& pathList)
4377 pathList.Clear();
4378 int nListItems = GetItemCount();
4379 for (int i=0; i< nListItems; i++)
4381 CTGitPath * entry = (CTGitPath*)GetItemData(i);
4382 ASSERT(entry != NULL);
4383 if (entry->m_Checked)
4385 pathList.AddPath(*entry);
4388 pathList.SortByPathname();
4393 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
4394 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList& pathList, bool bNoIgnored)
4396 pathList.Clear();
4398 POSITION pos = GetFirstSelectedItemPosition();
4399 int index;
4400 while ((index = GetNextSelectedItem(pos)) >= 0)
4402 CTGitPath * entry = (CTGitPath*)GetItemData(index);
4403 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
4404 // continue;
4405 pathList.AddPath(*entry);
4409 UINT CGitStatusListCtrl::OnGetDlgCode()
4411 // we want to process the return key and not have that one
4412 // routed to the default pushbutton
4413 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS;
4416 void CGitStatusListCtrl::OnNMReturn(NMHDR * /*pNMHDR*/, LRESULT *pResult)
4418 *pResult = 0;
4419 if (m_bBlock)
4420 return;
4421 POSITION pos = GetFirstSelectedItemPosition();
4422 while ( pos )
4424 int index = GetNextSelectedItem(pos);
4425 StartDiff(index);
4429 void CGitStatusListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
4431 // Since we catch all keystrokes (to have the enter key processed here instead
4432 // of routed to the default pushbutton) we have to make sure that other
4433 // keys like Tab and Esc still do what they're supposed to do
4434 // Tab = change focus to next/previous control
4435 // Esc = quit the dialog
4436 switch (nChar)
4438 case (VK_TAB):
4440 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL, GetKeyState(VK_SHIFT)&0x8000, 0);
4441 return;
4443 break;
4444 case (VK_ESCAPE):
4446 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE, 0, 0);
4448 break;
4451 CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
4454 void CGitStatusListCtrl::PreSubclassWindow()
4456 CListCtrl::PreSubclassWindow();
4457 EnableToolTips(TRUE);
4458 m_Theme.SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);
4461 INT_PTR CGitStatusListCtrl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
4463 int row, col;
4464 RECT cellrect;
4465 row = CellRectFromPoint(point, &cellrect, &col );
4467 if (row == -1)
4468 return -1;
4471 pTI->hwnd = m_hWnd;
4472 pTI->uId = (UINT)((row<<10)+(col&0x3ff)+1);
4473 pTI->lpszText = LPSTR_TEXTCALLBACK;
4475 pTI->rect = cellrect;
4477 return pTI->uId;
4480 int CGitStatusListCtrl::CellRectFromPoint(CPoint& point, RECT *cellrect, int *col) const
4482 int colnum;
4484 // Make sure that the ListView is in LVS_REPORT
4485 if ((GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
4486 return -1;
4488 // Get the top and bottom row visible
4489 int row = GetTopIndex();
4490 int bottom = row + GetCountPerPage();
4491 if (bottom > GetItemCount())
4492 bottom = GetItemCount();
4494 // Get the number of columns
4495 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
4496 int nColumnCount = pHeader->GetItemCount();
4498 // Loop through the visible rows
4499 for ( ;row <=bottom;row++)
4501 // Get bounding rect of item and check whether point falls in it.
4502 CRect rect;
4503 GetItemRect(row, &rect, LVIR_BOUNDS);
4504 if (rect.PtInRect(point))
4506 // Now find the column
4507 for (colnum = 0; colnum < nColumnCount; colnum++)
4509 int colwidth = GetColumnWidth(colnum);
4510 if (point.x >= rect.left && point.x <= (rect.left + colwidth))
4512 RECT rectClient;
4513 GetClientRect(&rectClient);
4514 if (col)
4515 *col = colnum;
4516 rect.right = rect.left + colwidth;
4518 // Make sure that the right extent does not exceed
4519 // the client area
4520 if (rect.right > rectClient.right)
4521 rect.right = rectClient.right;
4522 *cellrect = rect;
4523 return row;
4525 rect.left += colwidth;
4529 return -1;
4532 BOOL CGitStatusListCtrl::OnToolTipText(UINT /*id*/, NMHDR *pNMHDR, LRESULT *pResult)
4534 #if 0
4535 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4536 CString strTipText;
4537 UINT_PTR nID = pNMHDR->idFrom;
4539 if (nID == 0)
4540 return FALSE;
4542 UINT_PTR row = ((nID-1) >> 10) & 0x3fffff;
4543 UINT_PTR col = (nID-1) & 0x3ff;
4545 if (col == 0)
4546 return FALSE; // no custom tooltip for the path, we use the infotip there!
4548 // get the internal column from the visible columns
4549 int internalcol = 0;
4550 UINT_PTR currentcol = 0;
4551 for (; (currentcol != col)
4552 && (internalcol < m_ColumnManager.GetColumnCount()-1)
4553 ; ++internalcol)
4555 if (m_ColumnManager.IsVisible (internalcol))
4556 currentcol++;
4559 AFX_MODULE_THREAD_STATE* pModuleThreadState = AfxGetModuleThreadState();
4560 CToolTipCtrl* pToolTip = pModuleThreadState->m_pToolTip;
4561 pToolTip->SendMessage(TTM_SETMAXTIPWIDTH, 0, 300);
4563 *pResult = 0;
4564 if ((internalcol == 2)||(internalcol == 4))
4566 FileEntry *fentry = GetListEntry(row);
4567 if (fentry)
4569 if (fentry->copied)
4571 CString url;
4572 url.Format(IDS_STATUSLIST_COPYFROM, (LPCTSTR)CPathUtils::PathUnescape(fentry->copyfrom_url), (LONG)fentry->copyfrom_rev);
4573 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4574 return TRUE;
4576 if (fentry->switched)
4578 CString url;
4579 url.Format(IDS_STATUSLIST_SWITCHEDTO, (LPCTSTR)CPathUtils::PathUnescape(fentry->url));
4580 lstrcpyn(pTTTW->szText, (LPCTSTR)url, 80);
4581 return TRUE;
4583 if (fentry->keeplocal)
4585 lstrcpyn(pTTTW->szText, (LPCTSTR)CString(MAKEINTRESOURCE(IDS_STATUSLIST_KEEPLOCAL)), 80);
4586 return TRUE;
4590 #endif
4591 return FALSE;
4594 void CGitStatusListCtrl::OnPaint()
4596 Default();
4597 if ((m_bBusy)||(m_bEmpty))
4599 CString str;
4600 if (m_bBusy)
4602 if (m_sBusy.IsEmpty())
4603 str.LoadString(IDS_STATUSLIST_BUSYMSG);
4604 else
4605 str = m_sBusy;
4607 else
4609 if (m_sEmpty.IsEmpty())
4610 str.LoadString(IDS_STATUSLIST_EMPTYMSG);
4611 else
4612 str = m_sEmpty;
4614 COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
4615 COLORREF clrTextBk;
4616 if (IsWindowEnabled())
4617 clrTextBk = ::GetSysColor(COLOR_WINDOW);
4618 else
4619 clrTextBk = ::GetSysColor(COLOR_3DFACE);
4621 CRect rc;
4622 GetClientRect(&rc);
4623 CHeaderCtrl* pHC;
4624 pHC = GetHeaderCtrl();
4625 if (pHC != NULL)
4627 CRect rcH;
4628 pHC->GetItemRect(0, &rcH);
4629 rc.top += rcH.bottom;
4631 CDC* pDC = GetDC();
4633 CMyMemDC memDC(pDC, &rc);
4635 memDC.SetTextColor(clrText);
4636 memDC.SetBkColor(clrTextBk);
4637 memDC.FillSolidRect(rc, clrTextBk);
4638 rc.top += 10;
4639 CGdiObject * oldfont = memDC.SelectStockObject(DEFAULT_GUI_FONT);
4640 memDC.DrawText(str, rc, DT_CENTER | DT_VCENTER |
4641 DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
4642 memDC.SelectObject(oldfont);
4644 ReleaseDC(pDC);
4648 // prevent users from extending our hidden (size 0) columns
4649 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
4651 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
4652 *pResult = 0;
4653 if ((phdr->iItem < 0)||(phdr->iItem >= SVNSLC_NUMCOLUMNS))
4654 return;
4656 if (m_ColumnManager.IsVisible (phdr->iItem))
4658 return;
4660 *pResult = 1;
4663 // prevent any function from extending our hidden (size 0) columns
4664 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
4666 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
4667 *pResult = 0;
4668 if ((phdr->iItem < 0)||(phdr->iItem >= m_ColumnManager.GetColumnCount()))
4670 Default();
4671 return;
4674 // visible columns may be modified
4676 if (m_ColumnManager.IsVisible (phdr->iItem))
4678 Default();
4679 return;
4682 // columns already marked as "invisible" internally may be (re-)sized to 0
4684 if ( (phdr->pitem != NULL)
4685 && (phdr->pitem->mask == HDI_WIDTH)
4686 && (phdr->pitem->cxy == 0))
4688 Default();
4689 return;
4692 if ( (phdr->pitem != NULL)
4693 && (phdr->pitem->mask != HDI_WIDTH))
4695 Default();
4696 return;
4699 *pResult = 1;
4702 void CGitStatusListCtrl::OnDestroy()
4704 SaveColumnWidths(true);
4705 CListCtrl::OnDestroy();
4708 void CGitStatusListCtrl::OnBeginDrag(NMHDR* /*pNMHDR*/, LRESULT* pResult)
4710 #if 0
4711 Locker lock(m_critSec);
4712 CDropFiles dropFiles; // class for creating DROPFILES struct
4714 int index;
4715 POSITION pos = GetFirstSelectedItemPosition();
4716 while ( (index = GetNextSelectedItem(pos)) >= 0 )
4718 FileEntry * fentry = m_arStatusArray[m_arListArray[index]];
4719 CTGitPath path = fentry->GetPath();
4720 dropFiles.AddFile( path.GetWinPathString() );
4723 if ( dropFiles.GetCount()>0 )
4725 m_bOwnDrag = true;
4726 dropFiles.CreateStructure();
4727 m_bOwnDrag = false;
4729 #endif
4730 *pResult = 0;
4733 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry /* = false */)
4735 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;
4736 for (int col = 0; col <= maxcol; col++)
4737 if (m_ColumnManager.IsVisible (col))
4738 m_ColumnManager.ColumnResized (col);
4740 if (bSaveToRegistry)
4741 m_ColumnManager.WriteSettings();
4744 bool CGitStatusListCtrl::EnableFileDrop()
4746 m_bFileDropsEnabled = true;
4747 return true;
4750 bool CGitStatusListCtrl::HasPath(const CTGitPath& path)
4752 #if 0
4753 for (size_t i=0; i < m_arStatusArray.size(); i++)
4755 FileEntry * entry = m_arStatusArray[i];
4756 if (entry->GetPath().IsEquivalentTo(path))
4757 return true;
4759 #endif
4760 return false;
4763 bool CGitStatusListCtrl::IsPathShown(const CTGitPath& path)
4765 #if 0
4766 int itemCount = GetItemCount();
4767 for (int i=0; i < itemCount; i++)
4769 FileEntry * entry = GetListEntry(i);
4770 if (entry->GetPath().IsEquivalentTo(path))
4771 return true;
4773 #endif
4774 return false;
4777 BOOL CGitStatusListCtrl::PreTranslateMessage(MSG* pMsg)
4779 if (pMsg->message == WM_KEYDOWN)
4781 switch (pMsg->wParam)
4783 case 'A':
4785 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4787 // select all entries
4788 for (int i=0; i<GetItemCount(); ++i)
4790 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
4792 return TRUE;
4795 break;
4796 case 'C':
4797 case VK_INSERT:
4799 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
4801 // copy all selected paths to the clipboard
4802 if (GetAsyncKeyState(VK_SHIFT)&0x8000)
4803 CopySelectedEntriesToClipboard(SVNSLC_COLSTATUS);
4804 else
4805 CopySelectedEntriesToClipboard(0);
4806 return TRUE;
4809 break;
4813 return CListCtrl::PreTranslateMessage(pMsg);
4816 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols)
4819 static CString ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY));
4820 static HINSTANCE hResourceHandle(AfxGetResourceHandle());
4821 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4823 CString sClipboard;
4824 CString temp;
4825 TCHAR buf[100];
4826 if (GetSelectedCount() == 0)
4827 return false;
4828 // first add the column titles as the first line
4829 temp.LoadString(IDS_STATUSLIST_COLFILE);
4830 sClipboard = temp;
4832 DWORD selection = 0;
4833 for (int i = 0, count = m_ColumnManager.GetColumnCount(); i < count; ++i)
4834 if ( ((dwCols == -1) && m_ColumnManager.IsVisible (i))
4835 || ((dwCols != 1) && (i < 32) && ((dwCols & (1 << i)) != 0)))
4837 sClipboard += _T("\t") + m_ColumnManager.GetName(i);
4839 if (i < 32)
4840 selection += 1 << i;
4843 sClipboard += _T("\r\n");
4845 POSITION pos = GetFirstSelectedItemPosition();
4846 int index;
4847 while ((index = GetNextSelectedItem(pos)) >= 0)
4849 CTGitPath * entry = (CTGitPath*)GetItemData(index);
4850 if(entry == NULL)
4851 continue;
4853 sClipboard += entry->GetWinPathString();
4854 if (selection & SVNSLC_COLFILENAME)
4856 sClipboard += _T("\t")+entry->GetFileOrDirectoryName();
4858 if (selection & SVNSLC_COLEXT)
4860 sClipboard += _T("\t")+entry->GetFileExtension();
4863 if (selection & SVNSLC_COLSTATUS)
4865 #if 0
4866 if (entry->isNested)
4868 temp.LoadString(IDS_STATUSLIST_NESTED);
4870 else
4872 GitStatus::GetStatusString(hResourceHandle, entry->status, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4873 if ((entry->copied)&&(_tcslen(buf)>1))
4874 _tcscat_s(buf, 100, _T(" (+)"));
4875 if ((entry->switched)&&(_tcslen(buf)>1))
4876 _tcscat_s(buf, 100, _T(" (s)"));
4877 if ((entry->status == entry->propstatus)&&
4878 (entry->status != git_wc_status_normal)&&
4879 (entry->status != git_wc_status_unversioned)&&
4880 (!GitStatus::IsImportant(entry->textstatus)))
4881 _tcscat_s(buf, 100, ponly);
4882 temp = buf;
4884 #endif
4885 sClipboard += _T("\t")+entry->GetActionName();
4887 #if 0
4888 if (selection & SVNSLC_COLTEXTSTATUS)
4891 if (entry->isNested)
4893 temp.LoadString(IDS_STATUSLIST_NESTED);
4895 else
4897 GitStatus::GetStatusString(hResourceHandle, entry->textstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4898 if ((entry->copied)&&(_tcslen(buf)>1))
4899 _tcscat_s(buf, 100, _T(" (+)"));
4900 if ((entry->switched)&&(_tcslen(buf)>1))
4901 _tcscat_s(buf, 100, _T(" (s)"));
4902 temp = buf;
4904 sClipboard += _T("\t")+temp;
4906 #endif
4907 #if 0
4908 if (selection & SVNSLC_COLREMOTESTATUS)
4910 if (entry->isNested)
4912 temp.LoadString(IDS_STATUSLIST_NESTED);
4914 else
4916 GitStatus::GetStatusString(hResourceHandle, entry->remotestatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4917 if ((entry->copied)&&(_tcslen(buf)>1))
4918 _tcscat_s(buf, 100, _T(" (+)"));
4919 if ((entry->switched)&&(_tcslen(buf)>1))
4920 _tcscat_s(buf, 100, _T(" (s)"));
4921 if ((entry->remotestatus == entry->remotepropstatus)&&
4922 (entry->remotestatus != git_wc_status_none)&&
4923 (entry->remotestatus != git_wc_status_normal)&&
4924 (entry->remotestatus != git_wc_status_unversioned)&&
4925 (!SVNStatus::IsImportant(entry->remotetextstatus)))
4926 _tcscat_s(buf, 100, ponly);
4927 temp = buf;
4929 sClipboard += _T("\t")+temp;
4931 if (selection & GitSLC_COLPROPSTATUS)
4933 if (entry->isNested)
4935 temp.Empty();
4937 else
4939 GitStatus::GetStatusString(hResourceHandle, entry->propstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4940 if ((entry->copied)&&(_tcslen(buf)>1))
4941 _tcscat_s(buf, 100, _T(" (+)"));
4942 if ((entry->switched)&&(_tcslen(buf)>1))
4943 _tcscat_s(buf, 100, _T(" (s)"));
4944 temp = buf;
4946 sClipboard += _T("\t")+temp;
4948 if (selection & SVNSLC_COLREMOTETEXT)
4950 if (entry->isNested)
4952 temp.Empty();
4954 else
4956 GitStatus::GetStatusString(hResourceHandle, entry->remotetextstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4957 temp = buf;
4959 sClipboard += _T("\t")+temp;
4961 if (selection & SVNSLC_COLREMOTEPROP)
4963 // SVNSLC_COLREMOTEPROP
4964 if (entry->isNested)
4966 temp.Empty();
4968 else
4970 GitStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
4971 temp = buf;
4973 sClipboard += _T("\t")+temp;
4975 if (selection & SVNSLC_COLURL)
4976 sClipboard += _T("\t")+entry->url;
4977 if (selection & SVNSLC_COLLOCK)
4979 if (!m_HeadRev.IsHead())
4981 // we have contacted the repository
4983 // decision-matrix
4984 // wc repository text
4985 // "" "" ""
4986 // "" UID1 owner
4987 // UID1 UID1 owner
4988 // UID1 "" lock has been broken
4989 // UID1 UID2 lock has been stolen
4990 if (entry->lock_token.IsEmpty() || (entry->lock_token.Compare(entry->lock_remotetoken)==0))
4992 if (entry->lock_owner.IsEmpty())
4993 temp = entry->lock_remoteowner;
4994 else
4995 temp = entry->lock_owner;
4997 else if (entry->lock_remotetoken.IsEmpty())
4999 // broken lock
5000 temp.LoadString(IDS_STATUSLIST_LOCKBROKEN);
5002 else
5004 // stolen lock
5005 temp.Format(IDS_STATUSLIST_LOCKSTOLEN, (LPCTSTR)entry->lock_remoteowner);
5008 else
5009 temp = entry->lock_owner;
5010 sClipboard += _T("\t")+temp;
5012 if (selection & SVNSLC_COLLOCKCOMMENT)
5013 sClipboard += _T("\t")+entry->lock_comment;
5014 if (selection & SVNSLC_COLAUTHOR)
5015 sClipboard += _T("\t")+entry->last_commit_author;
5016 if (selection & SVNSLC_COLREVISION)
5018 temp.Format(_T("%ld"), entry->last_commit_rev);
5019 if (entry->last_commit_rev == 0)
5020 temp.Empty();
5021 sClipboard += _T("\t")+temp;
5023 if (selection & SVNSLC_COLREMOTEREVISION)
5025 temp.Format(_T("%ld"), entry->remoterev);
5026 if (entry->remoterev == 0)
5027 temp.Empty();
5028 sClipboard += _T("\t")+temp;
5031 if (selection & SVNSLC_COLDATE)
5033 TCHAR datebuf[SVN_DATE_BUFFER];
5034 apr_time_t date = entry->last_commit_date;
5035 SVN::formatDate(datebuf, date, true);
5036 if (date)
5037 temp = datebuf;
5038 else
5039 temp.Empty();
5040 sClipboard += _T("\t")+temp;
5042 if (selection & SVNSLC_COLCOPYFROM)
5044 if (m_sURL.Compare(entry->copyfrom_url.Left(m_sURL.GetLength()))==0)
5045 temp = entry->copyfrom_url.Mid(m_sURL.GetLength());
5046 else
5047 temp = entry->copyfrom_url;
5048 sClipboard += _T("\t")+temp;
5051 for ( int i = SVNSLC_NUMCOLUMNS, count = m_ColumnManager.GetColumnCount()
5052 ; i < count
5053 ; ++i)
5055 if ((dwCols == -1) && m_ColumnManager.IsVisible (i))
5057 CString value
5058 = entry->present_props[m_ColumnManager.GetName(i)];
5059 sClipboard += _T("\t") + value;
5062 #endif
5063 if (selection & SVNSLC_COLADD)
5065 sClipboard += _T("\t")+entry->m_StatAdd;
5067 if (selection & SVNSLC_COLDEL)
5069 sClipboard += _T("\t")+entry->m_StatDel;
5072 sClipboard += _T("\r\n");
5075 return CStringUtils::WriteAsciiStringToClipboard(sClipboard);
5077 return TRUE;
5081 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
5083 #if 0
5084 std::set<CString> changelists;
5085 POSITION pos = GetFirstSelectedItemPosition();
5086 int index;
5087 while ((index = GetNextSelectedItem(pos)) >= 0)
5089 FileEntry * entry = GetListEntry(index);
5090 if (!entry->changelist.IsEmpty())
5091 changelists.insert(entry->changelist);
5093 return changelists.size();
5094 #endif
5095 return 0;
5098 bool CGitStatusListCtrl::PrepareGroups(bool bForce /* = false */)
5101 bool bHasGroups=false;
5102 if ( this->m_UnRevFileList.GetCount()>0 ||
5103 this->m_IgnoreFileList.GetCount()>0 || bForce)
5105 bHasGroups = true;
5108 RemoveAllGroups();
5109 EnableGroupView(bHasGroups);
5111 TCHAR groupname[1024];
5112 int groupindex = 0;
5114 if(bHasGroups)
5116 LVGROUP grp = {0};
5117 grp.cbSize = sizeof(LVGROUP);
5118 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5119 CString sUnassignedName(_T("Modified File"));
5120 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
5121 grp.pszHeader = groupname;
5122 grp.iGroupId = groupindex;
5123 grp.uAlign = LVGA_HEADER_LEFT;
5124 InsertGroup(groupindex++, &grp);
5126 //if(m_UnRevFileList.GetCount()>0)
5128 _tcsncpy_s(groupname, 1024, (LPCTSTR)_T("No Version Control"), 1023);
5129 grp.pszHeader = groupname;
5130 grp.iGroupId = groupindex;
5131 grp.uAlign = LVGA_HEADER_LEFT;
5132 InsertGroup(groupindex++, &grp);
5135 //if(m_IgnoreFileList.GetCount()>0)
5137 _tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Ignored File"), 1023);
5138 grp.pszHeader = groupname;
5139 grp.iGroupId = groupindex;
5140 grp.uAlign = LVGA_HEADER_LEFT;
5141 InsertGroup(groupindex++, &grp);
5146 #if 0
5147 m_bHasIgnoreGroup = false;
5149 // now add the items which don't belong to a group
5150 LVGROUP grp = {0};
5151 grp.cbSize = sizeof(LVGROUP);
5152 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5153 CString sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET));
5154 _tcsncpy_s(groupname, 1024, (LPCTSTR)sUnassignedName, 1023);
5155 grp.pszHeader = groupname;
5156 grp.iGroupId = groupindex;
5157 grp.uAlign = LVGA_HEADER_LEFT;
5158 InsertGroup(groupindex++, &grp);
5160 for (std::map<CString,int>::iterator it = m_changelists.begin(); it != m_changelists.end(); ++it)
5162 if (it->first.Compare(SVNSLC_IGNORECHANGELIST)!=0)
5164 LVGROUP grp = {0};
5165 grp.cbSize = sizeof(LVGROUP);
5166 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5167 _tcsncpy_s(groupname, 1024, it->first, 1023);
5168 grp.pszHeader = groupname;
5169 grp.iGroupId = groupindex;
5170 grp.uAlign = LVGA_HEADER_LEFT;
5171 it->second = InsertGroup(groupindex++, &grp);
5173 else
5174 m_bHasIgnoreGroup = true;
5177 if (m_bHasIgnoreGroup)
5179 // and now add the group 'ignore-on-commit'
5180 std::map<CString,int>::iterator it = m_changelists.find(SVNSLC_IGNORECHANGELIST);
5181 if (it != m_changelists.end())
5183 grp.cbSize = sizeof(LVGROUP);
5184 grp.mask = LVGF_ALIGN | LVGF_GROUPID | LVGF_HEADER;
5185 _tcsncpy_s(groupname, 1024, SVNSLC_IGNORECHANGELIST, 1023);
5186 grp.pszHeader = groupname;
5187 grp.iGroupId = groupindex;
5188 grp.uAlign = LVGA_HEADER_LEFT;
5189 it->second = InsertGroup(groupindex, &grp);
5192 #endif
5193 return bHasGroups;
5196 void CGitStatusListCtrl::NotifyCheck()
5198 CWnd* pParent = GetParent();
5199 if (NULL != pParent && NULL != pParent->GetSafeHwnd())
5201 pParent->SendMessage(SVNSLNM_CHECKCHANGED, m_nSelected);
5205 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash,CTGitPathList *list)
5207 BYTE_VECTOR out;
5208 this->m_bBusy=TRUE;
5209 m_CurrentVersion=hash;
5211 int count = 0;
5212 if(list == NULL)
5213 count = 1;
5214 else
5215 count = list->GetCount();
5217 if(hash == GIT_REV_ZERO)
5219 for(int i=0;i<count;i++)
5221 BYTE_VECTOR cmdout;
5222 cmdout.clear();
5223 CString cmd;
5224 if(!g_Git.IsInitRepos())
5226 if(list == NULL)
5227 cmd=(_T("git.exe diff-index --raw HEAD --numstat -C -M -z"));
5228 else
5229 cmd.Format(_T("git.exe diff-index --raw HEAD --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
5231 if(g_Git.Run(cmd,&cmdout))
5233 cmdout.clear();
5234 CString strout;
5235 if(g_Git.Run(_T("git.exe rev-parse --revs-only HEAD"),&strout,CP_UTF8))
5237 CMessageBox::Show(NULL,strout,_T("TortoiseGit"),MB_OK);
5238 return -1;
5240 if(strout.IsEmpty())
5241 break; //this is initial repositoyr, there are no any history
5243 CMessageBox::Show(NULL,strout,_T("TortoiseGit"),MB_OK);
5244 return -1;
5248 if(list == NULL)
5249 cmd=(_T("git.exe diff-index --cached --raw HEAD --numstat -C -M -z"));
5250 else
5251 cmd.Format(_T("git.exe diff-index --cached --raw HEAD --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
5253 g_Git.Run(cmd,&cmdout);
5254 //out+=cmdout;
5255 out.append(cmdout,0);
5257 else // Init Repository
5259 if(list == NULL)
5260 cmd=_T("git.exe ls-files -s -t -z");
5261 else
5262 cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
5264 g_Git.Run(cmd,&cmdout);
5265 //out+=cmdout;
5266 out.append(cmdout,0);
5270 if(g_Git.IsInitRepos())
5272 m_StatusFileList.ParserFromLsFile(out);
5273 for(int i=0;i<m_StatusFileList.GetCount();i++)
5274 ((CTGitPath&)(m_StatusFileList[i])).m_Action=CTGitPath::LOGACTIONS_ADDED;
5276 else
5277 this->m_StatusFileList.ParserFromLog(out);
5279 //handle delete conflict case, when remote : modified, local : deleted.
5280 for(int i=0;i<count;i++)
5282 BYTE_VECTOR cmdout;
5283 CString cmd;
5285 if(list == NULL)
5286 cmd=_T("git.exe ls-files -u -t -z");
5287 else
5288 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list)[i].GetGitPathString());
5290 g_Git.Run(cmd,&cmdout);
5292 CTGitPathList conflictlist;
5293 conflictlist.ParserFromLog(cmdout);
5294 for(int i=0;i<conflictlist.GetCount();i++)
5296 CTGitPath *p=m_StatusFileList.LookForGitPath(conflictlist[i].GetGitPathString());
5297 if(p)
5298 p->m_Action|=CTGitPath::LOGACTIONS_UNMERGED;
5299 else
5300 m_StatusFileList.AddPath(conflictlist[i]);
5304 }else
5306 int count = 0;
5307 if(list == NULL)
5308 count = 1;
5309 else
5310 count = list->GetCount();
5312 for(int i=0;i<count;i++)
5314 BYTE_VECTOR cmdout;
5315 CString cmd;
5316 if(list == NULL)
5317 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash);
5318 else
5319 cmd.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash,(*list)[i].GetGitPathString());
5321 g_Git.Run(cmd,&cmdout);
5323 out.append(cmdout);
5325 this->m_StatusFileList.ParserFromLog(out);
5329 for(int i=0;i<m_StatusFileList.GetCount();i++)
5331 CTGitPath * gitpatch=(CTGitPath*)&m_StatusFileList[i];
5332 gitpatch->m_Checked = TRUE;
5333 m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]);
5336 this->m_bBusy=FALSE;
5337 return 0;
5340 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList &list)
5342 m_arStatusArray.clear();
5343 for(int i=0;i<list.GetCount();i++)
5345 CTGitPath * gitpath=(CTGitPath*)&list[i];
5347 if(gitpath ->m_Action & CTGitPath::LOGACTIONS_HIDE)
5348 continue;
5350 gitpath->m_Checked = TRUE;
5351 m_arStatusArray.push_back((CTGitPath*)&list[i]);
5353 return 0;
5356 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList *List)
5358 this->m_UnRevFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER,List);
5359 for(int i=0;i<m_UnRevFileList.GetCount();i++)
5361 CTGitPath * gitpatch=(CTGitPath*)&m_UnRevFileList[i];
5362 gitpatch->m_Checked = FALSE;
5363 m_arStatusArray.push_back((CTGitPath*)&m_UnRevFileList[i]);
5365 return 0;
5368 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList *List)
5370 this->m_IgnoreFileList.FillUnRev(CTGitPath::LOGACTIONS_UNVER|CTGitPath::LOGACTIONS_IGNORE,List);
5371 for(int i=0;i<m_IgnoreFileList.GetCount();i++)
5373 CTGitPath * gitpatch=(CTGitPath*)&m_IgnoreFileList[i];
5374 gitpatch->m_Checked = FALSE;
5375 m_arStatusArray.push_back((CTGitPath*)&m_IgnoreFileList[i]);
5377 return 0;
5379 int CGitStatusListCtrl::UpdateFileList(int mask,bool once,CTGitPathList *List)
5381 if(mask&CGitStatusListCtrl::FILELIST_MODIFY)
5383 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_MODIFY)))
5385 UpdateFileList(git_revnum_t(GIT_REV_ZERO),List);
5386 m_FileLoaded|=CGitStatusListCtrl::FILELIST_MODIFY;
5389 if(mask&CGitStatusListCtrl::FILELIST_UNVER)
5391 if(once || (!(m_FileLoaded&CGitStatusListCtrl::FILELIST_UNVER)))
5393 UpdateUnRevFileList(List);
5394 m_FileLoaded|=CGitStatusListCtrl::FILELIST_UNVER;
5397 return 0;
5400 void CGitStatusListCtrl::Clear()
5402 m_FileLoaded=0;
5403 this->DeleteAllItems();
5404 this->m_arListArray.clear();
5405 this->m_arStatusArray.clear();
5406 this->m_changelists.clear();
5408 //////////////////////////////////////////////////////////////////////////
5409 #if 0
5410 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD * /*pdwEffect*/, POINTL pt)
5412 if(pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
5414 HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
5415 if(hDrop != NULL)
5417 TCHAR szFileName[MAX_PATH];
5419 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
5421 POINT clientpoint;
5422 clientpoint.x = pt.x;
5423 clientpoint.y = pt.y;
5424 ScreenToClient(m_hTargetWnd, &clientpoint);
5425 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5427 CTSVNPathList changelistItems;
5428 for(UINT i = 0; i < cFiles; ++i)
5430 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5431 changelistItems.AddPath(CTSVNPath(szFileName));
5433 // find the changelist name
5434 CString sChangelist;
5435 LONG_PTR nGroup = m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint);
5436 for (std::map<CString, int>::iterator it = m_pSVNStatusListCtrl->m_changelists.begin(); it != m_pSVNStatusListCtrl->m_changelists.end(); ++it)
5437 if (it->second == nGroup)
5438 sChangelist = it->first;
5439 if (!sChangelist.IsEmpty())
5441 SVN git;
5442 if (git.AddToChangeList(changelistItems, sChangelist, git_depth_empty))
5444 for (int l=0; l<changelistItems.GetCount(); ++l)
5446 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5447 if (index >= 0)
5449 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5450 if (e)
5452 e->changelist = sChangelist;
5453 if (!e->IsFolder())
5455 if (m_pSVNStatusListCtrl->m_changelists.find(e->changelist)!=m_pSVNStatusListCtrl->m_changelists.end())
5456 m_pSVNStatusListCtrl->SetItemGroup(index, m_pSVNStatusListCtrl->m_changelists[e->changelist]);
5457 else
5458 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5462 else
5464 HWND hParentWnd = GetParent(m_hTargetWnd);
5465 if (hParentWnd != NULL)
5466 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5470 else
5472 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
5475 else
5477 SVN git;
5478 if (git.RemoveFromChangeList(changelistItems, CStringArray(), git_depth_empty))
5480 for (int l=0; l<changelistItems.GetCount(); ++l)
5482 int index = m_pSVNStatusListCtrl->GetIndex(changelistItems[l]);
5483 if (index >= 0)
5485 CSVNStatusListCtrl::FileEntry * e = m_pSVNStatusListCtrl->GetListEntry(index);
5486 if (e)
5488 e->changelist = sChangelist;
5489 m_pSVNStatusListCtrl->SetItemGroup(index, 0);
5492 else
5494 HWND hParentWnd = GetParent(m_hTargetWnd);
5495 if (hParentWnd != NULL)
5496 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)changelistItems[l].GetWinPath());
5500 else
5502 CMessageBox::Show(m_pSVNStatusListCtrl->m_hWnd, git.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
5506 else
5508 for(UINT i = 0; i < cFiles; ++i)
5510 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
5511 HWND hParentWnd = GetParent(m_hTargetWnd);
5512 if (hParentWnd != NULL)
5513 ::SendMessage(hParentWnd, CSVNStatusListCtrl::SVNSLNM_ADDFILE, 0, (LPARAM)szFileName);
5517 GlobalUnlock(medium.hGlobal);
5519 return true; //let base free the medium
5521 HRESULT STDMETHODCALLTYPE CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)
5523 CIDropTarget::DragOver(grfKeyState, pt, pdwEffect);
5524 *pdwEffect = DROPEFFECT_COPY;
5525 if (m_pSVNStatusListCtrl)
5527 POINT clientpoint;
5528 clientpoint.x = pt.x;
5529 clientpoint.y = pt.y;
5530 ScreenToClient(m_hTargetWnd, &clientpoint);
5531 if ((m_pSVNStatusListCtrl->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl->GetGroupFromPoint(&clientpoint) >= 0))
5533 *pdwEffect = DROPEFFECT_MOVE;
5535 else if ((!m_pSVNStatusListCtrl->m_bFileDropsEnabled)||(m_pSVNStatusListCtrl->m_bOwnDrag))
5537 *pdwEffect = DROPEFFECT_NONE;
5540 return S_OK;
5543 #endif
5545 void CGitStatusListCtrl::FileSaveAs(CTGitPath *path)
5547 CString filename;
5548 filename.Format(_T("%s-%s%s"),path->GetBaseFilename(),this->m_CurrentVersion.Left(6),path->GetFileExtension());
5549 CFileDialog dlg(FALSE,NULL,
5550 filename,
5551 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
5552 NULL);
5553 CString currentpath;
5554 currentpath=g_Git.m_CurrentDir+_T("\\");
5555 currentpath+=path->GetWinPathString();
5557 dlg.m_ofn.lpstrInitialDir=currentpath.GetBuffer();
5559 CString cmd,out;
5560 if(dlg.DoModal()==IDOK)
5562 filename = dlg.GetFileName();
5563 if(m_CurrentVersion == GIT_REV_ZERO)
5565 cmd.Format(_T("copy /Y \"%s\" \"%s\""),path->GetWinPath(),filename);
5566 if(g_Git.Run(cmd,&out,CP_ACP))
5568 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5569 return;
5572 }else
5574 cmd.Format(_T("git.exe cat-file -p %s:\"%s\""),m_CurrentVersion,path->GetGitPathString());
5575 if(g_Git.RunLogFile(cmd,filename))
5577 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5578 return;
5585 int CGitStatusListCtrl::RevertSelectedItemToVersion()
5587 if(this->m_CurrentVersion.IsEmpty())
5588 return 0;
5589 if(this->m_CurrentVersion == GIT_REV_ZERO)
5590 return 0;
5592 POSITION pos = GetFirstSelectedItemPosition();
5593 int index;
5594 CString cmd,out;
5595 int count =0;
5596 while ((index = GetNextSelectedItem(pos)) >= 0)
5598 CTGitPath *fentry=(CTGitPath*)GetItemData(index);
5599 cmd.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion,fentry->GetGitPathString());
5600 out.Empty();
5601 if(g_Git.Run(cmd,&out,CP_ACP))
5603 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5605 count++;
5608 out.Format(_T("%d files revert to %s"),count,m_CurrentVersion.Left(6));
5609 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5612 void CGitStatusListCtrl::OpenFile(CTGitPath*filepath,int mode)
5614 CString file;
5615 if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion == GIT_REV_ZERO)
5617 file= filepath->GetWinPath();
5618 }else
5620 CString temppath;
5621 GetTempPath(temppath);
5622 file.Format(_T("%s%s_%s%s"),
5623 temppath,
5624 filepath->GetBaseFilename(),
5625 m_CurrentVersion.Left(6),
5626 filepath->GetFileExtension());
5627 CString cmd,out;
5628 cmd.Format(_T("git.exe cat-file -p %s:\"%s\""),m_CurrentVersion,filepath->GetGitPathString());
5629 if(g_Git.RunLogFile(cmd,file))
5631 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
5632 return;
5636 if(mode == NOTEPAD2)
5638 CString sCmd;
5639 sCmd.Format(_T("\"%s\" \"%s\""),
5640 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("notepad2.exe")), file);
5642 CAppUtils::LaunchApplication(sCmd, NULL, false);
5643 return ;
5645 int ret = HINSTANCE_ERROR;
5647 if(mode == OPEN )
5649 ret = (int)ShellExecute(this->m_hWnd, NULL,file, NULL, NULL, SW_SHOW);
5651 if (ret > HINSTANCE_ERROR)
5653 return;
5658 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
5659 cmd += file;
5660 CAppUtils::LaunchApplication(cmd, NULL, false);