Can run cleanup without using recycle bin and add dry run option
[TortoiseGit.git] / src / TortoiseProc / ImportPatchDlg.cpp
blobd6ce563a32f1d0ae977c36a8b2e54a90b674e137
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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.
19 // ImportPatchDlg.cpp : implementation file
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "ImportPatchDlg.h"
25 #include "git.h"
26 #include "MessageBox.h"
27 #include "AppUtils.h"
28 #include "SmartHandle.h"
30 // CImportPatchDlg dialog
32 IMPLEMENT_DYNAMIC(CImportPatchDlg, CResizableStandAloneDialog)
34 CImportPatchDlg::CImportPatchDlg(CWnd* pParent /*=NULL*/)
35 : CResizableStandAloneDialog(CImportPatchDlg::IDD, pParent)
37 m_cList.m_ContextMenuMask &=~ m_cList.GetMenuMask(CPatchListCtrl::MENU_APPLY);
39 m_CurrentItem =0;
41 m_bExitThread = false;
42 m_bThreadRunning =false;
44 m_b3Way = 1;
45 m_bIgnoreSpace = 1;
46 m_bAddSignedOffBy = FALSE;
47 m_bKeepCR = TRUE;
50 CImportPatchDlg::~CImportPatchDlg()
55 void CImportPatchDlg::DoDataExchange(CDataExchange* pDX)
57 CDialog::DoDataExchange(pDX);
58 DDX_Control(pDX, IDC_LIST_PATCH,m_cList);
59 DDX_Control(pDX, IDC_AM_SPLIT, m_wndSplitter);
60 DDX_Check(pDX, IDC_CHECK_3WAY, m_b3Way);
61 DDX_Check(pDX, IDC_CHECK_IGNORE_SPACE, m_bIgnoreSpace);
62 DDX_Check(pDX, IDC_SIGN_OFF, m_bAddSignedOffBy);
63 DDX_Check(pDX, IDC_KEEP_CR, m_bKeepCR);
66 void CImportPatchDlg::AddAmAnchor()
68 AddAnchor(IDC_AM_TAB,TOP_LEFT,BOTTOM_RIGHT);
69 AddAnchor(IDC_LIST_PATCH, TOP_LEFT, TOP_RIGHT);
70 AddAnchor(IDC_AM_SPLIT, TOP_LEFT, TOP_RIGHT);
71 AddAnchor(IDC_BUTTON_ADD, TOP_RIGHT);
72 AddAnchor(IDC_BUTTON_UP, TOP_RIGHT);
73 AddAnchor(IDC_BUTTON_DOWN, TOP_RIGHT);
74 AddAnchor(IDC_BUTTON_REMOVE, TOP_RIGHT);
76 AddAnchor(IDOK,BOTTOM_RIGHT);
77 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
78 AddAnchor(IDHELP, BOTTOM_RIGHT);
80 AddAnchor(IDC_AM_DUMY_TAB, TOP_LEFT, BOTTOM_RIGHT);
82 this->AddOthersToAnchor();
85 void CImportPatchDlg::SetSplitterRange()
87 if ((m_cList)&&(m_ctrlTabCtrl))
89 CRect rcTop;
90 m_cList.GetWindowRect(rcTop);
91 ScreenToClient(rcTop);
92 CRect rcMiddle;
93 m_ctrlTabCtrl.GetWindowRect(rcMiddle);
94 ScreenToClient(rcMiddle);
95 if (rcMiddle.Height() && rcMiddle.Width())
96 m_wndSplitter.SetRange(rcTop.top+160, rcMiddle.bottom-160);
100 BOOL CImportPatchDlg::OnInitDialog()
102 CResizableStandAloneDialog::OnInitDialog();
103 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
105 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
106 // do this, Explorer would be unable to send that message to our window if we
107 // were running elevated. It's OK to make the call all the time, since if we're
108 // not elevated, this is a no-op.
109 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
110 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
111 CAutoLibrary hUser = ::LoadLibrary(_T("user32.dll"));
112 if (hUser)
114 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
115 if (pfnChangeWindowMessageFilterEx)
117 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
120 m_pTaskbarList.Release();
121 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
123 CRect rectDummy;
125 GetClientRect(m_DlgOrigRect);
126 m_cList.GetClientRect(m_PatchListOrigRect);
128 CWnd *pwnd=this->GetDlgItem(IDC_AM_DUMY_TAB);
129 pwnd->GetWindowRect(&rectDummy);
130 this->ScreenToClient(rectDummy);
132 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_AM_TAB))
134 TRACE0("Failed to create output tab window\n");
135 return FALSE; // fail to create
137 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
138 // Create output panes:
139 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
140 DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
142 if( ! this->m_PatchCtrl.Create(_T("Scintilla"),_T("source"),0,rectDummy,&m_ctrlTabCtrl,0,0) )
144 TRACE0("Failed to create log message control");
145 return FALSE;
147 m_PatchCtrl.Init(0);
148 m_PatchCtrl.Call(SCI_SETREADONLY, TRUE);
149 m_PatchCtrl.SetUDiffStyle();
151 dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
153 if (!m_wndOutput.Create(_T("Scintilla"),_T("source"),0,rectDummy, &m_ctrlTabCtrl, 0,0) )
155 TRACE0("Failed to create output windows\n");
156 return -1; // fail to create
158 m_wndOutput.Init(0);
159 m_wndOutput.Call(SCI_SETREADONLY, TRUE);
161 m_tooltips.Create(this);
163 m_tooltips.AddTool(IDC_CHECK_3WAY,IDS_AM_3WAY_TT);
164 m_tooltips.AddTool(IDC_CHECK_IGNORE_SPACE,IDS_AM_IGNORE_SPACE_TT);
166 m_ctrlTabCtrl.AddTab(&m_PatchCtrl, CString(MAKEINTRESOURCE(IDS_PATCH)), 0);
167 m_ctrlTabCtrl.AddTab(&m_wndOutput, CString(MAKEINTRESOURCE(IDS_LOG)), 1);
169 AddAmAnchor();
170 AdjustControlSize(IDC_CHECK_3WAY);
171 AdjustControlSize(IDC_CHECK_IGNORE_SPACE);
172 AdjustControlSize(IDC_SIGN_OFF);
173 AdjustControlSize(IDC_KEEP_CR);
175 m_PathList.SortByPathname(true);
176 m_cList.SetExtendedStyle( m_cList.GetExtendedStyle()| LVS_EX_CHECKBOXES );
178 for(int i=0;i<m_PathList.GetCount();i++)
180 m_cList.InsertItem(0,m_PathList[i].GetWinPath());
181 m_cList.SetCheck(0,true);
184 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer"));
185 RECT rcDlg, rcLogMsg, rcFileList;
186 GetClientRect(&rcDlg);
187 m_cList.GetWindowRect(&rcLogMsg);
188 ScreenToClient(&rcLogMsg);
189 this->m_ctrlTabCtrl.GetWindowRect(&rcFileList);
190 ScreenToClient(&rcFileList);
191 if (yPos)
193 RECT rectSplitter;
194 m_wndSplitter.GetWindowRect(&rectSplitter);
195 ScreenToClient(&rectSplitter);
196 int delta = yPos - rectSplitter.top;
197 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
199 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
200 DoSize(delta);
204 CAppUtils::SetListCtrlBackgroundImage(m_cList.GetSafeHwnd(), IDI_IMPORTPATHCES_BKG);
206 CString sWindowTitle;
207 GetWindowText(sWindowTitle);
208 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
210 EnableSaveRestore(_T("ImportDlg"));
212 SetSplitterRange();
214 return TRUE;
217 BEGIN_MESSAGE_MAP(CImportPatchDlg, CResizableStandAloneDialog)
218 ON_LBN_SELCHANGE(IDC_LIST_PATCH, &CImportPatchDlg::OnLbnSelchangeListPatch)
219 ON_BN_CLICKED(IDC_BUTTON_ADD, &CImportPatchDlg::OnBnClickedButtonAdd)
220 ON_BN_CLICKED(IDC_BUTTON_UP, &CImportPatchDlg::OnBnClickedButtonUp)
221 ON_BN_CLICKED(IDC_BUTTON_DOWN, &CImportPatchDlg::OnBnClickedButtonDown)
222 ON_BN_CLICKED(IDC_BUTTON_REMOVE, &CImportPatchDlg::OnBnClickedButtonRemove)
223 ON_BN_CLICKED(IDOK, &CImportPatchDlg::OnBnClickedOk)
224 ON_WM_SIZE()
225 ON_BN_CLICKED(IDCANCEL, &CImportPatchDlg::OnBnClickedCancel)
226 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_PATCH, &CImportPatchDlg::OnHdnItemchangedListPatch)
227 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
228 END_MESSAGE_MAP()
231 // CImportPatchDlg message handlers
233 void CImportPatchDlg::OnLbnSelchangeListPatch()
235 if(m_cList.GetSelectedCount() == 0)
237 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(FALSE);
238 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(FALSE);
239 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(FALSE);
241 else
243 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(TRUE);
244 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(TRUE);
245 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(TRUE);
249 void CImportPatchDlg::OnBnClickedButtonAdd()
251 CFileDialog dlg(TRUE,NULL,
252 NULL,
253 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
254 CString(MAKEINTRESOURCE(IDS_PATCHFILEFILTER)));
255 dlg.m_ofn.nMaxFile = 65536;
256 auto_buffer<TCHAR> path(dlg.m_ofn.nMaxFile);
257 dlg.m_ofn.lpstrFile = path;
258 INT_PTR ret = dlg.DoModal();
259 SetCurrentDirectory(g_Git.m_CurrentDir);
260 if (ret == IDOK)
262 POSITION pos;
263 pos = dlg.GetStartPosition();
264 while (pos)
266 CString file = dlg.GetNextPathName(pos);
267 file.Trim();
268 if(!file.IsEmpty())
270 int index = m_cList.InsertItem(m_cList.GetItemCount(), file);
271 if (index >= 0)
272 m_cList.SetCheck(index, true);
278 void CImportPatchDlg::OnBnClickedButtonUp()
280 POSITION pos;
281 pos = m_cList.GetFirstSelectedItemPosition();
283 // do nothing if the first selected item is the first item in the list
284 if (m_cList.GetNextSelectedItem(pos) == 0)
285 return;
287 pos = m_cList.GetFirstSelectedItemPosition();
289 while (pos)
291 int index = m_cList.GetNextSelectedItem(pos);
292 if(index >= 1)
294 CString old = m_cList.GetItemText(index, 0);
295 BOOL oldState = m_cList.GetCheck(index);
296 m_cList.DeleteItem(index);
297 m_cList.InsertItem(index - 1, old);
298 m_cList.SetCheck(index - 1, oldState);
299 m_cList.SetItemState(index - 1, LVIS_SELECTED, LVIS_SELECTED);
300 m_cList.SetItemState(index, 0, LVIS_SELECTED);
306 void CImportPatchDlg::OnBnClickedButtonDown()
308 if (m_cList.GetSelectedCount() == 0)
309 return;
311 POSITION pos;
312 pos = m_cList.GetFirstSelectedItemPosition();
313 // use an array to store all selected item indexes; the user won't select too much items
314 int* indexes = NULL;
315 indexes = new int[m_cList.GetSelectedCount()];
316 int i = 0;
317 while(pos)
319 indexes[i++] = m_cList.GetNextSelectedItem(pos);
322 // don't move any item if the last selected item is the last item in the m_CommitList
323 // (that would change the order of the selected items)
324 if(indexes[m_cList.GetSelectedCount() - 1] < m_cList.GetItemCount() - 1)
326 // iterate over the indexes backwards in order to correctly move multiselected items
327 for (i = m_cList.GetSelectedCount() - 1; i >= 0; i--)
329 int index = indexes[i];
330 CString old = m_cList.GetItemText(index, 0);
331 BOOL oldState = m_cList.GetCheck(index);
332 m_cList.DeleteItem(index);
333 m_cList.InsertItem(index + 1, old);
334 m_cList.SetCheck(index + 1, oldState);
335 m_cList.SetItemState(index + 1, LVIS_SELECTED, LVIS_SELECTED);
336 m_cList.SetItemState(index, 0, LVIS_SELECTED);
339 delete [] indexes;
340 indexes = NULL;
343 void CImportPatchDlg::OnBnClickedButtonRemove()
345 POSITION pos;
346 pos = m_cList.GetFirstSelectedItemPosition();
347 while (pos)
349 int index = m_cList.GetNextSelectedItem(pos);
350 m_cList.DeleteItem(index);
351 pos = m_cList.GetFirstSelectedItemPosition();
355 UINT CImportPatchDlg::PatchThread()
357 CTGitPath path;
358 path.SetFromWin(g_Git.m_CurrentDir);
360 int i=0;
361 UpdateOkCancelText();
362 for(i=m_CurrentItem;i<m_cList.GetItemCount();i++)
364 if (m_pTaskbarList)
366 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
367 m_pTaskbarList->SetProgressValue(m_hWnd, i, m_cList.GetItemCount());
370 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLYING|m_cList.GetItemData(i));
372 CRect rect;
373 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
374 this->m_cList.InvalidateRect(rect);
376 if(m_bExitThread)
377 break;
379 if(m_cList.GetCheck(i))
381 CString cmd;
383 while(path.HasRebaseApply())
385 if (m_pTaskbarList)
386 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
388 int ret = CMessageBox::Show(NULL, IDS_PROC_APPLYPATCH_REBASEDIRFOUND,
389 IDS_APPNAME,
390 1, IDI_ERROR, IDS_ABORTBUTTON, IDS_SKIPBUTTON, IDS_RESOLVEDBUTTON);
392 switch(ret)
394 case 1:
395 cmd = _T("git.exe am --abort");
396 break;
397 case 2:
398 cmd = _T("git.exe am --skip");
399 i++;
400 break;
401 case 3:
402 cmd = _T("git.exe am --resolved");
403 break;
404 default:
405 cmd.Empty();
407 if(cmd.IsEmpty())
409 m_bExitThread = TRUE;
410 break;
413 this->AddLogString(cmd);
414 CString output;
415 if (g_Git.Run(cmd, &output, CP_UTF8))
417 this->AddLogString(output);
418 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL)));
420 else
422 this->AddLogString(CString(MAKEINTRESOURCE(IDS_DONE)));
426 if(m_bExitThread)
427 break;
429 cmd = _T("git.exe am ");
431 if(this->m_bAddSignedOffBy)
432 cmd += _T("--signoff ");
434 if(this->m_b3Way)
435 cmd += _T("--3way ");
437 if(this->m_bIgnoreSpace)
438 cmd += _T("--ignore-space-change ");
440 if(this->m_bKeepCR)
441 cmd += _T("--keep-cr ");
443 cmd += _T("\"");
444 cmd += m_cList.GetItemText(i,0);
445 cmd += _T("\"");
447 this->AddLogString(cmd);
448 CString output;
449 if (g_Git.Run(cmd, &output, CP_UTF8))
451 //keep STATUS_APPLYING to let user retry failed patch
452 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_FAIL|CPatchListCtrl::STATUS_APPLYING);
453 this->AddLogString(output);
454 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL)));
455 if (m_pTaskbarList)
456 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
457 break;
460 else
462 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SUCCESS);
463 this->AddLogString(CString(MAKEINTRESOURCE(IDS_SUCCESS)));
467 else
469 CString sMessage;
470 sMessage.Format(IDS_PROC_SKIPPATCH, m_cList.GetItemText(i,0));
471 AddLogString(sMessage);
472 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SKIP);
475 m_cList.SetItemData(m_CurrentItem, (~CPatchListCtrl::STATUS_APPLYING)&m_cList.GetItemData(i));
476 m_CurrentItem++;
478 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
479 this->m_cList.InvalidateRect(rect);
481 UpdateOkCancelText();
484 //in case am fail, need refresh finial item status
485 CRect rect;
486 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
487 this->m_cList.InvalidateRect(rect);
489 this->m_cList.GetItemRect(m_CurrentItem,&rect,LVIR_BOUNDS);
490 this->m_cList.InvalidateRect(rect);
492 if (m_pTaskbarList)
494 m_pTaskbarList->SetProgressValue(m_hWnd, m_CurrentItem, m_cList.GetItemCount());
495 if (m_bExitThread && m_CurrentItem != m_cList.GetItemCount())
496 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
497 else if (!m_bExitThread && m_CurrentItem == m_cList.GetItemCount())
498 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
501 EnableInputCtrl(true);
502 InterlockedExchange(&m_bThreadRunning, FALSE);
503 UpdateOkCancelText();
504 return 0;
507 void CImportPatchDlg::OnBnClickedOk()
509 m_PathList.Clear();
510 this->UpdateData();
512 SaveSplitterPos();
514 if(IsFinish())
516 this->OnOK();
517 return;
520 m_ctrlTabCtrl.SetActiveTab(1);
522 EnableInputCtrl(false);
523 InterlockedExchange(&m_bThreadRunning, TRUE);
524 InterlockedExchange(&this->m_bExitThread, FALSE);
525 if ( (m_LoadingThread=AfxBeginThread(ThreadEntry, this)) ==NULL)
527 InterlockedExchange(&m_bThreadRunning, FALSE);
528 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
533 void CImportPatchDlg::DoSize(int delta)
535 this->RemoveAllAnchors();
537 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LIST_PATCH), delta, CW_TOPALIGN);
538 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
539 CSplitterControl::ChangeHeight(GetDlgItem(IDC_AM_TAB), -delta, CW_BOTTOMALIGN);
540 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
541 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_3WAY), 0, delta);
542 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_IGNORE_SPACE), 0, delta);
543 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGN_OFF), 0, delta);
544 CSplitterControl::ChangePos(GetDlgItem(IDC_KEEP_CR), 0, delta);
546 this->AddAmAnchor();
547 // adjust the minimum size of the dialog to prevent the resizing from
548 // moving the list control too far down.
549 CRect rcLogMsg;
550 m_cList.GetClientRect(rcLogMsg);
551 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_PatchListOrigRect.Height()+rcLogMsg.Height()));
553 SetSplitterRange();
554 // m_CommitList.Invalidate();
556 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
558 this->m_ctrlTabCtrl.Invalidate();
561 void CImportPatchDlg::OnSize(UINT nType, int cx, int cy)
563 CResizableStandAloneDialog::OnSize(nType, cx, cy);
565 SetSplitterRange();
568 LRESULT CImportPatchDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
570 switch (message) {
571 case WM_NOTIFY:
572 if (wParam == IDC_AM_SPLIT)
574 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
575 DoSize(pHdr->delta);
577 break;
580 return CResizableStandAloneDialog::DefWindowProc(message, wParam, lParam);
583 void CImportPatchDlg::SaveSplitterPos()
585 if (!IsIconic())
587 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer"));
588 RECT rectSplitter;
589 m_wndSplitter.GetWindowRect(&rectSplitter);
590 ScreenToClient(&rectSplitter);
591 regPos = rectSplitter.top;
597 void CImportPatchDlg::EnableInputCtrl(BOOL b)
599 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(b);
600 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(b);
601 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(b);
602 this->GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(b);
603 this->GetDlgItem(IDOK)->EnableWindow(b);
606 void CImportPatchDlg::UpdateOkCancelText()
608 if (this->m_bThreadRunning && !IsFinish())
610 this->GetDlgItem(IDOK)->EnableWindow(FALSE);
611 this->GetDlgItem(IDCANCEL)->SetWindowText(CString(MAKEINTRESOURCE(IDS_ABORTBUTTON)));
613 else if (!IsFinish())
615 this->GetDlgItem(IDOK)->EnableWindow(TRUE);
617 else
619 this->GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
620 this->GetDlgItem(IDOK)->SetWindowText(CString(MAKEINTRESOURCE(IDS_OKBUTTON)));
623 void CImportPatchDlg::OnBnClickedCancel()
625 if(this->m_bThreadRunning)
627 InterlockedExchange(&m_bExitThread,TRUE);
629 else
631 CTGitPath path;
632 path.SetFromWin(g_Git.m_CurrentDir);
633 if(path.HasRebaseApply())
634 if(CMessageBox::Show(NULL, IDS_PROC_APPLYPATCH_GITAMACTIVE, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION) == IDYES)
636 CString output;
637 if (g_Git.Run(_T("git.exe am --abort"), &output, CP_UTF8))
638 MessageBox(output, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
640 OnCancel();
644 void CImportPatchDlg::AddLogString(CString str)
646 this->m_wndOutput.SendMessage(SCI_SETREADONLY, FALSE);
647 CStringA sTextA = m_wndOutput.StringForControl(str);//CUnicodeUtils::GetUTF8(str);
648 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)sTextA);
649 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n");
650 this->m_wndOutput.SendMessage(SCI_SETREADONLY, TRUE);
651 //this->m_wndOutput.SendMessage(SCI_LINESCROLL,0,0x7FFFFFFF);
653 BOOL CImportPatchDlg::PreTranslateMessage(MSG* pMsg)
655 if (pMsg->message == WM_KEYDOWN)
657 switch (pMsg->wParam)
660 /* Avoid TAB control destroy but dialog exist*/
661 case VK_ESCAPE:
662 case VK_CANCEL:
664 TCHAR buff[128];
665 ::GetClassName(pMsg->hwnd,buff,128);
667 if(_tcsnicmp(buff,_T("RichEdit20W"),128)==0 ||
668 _tcsnicmp(buff,_T("Scintilla"),128)==0 ||
669 _tcsnicmp(buff,_T("SysListView32"),128)==0||
670 ::GetParent(pMsg->hwnd) == this->m_ctrlTabCtrl.m_hWnd)
672 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
673 return TRUE;
678 m_tooltips.RelayEvent(pMsg);
679 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
682 void CImportPatchDlg::OnHdnItemchangedListPatch(NMHDR * /*pNMHDR*/, LRESULT *pResult)
684 *pResult = 0;
686 if(this->m_cList.GetSelectedCount() != 1)
688 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
689 m_PatchCtrl.SetText(CString());
690 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
692 else
694 CString text;
696 POSITION pos;
697 pos = m_cList.GetFirstSelectedItemPosition();
698 int selected = m_cList.GetNextSelectedItem(pos);
700 if(selected>=0&& selected< m_cList.GetItemCount())
702 CString str = m_cList.GetItemText(selected,0);
703 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
704 m_PatchCtrl.SetText(text);
705 m_PatchCtrl.LoadFromFile(str);
706 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
709 else
711 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
712 m_PatchCtrl.SetText(text);
713 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
718 LRESULT CImportPatchDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
720 m_pTaskbarList.Release();
721 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
722 return 0;