1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
5 // Copyright (C) 2010-2011 Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "..\\TortoiseShell\resource.h"
25 #include "GitStatusListCtrl.h"
26 #include "MessageBox.h"
28 #include "UnicodeUtils.h"
30 #include "PathUtils.h"
32 #include "StringUtils.h"
33 #include "DirFileEnum.h"
34 #include "GitConfig.h"
35 //#include "SVNProperties.h"
39 //#include "SVNProgressDlg.h"
40 #include "SysImageList.h"
41 //#include "Svnstatuslistctrl.h"
44 #include "GitStatus.h"
45 //#include "SVNHelpers.h"
47 #include "ShellUpdater.h"
48 #include "GitAdminDir.h"
49 //#include "DropFiles.h"
52 //#include "EditPropertiesDlg.h"
53 //#include "CreateChangelistDlg.h"
54 #include "CommonResource.h"
56 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
57 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
58 const UINT
CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
59 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
60 const UINT
CGitStatusListCtrl::GITSLNM_ADDFILE
61 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
62 const UINT
CGitStatusListCtrl::GITSLNM_CHECKCHANGED
63 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
64 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCHANGED
65 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCHANGED"));
70 BEGIN_MESSAGE_MAP(CGitStatusListCtrl
, CListCtrl
)
71 ON_NOTIFY(HDN_ITEMCLICKA
, 0, OnHdnItemclick
)
72 ON_NOTIFY(HDN_ITEMCLICKW
, 0, OnHdnItemclick
)
73 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
74 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
75 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED
, OnLvnItemchanged
)
77 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclk
)
78 ON_NOTIFY_REFLECT(LVN_GETINFOTIP
, OnLvnGetInfoTip
)
79 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdraw
)
82 ON_NOTIFY_REFLECT(NM_RETURN
, OnNMReturn
)
84 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, OnToolTipText
)
85 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, OnToolTipText
)
87 ON_NOTIFY(HDN_BEGINTRACKA
, 0, &CGitStatusListCtrl::OnHdnBegintrack
)
88 ON_NOTIFY(HDN_BEGINTRACKW
, 0, &CGitStatusListCtrl::OnHdnBegintrack
)
89 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, &CGitStatusListCtrl::OnHdnItemchanging
)
90 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, &CGitStatusListCtrl::OnHdnItemchanging
)
92 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnBeginDrag
)
93 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING
, &CGitStatusListCtrl::OnLvnItemchanging
)
98 CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl()
99 //, m_HeadRev(GitRev::REV_HEAD)
102 , m_pSelectButton(NULL
)
103 , m_pConfirmButton(NULL
)
106 , m_bShowIgnores(false)
107 , m_pDropTarget(NULL
)
108 , m_bIgnoreRemoveOnly(false)
109 , m_bCheckChildrenWithParent(false)
110 , m_bUnversionedLast(true)
111 , m_bHasChangeLists(false)
115 , m_bHasCheckboxes(false)
116 , m_bCheckIfGroupsExist(true)
117 , m_bFileDropsEnabled(false)
119 , m_dwDefaultColumns(0)
120 , m_ColumnManager(this)
121 , m_bAscending(false)
122 , m_nSortedColumn(-1)
123 , m_bHasExternalsFromDifferentRepos(false)
124 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE
))
126 , m_bDoNotAutoselectSubmodules(false)
130 m_bIsRevertTheirMy
= false;
131 this->m_nLineAdded
=this->m_nLineDeleted
=0;
134 CGitStatusListCtrl::~CGitStatusListCtrl()
136 // if (m_pDropTarget)
137 // delete m_pDropTarget;
141 void CGitStatusListCtrl::ClearStatusArray()
144 Locker
lock(m_critSec
);
145 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
147 delete m_arStatusArray
[i
];
149 m_arStatusArray
.clear();
153 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetListEntry(UINT_PTR index
)
156 if (index
>= (UINT_PTR
)m_arListArray
.size())
158 if (m_arListArray
[index
] >= m_arStatusArray
.size())
160 return m_arStatusArray
[m_arListArray
[index
]];
166 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetVisibleListEntry(const CTGitPath
& path
)
168 int itemCount
= GetItemCount();
169 for (int i
=0; i
< itemCount
; i
++)
171 FileEntry
* entry
= GetListEntry(i
);
172 if (entry
->GetPath().IsEquivalentTo(path
))
179 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetListEntry(const CTGitPath
& path
)
182 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
184 FileEntry
* entry
= m_arStatusArray
[i
];
185 if (entry
->GetPath().IsEquivalentTo(path
))
194 int CGitStatusListCtrl::GetIndex(const CTGitPath
& path
)
196 int itemCount
= GetItemCount();
197 for (int i
=0; i
< itemCount
; i
++)
199 FileEntry
* entry
= GetListEntry(i
);
200 if (entry
->GetPath().IsEquivalentTo(path
))
207 void CGitStatusListCtrl::Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
/* = GitSLC_POPALL */, bool bHasCheckboxes
/* = true */)
209 Locker
lock(m_critSec
);
211 m_dwDefaultColumns
= dwColumns
| 1;
212 m_dwContextMenus
= dwContextMenus
;
213 m_bHasCheckboxes
= bHasCheckboxes
;
215 // set the extended style of the listcontrol
216 // 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.
217 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
218 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
219 if (DWORD(regFullRowSelect
))
220 exStyle
|= LVS_EX_FULLROWSELECT
;
221 exStyle
|= (bHasCheckboxes
? LVS_EX_CHECKBOXES
: 0);
223 SetExtendedStyle(exStyle
);
225 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
227 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
228 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
230 // keep CSorter::operator() in sync!!
231 static UINT standardColumnNames
[GITSLC_NUMCOLUMNS
]
232 = { IDS_STATUSLIST_COLFILE
233 , IDS_STATUSLIST_COLFILENAME
234 , IDS_STATUSLIST_COLEXT
235 , IDS_STATUSLIST_COLSTATUS
236 , IDS_STATUSLIST_COLADD
237 , IDS_STATUSLIST_COLDEL
240 m_ColumnManager
.SetNames(standardColumnNames
,GITSLC_NUMCOLUMNS
);
241 m_ColumnManager
.ReadSettings (m_dwDefaultColumns
, 0, sColumnInfoContainer
, GITSLC_NUMCOLUMNS
);
245 if (m_pDropTarget
== NULL
)
247 m_pDropTarget
= new CGitStatusListCtrlDropTarget(this);
248 RegisterDragDrop(m_hWnd
,m_pDropTarget
);
249 // create the supported formats:
251 ftetc
.dwAspect
= DVASPECT_CONTENT
;
253 ftetc
.tymed
= TYMED_HGLOBAL
;
254 ftetc
.cfFormat
=CF_HDROP
;
255 m_pDropTarget
->AddSuportedFormat(ftetc
);
262 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID
)
264 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
267 BOOL
CGitStatusListCtrl::GetStatus ( const CTGitPathList
* pathList
268 , bool bUpdate
/* = FALSE */
269 , bool bShowIgnores
/* = false */
271 , bool /*bShowUserProps*/ /* = false */)
273 Locker
lock(m_critSec
);
274 int mask
= CGitStatusListCtrl::FILELIST_MODIFY
;
276 mask
|= CGitStatusListCtrl::FILELIST_IGNORE
;
278 mask
|= CGitStatusListCtrl::FILELIST_UNVER
;
279 this->UpdateFileList(mask
,bUpdate
,(CTGitPathList
*)pathList
);
283 int refetchcounter
= 0;
286 // force the cursor to change
289 SetCursorPos(pt
.x
, pt
.y
);
291 m_mapFilenameToChecked
.clear();
292 //m_StatusUrlList.Clear();
293 bool bHasChangelists
= (m_changelists
.size()>1 || (m_changelists
.size()>0 && !m_bHasIgnoreGroup
));
294 m_changelists
.clear();
295 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
297 FileEntry
* entry
= m_arStatusArray
[i
];
298 if ( bHasChangelists
&& entry
->checked
)
300 // If change lists are present, remember all checked entries
301 CString path
= entry
->GetPath().GetGitPathString();
302 m_mapFilenameToChecked
[path
] = true;
304 if ( (entry
->status
==git_wc_status_unversioned
|| entry
->status
==git_wc_status_missing
) && entry
->checked
)
306 // The user manually selected an unversioned or missing file. We remember
307 // this so that the selection can be restored when refreshing.
308 CString path
= entry
->GetPath().GetGitPathString();
309 m_mapFilenameToChecked
[path
] = true;
311 else if ( entry
->status
> git_wc_status_normal
&& !entry
->checked
)
313 // The user manually deselected a versioned file. We remember
314 // this so that the deselection can be restored when refreshing.
315 CString path
= entry
->GetPath().GetGitPathString();
316 m_mapFilenameToChecked
[path
] = false;
320 // use a sorted path list to make sure we fetch the status of
321 // parent items first, *then* the child items (if any)
322 CTGitPathList sortedPathList
= pathList
;
323 sortedPathList
.SortByPathname();
328 m_bHasExternalsFromDifferentRepos
= FALSE
;
329 m_bHasExternals
= FALSE
;
330 m_bHasUnversionedItems
= FALSE
;
332 m_bHasChangeLists
= false;
333 m_bShowIgnores
= bShowIgnores
;
340 // first clear possible status data left from
341 // previous GetStatus() calls
344 m_StatusFileList
= sortedPathList
;
346 // Since Git_client_status() returns all files, even those in
347 // folders included with Git:externals we need to check if all
348 // files we get here belongs to the same repository.
349 // It is possible to commit changes in an external folder, as long
350 // as the folder belongs to the same repository (but another path),
351 // but it is not possible to commit all files if the externals are
352 // from a different repository.
354 // To check if all files belong to the same repository, we compare the
355 // UUID's - if they're identical then the files belong to the same
356 // repository and can be committed. But if they're different, then
357 // tell the user to commit all changes in the external folders
359 CStringA sUUID
; // holds the repo UUID
360 CTGitPathList arExtPaths
; // list of Git:external paths
366 m_nTargetCount
= sortedPathList
.GetCount();
368 GitStatus
status(m_pbCanceled
);
369 if(m_nTargetCount
> 1 && sortedPathList
.AreAllPathsFilesInOneDirectory())
371 // This is a special case, where we've been given a list of files
372 // all from one folder
373 // We handle them by setting a status filter, then requesting the Git status of
374 // all the files in the directory, filtering for the ones we're interested in
375 status
.SetFilter(sortedPathList
);
377 // if all selected entries are files, we don't do a recursive status
378 // fetching. But if only one is a directory, we have to recurse.
379 git_depth_t depth
= git_depth_files
;
380 // We have set a filter. If all selected items were files or we fetch
381 // the status not recursively, then we have to include
382 // ignored items too - the user has selected them
383 bool bShowIgnoresRight
= true;
384 for (int fcindex
=0; fcindex
<sortedPathList
.GetCount(); ++fcindex
)
386 if (sortedPathList
[fcindex
].IsDirectory())
388 depth
= git_depth_infinity
;
389 bShowIgnoresRight
= false;
393 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
.GetCommonDirectory(), bUpdate
, sUUID
, arExtPaths
, true, depth
, bShowIgnoresRight
))
400 for(int nTarget
= 0; nTarget
< m_nTargetCount
; nTarget
++)
402 // check whether the path we want the status for is already fetched due to status-fetching
404 // this check is only done for file paths, because folder paths could be included already
405 // but not recursively
406 if (sortedPathList
[nTarget
].IsDirectory() || GetListEntry(sortedPathList
[nTarget
]) == NULL
)
408 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
[nTarget
], bUpdate
, sUUID
,
409 arExtPaths
, false, git_depth_infinity
, bShowIgnores
))
417 // remove the 'helper' files of conflicted items from the list.
418 // otherwise they would appear as unversioned files.
419 for (INT_PTR cind
= 0; cind
< m_ConflictFileList
.GetCount(); ++cind
)
421 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
423 if (m_arStatusArray
[i
]->GetPath().IsEquivalentTo(m_ConflictFileList
[cind
]))
425 delete m_arStatusArray
[i
];
426 m_arStatusArray
.erase(m_arStatusArray
.begin()+i
);
432 } while(!BuildStatistics() && (refetchcounter
< 2) && (*m_pbCanceled
==false));
435 FetchUserProperties();
437 m_ColumnManager
.UpdateUserPropList (m_arStatusArray
);
442 SetCursorPos(pt
.x
, pt
.y
);
450 // Fetch all local properties for all elements in the status array
452 void CGitStatusListCtrl::FetchUserProperties()
457 for (size_t i
= 0, count
= m_arStatusArray
.size(); i
< count
; ++i
)
459 // local / temp pool to hold parameters and props for a single item
461 GitPool
localPool ((apr_pool_t
*)globalPool
);
463 // open working copy for this path
465 const char* path
= m_arStatusArray
[i
]->path
.GetGitApiPath (localPool
);
467 Git_wc_adm_access_t
*adm_access
= NULL
;
468 Git_error_t
* error
= Git_wc_adm_probe_open3 ( &adm_access
471 , FALSE
// no write lock
472 , 0 // lock just the directory/file itself
478 // get the props and add them to the status info
480 apr_hash_t
* props
= NULL
;
481 Git_error_t
* error
= Git_wc_prop_list ( &props
487 for ( apr_hash_index_t
*index
488 = apr_hash_first (localPool
, props
)
490 ; index
= apr_hash_next (index
))
492 // extract next entry from hash
494 const char* key
= NULL
;
496 const char** val
= NULL
;
498 apr_hash_this ( index
499 , reinterpret_cast<const void**>(&key
)
501 , reinterpret_cast<void**>(&val
));
503 // decode / dispatch it
505 CString name
= CUnicodeUtils::GetUnicode (key
);
506 CString value
= CUnicodeUtils::GetUnicode (*val
);
508 // store in property container (truncate it after ~100 chars)
510 m_arStatusArray
[i
]->present_props
[name
]
511 = value
.Left (GitSLC_MAXUSERPROPLENGTH
);
514 error
= Git_wc_adm_close2 (adm_access
, localPool
);
516 Git_error_clear (error
);
521 // Get the show-flags bitmap value which corresponds to a particular Git status
522 DWORD
CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status
)
526 case git_wc_status_none
:
527 case git_wc_status_unversioned
:
528 return GITSLC_SHOWUNVERSIONED
;
529 case git_wc_status_ignored
:
531 return GITSLC_SHOWDIRECTS
;
532 return GITSLC_SHOWDIRECTS
|GITSLC_SHOWIGNORED
;
533 case git_wc_status_incomplete
:
534 return GITSLC_SHOWINCOMPLETE
;
535 case git_wc_status_normal
:
536 return GITSLC_SHOWNORMAL
;
537 case git_wc_status_external
:
538 return GITSLC_SHOWEXTERNAL
;
539 case git_wc_status_added
:
540 return GITSLC_SHOWADDED
;
541 case git_wc_status_missing
:
542 return GITSLC_SHOWMISSING
;
543 case git_wc_status_deleted
:
544 return GITSLC_SHOWREMOVED
;
545 case git_wc_status_replaced
:
546 return GITSLC_SHOWREPLACED
;
547 case git_wc_status_modified
:
548 return GITSLC_SHOWMODIFIED
;
549 case git_wc_status_merged
:
550 return GITSLC_SHOWMERGED
;
551 case git_wc_status_conflicted
:
552 return GITSLC_SHOWCONFLICTED
;
553 case git_wc_status_obstructed
:
554 return GITSLC_SHOWOBSTRUCTED
;
556 // we should NEVER get here!
563 void CGitStatusListCtrl::Show(unsigned int dwShow
, unsigned int dwCheck
/*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList
,bool UseStoredCheckStatus
)
565 CWinApp
* pApp
= AfxGetApp();
567 pApp
->DoWaitCursor(1);
569 Locker
lock(m_critSec
);
570 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
572 //SetItemCount(listIndex);
579 m_arStatusArray
.clear();
580 for(int i
=0;i
<this->m_StatusFileList
.GetCount();i
++)
582 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
585 for(int i
=0;i
<this->m_UnRevFileList
.GetCount();i
++)
587 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
590 for(int i
=0;i
<this->m_IgnoreFileList
.GetCount();i
++)
592 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
596 if (m_nSortedColumn
>= 0)
598 CSorter
predicate (&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
599 std::sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
603 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
605 //set default checkbox status
606 CTGitPath
* entry
= ((CTGitPath
*)m_arStatusArray
[i
]);
607 CString path
= entry
->GetGitPathString();
608 if (m_mapFilenameToChecked
.size()!=0 && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end())
610 entry
->m_Checked
=m_mapFilenameToChecked
[path
];
612 else if (!UseStoredCheckStatus
)
614 bool autoSelectSubmodules
= !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
);
615 if(entry
->m_Action
& dwCheck
&& autoSelectSubmodules
)
616 entry
->m_Checked
=true;
618 entry
->m_Checked
=false;
621 if(entry
->m_Action
& dwShow
)
623 AddEntry(entry
,langID
,index
);
628 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
629 for (int col
= 0; col
<= maxcol
; col
++)
630 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
633 GetStatisticsString();
635 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
636 HDITEM HeaderItem
= {0};
637 HeaderItem
.mask
= HDI_FORMAT
;
638 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
640 pHeader
->GetItem(i
, &HeaderItem
);
641 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
642 pHeader
->SetItem(i
, &HeaderItem
);
644 if (m_nSortedColumn
>= 0)
646 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
647 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
648 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
654 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
655 EnsureVisible(nSelectedEntry
, false);
659 // Restore the item at the top of the list.
660 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
662 if ( !EnsureVisible(nTopIndex
+i
,false) )
670 pApp
->DoWaitCursor(-1);
676 this->BuildStatistics();
680 CWinApp
* pApp
= AfxGetApp();
682 pApp
->DoWaitCursor(1);
684 m_bShowFolders
= bShowFolders
;
686 int nTopIndex
= GetTopIndex();
687 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
688 int nSelectedEntry
= 0;
689 if (posSelectedEntry
)
690 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
696 m_arListArray
.clear();
698 m_arListArray
.reserve(m_arStatusArray
.size());
699 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
702 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
704 FileEntry
* entry
= m_arStatusArray
[i
];
705 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
707 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
709 if (entry
->IsFolder() && (!bShowFolders
))
710 continue; // don't show folders if they're not wanted.
713 git_wc_status_kind status
= GitStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
714 DWORD showFlags
= GetShowFlagsFromGitStatus(status
);
715 if (entry
->IsLocked())
716 showFlags
|= SVNSLC_SHOWLOCKS
;
718 showFlags
|= SVNSLC_SHOWSWITCHED
;
719 if (!entry
->changelist
.IsEmpty())
720 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
722 bool bAllowCheck
= ((entry
->changelist
.Compare(GITSLC_IGNORECHANGELIST
) != 0)
723 && (m_bCheckIfGroupsExist
|| (m_changelists
.size()==0 || (m_changelists
.size()==1 && m_bHasIgnoreGroup
))));
725 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
727 if (status
!= Git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& GitSLC_SHOWIGNORED
))
729 if ((!entry
->IsFolder()) && (status
== Git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
731 if (PathFileExists(entry
->GetPath().GetWinPath()))
733 m_arListArray
.push_back(i
);
734 if ((dwCheck
& SVNSLC_SHOWREMOVEDANDPRESENT
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
737 entry
->checked
= true;
739 AddEntry(entry
, langID
, listIndex
++);
742 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
744 m_arListArray
.push_back(i
);
745 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
748 entry
->checked
= true;
750 AddEntry(entry
, langID
, listIndex
++);
752 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
754 m_arListArray
.push_back(i
);
755 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
758 entry
->checked
= true;
760 AddEntry(entry
, langID
, listIndex
++);
766 SetItemCount(listIndex
);
768 m_ColumnManager
.UpdateRelevance (m_arStatusArray
, m_arListArray
);
770 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
771 for (int col
= 0; col
<= maxcol
; col
++)
772 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
775 GetStatisticsString();
777 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
778 HDITEM HeaderItem
= {0};
779 HeaderItem
.mask
= HDI_FORMAT
;
780 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
782 pHeader
->GetItem(i
, &HeaderItem
);
783 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
784 pHeader
->SetItem(i
, &HeaderItem
);
788 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
789 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
790 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
795 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
796 EnsureVisible(nSelectedEntry
, false);
800 // Restore the item at the top of the list.
801 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
803 if ( !EnsureVisible(nTopIndex
+i
,false) )
811 pApp
->DoWaitCursor(-1);
813 m_bEmpty
= (GetItemCount() == 0);
819 void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList
& checkedList
, bool /*bShowFolders*/ /* = true */)
822 for(int i
=0;i
<checkedList
.GetCount();i
++)
823 this->AddEntry((CTGitPath
*)&checkedList
[i
],0,i
);
827 Locker
lock(m_critSec
);
828 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
830 CWinApp
* pApp
= AfxGetApp();
832 pApp
->DoWaitCursor(1);
834 m_bShowFolders
= bShowFolders
;
836 int nTopIndex
= GetTopIndex();
837 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
838 int nSelectedEntry
= 0;
839 if (posSelectedEntry
)
840 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
846 m_arListArray
.clear();
848 m_arListArray
.reserve(m_arStatusArray
.size());
849 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
852 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
854 FileEntry
* entry
= m_arStatusArray
[i
];
855 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
857 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
859 if (entry
->IsFolder() && (!bShowFolders
))
860 continue; // don't show folders if they're not wanted.
862 git_wc_status_kind status
= SVNStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
863 DWORD showFlags
= GetShowFlagsFromSVNStatus(status
);
864 if (entry
->IsLocked())
865 showFlags
|= SVNSLC_SHOWLOCKS
;
866 if (!entry
->changelist
.IsEmpty())
867 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
869 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
870 if (status
!= git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& SVNSLC_SHOWIGNORED
))
872 for (int npath
= 0; npath
< checkedList
.GetCount(); ++npath
)
874 if (entry
->GetPath().IsEquivalentTo(checkedList
[npath
]))
876 entry
->checked
= true;
880 if ((!entry
->IsFolder()) && (status
== git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
882 if (PathFileExists(entry
->GetPath().GetWinPath()))
884 m_arListArray
.push_back(i
);
885 AddEntry(entry
, langID
, listIndex
++);
888 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
890 m_arListArray
.push_back(i
);
891 AddEntry(entry
, langID
, listIndex
++);
893 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
895 m_arListArray
.push_back(i
);
896 AddEntry(entry
, langID
, listIndex
++);
898 else if (entry
->switched
)
900 m_arListArray
.push_back(i
);
901 AddEntry(entry
, langID
, listIndex
++);
907 SetItemCount(listIndex
);
909 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
910 for (int col
= 0; col
<= maxcol
; col
++)
911 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
914 GetStatisticsString();
916 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
917 HDITEM HeaderItem
= {0};
918 HeaderItem
.mask
= HDI_FORMAT
;
919 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
921 pHeader
->GetItem(i
, &HeaderItem
);
922 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
923 pHeader
->SetItem(i
, &HeaderItem
);
927 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
928 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
929 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
934 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
935 EnsureVisible(nSelectedEntry
, false);
939 // Restore the item at the top of the list.
940 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
942 if ( !EnsureVisible(nTopIndex
+i
,false) )
950 pApp
->DoWaitCursor(-1);
952 m_bEmpty
= (GetItemCount() == 0);
957 int CGitStatusListCtrl::GetColumnIndex(int mask
)
967 void CGitStatusListCtrl::AddEntry(CTGitPath
* GitPath
, WORD
/*langID*/, int listIndex
)
969 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
970 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
972 CString path
= GitPath
->GetGitPathString();
975 int index
= listIndex
;
977 CString entryname
= GitPath
->GetGitPathString();
979 if (GitPath
->IsDirectory())
980 icon_idx
= m_nIconFolder
;
983 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(*GitPath
);
985 if(GitPath
->m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !GitPath
->GetGitOldPathString().IsEmpty())
989 rename
.Format(_T(" (from %s)"), GitPath
->GetGitOldPathString());
993 InsertItem(index
, entryname
, icon_idx
);
995 this->SetItemData(index
, (DWORD_PTR
)GitPath
);
996 // SVNSLC_COLFILENAME
997 SetItemText(index
, nCol
++, GitPath
->GetFileOrDirectoryName());
999 SetItemText(index
, nCol
++, GitPath
->GetFileExtension());
1001 SetItemText(index
, nCol
++, GitPath
->GetActionName());
1003 SetItemText(index
, GetColumnIndex(GITSLC_COLADD
),GitPath
->m_StatAdd
);
1004 SetItemText(index
, GetColumnIndex(GITSLC_COLDEL
),GitPath
->m_StatDel
);
1007 SetCheck(index
, GitPath
->m_Checked
);
1008 if (GitPath
->m_Checked
)
1012 if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_IGNORE
)
1013 SetItemGroup(index
, 2);
1014 else if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1015 SetItemGroup(index
,1);
1018 SetItemGroup(index
, GitPath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
));
1026 void CGitStatusListCtrl::AddEntry(FileEntry
* entry
, WORD langID
, int listIndex
)
1028 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
1029 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
1031 CString path
= entry
->GetPath().GetGitPathString();
1032 if ( m_mapFilenameToChecked
.size()!=0 && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end() )
1034 // The user manually de-/selected an item. We now restore this status
1036 entry
->checked
= m_mapFilenameToChecked
[path
];
1041 int index
= listIndex
;
1043 CString entryname
= entry
->GetDisplayName();
1045 if (entry
->isfolder
)
1046 icon_idx
= m_nIconFolder
;
1049 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(entry
->path
);
1052 InsertItem(index
, entryname
, icon_idx
);
1053 // SVNSLC_COLFILENAME
1054 SetItemText(index
, nCol
++, entry
->path
.GetFileOrDirectoryName());
1056 SetItemText(index
, nCol
++, entry
->path
.GetFileExtension());
1058 if (entry
->isNested
)
1060 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1061 SetItemText(index
, nCol
++, sTemp
);
1065 GitStatus::GetStatusString(hResourceHandle
, entry
->status
, buf
, _countof(buf
), (WORD
)langID
);
1066 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1067 _tcscat_s(buf
, 100, _T(" (+)"));
1068 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1069 _tcscat_s(buf
, 100, _T(" (s)"));
1071 if ((entry
->status
== entry
->propstatus
)&&
1072 (entry
->status
!= git_wc_status_normal
)&&
1073 (entry
->status
!= git_wc_status_unversioned
)&&
1074 (!GitStatus::IsImportant(entry
->textstatus
)))
1075 _tcscat_s(buf
, 100, ponly
);
1077 SetItemText(index
, nCol
++, buf
);
1079 // SVNSLC_COLREMOTESTATUS
1080 if (entry
->isNested
)
1082 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1083 SetItemText(index
, nCol
++, sTemp
);
1088 SVNStatus::GetStatusString(hResourceHandle
, entry
->remotestatus
, buf
, _countof(buf
), (WORD
)langID
);
1089 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1090 _tcscat_s(buf
, 100, _T(" (+)"));
1091 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1092 _tcscat_s(buf
, 100, _T(" (s)"));
1093 if ((entry
->remotestatus
== entry
->remotepropstatus
)&&
1094 (entry
->remotestatus
!= git_wc_status_none
)&&
1095 (entry
->remotestatus
!= git_wc_status_normal
)&&
1096 (entry
->remotestatus
!= git_wc_status_unversioned
)&&
1097 (!SVNStatus::IsImportant(entry
->remotetextstatus
)))
1098 _tcscat_s(buf
, 100, ponly
);
1100 SetItemText(index
, nCol
++, buf
);
1102 // SVNSLC_COLTEXTSTATUS
1103 if (entry
->isNested
)
1105 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1106 SetItemText(index
, nCol
++, sTemp
);
1111 SVNStatus::GetStatusString(hResourceHandle
, entry
->textstatus
, buf
, _countof(buf
), (WORD
)langID
);
1112 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1113 _tcscat_s(buf
, 100, _T(" (+)"));
1114 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1115 _tcscat_s(buf
, 100, _T(" (s)"));
1117 SetItemText(index
, nCol
++, buf
);
1119 // SVNSLC_COLPROPSTATUS
1120 if (entry
->isNested
)
1122 SetItemText(index
, nCol
++, _T(""));
1127 SVNStatus::GetStatusString(hResourceHandle
, entry
->propstatus
, buf
, _countof(buf
), (WORD
)langID
);
1128 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1129 _tcscat_s(buf
, 100, _T(" (+)"));
1130 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1131 _tcscat_s(buf
, 100, _T(" (s)"));
1133 SetItemText(index
, nCol
++, buf
);
1135 // SVNSLC_COLREMOTETEXT
1136 if (entry
->isNested
)
1138 SetItemText(index
, nCol
++, _T(""));
1143 SVNStatus::GetStatusString(hResourceHandle
, entry
->remotetextstatus
, buf
, _countof(buf
), (WORD
)langID
);
1144 SetItemText(index
, nCol
++, buf
);
1147 // SVNSLC_COLREMOTEPROP
1148 if (entry
->isNested
)
1150 SetItemText(index
, nCol
++, _T(""));
1154 // SVNStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, _countof(buf), (WORD)langID);
1155 SetItemText(index
, nCol
++, buf
);
1158 // SetItemText(index, nCol++, entry->url);
1161 if (!m_HeadRev
.IsHead())
1163 // we have contacted the repository
1166 // wc repository text
1170 // UID1 "" lock has been broken
1171 // UID1 UID2 lock has been stolen
1172 if (entry
->lock_token
.IsEmpty() || (entry
->lock_token
.Compare(entry
->lock_remotetoken
)==0))
1174 if (entry
->lock_owner
.IsEmpty())
1175 SetItemText(index
, nCol
++, entry
->lock_remoteowner
);
1177 SetItemText(index
, nCol
++, entry
->lock_owner
);
1179 else if (entry
->lock_remotetoken
.IsEmpty())
1182 CString
temp(MAKEINTRESOURCE(IDS_STATUSLIST_LOCKBROKEN
));
1183 SetItemText(index
, nCol
++, temp
);
1189 temp
.Format(IDS_STATUSLIST_LOCKSTOLEN
, (LPCTSTR
)entry
->lock_remoteowner
);
1190 SetItemText(index
, nCol
++, temp
);
1194 SetItemText(index
, nCol
++, entry
->lock_owner
);
1195 // SVNSLC_COLLOCKCOMMENT
1196 SetItemText(index
, nCol
++, entry
->lock_comment
);
1198 SetItemText(index
, nCol
++, entry
->last_commit_author
);
1199 // SVNSLC_COLREVISION
1201 temp
.Format(_T("%ld"), entry
->last_commit_rev
);
1202 if (entry
->last_commit_rev
> 0)
1203 SetItemText(index
, nCol
++, temp
);
1205 SetItemText(index
, nCol
++, _T(""));
1206 // SVNSLC_COLREMOTEREVISION
1207 temp
.Format(_T("%ld"), entry
->remoterev
);
1208 if (entry
->remoterev
> 0)
1209 SetItemText(index
, nCol
++, temp
);
1211 SetItemText(index
, nCol
++, _T(""));
1213 TCHAR datebuf
[SVN_DATE_BUFFER
];
1214 apr_time_t date
= entry
->last_commit_date
;
1215 SVN::formatDate(datebuf
, date
, true);
1217 SetItemText(index
, nCol
++, datebuf
);
1219 SetItemText(index
, nCol
++, _T(""));
1220 // SVNSLC_COLSVNNEEDSLOCK
1221 BOOL bFoundSVNNeedsLock
= entry
->present_props
.IsNeedsLockSet();
1222 CString strSVNNeedsLock
= (bFoundSVNNeedsLock
) ? _T("*") : _T("");
1223 SetItemText(index
, nCol
++, strSVNNeedsLock
);
1224 // SVNSLC_COLCOPYFROM
1225 if (m_sURL
.Compare(entry
->copyfrom_url
.Left(m_sURL
.GetLength()))==0)
1226 temp
= entry
->copyfrom_url
.Mid(m_sURL
.GetLength());
1228 temp
= entry
->copyfrom_url
;
1229 SetItemText(index
, nCol
++, temp
);
1230 // SVNSLC_COLMODIFICATIONDATE
1231 __int64 filetime
= entry
->GetPath().GetLastWriteTime();
1232 if ( (filetime
) && (entry
->status
!=git_wc_status_deleted
) )
1234 FILETIME
* f
= (FILETIME
*)(__int64
*)&filetime
;
1235 TCHAR datebuf
[SVN_DATE_BUFFER
];
1236 SVN::formatDate(datebuf
,*f
,true);
1237 SetItemText(index
, nCol
++, datebuf
);
1241 SetItemText(index
, nCol
++, _T(""));
1244 // user-defined properties
1245 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
1249 assert (i
== nCol
++);
1250 assert (m_ColumnManager
.IsUserProp (i
));
1252 CString name
= m_ColumnManager
.GetName(i
);
1253 if (entry
->present_props
.HasProperty (name
))
1255 const CString
& propVal
= entry
->present_props
[name
];
1256 if (propVal
.IsEmpty())
1257 SetItemText(index
, i
, m_sNoPropValueText
);
1259 SetItemText(index
, i
, propVal
);
1262 SetItemText(index
, i
, _T(""));
1265 SetCheck(index
, entry
->checked
);
1268 if (m_changelists
.find(entry
->changelist
) != m_changelists
.end())
1269 SetItemGroup(index
, m_changelists
[entry
->changelist
]);
1271 SetItemGroup(index
, 0);
1276 bool CGitStatusListCtrl::SetItemGroup(int item
, int groupindex
)
1278 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1283 i
.mask
= LVIF_GROUPID
;
1286 i
.iGroupId
= groupindex
;
1288 return !!SetItem(&i
);
1291 void CGitStatusListCtrl::OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1293 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1298 if (m_nSortedColumn
== phdr
->iItem
)
1299 m_bAscending
= !m_bAscending
;
1301 m_bAscending
= TRUE
;
1302 m_nSortedColumn
= phdr
->iItem
;
1303 Show(m_dwShow
, 0, m_bShowFolders
,false,true);
1308 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1310 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1313 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1314 if ((m_bBlock
)&&(m_bBlockUI
))
1316 // if we're blocked, prevent changing of the check state
1317 if ((!ISCHECKED(pNMLV
->uOldState
) && ISCHECKED(pNMLV
->uNewState
))||
1318 (ISCHECKED(pNMLV
->uOldState
) && !ISCHECKED(pNMLV
->uNewState
)))
1323 BOOL
CGitStatusListCtrl::OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1325 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1327 CWnd
* pParent
= GetParent();
1328 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
1330 pParent
->SendMessage(GITSLNM_ITEMCHANGED
, pNMLV
->iItem
);
1333 if ((pNMLV
->uNewState
==0)||(pNMLV
->uNewState
& LVIS_SELECTED
)||(pNMLV
->uNewState
& LVIS_FOCUSED
))
1339 bool bSelected
= !!(ListView_GetItemState(m_hWnd
, pNMLV
->iItem
, LVIS_SELECTED
) & LVIS_SELECTED
);
1340 int nListItems
= GetItemCount();
1343 // was the item checked?
1345 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1346 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1348 if (GetCheck(pNMLV
->iItem
))
1350 CheckEntry(pNMLV
->iItem
, nListItems
);
1353 POSITION pos
= GetFirstSelectedItemPosition();
1355 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1357 if (index
!= pNMLV
->iItem
)
1358 CheckEntry(index
, nListItems
);
1364 UncheckEntry(pNMLV
->iItem
, nListItems
);
1367 POSITION pos
= GetFirstSelectedItemPosition();
1369 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1371 if (index
!= pNMLV
->iItem
)
1372 UncheckEntry(index
, nListItems
);
1377 GetStatisticsString();
1384 void CGitStatusListCtrl::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1386 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
1391 void CGitStatusListCtrl::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1393 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
1398 void CGitStatusListCtrl::CheckEntry(int index
, int /*nListItems*/)
1400 Locker
lock(m_critSec
);
1401 //FileEntry * entry = GetListEntry(index);
1402 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1403 ASSERT(path
!= NULL
);
1406 m_mapFilenameToChecked
[path
->GetGitPathString()] = true;
1407 SetCheck(index
, TRUE
);
1408 //entry = GetListEntry(index);
1409 // if an unversioned item was checked, then we need to check if
1410 // the parent folders are unversioned too. If the parent folders actually
1411 // are unversioned, then check those too.
1413 if (entry
->status
== git_wc_status_unversioned
)
1415 // we need to check the parent folder too
1416 const CTGitPath
& folderpath
= entry
->path
;
1417 for (int i
=0; i
< nListItems
; ++i
)
1419 FileEntry
* testEntry
= GetListEntry(i
);
1420 ASSERT(testEntry
!= NULL
);
1421 if (testEntry
== NULL
)
1423 if (!testEntry
->checked
)
1425 if (testEntry
->path
.IsAncestorOf(folderpath
) && (!testEntry
->path
.IsEquivalentTo(folderpath
)))
1427 SetEntryCheck(testEntry
,i
,true);
1433 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1434 if ( (entry
->status
== git_wc_status_deleted
) || (m_bCheckChildrenWithParent
) || (bShift
) )
1436 // if a deleted folder gets checked, we have to check all
1437 // children of that folder too.
1438 if (entry
->path
.IsDirectory())
1440 SetCheckOnAllDescendentsOf(entry
, true);
1443 // if a deleted file or folder gets checked, we have to
1444 // check all parents of this item too.
1445 for (int i
=0; i
<nListItems
; ++i
)
1447 FileEntry
* testEntry
= GetListEntry(i
);
1448 ASSERT(testEntry
!= NULL
);
1449 if (testEntry
== NULL
)
1451 if (!testEntry
->checked
)
1453 if (testEntry
->path
.IsAncestorOf(entry
->path
) && (!testEntry
->path
.IsEquivalentTo(entry
->path
)))
1455 if ((testEntry
->status
== git_wc_status_deleted
)||(m_bCheckChildrenWithParent
))
1457 SetEntryCheck(testEntry
,i
,true);
1459 // now we need to check all children of this parent folder
1460 SetCheckOnAllDescendentsOf(testEntry
, true);
1467 if ( !path
->m_Checked
)
1469 path
->m_Checked
= TRUE
;
1474 void CGitStatusListCtrl::UncheckEntry(int index
, int /*nListItems*/)
1476 Locker
lock(m_critSec
);
1477 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1478 ASSERT(path
!= NULL
);
1481 SetCheck(index
, FALSE
);
1482 m_mapFilenameToChecked
[path
->GetGitPathString()] = false;
1483 //entry = GetListEntry(index);
1484 // item was unchecked
1486 if (entry
->path
.IsDirectory())
1488 // disable all files within an unselected folder, except when unchecking a folder with property changes
1489 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1490 if ( (entry
->status
!= git_wc_status_modified
) || (bShift
) )
1492 SetCheckOnAllDescendentsOf(entry
, false);
1495 else if (entry
->status
== git_wc_status_deleted
)
1497 // a "deleted" file was unchecked, so uncheck all parent folders
1498 // and all children of those parents
1499 for (int i
=0; i
<nListItems
; i
++)
1501 FileEntry
* testEntry
= GetListEntry(i
);
1502 ASSERT(testEntry
!= NULL
);
1503 if (testEntry
== NULL
)
1505 if (testEntry
->checked
)
1507 if (testEntry
->path
.IsAncestorOf(entry
->path
))
1509 if (testEntry
->status
== git_wc_status_deleted
)
1511 SetEntryCheck(testEntry
,i
,false);
1514 SetCheckOnAllDescendentsOf(testEntry
, false);
1521 if ( path
->m_Checked
)
1523 path
->m_Checked
= FALSE
;
1528 bool CGitStatusListCtrl::EntryPathCompareNoCase(const FileEntry
* pEntry1
, const FileEntry
* pEntry2
)
1530 return pEntry1
->path
< pEntry2
->path
;
1533 bool CGitStatusListCtrl::IsEntryVersioned(const FileEntry
* pEntry1
)
1535 return pEntry1
->status
!= git_wc_status_unversioned
;
1538 bool CGitStatusListCtrl::BuildStatistics()
1541 bool bRefetchStatus
= false;
1543 // now gather some statistics
1556 for (int i
=0; i
< (int)m_arStatusArray
.size(); ++i
)
1558 int status
=((CTGitPath
*)m_arStatusArray
[i
])->m_Action
;
1560 m_nLineAdded
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatAdd
);
1561 m_nLineDeleted
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatDel
);
1563 if(status
&(CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
1566 if(status
&CTGitPath::LOGACTIONS_DELETED
)
1569 if(status
&(CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_MODIFIED
))
1572 if(status
&CTGitPath::LOGACTIONS_UNMERGED
)
1575 if(status
&(CTGitPath::LOGACTIONS_IGNORE
|CTGitPath::LOGACTIONS_UNVER
))
1578 if(status
&(CTGitPath::LOGACTIONS_REPLACED
))
1581 if(((CTGitPath
*)m_arStatusArray
[i
])->m_Checked
)
1584 // } // switch (entry->status)
1586 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1587 return !bRefetchStatus
;
1593 int CGitStatusListCtrl::GetGroupFromPoint(POINT
* ppt
)
1595 // the point must be relative to the upper left corner of the control
1599 if (!IsGroupViewEnabled())
1608 while (((flags
& LVHT_BELOW
) == 0)&&(pt
.y
< rc
.bottom
))
1610 nItem
= HitTest(pt
, &flags
);
1611 if ((flags
& LVHT_ONITEM
)||(flags
& LVHT_EX_GROUP_HEADER
))
1613 // the first item below the point
1615 // check if the point is too much right (i.e. if the point
1616 // is farther to the right than the width of the item)
1618 GetItemRect(nItem
, &r
, LVIR_LABEL
);
1619 if (ppt
->x
> r
.right
)
1623 lv
.mask
= LVIF_GROUPID
;
1626 int groupID
= lv
.iGroupId
;
1627 // now we search upwards and check if the item above this one
1628 // belongs to another group. If it belongs to the same group,
1629 // we're not over a group header
1633 nItem
= HitTest(pt
, &flags
);
1634 if ((flags
& LVHT_ONITEM
)&&(nItem
>= 0))
1636 // the first item below the point
1638 lv
.mask
= LVIF_GROUPID
;
1641 if (lv
.iGroupId
!= groupID
)
1656 void CGitStatusListCtrl::OnContextMenuGroup(CWnd
* /*pWnd*/, CPoint point
)
1658 POINT clientpoint
= point
;
1659 ScreenToClient(&clientpoint
);
1660 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint
) >= 0))
1663 if (popup
.CreatePopupMenu())
1666 temp
.LoadString(IDS_STATUSLIST_CHECKGROUP
);
1667 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_CHECKGROUP
, temp
);
1668 temp
.LoadString(IDS_STATUSLIST_UNCHECKGROUP
);
1669 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_UNCHECKGROUP
, temp
);
1670 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1671 bool bCheck
= false;
1674 case IDGITLC_CHECKGROUP
:
1676 // fall through here
1677 case IDGITLC_UNCHECKGROUP
:
1679 int group
= GetGroupFromPoint(&clientpoint
);
1680 // go through all items and check/uncheck those assigned to the group
1681 // but block the OnLvnItemChanged handler
1684 for (int i
=0; i
<GetItemCount(); ++i
)
1686 SecureZeroMemory(&lv
, sizeof(LVITEM
));
1687 lv
.mask
= LVIF_GROUPID
;
1691 if (lv
.iGroupId
== group
)
1693 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
1696 bool bOldCheck
= entry
->m_Checked
;
1697 SetEntryCheck(entry
, i
, bCheck
);
1698 if (bCheck
!= bOldCheck
)
1709 GetStatisticsString();
1719 void CGitStatusListCtrl::OnContextMenuList(CWnd
* pWnd
, CPoint point
)
1722 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1724 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1725 CTGitPath
* filepath
;
1727 int selIndex
= GetSelectionMark();
1728 if ((point
.x
== -1) && (point
.y
== -1))
1731 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1732 ClientToScreen(&rect
);
1733 point
= rect
.CenterPoint();
1735 if ((GetSelectedCount() == 0) && (m_bHasCheckboxes
))
1737 // nothing selected could mean the context menu is requested for
1739 OnContextMenuGroup(pWnd
, point
);
1741 else if (selIndex
>= 0)
1743 //FileEntry * entry = GetListEntry(selIndex);
1745 filepath
= (CTGitPath
* )GetItemData(selIndex
);
1747 ASSERT(filepath
!= NULL
);
1748 if (filepath
== NULL
)
1751 //const CTGitPath& filepath = entry->path;
1752 int wcStatus
= filepath
->m_Action
;
1753 // entry is selected, now show the popup menu
1754 Locker
lock(m_critSec
);
1756 CMenu changelistSubMenu
;
1757 CMenu ignoreSubMenu
;
1758 if (popup
.CreatePopupMenu())
1760 //Add Menu for version controlled file
1762 if (GetSelectedCount() > 0 && wcStatus
& CTGitPath::LOGACTIONS_UNMERGED
)
1764 if (GetSelectedCount() == 1 && (m_dwContextMenus
& GITSLC_POPCONFLICT
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1766 popup
.AppendMenuIcon(IDGITLC_EDITCONFLICT
, IDS_MENUCONFLICT
, IDI_CONFLICT
);
1768 if (m_dwContextMenus
& GITSLC_POPRESOLVE
)
1770 popup
.AppendMenuIcon(IDGITLC_RESOLVECONFLICT
, IDS_STATUSLIST_CONTEXT_RESOLVED
, IDI_RESOLVE
);
1772 if ((m_dwContextMenus
& GITSLC_POPRESOLVE
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1774 popup
.AppendMenuIcon(IDGITLC_RESOLVETHEIRS
, IDS_SVNPROGRESS_MENUUSETHEIRS
, IDI_RESOLVE
);
1775 popup
.AppendMenuIcon(IDGITLC_RESOLVEMINE
, IDS_SVNPROGRESS_MENUUSEMINE
, IDI_RESOLVE
);
1777 if ((m_dwContextMenus
& GITSLC_POPCONFLICT
)||(m_dwContextMenus
& GITSLC_POPRESOLVE
))
1778 popup
.AppendMenu(MF_SEPARATOR
);
1781 if (GetSelectedCount() > 0)
1783 if (wcStatus
& CTGitPath::LOGACTIONS_UNVER
)
1784 if (m_dwContextMenus
& GITSLC_POPADD
)
1786 //if ( entry->IsFolder() )
1788 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1792 popup
.AppendMenuIcon(IDGITLC_ADD
, IDS_STATUSLIST_CONTEXT_ADD
, IDI_ADD
);
1797 if (!(wcStatus
&CTGitPath::LOGACTIONS_UNVER
))
1799 if ( (m_dwContextMenus
& GITSLC_POPCOMPAREWITHBASE
) && GetSelectedCount()>0)
1801 if(filepath
->m_ParentNo
& MERGE_MASK
)
1802 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_TREE_DIFF
, IDI_DIFF
);
1804 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_LOG_COMPAREWITHBASE
, IDI_DIFF
);
1806 popup
.SetDefaultItem(IDGITLC_COMPARE
, FALSE
);
1809 if ((m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPAREWC
)) && GetSelectedCount()>0)
1811 if( (!m_CurrentVersion
.IsEmpty()) && m_CurrentVersion
!= GIT_REV_ZERO
)
1812 popup
.AppendMenuIcon(IDGITLC_COMPAREWC
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1815 if (GetSelectedCount() == 1)
1817 bool bEntryAdded
= false;
1818 //if (entry->remotestatus <= git_wc_status_normal)
1820 // if (wcStatus > git_wc_status_normal)
1822 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
1824 if(!g_Git
.IsInitRepos() && (m_dwContextMenus
&GITSLC_POPGNUDIFF
))
1826 popup
.AppendMenuIcon(IDGITLC_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1834 //else if (wcStatus != git_wc_status_deleted)
1836 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
1838 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1839 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1840 // bEntryAdded = true;
1842 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
1844 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1845 // bEntryAdded = true;
1849 popup
.AppendMenu(MF_SEPARATOR
);
1851 //else if (GetSelectedCount() > 1)
1853 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1855 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1856 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1861 if( (!this->m_Rev1
.IsEmpty()) || (!this->m_Rev1
.IsEmpty()) )
1863 if(GetSelectedCount() == 1)
1865 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPARETWO
))
1867 popup
.AppendMenuIcon(IDGITLC_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1868 popup
.SetDefaultItem(IDGITLC_COMPARETWO
, FALSE
);
1870 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_GNUDIFF2
))
1872 popup
.AppendMenuIcon(IDGITLC_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1878 if (GetSelectedCount() > 0)
1880 if ((GetSelectedCount() == 2) && (m_dwContextMenus
& this->GetContextMenuBit(GITSLC_POPCOMPARETWOFILES
)))
1882 POSITION pos
= GetFirstSelectedItemPosition();
1883 int index
= GetNextSelectedItem(pos
);
1886 CTGitPath
* entry2
= NULL
;
1887 bool bothItemsAreFiles
= true;
1888 entry2
= (CTGitPath
* )GetItemData(index
);
1890 bothItemsAreFiles
= !entry2
->IsDirectory();
1891 index
= GetNextSelectedItem(pos
);
1894 entry2
= (CTGitPath
* )GetItemData(index
);
1896 bothItemsAreFiles
= bothItemsAreFiles
&& !entry2
->IsDirectory();
1897 if (bothItemsAreFiles
)
1898 popup
.AppendMenuIcon(IDGITLC_COMPARETWOFILES
, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES
, IDI_DIFF
);
1902 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
1904 // POSITION pos = GetFirstSelectedItemPosition();
1905 // int index = GetNextSelectedItem(pos);
1908 // FileEntry * entry = GetListEntry(index);
1909 // git_wc_status_kind status1 = git_wc_status_none;
1910 // git_wc_status_kind status2 = git_wc_status_none;
1912 // status1 = entry->status;
1913 // index = GetNextSelectedItem(pos);
1916 // entry = GetListEntry(index);
1918 // status2 = entry->status;
1919 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
1920 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
1922 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
1927 // if (wcStatus > git_wc_status_normal)
1929 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1931 // // reverting missing folders is not possible
1932 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1934 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1938 // if (entry->remotestatus > git_wc_status_normal)
1940 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1942 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1947 if ( (GetSelectedCount() >0 ) && (!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
)))
1949 if ((m_dwContextMenus
& GITSLC_POPREVERT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1951 popup
.AppendMenuIcon(IDGITLC_REVERT
, IDS_MENUREVERT
, IDI_REVERT
);
1954 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOREV
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1955 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1957 popup
.AppendMenuIcon(IDGITLC_REVERTTOREV
, IDS_LOG_POPUP_REVERTTOREV
, IDI_REVERT
);
1961 if ((GetSelectedCount() == 1)&&(!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
))
1962 &&(!(wcStatus
& CTGitPath::LOGACTIONS_IGNORE
)))
1964 if (m_dwContextMenus
& GITSLC_POPSHOWLOG
)
1966 popup
.AppendMenuIcon(IDGITLC_LOG
, IDS_REPOBROWSE_SHOWLOG
, IDI_LOG
);
1968 if (m_dwContextMenus
& GITSLC_POPBLAME
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1970 popup
.AppendMenuIcon(IDGITLC_BLAME
, IDS_MENUBLAME
, IDI_BLAME
);
1973 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1974 if ( (GetSelectedCount() == 1) )
1976 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_SAVEAS
) && ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1978 popup
.AppendMenuIcon(IDGITLC_SAVEAS
, IDS_LOG_POPUP_SAVE
, IDI_SAVEAS
);
1981 if (m_dwContextMenus
& GITSLC_POPOPEN
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1983 popup
.AppendMenuIcon(IDGITLC_VIEWREV
, IDS_LOG_POPUP_VIEWREV
);
1984 popup
.AppendMenuIcon(IDGITLC_OPEN
, IDS_REPOBROWSE_OPEN
, IDI_OPEN
);
1985 popup
.AppendMenuIcon(IDGITLC_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1986 if (wcStatus
&CTGitPath::LOGACTIONS_UNVER
) {
1987 popup
.SetDefaultItem(IDGITLC_OPEN
, FALSE
);
1991 if (m_dwContextMenus
& GITSLC_POPEXPLORE
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1993 popup
.AppendMenuIcon(IDGITLC_EXPLORE
, IDS_STATUSLIST_CONTEXT_EXPLORE
, IDI_EXPLORER
);
1997 if (GetSelectedCount() > 0)
1999 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
2001 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2003 // 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))
2006 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
2008 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
2010 if ((wcStatus
& CTGitPath::LOGACTIONS_UNVER
)/*||(wcStatus == git_wc_status_deleted)*/)
2012 if (m_dwContextMenus
& GITSLC_POPDELETE
)
2014 popup
.AppendMenuIcon(IDGITLC_DELETE
, IDS_MENUREMOVE
, IDI_DELETE
);
2017 if ( (wcStatus
& CTGitPath::LOGACTIONS_UNVER
|| wcStatus
& CTGitPath::LOGACTIONS_DELETED
) )
2019 if (m_dwContextMenus
& GITSLC_POPIGNORE
)
2022 CTGitPathList ignorelist
;
2023 FillListOfSelectedItemPaths(ignorelist
);
2024 //check if all selected entries have the same extension
2025 bool bSameExt
= true;
2027 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
2029 if (sExt
.IsEmpty() && (i
==0))
2030 sExt
= ignorelist
[i
].GetFileExtension();
2031 else if (sExt
.CompareNoCase(ignorelist
[i
].GetFileExtension())!=0)
2036 if (ignoreSubMenu
.CreateMenu())
2039 if (ignorelist
.GetCount()==1)
2040 ignorepath
= ignorelist
[0].GetFileOrDirectoryName();
2042 ignorepath
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
2043 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNORE
, ignorepath
);
2044 ignorepath
= _T("*")+sExt
;
2045 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREMASK
, ignorepath
);
2047 temp
.LoadString(IDS_MENUIGNORE
);
2048 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)ignoreSubMenu
.m_hMenu
, temp
);
2054 if (ignorelist
.GetCount()==1)
2056 temp
.LoadString(IDS_MENUIGNORE
);
2060 temp
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
2062 popup
.AppendMenuIcon(IDGITLC_IGNORE
, temp
, IDI_IGNORE
);
2070 if (GetSelectedCount() > 0)
2073 if ((!entry
->IsFolder())&&(wcStatus
>= git_wc_status_normal
)
2074 &&(wcStatus
!=git_wc_status_missing
)&&(wcStatus
!=git_wc_status_deleted
)
2075 &&(wcStatus
!=git_wc_status_added
))
2077 popup
.AppendMenu(MF_SEPARATOR
);
2078 if ((entry
->lock_token
.IsEmpty())&&(!entry
->IsFolder()))
2080 if (m_dwContextMenus
& SVNSLC_POPLOCK
)
2082 popup
.AppendMenuIcon(IDSVNLC_LOCK
, IDS_MENU_LOCK
, IDI_LOCK
);
2085 if ((!entry
->lock_token
.IsEmpty())&&(!entry
->IsFolder()))
2087 if (m_dwContextMenus
& SVNSLC_POPUNLOCK
)
2089 popup
.AppendMenuIcon(IDSVNLC_UNLOCK
, IDS_MENU_UNLOCK
, IDI_UNLOCK
);
2094 if ((!entry
->IsFolder())&&((!entry
->lock_token
.IsEmpty())||(!entry
->lock_remotetoken
.IsEmpty())))
2096 if (m_dwContextMenus
& SVNSLC_POPUNLOCKFORCE
)
2098 popup
.AppendMenuIcon(IDSVNLC_UNLOCKFORCE
, IDS_MENU_UNLOCKFORCE
, IDI_UNLOCK
);
2102 if (wcStatus
!= git_wc_status_missing
&& wcStatus
!= git_wc_status_deleted
&&wcStatus
!=git_wc_status_unversioned
)
2104 popup
.AppendMenu(MF_SEPARATOR
);
2105 popup
.AppendMenuIcon(IDSVNLC_PROPERTIES
, IDS_STATUSLIST_CONTEXT_PROPERTIES
, IDI_PROPERTIES
);
2108 popup
.AppendMenu(MF_SEPARATOR
);
2109 popup
.AppendMenuIcon(IDGITLC_COPY
, IDS_STATUSLIST_CONTEXT_COPY
, IDI_COPYCLIP
);
2110 popup
.AppendMenuIcon(IDGITLC_COPYEXT
, IDS_STATUSLIST_CONTEXT_COPYEXT
, IDI_COPYCLIP
);
2112 if ((m_dwContextMenus
& SVNSLC_POPCHANGELISTS
))
2113 &&(wcStatus
!= git_wc_status_unversioned
)&&(wcStatus
!= git_wc_status_none
))
2115 popup
.AppendMenu(MF_SEPARATOR
);
2116 // changelist commands
2117 size_t numChangelists
= GetNumberOfChangelistsInSelection();
2118 if (numChangelists
> 0)
2120 popup
.AppendMenuIcon(IDSVNLC_REMOVEFROMCS
, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS
);
2122 if ((!entry
->IsFolder())&&(changelistSubMenu
.CreateMenu()))
2125 temp
.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS
);
2126 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATECS
, temp
);
2128 if (entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
))
2130 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
2131 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATEIGNORECS
, SVNSLC_IGNORECHANGELIST
);
2134 if (m_changelists
.size() > 0)
2136 // find the changelist names
2137 bool bNeedSeparator
= true;
2138 int cmdID
= IDSVNLC_MOVETOCS
;
2139 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
2141 if ((entry
->changelist
.Compare(it
->first
))&&(it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)))
2145 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
2146 bNeedSeparator
= false;
2148 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, cmdID
, it
->first
);
2153 temp
.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS
);
2154 popup
.AppendMenu(MF_POPUP
|MF_STRING
, (UINT_PTR
)changelistSubMenu
.GetSafeHmenu(), temp
);
2160 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2163 AfxGetApp()->DoWaitCursor(1);
2164 //int iItemCountBeforeMenuCmd = GetItemCount();
2165 //bool bForce = false;
2168 case IDGITLC_VIEWREV
:
2169 OpenFile(filepath
, ALTERNATIVEEDITOR
);
2172 OpenFile(filepath
,OPEN
);
2174 case IDGITLC_OPENWITH
:
2175 OpenFile(filepath
,OPEN_WITH
);
2177 case IDGITLC_EXPLORE
:
2179 ShellExecute(this->m_hWnd
, _T("explore"), filepath
->GetDirectory().GetWinPath(), NULL
, NULL
, SW_SHOW
);
2183 // Compare current version and work copy.
2184 case IDGITLC_COMPAREWC
:
2186 POSITION pos
= GetFirstSelectedItemPosition();
2189 int index
= GetNextSelectedItem(pos
);
2194 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2195 case IDGITLC_COMPARE
:
2197 POSITION pos
= GetFirstSelectedItemPosition();
2200 int index
= GetNextSelectedItem(pos
);
2205 case IDGITLC_COMPARETWO
:
2207 POSITION pos
= GetFirstSelectedItemPosition();
2210 int index
= GetNextSelectedItem(pos
);
2211 StartDiffTwo(index
);
2215 case IDGITLC_COMPARETWOFILES
:
2217 POSITION pos
= GetFirstSelectedItemPosition();
2218 CTGitPath
* firstfilepath
= NULL
, * secondfilepath
= NULL
;
2221 firstfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
2222 secondfilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
2224 ASSERT(firstfilepath
!= NULL
&& secondfilepath
!= NULL
);
2226 sCmd
.Format(_T("\"%s\" /command:diff /path:\"%s\" /path2:\"%s\" /hwnd:%ld"), (LPCTSTR
)(CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe")), firstfilepath
->GetWinPath(), secondfilepath
->GetWinPath(), (unsigned long)m_hWnd
);
2227 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
2230 case IDGITLC_GNUDIFF1
:
2232 // SVNDiff diff(NULL, this->m_hWnd, true);
2234 // if (entry->remotestatus <= git_wc_status_normal)
2235 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2237 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2238 if(m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2242 fromwhere
= _T("~1");
2243 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,GitRev::GetWorkingCopy(),
2244 *filepath
,GitRev::GetHead()+fromwhere
);
2248 if((filepath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
)) ==0)
2249 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_CurrentVersion
+_T("~1"),
2250 *filepath
,m_CurrentVersion
);
2254 if(filepath
->m_ParentNo
& MERGE_MASK
)
2259 str
.Format(_T("%s^%d"),m_CurrentVersion
,(filepath
->m_ParentNo
&PARENT_MASK
)+1);
2262 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_CurrentVersion
,
2263 *filepath
,str
, false,false,false,
2264 !!(filepath
->m_ParentNo
& MERGE_MASK
));
2269 case IDGITLC_GNUDIFF2
:
2271 // SVNDiff diff(NULL, this->m_hWnd, true);
2273 // if (entry->remotestatus <= git_wc_status_normal)
2274 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2276 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2278 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_Rev1
,
2284 { // The add went ok, but we now need to run through the selected items again
2285 // and update their status
2286 std::vector
<int> selectIndex
;
2288 POSITION pos
= GetFirstSelectedItemPosition();
2290 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2292 selectIndex
.push_back(index
);
2294 for(int i
=0;i
<selectIndex
.size();i
++)
2296 index
=selectIndex
[i
];
2298 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2303 cmd
.Format(_T("git.exe add -f -- \"%s\""), path
->GetGitPathString());
2305 if (!g_Git
.Run(cmd
, &output
, NULL
, CP_ACP
))
2307 path
->m_Action
= CTGitPath::LOGACTIONS_ADDED
;
2308 SetEntryCheck(path
,index
,true);
2310 SetItemGroup(index
,0);
2311 this->m_StatusFileList
.AddPath(*path
);
2312 this->m_UnRevFileList
.RemoveItem(*path
);
2313 this->m_IgnoreFileList
.RemoveItem(*path
);
2315 Show(this->m_dwShow
,0,true,true,true);
2322 case IDGITLC_DELETE
:
2325 std::vector
<int> selectIndex
;
2327 POSITION pos
= GetFirstSelectedItemPosition();
2329 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2331 selectIndex
.push_back(index
);
2334 //Create file-list ('\0' separated) for SHFileOperation
2336 for(int i
=0;i
<selectIndex
.size();i
++)
2338 index
=selectIndex
[i
];
2340 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2345 filelist
+= path
->GetWinPathString();
2346 filelist
+= _T("|");
2348 filelist
+= _T("|");
2349 int len
= filelist
.GetLength();
2350 TCHAR
* buf
= new TCHAR
[len
+2];
2351 _tcscpy_s(buf
, len
+2, filelist
);
2352 for (int i
=0; i
<len
; ++i
)
2355 SHFILEOPSTRUCT fileop
;
2356 fileop
.hwnd
= this->m_hWnd
;
2357 fileop
.wFunc
= FO_DELETE
;
2360 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
2361 fileop
.lpszProgressTitle
= _T("deleting file");
2362 int result
= SHFileOperation(&fileop
);
2365 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
2368 POSITION pos
= NULL
;
2369 while ((pos
= GetFirstSelectedItemPosition()) != 0)
2371 int index
= GetNextSelectedItem(pos
);
2372 if (GetCheck(index
))
2376 RemoveListEntry(index
);
2385 CAppUtils::LaunchTortoiseBlame(g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath(), m_CurrentVersion
);
2392 sCmd
.Format(_T("\"%s\" /command:log /path:\"%s\""),
2393 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath());
2395 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
2399 case IDGITLC_EDITCONFLICT
:
2401 CAppUtils::ConflictEdit(*filepath
,false,this->m_bIsRevertTheirMy
);
2404 case IDGITLC_RESOLVETHEIRS
: //follow up
2405 case IDGITLC_RESOLVEMINE
: //follow up
2406 case IDGITLC_RESOLVECONFLICT
:
2408 if (CMessageBox::Show(m_hWnd
, IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
)==IDYES
)
2410 POSITION pos
= GetFirstSelectedItemPosition();
2414 index
= GetNextSelectedItem(pos
);
2415 CTGitPath
* fentry
=(CTGitPath
*) this->GetItemData(index
);
2418 CString gitcmd
,output
;
2421 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVETHEIRS
) ||
2422 ((this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVEMINE
) )
2424 gitcmd
.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry
->GetGitPathString());
2425 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2427 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2432 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVEMINE
) ||
2433 ((this->m_bIsRevertTheirMy
)&&cmd
== IDGITLC_RESOLVETHEIRS
) )
2435 gitcmd
.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry
->GetGitPathString());
2436 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2438 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2444 if ( fentry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
2446 gitcmd
.Format(_T("git.exe add -f -- \"%s\""),fentry
->GetGitPathString());
2447 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2449 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2453 fentry
->m_Action
|= CTGitPath::LOGACTIONS_MODIFIED
;
2454 fentry
->m_Action
&=~CTGitPath::LOGACTIONS_UNMERGED
;
2458 CAppUtils::RemoveTempMergeFile(*fentry
);
2461 Show(m_dwShow
, 0, m_bShowFolders
,0,true);
2466 case IDGITLC_IGNORE
:
2468 CTGitPathList ignorelist
;
2469 //std::vector<CString> toremove;
2470 FillListOfSelectedItemPaths(ignorelist
, true);
2473 if(!CAppUtils::IgnoreFile(ignorelist
,false))
2476 for(int i
=0;i
<ignorelist
.GetCount();i
++)
2478 int nListboxEntries
= GetItemCount();
2479 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2481 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2482 if (path
->GetGitPathString()==ignorelist
[i
].GetGitPathString())
2484 RemoveListEntry(nItem
);
2492 CTSVNPathList ignorelist
;
2493 std::vector
<CString
> toremove
;
2494 FillListOfSelectedItemPaths(ignorelist
, true);
2496 for (int j
=0; j
<ignorelist
.GetCount(); ++j
)
2498 int nListboxEntries
= GetItemCount();
2499 for (int i
=0; i
<nListboxEntries
; ++i
)
2501 if (GetListEntry(i
)->GetPath().IsEquivalentTo(ignorelist
[j
]))
2507 CString name
= CPathUtils::PathPatternEscape(ignorelist
[j
].GetFileOrDirectoryName());
2508 CTSVNPath parentfolder
= ignorelist
[j
].GetContainingDirectory();
2509 SVNProperties
props(parentfolder
, SVNRev::REV_WC
, false);
2511 for (int i
=0; i
<props
.GetCount(); i
++)
2513 CString
propname(props
.GetItemName(i
).c_str());
2514 if (propname
.CompareNoCase(_T("git:ignore"))==0)
2517 // treat values as normal text even if they're not
2518 value
= (char *)props
.GetItemValue(i
).c_str();
2521 if (value
.IsEmpty())
2525 value
= value
.Trim("\n\r");
2530 if (!props
.Add(_T("git:ignore"), (LPCSTR
)value
))
2533 temp
.Format(IDS_ERR_FAILEDIGNOREPROPERTY
, (LPCTSTR
)name
);
2534 CMessageBox::Show(this->m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONERROR
);
2537 if (GetCheck(selIndex
))
2541 // now, if we ignored a folder, remove all its children
2542 if (ignorelist
[j
].IsDirectory())
2544 for (int i
=0; i
<(int)m_arListArray
.size(); ++i
)
2546 FileEntry
* entry
= GetListEntry(i
);
2547 if (entry
->status
== git_wc_status_unversioned
)
2549 if (!ignorelist
[j
].IsEquivalentTo(entry
->GetPath())&&(ignorelist
[j
].IsAncestorOf(entry
->GetPath())))
2551 entry
->status
= git_wc_status_ignored
;
2552 entry
->textstatus
= git_wc_status_ignored
;
2555 toremove
.push_back(entry
->GetPath().GetSVNPathString());
2561 CTSVNPath basepath
= m_arStatusArray
[m_arListArray
[selIndex
]]->basepath
;
2563 FileEntry
* entry
= m_arStatusArray
[m_arListArray
[selIndex
]];
2564 if ( entry
->status
== git_wc_status_unversioned
) // keep "deleted" items
2565 toremove
.push_back(entry
->GetPath().GetSVNPathString());
2567 if (!m_bIgnoreRemoveOnly
)
2570 git_wc_status2_t
* s
;
2572 s
= status
.GetFirstFileStatus(parentfolder
, gitPath
, false, git_depth_empty
);
2573 // first check if the folder isn't already present in the list
2574 bool bFound
= false;
2575 nListboxEntries
= GetItemCount();
2576 for (int i
=0; i
<nListboxEntries
; ++i
)
2578 FileEntry
* entry
= GetListEntry(i
);
2579 if (entry
->path
.IsEquivalentTo(gitPath
))
2589 FileEntry
* entry
= new FileEntry();
2590 entry
->path
= gitPath
;
2591 entry
->basepath
= basepath
;
2592 entry
->status
= SVNStatus::GetMoreImportant(s
->text_status
, s
->prop_status
);
2593 entry
->textstatus
= s
->text_status
;
2594 entry
->propstatus
= s
->prop_status
;
2595 entry
->remotestatus
= SVNStatus::GetMoreImportant(s
->repos_text_status
, s
->repos_prop_status
);
2596 entry
->remotetextstatus
= s
->repos_text_status
;
2597 entry
->remotepropstatus
= s
->repos_prop_status
;
2598 entry
->inunversionedfolder
= FALSE
;
2599 entry
->checked
= true;
2600 entry
->inexternal
= false;
2601 entry
->direct
= false;
2602 entry
->isfolder
= true;
2603 entry
->last_commit_date
= 0;
2604 entry
->last_commit_rev
= 0;
2605 entry
->remoterev
= 0;
2610 entry
->url
= CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s
->entry
->url
));
2613 if (s
->entry
&& s
->entry
->present_props
)
2615 entry
->present_props
= s
->entry
->present_props
;
2617 m_arStatusArray
.push_back(entry
);
2618 m_arListArray
.push_back(m_arStatusArray
.size()-1);
2619 AddEntry(entry
, langID
, GetItemCount());
2624 for (std::vector
<CString
>::iterator it
= toremove
.begin(); it
!= toremove
.end(); ++it
)
2626 int nListboxEntries
= GetItemCount();
2627 for (int i
=0; i
<nListboxEntries
; ++i
)
2629 if (GetListEntry(i
)->path
.GetSVNPathString().Compare(*it
)==0)
2640 case IDGITLC_IGNOREMASK
:
2643 CString ext
=filepath
->GetFileExtension();
2644 CTGitPathList ignorelist
;
2645 FillListOfSelectedItemPaths(ignorelist
, true);
2648 CAppUtils::IgnoreFile(ignorelist
,true);
2650 common
=ignorelist
.GetCommonRoot().GetGitPathString();
2652 for (int i
=0; i
< GetItemCount(); ++i
)
2654 CTGitPath
*path
=(CTGitPath
*)GetItemData(i
);
2655 if(!( path
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
2657 if( path
->GetGitPathString().Left(common
.GetLength()) == common
)
2659 if (path
->GetFileExtension()==ext
)
2662 i
--; // remove index i at item, new one will replace.
2667 CWnd
* pParent
= GetParent();
2668 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2670 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2676 std::set
<CTSVNPath
> parentlist
;
2677 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
2679 parentlist
.insert(ignorelist
[i
].GetContainingDirectory());
2681 std::set
<CTSVNPath
>::iterator it
;
2682 std::vector
<CString
> toremove
;
2684 for (it
= parentlist
.begin(); it
!= parentlist
.end(); ++it
)
2686 CTSVNPath parentFolder
= (*it
).GetDirectory();
2687 SVNProperties
props(parentFolder
, SVNRev::REV_WC
, false);
2689 for (int i
=0; i
<props
.GetCount(); i
++)
2691 CString
propname(props
.GetItemName(i
).c_str());
2692 if (propname
.CompareNoCase(_T("git:ignore"))==0)
2695 // treat values as normal text even if they're not
2696 value
= (char *)props
.GetItemValue(i
).c_str();
2699 if (value
.IsEmpty())
2703 value
= value
.Trim("\n\r");
2708 if (!props
.Add(_T("git:ignore"), (LPCSTR
)value
))
2711 temp
.Format(IDS_ERR_FAILEDIGNOREPROPERTY
, (LPCTSTR
)name
);
2712 CMessageBox::Show(this->m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONERROR
);
2717 int nListboxEntries
= GetItemCount();
2718 for (int i
=0; i
<nListboxEntries
; ++i
)
2720 FileEntry
* entry
= GetListEntry(i
);
2721 ASSERT(entry
!= NULL
);
2724 if (basepath
.IsEmpty())
2725 basepath
= entry
->basepath
;
2726 // since we ignored files with a mask (e.g. *.exe)
2727 // we have to find find all files in the same
2728 // folder (IsAncestorOf() returns TRUE for _all_ children,
2729 // not just the immediate ones) which match the
2730 // mask and remove them from the list too.
2731 if ((entry
->status
== git_wc_status_unversioned
)&&(parentFolder
.IsAncestorOf(entry
->path
)))
2733 CString f
= entry
->path
.GetSVNPathString();
2734 if (f
.Mid(parentFolder
.GetSVNPathString().GetLength()).Find('/')<=0)
2736 if (CStringUtils::WildCardMatch(name
, f
))
2741 toremove
.push_back(f
);
2746 if (!m_bIgnoreRemoveOnly
)
2749 git_wc_status2_t
* s
;
2751 s
= status
.GetFirstFileStatus(parentFolder
, gitPath
, false, git_depth_empty
);
2754 // first check if the folder isn't already present in the list
2755 bool bFound
= false;
2756 for (int i
=0; i
<nListboxEntries
; ++i
)
2758 FileEntry
* entry
= GetListEntry(i
);
2759 if (entry
->path
.IsEquivalentTo(gitPath
))
2767 FileEntry
* entry
= new FileEntry();
2768 entry
->path
= gitPath
;
2769 entry
->basepath
= basepath
;
2770 entry
->status
= SVNStatus::GetMoreImportant(s
->text_status
, s
->prop_status
);
2771 entry
->textstatus
= s
->text_status
;
2772 entry
->propstatus
= s
->prop_status
;
2773 entry
->remotestatus
= SVNStatus::GetMoreImportant(s
->repos_text_status
, s
->repos_prop_status
);
2774 entry
->remotetextstatus
= s
->repos_text_status
;
2775 entry
->remotepropstatus
= s
->repos_prop_status
;
2776 entry
->inunversionedfolder
= false;
2777 entry
->checked
= true;
2778 entry
->inexternal
= false;
2779 entry
->direct
= false;
2780 entry
->isfolder
= true;
2781 entry
->last_commit_date
= 0;
2782 entry
->last_commit_rev
= 0;
2783 entry
->remoterev
= 0;
2788 entry
->url
= CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s
->entry
->url
));
2791 if (s
->entry
&& s
->entry
->present_props
)
2793 entry
->present_props
= s
->entry
->present_props
;
2795 m_arStatusArray
.push_back(entry
);
2796 m_arListArray
.push_back(m_arStatusArray
.size()-1);
2797 AddEntry(entry
, langID
, GetItemCount());
2803 for (std::vector
<CString
>::iterator it
= toremove
.begin(); it
!= toremove
.end(); ++it
)
2805 int nListboxEntries
= GetItemCount();
2806 for (int i
=0; i
<nListboxEntries
; ++i
)
2808 if (GetListEntry(i
)->path
.GetSVNPathString().Compare(*it
)==0)
2820 case IDGITLC_REVERT
:
2822 // If at least one item is not in the status "added"
2823 // we ask for a confirmation
2824 BOOL bConfirm
= FALSE
;
2825 POSITION pos
= GetFirstSelectedItemPosition();
2827 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2829 //FileEntry * fentry = GetListEntry(index);
2830 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
2831 if(fentry
&& fentry
->m_Action
&CTGitPath::LOGACTIONS_MODIFIED
)
2839 str
.Format(IDS_PROC_WARNREVERT
,GetSelectedCount());
2841 if (!bConfirm
|| CMessageBox::Show(this->m_hWnd
, str
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
2843 CTGitPathList targetList
;
2844 FillListOfSelectedItemPaths(targetList
);
2846 // make sure that the list is reverse sorted, so that
2847 // children are removed before any parents
2848 targetList
.SortByPathname(true);
2850 // put all reverted files in the trashbin, except the ones with 'added'
2851 // status because they are not restored by the revert.
2852 CTGitPathList delList
;
2853 POSITION pos
= GetFirstSelectedItemPosition();
2855 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2857 CTGitPath
*entry
=(CTGitPath
*)GetItemData(index
);
2858 if (entry
&&(!(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
))
2859 && (!(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)))
2862 fullpath
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+entry
->GetWinPath());
2863 delList
.AddPath(fullpath
);
2866 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
2867 delList
.DeleteAllFiles(true);
2869 CString revertToCommit
= _T("HEAD");
2871 revertToCommit
= _T("HEAD~1");
2872 if (g_Git
.Revert(revertToCommit
, targetList
))
2874 CMessageBox::Show(this->m_hWnd
, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR
);
2878 bool updateStatusList
= false;
2879 for(int i
=0;i
<targetList
.GetCount();i
++)
2881 int nListboxEntries
= GetItemCount();
2882 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2884 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2885 if (path
->GetGitPathString()==targetList
[i
].GetGitPathString())
2887 if(path
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2889 path
->m_Action
= CTGitPath::LOGACTIONS_UNVER
;
2890 SetEntryCheck(path
,nItem
,false);
2891 updateStatusList
= true;
2892 SetItemGroup(nItem
,1);
2893 this->m_StatusFileList
.RemoveItem(*path
);
2894 this->m_UnRevFileList
.AddPath(*path
);
2895 //this->m_IgnoreFileList.RemoveItem(*path);
2900 RemoveListEntry(nItem
);
2908 Show(m_dwShow
, 0, m_bShowFolders
,updateStatusList
,true);
2916 CopySelectedEntriesToClipboard(0);
2918 case IDGITLC_COPYEXT
:
2919 CopySelectedEntriesToClipboard((DWORD
)-1);
2922 case IDGITLC_SAVEAS
:
2923 FileSaveAs(filepath
);
2926 case IDGITLC_REVERTTOREV
:
2927 RevertSelectedItemToVersion();
2930 case IDSVNLC_PROPERTIES
:
2932 CTSVNPathList targetList
;
2933 FillListOfSelectedItemPaths(targetList
);
2934 CEditPropertiesDlg dlg
;
2935 dlg
.SetPathList(targetList
);
2937 if (dlg
.HasChanged())
2939 // since the user might have changed/removed/added
2940 // properties recursively, we don't really know
2941 // which items have changed their status.
2942 // So tell the parent to do a refresh.
2943 CWnd
* pParent
= GetParent();
2944 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2946 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
2951 case IDSVNLC_COMMIT
:
2953 CTSVNPathList targetList
;
2954 FillListOfSelectedItemPaths(targetList
);
2955 CTSVNPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2956 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2957 CString commandline
= CPathUtils::GetAppDirectory();
2958 commandline
+= _T("TortoiseProc.exe /command:commit /pathfile:\"");
2959 commandline
+= tempFile
.GetWinPathString();
2960 commandline
+= _T("\"");
2961 commandline
+= _T(" /deletepathfile");
2962 CAppUtils::LaunchApplication(commandline
, NULL
, false);
2966 case IDSVNLC_COMPAREWC
:
2968 POSITION pos
= GetFirstSelectedItemPosition();
2971 int index
= GetNextSelectedItem(pos
);
2972 FileEntry
* entry
= GetListEntry(index
);
2973 ASSERT(entry
!= NULL
);
2976 SVNDiff
diff(NULL
, m_hWnd
, true);
2977 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2978 git_revnum_t baseRev
= entry
->Revision
;
2979 diff
.DiffFileAgainstBase(
2980 entry
->path
, baseRev
, entry
->textstatus
, entry
->propstatus
);
2984 case IDSVNLC_GNUDIFF1
:
2986 SVNDiff
diff(NULL
, this->m_hWnd
, true);
2988 if (entry
->remotestatus
<= git_wc_status_normal
)
2989 CAppUtils::StartShowUnifiedDiff(m_hWnd
, entry
->path
, SVNRev::REV_BASE
, entry
->path
, SVNRev::REV_WC
);
2991 CAppUtils::StartShowUnifiedDiff(m_hWnd
, entry
->path
, SVNRev::REV_WC
, entry
->path
, SVNRev::REV_HEAD
);
2994 case IDSVNLC_UPDATE
:
2996 CTSVNPathList targetList
;
2997 FillListOfSelectedItemPaths(targetList
);
2998 bool bAllExist
= true;
2999 for (int i
=0; i
<targetList
.GetCount(); ++i
)
3001 if (!targetList
[i
].Exists())
3009 CSVNProgressDlg dlg
;
3010 dlg
.SetCommand(CSVNProgressDlg::SVNProgress_Update
);
3011 dlg
.SetPathList(targetList
);
3012 dlg
.SetRevision(SVNRev::REV_HEAD
);
3017 CString sTempFile
= CTempFiles::Instance().GetTempFilePath(false).GetWinPathString();
3018 targetList
.WriteToFile(sTempFile
, false);
3020 sCmd
.Format(_T("\"%s\" /command:update /rev /pathfile:\"%s\" /deletepathfile"),
3021 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR
)sTempFile
);
3023 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
3028 case IDSVNLC_REMOVE
:
3031 CTSVNPathList itemsToRemove
;
3032 FillListOfSelectedItemPaths(itemsToRemove
);
3034 // We must sort items before removing, so that files are always removed
3035 // *before* their parents
3036 itemsToRemove
.SortByPathname(true);
3038 bool bSuccess
= false;
3039 if (git
.Remove(itemsToRemove
, FALSE
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)))
3045 if ((git
.Err
->apr_err
== SVN_ERR_UNVERSIONED_RESOURCE
) ||
3046 (git
.Err
->apr_err
== SVN_ERR_CLIENT_MODIFIED
))
3048 CString msg
, yes
, no
, yestoall
;
3049 msg
.Format(IDS_PROC_REMOVEFORCE
, (LPCTSTR
)git
.GetLastErrorMessage());
3050 yes
.LoadString(IDS_MSGBOX_YES
);
3051 no
.LoadString(IDS_MSGBOX_NO
);
3052 yestoall
.LoadString(IDS_PROC_YESTOALL
);
3053 UINT ret
= CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_ERROR
, yes
, no
, yestoall
);
3054 if ((ret
== 1)||(ret
==3))
3056 if (!git
.Remove(itemsToRemove
, TRUE
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)))
3058 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3065 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3069 // The remove went ok, but we now need to run through the selected items again
3070 // and update their status
3071 POSITION pos
= GetFirstSelectedItemPosition();
3073 std::vector
<int> entriesToRemove
;
3074 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3076 FileEntry
* e
= GetListEntry(index
);
3078 ((e
->textstatus
== git_wc_status_unversioned
)||
3079 (e
->textstatus
== git_wc_status_none
)||
3080 (e
->textstatus
== git_wc_status_ignored
)))
3082 if (GetCheck(index
))
3085 entriesToRemove
.push_back(index
);
3089 e
->textstatus
= git_wc_status_deleted
;
3090 e
->status
= git_wc_status_deleted
;
3091 SetEntryCheck(e
,index
,true);
3094 for (std::vector
<int>::reverse_iterator it
= entriesToRemove
.rbegin(); it
!= entriesToRemove
.rend(); ++it
)
3096 RemoveListEntry(*it
);
3100 Show(m_dwShow
, 0, m_bShowFolders
);
3104 case IDSVNLC_DELETE
:
3106 CTSVNPathList pathlist
;
3107 FillListOfSelectedItemPaths(pathlist
);
3108 pathlist
.RemoveChildren();
3110 for (INT_PTR i
=0; i
<pathlist
.GetCount(); ++i
)
3112 filelist
+= pathlist
[i
].GetWinPathString();
3113 filelist
+= _T("|");
3115 filelist
+= _T("|");
3116 int len
= filelist
.GetLength();
3117 TCHAR
* buf
= new TCHAR
[len
+2];
3118 _tcscpy_s(buf
, len
+2, filelist
);
3119 for (int i
=0; i
<len
; ++i
)
3122 SHFILEOPSTRUCT fileop
;
3123 fileop
.hwnd
= this->m_hWnd
;
3124 fileop
.wFunc
= FO_DELETE
;
3127 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
3128 fileop
.lpszProgressTitle
= _T("deleting file");
3129 int result
= SHFileOperation(&fileop
);
3132 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
3135 POSITION pos
= NULL
;
3136 CTSVNPathList deletedlist
; // to store list of deleted folders
3137 while ((pos
= GetFirstSelectedItemPosition()) != 0)
3139 int index
= GetNextSelectedItem(pos
);
3140 if (GetCheck(index
))
3143 FileEntry
* fentry
= GetListEntry(index
);
3144 if ((fentry
)&&(fentry
->isfolder
))
3145 deletedlist
.AddPath(fentry
->path
);
3146 RemoveListEntry(index
);
3148 // now go through the list of deleted folders
3149 // and remove all their children from the list too!
3150 int nListboxEntries
= GetItemCount();
3151 for (int folderindex
= 0; folderindex
< deletedlist
.GetCount(); ++folderindex
)
3153 CTSVNPath folderpath
= deletedlist
[folderindex
];
3154 for (int i
=0; i
<nListboxEntries
; ++i
)
3156 FileEntry
* entry
= GetListEntry(i
);
3157 if (folderpath
.IsAncestorOf(entry
->path
))
3159 RemoveListEntry(i
--);
3173 CTSVNPathList itemsToAdd
;
3174 FillListOfSelectedItemPaths(itemsToAdd
);
3176 // We must sort items before adding, so that folders are always added
3177 // *before* any of their children
3178 itemsToAdd
.SortByPathname();
3180 ProjectProperties props
;
3181 props
.ReadPropsPathList(itemsToAdd
);
3182 if (git
.Add(itemsToAdd
, &props
, git_depth_empty
, TRUE
, TRUE
, TRUE
))
3184 // The add went ok, but we now need to run through the selected items again
3185 // and update their status
3186 POSITION pos
= GetFirstSelectedItemPosition();
3188 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3190 FileEntry
* e
= GetListEntry(index
);
3191 e
->textstatus
= git_wc_status_added
;
3192 e
->propstatus
= git_wc_status_none
;
3193 e
->status
= git_wc_status_added
;
3194 SetEntryCheck(e
,index
,true);
3199 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3202 Show(m_dwShow
, 0, m_bShowFolders
);
3206 case IDSVNLC_ADD_RECURSIVE
:
3208 CTSVNPathList itemsToAdd
;
3209 FillListOfSelectedItemPaths(itemsToAdd
);
3212 dlg
.m_pathList
= itemsToAdd
;
3213 if (dlg
.DoModal() == IDOK
)
3215 if (dlg
.m_pathList
.GetCount() == 0)
3217 CSVNProgressDlg progDlg
;
3218 progDlg
.SetCommand(CSVNProgressDlg::SVNProgress_Add
);
3219 progDlg
.SetPathList(dlg
.m_pathList
);
3220 ProjectProperties props
;
3221 props
.ReadPropsPathList(dlg
.m_pathList
);
3222 progDlg
.SetProjectProperties(props
);
3223 progDlg
.SetItemCount(dlg
.m_pathList
.GetCount());
3227 CWnd
* pParent
= GetParent();
3228 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3230 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
3236 case IDSVNLC_REPAIRMOVE
:
3238 POSITION pos
= GetFirstSelectedItemPosition();
3239 int index
= GetNextSelectedItem(pos
);
3240 FileEntry
* entry1
= NULL
;
3241 FileEntry
* entry2
= NULL
;
3244 entry1
= GetListEntry(index
);
3245 git_wc_status_kind status1
= git_wc_status_none
;
3246 git_wc_status_kind status2
= git_wc_status_none
;
3249 status1
= entry1
->status
;
3250 index
= GetNextSelectedItem(pos
);
3253 entry2
= GetListEntry(index
);
3256 status2
= entry2
->status
;
3257 if (status2
== git_wc_status_missing
&& status1
== git_wc_status_unversioned
)
3259 FileEntry
* tempentry
= entry1
;
3263 // entry1 was renamed to entry2 but outside of Subversion
3264 // fix this by moving entry2 back to entry1 first,
3265 // then do an git-move from entry1 to entry2
3266 if (MoveFile(entry2
->GetPath().GetWinPath(), entry1
->GetPath().GetWinPath()))
3269 if (!git
.Move(CTSVNPathList(entry1
->GetPath()), entry2
->GetPath(), TRUE
))
3271 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3275 // check the previously unversioned item
3276 entry1
->checked
= true;
3277 // fixing the move was successful. We have to adjust the new status of the
3279 // Since we don't know if the moved/renamed file had local modifications or not,
3280 // we can't guess the new status. That means we have to refresh...
3281 CWnd
* pParent
= GetParent();
3282 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3284 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
3291 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
3292 FORMAT_MESSAGE_FROM_SYSTEM
|
3293 FORMAT_MESSAGE_IGNORE_INSERTS
,
3296 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
3301 MessageBox((LPCTSTR
)lpMsgBuf
, _T("Error"), MB_OK
| MB_ICONINFORMATION
);
3302 LocalFree( lpMsgBuf
);
3310 case IDSVNLC_REMOVEFROMCS
:
3312 CTSVNPathList changelistItems
;
3313 FillListOfSelectedItemPaths(changelistItems
);
3316 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
3318 // The changelists were removed, but we now need to run through the selected items again
3319 // and update their changelist
3320 POSITION pos
= GetFirstSelectedItemPosition();
3322 std::vector
<int> entriesToRemove
;
3323 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3325 FileEntry
* e
= GetListEntry(index
);
3328 e
->changelist
.Empty();
3329 if (e
->status
== git_wc_status_normal
)
3331 // remove the entry completely
3332 entriesToRemove
.push_back(index
);
3335 SetItemGroup(index
, 0);
3338 for (std::vector
<int>::reverse_iterator it
= entriesToRemove
.rbegin(); it
!= entriesToRemove
.rend(); ++it
)
3340 RemoveListEntry(*it
);
3342 // TODO: Should we go through all entries here and check if we also could
3343 // remove the changelist from m_changelists ?
3347 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3352 case IDSVNLC_CREATEIGNORECS
:
3353 CreateChangeList(SVNSLC_IGNORECHANGELIST
);
3355 case IDSVNLC_CREATECS
:
3357 CCreateChangelistDlg dlg
;
3358 if (dlg
.DoModal() == IDOK
)
3360 CreateChangeList(dlg
.m_sName
);
3366 if (cmd
< IDSVNLC_MOVETOCS
)
3368 CTSVNPathList changelistItems
;
3369 FillListOfSelectedItemPaths(changelistItems
);
3371 // find the changelist name
3372 CString sChangelist
;
3373 int cmdID
= IDSVNLC_MOVETOCS
;
3375 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
3377 if ((it
->first
.Compare(SVNSLC_IGNORECHANGELIST
))&&(entry
->changelist
.Compare(it
->first
)))
3381 sChangelist
= it
->first
;
3386 if (!sChangelist
.IsEmpty())
3389 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
3391 // The changelists were moved, but we now need to run through the selected items again
3392 // and update their changelist
3393 POSITION pos
= GetFirstSelectedItemPosition();
3395 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3397 FileEntry
* e
= GetListEntry(index
);
3398 e
->changelist
= sChangelist
;
3401 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
3402 SetItemGroup(index
, m_changelists
[e
->changelist
]);
3404 SetItemGroup(index
, 0);
3410 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3420 AfxGetApp()->DoWaitCursor(-1);
3421 GetStatisticsString();
3422 //int iItemCountAfterMenuCmd = GetItemCount();
3423 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
3425 // CWnd* pParent = GetParent();
3426 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3428 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
3431 } // if (popup.CreatePopupMenu())
3432 } // if (selIndex >= 0)
3436 void CGitStatusListCtrl::OnContextMenuHeader(CWnd
* pWnd
, CPoint point
)
3438 Locker
lock(m_critSec
);
3439 m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
3442 void CGitStatusListCtrl::OnContextMenu(CWnd
* pWnd
, CPoint point
)
3447 OnContextMenuList(pWnd
, point
);
3448 } // if (pWnd == this)
3449 else if (pWnd
== GetHeaderCtrl())
3451 OnContextMenuHeader(pWnd
, point
);
3455 void CGitStatusListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3458 Locker
lock(m_critSec
);
3459 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
3464 if (pNMLV
->iItem
< 0)
3466 if (!IsGroupViewEnabled())
3469 DWORD ptW
= GetMessagePos();
3470 pt
.x
= GET_X_LPARAM(ptW
);
3471 pt
.y
= GET_Y_LPARAM(ptW
);
3472 ScreenToClient(&pt
);
3473 int group
= GetGroupFromPoint(&pt
);
3476 // check/uncheck the whole group depending on the check-state
3477 // of the first item in the group
3479 bool bCheck
= false;
3480 bool bFirst
= false;
3482 for (int i
=0; i
<GetItemCount(); ++i
)
3484 SecureZeroMemory(&lv
, sizeof(LVITEM
));
3485 lv
.mask
= LVIF_GROUPID
;
3488 if (lv
.iGroupId
== group
)
3490 CTGitPath
*entry
=(CTGitPath
*)GetItemData(i
);
3494 bCheck
= !GetCheck(i
);
3499 bool bOldCheck
= !!GetCheck(i
);
3500 SetEntryCheck(entry
, i
, bCheck
);
3501 if (bCheck
!= bOldCheck
)
3511 GetStatisticsString();
3517 CTGitPath
*file
=(CTGitPath
*)GetItemData(pNMLV
->iItem
);
3519 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
) {
3520 OpenFile(file
, OPEN
);
3523 if( file
->m_Action
&CTGitPath::LOGACTIONS_UNMERGED
)
3525 CAppUtils::ConflictEdit(*file
,false,m_bIsRevertTheirMy
);
3530 if( (!m_Rev1
.IsEmpty()) || (!m_Rev1
.IsEmpty())) // m_Rev1 twice???
3531 StartDiffTwo(pNMLV
->iItem
);
3533 StartDiff(pNMLV
->iItem
);
3537 void CGitStatusListCtrl::StartDiffTwo(int fileindex
)
3542 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3544 CGitDiff::Diff(&file1
,&file1
,
3549 void CGitStatusListCtrl::StartDiffWC(int fileindex
)
3555 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
3558 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3560 CGitDiff::Diff(&file1
,&file1
, GIT_REV_ZERO
, m_CurrentVersion
);
3564 void CGitStatusListCtrl::StartDiff(int fileindex
)
3569 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3571 if(file1
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
3573 file2
.SetFromGit(file1
.GetGitOldPathString());
3580 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
3583 if(m_amend
&& (file1
.m_Action
& CTGitPath::LOGACTIONS_ADDED
) == 0)
3584 fromwhere
= _T("~1");
3585 if( g_Git
.IsInitRepos())
3586 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3588 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_ADDED
)
3589 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3590 m_CurrentVersion
+fromwhere
,true);
3591 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_DELETED
)
3592 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3593 GitRev::GetHead()+fromwhere
,false);
3595 CGitDiff::Diff(&file1
,&file2
,
3596 CString(GIT_REV_ZERO
),
3597 GitRev::GetHead()+fromwhere
);
3602 CString fromwhere
= m_CurrentVersion
+_T("~1");
3604 fromwhere
= m_CurrentVersion
+_T("~2");
3605 if(rev
.GetCommit(fromwhere
) || (file1
.m_Action
== file1
.LOGACTIONS_ADDED
))
3607 CGitDiff::DiffNull(&file1
,m_CurrentVersion
,true);
3610 else if (file1
.m_Action
== file1
.LOGACTIONS_DELETED
)
3612 CGitDiff::DiffNull(&file1
,fromwhere
,false);
3616 if( file1
.m_ParentNo
& MERGE_MASK
)
3619 CTGitPath base
,theirs
, mine
;
3621 CTGitPath merge
=file1
;
3622 CTGitPath directory
= merge
.GetDirectory();
3624 mine
.SetFromGit(CAppUtils::GetMergeTempFile(_T("LOCAL"),merge
));
3625 theirs
.SetFromGit(CAppUtils::GetMergeTempFile(_T("REMOTE"),merge
));
3626 base
.SetFromGit(CAppUtils::GetMergeTempFile(_T("BASE"),merge
));
3629 //create a empty file, incase stage is not three
3630 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3632 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3634 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3637 merge
.SetFromGit(merge
.GetGitPathString()+_T("Merged"));
3639 int parent1
=-1, parent2
=-1;
3640 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
3642 if(m_arStatusArray
[i
]->GetGitPathString() == file1
.GetGitPathString())
3644 if(m_arStatusArray
[i
]->m_ParentNo
& MERGE_MASK
)
3651 parent1
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
3653 else if (parent2
<0)
3655 parent2
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
3661 if(g_Git
.GetOneFile(m_CurrentVersion
, file1
, (CString
&)merge
.GetWinPathString()))
3663 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3669 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent1
+1);
3671 if(g_Git
.GetOneFile(str
, file1
, (CString
&)mine
.GetWinPathString()))
3673 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3680 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent2
+1);
3682 if(g_Git
.GetOneFile(str
, file1
, (CString
&)theirs
.GetWinPathString()))
3684 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3688 if(parent1
>=0 && parent2
>=0)
3690 CString cmd
, output
;
3691 cmd
.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion
, parent1
+1,
3692 this->m_CurrentVersion
,parent2
+1);
3694 if(g_Git
.Run(cmd
, &output
, NULL
, CP_ACP
))
3699 if(g_Git
.GetOneFile(output
.Left(40), file1
, (CString
&)base
.GetWinPathString()))
3701 CMessageBox::Show(NULL
, _T("Fail to get base file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3705 CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
3711 if( (file1
.m_ParentNo
&PARENT_MASK
) == 0)
3717 str
.Format(_T("^%d"), (file1
.m_ParentNo
&PARENT_MASK
)+1);
3719 CGitDiff::Diff(&file1
,&file2
,
3721 m_CurrentVersion
+str
);
3728 FileEntry
* entry
= GetListEntry(fileindex
);
3729 ASSERT(entry
!= NULL
);
3732 if (((entry
->status
== git_wc_status_normal
)&&(entry
->remotestatus
<= git_wc_status_normal
))||
3733 (entry
->status
== git_wc_status_unversioned
)||(entry
->status
== git_wc_status_none
))
3735 int ret
= (int)ShellExecute(this->m_hWnd
, NULL
, entry
->path
.GetWinPath(), NULL
, NULL
, SW_SHOW
);
3736 if (ret
<= HINSTANCE_ERROR
)
3738 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
3739 cmd
+= entry
->path
.GetWinPathString();
3740 CAppUtils::LaunchApplication(cmd
, NULL
, false);
3745 GitDiff
diff(NULL
, m_hWnd
, true);
3746 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
3748 entry
->path
, entry
->textstatus
, entry
->propstatus
,
3749 entry
->remotetextstatus
, entry
->remotepropstatus
);
3753 CString
CGitStatusListCtrl::GetStatisticsString(bool simple
)
3756 CString sNormal
, sAdded
, sDeleted
, sModified
, sConflicted
, sUnversioned
, sRenamed
;
3757 WORD langID
= (WORD
)(DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3758 TCHAR buf
[MAX_STATUS_STRING_LENGTH
];
3759 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal
, buf
, _countof(buf
), langID
);
3761 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added
, buf
, _countof(buf
), langID
);
3763 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted
, buf
, _countof(buf
), langID
);
3765 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified
, buf
, _countof(buf
), langID
);
3767 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted
, buf
, _countof(buf
), langID
);
3769 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned
, buf
, _countof(buf
), langID
);
3771 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced
, buf
, _countof(buf
), langID
);
3776 sToolTip
.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d"),
3777 this->m_nLineAdded
,this->m_nLineDeleted
,
3778 (LPCTSTR
)sModified
, m_nModified
,
3779 (LPCTSTR
)sAdded
, m_nAdded
,
3780 (LPCTSTR
)sDeleted
, m_nDeleted
,
3781 (LPCTSTR
)sRenamed
, m_nRenamed
3786 sToolTip
.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d"),
3787 this->m_nLineAdded
,this->m_nLineDeleted
,
3788 (LPCTSTR
)sNormal
, m_nNormal
,
3789 (LPCTSTR
)sUnversioned
, m_nUnversioned
,
3790 (LPCTSTR
)sModified
, m_nModified
,
3791 (LPCTSTR
)sAdded
, m_nAdded
,
3792 (LPCTSTR
)sDeleted
, m_nDeleted
,
3793 (LPCTSTR
)sConflicted
, m_nConflicted
3797 sStats
.Format(IDS_COMMITDLG_STATISTICSFORMAT
, m_nSelected
, GetItemCount());
3800 m_pStatLabel
->SetWindowText(sStats
);
3803 if (m_pSelectButton
)
3805 if (m_nSelected
== 0)
3806 m_pSelectButton
->SetCheck(BST_UNCHECKED
);
3807 else if (m_nSelected
!= GetItemCount())
3808 m_pSelectButton
->SetCheck(BST_INDETERMINATE
);
3810 m_pSelectButton
->SetCheck(BST_CHECKED
);
3813 if (m_pConfirmButton
)
3815 m_pConfirmButton
->EnableWindow(m_nSelected
>0);
3823 CString
CGitStatusListCtrl::GetCommonDirectory(bool bStrict
)
3827 // not strict means that the selected folder has priority
3828 if (!m_StatusFileList
.GetCommonDirectory().IsEmpty())
3829 return m_StatusFileList
.GetCommonDirectory().GetWinPath();
3832 CTGitPath commonBaseDirectory
;
3833 int nListItems
= GetItemCount();
3834 for (int i
=0; i
<nListItems
; ++i
)
3836 CTGitPath baseDirectory
,*p
= (CTGitPath
*)this->GetItemData(i
);
3840 baseDirectory
= p
->GetDirectory();
3842 if(commonBaseDirectory
.IsEmpty())
3844 commonBaseDirectory
= baseDirectory
;
3848 if (commonBaseDirectory
.GetWinPathString().GetLength() > baseDirectory
.GetWinPathString().GetLength())
3850 if (baseDirectory
.IsAncestorOf(commonBaseDirectory
))
3851 commonBaseDirectory
= baseDirectory
;
3855 return g_Git
.m_CurrentDir
+CString(_T("\\"))+commonBaseDirectory
.GetWinPath();
3859 void CGitStatusListCtrl::SelectAll(bool bSelect
, bool /*bIncludeNoCommits*/)
3861 CWaitCursor waitCursor
;
3862 // block here so the LVN_ITEMCHANGED messages
3867 int nListItems
= GetItemCount();
3869 m_nSelected
= nListItems
;
3873 for (int i
=0; i
<nListItems
; ++i
)
3875 //FileEntry * entry = GetListEntry(i);
3876 //ASSERT(entry != NULL);
3877 CTGitPath
*path
= (CTGitPath
*) GetItemData(i
);
3880 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
3881 SetEntryCheck(path
,i
,bSelect
);
3884 // unblock before redrawing
3887 GetStatisticsString();
3891 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3893 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
3898 CTGitPath
*entry
=(CTGitPath
*)GetItemData(pGetInfoTip
->iItem
);
3901 if (pGetInfoTip
->cchTextMax
> entry
->GetGitPathString().GetLength() + g_Git
.m_CurrentDir
.GetLength())
3904 str
+= g_Git
.m_CurrentDir
;
3906 str
+= entry
->GetWinPathString();
3908 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, str
.GetBuffer(), str
.GetLength());
3912 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3914 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
3916 // Take the default processing unless we set this to something else below.
3917 *pResult
= CDRF_DODEFAULT
;
3919 // First thing - check the draw stage. If it's the control's prepaint
3920 // stage, then tell Windows we want messages for every item.
3922 switch (pLVCD
->nmcd
.dwDrawStage
)
3925 *pResult
= CDRF_NOTIFYITEMDRAW
;
3927 case CDDS_ITEMPREPAINT
:
3929 // This is the prepaint stage for an item. Here's where we set the
3930 // item's text color. Our return value will tell Windows to draw the
3931 // item itself, but it will use the new color we set here.
3933 // Tell Windows to paint the control itself.
3934 *pResult
= CDRF_DODEFAULT
;
3938 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
3940 if (m_arStatusArray
.size() > (DWORD_PTR
)pLVCD
->nmcd
.dwItemSpec
)
3943 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3944 CTGitPath
*entry
=(CTGitPath
*)GetItemData((int)pLVCD
->nmcd
.dwItemSpec
);
3950 // black : unversioned, normal
3953 // brown : missing, deleted, replaced
3954 // green : merged (or potential merges)
3955 // red : conflicts or sure conflicts
3956 if(entry
->m_Action
& CTGitPath::LOGACTIONS_GRAY
)
3958 crText
= RGB(128,128,128);
3961 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
3963 crText
= m_Colors
.GetColor(CColors::Conflict
);
3966 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_MODIFIED
))
3968 crText
= m_Colors
.GetColor(CColors::Modified
);
3971 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
3973 crText
= m_Colors
.GetColor(CColors::Added
);
3975 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3977 crText
= m_Colors
.GetColor(CColors::DeletedNode
);
3979 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
3981 crText
= m_Colors
.GetColor(CColors::RenamedNode
);
3983 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_MERGED
)
3985 crText
= m_Colors
.GetColor(CColors::Merged
);
3989 crText
= GetSysColor(COLOR_WINDOWTEXT
);
3991 // Store the color back in the NMLVCUSTOMDRAW struct.
3992 pLVCD
->clrText
= crText
;
3999 BOOL
CGitStatusListCtrl::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
4002 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
4005 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
4007 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
4009 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_WAIT
));
4014 void CGitStatusListCtrl::RemoveListEntry(int index
)
4017 Locker
lock(m_critSec
);
4020 m_arStatusArray
.erase(m_arStatusArray
.begin()+index
);
4023 delete m_arStatusArray
[m_arListArray
[index
]];
4024 m_arStatusArray
.erase(m_arStatusArray
.begin()+m_arListArray
[index
]);
4025 m_arListArray
.erase(m_arListArray
.begin()+index
);
4026 for (int i
=index
; i
< (int)m_arListArray
.size(); ++i
)
4033 ///< Set a checkbox on an entry in the listbox
4034 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
4035 void CGitStatusListCtrl::SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
)
4037 pEntry
->m_Checked
= bCheck
;
4038 SetCheck(listboxIndex
, bCheck
);
4042 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry
* parentEntry
, bool bCheck
)
4045 int nListItems
= GetItemCount();
4046 for (int j
=0; j
< nListItems
; ++j
)
4048 FileEntry
* childEntry
= GetListEntry(j
);
4049 ASSERT(childEntry
!= NULL
);
4050 if (childEntry
== NULL
|| childEntry
== parentEntry
)
4052 if (childEntry
->checked
!= bCheck
)
4054 if (parentEntry
->path
.IsAncestorOf(childEntry
->path
))
4056 SetEntryCheck(childEntry
,j
,bCheck
);
4072 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList
& pathList
)
4076 int nListItems
= GetItemCount();
4077 for (int i
=0; i
< nListItems
; i
++)
4079 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
4080 ASSERT(entry
!= NULL
);
4081 if (entry
->m_Checked
)
4083 pathList
.AddPath(*entry
);
4086 pathList
.SortByPathname();
4091 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
4092 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool /*bNoIgnored*/)
4096 POSITION pos
= GetFirstSelectedItemPosition();
4098 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4100 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
4101 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
4103 pathList
.AddPath(*entry
);
4107 UINT
CGitStatusListCtrl::OnGetDlgCode()
4109 // we want to process the return key and not have that one
4110 // routed to the default pushbutton
4111 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS
;
4114 void CGitStatusListCtrl::OnNMReturn(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
4119 POSITION pos
= GetFirstSelectedItemPosition();
4122 int index
= GetNextSelectedItem(pos
);
4123 CTGitPath
*file
=(CTGitPath
*)GetItemData(index
);
4124 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
)
4126 OpenFile(file
, OPEN
);
4135 void CGitStatusListCtrl::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
4137 // Since we catch all keystrokes (to have the enter key processed here instead
4138 // of routed to the default pushbutton) we have to make sure that other
4139 // keys like Tab and Esc still do what they're supposed to do
4140 // Tab = change focus to next/previous control
4141 // Esc = quit the dialog
4146 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL
, GetKeyState(VK_SHIFT
)&0x8000, 0);
4152 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE
, 0, 0);
4157 CListCtrl::OnKeyDown(nChar
, nRepCnt
, nFlags
);
4160 void CGitStatusListCtrl::PreSubclassWindow()
4162 CListCtrl::PreSubclassWindow();
4163 EnableToolTips(TRUE
);
4164 SetWindowTheme(GetSafeHwnd(), L
"Explorer", NULL
);
4167 INT_PTR
CGitStatusListCtrl::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4171 row
= CellRectFromPoint(point
, &cellrect
, &col
);
4178 pTI
->uId
= (UINT
)((row
<<10)+(col
&0x3ff)+1);
4179 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4181 pTI
->rect
= cellrect
;
4186 int CGitStatusListCtrl::CellRectFromPoint(CPoint
& point
, RECT
*cellrect
, int *col
) const
4190 // Make sure that the ListView is in LVS_REPORT
4191 if ((GetWindowLong(m_hWnd
, GWL_STYLE
) & LVS_TYPEMASK
) != LVS_REPORT
)
4194 // Get the top and bottom row visible
4195 int row
= GetTopIndex();
4196 int bottom
= row
+ GetCountPerPage();
4197 if (bottom
> GetItemCount())
4198 bottom
= GetItemCount();
4200 // Get the number of columns
4201 CHeaderCtrl
* pHeader
= (CHeaderCtrl
*)GetDlgItem(0);
4202 int nColumnCount
= pHeader
->GetItemCount();
4204 // Loop through the visible rows
4205 for ( ;row
<=bottom
;row
++)
4207 // Get bounding rect of item and check whether point falls in it.
4209 GetItemRect(row
, &rect
, LVIR_BOUNDS
);
4210 if (rect
.PtInRect(point
))
4212 // Now find the column
4213 for (colnum
= 0; colnum
< nColumnCount
; colnum
++)
4215 int colwidth
= GetColumnWidth(colnum
);
4216 if (point
.x
>= rect
.left
&& point
.x
<= (rect
.left
+ colwidth
))
4219 GetClientRect(&rectClient
);
4222 rect
.right
= rect
.left
+ colwidth
;
4224 // Make sure that the right extent does not exceed
4226 if (rect
.right
> rectClient
.right
)
4227 rect
.right
= rectClient
.right
;
4231 rect
.left
+= colwidth
;
4238 BOOL
CGitStatusListCtrl::OnToolTipText(UINT
/*id*/, NMHDR
* /*pNMHDR*/, LRESULT
* /*pResult*/)
4241 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4243 UINT_PTR nID
= pNMHDR
->idFrom
;
4248 UINT_PTR row
= ((nID
-1) >> 10) & 0x3fffff;
4249 UINT_PTR col
= (nID
-1) & 0x3ff;
4252 return FALSE
; // no custom tooltip for the path, we use the infotip there!
4254 // get the internal column from the visible columns
4255 int internalcol
= 0;
4256 UINT_PTR currentcol
= 0;
4257 for (; (currentcol
!= col
)
4258 && (internalcol
< m_ColumnManager
.GetColumnCount()-1)
4261 if (m_ColumnManager
.IsVisible (internalcol
))
4265 AFX_MODULE_THREAD_STATE
* pModuleThreadState
= AfxGetModuleThreadState();
4266 CToolTipCtrl
* pToolTip
= pModuleThreadState
->m_pToolTip
;
4267 pToolTip
->SendMessage(TTM_SETMAXTIPWIDTH
, 0, 300);
4270 if ((internalcol
== 2)||(internalcol
== 4))
4272 FileEntry
*fentry
= GetListEntry(row
);
4278 url
.Format(IDS_STATUSLIST_COPYFROM
, (LPCTSTR
)CPathUtils::PathUnescape(fentry
->copyfrom_url
), (LONG
)fentry
->copyfrom_rev
);
4279 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)url
, 80);
4282 if (fentry
->switched
)
4285 url
.Format(IDS_STATUSLIST_SWITCHEDTO
, (LPCTSTR
)CPathUtils::PathUnescape(fentry
->url
));
4286 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)url
, 80);
4289 if (fentry
->keeplocal
)
4291 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_KEEPLOCAL
)), 80);
4300 void CGitStatusListCtrl::OnPaint()
4303 if ((m_bBusy
)||(m_bEmpty
))
4308 if (m_sBusy
.IsEmpty())
4309 str
.LoadString(IDS_STATUSLIST_BUSYMSG
);
4315 if (m_sEmpty
.IsEmpty())
4316 str
.LoadString(IDS_STATUSLIST_EMPTYMSG
);
4320 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
4322 if (IsWindowEnabled())
4323 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
4325 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
4330 pHC
= GetHeaderCtrl();
4334 pHC
->GetItemRect(0, &rcH
);
4335 rc
.top
+= rcH
.bottom
;
4339 CMyMemDC
memDC(pDC
, &rc
);
4341 memDC
.SetTextColor(clrText
);
4342 memDC
.SetBkColor(clrTextBk
);
4343 memDC
.FillSolidRect(rc
, clrTextBk
);
4345 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
4346 memDC
.DrawText(str
, rc
, DT_CENTER
| DT_VCENTER
|
4347 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
4348 memDC
.SelectObject(oldfont
);
4354 // prevent users from extending our hidden (size 0) columns
4355 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4357 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
4360 // prevent any function from extending our hidden (size 0) columns
4361 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4363 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
4367 void CGitStatusListCtrl::OnDestroy()
4369 SaveColumnWidths(true);
4370 CListCtrl::OnDestroy();
4373 void CGitStatusListCtrl::OnBeginDrag(NMHDR
* /*pNMHDR*/, LRESULT
* pResult
)
4376 Locker
lock(m_critSec
);
4377 CDropFiles dropFiles
; // class for creating DROPFILES struct
4380 POSITION pos
= GetFirstSelectedItemPosition();
4381 while ( (index
= GetNextSelectedItem(pos
)) >= 0 )
4383 FileEntry
* fentry
= m_arStatusArray
[m_arListArray
[index
]];
4384 CTGitPath path
= fentry
->GetPath();
4385 dropFiles
.AddFile( path
.GetWinPathString() );
4388 if ( dropFiles
.GetCount()>0 )
4391 dropFiles
.CreateStructure();
4398 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry
/* = false */)
4400 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
4401 for (int col
= 0; col
<= maxcol
; col
++)
4402 if (m_ColumnManager
.IsVisible (col
))
4403 m_ColumnManager
.ColumnResized (col
);
4405 if (bSaveToRegistry
)
4406 m_ColumnManager
.WriteSettings();
4409 bool CGitStatusListCtrl::EnableFileDrop()
4411 m_bFileDropsEnabled
= true;
4415 bool CGitStatusListCtrl::HasPath(const CTGitPath
& path
)
4417 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
4419 if (m_arStatusArray
[i
]->IsEquivalentTo(path
))
4426 BOOL
CGitStatusListCtrl::PreTranslateMessage(MSG
* pMsg
)
4428 if (pMsg
->message
== WM_KEYDOWN
)
4430 switch (pMsg
->wParam
)
4434 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
4436 // select all entries
4437 for (int i
=0; i
<GetItemCount(); ++i
)
4439 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
4448 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
4450 // copy all selected paths to the clipboard
4451 if (GetAsyncKeyState(VK_SHIFT
)&0x8000)
4452 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS
);
4454 CopySelectedEntriesToClipboard(0);
4462 return CListCtrl::PreTranslateMessage(pMsg
);
4465 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols
)
4468 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
4469 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
4470 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4475 if (GetSelectedCount() == 0)
4478 // first add the column titles as the first line
4479 // We needn't head when only path copy
4480 //temp.LoadString(IDS_STATUSLIST_COLFILE);
4481 //sClipboard = temp;
4483 DWORD selection
= 0;
4484 for (int i
= 0, count
= m_ColumnManager
.GetColumnCount(); i
< count
; ++i
)
4485 if ( ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
4486 || ((dwCols
!= 1) && (i
< 32) && ((dwCols
& (1 << i
)) != 0)))
4488 sClipboard
+= _T("\t") + m_ColumnManager
.GetName(i
);
4491 selection
+= 1 << i
;
4495 sClipboard
+= _T("\r\n");
4497 POSITION pos
= GetFirstSelectedItemPosition();
4499 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4501 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
4505 sClipboard
+= entry
->GetWinPathString();
4506 if (selection
& GITSLC_COLFILENAME
)
4508 sClipboard
+= _T("\t")+entry
->GetFileOrDirectoryName();
4510 if (selection
& GITSLC_COLEXT
)
4512 sClipboard
+= _T("\t")+entry
->GetFileExtension();
4515 if (selection
& GITSLC_COLSTATUS
)
4518 if (entry
->isNested
)
4520 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4524 GitStatus::GetStatusString(hResourceHandle
, entry
->status
, buf
, _countof(buf
), (WORD
)langID
);
4525 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4526 _tcscat_s(buf
, 100, _T(" (+)"));
4527 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4528 _tcscat_s(buf
, 100, _T(" (s)"));
4529 if ((entry
->status
== entry
->propstatus
)&&
4530 (entry
->status
!= git_wc_status_normal
)&&
4531 (entry
->status
!= git_wc_status_unversioned
)&&
4532 (!GitStatus::IsImportant(entry
->textstatus
)))
4533 _tcscat_s(buf
, 100, ponly
);
4537 sClipboard
+= _T("\t")+entry
->GetActionName();
4540 if (selection
& SVNSLC_COLTEXTSTATUS
)
4543 if (entry
->isNested
)
4545 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4549 GitStatus::GetStatusString(hResourceHandle
, entry
->textstatus
, buf
, _countof(buf
), (WORD
)langID
);
4550 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4551 _tcscat_s(buf
, 100, _T(" (+)"));
4552 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4553 _tcscat_s(buf
, 100, _T(" (s)"));
4556 sClipboard
+= _T("\t")+temp
;
4560 if (selection
& SVNSLC_COLREMOTESTATUS
)
4562 if (entry
->isNested
)
4564 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4568 GitStatus::GetStatusString(hResourceHandle
, entry
->remotestatus
, buf
, _countof(buf
), (WORD
)langID
);
4569 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4570 _tcscat_s(buf
, 100, _T(" (+)"));
4571 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4572 _tcscat_s(buf
, 100, _T(" (s)"));
4573 if ((entry
->remotestatus
== entry
->remotepropstatus
)&&
4574 (entry
->remotestatus
!= git_wc_status_none
)&&
4575 (entry
->remotestatus
!= git_wc_status_normal
)&&
4576 (entry
->remotestatus
!= git_wc_status_unversioned
)&&
4577 (!SVNStatus::IsImportant(entry
->remotetextstatus
)))
4578 _tcscat_s(buf
, 100, ponly
);
4581 sClipboard
+= _T("\t")+temp
;
4583 if (selection
& GitSLC_COLPROPSTATUS
)
4585 if (entry
->isNested
)
4591 GitStatus::GetStatusString(hResourceHandle
, entry
->propstatus
, buf
, _countof(buf
), (WORD
)langID
);
4592 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4593 _tcscat_s(buf
, 100, _T(" (+)"));
4594 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4595 _tcscat_s(buf
, 100, _T(" (s)"));
4598 sClipboard
+= _T("\t")+temp
;
4600 if (selection
& SVNSLC_COLREMOTETEXT
)
4602 if (entry
->isNested
)
4608 GitStatus::GetStatusString(hResourceHandle
, entry
->remotetextstatus
, buf
, _countof(buf
), (WORD
)langID
);
4611 sClipboard
+= _T("\t")+temp
;
4613 if (selection
& SVNSLC_COLREMOTEPROP
)
4615 // SVNSLC_COLREMOTEPROP
4616 if (entry
->isNested
)
4622 GitStatus::GetStatusString(hResourceHandle
, entry
->remotepropstatus
, buf
, _countof(buf
), (WORD
)langID
);
4625 sClipboard
+= _T("\t")+temp
;
4627 if (selection
& SVNSLC_COLURL
)
4628 sClipboard
+= _T("\t")+entry
->url
;
4629 if (selection
& SVNSLC_COLLOCK
)
4631 if (!m_HeadRev
.IsHead())
4633 // we have contacted the repository
4636 // wc repository text
4640 // UID1 "" lock has been broken
4641 // UID1 UID2 lock has been stolen
4642 if (entry
->lock_token
.IsEmpty() || (entry
->lock_token
.Compare(entry
->lock_remotetoken
)==0))
4644 if (entry
->lock_owner
.IsEmpty())
4645 temp
= entry
->lock_remoteowner
;
4647 temp
= entry
->lock_owner
;
4649 else if (entry
->lock_remotetoken
.IsEmpty())
4652 temp
.LoadString(IDS_STATUSLIST_LOCKBROKEN
);
4657 temp
.Format(IDS_STATUSLIST_LOCKSTOLEN
, (LPCTSTR
)entry
->lock_remoteowner
);
4661 temp
= entry
->lock_owner
;
4662 sClipboard
+= _T("\t")+temp
;
4664 if (selection
& SVNSLC_COLLOCKCOMMENT
)
4665 sClipboard
+= _T("\t")+entry
->lock_comment
;
4666 if (selection
& SVNSLC_COLAUTHOR
)
4667 sClipboard
+= _T("\t")+entry
->last_commit_author
;
4668 if (selection
& SVNSLC_COLREVISION
)
4670 temp
.Format(_T("%ld"), entry
->last_commit_rev
);
4671 if (entry
->last_commit_rev
== 0)
4673 sClipboard
+= _T("\t")+temp
;
4675 if (selection
& SVNSLC_COLREMOTEREVISION
)
4677 temp
.Format(_T("%ld"), entry
->remoterev
);
4678 if (entry
->remoterev
== 0)
4680 sClipboard
+= _T("\t")+temp
;
4683 if (selection
& SVNSLC_COLDATE
)
4685 TCHAR datebuf
[SVN_DATE_BUFFER
];
4686 apr_time_t date
= entry
->last_commit_date
;
4687 SVN::formatDate(datebuf
, date
, true);
4692 sClipboard
+= _T("\t")+temp
;
4694 if (selection
& SVNSLC_COLCOPYFROM
)
4696 if (m_sURL
.Compare(entry
->copyfrom_url
.Left(m_sURL
.GetLength()))==0)
4697 temp
= entry
->copyfrom_url
.Mid(m_sURL
.GetLength());
4699 temp
= entry
->copyfrom_url
;
4700 sClipboard
+= _T("\t")+temp
;
4703 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
4707 if ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
4710 = entry
->present_props
[m_ColumnManager
.GetName(i
)];
4711 sClipboard
+= _T("\t") + value
;
4715 if (selection
& GITSLC_COLADD
)
4717 sClipboard
+= _T("\t")+entry
->m_StatAdd
;
4719 if (selection
& GITSLC_COLDEL
)
4721 sClipboard
+= _T("\t")+entry
->m_StatDel
;
4724 sClipboard
+= _T("\r\n");
4727 return CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
4733 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
4736 std::set
<CString
> changelists
;
4737 POSITION pos
= GetFirstSelectedItemPosition();
4739 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4741 FileEntry
* entry
= GetListEntry(index
);
4742 if (!entry
->changelist
.IsEmpty())
4743 changelists
.insert(entry
->changelist
);
4745 return changelists
.size();
4750 bool CGitStatusListCtrl::PrepareGroups(bool bForce
/* = false */)
4753 bool bHasGroups
=false;
4756 for(int i
=0;i
< this->m_arStatusArray
.size(); i
++)
4758 int ParentNo
= m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
4760 max
=m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
4763 if ( this->m_UnRevFileList
.GetCount()>0 ||
4764 this->m_IgnoreFileList
.GetCount()>0 ||
4771 EnableGroupView(bHasGroups
);
4773 TCHAR groupname
[1024];
4779 grp
.cbSize
= sizeof(LVGROUP
);
4780 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4783 //if(m_UnRevFileList.GetCount()>0)
4786 grp
.pszHeader
= _T("Merged Files");
4787 grp
.iGroupId
= MERGE_MASK
;
4788 grp
.uAlign
= LVGA_HEADER_LEFT
;
4789 InsertGroup(0, &grp
);
4791 for(int i
=0;i
<=max
;i
++)
4794 str
.Format(_T("Diff with parent %d"), i
+1);
4795 //_tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Not Versioned"), 1023);
4796 grp
.pszHeader
= str
.GetBuffer();
4798 grp
.uAlign
= LVGA_HEADER_LEFT
;
4799 InsertGroup(i
+1, &grp
);
4804 CString
sUnassignedName(_T("Modified File"));
4805 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
4806 grp
.pszHeader
= groupname
;
4807 grp
.iGroupId
= groupindex
;
4808 grp
.uAlign
= LVGA_HEADER_LEFT
;
4809 InsertGroup(groupindex
++, &grp
);
4813 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)_T("Not Versioned"), 1023);
4814 grp
.pszHeader
= groupname
;
4815 grp
.iGroupId
= groupindex
;
4816 grp
.uAlign
= LVGA_HEADER_LEFT
;
4817 InsertGroup(groupindex
++, &grp
);
4820 //if(m_IgnoreFileList.GetCount()>0)
4822 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)_T("Ignored"), 1023);
4823 grp
.pszHeader
= groupname
;
4824 grp
.iGroupId
= groupindex
;
4825 grp
.uAlign
= LVGA_HEADER_LEFT
;
4826 InsertGroup(groupindex
++, &grp
);
4832 m_bHasIgnoreGroup
= false;
4834 // now add the items which don't belong to a group
4836 grp
.cbSize
= sizeof(LVGROUP
);
4837 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4838 CString
sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET
));
4839 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
4840 grp
.pszHeader
= groupname
;
4841 grp
.iGroupId
= groupindex
;
4842 grp
.uAlign
= LVGA_HEADER_LEFT
;
4843 InsertGroup(groupindex
++, &grp
);
4845 for (std::map
<CString
,int>::iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
4847 if (it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)!=0)
4850 grp
.cbSize
= sizeof(LVGROUP
);
4851 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4852 _tcsncpy_s(groupname
, 1024, it
->first
, 1023);
4853 grp
.pszHeader
= groupname
;
4854 grp
.iGroupId
= groupindex
;
4855 grp
.uAlign
= LVGA_HEADER_LEFT
;
4856 it
->second
= InsertGroup(groupindex
++, &grp
);
4859 m_bHasIgnoreGroup
= true;
4862 if (m_bHasIgnoreGroup
)
4864 // and now add the group 'ignore-on-commit'
4865 std::map
<CString
,int>::iterator it
= m_changelists
.find(SVNSLC_IGNORECHANGELIST
);
4866 if (it
!= m_changelists
.end())
4868 grp
.cbSize
= sizeof(LVGROUP
);
4869 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4870 _tcsncpy_s(groupname
, 1024, SVNSLC_IGNORECHANGELIST
, 1023);
4871 grp
.pszHeader
= groupname
;
4872 grp
.iGroupId
= groupindex
;
4873 grp
.uAlign
= LVGA_HEADER_LEFT
;
4874 it
->second
= InsertGroup(groupindex
, &grp
);
4881 void CGitStatusListCtrl::NotifyCheck()
4883 CWnd
* pParent
= GetParent();
4884 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
4886 pParent
->SendMessage(GITSLNM_CHECKCHANGED
, m_nSelected
);
4890 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash
,CTGitPathList
*list
)
4894 m_CurrentVersion
=hash
;
4900 count
= list
->GetCount();
4902 CString head
= _T("HEAD");
4904 head
= _T("HEAD~1");
4906 if(hash
== GIT_REV_ZERO
)
4908 for(int i
=0;i
<count
;i
++)
4913 if(!g_Git
.IsInitRepos())
4915 // also list staged files which will be in the commit
4916 cmd
=(_T("git.exe diff-index --cached --raw ") + head
+ _T(" --numstat -C -M -z"));
4917 g_Git
.Run(cmd
, &cmdout
);
4920 cmd
=(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z"));
4922 cmd
.Format(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z -- \"%s\""),(*list
)[i
].GetGitPathString());
4925 if(g_Git
.Run(cmd
, &cmdout
, &cmdErr
))
4927 int last
= cmdErr
.RevertFind(0,-1);
4931 g_Git
.StringAppend(&str
, &cmdErr
[last
+1], CP_ACP
, cmdErr
.size() - last
-1);
4932 CMessageBox::Show(NULL
,str
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
4937 CString strout
, err
;
4938 if (g_Git
.Run(_T("git.exe rev-parse --revs-only ") + head
, &strout
, &err
, CP_UTF8
))
4940 CMessageBox::Show(NULL
, strout
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
);
4943 if(strout
.IsEmpty() && err
.IsEmpty())
4944 break; //this is initial repository, there are no any history
4946 CMessageBox::Show(NULL
, strout
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
);
4951 out
.append(cmdout
, 0);
4953 else // Init Repository
4955 //We will list all added file for init repository because commit will comit these
4957 cmd
=_T("git.exe ls-files -s -t -z");
4959 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
4961 g_Git
.Run(cmd
, &cmdout
);
4963 out
.append(cmdout
,0);
4967 if(g_Git
.IsInitRepos())
4969 m_StatusFileList
.ParserFromLsFile(out
);
4970 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
4971 ((CTGitPath
&)(m_StatusFileList
[i
])).m_Action
=CTGitPath::LOGACTIONS_ADDED
;
4974 this->m_StatusFileList
.ParserFromLog(out
);
4976 //handle delete conflict case, when remote : modified, local : deleted.
4977 for(int i
=0;i
<count
;i
++)
4983 cmd
=_T("git.exe ls-files -u -t -z");
4985 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list
)[i
].GetGitPathString());
4987 g_Git
.Run(cmd
, &cmdout
);
4989 CTGitPathList conflictlist
;
4990 conflictlist
.ParserFromLog(cmdout
);
4991 for(int i
=0;i
<conflictlist
.GetCount();i
++)
4993 CTGitPath
*p
=m_StatusFileList
.LookForGitPath(conflictlist
[i
].GetGitPathString());
4995 p
->m_Action
|=CTGitPath::LOGACTIONS_UNMERGED
;
4997 m_StatusFileList
.AddPath(conflictlist
[i
]);
5001 // handle source files of file renames/moves (issue #860)
5002 // if a file gets renamed and the new file "git add"ed, diff-index doesn't list the source file anymore
5003 for(int i
= 0; i
< count
; i
++)
5009 cmd
= _T("git.exe ls-files -d -z");
5011 cmd
.Format(_T("git.exe ls-files -d -z -- \"%s\""),(*list
)[i
].GetGitPathString());
5013 g_Git
.Run(cmd
, &cmdout
);
5015 CTGitPathList deletelist
;
5016 deletelist
.ParserFromLog(cmdout
, true);
5017 for(int i
= 0; i
< deletelist
.GetCount(); i
++)
5019 CTGitPath
*p
= m_StatusFileList
.LookForGitPath(deletelist
[i
].GetGitPathString());
5021 m_StatusFileList
.AddPath(deletelist
[i
]);
5031 count
= list
->GetCount();
5033 for(int i
=0;i
<count
;i
++)
5038 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash
);
5040 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash
,(*list
)[i
].GetGitPathString());
5042 g_Git
.Run(cmd
, &cmdout
, NULL
);
5046 this->m_StatusFileList
.ParserFromLog(out
);
5050 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
5052 CTGitPath
* gitpatch
=(CTGitPath
*)&m_StatusFileList
[i
];
5053 gitpatch
->m_Checked
= TRUE
;
5054 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
5057 this->m_bBusy
=FALSE
;
5061 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList
&list
)
5063 m_arStatusArray
.clear();
5064 for(int i
=0;i
<list
.GetCount();i
++)
5066 CTGitPath
* gitpath
=(CTGitPath
*)&list
[i
];
5068 if(gitpath
->m_Action
& CTGitPath::LOGACTIONS_HIDE
)
5071 gitpath
->m_Checked
= TRUE
;
5072 m_arStatusArray
.push_back((CTGitPath
*)&list
[i
]);
5077 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
*List
)
5079 this->m_UnRevFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
,List
);
5080 for(int i
=0;i
<m_UnRevFileList
.GetCount();i
++)
5082 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
5083 gitpatch
->m_Checked
= FALSE
;
5084 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
5089 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList
*List
)
5091 this->m_IgnoreFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
|CTGitPath::LOGACTIONS_IGNORE
,List
);
5092 for(int i
=0;i
<m_IgnoreFileList
.GetCount();i
++)
5094 CTGitPath
* gitpatch
=(CTGitPath
*)&m_IgnoreFileList
[i
];
5095 gitpatch
->m_Checked
= FALSE
;
5096 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
5100 int CGitStatusListCtrl::UpdateFileList(int mask
,bool once
,CTGitPathList
*List
)
5102 if(mask
&CGitStatusListCtrl::FILELIST_MODIFY
)
5104 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_MODIFY
)))
5106 UpdateFileList(git_revnum_t(GIT_REV_ZERO
),List
);
5107 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_MODIFY
;
5110 if(mask
&CGitStatusListCtrl::FILELIST_UNVER
)
5112 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_UNVER
)))
5114 UpdateUnRevFileList(List
);
5115 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
5117 if(mask
&CGitStatusListCtrl::FILELIST_IGNORE
&& (once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_IGNORE
))))
5119 UpdateIgnoreFileList(List
);
5120 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
5126 void CGitStatusListCtrl::Clear()
5129 this->DeleteAllItems();
5130 this->m_arListArray
.clear();
5131 this->m_arStatusArray
.clear();
5132 this->m_changelists
.clear();
5134 //////////////////////////////////////////////////////////////////////////
5136 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
)
5138 if(pFmtEtc
->cfFormat
== CF_HDROP
&& medium
.tymed
== TYMED_HGLOBAL
)
5140 HDROP hDrop
= (HDROP
)GlobalLock(medium
.hGlobal
);
5143 TCHAR szFileName
[MAX_PATH
];
5145 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, NULL
, 0);
5148 clientpoint
.x
= pt
.x
;
5149 clientpoint
.y
= pt
.y
;
5150 ScreenToClient(m_hTargetWnd
, &clientpoint
);
5151 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
5153 CTSVNPathList changelistItems
;
5154 for(UINT i
= 0; i
< cFiles
; ++i
)
5156 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
5157 changelistItems
.AddPath(CTSVNPath(szFileName
));
5159 // find the changelist name
5160 CString sChangelist
;
5161 LONG_PTR nGroup
= m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
);
5162 for (std::map
<CString
, int>::iterator it
= m_pSVNStatusListCtrl
->m_changelists
.begin(); it
!= m_pSVNStatusListCtrl
->m_changelists
.end(); ++it
)
5163 if (it
->second
== nGroup
)
5164 sChangelist
= it
->first
;
5165 if (!sChangelist
.IsEmpty())
5168 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
5170 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
5172 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
5175 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
5178 e
->changelist
= sChangelist
;
5181 if (m_pSVNStatusListCtrl
->m_changelists
.find(e
->changelist
)!=m_pSVNStatusListCtrl
->m_changelists
.end())
5182 m_pSVNStatusListCtrl
->SetItemGroup(index
, m_pSVNStatusListCtrl
->m_changelists
[e
->changelist
]);
5184 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
5190 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5191 if (hParentWnd
!= NULL
)
5192 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
5198 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
5204 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
5206 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
5208 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
5211 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
5214 e
->changelist
= sChangelist
;
5215 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
5220 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5221 if (hParentWnd
!= NULL
)
5222 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
5228 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
5234 for(UINT i
= 0; i
< cFiles
; ++i
)
5236 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
5237 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5238 if (hParentWnd
!= NULL
)
5239 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)szFileName
);
5243 GlobalUnlock(medium
.hGlobal
);
5245 return true; //let base free the medium
5247 HRESULT STDMETHODCALLTYPE
CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
)
5249 CIDropTarget::DragOver(grfKeyState
, pt
, pdwEffect
);
5250 *pdwEffect
= DROPEFFECT_COPY
;
5251 if (m_pSVNStatusListCtrl
)
5254 clientpoint
.x
= pt
.x
;
5255 clientpoint
.y
= pt
.y
;
5256 ScreenToClient(m_hTargetWnd
, &clientpoint
);
5257 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
5259 *pdwEffect
= DROPEFFECT_MOVE
;
5261 else if ((!m_pSVNStatusListCtrl
->m_bFileDropsEnabled
)||(m_pSVNStatusListCtrl
->m_bOwnDrag
))
5263 *pdwEffect
= DROPEFFECT_NONE
;
5271 void CGitStatusListCtrl::FileSaveAs(CTGitPath
*path
)
5274 filename
.Format(_T("%s-%s%s"),path
->GetBaseFilename(),this->m_CurrentVersion
.Left(6),path
->GetFileExtension());
5275 CFileDialog
dlg(FALSE
,NULL
,
5277 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
5279 CString currentpath
;
5280 currentpath
=g_Git
.m_CurrentDir
+_T("\\");
5281 currentpath
+=path
->GetWinPathString();
5283 dlg
.m_ofn
.lpstrInitialDir
=currentpath
.GetBuffer();
5286 if(dlg
.DoModal()==IDOK
)
5288 filename
= dlg
.GetPathName();
5289 if(m_CurrentVersion
== GIT_REV_ZERO
)
5291 if(!CopyFile(g_Git
.m_CurrentDir
+_T("\\") + path
->GetWinPath(),filename
,false))
5293 LPVOID lpMsgBuf
=NULL
;
5294 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
5295 NULL
,GetLastError(),MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
5298 CMessageBox::Show(NULL
,(TCHAR
*)lpMsgBuf
,_T("TortoiseGit"),MB_OK
);
5299 LocalFree(lpMsgBuf
);
5306 if(g_Git
.GetOneFile(m_CurrentVersion
,*path
,filename
))
5308 out
.Format(_T("Fail checkout one file %s;%s"),m_CurrentVersion
, path
->GetWinPath());
5309 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5317 int CGitStatusListCtrl::RevertSelectedItemToVersion()
5319 if(this->m_CurrentVersion
.IsEmpty())
5321 if(this->m_CurrentVersion
== GIT_REV_ZERO
)
5324 POSITION pos
= GetFirstSelectedItemPosition();
5328 while ((index
= GetNextSelectedItem(pos
)) >= 0)
5330 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
5331 cmd
.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion
,fentry
->GetGitPathString());
5333 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
5335 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5340 out
.Format(_T("%d files revert to %s"),count
,m_CurrentVersion
.Left(6));
5341 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5345 void CGitStatusListCtrl::OpenFile(CTGitPath
*filepath
,int mode
)
5348 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
5350 file
= filepath
->GetWinPath();
5355 GetTempPath(temppath
);
5356 file
.Format(_T("%s%s_%s%s"),
5358 filepath
->GetBaseFilename(),
5359 m_CurrentVersion
.Left(6),
5360 filepath
->GetFileExtension());
5362 if(g_Git
.GetOneFile(m_CurrentVersion
, *filepath
, file
))
5364 out
.Format(_T("Fail checkout file %s to %s\n"), filepath
->GetGitPathString(), file
);
5365 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5370 if(mode
== ALTERNATIVEEDITOR
)
5372 CAppUtils::LaunchAlternativeEditor(file
);
5375 int ret
= HINSTANCE_ERROR
;
5379 ret
= (int)ShellExecute(this->m_hWnd
, NULL
,file
, NULL
, NULL
, SW_SHOW
);
5381 if (ret
> HINSTANCE_ERROR
)
5388 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
5390 CAppUtils::LaunchApplication(cmd
, NULL
, false);