1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2008 - 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
)
132 m_bIsRevertTheirMy
= false;
133 this->m_nLineAdded
=this->m_nLineDeleted
=0;
136 CGitStatusListCtrl::~CGitStatusListCtrl()
138 // if (m_pDropTarget)
139 // delete m_pDropTarget;
143 void CGitStatusListCtrl::ClearStatusArray()
146 Locker
lock(m_critSec
);
147 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
149 delete m_arStatusArray
[i
];
151 m_arStatusArray
.clear();
155 void CGitStatusListCtrl::Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
/* = GitSLC_POPALL */, bool bHasCheckboxes
/* = true */, bool bHasWC
/* = true */, DWORD allowedColumns
/* = 0xffffffff */)
157 Locker
lock(m_critSec
);
159 m_dwDefaultColumns
= dwColumns
| 1;
160 m_dwContextMenus
= dwContextMenus
;
161 m_bHasCheckboxes
= bHasCheckboxes
;
164 // set the extended style of the listcontrol
165 // 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.
166 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
167 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
168 if (DWORD(regFullRowSelect
))
169 exStyle
|= LVS_EX_FULLROWSELECT
;
170 exStyle
|= (bHasCheckboxes
? LVS_EX_CHECKBOXES
: 0);
172 SetExtendedStyle(exStyle
);
174 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
176 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
177 m_nRestoreOvl
= SYS_IMAGE_LIST().AddIcon((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_RESTOREOVL
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
));
178 SYS_IMAGE_LIST().SetOverlayImage(m_nRestoreOvl
, OVL_RESTORE
);
179 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
181 // keep CSorter::operator() in sync!!
182 static UINT standardColumnNames
[GITSLC_NUMCOLUMNS
]
183 = { IDS_STATUSLIST_COLFILE
184 , IDS_STATUSLIST_COLFILENAME
185 , IDS_STATUSLIST_COLEXT
186 , IDS_STATUSLIST_COLSTATUS
187 , IDS_STATUSLIST_COLADD
188 , IDS_STATUSLIST_COLDEL
189 , IDS_STATUSLIST_COLLASTMODIFIED
190 , IDS_STATUSLIST_COLSIZE
193 m_ColumnManager
.SetNames(standardColumnNames
,GITSLC_NUMCOLUMNS
);
194 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, 0xffffffff & ~(allowedColumns
| m_dwDefaultColumns
), sColumnInfoContainer
, GITSLC_NUMCOLUMNS
);
198 if (m_pDropTarget
== NULL
)
200 m_pDropTarget
= new CGitStatusListCtrlDropTarget(this);
201 RegisterDragDrop(m_hWnd
,m_pDropTarget
);
202 // create the supported formats:
204 ftetc
.dwAspect
= DVASPECT_CONTENT
;
206 ftetc
.tymed
= TYMED_HGLOBAL
;
207 ftetc
.cfFormat
=CF_HDROP
;
208 m_pDropTarget
->AddSuportedFormat(ftetc
);
215 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID
)
217 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
220 BOOL
CGitStatusListCtrl::GetStatus ( const CTGitPathList
* pathList
221 , bool bUpdate
/* = FALSE */
222 , bool bShowIgnores
/* = false */
225 Locker
lock(m_critSec
);
226 int mask
= CGitStatusListCtrl::FILELIST_MODIFY
;
228 mask
|= CGitStatusListCtrl::FILELIST_IGNORE
;
230 mask
|= CGitStatusListCtrl::FILELIST_UNVER
;
231 this->UpdateFileList(mask
,bUpdate
,(CTGitPathList
*)pathList
);
235 int refetchcounter
= 0;
238 // force the cursor to change
241 SetCursorPos(pt
.x
, pt
.y
);
243 m_mapFilenameToChecked
.clear();
244 //m_StatusUrlList.Clear();
245 bool bHasChangelists
= (m_changelists
.size() > 1 || (!m_changelists
.empty() && !m_bHasIgnoreGroup
));
246 m_changelists
.clear();
247 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
249 FileEntry
* entry
= m_arStatusArray
[i
];
250 if ( bHasChangelists
&& entry
->checked
)
252 // If change lists are present, remember all checked entries
253 CString path
= entry
->GetPath().GetGitPathString();
254 m_mapFilenameToChecked
[path
] = true;
256 if ( (entry
->status
==git_wc_status_unversioned
|| entry
->status
==git_wc_status_missing
) && entry
->checked
)
258 // The user manually selected an unversioned or missing file. We remember
259 // this so that the selection can be restored when refreshing.
260 CString path
= entry
->GetPath().GetGitPathString();
261 m_mapFilenameToChecked
[path
] = true;
263 else if ( entry
->status
> git_wc_status_normal
&& !entry
->checked
)
265 // The user manually deselected a versioned file. We remember
266 // this so that the deselection can be restored when refreshing.
267 CString path
= entry
->GetPath().GetGitPathString();
268 m_mapFilenameToChecked
[path
] = false;
272 // use a sorted path list to make sure we fetch the status of
273 // parent items first, *then* the child items (if any)
274 CTGitPathList sortedPathList
= pathList
;
275 sortedPathList
.SortByPathname();
280 m_bHasExternalsFromDifferentRepos
= FALSE
;
281 m_bHasExternals
= FALSE
;
282 m_bHasUnversionedItems
= FALSE
;
284 m_bHasChangeLists
= false;
285 m_bShowIgnores
= bShowIgnores
;
292 // first clear possible status data left from
293 // previous GetStatus() calls
296 m_StatusFileList
= sortedPathList
;
298 // Since Git_client_status() returns all files, even those in
299 // folders included with Git:externals we need to check if all
300 // files we get here belongs to the same repository.
301 // It is possible to commit changes in an external folder, as long
302 // as the folder belongs to the same repository (but another path),
303 // but it is not possible to commit all files if the externals are
304 // from a different repository.
306 // To check if all files belong to the same repository, we compare the
307 // UUID's - if they're identical then the files belong to the same
308 // repository and can be committed. But if they're different, then
309 // tell the user to commit all changes in the external folders
311 CStringA sUUID
; // holds the repo UUID
312 CTGitPathList arExtPaths
; // list of Git:external paths
318 m_nTargetCount
= sortedPathList
.GetCount();
320 GitStatus
status(m_pbCanceled
);
321 if(m_nTargetCount
> 1 && sortedPathList
.AreAllPathsFilesInOneDirectory())
323 // This is a special case, where we've been given a list of files
324 // all from one folder
325 // We handle them by setting a status filter, then requesting the Git status of
326 // all the files in the directory, filtering for the ones we're interested in
327 status
.SetFilter(sortedPathList
);
329 // if all selected entries are files, we don't do a recursive status
330 // fetching. But if only one is a directory, we have to recurse.
331 git_depth_t depth
= git_depth_files
;
332 // We have set a filter. If all selected items were files or we fetch
333 // the status not recursively, then we have to include
334 // ignored items too - the user has selected them
335 bool bShowIgnoresRight
= true;
336 for (int fcindex
=0; fcindex
<sortedPathList
.GetCount(); ++fcindex
)
338 if (sortedPathList
[fcindex
].IsDirectory())
340 depth
= git_depth_infinity
;
341 bShowIgnoresRight
= false;
345 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
.GetCommonDirectory(), bUpdate
, sUUID
, arExtPaths
, true, depth
, bShowIgnoresRight
))
352 for(int nTarget
= 0; nTarget
< m_nTargetCount
; nTarget
++)
354 // check whether the path we want the status for is already fetched due to status-fetching
356 // this check is only done for file paths, because folder paths could be included already
357 // but not recursively
358 if (sortedPathList
[nTarget
].IsDirectory() || GetListEntry(sortedPathList
[nTarget
]) == NULL
)
360 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
[nTarget
], bUpdate
, sUUID
,
361 arExtPaths
, false, git_depth_infinity
, bShowIgnores
))
369 // remove the 'helper' files of conflicted items from the list.
370 // otherwise they would appear as unversioned files.
371 for (INT_PTR cind
= 0; cind
< m_ConflictFileList
.GetCount(); ++cind
)
373 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
375 if (m_arStatusArray
[i
]->GetPath().IsEquivalentTo(m_ConflictFileList
[cind
]))
377 delete m_arStatusArray
[i
];
378 m_arStatusArray
.erase(m_arStatusArray
.begin()+i
);
384 } while(!BuildStatistics() && (refetchcounter
< 2) && (*m_pbCanceled
==false));
389 SetCursorPos(pt
.x
, pt
.y
);
396 // Get the show-flags bitmap value which corresponds to a particular Git status
397 DWORD
CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status
)
401 case git_wc_status_none
:
402 case git_wc_status_unversioned
:
403 return GITSLC_SHOWUNVERSIONED
;
404 case git_wc_status_ignored
:
406 return GITSLC_SHOWDIRECTS
;
407 return GITSLC_SHOWDIRECTS
|GITSLC_SHOWIGNORED
;
408 case git_wc_status_incomplete
:
409 return GITSLC_SHOWINCOMPLETE
;
410 case git_wc_status_normal
:
411 return GITSLC_SHOWNORMAL
;
412 case git_wc_status_external
:
413 return GITSLC_SHOWEXTERNAL
;
414 case git_wc_status_added
:
415 return GITSLC_SHOWADDED
;
416 case git_wc_status_missing
:
417 return GITSLC_SHOWMISSING
;
418 case git_wc_status_deleted
:
419 return GITSLC_SHOWREMOVED
;
420 case git_wc_status_replaced
:
421 return GITSLC_SHOWREPLACED
;
422 case git_wc_status_modified
:
423 return GITSLC_SHOWMODIFIED
;
424 case git_wc_status_merged
:
425 return GITSLC_SHOWMERGED
;
426 case git_wc_status_conflicted
:
427 return GITSLC_SHOWCONFLICTED
;
428 case git_wc_status_obstructed
:
429 return GITSLC_SHOWOBSTRUCTED
;
431 // we should NEVER get here!
438 void CGitStatusListCtrl::Show(unsigned int dwShow
, unsigned int dwCheck
/*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList
,bool UseStoredCheckStatus
)
440 CWinApp
* pApp
= AfxGetApp();
442 pApp
->DoWaitCursor(1);
444 Locker
lock(m_critSec
);
445 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
447 //SetItemCount(listIndex);
452 m_nShownUnversioned
= 0;
453 m_nShownModified
= 0;
456 m_nShownConflicted
= 0;
458 m_nShownSubmodules
= 0;
462 m_arStatusArray
.clear();
463 for(int i
=0;i
<this->m_StatusFileList
.GetCount();i
++)
465 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
468 for(int i
=0;i
<this->m_UnRevFileList
.GetCount();i
++)
470 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
473 for(int i
=0;i
<this->m_IgnoreFileList
.GetCount();i
++)
475 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
479 if (m_nSortedColumn
>= 0)
481 CSorter
predicate (&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
482 std::sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
486 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
488 //set default checkbox status
489 CTGitPath
* entry
= ((CTGitPath
*)m_arStatusArray
[i
]);
490 CString path
= entry
->GetGitPathString();
491 if (!m_mapFilenameToChecked
.empty() && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end())
493 entry
->m_Checked
=m_mapFilenameToChecked
[path
];
495 else if (!UseStoredCheckStatus
)
497 bool autoSelectSubmodules
= !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
);
498 if(entry
->m_Action
& dwCheck
&& autoSelectSubmodules
)
499 entry
->m_Checked
=true;
501 entry
->m_Checked
=false;
502 m_mapFilenameToChecked
[path
] = entry
->m_Checked
;
505 if(entry
->m_Action
& dwShow
)
507 AddEntry(entry
,langID
,index
);
512 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
513 for (int col
= 0; col
<= maxcol
; col
++)
514 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
517 GetStatisticsString();
519 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
520 HDITEM HeaderItem
= {0};
521 HeaderItem
.mask
= HDI_FORMAT
;
522 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
524 pHeader
->GetItem(i
, &HeaderItem
);
525 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
526 pHeader
->SetItem(i
, &HeaderItem
);
528 if (m_nSortedColumn
>= 0)
530 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
531 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
532 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
538 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
539 EnsureVisible(nSelectedEntry
, false);
543 // Restore the item at the top of the list.
544 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
546 if ( !EnsureVisible(nTopIndex
+i
,false) )
554 pApp
->DoWaitCursor(-1);
560 this->BuildStatistics();
564 CWinApp
* pApp
= AfxGetApp();
566 pApp
->DoWaitCursor(1);
568 m_bShowFolders
= bShowFolders
;
570 int nTopIndex
= GetTopIndex();
571 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
572 int nSelectedEntry
= 0;
573 if (posSelectedEntry
)
574 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
580 m_arListArray
.clear();
582 m_arListArray
.reserve(m_arStatusArray
.size());
583 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
586 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
588 FileEntry
* entry
= m_arStatusArray
[i
];
589 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
591 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
593 if (entry
->IsFolder() && (!bShowFolders
))
594 continue; // don't show folders if they're not wanted.
597 git_wc_status_kind status
= GitStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
598 DWORD showFlags
= GetShowFlagsFromGitStatus(status
);
599 if (entry
->IsLocked())
600 showFlags
|= SVNSLC_SHOWLOCKS
;
602 showFlags
|= SVNSLC_SHOWSWITCHED
;
603 if (!entry
->changelist
.IsEmpty())
604 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
606 bool bAllowCheck
= ((entry
->changelist
.Compare(GITSLC_IGNORECHANGELIST
) != 0)
607 && (m_bCheckIfGroupsExist
|| (m_changelists
.empty() || (m_changelists
.size() == 1 && m_bHasIgnoreGroup
))));
609 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
611 if (status
!= Git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& GitSLC_SHOWIGNORED
))
613 if ((!entry
->IsFolder()) && (status
== Git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
615 if (PathFileExists(entry
->GetPath().GetWinPath()))
617 m_arListArray
.push_back(i
);
618 if ((dwCheck
& SVNSLC_SHOWREMOVEDANDPRESENT
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
621 entry
->checked
= true;
623 AddEntry(entry
, langID
, listIndex
++);
626 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
628 m_arListArray
.push_back(i
);
629 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
632 entry
->checked
= true;
634 AddEntry(entry
, langID
, listIndex
++);
636 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
638 m_arListArray
.push_back(i
);
639 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
642 entry
->checked
= true;
644 AddEntry(entry
, langID
, listIndex
++);
650 SetItemCount(listIndex
);
652 m_ColumnManager
.UpdateRelevance (m_arStatusArray
, m_arListArray
);
654 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
655 for (int col
= 0; col
<= maxcol
; col
++)
656 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
659 GetStatisticsString();
661 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
662 HDITEM HeaderItem
= {0};
663 HeaderItem
.mask
= HDI_FORMAT
;
664 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
666 pHeader
->GetItem(i
, &HeaderItem
);
667 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
668 pHeader
->SetItem(i
, &HeaderItem
);
672 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
673 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
674 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
679 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
680 EnsureVisible(nSelectedEntry
, false);
684 // Restore the item at the top of the list.
685 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
687 if ( !EnsureVisible(nTopIndex
+i
,false) )
695 pApp
->DoWaitCursor(-1);
697 m_bEmpty
= (GetItemCount() == 0);
703 void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList
& checkedList
, bool /*bShowFolders*/ /* = true */)
706 for(int i
=0;i
<checkedList
.GetCount();i
++)
707 this->AddEntry((CTGitPath
*)&checkedList
[i
],0,i
);
711 Locker
lock(m_critSec
);
712 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
714 CWinApp
* pApp
= AfxGetApp();
716 pApp
->DoWaitCursor(1);
718 m_bShowFolders
= bShowFolders
;
720 int nTopIndex
= GetTopIndex();
721 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
722 int nSelectedEntry
= 0;
723 if (posSelectedEntry
)
724 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
730 m_arListArray
.clear();
732 m_arListArray
.reserve(m_arStatusArray
.size());
733 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
736 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
738 FileEntry
* entry
= m_arStatusArray
[i
];
739 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
741 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
743 if (entry
->IsFolder() && (!bShowFolders
))
744 continue; // don't show folders if they're not wanted.
746 git_wc_status_kind status
= SVNStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
747 DWORD showFlags
= GetShowFlagsFromSVNStatus(status
);
748 if (entry
->IsLocked())
749 showFlags
|= SVNSLC_SHOWLOCKS
;
750 if (!entry
->changelist
.IsEmpty())
751 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
753 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
754 if (status
!= git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& SVNSLC_SHOWIGNORED
))
756 for (int npath
= 0; npath
< checkedList
.GetCount(); ++npath
)
758 if (entry
->GetPath().IsEquivalentTo(checkedList
[npath
]))
760 entry
->checked
= true;
764 if ((!entry
->IsFolder()) && (status
== git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
766 if (PathFileExists(entry
->GetPath().GetWinPath()))
768 m_arListArray
.push_back(i
);
769 AddEntry(entry
, langID
, listIndex
++);
772 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
774 m_arListArray
.push_back(i
);
775 AddEntry(entry
, langID
, listIndex
++);
777 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
779 m_arListArray
.push_back(i
);
780 AddEntry(entry
, langID
, listIndex
++);
782 else if (entry
->switched
)
784 m_arListArray
.push_back(i
);
785 AddEntry(entry
, langID
, listIndex
++);
791 SetItemCount(listIndex
);
793 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
794 for (int col
= 0; col
<= maxcol
; col
++)
795 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
798 GetStatisticsString();
800 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
801 HDITEM HeaderItem
= {0};
802 HeaderItem
.mask
= HDI_FORMAT
;
803 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
805 pHeader
->GetItem(i
, &HeaderItem
);
806 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
807 pHeader
->SetItem(i
, &HeaderItem
);
811 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
812 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
813 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
818 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
819 EnsureVisible(nSelectedEntry
, false);
823 // Restore the item at the top of the list.
824 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
826 if ( !EnsureVisible(nTopIndex
+i
,false) )
834 pApp
->DoWaitCursor(-1);
836 m_bEmpty
= (GetItemCount() == 0);
841 int CGitStatusListCtrl::GetColumnIndex(int mask
)
851 void CGitStatusListCtrl::AddEntry(CTGitPath
* GitPath
, WORD
/*langID*/, int listIndex
)
853 static CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
854 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
855 static bool abbreviateRenamings(((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\AbbreviateRenamings"), FALSE
)) == TRUE
);
856 static bool relativeTimes
= (CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
) != FALSE
);
858 CString path
= GitPath
->GetGitPathString();
861 int index
= listIndex
;
863 CString entryname
= GitPath
->GetGitPathString();
865 if (GitPath
->IsDirectory())
867 icon_idx
= m_nIconFolder
;
868 m_nShownSubmodules
++;
872 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(*GitPath
);
875 switch (GitPath
->m_Action
)
877 case CTGitPath::LOGACTIONS_ADDED
:
878 case CTGitPath::LOGACTIONS_COPY
:
881 case CTGitPath::LOGACTIONS_DELETED
:
884 case CTGitPath::LOGACTIONS_REPLACED
:
885 case CTGitPath::LOGACTIONS_MODIFIED
:
886 case CTGitPath::LOGACTIONS_MERGED
:
889 case CTGitPath::LOGACTIONS_UNMERGED
:
890 m_nShownConflicted
++;
892 case CTGitPath::LOGACTIONS_UNVER
:
893 m_nShownUnversioned
++;
896 m_nShownUnversioned
++;
899 if(GitPath
->m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !GitPath
->GetGitOldPathString().IsEmpty())
901 if (!abbreviateRenamings
)
905 rename
.Format(from
, GitPath
->GetGitOldPathString());
906 entryname
+= _T(" ") + rename
;
911 tgpl
.AddPath(*GitPath
);
912 CTGitPath
old(GitPath
->GetGitOldPathString());
914 CString commonRoot
= tgpl
.GetCommonRoot().GetGitPathString();
915 if (!commonRoot
.IsEmpty())
916 commonRoot
+= _T("/");
917 if (old
.GetFileOrDirectoryName() == GitPath
->GetFileOrDirectoryName() && old
.GetContainingDirectory().GetGitPathString() != "" && GitPath
->GetContainingDirectory().GetGitPathString())
919 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();
921 else if (!commonRoot
.IsEmpty())
923 entryname
= commonRoot
+ _T("{") + GitPath
->GetGitOldPathString().Mid(commonRoot
.GetLength()) + _T(" => ") + GitPath
->GetGitPathString().Mid(commonRoot
.GetLength()) + _T("}");
927 entryname
= GitPath
->GetGitOldPathString().Mid(commonRoot
.GetLength()) + _T(" => ") + GitPath
->GetGitPathString().Mid(commonRoot
.GetLength());
932 InsertItem(index
, entryname
, icon_idx
);
933 if (m_restorepaths
.find(GitPath
->GetWinPathString()) != m_restorepaths
.end())
934 SetItemState(index
, INDEXTOOVERLAYMASK(OVL_RESTORE
), TVIS_OVERLAYMASK
);
936 this->SetItemData(index
, (DWORD_PTR
)GitPath
);
937 // SVNSLC_COLFILENAME
938 SetItemText(index
, nCol
++, GitPath
->GetFileOrDirectoryName());
940 SetItemText(index
, nCol
++, GitPath
->GetFileExtension());
942 SetItemText(index
, nCol
++, GitPath
->GetActionName());
944 SetItemText(index
, GetColumnIndex(GITSLC_COLADD
),GitPath
->m_StatAdd
);
945 SetItemText(index
, GetColumnIndex(GITSLC_COLDEL
),GitPath
->m_StatDel
);
948 CString modificationDate
;
949 __int64 filetime
= GitPath
->GetLastWriteTime();
950 if (filetime
&& (GitPath
->m_Action
!= CTGitPath::LOGACTIONS_DELETED
))
952 FILETIME
* f
= (FILETIME
*)(__int64
*)&filetime
;
953 modificationDate
= CLoglistUtils::FormatDateAndTime(CTime(g_Git
.filetime_to_time_t(f
)), DATE_SHORTDATE
, true, relativeTimes
);
955 SetItemText(index
, GetColumnIndex(GITSLC_COLMODIFICATIONDATE
), modificationDate
);
958 if (GitPath
->IsDirectory())
959 SetItemText(index
, GetColumnIndex(GITSLC_COLSIZE
), _T(""));
963 StrFormatByteSize64(GitPath
->GetFileSize(), buf
, 100);
964 SetItemText(index
, GetColumnIndex(GITSLC_COLSIZE
), buf
);
967 SetCheck(index
, GitPath
->m_Checked
);
968 if (GitPath
->m_Checked
)
972 if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_IGNORE
)
973 SetItemGroup(index
, 2);
974 else if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
975 SetItemGroup(index
,1);
978 SetItemGroup(index
, GitPath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
));
986 bool CGitStatusListCtrl::SetItemGroup(int item
, int groupindex
)
988 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
993 i
.mask
= LVIF_GROUPID
;
996 i
.iGroupId
= groupindex
;
998 return !!SetItem(&i
);
1001 void CGitStatusListCtrl::OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1003 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1005 if (m_bBlock
|| m_arStatusArray
.empty())
1008 if (m_nSortedColumn
== phdr
->iItem
)
1009 m_bAscending
= !m_bAscending
;
1011 m_bAscending
= TRUE
;
1012 m_nSortedColumn
= phdr
->iItem
;
1013 Show(m_dwShow
, 0, m_bShowFolders
,false,true);
1018 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1020 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1023 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1024 if ((m_bBlock
)&&(m_bBlockUI
))
1026 // if we're blocked, prevent changing of the check state
1027 if ((!ISCHECKED(pNMLV
->uOldState
) && ISCHECKED(pNMLV
->uNewState
))||
1028 (ISCHECKED(pNMLV
->uOldState
) && !ISCHECKED(pNMLV
->uNewState
)))
1033 BOOL
CGitStatusListCtrl::OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1035 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1037 CWnd
* pParent
= GetLogicalParent();
1038 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
1040 pParent
->SendMessage(GITSLNM_ITEMCHANGED
, pNMLV
->iItem
);
1043 if ((pNMLV
->uNewState
==0)||(pNMLV
->uNewState
& LVIS_SELECTED
)||(pNMLV
->uNewState
& LVIS_FOCUSED
))
1049 bool bSelected
= !!(ListView_GetItemState(m_hWnd
, pNMLV
->iItem
, LVIS_SELECTED
) & LVIS_SELECTED
);
1050 int nListItems
= GetItemCount();
1053 // was the item checked?
1055 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1056 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1058 if (GetCheck(pNMLV
->iItem
))
1060 CheckEntry(pNMLV
->iItem
, nListItems
);
1063 POSITION pos
= GetFirstSelectedItemPosition();
1065 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1067 if (index
!= pNMLV
->iItem
)
1068 CheckEntry(index
, nListItems
);
1074 UncheckEntry(pNMLV
->iItem
, nListItems
);
1077 POSITION pos
= GetFirstSelectedItemPosition();
1079 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1081 if (index
!= pNMLV
->iItem
)
1082 UncheckEntry(index
, nListItems
);
1087 GetStatisticsString();
1094 void CGitStatusListCtrl::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1096 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
1101 void CGitStatusListCtrl::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1103 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
1108 void CGitStatusListCtrl::CheckEntry(int index
, int /*nListItems*/)
1110 Locker
lock(m_critSec
);
1111 //FileEntry * entry = GetListEntry(index);
1112 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1113 ASSERT(path
!= NULL
);
1116 m_mapFilenameToChecked
[path
->GetGitPathString()] = true;
1117 SetCheck(index
, TRUE
);
1118 //entry = GetListEntry(index);
1119 // if an unversioned item was checked, then we need to check if
1120 // the parent folders are unversioned too. If the parent folders actually
1121 // are unversioned, then check those too.
1123 if (entry
->status
== git_wc_status_unversioned
)
1125 // we need to check the parent folder too
1126 const CTGitPath
& folderpath
= entry
->path
;
1127 for (int i
=0; i
< nListItems
; ++i
)
1129 FileEntry
* testEntry
= GetListEntry(i
);
1130 ASSERT(testEntry
!= NULL
);
1131 if (testEntry
== NULL
)
1133 if (!testEntry
->checked
)
1135 if (testEntry
->path
.IsAncestorOf(folderpath
) && (!testEntry
->path
.IsEquivalentTo(folderpath
)))
1137 SetEntryCheck(testEntry
,i
,true);
1143 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1144 if ( (entry
->status
== git_wc_status_deleted
) || (m_bCheckChildrenWithParent
) || (bShift
) )
1146 // if a deleted folder gets checked, we have to check all
1147 // children of that folder too.
1148 if (entry
->path
.IsDirectory())
1150 SetCheckOnAllDescendentsOf(entry
, true);
1153 // if a deleted file or folder gets checked, we have to
1154 // check all parents of this item too.
1155 for (int i
=0; i
<nListItems
; ++i
)
1157 FileEntry
* testEntry
= GetListEntry(i
);
1158 ASSERT(testEntry
!= NULL
);
1159 if (testEntry
== NULL
)
1161 if (!testEntry
->checked
)
1163 if (testEntry
->path
.IsAncestorOf(entry
->path
) && (!testEntry
->path
.IsEquivalentTo(entry
->path
)))
1165 if ((testEntry
->status
== git_wc_status_deleted
)||(m_bCheckChildrenWithParent
))
1167 SetEntryCheck(testEntry
,i
,true);
1169 // now we need to check all children of this parent folder
1170 SetCheckOnAllDescendentsOf(testEntry
, true);
1177 if ( !path
->m_Checked
)
1179 path
->m_Checked
= TRUE
;
1184 void CGitStatusListCtrl::UncheckEntry(int index
, int /*nListItems*/)
1186 Locker
lock(m_critSec
);
1187 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1188 ASSERT(path
!= NULL
);
1191 SetCheck(index
, FALSE
);
1192 m_mapFilenameToChecked
[path
->GetGitPathString()] = false;
1193 //entry = GetListEntry(index);
1194 // item was unchecked
1196 if (entry
->path
.IsDirectory())
1198 // disable all files within an unselected folder, except when unchecking a folder with property changes
1199 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1200 if ( (entry
->status
!= git_wc_status_modified
) || (bShift
) )
1202 SetCheckOnAllDescendentsOf(entry
, false);
1205 else if (entry
->status
== git_wc_status_deleted
)
1207 // a "deleted" file was unchecked, so uncheck all parent folders
1208 // and all children of those parents
1209 for (int i
=0; i
<nListItems
; i
++)
1211 FileEntry
* testEntry
= GetListEntry(i
);
1212 ASSERT(testEntry
!= NULL
);
1213 if (testEntry
== NULL
)
1215 if (testEntry
->checked
)
1217 if (testEntry
->path
.IsAncestorOf(entry
->path
))
1219 if (testEntry
->status
== git_wc_status_deleted
)
1221 SetEntryCheck(testEntry
,i
,false);
1224 SetCheckOnAllDescendentsOf(testEntry
, false);
1231 if ( path
->m_Checked
)
1233 path
->m_Checked
= FALSE
;
1237 bool CGitStatusListCtrl::BuildStatistics()
1240 bool bRefetchStatus
= false;
1242 // now gather some statistics
1255 for (int i
=0; i
< (int)m_arStatusArray
.size(); ++i
)
1257 int status
=((CTGitPath
*)m_arStatusArray
[i
])->m_Action
;
1259 m_nLineAdded
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatAdd
);
1260 m_nLineDeleted
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatDel
);
1262 if(status
&(CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
1265 if(status
&CTGitPath::LOGACTIONS_DELETED
)
1268 if(status
&(CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_MODIFIED
))
1271 if(status
&CTGitPath::LOGACTIONS_UNMERGED
)
1274 if(status
&(CTGitPath::LOGACTIONS_IGNORE
|CTGitPath::LOGACTIONS_UNVER
))
1277 if(status
&(CTGitPath::LOGACTIONS_REPLACED
))
1280 if(((CTGitPath
*)m_arStatusArray
[i
])->m_Checked
)
1283 // } // switch (entry->status)
1285 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1286 return !bRefetchStatus
;
1292 int CGitStatusListCtrl::GetGroupFromPoint(POINT
* ppt
)
1294 // the point must be relative to the upper left corner of the control
1298 if (!IsGroupViewEnabled())
1307 while (((flags
& LVHT_BELOW
) == 0)&&(pt
.y
< rc
.bottom
))
1309 nItem
= HitTest(pt
, &flags
);
1310 if ((flags
& LVHT_ONITEM
)||(flags
& LVHT_EX_GROUP_HEADER
))
1312 // the first item below the point
1314 // check if the point is too much right (i.e. if the point
1315 // is farther to the right than the width of the item)
1317 GetItemRect(nItem
, &r
, LVIR_LABEL
);
1318 if (ppt
->x
> r
.right
)
1322 lv
.mask
= LVIF_GROUPID
;
1325 int groupID
= lv
.iGroupId
;
1326 // now we search upwards and check if the item above this one
1327 // belongs to another group. If it belongs to the same group,
1328 // we're not over a group header
1332 nItem
= HitTest(pt
, &flags
);
1333 if ((flags
& LVHT_ONITEM
)&&(nItem
>= 0))
1335 // the first item below the point
1337 lv
.mask
= LVIF_GROUPID
;
1340 if (lv
.iGroupId
!= groupID
)
1355 void CGitStatusListCtrl::OnContextMenuGroup(CWnd
* /*pWnd*/, CPoint point
)
1357 POINT clientpoint
= point
;
1358 ScreenToClient(&clientpoint
);
1359 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint
) >= 0))
1362 if (popup
.CreatePopupMenu())
1365 temp
.LoadString(IDS_STATUSLIST_CHECKGROUP
);
1366 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_CHECKGROUP
, temp
);
1367 temp
.LoadString(IDS_STATUSLIST_UNCHECKGROUP
);
1368 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_UNCHECKGROUP
, temp
);
1369 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1370 bool bCheck
= false;
1373 case IDGITLC_CHECKGROUP
:
1375 // fall through here
1376 case IDGITLC_UNCHECKGROUP
:
1378 int group
= GetGroupFromPoint(&clientpoint
);
1379 // go through all items and check/uncheck those assigned to the group
1380 // but block the OnLvnItemChanged handler
1383 for (int i
=0; i
<GetItemCount(); ++i
)
1385 SecureZeroMemory(&lv
, sizeof(LVITEM
));
1386 lv
.mask
= LVIF_GROUPID
;
1390 if (lv
.iGroupId
== group
)
1392 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
1395 bool bOldCheck
= entry
->m_Checked
;
1396 SetEntryCheck(entry
, i
, bCheck
);
1397 if (bCheck
!= bOldCheck
)
1408 GetStatisticsString();
1418 void CGitStatusListCtrl::OnContextMenuList(CWnd
* pWnd
, CPoint point
)
1421 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1423 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1424 CTGitPath
* filepath
;
1426 int selIndex
= GetSelectionMark();
1427 if ((point
.x
== -1) && (point
.y
== -1))
1430 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1431 ClientToScreen(&rect
);
1432 point
= rect
.CenterPoint();
1434 if ((GetSelectedCount() == 0) && (m_bHasCheckboxes
))
1436 // nothing selected could mean the context menu is requested for
1438 OnContextMenuGroup(pWnd
, point
);
1440 else if (selIndex
>= 0)
1442 //FileEntry * entry = GetListEntry(selIndex);
1444 filepath
= (CTGitPath
* )GetItemData(selIndex
);
1446 ASSERT(filepath
!= NULL
);
1447 if (filepath
== NULL
)
1450 //const CTGitPath& filepath = entry->path;
1451 int wcStatus
= filepath
->m_Action
;
1452 // entry is selected, now show the popup menu
1453 Locker
lock(m_critSec
);
1455 CMenu changelistSubMenu
;
1456 CMenu ignoreSubMenu
;
1457 if (popup
.CreatePopupMenu())
1459 //Add Menu for version controlled file
1461 if (GetSelectedCount() > 0 && wcStatus
& CTGitPath::LOGACTIONS_UNMERGED
)
1463 if (GetSelectedCount() == 1 && (m_dwContextMenus
& GITSLC_POPCONFLICT
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1465 popup
.AppendMenuIcon(IDGITLC_EDITCONFLICT
, IDS_MENUCONFLICT
, IDI_CONFLICT
);
1467 if (m_dwContextMenus
& GITSLC_POPRESOLVE
)
1469 popup
.AppendMenuIcon(IDGITLC_RESOLVECONFLICT
, IDS_STATUSLIST_CONTEXT_RESOLVED
, IDI_RESOLVE
);
1471 if ((m_dwContextMenus
& GITSLC_POPRESOLVE
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1473 popup
.AppendMenuIcon(IDGITLC_RESOLVETHEIRS
, IDS_SVNPROGRESS_MENUUSETHEIRS
, IDI_RESOLVE
);
1474 popup
.AppendMenuIcon(IDGITLC_RESOLVEMINE
, IDS_SVNPROGRESS_MENUUSEMINE
, IDI_RESOLVE
);
1476 if ((m_dwContextMenus
& GITSLC_POPCONFLICT
)||(m_dwContextMenus
& GITSLC_POPRESOLVE
))
1477 popup
.AppendMenu(MF_SEPARATOR
);
1480 if (GetSelectedCount() > 0)
1482 if (wcStatus
& CTGitPath::LOGACTIONS_UNVER
)
1483 if (m_dwContextMenus
& GITSLC_POPADD
)
1485 //if ( entry->IsFolder() )
1487 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1491 popup
.AppendMenuIcon(IDGITLC_ADD
, IDS_STATUSLIST_CONTEXT_ADD
, IDI_ADD
);
1496 if (!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
) && GetSelectedCount() > 0)
1498 bool bEntryAdded
= false;
1499 if (m_dwContextMenus
& GITSLC_POPCOMPAREWITHBASE
)
1501 if(filepath
->m_ParentNo
& MERGE_MASK
)
1502 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_TREE_DIFF
, IDI_DIFF
);
1504 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_LOG_COMPAREWITHBASE
, IDI_DIFF
);
1506 popup
.SetDefaultItem(IDGITLC_COMPARE
, FALSE
);
1510 if (!g_Git
.IsInitRepos() && (m_dwContextMenus
& GITSLC_POPGNUDIFF
))
1512 popup
.AppendMenuIcon(IDGITLC_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1516 if ((m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPAREWC
)) && m_bHasWC
)
1518 if ((!m_CurrentVersion
.IsEmpty()) && m_CurrentVersion
!= GIT_REV_ZERO
)
1520 popup
.AppendMenuIcon(IDGITLC_COMPAREWC
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1525 //else if (GetSelectedCount() > 1)
1527 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1529 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1530 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1535 popup
.AppendMenu(MF_SEPARATOR
);
1538 if( (!this->m_Rev1
.IsEmpty()) || (!this->m_Rev1
.IsEmpty()) )
1540 if(GetSelectedCount() == 1)
1542 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPARETWO
))
1544 popup
.AppendMenuIcon(IDGITLC_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1545 popup
.SetDefaultItem(IDGITLC_COMPARETWO
, FALSE
);
1547 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_GNUDIFF2
))
1549 popup
.AppendMenuIcon(IDGITLC_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1555 if (GetSelectedCount() > 0)
1557 if ((GetSelectedCount() == 2) && (m_dwContextMenus
& GITSLC_POPCOMPARETWOFILES
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1559 POSITION pos
= GetFirstSelectedItemPosition();
1560 int index
= GetNextSelectedItem(pos
);
1563 CTGitPath
* entry2
= NULL
;
1564 bool bothItemsAreExistingFiles
= true;
1565 entry2
= (CTGitPath
* )GetItemData(index
);
1567 bothItemsAreExistingFiles
= !entry2
->IsDirectory() && entry2
->Exists();
1568 index
= GetNextSelectedItem(pos
);
1571 entry2
= (CTGitPath
* )GetItemData(index
);
1573 bothItemsAreExistingFiles
= bothItemsAreExistingFiles
&& !entry2
->IsDirectory() && entry2
->Exists();
1574 if (bothItemsAreExistingFiles
)
1575 popup
.AppendMenuIcon(IDGITLC_COMPARETWOFILES
, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES
, IDI_DIFF
);
1579 // if (wcStatus > git_wc_status_normal)
1581 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1583 // // reverting missing folders is not possible
1584 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1586 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1590 // if (entry->remotestatus > git_wc_status_normal)
1592 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1594 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1599 if ( (GetSelectedCount() >0 ) && (!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
)) && m_bHasWC
)
1601 if ((m_dwContextMenus
& GITSLC_POPREVERT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1603 popup
.AppendMenuIcon(IDGITLC_REVERT
, IDS_MENUREVERT
, IDI_REVERT
);
1606 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())
1608 popup
.AppendMenuIcon(IDGITLC_SKIPWORKTREE
, IDS_STATUSLIST_SKIPWORKTREE
);
1611 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())
1613 popup
.AppendMenuIcon(IDGITLC_ASSUMEVALID
, IDS_MENUASSUMEVALID
);
1616 if (m_dwContextMenus
& GITSLC_POPRESTORE
&& !filepath
->IsDirectory())
1618 if (m_restorepaths
.find(filepath
->GetWinPathString()) == m_restorepaths
.end())
1619 popup
.AppendMenuIcon(IDGITLC_CREATERESTORE
, IDS_MENUCREATERESTORE
, IDI_RESTORE
);
1621 popup
.AppendMenuIcon(IDGITLC_RESTOREPATH
, IDS_MENURESTORE
, IDI_RESTORE
);
1624 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOREV
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1625 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1627 popup
.AppendMenuIcon(IDGITLC_REVERTTOREV
, IDS_LOG_POPUP_REVERTTOREV
, IDI_REVERT
);
1631 if ((GetSelectedCount() == 1)&&(!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
))
1632 &&(!(wcStatus
& CTGitPath::LOGACTIONS_IGNORE
)))
1634 if (m_dwContextMenus
& GITSLC_POPSHOWLOG
)
1636 popup
.AppendMenuIcon(IDGITLC_LOG
, IDS_REPOBROWSE_SHOWLOG
, IDI_LOG
);
1638 if (m_dwContextMenus
& GITSLC_POPSHOWLOGSUBMODULE
&& filepath
->IsDirectory())
1640 popup
.AppendMenuIcon(IDGITLC_LOGSUBMODULE
, IDS_LOG_SUBMODULE
, IDI_LOG
);
1642 if (m_dwContextMenus
& GITSLC_POPSHOWLOGOLDNAME
&& (wcStatus
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !filepath
->GetGitOldPathString().IsEmpty()))
1644 popup
.AppendMenuIcon(IDGITLC_LOGOLDNAME
, IDS_STATUSLIST_SHOWLOGOLDNAME
, IDI_LOG
);
1646 if (m_dwContextMenus
& GITSLC_POPBLAME
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
)
1648 popup
.AppendMenuIcon(IDGITLC_BLAME
, IDS_MENUBLAME
, IDI_BLAME
);
1652 if (GetSelectedCount() > 0)
1654 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_EXPORT
)) && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1655 popup
.AppendMenuIcon(IDGITLC_EXPORT
, IDS_LOG_POPUP_EXPORT
, IDI_EXPORT
);
1658 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1659 if ( (GetSelectedCount() == 1) )
1661 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_SAVEAS
) && ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1663 popup
.AppendMenuIcon(IDGITLC_SAVEAS
, IDS_LOG_POPUP_SAVE
, IDI_SAVEAS
);
1666 if (m_dwContextMenus
& GITSLC_POPOPEN
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1668 popup
.AppendMenuIcon(IDGITLC_VIEWREV
, IDS_LOG_POPUP_VIEWREV
);
1669 popup
.AppendMenuIcon(IDGITLC_OPEN
, IDS_REPOBROWSE_OPEN
, IDI_OPEN
);
1670 popup
.AppendMenuIcon(IDGITLC_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1671 if (wcStatus
&CTGitPath::LOGACTIONS_UNVER
) {
1672 popup
.SetDefaultItem(IDGITLC_OPEN
, FALSE
);
1676 if (m_dwContextMenus
& GITSLC_POPEXPLORE
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
)
1678 popup
.AppendMenuIcon(IDGITLC_EXPLORE
, IDS_STATUSLIST_CONTEXT_EXPLORE
, IDI_EXPLORER
);
1682 if (GetSelectedCount() > 0)
1684 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
1686 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1688 // 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))
1691 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
1693 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
1695 if ((wcStatus
& CTGitPath::LOGACTIONS_UNVER
)/*||(wcStatus == git_wc_status_deleted)*/)
1697 if (m_dwContextMenus
& GITSLC_POPDELETE
)
1699 popup
.AppendMenuIcon(IDGITLC_DELETE
, IDS_MENUREMOVE
, IDI_DELETE
);
1702 if ( (wcStatus
& CTGitPath::LOGACTIONS_UNVER
|| wcStatus
& CTGitPath::LOGACTIONS_DELETED
) )
1704 if (m_dwContextMenus
& GITSLC_POPIGNORE
)
1707 CTGitPathList ignorelist
;
1708 FillListOfSelectedItemPaths(ignorelist
);
1709 //check if all selected entries have the same extension
1710 bool bSameExt
= true;
1712 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
1714 if (sExt
.IsEmpty() && (i
==0))
1715 sExt
= ignorelist
[i
].GetFileExtension();
1716 else if (sExt
.CompareNoCase(ignorelist
[i
].GetFileExtension())!=0)
1721 if (ignoreSubMenu
.CreateMenu())
1724 if (ignorelist
.GetCount()==1)
1725 ignorepath
= ignorelist
[0].GetFileOrDirectoryName();
1727 ignorepath
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1728 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNORE
, ignorepath
);
1729 ignorepath
= _T("*")+sExt
;
1730 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREMASK
, ignorepath
);
1732 temp
.LoadString(IDS_MENUIGNORE
);
1733 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)ignoreSubMenu
.m_hMenu
, temp
);
1739 if (ignorelist
.GetCount()==1)
1741 temp
.LoadString(IDS_MENUIGNORE
);
1745 temp
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1747 popup
.AppendMenuIcon(IDGITLC_IGNORE
, temp
, IDI_IGNORE
);
1755 if (GetSelectedCount() > 0)
1757 popup
.AppendMenu(MF_SEPARATOR
);
1758 popup
.AppendMenuIcon(IDGITLC_COPY
, IDS_STATUSLIST_CONTEXT_COPY
, IDI_COPYCLIP
);
1759 popup
.AppendMenuIcon(IDGITLC_COPYEXT
, IDS_STATUSLIST_CONTEXT_COPYEXT
, IDI_COPYCLIP
);
1761 if ((m_dwContextMenus
& SVNSLC_POPCHANGELISTS
))
1762 &&(wcStatus
!= git_wc_status_unversioned
)&&(wcStatus
!= git_wc_status_none
))
1764 popup
.AppendMenu(MF_SEPARATOR
);
1765 // changelist commands
1766 size_t numChangelists
= GetNumberOfChangelistsInSelection();
1767 if (numChangelists
> 0)
1769 popup
.AppendMenuIcon(IDSVNLC_REMOVEFROMCS
, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS
);
1771 if ((!entry
->IsFolder())&&(changelistSubMenu
.CreateMenu()))
1774 temp
.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS
);
1775 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATECS
, temp
);
1777 if (entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
))
1779 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1780 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATEIGNORECS
, SVNSLC_IGNORECHANGELIST
);
1783 if (!m_changelists
.empty())
1785 // find the changelist names
1786 bool bNeedSeparator
= true;
1787 int cmdID
= IDSVNLC_MOVETOCS
;
1788 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
1790 if ((entry
->changelist
.Compare(it
->first
))&&(it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)))
1794 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1795 bNeedSeparator
= false;
1797 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, cmdID
, it
->first
);
1802 temp
.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS
);
1803 popup
.AppendMenu(MF_POPUP
|MF_STRING
, (UINT_PTR
)changelistSubMenu
.GetSafeHmenu(), temp
);
1809 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1812 AfxGetApp()->DoWaitCursor(1);
1813 //int iItemCountBeforeMenuCmd = GetItemCount();
1814 //bool bForce = false;
1817 case IDGITLC_VIEWREV
:
1818 OpenFile(filepath
, ALTERNATIVEEDITOR
);
1821 OpenFile(filepath
,OPEN
);
1823 case IDGITLC_OPENWITH
:
1824 OpenFile(filepath
,OPEN_WITH
);
1826 case IDGITLC_EXPLORE
:
1828 ShellExecute(this->m_hWnd
, _T("explore"), filepath
->GetDirectory().GetWinPath(), NULL
, NULL
, SW_SHOW
);
1831 case IDGITLC_CREATERESTORE
:
1833 POSITION pos
= GetFirstSelectedItemPosition();
1836 int index
= GetNextSelectedItem(pos
);
1837 CTGitPath
* entry2
= (CTGitPath
* )GetItemData(index
);
1838 ASSERT(entry2
!= NULL
);
1839 if (entry2
== NULL
|| entry2
->IsDirectory())
1841 if (m_restorepaths
.find(entry2
->GetWinPathString()) != m_restorepaths
.end())
1843 CTGitPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
1844 if (CopyFile(g_Git
.m_CurrentDir
+ _T("\\") + entry2
->GetWinPathString(), tempFile
.GetWinPath(), FALSE
))
1846 m_restorepaths
[entry2
->GetWinPathString()] = tempFile
.GetWinPathString();
1847 SetItemState(index
, INDEXTOOVERLAYMASK(OVL_RESTORE
), LVIS_OVERLAYMASK
);
1853 case IDGITLC_RESTOREPATH
:
1855 if (CMessageBox::Show(m_hWnd
, IDS_STATUSLIST_RESTOREPATH
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_RESTOREBUTTON
, IDS_ABORTBUTTON
) == 2)
1857 POSITION pos
= GetFirstSelectedItemPosition();
1860 int index
= GetNextSelectedItem(pos
);
1861 CTGitPath
* entry2
= (CTGitPath
* )GetItemData(index
);
1862 ASSERT(entry2
!= NULL
);
1865 if (m_restorepaths
.find(entry2
->GetWinPathString()) == m_restorepaths
.end())
1867 if (CopyFile(m_restorepaths
[entry2
->GetWinPathString()], g_Git
.m_CurrentDir
+ _T("\\") + entry2
->GetWinPathString(), FALSE
))
1869 m_restorepaths
.erase(entry2
->GetWinPathString());
1870 SetItemState(index
, 0, LVIS_OVERLAYMASK
);
1876 // Compare current version and work copy.
1877 case IDGITLC_COMPAREWC
:
1879 POSITION pos
= GetFirstSelectedItemPosition();
1882 int index
= GetNextSelectedItem(pos
);
1887 // Compare with base version. when current version is zero, compare workcopy and HEAD.
1888 case IDGITLC_COMPARE
:
1890 POSITION pos
= GetFirstSelectedItemPosition();
1893 int index
= GetNextSelectedItem(pos
);
1898 case IDGITLC_COMPARETWO
:
1900 POSITION pos
= GetFirstSelectedItemPosition();
1903 int index
= GetNextSelectedItem(pos
);
1904 StartDiffTwo(index
);
1908 case IDGITLC_COMPARETWOFILES
:
1910 POSITION pos
= GetFirstSelectedItemPosition();
1911 CTGitPath
* firstfilepath
= NULL
, * secondfilepath
= NULL
;
1914 firstfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
1915 ASSERT(firstfilepath
!= NULL
);
1916 if (firstfilepath
== NULL
)
1919 secondfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
1920 ASSERT(secondfilepath
!= NULL
);
1921 if (secondfilepath
== NULL
)
1925 sCmd
.Format(_T("/command:diff /path:\"%s\" /path2:\"%s\" /hwnd:%ld"), firstfilepath
->GetWinPath(), secondfilepath
->GetWinPath(), (unsigned long)m_hWnd
);
1926 CAppUtils::RunTortoiseProc(sCmd
);
1930 case IDGITLC_GNUDIFF1
:
1932 POSITION pos
= GetFirstSelectedItemPosition();
1935 CTGitPath
* selectedFilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
1936 if (m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
1940 fromwhere
= _T("~1");
1941 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, GitRev::GetHead() + fromwhere
, *selectedFilepath
, GitRev::GetWorkingCopy());
1945 if ((selectedFilepath
->m_ParentNo
& (PARENT_MASK
| MERGE_MASK
)) == 0)
1946 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, m_CurrentVersion
+ _T("~1"), *selectedFilepath
, m_CurrentVersion
);
1950 if (!(selectedFilepath
->m_ParentNo
& MERGE_MASK
))
1951 str
.Format(_T("%s^%d"), m_CurrentVersion
, (selectedFilepath
->m_ParentNo
& PARENT_MASK
) + 1);
1953 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, str
, *selectedFilepath
, m_CurrentVersion
, false, false, false, !!(selectedFilepath
->m_ParentNo
& MERGE_MASK
));
1959 case IDGITLC_GNUDIFF2
:
1961 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *filepath
, m_Rev2
, *filepath
, m_Rev1
);
1967 CTGitPathList paths
;
1968 FillListOfSelectedItemPaths(paths
, true);
1970 CGitProgressDlg progDlg
;
1971 progDlg
.SetCommand(CGitProgressDlg::GitProgress_Add
);
1972 progDlg
.SetPathList(paths
);
1973 progDlg
.SetItemCount(paths
.GetCount());
1976 // reset unchecked status
1977 POSITION pos
= GetFirstSelectedItemPosition();
1979 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1981 m_mapFilenameToChecked
.erase(((CTGitPath
*)GetItemData(index
))->GetGitPathString());
1984 if (NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
1985 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
1991 case IDGITLC_DELETE
:
1994 std::vector
<int> selectIndex
;
1996 POSITION pos
= GetFirstSelectedItemPosition();
1998 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2000 selectIndex
.push_back(index
);
2003 //Create file-list ('\0' separated) for SHFileOperation
2005 for(int i
=0;i
<selectIndex
.size();i
++)
2007 index
=selectIndex
[i
];
2009 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2014 filelist
+= path
->GetWinPathString();
2015 filelist
+= _T("|");
2017 filelist
+= _T("|");
2018 int len
= filelist
.GetLength();
2019 TCHAR
* buf
= new TCHAR
[len
+2];
2020 _tcscpy_s(buf
, len
+2, filelist
);
2021 for (int i
=0; i
<len
; ++i
)
2024 SHFILEOPSTRUCT fileop
;
2025 fileop
.hwnd
= this->m_hWnd
;
2026 fileop
.wFunc
= FO_DELETE
;
2029 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
2030 fileop
.lpszProgressTitle
= _T("deleting file");
2031 int result
= SHFileOperation(&fileop
);
2034 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
2037 POSITION pos
= NULL
;
2038 while ((pos
= GetFirstSelectedItemPosition()) != 0)
2040 int index
= GetNextSelectedItem(pos
);
2041 if (GetCheck(index
))
2045 RemoveListEntry(index
);
2054 CAppUtils::LaunchTortoiseBlame(g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath(), m_CurrentVersion
);
2059 case IDGITLC_LOGSUBMODULE
:
2062 sCmd
.Format(_T("/command:log /path:\"%s\""), g_Git
.m_CurrentDir
+ _T("\\") + filepath
->GetWinPath());
2063 if (cmd
== IDGITLC_LOG
&& filepath
->IsDirectory())
2064 sCmd
+= _T(" /submodule");
2065 CAppUtils::RunTortoiseProc(sCmd
);
2069 case IDGITLC_LOGOLDNAME
:
2071 CTGitPath
oldName(filepath
->GetGitOldPathString());
2073 sCmd
.Format(_T("/command:log /path:\"%s\""), g_Git
.m_CurrentDir
+ _T("\\") + oldName
.GetWinPath());
2074 CAppUtils::RunTortoiseProc(sCmd
);
2079 case IDGITLC_EDITCONFLICT
:
2081 if (CAppUtils::ConflictEdit(*filepath
, false, this->m_bIsRevertTheirMy
))
2083 CString conflictedFile
= g_Git
.m_CurrentDir
+ _T("\\") + filepath
->GetWinPathString();
2084 if (!PathFileExists(conflictedFile
) && NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2085 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2089 case IDGITLC_RESOLVETHEIRS
: //follow up
2090 case IDGITLC_RESOLVEMINE
: //follow up
2091 case IDGITLC_RESOLVECONFLICT
:
2093 if (CMessageBox::Show(m_hWnd
, IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
)==IDYES
)
2095 POSITION pos
= GetFirstSelectedItemPosition();
2099 index
= GetNextSelectedItem(pos
);
2100 CTGitPath
* fentry
=(CTGitPath
*) this->GetItemData(index
);
2103 CString gitcmd
,output
;
2106 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVETHEIRS
) ||
2107 ((this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVEMINE
) )
2109 gitcmd
.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry
->GetGitPathString());
2110 if (g_Git
.Run(gitcmd
, &output
,CP_UTF8
))
2112 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2117 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVEMINE
) ||
2118 ((this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVETHEIRS
) )
2120 gitcmd
.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry
->GetGitPathString());
2121 if (g_Git
.Run(gitcmd
, &output
,CP_UTF8
))
2123 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2129 if ( fentry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
2131 gitcmd
.Format(_T("git.exe add -f -- \"%s\""),fentry
->GetGitPathString());
2132 if (g_Git
.Run(gitcmd
, &output
,CP_UTF8
))
2134 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2138 fentry
->m_Action
|= CTGitPath::LOGACTIONS_MODIFIED
;
2139 fentry
->m_Action
&=~CTGitPath::LOGACTIONS_UNMERGED
;
2143 CAppUtils::RemoveTempMergeFile(*fentry
);
2146 Show(m_dwShow
, 0, m_bShowFolders
,0,true);
2151 case IDGITLC_IGNORE
:
2153 CTGitPathList ignorelist
;
2154 //std::vector<CString> toremove;
2155 FillListOfSelectedItemPaths(ignorelist
, true);
2158 if(!CAppUtils::IgnoreFile(ignorelist
,false))
2161 CWnd
* pParent
= GetLogicalParent();
2162 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2164 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2169 case IDGITLC_IGNOREMASK
:
2172 CString ext
=filepath
->GetFileExtension();
2173 CTGitPathList ignorelist
;
2174 FillListOfSelectedItemPaths(ignorelist
, true);
2177 if (!CAppUtils::IgnoreFile(ignorelist
,true))
2180 CWnd
* pParent
= GetLogicalParent();
2181 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2183 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2190 case IDGITLC_REVERT
:
2192 // If at least one item is not in the status "added"
2193 // we ask for a confirmation
2194 BOOL bConfirm
= FALSE
;
2195 POSITION pos
= GetFirstSelectedItemPosition();
2197 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2199 //FileEntry * fentry = GetListEntry(index);
2200 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
2201 if(fentry
&& fentry
->m_Action
&CTGitPath::LOGACTIONS_MODIFIED
&& !fentry
->IsDirectory())
2209 str
.Format(IDS_PROC_WARNREVERT
,GetSelectedCount());
2211 if (!bConfirm
|| CMessageBox::Show(this->m_hWnd
, str
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
2213 CTGitPathList targetList
;
2214 FillListOfSelectedItemPaths(targetList
);
2216 // make sure that the list is reverse sorted, so that
2217 // children are removed before any parents
2218 targetList
.SortByPathname(true);
2220 // put all reverted files in the trashbin, except the ones with 'added'
2221 // status because they are not restored by the revert.
2222 CTGitPathList delList
;
2223 POSITION pos
= GetFirstSelectedItemPosition();
2225 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2227 CTGitPath
*entry
=(CTGitPath
*)GetItemData(index
);
2228 if (entry
&&(!(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
))
2229 && (!(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)) && !entry
->IsDirectory())
2232 fullpath
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+entry
->GetWinPath());
2233 delList
.AddPath(fullpath
);
2236 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
2237 delList
.DeleteAllFiles(true);
2239 CString revertToCommit
= _T("HEAD");
2241 revertToCommit
= _T("HEAD~1");
2242 if (g_Git
.Revert(revertToCommit
, targetList
))
2244 CMessageBox::Show(this->m_hWnd
, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR
);
2248 bool updateStatusList
= false;
2249 for(int i
=0;i
<targetList
.GetCount();i
++)
2251 int nListboxEntries
= GetItemCount();
2252 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2254 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2255 if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && !path
->IsDirectory())
2257 if(path
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2259 path
->m_Action
= CTGitPath::LOGACTIONS_UNVER
;
2260 SetEntryCheck(path
,nItem
,false);
2261 updateStatusList
= true;
2262 SetItemGroup(nItem
,1);
2263 this->m_StatusFileList
.RemoveItem(*path
);
2264 this->m_UnRevFileList
.AddPath(*path
);
2265 //this->m_IgnoreFileList.RemoveItem(*path);
2270 RemoveListEntry(nItem
);
2274 else if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && path
->IsDirectory() && path
->IsWCRoot())
2277 sCmd
.Format(_T("/command:revert /path:\"%s\""), path
->GetGitPathString());
2278 CCommonAppUtils::RunTortoiseProc(sCmd
);
2284 Show(m_dwShow
, 0, m_bShowFolders
,updateStatusList
,true);
2291 case IDGITLC_ASSUMEVALID
:
2293 CString cmdTemplate
;
2294 cmdTemplate
= _T("git.exe update-index --assume-unchanged \"%s\"");
2295 POSITION pos
= GetFirstSelectedItemPosition();
2297 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2299 CTGitPath
* path
= (CTGitPath
*)GetItemData(index
);
2304 CString cmd
, output
;
2305 cmd
.Format(cmdTemplate
, path
->GetGitPathString());
2306 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
2308 MessageBox(output
, _T("TortoiseGit"), MB_ICONERROR
);
2311 if (NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2312 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2317 case IDGITLC_SKIPWORKTREE
:
2319 CString cmdTemplate
;
2320 cmdTemplate
= _T("git.exe update-index --skip-worktree \"%s\"");
2321 POSITION pos
= GetFirstSelectedItemPosition();
2323 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2325 CTGitPath
* path
= (CTGitPath
*)GetItemData(index
);
2330 CString cmd
, output
;
2331 cmd
.Format(cmdTemplate
, path
->GetGitPathString());
2332 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
2334 MessageBox(output
, _T("TortoiseGit"), MB_ICONERROR
);
2337 if (NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2338 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2344 CopySelectedEntriesToClipboard(0);
2346 case IDGITLC_COPYEXT
:
2347 CopySelectedEntriesToClipboard((DWORD
)-1);
2349 case IDGITLC_EXPORT
:
2352 case IDGITLC_SAVEAS
:
2353 FileSaveAs(filepath
);
2356 case IDGITLC_REVERTTOREV
:
2357 RevertSelectedItemToVersion();
2360 case IDSVNLC_COMMIT
:
2362 CTSVNPathList targetList
;
2363 FillListOfSelectedItemPaths(targetList
);
2364 CTSVNPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2365 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2366 CString commandline
= CPathUtils::GetAppDirectory();
2367 commandline
+= _T("TortoiseProc.exe /command:commit /pathfile:\"");
2368 commandline
+= tempFile
.GetWinPathString();
2369 commandline
+= _T("\"");
2370 commandline
+= _T(" /deletepathfile");
2371 CAppUtils::LaunchApplication(commandline
, NULL
, false);
2374 case IDSVNLC_CREATEIGNORECS
:
2375 CreateChangeList(SVNSLC_IGNORECHANGELIST
);
2377 case IDSVNLC_CREATECS
:
2379 CCreateChangelistDlg dlg
;
2380 if (dlg
.DoModal() == IDOK
)
2382 CreateChangeList(dlg
.m_sName
);
2388 if (cmd
< IDSVNLC_MOVETOCS
)
2390 CTSVNPathList changelistItems
;
2391 FillListOfSelectedItemPaths(changelistItems
);
2393 // find the changelist name
2394 CString sChangelist
;
2395 int cmdID
= IDSVNLC_MOVETOCS
;
2397 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
2399 if ((it
->first
.Compare(SVNSLC_IGNORECHANGELIST
))&&(entry
->changelist
.Compare(it
->first
)))
2403 sChangelist
= it
->first
;
2408 if (!sChangelist
.IsEmpty())
2411 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
2413 // The changelists were moved, but we now need to run through the selected items again
2414 // and update their changelist
2415 POSITION pos
= GetFirstSelectedItemPosition();
2417 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2419 FileEntry
* e
= GetListEntry(index
);
2420 e
->changelist
= sChangelist
;
2423 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
2424 SetItemGroup(index
, m_changelists
[e
->changelist
]);
2426 SetItemGroup(index
, 0);
2432 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
2442 AfxGetApp()->DoWaitCursor(-1);
2443 GetStatisticsString();
2444 //int iItemCountAfterMenuCmd = GetItemCount();
2445 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
2447 // CWnd* pParent = GetParent();
2448 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2450 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
2453 } // if (popup.CreatePopupMenu())
2454 } // if (selIndex >= 0)
2458 void CGitStatusListCtrl::OnContextMenuHeader(CWnd
* pWnd
, CPoint point
)
2460 Locker
lock(m_critSec
);
2461 m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
2464 void CGitStatusListCtrl::OnContextMenu(CWnd
* pWnd
, CPoint point
)
2469 OnContextMenuList(pWnd
, point
);
2470 } // if (pWnd == this)
2471 else if (pWnd
== GetHeaderCtrl())
2473 OnContextMenuHeader(pWnd
, point
);
2477 void CGitStatusListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2480 Locker
lock(m_critSec
);
2481 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
2486 if (pNMLV
->iItem
< 0)
2488 if (!IsGroupViewEnabled())
2491 DWORD ptW
= GetMessagePos();
2492 pt
.x
= GET_X_LPARAM(ptW
);
2493 pt
.y
= GET_Y_LPARAM(ptW
);
2494 ScreenToClient(&pt
);
2495 int group
= GetGroupFromPoint(&pt
);
2498 // check/uncheck the whole group depending on the check-state
2499 // of the first item in the group
2501 bool bCheck
= false;
2502 bool bFirst
= false;
2504 for (int i
=0; i
<GetItemCount(); ++i
)
2506 SecureZeroMemory(&lv
, sizeof(LVITEM
));
2507 lv
.mask
= LVIF_GROUPID
;
2510 if (lv
.iGroupId
== group
)
2512 CTGitPath
*entry
=(CTGitPath
*)GetItemData(i
);
2516 bCheck
= !GetCheck(i
);
2521 bool bOldCheck
= !!GetCheck(i
);
2522 SetEntryCheck(entry
, i
, bCheck
);
2523 if (bCheck
!= bOldCheck
)
2533 GetStatisticsString();
2539 CTGitPath
*file
=(CTGitPath
*)GetItemData(pNMLV
->iItem
);
2541 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
) {
2542 OpenFile(file
, OPEN
);
2545 if( file
->m_Action
&CTGitPath::LOGACTIONS_UNMERGED
)
2547 if (CAppUtils::ConflictEdit(*file
, false, m_bIsRevertTheirMy
))
2549 CString conflictedFile
= g_Git
.m_CurrentDir
+ _T("\\") + file
->GetWinPathString();
2550 if (!PathFileExists(conflictedFile
) && NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2551 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2556 if( (!m_Rev1
.IsEmpty()) || (!m_Rev1
.IsEmpty())) // m_Rev1 twice???
2557 StartDiffTwo(pNMLV
->iItem
);
2559 StartDiff(pNMLV
->iItem
);
2563 void CGitStatusListCtrl::StartDiffTwo(int fileindex
)
2568 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
2570 CGitDiff::Diff(&file1
,&file1
,
2575 void CGitStatusListCtrl::StartDiffWC(int fileindex
)
2581 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2584 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
2586 CGitDiff::Diff(&file1
,&file1
, GIT_REV_ZERO
, m_CurrentVersion
);
2590 void CGitStatusListCtrl::StartDiff(int fileindex
)
2595 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
2597 if(file1
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
2599 file2
.SetFromGit(file1
.GetGitOldPathString());
2606 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2609 if(m_amend
&& (file1
.m_Action
& CTGitPath::LOGACTIONS_ADDED
) == 0)
2610 fromwhere
= _T("~1");
2611 if( g_Git
.IsInitRepos())
2612 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2614 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_ADDED
)
2615 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2616 m_CurrentVersion
+fromwhere
,true);
2617 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_DELETED
)
2618 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2619 GitRev::GetHead()+fromwhere
,false);
2621 CGitDiff::Diff(&file1
,&file2
,
2622 CString(GIT_REV_ZERO
),
2623 GitRev::GetHead()+fromwhere
);
2628 CString fromwhere
= m_CurrentVersion
+_T("~1");
2630 fromwhere
= m_CurrentVersion
+_T("~2");
2631 if (rev
.GetCommit(fromwhere
) || (file1
.m_Action
& file1
.LOGACTIONS_ADDED
))
2633 CGitDiff::DiffNull(&file1
,m_CurrentVersion
,true);
2636 else if (file1
.m_Action
& file1
.LOGACTIONS_DELETED
)
2638 if (file1
.m_ParentNo
> 0)
2639 fromwhere
.Format(_T("%s^%d"), m_CurrentVersion
, file1
.m_ParentNo
+ 1);
2641 CGitDiff::DiffNull(&file1
,fromwhere
,false);
2645 if( file1
.m_ParentNo
& MERGE_MASK
)
2648 CTGitPath base
, theirs
, mine
, merge
;
2651 GetTempPath(temppath
);
2652 temppath
.TrimRight(_T("\\"));
2654 mine
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".LOCAL") + file1
.GetFileExtension());
2655 theirs
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".REMOTE") + file1
.GetFileExtension());
2656 base
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".BASE") + file1
.GetFileExtension());
2659 //create a empty file, incase stage is not three
2660 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2662 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2664 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2667 merge
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".Merged") + file1
.GetFileExtension());
2669 int parent1
=-1, parent2
=-1;
2670 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
2672 if(m_arStatusArray
[i
]->GetGitPathString() == file1
.GetGitPathString())
2674 if(m_arStatusArray
[i
]->m_ParentNo
& MERGE_MASK
)
2681 parent1
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2683 else if (parent2
<0)
2685 parent2
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2691 if(g_Git
.GetOneFile(m_CurrentVersion
, file1
, (CString
&)merge
.GetWinPathString()))
2693 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2699 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent1
+1);
2701 if(g_Git
.GetOneFile(str
, file1
, (CString
&)mine
.GetWinPathString()))
2703 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2710 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent2
+1);
2712 if(g_Git
.GetOneFile(str
, file1
, (CString
&)theirs
.GetWinPathString()))
2714 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2718 if(parent1
>=0 && parent2
>=0)
2720 CString cmd
, output
;
2721 cmd
.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion
, parent1
+1,
2722 this->m_CurrentVersion
,parent2
+1);
2724 if (g_Git
.Run(cmd
, &output
, NULL
, CP_UTF8
))
2729 if(g_Git
.GetOneFile(output
.Left(40), file1
, (CString
&)base
.GetWinPathString()))
2731 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETBASEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2735 CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
2741 if( (file1
.m_ParentNo
&PARENT_MASK
) == 0)
2747 str
.Format(_T("^%d"), (file1
.m_ParentNo
&PARENT_MASK
)+1);
2749 CGitDiff::Diff(&file1
,&file2
,
2751 m_CurrentVersion
+str
);
2757 CString
CGitStatusListCtrl::GetStatisticsString(bool simple
)
2760 CString sNormal
, sAdded
, sDeleted
, sModified
, sConflicted
, sUnversioned
, sRenamed
;
2761 WORD langID
= (WORD
)(DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
2762 TCHAR buf
[MAX_STATUS_STRING_LENGTH
];
2763 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal
, buf
, _countof(buf
), langID
);
2765 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added
, buf
, _countof(buf
), langID
);
2767 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted
, buf
, _countof(buf
), langID
);
2769 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified
, buf
, _countof(buf
), langID
);
2771 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted
, buf
, _countof(buf
), langID
);
2773 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned
, buf
, _countof(buf
), langID
);
2775 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced
, buf
, _countof(buf
), langID
);
2780 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE1
,
2781 this->m_nLineAdded
,this->m_nLineDeleted
,
2782 (LPCTSTR
)sModified
, m_nModified
,
2783 (LPCTSTR
)sAdded
, m_nAdded
,
2784 (LPCTSTR
)sDeleted
, m_nDeleted
,
2785 (LPCTSTR
)sRenamed
, m_nRenamed
2790 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE2
,
2791 this->m_nLineAdded
,this->m_nLineDeleted
,
2792 (LPCTSTR
)sNormal
, m_nNormal
,
2793 (LPCTSTR
)sUnversioned
, m_nUnversioned
,
2794 (LPCTSTR
)sModified
, m_nModified
,
2795 (LPCTSTR
)sAdded
, m_nAdded
,
2796 (LPCTSTR
)sDeleted
, m_nDeleted
,
2797 (LPCTSTR
)sConflicted
, m_nConflicted
2801 sStats
.Format(IDS_COMMITDLG_STATISTICSFORMAT
, m_nSelected
, GetItemCount());
2804 m_pStatLabel
->SetWindowText(sStats
);
2807 if (m_pSelectButton
)
2809 if (m_nSelected
== 0)
2810 m_pSelectButton
->SetCheck(BST_UNCHECKED
);
2811 else if (m_nSelected
!= GetItemCount())
2812 m_pSelectButton
->SetCheck(BST_INDETERMINATE
);
2814 m_pSelectButton
->SetCheck(BST_CHECKED
);
2817 if (m_pConfirmButton
)
2819 m_pConfirmButton
->EnableWindow(m_nSelected
>0);
2827 CString
CGitStatusListCtrl::GetCommonDirectory(bool bStrict
)
2831 // not strict means that the selected folder has priority
2832 if (!m_StatusFileList
.GetCommonDirectory().IsEmpty())
2833 return m_StatusFileList
.GetCommonDirectory().GetWinPath();
2836 CTGitPath commonBaseDirectory
;
2837 int nListItems
= GetItemCount();
2838 for (int i
=0; i
<nListItems
; ++i
)
2840 CTGitPath baseDirectory
,*p
= (CTGitPath
*)this->GetItemData(i
);
2844 baseDirectory
= p
->GetDirectory();
2846 if(commonBaseDirectory
.IsEmpty())
2848 commonBaseDirectory
= baseDirectory
;
2852 if (commonBaseDirectory
.GetWinPathString().GetLength() > baseDirectory
.GetWinPathString().GetLength())
2854 if (baseDirectory
.IsAncestorOf(commonBaseDirectory
))
2855 commonBaseDirectory
= baseDirectory
;
2859 return g_Git
.m_CurrentDir
+CString(_T("\\"))+commonBaseDirectory
.GetWinPath();
2863 void CGitStatusListCtrl::SelectAll(bool bSelect
, bool /*bIncludeNoCommits*/)
2865 CWaitCursor waitCursor
;
2866 // block here so the LVN_ITEMCHANGED messages
2871 int nListItems
= GetItemCount();
2873 m_nSelected
= nListItems
;
2877 for (int i
=0; i
<nListItems
; ++i
)
2879 //FileEntry * entry = GetListEntry(i);
2880 //ASSERT(entry != NULL);
2881 CTGitPath
*path
= (CTGitPath
*) GetItemData(i
);
2884 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
2885 SetEntryCheck(path
,i
,bSelect
);
2888 // unblock before redrawing
2891 GetStatisticsString();
2895 void CGitStatusListCtrl::Check(DWORD dwCheck
, bool check
)
2897 CWaitCursor waitCursor
;
2898 // block here so the LVN_ITEMCHANGED messages
2903 int nListItems
= GetItemCount();
2905 for (int i
= 0; i
< nListItems
; ++i
)
2907 CTGitPath
*entry
= (CTGitPath
*) GetItemData(i
);
2911 DWORD showFlags
= entry
->m_Action
;
2912 if (entry
->IsDirectory())
2913 showFlags
|= GITSLC_SHOWSUBMODULES
;
2915 showFlags
|= GITSLC_SHOWFILES
;
2917 if (check
&& (showFlags
& dwCheck
) && !GetCheck(i
) && !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
&& !(dwCheck
& GITSLC_SHOWSUBMODULES
)))
2919 SetEntryCheck(entry
, i
, true);
2922 else if (!check
&& (showFlags
& dwCheck
) && GetCheck(i
))
2924 SetEntryCheck(entry
, i
, false);
2928 // unblock before redrawing
2931 GetStatisticsString();
2935 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2937 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
2942 CTGitPath
*entry
=(CTGitPath
*)GetItemData(pGetInfoTip
->iItem
);
2945 if (pGetInfoTip
->cchTextMax
> entry
->GetGitPathString().GetLength() + g_Git
.m_CurrentDir
.GetLength())
2948 str
+= g_Git
.m_CurrentDir
;
2950 str
+= entry
->GetWinPathString();
2952 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, str
.GetBuffer(), str
.GetLength());
2956 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2958 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
2960 // Take the default processing unless we set this to something else below.
2961 *pResult
= CDRF_DODEFAULT
;
2963 // First thing - check the draw stage. If it's the control's prepaint
2964 // stage, then tell Windows we want messages for every item.
2966 switch (pLVCD
->nmcd
.dwDrawStage
)
2969 *pResult
= CDRF_NOTIFYITEMDRAW
;
2971 case CDDS_ITEMPREPAINT
:
2973 // This is the prepaint stage for an item. Here's where we set the
2974 // item's text color. Our return value will tell Windows to draw the
2975 // item itself, but it will use the new color we set here.
2977 // Tell Windows to paint the control itself.
2978 *pResult
= CDRF_DODEFAULT
;
2982 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
2984 if (m_arStatusArray
.size() > (DWORD_PTR
)pLVCD
->nmcd
.dwItemSpec
)
2987 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
2988 CTGitPath
*entry
=(CTGitPath
*)GetItemData((int)pLVCD
->nmcd
.dwItemSpec
);
2994 // black : unversioned, normal
2997 // brown : missing, deleted, replaced
2998 // green : merged (or potential merges)
2999 // red : conflicts or sure conflicts
3000 if(entry
->m_Action
& CTGitPath::LOGACTIONS_GRAY
)
3002 crText
= RGB(128,128,128);
3005 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
3007 crText
= m_Colors
.GetColor(CColors::Conflict
);
3010 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_MODIFIED
))
3012 crText
= m_Colors
.GetColor(CColors::Modified
);
3015 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
3017 crText
= m_Colors
.GetColor(CColors::Added
);
3019 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3021 crText
= m_Colors
.GetColor(CColors::DeletedNode
);
3023 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
3025 crText
= m_Colors
.GetColor(CColors::RenamedNode
);
3027 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_MERGED
)
3029 crText
= m_Colors
.GetColor(CColors::Merged
);
3033 crText
= GetSysColor(COLOR_WINDOWTEXT
);
3035 // Store the color back in the NMLVCUSTOMDRAW struct.
3036 pLVCD
->clrText
= crText
;
3043 BOOL
CGitStatusListCtrl::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
3046 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3049 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
3051 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3053 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_WAIT
));
3058 void CGitStatusListCtrl::RemoveListEntry(int index
)
3061 Locker
lock(m_critSec
);
3064 m_arStatusArray
.erase(m_arStatusArray
.begin()+index
);
3067 delete m_arStatusArray
[m_arListArray
[index
]];
3068 m_arStatusArray
.erase(m_arStatusArray
.begin()+m_arListArray
[index
]);
3069 m_arListArray
.erase(m_arListArray
.begin()+index
);
3070 for (int i
=index
; i
< (int)m_arListArray
.size(); ++i
)
3077 ///< Set a checkbox on an entry in the listbox
3078 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
3079 void CGitStatusListCtrl::SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
)
3081 pEntry
->m_Checked
= bCheck
;
3082 m_mapFilenameToChecked
[pEntry
->GetGitPathString()] = bCheck
;
3083 SetCheck(listboxIndex
, bCheck
);
3087 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry
* parentEntry
, bool bCheck
)
3090 int nListItems
= GetItemCount();
3091 for (int j
=0; j
< nListItems
; ++j
)
3093 FileEntry
* childEntry
= GetListEntry(j
);
3094 ASSERT(childEntry
!= NULL
);
3095 if (childEntry
== NULL
|| childEntry
== parentEntry
)
3097 if (childEntry
->checked
!= bCheck
)
3099 if (parentEntry
->path
.IsAncestorOf(childEntry
->path
))
3101 SetEntryCheck(childEntry
,j
,bCheck
);
3117 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList
& pathList
)
3121 int nListItems
= GetItemCount();
3122 for (int i
=0; i
< nListItems
; i
++)
3124 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
3125 ASSERT(entry
!= NULL
);
3126 if (entry
->m_Checked
)
3128 pathList
.AddPath(*entry
);
3131 pathList
.SortByPathname();
3136 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
3137 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool /*bNoIgnored*/)
3141 POSITION pos
= GetFirstSelectedItemPosition();
3143 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3145 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
3146 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
3148 pathList
.AddPath(*entry
);
3152 UINT
CGitStatusListCtrl::OnGetDlgCode()
3154 // we want to process the return key and not have that one
3155 // routed to the default pushbutton
3156 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS
;
3159 void CGitStatusListCtrl::OnNMReturn(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
3164 POSITION pos
= GetFirstSelectedItemPosition();
3167 int index
= GetNextSelectedItem(pos
);
3168 CTGitPath
*file
=(CTGitPath
*)GetItemData(index
);
3169 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
)
3171 OpenFile(file
, OPEN
);
3180 void CGitStatusListCtrl::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
3182 // Since we catch all keystrokes (to have the enter key processed here instead
3183 // of routed to the default pushbutton) we have to make sure that other
3184 // keys like Tab and Esc still do what they're supposed to do
3185 // Tab = change focus to next/previous control
3186 // Esc = quit the dialog
3191 ::PostMessage(GetLogicalParent()->GetSafeHwnd(), WM_NEXTDLGCTL
, GetKeyState(VK_SHIFT
)&0x8000, 0);
3197 ::SendMessage(GetLogicalParent()->GetSafeHwnd(), WM_CLOSE
, 0, 0);
3202 CListCtrl::OnKeyDown(nChar
, nRepCnt
, nFlags
);
3205 void CGitStatusListCtrl::PreSubclassWindow()
3207 CListCtrl::PreSubclassWindow();
3208 EnableToolTips(TRUE
);
3209 SetWindowTheme(GetSafeHwnd(), L
"Explorer", NULL
);
3212 INT_PTR
CGitStatusListCtrl::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
3216 row
= CellRectFromPoint(point
, &cellrect
, &col
);
3223 pTI
->uId
= (UINT
)((row
<<10)+(col
&0x3ff)+1);
3224 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
3226 pTI
->rect
= cellrect
;
3231 int CGitStatusListCtrl::CellRectFromPoint(CPoint
& point
, RECT
*cellrect
, int *col
) const
3235 // Make sure that the ListView is in LVS_REPORT
3236 if ((GetWindowLong(m_hWnd
, GWL_STYLE
) & LVS_TYPEMASK
) != LVS_REPORT
)
3239 // Get the top and bottom row visible
3240 int row
= GetTopIndex();
3241 int bottom
= row
+ GetCountPerPage();
3242 if (bottom
> GetItemCount())
3243 bottom
= GetItemCount();
3245 // Get the number of columns
3246 CHeaderCtrl
* pHeader
= (CHeaderCtrl
*)GetDlgItem(0);
3247 int nColumnCount
= pHeader
->GetItemCount();
3249 // Loop through the visible rows
3250 for ( ;row
<=bottom
;row
++)
3252 // Get bounding rect of item and check whether point falls in it.
3254 GetItemRect(row
, &rect
, LVIR_BOUNDS
);
3255 if (rect
.PtInRect(point
))
3257 // Now find the column
3258 for (colnum
= 0; colnum
< nColumnCount
; colnum
++)
3260 int colwidth
= GetColumnWidth(colnum
);
3261 if (point
.x
>= rect
.left
&& point
.x
<= (rect
.left
+ colwidth
))
3264 GetClientRect(&rectClient
);
3267 rect
.right
= rect
.left
+ colwidth
;
3269 // Make sure that the right extent does not exceed
3271 if (rect
.right
> rectClient
.right
)
3272 rect
.right
= rectClient
.right
;
3276 rect
.left
+= colwidth
;
3283 void CGitStatusListCtrl::OnPaint()
3286 if ((m_bBusy
)||(m_bEmpty
))
3291 if (m_sBusy
.IsEmpty())
3292 str
.LoadString(IDS_STATUSLIST_BUSYMSG
);
3298 if (m_sEmpty
.IsEmpty())
3299 str
.LoadString(IDS_STATUSLIST_EMPTYMSG
);
3303 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
3305 if (IsWindowEnabled())
3306 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
3308 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
3313 pHC
= GetHeaderCtrl();
3317 pHC
->GetItemRect(0, &rcH
);
3318 rc
.top
+= rcH
.bottom
;
3322 CMyMemDC
memDC(pDC
, &rc
);
3324 memDC
.SetTextColor(clrText
);
3325 memDC
.SetBkColor(clrTextBk
);
3326 memDC
.FillSolidRect(rc
, clrTextBk
);
3328 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
3329 memDC
.DrawText(str
, rc
, DT_CENTER
| DT_VCENTER
|
3330 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
3331 memDC
.SelectObject(oldfont
);
3337 // prevent users from extending our hidden (size 0) columns
3338 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3340 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3343 // prevent any function from extending our hidden (size 0) columns
3344 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3346 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3350 void CGitStatusListCtrl::OnDestroy()
3352 SaveColumnWidths(true);
3353 CListCtrl::OnDestroy();
3356 void CGitStatusListCtrl::OnBeginDrag(NMHDR
* /*pNMHDR*/, LRESULT
* pResult
)
3359 Locker
lock(m_critSec
);
3360 CDropFiles dropFiles
; // class for creating DROPFILES struct
3363 POSITION pos
= GetFirstSelectedItemPosition();
3364 while ( (index
= GetNextSelectedItem(pos
)) >= 0 )
3366 FileEntry
* fentry
= m_arStatusArray
[m_arListArray
[index
]];
3367 CTGitPath path
= fentry
->GetPath();
3368 dropFiles
.AddFile( path
.GetWinPathString() );
3371 if ( dropFiles
.GetCount()>0 )
3374 dropFiles
.CreateStructure();
3381 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry
/* = false */)
3383 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
3384 for (int col
= 0; col
<= maxcol
; col
++)
3385 if (m_ColumnManager
.IsVisible (col
))
3386 m_ColumnManager
.ColumnResized (col
);
3388 if (bSaveToRegistry
)
3389 m_ColumnManager
.WriteSettings();
3392 bool CGitStatusListCtrl::EnableFileDrop()
3394 m_bFileDropsEnabled
= true;
3398 bool CGitStatusListCtrl::HasPath(const CTGitPath
& path
)
3400 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
3402 if (m_arStatusArray
[i
]->IsEquivalentTo(path
))
3409 BOOL
CGitStatusListCtrl::PreTranslateMessage(MSG
* pMsg
)
3411 if (pMsg
->message
== WM_KEYDOWN
)
3413 switch (pMsg
->wParam
)
3417 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3419 // select all entries
3420 for (int i
=0; i
<GetItemCount(); ++i
)
3422 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3431 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3433 // copy all selected paths to the clipboard
3434 if (GetAsyncKeyState(VK_SHIFT
)&0x8000)
3435 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS
);
3437 CopySelectedEntriesToClipboard(0);
3445 return CListCtrl::PreTranslateMessage(pMsg
);
3448 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols
)
3451 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
3452 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3457 if (GetSelectedCount() == 0)
3460 // first add the column titles as the first line
3461 // We needn't head when only path copy
3462 //temp.LoadString(IDS_STATUSLIST_COLFILE);
3463 //sClipboard = temp;
3465 DWORD selection
= 0;
3466 for (int i
= 0, count
= m_ColumnManager
.GetColumnCount(); i
< count
; ++i
)
3467 if ( ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
3468 || ((dwCols
!= 1) && (i
< 32) && ((dwCols
& (1 << i
)) != 0)))
3470 sClipboard
+= _T("\t") + m_ColumnManager
.GetName(i
);
3473 selection
+= 1 << i
;
3477 sClipboard
+= _T("\r\n");
3479 POSITION pos
= GetFirstSelectedItemPosition();
3481 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3483 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
3487 sClipboard
+= entry
->GetWinPathString();
3488 if (selection
& GITSLC_COLFILENAME
)
3490 sClipboard
+= _T("\t")+entry
->GetFileOrDirectoryName();
3492 if (selection
& GITSLC_COLEXT
)
3494 sClipboard
+= _T("\t")+entry
->GetFileExtension();
3497 if (selection
& GITSLC_COLSTATUS
)
3499 sClipboard
+= _T("\t")+entry
->GetActionName();
3502 if (selection
& SVNSLC_COLDATE
)
3504 TCHAR datebuf
[SVN_DATE_BUFFER
];
3505 apr_time_t date
= entry
->last_commit_date
;
3506 SVN::formatDate(datebuf
, date
, true);
3511 sClipboard
+= _T("\t")+temp
;
3513 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
3517 if ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
3520 = entry
->present_props
[m_ColumnManager
.GetName(i
)];
3521 sClipboard
+= _T("\t") + value
;
3525 if (selection
& GITSLC_COLADD
)
3527 sClipboard
+= _T("\t")+entry
->m_StatAdd
;
3529 if (selection
& GITSLC_COLDEL
)
3531 sClipboard
+= _T("\t")+entry
->m_StatDel
;
3534 sClipboard
+= _T("\r\n");
3537 return CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
3543 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
3546 std::set
<CString
> changelists
;
3547 POSITION pos
= GetFirstSelectedItemPosition();
3549 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3551 FileEntry
* entry
= GetListEntry(index
);
3552 if (!entry
->changelist
.IsEmpty())
3553 changelists
.insert(entry
->changelist
);
3555 return changelists
.size();
3560 bool CGitStatusListCtrl::PrepareGroups(bool bForce
/* = false */)
3563 bool bHasGroups
=false;
3566 for(int i
=0;i
< this->m_arStatusArray
.size(); i
++)
3568 int ParentNo
= m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3570 max
=m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3573 if ( this->m_UnRevFileList
.GetCount()>0 ||
3574 this->m_IgnoreFileList
.GetCount()>0 ||
3581 EnableGroupView(bHasGroups
);
3583 TCHAR groupname
[1024];
3589 grp
.cbSize
= sizeof(LVGROUP
);
3590 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3593 //if(m_UnRevFileList.GetCount()>0)
3596 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MERGEDFILES
)), 1023);
3597 grp
.pszHeader
= groupname
;
3598 grp
.iGroupId
= MERGE_MASK
;
3599 grp
.uAlign
= LVGA_HEADER_LEFT
;
3600 InsertGroup(0, &grp
);
3602 for(int i
=0;i
<=max
;i
++)
3605 str
.Format(IDS_STATUSLIST_GROUP_DIFFWITHPARENT
, i
+1);
3606 grp
.pszHeader
= str
.GetBuffer();
3607 str
.ReleaseBuffer();
3609 grp
.uAlign
= LVGA_HEADER_LEFT
;
3610 InsertGroup(i
+1, &grp
);
3615 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MODIFIEDFILES
)), 1023);
3616 grp
.pszHeader
= groupname
;
3617 grp
.iGroupId
= groupindex
;
3618 grp
.uAlign
= LVGA_HEADER_LEFT
;
3619 InsertGroup(groupindex
++, &grp
);
3623 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_NOTVERSIONEDFILES
)), 1023);
3624 grp
.pszHeader
= groupname
;
3625 grp
.iGroupId
= groupindex
;
3626 grp
.uAlign
= LVGA_HEADER_LEFT
;
3627 InsertGroup(groupindex
++, &grp
);
3630 //if(m_IgnoreFileList.GetCount()>0)
3632 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNOREDFILES
)), 1023);
3633 grp
.pszHeader
= groupname
;
3634 grp
.iGroupId
= groupindex
;
3635 grp
.uAlign
= LVGA_HEADER_LEFT
;
3636 InsertGroup(groupindex
++, &grp
);
3642 m_bHasIgnoreGroup
= false;
3644 // now add the items which don't belong to a group
3646 grp
.cbSize
= sizeof(LVGROUP
);
3647 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3648 CString
sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET
));
3649 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
3650 grp
.pszHeader
= groupname
;
3651 grp
.iGroupId
= groupindex
;
3652 grp
.uAlign
= LVGA_HEADER_LEFT
;
3653 InsertGroup(groupindex
++, &grp
);
3655 for (std::map
<CString
,int>::iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
3657 if (it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)!=0)
3660 grp
.cbSize
= sizeof(LVGROUP
);
3661 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3662 _tcsncpy_s(groupname
, 1024, it
->first
, 1023);
3663 grp
.pszHeader
= groupname
;
3664 grp
.iGroupId
= groupindex
;
3665 grp
.uAlign
= LVGA_HEADER_LEFT
;
3666 it
->second
= InsertGroup(groupindex
++, &grp
);
3669 m_bHasIgnoreGroup
= true;
3672 if (m_bHasIgnoreGroup
)
3674 // and now add the group 'ignore-on-commit'
3675 std::map
<CString
,int>::iterator it
= m_changelists
.find(SVNSLC_IGNORECHANGELIST
);
3676 if (it
!= m_changelists
.end())
3678 grp
.cbSize
= sizeof(LVGROUP
);
3679 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3680 _tcsncpy_s(groupname
, 1024, SVNSLC_IGNORECHANGELIST
, 1023);
3681 grp
.pszHeader
= groupname
;
3682 grp
.iGroupId
= groupindex
;
3683 grp
.uAlign
= LVGA_HEADER_LEFT
;
3684 it
->second
= InsertGroup(groupindex
, &grp
);
3691 void CGitStatusListCtrl::NotifyCheck()
3693 CWnd
* pParent
= GetLogicalParent();
3694 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3696 pParent
->SendMessage(GITSLNM_CHECKCHANGED
, m_nSelected
);
3700 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash
,CTGitPathList
*list
)
3704 m_CurrentVersion
=hash
;
3710 count
= list
->GetCount();
3712 CString head
= _T("HEAD");
3714 head
= _T("HEAD~1");
3716 if(hash
== GIT_REV_ZERO
)
3718 for(int i
=0;i
<count
;i
++)
3723 if(!g_Git
.IsInitRepos())
3725 // also list staged files which will be in the commit
3726 cmd
=(_T("git.exe diff-index --cached --raw ") + head
+ _T(" --numstat -C -M -z"));
3727 g_Git
.Run(cmd
, &cmdout
);
3730 cmd
=(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z"));
3732 cmd
.Format(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z -- \"%s\""),(*list
)[i
].GetGitPathString());
3735 if(g_Git
.Run(cmd
, &cmdout
, &cmdErr
))
3737 int last
= cmdErr
.RevertFind(0,-1);
3739 g_Git
.StringAppend(&str
, &cmdErr
[last
+ 1], CP_UTF8
, (int)cmdErr
.size() - last
-1);
3740 CMessageBox::Show(NULL
, str
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
3743 out
.append(cmdout
, 0);
3745 else // Init Repository
3747 //We will list all added file for init repository because commit will comit these
3749 cmd
=_T("git.exe ls-files -s -t -z");
3751 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
3753 g_Git
.Run(cmd
, &cmdout
);
3755 out
.append(cmdout
,0);
3759 if(g_Git
.IsInitRepos())
3761 m_StatusFileList
.ParserFromLsFile(out
);
3762 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
3763 ((CTGitPath
&)(m_StatusFileList
[i
])).m_Action
=CTGitPath::LOGACTIONS_ADDED
;
3766 this->m_StatusFileList
.ParserFromLog(out
);
3768 //handle delete conflict case, when remote : modified, local : deleted.
3769 for(int i
=0;i
<count
;i
++)
3775 cmd
=_T("git.exe ls-files -u -t -z");
3777 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list
)[i
].GetGitPathString());
3779 g_Git
.Run(cmd
, &cmdout
);
3781 CTGitPathList conflictlist
;
3782 conflictlist
.ParserFromLog(cmdout
);
3783 for(int i
=0;i
<conflictlist
.GetCount();i
++)
3785 CTGitPath
*p
=m_StatusFileList
.LookForGitPath(conflictlist
[i
].GetGitPathString());
3787 p
->m_Action
|=CTGitPath::LOGACTIONS_UNMERGED
;
3789 m_StatusFileList
.AddPath(conflictlist
[i
]);
3793 // handle source files of file renames/moves (issue #860)
3794 // if a file gets renamed and the new file "git add"ed, diff-index doesn't list the source file anymore
3795 for(int i
= 0; i
< count
; i
++)
3801 cmd
= _T("git.exe ls-files -d -z");
3803 cmd
.Format(_T("git.exe ls-files -d -z -- \"%s\""),(*list
)[i
].GetGitPathString());
3805 g_Git
.Run(cmd
, &cmdout
);
3807 CTGitPathList deletelist
;
3808 deletelist
.ParserFromLog(cmdout
, true);
3809 for(int i
= 0; i
< deletelist
.GetCount(); i
++)
3811 CTGitPath
*p
= m_StatusFileList
.LookForGitPath(deletelist
[i
].GetGitPathString());
3813 m_StatusFileList
.AddPath(deletelist
[i
]);
3814 else if ((p
->m_Action
== CTGitPath::LOGACTIONS_ADDED
|| p
->m_Action
== CTGitPath::LOGACTIONS_REPLACED
) && !p
->Exists())
3816 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)
3818 g_Git
.Run(_T("git.exe rm -f --cache -- \"") + p
->GetWinPathString() + _T("\""), &cmdout
);
3819 m_StatusFileList
.RemoveItem(*p
);
3831 count
= list
->GetCount();
3833 for(int i
=0;i
<count
;i
++)
3838 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash
);
3840 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash
,(*list
)[i
].GetGitPathString());
3842 g_Git
.Run(cmd
, &cmdout
, NULL
);
3846 this->m_StatusFileList
.ParserFromLog(out
);
3850 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
3852 CTGitPath
* gitpatch
=(CTGitPath
*)&m_StatusFileList
[i
];
3853 gitpatch
->m_Checked
= TRUE
;
3854 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
3857 this->m_bBusy
=FALSE
;
3861 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList
&list
)
3863 m_arStatusArray
.clear();
3864 for(int i
=0;i
<list
.GetCount();i
++)
3866 CTGitPath
* gitpath
=(CTGitPath
*)&list
[i
];
3868 if(gitpath
->m_Action
& CTGitPath::LOGACTIONS_HIDE
)
3871 gitpath
->m_Checked
= TRUE
;
3872 m_arStatusArray
.push_back((CTGitPath
*)&list
[i
]);
3877 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
&list
)
3879 m_UnRevFileList
= list
;
3880 for(int i
=0;i
<m_UnRevFileList
.GetCount();i
++)
3882 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
3883 gitpatch
->m_Checked
= FALSE
;
3884 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
3889 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
*List
)
3891 this->m_UnRevFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
,List
);
3892 for(int i
=0;i
<m_UnRevFileList
.GetCount();i
++)
3894 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
3895 gitpatch
->m_Checked
= FALSE
;
3896 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
3901 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList
*List
)
3903 this->m_IgnoreFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
|CTGitPath::LOGACTIONS_IGNORE
,List
);
3904 for(int i
=0;i
<m_IgnoreFileList
.GetCount();i
++)
3906 CTGitPath
* gitpatch
=(CTGitPath
*)&m_IgnoreFileList
[i
];
3907 gitpatch
->m_Checked
= FALSE
;
3908 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
3912 int CGitStatusListCtrl::UpdateFileList(int mask
,bool once
,CTGitPathList
*List
)
3914 if(mask
&CGitStatusListCtrl::FILELIST_MODIFY
)
3916 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_MODIFY
)))
3918 UpdateFileList(git_revnum_t(GIT_REV_ZERO
),List
);
3919 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_MODIFY
;
3922 if(mask
&CGitStatusListCtrl::FILELIST_UNVER
)
3924 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_UNVER
)))
3926 UpdateUnRevFileList(List
);
3927 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
3929 if(mask
&CGitStatusListCtrl::FILELIST_IGNORE
&& (once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_IGNORE
))))
3931 UpdateIgnoreFileList(List
);
3932 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
3938 void CGitStatusListCtrl::Clear()
3941 this->DeleteAllItems();
3942 this->m_arListArray
.clear();
3943 this->m_arStatusArray
.clear();
3944 this->m_changelists
.clear();
3946 //////////////////////////////////////////////////////////////////////////
3948 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
)
3950 if(pFmtEtc
->cfFormat
== CF_HDROP
&& medium
.tymed
== TYMED_HGLOBAL
)
3952 HDROP hDrop
= (HDROP
)GlobalLock(medium
.hGlobal
);
3955 TCHAR szFileName
[MAX_PATH
];
3957 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, NULL
, 0);
3960 clientpoint
.x
= pt
.x
;
3961 clientpoint
.y
= pt
.y
;
3962 ScreenToClient(m_hTargetWnd
, &clientpoint
);
3963 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
3965 CTSVNPathList changelistItems
;
3966 for(UINT i
= 0; i
< cFiles
; ++i
)
3968 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
3969 changelistItems
.AddPath(CTSVNPath(szFileName
));
3971 // find the changelist name
3972 CString sChangelist
;
3973 LONG_PTR nGroup
= m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
);
3974 for (std::map
<CString
, int>::iterator it
= m_pSVNStatusListCtrl
->m_changelists
.begin(); it
!= m_pSVNStatusListCtrl
->m_changelists
.end(); ++it
)
3975 if (it
->second
== nGroup
)
3976 sChangelist
= it
->first
;
3977 if (!sChangelist
.IsEmpty())
3980 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
3982 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
3984 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
3987 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
3990 e
->changelist
= sChangelist
;
3993 if (m_pSVNStatusListCtrl
->m_changelists
.find(e
->changelist
)!=m_pSVNStatusListCtrl
->m_changelists
.end())
3994 m_pSVNStatusListCtrl
->SetItemGroup(index
, m_pSVNStatusListCtrl
->m_changelists
[e
->changelist
]);
3996 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
4002 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4003 if (hParentWnd
!= NULL
)
4004 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
4010 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
4016 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
4018 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
4020 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
4023 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
4026 e
->changelist
= sChangelist
;
4027 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
4032 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4033 if (hParentWnd
!= NULL
)
4034 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
4040 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
4046 for(UINT i
= 0; i
< cFiles
; ++i
)
4048 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
4049 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4050 if (hParentWnd
!= NULL
)
4051 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)szFileName
);
4055 GlobalUnlock(medium
.hGlobal
);
4057 return true; //let base free the medium
4059 HRESULT STDMETHODCALLTYPE
CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
)
4061 CIDropTarget::DragOver(grfKeyState
, pt
, pdwEffect
);
4062 *pdwEffect
= DROPEFFECT_COPY
;
4063 if (m_pSVNStatusListCtrl
)
4066 clientpoint
.x
= pt
.x
;
4067 clientpoint
.y
= pt
.y
;
4068 ScreenToClient(m_hTargetWnd
, &clientpoint
);
4069 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
4071 *pdwEffect
= DROPEFFECT_MOVE
;
4073 else if ((!m_pSVNStatusListCtrl
->m_bFileDropsEnabled
)||(m_pSVNStatusListCtrl
->m_bOwnDrag
))
4075 *pdwEffect
= DROPEFFECT_NONE
;
4083 void CGitStatusListCtrl::FilesExport()
4086 // export all changed files to a folder
4087 CBrowseFolder browseFolder
;
4088 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
4089 if (browseFolder
.Show(GetSafeHwnd(), exportDir
) != CBrowseFolder::OK
)
4092 POSITION pos
= GetFirstSelectedItemPosition();
4094 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4096 CTGitPath
*fd
= (CTGitPath
*)GetItemData(index
);
4097 // we cannot export directories or folders
4098 if (fd
->m_Action
== CTGitPath::LOGACTIONS_DELETED
|| fd
->IsDirectory())
4101 CAppUtils::CreateMultipleDirectory(exportDir
+ _T("\\") + fd
->GetDirectory().GetWinPathString());
4102 CString filename
= exportDir
+ _T("\\") + fd
->GetWinPathString();
4103 if (m_CurrentVersion
== GIT_REV_ZERO
)
4105 if (!CopyFile(g_Git
.m_CurrentDir
+ _T("\\") + fd
->GetWinPath(), filename
, false))
4107 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
4113 if (g_Git
.GetOneFile(m_CurrentVersion
, *fd
, filename
))
4116 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, fd
->GetGitPathString(), m_CurrentVersion
, filename
);
4117 if (CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), 2, IDI_WARNING
, CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
4124 void CGitStatusListCtrl::FileSaveAs(CTGitPath
*path
)
4127 filename
.Format(_T("%s-%s%s"), path
->GetBaseFilename(), this->m_CurrentVersion
.Left(g_Git
.GetShortHASHLength()), path
->GetFileExtension());
4128 CFileDialog
dlg(FALSE
,NULL
,
4130 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
4132 CString currentpath
;
4133 currentpath
=g_Git
.m_CurrentDir
+_T("\\");
4134 currentpath
+=path
->GetWinPathString();
4136 dlg
.m_ofn
.lpstrInitialDir
=currentpath
.GetBuffer();
4139 INT_PTR ret
= dlg
.DoModal();
4140 SetCurrentDirectory(g_Git
.m_CurrentDir
);
4143 filename
= dlg
.GetPathName();
4144 if(m_CurrentVersion
== GIT_REV_ZERO
)
4146 if(!CopyFile(g_Git
.m_CurrentDir
+_T("\\") + path
->GetWinPath(),filename
,false))
4148 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
4155 if(g_Git
.GetOneFile(m_CurrentVersion
,*path
,filename
))
4157 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, path
->GetGitPathString(), m_CurrentVersion
, filename
);
4158 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
4166 int CGitStatusListCtrl::RevertSelectedItemToVersion()
4168 if(this->m_CurrentVersion
.IsEmpty())
4170 if(this->m_CurrentVersion
== GIT_REV_ZERO
)
4173 POSITION pos
= GetFirstSelectedItemPosition();
4177 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4179 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
4180 cmd
.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion
,fentry
->GetGitPathString());
4182 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
4184 if (MessageBox(out
, _T("TortoiseGit"), MB_ICONEXCLAMATION
| MB_OKCANCEL
) == IDCANCEL
)
4191 out
.Format(IDS_STATUSLIST_FILESREVERTED
, count
, m_CurrentVersion
);
4192 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
4196 void CGitStatusListCtrl::OpenFile(CTGitPath
*filepath
,int mode
)
4199 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
4201 file
= g_Git
.m_CurrentDir
+ _T("\\") + filepath
->GetWinPath();
4206 GetTempPath(temppath
);
4207 TCHAR szTempName
[MAX_PATH
];
4208 GetTempFileName(temppath
, filepath
->GetBaseFilename(), 0, szTempName
);
4209 CString
temp(szTempName
);
4210 DeleteFile(szTempName
);
4211 CreateDirectory(szTempName
, NULL
);
4212 file
.Format(_T("%s\\%s_%s%s"),
4214 filepath
->GetBaseFilename(),
4215 m_CurrentVersion
.Left(g_Git
.GetShortHASHLength()),
4216 filepath
->GetFileExtension());
4218 if(g_Git
.GetOneFile(m_CurrentVersion
, *filepath
, file
))
4220 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, filepath
->GetGitPathString(), m_CurrentVersion
, file
);
4221 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
4224 SetFileAttributes(file
, FILE_ATTRIBUTE_READONLY
);
4226 if(mode
== ALTERNATIVEEDITOR
)
4228 CAppUtils::LaunchAlternativeEditor(file
);
4231 int ret
= HINSTANCE_ERROR
;
4235 ret
= (int)ShellExecute(this->m_hWnd
, NULL
,file
, NULL
, NULL
, SW_SHOW
);
4237 if (ret
> HINSTANCE_ERROR
)
4244 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
4246 CAppUtils::LaunchApplication(cmd
, NULL
, false);