Fixed issue #2219: "add cherry picked from" is not applied when squashing/editing...
[TortoiseGit.git] / src / TortoiseGitBlame / OutputWnd.cpp
blob1a533dd8eab9aa604e8544d3dc4996b21c67c752
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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_DYNAMIC(COutputWnd, CDockablePane)
48 BEGIN_MESSAGE_MAP(COutputWnd, CDockablePane)
49 ON_WM_CREATE()
50 ON_WM_SIZE()
51 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOG, OnLvnItemchangedLoglist)
52 END_MESSAGE_MAP()
54 int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
56 if (CDockablePane::OnCreate(lpCreateStruct) == -1)
57 return -1;
59 TRACE(_T("%u\n"),LVN_ITEMCHANGED);
60 m_Font.CreateStockObject(DEFAULT_GUI_FONT);
62 CRect rectDummy;
63 rectDummy.SetRectEmpty();
65 // Create output panes:
66 const DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
68 if (!m_LogList.Create(dwStyle, rectDummy, this, IDC_LOG))
70 TRACE0("Failed to create output windows\n");
71 return -1; // fail to create
74 m_LogList.SetFont(&m_Font);
76 m_Gravatar.Create(_T(""), WS_CHILD | WS_VISIBLE, rectDummy, this);
77 bool bEnableGravatar = !!CRegDWORD(_T("Software\\TortoiseGit\\EnableGravatar"), FALSE);
78 m_Gravatar.EnableGravatar(bEnableGravatar);
79 if (bEnableGravatar)
80 m_Gravatar.Init();
82 CString strTabName;
83 BOOL bNameValid;
85 // Attach list windows to tab:
86 bNameValid = strTabName.LoadString(IDS_GIT_LOG_TAB);
87 ASSERT(bNameValid);
89 m_LogList.m_IsIDReplaceAction=TRUE;
90 m_LogList.DeleteAllItems();
91 m_LogList.m_ColumnRegKey=_T("Blame");
92 m_LogList.InsertGitColumn();
94 m_LogList.hideUnimplementedCommands();
96 this->SetWindowTextW(CString(MAKEINTRESOURCE(IDS_GIT_LOG_TAB)));
97 return 0;
100 void COutputWnd::OnSize(UINT nType, int cx, int cy)
102 CDockablePane::OnSize(nType, cx, cy);
104 // Tab control should cover the whole client area:
105 if (m_Gravatar.IsGravatarEnabled())
107 m_LogList.SetWindowPos(NULL, -1, -1, cx - 80, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
108 m_Gravatar.SetWindowPos(NULL, cx - 80, 0, 80, 80, SWP_NOACTIVATE | SWP_NOZORDER);
109 return;
111 m_LogList.SetWindowPos(NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
114 void COutputWnd::AdjustHorzScroll(CListBox& wndListBox)
116 CClientDC dc(this);
117 CFont* pOldFont = dc.SelectObject(&m_Font);
119 int cxExtentMax = 0;
121 for (int i = 0; i < wndListBox.GetCount(); ++i)
123 CString strItem;
124 wndListBox.GetText(i, strItem);
126 cxExtentMax = max(cxExtentMax, dc.GetTextExtent(strItem).cx);
129 wndListBox.SetHorizontalExtent(cxExtentMax);
130 dc.SelectObject(pOldFont);
133 int COutputWnd::LoadHistory(CString filename, CString revision, bool follow)
135 CTGitPath path;
136 path.SetFromGit(filename);
138 m_LogList.Clear();
139 m_LogList.ShowGraphColumn(!follow);
140 if (m_LogList.FillGitLog(&path, &revision, follow ? CGit::LOG_INFO_FOLLOW : 0))
141 return -1;
142 m_LogList.UpdateProjectProperties();
143 return 0;
146 int COutputWnd::LoadHistory(std::set<CGitHash>& hashes)
148 m_LogList.Clear();
149 m_LogList.ShowGraphColumn(false);
150 if (m_LogList.FillGitLog(hashes))
151 return -1;
152 m_LogList.UpdateProjectProperties();
153 return 0;
156 void COutputWnd::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
158 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
159 *pResult = 0;
161 //if (this->IsThreadRunning())
162 if (pNMLV->iItem >= 0)
164 if (pNMLV->iSubItem != 0)
165 return;
167 if (pNMLV->uNewState & LVIS_SELECTED)
169 CMainFrame *pMain=DYNAMIC_DOWNCAST(CMainFrame,AfxGetApp()->GetMainWnd());
170 POSITION pos=pMain->GetActiveDocument()->GetFirstViewPosition();
171 CTortoiseGitBlameView *pView=DYNAMIC_DOWNCAST(CTortoiseGitBlameView,pMain->GetActiveDocument()->GetNextView(pos));
172 pView->FocusOn(&this->m_LogList.m_logEntries.GetGitRevAt(pNMLV->iItem));
173 m_Gravatar.LoadGravatar(m_LogList.m_logEntries.GetGitRevAt(pNMLV->iItem).GetAuthorEmail());
177 /////////////////////////////////////////////////////////////////////////////
178 // COutputList1
180 COutputList::COutputList()
184 COutputList::~COutputList()
188 BEGIN_MESSAGE_MAP(COutputList, CListBox)
189 ON_WM_CONTEXTMENU()
190 ON_COMMAND(ID_VIEW_OUTPUTWND, OnViewOutput)
191 ON_WM_WINDOWPOSCHANGING()
192 END_MESSAGE_MAP()
193 /////////////////////////////////////////////////////////////////////////////
194 // COutputList message handlers
196 void COutputList::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
198 CMenu menu;
199 menu.LoadMenu(IDR_OUTPUT_POPUP);
201 CMenu* pSumMenu = menu.GetSubMenu(0);
203 if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
205 CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
207 if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
208 return;
210 ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
211 UpdateDialogControls(this, FALSE);
214 SetFocus();
217 void COutputList::OnViewOutput()
219 CDockablePane* pParentBar = DYNAMIC_DOWNCAST(CDockablePane, GetOwner());
220 CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
222 if (pMainFrame != NULL && pParentBar != NULL)
224 pMainFrame->SetFocus();
225 pMainFrame->ShowPane(pParentBar, FALSE, FALSE, FALSE);
226 pMainFrame->RecalcLayout();