1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017 - 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
23 #include "TortoiseProc.h"
24 #include "ImportPatchDlg.h"
26 #include "MessageBox.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
)
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
))
88 m_cList
.GetWindowRect(rcTop
);
89 ScreenToClient(rcTop
);
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");
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;
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");
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
);
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
);
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
);
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");
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
)
222 ON_WM_SYSCOLORCHANGE()
224 ON_BN_CLICKED(IDCANCEL
, &CImportPatchDlg::OnBnClickedCancel
)
225 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_LIST_PATCH
, &CImportPatchDlg::OnHdnItemchangedListPatch
)
226 ON_REGISTERED_MESSAGE(TaskBarButtonCreated
, OnTaskbarBtnCreated
)
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
);
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
);
259 pos
= dlg
.GetStartPosition();
262 CString file
= dlg
.GetNextPathName(pos
);
266 int index
= m_cList
.InsertItem(m_cList
.GetItemCount(), file
);
268 m_cList
.SetCheck(index
, true);
271 m_cList
.SetColumnWidth(0, LVSCW_AUTOSIZE
);
275 void CImportPatchDlg::OnBnClickedButtonUp()
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)
284 pos
= m_cList
.GetFirstSelectedItemPosition();
288 int index
= m_cList
.GetNextSelectedItem(pos
);
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)
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());
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()
337 pos
= m_cList
.GetFirstSelectedItemPosition();
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()
350 path
.SetFromWin(g_Git
.m_CurrentDir
);
353 UpdateOkCancelText();
354 for (i
= m_CurrentItem
; i
< m_cList
.GetItemCount(); ++i
)
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
));
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
);
374 if(m_cList
.GetCheck(i
))
378 while(path
.HasRebaseApply())
381 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
383 int ret
= CMessageBox::Show(GetSafeHwnd(), IDS_PROC_APPLYPATCH_REBASEDIRFOUND
,
385 1, IDI_ERROR
, IDS_ABORTBUTTON
, IDS_SKIPBUTTON
, IDS_RESOLVEDBUTTON
);
390 cmd
= L
"git.exe am --abort";
393 cmd
= L
"git.exe am --skip";
397 cmd
= L
"git.exe am --resolved";
404 m_bExitThread
= TRUE
;
408 this->AddLogString(cmd
);
410 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
412 this->AddLogString(output
);
413 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL
)));
417 this->AddLogString(CString(MAKEINTRESOURCE(IDS_DONE
)));
424 cmd
= L
"git.exe am ";
426 if(this->m_bAddSignedOffBy
)
427 cmd
+= L
"--signoff ";
432 if(this->m_bIgnoreSpace
)
433 cmd
+= L
"--ignore-space-change ";
436 cmd
+= L
"--keep-cr ";
439 cmd
+= m_cList
.GetItemText(i
,0);
442 this->AddLogString(cmd
);
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
)));
451 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
457 m_cList
.SetItemData(i
, CPatchListCtrl::STATUS_APPLY_SUCCESS
);
458 this->AddLogString(CString(MAKEINTRESOURCE(IDS_SUCCESS
)));
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
));
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
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
);
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();
502 void CImportPatchDlg::OnBnClickedOk()
509 if (!CAppUtils::CheckUserData())
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
);
544 // adjust the minimum size of the dialog to prevent the resizing from
545 // moving the list control too far down.
547 m_cList
.GetClientRect(rcLogMsg
);
548 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_PatchListOrigRect
.Height()+rcLogMsg
.Height()));
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
);
565 LRESULT
CImportPatchDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
569 if (wParam
== IDC_AM_SPLIT
)
571 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
577 return CResizableStandAloneDialog::DefWindowProc(message
, wParam
, lParam
);
580 void CImportPatchDlg::SaveSplitterPos()
584 CRegDWORD
regPos(L
"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer");
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
);
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
);
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
)
632 if (g_Git
.Run(L
"git.exe am --abort", &output
, CP_UTF8
))
633 MessageBox(output
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
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*/
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);
674 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
677 void CImportPatchDlg::OnHdnItemchangedListPatch(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
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
);
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
);
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();