Drop only once used member
[TortoiseGit.git] / src / TortoiseProc / ImportPatchDlg.cpp
blob139c302f7d44a6553fe5cdb52058d7ede10a6d5c
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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)
36 , m_LoadingThread(FALSE)
38 m_cList.m_ContextMenuMask &=~ m_cList.GetMenuMask(CPatchListCtrl::MENU_APPLY);
40 m_CurrentItem =0;
42 m_bExitThread = false;
43 m_bThreadRunning =false;
45 m_b3Way = 1;
46 m_bIgnoreSpace = 1;
47 m_bAddSignedOffBy = FALSE;
48 m_bKeepCR = TRUE;
51 CImportPatchDlg::~CImportPatchDlg()
56 void CImportPatchDlg::DoDataExchange(CDataExchange* pDX)
58 CDialog::DoDataExchange(pDX);
59 DDX_Control(pDX, IDC_LIST_PATCH,m_cList);
60 DDX_Control(pDX, IDC_AM_SPLIT, m_wndSplitter);
61 DDX_Check(pDX, IDC_CHECK_3WAY, m_b3Way);
62 DDX_Check(pDX, IDC_CHECK_IGNORE_SPACE, m_bIgnoreSpace);
63 DDX_Check(pDX, IDC_SIGN_OFF, m_bAddSignedOffBy);
64 DDX_Check(pDX, IDC_KEEP_CR, m_bKeepCR);
67 void CImportPatchDlg::AddAmAnchor()
69 AddAnchor(IDC_AM_TAB,TOP_LEFT,BOTTOM_RIGHT);
70 AddAnchor(IDC_LIST_PATCH, TOP_LEFT, TOP_RIGHT);
71 AddAnchor(IDC_AM_SPLIT, TOP_LEFT, TOP_RIGHT);
72 AddAnchor(IDC_BUTTON_ADD, TOP_RIGHT);
73 AddAnchor(IDC_BUTTON_UP, TOP_RIGHT);
74 AddAnchor(IDC_BUTTON_DOWN, TOP_RIGHT);
75 AddAnchor(IDC_BUTTON_REMOVE, TOP_RIGHT);
77 AddAnchor(IDOK,BOTTOM_RIGHT);
78 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
79 AddAnchor(IDHELP, BOTTOM_RIGHT);
81 AddAnchor(IDC_AM_DUMY_TAB, TOP_LEFT, BOTTOM_RIGHT);
83 this->AddOthersToAnchor();
86 void CImportPatchDlg::SetSplitterRange()
88 if ((m_cList)&&(m_ctrlTabCtrl))
90 CRect rcTop;
91 m_cList.GetWindowRect(rcTop);
92 ScreenToClient(rcTop);
93 CRect rcMiddle;
94 m_ctrlTabCtrl.GetWindowRect(rcMiddle);
95 ScreenToClient(rcMiddle);
96 if (rcMiddle.Height() && rcMiddle.Width())
97 m_wndSplitter.SetRange(rcTop.top+160, rcMiddle.bottom-160);
101 BOOL CImportPatchDlg::OnInitDialog()
103 CResizableStandAloneDialog::OnInitDialog();
104 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
106 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
107 // do this, Explorer would be unable to send that message to our window if we
108 // were running elevated. It's OK to make the call all the time, since if we're
109 // not elevated, this is a no-op.
110 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
111 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
112 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
113 if (hUser)
115 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
116 if (pfnChangeWindowMessageFilterEx)
118 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
121 m_pTaskbarList.Release();
122 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
123 m_pTaskbarList = nullptr;
125 CRect rectDummy;
127 GetClientRect(m_DlgOrigRect);
128 m_cList.GetClientRect(m_PatchListOrigRect);
130 CWnd *pwnd=this->GetDlgItem(IDC_AM_DUMY_TAB);
131 pwnd->GetWindowRect(&rectDummy);
132 this->ScreenToClient(rectDummy);
134 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_AM_TAB))
136 TRACE0("Failed to create output tab window\n");
137 return FALSE; // fail to create
139 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
140 // Create output panes:
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 if (!m_wndOutput.Create(_T("Scintilla"),_T("source"),0,rectDummy, &m_ctrlTabCtrl, 0,0) )
153 TRACE0("Failed to create output windows\n");
154 return -1; // fail to create
156 m_wndOutput.Init(-1, FALSE);
157 m_wndOutput.Call(SCI_SETREADONLY, TRUE);
159 m_tooltips.Create(this);
161 m_tooltips.AddTool(IDC_CHECK_3WAY,IDS_AM_3WAY_TT);
162 m_tooltips.AddTool(IDC_CHECK_IGNORE_SPACE,IDS_AM_IGNORE_SPACE_TT);
164 m_ctrlTabCtrl.AddTab(&m_PatchCtrl, CString(MAKEINTRESOURCE(IDS_PATCH)), 0);
165 m_ctrlTabCtrl.AddTab(&m_wndOutput, CString(MAKEINTRESOURCE(IDS_LOG)), 1);
167 AddAmAnchor();
168 AdjustControlSize(IDC_CHECK_3WAY);
169 AdjustControlSize(IDC_CHECK_IGNORE_SPACE);
170 AdjustControlSize(IDC_SIGN_OFF);
171 AdjustControlSize(IDC_KEEP_CR);
173 m_PathList.SortByPathname(true);
174 m_cList.SetExtendedStyle( m_cList.GetExtendedStyle()| LVS_EX_CHECKBOXES );
175 m_cList.InsertColumn(0, L"");
177 for (int i = 0; i < m_PathList.GetCount(); ++i)
179 m_cList.InsertItem(0,m_PathList[i].GetWinPath());
180 m_cList.SetCheck(0,true);
182 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
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 std::unique_ptr<TCHAR[]> path(new TCHAR[dlg.m_ofn.nMaxFile]);
257 SecureZeroMemory(path.get(), 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);
276 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
280 void CImportPatchDlg::OnBnClickedButtonUp()
282 POSITION pos;
283 pos = m_cList.GetFirstSelectedItemPosition();
285 // do nothing if the first selected item is the first item in the list
286 if (m_cList.GetNextSelectedItem(pos) == 0)
287 return;
289 pos = m_cList.GetFirstSelectedItemPosition();
291 while (pos)
293 int index = m_cList.GetNextSelectedItem(pos);
294 if(index >= 1)
296 CString old = m_cList.GetItemText(index, 0);
297 BOOL oldState = m_cList.GetCheck(index);
298 m_cList.DeleteItem(index);
299 m_cList.InsertItem(index - 1, old);
300 m_cList.SetCheck(index - 1, oldState);
301 m_cList.SetItemState(index - 1, LVIS_SELECTED, LVIS_SELECTED);
302 m_cList.SetItemState(index, 0, LVIS_SELECTED);
308 void CImportPatchDlg::OnBnClickedButtonDown()
310 if (m_cList.GetSelectedCount() == 0)
311 return;
313 POSITION pos;
314 pos = m_cList.GetFirstSelectedItemPosition();
315 // use an array to store all selected item indexes; the user won't select too much items
316 int* indexes = NULL;
317 indexes = new int[m_cList.GetSelectedCount()];
318 int i = 0;
319 while(pos)
321 indexes[i++] = m_cList.GetNextSelectedItem(pos);
324 // don't move any item if the last selected item is the last item in the m_CommitList
325 // (that would change the order of the selected items)
326 if(indexes[m_cList.GetSelectedCount() - 1] < m_cList.GetItemCount() - 1)
328 // iterate over the indexes backwards in order to correctly move multiselected items
329 for (i = m_cList.GetSelectedCount() - 1; i >= 0; i--)
331 int index = indexes[i];
332 CString old = m_cList.GetItemText(index, 0);
333 BOOL oldState = m_cList.GetCheck(index);
334 m_cList.DeleteItem(index);
335 m_cList.InsertItem(index + 1, old);
336 m_cList.SetCheck(index + 1, oldState);
337 m_cList.SetItemState(index + 1, LVIS_SELECTED, LVIS_SELECTED);
338 m_cList.SetItemState(index, 0, LVIS_SELECTED);
341 delete [] indexes;
342 indexes = NULL;
345 void CImportPatchDlg::OnBnClickedButtonRemove()
347 POSITION pos;
348 pos = m_cList.GetFirstSelectedItemPosition();
349 while (pos)
351 int index = m_cList.GetNextSelectedItem(pos);
352 m_cList.DeleteItem(index);
353 pos = m_cList.GetFirstSelectedItemPosition();
355 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
358 UINT CImportPatchDlg::PatchThread()
360 CTGitPath path;
361 path.SetFromWin(g_Git.m_CurrentDir);
363 int i=0;
364 UpdateOkCancelText();
365 for (i = m_CurrentItem; i < m_cList.GetItemCount(); ++i)
367 if (m_pTaskbarList)
369 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
370 m_pTaskbarList->SetProgressValue(m_hWnd, i, m_cList.GetItemCount());
373 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLYING|m_cList.GetItemData(i));
375 CRect rect;
376 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
377 this->m_cList.InvalidateRect(rect);
379 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
380 m_cList.EnsureVisible(i, FALSE);
382 if(m_bExitThread)
383 break;
385 if(m_cList.GetCheck(i))
387 CString cmd;
389 while(path.HasRebaseApply())
391 if (m_pTaskbarList)
392 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
394 int ret = CMessageBox::Show(NULL, IDS_PROC_APPLYPATCH_REBASEDIRFOUND,
395 IDS_APPNAME,
396 1, IDI_ERROR, IDS_ABORTBUTTON, IDS_SKIPBUTTON, IDS_RESOLVEDBUTTON);
398 switch(ret)
400 case 1:
401 cmd = _T("git.exe am --abort");
402 break;
403 case 2:
404 cmd = _T("git.exe am --skip");
405 ++i;
406 break;
407 case 3:
408 cmd = _T("git.exe am --resolved");
409 break;
410 default:
411 cmd.Empty();
413 if(cmd.IsEmpty())
415 m_bExitThread = TRUE;
416 break;
419 this->AddLogString(cmd);
420 CString output;
421 if (g_Git.Run(cmd, &output, CP_UTF8))
423 this->AddLogString(output);
424 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL)));
426 else
428 this->AddLogString(CString(MAKEINTRESOURCE(IDS_DONE)));
432 if(m_bExitThread)
433 break;
435 cmd = _T("git.exe am ");
437 if(this->m_bAddSignedOffBy)
438 cmd += _T("--signoff ");
440 if(this->m_b3Way)
441 cmd += _T("--3way ");
443 if(this->m_bIgnoreSpace)
444 cmd += _T("--ignore-space-change ");
446 if(this->m_bKeepCR)
447 cmd += _T("--keep-cr ");
449 cmd += _T("\"");
450 cmd += m_cList.GetItemText(i,0);
451 cmd += _T("\"");
453 this->AddLogString(cmd);
454 CString output;
455 if (g_Git.Run(cmd, &output, CP_UTF8))
457 //keep STATUS_APPLYING to let user retry failed patch
458 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_FAIL|CPatchListCtrl::STATUS_APPLYING);
459 this->AddLogString(output);
460 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL)));
461 if (m_pTaskbarList)
462 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
463 break;
466 else
468 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SUCCESS);
469 this->AddLogString(CString(MAKEINTRESOURCE(IDS_SUCCESS)));
473 else
475 CString sMessage;
476 sMessage.Format(IDS_PROC_SKIPPATCH, m_cList.GetItemText(i,0));
477 AddLogString(sMessage);
478 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SKIP);
481 m_cList.SetItemData(m_CurrentItem, (~CPatchListCtrl::STATUS_APPLYING)&m_cList.GetItemData(i));
482 ++m_CurrentItem;
484 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
485 this->m_cList.InvalidateRect(rect);
487 UpdateOkCancelText();
490 //in case am fail, need refresh finial item status
491 CRect rect;
492 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
493 this->m_cList.InvalidateRect(rect);
495 this->m_cList.GetItemRect(m_CurrentItem,&rect,LVIR_BOUNDS);
496 this->m_cList.InvalidateRect(rect);
498 if (m_pTaskbarList)
500 m_pTaskbarList->SetProgressValue(m_hWnd, m_CurrentItem, m_cList.GetItemCount());
501 if (m_bExitThread && m_CurrentItem != m_cList.GetItemCount())
502 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
503 else if (!m_bExitThread && m_CurrentItem == m_cList.GetItemCount())
504 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
507 EnableInputCtrl(true);
508 InterlockedExchange(&m_bThreadRunning, FALSE);
509 UpdateOkCancelText();
510 return 0;
513 void CImportPatchDlg::OnBnClickedOk()
515 m_PathList.Clear();
516 this->UpdateData();
518 SaveSplitterPos();
520 if(IsFinish())
522 this->OnOK();
523 return;
526 m_ctrlTabCtrl.SetActiveTab(1);
528 EnableInputCtrl(false);
529 InterlockedExchange(&m_bThreadRunning, TRUE);
530 InterlockedExchange(&this->m_bExitThread, FALSE);
531 if ( (m_LoadingThread=AfxBeginThread(ThreadEntry, this)) ==NULL)
533 InterlockedExchange(&m_bThreadRunning, FALSE);
534 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
539 void CImportPatchDlg::DoSize(int delta)
541 this->RemoveAllAnchors();
543 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LIST_PATCH), delta, CW_TOPALIGN);
544 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
545 CSplitterControl::ChangeHeight(GetDlgItem(IDC_AM_TAB), -delta, CW_BOTTOMALIGN);
546 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
547 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_3WAY), 0, delta);
548 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_IGNORE_SPACE), 0, delta);
549 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGN_OFF), 0, delta);
550 CSplitterControl::ChangePos(GetDlgItem(IDC_KEEP_CR), 0, delta);
552 this->AddAmAnchor();
553 // adjust the minimum size of the dialog to prevent the resizing from
554 // moving the list control too far down.
555 CRect rcLogMsg;
556 m_cList.GetClientRect(rcLogMsg);
557 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_PatchListOrigRect.Height()+rcLogMsg.Height()));
559 SetSplitterRange();
560 // m_CommitList.Invalidate();
562 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
564 this->m_ctrlTabCtrl.Invalidate();
567 void CImportPatchDlg::OnSize(UINT nType, int cx, int cy)
569 CResizableStandAloneDialog::OnSize(nType, cx, cy);
571 SetSplitterRange();
574 LRESULT CImportPatchDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
576 switch (message) {
577 case WM_NOTIFY:
578 if (wParam == IDC_AM_SPLIT)
580 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
581 DoSize(pHdr->delta);
583 break;
586 return CResizableStandAloneDialog::DefWindowProc(message, wParam, lParam);
589 void CImportPatchDlg::SaveSplitterPos()
591 if (!IsIconic())
593 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer"));
594 RECT rectSplitter;
595 m_wndSplitter.GetWindowRect(&rectSplitter);
596 ScreenToClient(&rectSplitter);
597 regPos = rectSplitter.top;
603 void CImportPatchDlg::EnableInputCtrl(BOOL b)
605 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(b);
606 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(b);
607 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(b);
608 this->GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(b);
609 this->GetDlgItem(IDOK)->EnableWindow(b);
612 void CImportPatchDlg::UpdateOkCancelText()
614 if (this->m_bThreadRunning && !IsFinish())
616 this->GetDlgItem(IDOK)->EnableWindow(FALSE);
617 this->GetDlgItem(IDCANCEL)->SetWindowText(CString(MAKEINTRESOURCE(IDS_ABORTBUTTON)));
619 else if (!IsFinish())
621 this->GetDlgItem(IDOK)->EnableWindow(TRUE);
623 else
625 this->GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
626 this->GetDlgItem(IDOK)->SetWindowText(CString(MAKEINTRESOURCE(IDS_OKBUTTON)));
629 void CImportPatchDlg::OnBnClickedCancel()
631 if(this->m_bThreadRunning)
633 InterlockedExchange(&m_bExitThread,TRUE);
635 else
637 CTGitPath path;
638 path.SetFromWin(g_Git.m_CurrentDir);
639 if(path.HasRebaseApply())
640 if(CMessageBox::Show(NULL, IDS_PROC_APPLYPATCH_GITAMACTIVE, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION) == IDYES)
642 CString output;
643 if (g_Git.Run(_T("git.exe am --abort"), &output, CP_UTF8))
644 MessageBox(output, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
646 OnCancel();
650 void CImportPatchDlg::AddLogString(CString str)
652 this->m_wndOutput.SendMessage(SCI_SETREADONLY, FALSE);
653 CStringA sTextA = m_wndOutput.StringForControl(str);//CUnicodeUtils::GetUTF8(str);
654 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)sTextA);
655 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n");
656 this->m_wndOutput.SendMessage(SCI_SETREADONLY, TRUE);
657 //this->m_wndOutput.SendMessage(SCI_LINESCROLL,0,0x7FFFFFFF);
659 BOOL CImportPatchDlg::PreTranslateMessage(MSG* pMsg)
661 if (pMsg->message == WM_KEYDOWN)
663 switch (pMsg->wParam)
666 /* Avoid TAB control destroy but dialog exist*/
667 case VK_ESCAPE:
668 case VK_CANCEL:
670 TCHAR buff[128] = { 0 };
671 ::GetClassName(pMsg->hwnd,buff,128);
673 /* Use MSFTEDIT_CLASS http://msdn.microsoft.com/en-us/library/bb531344.aspx */
674 if (_tcsnicmp(buff, MSFTEDIT_CLASS, 128) == 0 || //Unicode and MFC 2012 and later
675 _tcsnicmp(buff, RICHEDIT_CLASS, 128) == 0 || //ANSI or MFC 2010
676 _tcsnicmp(buff,_T("Scintilla"),128)==0 ||
677 _tcsnicmp(buff,_T("SysListView32"),128)==0||
678 ::GetParent(pMsg->hwnd) == this->m_ctrlTabCtrl.m_hWnd)
680 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
681 return TRUE;
686 m_tooltips.RelayEvent(pMsg);
687 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
690 void CImportPatchDlg::OnHdnItemchangedListPatch(NMHDR * /*pNMHDR*/, LRESULT *pResult)
692 *pResult = 0;
694 if(this->m_cList.GetSelectedCount() != 1)
696 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
697 m_PatchCtrl.SetText(CString());
698 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
700 else
702 CString text;
704 POSITION pos;
705 pos = m_cList.GetFirstSelectedItemPosition();
706 int selected = m_cList.GetNextSelectedItem(pos);
708 if(selected>=0&& selected< m_cList.GetItemCount())
710 CString str = m_cList.GetItemText(selected,0);
711 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
712 m_PatchCtrl.SetText(text);
713 m_PatchCtrl.LoadFromFile(str);
714 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
717 else
719 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
720 m_PatchCtrl.SetText(text);
721 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
726 LRESULT CImportPatchDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
728 m_pTaskbarList.Release();
729 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
730 SetUUIDOverlayIcon(m_hWnd);
731 return 0;