1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - TortoiseGit
4 // Copyright (C) 2003-2008, 2013-2014 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "..\\TortoiseShell\resource.h"
24 #include "GitStatusListCtrl.h"
25 #include "MessageBox.h"
27 #include "UnicodeUtils.h"
29 #include "PathUtils.h"
31 #include "StringUtils.h"
32 #include "LoglistUtils.h"
35 #include "GitProgressDlg.h"
36 #include "SysImageList.h"
40 #include "GitAdminDir.h"
41 #include "DropFiles.h"
42 #include "ProgressCommands/AddProgressCommand.h"
44 #include "FormatMessageWrapper.h"
45 #include "BrowseFolder.h"
47 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
48 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
49 const UINT
CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
50 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
51 const UINT
CGitStatusListCtrl::GITSLNM_ADDFILE
52 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
53 const UINT
CGitStatusListCtrl::GITSLNM_CHECKCHANGED
54 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
55 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCHANGED
56 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCHANGED"));
60 bool operator() (const std::wstring
& lhs
, const std::wstring
& rhs
) const
62 // no logical comparison here: we need this sorted strictly
63 return _wcsicmp(lhs
.c_str(), rhs
.c_str()) < 0;
67 class CIShellFolderHook
: public IShellFolder
70 CIShellFolderHook(LPSHELLFOLDER sf
, const CTGitPathList
& pathlist
)
74 // it seems the paths in the HDROP need to be sorted, otherwise
75 // it might not work properly or even crash.
76 // to get the items sorted, we just add them to a set
77 for (int i
= 0; i
< pathlist
.GetCount(); ++i
)
78 sortedpaths
.insert((LPCTSTR
)g_Git
.CombinePath(pathlist
[i
].GetWinPath()));
81 ~CIShellFolderHook() { m_iSF
->Release(); }
83 // IUnknown methods --------
84 virtual HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, __RPC__deref_out
void **ppvObject
) { return m_iSF
->QueryInterface(riid
, ppvObject
); }
85 virtual ULONG STDMETHODCALLTYPE
AddRef(void) { return m_iSF
->AddRef(); }
86 virtual ULONG STDMETHODCALLTYPE
Release(void) { return m_iSF
->Release(); }
88 // IShellFolder methods ----
89 virtual HRESULT STDMETHODCALLTYPE
GetUIObjectOf(HWND hwndOwner
, UINT cidl
, PCUITEMID_CHILD_ARRAY apidl
, REFIID riid
, UINT
*rgfReserved
, void **ppv
);
91 virtual HRESULT STDMETHODCALLTYPE
CompareIDs(LPARAM lParam
, __RPC__in PCUIDLIST_RELATIVE pidl1
, __RPC__in PCUIDLIST_RELATIVE pidl2
) { return m_iSF
->CompareIDs(lParam
, pidl1
, pidl2
); }
92 virtual HRESULT STDMETHODCALLTYPE
GetDisplayNameOf(__RPC__in_opt PCUITEMID_CHILD pidl
, SHGDNF uFlags
, __RPC__out STRRET
*pName
) { return m_iSF
->GetDisplayNameOf(pidl
, uFlags
, pName
); }
93 virtual HRESULT STDMETHODCALLTYPE
CreateViewObject(__RPC__in_opt HWND hwndOwner
, __RPC__in REFIID riid
, __RPC__deref_out_opt
void **ppv
) { return m_iSF
->CreateViewObject(hwndOwner
, riid
, ppv
); }
94 virtual HRESULT STDMETHODCALLTYPE
EnumObjects(__RPC__in_opt HWND hwndOwner
, SHCONTF grfFlags
, __RPC__deref_out_opt IEnumIDList
**ppenumIDList
) { return m_iSF
->EnumObjects(hwndOwner
, grfFlags
, ppenumIDList
); }
95 virtual HRESULT STDMETHODCALLTYPE
BindToObject(__RPC__in PCUIDLIST_RELATIVE pidl
, __RPC__in_opt IBindCtx
*pbc
, __RPC__in REFIID riid
, __RPC__deref_out_opt
void **ppv
) { return m_iSF
->BindToObject(pidl
, pbc
, riid
, ppv
); }
96 virtual HRESULT STDMETHODCALLTYPE
ParseDisplayName(__RPC__in_opt HWND hwnd
, __RPC__in_opt IBindCtx
*pbc
, __RPC__in_string LPWSTR pszDisplayName
, __reserved ULONG
*pchEaten
, __RPC__deref_out_opt PIDLIST_RELATIVE
*ppidl
, __RPC__inout_opt ULONG
*pdwAttributes
) { return m_iSF
->ParseDisplayName(hwnd
, pbc
, pszDisplayName
, pchEaten
, ppidl
, pdwAttributes
); }
97 virtual HRESULT STDMETHODCALLTYPE
GetAttributesOf(UINT cidl
, __RPC__in_ecount_full_opt(cidl
) PCUITEMID_CHILD_ARRAY apidl
, __RPC__inout SFGAOF
*rgfInOut
) { return m_iSF
->GetAttributesOf(cidl
, apidl
, rgfInOut
); }
98 virtual HRESULT STDMETHODCALLTYPE
BindToStorage(__RPC__in PCUIDLIST_RELATIVE pidl
, __RPC__in_opt IBindCtx
*pbc
, __RPC__in REFIID riid
, __RPC__deref_out_opt
void **ppv
) { return m_iSF
->BindToStorage(pidl
, pbc
, riid
, ppv
); }
99 virtual HRESULT STDMETHODCALLTYPE
SetNameOf(__in_opt HWND hwnd
, __in PCUITEMID_CHILD pidl
, __in LPCWSTR pszName
, __in SHGDNF uFlags
, __deref_opt_out PITEMID_CHILD
*ppidlOut
) { return m_iSF
->SetNameOf(hwnd
, pidl
, pszName
, uFlags
, ppidlOut
); }
103 std::set
<std::wstring
, icompare
> sortedpaths
;
106 HRESULT STDMETHODCALLTYPE
CIShellFolderHook::GetUIObjectOf(HWND hwndOwner
, UINT cidl
, PCUITEMID_CHILD_ARRAY apidl
, REFIID riid
, UINT
*rgfReserved
, void **ppv
)
108 if (InlineIsEqualGUID(riid
, IID_IDataObject
))
110 HRESULT hres
= m_iSF
->GetUIObjectOf(hwndOwner
, cidl
, apidl
, IID_IDataObject
, NULL
, ppv
);
114 IDataObject
* idata
= (LPDATAOBJECT
)(*ppv
);
115 // the IDataObject returned here doesn't have a HDROP, so we create one ourselves and add it to the IDataObject
116 // the HDROP is necessary for most context menu handlers
118 for (auto it
= sortedpaths
.cbegin(); it
!= sortedpaths
.cend(); ++it
)
120 nLength
+= (int)it
->size();
121 nLength
+= 1; // '\0' separator
123 int nBufferSize
= sizeof(DROPFILES
) + ((nLength
+ 5)*sizeof(TCHAR
));
124 std::unique_ptr
<char[]> pBuffer(new char[nBufferSize
]);
125 SecureZeroMemory(pBuffer
.get(), nBufferSize
);
126 DROPFILES
* df
= (DROPFILES
*)pBuffer
.get();
127 df
->pFiles
= sizeof(DROPFILES
);
129 TCHAR
* pFilenames
= (TCHAR
*)((BYTE
*)(pBuffer
.get()) + sizeof(DROPFILES
));
130 TCHAR
* pCurrentFilename
= pFilenames
;
132 for (auto it
= sortedpaths
.cbegin(); it
!= sortedpaths
.cend(); ++it
)
134 wcscpy_s(pCurrentFilename
, it
->size() + 1, it
->c_str());
135 pCurrentFilename
+= it
->size();
136 *pCurrentFilename
= '\0'; // separator between file names
139 *pCurrentFilename
= '\0'; // terminate array
141 *pCurrentFilename
= '\0'; // terminate array
142 STGMEDIUM medium
= { 0 };
143 medium
.tymed
= TYMED_HGLOBAL
;
144 medium
.hGlobal
= GlobalAlloc(GMEM_ZEROINIT
| GMEM_MOVEABLE
, nBufferSize
+ 20);
147 LPVOID pMem
= ::GlobalLock(medium
.hGlobal
);
150 memcpy(pMem
, pBuffer
.get(), nBufferSize
);
151 GlobalUnlock(medium
.hGlobal
);
152 FORMATETC formatetc
= { 0 };
153 formatetc
.cfFormat
= CF_HDROP
;
154 formatetc
.dwAspect
= DVASPECT_CONTENT
;
155 formatetc
.lindex
= -1;
156 formatetc
.tymed
= TYMED_HGLOBAL
;
157 medium
.pUnkForRelease
= nullptr;
158 hres
= idata
->SetData(&formatetc
, &medium
, TRUE
);
162 return E_OUTOFMEMORY
;
166 // just pass it on to the base object
167 return m_iSF
->GetUIObjectOf(hwndOwner
, cidl
, apidl
, riid
, rgfReserved
, ppv
);
171 IContextMenu2
* g_IContext2
= nullptr;
172 IContextMenu3
* g_IContext3
= nullptr;
173 CIShellFolderHook
* g_pFolderhook
= nullptr;
174 IShellFolder
* g_psfDesktopFolder
= nullptr;
175 LPITEMIDLIST
* g_pidlArray
= nullptr;
176 int g_pidlArrayItems
= 0;
178 #define SHELL_MIN_CMD 10000
179 #define SHELL_MAX_CMD 20000
181 HRESULT CALLBACK
dfmCallback(IShellFolder
* /*psf*/, HWND
/*hwnd*/, IDataObject
* /*pdtobj*/, UINT uMsg
, WPARAM
/*wParam*/, LPARAM
/*lParam*/)
185 case DFM_MERGECONTEXTMENU
:
187 case DFM_INVOKECOMMAND
:
188 case DFM_INVOKECOMMANDEX
:
189 case DFM_GETDEFSTATICID
: // Required for Windows 7 to pick a default
195 BEGIN_MESSAGE_MAP(CGitStatusListCtrl
, CListCtrl
)
196 ON_NOTIFY(HDN_ITEMCLICKA
, 0, OnHdnItemclick
)
197 ON_NOTIFY(HDN_ITEMCLICKW
, 0, OnHdnItemclick
)
198 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
199 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
200 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED
, OnLvnItemchanged
)
202 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclk
)
203 ON_NOTIFY_REFLECT(LVN_GETINFOTIP
, OnLvnGetInfoTip
)
204 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdraw
)
207 ON_NOTIFY_REFLECT(NM_RETURN
, OnNMReturn
)
210 ON_NOTIFY(HDN_BEGINTRACKA
, 0, &CGitStatusListCtrl::OnHdnBegintrack
)
211 ON_NOTIFY(HDN_BEGINTRACKW
, 0, &CGitStatusListCtrl::OnHdnBegintrack
)
212 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, &CGitStatusListCtrl::OnHdnItemchanging
)
213 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, &CGitStatusListCtrl::OnHdnItemchanging
)
215 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnBeginDrag
)
216 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING
, &CGitStatusListCtrl::OnLvnItemchanging
)
221 CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl()
222 //, m_HeadRev(GitRev::REV_HEAD)
225 , m_pSelectButton(NULL
)
226 , m_pConfirmButton(NULL
)
229 , m_bShowIgnores(false)
230 , m_pDropTarget(NULL
)
231 , m_bIgnoreRemoveOnly(false)
232 , m_bCheckChildrenWithParent(false)
233 , m_bUnversionedLast(true)
234 , m_bHasChangeLists(false)
238 , m_bHasCheckboxes(false)
239 , m_bCheckIfGroupsExist(true)
240 , m_bFileDropsEnabled(false)
242 , m_dwDefaultColumns(0)
243 , m_ColumnManager(this)
244 , m_bAscending(false)
245 , m_nSortedColumn(-1)
246 , m_bHasExternalsFromDifferentRepos(false)
247 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE
))
249 , m_bDoNotAutoselectSubmodules(false)
251 , m_hwndLogicalParent(NULL
)
252 , m_bHasUnversionedItems(FALSE
)
254 , m_bHasExternals(false)
255 , m_bHasIgnoreGroup(false)
265 , m_nShownUnversioned(0)
266 , m_nShownModified(0)
269 , m_nShownConflicted(0)
271 , m_nShownSubmodules(0)
273 , m_bShowFolders(false)
275 , m_dwContextMenus(0)
278 , pfnSHCreateDefaultContextMenu(nullptr)
279 , pfnAssocCreateForClasses(nullptr)
280 , m_pContextMenu(nullptr)
281 , m_hShellMenu(nullptr)
284 m_dwDefaultColumns
= 0;
286 m_bIsRevertTheirMy
= false;
287 this->m_nLineAdded
=this->m_nLineDeleted
=0;
288 m_ShellDll
= AtlLoadSystemLibraryUsingFullPath(_T("Shell32.dll"));
291 pfnSHCreateDefaultContextMenu
= (FNSHCreateDefaultContextMenu
)::GetProcAddress(m_ShellDll
, "SHCreateDefaultContextMenu");
292 pfnAssocCreateForClasses
= (FNAssocCreateForClasses
)::GetProcAddress(m_ShellDll
, "AssocCreateForClasses");
296 CGitStatusListCtrl::~CGitStatusListCtrl()
298 // if (m_pDropTarget)
299 // delete m_pDropTarget;
303 void CGitStatusListCtrl::ClearStatusArray()
306 Locker
lock(m_critSec
);
307 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
309 delete m_arStatusArray
[i
];
311 m_arStatusArray
.clear();
315 void CGitStatusListCtrl::Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
/* = GitSLC_POPALL */, bool bHasCheckboxes
/* = true */, bool bHasWC
/* = true */, DWORD allowedColumns
/* = 0xffffffff */)
317 Locker
lock(m_critSec
);
319 m_dwDefaultColumns
= dwColumns
| 1;
320 m_dwContextMenus
= dwContextMenus
;
321 m_bHasCheckboxes
= bHasCheckboxes
;
324 // set the extended style of the listcontrol
325 // 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.
326 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
327 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
328 if (DWORD(regFullRowSelect
))
329 exStyle
|= LVS_EX_FULLROWSELECT
;
330 exStyle
|= (bHasCheckboxes
? LVS_EX_CHECKBOXES
: 0);
332 SetExtendedStyle(exStyle
);
334 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
336 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
337 m_nRestoreOvl
= SYS_IMAGE_LIST().AddIcon((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_RESTOREOVL
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
));
338 SYS_IMAGE_LIST().SetOverlayImage(m_nRestoreOvl
, OVL_RESTORE
);
339 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
341 // keep CSorter::operator() in sync!!
342 static UINT standardColumnNames
[GITSLC_NUMCOLUMNS
]
343 = { IDS_STATUSLIST_COLFILE
344 , IDS_STATUSLIST_COLFILENAME
345 , IDS_STATUSLIST_COLEXT
346 , IDS_STATUSLIST_COLSTATUS
347 , IDS_STATUSLIST_COLADD
348 , IDS_STATUSLIST_COLDEL
349 , IDS_STATUSLIST_COLLASTMODIFIED
350 , IDS_STATUSLIST_COLSIZE
353 m_ColumnManager
.SetNames(standardColumnNames
,GITSLC_NUMCOLUMNS
);
354 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, 0xffffffff & ~(allowedColumns
| m_dwDefaultColumns
), sColumnInfoContainer
, GITSLC_NUMCOLUMNS
);
358 if (m_pDropTarget
== NULL
)
360 m_pDropTarget
= new CGitStatusListCtrlDropTarget(this);
361 RegisterDragDrop(m_hWnd
,m_pDropTarget
);
362 // create the supported formats:
364 ftetc
.dwAspect
= DVASPECT_CONTENT
;
366 ftetc
.tymed
= TYMED_HGLOBAL
;
367 ftetc
.cfFormat
=CF_HDROP
;
368 m_pDropTarget
->AddSuportedFormat(ftetc
);
375 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID
)
377 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
380 BOOL
CGitStatusListCtrl::GetStatus ( const CTGitPathList
* pathList
381 , bool bUpdate
/* = FALSE */
382 , bool bShowIgnores
/* = false */
383 , bool bShowUnRev
/* = false */
384 , bool bShowLocalChangesIgnored
/* = false */)
386 Locker
lock(m_critSec
);
387 int mask
= CGitStatusListCtrl::FILELIST_MODIFY
;
389 mask
|= CGitStatusListCtrl::FILELIST_IGNORE
;
391 mask
|= CGitStatusListCtrl::FILELIST_UNVER
;
392 if (bShowLocalChangesIgnored
)
393 mask
|= CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED
;
394 this->UpdateFileList(mask
,bUpdate
,(CTGitPathList
*)pathList
);
396 if (pathList
&& m_mapDirectFiles
.empty())
398 // remember files which are selected by users so that those can be preselected
399 for (int i
= 0; i
< pathList
->GetCount(); ++i
)
400 if (!(*pathList
)[i
].IsDirectory())
401 m_mapDirectFiles
[(*pathList
)[i
].GetGitPathString()] = true;
405 int refetchcounter
= 0;
408 // force the cursor to change
411 SetCursorPos(pt
.x
, pt
.y
);
413 m_mapFilenameToChecked
.clear();
414 //m_StatusUrlList.Clear();
415 bool bHasChangelists
= (m_changelists
.size() > 1 || (!m_changelists
.empty() && !m_bHasIgnoreGroup
));
416 m_changelists
.clear();
417 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
419 FileEntry
* entry
= m_arStatusArray
[i
];
420 if ( bHasChangelists
&& entry
->checked
)
422 // If change lists are present, remember all checked entries
423 CString path
= entry
->GetPath().GetGitPathString();
424 m_mapFilenameToChecked
[path
] = true;
426 if ( (entry
->status
==git_wc_status_unversioned
|| entry
->status
==git_wc_status_missing
) && entry
->checked
)
428 // The user manually selected an unversioned or missing file. We remember
429 // this so that the selection can be restored when refreshing.
430 CString path
= entry
->GetPath().GetGitPathString();
431 m_mapFilenameToChecked
[path
] = true;
433 else if ( entry
->status
> git_wc_status_normal
&& !entry
->checked
)
435 // The user manually deselected a versioned file. We remember
436 // this so that the deselection can be restored when refreshing.
437 CString path
= entry
->GetPath().GetGitPathString();
438 m_mapFilenameToChecked
[path
] = false;
442 // use a sorted path list to make sure we fetch the status of
443 // parent items first, *then* the child items (if any)
444 CTGitPathList sortedPathList
= pathList
;
445 sortedPathList
.SortByPathname();
450 m_bHasExternalsFromDifferentRepos
= FALSE
;
451 m_bHasExternals
= FALSE
;
452 m_bHasUnversionedItems
= FALSE
;
454 m_bHasChangeLists
= false;
455 m_bShowIgnores
= bShowIgnores
;
462 // first clear possible status data left from
463 // previous GetStatus() calls
466 m_StatusFileList
= sortedPathList
;
468 // Since Git_client_status() returns all files, even those in
469 // folders included with Git:externals we need to check if all
470 // files we get here belongs to the same repository.
471 // It is possible to commit changes in an external folder, as long
472 // as the folder belongs to the same repository (but another path),
473 // but it is not possible to commit all files if the externals are
474 // from a different repository.
476 // To check if all files belong to the same repository, we compare the
477 // UUID's - if they're identical then the files belong to the same
478 // repository and can be committed. But if they're different, then
479 // tell the user to commit all changes in the external folders
481 CStringA sUUID
; // holds the repo UUID
482 CTGitPathList arExtPaths
; // list of Git:external paths
488 m_nTargetCount
= sortedPathList
.GetCount();
490 GitStatus
status(m_pbCanceled
);
491 if(m_nTargetCount
> 1 && sortedPathList
.AreAllPathsFilesInOneDirectory())
493 // This is a special case, where we've been given a list of files
494 // all from one folder
495 // We handle them by setting a status filter, then requesting the Git status of
496 // all the files in the directory, filtering for the ones we're interested in
497 status
.SetFilter(sortedPathList
);
499 // if all selected entries are files, we don't do a recursive status
500 // fetching. But if only one is a directory, we have to recurse.
501 git_depth_t depth
= git_depth_files
;
502 // We have set a filter. If all selected items were files or we fetch
503 // the status not recursively, then we have to include
504 // ignored items too - the user has selected them
505 bool bShowIgnoresRight
= true;
506 for (int fcindex
=0; fcindex
<sortedPathList
.GetCount(); ++fcindex
)
508 if (sortedPathList
[fcindex
].IsDirectory())
510 depth
= git_depth_infinity
;
511 bShowIgnoresRight
= false;
515 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
.GetCommonDirectory(), bUpdate
, sUUID
, arExtPaths
, true, depth
, bShowIgnoresRight
))
522 for(int nTarget
= 0; nTarget
< m_nTargetCount
; nTarget
++)
524 // check whether the path we want the status for is already fetched due to status-fetching
526 // this check is only done for file paths, because folder paths could be included already
527 // but not recursively
528 if (sortedPathList
[nTarget
].IsDirectory() || GetListEntry(sortedPathList
[nTarget
]) == NULL
)
530 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
[nTarget
], bUpdate
, sUUID
,
531 arExtPaths
, false, git_depth_infinity
, bShowIgnores
))
539 // remove the 'helper' files of conflicted items from the list.
540 // otherwise they would appear as unversioned files.
541 for (INT_PTR cind
= 0; cind
< m_ConflictFileList
.GetCount(); ++cind
)
543 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
545 if (m_arStatusArray
[i
]->GetPath().IsEquivalentTo(m_ConflictFileList
[cind
]))
547 delete m_arStatusArray
[i
];
548 m_arStatusArray
.erase(m_arStatusArray
.begin()+i
);
554 } while(!BuildStatistics() && (refetchcounter
< 2) && (*m_pbCanceled
==false));
559 SetCursorPos(pt
.x
, pt
.y
);
566 // Get the show-flags bitmap value which corresponds to a particular Git status
567 DWORD
CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status
)
571 case git_wc_status_none
:
572 case git_wc_status_unversioned
:
573 return GITSLC_SHOWUNVERSIONED
;
574 case git_wc_status_ignored
:
576 return GITSLC_SHOWDIRECTS
;
577 return GITSLC_SHOWDIRECTS
|GITSLC_SHOWIGNORED
;
578 case git_wc_status_incomplete
:
579 return GITSLC_SHOWINCOMPLETE
;
580 case git_wc_status_normal
:
581 return GITSLC_SHOWNORMAL
;
582 case git_wc_status_external
:
583 return GITSLC_SHOWEXTERNAL
;
584 case git_wc_status_added
:
585 return GITSLC_SHOWADDED
;
586 case git_wc_status_missing
:
587 return GITSLC_SHOWMISSING
;
588 case git_wc_status_deleted
:
589 return GITSLC_SHOWREMOVED
;
590 case git_wc_status_replaced
:
591 return GITSLC_SHOWREPLACED
;
592 case git_wc_status_modified
:
593 return GITSLC_SHOWMODIFIED
;
594 case git_wc_status_merged
:
595 return GITSLC_SHOWMERGED
;
596 case git_wc_status_conflicted
:
597 return GITSLC_SHOWCONFLICTED
;
598 case git_wc_status_obstructed
:
599 return GITSLC_SHOWOBSTRUCTED
;
601 // we should NEVER get here!
608 void CGitStatusListCtrl::Show(unsigned int dwShow
, unsigned int dwCheck
/*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList
,bool UseStoredCheckStatus
)
610 CWinApp
* pApp
= AfxGetApp();
612 pApp
->DoWaitCursor(1);
614 Locker
lock(m_critSec
);
615 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
617 //SetItemCount(listIndex);
622 m_nShownUnversioned
= 0;
623 m_nShownModified
= 0;
626 m_nShownConflicted
= 0;
628 m_nShownSubmodules
= 0;
632 m_arStatusArray
.clear();
633 for (int i
= 0; i
< m_StatusFileList
.GetCount(); ++i
)
635 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
638 for (int i
= 0; i
< m_UnRevFileList
.GetCount(); ++i
)
640 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
643 for (int i
= 0; i
< m_IgnoreFileList
.GetCount(); ++i
)
645 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
649 if (m_nSortedColumn
>= 0)
651 CSorter
predicate (&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
652 std::sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
656 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
658 //set default checkbox status
659 CTGitPath
* entry
= ((CTGitPath
*)m_arStatusArray
[i
]);
660 CString path
= entry
->GetGitPathString();
661 if (!m_mapFilenameToChecked
.empty() && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end())
663 entry
->m_Checked
=m_mapFilenameToChecked
[path
];
665 else if (!UseStoredCheckStatus
)
667 bool autoSelectSubmodules
= !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
);
668 if ((entry
->m_Action
& dwCheck
|| dwShow
& GITSLC_SHOWDIRECTFILES
&& m_mapDirectFiles
.find(path
) != m_mapDirectFiles
.end()) && autoSelectSubmodules
)
669 entry
->m_Checked
=true;
671 entry
->m_Checked
=false;
672 m_mapFilenameToChecked
[path
] = entry
->m_Checked
;
675 if(entry
->m_Action
& dwShow
)
677 AddEntry(entry
,langID
,index
);
682 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
683 for (int col
= 0; col
<= maxcol
; col
++)
684 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
687 GetStatisticsString();
689 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
690 HDITEM HeaderItem
= {0};
691 HeaderItem
.mask
= HDI_FORMAT
;
692 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
694 pHeader
->GetItem(i
, &HeaderItem
);
695 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
696 pHeader
->SetItem(i
, &HeaderItem
);
698 if (m_nSortedColumn
>= 0)
700 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
701 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
702 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
708 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
709 EnsureVisible(nSelectedEntry
, false);
713 // Restore the item at the top of the list.
714 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
716 if ( !EnsureVisible(nTopIndex
+i
,false) )
724 pApp
->DoWaitCursor(-1);
730 this->BuildStatistics();
734 CWinApp
* pApp
= AfxGetApp();
736 pApp
->DoWaitCursor(1);
738 m_bShowFolders
= bShowFolders
;
740 int nTopIndex
= GetTopIndex();
741 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
742 int nSelectedEntry
= 0;
743 if (posSelectedEntry
)
744 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
750 m_arListArray
.clear();
752 m_arListArray
.reserve(m_arStatusArray
.size());
753 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
756 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
758 FileEntry
* entry
= m_arStatusArray
[i
];
759 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
761 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
763 if (entry
->IsFolder() && (!bShowFolders
))
764 continue; // don't show folders if they're not wanted.
767 git_wc_status_kind status
= GitStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
768 DWORD showFlags
= GetShowFlagsFromGitStatus(status
);
769 if (entry
->IsLocked())
770 showFlags
|= SVNSLC_SHOWLOCKS
;
772 showFlags
|= SVNSLC_SHOWSWITCHED
;
773 if (!entry
->changelist
.IsEmpty())
774 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
776 bool bAllowCheck
= ((entry
->changelist
.Compare(GITSLC_IGNORECHANGELIST
) != 0)
777 && (m_bCheckIfGroupsExist
|| (m_changelists
.empty() || (m_changelists
.size() == 1 && m_bHasIgnoreGroup
))));
779 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
781 if (status
!= Git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& GitSLC_SHOWIGNORED
))
783 if ((!entry
->IsFolder()) && (status
== Git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
785 if (PathFileExists(entry
->GetPath().GetWinPath()))
787 m_arListArray
.push_back(i
);
788 if ((dwCheck
& SVNSLC_SHOWREMOVEDANDPRESENT
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
791 entry
->checked
= true;
793 AddEntry(entry
, langID
, listIndex
++);
796 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
798 m_arListArray
.push_back(i
);
799 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
802 entry
->checked
= true;
804 AddEntry(entry
, langID
, listIndex
++);
806 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
808 m_arListArray
.push_back(i
);
809 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
812 entry
->checked
= true;
814 AddEntry(entry
, langID
, listIndex
++);
820 SetItemCount(listIndex
);
822 m_ColumnManager
.UpdateRelevance (m_arStatusArray
, m_arListArray
);
824 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
825 for (int col
= 0; col
<= maxcol
; col
++)
826 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
829 GetStatisticsString();
831 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
832 HDITEM HeaderItem
= {0};
833 HeaderItem
.mask
= HDI_FORMAT
;
834 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
836 pHeader
->GetItem(i
, &HeaderItem
);
837 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
838 pHeader
->SetItem(i
, &HeaderItem
);
842 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
843 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
844 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
849 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
850 EnsureVisible(nSelectedEntry
, false);
854 // Restore the item at the top of the list.
855 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
857 if ( !EnsureVisible(nTopIndex
+i
,false) )
865 pApp
->DoWaitCursor(-1);
867 m_bEmpty
= (GetItemCount() == 0);
873 void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList
& checkedList
, bool /*bShowFolders*/ /* = true */)
876 for (int i
= 0; i
< checkedList
.GetCount(); ++i
)
877 this->AddEntry((CTGitPath
*)&checkedList
[i
],0,i
);
881 Locker
lock(m_critSec
);
882 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
884 CWinApp
* pApp
= AfxGetApp();
886 pApp
->DoWaitCursor(1);
888 m_bShowFolders
= bShowFolders
;
890 int nTopIndex
= GetTopIndex();
891 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
892 int nSelectedEntry
= 0;
893 if (posSelectedEntry
)
894 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
900 m_arListArray
.clear();
902 m_arListArray
.reserve(m_arStatusArray
.size());
903 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
906 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
908 FileEntry
* entry
= m_arStatusArray
[i
];
909 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
911 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
913 if (entry
->IsFolder() && (!bShowFolders
))
914 continue; // don't show folders if they're not wanted.
916 git_wc_status_kind status
= SVNStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
917 DWORD showFlags
= GetShowFlagsFromSVNStatus(status
);
918 if (entry
->IsLocked())
919 showFlags
|= SVNSLC_SHOWLOCKS
;
920 if (!entry
->changelist
.IsEmpty())
921 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
923 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
924 if (status
!= git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& SVNSLC_SHOWIGNORED
))
926 for (int npath
= 0; npath
< checkedList
.GetCount(); ++npath
)
928 if (entry
->GetPath().IsEquivalentTo(checkedList
[npath
]))
930 entry
->checked
= true;
934 if ((!entry
->IsFolder()) && (status
== git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
936 if (PathFileExists(entry
->GetPath().GetWinPath()))
938 m_arListArray
.push_back(i
);
939 AddEntry(entry
, langID
, listIndex
++);
942 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
944 m_arListArray
.push_back(i
);
945 AddEntry(entry
, langID
, listIndex
++);
947 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
949 m_arListArray
.push_back(i
);
950 AddEntry(entry
, langID
, listIndex
++);
952 else if (entry
->switched
)
954 m_arListArray
.push_back(i
);
955 AddEntry(entry
, langID
, listIndex
++);
961 SetItemCount(listIndex
);
963 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
964 for (int col
= 0; col
<= maxcol
; col
++)
965 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
968 GetStatisticsString();
970 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
971 HDITEM HeaderItem
= {0};
972 HeaderItem
.mask
= HDI_FORMAT
;
973 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
975 pHeader
->GetItem(i
, &HeaderItem
);
976 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
977 pHeader
->SetItem(i
, &HeaderItem
);
981 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
982 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
983 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
988 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
989 EnsureVisible(nSelectedEntry
, false);
993 // Restore the item at the top of the list.
994 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
996 if ( !EnsureVisible(nTopIndex
+i
,false) )
1004 pApp
->DoWaitCursor(-1);
1006 m_bEmpty
= (GetItemCount() == 0);
1011 int CGitStatusListCtrl::GetColumnIndex(int mask
)
1013 for (int i
= 0; i
< 32; ++i
)
1020 void CGitStatusListCtrl::AddEntry(CTGitPath
* GitPath
, WORD
/*langID*/, int listIndex
)
1022 static CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
1023 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
1024 static bool abbreviateRenamings(((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\AbbreviateRenamings"), FALSE
)) == TRUE
);
1025 static bool relativeTimes
= (CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
) != FALSE
);
1027 CString path
= GitPath
->GetGitPathString();
1030 int index
= listIndex
;
1032 CString entryname
= GitPath
->GetGitPathString();
1034 if (GitPath
->IsDirectory())
1036 icon_idx
= m_nIconFolder
;
1037 m_nShownSubmodules
++;
1041 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(*GitPath
);
1044 switch (GitPath
->m_Action
)
1046 case CTGitPath::LOGACTIONS_ADDED
:
1047 case CTGitPath::LOGACTIONS_COPY
:
1050 case CTGitPath::LOGACTIONS_DELETED
:
1053 case CTGitPath::LOGACTIONS_REPLACED
:
1054 case CTGitPath::LOGACTIONS_MODIFIED
:
1055 case CTGitPath::LOGACTIONS_MERGED
:
1058 case CTGitPath::LOGACTIONS_UNMERGED
:
1059 m_nShownConflicted
++;
1061 case CTGitPath::LOGACTIONS_UNVER
:
1062 m_nShownUnversioned
++;
1065 m_nShownUnversioned
++;
1068 if(GitPath
->m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !GitPath
->GetGitOldPathString().IsEmpty())
1070 if (!abbreviateRenamings
)
1074 rename
.Format(from
, GitPath
->GetGitOldPathString());
1075 entryname
+= _T(" ") + rename
;
1080 tgpl
.AddPath(*GitPath
);
1081 CTGitPath
old(GitPath
->GetGitOldPathString());
1083 CString commonRoot
= tgpl
.GetCommonRoot().GetGitPathString();
1084 if (!commonRoot
.IsEmpty())
1085 commonRoot
+= _T("/");
1086 if (old
.GetFileOrDirectoryName() == GitPath
->GetFileOrDirectoryName() && old
.GetContainingDirectory().GetGitPathString() != "" && GitPath
->GetContainingDirectory().GetGitPathString())
1088 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();
1090 else if (!commonRoot
.IsEmpty())
1092 entryname
= commonRoot
+ _T("{") + GitPath
->GetGitOldPathString().Mid(commonRoot
.GetLength()) + _T(" => ") + GitPath
->GetGitPathString().Mid(commonRoot
.GetLength()) + _T("}");
1096 entryname
= GitPath
->GetGitOldPathString().Mid(commonRoot
.GetLength()) + _T(" => ") + GitPath
->GetGitPathString().Mid(commonRoot
.GetLength());
1101 InsertItem(index
, entryname
, icon_idx
);
1102 if (m_restorepaths
.find(GitPath
->GetWinPathString()) != m_restorepaths
.end())
1103 SetItemState(index
, INDEXTOOVERLAYMASK(OVL_RESTORE
), TVIS_OVERLAYMASK
);
1105 this->SetItemData(index
, (DWORD_PTR
)GitPath
);
1106 // SVNSLC_COLFILENAME
1107 SetItemText(index
, nCol
++, GitPath
->GetFileOrDirectoryName());
1109 SetItemText(index
, nCol
++, GitPath
->GetFileExtension());
1111 SetItemText(index
, nCol
++, GitPath
->GetActionName());
1113 SetItemText(index
, GetColumnIndex(GITSLC_COLADD
),GitPath
->m_StatAdd
);
1114 SetItemText(index
, GetColumnIndex(GITSLC_COLDEL
),GitPath
->m_StatDel
);
1117 CString modificationDate
;
1118 __int64 filetime
= GitPath
->GetLastWriteTime();
1119 if (filetime
&& (GitPath
->m_Action
!= CTGitPath::LOGACTIONS_DELETED
))
1121 FILETIME
* f
= (FILETIME
*)(__int64
*)&filetime
;
1122 modificationDate
= CLoglistUtils::FormatDateAndTime(CTime(g_Git
.filetime_to_time_t(f
)), DATE_SHORTDATE
, true, relativeTimes
);
1124 SetItemText(index
, GetColumnIndex(GITSLC_COLMODIFICATIONDATE
), modificationDate
);
1127 if (GitPath
->IsDirectory())
1128 SetItemText(index
, GetColumnIndex(GITSLC_COLSIZE
), _T(""));
1131 TCHAR buf
[100] = { 0 };
1132 StrFormatByteSize64(GitPath
->GetFileSize(), buf
, 100);
1133 SetItemText(index
, GetColumnIndex(GITSLC_COLSIZE
), buf
);
1136 SetCheck(index
, GitPath
->m_Checked
);
1137 if (GitPath
->m_Checked
)
1140 if ((GitPath
->m_Action
& CTGitPath::LOGACTIONS_SKIPWORKTREE
) || (GitPath
->m_Action
& CTGitPath::LOGACTIONS_ASSUMEVALID
))
1141 SetItemGroup(index
, 3);
1142 else if (GitPath
->m_Action
& CTGitPath::LOGACTIONS_IGNORE
)
1143 SetItemGroup(index
, 2);
1144 else if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1145 SetItemGroup(index
,1);
1148 SetItemGroup(index
, GitPath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
));
1156 bool CGitStatusListCtrl::SetItemGroup(int item
, int groupindex
)
1158 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1163 i
.mask
= LVIF_GROUPID
;
1166 i
.iGroupId
= groupindex
;
1168 return !!SetItem(&i
);
1171 void CGitStatusListCtrl::OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1173 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1175 if (m_bBlock
|| m_arStatusArray
.empty())
1178 if (m_nSortedColumn
== phdr
->iItem
)
1179 m_bAscending
= !m_bAscending
;
1181 m_bAscending
= TRUE
;
1182 m_nSortedColumn
= phdr
->iItem
;
1183 Show(m_dwShow
, 0, m_bShowFolders
,false,true);
1188 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1190 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1193 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1194 if ((m_bBlock
)&&(m_bBlockUI
))
1196 // if we're blocked, prevent changing of the check state
1197 if ((!ISCHECKED(pNMLV
->uOldState
) && ISCHECKED(pNMLV
->uNewState
))||
1198 (ISCHECKED(pNMLV
->uOldState
) && !ISCHECKED(pNMLV
->uNewState
)))
1203 BOOL
CGitStatusListCtrl::OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1205 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1207 CWnd
* pParent
= GetLogicalParent();
1208 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
1210 pParent
->SendMessage(GITSLNM_ITEMCHANGED
, pNMLV
->iItem
);
1213 if ((pNMLV
->uNewState
==0)||(pNMLV
->uNewState
& LVIS_SELECTED
)||(pNMLV
->uNewState
& LVIS_FOCUSED
))
1219 bool bSelected
= !!(ListView_GetItemState(m_hWnd
, pNMLV
->iItem
, LVIS_SELECTED
) & LVIS_SELECTED
);
1220 int nListItems
= GetItemCount();
1223 // was the item checked?
1225 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1226 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1228 if (GetCheck(pNMLV
->iItem
))
1230 CheckEntry(pNMLV
->iItem
, nListItems
);
1233 POSITION pos
= GetFirstSelectedItemPosition();
1235 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1237 if (index
!= pNMLV
->iItem
)
1238 CheckEntry(index
, nListItems
);
1244 UncheckEntry(pNMLV
->iItem
, nListItems
);
1247 POSITION pos
= GetFirstSelectedItemPosition();
1249 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1251 if (index
!= pNMLV
->iItem
)
1252 UncheckEntry(index
, nListItems
);
1257 GetStatisticsString();
1264 void CGitStatusListCtrl::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1266 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
1271 void CGitStatusListCtrl::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1273 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
1278 void CGitStatusListCtrl::CheckEntry(int index
, int /*nListItems*/)
1280 Locker
lock(m_critSec
);
1281 //FileEntry * entry = GetListEntry(index);
1282 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1283 ASSERT(path
!= NULL
);
1286 m_mapFilenameToChecked
[path
->GetGitPathString()] = true;
1287 SetCheck(index
, TRUE
);
1288 //entry = GetListEntry(index);
1289 // if an unversioned item was checked, then we need to check if
1290 // the parent folders are unversioned too. If the parent folders actually
1291 // are unversioned, then check those too.
1293 if (entry
->status
== git_wc_status_unversioned
)
1295 // we need to check the parent folder too
1296 const CTGitPath
& folderpath
= entry
->path
;
1297 for (int i
=0; i
< nListItems
; ++i
)
1299 FileEntry
* testEntry
= GetListEntry(i
);
1300 ASSERT(testEntry
!= NULL
);
1301 if (testEntry
== NULL
)
1303 if (!testEntry
->checked
)
1305 if (testEntry
->path
.IsAncestorOf(folderpath
) && (!testEntry
->path
.IsEquivalentTo(folderpath
)))
1307 SetEntryCheck(testEntry
,i
,true);
1313 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1314 if ( (entry
->status
== git_wc_status_deleted
) || (m_bCheckChildrenWithParent
) || (bShift
) )
1316 // if a deleted folder gets checked, we have to check all
1317 // children of that folder too.
1318 if (entry
->path
.IsDirectory())
1320 SetCheckOnAllDescendentsOf(entry
, true);
1323 // if a deleted file or folder gets checked, we have to
1324 // check all parents of this item too.
1325 for (int i
=0; i
<nListItems
; ++i
)
1327 FileEntry
* testEntry
= GetListEntry(i
);
1328 ASSERT(testEntry
!= NULL
);
1329 if (testEntry
== NULL
)
1331 if (!testEntry
->checked
)
1333 if (testEntry
->path
.IsAncestorOf(entry
->path
) && (!testEntry
->path
.IsEquivalentTo(entry
->path
)))
1335 if ((testEntry
->status
== git_wc_status_deleted
)||(m_bCheckChildrenWithParent
))
1337 SetEntryCheck(testEntry
,i
,true);
1339 // now we need to check all children of this parent folder
1340 SetCheckOnAllDescendentsOf(testEntry
, true);
1347 if ( !path
->m_Checked
)
1349 path
->m_Checked
= TRUE
;
1354 void CGitStatusListCtrl::UncheckEntry(int index
, int /*nListItems*/)
1356 Locker
lock(m_critSec
);
1357 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1358 ASSERT(path
!= NULL
);
1361 SetCheck(index
, FALSE
);
1362 m_mapFilenameToChecked
[path
->GetGitPathString()] = false;
1363 //entry = GetListEntry(index);
1364 // item was unchecked
1366 if (entry
->path
.IsDirectory())
1368 // disable all files within an unselected folder, except when unchecking a folder with property changes
1369 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1370 if ( (entry
->status
!= git_wc_status_modified
) || (bShift
) )
1372 SetCheckOnAllDescendentsOf(entry
, false);
1375 else if (entry
->status
== git_wc_status_deleted
)
1377 // a "deleted" file was unchecked, so uncheck all parent folders
1378 // and all children of those parents
1379 for (int i
=0; i
<nListItems
; i
++)
1381 FileEntry
* testEntry
= GetListEntry(i
);
1382 ASSERT(testEntry
!= NULL
);
1383 if (testEntry
== NULL
)
1385 if (testEntry
->checked
)
1387 if (testEntry
->path
.IsAncestorOf(entry
->path
))
1389 if (testEntry
->status
== git_wc_status_deleted
)
1391 SetEntryCheck(testEntry
,i
,false);
1394 SetCheckOnAllDescendentsOf(testEntry
, false);
1401 if ( path
->m_Checked
)
1403 path
->m_Checked
= FALSE
;
1407 bool CGitStatusListCtrl::BuildStatistics()
1410 bool bRefetchStatus
= false;
1412 // now gather some statistics
1425 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
1427 int status
=((CTGitPath
*)m_arStatusArray
[i
])->m_Action
;
1429 m_nLineAdded
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatAdd
);
1430 m_nLineDeleted
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatDel
);
1432 if(status
&(CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
1435 if(status
&CTGitPath::LOGACTIONS_DELETED
)
1438 if(status
&(CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_MODIFIED
))
1441 if(status
&CTGitPath::LOGACTIONS_UNMERGED
)
1444 if(status
&(CTGitPath::LOGACTIONS_IGNORE
|CTGitPath::LOGACTIONS_UNVER
))
1447 if(status
&(CTGitPath::LOGACTIONS_REPLACED
))
1450 if(((CTGitPath
*)m_arStatusArray
[i
])->m_Checked
)
1453 return !bRefetchStatus
;
1457 int CGitStatusListCtrl::GetGroupFromPoint(POINT
* ppt
)
1459 // the point must be relative to the upper left corner of the control
1463 if (!IsGroupViewEnabled())
1472 while (((flags
& LVHT_BELOW
) == 0)&&(pt
.y
< rc
.bottom
))
1474 nItem
= HitTest(pt
, &flags
);
1475 if ((flags
& LVHT_ONITEM
)||(flags
& LVHT_EX_GROUP_HEADER
))
1477 // the first item below the point
1479 // check if the point is too much right (i.e. if the point
1480 // is farther to the right than the width of the item)
1482 GetItemRect(nItem
, &r
, LVIR_LABEL
);
1483 if (ppt
->x
> r
.right
)
1487 lv
.mask
= LVIF_GROUPID
;
1490 int groupID
= lv
.iGroupId
;
1491 // now we search upwards and check if the item above this one
1492 // belongs to another group. If it belongs to the same group,
1493 // we're not over a group header
1497 nItem
= HitTest(pt
, &flags
);
1498 if ((flags
& LVHT_ONITEM
)&&(nItem
>= 0))
1500 // the first item below the point
1502 lv2
.mask
= LVIF_GROUPID
;
1505 if (lv2
.iGroupId
!= groupID
)
1520 void CGitStatusListCtrl::OnContextMenuGroup(CWnd
* /*pWnd*/, CPoint point
)
1522 POINT clientpoint
= point
;
1523 ScreenToClient(&clientpoint
);
1524 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint
) >= 0))
1527 if (popup
.CreatePopupMenu())
1530 temp
.LoadString(IDS_STATUSLIST_CHECKGROUP
);
1531 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_CHECKGROUP
, temp
);
1532 temp
.LoadString(IDS_STATUSLIST_UNCHECKGROUP
);
1533 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_UNCHECKGROUP
, temp
);
1534 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1535 bool bCheck
= false;
1538 case IDGITLC_CHECKGROUP
:
1540 // fall through here
1541 case IDGITLC_UNCHECKGROUP
:
1543 int group
= GetGroupFromPoint(&clientpoint
);
1544 // go through all items and check/uncheck those assigned to the group
1545 // but block the OnLvnItemChanged handler
1548 for (int i
=0; i
<GetItemCount(); ++i
)
1550 SecureZeroMemory(&lv
, sizeof(LVITEM
));
1551 lv
.mask
= LVIF_GROUPID
;
1555 if (lv
.iGroupId
== group
)
1557 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
1560 bool bOldCheck
= entry
->m_Checked
;
1561 SetEntryCheck(entry
, i
, bCheck
);
1562 if (bCheck
!= bOldCheck
)
1573 GetStatisticsString();
1583 void CGitStatusListCtrl::OnContextMenuList(CWnd
* pWnd
, CPoint point
)
1586 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1588 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1589 CTGitPath
* filepath
;
1591 int selIndex
= GetSelectionMark();
1592 if ((point
.x
== -1) && (point
.y
== -1))
1595 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1596 ClientToScreen(&rect
);
1597 point
= rect
.CenterPoint();
1599 if ((GetSelectedCount() == 0) && (m_bHasCheckboxes
))
1601 // nothing selected could mean the context menu is requested for
1603 OnContextMenuGroup(pWnd
, point
);
1605 else if (selIndex
>= 0)
1607 //FileEntry * entry = GetListEntry(selIndex);
1609 filepath
= (CTGitPath
* )GetItemData(selIndex
);
1611 ASSERT(filepath
!= NULL
);
1612 if (filepath
== NULL
)
1615 //const CTGitPath& filepath = entry->path;
1616 int wcStatus
= filepath
->m_Action
;
1617 // entry is selected, now show the popup menu
1618 Locker
lock(m_critSec
);
1620 CMenu changelistSubMenu
;
1621 CMenu ignoreSubMenu
;
1623 if (popup
.CreatePopupMenu())
1625 //Add Menu for version controlled file
1627 if (GetSelectedCount() > 0 && wcStatus
& CTGitPath::LOGACTIONS_UNMERGED
)
1629 if (GetSelectedCount() == 1 && (m_dwContextMenus
& GITSLC_POPCONFLICT
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1631 popup
.AppendMenuIcon(IDGITLC_EDITCONFLICT
, IDS_MENUCONFLICT
, IDI_CONFLICT
);
1633 if (m_dwContextMenus
& GITSLC_POPRESOLVE
)
1635 popup
.AppendMenuIcon(IDGITLC_RESOLVECONFLICT
, IDS_STATUSLIST_CONTEXT_RESOLVED
, IDI_RESOLVE
);
1637 if ((m_dwContextMenus
& GITSLC_POPRESOLVE
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1639 popup
.AppendMenuIcon(IDGITLC_RESOLVETHEIRS
, IDS_SVNPROGRESS_MENUUSETHEIRS
, IDI_RESOLVE
);
1640 popup
.AppendMenuIcon(IDGITLC_RESOLVEMINE
, IDS_SVNPROGRESS_MENUUSEMINE
, IDI_RESOLVE
);
1642 if ((m_dwContextMenus
& GITSLC_POPCONFLICT
)||(m_dwContextMenus
& GITSLC_POPRESOLVE
))
1643 popup
.AppendMenu(MF_SEPARATOR
);
1646 if (GetSelectedCount() > 0)
1648 if (wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
))
1650 if (m_dwContextMenus
& GITSLC_POPADD
)
1652 //if ( entry->IsFolder() )
1654 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1658 popup
.AppendMenuIcon(IDGITLC_ADD
, IDS_STATUSLIST_CONTEXT_ADD
, IDI_ADD
);
1661 if (m_dwContextMenus
& GITSLC_POPCOMMIT
)
1663 popup
.AppendMenuIcon(IDGITLC_COMMIT
, IDS_STATUSLIST_CONTEXT_COMMIT
, IDI_COMMIT
);
1668 if (!(wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
)) && GetSelectedCount() > 0)
1670 bool bEntryAdded
= false;
1671 if (m_dwContextMenus
& GITSLC_POPCOMPAREWITHBASE
)
1673 if(filepath
->m_ParentNo
& MERGE_MASK
)
1674 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_TREE_DIFF
, IDI_DIFF
);
1676 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_LOG_COMPAREWITHBASE
, IDI_DIFF
);
1678 popup
.SetDefaultItem(IDGITLC_COMPARE
, FALSE
);
1682 if (!g_Git
.IsInitRepos() && (m_dwContextMenus
& GITSLC_POPGNUDIFF
))
1684 popup
.AppendMenuIcon(IDGITLC_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1688 if ((m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPAREWC
)) && m_bHasWC
)
1690 if ((!m_CurrentVersion
.IsEmpty()) && m_CurrentVersion
!= GIT_REV_ZERO
)
1692 popup
.AppendMenuIcon(IDGITLC_COMPAREWC
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1698 popup
.AppendMenu(MF_SEPARATOR
);
1701 if (!m_Rev1
.IsEmpty() && !m_Rev2
.IsEmpty())
1703 if(GetSelectedCount() == 1)
1705 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPARETWOREVISIONS
))
1707 popup
.AppendMenuIcon(IDGITLC_COMPARETWOREVISIONS
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1708 popup
.SetDefaultItem(IDGITLC_COMPARETWOREVISIONS
, FALSE
);
1710 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_GNUDIFF2REVISIONS
))
1712 popup
.AppendMenuIcon(IDGITLC_GNUDIFF2REVISIONS
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1718 if (GetSelectedCount() > 0)
1720 if ((GetSelectedCount() == 2) && (m_dwContextMenus
& GITSLC_POPCOMPARETWOFILES
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1722 POSITION pos
= GetFirstSelectedItemPosition();
1723 int index
= GetNextSelectedItem(pos
);
1726 CTGitPath
* entry2
= NULL
;
1727 entry2
= (CTGitPath
*)GetItemData(index
);
1728 bool firstEntryExistsAndIsFile
= entry2
&& !entry2
->IsDirectory();
1729 index
= GetNextSelectedItem(pos
);
1732 entry2
= (CTGitPath
* )GetItemData(index
);
1733 if (firstEntryExistsAndIsFile
&& entry2
&& !entry2
->IsDirectory())
1734 popup
.AppendMenuIcon(IDGITLC_COMPARETWOFILES
, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES
, IDI_DIFF
);
1740 if ( (GetSelectedCount() >0 ) && (!(wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
))) && m_bHasWC
)
1742 if ((m_dwContextMenus
& GITSLC_POPCOMMIT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && !(wcStatus
& (CTGitPath::LOGACTIONS_SKIPWORKTREE
| CTGitPath::LOGACTIONS_ASSUMEVALID
)))
1744 popup
.AppendMenuIcon(IDGITLC_COMMIT
, IDS_STATUSLIST_CONTEXT_COMMIT
, IDI_COMMIT
);
1747 if ((m_dwContextMenus
& GITSLC_POPREVERT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1749 popup
.AppendMenuIcon(IDGITLC_REVERT
, IDS_MENUREVERT
, IDI_REVERT
);
1752 if ((m_dwContextMenus
& GITSLC_POPSKIPWORKTREE
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && !(wcStatus
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_UNMERGED
| CTGitPath::LOGACTIONS_SKIPWORKTREE
)))
1754 popup
.AppendMenuIcon(IDGITLC_SKIPWORKTREE
, IDS_STATUSLIST_SKIPWORKTREE
);
1757 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
| CTGitPath::LOGACTIONS_ASSUMEVALID
)))
1759 popup
.AppendMenuIcon(IDGITLC_ASSUMEVALID
, IDS_MENUASSUMEVALID
);
1762 if ((m_dwContextMenus
& GITLC_POPUNSETIGNORELOCALCHANGES
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && (wcStatus
& (CTGitPath::LOGACTIONS_SKIPWORKTREE
| CTGitPath::LOGACTIONS_ASSUMEVALID
)))
1764 popup
.AppendMenuIcon(IDGITLC_UNSETIGNORELOCALCHANGES
, IDS_STATUSLIST_UNSETIGNORELOCALCHANGES
);
1767 if (m_dwContextMenus
& GITSLC_POPRESTORE
&& !filepath
->IsDirectory())
1769 if (m_restorepaths
.find(filepath
->GetWinPathString()) == m_restorepaths
.end())
1770 popup
.AppendMenuIcon(IDGITLC_CREATERESTORE
, IDS_MENUCREATERESTORE
, IDI_RESTORE
);
1772 popup
.AppendMenuIcon(IDGITLC_RESTOREPATH
, IDS_MENURESTORE
, IDI_RESTORE
);
1775 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOREV
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1776 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1778 popup
.AppendMenuIcon(IDGITLC_REVERTTOREV
, IDS_LOG_POPUP_REVERTTOREV
, IDI_REVERT
);
1781 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOPARENT
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1782 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_ADDED
))
1784 popup
.AppendMenuIcon(IDGITLC_REVERTTOPARENT
, IDS_LOG_POPUP_REVERTTOPARENT
, IDI_REVERT
);
1788 if ((GetSelectedCount() == 1)&&(!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
))
1789 &&(!(wcStatus
& CTGitPath::LOGACTIONS_IGNORE
)))
1791 if (m_dwContextMenus
& GITSLC_POPSHOWLOG
)
1793 popup
.AppendMenuIcon(IDGITLC_LOG
, IDS_REPOBROWSE_SHOWLOG
, IDI_LOG
);
1795 if (m_dwContextMenus
& GITSLC_POPSHOWLOGSUBMODULE
&& filepath
->IsDirectory())
1797 popup
.AppendMenuIcon(IDGITLC_LOGSUBMODULE
, IDS_LOG_SUBMODULE
, IDI_LOG
);
1799 if (m_dwContextMenus
& GITSLC_POPSHOWLOGOLDNAME
&& (wcStatus
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !filepath
->GetGitOldPathString().IsEmpty()))
1801 popup
.AppendMenuIcon(IDGITLC_LOGOLDNAME
, IDS_STATUSLIST_SHOWLOGOLDNAME
, IDI_LOG
);
1803 if (m_dwContextMenus
& GITSLC_POPBLAME
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
)
1805 popup
.AppendMenuIcon(IDGITLC_BLAME
, IDS_MENUBLAME
, IDI_BLAME
);
1809 if (GetSelectedCount() > 0)
1811 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_EXPORT
)) && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1812 popup
.AppendMenuIcon(IDGITLC_EXPORT
, IDS_LOG_POPUP_EXPORT
, IDI_EXPORT
);
1815 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1816 if ( (GetSelectedCount() == 1) )
1818 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_SAVEAS
) && ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1820 popup
.AppendMenuIcon(IDGITLC_SAVEAS
, IDS_LOG_POPUP_SAVE
, IDI_SAVEAS
);
1823 if (m_dwContextMenus
& GITSLC_POPOPEN
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1825 popup
.AppendMenuIcon(IDGITLC_VIEWREV
, IDS_LOG_POPUP_VIEWREV
);
1826 popup
.AppendMenuIcon(IDGITLC_OPEN
, IDS_REPOBROWSE_OPEN
, IDI_OPEN
);
1827 popup
.AppendMenuIcon(IDGITLC_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1828 if (wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
)) {
1829 popup
.SetDefaultItem(IDGITLC_OPEN
, FALSE
);
1833 if (m_dwContextMenus
& GITSLC_POPEXPLORE
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
)
1835 popup
.AppendMenuIcon(IDGITLC_EXPLORE
, IDS_STATUSLIST_CONTEXT_EXPLORE
, IDI_EXPLORER
);
1838 if (m_dwContextMenus
& GITSLC_PREPAREDIFF
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1840 popup
.AppendMenu(MF_SEPARATOR
);
1841 popup
.AppendMenuIcon(IDGITLC_PREPAREDIFF
, IDS_PREPAREDIFF
, IDI_DIFF
);
1842 if (!m_sMarkForDiffFilename
.IsEmpty())
1845 if (filepath
&& filepath
->GetGitPathString() == m_sMarkForDiffFilename
)
1846 diffWith
= m_sMarkForDiffVersion
;
1849 PathCompactPathEx(diffWith
.GetBuffer(40), m_sMarkForDiffFilename
, 39, 0);
1850 diffWith
.ReleaseBuffer();
1851 diffWith
+= _T(":") + m_sMarkForDiffVersion
.Left(g_Git
.GetShortHASHLength());
1854 menuEntry
.Format(IDS_MENUDIFFNOW
, (LPCTSTR
)diffWith
);
1855 popup
.AppendMenuIcon(IDGITLC_PREPAREDIFF_COMPARE
, menuEntry
, IDI_DIFF
);
1859 if (GetSelectedCount() > 0)
1861 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
1863 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1865 // 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))
1868 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
1870 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
1872 if ((wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
))/*||(wcStatus == git_wc_status_deleted)*/)
1874 if (m_dwContextMenus
& GITSLC_POPDELETE
)
1876 popup
.AppendMenuIcon(IDGITLC_DELETE
, IDS_MENUREMOVE
, IDI_DELETE
);
1879 if ( (wcStatus
& CTGitPath::LOGACTIONS_UNVER
|| wcStatus
& CTGitPath::LOGACTIONS_DELETED
) )
1881 if (m_dwContextMenus
& GITSLC_POPIGNORE
)
1884 CTGitPathList ignorelist
;
1885 FillListOfSelectedItemPaths(ignorelist
);
1886 //check if all selected entries have the same extension
1887 bool bSameExt
= true;
1889 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
1891 if (sExt
.IsEmpty() && (i
==0))
1892 sExt
= ignorelist
[i
].GetFileExtension();
1893 else if (sExt
.CompareNoCase(ignorelist
[i
].GetFileExtension())!=0)
1898 if (ignoreSubMenu
.CreateMenu())
1901 if (ignorelist
.GetCount()==1)
1902 ignorepath
= ignorelist
[0].GetFileOrDirectoryName();
1904 ignorepath
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1905 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNORE
, ignorepath
);
1906 ignorepath
= _T("*")+sExt
;
1907 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREMASK
, ignorepath
);
1908 if (ignorelist
.GetCount() == 1 && !ignorelist
[0].GetContainingDirectory().GetGitPathString().IsEmpty())
1909 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREFOLDER
, ignorelist
[0].GetContainingDirectory().GetGitPathString());
1911 temp
.LoadString(IDS_MENUIGNORE
);
1912 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)ignoreSubMenu
.m_hMenu
, temp
);
1918 if (ignorelist
.GetCount()==1)
1920 temp
.LoadString(IDS_MENUIGNORE
);
1924 temp
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1926 popup
.AppendMenuIcon(IDGITLC_IGNORE
, temp
, IDI_IGNORE
);
1927 temp
.Format(IDS_MENUIGNOREMULTIPLEMASK
, ignorelist
.GetCount());
1928 popup
.AppendMenuIcon(IDGITLC_IGNOREMASK
, temp
, IDI_IGNORE
);
1936 if (GetSelectedCount() > 0)
1938 popup
.AppendMenu(MF_SEPARATOR
);
1939 popup
.AppendMenuIcon(IDGITLC_COPY
, IDS_STATUSLIST_CONTEXT_COPY
, IDI_COPYCLIP
);
1940 popup
.AppendMenuIcon(IDGITLC_COPYEXT
, IDS_STATUSLIST_CONTEXT_COPYEXT
, IDI_COPYCLIP
);
1942 if ((m_dwContextMenus
& SVNSLC_POPCHANGELISTS
))
1943 &&(wcStatus
!= git_wc_status_unversioned
)&&(wcStatus
!= git_wc_status_none
))
1945 popup
.AppendMenu(MF_SEPARATOR
);
1946 // changelist commands
1947 size_t numChangelists
= GetNumberOfChangelistsInSelection();
1948 if (numChangelists
> 0)
1950 popup
.AppendMenuIcon(IDSVNLC_REMOVEFROMCS
, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS
);
1952 if ((!entry
->IsFolder())&&(changelistSubMenu
.CreateMenu()))
1955 temp
.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS
);
1956 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATECS
, temp
);
1958 if (entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
))
1960 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1961 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATEIGNORECS
, SVNSLC_IGNORECHANGELIST
);
1964 if (!m_changelists
.empty())
1966 // find the changelist names
1967 bool bNeedSeparator
= true;
1968 int cmdID
= IDSVNLC_MOVETOCS
;
1969 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
1971 if ((entry
->changelist
.Compare(it
->first
))&&(it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)))
1975 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1976 bNeedSeparator
= false;
1978 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, cmdID
, it
->first
);
1983 temp
.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS
);
1984 popup
.AppendMenu(MF_POPUP
|MF_STRING
, (UINT_PTR
)changelistSubMenu
.GetSafeHmenu(), temp
);
1990 m_hShellMenu
= nullptr;
1991 if (pfnSHCreateDefaultContextMenu
&& pfnAssocCreateForClasses
&& GetSelectedCount() > 0 && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
&& (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && shellMenu
.CreatePopupMenu())
1993 // insert the shell context menu
1994 popup
.AppendMenu(MF_SEPARATOR
);
1995 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)shellMenu
.m_hMenu
, CString(MAKEINTRESOURCE(IDS_STATUSLIST_CONTEXT_SHELL
)));
1996 m_hShellMenu
= shellMenu
.m_hMenu
;
1999 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, point
.x
, point
.y
, this, 0);
2000 g_IContext2
= nullptr;
2001 g_IContext3
= nullptr;
2004 if (cmd
>= SHELL_MIN_CMD
&& cmd
<= SHELL_MAX_CMD
) // see if returned idCommand belongs to shell menu entries)
2006 CMINVOKECOMMANDINFOEX cmi
= { 0 };
2007 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFOEX
);
2008 cmi
.fMask
= CMIC_MASK_UNICODE
| CMIC_MASK_PTINVOKE
;
2009 if (GetKeyState(VK_CONTROL
) < 0)
2010 cmi
.fMask
|= CMIC_MASK_CONTROL_DOWN
;
2012 cmi
.fMask
|= CMIC_MASK_SHIFT_DOWN
;
2014 cmi
.lpVerb
= MAKEINTRESOURCEA(cmd
- SHELL_MIN_CMD
);
2015 cmi
.lpVerbW
= MAKEINTRESOURCEW(cmd
- SHELL_MIN_CMD
);
2016 cmi
.nShow
= SW_SHOWNORMAL
;
2017 cmi
.ptInvoke
= point
;
2019 m_pContextMenu
->InvokeCommand((LPCMINVOKECOMMANDINFO
)&cmi
);
2023 m_pContextMenu
->Release();
2024 m_pContextMenu
= nullptr;
2028 delete g_pFolderhook
;
2029 g_pFolderhook
= nullptr;
2031 if (g_psfDesktopFolder
)
2033 g_psfDesktopFolder
->Release();
2034 g_psfDesktopFolder
= nullptr;
2036 for (int i
= 0; i
< g_pidlArrayItems
; i
++)
2039 CoTaskMemFree(g_pidlArray
[i
]);
2042 CoTaskMemFree(g_pidlArray
);
2043 g_pidlArray
= nullptr;
2044 g_pidlArrayItems
= 0;
2047 AfxGetApp()->DoWaitCursor(1);
2048 //int iItemCountBeforeMenuCmd = GetItemCount();
2049 //bool bForce = false;
2052 case IDGITLC_VIEWREV
:
2053 OpenFile(filepath
, ALTERNATIVEEDITOR
);
2057 OpenFile(filepath
,OPEN
);
2060 case IDGITLC_OPENWITH
:
2061 OpenFile(filepath
,OPEN_WITH
);
2064 case IDGITLC_EXPLORE
:
2065 CAppUtils::ExploreTo(GetSafeHwnd(), g_Git
.CombinePath(filepath
));
2068 case IDGITLC_PREPAREDIFF
:
2071 m_sMarkForDiffFilename
= filepath
->GetGitPathString();
2072 m_sMarkForDiffVersion
= m_CurrentVersion
;
2075 case IDGITLC_PREPAREDIFF_COMPARE
:
2080 CTGitPath
savedFile(m_sMarkForDiffFilename
);
2081 CGitDiff::Diff(filepath
, &savedFile
, m_CurrentVersion
, m_sMarkForDiffVersion
);
2085 case IDGITLC_CREATERESTORE
:
2087 POSITION pos
= GetFirstSelectedItemPosition();
2090 int index
= GetNextSelectedItem(pos
);
2091 CTGitPath
* entry2
= (CTGitPath
* )GetItemData(index
);
2092 ASSERT(entry2
!= NULL
);
2093 if (entry2
== NULL
|| entry2
->IsDirectory())
2095 if (m_restorepaths
.find(entry2
->GetWinPathString()) != m_restorepaths
.end())
2097 CTGitPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2098 // delete the temp file: the temp file has the FILE_ATTRIBUTE_TEMPORARY flag set
2099 // and copying the real file over it would leave that temp flag.
2100 DeleteFile(tempFile
.GetWinPath());
2101 if (CopyFile(g_Git
.CombinePath(entry2
), tempFile
.GetWinPath(), FALSE
))
2103 m_restorepaths
[entry2
->GetWinPathString()] = tempFile
.GetWinPathString();
2104 SetItemState(index
, INDEXTOOVERLAYMASK(OVL_RESTORE
), LVIS_OVERLAYMASK
);
2111 case IDGITLC_RESTOREPATH
:
2113 if (CMessageBox::Show(m_hWnd
, IDS_STATUSLIST_RESTOREPATH
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_RESTOREBUTTON
, IDS_ABORTBUTTON
) == 2)
2115 POSITION pos
= GetFirstSelectedItemPosition();
2118 int index
= GetNextSelectedItem(pos
);
2119 CTGitPath
* entry2
= (CTGitPath
* )GetItemData(index
);
2120 ASSERT(entry2
!= NULL
);
2123 if (m_restorepaths
.find(entry2
->GetWinPathString()) == m_restorepaths
.end())
2125 if (CopyFile(m_restorepaths
[entry2
->GetWinPathString()], g_Git
.CombinePath(entry2
), FALSE
))
2127 m_restorepaths
.erase(entry2
->GetWinPathString());
2128 SetItemState(index
, 0, LVIS_OVERLAYMASK
);
2135 // Compare current version and work copy.
2136 case IDGITLC_COMPAREWC
:
2138 if (!CheckMultipleDiffs())
2140 POSITION pos
= GetFirstSelectedItemPosition();
2143 int index
= GetNextSelectedItem(pos
);
2149 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2150 case IDGITLC_COMPARE
:
2152 if (!CheckMultipleDiffs())
2154 POSITION pos
= GetFirstSelectedItemPosition();
2157 int index
= GetNextSelectedItem(pos
);
2163 case IDGITLC_COMPARETWOREVISIONS
:
2165 POSITION pos
= GetFirstSelectedItemPosition();
2168 int index
= GetNextSelectedItem(pos
);
2169 StartDiffTwo(index
);
2174 case IDGITLC_COMPARETWOFILES
:
2176 POSITION pos
= GetFirstSelectedItemPosition();
2177 CTGitPath
* firstfilepath
= NULL
, * secondfilepath
= NULL
;
2180 firstfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
2181 ASSERT(firstfilepath
!= NULL
);
2182 if (firstfilepath
== NULL
)
2185 secondfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
2186 ASSERT(secondfilepath
!= NULL
);
2187 if (secondfilepath
== NULL
)
2191 sCmd
.Format(_T("/command:diff /path:\"%s\" /endrev:%s /path2:\"%s\" /startrev:%s /hwnd:%p"), firstfilepath
->GetWinPath(), firstfilepath
->Exists() ? GIT_REV_ZERO
: _T("HEAD"), secondfilepath
->GetWinPath(), secondfilepath
->Exists() ? GIT_REV_ZERO
: _T("HEAD"), (void*)m_hWnd
);
2192 CAppUtils::RunTortoiseGitProc(sCmd
);
2197 case IDGITLC_GNUDIFF1
:
2199 POSITION pos
= GetFirstSelectedItemPosition();
2202 CTGitPath
* selectedFilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
2203 if (m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2207 fromwhere
= _T("~1");
2208 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, GitRev::GetHead() + fromwhere
, *selectedFilepath
, GitRev::GetWorkingCopy());
2212 if ((selectedFilepath
->m_ParentNo
& (PARENT_MASK
| MERGE_MASK
)) == 0)
2213 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, m_CurrentVersion
+ _T("~1"), *selectedFilepath
, m_CurrentVersion
);
2217 if (!(selectedFilepath
->m_ParentNo
& MERGE_MASK
))
2218 str
.Format(_T("%s^%d"), m_CurrentVersion
, (selectedFilepath
->m_ParentNo
& PARENT_MASK
) + 1);
2220 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, str
, *selectedFilepath
, m_CurrentVersion
, false, false, false, false, !!(selectedFilepath
->m_ParentNo
& MERGE_MASK
));
2227 case IDGITLC_GNUDIFF2REVISIONS
:
2229 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *filepath
, m_Rev2
, *filepath
, m_Rev1
);
2235 CTGitPathList paths
;
2236 FillListOfSelectedItemPaths(paths
, true);
2238 CGitProgressDlg progDlg
;
2239 AddProgressCommand addCommand
;
2240 progDlg
.SetCommand(&addCommand
);
2241 addCommand
.SetPathList(paths
);
2242 progDlg
.SetItemCount(paths
.GetCount());
2245 // reset unchecked status
2246 POSITION pos
= GetFirstSelectedItemPosition();
2248 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2250 m_mapFilenameToChecked
.erase(((CTGitPath
*)GetItemData(index
))->GetGitPathString());
2253 if (NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2254 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2260 case IDGITLC_DELETE
:
2261 DeleteSelectedFiles();
2266 CAppUtils::LaunchTortoiseBlame(g_Git
.CombinePath(filepath
), m_CurrentVersion
);
2271 case IDGITLC_LOGSUBMODULE
:
2274 sCmd
.Format(_T("/command:log /path:\"%s\""), g_Git
.CombinePath(filepath
));
2275 if (cmd
== IDGITLC_LOG
&& filepath
->IsDirectory())
2276 sCmd
+= _T(" /submodule");
2277 if (!m_sDisplayedBranch
.IsEmpty())
2278 sCmd
+= _T(" /range:\"") + m_sDisplayedBranch
+ _T("\"");
2279 CAppUtils::RunTortoiseGitProc(sCmd
, false, !(cmd
== IDGITLC_LOGSUBMODULE
));
2283 case IDGITLC_LOGOLDNAME
:
2285 CTGitPath
oldName(filepath
->GetGitOldPathString());
2287 sCmd
.Format(_T("/command:log /path:\"%s\""), g_Git
.CombinePath(oldName
));
2288 if (!m_sDisplayedBranch
.IsEmpty())
2289 sCmd
+= _T(" /range:\"") + m_sDisplayedBranch
+ _T("\"");
2290 CAppUtils::RunTortoiseGitProc(sCmd
);
2294 case IDGITLC_EDITCONFLICT
:
2296 if (CAppUtils::ConflictEdit(*filepath
, false, m_bIsRevertTheirMy
, GetLogicalParent() ? GetLogicalParent()->GetSafeHwnd() : nullptr))
2298 CString conflictedFile
= g_Git
.CombinePath(filepath
);
2299 if (!PathFileExists(conflictedFile
) && NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2300 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2305 case IDGITLC_RESOLVETHEIRS
: //follow up
2306 case IDGITLC_RESOLVEMINE
: //follow up
2307 case IDGITLC_RESOLVECONFLICT
:
2309 if (CMessageBox::Show(m_hWnd
, IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
)==IDYES
)
2311 POSITION pos
= GetFirstSelectedItemPosition();
2315 index
= GetNextSelectedItem(pos
);
2316 CTGitPath
* fentry
=(CTGitPath
*) this->GetItemData(index
);
2320 CAppUtils::resolve_with resolveWith
= CAppUtils::RESOLVE_WITH_CURRENT
;
2321 if (((!this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVETHEIRS
) || ((this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVEMINE
))
2322 resolveWith
= CAppUtils::RESOLVE_WITH_THEIRS
;
2323 else if (((!this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVEMINE
) || ((this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVETHEIRS
))
2324 resolveWith
= CAppUtils::RESOLVE_WITH_MINE
;
2325 if (CAppUtils::ResolveConflict(*fentry
, resolveWith
) == 0 && fentry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
&& CRegDWORD(_T("Software\\TortoiseGit\\RefreshFileListAfterResolvingConflict"), TRUE
) == TRUE
)
2327 CWnd
* pParent
= GetLogicalParent();
2328 if (pParent
&& pParent
->GetSafeHwnd())
2329 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2334 Show(m_dwShow
, 0, m_bShowFolders
,0,true);
2339 case IDGITLC_IGNORE
:
2341 CTGitPathList ignorelist
;
2342 //std::vector<CString> toremove;
2343 FillListOfSelectedItemPaths(ignorelist
, true);
2345 if(!CAppUtils::IgnoreFile(ignorelist
,false))
2349 CWnd
* pParent
= GetLogicalParent();
2350 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2352 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2358 case IDGITLC_IGNOREMASK
:
2361 CString ext
=filepath
->GetFileExtension();
2362 CTGitPathList ignorelist
;
2363 FillListOfSelectedItemPaths(ignorelist
, true);
2365 if (!CAppUtils::IgnoreFile(ignorelist
,true))
2369 CWnd
* pParent
= GetLogicalParent();
2370 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2372 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2379 case IDGITLC_IGNOREFOLDER
:
2381 CTGitPathList ignorelist
;
2382 ignorelist
.AddPath(filepath
->GetContainingDirectory());
2384 if (!CAppUtils::IgnoreFile(ignorelist
, false))
2388 CWnd
*pParent
= GetLogicalParent();
2389 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2390 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2395 case IDGITLC_COMMIT
:
2397 CTGitPathList targetList
;
2398 FillListOfSelectedItemPaths(targetList
);
2399 CTGitPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2400 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2401 CString commandline
= _T("/command:commit /pathfile:\"");
2402 commandline
+= tempFile
.GetWinPathString();
2403 commandline
+= _T("\"");
2404 commandline
+= _T(" /deletepathfile");
2405 CAppUtils::RunTortoiseGitProc(commandline
);
2408 case IDGITLC_REVERT
:
2410 // If at least one item is not in the status "added"
2411 // we ask for a confirmation
2412 BOOL bConfirm
= FALSE
;
2413 POSITION pos
= GetFirstSelectedItemPosition();
2415 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2417 //FileEntry * fentry = GetListEntry(index);
2418 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
2419 if(fentry
&& fentry
->m_Action
&CTGitPath::LOGACTIONS_MODIFIED
&& !fentry
->IsDirectory())
2427 str
.Format(IDS_PROC_WARNREVERT
,GetSelectedCount());
2429 if (!bConfirm
|| CMessageBox::Show(this->m_hWnd
, str
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
2431 CTGitPathList targetList
;
2432 FillListOfSelectedItemPaths(targetList
);
2434 // make sure that the list is reverse sorted, so that
2435 // children are removed before any parents
2436 targetList
.SortByPathname(true);
2438 // put all reverted files in the trashbin, except the ones with 'added'
2439 // status because they are not restored by the revert.
2440 CTGitPathList delList
;
2441 POSITION pos2
= GetFirstSelectedItemPosition();
2443 while ((index2
= GetNextSelectedItem(pos2
)) >= 0)
2445 CTGitPath
*entry
=(CTGitPath
*)GetItemData(index2
);
2446 if (entry
&&(!(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
))
2447 && (!(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)) && !entry
->IsDirectory())
2450 fullpath
.SetFromWin(g_Git
.CombinePath(entry
));
2451 delList
.AddPath(fullpath
);
2454 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
2455 delList
.DeleteAllFiles(true);
2457 CString revertToCommit
= _T("HEAD");
2459 revertToCommit
= _T("HEAD~1");
2461 if (g_Git
.Revert(revertToCommit
, targetList
, err
))
2463 CMessageBox::Show(this->m_hWnd
, _T("Revert failed:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2467 bool updateStatusList
= false;
2468 for (int i
= 0 ; i
< targetList
.GetCount(); ++i
)
2470 int nListboxEntries
= GetItemCount();
2471 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2473 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2474 if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && !path
->IsDirectory())
2476 if(path
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2478 path
->m_Action
= CTGitPath::LOGACTIONS_UNVER
;
2479 SetEntryCheck(path
,nItem
,false);
2480 updateStatusList
= true;
2481 #if 0 // revert an added file and some entry will be cloned (part 1/2)
2482 SetItemGroup(nItem
,1);
2483 this->m_StatusFileList
.RemoveItem(*path
);
2484 this->m_UnRevFileList
.AddPath(*path
);
2485 //this->m_IgnoreFileList.RemoveItem(*path);
2490 if (GetCheck(nItem
))
2492 RemoveListEntry(nItem
);
2496 else if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && path
->IsDirectory() && path
->IsWCRoot())
2499 sCmd
.Format(_T("/command:revert /path:\"%s\""), path
->GetGitPathString());
2500 CCommonAppUtils::RunTortoiseGitProc(sCmd
);
2506 #if 0 // revert an added file and some entry will be cloned (part 2/2)
2507 Show(m_dwShow
, 0, m_bShowFolders
,updateStatusList
,true);
2510 if (updateStatusList
&& nullptr != GetLogicalParent() && nullptr != GetLogicalParent()->GetSafeHwnd())
2511 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2518 case IDGITLC_ASSUMEVALID
:
2519 SetGitIndexFlagsForSelectedFiles(IDS_PROC_MARK_ASSUMEVALID
, BST_CHECKED
, BST_INDETERMINATE
);
2521 case IDGITLC_SKIPWORKTREE
:
2522 SetGitIndexFlagsForSelectedFiles(IDS_PROC_MARK_SKIPWORKTREE
, BST_INDETERMINATE
, BST_CHECKED
);
2524 case IDGITLC_UNSETIGNORELOCALCHANGES
:
2525 SetGitIndexFlagsForSelectedFiles(IDS_PROC_UNSET_IGNORELOCALCHANGES
, BST_UNCHECKED
, BST_UNCHECKED
);
2528 CopySelectedEntriesToClipboard(0);
2530 case IDGITLC_COPYEXT
:
2531 CopySelectedEntriesToClipboard((DWORD
)-1);
2533 case IDGITLC_EXPORT
:
2536 case IDGITLC_SAVEAS
:
2537 FileSaveAs(filepath
);
2540 case IDGITLC_REVERTTOREV
:
2541 RevertSelectedItemToVersion();
2543 case IDGITLC_REVERTTOPARENT
:
2544 RevertSelectedItemToVersion(true);
2547 case IDSVNLC_COMMIT
:
2549 CTSVNPathList targetList
;
2550 FillListOfSelectedItemPaths(targetList
);
2551 CTSVNPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2552 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2553 CString commandline
= CPathUtils::GetAppDirectory();
2554 commandline
+= _T("TortoiseGitProc.exe /command:commit /pathfile:\"");
2555 commandline
+= tempFile
.GetWinPathString();
2556 commandline
+= _T("\"");
2557 commandline
+= _T(" /deletepathfile");
2558 CAppUtils::LaunchApplication(commandline
, NULL
, false);
2561 case IDSVNLC_CREATEIGNORECS
:
2562 CreateChangeList(SVNSLC_IGNORECHANGELIST
);
2564 case IDSVNLC_CREATECS
:
2566 CCreateChangelistDlg dlg
;
2567 if (dlg
.DoModal() == IDOK
)
2569 CreateChangeList(dlg
.m_sName
);
2575 if (cmd
< IDSVNLC_MOVETOCS
)
2577 CTSVNPathList changelistItems
;
2578 FillListOfSelectedItemPaths(changelistItems
);
2580 // find the changelist name
2581 CString sChangelist
;
2582 int cmdID
= IDSVNLC_MOVETOCS
;
2584 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
2586 if ((it
->first
.Compare(SVNSLC_IGNORECHANGELIST
))&&(entry
->changelist
.Compare(it
->first
)))
2590 sChangelist
= it
->first
;
2595 if (!sChangelist
.IsEmpty())
2598 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
2600 // The changelists were moved, but we now need to run through the selected items again
2601 // and update their changelist
2602 POSITION pos
= GetFirstSelectedItemPosition();
2604 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2606 FileEntry
* e
= GetListEntry(index
);
2607 e
->changelist
= sChangelist
;
2610 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
2611 SetItemGroup(index
, m_changelists
[e
->changelist
]);
2613 SetItemGroup(index
, 0);
2619 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
2629 AfxGetApp()->DoWaitCursor(-1);
2630 GetStatisticsString();
2631 //int iItemCountAfterMenuCmd = GetItemCount();
2632 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
2634 // CWnd* pParent = GetParent();
2635 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
2637 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
2640 } // if (popup.CreatePopupMenu())
2641 } // if (selIndex >= 0)
2645 void CGitStatusListCtrl::SetGitIndexFlagsForSelectedFiles(UINT message
, BOOL assumevalid
, BOOL skipworktree
)
2647 if (CMessageBox::Show(GetSafeHwnd(), message
, IDS_APPNAME
, MB_YESNO
| MB_DEFBUTTON2
| MB_ICONQUESTION
) != IDYES
)
2650 CAutoRepository
repository(g_Git
.GetGitRepository());
2653 CMessageBox::Show(m_hWnd
, g_Git
.GetLibGit2LastErr(), _T("TortoiseGit"), MB_ICONERROR
);
2657 CAutoIndex gitindex
;
2658 if (git_repository_index(gitindex
.GetPointer(), repository
))
2660 CMessageBox::Show(m_hWnd
, g_Git
.GetLibGit2LastErr(), _T("TortoiseGit"), MB_ICONERROR
);
2664 POSITION pos
= GetFirstSelectedItemPosition();
2666 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2668 CTGitPath
* path
= (CTGitPath
*)GetItemData(index
);
2670 if (path
== nullptr)
2674 if (!git_index_find(&idx
, gitindex
, CUnicodeUtils::GetMulti(path
->GetGitPathString(), CP_UTF8
)))
2676 git_index_entry
*e
= const_cast<git_index_entry
*>(git_index_get_byindex(gitindex
, idx
)); // HACK
2677 if (assumevalid
== BST_UNCHECKED
)
2678 e
->flags
&= ~GIT_IDXENTRY_VALID
;
2679 else if (assumevalid
== BST_CHECKED
)
2680 e
->flags
|= GIT_IDXENTRY_VALID
;
2681 if (skipworktree
== BST_UNCHECKED
)
2682 e
->flags_extended
&= ~GIT_IDXENTRY_SKIP_WORKTREE
;
2683 else if (skipworktree
== BST_CHECKED
)
2684 e
->flags_extended
|= GIT_IDXENTRY_SKIP_WORKTREE
;
2685 git_index_add(gitindex
, e
);
2688 CMessageBox::Show(m_hWnd
, g_Git
.GetLibGit2LastErr(), _T("TortoiseGit"), MB_ICONERROR
);
2691 if (git_index_write(gitindex
))
2693 CMessageBox::Show(m_hWnd
, g_Git
.GetLibGit2LastErr(), _T("TortoiseGit"), MB_ICONERROR
);
2697 if (nullptr != GetLogicalParent() && nullptr != GetLogicalParent()->GetSafeHwnd())
2698 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2703 void CGitStatusListCtrl::OnContextMenuHeader(CWnd
* pWnd
, CPoint point
)
2705 Locker
lock(m_critSec
);
2706 m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
2709 void CGitStatusListCtrl::OnContextMenu(CWnd
* pWnd
, CPoint point
)
2714 OnContextMenuList(pWnd
, point
);
2715 } // if (pWnd == this)
2716 else if (pWnd
== GetHeaderCtrl())
2718 OnContextMenuHeader(pWnd
, point
);
2722 void CGitStatusListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2725 Locker
lock(m_critSec
);
2726 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
2731 if (pNMLV
->iItem
< 0)
2734 CTGitPath
*file
=(CTGitPath
*)GetItemData(pNMLV
->iItem
);
2736 if (file
->m_Action
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
)) {
2737 OpenFile(file
, OPEN
);
2740 if( file
->m_Action
&CTGitPath::LOGACTIONS_UNMERGED
)
2742 if (CAppUtils::ConflictEdit(*file
, false, m_bIsRevertTheirMy
, GetLogicalParent() ? GetLogicalParent()->GetSafeHwnd() : nullptr))
2744 CString conflictedFile
= g_Git
.CombinePath(file
);
2745 if (!PathFileExists(conflictedFile
) && NULL
!= GetLogicalParent() && NULL
!= GetLogicalParent()->GetSafeHwnd())
2746 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2751 if (!m_Rev1
.IsEmpty() && !m_Rev2
.IsEmpty())
2752 StartDiffTwo(pNMLV
->iItem
);
2754 StartDiff(pNMLV
->iItem
);
2758 void CGitStatusListCtrl::StartDiffTwo(int fileindex
)
2763 auto ptr
= (CTGitPath
*)GetItemData(fileindex
);
2766 CTGitPath file1
= *ptr
;
2768 if (file1
.m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2769 CGitDiff::DiffNull(&file1
, m_Rev1
, true);
2770 else if (file1
.m_Action
& CTGitPath::LOGACTIONS_DELETED
)
2771 CGitDiff::DiffNull(&file1
, m_Rev2
, false);
2773 CGitDiff::Diff(&file1
, &file1
, m_Rev1
, m_Rev2
);
2776 void CGitStatusListCtrl::StartDiffWC(int fileindex
)
2782 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2785 auto ptr
= (CTGitPath
*)GetItemData(fileindex
);
2788 CTGitPath file1
= *ptr
;
2789 file1
.m_Action
= 0; // reset action, so that diff is not started as added/deleted file; see issue #1757
2791 CGitDiff::Diff(&file1
,&file1
, GIT_REV_ZERO
, m_CurrentVersion
);
2795 void CGitStatusListCtrl::StartDiff(int fileindex
)
2800 auto ptr
= (CTGitPath
*)GetItemData(fileindex
);
2803 CTGitPath file1
= *ptr
;
2805 if(file1
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
2807 file2
.SetFromGit(file1
.GetGitOldPathString());
2814 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2817 if(m_amend
&& (file1
.m_Action
& CTGitPath::LOGACTIONS_ADDED
) == 0)
2818 fromwhere
= _T("~1");
2819 if( g_Git
.IsInitRepos())
2820 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2822 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_ADDED
)
2823 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2824 m_CurrentVersion
+fromwhere
,true);
2825 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_DELETED
)
2826 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2827 GitRev::GetHead()+fromwhere
,false);
2829 CGitDiff::Diff(&file1
,&file2
,
2830 CString(GIT_REV_ZERO
),
2831 GitRev::GetHead()+fromwhere
);
2836 CString fromwhere
= m_CurrentVersion
+_T("~1");
2838 fromwhere
= m_CurrentVersion
+_T("~2");
2839 bool revfail
= !!g_Git
.GetHash(hash
, fromwhere
);
2840 if (revfail
|| (file1
.m_Action
& file1
.LOGACTIONS_ADDED
))
2842 CGitDiff::DiffNull(&file1
,m_CurrentVersion
,true);
2845 else if (file1
.m_Action
& file1
.LOGACTIONS_DELETED
)
2847 if (file1
.m_ParentNo
> 0)
2848 fromwhere
.Format(_T("%s^%d"), m_CurrentVersion
, file1
.m_ParentNo
+ 1);
2850 CGitDiff::DiffNull(&file1
,fromwhere
,false);
2854 if( file1
.m_ParentNo
& MERGE_MASK
)
2857 CTGitPath base
, theirs
, mine
, merge
;
2860 GetTempPath(temppath
);
2861 temppath
.TrimRight(_T("\\"));
2863 mine
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".LOCAL") + file1
.GetFileExtension());
2864 theirs
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".REMOTE") + file1
.GetFileExtension());
2865 base
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".BASE") + file1
.GetFileExtension());
2868 //create a empty file, incase stage is not three
2869 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2871 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2873 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2876 merge
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".Merged") + file1
.GetFileExtension());
2878 int parent1
=-1, parent2
=-1;
2879 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
2881 if(m_arStatusArray
[i
]->GetGitPathString() == file1
.GetGitPathString())
2883 if(m_arStatusArray
[i
]->m_ParentNo
& MERGE_MASK
)
2890 parent1
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2892 else if (parent2
<0)
2894 parent2
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2900 if(g_Git
.GetOneFile(m_CurrentVersion
, file1
, (CString
&)merge
.GetWinPathString()))
2902 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2908 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent1
+1);
2910 if(g_Git
.GetOneFile(str
, file1
, (CString
&)mine
.GetWinPathString()))
2912 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2919 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent2
+1);
2921 if(g_Git
.GetOneFile(str
, file1
, (CString
&)theirs
.GetWinPathString()))
2923 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2927 if(parent1
>=0 && parent2
>=0)
2929 CString cmd
, output
;
2930 cmd
.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion
, parent1
+1,
2931 this->m_CurrentVersion
,parent2
+1);
2933 if (g_Git
.Run(cmd
, &output
, NULL
, CP_UTF8
))
2938 if(g_Git
.GetOneFile(output
.Left(40), file1
, (CString
&)base
.GetWinPathString()))
2940 CMessageBox::Show(NULL
, IDS_STATUSLIST_FAILEDGETBASEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2944 CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
2950 if( (file1
.m_ParentNo
&PARENT_MASK
) == 0)
2956 str
.Format(_T("^%d"), (file1
.m_ParentNo
&PARENT_MASK
)+1);
2958 CGitDiff::Diff(&file1
,&file2
,
2960 m_CurrentVersion
+str
);
2966 CString
CGitStatusListCtrl::GetStatisticsString(bool simple
)
2968 CString sNormal
= CString(MAKEINTRESOURCE(IDS_STATUSNORMAL
));
2969 CString sAdded
= CString(MAKEINTRESOURCE(IDS_STATUSADDED
));
2970 CString sDeleted
= CString(MAKEINTRESOURCE(IDS_STATUSDELETED
));
2971 CString sModified
= CString(MAKEINTRESOURCE(IDS_STATUSMODIFIED
));
2972 CString sConflicted
= CString(MAKEINTRESOURCE(IDS_STATUSCONFLICTED
));
2973 CString sUnversioned
= CString(MAKEINTRESOURCE(IDS_STATUSUNVERSIONED
));
2974 CString sRenamed
= CString(MAKEINTRESOURCE(IDS_STATUSREPLACED
));
2978 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE1
,
2979 this->m_nLineAdded
,this->m_nLineDeleted
,
2980 (LPCTSTR
)sModified
, m_nModified
,
2981 (LPCTSTR
)sAdded
, m_nAdded
,
2982 (LPCTSTR
)sDeleted
, m_nDeleted
,
2983 (LPCTSTR
)sRenamed
, m_nRenamed
2988 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE2
,
2989 this->m_nLineAdded
,this->m_nLineDeleted
,
2990 (LPCTSTR
)sNormal
, m_nNormal
,
2991 (LPCTSTR
)sUnversioned
, m_nUnversioned
,
2992 (LPCTSTR
)sModified
, m_nModified
,
2993 (LPCTSTR
)sAdded
, m_nAdded
,
2994 (LPCTSTR
)sDeleted
, m_nDeleted
,
2995 (LPCTSTR
)sConflicted
, m_nConflicted
2999 sStats
.Format(IDS_COMMITDLG_STATISTICSFORMAT
, m_nSelected
, GetItemCount());
3002 m_pStatLabel
->SetWindowText(sStats
);
3005 if (m_pSelectButton
)
3007 if (m_nSelected
== 0)
3008 m_pSelectButton
->SetCheck(BST_UNCHECKED
);
3009 else if (m_nSelected
!= GetItemCount())
3010 m_pSelectButton
->SetCheck(BST_INDETERMINATE
);
3012 m_pSelectButton
->SetCheck(BST_CHECKED
);
3015 if (m_pConfirmButton
)
3017 m_pConfirmButton
->EnableWindow(m_nSelected
>0);
3025 CString
CGitStatusListCtrl::GetCommonDirectory(bool bStrict
)
3029 // not strict means that the selected folder has priority
3030 if (!m_StatusFileList
.GetCommonDirectory().IsEmpty())
3031 return m_StatusFileList
.GetCommonDirectory().GetWinPath();
3034 CTGitPath commonBaseDirectory
;
3035 int nListItems
= GetItemCount();
3036 for (int i
=0; i
<nListItems
; ++i
)
3038 CTGitPath baseDirectory
,*p
= (CTGitPath
*)this->GetItemData(i
);
3042 baseDirectory
= p
->GetDirectory();
3044 if(commonBaseDirectory
.IsEmpty())
3046 commonBaseDirectory
= baseDirectory
;
3050 if (commonBaseDirectory
.GetWinPathString().GetLength() > baseDirectory
.GetWinPathString().GetLength())
3052 if (baseDirectory
.IsAncestorOf(commonBaseDirectory
))
3053 commonBaseDirectory
= baseDirectory
;
3057 return g_Git
.CombinePath(commonBaseDirectory
);
3061 void CGitStatusListCtrl::SelectAll(bool bSelect
, bool /*bIncludeNoCommits*/)
3063 CWaitCursor waitCursor
;
3064 // block here so the LVN_ITEMCHANGED messages
3069 int nListItems
= GetItemCount();
3071 m_nSelected
= nListItems
;
3075 for (int i
=0; i
<nListItems
; ++i
)
3077 //FileEntry * entry = GetListEntry(i);
3078 //ASSERT(entry != NULL);
3079 CTGitPath
*path
= (CTGitPath
*) GetItemData(i
);
3082 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
3083 SetEntryCheck(path
,i
,bSelect
);
3086 // unblock before redrawing
3089 GetStatisticsString();
3093 void CGitStatusListCtrl::Check(DWORD dwCheck
, bool check
)
3095 CWaitCursor waitCursor
;
3096 // block here so the LVN_ITEMCHANGED messages
3101 int nListItems
= GetItemCount();
3103 for (int i
= 0; i
< nListItems
; ++i
)
3105 CTGitPath
*entry
= (CTGitPath
*) GetItemData(i
);
3109 DWORD showFlags
= entry
->m_Action
;
3110 if (entry
->IsDirectory())
3111 showFlags
|= GITSLC_SHOWSUBMODULES
;
3113 showFlags
|= GITSLC_SHOWFILES
;
3115 if (check
&& (showFlags
& dwCheck
) && !GetCheck(i
) && !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
&& !(dwCheck
& GITSLC_SHOWSUBMODULES
)))
3117 SetEntryCheck(entry
, i
, true);
3120 else if (!check
&& (showFlags
& dwCheck
) && GetCheck(i
))
3122 SetEntryCheck(entry
, i
, false);
3126 // unblock before redrawing
3129 GetStatisticsString();
3133 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3135 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
3140 CTGitPath
*entry
=(CTGitPath
*)GetItemData(pGetInfoTip
->iItem
);
3143 if (pGetInfoTip
->cchTextMax
> entry
->GetGitPathString().GetLength() + g_Git
.m_CurrentDir
.GetLength())
3145 CString str
= g_Git
.CombinePath(entry
->GetWinPathString());
3146 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, str
.GetBuffer(), pGetInfoTip
->cchTextMax
- 1);
3150 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3152 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
3154 // Take the default processing unless we set this to something else below.
3155 *pResult
= CDRF_DODEFAULT
;
3157 // First thing - check the draw stage. If it's the control's prepaint
3158 // stage, then tell Windows we want messages for every item.
3160 switch (pLVCD
->nmcd
.dwDrawStage
)
3163 *pResult
= CDRF_NOTIFYITEMDRAW
;
3165 case CDDS_ITEMPREPAINT
:
3167 // This is the prepaint stage for an item. Here's where we set the
3168 // item's text color. Our return value will tell Windows to draw the
3169 // item itself, but it will use the new color we set here.
3171 // Tell Windows to paint the control itself.
3172 *pResult
= CDRF_DODEFAULT
;
3176 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
3178 if (m_arStatusArray
.size() > (DWORD_PTR
)pLVCD
->nmcd
.dwItemSpec
)
3181 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3182 CTGitPath
*entry
=(CTGitPath
*)GetItemData((int)pLVCD
->nmcd
.dwItemSpec
);
3188 // black : unversioned, normal
3191 // brown : missing, deleted, replaced
3192 // green : merged (or potential merges)
3193 // red : conflicts or sure conflicts
3194 if(entry
->m_Action
& CTGitPath::LOGACTIONS_GRAY
)
3196 crText
= RGB(128,128,128);
3199 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
3201 crText
= m_Colors
.GetColor(CColors::Conflict
);
3204 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_MODIFIED
))
3206 crText
= m_Colors
.GetColor(CColors::Modified
);
3209 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
3211 crText
= m_Colors
.GetColor(CColors::Added
);
3213 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3215 crText
= m_Colors
.GetColor(CColors::Deleted
);
3217 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
3219 crText
= m_Colors
.GetColor(CColors::Renamed
);
3221 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_MERGED
)
3223 crText
= m_Colors
.GetColor(CColors::Merged
);
3227 crText
= GetSysColor(COLOR_WINDOWTEXT
);
3229 // Store the color back in the NMLVCUSTOMDRAW struct.
3230 pLVCD
->clrText
= crText
;
3237 BOOL
CGitStatusListCtrl::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
3240 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3243 HCURSOR hCur
= LoadCursor(NULL
, IDC_ARROW
);
3245 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3247 HCURSOR hCur
= LoadCursor(NULL
, IDC_WAIT
);
3252 void CGitStatusListCtrl::RemoveListEntry(int index
)
3255 Locker
lock(m_critSec
);
3258 m_arStatusArray
.erase(m_arStatusArray
.begin()+index
);
3261 delete m_arStatusArray
[m_arListArray
[index
]];
3262 m_arStatusArray
.erase(m_arStatusArray
.begin()+m_arListArray
[index
]);
3263 m_arListArray
.erase(m_arListArray
.begin()+index
);
3264 for (int i
=index
; i
< (int)m_arListArray
.size(); ++i
)
3271 ///< Set a checkbox on an entry in the listbox
3272 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
3273 void CGitStatusListCtrl::SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
)
3275 pEntry
->m_Checked
= bCheck
;
3276 m_mapFilenameToChecked
[pEntry
->GetGitPathString()] = bCheck
;
3277 SetCheck(listboxIndex
, bCheck
);
3281 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry
* parentEntry
, bool bCheck
)
3284 int nListItems
= GetItemCount();
3285 for (int j
=0; j
< nListItems
; ++j
)
3287 FileEntry
* childEntry
= GetListEntry(j
);
3288 ASSERT(childEntry
!= NULL
);
3289 if (childEntry
== NULL
|| childEntry
== parentEntry
)
3291 if (childEntry
->checked
!= bCheck
)
3293 if (parentEntry
->path
.IsAncestorOf(childEntry
->path
))
3295 SetEntryCheck(childEntry
,j
,bCheck
);
3311 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList
& pathList
)
3315 int nListItems
= GetItemCount();
3316 for (int i
= 0; i
< nListItems
; ++i
)
3318 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
3319 ASSERT(entry
!= NULL
);
3320 if (entry
->m_Checked
)
3322 pathList
.AddPath(*entry
);
3325 pathList
.SortByPathname();
3330 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
3331 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool /*bNoIgnored*/)
3335 POSITION pos
= GetFirstSelectedItemPosition();
3337 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3339 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
3340 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
3342 pathList
.AddPath(*entry
);
3346 UINT
CGitStatusListCtrl::OnGetDlgCode()
3348 // we want to process the return key and not have that one
3349 // routed to the default pushbutton
3350 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS
;
3353 void CGitStatusListCtrl::OnNMReturn(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
3358 if (!CheckMultipleDiffs())
3360 POSITION pos
= GetFirstSelectedItemPosition();
3363 int index
= GetNextSelectedItem(pos
);
3366 CTGitPath
*file
=(CTGitPath
*)GetItemData(index
);
3367 if (file
== nullptr)
3369 if (file
->m_Action
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
))
3371 OpenFile(file
, OPEN
);
3375 if (!m_Rev1
.IsEmpty() && !m_Rev2
.IsEmpty())
3376 StartDiffTwo(index
);
3383 void CGitStatusListCtrl::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
3385 // Since we catch all keystrokes (to have the enter key processed here instead
3386 // of routed to the default pushbutton) we have to make sure that other
3387 // keys like Tab and Esc still do what they're supposed to do
3388 // Tab = change focus to next/previous control
3389 // Esc = quit the dialog
3394 ::PostMessage(GetLogicalParent()->GetSafeHwnd(), WM_NEXTDLGCTL
, GetKeyState(VK_SHIFT
)&0x8000, 0);
3400 ::SendMessage(GetLogicalParent()->GetSafeHwnd(), WM_CLOSE
, 0, 0);
3405 CListCtrl::OnKeyDown(nChar
, nRepCnt
, nFlags
);
3408 void CGitStatusListCtrl::PreSubclassWindow()
3410 CListCtrl::PreSubclassWindow();
3411 EnableToolTips(TRUE
);
3412 SetWindowTheme(GetSafeHwnd(), L
"Explorer", NULL
);
3415 void CGitStatusListCtrl::OnPaint()
3417 LRESULT defres
= Default();
3418 if ((m_bBusy
)||(m_bEmpty
))
3423 if (m_sBusy
.IsEmpty())
3424 str
.LoadString(IDS_STATUSLIST_BUSYMSG
);
3430 if (m_sEmpty
.IsEmpty())
3431 str
.LoadString(IDS_STATUSLIST_EMPTYMSG
);
3435 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
3437 if (IsWindowEnabled())
3438 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
3440 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
3445 pHC
= GetHeaderCtrl();
3449 pHC
->GetItemRect(0, &rcH
);
3450 rc
.top
+= rcH
.bottom
;
3454 CMyMemDC
memDC(pDC
, &rc
);
3456 memDC
.SetTextColor(clrText
);
3457 memDC
.SetBkColor(clrTextBk
);
3458 memDC
.FillSolidRect(rc
, clrTextBk
);
3460 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
3461 memDC
.DrawText(str
, rc
, DT_CENTER
| DT_VCENTER
|
3462 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
3463 memDC
.SelectObject(oldfont
);
3469 // the Default() call did not process the WM_PAINT message!
3470 // Validate the update region ourselves to avoid
3471 // an endless loop repainting
3473 GetUpdateRect(&rc
, FALSE
);
3474 if (!rc
.IsRectEmpty())
3479 // prevent users from extending our hidden (size 0) columns
3480 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3482 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3485 // prevent any function from extending our hidden (size 0) columns
3486 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3488 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3492 void CGitStatusListCtrl::OnDestroy()
3494 SaveColumnWidths(true);
3495 CListCtrl::OnDestroy();
3498 void CGitStatusListCtrl::OnBeginDrag(NMHDR
* /*pNMHDR*/, LRESULT
* pResult
)
3500 Locker
lock(m_critSec
);
3501 CDropFiles dropFiles
; // class for creating DROPFILES struct
3504 POSITION pos
= GetFirstSelectedItemPosition();
3508 bool bTempDirCreated
= false;
3510 while ( (index
= GetNextSelectedItem(pos
)) >= 0 )
3512 CTGitPath
*path
= (CTGitPath
*)GetItemData(index
); // m_arStatusArray[index] does not work with SyncDlg
3513 if (path
->IsDirectory())
3517 if (!this->m_CurrentVersion
.IsEmpty() && this->m_CurrentVersion
!= GIT_REV_ZERO
)
3519 if (path
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3520 version
.Format(_T("%s^%d"), m_CurrentVersion
, (path
->m_ParentNo
+ 1) & PARENT_MASK
);
3522 version
= m_CurrentVersion
;
3526 if (path
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3527 version
= _T("HEAD");
3531 if (version
.IsEmpty())
3533 TCHAR abspath
[MAX_PATH
] = {0};
3534 PathCombine(abspath
, g_Git
.m_CurrentDir
, path
->GetWinPath());
3539 if (!bTempDirCreated
)
3541 tempDir
= GetTempFile();
3542 ::DeleteFile(tempDir
);
3543 ::CreateDirectory(tempDir
, NULL
);
3544 bTempDirCreated
= true;
3546 tempFile
= tempDir
+ _T("\\") + path
->GetWinPathString();
3547 CString tempSubDir
= tempDir
+ _T("\\") + path
->GetContainingDirectory().GetWinPathString();
3548 CPathUtils::MakeSureDirectoryPathExists(tempSubDir
);
3549 if (g_Git
.GetOneFile(version
, *path
, tempFile
))
3552 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, path
->GetGitPathString(), version
, tempFile
);
3553 CMessageBox::Show(nullptr, g_Git
.GetGitLastErr(out
, CGit::GIT_CMD_GETONEFILE
), _T("TortoiseGit"), MB_OK
);
3557 dropFiles
.AddFile(tempFile
);
3560 if (!dropFiles
.IsEmpty())
3563 dropFiles
.CreateStructure();
3569 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry
/* = false */)
3571 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
3572 for (int col
= 0; col
<= maxcol
; col
++)
3573 if (m_ColumnManager
.IsVisible (col
))
3574 m_ColumnManager
.ColumnResized (col
);
3576 if (bSaveToRegistry
)
3577 m_ColumnManager
.WriteSettings();
3580 bool CGitStatusListCtrl::EnableFileDrop()
3582 m_bFileDropsEnabled
= true;
3586 bool CGitStatusListCtrl::HasPath(const CTGitPath
& path
)
3588 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
3590 if (m_arStatusArray
[i
]->IsEquivalentTo(path
))
3597 BOOL
CGitStatusListCtrl::PreTranslateMessage(MSG
* pMsg
)
3599 if (pMsg
->message
== WM_KEYDOWN
)
3601 switch (pMsg
->wParam
)
3605 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3607 // select all entries
3608 for (int i
=0; i
<GetItemCount(); ++i
)
3610 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3619 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3621 // copy all selected paths to the clipboard
3622 if (GetAsyncKeyState(VK_SHIFT
)&0x8000)
3623 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS
);
3625 CopySelectedEntriesToClipboard(0);
3632 if ((GetSelectedCount() > 0) && (m_dwContextMenus
& GITSLC_POPDELETE
))
3635 CTGitPath
* filepath
= (CTGitPath
*)GetItemData(GetSelectionMark());
3636 if (filepath
!= nullptr && (filepath
->m_Action
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
)))
3637 DeleteSelectedFiles();
3645 return CListCtrl::PreTranslateMessage(pMsg
);
3648 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols
)
3651 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
3652 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3657 if (GetSelectedCount() == 0)
3660 // first add the column titles as the first line
3661 // We needn't head when only path copy
3662 //temp.LoadString(IDS_STATUSLIST_COLFILE);
3663 //sClipboard = temp;
3665 DWORD selection
= 0;
3666 for (int i
= 0, count
= m_ColumnManager
.GetColumnCount(); i
< count
; ++i
)
3667 if ( ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
3668 || ((dwCols
!= 1) && (i
< 32) && ((dwCols
& (1 << i
)) != 0)))
3670 sClipboard
+= _T("\t") + m_ColumnManager
.GetName(i
);
3673 selection
+= 1 << i
;
3677 sClipboard
+= _T("\r\n");
3679 POSITION pos
= GetFirstSelectedItemPosition();
3681 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3683 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
3687 sClipboard
+= entry
->GetWinPathString();
3688 if (selection
& GITSLC_COLFILENAME
)
3690 sClipboard
+= _T("\t")+entry
->GetFileOrDirectoryName();
3692 if (selection
& GITSLC_COLEXT
)
3694 sClipboard
+= _T("\t")+entry
->GetFileExtension();
3697 if (selection
& GITSLC_COLSTATUS
)
3699 sClipboard
+= _T("\t")+entry
->GetActionName();
3702 if (selection
& SVNSLC_COLDATE
)
3704 TCHAR datebuf
[SVN_DATE_BUFFER
];
3705 apr_time_t date
= entry
->last_commit_date
;
3706 SVN::formatDate(datebuf
, date
, true);
3711 sClipboard
+= _T("\t")+temp
;
3713 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
3717 if ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
3720 = entry
->present_props
[m_ColumnManager
.GetName(i
)];
3721 sClipboard
+= _T("\t") + value
;
3725 if (selection
& GITSLC_COLADD
)
3727 sClipboard
+= _T("\t")+entry
->m_StatAdd
;
3729 if (selection
& GITSLC_COLDEL
)
3731 sClipboard
+= _T("\t")+entry
->m_StatDel
;
3734 sClipboard
+= _T("\r\n");
3737 return CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
3740 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
3743 std::set
<CString
> changelists
;
3744 POSITION pos
= GetFirstSelectedItemPosition();
3746 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3748 FileEntry
* entry
= GetListEntry(index
);
3749 if (!entry
->changelist
.IsEmpty())
3750 changelists
.insert(entry
->changelist
);
3752 return changelists
.size();
3757 bool CGitStatusListCtrl::PrepareGroups(bool bForce
/* = false */)
3760 bool bHasGroups
=false;
3763 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
3765 int ParentNo
= m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3767 max
=m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3770 if (!m_UnRevFileList
.IsEmpty() ||
3771 !m_IgnoreFileList
.IsEmpty() ||
3772 !m_LocalChangesIgnoredFileList
.IsEmpty() ||
3779 EnableGroupView(bHasGroups
);
3781 TCHAR groupname
[1024] = { 0 };
3787 grp
.cbSize
= sizeof(LVGROUP
);
3788 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3791 //if(m_UnRevFileList.GetCount()>0)
3794 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MERGEDFILES
)), 1023);
3795 grp
.pszHeader
= groupname
;
3796 grp
.iGroupId
= MERGE_MASK
;
3797 grp
.uAlign
= LVGA_HEADER_LEFT
;
3798 InsertGroup(0, &grp
);
3800 CAutoRepository
repository(g_Git
.GetGitRepository());
3802 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
3803 for (int i
= 0; i
<= max
; ++i
)
3806 str
.Format(IDS_STATUSLIST_GROUP_DIFFWITHPARENT
, i
+1);
3810 rev
.Format(_T("%s^%d"), m_CurrentVersion
, i
+ 1);
3812 if (!CGit::GetHash(repository
, hash
, rev
))
3813 str
+= _T(": ") + hash
.ToString().Left(g_Git
.GetShortHASHLength());
3815 grp
.pszHeader
= str
.GetBuffer();
3816 str
.ReleaseBuffer();
3818 grp
.uAlign
= LVGA_HEADER_LEFT
;
3819 InsertGroup(i
+1, &grp
);
3824 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MODIFIEDFILES
)), 1023);
3825 grp
.pszHeader
= groupname
;
3826 grp
.iGroupId
= groupindex
;
3827 grp
.uAlign
= LVGA_HEADER_LEFT
;
3828 InsertGroup(groupindex
++, &grp
);
3832 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_NOTVERSIONEDFILES
)), 1023);
3833 grp
.pszHeader
= groupname
;
3834 grp
.iGroupId
= groupindex
;
3835 grp
.uAlign
= LVGA_HEADER_LEFT
;
3836 InsertGroup(groupindex
++, &grp
);
3839 //if(m_IgnoreFileList.GetCount()>0)
3841 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNOREDFILES
)), 1023);
3842 grp
.pszHeader
= groupname
;
3843 grp
.iGroupId
= groupindex
;
3844 grp
.uAlign
= LVGA_HEADER_LEFT
;
3845 InsertGroup(groupindex
++, &grp
);
3849 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNORELOCALCHANGES
)), 1023);
3850 grp
.pszHeader
= groupname
;
3851 grp
.iGroupId
= groupindex
;
3852 grp
.uAlign
= LVGA_HEADER_LEFT
;
3853 InsertGroup(groupindex
++, &grp
);
3859 m_bHasIgnoreGroup
= false;
3861 // now add the items which don't belong to a group
3863 grp
.cbSize
= sizeof(LVGROUP
);
3864 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3865 CString
sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET
));
3866 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
3867 grp
.pszHeader
= groupname
;
3868 grp
.iGroupId
= groupindex
;
3869 grp
.uAlign
= LVGA_HEADER_LEFT
;
3870 InsertGroup(groupindex
++, &grp
);
3872 for (std::map
<CString
,int>::iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
3874 if (it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)!=0)
3877 grp
.cbSize
= sizeof(LVGROUP
);
3878 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3879 _tcsncpy_s(groupname
, 1024, it
->first
, 1023);
3880 grp
.pszHeader
= groupname
;
3881 grp
.iGroupId
= groupindex
;
3882 grp
.uAlign
= LVGA_HEADER_LEFT
;
3883 it
->second
= InsertGroup(groupindex
++, &grp
);
3886 m_bHasIgnoreGroup
= true;
3889 if (m_bHasIgnoreGroup
)
3891 // and now add the group 'ignore-on-commit'
3892 std::map
<CString
,int>::iterator it
= m_changelists
.find(SVNSLC_IGNORECHANGELIST
);
3893 if (it
!= m_changelists
.end())
3895 grp
.cbSize
= sizeof(LVGROUP
);
3896 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3897 _tcsncpy_s(groupname
, 1024, SVNSLC_IGNORECHANGELIST
, 1023);
3898 grp
.pszHeader
= groupname
;
3899 grp
.iGroupId
= groupindex
;
3900 grp
.uAlign
= LVGA_HEADER_LEFT
;
3901 it
->second
= InsertGroup(groupindex
, &grp
);
3908 void CGitStatusListCtrl::NotifyCheck()
3910 CWnd
* pParent
= GetLogicalParent();
3911 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3913 pParent
->SendMessage(GITSLNM_CHECKCHANGED
, m_nSelected
);
3917 int CGitStatusListCtrl::UpdateFileList(CTGitPathList
*list
)
3920 m_CurrentVersion
= GIT_REV_ZERO
;
3922 g_Git
.GetWorkingTreeChanges(m_StatusFileList
, m_amend
, list
);
3924 BOOL bDeleteChecked
= FALSE
;
3925 int deleteFromIndex
= 0;
3926 for (int i
= 0; i
< m_StatusFileList
.GetCount(); ++i
)
3928 CTGitPath
* gitpatch
=(CTGitPath
*)&m_StatusFileList
[i
];
3929 gitpatch
->m_Checked
= TRUE
;
3931 if ((gitpatch
->m_Action
== CTGitPath::LOGACTIONS_ADDED
|| gitpatch
->m_Action
== CTGitPath::LOGACTIONS_REPLACED
) && !gitpatch
->Exists())
3933 if (!bDeleteChecked
)
3936 message
.Format(IDS_ASK_REMOVE_FROM_INDEX
, gitpatch
->GetWinPathString());
3937 deleteFromIndex
= CMessageBox::ShowCheck(m_hWnd
, message
, _T("TortoiseGit"), 1, IDI_EXCLAMATION
, CString(MAKEINTRESOURCE(IDS_REMOVE_FROM_INDEX
)), CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON
)), NULL
, NULL
, CString(MAKEINTRESOURCE(IDS_DO_SAME_FOR_REST
)), &bDeleteChecked
);
3939 if (deleteFromIndex
== 1)
3941 g_Git
.Run(_T("git.exe rm -f --cache -- \"") + gitpatch
->GetWinPathString() + _T("\""), nullptr, CP_UTF8
);
3946 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
3949 this->m_bBusy
=FALSE
;
3953 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList
&list
)
3955 m_arStatusArray
.clear();
3956 for (int i
= 0; i
< list
.GetCount(); ++i
)
3958 CTGitPath
* gitpath
=(CTGitPath
*)&list
[i
];
3960 if(gitpath
->m_Action
& CTGitPath::LOGACTIONS_HIDE
)
3963 gitpath
->m_Checked
= TRUE
;
3964 m_arStatusArray
.push_back((CTGitPath
*)&list
[i
]);
3969 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
&list
)
3971 m_UnRevFileList
= list
;
3972 for (int i
= 0; i
< m_UnRevFileList
.GetCount(); ++i
)
3974 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
3975 gitpatch
->m_Checked
= FALSE
;
3976 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
3981 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
*List
)
3984 if (m_UnRevFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
, List
, &err
))
3986 CMessageBox::Show(NULL
, _T("Failed to get UnRev file list\n") + err
, _T("TortoiseGit"), MB_OK
);
3990 for (int i
= 0; i
< m_UnRevFileList
.GetCount(); ++i
)
3992 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
3993 gitpatch
->m_Checked
= FALSE
;
3994 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
3999 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList
*List
)
4002 if (m_IgnoreFileList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, List
, &err
))
4004 CMessageBox::Show(NULL
, _T("Failed to get Ignore file list\n") + err
, _T("TortoiseGit"), MB_OK
);
4008 for (int i
= 0; i
< m_IgnoreFileList
.GetCount(); ++i
)
4010 CTGitPath
* gitpatch
=(CTGitPath
*)&m_IgnoreFileList
[i
];
4011 gitpatch
->m_Checked
= FALSE
;
4012 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
4017 int CGitStatusListCtrl::UpdateLocalChangesIgnoredFileList(CTGitPathList
*list
)
4019 m_LocalChangesIgnoredFileList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
| GIT_IDXENTRY_SKIP_WORKTREE
, list
);
4020 for (int i
= 0; i
< m_LocalChangesIgnoredFileList
.GetCount(); ++i
)
4022 CTGitPath
* gitpatch
= (CTGitPath
*)&m_LocalChangesIgnoredFileList
[i
];
4023 gitpatch
->m_Checked
= FALSE
;
4024 m_arStatusArray
.push_back((CTGitPath
*)&m_LocalChangesIgnoredFileList
[i
]);
4029 int CGitStatusListCtrl::UpdateFileList(int mask
,bool once
,CTGitPathList
*List
)
4031 if(mask
&CGitStatusListCtrl::FILELIST_MODIFY
)
4033 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_MODIFY
)))
4035 UpdateFileList(List
);
4036 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_MODIFY
;
4039 if (mask
& CGitStatusListCtrl::FILELIST_UNVER
|| mask
& CGitStatusListCtrl::FILELIST_IGNORE
)
4041 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_UNVER
)))
4043 UpdateUnRevFileList(List
);
4044 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
4046 if(mask
&CGitStatusListCtrl::FILELIST_IGNORE
&& (once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_IGNORE
))))
4048 UpdateIgnoreFileList(List
);
4049 m_FileLoaded
|= CGitStatusListCtrl::FILELIST_IGNORE
;
4052 if (mask
& CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED
&& (once
|| (!(m_FileLoaded
& CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED
))))
4054 UpdateLocalChangesIgnoredFileList(List
);
4055 m_FileLoaded
|= CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED
;
4060 void CGitStatusListCtrl::Clear()
4063 this->DeleteAllItems();
4064 this->m_arListArray
.clear();
4065 this->m_arStatusArray
.clear();
4066 this->m_changelists
.clear();
4069 bool CGitStatusListCtrl::CheckMultipleDiffs()
4071 UINT selCount
= GetSelectedCount();
4072 if (selCount
> max(3, (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\NumDiffWarning"), 10)))
4075 message
.Format(CString(MAKEINTRESOURCE(IDS_STATUSLIST_WARN_MAXDIFF
)), selCount
);
4076 return ::MessageBox(GetSafeHwnd(), message
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
) == IDYES
;
4080 //////////////////////////////////////////////////////////////////////////
4082 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
)
4084 if(pFmtEtc
->cfFormat
== CF_HDROP
&& medium
.tymed
== TYMED_HGLOBAL
)
4086 HDROP hDrop
= (HDROP
)GlobalLock(medium
.hGlobal
);
4089 TCHAR szFileName
[MAX_PATH
] = {0};
4091 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, NULL
, 0);
4094 clientpoint
.x
= pt
.x
;
4095 clientpoint
.y
= pt
.y
;
4096 ScreenToClient(m_hTargetWnd
, &clientpoint
);
4097 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
4099 CTSVNPathList changelistItems
;
4100 for(UINT i
= 0; i
< cFiles
; ++i
)
4102 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
4103 changelistItems
.AddPath(CTSVNPath(szFileName
));
4105 // find the changelist name
4106 CString sChangelist
;
4107 LONG_PTR nGroup
= m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
);
4108 for (std::map
<CString
, int>::iterator it
= m_pSVNStatusListCtrl
->m_changelists
.begin(); it
!= m_pSVNStatusListCtrl
->m_changelists
.end(); ++it
)
4109 if (it
->second
== nGroup
)
4110 sChangelist
= it
->first
;
4111 if (!sChangelist
.IsEmpty())
4114 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
4116 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
4118 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
4121 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
4124 e
->changelist
= sChangelist
;
4127 if (m_pSVNStatusListCtrl
->m_changelists
.find(e
->changelist
)!=m_pSVNStatusListCtrl
->m_changelists
.end())
4128 m_pSVNStatusListCtrl
->SetItemGroup(index
, m_pSVNStatusListCtrl
->m_changelists
[e
->changelist
]);
4130 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
4136 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4137 if (hParentWnd
!= NULL
)
4138 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
4144 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
4150 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
4152 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
4154 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
4157 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
4160 e
->changelist
= sChangelist
;
4161 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
4166 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4167 if (hParentWnd
!= NULL
)
4168 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
4174 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
4180 for(UINT i
= 0; i
< cFiles
; ++i
)
4182 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
4183 HWND hParentWnd
= GetParent(m_hTargetWnd
);
4184 if (hParentWnd
!= NULL
)
4185 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)szFileName
);
4189 GlobalUnlock(medium
.hGlobal
);
4191 return true; //let base free the medium
4193 HRESULT STDMETHODCALLTYPE
CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
)
4195 CIDropTarget::DragOver(grfKeyState
, pt
, pdwEffect
);
4196 *pdwEffect
= DROPEFFECT_COPY
;
4197 if (m_pSVNStatusListCtrl
)
4200 clientpoint
.x
= pt
.x
;
4201 clientpoint
.y
= pt
.y
;
4202 ScreenToClient(m_hTargetWnd
, &clientpoint
);
4203 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
4205 *pdwEffect
= DROPEFFECT_MOVE
;
4207 else if ((!m_pSVNStatusListCtrl
->m_bFileDropsEnabled
)||(m_pSVNStatusListCtrl
->m_bOwnDrag
))
4209 *pdwEffect
= DROPEFFECT_NONE
;
4217 void CGitStatusListCtrl::FilesExport()
4220 // export all changed files to a folder
4221 CBrowseFolder browseFolder
;
4222 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
4223 if (browseFolder
.Show(GetSafeHwnd(), exportDir
) != CBrowseFolder::OK
)
4226 POSITION pos
= GetFirstSelectedItemPosition();
4228 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4230 CTGitPath
*fd
= (CTGitPath
*)GetItemData(index
);
4231 // we cannot export directories or folders
4232 if (fd
->m_Action
== CTGitPath::LOGACTIONS_DELETED
|| fd
->IsDirectory())
4235 CAppUtils::CreateMultipleDirectory(exportDir
+ _T("\\") + fd
->GetContainingDirectory().GetWinPathString());
4236 CString filename
= exportDir
+ _T("\\") + fd
->GetWinPathString();
4237 if (m_CurrentVersion
== GIT_REV_ZERO
)
4239 if (!CopyFile(g_Git
.CombinePath(fd
), filename
, false))
4241 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
4247 if (g_Git
.GetOneFile(m_CurrentVersion
, *fd
, filename
))
4250 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, fd
->GetGitPathString(), m_CurrentVersion
, filename
);
4251 if (CMessageBox::Show(nullptr, g_Git
.GetGitLastErr(out
, CGit::GIT_CMD_GETONEFILE
), _T("TortoiseGit"), 2, IDI_WARNING
, CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
4258 void CGitStatusListCtrl::FileSaveAs(CTGitPath
*path
)
4261 filename
.Format(_T("%s-%s%s"), path
->GetBaseFilename(), this->m_CurrentVersion
.Left(g_Git
.GetShortHASHLength()), path
->GetFileExtension());
4262 CFileDialog
dlg(FALSE
,NULL
,
4264 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
4266 CString currentpath
;
4267 currentpath
= g_Git
.CombinePath(path
->GetContainingDirectory());
4269 dlg
.m_ofn
.lpstrInitialDir
=currentpath
.GetBuffer();
4272 INT_PTR ret
= dlg
.DoModal();
4273 SetCurrentDirectory(g_Git
.m_CurrentDir
);
4276 filename
= dlg
.GetPathName();
4277 if(m_CurrentVersion
== GIT_REV_ZERO
)
4279 if(!CopyFile(g_Git
.CombinePath(path
), filename
, false))
4281 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
4288 if(g_Git
.GetOneFile(m_CurrentVersion
,*path
,filename
))
4290 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, path
->GetGitPathString(), m_CurrentVersion
, filename
);
4291 CMessageBox::Show(nullptr, g_Git
.GetGitLastErr(out
, CGit::GIT_CMD_GETONEFILE
), _T("TortoiseGit"), MB_OK
);
4299 int CGitStatusListCtrl::RevertSelectedItemToVersion(bool parent
)
4301 if(this->m_CurrentVersion
.IsEmpty())
4303 if(this->m_CurrentVersion
== GIT_REV_ZERO
)
4306 POSITION pos
= GetFirstSelectedItemPosition();
4309 std::map
<CString
, int> versionMap
;
4310 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4312 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
4316 int parentNo
= fentry
->m_ParentNo
& PARENT_MASK
;
4318 ref
.Format(_T("%s^%d"), m_CurrentVersion
, parentNo
+ 1);
4320 if (g_Git
.GetHash(hash
, ref
))
4322 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + ref
+ _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
4326 version
= hash
.ToString();
4329 version
= m_CurrentVersion
;
4331 CString filename
= fentry
->GetGitPathString();
4332 if (!fentry
->GetGitOldPathString().IsEmpty())
4333 filename
= fentry
->GetGitOldPathString();
4334 cmd
.Format(_T("git.exe checkout %s -- \"%s\""), version
, filename
);
4336 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
4338 if (MessageBox(out
, _T("TortoiseGit"), MB_ICONEXCLAMATION
| MB_OKCANCEL
) == IDCANCEL
)
4342 versionMap
[version
]++;
4346 for (auto it
= versionMap
.begin(); it
!= versionMap
.end(); ++it
)
4348 CString versionEntry
;
4349 versionEntry
.Format(IDS_STATUSLIST_FILESREVERTED
, it
->second
, it
->first
);
4350 out
+= versionEntry
+ _T("\r\n");
4353 CMessageBox::Show(nullptr, out
, _T("TortoiseGit"), MB_OK
);
4357 void CGitStatusListCtrl::OpenFile(CTGitPath
*filepath
,int mode
)
4360 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
4362 file
= g_Git
.CombinePath(filepath
);
4367 GetTempPath(temppath
);
4368 TCHAR szTempName
[MAX_PATH
] = {0};
4369 GetTempFileName(temppath
, filepath
->GetBaseFilename(), 0, szTempName
);
4370 CString
temp(szTempName
);
4371 DeleteFile(szTempName
);
4372 CreateDirectory(szTempName
, NULL
);
4373 file
.Format(_T("%s\\%s_%s%s"),
4375 filepath
->GetBaseFilename(),
4376 m_CurrentVersion
.Left(g_Git
.GetShortHASHLength()),
4377 filepath
->GetFileExtension());
4379 if(g_Git
.GetOneFile(m_CurrentVersion
, *filepath
, file
))
4381 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, filepath
->GetGitPathString(), m_CurrentVersion
, file
);
4382 CMessageBox::Show(nullptr, g_Git
.GetGitLastErr(out
, CGit::GIT_CMD_GETONEFILE
), _T("TortoiseGit"), MB_OK
);
4385 SetFileAttributes(file
, FILE_ATTRIBUTE_READONLY
);
4387 if(mode
== ALTERNATIVEEDITOR
)
4389 CAppUtils::LaunchAlternativeEditor(file
);
4394 CAppUtils::ShellOpen(file
, GetSafeHwnd());
4396 CAppUtils::ShowOpenWithDialog(file
, GetSafeHwnd());
4399 void CGitStatusListCtrl::DeleteSelectedFiles()
4402 std::vector
<int> selectIndex
;
4404 POSITION pos
= GetFirstSelectedItemPosition();
4406 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4408 selectIndex
.push_back(index
);
4411 //Create file-list ('\0' separated) for SHFileOperation
4413 for (size_t i
= 0; i
< selectIndex
.size(); ++i
)
4415 index
= selectIndex
[i
];
4417 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
4419 if (path
== nullptr)
4422 filelist
+= path
->GetWinPathString();
4423 filelist
+= _T("|");
4425 filelist
+= _T("|");
4426 int len
= filelist
.GetLength();
4427 std::unique_ptr
<TCHAR
[]> buf(new TCHAR
[len
+ 2]);
4428 _tcscpy_s(buf
.get(), len
+ 2, filelist
);
4429 CStringUtils::PipesToNulls(buf
.get(), len
+ 2);
4430 SHFILEOPSTRUCT fileop
;
4431 fileop
.hwnd
= this->m_hWnd
;
4432 fileop
.wFunc
= FO_DELETE
;
4433 fileop
.pFrom
= buf
.get();
4435 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
4436 fileop
.lpszProgressTitle
= _T("deleting file");
4437 int result
= SHFileOperation(&fileop
);
4439 if ((result
== 0) && (!fileop
.fAnyOperationsAborted
))
4442 POSITION pos2
= NULL
;
4443 while ((pos2
= GetFirstSelectedItemPosition()) != 0)
4445 int index2
= GetNextSelectedItem(pos2
);
4446 if (GetCheck(index2
))
4450 RemoveListEntry(index2
);
4456 BOOL
CGitStatusListCtrl::OnWndMsg(UINT message
, WPARAM wParam
, LPARAM lParam
, LRESULT
* pResult
)
4460 case WM_MENUCHAR
: // only supported by IContextMenu3
4463 g_IContext3
->HandleMenuMsg2(message
, wParam
, lParam
, pResult
);
4469 case WM_MEASUREITEM
:
4471 break; // if wParam != 0 then the message is not menu-related
4474 case WM_INITMENUPOPUP
:
4476 HMENU hMenu
= (HMENU
)wParam
;
4477 if (pfnSHCreateDefaultContextMenu
&& pfnAssocCreateForClasses
&& (hMenu
== m_hShellMenu
) && (GetMenuItemCount(hMenu
) == 0))
4479 // the shell submenu is populated only on request, i.e. right
4480 // before the submenu is shown
4483 delete g_pFolderhook
;
4484 g_pFolderhook
= nullptr;
4486 CTGitPathList targetList
;
4487 FillListOfSelectedItemPaths(targetList
);
4488 if (targetList
.GetCount() > 0)
4490 // get IShellFolder interface of Desktop (root of shell namespace)
4491 if (g_psfDesktopFolder
)
4492 g_psfDesktopFolder
->Release();
4493 SHGetDesktopFolder(&g_psfDesktopFolder
); // needed to obtain full qualified pidl
4495 // ParseDisplayName creates a PIDL from a file system path relative to the IShellFolder interface
4496 // but since we use the Desktop as our interface and the Desktop is the namespace root
4497 // that means that it's a fully qualified PIDL, which is what we need
4501 for (int i
= 0; i
< g_pidlArrayItems
; i
++)
4504 CoTaskMemFree(g_pidlArray
[i
]);
4506 CoTaskMemFree(g_pidlArray
);
4507 g_pidlArray
= nullptr;
4508 g_pidlArrayItems
= 0;
4510 int nItems
= targetList
.GetCount();
4511 g_pidlArray
= (LPITEMIDLIST
*)CoTaskMemAlloc((nItems
+ 10) * sizeof(LPITEMIDLIST
));
4512 SecureZeroMemory(g_pidlArray
, (nItems
+ 10) * sizeof(LPITEMIDLIST
));
4513 int succeededItems
= 0;
4514 PIDLIST_RELATIVE pidl
= nullptr;
4516 size_t bufsize
= 1024;
4517 std::unique_ptr
<WCHAR
[]> filepath(new WCHAR
[bufsize
]);
4518 for (size_t i
= 0; i
< nItems
; i
++)
4520 CString fullPath
= g_Git
.CombinePath(targetList
[i
].GetWinPath());
4521 if (bufsize
< fullPath
.GetLength())
4523 bufsize
= fullPath
.GetLength() + 3;
4524 filepath
= std::unique_ptr
<WCHAR
[]>(new WCHAR
[bufsize
]);
4526 wcscpy_s(filepath
.get(), bufsize
, fullPath
);
4527 if (SUCCEEDED(g_psfDesktopFolder
->ParseDisplayName(nullptr, 0, filepath
.get(), nullptr, &pidl
, nullptr)))
4528 g_pidlArray
[succeededItems
++] = pidl
; // copy pidl to pidlArray
4530 if (succeededItems
== 0)
4532 CoTaskMemFree(g_pidlArray
);
4533 g_pidlArray
= nullptr;
4536 g_pidlArrayItems
= succeededItems
;
4538 if (g_pidlArrayItems
)
4540 CString ext
= targetList
[0].GetFileExtension();
4542 ASSOCIATIONELEMENT
const rgAssocItem
[] =
4544 { ASSOCCLASS_PROGID_STR
, NULL
, ext
},
4545 { ASSOCCLASS_SYSTEM_STR
, NULL
, ext
},
4546 { ASSOCCLASS_APP_STR
, NULL
, ext
},
4547 { ASSOCCLASS_STAR
, NULL
, NULL
},
4548 { ASSOCCLASS_FOLDER
, NULL
, NULL
},
4550 IQueryAssociations
* pIQueryAssociations
;
4551 pfnAssocCreateForClasses(rgAssocItem
, ARRAYSIZE(rgAssocItem
), IID_IQueryAssociations
, (void**)&pIQueryAssociations
);
4553 g_pFolderhook
= new CIShellFolderHook(g_psfDesktopFolder
, targetList
);
4554 LPCONTEXTMENU icm1
= nullptr;
4556 DEFCONTEXTMENU dcm
= { 0 };
4558 dcm
.psf
= g_pFolderhook
;
4559 dcm
.cidl
= g_pidlArrayItems
;
4560 dcm
.apidl
= (PCUITEMID_CHILD_ARRAY
)g_pidlArray
;
4561 dcm
.punkAssociationInfo
= pIQueryAssociations
;
4562 if (SUCCEEDED(pfnSHCreateDefaultContextMenu(&dcm
, IID_IContextMenu
, (void**)&icm1
)))
4564 int iMenuType
= 0; // to know which version of IContextMenu is supported
4566 { // since we got an IContextMenu interface we can now obtain the higher version interfaces via that
4567 if (icm1
->QueryInterface(IID_IContextMenu3
, (void**)&m_pContextMenu
) == S_OK
)
4569 else if (icm1
->QueryInterface(IID_IContextMenu2
, (void**)&m_pContextMenu
) == S_OK
)
4573 icm1
->Release(); // we can now release version 1 interface, cause we got a higher one
4576 // since no higher versions were found
4577 // redirect ppContextMenu to version 1 interface
4579 m_pContextMenu
= icm1
;
4584 // lets fill the our popup menu
4585 UINT flags
= CMF_NORMAL
;
4586 flags
|= (GetKeyState(VK_SHIFT
) & 0x8000) != 0 ? CMF_EXTENDEDVERBS
: 0;
4587 m_pContextMenu
->QueryContextMenu(hMenu
, 0, SHELL_MIN_CMD
, SHELL_MAX_CMD
, flags
);
4590 // subclass window to handle menu related messages in CShellContextMenu
4591 if (iMenuType
> 1) // only subclass if its version 2 or 3
4594 g_IContext2
= (LPCONTEXTMENU2
)m_pContextMenu
;
4596 g_IContext3
= (LPCONTEXTMENU3
)m_pContextMenu
;
4600 pIQueryAssociations
->Release();
4604 g_IContext3
->HandleMenuMsg2(message
, wParam
, lParam
, pResult
);
4605 else if (g_IContext2
)
4606 g_IContext2
->HandleMenuMsg(message
, wParam
, lParam
);
4616 return CListCtrl::OnWndMsg(message
, wParam
, lParam
, pResult
);