OSDN Git Service

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