OSDN Git Service

GitBlame Use command Line argument to open file
[tortoisegit/TortoiseGitJp.git] / src / TortoiseGitBlame / OutputWnd.cpp
1 \r
2 #include "stdafx.h"\r
3 \r
4 #include "OutputWnd.h"\r
5 #include "Resource.h"\r
6 #include "MainFrm.h"\r
7 #include "TortoiseGitBlameDoc.h"\r
8 #include "TortoiseGitBlameView.h"\r
9 \r
10 #ifdef _DEBUG\r
11 #define new DEBUG_NEW\r
12 #undef THIS_FILE\r
13 static char THIS_FILE[] = __FILE__;\r
14 #endif\r
15 \r
16 /////////////////////////////////////////////////////////////////////////////\r
17 // COutputBar\r
18 \r
19 COutputWnd::COutputWnd()\r
20 {\r
21 }\r
22 \r
23 COutputWnd::~COutputWnd()\r
24 {\r
25 }\r
26 \r
27 IMPLEMENT_DYNCREATE(CGitMFCTabCtrl, CMFCTabCtrl)\r
28 \r
29 BEGIN_MESSAGE_MAP(CGitMFCTabCtrl, CMFCTabCtrl)\r
30         ON_NOTIFY(LVN_ITEMCHANGED, 0, OnLvnItemchangedLoglist)\r
31 END_MESSAGE_MAP()\r
32 \r
33 void CGitMFCTabCtrl::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
34 {\r
35         COutputWnd *pWnd=DYNAMIC_DOWNCAST(COutputWnd,this->GetParent());\r
36         pWnd->OnLvnItemchangedLoglist(pNMHDR,pResult);\r
37 }\r
38 \r
39 BEGIN_MESSAGE_MAP(COutputWnd, CDockablePane)\r
40         ON_WM_CREATE()\r
41         ON_WM_SIZE()\r
42         ON_NOTIFY(LVN_ITEMCHANGED, 0, OnLvnItemchangedLoglist)\r
43 END_MESSAGE_MAP()\r
44 \r
45 int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)\r
46 {\r
47         if (CDockablePane::OnCreate(lpCreateStruct) == -1)\r
48                 return -1;\r
49 \r
50         TRACE(_T("%u\n"),LVN_ITEMCHANGED);\r
51         m_Font.CreateStockObject(DEFAULT_GUI_FONT);\r
52 \r
53         CRect rectDummy;\r
54         rectDummy.SetRectEmpty();\r
55 \r
56         // Create tabs window:\r
57         if (!m_wndTabs.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, 0))\r
58         {\r
59                 TRACE0("Failed to create output tab window\n");\r
60                 return -1;      // fail to create\r
61         }\r
62 \r
63         // Create output panes:\r
64         //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;\r
65         const DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
66 \r
67         if (! m_LogList.Create(dwStyle,rectDummy,&m_wndTabs,0) )\r
68         {\r
69                 TRACE0("Failed to create output windows\n");\r
70                 return -1;      // fail to create\r
71         }\r
72 #if 0\r
73         if (!m_wndOutputBuild.Create(dwStyle, rectDummy, &m_wndTabs, 2) ||\r
74                 !m_wndOutputDebug.Create(dwStyle, rectDummy, &m_wndTabs, 3) ||\r
75                 !m_wndOutputFind.Create(dwStyle, rectDummy, &m_wndTabs, 4))\r
76         {\r
77                 TRACE0("Failed to create output windows\n");\r
78                 return -1;      // fail to create\r
79         }\r
80 #endif\r
81 \r
82         m_LogList.SetFont(&m_Font);\r
83         //m_wndOutputBuild.SetFont(&m_Font);\r
84         //m_wndOutputDebug.SetFont(&m_Font);\r
85         //m_wndOutputFind.SetFont(&m_Font);\r
86 \r
87         CString strTabName;\r
88         BOOL bNameValid;\r
89 \r
90         // Attach list windows to tab:\r
91         bNameValid = strTabName.LoadString(IDS_GIT_LOG_TAB);\r
92         ASSERT(bNameValid);\r
93 \r
94         m_wndTabs.AddTab(&m_LogList, strTabName, (UINT)0);\r
95 \r
96         m_LogList.m_IsIDReplaceAction=TRUE;\r
97         m_LogList.DeleteAllItems();\r
98         m_LogList.InsertGitColumn();\r
99 \r
100 \r
101 #if 0\r
102         bNameValid = strTabName.LoadString(IDS_DEBUG_TAB);\r
103         ASSERT(bNameValid);\r
104         m_wndTabs.AddTab(&m_wndOutputDebug, strTabName, (UINT)1);\r
105         bNameValid = strTabName.LoadString(IDS_FIND_TAB);\r
106         ASSERT(bNameValid);\r
107         m_wndTabs.AddTab(&m_wndOutputFind, strTabName, (UINT)2);\r
108 #endif;\r
109 \r
110         // Fill output tabs with some dummy text (nothing magic here)\r
111         FillBuildWindow();\r
112 //      FillDebugWindow();\r
113 //      FillFindWindow();\r
114 \r
115         this->SetWindowTextW(_T("Git Log"));\r
116         return 0;\r
117 }\r
118 \r
119 void COutputWnd::OnSize(UINT nType, int cx, int cy)\r
120 {\r
121         CDockablePane::OnSize(nType, cx, cy);\r
122 \r
123         // Tab control should cover the whole client area:\r
124         m_wndTabs.SetWindowPos (NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);\r
125 }\r
126 \r
127 void COutputWnd::AdjustHorzScroll(CListBox& wndListBox)\r
128 {\r
129         CClientDC dc(this);\r
130         CFont* pOldFont = dc.SelectObject(&m_Font);\r
131 \r
132         int cxExtentMax = 0;\r
133 \r
134         for (int i = 0; i < wndListBox.GetCount(); i ++)\r
135         {\r
136                 CString strItem;\r
137                 wndListBox.GetText(i, strItem);\r
138 \r
139                 cxExtentMax = max(cxExtentMax, dc.GetTextExtent(strItem).cx);\r
140         }\r
141 \r
142         wndListBox.SetHorizontalExtent(cxExtentMax);\r
143         dc.SelectObject(pOldFont);\r
144 }\r
145 \r
146 void COutputWnd::FillBuildWindow()\r
147 {\r
148 //      m_wndOutputBuild.AddString(_T("Build output is being displayed here."));\r
149 //      m_wndOutputBuild.AddString(_T("The output is being displayed in rows of a list view"));\r
150 //      m_wndOutputBuild.AddString(_T("but you can change the way it is displayed as you wish..."));\r
151 }\r
152 \r
153 void COutputWnd::FillDebugWindow()\r
154 {\r
155 //      m_wndOutputDebug.AddString(_T("Debug output is being displayed here."));\r
156 //      m_wndOutputDebug.AddString(_T("The output is being displayed in rows of a list view"));\r
157 //      m_wndOutputDebug.AddString(_T("but you can change the way it is displayed as you wish..."));\r
158 }\r
159 \r
160 void COutputWnd::FillFindWindow()\r
161 {\r
162 //      m_wndOutputFind.AddString(_T("Find output is being displayed here."));\r
163 //      m_wndOutputFind.AddString(_T("The output is being displayed in rows of a list view"));\r
164 //      m_wndOutputFind.AddString(_T("but you can change the way it is displayed as you wish..."));\r
165 }\r
166 \r
167 int COutputWnd::LoadHistory(CString filename)\r
168 {\r
169         m_LogList.ReloadHashMap();\r
170         CTGitPath path;\r
171         path.SetFromWin(filename);\r
172         \r
173         m_LogList.Clear();\r
174         m_LogList.FillGitLog(&path,0/*CGit::LOG_INFO_FULLHISTORY*/);\r
175 \r
176         return 0;\r
177 \r
178 }\r
179 void COutputWnd::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
180 {\r
181         LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
182         *pResult = 0;\r
183 \r
184         //if (this->IsThreadRunning())\r
185         if (pNMLV->iItem >= 0)\r
186         {\r
187                 if (pNMLV->iSubItem != 0)\r
188                         return;\r
189                 \r
190                 if (pNMLV->uNewState & LVIS_SELECTED)\r
191                 {\r
192                         CMainFrame *pMain=DYNAMIC_DOWNCAST(CMainFrame,AfxGetApp()->GetMainWnd());\r
193                         POSITION pos=pMain->GetActiveDocument()->GetFirstViewPosition();\r
194                         CTortoiseGitBlameView *pView=DYNAMIC_DOWNCAST(CTortoiseGitBlameView,pMain->GetActiveDocument()->GetNextView(pos));\r
195                         pView->FocusOn(&this->m_LogList.m_logEntries[pNMLV->iItem]);\r
196                 }\r
197         }\r
198 }\r
199 /////////////////////////////////////////////////////////////////////////////\r
200 // COutputList1\r
201 \r
202 COutputList::COutputList()\r
203 {\r
204 }\r
205 \r
206 COutputList::~COutputList()\r
207 {\r
208 }\r
209 \r
210 BEGIN_MESSAGE_MAP(COutputList, CListBox)\r
211         ON_WM_CONTEXTMENU()\r
212         ON_COMMAND(ID_EDIT_COPY, OnEditCopy)\r
213         ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)\r
214         ON_COMMAND(ID_VIEW_OUTPUTWND, OnViewOutput)\r
215         ON_WM_WINDOWPOSCHANGING()\r
216 END_MESSAGE_MAP()\r
217 /////////////////////////////////////////////////////////////////////////////\r
218 // COutputList message handlers\r
219 \r
220 void COutputList::OnContextMenu(CWnd* /*pWnd*/, CPoint point)\r
221 {\r
222         CMenu menu;\r
223         menu.LoadMenu(IDR_OUTPUT_POPUP);\r
224 \r
225         CMenu* pSumMenu = menu.GetSubMenu(0);\r
226 \r
227         if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))\r
228         {\r
229                 CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;\r
230 \r
231                 if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))\r
232                         return;\r
233 \r
234                 ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);\r
235                 UpdateDialogControls(this, FALSE);\r
236         }\r
237 \r
238         SetFocus();\r
239 }\r
240 \r
241 void COutputList::OnEditCopy()\r
242 {\r
243         MessageBox(_T("Copy output"));\r
244 }\r
245 \r
246 void COutputList::OnEditClear()\r
247 {\r
248         MessageBox(_T("Clear output"));\r
249 }\r
250 \r
251 void COutputList::OnViewOutput()\r
252 {\r
253         CDockablePane* pParentBar = DYNAMIC_DOWNCAST(CDockablePane, GetOwner());\r
254         CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());\r
255 \r
256         if (pMainFrame != NULL && pParentBar != NULL)\r
257         {\r
258                 pMainFrame->SetFocus();\r
259                 pMainFrame->ShowPane(pParentBar, FALSE, FALSE, FALSE);\r
260                 pMainFrame->RecalcLayout();\r
261 \r
262         }\r
263 }\r
264 \r