From 8fe18077bb6687a449ab19fbaa0a6f4493fd0cc5 Mon Sep 17 00:00:00 2001 From: Sup Yut Sum Date: Tue, 1 Jan 2013 10:20:33 +0800 Subject: [PATCH] Refactor code that gets ref label color Signed-off-by: Sup Yut Sum --- src/TortoiseProc/GitLogListBase.cpp | 108 +++++++++++++----------------------- src/TortoiseProc/GitLogListBase.h | 9 ++- 2 files changed, 47 insertions(+), 70 deletions(-) diff --git a/src/TortoiseProc/GitLogListBase.cpp b/src/TortoiseProc/GitLogListBase.cpp index 5dd3b6f5c..41ab674fd 100644 --- a/src/TortoiseProc/GitLogListBase.cpp +++ b/src/TortoiseProc/GitLogListBase.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2012 - TortoiseGit +// Copyright (C) 2008-2013 - TortoiseGit // Copyright (C) 2005-2007 Marco Costalba // Copyright (C) 2011-2012 - Sven Strickroth @@ -526,7 +526,7 @@ void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect) } } -void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index) +void CGitLogListBase::DrawTagBranch(HDC hdc, CRect &rect, INT_PTR index, std::vector refList) { GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index); CRect rt=rect; @@ -544,62 +544,11 @@ void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index) if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater()) hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView"); - for(unsigned int i=0;im_CommitHash].size();i++) + for (unsigned int i = 0; i < refList.size(); i++) { - CString str; - str=m_HashMap[data->m_CommitHash][i]; - - CString shortname; + CString shortname = refList[i].name; HBRUSH brush = 0; - shortname = _T(""); - COLORREF colRef = 0; - - //Determine label color - if(CGit::GetShortName(str,shortname,_T("refs/heads/"))) - { - if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)) - continue; - if( shortname == m_CurrentBranch ) - colRef = m_Colors.GetColor(CColors::CurrentBranch); - else - colRef = m_Colors.GetColor(CColors::LocalBranch); - - } - else if(CGit::GetShortName(str,shortname,_T("refs/remotes/"))) - { - if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)) - continue; - colRef = m_Colors.GetColor(CColors::RemoteBranch); - } - else if(CGit::GetShortName(str,shortname,_T("refs/tags/"))) - { - if (!(m_ShowRefMask & LOGLIST_SHOWTAGS)) - continue; - colRef = m_Colors.GetColor(CColors::Tag); - } - else if(CGit::GetShortName(str,shortname,_T("refs/stash"))) - { - if (!(m_ShowRefMask & LOGLIST_SHOWSTASH)) - continue; - colRef = m_Colors.GetColor(CColors::Stash); - shortname=_T("stash"); - } - else if(CGit::GetShortName(str,shortname,_T("refs/bisect/"))) - { - if (!(m_ShowRefMask & LOGLIST_SHOWBISECT)) - continue; - if(shortname.Find(_T("good")) == 0) - { - colRef = m_Colors.GetColor(CColors::BisectGood); - shortname = _T("good"); - } - - if(shortname.Find(_T("bad")) == 0) - { - colRef = m_Colors.GetColor(CColors::BisectBad); - shortname = _T("bad"); - } - } + COLORREF colRef = refList[i].color; //When row selected, ajust label color if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater())) @@ -1176,47 +1125,70 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect); FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect); - int displayedRefs = 0; - for (unsigned int i = 0; i < m_HashMap[data->m_CommitHash].size(); i++) + std::vector refsToShow; + STRING_VECTOR refList = m_HashMap[data->m_CommitHash]; + for (unsigned int i = 0; i < refList.size(); i++) { - CString str = m_HashMap[data->m_CommitHash][i]; + CString str = refList[i]; - CString shortname; - if (CGit::GetShortName(str, shortname, _T("refs/heads/"))) + REFLABEL refLabel; + refLabel.color = RGB(255, 255, 255); + if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/"))) { if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)) continue; + if (refLabel.name == m_CurrentBranch ) + refLabel.color = m_Colors.GetColor(CColors::CurrentBranch); + else + refLabel.color = m_Colors.GetColor(CColors::LocalBranch); } - else if (CGit::GetShortName(str, shortname, _T("refs/remotes/"))) + else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/"))) { if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)) continue; + refLabel.color = m_Colors.GetColor(CColors::RemoteBranch); } - else if (CGit::GetShortName(str, shortname, _T("refs/tags/"))) + else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/"))) { if (!(m_ShowRefMask & LOGLIST_SHOWTAGS)) continue; + refLabel.color = m_Colors.GetColor(CColors::Tag); } - else if (CGit::GetShortName(str, shortname, _T("refs/stash"))) + else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash"))) { if (!(m_ShowRefMask & LOGLIST_SHOWSTASH)) continue; + refLabel.color = m_Colors.GetColor(CColors::Stash); + refLabel.name = _T("stash"); } - else if (CGit::GetShortName(str, shortname, _T("refs/bisect/"))) + else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/"))) { if (!(m_ShowRefMask & LOGLIST_SHOWBISECT)) continue; + if (refLabel.name.Find(_T("good")) == 0) + { + refLabel.color = m_Colors.GetColor(CColors::BisectGood); + refLabel.name = _T("good"); + } + if (refLabel.name.Find(_T("bad")) == 0) + { + refLabel.color = m_Colors.GetColor(CColors::BisectBad); + refLabel.name = _T("bad"); + } } - displayedRefs++; + else + continue; + + refsToShow.push_back(refLabel); } - if (displayedRefs == 0) + if (refsToShow.empty()) { *pResult = CDRF_DODEFAULT; return; } - DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec); + DrawTagBranch(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow); *pResult = CDRF_SKIPDEFAULT; return; diff --git a/src/TortoiseProc/GitLogListBase.h b/src/TortoiseProc/GitLogListBase.h index 6dd12bfe8..1303a1387 100644 --- a/src/TortoiseProc/GitLogListBase.h +++ b/src/TortoiseProc/GitLogListBase.h @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2012 - TortoiseGit +// Copyright (C) 2008-2013 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -386,6 +386,11 @@ public: CString m_ColumnRegKey; protected: + typedef struct { + CString name; + COLORREF color; + } REFLABEL; + DECLARE_MESSAGE_MAP() afx_msg void OnDestroy(); virtual afx_msg void OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult); @@ -408,7 +413,7 @@ protected: void FetchLastLogInfo(); void FetchFullLogInfo(CString &from, CString &to); void FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect); - void DrawTagBranch(HDC,CRect &rect,INT_PTR index); + void DrawTagBranch(HDC hdc, CRect &rect, INT_PTR index, std::vector refList); void DrawGraph(HDC,CRect &rect,INT_PTR index); void paintGraphLane(HDC hdc,int laneHeight, int type, int x1, int x2, -- 2.11.4.GIT