SyncDlg: Make check if local branch fast-fowards to remote branch work again
[TortoiseGit.git] / src / TortoiseProc / Settings / SetBugTraqAdv.cpp
bloba3b96094272d43a63e8aee9b314495455586f621
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008,2010 - 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 "SetBugTraqAdv.h"
21 #include "BrowseFolder.h"
22 #include "BugTraqAssociations.h"
23 #include "..\IBugTraqProvider\IBugTraqProvider_h.h"
25 IMPLEMENT_DYNAMIC(CSetBugTraqAdv, CResizableStandAloneDialog)
27 CSetBugTraqAdv::CSetBugTraqAdv(CWnd* pParent /*= NULL*/)
28 : CResizableStandAloneDialog(CSetBugTraqAdv::IDD, pParent)
29 , m_provider_clsid(GUID_NULL)
33 CSetBugTraqAdv::CSetBugTraqAdv(const CBugTraqAssociation &assoc, CWnd* pParent /*= NULL*/)
34 : CResizableStandAloneDialog(CSetBugTraqAdv::IDD, pParent)
35 , m_sPath(assoc.GetPath().GetWinPathString())
36 , m_provider_clsid(assoc.GetProviderClass())
37 , m_sParameters(assoc.GetParameters())
41 CSetBugTraqAdv::~CSetBugTraqAdv()
45 void CSetBugTraqAdv::DoDataExchange(CDataExchange* pDX)
47 CResizableStandAloneDialog::DoDataExchange(pDX);
48 DDX_Text(pDX, IDC_BUGTRAQPATH, m_sPath);
49 DDX_Control(pDX, IDC_BUGTRAQPROVIDERCOMBO, m_cProviderCombo);
50 DDX_Text(pDX, IDC_BUGTRAQPARAMETERS, m_sParameters);
53 BEGIN_MESSAGE_MAP(CSetBugTraqAdv, CResizableStandAloneDialog)
54 ON_WM_DESTROY()
55 ON_BN_CLICKED(IDC_BUGTRAQBROWSE, &CSetBugTraqAdv::OnBnClickedBugTraqbrowse)
56 ON_BN_CLICKED(IDHELP, &CSetBugTraqAdv::OnBnClickedHelp)
57 ON_CBN_SELCHANGE(IDC_BUGTRAQPROVIDERCOMBO, &CSetBugTraqAdv::OnCbnSelchangeBugtraqprovidercombo)
58 ON_BN_CLICKED(IDC_OPTIONS, &CSetBugTraqAdv::OnBnClickedOptions)
59 END_MESSAGE_MAP()
61 BOOL CSetBugTraqAdv::OnInitDialog()
63 CResizableStandAloneDialog::OnInitDialog();
65 std::vector<CBugTraqProvider> providers = CBugTraqAssociations::GetAvailableProviders();
66 if (providers.empty())
68 AfxMessageBox(IDS_ERR_NO_AVAILABLE_BUGTRAQ_PROVIDERS);
69 EndDialog(IDCANCEL);
70 return TRUE;
73 for (std::vector<CBugTraqProvider>::const_iterator it = providers.begin(); it != providers.end(); ++it)
75 int index = m_cProviderCombo.AddString(it->name);
76 m_cProviderCombo.SetItemDataPtr(index, new CBugTraqProvider(*it));
79 // preselect the right provider in the combo; we can't do this above, because the
80 // combo will sort the entries.
81 if (m_provider_clsid == GUID_NULL)
82 m_cProviderCombo.SetCurSel(0);
84 for (int i = 0; i < m_cProviderCombo.GetCount(); ++i)
86 CBugTraqProvider *p = (CBugTraqProvider *)m_cProviderCombo.GetItemDataPtr(i);
87 if (p->clsid == m_provider_clsid)
89 m_cProviderCombo.SetCurSel(i);
90 break;
94 m_tooltips.Create(this);
95 UpdateData(FALSE);
96 CheckHasOptions();
98 AddAnchor(IDC_BUGTRAQWCPATHLABEL, TOP_LEFT, TOP_RIGHT);
99 AddAnchor(IDC_BUGTRAQPATH, TOP_LEFT, TOP_RIGHT);
100 AddAnchor(IDC_BUGTRAQBROWSE, TOP_RIGHT);
101 AddAnchor(IDC_BUGTRAQPROVIDERLABEL, TOP_LEFT, TOP_RIGHT);
102 AddAnchor(IDC_BUGTRAQPROVIDERCOMBO, TOP_LEFT, TOP_RIGHT);
103 AddAnchor(IDC_BUGTRAQPARAMETERSLABEL, TOP_LEFT, TOP_RIGHT);
104 AddAnchor(IDC_BUGTRAQPARAMETERS, TOP_LEFT, TOP_RIGHT);
105 AddAnchor(IDC_OPTIONS, TOP_RIGHT);
106 AddAnchor(IDOK, BOTTOM_RIGHT);
107 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
108 AddAnchor(IDHELP, BOTTOM_RIGHT);
109 EnableSaveRestore(_T("SetBugTraqAdvDlg"));
110 return TRUE;
113 void CSetBugTraqAdv::OnDestroy()
115 for (int i = 0; i < m_cProviderCombo.GetCount(); ++i)
116 delete (CBugTraqProvider *)m_cProviderCombo.GetItemDataPtr(i);
118 CResizableStandAloneDialog::OnDestroy();
121 void CSetBugTraqAdv::OnOK()
123 UpdateData();
125 m_provider_clsid = GUID_NULL;
127 int index = m_cProviderCombo.GetCurSel();
128 if (index != CB_ERR)
130 CBugTraqProvider *provider = (CBugTraqProvider *)m_cProviderCombo.GetItemDataPtr(index);
131 m_provider_clsid = provider->clsid;
134 CComPtr<IBugTraqProvider> pProvider;
135 HRESULT hr = pProvider.CoCreateInstance(m_provider_clsid);
137 if (FAILED(hr))
139 m_tooltips.ShowBalloon(IDC_BUGTRAQPROVIDERCOMBO, IDS_ERR_MISSING_PROVIDER, IDS_ERR_ERROR, TTI_ERROR);
140 return;
143 VARIANT_BOOL valid;
144 if (FAILED(hr = pProvider->ValidateParameters(GetSafeHwnd(), m_sParameters.AllocSysString(), &valid)))
146 ShowEditBalloon(IDC_BUGTRAQPARAMETERS, IDS_ERR_PROVIDER_VALIDATE_FAILED, IDS_ERR_ERROR, TTI_ERROR);
147 return;
150 if (valid != VARIANT_TRUE)
151 return; // It's assumed that the provider will have done this.
153 CResizableStandAloneDialog::OnOK();
156 void CSetBugTraqAdv::OnBnClickedBugTraqbrowse()
158 CBrowseFolder browser;
159 CString sPath;
160 browser.SetInfo(CString(MAKEINTRESOURCE(IDS_SETTINGS_BUGTRAQ_SELECTFOLDERPATH)));
161 browser.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
162 if (browser.Show(m_hWnd, sPath) == CBrowseFolder::OK)
164 m_sPath = sPath;
165 UpdateData(FALSE);
169 void CSetBugTraqAdv::OnBnClickedHelp()
171 OnHelp();
174 CBugTraqAssociation CSetBugTraqAdv::GetAssociation() const
176 return CBugTraqAssociation(m_sPath, m_provider_clsid, CBugTraqAssociations::LookupProviderName(m_provider_clsid), m_sParameters);
179 void CSetBugTraqAdv::CheckHasOptions()
181 m_provider_clsid = GUID_NULL;
183 int index = m_cProviderCombo.GetCurSel();
184 if (index != CB_ERR)
186 CBugTraqProvider *provider = (CBugTraqProvider *)m_cProviderCombo.GetItemDataPtr(index);
187 m_provider_clsid = provider->clsid;
190 CComPtr<IBugTraqProvider2> pProvider;
191 HRESULT hr = pProvider.CoCreateInstance(m_provider_clsid);
193 if (SUCCEEDED(hr))
195 VARIANT_BOOL hasOptions = VARIANT_FALSE;
196 if (SUCCEEDED(hr = pProvider->HasOptions(&hasOptions)))
198 if (hasOptions == VARIANT_TRUE)
200 GetDlgItem(IDC_OPTIONS)->EnableWindow(TRUE);
201 return;
206 GetDlgItem(IDC_OPTIONS)->EnableWindow(FALSE);
209 void CSetBugTraqAdv::OnCbnSelchangeBugtraqprovidercombo()
211 CheckHasOptions();
214 void CSetBugTraqAdv::OnBnClickedOptions()
216 m_provider_clsid = GUID_NULL;
218 int index = m_cProviderCombo.GetCurSel();
219 if (index != CB_ERR)
221 CBugTraqProvider *provider = (CBugTraqProvider *)m_cProviderCombo.GetItemDataPtr(index);
222 m_provider_clsid = provider->clsid;
225 CComPtr<IBugTraqProvider2> pProvider;
226 HRESULT hr = pProvider.CoCreateInstance(m_provider_clsid);
228 if (SUCCEEDED(hr))
230 BSTR temp = NULL;
231 CString p;
232 GetDlgItemText(IDC_BUGTRAQPARAMETERS, p);
233 BSTR params = p.AllocSysString();
234 if (SUCCEEDED(hr = pProvider->ShowOptionsDialog(GetSafeHwnd(), params, &temp)))
236 SetDlgItemText(IDC_BUGTRAQPARAMETERS, temp);
238 SysFreeString(temp);
242 BOOL CSetBugTraqAdv::PreTranslateMessage(MSG* pMsg)
244 m_tooltips.RelayEvent(pMsg);
245 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);