OSDN Git Service

Update version number to 1.2.1.0
[tortoisegit/TortoiseGitJp.git] / src / TortoiseGitBlame / TortoiseGitBlameDoc.cpp
index a04d238..2df2566 100644 (file)
@@ -6,6 +6,13 @@
 #include "TortoiseGitBlame.h"\r
 \r
 #include "TortoiseGitBlameDoc.h"\r
+#include "GitAdminDir.h"\r
+#include "MessageBox.h"\r
+#include "Git.h"\r
+#include "MainFrm.h"\r
+#include "TGitPath.h"\r
+#include "TortoiseGitBlameView.h"\r
+#include "CmdLineParser.h"\r
 \r
 #ifdef _DEBUG\r
 #define new DEBUG_NEW\r
@@ -42,9 +49,102 @@ BOOL CTortoiseGitBlameDoc::OnNewDocument()
 \r
        return TRUE;\r
 }\r
+BOOL CTortoiseGitBlameDoc::OnOpenDocument(LPCTSTR lpszPathName)\r
+{\r
+       CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);\r
+       if(parser.HasVal(_T("rev")))\r
+       {\r
+               m_Rev=parser.GetVal(_T("rev"));\r
+       }else\r
+       {\r
+               m_Rev.Empty();\r
+       }\r
+\r
+       return OnOpenDocument(lpszPathName,m_Rev);\r
+}\r
+\r
+BOOL CTortoiseGitBlameDoc::OnOpenDocument(LPCTSTR lpszPathName,CString Rev)\r
+{\r
+       if (!CDocument::OnOpenDocument(lpszPathName))\r
+               return FALSE;\r
+\r
+       m_CurrentFileName=lpszPathName;\r
+       m_Rev=Rev;\r
+\r
+       // TODO: add reinitialization code here\r
+       // (SDI documents will reuse this document)\r
+       if(!CGit::CheckMsysGitDir())\r
+       {\r
+               CMessageBox::Show(NULL,_T("MsysGit have not install or config fail"),_T("TortoiseGitBlame"),MB_OK);\r
+               return FALSE;\r
+       }\r
 \r
+       GitAdminDir admindir;\r
+       CString topdir;\r
+       if(!admindir.HasAdminDir(lpszPathName,&topdir))\r
+       {\r
+               CMessageBox::Show(NULL,CString(lpszPathName)+_T(" is not controled by git\nJust Show File Context"),_T("TortoiseGitBlame"),MB_OK);\r
+       }else\r
+       {\r
+               m_IsGitFile=TRUE;\r
+               g_Git.m_CurrentDir=topdir;\r
+\r
+               CString PathName=lpszPathName;\r
+               if(topdir[topdir.GetLength()-1] == _T('\\') || \r
+                       topdir[topdir.GetLength()-1] == _T('/'))\r
+                       PathName=PathName.Right(PathName.GetLength()-g_Git.m_CurrentDir.GetLength());\r
+               else\r
+                       PathName=PathName.Right(PathName.GetLength()-g_Git.m_CurrentDir.GetLength()-1);\r
+\r
+               CTGitPath path;\r
+               path.SetFromWin(PathName);\r
+\r
+               if(!g_Git.m_CurrentDir.IsEmpty())\r
+                       SetCurrentDirectory(g_Git.m_CurrentDir);\r
+               \r
+               m_GitPath = path;\r
+               GetMainFrame()->m_wndOutput.LoadHistory(path.GetGitPathString());\r
+       \r
+               CString cmd;\r
+               \r
+               cmd.Format(_T("git.exe blame -s -l %s -- \"%s\""),Rev,path.GetGitPathString());\r
+               m_BlameData.Empty();\r
+               if(g_Git.Run(cmd,&m_BlameData,CP_UTF8))\r
+               {\r
+                       CMessageBox::Show(NULL,CString(_T("Blame Error"))+m_BlameData,_T("TortoiseGitBlame"),MB_OK);\r
+\r
+               }\r
+               CTortoiseGitBlameView *pView=DYNAMIC_DOWNCAST(CTortoiseGitBlameView,GetMainFrame()->GetActiveView());\r
+               if(pView == NULL)\r
+               {\r
+                       CWnd* pWnd = GetMainFrame()->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);\r
+                       if (pWnd != NULL && pWnd->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameView)))\r
+                       {\r
+                               pView = (CTortoiseGitBlameView*)pWnd;\r
+                       }\r
+                       else\r
+                       {\r
+                               return FALSE;\r
+                       }\r
+               }\r
+               pView->UpdateInfo();            \r
+       }\r
 \r
+       return TRUE;\r
+}\r
+\r
+void CTortoiseGitBlameDoc::SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU)\r
+{\r
+       CDocument::SetPathName(lpszPathName,bAddToMRU);\r
 \r
+       CString title;\r
+       if(m_Rev.IsEmpty())\r
+               title=CString(lpszPathName)+_T(":HEAD");\r
+       else\r
+               title=CString(lpszPathName)+_T(":")+m_Rev;\r
+\r
+       this->SetTitle(title);\r
+}\r
 \r
 // CTortoiseGitBlameDoc serialization\r
 \r