1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
5 // Copyright (C) 2010-2011 Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "..\\TortoiseShell\resource.h"
25 #include "GitStatusListCtrl.h"
26 #include "MessageBox.h"
28 #include "UnicodeUtils.h"
30 #include "PathUtils.h"
32 #include "StringUtils.h"
33 #include "DirFileEnum.h"
34 #include "GitConfig.h"
35 //#include "SVNProperties.h"
39 //#include "SVNProgressDlg.h"
40 #include "SysImageList.h"
41 //#include "Svnstatuslistctrl.h"
44 #include "GitStatus.h"
45 //#include "SVNHelpers.h"
47 #include "ShellUpdater.h"
48 #include "GitAdminDir.h"
49 //#include "DropFiles.h"
52 //#include "EditPropertiesDlg.h"
53 //#include "CreateChangelistDlg.h"
55 #include "CommonResource.h"
58 const UINT
CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED
59 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
60 const UINT
CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH
61 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
62 const UINT
CGitStatusListCtrl::SVNSLNM_ADDFILE
63 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
64 const UINT
CGitStatusListCtrl::SVNSLNM_CHECKCHANGED
65 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
66 const UINT
CGitStatusListCtrl::SVNSLNM_ITEMCHANGED
67 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCHANGED"));
72 BEGIN_MESSAGE_MAP(CGitStatusListCtrl
, CListCtrl
)
73 ON_NOTIFY(HDN_ITEMCLICKA
, 0, OnHdnItemclick
)
74 ON_NOTIFY(HDN_ITEMCLICKW
, 0, OnHdnItemclick
)
75 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
76 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
77 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED
, OnLvnItemchanged
)
79 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclk
)
80 ON_NOTIFY_REFLECT(LVN_GETINFOTIP
, OnLvnGetInfoTip
)
81 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdraw
)
84 ON_NOTIFY_REFLECT(NM_RETURN
, OnNMReturn
)
86 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, OnToolTipText
)
87 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, OnToolTipText
)
89 ON_NOTIFY(HDN_BEGINTRACKA
, 0, &CGitStatusListCtrl::OnHdnBegintrack
)
90 ON_NOTIFY(HDN_BEGINTRACKW
, 0, &CGitStatusListCtrl::OnHdnBegintrack
)
91 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, &CGitStatusListCtrl::OnHdnItemchanging
)
92 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, &CGitStatusListCtrl::OnHdnItemchanging
)
94 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnBeginDrag
)
95 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING
, &CGitStatusListCtrl::OnLvnItemchanging
)
100 CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl()
101 //, m_HeadRev(GitRev::REV_HEAD)
104 , m_pSelectButton(NULL
)
105 , m_pConfirmButton(NULL
)
108 , m_bUnversionedRecurse(true)
109 , m_bShowIgnores(false)
110 , m_pDropTarget(NULL
)
111 , m_bIgnoreRemoveOnly(false)
112 , m_bCheckChildrenWithParent(false)
113 , m_bUnversionedLast(true)
114 , m_bHasChangeLists(false)
118 , m_bHasCheckboxes(false)
119 , m_bCheckIfGroupsExist(true)
120 , m_bFileDropsEnabled(false)
122 , m_dwDefaultColumns(0)
123 , m_ColumnManager(this)
124 , m_bAscending(false)
125 , m_nSortedColumn(-1)
126 , m_bHasExternalsFromDifferentRepos(false)
127 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE
))
129 , m_bDoNotAutoselectSubmodules(false)
133 m_bIsRevertTheirMy
= false;
134 this->m_nLineAdded
=this->m_nLineDeleted
=0;
137 CGitStatusListCtrl::~CGitStatusListCtrl()
139 // if (m_pDropTarget)
140 // delete m_pDropTarget;
144 void CGitStatusListCtrl::ClearStatusArray()
147 Locker
lock(m_critSec
);
148 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
150 delete m_arStatusArray
[i
];
152 m_arStatusArray
.clear();
156 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetListEntry(UINT_PTR index
)
159 if (index
>= (UINT_PTR
)m_arListArray
.size())
161 if (m_arListArray
[index
] >= m_arStatusArray
.size())
163 return m_arStatusArray
[m_arListArray
[index
]];
169 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetVisibleListEntry(const CTGitPath
& path
)
171 int itemCount
= GetItemCount();
172 for (int i
=0; i
< itemCount
; i
++)
174 FileEntry
* entry
= GetListEntry(i
);
175 if (entry
->GetPath().IsEquivalentTo(path
))
182 CGitStatusListCtrl::FileEntry
* CGitStatusListCtrl::GetListEntry(const CTGitPath
& path
)
185 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
187 FileEntry
* entry
= m_arStatusArray
[i
];
188 if (entry
->GetPath().IsEquivalentTo(path
))
197 int CGitStatusListCtrl::GetIndex(const CTGitPath
& path
)
199 int itemCount
= GetItemCount();
200 for (int i
=0; i
< itemCount
; i
++)
202 FileEntry
* entry
= GetListEntry(i
);
203 if (entry
->GetPath().IsEquivalentTo(path
))
210 void CGitStatusListCtrl::Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
/* = GitSLC_POPALL */, bool bHasCheckboxes
/* = true */)
212 Locker
lock(m_critSec
);
214 m_dwDefaultColumns
= dwColumns
| 1;
215 m_dwContextMenus
= dwContextMenus
;
216 m_bHasCheckboxes
= bHasCheckboxes
;
218 // set the extended style of the listcontrol
219 // 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.
220 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
221 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
222 if (DWORD(regFullRowSelect
))
223 exStyle
|= LVS_EX_FULLROWSELECT
;
224 exStyle
|= (bHasCheckboxes
? LVS_EX_CHECKBOXES
: 0);
226 SetExtendedStyle(exStyle
);
229 theme
.SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
231 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
232 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
234 static UINT standardColumnNames
[SVNSLC_NUMCOLUMNS
]
235 = { IDS_STATUSLIST_COLFILE
236 , IDS_STATUSLIST_COLFILENAME
237 , IDS_STATUSLIST_COLEXT
238 , IDS_STATUSLIST_COLSTATUS
239 , IDS_STATUSLIST_COLADD
240 , IDS_STATUSLIST_COLDEL
243 m_ColumnManager
.SetNames(standardColumnNames
,SVNSLC_NUMCOLUMNS
);
244 m_ColumnManager
.ReadSettings (m_dwDefaultColumns
, 0, sColumnInfoContainer
, SVNSLC_NUMCOLUMNS
);
248 if (m_pDropTarget
== NULL
)
250 m_pDropTarget
= new CGitStatusListCtrlDropTarget(this);
251 RegisterDragDrop(m_hWnd
,m_pDropTarget
);
252 // create the supported formats:
254 ftetc
.dwAspect
= DVASPECT_CONTENT
;
256 ftetc
.tymed
= TYMED_HGLOBAL
;
257 ftetc
.cfFormat
=CF_HDROP
;
258 m_pDropTarget
->AddSuportedFormat(ftetc
);
264 m_bUnversionedRecurse
= !!((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE
));
267 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID
)
269 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
272 BOOL
CGitStatusListCtrl::GetStatus ( const CTGitPathList
* pathList
273 , bool bUpdate
/* = FALSE */
274 , bool bShowIgnores
/* = false */
276 , bool /*bShowUserProps*/ /* = false */)
278 Locker
lock(m_critSec
);
279 int mask
= CGitStatusListCtrl::FILELIST_MODIFY
;
281 mask
|= CGitStatusListCtrl::FILELIST_IGNORE
;
283 mask
|= CGitStatusListCtrl::FILELIST_UNVER
;
284 this->UpdateFileList(mask
,bUpdate
,(CTGitPathList
*)pathList
);
288 int refetchcounter
= 0;
291 // force the cursor to change
294 SetCursorPos(pt
.x
, pt
.y
);
296 m_mapFilenameToChecked
.clear();
297 //m_StatusUrlList.Clear();
298 bool bHasChangelists
= (m_changelists
.size()>1 || (m_changelists
.size()>0 && !m_bHasIgnoreGroup
));
299 m_changelists
.clear();
300 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
302 FileEntry
* entry
= m_arStatusArray
[i
];
303 if ( bHasChangelists
&& entry
->checked
)
305 // If change lists are present, remember all checked entries
306 CString path
= entry
->GetPath().GetGitPathString();
307 m_mapFilenameToChecked
[path
] = true;
309 if ( (entry
->status
==git_wc_status_unversioned
|| entry
->status
==git_wc_status_missing
) && entry
->checked
)
311 // The user manually selected an unversioned or missing file. We remember
312 // this so that the selection can be restored when refreshing.
313 CString path
= entry
->GetPath().GetGitPathString();
314 m_mapFilenameToChecked
[path
] = true;
316 else if ( entry
->status
> git_wc_status_normal
&& !entry
->checked
)
318 // The user manually deselected a versioned file. We remember
319 // this so that the deselection can be restored when refreshing.
320 CString path
= entry
->GetPath().GetGitPathString();
321 m_mapFilenameToChecked
[path
] = false;
325 // use a sorted path list to make sure we fetch the status of
326 // parent items first, *then* the child items (if any)
327 CTGitPathList sortedPathList
= pathList
;
328 sortedPathList
.SortByPathname();
333 m_bHasExternalsFromDifferentRepos
= FALSE
;
334 m_bHasExternals
= FALSE
;
335 m_bHasUnversionedItems
= FALSE
;
337 m_bHasChangeLists
= false;
338 m_bShowIgnores
= bShowIgnores
;
345 // first clear possible status data left from
346 // previous GetStatus() calls
349 m_StatusFileList
= sortedPathList
;
351 // Since Git_client_status() returns all files, even those in
352 // folders included with Git:externals we need to check if all
353 // files we get here belongs to the same repository.
354 // It is possible to commit changes in an external folder, as long
355 // as the folder belongs to the same repository (but another path),
356 // but it is not possible to commit all files if the externals are
357 // from a different repository.
359 // To check if all files belong to the same repository, we compare the
360 // UUID's - if they're identical then the files belong to the same
361 // repository and can be committed. But if they're different, then
362 // tell the user to commit all changes in the external folders
364 CStringA sUUID
; // holds the repo UUID
365 CTGitPathList arExtPaths
; // list of Git:external paths
371 m_nTargetCount
= sortedPathList
.GetCount();
373 GitStatus
status(m_pbCanceled
);
374 if(m_nTargetCount
> 1 && sortedPathList
.AreAllPathsFilesInOneDirectory())
376 // This is a special case, where we've been given a list of files
377 // all from one folder
378 // We handle them by setting a status filter, then requesting the Git status of
379 // all the files in the directory, filtering for the ones we're interested in
380 status
.SetFilter(sortedPathList
);
382 // if all selected entries are files, we don't do a recursive status
383 // fetching. But if only one is a directory, we have to recurse.
384 git_depth_t depth
= git_depth_files
;
385 // We have set a filter. If all selected items were files or we fetch
386 // the status not recursively, then we have to include
387 // ignored items too - the user has selected them
388 bool bShowIgnoresRight
= true;
389 for (int fcindex
=0; fcindex
<sortedPathList
.GetCount(); ++fcindex
)
391 if (sortedPathList
[fcindex
].IsDirectory())
393 depth
= git_depth_infinity
;
394 bShowIgnoresRight
= false;
398 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
.GetCommonDirectory(), bUpdate
, sUUID
, arExtPaths
, true, depth
, bShowIgnoresRight
))
405 for(int nTarget
= 0; nTarget
< m_nTargetCount
; nTarget
++)
407 // check whether the path we want the status for is already fetched due to status-fetching
409 // this check is only done for file paths, because folder paths could be included already
410 // but not recursively
411 if (sortedPathList
[nTarget
].IsDirectory() || GetListEntry(sortedPathList
[nTarget
]) == NULL
)
413 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
[nTarget
], bUpdate
, sUUID
,
414 arExtPaths
, false, git_depth_infinity
, bShowIgnores
))
422 // remove the 'helper' files of conflicted items from the list.
423 // otherwise they would appear as unversioned files.
424 for (INT_PTR cind
= 0; cind
< m_ConflictFileList
.GetCount(); ++cind
)
426 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
428 if (m_arStatusArray
[i
]->GetPath().IsEquivalentTo(m_ConflictFileList
[cind
]))
430 delete m_arStatusArray
[i
];
431 m_arStatusArray
.erase(m_arStatusArray
.begin()+i
);
437 } while(!BuildStatistics() && (refetchcounter
< 2) && (*m_pbCanceled
==false));
440 FetchUserProperties();
442 m_ColumnManager
.UpdateUserPropList (m_arStatusArray
);
447 SetCursorPos(pt
.x
, pt
.y
);
455 // Fetch all local properties for all elements in the status array
457 void CGitStatusListCtrl::FetchUserProperties()
462 for (size_t i
= 0, count
= m_arStatusArray
.size(); i
< count
; ++i
)
464 // local / temp pool to hold parameters and props for a single item
466 GitPool
localPool ((apr_pool_t
*)globalPool
);
468 // open working copy for this path
470 const char* path
= m_arStatusArray
[i
]->path
.GetGitApiPath (localPool
);
472 Git_wc_adm_access_t
*adm_access
= NULL
;
473 Git_error_t
* error
= Git_wc_adm_probe_open3 ( &adm_access
476 , FALSE
// no write lock
477 , 0 // lock just the directory/file itself
483 // get the props and add them to the status info
485 apr_hash_t
* props
= NULL
;
486 Git_error_t
* error
= Git_wc_prop_list ( &props
492 for ( apr_hash_index_t
*index
493 = apr_hash_first (localPool
, props
)
495 ; index
= apr_hash_next (index
))
497 // extract next entry from hash
499 const char* key
= NULL
;
501 const char** val
= NULL
;
503 apr_hash_this ( index
504 , reinterpret_cast<const void**>(&key
)
506 , reinterpret_cast<void**>(&val
));
508 // decode / dispatch it
510 CString name
= CUnicodeUtils::GetUnicode (key
);
511 CString value
= CUnicodeUtils::GetUnicode (*val
);
513 // store in property container (truncate it after ~100 chars)
515 m_arStatusArray
[i
]->present_props
[name
]
516 = value
.Left (GitSLC_MAXUSERPROPLENGTH
);
519 error
= Git_wc_adm_close2 (adm_access
, localPool
);
521 Git_error_clear (error
);
526 // Get the show-flags bitmap value which corresponds to a particular Git status
527 DWORD
CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status
)
531 case git_wc_status_none
:
532 case git_wc_status_unversioned
:
533 return SVNSLC_SHOWUNVERSIONED
;
534 case git_wc_status_ignored
:
536 return SVNSLC_SHOWDIRECTS
;
537 return SVNSLC_SHOWDIRECTS
|SVNSLC_SHOWIGNORED
;
538 case git_wc_status_incomplete
:
539 return SVNSLC_SHOWINCOMPLETE
;
540 case git_wc_status_normal
:
541 return SVNSLC_SHOWNORMAL
;
542 case git_wc_status_external
:
543 return SVNSLC_SHOWEXTERNAL
;
544 case git_wc_status_added
:
545 return SVNSLC_SHOWADDED
;
546 case git_wc_status_missing
:
547 return SVNSLC_SHOWMISSING
;
548 case git_wc_status_deleted
:
549 return SVNSLC_SHOWREMOVED
;
550 case git_wc_status_replaced
:
551 return SVNSLC_SHOWREPLACED
;
552 case git_wc_status_modified
:
553 return SVNSLC_SHOWMODIFIED
;
554 case git_wc_status_merged
:
555 return SVNSLC_SHOWMERGED
;
556 case git_wc_status_conflicted
:
557 return SVNSLC_SHOWCONFLICTED
;
558 case git_wc_status_obstructed
:
559 return SVNSLC_SHOWOBSTRUCTED
;
561 // we should NEVER get here!
568 void CGitStatusListCtrl::Show(DWORD dwShow
, DWORD dwCheck
/*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList
,bool UseStoredCheckStatus
)
570 CWinApp
* pApp
= AfxGetApp();
572 pApp
->DoWaitCursor(1);
574 Locker
lock(m_critSec
);
575 WORD langID
= (WORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
577 //SetItemCount(listIndex);
584 m_arStatusArray
.clear();
585 for(int i
=0;i
<this->m_StatusFileList
.GetCount();i
++)
587 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
590 for(int i
=0;i
<this->m_UnRevFileList
.GetCount();i
++)
592 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
595 for(int i
=0;i
<this->m_IgnoreFileList
.GetCount();i
++)
597 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
601 if( m_nSortedColumn
)
603 CSorter
predicate (&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
604 std::sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
608 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
610 //set default checkbox status
611 CTGitPath
* entry
= ((CTGitPath
*)m_arStatusArray
[i
]);
612 CString path
= entry
->GetGitPathString();
613 if (m_mapFilenameToChecked
.size()!=0 && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end())
615 entry
->m_Checked
=m_mapFilenameToChecked
[path
];
619 bool autoSelectSubmodules
= !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
);
620 if(entry
->m_Action
& dwCheck
&& autoSelectSubmodules
)
621 entry
->m_Checked
=true;
623 entry
->m_Checked
=false;
626 if(entry
->m_Action
& dwShow
)
628 AddEntry(entry
,langID
,index
);
633 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
634 for (int col
= 0; col
<= maxcol
; col
++)
635 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
638 GetStatisticsString();
640 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
641 HDITEM HeaderItem
= {0};
642 HeaderItem
.mask
= HDI_FORMAT
;
643 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
645 pHeader
->GetItem(i
, &HeaderItem
);
646 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
647 pHeader
->SetItem(i
, &HeaderItem
);
651 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
652 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
653 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
659 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
660 EnsureVisible(nSelectedEntry
, false);
664 // Restore the item at the top of the list.
665 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
667 if ( !EnsureVisible(nTopIndex
+i
,false) )
675 pApp
->DoWaitCursor(-1);
681 this->BuildStatistics();
685 CWinApp
* pApp
= AfxGetApp();
687 pApp
->DoWaitCursor(1);
689 m_bShowFolders
= bShowFolders
;
691 int nTopIndex
= GetTopIndex();
692 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
693 int nSelectedEntry
= 0;
694 if (posSelectedEntry
)
695 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
701 m_arListArray
.clear();
703 m_arListArray
.reserve(m_arStatusArray
.size());
704 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
707 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
709 FileEntry
* entry
= m_arStatusArray
[i
];
710 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
712 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
714 if (entry
->IsFolder() && (!bShowFolders
))
715 continue; // don't show folders if they're not wanted.
718 git_wc_status_kind status
= GitStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
719 DWORD showFlags
= GetShowFlagsFromGitStatus(status
);
720 if (entry
->IsLocked())
721 showFlags
|= SVNSLC_SHOWLOCKS
;
723 showFlags
|= SVNSLC_SHOWSWITCHED
;
724 if (!entry
->changelist
.IsEmpty())
725 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
727 bool bAllowCheck
= ((entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
) != 0)
728 && (m_bCheckIfGroupsExist
|| (m_changelists
.size()==0 || (m_changelists
.size()==1 && m_bHasIgnoreGroup
))));
730 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
732 if (status
!= Git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& GitSLC_SHOWIGNORED
))
734 if ((!entry
->IsFolder()) && (status
== Git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
736 if (PathFileExists(entry
->GetPath().GetWinPath()))
738 m_arListArray
.push_back(i
);
739 if ((dwCheck
& SVNSLC_SHOWREMOVEDANDPRESENT
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
742 entry
->checked
= true;
744 AddEntry(entry
, langID
, listIndex
++);
747 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
749 m_arListArray
.push_back(i
);
750 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
753 entry
->checked
= true;
755 AddEntry(entry
, langID
, listIndex
++);
757 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
759 m_arListArray
.push_back(i
);
760 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
763 entry
->checked
= true;
765 AddEntry(entry
, langID
, listIndex
++);
771 SetItemCount(listIndex
);
773 m_ColumnManager
.UpdateRelevance (m_arStatusArray
, m_arListArray
);
775 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
776 for (int col
= 0; col
<= maxcol
; col
++)
777 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
780 GetStatisticsString();
782 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
783 HDITEM HeaderItem
= {0};
784 HeaderItem
.mask
= HDI_FORMAT
;
785 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
787 pHeader
->GetItem(i
, &HeaderItem
);
788 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
789 pHeader
->SetItem(i
, &HeaderItem
);
793 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
794 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
795 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
800 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
801 EnsureVisible(nSelectedEntry
, false);
805 // Restore the item at the top of the list.
806 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
808 if ( !EnsureVisible(nTopIndex
+i
,false) )
816 pApp
->DoWaitCursor(-1);
818 m_bEmpty
= (GetItemCount() == 0);
824 void CGitStatusListCtrl::Show(DWORD
/*dwShow*/, const CTGitPathList
& checkedList
, bool /*bShowFolders*/ /* = true */)
827 for(int i
=0;i
<checkedList
.GetCount();i
++)
828 this->AddEntry((CTGitPath
*)&checkedList
[i
],0,i
);
832 Locker
lock(m_critSec
);
833 WORD langID
= (WORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
835 CWinApp
* pApp
= AfxGetApp();
837 pApp
->DoWaitCursor(1);
839 m_bShowFolders
= bShowFolders
;
841 int nTopIndex
= GetTopIndex();
842 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
843 int nSelectedEntry
= 0;
844 if (posSelectedEntry
)
845 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
851 m_arListArray
.clear();
853 m_arListArray
.reserve(m_arStatusArray
.size());
854 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
857 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
859 FileEntry
* entry
= m_arStatusArray
[i
];
860 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
862 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
864 if (entry
->IsFolder() && (!bShowFolders
))
865 continue; // don't show folders if they're not wanted.
867 git_wc_status_kind status
= SVNStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
868 DWORD showFlags
= GetShowFlagsFromSVNStatus(status
);
869 if (entry
->IsLocked())
870 showFlags
|= SVNSLC_SHOWLOCKS
;
871 if (!entry
->changelist
.IsEmpty())
872 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
874 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
875 if (status
!= git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& SVNSLC_SHOWIGNORED
))
877 for (int npath
= 0; npath
< checkedList
.GetCount(); ++npath
)
879 if (entry
->GetPath().IsEquivalentTo(checkedList
[npath
]))
881 entry
->checked
= true;
885 if ((!entry
->IsFolder()) && (status
== git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
887 if (PathFileExists(entry
->GetPath().GetWinPath()))
889 m_arListArray
.push_back(i
);
890 AddEntry(entry
, langID
, listIndex
++);
893 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
895 m_arListArray
.push_back(i
);
896 AddEntry(entry
, langID
, listIndex
++);
898 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
900 m_arListArray
.push_back(i
);
901 AddEntry(entry
, langID
, listIndex
++);
903 else if (entry
->switched
)
905 m_arListArray
.push_back(i
);
906 AddEntry(entry
, langID
, listIndex
++);
912 SetItemCount(listIndex
);
914 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
915 for (int col
= 0; col
<= maxcol
; col
++)
916 SetColumnWidth (col
, m_ColumnManager
.GetWidth (col
, true));
919 GetStatisticsString();
921 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
922 HDITEM HeaderItem
= {0};
923 HeaderItem
.mask
= HDI_FORMAT
;
924 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
926 pHeader
->GetItem(i
, &HeaderItem
);
927 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
928 pHeader
->SetItem(i
, &HeaderItem
);
932 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
933 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
934 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
939 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
940 EnsureVisible(nSelectedEntry
, false);
944 // Restore the item at the top of the list.
945 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
947 if ( !EnsureVisible(nTopIndex
+i
,false) )
955 pApp
->DoWaitCursor(-1);
957 m_bEmpty
= (GetItemCount() == 0);
962 int CGitStatusListCtrl::GetColumnIndex(int mask
)
972 void CGitStatusListCtrl::AddEntry(CTGitPath
* GitPath
, WORD
/*langID*/, int listIndex
)
974 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
975 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
977 CString path
= GitPath
->GetGitPathString();
980 int index
= listIndex
;
982 CString entryname
= GitPath
->GetGitPathString();
984 if (GitPath
->IsDirectory())
985 icon_idx
= m_nIconFolder
;
988 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(*GitPath
);
992 rename
.Format(_T(" (from %s)"),GitPath
->GetGitOldPathString());
993 if(GitPath
->m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
996 InsertItem(index
, entryname
, icon_idx
);
998 this->SetItemData(index
, (DWORD_PTR
)GitPath
);
999 // SVNSLC_COLFILENAME
1000 SetItemText(index
, nCol
++, GitPath
->GetFileOrDirectoryName());
1002 SetItemText(index
, nCol
++, GitPath
->GetFileExtension());
1004 SetItemText(index
, nCol
++, GitPath
->GetActionName());
1006 SetItemText(index
, GetColumnIndex(SVNSLC_COLADD
),GitPath
->m_StatAdd
);
1007 SetItemText(index
, GetColumnIndex(SVNSLC_COLDEL
),GitPath
->m_StatDel
);
1010 SetCheck(index
, GitPath
->m_Checked
);
1011 if (GitPath
->m_Checked
)
1015 if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_IGNORE
)
1016 SetItemGroup(index
, 2);
1017 else if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1018 SetItemGroup(index
,1);
1021 SetItemGroup(index
, GitPath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
));
1029 void CGitStatusListCtrl::AddEntry(FileEntry
* entry
, WORD langID
, int listIndex
)
1031 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
1032 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
1034 CString path
= entry
->GetPath().GetGitPathString();
1035 if ( m_mapFilenameToChecked
.size()!=0 && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end() )
1037 // The user manually de-/selected an item. We now restore this status
1039 entry
->checked
= m_mapFilenameToChecked
[path
];
1044 int index
= listIndex
;
1046 CString entryname
= entry
->GetDisplayName();
1048 if (entry
->isfolder
)
1049 icon_idx
= m_nIconFolder
;
1052 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(entry
->path
);
1055 InsertItem(index
, entryname
, icon_idx
);
1056 // SVNSLC_COLFILENAME
1057 SetItemText(index
, nCol
++, entry
->path
.GetFileOrDirectoryName());
1059 SetItemText(index
, nCol
++, entry
->path
.GetFileExtension());
1061 if (entry
->isNested
)
1063 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1064 SetItemText(index
, nCol
++, sTemp
);
1068 GitStatus::GetStatusString(hResourceHandle
, entry
->status
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
1069 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1070 _tcscat_s(buf
, 100, _T(" (+)"));
1071 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1072 _tcscat_s(buf
, 100, _T(" (s)"));
1074 if ((entry
->status
== entry
->propstatus
)&&
1075 (entry
->status
!= git_wc_status_normal
)&&
1076 (entry
->status
!= git_wc_status_unversioned
)&&
1077 (!GitStatus::IsImportant(entry
->textstatus
)))
1078 _tcscat_s(buf
, 100, ponly
);
1080 SetItemText(index
, nCol
++, buf
);
1082 // SVNSLC_COLREMOTESTATUS
1083 if (entry
->isNested
)
1085 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1086 SetItemText(index
, nCol
++, sTemp
);
1091 SVNStatus::GetStatusString(hResourceHandle
, entry
->remotestatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
1092 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1093 _tcscat_s(buf
, 100, _T(" (+)"));
1094 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1095 _tcscat_s(buf
, 100, _T(" (s)"));
1096 if ((entry
->remotestatus
== entry
->remotepropstatus
)&&
1097 (entry
->remotestatus
!= git_wc_status_none
)&&
1098 (entry
->remotestatus
!= git_wc_status_normal
)&&
1099 (entry
->remotestatus
!= git_wc_status_unversioned
)&&
1100 (!SVNStatus::IsImportant(entry
->remotetextstatus
)))
1101 _tcscat_s(buf
, 100, ponly
);
1103 SetItemText(index
, nCol
++, buf
);
1105 // SVNSLC_COLTEXTSTATUS
1106 if (entry
->isNested
)
1108 CString
sTemp(MAKEINTRESOURCE(IDS_STATUSLIST_NESTED
));
1109 SetItemText(index
, nCol
++, sTemp
);
1114 SVNStatus::GetStatusString(hResourceHandle
, entry
->textstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
1115 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1116 _tcscat_s(buf
, 100, _T(" (+)"));
1117 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1118 _tcscat_s(buf
, 100, _T(" (s)"));
1120 SetItemText(index
, nCol
++, buf
);
1122 // SVNSLC_COLPROPSTATUS
1123 if (entry
->isNested
)
1125 SetItemText(index
, nCol
++, _T(""));
1130 SVNStatus::GetStatusString(hResourceHandle
, entry
->propstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
1131 if ((entry
->copied
)&&(_tcslen(buf
)>1))
1132 _tcscat_s(buf
, 100, _T(" (+)"));
1133 if ((entry
->switched
)&&(_tcslen(buf
)>1))
1134 _tcscat_s(buf
, 100, _T(" (s)"));
1136 SetItemText(index
, nCol
++, buf
);
1138 // SVNSLC_COLREMOTETEXT
1139 if (entry
->isNested
)
1141 SetItemText(index
, nCol
++, _T(""));
1146 SVNStatus::GetStatusString(hResourceHandle
, entry
->remotetextstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
1147 SetItemText(index
, nCol
++, buf
);
1150 // SVNSLC_COLREMOTEPROP
1151 if (entry
->isNested
)
1153 SetItemText(index
, nCol
++, _T(""));
1157 // SVNStatus::GetStatusString(hResourceHandle, entry->remotepropstatus, buf, sizeof(buf)/sizeof(TCHAR), (WORD)langID);
1158 SetItemText(index
, nCol
++, buf
);
1161 // SetItemText(index, nCol++, entry->url);
1164 if (!m_HeadRev
.IsHead())
1166 // we have contacted the repository
1169 // wc repository text
1173 // UID1 "" lock has been broken
1174 // UID1 UID2 lock has been stolen
1175 if (entry
->lock_token
.IsEmpty() || (entry
->lock_token
.Compare(entry
->lock_remotetoken
)==0))
1177 if (entry
->lock_owner
.IsEmpty())
1178 SetItemText(index
, nCol
++, entry
->lock_remoteowner
);
1180 SetItemText(index
, nCol
++, entry
->lock_owner
);
1182 else if (entry
->lock_remotetoken
.IsEmpty())
1185 CString
temp(MAKEINTRESOURCE(IDS_STATUSLIST_LOCKBROKEN
));
1186 SetItemText(index
, nCol
++, temp
);
1192 temp
.Format(IDS_STATUSLIST_LOCKSTOLEN
, (LPCTSTR
)entry
->lock_remoteowner
);
1193 SetItemText(index
, nCol
++, temp
);
1197 SetItemText(index
, nCol
++, entry
->lock_owner
);
1198 // SVNSLC_COLLOCKCOMMENT
1199 SetItemText(index
, nCol
++, entry
->lock_comment
);
1201 SetItemText(index
, nCol
++, entry
->last_commit_author
);
1202 // SVNSLC_COLREVISION
1204 temp
.Format(_T("%ld"), entry
->last_commit_rev
);
1205 if (entry
->last_commit_rev
> 0)
1206 SetItemText(index
, nCol
++, temp
);
1208 SetItemText(index
, nCol
++, _T(""));
1209 // SVNSLC_COLREMOTEREVISION
1210 temp
.Format(_T("%ld"), entry
->remoterev
);
1211 if (entry
->remoterev
> 0)
1212 SetItemText(index
, nCol
++, temp
);
1214 SetItemText(index
, nCol
++, _T(""));
1216 TCHAR datebuf
[SVN_DATE_BUFFER
];
1217 apr_time_t date
= entry
->last_commit_date
;
1218 SVN::formatDate(datebuf
, date
, true);
1220 SetItemText(index
, nCol
++, datebuf
);
1222 SetItemText(index
, nCol
++, _T(""));
1223 // SVNSLC_COLSVNNEEDSLOCK
1224 BOOL bFoundSVNNeedsLock
= entry
->present_props
.IsNeedsLockSet();
1225 CString strSVNNeedsLock
= (bFoundSVNNeedsLock
) ? _T("*") : _T("");
1226 SetItemText(index
, nCol
++, strSVNNeedsLock
);
1227 // SVNSLC_COLCOPYFROM
1228 if (m_sURL
.Compare(entry
->copyfrom_url
.Left(m_sURL
.GetLength()))==0)
1229 temp
= entry
->copyfrom_url
.Mid(m_sURL
.GetLength());
1231 temp
= entry
->copyfrom_url
;
1232 SetItemText(index
, nCol
++, temp
);
1233 // SVNSLC_COLMODIFICATIONDATE
1234 __int64 filetime
= entry
->GetPath().GetLastWriteTime();
1235 if ( (filetime
) && (entry
->status
!=git_wc_status_deleted
) )
1237 FILETIME
* f
= (FILETIME
*)(__int64
*)&filetime
;
1238 TCHAR datebuf
[SVN_DATE_BUFFER
];
1239 SVN::formatDate(datebuf
,*f
,true);
1240 SetItemText(index
, nCol
++, datebuf
);
1244 SetItemText(index
, nCol
++, _T(""));
1247 // user-defined properties
1248 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
1252 assert (i
== nCol
++);
1253 assert (m_ColumnManager
.IsUserProp (i
));
1255 CString name
= m_ColumnManager
.GetName(i
);
1256 if (entry
->present_props
.HasProperty (name
))
1258 const CString
& propVal
= entry
->present_props
[name
];
1259 if (propVal
.IsEmpty())
1260 SetItemText(index
, i
, m_sNoPropValueText
);
1262 SetItemText(index
, i
, propVal
);
1265 SetItemText(index
, i
, _T(""));
1268 SetCheck(index
, entry
->checked
);
1271 if (m_changelists
.find(entry
->changelist
) != m_changelists
.end())
1272 SetItemGroup(index
, m_changelists
[entry
->changelist
]);
1274 SetItemGroup(index
, 0);
1279 bool CGitStatusListCtrl::SetItemGroup(int item
, int groupindex
)
1281 // if ((m_dwContextMenus & SVNSLC_POPCHANGELISTS) == NULL)
1286 i
.mask
= LVIF_GROUPID
;
1289 i
.iGroupId
= groupindex
;
1291 return !!SetItem(&i
);
1294 void CGitStatusListCtrl::Sort()
1296 Locker
lock(m_critSec
);
1298 CSorter
predicate (&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
1300 std::sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
1302 Show(m_dwShow
, 0, m_bShowFolders
,false,true);
1306 void CGitStatusListCtrl::OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1308 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1313 if (m_nSortedColumn
== phdr
->iItem
)
1314 m_bAscending
= !m_bAscending
;
1316 m_bAscending
= TRUE
;
1317 m_nSortedColumn
= phdr
->iItem
;
1318 m_mapFilenameToChecked
.clear();
1321 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
1322 HDITEM HeaderItem
= {0};
1323 HeaderItem
.mask
= HDI_FORMAT
;
1324 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
1326 pHeader
->GetItem(i
, &HeaderItem
);
1327 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
1328 pHeader
->SetItem(i
, &HeaderItem
);
1330 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
1331 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
1332 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
1334 // the checked state of the list control items must be restored
1336 for (int i
=0; i
<GetItemCount(); ++i
)
1338 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
1341 SetCheck(i
, entry
->m_Checked
);
1347 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1349 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1352 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1353 if ((m_bBlock
)&&(m_bBlockUI
))
1355 // if we're blocked, prevent changing of the check state
1356 if ((!ISCHECKED(pNMLV
->uOldState
) && ISCHECKED(pNMLV
->uNewState
))||
1357 (ISCHECKED(pNMLV
->uOldState
) && !ISCHECKED(pNMLV
->uNewState
)))
1362 BOOL
CGitStatusListCtrl::OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1364 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1366 CWnd
* pParent
= GetParent();
1367 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
1369 pParent
->SendMessage(SVNSLNM_ITEMCHANGED
, pNMLV
->iItem
);
1372 if ((pNMLV
->uNewState
==0)||(pNMLV
->uNewState
& LVIS_SELECTED
)||(pNMLV
->uNewState
& LVIS_FOCUSED
))
1378 bool bSelected
= !!(ListView_GetItemState(m_hWnd
, pNMLV
->iItem
, LVIS_SELECTED
) & LVIS_SELECTED
);
1379 int nListItems
= GetItemCount();
1382 // was the item checked?
1384 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1385 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1387 if (GetCheck(pNMLV
->iItem
))
1389 CheckEntry(pNMLV
->iItem
, nListItems
);
1392 POSITION pos
= GetFirstSelectedItemPosition();
1394 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1396 if (index
!= pNMLV
->iItem
)
1397 CheckEntry(index
, nListItems
);
1403 UncheckEntry(pNMLV
->iItem
, nListItems
);
1406 POSITION pos
= GetFirstSelectedItemPosition();
1408 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1410 if (index
!= pNMLV
->iItem
)
1411 UncheckEntry(index
, nListItems
);
1416 GetStatisticsString();
1423 void CGitStatusListCtrl::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1425 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
1430 void CGitStatusListCtrl::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1432 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
1437 void CGitStatusListCtrl::CheckEntry(int index
, int /*nListItems*/)
1439 Locker
lock(m_critSec
);
1440 //FileEntry * entry = GetListEntry(index);
1441 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1442 ASSERT(path
!= NULL
);
1445 m_mapFilenameToChecked
[path
->GetGitPathString()] = true;
1446 SetCheck(index
, TRUE
);
1447 //entry = GetListEntry(index);
1448 // if an unversioned item was checked, then we need to check if
1449 // the parent folders are unversioned too. If the parent folders actually
1450 // are unversioned, then check those too.
1452 if (entry
->status
== git_wc_status_unversioned
)
1454 // we need to check the parent folder too
1455 const CTGitPath
& folderpath
= entry
->path
;
1456 for (int i
=0; i
< nListItems
; ++i
)
1458 FileEntry
* testEntry
= GetListEntry(i
);
1459 ASSERT(testEntry
!= NULL
);
1460 if (testEntry
== NULL
)
1462 if (!testEntry
->checked
)
1464 if (testEntry
->path
.IsAncestorOf(folderpath
) && (!testEntry
->path
.IsEquivalentTo(folderpath
)))
1466 SetEntryCheck(testEntry
,i
,true);
1472 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1473 if ( (entry
->status
== git_wc_status_deleted
) || (m_bCheckChildrenWithParent
) || (bShift
) )
1475 // if a deleted folder gets checked, we have to check all
1476 // children of that folder too.
1477 if (entry
->path
.IsDirectory())
1479 SetCheckOnAllDescendentsOf(entry
, true);
1482 // if a deleted file or folder gets checked, we have to
1483 // check all parents of this item too.
1484 for (int i
=0; i
<nListItems
; ++i
)
1486 FileEntry
* testEntry
= GetListEntry(i
);
1487 ASSERT(testEntry
!= NULL
);
1488 if (testEntry
== NULL
)
1490 if (!testEntry
->checked
)
1492 if (testEntry
->path
.IsAncestorOf(entry
->path
) && (!testEntry
->path
.IsEquivalentTo(entry
->path
)))
1494 if ((testEntry
->status
== git_wc_status_deleted
)||(m_bCheckChildrenWithParent
))
1496 SetEntryCheck(testEntry
,i
,true);
1498 // now we need to check all children of this parent folder
1499 SetCheckOnAllDescendentsOf(testEntry
, true);
1506 if ( !path
->m_Checked
)
1508 path
->m_Checked
= TRUE
;
1513 void CGitStatusListCtrl::UncheckEntry(int index
, int /*nListItems*/)
1515 Locker
lock(m_critSec
);
1516 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1517 ASSERT(path
!= NULL
);
1520 SetCheck(index
, FALSE
);
1521 m_mapFilenameToChecked
[path
->GetGitPathString()] = false;
1522 //entry = GetListEntry(index);
1523 // item was unchecked
1525 if (entry
->path
.IsDirectory())
1527 // disable all files within an unselected folder, except when unchecking a folder with property changes
1528 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1529 if ( (entry
->status
!= git_wc_status_modified
) || (bShift
) )
1531 SetCheckOnAllDescendentsOf(entry
, false);
1534 else if (entry
->status
== git_wc_status_deleted
)
1536 // a "deleted" file was unchecked, so uncheck all parent folders
1537 // and all children of those parents
1538 for (int i
=0; i
<nListItems
; i
++)
1540 FileEntry
* testEntry
= GetListEntry(i
);
1541 ASSERT(testEntry
!= NULL
);
1542 if (testEntry
== NULL
)
1544 if (testEntry
->checked
)
1546 if (testEntry
->path
.IsAncestorOf(entry
->path
))
1548 if (testEntry
->status
== git_wc_status_deleted
)
1550 SetEntryCheck(testEntry
,i
,false);
1553 SetCheckOnAllDescendentsOf(testEntry
, false);
1560 if ( path
->m_Checked
)
1562 path
->m_Checked
= FALSE
;
1567 bool CGitStatusListCtrl::EntryPathCompareNoCase(const FileEntry
* pEntry1
, const FileEntry
* pEntry2
)
1569 return pEntry1
->path
< pEntry2
->path
;
1572 bool CGitStatusListCtrl::IsEntryVersioned(const FileEntry
* pEntry1
)
1574 return pEntry1
->status
!= git_wc_status_unversioned
;
1577 bool CGitStatusListCtrl::BuildStatistics()
1580 bool bRefetchStatus
= false;
1582 // now gather some statistics
1595 for (int i
=0; i
< (int)m_arStatusArray
.size(); ++i
)
1597 int status
=((CTGitPath
*)m_arStatusArray
[i
])->m_Action
;
1599 m_nLineAdded
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatAdd
);
1600 m_nLineDeleted
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatDel
);
1602 if(status
&(CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
1605 if(status
&CTGitPath::LOGACTIONS_DELETED
)
1608 if(status
&(CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_MODIFIED
))
1611 if(status
&CTGitPath::LOGACTIONS_UNMERGED
)
1614 if(status
&(CTGitPath::LOGACTIONS_IGNORE
|CTGitPath::LOGACTIONS_UNVER
))
1617 if(status
&(CTGitPath::LOGACTIONS_REPLACED
))
1620 if(((CTGitPath
*)m_arStatusArray
[i
])->m_Checked
)
1623 // } // switch (entry->status)
1625 } // for (int i=0; i < (int)m_arStatusArray.size(); ++i)
1626 return !bRefetchStatus
;
1632 int CGitStatusListCtrl::GetGroupFromPoint(POINT
* ppt
)
1634 // the point must be relative to the upper left corner of the control
1638 if (!IsGroupViewEnabled())
1647 while (((flags
& LVHT_BELOW
) == 0)&&(pt
.y
< rc
.bottom
))
1649 nItem
= HitTest(pt
, &flags
);
1650 if ((flags
& LVHT_ONITEM
)||(flags
& LVHT_EX_GROUP_HEADER
))
1652 // the first item below the point
1654 // check if the point is too much right (i.e. if the point
1655 // is farther to the right than the width of the item)
1657 GetItemRect(nItem
, &r
, LVIR_LABEL
);
1658 if (ppt
->x
> r
.right
)
1662 lv
.mask
= LVIF_GROUPID
;
1665 int groupID
= lv
.iGroupId
;
1666 // now we search upwards and check if the item above this one
1667 // belongs to another group. If it belongs to the same group,
1668 // we're not over a group header
1672 nItem
= HitTest(pt
, &flags
);
1673 if ((flags
& LVHT_ONITEM
)&&(nItem
>= 0))
1675 // the first item below the point
1677 lv
.mask
= LVIF_GROUPID
;
1680 if (lv
.iGroupId
!= groupID
)
1695 void CGitStatusListCtrl::OnContextMenuGroup(CWnd
* /*pWnd*/, CPoint point
)
1697 POINT clientpoint
= point
;
1698 ScreenToClient(&clientpoint
);
1699 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint
) >= 0))
1702 if (popup
.CreatePopupMenu())
1705 temp
.LoadString(IDS_STATUSLIST_CHECKGROUP
);
1706 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CHECKGROUP
, temp
);
1707 temp
.LoadString(IDS_STATUSLIST_UNCHECKGROUP
);
1708 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_UNCHECKGROUP
, temp
);
1709 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1710 bool bCheck
= false;
1713 case IDSVNLC_CHECKGROUP
:
1715 // fall through here
1716 case IDSVNLC_UNCHECKGROUP
:
1718 int group
= GetGroupFromPoint(&clientpoint
);
1719 // go through all items and check/uncheck those assigned to the group
1720 // but block the OnLvnItemChanged handler
1723 for (int i
=0; i
<GetItemCount(); ++i
)
1725 SecureZeroMemory(&lv
, sizeof(LVITEM
));
1726 lv
.mask
= LVIF_GROUPID
;
1730 if (lv
.iGroupId
== group
)
1732 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
1735 bool bOldCheck
= entry
->m_Checked
;
1736 SetEntryCheck(entry
, i
, bCheck
);
1737 if (bCheck
!= bOldCheck
)
1748 GetStatisticsString();
1758 void CGitStatusListCtrl::OnContextMenuList(CWnd
* pWnd
, CPoint point
)
1761 //WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1763 bool XPorLater
= false;
1764 OSVERSIONINFOEX inf
;
1765 SecureZeroMemory(&inf
, sizeof(OSVERSIONINFOEX
));
1766 inf
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
1767 GetVersionEx((OSVERSIONINFO
*)&inf
);
1768 WORD fullver
= MAKEWORD(inf
.dwMinorVersion
, inf
.dwMajorVersion
);
1769 if (fullver
>= 0x0501)
1771 //bool bShift = !!(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1772 CTGitPath
* filepath
;
1774 int selIndex
= GetSelectionMark();
1775 if ((point
.x
== -1) && (point
.y
== -1))
1778 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1779 ClientToScreen(&rect
);
1780 point
= rect
.CenterPoint();
1782 if ((GetSelectedCount() == 0)&&(XPorLater
)&&(m_bHasCheckboxes
))
1784 // nothing selected could mean the context menu is requested for
1786 OnContextMenuGroup(pWnd
, point
);
1788 else if (selIndex
>= 0)
1790 //FileEntry * entry = GetListEntry(selIndex);
1792 filepath
= (CTGitPath
* )GetItemData(selIndex
);
1794 ASSERT(filepath
!= NULL
);
1795 if (filepath
== NULL
)
1798 //const CTGitPath& filepath = entry->path;
1799 int wcStatus
= filepath
->m_Action
;
1800 // entry is selected, now show the popup menu
1801 Locker
lock(m_critSec
);
1803 CMenu changelistSubMenu
;
1804 CMenu ignoreSubMenu
;
1805 if (popup
.CreatePopupMenu())
1807 //Add Menu for verion controled file
1809 if (wcStatus
& CTGitPath::LOGACTIONS_UNMERGED
)
1811 if ((m_dwContextMenus
& SVNSLC_POPCONFLICT
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1813 popup
.AppendMenuIcon(IDSVNLC_EDITCONFLICT
, IDS_MENUCONFLICT
, IDI_CONFLICT
);
1815 if (m_dwContextMenus
& SVNSLC_POPRESOLVE
)
1817 popup
.AppendMenuIcon(IDSVNLC_RESOLVECONFLICT
, IDS_STATUSLIST_CONTEXT_RESOLVED
, IDI_RESOLVE
);
1819 if ((m_dwContextMenus
& SVNSLC_POPRESOLVE
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1821 popup
.AppendMenuIcon(IDSVNLC_RESOLVETHEIRS
, IDS_SVNPROGRESS_MENUUSETHEIRS
, IDI_RESOLVE
);
1822 popup
.AppendMenuIcon(IDSVNLC_RESOLVEMINE
, IDS_SVNPROGRESS_MENUUSEMINE
, IDI_RESOLVE
);
1824 if ((m_dwContextMenus
& SVNSLC_POPCONFLICT
)||(m_dwContextMenus
& SVNSLC_POPRESOLVE
))
1825 popup
.AppendMenu(MF_SEPARATOR
);
1828 if (GetSelectedCount() > 0)
1830 if (wcStatus
& CTGitPath::LOGACTIONS_UNVER
)
1831 if (m_dwContextMenus
& SVNSLC_POPADD
)
1833 //if ( entry->IsFolder() )
1835 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1839 popup
.AppendMenuIcon(IDSVNLC_ADD
, IDS_STATUSLIST_CONTEXT_ADD
, IDI_ADD
);
1844 if (!(wcStatus
&CTGitPath::LOGACTIONS_UNVER
))
1846 if ( (m_dwContextMenus
& SVNSLC_POPCOMPAREWITHBASE
) && GetSelectedCount()>0)
1848 if(filepath
->m_ParentNo
& MERGE_MASK
)
1849 popup
.AppendMenuIcon(IDSVNLC_COMPARE
, IDS_TREE_DIFF
, IDI_DIFF
);
1851 popup
.AppendMenuIcon(IDSVNLC_COMPARE
, IDS_LOG_COMPAREWITHBASE
, IDI_DIFF
);
1853 popup
.SetDefaultItem(IDSVNLC_COMPARE
, FALSE
);
1856 if ((m_dwContextMenus
& this->GetContextMenuBit(IDSVNLC_COMPAREWC
)) && GetSelectedCount()>0)
1858 if( (!m_CurrentVersion
.IsEmpty()) && m_CurrentVersion
!= GIT_REV_ZERO
)
1859 popup
.AppendMenuIcon(IDSVNLC_COMPAREWC
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1862 if (GetSelectedCount() == 1)
1864 bool bEntryAdded
= false;
1865 //if (entry->remotestatus <= git_wc_status_normal)
1867 // if (wcStatus > git_wc_status_normal)
1869 // if ((m_dwContextMenus & SVNSLC_POPGNUDIFF)&&(wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing))
1871 if(!g_Git
.IsInitRepos() && (m_dwContextMenus
&SVNSLC_POPGNUDIFF
))
1873 popup
.AppendMenuIcon(IDSVNLC_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1881 //else if (wcStatus != git_wc_status_deleted)
1883 // if (m_dwContextMenus & SVNSLC_POPCOMPARE)
1885 // popup.AppendMenuIcon(IDSVNLC_COMPAREWC, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1886 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1887 // bEntryAdded = true;
1889 // if (m_dwContextMenus & SVNSLC_POPGNUDIFF)
1891 // popup.AppendMenuIcon(IDSVNLC_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1892 // bEntryAdded = true;
1896 popup
.AppendMenu(MF_SEPARATOR
);
1898 //else if (GetSelectedCount() > 1)
1900 // if (m_dwContextMenus & SVNSLC_POPCOMMIT)
1902 // popup.AppendMenuIcon(IDSVNLC_COMMIT, IDS_STATUSLIST_CONTEXT_COMMIT, IDI_COMMIT);
1903 // popup.SetDefaultItem(IDSVNLC_COMPARE, FALSE);
1908 if( (!this->m_Rev1
.IsEmpty()) || (!this->m_Rev1
.IsEmpty()) )
1910 if(GetSelectedCount() == 1)
1912 if (m_dwContextMenus
& this->GetContextMenuBit(IDSVNLC_COMPARETWO
))
1914 popup
.AppendMenuIcon(IDSVNLC_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1915 popup
.SetDefaultItem(IDSVNLC_COMPARETWO
, FALSE
);
1917 if (m_dwContextMenus
& this->GetContextMenuBit(IDSVNLC_GNUDIFF2
))
1919 popup
.AppendMenuIcon(IDSVNLC_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1924 ///Select Multi item
1925 //if (GetSelectedCount() > 0)
1927 // if ((GetSelectedCount() == 2)&&(m_dwContextMenus & SVNSLC_POPREPAIRMOVE))
1929 // POSITION pos = GetFirstSelectedItemPosition();
1930 // int index = GetNextSelectedItem(pos);
1933 // FileEntry * entry = GetListEntry(index);
1934 // git_wc_status_kind status1 = git_wc_status_none;
1935 // git_wc_status_kind status2 = git_wc_status_none;
1937 // status1 = entry->status;
1938 // index = GetNextSelectedItem(pos);
1941 // entry = GetListEntry(index);
1943 // status2 = entry->status;
1944 // if ((status1 == git_wc_status_missing && status2 == git_wc_status_unversioned) ||
1945 // (status2 == git_wc_status_missing && status1 == git_wc_status_unversioned))
1947 // popup.AppendMenuIcon(IDSVNLC_REPAIRMOVE, IDS_STATUSLIST_CONTEXT_REPAIRMOVE);
1952 // if (wcStatus > git_wc_status_normal)
1954 // if (m_dwContextMenus & SVNSLC_POPREVERT)
1956 // // reverting missing folders is not possible
1957 // if (!entry->IsFolder() || (wcStatus != git_wc_status_missing))
1959 // popup.AppendMenuIcon(IDSVNLC_REVERT, IDS_MENUREVERT, IDI_REVERT);
1963 // if (entry->remotestatus > git_wc_status_normal)
1965 // if (m_dwContextMenus & SVNSLC_POPUPDATE)
1967 // popup.AppendMenuIcon(IDSVNLC_UPDATE, IDS_MENUUPDATE, IDI_UPDATE);
1972 if ( (GetSelectedCount() >0 ) && (!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
)))
1974 if ((m_dwContextMenus
& SVNSLC_POPREVERT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1976 popup
.AppendMenuIcon(IDSVNLC_REVERT
, IDS_MENUREVERT
, IDI_REVERT
);
1979 if ((m_dwContextMenus
& GetContextMenuBit(IDSVNLC_REVERTTOREV
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1980 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1982 popup
.AppendMenuIcon(IDSVNLC_REVERTTOREV
, IDS_LOG_POPUP_REVERTTOREV
, IDI_REVERT
);
1986 if ((GetSelectedCount() == 1)&&(!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
))
1987 &&(!(wcStatus
& CTGitPath::LOGACTIONS_IGNORE
)))
1989 if (m_dwContextMenus
& SVNSLC_POPSHOWLOG
)
1991 popup
.AppendMenuIcon(IDSVNLC_LOG
, IDS_REPOBROWSE_SHOWLOG
, IDI_LOG
);
1993 if (m_dwContextMenus
& SVNSLC_POPBLAME
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1995 popup
.AppendMenuIcon(IDSVNLC_BLAME
, IDS_MENUBLAME
, IDI_BLAME
);
1998 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1999 if ( (GetSelectedCount() == 1) )
2001 if (m_dwContextMenus
& this->GetContextMenuBit(IDSVNLC_SAVEAS
) && ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
2003 popup
.AppendMenuIcon(IDSVNLC_SAVEAS
, IDS_LOG_POPUP_SAVE
, IDI_SAVEAS
);
2006 if (m_dwContextMenus
& SVNSLC_POPOPEN
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
2008 popup
.AppendMenuIcon(IDSVNLC_VIEWREV
, IDS_LOG_POPUP_VIEWREV
);
2009 popup
.AppendMenuIcon(IDSVNLC_OPEN
, IDS_REPOBROWSE_OPEN
, IDI_OPEN
);
2010 popup
.AppendMenuIcon(IDSVNLC_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
2011 if (wcStatus
&CTGitPath::LOGACTIONS_UNVER
) {
2012 popup
.SetDefaultItem(IDSVNLC_OPEN
, FALSE
);
2016 if (m_dwContextMenus
& SVNSLC_POPEXPLORE
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
2018 popup
.AppendMenuIcon(IDSVNLC_EXPLORE
, IDS_STATUSLIST_CONTEXT_EXPLORE
, IDI_EXPLORER
);
2022 if (GetSelectedCount() > 0)
2024 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
2026 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
2028 // 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))
2031 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
2033 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
2035 if ((wcStatus
& CTGitPath::LOGACTIONS_UNVER
)/*||(wcStatus == git_wc_status_deleted)*/)
2037 if (m_dwContextMenus
& SVNSLC_POPDELETE
)
2039 popup
.AppendMenuIcon(IDSVNLC_DELETE
, IDS_MENUREMOVE
, IDI_DELETE
);
2042 if ( (wcStatus
& CTGitPath::LOGACTIONS_UNVER
|| wcStatus
& CTGitPath::LOGACTIONS_DELETED
) )
2044 if (m_dwContextMenus
& SVNSLC_POPIGNORE
)
2047 CTGitPathList ignorelist
;
2048 FillListOfSelectedItemPaths(ignorelist
);
2049 //check if all selected entries have the same extension
2050 bool bSameExt
= true;
2052 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
2054 if (sExt
.IsEmpty() && (i
==0))
2055 sExt
= ignorelist
[i
].GetFileExtension();
2056 else if (sExt
.CompareNoCase(ignorelist
[i
].GetFileExtension())!=0)
2061 if (ignoreSubMenu
.CreateMenu())
2064 if (ignorelist
.GetCount()==1)
2065 ignorepath
= ignorelist
[0].GetFileOrDirectoryName();
2067 ignorepath
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
2068 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_IGNORE
, ignorepath
);
2069 ignorepath
= _T("*")+sExt
;
2070 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_IGNOREMASK
, ignorepath
);
2072 temp
.LoadString(IDS_MENUIGNORE
);
2073 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)ignoreSubMenu
.m_hMenu
, temp
);
2079 if (ignorelist
.GetCount()==1)
2081 temp
.LoadString(IDS_MENUIGNORE
);
2085 temp
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
2087 popup
.AppendMenuIcon(IDSVNLC_IGNORE
, temp
, IDI_IGNORE
);
2095 if (GetSelectedCount() > 0)
2098 if ((!entry
->IsFolder())&&(wcStatus
>= git_wc_status_normal
)
2099 &&(wcStatus
!=git_wc_status_missing
)&&(wcStatus
!=git_wc_status_deleted
)
2100 &&(wcStatus
!=git_wc_status_added
))
2102 popup
.AppendMenu(MF_SEPARATOR
);
2103 if ((entry
->lock_token
.IsEmpty())&&(!entry
->IsFolder()))
2105 if (m_dwContextMenus
& SVNSLC_POPLOCK
)
2107 popup
.AppendMenuIcon(IDSVNLC_LOCK
, IDS_MENU_LOCK
, IDI_LOCK
);
2110 if ((!entry
->lock_token
.IsEmpty())&&(!entry
->IsFolder()))
2112 if (m_dwContextMenus
& SVNSLC_POPUNLOCK
)
2114 popup
.AppendMenuIcon(IDSVNLC_UNLOCK
, IDS_MENU_UNLOCK
, IDI_UNLOCK
);
2119 if ((!entry
->IsFolder())&&((!entry
->lock_token
.IsEmpty())||(!entry
->lock_remotetoken
.IsEmpty())))
2121 if (m_dwContextMenus
& SVNSLC_POPUNLOCKFORCE
)
2123 popup
.AppendMenuIcon(IDSVNLC_UNLOCKFORCE
, IDS_MENU_UNLOCKFORCE
, IDI_UNLOCK
);
2127 if (wcStatus
!= git_wc_status_missing
&& wcStatus
!= git_wc_status_deleted
&&wcStatus
!=git_wc_status_unversioned
)
2129 popup
.AppendMenu(MF_SEPARATOR
);
2130 popup
.AppendMenuIcon(IDSVNLC_PROPERTIES
, IDS_STATUSLIST_CONTEXT_PROPERTIES
, IDI_PROPERTIES
);
2133 popup
.AppendMenu(MF_SEPARATOR
);
2134 popup
.AppendMenuIcon(IDSVNLC_COPY
, IDS_STATUSLIST_CONTEXT_COPY
, IDI_COPYCLIP
);
2135 popup
.AppendMenuIcon(IDSVNLC_COPYEXT
, IDS_STATUSLIST_CONTEXT_COPYEXT
, IDI_COPYCLIP
);
2137 if ((m_dwContextMenus
& SVNSLC_POPCHANGELISTS
)&&(XPorLater
)
2138 &&(wcStatus
!= git_wc_status_unversioned
)&&(wcStatus
!= git_wc_status_none
))
2140 popup
.AppendMenu(MF_SEPARATOR
);
2141 // changelist commands
2142 size_t numChangelists
= GetNumberOfChangelistsInSelection();
2143 if (numChangelists
> 0)
2145 popup
.AppendMenuIcon(IDSVNLC_REMOVEFROMCS
, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS
);
2147 if ((!entry
->IsFolder())&&(changelistSubMenu
.CreateMenu()))
2150 temp
.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS
);
2151 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATECS
, temp
);
2153 if (entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
))
2155 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
2156 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATEIGNORECS
, SVNSLC_IGNORECHANGELIST
);
2159 if (m_changelists
.size() > 0)
2161 // find the changelist names
2162 bool bNeedSeparator
= true;
2163 int cmdID
= IDSVNLC_MOVETOCS
;
2164 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
2166 if ((entry
->changelist
.Compare(it
->first
))&&(it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)))
2170 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
2171 bNeedSeparator
= false;
2173 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, cmdID
, it
->first
);
2178 temp
.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS
);
2179 popup
.AppendMenu(MF_POPUP
|MF_STRING
, (UINT_PTR
)changelistSubMenu
.GetSafeHmenu(), temp
);
2185 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2188 AfxGetApp()->DoWaitCursor(1);
2189 //int iItemCountBeforeMenuCmd = GetItemCount();
2190 //bool bForce = false;
2193 case IDSVNLC_VIEWREV
:
2194 OpenFile(filepath
, ALTERNATIVEEDITOR
);
2197 OpenFile(filepath
,OPEN
);
2199 case IDSVNLC_OPENWITH
:
2200 OpenFile(filepath
,OPEN_WITH
);
2202 case IDSVNLC_EXPLORE
:
2204 ShellExecute(this->m_hWnd
, _T("explore"), filepath
->GetDirectory().GetWinPath(), NULL
, NULL
, SW_SHOW
);
2208 // Compare current version and work copy.
2209 case IDSVNLC_COMPAREWC
:
2211 POSITION pos
= GetFirstSelectedItemPosition();
2214 int index
= GetNextSelectedItem(pos
);
2219 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2220 case IDSVNLC_COMPARE
:
2222 POSITION pos
= GetFirstSelectedItemPosition();
2225 int index
= GetNextSelectedItem(pos
);
2230 case IDSVNLC_COMPARETWO
:
2232 POSITION pos
= GetFirstSelectedItemPosition();
2235 int index
= GetNextSelectedItem(pos
);
2236 StartDiffTwo(index
);
2240 case IDSVNLC_GNUDIFF1
:
2242 // SVNDiff diff(NULL, this->m_hWnd, true);
2244 // if (entry->remotestatus <= git_wc_status_normal)
2245 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2247 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2248 if(m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2252 fromwhere
= _T("~1");
2253 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,GitRev::GetWorkingCopy(),
2254 *filepath
,GitRev::GetHead()+fromwhere
);
2258 if((filepath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
)) ==0)
2259 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_CurrentVersion
,
2260 *filepath
,m_CurrentVersion
+_T("~1"));
2264 if(filepath
->m_ParentNo
& MERGE_MASK
)
2268 str
.Format(_T("%s^%d"),m_CurrentVersion
,(filepath
->m_ParentNo
&PARENT_MASK
)+1);
2271 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_CurrentVersion
,
2272 *filepath
,str
, false,false,false,
2273 !!(filepath
->m_ParentNo
& MERGE_MASK
));
2278 case IDSVNLC_GNUDIFF2
:
2280 // SVNDiff diff(NULL, this->m_hWnd, true);
2282 // if (entry->remotestatus <= git_wc_status_normal)
2283 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_BASE, entry->path, SVNRev::REV_WC);
2285 // CAppUtils::StartShowUnifiedDiff(m_hWnd, entry->path, SVNRev::REV_WC, entry->path, SVNRev::REV_HEAD);
2287 CAppUtils::StartShowUnifiedDiff(m_hWnd
,*filepath
,m_Rev1
,
2293 { // The add went ok, but we now need to run through the selected items again
2294 // and update their status
2295 std::vector
<int> selectIndex
;
2297 POSITION pos
= GetFirstSelectedItemPosition();
2299 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2301 selectIndex
.push_back(index
);
2303 for(int i
=0;i
<selectIndex
.size();i
++)
2305 index
=selectIndex
[i
];
2307 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2312 cmd
.Format(_T("git.exe add -- \"%s\""),path
->GetGitPathString());
2314 if(!g_Git
.Run(cmd
,&output
,CP_ACP
))
2316 path
->m_Action
= CTGitPath::LOGACTIONS_ADDED
;
2317 SetEntryCheck(path
,index
,true);
2319 SetItemGroup(index
,0);
2320 this->m_StatusFileList
.AddPath(*path
);
2321 this->m_UnRevFileList
.RemoveItem(*path
);
2322 this->m_IgnoreFileList
.RemoveItem(*path
);
2324 Show(this->m_dwShow
,0,true,true,true);
2331 case IDSVNLC_DELETE
:
2334 std::vector
<int> selectIndex
;
2336 POSITION pos
= GetFirstSelectedItemPosition();
2338 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2340 selectIndex
.push_back(index
);
2343 //Create file-list ('\0' separated) for SHFileOperation
2345 for(int i
=0;i
<selectIndex
.size();i
++)
2347 index
=selectIndex
[i
];
2349 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
2354 filelist
+= path
->GetWinPathString();
2355 filelist
+= _T("|");
2357 filelist
+= _T("|");
2358 int len
= filelist
.GetLength();
2359 TCHAR
* buf
= new TCHAR
[len
+2];
2360 _tcscpy_s(buf
, len
+2, filelist
);
2361 for (int i
=0; i
<len
; ++i
)
2364 SHFILEOPSTRUCT fileop
;
2365 fileop
.hwnd
= this->m_hWnd
;
2366 fileop
.wFunc
= FO_DELETE
;
2369 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
2370 fileop
.lpszProgressTitle
= _T("deleting file");
2371 int result
= SHFileOperation(&fileop
);
2374 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
2377 POSITION pos
= NULL
;
2378 while ((pos
= GetFirstSelectedItemPosition()) != 0)
2380 int index
= GetNextSelectedItem(pos
);
2381 if (GetCheck(index
))
2385 RemoveListEntry(index
);
2394 CAppUtils::LaunchTortoiseBlame(g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath(), m_CurrentVersion
);
2401 sCmd
.Format(_T("\"%s\" /command:log /path:\"%s\""),
2402 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), g_Git
.m_CurrentDir
+_T("\\")+filepath
->GetWinPath());
2404 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
2408 case IDSVNLC_EDITCONFLICT
:
2410 CAppUtils::ConflictEdit(*filepath
,false,this->m_bIsRevertTheirMy
);
2413 case IDSVNLC_RESOLVETHEIRS
: //follow up
2414 case IDSVNLC_RESOLVEMINE
: //follow up
2415 case IDSVNLC_RESOLVECONFLICT
:
2417 if (CMessageBox::Show(m_hWnd
, IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
)==IDYES
)
2419 POSITION pos
= GetFirstSelectedItemPosition();
2423 index
= GetNextSelectedItem(pos
);
2424 CTGitPath
* fentry
=(CTGitPath
*) this->GetItemData(index
);
2427 CString gitcmd
,output
;
2430 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDSVNLC_RESOLVETHEIRS
) ||
2431 ((this->m_bIsRevertTheirMy
)&&cmd
== IDSVNLC_RESOLVEMINE
) )
2433 gitcmd
.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""),fentry
->GetGitPathString());
2434 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2436 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2441 if ( ((!this->m_bIsRevertTheirMy
)&&cmd
== IDSVNLC_RESOLVEMINE
) ||
2442 ((this->m_bIsRevertTheirMy
)&&cmd
== IDSVNLC_RESOLVETHEIRS
) )
2444 gitcmd
.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""),fentry
->GetGitPathString());
2445 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2447 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2453 if ( fentry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
2455 gitcmd
.Format(_T("git.exe add -- \"%s\""),fentry
->GetGitPathString());
2456 if(g_Git
.Run(gitcmd
,&output
,CP_ACP
))
2458 CMessageBox::Show(m_hWnd
, output
, _T("TortoiseGit"), MB_ICONERROR
);
2461 fentry
->m_Action
|= CTGitPath::LOGACTIONS_MODIFIED
;
2462 fentry
->m_Action
&=~CTGitPath::LOGACTIONS_UNMERGED
;
2466 CAppUtils::RemoveTempMergeFile(*fentry
);
2469 Show(m_dwShow
, 0, m_bShowFolders
,0,true);
2474 case IDSVNLC_IGNORE
:
2476 CTGitPathList ignorelist
;
2477 //std::vector<CString> toremove;
2478 FillListOfSelectedItemPaths(ignorelist
, true);
2481 if(!CAppUtils::IgnoreFile(ignorelist
,false))
2484 for(int i
=0;i
<ignorelist
.GetCount();i
++)
2486 int nListboxEntries
= GetItemCount();
2487 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2489 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2490 if (path
->GetGitPathString()==ignorelist
[i
].GetGitPathString())
2492 RemoveListEntry(nItem
);
2500 CTSVNPathList ignorelist
;
2501 std::vector
<CString
> toremove
;
2502 FillListOfSelectedItemPaths(ignorelist
, true);
2504 for (int j
=0; j
<ignorelist
.GetCount(); ++j
)
2506 int nListboxEntries
= GetItemCount();
2507 for (int i
=0; i
<nListboxEntries
; ++i
)
2509 if (GetListEntry(i
)->GetPath().IsEquivalentTo(ignorelist
[j
]))
2515 CString name
= CPathUtils::PathPatternEscape(ignorelist
[j
].GetFileOrDirectoryName());
2516 CTSVNPath parentfolder
= ignorelist
[j
].GetContainingDirectory();
2517 SVNProperties
props(parentfolder
, SVNRev::REV_WC
, false);
2519 for (int i
=0; i
<props
.GetCount(); i
++)
2521 CString
propname(props
.GetItemName(i
).c_str());
2522 if (propname
.CompareNoCase(_T("git:ignore"))==0)
2525 // treat values as normal text even if they're not
2526 value
= (char *)props
.GetItemValue(i
).c_str();
2529 if (value
.IsEmpty())
2533 value
= value
.Trim("\n\r");
2538 if (!props
.Add(_T("git:ignore"), (LPCSTR
)value
))
2541 temp
.Format(IDS_ERR_FAILEDIGNOREPROPERTY
, (LPCTSTR
)name
);
2542 CMessageBox::Show(this->m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONERROR
);
2545 if (GetCheck(selIndex
))
2549 // now, if we ignored a folder, remove all its children
2550 if (ignorelist
[j
].IsDirectory())
2552 for (int i
=0; i
<(int)m_arListArray
.size(); ++i
)
2554 FileEntry
* entry
= GetListEntry(i
);
2555 if (entry
->status
== git_wc_status_unversioned
)
2557 if (!ignorelist
[j
].IsEquivalentTo(entry
->GetPath())&&(ignorelist
[j
].IsAncestorOf(entry
->GetPath())))
2559 entry
->status
= git_wc_status_ignored
;
2560 entry
->textstatus
= git_wc_status_ignored
;
2563 toremove
.push_back(entry
->GetPath().GetSVNPathString());
2569 CTSVNPath basepath
= m_arStatusArray
[m_arListArray
[selIndex
]]->basepath
;
2571 FileEntry
* entry
= m_arStatusArray
[m_arListArray
[selIndex
]];
2572 if ( entry
->status
== git_wc_status_unversioned
) // keep "deleted" items
2573 toremove
.push_back(entry
->GetPath().GetSVNPathString());
2575 if (!m_bIgnoreRemoveOnly
)
2578 git_wc_status2_t
* s
;
2580 s
= status
.GetFirstFileStatus(parentfolder
, gitPath
, false, git_depth_empty
);
2581 // first check if the folder isn't already present in the list
2582 bool bFound
= false;
2583 nListboxEntries
= GetItemCount();
2584 for (int i
=0; i
<nListboxEntries
; ++i
)
2586 FileEntry
* entry
= GetListEntry(i
);
2587 if (entry
->path
.IsEquivalentTo(gitPath
))
2597 FileEntry
* entry
= new FileEntry();
2598 entry
->path
= gitPath
;
2599 entry
->basepath
= basepath
;
2600 entry
->status
= SVNStatus::GetMoreImportant(s
->text_status
, s
->prop_status
);
2601 entry
->textstatus
= s
->text_status
;
2602 entry
->propstatus
= s
->prop_status
;
2603 entry
->remotestatus
= SVNStatus::GetMoreImportant(s
->repos_text_status
, s
->repos_prop_status
);
2604 entry
->remotetextstatus
= s
->repos_text_status
;
2605 entry
->remotepropstatus
= s
->repos_prop_status
;
2606 entry
->inunversionedfolder
= FALSE
;
2607 entry
->checked
= true;
2608 entry
->inexternal
= false;
2609 entry
->direct
= false;
2610 entry
->isfolder
= true;
2611 entry
->last_commit_date
= 0;
2612 entry
->last_commit_rev
= 0;
2613 entry
->remoterev
= 0;
2618 entry
->url
= CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s
->entry
->url
));
2621 if (s
->entry
&& s
->entry
->present_props
)
2623 entry
->present_props
= s
->entry
->present_props
;
2625 m_arStatusArray
.push_back(entry
);
2626 m_arListArray
.push_back(m_arStatusArray
.size()-1);
2627 AddEntry(entry
, langID
, GetItemCount());
2632 for (std::vector
<CString
>::iterator it
= toremove
.begin(); it
!= toremove
.end(); ++it
)
2634 int nListboxEntries
= GetItemCount();
2635 for (int i
=0; i
<nListboxEntries
; ++i
)
2637 if (GetListEntry(i
)->path
.GetSVNPathString().Compare(*it
)==0)
2648 case IDSVNLC_IGNOREMASK
:
2651 CString ext
=filepath
->GetFileExtension();
2652 CTGitPathList ignorelist
;
2653 FillListOfSelectedItemPaths(ignorelist
, true);
2656 CAppUtils::IgnoreFile(ignorelist
,true);
2658 common
=ignorelist
.GetCommonRoot().GetGitPathString();
2660 for (int i
=0; i
< GetItemCount(); ++i
)
2662 CTGitPath
*path
=(CTGitPath
*)GetItemData(i
);
2663 if(!( path
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
2665 if( path
->GetGitPathString().Left(common
.GetLength()) == common
)
2667 if (path
->GetFileExtension()==ext
)
2670 i
--; // remove index i at item, new one will replace.
2675 CWnd
* pParent
= GetParent();
2676 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2678 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
2684 std::set
<CTSVNPath
> parentlist
;
2685 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
2687 parentlist
.insert(ignorelist
[i
].GetContainingDirectory());
2689 std::set
<CTSVNPath
>::iterator it
;
2690 std::vector
<CString
> toremove
;
2692 for (it
= parentlist
.begin(); it
!= parentlist
.end(); ++it
)
2694 CTSVNPath parentFolder
= (*it
).GetDirectory();
2695 SVNProperties
props(parentFolder
, SVNRev::REV_WC
, false);
2697 for (int i
=0; i
<props
.GetCount(); i
++)
2699 CString
propname(props
.GetItemName(i
).c_str());
2700 if (propname
.CompareNoCase(_T("git:ignore"))==0)
2703 // treat values as normal text even if they're not
2704 value
= (char *)props
.GetItemValue(i
).c_str();
2707 if (value
.IsEmpty())
2711 value
= value
.Trim("\n\r");
2716 if (!props
.Add(_T("git:ignore"), (LPCSTR
)value
))
2719 temp
.Format(IDS_ERR_FAILEDIGNOREPROPERTY
, (LPCTSTR
)name
);
2720 CMessageBox::Show(this->m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONERROR
);
2725 int nListboxEntries
= GetItemCount();
2726 for (int i
=0; i
<nListboxEntries
; ++i
)
2728 FileEntry
* entry
= GetListEntry(i
);
2729 ASSERT(entry
!= NULL
);
2732 if (basepath
.IsEmpty())
2733 basepath
= entry
->basepath
;
2734 // since we ignored files with a mask (e.g. *.exe)
2735 // we have to find find all files in the same
2736 // folder (IsAncestorOf() returns TRUE for _all_ children,
2737 // not just the immediate ones) which match the
2738 // mask and remove them from the list too.
2739 if ((entry
->status
== git_wc_status_unversioned
)&&(parentFolder
.IsAncestorOf(entry
->path
)))
2741 CString f
= entry
->path
.GetSVNPathString();
2742 if (f
.Mid(parentFolder
.GetSVNPathString().GetLength()).Find('/')<=0)
2744 if (CStringUtils::WildCardMatch(name
, f
))
2749 toremove
.push_back(f
);
2754 if (!m_bIgnoreRemoveOnly
)
2757 git_wc_status2_t
* s
;
2759 s
= status
.GetFirstFileStatus(parentFolder
, gitPath
, false, git_depth_empty
);
2762 // first check if the folder isn't already present in the list
2763 bool bFound
= false;
2764 for (int i
=0; i
<nListboxEntries
; ++i
)
2766 FileEntry
* entry
= GetListEntry(i
);
2767 if (entry
->path
.IsEquivalentTo(gitPath
))
2775 FileEntry
* entry
= new FileEntry();
2776 entry
->path
= gitPath
;
2777 entry
->basepath
= basepath
;
2778 entry
->status
= SVNStatus::GetMoreImportant(s
->text_status
, s
->prop_status
);
2779 entry
->textstatus
= s
->text_status
;
2780 entry
->propstatus
= s
->prop_status
;
2781 entry
->remotestatus
= SVNStatus::GetMoreImportant(s
->repos_text_status
, s
->repos_prop_status
);
2782 entry
->remotetextstatus
= s
->repos_text_status
;
2783 entry
->remotepropstatus
= s
->repos_prop_status
;
2784 entry
->inunversionedfolder
= false;
2785 entry
->checked
= true;
2786 entry
->inexternal
= false;
2787 entry
->direct
= false;
2788 entry
->isfolder
= true;
2789 entry
->last_commit_date
= 0;
2790 entry
->last_commit_rev
= 0;
2791 entry
->remoterev
= 0;
2796 entry
->url
= CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s
->entry
->url
));
2799 if (s
->entry
&& s
->entry
->present_props
)
2801 entry
->present_props
= s
->entry
->present_props
;
2803 m_arStatusArray
.push_back(entry
);
2804 m_arListArray
.push_back(m_arStatusArray
.size()-1);
2805 AddEntry(entry
, langID
, GetItemCount());
2811 for (std::vector
<CString
>::iterator it
= toremove
.begin(); it
!= toremove
.end(); ++it
)
2813 int nListboxEntries
= GetItemCount();
2814 for (int i
=0; i
<nListboxEntries
; ++i
)
2816 if (GetListEntry(i
)->path
.GetSVNPathString().Compare(*it
)==0)
2828 case IDSVNLC_REVERT
:
2830 // If at least one item is not in the status "added"
2831 // we ask for a confirmation
2832 BOOL bConfirm
= FALSE
;
2833 POSITION pos
= GetFirstSelectedItemPosition();
2835 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2837 //FileEntry * fentry = GetListEntry(index);
2838 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
2839 if(fentry
&& fentry
->m_Action
&CTGitPath::LOGACTIONS_MODIFIED
)
2847 str
.Format(IDS_PROC_WARNREVERT
,GetSelectedCount());
2849 if (!bConfirm
|| CMessageBox::Show(this->m_hWnd
, str
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
2851 CTGitPathList targetList
;
2852 FillListOfSelectedItemPaths(targetList
);
2854 // make sure that the list is reverse sorted, so that
2855 // children are removed before any parents
2856 targetList
.SortByPathname(true);
2858 // put all reverted files in the trashbin, except the ones with 'added'
2859 // status because they are not restored by the revert.
2860 CTGitPathList delList
;
2861 POSITION pos
= GetFirstSelectedItemPosition();
2863 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2865 CTGitPath
*entry
=(CTGitPath
*)GetItemData(index
);
2866 if (entry
&&(!(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
))
2867 && (!(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)))
2870 fullpath
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+entry
->GetWinPath());
2871 delList
.AddPath(fullpath
);
2874 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
2875 delList
.DeleteAllFiles(true);
2877 if (g_Git
.Revert(targetList
))
2879 CMessageBox::Show(this->m_hWnd
, _T("Revert Fail"), _T("TortoiseGit"), MB_ICONERROR
);
2883 bool updateStatusList
= false;
2884 for(int i
=0;i
<targetList
.GetCount();i
++)
2886 int nListboxEntries
= GetItemCount();
2887 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2889 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2890 if (path
->GetGitPathString()==targetList
[i
].GetGitPathString())
2892 if(path
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2894 path
->m_Action
= CTGitPath::LOGACTIONS_UNVER
;
2895 SetEntryCheck(path
,nItem
,false);
2896 updateStatusList
= true;
2897 SetItemGroup(nItem
,1);
2898 this->m_StatusFileList
.RemoveItem(*path
);
2899 this->m_UnRevFileList
.AddPath(*path
);
2900 //this->m_IgnoreFileList.RemoveItem(*path);
2904 RemoveListEntry(nItem
);
2912 Show(m_dwShow
, 0, m_bShowFolders
,updateStatusList
,true);
2920 CopySelectedEntriesToClipboard(0);
2922 case IDSVNLC_COPYEXT
:
2923 CopySelectedEntriesToClipboard((DWORD
)-1);
2926 case IDSVNLC_SAVEAS
:
2927 FileSaveAs(filepath
);
2930 case IDSVNLC_REVERTTOREV
:
2931 RevertSelectedItemToVersion();
2934 case IDSVNLC_PROPERTIES
:
2936 CTSVNPathList targetList
;
2937 FillListOfSelectedItemPaths(targetList
);
2938 CEditPropertiesDlg dlg
;
2939 dlg
.SetPathList(targetList
);
2941 if (dlg
.HasChanged())
2943 // since the user might have changed/removed/added
2944 // properties recursively, we don't really know
2945 // which items have changed their status.
2946 // So tell the parent to do a refresh.
2947 CWnd
* pParent
= GetParent();
2948 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
2950 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
2955 case IDSVNLC_COMMIT
:
2957 CTSVNPathList targetList
;
2958 FillListOfSelectedItemPaths(targetList
);
2959 CTSVNPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2960 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2961 CString commandline
= CPathUtils::GetAppDirectory();
2962 commandline
+= _T("TortoiseProc.exe /command:commit /pathfile:\"");
2963 commandline
+= tempFile
.GetWinPathString();
2964 commandline
+= _T("\"");
2965 commandline
+= _T(" /deletepathfile");
2966 CAppUtils::LaunchApplication(commandline
, NULL
, false);
2970 case IDSVNLC_COMPAREWC
:
2972 POSITION pos
= GetFirstSelectedItemPosition();
2975 int index
= GetNextSelectedItem(pos
);
2976 FileEntry
* entry
= GetListEntry(index
);
2977 ASSERT(entry
!= NULL
);
2980 SVNDiff
diff(NULL
, m_hWnd
, true);
2981 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2982 git_revnum_t baseRev
= entry
->Revision
;
2983 diff
.DiffFileAgainstBase(
2984 entry
->path
, baseRev
, entry
->textstatus
, entry
->propstatus
);
2988 case IDSVNLC_GNUDIFF1
:
2990 SVNDiff
diff(NULL
, this->m_hWnd
, true);
2992 if (entry
->remotestatus
<= git_wc_status_normal
)
2993 CAppUtils::StartShowUnifiedDiff(m_hWnd
, entry
->path
, SVNRev::REV_BASE
, entry
->path
, SVNRev::REV_WC
);
2995 CAppUtils::StartShowUnifiedDiff(m_hWnd
, entry
->path
, SVNRev::REV_WC
, entry
->path
, SVNRev::REV_HEAD
);
2998 case IDSVNLC_UPDATE
:
3000 CTSVNPathList targetList
;
3001 FillListOfSelectedItemPaths(targetList
);
3002 bool bAllExist
= true;
3003 for (int i
=0; i
<targetList
.GetCount(); ++i
)
3005 if (!targetList
[i
].Exists())
3013 CSVNProgressDlg dlg
;
3014 dlg
.SetCommand(CSVNProgressDlg::SVNProgress_Update
);
3015 dlg
.SetPathList(targetList
);
3016 dlg
.SetRevision(SVNRev::REV_HEAD
);
3021 CString sTempFile
= CTempFiles::Instance().GetTempFilePath(false).GetWinPathString();
3022 targetList
.WriteToFile(sTempFile
, false);
3024 sCmd
.Format(_T("\"%s\" /command:update /rev /pathfile:\"%s\" /deletepathfile"),
3025 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR
)sTempFile
);
3027 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
3032 case IDSVNLC_REMOVE
:
3035 CTSVNPathList itemsToRemove
;
3036 FillListOfSelectedItemPaths(itemsToRemove
);
3038 // We must sort items before removing, so that files are always removed
3039 // *before* their parents
3040 itemsToRemove
.SortByPathname(true);
3042 bool bSuccess
= false;
3043 if (git
.Remove(itemsToRemove
, FALSE
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)))
3049 if ((git
.Err
->apr_err
== SVN_ERR_UNVERSIONED_RESOURCE
) ||
3050 (git
.Err
->apr_err
== SVN_ERR_CLIENT_MODIFIED
))
3052 CString msg
, yes
, no
, yestoall
;
3053 msg
.Format(IDS_PROC_REMOVEFORCE
, (LPCTSTR
)git
.GetLastErrorMessage());
3054 yes
.LoadString(IDS_MSGBOX_YES
);
3055 no
.LoadString(IDS_MSGBOX_NO
);
3056 yestoall
.LoadString(IDS_PROC_YESTOALL
);
3057 UINT ret
= CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_ERROR
, yes
, no
, yestoall
);
3058 if ((ret
== 1)||(ret
==3))
3060 if (!git
.Remove(itemsToRemove
, TRUE
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)))
3062 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3069 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3073 // The remove went ok, but we now need to run through the selected items again
3074 // and update their status
3075 POSITION pos
= GetFirstSelectedItemPosition();
3077 std::vector
<int> entriesToRemove
;
3078 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3080 FileEntry
* e
= GetListEntry(index
);
3082 ((e
->textstatus
== git_wc_status_unversioned
)||
3083 (e
->textstatus
== git_wc_status_none
)||
3084 (e
->textstatus
== git_wc_status_ignored
)))
3086 if (GetCheck(index
))
3089 entriesToRemove
.push_back(index
);
3093 e
->textstatus
= git_wc_status_deleted
;
3094 e
->status
= git_wc_status_deleted
;
3095 SetEntryCheck(e
,index
,true);
3098 for (std::vector
<int>::reverse_iterator it
= entriesToRemove
.rbegin(); it
!= entriesToRemove
.rend(); ++it
)
3100 RemoveListEntry(*it
);
3104 Show(m_dwShow
, 0, m_bShowFolders
);
3108 case IDSVNLC_DELETE
:
3110 CTSVNPathList pathlist
;
3111 FillListOfSelectedItemPaths(pathlist
);
3112 pathlist
.RemoveChildren();
3114 for (INT_PTR i
=0; i
<pathlist
.GetCount(); ++i
)
3116 filelist
+= pathlist
[i
].GetWinPathString();
3117 filelist
+= _T("|");
3119 filelist
+= _T("|");
3120 int len
= filelist
.GetLength();
3121 TCHAR
* buf
= new TCHAR
[len
+2];
3122 _tcscpy_s(buf
, len
+2, filelist
);
3123 for (int i
=0; i
<len
; ++i
)
3126 SHFILEOPSTRUCT fileop
;
3127 fileop
.hwnd
= this->m_hWnd
;
3128 fileop
.wFunc
= FO_DELETE
;
3131 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
3132 fileop
.lpszProgressTitle
= _T("deleting file");
3133 int result
= SHFileOperation(&fileop
);
3136 if ( (result
==0) && (!fileop
.fAnyOperationsAborted
) )
3139 POSITION pos
= NULL
;
3140 CTSVNPathList deletedlist
; // to store list of deleted folders
3141 while ((pos
= GetFirstSelectedItemPosition()) != 0)
3143 int index
= GetNextSelectedItem(pos
);
3144 if (GetCheck(index
))
3147 FileEntry
* fentry
= GetListEntry(index
);
3148 if ((fentry
)&&(fentry
->isfolder
))
3149 deletedlist
.AddPath(fentry
->path
);
3150 RemoveListEntry(index
);
3152 // now go through the list of deleted folders
3153 // and remove all their children from the list too!
3154 int nListboxEntries
= GetItemCount();
3155 for (int folderindex
= 0; folderindex
< deletedlist
.GetCount(); ++folderindex
)
3157 CTSVNPath folderpath
= deletedlist
[folderindex
];
3158 for (int i
=0; i
<nListboxEntries
; ++i
)
3160 FileEntry
* entry
= GetListEntry(i
);
3161 if (folderpath
.IsAncestorOf(entry
->path
))
3163 RemoveListEntry(i
--);
3177 CTSVNPathList itemsToAdd
;
3178 FillListOfSelectedItemPaths(itemsToAdd
);
3180 // We must sort items before adding, so that folders are always added
3181 // *before* any of their children
3182 itemsToAdd
.SortByPathname();
3184 ProjectProperties props
;
3185 props
.ReadPropsPathList(itemsToAdd
);
3186 if (git
.Add(itemsToAdd
, &props
, git_depth_empty
, TRUE
, TRUE
, TRUE
))
3188 // The add went ok, but we now need to run through the selected items again
3189 // and update their status
3190 POSITION pos
= GetFirstSelectedItemPosition();
3192 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3194 FileEntry
* e
= GetListEntry(index
);
3195 e
->textstatus
= git_wc_status_added
;
3196 e
->propstatus
= git_wc_status_none
;
3197 e
->status
= git_wc_status_added
;
3198 SetEntryCheck(e
,index
,true);
3203 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3206 Show(m_dwShow
, 0, m_bShowFolders
);
3210 case IDSVNLC_ADD_RECURSIVE
:
3212 CTSVNPathList itemsToAdd
;
3213 FillListOfSelectedItemPaths(itemsToAdd
);
3216 dlg
.m_pathList
= itemsToAdd
;
3217 if (dlg
.DoModal() == IDOK
)
3219 if (dlg
.m_pathList
.GetCount() == 0)
3221 CSVNProgressDlg progDlg
;
3222 progDlg
.SetCommand(CSVNProgressDlg::SVNProgress_Add
);
3223 progDlg
.SetPathList(dlg
.m_pathList
);
3224 ProjectProperties props
;
3225 props
.ReadPropsPathList(dlg
.m_pathList
);
3226 progDlg
.SetProjectProperties(props
);
3227 progDlg
.SetItemCount(dlg
.m_pathList
.GetCount());
3231 CWnd
* pParent
= GetParent();
3232 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3234 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
3240 case IDSVNLC_REPAIRMOVE
:
3242 POSITION pos
= GetFirstSelectedItemPosition();
3243 int index
= GetNextSelectedItem(pos
);
3244 FileEntry
* entry1
= NULL
;
3245 FileEntry
* entry2
= NULL
;
3248 entry1
= GetListEntry(index
);
3249 git_wc_status_kind status1
= git_wc_status_none
;
3250 git_wc_status_kind status2
= git_wc_status_none
;
3253 status1
= entry1
->status
;
3254 index
= GetNextSelectedItem(pos
);
3257 entry2
= GetListEntry(index
);
3260 status2
= entry2
->status
;
3261 if (status2
== git_wc_status_missing
&& status1
== git_wc_status_unversioned
)
3263 FileEntry
* tempentry
= entry1
;
3267 // entry1 was renamed to entry2 but outside of Subversion
3268 // fix this by moving entry2 back to entry1 first,
3269 // then do an git-move from entry1 to entry2
3270 if (MoveFile(entry2
->GetPath().GetWinPath(), entry1
->GetPath().GetWinPath()))
3273 if (!git
.Move(CTSVNPathList(entry1
->GetPath()), entry2
->GetPath(), TRUE
))
3275 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3279 // check the previously unversioned item
3280 entry1
->checked
= true;
3281 // fixing the move was successful. We have to adjust the new status of the
3283 // Since we don't know if the moved/renamed file had local modifications or not,
3284 // we can't guess the new status. That means we have to refresh...
3285 CWnd
* pParent
= GetParent();
3286 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
3288 pParent
->SendMessage(SVNSLNM_NEEDSREFRESH
);
3295 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
3296 FORMAT_MESSAGE_FROM_SYSTEM
|
3297 FORMAT_MESSAGE_IGNORE_INSERTS
,
3300 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
3305 MessageBox((LPCTSTR
)lpMsgBuf
, _T("Error"), MB_OK
| MB_ICONINFORMATION
);
3306 LocalFree( lpMsgBuf
);
3314 case IDSVNLC_REMOVEFROMCS
:
3316 CTSVNPathList changelistItems
;
3317 FillListOfSelectedItemPaths(changelistItems
);
3320 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
3322 // The changelists were removed, but we now need to run through the selected items again
3323 // and update their changelist
3324 POSITION pos
= GetFirstSelectedItemPosition();
3326 std::vector
<int> entriesToRemove
;
3327 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3329 FileEntry
* e
= GetListEntry(index
);
3332 e
->changelist
.Empty();
3333 if (e
->status
== git_wc_status_normal
)
3335 // remove the entry completely
3336 entriesToRemove
.push_back(index
);
3339 SetItemGroup(index
, 0);
3342 for (std::vector
<int>::reverse_iterator it
= entriesToRemove
.rbegin(); it
!= entriesToRemove
.rend(); ++it
)
3344 RemoveListEntry(*it
);
3346 // TODO: Should we go through all entries here and check if we also could
3347 // remove the changelist from m_changelists ?
3351 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3356 case IDSVNLC_CREATEIGNORECS
:
3357 CreateChangeList(SVNSLC_IGNORECHANGELIST
);
3359 case IDSVNLC_CREATECS
:
3361 CCreateChangelistDlg dlg
;
3362 if (dlg
.DoModal() == IDOK
)
3364 CreateChangeList(dlg
.m_sName
);
3370 if (cmd
< IDSVNLC_MOVETOCS
)
3372 CTSVNPathList changelistItems
;
3373 FillListOfSelectedItemPaths(changelistItems
);
3375 // find the changelist name
3376 CString sChangelist
;
3377 int cmdID
= IDSVNLC_MOVETOCS
;
3379 for (std::map
<CString
, int>::const_iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
3381 if ((it
->first
.Compare(SVNSLC_IGNORECHANGELIST
))&&(entry
->changelist
.Compare(it
->first
)))
3385 sChangelist
= it
->first
;
3390 if (!sChangelist
.IsEmpty())
3393 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
3395 // The changelists were moved, but we now need to run through the selected items again
3396 // and update their changelist
3397 POSITION pos
= GetFirstSelectedItemPosition();
3399 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3401 FileEntry
* e
= GetListEntry(index
);
3402 e
->changelist
= sChangelist
;
3405 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
3406 SetItemGroup(index
, m_changelists
[e
->changelist
]);
3408 SetItemGroup(index
, 0);
3414 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3424 AfxGetApp()->DoWaitCursor(-1);
3425 GetStatisticsString();
3426 //int iItemCountAfterMenuCmd = GetItemCount();
3427 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
3429 // CWnd* pParent = GetParent();
3430 // if (NULL != pParent && NULL != pParent->GetSafeHwnd())
3432 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
3435 } // if (popup.CreatePopupMenu())
3436 } // if (selIndex >= 0)
3440 void CGitStatusListCtrl::OnContextMenuHeader(CWnd
* pWnd
, CPoint point
)
3442 Locker
lock(m_critSec
);
3443 m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
3446 void CGitStatusListCtrl::OnContextMenu(CWnd
* pWnd
, CPoint point
)
3451 OnContextMenuList(pWnd
, point
);
3452 } // if (pWnd == this)
3453 else if (pWnd
== GetHeaderCtrl())
3455 OnContextMenuHeader(pWnd
, point
);
3459 void CGitStatusListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3462 Locker
lock(m_critSec
);
3463 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
3468 if (pNMLV
->iItem
< 0)
3470 if (!IsGroupViewEnabled())
3473 DWORD ptW
= GetMessagePos();
3474 pt
.x
= GET_X_LPARAM(ptW
);
3475 pt
.y
= GET_Y_LPARAM(ptW
);
3476 ScreenToClient(&pt
);
3477 int group
= GetGroupFromPoint(&pt
);
3480 // check/uncheck the whole group depending on the check-state
3481 // of the first item in the group
3483 bool bCheck
= false;
3484 bool bFirst
= false;
3486 for (int i
=0; i
<GetItemCount(); ++i
)
3488 SecureZeroMemory(&lv
, sizeof(LVITEM
));
3489 lv
.mask
= LVIF_GROUPID
;
3492 if (lv
.iGroupId
== group
)
3494 CTGitPath
*entry
=(CTGitPath
*)GetItemData(i
);
3498 bCheck
= !GetCheck(i
);
3503 bool bOldCheck
= !!GetCheck(i
);
3504 SetEntryCheck(entry
, i
, bCheck
);
3505 if (bCheck
!= bOldCheck
)
3515 GetStatisticsString();
3521 CTGitPath
*file
=(CTGitPath
*)GetItemData(pNMLV
->iItem
);
3523 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
) {
3524 OpenFile(file
, OPEN
);
3527 if( file
->m_Action
&CTGitPath::LOGACTIONS_UNMERGED
)
3529 CAppUtils::ConflictEdit(*file
,false,m_bIsRevertTheirMy
);
3533 if( (!m_Rev1
.IsEmpty()) || (!m_Rev1
.IsEmpty())) // m_Rev1 twice???
3534 StartDiffTwo(pNMLV
->iItem
);
3536 StartDiff(pNMLV
->iItem
);
3540 void CGitStatusListCtrl::StartDiffTwo(int fileindex
)
3545 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3547 CGitDiff::Diff(&file1
,&file1
,
3552 void CGitStatusListCtrl::StartDiffWC(int fileindex
)
3558 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
3561 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3563 CGitDiff::Diff(&file1
,&file1
, GIT_REV_ZERO
, m_CurrentVersion
);
3567 void CGitStatusListCtrl::StartDiff(int fileindex
)
3572 CTGitPath file1
=*(CTGitPath
*)GetItemData(fileindex
);
3574 if(file1
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
3576 file2
.SetFromGit(file1
.GetGitOldPathString());
3582 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
3586 fromwhere
= _T("~1");
3587 if( g_Git
.IsInitRepos())
3588 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3590 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_ADDED
)
3591 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3592 m_CurrentVersion
+fromwhere
,true);
3593 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_DELETED
)
3594 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
3595 GitRev::GetHead()+fromwhere
,false);
3597 CGitDiff::Diff(&file1
,&file2
,
3598 CString(GIT_REV_ZERO
),
3599 GitRev::GetHead()+fromwhere
);
3603 CString fromwhere
= m_CurrentVersion
+_T("~1");
3605 fromwhere
= m_CurrentVersion
+_T("~2");
3606 if(rev
.GetCommit(fromwhere
) || (file1
.m_Action
== file1
.LOGACTIONS_ADDED
))
3608 CGitDiff::DiffNull(&file1
,m_CurrentVersion
,true);
3610 } else if (file1
.m_Action
== file1
.LOGACTIONS_DELETED
) {
3611 CGitDiff::DiffNull(&file1
,fromwhere
,false);
3614 if( file1
.m_ParentNo
& MERGE_MASK
)
3617 CTGitPath base
,theirs
, mine
;
3619 CTGitPath merge
=file1
;
3620 CTGitPath directory
= merge
.GetDirectory();
3622 mine
.SetFromGit(CAppUtils::GetMergeTempFile(_T("LOCAL"),merge
));
3623 theirs
.SetFromGit(CAppUtils::GetMergeTempFile(_T("REMOTE"),merge
));
3624 base
.SetFromGit(CAppUtils::GetMergeTempFile(_T("BASE"),merge
));
3627 //create a empty file, incase stage is not three
3628 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3630 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3632 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
3635 merge
.SetFromGit(merge
.GetGitPathString()+_T("Merged"));
3637 int parent1
=-1, parent2
=-1;
3638 for(int i
=0;i
<this->m_arStatusArray
.size();i
++)
3640 if(m_arStatusArray
[i
]->GetGitPathString() == file1
.GetGitPathString())
3642 if(m_arStatusArray
[i
]->m_ParentNo
& MERGE_MASK
)
3648 parent1
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
3649 }else if (parent2
<0)
3651 parent2
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
3657 if(g_Git
.GetOneFile(m_CurrentVersion
, file1
, (CString
&)merge
.GetWinPathString()))
3659 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3665 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent1
+1);
3667 if(g_Git
.GetOneFile(str
, file1
, (CString
&)mine
.GetWinPathString()))
3669 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3676 str
.Format(_T("%s^%d"),this->m_CurrentVersion
, parent2
+1);
3678 if(g_Git
.GetOneFile(str
, file1
, (CString
&)theirs
.GetWinPathString()))
3680 CMessageBox::Show(NULL
, _T("Fail to get merge file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3684 if(parent1
>=0 && parent2
>=0)
3687 cmd
.Format(_T("git.exe merge-base %s^%d %s^%d"), this->m_CurrentVersion
, parent1
+1,
3688 this->m_CurrentVersion
,parent2
+1);
3690 if(g_Git
.Run(cmd
,&output
, CP_ACP
))
3694 if(g_Git
.GetOneFile(output
.Left(40), file1
, (CString
&)base
.GetWinPathString()))
3696 CMessageBox::Show(NULL
, _T("Fail to get base file"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
3700 CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
3705 if( (file1
.m_ParentNo
&PARENT_MASK
) == 0)
3710 str
.Format(_T("^%d"), (file1
.m_ParentNo
&PARENT_MASK
)+1);
3712 CGitDiff::Diff(&file1
,&file2
,
3714 m_CurrentVersion
+str
);
3721 FileEntry
* entry
= GetListEntry(fileindex
);
3722 ASSERT(entry
!= NULL
);
3725 if (((entry
->status
== git_wc_status_normal
)&&(entry
->remotestatus
<= git_wc_status_normal
))||
3726 (entry
->status
== git_wc_status_unversioned
)||(entry
->status
== git_wc_status_none
))
3728 int ret
= (int)ShellExecute(this->m_hWnd
, NULL
, entry
->path
.GetWinPath(), NULL
, NULL
, SW_SHOW
);
3729 if (ret
<= HINSTANCE_ERROR
)
3731 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
3732 cmd
+= entry
->path
.GetWinPathString();
3733 CAppUtils::LaunchApplication(cmd
, NULL
, false);
3738 GitDiff
diff(NULL
, m_hWnd
, true);
3739 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
3741 entry
->path
, entry
->textstatus
, entry
->propstatus
,
3742 entry
->remotetextstatus
, entry
->remotepropstatus
);
3746 CString
CGitStatusListCtrl::GetStatisticsString(bool simple
)
3749 CString sNormal
, sAdded
, sDeleted
, sModified
, sConflicted
, sUnversioned
, sRenamed
;
3750 WORD langID
= (WORD
)(DWORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3751 TCHAR buf
[MAX_STATUS_STRING_LENGTH
];
3752 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_normal
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3754 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_added
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3756 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_deleted
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3758 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_modified
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3760 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_conflicted
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3762 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_unversioned
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3764 GitStatus::GetStatusString(AfxGetResourceHandle(), git_wc_status_replaced
, buf
, sizeof(buf
)/sizeof(TCHAR
), langID
);
3769 sToolTip
.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d"),
3770 this->m_nLineAdded
,this->m_nLineDeleted
,
3771 (LPCTSTR
)sModified
, m_nModified
,
3772 (LPCTSTR
)sAdded
, m_nAdded
,
3773 (LPCTSTR
)sDeleted
, m_nDeleted
,
3774 (LPCTSTR
)sRenamed
, m_nRenamed
3778 sToolTip
.Format(_T("line: %d(+) %d(-) files: %s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d\n%s = %d"),
3779 this->m_nLineAdded
,this->m_nLineDeleted
,
3780 (LPCTSTR
)sNormal
, m_nNormal
,
3781 (LPCTSTR
)sUnversioned
, m_nUnversioned
,
3782 (LPCTSTR
)sModified
, m_nModified
,
3783 (LPCTSTR
)sAdded
, m_nAdded
,
3784 (LPCTSTR
)sDeleted
, m_nDeleted
,
3785 (LPCTSTR
)sConflicted
, m_nConflicted
3789 sStats
.Format(IDS_COMMITDLG_STATISTICSFORMAT
, m_nSelected
, GetItemCount());
3792 m_pStatLabel
->SetWindowText(sStats
);
3795 if (m_pSelectButton
)
3797 if (m_nSelected
== 0)
3798 m_pSelectButton
->SetCheck(BST_UNCHECKED
);
3799 else if (m_nSelected
!= GetItemCount())
3800 m_pSelectButton
->SetCheck(BST_INDETERMINATE
);
3802 m_pSelectButton
->SetCheck(BST_CHECKED
);
3805 if (m_pConfirmButton
)
3807 m_pConfirmButton
->EnableWindow(m_nSelected
>0);
3815 CString
CGitStatusListCtrl::GetCommonDirectory(bool bStrict
)
3819 // not strict means that the selected folder has priority
3820 if (!m_StatusFileList
.GetCommonDirectory().IsEmpty())
3821 return m_StatusFileList
.GetCommonDirectory().GetWinPath();
3824 CTGitPath commonBaseDirectory
;
3825 int nListItems
= GetItemCount();
3826 for (int i
=0; i
<nListItems
; ++i
)
3828 CTGitPath baseDirectory
,*p
= (CTGitPath
*)this->GetItemData(i
);
3832 baseDirectory
= p
->GetDirectory();
3834 if(commonBaseDirectory
.IsEmpty())
3836 commonBaseDirectory
= baseDirectory
;
3840 if (commonBaseDirectory
.GetWinPathString().GetLength() > baseDirectory
.GetWinPathString().GetLength())
3842 if (baseDirectory
.IsAncestorOf(commonBaseDirectory
))
3843 commonBaseDirectory
= baseDirectory
;
3847 return g_Git
.m_CurrentDir
+CString(_T("\\"))+commonBaseDirectory
.GetWinPath();
3851 void CGitStatusListCtrl::SelectAll(bool bSelect
, bool /*bIncludeNoCommits*/)
3853 CWaitCursor waitCursor
;
3854 // block here so the LVN_ITEMCHANGED messages
3859 int nListItems
= GetItemCount();
3861 m_nSelected
= nListItems
;
3865 for (int i
=0; i
<nListItems
; ++i
)
3867 //FileEntry * entry = GetListEntry(i);
3868 //ASSERT(entry != NULL);
3869 CTGitPath
*path
= (CTGitPath
*) GetItemData(i
);
3872 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
3873 SetEntryCheck(path
,i
,bSelect
);
3876 // unblock before redrawing
3879 GetStatisticsString();
3883 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3885 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
3890 CTGitPath
*entry
=(CTGitPath
*)GetItemData(pGetInfoTip
->iItem
);
3893 if (pGetInfoTip
->cchTextMax
> entry
->GetGitPathString().GetLength() + g_Git
.m_CurrentDir
.GetLength())
3896 str
+= g_Git
.m_CurrentDir
;
3898 str
+= entry
->GetWinPathString();
3900 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, str
.GetBuffer(), str
.GetLength());
3904 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3906 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
3908 // Take the default processing unless we set this to something else below.
3909 *pResult
= CDRF_DODEFAULT
;
3911 // First thing - check the draw stage. If it's the control's prepaint
3912 // stage, then tell Windows we want messages for every item.
3914 switch (pLVCD
->nmcd
.dwDrawStage
)
3917 *pResult
= CDRF_NOTIFYITEMDRAW
;
3919 case CDDS_ITEMPREPAINT
:
3921 // This is the prepaint stage for an item. Here's where we set the
3922 // item's text color. Our return value will tell Windows to draw the
3923 // item itself, but it will use the new color we set here.
3925 // Tell Windows to paint the control itself.
3926 *pResult
= CDRF_DODEFAULT
;
3930 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
3932 if (m_arStatusArray
.size() > (DWORD_PTR
)pLVCD
->nmcd
.dwItemSpec
)
3935 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3936 CTGitPath
*entry
=(CTGitPath
*)GetItemData((int)pLVCD
->nmcd
.dwItemSpec
);
3942 // black : unversioned, normal
3945 // brown : missing, deleted, replaced
3946 // green : merged (or potential merges)
3947 // red : conflicts or sure conflicts
3948 if(entry
->m_Action
& CTGitPath::LOGACTIONS_GRAY
)
3950 crText
= RGB(128,128,128);
3952 }else if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
3954 crText
= m_Colors
.GetColor(CColors::Conflict
);
3956 }else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_MODIFIED
))
3958 crText
= m_Colors
.GetColor(CColors::Modified
);
3960 }else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
3962 crText
= m_Colors
.GetColor(CColors::Added
);
3964 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3966 crText
= m_Colors
.GetColor(CColors::DeletedNode
);
3968 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
3970 crText
= m_Colors
.GetColor(CColors::RenamedNode
);
3971 }else if(entry
->m_Action
& CTGitPath::LOGACTIONS_MERGED
)
3973 crText
= m_Colors
.GetColor(CColors::Merged
);
3976 crText
= GetSysColor(COLOR_WINDOWTEXT
);
3978 // Store the color back in the NMLVCUSTOMDRAW struct.
3979 pLVCD
->clrText
= crText
;
3986 BOOL
CGitStatusListCtrl::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
3989 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3992 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
3994 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3996 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_WAIT
));
4001 void CGitStatusListCtrl::RemoveListEntry(int index
)
4004 Locker
lock(m_critSec
);
4007 m_arStatusArray
.erase(m_arStatusArray
.begin()+index
);
4010 delete m_arStatusArray
[m_arListArray
[index
]];
4011 m_arStatusArray
.erase(m_arStatusArray
.begin()+m_arListArray
[index
]);
4012 m_arListArray
.erase(m_arListArray
.begin()+index
);
4013 for (int i
=index
; i
< (int)m_arListArray
.size(); ++i
)
4020 ///< Set a checkbox on an entry in the listbox
4021 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
4022 void CGitStatusListCtrl::SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
)
4024 pEntry
->m_Checked
= bCheck
;
4025 SetCheck(listboxIndex
, bCheck
);
4029 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry
* parentEntry
, bool bCheck
)
4032 int nListItems
= GetItemCount();
4033 for (int j
=0; j
< nListItems
; ++j
)
4035 FileEntry
* childEntry
= GetListEntry(j
);
4036 ASSERT(childEntry
!= NULL
);
4037 if (childEntry
== NULL
|| childEntry
== parentEntry
)
4039 if (childEntry
->checked
!= bCheck
)
4041 if (parentEntry
->path
.IsAncestorOf(childEntry
->path
))
4043 SetEntryCheck(childEntry
,j
,bCheck
);
4059 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList
& pathList
)
4063 int nListItems
= GetItemCount();
4064 for (int i
=0; i
< nListItems
; i
++)
4066 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
4067 ASSERT(entry
!= NULL
);
4068 if (entry
->m_Checked
)
4070 pathList
.AddPath(*entry
);
4073 pathList
.SortByPathname();
4078 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
4079 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool /*bNoIgnored*/)
4083 POSITION pos
= GetFirstSelectedItemPosition();
4085 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4087 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
4088 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
4090 pathList
.AddPath(*entry
);
4094 UINT
CGitStatusListCtrl::OnGetDlgCode()
4096 // we want to process the return key and not have that one
4097 // routed to the default pushbutton
4098 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS
;
4101 void CGitStatusListCtrl::OnNMReturn(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
4106 POSITION pos
= GetFirstSelectedItemPosition();
4109 int index
= GetNextSelectedItem(pos
);
4110 CTGitPath
*file
=(CTGitPath
*)GetItemData(index
);
4111 if (file
->m_Action
== CTGitPath::LOGACTIONS_UNVER
) {
4112 OpenFile(file
, OPEN
);
4119 void CGitStatusListCtrl::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
4121 // Since we catch all keystrokes (to have the enter key processed here instead
4122 // of routed to the default pushbutton) we have to make sure that other
4123 // keys like Tab and Esc still do what they're supposed to do
4124 // Tab = change focus to next/previous control
4125 // Esc = quit the dialog
4130 ::PostMessage(GetParent()->GetSafeHwnd(), WM_NEXTDLGCTL
, GetKeyState(VK_SHIFT
)&0x8000, 0);
4136 ::SendMessage(GetParent()->GetSafeHwnd(), WM_CLOSE
, 0, 0);
4141 CListCtrl::OnKeyDown(nChar
, nRepCnt
, nFlags
);
4144 void CGitStatusListCtrl::PreSubclassWindow()
4146 CListCtrl::PreSubclassWindow();
4147 EnableToolTips(TRUE
);
4148 m_Theme
.SetWindowTheme(GetSafeHwnd(), L
"Explorer", NULL
);
4151 INT_PTR
CGitStatusListCtrl::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4155 row
= CellRectFromPoint(point
, &cellrect
, &col
);
4162 pTI
->uId
= (UINT
)((row
<<10)+(col
&0x3ff)+1);
4163 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4165 pTI
->rect
= cellrect
;
4170 int CGitStatusListCtrl::CellRectFromPoint(CPoint
& point
, RECT
*cellrect
, int *col
) const
4174 // Make sure that the ListView is in LVS_REPORT
4175 if ((GetWindowLong(m_hWnd
, GWL_STYLE
) & LVS_TYPEMASK
) != LVS_REPORT
)
4178 // Get the top and bottom row visible
4179 int row
= GetTopIndex();
4180 int bottom
= row
+ GetCountPerPage();
4181 if (bottom
> GetItemCount())
4182 bottom
= GetItemCount();
4184 // Get the number of columns
4185 CHeaderCtrl
* pHeader
= (CHeaderCtrl
*)GetDlgItem(0);
4186 int nColumnCount
= pHeader
->GetItemCount();
4188 // Loop through the visible rows
4189 for ( ;row
<=bottom
;row
++)
4191 // Get bounding rect of item and check whether point falls in it.
4193 GetItemRect(row
, &rect
, LVIR_BOUNDS
);
4194 if (rect
.PtInRect(point
))
4196 // Now find the column
4197 for (colnum
= 0; colnum
< nColumnCount
; colnum
++)
4199 int colwidth
= GetColumnWidth(colnum
);
4200 if (point
.x
>= rect
.left
&& point
.x
<= (rect
.left
+ colwidth
))
4203 GetClientRect(&rectClient
);
4206 rect
.right
= rect
.left
+ colwidth
;
4208 // Make sure that the right extent does not exceed
4210 if (rect
.right
> rectClient
.right
)
4211 rect
.right
= rectClient
.right
;
4215 rect
.left
+= colwidth
;
4222 BOOL
CGitStatusListCtrl::OnToolTipText(UINT
/*id*/, NMHDR
* /*pNMHDR*/, LRESULT
* /*pResult*/)
4225 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4227 UINT_PTR nID
= pNMHDR
->idFrom
;
4232 UINT_PTR row
= ((nID
-1) >> 10) & 0x3fffff;
4233 UINT_PTR col
= (nID
-1) & 0x3ff;
4236 return FALSE
; // no custom tooltip for the path, we use the infotip there!
4238 // get the internal column from the visible columns
4239 int internalcol
= 0;
4240 UINT_PTR currentcol
= 0;
4241 for (; (currentcol
!= col
)
4242 && (internalcol
< m_ColumnManager
.GetColumnCount()-1)
4245 if (m_ColumnManager
.IsVisible (internalcol
))
4249 AFX_MODULE_THREAD_STATE
* pModuleThreadState
= AfxGetModuleThreadState();
4250 CToolTipCtrl
* pToolTip
= pModuleThreadState
->m_pToolTip
;
4251 pToolTip
->SendMessage(TTM_SETMAXTIPWIDTH
, 0, 300);
4254 if ((internalcol
== 2)||(internalcol
== 4))
4256 FileEntry
*fentry
= GetListEntry(row
);
4262 url
.Format(IDS_STATUSLIST_COPYFROM
, (LPCTSTR
)CPathUtils::PathUnescape(fentry
->copyfrom_url
), (LONG
)fentry
->copyfrom_rev
);
4263 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)url
, 80);
4266 if (fentry
->switched
)
4269 url
.Format(IDS_STATUSLIST_SWITCHEDTO
, (LPCTSTR
)CPathUtils::PathUnescape(fentry
->url
));
4270 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)url
, 80);
4273 if (fentry
->keeplocal
)
4275 lstrcpyn(pTTTW
->szText
, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_KEEPLOCAL
)), 80);
4284 void CGitStatusListCtrl::OnPaint()
4287 if ((m_bBusy
)||(m_bEmpty
))
4292 if (m_sBusy
.IsEmpty())
4293 str
.LoadString(IDS_STATUSLIST_BUSYMSG
);
4299 if (m_sEmpty
.IsEmpty())
4300 str
.LoadString(IDS_STATUSLIST_EMPTYMSG
);
4304 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
4306 if (IsWindowEnabled())
4307 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
4309 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
4314 pHC
= GetHeaderCtrl();
4318 pHC
->GetItemRect(0, &rcH
);
4319 rc
.top
+= rcH
.bottom
;
4323 CMyMemDC
memDC(pDC
, &rc
);
4325 memDC
.SetTextColor(clrText
);
4326 memDC
.SetBkColor(clrTextBk
);
4327 memDC
.FillSolidRect(rc
, clrTextBk
);
4329 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
4330 memDC
.DrawText(str
, rc
, DT_CENTER
| DT_VCENTER
|
4331 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
4332 memDC
.SelectObject(oldfont
);
4338 // prevent users from extending our hidden (size 0) columns
4339 void CGitStatusListCtrl::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4341 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
4344 // prevent any function from extending our hidden (size 0) columns
4345 void CGitStatusListCtrl::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4347 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
4351 void CGitStatusListCtrl::OnDestroy()
4353 SaveColumnWidths(true);
4354 CListCtrl::OnDestroy();
4357 void CGitStatusListCtrl::OnBeginDrag(NMHDR
* /*pNMHDR*/, LRESULT
* pResult
)
4360 Locker
lock(m_critSec
);
4361 CDropFiles dropFiles
; // class for creating DROPFILES struct
4364 POSITION pos
= GetFirstSelectedItemPosition();
4365 while ( (index
= GetNextSelectedItem(pos
)) >= 0 )
4367 FileEntry
* fentry
= m_arStatusArray
[m_arListArray
[index
]];
4368 CTGitPath path
= fentry
->GetPath();
4369 dropFiles
.AddFile( path
.GetWinPathString() );
4372 if ( dropFiles
.GetCount()>0 )
4375 dropFiles
.CreateStructure();
4382 void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry
/* = false */)
4384 int maxcol
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
4385 for (int col
= 0; col
<= maxcol
; col
++)
4386 if (m_ColumnManager
.IsVisible (col
))
4387 m_ColumnManager
.ColumnResized (col
);
4389 if (bSaveToRegistry
)
4390 m_ColumnManager
.WriteSettings();
4393 bool CGitStatusListCtrl::EnableFileDrop()
4395 m_bFileDropsEnabled
= true;
4399 bool CGitStatusListCtrl::HasPath(const CTGitPath
& path
)
4401 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
4403 if (m_arStatusArray
[i
]->IsEquivalentTo(path
))
4410 BOOL
CGitStatusListCtrl::PreTranslateMessage(MSG
* pMsg
)
4412 if (pMsg
->message
== WM_KEYDOWN
)
4414 switch (pMsg
->wParam
)
4418 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
4420 // select all entries
4421 for (int i
=0; i
<GetItemCount(); ++i
)
4423 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
4432 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
4434 // copy all selected paths to the clipboard
4435 if (GetAsyncKeyState(VK_SHIFT
)&0x8000)
4436 CopySelectedEntriesToClipboard(SVNSLC_COLSTATUS
);
4438 CopySelectedEntriesToClipboard(0);
4446 return CListCtrl::PreTranslateMessage(pMsg
);
4449 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols
)
4452 static CString
ponly(MAKEINTRESOURCE(IDS_STATUSLIST_PROPONLY
));
4453 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
4454 // WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
4459 if (GetSelectedCount() == 0)
4462 // first add the column titles as the first line
4463 // We needn't head when only path copy
4464 //temp.LoadString(IDS_STATUSLIST_COLFILE);
4465 //sClipboard = temp;
4467 DWORD selection
= 0;
4468 for (int i
= 0, count
= m_ColumnManager
.GetColumnCount(); i
< count
; ++i
)
4469 if ( ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
4470 || ((dwCols
!= 1) && (i
< 32) && ((dwCols
& (1 << i
)) != 0)))
4472 sClipboard
+= _T("\t") + m_ColumnManager
.GetName(i
);
4475 selection
+= 1 << i
;
4479 sClipboard
+= _T("\r\n");
4481 POSITION pos
= GetFirstSelectedItemPosition();
4483 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4485 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
4489 sClipboard
+= entry
->GetWinPathString();
4490 if (selection
& SVNSLC_COLFILENAME
)
4492 sClipboard
+= _T("\t")+entry
->GetFileOrDirectoryName();
4494 if (selection
& SVNSLC_COLEXT
)
4496 sClipboard
+= _T("\t")+entry
->GetFileExtension();
4499 if (selection
& SVNSLC_COLSTATUS
)
4502 if (entry
->isNested
)
4504 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4508 GitStatus::GetStatusString(hResourceHandle
, entry
->status
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4509 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4510 _tcscat_s(buf
, 100, _T(" (+)"));
4511 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4512 _tcscat_s(buf
, 100, _T(" (s)"));
4513 if ((entry
->status
== entry
->propstatus
)&&
4514 (entry
->status
!= git_wc_status_normal
)&&
4515 (entry
->status
!= git_wc_status_unversioned
)&&
4516 (!GitStatus::IsImportant(entry
->textstatus
)))
4517 _tcscat_s(buf
, 100, ponly
);
4521 sClipboard
+= _T("\t")+entry
->GetActionName();
4524 if (selection
& SVNSLC_COLTEXTSTATUS
)
4527 if (entry
->isNested
)
4529 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4533 GitStatus::GetStatusString(hResourceHandle
, entry
->textstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4534 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4535 _tcscat_s(buf
, 100, _T(" (+)"));
4536 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4537 _tcscat_s(buf
, 100, _T(" (s)"));
4540 sClipboard
+= _T("\t")+temp
;
4544 if (selection
& SVNSLC_COLREMOTESTATUS
)
4546 if (entry
->isNested
)
4548 temp
.LoadString(IDS_STATUSLIST_NESTED
);
4552 GitStatus::GetStatusString(hResourceHandle
, entry
->remotestatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4553 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4554 _tcscat_s(buf
, 100, _T(" (+)"));
4555 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4556 _tcscat_s(buf
, 100, _T(" (s)"));
4557 if ((entry
->remotestatus
== entry
->remotepropstatus
)&&
4558 (entry
->remotestatus
!= git_wc_status_none
)&&
4559 (entry
->remotestatus
!= git_wc_status_normal
)&&
4560 (entry
->remotestatus
!= git_wc_status_unversioned
)&&
4561 (!SVNStatus::IsImportant(entry
->remotetextstatus
)))
4562 _tcscat_s(buf
, 100, ponly
);
4565 sClipboard
+= _T("\t")+temp
;
4567 if (selection
& GitSLC_COLPROPSTATUS
)
4569 if (entry
->isNested
)
4575 GitStatus::GetStatusString(hResourceHandle
, entry
->propstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4576 if ((entry
->copied
)&&(_tcslen(buf
)>1))
4577 _tcscat_s(buf
, 100, _T(" (+)"));
4578 if ((entry
->switched
)&&(_tcslen(buf
)>1))
4579 _tcscat_s(buf
, 100, _T(" (s)"));
4582 sClipboard
+= _T("\t")+temp
;
4584 if (selection
& SVNSLC_COLREMOTETEXT
)
4586 if (entry
->isNested
)
4592 GitStatus::GetStatusString(hResourceHandle
, entry
->remotetextstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4595 sClipboard
+= _T("\t")+temp
;
4597 if (selection
& SVNSLC_COLREMOTEPROP
)
4599 // SVNSLC_COLREMOTEPROP
4600 if (entry
->isNested
)
4606 GitStatus::GetStatusString(hResourceHandle
, entry
->remotepropstatus
, buf
, sizeof(buf
)/sizeof(TCHAR
), (WORD
)langID
);
4609 sClipboard
+= _T("\t")+temp
;
4611 if (selection
& SVNSLC_COLURL
)
4612 sClipboard
+= _T("\t")+entry
->url
;
4613 if (selection
& SVNSLC_COLLOCK
)
4615 if (!m_HeadRev
.IsHead())
4617 // we have contacted the repository
4620 // wc repository text
4624 // UID1 "" lock has been broken
4625 // UID1 UID2 lock has been stolen
4626 if (entry
->lock_token
.IsEmpty() || (entry
->lock_token
.Compare(entry
->lock_remotetoken
)==0))
4628 if (entry
->lock_owner
.IsEmpty())
4629 temp
= entry
->lock_remoteowner
;
4631 temp
= entry
->lock_owner
;
4633 else if (entry
->lock_remotetoken
.IsEmpty())
4636 temp
.LoadString(IDS_STATUSLIST_LOCKBROKEN
);
4641 temp
.Format(IDS_STATUSLIST_LOCKSTOLEN
, (LPCTSTR
)entry
->lock_remoteowner
);
4645 temp
= entry
->lock_owner
;
4646 sClipboard
+= _T("\t")+temp
;
4648 if (selection
& SVNSLC_COLLOCKCOMMENT
)
4649 sClipboard
+= _T("\t")+entry
->lock_comment
;
4650 if (selection
& SVNSLC_COLAUTHOR
)
4651 sClipboard
+= _T("\t")+entry
->last_commit_author
;
4652 if (selection
& SVNSLC_COLREVISION
)
4654 temp
.Format(_T("%ld"), entry
->last_commit_rev
);
4655 if (entry
->last_commit_rev
== 0)
4657 sClipboard
+= _T("\t")+temp
;
4659 if (selection
& SVNSLC_COLREMOTEREVISION
)
4661 temp
.Format(_T("%ld"), entry
->remoterev
);
4662 if (entry
->remoterev
== 0)
4664 sClipboard
+= _T("\t")+temp
;
4667 if (selection
& SVNSLC_COLDATE
)
4669 TCHAR datebuf
[SVN_DATE_BUFFER
];
4670 apr_time_t date
= entry
->last_commit_date
;
4671 SVN::formatDate(datebuf
, date
, true);
4676 sClipboard
+= _T("\t")+temp
;
4678 if (selection
& SVNSLC_COLCOPYFROM
)
4680 if (m_sURL
.Compare(entry
->copyfrom_url
.Left(m_sURL
.GetLength()))==0)
4681 temp
= entry
->copyfrom_url
.Mid(m_sURL
.GetLength());
4683 temp
= entry
->copyfrom_url
;
4684 sClipboard
+= _T("\t")+temp
;
4687 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
4691 if ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
4694 = entry
->present_props
[m_ColumnManager
.GetName(i
)];
4695 sClipboard
+= _T("\t") + value
;
4699 if (selection
& SVNSLC_COLADD
)
4701 sClipboard
+= _T("\t")+entry
->m_StatAdd
;
4703 if (selection
& SVNSLC_COLDEL
)
4705 sClipboard
+= _T("\t")+entry
->m_StatDel
;
4708 sClipboard
+= _T("\r\n");
4711 return CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
4717 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
4720 std::set
<CString
> changelists
;
4721 POSITION pos
= GetFirstSelectedItemPosition();
4723 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4725 FileEntry
* entry
= GetListEntry(index
);
4726 if (!entry
->changelist
.IsEmpty())
4727 changelists
.insert(entry
->changelist
);
4729 return changelists
.size();
4734 bool CGitStatusListCtrl::PrepareGroups(bool bForce
/* = false */)
4737 bool bHasGroups
=false;
4740 for(int i
=0;i
< this->m_arStatusArray
.size(); i
++)
4742 int ParentNo
= m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
4744 max
=m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
4747 if ( this->m_UnRevFileList
.GetCount()>0 ||
4748 this->m_IgnoreFileList
.GetCount()>0 ||
4755 EnableGroupView(bHasGroups
);
4757 TCHAR groupname
[1024];
4763 grp
.cbSize
= sizeof(LVGROUP
);
4764 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4767 //if(m_UnRevFileList.GetCount()>0)
4770 grp
.pszHeader
= _T("Merged Files");
4771 grp
.iGroupId
= MERGE_MASK
;
4772 grp
.uAlign
= LVGA_HEADER_LEFT
;
4773 InsertGroup(0, &grp
);
4775 for(int i
=0;i
<=max
;i
++)
4778 str
.Format(_T("Diff with %d Parent"), i
+1);
4779 //_tcsncpy_s(groupname, 1024, (LPCTSTR)_T("Not Versioned"), 1023);
4780 grp
.pszHeader
= str
.GetBuffer();
4782 grp
.uAlign
= LVGA_HEADER_LEFT
;
4783 InsertGroup(i
+1, &grp
);
4787 CString
sUnassignedName(_T("Modified File"));
4788 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
4789 grp
.pszHeader
= groupname
;
4790 grp
.iGroupId
= groupindex
;
4791 grp
.uAlign
= LVGA_HEADER_LEFT
;
4792 InsertGroup(groupindex
++, &grp
);
4796 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)_T("Not Versioned"), 1023);
4797 grp
.pszHeader
= groupname
;
4798 grp
.iGroupId
= groupindex
;
4799 grp
.uAlign
= LVGA_HEADER_LEFT
;
4800 InsertGroup(groupindex
++, &grp
);
4803 //if(m_IgnoreFileList.GetCount()>0)
4805 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)_T("Ignored"), 1023);
4806 grp
.pszHeader
= groupname
;
4807 grp
.iGroupId
= groupindex
;
4808 grp
.uAlign
= LVGA_HEADER_LEFT
;
4809 InsertGroup(groupindex
++, &grp
);
4815 m_bHasIgnoreGroup
= false;
4817 // now add the items which don't belong to a group
4819 grp
.cbSize
= sizeof(LVGROUP
);
4820 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4821 CString
sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET
));
4822 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
4823 grp
.pszHeader
= groupname
;
4824 grp
.iGroupId
= groupindex
;
4825 grp
.uAlign
= LVGA_HEADER_LEFT
;
4826 InsertGroup(groupindex
++, &grp
);
4828 for (std::map
<CString
,int>::iterator it
= m_changelists
.begin(); it
!= m_changelists
.end(); ++it
)
4830 if (it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)!=0)
4833 grp
.cbSize
= sizeof(LVGROUP
);
4834 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4835 _tcsncpy_s(groupname
, 1024, it
->first
, 1023);
4836 grp
.pszHeader
= groupname
;
4837 grp
.iGroupId
= groupindex
;
4838 grp
.uAlign
= LVGA_HEADER_LEFT
;
4839 it
->second
= InsertGroup(groupindex
++, &grp
);
4842 m_bHasIgnoreGroup
= true;
4845 if (m_bHasIgnoreGroup
)
4847 // and now add the group 'ignore-on-commit'
4848 std::map
<CString
,int>::iterator it
= m_changelists
.find(SVNSLC_IGNORECHANGELIST
);
4849 if (it
!= m_changelists
.end())
4851 grp
.cbSize
= sizeof(LVGROUP
);
4852 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
4853 _tcsncpy_s(groupname
, 1024, SVNSLC_IGNORECHANGELIST
, 1023);
4854 grp
.pszHeader
= groupname
;
4855 grp
.iGroupId
= groupindex
;
4856 grp
.uAlign
= LVGA_HEADER_LEFT
;
4857 it
->second
= InsertGroup(groupindex
, &grp
);
4864 void CGitStatusListCtrl::NotifyCheck()
4866 CWnd
* pParent
= GetParent();
4867 if (NULL
!= pParent
&& NULL
!= pParent
->GetSafeHwnd())
4869 pParent
->SendMessage(SVNSLNM_CHECKCHANGED
, m_nSelected
);
4873 int CGitStatusListCtrl::UpdateFileList(git_revnum_t hash
,CTGitPathList
*list
)
4877 m_CurrentVersion
=hash
;
4883 count
= list
->GetCount();
4885 CString head
= _T("HEAD");
4887 head
= _T("HEAD~1");
4889 if(hash
== GIT_REV_ZERO
)
4891 for(int i
=0;i
<count
;i
++)
4896 if(!g_Git
.IsInitRepos())
4899 cmd
=(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z"));
4901 cmd
.Format(_T("git.exe diff-index --raw ") + head
+ _T(" --numstat -C -M -z -- \"%s\""),(*list
)[i
].GetGitPathString());
4903 if(g_Git
.Run(cmd
,&cmdout
))
4905 int last
= cmdout
.RevertFind(0,-1);
4909 g_Git
.StringAppend(&str
, &cmdout
[last
+1], CP_ACP
,cmdout
.size()-last
-1);
4910 CMessageBox::Show(NULL
,str
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
4911 cmdout
.resize(last
+1);
4917 if(g_Git
.Run(_T("git.exe rev-parse --revs-only ") + head
,&strout
,CP_UTF8
))
4919 CMessageBox::Show(NULL
,strout
,_T("TortoiseGit"),MB_OK
);
4922 if(strout
.IsEmpty())
4923 break; //this is initial repositoyr, there are no any history
4925 CMessageBox::Show(NULL
,strout
,_T("TortoiseGit"),MB_OK
);
4931 //We will list all stage file anyway because commit will commit thats
4932 cmd
=(_T("git.exe diff-index --cached --raw ") + head
+ _T(" --numstat -C -M -z"));
4934 // cmd.Format(_T("git.exe diff-index --cached --raw ") + head + _T(" --numstat -C -M -z -- \"%s\""),(*list)[i].GetGitPathString());
4936 g_Git
.Run(cmd
,&cmdout
);
4938 out
.append(cmdout
,0);
4940 else // Init Repository
4942 //We will list all added file for init repository because commit will comit these
4944 cmd
=_T("git.exe ls-files -s -t -z");
4946 // cmd.Format(_T("git.exe ls-files -s -t -z -- \"%s\""),(*list)[i].GetGitPathString());
4948 g_Git
.Run(cmd
,&cmdout
);
4950 out
.append(cmdout
,0);
4954 if(g_Git
.IsInitRepos())
4956 m_StatusFileList
.ParserFromLsFile(out
);
4957 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
4958 ((CTGitPath
&)(m_StatusFileList
[i
])).m_Action
=CTGitPath::LOGACTIONS_ADDED
;
4961 this->m_StatusFileList
.ParserFromLog(out
);
4963 //handle delete conflict case, when remote : modified, local : deleted.
4964 for(int i
=0;i
<count
;i
++)
4970 cmd
=_T("git.exe ls-files -u -t -z");
4972 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),(*list
)[i
].GetGitPathString());
4974 g_Git
.Run(cmd
,&cmdout
);
4976 CTGitPathList conflictlist
;
4977 conflictlist
.ParserFromLog(cmdout
);
4978 for(int i
=0;i
<conflictlist
.GetCount();i
++)
4980 CTGitPath
*p
=m_StatusFileList
.LookForGitPath(conflictlist
[i
].GetGitPathString());
4982 p
->m_Action
|=CTGitPath::LOGACTIONS_UNMERGED
;
4984 m_StatusFileList
.AddPath(conflictlist
[i
]);
4994 count
= list
->GetCount();
4996 for(int i
=0;i
<count
;i
++)
5001 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M -z %s"),hash
);
5003 cmd
.Format(_T("git.exe diff-tree --raw --numstat -C -M %s -z -- \"%s\""),hash
,(*list
)[i
].GetGitPathString());
5005 g_Git
.Run(cmd
,&cmdout
);
5009 this->m_StatusFileList
.ParserFromLog(out
);
5013 for(int i
=0;i
<m_StatusFileList
.GetCount();i
++)
5015 CTGitPath
* gitpatch
=(CTGitPath
*)&m_StatusFileList
[i
];
5016 gitpatch
->m_Checked
= TRUE
;
5017 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
5020 this->m_bBusy
=FALSE
;
5024 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList
&list
)
5026 m_arStatusArray
.clear();
5027 for(int i
=0;i
<list
.GetCount();i
++)
5029 CTGitPath
* gitpath
=(CTGitPath
*)&list
[i
];
5031 if(gitpath
->m_Action
& CTGitPath::LOGACTIONS_HIDE
)
5034 gitpath
->m_Checked
= TRUE
;
5035 m_arStatusArray
.push_back((CTGitPath
*)&list
[i
]);
5040 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
*List
)
5042 this->m_UnRevFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
,List
);
5043 for(int i
=0;i
<m_UnRevFileList
.GetCount();i
++)
5045 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
5046 gitpatch
->m_Checked
= FALSE
;
5047 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
5052 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList
*List
)
5054 this->m_IgnoreFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
|CTGitPath::LOGACTIONS_IGNORE
,List
);
5055 for(int i
=0;i
<m_IgnoreFileList
.GetCount();i
++)
5057 CTGitPath
* gitpatch
=(CTGitPath
*)&m_IgnoreFileList
[i
];
5058 gitpatch
->m_Checked
= FALSE
;
5059 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
5063 int CGitStatusListCtrl::UpdateFileList(int mask
,bool once
,CTGitPathList
*List
)
5065 if(mask
&CGitStatusListCtrl::FILELIST_MODIFY
)
5067 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_MODIFY
)))
5069 UpdateFileList(git_revnum_t(GIT_REV_ZERO
),List
);
5070 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_MODIFY
;
5073 if(mask
&CGitStatusListCtrl::FILELIST_UNVER
)
5075 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_UNVER
)))
5077 UpdateUnRevFileList(List
);
5078 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
5084 void CGitStatusListCtrl::Clear()
5087 this->DeleteAllItems();
5088 this->m_arListArray
.clear();
5089 this->m_arStatusArray
.clear();
5090 this->m_changelists
.clear();
5092 //////////////////////////////////////////////////////////////////////////
5094 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
)
5096 if(pFmtEtc
->cfFormat
== CF_HDROP
&& medium
.tymed
== TYMED_HGLOBAL
)
5098 HDROP hDrop
= (HDROP
)GlobalLock(medium
.hGlobal
);
5101 TCHAR szFileName
[MAX_PATH
];
5103 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, NULL
, 0);
5106 clientpoint
.x
= pt
.x
;
5107 clientpoint
.y
= pt
.y
;
5108 ScreenToClient(m_hTargetWnd
, &clientpoint
);
5109 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
5111 CTSVNPathList changelistItems
;
5112 for(UINT i
= 0; i
< cFiles
; ++i
)
5114 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
5115 changelistItems
.AddPath(CTSVNPath(szFileName
));
5117 // find the changelist name
5118 CString sChangelist
;
5119 LONG_PTR nGroup
= m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
);
5120 for (std::map
<CString
, int>::iterator it
= m_pSVNStatusListCtrl
->m_changelists
.begin(); it
!= m_pSVNStatusListCtrl
->m_changelists
.end(); ++it
)
5121 if (it
->second
== nGroup
)
5122 sChangelist
= it
->first
;
5123 if (!sChangelist
.IsEmpty())
5126 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
5128 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
5130 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
5133 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
5136 e
->changelist
= sChangelist
;
5139 if (m_pSVNStatusListCtrl
->m_changelists
.find(e
->changelist
)!=m_pSVNStatusListCtrl
->m_changelists
.end())
5140 m_pSVNStatusListCtrl
->SetItemGroup(index
, m_pSVNStatusListCtrl
->m_changelists
[e
->changelist
]);
5142 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
5148 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5149 if (hParentWnd
!= NULL
)
5150 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
5156 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
5162 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
5164 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
5166 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
5169 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
5172 e
->changelist
= sChangelist
;
5173 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
5178 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5179 if (hParentWnd
!= NULL
)
5180 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
5186 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
5192 for(UINT i
= 0; i
< cFiles
; ++i
)
5194 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
5195 HWND hParentWnd
= GetParent(m_hTargetWnd
);
5196 if (hParentWnd
!= NULL
)
5197 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)szFileName
);
5201 GlobalUnlock(medium
.hGlobal
);
5203 return true; //let base free the medium
5205 HRESULT STDMETHODCALLTYPE
CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
)
5207 CIDropTarget::DragOver(grfKeyState
, pt
, pdwEffect
);
5208 *pdwEffect
= DROPEFFECT_COPY
;
5209 if (m_pSVNStatusListCtrl
)
5212 clientpoint
.x
= pt
.x
;
5213 clientpoint
.y
= pt
.y
;
5214 ScreenToClient(m_hTargetWnd
, &clientpoint
);
5215 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
5217 *pdwEffect
= DROPEFFECT_MOVE
;
5219 else if ((!m_pSVNStatusListCtrl
->m_bFileDropsEnabled
)||(m_pSVNStatusListCtrl
->m_bOwnDrag
))
5221 *pdwEffect
= DROPEFFECT_NONE
;
5229 void CGitStatusListCtrl::FileSaveAs(CTGitPath
*path
)
5232 filename
.Format(_T("%s-%s%s"),path
->GetBaseFilename(),this->m_CurrentVersion
.Left(6),path
->GetFileExtension());
5233 CFileDialog
dlg(FALSE
,NULL
,
5235 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
5237 CString currentpath
;
5238 currentpath
=g_Git
.m_CurrentDir
+_T("\\");
5239 currentpath
+=path
->GetWinPathString();
5241 dlg
.m_ofn
.lpstrInitialDir
=currentpath
.GetBuffer();
5244 if(dlg
.DoModal()==IDOK
)
5246 filename
= dlg
.GetPathName();
5247 if(m_CurrentVersion
== GIT_REV_ZERO
)
5249 if(!CopyFile(g_Git
.m_CurrentDir
+_T("\\") + path
->GetWinPath(),filename
,false))
5251 LPVOID lpMsgBuf
=NULL
;
5252 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
5253 NULL
,GetLastError(),MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
5256 CMessageBox::Show(NULL
,(TCHAR
*)lpMsgBuf
,_T("TortoiseGit"),MB_OK
);
5257 LocalFree(lpMsgBuf
);
5263 if(g_Git
.GetOneFile(m_CurrentVersion
,*path
,filename
))
5265 out
.Format(_T("Fail checkout one file %s;%s"),m_CurrentVersion
, path
->GetWinPath());
5266 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5274 int CGitStatusListCtrl::RevertSelectedItemToVersion()
5276 if(this->m_CurrentVersion
.IsEmpty())
5278 if(this->m_CurrentVersion
== GIT_REV_ZERO
)
5281 POSITION pos
= GetFirstSelectedItemPosition();
5285 while ((index
= GetNextSelectedItem(pos
)) >= 0)
5287 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
5288 cmd
.Format(_T("git.exe checkout %s -- \"%s\""),m_CurrentVersion
,fentry
->GetGitPathString());
5290 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
5292 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5297 out
.Format(_T("%d files revert to %s"),count
,m_CurrentVersion
.Left(6));
5298 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5302 void CGitStatusListCtrl::OpenFile(CTGitPath
*filepath
,int mode
)
5305 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
5307 file
= filepath
->GetWinPath();
5311 GetTempPath(temppath
);
5312 file
.Format(_T("%s%s_%s%s"),
5314 filepath
->GetBaseFilename(),
5315 m_CurrentVersion
.Left(6),
5316 filepath
->GetFileExtension());
5318 if(g_Git
.GetOneFile(m_CurrentVersion
, *filepath
, file
))
5320 out
.Format(_T("Fail checkout file %s to %s\n"), filepath
->GetGitPathString(), file
);
5321 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
5326 if(mode
== ALTERNATIVEEDITOR
)
5328 CAppUtils::LaunchAlternativeEditor(file
);
5331 int ret
= HINSTANCE_ERROR
;
5335 ret
= (int)ShellExecute(this->m_hWnd
, NULL
,file
, NULL
, NULL
, SW_SHOW
);
5337 if (ret
> HINSTANCE_ERROR
)
5344 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
5346 CAppUtils::LaunchApplication(cmd
, NULL
, false);