OSDN Git Service

Correct Handle case when patch file is not in repository path.
[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 \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 \r
47         for(int i=0;i<m_PathList.GetCount();i++)\r
48         {\r
49                 m_cList.InsertItem(0,m_PathList[i].GetWinPath());\r
50         }\r
51 \r
52         //CAppUtils::SetListCtrlBackgroundImage(m_cList.GetSafeHwnd(), nID);\r
53 \r
54         CString title;\r
55         this->GetWindowText(title);\r
56         this->SetWindowText(title+_T(" - ")+g_Git.m_CurrentDir);\r
57         EnableSaveRestore(_T("ImportDlg"));\r
58 \r
59         return TRUE;\r
60 }\r
61 \r
62 BEGIN_MESSAGE_MAP(CImportPatchDlg, CResizableStandAloneDialog)\r
63         ON_LBN_SELCHANGE(IDC_LIST_PATCH, &CImportPatchDlg::OnLbnSelchangeListPatch)\r
64         ON_BN_CLICKED(IDC_BUTTON_ADD, &CImportPatchDlg::OnBnClickedButtonAdd)\r
65         ON_BN_CLICKED(IDC_BUTTON_UP, &CImportPatchDlg::OnBnClickedButtonUp)\r
66         ON_BN_CLICKED(IDC_BUTTON_DOWN, &CImportPatchDlg::OnBnClickedButtonDown)\r
67         ON_BN_CLICKED(IDC_BUTTON_REMOVE, &CImportPatchDlg::OnBnClickedButtonRemove)\r
68         ON_BN_CLICKED(IDOK, &CImportPatchDlg::OnBnClickedOk)\r
69 END_MESSAGE_MAP()\r
70 \r
71 \r
72 // CImportPatchDlg message handlers\r
73 \r
74 void CImportPatchDlg::OnLbnSelchangeListPatch()\r
75 {\r
76         // TODO: Add your control notification handler code here\r
77         if(m_cList.GetSelectedCount() == 0)\r
78         {\r
79                 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(FALSE);\r
80                 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(FALSE);\r
81                 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(FALSE);\r
82         }else\r
83         {\r
84                 this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(TRUE);\r
85                 this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(TRUE);\r
86                 this->GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(TRUE);\r
87 \r
88         }\r
89 \r
90 }\r
91 \r
92 void CImportPatchDlg::OnBnClickedButtonAdd()\r
93 {\r
94         \r
95         CFileDialog dlg(TRUE,NULL,\r
96                                         NULL,\r
97                                         OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,\r
98                                         _T("Patch Files(*.patch)|*.patch|Diff Files(*.diff)|*.diff|All Files(*.*)|*.*||"));\r
99         if(dlg.DoModal()==IDOK)\r
100         {\r
101                 POSITION pos;\r
102                 pos=dlg.GetStartPosition();\r
103                 while(pos)\r
104                 {\r
105                         m_cList.InsertItem(0,dlg.GetNextPathName(pos));\r
106                 }\r
107         }\r
108 \r
109         // TODO: Add your control notification handler code here\r
110 }\r
111 \r
112 void CImportPatchDlg::OnBnClickedButtonUp()\r
113 {\r
114         // TODO: Add your control notification handler code here\r
115         POSITION pos;\r
116         pos=m_cList.GetFirstSelectedItemPosition();\r
117         while(pos)\r
118         {\r
119                 int index=m_cList.GetNextSelectedItem(pos);\r
120                 if(index>1)\r
121                 {\r
122                         CString old=m_cList.GetItemText(index,0);\r
123                         m_cList.DeleteItem(index);\r
124 \r
125                         m_cList.InsertItem(index-1,old);\r
126                 }\r
127         }\r
128 \r
129 }\r
130 \r
131 void CImportPatchDlg::OnBnClickedButtonDown()\r
132 {\r
133         // TODO: Add your control notification handler code here\r
134         POSITION pos;\r
135         pos=m_cList.GetFirstSelectedItemPosition();\r
136         while(pos)\r
137         {\r
138                 int index=m_cList.GetNextSelectedItem(pos);\r
139                 \r
140                 CString old=m_cList.GetItemText(index,0);\r
141                 m_cList.DeleteItem(index);\r
142 \r
143                 m_cList.InsertItem(index+1,old);\r
144                 \r
145         }\r
146 }\r
147 \r
148 void CImportPatchDlg::OnBnClickedButtonRemove()\r
149 {\r
150         // TODO: Add your control notification handler code here\r
151         POSITION pos;\r
152         pos=m_cList.GetFirstSelectedItemPosition();\r
153         while(pos)\r
154         {\r
155                 int index=m_cList.GetNextSelectedItem(pos);\r
156                 m_cList.DeleteItem(index);\r
157                 pos=m_cList.GetFirstSelectedItemPosition();\r
158         }\r
159 }\r
160 \r
161 void CImportPatchDlg::OnBnClickedOk()\r
162 {\r
163         m_PathList.Clear();\r
164 \r
165         for(int i=0;i<m_cList.GetItemCount();i++)\r
166         {\r
167                 CTGitPath path;\r
168                 path.SetFromWin(m_cList.GetItemText(i,0));\r
169                 m_PathList.AddPath(path);\r
170         }\r
171         OnOK();\r
172 }\r