BrowseRefs: Context menu enhancements
[TortoiseGit.git] / src / TortoiseProc / ImportPatchDlg.cpp
blobc0f45448c40d7466b0c3db2dea0ea83961b2848d
1 // ImportPatchDlg.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "TortoiseProc.h"
6 #include "ImportPatchDlg.h"
7 #include "git.h"
9 // CImportPatchDlg dialog
11 IMPLEMENT_DYNAMIC(CImportPatchDlg, CResizableStandAloneDialog)
13 CImportPatchDlg::CImportPatchDlg(CWnd* pParent /*=NULL*/)
14 : CResizableStandAloneDialog(CImportPatchDlg::IDD, pParent)
16 m_cList.m_ContextMenuMask &=~ m_cList.GetMenuMask(CPatchListCtrl::MENU_APPLY);
19 CImportPatchDlg::~CImportPatchDlg()
24 void CImportPatchDlg::DoDataExchange(CDataExchange* pDX)
26 CDialog::DoDataExchange(pDX);
27 DDX_Control(pDX, IDC_LIST_PATCH,m_cList);
30 BOOL CImportPatchDlg::OnInitDialog()
32 CResizableStandAloneDialog::OnInitDialog();
34 AddAnchor(IDC_LIST_PATCH, TOP_LEFT, BOTTOM_RIGHT);
35 AddAnchor(IDC_BUTTON_ADD, TOP_RIGHT);
36 AddAnchor(IDC_BUTTON_UP, TOP_RIGHT);
37 AddAnchor(IDC_BUTTON_DOWN, TOP_RIGHT);
38 AddAnchor(IDC_BUTTON_REMOVE, TOP_RIGHT);
40 AddAnchor(IDOK,BOTTOM_RIGHT);
41 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
43 this->AddOthersToAnchor();
45 m_PathList.SortByPathname(true);
46 m_cList.SetExtendedStyle( m_cList.GetExtendedStyle()| LVS_EX_CHECKBOXES );
48 for(int i=0;i<m_PathList.GetCount();i++)
50 m_cList.InsertItem(0,m_PathList[i].GetWinPath());
51 m_cList.SetCheck(0,true);
56 //CAppUtils::SetListCtrlBackgroundImage(m_cList.GetSafeHwnd(), nID);
58 CString title;
59 this->GetWindowText(title);
60 this->SetWindowText(title+_T(" - ")+g_Git.m_CurrentDir);
61 EnableSaveRestore(_T("ImportDlg"));
63 return TRUE;
66 BEGIN_MESSAGE_MAP(CImportPatchDlg, CResizableStandAloneDialog)
67 ON_LBN_SELCHANGE(IDC_LIST_PATCH, &CImportPatchDlg::OnLbnSelchangeListPatch)
68 ON_BN_CLICKED(IDC_BUTTON_ADD, &CImportPatchDlg::OnBnClickedButtonAdd)
69 ON_BN_CLICKED(IDC_BUTTON_UP, &CImportPatchDlg::OnBnClickedButtonUp)
70 ON_BN_CLICKED(IDC_BUTTON_DOWN, &CImportPatchDlg::OnBnClickedButtonDown)
71 ON_BN_CLICKED(IDC_BUTTON_REMOVE, &CImportPatchDlg::OnBnClickedButtonRemove)
72 ON_BN_CLICKED(IDOK, &CImportPatchDlg::OnBnClickedOk)
73 END_MESSAGE_MAP()
76 // CImportPatchDlg message handlers
78 void CImportPatchDlg::OnLbnSelchangeListPatch()
80 // TODO: Add your control notification handler code here
81 if(m_cList.GetSelectedCount() == 0)
83 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(FALSE);
84 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(FALSE);
85 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(FALSE);
86 }else
88 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(TRUE);
89 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(TRUE);
90 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(TRUE);
96 void CImportPatchDlg::OnBnClickedButtonAdd()
99 CFileDialog dlg(TRUE,NULL,
100 NULL,
101 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
102 _T("Patch Files(*.patch)|*.patch|Diff Files(*.diff)|*.diff|All Files(*.*)|*.*||"));
103 if(dlg.DoModal()==IDOK)
105 POSITION pos;
106 pos=dlg.GetStartPosition();
107 while(pos)
109 CString file=dlg.GetNextPathName(pos);
110 file.Trim();
111 if(!file.IsEmpty())
113 m_cList.InsertItem(0,file);
114 m_cList.SetCheck(0,true);
119 // TODO: Add your control notification handler code here
122 void CImportPatchDlg::OnBnClickedButtonUp()
124 // TODO: Add your control notification handler code here
125 POSITION pos;
126 pos=m_cList.GetFirstSelectedItemPosition();
127 while(pos)
129 int index=m_cList.GetNextSelectedItem(pos);
130 if(index>1)
132 CString old=m_cList.GetItemText(index,0);
133 m_cList.DeleteItem(index);
135 m_cList.InsertItem(index-1,old);
141 void CImportPatchDlg::OnBnClickedButtonDown()
143 // TODO: Add your control notification handler code here
144 POSITION pos;
145 pos=m_cList.GetFirstSelectedItemPosition();
146 while(pos)
148 int index=m_cList.GetNextSelectedItem(pos);
150 CString old=m_cList.GetItemText(index,0);
151 m_cList.DeleteItem(index);
153 m_cList.InsertItem(index+1,old);
158 void CImportPatchDlg::OnBnClickedButtonRemove()
160 // TODO: Add your control notification handler code here
161 POSITION pos;
162 pos=m_cList.GetFirstSelectedItemPosition();
163 while(pos)
165 int index=m_cList.GetNextSelectedItem(pos);
166 m_cList.DeleteItem(index);
167 pos=m_cList.GetFirstSelectedItemPosition();
171 void CImportPatchDlg::OnBnClickedOk()
173 m_PathList.Clear();
175 for(int i=0;i<m_cList.GetItemCount();i++)
177 if(m_cList.GetCheck(i))
179 CTGitPath path;
180 path.SetFromWin(m_cList.GetItemText(i,0));
181 m_PathList.AddPath(path);
184 OnOK();