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 "SVNProgressDlg.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 "MassiveGitTask.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)
131 m_bIsRevertTheirMy
= false;
132 this->m_nLineAdded
=this->m_nLineDeleted
=0;
135 CGitStatusListCtrl::~CGitStatusListCtrl()
137 // if (m_pDropTarget)
138 // delete m_pDropTarget;
142 void CGitStatusListCtrl::ClearStatusArray()
145 Locker
lock(m_critSec
);
146 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
148 delete m_arStatusArray
[i
];
150 m_arStatusArray
.clear();
154 void CGitStatusListCtrl::Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
/* = GitSLC_POPALL */, bool bHasCheckboxes
/* = true */, bool bHasWC
/* = true */, DWORD allowedColumns
/* = 0xffffffff */)
156 Locker
lock(m_critSec
);
158 m_dwDefaultColumns
= dwColumns
| 1;
159 m_dwContextMenus
= dwContextMenus
;
160 m_bHasCheckboxes
= bHasCheckboxes
;
163 // set the extended style of the listcontrol
164 // 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.
165 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
166 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
167 if (DWORD(regFullRowSelect
))
168 exStyle
|= LVS_EX_FULLROWSELECT
;
169 exStyle
|= (bHasCheckboxes
? LVS_EX_CHECKBOXES
: 0);
171 SetExtendedStyle(exStyle
);
173 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
175 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
176 m_nRestoreOvl
= SYS_IMAGE_LIST().AddIcon((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_RESTOREOVL
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
));
177 SYS_IMAGE_LIST().SetOverlayImage(m_nRestoreOvl
, OVL_RESTORE
);
178 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
180 // keep CSorter::operator() in sync!!
181 static UINT standardColumnNames
[GITSLC_NUMCOLUMNS
]
182 = { IDS_STATUSLIST_COLFILE
183 , IDS_STATUSLIST_COLFILENAME
184 , IDS_STATUSLIST_COLEXT
185 , IDS_STATUSLIST_COLSTATUS
186 , IDS_STATUSLIST_COLADD
187 , IDS_STATUSLIST_COLDEL
188 , IDS_STATUSLIST_COLLASTMODIFIED
189 , IDS_STATUSLIST_COLSIZE
192 m_ColumnManager
.SetNames(standardColumnNames
,GITSLC_NUMCOLUMNS
);
193 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, 0xffffffff & ~(allowedColumns
| m_dwDefaultColumns
), sColumnInfoContainer
, GITSLC_NUMCOLUMNS
);
197 if (m_pDropTarget
== NULL
)
199 m_pDropTarget
= new CGitStatusListCtrlDropTarget(this);
200 RegisterDragDrop(m_hWnd
,m_pDropTarget
);
201 // create the supported formats:
203 ftetc
.dwAspect
= DVASPECT_CONTENT
;
205 ftetc
.tymed
= TYMED_HGLOBAL
;
206 ftetc
.cfFormat
=CF_HDROP
;
207 m_pDropTarget
->AddSuportedFormat(ftetc
);
214 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID
)
216 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
219 BOOL
CGitStatusListCtrl::GetStatus ( const CTGitPathList
* pathList
220 , bool bUpdate
/* = FALSE */
221 , bool bShowIgnores
/* = false */
224 Locker
lock(m_critSec
);
225 int mask
= CGitStatusListCtrl::FILELIST_MODIFY
;
227 mask
|= CGitStatusListCtrl::FILELIST_IGNORE
;
229 mask
|= CGitStatusListCtrl::FILELIST_UNVER
;
230 this->UpdateFileList(mask
,bUpdate
,(CTGitPathList
*)pathList
);
234 int refetchcounter
= 0;
237 // force the cursor to change
240 SetCursorPos(pt
.x
, pt
.y
);
242 m_mapFilenameToChecked
.clear();
243 //m_StatusUrlList.Clear();
244 bool bHasChangelists
= (m_changelists
.size()>1 || (m_changelists
.size()>0 && !m_bHasIgnoreGroup
));
245 m_changelists
.clear();
246 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
248 FileEntry
* entry
= m_arStatusArray
[i
];
249 if ( bHasChangelists
&& entry
->checked
)
251 // If change lists are present, remember all checked entries
252 CString path
= entry
->GetPath().GetGitPathString();
253 m_mapFilenameToChecked
[path
] = true;
255 if ( (entry
->status
==git_wc_status_unversioned
|| entry
->status
==git_wc_status_missing
) && entry
->checked
)
257 // The user manually selected an unversioned or missing file. We remember
258 // this so that the selection can be restored when refreshing.
259 CString path
= entry
->GetPath().GetGitPathString();
260 m_mapFilenameToChecked
[path
] = true;
262 else if ( entry
->status
> git_wc_status_normal
&& !entry
->checked
)
264 // The user manually deselected a versioned file. We remember
265 // this so that the deselection can be restored when refreshing.
266 CString path
= entry
->GetPath().GetGitPathString();
267 m_mapFilenameToChecked
[path
] = false;
271 // use a sorted path list to make sure we fetch the status of
272 // parent items first, *then* the child items (if any)
273 CTGitPathList sortedPathList
= pathList
;
274 sortedPathList
.SortByPathname();
279 m_bHasExternalsFromDifferentRepos
= FALSE
;
280 m_bHasExternals
= FALSE
;
281 m_bHasUnversionedItems
= FALSE
;
283 m_bHasChangeLists
= false;
284 m_bShowIgnores
= bShowIgnores
;
291 // first clear possible status data left from
292 // previous GetStatus() calls
295 m_StatusFileList
= sortedPathList
;
297 // Since Git_client_status() returns all files, even those in
298 // folders included with Git:externals we need to check if all
299 // files we get here belongs to the same repository.
300 // It is possible to commit changes in an external folder, as long
301 // as the folder belongs to the same repository (but another path),
302 // but it is not possible to commit all files if the externals are
303 // from a different repository.
305 // To check if all files belong to the same repository, we compare the
306 // UUID's - if they're identical then the files belong to the same
307 // repository and can be committed. But if they're different, then
308 // tell the user to commit all changes in the external folders
310 CStringA sUUID
; // holds the repo UUID
311 CTGitPathList arExtPaths
; // list of Git:external paths
317 m_nTargetCount
= sortedPathList
.GetCount();
319 GitStatus
status(m_pbCanceled
);
320 if(m_nTargetCount
> 1 && sortedPathList
.AreAllPathsFilesInOneDirectory())
322 // This is a special case, where we've been given a list of files
323 // all from one folder
324 // We handle them by setting a status filter, then requesting the Git status of
325 // all the files in the directory, filtering for the ones we're interested in
326 status
.SetFilter(sortedPathList
);
328 // if all selected entries are files, we don't do a recursive status
329 // fetching. But if only one is a directory, we have to recurse.
330 git_depth_t depth
= git_depth_files
;
331 // We have set a filter. If all selected items were files or we fetch
332 // the status not recursively, then we have to include
333 // ignored items too - the user has selected them
334 bool bShowIgnoresRight
= true;
335 for (int fcindex
=0; fcindex
<sortedPathList
.GetCount(); ++fcindex
)
337 if (sortedPathList
[fcindex
].IsDirectory())
339 depth
= git_depth_infinity
;
340 bShowIgnoresRight
= false;
344 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
.GetCommonDirectory(), bUpdate
, sUUID
, arExtPaths
, true, depth
, bShowIgnoresRight
))
351 for(int nTarget
= 0; nTarget
< m_nTargetCount
; nTarget
++)
353 // check whether the path we want the status for is already fetched due to status-fetching
355 // this check is only done for file paths, because folder paths could be included already
356 // but not recursively
357 if (sortedPathList
[nTarget
].IsDirectory() || GetListEntry(sortedPathList
[nTarget
]) == NULL
)
359 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
[nTarget
], bUpdate
, sUUID
,
360 arExtPaths
, false, git_depth_infinity
, bShowIgnores
))
368 // remove the 'helper' files of conflicted items from the list.
369 // otherwise they would appear as unversioned files.
370 for (INT_PTR cind
= 0; cind
< m_ConflictFileList
.GetCount(); ++cind
)
372 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
374 if (m_arStatusArray
[i
]->GetPath().IsEquivalentTo(m_ConflictFileList
[cind
]))
376 delete m_arStatusArray
[i
];
377 m_arStatusArray
.erase(m_arStatusArray
.begin()+i
);
383 } while(!BuildStatistics() && (refetchcounter
< 2) && (*m_pbCanceled
==false));
388 SetCursorPos(pt
.x
, pt
.y
);
395 // Get the show-flags bitmap value which corresponds to a particular Git status
396 DWORD
CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status
)
400 case git_wc_status_none
:
401 case git_wc_status_unversioned
:
402 return GITSLC_SHOWUNVERSIONED
;
403 case git_wc_status_ignored
:
405 return GITSLC_SHOWDIRECTS
;
406 return GITSLC_SHOWDIRECTS
|GITSLC_SHOWIGNORED
;
407 case git_wc_status_incomplete
:
408 return GITSLC_SHOWINCOMPLETE
;
409 case git_wc_status_normal
:
410 return GITSLC_SHOWNORMAL
;
411 case git_wc_status_external
:
412 return GITSLC_SHOWEXTERNAL
;
413 case git_wc_status_added
:
414 return GITSLC_SHOWADDED
;
415 case git_wc_status_missing
:
416 return GITSLC_SHOWMISSING
;
417 case git_wc_status_deleted
:
418 return GITSLC_SHOWREMOVED
;
419 case git_wc_status_replaced
:
420 return GITSLC_SHOWREPLACED
;
421 case git_wc_status_modified
:
422 return GITSLC_SHOWMODIFIED
;
423 case git_wc_status_merged
:
424 return GITSLC_SHOWMERGED
;
425 case git_wc_status_conflicted
:
426 return GITSLC_SHOWCONFLICTED
;
427 case git_wc_status_obstructed
:
428 return GITSLC_SHOWOBSTRUCTED
;
430 // we should NEVER get here!
437 void CGitStatusListCtrl::Show(unsigned int dwShow
, unsigned int dwCheck
/*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList
,bool UseStoredCheckStatus
)
439 CWinApp
* pApp
= AfxGetApp();
441 pApp
->DoWaitCursor(1);
443 Locker
lock(m_critSec
);
444 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
446 //SetItemCount(listIndex);
451 m_nShownUnversioned
= 0;
452 m_nShownModified
= 0;
455 m_nShownConflicted
= 0;
457 m_nShownSubmodules
= 0;
461 m_arStatusArray
.clear();
462 for(int i
=0;i
<this->m_StatusFileList
.GetCount();i
++)
464 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
467 for(int i
=0;i
<this->m_UnRevFileList
.GetCount();i
++)
469 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
472 for(int i
=0;i
<this->m_IgnoreFileList
.GetCount();i
++)
474 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
478 if (m_nSortedColumn
>= 0)
480 CSorter
predicate (&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
481 std::sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
485 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
487 //set default checkbox status
488 CTGitPath
* entry
= ((CTGitPath
*)m_arStatusArray
[i
]);
489 CString path
= entry
->GetGitPathString();
490 if (m_mapFilenameToChecked
.size()!=0 && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end())
492 entry
->m_Checked
=m_mapFilenameToChecked
[path
];
494 else if (!UseStoredCheckStatus
)
496 bool autoSelectSubmodules
= !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
);
497 if(entry
->m_Action
& dwCheck
&& autoSelectSubmodules
)
498 entry
->m_Checked
=true;
500 entry
->m_Checked
=false;
501 m_mapFilenameToChecked
[path
] = entry
->m_Checked
;
504 if(entry
->m_Action
& dwShow
)
506 AddEntry(entry
,langID
,index
);
511 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
512 for (int col
= 0; col
<= maxcol
; col
++)
513 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
516 GetStatisticsString();
518 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
519 HDITEM HeaderItem
= {0};
520 HeaderItem
.mask
= HDI_FORMAT
;
521 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
523 pHeader
->GetItem(i
, &HeaderItem
);
524 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
525 pHeader
->SetItem(i
, &HeaderItem
);
527 if (m_nSortedColumn
>= 0)
529 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
530 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
531 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
537 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
538 EnsureVisible(nSelectedEntry
, false);
542 // Restore the item at the top of the list.
543 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
545 if ( !EnsureVisible(nTopIndex
+i
,false) )
553 pApp
->DoWaitCursor(-1);
559 this->BuildStatistics();
563 CWinApp
* pApp
= AfxGetApp();
565 pApp
->DoWaitCursor(1);
567 m_bShowFolders
= bShowFolders
;
569 int nTopIndex
= GetTopIndex();
570 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
571 int nSelectedEntry
= 0;
572 if (posSelectedEntry
)
573 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
579 m_arListArray
.clear();
581 m_arListArray
.reserve(m_arStatusArray
.size());
582 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
585 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
587 FileEntry
* entry
= m_arStatusArray
[i
];
588 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
590 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
592 if (entry
->IsFolder() && (!bShowFolders
))
593 continue; // don't show folders if they're not wanted.
596 git_wc_status_kind status
= GitStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
597 DWORD showFlags
= GetShowFlagsFromGitStatus(status
);
598 if (entry
->IsLocked())
599 showFlags
|= SVNSLC_SHOWLOCKS
;
601 showFlags
|= SVNSLC_SHOWSWITCHED
;
602 if (!entry
->changelist
.IsEmpty())
603 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
605 bool bAllowCheck
= ((entry
->changelist
.Compare(GITSLC_IGNORECHANGELIST
) != 0)
606 && (m_bCheckIfGroupsExist
|| (m_changelists
.size()==0 || (m_changelists
.size()==1 && m_bHasIgnoreGroup
))));
608 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
610 if (status
!= Git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& GitSLC_SHOWIGNORED
))
612 if ((!entry
->IsFolder()) && (status
== Git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
614 if (PathFileExists(entry
->GetPath().GetWinPath()))
616 m_arListArray
.push_back(i
);
617 if ((dwCheck
& SVNSLC_SHOWREMOVEDANDPRESENT
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
620 entry
->checked
= true;
622 AddEntry(entry
, langID
, listIndex
++);
625 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
627 m_arListArray
.push_back(i
);
628 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
631 entry
->checked
= true;
633 AddEntry(entry
, langID
, listIndex
++);
635 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
637 m_arListArray
.push_back(i
);
638 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
641 entry
->checked
= true;
643 AddEntry(entry
, langID
, listIndex
++);
649 SetItemCount(listIndex
);
651 m_ColumnManager
.UpdateRelevance (m_arStatusArray
, m_arListArray
);
653 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
654 for (int col
= 0; col
<= maxcol
; col
++)
655 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
658 GetStatisticsString();
660 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
661 HDITEM HeaderItem
= {0};
662 HeaderItem
.mask
= HDI_FORMAT
;
663 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
665 pHeader
->GetItem(i
, &HeaderItem
);
666 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
667 pHeader
->SetItem(i
, &HeaderItem
);
671 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
672 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
673 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
678 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
679 EnsureVisible(nSelectedEntry
, false);
683 // Restore the item at the top of the list.
684 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
686 if ( !EnsureVisible(nTopIndex
+i
,false) )
694 pApp
->DoWaitCursor(-1);
696 m_bEmpty
= (GetItemCount() == 0);
702 void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList
& checkedList
, bool /*bShowFolders*/ /* = true */)
705 for(int i
=0;i
<checkedList
.GetCount();i
++)
706 this->AddEntry((CTGitPath
*)&checkedList
[i
],0,i
);
710 Locker
lock(m_critSec
);
711 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
713 CWinApp
* pApp
= AfxGetApp();
715 pApp
->DoWaitCursor(1);
717 m_bShowFolders
= bShowFolders
;
719 int nTopIndex
= GetTopIndex();
720 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
721 int nSelectedEntry
= 0;
722 if (posSelectedEntry
)
723 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
729 m_arListArray
.clear();
731 m_arListArray
.reserve(m_arStatusArray
.size());
732 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
735 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
737 FileEntry
* entry
= m_arStatusArray
[i
];
738 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
740 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
742 if (entry
->IsFolder() && (!bShowFolders
))
743 continue; // don't show folders if they're not wanted.
745 git_wc_status_kind status
= SVNStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
746 DWORD showFlags
= GetShowFlagsFromSVNStatus(status
);
747 if (entry
->IsLocked())
748 showFlags
|= SVNSLC_SHOWLOCKS
;
749 if (!entry
->changelist
.IsEmpty())
750 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
752 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
753 if (status
!= git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& SVNSLC_SHOWIGNORED
))
755 for (int npath
= 0; npath
< checkedList
.GetCount(); ++npath
)
757 if (entry
->GetPath().IsEquivalentTo(checkedList
[npath
]))
759 entry
->checked
= true;
763 if ((!entry
->IsFolder()) && (status
== git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
765 if (PathFileExists(entry
->GetPath().GetWinPath()))
767 m_arListArray
.push_back(i
);
768 AddEntry(entry
, langID
, listIndex
++);
771 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
773 m_arListArray
.push_back(i
);
774 AddEntry(entry
, langID
, listIndex
++);
776 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
778 m_arListArray
.push_back(i
);
779 AddEntry(entry
, langID
, listIndex
++);
781 else if (entry
->switched
)
783 m_arListArray
.push_back(i
);
784 AddEntry(entry
, langID
, listIndex
++);
790 SetItemCount(listIndex
);
792 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
793 for (int col
= 0; col
<= maxcol
; col
++)
794 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
797 GetStatisticsString();
799 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
800 HDITEM HeaderItem
= {0};
801 HeaderItem
.mask
= HDI_FORMAT
;
802 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
804 pHeader
->GetItem(i
, &HeaderItem
);
805 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
806 pHeader
->SetItem(i
, &HeaderItem
);
810 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
811 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
812 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
817 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
818 EnsureVisible(nSelectedEntry
, false);
822 // Restore the item at the top of the list.
823 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
825 if ( !EnsureVisible(nTopIndex
+i
,false) )
833 pApp
->DoWaitCursor(-1);
835 m_bEmpty
= (GetItemCount() == 0);
840 int CGitStatusListCtrl::GetColumnIndex(int mask
)
850 void CGitStatusListCtrl::AddEntry(CTGitPath
* GitPath
, WORD
/*langID*/, int listIndex
)
852 static CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
853 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
854 static bool abbreviateRenamings(((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\AbbreviateRenamings"), FALSE
)) == TRUE
);
855 static bool relativeTimes
= (CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
) != FALSE
);
857 CString path
= GitPath
->GetGitPathString();
860 int index
= listIndex
;
862 CString entryname
= GitPath
->GetGitPathString();
864 if (GitPath
->IsDirectory())
866 icon_idx
= m_nIconFolder
;
867 m_nShownSubmodules
++;
871 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(*GitPath
);
874 switch (GitPath
->m_Action
)
876 case CTGitPath::LOGACTIONS_ADDED
:
877 case CTGitPath::LOGACTIONS_COPY
:
880 case CTGitPath::LOGACTIONS_DELETED
:
883 case CTGitPath::LOGACTIONS_REPLACED
:
884 case CTGitPath::LOGACTIONS_MODIFIED
:
885 case CTGitPath::LOGACTIONS_MERGED
:
888 case CTGitPath::LOGACTIONS_UNMERGED
:
889 m_nShownConflicted
++;
891 case CTGitPath::LOGACTIONS_UNVER
:
892 m_nShownUnversioned
++;
895 m_nShownUnversioned
++;
898 if(GitPath
->m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !GitPath
->GetGitOldPathString().IsEmpty())
900 if (!abbreviateRenamings
)
904 rename
.Format(from
, GitPath
->GetGitOldPathString());
905 entryname
+= _T(" ") + rename
;
910 tgpl
.AddPath(*GitPath
);
911 CTGitPath
old(GitPath
->GetGitOldPathString());
913 CString commonRoot
= tgpl
.GetCommonRoot().GetGitPathString();
914 if (!commonRoot
.IsEmpty())
915 commonRoot
+= _T("/");
916 if (old
.GetFileOrDirectoryName() == GitPath
->GetFileOrDirectoryName() && old
.GetContainingDirectory().GetGitPathString() != "" && GitPath
->GetContainingDirectory().GetGitPathString())
918 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();
920 else if (!commonRoot
.IsEmpty())
922 entryname
= commonRoot
+ _T("{") + GitPath
->GetGitOldPathString().Mid(commonRoot
.GetLength()) + _T(" => ") + GitPath
->GetGitPathString().Mid(commonRoot
.GetLength()) + _T("}");
926 entryname
= GitPath
->GetGitOldPathString().Mid(commonRoot
.GetLength()) + _T(" => ") + GitPath
->GetGitPathString().Mid(commonRoot
.GetLength());
931 InsertItem(index
, entryname
, icon_idx
);
932 if (m_restorepaths
.find(GitPath
->GetWinPathString()) != m_restorepaths
.end())
933 SetItemState(index
, INDEXTOOVERLAYMASK(OVL_RESTORE
), TVIS_OVERLAYMASK
);
935 this->SetItemData(index
, (DWORD_PTR
)GitPath
);
936 // SVNSLC_COLFILENAME
937 SetItemText(index
, nCol
++, GitPath
->GetFileOrDirectoryName());
939 SetItemText(index
, nCol
++, GitPath
->GetFileExtension());
941 SetItemText(index
, nCol
++, GitPath
->GetActionName());
943 SetItemText(index
, GetColumnIndex(GITSLC_COLADD
),GitPath
->m_StatAdd
);
944 SetItemText(index
, GetColumnIndex(GITSLC_COLDEL
),GitPath
->m_StatDel
);
947 CString modificationDate
;
948 __int64 filetime
= GitPath
->GetLastWriteTime();
949 if (filetime
&& (GitPath
->m_Action
!= CTGitPath::LOGACTIONS_DELETED
))
951 FILETIME
* f
= (FILETIME
*)(__int64
*)&filetime
;
952 modificationDate
= CLoglistUtils::FormatDateAndTime(CTime(g_Git
.filetime_to_time_t(f
)), DATE_SHORTDATE
, true, relativeTimes
);
954 SetItemText(index
, GetColumnIndex(GITSLC_COLMODIFICATIONDATE
), modificationDate
);
957 if (GitPath
->IsDirectory())
958 SetItemText(index
, GetColumnIndex(GITSLC_COLSIZE
), _T(""));
962 StrFormatByteSize64(GitPath
->GetFileSize(), buf
, 100);
963 SetItemText(index
, GetColumnIndex(GITSLC_COLSIZE
), buf
);
966 SetCheck(index
, GitPath
->m_Checked
);
967 if (GitPath
->m_Checked
)
971 if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_IGNORE
)
972 SetItemGroup(index
, 2);
973 else if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
974 SetItemGroup(index
,1);
977 SetItemGroup(index
, GitPath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
));
985 bool CGitStatusListCtrl::SetItemGroup(int item
, int groupindex
)
987 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
992 i
.mask
= LVIF_GROUPID
;
995 i
.iGroupId
= groupindex
;
997 return !!SetItem(&i
);
1000 void CGitStatusListCtrl::OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1002 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1007 if (m_nSortedColumn
== phdr
->iItem
)
1008 m_bAscending
= !m_bAscending
;
1010 m_bAscending
= TRUE
;
1011 m_nSortedColumn
= phdr
->iItem
;
1012 Show(m_dwShow
, 0, m_bShowFolders
,false,true);
1017 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1019 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1022 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1023 if ((m_bBlock
)&&(m_bBlockUI
))
1025 // if we're blocked, prevent changing of the check state
1026 if ((!ISCHECKED(pNMLV
->uOldState
) && ISCHECKED(pNMLV
->uNewState
))||
1027 (ISCHECKED(pNMLV
->uOldState
) && !ISCHECKED(pNMLV
->uNewState
)))
1032 BOOL
CGitStatusListCtrl::OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1034 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1036 CWnd
* pParent
= GetParent();
1037 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
1039 pParent
->SendMessage(GITSLNM_ITEMCHANGED
, pNMLV
->iItem
);
1042 if ((pNMLV
->uNewState
==0)||(pNMLV
->uNewState
& LVIS_SELECTED
)||(pNMLV
->uNewState
& LVIS_FOCUSED
))
1048 bool bSelected
= !!(ListView_GetItemState(m_hWnd
, pNMLV
->iItem
, LVIS_SELECTED
) & LVIS_SELECTED
);
1049 int nListItems
= GetItemCount();
1052 // was the item checked?
1054 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1055 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1057 if (GetCheck(pNMLV
->iItem
))
1059 CheckEntry(pNMLV
->iItem
, nListItems
);
1062 POSITION pos
= GetFirstSelectedItemPosition();
1064 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1066 if (index
!= pNMLV
->iItem
)
1067 CheckEntry(index
, nListItems
);
1073 UncheckEntry(pNMLV
->iItem
, nListItems
);
1076 POSITION pos
= GetFirstSelectedItemPosition();
1078 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1080 if (index
!= pNMLV
->iItem
)
1081 UncheckEntry(index
, nListItems
);
1086 GetStatisticsString();
1093 void CGitStatusListCtrl::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1095 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
1100 void CGitStatusListCtrl::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1102 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
1107 void CGitStatusListCtrl::CheckEntry(int index
, int /*nListItems*/)
1109 Locker
lock(m_critSec
);
1110 //FileEntry * entry = GetListEntry(index);
1111 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1112 ASSERT(path
!= NULL
);
1115 m_mapFilenameToChecked
[path
->GetGitPathString()] = true;
1116 SetCheck(index
, TRUE
);
1117 //entry = GetListEntry(index);
1118 // if an unversioned item was checked, then we need to check if
1119 // the parent folders are unversioned too. If the parent folders actually
1120 // are unversioned, then check those too.
1122 if (entry
->status
== git_wc_status_unversioned
)
1124 // we need to check the parent folder too
1125 const CTGitPath
& folderpath
= entry
->path
;
1126 for (int i
=0; i
< nListItems
; ++i
)
1128 FileEntry
* testEntry
= GetListEntry(i
);
1129 ASSERT(testEntry
!= NULL
);
1130 if (testEntry
== NULL
)
1132 if (!testEntry
->checked
)
1134 if (testEntry
->path
.IsAncestorOf(folderpath
) && (!testEntry
->path
.IsEquivalentTo(folderpath
)))
1136 SetEntryCheck(testEntry
,i
,true);
1142 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1143 if ( (entry
->status
== git_wc_status_deleted
) || (m_bCheckChildrenWithParent
) || (bShift
) )
1145 // if a deleted folder gets checked, we have to check all
1146 // children of that folder too.
1147 if (entry
->path
.IsDirectory())
1149 SetCheckOnAllDescendentsOf(entry
, true);
1152 // if a deleted file or folder gets checked, we have to
1153 // check all parents of this item too.
1154 for (int i
=0; i
<nListItems
; ++i
)
1156 FileEntry
* testEntry
= GetListEntry(i
);
1157 ASSERT(testEntry
!= NULL
);
1158 if (testEntry
== NULL
)
1160 if (!testEntry
->checked
)
1162 if (testEntry
->path
.IsAncestorOf(entry
->path
) && (!testEntry
->path
.IsEquivalentTo(entry
->path
)))
1164 if ((testEntry
->status
== git_wc_status_deleted
)||(m_bCheckChildrenWithParent
))
1166 SetEntryCheck(testEntry
,i
,true);
1168 // now we need to check all children of this parent folder
1169 SetCheckOnAllDescendentsOf(testEntry
, true);
1176 if ( !path
->m_Checked
)
1178 path
->m_Checked
= TRUE
;
1183 void CGitStatusListCtrl::UncheckEntry(int index
, int /*nListItems*/)
1185 Locker
lock(m_critSec
);
1186 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1187 ASSERT(path
!= NULL
);
1190 SetCheck(index
, FALSE
);
1191 m_mapFilenameToChecked
[path
->GetGitPathString()] = false;
1192 //entry = GetListEntry(index);
1193 // item was unchecked
1195 if (entry
->path
.IsDirectory())
1197 // disable all files within an unselected folder, except when unchecking a folder with property changes
1198 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1199 if ( (entry
->status
!= git_wc_status_modified
) || (bShift
) )
1201 SetCheckOnAllDescendentsOf(entry
, false);
1204 else if (entry
->status
== git_wc_status_deleted
)
1206 // a "deleted" file was unchecked, so uncheck all parent folders
1207 // and all children of those parents
1208 for (int i
=0; i
<nListItems
; i
++)
1210 FileEntry
* testEntry
= GetListEntry(i
);
1211 ASSERT(testEntry
!= NULL
);
1212 if (testEntry
== NULL
)
1214 if (testEntry
->checked
)
1216 if (testEntry
->path
.IsAncestorOf(entry
->path
))
1218 if (testEntry
->status
== git_wc_status_deleted
)
1220 SetEntryCheck(testEntry
,i
,false);
1223 SetCheckOnAllDescendentsOf(testEntry
, false);
1230 if ( path
->m_Checked
)
1232 path
->m_Checked
= FALSE
;
1236 bool CGitStatusListCtrl::BuildStatistics()
1239 bool bRefetchStatus
= false;
1241 // now gather some statistics
1254 for (int i
=0; i
< (int)m_arStatusArray
.size(); ++i
)
1256 int status
=((CTGitPath
*)m_arStatusArray
[i
])->m_Action
;
1258 m_nLineAdded
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatAdd
);
1259 m_nLineDeleted
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatDel
);
1261 if(status
&(CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
1264 if(status
&CTGitPath::LOGACTIONS_DELETED
)
1267 if(status
&(CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_MODIFIED
))
1270 if(status
&CTGitPath::LOGACTIONS_UNMERGED
)
1273 if(status
&(CTGitPath::LOGACTIONS_IGNORE
|CTGitPath::LOGACTIONS_UNVER
))
1276 if(status
&(CTGitPath::LOGACTIONS_REPLACED
))
1279 if(((CTGitPath
*)m_arStatusArray
[i
])->m_Checked
)
1282 // } // switch (entry->status)
1284 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1285 return !bRefetchStatus
;
1291 int CGitStatusListCtrl::GetGroupFromPoint(POINT
* ppt
)
1293 // the point must be relative to the upper left corner of the control
1297 if (!IsGroupViewEnabled())
1306 while (((flags
& LVHT_BELOW
) == 0)&&(pt
.y
< rc
.bottom
))
1308 nItem
= HitTest(pt
, &flags
);
1309 if ((flags
& LVHT_ONITEM
)||(flags
& LVHT_EX_GROUP_HEADER
))
1311 // the first item below the point
1313 // check if the point is too much right (i.e. if the point
1314 // is farther to the right than the width of the item)
1316 GetItemRect(nItem
, &r
, LVIR_LABEL
);
1317 if (ppt
->x
> r
.right
)
1321 lv
.mask
= LVIF_GROUPID
;
1324 int groupID
= lv
.iGroupId
;
1325 // now we search upwards and check if the item above this one
1326 // belongs to another group. If it belongs to the same group,
1327 // we're not over a group header
1331 nItem
= HitTest(pt
, &flags
);
1332 if ((flags
& LVHT_ONITEM
)&&(nItem
>= 0))
1334 // the first item below the point
1336 lv
.mask
= LVIF_GROUPID
;
1339 if (lv
.iGroupId
!= groupID
)
1354 void CGitStatusListCtrl::OnContextMenuGroup(CWnd
* /*pWnd*/, CPoint point
)
1356 POINT clientpoint
= point
;
1357 ScreenToClient(&clientpoint
);
1358 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint
) >= 0))
1361 if (popup
.CreatePopupMenu())
1364 temp
.LoadString(IDS_STATUSLIST_CHECKGROUP
);
1365 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_CHECKGROUP
, temp
);
1366 temp
.LoadString(IDS_STATUSLIST_UNCHECKGROUP
);
1367 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_UNCHECKGROUP
, temp
);
1368 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1369 bool bCheck
= false;
1372 case IDGITLC_CHECKGROUP
:
1374 // fall through here
1375 case IDGITLC_UNCHECKGROUP
:
1377 int group
= GetGroupFromPoint(&clientpoint
);
1378 // go through all items and check/uncheck those assigned to the group
1379 // but block the OnLvnItemChanged handler
1382 for (int i
=0; i
<GetItemCount(); ++i
)
1384 SecureZeroMemory(&lv
, sizeof(LVITEM
));
1385 lv
.mask
= LVIF_GROUPID
;
1389 if (lv
.iGroupId
== group
)
1391 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
1394 bool bOldCheck
= entry
->m_Checked
;
1395 SetEntryCheck(entry
, i
, bCheck
);
1396 if (bCheck
!= bOldCheck
)
1407 GetStatisticsString();
1417 void CGitStatusListCtrl::OnContextMenuList(CWnd
* pWnd
, CPoint point
)
1420 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1422 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1423 CTGitPath
* filepath
;
1425 int selIndex
= GetSelectionMark();
1426 if ((point
.x
== -1) && (point
.y
== -1))
1429 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1430 ClientToScreen(&rect
);
1431 point
= rect
.CenterPoint();
1433 if ((GetSelectedCount() == 0) && (m_bHasCheckboxes
))
1435 // nothing selected could mean the context menu is requested for
1437 OnContextMenuGroup(pWnd
, point
);
1439 else if (selIndex
>= 0)
1441 //FileEntry * entry = GetListEntry(selIndex);
1443 filepath
= (CTGitPath
* )GetItemData(selIndex
);
1445 ASSERT(filepath
!= NULL
);
1446 if (filepath
== NULL
)
1449 //const CTGitPath& filepath = entry->path;
1450 int wcStatus
= filepath
->m_Action
;
1451 // entry is selected, now show the popup menu
1452 Locker
lock(m_critSec
);
1454 CMenu changelistSubMenu
;
1455 CMenu ignoreSubMenu
;
1456 if (popup
.CreatePopupMenu())
1458 //Add Menu for version controlled file
1460 if (GetSelectedCount() > 0 && wcStatus
& CTGitPath::LOGACTIONS_UNMERGED
)
1462 if (GetSelectedCount() == 1 && (m_dwContextMenus
& GITSLC_POPCONFLICT
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1464 popup
.AppendMenuIcon(IDGITLC_EDITCONFLICT
, IDS_MENUCONFLICT
, IDI_CONFLICT
);
1466 if (m_dwContextMenus
& GITSLC_POPRESOLVE
)
1468 popup
.AppendMenuIcon(IDGITLC_RESOLVECONFLICT
, IDS_STATUSLIST_CONTEXT_RESOLVED
, IDI_RESOLVE
);
1470 if ((m_dwContextMenus
& GITSLC_POPRESOLVE
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1472 popup
.AppendMenuIcon(IDGITLC_RESOLVETHEIRS
, IDS_SVNPROGRESS_MENUUSETHEIRS
, IDI_RESOLVE
);
1473 popup
.AppendMenuIcon(IDGITLC_RESOLVEMINE
, IDS_SVNPROGRESS_MENUUSEMINE
, IDI_RESOLVE
);
1475 if ((m_dwContextMenus
& GITSLC_POPCONFLICT
)||(m_dwContextMenus
& GITSLC_POPRESOLVE
))
1476 popup
.AppendMenu(MF_SEPARATOR
);
1479 if (GetSelectedCount() > 0)
1481 if (wcStatus
& CTGitPath::LOGACTIONS_UNVER
)
1482 if (m_dwContextMenus
& GITSLC_POPADD
)
1484 //if ( entry->IsFolder() )
1486 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1490 popup
.AppendMenuIcon(IDGITLC_ADD
, IDS_STATUSLIST_CONTEXT_ADD
, IDI_ADD
);
1495 if (!(wcStatus
&CTGitPath::LOGACTIONS_UNVER
))
1497 if ( (m_dwContextMenus
& GITSLC_POPCOMPAREWITHBASE
) && GetSelectedCount()>0)
1499 if(filepath
->m_ParentNo
& MERGE_MASK
)
1500 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_TREE_DIFF
, IDI_DIFF
);
1502 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_LOG_COMPAREWITHBASE
, IDI_DIFF
);
1504 popup
.SetDefaultItem(IDGITLC_COMPARE
, FALSE
);
1507 if ((m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPAREWC
)) && GetSelectedCount()>0 && m_bHasWC
)
1509 if( (!m_CurrentVersion
.IsEmpty()) && m_CurrentVersion
!= GIT_REV_ZERO
)
1510 popup
.AppendMenuIcon(IDGITLC_COMPAREWC
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1513 if (GetSelectedCount() == 1)
1515 bool bEntryAdded
= false;
1516 //if (entry->remotestatus <= git_wc_status_normal)
1518 // if (wcStatus > git_wc_status_normal)
1520 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
1522 if(!g_Git
.IsInitRepos() && (m_dwContextMenus
&GITSLC_POPGNUDIFF
))
1524 popup
.AppendMenuIcon(IDGITLC_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1532 //else if (wcStatus != git_wc_status_deleted)
1534 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
1536 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1537 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1538 // bEntryAdded = true;
1540 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
1542 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1543 // bEntryAdded = true;
1547 popup
.AppendMenu(MF_SEPARATOR
);
1549 //else if (GetSelectedCount() > 1)
1551 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1553 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1554 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1559 if( (!this->m_Rev1
.IsEmpty()) || (!this->m_Rev1
.IsEmpty()) )
1561 if(GetSelectedCount() == 1)
1563 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPARETWO
))
1565 popup
.AppendMenuIcon(IDGITLC_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1566 popup
.SetDefaultItem(IDGITLC_COMPARETWO
, FALSE
);
1568 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_GNUDIFF2
))
1570 popup
.AppendMenuIcon(IDGITLC_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1576 if (GetSelectedCount() > 0)
1578 if ((GetSelectedCount() == 2) && (m_dwContextMenus
& this->GetContextMenuBit(GITSLC_POPCOMPARETWOFILES
)) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1580 POSITION pos
= GetFirstSelectedItemPosition();
1581 int index
= GetNextSelectedItem(pos
);
1584 CTGitPath
* entry2
= NULL
;
1585 bool bothItemsAreExistingFiles
= true;
1586 entry2
= (CTGitPath
* )GetItemData(index
);
1588 bothItemsAreExistingFiles
= !entry2
->IsDirectory() && entry2
->Exists();
1589 index
= GetNextSelectedItem(pos
);
1592 entry2
= (CTGitPath
* )GetItemData(index
);
1594 bothItemsAreExistingFiles
= bothItemsAreExistingFiles
&& !entry2
->IsDirectory() && entry2
->Exists();
1595 if (bothItemsAreExistingFiles
)
1596 popup
.AppendMenuIcon(IDGITLC_COMPARETWOFILES
, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES
, IDI_DIFF
);
1600 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
1602 // POSITION pos = GetFirstSelectedItemPosition();
1603 // int index = GetNextSelectedItem(pos);
1606 // FileEntry * entry = GetListEntry(index);
1607 // git_wc_status_kind status1 = git_wc_status_none;
1608 // git_wc_status_kind status2 = git_wc_status_none;
1610 // status1 = entry->status;
1611 // index = GetNextSelectedItem(pos);
1614 // entry = GetListEntry(index);
1616 // status2 = entry->status;
1617 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
1618 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
1620 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
1625 // if (wcStatus > git_wc_status_normal)
1627 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1629 // // reverting missing folders is not possible
1630 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1632 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1636 // if (entry->remotestatus > git_wc_status_normal)
1638 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1640 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1645 if ( (GetSelectedCount() >0 ) && (!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
)) && m_bHasWC
)
1647 if ((m_dwContextMenus
& GITSLC_POPREVERT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1649 popup
.AppendMenuIcon(IDGITLC_REVERT
, IDS_MENUREVERT
, IDI_REVERT
);
1652 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())
1654 popup
.AppendMenuIcon(IDGITLC_ASSUMEVALID
, IDS_MENUASSUMEVALID
);
1657 if (m_dwContextMenus
& GITSLC_POPRESTORE
&& !filepath
->IsDirectory())
1659 if (m_restorepaths
.find(filepath
->GetWinPathString()) == m_restorepaths
.end())
1660 popup
.AppendMenuIcon(IDGITLC_CREATERESTORE
, IDS_MENUCREATERESTORE
, IDI_RESTORE
);
1662 popup
.AppendMenuIcon(IDGITLC_RESTOREPATH
, IDS_MENURESTORE
, IDI_RESTORE
);
1665 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOREV
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1666 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1668 popup
.AppendMenuIcon(IDGITLC_REVERTTOREV
, IDS_LOG_POPUP_REVERTTOREV
, IDI_REVERT
);
1672 if ((GetSelectedCount() == 1)&&(!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
))
1673 &&(!(wcStatus
& CTGitPath::LOGACTIONS_IGNORE
)))
1675 if (m_dwContextMenus
& GITSLC_POPSHOWLOG
)
1677 popup
.AppendMenuIcon(IDGITLC_LOG
, IDS_REPOBROWSE_SHOWLOG
, IDI_LOG
);
1679 if (m_dwContextMenus
& GITSLC_POPSHOWLOGOLDNAME
&& (wcStatus
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !filepath
->GetGitOldPathString().IsEmpty()))
1681 popup
.AppendMenuIcon(IDGITLC_LOGOLDNAME
, IDS_STATUSLIST_SHOWLOGOLDNAME
, IDI_LOG
);
1683 if (m_dwContextMenus
& GITSLC_POPBLAME
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
)
1685 popup
.AppendMenuIcon(IDGITLC_BLAME
, IDS_MENUBLAME
, IDI_BLAME
);
1688 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1689 if ( (GetSelectedCount() == 1) )
1691 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_SAVEAS
) && ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1693 popup
.AppendMenuIcon(IDGITLC_SAVEAS
, IDS_LOG_POPUP_SAVE
, IDI_SAVEAS
);
1696 if (m_dwContextMenus
& GITSLC_POPOPEN
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1698 popup
.AppendMenuIcon(IDGITLC_VIEWREV
, IDS_LOG_POPUP_VIEWREV
);
1699 popup
.AppendMenuIcon(IDGITLC_OPEN
, IDS_REPOBROWSE_OPEN
, IDI_OPEN
);
1700 popup
.AppendMenuIcon(IDGITLC_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1701 if (wcStatus
&CTGitPath::LOGACTIONS_UNVER
) {
1702 popup
.SetDefaultItem(IDGITLC_OPEN
, FALSE
);
1706 if (m_dwContextMenus
& GITSLC_POPEXPLORE
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
)
1708 popup
.AppendMenuIcon(IDGITLC_EXPLORE
, IDS_STATUSLIST_CONTEXT_EXPLORE
, IDI_EXPLORER
);
1712 if (GetSelectedCount() > 0)
1714 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
1716 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1718 // 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))
1721 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
1723 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
1725 if ((wcStatus
& CTGitPath::LOGACTIONS_UNVER
)/*||(wcStatus == git_wc_status_deleted)*/)
1727 if (m_dwContextMenus
& GITSLC_POPDELETE
)
1729 popup
.AppendMenuIcon(IDGITLC_DELETE
, IDS_MENUREMOVE
, IDI_DELETE
);
1732 if ( (wcStatus
& CTGitPath::LOGACTIONS_UNVER
|| wcStatus
& CTGitPath::LOGACTIONS_DELETED
) )
1734 if (m_dwContextMenus
& GITSLC_POPIGNORE
)
1737 CTGitPathList ignorelist
;
1738 FillListOfSelectedItemPaths(ignorelist
);
1739 //check if all selected entries have the same extension
1740 bool bSameExt
= true;
1742 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
1744 if (sExt
.IsEmpty() && (i
==0))
1745 sExt
= ignorelist
[i
].GetFileExtension();
1746 else if (sExt
.CompareNoCase(ignorelist
[i
].GetFileExtension())!=0)
1751 if (ignoreSubMenu
.CreateMenu())
1754 if (ignorelist
.GetCount()==1)
1755 ignorepath
= ignorelist
[0].GetFileOrDirectoryName();
1757 ignorepath
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1758 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNORE
, ignorepath
);
1759 ignorepath
= _T("*")+sExt
;
1760 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREMASK
, ignorepath
);
1762 temp
.LoadString(IDS_MENUIGNORE
);
1763 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)ignoreSubMenu
.m_hMenu
, temp
);
1769 if (ignorelist
.GetCount()==1)
1771 temp
.LoadString(IDS_MENUIGNORE
);
1775 temp
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1777 popup
.AppendMenuIcon(IDGITLC_IGNORE
, temp
, IDI_IGNORE
);
1785 if (GetSelectedCount() > 0)
1787 popup
.AppendMenu(MF_SEPARATOR
);
1788 popup
.AppendMenuIcon(IDGITLC_COPY
, IDS_STATUSLIST_CONTEXT_COPY
, IDI_COPYCLIP
);
1789 popup
.AppendMenuIcon(IDGITLC_COPYEXT
, IDS_STATUSLIST_CONTEXT_COPYEXT
, IDI_COPYCLIP
);
1791 if ((m_dwContextMenus
& SVNSLC_POPCHANGELISTS
))
1792 &&(wcStatus
!= git_wc_status_unversioned
)&&(wcStatus
!= git_wc_status_none
))
1794 popup
.AppendMenu(MF_SEPARATOR
);
1795 // changelist commands
1796 size_t numChangelists
= GetNumberOfChangelistsInSelection();
1797 if (numChangelists
> 0)
1799 popup
.AppendMenuIcon(IDSVNLC_REMOVEFROMCS
, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS
);
1801 if ((!entry
->IsFolder())&&(changelistSubMenu
.CreateMenu()))
1804 temp
.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS
);
1805 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATECS
, temp
);
1807 if (entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
))
1809 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1810 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATEIGNORECS
, SVNSLC_IGNORECHANGELIST
);
1813 if (m_changelists
.size() > 0)
1815 // find the changelist names
1816 bool bNeedSeparator
= true;
1817 int cmdID
= IDSVNLC_MOVETOCS
;
1818 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
1820 if ((entry
->changelist
.Compare(it
->first
))&&(it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)))
1824 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1825 bNeedSeparator
= false;
1827 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, cmdID
, it
->first
);
1832 temp
.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS
);
1833 popup
.AppendMenu(MF_POPUP
|MF_STRING
, (UINT_PTR
)changelistSubMenu
.GetSafeHmenu(), temp
);
1839 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1842 AfxGetApp()->DoWaitCursor(1);
1843 //int iItemCountBeforeMenuCmd = GetItemCount();
1844 //bool bForce = false;
1847 case IDGITLC_VIEWREV
:
1848 OpenFile(filepath
, ALTERNATIVEEDITOR
);
1851 OpenFile(filepath
,OPEN
);
1853 case IDGITLC_OPENWITH
:
1854 OpenFile(filepath
,OPEN_WITH
);
1856 case IDGITLC_EXPLORE
:
1858 ShellExecute(this->m_hWnd
, _T("explore"), filepath
->GetDirectory().GetWinPath(), NULL
, NULL
, SW_SHOW
);
1861 case IDGITLC_CREATERESTORE
:
1863 POSITION pos
= GetFirstSelectedItemPosition();
1866 int index
= GetNextSelectedItem(pos
);
1867 CTGitPath
* entry2
= (CTGitPath
* )GetItemData(index
);
1868 ASSERT(entry2
!= NULL
);
1869 if (entry2
== NULL
|| entry2
->IsDirectory())
1871 if (m_restorepaths
.find(entry2
->GetWinPathString()) != m_restorepaths
.end())
1873 CTGitPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
1874 if (CopyFile(g_Git
.m_CurrentDir
+ _T("\\") + entry2
->GetWinPathString(), tempFile
.GetWinPath(), FALSE
))
1876 m_restorepaths
[entry2
->GetWinPathString()] = tempFile
.GetWinPathString();
1877 SetItemState(index
, INDEXTOOVERLAYMASK(OVL_RESTORE
), LVIS_OVERLAYMASK
);
1883 case IDGITLC_RESTOREPATH
:
1885 if (CMessageBox::Show(m_hWnd
, IDS_STATUSLIST_RESTOREPATH
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_RESTOREBUTTON
, IDS_ABORTBUTTON
) == 2)
1887 POSITION pos
= GetFirstSelectedItemPosition();
1890 int index
= GetNextSelectedItem(pos
);
1891 CTGitPath
* entry2
= (CTGitPath
* )GetItemData(index
);
1892 ASSERT(entry2
!= NULL
);
1895 if (m_restorepaths
.find(entry2
->GetWinPathString()) == m_restorepaths
.end())
1897 if (CopyFile(m_restorepaths
[entry2
->GetWinPathString()], g_Git
.m_CurrentDir
+ _T("\\") + entry2
->GetWinPathString(), FALSE
))
1899 m_restorepaths
.erase(entry2
->GetWinPathString());
1900 SetItemState(index
, 0, LVIS_OVERLAYMASK
);
1906 // Compare current version and work copy.
1907 case IDGITLC_COMPAREWC
:
1909 POSITION pos
= GetFirstSelectedItemPosition();
1912 int index
= GetNextSelectedItem(pos
);
1917 // Compare with base version. when current version is zero, compare workcopy and HEAD.
1918 case IDGITLC_COMPARE
:
1920 POSITION pos
= GetFirstSelectedItemPosition();
1923 int index
= GetNextSelectedItem(pos
);
1928 case IDGITLC_COMPARETWO
:
1930 POSITION pos
= GetFirstSelectedItemPosition();
1933 int index
= GetNextSelectedItem(pos
);
1934 StartDiffTwo(index
);
1938 case IDGITLC_COMPARETWOFILES
:
1940 POSITION pos
= GetFirstSelectedItemPosition();
1941 CTGitPath
* firstfilepath
= NULL
, * secondfilepath
= NULL
;
1944 firstfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
1945 ASSERT(firstfilepath
!= NULL
);
1946 if (firstfilepath
== NULL
)
1949 secondfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
1950 ASSERT(secondfilepath
!= NULL
);
1951 if (secondfilepath
== NULL
)
1955 sCmd
.Format(_T("/command:diff /path:\"%s\" /path2:\"%s\" /hwnd:%ld"), firstfilepath
->GetWinPath(), secondfilepath
->GetWinPath(), (unsigned long)m_hWnd
);
1956 CAppUtils::RunTortoiseProc(sCmd
);
1960 case IDGITLC_GNUDIFF1
:
1962 // SVNDiff diff(NULL, this->m_hWnd, true);
1964 // if (entry->remotestatus <= git_wc_status_normal)
1965 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
1967 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
1968 if(m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
1972 fromwhere
= _T("~1");
1973 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,GitRev::GetHead()+fromwhere
,
1974 *filepath
,GitRev::GetWorkingCopy());
1978 if((filepath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
)) ==0)
1979 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_CurrentVersion
+_T("~1"),
1980 *filepath
,m_CurrentVersion
);
1984 if(filepath
->m_ParentNo
& MERGE_MASK
)
1989 str
.Format(_T("%s^%d"),m_CurrentVersion
,(filepath
->m_ParentNo
&PARENT_MASK
)+1);
1992 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
, str
,
1993 *filepath
, m_CurrentVersion
, false, false, false,
1994 !!(filepath
->m_ParentNo
& MERGE_MASK
));
1999 case IDGITLC_GNUDIFF2
:
2001 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *filepath
, m_Rev2
, *filepath
, m_Rev1
);
2006 { // The add went ok, but we now need to run through the selected items again
2007 // and update their status
2008 std::vector
<int> selectIndex
;
2010 POSITION pos
= GetFirstSelectedItemPosition();
2012 CMassiveGitTask
mgt(L
"add -f");
2013 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2015 CTGitPath
* path
= (CTGitPath
*)GetItemData(index
);
2020 selectIndex
.push_back(index
);
2023 BOOL cancel
= FALSE
;
2024 mgt
.Execute(cancel
);
2026 if (NULL
!= GetParent() && NULL
!= GetParent()->GetSafeHwnd())
2027 GetParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2033 case IDGITLC_DELETE
:
2036 std::vector
<int> selectIndex
;
2038 POSITION pos
= GetFirstSelectedItemPosition();
2040 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2042 selectIndex
.push_back(index
);
2045 //Create file-list ('\0' separated) for SHFileOperation
2047 for(int i
=0;i
<selectIndex
.size();i
++)
2049 index
=selectIndex
[i
];
2051 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2056 filelist
+= path
->GetWinPathString();
2057 filelist
+= _T("|");
2059 filelist
+= _T("|");
2060 int len
= filelist
.GetLength();
2061 TCHAR
* buf
= new TCHAR
[len
+2];
2062 _tcscpy_s(buf
, len
+2, filelist
);
2063 for (int i
=0; i
<len
; ++i
)
2066 SHFILEOPSTRUCT fileop
;
2067 fileop
.hwnd
= this->m_hWnd
;
2068 fileop
.wFunc
= FO_DELETE
;
2071 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
2072 fileop
.lpszProgressTitle
= _T("deleting file");
2073 int result
= SHFileOperation(&fileop
);
2076 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
2079 POSITION pos
= NULL
;
2080 while ((pos
= GetFirstSelectedItemPosition()) != 0)
2082 int index
= GetNextSelectedItem(pos
);
2083 if (GetCheck(index
))
2087 RemoveListEntry(index
);
2096 CAppUtils::LaunchTortoiseBlame(g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath(), m_CurrentVersion
);
2103 sCmd
.Format(_T("/command:log /path:\"%s\""), g_Git
.m_CurrentDir
+ _T("\\") + filepath
->GetWinPath());
2104 CAppUtils::RunTortoiseProc(sCmd
);
2108 case IDGITLC_LOGOLDNAME
:
2110 CTGitPath
oldName(filepath
->GetGitOldPathString());
2112 sCmd
.Format(_T("/command:log /path:\"%s\""), g_Git
.m_CurrentDir
+ _T("\\") + oldName
.GetWinPath());
2113 CAppUtils::RunTortoiseProc(sCmd
);
2118 case IDGITLC_EDITCONFLICT
:
2120 CAppUtils::ConflictEdit(*filepath
,false,this->m_bIsRevertTheirMy
);
2123 case IDGITLC_RESOLVETHEIRS
: //follow up
2124 case IDGITLC_RESOLVEMINE
: //follow up
2125 case IDGITLC_RESOLVECONFLICT
:
2127 if (CMessageBox::Show(m_hWnd
, IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
)==IDYES
)
2129 POSITION pos
= GetFirstSelectedItemPosition();
2133 index
= GetNextSelectedItem(pos
);
2134 CTGitPath
* fentry
=(CTGitPath
*) this->GetItemData(index
);
2137 CString gitcmd
,output
;
2140 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVETHEIRS
) ||
2141 ((this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVEMINE
) )
2143 gitcmd
.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry
->GetGitPathString());
2144 if (g_Git
.Run(gitcmd
, &output
,CP_UTF8
))
2146 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2151 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVEMINE
) ||
2152 ((this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVETHEIRS
) )
2154 gitcmd
.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry
->GetGitPathString());
2155 if (g_Git
.Run(gitcmd
, &output
,CP_UTF8
))
2157 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2163 if ( fentry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
2165 gitcmd
.Format(_T("git.exe add -f -- \"%s\""),fentry
->GetGitPathString());
2166 if (g_Git
.Run(gitcmd
, &output
,CP_UTF8
))
2168 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2172 fentry
->m_Action
|= CTGitPath::LOGACTIONS_MODIFIED
;
2173 fentry
->m_Action
&=~CTGitPath::LOGACTIONS_UNMERGED
;
2177 CAppUtils::RemoveTempMergeFile(*fentry
);
2180 Show(m_dwShow
, 0, m_bShowFolders
,0,true);
2185 case IDGITLC_IGNORE
:
2187 CTGitPathList ignorelist
;
2188 //std::vector<CString> toremove;
2189 FillListOfSelectedItemPaths(ignorelist
, true);
2192 if(!CAppUtils::IgnoreFile(ignorelist
,false))
2195 for(int i
=0;i
<ignorelist
.GetCount();i
++)
2197 int nListboxEntries
= GetItemCount();
2198 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2200 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2201 if (path
->GetGitPathString()==ignorelist
[i
].GetGitPathString())
2203 RemoveListEntry(nItem
);
2211 case IDGITLC_IGNOREMASK
:
2214 CString ext
=filepath
->GetFileExtension();
2215 CTGitPathList ignorelist
;
2216 FillListOfSelectedItemPaths(ignorelist
, true);
2219 CAppUtils::IgnoreFile(ignorelist
,true);
2221 common
=ignorelist
.GetCommonRoot().GetGitPathString();
2223 for (int i
=0; i
< GetItemCount(); ++i
)
2225 CTGitPath
*path
=(CTGitPath
*)GetItemData(i
);
2226 if(!( path
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
2228 if( path
->GetGitPathString().Left(common
.GetLength()) == common
)
2230 if (path
->GetFileExtension()==ext
)
2233 i
--; // remove index i at item, new one will replace.
2238 CWnd
* pParent
= GetParent();
2239 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2241 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2248 case IDGITLC_REVERT
:
2250 // If at least one item is not in the status "added"
2251 // we ask for a confirmation
2252 BOOL bConfirm
= FALSE
;
2253 POSITION pos
= GetFirstSelectedItemPosition();
2255 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2257 //FileEntry * fentry = GetListEntry(index);
2258 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
2259 if(fentry
&& fentry
->m_Action
&CTGitPath::LOGACTIONS_MODIFIED
&& !fentry
->IsDirectory())
2267 str
.Format(IDS_PROC_WARNREVERT
,GetSelectedCount());
2269 if (!bConfirm
|| CMessageBox::Show(this->m_hWnd
, str
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
2271 CTGitPathList targetList
;
2272 FillListOfSelectedItemPaths(targetList
);
2274 // make sure that the list is reverse sorted, so that
2275 // children are removed before any parents
2276 targetList
.SortByPathname(true);
2278 // put all reverted files in the trashbin, except the ones with 'added'
2279 // status because they are not restored by the revert.
2280 CTGitPathList delList
;
2281 POSITION pos
= GetFirstSelectedItemPosition();
2283 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2285 CTGitPath
*entry
=(CTGitPath
*)GetItemData(index
);
2286 if (entry
&&(!(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
))
2287 && (!(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)) && !entry
->IsDirectory())
2290 fullpath
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+entry
->GetWinPath());
2291 delList
.AddPath(fullpath
);
2294 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
2295 delList
.DeleteAllFiles(true);
2297 CString revertToCommit
= _T("HEAD");
2299 revertToCommit
= _T("HEAD~1");
2300 if (g_Git
.Revert(revertToCommit
, targetList
))
2302 CMessageBox::Show(this->m_hWnd
, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR
);
2306 bool updateStatusList
= false;
2307 for(int i
=0;i
<targetList
.GetCount();i
++)
2309 int nListboxEntries
= GetItemCount();
2310 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2312 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2313 if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && !path
->IsDirectory())
2315 if(path
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2317 path
->m_Action
= CTGitPath::LOGACTIONS_UNVER
;
2318 SetEntryCheck(path
,nItem
,false);
2319 updateStatusList
= true;
2320 SetItemGroup(nItem
,1);
2321 this->m_StatusFileList
.RemoveItem(*path
);
2322 this->m_UnRevFileList
.AddPath(*path
);
2323 //this->m_IgnoreFileList.RemoveItem(*path);
2328 RemoveListEntry(nItem
);
2332 else if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && path
->IsDirectory() && path
->IsWCRoot())
2335 sCmd
.Format(_T("/command:revert /path:\"%s\""), path
->GetGitPathString());
2336 CCommonAppUtils::RunTortoiseProc(sCmd
);
2342 Show(m_dwShow
, 0, m_bShowFolders
,updateStatusList
,true);
2349 case IDGITLC_ASSUMEVALID
:
2351 CString cmdTemplate
;
2352 cmdTemplate
= _T("git.exe update-index --assume-unchanged \"%s\"");
2353 POSITION pos
= GetFirstSelectedItemPosition();
2355 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2357 CTGitPath
* path
= (CTGitPath
*)GetItemData(index
);
2362 CString cmd
, output
;
2363 cmd
.Format(cmdTemplate
, path
->GetGitPathString());
2364 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
2366 MessageBox(output
, _T("TortoiseGit"), MB_ICONERROR
);
2369 if (NULL
!= GetParent() && NULL
!= GetParent()->GetSafeHwnd())
2370 GetParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2377 CopySelectedEntriesToClipboard(0);
2379 case IDGITLC_COPYEXT
:
2380 CopySelectedEntriesToClipboard((DWORD
)-1);
2383 case IDGITLC_SAVEAS
:
2384 FileSaveAs(filepath
);
2387 case IDGITLC_REVERTTOREV
:
2388 RevertSelectedItemToVersion();
2391 case IDSVNLC_COMMIT
:
2393 CTSVNPathList targetList
;
2394 FillListOfSelectedItemPaths(targetList
);
2395 CTSVNPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2396 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2397 CString commandline
= CPathUtils::GetAppDirectory();
2398 commandline
+= _T("TortoiseProc.exe /command:commit /pathfile:\"");
2399 commandline
+= tempFile
.GetWinPathString();
2400 commandline
+= _T("\"");
2401 commandline
+= _T(" /deletepathfile");
2402 CAppUtils::LaunchApplication(commandline
, NULL
, false);
2405 case IDSVNLC_CREATEIGNORECS
:
2406 CreateChangeList(SVNSLC_IGNORECHANGELIST
);
2408 case IDSVNLC_CREATECS
:
2410 CCreateChangelistDlg dlg
;
2411 if (dlg
.DoModal() == IDOK
)
2413 CreateChangeList(dlg
.m_sName
);
2419 if (cmd
< IDSVNLC_MOVETOCS
)
2421 CTSVNPathList changelistItems
;
2422 FillListOfSelectedItemPaths(changelistItems
);
2424 // find the changelist name
2425 CString sChangelist
;
2426 int cmdID
= IDSVNLC_MOVETOCS
;
2428 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
2430 if ((it
->first
.Compare(SVNSLC_IGNORECHANGELIST
))&&(entry
->changelist
.Compare(it
->first
)))
2434 sChangelist
= it
->first
;
2439 if (!sChangelist
.IsEmpty())
2442 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
2444 // The changelists were moved, but we now need to run through the selected items again
2445 // and update their changelist
2446 POSITION pos
= GetFirstSelectedItemPosition();
2448 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2450 FileEntry
* e
= GetListEntry(index
);
2451 e
->changelist
= sChangelist
;
2454 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
2455 SetItemGroup(index
, m_changelists
[e
->changelist
]);
2457 SetItemGroup(index
, 0);
2463 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
2473 AfxGetApp()->DoWaitCursor(-1);
2474 GetStatisticsString();
2475 //int iItemCountAfterMenuCmd = GetItemCount();
2476 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
2478 // CWnd* pParent = GetParent();
2479 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2481 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
2484 } // if (popup.CreatePopupMenu())
2485 } // if (selIndex >= 0)
2489 void CGitStatusListCtrl::OnContextMenuHeader(CWnd
* pWnd
, CPoint point
)
2491 Locker
lock(m_critSec
);
2492 m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
2495 void CGitStatusListCtrl::OnContextMenu(CWnd
* pWnd
, CPoint point
)
2500 OnContextMenuList(pWnd
, point
);
2501 } // if (pWnd == this)
2502 else if (pWnd
== GetHeaderCtrl())
2504 OnContextMenuHeader(pWnd
, point
);
2508 void CGitStatusListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2511 Locker
lock(m_critSec
);
2512 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
2517 if (pNMLV
->iItem
< 0)
2519 if (!IsGroupViewEnabled())
2522 DWORD ptW
= GetMessagePos();
2523 pt
.x
= GET_X_LPARAM(ptW
);
2524 pt
.y
= GET_Y_LPARAM(ptW
);
2525 ScreenToClient(&pt
);
2526 int group
= GetGroupFromPoint(&pt
);
2529 // check/uncheck the whole group depending on the check-state
2530 // of the first item in the group
2532 bool bCheck
= false;
2533 bool bFirst
= false;
2535 for (int i
=0; i
<GetItemCount(); ++i
)
2537 SecureZeroMemory(&lv
, sizeof(LVITEM
));
2538 lv
.mask
= LVIF_GROUPID
;
2541 if (lv
.iGroupId
== group
)
2543 CTGitPath
*entry
=(CTGitPath
*)GetItemData(i
);
2547 bCheck
= !GetCheck(i
);
2552 bool bOldCheck
= !!GetCheck(i
);
2553 SetEntryCheck(entry
, i
, bCheck
);
2554 if (bCheck
!= bOldCheck
)
2564 GetStatisticsString();
2570 CTGitPath
*file
=(CTGitPath
*)GetItemData(pNMLV
->iItem
);
2572 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
) {
2573 OpenFile(file
, OPEN
);
2576 if( file
->m_Action
&CTGitPath::LOGACTIONS_UNMERGED
)
2578 CAppUtils::ConflictEdit(*file
,false,m_bIsRevertTheirMy
);
2583 if( (!m_Rev1
.IsEmpty()) || (!m_Rev1
.IsEmpty())) // m_Rev1 twice???
2584 StartDiffTwo(pNMLV
->iItem
);
2586 StartDiff(pNMLV
->iItem
);
2590 void CGitStatusListCtrl::StartDiffTwo(int fileindex
)
2595 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
2597 CGitDiff::Diff(&file1
,&file1
,
2602 void CGitStatusListCtrl::StartDiffWC(int fileindex
)
2608 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2611 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
2613 CGitDiff::Diff(&file1
,&file1
, GIT_REV_ZERO
, m_CurrentVersion
);
2617 void CGitStatusListCtrl::StartDiff(int fileindex
)
2622 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
2624 if(file1
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
2626 file2
.SetFromGit(file1
.GetGitOldPathString());
2633 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2636 if(m_amend
&& (file1
.m_Action
& CTGitPath::LOGACTIONS_ADDED
) == 0)
2637 fromwhere
= _T("~1");
2638 if( g_Git
.IsInitRepos())
2639 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2641 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_ADDED
)
2642 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2643 m_CurrentVersion
+fromwhere
,true);
2644 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_DELETED
)
2645 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2646 GitRev::GetHead()+fromwhere
,false);
2648 CGitDiff::Diff(&file1
,&file2
,
2649 CString(GIT_REV_ZERO
),
2650 GitRev::GetHead()+fromwhere
);
2655 CString fromwhere
= m_CurrentVersion
+_T("~1");
2657 fromwhere
= m_CurrentVersion
+_T("~2");
2658 if(rev
.GetCommit(fromwhere
) || (file1
.m_Action
== file1
.LOGACTIONS_ADDED
))
2660 CGitDiff::DiffNull(&file1
,m_CurrentVersion
,true);
2663 else if (file1
.m_Action
== file1
.LOGACTIONS_DELETED
)
2665 if (file1
.m_ParentNo
> 0)
2666 fromwhere
.Format(_T("%s^%d"), m_CurrentVersion
, file1
.m_ParentNo
+ 1);
2668 CGitDiff::DiffNull(&file1
,fromwhere
,false);
2672 if( file1
.m_ParentNo
& MERGE_MASK
)
2675 CTGitPath base
, theirs
, mine
, merge
;
2678 GetTempPath(temppath
);
2679 temppath
.TrimRight(_T("\\"));
2681 mine
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".LOCAL") + file1
.GetFileExtension());
2682 theirs
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".REMOTE") + file1
.GetFileExtension());
2683 base
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".BASE") + file1
.GetFileExtension());
2686 //create a empty file, incase stage is not three
2687 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2689 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2691 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2694 merge
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".Merged") + file1
.GetFileExtension());
2696 int parent1
=-1, parent2
=-1;
2697 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
2699 if(m_arStatusArray
[i
]->GetGitPathString() == file1
.GetGitPathString())
2701 if(m_arStatusArray
[i
]->m_ParentNo
& MERGE_MASK
)
2708 parent1
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2710 else if (parent2
<0)
2712 parent2
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2718 if(g_Git
.GetOneFile(m_CurrentVersion
, file1
, (CString
&)merge
.GetWinPathString()))
2720 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2726 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent1
+1);
2728 if(g_Git
.GetOneFile(str
, file1
, (CString
&)mine
.GetWinPathString()))
2730 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2737 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent2
+1);
2739 if(g_Git
.GetOneFile(str
, file1
, (CString
&)theirs
.GetWinPathString()))
2741 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2745 if(parent1
>=0 && parent2
>=0)
2747 CString cmd
, output
;
2748 cmd
.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion
, parent1
+1,
2749 this->m_CurrentVersion
,parent2
+1);
2751 if (g_Git
.Run(cmd
, &output
, NULL
, CP_UTF8
))
2756 if(g_Git
.GetOneFile(output
.Left(40), file1
, (CString
&)base
.GetWinPathString()))
2758 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETBASEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2762 CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
2768 if( (file1
.m_ParentNo
&PARENT_MASK
) == 0)
2774 str
.Format(_T("^%d"), (file1
.m_ParentNo
&PARENT_MASK
)+1);
2776 CGitDiff::Diff(&file1
,&file2
,
2778 m_CurrentVersion
+str
);
2784 CString
CGitStatusListCtrl::GetStatisticsString(bool simple
)
2787 CString sNormal
, sAdded
, sDeleted
, sModified
, sConflicted
, sUnversioned
, sRenamed
;
2788 WORD langID
= (WORD
)(DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
2789 TCHAR buf
[MAX_STATUS_STRING_LENGTH
];
2790 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal
, buf
, _countof(buf
), langID
);
2792 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added
, buf
, _countof(buf
), langID
);
2794 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted
, buf
, _countof(buf
), langID
);
2796 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified
, buf
, _countof(buf
), langID
);
2798 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted
, buf
, _countof(buf
), langID
);
2800 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned
, buf
, _countof(buf
), langID
);
2802 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced
, buf
, _countof(buf
), langID
);
2807 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE1
,
2808 this->m_nLineAdded
,this->m_nLineDeleted
,
2809 (LPCTSTR
)sModified
, m_nModified
,
2810 (LPCTSTR
)sAdded
, m_nAdded
,
2811 (LPCTSTR
)sDeleted
, m_nDeleted
,
2812 (LPCTSTR
)sRenamed
, m_nRenamed
2817 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE2
,
2818 this->m_nLineAdded
,this->m_nLineDeleted
,
2819 (LPCTSTR
)sNormal
, m_nNormal
,
2820 (LPCTSTR
)sUnversioned
, m_nUnversioned
,
2821 (LPCTSTR
)sModified
, m_nModified
,
2822 (LPCTSTR
)sAdded
, m_nAdded
,
2823 (LPCTSTR
)sDeleted
, m_nDeleted
,
2824 (LPCTSTR
)sConflicted
, m_nConflicted
2828 sStats
.Format(IDS_COMMITDLG_STATISTICSFORMAT
, m_nSelected
, GetItemCount());
2831 m_pStatLabel
->SetWindowText(sStats
);
2834 if (m_pSelectButton
)
2836 if (m_nSelected
== 0)
2837 m_pSelectButton
->SetCheck(BST_UNCHECKED
);
2838 else if (m_nSelected
!= GetItemCount())
2839 m_pSelectButton
->SetCheck(BST_INDETERMINATE
);
2841 m_pSelectButton
->SetCheck(BST_CHECKED
);
2844 if (m_pConfirmButton
)
2846 m_pConfirmButton
->EnableWindow(m_nSelected
>0);
2854 CString
CGitStatusListCtrl::GetCommonDirectory(bool bStrict
)
2858 // not strict means that the selected folder has priority
2859 if (!m_StatusFileList
.GetCommonDirectory().IsEmpty())
2860 return m_StatusFileList
.GetCommonDirectory().GetWinPath();
2863 CTGitPath commonBaseDirectory
;
2864 int nListItems
= GetItemCount();
2865 for (int i
=0; i
<nListItems
; ++i
)
2867 CTGitPath baseDirectory
,*p
= (CTGitPath
*)this->GetItemData(i
);
2871 baseDirectory
= p
->GetDirectory();
2873 if(commonBaseDirectory
.IsEmpty())
2875 commonBaseDirectory
= baseDirectory
;
2879 if (commonBaseDirectory
.GetWinPathString().GetLength() > baseDirectory
.GetWinPathString().GetLength())
2881 if (baseDirectory
.IsAncestorOf(commonBaseDirectory
))
2882 commonBaseDirectory
= baseDirectory
;
2886 return g_Git
.m_CurrentDir
+CString(_T("\\"))+commonBaseDirectory
.GetWinPath();
2890 void CGitStatusListCtrl::SelectAll(bool bSelect
, bool /*bIncludeNoCommits*/)
2892 CWaitCursor waitCursor
;
2893 // block here so the LVN_ITEMCHANGED messages
2898 int nListItems
= GetItemCount();
2900 m_nSelected
= nListItems
;
2904 for (int i
=0; i
<nListItems
; ++i
)
2906 //FileEntry * entry = GetListEntry(i);
2907 //ASSERT(entry != NULL);
2908 CTGitPath
*path
= (CTGitPath
*) GetItemData(i
);
2911 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
2912 SetEntryCheck(path
,i
,bSelect
);
2915 // unblock before redrawing
2918 GetStatisticsString();
2922 void CGitStatusListCtrl::Check(DWORD dwCheck
, bool uncheckNonMatches
)
2924 CWaitCursor waitCursor
;
2925 // block here so the LVN_ITEMCHANGED messages
2930 int nListItems
= GetItemCount();
2933 for (int i
= 0; i
< nListItems
; ++i
)
2935 CTGitPath
*entry
= (CTGitPath
*) GetItemData(i
);
2939 DWORD showFlags
= entry
->m_Action
;
2940 if (entry
->IsDirectory())
2941 showFlags
|= GITSLC_SHOWSUBMODULES
;
2943 showFlags
|= GITSLC_SHOWFILES
;
2945 if (showFlags
& dwCheck
&& !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
&& !(dwCheck
& GITSLC_SHOWSUBMODULES
)))
2947 SetEntryCheck(entry
, i
, true);
2950 else if (uncheckNonMatches
)
2951 SetEntryCheck(entry
, i
, false);
2953 // unblock before redrawing
2956 GetStatisticsString();
2960 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2962 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
2967 CTGitPath
*entry
=(CTGitPath
*)GetItemData(pGetInfoTip
->iItem
);
2970 if (pGetInfoTip
->cchTextMax
> entry
->GetGitPathString().GetLength() + g_Git
.m_CurrentDir
.GetLength())
2973 str
+= g_Git
.m_CurrentDir
;
2975 str
+= entry
->GetWinPathString();
2977 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, str
.GetBuffer(), str
.GetLength());
2981 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2983 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
2985 // Take the default processing unless we set this to something else below.
2986 *pResult
= CDRF_DODEFAULT
;
2988 // First thing - check the draw stage. If it's the control's prepaint
2989 // stage, then tell Windows we want messages for every item.
2991 switch (pLVCD
->nmcd
.dwDrawStage
)
2994 *pResult
= CDRF_NOTIFYITEMDRAW
;
2996 case CDDS_ITEMPREPAINT
:
2998 // This is the prepaint stage for an item. Here's where we set the
2999 // item's text color. Our return value will tell Windows to draw the
3000 // item itself, but it will use the new color we set here.
3002 // Tell Windows to paint the control itself.
3003 *pResult
= CDRF_DODEFAULT
;
3007 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
3009 if (m_arStatusArray
.size() > (DWORD_PTR
)pLVCD
->nmcd
.dwItemSpec
)
3012 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3013 CTGitPath
*entry
=(CTGitPath
*)GetItemData((int)pLVCD
->nmcd
.dwItemSpec
);
3019 // black : unversioned, normal
3022 // brown : missing, deleted, replaced
3023 // green : merged (or potential merges)
3024 // red : conflicts or sure conflicts
3025 if(entry
->m_Action
& CTGitPath::LOGACTIONS_GRAY
)
3027 crText
= RGB(128,128,128);
3030 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
3032 crText
= m_Colors
.GetColor(CColors::Conflict
);
3035 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_MODIFIED
))
3037 crText
= m_Colors
.GetColor(CColors::Modified
);
3040 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
3042 crText
= m_Colors
.GetColor(CColors::Added
);
3044 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3046 crText
= m_Colors
.GetColor(CColors::DeletedNode
);
3048 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
3050 crText
= m_Colors
.GetColor(CColors::RenamedNode
);
3052 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_MERGED
)
3054 crText
= m_Colors
.GetColor(CColors::Merged
);
3058 crText
= GetSysColor(COLOR_WINDOWTEXT
);
3060 // Store the color back in the NMLVCUSTOMDRAW struct.
3061 pLVCD
->clrText
= crText
;
3068 BOOL
CGitStatusListCtrl::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
3071 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3074 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
3076 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3078 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_WAIT
));
3083 void CGitStatusListCtrl::RemoveListEntry(int index
)
3086 Locker
lock(m_critSec
);
3089 m_arStatusArray
.erase(m_arStatusArray
.begin()+index
);
3092 delete m_arStatusArray
[m_arListArray
[index
]];
3093 m_arStatusArray
.erase(m_arStatusArray
.begin()+m_arListArray
[index
]);
3094 m_arListArray
.erase(m_arListArray
.begin()+index
);
3095 for (int i
=index
; i
< (int)m_arListArray
.size(); ++i
)
3102 ///< Set a checkbox on an entry in the listbox
3103 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
3104 void CGitStatusListCtrl::SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
)
3106 pEntry
->m_Checked
= bCheck
;
3107 m_mapFilenameToChecked
[pEntry
->GetGitPathString()] = bCheck
;
3108 SetCheck(listboxIndex
, bCheck
);
3112 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry
* parentEntry
, bool bCheck
)
3115 int nListItems
= GetItemCount();
3116 for (int j
=0; j
< nListItems
; ++j
)
3118 FileEntry
* childEntry
= GetListEntry(j
);
3119 ASSERT(childEntry
!= NULL
);
3120 if (childEntry
== NULL
|| childEntry
== parentEntry
)
3122 if (childEntry
->checked
!= bCheck
)
3124 if (parentEntry
->path
.IsAncestorOf(childEntry
->path
))
3126 SetEntryCheck(childEntry
,j
,bCheck
);
3142 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList
& pathList
)
3146 int nListItems
= GetItemCount();
3147 for (int i
=0; i
< nListItems
; i
++)
3149 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
3150 ASSERT(entry
!= NULL
);
3151 if (entry
->m_Checked
)
3153 pathList
.AddPath(*entry
);
3156 pathList
.SortByPathname();
3161 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
3162 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool /*bNoIgnored*/)
3166 POSITION pos
= GetFirstSelectedItemPosition();
3168 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3170 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
3171 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
3173 pathList
.AddPath(*entry
);
3177 UINT
CGitStatusListCtrl::OnGetDlgCode()
3179 // we want to process the return key and not have that one
3180 // routed to the default pushbutton
3181 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS
;
3184 void CGitStatusListCtrl::OnNMReturn(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
3189 POSITION pos
= GetFirstSelectedItemPosition();
3192 int index
= GetNextSelectedItem(pos
);
3193 CTGitPath
*file
=(CTGitPath
*)GetItemData(index
);
3194 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
)
3196 OpenFile(file
, OPEN
);
3205 void CGitStatusListCtrl::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
3207 // Since we catch all keystrokes (to have the enter key processed here instead
3208 // of routed to the default pushbutton) we have to make sure that other
3209 // keys like Tab and Esc still do what they're supposed to do
3210 // Tab = change focus to next/previous control
3211 // Esc = quit the dialog
3216 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL
, GetKeyState(VK_SHIFT
)&0x8000, 0);
3222 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE
, 0, 0);
3227 CListCtrl::OnKeyDown(nChar
, nRepCnt
, nFlags
);
3230 void CGitStatusListCtrl::PreSubclassWindow()
3232 CListCtrl::PreSubclassWindow();
3233 EnableToolTips(TRUE
);
3234 SetWindowTheme(GetSafeHwnd(), L
"Explorer", NULL
);
3237 INT_PTR
CGitStatusListCtrl::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
3241 row
= CellRectFromPoint(point
, &cellrect
, &col
);
3248 pTI
->uId
= (UINT
)((row
<<10)+(col
&0x3ff)+1);
3249 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
3251 pTI
->rect
= cellrect
;
3256 int CGitStatusListCtrl::CellRectFromPoint(CPoint
& point
, RECT
*cellrect
, int *col
) const
3260 // Make sure that the ListView is in LVS_REPORT
3261 if ((GetWindowLong(m_hWnd
, GWL_STYLE
) & LVS_TYPEMASK
) != LVS_REPORT
)
3264 // Get the top and bottom row visible
3265 int row
= GetTopIndex();
3266 int bottom
= row
+ GetCountPerPage();
3267 if (bottom
> GetItemCount())
3268 bottom
= GetItemCount();
3270 // Get the number of columns
3271 CHeaderCtrl
* pHeader
= (CHeaderCtrl
*)GetDlgItem(0);
3272 int nColumnCount
= pHeader
->GetItemCount();
3274 // Loop through the visible rows
3275 for ( ;row
<=bottom
;row
++)
3277 // Get bounding rect of item and check whether point falls in it.
3279 GetItemRect(row
, &rect
, LVIR_BOUNDS
);
3280 if (rect
.PtInRect(point
))
3282 // Now find the column
3283 for (colnum
= 0; colnum
< nColumnCount
; colnum
++)
3285 int colwidth
= GetColumnWidth(colnum
);
3286 if (point
.x
>= rect
.left
&& point
.x
<= (rect
.left
+ colwidth
))
3289 GetClientRect(&rectClient
);
3292 rect
.right
= rect
.left
+ colwidth
;
3294 // Make sure that the right extent does not exceed
3296 if (rect
.right
> rectClient
.right
)
3297 rect
.right
= rectClient
.right
;
3301 rect
.left
+= colwidth
;
3308 void CGitStatusListCtrl::OnPaint()
3311 if ((m_bBusy
)||(m_bEmpty
))
3316 if (m_sBusy
.IsEmpty())
3317 str
.LoadString(IDS_STATUSLIST_BUSYMSG
);
3323 if (m_sEmpty
.IsEmpty())
3324 str
.LoadString(IDS_STATUSLIST_EMPTYMSG
);
3328 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
3330 if (IsWindowEnabled())
3331 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
3333 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
3338 pHC
= GetHeaderCtrl();
3342 pHC
->GetItemRect(0, &rcH
);
3343 rc
.top
+= rcH
.bottom
;
3347 CMyMemDC
memDC(pDC
, &rc
);
3349 memDC
.SetTextColor(clrText
);
3350 memDC
.SetBkColor(clrTextBk
);
3351 memDC
.FillSolidRect(rc
, clrTextBk
);
3353 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
3354 memDC
.DrawText(str
, rc
, DT_CENTER
| DT_VCENTER
|
3355 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
3356 memDC
.SelectObject(oldfont
);
3362 // prevent users from extending our hidden (size 0) columns
3363 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3365 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3368 // prevent any function from extending our hidden (size 0) columns
3369 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3371 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3375 void CGitStatusListCtrl::OnDestroy()
3377 SaveColumnWidths(true);
3378 CListCtrl::OnDestroy();
3381 void CGitStatusListCtrl::OnBeginDrag(NMHDR
* /*pNMHDR*/, LRESULT
* pResult
)
3384 Locker
lock(m_critSec
);
3385 CDropFiles dropFiles
; // class for creating DROPFILES struct
3388 POSITION pos
= GetFirstSelectedItemPosition();
3389 while ( (index
= GetNextSelectedItem(pos
)) >= 0 )
3391 FileEntry
* fentry
= m_arStatusArray
[m_arListArray
[index
]];
3392 CTGitPath path
= fentry
->GetPath();
3393 dropFiles
.AddFile( path
.GetWinPathString() );
3396 if ( dropFiles
.GetCount()>0 )
3399 dropFiles
.CreateStructure();
3406 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry
/* = false */)
3408 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
3409 for (int col
= 0; col
<= maxcol
; col
++)
3410 if (m_ColumnManager
.IsVisible (col
))
3411 m_ColumnManager
.ColumnResized (col
);
3413 if (bSaveToRegistry
)
3414 m_ColumnManager
.WriteSettings();
3417 bool CGitStatusListCtrl::EnableFileDrop()
3419 m_bFileDropsEnabled
= true;
3423 bool CGitStatusListCtrl::HasPath(const CTGitPath
& path
)
3425 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
3427 if (m_arStatusArray
[i
]->IsEquivalentTo(path
))
3434 BOOL
CGitStatusListCtrl::PreTranslateMessage(MSG
* pMsg
)
3436 if (pMsg
->message
== WM_KEYDOWN
)
3438 switch (pMsg
->wParam
)
3442 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3444 // select all entries
3445 for (int i
=0; i
<GetItemCount(); ++i
)
3447 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3456 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3458 // copy all selected paths to the clipboard
3459 if (GetAsyncKeyState(VK_SHIFT
)&0x8000)
3460 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS
);
3462 CopySelectedEntriesToClipboard(0);
3470 return CListCtrl::PreTranslateMessage(pMsg
);
3473 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols
)
3476 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
3477 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3482 if (GetSelectedCount() == 0)
3485 // first add the column titles as the first line
3486 // We needn't head when only path copy
3487 //temp.LoadString(IDS_STATUSLIST_COLFILE);
3488 //sClipboard = temp;
3490 DWORD selection
= 0;
3491 for (int i
= 0, count
= m_ColumnManager
.GetColumnCount(); i
< count
; ++i
)
3492 if ( ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
3493 || ((dwCols
!= 1) && (i
< 32) && ((dwCols
& (1 << i
)) != 0)))
3495 sClipboard
+= _T("\t") + m_ColumnManager
.GetName(i
);
3498 selection
+= 1 << i
;
3502 sClipboard
+= _T("\r\n");
3504 POSITION pos
= GetFirstSelectedItemPosition();
3506 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3508 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
3512 sClipboard
+= entry
->GetWinPathString();
3513 if (selection
& GITSLC_COLFILENAME
)
3515 sClipboard
+= _T("\t")+entry
->GetFileOrDirectoryName();
3517 if (selection
& GITSLC_COLEXT
)
3519 sClipboard
+= _T("\t")+entry
->GetFileExtension();
3522 if (selection
& GITSLC_COLSTATUS
)
3524 sClipboard
+= _T("\t")+entry
->GetActionName();
3527 if (selection
& SVNSLC_COLDATE
)
3529 TCHAR datebuf
[SVN_DATE_BUFFER
];
3530 apr_time_t date
= entry
->last_commit_date
;
3531 SVN::formatDate(datebuf
, date
, true);
3536 sClipboard
+= _T("\t")+temp
;
3538 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
3542 if ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
3545 = entry
->present_props
[m_ColumnManager
.GetName(i
)];
3546 sClipboard
+= _T("\t") + value
;
3550 if (selection
& GITSLC_COLADD
)
3552 sClipboard
+= _T("\t")+entry
->m_StatAdd
;
3554 if (selection
& GITSLC_COLDEL
)
3556 sClipboard
+= _T("\t")+entry
->m_StatDel
;
3559 sClipboard
+= _T("\r\n");
3562 return CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
3568 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
3571 std::set
<CString
> changelists
;
3572 POSITION pos
= GetFirstSelectedItemPosition();
3574 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3576 FileEntry
* entry
= GetListEntry(index
);
3577 if (!entry
->changelist
.IsEmpty())
3578 changelists
.insert(entry
->changelist
);
3580 return changelists
.size();
3585 bool CGitStatusListCtrl::PrepareGroups(bool bForce
/* = false */)
3588 bool bHasGroups
=false;
3591 for(int i
=0;i
< this->m_arStatusArray
.size(); i
++)
3593 int ParentNo
= m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3595 max
=m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3598 if ( this->m_UnRevFileList
.GetCount()>0 ||
3599 this->m_IgnoreFileList
.GetCount()>0 ||
3606 EnableGroupView(bHasGroups
);
3608 TCHAR groupname
[1024];
3614 grp
.cbSize
= sizeof(LVGROUP
);
3615 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3618 //if(m_UnRevFileList.GetCount()>0)
3621 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MERGEDFILES
)), 1023);
3622 grp
.pszHeader
= groupname
;
3623 grp
.iGroupId
= MERGE_MASK
;
3624 grp
.uAlign
= LVGA_HEADER_LEFT
;
3625 InsertGroup(0, &grp
);
3627 for(int i
=0;i
<=max
;i
++)
3630 str
.Format(IDS_STATUSLIST_GROUP_DIFFWITHPARENT
, i
+1);
3631 grp
.pszHeader
= str
.GetBuffer();
3632 str
.ReleaseBuffer();
3634 grp
.uAlign
= LVGA_HEADER_LEFT
;
3635 InsertGroup(i
+1, &grp
);
3640 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MODIFIEDFILES
)), 1023);
3641 grp
.pszHeader
= groupname
;
3642 grp
.iGroupId
= groupindex
;
3643 grp
.uAlign
= LVGA_HEADER_LEFT
;
3644 InsertGroup(groupindex
++, &grp
);
3648 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_NOTVERSIONEDFILES
)), 1023);
3649 grp
.pszHeader
= groupname
;
3650 grp
.iGroupId
= groupindex
;
3651 grp
.uAlign
= LVGA_HEADER_LEFT
;
3652 InsertGroup(groupindex
++, &grp
);
3655 //if(m_IgnoreFileList.GetCount()>0)
3657 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNOREDFILES
)), 1023);
3658 grp
.pszHeader
= groupname
;
3659 grp
.iGroupId
= groupindex
;
3660 grp
.uAlign
= LVGA_HEADER_LEFT
;
3661 InsertGroup(groupindex
++, &grp
);
3667 m_bHasIgnoreGroup
= false;
3669 // now add the items which don't belong to a group
3671 grp
.cbSize
= sizeof(LVGROUP
);
3672 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3673 CString
sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET
));
3674 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
3675 grp
.pszHeader
= groupname
;
3676 grp
.iGroupId
= groupindex
;
3677 grp
.uAlign
= LVGA_HEADER_LEFT
;
3678 InsertGroup(groupindex
++, &grp
);
3680 for (std::map
<CString
,int>::iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
3682 if (it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)!=0)
3685 grp
.cbSize
= sizeof(LVGROUP
);
3686 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3687 _tcsncpy_s(groupname
, 1024, it
->first
, 1023);
3688 grp
.pszHeader
= groupname
;
3689 grp
.iGroupId
= groupindex
;
3690 grp
.uAlign
= LVGA_HEADER_LEFT
;
3691 it
->second
= InsertGroup(groupindex
++, &grp
);
3694 m_bHasIgnoreGroup
= true;
3697 if (m_bHasIgnoreGroup
)
3699 // and now add the group 'ignore-on-commit'
3700 std::map
<CString
,int>::iterator it
= m_changelists
.find(SVNSLC_IGNORECHANGELIST
);
3701 if (it
!= m_changelists
.end())
3703 grp
.cbSize
= sizeof(LVGROUP
);
3704 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3705 _tcsncpy_s(groupname
, 1024, SVNSLC_IGNORECHANGELIST
, 1023);
3706 grp
.pszHeader
= groupname
;
3707 grp
.iGroupId
= groupindex
;
3708 grp
.uAlign
= LVGA_HEADER_LEFT
;
3709 it
->second
= InsertGroup(groupindex
, &grp
);
3716 void CGitStatusListCtrl::NotifyCheck()
3718 CWnd
* pParent
= GetParent();
3719 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3721 pParent
->SendMessage(GITSLNM_CHECKCHANGED
, m_nSelected
);
3725 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash
,CTGitPathList
*list
)
3729 m_CurrentVersion
=hash
;
3735 count
= list
->GetCount();
3737 CString head
= _T("HEAD");
3739 head
= _T("HEAD~1");
3741 if(hash
== GIT_REV_ZERO
)
3743 for(int i
=0;i
<count
;i
++)
3748 if(!g_Git
.IsInitRepos())
3750 // also list staged files which will be in the commit
3751 cmd
=(_T("git.exe diff-index --cached --raw ") + head
+ _T(" --numstat -C -M -z"));
3752 g_Git
.Run(cmd
, &cmdout
);
3755 cmd
=(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z"));
3757 cmd
.Format(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z -- \"%s\""),(*list
)[i
].GetGitPathString());
3760 if(g_Git
.Run(cmd
, &cmdout
, &cmdErr
))
3762 int last
= cmdErr
.RevertFind(0,-1);
3764 g_Git
.StringAppend(&str
, &cmdErr
[last
+ 1], CP_UTF8
, cmdErr
.size() - last
-1);
3765 CMessageBox::Show(NULL
, str
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
3768 out
.append(cmdout
, 0);
3770 else // Init Repository
3772 //We will list all added file for init repository because commit will comit these
3774 cmd
=_T("git.exe ls-files -s -t -z");
3776 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
3778 g_Git
.Run(cmd
, &cmdout
);
3780 out
.append(cmdout
,0);
3784 if(g_Git
.IsInitRepos())
3786 m_StatusFileList
.ParserFromLsFile(out
);
3787 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
3788 ((CTGitPath
&)(m_StatusFileList
[i
])).m_Action
=CTGitPath::LOGACTIONS_ADDED
;
3791 this->m_StatusFileList
.ParserFromLog(out
);
3793 //handle delete conflict case, when remote : modified, local : deleted.
3794 for(int i
=0;i
<count
;i
++)
3800 cmd
=_T("git.exe ls-files -u -t -z");
3802 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list
)[i
].GetGitPathString());
3804 g_Git
.Run(cmd
, &cmdout
);
3806 CTGitPathList conflictlist
;
3807 conflictlist
.ParserFromLog(cmdout
);
3808 for(int i
=0;i
<conflictlist
.GetCount();i
++)
3810 CTGitPath
*p
=m_StatusFileList
.LookForGitPath(conflictlist
[i
].GetGitPathString());
3812 p
->m_Action
|=CTGitPath::LOGACTIONS_UNMERGED
;
3814 m_StatusFileList
.AddPath(conflictlist
[i
]);
3818 // handle source files of file renames/moves (issue #860)
3819 // if a file gets renamed and the new file "git add"ed, diff-index doesn't list the source file anymore
3820 for(int i
= 0; i
< count
; i
++)
3826 cmd
= _T("git.exe ls-files -d -z");
3828 cmd
.Format(_T("git.exe ls-files -d -z -- \"%s\""),(*list
)[i
].GetGitPathString());
3830 g_Git
.Run(cmd
, &cmdout
);
3832 CTGitPathList deletelist
;
3833 deletelist
.ParserFromLog(cmdout
, true);
3834 for(int i
= 0; i
< deletelist
.GetCount(); i
++)
3836 CTGitPath
*p
= m_StatusFileList
.LookForGitPath(deletelist
[i
].GetGitPathString());
3838 m_StatusFileList
.AddPath(deletelist
[i
]);
3839 else if ((p
->m_Action
== CTGitPath::LOGACTIONS_ADDED
|| p
->m_Action
== CTGitPath::LOGACTIONS_REPLACED
) && !p
->Exists())
3841 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)
3843 g_Git
.Run(_T("git.exe rm -f --cache -- \"") + p
->GetWinPathString() + _T("\""), &cmdout
);
3844 m_StatusFileList
.RemoveItem(*p
);
3856 count
= list
->GetCount();
3858 for(int i
=0;i
<count
;i
++)
3863 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash
);
3865 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash
,(*list
)[i
].GetGitPathString());
3867 g_Git
.Run(cmd
, &cmdout
, NULL
);
3871 this->m_StatusFileList
.ParserFromLog(out
);
3875 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
3877 CTGitPath
* gitpatch
=(CTGitPath
*)&m_StatusFileList
[i
];
3878 gitpatch
->m_Checked
= TRUE
;
3879 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
3882 this->m_bBusy
=FALSE
;
3886 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList
&list
)
3888 m_arStatusArray
.clear();
3889 for(int i
=0;i
<list
.GetCount();i
++)
3891 CTGitPath
* gitpath
=(CTGitPath
*)&list
[i
];
3893 if(gitpath
->m_Action
& CTGitPath::LOGACTIONS_HIDE
)
3896 gitpath
->m_Checked
= TRUE
;
3897 m_arStatusArray
.push_back((CTGitPath
*)&list
[i
]);
3902 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
*List
)
3904 this->m_UnRevFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
,List
);
3905 for(int i
=0;i
<m_UnRevFileList
.GetCount();i
++)
3907 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
3908 gitpatch
->m_Checked
= FALSE
;
3909 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
3914 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList
*List
)
3916 this->m_IgnoreFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
|CTGitPath::LOGACTIONS_IGNORE
,List
);
3917 for(int i
=0;i
<m_IgnoreFileList
.GetCount();i
++)
3919 CTGitPath
* gitpatch
=(CTGitPath
*)&m_IgnoreFileList
[i
];
3920 gitpatch
->m_Checked
= FALSE
;
3921 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
3925 int CGitStatusListCtrl::UpdateFileList(int mask
,bool once
,CTGitPathList
*List
)
3927 if(mask
&CGitStatusListCtrl::FILELIST_MODIFY
)
3929 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_MODIFY
)))
3931 UpdateFileList(git_revnum_t(GIT_REV_ZERO
),List
);
3932 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_MODIFY
;
3935 if(mask
&CGitStatusListCtrl::FILELIST_UNVER
)
3937 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_UNVER
)))
3939 UpdateUnRevFileList(List
);
3940 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
3942 if(mask
&CGitStatusListCtrl::FILELIST_IGNORE
&& (once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_IGNORE
))))
3944 UpdateIgnoreFileList(List
);
3945 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
3951 void CGitStatusListCtrl::Clear()
3954 this->DeleteAllItems();
3955 this->m_arListArray
.clear();
3956 this->m_arStatusArray
.clear();
3957 this->m_changelists
.clear();
3959 //////////////////////////////////////////////////////////////////////////
3961 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
)
3963 if(pFmtEtc
->cfFormat
== CF_HDROP
&& medium
.tymed
== TYMED_HGLOBAL
)
3965 HDROP hDrop
= (HDROP
)GlobalLock(medium
.hGlobal
);
3968 TCHAR szFileName
[MAX_PATH
];
3970 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, NULL
, 0);
3973 clientpoint
.x
= pt
.x
;
3974 clientpoint
.y
= pt
.y
;
3975 ScreenToClient(m_hTargetWnd
, &clientpoint
);
3976 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
3978 CTSVNPathList changelistItems
;
3979 for(UINT i
= 0; i
< cFiles
; ++i
)
3981 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
3982 changelistItems
.AddPath(CTSVNPath(szFileName
));
3984 // find the changelist name
3985 CString sChangelist
;
3986 LONG_PTR nGroup
= m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
);
3987 for (std::map
<CString
, int>::iterator it
= m_pSVNStatusListCtrl
->m_changelists
.begin(); it
!= m_pSVNStatusListCtrl
->m_changelists
.end(); ++it
)
3988 if (it
->second
== nGroup
)
3989 sChangelist
= it
->first
;
3990 if (!sChangelist
.IsEmpty())
3993 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
3995 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
3997 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
4000 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
4003 e
->changelist
= sChangelist
;
4006 if (m_pSVNStatusListCtrl
->m_changelists
.find(e
->changelist
)!=m_pSVNStatusListCtrl
->m_changelists
.end())
4007 m_pSVNStatusListCtrl
->SetItemGroup(index
, m_pSVNStatusListCtrl
->m_changelists
[e
->changelist
]);
4009 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
4015 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4016 if (hParentWnd
!= NULL
)
4017 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
4023 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
4029 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
4031 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
4033 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
4036 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
4039 e
->changelist
= sChangelist
;
4040 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
4045 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4046 if (hParentWnd
!= NULL
)
4047 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
4053 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
4059 for(UINT i
= 0; i
< cFiles
; ++i
)
4061 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
4062 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4063 if (hParentWnd
!= NULL
)
4064 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)szFileName
);
4068 GlobalUnlock(medium
.hGlobal
);
4070 return true; //let base free the medium
4072 HRESULT STDMETHODCALLTYPE
CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
)
4074 CIDropTarget::DragOver(grfKeyState
, pt
, pdwEffect
);
4075 *pdwEffect
= DROPEFFECT_COPY
;
4076 if (m_pSVNStatusListCtrl
)
4079 clientpoint
.x
= pt
.x
;
4080 clientpoint
.y
= pt
.y
;
4081 ScreenToClient(m_hTargetWnd
, &clientpoint
);
4082 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
4084 *pdwEffect
= DROPEFFECT_MOVE
;
4086 else if ((!m_pSVNStatusListCtrl
->m_bFileDropsEnabled
)||(m_pSVNStatusListCtrl
->m_bOwnDrag
))
4088 *pdwEffect
= DROPEFFECT_NONE
;
4096 void CGitStatusListCtrl::FileSaveAs(CTGitPath
*path
)
4099 filename
.Format(_T("%s-%s%s"), path
->GetBaseFilename(), this->m_CurrentVersion
.Left(g_Git
.GetShortHASHLength()), path
->GetFileExtension());
4100 CFileDialog
dlg(FALSE
,NULL
,
4102 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
4104 CString currentpath
;
4105 currentpath
=g_Git
.m_CurrentDir
+_T("\\");
4106 currentpath
+=path
->GetWinPathString();
4108 dlg
.m_ofn
.lpstrInitialDir
=currentpath
.GetBuffer();
4111 if(dlg
.DoModal()==IDOK
)
4113 filename
= dlg
.GetPathName();
4114 if(m_CurrentVersion
== GIT_REV_ZERO
)
4116 if(!CopyFile(g_Git
.m_CurrentDir
+_T("\\") + path
->GetWinPath(),filename
,false))
4118 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
4125 if(g_Git
.GetOneFile(m_CurrentVersion
,*path
,filename
))
4127 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, path
->GetGitPathString(), m_CurrentVersion
, filename
);
4128 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
4136 int CGitStatusListCtrl::RevertSelectedItemToVersion()
4138 if(this->m_CurrentVersion
.IsEmpty())
4140 if(this->m_CurrentVersion
== GIT_REV_ZERO
)
4143 POSITION pos
= GetFirstSelectedItemPosition();
4147 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4149 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
4150 cmd
.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion
,fentry
->GetGitPathString());
4152 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
4154 if (MessageBox(out
, _T("TortoiseGit"), MB_ICONEXCLAMATION
| MB_OKCANCEL
) == IDCANCEL
)
4161 out
.Format(IDS_STATUSLIST_FILESREVERTED
, count
, m_CurrentVersion
);
4162 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
4166 void CGitStatusListCtrl::OpenFile(CTGitPath
*filepath
,int mode
)
4169 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
4171 file
= filepath
->GetWinPath();
4176 GetTempPath(temppath
);
4177 file
.Format(_T("%s%s_%s%s"),
4179 filepath
->GetBaseFilename(),
4180 m_CurrentVersion
.Left(g_Git
.GetShortHASHLength()),
4181 filepath
->GetFileExtension());
4183 if(g_Git
.GetOneFile(m_CurrentVersion
, *filepath
, file
))
4185 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, filepath
->GetGitPathString(), m_CurrentVersion
, file
);
4186 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
4191 if(mode
== ALTERNATIVEEDITOR
)
4193 CAppUtils::LaunchAlternativeEditor(file
);
4196 int ret
= HINSTANCE_ERROR
;
4200 ret
= (int)ShellExecute(this->m_hWnd
, NULL
,file
, NULL
, NULL
, SW_SHOW
);
4202 if (ret
> HINSTANCE_ERROR
)
4209 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
4211 CAppUtils::LaunchApplication(cmd
, NULL
, false);