OSDN Git Service

merge original branch.
[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                 if(topdir[topdir.GetLength()-1] == _T('\\') || \r
94                         topdir[topdir.GetLength()-1] == _T('/'))\r
95                         PathName=PathName.Right(PathName.GetLength()-g_Git.m_CurrentDir.GetLength());\r
96                 else\r
97                         PathName=PathName.Right(PathName.GetLength()-g_Git.m_CurrentDir.GetLength()-1);\r
98 \r
99                 CTGitPath path;\r
100                 path.SetFromWin(PathName);\r
101 \r
102                 if(!g_Git.m_CurrentDir.IsEmpty())\r
103                         SetCurrentDirectory(g_Git.m_CurrentDir);\r
104                 \r
105                 m_GitPath = path;\r
106                 GetMainFrame()->m_wndOutput.LoadHistory(path.GetGitPathString());\r
107         \r
108                 CString cmd;\r
109                 \r
110                 cmd.Format(_T("git.exe blame -s -l %s -- \"%s\""),Rev,path.GetGitPathString());\r
111                 m_BlameData.Empty();\r
112                 if(g_Git.Run(cmd,&m_BlameData,CP_UTF8))\r
113                 {\r
114                         CMessageBox::Show(NULL,CString(_T("Blame Error"))+m_BlameData,_T("TortoiseGitBlame"),MB_OK);\r
115 \r
116                 }\r
117                 CTortoiseGitBlameView *pView=DYNAMIC_DOWNCAST(CTortoiseGitBlameView,GetMainFrame()->GetActiveView());\r
118                 if(pView == NULL)\r
119                 {\r
120                         CWnd* pWnd = GetMainFrame()->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);\r
121                         if (pWnd != NULL && pWnd->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameView)))\r
122                         {\r
123                                 pView = (CTortoiseGitBlameView*)pWnd;\r
124                         }\r
125                         else\r
126                         {\r
127                                 return FALSE;\r
128                         }\r
129                 }\r
130                 pView->UpdateInfo();            \r
131         }\r
132 \r
133         return TRUE;\r
134 }\r
135 \r
136 void CTortoiseGitBlameDoc::SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU)\r
137 {\r
138         CDocument::SetPathName(lpszPathName,bAddToMRU);\r
139 \r
140         CString title;\r
141         if(m_Rev.IsEmpty())\r
142                 title=CString(lpszPathName)+_T(":HEAD");\r
143         else\r
144                 title=CString(lpszPathName)+_T(":")+m_Rev;\r
145 \r
146         this->SetTitle(title);\r
147 }\r
148 \r
149 // CTortoiseGitBlameDoc serialization\r
150 \r
151 void CTortoiseGitBlameDoc::Serialize(CArchive& ar)\r
152 {\r
153         if (ar.IsStoring())\r
154         {\r
155                 // TODO: add storing code here\r
156         }\r
157         else\r
158         {\r
159                 // TODO: add loading code here\r
160         }\r
161 }\r
162 \r
163 \r
164 // CTortoiseGitBlameDoc diagnostics\r
165 \r
166 #ifdef _DEBUG\r
167 void CTortoiseGitBlameDoc::AssertValid() const\r
168 {\r
169         CDocument::AssertValid();\r
170 }\r
171 \r
172 void CTortoiseGitBlameDoc::Dump(CDumpContext& dc) const\r
173 {\r
174         CDocument::Dump(dc);\r
175 }\r
176 #endif //_DEBUG\r
177 \r
178 \r
179 // CTortoiseGitBlameDoc commands\r