OSDN Git Service

High light lines when Click Log List at gitblame
[tortoisegit/TortoiseGitJp.git] / src / TortoiseGitBlame / OutputWnd.cpp
1 \r
2 #include "stdafx.h"\r
3 \r
4 #include "OutputWnd.h"\r
5 #include "Resource.h"\r
6 #include "MainFrm.h"\r
7 #include "TortoiseGitBlameDoc.h"\r
8 #include "TortoiseGitBlameView.h"\r
9 \r
10 #ifdef _DEBUG\r
11 #define new DEBUG_NEW\r
12 #undef THIS_FILE\r
13 static char THIS_FILE[] = __FILE__;\r
14 #endif\r
15 \r
16 /////////////////////////////////////////////////////////////////////////////\r
17 // COutputBar\r
18 \r
19 COutputWnd::COutputWnd()\r
20 {\r
21 }\r
22 \r
23 COutputWnd::~COutputWnd()\r
24 {\r
25 }\r
26 \r
27 IMPLEMENT_DYNCREATE(CGitMFCTabCtrl, CMFCTabCtrl)\r
28 \r
29 BEGIN_MESSAGE_MAP(CGitMFCTabCtrl, CMFCTabCtrl)\r
30         ON_NOTIFY(LVN_ITEMCHANGED, 0, OnLvnItemchangedLoglist)\r
31 END_MESSAGE_MAP()\r
32 \r
33 void CGitMFCTabCtrl::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
34 {\r
35         COutputWnd *pWnd=DYNAMIC_DOWNCAST(COutputWnd,this->GetParent());\r
36         pWnd->OnLvnItemchangedLoglist(pNMHDR,pResult);\r
37 }\r
38 \r
39 BEGIN_MESSAGE_MAP(COutputWnd, CDockablePane)\r
40         ON_WM_CREATE()\r
41         ON_WM_SIZE()\r
42         ON_NOTIFY(LVN_ITEMCHANGED, 0, OnLvnItemchangedLoglist)\r
43 END_MESSAGE_MAP()\r
44 \r
45 int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)\r
46 {\r
47         if (CDockablePane::OnCreate(lpCreateStruct) == -1)\r
48                 return -1;\r
49 \r
50         TRACE(_T("%u\n"),LVN_ITEMCHANGED);\r
51         m_Font.CreateStockObject(DEFAULT_GUI_FONT);\r
52 \r
53         CRect rectDummy;\r
54         rectDummy.SetRectEmpty();\r
55 \r
56         // Create tabs window:\r
57         if (!m_wndTabs.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, 0))\r
58         {\r
59                 TRACE0("Failed to create output tab window\n");\r
60                 return -1;      // fail to create\r
61         }\r
62 \r
63         // Create output panes:\r
64         //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;\r
65         const DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
66 \r
67         if (! m_LogList.Create(dwStyle,rectDummy,&m_wndTabs,0) )\r
68         {\r
69                 TRACE0("Failed to create output windows\n");\r
70                 return -1;      // fail to create\r
71         }\r
72 #if 0\r
73         if (!m_wndOutputBuild.Create(dwStyle, rectDummy, &m_wndTabs, 2) ||\r
74                 !m_wndOutputDebug.Create(dwStyle, rectDummy, &m_wndTabs, 3) ||\r
75                 !m_wndOutputFind.Create(dwStyle, rectDummy, &m_wndTabs, 4))\r
76         {\r
77                 TRACE0("Failed to create output windows\n");\r
78                 return -1;      // fail to create\r
79         }\r
80 #endif\r
81 \r
82         m_LogList.SetFont(&m_Font);\r
83         //m_wndOutputBuild.SetFont(&m_Font);\r
84         //m_wndOutputDebug.SetFont(&m_Font);\r
85         //m_wndOutputFind.SetFont(&m_Font);\r
86 \r
87         CString strTabName;\r
88         BOOL bNameValid;\r
89 \r
90         // Attach list windows to tab:\r
91         bNameValid = strTabName.LoadString(IDS_GIT_LOG_TAB);\r
92         ASSERT(bNameValid);\r
93 \r
94         m_wndTabs.AddTab(&m_LogList, strTabName, (UINT)0);\r
95 \r
96         m_LogList.m_IsIDReplaceAction=TRUE;\r
97         m_LogList.DeleteAllItems();\r
98         m_LogList.InsertGitColumn();\r
99 \r
100 \r
101 #if 0\r
102         bNameValid = strTabName.LoadString(IDS_DEBUG_TAB);\r
103         ASSERT(bNameValid);\r
104         m_wndTabs.AddTab(&m_wndOutputDebug, strTabName, (UINT)1);\r
105         bNameValid = strTabName.LoadString(IDS_FIND_TAB);\r
106         ASSERT(bNameValid);\r
107         m_wndTabs.AddTab(&m_wndOutputFind, strTabName, (UINT)2);\r
108 #endif;\r
109 \r
110         // Fill output tabs with some dummy text (nothing magic here)\r
111         FillBuildWindow();\r
112 //      FillDebugWindow();\r
113 //      FillFindWindow();\r
114 \r
115         this->SetWindowTextW(_T("Git Log"));\r
116         return 0;\r
117 }\r
118 \r
119 void COutputWnd::OnSize(UINT nType, int cx, int cy)\r
120 {\r
121         CDockablePane::OnSize(nType, cx, cy);\r
122 \r
123         // Tab control should cover the whole client area:\r
124         m_wndTabs.SetWindowPos (NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);\r
125 }\r
126 \r
127 void COutputWnd::AdjustHorzScroll(CListBox& wndListBox)\r
128 {\r
129         CClientDC dc(this);\r
130         CFont* pOldFont = dc.SelectObject(&m_Font);\r
131 \r
132         int cxExtentMax = 0;\r
133 \r
134         for (int i = 0; i < wndListBox.GetCount(); i ++)\r
135         {\r
136                 CString strItem;\r
137                 wndListBox.GetText(i, strItem);\r
138 \r
139                 cxExtentMax = max(cxExtentMax, dc.GetTextExtent(strItem).cx);\r
140         }\r
141 \r
142         wndListBox.SetHorizontalExtent(cxExtentMax);\r
143         dc.SelectObject(pOldFont);\r
144 }\r
145 \r
146 void COutputWnd::FillBuildWindow()\r
147 {\r
148 //      m_wndOutputBuild.AddString(_T("Build output is being displayed here."));\r
149 //      m_wndOutputBuild.AddString(_T("The output is being displayed in rows of a list view"));\r
150 //      m_wndOutputBuild.AddString(_T("but you can change the way it is displayed as you wish..."));\r
151 }\r
152 \r
153 void COutputWnd::FillDebugWindow()\r
154 {\r
155 //      m_wndOutputDebug.AddString(_T("Debug output is being displayed here."));\r
156 //      m_wndOutputDebug.AddString(_T("The output is being displayed in rows of a list view"));\r
157 //      m_wndOutputDebug.AddString(_T("but you can change the way it is displayed as you wish..."));\r
158 }\r
159 \r
160 void COutputWnd::FillFindWindow()\r
161 {\r
162 //      m_wndOutputFind.AddString(_T("Find output is being displayed here."));\r
163 //      m_wndOutputFind.AddString(_T("The output is being displayed in rows of a list view"));\r
164 //      m_wndOutputFind.AddString(_T("but you can change the way it is displayed as you wish..."));\r
165 }\r
166 \r
167 int COutputWnd::LoadHistory(CString filename)\r
168 {\r
169         m_LogList.ReloadHashMap();\r
170         CTGitPath path;\r
171         path.SetFromWin(filename);\r
172 \r
173         m_LogList.FillGitLog(&path,CGit::LOG_INFO_FULLHISTORY);\r
174 \r
175         return 0;\r
176 \r
177 }\r
178 void COutputWnd::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
179 {\r
180         LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
181         *pResult = 0;\r
182 \r
183         //if (this->IsThreadRunning())\r
184         if (pNMLV->iItem >= 0)\r
185         {\r
186                 if (pNMLV->iSubItem != 0)\r
187                         return;\r
188                 \r
189                 if (pNMLV->uNewState & LVIS_SELECTED)\r
190                 {\r
191                         CMainFrame *pMain=DYNAMIC_DOWNCAST(CMainFrame,AfxGetApp()->GetMainWnd());\r
192                         POSITION pos=pMain->GetActiveDocument()->GetFirstViewPosition();\r
193                         CTortoiseGitBlameView *pView=DYNAMIC_DOWNCAST(CTortoiseGitBlameView,pMain->GetActiveDocument()->GetNextView(pos));\r
194                         pView->FocusOn(&this->m_LogList.m_logEntries[pNMLV->iItem]);\r
195                 }\r
196         }\r
197 }\r
198 /////////////////////////////////////////////////////////////////////////////\r
199 // COutputList1\r
200 \r
201 COutputList::COutputList()\r
202 {\r
203 }\r
204 \r
205 COutputList::~COutputList()\r
206 {\r
207 }\r
208 \r
209 BEGIN_MESSAGE_MAP(COutputList, CListBox)\r
210         ON_WM_CONTEXTMENU()\r
211         ON_COMMAND(ID_EDIT_COPY, OnEditCopy)\r
212         ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)\r
213         ON_COMMAND(ID_VIEW_OUTPUTWND, OnViewOutput)\r
214         ON_WM_WINDOWPOSCHANGING()\r
215 END_MESSAGE_MAP()\r
216 /////////////////////////////////////////////////////////////////////////////\r
217 // COutputList message handlers\r
218 \r
219 void COutputList::OnContextMenu(CWnd* /*pWnd*/, CPoint point)\r
220 {\r
221         CMenu menu;\r
222         menu.LoadMenu(IDR_OUTPUT_POPUP);\r
223 \r
224         CMenu* pSumMenu = menu.GetSubMenu(0);\r
225 \r
226         if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))\r
227         {\r
228                 CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;\r
229 \r
230                 if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))\r
231                         return;\r
232 \r
233                 ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);\r
234                 UpdateDialogControls(this, FALSE);\r
235         }\r
236 \r
237         SetFocus();\r
238 }\r
239 \r
240 void COutputList::OnEditCopy()\r
241 {\r
242         MessageBox(_T("Copy output"));\r
243 }\r
244 \r
245 void COutputList::OnEditClear()\r
246 {\r
247         MessageBox(_T("Clear output"));\r
248 }\r
249 \r
250 void COutputList::OnViewOutput()\r
251 {\r
252         CDockablePane* pParentBar = DYNAMIC_DOWNCAST(CDockablePane, GetOwner());\r
253         CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());\r
254 \r
255         if (pMainFrame != NULL && pParentBar != NULL)\r
256         {\r
257                 pMainFrame->SetFocus();\r
258                 pMainFrame->ShowPane(pParentBar, FALSE, FALSE, FALSE);\r
259                 pMainFrame->RecalcLayout();\r
260 \r
261         }\r
262 }\r
263 \r