1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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_cList
.m_ContextMenuMask
&=~ m_cList
.GetMenuMask(CPatchListCtrl::MENU_APPLY
);
43 m_bExitThread
= false;
44 m_bThreadRunning
=false;
48 m_bAddSignedOffBy
= FALSE
;
52 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
))
91 m_cList
.GetWindowRect(rcTop
);
92 ScreenToClient(rcTop
);
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(L
"user32.dll");
115 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
116 if (pfnChangeWindowMessageFilterEx
)
118 pfnChangeWindowMessageFilterEx(m_hWnd
, TaskBarButtonCreated
, MSGFLT_ALLOW
, &cfs
);
121 m_pTaskbarList
.Release();
122 if (FAILED(m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
)))
123 m_pTaskbarList
= nullptr;
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 (!m_PatchCtrl
.Create(L
"Scintilla", L
"source", 0, rectDummy
, &m_ctrlTabCtrl
, 0, 0))
144 TRACE0("Failed to create log message control");
147 m_PatchCtrl
.Init(-1);
148 m_PatchCtrl
.Call(SCI_SETREADONLY
, TRUE
);
149 m_PatchCtrl
.SetUDiffStyle();
151 if (!m_wndOutput
.Create(L
"Scintilla", L
"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);
157 m_wndOutput
.Call(SCI_SETREADONLY
, TRUE
);
159 m_tooltips
.AddTool(IDC_CHECK_3WAY
,IDS_AM_3WAY_TT
);
160 m_tooltips
.AddTool(IDC_CHECK_IGNORE_SPACE
,IDS_AM_IGNORE_SPACE_TT
);
162 m_ctrlTabCtrl
.AddTab(&m_PatchCtrl
, CString(MAKEINTRESOURCE(IDS_PATCH
)), 0);
163 m_ctrlTabCtrl
.AddTab(&m_wndOutput
, CString(MAKEINTRESOURCE(IDS_LOG
)), 1);
166 AdjustControlSize(IDC_CHECK_3WAY
);
167 AdjustControlSize(IDC_CHECK_IGNORE_SPACE
);
168 AdjustControlSize(IDC_SIGN_OFF
);
169 AdjustControlSize(IDC_KEEP_CR
);
171 m_PathList
.SortByPathname(true);
172 m_cList
.SetExtendedStyle( m_cList
.GetExtendedStyle()| LVS_EX_CHECKBOXES
);
173 m_cList
.InsertColumn(0, L
"");
174 m_cList
.SetExtendedStyle((CRegDWORD(L
"Software\\TortoiseGit\\FullRowSelect", TRUE
) ? LVS_EX_FULLROWSELECT
: 0) | m_cList
.GetExtendedStyle());
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(L
"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
);
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(nullptr, 0, yPos
, 0, 0, SWP_NOSIZE
);
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(L
"ImportDlg");
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
)
224 ON_WM_SYSCOLORCHANGE()
226 ON_BN_CLICKED(IDCANCEL
, &CImportPatchDlg::OnBnClickedCancel
)
227 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_LIST_PATCH
, &CImportPatchDlg::OnHdnItemchangedListPatch
)
228 ON_REGISTERED_MESSAGE(TaskBarButtonCreated
, OnTaskbarBtnCreated
)
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
);
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
, nullptr, nullptr, OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
| OFN_ALLOWMULTISELECT
, CString(MAKEINTRESOURCE(IDS_PATCHFILEFILTER
)));
253 dlg
.m_ofn
.nMaxFile
= 65536;
254 TCHAR path
[65536] = { 0 };
255 dlg
.m_ofn
.lpstrFile
= path
;
256 INT_PTR ret
= dlg
.DoModal();
257 SetCurrentDirectory(g_Git
.m_CurrentDir
);
261 pos
= dlg
.GetStartPosition();
264 CString file
= dlg
.GetNextPathName(pos
);
268 int index
= m_cList
.InsertItem(m_cList
.GetItemCount(), file
);
270 m_cList
.SetCheck(index
, true);
273 m_cList
.SetColumnWidth(0, LVSCW_AUTOSIZE
);
277 void CImportPatchDlg::OnBnClickedButtonUp()
280 pos
= m_cList
.GetFirstSelectedItemPosition();
282 // do nothing if the first selected item is the first item in the list
283 if (m_cList
.GetNextSelectedItem(pos
) == 0)
286 pos
= m_cList
.GetFirstSelectedItemPosition();
290 int index
= m_cList
.GetNextSelectedItem(pos
);
293 CString old
= m_cList
.GetItemText(index
, 0);
294 BOOL oldState
= m_cList
.GetCheck(index
);
295 m_cList
.DeleteItem(index
);
296 m_cList
.InsertItem(index
- 1, old
);
297 m_cList
.SetCheck(index
- 1, oldState
);
298 m_cList
.SetItemState(index
- 1, LVIS_SELECTED
, LVIS_SELECTED
);
299 m_cList
.SetItemState(index
, 0, LVIS_SELECTED
);
304 void CImportPatchDlg::OnBnClickedButtonDown()
306 if (m_cList
.GetSelectedCount() == 0)
310 pos
= m_cList
.GetFirstSelectedItemPosition();
311 // use an array to store all selected item indexes; the user won't select too much items
312 auto indexes
= std::make_unique
<int[]>(m_cList
.GetSelectedCount());
315 indexes
[i
++] = m_cList
.GetNextSelectedItem(pos
);
317 // don't move any item if the last selected item is the last item in the m_CommitList
318 // (that would change the order of the selected items)
319 if(indexes
[m_cList
.GetSelectedCount() - 1] < m_cList
.GetItemCount() - 1)
321 // iterate over the indexes backwards in order to correctly move multiselected items
322 for (i
= m_cList
.GetSelectedCount() - 1; i
>= 0; i
--)
324 int index
= indexes
[i
];
325 CString old
= m_cList
.GetItemText(index
, 0);
326 BOOL oldState
= m_cList
.GetCheck(index
);
327 m_cList
.DeleteItem(index
);
328 m_cList
.InsertItem(index
+ 1, old
);
329 m_cList
.SetCheck(index
+ 1, oldState
);
330 m_cList
.SetItemState(index
+ 1, LVIS_SELECTED
, LVIS_SELECTED
);
331 m_cList
.SetItemState(index
, 0, LVIS_SELECTED
);
336 void CImportPatchDlg::OnBnClickedButtonRemove()
339 pos
= m_cList
.GetFirstSelectedItemPosition();
342 int index
= m_cList
.GetNextSelectedItem(pos
);
343 m_cList
.DeleteItem(index
);
344 pos
= m_cList
.GetFirstSelectedItemPosition();
346 m_cList
.SetColumnWidth(0, LVSCW_AUTOSIZE
);
349 UINT
CImportPatchDlg::PatchThread()
352 path
.SetFromWin(g_Git
.m_CurrentDir
);
355 UpdateOkCancelText();
356 for (i
= m_CurrentItem
; i
< m_cList
.GetItemCount(); ++i
)
360 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
361 m_pTaskbarList
->SetProgressValue(m_hWnd
, i
, m_cList
.GetItemCount());
364 m_cList
.SetItemData(i
, CPatchListCtrl::STATUS_APPLYING
|m_cList
.GetItemData(i
));
367 this->m_cList
.GetItemRect(i
,&rect
,LVIR_BOUNDS
);
368 this->m_cList
.InvalidateRect(rect
);
370 m_cList
.SetColumnWidth(0, LVSCW_AUTOSIZE
);
371 m_cList
.EnsureVisible(i
, FALSE
);
376 if(m_cList
.GetCheck(i
))
380 while(path
.HasRebaseApply())
383 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
385 int ret
= CMessageBox::Show(GetSafeHwnd(), IDS_PROC_APPLYPATCH_REBASEDIRFOUND
,
387 1, IDI_ERROR
, IDS_ABORTBUTTON
, IDS_SKIPBUTTON
, IDS_RESOLVEDBUTTON
);
392 cmd
= L
"git.exe am --abort";
395 cmd
= L
"git.exe am --skip";
399 cmd
= L
"git.exe am --resolved";
406 m_bExitThread
= TRUE
;
410 this->AddLogString(cmd
);
412 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
414 this->AddLogString(output
);
415 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL
)));
419 this->AddLogString(CString(MAKEINTRESOURCE(IDS_DONE
)));
426 cmd
= L
"git.exe am ";
428 if(this->m_bAddSignedOffBy
)
429 cmd
+= L
"--signoff ";
434 if(this->m_bIgnoreSpace
)
435 cmd
+= L
"--ignore-space-change ";
438 cmd
+= L
"--keep-cr ";
441 cmd
+= m_cList
.GetItemText(i
,0);
444 this->AddLogString(cmd
);
446 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
448 //keep STATUS_APPLYING to let user retry failed patch
449 m_cList
.SetItemData(i
, CPatchListCtrl::STATUS_APPLY_FAIL
|CPatchListCtrl::STATUS_APPLYING
);
450 this->AddLogString(output
);
451 this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL
)));
453 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
459 m_cList
.SetItemData(i
, CPatchListCtrl::STATUS_APPLY_SUCCESS
);
460 this->AddLogString(CString(MAKEINTRESOURCE(IDS_SUCCESS
)));
467 sMessage
.Format(IDS_PROC_SKIPPATCH
, (LPCTSTR
)m_cList
.GetItemText(i
, 0));
468 AddLogString(sMessage
);
469 m_cList
.SetItemData(i
, CPatchListCtrl::STATUS_APPLY_SKIP
);
472 m_cList
.SetItemData(m_CurrentItem
, (~CPatchListCtrl::STATUS_APPLYING
)&m_cList
.GetItemData(i
));
475 this->m_cList
.GetItemRect(i
,&rect
,LVIR_BOUNDS
);
476 this->m_cList
.InvalidateRect(rect
);
478 UpdateOkCancelText();
481 //in case am fail, need refresh finial item status
483 this->m_cList
.GetItemRect(i
,&rect
,LVIR_BOUNDS
);
484 this->m_cList
.InvalidateRect(rect
);
486 this->m_cList
.GetItemRect(m_CurrentItem
,&rect
,LVIR_BOUNDS
);
487 this->m_cList
.InvalidateRect(rect
);
491 m_pTaskbarList
->SetProgressValue(m_hWnd
, m_CurrentItem
, m_cList
.GetItemCount());
492 if (m_bExitThread
&& m_CurrentItem
!= m_cList
.GetItemCount())
493 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
494 else if (!m_bExitThread
&& m_CurrentItem
== m_cList
.GetItemCount())
495 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
498 EnableInputCtrl(true);
499 InterlockedExchange(&m_bThreadRunning
, FALSE
);
500 UpdateOkCancelText();
504 void CImportPatchDlg::OnBnClickedOk()
517 m_ctrlTabCtrl
.SetActiveTab(1);
519 EnableInputCtrl(false);
520 InterlockedExchange(&m_bThreadRunning
, TRUE
);
521 InterlockedExchange(&this->m_bExitThread
, FALSE
);
522 if ((m_LoadingThread
= AfxBeginThread(ThreadEntry
, this)) == nullptr)
524 InterlockedExchange(&m_bThreadRunning
, FALSE
);
525 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
529 void CImportPatchDlg::DoSize(int delta
)
531 this->RemoveAllAnchors();
533 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LIST_PATCH
), delta
, CW_TOPALIGN
);
534 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
535 CSplitterControl::ChangeHeight(GetDlgItem(IDC_AM_TAB
), -delta
, CW_BOTTOMALIGN
);
536 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
537 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_3WAY
), 0, delta
);
538 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_IGNORE_SPACE
), 0, delta
);
539 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGN_OFF
), 0, delta
);
540 CSplitterControl::ChangePos(GetDlgItem(IDC_KEEP_CR
), 0, delta
);
543 // adjust the minimum size of the dialog to prevent the resizing from
544 // moving the list control too far down.
546 m_cList
.GetClientRect(rcLogMsg
);
547 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_PatchListOrigRect
.Height()+rcLogMsg
.Height()));
550 // m_CommitList.Invalidate();
552 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
554 this->m_ctrlTabCtrl
.Invalidate();
557 void CImportPatchDlg::OnSize(UINT nType
, int cx
, int cy
)
559 CResizableStandAloneDialog::OnSize(nType
, cx
, cy
);
564 LRESULT
CImportPatchDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
568 if (wParam
== IDC_AM_SPLIT
)
570 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
576 return CResizableStandAloneDialog::DefWindowProc(message
, wParam
, lParam
);
579 void CImportPatchDlg::SaveSplitterPos()
583 CRegDWORD
regPos(L
"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer");
585 m_wndSplitter
.GetWindowRect(&rectSplitter
);
586 ScreenToClient(&rectSplitter
);
587 regPos
= rectSplitter
.top
;
591 void CImportPatchDlg::EnableInputCtrl(BOOL b
)
593 this->GetDlgItem(IDC_BUTTON_UP
)->EnableWindow(b
);
594 this->GetDlgItem(IDC_BUTTON_DOWN
)->EnableWindow(b
);
595 this->GetDlgItem(IDC_BUTTON_REMOVE
)->EnableWindow(b
);
596 this->GetDlgItem(IDC_BUTTON_ADD
)->EnableWindow(b
);
597 this->GetDlgItem(IDOK
)->EnableWindow(b
);
600 void CImportPatchDlg::UpdateOkCancelText()
602 if (this->m_bThreadRunning
&& !IsFinish())
604 this->GetDlgItem(IDOK
)->EnableWindow(FALSE
);
605 this->GetDlgItem(IDCANCEL
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
)));
607 else if (!IsFinish())
609 this->GetDlgItem(IDOK
)->EnableWindow(TRUE
);
613 this->GetDlgItem(IDCANCEL
)->EnableWindow(FALSE
);
614 this->GetDlgItem(IDOK
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_OKBUTTON
)));
617 void CImportPatchDlg::OnBnClickedCancel()
619 if(this->m_bThreadRunning
)
621 InterlockedExchange(&m_bExitThread
,TRUE
);
626 path
.SetFromWin(g_Git
.m_CurrentDir
);
627 if(path
.HasRebaseApply())
628 if (CMessageBox::Show(GetSafeHwnd(), IDS_PROC_APPLYPATCH_GITAMACTIVE
, IDS_APPNAME
, MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
631 if (g_Git
.Run(L
"git.exe am --abort", &output
, CP_UTF8
))
632 MessageBox(output
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
638 void CImportPatchDlg::AddLogString(CString str
)
640 this->m_wndOutput
.SendMessage(SCI_SETREADONLY
, FALSE
);
641 CStringA sTextA
= m_wndOutput
.StringForControl(str
);//CUnicodeUtils::GetUTF8(str);
642 this->m_wndOutput
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)sTextA
);
643 this->m_wndOutput
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n");
644 this->m_wndOutput
.SendMessage(SCI_SETREADONLY
, TRUE
);
645 //this->m_wndOutput.SendMessage(SCI_LINESCROLL,0,0x7FFFFFFF);
647 BOOL
CImportPatchDlg::PreTranslateMessage(MSG
* pMsg
)
649 if (pMsg
->message
== WM_KEYDOWN
)
651 switch (pMsg
->wParam
)
653 /* Avoid TAB control destroy but dialog exist*/
657 TCHAR buff
[128] = { 0 };
658 ::GetClassName(pMsg
->hwnd
,buff
,128);
660 /* Use MSFTEDIT_CLASS http://msdn.microsoft.com/en-us/library/bb531344.aspx */
661 if (_wcsnicmp(buff
, MSFTEDIT_CLASS
, 128) == 0 || //Unicode and MFC 2012 and later
662 _wcsnicmp(buff
, RICHEDIT_CLASS
, 128) == 0 || //ANSI or MFC 2010
663 _wcsnicmp(buff
, L
"Scintilla", 128) == 0 ||
664 _wcsnicmp(buff
, L
"SysListView32", 128) == 0 ||
665 ::GetParent(pMsg
->hwnd
) == this->m_ctrlTabCtrl
.m_hWnd
)
667 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
673 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
676 void CImportPatchDlg::OnHdnItemchangedListPatch(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
680 if(this->m_cList
.GetSelectedCount() != 1)
682 m_PatchCtrl
.SendMessage(SCI_SETREADONLY
, FALSE
);
683 m_PatchCtrl
.SetText(CString());
684 m_PatchCtrl
.SendMessage(SCI_SETREADONLY
, TRUE
);
691 pos
= m_cList
.GetFirstSelectedItemPosition();
692 int selected
= m_cList
.GetNextSelectedItem(pos
);
694 if(selected
>=0&& selected
< m_cList
.GetItemCount())
696 CString str
= m_cList
.GetItemText(selected
,0);
697 m_PatchCtrl
.SendMessage(SCI_SETREADONLY
, FALSE
);
698 m_PatchCtrl
.SetText(text
);
699 m_PatchCtrl
.LoadFromFile(str
);
700 m_PatchCtrl
.SendMessage(SCI_SETREADONLY
, TRUE
);
705 m_PatchCtrl
.SendMessage(SCI_SETREADONLY
, FALSE
);
706 m_PatchCtrl
.SetText(text
);
707 m_PatchCtrl
.SendMessage(SCI_SETREADONLY
, TRUE
);
712 LRESULT
CImportPatchDlg::OnTaskbarBtnCreated(WPARAM wParam
, LPARAM lParam
)
714 m_pTaskbarList
.Release();
715 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
716 return __super::OnTaskbarButtonCreated(wParam
, lParam
);
719 void CImportPatchDlg::OnSysColorChange()
721 __super::OnSysColorChange();
722 m_PatchCtrl
.SetUDiffStyle();
723 m_wndOutput
.SetColors(true);
724 CAppUtils::SetListCtrlBackgroundImage(m_cList
.GetSafeHwnd(), IDI_IMPORTPATHCES_BKG
);
727 LRESULT
CImportPatchDlg::OnThemeChanged()
729 CMFCVisualManager::GetInstance()->DestroyInstance();