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.
23 #include "GitStatusListCtrl.h"
25 #include "..\\TortoiseShell\resource.h"
26 #include "MessageBox.h"
28 #include "UnicodeUtils.h"
30 #include "PathUtils.h"
32 #include "StringUtils.h"
33 #include "DirFileEnum.h"
34 #include "GitConfig.h"
35 //#include "SVNProperties.h"
39 //#include "SVNProgressDlg.h"
40 #include "SysImageList.h"
41 //#include "Svnstatuslistctrl.h"
44 #include "GitStatus.h"
45 //#include "SVNHelpers.h"
47 #include "ShellUpdater.h"
48 #include "GitAdminDir.h"
49 //#include "DropFiles.h"
52 //#include "EditPropertiesDlg.h"
53 //#include "CreateChangelistDlg.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
)
76 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclk
)
77 ON_NOTIFY_REFLECT(LVN_GETINFOTIP
, OnLvnGetInfoTip
)
78 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdraw
)
81 ON_NOTIFY_REFLECT(NM_RETURN
, OnNMReturn
)
83 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, OnToolTipText
)
84 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, OnToolTipText
)
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
)
91 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnBeginDrag
)
92 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING
, &CGitStatusListCtrl::OnLvnItemchanging
)
97 CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl()
98 //, m_HeadRev(GitRev::REV_HEAD)
101 , m_pSelectButton(NULL
)
102 , m_pConfirmButton(NULL
)
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)
115 , m_bHasCheckboxes(false)
116 , m_bCheckIfGroupsExist(true)
117 , m_bFileDropsEnabled(false)
119 , m_dwDefaultColumns(0)
120 , m_ColumnManager(this)
121 , m_bAscending(false)
122 , m_nSortedColumn(-1)
123 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE
))
129 CGitStatusListCtrl::~CGitStatusListCtrl()
131 // if (m_pDropTarget)
132 // delete m_pDropTarget;
136 void CGitStatusListCtrl::ClearStatusArray()
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();
148 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetListEntry(UINT_PTR index
)
151 if (index
>= (UINT_PTR
)m_arListArray
.size())
153 if (m_arListArray
[index
] >= m_arStatusArray
.size())
155 return m_arStatusArray
[m_arListArray
[index
]];
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
))
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
))
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
))
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);
218 SetExtendedStyle(exStyle
);
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
);
230 if (m_pDropTarget
== NULL
)
232 m_pDropTarget
= new CGitStatusListCtrlDropTarget(this);
233 RegisterDragDrop(m_hWnd
,m_pDropTarget
);
234 // create the supported formats:
236 ftetc
.dwAspect
= DVASPECT_CONTENT
;
238 ftetc
.tymed
= TYMED_HGLOBAL
;
239 ftetc
.cfFormat
=CF_HDROP
;
240 m_pDropTarget
->AddSuportedFormat(ftetc
);
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 */
258 , bool bShowUserProps
/* = false */)
260 Locker
lock(m_critSec
);
261 int mask
= CGitStatusListCtrl::FILELIST_MODIFY
;
263 mask
|= CGitStatusListCtrl::FILELIST_IGNORE
;
265 mask
|= CGitStatusListCtrl::FILELIST_UNVER
;
266 this->UpdateFileList(mask
,bUpdate
,(CTGitPathList
*)pathList
);
271 int refetchcounter
= 0;
274 // force the cursor to change
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();
316 m_bHasExternalsFromDifferentRepos
= FALSE
;
317 m_bHasExternals
= FALSE
;
318 m_bHasUnversionedItems
= FALSE
;
320 m_bHasChangeLists
= false;
321 m_bShowIgnores
= bShowIgnores
;
328 // first clear possible status data left from
329 // previous GetStatus() calls
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
347 CStringA sUUID
; // holds the repo UUID
348 CTGitPathList arExtPaths
; // list of Git:external paths
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;
381 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
.GetCommonDirectory(), bUpdate
, sUUID
, arExtPaths
, true, depth
, bShowIgnoresRight
))
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
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
))
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
);
420 } while(!BuildStatistics() && (refetchcounter
< 2) && (*m_pbCanceled
==false));
423 FetchUserProperties();
425 m_ColumnManager
.UpdateUserPropList (m_arStatusArray
);
430 SetCursorPos(pt
.x
, pt
.y
);
438 // Fetch all local properties for all elements in the status array
440 void CGitStatusListCtrl::FetchUserProperties()
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
459 , FALSE
// no write lock
460 , 0 // lock just the directory/file itself
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
475 for ( apr_hash_index_t
*index
476 = apr_hash_first (localPool
, props
)
478 ; index
= apr_hash_next (index
))
480 // extract next entry from hash
482 const char* key
= NULL
;
484 const char** val
= NULL
;
486 apr_hash_this ( index
487 , reinterpret_cast<const void**>(&key
)
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
);
511 // Work on a single item from the list of paths which is provided to us
513 bool CGitStatusListCtrl::FetchStatusForSingleTarget(
516 const CTGitPath
& target
,
517 bool bFetchStatusFromRepository
,
518 CStringA
& strCurrentRepositoryUUID
,
519 CTGitPathList
& arExtPaths
,
526 config
.GetDefaultIgnores();
528 CTGitPath
workingTarget(target
);
530 git_wc_status2_t
* s
;
532 s
= status
.GetFirstFileStatus(workingTarget
, GitPath
, bFetchStatusFromRepository
, depth
, bShowIgnores
);
534 m_HeadRev
= SVNRev(status
.headrev
);
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
))
549 s
= status
.GetNextFileStatus(GitPath
);
550 if(workingTarget
.IsEquivalentTo(GitPath
))
557 m_sLastError
= status
.GetLastErrorMsg();
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
;
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
);
640 m_sLastError
= status
.GetLastErrorMsg();
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();
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
)
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
;
739 entry
->copyfrom_rev
= 0;
743 if (m_sURL
.IsEmpty())
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
);
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
) );
774 if (pGitStatus
->ood_kind
== Git_node_none
)
775 entry
->isfolder
= path
.IsDirectory();
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
);
796 void CGitStatusListCtrl::AddUnversionedFolder(const CTGitPath
& folderName
,
797 const CTGitPath
& basePath
,
801 if (!m_bUnversionedRecurse
)
803 CSimpleFileFind
filefinder(folderName
.GetWinPathString());
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
);
824 if (!g_GitAdminDir
.HasAdminDir(entry
->path
.GetWinPathString(), true))
825 AddUnversionedFolder(entry
->path
, basePath
, config
);
833 void CGitStatusListCtrl::ReadRemainingItemsStatus(GitStatus
& status
, const CTGitPath
& basePath
,
834 CStringA
& strCurrentRepositoryUUID
,
835 CTGitPathList
& arExtPaths
, GitConfig
* config
, bool bAllDirect
)
838 git_wc_status2_t
* s
;
840 CTGitPath lastexternalpath
;
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
);
862 bool bDirectoryIsExternal
= false;
863 bool bEntryfromDifferentRepo
= false;
868 if (strCurrentRepositoryUUID
.IsEmpty())
869 strCurrentRepositoryUUID
= s
->entry
->uuid
;
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
;
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
;
904 // if unversioned items lie around in external
905 // directories from different repos, we have to mark them
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
928 CTGitPath extpath
= GitPath
;
929 while (basePath
.IsAncestorOf(extpath
))
931 if (!extpath
.HasAdminDir())
933 bEntryfromDifferentRepo
= true;
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
944 for (int ix
=0; ix
<arExtPaths
.GetCount(); ix
++)
946 if (arExtPaths
[ix
].IsAncestorOf(GitPath
))
948 bDirectoryIsExternal
= true;
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
)))
967 // we have an unversioned folder -> get all files in it recursively!
968 AddUnversionedFolder(GitPath
, basePath
, config
);
971 } // while ((s = status.GetNextFileStatus(GitPath)) != NULL)
975 // Get the show-flags bitmap value which corresponds to a particular Git status
976 DWORD
CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status
)
980 case git_wc_status_none
:
981 case git_wc_status_unversioned
:
982 return SVNSLC_SHOWUNVERSIONED
;
983 case git_wc_status_ignored
:
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
;
1010 // we should NEVER get here!
1017 void CGitStatusListCtrl::Show(DWORD dwShow
, DWORD dwCheck
/*=0*/, bool bShowFolders
/* = true */,BOOL UpdateStatusList
)
1019 CWinApp
* pApp
= AfxGetApp();
1021 pApp
->DoWaitCursor(1);
1023 Locker
lock(m_critSec
);
1024 WORD langID
= (WORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1026 //SetItemCount(listIndex);
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
]);
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
);
1064 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
1065 for (int col
= 0; col
<= maxcol
; col
++)
1066 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, 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
);
1090 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
1091 EnsureVisible(nSelectedEntry
, false);
1095 // Restore the item at the top of the list.
1096 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
1098 if ( !EnsureVisible(nTopIndex
+i
,false) )
1106 pApp
->DoWaitCursor(-1);
1114 CWinApp
* pApp
= AfxGetApp();
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
);
1130 m_arListArray
.clear();
1132 m_arListArray
.reserve(m_arStatusArray
.size());
1133 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
1136 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
1138 FileEntry
* entry
= m_arStatusArray
[i
];
1139 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
1141 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
1143 if (entry
->IsFolder() && (!bShowFolders
))
1144 continue; // don't show folders if they're not wanted.
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
;
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
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
)))
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
)))
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
)))
1192 entry
->checked
= true;
1194 AddEntry(entry
, langID
, listIndex
++);
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));
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
);
1229 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
1230 EnsureVisible(nSelectedEntry
, false);
1234 // Restore the item at the top of the list.
1235 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
1237 if ( !EnsureVisible(nTopIndex
+i
,false) )
1245 pApp
->DoWaitCursor(-1);
1247 m_bEmpty
= (GetItemCount() == 0);
1253 void CGitStatusListCtrl::Show(DWORD dwShow
, const CTGitPathList
& checkedList
, bool bShowFolders
/* = true */)
1258 Locker
lock(m_critSec
);
1259 WORD langID
= (WORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1261 CWinApp
* pApp
= AfxGetApp();
1263 pApp
->DoWaitCursor(1);
1265 m_bShowFolders
= bShowFolders
;
1267 int nTopIndex
= GetTopIndex();
1268 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
1269 int nSelectedEntry
= 0;
1270 if (posSelectedEntry
)
1271 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
1277 m_arListArray
.clear();
1279 m_arListArray
.reserve(m_arStatusArray
.size());
1280 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
1283 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
1285 FileEntry
* entry
= m_arStatusArray
[i
];
1286 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
1288 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
1290 if (entry
->IsFolder() && (!bShowFolders
))
1291 continue; // don't show folders if they're not wanted.
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;
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
++);
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));
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
);
1365 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
1366 EnsureVisible(nSelectedEntry
, false);
1370 // Restore the item at the top of the list.
1371 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
1373 if ( !EnsureVisible(nTopIndex
+i
,false) )
1381 pApp
->DoWaitCursor(-1);
1383 m_bEmpty
= (GetItemCount() == 0);
1388 int CGitStatusListCtrl::GetColumnIndex(int mask
)
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();
1407 int index
= listIndex
;
1409 CString entryname
= GitPath
->GetGitPathString();
1411 // if (entry->isfolder)
1412 // icon_idx = m_nIconFolder;
1415 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(*GitPath
);
1419 rename
.Format(_T("(from %s)"),GitPath
->GetGitOldPathString());
1420 if(GitPath
->m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
1423 InsertItem(index
, entryname
, icon_idx
);
1425 this->SetItemData(index
, (DWORD_PTR
)GitPath
);
1426 // SVNSLC_COLFILENAME
1427 SetItemText(index
, nCol
++, GitPath
->GetFileOrDirectoryName());
1429 SetItemText(index
, nCol
++, GitPath
->GetFileExtension());
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
)
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);
1447 SetItemGroup(index
,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
1463 entry
->checked
= m_mapFilenameToChecked
[path
];
1468 int index
= listIndex
;
1470 CString entryname
= entry
->GetDisplayName();
1472 if (entry
->isfolder
)
1473 icon_idx
= m_nIconFolder
;
1476 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(entry
->path
);
1479 InsertItem(index
, entryname
, icon_idx
);
1480 // SVNSLC_COLFILENAME
1481 SetItemText(index
, nCol
++, entry
->path
.GetFileOrDirectoryName());
1483 SetItemText(index
, nCol
++, entry
->path
.GetFileExtension());
1485 if (entry
->isNested
)
1487 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1488 SetItemText(index
, nCol
++, sTemp
);
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)"));
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
);
1504 SetItemText(index
, nCol
++, buf
);
1506 // SVNSLC_COLREMOTESTATUS
1507 if (entry
->isNested
)
1509 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1510 SetItemText(index
, nCol
++, sTemp
);
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
);
1527 SetItemText(index
, nCol
++, buf
);
1529 // SVNSLC_COLTEXTSTATUS
1530 if (entry
->isNested
)
1532 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1533 SetItemText(index
, nCol
++, sTemp
);
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)"));
1544 SetItemText(index
, nCol
++, buf
);
1546 // SVNSLC_COLPROPSTATUS
1547 if (entry
->isNested
)
1549 SetItemText(index
, nCol
++, _T(""));
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)"));
1560 SetItemText(index
, nCol
++, buf
);
1562 // SVNSLC_COLREMOTETEXT
1563 if (entry
->isNested
)
1565 SetItemText(index
, nCol
++, _T(""));
1570 SVNStatus::GetStatusString(hResourceHandle
, entry
->remotetextstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
1571 SetItemText(index
, nCol
++, buf
);
1574 // SVNSLC_COLREMOTEPROP
1575 if (entry
->isNested
)
1577 SetItemText(index
, nCol
++, _T(""));
1581 // SVNStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1582 SetItemText(index
, nCol
++, buf
);
1585 // SetItemText(index, nCol++, entry->url);
1588 if (!m_HeadRev
.IsHead())
1590 // we have contacted the repository
1593 // wc repository text
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
);
1604 SetItemText(index
, nCol
++, entry
->lock_owner
);
1606 else if (entry
->lock_remotetoken
.IsEmpty())
1609 CString
temp(MAKEINTRESOURCE(IDS_STATUSLIST_LOCKBROKEN
));
1610 SetItemText(index
, nCol
++, temp
);
1616 temp
.Format(IDS_STATUSLIST_LOCKSTOLEN
, (LPCTSTR
)entry
->lock_remoteowner
);
1617 SetItemText(index
, nCol
++, temp
);
1621 SetItemText(index
, nCol
++, entry
->lock_owner
);
1622 // SVNSLC_COLLOCKCOMMENT
1623 SetItemText(index
, nCol
++, entry
->lock_comment
);
1625 SetItemText(index
, nCol
++, entry
->last_commit_author
);
1626 // SVNSLC_COLREVISION
1628 temp
.Format(_T("%ld"), entry
->last_commit_rev
);
1629 if (entry
->last_commit_rev
> 0)
1630 SetItemText(index
, nCol
++, temp
);
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
);
1638 SetItemText(index
, nCol
++, _T(""));
1640 TCHAR datebuf
[SVN_DATE_BUFFER
];
1641 apr_time_t date
= entry
->last_commit_date
;
1642 SVN::formatDate(datebuf
, date
, true);
1644 SetItemText(index
, nCol
++, datebuf
);
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());
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
);
1668 SetItemText(index
, nCol
++, _T(""));
1671 // user-defined properties
1672 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
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
);
1686 SetItemText(index
, i
, propVal
);
1689 SetItemText(index
, i
, _T(""));
1692 SetCheck(index
, entry
->checked
);
1695 if (m_changelists
.find(entry
->changelist
) != m_changelists
.end())
1696 SetItemGroup(index
, m_changelists
[entry
->changelist
]);
1698 SetItemGroup(index
, 0);
1703 bool CGitStatusListCtrl::SetItemGroup(int item
, int groupindex
)
1705 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1710 i
.mask
= LVIF_GROUPID
;
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
);
1726 Show(m_dwShow
, 0, m_bShowFolders
);
1730 void CGitStatusListCtrl::OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1732 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1737 if (m_nSortedColumn
== phdr
->iItem
)
1738 m_bAscending
= !m_bAscending
;
1740 m_bAscending
= TRUE
;
1741 m_nSortedColumn
= phdr
->iItem
;
1742 m_mapFilenameToChecked
.clear();
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
);
1765 SetCheck(i
, entry
->m_Checked
);
1771 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1773 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
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
)))
1786 BOOL
CGitStatusListCtrl::OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1788 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1790 if ((pNMLV
->uNewState
==0)||(pNMLV
->uNewState
& LVIS_SELECTED
)||(pNMLV
->uNewState
& LVIS_FOCUSED
))
1796 bool bSelected
= !!(ListView_GetItemState(m_hWnd
, pNMLV
->iItem
, LVIS_SELECTED
) & LVIS_SELECTED
);
1797 int nListItems
= GetItemCount();
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
);
1810 POSITION pos
= GetFirstSelectedItemPosition();
1812 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1814 if (index
!= pNMLV
->iItem
)
1815 CheckEntry(index
, nListItems
);
1821 UncheckEntry(pNMLV
->iItem
, nListItems
);
1824 POSITION pos
= GetFirstSelectedItemPosition();
1826 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1828 if (index
!= pNMLV
->iItem
)
1829 UncheckEntry(index
, nListItems
);
1834 GetStatisticsString();
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
);
1854 void CGitStatusListCtrl::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1856 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
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.
1865 && (header
->pitem
->iOrder
> m_ColumnManager
.GetInvisibleCount()))
1867 m_ColumnManager
.ColumnMoved (header
->iItem
, header
->pitem
->iOrder
);
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
);
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.
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
)
1898 if (!testEntry
->checked
)
1900 if (testEntry
->path
.IsAncestorOf(folderpath
) && (!testEntry
->path
.IsEquivalentTo(folderpath
)))
1902 SetEntryCheck(testEntry
,i
,true);
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
)
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);
1934 // now we need to check all children of this parent folder
1935 SetCheckOnAllDescendentsOf(testEntry
, true);
1942 if ( !path
->m_Checked
)
1944 path
->m_Checked
= TRUE
;
1949 void CGitStatusListCtrl::UncheckEntry(int index
, int nListItems
)
1951 Locker
lock(m_critSec
);
1952 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1953 ASSERT(path
!= NULL
);
1956 SetCheck(index
, FALSE
);
1957 //entry = GetListEntry(index);
1958 // item was unchecked
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
)
1979 if (testEntry
->checked
)
1981 if (testEntry
->path
.IsAncestorOf(entry
->path
))
1983 if (testEntry
->status
== git_wc_status_deleted
)
1985 SetEntryCheck(testEntry
,i
,false);
1988 SetCheckOnAllDescendentsOf(testEntry
, false);
1995 if ( path
->m_Checked
)
1997 path
->m_Checked
= FALSE
;
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
;
2012 bool CGitStatusListCtrl::BuildStatistics()
2015 bool bRefetchStatus
= false;
2017 // now gather some statistics
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
))
2034 if(status
&CTGitPath::LOGACTIONS_DELETED
)
2037 if(status
&(CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_MODIFIED
))
2040 if(status
&CTGitPath::LOGACTIONS_UNMERGED
)
2043 if(status
&(CTGitPath::LOGACTIONS_IGNORE
|CTGitPath::LOGACTIONS_UNVER
))
2048 // } // switch (entry->status)
2050 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
2051 return !bRefetchStatus
;
2056 void CGitStatusListCtrl::GetMinMaxRevisions(git_revnum_t
& rMin
, git_revnum_t
& rMax
, bool bShownOnly
, bool bCheckedOnly
)
2059 Locker
lock(m_critSec
);
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
);
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
)
2102 int CGitStatusListCtrl::GetGroupFromPoint(POINT
* ppt
)
2104 // the point must be relative to the upper left corner of the control
2108 if (!IsGroupViewEnabled())
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)
2127 GetItemRect(nItem
, &r
, LVIR_LABEL
);
2128 if (ppt
->x
> r
.right
)
2132 lv
.mask
= LVIF_GROUPID
;
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
2142 nItem
= HitTest(pt
, &flags
);
2143 if ((flags
& LVHT_ONITEM
)&&(nItem
>= 0))
2145 // the first item below the point
2147 lv
.mask
= LVIF_GROUPID
;
2150 if (lv
.iGroupId
!= groupID
)
2165 void CGitStatusListCtrl::OnContextMenuGroup(CWnd
* /*pWnd*/, CPoint point
)
2167 POINT clientpoint
= point
;
2168 ScreenToClient(&clientpoint
);
2169 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint
) >= 0))
2172 if (popup
.CreatePopupMenu())
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;
2183 case IDSVNLC_CHECKGROUP
:
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
2193 for (int i
=0; i
<GetItemCount(); ++i
)
2195 SecureZeroMemory(&lv
, sizeof(LVITEM
));
2196 lv
.mask
= LVIF_GROUPID
;
2200 if (lv
.iGroupId
== group
)
2202 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
2205 bool bOldCheck
= entry
->m_Checked
;
2206 SetEntryCheck(entry
, i
, bCheck
);
2207 if (bCheck
!= bOldCheck
)
2218 GetStatisticsString();
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)
2241 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
2242 CTGitPath
* filepath
;
2244 int selIndex
= GetSelectionMark();
2245 if ((point
.x
== -1) && (point
.y
== -1))
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
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
)
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
);
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
);
2312 if (GetSelectedCount() == 1)
2314 bool bEntryAdded
= false;
2315 //if (entry->remotestatus <= git_wc_status_normal)
2317 // if (wcStatus > git_wc_status_normal)
2319 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
2321 if(!g_Git
.IsInitRepos())
2322 popup
.AppendMenuIcon(IDSVNLC_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2329 //else if (wcStatus != git_wc_status_deleted)
2331 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
2333 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
2334 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
2335 // bEntryAdded = true;
2337 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
2339 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2340 // bEntryAdded = true;
2344 popup
.AppendMenu(MF_SEPARATOR
);
2346 //else if (GetSelectedCount() > 1)
2348 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
2350 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
2351 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
2357 ///Select Multi item
2358 //if (GetSelectedCount() > 0)
2360 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
2362 // POSITION pos = GetFirstSelectedItemPosition();
2363 // int index = GetNextSelectedItem(pos);
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;
2370 // status1 = entry->status;
2371 // index = GetNextSelectedItem(pos);
2374 // entry = GetListEntry(index);
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))
2380 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
2385 // if (wcStatus > git_wc_status_normal)
2387 // if (m_dwContextMenus & SVNSLC_POPREVERT)
2389 // // reverting missing folders is not possible
2390 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
2392 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
2396 // if (entry->remotestatus > git_wc_status_normal)
2398 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
2400 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
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))
2456 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
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))
2461 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
2463 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
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);
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;
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)
2498 if (ignoreSubMenu
.CreateMenu())
2501 if (ignorelist
.GetCount()==1)
2502 ignorepath
= ignorelist
[0].GetFileOrDirectoryName();
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
);
2509 temp
.LoadString(IDS_MENUIGNORE
);
2510 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)ignoreSubMenu
.m_hMenu
, temp
);
2516 if (ignorelist
.GetCount()==1)
2518 temp
.LoadString(IDS_MENUIGNORE
);
2522 temp
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
2524 popup
.AppendMenuIcon(IDSVNLC_IGNORE
, temp
, IDI_IGNORE
);
2532 if (GetSelectedCount() > 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
);
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
);
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()))
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
)))
2607 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
2608 bNeedSeparator
= false;
2610 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, cmdID
, it
->first
);
2615 temp
.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS
);
2616 popup
.AppendMenu(MF_POPUP
|MF_STRING
, (UINT_PTR
)changelistSubMenu
.GetSafeHmenu(), temp
);
2622 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2625 AfxGetApp()->DoWaitCursor(1);
2626 int iItemCountBeforeMenuCmd
= GetItemCount();
2627 bool bForce
= false;
2630 case IDSVNLC_VIEWREV
:
2631 OpenFile(filepath
,NOTEPAD2
);
2634 OpenFile(filepath
,OPEN
);
2636 case IDSVNLC_OPENWITH
:
2637 OpenFile(filepath
,OPEN_WITH
);
2639 case IDSVNLC_EXPLORE
:
2641 ShellExecute(this->m_hWnd
, _T("explore"), filepath
->GetDirectory().GetWinPath(), NULL
, NULL
, SW_SHOW
);
2645 // Compare current version and work copy.
2646 case IDSVNLC_COMPAREWC
:
2648 POSITION pos
= GetFirstSelectedItemPosition();
2651 int index
= GetNextSelectedItem(pos
);
2656 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2657 case IDSVNLC_COMPARE
:
2659 POSITION pos
= GetFirstSelectedItemPosition();
2662 int index
= GetNextSelectedItem(pos
);
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);
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());
2679 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_CurrentVersion
,
2680 *filepath
,m_CurrentVersion
+_T("~1"));
2684 { // The add went ok, but we now need to run through the selected items again
2685 // and update their status
2686 POSITION pos
= GetFirstSelectedItemPosition();
2688 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2690 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2695 cmd
.Format(_T("git.exe add \"%s\""),path
->GetGitPathString());
2697 if(!g_Git
.Run(cmd
,&output
,CP_ACP
))
2699 path
->m_Action
= CTGitPath::LOGACTIONS_ADDED
;
2700 SetEntryCheck(path
,index
,true);
2701 SetItemGroup(index
,0);
2702 this->m_StatusFileList
.AddPath(*path
);
2703 this->m_UnRevFileList
.RemoveItem(*path
);
2704 this->m_IgnoreFileList
.RemoveItem(*path
);
2705 Show(this->m_dwShow
,0,true,true);
2715 sCmd
.Format(_T("\"%s\" /command:blame /path:\"%s\""),
2716 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath());
2718 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
2725 sCmd
.Format(_T("\"%s\" /command:log /path:\"%s\""),
2726 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath());
2728 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
2732 case IDSVNLC_EDITCONFLICT
:
2734 CAppUtils::ConflictEdit(*filepath
);
2737 case IDSVNLC_RESOLVECONFLICT
:
2739 if (CMessageBox::Show(m_hWnd
, IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
)==IDYES
)
2741 POSITION pos
= GetFirstSelectedItemPosition();
2745 index
= GetNextSelectedItem(pos
);
2746 CTGitPath
* fentry
=(CTGitPath
*) this->GetItemData(index
);
2750 if ( fentry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
2753 cmd
.Format(_T("git.exe add \"%s\""),fentry
->GetGitPathString());
2754 if(g_Git
.Run(cmd
,&output
,CP_ACP
))
2756 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseSVN"), MB_ICONERROR
);
2759 fentry
->m_Action
|= CTGitPath::LOGACTIONS_MODIFIED
;
2760 fentry
->m_Action
&=~CTGitPath::LOGACTIONS_UNMERGED
;
2765 Show(m_dwShow
, 0, m_bShowFolders
);
2770 case IDSVNLC_IGNORE
:
2772 CTGitPathList ignorelist
;
2773 //std::vector<CString> toremove;
2774 FillListOfSelectedItemPaths(ignorelist
, true);
2777 if(!CAppUtils::IgnoreFile(ignorelist
,false))
2780 for(int i
=0;i
<ignorelist
.GetCount();i
++)
2782 int nListboxEntries
= GetItemCount();
2783 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2785 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2786 if (path
->GetGitPathString()==ignorelist
[i
].GetGitPathString())
2788 RemoveListEntry(nItem
);
2796 CTSVNPathList ignorelist
;
2797 std::vector
<CString
> toremove
;
2798 FillListOfSelectedItemPaths(ignorelist
, true);
2800 for (int j
=0; j
<ignorelist
.GetCount(); ++j
)
2802 int nListboxEntries
= GetItemCount();
2803 for (int i
=0; i
<nListboxEntries
; ++i
)
2805 if (GetListEntry(i
)->GetPath().IsEquivalentTo(ignorelist
[j
]))
2811 CString name
= CPathUtils::PathPatternEscape(ignorelist
[j
].GetFileOrDirectoryName());
2812 CTSVNPath parentfolder
= ignorelist
[j
].GetContainingDirectory();
2813 SVNProperties
props(parentfolder
, SVNRev::REV_WC
, false);
2815 for (int i
=0; i
<props
.GetCount(); i
++)
2817 CString
propname(props
.GetItemName(i
).c_str());
2818 if (propname
.CompareNoCase(_T("git:ignore"))==0)
2821 // treat values as normal text even if they're not
2822 value
= (char *)props
.GetItemValue(i
).c_str();
2825 if (value
.IsEmpty())
2829 value
= value
.Trim("\n\r");
2834 if (!props
.Add(_T("git:ignore"), (LPCSTR
)value
))
2837 temp
.Format(IDS_ERR_FAILEDIGNOREPROPERTY
, (LPCTSTR
)name
);
2838 CMessageBox::Show(this->m_hWnd
, temp
, _T("TortoiseSVN"), MB_ICONERROR
);
2841 if (GetCheck(selIndex
))
2845 // now, if we ignored a folder, remove all its children
2846 if (ignorelist
[j
].IsDirectory())
2848 for (int i
=0; i
<(int)m_arListArray
.size(); ++i
)
2850 FileEntry
* entry
= GetListEntry(i
);
2851 if (entry
->status
== git_wc_status_unversioned
)
2853 if (!ignorelist
[j
].IsEquivalentTo(entry
->GetPath())&&(ignorelist
[j
].IsAncestorOf(entry
->GetPath())))
2855 entry
->status
= git_wc_status_ignored
;
2856 entry
->textstatus
= git_wc_status_ignored
;
2859 toremove
.push_back(entry
->GetPath().GetSVNPathString());
2865 CTSVNPath basepath
= m_arStatusArray
[m_arListArray
[selIndex
]]->basepath
;
2867 FileEntry
* entry
= m_arStatusArray
[m_arListArray
[selIndex
]];
2868 if ( entry
->status
== git_wc_status_unversioned
) // keep "deleted" items
2869 toremove
.push_back(entry
->GetPath().GetSVNPathString());
2871 if (!m_bIgnoreRemoveOnly
)
2874 git_wc_status2_t
* s
;
2876 s
= status
.GetFirstFileStatus(parentfolder
, gitPath
, false, git_depth_empty
);
2877 // first check if the folder isn't already present in the list
2878 bool bFound
= false;
2879 nListboxEntries
= GetItemCount();
2880 for (int i
=0; i
<nListboxEntries
; ++i
)
2882 FileEntry
* entry
= GetListEntry(i
);
2883 if (entry
->path
.IsEquivalentTo(gitPath
))
2893 FileEntry
* entry
= new FileEntry();
2894 entry
->path
= gitPath
;
2895 entry
->basepath
= basepath
;
2896 entry
->status
= SVNStatus::GetMoreImportant(s
->text_status
, s
->prop_status
);
2897 entry
->textstatus
= s
->text_status
;
2898 entry
->propstatus
= s
->prop_status
;
2899 entry
->remotestatus
= SVNStatus::GetMoreImportant(s
->repos_text_status
, s
->repos_prop_status
);
2900 entry
->remotetextstatus
= s
->repos_text_status
;
2901 entry
->remotepropstatus
= s
->repos_prop_status
;
2902 entry
->inunversionedfolder
= FALSE
;
2903 entry
->checked
= true;
2904 entry
->inexternal
= false;
2905 entry
->direct
= false;
2906 entry
->isfolder
= true;
2907 entry
->last_commit_date
= 0;
2908 entry
->last_commit_rev
= 0;
2909 entry
->remoterev
= 0;
2914 entry
->url
= CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s
->entry
->url
));
2917 if (s
->entry
&& s
->entry
->present_props
)
2919 entry
->present_props
= s
->entry
->present_props
;
2921 m_arStatusArray
.push_back(entry
);
2922 m_arListArray
.push_back(m_arStatusArray
.size()-1);
2923 AddEntry(entry
, langID
, GetItemCount());
2928 for (std::vector
<CString
>::iterator it
= toremove
.begin(); it
!= toremove
.end(); ++it
)
2930 int nListboxEntries
= GetItemCount();
2931 for (int i
=0; i
<nListboxEntries
; ++i
)
2933 if (GetListEntry(i
)->path
.GetSVNPathString().Compare(*it
)==0)
2944 case IDSVNLC_IGNOREMASK
:
2947 CString ext
=filepath
->GetFileExtension();
2948 CTGitPathList ignorelist
;
2949 FillListOfSelectedItemPaths(ignorelist
, true);
2952 CAppUtils::IgnoreFile(ignorelist
,true);
2953 common
=ignorelist
.GetCommonRoot().GetGitPathString();
2955 for (int i
=0; i
< GetItemCount(); ++i
)
2957 CTGitPath
*path
=(CTGitPath
*)GetItemData(i
);
2958 if(!( path
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
2960 if( path
->GetGitPathString().Left(common
.GetLength()) == common
)
2962 if (path
->GetFileExtension()==ext
)
2965 i
--; // remove index i at item, new one will replace.
2973 std::set
<CTSVNPath
> parentlist
;
2974 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
2976 parentlist
.insert(ignorelist
[i
].GetContainingDirectory());
2978 std::set
<CTSVNPath
>::iterator it
;
2979 std::vector
<CString
> toremove
;
2981 for (it
= parentlist
.begin(); it
!= parentlist
.end(); ++it
)
2983 CTSVNPath parentFolder
= (*it
).GetDirectory();
2984 SVNProperties
props(parentFolder
, SVNRev::REV_WC
, false);
2986 for (int i
=0; i
<props
.GetCount(); i
++)
2988 CString
propname(props
.GetItemName(i
).c_str());
2989 if (propname
.CompareNoCase(_T("git:ignore"))==0)
2992 // treat values as normal text even if they're not
2993 value
= (char *)props
.GetItemValue(i
).c_str();
2996 if (value
.IsEmpty())
3000 value
= value
.Trim("\n\r");
3005 if (!props
.Add(_T("git:ignore"), (LPCSTR
)value
))
3008 temp
.Format(IDS_ERR_FAILEDIGNOREPROPERTY
, (LPCTSTR
)name
);
3009 CMessageBox::Show(this->m_hWnd
, temp
, _T("TortoiseSVN"), MB_ICONERROR
);
3014 int nListboxEntries
= GetItemCount();
3015 for (int i
=0; i
<nListboxEntries
; ++i
)
3017 FileEntry
* entry
= GetListEntry(i
);
3018 ASSERT(entry
!= NULL
);
3021 if (basepath
.IsEmpty())
3022 basepath
= entry
->basepath
;
3023 // since we ignored files with a mask (e.g. *.exe)
3024 // we have to find find all files in the same
3025 // folder (IsAncestorOf() returns TRUE for _all_ children,
3026 // not just the immediate ones) which match the
3027 // mask and remove them from the list too.
3028 if ((entry
->status
== git_wc_status_unversioned
)&&(parentFolder
.IsAncestorOf(entry
->path
)))
3030 CString f
= entry
->path
.GetSVNPathString();
3031 if (f
.Mid(parentFolder
.GetSVNPathString().GetLength()).Find('/')<=0)
3033 if (CStringUtils::WildCardMatch(name
, f
))
3038 toremove
.push_back(f
);
3043 if (!m_bIgnoreRemoveOnly
)
3046 git_wc_status2_t
* s
;
3048 s
= status
.GetFirstFileStatus(parentFolder
, gitPath
, false, git_depth_empty
);
3051 // first check if the folder isn't already present in the list
3052 bool bFound
= false;
3053 for (int i
=0; i
<nListboxEntries
; ++i
)
3055 FileEntry
* entry
= GetListEntry(i
);
3056 if (entry
->path
.IsEquivalentTo(gitPath
))
3064 FileEntry
* entry
= new FileEntry();
3065 entry
->path
= gitPath
;
3066 entry
->basepath
= basepath
;
3067 entry
->status
= SVNStatus::GetMoreImportant(s
->text_status
, s
->prop_status
);
3068 entry
->textstatus
= s
->text_status
;
3069 entry
->propstatus
= s
->prop_status
;
3070 entry
->remotestatus
= SVNStatus::GetMoreImportant(s
->repos_text_status
, s
->repos_prop_status
);
3071 entry
->remotetextstatus
= s
->repos_text_status
;
3072 entry
->remotepropstatus
= s
->repos_prop_status
;
3073 entry
->inunversionedfolder
= false;
3074 entry
->checked
= true;
3075 entry
->inexternal
= false;
3076 entry
->direct
= false;
3077 entry
->isfolder
= true;
3078 entry
->last_commit_date
= 0;
3079 entry
->last_commit_rev
= 0;
3080 entry
->remoterev
= 0;
3085 entry
->url
= CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s
->entry
->url
));
3088 if (s
->entry
&& s
->entry
->present_props
)
3090 entry
->present_props
= s
->entry
->present_props
;
3092 m_arStatusArray
.push_back(entry
);
3093 m_arListArray
.push_back(m_arStatusArray
.size()-1);
3094 AddEntry(entry
, langID
, GetItemCount());
3100 for (std::vector
<CString
>::iterator it
= toremove
.begin(); it
!= toremove
.end(); ++it
)
3102 int nListboxEntries
= GetItemCount();
3103 for (int i
=0; i
<nListboxEntries
; ++i
)
3105 if (GetListEntry(i
)->path
.GetSVNPathString().Compare(*it
)==0)
3117 case IDSVNLC_REVERT
:
3119 // If at least one item is not in the status "added"
3120 // we ask for a confirmation
3121 BOOL bConfirm
= FALSE
;
3122 POSITION pos
= GetFirstSelectedItemPosition();
3124 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3126 //FileEntry * fentry = GetListEntry(index);
3127 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
3128 if(fentry
&& fentry
->m_Action
&CTGitPath::LOGACTIONS_MODIFIED
)
3136 str
.Format(IDS_PROC_WARNREVERT
,GetSelectedCount());
3138 if (!bConfirm
|| CMessageBox::Show(this->m_hWnd
, str
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
3140 CTGitPathList targetList
;
3141 FillListOfSelectedItemPaths(targetList
);
3143 // make sure that the list is reverse sorted, so that
3144 // children are removed before any parents
3145 targetList
.SortByPathname(true);
3147 // put all reverted files in the trashbin, except the ones with 'added'
3148 // status because they are not restored by the revert.
3149 CTGitPathList delList
;
3150 POSITION pos
= GetFirstSelectedItemPosition();
3152 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3154 CTGitPath
*entry
=(CTGitPath
*)GetItemData(index
);
3155 if (entry
&&(!(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)))
3156 delList
.AddPath(*entry
);
3158 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
3159 delList
.DeleteAllFiles(true);
3161 if (g_Git
.Revert(targetList
))
3163 CMessageBox::Show(this->m_hWnd
, _T("Revert Fail"), _T("TortoiseSVN"), MB_ICONERROR
);
3167 for(int i
=0;i
<targetList
.GetCount();i
++)
3169 int nListboxEntries
= GetItemCount();
3170 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
3172 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
3173 if (path
->GetGitPathString()==targetList
[i
].GetGitPathString())
3175 RemoveListEntry(nItem
);
3182 Show(m_dwShow
, 0, m_bShowFolders
);
3190 CopySelectedEntriesToClipboard(0);
3192 case IDSVNLC_COPYEXT
:
3193 CopySelectedEntriesToClipboard((DWORD
)-1);
3196 case IDSVNLC_SAVEAS
:
3197 FileSaveAs(filepath
);
3200 case IDSVNLC_REVERTTOREV
:
3201 RevertSelectedItemToVersion();
3204 case IDSVNLC_PROPERTIES
:
3206 CTSVNPathList targetList
;
3207 FillListOfSelectedItemPaths(targetList
);
3208 CEditPropertiesDlg dlg
;
3209 dlg
.SetPathList(targetList
);
3211 if (dlg
.HasChanged())
3213 // since the user might have changed/removed/added
3214 // properties recursively, we don't really know
3215 // which items have changed their status.
3216 // So tell the parent to do a refresh.
3217 CWnd
* pParent
= GetParent();
3218 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3220 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
3225 case IDSVNLC_COMMIT
:
3227 CTSVNPathList targetList
;
3228 FillListOfSelectedItemPaths(targetList
);
3229 CTSVNPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
3230 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
3231 CString commandline
= CPathUtils::GetAppDirectory();
3232 commandline
+= _T("TortoiseProc.exe /command:commit /pathfile:\"");
3233 commandline
+= tempFile
.GetWinPathString();
3234 commandline
+= _T("\"");
3235 commandline
+= _T(" /deletepathfile");
3236 CAppUtils::LaunchApplication(commandline
, NULL
, false);
3240 case IDSVNLC_COMPAREWC
:
3242 POSITION pos
= GetFirstSelectedItemPosition();
3245 int index
= GetNextSelectedItem(pos
);
3246 FileEntry
* entry
= GetListEntry(index
);
3247 ASSERT(entry
!= NULL
);
3250 SVNDiff
diff(NULL
, m_hWnd
, true);
3251 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
3252 git_revnum_t baseRev
= entry
->Revision
;
3253 diff
.DiffFileAgainstBase(
3254 entry
->path
, baseRev
, entry
->textstatus
, entry
->propstatus
);
3258 case IDSVNLC_GNUDIFF1
:
3260 SVNDiff
diff(NULL
, this->m_hWnd
, true);
3262 if (entry
->remotestatus
<= git_wc_status_normal
)
3263 CAppUtils::StartShowUnifiedDiff(m_hWnd
, entry
->path
, SVNRev::REV_BASE
, entry
->path
, SVNRev::REV_WC
);
3265 CAppUtils::StartShowUnifiedDiff(m_hWnd
, entry
->path
, SVNRev::REV_WC
, entry
->path
, SVNRev::REV_HEAD
);
3268 case IDSVNLC_UPDATE
:
3270 CTSVNPathList targetList
;
3271 FillListOfSelectedItemPaths(targetList
);
3272 bool bAllExist
= true;
3273 for (int i
=0; i
<targetList
.GetCount(); ++i
)
3275 if (!targetList
[i
].Exists())
3283 CSVNProgressDlg dlg
;
3284 dlg
.SetCommand(CSVNProgressDlg::SVNProgress_Update
);
3285 dlg
.SetPathList(targetList
);
3286 dlg
.SetRevision(SVNRev::REV_HEAD
);
3291 CString sTempFile
= CTempFiles::Instance().GetTempFilePath(false).GetWinPathString();
3292 targetList
.WriteToFile(sTempFile
, false);
3294 sCmd
.Format(_T("\"%s\" /command:update /rev /pathfile:\"%s\" /deletepathfile"),
3295 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR
)sTempFile
);
3297 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
3302 case IDSVNLC_REMOVE
:
3305 CTSVNPathList itemsToRemove
;
3306 FillListOfSelectedItemPaths(itemsToRemove
);
3308 // We must sort items before removing, so that files are always removed
3309 // *before* their parents
3310 itemsToRemove
.SortByPathname(true);
3312 bool bSuccess
= false;
3313 if (git
.Remove(itemsToRemove
, FALSE
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)))
3319 if ((git
.Err
->apr_err
== SVN_ERR_UNVERSIONED_RESOURCE
) ||
3320 (git
.Err
->apr_err
== SVN_ERR_CLIENT_MODIFIED
))
3322 CString msg
, yes
, no
, yestoall
;
3323 msg
.Format(IDS_PROC_REMOVEFORCE
, (LPCTSTR
)git
.GetLastErrorMessage());
3324 yes
.LoadString(IDS_MSGBOX_YES
);
3325 no
.LoadString(IDS_MSGBOX_NO
);
3326 yestoall
.LoadString(IDS_PROC_YESTOALL
);
3327 UINT ret
= CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseSVN"), 2, IDI_ERROR
, yes
, no
, yestoall
);
3328 if ((ret
== 1)||(ret
==3))
3330 if (!git
.Remove(itemsToRemove
, TRUE
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)))
3332 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR
);
3339 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR
);
3343 // The remove went ok, but we now need to run through the selected items again
3344 // and update their status
3345 POSITION pos
= GetFirstSelectedItemPosition();
3347 std::vector
<int> entriesToRemove
;
3348 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3350 FileEntry
* e
= GetListEntry(index
);
3352 ((e
->textstatus
== git_wc_status_unversioned
)||
3353 (e
->textstatus
== git_wc_status_none
)||
3354 (e
->textstatus
== git_wc_status_ignored
)))
3356 if (GetCheck(index
))
3359 entriesToRemove
.push_back(index
);
3363 e
->textstatus
= git_wc_status_deleted
;
3364 e
->status
= git_wc_status_deleted
;
3365 SetEntryCheck(e
,index
,true);
3368 for (std::vector
<int>::reverse_iterator it
= entriesToRemove
.rbegin(); it
!= entriesToRemove
.rend(); ++it
)
3370 RemoveListEntry(*it
);
3374 Show(m_dwShow
, 0, m_bShowFolders
);
3378 case IDSVNLC_DELETE
:
3380 CTSVNPathList pathlist
;
3381 FillListOfSelectedItemPaths(pathlist
);
3382 pathlist
.RemoveChildren();
3384 for (INT_PTR i
=0; i
<pathlist
.GetCount(); ++i
)
3386 filelist
+= pathlist
[i
].GetWinPathString();
3387 filelist
+= _T("|");
3389 filelist
+= _T("|");
3390 int len
= filelist
.GetLength();
3391 TCHAR
* buf
= new TCHAR
[len
+2];
3392 _tcscpy_s(buf
, len
+2, filelist
);
3393 for (int i
=0; i
<len
; ++i
)
3396 SHFILEOPSTRUCT fileop
;
3397 fileop
.hwnd
= this->m_hWnd
;
3398 fileop
.wFunc
= FO_DELETE
;
3401 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
3402 fileop
.lpszProgressTitle
= _T("deleting file");
3403 int result
= SHFileOperation(&fileop
);
3406 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
3409 POSITION pos
= NULL
;
3410 CTSVNPathList deletedlist
; // to store list of deleted folders
3411 while ((pos
= GetFirstSelectedItemPosition()) != 0)
3413 int index
= GetNextSelectedItem(pos
);
3414 if (GetCheck(index
))
3417 FileEntry
* fentry
= GetListEntry(index
);
3418 if ((fentry
)&&(fentry
->isfolder
))
3419 deletedlist
.AddPath(fentry
->path
);
3420 RemoveListEntry(index
);
3422 // now go through the list of deleted folders
3423 // and remove all their children from the list too!
3424 int nListboxEntries
= GetItemCount();
3425 for (int folderindex
= 0; folderindex
< deletedlist
.GetCount(); ++folderindex
)
3427 CTSVNPath folderpath
= deletedlist
[folderindex
];
3428 for (int i
=0; i
<nListboxEntries
; ++i
)
3430 FileEntry
* entry
= GetListEntry(i
);
3431 if (folderpath
.IsAncestorOf(entry
->path
))
3433 RemoveListEntry(i
--);
3447 CTSVNPathList itemsToAdd
;
3448 FillListOfSelectedItemPaths(itemsToAdd
);
3450 // We must sort items before adding, so that folders are always added
3451 // *before* any of their children
3452 itemsToAdd
.SortByPathname();
3454 ProjectProperties props
;
3455 props
.ReadPropsPathList(itemsToAdd
);
3456 if (git
.Add(itemsToAdd
, &props
, git_depth_empty
, TRUE
, TRUE
, TRUE
))
3458 // The add went ok, but we now need to run through the selected items again
3459 // and update their status
3460 POSITION pos
= GetFirstSelectedItemPosition();
3462 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3464 FileEntry
* e
= GetListEntry(index
);
3465 e
->textstatus
= git_wc_status_added
;
3466 e
->propstatus
= git_wc_status_none
;
3467 e
->status
= git_wc_status_added
;
3468 SetEntryCheck(e
,index
,true);
3473 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR
);
3476 Show(m_dwShow
, 0, m_bShowFolders
);
3480 case IDSVNLC_ADD_RECURSIVE
:
3482 CTSVNPathList itemsToAdd
;
3483 FillListOfSelectedItemPaths(itemsToAdd
);
3486 dlg
.m_pathList
= itemsToAdd
;
3487 if (dlg
.DoModal() == IDOK
)
3489 if (dlg
.m_pathList
.GetCount() == 0)
3491 CSVNProgressDlg progDlg
;
3492 progDlg
.SetCommand(CSVNProgressDlg::SVNProgress_Add
);
3493 progDlg
.SetPathList(dlg
.m_pathList
);
3494 ProjectProperties props
;
3495 props
.ReadPropsPathList(dlg
.m_pathList
);
3496 progDlg
.SetProjectProperties(props
);
3497 progDlg
.SetItemCount(dlg
.m_pathList
.GetCount());
3501 CWnd
* pParent
= GetParent();
3502 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3504 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
3510 case IDSVNLC_REPAIRMOVE
:
3512 POSITION pos
= GetFirstSelectedItemPosition();
3513 int index
= GetNextSelectedItem(pos
);
3514 FileEntry
* entry1
= NULL
;
3515 FileEntry
* entry2
= NULL
;
3518 entry1
= GetListEntry(index
);
3519 git_wc_status_kind status1
= git_wc_status_none
;
3520 git_wc_status_kind status2
= git_wc_status_none
;
3523 status1
= entry1
->status
;
3524 index
= GetNextSelectedItem(pos
);
3527 entry2
= GetListEntry(index
);
3530 status2
= entry2
->status
;
3531 if (status2
== git_wc_status_missing
&& status1
== git_wc_status_unversioned
)
3533 FileEntry
* tempentry
= entry1
;
3537 // entry1 was renamed to entry2 but outside of Subversion
3538 // fix this by moving entry2 back to entry1 first,
3539 // then do an git-move from entry1 to entry2
3540 if (MoveFile(entry2
->GetPath().GetWinPath(), entry1
->GetPath().GetWinPath()))
3543 if (!git
.Move(CTSVNPathList(entry1
->GetPath()), entry2
->GetPath(), TRUE
))
3545 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR
);
3549 // check the previously unversioned item
3550 entry1
->checked
= true;
3551 // fixing the move was successful. We have to adjust the new status of the
3553 // Since we don't know if the moved/renamed file had local modifications or not,
3554 // we can't guess the new status. That means we have to refresh...
3555 CWnd
* pParent
= GetParent();
3556 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3558 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
3565 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
3566 FORMAT_MESSAGE_FROM_SYSTEM
|
3567 FORMAT_MESSAGE_IGNORE_INSERTS
,
3570 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
3575 MessageBox((LPCTSTR
)lpMsgBuf
, _T("Error"), MB_OK
| MB_ICONINFORMATION
);
3576 LocalFree( lpMsgBuf
);
3584 case IDSVNLC_REMOVEFROMCS
:
3586 CTSVNPathList changelistItems
;
3587 FillListOfSelectedItemPaths(changelistItems
);
3590 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
3592 // The changelists were removed, but we now need to run through the selected items again
3593 // and update their changelist
3594 POSITION pos
= GetFirstSelectedItemPosition();
3596 std::vector
<int> entriesToRemove
;
3597 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3599 FileEntry
* e
= GetListEntry(index
);
3602 e
->changelist
.Empty();
3603 if (e
->status
== git_wc_status_normal
)
3605 // remove the entry completely
3606 entriesToRemove
.push_back(index
);
3609 SetItemGroup(index
, 0);
3612 for (std::vector
<int>::reverse_iterator it
= entriesToRemove
.rbegin(); it
!= entriesToRemove
.rend(); ++it
)
3614 RemoveListEntry(*it
);
3616 // TODO: Should we go through all entries here and check if we also could
3617 // remove the changelist from m_changelists ?
3621 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR
);
3626 case IDSVNLC_CREATEIGNORECS
:
3627 CreateChangeList(SVNSLC_IGNORECHANGELIST
);
3629 case IDSVNLC_CREATECS
:
3631 CCreateChangelistDlg dlg
;
3632 if (dlg
.DoModal() == IDOK
)
3634 CreateChangeList(dlg
.m_sName
);
3640 if (cmd
< IDSVNLC_MOVETOCS
)
3642 CTSVNPathList changelistItems
;
3643 FillListOfSelectedItemPaths(changelistItems
);
3645 // find the changelist name
3646 CString sChangelist
;
3647 int cmdID
= IDSVNLC_MOVETOCS
;
3649 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
3651 if ((it
->first
.Compare(SVNSLC_IGNORECHANGELIST
))&&(entry
->changelist
.Compare(it
->first
)))
3655 sChangelist
= it
->first
;
3660 if (!sChangelist
.IsEmpty())
3663 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
3665 // The changelists were moved, but we now need to run through the selected items again
3666 // and update their changelist
3667 POSITION pos
= GetFirstSelectedItemPosition();
3669 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3671 FileEntry
* e
= GetListEntry(index
);
3672 e
->changelist
= sChangelist
;
3675 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
3676 SetItemGroup(index
, m_changelists
[e
->changelist
]);
3678 SetItemGroup(index
, 0);
3684 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR
);
3694 AfxGetApp()->DoWaitCursor(-1);
3695 GetStatisticsString();
3696 int iItemCountAfterMenuCmd
= GetItemCount();
3697 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
3699 // CWnd* pParent = GetParent();
3700 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3702 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
3705 } // if (popup.CreatePopupMenu())
3706 } // if (selIndex >= 0)
3710 void CGitStatusListCtrl::OnContextMenuHeader(CWnd
* pWnd
, CPoint point
)
3712 bool XPorLater
= false;
3713 OSVERSIONINFOEX inf
;
3714 SecureZeroMemory(&inf
, sizeof(OSVERSIONINFOEX
));
3715 inf
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
3716 GetVersionEx((OSVERSIONINFO
*)&inf
);
3717 WORD fullver
= MAKEWORD(inf
.dwMinorVersion
, inf
.dwMajorVersion
);
3718 if (fullver
>= 0x0501)
3721 CHeaderCtrl
* pHeaderCtrl
= (CHeaderCtrl
*)pWnd
;
3722 if ((point
.x
== -1) && (point
.y
== -1))
3725 pHeaderCtrl
->GetItemRect(0, &rect
);
3726 ClientToScreen(&rect
);
3727 point
= rect
.CenterPoint();
3729 Locker
lock(m_critSec
);
3731 if (popup
.CreatePopupMenu())
3733 int columnCount
= m_ColumnManager
.GetColumnCount();
3736 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
3737 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
3739 // build control menu
3743 temp
.LoadString(IDS_STATUSLIST_SHOWGROUPS
);
3744 popup
.AppendMenu(IsGroupViewEnabled() ? uCheckedFlags
: uUnCheckedFlags
, columnCount
, temp
);
3747 if (m_ColumnManager
.AnyUnusedProperties())
3749 temp
.LoadString(IDS_STATUSLIST_REMOVEUNUSEDPROPS
);
3750 popup
.AppendMenu(uUnCheckedFlags
, columnCount
+1, temp
);
3753 temp
.LoadString(IDS_STATUSLIST_RESETCOLUMNORDER
);
3754 popup
.AppendMenu(uUnCheckedFlags
, columnCount
+2, temp
);
3755 popup
.AppendMenu(MF_SEPARATOR
);
3759 for (int i
= 1; i
< SVNSLC_NUMCOLUMNS
; ++i
)
3761 popup
.AppendMenu ( m_ColumnManager
.IsVisible(i
)
3765 , m_ColumnManager
.GetName(i
));
3768 // user-prop columns:
3769 // find relevant ones and sort 'em
3771 std::map
<CString
, int> sortedProps
;
3772 for (int i
= SVNSLC_NUMCOLUMNS
; i
< columnCount
; ++i
)
3773 if (m_ColumnManager
.IsRelevant(i
))
3774 sortedProps
[m_ColumnManager
.GetName(i
)] = i
;
3776 if (!sortedProps
.empty())
3778 // add 'em to the menu
3780 popup
.AppendMenu(MF_SEPARATOR
);
3782 typedef std::map
<CString
, int>::const_iterator CIT
;
3783 for ( CIT iter
= sortedProps
.begin(), end
= sortedProps
.end()
3787 popup
.AppendMenu ( m_ColumnManager
.IsVisible(iter
->second
)
3795 // show menu & let user pick an entry
3797 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
3798 if ((cmd
>= 1)&&(cmd
< columnCount
))
3800 m_ColumnManager
.SetVisible (cmd
, !m_ColumnManager
.IsVisible(cmd
));
3802 else if (cmd
== columnCount
)
3804 EnableGroupView(!IsGroupViewEnabled());
3806 else if (cmd
== columnCount
+1)
3808 m_ColumnManager
.RemoveUnusedProps();
3810 else if (cmd
== columnCount
+2)
3812 m_ColumnManager
.ResetColumns (m_dwDefaultColumns
);
3817 void CGitStatusListCtrl::OnContextMenu(CWnd
* pWnd
, CPoint point
)
3822 OnContextMenuList(pWnd
, point
);
3823 } // if (pWnd == this)
3824 else if (pWnd
== GetHeaderCtrl())
3826 OnContextMenuHeader(pWnd
, point
);
3830 void CGitStatusListCtrl::CreateChangeList(const CString
& name
)
3833 CTGitPathList changelistItems
;
3834 FillListOfSelectedItemPaths(changelistItems
);
3836 if (git
.AddToChangeList(changelistItems
, name
, git_depth_empty
))
3838 TCHAR groupname
[1024];
3840 grp
.cbSize
= sizeof(LVGROUP
);
3841 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3842 _tcsncpy_s(groupname
, 1024, name
, 1023);
3843 grp
.pszHeader
= groupname
;
3844 grp
.iGroupId
= (int)m_changelists
.size();
3845 grp
.uAlign
= LVGA_HEADER_LEFT
;
3846 m_changelists
[name
] = InsertGroup(-1, &grp
);
3848 PrepareGroups(true);
3850 POSITION pos
= GetFirstSelectedItemPosition();
3852 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3854 FileEntry
* e
= GetListEntry(index
);
3855 e
->changelist
= name
;
3856 SetEntryCheck(e
, index
, FALSE
);
3859 for (index
= 0; index
< GetItemCount(); ++index
)
3861 FileEntry
* e
= GetListEntry(index
);
3862 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
3863 SetItemGroup(index
, m_changelists
[e
->changelist
]);
3865 SetItemGroup(index
, 0);
3870 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("Tortoisegit"), MB_ICONERROR
);
3875 void CGitStatusListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3878 Locker
lock(m_critSec
);
3879 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
3884 if (pNMLV
->iItem
< 0)
3886 if (!IsGroupViewEnabled())
3889 DWORD ptW
= GetMessagePos();
3890 pt
.x
= GET_X_LPARAM(ptW
);
3891 pt
.y
= GET_Y_LPARAM(ptW
);
3892 ScreenToClient(&pt
);
3893 int group
= GetGroupFromPoint(&pt
);
3896 // check/uncheck the whole group depending on the check-state
3897 // of the first item in the group
3899 bool bCheck
= false;
3900 bool bFirst
= false;
3902 for (int i
=0; i
<GetItemCount(); ++i
)
3904 SecureZeroMemory(&lv
, sizeof(LVITEM
));
3905 lv
.mask
= LVIF_GROUPID
;
3908 if (lv
.iGroupId
== group
)
3910 FileEntry
* entry
= GetListEntry(i
);
3913 bCheck
= !GetCheck(i
);
3918 bool bOldCheck
= !!GetCheck(i
);
3919 SetEntryCheck(entry
, i
, bCheck
);
3920 if (bCheck
!= bOldCheck
)
3930 GetStatisticsString();
3936 // FileEntry * entry = GetListEntry(pNMLV->iItem);
3939 // if (entry->isConflicted)
3941 // gitDiff::StartConflictEditor(entry->GetPath());
3945 StartDiff(pNMLV
->iItem
);
3950 void CGitStatusListCtrl::StartDiffWC(int fileindex
)
3956 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
3959 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3961 CGitDiff::Diff(&file1
,&file1
,
3962 CString(GIT_REV_ZERO
),
3967 void CGitStatusListCtrl::StartDiff(int fileindex
)
3972 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3974 if(file1
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
3976 file2
.SetFromGit(file1
.GetGitOldPathString());
3982 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
3984 if(!g_Git
.IsInitRepos())
3985 CGitDiff::Diff(&file1
,&file2
,
3986 CString(GIT_REV_ZERO
),
3989 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3990 CString(GIT_REV_ZERO
));
3993 CGitDiff::Diff(&file1
,&file2
,
3995 m_CurrentVersion
+_T("~1"));
4000 FileEntry
* entry
= GetListEntry(fileindex
);
4001 ASSERT(entry
!= NULL
);
4004 if (((entry
->status
== git_wc_status_normal
)&&(entry
->remotestatus
<= git_wc_status_normal
))||
4005 (entry
->status
== git_wc_status_unversioned
)||(entry
->status
== git_wc_status_none
))
4007 int ret
= (int)ShellExecute(this->m_hWnd
, NULL
, entry
->path
.GetWinPath(), NULL
, NULL
, SW_SHOW
);
4008 if (ret
<= HINSTANCE_ERROR
)
4010 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
4011 cmd
+= entry
->path
.GetWinPathString();
4012 CAppUtils::LaunchApplication(cmd
, NULL
, false);
4017 GitDiff
diff(NULL
, m_hWnd
, true);
4018 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
4020 entry
->path
, entry
->textstatus
, entry
->propstatus
,
4021 entry
->remotetextstatus
, entry
->remotepropstatus
);
4025 CString
CGitStatusListCtrl::GetStatisticsString()
4028 CString sNormal
, sAdded
, sDeleted
, sModified
, sConflicted
, sUnversioned
;
4029 WORD langID
= (WORD
)(DWORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4030 TCHAR buf
[MAX_STATUS_STRING_LENGTH
];
4031 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
4033 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
4035 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
4037 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
4039 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
4041 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
4044 sToolTip
.Format(_T("%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d"),
4045 (LPCTSTR
)sNormal
, m_nNormal
,
4046 (LPCTSTR
)sUnversioned
, m_nUnversioned
,
4047 (LPCTSTR
)sModified
, m_nModified
,
4048 (LPCTSTR
)sAdded
, m_nAdded
,
4049 (LPCTSTR
)sDeleted
, m_nDeleted
,
4050 (LPCTSTR
)sConflicted
, m_nConflicted
4053 sStats
.Format(IDS_COMMITDLG_STATISTICSFORMAT
, m_nSelected
, GetItemCount());
4056 m_pStatLabel
->SetWindowText(sStats
);
4059 if (m_pSelectButton
)
4061 if (m_nSelected
== 0)
4062 m_pSelectButton
->SetCheck(BST_UNCHECKED
);
4063 else if (m_nSelected
!= GetItemCount())
4064 m_pSelectButton
->SetCheck(BST_INDETERMINATE
);
4066 m_pSelectButton
->SetCheck(BST_CHECKED
);
4069 if (m_pConfirmButton
)
4071 m_pConfirmButton
->EnableWindow(m_nSelected
>0);
4079 CString
CGitStatusListCtrl::GetCommonDirectory(bool bStrict
)
4083 // not strict means that the selected folder has priority
4084 if (!m_StatusFileList
.GetCommonDirectory().IsEmpty())
4085 return m_StatusFileList
.GetCommonDirectory().GetWinPath();
4088 CTGitPath commonBaseDirectory
;
4089 int nListItems
= GetItemCount();
4090 for (int i
=0; i
<nListItems
; ++i
)
4092 CTGitPath baseDirectory
,*p
= (CTGitPath
*)this->GetItemData(i
);
4096 baseDirectory
= p
->GetDirectory();
4098 if(commonBaseDirectory
.IsEmpty())
4100 commonBaseDirectory
= baseDirectory
;
4104 if (commonBaseDirectory
.GetWinPathString().GetLength() > baseDirectory
.GetWinPathString().GetLength())
4106 if (baseDirectory
.IsAncestorOf(commonBaseDirectory
))
4107 commonBaseDirectory
= baseDirectory
;
4111 return g_Git
.m_CurrentDir
+CString(_T("\\"))+commonBaseDirectory
.GetWinPath();
4114 CTGitPath
CGitStatusListCtrl::GetCommonURL(bool bStrict
)
4116 CTGitPath commonBaseURL
;
4121 // not strict means that the selected folder has priority
4122 if (!m_StatusUrlList
.GetCommonDirectory().IsEmpty())
4123 return m_StatusUrlList
.GetCommonDirectory();
4126 int nListItems
= GetItemCount();
4127 for (int i
=0; i
<nListItems
; ++i
)
4129 const CTGitPath
& baseURL
= CTGitPath(GetListEntry(i
)->GetURL());
4130 if (baseURL
.IsEmpty())
4131 continue; // item has no url
4132 if(commonBaseURL
.IsEmpty())
4134 commonBaseURL
= baseURL
;
4138 if (commonBaseURL
.GetGitPathString().GetLength() > baseURL
.GetGitPathString().GetLength())
4140 if (baseURL
.IsAncestorOf(commonBaseURL
))
4141 commonBaseURL
= baseURL
;
4147 return commonBaseURL
;
4150 void CGitStatusListCtrl::SelectAll(bool bSelect
, bool bIncludeNoCommits
)
4152 CWaitCursor waitCursor
;
4153 // block here so the LVN_ITEMCHANGED messages
4158 int nListItems
= GetItemCount();
4160 m_nSelected
= nListItems
;
4164 for (int i
=0; i
<nListItems
; ++i
)
4166 //FileEntry * entry = GetListEntry(i);
4167 //ASSERT(entry != NULL);
4168 CTGitPath
*path
= (CTGitPath
*) GetItemData(i
);
4171 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
4172 SetEntryCheck(path
,i
,bSelect
);
4175 // unblock before redrawing
4178 GetStatisticsString();
4182 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4184 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
4189 if (GetListEntry(pGetInfoTip
->iItem
>= 0))
4190 if (pGetInfoTip
->cchTextMax
> GetListEntry(pGetInfoTip
->iItem
)->path
.GetGitPathString().GetLength())
4192 if (GetListEntry(pGetInfoTip
->iItem
)->GetRelativeGitPath().Compare(GetListEntry(pGetInfoTip
->iItem
)->path
.GetGitPathString())!= 0)
4193 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, GetListEntry(pGetInfoTip
->iItem
)->path
.GetGitPathString(), pGetInfoTip
->cchTextMax
);
4194 else if (GetStringWidth(GetListEntry(pGetInfoTip
->iItem
)->path
.GetGitPathString()) > GetColumnWidth(pGetInfoTip
->iItem
))
4195 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, GetListEntry(pGetInfoTip
->iItem
)->path
.GetGitPathString(), pGetInfoTip
->cchTextMax
);
4200 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4202 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
4204 // Take the default processing unless we set this to something else below.
4205 *pResult
= CDRF_DODEFAULT
;
4207 // First thing - check the draw stage. If it's the control's prepaint
4208 // stage, then tell Windows we want messages for every item.
4210 switch (pLVCD
->nmcd
.dwDrawStage
)
4213 *pResult
= CDRF_NOTIFYITEMDRAW
;
4215 case CDDS_ITEMPREPAINT
:
4217 // This is the prepaint stage for an item. Here's where we set the
4218 // item's text color. Our return value will tell Windows to draw the
4219 // item itself, but it will use the new color we set here.
4221 // Tell Windows to paint the control itself.
4222 *pResult
= CDRF_DODEFAULT
;
4226 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
4228 if (m_arStatusArray
.size() > (DWORD_PTR
)pLVCD
->nmcd
.dwItemSpec
)
4231 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
4232 CTGitPath
*entry
=(CTGitPath
*)GetItemData((int)pLVCD
->nmcd
.dwItemSpec
);
4238 // black : unversioned, normal
4241 // brown : missing, deleted, replaced
4242 // green : merged (or potential merges)
4243 // red : conflicts or sure conflicts
4244 if(entry
->m_Action
& CTGitPath::LOGACTIONS_GRAY
)
4246 crText
= RGB(128,128,128);
4248 }else if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
4250 crText
= m_Colors
.GetColor(CColors::Conflict
);
4252 }else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_MODIFIED
))
4254 crText
= m_Colors
.GetColor(CColors::Modified
);
4256 }else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
4258 crText
= m_Colors
.GetColor(CColors::Added
);
4260 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
4262 crText
= m_Colors
.GetColor(CColors::DeletedNode
);
4264 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
4266 crText
= m_Colors
.GetColor(CColors::RenamedNode
);
4269 crText
= GetSysColor(COLOR_WINDOWTEXT
);
4271 // Store the color back in the NMLVCUSTOMDRAW struct.
4272 pLVCD
->clrText
= crText
;
4279 BOOL
CGitStatusListCtrl::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
4282 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
4285 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
4287 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
4289 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_WAIT
));
4294 void CGitStatusListCtrl::RemoveListEntry(int index
)
4297 Locker
lock(m_critSec
);
4300 m_arStatusArray
.erase(m_arStatusArray
.begin()+index
);
4303 delete m_arStatusArray
[m_arListArray
[index
]];
4304 m_arStatusArray
.erase(m_arStatusArray
.begin()+m_arListArray
[index
]);
4305 m_arListArray
.erase(m_arListArray
.begin()+index
);
4306 for (int i
=index
; i
< (int)m_arListArray
.size(); ++i
)
4313 ///< Set a checkbox on an entry in the listbox
4314 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
4315 void CGitStatusListCtrl::SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
)
4317 pEntry
->m_Checked
= bCheck
;
4318 SetCheck(listboxIndex
, bCheck
);
4322 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry
* parentEntry
, bool bCheck
)
4325 int nListItems
= GetItemCount();
4326 for (int j
=0; j
< nListItems
; ++j
)
4328 FileEntry
* childEntry
= GetListEntry(j
);
4329 ASSERT(childEntry
!= NULL
);
4330 if (childEntry
== NULL
|| childEntry
== parentEntry
)
4332 if (childEntry
->checked
!= bCheck
)
4334 if (parentEntry
->path
.IsAncestorOf(childEntry
->path
))
4336 SetEntryCheck(childEntry
,j
,bCheck
);
4352 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList
& pathList
)
4356 int nListItems
= GetItemCount();
4357 for (int i
=0; i
< nListItems
; i
++)
4359 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
4360 ASSERT(entry
!= NULL
);
4361 if (entry
->m_Checked
)
4363 pathList
.AddPath(*entry
);
4366 pathList
.SortByPathname();
4371 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
4372 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool bNoIgnored
)
4376 POSITION pos
= GetFirstSelectedItemPosition();
4378 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4380 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
4381 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
4383 pathList
.AddPath(*entry
);
4387 UINT
CGitStatusListCtrl::OnGetDlgCode()
4389 // we want to process the return key and not have that one
4390 // routed to the default pushbutton
4391 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS
;
4394 void CGitStatusListCtrl::OnNMReturn(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
4399 POSITION pos
= GetFirstSelectedItemPosition();
4402 int index
= GetNextSelectedItem(pos
);
4407 void CGitStatusListCtrl::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
4409 // Since we catch all keystrokes (to have the enter key processed here instead
4410 // of routed to the default pushbutton) we have to make sure that other
4411 // keys like Tab and Esc still do what they're supposed to do
4412 // Tab = change focus to next/previous control
4413 // Esc = quit the dialog
4418 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL
, GetKeyState(VK_SHIFT
)&0x8000, 0);
4424 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE
, 0, 0);
4429 CListCtrl::OnKeyDown(nChar
, nRepCnt
, nFlags
);
4432 void CGitStatusListCtrl::PreSubclassWindow()
4434 CListCtrl::PreSubclassWindow();
4435 EnableToolTips(TRUE
);
4436 m_Theme
.SetWindowTheme(GetSafeHwnd(), L
"Explorer", NULL
);
4439 INT_PTR
CGitStatusListCtrl::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4443 row
= CellRectFromPoint(point
, &cellrect
, &col
);
4450 pTI
->uId
= (UINT
)((row
<<10)+(col
&0x3ff)+1);
4451 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4453 pTI
->rect
= cellrect
;
4458 int CGitStatusListCtrl::CellRectFromPoint(CPoint
& point
, RECT
*cellrect
, int *col
) const
4462 // Make sure that the ListView is in LVS_REPORT
4463 if ((GetWindowLong(m_hWnd
, GWL_STYLE
) & LVS_TYPEMASK
) != LVS_REPORT
)
4466 // Get the top and bottom row visible
4467 int row
= GetTopIndex();
4468 int bottom
= row
+ GetCountPerPage();
4469 if (bottom
> GetItemCount())
4470 bottom
= GetItemCount();
4472 // Get the number of columns
4473 CHeaderCtrl
* pHeader
= (CHeaderCtrl
*)GetDlgItem(0);
4474 int nColumnCount
= pHeader
->GetItemCount();
4476 // Loop through the visible rows
4477 for ( ;row
<=bottom
;row
++)
4479 // Get bounding rect of item and check whether point falls in it.
4481 GetItemRect(row
, &rect
, LVIR_BOUNDS
);
4482 if (rect
.PtInRect(point
))
4484 // Now find the column
4485 for (colnum
= 0; colnum
< nColumnCount
; colnum
++)
4487 int colwidth
= GetColumnWidth(colnum
);
4488 if (point
.x
>= rect
.left
&& point
.x
<= (rect
.left
+ colwidth
))
4491 GetClientRect(&rectClient
);
4494 rect
.right
= rect
.left
+ colwidth
;
4496 // Make sure that the right extent does not exceed
4498 if (rect
.right
> rectClient
.right
)
4499 rect
.right
= rectClient
.right
;
4503 rect
.left
+= colwidth
;
4510 BOOL
CGitStatusListCtrl::OnToolTipText(UINT
/*id*/, NMHDR
*pNMHDR
, LRESULT
*pResult
)
4513 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4515 UINT_PTR nID
= pNMHDR
->idFrom
;
4520 UINT_PTR row
= ((nID
-1) >> 10) & 0x3fffff;
4521 UINT_PTR col
= (nID
-1) & 0x3ff;
4524 return FALSE
; // no custom tooltip for the path, we use the infotip there!
4526 // get the internal column from the visible columns
4527 int internalcol
= 0;
4528 UINT_PTR currentcol
= 0;
4529 for (; (currentcol
!= col
)
4530 && (internalcol
< m_ColumnManager
.GetColumnCount()-1)
4533 if (m_ColumnManager
.IsVisible (internalcol
))
4537 AFX_MODULE_THREAD_STATE
* pModuleThreadState
= AfxGetModuleThreadState();
4538 CToolTipCtrl
* pToolTip
= pModuleThreadState
->m_pToolTip
;
4539 pToolTip
->SendMessage(TTM_SETMAXTIPWIDTH
, 0, 300);
4542 if ((internalcol
== 2)||(internalcol
== 4))
4544 FileEntry
*fentry
= GetListEntry(row
);
4550 url
.Format(IDS_STATUSLIST_COPYFROM
, (LPCTSTR
)CPathUtils::PathUnescape(fentry
->copyfrom_url
), (LONG
)fentry
->copyfrom_rev
);
4551 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)url
, 80);
4554 if (fentry
->switched
)
4557 url
.Format(IDS_STATUSLIST_SWITCHEDTO
, (LPCTSTR
)CPathUtils::PathUnescape(fentry
->url
));
4558 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)url
, 80);
4561 if (fentry
->keeplocal
)
4563 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_KEEPLOCAL
)), 80);
4572 void CGitStatusListCtrl::OnPaint()
4575 if ((m_bBusy
)||(m_bEmpty
))
4580 if (m_sBusy
.IsEmpty())
4581 str
.LoadString(IDS_STATUSLIST_BUSYMSG
);
4587 if (m_sEmpty
.IsEmpty())
4588 str
.LoadString(IDS_STATUSLIST_EMPTYMSG
);
4592 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
4594 if (IsWindowEnabled())
4595 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
4597 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
4602 pHC
= GetHeaderCtrl();
4606 pHC
->GetItemRect(0, &rcH
);
4607 rc
.top
+= rcH
.bottom
;
4611 CMyMemDC
memDC(pDC
, &rc
);
4613 memDC
.SetTextColor(clrText
);
4614 memDC
.SetBkColor(clrTextBk
);
4615 memDC
.FillSolidRect(rc
, clrTextBk
);
4617 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
4618 memDC
.DrawText(str
, rc
, DT_CENTER
| DT_VCENTER
|
4619 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
4620 memDC
.SelectObject(oldfont
);
4626 // prevent users from extending our hidden (size 0) columns
4627 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4629 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
4631 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= SVNSLC_NUMCOLUMNS
))
4634 if (m_ColumnManager
.IsVisible (phdr
->iItem
))
4641 // prevent any function from extending our hidden (size 0) columns
4642 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4644 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
4646 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= m_ColumnManager
.GetColumnCount()))
4652 // visible columns may be modified
4654 if (m_ColumnManager
.IsVisible (phdr
->iItem
))
4660 // columns already marked as "invisible" internally may be (re-)sized to 0
4662 if ( (phdr
->pitem
!= NULL
)
4663 && (phdr
->pitem
->mask
== HDI_WIDTH
)
4664 && (phdr
->pitem
->cxy
== 0))
4670 if ( (phdr
->pitem
!= NULL
)
4671 && (phdr
->pitem
->mask
!= HDI_WIDTH
))
4680 void CGitStatusListCtrl::OnDestroy()
4682 SaveColumnWidths(true);
4683 CListCtrl::OnDestroy();
4686 void CGitStatusListCtrl::OnBeginDrag(NMHDR
* /*pNMHDR*/, LRESULT
* pResult
)
4689 Locker
lock(m_critSec
);
4690 CDropFiles dropFiles
; // class for creating DROPFILES struct
4693 POSITION pos
= GetFirstSelectedItemPosition();
4694 while ( (index
= GetNextSelectedItem(pos
)) >= 0 )
4696 FileEntry
* fentry
= m_arStatusArray
[m_arListArray
[index
]];
4697 CTGitPath path
= fentry
->GetPath();
4698 dropFiles
.AddFile( path
.GetWinPathString() );
4701 if ( dropFiles
.GetCount()>0 )
4704 dropFiles
.CreateStructure();
4711 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry
/* = false */)
4713 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
4714 for (int col
= 0; col
<= maxcol
; col
++)
4715 if (m_ColumnManager
.IsVisible (col
))
4716 m_ColumnManager
.ColumnResized (col
);
4718 if (bSaveToRegistry
)
4719 m_ColumnManager
.WriteSettings();
4722 bool CGitStatusListCtrl::EnableFileDrop()
4724 m_bFileDropsEnabled
= true;
4728 bool CGitStatusListCtrl::HasPath(const CTGitPath
& path
)
4731 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
4733 FileEntry
* entry
= m_arStatusArray
[i
];
4734 if (entry
->GetPath().IsEquivalentTo(path
))
4741 bool CGitStatusListCtrl::IsPathShown(const CTGitPath
& path
)
4744 int itemCount
= GetItemCount();
4745 for (int i
=0; i
< itemCount
; i
++)
4747 FileEntry
* entry
= GetListEntry(i
);
4748 if (entry
->GetPath().IsEquivalentTo(path
))
4755 BOOL
CGitStatusListCtrl::PreTranslateMessage(MSG
* pMsg
)
4757 if (pMsg
->message
== WM_KEYDOWN
)
4759 switch (pMsg
->wParam
)
4763 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
4765 // select all entries
4766 for (int i
=0; i
<GetItemCount(); ++i
)
4768 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
4777 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
4779 // copy all selected paths to the clipboard
4780 if (GetAsyncKeyState(VK_SHIFT
)&0x8000)
4781 CopySelectedEntriesToClipboard(SVNSLC_COLSTATUS
);
4783 CopySelectedEntriesToClipboard(0);
4791 return CListCtrl::PreTranslateMessage(pMsg
);
4794 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols
)
4797 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
4798 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
4799 WORD langID
= (WORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4804 if (GetSelectedCount() == 0)
4806 // first add the column titles as the first line
4807 temp
.LoadString(IDS_STATUSLIST_COLFILE
);
4810 DWORD selection
= 0;
4811 for (int i
= 0, count
= m_ColumnManager
.GetColumnCount(); i
< count
; ++i
)
4812 if ( ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
4813 || ((dwCols
!= 1) && (i
< 32) && ((dwCols
& (1 << i
)) != 0)))
4815 sClipboard
+= _T("\t") + m_ColumnManager
.GetName(i
);
4818 selection
+= 1 << i
;
4821 sClipboard
+= _T("\r\n");
4823 POSITION pos
= GetFirstSelectedItemPosition();
4825 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4827 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
4831 sClipboard
+= entry
->GetWinPathString();
4832 if (selection
& SVNSLC_COLFILENAME
)
4834 sClipboard
+= _T("\t")+entry
->GetFileOrDirectoryName();
4836 if (selection
& SVNSLC_COLEXT
)
4838 sClipboard
+= _T("\t")+entry
->GetFileExtension();
4841 if (selection
& SVNSLC_COLSTATUS
)
4844 if (entry
->isNested
)
4846 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4850 GitStatus::GetStatusString(hResourceHandle
, entry
->status
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4851 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4852 _tcscat_s(buf
, 100, _T(" (+)"));
4853 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4854 _tcscat_s(buf
, 100, _T(" (s)"));
4855 if ((entry
->status
== entry
->propstatus
)&&
4856 (entry
->status
!= git_wc_status_normal
)&&
4857 (entry
->status
!= git_wc_status_unversioned
)&&
4858 (!GitStatus::IsImportant(entry
->textstatus
)))
4859 _tcscat_s(buf
, 100, ponly
);
4863 sClipboard
+= _T("\t")+entry
->GetActionName();
4866 if (selection
& SVNSLC_COLTEXTSTATUS
)
4869 if (entry
->isNested
)
4871 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4875 GitStatus::GetStatusString(hResourceHandle
, entry
->textstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4876 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4877 _tcscat_s(buf
, 100, _T(" (+)"));
4878 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4879 _tcscat_s(buf
, 100, _T(" (s)"));
4882 sClipboard
+= _T("\t")+temp
;
4886 if (selection
& SVNSLC_COLREMOTESTATUS
)
4888 if (entry
->isNested
)
4890 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4894 GitStatus::GetStatusString(hResourceHandle
, entry
->remotestatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4895 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4896 _tcscat_s(buf
, 100, _T(" (+)"));
4897 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4898 _tcscat_s(buf
, 100, _T(" (s)"));
4899 if ((entry
->remotestatus
== entry
->remotepropstatus
)&&
4900 (entry
->remotestatus
!= git_wc_status_none
)&&
4901 (entry
->remotestatus
!= git_wc_status_normal
)&&
4902 (entry
->remotestatus
!= git_wc_status_unversioned
)&&
4903 (!SVNStatus::IsImportant(entry
->remotetextstatus
)))
4904 _tcscat_s(buf
, 100, ponly
);
4907 sClipboard
+= _T("\t")+temp
;
4909 if (selection
& GitSLC_COLPROPSTATUS
)
4911 if (entry
->isNested
)
4917 GitStatus::GetStatusString(hResourceHandle
, entry
->propstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4918 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4919 _tcscat_s(buf
, 100, _T(" (+)"));
4920 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4921 _tcscat_s(buf
, 100, _T(" (s)"));
4924 sClipboard
+= _T("\t")+temp
;
4926 if (selection
& SVNSLC_COLREMOTETEXT
)
4928 if (entry
->isNested
)
4934 GitStatus::GetStatusString(hResourceHandle
, entry
->remotetextstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4937 sClipboard
+= _T("\t")+temp
;
4939 if (selection
& SVNSLC_COLREMOTEPROP
)
4941 // SVNSLC_COLREMOTEPROP
4942 if (entry
->isNested
)
4948 GitStatus::GetStatusString(hResourceHandle
, entry
->remotepropstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4951 sClipboard
+= _T("\t")+temp
;
4953 if (selection
& SVNSLC_COLURL
)
4954 sClipboard
+= _T("\t")+entry
->url
;
4955 if (selection
& SVNSLC_COLLOCK
)
4957 if (!m_HeadRev
.IsHead())
4959 // we have contacted the repository
4962 // wc repository text
4966 // UID1 "" lock has been broken
4967 // UID1 UID2 lock has been stolen
4968 if (entry
->lock_token
.IsEmpty() || (entry
->lock_token
.Compare(entry
->lock_remotetoken
)==0))
4970 if (entry
->lock_owner
.IsEmpty())
4971 temp
= entry
->lock_remoteowner
;
4973 temp
= entry
->lock_owner
;
4975 else if (entry
->lock_remotetoken
.IsEmpty())
4978 temp
.LoadString(IDS_STATUSLIST_LOCKBROKEN
);
4983 temp
.Format(IDS_STATUSLIST_LOCKSTOLEN
, (LPCTSTR
)entry
->lock_remoteowner
);
4987 temp
= entry
->lock_owner
;
4988 sClipboard
+= _T("\t")+temp
;
4990 if (selection
& SVNSLC_COLLOCKCOMMENT
)
4991 sClipboard
+= _T("\t")+entry
->lock_comment
;
4992 if (selection
& SVNSLC_COLAUTHOR
)
4993 sClipboard
+= _T("\t")+entry
->last_commit_author
;
4994 if (selection
& SVNSLC_COLREVISION
)
4996 temp
.Format(_T("%ld"), entry
->last_commit_rev
);
4997 if (entry
->last_commit_rev
== 0)
4999 sClipboard
+= _T("\t")+temp
;
5001 if (selection
& SVNSLC_COLREMOTEREVISION
)
5003 temp
.Format(_T("%ld"), entry
->remoterev
);
5004 if (entry
->remoterev
== 0)
5006 sClipboard
+= _T("\t")+temp
;
5009 if (selection
& SVNSLC_COLDATE
)
5011 TCHAR datebuf
[SVN_DATE_BUFFER
];
5012 apr_time_t date
= entry
->last_commit_date
;
5013 SVN::formatDate(datebuf
, date
, true);
5018 sClipboard
+= _T("\t")+temp
;
5020 if (selection
& SVNSLC_COLCOPYFROM
)
5022 if (m_sURL
.Compare(entry
->copyfrom_url
.Left(m_sURL
.GetLength()))==0)
5023 temp
= entry
->copyfrom_url
.Mid(m_sURL
.GetLength());
5025 temp
= entry
->copyfrom_url
;
5026 sClipboard
+= _T("\t")+temp
;
5029 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
5033 if ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
5036 = entry
->present_props
[m_ColumnManager
.GetName(i
)];
5037 sClipboard
+= _T("\t") + value
;
5041 if (selection
& SVNSLC_COLADD
)
5043 sClipboard
+= _T("\t")+entry
->m_StatAdd
;
5045 if (selection
& SVNSLC_COLDEL
)
5047 sClipboard
+= _T("\t")+entry
->m_StatDel
;
5050 sClipboard
+= _T("\r\n");
5053 return CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
5059 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
5062 std::set
<CString
> changelists
;
5063 POSITION pos
= GetFirstSelectedItemPosition();
5065 while ((index
= GetNextSelectedItem(pos
)) >= 0)
5067 FileEntry
* entry
= GetListEntry(index
);
5068 if (!entry
->changelist
.IsEmpty())
5069 changelists
.insert(entry
->changelist
);
5071 return changelists
.size();
5076 bool CGitStatusListCtrl::PrepareGroups(bool bForce
/* = false */)
5079 bool bHasGroups
=false;
5080 if ( this->m_UnRevFileList
.GetCount()>0 ||
5081 this->m_IgnoreFileList
.GetCount()>0 || bForce
)
5087 EnableGroupView(bHasGroups
);
5089 TCHAR groupname
[1024];
5095 grp
.cbSize
= sizeof(LVGROUP
);
5096 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
5097 CString
sUnassignedName(_T("Modified File"));
5098 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
5099 grp
.pszHeader
= groupname
;
5100 grp
.iGroupId
= groupindex
;
5101 grp
.uAlign
= LVGA_HEADER_LEFT
;
5102 InsertGroup(groupindex
++, &grp
);
5104 //if(m_UnRevFileList.GetCount()>0)
5106 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)_T("No Version Control"), 1023);
5107 grp
.pszHeader
= groupname
;
5108 grp
.iGroupId
= groupindex
;
5109 grp
.uAlign
= LVGA_HEADER_LEFT
;
5110 InsertGroup(groupindex
++, &grp
);
5113 //if(m_IgnoreFileList.GetCount()>0)
5115 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)_T("Ignored File"), 1023);
5116 grp
.pszHeader
= groupname
;
5117 grp
.iGroupId
= groupindex
;
5118 grp
.uAlign
= LVGA_HEADER_LEFT
;
5119 InsertGroup(groupindex
++, &grp
);
5125 m_bHasIgnoreGroup
= false;
5127 // now add the items which don't belong to a group
5129 grp
.cbSize
= sizeof(LVGROUP
);
5130 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
5131 CString
sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET
));
5132 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
5133 grp
.pszHeader
= groupname
;
5134 grp
.iGroupId
= groupindex
;
5135 grp
.uAlign
= LVGA_HEADER_LEFT
;
5136 InsertGroup(groupindex
++, &grp
);
5138 for (std::map
<CString
,int>::iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
5140 if (it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)!=0)
5143 grp
.cbSize
= sizeof(LVGROUP
);
5144 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
5145 _tcsncpy_s(groupname
, 1024, it
->first
, 1023);
5146 grp
.pszHeader
= groupname
;
5147 grp
.iGroupId
= groupindex
;
5148 grp
.uAlign
= LVGA_HEADER_LEFT
;
5149 it
->second
= InsertGroup(groupindex
++, &grp
);
5152 m_bHasIgnoreGroup
= true;
5155 if (m_bHasIgnoreGroup
)
5157 // and now add the group 'ignore-on-commit'
5158 std::map
<CString
,int>::iterator it
= m_changelists
.find(SVNSLC_IGNORECHANGELIST
);
5159 if (it
!= m_changelists
.end())
5161 grp
.cbSize
= sizeof(LVGROUP
);
5162 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
5163 _tcsncpy_s(groupname
, 1024, SVNSLC_IGNORECHANGELIST
, 1023);
5164 grp
.pszHeader
= groupname
;
5165 grp
.iGroupId
= groupindex
;
5166 grp
.uAlign
= LVGA_HEADER_LEFT
;
5167 it
->second
= InsertGroup(groupindex
, &grp
);
5174 void CGitStatusListCtrl::NotifyCheck()
5176 CWnd
* pParent
= GetParent();
5177 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
5179 pParent
->SendMessage(SVNSLNM_CHECKCHANGED
, m_nSelected
);
5183 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash
,CTGitPathList
*list
)
5187 m_CurrentVersion
=hash
;
5193 count
= list
->GetCount();
5195 if(hash
== GIT_REV_ZERO
)
5197 for(int i
=0;i
<count
;i
++)
5202 if(!g_Git
.IsInitRepos())
5205 cmd
=(_T("git.exe diff-index --raw HEAD --numstat -C -M -z"));
5207 cmd
.Format(_T("git.exe diff-index --raw HEAD --numstat -C -M -z -- \"%s\""),(*list
)[i
].GetGitPathString());
5209 if(g_Git
.Run(cmd
,&cmdout
))
5213 if(g_Git
.Run(_T("git.exe rev-parse --revs-only HEAD"),&strout
,CP_UTF8
))
5215 CMessageBox::Show(NULL
,strout
,_T("TortoiseGit"),MB_OK
);
5218 if(strout
.IsEmpty())
5219 break; //this is initial repositoyr, there are no any history
5221 CMessageBox::Show(NULL
,strout
,_T("TortoiseGit"),MB_OK
);
5227 cmd
=(_T("git.exe diff-index --cached --raw HEAD --numstat -C -M -z"));
5229 cmd
.Format(_T("git.exe diff-index --cached --raw HEAD --numstat -C -M -z -- \"%s\""),(*list
)[i
].GetGitPathString());
5231 g_Git
.Run(cmd
,&cmdout
);
5233 out
.append(cmdout
,0);
5235 else // Init Repository
5238 cmd
=_T("git.exe ls-files -s -t -z");
5240 cmd
.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list
)[i
].GetGitPathString());
5242 g_Git
.Run(cmd
,&cmdout
);
5244 out
.append(cmdout
,0);
5248 if(g_Git
.IsInitRepos())
5250 m_StatusFileList
.ParserFromLsFile(out
);
5251 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
5252 ((CTGitPath
&)(m_StatusFileList
[i
])).m_Action
=CTGitPath::LOGACTIONS_ADDED
;
5255 this->m_StatusFileList
.ParserFromLog(out
);
5257 //handle delete conflict case, when remote : modified, local : deleted.
5258 for(int i
=0;i
<count
;i
++)
5264 cmd
=_T("git.exe ls-files -u -t -z");
5266 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list
)[i
].GetGitPathString());
5268 g_Git
.Run(cmd
,&cmdout
);
5270 CTGitPathList conflictlist
;
5271 conflictlist
.ParserFromLog(cmdout
);
5272 for(int i
=0;i
<conflictlist
.GetCount();i
++)
5274 CTGitPath
*p
=m_StatusFileList
.LookForGitPath(conflictlist
[i
].GetGitPathString());
5276 p
->m_Action
|=CTGitPath::LOGACTIONS_UNMERGED
;
5278 m_StatusFileList
.AddPath(conflictlist
[i
]);
5288 count
= list
->GetCount();
5290 for(int i
=0;i
<count
;i
++)
5295 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash
);
5297 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash
,(*list
)[i
].GetGitPathString());
5299 g_Git
.Run(cmd
,&cmdout
);
5303 this->m_StatusFileList
.ParserFromLog(out
);
5307 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
5309 CTGitPath
* gitpatch
=(CTGitPath
*)&m_StatusFileList
[i
];
5310 gitpatch
->m_Checked
= TRUE
;
5311 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
5314 this->m_bBusy
=FALSE
;
5318 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList
&list
)
5320 m_arStatusArray
.clear();
5321 for(int i
=0;i
<list
.GetCount();i
++)
5323 CTGitPath
* gitpath
=(CTGitPath
*)&list
[i
];
5325 if(gitpath
->m_Action
& CTGitPath::LOGACTIONS_HIDE
)
5328 gitpath
->m_Checked
= TRUE
;
5329 m_arStatusArray
.push_back((CTGitPath
*)&list
[i
]);
5334 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
*List
)
5336 this->m_UnRevFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
,List
);
5337 for(int i
=0;i
<m_UnRevFileList
.GetCount();i
++)
5339 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
5340 gitpatch
->m_Checked
= FALSE
;
5341 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
5346 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList
*List
)
5348 this->m_IgnoreFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
|CTGitPath::LOGACTIONS_IGNORE
,List
);
5349 for(int i
=0;i
<m_IgnoreFileList
.GetCount();i
++)
5351 CTGitPath
* gitpatch
=(CTGitPath
*)&m_IgnoreFileList
[i
];
5352 gitpatch
->m_Checked
= FALSE
;
5353 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
5357 int CGitStatusListCtrl::UpdateFileList(int mask
,bool once
,CTGitPathList
*List
)
5359 if(mask
&CGitStatusListCtrl::FILELIST_MODIFY
)
5361 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_MODIFY
)))
5363 UpdateFileList(git_revnum_t(GIT_REV_ZERO
),List
);
5364 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_MODIFY
;
5367 if(mask
&CGitStatusListCtrl::FILELIST_UNVER
)
5369 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_UNVER
)))
5371 UpdateUnRevFileList(List
);
5372 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
5378 void CGitStatusListCtrl::Clear()
5381 this->DeleteAllItems();
5382 this->m_arListArray
.clear();
5383 this->m_arStatusArray
.clear();
5384 this->m_changelists
.clear();
5386 //////////////////////////////////////////////////////////////////////////
5388 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
)
5390 if(pFmtEtc
->cfFormat
== CF_HDROP
&& medium
.tymed
== TYMED_HGLOBAL
)
5392 HDROP hDrop
= (HDROP
)GlobalLock(medium
.hGlobal
);
5395 TCHAR szFileName
[MAX_PATH
];
5397 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, NULL
, 0);
5400 clientpoint
.x
= pt
.x
;
5401 clientpoint
.y
= pt
.y
;
5402 ScreenToClient(m_hTargetWnd
, &clientpoint
);
5403 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
5405 CTSVNPathList changelistItems
;
5406 for(UINT i
= 0; i
< cFiles
; ++i
)
5408 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
5409 changelistItems
.AddPath(CTSVNPath(szFileName
));
5411 // find the changelist name
5412 CString sChangelist
;
5413 LONG_PTR nGroup
= m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
);
5414 for (std::map
<CString
, int>::iterator it
= m_pSVNStatusListCtrl
->m_changelists
.begin(); it
!= m_pSVNStatusListCtrl
->m_changelists
.end(); ++it
)
5415 if (it
->second
== nGroup
)
5416 sChangelist
= it
->first
;
5417 if (!sChangelist
.IsEmpty())
5420 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
5422 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
5424 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
5427 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
5430 e
->changelist
= sChangelist
;
5433 if (m_pSVNStatusListCtrl
->m_changelists
.find(e
->changelist
)!=m_pSVNStatusListCtrl
->m_changelists
.end())
5434 m_pSVNStatusListCtrl
->SetItemGroup(index
, m_pSVNStatusListCtrl
->m_changelists
[e
->changelist
]);
5436 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
5442 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5443 if (hParentWnd
!= NULL
)
5444 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
5450 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR
);
5456 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
5458 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
5460 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
5463 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
5466 e
->changelist
= sChangelist
;
5467 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
5472 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5473 if (hParentWnd
!= NULL
)
5474 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
5480 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR
);
5486 for(UINT i
= 0; i
< cFiles
; ++i
)
5488 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
5489 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5490 if (hParentWnd
!= NULL
)
5491 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)szFileName
);
5495 GlobalUnlock(medium
.hGlobal
);
5497 return true; //let base free the medium
5499 HRESULT STDMETHODCALLTYPE
CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
)
5501 CIDropTarget::DragOver(grfKeyState
, pt
, pdwEffect
);
5502 *pdwEffect
= DROPEFFECT_COPY
;
5503 if (m_pSVNStatusListCtrl
)
5506 clientpoint
.x
= pt
.x
;
5507 clientpoint
.y
= pt
.y
;
5508 ScreenToClient(m_hTargetWnd
, &clientpoint
);
5509 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
5511 *pdwEffect
= DROPEFFECT_MOVE
;
5513 else if ((!m_pSVNStatusListCtrl
->m_bFileDropsEnabled
)||(m_pSVNStatusListCtrl
->m_bOwnDrag
))
5515 *pdwEffect
= DROPEFFECT_NONE
;
5523 void CGitStatusListCtrl::FileSaveAs(CTGitPath
*path
)
5526 filename
.Format(_T("%s-%s%s"),path
->GetBaseFilename(),this->m_CurrentVersion
.Left(6),path
->GetFileExtension());
5527 CFileDialog
dlg(FALSE
,NULL
,
5529 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
5531 CString currentpath
;
5532 currentpath
=g_Git
.m_CurrentDir
+_T("\\");
5533 currentpath
+=path
->GetWinPathString();
5535 dlg
.m_ofn
.lpstrInitialDir
=currentpath
.GetBuffer();
5538 if(dlg
.DoModal()==IDOK
)
5540 filename
= dlg
.GetFileName();
5541 if(m_CurrentVersion
== GIT_REV_ZERO
)
5543 cmd
.Format(_T("copy /Y \"%s\" \"%s\""),path
->GetWinPath(),filename
);
5544 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
5546 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5552 cmd
.Format(_T("git.exe cat-file -p %s:\"%s\""),m_CurrentVersion
,path
->GetGitPathString());
5553 if(g_Git
.RunLogFile(cmd
,filename
))
5555 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5563 int CGitStatusListCtrl::RevertSelectedItemToVersion()
5565 if(this->m_CurrentVersion
.IsEmpty())
5567 if(this->m_CurrentVersion
== GIT_REV_ZERO
)
5570 POSITION pos
= GetFirstSelectedItemPosition();
5574 while ((index
= GetNextSelectedItem(pos
)) >= 0)
5576 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
5577 cmd
.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion
,fentry
->GetGitPathString());
5579 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
5581 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5586 out
.Format(_T("%d files revert to %s"),count
,m_CurrentVersion
.Left(6));
5587 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5590 void CGitStatusListCtrl::OpenFile(CTGitPath
*filepath
,int mode
)
5593 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
5595 file
= filepath
->GetWinPath();
5599 GetTempPath(temppath
);
5600 file
.Format(_T("%s%s_%s%s"),
5602 filepath
->GetBaseFilename(),
5603 m_CurrentVersion
.Left(6),
5604 filepath
->GetFileExtension());
5606 cmd
.Format(_T("git.exe cat-file -p %s:\"%s\""),m_CurrentVersion
,filepath
->GetGitPathString());
5607 if(g_Git
.RunLogFile(cmd
,file
))
5609 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5614 if(mode
== NOTEPAD2
)
5617 sCmd
.Format(_T("\"%s\" \"%s\""),
5618 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("notepad2.exe")), file
);
5620 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
5623 int ret
= HINSTANCE_ERROR
;
5627 ret
= (int)ShellExecute(this->m_hWnd
, NULL
,file
, NULL
, NULL
, SW_SHOW
);
5629 if (ret
> HINSTANCE_ERROR
)
5636 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
5638 CAppUtils::LaunchApplication(cmd
, NULL
, false);