OSDN Git Service

GitBlame Use command Line argument to open file
[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 \r
16 #ifdef _DEBUG\r
17 #define new DEBUG_NEW\r
18 #endif\r
19 \r
20 \r
21 // CTortoiseGitBlameDoc\r
22 \r
23 IMPLEMENT_DYNCREATE(CTortoiseGitBlameDoc, CDocument)\r
24 \r
25 BEGIN_MESSAGE_MAP(CTortoiseGitBlameDoc, CDocument)\r
26 END_MESSAGE_MAP()\r
27 \r
28 \r
29 // CTortoiseGitBlameDoc construction/destruction\r
30 \r
31 CTortoiseGitBlameDoc::CTortoiseGitBlameDoc()\r
32 {\r
33         // TODO: add one-time construction code here\r
34 \r
35 }\r
36 \r
37 CTortoiseGitBlameDoc::~CTortoiseGitBlameDoc()\r
38 {\r
39 }\r
40 \r
41 BOOL CTortoiseGitBlameDoc::OnNewDocument()\r
42 {\r
43         if (!CDocument::OnNewDocument())\r
44                 return FALSE;\r
45 \r
46         // TODO: add reinitialization code here\r
47         // (SDI documents will reuse this document)\r
48 \r
49         return TRUE;\r
50 }\r
51 BOOL CTortoiseGitBlameDoc::OnOpenDocument(LPCTSTR lpszPathName)\r
52 {\r
53         return OnOpenDocument(lpszPathName,_T(""));\r
54 }\r
55 \r
56 BOOL CTortoiseGitBlameDoc::OnOpenDocument(LPCTSTR lpszPathName,CString Rev)\r
57 {\r
58         if (!CDocument::OnOpenDocument(lpszPathName))\r
59                 return FALSE;\r
60 \r
61         m_CurrentFileName=lpszPathName;\r
62 \r
63         m_Rev=Rev;\r
64 \r
65         // TODO: add reinitialization code here\r
66         // (SDI documents will reuse this document)\r
67         if(!CGit::CheckMsysGitDir())\r
68         {\r
69                 CMessageBox::Show(NULL,_T("MsysGit have not install or config fail"),_T("TortoiseGitBlame"),MB_OK);\r
70                 return FALSE;\r
71         }\r
72 \r
73         GitAdminDir admindir;\r
74         CString topdir;\r
75         if(!admindir.HasAdminDir(lpszPathName,&topdir))\r
76         {\r
77                 CMessageBox::Show(NULL,CString(lpszPathName)+_T(" is not controled by git\nJust Show File Context"),_T("TortoiseGitBlame"),MB_OK);\r
78         }else\r
79         {\r
80                 m_IsGitFile=TRUE;\r
81                 g_Git.m_CurrentDir=topdir;\r
82                 GetMainFrame()->m_wndOutput.LoadHistory(lpszPathName);\r
83                 \r
84                 CString cmd;\r
85                 CTGitPath path;\r
86                 path.SetFromWin(lpszPathName);\r
87                 cmd.Format(_T("git.exe blame -s -l %s -- \"%s\""),Rev,path.GetGitPathString());\r
88                 m_BlameData.Empty();\r
89                 if(g_Git.Run(cmd,&m_BlameData))\r
90                 {\r
91                         CMessageBox::Show(NULL,CString(_T("Blame Error"))+m_BlameData,_T("TortoiseGitBlame"),MB_OK);\r
92 \r
93                 }\r
94                 CTortoiseGitBlameView *pView=DYNAMIC_DOWNCAST(CTortoiseGitBlameView,GetMainFrame()->GetActiveView());\r
95                 if(pView == NULL)\r
96                 {\r
97                         CWnd* pWnd = GetMainFrame()->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);\r
98                         if (pWnd != NULL && pWnd->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameView)))\r
99                         {\r
100                                 pView = (CTortoiseGitBlameView*)pWnd;\r
101                         }\r
102                         else\r
103                         {\r
104                                 return FALSE;\r
105                         }\r
106                 }\r
107                 pView->UpdateInfo();            \r
108         }\r
109 \r
110         return TRUE;\r
111 }\r
112 \r
113 void CTortoiseGitBlameDoc::SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU)\r
114 {\r
115         CDocument::SetPathName(lpszPathName,bAddToMRU);\r
116 \r
117         CString title;\r
118         if(m_Rev.IsEmpty())\r
119                 title=CString(lpszPathName)+_T(":HEAD");\r
120         else\r
121                 title=CString(lpszPathName)+_T(":")+m_Rev;\r
122 \r
123         this->SetTitle(title);\r
124 }\r
125 \r
126 // CTortoiseGitBlameDoc serialization\r
127 \r
128 void CTortoiseGitBlameDoc::Serialize(CArchive& ar)\r
129 {\r
130         if (ar.IsStoring())\r
131         {\r
132                 // TODO: add storing code here\r
133         }\r
134         else\r
135         {\r
136                 // TODO: add loading code here\r
137         }\r
138 }\r
139 \r
140 \r
141 // CTortoiseGitBlameDoc diagnostics\r
142 \r
143 #ifdef _DEBUG\r
144 void CTortoiseGitBlameDoc::AssertValid() const\r
145 {\r
146         CDocument::AssertValid();\r
147 }\r
148 \r
149 void CTortoiseGitBlameDoc::Dump(CDumpContext& dc) const\r
150 {\r
151         CDocument::Dump(dc);\r
152 }\r
153 #endif //_DEBUG\r
154 \r
155 \r
156 // CTortoiseGitBlameDoc commands\r