OSDN Git Service

Fix TortoiseGitBlame commit is not in log list problem.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseGitBlame / TortoiseGitBlameDoc.cpp
1 \r
2 // TortoiseGitBlameDoc.cpp : implementation of the CTortoiseGitBlameDoc class\r
3 //\r
4 \r
5 #include "stdafx.h"\r
6 #include "TortoiseGitBlame.h"\r
7 \r
8 #include "TortoiseGitBlameDoc.h"\r
9 #include "GitAdminDir.h"\r
10 #include "MessageBox.h"\r
11 #include "Git.h"\r
12 #include "MainFrm.h"\r
13 #include "TGitPath.h"\r
14 #include "TortoiseGitBlameView.h"\r
15 #include "CmdLineParser.h"\r
16 \r
17 #ifdef _DEBUG\r
18 #define new DEBUG_NEW\r
19 #endif\r
20 \r
21 \r
22 // CTortoiseGitBlameDoc\r
23 \r
24 IMPLEMENT_DYNCREATE(CTortoiseGitBlameDoc, CDocument)\r
25 \r
26 BEGIN_MESSAGE_MAP(CTortoiseGitBlameDoc, CDocument)\r
27 END_MESSAGE_MAP()\r
28 \r
29 \r
30 // CTortoiseGitBlameDoc construction/destruction\r
31 \r
32 CTortoiseGitBlameDoc::CTortoiseGitBlameDoc()\r
33 {\r
34         // TODO: add one-time construction code here\r
35 \r
36 }\r
37 \r
38 CTortoiseGitBlameDoc::~CTortoiseGitBlameDoc()\r
39 {\r
40 }\r
41 \r
42 BOOL CTortoiseGitBlameDoc::OnNewDocument()\r
43 {\r
44         if (!CDocument::OnNewDocument())\r
45                 return FALSE;\r
46 \r
47         // TODO: add reinitialization code here\r
48         // (SDI documents will reuse this document)\r
49 \r
50         return TRUE;\r
51 }\r
52 BOOL CTortoiseGitBlameDoc::OnOpenDocument(LPCTSTR lpszPathName)\r
53 {\r
54         CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);\r
55         if(parser.HasVal(_T("rev")))\r
56         {\r
57                 m_Rev=parser.GetVal(_T("rev"));\r
58         }else\r
59         {\r
60                 m_Rev.Empty();\r
61         }\r
62 \r
63         return OnOpenDocument(lpszPathName,m_Rev);\r
64 }\r
65 \r
66 BOOL CTortoiseGitBlameDoc::OnOpenDocument(LPCTSTR lpszPathName,CString Rev)\r
67 {\r
68         if (!CDocument::OnOpenDocument(lpszPathName))\r
69                 return FALSE;\r
70 \r
71         m_CurrentFileName=lpszPathName;\r
72         m_Rev=Rev;\r
73 \r
74         // TODO: add reinitialization code here\r
75         // (SDI documents will reuse this document)\r
76         if(!CGit::CheckMsysGitDir())\r
77         {\r
78                 CMessageBox::Show(NULL,_T("MsysGit have not install or config fail"),_T("TortoiseGitBlame"),MB_OK);\r
79                 return FALSE;\r
80         }\r
81 \r
82         GitAdminDir admindir;\r
83         CString topdir;\r
84         if(!admindir.HasAdminDir(lpszPathName,&topdir))\r
85         {\r
86                 CMessageBox::Show(NULL,CString(lpszPathName)+_T(" is not controled by git\nJust Show File Context"),_T("TortoiseGitBlame"),MB_OK);\r
87         }else\r
88         {\r
89                 m_IsGitFile=TRUE;\r
90                 g_Git.m_CurrentDir=topdir;\r
91 \r
92                 CString PathName=lpszPathName;\r
93                 PathName=PathName.Right(PathName.GetLength()-g_Git.m_CurrentDir.GetLength()-1);\r
94                 CTGitPath path;\r
95                 path.SetFromWin(PathName);\r
96 \r
97                 if(!g_Git.m_CurrentDir.IsEmpty())\r
98                         SetCurrentDirectory(g_Git.m_CurrentDir);\r
99                 \r
100                 m_GitPath = path;\r
101                 GetMainFrame()->m_wndOutput.LoadHistory(path.GetGitPathString());\r
102         \r
103                 CString cmd;\r
104                 \r
105                 cmd.Format(_T("git.exe blame -s -l %s -- \"%s\""),Rev,path.GetGitPathString());\r
106                 m_BlameData.Empty();\r
107                 if(g_Git.Run(cmd,&m_BlameData,CP_UTF8))\r
108                 {\r
109                         CMessageBox::Show(NULL,CString(_T("Blame Error"))+m_BlameData,_T("TortoiseGitBlame"),MB_OK);\r
110 \r
111                 }\r
112                 CTortoiseGitBlameView *pView=DYNAMIC_DOWNCAST(CTortoiseGitBlameView,GetMainFrame()->GetActiveView());\r
113                 if(pView == NULL)\r
114                 {\r
115                         CWnd* pWnd = GetMainFrame()->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);\r
116                         if (pWnd != NULL && pWnd->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameView)))\r
117                         {\r
118                                 pView = (CTortoiseGitBlameView*)pWnd;\r
119                         }\r
120                         else\r
121                         {\r
122                                 return FALSE;\r
123                         }\r
124                 }\r
125                 pView->UpdateInfo();            \r
126         }\r
127 \r
128         return TRUE;\r
129 }\r
130 \r
131 void CTortoiseGitBlameDoc::SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU)\r
132 {\r
133         CDocument::SetPathName(lpszPathName,bAddToMRU);\r
134 \r
135         CString title;\r
136         if(m_Rev.IsEmpty())\r
137                 title=CString(lpszPathName)+_T(":HEAD");\r
138         else\r
139                 title=CString(lpszPathName)+_T(":")+m_Rev;\r
140 \r
141         this->SetTitle(title);\r
142 }\r
143 \r
144 // CTortoiseGitBlameDoc serialization\r
145 \r
146 void CTortoiseGitBlameDoc::Serialize(CArchive& ar)\r
147 {\r
148         if (ar.IsStoring())\r
149         {\r
150                 // TODO: add storing code here\r
151         }\r
152         else\r
153         {\r
154                 // TODO: add loading code here\r
155         }\r
156 }\r
157 \r
158 \r
159 // CTortoiseGitBlameDoc diagnostics\r
160 \r
161 #ifdef _DEBUG\r
162 void CTortoiseGitBlameDoc::AssertValid() const\r
163 {\r
164         CDocument::AssertValid();\r
165 }\r
166 \r
167 void CTortoiseGitBlameDoc::Dump(CDumpContext& dc) const\r
168 {\r
169         CDocument::Dump(dc);\r
170 }\r
171 #endif //_DEBUG\r
172 \r
173 \r
174 // CTortoiseGitBlameDoc commands\r