OSDN Git Service

f92d85c420fe32a329e55d7b8d23f8b05117b87c
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Settings / SetBugTraq.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "SetBugTraq.h"\r
21 #include "SetBugTraqAdv.h"\r
22 #include "XPTheme.h"\r
23 \r
24 IMPLEMENT_DYNAMIC(CSetBugTraq, ISettingsPropPage)\r
25 \r
26 CSetBugTraq::CSetBugTraq()\r
27         : ISettingsPropPage(CSetBugTraq::IDD)\r
28 {\r
29 }\r
30 \r
31 CSetBugTraq::~CSetBugTraq()\r
32 {\r
33 }\r
34 \r
35 void CSetBugTraq::DoDataExchange(CDataExchange* pDX)\r
36 {\r
37         ISettingsPropPage::DoDataExchange(pDX);\r
38         DDX_Control(pDX, IDC_BUGTRAQLIST, m_cBugTraqList);\r
39 }\r
40 \r
41 \r
42 BEGIN_MESSAGE_MAP(CSetBugTraq, ISettingsPropPage)\r
43         ON_BN_CLICKED(IDC_BUGTRAQREMOVEBUTTON, &CSetBugTraq::OnBnClickedRemovebutton)\r
44         ON_BN_CLICKED(IDC_BUGTRAQEDITBUTTON, &CSetBugTraq::OnBnClickedEditbutton)\r
45         ON_BN_CLICKED(IDC_BUGTRAQADDBUTTON, &CSetBugTraq::OnBnClickedAddbutton)\r
46         ON_BN_CLICKED(IDC_BUGTRAQCOPYBUTTON, &CSetBugTraq::OnBnClickedBugTraqcopybutton)\r
47         ON_NOTIFY(LVN_ITEMCHANGED, IDC_BUGTRAQLIST, &CSetBugTraq::OnLvnItemchangedBugTraqlist)\r
48         ON_NOTIFY(NM_DBLCLK, IDC_BUGTRAQLIST, &CSetBugTraq::OnNMDblclkBugTraqlist)\r
49 END_MESSAGE_MAP()\r
50 \r
51 BOOL CSetBugTraq::OnInitDialog()\r
52 {\r
53         ISettingsPropPage::OnInitDialog();\r
54 \r
55         m_associations.Load();\r
56 \r
57         m_cBugTraqList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP);\r
58 \r
59         // clear all previously set header columns\r
60         m_cBugTraqList.DeleteAllItems();\r
61         int c = ((CHeaderCtrl*)(m_cBugTraqList.GetDlgItem(0)))->GetItemCount()-1;\r
62         while (c>=0)\r
63                 m_cBugTraqList.DeleteColumn(c--);\r
64 \r
65         // now set up the requested columns\r
66         CString temp;\r
67 \r
68         temp.LoadString(IDS_SETTINGS_BUGTRAQ_PATHCOL);\r
69         m_cBugTraqList.InsertColumn(0, temp);\r
70         temp.LoadString(IDS_SETTINGS_BUGTRAQ_PROVIDERCOL);\r
71         m_cBugTraqList.InsertColumn(1, temp);\r
72         temp.LoadString(IDS_SETTINGS_BUGTRAQ_PARAMETERSCOL);\r
73         m_cBugTraqList.InsertColumn(2, temp);\r
74 \r
75         CXPTheme theme;\r
76         theme.SetWindowTheme(m_cBugTraqList.GetSafeHwnd(), L"Explorer", NULL);\r
77 \r
78         RebuildBugTraqList();\r
79 \r
80         return TRUE;\r
81 }\r
82 \r
83 void CSetBugTraq::RebuildBugTraqList()\r
84 {\r
85         m_cBugTraqList.SetRedraw(false);\r
86         m_cBugTraqList.DeleteAllItems();\r
87 \r
88         // fill the list control with all the hooks\r
89         for (CBugTraqAssociations::const_iterator it = m_associations.begin(); it != m_associations.end(); ++it)\r
90         {\r
91                 int pos = m_cBugTraqList.InsertItem(m_cBugTraqList.GetItemCount(), (*it)->GetPath().GetWinPathString());\r
92                 m_cBugTraqList.SetItemText(pos, 1, (*it)->GetProviderName());\r
93                 m_cBugTraqList.SetItemText(pos, 2, (*it)->GetParameters());\r
94                 m_cBugTraqList.SetItemData(pos, (DWORD_PTR)*it);\r
95         }\r
96 \r
97         int maxcol = ((CHeaderCtrl*)(m_cBugTraqList.GetDlgItem(0)))->GetItemCount()-1;\r
98         for (int col = 0; col <= maxcol; col++)\r
99         {\r
100                 m_cBugTraqList.SetColumnWidth(col, LVSCW_AUTOSIZE_USEHEADER);\r
101         }\r
102         m_cBugTraqList.SetRedraw(true);\r
103 }\r
104 \r
105 void CSetBugTraq::OnBnClickedRemovebutton()\r
106 {\r
107         // traversing from the end to the beginning so that the indices are not skipped\r
108         int index = m_cBugTraqList.GetItemCount()-1;\r
109         while (index >= 0)\r
110         {\r
111                 if (m_cBugTraqList.GetItemState(index, LVIS_SELECTED) & LVIS_SELECTED)\r
112                 {\r
113                         CTSVNPath path = CTSVNPath(m_cBugTraqList.GetItemText(index, 0));\r
114                         m_cBugTraqList.DeleteItem(index);\r
115                         m_associations.RemoveByPath(path);\r
116                         SetModified();\r
117                 }\r
118                 index--;\r
119         }\r
120 }\r
121 \r
122 void CSetBugTraq::OnBnClickedEditbutton()\r
123 {\r
124         if (m_cBugTraqList.GetSelectedCount() != 1)\r
125                 return;\r
126 \r
127         int index = m_cBugTraqList.GetNextItem(-1, LVNI_SELECTED);\r
128         if (index == -1)\r
129                 return;\r
130 \r
131         CBugTraqAssociation *assoc = (CBugTraqAssociation *)m_cBugTraqList.GetItemData(index);\r
132         if (!assoc)\r
133                 return;\r
134 \r
135         CSetBugTraqAdv dlg(*assoc);\r
136         if (dlg.DoModal() == IDOK)\r
137         {\r
138                 m_associations.RemoveByPath(assoc->GetPath());\r
139                 m_associations.Add(dlg.GetAssociation());\r
140                 RebuildBugTraqList();\r
141                 SetModified();\r
142         }\r
143 }\r
144 \r
145 void CSetBugTraq::OnBnClickedAddbutton()\r
146 {\r
147         CSetBugTraqAdv dlg;\r
148         if (dlg.DoModal() == IDOK)\r
149         {\r
150                 m_associations.Add(dlg.GetAssociation());\r
151                 RebuildBugTraqList();\r
152                 SetModified();\r
153         }\r
154 }\r
155 \r
156 void CSetBugTraq::OnLvnItemchangedBugTraqlist(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
157 {\r
158         UINT count = m_cBugTraqList.GetSelectedCount();\r
159         GetDlgItem(IDC_BUGTRAQREMOVEBUTTON)->EnableWindow(count > 0);\r
160         GetDlgItem(IDC_BUGTRAQEDITBUTTON)->EnableWindow(count == 1);\r
161         GetDlgItem(IDC_BUGTRAQCOPYBUTTON)->EnableWindow(count == 1);\r
162         *pResult = 0;\r
163 }\r
164 \r
165 void CSetBugTraq::OnNMDblclkBugTraqlist(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
166 {\r
167         OnBnClickedEditbutton();\r
168         *pResult = 0;\r
169 }\r
170 \r
171 BOOL CSetBugTraq::OnApply()\r
172 {\r
173         UpdateData();\r
174         m_associations.Save();\r
175         SetModified(FALSE);\r
176         return ISettingsPropPage::OnApply();\r
177 }\r
178 \r
179 void CSetBugTraq::OnBnClickedBugTraqcopybutton()\r
180 {\r
181         if (m_cBugTraqList.GetSelectedCount() != 1)\r
182                 return;\r
183 \r
184         int index = m_cBugTraqList.GetNextItem(-1, LVNI_SELECTED);\r
185         if (index == -1)\r
186                 return;\r
187 \r
188         CBugTraqAssociation *assoc = (CBugTraqAssociation *)m_cBugTraqList.GetItemData(index);\r
189         if (!assoc)\r
190                 return;\r
191 \r
192         CSetBugTraqAdv dlg(*assoc);\r
193         if (dlg.DoModal() == IDOK)\r
194         {\r
195                 m_associations.Add(dlg.GetAssociation());\r
196                 RebuildBugTraqList();\r
197                 SetModified();\r
198         }\r
199 }\r