Use processdlg to format patch.
[TortoiseGit.git] / src / TortoiseGitBlame / OutputWnd.cpp
blob2dcbf832beb21fc8041bc3b7855e22b7cf2bb007
2 #include "stdafx.h"
4 #include "OutputWnd.h"
5 #include "Resource.h"
6 #include "MainFrm.h"
7 #include "TortoiseGitBlameDoc.h"
8 #include "TortoiseGitBlameView.h"
10 #ifdef _DEBUG
11 #define new DEBUG_NEW
12 #undef THIS_FILE
13 static char THIS_FILE[] = __FILE__;
14 #endif
16 /////////////////////////////////////////////////////////////////////////////
17 // COutputBar
19 COutputWnd::COutputWnd()
23 COutputWnd::~COutputWnd()
27 IMPLEMENT_DYNCREATE(CGitMFCTabCtrl, CMFCTabCtrl)
29 BEGIN_MESSAGE_MAP(CGitMFCTabCtrl, CMFCTabCtrl)
30 ON_NOTIFY(LVN_ITEMCHANGED, 0, OnLvnItemchangedLoglist)
31 END_MESSAGE_MAP()
33 void CGitMFCTabCtrl::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
35 COutputWnd *pWnd=DYNAMIC_DOWNCAST(COutputWnd,this->GetParent());
36 pWnd->OnLvnItemchangedLoglist(pNMHDR,pResult);
39 IMPLEMENT_DYNAMIC(COutputWnd, CDockablePane)
41 BEGIN_MESSAGE_MAP(COutputWnd, CDockablePane)
42 ON_WM_CREATE()
43 ON_WM_SIZE()
44 ON_NOTIFY(LVN_ITEMCHANGED, 0, OnLvnItemchangedLoglist)
45 END_MESSAGE_MAP()
47 int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
49 if (CDockablePane::OnCreate(lpCreateStruct) == -1)
50 return -1;
52 TRACE(_T("%u\n"),LVN_ITEMCHANGED);
53 m_Font.CreateStockObject(DEFAULT_GUI_FONT);
55 CRect rectDummy;
56 rectDummy.SetRectEmpty();
58 // Create tabs window:
59 if (!m_wndTabs.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, 0))
61 TRACE0("Failed to create output tab window\n");
62 return -1; // fail to create
65 // Create output panes:
66 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
67 const DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
69 if (! m_LogList.Create(dwStyle,rectDummy,&m_wndTabs,0) )
71 TRACE0("Failed to create output windows\n");
72 return -1; // fail to create
74 #if 0
75 if (!m_wndOutputBuild.Create(dwStyle, rectDummy, &m_wndTabs, 2) ||
76 !m_wndOutputDebug.Create(dwStyle, rectDummy, &m_wndTabs, 3) ||
77 !m_wndOutputFind.Create(dwStyle, rectDummy, &m_wndTabs, 4))
79 TRACE0("Failed to create output windows\n");
80 return -1; // fail to create
82 #endif
84 m_LogList.SetFont(&m_Font);
85 //m_wndOutputBuild.SetFont(&m_Font);
86 //m_wndOutputDebug.SetFont(&m_Font);
87 //m_wndOutputFind.SetFont(&m_Font);
89 CString strTabName;
90 BOOL bNameValid;
92 // Attach list windows to tab:
93 bNameValid = strTabName.LoadString(IDS_GIT_LOG_TAB);
94 ASSERT(bNameValid);
96 m_wndTabs.AddTab(&m_LogList, strTabName, (UINT)0);
98 m_LogList.m_IsIDReplaceAction=TRUE;
99 m_LogList.DeleteAllItems();
100 m_LogList.InsertGitColumn();
103 #if 0
104 bNameValid = strTabName.LoadString(IDS_DEBUG_TAB);
105 ASSERT(bNameValid);
106 m_wndTabs.AddTab(&m_wndOutputDebug, strTabName, (UINT)1);
107 bNameValid = strTabName.LoadString(IDS_FIND_TAB);
108 ASSERT(bNameValid);
109 m_wndTabs.AddTab(&m_wndOutputFind, strTabName, (UINT)2);
110 #endif;
112 // Fill output tabs with some dummy text (nothing magic here)
113 FillBuildWindow();
114 // FillDebugWindow();
115 // FillFindWindow();
117 this->SetWindowTextW(_T("Git Log"));
118 return 0;
121 void COutputWnd::OnSize(UINT nType, int cx, int cy)
123 CDockablePane::OnSize(nType, cx, cy);
125 // Tab control should cover the whole client area:
126 m_wndTabs.SetWindowPos (NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
129 void COutputWnd::AdjustHorzScroll(CListBox& wndListBox)
131 CClientDC dc(this);
132 CFont* pOldFont = dc.SelectObject(&m_Font);
134 int cxExtentMax = 0;
136 for (int i = 0; i < wndListBox.GetCount(); i ++)
138 CString strItem;
139 wndListBox.GetText(i, strItem);
141 cxExtentMax = max(cxExtentMax, dc.GetTextExtent(strItem).cx);
144 wndListBox.SetHorizontalExtent(cxExtentMax);
145 dc.SelectObject(pOldFont);
148 void COutputWnd::FillBuildWindow()
150 // m_wndOutputBuild.AddString(_T("Build output is being displayed here."));
151 // m_wndOutputBuild.AddString(_T("The output is being displayed in rows of a list view"));
152 // m_wndOutputBuild.AddString(_T("but you can change the way it is displayed as you wish..."));
155 void COutputWnd::FillDebugWindow()
157 // m_wndOutputDebug.AddString(_T("Debug output is being displayed here."));
158 // m_wndOutputDebug.AddString(_T("The output is being displayed in rows of a list view"));
159 // m_wndOutputDebug.AddString(_T("but you can change the way it is displayed as you wish..."));
162 void COutputWnd::FillFindWindow()
164 // m_wndOutputFind.AddString(_T("Find output is being displayed here."));
165 // m_wndOutputFind.AddString(_T("The output is being displayed in rows of a list view"));
166 // m_wndOutputFind.AddString(_T("but you can change the way it is displayed as you wish..."));
169 int COutputWnd::LoadHistory(CString filename)
171 m_LogList.ReloadHashMap();
172 CTGitPath path;
173 path.SetFromGit(filename);
175 m_LogList.Clear();
176 m_LogList.FillGitLog(&path,0/*CGit::LOG_INFO_FOLLOW*/);
178 return 0;
181 void COutputWnd::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
183 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
184 *pResult = 0;
186 //if (this->IsThreadRunning())
187 if (pNMLV->iItem >= 0)
189 if (pNMLV->iSubItem != 0)
190 return;
192 if (pNMLV->uNewState & LVIS_SELECTED)
194 CMainFrame *pMain=DYNAMIC_DOWNCAST(CMainFrame,AfxGetApp()->GetMainWnd());
195 POSITION pos=pMain->GetActiveDocument()->GetFirstViewPosition();
196 CTortoiseGitBlameView *pView=DYNAMIC_DOWNCAST(CTortoiseGitBlameView,pMain->GetActiveDocument()->GetNextView(pos));
197 pView->FocusOn(&this->m_LogList.m_logEntries[pNMLV->iItem]);
201 /////////////////////////////////////////////////////////////////////////////
202 // COutputList1
204 COutputList::COutputList()
208 COutputList::~COutputList()
212 BEGIN_MESSAGE_MAP(COutputList, CListBox)
213 ON_WM_CONTEXTMENU()
214 ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
215 ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
216 ON_COMMAND(ID_VIEW_OUTPUTWND, OnViewOutput)
217 ON_WM_WINDOWPOSCHANGING()
218 END_MESSAGE_MAP()
219 /////////////////////////////////////////////////////////////////////////////
220 // COutputList message handlers
222 void COutputList::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
224 CMenu menu;
225 menu.LoadMenu(IDR_OUTPUT_POPUP);
227 CMenu* pSumMenu = menu.GetSubMenu(0);
229 if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
231 CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
233 if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
234 return;
236 ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
237 UpdateDialogControls(this, FALSE);
240 SetFocus();
243 void COutputList::OnEditCopy()
245 MessageBox(_T("Copy output"));
248 void COutputList::OnEditClear()
250 MessageBox(_T("Clear output"));
253 void COutputList::OnViewOutput()
255 CDockablePane* pParentBar = DYNAMIC_DOWNCAST(CDockablePane, GetOwner());
256 CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
258 if (pMainFrame != NULL && pParentBar != NULL)
260 pMainFrame->SetFocus();
261 pMainFrame->ShowPane(pParentBar, FALSE, FALSE, FALSE);
262 pMainFrame->RecalcLayout();