1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2016, 2018 - 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_DYNAMIC(COutputWnd
, CDockablePane
)
48 BEGIN_MESSAGE_MAP(COutputWnd
, CDockablePane
)
51 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_LOG
, OnLvnItemchangedLoglist
)
54 int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct
)
56 if (CDockablePane::OnCreate(lpCreateStruct
) == -1)
60 rectDummy
.SetRectEmpty();
62 // Create output panes:
63 const DWORD dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
65 if (!m_LogList
.Create(dwStyle
, rectDummy
, this, IDC_LOG
))
67 TRACE0("Failed to create output windows\n");
68 return -1; // fail to create
71 // for some unknown reason, the SetExtendedStyle in OnCreate/PreSubclassWindow is not working here
74 m_Gravatar
.Create(L
"", WS_CHILD
| WS_VISIBLE
, rectDummy
, this);
75 bool bEnableGravatar
= !!CRegDWORD(L
"Software\\TortoiseGit\\EnableGravatar", FALSE
);
76 m_Gravatar
.EnableGravatar(bEnableGravatar
);
83 // Attach list windows to tab:
84 bNameValid
= strTabName
.LoadString(IDS_GIT_LOG_TAB
);
87 m_LogList
.m_IsIDReplaceAction
=TRUE
;
88 m_LogList
.DeleteAllItems();
89 m_LogList
.m_ColumnRegKey
= L
"Blame";
90 m_LogList
.InsertGitColumn();
92 m_LogList
.hideUnimplementedCommands();
94 this->SetWindowTextW(CString(MAKEINTRESOURCE(IDS_GIT_LOG_TAB
)));
98 void COutputWnd::OnSize(UINT nType
, int cx
, int cy
)
100 CDockablePane::OnSize(nType
, cx
, cy
);
102 // Tab control should cover the whole client area:
103 if (m_Gravatar
.IsGravatarEnabled())
105 m_LogList
.SetWindowPos(nullptr, -1, -1, cx
- 80, cy
, SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
106 m_Gravatar
.SetWindowPos(nullptr, cx
- 80, 0, 80, 80, SWP_NOACTIVATE
| SWP_NOZORDER
);
109 m_LogList
.SetWindowPos(nullptr, -1, -1, cx
, cy
, SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
112 int COutputWnd::LoadHistory(CString filename
, CString revision
, bool follow
)
115 path
.SetFromGit(filename
);
118 m_LogList
.ShowGraphColumn(!follow
);
119 if (m_LogList
.FillGitLog(&path
, &revision
, follow
? CGit::LOG_INFO_FOLLOW
: 0))
121 m_LogList
.UpdateProjectProperties();
125 int COutputWnd::LoadHistory(std::unordered_set
<CGitHash
>& hashes
)
128 m_LogList
.ShowGraphColumn(false);
129 if (m_LogList
.FillGitLog(hashes
))
131 m_LogList
.UpdateProjectProperties();
135 void COutputWnd::OnLvnItemchangedLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
137 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
140 //if (this->IsThreadRunning())
141 if (pNMLV
->iItem
>= 0)
143 if (pNMLV
->iSubItem
!= 0)
146 if (pNMLV
->uNewState
& LVIS_SELECTED
)
148 CMainFrame
*pMain
=DYNAMIC_DOWNCAST(CMainFrame
,AfxGetApp()->GetMainWnd());
149 POSITION pos
=pMain
->GetActiveDocument()->GetFirstViewPosition();
150 CTortoiseGitBlameView
*pView
=DYNAMIC_DOWNCAST(CTortoiseGitBlameView
,pMain
->GetActiveDocument()->GetNextView(pos
));
151 pView
->FocusOn(&this->m_LogList
.m_logEntries
.GetGitRevAt(pNMLV
->iItem
));
152 m_Gravatar
.LoadGravatar(m_LogList
.m_logEntries
.GetGitRevAt(pNMLV
->iItem
).GetAuthorEmail());
156 /////////////////////////////////////////////////////////////////////////////
159 COutputList::COutputList()
163 COutputList::~COutputList()
167 BEGIN_MESSAGE_MAP(COutputList
, CListBox
)
169 ON_COMMAND(ID_VIEW_OUTPUTWND
, OnViewOutput
)
170 ON_WM_WINDOWPOSCHANGING()
172 /////////////////////////////////////////////////////////////////////////////
173 // COutputList message handlers
175 void COutputList::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
178 menu
.LoadMenu(IDR_OUTPUT_POPUP
);
180 CMenu
* pSumMenu
= menu
.GetSubMenu(0);
182 if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx
)))
184 CMFCPopupMenu
* pPopupMenu
= new CMFCPopupMenu
;
186 if (!pPopupMenu
->Create(this, point
.x
, point
.y
, (HMENU
)pSumMenu
->m_hMenu
, FALSE
, TRUE
))
189 ((CMDIFrameWndEx
*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu
);
190 UpdateDialogControls(this, FALSE
);
196 void COutputList::OnViewOutput()
198 CDockablePane
* pParentBar
= DYNAMIC_DOWNCAST(CDockablePane
, GetOwner());
199 CMDIFrameWndEx
* pMainFrame
= DYNAMIC_DOWNCAST(CMDIFrameWndEx
, GetTopLevelFrame());
201 if (pMainFrame
&& pParentBar
)
203 pMainFrame
->SetFocus();
204 pMainFrame
->ShowPane(pParentBar
, FALSE
, FALSE
, FALSE
);
205 pMainFrame
->RecalcLayout();