OSDN Git Service

Rebase: Add branch to list
[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 \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 }\r
21 \r
22 CRebaseDlg::~CRebaseDlg()\r
23 {\r
24 }\r
25 \r
26 void CRebaseDlg::DoDataExchange(CDataExchange* pDX)\r
27 {\r
28     CDialog::DoDataExchange(pDX);\r
29     DDX_Control(pDX, IDC_REBASE_PROGRESS, m_ProgressBar);\r
30     DDX_Control(pDX, IDC_STATUS_STATIC, m_CtrlStatusText);\r
31     DDX_Check(pDX, IDC_PICK_ALL, m_bPickAll);\r
32     DDX_Check(pDX, IDC_SQUASH_ALL, m_bSquashAll);\r
33     DDX_Check(pDX, IDC_EDIT_ALL, m_bEditAll);\r
34         DDX_Control(pDX, IDC_REBASE_SPLIT, m_wndSplitter);\r
35         DDX_Control(pDX,IDC_COMMIT_LIST,m_CommitList);\r
36         DDX_Control(pDX,IDC_REBASE_COMBOXEX_BRANCH, this->m_BranchCtrl);\r
37         DDX_Control(pDX,IDC_REBASE_COMBOXEX_UPSTREAM,   this->m_UpstreamCtrl);\r
38 \r
39 }\r
40 \r
41 \r
42 BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog)\r
43     ON_BN_CLICKED(IDC_PICK_ALL, &CRebaseDlg::OnBnClickedPickAll)\r
44     ON_BN_CLICKED(IDC_SQUASH_ALL, &CRebaseDlg::OnBnClickedSquashAll)\r
45     ON_BN_CLICKED(IDC_EDIT_ALL, &CRebaseDlg::OnBnClickedEditAll)\r
46     ON_BN_CLICKED(IDC_REBASE_SPLIT, &CRebaseDlg::OnBnClickedRebaseSplit)\r
47         ON_WM_SIZE()\r
48 END_MESSAGE_MAP()\r
49 \r
50 void CRebaseDlg::AddRebaseAnchor()\r
51 {\r
52         AddAnchor(IDC_REBASE_TAB,TOP_LEFT,BOTTOM_RIGHT);\r
53         AddAnchor(IDC_COMMIT_LIST,TOP_LEFT, TOP_RIGHT);\r
54         AddAnchor(IDC_REBASE_SPLIT,TOP_LEFT, TOP_RIGHT);\r
55         AddAnchor(IDC_STATUS_STATIC, BOTTOM_LEFT,BOTTOM_RIGHT);\r
56         AddAnchor(IDC_REBASE_CONTINUE,BOTTOM_RIGHT);\r
57         AddAnchor(IDC_REBASE_ABORT, BOTTOM_RIGHT);\r
58         AddAnchor(IDC_REBASE_PROGRESS,BOTTOM_LEFT, BOTTOM_RIGHT);\r
59         AddAnchor(IDC_PICK_ALL,TOP_LEFT);\r
60         AddAnchor(IDC_SQUASH_ALL,TOP_LEFT);\r
61         AddAnchor(IDC_EDIT_ALL,TOP_LEFT);       \r
62         AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM,TOP_LEFT);\r
63         AddAnchor(IDC_REBASE_COMBOXEX_BRANCH,TOP_LEFT);\r
64         AddAnchor(IDC_REBASE_STATIC_UPSTREAM,TOP_LEFT);\r
65         AddAnchor(IDC_REBASE_STATIC_BRANCH,TOP_LEFT);\r
66         \r
67 }\r
68 \r
69 BOOL CRebaseDlg::OnInitDialog()\r
70 {\r
71         CResizableStandAloneDialog::OnInitDialog();\r
72 \r
73         CRect rectDummy;\r
74         //IDC_REBASE_DUMY_TAB\r
75         \r
76         GetClientRect(m_DlgOrigRect);\r
77         m_CommitList.GetClientRect(m_CommitListOrigRect);\r
78 \r
79         CWnd *pwnd=this->GetDlgItem(IDC_REBASE_DUMY_TAB);\r
80         pwnd->GetWindowRect(&rectDummy);\r
81 \r
82         rectDummy.top-=20;\r
83         rectDummy.bottom-=20;\r
84 \r
85         rectDummy.left-=5;\r
86         rectDummy.right-=5;\r
87         \r
88         if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_REBASE_TAB))\r
89         {\r
90                 TRACE0("Failed to create output tab window\n");\r
91                 return FALSE;      // fail to create\r
92         }\r
93         m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);\r
94         // Create output panes:\r
95         //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;\r
96         const DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
97 \r
98         if (! this->m_FileListCtrl.Create(dwStyle,rectDummy,&this->m_ctrlTabCtrl,0) )\r
99         {\r
100                 TRACE0("Failed to create output windows\n");\r
101                 return FALSE;      // fail to create\r
102         }\r
103 \r
104         if( ! this->m_LogMessageCtrl.Create(_T("Scintilla"),_T("source"),0,rectDummy,&m_ctrlTabCtrl,0,0) )\r
105         {\r
106                 TRACE0("Failed to create log message control");\r
107                 return FALSE;\r
108         }\r
109 \r
110         m_FileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS , _T("RebaseDlg"));\r
111 \r
112         m_ctrlTabCtrl.AddTab(&m_FileListCtrl,_T("Modified File"));\r
113         m_ctrlTabCtrl.AddTab(&m_LogMessageCtrl,_T("Log Message"),1);\r
114         AddRebaseAnchor();\r
115 \r
116 \r
117         EnableSaveRestore(_T("RebaseDlg"));\r
118 \r
119         DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));\r
120         RECT rcDlg, rcLogMsg, rcFileList;\r
121         GetClientRect(&rcDlg);\r
122         m_CommitList.GetWindowRect(&rcLogMsg);\r
123         ScreenToClient(&rcLogMsg);\r
124         this->m_ctrlTabCtrl.GetWindowRect(&rcFileList);\r
125         ScreenToClient(&rcFileList);\r
126         if (yPos)\r
127         {\r
128                 RECT rectSplitter;\r
129                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
130                 ScreenToClient(&rectSplitter);\r
131                 int delta = yPos - rectSplitter.top;\r
132                 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))\r
133                 {\r
134                         m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);\r
135                         DoSize(delta);\r
136                 }\r
137         }\r
138 \r
139         if( this->m_RebaseStage == CHOOSE_BRANCH)\r
140         {\r
141                 this->LoadBranchInfo();\r
142 \r
143         }else\r
144         {\r
145                 this->m_BranchCtrl.EnableWindow(FALSE);\r
146                 this->m_UpstreamCtrl.EnableWindow(FALSE);\r
147         }\r
148 \r
149         return TRUE;\r
150 }\r
151 // CRebaseDlg message handlers\r
152 \r
153 void CRebaseDlg::OnBnClickedPickAll()\r
154 {\r
155     // TODO: Add your control notification handler code here\r
156 }\r
157 \r
158 void CRebaseDlg::OnBnClickedSquashAll()\r
159 {\r
160     // TODO: Add your control notification handler code here\r
161 }\r
162 \r
163 void CRebaseDlg::OnBnClickedEditAll()\r
164 {\r
165     // TODO: Add your control notification handler code here\r
166 }\r
167 \r
168 void CRebaseDlg::OnBnClickedRebaseSplit()\r
169 {\r
170     // TODO: Add your control notification handler code here\r
171 }\r
172 \r
173 LRESULT CRebaseDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)\r
174 {\r
175         switch (message) {\r
176         case WM_NOTIFY:\r
177                 if (wParam == IDC_REBASE_SPLIT)\r
178                 { \r
179                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
180                         DoSize(pHdr->delta);\r
181                 }\r
182                 break;\r
183         }\r
184 \r
185         return __super::DefWindowProc(message, wParam, lParam);\r
186 }\r
187 \r
188 void CRebaseDlg::DoSize(int delta)\r
189 {\r
190         \r
191         this->RemoveAllAnchors();\r
192 \r
193         CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST), delta, CW_TOPALIGN);\r
194         //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);\r
195         CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB), -delta, CW_BOTTOMALIGN);\r
196         //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);\r
197         CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL),0,delta);\r
198         CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL),0,delta);\r
199         CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL),0,delta);\r
200         \r
201         this->AddRebaseAnchor();\r
202         // adjust the minimum size of the dialog to prevent the resizing from\r
203         // moving the list control too far down.\r
204         CRect rcLogMsg;\r
205         m_CommitList.GetClientRect(rcLogMsg);\r
206         SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_CommitListOrigRect.Height()+rcLogMsg.Height()));\r
207 \r
208         SetSplitterRange();\r
209 //      m_CommitList.Invalidate();\r
210 \r
211 //      GetDlgItem(IDC_LOGMESSAGE)->Invalidate();\r
212 \r
213         this->m_ctrlTabCtrl.Invalidate();\r
214         this->m_CommitList.Invalidate();\r
215         this->m_FileListCtrl.Invalidate();\r
216         this->m_LogMessageCtrl.Invalidate();\r
217 \r
218 }\r
219 \r
220 void CRebaseDlg::SetSplitterRange()\r
221 {\r
222         if ((m_CommitList)&&(m_ctrlTabCtrl))\r
223         {\r
224                 CRect rcTop;\r
225                 m_CommitList.GetWindowRect(rcTop);\r
226                 ScreenToClient(rcTop);\r
227                 CRect rcMiddle;\r
228                 m_ctrlTabCtrl.GetWindowRect(rcMiddle);\r
229                 ScreenToClient(rcMiddle);\r
230                 if (rcMiddle.Height() && rcMiddle.Width())\r
231                         m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);\r
232         }\r
233 }\r
234 \r
235 void CRebaseDlg::OnSize(UINT nType,int cx, int cy)\r
236 {\r
237          // first, let the resizing take place\r
238     __super::OnSize(nType, cx, cy);\r
239 \r
240     //set range\r
241     SetSplitterRange();\r
242 }\r
243 \r
244 void CRebaseDlg::SaveSplitterPos()\r
245 {\r
246         if (!IsIconic())\r
247         {\r
248                 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));\r
249                 RECT rectSplitter;\r
250                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
251                 ScreenToClient(&rectSplitter);\r
252                 regPos = rectSplitter.top;\r
253         }\r
254 }\r
255 \r
256 void CRebaseDlg::LoadBranchInfo()\r
257 {\r
258         m_BranchCtrl.SetMaxHistoryItems(0x7FFFFFFF);\r
259         m_UpstreamCtrl.SetMaxHistoryItems(0x7FFFFFFF);\r
260 \r
261         STRING_VECTOR list;\r
262         list.clear();\r
263         int current;\r
264         g_Git.GetBranchList(list,&current,CGit::BRANCH_ALL);\r
265         m_BranchCtrl.AddString(list);\r
266         m_UpstreamCtrl.AddString(list);\r
267 \r
268         m_BranchCtrl.SetCurSel(current);\r
269 \r
270 }