dropped unused TSVN settings
[TortoiseGit.git] / src / TortoiseProc / ImportPatchDlg.cpp
blob4ff0517f85ac3ae60087efb0905da13149adc709
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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"
29 // CImportPatchDlg dialog
31 IMPLEMENT_DYNAMIC(CImportPatchDlg, CResizableStandAloneDialog)
33 CImportPatchDlg::CImportPatchDlg(CWnd* pParent /*=NULL*/)
34 : CResizableStandAloneDialog(CImportPatchDlg::IDD, pParent)
36 m_cList.m_ContextMenuMask &=~ m_cList.GetMenuMask(CPatchListCtrl::MENU_APPLY);
38 m_CurrentItem =0;
40 m_bExitThread = false;
41 m_bThreadRunning =false;
43 m_b3Way = 1;
44 m_bIgnoreSpace = 1;
45 m_bAddSignedOffBy = FALSE;
46 m_bKeepCR = TRUE;
49 CImportPatchDlg::~CImportPatchDlg()
54 void CImportPatchDlg::DoDataExchange(CDataExchange* pDX)
56 CDialog::DoDataExchange(pDX);
57 DDX_Control(pDX, IDC_LIST_PATCH,m_cList);
58 DDX_Control(pDX, IDC_AM_SPLIT, m_wndSplitter);
59 DDX_Check(pDX, IDC_CHECK_3WAY, m_b3Way);
60 DDX_Check(pDX, IDC_CHECK_IGNORE_SPACE, m_bIgnoreSpace);
61 DDX_Check(pDX, IDC_SIGN_OFF, m_bAddSignedOffBy);
62 DDX_Check(pDX, IDC_KEEP_CR, m_bKeepCR);
65 void CImportPatchDlg::AddAmAnchor()
67 AddAnchor(IDC_AM_TAB,TOP_LEFT,BOTTOM_RIGHT);
68 AddAnchor(IDC_LIST_PATCH, TOP_LEFT, TOP_RIGHT);
69 AddAnchor(IDC_AM_SPLIT, TOP_LEFT, TOP_RIGHT);
70 AddAnchor(IDC_BUTTON_ADD, TOP_RIGHT);
71 AddAnchor(IDC_BUTTON_UP, TOP_RIGHT);
72 AddAnchor(IDC_BUTTON_DOWN, TOP_RIGHT);
73 AddAnchor(IDC_BUTTON_REMOVE, TOP_RIGHT);
75 AddAnchor(IDOK,BOTTOM_RIGHT);
76 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
77 AddAnchor(IDHELP, BOTTOM_RIGHT);
79 AddAnchor(IDC_AM_DUMY_TAB, TOP_LEFT, BOTTOM_RIGHT);
81 this->AddOthersToAnchor();
84 void CImportPatchDlg::SetSplitterRange()
86 if ((m_cList)&&(m_ctrlTabCtrl))
88 CRect rcTop;
89 m_cList.GetWindowRect(rcTop);
90 ScreenToClient(rcTop);
91 CRect rcMiddle;
92 m_ctrlTabCtrl.GetWindowRect(rcMiddle);
93 ScreenToClient(rcMiddle);
94 if (rcMiddle.Height() && rcMiddle.Width())
95 m_wndSplitter.SetRange(rcTop.top+160, rcMiddle.bottom-160);
99 BOOL CImportPatchDlg::OnInitDialog()
101 CResizableStandAloneDialog::OnInitDialog();
102 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
104 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
105 // do this, Explorer would be unable to send that message to our window if we
106 // were running elevated. It's OK to make the call all the time, since if we're
107 // not elevated, this is a no-op.
108 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
109 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
110 HMODULE hUser = ::LoadLibrary(_T("user32.dll"));
111 if (hUser)
113 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
114 if (pfnChangeWindowMessageFilterEx)
116 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
118 FreeLibrary(hUser);
120 m_pTaskbarList.Release();
121 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
123 CRect rectDummy;
125 GetClientRect(m_DlgOrigRect);
126 m_cList.GetClientRect(m_PatchListOrigRect);
128 CWnd *pwnd=this->GetDlgItem(IDC_AM_DUMY_TAB);
129 pwnd->GetWindowRect(&rectDummy);
130 this->ScreenToClient(rectDummy);
132 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_AM_TAB))
134 TRACE0("Failed to create output tab window\n");
135 return FALSE; // fail to create
137 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
138 // Create output panes:
139 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
140 DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
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 dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
153 if (!m_wndOutput.Create(_T("Scintilla"),_T("source"),0,rectDummy, &m_ctrlTabCtrl, 0,0) )
155 TRACE0("Failed to create output windows\n");
156 return -1; // fail to create
158 m_wndOutput.Init(0);
159 m_wndOutput.Call(SCI_SETREADONLY, TRUE);
161 m_tooltips.Create(this);
163 m_tooltips.AddTool(IDC_CHECK_3WAY,IDS_AM_3WAY_TT);
164 m_tooltips.AddTool(IDC_CHECK_IGNORE_SPACE,IDS_AM_IGNORE_SPACE_TT);
166 m_ctrlTabCtrl.AddTab(&m_PatchCtrl,_T("Patch"),0);
167 m_ctrlTabCtrl.AddTab(&m_wndOutput,_T("Log"),1);
169 AddAmAnchor();
171 m_PathList.SortByPathname(true);
172 m_cList.SetExtendedStyle( m_cList.GetExtendedStyle()| LVS_EX_CHECKBOXES );
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);
180 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer"));
181 RECT rcDlg, rcLogMsg, rcFileList;
182 GetClientRect(&rcDlg);
183 m_cList.GetWindowRect(&rcLogMsg);
184 ScreenToClient(&rcLogMsg);
185 this->m_ctrlTabCtrl.GetWindowRect(&rcFileList);
186 ScreenToClient(&rcFileList);
187 if (yPos)
189 RECT rectSplitter;
190 m_wndSplitter.GetWindowRect(&rectSplitter);
191 ScreenToClient(&rectSplitter);
192 int delta = yPos - rectSplitter.top;
193 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
195 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
196 DoSize(delta);
200 CAppUtils::SetListCtrlBackgroundImage(m_cList.GetSafeHwnd(), IDI_IMPORTPATHCES_BKG);
202 CString sWindowTitle;
203 GetWindowText(sWindowTitle);
204 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
206 EnableSaveRestore(_T("ImportDlg"));
208 SetSplitterRange();
210 return TRUE;
213 BEGIN_MESSAGE_MAP(CImportPatchDlg, CResizableStandAloneDialog)
214 ON_LBN_SELCHANGE(IDC_LIST_PATCH, &CImportPatchDlg::OnLbnSelchangeListPatch)
215 ON_BN_CLICKED(IDC_BUTTON_ADD, &CImportPatchDlg::OnBnClickedButtonAdd)
216 ON_BN_CLICKED(IDC_BUTTON_UP, &CImportPatchDlg::OnBnClickedButtonUp)
217 ON_BN_CLICKED(IDC_BUTTON_DOWN, &CImportPatchDlg::OnBnClickedButtonDown)
218 ON_BN_CLICKED(IDC_BUTTON_REMOVE, &CImportPatchDlg::OnBnClickedButtonRemove)
219 ON_BN_CLICKED(IDOK, &CImportPatchDlg::OnBnClickedOk)
220 ON_WM_SIZE()
221 ON_BN_CLICKED(IDCANCEL, &CImportPatchDlg::OnBnClickedCancel)
222 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_PATCH, &CImportPatchDlg::OnHdnItemchangedListPatch)
223 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
224 END_MESSAGE_MAP()
227 // CImportPatchDlg message handlers
229 void CImportPatchDlg::OnLbnSelchangeListPatch()
231 if(m_cList.GetSelectedCount() == 0)
233 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(FALSE);
234 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(FALSE);
235 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(FALSE);
237 else
239 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(TRUE);
240 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(TRUE);
241 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(TRUE);
245 void CImportPatchDlg::OnBnClickedButtonAdd()
247 CFileDialog dlg(TRUE,NULL,
248 NULL,
249 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
250 _T("Patch Files(*.patch)|*.patch|Diff Files(*.diff)|*.diff|All Files(*.*)|*.*||"));
251 if(dlg.DoModal() == IDOK)
253 POSITION pos;
254 pos = dlg.GetStartPosition();
255 while (pos)
257 CString file = dlg.GetNextPathName(pos);
258 file.Trim();
259 if(!file.IsEmpty())
261 int index = m_cList.InsertItem(m_cList.GetItemCount(), file);
262 if (index >= 0)
263 m_cList.SetCheck(index, true);
269 void CImportPatchDlg::OnBnClickedButtonUp()
271 POSITION pos;
272 pos = m_cList.GetFirstSelectedItemPosition();
274 // do nothing if the first selected item is the first item in the list
275 if (m_cList.GetNextSelectedItem(pos) == 0)
276 return;
278 pos = m_cList.GetFirstSelectedItemPosition();
280 while (pos)
282 int index = m_cList.GetNextSelectedItem(pos);
283 if(index >= 1)
285 CString old = m_cList.GetItemText(index, 0);
286 BOOL oldState = m_cList.GetCheck(index);
287 m_cList.DeleteItem(index);
288 m_cList.InsertItem(index - 1, old);
289 m_cList.SetCheck(index - 1, oldState);
290 m_cList.SetItemState(index - 1, LVIS_SELECTED, LVIS_SELECTED);
291 m_cList.SetItemState(index, 0, LVIS_SELECTED);
297 void CImportPatchDlg::OnBnClickedButtonDown()
299 if (m_cList.GetSelectedCount() == 0)
300 return;
302 POSITION pos;
303 pos = m_cList.GetFirstSelectedItemPosition();
304 // use an array to store all selected item indexes; the user won't select too much items
305 int* indexes = NULL;
306 indexes = new int[m_cList.GetSelectedCount()];
307 int i = 0;
308 while(pos)
310 indexes[i++] = m_cList.GetNextSelectedItem(pos);
313 // don't move any item if the last selected item is the last item in the m_CommitList
314 // (that would change the order of the selected items)
315 if(indexes[m_cList.GetSelectedCount() - 1] < m_cList.GetItemCount() - 1)
317 // iterate over the indexes backwards in order to correctly move multiselected items
318 for (i = m_cList.GetSelectedCount() - 1; i >= 0; i--)
320 int index = indexes[i];
321 CString old = m_cList.GetItemText(index, 0);
322 BOOL oldState = m_cList.GetCheck(index);
323 m_cList.DeleteItem(index);
324 m_cList.InsertItem(index + 1, old);
325 m_cList.SetCheck(index + 1, oldState);
326 m_cList.SetItemState(index + 1, LVIS_SELECTED, LVIS_SELECTED);
327 m_cList.SetItemState(index, 0, LVIS_SELECTED);
330 delete [] indexes;
331 indexes = NULL;
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();
346 UINT CImportPatchDlg::PatchThread()
348 CTGitPath path;
349 path.SetFromWin(g_Git.m_CurrentDir);
351 int i=0;
353 for(i=m_CurrentItem;i<m_cList.GetItemCount();i++)
355 if (m_pTaskbarList)
357 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
358 m_pTaskbarList->SetProgressValue(m_hWnd, i + 1, m_cList.GetItemCount());
361 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLYING|m_cList.GetItemData(i));
363 if(m_bExitThread)
364 break;
366 if(m_cList.GetCheck(i))
368 CString cmd;
370 while(path.HasRebaseApply())
372 if (m_pTaskbarList)
373 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
375 int ret = CMessageBox::Show(NULL, _T("<ct=0x0000FF>previous rebase directory rebase-apply still exists but mbox given</ct>\n\n Do you want to"),
376 _T("TortoiseGit"),
377 1,IDI_ERROR ,_T("&Abort"), _T("&Skip"),_T("&Resolved"));
379 switch(ret)
381 case 1:
382 cmd = _T("git.exe am --abort");
383 break;
384 case 2:
385 cmd = _T("git.exe am --skip");
386 i++;
387 break;
388 case 3:
389 cmd = _T("git.exe am --resolved");
390 break;
391 default:
392 cmd.Empty();
394 if(cmd.IsEmpty())
396 m_bExitThread = TRUE;
397 break;
400 this->AddLogString(cmd);
401 CString output;
402 if(g_Git.Run(cmd, &output, CP_ACP))
404 this->AddLogString(output);
405 this->AddLogString(_T("Fail"));
407 else
409 this->AddLogString(_T("Done"));
413 if(m_bExitThread)
414 break;
416 cmd = _T("git.exe am ");
418 if(this->m_bAddSignedOffBy)
419 cmd += _T("--signoff ");
421 if(this->m_b3Way)
422 cmd += _T("--3way ");
424 if(this->m_bIgnoreSpace)
425 cmd += _T("--ignore-space-change ");
427 if(this->m_bKeepCR)
428 cmd += _T("--keep-cr ");
430 cmd += _T("\"");
431 cmd += m_cList.GetItemText(i,0);
432 cmd += _T("\"");
434 this->AddLogString(cmd);
435 CString output;
436 if(g_Git.Run(cmd,&output,CP_ACP))
438 //keep STATUS_APPLYING to let user retry failed patch
439 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_FAIL|CPatchListCtrl::STATUS_APPLYING);
440 this->AddLogString(output);
441 this->AddLogString(_T("Fail"));
442 if (m_pTaskbarList)
443 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
444 break;
447 else
449 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SUCCESS);
450 this->AddLogString(_T("Success"));
454 else
456 AddLogString(CString(_T("Skip Patch: "))+m_cList.GetItemText(i,0));
457 m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SKIP);
460 m_cList.SetItemData(m_CurrentItem, (~CPatchListCtrl::STATUS_APPLYING)&m_cList.GetItemData(i));
461 m_CurrentItem++;
462 m_cList.SetItemData(m_CurrentItem, CPatchListCtrl::STATUS_APPLYING|m_cList.GetItemData(i));
464 CRect rect;
465 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
466 this->m_cList.InvalidateRect(rect);
468 this->m_cList.GetItemRect(m_CurrentItem,&rect,LVIR_BOUNDS);
469 this->m_cList.InvalidateRect(rect);
471 if (m_pTaskbarList)
472 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
474 UpdateOkCancelText();
477 //in case am fail, need refresh finial item status
478 CRect rect;
479 this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS);
480 this->m_cList.InvalidateRect(rect);
482 this->m_cList.GetItemRect(m_CurrentItem,&rect,LVIR_BOUNDS);
483 this->m_cList.InvalidateRect(rect);
485 EnableInputCtrl(true);
486 InterlockedExchange(&m_bThreadRunning, FALSE);
487 UpdateOkCancelText();
488 return 0;
491 void CImportPatchDlg::OnBnClickedOk()
493 m_PathList.Clear();
494 this->UpdateData();
496 SaveSplitterPos();
498 if(IsFinish())
500 this->OnOK();
501 return;
504 m_ctrlTabCtrl.SetActiveTab(1);
506 EnableInputCtrl(false);
507 InterlockedExchange(&m_bThreadRunning, TRUE);
508 InterlockedExchange(&this->m_bExitThread, FALSE);
509 if ( (m_LoadingThread=AfxBeginThread(ThreadEntry, this)) ==NULL)
511 InterlockedExchange(&m_bThreadRunning, FALSE);
512 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
517 void CImportPatchDlg::DoSize(int delta)
519 this->RemoveAllAnchors();
521 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LIST_PATCH), delta, CW_TOPALIGN);
522 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
523 CSplitterControl::ChangeHeight(GetDlgItem(IDC_AM_TAB), -delta, CW_BOTTOMALIGN);
524 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
525 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_3WAY), 0, delta);
526 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_IGNORE_SPACE), 0, delta);
527 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGN_OFF), 0, delta);
528 CSplitterControl::ChangePos(GetDlgItem(IDC_KEEP_CR), 0, delta);
530 this->AddAmAnchor();
531 // adjust the minimum size of the dialog to prevent the resizing from
532 // moving the list control too far down.
533 CRect rcLogMsg;
534 m_cList.GetClientRect(rcLogMsg);
535 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_PatchListOrigRect.Height()+rcLogMsg.Height()));
537 SetSplitterRange();
538 // m_CommitList.Invalidate();
540 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
542 this->m_ctrlTabCtrl.Invalidate();
545 void CImportPatchDlg::OnSize(UINT nType, int cx, int cy)
547 CResizableStandAloneDialog::OnSize(nType, cx, cy);
549 SetSplitterRange();
552 LRESULT CImportPatchDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
554 switch (message) {
555 case WM_NOTIFY:
556 if (wParam == IDC_AM_SPLIT)
558 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
559 DoSize(pHdr->delta);
561 break;
564 return CResizableStandAloneDialog::DefWindowProc(message, wParam, lParam);
567 void CImportPatchDlg::SaveSplitterPos()
569 if (!IsIconic())
571 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\AMDlgSizer"));
572 RECT rectSplitter;
573 m_wndSplitter.GetWindowRect(&rectSplitter);
574 ScreenToClient(&rectSplitter);
575 regPos = rectSplitter.top;
581 void CImportPatchDlg::EnableInputCtrl(BOOL b)
583 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(b);
584 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(b);
585 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(b);
586 this->GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(b);
587 this->GetDlgItem(IDOK)->EnableWindow(b);
590 void CImportPatchDlg::UpdateOkCancelText()
592 if( !IsFinish() )
594 this->GetDlgItem(IDOK)->SetWindowText(_T("&Apply"));
596 else
598 this->GetDlgItem(IDOK)->SetWindowText(_T("&OK"));
601 if(this->m_bThreadRunning)
602 this->GetDlgItem(IDCANCEL)->SetWindowText(_T("A&bort"));
603 else
604 this->GetDlgItem(IDCANCEL)->SetWindowText(_T("&Cancel"));
607 void CImportPatchDlg::OnBnClickedCancel()
609 if(this->m_bThreadRunning)
611 InterlockedExchange(&m_bExitThread,TRUE);
613 else
614 OnCancel();
617 void CImportPatchDlg::AddLogString(CString str)
619 this->m_wndOutput.SendMessage(SCI_SETREADONLY, FALSE);
620 CStringA sTextA = m_wndOutput.StringForControl(str);//CUnicodeUtils::GetUTF8(str);
621 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)sTextA);
622 this->m_wndOutput.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n");
623 this->m_wndOutput.SendMessage(SCI_SETREADONLY, TRUE);
624 //this->m_wndOutput.SendMessage(SCI_LINESCROLL,0,0x7FFFFFFF);
626 BOOL CImportPatchDlg::PreTranslateMessage(MSG* pMsg)
628 if (pMsg->message == WM_KEYDOWN)
630 switch (pMsg->wParam)
633 /* Avoid TAB control destroy but dialog exist*/
634 case VK_ESCAPE:
635 case VK_CANCEL:
637 TCHAR buff[128];
638 ::GetClassName(pMsg->hwnd,buff,128);
640 if(_tcsnicmp(buff,_T("RichEdit20W"),128)==0 ||
641 _tcsnicmp(buff,_T("Scintilla"),128)==0 ||
642 _tcsnicmp(buff,_T("SysListView32"),128)==0||
643 ::GetParent(pMsg->hwnd) == this->m_ctrlTabCtrl.m_hWnd)
645 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
646 return TRUE;
651 m_tooltips.RelayEvent(pMsg);
652 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
655 void CImportPatchDlg::OnHdnItemchangedListPatch(NMHDR * /*pNMHDR*/, LRESULT *pResult)
657 *pResult = 0;
659 if(this->m_cList.GetSelectedCount() != 1)
661 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
662 m_PatchCtrl.SetText(CString());
663 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
665 else
667 CString text;
669 POSITION pos;
670 pos = m_cList.GetFirstSelectedItemPosition();
671 int selected = m_cList.GetNextSelectedItem(pos);
673 if(selected>=0&& selected< m_cList.GetItemCount())
675 CString str = m_cList.GetItemText(selected,0);
676 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
677 m_PatchCtrl.SetText(text);
678 m_PatchCtrl.LoadFromFile(str);
679 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
682 else
684 m_PatchCtrl.SendMessage(SCI_SETREADONLY, FALSE);
685 m_PatchCtrl.SetText(text);
686 m_PatchCtrl.SendMessage(SCI_SETREADONLY, TRUE);
691 LRESULT CImportPatchDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
693 m_pTaskbarList.Release();
694 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
695 return 0;