OSDN Git Service

Blame Color Is Okay
authorFrank Li <lznuaa@gmail.com>
Mon, 12 Jan 2009 06:21:20 +0000 (14:21 +0800)
committerFrank Li <lznuaa@gmail.com>
Mon, 12 Jan 2009 06:21:20 +0000 (14:21 +0800)
User click blame bar and high light select.
Log List auto select commits.

Signed-off-by: Frank Li <lznuaa@gmail.com>
src/TortoiseGitBlame/OutputWnd.cpp
src/TortoiseGitBlame/TortoiseGitBlameView.cpp
src/TortoiseGitBlame/TortoiseGitBlameView.h

index 7fc8ba6..0979d68 100644 (file)
@@ -46,7 +46,7 @@ int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
 \r
        // Create output panes:\r
        //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;\r
-       const DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP;\r
+       const DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL ;\r
 \r
        if (! m_LogList.Create(dwStyle,rectDummy,&m_wndTabs,2) )\r
        {\r
@@ -96,6 +96,7 @@ int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
 //     FillDebugWindow();\r
 //     FillFindWindow();\r
 \r
+       this->SetWindowTextW(_T("Git Log"));\r
        return 0;\r
 }\r
 \r
index 1ea2dab..728d3e4 100644 (file)
@@ -42,7 +42,13 @@ BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
        ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTortoiseGitBlameView::OnFilePrintPreview)\r
        ON_WM_CREATE()\r
        ON_WM_SIZE()\r
+       ON_WM_MOUSEMOVE()\r
+       ON_WM_MOUSEHOVER()\r
+       ON_WM_MOUSELEAVE()\r
+       ON_WM_LBUTTONDOWN()\r
+       ON_WM_RBUTTONDOWN()\r
        ON_NOTIFY(SCN_PAINTED,0,OnSciPainted)\r
+       ON_NOTIFY(SCN_GETBKCOLOR,0,OnSciGetBkColor)\r
 END_MESSAGE_MAP()\r
 \r
 // CTortoiseGitBlameView construction/destruction\r
@@ -102,7 +108,7 @@ int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
 \r
        CRect rect,rect1;\r
        this->GetWindowRect(&rect1);\r
-       rect.left=m_blamewidth;\r
+       rect.left=m_blamewidth+LOCATOR_WIDTH;\r
        rect.right=rect.Width();\r
        rect.top=0;\r
        rect.bottom=rect.Height();\r
@@ -146,6 +152,7 @@ void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
                return;\r
 \r
        DrawBlame(this->GetDC()->m_hDC);\r
+       DrawLocatorBar(this->GetDC()->m_hDC);\r
        // TODO: add draw code for native data here\r
 }\r
 \r
@@ -1121,10 +1128,11 @@ void CTortoiseGitBlameView::DrawBlame(HDC hDC)
                        str.Format(_T("%d.%s"),m_ID[i],m_Authors[i]);\r
 \r
                        //_stprintf_s(buf, MAX_PATH, _T("%8ld       "), revs[i]);\r
-                       rc.top=Y;rc.left=0;             \r
+                       rc.top=Y;\r
+                       rc.left=LOCATOR_WIDTH;          \r
                        rc.bottom=Y+height;\r
-                       rc.right = rc.left + 100;\r
-                       ::ExtTextOut(hDC, 0, Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);\r
+                       rc.right = rc.left + m_blamewidth;\r
+                       ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);\r
                        int Left = m_revwidth;\r
 #if 0\r
                        if (ShowDate)\r
@@ -1227,7 +1235,6 @@ void CTortoiseGitBlameView::DrawHeader(HDC hDC)
 \r
 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)\r
 {\r
-#if 0\r
        if (hDC == NULL)\r
                return;\r
 \r
@@ -1237,13 +1244,17 @@ void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
        COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);\r
 \r
        RECT rc;\r
-       ::GetClientRect(wLocator, &rc);\r
+       //::GetClientRect(wLocator, &rc);\r
+       this->GetClientRect(&rc);\r
+\r
+       rc.right=LOCATOR_WIDTH;\r
+\r
        RECT lineRect = rc;\r
        LONG height = rc.bottom-rc.top;\r
        LONG currentLine = 0;\r
 \r
        // draw the colored bar\r
-       for (std::vector<LONG>::const_iterator it = revs.begin(); it != revs.end(); ++it)\r
+       for (std::vector<LONG>::const_iterator it = m_ID.begin(); it != m_ID.end(); ++it)\r
        {\r
                currentLine++;\r
                // get the line color\r
@@ -1254,23 +1265,23 @@ void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
                }\r
                SetBkColor(hDC, cr);\r
                lineRect.top = Y;\r
-               lineRect.bottom = (currentLine * height / revs.size());\r
+               lineRect.bottom = (currentLine * height / m_ID.size());\r
                ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);\r
                Y = lineRect.bottom;\r
        }\r
 \r
-       if (revs.size())\r
+       if (m_ID.size())\r
        {\r
                // now draw two lines indicating the scroll position of the source view\r
                SetBkColor(hDC, blackColor);\r
-               lineRect.top = line * height / revs.size();\r
+               lineRect.top = line * height / m_ID.size();\r
                lineRect.bottom = lineRect.top+1;\r
                ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);\r
-               lineRect.top = (line + linesonscreen) * height / revs.size();\r
+               lineRect.top = (line + linesonscreen) * height / m_ID.size();\r
                lineRect.bottom = lineRect.top+1;\r
                ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);\r
        }\r
-#endif\r
+\r
 }\r
 \r
 void CTortoiseGitBlameView::StringExpand(LPSTR str)\r
@@ -1901,34 +1912,6 @@ LRESULT CALLBACK WndBlameProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
                // fall through\r
        case WM_LBUTTONDOWN:\r
                {\r
-                       int y = ((int)(short)HIWORD(lParam));\r
-                       LONG_PTR line = app.SendEditor(SCI_GETFIRSTVISIBLELINE);\r
-                       LONG_PTR height = app.SendEditor(SCI_TEXTHEIGHT);\r
-                       line = line + (y/height);\r
-                       if (line < (LONG)app.revs.size())\r
-                       {\r
-                               app.SetSelectedLine(line);\r
-                               if (app.revs[line] != app.m_selectedrev)\r
-                               {\r
-                                       app.m_selectedrev = app.revs[line];\r
-                                       app.m_selectedorigrev = app.origrevs[line];\r
-                                       app.m_selectedauthor = app.authors[line];\r
-                                       app.m_selecteddate = app.dates[line];\r
-                               }\r
-                               else\r
-                               {\r
-                                       app.m_selectedauthor.clear();\r
-                                       app.m_selecteddate.clear();\r
-                                       app.m_selectedrev = -2;\r
-                                       app.m_selectedorigrev = -2;\r
-                               }\r
-                               ::InvalidateRect(app.wBlame, NULL, FALSE);\r
-                       }\r
-                       else\r
-                       {\r
-                               app.SetSelectedLine(-1);\r
-                       }\r
-               }\r
                break;\r
        case WM_SETFOCUS:\r
                ::SetFocus(app.wBlame);\r
@@ -2474,7 +2457,7 @@ void CTortoiseGitBlameView::UpdateInfo()
                        this->m_TextView.InsertText(line,true);\r
                }\r
                int id=pRevs->m_HashMap[one.Left(40)];          \r
-               if(id>=0)\r
+               if(id>=0 && id <GetLogData()->size())\r
                {\r
                        m_ID.push_back(pRevs->size()-id);\r
                        m_Authors.push_back(pRevs->at(id).m_AuthorName);\r
@@ -2493,10 +2476,18 @@ void CTortoiseGitBlameView::UpdateInfo()
        SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);\r
        SendEditor(SCI_SETREADONLY, TRUE);\r
 \r
+       m_lowestrev=1;\r
+       m_highestrev=this->GetLogData()->size();\r
 \r
        this->Invalidate();\r
 }\r
 \r
+CGitBlameLogList * CTortoiseGitBlameView::GetLogList()\r
+{\r
+       return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);\r
+}\r
+\r
+\r
 CLogDataVector * CTortoiseGitBlameView::GetLogData()\r
 {\r
        return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);\r
@@ -2505,4 +2496,62 @@ CLogDataVector * CTortoiseGitBlameView::GetLogData()
 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)\r
 {\r
        this->Invalidate();\r
+}\r
+\r
+void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)\r
+{\r
+\r
+       LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);\r
+       LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);\r
+       line = line + (point.y/height);\r
+                       \r
+       if (line < (LONG)m_CommitHash.size())\r
+       {\r
+               SetSelectedLine(line);\r
+               if (m_CommitHash[line] != m_SelectedHash)\r
+               {\r
+                       m_SelectedHash = m_CommitHash[line];\r
+//                     app.m_selectedorigrev = app.origrevs[line];\r
+//                     app.m_selectedauthor = app.authors[line];\r
+//                     app.m_selecteddate = app.dates[line];\r
+                       \r
+                       \r
+                       this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID[line],\r
+                                                                                                                       LVIS_SELECTED,\r
+                                                                                                                       LVIS_SELECTED);\r
+               }\r
+               else\r
+               {\r
+                       m_SelectedHash.Empty();\r
+//                     app.m_selecteddate.clear();\r
+//                     app.m_selectedrev = -2;\r
+//                     app.m_selectedorigrev = -2;\r
+               }\r
+               //::InvalidateRect( NULL, FALSE);\r
+               this->Invalidate();\r
+               this->m_TextView.Invalidate();\r
+               \r
+       }\r
+       else\r
+       {\r
+               SetSelectedLine(-1);\r
+       }\r
+               \r
+       CView::OnLButtonDown(nFlags,point);\r
+}\r
+\r
+void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* result)\r
+{\r
+\r
+       SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);\r
+\r
+       if ((m_colorage)&&(notification->line < (int)m_CommitHash.size()))\r
+       {\r
+               if(m_CommitHash[notification->line] == this->m_SelectedHash )\r
+                       notification->lParam = m_selectedauthorcolor;\r
+               else\r
+                       notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (m_ID[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));\r
+       }\r
+\r
+\r
 }
\ No newline at end of file
index e1a0a7d..7fdf811 100644 (file)
@@ -23,7 +23,7 @@ const int blockSize = 128 * 1024;
 \r
 #define BLAMESPACE 20\r
 #define HEADER_HEIGHT 18\r
-#define LOCATOR_WIDTH 20\r
+#define LOCATOR_WIDTH 10\r
 \r
 #define MAX_LOG_LENGTH 2000\r
 \r
@@ -76,6 +76,9 @@ protected:
        afx_msg int OnCreate(LPCREATESTRUCT lpcs);\r
        afx_msg void OnSize(UINT nType, int cx, int cy);\r
        afx_msg void OnSciPainted(NMHDR*, LRESULT*);\r
+       afx_msg void OnLButtonDown(UINT nFlags,CPoint point);\r
+       afx_msg void OnRButtonDown(UINT nFlags,CPoint point){OnLButtonDown(nFlags,point);CView::OnRButtonDown(nFlags,point);};\r
+       afx_msg void OnSciGetBkColor(NMHDR*, LRESULT*);\r
        DECLARE_MESSAGE_MAP()\r
 \r
 public:\r
@@ -194,6 +197,8 @@ protected:
        CRegStdWORD                                     m_regOldLinesColor;\r
        CRegStdWORD                                     m_regNewLinesColor;\r
 \r
+       CGitBlameLogList * GetLogList();\r
+\r
 };\r
 \r
 #ifndef _DEBUG  // debug version in TortoiseGitBlameView.cpp\r