Cleanup: Drop unnecessary method definitions
[TortoiseGit.git] / src / TortoiseProc / Settings / SetBugTraq.cpp
blob8f2695923a4f288fb56ef2178056c7de03af77b8
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008 - TortoiseSVN
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 #include "stdafx.h"
20 #include "SetBugTraq.h"
21 #include "SetBugTraqAdv.h"
23 IMPLEMENT_DYNAMIC(CSetBugTraq, ISettingsPropPage)
25 CSetBugTraq::CSetBugTraq()
26 : ISettingsPropPage(CSetBugTraq::IDD)
30 CSetBugTraq::~CSetBugTraq()
34 void CSetBugTraq::DoDataExchange(CDataExchange* pDX)
36 ISettingsPropPage::DoDataExchange(pDX);
37 DDX_Control(pDX, IDC_BUGTRAQLIST, m_cBugTraqList);
41 BEGIN_MESSAGE_MAP(CSetBugTraq, ISettingsPropPage)
42 ON_BN_CLICKED(IDC_BUGTRAQREMOVEBUTTON, &CSetBugTraq::OnBnClickedRemovebutton)
43 ON_BN_CLICKED(IDC_BUGTRAQEDITBUTTON, &CSetBugTraq::OnBnClickedEditbutton)
44 ON_BN_CLICKED(IDC_BUGTRAQADDBUTTON, &CSetBugTraq::OnBnClickedAddbutton)
45 ON_BN_CLICKED(IDC_BUGTRAQCOPYBUTTON, &CSetBugTraq::OnBnClickedBugTraqcopybutton)
46 ON_NOTIFY(LVN_ITEMCHANGED, IDC_BUGTRAQLIST, &CSetBugTraq::OnLvnItemchangedBugTraqlist)
47 ON_NOTIFY(NM_DBLCLK, IDC_BUGTRAQLIST, &CSetBugTraq::OnNMDblclkBugTraqlist)
48 END_MESSAGE_MAP()
50 BOOL CSetBugTraq::OnInitDialog()
52 ISettingsPropPage::OnInitDialog();
54 m_associations.Load();
56 m_cBugTraqList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP);
58 // clear all previously set header columns
59 m_cBugTraqList.DeleteAllItems();
60 int c = ((CHeaderCtrl*)(m_cBugTraqList.GetDlgItem(0)))->GetItemCount()-1;
61 while (c>=0)
62 m_cBugTraqList.DeleteColumn(c--);
64 // now set up the requested columns
65 CString temp;
67 temp.LoadString(IDS_SETTINGS_BUGTRAQ_PATHCOL);
68 m_cBugTraqList.InsertColumn(0, temp);
69 temp.LoadString(IDS_SETTINGS_BUGTRAQ_PROVIDERCOL);
70 m_cBugTraqList.InsertColumn(1, temp);
71 temp.LoadString(IDS_SETTINGS_BUGTRAQ_PARAMETERSCOL);
72 m_cBugTraqList.InsertColumn(2, temp);
74 SetWindowTheme(m_hWnd, L"Explorer", NULL);
76 RebuildBugTraqList();
78 return TRUE;
81 void CSetBugTraq::RebuildBugTraqList()
83 m_cBugTraqList.SetRedraw(false);
84 m_cBugTraqList.DeleteAllItems();
86 // fill the list control with all the hooks
87 for (CBugTraqAssociations::const_iterator it = m_associations.begin(); it != m_associations.end(); ++it)
89 int pos = m_cBugTraqList.InsertItem(m_cBugTraqList.GetItemCount(), (*it)->GetPath().GetWinPathString());
90 m_cBugTraqList.SetItemText(pos, 1, (*it)->GetProviderName());
91 m_cBugTraqList.SetItemText(pos, 2, (*it)->GetParameters());
92 m_cBugTraqList.SetItemData(pos, (DWORD_PTR)*it);
95 int maxcol = ((CHeaderCtrl*)(m_cBugTraqList.GetDlgItem(0)))->GetItemCount()-1;
96 for (int col = 0; col <= maxcol; col++)
98 m_cBugTraqList.SetColumnWidth(col, LVSCW_AUTOSIZE_USEHEADER);
100 m_cBugTraqList.SetRedraw(true);
103 void CSetBugTraq::OnBnClickedRemovebutton()
105 // traversing from the end to the beginning so that the indices are not skipped
106 int index = m_cBugTraqList.GetItemCount()-1;
107 while (index >= 0)
109 if (m_cBugTraqList.GetItemState(index, LVIS_SELECTED) & LVIS_SELECTED)
111 CTGitPath path = CTGitPath(m_cBugTraqList.GetItemText(index, 0));
112 m_cBugTraqList.DeleteItem(index);
113 m_associations.RemoveByPath(path);
114 SetModified();
116 index--;
120 void CSetBugTraq::OnBnClickedEditbutton()
122 if (m_cBugTraqList.GetSelectedCount() != 1)
123 return;
125 int index = m_cBugTraqList.GetNextItem(-1, LVNI_SELECTED);
126 if (index == -1)
127 return;
129 CBugTraqAssociation *assoc = (CBugTraqAssociation *)m_cBugTraqList.GetItemData(index);
130 if (!assoc)
131 return;
133 CSetBugTraqAdv dlg(*assoc);
134 if (dlg.DoModal() == IDOK)
136 m_associations.RemoveByPath(assoc->GetPath());
137 m_associations.Add(dlg.GetAssociation());
138 RebuildBugTraqList();
139 SetModified();
143 void CSetBugTraq::OnBnClickedAddbutton()
145 CSetBugTraqAdv dlg;
146 if (dlg.DoModal() == IDOK)
148 m_associations.Add(dlg.GetAssociation());
149 RebuildBugTraqList();
150 SetModified();
154 void CSetBugTraq::OnLvnItemchangedBugTraqlist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
156 UINT count = m_cBugTraqList.GetSelectedCount();
157 GetDlgItem(IDC_BUGTRAQREMOVEBUTTON)->EnableWindow(count > 0);
158 GetDlgItem(IDC_BUGTRAQEDITBUTTON)->EnableWindow(count == 1);
159 GetDlgItem(IDC_BUGTRAQCOPYBUTTON)->EnableWindow(count == 1);
160 *pResult = 0;
163 void CSetBugTraq::OnNMDblclkBugTraqlist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
165 OnBnClickedEditbutton();
166 *pResult = 0;
169 BOOL CSetBugTraq::OnApply()
171 UpdateData();
172 m_associations.Save();
173 SetModified(FALSE);
174 return ISettingsPropPage::OnApply();
177 void CSetBugTraq::OnBnClickedBugTraqcopybutton()
179 if (m_cBugTraqList.GetSelectedCount() != 1)
180 return;
182 int index = m_cBugTraqList.GetNextItem(-1, LVNI_SELECTED);
183 if (index == -1)
184 return;
186 CBugTraqAssociation *assoc = (CBugTraqAssociation *)m_cBugTraqList.GetItemData(index);
187 if (!assoc)
188 return;
190 CSetBugTraqAdv dlg(*assoc);
191 if (dlg.DoModal() == IDOK)
193 m_associations.Add(dlg.GetAssociation());
194 RebuildBugTraqList();
195 SetModified();