2 // TortoiseGitBlameDoc.cpp : implementation of the CTortoiseGitBlameDoc class
6 #include "TortoiseGitBlame.h"
8 #include "TortoiseGitBlameDoc.h"
9 #include "GitAdminDir.h"
10 #include "MessageBox.h"
14 #include "TortoiseGitBlameView.h"
15 #include "CmdLineParser.h"
22 // CTortoiseGitBlameDoc
24 IMPLEMENT_DYNCREATE(CTortoiseGitBlameDoc
, CDocument
)
26 BEGIN_MESSAGE_MAP(CTortoiseGitBlameDoc
, CDocument
)
30 // CTortoiseGitBlameDoc construction/destruction
32 CTortoiseGitBlameDoc::CTortoiseGitBlameDoc()
34 // TODO: add one-time construction code here
38 CTortoiseGitBlameDoc::~CTortoiseGitBlameDoc()
42 BOOL
CTortoiseGitBlameDoc::OnNewDocument()
44 if (!CDocument::OnNewDocument())
47 // TODO: add reinitialization code here
48 // (SDI documents will reuse this document)
52 BOOL
CTortoiseGitBlameDoc::OnOpenDocument(LPCTSTR lpszPathName
)
54 CCmdLineParser
parser(AfxGetApp()->m_lpCmdLine
);
55 if(parser
.HasVal(_T("rev")))
57 m_Rev
=parser
.GetVal(_T("rev"));
63 return OnOpenDocument(lpszPathName
,m_Rev
);
66 BOOL
CTortoiseGitBlameDoc::OnOpenDocument(LPCTSTR lpszPathName
,CString Rev
)
68 if (!CDocument::OnOpenDocument(lpszPathName
))
71 m_CurrentFileName
=lpszPathName
;
74 // TODO: add reinitialization code here
75 // (SDI documents will reuse this document)
76 if(!CGit::CheckMsysGitDir())
78 CMessageBox::Show(NULL
,_T("MsysGit have not install or config fail"),_T("TortoiseGitBlame"),MB_OK
);
84 if(!admindir
.HasAdminDir(lpszPathName
,&topdir
))
86 CMessageBox::Show(NULL
,CString(lpszPathName
)+_T(" is not controled by git\nJust Show File Context"),_T("TortoiseGitBlame"),MB_OK
);
90 g_Git
.m_CurrentDir
=topdir
;
91 GetMainFrame()->m_wndOutput
.LoadHistory(lpszPathName
);
95 path
.SetFromWin(lpszPathName
);
96 cmd
.Format(_T("git.exe blame -s -l %s -- \"%s\""),Rev
,path
.GetGitPathString());
98 if(g_Git
.Run(cmd
,&m_BlameData
))
100 CMessageBox::Show(NULL
,CString(_T("Blame Error"))+m_BlameData
,_T("TortoiseGitBlame"),MB_OK
);
103 CTortoiseGitBlameView
*pView
=DYNAMIC_DOWNCAST(CTortoiseGitBlameView
,GetMainFrame()->GetActiveView());
106 CWnd
* pWnd
= GetMainFrame()->GetDescendantWindow(AFX_IDW_PANE_FIRST
, TRUE
);
107 if (pWnd
!= NULL
&& pWnd
->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameView
)))
109 pView
= (CTortoiseGitBlameView
*)pWnd
;
122 void CTortoiseGitBlameDoc::SetPathName(LPCTSTR lpszPathName
, BOOL bAddToMRU
)
124 CDocument::SetPathName(lpszPathName
,bAddToMRU
);
128 title
=CString(lpszPathName
)+_T(":HEAD");
130 title
=CString(lpszPathName
)+_T(":")+m_Rev
;
132 this->SetTitle(title
);
135 // CTortoiseGitBlameDoc serialization
137 void CTortoiseGitBlameDoc::Serialize(CArchive
& ar
)
141 // TODO: add storing code here
145 // TODO: add loading code here
150 // CTortoiseGitBlameDoc diagnostics
153 void CTortoiseGitBlameDoc::AssertValid() const
155 CDocument::AssertValid();
158 void CTortoiseGitBlameDoc::Dump(CDumpContext
& dc
) const
165 // CTortoiseGitBlameDoc commands