OSDN Git Service

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