1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2003-2008, 2013 - TortoiseSVN
5 // Copyright (C) 2010-2012 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 "LoglistUtils.h"
36 //#include "SVNProperties.h"
40 #include "GitProgressDlg.h"
41 #include "SysImageList.h"
42 //#include "Svnstatuslistctrl.h"
45 #include "GitStatus.h"
46 //#include "SVNHelpers.h"
48 #include "ShellUpdater.h"
49 #include "GitAdminDir.h"
50 //#include "DropFiles.h"
53 //#include "EditPropertiesDlg.h"
54 //#include "CreateChangelistDlg.h"
55 #include "FormatMessageWrapper.h"
56 #include "BrowseFolder.h"
58 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
59 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
60 const UINT
CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
61 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
62 const UINT
CGitStatusListCtrl::GITSLNM_ADDFILE
63 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
64 const UINT
CGitStatusListCtrl::GITSLNM_CHECKCHANGED
65 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
66 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCHANGED
67 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCHANGED"));
72 BEGIN_MESSAGE_MAP(CGitStatusListCtrl
, CListCtrl
)
73 ON_NOTIFY(HDN_ITEMCLICKA
, 0, OnHdnItemclick
)
74 ON_NOTIFY(HDN_ITEMCLICKW
, 0, OnHdnItemclick
)
75 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
76 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
77 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED
, OnLvnItemchanged
)
79 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclk
)
80 ON_NOTIFY_REFLECT(LVN_GETINFOTIP
, OnLvnGetInfoTip
)
81 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdraw
)
84 ON_NOTIFY_REFLECT(NM_RETURN
, OnNMReturn
)
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_bShowIgnores(false)
107 , m_pDropTarget(NULL
)
108 , m_bIgnoreRemoveOnly(false)
109 , m_bCheckChildrenWithParent(false)
110 , m_bUnversionedLast(true)
111 , m_bHasChangeLists(false)
115 , m_bHasCheckboxes(false)
116 , m_bCheckIfGroupsExist(true)
117 , m_bFileDropsEnabled(false)
119 , m_dwDefaultColumns(0)
120 , m_ColumnManager(this)
121 , m_bAscending(false)
122 , m_nSortedColumn(-1)
123 , m_bHasExternalsFromDifferentRepos(false)
124 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE
))
126 , m_bDoNotAutoselectSubmodules(false)
128 , m_hwndLogicalParent(NULL
)
129 , m_bHasUnversionedItems(FALSE
)
132 m_dwDefaultColumns
= 0;
134 m_bIsRevertTheirMy
= false;
135 this->m_nLineAdded
=this->m_nLineDeleted
=0;
138 CGitStatusListCtrl::~CGitStatusListCtrl()
140 // if (m_pDropTarget)
141 // delete m_pDropTarget;
145 void CGitStatusListCtrl::ClearStatusArray()
148 Locker
lock(m_critSec
);
149 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
151 delete m_arStatusArray
[i
];
153 m_arStatusArray
.clear();
157 void CGitStatusListCtrl::Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
/* = GitSLC_POPALL */, bool bHasCheckboxes
/* = true */, bool bHasWC
/* = true */, DWORD allowedColumns
/* = 0xffffffff */)
159 Locker
lock(m_critSec
);
161 m_dwDefaultColumns
= dwColumns
| 1;
162 m_dwContextMenus
= dwContextMenus
;
163 m_bHasCheckboxes
= bHasCheckboxes
;
166 // set the extended style of the listcontrol
167 // 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.
168 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
169 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
170 if (DWORD(regFullRowSelect
))
171 exStyle
|= LVS_EX_FULLROWSELECT
;
172 exStyle
|= (bHasCheckboxes
? LVS_EX_CHECKBOXES
: 0);
174 SetExtendedStyle(exStyle
);
176 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
178 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
179 m_nRestoreOvl
= SYS_IMAGE_LIST().AddIcon((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_RESTOREOVL
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
));
180 SYS_IMAGE_LIST().SetOverlayImage(m_nRestoreOvl
, OVL_RESTORE
);
181 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
183 // keep CSorter::operator() in sync!!
184 static UINT standardColumnNames
[GITSLC_NUMCOLUMNS
]
185 = { IDS_STATUSLIST_COLFILE
186 , IDS_STATUSLIST_COLFILENAME
187 , IDS_STATUSLIST_COLEXT
188 , IDS_STATUSLIST_COLSTATUS
189 , IDS_STATUSLIST_COLADD
190 , IDS_STATUSLIST_COLDEL
191 , IDS_STATUSLIST_COLLASTMODIFIED
192 , IDS_STATUSLIST_COLSIZE
195 m_ColumnManager
.SetNames(standardColumnNames
,GITSLC_NUMCOLUMNS
);
196 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, 0xffffffff & ~(allowedColumns
| m_dwDefaultColumns
), sColumnInfoContainer
, GITSLC_NUMCOLUMNS
);
200 if (m_pDropTarget
== NULL
)
202 m_pDropTarget
= new CGitStatusListCtrlDropTarget(this);
203 RegisterDragDrop(m_hWnd
,m_pDropTarget
);
204 // create the supported formats:
206 ftetc
.dwAspect
= DVASPECT_CONTENT
;
208 ftetc
.tymed
= TYMED_HGLOBAL
;
209 ftetc
.cfFormat
=CF_HDROP
;
210 m_pDropTarget
->AddSuportedFormat(ftetc
);
217 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID
)
219 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
222 BOOL
CGitStatusListCtrl::GetStatus ( const CTGitPathList
* pathList
223 , bool bUpdate
/* = FALSE */
224 , bool bShowIgnores
/* = false */
227 Locker
lock(m_critSec
);
228 int mask
= CGitStatusListCtrl::FILELIST_MODIFY
;
230 mask
|= CGitStatusListCtrl::FILELIST_IGNORE
;
232 mask
|= CGitStatusListCtrl::FILELIST_UNVER
;
233 this->UpdateFileList(mask
,bUpdate
,(CTGitPathList
*)pathList
);
235 if (pathList
&& m_mapDirectFiles
.empty())
237 // remember files which are selected by users so that those can be preselected
238 for (int i
= 0; i
< pathList
->GetCount(); ++i
)
239 if (!(*pathList
)[i
].IsDirectory())
240 m_mapDirectFiles
[(*pathList
)[i
].GetGitPathString()] = true;
244 int refetchcounter
= 0;
247 // force the cursor to change
250 SetCursorPos(pt
.x
, pt
.y
);
252 m_mapFilenameToChecked
.clear();
253 //m_StatusUrlList.Clear();
254 bool bHasChangelists
= (m_changelists
.size() > 1 || (!m_changelists
.empty() && !m_bHasIgnoreGroup
));
255 m_changelists
.clear();
256 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
258 FileEntry
* entry
= m_arStatusArray
[i
];
259 if ( bHasChangelists
&& entry
->checked
)
261 // If change lists are present, remember all checked entries
262 CString path
= entry
->GetPath().GetGitPathString();
263 m_mapFilenameToChecked
[path
] = true;
265 if ( (entry
->status
==git_wc_status_unversioned
|| entry
->status
==git_wc_status_missing
) && entry
->checked
)
267 // The user manually selected an unversioned or missing file. We remember
268 // this so that the selection can be restored when refreshing.
269 CString path
= entry
->GetPath().GetGitPathString();
270 m_mapFilenameToChecked
[path
] = true;
272 else if ( entry
->status
> git_wc_status_normal
&& !entry
->checked
)
274 // The user manually deselected a versioned file. We remember
275 // this so that the deselection can be restored when refreshing.
276 CString path
= entry
->GetPath().GetGitPathString();
277 m_mapFilenameToChecked
[path
] = false;
281 // use a sorted path list to make sure we fetch the status of
282 // parent items first, *then* the child items (if any)
283 CTGitPathList sortedPathList
= pathList
;
284 sortedPathList
.SortByPathname();
289 m_bHasExternalsFromDifferentRepos
= FALSE
;
290 m_bHasExternals
= FALSE
;
291 m_bHasUnversionedItems
= FALSE
;
293 m_bHasChangeLists
= false;
294 m_bShowIgnores
= bShowIgnores
;
301 // first clear possible status data left from
302 // previous GetStatus() calls
305 m_StatusFileList
= sortedPathList
;
307 // Since Git_client_status() returns all files, even those in
308 // folders included with Git:externals we need to check if all
309 // files we get here belongs to the same repository.
310 // It is possible to commit changes in an external folder, as long
311 // as the folder belongs to the same repository (but another path),
312 // but it is not possible to commit all files if the externals are
313 // from a different repository.
315 // To check if all files belong to the same repository, we compare the
316 // UUID's - if they're identical then the files belong to the same
317 // repository and can be committed. But if they're different, then
318 // tell the user to commit all changes in the external folders
320 CStringA sUUID
; // holds the repo UUID
321 CTGitPathList arExtPaths
; // list of Git:external paths
327 m_nTargetCount
= sortedPathList
.GetCount();
329 GitStatus
status(m_pbCanceled
);
330 if(m_nTargetCount
> 1 && sortedPathList
.AreAllPathsFilesInOneDirectory())
332 // This is a special case, where we've been given a list of files
333 // all from one folder
334 // We handle them by setting a status filter, then requesting the Git status of
335 // all the files in the directory, filtering for the ones we're interested in
336 status
.SetFilter(sortedPathList
);
338 // if all selected entries are files, we don't do a recursive status
339 // fetching. But if only one is a directory, we have to recurse.
340 git_depth_t depth
= git_depth_files
;
341 // We have set a filter. If all selected items were files or we fetch
342 // the status not recursively, then we have to include
343 // ignored items too - the user has selected them
344 bool bShowIgnoresRight
= true;
345 for (int fcindex
=0; fcindex
<sortedPathList
.GetCount(); ++fcindex
)
347 if (sortedPathList
[fcindex
].IsDirectory())
349 depth
= git_depth_infinity
;
350 bShowIgnoresRight
= false;
354 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
.GetCommonDirectory(), bUpdate
, sUUID
, arExtPaths
, true, depth
, bShowIgnoresRight
))
361 for(int nTarget
= 0; nTarget
< m_nTargetCount
; nTarget
++)
363 // check whether the path we want the status for is already fetched due to status-fetching
365 // this check is only done for file paths, because folder paths could be included already
366 // but not recursively
367 if (sortedPathList
[nTarget
].IsDirectory() || GetListEntry(sortedPathList
[nTarget
]) == NULL
)
369 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
[nTarget
], bUpdate
, sUUID
,
370 arExtPaths
, false, git_depth_infinity
, bShowIgnores
))
378 // remove the 'helper' files of conflicted items from the list.
379 // otherwise they would appear as unversioned files.
380 for (INT_PTR cind
= 0; cind
< m_ConflictFileList
.GetCount(); ++cind
)
382 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
384 if (m_arStatusArray
[i
]->GetPath().IsEquivalentTo(m_ConflictFileList
[cind
]))
386 delete m_arStatusArray
[i
];
387 m_arStatusArray
.erase(m_arStatusArray
.begin()+i
);
393 } while(!BuildStatistics() && (refetchcounter
< 2) && (*m_pbCanceled
==false));
398 SetCursorPos(pt
.x
, pt
.y
);
405 // Get the show-flags bitmap value which corresponds to a particular Git status
406 DWORD
CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status
)
410 case git_wc_status_none
:
411 case git_wc_status_unversioned
:
412 return GITSLC_SHOWUNVERSIONED
;
413 case git_wc_status_ignored
:
415 return GITSLC_SHOWDIRECTS
;
416 return GITSLC_SHOWDIRECTS
|GITSLC_SHOWIGNORED
;
417 case git_wc_status_incomplete
:
418 return GITSLC_SHOWINCOMPLETE
;
419 case git_wc_status_normal
:
420 return GITSLC_SHOWNORMAL
;
421 case git_wc_status_external
:
422 return GITSLC_SHOWEXTERNAL
;
423 case git_wc_status_added
:
424 return GITSLC_SHOWADDED
;
425 case git_wc_status_missing
:
426 return GITSLC_SHOWMISSING
;
427 case git_wc_status_deleted
:
428 return GITSLC_SHOWREMOVED
;
429 case git_wc_status_replaced
:
430 return GITSLC_SHOWREPLACED
;
431 case git_wc_status_modified
:
432 return GITSLC_SHOWMODIFIED
;
433 case git_wc_status_merged
:
434 return GITSLC_SHOWMERGED
;
435 case git_wc_status_conflicted
:
436 return GITSLC_SHOWCONFLICTED
;
437 case git_wc_status_obstructed
:
438 return GITSLC_SHOWOBSTRUCTED
;
440 // we should NEVER get here!
447 void CGitStatusListCtrl::Show(unsigned int dwShow
, unsigned int dwCheck
/*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList
,bool UseStoredCheckStatus
)
449 CWinApp
* pApp
= AfxGetApp();
451 pApp
->DoWaitCursor(1);
453 Locker
lock(m_critSec
);
454 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
456 //SetItemCount(listIndex);
461 m_nShownUnversioned
= 0;
462 m_nShownModified
= 0;
465 m_nShownConflicted
= 0;
467 m_nShownSubmodules
= 0;
471 m_arStatusArray
.clear();
472 for(int i
=0;i
<this->m_StatusFileList
.GetCount();i
++)
474 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
477 for(int i
=0;i
<this->m_UnRevFileList
.GetCount();i
++)
479 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
482 for(int i
=0;i
<this->m_IgnoreFileList
.GetCount();i
++)
484 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
488 if (m_nSortedColumn
>= 0)
490 CSorter
predicate (&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
491 std::sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
495 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
497 //set default checkbox status
498 CTGitPath
* entry
= ((CTGitPath
*)m_arStatusArray
[i
]);
499 CString path
= entry
->GetGitPathString();
500 if (!m_mapFilenameToChecked
.empty() && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end())
502 entry
->m_Checked
=m_mapFilenameToChecked
[path
];
504 else if (!UseStoredCheckStatus
)
506 bool autoSelectSubmodules
= !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
);
507 if ((entry
->m_Action
& dwCheck
|| dwShow
& GITSLC_SHOWDIRECTFILES
&& m_mapDirectFiles
.find(path
) != m_mapDirectFiles
.end()) && autoSelectSubmodules
)
508 entry
->m_Checked
=true;
510 entry
->m_Checked
=false;
511 m_mapFilenameToChecked
[path
] = entry
->m_Checked
;
514 if(entry
->m_Action
& dwShow
)
516 AddEntry(entry
,langID
,index
);
521 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
522 for (int col
= 0; col
<= maxcol
; col
++)
523 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
526 GetStatisticsString();
528 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
529 HDITEM HeaderItem
= {0};
530 HeaderItem
.mask
= HDI_FORMAT
;
531 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
533 pHeader
->GetItem(i
, &HeaderItem
);
534 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
535 pHeader
->SetItem(i
, &HeaderItem
);
537 if (m_nSortedColumn
>= 0)
539 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
540 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
541 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
547 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
548 EnsureVisible(nSelectedEntry
, false);
552 // Restore the item at the top of the list.
553 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
555 if ( !EnsureVisible(nTopIndex
+i
,false) )
563 pApp
->DoWaitCursor(-1);
569 this->BuildStatistics();
573 CWinApp
* pApp
= AfxGetApp();
575 pApp
->DoWaitCursor(1);
577 m_bShowFolders
= bShowFolders
;
579 int nTopIndex
= GetTopIndex();
580 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
581 int nSelectedEntry
= 0;
582 if (posSelectedEntry
)
583 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
589 m_arListArray
.clear();
591 m_arListArray
.reserve(m_arStatusArray
.size());
592 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
595 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
597 FileEntry
* entry
= m_arStatusArray
[i
];
598 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
600 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
602 if (entry
->IsFolder() && (!bShowFolders
))
603 continue; // don't show folders if they're not wanted.
606 git_wc_status_kind status
= GitStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
607 DWORD showFlags
= GetShowFlagsFromGitStatus(status
);
608 if (entry
->IsLocked())
609 showFlags
|= SVNSLC_SHOWLOCKS
;
611 showFlags
|= SVNSLC_SHOWSWITCHED
;
612 if (!entry
->changelist
.IsEmpty())
613 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
615 bool bAllowCheck
= ((entry
->changelist
.Compare(GITSLC_IGNORECHANGELIST
) != 0)
616 && (m_bCheckIfGroupsExist
|| (m_changelists
.empty() || (m_changelists
.size() == 1 && m_bHasIgnoreGroup
))));
618 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
620 if (status
!= Git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& GitSLC_SHOWIGNORED
))
622 if ((!entry
->IsFolder()) && (status
== Git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
624 if (PathFileExists(entry
->GetPath().GetWinPath()))
626 m_arListArray
.push_back(i
);
627 if ((dwCheck
& SVNSLC_SHOWREMOVEDANDPRESENT
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
630 entry
->checked
= true;
632 AddEntry(entry
, langID
, listIndex
++);
635 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
637 m_arListArray
.push_back(i
);
638 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
641 entry
->checked
= true;
643 AddEntry(entry
, langID
, listIndex
++);
645 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
647 m_arListArray
.push_back(i
);
648 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
651 entry
->checked
= true;
653 AddEntry(entry
, langID
, listIndex
++);
659 SetItemCount(listIndex
);
661 m_ColumnManager
.UpdateRelevance (m_arStatusArray
, m_arListArray
);
663 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
664 for (int col
= 0; col
<= maxcol
; col
++)
665 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
668 GetStatisticsString();
670 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
671 HDITEM HeaderItem
= {0};
672 HeaderItem
.mask
= HDI_FORMAT
;
673 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
675 pHeader
->GetItem(i
, &HeaderItem
);
676 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
677 pHeader
->SetItem(i
, &HeaderItem
);
681 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
682 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
683 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
688 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
689 EnsureVisible(nSelectedEntry
, false);
693 // Restore the item at the top of the list.
694 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
696 if ( !EnsureVisible(nTopIndex
+i
,false) )
704 pApp
->DoWaitCursor(-1);
706 m_bEmpty
= (GetItemCount() == 0);
712 void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList
& checkedList
, bool /*bShowFolders*/ /* = true */)
715 for(int i
=0;i
<checkedList
.GetCount();i
++)
716 this->AddEntry((CTGitPath
*)&checkedList
[i
],0,i
);
720 Locker
lock(m_critSec
);
721 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
723 CWinApp
* pApp
= AfxGetApp();
725 pApp
->DoWaitCursor(1);
727 m_bShowFolders
= bShowFolders
;
729 int nTopIndex
= GetTopIndex();
730 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
731 int nSelectedEntry
= 0;
732 if (posSelectedEntry
)
733 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
739 m_arListArray
.clear();
741 m_arListArray
.reserve(m_arStatusArray
.size());
742 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
745 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
747 FileEntry
* entry
= m_arStatusArray
[i
];
748 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
750 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
752 if (entry
->IsFolder() && (!bShowFolders
))
753 continue; // don't show folders if they're not wanted.
755 git_wc_status_kind status
= SVNStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
756 DWORD showFlags
= GetShowFlagsFromSVNStatus(status
);
757 if (entry
->IsLocked())
758 showFlags
|= SVNSLC_SHOWLOCKS
;
759 if (!entry
->changelist
.IsEmpty())
760 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
762 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
763 if (status
!= git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& SVNSLC_SHOWIGNORED
))
765 for (int npath
= 0; npath
< checkedList
.GetCount(); ++npath
)
767 if (entry
->GetPath().IsEquivalentTo(checkedList
[npath
]))
769 entry
->checked
= true;
773 if ((!entry
->IsFolder()) && (status
== git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
775 if (PathFileExists(entry
->GetPath().GetWinPath()))
777 m_arListArray
.push_back(i
);
778 AddEntry(entry
, langID
, listIndex
++);
781 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
783 m_arListArray
.push_back(i
);
784 AddEntry(entry
, langID
, listIndex
++);
786 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
788 m_arListArray
.push_back(i
);
789 AddEntry(entry
, langID
, listIndex
++);
791 else if (entry
->switched
)
793 m_arListArray
.push_back(i
);
794 AddEntry(entry
, langID
, listIndex
++);
800 SetItemCount(listIndex
);
802 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
803 for (int col
= 0; col
<= maxcol
; col
++)
804 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
807 GetStatisticsString();
809 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
810 HDITEM HeaderItem
= {0};
811 HeaderItem
.mask
= HDI_FORMAT
;
812 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
814 pHeader
->GetItem(i
, &HeaderItem
);
815 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
816 pHeader
->SetItem(i
, &HeaderItem
);
820 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
821 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
822 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
827 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
828 EnsureVisible(nSelectedEntry
, false);
832 // Restore the item at the top of the list.
833 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
835 if ( !EnsureVisible(nTopIndex
+i
,false) )
843 pApp
->DoWaitCursor(-1);
845 m_bEmpty
= (GetItemCount() == 0);
850 int CGitStatusListCtrl::GetColumnIndex(int mask
)
860 void CGitStatusListCtrl::AddEntry(CTGitPath
* GitPath
, WORD
/*langID*/, int listIndex
)
862 static CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
863 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
864 static bool abbreviateRenamings(((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\AbbreviateRenamings"), FALSE
)) == TRUE
);
865 static bool relativeTimes
= (CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
) != FALSE
);
867 CString path
= GitPath
->GetGitPathString();
870 int index
= listIndex
;
872 CString entryname
= GitPath
->GetGitPathString();
874 if (GitPath
->IsDirectory())
876 icon_idx
= m_nIconFolder
;
877 m_nShownSubmodules
++;
881 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(*GitPath
);
884 switch (GitPath
->m_Action
)
886 case CTGitPath::LOGACTIONS_ADDED
:
887 case CTGitPath::LOGACTIONS_COPY
:
890 case CTGitPath::LOGACTIONS_DELETED
:
893 case CTGitPath::LOGACTIONS_REPLACED
:
894 case CTGitPath::LOGACTIONS_MODIFIED
:
895 case CTGitPath::LOGACTIONS_MERGED
:
898 case CTGitPath::LOGACTIONS_UNMERGED
:
899 m_nShownConflicted
++;
901 case CTGitPath::LOGACTIONS_UNVER
:
902 m_nShownUnversioned
++;
905 m_nShownUnversioned
++;
908 if(GitPath
->m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !GitPath
->GetGitOldPathString().IsEmpty())
910 if (!abbreviateRenamings
)
914 rename
.Format(from
, GitPath
->GetGitOldPathString());
915 entryname
+= _T(" ") + rename
;
920 tgpl
.AddPath(*GitPath
);
921 CTGitPath
old(GitPath
->GetGitOldPathString());
923 CString commonRoot
= tgpl
.GetCommonRoot().GetGitPathString();
924 if (!commonRoot
.IsEmpty())
925 commonRoot
+= _T("/");
926 if (old
.GetFileOrDirectoryName() == GitPath
->GetFileOrDirectoryName() && old
.GetContainingDirectory().GetGitPathString() != "" && GitPath
->GetContainingDirectory().GetGitPathString())
928 entryname
= commonRoot
+ _T("{") + GitPath
->GetGitOldPathString().Mid(commonRoot
.GetLength(), old
.GetGitPathString().GetLength() - commonRoot
.GetLength() - old
.GetFileOrDirectoryName().GetLength() - 1) + _T(" => ") + GitPath
->GetGitPathString().Mid(commonRoot
.GetLength(), GitPath
->GetGitPathString().GetLength() - commonRoot
.GetLength() - old
.GetFileOrDirectoryName().GetLength() - 1) + _T("}/") + old
.GetFileOrDirectoryName();
930 else if (!commonRoot
.IsEmpty())
932 entryname
= commonRoot
+ _T("{") + GitPath
->GetGitOldPathString().Mid(commonRoot
.GetLength()) + _T(" => ") + GitPath
->GetGitPathString().Mid(commonRoot
.GetLength()) + _T("}");
936 entryname
= GitPath
->GetGitOldPathString().Mid(commonRoot
.GetLength()) + _T(" => ") + GitPath
->GetGitPathString().Mid(commonRoot
.GetLength());
941 InsertItem(index
, entryname
, icon_idx
);
942 if (m_restorepaths
.find(GitPath
->GetWinPathString()) != m_restorepaths
.end())
943 SetItemState(index
, INDEXTOOVERLAYMASK(OVL_RESTORE
), TVIS_OVERLAYMASK
);
945 this->SetItemData(index
, (DWORD_PTR
)GitPath
);
946 // SVNSLC_COLFILENAME
947 SetItemText(index
, nCol
++, GitPath
->GetFileOrDirectoryName());
949 SetItemText(index
, nCol
++, GitPath
->GetFileExtension());
951 SetItemText(index
, nCol
++, GitPath
->GetActionName());
953 SetItemText(index
, GetColumnIndex(GITSLC_COLADD
),GitPath
->m_StatAdd
);
954 SetItemText(index
, GetColumnIndex(GITSLC_COLDEL
),GitPath
->m_StatDel
);
957 CString modificationDate
;
958 __int64 filetime
= GitPath
->GetLastWriteTime();
959 if (filetime
&& (GitPath
->m_Action
!= CTGitPath::LOGACTIONS_DELETED
))
961 FILETIME
* f
= (FILETIME
*)(__int64
*)&filetime
;
962 modificationDate
= CLoglistUtils::FormatDateAndTime(CTime(g_Git
.filetime_to_time_t(f
)), DATE_SHORTDATE
, true, relativeTimes
);
964 SetItemText(index
, GetColumnIndex(GITSLC_COLMODIFICATIONDATE
), modificationDate
);
967 if (GitPath
->IsDirectory())
968 SetItemText(index
, GetColumnIndex(GITSLC_COLSIZE
), _T(""));
972 StrFormatByteSize64(GitPath
->GetFileSize(), buf
, 100);
973 SetItemText(index
, GetColumnIndex(GITSLC_COLSIZE
), buf
);
976 SetCheck(index
, GitPath
->m_Checked
);
977 if (GitPath
->m_Checked
)
981 if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_IGNORE
)
982 SetItemGroup(index
, 2);
983 else if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
984 SetItemGroup(index
,1);
987 SetItemGroup(index
, GitPath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
));
995 bool CGitStatusListCtrl::SetItemGroup(int item
, int groupindex
)
997 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1002 i
.mask
= LVIF_GROUPID
;
1005 i
.iGroupId
= groupindex
;
1007 return !!SetItem(&i
);
1010 void CGitStatusListCtrl::OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1012 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1014 if (m_bBlock
|| m_arStatusArray
.empty())
1017 if (m_nSortedColumn
== phdr
->iItem
)
1018 m_bAscending
= !m_bAscending
;
1020 m_bAscending
= TRUE
;
1021 m_nSortedColumn
= phdr
->iItem
;
1022 Show(m_dwShow
, 0, m_bShowFolders
,false,true);
1027 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1029 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1032 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1033 if ((m_bBlock
)&&(m_bBlockUI
))
1035 // if we're blocked, prevent changing of the check state
1036 if ((!ISCHECKED(pNMLV
->uOldState
) && ISCHECKED(pNMLV
->uNewState
))||
1037 (ISCHECKED(pNMLV
->uOldState
) && !ISCHECKED(pNMLV
->uNewState
)))
1042 BOOL
CGitStatusListCtrl::OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1044 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1046 CWnd
* pParent
= GetLogicalParent();
1047 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
1049 pParent
->SendMessage(GITSLNM_ITEMCHANGED
, pNMLV
->iItem
);
1052 if ((pNMLV
->uNewState
==0)||(pNMLV
->uNewState
& LVIS_SELECTED
)||(pNMLV
->uNewState
& LVIS_FOCUSED
))
1058 bool bSelected
= !!(ListView_GetItemState(m_hWnd
, pNMLV
->iItem
, LVIS_SELECTED
) & LVIS_SELECTED
);
1059 int nListItems
= GetItemCount();
1062 // was the item checked?
1064 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1065 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1067 if (GetCheck(pNMLV
->iItem
))
1069 CheckEntry(pNMLV
->iItem
, nListItems
);
1072 POSITION pos
= GetFirstSelectedItemPosition();
1074 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1076 if (index
!= pNMLV
->iItem
)
1077 CheckEntry(index
, nListItems
);
1083 UncheckEntry(pNMLV
->iItem
, nListItems
);
1086 POSITION pos
= GetFirstSelectedItemPosition();
1088 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1090 if (index
!= pNMLV
->iItem
)
1091 UncheckEntry(index
, nListItems
);
1096 GetStatisticsString();
1103 void CGitStatusListCtrl::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1105 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
1110 void CGitStatusListCtrl::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1112 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
1117 void CGitStatusListCtrl::CheckEntry(int index
, int /*nListItems*/)
1119 Locker
lock(m_critSec
);
1120 //FileEntry * entry = GetListEntry(index);
1121 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1122 ASSERT(path
!= NULL
);
1125 m_mapFilenameToChecked
[path
->GetGitPathString()] = true;
1126 SetCheck(index
, TRUE
);
1127 //entry = GetListEntry(index);
1128 // if an unversioned item was checked, then we need to check if
1129 // the parent folders are unversioned too. If the parent folders actually
1130 // are unversioned, then check those too.
1132 if (entry
->status
== git_wc_status_unversioned
)
1134 // we need to check the parent folder too
1135 const CTGitPath
& folderpath
= entry
->path
;
1136 for (int i
=0; i
< nListItems
; ++i
)
1138 FileEntry
* testEntry
= GetListEntry(i
);
1139 ASSERT(testEntry
!= NULL
);
1140 if (testEntry
== NULL
)
1142 if (!testEntry
->checked
)
1144 if (testEntry
->path
.IsAncestorOf(folderpath
) && (!testEntry
->path
.IsEquivalentTo(folderpath
)))
1146 SetEntryCheck(testEntry
,i
,true);
1152 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1153 if ( (entry
->status
== git_wc_status_deleted
) || (m_bCheckChildrenWithParent
) || (bShift
) )
1155 // if a deleted folder gets checked, we have to check all
1156 // children of that folder too.
1157 if (entry
->path
.IsDirectory())
1159 SetCheckOnAllDescendentsOf(entry
, true);
1162 // if a deleted file or folder gets checked, we have to
1163 // check all parents of this item too.
1164 for (int i
=0; i
<nListItems
; ++i
)
1166 FileEntry
* testEntry
= GetListEntry(i
);
1167 ASSERT(testEntry
!= NULL
);
1168 if (testEntry
== NULL
)
1170 if (!testEntry
->checked
)
1172 if (testEntry
->path
.IsAncestorOf(entry
->path
) && (!testEntry
->path
.IsEquivalentTo(entry
->path
)))
1174 if ((testEntry
->status
== git_wc_status_deleted
)||(m_bCheckChildrenWithParent
))
1176 SetEntryCheck(testEntry
,i
,true);
1178 // now we need to check all children of this parent folder
1179 SetCheckOnAllDescendentsOf(testEntry
, true);
1186 if ( !path
->m_Checked
)
1188 path
->m_Checked
= TRUE
;
1193 void CGitStatusListCtrl::UncheckEntry(int index
, int /*nListItems*/)
1195 Locker
lock(m_critSec
);
1196 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1197 ASSERT(path
!= NULL
);
1200 SetCheck(index
, FALSE
);
1201 m_mapFilenameToChecked
[path
->GetGitPathString()] = false;
1202 //entry = GetListEntry(index);
1203 // item was unchecked
1205 if (entry
->path
.IsDirectory())
1207 // disable all files within an unselected folder, except when unchecking a folder with property changes
1208 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1209 if ( (entry
->status
!= git_wc_status_modified
) || (bShift
) )
1211 SetCheckOnAllDescendentsOf(entry
, false);
1214 else if (entry
->status
== git_wc_status_deleted
)
1216 // a "deleted" file was unchecked, so uncheck all parent folders
1217 // and all children of those parents
1218 for (int i
=0; i
<nListItems
; i
++)
1220 FileEntry
* testEntry
= GetListEntry(i
);
1221 ASSERT(testEntry
!= NULL
);
1222 if (testEntry
== NULL
)
1224 if (testEntry
->checked
)
1226 if (testEntry
->path
.IsAncestorOf(entry
->path
))
1228 if (testEntry
->status
== git_wc_status_deleted
)
1230 SetEntryCheck(testEntry
,i
,false);
1233 SetCheckOnAllDescendentsOf(testEntry
, false);
1240 if ( path
->m_Checked
)
1242 path
->m_Checked
= FALSE
;
1246 bool CGitStatusListCtrl::BuildStatistics()
1249 bool bRefetchStatus
= false;
1251 // now gather some statistics
1264 for (int i
=0; i
< (int)m_arStatusArray
.size(); ++i
)
1266 int status
=((CTGitPath
*)m_arStatusArray
[i
])->m_Action
;
1268 m_nLineAdded
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatAdd
);
1269 m_nLineDeleted
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatDel
);
1271 if(status
&(CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
1274 if(status
&CTGitPath::LOGACTIONS_DELETED
)
1277 if(status
&(CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_MODIFIED
))
1280 if(status
&CTGitPath::LOGACTIONS_UNMERGED
)
1283 if(status
&(CTGitPath::LOGACTIONS_IGNORE
|CTGitPath::LOGACTIONS_UNVER
))
1286 if(status
&(CTGitPath::LOGACTIONS_REPLACED
))
1289 if(((CTGitPath
*)m_arStatusArray
[i
])->m_Checked
)
1292 // } // switch (entry->status)
1294 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1295 return !bRefetchStatus
;
1299 int CGitStatusListCtrl::GetGroupFromPoint(POINT
* ppt
)
1301 // the point must be relative to the upper left corner of the control
1305 if (!IsGroupViewEnabled())
1314 while (((flags
& LVHT_BELOW
) == 0)&&(pt
.y
< rc
.bottom
))
1316 nItem
= HitTest(pt
, &flags
);
1317 if ((flags
& LVHT_ONITEM
)||(flags
& LVHT_EX_GROUP_HEADER
))
1319 // the first item below the point
1321 // check if the point is too much right (i.e. if the point
1322 // is farther to the right than the width of the item)
1324 GetItemRect(nItem
, &r
, LVIR_LABEL
);
1325 if (ppt
->x
> r
.right
)
1329 lv
.mask
= LVIF_GROUPID
;
1332 int groupID
= lv
.iGroupId
;
1333 // now we search upwards and check if the item above this one
1334 // belongs to another group. If it belongs to the same group,
1335 // we're not over a group header
1339 nItem
= HitTest(pt
, &flags
);
1340 if ((flags
& LVHT_ONITEM
)&&(nItem
>= 0))
1342 // the first item below the point
1344 lv
.mask
= LVIF_GROUPID
;
1347 if (lv
.iGroupId
!= groupID
)
1362 void CGitStatusListCtrl::OnContextMenuGroup(CWnd
* /*pWnd*/, CPoint point
)
1364 POINT clientpoint
= point
;
1365 ScreenToClient(&clientpoint
);
1366 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint
) >= 0))
1369 if (popup
.CreatePopupMenu())
1372 temp
.LoadString(IDS_STATUSLIST_CHECKGROUP
);
1373 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_CHECKGROUP
, temp
);
1374 temp
.LoadString(IDS_STATUSLIST_UNCHECKGROUP
);
1375 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_UNCHECKGROUP
, temp
);
1376 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1377 bool bCheck
= false;
1380 case IDGITLC_CHECKGROUP
:
1382 // fall through here
1383 case IDGITLC_UNCHECKGROUP
:
1385 int group
= GetGroupFromPoint(&clientpoint
);
1386 // go through all items and check/uncheck those assigned to the group
1387 // but block the OnLvnItemChanged handler
1390 for (int i
=0; i
<GetItemCount(); ++i
)
1392 SecureZeroMemory(&lv
, sizeof(LVITEM
));
1393 lv
.mask
= LVIF_GROUPID
;
1397 if (lv
.iGroupId
== group
)
1399 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
1402 bool bOldCheck
= entry
->m_Checked
;
1403 SetEntryCheck(entry
, i
, bCheck
);
1404 if (bCheck
!= bOldCheck
)
1415 GetStatisticsString();
1425 void CGitStatusListCtrl::OnContextMenuList(CWnd
* pWnd
, CPoint point
)
1428 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1430 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1431 CTGitPath
* filepath
;
1433 int selIndex
= GetSelectionMark();
1434 if ((point
.x
== -1) && (point
.y
== -1))
1437 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1438 ClientToScreen(&rect
);
1439 point
= rect
.CenterPoint();
1441 if ((GetSelectedCount() == 0) && (m_bHasCheckboxes
))
1443 // nothing selected could mean the context menu is requested for
1445 OnContextMenuGroup(pWnd
, point
);
1447 else if (selIndex
>= 0)
1449 //FileEntry * entry = GetListEntry(selIndex);
1451 filepath
= (CTGitPath
* )GetItemData(selIndex
);
1453 ASSERT(filepath
!= NULL
);
1454 if (filepath
== NULL
)
1457 //const CTGitPath& filepath = entry->path;
1458 int wcStatus
= filepath
->m_Action
;
1459 // entry is selected, now show the popup menu
1460 Locker
lock(m_critSec
);
1462 CMenu changelistSubMenu
;
1463 CMenu ignoreSubMenu
;
1464 if (popup
.CreatePopupMenu())
1466 //Add Menu for version controlled file
1468 if (GetSelectedCount() > 0 && wcStatus
& CTGitPath::LOGACTIONS_UNMERGED
)
1470 if (GetSelectedCount() == 1 && (m_dwContextMenus
& GITSLC_POPCONFLICT
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1472 popup
.AppendMenuIcon(IDGITLC_EDITCONFLICT
, IDS_MENUCONFLICT
, IDI_CONFLICT
);
1474 if (m_dwContextMenus
& GITSLC_POPRESOLVE
)
1476 popup
.AppendMenuIcon(IDGITLC_RESOLVECONFLICT
, IDS_STATUSLIST_CONTEXT_RESOLVED
, IDI_RESOLVE
);
1478 if ((m_dwContextMenus
& GITSLC_POPRESOLVE
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1480 popup
.AppendMenuIcon(IDGITLC_RESOLVETHEIRS
, IDS_SVNPROGRESS_MENUUSETHEIRS
, IDI_RESOLVE
);
1481 popup
.AppendMenuIcon(IDGITLC_RESOLVEMINE
, IDS_SVNPROGRESS_MENUUSEMINE
, IDI_RESOLVE
);
1483 if ((m_dwContextMenus
& GITSLC_POPCONFLICT
)||(m_dwContextMenus
& GITSLC_POPRESOLVE
))
1484 popup
.AppendMenu(MF_SEPARATOR
);
1487 if (GetSelectedCount() > 0)
1489 if (wcStatus
& CTGitPath::LOGACTIONS_UNVER
)
1490 if (m_dwContextMenus
& GITSLC_POPADD
)
1492 //if ( entry->IsFolder() )
1494 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1498 popup
.AppendMenuIcon(IDGITLC_ADD
, IDS_STATUSLIST_CONTEXT_ADD
, IDI_ADD
);
1503 if (!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
) && GetSelectedCount() > 0)
1505 bool bEntryAdded
= false;
1506 if (m_dwContextMenus
& GITSLC_POPCOMPAREWITHBASE
)
1508 if(filepath
->m_ParentNo
& MERGE_MASK
)
1509 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_TREE_DIFF
, IDI_DIFF
);
1511 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_LOG_COMPAREWITHBASE
, IDI_DIFF
);
1513 popup
.SetDefaultItem(IDGITLC_COMPARE
, FALSE
);
1517 if (!g_Git
.IsInitRepos() && (m_dwContextMenus
& GITSLC_POPGNUDIFF
))
1519 popup
.AppendMenuIcon(IDGITLC_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1523 if ((m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPAREWC
)) && m_bHasWC
)
1525 if ((!m_CurrentVersion
.IsEmpty()) && m_CurrentVersion
!= GIT_REV_ZERO
)
1527 popup
.AppendMenuIcon(IDGITLC_COMPAREWC
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1532 //else if (GetSelectedCount() > 1)
1534 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1536 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1537 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1542 popup
.AppendMenu(MF_SEPARATOR
);
1545 if( (!this->m_Rev1
.IsEmpty()) || (!this->m_Rev1
.IsEmpty()) )
1547 if(GetSelectedCount() == 1)
1549 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPARETWO
))
1551 popup
.AppendMenuIcon(IDGITLC_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1552 popup
.SetDefaultItem(IDGITLC_COMPARETWO
, FALSE
);
1554 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_GNUDIFF2
))
1556 popup
.AppendMenuIcon(IDGITLC_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1562 if (GetSelectedCount() > 0)
1564 if ((GetSelectedCount() == 2) && (m_dwContextMenus
& GITSLC_POPCOMPARETWOFILES
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1566 POSITION pos
= GetFirstSelectedItemPosition();
1567 int index
= GetNextSelectedItem(pos
);
1570 CTGitPath
* entry2
= NULL
;
1571 bool bothItemsAreExistingFiles
= true;
1572 entry2
= (CTGitPath
* )GetItemData(index
);
1574 bothItemsAreExistingFiles
= !entry2
->IsDirectory() && entry2
->Exists();
1575 index
= GetNextSelectedItem(pos
);
1578 entry2
= (CTGitPath
* )GetItemData(index
);
1580 bothItemsAreExistingFiles
= bothItemsAreExistingFiles
&& !entry2
->IsDirectory() && entry2
->Exists();
1581 if (bothItemsAreExistingFiles
)
1582 popup
.AppendMenuIcon(IDGITLC_COMPARETWOFILES
, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES
, IDI_DIFF
);
1586 // if (wcStatus > git_wc_status_normal)
1588 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1590 // // reverting missing folders is not possible
1591 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1593 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1597 // if (entry->remotestatus > git_wc_status_normal)
1599 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1601 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1606 if ( (GetSelectedCount() >0 ) && (!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
)) && m_bHasWC
)
1608 if ((m_dwContextMenus
& GITSLC_POPREVERT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1610 popup
.AppendMenuIcon(IDGITLC_REVERT
, IDS_MENUREVERT
, IDI_REVERT
);
1613 if ((m_dwContextMenus
& GITSLC_POPSKIPWORKTREE
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && !(wcStatus
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_UNMERGED
)) && !filepath
->IsDirectory())
1615 popup
.AppendMenuIcon(IDGITLC_SKIPWORKTREE
, IDS_STATUSLIST_SKIPWORKTREE
);
1618 if ((m_dwContextMenus
& GITSLC_POPASSUMEVALID
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && !(wcStatus
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_UNMERGED
)) && !filepath
->IsDirectory())
1620 popup
.AppendMenuIcon(IDGITLC_ASSUMEVALID
, IDS_MENUASSUMEVALID
);
1623 if (m_dwContextMenus
& GITSLC_POPRESTORE
&& !filepath
->IsDirectory())
1625 if (m_restorepaths
.find(filepath
->GetWinPathString()) == m_restorepaths
.end())
1626 popup
.AppendMenuIcon(IDGITLC_CREATERESTORE
, IDS_MENUCREATERESTORE
, IDI_RESTORE
);
1628 popup
.AppendMenuIcon(IDGITLC_RESTOREPATH
, IDS_MENURESTORE
, IDI_RESTORE
);
1631 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOREV
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1632 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1634 popup
.AppendMenuIcon(IDGITLC_REVERTTOREV
, IDS_LOG_POPUP_REVERTTOREV
, IDI_REVERT
);
1637 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOPARENT
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1638 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_ADDED
))
1640 popup
.AppendMenuIcon(IDGITLC_REVERTTOPARENT
, IDS_LOG_POPUP_REVERTTOPARENT
, IDI_REVERT
);
1644 if ((GetSelectedCount() == 1)&&(!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
))
1645 &&(!(wcStatus
& CTGitPath::LOGACTIONS_IGNORE
)))
1647 if (m_dwContextMenus
& GITSLC_POPSHOWLOG
)
1649 popup
.AppendMenuIcon(IDGITLC_LOG
, IDS_REPOBROWSE_SHOWLOG
, IDI_LOG
);
1651 if (m_dwContextMenus
& GITSLC_POPSHOWLOGSUBMODULE
&& filepath
->IsDirectory())
1653 popup
.AppendMenuIcon(IDGITLC_LOGSUBMODULE
, IDS_LOG_SUBMODULE
, IDI_LOG
);
1655 if (m_dwContextMenus
& GITSLC_POPSHOWLOGOLDNAME
&& (wcStatus
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !filepath
->GetGitOldPathString().IsEmpty()))
1657 popup
.AppendMenuIcon(IDGITLC_LOGOLDNAME
, IDS_STATUSLIST_SHOWLOGOLDNAME
, IDI_LOG
);
1659 if (m_dwContextMenus
& GITSLC_POPBLAME
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
)
1661 popup
.AppendMenuIcon(IDGITLC_BLAME
, IDS_MENUBLAME
, IDI_BLAME
);
1665 if (GetSelectedCount() > 0)
1667 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_EXPORT
)) && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1668 popup
.AppendMenuIcon(IDGITLC_EXPORT
, IDS_LOG_POPUP_EXPORT
, IDI_EXPORT
);
1671 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1672 if ( (GetSelectedCount() == 1) )
1674 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_SAVEAS
) && ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1676 popup
.AppendMenuIcon(IDGITLC_SAVEAS
, IDS_LOG_POPUP_SAVE
, IDI_SAVEAS
);
1679 if (m_dwContextMenus
& GITSLC_POPOPEN
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1681 popup
.AppendMenuIcon(IDGITLC_VIEWREV
, IDS_LOG_POPUP_VIEWREV
);
1682 popup
.AppendMenuIcon(IDGITLC_OPEN
, IDS_REPOBROWSE_OPEN
, IDI_OPEN
);
1683 popup
.AppendMenuIcon(IDGITLC_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1684 if (wcStatus
&CTGitPath::LOGACTIONS_UNVER
) {
1685 popup
.SetDefaultItem(IDGITLC_OPEN
, FALSE
);
1689 if (m_dwContextMenus
& GITSLC_POPEXPLORE
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
)
1691 popup
.AppendMenuIcon(IDGITLC_EXPLORE
, IDS_STATUSLIST_CONTEXT_EXPLORE
, IDI_EXPLORER
);
1695 if (GetSelectedCount() > 0)
1697 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
1699 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1701 // 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))
1704 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
1706 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
1708 if ((wcStatus
& CTGitPath::LOGACTIONS_UNVER
)/*||(wcStatus == git_wc_status_deleted)*/)
1710 if (m_dwContextMenus
& GITSLC_POPDELETE
)
1712 popup
.AppendMenuIcon(IDGITLC_DELETE
, IDS_MENUREMOVE
, IDI_DELETE
);
1715 if ( (wcStatus
& CTGitPath::LOGACTIONS_UNVER
|| wcStatus
& CTGitPath::LOGACTIONS_DELETED
) )
1717 if (m_dwContextMenus
& GITSLC_POPIGNORE
)
1720 CTGitPathList ignorelist
;
1721 FillListOfSelectedItemPaths(ignorelist
);
1722 //check if all selected entries have the same extension
1723 bool bSameExt
= true;
1725 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
1727 if (sExt
.IsEmpty() && (i
==0))
1728 sExt
= ignorelist
[i
].GetFileExtension();
1729 else if (sExt
.CompareNoCase(ignorelist
[i
].GetFileExtension())!=0)
1734 if (ignoreSubMenu
.CreateMenu())
1737 if (ignorelist
.GetCount()==1)
1738 ignorepath
= ignorelist
[0].GetFileOrDirectoryName();
1740 ignorepath
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1741 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNORE
, ignorepath
);
1742 ignorepath
= _T("*")+sExt
;
1743 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREMASK
, ignorepath
);
1744 if (ignorelist
.GetCount() == 1)
1745 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREFOLDER
, ignorelist
[0].GetContainingDirectory().GetGitPathString());
1747 temp
.LoadString(IDS_MENUIGNORE
);
1748 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)ignoreSubMenu
.m_hMenu
, temp
);
1754 if (ignorelist
.GetCount()==1)
1756 temp
.LoadString(IDS_MENUIGNORE
);
1760 temp
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1762 popup
.AppendMenuIcon(IDGITLC_IGNORE
, temp
, IDI_IGNORE
);
1770 if (GetSelectedCount() > 0)
1772 popup
.AppendMenu(MF_SEPARATOR
);
1773 popup
.AppendMenuIcon(IDGITLC_COPY
, IDS_STATUSLIST_CONTEXT_COPY
, IDI_COPYCLIP
);
1774 popup
.AppendMenuIcon(IDGITLC_COPYEXT
, IDS_STATUSLIST_CONTEXT_COPYEXT
, IDI_COPYCLIP
);
1776 if ((m_dwContextMenus
& SVNSLC_POPCHANGELISTS
))
1777 &&(wcStatus
!= git_wc_status_unversioned
)&&(wcStatus
!= git_wc_status_none
))
1779 popup
.AppendMenu(MF_SEPARATOR
);
1780 // changelist commands
1781 size_t numChangelists
= GetNumberOfChangelistsInSelection();
1782 if (numChangelists
> 0)
1784 popup
.AppendMenuIcon(IDSVNLC_REMOVEFROMCS
, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS
);
1786 if ((!entry
->IsFolder())&&(changelistSubMenu
.CreateMenu()))
1789 temp
.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS
);
1790 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATECS
, temp
);
1792 if (entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
))
1794 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1795 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATEIGNORECS
, SVNSLC_IGNORECHANGELIST
);
1798 if (!m_changelists
.empty())
1800 // find the changelist names
1801 bool bNeedSeparator
= true;
1802 int cmdID
= IDSVNLC_MOVETOCS
;
1803 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
1805 if ((entry
->changelist
.Compare(it
->first
))&&(it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)))
1809 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1810 bNeedSeparator
= false;
1812 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, cmdID
, it
->first
);
1817 temp
.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS
);
1818 popup
.AppendMenu(MF_POPUP
|MF_STRING
, (UINT_PTR
)changelistSubMenu
.GetSafeHmenu(), temp
);
1824 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1827 AfxGetApp()->DoWaitCursor(1);
1828 //int iItemCountBeforeMenuCmd = GetItemCount();
1829 //bool bForce = false;
1832 case IDGITLC_VIEWREV
:
1833 OpenFile(filepath
, ALTERNATIVEEDITOR
);
1837 OpenFile(filepath
,OPEN
);
1840 case IDGITLC_OPENWITH
:
1841 OpenFile(filepath
,OPEN_WITH
);
1844 case IDGITLC_EXPLORE
:
1846 ShellExecute(this->m_hWnd
, _T("explore"), filepath
->GetDirectory().GetWinPath(), NULL
, NULL
, SW_SHOW
);
1850 case IDGITLC_CREATERESTORE
:
1852 POSITION pos
= GetFirstSelectedItemPosition();
1855 int index
= GetNextSelectedItem(pos
);
1856 CTGitPath
* entry2
= (CTGitPath
* )GetItemData(index
);
1857 ASSERT(entry2
!= NULL
);
1858 if (entry2
== NULL
|| entry2
->IsDirectory())
1860 if (m_restorepaths
.find(entry2
->GetWinPathString()) != m_restorepaths
.end())
1862 CTGitPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
1863 if (CopyFile(g_Git
.m_CurrentDir
+ _T("\\") + entry2
->GetWinPathString(), tempFile
.GetWinPath(), FALSE
))
1865 m_restorepaths
[entry2
->GetWinPathString()] = tempFile
.GetWinPathString();
1866 SetItemState(index
, INDEXTOOVERLAYMASK(OVL_RESTORE
), LVIS_OVERLAYMASK
);
1873 case IDGITLC_RESTOREPATH
:
1875 if (CMessageBox::Show(m_hWnd
, IDS_STATUSLIST_RESTOREPATH
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_RESTOREBUTTON
, IDS_ABORTBUTTON
) == 2)
1877 POSITION pos
= GetFirstSelectedItemPosition();
1880 int index
= GetNextSelectedItem(pos
);
1881 CTGitPath
* entry2
= (CTGitPath
* )GetItemData(index
);
1882 ASSERT(entry2
!= NULL
);
1885 if (m_restorepaths
.find(entry2
->GetWinPathString()) == m_restorepaths
.end())
1887 if (CopyFile(m_restorepaths
[entry2
->GetWinPathString()], g_Git
.m_CurrentDir
+ _T("\\") + entry2
->GetWinPathString(), FALSE
))
1889 m_restorepaths
.erase(entry2
->GetWinPathString());
1890 SetItemState(index
, 0, LVIS_OVERLAYMASK
);
1897 // Compare current version and work copy.
1898 case IDGITLC_COMPAREWC
:
1900 if (!CheckMultipleDiffs())
1902 POSITION pos
= GetFirstSelectedItemPosition();
1905 int index
= GetNextSelectedItem(pos
);
1911 // Compare with base version. when current version is zero, compare workcopy and HEAD.
1912 case IDGITLC_COMPARE
:
1914 if (!CheckMultipleDiffs())
1916 POSITION pos
= GetFirstSelectedItemPosition();
1919 int index
= GetNextSelectedItem(pos
);
1925 case IDGITLC_COMPARETWO
:
1927 POSITION pos
= GetFirstSelectedItemPosition();
1930 int index
= GetNextSelectedItem(pos
);
1931 StartDiffTwo(index
);
1936 case IDGITLC_COMPARETWOFILES
:
1938 POSITION pos
= GetFirstSelectedItemPosition();
1939 CTGitPath
* firstfilepath
= NULL
, * secondfilepath
= NULL
;
1942 firstfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
1943 ASSERT(firstfilepath
!= NULL
);
1944 if (firstfilepath
== NULL
)
1947 secondfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
1948 ASSERT(secondfilepath
!= NULL
);
1949 if (secondfilepath
== NULL
)
1953 sCmd
.Format(_T("/command:diff /path:\"%s\" /path2:\"%s\" /hwnd:%ld"), firstfilepath
->GetWinPath(), secondfilepath
->GetWinPath(), (unsigned long)m_hWnd
);
1954 CAppUtils::RunTortoiseGitProc(sCmd
);
1959 case IDGITLC_GNUDIFF1
:
1961 POSITION pos
= GetFirstSelectedItemPosition();
1964 CTGitPath
* selectedFilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
1965 if (m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
1969 fromwhere
= _T("~1");
1970 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, GitRev::GetHead() + fromwhere
, *selectedFilepath
, GitRev::GetWorkingCopy());
1974 if ((selectedFilepath
->m_ParentNo
& (PARENT_MASK
| MERGE_MASK
)) == 0)
1975 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, m_CurrentVersion
+ _T("~1"), *selectedFilepath
, m_CurrentVersion
);
1979 if (!(selectedFilepath
->m_ParentNo
& MERGE_MASK
))
1980 str
.Format(_T("%s^%d"), m_CurrentVersion
, (selectedFilepath
->m_ParentNo
& PARENT_MASK
) + 1);
1982 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, str
, *selectedFilepath
, m_CurrentVersion
, false, false, false, !!(selectedFilepath
->m_ParentNo
& MERGE_MASK
));
1989 case IDGITLC_GNUDIFF2
:
1991 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *filepath
, m_Rev2
, *filepath
, m_Rev1
);
1997 CTGitPathList paths
;
1998 FillListOfSelectedItemPaths(paths
, true);
2000 CGitProgressDlg progDlg
;
2001 progDlg
.SetCommand(CGitProgressList::GitProgress_Add
);
2002 progDlg
.SetPathList(paths
);
2003 progDlg
.SetItemCount(paths
.GetCount());
2006 // reset unchecked status
2007 POSITION pos
= GetFirstSelectedItemPosition();
2009 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2011 m_mapFilenameToChecked
.erase(((CTGitPath
*)GetItemData(index
))->GetGitPathString());
2014 if (NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2015 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2021 case IDGITLC_DELETE
:
2024 std::vector
<int> selectIndex
;
2026 POSITION pos
= GetFirstSelectedItemPosition();
2028 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2030 selectIndex
.push_back(index
);
2033 //Create file-list ('\0' separated) for SHFileOperation
2035 for(int i
=0;i
<selectIndex
.size();i
++)
2037 index
=selectIndex
[i
];
2039 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2044 filelist
+= path
->GetWinPathString();
2045 filelist
+= _T("|");
2047 filelist
+= _T("|");
2048 int len
= filelist
.GetLength();
2049 std::unique_ptr
<TCHAR
[]> buf(new TCHAR
[len
+ 2]);
2050 _tcscpy_s(buf
.get(), len
+ 2, filelist
);
2051 for (int i
=0; i
<len
; ++i
)
2052 if (buf
.get()[i
] == '|')
2054 SHFILEOPSTRUCT fileop
;
2055 fileop
.hwnd
= this->m_hWnd
;
2056 fileop
.wFunc
= FO_DELETE
;
2057 fileop
.pFrom
= buf
.get();
2059 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
2060 fileop
.lpszProgressTitle
= _T("deleting file");
2061 int result
= SHFileOperation(&fileop
);
2063 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
2066 POSITION pos
= NULL
;
2067 while ((pos
= GetFirstSelectedItemPosition()) != 0)
2069 int index
= GetNextSelectedItem(pos
);
2070 if (GetCheck(index
))
2074 RemoveListEntry(index
);
2083 CAppUtils::LaunchTortoiseBlame(g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath(), m_CurrentVersion
);
2088 case IDGITLC_LOGSUBMODULE
:
2091 sCmd
.Format(_T("/command:log /path:\"%s\""), g_Git
.m_CurrentDir
+ _T("\\") + filepath
->GetWinPath());
2092 if (cmd
== IDGITLC_LOG
&& filepath
->IsDirectory())
2093 sCmd
+= _T(" /submodule");
2094 CAppUtils::RunTortoiseGitProc(sCmd
, false, !(cmd
== IDGITLC_LOGSUBMODULE
));
2098 case IDGITLC_LOGOLDNAME
:
2100 CTGitPath
oldName(filepath
->GetGitOldPathString());
2102 sCmd
.Format(_T("/command:log /path:\"%s\""), g_Git
.m_CurrentDir
+ _T("\\") + oldName
.GetWinPath());
2103 CAppUtils::RunTortoiseGitProc(sCmd
);
2107 case IDGITLC_EDITCONFLICT
:
2109 if (CAppUtils::ConflictEdit(*filepath
, false, this->m_bIsRevertTheirMy
))
2111 CString conflictedFile
= g_Git
.m_CurrentDir
+ _T("\\") + filepath
->GetWinPathString();
2112 if (!PathFileExists(conflictedFile
) && NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2113 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2118 case IDGITLC_RESOLVETHEIRS
: //follow up
2119 case IDGITLC_RESOLVEMINE
: //follow up
2120 case IDGITLC_RESOLVECONFLICT
:
2122 if (CMessageBox::Show(m_hWnd
, IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
)==IDYES
)
2124 POSITION pos
= GetFirstSelectedItemPosition();
2128 index
= GetNextSelectedItem(pos
);
2129 CTGitPath
* fentry
=(CTGitPath
*) this->GetItemData(index
);
2132 CString gitcmd
,output
;
2135 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVETHEIRS
) ||
2136 ((this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVEMINE
) )
2138 gitcmd
.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry
->GetGitPathString());
2139 if (g_Git
.Run(gitcmd
, &output
,CP_UTF8
))
2141 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2146 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVEMINE
) ||
2147 ((this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVETHEIRS
) )
2149 gitcmd
.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry
->GetGitPathString());
2150 if (g_Git
.Run(gitcmd
, &output
,CP_UTF8
))
2152 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2158 if ( fentry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
2160 gitcmd
.Format(_T("git.exe add -f -- \"%s\""),fentry
->GetGitPathString());
2161 if (g_Git
.Run(gitcmd
, &output
,CP_UTF8
))
2163 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2167 fentry
->m_Action
|= CTGitPath::LOGACTIONS_MODIFIED
;
2168 fentry
->m_Action
&=~CTGitPath::LOGACTIONS_UNMERGED
;
2172 CAppUtils::RemoveTempMergeFile(*fentry
);
2175 Show(m_dwShow
, 0, m_bShowFolders
,0,true);
2180 case IDGITLC_IGNORE
:
2182 CTGitPathList ignorelist
;
2183 //std::vector<CString> toremove;
2184 FillListOfSelectedItemPaths(ignorelist
, true);
2186 if(!CAppUtils::IgnoreFile(ignorelist
,false))
2190 CWnd
* pParent
= GetLogicalParent();
2191 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2193 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2199 case IDGITLC_IGNOREMASK
:
2202 CString ext
=filepath
->GetFileExtension();
2203 CTGitPathList ignorelist
;
2204 FillListOfSelectedItemPaths(ignorelist
, true);
2206 if (!CAppUtils::IgnoreFile(ignorelist
,true))
2210 CWnd
* pParent
= GetLogicalParent();
2211 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2213 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2220 case IDGITLC_IGNOREFOLDER
:
2222 CTGitPathList ignorelist
;
2223 ignorelist
.AddPath(filepath
->GetContainingDirectory());
2225 if (!CAppUtils::IgnoreFile(ignorelist
, false))
2229 CWnd
*pParent
= GetLogicalParent();
2230 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2231 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2237 case IDGITLC_REVERT
:
2239 // If at least one item is not in the status "added"
2240 // we ask for a confirmation
2241 BOOL bConfirm
= FALSE
;
2242 POSITION pos
= GetFirstSelectedItemPosition();
2244 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2246 //FileEntry * fentry = GetListEntry(index);
2247 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
2248 if(fentry
&& fentry
->m_Action
&CTGitPath::LOGACTIONS_MODIFIED
&& !fentry
->IsDirectory())
2256 str
.Format(IDS_PROC_WARNREVERT
,GetSelectedCount());
2258 if (!bConfirm
|| CMessageBox::Show(this->m_hWnd
, str
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
2260 CTGitPathList targetList
;
2261 FillListOfSelectedItemPaths(targetList
);
2263 // make sure that the list is reverse sorted, so that
2264 // children are removed before any parents
2265 targetList
.SortByPathname(true);
2267 // put all reverted files in the trashbin, except the ones with 'added'
2268 // status because they are not restored by the revert.
2269 CTGitPathList delList
;
2270 POSITION pos
= GetFirstSelectedItemPosition();
2272 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2274 CTGitPath
*entry
=(CTGitPath
*)GetItemData(index
);
2275 if (entry
&&(!(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
))
2276 && (!(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)) && !entry
->IsDirectory())
2279 fullpath
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+entry
->GetWinPath());
2280 delList
.AddPath(fullpath
);
2283 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
2284 delList
.DeleteAllFiles(true);
2286 CString revertToCommit
= _T("HEAD");
2288 revertToCommit
= _T("HEAD~1");
2289 if (g_Git
.Revert(revertToCommit
, targetList
))
2291 CMessageBox::Show(this->m_hWnd
, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR
);
2295 bool updateStatusList
= false;
2296 for(int i
=0;i
<targetList
.GetCount();i
++)
2298 int nListboxEntries
= GetItemCount();
2299 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2301 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2302 if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && !path
->IsDirectory())
2304 if(path
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2306 path
->m_Action
= CTGitPath::LOGACTIONS_UNVER
;
2307 SetEntryCheck(path
,nItem
,false);
2308 updateStatusList
= true;
2309 SetItemGroup(nItem
,1);
2310 this->m_StatusFileList
.RemoveItem(*path
);
2311 this->m_UnRevFileList
.AddPath(*path
);
2312 //this->m_IgnoreFileList.RemoveItem(*path);
2317 RemoveListEntry(nItem
);
2321 else if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && path
->IsDirectory() && path
->IsWCRoot())
2324 sCmd
.Format(_T("/command:revert /path:\"%s\""), path
->GetGitPathString());
2325 CCommonAppUtils::RunTortoiseGitProc(sCmd
);
2331 Show(m_dwShow
, 0, m_bShowFolders
,updateStatusList
,true);
2338 case IDGITLC_ASSUMEVALID
:
2340 if (CMessageBox::Show(GetSafeHwnd(), IDS_PROC_MARK_ASSUMEVALID
, IDS_APPNAME
, MB_YESNO
| MB_DEFBUTTON2
| MB_ICONQUESTION
) == IDNO
)
2342 CString cmdTemplate
;
2343 cmdTemplate
= _T("git.exe update-index --assume-unchanged \"%s\"");
2344 POSITION pos
= GetFirstSelectedItemPosition();
2346 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2348 CTGitPath
* path
= (CTGitPath
*)GetItemData(index
);
2353 CString cmd
, output
;
2354 cmd
.Format(cmdTemplate
, path
->GetGitPathString());
2355 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
2357 MessageBox(output
, _T("TortoiseGit"), MB_ICONERROR
);
2360 if (NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2361 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2366 case IDGITLC_SKIPWORKTREE
:
2368 if (CMessageBox::Show(GetSafeHwnd(), IDS_PROC_MARK_SKIPWORKTREE
, IDS_APPNAME
, MB_YESNO
| MB_DEFBUTTON2
| MB_ICONQUESTION
) == IDNO
)
2370 CString cmdTemplate
;
2371 cmdTemplate
= _T("git.exe update-index --skip-worktree \"%s\"");
2372 POSITION pos
= GetFirstSelectedItemPosition();
2374 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2376 CTGitPath
* path
= (CTGitPath
*)GetItemData(index
);
2381 CString cmd
, output
;
2382 cmd
.Format(cmdTemplate
, path
->GetGitPathString());
2383 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
2385 MessageBox(output
, _T("TortoiseGit"), MB_ICONERROR
);
2388 if (NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2389 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2395 CopySelectedEntriesToClipboard(0);
2397 case IDGITLC_COPYEXT
:
2398 CopySelectedEntriesToClipboard((DWORD
)-1);
2400 case IDGITLC_EXPORT
:
2403 case IDGITLC_SAVEAS
:
2404 FileSaveAs(filepath
);
2407 case IDGITLC_REVERTTOREV
:
2408 RevertSelectedItemToVersion();
2410 case IDGITLC_REVERTTOPARENT
:
2411 RevertSelectedItemToVersion(true);
2414 case IDSVNLC_COMMIT
:
2416 CTSVNPathList targetList
;
2417 FillListOfSelectedItemPaths(targetList
);
2418 CTSVNPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2419 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2420 CString commandline
= CPathUtils::GetAppDirectory();
2421 commandline
+= _T("TortoiseGitProc.exe /command:commit /pathfile:\"");
2422 commandline
+= tempFile
.GetWinPathString();
2423 commandline
+= _T("\"");
2424 commandline
+= _T(" /deletepathfile");
2425 CAppUtils::LaunchApplication(commandline
, NULL
, false);
2428 case IDSVNLC_CREATEIGNORECS
:
2429 CreateChangeList(SVNSLC_IGNORECHANGELIST
);
2431 case IDSVNLC_CREATECS
:
2433 CCreateChangelistDlg dlg
;
2434 if (dlg
.DoModal() == IDOK
)
2436 CreateChangeList(dlg
.m_sName
);
2442 if (cmd
< IDSVNLC_MOVETOCS
)
2444 CTSVNPathList changelistItems
;
2445 FillListOfSelectedItemPaths(changelistItems
);
2447 // find the changelist name
2448 CString sChangelist
;
2449 int cmdID
= IDSVNLC_MOVETOCS
;
2451 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
2453 if ((it
->first
.Compare(SVNSLC_IGNORECHANGELIST
))&&(entry
->changelist
.Compare(it
->first
)))
2457 sChangelist
= it
->first
;
2462 if (!sChangelist
.IsEmpty())
2465 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
2467 // The changelists were moved, but we now need to run through the selected items again
2468 // and update their changelist
2469 POSITION pos
= GetFirstSelectedItemPosition();
2471 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2473 FileEntry
* e
= GetListEntry(index
);
2474 e
->changelist
= sChangelist
;
2477 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
2478 SetItemGroup(index
, m_changelists
[e
->changelist
]);
2480 SetItemGroup(index
, 0);
2486 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
2496 AfxGetApp()->DoWaitCursor(-1);
2497 GetStatisticsString();
2498 //int iItemCountAfterMenuCmd = GetItemCount();
2499 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
2501 // CWnd* pParent = GetParent();
2502 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2504 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
2507 } // if (popup.CreatePopupMenu())
2508 } // if (selIndex >= 0)
2512 void CGitStatusListCtrl::OnContextMenuHeader(CWnd
* pWnd
, CPoint point
)
2514 Locker
lock(m_critSec
);
2515 m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
2518 void CGitStatusListCtrl::OnContextMenu(CWnd
* pWnd
, CPoint point
)
2523 OnContextMenuList(pWnd
, point
);
2524 } // if (pWnd == this)
2525 else if (pWnd
== GetHeaderCtrl())
2527 OnContextMenuHeader(pWnd
, point
);
2531 void CGitStatusListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2534 Locker
lock(m_critSec
);
2535 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
2540 if (pNMLV
->iItem
< 0)
2542 if (!IsGroupViewEnabled())
2545 DWORD ptW
= GetMessagePos();
2546 pt
.x
= GET_X_LPARAM(ptW
);
2547 pt
.y
= GET_Y_LPARAM(ptW
);
2548 ScreenToClient(&pt
);
2549 int group
= GetGroupFromPoint(&pt
);
2552 // check/uncheck the whole group depending on the check-state
2553 // of the first item in the group
2555 bool bCheck
= false;
2556 bool bFirst
= false;
2558 for (int i
=0; i
<GetItemCount(); ++i
)
2560 SecureZeroMemory(&lv
, sizeof(LVITEM
));
2561 lv
.mask
= LVIF_GROUPID
;
2564 if (lv
.iGroupId
== group
)
2566 CTGitPath
*entry
=(CTGitPath
*)GetItemData(i
);
2570 bCheck
= !GetCheck(i
);
2575 bool bOldCheck
= !!GetCheck(i
);
2576 SetEntryCheck(entry
, i
, bCheck
);
2577 if (bCheck
!= bOldCheck
)
2587 GetStatisticsString();
2593 CTGitPath
*file
=(CTGitPath
*)GetItemData(pNMLV
->iItem
);
2595 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
) {
2596 OpenFile(file
, OPEN
);
2599 if( file
->m_Action
&CTGitPath::LOGACTIONS_UNMERGED
)
2601 if (CAppUtils::ConflictEdit(*file
, false, m_bIsRevertTheirMy
))
2603 CString conflictedFile
= g_Git
.m_CurrentDir
+ _T("\\") + file
->GetWinPathString();
2604 if (!PathFileExists(conflictedFile
) && NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2605 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2610 if( (!m_Rev1
.IsEmpty()) || (!m_Rev1
.IsEmpty())) // m_Rev1 twice???
2611 StartDiffTwo(pNMLV
->iItem
);
2613 StartDiff(pNMLV
->iItem
);
2617 void CGitStatusListCtrl::StartDiffTwo(int fileindex
)
2622 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
2624 CGitDiff::Diff(&file1
,&file1
,
2629 void CGitStatusListCtrl::StartDiffWC(int fileindex
)
2635 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2638 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
2640 CGitDiff::Diff(&file1
,&file1
, GIT_REV_ZERO
, m_CurrentVersion
);
2644 void CGitStatusListCtrl::StartDiff(int fileindex
)
2649 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
2651 if(file1
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
2653 file2
.SetFromGit(file1
.GetGitOldPathString());
2660 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2663 if(m_amend
&& (file1
.m_Action
& CTGitPath::LOGACTIONS_ADDED
) == 0)
2664 fromwhere
= _T("~1");
2665 if( g_Git
.IsInitRepos())
2666 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2668 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_ADDED
)
2669 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2670 m_CurrentVersion
+fromwhere
,true);
2671 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_DELETED
)
2672 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2673 GitRev::GetHead()+fromwhere
,false);
2675 CGitDiff::Diff(&file1
,&file2
,
2676 CString(GIT_REV_ZERO
),
2677 GitRev::GetHead()+fromwhere
);
2682 CString fromwhere
= m_CurrentVersion
+_T("~1");
2684 fromwhere
= m_CurrentVersion
+_T("~2");
2685 if (rev
.GetCommit(fromwhere
) || (file1
.m_Action
& file1
.LOGACTIONS_ADDED
))
2687 CGitDiff::DiffNull(&file1
,m_CurrentVersion
,true);
2690 else if (file1
.m_Action
& file1
.LOGACTIONS_DELETED
)
2692 if (file1
.m_ParentNo
> 0)
2693 fromwhere
.Format(_T("%s^%d"), m_CurrentVersion
, file1
.m_ParentNo
+ 1);
2695 CGitDiff::DiffNull(&file1
,fromwhere
,false);
2699 if( file1
.m_ParentNo
& MERGE_MASK
)
2702 CTGitPath base
, theirs
, mine
, merge
;
2705 GetTempPath(temppath
);
2706 temppath
.TrimRight(_T("\\"));
2708 mine
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".LOCAL") + file1
.GetFileExtension());
2709 theirs
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".REMOTE") + file1
.GetFileExtension());
2710 base
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".BASE") + file1
.GetFileExtension());
2713 //create a empty file, incase stage is not three
2714 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2716 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2718 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2721 merge
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".Merged") + file1
.GetFileExtension());
2723 int parent1
=-1, parent2
=-1;
2724 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
2726 if(m_arStatusArray
[i
]->GetGitPathString() == file1
.GetGitPathString())
2728 if(m_arStatusArray
[i
]->m_ParentNo
& MERGE_MASK
)
2735 parent1
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2737 else if (parent2
<0)
2739 parent2
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2745 if(g_Git
.GetOneFile(m_CurrentVersion
, file1
, (CString
&)merge
.GetWinPathString()))
2747 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2753 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent1
+1);
2755 if(g_Git
.GetOneFile(str
, file1
, (CString
&)mine
.GetWinPathString()))
2757 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2764 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent2
+1);
2766 if(g_Git
.GetOneFile(str
, file1
, (CString
&)theirs
.GetWinPathString()))
2768 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2772 if(parent1
>=0 && parent2
>=0)
2774 CString cmd
, output
;
2775 cmd
.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion
, parent1
+1,
2776 this->m_CurrentVersion
,parent2
+1);
2778 if (g_Git
.Run(cmd
, &output
, NULL
, CP_UTF8
))
2783 if(g_Git
.GetOneFile(output
.Left(40), file1
, (CString
&)base
.GetWinPathString()))
2785 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETBASEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2789 CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
2795 if( (file1
.m_ParentNo
&PARENT_MASK
) == 0)
2801 str
.Format(_T("^%d"), (file1
.m_ParentNo
&PARENT_MASK
)+1);
2803 CGitDiff::Diff(&file1
,&file2
,
2805 m_CurrentVersion
+str
);
2811 CString
CGitStatusListCtrl::GetStatisticsString(bool simple
)
2814 CString sNormal
, sAdded
, sDeleted
, sModified
, sConflicted
, sUnversioned
, sRenamed
;
2815 WORD langID
= (WORD
)(DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
2816 TCHAR buf
[MAX_STATUS_STRING_LENGTH
];
2817 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal
, buf
, _countof(buf
), langID
);
2819 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added
, buf
, _countof(buf
), langID
);
2821 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted
, buf
, _countof(buf
), langID
);
2823 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified
, buf
, _countof(buf
), langID
);
2825 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted
, buf
, _countof(buf
), langID
);
2827 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned
, buf
, _countof(buf
), langID
);
2829 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced
, buf
, _countof(buf
), langID
);
2834 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE1
,
2835 this->m_nLineAdded
,this->m_nLineDeleted
,
2836 (LPCTSTR
)sModified
, m_nModified
,
2837 (LPCTSTR
)sAdded
, m_nAdded
,
2838 (LPCTSTR
)sDeleted
, m_nDeleted
,
2839 (LPCTSTR
)sRenamed
, m_nRenamed
2844 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE2
,
2845 this->m_nLineAdded
,this->m_nLineDeleted
,
2846 (LPCTSTR
)sNormal
, m_nNormal
,
2847 (LPCTSTR
)sUnversioned
, m_nUnversioned
,
2848 (LPCTSTR
)sModified
, m_nModified
,
2849 (LPCTSTR
)sAdded
, m_nAdded
,
2850 (LPCTSTR
)sDeleted
, m_nDeleted
,
2851 (LPCTSTR
)sConflicted
, m_nConflicted
2855 sStats
.Format(IDS_COMMITDLG_STATISTICSFORMAT
, m_nSelected
, GetItemCount());
2858 m_pStatLabel
->SetWindowText(sStats
);
2861 if (m_pSelectButton
)
2863 if (m_nSelected
== 0)
2864 m_pSelectButton
->SetCheck(BST_UNCHECKED
);
2865 else if (m_nSelected
!= GetItemCount())
2866 m_pSelectButton
->SetCheck(BST_INDETERMINATE
);
2868 m_pSelectButton
->SetCheck(BST_CHECKED
);
2871 if (m_pConfirmButton
)
2873 m_pConfirmButton
->EnableWindow(m_nSelected
>0);
2881 CString
CGitStatusListCtrl::GetCommonDirectory(bool bStrict
)
2885 // not strict means that the selected folder has priority
2886 if (!m_StatusFileList
.GetCommonDirectory().IsEmpty())
2887 return m_StatusFileList
.GetCommonDirectory().GetWinPath();
2890 CTGitPath commonBaseDirectory
;
2891 int nListItems
= GetItemCount();
2892 for (int i
=0; i
<nListItems
; ++i
)
2894 CTGitPath baseDirectory
,*p
= (CTGitPath
*)this->GetItemData(i
);
2898 baseDirectory
= p
->GetDirectory();
2900 if(commonBaseDirectory
.IsEmpty())
2902 commonBaseDirectory
= baseDirectory
;
2906 if (commonBaseDirectory
.GetWinPathString().GetLength() > baseDirectory
.GetWinPathString().GetLength())
2908 if (baseDirectory
.IsAncestorOf(commonBaseDirectory
))
2909 commonBaseDirectory
= baseDirectory
;
2913 return g_Git
.m_CurrentDir
+CString(_T("\\"))+commonBaseDirectory
.GetWinPath();
2917 void CGitStatusListCtrl::SelectAll(bool bSelect
, bool /*bIncludeNoCommits*/)
2919 CWaitCursor waitCursor
;
2920 // block here so the LVN_ITEMCHANGED messages
2925 int nListItems
= GetItemCount();
2927 m_nSelected
= nListItems
;
2931 for (int i
=0; i
<nListItems
; ++i
)
2933 //FileEntry * entry = GetListEntry(i);
2934 //ASSERT(entry != NULL);
2935 CTGitPath
*path
= (CTGitPath
*) GetItemData(i
);
2938 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
2939 SetEntryCheck(path
,i
,bSelect
);
2942 // unblock before redrawing
2945 GetStatisticsString();
2949 void CGitStatusListCtrl::Check(DWORD dwCheck
, bool check
)
2951 CWaitCursor waitCursor
;
2952 // block here so the LVN_ITEMCHANGED messages
2957 int nListItems
= GetItemCount();
2959 for (int i
= 0; i
< nListItems
; ++i
)
2961 CTGitPath
*entry
= (CTGitPath
*) GetItemData(i
);
2965 DWORD showFlags
= entry
->m_Action
;
2966 if (entry
->IsDirectory())
2967 showFlags
|= GITSLC_SHOWSUBMODULES
;
2969 showFlags
|= GITSLC_SHOWFILES
;
2971 if (check
&& (showFlags
& dwCheck
) && !GetCheck(i
) && !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
&& !(dwCheck
& GITSLC_SHOWSUBMODULES
)))
2973 SetEntryCheck(entry
, i
, true);
2976 else if (!check
&& (showFlags
& dwCheck
) && GetCheck(i
))
2978 SetEntryCheck(entry
, i
, false);
2982 // unblock before redrawing
2985 GetStatisticsString();
2989 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2991 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
2996 CTGitPath
*entry
=(CTGitPath
*)GetItemData(pGetInfoTip
->iItem
);
2999 if (pGetInfoTip
->cchTextMax
> entry
->GetGitPathString().GetLength() + g_Git
.m_CurrentDir
.GetLength())
3002 str
+= g_Git
.m_CurrentDir
;
3004 str
+= entry
->GetWinPathString();
3006 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, str
.GetBuffer(), str
.GetLength());
3010 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3012 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
3014 // Take the default processing unless we set this to something else below.
3015 *pResult
= CDRF_DODEFAULT
;
3017 // First thing - check the draw stage. If it's the control's prepaint
3018 // stage, then tell Windows we want messages for every item.
3020 switch (pLVCD
->nmcd
.dwDrawStage
)
3023 *pResult
= CDRF_NOTIFYITEMDRAW
;
3025 case CDDS_ITEMPREPAINT
:
3027 // This is the prepaint stage for an item. Here's where we set the
3028 // item's text color. Our return value will tell Windows to draw the
3029 // item itself, but it will use the new color we set here.
3031 // Tell Windows to paint the control itself.
3032 *pResult
= CDRF_DODEFAULT
;
3036 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
3038 if (m_arStatusArray
.size() > (DWORD_PTR
)pLVCD
->nmcd
.dwItemSpec
)
3041 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3042 CTGitPath
*entry
=(CTGitPath
*)GetItemData((int)pLVCD
->nmcd
.dwItemSpec
);
3048 // black : unversioned, normal
3051 // brown : missing, deleted, replaced
3052 // green : merged (or potential merges)
3053 // red : conflicts or sure conflicts
3054 if(entry
->m_Action
& CTGitPath::LOGACTIONS_GRAY
)
3056 crText
= RGB(128,128,128);
3059 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
3061 crText
= m_Colors
.GetColor(CColors::Conflict
);
3064 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_MODIFIED
))
3066 crText
= m_Colors
.GetColor(CColors::Modified
);
3069 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
3071 crText
= m_Colors
.GetColor(CColors::Added
);
3073 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3075 crText
= m_Colors
.GetColor(CColors::DeletedNode
);
3077 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
3079 crText
= m_Colors
.GetColor(CColors::RenamedNode
);
3081 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_MERGED
)
3083 crText
= m_Colors
.GetColor(CColors::Merged
);
3087 crText
= GetSysColor(COLOR_WINDOWTEXT
);
3089 // Store the color back in the NMLVCUSTOMDRAW struct.
3090 pLVCD
->clrText
= crText
;
3097 BOOL
CGitStatusListCtrl::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
3100 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3103 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
3105 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3107 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_WAIT
));
3112 void CGitStatusListCtrl::RemoveListEntry(int index
)
3115 Locker
lock(m_critSec
);
3118 m_arStatusArray
.erase(m_arStatusArray
.begin()+index
);
3121 delete m_arStatusArray
[m_arListArray
[index
]];
3122 m_arStatusArray
.erase(m_arStatusArray
.begin()+m_arListArray
[index
]);
3123 m_arListArray
.erase(m_arListArray
.begin()+index
);
3124 for (int i
=index
; i
< (int)m_arListArray
.size(); ++i
)
3131 ///< Set a checkbox on an entry in the listbox
3132 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
3133 void CGitStatusListCtrl::SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
)
3135 pEntry
->m_Checked
= bCheck
;
3136 m_mapFilenameToChecked
[pEntry
->GetGitPathString()] = bCheck
;
3137 SetCheck(listboxIndex
, bCheck
);
3141 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry
* parentEntry
, bool bCheck
)
3144 int nListItems
= GetItemCount();
3145 for (int j
=0; j
< nListItems
; ++j
)
3147 FileEntry
* childEntry
= GetListEntry(j
);
3148 ASSERT(childEntry
!= NULL
);
3149 if (childEntry
== NULL
|| childEntry
== parentEntry
)
3151 if (childEntry
->checked
!= bCheck
)
3153 if (parentEntry
->path
.IsAncestorOf(childEntry
->path
))
3155 SetEntryCheck(childEntry
,j
,bCheck
);
3171 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList
& pathList
)
3175 int nListItems
= GetItemCount();
3176 for (int i
=0; i
< nListItems
; i
++)
3178 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
3179 ASSERT(entry
!= NULL
);
3180 if (entry
->m_Checked
)
3182 pathList
.AddPath(*entry
);
3185 pathList
.SortByPathname();
3190 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
3191 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool /*bNoIgnored*/)
3195 POSITION pos
= GetFirstSelectedItemPosition();
3197 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3199 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
3200 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
3202 pathList
.AddPath(*entry
);
3206 UINT
CGitStatusListCtrl::OnGetDlgCode()
3208 // we want to process the return key and not have that one
3209 // routed to the default pushbutton
3210 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS
;
3213 void CGitStatusListCtrl::OnNMReturn(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
3218 if (!CheckMultipleDiffs())
3220 POSITION pos
= GetFirstSelectedItemPosition();
3223 int index
= GetNextSelectedItem(pos
);
3224 CTGitPath
*file
=(CTGitPath
*)GetItemData(index
);
3225 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
)
3227 OpenFile(file
, OPEN
);
3231 if( (!m_Rev1
.IsEmpty()) || (!m_Rev1
.IsEmpty())) // m_Rev1 twice???
3232 StartDiffTwo(index
);
3239 void CGitStatusListCtrl::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
3241 // Since we catch all keystrokes (to have the enter key processed here instead
3242 // of routed to the default pushbutton) we have to make sure that other
3243 // keys like Tab and Esc still do what they're supposed to do
3244 // Tab = change focus to next/previous control
3245 // Esc = quit the dialog
3250 ::PostMessage(GetLogicalParent()->GetSafeHwnd(), WM_NEXTDLGCTL
, GetKeyState(VK_SHIFT
)&0x8000, 0);
3256 ::SendMessage(GetLogicalParent()->GetSafeHwnd(), WM_CLOSE
, 0, 0);
3261 CListCtrl::OnKeyDown(nChar
, nRepCnt
, nFlags
);
3264 void CGitStatusListCtrl::PreSubclassWindow()
3266 CListCtrl::PreSubclassWindow();
3267 EnableToolTips(TRUE
);
3268 SetWindowTheme(GetSafeHwnd(), L
"Explorer", NULL
);
3271 INT_PTR
CGitStatusListCtrl::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
3275 row
= CellRectFromPoint(point
, &cellrect
, &col
);
3282 pTI
->uId
= (UINT
)((row
<<10)+(col
&0x3ff)+1);
3283 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
3285 pTI
->rect
= cellrect
;
3290 int CGitStatusListCtrl::CellRectFromPoint(CPoint
& point
, RECT
*cellrect
, int *col
) const
3294 // Make sure that the ListView is in LVS_REPORT
3295 if ((GetWindowLong(m_hWnd
, GWL_STYLE
) & LVS_TYPEMASK
) != LVS_REPORT
)
3298 // Get the top and bottom row visible
3299 int row
= GetTopIndex();
3300 int bottom
= row
+ GetCountPerPage();
3301 if (bottom
> GetItemCount())
3302 bottom
= GetItemCount();
3304 // Get the number of columns
3305 CHeaderCtrl
* pHeader
= (CHeaderCtrl
*)GetDlgItem(0);
3306 int nColumnCount
= pHeader
->GetItemCount();
3308 // Loop through the visible rows
3309 for ( ;row
<=bottom
;row
++)
3311 // Get bounding rect of item and check whether point falls in it.
3313 GetItemRect(row
, &rect
, LVIR_BOUNDS
);
3314 if (rect
.PtInRect(point
))
3316 // Now find the column
3317 for (colnum
= 0; colnum
< nColumnCount
; colnum
++)
3319 int colwidth
= GetColumnWidth(colnum
);
3320 if (point
.x
>= rect
.left
&& point
.x
<= (rect
.left
+ colwidth
))
3323 GetClientRect(&rectClient
);
3326 rect
.right
= rect
.left
+ colwidth
;
3328 // Make sure that the right extent does not exceed
3330 if (rect
.right
> rectClient
.right
)
3331 rect
.right
= rectClient
.right
;
3335 rect
.left
+= colwidth
;
3342 void CGitStatusListCtrl::OnPaint()
3345 if ((m_bBusy
)||(m_bEmpty
))
3350 if (m_sBusy
.IsEmpty())
3351 str
.LoadString(IDS_STATUSLIST_BUSYMSG
);
3357 if (m_sEmpty
.IsEmpty())
3358 str
.LoadString(IDS_STATUSLIST_EMPTYMSG
);
3362 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
3364 if (IsWindowEnabled())
3365 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
3367 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
3372 pHC
= GetHeaderCtrl();
3376 pHC
->GetItemRect(0, &rcH
);
3377 rc
.top
+= rcH
.bottom
;
3381 CMyMemDC
memDC(pDC
, &rc
);
3383 memDC
.SetTextColor(clrText
);
3384 memDC
.SetBkColor(clrTextBk
);
3385 memDC
.FillSolidRect(rc
, clrTextBk
);
3387 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
3388 memDC
.DrawText(str
, rc
, DT_CENTER
| DT_VCENTER
|
3389 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
3390 memDC
.SelectObject(oldfont
);
3397 // prevent users from extending our hidden (size 0) columns
3398 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3400 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3403 // prevent any function from extending our hidden (size 0) columns
3404 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3406 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3410 void CGitStatusListCtrl::OnDestroy()
3412 SaveColumnWidths(true);
3413 CListCtrl::OnDestroy();
3416 void CGitStatusListCtrl::OnBeginDrag(NMHDR
* /*pNMHDR*/, LRESULT
* pResult
)
3419 Locker
lock(m_critSec
);
3420 CDropFiles dropFiles
; // class for creating DROPFILES struct
3423 POSITION pos
= GetFirstSelectedItemPosition();
3424 while ( (index
= GetNextSelectedItem(pos
)) >= 0 )
3426 FileEntry
* fentry
= m_arStatusArray
[m_arListArray
[index
]];
3427 CTGitPath path
= fentry
->GetPath();
3428 dropFiles
.AddFile( path
.GetWinPathString() );
3431 if ( dropFiles
.GetCount()>0 )
3434 dropFiles
.CreateStructure();
3441 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry
/* = false */)
3443 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
3444 for (int col
= 0; col
<= maxcol
; col
++)
3445 if (m_ColumnManager
.IsVisible (col
))
3446 m_ColumnManager
.ColumnResized (col
);
3448 if (bSaveToRegistry
)
3449 m_ColumnManager
.WriteSettings();
3452 bool CGitStatusListCtrl::EnableFileDrop()
3454 m_bFileDropsEnabled
= true;
3458 bool CGitStatusListCtrl::HasPath(const CTGitPath
& path
)
3460 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
3462 if (m_arStatusArray
[i
]->IsEquivalentTo(path
))
3469 BOOL
CGitStatusListCtrl::PreTranslateMessage(MSG
* pMsg
)
3471 if (pMsg
->message
== WM_KEYDOWN
)
3473 switch (pMsg
->wParam
)
3477 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3479 // select all entries
3480 for (int i
=0; i
<GetItemCount(); ++i
)
3482 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3491 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3493 // copy all selected paths to the clipboard
3494 if (GetAsyncKeyState(VK_SHIFT
)&0x8000)
3495 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS
);
3497 CopySelectedEntriesToClipboard(0);
3505 return CListCtrl::PreTranslateMessage(pMsg
);
3508 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols
)
3511 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
3512 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3517 if (GetSelectedCount() == 0)
3520 // first add the column titles as the first line
3521 // We needn't head when only path copy
3522 //temp.LoadString(IDS_STATUSLIST_COLFILE);
3523 //sClipboard = temp;
3525 DWORD selection
= 0;
3526 for (int i
= 0, count
= m_ColumnManager
.GetColumnCount(); i
< count
; ++i
)
3527 if ( ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
3528 || ((dwCols
!= 1) && (i
< 32) && ((dwCols
& (1 << i
)) != 0)))
3530 sClipboard
+= _T("\t") + m_ColumnManager
.GetName(i
);
3533 selection
+= 1 << i
;
3537 sClipboard
+= _T("\r\n");
3539 POSITION pos
= GetFirstSelectedItemPosition();
3541 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3543 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
3547 sClipboard
+= entry
->GetWinPathString();
3548 if (selection
& GITSLC_COLFILENAME
)
3550 sClipboard
+= _T("\t")+entry
->GetFileOrDirectoryName();
3552 if (selection
& GITSLC_COLEXT
)
3554 sClipboard
+= _T("\t")+entry
->GetFileExtension();
3557 if (selection
& GITSLC_COLSTATUS
)
3559 sClipboard
+= _T("\t")+entry
->GetActionName();
3562 if (selection
& SVNSLC_COLDATE
)
3564 TCHAR datebuf
[SVN_DATE_BUFFER
];
3565 apr_time_t date
= entry
->last_commit_date
;
3566 SVN::formatDate(datebuf
, date
, true);
3571 sClipboard
+= _T("\t")+temp
;
3573 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
3577 if ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
3580 = entry
->present_props
[m_ColumnManager
.GetName(i
)];
3581 sClipboard
+= _T("\t") + value
;
3585 if (selection
& GITSLC_COLADD
)
3587 sClipboard
+= _T("\t")+entry
->m_StatAdd
;
3589 if (selection
& GITSLC_COLDEL
)
3591 sClipboard
+= _T("\t")+entry
->m_StatDel
;
3594 sClipboard
+= _T("\r\n");
3597 return CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
3600 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
3603 std::set
<CString
> changelists
;
3604 POSITION pos
= GetFirstSelectedItemPosition();
3606 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3608 FileEntry
* entry
= GetListEntry(index
);
3609 if (!entry
->changelist
.IsEmpty())
3610 changelists
.insert(entry
->changelist
);
3612 return changelists
.size();
3617 bool CGitStatusListCtrl::PrepareGroups(bool bForce
/* = false */)
3620 bool bHasGroups
=false;
3623 for(int i
=0;i
< this->m_arStatusArray
.size(); i
++)
3625 int ParentNo
= m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3627 max
=m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3630 if ( this->m_UnRevFileList
.GetCount()>0 ||
3631 this->m_IgnoreFileList
.GetCount()>0 ||
3638 EnableGroupView(bHasGroups
);
3640 TCHAR groupname
[1024];
3646 grp
.cbSize
= sizeof(LVGROUP
);
3647 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3650 //if(m_UnRevFileList.GetCount()>0)
3653 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MERGEDFILES
)), 1023);
3654 grp
.pszHeader
= groupname
;
3655 grp
.iGroupId
= MERGE_MASK
;
3656 grp
.uAlign
= LVGA_HEADER_LEFT
;
3657 InsertGroup(0, &grp
);
3659 for(int i
=0;i
<=max
;i
++)
3662 str
.Format(IDS_STATUSLIST_GROUP_DIFFWITHPARENT
, i
+1);
3663 grp
.pszHeader
= str
.GetBuffer();
3664 str
.ReleaseBuffer();
3666 grp
.uAlign
= LVGA_HEADER_LEFT
;
3667 InsertGroup(i
+1, &grp
);
3672 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MODIFIEDFILES
)), 1023);
3673 grp
.pszHeader
= groupname
;
3674 grp
.iGroupId
= groupindex
;
3675 grp
.uAlign
= LVGA_HEADER_LEFT
;
3676 InsertGroup(groupindex
++, &grp
);
3680 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_NOTVERSIONEDFILES
)), 1023);
3681 grp
.pszHeader
= groupname
;
3682 grp
.iGroupId
= groupindex
;
3683 grp
.uAlign
= LVGA_HEADER_LEFT
;
3684 InsertGroup(groupindex
++, &grp
);
3687 //if(m_IgnoreFileList.GetCount()>0)
3689 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNOREDFILES
)), 1023);
3690 grp
.pszHeader
= groupname
;
3691 grp
.iGroupId
= groupindex
;
3692 grp
.uAlign
= LVGA_HEADER_LEFT
;
3693 InsertGroup(groupindex
++, &grp
);
3699 m_bHasIgnoreGroup
= false;
3701 // now add the items which don't belong to a group
3703 grp
.cbSize
= sizeof(LVGROUP
);
3704 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3705 CString
sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET
));
3706 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
3707 grp
.pszHeader
= groupname
;
3708 grp
.iGroupId
= groupindex
;
3709 grp
.uAlign
= LVGA_HEADER_LEFT
;
3710 InsertGroup(groupindex
++, &grp
);
3712 for (std::map
<CString
,int>::iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
3714 if (it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)!=0)
3717 grp
.cbSize
= sizeof(LVGROUP
);
3718 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3719 _tcsncpy_s(groupname
, 1024, it
->first
, 1023);
3720 grp
.pszHeader
= groupname
;
3721 grp
.iGroupId
= groupindex
;
3722 grp
.uAlign
= LVGA_HEADER_LEFT
;
3723 it
->second
= InsertGroup(groupindex
++, &grp
);
3726 m_bHasIgnoreGroup
= true;
3729 if (m_bHasIgnoreGroup
)
3731 // and now add the group 'ignore-on-commit'
3732 std::map
<CString
,int>::iterator it
= m_changelists
.find(SVNSLC_IGNORECHANGELIST
);
3733 if (it
!= m_changelists
.end())
3735 grp
.cbSize
= sizeof(LVGROUP
);
3736 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3737 _tcsncpy_s(groupname
, 1024, SVNSLC_IGNORECHANGELIST
, 1023);
3738 grp
.pszHeader
= groupname
;
3739 grp
.iGroupId
= groupindex
;
3740 grp
.uAlign
= LVGA_HEADER_LEFT
;
3741 it
->second
= InsertGroup(groupindex
, &grp
);
3748 void CGitStatusListCtrl::NotifyCheck()
3750 CWnd
* pParent
= GetLogicalParent();
3751 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3753 pParent
->SendMessage(GITSLNM_CHECKCHANGED
, m_nSelected
);
3757 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash
,CTGitPathList
*list
)
3761 m_CurrentVersion
=hash
;
3767 count
= list
->GetCount();
3769 CString head
= _T("HEAD");
3771 head
= _T("HEAD~1");
3773 if(hash
== GIT_REV_ZERO
)
3775 for(int i
=0;i
<count
;i
++)
3780 if(!g_Git
.IsInitRepos())
3782 // also list staged files which will be in the commit
3783 cmd
=(_T("git.exe diff-index --cached --raw ") + head
+ _T(" --numstat -C -M -z"));
3784 g_Git
.Run(cmd
, &cmdout
);
3787 cmd
=(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z"));
3789 cmd
.Format(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z -- \"%s\""),(*list
)[i
].GetGitPathString());
3792 if(g_Git
.Run(cmd
, &cmdout
, &cmdErr
))
3794 int last
= cmdErr
.RevertFind(0,-1);
3796 g_Git
.StringAppend(&str
, &cmdErr
[last
+ 1], CP_UTF8
, (int)cmdErr
.size() - last
-1);
3797 CMessageBox::Show(NULL
, str
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
3800 out
.append(cmdout
, 0);
3802 else // Init Repository
3804 //We will list all added file for init repository because commit will comit these
3806 cmd
=_T("git.exe ls-files -s -t -z");
3808 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
3810 g_Git
.Run(cmd
, &cmdout
);
3812 out
.append(cmdout
,0);
3816 if(g_Git
.IsInitRepos())
3818 m_StatusFileList
.ParserFromLsFile(out
);
3819 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
3820 ((CTGitPath
&)(m_StatusFileList
[i
])).m_Action
=CTGitPath::LOGACTIONS_ADDED
;
3823 this->m_StatusFileList
.ParserFromLog(out
);
3825 //handle delete conflict case, when remote : modified, local : deleted.
3826 for(int i
=0;i
<count
;i
++)
3832 cmd
=_T("git.exe ls-files -u -t -z");
3834 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list
)[i
].GetGitPathString());
3836 g_Git
.Run(cmd
, &cmdout
);
3838 CTGitPathList conflictlist
;
3839 conflictlist
.ParserFromLog(cmdout
);
3840 for(int i
=0;i
<conflictlist
.GetCount();i
++)
3842 CTGitPath
*p
=m_StatusFileList
.LookForGitPath(conflictlist
[i
].GetGitPathString());
3844 p
->m_Action
|=CTGitPath::LOGACTIONS_UNMERGED
;
3846 m_StatusFileList
.AddPath(conflictlist
[i
]);
3850 // handle source files of file renames/moves (issue #860)
3851 // if a file gets renamed and the new file "git add"ed, diff-index doesn't list the source file anymore
3852 for(int i
= 0; i
< count
; i
++)
3858 cmd
= _T("git.exe ls-files -d -z");
3860 cmd
.Format(_T("git.exe ls-files -d -z -- \"%s\""),(*list
)[i
].GetGitPathString());
3862 g_Git
.Run(cmd
, &cmdout
);
3864 CTGitPathList deletelist
;
3865 deletelist
.ParserFromLog(cmdout
, true);
3866 for(int i
= 0; i
< deletelist
.GetCount(); i
++)
3868 CTGitPath
*p
= m_StatusFileList
.LookForGitPath(deletelist
[i
].GetGitPathString());
3870 m_StatusFileList
.AddPath(deletelist
[i
]);
3871 else if ((p
->m_Action
== CTGitPath::LOGACTIONS_ADDED
|| p
->m_Action
== CTGitPath::LOGACTIONS_REPLACED
) && !p
->Exists())
3873 if (CMessageBox::Show(m_hWnd
, _T("TortoiseGit detected that the file \"") + p
->GetWinPathString() +_T("\" does not exist, but is staged as \"Added\".\nThe commit dialog cannot handle this.\n\nDo you want to remove it from the index?"), _T("TortoiseGit"), 1, IDI_EXCLAMATION
, _T("&Remove file from index"), _T("&Ignore")) == 1)
3875 g_Git
.Run(_T("git.exe rm -f --cache -- \"") + p
->GetWinPathString() + _T("\""), &cmdout
);
3876 m_StatusFileList
.RemoveItem(*p
);
3888 count
= list
->GetCount();
3890 for(int i
=0;i
<count
;i
++)
3895 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash
);
3897 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash
,(*list
)[i
].GetGitPathString());
3899 g_Git
.Run(cmd
, &cmdout
, NULL
);
3903 this->m_StatusFileList
.ParserFromLog(out
);
3907 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
3909 CTGitPath
* gitpatch
=(CTGitPath
*)&m_StatusFileList
[i
];
3910 gitpatch
->m_Checked
= TRUE
;
3911 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
3914 this->m_bBusy
=FALSE
;
3918 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList
&list
)
3920 m_arStatusArray
.clear();
3921 for(int i
=0;i
<list
.GetCount();i
++)
3923 CTGitPath
* gitpath
=(CTGitPath
*)&list
[i
];
3925 if(gitpath
->m_Action
& CTGitPath::LOGACTIONS_HIDE
)
3928 gitpath
->m_Checked
= TRUE
;
3929 m_arStatusArray
.push_back((CTGitPath
*)&list
[i
]);
3934 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
&list
)
3936 m_UnRevFileList
= list
;
3937 for(int i
=0;i
<m_UnRevFileList
.GetCount();i
++)
3939 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
3940 gitpatch
->m_Checked
= FALSE
;
3941 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
3946 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
*List
)
3948 this->m_UnRevFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
,List
);
3949 for(int i
=0;i
<m_UnRevFileList
.GetCount();i
++)
3951 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
3952 gitpatch
->m_Checked
= FALSE
;
3953 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
3958 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList
*List
)
3960 this->m_IgnoreFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
|CTGitPath::LOGACTIONS_IGNORE
,List
);
3961 for(int i
=0;i
<m_IgnoreFileList
.GetCount();i
++)
3963 CTGitPath
* gitpatch
=(CTGitPath
*)&m_IgnoreFileList
[i
];
3964 gitpatch
->m_Checked
= FALSE
;
3965 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
3969 int CGitStatusListCtrl::UpdateFileList(int mask
,bool once
,CTGitPathList
*List
)
3971 if(mask
&CGitStatusListCtrl::FILELIST_MODIFY
)
3973 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_MODIFY
)))
3975 UpdateFileList(git_revnum_t(GIT_REV_ZERO
),List
);
3976 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_MODIFY
;
3979 if(mask
&CGitStatusListCtrl::FILELIST_UNVER
)
3981 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_UNVER
)))
3983 UpdateUnRevFileList(List
);
3984 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
3986 if(mask
&CGitStatusListCtrl::FILELIST_IGNORE
&& (once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_IGNORE
))))
3988 UpdateIgnoreFileList(List
);
3989 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
3995 void CGitStatusListCtrl::Clear()
3998 this->DeleteAllItems();
3999 this->m_arListArray
.clear();
4000 this->m_arStatusArray
.clear();
4001 this->m_changelists
.clear();
4004 bool CGitStatusListCtrl::CheckMultipleDiffs()
4006 UINT selCount
= GetSelectedCount();
4007 if (selCount
> max(3, (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\NumDiffWarning"), 10)))
4010 message
.Format(CString(MAKEINTRESOURCE(IDS_STATUSLIST_WARN_MAXDIFF
)), selCount
);
4011 return ::MessageBox(GetSafeHwnd(), message
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
) == IDYES
;
4015 //////////////////////////////////////////////////////////////////////////
4017 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
)
4019 if(pFmtEtc
->cfFormat
== CF_HDROP
&& medium
.tymed
== TYMED_HGLOBAL
)
4021 HDROP hDrop
= (HDROP
)GlobalLock(medium
.hGlobal
);
4024 TCHAR szFileName
[MAX_PATH
];
4026 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, NULL
, 0);
4029 clientpoint
.x
= pt
.x
;
4030 clientpoint
.y
= pt
.y
;
4031 ScreenToClient(m_hTargetWnd
, &clientpoint
);
4032 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
4034 CTSVNPathList changelistItems
;
4035 for(UINT i
= 0; i
< cFiles
; ++i
)
4037 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
4038 changelistItems
.AddPath(CTSVNPath(szFileName
));
4040 // find the changelist name
4041 CString sChangelist
;
4042 LONG_PTR nGroup
= m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
);
4043 for (std::map
<CString
, int>::iterator it
= m_pSVNStatusListCtrl
->m_changelists
.begin(); it
!= m_pSVNStatusListCtrl
->m_changelists
.end(); ++it
)
4044 if (it
->second
== nGroup
)
4045 sChangelist
= it
->first
;
4046 if (!sChangelist
.IsEmpty())
4049 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
4051 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
4053 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
4056 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
4059 e
->changelist
= sChangelist
;
4062 if (m_pSVNStatusListCtrl
->m_changelists
.find(e
->changelist
)!=m_pSVNStatusListCtrl
->m_changelists
.end())
4063 m_pSVNStatusListCtrl
->SetItemGroup(index
, m_pSVNStatusListCtrl
->m_changelists
[e
->changelist
]);
4065 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
4071 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4072 if (hParentWnd
!= NULL
)
4073 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
4079 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
4085 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
4087 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
4089 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
4092 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
4095 e
->changelist
= sChangelist
;
4096 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
4101 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4102 if (hParentWnd
!= NULL
)
4103 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
4109 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
4115 for(UINT i
= 0; i
< cFiles
; ++i
)
4117 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
4118 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4119 if (hParentWnd
!= NULL
)
4120 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)szFileName
);
4124 GlobalUnlock(medium
.hGlobal
);
4126 return true; //let base free the medium
4128 HRESULT STDMETHODCALLTYPE
CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
)
4130 CIDropTarget::DragOver(grfKeyState
, pt
, pdwEffect
);
4131 *pdwEffect
= DROPEFFECT_COPY
;
4132 if (m_pSVNStatusListCtrl
)
4135 clientpoint
.x
= pt
.x
;
4136 clientpoint
.y
= pt
.y
;
4137 ScreenToClient(m_hTargetWnd
, &clientpoint
);
4138 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
4140 *pdwEffect
= DROPEFFECT_MOVE
;
4142 else if ((!m_pSVNStatusListCtrl
->m_bFileDropsEnabled
)||(m_pSVNStatusListCtrl
->m_bOwnDrag
))
4144 *pdwEffect
= DROPEFFECT_NONE
;
4152 void CGitStatusListCtrl::FilesExport()
4155 // export all changed files to a folder
4156 CBrowseFolder browseFolder
;
4157 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
4158 if (browseFolder
.Show(GetSafeHwnd(), exportDir
) != CBrowseFolder::OK
)
4161 POSITION pos
= GetFirstSelectedItemPosition();
4163 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4165 CTGitPath
*fd
= (CTGitPath
*)GetItemData(index
);
4166 // we cannot export directories or folders
4167 if (fd
->m_Action
== CTGitPath::LOGACTIONS_DELETED
|| fd
->IsDirectory())
4170 CAppUtils::CreateMultipleDirectory(exportDir
+ _T("\\") + fd
->GetDirectory().GetWinPathString());
4171 CString filename
= exportDir
+ _T("\\") + fd
->GetWinPathString();
4172 if (m_CurrentVersion
== GIT_REV_ZERO
)
4174 if (!CopyFile(g_Git
.m_CurrentDir
+ _T("\\") + fd
->GetWinPath(), filename
, false))
4176 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
4182 if (g_Git
.GetOneFile(m_CurrentVersion
, *fd
, filename
))
4185 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, fd
->GetGitPathString(), m_CurrentVersion
, filename
);
4186 if (CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), 2, IDI_WARNING
, CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
4193 void CGitStatusListCtrl::FileSaveAs(CTGitPath
*path
)
4196 filename
.Format(_T("%s-%s%s"), path
->GetBaseFilename(), this->m_CurrentVersion
.Left(g_Git
.GetShortHASHLength()), path
->GetFileExtension());
4197 CFileDialog
dlg(FALSE
,NULL
,
4199 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
4201 CString currentpath
;
4202 currentpath
=g_Git
.m_CurrentDir
+_T("\\");
4203 currentpath
+=path
->GetWinPathString();
4205 dlg
.m_ofn
.lpstrInitialDir
=currentpath
.GetBuffer();
4208 INT_PTR ret
= dlg
.DoModal();
4209 SetCurrentDirectory(g_Git
.m_CurrentDir
);
4212 filename
= dlg
.GetPathName();
4213 if(m_CurrentVersion
== GIT_REV_ZERO
)
4215 if(!CopyFile(g_Git
.m_CurrentDir
+_T("\\") + path
->GetWinPath(),filename
,false))
4217 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
4224 if(g_Git
.GetOneFile(m_CurrentVersion
,*path
,filename
))
4226 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, path
->GetGitPathString(), m_CurrentVersion
, filename
);
4227 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
4235 int CGitStatusListCtrl::RevertSelectedItemToVersion(bool parent
)
4237 if(this->m_CurrentVersion
.IsEmpty())
4239 if(this->m_CurrentVersion
== GIT_REV_ZERO
)
4242 POSITION pos
= GetFirstSelectedItemPosition();
4245 std::map
<CString
, int> versionMap
;
4246 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4248 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
4252 int parentNo
= fentry
->m_ParentNo
& PARENT_MASK
;
4254 ref
.Format(_T("%s^%d"), m_CurrentVersion
, parentNo
+ 1);
4256 if (g_Git
.GetHash(hash
, ref
))
4258 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + ref
+ _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
4262 version
= hash
.ToString();
4265 version
= m_CurrentVersion
;
4267 cmd
.Format(_T("git.exe checkout %s -- \"%s\""), version
, fentry
->GetGitPathString());
4269 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
4271 if (MessageBox(out
, _T("TortoiseGit"), MB_ICONEXCLAMATION
| MB_OKCANCEL
) == IDCANCEL
)
4275 versionMap
[version
]++;
4279 for (auto it
= versionMap
.begin(); it
!= versionMap
.end(); ++it
)
4281 CString versionEntry
;
4282 versionEntry
.Format(IDS_STATUSLIST_FILESREVERTED
, it
->second
, it
->first
);
4283 out
+= versionEntry
+ _T("\r\n");
4285 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
4289 void CGitStatusListCtrl::OpenFile(CTGitPath
*filepath
,int mode
)
4292 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
4294 file
= g_Git
.m_CurrentDir
+ _T("\\") + filepath
->GetWinPath();
4299 GetTempPath(temppath
);
4300 TCHAR szTempName
[MAX_PATH
];
4301 GetTempFileName(temppath
, filepath
->GetBaseFilename(), 0, szTempName
);
4302 CString
temp(szTempName
);
4303 DeleteFile(szTempName
);
4304 CreateDirectory(szTempName
, NULL
);
4305 file
.Format(_T("%s\\%s_%s%s"),
4307 filepath
->GetBaseFilename(),
4308 m_CurrentVersion
.Left(g_Git
.GetShortHASHLength()),
4309 filepath
->GetFileExtension());
4311 if(g_Git
.GetOneFile(m_CurrentVersion
, *filepath
, file
))
4313 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, filepath
->GetGitPathString(), m_CurrentVersion
, file
);
4314 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
4317 SetFileAttributes(file
, FILE_ATTRIBUTE_READONLY
);
4319 if(mode
== ALTERNATIVEEDITOR
)
4321 CAppUtils::LaunchAlternativeEditor(file
);
4324 int ret
= HINSTANCE_ERROR
;
4328 ret
= (int)ShellExecute(this->m_hWnd
, NULL
,file
, NULL
, NULL
, SW_SHOW
);
4330 if (ret
> HINSTANCE_ERROR
)
4337 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
4339 CAppUtils::LaunchApplication(cmd
, NULL
, false);