1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "..\\TortoiseShell\resource.h"
23 #include "GitStatusListCtrl.h"
24 #include "MessageBox.h"
26 #include "UnicodeUtils.h"
28 #include "PathUtils.h"
30 #include "StringUtils.h"
31 #include "DirFileEnum.h"
32 #include "GitConfig.h"
33 //#include "SVNProperties.h"
37 //#include "SVNProgressDlg.h"
38 #include "SysImageList.h"
39 //#include "Svnstatuslistctrl.h"
42 #include "GitStatus.h"
43 //#include "SVNHelpers.h"
45 #include "ShellUpdater.h"
46 #include "GitAdminDir.h"
47 //#include "DropFiles.h"
50 //#include "EditPropertiesDlg.h"
51 //#include "CreateChangelistDlg.h"
53 #include "CommonResource.h"
56 const UINT
CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED
57 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
58 const UINT
CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH
59 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
60 const UINT
CGitStatusListCtrl::SVNSLNM_ADDFILE
61 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
62 const UINT
CGitStatusListCtrl::SVNSLNM_CHECKCHANGED
63 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
64 const UINT
CGitStatusListCtrl::SVNSLNM_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_bUnversionedRecurse(true)
107 , m_bShowIgnores(false)
108 , m_pDropTarget(NULL
)
109 , m_bIgnoreRemoveOnly(false)
110 , m_bCheckChildrenWithParent(false)
111 , m_bUnversionedLast(true)
112 , m_bHasChangeLists(false)
116 , m_bHasCheckboxes(false)
117 , m_bCheckIfGroupsExist(true)
118 , m_bFileDropsEnabled(false)
120 , m_dwDefaultColumns(0)
121 , m_ColumnManager(this)
122 , m_bAscending(false)
123 , m_nSortedColumn(-1)
124 , m_bHasExternalsFromDifferentRepos(false)
125 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE
))
129 m_bIsRevertTheirMy
= false;
130 this->m_nLineAdded
=this->m_nLineDeleted
=0;
133 CGitStatusListCtrl::~CGitStatusListCtrl()
135 // if (m_pDropTarget)
136 // delete m_pDropTarget;
140 void CGitStatusListCtrl::ClearStatusArray()
143 Locker
lock(m_critSec
);
144 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
146 delete m_arStatusArray
[i
];
148 m_arStatusArray
.clear();
152 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetListEntry(UINT_PTR index
)
155 if (index
>= (UINT_PTR
)m_arListArray
.size())
157 if (m_arListArray
[index
] >= m_arStatusArray
.size())
159 return m_arStatusArray
[m_arListArray
[index
]];
165 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetVisibleListEntry(const CTGitPath
& path
)
167 int itemCount
= GetItemCount();
168 for (int i
=0; i
< itemCount
; i
++)
170 FileEntry
* entry
= GetListEntry(i
);
171 if (entry
->GetPath().IsEquivalentTo(path
))
178 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetListEntry(const CTGitPath
& path
)
181 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
183 FileEntry
* entry
= m_arStatusArray
[i
];
184 if (entry
->GetPath().IsEquivalentTo(path
))
193 int CGitStatusListCtrl::GetIndex(const CTGitPath
& path
)
195 int itemCount
= GetItemCount();
196 for (int i
=0; i
< itemCount
; i
++)
198 FileEntry
* entry
= GetListEntry(i
);
199 if (entry
->GetPath().IsEquivalentTo(path
))
206 void CGitStatusListCtrl::Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
/* = GitSLC_POPALL */, bool bHasCheckboxes
/* = true */)
208 Locker
lock(m_critSec
);
210 m_dwDefaultColumns
= dwColumns
| 1;
211 m_dwContextMenus
= dwContextMenus
;
212 m_bHasCheckboxes
= bHasCheckboxes
;
214 // set the extended style of the listcontrol
215 // 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.
216 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
217 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
218 if (DWORD(regFullRowSelect
))
219 exStyle
|= LVS_EX_FULLROWSELECT
;
220 exStyle
|= (bHasCheckboxes
? LVS_EX_CHECKBOXES
: 0);
222 SetExtendedStyle(exStyle
);
225 theme
.SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
227 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
228 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
230 static UINT standardColumnNames
[SVNSLC_NUMCOLUMNS
]
231 = { IDS_STATUSLIST_COLFILE
232 , IDS_STATUSLIST_COLFILENAME
233 , IDS_STATUSLIST_COLEXT
234 , IDS_STATUSLIST_COLSTATUS
235 , IDS_STATUSLIST_COLADD
236 , IDS_STATUSLIST_COLDEL
239 m_ColumnManager
.SetNames(standardColumnNames
,SVNSLC_NUMCOLUMNS
);
240 m_ColumnManager
.ReadSettings (m_dwDefaultColumns
, 0, sColumnInfoContainer
, SVNSLC_NUMCOLUMNS
);
244 if (m_pDropTarget
== NULL
)
246 m_pDropTarget
= new CGitStatusListCtrlDropTarget(this);
247 RegisterDragDrop(m_hWnd
,m_pDropTarget
);
248 // create the supported formats:
250 ftetc
.dwAspect
= DVASPECT_CONTENT
;
252 ftetc
.tymed
= TYMED_HGLOBAL
;
253 ftetc
.cfFormat
=CF_HDROP
;
254 m_pDropTarget
->AddSuportedFormat(ftetc
);
260 m_bUnversionedRecurse
= !!((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE
));
263 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID
)
265 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
268 BOOL
CGitStatusListCtrl::GetStatus ( const CTGitPathList
* pathList
269 , bool bUpdate
/* = FALSE */
270 , bool bShowIgnores
/* = false */
272 , bool /*bShowUserProps*/ /* = false */)
274 Locker
lock(m_critSec
);
275 int mask
= CGitStatusListCtrl::FILELIST_MODIFY
;
277 mask
|= CGitStatusListCtrl::FILELIST_IGNORE
;
279 mask
|= CGitStatusListCtrl::FILELIST_UNVER
;
280 this->UpdateFileList(mask
,bUpdate
,(CTGitPathList
*)pathList
);
284 int refetchcounter
= 0;
287 // force the cursor to change
290 SetCursorPos(pt
.x
, pt
.y
);
292 m_mapFilenameToChecked
.clear();
293 //m_StatusUrlList.Clear();
294 bool bHasChangelists
= (m_changelists
.size()>1 || (m_changelists
.size()>0 && !m_bHasIgnoreGroup
));
295 m_changelists
.clear();
296 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
298 FileEntry
* entry
= m_arStatusArray
[i
];
299 if ( bHasChangelists
&& entry
->checked
)
301 // If change lists are present, remember all checked entries
302 CString path
= entry
->GetPath().GetGitPathString();
303 m_mapFilenameToChecked
[path
] = true;
305 if ( (entry
->status
==git_wc_status_unversioned
|| entry
->status
==git_wc_status_missing
) && entry
->checked
)
307 // The user manually selected an unversioned or missing file. We remember
308 // this so that the selection can be restored when refreshing.
309 CString path
= entry
->GetPath().GetGitPathString();
310 m_mapFilenameToChecked
[path
] = true;
312 else if ( entry
->status
> git_wc_status_normal
&& !entry
->checked
)
314 // The user manually deselected a versioned file. We remember
315 // this so that the deselection can be restored when refreshing.
316 CString path
= entry
->GetPath().GetGitPathString();
317 m_mapFilenameToChecked
[path
] = false;
321 // use a sorted path list to make sure we fetch the status of
322 // parent items first, *then* the child items (if any)
323 CTGitPathList sortedPathList
= pathList
;
324 sortedPathList
.SortByPathname();
329 m_bHasExternalsFromDifferentRepos
= FALSE
;
330 m_bHasExternals
= FALSE
;
331 m_bHasUnversionedItems
= FALSE
;
333 m_bHasChangeLists
= false;
334 m_bShowIgnores
= bShowIgnores
;
341 // first clear possible status data left from
342 // previous GetStatus() calls
345 m_StatusFileList
= sortedPathList
;
347 // Since Git_client_status() returns all files, even those in
348 // folders included with Git:externals we need to check if all
349 // files we get here belongs to the same repository.
350 // It is possible to commit changes in an external folder, as long
351 // as the folder belongs to the same repository (but another path),
352 // but it is not possible to commit all files if the externals are
353 // from a different repository.
355 // To check if all files belong to the same repository, we compare the
356 // UUID's - if they're identical then the files belong to the same
357 // repository and can be committed. But if they're different, then
358 // tell the user to commit all changes in the external folders
360 CStringA sUUID
; // holds the repo UUID
361 CTGitPathList arExtPaths
; // list of Git:external paths
367 m_nTargetCount
= sortedPathList
.GetCount();
369 GitStatus
status(m_pbCanceled
);
370 if(m_nTargetCount
> 1 && sortedPathList
.AreAllPathsFilesInOneDirectory())
372 // This is a special case, where we've been given a list of files
373 // all from one folder
374 // We handle them by setting a status filter, then requesting the Git status of
375 // all the files in the directory, filtering for the ones we're interested in
376 status
.SetFilter(sortedPathList
);
378 // if all selected entries are files, we don't do a recursive status
379 // fetching. But if only one is a directory, we have to recurse.
380 git_depth_t depth
= git_depth_files
;
381 // We have set a filter. If all selected items were files or we fetch
382 // the status not recursively, then we have to include
383 // ignored items too - the user has selected them
384 bool bShowIgnoresRight
= true;
385 for (int fcindex
=0; fcindex
<sortedPathList
.GetCount(); ++fcindex
)
387 if (sortedPathList
[fcindex
].IsDirectory())
389 depth
= git_depth_infinity
;
390 bShowIgnoresRight
= false;
394 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
.GetCommonDirectory(), bUpdate
, sUUID
, arExtPaths
, true, depth
, bShowIgnoresRight
))
401 for(int nTarget
= 0; nTarget
< m_nTargetCount
; nTarget
++)
403 // check whether the path we want the status for is already fetched due to status-fetching
405 // this check is only done for file paths, because folder paths could be included already
406 // but not recursively
407 if (sortedPathList
[nTarget
].IsDirectory() || GetListEntry(sortedPathList
[nTarget
]) == NULL
)
409 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
[nTarget
], bUpdate
, sUUID
,
410 arExtPaths
, false, git_depth_infinity
, bShowIgnores
))
418 // remove the 'helper' files of conflicted items from the list.
419 // otherwise they would appear as unversioned files.
420 for (INT_PTR cind
= 0; cind
< m_ConflictFileList
.GetCount(); ++cind
)
422 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
424 if (m_arStatusArray
[i
]->GetPath().IsEquivalentTo(m_ConflictFileList
[cind
]))
426 delete m_arStatusArray
[i
];
427 m_arStatusArray
.erase(m_arStatusArray
.begin()+i
);
433 } while(!BuildStatistics() && (refetchcounter
< 2) && (*m_pbCanceled
==false));
436 FetchUserProperties();
438 m_ColumnManager
.UpdateUserPropList (m_arStatusArray
);
443 SetCursorPos(pt
.x
, pt
.y
);
451 // Fetch all local properties for all elements in the status array
453 void CGitStatusListCtrl::FetchUserProperties()
458 for (size_t i
= 0, count
= m_arStatusArray
.size(); i
< count
; ++i
)
460 // local / temp pool to hold parameters and props for a single item
462 GitPool
localPool ((apr_pool_t
*)globalPool
);
464 // open working copy for this path
466 const char* path
= m_arStatusArray
[i
]->path
.GetGitApiPath (localPool
);
468 Git_wc_adm_access_t
*adm_access
= NULL
;
469 Git_error_t
* error
= Git_wc_adm_probe_open3 ( &adm_access
472 , FALSE
// no write lock
473 , 0 // lock just the directory/file itself
479 // get the props and add them to the status info
481 apr_hash_t
* props
= NULL
;
482 Git_error_t
* error
= Git_wc_prop_list ( &props
488 for ( apr_hash_index_t
*index
489 = apr_hash_first (localPool
, props
)
491 ; index
= apr_hash_next (index
))
493 // extract next entry from hash
495 const char* key
= NULL
;
497 const char** val
= NULL
;
499 apr_hash_this ( index
500 , reinterpret_cast<const void**>(&key
)
502 , reinterpret_cast<void**>(&val
));
504 // decode / dispatch it
506 CString name
= CUnicodeUtils::GetUnicode (key
);
507 CString value
= CUnicodeUtils::GetUnicode (*val
);
509 // store in property container (truncate it after ~100 chars)
511 m_arStatusArray
[i
]->present_props
[name
]
512 = value
.Left (GitSLC_MAXUSERPROPLENGTH
);
515 error
= Git_wc_adm_close2 (adm_access
, localPool
);
517 Git_error_clear (error
);
522 // Get the show-flags bitmap value which corresponds to a particular Git status
523 DWORD
CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status
)
527 case git_wc_status_none
:
528 case git_wc_status_unversioned
:
529 return SVNSLC_SHOWUNVERSIONED
;
530 case git_wc_status_ignored
:
532 return SVNSLC_SHOWDIRECTS
;
533 return SVNSLC_SHOWDIRECTS
|SVNSLC_SHOWIGNORED
;
534 case git_wc_status_incomplete
:
535 return SVNSLC_SHOWINCOMPLETE
;
536 case git_wc_status_normal
:
537 return SVNSLC_SHOWNORMAL
;
538 case git_wc_status_external
:
539 return SVNSLC_SHOWEXTERNAL
;
540 case git_wc_status_added
:
541 return SVNSLC_SHOWADDED
;
542 case git_wc_status_missing
:
543 return SVNSLC_SHOWMISSING
;
544 case git_wc_status_deleted
:
545 return SVNSLC_SHOWREMOVED
;
546 case git_wc_status_replaced
:
547 return SVNSLC_SHOWREPLACED
;
548 case git_wc_status_modified
:
549 return SVNSLC_SHOWMODIFIED
;
550 case git_wc_status_merged
:
551 return SVNSLC_SHOWMERGED
;
552 case git_wc_status_conflicted
:
553 return SVNSLC_SHOWCONFLICTED
;
554 case git_wc_status_obstructed
:
555 return SVNSLC_SHOWOBSTRUCTED
;
557 // we should NEVER get here!
564 void CGitStatusListCtrl::Show(DWORD dwShow
, DWORD dwCheck
/*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList
,bool UseStoredCheckStatus
)
566 CWinApp
* pApp
= AfxGetApp();
568 pApp
->DoWaitCursor(1);
570 Locker
lock(m_critSec
);
571 WORD langID
= (WORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
573 //SetItemCount(listIndex);
580 m_arStatusArray
.clear();
581 for(int i
=0;i
<this->m_StatusFileList
.GetCount();i
++)
583 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
586 for(int i
=0;i
<this->m_UnRevFileList
.GetCount();i
++)
588 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
591 for(int i
=0;i
<this->m_IgnoreFileList
.GetCount();i
++)
593 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
597 if( m_nSortedColumn
)
599 CSorter
predicate (&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
600 std::sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
604 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
606 //set default checkbox status
607 if(!UseStoredCheckStatus
)
608 if(((CTGitPath
*)m_arStatusArray
[i
])->m_Action
& dwCheck
)
609 ((CTGitPath
*)m_arStatusArray
[i
])->m_Checked
=true;
611 ((CTGitPath
*)m_arStatusArray
[i
])->m_Checked
=false;
613 if(((CTGitPath
*)m_arStatusArray
[i
])->m_Action
& dwShow
)
615 AddEntry((CTGitPath
*)m_arStatusArray
[i
],langID
,index
);
620 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
621 for (int col
= 0; col
<= maxcol
; col
++)
622 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
625 GetStatisticsString();
627 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
628 HDITEM HeaderItem
= {0};
629 HeaderItem
.mask
= HDI_FORMAT
;
630 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
632 pHeader
->GetItem(i
, &HeaderItem
);
633 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
634 pHeader
->SetItem(i
, &HeaderItem
);
638 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
639 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
640 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
646 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
647 EnsureVisible(nSelectedEntry
, false);
651 // Restore the item at the top of the list.
652 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
654 if ( !EnsureVisible(nTopIndex
+i
,false) )
662 pApp
->DoWaitCursor(-1);
668 this->BuildStatistics();
672 CWinApp
* pApp
= AfxGetApp();
674 pApp
->DoWaitCursor(1);
676 m_bShowFolders
= bShowFolders
;
678 int nTopIndex
= GetTopIndex();
679 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
680 int nSelectedEntry
= 0;
681 if (posSelectedEntry
)
682 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
688 m_arListArray
.clear();
690 m_arListArray
.reserve(m_arStatusArray
.size());
691 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
694 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
696 FileEntry
* entry
= m_arStatusArray
[i
];
697 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
699 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
701 if (entry
->IsFolder() && (!bShowFolders
))
702 continue; // don't show folders if they're not wanted.
705 git_wc_status_kind status
= GitStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
706 DWORD showFlags
= GetShowFlagsFromGitStatus(status
);
707 if (entry
->IsLocked())
708 showFlags
|= SVNSLC_SHOWLOCKS
;
710 showFlags
|= SVNSLC_SHOWSWITCHED
;
711 if (!entry
->changelist
.IsEmpty())
712 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
714 bool bAllowCheck
= ((entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
) != 0)
715 && (m_bCheckIfGroupsExist
|| (m_changelists
.size()==0 || (m_changelists
.size()==1 && m_bHasIgnoreGroup
))));
717 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
719 if (status
!= Git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& GitSLC_SHOWIGNORED
))
721 if ((!entry
->IsFolder()) && (status
== Git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
723 if (PathFileExists(entry
->GetPath().GetWinPath()))
725 m_arListArray
.push_back(i
);
726 if ((dwCheck
& SVNSLC_SHOWREMOVEDANDPRESENT
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
729 entry
->checked
= true;
731 AddEntry(entry
, langID
, listIndex
++);
734 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
736 m_arListArray
.push_back(i
);
737 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
740 entry
->checked
= true;
742 AddEntry(entry
, langID
, listIndex
++);
744 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
746 m_arListArray
.push_back(i
);
747 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
750 entry
->checked
= true;
752 AddEntry(entry
, langID
, listIndex
++);
758 SetItemCount(listIndex
);
760 m_ColumnManager
.UpdateRelevance (m_arStatusArray
, m_arListArray
);
762 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
763 for (int col
= 0; col
<= maxcol
; col
++)
764 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
767 GetStatisticsString();
769 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
770 HDITEM HeaderItem
= {0};
771 HeaderItem
.mask
= HDI_FORMAT
;
772 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
774 pHeader
->GetItem(i
, &HeaderItem
);
775 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
776 pHeader
->SetItem(i
, &HeaderItem
);
780 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
781 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
782 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
787 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
788 EnsureVisible(nSelectedEntry
, false);
792 // Restore the item at the top of the list.
793 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
795 if ( !EnsureVisible(nTopIndex
+i
,false) )
803 pApp
->DoWaitCursor(-1);
805 m_bEmpty
= (GetItemCount() == 0);
811 void CGitStatusListCtrl::Show(DWORD
/*dwShow*/, const CTGitPathList
& checkedList
, bool /*bShowFolders*/ /* = true */)
814 for(int i
=0;i
<checkedList
.GetCount();i
++)
815 this->AddEntry((CTGitPath
*)&checkedList
[i
],0,i
);
819 Locker
lock(m_critSec
);
820 WORD langID
= (WORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
822 CWinApp
* pApp
= AfxGetApp();
824 pApp
->DoWaitCursor(1);
826 m_bShowFolders
= bShowFolders
;
828 int nTopIndex
= GetTopIndex();
829 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
830 int nSelectedEntry
= 0;
831 if (posSelectedEntry
)
832 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
838 m_arListArray
.clear();
840 m_arListArray
.reserve(m_arStatusArray
.size());
841 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
844 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
846 FileEntry
* entry
= m_arStatusArray
[i
];
847 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
849 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
851 if (entry
->IsFolder() && (!bShowFolders
))
852 continue; // don't show folders if they're not wanted.
854 git_wc_status_kind status
= SVNStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
855 DWORD showFlags
= GetShowFlagsFromSVNStatus(status
);
856 if (entry
->IsLocked())
857 showFlags
|= SVNSLC_SHOWLOCKS
;
858 if (!entry
->changelist
.IsEmpty())
859 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
861 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
862 if (status
!= git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& SVNSLC_SHOWIGNORED
))
864 for (int npath
= 0; npath
< checkedList
.GetCount(); ++npath
)
866 if (entry
->GetPath().IsEquivalentTo(checkedList
[npath
]))
868 entry
->checked
= true;
872 if ((!entry
->IsFolder()) && (status
== git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
874 if (PathFileExists(entry
->GetPath().GetWinPath()))
876 m_arListArray
.push_back(i
);
877 AddEntry(entry
, langID
, listIndex
++);
880 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
882 m_arListArray
.push_back(i
);
883 AddEntry(entry
, langID
, listIndex
++);
885 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
887 m_arListArray
.push_back(i
);
888 AddEntry(entry
, langID
, listIndex
++);
890 else if (entry
->switched
)
892 m_arListArray
.push_back(i
);
893 AddEntry(entry
, langID
, listIndex
++);
899 SetItemCount(listIndex
);
901 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
902 for (int col
= 0; col
<= maxcol
; col
++)
903 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
906 GetStatisticsString();
908 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
909 HDITEM HeaderItem
= {0};
910 HeaderItem
.mask
= HDI_FORMAT
;
911 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
913 pHeader
->GetItem(i
, &HeaderItem
);
914 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
915 pHeader
->SetItem(i
, &HeaderItem
);
919 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
920 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
921 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
926 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
927 EnsureVisible(nSelectedEntry
, false);
931 // Restore the item at the top of the list.
932 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
934 if ( !EnsureVisible(nTopIndex
+i
,false) )
942 pApp
->DoWaitCursor(-1);
944 m_bEmpty
= (GetItemCount() == 0);
949 int CGitStatusListCtrl::GetColumnIndex(int mask
)
959 void CGitStatusListCtrl::AddEntry(CTGitPath
* GitPath
, WORD
/*langID*/, int listIndex
)
961 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
962 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
964 CString path
= GitPath
->GetGitPathString();
967 int index
= listIndex
;
969 CString entryname
= GitPath
->GetGitPathString();
971 if (GitPath
->IsDirectory())
972 icon_idx
= m_nIconFolder
;
975 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(*GitPath
);
979 rename
.Format(_T(" (from %s)"),GitPath
->GetGitOldPathString());
980 if(GitPath
->m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
983 InsertItem(index
, entryname
, icon_idx
);
985 this->SetItemData(index
, (DWORD_PTR
)GitPath
);
986 // SVNSLC_COLFILENAME
987 SetItemText(index
, nCol
++, GitPath
->GetFileOrDirectoryName());
989 SetItemText(index
, nCol
++, GitPath
->GetFileExtension());
991 SetItemText(index
, nCol
++, GitPath
->GetActionName());
993 SetItemText(index
, GetColumnIndex(SVNSLC_COLADD
),GitPath
->m_StatAdd
);
994 SetItemText(index
, GetColumnIndex(SVNSLC_COLDEL
),GitPath
->m_StatDel
);
997 SetCheck(index
, GitPath
->m_Checked
);
998 if (GitPath
->m_Checked
)
1002 if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_IGNORE
)
1003 SetItemGroup(index
, 2);
1004 else if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1005 SetItemGroup(index
,1);
1008 SetItemGroup(index
, GitPath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
));
1016 void CGitStatusListCtrl::AddEntry(FileEntry
* entry
, WORD langID
, int listIndex
)
1018 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
1019 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
1021 CString path
= entry
->GetPath().GetGitPathString();
1022 if ( m_mapFilenameToChecked
.size()!=0 && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end() )
1024 // The user manually de-/selected an item. We now restore this status
1026 entry
->checked
= m_mapFilenameToChecked
[path
];
1031 int index
= listIndex
;
1033 CString entryname
= entry
->GetDisplayName();
1035 if (entry
->isfolder
)
1036 icon_idx
= m_nIconFolder
;
1039 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(entry
->path
);
1042 InsertItem(index
, entryname
, icon_idx
);
1043 // SVNSLC_COLFILENAME
1044 SetItemText(index
, nCol
++, entry
->path
.GetFileOrDirectoryName());
1046 SetItemText(index
, nCol
++, entry
->path
.GetFileExtension());
1048 if (entry
->isNested
)
1050 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1051 SetItemText(index
, nCol
++, sTemp
);
1055 GitStatus::GetStatusString(hResourceHandle
, entry
->status
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
1056 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1057 _tcscat_s(buf
, 100, _T(" (+)"));
1058 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1059 _tcscat_s(buf
, 100, _T(" (s)"));
1061 if ((entry
->status
== entry
->propstatus
)&&
1062 (entry
->status
!= git_wc_status_normal
)&&
1063 (entry
->status
!= git_wc_status_unversioned
)&&
1064 (!GitStatus::IsImportant(entry
->textstatus
)))
1065 _tcscat_s(buf
, 100, ponly
);
1067 SetItemText(index
, nCol
++, buf
);
1069 // SVNSLC_COLREMOTESTATUS
1070 if (entry
->isNested
)
1072 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1073 SetItemText(index
, nCol
++, sTemp
);
1078 SVNStatus::GetStatusString(hResourceHandle
, entry
->remotestatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
1079 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1080 _tcscat_s(buf
, 100, _T(" (+)"));
1081 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1082 _tcscat_s(buf
, 100, _T(" (s)"));
1083 if ((entry
->remotestatus
== entry
->remotepropstatus
)&&
1084 (entry
->remotestatus
!= git_wc_status_none
)&&
1085 (entry
->remotestatus
!= git_wc_status_normal
)&&
1086 (entry
->remotestatus
!= git_wc_status_unversioned
)&&
1087 (!SVNStatus::IsImportant(entry
->remotetextstatus
)))
1088 _tcscat_s(buf
, 100, ponly
);
1090 SetItemText(index
, nCol
++, buf
);
1092 // SVNSLC_COLTEXTSTATUS
1093 if (entry
->isNested
)
1095 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1096 SetItemText(index
, nCol
++, sTemp
);
1101 SVNStatus::GetStatusString(hResourceHandle
, entry
->textstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
1102 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1103 _tcscat_s(buf
, 100, _T(" (+)"));
1104 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1105 _tcscat_s(buf
, 100, _T(" (s)"));
1107 SetItemText(index
, nCol
++, buf
);
1109 // SVNSLC_COLPROPSTATUS
1110 if (entry
->isNested
)
1112 SetItemText(index
, nCol
++, _T(""));
1117 SVNStatus::GetStatusString(hResourceHandle
, entry
->propstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
1118 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1119 _tcscat_s(buf
, 100, _T(" (+)"));
1120 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1121 _tcscat_s(buf
, 100, _T(" (s)"));
1123 SetItemText(index
, nCol
++, buf
);
1125 // SVNSLC_COLREMOTETEXT
1126 if (entry
->isNested
)
1128 SetItemText(index
, nCol
++, _T(""));
1133 SVNStatus::GetStatusString(hResourceHandle
, entry
->remotetextstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
1134 SetItemText(index
, nCol
++, buf
);
1137 // SVNSLC_COLREMOTEPROP
1138 if (entry
->isNested
)
1140 SetItemText(index
, nCol
++, _T(""));
1144 // SVNStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1145 SetItemText(index
, nCol
++, buf
);
1148 // SetItemText(index, nCol++, entry->url);
1151 if (!m_HeadRev
.IsHead())
1153 // we have contacted the repository
1156 // wc repository text
1160 // UID1 "" lock has been broken
1161 // UID1 UID2 lock has been stolen
1162 if (entry
->lock_token
.IsEmpty() || (entry
->lock_token
.Compare(entry
->lock_remotetoken
)==0))
1164 if (entry
->lock_owner
.IsEmpty())
1165 SetItemText(index
, nCol
++, entry
->lock_remoteowner
);
1167 SetItemText(index
, nCol
++, entry
->lock_owner
);
1169 else if (entry
->lock_remotetoken
.IsEmpty())
1172 CString
temp(MAKEINTRESOURCE(IDS_STATUSLIST_LOCKBROKEN
));
1173 SetItemText(index
, nCol
++, temp
);
1179 temp
.Format(IDS_STATUSLIST_LOCKSTOLEN
, (LPCTSTR
)entry
->lock_remoteowner
);
1180 SetItemText(index
, nCol
++, temp
);
1184 SetItemText(index
, nCol
++, entry
->lock_owner
);
1185 // SVNSLC_COLLOCKCOMMENT
1186 SetItemText(index
, nCol
++, entry
->lock_comment
);
1188 SetItemText(index
, nCol
++, entry
->last_commit_author
);
1189 // SVNSLC_COLREVISION
1191 temp
.Format(_T("%ld"), entry
->last_commit_rev
);
1192 if (entry
->last_commit_rev
> 0)
1193 SetItemText(index
, nCol
++, temp
);
1195 SetItemText(index
, nCol
++, _T(""));
1196 // SVNSLC_COLREMOTEREVISION
1197 temp
.Format(_T("%ld"), entry
->remoterev
);
1198 if (entry
->remoterev
> 0)
1199 SetItemText(index
, nCol
++, temp
);
1201 SetItemText(index
, nCol
++, _T(""));
1203 TCHAR datebuf
[SVN_DATE_BUFFER
];
1204 apr_time_t date
= entry
->last_commit_date
;
1205 SVN::formatDate(datebuf
, date
, true);
1207 SetItemText(index
, nCol
++, datebuf
);
1209 SetItemText(index
, nCol
++, _T(""));
1210 // SVNSLC_COLSVNNEEDSLOCK
1211 BOOL bFoundSVNNeedsLock
= entry
->present_props
.IsNeedsLockSet();
1212 CString strSVNNeedsLock
= (bFoundSVNNeedsLock
) ? _T("*") : _T("");
1213 SetItemText(index
, nCol
++, strSVNNeedsLock
);
1214 // SVNSLC_COLCOPYFROM
1215 if (m_sURL
.Compare(entry
->copyfrom_url
.Left(m_sURL
.GetLength()))==0)
1216 temp
= entry
->copyfrom_url
.Mid(m_sURL
.GetLength());
1218 temp
= entry
->copyfrom_url
;
1219 SetItemText(index
, nCol
++, temp
);
1220 // SVNSLC_COLMODIFICATIONDATE
1221 __int64 filetime
= entry
->GetPath().GetLastWriteTime();
1222 if ( (filetime
) && (entry
->status
!=git_wc_status_deleted
) )
1224 FILETIME
* f
= (FILETIME
*)(__int64
*)&filetime
;
1225 TCHAR datebuf
[SVN_DATE_BUFFER
];
1226 SVN::formatDate(datebuf
,*f
,true);
1227 SetItemText(index
, nCol
++, datebuf
);
1231 SetItemText(index
, nCol
++, _T(""));
1234 // user-defined properties
1235 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
1239 assert (i
== nCol
++);
1240 assert (m_ColumnManager
.IsUserProp (i
));
1242 CString name
= m_ColumnManager
.GetName(i
);
1243 if (entry
->present_props
.HasProperty (name
))
1245 const CString
& propVal
= entry
->present_props
[name
];
1246 if (propVal
.IsEmpty())
1247 SetItemText(index
, i
, m_sNoPropValueText
);
1249 SetItemText(index
, i
, propVal
);
1252 SetItemText(index
, i
, _T(""));
1255 SetCheck(index
, entry
->checked
);
1258 if (m_changelists
.find(entry
->changelist
) != m_changelists
.end())
1259 SetItemGroup(index
, m_changelists
[entry
->changelist
]);
1261 SetItemGroup(index
, 0);
1266 bool CGitStatusListCtrl::SetItemGroup(int item
, int groupindex
)
1268 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1273 i
.mask
= LVIF_GROUPID
;
1276 i
.iGroupId
= groupindex
;
1278 return !!SetItem(&i
);
1281 void CGitStatusListCtrl::Sort()
1283 Locker
lock(m_critSec
);
1285 CSorter
predicate (&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
1287 std::sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
1289 Show(m_dwShow
, 0, m_bShowFolders
,false,true);
1293 void CGitStatusListCtrl::OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1295 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1300 if (m_nSortedColumn
== phdr
->iItem
)
1301 m_bAscending
= !m_bAscending
;
1303 m_bAscending
= TRUE
;
1304 m_nSortedColumn
= phdr
->iItem
;
1305 m_mapFilenameToChecked
.clear();
1308 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
1309 HDITEM HeaderItem
= {0};
1310 HeaderItem
.mask
= HDI_FORMAT
;
1311 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
1313 pHeader
->GetItem(i
, &HeaderItem
);
1314 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
1315 pHeader
->SetItem(i
, &HeaderItem
);
1317 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
1318 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
1319 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
1321 // the checked state of the list control items must be restored
1323 for (int i
=0; i
<GetItemCount(); ++i
)
1325 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
1328 SetCheck(i
, entry
->m_Checked
);
1334 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1336 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1339 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1340 if ((m_bBlock
)&&(m_bBlockUI
))
1342 // if we're blocked, prevent changing of the check state
1343 if ((!ISCHECKED(pNMLV
->uOldState
) && ISCHECKED(pNMLV
->uNewState
))||
1344 (ISCHECKED(pNMLV
->uOldState
) && !ISCHECKED(pNMLV
->uNewState
)))
1349 BOOL
CGitStatusListCtrl::OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1351 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1353 CWnd
* pParent
= GetParent();
1354 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
1356 pParent
->SendMessage(SVNSLNM_ITEMCHANGED
, pNMLV
->iItem
);
1359 if ((pNMLV
->uNewState
==0)||(pNMLV
->uNewState
& LVIS_SELECTED
)||(pNMLV
->uNewState
& LVIS_FOCUSED
))
1365 bool bSelected
= !!(ListView_GetItemState(m_hWnd
, pNMLV
->iItem
, LVIS_SELECTED
) & LVIS_SELECTED
);
1366 int nListItems
= GetItemCount();
1369 // was the item checked?
1371 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1372 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1374 if (GetCheck(pNMLV
->iItem
))
1376 CheckEntry(pNMLV
->iItem
, nListItems
);
1379 POSITION pos
= GetFirstSelectedItemPosition();
1381 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1383 if (index
!= pNMLV
->iItem
)
1384 CheckEntry(index
, nListItems
);
1390 UncheckEntry(pNMLV
->iItem
, nListItems
);
1393 POSITION pos
= GetFirstSelectedItemPosition();
1395 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1397 if (index
!= pNMLV
->iItem
)
1398 UncheckEntry(index
, nListItems
);
1403 GetStatisticsString();
1410 void CGitStatusListCtrl::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1412 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
1417 void CGitStatusListCtrl::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1419 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
1424 void CGitStatusListCtrl::CheckEntry(int index
, int /*nListItems*/)
1426 Locker
lock(m_critSec
);
1427 //FileEntry * entry = GetListEntry(index);
1428 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1429 ASSERT(path
!= NULL
);
1432 SetCheck(index
, TRUE
);
1433 //entry = GetListEntry(index);
1434 // if an unversioned item was checked, then we need to check if
1435 // the parent folders are unversioned too. If the parent folders actually
1436 // are unversioned, then check those too.
1438 if (entry
->status
== git_wc_status_unversioned
)
1440 // we need to check the parent folder too
1441 const CTGitPath
& folderpath
= entry
->path
;
1442 for (int i
=0; i
< nListItems
; ++i
)
1444 FileEntry
* testEntry
= GetListEntry(i
);
1445 ASSERT(testEntry
!= NULL
);
1446 if (testEntry
== NULL
)
1448 if (!testEntry
->checked
)
1450 if (testEntry
->path
.IsAncestorOf(folderpath
) && (!testEntry
->path
.IsEquivalentTo(folderpath
)))
1452 SetEntryCheck(testEntry
,i
,true);
1458 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1459 if ( (entry
->status
== git_wc_status_deleted
) || (m_bCheckChildrenWithParent
) || (bShift
) )
1461 // if a deleted folder gets checked, we have to check all
1462 // children of that folder too.
1463 if (entry
->path
.IsDirectory())
1465 SetCheckOnAllDescendentsOf(entry
, true);
1468 // if a deleted file or folder gets checked, we have to
1469 // check all parents of this item too.
1470 for (int i
=0; i
<nListItems
; ++i
)
1472 FileEntry
* testEntry
= GetListEntry(i
);
1473 ASSERT(testEntry
!= NULL
);
1474 if (testEntry
== NULL
)
1476 if (!testEntry
->checked
)
1478 if (testEntry
->path
.IsAncestorOf(entry
->path
) && (!testEntry
->path
.IsEquivalentTo(entry
->path
)))
1480 if ((testEntry
->status
== git_wc_status_deleted
)||(m_bCheckChildrenWithParent
))
1482 SetEntryCheck(testEntry
,i
,true);
1484 // now we need to check all children of this parent folder
1485 SetCheckOnAllDescendentsOf(testEntry
, true);
1492 if ( !path
->m_Checked
)
1494 path
->m_Checked
= TRUE
;
1499 void CGitStatusListCtrl::UncheckEntry(int index
, int /*nListItems*/)
1501 Locker
lock(m_critSec
);
1502 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1503 ASSERT(path
!= NULL
);
1506 SetCheck(index
, FALSE
);
1507 //entry = GetListEntry(index);
1508 // item was unchecked
1510 if (entry
->path
.IsDirectory())
1512 // disable all files within an unselected folder, except when unchecking a folder with property changes
1513 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1514 if ( (entry
->status
!= git_wc_status_modified
) || (bShift
) )
1516 SetCheckOnAllDescendentsOf(entry
, false);
1519 else if (entry
->status
== git_wc_status_deleted
)
1521 // a "deleted" file was unchecked, so uncheck all parent folders
1522 // and all children of those parents
1523 for (int i
=0; i
<nListItems
; i
++)
1525 FileEntry
* testEntry
= GetListEntry(i
);
1526 ASSERT(testEntry
!= NULL
);
1527 if (testEntry
== NULL
)
1529 if (testEntry
->checked
)
1531 if (testEntry
->path
.IsAncestorOf(entry
->path
))
1533 if (testEntry
->status
== git_wc_status_deleted
)
1535 SetEntryCheck(testEntry
,i
,false);
1538 SetCheckOnAllDescendentsOf(testEntry
, false);
1545 if ( path
->m_Checked
)
1547 path
->m_Checked
= FALSE
;
1552 bool CGitStatusListCtrl::EntryPathCompareNoCase(const FileEntry
* pEntry1
, const FileEntry
* pEntry2
)
1554 return pEntry1
->path
< pEntry2
->path
;
1557 bool CGitStatusListCtrl::IsEntryVersioned(const FileEntry
* pEntry1
)
1559 return pEntry1
->status
!= git_wc_status_unversioned
;
1562 bool CGitStatusListCtrl::BuildStatistics()
1565 bool bRefetchStatus
= false;
1567 // now gather some statistics
1580 for (int i
=0; i
< (int)m_arStatusArray
.size(); ++i
)
1582 int status
=((CTGitPath
*)m_arStatusArray
[i
])->m_Action
;
1584 m_nLineAdded
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatAdd
);
1585 m_nLineDeleted
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatDel
);
1587 if(status
&(CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
1590 if(status
&CTGitPath::LOGACTIONS_DELETED
)
1593 if(status
&(CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_MODIFIED
))
1596 if(status
&CTGitPath::LOGACTIONS_UNMERGED
)
1599 if(status
&(CTGitPath::LOGACTIONS_IGNORE
|CTGitPath::LOGACTIONS_UNVER
))
1602 if(status
&(CTGitPath::LOGACTIONS_REPLACED
))
1605 if(((CTGitPath
*)m_arStatusArray
[i
])->m_Checked
)
1608 // } // switch (entry->status)
1610 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1611 return !bRefetchStatus
;
1617 int CGitStatusListCtrl::GetGroupFromPoint(POINT
* ppt
)
1619 // the point must be relative to the upper left corner of the control
1623 if (!IsGroupViewEnabled())
1632 while (((flags
& LVHT_BELOW
) == 0)&&(pt
.y
< rc
.bottom
))
1634 nItem
= HitTest(pt
, &flags
);
1635 if ((flags
& LVHT_ONITEM
)||(flags
& LVHT_EX_GROUP_HEADER
))
1637 // the first item below the point
1639 // check if the point is too much right (i.e. if the point
1640 // is farther to the right than the width of the item)
1642 GetItemRect(nItem
, &r
, LVIR_LABEL
);
1643 if (ppt
->x
> r
.right
)
1647 lv
.mask
= LVIF_GROUPID
;
1650 int groupID
= lv
.iGroupId
;
1651 // now we search upwards and check if the item above this one
1652 // belongs to another group. If it belongs to the same group,
1653 // we're not over a group header
1657 nItem
= HitTest(pt
, &flags
);
1658 if ((flags
& LVHT_ONITEM
)&&(nItem
>= 0))
1660 // the first item below the point
1662 lv
.mask
= LVIF_GROUPID
;
1665 if (lv
.iGroupId
!= groupID
)
1680 void CGitStatusListCtrl::OnContextMenuGroup(CWnd
* /*pWnd*/, CPoint point
)
1682 POINT clientpoint
= point
;
1683 ScreenToClient(&clientpoint
);
1684 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint
) >= 0))
1687 if (popup
.CreatePopupMenu())
1690 temp
.LoadString(IDS_STATUSLIST_CHECKGROUP
);
1691 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CHECKGROUP
, temp
);
1692 temp
.LoadString(IDS_STATUSLIST_UNCHECKGROUP
);
1693 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_UNCHECKGROUP
, temp
);
1694 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1695 bool bCheck
= false;
1698 case IDSVNLC_CHECKGROUP
:
1700 // fall through here
1701 case IDSVNLC_UNCHECKGROUP
:
1703 int group
= GetGroupFromPoint(&clientpoint
);
1704 // go through all items and check/uncheck those assigned to the group
1705 // but block the OnLvnItemChanged handler
1708 for (int i
=0; i
<GetItemCount(); ++i
)
1710 SecureZeroMemory(&lv
, sizeof(LVITEM
));
1711 lv
.mask
= LVIF_GROUPID
;
1715 if (lv
.iGroupId
== group
)
1717 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
1720 bool bOldCheck
= entry
->m_Checked
;
1721 SetEntryCheck(entry
, i
, bCheck
);
1722 if (bCheck
!= bOldCheck
)
1733 GetStatisticsString();
1743 void CGitStatusListCtrl::OnContextMenuList(CWnd
* pWnd
, CPoint point
)
1746 //WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1748 bool XPorLater
= false;
1749 OSVERSIONINFOEX inf
;
1750 SecureZeroMemory(&inf
, sizeof(OSVERSIONINFOEX
));
1751 inf
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
1752 GetVersionEx((OSVERSIONINFO
*)&inf
);
1753 WORD fullver
= MAKEWORD(inf
.dwMinorVersion
, inf
.dwMajorVersion
);
1754 if (fullver
>= 0x0501)
1756 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1757 CTGitPath
* filepath
;
1759 int selIndex
= GetSelectionMark();
1760 if ((point
.x
== -1) && (point
.y
== -1))
1763 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1764 ClientToScreen(&rect
);
1765 point
= rect
.CenterPoint();
1767 if ((GetSelectedCount() == 0)&&(XPorLater
)&&(m_bHasCheckboxes
))
1769 // nothing selected could mean the context menu is requested for
1771 OnContextMenuGroup(pWnd
, point
);
1773 else if (selIndex
>= 0)
1775 //FileEntry * entry = GetListEntry(selIndex);
1777 filepath
= (CTGitPath
* )GetItemData(selIndex
);
1779 ASSERT(filepath
!= NULL
);
1780 if (filepath
== NULL
)
1783 //const CTGitPath& filepath = entry->path;
1784 int wcStatus
= filepath
->m_Action
;
1785 // entry is selected, now show the popup menu
1786 Locker
lock(m_critSec
);
1788 CMenu changelistSubMenu
;
1789 CMenu ignoreSubMenu
;
1790 if (popup
.CreatePopupMenu())
1792 //Add Menu for verion controled file
1794 if (wcStatus
& CTGitPath::LOGACTIONS_UNMERGED
)
1796 if ((m_dwContextMenus
& SVNSLC_POPCONFLICT
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1798 popup
.AppendMenuIcon(IDSVNLC_EDITCONFLICT
, IDS_MENUCONFLICT
, IDI_CONFLICT
);
1800 if (m_dwContextMenus
& SVNSLC_POPRESOLVE
)
1802 popup
.AppendMenuIcon(IDSVNLC_RESOLVECONFLICT
, IDS_STATUSLIST_CONTEXT_RESOLVED
, IDI_RESOLVE
);
1804 if ((m_dwContextMenus
& SVNSLC_POPRESOLVE
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1806 popup
.AppendMenuIcon(IDSVNLC_RESOLVETHEIRS
, IDS_SVNPROGRESS_MENUUSETHEIRS
, IDI_RESOLVE
);
1807 popup
.AppendMenuIcon(IDSVNLC_RESOLVEMINE
, IDS_SVNPROGRESS_MENUUSEMINE
, IDI_RESOLVE
);
1809 if ((m_dwContextMenus
& SVNSLC_POPCONFLICT
)||(m_dwContextMenus
& SVNSLC_POPRESOLVE
))
1810 popup
.AppendMenu(MF_SEPARATOR
);
1813 if (GetSelectedCount() > 0)
1815 if (wcStatus
& CTGitPath::LOGACTIONS_UNVER
)
1816 if (m_dwContextMenus
& SVNSLC_POPADD
)
1818 //if ( entry->IsFolder() )
1820 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1824 popup
.AppendMenuIcon(IDSVNLC_ADD
, IDS_STATUSLIST_CONTEXT_ADD
, IDI_ADD
);
1829 if (!(wcStatus
&CTGitPath::LOGACTIONS_UNVER
))
1831 if ( (m_dwContextMenus
& SVNSLC_POPCOMPAREWITHBASE
) && GetSelectedCount()>0)
1833 if(filepath
->m_ParentNo
& MERGE_MASK
)
1834 popup
.AppendMenuIcon(IDSVNLC_COMPARE
, IDS_TREE_DIFF
, IDI_DIFF
);
1836 popup
.AppendMenuIcon(IDSVNLC_COMPARE
, IDS_LOG_COMPAREWITHBASE
, IDI_DIFF
);
1838 popup
.SetDefaultItem(IDSVNLC_COMPARE
, FALSE
);
1841 if ((m_dwContextMenus
& this->GetContextMenuBit(IDSVNLC_COMPAREWC
)) && GetSelectedCount()>0)
1843 if( (!m_CurrentVersion
.IsEmpty()) && m_CurrentVersion
!= GIT_REV_ZERO
)
1844 popup
.AppendMenuIcon(IDSVNLC_COMPAREWC
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1847 if (GetSelectedCount() == 1)
1849 bool bEntryAdded
= false;
1850 //if (entry->remotestatus <= git_wc_status_normal)
1852 // if (wcStatus > git_wc_status_normal)
1854 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
1856 if(!g_Git
.IsInitRepos() && (m_dwContextMenus
&SVNSLC_POPGNUDIFF
))
1858 popup
.AppendMenuIcon(IDSVNLC_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1866 //else if (wcStatus != git_wc_status_deleted)
1868 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
1870 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1871 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1872 // bEntryAdded = true;
1874 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
1876 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1877 // bEntryAdded = true;
1881 popup
.AppendMenu(MF_SEPARATOR
);
1883 //else if (GetSelectedCount() > 1)
1885 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1887 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1888 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1893 if( (!this->m_Rev1
.IsEmpty()) || (!this->m_Rev1
.IsEmpty()) )
1895 if(GetSelectedCount() == 1)
1897 if (m_dwContextMenus
& this->GetContextMenuBit(IDSVNLC_COMPARETWO
))
1899 popup
.AppendMenuIcon(IDSVNLC_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1900 popup
.SetDefaultItem(IDSVNLC_COMPARETWO
, FALSE
);
1902 if (m_dwContextMenus
& this->GetContextMenuBit(IDSVNLC_GNUDIFF2
))
1904 popup
.AppendMenuIcon(IDSVNLC_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1909 ///Select Multi item
1910 //if (GetSelectedCount() > 0)
1912 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
1914 // POSITION pos = GetFirstSelectedItemPosition();
1915 // int index = GetNextSelectedItem(pos);
1918 // FileEntry * entry = GetListEntry(index);
1919 // git_wc_status_kind status1 = git_wc_status_none;
1920 // git_wc_status_kind status2 = git_wc_status_none;
1922 // status1 = entry->status;
1923 // index = GetNextSelectedItem(pos);
1926 // entry = GetListEntry(index);
1928 // status2 = entry->status;
1929 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
1930 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
1932 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
1937 // if (wcStatus > git_wc_status_normal)
1939 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1941 // // reverting missing folders is not possible
1942 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1944 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1948 // if (entry->remotestatus > git_wc_status_normal)
1950 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1952 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1957 if ( (GetSelectedCount() >0 ) && (!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
)))
1959 if ((m_dwContextMenus
& SVNSLC_POPREVERT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1961 popup
.AppendMenuIcon(IDSVNLC_REVERT
, IDS_MENUREVERT
, IDI_REVERT
);
1964 if ((m_dwContextMenus
& GetContextMenuBit(IDSVNLC_REVERTTOREV
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1965 && this->m_CurrentVersion
!= GIT_REV_ZERO
)
1967 popup
.AppendMenuIcon(IDSVNLC_REVERTTOREV
, IDS_LOG_POPUP_REVERTTOREV
, IDI_REVERT
);
1971 if ((GetSelectedCount() == 1)&&(!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
))
1972 &&(!(wcStatus
& CTGitPath::LOGACTIONS_IGNORE
)))
1974 if (m_dwContextMenus
& SVNSLC_POPSHOWLOG
)
1976 popup
.AppendMenuIcon(IDSVNLC_LOG
, IDS_REPOBROWSE_SHOWLOG
, IDI_LOG
);
1978 if (m_dwContextMenus
& SVNSLC_POPBLAME
&& ! filepath
->IsDirectory())
1980 popup
.AppendMenuIcon(IDSVNLC_BLAME
, IDS_MENUBLAME
, IDI_BLAME
);
1983 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1984 if ( (GetSelectedCount() == 1) )
1986 if (m_dwContextMenus
& this->GetContextMenuBit(IDSVNLC_SAVEAS
) && ! filepath
->IsDirectory())
1988 popup
.AppendMenuIcon(IDSVNLC_SAVEAS
, IDS_LOG_POPUP_SAVE
, IDI_SAVEAS
);
1991 if (m_dwContextMenus
& SVNSLC_POPOPEN
&& ! filepath
->IsDirectory())
1993 popup
.AppendMenuIcon(IDSVNLC_VIEWREV
, IDS_LOG_POPUP_VIEWREV
);
1994 popup
.AppendMenuIcon(IDSVNLC_OPEN
, IDS_REPOBROWSE_OPEN
, IDI_OPEN
);
1995 popup
.AppendMenuIcon(IDSVNLC_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1996 if (wcStatus
&CTGitPath::LOGACTIONS_UNVER
) {
1997 popup
.SetDefaultItem(IDSVNLC_OPEN
, FALSE
);
2001 if (m_dwContextMenus
& SVNSLC_POPEXPLORE
)
2003 popup
.AppendMenuIcon(IDSVNLC_EXPLORE
, IDS_STATUSLIST_CONTEXT_EXPLORE
, IDI_EXPLORER
);
2007 if (GetSelectedCount() > 0)
2009 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
2011 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2013 // 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))
2016 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
2018 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
2020 if ((wcStatus
& CTGitPath::LOGACTIONS_UNVER
)/*||(wcStatus == git_wc_status_deleted)*/)
2022 if (m_dwContextMenus
& SVNSLC_POPDELETE
)
2024 popup
.AppendMenuIcon(IDSVNLC_DELETE
, IDS_MENUREMOVE
, IDI_DELETE
);
2027 if ( (wcStatus
& CTGitPath::LOGACTIONS_UNVER
|| wcStatus
& CTGitPath::LOGACTIONS_DELETED
) )
2029 if (m_dwContextMenus
& SVNSLC_POPIGNORE
)
2032 CTGitPathList ignorelist
;
2033 FillListOfSelectedItemPaths(ignorelist
);
2034 //check if all selected entries have the same extension
2035 bool bSameExt
= true;
2037 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
2039 if (sExt
.IsEmpty() && (i
==0))
2040 sExt
= ignorelist
[i
].GetFileExtension();
2041 else if (sExt
.CompareNoCase(ignorelist
[i
].GetFileExtension())!=0)
2046 if (ignoreSubMenu
.CreateMenu())
2049 if (ignorelist
.GetCount()==1)
2050 ignorepath
= ignorelist
[0].GetFileOrDirectoryName();
2052 ignorepath
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
2053 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_IGNORE
, ignorepath
);
2054 ignorepath
= _T("*")+sExt
;
2055 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_IGNOREMASK
, ignorepath
);
2057 temp
.LoadString(IDS_MENUIGNORE
);
2058 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)ignoreSubMenu
.m_hMenu
, temp
);
2064 if (ignorelist
.GetCount()==1)
2066 temp
.LoadString(IDS_MENUIGNORE
);
2070 temp
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
2072 popup
.AppendMenuIcon(IDSVNLC_IGNORE
, temp
, IDI_IGNORE
);
2080 if (GetSelectedCount() > 0)
2083 if ((!entry
->IsFolder())&&(wcStatus
>= git_wc_status_normal
)
2084 &&(wcStatus
!=git_wc_status_missing
)&&(wcStatus
!=git_wc_status_deleted
)
2085 &&(wcStatus
!=git_wc_status_added
))
2087 popup
.AppendMenu(MF_SEPARATOR
);
2088 if ((entry
->lock_token
.IsEmpty())&&(!entry
->IsFolder()))
2090 if (m_dwContextMenus
& SVNSLC_POPLOCK
)
2092 popup
.AppendMenuIcon(IDSVNLC_LOCK
, IDS_MENU_LOCK
, IDI_LOCK
);
2095 if ((!entry
->lock_token
.IsEmpty())&&(!entry
->IsFolder()))
2097 if (m_dwContextMenus
& SVNSLC_POPUNLOCK
)
2099 popup
.AppendMenuIcon(IDSVNLC_UNLOCK
, IDS_MENU_UNLOCK
, IDI_UNLOCK
);
2104 if ((!entry
->IsFolder())&&((!entry
->lock_token
.IsEmpty())||(!entry
->lock_remotetoken
.IsEmpty())))
2106 if (m_dwContextMenus
& SVNSLC_POPUNLOCKFORCE
)
2108 popup
.AppendMenuIcon(IDSVNLC_UNLOCKFORCE
, IDS_MENU_UNLOCKFORCE
, IDI_UNLOCK
);
2112 if (wcStatus
!= git_wc_status_missing
&& wcStatus
!= git_wc_status_deleted
&&wcStatus
!=git_wc_status_unversioned
)
2114 popup
.AppendMenu(MF_SEPARATOR
);
2115 popup
.AppendMenuIcon(IDSVNLC_PROPERTIES
, IDS_STATUSLIST_CONTEXT_PROPERTIES
, IDI_PROPERTIES
);
2118 popup
.AppendMenu(MF_SEPARATOR
);
2119 popup
.AppendMenuIcon(IDSVNLC_COPY
, IDS_STATUSLIST_CONTEXT_COPY
, IDI_COPYCLIP
);
2120 popup
.AppendMenuIcon(IDSVNLC_COPYEXT
, IDS_STATUSLIST_CONTEXT_COPYEXT
, IDI_COPYCLIP
);
2122 if ((m_dwContextMenus
& SVNSLC_POPCHANGELISTS
)&&(XPorLater
)
2123 &&(wcStatus
!= git_wc_status_unversioned
)&&(wcStatus
!= git_wc_status_none
))
2125 popup
.AppendMenu(MF_SEPARATOR
);
2126 // changelist commands
2127 size_t numChangelists
= GetNumberOfChangelistsInSelection();
2128 if (numChangelists
> 0)
2130 popup
.AppendMenuIcon(IDSVNLC_REMOVEFROMCS
, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS
);
2132 if ((!entry
->IsFolder())&&(changelistSubMenu
.CreateMenu()))
2135 temp
.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS
);
2136 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATECS
, temp
);
2138 if (entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
))
2140 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
2141 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATEIGNORECS
, SVNSLC_IGNORECHANGELIST
);
2144 if (m_changelists
.size() > 0)
2146 // find the changelist names
2147 bool bNeedSeparator
= true;
2148 int cmdID
= IDSVNLC_MOVETOCS
;
2149 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
2151 if ((entry
->changelist
.Compare(it
->first
))&&(it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)))
2155 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
2156 bNeedSeparator
= false;
2158 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, cmdID
, it
->first
);
2163 temp
.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS
);
2164 popup
.AppendMenu(MF_POPUP
|MF_STRING
, (UINT_PTR
)changelistSubMenu
.GetSafeHmenu(), temp
);
2170 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2173 AfxGetApp()->DoWaitCursor(1);
2174 //int iItemCountBeforeMenuCmd = GetItemCount();
2175 //bool bForce = false;
2178 case IDSVNLC_VIEWREV
:
2179 OpenFile(filepath
, ALTERNATIVEEDITOR
);
2182 OpenFile(filepath
,OPEN
);
2184 case IDSVNLC_OPENWITH
:
2185 OpenFile(filepath
,OPEN_WITH
);
2187 case IDSVNLC_EXPLORE
:
2189 ShellExecute(this->m_hWnd
, _T("explore"), filepath
->GetDirectory().GetWinPath(), NULL
, NULL
, SW_SHOW
);
2193 // Compare current version and work copy.
2194 case IDSVNLC_COMPAREWC
:
2196 POSITION pos
= GetFirstSelectedItemPosition();
2199 int index
= GetNextSelectedItem(pos
);
2204 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2205 case IDSVNLC_COMPARE
:
2207 POSITION pos
= GetFirstSelectedItemPosition();
2210 int index
= GetNextSelectedItem(pos
);
2215 case IDSVNLC_COMPARETWO
:
2217 POSITION pos
= GetFirstSelectedItemPosition();
2220 int index
= GetNextSelectedItem(pos
);
2221 StartDiffTwo(index
);
2225 case IDSVNLC_GNUDIFF1
:
2227 // SVNDiff diff(NULL, this->m_hWnd, true);
2229 // if (entry->remotestatus <= git_wc_status_normal)
2230 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2232 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2233 if(m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2234 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,GitRev::GetWorkingCopy(),
2235 *filepath
,GitRev::GetHead());
2238 if((filepath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
)) ==0)
2239 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_CurrentVersion
,
2240 *filepath
,m_CurrentVersion
+_T("~1"));
2244 if(filepath
->m_ParentNo
& MERGE_MASK
)
2248 str
.Format(_T("%s^%d"),m_CurrentVersion
,(filepath
->m_ParentNo
&PARENT_MASK
)+1);
2251 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_CurrentVersion
,
2252 *filepath
,str
, false,false,false,
2253 !!(filepath
->m_ParentNo
& MERGE_MASK
));
2258 case IDSVNLC_GNUDIFF2
:
2260 // SVNDiff diff(NULL, this->m_hWnd, true);
2262 // if (entry->remotestatus <= git_wc_status_normal)
2263 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2265 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2267 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_Rev1
,
2273 { // The add went ok, but we now need to run through the selected items again
2274 // and update their status
2275 std::vector
<int> selectIndex
;
2277 POSITION pos
= GetFirstSelectedItemPosition();
2279 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2281 selectIndex
.push_back(index
);
2283 for(int i
=0;i
<selectIndex
.size();i
++)
2285 index
=selectIndex
[i
];
2287 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2292 cmd
.Format(_T("git.exe add -- \"%s\""),path
->GetGitPathString());
2294 if(!g_Git
.Run(cmd
,&output
,CP_ACP
))
2296 path
->m_Action
= CTGitPath::LOGACTIONS_ADDED
;
2297 SetEntryCheck(path
,index
,true);
2299 SetItemGroup(index
,0);
2300 this->m_StatusFileList
.AddPath(*path
);
2301 this->m_UnRevFileList
.RemoveItem(*path
);
2302 this->m_IgnoreFileList
.RemoveItem(*path
);
2304 Show(this->m_dwShow
,0,true,true,true);
2311 case IDSVNLC_DELETE
:
2314 std::vector
<int> selectIndex
;
2316 POSITION pos
= GetFirstSelectedItemPosition();
2318 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2320 selectIndex
.push_back(index
);
2323 //Create file-list ('\0' separated) for SHFileOperation
2325 for(int i
=0;i
<selectIndex
.size();i
++)
2327 index
=selectIndex
[i
];
2329 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2334 filelist
+= path
->GetWinPathString();
2335 filelist
+= _T("|");
2337 filelist
+= _T("|");
2338 int len
= filelist
.GetLength();
2339 TCHAR
* buf
= new TCHAR
[len
+2];
2340 _tcscpy_s(buf
, len
+2, filelist
);
2341 for (int i
=0; i
<len
; ++i
)
2344 SHFILEOPSTRUCT fileop
;
2345 fileop
.hwnd
= this->m_hWnd
;
2346 fileop
.wFunc
= FO_DELETE
;
2349 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
2350 fileop
.lpszProgressTitle
= _T("deleting file");
2351 int result
= SHFileOperation(&fileop
);
2354 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
2357 POSITION pos
= NULL
;
2358 while ((pos
= GetFirstSelectedItemPosition()) != 0)
2360 int index
= GetNextSelectedItem(pos
);
2361 if (GetCheck(index
))
2365 RemoveListEntry(index
);
2375 sCmd
.Format(_T("\"%s\" /command:blame /path:\"%s\""),
2376 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath());
2378 if( (!this->m_CurrentVersion
.IsEmpty()) && this->m_CurrentVersion
!= GIT_REV_ZERO
)
2380 sCmd
+= _T(" /endrev:") + m_CurrentVersion
;
2382 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
2389 sCmd
.Format(_T("\"%s\" /command:log /path:\"%s\""),
2390 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath());
2392 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
2396 case IDSVNLC_EDITCONFLICT
:
2398 CAppUtils::ConflictEdit(*filepath
,false,this->m_bIsRevertTheirMy
);
2401 case IDSVNLC_RESOLVETHEIRS
: //follow up
2402 case IDSVNLC_RESOLVEMINE
: //follow up
2403 case IDSVNLC_RESOLVECONFLICT
:
2405 if (CMessageBox::Show(m_hWnd
, IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
)==IDYES
)
2407 POSITION pos
= GetFirstSelectedItemPosition();
2411 index
= GetNextSelectedItem(pos
);
2412 CTGitPath
* fentry
=(CTGitPath
*) this->GetItemData(index
);
2415 CString gitcmd
,output
;
2418 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDSVNLC_RESOLVETHEIRS
) ||
2419 ((this->m_bIsRevertTheirMy
)&&cmd
== IDSVNLC_RESOLVEMINE
) )
2421 gitcmd
.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry
->GetGitPathString());
2422 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2424 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2429 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDSVNLC_RESOLVEMINE
) ||
2430 ((this->m_bIsRevertTheirMy
)&&cmd
== IDSVNLC_RESOLVETHEIRS
) )
2432 gitcmd
.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry
->GetGitPathString());
2433 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2435 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2441 if ( fentry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
2443 gitcmd
.Format(_T("git.exe add -- \"%s\""),fentry
->GetGitPathString());
2444 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2446 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2449 fentry
->m_Action
|= CTGitPath::LOGACTIONS_MODIFIED
;
2450 fentry
->m_Action
&=~CTGitPath::LOGACTIONS_UNMERGED
;
2454 CAppUtils::RemoveTempMergeFile(*fentry
);
2457 Show(m_dwShow
, 0, m_bShowFolders
,0,true);
2462 case IDSVNLC_IGNORE
:
2464 CTGitPathList ignorelist
;
2465 //std::vector<CString> toremove;
2466 FillListOfSelectedItemPaths(ignorelist
, true);
2469 if(!CAppUtils::IgnoreFile(ignorelist
,false))
2472 for(int i
=0;i
<ignorelist
.GetCount();i
++)
2474 int nListboxEntries
= GetItemCount();
2475 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2477 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2478 if (path
->GetGitPathString()==ignorelist
[i
].GetGitPathString())
2480 RemoveListEntry(nItem
);
2488 CTSVNPathList ignorelist
;
2489 std::vector
<CString
> toremove
;
2490 FillListOfSelectedItemPaths(ignorelist
, true);
2492 for (int j
=0; j
<ignorelist
.GetCount(); ++j
)
2494 int nListboxEntries
= GetItemCount();
2495 for (int i
=0; i
<nListboxEntries
; ++i
)
2497 if (GetListEntry(i
)->GetPath().IsEquivalentTo(ignorelist
[j
]))
2503 CString name
= CPathUtils::PathPatternEscape(ignorelist
[j
].GetFileOrDirectoryName());
2504 CTSVNPath parentfolder
= ignorelist
[j
].GetContainingDirectory();
2505 SVNProperties
props(parentfolder
, SVNRev::REV_WC
, false);
2507 for (int i
=0; i
<props
.GetCount(); i
++)
2509 CString
propname(props
.GetItemName(i
).c_str());
2510 if (propname
.CompareNoCase(_T("git:ignore"))==0)
2513 // treat values as normal text even if they're not
2514 value
= (char *)props
.GetItemValue(i
).c_str();
2517 if (value
.IsEmpty())
2521 value
= value
.Trim("\n\r");
2526 if (!props
.Add(_T("git:ignore"), (LPCSTR
)value
))
2529 temp
.Format(IDS_ERR_FAILEDIGNOREPROPERTY
, (LPCTSTR
)name
);
2530 CMessageBox::Show(this->m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONERROR
);
2533 if (GetCheck(selIndex
))
2537 // now, if we ignored a folder, remove all its children
2538 if (ignorelist
[j
].IsDirectory())
2540 for (int i
=0; i
<(int)m_arListArray
.size(); ++i
)
2542 FileEntry
* entry
= GetListEntry(i
);
2543 if (entry
->status
== git_wc_status_unversioned
)
2545 if (!ignorelist
[j
].IsEquivalentTo(entry
->GetPath())&&(ignorelist
[j
].IsAncestorOf(entry
->GetPath())))
2547 entry
->status
= git_wc_status_ignored
;
2548 entry
->textstatus
= git_wc_status_ignored
;
2551 toremove
.push_back(entry
->GetPath().GetSVNPathString());
2557 CTSVNPath basepath
= m_arStatusArray
[m_arListArray
[selIndex
]]->basepath
;
2559 FileEntry
* entry
= m_arStatusArray
[m_arListArray
[selIndex
]];
2560 if ( entry
->status
== git_wc_status_unversioned
) // keep "deleted" items
2561 toremove
.push_back(entry
->GetPath().GetSVNPathString());
2563 if (!m_bIgnoreRemoveOnly
)
2566 git_wc_status2_t
* s
;
2568 s
= status
.GetFirstFileStatus(parentfolder
, gitPath
, false, git_depth_empty
);
2569 // first check if the folder isn't already present in the list
2570 bool bFound
= false;
2571 nListboxEntries
= GetItemCount();
2572 for (int i
=0; i
<nListboxEntries
; ++i
)
2574 FileEntry
* entry
= GetListEntry(i
);
2575 if (entry
->path
.IsEquivalentTo(gitPath
))
2585 FileEntry
* entry
= new FileEntry();
2586 entry
->path
= gitPath
;
2587 entry
->basepath
= basepath
;
2588 entry
->status
= SVNStatus::GetMoreImportant(s
->text_status
, s
->prop_status
);
2589 entry
->textstatus
= s
->text_status
;
2590 entry
->propstatus
= s
->prop_status
;
2591 entry
->remotestatus
= SVNStatus::GetMoreImportant(s
->repos_text_status
, s
->repos_prop_status
);
2592 entry
->remotetextstatus
= s
->repos_text_status
;
2593 entry
->remotepropstatus
= s
->repos_prop_status
;
2594 entry
->inunversionedfolder
= FALSE
;
2595 entry
->checked
= true;
2596 entry
->inexternal
= false;
2597 entry
->direct
= false;
2598 entry
->isfolder
= true;
2599 entry
->last_commit_date
= 0;
2600 entry
->last_commit_rev
= 0;
2601 entry
->remoterev
= 0;
2606 entry
->url
= CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s
->entry
->url
));
2609 if (s
->entry
&& s
->entry
->present_props
)
2611 entry
->present_props
= s
->entry
->present_props
;
2613 m_arStatusArray
.push_back(entry
);
2614 m_arListArray
.push_back(m_arStatusArray
.size()-1);
2615 AddEntry(entry
, langID
, GetItemCount());
2620 for (std::vector
<CString
>::iterator it
= toremove
.begin(); it
!= toremove
.end(); ++it
)
2622 int nListboxEntries
= GetItemCount();
2623 for (int i
=0; i
<nListboxEntries
; ++i
)
2625 if (GetListEntry(i
)->path
.GetSVNPathString().Compare(*it
)==0)
2636 case IDSVNLC_IGNOREMASK
:
2639 CString ext
=filepath
->GetFileExtension();
2640 CTGitPathList ignorelist
;
2641 FillListOfSelectedItemPaths(ignorelist
, true);
2644 CAppUtils::IgnoreFile(ignorelist
,true);
2646 common
=ignorelist
.GetCommonRoot().GetGitPathString();
2648 for (int i
=0; i
< GetItemCount(); ++i
)
2650 CTGitPath
*path
=(CTGitPath
*)GetItemData(i
);
2651 if(!( path
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
2653 if( path
->GetGitPathString().Left(common
.GetLength()) == common
)
2655 if (path
->GetFileExtension()==ext
)
2658 i
--; // remove index i at item, new one will replace.
2663 CWnd
* pParent
= GetParent();
2664 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2666 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
2672 std::set
<CTSVNPath
> parentlist
;
2673 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
2675 parentlist
.insert(ignorelist
[i
].GetContainingDirectory());
2677 std::set
<CTSVNPath
>::iterator it
;
2678 std::vector
<CString
> toremove
;
2680 for (it
= parentlist
.begin(); it
!= parentlist
.end(); ++it
)
2682 CTSVNPath parentFolder
= (*it
).GetDirectory();
2683 SVNProperties
props(parentFolder
, SVNRev::REV_WC
, false);
2685 for (int i
=0; i
<props
.GetCount(); i
++)
2687 CString
propname(props
.GetItemName(i
).c_str());
2688 if (propname
.CompareNoCase(_T("git:ignore"))==0)
2691 // treat values as normal text even if they're not
2692 value
= (char *)props
.GetItemValue(i
).c_str();
2695 if (value
.IsEmpty())
2699 value
= value
.Trim("\n\r");
2704 if (!props
.Add(_T("git:ignore"), (LPCSTR
)value
))
2707 temp
.Format(IDS_ERR_FAILEDIGNOREPROPERTY
, (LPCTSTR
)name
);
2708 CMessageBox::Show(this->m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONERROR
);
2713 int nListboxEntries
= GetItemCount();
2714 for (int i
=0; i
<nListboxEntries
; ++i
)
2716 FileEntry
* entry
= GetListEntry(i
);
2717 ASSERT(entry
!= NULL
);
2720 if (basepath
.IsEmpty())
2721 basepath
= entry
->basepath
;
2722 // since we ignored files with a mask (e.g. *.exe)
2723 // we have to find find all files in the same
2724 // folder (IsAncestorOf() returns TRUE for _all_ children,
2725 // not just the immediate ones) which match the
2726 // mask and remove them from the list too.
2727 if ((entry
->status
== git_wc_status_unversioned
)&&(parentFolder
.IsAncestorOf(entry
->path
)))
2729 CString f
= entry
->path
.GetSVNPathString();
2730 if (f
.Mid(parentFolder
.GetSVNPathString().GetLength()).Find('/')<=0)
2732 if (CStringUtils::WildCardMatch(name
, f
))
2737 toremove
.push_back(f
);
2742 if (!m_bIgnoreRemoveOnly
)
2745 git_wc_status2_t
* s
;
2747 s
= status
.GetFirstFileStatus(parentFolder
, gitPath
, false, git_depth_empty
);
2750 // first check if the folder isn't already present in the list
2751 bool bFound
= false;
2752 for (int i
=0; i
<nListboxEntries
; ++i
)
2754 FileEntry
* entry
= GetListEntry(i
);
2755 if (entry
->path
.IsEquivalentTo(gitPath
))
2763 FileEntry
* entry
= new FileEntry();
2764 entry
->path
= gitPath
;
2765 entry
->basepath
= basepath
;
2766 entry
->status
= SVNStatus::GetMoreImportant(s
->text_status
, s
->prop_status
);
2767 entry
->textstatus
= s
->text_status
;
2768 entry
->propstatus
= s
->prop_status
;
2769 entry
->remotestatus
= SVNStatus::GetMoreImportant(s
->repos_text_status
, s
->repos_prop_status
);
2770 entry
->remotetextstatus
= s
->repos_text_status
;
2771 entry
->remotepropstatus
= s
->repos_prop_status
;
2772 entry
->inunversionedfolder
= false;
2773 entry
->checked
= true;
2774 entry
->inexternal
= false;
2775 entry
->direct
= false;
2776 entry
->isfolder
= true;
2777 entry
->last_commit_date
= 0;
2778 entry
->last_commit_rev
= 0;
2779 entry
->remoterev
= 0;
2784 entry
->url
= CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s
->entry
->url
));
2787 if (s
->entry
&& s
->entry
->present_props
)
2789 entry
->present_props
= s
->entry
->present_props
;
2791 m_arStatusArray
.push_back(entry
);
2792 m_arListArray
.push_back(m_arStatusArray
.size()-1);
2793 AddEntry(entry
, langID
, GetItemCount());
2799 for (std::vector
<CString
>::iterator it
= toremove
.begin(); it
!= toremove
.end(); ++it
)
2801 int nListboxEntries
= GetItemCount();
2802 for (int i
=0; i
<nListboxEntries
; ++i
)
2804 if (GetListEntry(i
)->path
.GetSVNPathString().Compare(*it
)==0)
2816 case IDSVNLC_REVERT
:
2818 // If at least one item is not in the status "added"
2819 // we ask for a confirmation
2820 BOOL bConfirm
= FALSE
;
2821 POSITION pos
= GetFirstSelectedItemPosition();
2823 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2825 //FileEntry * fentry = GetListEntry(index);
2826 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
2827 if(fentry
&& fentry
->m_Action
&CTGitPath::LOGACTIONS_MODIFIED
)
2835 str
.Format(IDS_PROC_WARNREVERT
,GetSelectedCount());
2837 if (!bConfirm
|| CMessageBox::Show(this->m_hWnd
, str
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
2839 CTGitPathList targetList
;
2840 FillListOfSelectedItemPaths(targetList
);
2842 // make sure that the list is reverse sorted, so that
2843 // children are removed before any parents
2844 targetList
.SortByPathname(true);
2846 // put all reverted files in the trashbin, except the ones with 'added'
2847 // status because they are not restored by the revert.
2848 CTGitPathList delList
;
2849 POSITION pos
= GetFirstSelectedItemPosition();
2851 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2853 CTGitPath
*entry
=(CTGitPath
*)GetItemData(index
);
2854 if (entry
&&(!(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
))
2855 && (!(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)))
2858 fullpath
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+entry
->GetWinPath());
2859 delList
.AddPath(fullpath
);
2862 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
2863 delList
.DeleteAllFiles(true);
2865 if (g_Git
.Revert(targetList
))
2867 CMessageBox::Show(this->m_hWnd
, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR
);
2871 bool updateStatusList
= false;
2872 for(int i
=0;i
<targetList
.GetCount();i
++)
2874 int nListboxEntries
= GetItemCount();
2875 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2877 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2878 if (path
->GetGitPathString()==targetList
[i
].GetGitPathString())
2880 if(path
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2882 path
->m_Action
= CTGitPath::LOGACTIONS_UNVER
;
2883 SetEntryCheck(path
,nItem
,false);
2884 updateStatusList
= true;
2885 SetItemGroup(nItem
,1);
2886 this->m_StatusFileList
.RemoveItem(*path
);
2887 this->m_UnRevFileList
.AddPath(*path
);
2888 //this->m_IgnoreFileList.RemoveItem(*path);
2892 RemoveListEntry(nItem
);
2900 Show(m_dwShow
, 0, m_bShowFolders
,updateStatusList
,true);
2908 CopySelectedEntriesToClipboard(0);
2910 case IDSVNLC_COPYEXT
:
2911 CopySelectedEntriesToClipboard((DWORD
)-1);
2914 case IDSVNLC_SAVEAS
:
2915 FileSaveAs(filepath
);
2918 case IDSVNLC_REVERTTOREV
:
2919 RevertSelectedItemToVersion();
2922 case IDSVNLC_PROPERTIES
:
2924 CTSVNPathList targetList
;
2925 FillListOfSelectedItemPaths(targetList
);
2926 CEditPropertiesDlg dlg
;
2927 dlg
.SetPathList(targetList
);
2929 if (dlg
.HasChanged())
2931 // since the user might have changed/removed/added
2932 // properties recursively, we don't really know
2933 // which items have changed their status.
2934 // So tell the parent to do a refresh.
2935 CWnd
* pParent
= GetParent();
2936 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2938 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
2943 case IDSVNLC_COMMIT
:
2945 CTSVNPathList targetList
;
2946 FillListOfSelectedItemPaths(targetList
);
2947 CTSVNPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2948 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2949 CString commandline
= CPathUtils::GetAppDirectory();
2950 commandline
+= _T("TortoiseProc.exe /command:commit /pathfile:\"");
2951 commandline
+= tempFile
.GetWinPathString();
2952 commandline
+= _T("\"");
2953 commandline
+= _T(" /deletepathfile");
2954 CAppUtils::LaunchApplication(commandline
, NULL
, false);
2958 case IDSVNLC_COMPAREWC
:
2960 POSITION pos
= GetFirstSelectedItemPosition();
2963 int index
= GetNextSelectedItem(pos
);
2964 FileEntry
* entry
= GetListEntry(index
);
2965 ASSERT(entry
!= NULL
);
2968 SVNDiff
diff(NULL
, m_hWnd
, true);
2969 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2970 git_revnum_t baseRev
= entry
->Revision
;
2971 diff
.DiffFileAgainstBase(
2972 entry
->path
, baseRev
, entry
->textstatus
, entry
->propstatus
);
2976 case IDSVNLC_GNUDIFF1
:
2978 SVNDiff
diff(NULL
, this->m_hWnd
, true);
2980 if (entry
->remotestatus
<= git_wc_status_normal
)
2981 CAppUtils::StartShowUnifiedDiff(m_hWnd
, entry
->path
, SVNRev::REV_BASE
, entry
->path
, SVNRev::REV_WC
);
2983 CAppUtils::StartShowUnifiedDiff(m_hWnd
, entry
->path
, SVNRev::REV_WC
, entry
->path
, SVNRev::REV_HEAD
);
2986 case IDSVNLC_UPDATE
:
2988 CTSVNPathList targetList
;
2989 FillListOfSelectedItemPaths(targetList
);
2990 bool bAllExist
= true;
2991 for (int i
=0; i
<targetList
.GetCount(); ++i
)
2993 if (!targetList
[i
].Exists())
3001 CSVNProgressDlg dlg
;
3002 dlg
.SetCommand(CSVNProgressDlg::SVNProgress_Update
);
3003 dlg
.SetPathList(targetList
);
3004 dlg
.SetRevision(SVNRev::REV_HEAD
);
3009 CString sTempFile
= CTempFiles::Instance().GetTempFilePath(false).GetWinPathString();
3010 targetList
.WriteToFile(sTempFile
, false);
3012 sCmd
.Format(_T("\"%s\" /command:update /rev /pathfile:\"%s\" /deletepathfile"),
3013 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR
)sTempFile
);
3015 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
3020 case IDSVNLC_REMOVE
:
3023 CTSVNPathList itemsToRemove
;
3024 FillListOfSelectedItemPaths(itemsToRemove
);
3026 // We must sort items before removing, so that files are always removed
3027 // *before* their parents
3028 itemsToRemove
.SortByPathname(true);
3030 bool bSuccess
= false;
3031 if (git
.Remove(itemsToRemove
, FALSE
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)))
3037 if ((git
.Err
->apr_err
== SVN_ERR_UNVERSIONED_RESOURCE
) ||
3038 (git
.Err
->apr_err
== SVN_ERR_CLIENT_MODIFIED
))
3040 CString msg
, yes
, no
, yestoall
;
3041 msg
.Format(IDS_PROC_REMOVEFORCE
, (LPCTSTR
)git
.GetLastErrorMessage());
3042 yes
.LoadString(IDS_MSGBOX_YES
);
3043 no
.LoadString(IDS_MSGBOX_NO
);
3044 yestoall
.LoadString(IDS_PROC_YESTOALL
);
3045 UINT ret
= CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_ERROR
, yes
, no
, yestoall
);
3046 if ((ret
== 1)||(ret
==3))
3048 if (!git
.Remove(itemsToRemove
, TRUE
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)))
3050 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3057 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3061 // The remove went ok, but we now need to run through the selected items again
3062 // and update their status
3063 POSITION pos
= GetFirstSelectedItemPosition();
3065 std::vector
<int> entriesToRemove
;
3066 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3068 FileEntry
* e
= GetListEntry(index
);
3070 ((e
->textstatus
== git_wc_status_unversioned
)||
3071 (e
->textstatus
== git_wc_status_none
)||
3072 (e
->textstatus
== git_wc_status_ignored
)))
3074 if (GetCheck(index
))
3077 entriesToRemove
.push_back(index
);
3081 e
->textstatus
= git_wc_status_deleted
;
3082 e
->status
= git_wc_status_deleted
;
3083 SetEntryCheck(e
,index
,true);
3086 for (std::vector
<int>::reverse_iterator it
= entriesToRemove
.rbegin(); it
!= entriesToRemove
.rend(); ++it
)
3088 RemoveListEntry(*it
);
3092 Show(m_dwShow
, 0, m_bShowFolders
);
3096 case IDSVNLC_DELETE
:
3098 CTSVNPathList pathlist
;
3099 FillListOfSelectedItemPaths(pathlist
);
3100 pathlist
.RemoveChildren();
3102 for (INT_PTR i
=0; i
<pathlist
.GetCount(); ++i
)
3104 filelist
+= pathlist
[i
].GetWinPathString();
3105 filelist
+= _T("|");
3107 filelist
+= _T("|");
3108 int len
= filelist
.GetLength();
3109 TCHAR
* buf
= new TCHAR
[len
+2];
3110 _tcscpy_s(buf
, len
+2, filelist
);
3111 for (int i
=0; i
<len
; ++i
)
3114 SHFILEOPSTRUCT fileop
;
3115 fileop
.hwnd
= this->m_hWnd
;
3116 fileop
.wFunc
= FO_DELETE
;
3119 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
3120 fileop
.lpszProgressTitle
= _T("deleting file");
3121 int result
= SHFileOperation(&fileop
);
3124 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
3127 POSITION pos
= NULL
;
3128 CTSVNPathList deletedlist
; // to store list of deleted folders
3129 while ((pos
= GetFirstSelectedItemPosition()) != 0)
3131 int index
= GetNextSelectedItem(pos
);
3132 if (GetCheck(index
))
3135 FileEntry
* fentry
= GetListEntry(index
);
3136 if ((fentry
)&&(fentry
->isfolder
))
3137 deletedlist
.AddPath(fentry
->path
);
3138 RemoveListEntry(index
);
3140 // now go through the list of deleted folders
3141 // and remove all their children from the list too!
3142 int nListboxEntries
= GetItemCount();
3143 for (int folderindex
= 0; folderindex
< deletedlist
.GetCount(); ++folderindex
)
3145 CTSVNPath folderpath
= deletedlist
[folderindex
];
3146 for (int i
=0; i
<nListboxEntries
; ++i
)
3148 FileEntry
* entry
= GetListEntry(i
);
3149 if (folderpath
.IsAncestorOf(entry
->path
))
3151 RemoveListEntry(i
--);
3165 CTSVNPathList itemsToAdd
;
3166 FillListOfSelectedItemPaths(itemsToAdd
);
3168 // We must sort items before adding, so that folders are always added
3169 // *before* any of their children
3170 itemsToAdd
.SortByPathname();
3172 ProjectProperties props
;
3173 props
.ReadPropsPathList(itemsToAdd
);
3174 if (git
.Add(itemsToAdd
, &props
, git_depth_empty
, TRUE
, TRUE
, TRUE
))
3176 // The add went ok, but we now need to run through the selected items again
3177 // and update their status
3178 POSITION pos
= GetFirstSelectedItemPosition();
3180 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3182 FileEntry
* e
= GetListEntry(index
);
3183 e
->textstatus
= git_wc_status_added
;
3184 e
->propstatus
= git_wc_status_none
;
3185 e
->status
= git_wc_status_added
;
3186 SetEntryCheck(e
,index
,true);
3191 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3194 Show(m_dwShow
, 0, m_bShowFolders
);
3198 case IDSVNLC_ADD_RECURSIVE
:
3200 CTSVNPathList itemsToAdd
;
3201 FillListOfSelectedItemPaths(itemsToAdd
);
3204 dlg
.m_pathList
= itemsToAdd
;
3205 if (dlg
.DoModal() == IDOK
)
3207 if (dlg
.m_pathList
.GetCount() == 0)
3209 CSVNProgressDlg progDlg
;
3210 progDlg
.SetCommand(CSVNProgressDlg::SVNProgress_Add
);
3211 progDlg
.SetPathList(dlg
.m_pathList
);
3212 ProjectProperties props
;
3213 props
.ReadPropsPathList(dlg
.m_pathList
);
3214 progDlg
.SetProjectProperties(props
);
3215 progDlg
.SetItemCount(dlg
.m_pathList
.GetCount());
3219 CWnd
* pParent
= GetParent();
3220 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3222 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
3228 case IDSVNLC_REPAIRMOVE
:
3230 POSITION pos
= GetFirstSelectedItemPosition();
3231 int index
= GetNextSelectedItem(pos
);
3232 FileEntry
* entry1
= NULL
;
3233 FileEntry
* entry2
= NULL
;
3236 entry1
= GetListEntry(index
);
3237 git_wc_status_kind status1
= git_wc_status_none
;
3238 git_wc_status_kind status2
= git_wc_status_none
;
3241 status1
= entry1
->status
;
3242 index
= GetNextSelectedItem(pos
);
3245 entry2
= GetListEntry(index
);
3248 status2
= entry2
->status
;
3249 if (status2
== git_wc_status_missing
&& status1
== git_wc_status_unversioned
)
3251 FileEntry
* tempentry
= entry1
;
3255 // entry1 was renamed to entry2 but outside of Subversion
3256 // fix this by moving entry2 back to entry1 first,
3257 // then do an git-move from entry1 to entry2
3258 if (MoveFile(entry2
->GetPath().GetWinPath(), entry1
->GetPath().GetWinPath()))
3261 if (!git
.Move(CTSVNPathList(entry1
->GetPath()), entry2
->GetPath(), TRUE
))
3263 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3267 // check the previously unversioned item
3268 entry1
->checked
= true;
3269 // fixing the move was successful. We have to adjust the new status of the
3271 // Since we don't know if the moved/renamed file had local modifications or not,
3272 // we can't guess the new status. That means we have to refresh...
3273 CWnd
* pParent
= GetParent();
3274 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3276 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
3283 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
3284 FORMAT_MESSAGE_FROM_SYSTEM
|
3285 FORMAT_MESSAGE_IGNORE_INSERTS
,
3288 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
3293 MessageBox((LPCTSTR
)lpMsgBuf
, _T("Error"), MB_OK
| MB_ICONINFORMATION
);
3294 LocalFree( lpMsgBuf
);
3302 case IDSVNLC_REMOVEFROMCS
:
3304 CTSVNPathList changelistItems
;
3305 FillListOfSelectedItemPaths(changelistItems
);
3308 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
3310 // The changelists were removed, but we now need to run through the selected items again
3311 // and update their changelist
3312 POSITION pos
= GetFirstSelectedItemPosition();
3314 std::vector
<int> entriesToRemove
;
3315 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3317 FileEntry
* e
= GetListEntry(index
);
3320 e
->changelist
.Empty();
3321 if (e
->status
== git_wc_status_normal
)
3323 // remove the entry completely
3324 entriesToRemove
.push_back(index
);
3327 SetItemGroup(index
, 0);
3330 for (std::vector
<int>::reverse_iterator it
= entriesToRemove
.rbegin(); it
!= entriesToRemove
.rend(); ++it
)
3332 RemoveListEntry(*it
);
3334 // TODO: Should we go through all entries here and check if we also could
3335 // remove the changelist from m_changelists ?
3339 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3344 case IDSVNLC_CREATEIGNORECS
:
3345 CreateChangeList(SVNSLC_IGNORECHANGELIST
);
3347 case IDSVNLC_CREATECS
:
3349 CCreateChangelistDlg dlg
;
3350 if (dlg
.DoModal() == IDOK
)
3352 CreateChangeList(dlg
.m_sName
);
3358 if (cmd
< IDSVNLC_MOVETOCS
)
3360 CTSVNPathList changelistItems
;
3361 FillListOfSelectedItemPaths(changelistItems
);
3363 // find the changelist name
3364 CString sChangelist
;
3365 int cmdID
= IDSVNLC_MOVETOCS
;
3367 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
3369 if ((it
->first
.Compare(SVNSLC_IGNORECHANGELIST
))&&(entry
->changelist
.Compare(it
->first
)))
3373 sChangelist
= it
->first
;
3378 if (!sChangelist
.IsEmpty())
3381 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
3383 // The changelists were moved, but we now need to run through the selected items again
3384 // and update their changelist
3385 POSITION pos
= GetFirstSelectedItemPosition();
3387 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3389 FileEntry
* e
= GetListEntry(index
);
3390 e
->changelist
= sChangelist
;
3393 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
3394 SetItemGroup(index
, m_changelists
[e
->changelist
]);
3396 SetItemGroup(index
, 0);
3402 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3412 AfxGetApp()->DoWaitCursor(-1);
3413 GetStatisticsString();
3414 //int iItemCountAfterMenuCmd = GetItemCount();
3415 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
3417 // CWnd* pParent = GetParent();
3418 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3420 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
3423 } // if (popup.CreatePopupMenu())
3424 } // if (selIndex >= 0)
3428 void CGitStatusListCtrl::OnContextMenuHeader(CWnd
* pWnd
, CPoint point
)
3430 Locker
lock(m_critSec
);
3431 m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
3434 void CGitStatusListCtrl::OnContextMenu(CWnd
* pWnd
, CPoint point
)
3439 OnContextMenuList(pWnd
, point
);
3440 } // if (pWnd == this)
3441 else if (pWnd
== GetHeaderCtrl())
3443 OnContextMenuHeader(pWnd
, point
);
3447 void CGitStatusListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3450 Locker
lock(m_critSec
);
3451 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
3456 if (pNMLV
->iItem
< 0)
3458 if (!IsGroupViewEnabled())
3461 DWORD ptW
= GetMessagePos();
3462 pt
.x
= GET_X_LPARAM(ptW
);
3463 pt
.y
= GET_Y_LPARAM(ptW
);
3464 ScreenToClient(&pt
);
3465 int group
= GetGroupFromPoint(&pt
);
3468 // check/uncheck the whole group depending on the check-state
3469 // of the first item in the group
3471 bool bCheck
= false;
3472 bool bFirst
= false;
3474 for (int i
=0; i
<GetItemCount(); ++i
)
3476 SecureZeroMemory(&lv
, sizeof(LVITEM
));
3477 lv
.mask
= LVIF_GROUPID
;
3480 if (lv
.iGroupId
== group
)
3482 CTGitPath
*entry
=(CTGitPath
*)GetItemData(i
);
3486 bCheck
= !GetCheck(i
);
3491 bool bOldCheck
= !!GetCheck(i
);
3492 SetEntryCheck(entry
, i
, bCheck
);
3493 if (bCheck
!= bOldCheck
)
3503 GetStatisticsString();
3509 CTGitPath
*file
=(CTGitPath
*)GetItemData(pNMLV
->iItem
);
3511 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
) {
3512 OpenFile(file
, OPEN
);
3515 if( file
->m_Action
&CTGitPath::LOGACTIONS_UNMERGED
)
3517 CAppUtils::ConflictEdit(*file
,false,m_bIsRevertTheirMy
);
3521 if( (!m_Rev1
.IsEmpty()) || (!m_Rev1
.IsEmpty())) // m_Rev1 twice???
3522 StartDiffTwo(pNMLV
->iItem
);
3524 StartDiff(pNMLV
->iItem
);
3528 void CGitStatusListCtrl::StartDiffTwo(int fileindex
)
3533 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3535 CGitDiff::Diff(&file1
,&file1
,
3540 void CGitStatusListCtrl::StartDiffWC(int fileindex
)
3546 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
3549 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3551 CGitDiff::Diff(&file1
,&file1
, GIT_REV_ZERO
, m_CurrentVersion
);
3555 void CGitStatusListCtrl::StartDiff(int fileindex
)
3560 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3562 if(file1
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
3564 file2
.SetFromGit(file1
.GetGitOldPathString());
3570 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
3572 if( g_Git
.IsInitRepos())
3573 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3575 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_ADDED
)
3576 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3577 m_CurrentVersion
,true);
3578 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_DELETED
)
3579 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3580 GitRev::GetHead(),false);
3582 CGitDiff::Diff(&file1
,&file2
,
3583 CString(GIT_REV_ZERO
),
3588 if(rev
.GetCommit(m_CurrentVersion
+_T("~1")) || (file1
.m_Action
== file1
.LOGACTIONS_ADDED
))
3590 CGitDiff::DiffNull(&file1
,m_CurrentVersion
,true);
3592 } else if (file1
.m_Action
== file1
.LOGACTIONS_DELETED
) {
3593 CGitDiff::DiffNull(&file1
,m_CurrentVersion
+_T("~1"),false);
3596 if( file1
.m_ParentNo
& MERGE_MASK
)
3599 CTGitPath base
,theirs
, mine
;
3601 CTGitPath merge
=file1
;
3602 CTGitPath directory
= merge
.GetDirectory();
3604 mine
.SetFromGit(CAppUtils::GetMergeTempFile(_T("LOCAL"),merge
));
3605 theirs
.SetFromGit(CAppUtils::GetMergeTempFile(_T("REMOTE"),merge
));
3606 base
.SetFromGit(CAppUtils::GetMergeTempFile(_T("BASE"),merge
));
3609 //create a empty file, incase stage is not three
3610 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3612 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3614 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3617 merge
.SetFromGit(merge
.GetGitPathString()+_T("Merged"));
3619 int parent1
=-1, parent2
=-1;
3620 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
3622 if(m_arStatusArray
[i
]->GetGitPathString() == file1
.GetGitPathString())
3624 if(m_arStatusArray
[i
]->m_ParentNo
& MERGE_MASK
)
3630 parent1
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
3631 }else if (parent2
<0)
3633 parent2
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
3639 if(g_Git
.GetOneFile(m_CurrentVersion
, file1
, (CString
&)merge
.GetWinPathString()))
3641 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3647 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent1
+1);
3649 if(g_Git
.GetOneFile(str
, file1
, (CString
&)mine
.GetWinPathString()))
3651 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3658 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent2
+1);
3660 if(g_Git
.GetOneFile(str
, file1
, (CString
&)theirs
.GetWinPathString()))
3662 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3666 if(parent1
>=0 && parent2
>=0)
3669 cmd
.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion
, parent1
+1,
3670 this->m_CurrentVersion
,parent2
+1);
3672 if(g_Git
.Run(cmd
,&output
, CP_ACP
))
3676 if(g_Git
.GetOneFile(output
.Left(40), file1
, (CString
&)base
.GetWinPathString()))
3678 CMessageBox::Show(NULL
, _T("Fail to get base file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3682 CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
3687 if( (file1
.m_ParentNo
&PARENT_MASK
) == 0)
3692 str
.Format(_T("^%d"), (file1
.m_ParentNo
&PARENT_MASK
)+1);
3694 CGitDiff::Diff(&file1
,&file2
,
3696 m_CurrentVersion
+str
);
3703 FileEntry
* entry
= GetListEntry(fileindex
);
3704 ASSERT(entry
!= NULL
);
3707 if (((entry
->status
== git_wc_status_normal
)&&(entry
->remotestatus
<= git_wc_status_normal
))||
3708 (entry
->status
== git_wc_status_unversioned
)||(entry
->status
== git_wc_status_none
))
3710 int ret
= (int)ShellExecute(this->m_hWnd
, NULL
, entry
->path
.GetWinPath(), NULL
, NULL
, SW_SHOW
);
3711 if (ret
<= HINSTANCE_ERROR
)
3713 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
3714 cmd
+= entry
->path
.GetWinPathString();
3715 CAppUtils::LaunchApplication(cmd
, NULL
, false);
3720 GitDiff
diff(NULL
, m_hWnd
, true);
3721 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
3723 entry
->path
, entry
->textstatus
, entry
->propstatus
,
3724 entry
->remotetextstatus
, entry
->remotepropstatus
);
3728 CString
CGitStatusListCtrl::GetStatisticsString(bool simple
)
3731 CString sNormal
, sAdded
, sDeleted
, sModified
, sConflicted
, sUnversioned
, sRenamed
;
3732 WORD langID
= (WORD
)(DWORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3733 TCHAR buf
[MAX_STATUS_STRING_LENGTH
];
3734 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3736 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3738 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3740 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3742 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3744 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3746 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3751 sToolTip
.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d"),
3752 this->m_nLineAdded
,this->m_nLineDeleted
,
3753 (LPCTSTR
)sModified
, m_nModified
,
3754 (LPCTSTR
)sAdded
, m_nAdded
,
3755 (LPCTSTR
)sDeleted
, m_nDeleted
,
3756 (LPCTSTR
)sRenamed
, m_nRenamed
3760 sToolTip
.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d"),
3761 this->m_nLineAdded
,this->m_nLineDeleted
,
3762 (LPCTSTR
)sNormal
, m_nNormal
,
3763 (LPCTSTR
)sUnversioned
, m_nUnversioned
,
3764 (LPCTSTR
)sModified
, m_nModified
,
3765 (LPCTSTR
)sAdded
, m_nAdded
,
3766 (LPCTSTR
)sDeleted
, m_nDeleted
,
3767 (LPCTSTR
)sConflicted
, m_nConflicted
3771 sStats
.Format(IDS_COMMITDLG_STATISTICSFORMAT
, m_nSelected
, GetItemCount());
3774 m_pStatLabel
->SetWindowText(sStats
);
3777 if (m_pSelectButton
)
3779 if (m_nSelected
== 0)
3780 m_pSelectButton
->SetCheck(BST_UNCHECKED
);
3781 else if (m_nSelected
!= GetItemCount())
3782 m_pSelectButton
->SetCheck(BST_INDETERMINATE
);
3784 m_pSelectButton
->SetCheck(BST_CHECKED
);
3787 if (m_pConfirmButton
)
3789 m_pConfirmButton
->EnableWindow(m_nSelected
>0);
3797 CString
CGitStatusListCtrl::GetCommonDirectory(bool bStrict
)
3801 // not strict means that the selected folder has priority
3802 if (!m_StatusFileList
.GetCommonDirectory().IsEmpty())
3803 return m_StatusFileList
.GetCommonDirectory().GetWinPath();
3806 CTGitPath commonBaseDirectory
;
3807 int nListItems
= GetItemCount();
3808 for (int i
=0; i
<nListItems
; ++i
)
3810 CTGitPath baseDirectory
,*p
= (CTGitPath
*)this->GetItemData(i
);
3814 baseDirectory
= p
->GetDirectory();
3816 if(commonBaseDirectory
.IsEmpty())
3818 commonBaseDirectory
= baseDirectory
;
3822 if (commonBaseDirectory
.GetWinPathString().GetLength() > baseDirectory
.GetWinPathString().GetLength())
3824 if (baseDirectory
.IsAncestorOf(commonBaseDirectory
))
3825 commonBaseDirectory
= baseDirectory
;
3829 return g_Git
.m_CurrentDir
+CString(_T("\\"))+commonBaseDirectory
.GetWinPath();
3833 void CGitStatusListCtrl::SelectAll(bool bSelect
, bool /*bIncludeNoCommits*/)
3835 CWaitCursor waitCursor
;
3836 // block here so the LVN_ITEMCHANGED messages
3841 int nListItems
= GetItemCount();
3843 m_nSelected
= nListItems
;
3847 for (int i
=0; i
<nListItems
; ++i
)
3849 //FileEntry * entry = GetListEntry(i);
3850 //ASSERT(entry != NULL);
3851 CTGitPath
*path
= (CTGitPath
*) GetItemData(i
);
3854 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
3855 SetEntryCheck(path
,i
,bSelect
);
3858 // unblock before redrawing
3861 GetStatisticsString();
3865 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3867 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
3872 CTGitPath
*entry
=(CTGitPath
*)GetItemData(pGetInfoTip
->iItem
);
3875 if (pGetInfoTip
->cchTextMax
> entry
->GetGitPathString().GetLength() + g_Git
.m_CurrentDir
.GetLength())
3878 str
+= g_Git
.m_CurrentDir
;
3880 str
+= entry
->GetWinPathString();
3882 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, str
.GetBuffer(), str
.GetLength());
3886 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3888 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
3890 // Take the default processing unless we set this to something else below.
3891 *pResult
= CDRF_DODEFAULT
;
3893 // First thing - check the draw stage. If it's the control's prepaint
3894 // stage, then tell Windows we want messages for every item.
3896 switch (pLVCD
->nmcd
.dwDrawStage
)
3899 *pResult
= CDRF_NOTIFYITEMDRAW
;
3901 case CDDS_ITEMPREPAINT
:
3903 // This is the prepaint stage for an item. Here's where we set the
3904 // item's text color. Our return value will tell Windows to draw the
3905 // item itself, but it will use the new color we set here.
3907 // Tell Windows to paint the control itself.
3908 *pResult
= CDRF_DODEFAULT
;
3912 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
3914 if (m_arStatusArray
.size() > (DWORD_PTR
)pLVCD
->nmcd
.dwItemSpec
)
3917 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3918 CTGitPath
*entry
=(CTGitPath
*)GetItemData((int)pLVCD
->nmcd
.dwItemSpec
);
3924 // black : unversioned, normal
3927 // brown : missing, deleted, replaced
3928 // green : merged (or potential merges)
3929 // red : conflicts or sure conflicts
3930 if(entry
->m_Action
& CTGitPath::LOGACTIONS_GRAY
)
3932 crText
= RGB(128,128,128);
3934 }else if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
3936 crText
= m_Colors
.GetColor(CColors::Conflict
);
3938 }else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_MODIFIED
))
3940 crText
= m_Colors
.GetColor(CColors::Modified
);
3942 }else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
3944 crText
= m_Colors
.GetColor(CColors::Added
);
3946 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3948 crText
= m_Colors
.GetColor(CColors::DeletedNode
);
3950 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
3952 crText
= m_Colors
.GetColor(CColors::RenamedNode
);
3953 }else if(entry
->m_Action
& CTGitPath::LOGACTIONS_MERGED
)
3955 crText
= m_Colors
.GetColor(CColors::Merged
);
3958 crText
= GetSysColor(COLOR_WINDOWTEXT
);
3960 // Store the color back in the NMLVCUSTOMDRAW struct.
3961 pLVCD
->clrText
= crText
;
3968 BOOL
CGitStatusListCtrl::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
3971 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3974 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
3976 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3978 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_WAIT
));
3983 void CGitStatusListCtrl::RemoveListEntry(int index
)
3986 Locker
lock(m_critSec
);
3989 m_arStatusArray
.erase(m_arStatusArray
.begin()+index
);
3992 delete m_arStatusArray
[m_arListArray
[index
]];
3993 m_arStatusArray
.erase(m_arStatusArray
.begin()+m_arListArray
[index
]);
3994 m_arListArray
.erase(m_arListArray
.begin()+index
);
3995 for (int i
=index
; i
< (int)m_arListArray
.size(); ++i
)
4002 ///< Set a checkbox on an entry in the listbox
4003 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
4004 void CGitStatusListCtrl::SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
)
4006 pEntry
->m_Checked
= bCheck
;
4007 SetCheck(listboxIndex
, bCheck
);
4011 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry
* parentEntry
, bool bCheck
)
4014 int nListItems
= GetItemCount();
4015 for (int j
=0; j
< nListItems
; ++j
)
4017 FileEntry
* childEntry
= GetListEntry(j
);
4018 ASSERT(childEntry
!= NULL
);
4019 if (childEntry
== NULL
|| childEntry
== parentEntry
)
4021 if (childEntry
->checked
!= bCheck
)
4023 if (parentEntry
->path
.IsAncestorOf(childEntry
->path
))
4025 SetEntryCheck(childEntry
,j
,bCheck
);
4041 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList
& pathList
)
4045 int nListItems
= GetItemCount();
4046 for (int i
=0; i
< nListItems
; i
++)
4048 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
4049 ASSERT(entry
!= NULL
);
4050 if (entry
->m_Checked
)
4052 pathList
.AddPath(*entry
);
4055 pathList
.SortByPathname();
4060 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
4061 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool /*bNoIgnored*/)
4065 POSITION pos
= GetFirstSelectedItemPosition();
4067 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4069 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
4070 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
4072 pathList
.AddPath(*entry
);
4076 UINT
CGitStatusListCtrl::OnGetDlgCode()
4078 // we want to process the return key and not have that one
4079 // routed to the default pushbutton
4080 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS
;
4083 void CGitStatusListCtrl::OnNMReturn(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
4088 POSITION pos
= GetFirstSelectedItemPosition();
4091 int index
= GetNextSelectedItem(pos
);
4092 CTGitPath
*file
=(CTGitPath
*)GetItemData(index
);
4093 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
) {
4094 OpenFile(file
, OPEN
);
4101 void CGitStatusListCtrl::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
4103 // Since we catch all keystrokes (to have the enter key processed here instead
4104 // of routed to the default pushbutton) we have to make sure that other
4105 // keys like Tab and Esc still do what they're supposed to do
4106 // Tab = change focus to next/previous control
4107 // Esc = quit the dialog
4112 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL
, GetKeyState(VK_SHIFT
)&0x8000, 0);
4118 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE
, 0, 0);
4123 CListCtrl::OnKeyDown(nChar
, nRepCnt
, nFlags
);
4126 void CGitStatusListCtrl::PreSubclassWindow()
4128 CListCtrl::PreSubclassWindow();
4129 EnableToolTips(TRUE
);
4130 m_Theme
.SetWindowTheme(GetSafeHwnd(), L
"Explorer", NULL
);
4133 INT_PTR
CGitStatusListCtrl::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4137 row
= CellRectFromPoint(point
, &cellrect
, &col
);
4144 pTI
->uId
= (UINT
)((row
<<10)+(col
&0x3ff)+1);
4145 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4147 pTI
->rect
= cellrect
;
4152 int CGitStatusListCtrl::CellRectFromPoint(CPoint
& point
, RECT
*cellrect
, int *col
) const
4156 // Make sure that the ListView is in LVS_REPORT
4157 if ((GetWindowLong(m_hWnd
, GWL_STYLE
) & LVS_TYPEMASK
) != LVS_REPORT
)
4160 // Get the top and bottom row visible
4161 int row
= GetTopIndex();
4162 int bottom
= row
+ GetCountPerPage();
4163 if (bottom
> GetItemCount())
4164 bottom
= GetItemCount();
4166 // Get the number of columns
4167 CHeaderCtrl
* pHeader
= (CHeaderCtrl
*)GetDlgItem(0);
4168 int nColumnCount
= pHeader
->GetItemCount();
4170 // Loop through the visible rows
4171 for ( ;row
<=bottom
;row
++)
4173 // Get bounding rect of item and check whether point falls in it.
4175 GetItemRect(row
, &rect
, LVIR_BOUNDS
);
4176 if (rect
.PtInRect(point
))
4178 // Now find the column
4179 for (colnum
= 0; colnum
< nColumnCount
; colnum
++)
4181 int colwidth
= GetColumnWidth(colnum
);
4182 if (point
.x
>= rect
.left
&& point
.x
<= (rect
.left
+ colwidth
))
4185 GetClientRect(&rectClient
);
4188 rect
.right
= rect
.left
+ colwidth
;
4190 // Make sure that the right extent does not exceed
4192 if (rect
.right
> rectClient
.right
)
4193 rect
.right
= rectClient
.right
;
4197 rect
.left
+= colwidth
;
4204 BOOL
CGitStatusListCtrl::OnToolTipText(UINT
/*id*/, NMHDR */
*pNMHDR*/
, LRESULT */
*pResult*/
)
4207 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4209 UINT_PTR nID
= pNMHDR
->idFrom
;
4214 UINT_PTR row
= ((nID
-1) >> 10) & 0x3fffff;
4215 UINT_PTR col
= (nID
-1) & 0x3ff;
4218 return FALSE
; // no custom tooltip for the path, we use the infotip there!
4220 // get the internal column from the visible columns
4221 int internalcol
= 0;
4222 UINT_PTR currentcol
= 0;
4223 for (; (currentcol
!= col
)
4224 && (internalcol
< m_ColumnManager
.GetColumnCount()-1)
4227 if (m_ColumnManager
.IsVisible (internalcol
))
4231 AFX_MODULE_THREAD_STATE
* pModuleThreadState
= AfxGetModuleThreadState();
4232 CToolTipCtrl
* pToolTip
= pModuleThreadState
->m_pToolTip
;
4233 pToolTip
->SendMessage(TTM_SETMAXTIPWIDTH
, 0, 300);
4236 if ((internalcol
== 2)||(internalcol
== 4))
4238 FileEntry
*fentry
= GetListEntry(row
);
4244 url
.Format(IDS_STATUSLIST_COPYFROM
, (LPCTSTR
)CPathUtils::PathUnescape(fentry
->copyfrom_url
), (LONG
)fentry
->copyfrom_rev
);
4245 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)url
, 80);
4248 if (fentry
->switched
)
4251 url
.Format(IDS_STATUSLIST_SWITCHEDTO
, (LPCTSTR
)CPathUtils::PathUnescape(fentry
->url
));
4252 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)url
, 80);
4255 if (fentry
->keeplocal
)
4257 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_KEEPLOCAL
)), 80);
4266 void CGitStatusListCtrl::OnPaint()
4269 if ((m_bBusy
)||(m_bEmpty
))
4274 if (m_sBusy
.IsEmpty())
4275 str
.LoadString(IDS_STATUSLIST_BUSYMSG
);
4281 if (m_sEmpty
.IsEmpty())
4282 str
.LoadString(IDS_STATUSLIST_EMPTYMSG
);
4286 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
4288 if (IsWindowEnabled())
4289 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
4291 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
4296 pHC
= GetHeaderCtrl();
4300 pHC
->GetItemRect(0, &rcH
);
4301 rc
.top
+= rcH
.bottom
;
4305 CMyMemDC
memDC(pDC
, &rc
);
4307 memDC
.SetTextColor(clrText
);
4308 memDC
.SetBkColor(clrTextBk
);
4309 memDC
.FillSolidRect(rc
, clrTextBk
);
4311 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
4312 memDC
.DrawText(str
, rc
, DT_CENTER
| DT_VCENTER
|
4313 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
4314 memDC
.SelectObject(oldfont
);
4320 // prevent users from extending our hidden (size 0) columns
4321 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4323 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
4326 // prevent any function from extending our hidden (size 0) columns
4327 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4329 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
4333 void CGitStatusListCtrl::OnDestroy()
4335 SaveColumnWidths(true);
4336 CListCtrl::OnDestroy();
4339 void CGitStatusListCtrl::OnBeginDrag(NMHDR
* /*pNMHDR*/, LRESULT
* pResult
)
4342 Locker
lock(m_critSec
);
4343 CDropFiles dropFiles
; // class for creating DROPFILES struct
4346 POSITION pos
= GetFirstSelectedItemPosition();
4347 while ( (index
= GetNextSelectedItem(pos
)) >= 0 )
4349 FileEntry
* fentry
= m_arStatusArray
[m_arListArray
[index
]];
4350 CTGitPath path
= fentry
->GetPath();
4351 dropFiles
.AddFile( path
.GetWinPathString() );
4354 if ( dropFiles
.GetCount()>0 )
4357 dropFiles
.CreateStructure();
4364 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry
/* = false */)
4366 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
4367 for (int col
= 0; col
<= maxcol
; col
++)
4368 if (m_ColumnManager
.IsVisible (col
))
4369 m_ColumnManager
.ColumnResized (col
);
4371 if (bSaveToRegistry
)
4372 m_ColumnManager
.WriteSettings();
4375 bool CGitStatusListCtrl::EnableFileDrop()
4377 m_bFileDropsEnabled
= true;
4381 bool CGitStatusListCtrl::HasPath(const CTGitPath
& path
)
4383 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
4385 if (m_arStatusArray
[i
]->IsEquivalentTo(path
))
4392 BOOL
CGitStatusListCtrl::PreTranslateMessage(MSG
* pMsg
)
4394 if (pMsg
->message
== WM_KEYDOWN
)
4396 switch (pMsg
->wParam
)
4400 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
4402 // select all entries
4403 for (int i
=0; i
<GetItemCount(); ++i
)
4405 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
4414 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
4416 // copy all selected paths to the clipboard
4417 if (GetAsyncKeyState(VK_SHIFT
)&0x8000)
4418 CopySelectedEntriesToClipboard(SVNSLC_COLSTATUS
);
4420 CopySelectedEntriesToClipboard(0);
4428 return CListCtrl::PreTranslateMessage(pMsg
);
4431 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols
)
4434 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
4435 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
4436 // WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4441 if (GetSelectedCount() == 0)
4444 // first add the column titles as the first line
4445 // We needn't head when only path copy
4446 //temp.LoadString(IDS_STATUSLIST_COLFILE);
4447 //sClipboard = temp;
4449 DWORD selection
= 0;
4450 for (int i
= 0, count
= m_ColumnManager
.GetColumnCount(); i
< count
; ++i
)
4451 if ( ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
4452 || ((dwCols
!= 1) && (i
< 32) && ((dwCols
& (1 << i
)) != 0)))
4454 sClipboard
+= _T("\t") + m_ColumnManager
.GetName(i
);
4457 selection
+= 1 << i
;
4461 sClipboard
+= _T("\r\n");
4463 POSITION pos
= GetFirstSelectedItemPosition();
4465 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4467 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
4471 sClipboard
+= entry
->GetWinPathString();
4472 if (selection
& SVNSLC_COLFILENAME
)
4474 sClipboard
+= _T("\t")+entry
->GetFileOrDirectoryName();
4476 if (selection
& SVNSLC_COLEXT
)
4478 sClipboard
+= _T("\t")+entry
->GetFileExtension();
4481 if (selection
& SVNSLC_COLSTATUS
)
4484 if (entry
->isNested
)
4486 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4490 GitStatus::GetStatusString(hResourceHandle
, entry
->status
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4491 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4492 _tcscat_s(buf
, 100, _T(" (+)"));
4493 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4494 _tcscat_s(buf
, 100, _T(" (s)"));
4495 if ((entry
->status
== entry
->propstatus
)&&
4496 (entry
->status
!= git_wc_status_normal
)&&
4497 (entry
->status
!= git_wc_status_unversioned
)&&
4498 (!GitStatus::IsImportant(entry
->textstatus
)))
4499 _tcscat_s(buf
, 100, ponly
);
4503 sClipboard
+= _T("\t")+entry
->GetActionName();
4506 if (selection
& SVNSLC_COLTEXTSTATUS
)
4509 if (entry
->isNested
)
4511 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4515 GitStatus::GetStatusString(hResourceHandle
, entry
->textstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4516 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4517 _tcscat_s(buf
, 100, _T(" (+)"));
4518 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4519 _tcscat_s(buf
, 100, _T(" (s)"));
4522 sClipboard
+= _T("\t")+temp
;
4526 if (selection
& SVNSLC_COLREMOTESTATUS
)
4528 if (entry
->isNested
)
4530 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4534 GitStatus::GetStatusString(hResourceHandle
, entry
->remotestatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4535 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4536 _tcscat_s(buf
, 100, _T(" (+)"));
4537 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4538 _tcscat_s(buf
, 100, _T(" (s)"));
4539 if ((entry
->remotestatus
== entry
->remotepropstatus
)&&
4540 (entry
->remotestatus
!= git_wc_status_none
)&&
4541 (entry
->remotestatus
!= git_wc_status_normal
)&&
4542 (entry
->remotestatus
!= git_wc_status_unversioned
)&&
4543 (!SVNStatus::IsImportant(entry
->remotetextstatus
)))
4544 _tcscat_s(buf
, 100, ponly
);
4547 sClipboard
+= _T("\t")+temp
;
4549 if (selection
& GitSLC_COLPROPSTATUS
)
4551 if (entry
->isNested
)
4557 GitStatus::GetStatusString(hResourceHandle
, entry
->propstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4558 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4559 _tcscat_s(buf
, 100, _T(" (+)"));
4560 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4561 _tcscat_s(buf
, 100, _T(" (s)"));
4564 sClipboard
+= _T("\t")+temp
;
4566 if (selection
& SVNSLC_COLREMOTETEXT
)
4568 if (entry
->isNested
)
4574 GitStatus::GetStatusString(hResourceHandle
, entry
->remotetextstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4577 sClipboard
+= _T("\t")+temp
;
4579 if (selection
& SVNSLC_COLREMOTEPROP
)
4581 // SVNSLC_COLREMOTEPROP
4582 if (entry
->isNested
)
4588 GitStatus::GetStatusString(hResourceHandle
, entry
->remotepropstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4591 sClipboard
+= _T("\t")+temp
;
4593 if (selection
& SVNSLC_COLURL
)
4594 sClipboard
+= _T("\t")+entry
->url
;
4595 if (selection
& SVNSLC_COLLOCK
)
4597 if (!m_HeadRev
.IsHead())
4599 // we have contacted the repository
4602 // wc repository text
4606 // UID1 "" lock has been broken
4607 // UID1 UID2 lock has been stolen
4608 if (entry
->lock_token
.IsEmpty() || (entry
->lock_token
.Compare(entry
->lock_remotetoken
)==0))
4610 if (entry
->lock_owner
.IsEmpty())
4611 temp
= entry
->lock_remoteowner
;
4613 temp
= entry
->lock_owner
;
4615 else if (entry
->lock_remotetoken
.IsEmpty())
4618 temp
.LoadString(IDS_STATUSLIST_LOCKBROKEN
);
4623 temp
.Format(IDS_STATUSLIST_LOCKSTOLEN
, (LPCTSTR
)entry
->lock_remoteowner
);
4627 temp
= entry
->lock_owner
;
4628 sClipboard
+= _T("\t")+temp
;
4630 if (selection
& SVNSLC_COLLOCKCOMMENT
)
4631 sClipboard
+= _T("\t")+entry
->lock_comment
;
4632 if (selection
& SVNSLC_COLAUTHOR
)
4633 sClipboard
+= _T("\t")+entry
->last_commit_author
;
4634 if (selection
& SVNSLC_COLREVISION
)
4636 temp
.Format(_T("%ld"), entry
->last_commit_rev
);
4637 if (entry
->last_commit_rev
== 0)
4639 sClipboard
+= _T("\t")+temp
;
4641 if (selection
& SVNSLC_COLREMOTEREVISION
)
4643 temp
.Format(_T("%ld"), entry
->remoterev
);
4644 if (entry
->remoterev
== 0)
4646 sClipboard
+= _T("\t")+temp
;
4649 if (selection
& SVNSLC_COLDATE
)
4651 TCHAR datebuf
[SVN_DATE_BUFFER
];
4652 apr_time_t date
= entry
->last_commit_date
;
4653 SVN::formatDate(datebuf
, date
, true);
4658 sClipboard
+= _T("\t")+temp
;
4660 if (selection
& SVNSLC_COLCOPYFROM
)
4662 if (m_sURL
.Compare(entry
->copyfrom_url
.Left(m_sURL
.GetLength()))==0)
4663 temp
= entry
->copyfrom_url
.Mid(m_sURL
.GetLength());
4665 temp
= entry
->copyfrom_url
;
4666 sClipboard
+= _T("\t")+temp
;
4669 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
4673 if ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
4676 = entry
->present_props
[m_ColumnManager
.GetName(i
)];
4677 sClipboard
+= _T("\t") + value
;
4681 if (selection
& SVNSLC_COLADD
)
4683 sClipboard
+= _T("\t")+entry
->m_StatAdd
;
4685 if (selection
& SVNSLC_COLDEL
)
4687 sClipboard
+= _T("\t")+entry
->m_StatDel
;
4690 sClipboard
+= _T("\r\n");
4693 return CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
4699 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
4702 std::set
<CString
> changelists
;
4703 POSITION pos
= GetFirstSelectedItemPosition();
4705 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4707 FileEntry
* entry
= GetListEntry(index
);
4708 if (!entry
->changelist
.IsEmpty())
4709 changelists
.insert(entry
->changelist
);
4711 return changelists
.size();
4716 bool CGitStatusListCtrl::PrepareGroups(bool bForce
/* = false */)
4719 bool bHasGroups
=false;
4722 for(int i
=0;i
< this->m_arStatusArray
.size(); i
++)
4724 int ParentNo
= m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
4726 max
=m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
4729 if ( this->m_UnRevFileList
.GetCount()>0 ||
4730 this->m_IgnoreFileList
.GetCount()>0 ||
4737 EnableGroupView(bHasGroups
);
4739 TCHAR groupname
[1024];
4745 grp
.cbSize
= sizeof(LVGROUP
);
4746 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4749 //if(m_UnRevFileList.GetCount()>0)
4752 grp
.pszHeader
= _T("Merged Files");
4753 grp
.iGroupId
= MERGE_MASK
;
4754 grp
.uAlign
= LVGA_HEADER_LEFT
;
4755 InsertGroup(0, &grp
);
4757 for(int i
=0;i
<=max
;i
++)
4760 str
.Format(_T("Diff with %d Parent"), i
+1);
4761 //_tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Not Versioned"), 1023);
4762 grp
.pszHeader
= str
.GetBuffer();
4764 grp
.uAlign
= LVGA_HEADER_LEFT
;
4765 InsertGroup(i
+1, &grp
);
4769 CString
sUnassignedName(_T("Modified File"));
4770 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
4771 grp
.pszHeader
= groupname
;
4772 grp
.iGroupId
= groupindex
;
4773 grp
.uAlign
= LVGA_HEADER_LEFT
;
4774 InsertGroup(groupindex
++, &grp
);
4778 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)_T("Not Versioned"), 1023);
4779 grp
.pszHeader
= groupname
;
4780 grp
.iGroupId
= groupindex
;
4781 grp
.uAlign
= LVGA_HEADER_LEFT
;
4782 InsertGroup(groupindex
++, &grp
);
4785 //if(m_IgnoreFileList.GetCount()>0)
4787 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)_T("Ignored"), 1023);
4788 grp
.pszHeader
= groupname
;
4789 grp
.iGroupId
= groupindex
;
4790 grp
.uAlign
= LVGA_HEADER_LEFT
;
4791 InsertGroup(groupindex
++, &grp
);
4797 m_bHasIgnoreGroup
= false;
4799 // now add the items which don't belong to a group
4801 grp
.cbSize
= sizeof(LVGROUP
);
4802 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4803 CString
sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET
));
4804 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
4805 grp
.pszHeader
= groupname
;
4806 grp
.iGroupId
= groupindex
;
4807 grp
.uAlign
= LVGA_HEADER_LEFT
;
4808 InsertGroup(groupindex
++, &grp
);
4810 for (std::map
<CString
,int>::iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
4812 if (it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)!=0)
4815 grp
.cbSize
= sizeof(LVGROUP
);
4816 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4817 _tcsncpy_s(groupname
, 1024, it
->first
, 1023);
4818 grp
.pszHeader
= groupname
;
4819 grp
.iGroupId
= groupindex
;
4820 grp
.uAlign
= LVGA_HEADER_LEFT
;
4821 it
->second
= InsertGroup(groupindex
++, &grp
);
4824 m_bHasIgnoreGroup
= true;
4827 if (m_bHasIgnoreGroup
)
4829 // and now add the group 'ignore-on-commit'
4830 std::map
<CString
,int>::iterator it
= m_changelists
.find(SVNSLC_IGNORECHANGELIST
);
4831 if (it
!= m_changelists
.end())
4833 grp
.cbSize
= sizeof(LVGROUP
);
4834 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4835 _tcsncpy_s(groupname
, 1024, SVNSLC_IGNORECHANGELIST
, 1023);
4836 grp
.pszHeader
= groupname
;
4837 grp
.iGroupId
= groupindex
;
4838 grp
.uAlign
= LVGA_HEADER_LEFT
;
4839 it
->second
= InsertGroup(groupindex
, &grp
);
4846 void CGitStatusListCtrl::NotifyCheck()
4848 CWnd
* pParent
= GetParent();
4849 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
4851 pParent
->SendMessage(SVNSLNM_CHECKCHANGED
, m_nSelected
);
4855 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash
,CTGitPathList
*list
)
4859 m_CurrentVersion
=hash
;
4865 count
= list
->GetCount();
4867 if(hash
== GIT_REV_ZERO
)
4869 for(int i
=0;i
<count
;i
++)
4874 if(!g_Git
.IsInitRepos())
4877 cmd
=(_T("git.exe diff-index --raw HEAD --numstat -C -M -z"));
4879 cmd
.Format(_T("git.exe diff-index --raw HEAD --numstat -C -M -z -- \"%s\""),(*list
)[i
].GetGitPathString());
4881 if(g_Git
.Run(cmd
,&cmdout
))
4883 int last
= cmdout
.RevertFind(0,-1);
4887 g_Git
.StringAppend(&str
, &cmdout
[last
+1], CP_ACP
,cmdout
.size()-last
-1);
4888 CMessageBox::Show(NULL
,str
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
4889 cmdout
.resize(last
+1);
4895 if(g_Git
.Run(_T("git.exe rev-parse --revs-only HEAD"),&strout
,CP_UTF8
))
4897 CMessageBox::Show(NULL
,strout
,_T("TortoiseGit"),MB_OK
);
4900 if(strout
.IsEmpty())
4901 break; //this is initial repositoyr, there are no any history
4903 CMessageBox::Show(NULL
,strout
,_T("TortoiseGit"),MB_OK
);
4909 //We will list all stage file anyway because commit will commit thats
4910 cmd
=(_T("git.exe diff-index --cached --raw HEAD --numstat -C -M -z"));
4912 // cmd.Format(_T("git.exe diff-index --cached --raw HEAD --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
4914 g_Git
.Run(cmd
,&cmdout
);
4916 out
.append(cmdout
,0);
4918 else // Init Repository
4920 //We will list all added file for init repository because commit will comit these
4922 cmd
=_T("git.exe ls-files -s -t -z");
4924 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
4926 g_Git
.Run(cmd
,&cmdout
);
4928 out
.append(cmdout
,0);
4932 if(g_Git
.IsInitRepos())
4934 m_StatusFileList
.ParserFromLsFile(out
);
4935 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
4936 ((CTGitPath
&)(m_StatusFileList
[i
])).m_Action
=CTGitPath::LOGACTIONS_ADDED
;
4939 this->m_StatusFileList
.ParserFromLog(out
);
4941 //handle delete conflict case, when remote : modified, local : deleted.
4942 for(int i
=0;i
<count
;i
++)
4948 cmd
=_T("git.exe ls-files -u -t -z");
4950 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list
)[i
].GetGitPathString());
4952 g_Git
.Run(cmd
,&cmdout
);
4954 CTGitPathList conflictlist
;
4955 conflictlist
.ParserFromLog(cmdout
);
4956 for(int i
=0;i
<conflictlist
.GetCount();i
++)
4958 CTGitPath
*p
=m_StatusFileList
.LookForGitPath(conflictlist
[i
].GetGitPathString());
4960 p
->m_Action
|=CTGitPath::LOGACTIONS_UNMERGED
;
4962 m_StatusFileList
.AddPath(conflictlist
[i
]);
4972 count
= list
->GetCount();
4974 for(int i
=0;i
<count
;i
++)
4979 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash
);
4981 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash
,(*list
)[i
].GetGitPathString());
4983 g_Git
.Run(cmd
,&cmdout
);
4987 this->m_StatusFileList
.ParserFromLog(out
);
4991 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
4993 CTGitPath
* gitpatch
=(CTGitPath
*)&m_StatusFileList
[i
];
4994 gitpatch
->m_Checked
= TRUE
;
4995 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
4998 this->m_bBusy
=FALSE
;
5002 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList
&list
)
5004 m_arStatusArray
.clear();
5005 for(int i
=0;i
<list
.GetCount();i
++)
5007 CTGitPath
* gitpath
=(CTGitPath
*)&list
[i
];
5009 if(gitpath
->m_Action
& CTGitPath::LOGACTIONS_HIDE
)
5012 gitpath
->m_Checked
= TRUE
;
5013 m_arStatusArray
.push_back((CTGitPath
*)&list
[i
]);
5018 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
*List
)
5020 this->m_UnRevFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
,List
);
5021 for(int i
=0;i
<m_UnRevFileList
.GetCount();i
++)
5023 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
5024 gitpatch
->m_Checked
= FALSE
;
5025 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
5030 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList
*List
)
5032 this->m_IgnoreFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
|CTGitPath::LOGACTIONS_IGNORE
,List
);
5033 for(int i
=0;i
<m_IgnoreFileList
.GetCount();i
++)
5035 CTGitPath
* gitpatch
=(CTGitPath
*)&m_IgnoreFileList
[i
];
5036 gitpatch
->m_Checked
= FALSE
;
5037 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
5041 int CGitStatusListCtrl::UpdateFileList(int mask
,bool once
,CTGitPathList
*List
)
5043 if(mask
&CGitStatusListCtrl::FILELIST_MODIFY
)
5045 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_MODIFY
)))
5047 UpdateFileList(git_revnum_t(GIT_REV_ZERO
),List
);
5048 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_MODIFY
;
5051 if(mask
&CGitStatusListCtrl::FILELIST_UNVER
)
5053 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_UNVER
)))
5055 UpdateUnRevFileList(List
);
5056 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
5062 void CGitStatusListCtrl::Clear()
5065 this->DeleteAllItems();
5066 this->m_arListArray
.clear();
5067 this->m_arStatusArray
.clear();
5068 this->m_changelists
.clear();
5070 //////////////////////////////////////////////////////////////////////////
5072 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
)
5074 if(pFmtEtc
->cfFormat
== CF_HDROP
&& medium
.tymed
== TYMED_HGLOBAL
)
5076 HDROP hDrop
= (HDROP
)GlobalLock(medium
.hGlobal
);
5079 TCHAR szFileName
[MAX_PATH
];
5081 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, NULL
, 0);
5084 clientpoint
.x
= pt
.x
;
5085 clientpoint
.y
= pt
.y
;
5086 ScreenToClient(m_hTargetWnd
, &clientpoint
);
5087 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
5089 CTSVNPathList changelistItems
;
5090 for(UINT i
= 0; i
< cFiles
; ++i
)
5092 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
5093 changelistItems
.AddPath(CTSVNPath(szFileName
));
5095 // find the changelist name
5096 CString sChangelist
;
5097 LONG_PTR nGroup
= m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
);
5098 for (std::map
<CString
, int>::iterator it
= m_pSVNStatusListCtrl
->m_changelists
.begin(); it
!= m_pSVNStatusListCtrl
->m_changelists
.end(); ++it
)
5099 if (it
->second
== nGroup
)
5100 sChangelist
= it
->first
;
5101 if (!sChangelist
.IsEmpty())
5104 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
5106 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
5108 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
5111 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
5114 e
->changelist
= sChangelist
;
5117 if (m_pSVNStatusListCtrl
->m_changelists
.find(e
->changelist
)!=m_pSVNStatusListCtrl
->m_changelists
.end())
5118 m_pSVNStatusListCtrl
->SetItemGroup(index
, m_pSVNStatusListCtrl
->m_changelists
[e
->changelist
]);
5120 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
5126 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5127 if (hParentWnd
!= NULL
)
5128 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
5134 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
5140 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
5142 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
5144 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
5147 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
5150 e
->changelist
= sChangelist
;
5151 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
5156 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5157 if (hParentWnd
!= NULL
)
5158 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
5164 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
5170 for(UINT i
= 0; i
< cFiles
; ++i
)
5172 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
5173 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5174 if (hParentWnd
!= NULL
)
5175 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)szFileName
);
5179 GlobalUnlock(medium
.hGlobal
);
5181 return true; //let base free the medium
5183 HRESULT STDMETHODCALLTYPE
CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
)
5185 CIDropTarget::DragOver(grfKeyState
, pt
, pdwEffect
);
5186 *pdwEffect
= DROPEFFECT_COPY
;
5187 if (m_pSVNStatusListCtrl
)
5190 clientpoint
.x
= pt
.x
;
5191 clientpoint
.y
= pt
.y
;
5192 ScreenToClient(m_hTargetWnd
, &clientpoint
);
5193 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
5195 *pdwEffect
= DROPEFFECT_MOVE
;
5197 else if ((!m_pSVNStatusListCtrl
->m_bFileDropsEnabled
)||(m_pSVNStatusListCtrl
->m_bOwnDrag
))
5199 *pdwEffect
= DROPEFFECT_NONE
;
5207 void CGitStatusListCtrl::FileSaveAs(CTGitPath
*path
)
5210 filename
.Format(_T("%s-%s%s"),path
->GetBaseFilename(),this->m_CurrentVersion
.Left(6),path
->GetFileExtension());
5211 CFileDialog
dlg(FALSE
,NULL
,
5213 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
5215 CString currentpath
;
5216 currentpath
=g_Git
.m_CurrentDir
+_T("\\");
5217 currentpath
+=path
->GetWinPathString();
5219 dlg
.m_ofn
.lpstrInitialDir
=currentpath
.GetBuffer();
5222 if(dlg
.DoModal()==IDOK
)
5224 filename
= dlg
.GetPathName();
5225 if(m_CurrentVersion
== GIT_REV_ZERO
)
5227 if(!CopyFile(g_Git
.m_CurrentDir
+_T("\\") + path
->GetWinPath(),filename
,false))
5229 LPVOID lpMsgBuf
=NULL
;
5230 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
5231 NULL
,GetLastError(),MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
5234 CMessageBox::Show(NULL
,(TCHAR
*)lpMsgBuf
,_T("TortoiseGit"),MB_OK
);
5235 LocalFree(lpMsgBuf
);
5241 if(g_Git
.GetOneFile(m_CurrentVersion
,*path
,filename
))
5243 out
.Format(_T("Fail checkout one file %s;%s"),m_CurrentVersion
, path
->GetWinPath());
5244 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5252 int CGitStatusListCtrl::RevertSelectedItemToVersion()
5254 if(this->m_CurrentVersion
.IsEmpty())
5256 if(this->m_CurrentVersion
== GIT_REV_ZERO
)
5259 POSITION pos
= GetFirstSelectedItemPosition();
5263 while ((index
= GetNextSelectedItem(pos
)) >= 0)
5265 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
5266 cmd
.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion
,fentry
->GetGitPathString());
5268 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
5270 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5275 out
.Format(_T("%d files revert to %s"),count
,m_CurrentVersion
.Left(6));
5276 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5280 void CGitStatusListCtrl::OpenFile(CTGitPath
*filepath
,int mode
)
5283 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
5285 file
= filepath
->GetWinPath();
5289 GetTempPath(temppath
);
5290 file
.Format(_T("%s%s_%s%s"),
5292 filepath
->GetBaseFilename(),
5293 m_CurrentVersion
.Left(6),
5294 filepath
->GetFileExtension());
5296 if(g_Git
.GetOneFile(m_CurrentVersion
, *filepath
, file
))
5298 out
.Format(_T("Fail checkout file %s to %s\n"), filepath
->GetGitPathString(), file
);
5299 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5304 if(mode
== ALTERNATIVEEDITOR
)
5306 CAppUtils::LaunchAlternativeEditor(file
);
5309 int ret
= HINSTANCE_ERROR
;
5313 ret
= (int)ShellExecute(this->m_hWnd
, NULL
,file
, NULL
, NULL
, SW_SHOW
);
5315 if (ret
> HINSTANCE_ERROR
)
5322 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
5324 CAppUtils::LaunchApplication(cmd
, NULL
, false);