Extend static functions in CAppUtils with a window handle parameter
[TortoiseGit.git] / src / TortoiseProc / ImportPatchDlg.cpp
blob7cc79b0e247f3f5b77eac33a36acfa2aa44701bf
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2018 - 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 /*=nullptr*/)
36 : CResizableStandAloneDialog(CImportPatchDlg::IDD, pParent)
37 , m_LoadingThread(FALSE)
38 , m_CurrentItem(0)
39 , m_bExitThread(FALSE)
40 , m_bThreadRunning(FALSE)
41 , m_b3Way(BST_CHECKED)
42 , m_bIgnoreSpace(BST_CHECKED)
43 , m_bAddSignedOffBy(BST_UNCHECKED)
44 , m_bKeepCR(BST_CHECKED)
46 m_cList.m_ContextMenuMask &=~ m_cList.GetMenuMask(CPatchListCtrl::MENU_APPLY);
49 CImportPatchDlg::~CImportPatchDlg()
53 void CImportPatchDlg::DoDataExchange(CDataExchange* pDX)
55 CDialog::DoDataExchange(pDX);
56 DDX_Control(pDX, IDC_LIST_PATCH,m_cList);
57 DDX_Control(pDX, IDC_AM_SPLIT, m_wndSplitter);
58 DDX_Check(pDX, IDC_CHECK_3WAY, m_b3Way);
59 DDX_Check(pDX, IDC_CHECK_IGNORE_SPACE, m_bIgnoreSpace);
60 DDX_Check(pDX, IDC_SIGN_OFF, m_bAddSignedOffBy);
61 DDX_Check(pDX, IDC_KEEP_CR, m_bKeepCR);
64 void CImportPatchDlg::AddAmAnchor()
66 AddAnchor(IDC_AM_TAB,TOP_LEFT,BOTTOM_RIGHT);
67 AddAnchor(IDC_LIST_PATCH, TOP_LEFT, TOP_RIGHT);
68 AddAnchor(IDC_AM_SPLIT, TOP_LEFT, TOP_RIGHT);
69 AddAnchor(IDC_BUTTON_ADD, TOP_RIGHT);
70 AddAnchor(IDC_BUTTON_UP, TOP_RIGHT);
71 AddAnchor(IDC_BUTTON_DOWN, TOP_RIGHT);
72 AddAnchor(IDC_BUTTON_REMOVE, TOP_RIGHT);
74 AddAnchor(IDOK,BOTTOM_RIGHT);
75 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
76 AddAnchor(IDHELP, BOTTOM_RIGHT);
78 AddAnchor(IDC_AM_DUMY_TAB, TOP_LEFT, BOTTOM_RIGHT);
80 this->AddOthersToAnchor();
83 void CImportPatchDlg::SetSplitterRange()
85 if ((m_cList)&&(m_ctrlTabCtrl))
87 CRect rcTop;
88 m_cList.GetWindowRect(rcTop);
89 ScreenToClient(rcTop);
90 CRect rcMiddle;
91 m_ctrlTabCtrl.GetWindowRect(rcMiddle);
92 ScreenToClient(rcMiddle);
93 if (rcMiddle.Height() && rcMiddle.Width())
94 m_wndSplitter.SetRange(rcTop.top+160, rcMiddle.bottom-160);
98 BOOL CImportPatchDlg::OnInitDialog()
100 CResizableStandAloneDialog::OnInitDialog();
101 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
103 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
104 // do this, Explorer would be unable to send that message to our window if we
105 // were running elevated. It's OK to make the call all the time, since if we're
106 // not elevated, this is a no-op.
107 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
108 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
109 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(L"user32.dll");
110 if (hUser)
112 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
113 if (pfnChangeWindowMessageFilterEx)
115 pfnChangeWindowMessageFilterEx(m_hWnd, TaskBarButtonCreated, MSGFLT_ALLOW, &cfs);
118 m_pTaskbarList.Release();
119 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
120 m_pTaskbarList = nullptr;
122 CRect rectDummy;
124 GetClientRect(m_DlgOrigRect);
125 m_cList.GetClientRect(m_PatchListOrigRect);
127 CWnd *pwnd=this->GetDlgItem(IDC_AM_DUMY_TAB);
128 pwnd->GetWindowRect(&rectDummy);
129 this->ScreenToClient(rectDummy);
131 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_AM_TAB))
133 TRACE0("Failed to create output tab window\n");
134 return FALSE; // fail to create
136 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
137 // Create output panes:
139 if (!m_PatchCtrl.Create(L"Scintilla", L"source", 0, rectDummy, &m_ctrlTabCtrl, 0, 0))
141 TRACE0("Failed to create log message control");
142 return FALSE;
144 m_PatchCtrl.Init(-1);
145 m_PatchCtrl.Call(SCI_SETREADONLY, TRUE);
146 m_PatchCtrl.SetUDiffStyle();
148 if (!m_wndOutput.Create(L"Scintilla", L"source", 0, rectDummy, &m_ctrlTabCtrl, 0, 0))
150 TRACE0("Failed to create output windows\n");
151 return -1; // fail to create
153 m_wndOutput.Init(-1);
154 m_wndOutput.Call(SCI_SETREADONLY, TRUE);
156 m_tooltips.AddTool(IDC_CHECK_3WAY,IDS_AM_3WAY_TT);
157 m_tooltips.AddTool(IDC_CHECK_IGNORE_SPACE,IDS_AM_IGNORE_SPACE_TT);
159 m_ctrlTabCtrl.AddTab(&m_PatchCtrl, CString(MAKEINTRESOURCE(IDS_PATCH)), 0);
160 m_ctrlTabCtrl.AddTab(&m_wndOutput, CString(MAKEINTRESOURCE(IDS_LOG)), 1);
162 AdjustControlSize(IDC_CHECK_3WAY);
163 AdjustControlSize(IDC_CHECK_IGNORE_SPACE);
164 AdjustControlSize(IDC_SIGN_OFF);
165 AdjustControlSize(IDC_KEEP_CR);
167 AddAmAnchor();
169 m_PathList.SortByPathname(true);
170 m_cList.SetExtendedStyle( m_cList.GetExtendedStyle()| LVS_EX_CHECKBOXES );
171 m_cList.InsertColumn(0, L"");
172 m_cList.SetExtendedStyle((CRegDWORD(L"Software\\TortoiseGit\\FullRowSelect", TRUE) ? LVS_EX_FULLROWSELECT : 0) | m_cList.GetExtendedStyle());
174 for (int i = 0; i < m_PathList.GetCount(); ++i)
176 m_cList.InsertItem(0,m_PathList[i].GetWinPath());
177 m_cList.SetCheck(0,true);
179 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
181 DWORD yPos = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer");
182 RECT rcDlg, rcLogMsg, rcFileList;
183 GetClientRect(&rcDlg);
184 m_cList.GetWindowRect(&rcLogMsg);
185 ScreenToClient(&rcLogMsg);
186 this->m_ctrlTabCtrl.GetWindowRect(&rcFileList);
187 ScreenToClient(&rcFileList);
188 if (yPos)
190 RECT rectSplitter;
191 m_wndSplitter.GetWindowRect(&rectSplitter);
192 ScreenToClient(&rectSplitter);
193 int delta = yPos - rectSplitter.top;
194 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
196 m_wndSplitter.SetWindowPos(nullptr, 0, yPos, 0, 0, SWP_NOSIZE);
197 DoSize(delta);
201 CAppUtils::SetListCtrlBackgroundImage(m_cList.GetSafeHwnd(), IDI_IMPORTPATHCES_BKG);
203 CString sWindowTitle;
204 GetWindowText(sWindowTitle);
205 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
207 EnableSaveRestore(L"ImportDlg");
209 SetSplitterRange();
211 return TRUE;
214 BEGIN_MESSAGE_MAP(CImportPatchDlg, CResizableStandAloneDialog)
215 ON_LBN_SELCHANGE(IDC_LIST_PATCH, &CImportPatchDlg::OnLbnSelchangeListPatch)
216 ON_BN_CLICKED(IDC_BUTTON_ADD, &CImportPatchDlg::OnBnClickedButtonAdd)
217 ON_BN_CLICKED(IDC_BUTTON_UP, &CImportPatchDlg::OnBnClickedButtonUp)
218 ON_BN_CLICKED(IDC_BUTTON_DOWN, &CImportPatchDlg::OnBnClickedButtonDown)
219 ON_BN_CLICKED(IDC_BUTTON_REMOVE, &CImportPatchDlg::OnBnClickedButtonRemove)
220 ON_BN_CLICKED(IDOK, &CImportPatchDlg::OnBnClickedOk)
221 ON_WM_SIZE()
222 ON_WM_SYSCOLORCHANGE()
223 ON_WM_THEMECHANGED()
224 ON_BN_CLICKED(IDCANCEL, &CImportPatchDlg::OnBnClickedCancel)
225 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_PATCH, &CImportPatchDlg::OnHdnItemchangedListPatch)
226 ON_REGISTERED_MESSAGE(TaskBarButtonCreated, 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, nullptr, nullptr, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, CString(MAKEINTRESOURCE(IDS_PATCHFILEFILTER)));
251 dlg.m_ofn.nMaxFile = 65536;
252 TCHAR path[65536] = { 0 };
253 dlg.m_ofn.lpstrFile = path;
254 INT_PTR ret = dlg.DoModal();
255 SetCurrentDirectory(g_Git.m_CurrentDir);
256 if (ret == IDOK)
258 POSITION pos;
259 pos = dlg.GetStartPosition();
260 while (pos)
262 CString file = dlg.GetNextPathName(pos);
263 file.Trim();
264 if(!file.IsEmpty())
266 int index = m_cList.InsertItem(m_cList.GetItemCount(), file);
267 if (index >= 0)
268 m_cList.SetCheck(index, true);
271 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
275 void CImportPatchDlg::OnBnClickedButtonUp()
277 POSITION pos;
278 pos = m_cList.GetFirstSelectedItemPosition();
280 // do nothing if the first selected item is the first item in the list
281 if (m_cList.GetNextSelectedItem(pos) == 0)
282 return;
284 pos = m_cList.GetFirstSelectedItemPosition();
286 while (pos)
288 int index = m_cList.GetNextSelectedItem(pos);
289 if(index >= 1)
291 CString old = m_cList.GetItemText(index, 0);
292 BOOL oldState = m_cList.GetCheck(index);
293 m_cList.DeleteItem(index);
294 m_cList.InsertItem(index - 1, old);
295 m_cList.SetCheck(index - 1, oldState);
296 m_cList.SetItemState(index - 1, LVIS_SELECTED, LVIS_SELECTED);
297 m_cList.SetItemState(index, 0, LVIS_SELECTED);
302 void CImportPatchDlg::OnBnClickedButtonDown()
304 if (m_cList.GetSelectedCount() == 0)
305 return;
307 POSITION pos;
308 pos = m_cList.GetFirstSelectedItemPosition();
309 // use an array to store all selected item indexes; the user won't select too much items
310 auto indexes = std::make_unique<int[]>(m_cList.GetSelectedCount());
311 int i = 0;
312 while(pos)
313 indexes[i++] = m_cList.GetNextSelectedItem(pos);
315 // don't move any item if the last selected item is the last item in the m_CommitList
316 // (that would change the order of the selected items)
317 if(indexes[m_cList.GetSelectedCount() - 1] < m_cList.GetItemCount() - 1)
319 // iterate over the indexes backwards in order to correctly move multiselected items
320 for (i = m_cList.GetSelectedCount() - 1; i >= 0; i--)
322 int index = indexes[i];
323 CString old = m_cList.GetItemText(index, 0);
324 BOOL oldState = m_cList.GetCheck(index);
325 m_cList.DeleteItem(index);
326 m_cList.InsertItem(index + 1, old);
327 m_cList.SetCheck(index + 1, oldState);
328 m_cList.SetItemState(index + 1, LVIS_SELECTED, LVIS_SELECTED);
329 m_cList.SetItemState(index, 0, LVIS_SELECTED);
334 void CImportPatchDlg::OnBnClickedButtonRemove()
336 POSITION pos;
337 pos = m_cList.GetFirstSelectedItemPosition();
338 while (pos)
340 int index = m_cList.GetNextSelectedItem(pos);
341 m_cList.DeleteItem(index);
342 pos = m_cList.GetFirstSelectedItemPosition();
344 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
347 UINT CImportPatchDlg::PatchThread()
349 CTGitPath path;
350 path.SetFromWin(g_Git.m_CurrentDir);
352 int i=0;
353 UpdateOkCancelText();
354 for (i = m_CurrentItem; i < m_cList.GetItemCount(); ++i)
356 if (m_pTaskbarList)
358 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
359 m_pTaskbarList->SetProgressValue(m_hWnd, i, m_cList.GetItemCount());
362 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLYING|m_cList.GetItemData(i));
364 CRect rect;
365 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
366 this->m_cList.InvalidateRect(rect);
368 m_cList.SetColumnWidth(0, LVSCW_AUTOSIZE);
369 m_cList.EnsureVisible(i, FALSE);
371 if(m_bExitThread)
372 break;
374 if(m_cList.GetCheck(i))
376 CString cmd;
378 while(path.HasRebaseApply())
380 if (m_pTaskbarList)
381 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
383 int ret = CMessageBox::Show(GetSafeHwnd(), IDS_PROC_APPLYPATCH_REBASEDIRFOUND,
384 IDS_APPNAME,
385 1, IDI_ERROR, IDS_ABORTBUTTON, IDS_SKIPBUTTON, IDS_RESOLVEDBUTTON);
387 switch(ret)
389 case 1:
390 cmd = L"git.exe am --abort";
391 break;
392 case 2:
393 cmd = L"git.exe am --skip";
394 ++i;
395 break;
396 case 3:
397 cmd = L"git.exe am --resolved";
398 break;
399 default:
400 cmd.Empty();
402 if(cmd.IsEmpty())
404 m_bExitThread = TRUE;
405 break;
408 this->AddLogString(cmd);
409 CString output;
410 if (g_Git.Run(cmd, &output, CP_UTF8))
412 this->AddLogString(output);
413 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL)));
415 else
417 this->AddLogString(CString(MAKEINTRESOURCE(IDS_DONE)));
421 if(m_bExitThread)
422 break;
424 cmd = L"git.exe am ";
426 if(this->m_bAddSignedOffBy)
427 cmd += L"--signoff ";
429 if(this->m_b3Way)
430 cmd += L"--3way ";
432 if(this->m_bIgnoreSpace)
433 cmd += L"--ignore-space-change ";
435 if(this->m_bKeepCR)
436 cmd += L"--keep-cr ";
438 cmd += L'"';
439 cmd += m_cList.GetItemText(i,0);
440 cmd += L'"';
442 this->AddLogString(cmd);
443 CString output;
444 if (g_Git.Run(cmd, &output, CP_UTF8))
446 //keep STATUS_APPLYING to let user retry failed patch
447 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_FAIL|CPatchListCtrl::STATUS_APPLYING);
448 this->AddLogString(output);
449 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL)));
450 if (m_pTaskbarList)
451 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
452 break;
455 else
457 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SUCCESS);
458 this->AddLogString(CString(MAKEINTRESOURCE(IDS_SUCCESS)));
462 else
464 CString sMessage;
465 sMessage.Format(IDS_PROC_SKIPPATCH, (LPCTSTR)m_cList.GetItemText(i, 0));
466 AddLogString(sMessage);
467 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SKIP);
470 m_cList.SetItemData(m_CurrentItem, (~CPatchListCtrl::STATUS_APPLYING)&m_cList.GetItemData(i));
471 ++m_CurrentItem;
473 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
474 this->m_cList.InvalidateRect(rect);
476 UpdateOkCancelText();
479 //in case am fail, need refresh finial item status
480 CRect rect;
481 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
482 this->m_cList.InvalidateRect(rect);
484 this->m_cList.GetItemRect(m_CurrentItem,&rect,LVIR_BOUNDS);
485 this->m_cList.InvalidateRect(rect);
487 if (m_pTaskbarList)
489 m_pTaskbarList->SetProgressValue(m_hWnd, m_CurrentItem, m_cList.GetItemCount());
490 if (m_bExitThread && m_CurrentItem != m_cList.GetItemCount())
491 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
492 else if (!m_bExitThread && m_CurrentItem == m_cList.GetItemCount())
493 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
496 EnableInputCtrl(true);
497 InterlockedExchange(&m_bThreadRunning, FALSE);
498 UpdateOkCancelText();
499 return 0;
502 void CImportPatchDlg::OnBnClickedOk()
504 m_PathList.Clear();
505 this->UpdateData();
507 SaveSplitterPos();
509 if (!CAppUtils::CheckUserData(GetSafeHwnd()))
510 return;
512 if(IsFinish())
514 this->OnOK();
515 return;
518 m_ctrlTabCtrl.SetActiveTab(1);
520 EnableInputCtrl(false);
521 InterlockedExchange(&m_bThreadRunning, TRUE);
522 InterlockedExchange(&this->m_bExitThread, FALSE);
523 if ((m_LoadingThread = AfxBeginThread(ThreadEntry, this)) == nullptr)
525 InterlockedExchange(&m_bThreadRunning, FALSE);
526 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
530 void CImportPatchDlg::DoSize(int delta)
532 this->RemoveAllAnchors();
534 auto hdwp = BeginDeferWindowPos(6);
535 hdwp = CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_LIST_PATCH), 0, 0, 0, delta);
536 hdwp = CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_AM_TAB), 0, delta, 0, 0);
537 hdwp = CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECK_3WAY), 0, delta, 0, delta);
538 hdwp = CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECK_IGNORE_SPACE), 0, delta, 0, delta);
539 hdwp = CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_SIGN_OFF), 0, delta, 0, delta);
540 hdwp = CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_KEEP_CR), 0, delta, 0, delta);
541 EndDeferWindowPos(hdwp);
543 this->AddAmAnchor();
544 // adjust the minimum size of the dialog to prevent the resizing from
545 // moving the list control too far down.
546 CRect rcLogMsg;
547 m_cList.GetClientRect(rcLogMsg);
548 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_PatchListOrigRect.Height()+rcLogMsg.Height()));
550 SetSplitterRange();
551 // m_CommitList.Invalidate();
553 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
555 this->m_ctrlTabCtrl.Invalidate();
558 void CImportPatchDlg::OnSize(UINT nType, int cx, int cy)
560 CResizableStandAloneDialog::OnSize(nType, cx, cy);
562 SetSplitterRange();
565 LRESULT CImportPatchDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
567 switch (message) {
568 case WM_NOTIFY:
569 if (wParam == IDC_AM_SPLIT)
571 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
572 DoSize(pHdr->delta);
574 break;
577 return CResizableStandAloneDialog::DefWindowProc(message, wParam, lParam);
580 void CImportPatchDlg::SaveSplitterPos()
582 if (!IsIconic())
584 CRegDWORD regPos(L"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer");
585 RECT rectSplitter;
586 m_wndSplitter.GetWindowRect(&rectSplitter);
587 ScreenToClient(&rectSplitter);
588 regPos = rectSplitter.top;
592 void CImportPatchDlg::EnableInputCtrl(BOOL b)
594 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(b);
595 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(b);
596 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(b);
597 this->GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(b);
598 this->GetDlgItem(IDOK)->EnableWindow(b);
601 void CImportPatchDlg::UpdateOkCancelText()
603 if (this->m_bThreadRunning && !IsFinish())
605 this->GetDlgItem(IDOK)->EnableWindow(FALSE);
606 this->GetDlgItem(IDCANCEL)->SetWindowText(CString(MAKEINTRESOURCE(IDS_ABORTBUTTON)));
608 else if (!IsFinish())
610 this->GetDlgItem(IDOK)->EnableWindow(TRUE);
612 else
614 this->GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
615 this->GetDlgItem(IDOK)->SetWindowText(CString(MAKEINTRESOURCE(IDS_OKBUTTON)));
618 void CImportPatchDlg::OnBnClickedCancel()
620 if(this->m_bThreadRunning)
622 InterlockedExchange(&m_bExitThread,TRUE);
624 else
626 CTGitPath path;
627 path.SetFromWin(g_Git.m_CurrentDir);
628 if(path.HasRebaseApply())
629 if (CMessageBox::Show(GetSafeHwnd(), IDS_PROC_APPLYPATCH_GITAMACTIVE, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION) == IDYES)
631 CString output;
632 if (g_Git.Run(L"git.exe am --abort", &output, CP_UTF8))
633 MessageBox(output, L"TortoiseGit", MB_OK | MB_ICONERROR);
635 OnCancel();
639 void CImportPatchDlg::AddLogString(CString str)
641 this->m_wndOutput.SendMessage(SCI_SETREADONLY, FALSE);
642 CStringA sTextA = m_wndOutput.StringForControl(str);//CUnicodeUtils::GetUTF8(str);
643 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)sTextA);
644 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n");
645 this->m_wndOutput.SendMessage(SCI_SETREADONLY, TRUE);
646 //this->m_wndOutput.SendMessage(SCI_LINESCROLL,0,0x7FFFFFFF);
648 BOOL CImportPatchDlg::PreTranslateMessage(MSG* pMsg)
650 if (pMsg->message == WM_KEYDOWN)
652 switch (pMsg->wParam)
654 /* Avoid TAB control destroy but dialog exist*/
655 case VK_ESCAPE:
656 case VK_CANCEL:
658 TCHAR buff[129];
659 ::GetClassName(pMsg->hwnd, buff, _countof(buff) - 1);
661 /* Use MSFTEDIT_CLASS http://msdn.microsoft.com/en-us/library/bb531344.aspx */
662 if (_wcsnicmp(buff, MSFTEDIT_CLASS, _countof(buff) - 1) == 0 || //Unicode and MFC 2012 and later
663 _wcsnicmp(buff, RICHEDIT_CLASS, _countof(buff) - 1) == 0 || //ANSI or MFC 2010
664 _wcsnicmp(buff, L"Scintilla", _countof(buff) - 1) == 0 ||
665 _wcsnicmp(buff, L"SysListView32", _countof(buff) - 1) == 0 ||
666 ::GetParent(pMsg->hwnd) == this->m_ctrlTabCtrl.m_hWnd)
668 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
669 return TRUE;
674 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
677 void CImportPatchDlg::OnHdnItemchangedListPatch(NMHDR * /*pNMHDR*/, LRESULT *pResult)
679 *pResult = 0;
681 if(this->m_cList.GetSelectedCount() != 1)
683 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
684 m_PatchCtrl.SetText(CString());
685 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
687 else
689 CString text;
691 POSITION pos;
692 pos = m_cList.GetFirstSelectedItemPosition();
693 int selected = m_cList.GetNextSelectedItem(pos);
695 if(selected>=0&& selected< m_cList.GetItemCount())
697 CString str = m_cList.GetItemText(selected,0);
698 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
699 m_PatchCtrl.SetText(text);
700 m_PatchCtrl.LoadFromFile(str);
701 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
704 else
706 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
707 m_PatchCtrl.SetText(text);
708 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
713 LRESULT CImportPatchDlg::OnTaskbarBtnCreated(WPARAM wParam, LPARAM lParam)
715 m_pTaskbarList.Release();
716 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
717 return __super::OnTaskbarButtonCreated(wParam, lParam);
720 void CImportPatchDlg::OnSysColorChange()
722 __super::OnSysColorChange();
723 m_PatchCtrl.SetUDiffStyle();
724 m_wndOutput.SetColors(true);
725 CAppUtils::SetListCtrlBackgroundImage(m_cList.GetSafeHwnd(), IDI_IMPORTPATHCES_BKG);
728 LRESULT CImportPatchDlg::OnThemeChanged()
730 CMFCVisualManager::GetInstance()->DestroyInstance();
731 return 0;