1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
5 // Copyright (C) 2010-2011 Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "..\\TortoiseShell\resource.h"
25 #include "GitStatusListCtrl.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"
54 #include "CommonResource.h"
56 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
57 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
58 const UINT
CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
59 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
60 const UINT
CGitStatusListCtrl::GITSLNM_ADDFILE
61 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
62 const UINT
CGitStatusListCtrl::GITSLNM_CHECKCHANGED
63 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
64 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCHANGED
65 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCHANGED"));
70 BEGIN_MESSAGE_MAP(CGitStatusListCtrl
, CListCtrl
)
71 ON_NOTIFY(HDN_ITEMCLICKA
, 0, OnHdnItemclick
)
72 ON_NOTIFY(HDN_ITEMCLICKW
, 0, OnHdnItemclick
)
73 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
74 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
75 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED
, OnLvnItemchanged
)
77 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclk
)
78 ON_NOTIFY_REFLECT(LVN_GETINFOTIP
, OnLvnGetInfoTip
)
79 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdraw
)
82 ON_NOTIFY_REFLECT(NM_RETURN
, OnNMReturn
)
84 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, OnToolTipText
)
85 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, OnToolTipText
)
87 ON_NOTIFY(HDN_BEGINTRACKA
, 0, &CGitStatusListCtrl::OnHdnBegintrack
)
88 ON_NOTIFY(HDN_BEGINTRACKW
, 0, &CGitStatusListCtrl::OnHdnBegintrack
)
89 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, &CGitStatusListCtrl::OnHdnItemchanging
)
90 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, &CGitStatusListCtrl::OnHdnItemchanging
)
92 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnBeginDrag
)
93 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING
, &CGitStatusListCtrl::OnLvnItemchanging
)
98 CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl()
99 //, m_HeadRev(GitRev::REV_HEAD)
102 , m_pSelectButton(NULL
)
103 , m_pConfirmButton(NULL
)
106 , m_bUnversionedRecurse(true)
107 , m_bShowIgnores(false)
108 , m_pDropTarget(NULL
)
109 , m_bIgnoreRemoveOnly(false)
110 , m_bCheckChildrenWithParent(false)
111 , m_bUnversionedLast(true)
112 , m_bHasChangeLists(false)
116 , m_bHasCheckboxes(false)
117 , m_bCheckIfGroupsExist(true)
118 , m_bFileDropsEnabled(false)
120 , m_dwDefaultColumns(0)
121 , m_ColumnManager(this)
122 , m_bAscending(false)
123 , m_nSortedColumn(-1)
124 , m_bHasExternalsFromDifferentRepos(false)
125 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE
))
127 , m_bDoNotAutoselectSubmodules(false)
131 m_bIsRevertTheirMy
= false;
132 this->m_nLineAdded
=this->m_nLineDeleted
=0;
135 CGitStatusListCtrl::~CGitStatusListCtrl()
137 // if (m_pDropTarget)
138 // delete m_pDropTarget;
142 void CGitStatusListCtrl::ClearStatusArray()
145 Locker
lock(m_critSec
);
146 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
148 delete m_arStatusArray
[i
];
150 m_arStatusArray
.clear();
154 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetListEntry(UINT_PTR index
)
157 if (index
>= (UINT_PTR
)m_arListArray
.size())
159 if (m_arListArray
[index
] >= m_arStatusArray
.size())
161 return m_arStatusArray
[m_arListArray
[index
]];
167 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetVisibleListEntry(const CTGitPath
& path
)
169 int itemCount
= GetItemCount();
170 for (int i
=0; i
< itemCount
; i
++)
172 FileEntry
* entry
= GetListEntry(i
);
173 if (entry
->GetPath().IsEquivalentTo(path
))
180 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetListEntry(const CTGitPath
& path
)
183 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
185 FileEntry
* entry
= m_arStatusArray
[i
];
186 if (entry
->GetPath().IsEquivalentTo(path
))
195 int CGitStatusListCtrl::GetIndex(const CTGitPath
& path
)
197 int itemCount
= GetItemCount();
198 for (int i
=0; i
< itemCount
; i
++)
200 FileEntry
* entry
= GetListEntry(i
);
201 if (entry
->GetPath().IsEquivalentTo(path
))
208 void CGitStatusListCtrl::Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
/* = GitSLC_POPALL */, bool bHasCheckboxes
/* = true */)
210 Locker
lock(m_critSec
);
212 m_dwDefaultColumns
= dwColumns
| 1;
213 m_dwContextMenus
= dwContextMenus
;
214 m_bHasCheckboxes
= bHasCheckboxes
;
216 // set the extended style of the listcontrol
217 // 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.
218 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
219 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
220 if (DWORD(regFullRowSelect
))
221 exStyle
|= LVS_EX_FULLROWSELECT
;
222 exStyle
|= (bHasCheckboxes
? LVS_EX_CHECKBOXES
: 0);
224 SetExtendedStyle(exStyle
);
226 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
228 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
229 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
231 // keep CSorter::operator() in sync!!
232 static UINT standardColumnNames
[GITSLC_NUMCOLUMNS
]
233 = { IDS_STATUSLIST_COLFILE
234 , IDS_STATUSLIST_COLFILENAME
235 , IDS_STATUSLIST_COLEXT
236 , IDS_STATUSLIST_COLSTATUS
237 , IDS_STATUSLIST_COLADD
238 , IDS_STATUSLIST_COLDEL
241 m_ColumnManager
.SetNames(standardColumnNames
,GITSLC_NUMCOLUMNS
);
242 m_ColumnManager
.ReadSettings (m_dwDefaultColumns
, 0, sColumnInfoContainer
, GITSLC_NUMCOLUMNS
);
246 if (m_pDropTarget
== NULL
)
248 m_pDropTarget
= new CGitStatusListCtrlDropTarget(this);
249 RegisterDragDrop(m_hWnd
,m_pDropTarget
);
250 // create the supported formats:
252 ftetc
.dwAspect
= DVASPECT_CONTENT
;
254 ftetc
.tymed
= TYMED_HGLOBAL
;
255 ftetc
.cfFormat
=CF_HDROP
;
256 m_pDropTarget
->AddSuportedFormat(ftetc
);
262 m_bUnversionedRecurse
= !!((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE
));
265 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID
)
267 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
270 BOOL
CGitStatusListCtrl::GetStatus ( const CTGitPathList
* pathList
271 , bool bUpdate
/* = FALSE */
272 , bool bShowIgnores
/* = false */
274 , bool /*bShowUserProps*/ /* = false */)
276 Locker
lock(m_critSec
);
277 int mask
= CGitStatusListCtrl::FILELIST_MODIFY
;
279 mask
|= CGitStatusListCtrl::FILELIST_IGNORE
;
281 mask
|= CGitStatusListCtrl::FILELIST_UNVER
;
282 this->UpdateFileList(mask
,bUpdate
,(CTGitPathList
*)pathList
);
286 int refetchcounter
= 0;
289 // force the cursor to change
292 SetCursorPos(pt
.x
, pt
.y
);
294 m_mapFilenameToChecked
.clear();
295 //m_StatusUrlList.Clear();
296 bool bHasChangelists
= (m_changelists
.size()>1 || (m_changelists
.size()>0 && !m_bHasIgnoreGroup
));
297 m_changelists
.clear();
298 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
300 FileEntry
* entry
= m_arStatusArray
[i
];
301 if ( bHasChangelists
&& entry
->checked
)
303 // If change lists are present, remember all checked entries
304 CString path
= entry
->GetPath().GetGitPathString();
305 m_mapFilenameToChecked
[path
] = true;
307 if ( (entry
->status
==git_wc_status_unversioned
|| entry
->status
==git_wc_status_missing
) && entry
->checked
)
309 // The user manually selected an unversioned or missing file. We remember
310 // this so that the selection can be restored when refreshing.
311 CString path
= entry
->GetPath().GetGitPathString();
312 m_mapFilenameToChecked
[path
] = true;
314 else if ( entry
->status
> git_wc_status_normal
&& !entry
->checked
)
316 // The user manually deselected a versioned file. We remember
317 // this so that the deselection can be restored when refreshing.
318 CString path
= entry
->GetPath().GetGitPathString();
319 m_mapFilenameToChecked
[path
] = false;
323 // use a sorted path list to make sure we fetch the status of
324 // parent items first, *then* the child items (if any)
325 CTGitPathList sortedPathList
= pathList
;
326 sortedPathList
.SortByPathname();
331 m_bHasExternalsFromDifferentRepos
= FALSE
;
332 m_bHasExternals
= FALSE
;
333 m_bHasUnversionedItems
= FALSE
;
335 m_bHasChangeLists
= false;
336 m_bShowIgnores
= bShowIgnores
;
343 // first clear possible status data left from
344 // previous GetStatus() calls
347 m_StatusFileList
= sortedPathList
;
349 // Since Git_client_status() returns all files, even those in
350 // folders included with Git:externals we need to check if all
351 // files we get here belongs to the same repository.
352 // It is possible to commit changes in an external folder, as long
353 // as the folder belongs to the same repository (but another path),
354 // but it is not possible to commit all files if the externals are
355 // from a different repository.
357 // To check if all files belong to the same repository, we compare the
358 // UUID's - if they're identical then the files belong to the same
359 // repository and can be committed. But if they're different, then
360 // tell the user to commit all changes in the external folders
362 CStringA sUUID
; // holds the repo UUID
363 CTGitPathList arExtPaths
; // list of Git:external paths
369 m_nTargetCount
= sortedPathList
.GetCount();
371 GitStatus
status(m_pbCanceled
);
372 if(m_nTargetCount
> 1 && sortedPathList
.AreAllPathsFilesInOneDirectory())
374 // This is a special case, where we've been given a list of files
375 // all from one folder
376 // We handle them by setting a status filter, then requesting the Git status of
377 // all the files in the directory, filtering for the ones we're interested in
378 status
.SetFilter(sortedPathList
);
380 // if all selected entries are files, we don't do a recursive status
381 // fetching. But if only one is a directory, we have to recurse.
382 git_depth_t depth
= git_depth_files
;
383 // We have set a filter. If all selected items were files or we fetch
384 // the status not recursively, then we have to include
385 // ignored items too - the user has selected them
386 bool bShowIgnoresRight
= true;
387 for (int fcindex
=0; fcindex
<sortedPathList
.GetCount(); ++fcindex
)
389 if (sortedPathList
[fcindex
].IsDirectory())
391 depth
= git_depth_infinity
;
392 bShowIgnoresRight
= false;
396 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
.GetCommonDirectory(), bUpdate
, sUUID
, arExtPaths
, true, depth
, bShowIgnoresRight
))
403 for(int nTarget
= 0; nTarget
< m_nTargetCount
; nTarget
++)
405 // check whether the path we want the status for is already fetched due to status-fetching
407 // this check is only done for file paths, because folder paths could be included already
408 // but not recursively
409 if (sortedPathList
[nTarget
].IsDirectory() || GetListEntry(sortedPathList
[nTarget
]) == NULL
)
411 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
[nTarget
], bUpdate
, sUUID
,
412 arExtPaths
, false, git_depth_infinity
, bShowIgnores
))
420 // remove the 'helper' files of conflicted items from the list.
421 // otherwise they would appear as unversioned files.
422 for (INT_PTR cind
= 0; cind
< m_ConflictFileList
.GetCount(); ++cind
)
424 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
426 if (m_arStatusArray
[i
]->GetPath().IsEquivalentTo(m_ConflictFileList
[cind
]))
428 delete m_arStatusArray
[i
];
429 m_arStatusArray
.erase(m_arStatusArray
.begin()+i
);
435 } while(!BuildStatistics() && (refetchcounter
< 2) && (*m_pbCanceled
==false));
438 FetchUserProperties();
440 m_ColumnManager
.UpdateUserPropList (m_arStatusArray
);
445 SetCursorPos(pt
.x
, pt
.y
);
453 // Fetch all local properties for all elements in the status array
455 void CGitStatusListCtrl::FetchUserProperties()
460 for (size_t i
= 0, count
= m_arStatusArray
.size(); i
< count
; ++i
)
462 // local / temp pool to hold parameters and props for a single item
464 GitPool
localPool ((apr_pool_t
*)globalPool
);
466 // open working copy for this path
468 const char* path
= m_arStatusArray
[i
]->path
.GetGitApiPath (localPool
);
470 Git_wc_adm_access_t
*adm_access
= NULL
;
471 Git_error_t
* error
= Git_wc_adm_probe_open3 ( &adm_access
474 , FALSE
// no write lock
475 , 0 // lock just the directory/file itself
481 // get the props and add them to the status info
483 apr_hash_t
* props
= NULL
;
484 Git_error_t
* error
= Git_wc_prop_list ( &props
490 for ( apr_hash_index_t
*index
491 = apr_hash_first (localPool
, props
)
493 ; index
= apr_hash_next (index
))
495 // extract next entry from hash
497 const char* key
= NULL
;
499 const char** val
= NULL
;
501 apr_hash_this ( index
502 , reinterpret_cast<const void**>(&key
)
504 , reinterpret_cast<void**>(&val
));
506 // decode / dispatch it
508 CString name
= CUnicodeUtils::GetUnicode (key
);
509 CString value
= CUnicodeUtils::GetUnicode (*val
);
511 // store in property container (truncate it after ~100 chars)
513 m_arStatusArray
[i
]->present_props
[name
]
514 = value
.Left (GitSLC_MAXUSERPROPLENGTH
);
517 error
= Git_wc_adm_close2 (adm_access
, localPool
);
519 Git_error_clear (error
);
524 // Get the show-flags bitmap value which corresponds to a particular Git status
525 DWORD
CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status
)
529 case git_wc_status_none
:
530 case git_wc_status_unversioned
:
531 return GITSLC_SHOWUNVERSIONED
;
532 case git_wc_status_ignored
:
534 return GITSLC_SHOWDIRECTS
;
535 return GITSLC_SHOWDIRECTS
|GITSLC_SHOWIGNORED
;
536 case git_wc_status_incomplete
:
537 return GITSLC_SHOWINCOMPLETE
;
538 case git_wc_status_normal
:
539 return GITSLC_SHOWNORMAL
;
540 case git_wc_status_external
:
541 return GITSLC_SHOWEXTERNAL
;
542 case git_wc_status_added
:
543 return GITSLC_SHOWADDED
;
544 case git_wc_status_missing
:
545 return GITSLC_SHOWMISSING
;
546 case git_wc_status_deleted
:
547 return GITSLC_SHOWREMOVED
;
548 case git_wc_status_replaced
:
549 return GITSLC_SHOWREPLACED
;
550 case git_wc_status_modified
:
551 return GITSLC_SHOWMODIFIED
;
552 case git_wc_status_merged
:
553 return GITSLC_SHOWMERGED
;
554 case git_wc_status_conflicted
:
555 return GITSLC_SHOWCONFLICTED
;
556 case git_wc_status_obstructed
:
557 return GITSLC_SHOWOBSTRUCTED
;
559 // we should NEVER get here!
566 void CGitStatusListCtrl::Show(unsigned int dwShow
, unsigned int dwCheck
/*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList
,bool UseStoredCheckStatus
)
568 CWinApp
* pApp
= AfxGetApp();
570 pApp
->DoWaitCursor(1);
572 Locker
lock(m_critSec
);
573 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
575 //SetItemCount(listIndex);
582 m_arStatusArray
.clear();
583 for(int i
=0;i
<this->m_StatusFileList
.GetCount();i
++)
585 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
588 for(int i
=0;i
<this->m_UnRevFileList
.GetCount();i
++)
590 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
593 for(int i
=0;i
<this->m_IgnoreFileList
.GetCount();i
++)
595 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
599 if (m_nSortedColumn
>= 0)
601 CSorter
predicate (&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
602 std::sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
606 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
608 //set default checkbox status
609 CTGitPath
* entry
= ((CTGitPath
*)m_arStatusArray
[i
]);
610 CString path
= entry
->GetGitPathString();
611 if (m_mapFilenameToChecked
.size()!=0 && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end())
613 entry
->m_Checked
=m_mapFilenameToChecked
[path
];
615 else if (!UseStoredCheckStatus
)
617 bool autoSelectSubmodules
= !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
);
618 if(entry
->m_Action
& dwCheck
&& autoSelectSubmodules
)
619 entry
->m_Checked
=true;
621 entry
->m_Checked
=false;
624 if(entry
->m_Action
& dwShow
)
626 AddEntry(entry
,langID
,index
);
631 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
632 for (int col
= 0; col
<= maxcol
; col
++)
633 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
636 GetStatisticsString();
638 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
639 HDITEM HeaderItem
= {0};
640 HeaderItem
.mask
= HDI_FORMAT
;
641 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
643 pHeader
->GetItem(i
, &HeaderItem
);
644 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
645 pHeader
->SetItem(i
, &HeaderItem
);
647 if (m_nSortedColumn
>= 0)
649 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
650 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
651 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
657 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
658 EnsureVisible(nSelectedEntry
, false);
662 // Restore the item at the top of the list.
663 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
665 if ( !EnsureVisible(nTopIndex
+i
,false) )
673 pApp
->DoWaitCursor(-1);
679 this->BuildStatistics();
683 CWinApp
* pApp
= AfxGetApp();
685 pApp
->DoWaitCursor(1);
687 m_bShowFolders
= bShowFolders
;
689 int nTopIndex
= GetTopIndex();
690 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
691 int nSelectedEntry
= 0;
692 if (posSelectedEntry
)
693 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
699 m_arListArray
.clear();
701 m_arListArray
.reserve(m_arStatusArray
.size());
702 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
705 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
707 FileEntry
* entry
= m_arStatusArray
[i
];
708 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
710 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
712 if (entry
->IsFolder() && (!bShowFolders
))
713 continue; // don't show folders if they're not wanted.
716 git_wc_status_kind status
= GitStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
717 DWORD showFlags
= GetShowFlagsFromGitStatus(status
);
718 if (entry
->IsLocked())
719 showFlags
|= SVNSLC_SHOWLOCKS
;
721 showFlags
|= SVNSLC_SHOWSWITCHED
;
722 if (!entry
->changelist
.IsEmpty())
723 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
725 bool bAllowCheck
= ((entry
->changelist
.Compare(GITSLC_IGNORECHANGELIST
) != 0)
726 && (m_bCheckIfGroupsExist
|| (m_changelists
.size()==0 || (m_changelists
.size()==1 && m_bHasIgnoreGroup
))));
728 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
730 if (status
!= Git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& GitSLC_SHOWIGNORED
))
732 if ((!entry
->IsFolder()) && (status
== Git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
734 if (PathFileExists(entry
->GetPath().GetWinPath()))
736 m_arListArray
.push_back(i
);
737 if ((dwCheck
& SVNSLC_SHOWREMOVEDANDPRESENT
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
740 entry
->checked
= true;
742 AddEntry(entry
, langID
, listIndex
++);
745 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
747 m_arListArray
.push_back(i
);
748 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
751 entry
->checked
= true;
753 AddEntry(entry
, langID
, listIndex
++);
755 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
757 m_arListArray
.push_back(i
);
758 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
761 entry
->checked
= true;
763 AddEntry(entry
, langID
, listIndex
++);
769 SetItemCount(listIndex
);
771 m_ColumnManager
.UpdateRelevance (m_arStatusArray
, m_arListArray
);
773 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
774 for (int col
= 0; col
<= maxcol
; col
++)
775 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
778 GetStatisticsString();
780 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
781 HDITEM HeaderItem
= {0};
782 HeaderItem
.mask
= HDI_FORMAT
;
783 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
785 pHeader
->GetItem(i
, &HeaderItem
);
786 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
787 pHeader
->SetItem(i
, &HeaderItem
);
791 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
792 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
793 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
798 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
799 EnsureVisible(nSelectedEntry
, false);
803 // Restore the item at the top of the list.
804 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
806 if ( !EnsureVisible(nTopIndex
+i
,false) )
814 pApp
->DoWaitCursor(-1);
816 m_bEmpty
= (GetItemCount() == 0);
822 void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList
& checkedList
, bool /*bShowFolders*/ /* = true */)
825 for(int i
=0;i
<checkedList
.GetCount();i
++)
826 this->AddEntry((CTGitPath
*)&checkedList
[i
],0,i
);
830 Locker
lock(m_critSec
);
831 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
833 CWinApp
* pApp
= AfxGetApp();
835 pApp
->DoWaitCursor(1);
837 m_bShowFolders
= bShowFolders
;
839 int nTopIndex
= GetTopIndex();
840 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
841 int nSelectedEntry
= 0;
842 if (posSelectedEntry
)
843 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
849 m_arListArray
.clear();
851 m_arListArray
.reserve(m_arStatusArray
.size());
852 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
855 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
857 FileEntry
* entry
= m_arStatusArray
[i
];
858 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
860 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
862 if (entry
->IsFolder() && (!bShowFolders
))
863 continue; // don't show folders if they're not wanted.
865 git_wc_status_kind status
= SVNStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
866 DWORD showFlags
= GetShowFlagsFromSVNStatus(status
);
867 if (entry
->IsLocked())
868 showFlags
|= SVNSLC_SHOWLOCKS
;
869 if (!entry
->changelist
.IsEmpty())
870 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
872 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
873 if (status
!= git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& SVNSLC_SHOWIGNORED
))
875 for (int npath
= 0; npath
< checkedList
.GetCount(); ++npath
)
877 if (entry
->GetPath().IsEquivalentTo(checkedList
[npath
]))
879 entry
->checked
= true;
883 if ((!entry
->IsFolder()) && (status
== git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
885 if (PathFileExists(entry
->GetPath().GetWinPath()))
887 m_arListArray
.push_back(i
);
888 AddEntry(entry
, langID
, listIndex
++);
891 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
893 m_arListArray
.push_back(i
);
894 AddEntry(entry
, langID
, listIndex
++);
896 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
898 m_arListArray
.push_back(i
);
899 AddEntry(entry
, langID
, listIndex
++);
901 else if (entry
->switched
)
903 m_arListArray
.push_back(i
);
904 AddEntry(entry
, langID
, listIndex
++);
910 SetItemCount(listIndex
);
912 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
913 for (int col
= 0; col
<= maxcol
; col
++)
914 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
917 GetStatisticsString();
919 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
920 HDITEM HeaderItem
= {0};
921 HeaderItem
.mask
= HDI_FORMAT
;
922 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
924 pHeader
->GetItem(i
, &HeaderItem
);
925 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
926 pHeader
->SetItem(i
, &HeaderItem
);
930 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
931 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
932 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
937 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
938 EnsureVisible(nSelectedEntry
, false);
942 // Restore the item at the top of the list.
943 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
945 if ( !EnsureVisible(nTopIndex
+i
,false) )
953 pApp
->DoWaitCursor(-1);
955 m_bEmpty
= (GetItemCount() == 0);
960 int CGitStatusListCtrl::GetColumnIndex(int mask
)
970 void CGitStatusListCtrl::AddEntry(CTGitPath
* GitPath
, WORD
/*langID*/, int listIndex
)
972 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
973 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
975 CString path
= GitPath
->GetGitPathString();
978 int index
= listIndex
;
980 CString entryname
= GitPath
->GetGitPathString();
982 if (GitPath
->IsDirectory())
983 icon_idx
= m_nIconFolder
;
986 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(*GitPath
);
988 if(GitPath
->m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !GitPath
->GetGitOldPathString().IsEmpty())
992 rename
.Format(_T(" (from %s)"), GitPath
->GetGitOldPathString());
996 InsertItem(index
, entryname
, icon_idx
);
998 this->SetItemData(index
, (DWORD_PTR
)GitPath
);
999 // SVNSLC_COLFILENAME
1000 SetItemText(index
, nCol
++, GitPath
->GetFileOrDirectoryName());
1002 SetItemText(index
, nCol
++, GitPath
->GetFileExtension());
1004 SetItemText(index
, nCol
++, GitPath
->GetActionName());
1006 SetItemText(index
, GetColumnIndex(GITSLC_COLADD
),GitPath
->m_StatAdd
);
1007 SetItemText(index
, GetColumnIndex(GITSLC_COLDEL
),GitPath
->m_StatDel
);
1010 SetCheck(index
, GitPath
->m_Checked
);
1011 if (GitPath
->m_Checked
)
1015 if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_IGNORE
)
1016 SetItemGroup(index
, 2);
1017 else if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1018 SetItemGroup(index
,1);
1021 SetItemGroup(index
, GitPath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
));
1029 void CGitStatusListCtrl::AddEntry(FileEntry
* entry
, WORD langID
, int listIndex
)
1031 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
1032 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
1034 CString path
= entry
->GetPath().GetGitPathString();
1035 if ( m_mapFilenameToChecked
.size()!=0 && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end() )
1037 // The user manually de-/selected an item. We now restore this status
1039 entry
->checked
= m_mapFilenameToChecked
[path
];
1044 int index
= listIndex
;
1046 CString entryname
= entry
->GetDisplayName();
1048 if (entry
->isfolder
)
1049 icon_idx
= m_nIconFolder
;
1052 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(entry
->path
);
1055 InsertItem(index
, entryname
, icon_idx
);
1056 // SVNSLC_COLFILENAME
1057 SetItemText(index
, nCol
++, entry
->path
.GetFileOrDirectoryName());
1059 SetItemText(index
, nCol
++, entry
->path
.GetFileExtension());
1061 if (entry
->isNested
)
1063 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1064 SetItemText(index
, nCol
++, sTemp
);
1068 GitStatus::GetStatusString(hResourceHandle
, entry
->status
, buf
, _countof(buf
), (WORD
)langID
);
1069 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1070 _tcscat_s(buf
, 100, _T(" (+)"));
1071 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1072 _tcscat_s(buf
, 100, _T(" (s)"));
1074 if ((entry
->status
== entry
->propstatus
)&&
1075 (entry
->status
!= git_wc_status_normal
)&&
1076 (entry
->status
!= git_wc_status_unversioned
)&&
1077 (!GitStatus::IsImportant(entry
->textstatus
)))
1078 _tcscat_s(buf
, 100, ponly
);
1080 SetItemText(index
, nCol
++, buf
);
1082 // SVNSLC_COLREMOTESTATUS
1083 if (entry
->isNested
)
1085 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1086 SetItemText(index
, nCol
++, sTemp
);
1091 SVNStatus::GetStatusString(hResourceHandle
, entry
->remotestatus
, buf
, _countof(buf
), (WORD
)langID
);
1092 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1093 _tcscat_s(buf
, 100, _T(" (+)"));
1094 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1095 _tcscat_s(buf
, 100, _T(" (s)"));
1096 if ((entry
->remotestatus
== entry
->remotepropstatus
)&&
1097 (entry
->remotestatus
!= git_wc_status_none
)&&
1098 (entry
->remotestatus
!= git_wc_status_normal
)&&
1099 (entry
->remotestatus
!= git_wc_status_unversioned
)&&
1100 (!SVNStatus::IsImportant(entry
->remotetextstatus
)))
1101 _tcscat_s(buf
, 100, ponly
);
1103 SetItemText(index
, nCol
++, buf
);
1105 // SVNSLC_COLTEXTSTATUS
1106 if (entry
->isNested
)
1108 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1109 SetItemText(index
, nCol
++, sTemp
);
1114 SVNStatus::GetStatusString(hResourceHandle
, entry
->textstatus
, buf
, _countof(buf
), (WORD
)langID
);
1115 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1116 _tcscat_s(buf
, 100, _T(" (+)"));
1117 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1118 _tcscat_s(buf
, 100, _T(" (s)"));
1120 SetItemText(index
, nCol
++, buf
);
1122 // SVNSLC_COLPROPSTATUS
1123 if (entry
->isNested
)
1125 SetItemText(index
, nCol
++, _T(""));
1130 SVNStatus::GetStatusString(hResourceHandle
, entry
->propstatus
, buf
, _countof(buf
), (WORD
)langID
);
1131 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1132 _tcscat_s(buf
, 100, _T(" (+)"));
1133 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1134 _tcscat_s(buf
, 100, _T(" (s)"));
1136 SetItemText(index
, nCol
++, buf
);
1138 // SVNSLC_COLREMOTETEXT
1139 if (entry
->isNested
)
1141 SetItemText(index
, nCol
++, _T(""));
1146 SVNStatus::GetStatusString(hResourceHandle
, entry
->remotetextstatus
, buf
, _countof(buf
), (WORD
)langID
);
1147 SetItemText(index
, nCol
++, buf
);
1150 // SVNSLC_COLREMOTEPROP
1151 if (entry
->isNested
)
1153 SetItemText(index
, nCol
++, _T(""));
1157 // SVNStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, _countof(buf), (WORD)langID);
1158 SetItemText(index
, nCol
++, buf
);
1161 // SetItemText(index, nCol++, entry->url);
1164 if (!m_HeadRev
.IsHead())
1166 // we have contacted the repository
1169 // wc repository text
1173 // UID1 "" lock has been broken
1174 // UID1 UID2 lock has been stolen
1175 if (entry
->lock_token
.IsEmpty() || (entry
->lock_token
.Compare(entry
->lock_remotetoken
)==0))
1177 if (entry
->lock_owner
.IsEmpty())
1178 SetItemText(index
, nCol
++, entry
->lock_remoteowner
);
1180 SetItemText(index
, nCol
++, entry
->lock_owner
);
1182 else if (entry
->lock_remotetoken
.IsEmpty())
1185 CString
temp(MAKEINTRESOURCE(IDS_STATUSLIST_LOCKBROKEN
));
1186 SetItemText(index
, nCol
++, temp
);
1192 temp
.Format(IDS_STATUSLIST_LOCKSTOLEN
, (LPCTSTR
)entry
->lock_remoteowner
);
1193 SetItemText(index
, nCol
++, temp
);
1197 SetItemText(index
, nCol
++, entry
->lock_owner
);
1198 // SVNSLC_COLLOCKCOMMENT
1199 SetItemText(index
, nCol
++, entry
->lock_comment
);
1201 SetItemText(index
, nCol
++, entry
->last_commit_author
);
1202 // SVNSLC_COLREVISION
1204 temp
.Format(_T("%ld"), entry
->last_commit_rev
);
1205 if (entry
->last_commit_rev
> 0)
1206 SetItemText(index
, nCol
++, temp
);
1208 SetItemText(index
, nCol
++, _T(""));
1209 // SVNSLC_COLREMOTEREVISION
1210 temp
.Format(_T("%ld"), entry
->remoterev
);
1211 if (entry
->remoterev
> 0)
1212 SetItemText(index
, nCol
++, temp
);
1214 SetItemText(index
, nCol
++, _T(""));
1216 TCHAR datebuf
[SVN_DATE_BUFFER
];
1217 apr_time_t date
= entry
->last_commit_date
;
1218 SVN::formatDate(datebuf
, date
, true);
1220 SetItemText(index
, nCol
++, datebuf
);
1222 SetItemText(index
, nCol
++, _T(""));
1223 // SVNSLC_COLSVNNEEDSLOCK
1224 BOOL bFoundSVNNeedsLock
= entry
->present_props
.IsNeedsLockSet();
1225 CString strSVNNeedsLock
= (bFoundSVNNeedsLock
) ? _T("*") : _T("");
1226 SetItemText(index
, nCol
++, strSVNNeedsLock
);
1227 // SVNSLC_COLCOPYFROM
1228 if (m_sURL
.Compare(entry
->copyfrom_url
.Left(m_sURL
.GetLength()))==0)
1229 temp
= entry
->copyfrom_url
.Mid(m_sURL
.GetLength());
1231 temp
= entry
->copyfrom_url
;
1232 SetItemText(index
, nCol
++, temp
);
1233 // SVNSLC_COLMODIFICATIONDATE
1234 __int64 filetime
= entry
->GetPath().GetLastWriteTime();
1235 if ( (filetime
) && (entry
->status
!=git_wc_status_deleted
) )
1237 FILETIME
* f
= (FILETIME
*)(__int64
*)&filetime
;
1238 TCHAR datebuf
[SVN_DATE_BUFFER
];
1239 SVN::formatDate(datebuf
,*f
,true);
1240 SetItemText(index
, nCol
++, datebuf
);
1244 SetItemText(index
, nCol
++, _T(""));
1247 // user-defined properties
1248 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
1252 assert (i
== nCol
++);
1253 assert (m_ColumnManager
.IsUserProp (i
));
1255 CString name
= m_ColumnManager
.GetName(i
);
1256 if (entry
->present_props
.HasProperty (name
))
1258 const CString
& propVal
= entry
->present_props
[name
];
1259 if (propVal
.IsEmpty())
1260 SetItemText(index
, i
, m_sNoPropValueText
);
1262 SetItemText(index
, i
, propVal
);
1265 SetItemText(index
, i
, _T(""));
1268 SetCheck(index
, entry
->checked
);
1271 if (m_changelists
.find(entry
->changelist
) != m_changelists
.end())
1272 SetItemGroup(index
, m_changelists
[entry
->changelist
]);
1274 SetItemGroup(index
, 0);
1279 bool CGitStatusListCtrl::SetItemGroup(int item
, int groupindex
)
1281 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1286 i
.mask
= LVIF_GROUPID
;
1289 i
.iGroupId
= groupindex
;
1291 return !!SetItem(&i
);
1294 void CGitStatusListCtrl::OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1296 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1301 if (m_nSortedColumn
== phdr
->iItem
)
1302 m_bAscending
= !m_bAscending
;
1304 m_bAscending
= TRUE
;
1305 m_nSortedColumn
= phdr
->iItem
;
1306 Show(m_dwShow
, 0, m_bShowFolders
,false,true);
1311 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1313 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1316 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1317 if ((m_bBlock
)&&(m_bBlockUI
))
1319 // if we're blocked, prevent changing of the check state
1320 if ((!ISCHECKED(pNMLV
->uOldState
) && ISCHECKED(pNMLV
->uNewState
))||
1321 (ISCHECKED(pNMLV
->uOldState
) && !ISCHECKED(pNMLV
->uNewState
)))
1326 BOOL
CGitStatusListCtrl::OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1328 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1330 CWnd
* pParent
= GetParent();
1331 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
1333 pParent
->SendMessage(GITSLNM_ITEMCHANGED
, pNMLV
->iItem
);
1336 if ((pNMLV
->uNewState
==0)||(pNMLV
->uNewState
& LVIS_SELECTED
)||(pNMLV
->uNewState
& LVIS_FOCUSED
))
1342 bool bSelected
= !!(ListView_GetItemState(m_hWnd
, pNMLV
->iItem
, LVIS_SELECTED
) & LVIS_SELECTED
);
1343 int nListItems
= GetItemCount();
1346 // was the item checked?
1348 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1349 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1351 if (GetCheck(pNMLV
->iItem
))
1353 CheckEntry(pNMLV
->iItem
, nListItems
);
1356 POSITION pos
= GetFirstSelectedItemPosition();
1358 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1360 if (index
!= pNMLV
->iItem
)
1361 CheckEntry(index
, nListItems
);
1367 UncheckEntry(pNMLV
->iItem
, nListItems
);
1370 POSITION pos
= GetFirstSelectedItemPosition();
1372 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1374 if (index
!= pNMLV
->iItem
)
1375 UncheckEntry(index
, nListItems
);
1380 GetStatisticsString();
1387 void CGitStatusListCtrl::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1389 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
1394 void CGitStatusListCtrl::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1396 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
1401 void CGitStatusListCtrl::CheckEntry(int index
, int /*nListItems*/)
1403 Locker
lock(m_critSec
);
1404 //FileEntry * entry = GetListEntry(index);
1405 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1406 ASSERT(path
!= NULL
);
1409 m_mapFilenameToChecked
[path
->GetGitPathString()] = true;
1410 SetCheck(index
, TRUE
);
1411 //entry = GetListEntry(index);
1412 // if an unversioned item was checked, then we need to check if
1413 // the parent folders are unversioned too. If the parent folders actually
1414 // are unversioned, then check those too.
1416 if (entry
->status
== git_wc_status_unversioned
)
1418 // we need to check the parent folder too
1419 const CTGitPath
& folderpath
= entry
->path
;
1420 for (int i
=0; i
< nListItems
; ++i
)
1422 FileEntry
* testEntry
= GetListEntry(i
);
1423 ASSERT(testEntry
!= NULL
);
1424 if (testEntry
== NULL
)
1426 if (!testEntry
->checked
)
1428 if (testEntry
->path
.IsAncestorOf(folderpath
) && (!testEntry
->path
.IsEquivalentTo(folderpath
)))
1430 SetEntryCheck(testEntry
,i
,true);
1436 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1437 if ( (entry
->status
== git_wc_status_deleted
) || (m_bCheckChildrenWithParent
) || (bShift
) )
1439 // if a deleted folder gets checked, we have to check all
1440 // children of that folder too.
1441 if (entry
->path
.IsDirectory())
1443 SetCheckOnAllDescendentsOf(entry
, true);
1446 // if a deleted file or folder gets checked, we have to
1447 // check all parents of this item too.
1448 for (int i
=0; i
<nListItems
; ++i
)
1450 FileEntry
* testEntry
= GetListEntry(i
);
1451 ASSERT(testEntry
!= NULL
);
1452 if (testEntry
== NULL
)
1454 if (!testEntry
->checked
)
1456 if (testEntry
->path
.IsAncestorOf(entry
->path
) && (!testEntry
->path
.IsEquivalentTo(entry
->path
)))
1458 if ((testEntry
->status
== git_wc_status_deleted
)||(m_bCheckChildrenWithParent
))
1460 SetEntryCheck(testEntry
,i
,true);
1462 // now we need to check all children of this parent folder
1463 SetCheckOnAllDescendentsOf(testEntry
, true);
1470 if ( !path
->m_Checked
)
1472 path
->m_Checked
= TRUE
;
1477 void CGitStatusListCtrl::UncheckEntry(int index
, int /*nListItems*/)
1479 Locker
lock(m_critSec
);
1480 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1481 ASSERT(path
!= NULL
);
1484 SetCheck(index
, FALSE
);
1485 m_mapFilenameToChecked
[path
->GetGitPathString()] = false;
1486 //entry = GetListEntry(index);
1487 // item was unchecked
1489 if (entry
->path
.IsDirectory())
1491 // disable all files within an unselected folder, except when unchecking a folder with property changes
1492 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1493 if ( (entry
->status
!= git_wc_status_modified
) || (bShift
) )
1495 SetCheckOnAllDescendentsOf(entry
, false);
1498 else if (entry
->status
== git_wc_status_deleted
)
1500 // a "deleted" file was unchecked, so uncheck all parent folders
1501 // and all children of those parents
1502 for (int i
=0; i
<nListItems
; i
++)
1504 FileEntry
* testEntry
= GetListEntry(i
);
1505 ASSERT(testEntry
!= NULL
);
1506 if (testEntry
== NULL
)
1508 if (testEntry
->checked
)
1510 if (testEntry
->path
.IsAncestorOf(entry
->path
))
1512 if (testEntry
->status
== git_wc_status_deleted
)
1514 SetEntryCheck(testEntry
,i
,false);
1517 SetCheckOnAllDescendentsOf(testEntry
, false);
1524 if ( path
->m_Checked
)
1526 path
->m_Checked
= FALSE
;
1531 bool CGitStatusListCtrl::EntryPathCompareNoCase(const FileEntry
* pEntry1
, const FileEntry
* pEntry2
)
1533 return pEntry1
->path
< pEntry2
->path
;
1536 bool CGitStatusListCtrl::IsEntryVersioned(const FileEntry
* pEntry1
)
1538 return pEntry1
->status
!= git_wc_status_unversioned
;
1541 bool CGitStatusListCtrl::BuildStatistics()
1544 bool bRefetchStatus
= false;
1546 // now gather some statistics
1559 for (int i
=0; i
< (int)m_arStatusArray
.size(); ++i
)
1561 int status
=((CTGitPath
*)m_arStatusArray
[i
])->m_Action
;
1563 m_nLineAdded
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatAdd
);
1564 m_nLineDeleted
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatDel
);
1566 if(status
&(CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
1569 if(status
&CTGitPath::LOGACTIONS_DELETED
)
1572 if(status
&(CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_MODIFIED
))
1575 if(status
&CTGitPath::LOGACTIONS_UNMERGED
)
1578 if(status
&(CTGitPath::LOGACTIONS_IGNORE
|CTGitPath::LOGACTIONS_UNVER
))
1581 if(status
&(CTGitPath::LOGACTIONS_REPLACED
))
1584 if(((CTGitPath
*)m_arStatusArray
[i
])->m_Checked
)
1587 // } // switch (entry->status)
1589 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1590 return !bRefetchStatus
;
1596 int CGitStatusListCtrl::GetGroupFromPoint(POINT
* ppt
)
1598 // the point must be relative to the upper left corner of the control
1602 if (!IsGroupViewEnabled())
1611 while (((flags
& LVHT_BELOW
) == 0)&&(pt
.y
< rc
.bottom
))
1613 nItem
= HitTest(pt
, &flags
);
1614 if ((flags
& LVHT_ONITEM
)||(flags
& LVHT_EX_GROUP_HEADER
))
1616 // the first item below the point
1618 // check if the point is too much right (i.e. if the point
1619 // is farther to the right than the width of the item)
1621 GetItemRect(nItem
, &r
, LVIR_LABEL
);
1622 if (ppt
->x
> r
.right
)
1626 lv
.mask
= LVIF_GROUPID
;
1629 int groupID
= lv
.iGroupId
;
1630 // now we search upwards and check if the item above this one
1631 // belongs to another group. If it belongs to the same group,
1632 // we're not over a group header
1636 nItem
= HitTest(pt
, &flags
);
1637 if ((flags
& LVHT_ONITEM
)&&(nItem
>= 0))
1639 // the first item below the point
1641 lv
.mask
= LVIF_GROUPID
;
1644 if (lv
.iGroupId
!= groupID
)
1659 void CGitStatusListCtrl::OnContextMenuGroup(CWnd
* /*pWnd*/, CPoint point
)
1661 POINT clientpoint
= point
;
1662 ScreenToClient(&clientpoint
);
1663 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint
) >= 0))
1666 if (popup
.CreatePopupMenu())
1669 temp
.LoadString(IDS_STATUSLIST_CHECKGROUP
);
1670 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_CHECKGROUP
, temp
);
1671 temp
.LoadString(IDS_STATUSLIST_UNCHECKGROUP
);
1672 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_UNCHECKGROUP
, temp
);
1673 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1674 bool bCheck
= false;
1677 case IDGITLC_CHECKGROUP
:
1679 // fall through here
1680 case IDGITLC_UNCHECKGROUP
:
1682 int group
= GetGroupFromPoint(&clientpoint
);
1683 // go through all items and check/uncheck those assigned to the group
1684 // but block the OnLvnItemChanged handler
1687 for (int i
=0; i
<GetItemCount(); ++i
)
1689 SecureZeroMemory(&lv
, sizeof(LVITEM
));
1690 lv
.mask
= LVIF_GROUPID
;
1694 if (lv
.iGroupId
== group
)
1696 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
1699 bool bOldCheck
= entry
->m_Checked
;
1700 SetEntryCheck(entry
, i
, bCheck
);
1701 if (bCheck
!= bOldCheck
)
1712 GetStatisticsString();
1722 void CGitStatusListCtrl::OnContextMenuList(CWnd
* pWnd
, CPoint point
)
1725 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1727 bool XPorLater
= false;
1728 OSVERSIONINFOEX inf
;
1729 SecureZeroMemory(&inf
, sizeof(OSVERSIONINFOEX
));
1730 inf
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
1731 GetVersionEx((OSVERSIONINFO
*)&inf
);
1732 WORD fullver
= MAKEWORD(inf
.dwMinorVersion
, inf
.dwMajorVersion
);
1733 if (fullver
>= 0x0501)
1735 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1736 CTGitPath
* filepath
;
1738 int selIndex
= GetSelectionMark();
1739 if ((point
.x
== -1) && (point
.y
== -1))
1742 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1743 ClientToScreen(&rect
);
1744 point
= rect
.CenterPoint();
1746 if ((GetSelectedCount() == 0)&&(XPorLater
)&&(m_bHasCheckboxes
))
1748 // nothing selected could mean the context menu is requested for
1750 OnContextMenuGroup(pWnd
, point
);
1752 else if (selIndex
>= 0)
1754 //FileEntry * entry = GetListEntry(selIndex);
1756 filepath
= (CTGitPath
* )GetItemData(selIndex
);
1758 ASSERT(filepath
!= NULL
);
1759 if (filepath
== NULL
)
1762 //const CTGitPath& filepath = entry->path;
1763 int wcStatus
= filepath
->m_Action
;
1764 // entry is selected, now show the popup menu
1765 Locker
lock(m_critSec
);
1767 CMenu changelistSubMenu
;
1768 CMenu ignoreSubMenu
;
1769 if (popup
.CreatePopupMenu())
1771 //Add Menu for version controlled file
1773 if (GetSelectedCount() > 0 && wcStatus
& CTGitPath::LOGACTIONS_UNMERGED
)
1775 if (GetSelectedCount() == 1 && (m_dwContextMenus
& GITSLC_POPCONFLICT
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1777 popup
.AppendMenuIcon(IDGITLC_EDITCONFLICT
, IDS_MENUCONFLICT
, IDI_CONFLICT
);
1779 if (m_dwContextMenus
& GITSLC_POPRESOLVE
)
1781 popup
.AppendMenuIcon(IDGITLC_RESOLVECONFLICT
, IDS_STATUSLIST_CONTEXT_RESOLVED
, IDI_RESOLVE
);
1783 if ((m_dwContextMenus
& GITSLC_POPRESOLVE
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1785 popup
.AppendMenuIcon(IDGITLC_RESOLVETHEIRS
, IDS_SVNPROGRESS_MENUUSETHEIRS
, IDI_RESOLVE
);
1786 popup
.AppendMenuIcon(IDGITLC_RESOLVEMINE
, IDS_SVNPROGRESS_MENUUSEMINE
, IDI_RESOLVE
);
1788 if ((m_dwContextMenus
& GITSLC_POPCONFLICT
)||(m_dwContextMenus
& GITSLC_POPRESOLVE
))
1789 popup
.AppendMenu(MF_SEPARATOR
);
1792 if (GetSelectedCount() > 0)
1794 if (wcStatus
& CTGitPath::LOGACTIONS_UNVER
)
1795 if (m_dwContextMenus
& GITSLC_POPADD
)
1797 //if ( entry->IsFolder() )
1799 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1803 popup
.AppendMenuIcon(IDGITLC_ADD
, IDS_STATUSLIST_CONTEXT_ADD
, IDI_ADD
);
1808 if (!(wcStatus
&CTGitPath::LOGACTIONS_UNVER
))
1810 if ( (m_dwContextMenus
& GITSLC_POPCOMPAREWITHBASE
) && GetSelectedCount()>0)
1812 if(filepath
->m_ParentNo
& MERGE_MASK
)
1813 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_TREE_DIFF
, IDI_DIFF
);
1815 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_LOG_COMPAREWITHBASE
, IDI_DIFF
);
1817 popup
.SetDefaultItem(IDGITLC_COMPARE
, FALSE
);
1820 if ((m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPAREWC
)) && GetSelectedCount()>0)
1822 if( (!m_CurrentVersion
.IsEmpty()) && m_CurrentVersion
!= GIT_REV_ZERO
)
1823 popup
.AppendMenuIcon(IDGITLC_COMPAREWC
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1826 if (GetSelectedCount() == 1)
1828 bool bEntryAdded
= false;
1829 //if (entry->remotestatus <= git_wc_status_normal)
1831 // if (wcStatus > git_wc_status_normal)
1833 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
1835 if(!g_Git
.IsInitRepos() && (m_dwContextMenus
&GITSLC_POPGNUDIFF
))
1837 popup
.AppendMenuIcon(IDGITLC_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1845 //else if (wcStatus != git_wc_status_deleted)
1847 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
1849 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1850 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1851 // bEntryAdded = true;
1853 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
1855 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1856 // bEntryAdded = true;
1860 popup
.AppendMenu(MF_SEPARATOR
);
1862 //else if (GetSelectedCount() > 1)
1864 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1866 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1867 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1872 if( (!this->m_Rev1
.IsEmpty()) || (!this->m_Rev1
.IsEmpty()) )
1874 if(GetSelectedCount() == 1)
1876 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPARETWO
))
1878 popup
.AppendMenuIcon(IDGITLC_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1879 popup
.SetDefaultItem(IDGITLC_COMPARETWO
, FALSE
);
1881 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_GNUDIFF2
))
1883 popup
.AppendMenuIcon(IDGITLC_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1889 if (GetSelectedCount() > 0)
1891 if ((GetSelectedCount() == 2) && (m_dwContextMenus
& this->GetContextMenuBit(GITSLC_POPCOMPARETWOFILES
)))
1893 POSITION pos
= GetFirstSelectedItemPosition();
1894 int index
= GetNextSelectedItem(pos
);
1897 CTGitPath
* entry2
= NULL
;
1898 bool bothItemsAreFiles
= true;
1899 entry2
= (CTGitPath
* )GetItemData(index
);
1901 bothItemsAreFiles
= !entry2
->IsDirectory();
1902 index
= GetNextSelectedItem(pos
);
1905 entry2
= (CTGitPath
* )GetItemData(index
);
1907 bothItemsAreFiles
= bothItemsAreFiles
&& !entry2
->IsDirectory();
1908 if (bothItemsAreFiles
)
1909 popup
.AppendMenuIcon(IDGITLC_COMPARETWOFILES
, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES
, IDI_DIFF
);
1913 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
1915 // POSITION pos = GetFirstSelectedItemPosition();
1916 // int index = GetNextSelectedItem(pos);
1919 // FileEntry * entry = GetListEntry(index);
1920 // git_wc_status_kind status1 = git_wc_status_none;
1921 // git_wc_status_kind status2 = git_wc_status_none;
1923 // status1 = entry->status;
1924 // index = GetNextSelectedItem(pos);
1927 // entry = GetListEntry(index);
1929 // status2 = entry->status;
1930 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
1931 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
1933 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
1938 // if (wcStatus > git_wc_status_normal)
1940 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1942 // // reverting missing folders is not possible
1943 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1945 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1949 // if (entry->remotestatus > git_wc_status_normal)
1951 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1953 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1958 if ( (GetSelectedCount() >0 ) && (!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
)))
1960 if ((m_dwContextMenus
& GITSLC_POPREVERT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1962 popup
.AppendMenuIcon(IDGITLC_REVERT
, IDS_MENUREVERT
, IDI_REVERT
);
1965 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOREV
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1966 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1968 popup
.AppendMenuIcon(IDGITLC_REVERTTOREV
, IDS_LOG_POPUP_REVERTTOREV
, IDI_REVERT
);
1972 if ((GetSelectedCount() == 1)&&(!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
))
1973 &&(!(wcStatus
& CTGitPath::LOGACTIONS_IGNORE
)))
1975 if (m_dwContextMenus
& GITSLC_POPSHOWLOG
)
1977 popup
.AppendMenuIcon(IDGITLC_LOG
, IDS_REPOBROWSE_SHOWLOG
, IDI_LOG
);
1979 if (m_dwContextMenus
& GITSLC_POPBLAME
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1981 popup
.AppendMenuIcon(IDGITLC_BLAME
, IDS_MENUBLAME
, IDI_BLAME
);
1984 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1985 if ( (GetSelectedCount() == 1) )
1987 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_SAVEAS
) && ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1989 popup
.AppendMenuIcon(IDGITLC_SAVEAS
, IDS_LOG_POPUP_SAVE
, IDI_SAVEAS
);
1992 if (m_dwContextMenus
& GITSLC_POPOPEN
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1994 popup
.AppendMenuIcon(IDGITLC_VIEWREV
, IDS_LOG_POPUP_VIEWREV
);
1995 popup
.AppendMenuIcon(IDGITLC_OPEN
, IDS_REPOBROWSE_OPEN
, IDI_OPEN
);
1996 popup
.AppendMenuIcon(IDGITLC_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1997 if (wcStatus
&CTGitPath::LOGACTIONS_UNVER
) {
1998 popup
.SetDefaultItem(IDGITLC_OPEN
, FALSE
);
2002 if (m_dwContextMenus
& GITSLC_POPEXPLORE
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
2004 popup
.AppendMenuIcon(IDGITLC_EXPLORE
, IDS_STATUSLIST_CONTEXT_EXPLORE
, IDI_EXPLORER
);
2008 if (GetSelectedCount() > 0)
2010 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
2012 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2014 // 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))
2017 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
2019 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
2021 if ((wcStatus
& CTGitPath::LOGACTIONS_UNVER
)/*||(wcStatus == git_wc_status_deleted)*/)
2023 if (m_dwContextMenus
& GITSLC_POPDELETE
)
2025 popup
.AppendMenuIcon(IDGITLC_DELETE
, IDS_MENUREMOVE
, IDI_DELETE
);
2028 if ( (wcStatus
& CTGitPath::LOGACTIONS_UNVER
|| wcStatus
& CTGitPath::LOGACTIONS_DELETED
) )
2030 if (m_dwContextMenus
& GITSLC_POPIGNORE
)
2033 CTGitPathList ignorelist
;
2034 FillListOfSelectedItemPaths(ignorelist
);
2035 //check if all selected entries have the same extension
2036 bool bSameExt
= true;
2038 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
2040 if (sExt
.IsEmpty() && (i
==0))
2041 sExt
= ignorelist
[i
].GetFileExtension();
2042 else if (sExt
.CompareNoCase(ignorelist
[i
].GetFileExtension())!=0)
2047 if (ignoreSubMenu
.CreateMenu())
2050 if (ignorelist
.GetCount()==1)
2051 ignorepath
= ignorelist
[0].GetFileOrDirectoryName();
2053 ignorepath
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
2054 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNORE
, ignorepath
);
2055 ignorepath
= _T("*")+sExt
;
2056 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREMASK
, ignorepath
);
2058 temp
.LoadString(IDS_MENUIGNORE
);
2059 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)ignoreSubMenu
.m_hMenu
, temp
);
2065 if (ignorelist
.GetCount()==1)
2067 temp
.LoadString(IDS_MENUIGNORE
);
2071 temp
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
2073 popup
.AppendMenuIcon(IDGITLC_IGNORE
, temp
, IDI_IGNORE
);
2081 if (GetSelectedCount() > 0)
2084 if ((!entry
->IsFolder())&&(wcStatus
>= git_wc_status_normal
)
2085 &&(wcStatus
!=git_wc_status_missing
)&&(wcStatus
!=git_wc_status_deleted
)
2086 &&(wcStatus
!=git_wc_status_added
))
2088 popup
.AppendMenu(MF_SEPARATOR
);
2089 if ((entry
->lock_token
.IsEmpty())&&(!entry
->IsFolder()))
2091 if (m_dwContextMenus
& SVNSLC_POPLOCK
)
2093 popup
.AppendMenuIcon(IDSVNLC_LOCK
, IDS_MENU_LOCK
, IDI_LOCK
);
2096 if ((!entry
->lock_token
.IsEmpty())&&(!entry
->IsFolder()))
2098 if (m_dwContextMenus
& SVNSLC_POPUNLOCK
)
2100 popup
.AppendMenuIcon(IDSVNLC_UNLOCK
, IDS_MENU_UNLOCK
, IDI_UNLOCK
);
2105 if ((!entry
->IsFolder())&&((!entry
->lock_token
.IsEmpty())||(!entry
->lock_remotetoken
.IsEmpty())))
2107 if (m_dwContextMenus
& SVNSLC_POPUNLOCKFORCE
)
2109 popup
.AppendMenuIcon(IDSVNLC_UNLOCKFORCE
, IDS_MENU_UNLOCKFORCE
, IDI_UNLOCK
);
2113 if (wcStatus
!= git_wc_status_missing
&& wcStatus
!= git_wc_status_deleted
&&wcStatus
!=git_wc_status_unversioned
)
2115 popup
.AppendMenu(MF_SEPARATOR
);
2116 popup
.AppendMenuIcon(IDSVNLC_PROPERTIES
, IDS_STATUSLIST_CONTEXT_PROPERTIES
, IDI_PROPERTIES
);
2119 popup
.AppendMenu(MF_SEPARATOR
);
2120 popup
.AppendMenuIcon(IDGITLC_COPY
, IDS_STATUSLIST_CONTEXT_COPY
, IDI_COPYCLIP
);
2121 popup
.AppendMenuIcon(IDGITLC_COPYEXT
, IDS_STATUSLIST_CONTEXT_COPYEXT
, IDI_COPYCLIP
);
2123 if ((m_dwContextMenus
& SVNSLC_POPCHANGELISTS
)&&(XPorLater
)
2124 &&(wcStatus
!= git_wc_status_unversioned
)&&(wcStatus
!= git_wc_status_none
))
2126 popup
.AppendMenu(MF_SEPARATOR
);
2127 // changelist commands
2128 size_t numChangelists
= GetNumberOfChangelistsInSelection();
2129 if (numChangelists
> 0)
2131 popup
.AppendMenuIcon(IDSVNLC_REMOVEFROMCS
, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS
);
2133 if ((!entry
->IsFolder())&&(changelistSubMenu
.CreateMenu()))
2136 temp
.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS
);
2137 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATECS
, temp
);
2139 if (entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
))
2141 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
2142 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATEIGNORECS
, SVNSLC_IGNORECHANGELIST
);
2145 if (m_changelists
.size() > 0)
2147 // find the changelist names
2148 bool bNeedSeparator
= true;
2149 int cmdID
= IDSVNLC_MOVETOCS
;
2150 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
2152 if ((entry
->changelist
.Compare(it
->first
))&&(it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)))
2156 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
2157 bNeedSeparator
= false;
2159 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, cmdID
, it
->first
);
2164 temp
.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS
);
2165 popup
.AppendMenu(MF_POPUP
|MF_STRING
, (UINT_PTR
)changelistSubMenu
.GetSafeHmenu(), temp
);
2171 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2174 AfxGetApp()->DoWaitCursor(1);
2175 //int iItemCountBeforeMenuCmd = GetItemCount();
2176 //bool bForce = false;
2179 case IDGITLC_VIEWREV
:
2180 OpenFile(filepath
, ALTERNATIVEEDITOR
);
2183 OpenFile(filepath
,OPEN
);
2185 case IDGITLC_OPENWITH
:
2186 OpenFile(filepath
,OPEN_WITH
);
2188 case IDGITLC_EXPLORE
:
2190 ShellExecute(this->m_hWnd
, _T("explore"), filepath
->GetDirectory().GetWinPath(), NULL
, NULL
, SW_SHOW
);
2194 // Compare current version and work copy.
2195 case IDGITLC_COMPAREWC
:
2197 POSITION pos
= GetFirstSelectedItemPosition();
2200 int index
= GetNextSelectedItem(pos
);
2205 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2206 case IDGITLC_COMPARE
:
2208 POSITION pos
= GetFirstSelectedItemPosition();
2211 int index
= GetNextSelectedItem(pos
);
2216 case IDGITLC_COMPARETWO
:
2218 POSITION pos
= GetFirstSelectedItemPosition();
2221 int index
= GetNextSelectedItem(pos
);
2222 StartDiffTwo(index
);
2226 case IDGITLC_COMPARETWOFILES
:
2228 POSITION pos
= GetFirstSelectedItemPosition();
2229 CTGitPath
* firstfilepath
, * secondfilepath
;
2232 firstfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
2233 secondfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
2235 ASSERT(firstfilepath
!= NULL
&& secondfilepath
!= NULL
);
2237 sCmd
.Format(_T("\"%s\" /command:diff /path:\"%s\" /path2:\"%s\" /hwnd:%ld"), (LPCTSTR
)(CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe")), firstfilepath
->GetWinPath(), secondfilepath
->GetWinPath(), (unsigned long)m_hWnd
);
2238 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
2241 case IDGITLC_GNUDIFF1
:
2243 // SVNDiff diff(NULL, this->m_hWnd, true);
2245 // if (entry->remotestatus <= git_wc_status_normal)
2246 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2248 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2249 if(m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2253 fromwhere
= _T("~1");
2254 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,GitRev::GetWorkingCopy(),
2255 *filepath
,GitRev::GetHead()+fromwhere
);
2259 if((filepath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
)) ==0)
2260 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_CurrentVersion
+_T("~1"),
2261 *filepath
,m_CurrentVersion
);
2265 if(filepath
->m_ParentNo
& MERGE_MASK
)
2270 str
.Format(_T("%s^%d"),m_CurrentVersion
,(filepath
->m_ParentNo
&PARENT_MASK
)+1);
2273 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_CurrentVersion
,
2274 *filepath
,str
, false,false,false,
2275 !!(filepath
->m_ParentNo
& MERGE_MASK
));
2280 case IDGITLC_GNUDIFF2
:
2282 // SVNDiff diff(NULL, this->m_hWnd, true);
2284 // if (entry->remotestatus <= git_wc_status_normal)
2285 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2287 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2289 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_Rev1
,
2295 { // The add went ok, but we now need to run through the selected items again
2296 // and update their status
2297 std::vector
<int> selectIndex
;
2299 POSITION pos
= GetFirstSelectedItemPosition();
2301 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2303 selectIndex
.push_back(index
);
2305 for(int i
=0;i
<selectIndex
.size();i
++)
2307 index
=selectIndex
[i
];
2309 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2314 cmd
.Format(_T("git.exe add -f -- \"%s\""), path
->GetGitPathString());
2316 if (!g_Git
.Run(cmd
, &output
, NULL
, CP_ACP
))
2318 path
->m_Action
= CTGitPath::LOGACTIONS_ADDED
;
2319 SetEntryCheck(path
,index
,true);
2321 SetItemGroup(index
,0);
2322 this->m_StatusFileList
.AddPath(*path
);
2323 this->m_UnRevFileList
.RemoveItem(*path
);
2324 this->m_IgnoreFileList
.RemoveItem(*path
);
2326 Show(this->m_dwShow
,0,true,true,true);
2333 case IDGITLC_DELETE
:
2336 std::vector
<int> selectIndex
;
2338 POSITION pos
= GetFirstSelectedItemPosition();
2340 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2342 selectIndex
.push_back(index
);
2345 //Create file-list ('\0' separated) for SHFileOperation
2347 for(int i
=0;i
<selectIndex
.size();i
++)
2349 index
=selectIndex
[i
];
2351 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2356 filelist
+= path
->GetWinPathString();
2357 filelist
+= _T("|");
2359 filelist
+= _T("|");
2360 int len
= filelist
.GetLength();
2361 TCHAR
* buf
= new TCHAR
[len
+2];
2362 _tcscpy_s(buf
, len
+2, filelist
);
2363 for (int i
=0; i
<len
; ++i
)
2366 SHFILEOPSTRUCT fileop
;
2367 fileop
.hwnd
= this->m_hWnd
;
2368 fileop
.wFunc
= FO_DELETE
;
2371 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
2372 fileop
.lpszProgressTitle
= _T("deleting file");
2373 int result
= SHFileOperation(&fileop
);
2376 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
2379 POSITION pos
= NULL
;
2380 while ((pos
= GetFirstSelectedItemPosition()) != 0)
2382 int index
= GetNextSelectedItem(pos
);
2383 if (GetCheck(index
))
2387 RemoveListEntry(index
);
2396 CAppUtils::LaunchTortoiseBlame(g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath(), m_CurrentVersion
);
2403 sCmd
.Format(_T("\"%s\" /command:log /path:\"%s\""),
2404 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath());
2406 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
2410 case IDGITLC_EDITCONFLICT
:
2412 CAppUtils::ConflictEdit(*filepath
,false,this->m_bIsRevertTheirMy
);
2415 case IDGITLC_RESOLVETHEIRS
: //follow up
2416 case IDGITLC_RESOLVEMINE
: //follow up
2417 case IDGITLC_RESOLVECONFLICT
:
2419 if (CMessageBox::Show(m_hWnd
, IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
)==IDYES
)
2421 POSITION pos
= GetFirstSelectedItemPosition();
2425 index
= GetNextSelectedItem(pos
);
2426 CTGitPath
* fentry
=(CTGitPath
*) this->GetItemData(index
);
2429 CString gitcmd
,output
;
2432 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVETHEIRS
) ||
2433 ((this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVEMINE
) )
2435 gitcmd
.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry
->GetGitPathString());
2436 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2438 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2443 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVEMINE
) ||
2444 ((this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVETHEIRS
) )
2446 gitcmd
.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry
->GetGitPathString());
2447 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2449 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2455 if ( fentry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
2457 gitcmd
.Format(_T("git.exe add -f -- \"%s\""),fentry
->GetGitPathString());
2458 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2460 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2464 fentry
->m_Action
|= CTGitPath::LOGACTIONS_MODIFIED
;
2465 fentry
->m_Action
&=~CTGitPath::LOGACTIONS_UNMERGED
;
2469 CAppUtils::RemoveTempMergeFile(*fentry
);
2472 Show(m_dwShow
, 0, m_bShowFolders
,0,true);
2477 case IDGITLC_IGNORE
:
2479 CTGitPathList ignorelist
;
2480 //std::vector<CString> toremove;
2481 FillListOfSelectedItemPaths(ignorelist
, true);
2484 if(!CAppUtils::IgnoreFile(ignorelist
,false))
2487 for(int i
=0;i
<ignorelist
.GetCount();i
++)
2489 int nListboxEntries
= GetItemCount();
2490 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2492 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2493 if (path
->GetGitPathString()==ignorelist
[i
].GetGitPathString())
2495 RemoveListEntry(nItem
);
2503 CTSVNPathList ignorelist
;
2504 std::vector
<CString
> toremove
;
2505 FillListOfSelectedItemPaths(ignorelist
, true);
2507 for (int j
=0; j
<ignorelist
.GetCount(); ++j
)
2509 int nListboxEntries
= GetItemCount();
2510 for (int i
=0; i
<nListboxEntries
; ++i
)
2512 if (GetListEntry(i
)->GetPath().IsEquivalentTo(ignorelist
[j
]))
2518 CString name
= CPathUtils::PathPatternEscape(ignorelist
[j
].GetFileOrDirectoryName());
2519 CTSVNPath parentfolder
= ignorelist
[j
].GetContainingDirectory();
2520 SVNProperties
props(parentfolder
, SVNRev::REV_WC
, false);
2522 for (int i
=0; i
<props
.GetCount(); i
++)
2524 CString
propname(props
.GetItemName(i
).c_str());
2525 if (propname
.CompareNoCase(_T("git:ignore"))==0)
2528 // treat values as normal text even if they're not
2529 value
= (char *)props
.GetItemValue(i
).c_str();
2532 if (value
.IsEmpty())
2536 value
= value
.Trim("\n\r");
2541 if (!props
.Add(_T("git:ignore"), (LPCSTR
)value
))
2544 temp
.Format(IDS_ERR_FAILEDIGNOREPROPERTY
, (LPCTSTR
)name
);
2545 CMessageBox::Show(this->m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONERROR
);
2548 if (GetCheck(selIndex
))
2552 // now, if we ignored a folder, remove all its children
2553 if (ignorelist
[j
].IsDirectory())
2555 for (int i
=0; i
<(int)m_arListArray
.size(); ++i
)
2557 FileEntry
* entry
= GetListEntry(i
);
2558 if (entry
->status
== git_wc_status_unversioned
)
2560 if (!ignorelist
[j
].IsEquivalentTo(entry
->GetPath())&&(ignorelist
[j
].IsAncestorOf(entry
->GetPath())))
2562 entry
->status
= git_wc_status_ignored
;
2563 entry
->textstatus
= git_wc_status_ignored
;
2566 toremove
.push_back(entry
->GetPath().GetSVNPathString());
2572 CTSVNPath basepath
= m_arStatusArray
[m_arListArray
[selIndex
]]->basepath
;
2574 FileEntry
* entry
= m_arStatusArray
[m_arListArray
[selIndex
]];
2575 if ( entry
->status
== git_wc_status_unversioned
) // keep "deleted" items
2576 toremove
.push_back(entry
->GetPath().GetSVNPathString());
2578 if (!m_bIgnoreRemoveOnly
)
2581 git_wc_status2_t
* s
;
2583 s
= status
.GetFirstFileStatus(parentfolder
, gitPath
, false, git_depth_empty
);
2584 // first check if the folder isn't already present in the list
2585 bool bFound
= false;
2586 nListboxEntries
= GetItemCount();
2587 for (int i
=0; i
<nListboxEntries
; ++i
)
2589 FileEntry
* entry
= GetListEntry(i
);
2590 if (entry
->path
.IsEquivalentTo(gitPath
))
2600 FileEntry
* entry
= new FileEntry();
2601 entry
->path
= gitPath
;
2602 entry
->basepath
= basepath
;
2603 entry
->status
= SVNStatus::GetMoreImportant(s
->text_status
, s
->prop_status
);
2604 entry
->textstatus
= s
->text_status
;
2605 entry
->propstatus
= s
->prop_status
;
2606 entry
->remotestatus
= SVNStatus::GetMoreImportant(s
->repos_text_status
, s
->repos_prop_status
);
2607 entry
->remotetextstatus
= s
->repos_text_status
;
2608 entry
->remotepropstatus
= s
->repos_prop_status
;
2609 entry
->inunversionedfolder
= FALSE
;
2610 entry
->checked
= true;
2611 entry
->inexternal
= false;
2612 entry
->direct
= false;
2613 entry
->isfolder
= true;
2614 entry
->last_commit_date
= 0;
2615 entry
->last_commit_rev
= 0;
2616 entry
->remoterev
= 0;
2621 entry
->url
= CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s
->entry
->url
));
2624 if (s
->entry
&& s
->entry
->present_props
)
2626 entry
->present_props
= s
->entry
->present_props
;
2628 m_arStatusArray
.push_back(entry
);
2629 m_arListArray
.push_back(m_arStatusArray
.size()-1);
2630 AddEntry(entry
, langID
, GetItemCount());
2635 for (std::vector
<CString
>::iterator it
= toremove
.begin(); it
!= toremove
.end(); ++it
)
2637 int nListboxEntries
= GetItemCount();
2638 for (int i
=0; i
<nListboxEntries
; ++i
)
2640 if (GetListEntry(i
)->path
.GetSVNPathString().Compare(*it
)==0)
2651 case IDGITLC_IGNOREMASK
:
2654 CString ext
=filepath
->GetFileExtension();
2655 CTGitPathList ignorelist
;
2656 FillListOfSelectedItemPaths(ignorelist
, true);
2659 CAppUtils::IgnoreFile(ignorelist
,true);
2661 common
=ignorelist
.GetCommonRoot().GetGitPathString();
2663 for (int i
=0; i
< GetItemCount(); ++i
)
2665 CTGitPath
*path
=(CTGitPath
*)GetItemData(i
);
2666 if(!( path
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
2668 if( path
->GetGitPathString().Left(common
.GetLength()) == common
)
2670 if (path
->GetFileExtension()==ext
)
2673 i
--; // remove index i at item, new one will replace.
2678 CWnd
* pParent
= GetParent();
2679 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2681 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2687 std::set
<CTSVNPath
> parentlist
;
2688 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
2690 parentlist
.insert(ignorelist
[i
].GetContainingDirectory());
2692 std::set
<CTSVNPath
>::iterator it
;
2693 std::vector
<CString
> toremove
;
2695 for (it
= parentlist
.begin(); it
!= parentlist
.end(); ++it
)
2697 CTSVNPath parentFolder
= (*it
).GetDirectory();
2698 SVNProperties
props(parentFolder
, SVNRev::REV_WC
, false);
2700 for (int i
=0; i
<props
.GetCount(); i
++)
2702 CString
propname(props
.GetItemName(i
).c_str());
2703 if (propname
.CompareNoCase(_T("git:ignore"))==0)
2706 // treat values as normal text even if they're not
2707 value
= (char *)props
.GetItemValue(i
).c_str();
2710 if (value
.IsEmpty())
2714 value
= value
.Trim("\n\r");
2719 if (!props
.Add(_T("git:ignore"), (LPCSTR
)value
))
2722 temp
.Format(IDS_ERR_FAILEDIGNOREPROPERTY
, (LPCTSTR
)name
);
2723 CMessageBox::Show(this->m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONERROR
);
2728 int nListboxEntries
= GetItemCount();
2729 for (int i
=0; i
<nListboxEntries
; ++i
)
2731 FileEntry
* entry
= GetListEntry(i
);
2732 ASSERT(entry
!= NULL
);
2735 if (basepath
.IsEmpty())
2736 basepath
= entry
->basepath
;
2737 // since we ignored files with a mask (e.g. *.exe)
2738 // we have to find find all files in the same
2739 // folder (IsAncestorOf() returns TRUE for _all_ children,
2740 // not just the immediate ones) which match the
2741 // mask and remove them from the list too.
2742 if ((entry
->status
== git_wc_status_unversioned
)&&(parentFolder
.IsAncestorOf(entry
->path
)))
2744 CString f
= entry
->path
.GetSVNPathString();
2745 if (f
.Mid(parentFolder
.GetSVNPathString().GetLength()).Find('/')<=0)
2747 if (CStringUtils::WildCardMatch(name
, f
))
2752 toremove
.push_back(f
);
2757 if (!m_bIgnoreRemoveOnly
)
2760 git_wc_status2_t
* s
;
2762 s
= status
.GetFirstFileStatus(parentFolder
, gitPath
, false, git_depth_empty
);
2765 // first check if the folder isn't already present in the list
2766 bool bFound
= false;
2767 for (int i
=0; i
<nListboxEntries
; ++i
)
2769 FileEntry
* entry
= GetListEntry(i
);
2770 if (entry
->path
.IsEquivalentTo(gitPath
))
2778 FileEntry
* entry
= new FileEntry();
2779 entry
->path
= gitPath
;
2780 entry
->basepath
= basepath
;
2781 entry
->status
= SVNStatus::GetMoreImportant(s
->text_status
, s
->prop_status
);
2782 entry
->textstatus
= s
->text_status
;
2783 entry
->propstatus
= s
->prop_status
;
2784 entry
->remotestatus
= SVNStatus::GetMoreImportant(s
->repos_text_status
, s
->repos_prop_status
);
2785 entry
->remotetextstatus
= s
->repos_text_status
;
2786 entry
->remotepropstatus
= s
->repos_prop_status
;
2787 entry
->inunversionedfolder
= false;
2788 entry
->checked
= true;
2789 entry
->inexternal
= false;
2790 entry
->direct
= false;
2791 entry
->isfolder
= true;
2792 entry
->last_commit_date
= 0;
2793 entry
->last_commit_rev
= 0;
2794 entry
->remoterev
= 0;
2799 entry
->url
= CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s
->entry
->url
));
2802 if (s
->entry
&& s
->entry
->present_props
)
2804 entry
->present_props
= s
->entry
->present_props
;
2806 m_arStatusArray
.push_back(entry
);
2807 m_arListArray
.push_back(m_arStatusArray
.size()-1);
2808 AddEntry(entry
, langID
, GetItemCount());
2814 for (std::vector
<CString
>::iterator it
= toremove
.begin(); it
!= toremove
.end(); ++it
)
2816 int nListboxEntries
= GetItemCount();
2817 for (int i
=0; i
<nListboxEntries
; ++i
)
2819 if (GetListEntry(i
)->path
.GetSVNPathString().Compare(*it
)==0)
2831 case IDGITLC_REVERT
:
2833 // If at least one item is not in the status "added"
2834 // we ask for a confirmation
2835 BOOL bConfirm
= FALSE
;
2836 POSITION pos
= GetFirstSelectedItemPosition();
2838 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2840 //FileEntry * fentry = GetListEntry(index);
2841 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
2842 if(fentry
&& fentry
->m_Action
&CTGitPath::LOGACTIONS_MODIFIED
)
2850 str
.Format(IDS_PROC_WARNREVERT
,GetSelectedCount());
2852 if (!bConfirm
|| CMessageBox::Show(this->m_hWnd
, str
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
2854 CTGitPathList targetList
;
2855 FillListOfSelectedItemPaths(targetList
);
2857 // make sure that the list is reverse sorted, so that
2858 // children are removed before any parents
2859 targetList
.SortByPathname(true);
2861 // put all reverted files in the trashbin, except the ones with 'added'
2862 // status because they are not restored by the revert.
2863 CTGitPathList delList
;
2864 POSITION pos
= GetFirstSelectedItemPosition();
2866 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2868 CTGitPath
*entry
=(CTGitPath
*)GetItemData(index
);
2869 if (entry
&&(!(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
))
2870 && (!(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)))
2873 fullpath
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+entry
->GetWinPath());
2874 delList
.AddPath(fullpath
);
2877 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
2878 delList
.DeleteAllFiles(true);
2880 CString revertToCommit
= _T("HEAD");
2882 revertToCommit
= _T("HEAD~1");
2883 if (g_Git
.Revert(revertToCommit
, targetList
))
2885 CMessageBox::Show(this->m_hWnd
, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR
);
2889 bool updateStatusList
= false;
2890 for(int i
=0;i
<targetList
.GetCount();i
++)
2892 int nListboxEntries
= GetItemCount();
2893 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2895 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2896 if (path
->GetGitPathString()==targetList
[i
].GetGitPathString())
2898 if(path
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2900 path
->m_Action
= CTGitPath::LOGACTIONS_UNVER
;
2901 SetEntryCheck(path
,nItem
,false);
2902 updateStatusList
= true;
2903 SetItemGroup(nItem
,1);
2904 this->m_StatusFileList
.RemoveItem(*path
);
2905 this->m_UnRevFileList
.AddPath(*path
);
2906 //this->m_IgnoreFileList.RemoveItem(*path);
2911 RemoveListEntry(nItem
);
2919 Show(m_dwShow
, 0, m_bShowFolders
,updateStatusList
,true);
2927 CopySelectedEntriesToClipboard(0);
2929 case IDGITLC_COPYEXT
:
2930 CopySelectedEntriesToClipboard((DWORD
)-1);
2933 case IDGITLC_SAVEAS
:
2934 FileSaveAs(filepath
);
2937 case IDGITLC_REVERTTOREV
:
2938 RevertSelectedItemToVersion();
2941 case IDSVNLC_PROPERTIES
:
2943 CTSVNPathList targetList
;
2944 FillListOfSelectedItemPaths(targetList
);
2945 CEditPropertiesDlg dlg
;
2946 dlg
.SetPathList(targetList
);
2948 if (dlg
.HasChanged())
2950 // since the user might have changed/removed/added
2951 // properties recursively, we don't really know
2952 // which items have changed their status.
2953 // So tell the parent to do a refresh.
2954 CWnd
* pParent
= GetParent();
2955 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2957 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
2962 case IDSVNLC_COMMIT
:
2964 CTSVNPathList targetList
;
2965 FillListOfSelectedItemPaths(targetList
);
2966 CTSVNPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2967 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2968 CString commandline
= CPathUtils::GetAppDirectory();
2969 commandline
+= _T("TortoiseProc.exe /command:commit /pathfile:\"");
2970 commandline
+= tempFile
.GetWinPathString();
2971 commandline
+= _T("\"");
2972 commandline
+= _T(" /deletepathfile");
2973 CAppUtils::LaunchApplication(commandline
, NULL
, false);
2977 case IDSVNLC_COMPAREWC
:
2979 POSITION pos
= GetFirstSelectedItemPosition();
2982 int index
= GetNextSelectedItem(pos
);
2983 FileEntry
* entry
= GetListEntry(index
);
2984 ASSERT(entry
!= NULL
);
2987 SVNDiff
diff(NULL
, m_hWnd
, true);
2988 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2989 git_revnum_t baseRev
= entry
->Revision
;
2990 diff
.DiffFileAgainstBase(
2991 entry
->path
, baseRev
, entry
->textstatus
, entry
->propstatus
);
2995 case IDSVNLC_GNUDIFF1
:
2997 SVNDiff
diff(NULL
, this->m_hWnd
, true);
2999 if (entry
->remotestatus
<= git_wc_status_normal
)
3000 CAppUtils::StartShowUnifiedDiff(m_hWnd
, entry
->path
, SVNRev::REV_BASE
, entry
->path
, SVNRev::REV_WC
);
3002 CAppUtils::StartShowUnifiedDiff(m_hWnd
, entry
->path
, SVNRev::REV_WC
, entry
->path
, SVNRev::REV_HEAD
);
3005 case IDSVNLC_UPDATE
:
3007 CTSVNPathList targetList
;
3008 FillListOfSelectedItemPaths(targetList
);
3009 bool bAllExist
= true;
3010 for (int i
=0; i
<targetList
.GetCount(); ++i
)
3012 if (!targetList
[i
].Exists())
3020 CSVNProgressDlg dlg
;
3021 dlg
.SetCommand(CSVNProgressDlg::SVNProgress_Update
);
3022 dlg
.SetPathList(targetList
);
3023 dlg
.SetRevision(SVNRev::REV_HEAD
);
3028 CString sTempFile
= CTempFiles::Instance().GetTempFilePath(false).GetWinPathString();
3029 targetList
.WriteToFile(sTempFile
, false);
3031 sCmd
.Format(_T("\"%s\" /command:update /rev /pathfile:\"%s\" /deletepathfile"),
3032 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR
)sTempFile
);
3034 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
3039 case IDSVNLC_REMOVE
:
3042 CTSVNPathList itemsToRemove
;
3043 FillListOfSelectedItemPaths(itemsToRemove
);
3045 // We must sort items before removing, so that files are always removed
3046 // *before* their parents
3047 itemsToRemove
.SortByPathname(true);
3049 bool bSuccess
= false;
3050 if (git
.Remove(itemsToRemove
, FALSE
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)))
3056 if ((git
.Err
->apr_err
== SVN_ERR_UNVERSIONED_RESOURCE
) ||
3057 (git
.Err
->apr_err
== SVN_ERR_CLIENT_MODIFIED
))
3059 CString msg
, yes
, no
, yestoall
;
3060 msg
.Format(IDS_PROC_REMOVEFORCE
, (LPCTSTR
)git
.GetLastErrorMessage());
3061 yes
.LoadString(IDS_MSGBOX_YES
);
3062 no
.LoadString(IDS_MSGBOX_NO
);
3063 yestoall
.LoadString(IDS_PROC_YESTOALL
);
3064 UINT ret
= CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_ERROR
, yes
, no
, yestoall
);
3065 if ((ret
== 1)||(ret
==3))
3067 if (!git
.Remove(itemsToRemove
, TRUE
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)))
3069 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3076 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3080 // The remove went ok, but we now need to run through the selected items again
3081 // and update their status
3082 POSITION pos
= GetFirstSelectedItemPosition();
3084 std::vector
<int> entriesToRemove
;
3085 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3087 FileEntry
* e
= GetListEntry(index
);
3089 ((e
->textstatus
== git_wc_status_unversioned
)||
3090 (e
->textstatus
== git_wc_status_none
)||
3091 (e
->textstatus
== git_wc_status_ignored
)))
3093 if (GetCheck(index
))
3096 entriesToRemove
.push_back(index
);
3100 e
->textstatus
= git_wc_status_deleted
;
3101 e
->status
= git_wc_status_deleted
;
3102 SetEntryCheck(e
,index
,true);
3105 for (std::vector
<int>::reverse_iterator it
= entriesToRemove
.rbegin(); it
!= entriesToRemove
.rend(); ++it
)
3107 RemoveListEntry(*it
);
3111 Show(m_dwShow
, 0, m_bShowFolders
);
3115 case IDSVNLC_DELETE
:
3117 CTSVNPathList pathlist
;
3118 FillListOfSelectedItemPaths(pathlist
);
3119 pathlist
.RemoveChildren();
3121 for (INT_PTR i
=0; i
<pathlist
.GetCount(); ++i
)
3123 filelist
+= pathlist
[i
].GetWinPathString();
3124 filelist
+= _T("|");
3126 filelist
+= _T("|");
3127 int len
= filelist
.GetLength();
3128 TCHAR
* buf
= new TCHAR
[len
+2];
3129 _tcscpy_s(buf
, len
+2, filelist
);
3130 for (int i
=0; i
<len
; ++i
)
3133 SHFILEOPSTRUCT fileop
;
3134 fileop
.hwnd
= this->m_hWnd
;
3135 fileop
.wFunc
= FO_DELETE
;
3138 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
3139 fileop
.lpszProgressTitle
= _T("deleting file");
3140 int result
= SHFileOperation(&fileop
);
3143 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
3146 POSITION pos
= NULL
;
3147 CTSVNPathList deletedlist
; // to store list of deleted folders
3148 while ((pos
= GetFirstSelectedItemPosition()) != 0)
3150 int index
= GetNextSelectedItem(pos
);
3151 if (GetCheck(index
))
3154 FileEntry
* fentry
= GetListEntry(index
);
3155 if ((fentry
)&&(fentry
->isfolder
))
3156 deletedlist
.AddPath(fentry
->path
);
3157 RemoveListEntry(index
);
3159 // now go through the list of deleted folders
3160 // and remove all their children from the list too!
3161 int nListboxEntries
= GetItemCount();
3162 for (int folderindex
= 0; folderindex
< deletedlist
.GetCount(); ++folderindex
)
3164 CTSVNPath folderpath
= deletedlist
[folderindex
];
3165 for (int i
=0; i
<nListboxEntries
; ++i
)
3167 FileEntry
* entry
= GetListEntry(i
);
3168 if (folderpath
.IsAncestorOf(entry
->path
))
3170 RemoveListEntry(i
--);
3184 CTSVNPathList itemsToAdd
;
3185 FillListOfSelectedItemPaths(itemsToAdd
);
3187 // We must sort items before adding, so that folders are always added
3188 // *before* any of their children
3189 itemsToAdd
.SortByPathname();
3191 ProjectProperties props
;
3192 props
.ReadPropsPathList(itemsToAdd
);
3193 if (git
.Add(itemsToAdd
, &props
, git_depth_empty
, TRUE
, TRUE
, TRUE
))
3195 // The add went ok, but we now need to run through the selected items again
3196 // and update their status
3197 POSITION pos
= GetFirstSelectedItemPosition();
3199 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3201 FileEntry
* e
= GetListEntry(index
);
3202 e
->textstatus
= git_wc_status_added
;
3203 e
->propstatus
= git_wc_status_none
;
3204 e
->status
= git_wc_status_added
;
3205 SetEntryCheck(e
,index
,true);
3210 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3213 Show(m_dwShow
, 0, m_bShowFolders
);
3217 case IDSVNLC_ADD_RECURSIVE
:
3219 CTSVNPathList itemsToAdd
;
3220 FillListOfSelectedItemPaths(itemsToAdd
);
3223 dlg
.m_pathList
= itemsToAdd
;
3224 if (dlg
.DoModal() == IDOK
)
3226 if (dlg
.m_pathList
.GetCount() == 0)
3228 CSVNProgressDlg progDlg
;
3229 progDlg
.SetCommand(CSVNProgressDlg::SVNProgress_Add
);
3230 progDlg
.SetPathList(dlg
.m_pathList
);
3231 ProjectProperties props
;
3232 props
.ReadPropsPathList(dlg
.m_pathList
);
3233 progDlg
.SetProjectProperties(props
);
3234 progDlg
.SetItemCount(dlg
.m_pathList
.GetCount());
3238 CWnd
* pParent
= GetParent();
3239 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3241 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
3247 case IDSVNLC_REPAIRMOVE
:
3249 POSITION pos
= GetFirstSelectedItemPosition();
3250 int index
= GetNextSelectedItem(pos
);
3251 FileEntry
* entry1
= NULL
;
3252 FileEntry
* entry2
= NULL
;
3255 entry1
= GetListEntry(index
);
3256 git_wc_status_kind status1
= git_wc_status_none
;
3257 git_wc_status_kind status2
= git_wc_status_none
;
3260 status1
= entry1
->status
;
3261 index
= GetNextSelectedItem(pos
);
3264 entry2
= GetListEntry(index
);
3267 status2
= entry2
->status
;
3268 if (status2
== git_wc_status_missing
&& status1
== git_wc_status_unversioned
)
3270 FileEntry
* tempentry
= entry1
;
3274 // entry1 was renamed to entry2 but outside of Subversion
3275 // fix this by moving entry2 back to entry1 first,
3276 // then do an git-move from entry1 to entry2
3277 if (MoveFile(entry2
->GetPath().GetWinPath(), entry1
->GetPath().GetWinPath()))
3280 if (!git
.Move(CTSVNPathList(entry1
->GetPath()), entry2
->GetPath(), TRUE
))
3282 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3286 // check the previously unversioned item
3287 entry1
->checked
= true;
3288 // fixing the move was successful. We have to adjust the new status of the
3290 // Since we don't know if the moved/renamed file had local modifications or not,
3291 // we can't guess the new status. That means we have to refresh...
3292 CWnd
* pParent
= GetParent();
3293 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3295 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
3302 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
3303 FORMAT_MESSAGE_FROM_SYSTEM
|
3304 FORMAT_MESSAGE_IGNORE_INSERTS
,
3307 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
3312 MessageBox((LPCTSTR
)lpMsgBuf
, _T("Error"), MB_OK
| MB_ICONINFORMATION
);
3313 LocalFree( lpMsgBuf
);
3321 case IDSVNLC_REMOVEFROMCS
:
3323 CTSVNPathList changelistItems
;
3324 FillListOfSelectedItemPaths(changelistItems
);
3327 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
3329 // The changelists were removed, but we now need to run through the selected items again
3330 // and update their changelist
3331 POSITION pos
= GetFirstSelectedItemPosition();
3333 std::vector
<int> entriesToRemove
;
3334 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3336 FileEntry
* e
= GetListEntry(index
);
3339 e
->changelist
.Empty();
3340 if (e
->status
== git_wc_status_normal
)
3342 // remove the entry completely
3343 entriesToRemove
.push_back(index
);
3346 SetItemGroup(index
, 0);
3349 for (std::vector
<int>::reverse_iterator it
= entriesToRemove
.rbegin(); it
!= entriesToRemove
.rend(); ++it
)
3351 RemoveListEntry(*it
);
3353 // TODO: Should we go through all entries here and check if we also could
3354 // remove the changelist from m_changelists ?
3358 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3363 case IDSVNLC_CREATEIGNORECS
:
3364 CreateChangeList(SVNSLC_IGNORECHANGELIST
);
3366 case IDSVNLC_CREATECS
:
3368 CCreateChangelistDlg dlg
;
3369 if (dlg
.DoModal() == IDOK
)
3371 CreateChangeList(dlg
.m_sName
);
3377 if (cmd
< IDSVNLC_MOVETOCS
)
3379 CTSVNPathList changelistItems
;
3380 FillListOfSelectedItemPaths(changelistItems
);
3382 // find the changelist name
3383 CString sChangelist
;
3384 int cmdID
= IDSVNLC_MOVETOCS
;
3386 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
3388 if ((it
->first
.Compare(SVNSLC_IGNORECHANGELIST
))&&(entry
->changelist
.Compare(it
->first
)))
3392 sChangelist
= it
->first
;
3397 if (!sChangelist
.IsEmpty())
3400 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
3402 // The changelists were moved, but we now need to run through the selected items again
3403 // and update their changelist
3404 POSITION pos
= GetFirstSelectedItemPosition();
3406 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3408 FileEntry
* e
= GetListEntry(index
);
3409 e
->changelist
= sChangelist
;
3412 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
3413 SetItemGroup(index
, m_changelists
[e
->changelist
]);
3415 SetItemGroup(index
, 0);
3421 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3431 AfxGetApp()->DoWaitCursor(-1);
3432 GetStatisticsString();
3433 //int iItemCountAfterMenuCmd = GetItemCount();
3434 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
3436 // CWnd* pParent = GetParent();
3437 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3439 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
3442 } // if (popup.CreatePopupMenu())
3443 } // if (selIndex >= 0)
3447 void CGitStatusListCtrl::OnContextMenuHeader(CWnd
* pWnd
, CPoint point
)
3449 Locker
lock(m_critSec
);
3450 m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
3453 void CGitStatusListCtrl::OnContextMenu(CWnd
* pWnd
, CPoint point
)
3458 OnContextMenuList(pWnd
, point
);
3459 } // if (pWnd == this)
3460 else if (pWnd
== GetHeaderCtrl())
3462 OnContextMenuHeader(pWnd
, point
);
3466 void CGitStatusListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3469 Locker
lock(m_critSec
);
3470 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
3475 if (pNMLV
->iItem
< 0)
3477 if (!IsGroupViewEnabled())
3480 DWORD ptW
= GetMessagePos();
3481 pt
.x
= GET_X_LPARAM(ptW
);
3482 pt
.y
= GET_Y_LPARAM(ptW
);
3483 ScreenToClient(&pt
);
3484 int group
= GetGroupFromPoint(&pt
);
3487 // check/uncheck the whole group depending on the check-state
3488 // of the first item in the group
3490 bool bCheck
= false;
3491 bool bFirst
= false;
3493 for (int i
=0; i
<GetItemCount(); ++i
)
3495 SecureZeroMemory(&lv
, sizeof(LVITEM
));
3496 lv
.mask
= LVIF_GROUPID
;
3499 if (lv
.iGroupId
== group
)
3501 CTGitPath
*entry
=(CTGitPath
*)GetItemData(i
);
3505 bCheck
= !GetCheck(i
);
3510 bool bOldCheck
= !!GetCheck(i
);
3511 SetEntryCheck(entry
, i
, bCheck
);
3512 if (bCheck
!= bOldCheck
)
3522 GetStatisticsString();
3528 CTGitPath
*file
=(CTGitPath
*)GetItemData(pNMLV
->iItem
);
3530 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
) {
3531 OpenFile(file
, OPEN
);
3534 if( file
->m_Action
&CTGitPath::LOGACTIONS_UNMERGED
)
3536 CAppUtils::ConflictEdit(*file
,false,m_bIsRevertTheirMy
);
3541 if( (!m_Rev1
.IsEmpty()) || (!m_Rev1
.IsEmpty())) // m_Rev1 twice???
3542 StartDiffTwo(pNMLV
->iItem
);
3544 StartDiff(pNMLV
->iItem
);
3548 void CGitStatusListCtrl::StartDiffTwo(int fileindex
)
3553 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3555 CGitDiff::Diff(&file1
,&file1
,
3560 void CGitStatusListCtrl::StartDiffWC(int fileindex
)
3566 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
3569 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3571 CGitDiff::Diff(&file1
,&file1
, GIT_REV_ZERO
, m_CurrentVersion
);
3575 void CGitStatusListCtrl::StartDiff(int fileindex
)
3580 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3582 if(file1
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
3584 file2
.SetFromGit(file1
.GetGitOldPathString());
3591 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
3594 if(m_amend
&& (file1
.m_Action
& CTGitPath::LOGACTIONS_ADDED
) == 0)
3595 fromwhere
= _T("~1");
3596 if( g_Git
.IsInitRepos())
3597 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3599 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_ADDED
)
3600 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3601 m_CurrentVersion
+fromwhere
,true);
3602 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_DELETED
)
3603 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3604 GitRev::GetHead()+fromwhere
,false);
3606 CGitDiff::Diff(&file1
,&file2
,
3607 CString(GIT_REV_ZERO
),
3608 GitRev::GetHead()+fromwhere
);
3613 CString fromwhere
= m_CurrentVersion
+_T("~1");
3615 fromwhere
= m_CurrentVersion
+_T("~2");
3616 if(rev
.GetCommit(fromwhere
) || (file1
.m_Action
== file1
.LOGACTIONS_ADDED
))
3618 CGitDiff::DiffNull(&file1
,m_CurrentVersion
,true);
3621 else if (file1
.m_Action
== file1
.LOGACTIONS_DELETED
)
3623 CGitDiff::DiffNull(&file1
,fromwhere
,false);
3627 if( file1
.m_ParentNo
& MERGE_MASK
)
3630 CTGitPath base
,theirs
, mine
;
3632 CTGitPath merge
=file1
;
3633 CTGitPath directory
= merge
.GetDirectory();
3635 mine
.SetFromGit(CAppUtils::GetMergeTempFile(_T("LOCAL"),merge
));
3636 theirs
.SetFromGit(CAppUtils::GetMergeTempFile(_T("REMOTE"),merge
));
3637 base
.SetFromGit(CAppUtils::GetMergeTempFile(_T("BASE"),merge
));
3640 //create a empty file, incase stage is not three
3641 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3643 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3645 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3648 merge
.SetFromGit(merge
.GetGitPathString()+_T("Merged"));
3650 int parent1
=-1, parent2
=-1;
3651 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
3653 if(m_arStatusArray
[i
]->GetGitPathString() == file1
.GetGitPathString())
3655 if(m_arStatusArray
[i
]->m_ParentNo
& MERGE_MASK
)
3662 parent1
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
3664 else if (parent2
<0)
3666 parent2
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
3672 if(g_Git
.GetOneFile(m_CurrentVersion
, file1
, (CString
&)merge
.GetWinPathString()))
3674 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3680 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent1
+1);
3682 if(g_Git
.GetOneFile(str
, file1
, (CString
&)mine
.GetWinPathString()))
3684 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3691 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent2
+1);
3693 if(g_Git
.GetOneFile(str
, file1
, (CString
&)theirs
.GetWinPathString()))
3695 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3699 if(parent1
>=0 && parent2
>=0)
3701 CString cmd
, output
;
3702 cmd
.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion
, parent1
+1,
3703 this->m_CurrentVersion
,parent2
+1);
3705 if(g_Git
.Run(cmd
, &output
, NULL
, CP_ACP
))
3710 if(g_Git
.GetOneFile(output
.Left(40), file1
, (CString
&)base
.GetWinPathString()))
3712 CMessageBox::Show(NULL
, _T("Fail to get base file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3716 CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
3722 if( (file1
.m_ParentNo
&PARENT_MASK
) == 0)
3728 str
.Format(_T("^%d"), (file1
.m_ParentNo
&PARENT_MASK
)+1);
3730 CGitDiff::Diff(&file1
,&file2
,
3732 m_CurrentVersion
+str
);
3739 FileEntry
* entry
= GetListEntry(fileindex
);
3740 ASSERT(entry
!= NULL
);
3743 if (((entry
->status
== git_wc_status_normal
)&&(entry
->remotestatus
<= git_wc_status_normal
))||
3744 (entry
->status
== git_wc_status_unversioned
)||(entry
->status
== git_wc_status_none
))
3746 int ret
= (int)ShellExecute(this->m_hWnd
, NULL
, entry
->path
.GetWinPath(), NULL
, NULL
, SW_SHOW
);
3747 if (ret
<= HINSTANCE_ERROR
)
3749 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
3750 cmd
+= entry
->path
.GetWinPathString();
3751 CAppUtils::LaunchApplication(cmd
, NULL
, false);
3756 GitDiff
diff(NULL
, m_hWnd
, true);
3757 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
3759 entry
->path
, entry
->textstatus
, entry
->propstatus
,
3760 entry
->remotetextstatus
, entry
->remotepropstatus
);
3764 CString
CGitStatusListCtrl::GetStatisticsString(bool simple
)
3767 CString sNormal
, sAdded
, sDeleted
, sModified
, sConflicted
, sUnversioned
, sRenamed
;
3768 WORD langID
= (WORD
)(DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3769 TCHAR buf
[MAX_STATUS_STRING_LENGTH
];
3770 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal
, buf
, _countof(buf
), langID
);
3772 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added
, buf
, _countof(buf
), langID
);
3774 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted
, buf
, _countof(buf
), langID
);
3776 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified
, buf
, _countof(buf
), langID
);
3778 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted
, buf
, _countof(buf
), langID
);
3780 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned
, buf
, _countof(buf
), langID
);
3782 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced
, buf
, _countof(buf
), langID
);
3787 sToolTip
.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d"),
3788 this->m_nLineAdded
,this->m_nLineDeleted
,
3789 (LPCTSTR
)sModified
, m_nModified
,
3790 (LPCTSTR
)sAdded
, m_nAdded
,
3791 (LPCTSTR
)sDeleted
, m_nDeleted
,
3792 (LPCTSTR
)sRenamed
, m_nRenamed
3797 sToolTip
.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d"),
3798 this->m_nLineAdded
,this->m_nLineDeleted
,
3799 (LPCTSTR
)sNormal
, m_nNormal
,
3800 (LPCTSTR
)sUnversioned
, m_nUnversioned
,
3801 (LPCTSTR
)sModified
, m_nModified
,
3802 (LPCTSTR
)sAdded
, m_nAdded
,
3803 (LPCTSTR
)sDeleted
, m_nDeleted
,
3804 (LPCTSTR
)sConflicted
, m_nConflicted
3808 sStats
.Format(IDS_COMMITDLG_STATISTICSFORMAT
, m_nSelected
, GetItemCount());
3811 m_pStatLabel
->SetWindowText(sStats
);
3814 if (m_pSelectButton
)
3816 if (m_nSelected
== 0)
3817 m_pSelectButton
->SetCheck(BST_UNCHECKED
);
3818 else if (m_nSelected
!= GetItemCount())
3819 m_pSelectButton
->SetCheck(BST_INDETERMINATE
);
3821 m_pSelectButton
->SetCheck(BST_CHECKED
);
3824 if (m_pConfirmButton
)
3826 m_pConfirmButton
->EnableWindow(m_nSelected
>0);
3834 CString
CGitStatusListCtrl::GetCommonDirectory(bool bStrict
)
3838 // not strict means that the selected folder has priority
3839 if (!m_StatusFileList
.GetCommonDirectory().IsEmpty())
3840 return m_StatusFileList
.GetCommonDirectory().GetWinPath();
3843 CTGitPath commonBaseDirectory
;
3844 int nListItems
= GetItemCount();
3845 for (int i
=0; i
<nListItems
; ++i
)
3847 CTGitPath baseDirectory
,*p
= (CTGitPath
*)this->GetItemData(i
);
3851 baseDirectory
= p
->GetDirectory();
3853 if(commonBaseDirectory
.IsEmpty())
3855 commonBaseDirectory
= baseDirectory
;
3859 if (commonBaseDirectory
.GetWinPathString().GetLength() > baseDirectory
.GetWinPathString().GetLength())
3861 if (baseDirectory
.IsAncestorOf(commonBaseDirectory
))
3862 commonBaseDirectory
= baseDirectory
;
3866 return g_Git
.m_CurrentDir
+CString(_T("\\"))+commonBaseDirectory
.GetWinPath();
3870 void CGitStatusListCtrl::SelectAll(bool bSelect
, bool /*bIncludeNoCommits*/)
3872 CWaitCursor waitCursor
;
3873 // block here so the LVN_ITEMCHANGED messages
3878 int nListItems
= GetItemCount();
3880 m_nSelected
= nListItems
;
3884 for (int i
=0; i
<nListItems
; ++i
)
3886 //FileEntry * entry = GetListEntry(i);
3887 //ASSERT(entry != NULL);
3888 CTGitPath
*path
= (CTGitPath
*) GetItemData(i
);
3891 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
3892 SetEntryCheck(path
,i
,bSelect
);
3895 // unblock before redrawing
3898 GetStatisticsString();
3902 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3904 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
3909 CTGitPath
*entry
=(CTGitPath
*)GetItemData(pGetInfoTip
->iItem
);
3912 if (pGetInfoTip
->cchTextMax
> entry
->GetGitPathString().GetLength() + g_Git
.m_CurrentDir
.GetLength())
3915 str
+= g_Git
.m_CurrentDir
;
3917 str
+= entry
->GetWinPathString();
3919 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, str
.GetBuffer(), str
.GetLength());
3923 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3925 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
3927 // Take the default processing unless we set this to something else below.
3928 *pResult
= CDRF_DODEFAULT
;
3930 // First thing - check the draw stage. If it's the control's prepaint
3931 // stage, then tell Windows we want messages for every item.
3933 switch (pLVCD
->nmcd
.dwDrawStage
)
3936 *pResult
= CDRF_NOTIFYITEMDRAW
;
3938 case CDDS_ITEMPREPAINT
:
3940 // This is the prepaint stage for an item. Here's where we set the
3941 // item's text color. Our return value will tell Windows to draw the
3942 // item itself, but it will use the new color we set here.
3944 // Tell Windows to paint the control itself.
3945 *pResult
= CDRF_DODEFAULT
;
3949 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
3951 if (m_arStatusArray
.size() > (DWORD_PTR
)pLVCD
->nmcd
.dwItemSpec
)
3954 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3955 CTGitPath
*entry
=(CTGitPath
*)GetItemData((int)pLVCD
->nmcd
.dwItemSpec
);
3961 // black : unversioned, normal
3964 // brown : missing, deleted, replaced
3965 // green : merged (or potential merges)
3966 // red : conflicts or sure conflicts
3967 if(entry
->m_Action
& CTGitPath::LOGACTIONS_GRAY
)
3969 crText
= RGB(128,128,128);
3972 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
3974 crText
= m_Colors
.GetColor(CColors::Conflict
);
3977 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_MODIFIED
))
3979 crText
= m_Colors
.GetColor(CColors::Modified
);
3982 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
3984 crText
= m_Colors
.GetColor(CColors::Added
);
3986 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3988 crText
= m_Colors
.GetColor(CColors::DeletedNode
);
3990 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
3992 crText
= m_Colors
.GetColor(CColors::RenamedNode
);
3994 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_MERGED
)
3996 crText
= m_Colors
.GetColor(CColors::Merged
);
4000 crText
= GetSysColor(COLOR_WINDOWTEXT
);
4002 // Store the color back in the NMLVCUSTOMDRAW struct.
4003 pLVCD
->clrText
= crText
;
4010 BOOL
CGitStatusListCtrl::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
4013 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
4016 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
4018 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
4020 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_WAIT
));
4025 void CGitStatusListCtrl::RemoveListEntry(int index
)
4028 Locker
lock(m_critSec
);
4031 m_arStatusArray
.erase(m_arStatusArray
.begin()+index
);
4034 delete m_arStatusArray
[m_arListArray
[index
]];
4035 m_arStatusArray
.erase(m_arStatusArray
.begin()+m_arListArray
[index
]);
4036 m_arListArray
.erase(m_arListArray
.begin()+index
);
4037 for (int i
=index
; i
< (int)m_arListArray
.size(); ++i
)
4044 ///< Set a checkbox on an entry in the listbox
4045 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
4046 void CGitStatusListCtrl::SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
)
4048 pEntry
->m_Checked
= bCheck
;
4049 SetCheck(listboxIndex
, bCheck
);
4053 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry
* parentEntry
, bool bCheck
)
4056 int nListItems
= GetItemCount();
4057 for (int j
=0; j
< nListItems
; ++j
)
4059 FileEntry
* childEntry
= GetListEntry(j
);
4060 ASSERT(childEntry
!= NULL
);
4061 if (childEntry
== NULL
|| childEntry
== parentEntry
)
4063 if (childEntry
->checked
!= bCheck
)
4065 if (parentEntry
->path
.IsAncestorOf(childEntry
->path
))
4067 SetEntryCheck(childEntry
,j
,bCheck
);
4083 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList
& pathList
)
4087 int nListItems
= GetItemCount();
4088 for (int i
=0; i
< nListItems
; i
++)
4090 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
4091 ASSERT(entry
!= NULL
);
4092 if (entry
->m_Checked
)
4094 pathList
.AddPath(*entry
);
4097 pathList
.SortByPathname();
4102 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
4103 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool /*bNoIgnored*/)
4107 POSITION pos
= GetFirstSelectedItemPosition();
4109 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4111 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
4112 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
4114 pathList
.AddPath(*entry
);
4118 UINT
CGitStatusListCtrl::OnGetDlgCode()
4120 // we want to process the return key and not have that one
4121 // routed to the default pushbutton
4122 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS
;
4125 void CGitStatusListCtrl::OnNMReturn(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
4130 POSITION pos
= GetFirstSelectedItemPosition();
4133 int index
= GetNextSelectedItem(pos
);
4134 CTGitPath
*file
=(CTGitPath
*)GetItemData(index
);
4135 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
)
4137 OpenFile(file
, OPEN
);
4146 void CGitStatusListCtrl::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
4148 // Since we catch all keystrokes (to have the enter key processed here instead
4149 // of routed to the default pushbutton) we have to make sure that other
4150 // keys like Tab and Esc still do what they're supposed to do
4151 // Tab = change focus to next/previous control
4152 // Esc = quit the dialog
4157 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL
, GetKeyState(VK_SHIFT
)&0x8000, 0);
4163 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE
, 0, 0);
4168 CListCtrl::OnKeyDown(nChar
, nRepCnt
, nFlags
);
4171 void CGitStatusListCtrl::PreSubclassWindow()
4173 CListCtrl::PreSubclassWindow();
4174 EnableToolTips(TRUE
);
4175 SetWindowTheme(GetSafeHwnd(), L
"Explorer", NULL
);
4178 INT_PTR
CGitStatusListCtrl::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4182 row
= CellRectFromPoint(point
, &cellrect
, &col
);
4189 pTI
->uId
= (UINT
)((row
<<10)+(col
&0x3ff)+1);
4190 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4192 pTI
->rect
= cellrect
;
4197 int CGitStatusListCtrl::CellRectFromPoint(CPoint
& point
, RECT
*cellrect
, int *col
) const
4201 // Make sure that the ListView is in LVS_REPORT
4202 if ((GetWindowLong(m_hWnd
, GWL_STYLE
) & LVS_TYPEMASK
) != LVS_REPORT
)
4205 // Get the top and bottom row visible
4206 int row
= GetTopIndex();
4207 int bottom
= row
+ GetCountPerPage();
4208 if (bottom
> GetItemCount())
4209 bottom
= GetItemCount();
4211 // Get the number of columns
4212 CHeaderCtrl
* pHeader
= (CHeaderCtrl
*)GetDlgItem(0);
4213 int nColumnCount
= pHeader
->GetItemCount();
4215 // Loop through the visible rows
4216 for ( ;row
<=bottom
;row
++)
4218 // Get bounding rect of item and check whether point falls in it.
4220 GetItemRect(row
, &rect
, LVIR_BOUNDS
);
4221 if (rect
.PtInRect(point
))
4223 // Now find the column
4224 for (colnum
= 0; colnum
< nColumnCount
; colnum
++)
4226 int colwidth
= GetColumnWidth(colnum
);
4227 if (point
.x
>= rect
.left
&& point
.x
<= (rect
.left
+ colwidth
))
4230 GetClientRect(&rectClient
);
4233 rect
.right
= rect
.left
+ colwidth
;
4235 // Make sure that the right extent does not exceed
4237 if (rect
.right
> rectClient
.right
)
4238 rect
.right
= rectClient
.right
;
4242 rect
.left
+= colwidth
;
4249 BOOL
CGitStatusListCtrl::OnToolTipText(UINT
/*id*/, NMHDR
* /*pNMHDR*/, LRESULT
* /*pResult*/)
4252 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4254 UINT_PTR nID
= pNMHDR
->idFrom
;
4259 UINT_PTR row
= ((nID
-1) >> 10) & 0x3fffff;
4260 UINT_PTR col
= (nID
-1) & 0x3ff;
4263 return FALSE
; // no custom tooltip for the path, we use the infotip there!
4265 // get the internal column from the visible columns
4266 int internalcol
= 0;
4267 UINT_PTR currentcol
= 0;
4268 for (; (currentcol
!= col
)
4269 && (internalcol
< m_ColumnManager
.GetColumnCount()-1)
4272 if (m_ColumnManager
.IsVisible (internalcol
))
4276 AFX_MODULE_THREAD_STATE
* pModuleThreadState
= AfxGetModuleThreadState();
4277 CToolTipCtrl
* pToolTip
= pModuleThreadState
->m_pToolTip
;
4278 pToolTip
->SendMessage(TTM_SETMAXTIPWIDTH
, 0, 300);
4281 if ((internalcol
== 2)||(internalcol
== 4))
4283 FileEntry
*fentry
= GetListEntry(row
);
4289 url
.Format(IDS_STATUSLIST_COPYFROM
, (LPCTSTR
)CPathUtils::PathUnescape(fentry
->copyfrom_url
), (LONG
)fentry
->copyfrom_rev
);
4290 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)url
, 80);
4293 if (fentry
->switched
)
4296 url
.Format(IDS_STATUSLIST_SWITCHEDTO
, (LPCTSTR
)CPathUtils::PathUnescape(fentry
->url
));
4297 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)url
, 80);
4300 if (fentry
->keeplocal
)
4302 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_KEEPLOCAL
)), 80);
4311 void CGitStatusListCtrl::OnPaint()
4314 if ((m_bBusy
)||(m_bEmpty
))
4319 if (m_sBusy
.IsEmpty())
4320 str
.LoadString(IDS_STATUSLIST_BUSYMSG
);
4326 if (m_sEmpty
.IsEmpty())
4327 str
.LoadString(IDS_STATUSLIST_EMPTYMSG
);
4331 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
4333 if (IsWindowEnabled())
4334 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
4336 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
4341 pHC
= GetHeaderCtrl();
4345 pHC
->GetItemRect(0, &rcH
);
4346 rc
.top
+= rcH
.bottom
;
4350 CMyMemDC
memDC(pDC
, &rc
);
4352 memDC
.SetTextColor(clrText
);
4353 memDC
.SetBkColor(clrTextBk
);
4354 memDC
.FillSolidRect(rc
, clrTextBk
);
4356 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
4357 memDC
.DrawText(str
, rc
, DT_CENTER
| DT_VCENTER
|
4358 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
4359 memDC
.SelectObject(oldfont
);
4365 // prevent users from extending our hidden (size 0) columns
4366 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4368 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
4371 // prevent any function from extending our hidden (size 0) columns
4372 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4374 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
4378 void CGitStatusListCtrl::OnDestroy()
4380 SaveColumnWidths(true);
4381 CListCtrl::OnDestroy();
4384 void CGitStatusListCtrl::OnBeginDrag(NMHDR
* /*pNMHDR*/, LRESULT
* pResult
)
4387 Locker
lock(m_critSec
);
4388 CDropFiles dropFiles
; // class for creating DROPFILES struct
4391 POSITION pos
= GetFirstSelectedItemPosition();
4392 while ( (index
= GetNextSelectedItem(pos
)) >= 0 )
4394 FileEntry
* fentry
= m_arStatusArray
[m_arListArray
[index
]];
4395 CTGitPath path
= fentry
->GetPath();
4396 dropFiles
.AddFile( path
.GetWinPathString() );
4399 if ( dropFiles
.GetCount()>0 )
4402 dropFiles
.CreateStructure();
4409 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry
/* = false */)
4411 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
4412 for (int col
= 0; col
<= maxcol
; col
++)
4413 if (m_ColumnManager
.IsVisible (col
))
4414 m_ColumnManager
.ColumnResized (col
);
4416 if (bSaveToRegistry
)
4417 m_ColumnManager
.WriteSettings();
4420 bool CGitStatusListCtrl::EnableFileDrop()
4422 m_bFileDropsEnabled
= true;
4426 bool CGitStatusListCtrl::HasPath(const CTGitPath
& path
)
4428 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
4430 if (m_arStatusArray
[i
]->IsEquivalentTo(path
))
4437 BOOL
CGitStatusListCtrl::PreTranslateMessage(MSG
* pMsg
)
4439 if (pMsg
->message
== WM_KEYDOWN
)
4441 switch (pMsg
->wParam
)
4445 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
4447 // select all entries
4448 for (int i
=0; i
<GetItemCount(); ++i
)
4450 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
4459 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
4461 // copy all selected paths to the clipboard
4462 if (GetAsyncKeyState(VK_SHIFT
)&0x8000)
4463 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS
);
4465 CopySelectedEntriesToClipboard(0);
4473 return CListCtrl::PreTranslateMessage(pMsg
);
4476 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols
)
4479 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
4480 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
4481 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4486 if (GetSelectedCount() == 0)
4489 // first add the column titles as the first line
4490 // We needn't head when only path copy
4491 //temp.LoadString(IDS_STATUSLIST_COLFILE);
4492 //sClipboard = temp;
4494 DWORD selection
= 0;
4495 for (int i
= 0, count
= m_ColumnManager
.GetColumnCount(); i
< count
; ++i
)
4496 if ( ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
4497 || ((dwCols
!= 1) && (i
< 32) && ((dwCols
& (1 << i
)) != 0)))
4499 sClipboard
+= _T("\t") + m_ColumnManager
.GetName(i
);
4502 selection
+= 1 << i
;
4506 sClipboard
+= _T("\r\n");
4508 POSITION pos
= GetFirstSelectedItemPosition();
4510 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4512 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
4516 sClipboard
+= entry
->GetWinPathString();
4517 if (selection
& GITSLC_COLFILENAME
)
4519 sClipboard
+= _T("\t")+entry
->GetFileOrDirectoryName();
4521 if (selection
& GITSLC_COLEXT
)
4523 sClipboard
+= _T("\t")+entry
->GetFileExtension();
4526 if (selection
& GITSLC_COLSTATUS
)
4529 if (entry
->isNested
)
4531 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4535 GitStatus::GetStatusString(hResourceHandle
, entry
->status
, buf
, _countof(buf
), (WORD
)langID
);
4536 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4537 _tcscat_s(buf
, 100, _T(" (+)"));
4538 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4539 _tcscat_s(buf
, 100, _T(" (s)"));
4540 if ((entry
->status
== entry
->propstatus
)&&
4541 (entry
->status
!= git_wc_status_normal
)&&
4542 (entry
->status
!= git_wc_status_unversioned
)&&
4543 (!GitStatus::IsImportant(entry
->textstatus
)))
4544 _tcscat_s(buf
, 100, ponly
);
4548 sClipboard
+= _T("\t")+entry
->GetActionName();
4551 if (selection
& SVNSLC_COLTEXTSTATUS
)
4554 if (entry
->isNested
)
4556 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4560 GitStatus::GetStatusString(hResourceHandle
, entry
->textstatus
, buf
, _countof(buf
), (WORD
)langID
);
4561 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4562 _tcscat_s(buf
, 100, _T(" (+)"));
4563 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4564 _tcscat_s(buf
, 100, _T(" (s)"));
4567 sClipboard
+= _T("\t")+temp
;
4571 if (selection
& SVNSLC_COLREMOTESTATUS
)
4573 if (entry
->isNested
)
4575 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4579 GitStatus::GetStatusString(hResourceHandle
, entry
->remotestatus
, buf
, _countof(buf
), (WORD
)langID
);
4580 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4581 _tcscat_s(buf
, 100, _T(" (+)"));
4582 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4583 _tcscat_s(buf
, 100, _T(" (s)"));
4584 if ((entry
->remotestatus
== entry
->remotepropstatus
)&&
4585 (entry
->remotestatus
!= git_wc_status_none
)&&
4586 (entry
->remotestatus
!= git_wc_status_normal
)&&
4587 (entry
->remotestatus
!= git_wc_status_unversioned
)&&
4588 (!SVNStatus::IsImportant(entry
->remotetextstatus
)))
4589 _tcscat_s(buf
, 100, ponly
);
4592 sClipboard
+= _T("\t")+temp
;
4594 if (selection
& GitSLC_COLPROPSTATUS
)
4596 if (entry
->isNested
)
4602 GitStatus::GetStatusString(hResourceHandle
, entry
->propstatus
, buf
, _countof(buf
), (WORD
)langID
);
4603 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4604 _tcscat_s(buf
, 100, _T(" (+)"));
4605 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4606 _tcscat_s(buf
, 100, _T(" (s)"));
4609 sClipboard
+= _T("\t")+temp
;
4611 if (selection
& SVNSLC_COLREMOTETEXT
)
4613 if (entry
->isNested
)
4619 GitStatus::GetStatusString(hResourceHandle
, entry
->remotetextstatus
, buf
, _countof(buf
), (WORD
)langID
);
4622 sClipboard
+= _T("\t")+temp
;
4624 if (selection
& SVNSLC_COLREMOTEPROP
)
4626 // SVNSLC_COLREMOTEPROP
4627 if (entry
->isNested
)
4633 GitStatus::GetStatusString(hResourceHandle
, entry
->remotepropstatus
, buf
, _countof(buf
), (WORD
)langID
);
4636 sClipboard
+= _T("\t")+temp
;
4638 if (selection
& SVNSLC_COLURL
)
4639 sClipboard
+= _T("\t")+entry
->url
;
4640 if (selection
& SVNSLC_COLLOCK
)
4642 if (!m_HeadRev
.IsHead())
4644 // we have contacted the repository
4647 // wc repository text
4651 // UID1 "" lock has been broken
4652 // UID1 UID2 lock has been stolen
4653 if (entry
->lock_token
.IsEmpty() || (entry
->lock_token
.Compare(entry
->lock_remotetoken
)==0))
4655 if (entry
->lock_owner
.IsEmpty())
4656 temp
= entry
->lock_remoteowner
;
4658 temp
= entry
->lock_owner
;
4660 else if (entry
->lock_remotetoken
.IsEmpty())
4663 temp
.LoadString(IDS_STATUSLIST_LOCKBROKEN
);
4668 temp
.Format(IDS_STATUSLIST_LOCKSTOLEN
, (LPCTSTR
)entry
->lock_remoteowner
);
4672 temp
= entry
->lock_owner
;
4673 sClipboard
+= _T("\t")+temp
;
4675 if (selection
& SVNSLC_COLLOCKCOMMENT
)
4676 sClipboard
+= _T("\t")+entry
->lock_comment
;
4677 if (selection
& SVNSLC_COLAUTHOR
)
4678 sClipboard
+= _T("\t")+entry
->last_commit_author
;
4679 if (selection
& SVNSLC_COLREVISION
)
4681 temp
.Format(_T("%ld"), entry
->last_commit_rev
);
4682 if (entry
->last_commit_rev
== 0)
4684 sClipboard
+= _T("\t")+temp
;
4686 if (selection
& SVNSLC_COLREMOTEREVISION
)
4688 temp
.Format(_T("%ld"), entry
->remoterev
);
4689 if (entry
->remoterev
== 0)
4691 sClipboard
+= _T("\t")+temp
;
4694 if (selection
& SVNSLC_COLDATE
)
4696 TCHAR datebuf
[SVN_DATE_BUFFER
];
4697 apr_time_t date
= entry
->last_commit_date
;
4698 SVN::formatDate(datebuf
, date
, true);
4703 sClipboard
+= _T("\t")+temp
;
4705 if (selection
& SVNSLC_COLCOPYFROM
)
4707 if (m_sURL
.Compare(entry
->copyfrom_url
.Left(m_sURL
.GetLength()))==0)
4708 temp
= entry
->copyfrom_url
.Mid(m_sURL
.GetLength());
4710 temp
= entry
->copyfrom_url
;
4711 sClipboard
+= _T("\t")+temp
;
4714 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
4718 if ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
4721 = entry
->present_props
[m_ColumnManager
.GetName(i
)];
4722 sClipboard
+= _T("\t") + value
;
4726 if (selection
& GITSLC_COLADD
)
4728 sClipboard
+= _T("\t")+entry
->m_StatAdd
;
4730 if (selection
& GITSLC_COLDEL
)
4732 sClipboard
+= _T("\t")+entry
->m_StatDel
;
4735 sClipboard
+= _T("\r\n");
4738 return CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
4744 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
4747 std::set
<CString
> changelists
;
4748 POSITION pos
= GetFirstSelectedItemPosition();
4750 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4752 FileEntry
* entry
= GetListEntry(index
);
4753 if (!entry
->changelist
.IsEmpty())
4754 changelists
.insert(entry
->changelist
);
4756 return changelists
.size();
4761 bool CGitStatusListCtrl::PrepareGroups(bool bForce
/* = false */)
4764 bool bHasGroups
=false;
4767 for(int i
=0;i
< this->m_arStatusArray
.size(); i
++)
4769 int ParentNo
= m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
4771 max
=m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
4774 if ( this->m_UnRevFileList
.GetCount()>0 ||
4775 this->m_IgnoreFileList
.GetCount()>0 ||
4782 EnableGroupView(bHasGroups
);
4784 TCHAR groupname
[1024];
4790 grp
.cbSize
= sizeof(LVGROUP
);
4791 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4794 //if(m_UnRevFileList.GetCount()>0)
4797 grp
.pszHeader
= _T("Merged Files");
4798 grp
.iGroupId
= MERGE_MASK
;
4799 grp
.uAlign
= LVGA_HEADER_LEFT
;
4800 InsertGroup(0, &grp
);
4802 for(int i
=0;i
<=max
;i
++)
4805 str
.Format(_T("Diff with parent %d"), i
+1);
4806 //_tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Not Versioned"), 1023);
4807 grp
.pszHeader
= str
.GetBuffer();
4809 grp
.uAlign
= LVGA_HEADER_LEFT
;
4810 InsertGroup(i
+1, &grp
);
4815 CString
sUnassignedName(_T("Modified File"));
4816 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
4817 grp
.pszHeader
= groupname
;
4818 grp
.iGroupId
= groupindex
;
4819 grp
.uAlign
= LVGA_HEADER_LEFT
;
4820 InsertGroup(groupindex
++, &grp
);
4824 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)_T("Not Versioned"), 1023);
4825 grp
.pszHeader
= groupname
;
4826 grp
.iGroupId
= groupindex
;
4827 grp
.uAlign
= LVGA_HEADER_LEFT
;
4828 InsertGroup(groupindex
++, &grp
);
4831 //if(m_IgnoreFileList.GetCount()>0)
4833 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)_T("Ignored"), 1023);
4834 grp
.pszHeader
= groupname
;
4835 grp
.iGroupId
= groupindex
;
4836 grp
.uAlign
= LVGA_HEADER_LEFT
;
4837 InsertGroup(groupindex
++, &grp
);
4843 m_bHasIgnoreGroup
= false;
4845 // now add the items which don't belong to a group
4847 grp
.cbSize
= sizeof(LVGROUP
);
4848 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4849 CString
sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET
));
4850 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
4851 grp
.pszHeader
= groupname
;
4852 grp
.iGroupId
= groupindex
;
4853 grp
.uAlign
= LVGA_HEADER_LEFT
;
4854 InsertGroup(groupindex
++, &grp
);
4856 for (std::map
<CString
,int>::iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
4858 if (it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)!=0)
4861 grp
.cbSize
= sizeof(LVGROUP
);
4862 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4863 _tcsncpy_s(groupname
, 1024, it
->first
, 1023);
4864 grp
.pszHeader
= groupname
;
4865 grp
.iGroupId
= groupindex
;
4866 grp
.uAlign
= LVGA_HEADER_LEFT
;
4867 it
->second
= InsertGroup(groupindex
++, &grp
);
4870 m_bHasIgnoreGroup
= true;
4873 if (m_bHasIgnoreGroup
)
4875 // and now add the group 'ignore-on-commit'
4876 std::map
<CString
,int>::iterator it
= m_changelists
.find(SVNSLC_IGNORECHANGELIST
);
4877 if (it
!= m_changelists
.end())
4879 grp
.cbSize
= sizeof(LVGROUP
);
4880 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4881 _tcsncpy_s(groupname
, 1024, SVNSLC_IGNORECHANGELIST
, 1023);
4882 grp
.pszHeader
= groupname
;
4883 grp
.iGroupId
= groupindex
;
4884 grp
.uAlign
= LVGA_HEADER_LEFT
;
4885 it
->second
= InsertGroup(groupindex
, &grp
);
4892 void CGitStatusListCtrl::NotifyCheck()
4894 CWnd
* pParent
= GetParent();
4895 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
4897 pParent
->SendMessage(GITSLNM_CHECKCHANGED
, m_nSelected
);
4901 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash
,CTGitPathList
*list
)
4905 m_CurrentVersion
=hash
;
4911 count
= list
->GetCount();
4913 CString head
= _T("HEAD");
4915 head
= _T("HEAD~1");
4917 if(hash
== GIT_REV_ZERO
)
4919 for(int i
=0;i
<count
;i
++)
4924 if(!g_Git
.IsInitRepos())
4926 // also list staged files which will be in the commit
4927 cmd
=(_T("git.exe diff-index --cached --raw ") + head
+ _T(" --numstat -C -M -z"));
4928 g_Git
.Run(cmd
, &cmdout
);
4931 cmd
=(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z"));
4933 cmd
.Format(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z -- \"%s\""),(*list
)[i
].GetGitPathString());
4936 if(g_Git
.Run(cmd
, &cmdout
, &cmdErr
))
4938 int last
= cmdErr
.RevertFind(0,-1);
4942 g_Git
.StringAppend(&str
, &cmdErr
[last
+1], CP_ACP
, cmdErr
.size() - last
-1);
4943 CMessageBox::Show(NULL
,str
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
4948 CString strout
, err
;
4949 if (g_Git
.Run(_T("git.exe rev-parse --revs-only ") + head
, &strout
, &err
, CP_UTF8
))
4951 CMessageBox::Show(NULL
, strout
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
);
4954 if(strout
.IsEmpty() && err
.IsEmpty())
4955 break; //this is initial repository, there are no any history
4957 CMessageBox::Show(NULL
, strout
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
);
4962 out
.append(cmdout
, 0);
4964 else // Init Repository
4966 //We will list all added file for init repository because commit will comit these
4968 cmd
=_T("git.exe ls-files -s -t -z");
4970 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
4972 g_Git
.Run(cmd
, &cmdout
);
4974 out
.append(cmdout
,0);
4978 if(g_Git
.IsInitRepos())
4980 m_StatusFileList
.ParserFromLsFile(out
);
4981 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
4982 ((CTGitPath
&)(m_StatusFileList
[i
])).m_Action
=CTGitPath::LOGACTIONS_ADDED
;
4985 this->m_StatusFileList
.ParserFromLog(out
);
4987 //handle delete conflict case, when remote : modified, local : deleted.
4988 for(int i
=0;i
<count
;i
++)
4994 cmd
=_T("git.exe ls-files -u -t -z");
4996 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list
)[i
].GetGitPathString());
4998 g_Git
.Run(cmd
, &cmdout
);
5000 CTGitPathList conflictlist
;
5001 conflictlist
.ParserFromLog(cmdout
);
5002 for(int i
=0;i
<conflictlist
.GetCount();i
++)
5004 CTGitPath
*p
=m_StatusFileList
.LookForGitPath(conflictlist
[i
].GetGitPathString());
5006 p
->m_Action
|=CTGitPath::LOGACTIONS_UNMERGED
;
5008 m_StatusFileList
.AddPath(conflictlist
[i
]);
5012 // handle source files of file renames/moves (issue #860)
5013 // if a file gets renamed and the new file "git add"ed, diff-index doesn't list the source file anymore
5014 for(int i
= 0; i
< count
; i
++)
5020 cmd
= _T("git.exe ls-files -d -z");
5022 cmd
.Format(_T("git.exe ls-files -d -z -- \"%s\""),(*list
)[i
].GetGitPathString());
5024 g_Git
.Run(cmd
, &cmdout
);
5026 CTGitPathList deletelist
;
5027 deletelist
.ParserFromLog(cmdout
, true);
5028 for(int i
= 0; i
< deletelist
.GetCount(); i
++)
5030 CTGitPath
*p
= m_StatusFileList
.LookForGitPath(deletelist
[i
].GetGitPathString());
5032 m_StatusFileList
.AddPath(deletelist
[i
]);
5042 count
= list
->GetCount();
5044 for(int i
=0;i
<count
;i
++)
5049 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash
);
5051 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash
,(*list
)[i
].GetGitPathString());
5053 g_Git
.Run(cmd
, &cmdout
, NULL
);
5057 this->m_StatusFileList
.ParserFromLog(out
);
5061 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
5063 CTGitPath
* gitpatch
=(CTGitPath
*)&m_StatusFileList
[i
];
5064 gitpatch
->m_Checked
= TRUE
;
5065 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
5068 this->m_bBusy
=FALSE
;
5072 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList
&list
)
5074 m_arStatusArray
.clear();
5075 for(int i
=0;i
<list
.GetCount();i
++)
5077 CTGitPath
* gitpath
=(CTGitPath
*)&list
[i
];
5079 if(gitpath
->m_Action
& CTGitPath::LOGACTIONS_HIDE
)
5082 gitpath
->m_Checked
= TRUE
;
5083 m_arStatusArray
.push_back((CTGitPath
*)&list
[i
]);
5088 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
*List
)
5090 this->m_UnRevFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
,List
);
5091 for(int i
=0;i
<m_UnRevFileList
.GetCount();i
++)
5093 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
5094 gitpatch
->m_Checked
= FALSE
;
5095 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
5100 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList
*List
)
5102 this->m_IgnoreFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
|CTGitPath::LOGACTIONS_IGNORE
,List
);
5103 for(int i
=0;i
<m_IgnoreFileList
.GetCount();i
++)
5105 CTGitPath
* gitpatch
=(CTGitPath
*)&m_IgnoreFileList
[i
];
5106 gitpatch
->m_Checked
= FALSE
;
5107 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
5111 int CGitStatusListCtrl::UpdateFileList(int mask
,bool once
,CTGitPathList
*List
)
5113 if(mask
&CGitStatusListCtrl::FILELIST_MODIFY
)
5115 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_MODIFY
)))
5117 UpdateFileList(git_revnum_t(GIT_REV_ZERO
),List
);
5118 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_MODIFY
;
5121 if(mask
&CGitStatusListCtrl::FILELIST_UNVER
)
5123 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_UNVER
)))
5125 UpdateUnRevFileList(List
);
5126 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
5128 if(mask
&CGitStatusListCtrl::FILELIST_IGNORE
&& (once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_IGNORE
))))
5130 UpdateIgnoreFileList(List
);
5131 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
5137 void CGitStatusListCtrl::Clear()
5140 this->DeleteAllItems();
5141 this->m_arListArray
.clear();
5142 this->m_arStatusArray
.clear();
5143 this->m_changelists
.clear();
5145 //////////////////////////////////////////////////////////////////////////
5147 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
)
5149 if(pFmtEtc
->cfFormat
== CF_HDROP
&& medium
.tymed
== TYMED_HGLOBAL
)
5151 HDROP hDrop
= (HDROP
)GlobalLock(medium
.hGlobal
);
5154 TCHAR szFileName
[MAX_PATH
];
5156 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, NULL
, 0);
5159 clientpoint
.x
= pt
.x
;
5160 clientpoint
.y
= pt
.y
;
5161 ScreenToClient(m_hTargetWnd
, &clientpoint
);
5162 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
5164 CTSVNPathList changelistItems
;
5165 for(UINT i
= 0; i
< cFiles
; ++i
)
5167 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
5168 changelistItems
.AddPath(CTSVNPath(szFileName
));
5170 // find the changelist name
5171 CString sChangelist
;
5172 LONG_PTR nGroup
= m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
);
5173 for (std::map
<CString
, int>::iterator it
= m_pSVNStatusListCtrl
->m_changelists
.begin(); it
!= m_pSVNStatusListCtrl
->m_changelists
.end(); ++it
)
5174 if (it
->second
== nGroup
)
5175 sChangelist
= it
->first
;
5176 if (!sChangelist
.IsEmpty())
5179 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
5181 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
5183 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
5186 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
5189 e
->changelist
= sChangelist
;
5192 if (m_pSVNStatusListCtrl
->m_changelists
.find(e
->changelist
)!=m_pSVNStatusListCtrl
->m_changelists
.end())
5193 m_pSVNStatusListCtrl
->SetItemGroup(index
, m_pSVNStatusListCtrl
->m_changelists
[e
->changelist
]);
5195 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
5201 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5202 if (hParentWnd
!= NULL
)
5203 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
5209 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
5215 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
5217 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
5219 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
5222 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
5225 e
->changelist
= sChangelist
;
5226 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
5231 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5232 if (hParentWnd
!= NULL
)
5233 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
5239 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
5245 for(UINT i
= 0; i
< cFiles
; ++i
)
5247 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
5248 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5249 if (hParentWnd
!= NULL
)
5250 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)szFileName
);
5254 GlobalUnlock(medium
.hGlobal
);
5256 return true; //let base free the medium
5258 HRESULT STDMETHODCALLTYPE
CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
)
5260 CIDropTarget::DragOver(grfKeyState
, pt
, pdwEffect
);
5261 *pdwEffect
= DROPEFFECT_COPY
;
5262 if (m_pSVNStatusListCtrl
)
5265 clientpoint
.x
= pt
.x
;
5266 clientpoint
.y
= pt
.y
;
5267 ScreenToClient(m_hTargetWnd
, &clientpoint
);
5268 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
5270 *pdwEffect
= DROPEFFECT_MOVE
;
5272 else if ((!m_pSVNStatusListCtrl
->m_bFileDropsEnabled
)||(m_pSVNStatusListCtrl
->m_bOwnDrag
))
5274 *pdwEffect
= DROPEFFECT_NONE
;
5282 void CGitStatusListCtrl::FileSaveAs(CTGitPath
*path
)
5285 filename
.Format(_T("%s-%s%s"),path
->GetBaseFilename(),this->m_CurrentVersion
.Left(6),path
->GetFileExtension());
5286 CFileDialog
dlg(FALSE
,NULL
,
5288 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
5290 CString currentpath
;
5291 currentpath
=g_Git
.m_CurrentDir
+_T("\\");
5292 currentpath
+=path
->GetWinPathString();
5294 dlg
.m_ofn
.lpstrInitialDir
=currentpath
.GetBuffer();
5297 if(dlg
.DoModal()==IDOK
)
5299 filename
= dlg
.GetPathName();
5300 if(m_CurrentVersion
== GIT_REV_ZERO
)
5302 if(!CopyFile(g_Git
.m_CurrentDir
+_T("\\") + path
->GetWinPath(),filename
,false))
5304 LPVOID lpMsgBuf
=NULL
;
5305 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
5306 NULL
,GetLastError(),MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
5309 CMessageBox::Show(NULL
,(TCHAR
*)lpMsgBuf
,_T("TortoiseGit"),MB_OK
);
5310 LocalFree(lpMsgBuf
);
5317 if(g_Git
.GetOneFile(m_CurrentVersion
,*path
,filename
))
5319 out
.Format(_T("Fail checkout one file %s;%s"),m_CurrentVersion
, path
->GetWinPath());
5320 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5328 int CGitStatusListCtrl::RevertSelectedItemToVersion()
5330 if(this->m_CurrentVersion
.IsEmpty())
5332 if(this->m_CurrentVersion
== GIT_REV_ZERO
)
5335 POSITION pos
= GetFirstSelectedItemPosition();
5339 while ((index
= GetNextSelectedItem(pos
)) >= 0)
5341 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
5342 cmd
.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion
,fentry
->GetGitPathString());
5344 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
5346 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5351 out
.Format(_T("%d files revert to %s"),count
,m_CurrentVersion
.Left(6));
5352 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5356 void CGitStatusListCtrl::OpenFile(CTGitPath
*filepath
,int mode
)
5359 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
5361 file
= filepath
->GetWinPath();
5366 GetTempPath(temppath
);
5367 file
.Format(_T("%s%s_%s%s"),
5369 filepath
->GetBaseFilename(),
5370 m_CurrentVersion
.Left(6),
5371 filepath
->GetFileExtension());
5373 if(g_Git
.GetOneFile(m_CurrentVersion
, *filepath
, file
))
5375 out
.Format(_T("Fail checkout file %s to %s\n"), filepath
->GetGitPathString(), file
);
5376 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5381 if(mode
== ALTERNATIVEEDITOR
)
5383 CAppUtils::LaunchAlternativeEditor(file
);
5386 int ret
= HINSTANCE_ERROR
;
5390 ret
= (int)ShellExecute(this->m_hWnd
, NULL
,file
, NULL
, NULL
, SW_SHOW
);
5392 if (ret
> HINSTANCE_ERROR
)
5399 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
5401 CAppUtils::LaunchApplication(cmd
, NULL
, false);