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.
23 #include "OutputWnd.h"
26 #include "TortoiseGitBlameDoc.h"
27 #include "TortoiseGitBlameView.h"
32 static char THIS_FILE
[] = __FILE__
;
35 /////////////////////////////////////////////////////////////////////////////
38 COutputWnd::COutputWnd()
42 COutputWnd::~COutputWnd()
46 IMPLEMENT_DYNCREATE(CGitMFCTabCtrl
, CMFCTabCtrl
)
48 BEGIN_MESSAGE_MAP(CGitMFCTabCtrl
, CMFCTabCtrl
)
49 ON_NOTIFY(LVN_ITEMCHANGED
, 0, OnLvnItemchangedLoglist
)
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
)
63 ON_NOTIFY(LVN_ITEMCHANGED
, 0, OnLvnItemchangedLoglist
)
66 int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct
)
68 if (CDockablePane::OnCreate(lpCreateStruct
) == -1)
71 TRACE(_T("%u\n"),LVN_ITEMCHANGED
);
72 m_Font
.CreateStockObject(DEFAULT_GUI_FONT
);
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
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
87 if (! m_LogList
.Create(dwStyle
,rectDummy
,&m_wndTabs
,0) )
89 TRACE0("Failed to create output windows\n");
90 return -1; // fail to create
93 m_LogList
.SetFont(&m_Font
);
98 // Attach list windows to tab:
99 bNameValid
= strTabName
.LoadString(IDS_GIT_LOG_TAB
);
102 m_wndTabs
.AddTab(&m_LogList
, strTabName
, (UINT
)0);
104 m_LogList
.m_IsIDReplaceAction
=TRUE
;
105 m_LogList
.DeleteAllItems();
106 m_LogList
.m_ColumnRegKey
=_T("Blame");
107 m_LogList
.InsertGitColumn();
109 m_LogList
.hideUnimplementedCommands();
111 this->SetWindowTextW(CString(MAKEINTRESOURCE(IDS_GIT_LOG_TAB
)));
115 void COutputWnd::OnSize(UINT nType
, int cx
, int cy
)
117 CDockablePane::OnSize(nType
, cx
, cy
);
119 // Tab control should cover the whole client area:
120 m_wndTabs
.SetWindowPos (NULL
, -1, -1, cx
, cy
, SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
123 void COutputWnd::AdjustHorzScroll(CListBox
& wndListBox
)
126 CFont
* pOldFont
= dc
.SelectObject(&m_Font
);
130 for (int i
= 0; i
< wndListBox
.GetCount(); i
++)
133 wndListBox
.GetText(i
, strItem
);
135 cxExtentMax
= max(cxExtentMax
, dc
.GetTextExtent(strItem
).cx
);
138 wndListBox
.SetHorizontalExtent(cxExtentMax
);
139 dc
.SelectObject(pOldFont
);
142 int COutputWnd::LoadHistory(CString filename
, CString revision
, bool follow
)
145 path
.SetFromGit(filename
);
148 if (m_LogList
.FillGitLog(&path
, follow
? CGit::LOG_INFO_FOLLOW
: 0, NULL
, &revision
))
150 m_LogList
.UpdateProjectProperties();
154 void COutputWnd::OnLvnItemchangedLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
156 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
159 //if (this->IsThreadRunning())
160 if (pNMLV
->iItem
>= 0)
162 if (pNMLV
->iSubItem
!= 0)
165 if (pNMLV
->uNewState
& LVIS_SELECTED
)
167 CMainFrame
*pMain
=DYNAMIC_DOWNCAST(CMainFrame
,AfxGetApp()->GetMainWnd());
168 POSITION pos
=pMain
->GetActiveDocument()->GetFirstViewPosition();
169 CTortoiseGitBlameView
*pView
=DYNAMIC_DOWNCAST(CTortoiseGitBlameView
,pMain
->GetActiveDocument()->GetNextView(pos
));
170 pView
->FocusOn(&this->m_LogList
.m_logEntries
.GetGitRevAt(pNMLV
->iItem
));
174 /////////////////////////////////////////////////////////////////////////////
177 COutputList::COutputList()
181 COutputList::~COutputList()
185 BEGIN_MESSAGE_MAP(COutputList
, CListBox
)
187 ON_COMMAND(ID_VIEW_OUTPUTWND
, OnViewOutput
)
188 ON_WM_WINDOWPOSCHANGING()
190 /////////////////////////////////////////////////////////////////////////////
191 // COutputList message handlers
193 void COutputList::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
196 menu
.LoadMenu(IDR_OUTPUT_POPUP
);
198 CMenu
* pSumMenu
= menu
.GetSubMenu(0);
200 if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx
)))
202 CMFCPopupMenu
* pPopupMenu
= new CMFCPopupMenu
;
204 if (!pPopupMenu
->Create(this, point
.x
, point
.y
, (HMENU
)pSumMenu
->m_hMenu
, FALSE
, TRUE
))
207 ((CMDIFrameWndEx
*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu
);
208 UpdateDialogControls(this, FALSE
);
214 void COutputList::OnViewOutput()
216 CDockablePane
* pParentBar
= DYNAMIC_DOWNCAST(CDockablePane
, GetOwner());
217 CMDIFrameWndEx
* pMainFrame
= DYNAMIC_DOWNCAST(CMDIFrameWndEx
, GetTopLevelFrame());
219 if (pMainFrame
!= NULL
&& pParentBar
!= NULL
)
221 pMainFrame
->SetFocus();
222 pMainFrame
->ShowPane(pParentBar
, FALSE
, FALSE
, FALSE
);
223 pMainFrame
->RecalcLayout();