Add Command Line Argument to select blame version.
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameDoc.cpp
blob6811a8cb7e8e8138343dd7e0c05eb6644c12fafe
2 // TortoiseGitBlameDoc.cpp : implementation of the CTortoiseGitBlameDoc class
3 //
5 #include "stdafx.h"
6 #include "TortoiseGitBlame.h"
8 #include "TortoiseGitBlameDoc.h"
9 #include "GitAdminDir.h"
10 #include "MessageBox.h"
11 #include "Git.h"
12 #include "MainFrm.h"
13 #include "TGitPath.h"
14 #include "TortoiseGitBlameView.h"
15 #include "CmdLineParser.h"
17 #ifdef _DEBUG
18 #define new DEBUG_NEW
19 #endif
22 // CTortoiseGitBlameDoc
24 IMPLEMENT_DYNCREATE(CTortoiseGitBlameDoc, CDocument)
26 BEGIN_MESSAGE_MAP(CTortoiseGitBlameDoc, CDocument)
27 END_MESSAGE_MAP()
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())
45 return FALSE;
47 // TODO: add reinitialization code here
48 // (SDI documents will reuse this document)
50 return TRUE;
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"));
58 }else
60 m_Rev.Empty();
63 return OnOpenDocument(lpszPathName,m_Rev);
66 BOOL CTortoiseGitBlameDoc::OnOpenDocument(LPCTSTR lpszPathName,CString Rev)
68 if (!CDocument::OnOpenDocument(lpszPathName))
69 return FALSE;
71 m_CurrentFileName=lpszPathName;
72 m_Rev=Rev;
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);
79 return FALSE;
82 GitAdminDir admindir;
83 CString topdir;
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);
87 }else
89 m_IsGitFile=TRUE;
90 g_Git.m_CurrentDir=topdir;
91 GetMainFrame()->m_wndOutput.LoadHistory(lpszPathName);
93 CString cmd;
94 CTGitPath path;
95 path.SetFromWin(lpszPathName);
96 cmd.Format(_T("git.exe blame -s -l %s -- \"%s\""),Rev,path.GetGitPathString());
97 m_BlameData.Empty();
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());
104 if(pView == NULL)
106 CWnd* pWnd = GetMainFrame()->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
107 if (pWnd != NULL && pWnd->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameView)))
109 pView = (CTortoiseGitBlameView*)pWnd;
111 else
113 return FALSE;
116 pView->UpdateInfo();
119 return TRUE;
122 void CTortoiseGitBlameDoc::SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU)
124 CDocument::SetPathName(lpszPathName,bAddToMRU);
126 CString title;
127 if(m_Rev.IsEmpty())
128 title=CString(lpszPathName)+_T(":HEAD");
129 else
130 title=CString(lpszPathName)+_T(":")+m_Rev;
132 this->SetTitle(title);
135 // CTortoiseGitBlameDoc serialization
137 void CTortoiseGitBlameDoc::Serialize(CArchive& ar)
139 if (ar.IsStoring())
141 // TODO: add storing code here
143 else
145 // TODO: add loading code here
150 // CTortoiseGitBlameDoc diagnostics
152 #ifdef _DEBUG
153 void CTortoiseGitBlameDoc::AssertValid() const
155 CDocument::AssertValid();
158 void CTortoiseGitBlameDoc::Dump(CDumpContext& dc) const
160 CDocument::Dump(dc);
162 #endif //_DEBUG
165 // CTortoiseGitBlameDoc commands