OSDN Git Service

GitBlame Use command Line argument to open file
[tortoisegit/TortoiseGitJp.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
index e152a90..c5a6796 100644 (file)
 #include "TortoiseGitBlameDoc.h"\r
 #include "TortoiseGitBlameView.h"\r
 #include "MainFrm.h"\r
+#include "Balloon.h"\r
+#include "EditGotoDlg.h"\r
 \r
 #ifdef _DEBUG\r
 #define new DEBUG_NEW\r
 #endif\r
 \r
+UINT CTortoiseGitBlameView::m_FindDialogMessage;\r
 \r
 // CTortoiseGitBlameView\r
 \r
@@ -40,6 +43,8 @@ BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
        ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)\r
        ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)\r
        ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTortoiseGitBlameView::OnFilePrintPreview)\r
+       ON_COMMAND(ID_EDIT_FIND,OnEditFind)\r
+       ON_COMMAND(ID_EDIT_GOTO,OnEditGoto)\r
        ON_WM_CREATE()\r
        ON_WM_SIZE()\r
        ON_WM_MOUSEMOVE()\r
@@ -49,8 +54,10 @@ BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
        ON_WM_RBUTTONDOWN()\r
        ON_NOTIFY(SCN_PAINTED,0,OnSciPainted)\r
        ON_NOTIFY(SCN_GETBKCOLOR,0,OnSciGetBkColor)\r
+    ON_REGISTERED_MESSAGE(m_FindDialogMessage,   OnFindDialogMessage)  \r
 END_MESSAGE_MAP()\r
 \r
+\r
 // CTortoiseGitBlameView construction/destruction\r
 \r
 CTortoiseGitBlameView::CTortoiseGitBlameView()\r
@@ -95,6 +102,9 @@ CTortoiseGitBlameView::CTortoiseGitBlameView()
 \r
        m_bShowAuthor=true;\r
        m_bShowDate=false;\r
+\r
+    m_FindDialogMessage   =   ::RegisterWindowMessage(FINDMSGSTRING);   \r
+       m_pFindDialog = NULL;\r
 }\r
 \r
 CTortoiseGitBlameView::~CTortoiseGitBlameView()\r
@@ -122,7 +132,12 @@ int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
        m_wEditor = m_TextView.m_hWnd;\r
        CreateFont();\r
        InitialiseEditor();\r
+       m_ToolTip.Create(this->GetParent());    \r
+       m_ToolTip.AddTool(this,_T("Test"));\r
+       \r
+       ::AfxGetApp()->GetMainWnd();\r
        return CView::OnCreate(lpcs);\r
+       \r
 }\r
 \r
 void CTortoiseGitBlameView::OnSize(UINT nType,int cx, int cy)\r
@@ -581,7 +596,7 @@ void CTortoiseGitBlameView::InitialiseEditor()
 \r
 void CTortoiseGitBlameView::StartSearch()\r
 {\r
-       if (currentDialog)\r
+       if (m_pFindDialog)\r
                return;\r
        bool bCase = false;\r
        // Initialize FINDREPLACE\r
@@ -598,87 +613,53 @@ void CTortoiseGitBlameView::StartSearch()
        currentDialog = FindText(&fr);\r
 }\r
 \r
-bool CTortoiseGitBlameView::DoSearch(LPSTR what, DWORD flags)\r
+bool CTortoiseGitBlameView::DoSearch(CString what, DWORD flags)\r
 {\r
-#if 0\r
-       TCHAR szWhat[80];\r
+\r
+       //char szWhat[80];\r
        int pos = SendEditor(SCI_GETCURRENTPOS);\r
        int line = SendEditor(SCI_LINEFROMPOSITION, pos);\r
        bool bFound = false;\r
        bool bCaseSensitive = !!(flags & FR_MATCHCASE);\r
 \r
-       strcpy_s(szWhat, sizeof(szWhat), what);\r
+       //strcpy_s(szWhat, sizeof(szWhat), what);\r
 \r
        if(!bCaseSensitive)\r
        {\r
-               char *p;\r
-               size_t len = strlen(szWhat);\r
-               for (p = szWhat; p < szWhat + len; p++)\r
-               {\r
-                       if (isupper(*p)&&__isascii(*p))\r
-                               *p = _tolower(*p);\r
-               }\r
+               what=what.MakeLower();\r
        }\r
 \r
-       CString sWhat = CString(szWhat);\r
+       //CString sWhat = CString(szWhat);\r
        \r
-       char buf[20];\r
-       int i=0;\r
-       for (i=line; (i<(int)authors.size())&&(!bFound); ++i)\r
+       //char buf[20];\r
+       //int i=0;\r
+       int i=line;\r
+       do\r
        {\r
                int bufsize = SendEditor(SCI_GETLINE, i);\r
                char * linebuf = new char[bufsize+1];\r
                SecureZeroMemory(linebuf, bufsize+1);\r
                SendEditor(SCI_GETLINE, i, (LPARAM)linebuf);\r
+               CString oneline=this->m_TextView.StringFromControl(linebuf);\r
                if (!bCaseSensitive)\r
                {\r
-                       char *p;\r
-                       for (p = linebuf; p < linebuf + bufsize; p++)\r
-                       {\r
-                               if (isupper(*p)&&__isascii(*p))\r
-                                       *p = _tolower(*p);\r
-                       }\r
+                       oneline=oneline.MakeLower();\r
                }\r
-               _stprintf_s(buf, 20, _T("%ld"), revs[i]);\r
-               if (authors[i].compare(sWhat)==0)\r
+               //_stprintf_s(buf, 20, _T("%ld"), revs[i]);\r
+               if (this->m_Authors[i].Find(what)>=0)\r
                        bFound = true;\r
-               else if ((!bCaseSensitive)&&(_stricmp(authors[i].c_str(), szWhat)==0))\r
+               else if ((!bCaseSensitive)&&(this->m_Authors[i].MakeLower().Find(what)>=0))\r
                        bFound = true;\r
-               else if (strcmp(buf, szWhat) == 0)\r
-                       bFound = true;\r
-               else if (strstr(linebuf, szWhat))\r
+               else if (oneline.Find(what) >=0)\r
                        bFound = true;\r
+               \r
                delete [] linebuf;\r
-       }\r
-       if (!bFound)\r
-       {\r
-               for (i=0; (i<line)&&(!bFound); ++i)\r
-               {\r
-                       int bufsize = SendEditor(SCI_GETLINE, i);\r
-                       char * linebuf = new char[bufsize+1];\r
-                       SecureZeroMemory(linebuf, bufsize+1);\r
-                       SendEditor(SCI_GETLINE, i, (LPARAM)linebuf);\r
-                       if (!bCaseSensitive)\r
-                       {\r
-                               char *p;\r
-                               for (p = linebuf; p < linebuf + bufsize; p++)\r
-                               {\r
-                                       if (isupper(*p)&&__isascii(*p))\r
-                                               *p = _tolower(*p);\r
-                               }\r
-                       }\r
-                       _stprintf_s(buf, 20, _T("%ld"), revs[i]);\r
-                       if (authors[i].compare(sWhat)==0)\r
-                               bFound = true;\r
-                       else if ((!bCaseSensitive)&&(_stricmp(authors[i].c_str(), szWhat)==0))\r
-                               bFound = true;\r
-                       else if (strcmp(buf, szWhat) == 0)\r
-                               bFound = true;\r
-                       else if (strstr(linebuf, szWhat))\r
-                               bFound = true;\r
-                       delete [] linebuf;\r
-               }\r
-       }\r
+\r
+               i++;\r
+               if(i>=m_CommitHash.size())\r
+                       i=0;\r
+       }while(i!=line &&(!bFound));\r
+\r
        if (bFound)\r
        {\r
                GotoLine(i);\r
@@ -690,21 +671,20 @@ bool CTortoiseGitBlameView::DoSearch(LPSTR what, DWORD flags)
        }\r
        else\r
        {\r
-               ::MessageBox(wMain, searchstringnotfound, "CTortoiseGitBlameView", MB_ICONINFORMATION);\r
+               ::MessageBox(wMain, what+_T(" not found"), _T("CTortoiseGitBlameView"), MB_ICONINFORMATION);\r
        }\r
-#endif\r
+\r
        return true;\r
 }\r
 \r
 bool CTortoiseGitBlameView::GotoLine(long line)\r
 {\r
-#if 0\r
        --line;\r
        if (line < 0)\r
                return false;\r
-       if ((unsigned long)line >= authors.size())\r
+       if ((unsigned long)line >= m_CommitHash.size())\r
        {\r
-               line = authors.size()-1;\r
+               line = m_CommitHash.size()-1;\r
        }\r
 \r
        int nCurrentPos = SendEditor(SCI_GETCURRENTPOS);\r
@@ -734,7 +714,7 @@ bool CTortoiseGitBlameView::GotoLine(long line)
        int nPosStart = SendEditor(SCI_POSITIONFROMLINE,line);\r
        int nPosEnd = SendEditor(SCI_GETLINEENDPOSITION,line);\r
        SendEditor(SCI_SETSEL,nPosEnd,nPosStart);\r
-#endif\r
+\r
        return true;\r
 }\r
 \r
@@ -1132,8 +1112,8 @@ void CTortoiseGitBlameView::DrawBlame(HDC hDC)
                        ::SetTextColor(hDC, m_textcolor);\r
                        if (m_CommitHash[i].GetLength()>0)\r
                        {\r
-                               if (m_CommitHash[i].Compare(m_MouseHash)==0)\r
-                                       ::SetBkColor(hDC, m_mouseauthorcolor);\r
+                               //if (m_CommitHash[i].Compare(m_MouseHash)==0)\r
+                               //      ::SetBkColor(hDC, m_mouseauthorcolor);\r
                                if (m_CommitHash[i].Compare(m_SelectedHash)==0)\r
                                {\r
                                        ::SetBkColor(hDC, m_selectedauthorcolor);\r
@@ -1141,6 +1121,10 @@ void CTortoiseGitBlameView::DrawBlame(HDC hDC)
                                        sel = TRUE;\r
                                }\r
                        }\r
+\r
+                       if(m_MouseLine == i)\r
+                               ::SetBkColor(hDC, m_mouserevcolor);\r
+\r
                        //if ((revs[i] == m_mouserev)&&(!sel))\r
                        //      ::SetBkColor(hDC, m_mouserevcolor);\r
                        //if (revs[i] == m_selectedrev)\r
@@ -1186,7 +1170,7 @@ void CTortoiseGitBlameView::DrawBlame(HDC hDC)
                                Left += m_authorwidth;\r
                        }\r
 #endif\r
-                       if ((i==m_SelectedLine)&&(currentDialog))\r
+                       if ((i==m_SelectedLine)&&(m_pFindDialog))\r
                        {\r
                                LOGBRUSH brush;\r
                                brush.lbColor = m_textcolor;\r
@@ -2607,4 +2591,130 @@ void CTortoiseGitBlameView::FocusOn(GitRev *pRev)
        this->Invalidate();\r
        this->m_TextView.Invalidate();\r
 \r
-}
\ No newline at end of file
+}\r
+\r
+void CTortoiseGitBlameView::OnMouseHover(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
+               if (line != m_MouseLine)\r
+               {\r
+                       m_MouseLine = line;//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
+                       GitRev *pRev;\r
+                       pRev=&this->GetLogData()->at(this->GetLogList()->GetItemCount()-m_ID[line]);\r
+                       //this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);\r
+                       this->ClientToScreen(&point);\r
+                       //BALLOON_INFO bi;\r
+                       //if(m_ToolTip.GetTool(this, bi))\r
+                       //{\r
+                       //      bi.sBalloonTip=pRev->m_CommitHash;\r
+                               CString str;\r
+                               str.Format(_T("%s\n<b>%s</b>\n%s\n%s"),pRev->m_CommitHash,\r
+                                                                                                          pRev->m_Subject,\r
+                                                                                                          pRev->m_AuthorDate.Format(_T("%Y-%m-%d %H:%M")),\r
+                                                                                                          pRev->m_Body);\r
+                               m_ToolTip.AddTool(this,str);\r
+                               m_ToolTip.DisplayToolTip(&point);\r
+                       //}\r
+       \r
+                       CRect rect;\r
+                       this->ScreenToClient(&point);\r
+                       rect.left=LOCATOR_WIDTH;\r
+                       rect.right=this->m_blamewidth+rect.left;\r
+                       rect.top=point.y-height;\r
+                       rect.bottom=point.y+height;\r
+                       this->InvalidateRect(rect);\r
+\r
+               }\r
+               else\r
+               {\r
+                       m_MouseLine=-1;\r
+//                     app.m_selecteddate.clear();\r
+//                     app.m_selectedrev = -2;\r
+//                     app.m_selectedorigrev = -2;\r
+               }\r
+               //::InvalidateRect( NULL, FALSE);\r
+               //this->Invalidate();\r
+       }\r
+       \r
+//      const CString str=_T("this is a <b>Message Balloon</b>\n<hr=100%>\n<ct=0x0000FF>Warning! Warning!</ct>\nSomething unexpected happened");\r
+        //CBalloon::ShowBalloon(NULL, point, \r
+         //            str,\r
+         //             FALSE, (HICON)IDI_EXCLAMATION,\r
+               //                 (UINT)CBalloon ::BALLOON_RIGHT_TOP, (UINT)CBalloon ::BALLOON_EFFECT_SOLID,(COLORREF)NULL,  (COLORREF)NULL,  (COLORREF)NULL);\r
+}\r
+\r
+void CTortoiseGitBlameView::OnMouseMove(UINT nFlags, CPoint point)\r
+{\r
+       TRACKMOUSEEVENT tme;\r
+       tme.cbSize=sizeof(TRACKMOUSEEVENT);\r
+       tme.dwFlags=TME_HOVER|TME_LEAVE;\r
+       tme.hwndTrack=this->m_hWnd;\r
+       tme.dwHoverTime=1;\r
+       TrackMouseEvent(&tme);\r
+}\r
+\r
+\r
+BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)\r
+{\r
+       m_ToolTip.RelayEvent(pMsg);\r
+       return CView::PreTranslateMessage(pMsg);\r
+}\r
+\r
+void CTortoiseGitBlameView::OnEditFind()\r
+{\r
+    m_pFindDialog=new CFindReplaceDialog();\r
+       \r
+    m_pFindDialog->Create(TRUE,_T(""),NULL,FR_DOWN,this);  \r
+}\r
+\r
+void CTortoiseGitBlameView::OnEditGoto()\r
+{\r
+    CEditGotoDlg dlg;\r
+    if(dlg.DoModal()==IDOK)\r
+    {\r
+        this->GotoLine(dlg.m_LineNumber);\r
+    }\r
+}\r
+\r
+LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM   wParam,   LPARAM   lParam)//Õâ¸öÒ²ÊÇÕÒÄǸö³ÌÐò¸ÄµÄ£¬Ö»²»¹ý»»³ÉÁË×Ô¼ºµÄÀà   \r
+{   \r
+    ASSERT(m_pFindDialog   !=   NULL);   \r
+    \r
+    //   If   the   FR_DIALOGTERM   flag   is   set,   \r
+          //   invalidate   the   handle   identifying   the   dialog   box.   \r
+    if   (m_pFindDialog->IsTerminating())   \r
+    {   \r
+            m_pFindDialog   =   NULL;   \r
+            return   0;   \r
+    }   \r
+\r
+    //   If   the   FR_FINDNEXT   flag   is   set,   \r
+    //   call   the   application-defined   search   routine   \r
+    //   to   search   for   the   requested   string.   \r
+    if(m_pFindDialog->FindNext())   \r
+    {   \r
+            //read   data   from   dialog   \r
+        CString   FindName   =   m_pFindDialog->GetFindString();   \r
+        bool   bMatchCase   =   m_pFindDialog->MatchCase()   ==   TRUE;   \r
+        bool   bMatchWholeWord   =   m_pFindDialog->MatchWholeWord()   ==   TRUE;   \r
+        bool   bSearchDown   =   m_pFindDialog->SearchDown()   ==   TRUE;   \r
+               \r
+               DoSearch(FindName,m_pFindDialog->m_fr.Flags);\r
+            //with   given   name   do   search   \r
+    //        *FindWhatYouNeed(FindName,   bMatchCase,   bMatchWholeWord,   bSearchDown);   \r
+    }   \r
+\r
+    return   0;   \r
+}   \r
+\r