Fixed issue #1220: ext/CrashServer/CommonLibs/Zlib/Zlib.vcproj immediate dir Win32...
[TortoiseGit.git] / src / TortoiseGitBlame / OutputWnd.cpp
blob9c600be5c1032a4b8f628c81fa20582546a03bcc
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "stdafx.h"
23 #include "OutputWnd.h"
24 #include "Resource.h"
25 #include "MainFrm.h"
26 #include "TortoiseGitBlameDoc.h"
27 #include "TortoiseGitBlameView.h"
29 #ifdef _DEBUG
30 #define new DEBUG_NEW
31 #undef THIS_FILE
32 static char THIS_FILE[] = __FILE__;
33 #endif
35 /////////////////////////////////////////////////////////////////////////////
36 // COutputBar
38 COutputWnd::COutputWnd()
42 COutputWnd::~COutputWnd()
46 IMPLEMENT_DYNCREATE(CGitMFCTabCtrl, CMFCTabCtrl)
48 BEGIN_MESSAGE_MAP(CGitMFCTabCtrl, CMFCTabCtrl)
49 ON_NOTIFY(LVN_ITEMCHANGED, 0, OnLvnItemchangedLoglist)
50 END_MESSAGE_MAP()
52 void CGitMFCTabCtrl::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
54 COutputWnd *pWnd=DYNAMIC_DOWNCAST(COutputWnd,this->GetParent());
55 pWnd->OnLvnItemchangedLoglist(pNMHDR,pResult);
58 IMPLEMENT_DYNAMIC(COutputWnd, CDockablePane)
60 BEGIN_MESSAGE_MAP(COutputWnd, CDockablePane)
61 ON_WM_CREATE()
62 ON_WM_SIZE()
63 ON_NOTIFY(LVN_ITEMCHANGED, 0, OnLvnItemchangedLoglist)
64 END_MESSAGE_MAP()
66 int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
68 if (CDockablePane::OnCreate(lpCreateStruct) == -1)
69 return -1;
71 TRACE(_T("%u\n"),LVN_ITEMCHANGED);
72 m_Font.CreateStockObject(DEFAULT_GUI_FONT);
74 CRect rectDummy;
75 rectDummy.SetRectEmpty();
77 // Create tabs window:
78 if (!m_wndTabs.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, 0))
80 TRACE0("Failed to create output tab window\n");
81 return -1; // fail to create
84 // Create output panes:
85 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
86 const DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
88 if (! m_LogList.Create(dwStyle,rectDummy,&m_wndTabs,0) )
90 TRACE0("Failed to create output windows\n");
91 return -1; // fail to create
93 #if 0
94 if (!m_wndOutputBuild.Create(dwStyle, rectDummy, &m_wndTabs, 2) ||
95 !m_wndOutputDebug.Create(dwStyle, rectDummy, &m_wndTabs, 3) ||
96 !m_wndOutputFind.Create(dwStyle, rectDummy, &m_wndTabs, 4))
98 TRACE0("Failed to create output windows\n");
99 return -1; // fail to create
101 #endif
103 m_LogList.SetFont(&m_Font);
104 //m_wndOutputBuild.SetFont(&m_Font);
105 //m_wndOutputDebug.SetFont(&m_Font);
106 //m_wndOutputFind.SetFont(&m_Font);
108 CString strTabName;
109 BOOL bNameValid;
111 // Attach list windows to tab:
112 bNameValid = strTabName.LoadString(IDS_GIT_LOG_TAB);
113 ASSERT(bNameValid);
115 m_wndTabs.AddTab(&m_LogList, strTabName, (UINT)0);
117 m_LogList.m_IsIDReplaceAction=TRUE;
118 m_LogList.DeleteAllItems();
119 m_LogList.m_ColumnRegKey=_T("Blame");
120 m_LogList.InsertGitColumn();
122 m_LogList.hideUnimplementedCommands();
124 #if 0
125 bNameValid = strTabName.LoadString(IDS_DEBUG_TAB);
126 ASSERT(bNameValid);
127 m_wndTabs.AddTab(&m_wndOutputDebug, strTabName, (UINT)1);
128 bNameValid = strTabName.LoadString(IDS_FIND_TAB);
129 ASSERT(bNameValid);
130 m_wndTabs.AddTab(&m_wndOutputFind, strTabName, (UINT)2);
131 #endif;
133 // Fill output tabs with some dummy text (nothing magic here)
134 FillBuildWindow();
135 // FillDebugWindow();
136 // FillFindWindow();
138 this->SetWindowTextW(CString(MAKEINTRESOURCE(IDS_GIT_LOG_TAB)));
139 return 0;
142 void COutputWnd::OnSize(UINT nType, int cx, int cy)
144 CDockablePane::OnSize(nType, cx, cy);
146 // Tab control should cover the whole client area:
147 m_wndTabs.SetWindowPos (NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
150 void COutputWnd::AdjustHorzScroll(CListBox& wndListBox)
152 CClientDC dc(this);
153 CFont* pOldFont = dc.SelectObject(&m_Font);
155 int cxExtentMax = 0;
157 for (int i = 0; i < wndListBox.GetCount(); i ++)
159 CString strItem;
160 wndListBox.GetText(i, strItem);
162 cxExtentMax = max(cxExtentMax, dc.GetTextExtent(strItem).cx);
165 wndListBox.SetHorizontalExtent(cxExtentMax);
166 dc.SelectObject(pOldFont);
169 void COutputWnd::FillBuildWindow()
171 // m_wndOutputBuild.AddString(_T("Build output is being displayed here."));
172 // m_wndOutputBuild.AddString(_T("The output is being displayed in rows of a list view"));
173 // m_wndOutputBuild.AddString(_T("but you can change the way it is displayed as you wish..."));
176 void COutputWnd::FillDebugWindow()
178 // m_wndOutputDebug.AddString(_T("Debug output is being displayed here."));
179 // m_wndOutputDebug.AddString(_T("The output is being displayed in rows of a list view"));
180 // m_wndOutputDebug.AddString(_T("but you can change the way it is displayed as you wish..."));
183 void COutputWnd::FillFindWindow()
185 // m_wndOutputFind.AddString(_T("Find output is being displayed here."));
186 // m_wndOutputFind.AddString(_T("The output is being displayed in rows of a list view"));
187 // m_wndOutputFind.AddString(_T("but you can change the way it is displayed as you wish..."));
190 int COutputWnd::LoadHistory(CString filename, CString revision, bool follow)
192 m_LogList.ReloadHashMap();
193 CTGitPath path;
194 path.SetFromGit(filename);
196 m_LogList.Clear();
197 if (m_LogList.FillGitLog(&path, follow ? CGit::LOG_INFO_FOLLOW : 0, NULL, &revision))
198 return -1;
199 m_LogList.UpdateProjectProperties();
200 return 0;
203 void COutputWnd::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
205 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
206 *pResult = 0;
208 //if (this->IsThreadRunning())
209 if (pNMLV->iItem >= 0)
211 if (pNMLV->iSubItem != 0)
212 return;
214 if (pNMLV->uNewState & LVIS_SELECTED)
216 CMainFrame *pMain=DYNAMIC_DOWNCAST(CMainFrame,AfxGetApp()->GetMainWnd());
217 POSITION pos=pMain->GetActiveDocument()->GetFirstViewPosition();
218 CTortoiseGitBlameView *pView=DYNAMIC_DOWNCAST(CTortoiseGitBlameView,pMain->GetActiveDocument()->GetNextView(pos));
219 pView->FocusOn(&this->m_LogList.m_logEntries.GetGitRevAt(pNMLV->iItem));
223 /////////////////////////////////////////////////////////////////////////////
224 // COutputList1
226 COutputList::COutputList()
230 COutputList::~COutputList()
234 BEGIN_MESSAGE_MAP(COutputList, CListBox)
235 ON_WM_CONTEXTMENU()
236 ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
237 ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
238 ON_COMMAND(ID_VIEW_OUTPUTWND, OnViewOutput)
239 ON_WM_WINDOWPOSCHANGING()
240 END_MESSAGE_MAP()
241 /////////////////////////////////////////////////////////////////////////////
242 // COutputList message handlers
244 void COutputList::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
246 CMenu menu;
247 menu.LoadMenu(IDR_OUTPUT_POPUP);
249 CMenu* pSumMenu = menu.GetSubMenu(0);
251 if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
253 CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
255 if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
256 return;
258 ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
259 UpdateDialogControls(this, FALSE);
262 SetFocus();
265 void COutputList::OnEditCopy()
267 MessageBox(_T("Copy output"));
270 void COutputList::OnEditClear()
272 MessageBox(_T("Clear output"));
275 void COutputList::OnViewOutput()
277 CDockablePane* pParentBar = DYNAMIC_DOWNCAST(CDockablePane, GetOwner());
278 CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
280 if (pMainFrame != NULL && pParentBar != NULL)
282 pMainFrame->SetFocus();
283 pMainFrame->ShowPane(pParentBar, FALSE, FALSE, FALSE);
284 pMainFrame->RecalcLayout();