OSDN Git Service

RebaseDlg: Change Current Rebase and rebased commit color
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RebaseDlg.cpp
1 // RebaseDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "RebaseDlg.h"\r
7 #include "AppUtils.h"\r
8 \r
9 // CRebaseDlg dialog\r
10 \r
11 IMPLEMENT_DYNAMIC(CRebaseDlg, CResizableStandAloneDialog)\r
12 \r
13 CRebaseDlg::CRebaseDlg(CWnd* pParent /*=NULL*/)\r
14         : CResizableStandAloneDialog(CRebaseDlg::IDD, pParent)\r
15     , m_bPickAll(FALSE)\r
16     , m_bSquashAll(FALSE)\r
17     , m_bEditAll(FALSE)\r
18 {\r
19         m_RebaseStage=CHOOSE_BRANCH;\r
20         m_CurrentRebaseIndex=-1;\r
21 }\r
22 \r
23 CRebaseDlg::~CRebaseDlg()\r
24 {\r
25 }\r
26 \r
27 void CRebaseDlg::DoDataExchange(CDataExchange* pDX)\r
28 {\r
29     CDialog::DoDataExchange(pDX);\r
30     DDX_Control(pDX, IDC_REBASE_PROGRESS, m_ProgressBar);\r
31     DDX_Control(pDX, IDC_STATUS_STATIC, m_CtrlStatusText);\r
32     DDX_Check(pDX, IDC_PICK_ALL, m_bPickAll);\r
33     DDX_Check(pDX, IDC_SQUASH_ALL, m_bSquashAll);\r
34     DDX_Check(pDX, IDC_EDIT_ALL, m_bEditAll);\r
35         DDX_Control(pDX, IDC_REBASE_SPLIT, m_wndSplitter);\r
36         DDX_Control(pDX,IDC_COMMIT_LIST,m_CommitList);\r
37         DDX_Control(pDX,IDC_REBASE_COMBOXEX_BRANCH, this->m_BranchCtrl);\r
38         DDX_Control(pDX,IDC_REBASE_COMBOXEX_UPSTREAM,   this->m_UpstreamCtrl);\r
39 \r
40 }\r
41 \r
42 \r
43 BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog)\r
44     ON_BN_CLICKED(IDC_PICK_ALL, &CRebaseDlg::OnBnClickedPickAll)\r
45     ON_BN_CLICKED(IDC_SQUASH_ALL, &CRebaseDlg::OnBnClickedSquashAll)\r
46     ON_BN_CLICKED(IDC_EDIT_ALL, &CRebaseDlg::OnBnClickedEditAll)\r
47     ON_BN_CLICKED(IDC_REBASE_SPLIT, &CRebaseDlg::OnBnClickedRebaseSplit)\r
48         ON_BN_CLICKED(IDC_REBASE_CONTINUE,OnBnClickedContinue)\r
49         ON_WM_SIZE()\r
50         ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH,   &CRebaseDlg::OnCbnSelchangeBranch)\r
51         ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM, &CRebaseDlg::OnCbnSelchangeUpstream)\r
52 END_MESSAGE_MAP()\r
53 \r
54 void CRebaseDlg::AddRebaseAnchor()\r
55 {\r
56         AddAnchor(IDC_REBASE_TAB,TOP_LEFT,BOTTOM_RIGHT);\r
57         AddAnchor(IDC_COMMIT_LIST,TOP_LEFT, TOP_RIGHT);\r
58         AddAnchor(IDC_REBASE_SPLIT,TOP_LEFT, TOP_RIGHT);\r
59         AddAnchor(IDC_STATUS_STATIC, BOTTOM_LEFT,BOTTOM_RIGHT);\r
60         AddAnchor(IDC_REBASE_CONTINUE,BOTTOM_RIGHT);\r
61         AddAnchor(IDC_REBASE_ABORT, BOTTOM_RIGHT);\r
62         AddAnchor(IDC_REBASE_PROGRESS,BOTTOM_LEFT, BOTTOM_RIGHT);\r
63         AddAnchor(IDC_PICK_ALL,TOP_LEFT);\r
64         AddAnchor(IDC_SQUASH_ALL,TOP_LEFT);\r
65         AddAnchor(IDC_EDIT_ALL,TOP_LEFT);       \r
66         AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM,TOP_LEFT);\r
67         AddAnchor(IDC_REBASE_COMBOXEX_BRANCH,TOP_LEFT);\r
68         AddAnchor(IDC_REBASE_STATIC_UPSTREAM,TOP_LEFT);\r
69         AddAnchor(IDC_REBASE_STATIC_BRANCH,TOP_LEFT);\r
70         \r
71 }\r
72 \r
73 BOOL CRebaseDlg::OnInitDialog()\r
74 {\r
75         CResizableStandAloneDialog::OnInitDialog();\r
76 \r
77         CRect rectDummy;\r
78         //IDC_REBASE_DUMY_TAB\r
79         \r
80         GetClientRect(m_DlgOrigRect);\r
81         m_CommitList.GetClientRect(m_CommitListOrigRect);\r
82 \r
83         CWnd *pwnd=this->GetDlgItem(IDC_REBASE_DUMY_TAB);\r
84         pwnd->GetWindowRect(&rectDummy);\r
85 \r
86         rectDummy.top-=20;\r
87         rectDummy.bottom-=20;\r
88 \r
89         rectDummy.left-=5;\r
90         rectDummy.right-=5;\r
91         \r
92         if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_REBASE_TAB))\r
93         {\r
94                 TRACE0("Failed to create output tab window\n");\r
95                 return FALSE;      // fail to create\r
96         }\r
97         m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);\r
98         // Create output panes:\r
99         //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;\r
100         const DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
101 \r
102         if (! this->m_FileListCtrl.Create(dwStyle,rectDummy,&this->m_ctrlTabCtrl,0) )\r
103         {\r
104                 TRACE0("Failed to create output windows\n");\r
105                 return FALSE;      // fail to create\r
106         }\r
107 \r
108         if( ! this->m_LogMessageCtrl.Create(_T("Scintilla"),_T("source"),0,rectDummy,&m_ctrlTabCtrl,0,0) )\r
109         {\r
110                 TRACE0("Failed to create log message control");\r
111                 return FALSE;\r
112         }\r
113 \r
114         m_tooltips.Create(this);\r
115 \r
116         m_FileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS , _T("RebaseDlg"));\r
117 \r
118         m_ctrlTabCtrl.AddTab(&m_FileListCtrl,_T("Conflict File"));\r
119         m_ctrlTabCtrl.AddTab(&m_LogMessageCtrl,_T("Commit Message"),1);\r
120         AddRebaseAnchor();\r
121 \r
122 \r
123         EnableSaveRestore(_T("RebaseDlg"));\r
124 \r
125         DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));\r
126         RECT rcDlg, rcLogMsg, rcFileList;\r
127         GetClientRect(&rcDlg);\r
128         m_CommitList.GetWindowRect(&rcLogMsg);\r
129         ScreenToClient(&rcLogMsg);\r
130         this->m_ctrlTabCtrl.GetWindowRect(&rcFileList);\r
131         ScreenToClient(&rcFileList);\r
132         if (yPos)\r
133         {\r
134                 RECT rectSplitter;\r
135                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
136                 ScreenToClient(&rectSplitter);\r
137                 int delta = yPos - rectSplitter.top;\r
138                 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))\r
139                 {\r
140                         m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);\r
141                         DoSize(delta);\r
142                 }\r
143         }\r
144 \r
145         if( this->m_RebaseStage == CHOOSE_BRANCH)\r
146         {\r
147                 this->LoadBranchInfo();\r
148 \r
149         }else\r
150         {\r
151                 this->m_BranchCtrl.EnableWindow(FALSE);\r
152                 this->m_UpstreamCtrl.EnableWindow(FALSE);\r
153         }\r
154 \r
155         m_CommitList.m_IsIDReplaceAction = TRUE;\r
156         m_CommitList.m_IsOldFirst = TRUE;\r
157         m_CommitList.m_IsRebaseReplaceGraph = TRUE;\r
158 \r
159         m_CommitList.DeleteAllItems();\r
160         m_CommitList.InsertGitColumn();\r
161 \r
162         FetchLogList();\r
163         return TRUE;\r
164 }\r
165 // CRebaseDlg message handlers\r
166 \r
167 void CRebaseDlg::OnBnClickedPickAll()\r
168 {\r
169     // TODO: Add your control notification handler code here\r
170         this->UpdateData();\r
171         if(this->m_bPickAll)\r
172                 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_PICK);\r
173 \r
174         this->m_bEditAll=FALSE;\r
175         this->m_bSquashAll=FALSE;\r
176         this->UpdateData(FALSE);\r
177         \r
178 }\r
179 \r
180 void CRebaseDlg::OnBnClickedSquashAll()\r
181 {\r
182     // TODO: Add your control notification handler code here\r
183         this->UpdateData();\r
184         if(this->m_bSquashAll)\r
185                 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_SQUASH);\r
186 \r
187         this->m_bEditAll=FALSE;\r
188         this->m_bPickAll=FALSE;\r
189         this->UpdateData(FALSE);\r
190 \r
191 }\r
192 \r
193 void CRebaseDlg::OnBnClickedEditAll()\r
194 {\r
195     // TODO: Add your control notification handler code here\r
196         this->UpdateData();\r
197         if( this->m_bEditAll )\r
198                 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_EDIT);\r
199 \r
200         this->m_bPickAll=FALSE;\r
201         this->m_bSquashAll=FALSE;\r
202         this->UpdateData(FALSE);\r
203 \r
204 }\r
205 \r
206 void CRebaseDlg::SetAllRebaseAction(int action)\r
207 {\r
208         for(int i=0;i<this->m_CommitList.m_logEntries.size();i++)\r
209         {\r
210                 m_CommitList.m_logEntries[i].m_Action=action;\r
211         }\r
212         m_CommitList.Invalidate();\r
213 }\r
214 \r
215 void CRebaseDlg::OnBnClickedRebaseSplit()\r
216 {\r
217         this->UpdateData();\r
218     // TODO: Add your control notification handler code here\r
219 }\r
220 \r
221 LRESULT CRebaseDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)\r
222 {\r
223         switch (message) {\r
224         case WM_NOTIFY:\r
225                 if (wParam == IDC_REBASE_SPLIT)\r
226                 { \r
227                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
228                         DoSize(pHdr->delta);\r
229                 }\r
230                 break;\r
231         }\r
232 \r
233         return __super::DefWindowProc(message, wParam, lParam);\r
234 }\r
235 \r
236 void CRebaseDlg::DoSize(int delta)\r
237 {\r
238         \r
239         this->RemoveAllAnchors();\r
240 \r
241         CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST), delta, CW_TOPALIGN);\r
242         //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);\r
243         CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB), -delta, CW_BOTTOMALIGN);\r
244         //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);\r
245         CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL),0,delta);\r
246         CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL),0,delta);\r
247         CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL),0,delta);\r
248         \r
249         this->AddRebaseAnchor();\r
250         // adjust the minimum size of the dialog to prevent the resizing from\r
251         // moving the list control too far down.\r
252         CRect rcLogMsg;\r
253         m_CommitList.GetClientRect(rcLogMsg);\r
254         SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_CommitListOrigRect.Height()+rcLogMsg.Height()));\r
255 \r
256         SetSplitterRange();\r
257 //      m_CommitList.Invalidate();\r
258 \r
259 //      GetDlgItem(IDC_LOGMESSAGE)->Invalidate();\r
260 \r
261         this->m_ctrlTabCtrl.Invalidate();\r
262         this->m_CommitList.Invalidate();\r
263         this->m_FileListCtrl.Invalidate();\r
264         this->m_LogMessageCtrl.Invalidate();\r
265 \r
266 }\r
267 \r
268 void CRebaseDlg::SetSplitterRange()\r
269 {\r
270         if ((m_CommitList)&&(m_ctrlTabCtrl))\r
271         {\r
272                 CRect rcTop;\r
273                 m_CommitList.GetWindowRect(rcTop);\r
274                 ScreenToClient(rcTop);\r
275                 CRect rcMiddle;\r
276                 m_ctrlTabCtrl.GetWindowRect(rcMiddle);\r
277                 ScreenToClient(rcMiddle);\r
278                 if (rcMiddle.Height() && rcMiddle.Width())\r
279                         m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);\r
280         }\r
281 }\r
282 \r
283 void CRebaseDlg::OnSize(UINT nType,int cx, int cy)\r
284 {\r
285          // first, let the resizing take place\r
286     __super::OnSize(nType, cx, cy);\r
287 \r
288     //set range\r
289     SetSplitterRange();\r
290 }\r
291 \r
292 void CRebaseDlg::SaveSplitterPos()\r
293 {\r
294         if (!IsIconic())\r
295         {\r
296                 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));\r
297                 RECT rectSplitter;\r
298                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
299                 ScreenToClient(&rectSplitter);\r
300                 regPos = rectSplitter.top;\r
301         }\r
302 }\r
303 \r
304 void CRebaseDlg::LoadBranchInfo()\r
305 {\r
306         m_BranchCtrl.SetMaxHistoryItems(0x7FFFFFFF);\r
307         m_UpstreamCtrl.SetMaxHistoryItems(0x7FFFFFFF);\r
308 \r
309         STRING_VECTOR list;\r
310         list.clear();\r
311         int current;\r
312         g_Git.GetBranchList(list,&current,CGit::BRANCH_ALL);\r
313         m_BranchCtrl.AddString(list);\r
314         m_UpstreamCtrl.AddString(list);\r
315 \r
316         m_BranchCtrl.SetCurSel(current);\r
317 \r
318         AddBranchToolTips(&m_BranchCtrl);\r
319         AddBranchToolTips(&m_UpstreamCtrl);\r
320 \r
321 }\r
322 \r
323 void CRebaseDlg::OnCbnSelchangeBranch()\r
324 {\r
325         FetchLogList();\r
326 }\r
327 \r
328 void CRebaseDlg::OnCbnSelchangeUpstream()\r
329 {\r
330         FetchLogList();\r
331 }\r
332 \r
333 void CRebaseDlg::FetchLogList()\r
334 {\r
335         m_CommitList.Clear();\r
336         this->m_CommitList.FillGitLog(NULL,0,&m_UpstreamCtrl.GetString(),&m_BranchCtrl.GetString());\r
337         if( m_CommitList.GetItemCount() == 0 )\r
338                 m_CommitList.ShowText(_T("Nothing Rebase"));\r
339 \r
340         CString hash=g_Git.GetHash(m_UpstreamCtrl.GetString());\r
341         \r
342         if(m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash.size() >=0 )\r
343         {\r
344                 if(hash ==  m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash[0])\r
345                 {\r
346                         m_CommitList.Clear();\r
347                         m_CommitList.ShowText(_T("Nothing Rebase"));\r
348                 }\r
349         }\r
350         \r
351         m_tooltips.Pop();\r
352         AddBranchToolTips(&this->m_BranchCtrl);\r
353         AddBranchToolTips(&this->m_UpstreamCtrl);\r
354         \r
355         for(int i=0;i<m_CommitList.m_logEntries.size();i++)\r
356         {\r
357                 m_CommitList.m_logEntries[i].m_Action = CTGitPath::LOGACTIONS_REBASE_PICK;\r
358         }\r
359         \r
360         m_CommitList.Invalidate();\r
361 }\r
362 \r
363 void CRebaseDlg::AddBranchToolTips(CHistoryCombo *pBranch)\r
364 {\r
365         if(pBranch)\r
366         {\r
367                 CString text=pBranch->GetString();\r
368                 CString tooltip;\r
369                 BYTE_VECTOR data;\r
370                 g_Git.GetLog(data,text,NULL,1,0);\r
371                 GitRev rev;\r
372                 rev.ParserFromLog(data);\r
373                 tooltip.Format(_T("CommitHash:%s\nCommit by: %s  %s\n <b>%s</b> \n %s"),\r
374                         rev.m_CommitHash,\r
375                         rev.m_AuthorName,\r
376                         CAppUtils::FormatDateAndTime(rev.m_AuthorDate,DATE_LONGDATE),\r
377                         rev.m_Subject,\r
378                         rev.m_Body);\r
379 \r
380                 pBranch->DisableTooltip();\r
381                 this->m_tooltips.AddTool(pBranch->GetComboBoxCtrl(),tooltip);\r
382         }\r
383 }\r
384 \r
385 BOOL CRebaseDlg::PreTranslateMessage(MSG*pMsg)\r
386 {\r
387         m_tooltips.RelayEvent(pMsg);\r
388         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
389 }\r
390 \r
391 void CRebaseDlg::OnBnClickedContinue()\r
392 {\r
393         GitRev *prevRev,*curRev;\r
394         prevRev=curRev=NULL;\r
395         CRect rect;\r
396         if( m_CurrentRebaseIndex >= m_CommitList.m_arShownList.GetSize())\r
397                 return;\r
398 \r
399         if( m_CurrentRebaseIndex >= 0)\r
400         {\r
401                 prevRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
402         }\r
403         m_CurrentRebaseIndex++;\r
404         if(m_CurrentRebaseIndex<m_CommitList.m_arShownList.GetSize())\r
405         {\r
406                 curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
407 \r
408         }\r
409         if(prevRev)\r
410         {\r
411                 prevRev->m_Action &= ~ CTGitPath::LOGACTIONS_REBASE_CURRENT;\r
412                 prevRev->m_Action |= CTGitPath::LOGACTIONS_REBASE_DONE;\r
413                 m_CommitList.GetItemRect(m_CurrentRebaseIndex-1,&rect,LVIR_BOUNDS);\r
414                 m_CommitList.InvalidateRect(rect);\r
415 \r
416         }\r
417 \r
418         if(curRev)\r
419         {\r
420                 curRev->m_Action |= CTGitPath::LOGACTIONS_REBASE_CURRENT;\r
421                 m_CommitList.GetItemRect(m_CurrentRebaseIndex,&rect,LVIR_BOUNDS);\r
422                 m_CommitList.InvalidateRect(rect);\r
423         }\r
424 \r
425         \r
426 }