16cbd642276e90b5003bc93af6d79aa4a48766ff
[TortoiseGit.git] / src / TortoiseProc / ImportPatchDlg.cpp
blob16cbd642276e90b5003bc93af6d79aa4a48766ff
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 = AtlLoadSystemLibraryUsingFullPath(_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 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
122 m_pTaskbarList = nullptr;
124 CRect rectDummy;
126 GetClientRect(m_DlgOrigRect);
127 m_cList.GetClientRect(m_PatchListOrigRect);
129 CWnd *pwnd=this->GetDlgItem(IDC_AM_DUMY_TAB);
130 pwnd->GetWindowRect(&rectDummy);
131 this->ScreenToClient(rectDummy);
133 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_AM_TAB))
135 TRACE0("Failed to create output tab window\n");
136 return FALSE; // fail to create
138 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
139 // Create output panes:
140 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
141 DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
143 if( ! this->m_PatchCtrl.Create(_T("Scintilla"),_T("source"),0,rectDummy,&m_ctrlTabCtrl,0,0) )
145 TRACE0("Failed to create log message control");
146 return FALSE;
148 m_PatchCtrl.Init(0);
149 m_PatchCtrl.Call(SCI_SETREADONLY, TRUE);
150 m_PatchCtrl.SetUDiffStyle();
152 dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
154 if (!m_wndOutput.Create(_T("Scintilla"),_T("source"),0,rectDummy, &m_ctrlTabCtrl, 0,0) )
156 TRACE0("Failed to create output windows\n");
157 return -1; // fail to create
159 m_wndOutput.Init(0);
160 m_wndOutput.Call(SCI_SETREADONLY, TRUE);
162 m_tooltips.Create(this);
164 m_tooltips.AddTool(IDC_CHECK_3WAY,IDS_AM_3WAY_TT);
165 m_tooltips.AddTool(IDC_CHECK_IGNORE_SPACE,IDS_AM_IGNORE_SPACE_TT);
167 m_ctrlTabCtrl.AddTab(&m_PatchCtrl, CString(MAKEINTRESOURCE(IDS_PATCH)), 0);
168 m_ctrlTabCtrl.AddTab(&m_wndOutput, CString(MAKEINTRESOURCE(IDS_LOG)), 1);
170 AddAmAnchor();
171 AdjustControlSize(IDC_CHECK_3WAY);
172 AdjustControlSize(IDC_CHECK_IGNORE_SPACE);
173 AdjustControlSize(IDC_SIGN_OFF);
174 AdjustControlSize(IDC_KEEP_CR);
176 m_PathList.SortByPathname(true);
177 m_cList.SetExtendedStyle( m_cList.GetExtendedStyle()| LVS_EX_CHECKBOXES );
179 for(int i=0;i<m_PathList.GetCount();i++)
181 m_cList.InsertItem(0,m_PathList[i].GetWinPath());
182 m_cList.SetCheck(0,true);
185 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer"));
186 RECT rcDlg, rcLogMsg, rcFileList;
187 GetClientRect(&rcDlg);
188 m_cList.GetWindowRect(&rcLogMsg);
189 ScreenToClient(&rcLogMsg);
190 this->m_ctrlTabCtrl.GetWindowRect(&rcFileList);
191 ScreenToClient(&rcFileList);
192 if (yPos)
194 RECT rectSplitter;
195 m_wndSplitter.GetWindowRect(&rectSplitter);
196 ScreenToClient(&rectSplitter);
197 int delta = yPos - rectSplitter.top;
198 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
200 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
201 DoSize(delta);
205 CAppUtils::SetListCtrlBackgroundImage(m_cList.GetSafeHwnd(), IDI_IMPORTPATHCES_BKG);
207 CString sWindowTitle;
208 GetWindowText(sWindowTitle);
209 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
211 EnableSaveRestore(_T("ImportDlg"));
213 SetSplitterRange();
215 return TRUE;
218 BEGIN_MESSAGE_MAP(CImportPatchDlg, CResizableStandAloneDialog)
219 ON_LBN_SELCHANGE(IDC_LIST_PATCH, &CImportPatchDlg::OnLbnSelchangeListPatch)
220 ON_BN_CLICKED(IDC_BUTTON_ADD, &CImportPatchDlg::OnBnClickedButtonAdd)
221 ON_BN_CLICKED(IDC_BUTTON_UP, &CImportPatchDlg::OnBnClickedButtonUp)
222 ON_BN_CLICKED(IDC_BUTTON_DOWN, &CImportPatchDlg::OnBnClickedButtonDown)
223 ON_BN_CLICKED(IDC_BUTTON_REMOVE, &CImportPatchDlg::OnBnClickedButtonRemove)
224 ON_BN_CLICKED(IDOK, &CImportPatchDlg::OnBnClickedOk)
225 ON_WM_SIZE()
226 ON_BN_CLICKED(IDCANCEL, &CImportPatchDlg::OnBnClickedCancel)
227 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_PATCH, &CImportPatchDlg::OnHdnItemchangedListPatch)
228 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
229 END_MESSAGE_MAP()
232 // CImportPatchDlg message handlers
234 void CImportPatchDlg::OnLbnSelchangeListPatch()
236 if(m_cList.GetSelectedCount() == 0)
238 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(FALSE);
239 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(FALSE);
240 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(FALSE);
242 else
244 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(TRUE);
245 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(TRUE);
246 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(TRUE);
250 void CImportPatchDlg::OnBnClickedButtonAdd()
252 CFileDialog dlg(TRUE,NULL,
253 NULL,
254 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
255 CString(MAKEINTRESOURCE(IDS_PATCHFILEFILTER)));
256 dlg.m_ofn.nMaxFile = 65536;
257 std::unique_ptr<TCHAR[]> path(new TCHAR[dlg.m_ofn.nMaxFile]);
258 dlg.m_ofn.lpstrFile = path.get();
259 INT_PTR ret = dlg.DoModal();
260 SetCurrentDirectory(g_Git.m_CurrentDir);
261 if (ret == IDOK)
263 POSITION pos;
264 pos = dlg.GetStartPosition();
265 while (pos)
267 CString file = dlg.GetNextPathName(pos);
268 file.Trim();
269 if(!file.IsEmpty())
271 int index = m_cList.InsertItem(m_cList.GetItemCount(), file);
272 if (index >= 0)
273 m_cList.SetCheck(index, true);
279 void CImportPatchDlg::OnBnClickedButtonUp()
281 POSITION pos;
282 pos = m_cList.GetFirstSelectedItemPosition();
284 // do nothing if the first selected item is the first item in the list
285 if (m_cList.GetNextSelectedItem(pos) == 0)
286 return;
288 pos = m_cList.GetFirstSelectedItemPosition();
290 while (pos)
292 int index = m_cList.GetNextSelectedItem(pos);
293 if(index >= 1)
295 CString old = m_cList.GetItemText(index, 0);
296 BOOL oldState = m_cList.GetCheck(index);
297 m_cList.DeleteItem(index);
298 m_cList.InsertItem(index - 1, old);
299 m_cList.SetCheck(index - 1, oldState);
300 m_cList.SetItemState(index - 1, LVIS_SELECTED, LVIS_SELECTED);
301 m_cList.SetItemState(index, 0, LVIS_SELECTED);
307 void CImportPatchDlg::OnBnClickedButtonDown()
309 if (m_cList.GetSelectedCount() == 0)
310 return;
312 POSITION pos;
313 pos = m_cList.GetFirstSelectedItemPosition();
314 // use an array to store all selected item indexes; the user won't select too much items
315 int* indexes = NULL;
316 indexes = new int[m_cList.GetSelectedCount()];
317 int i = 0;
318 while(pos)
320 indexes[i++] = m_cList.GetNextSelectedItem(pos);
323 // don't move any item if the last selected item is the last item in the m_CommitList
324 // (that would change the order of the selected items)
325 if(indexes[m_cList.GetSelectedCount() - 1] < m_cList.GetItemCount() - 1)
327 // iterate over the indexes backwards in order to correctly move multiselected items
328 for (i = m_cList.GetSelectedCount() - 1; i >= 0; i--)
330 int index = indexes[i];
331 CString old = m_cList.GetItemText(index, 0);
332 BOOL oldState = m_cList.GetCheck(index);
333 m_cList.DeleteItem(index);
334 m_cList.InsertItem(index + 1, old);
335 m_cList.SetCheck(index + 1, oldState);
336 m_cList.SetItemState(index + 1, LVIS_SELECTED, LVIS_SELECTED);
337 m_cList.SetItemState(index, 0, LVIS_SELECTED);
340 delete [] indexes;
341 indexes = NULL;
344 void CImportPatchDlg::OnBnClickedButtonRemove()
346 POSITION pos;
347 pos = m_cList.GetFirstSelectedItemPosition();
348 while (pos)
350 int index = m_cList.GetNextSelectedItem(pos);
351 m_cList.DeleteItem(index);
352 pos = m_cList.GetFirstSelectedItemPosition();
356 UINT CImportPatchDlg::PatchThread()
358 CTGitPath path;
359 path.SetFromWin(g_Git.m_CurrentDir);
361 int i=0;
362 UpdateOkCancelText();
363 for(i=m_CurrentItem;i<m_cList.GetItemCount();i++)
365 if (m_pTaskbarList)
367 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
368 m_pTaskbarList->SetProgressValue(m_hWnd, i, m_cList.GetItemCount());
371 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLYING|m_cList.GetItemData(i));
373 CRect rect;
374 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
375 this->m_cList.InvalidateRect(rect);
377 if(m_bExitThread)
378 break;
380 if(m_cList.GetCheck(i))
382 CString cmd;
384 while(path.HasRebaseApply())
386 if (m_pTaskbarList)
387 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
389 int ret = CMessageBox::Show(NULL, IDS_PROC_APPLYPATCH_REBASEDIRFOUND,
390 IDS_APPNAME,
391 1, IDI_ERROR, IDS_ABORTBUTTON, IDS_SKIPBUTTON, IDS_RESOLVEDBUTTON);
393 switch(ret)
395 case 1:
396 cmd = _T("git.exe am --abort");
397 break;
398 case 2:
399 cmd = _T("git.exe am --skip");
400 i++;
401 break;
402 case 3:
403 cmd = _T("git.exe am --resolved");
404 break;
405 default:
406 cmd.Empty();
408 if(cmd.IsEmpty())
410 m_bExitThread = TRUE;
411 break;
414 this->AddLogString(cmd);
415 CString output;
416 if (g_Git.Run(cmd, &output, CP_UTF8))
418 this->AddLogString(output);
419 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL)));
421 else
423 this->AddLogString(CString(MAKEINTRESOURCE(IDS_DONE)));
427 if(m_bExitThread)
428 break;
430 cmd = _T("git.exe am ");
432 if(this->m_bAddSignedOffBy)
433 cmd += _T("--signoff ");
435 if(this->m_b3Way)
436 cmd += _T("--3way ");
438 if(this->m_bIgnoreSpace)
439 cmd += _T("--ignore-space-change ");
441 if(this->m_bKeepCR)
442 cmd += _T("--keep-cr ");
444 cmd += _T("\"");
445 cmd += m_cList.GetItemText(i,0);
446 cmd += _T("\"");
448 this->AddLogString(cmd);
449 CString output;
450 if (g_Git.Run(cmd, &output, CP_UTF8))
452 //keep STATUS_APPLYING to let user retry failed patch
453 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_FAIL|CPatchListCtrl::STATUS_APPLYING);
454 this->AddLogString(output);
455 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL)));
456 if (m_pTaskbarList)
457 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
458 break;
461 else
463 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SUCCESS);
464 this->AddLogString(CString(MAKEINTRESOURCE(IDS_SUCCESS)));
468 else
470 CString sMessage;
471 sMessage.Format(IDS_PROC_SKIPPATCH, m_cList.GetItemText(i,0));
472 AddLogString(sMessage);
473 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SKIP);
476 m_cList.SetItemData(m_CurrentItem, (~CPatchListCtrl::STATUS_APPLYING)&m_cList.GetItemData(i));
477 m_CurrentItem++;
479 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
480 this->m_cList.InvalidateRect(rect);
482 UpdateOkCancelText();
485 //in case am fail, need refresh finial item status
486 CRect rect;
487 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
488 this->m_cList.InvalidateRect(rect);
490 this->m_cList.GetItemRect(m_CurrentItem,&rect,LVIR_BOUNDS);
491 this->m_cList.InvalidateRect(rect);
493 if (m_pTaskbarList)
495 m_pTaskbarList->SetProgressValue(m_hWnd, m_CurrentItem, m_cList.GetItemCount());
496 if (m_bExitThread && m_CurrentItem != m_cList.GetItemCount())
497 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
498 else if (!m_bExitThread && m_CurrentItem == m_cList.GetItemCount())
499 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
502 EnableInputCtrl(true);
503 InterlockedExchange(&m_bThreadRunning, FALSE);
504 UpdateOkCancelText();
505 return 0;
508 void CImportPatchDlg::OnBnClickedOk()
510 m_PathList.Clear();
511 this->UpdateData();
513 SaveSplitterPos();
515 if(IsFinish())
517 this->OnOK();
518 return;
521 m_ctrlTabCtrl.SetActiveTab(1);
523 EnableInputCtrl(false);
524 InterlockedExchange(&m_bThreadRunning, TRUE);
525 InterlockedExchange(&this->m_bExitThread, FALSE);
526 if ( (m_LoadingThread=AfxBeginThread(ThreadEntry, this)) ==NULL)
528 InterlockedExchange(&m_bThreadRunning, FALSE);
529 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
534 void CImportPatchDlg::DoSize(int delta)
536 this->RemoveAllAnchors();
538 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LIST_PATCH), delta, CW_TOPALIGN);
539 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
540 CSplitterControl::ChangeHeight(GetDlgItem(IDC_AM_TAB), -delta, CW_BOTTOMALIGN);
541 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
542 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_3WAY), 0, delta);
543 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_IGNORE_SPACE), 0, delta);
544 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGN_OFF), 0, delta);
545 CSplitterControl::ChangePos(GetDlgItem(IDC_KEEP_CR), 0, delta);
547 this->AddAmAnchor();
548 // adjust the minimum size of the dialog to prevent the resizing from
549 // moving the list control too far down.
550 CRect rcLogMsg;
551 m_cList.GetClientRect(rcLogMsg);
552 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_PatchListOrigRect.Height()+rcLogMsg.Height()));
554 SetSplitterRange();
555 // m_CommitList.Invalidate();
557 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
559 this->m_ctrlTabCtrl.Invalidate();
562 void CImportPatchDlg::OnSize(UINT nType, int cx, int cy)
564 CResizableStandAloneDialog::OnSize(nType, cx, cy);
566 SetSplitterRange();
569 LRESULT CImportPatchDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
571 switch (message) {
572 case WM_NOTIFY:
573 if (wParam == IDC_AM_SPLIT)
575 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
576 DoSize(pHdr->delta);
578 break;
581 return CResizableStandAloneDialog::DefWindowProc(message, wParam, lParam);
584 void CImportPatchDlg::SaveSplitterPos()
586 if (!IsIconic())
588 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer"));
589 RECT rectSplitter;
590 m_wndSplitter.GetWindowRect(&rectSplitter);
591 ScreenToClient(&rectSplitter);
592 regPos = rectSplitter.top;
598 void CImportPatchDlg::EnableInputCtrl(BOOL b)
600 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(b);
601 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(b);
602 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(b);
603 this->GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(b);
604 this->GetDlgItem(IDOK)->EnableWindow(b);
607 void CImportPatchDlg::UpdateOkCancelText()
609 if (this->m_bThreadRunning && !IsFinish())
611 this->GetDlgItem(IDOK)->EnableWindow(FALSE);
612 this->GetDlgItem(IDCANCEL)->SetWindowText(CString(MAKEINTRESOURCE(IDS_ABORTBUTTON)));
614 else if (!IsFinish())
616 this->GetDlgItem(IDOK)->EnableWindow(TRUE);
618 else
620 this->GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
621 this->GetDlgItem(IDOK)->SetWindowText(CString(MAKEINTRESOURCE(IDS_OKBUTTON)));
624 void CImportPatchDlg::OnBnClickedCancel()
626 if(this->m_bThreadRunning)
628 InterlockedExchange(&m_bExitThread,TRUE);
630 else
632 CTGitPath path;
633 path.SetFromWin(g_Git.m_CurrentDir);
634 if(path.HasRebaseApply())
635 if(CMessageBox::Show(NULL, IDS_PROC_APPLYPATCH_GITAMACTIVE, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION) == IDYES)
637 CString output;
638 if (g_Git.Run(_T("git.exe am --abort"), &output, CP_UTF8))
639 MessageBox(output, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
641 OnCancel();
645 void CImportPatchDlg::AddLogString(CString str)
647 this->m_wndOutput.SendMessage(SCI_SETREADONLY, FALSE);
648 CStringA sTextA = m_wndOutput.StringForControl(str);//CUnicodeUtils::GetUTF8(str);
649 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)sTextA);
650 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n");
651 this->m_wndOutput.SendMessage(SCI_SETREADONLY, TRUE);
652 //this->m_wndOutput.SendMessage(SCI_LINESCROLL,0,0x7FFFFFFF);
654 BOOL CImportPatchDlg::PreTranslateMessage(MSG* pMsg)
656 if (pMsg->message == WM_KEYDOWN)
658 switch (pMsg->wParam)
661 /* Avoid TAB control destroy but dialog exist*/
662 case VK_ESCAPE:
663 case VK_CANCEL:
665 TCHAR buff[128];
666 ::GetClassName(pMsg->hwnd,buff,128);
668 if(_tcsnicmp(buff,_T("RichEdit20W"),128)==0 ||
669 _tcsnicmp(buff,_T("Scintilla"),128)==0 ||
670 _tcsnicmp(buff,_T("SysListView32"),128)==0||
671 ::GetParent(pMsg->hwnd) == this->m_ctrlTabCtrl.m_hWnd)
673 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
674 return TRUE;
679 m_tooltips.RelayEvent(pMsg);
680 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
683 void CImportPatchDlg::OnHdnItemchangedListPatch(NMHDR * /*pNMHDR*/, LRESULT *pResult)
685 *pResult = 0;
687 if(this->m_cList.GetSelectedCount() != 1)
689 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
690 m_PatchCtrl.SetText(CString());
691 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
693 else
695 CString text;
697 POSITION pos;
698 pos = m_cList.GetFirstSelectedItemPosition();
699 int selected = m_cList.GetNextSelectedItem(pos);
701 if(selected>=0&& selected< m_cList.GetItemCount())
703 CString str = m_cList.GetItemText(selected,0);
704 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
705 m_PatchCtrl.SetText(text);
706 m_PatchCtrl.LoadFromFile(str);
707 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
710 else
712 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
713 m_PatchCtrl.SetText(text);
714 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
719 LRESULT CImportPatchDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
721 m_pTaskbarList.Release();
722 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
723 return 0;