2
* This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3
* http://www.gnu.org/licenses/lgpl-3.0.html
6
* $Id: editpairdlg.cpp 10307 2015-05-24 05:44:26Z fuscated $
7
* $HeadURL: http://svn.code.sf.net/p/codeblocks/code/branches/release-16.xx/src/sdk/editpairdlg.cpp $
10
#include "sdk_precomp.h"
13
#include <wx/xrc/xmlres.h>
14
#include <wx/button.h>
15
#include <wx/textctrl.h>
20
#include <wx/filedlg.h>
21
#include "editpairdlg.h"
22
#include "filefilters.h"
24
static const wxRegEx reKey(wxT("^[[:alnum:]_]+$"), wxRE_EXTENDED);
26
BEGIN_EVENT_TABLE(EditPairDlg, wxScrollingDialog)
27
EVT_BUTTON(XRCID("btnBrowse"), EditPairDlg::OnBrowse)
28
EVT_UPDATE_UI(-1, EditPairDlg::OnUpdateUI)
31
EditPairDlg::EditPairDlg(wxWindow* parent, wxString& key, wxString& value, const wxString& title, BrowseMode allowBrowse)
34
m_BrowseMode(allowBrowse)
37
wxXmlResource::Get()->LoadObject(this, parent, _T("dlgEditPair"),_T("wxScrollingDialog"));
39
XRCCTRL(*this, "btnBrowse", wxButton)->Enable(m_BrowseMode != bmDisable);
40
XRCCTRL(*this, "txtKey", wxTextCtrl)->SetValue(key);
41
XRCCTRL(*this, "txtValue", wxTextCtrl)->SetValue(value);
44
EditPairDlg::~EditPairDlg()
49
void EditPairDlg::OnUpdateUI(cb_unused wxUpdateUIEvent& event)
51
const wxString &value = XRCCTRL(*this, "txtKey", wxTextCtrl)->GetValue();
52
bool enable = !value.IsEmpty();
54
enable = reKey.Matches(value);
55
XRCCTRL(*this, "wxID_OK", wxButton)->Enable(enable);
58
void EditPairDlg::OnBrowse(cb_unused wxCommandEvent& event)
64
wxFileDialog dlg(this,
66
XRCCTRL(*this, "txtValue", wxTextCtrl)->GetValue(),
68
FileFilters::GetFilterAll(),
69
wxFD_OPEN | compatibility::wxHideReadonly);
71
if (dlg.ShowModal() == wxID_OK)
72
XRCCTRL(*this, "txtValue", wxTextCtrl)->SetValue(dlg.GetPath());
75
case bmBrowseForDirectory:
77
wxString dir = ChooseDirectory(this,
78
_("Select directory"),
79
XRCCTRL(*this, "txtValue", wxTextCtrl)->GetValue(),
84
XRCCTRL(*this, "txtValue", wxTextCtrl)->SetValue(dir);
87
case bmDisable: // fall through
92
void EditPairDlg::EndModal(int retCode)
94
if (retCode == wxID_OK)
96
m_Key = XRCCTRL(*this, "txtKey", wxTextCtrl)->GetValue();
97
m_Value = XRCCTRL(*this, "txtValue", wxTextCtrl)->GetValue();
99
wxScrollingDialog::EndModal(retCode);