OSDN Git Service

Only apply checked patch
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / ImportPatchDlg.cpp
1 // ImportPatchDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "ImportPatchDlg.h"\r
7 #include "git.h"\r
8 \r
9 // CImportPatchDlg dialog\r
10 \r
11 IMPLEMENT_DYNAMIC(CImportPatchDlg, CResizableStandAloneDialog)\r
12 \r
13 CImportPatchDlg::CImportPatchDlg(CWnd* pParent /*=NULL*/)\r
14         : CResizableStandAloneDialog(CImportPatchDlg::IDD, pParent)\r
15 {\r
16         m_cList.m_ContextMenuMask &=~ m_cList.GetMenuMask(CPatchListCtrl::MENU_APPLY);\r
17 }\r
18 \r
19 CImportPatchDlg::~CImportPatchDlg()\r
20 {\r
21 \r
22 }\r
23 \r
24 void CImportPatchDlg::DoDataExchange(CDataExchange* pDX)\r
25 {\r
26         CDialog::DoDataExchange(pDX);\r
27         DDX_Control(pDX, IDC_LIST_PATCH,m_cList);\r
28 }\r
29 \r
30 BOOL CImportPatchDlg::OnInitDialog()\r
31 {\r
32         CResizableStandAloneDialog::OnInitDialog();\r
33 \r
34         AddAnchor(IDC_LIST_PATCH, TOP_LEFT, BOTTOM_RIGHT);\r
35         AddAnchor(IDC_BUTTON_ADD, TOP_RIGHT);\r
36         AddAnchor(IDC_BUTTON_UP, TOP_RIGHT);\r
37         AddAnchor(IDC_BUTTON_DOWN, TOP_RIGHT);\r
38         AddAnchor(IDC_BUTTON_REMOVE, TOP_RIGHT);\r
39 \r
40         AddAnchor(IDOK,BOTTOM_RIGHT);\r
41         AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
42 \r
43         this->AddOthersToAnchor();\r
44 \r
45         m_PathList.SortByPathname(true);\r
46         m_cList.SetExtendedStyle( m_cList.GetExtendedStyle()| LVS_EX_CHECKBOXES );\r
47 \r
48         for(int i=0;i<m_PathList.GetCount();i++)\r
49         {\r
50                 m_cList.InsertItem(0,m_PathList[i].GetWinPath());\r
51                 m_cList.SetCheck(0,true);\r
52         }\r
53 \r
54         \r
55 \r
56         //CAppUtils::SetListCtrlBackgroundImage(m_cList.GetSafeHwnd(), nID);\r
57 \r
58         CString title;\r
59         this->GetWindowText(title);\r
60         this->SetWindowText(title+_T(" - ")+g_Git.m_CurrentDir);\r
61         EnableSaveRestore(_T("ImportDlg"));\r
62 \r
63         return TRUE;\r
64 }\r
65 \r
66 BEGIN_MESSAGE_MAP(CImportPatchDlg, CResizableStandAloneDialog)\r
67         ON_LBN_SELCHANGE(IDC_LIST_PATCH, &CImportPatchDlg::OnLbnSelchangeListPatch)\r
68         ON_BN_CLICKED(IDC_BUTTON_ADD, &CImportPatchDlg::OnBnClickedButtonAdd)\r
69         ON_BN_CLICKED(IDC_BUTTON_UP, &CImportPatchDlg::OnBnClickedButtonUp)\r
70         ON_BN_CLICKED(IDC_BUTTON_DOWN, &CImportPatchDlg::OnBnClickedButtonDown)\r
71         ON_BN_CLICKED(IDC_BUTTON_REMOVE, &CImportPatchDlg::OnBnClickedButtonRemove)\r
72         ON_BN_CLICKED(IDOK, &CImportPatchDlg::OnBnClickedOk)\r
73 END_MESSAGE_MAP()\r
74 \r
75 \r
76 // CImportPatchDlg message handlers\r
77 \r
78 void CImportPatchDlg::OnLbnSelchangeListPatch()\r
79 {\r
80         // TODO: Add your control notification handler code here\r
81         if(m_cList.GetSelectedCount() == 0)\r
82         {\r
83                 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(FALSE);\r
84                 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(FALSE);\r
85                 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(FALSE);\r
86         }else\r
87         {\r
88                 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(TRUE);\r
89                 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(TRUE);\r
90                 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(TRUE);\r
91 \r
92         }\r
93 \r
94 }\r
95 \r
96 void CImportPatchDlg::OnBnClickedButtonAdd()\r
97 {\r
98         \r
99         CFileDialog dlg(TRUE,NULL,\r
100                                         NULL,\r
101                                         OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,\r
102                                         _T("Patch Files(*.patch)|*.patch|Diff Files(*.diff)|*.diff|All Files(*.*)|*.*||"));\r
103         if(dlg.DoModal()==IDOK)\r
104         {\r
105                 POSITION pos;\r
106                 pos=dlg.GetStartPosition();\r
107                 while(pos)\r
108                 {\r
109                         CString file=dlg.GetNextPathName(pos);\r
110                         file.Trim();\r
111                         if(!file.IsEmpty())\r
112                         {\r
113                                 m_cList.InsertItem(0,file);\r
114                                 m_cList.SetCheck(0,true);\r
115                         }\r
116                 }\r
117         }\r
118 \r
119         // TODO: Add your control notification handler code here\r
120 }\r
121 \r
122 void CImportPatchDlg::OnBnClickedButtonUp()\r
123 {\r
124         // TODO: Add your control notification handler code here\r
125         POSITION pos;\r
126         pos=m_cList.GetFirstSelectedItemPosition();\r
127         while(pos)\r
128         {\r
129                 int index=m_cList.GetNextSelectedItem(pos);\r
130                 if(index>1)\r
131                 {\r
132                         CString old=m_cList.GetItemText(index,0);\r
133                         m_cList.DeleteItem(index);\r
134 \r
135                         m_cList.InsertItem(index-1,old);\r
136                 }\r
137         }\r
138 \r
139 }\r
140 \r
141 void CImportPatchDlg::OnBnClickedButtonDown()\r
142 {\r
143         // TODO: Add your control notification handler code here\r
144         POSITION pos;\r
145         pos=m_cList.GetFirstSelectedItemPosition();\r
146         while(pos)\r
147         {\r
148                 int index=m_cList.GetNextSelectedItem(pos);\r
149                 \r
150                 CString old=m_cList.GetItemText(index,0);\r
151                 m_cList.DeleteItem(index);\r
152 \r
153                 m_cList.InsertItem(index+1,old);\r
154                 \r
155         }\r
156 }\r
157 \r
158 void CImportPatchDlg::OnBnClickedButtonRemove()\r
159 {\r
160         // TODO: Add your control notification handler code here\r
161         POSITION pos;\r
162         pos=m_cList.GetFirstSelectedItemPosition();\r
163         while(pos)\r
164         {\r
165                 int index=m_cList.GetNextSelectedItem(pos);\r
166                 m_cList.DeleteItem(index);\r
167                 pos=m_cList.GetFirstSelectedItemPosition();\r
168         }\r
169 }\r
170 \r
171 void CImportPatchDlg::OnBnClickedOk()\r
172 {\r
173         m_PathList.Clear();\r
174 \r
175         for(int i=0;i<m_cList.GetItemCount();i++)\r
176         {\r
177                 if(m_cList.GetCheck(i))\r
178                 {\r
179                         CTGitPath path;\r
180                         path.SetFromWin(m_cList.GetItemText(i,0));\r
181                         m_PathList.AddPath(path);\r
182                 }\r
183         }\r
184         OnOK();\r
185 }\r