Fixed issue #2495: "Show Reflog" dialog shows empty action for "push" entries
[TortoiseGit.git] / src / TortoiseProc / ImportPatchDlg.cpp
blob022477e6d0c77bc2b795d59f70b0b7fe816a33ca
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - 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"
29 #include "LoglistCommonResource.h"
31 // CImportPatchDlg dialog
33 IMPLEMENT_DYNAMIC(CImportPatchDlg, CResizableStandAloneDialog)
35 CImportPatchDlg::CImportPatchDlg(CWnd* pParent /*=NULL*/)
36 : CResizableStandAloneDialog(CImportPatchDlg::IDD, pParent)
37 , m_LoadingThread(FALSE)
39 m_cList.m_ContextMenuMask &=~ m_cList.GetMenuMask(CPatchListCtrl::MENU_APPLY);
41 m_CurrentItem =0;
43 m_bExitThread = false;
44 m_bThreadRunning =false;
46 m_b3Way = 1;
47 m_bIgnoreSpace = 1;
48 m_bAddSignedOffBy = FALSE;
49 m_bKeepCR = TRUE;
52 CImportPatchDlg::~CImportPatchDlg()
57 void CImportPatchDlg::DoDataExchange(CDataExchange* pDX)
59 CDialog::DoDataExchange(pDX);
60 DDX_Control(pDX, IDC_LIST_PATCH,m_cList);
61 DDX_Control(pDX, IDC_AM_SPLIT, m_wndSplitter);
62 DDX_Check(pDX, IDC_CHECK_3WAY, m_b3Way);
63 DDX_Check(pDX, IDC_CHECK_IGNORE_SPACE, m_bIgnoreSpace);
64 DDX_Check(pDX, IDC_SIGN_OFF, m_bAddSignedOffBy);
65 DDX_Check(pDX, IDC_KEEP_CR, m_bKeepCR);
68 void CImportPatchDlg::AddAmAnchor()
70 AddAnchor(IDC_AM_TAB,TOP_LEFT,BOTTOM_RIGHT);
71 AddAnchor(IDC_LIST_PATCH, TOP_LEFT, TOP_RIGHT);
72 AddAnchor(IDC_AM_SPLIT, TOP_LEFT, TOP_RIGHT);
73 AddAnchor(IDC_BUTTON_ADD, TOP_RIGHT);
74 AddAnchor(IDC_BUTTON_UP, TOP_RIGHT);
75 AddAnchor(IDC_BUTTON_DOWN, TOP_RIGHT);
76 AddAnchor(IDC_BUTTON_REMOVE, TOP_RIGHT);
78 AddAnchor(IDOK,BOTTOM_RIGHT);
79 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
80 AddAnchor(IDHELP, BOTTOM_RIGHT);
82 AddAnchor(IDC_AM_DUMY_TAB, TOP_LEFT, BOTTOM_RIGHT);
84 this->AddOthersToAnchor();
87 void CImportPatchDlg::SetSplitterRange()
89 if ((m_cList)&&(m_ctrlTabCtrl))
91 CRect rcTop;
92 m_cList.GetWindowRect(rcTop);
93 ScreenToClient(rcTop);
94 CRect rcMiddle;
95 m_ctrlTabCtrl.GetWindowRect(rcMiddle);
96 ScreenToClient(rcMiddle);
97 if (rcMiddle.Height() && rcMiddle.Width())
98 m_wndSplitter.SetRange(rcTop.top+160, rcMiddle.bottom-160);
102 BOOL CImportPatchDlg::OnInitDialog()
104 CResizableStandAloneDialog::OnInitDialog();
105 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
107 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
108 // do this, Explorer would be unable to send that message to our window if we
109 // were running elevated. It's OK to make the call all the time, since if we're
110 // not elevated, this is a no-op.
111 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
112 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
113 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
114 if (hUser)
116 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
117 if (pfnChangeWindowMessageFilterEx)
119 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
122 m_pTaskbarList.Release();
123 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
124 m_pTaskbarList = nullptr;
126 CRect rectDummy;
128 GetClientRect(m_DlgOrigRect);
129 m_cList.GetClientRect(m_PatchListOrigRect);
131 CWnd *pwnd=this->GetDlgItem(IDC_AM_DUMY_TAB);
132 pwnd->GetWindowRect(&rectDummy);
133 this->ScreenToClient(rectDummy);
135 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_AM_TAB))
137 TRACE0("Failed to create output tab window\n");
138 return FALSE; // fail to create
140 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
141 // Create output panes:
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 if (!m_wndOutput.Create(_T("Scintilla"),_T("source"),0,rectDummy, &m_ctrlTabCtrl, 0,0) )
154 TRACE0("Failed to create output windows\n");
155 return -1; // fail to create
157 m_wndOutput.Init(-1, FALSE);
158 m_wndOutput.Call(SCI_SETREADONLY, TRUE);
160 m_tooltips.AddTool(IDC_CHECK_3WAY,IDS_AM_3WAY_TT);
161 m_tooltips.AddTool(IDC_CHECK_IGNORE_SPACE,IDS_AM_IGNORE_SPACE_TT);
163 m_ctrlTabCtrl.AddTab(&m_PatchCtrl, CString(MAKEINTRESOURCE(IDS_PATCH)), 0);
164 m_ctrlTabCtrl.AddTab(&m_wndOutput, CString(MAKEINTRESOURCE(IDS_LOG)), 1);
166 AddAmAnchor();
167 AdjustControlSize(IDC_CHECK_3WAY);
168 AdjustControlSize(IDC_CHECK_IGNORE_SPACE);
169 AdjustControlSize(IDC_SIGN_OFF);
170 AdjustControlSize(IDC_KEEP_CR);
172 m_PathList.SortByPathname(true);
173 m_cList.SetExtendedStyle( m_cList.GetExtendedStyle()| LVS_EX_CHECKBOXES );
174 m_cList.InsertColumn(0, L"");
176 for (int i = 0; i < m_PathList.GetCount(); ++i)
178 m_cList.InsertItem(0,m_PathList[i].GetWinPath());
179 m_cList.SetCheck(0,true);
181 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
183 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer"));
184 RECT rcDlg, rcLogMsg, rcFileList;
185 GetClientRect(&rcDlg);
186 m_cList.GetWindowRect(&rcLogMsg);
187 ScreenToClient(&rcLogMsg);
188 this->m_ctrlTabCtrl.GetWindowRect(&rcFileList);
189 ScreenToClient(&rcFileList);
190 if (yPos)
192 RECT rectSplitter;
193 m_wndSplitter.GetWindowRect(&rectSplitter);
194 ScreenToClient(&rectSplitter);
195 int delta = yPos - rectSplitter.top;
196 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
198 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
199 DoSize(delta);
203 CAppUtils::SetListCtrlBackgroundImage(m_cList.GetSafeHwnd(), IDI_IMPORTPATHCES_BKG);
205 CString sWindowTitle;
206 GetWindowText(sWindowTitle);
207 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
209 EnableSaveRestore(_T("ImportDlg"));
211 SetSplitterRange();
213 return TRUE;
216 BEGIN_MESSAGE_MAP(CImportPatchDlg, CResizableStandAloneDialog)
217 ON_LBN_SELCHANGE(IDC_LIST_PATCH, &CImportPatchDlg::OnLbnSelchangeListPatch)
218 ON_BN_CLICKED(IDC_BUTTON_ADD, &CImportPatchDlg::OnBnClickedButtonAdd)
219 ON_BN_CLICKED(IDC_BUTTON_UP, &CImportPatchDlg::OnBnClickedButtonUp)
220 ON_BN_CLICKED(IDC_BUTTON_DOWN, &CImportPatchDlg::OnBnClickedButtonDown)
221 ON_BN_CLICKED(IDC_BUTTON_REMOVE, &CImportPatchDlg::OnBnClickedButtonRemove)
222 ON_BN_CLICKED(IDOK, &CImportPatchDlg::OnBnClickedOk)
223 ON_WM_SIZE()
224 ON_BN_CLICKED(IDCANCEL, &CImportPatchDlg::OnBnClickedCancel)
225 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_PATCH, &CImportPatchDlg::OnHdnItemchangedListPatch)
226 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
227 END_MESSAGE_MAP()
230 // CImportPatchDlg message handlers
232 void CImportPatchDlg::OnLbnSelchangeListPatch()
234 if(m_cList.GetSelectedCount() == 0)
236 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(FALSE);
237 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(FALSE);
238 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(FALSE);
240 else
242 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(TRUE);
243 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(TRUE);
244 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(TRUE);
248 void CImportPatchDlg::OnBnClickedButtonAdd()
250 CFileDialog dlg(TRUE,NULL,
251 NULL,
252 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
253 CString(MAKEINTRESOURCE(IDS_PATCHFILEFILTER)));
254 dlg.m_ofn.nMaxFile = 65536;
255 std::unique_ptr<TCHAR[]> path(new TCHAR[dlg.m_ofn.nMaxFile]);
256 SecureZeroMemory(path.get(), dlg.m_ofn.nMaxFile);
257 dlg.m_ofn.lpstrFile = path.get();
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);
275 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
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();
354 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
357 UINT CImportPatchDlg::PatchThread()
359 CTGitPath path;
360 path.SetFromWin(g_Git.m_CurrentDir);
362 int i=0;
363 UpdateOkCancelText();
364 for (i = m_CurrentItem; i < m_cList.GetItemCount(); ++i)
366 if (m_pTaskbarList)
368 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
369 m_pTaskbarList->SetProgressValue(m_hWnd, i, m_cList.GetItemCount());
372 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLYING|m_cList.GetItemData(i));
374 CRect rect;
375 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
376 this->m_cList.InvalidateRect(rect);
378 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
379 m_cList.EnsureVisible(i, FALSE);
381 if(m_bExitThread)
382 break;
384 if(m_cList.GetCheck(i))
386 CString cmd;
388 while(path.HasRebaseApply())
390 if (m_pTaskbarList)
391 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
393 int ret = CMessageBox::Show(NULL, IDS_PROC_APPLYPATCH_REBASEDIRFOUND,
394 IDS_APPNAME,
395 1, IDI_ERROR, IDS_ABORTBUTTON, IDS_SKIPBUTTON, IDS_RESOLVEDBUTTON);
397 switch(ret)
399 case 1:
400 cmd = _T("git.exe am --abort");
401 break;
402 case 2:
403 cmd = _T("git.exe am --skip");
404 ++i;
405 break;
406 case 3:
407 cmd = _T("git.exe am --resolved");
408 break;
409 default:
410 cmd.Empty();
412 if(cmd.IsEmpty())
414 m_bExitThread = TRUE;
415 break;
418 this->AddLogString(cmd);
419 CString output;
420 if (g_Git.Run(cmd, &output, CP_UTF8))
422 this->AddLogString(output);
423 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL)));
425 else
427 this->AddLogString(CString(MAKEINTRESOURCE(IDS_DONE)));
431 if(m_bExitThread)
432 break;
434 cmd = _T("git.exe am ");
436 if(this->m_bAddSignedOffBy)
437 cmd += _T("--signoff ");
439 if(this->m_b3Way)
440 cmd += _T("--3way ");
442 if(this->m_bIgnoreSpace)
443 cmd += _T("--ignore-space-change ");
445 if(this->m_bKeepCR)
446 cmd += _T("--keep-cr ");
448 cmd += _T("\"");
449 cmd += m_cList.GetItemText(i,0);
450 cmd += _T("\"");
452 this->AddLogString(cmd);
453 CString output;
454 if (g_Git.Run(cmd, &output, CP_UTF8))
456 //keep STATUS_APPLYING to let user retry failed patch
457 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_FAIL|CPatchListCtrl::STATUS_APPLYING);
458 this->AddLogString(output);
459 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL)));
460 if (m_pTaskbarList)
461 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
462 break;
465 else
467 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SUCCESS);
468 this->AddLogString(CString(MAKEINTRESOURCE(IDS_SUCCESS)));
472 else
474 CString sMessage;
475 sMessage.Format(IDS_PROC_SKIPPATCH, m_cList.GetItemText(i,0));
476 AddLogString(sMessage);
477 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SKIP);
480 m_cList.SetItemData(m_CurrentItem, (~CPatchListCtrl::STATUS_APPLYING)&m_cList.GetItemData(i));
481 ++m_CurrentItem;
483 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
484 this->m_cList.InvalidateRect(rect);
486 UpdateOkCancelText();
489 //in case am fail, need refresh finial item status
490 CRect rect;
491 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
492 this->m_cList.InvalidateRect(rect);
494 this->m_cList.GetItemRect(m_CurrentItem,&rect,LVIR_BOUNDS);
495 this->m_cList.InvalidateRect(rect);
497 if (m_pTaskbarList)
499 m_pTaskbarList->SetProgressValue(m_hWnd, m_CurrentItem, m_cList.GetItemCount());
500 if (m_bExitThread && m_CurrentItem != m_cList.GetItemCount())
501 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
502 else if (!m_bExitThread && m_CurrentItem == m_cList.GetItemCount())
503 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
506 EnableInputCtrl(true);
507 InterlockedExchange(&m_bThreadRunning, FALSE);
508 UpdateOkCancelText();
509 return 0;
512 void CImportPatchDlg::OnBnClickedOk()
514 m_PathList.Clear();
515 this->UpdateData();
517 SaveSplitterPos();
519 if(IsFinish())
521 this->OnOK();
522 return;
525 m_ctrlTabCtrl.SetActiveTab(1);
527 EnableInputCtrl(false);
528 InterlockedExchange(&m_bThreadRunning, TRUE);
529 InterlockedExchange(&this->m_bExitThread, FALSE);
530 if ( (m_LoadingThread=AfxBeginThread(ThreadEntry, this)) ==NULL)
532 InterlockedExchange(&m_bThreadRunning, FALSE);
533 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
538 void CImportPatchDlg::DoSize(int delta)
540 this->RemoveAllAnchors();
542 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LIST_PATCH), delta, CW_TOPALIGN);
543 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
544 CSplitterControl::ChangeHeight(GetDlgItem(IDC_AM_TAB), -delta, CW_BOTTOMALIGN);
545 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
546 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_3WAY), 0, delta);
547 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_IGNORE_SPACE), 0, delta);
548 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGN_OFF), 0, delta);
549 CSplitterControl::ChangePos(GetDlgItem(IDC_KEEP_CR), 0, delta);
551 this->AddAmAnchor();
552 // adjust the minimum size of the dialog to prevent the resizing from
553 // moving the list control too far down.
554 CRect rcLogMsg;
555 m_cList.GetClientRect(rcLogMsg);
556 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_PatchListOrigRect.Height()+rcLogMsg.Height()));
558 SetSplitterRange();
559 // m_CommitList.Invalidate();
561 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
563 this->m_ctrlTabCtrl.Invalidate();
566 void CImportPatchDlg::OnSize(UINT nType, int cx, int cy)
568 CResizableStandAloneDialog::OnSize(nType, cx, cy);
570 SetSplitterRange();
573 LRESULT CImportPatchDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
575 switch (message) {
576 case WM_NOTIFY:
577 if (wParam == IDC_AM_SPLIT)
579 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
580 DoSize(pHdr->delta);
582 break;
585 return CResizableStandAloneDialog::DefWindowProc(message, wParam, lParam);
588 void CImportPatchDlg::SaveSplitterPos()
590 if (!IsIconic())
592 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer"));
593 RECT rectSplitter;
594 m_wndSplitter.GetWindowRect(&rectSplitter);
595 ScreenToClient(&rectSplitter);
596 regPos = rectSplitter.top;
602 void CImportPatchDlg::EnableInputCtrl(BOOL b)
604 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(b);
605 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(b);
606 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(b);
607 this->GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(b);
608 this->GetDlgItem(IDOK)->EnableWindow(b);
611 void CImportPatchDlg::UpdateOkCancelText()
613 if (this->m_bThreadRunning && !IsFinish())
615 this->GetDlgItem(IDOK)->EnableWindow(FALSE);
616 this->GetDlgItem(IDCANCEL)->SetWindowText(CString(MAKEINTRESOURCE(IDS_ABORTBUTTON)));
618 else if (!IsFinish())
620 this->GetDlgItem(IDOK)->EnableWindow(TRUE);
622 else
624 this->GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
625 this->GetDlgItem(IDOK)->SetWindowText(CString(MAKEINTRESOURCE(IDS_OKBUTTON)));
628 void CImportPatchDlg::OnBnClickedCancel()
630 if(this->m_bThreadRunning)
632 InterlockedExchange(&m_bExitThread,TRUE);
634 else
636 CTGitPath path;
637 path.SetFromWin(g_Git.m_CurrentDir);
638 if(path.HasRebaseApply())
639 if(CMessageBox::Show(NULL, IDS_PROC_APPLYPATCH_GITAMACTIVE, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION) == IDYES)
641 CString output;
642 if (g_Git.Run(_T("git.exe am --abort"), &output, CP_UTF8))
643 MessageBox(output, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
645 OnCancel();
649 void CImportPatchDlg::AddLogString(CString str)
651 this->m_wndOutput.SendMessage(SCI_SETREADONLY, FALSE);
652 CStringA sTextA = m_wndOutput.StringForControl(str);//CUnicodeUtils::GetUTF8(str);
653 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)sTextA);
654 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n");
655 this->m_wndOutput.SendMessage(SCI_SETREADONLY, TRUE);
656 //this->m_wndOutput.SendMessage(SCI_LINESCROLL,0,0x7FFFFFFF);
658 BOOL CImportPatchDlg::PreTranslateMessage(MSG* pMsg)
660 if (pMsg->message == WM_KEYDOWN)
662 switch (pMsg->wParam)
665 /* Avoid TAB control destroy but dialog exist*/
666 case VK_ESCAPE:
667 case VK_CANCEL:
669 TCHAR buff[128] = { 0 };
670 ::GetClassName(pMsg->hwnd,buff,128);
672 /* Use MSFTEDIT_CLASS http://msdn.microsoft.com/en-us/library/bb531344.aspx */
673 if (_tcsnicmp(buff, MSFTEDIT_CLASS, 128) == 0 || //Unicode and MFC 2012 and later
674 _tcsnicmp(buff, RICHEDIT_CLASS, 128) == 0 || //ANSI or MFC 2010
675 _tcsnicmp(buff,_T("Scintilla"),128)==0 ||
676 _tcsnicmp(buff,_T("SysListView32"),128)==0||
677 ::GetParent(pMsg->hwnd) == this->m_ctrlTabCtrl.m_hWnd)
679 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
680 return TRUE;
685 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
688 void CImportPatchDlg::OnHdnItemchangedListPatch(NMHDR * /*pNMHDR*/, LRESULT *pResult)
690 *pResult = 0;
692 if(this->m_cList.GetSelectedCount() != 1)
694 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
695 m_PatchCtrl.SetText(CString());
696 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
698 else
700 CString text;
702 POSITION pos;
703 pos = m_cList.GetFirstSelectedItemPosition();
704 int selected = m_cList.GetNextSelectedItem(pos);
706 if(selected>=0&& selected< m_cList.GetItemCount())
708 CString str = m_cList.GetItemText(selected,0);
709 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
710 m_PatchCtrl.SetText(text);
711 m_PatchCtrl.LoadFromFile(str);
712 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
715 else
717 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
718 m_PatchCtrl.SetText(text);
719 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
724 LRESULT CImportPatchDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
726 m_pTaskbarList.Release();
727 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
728 SetUUIDOverlayIcon(m_hWnd);
729 return 0;