Code::Blocks  SVN r11506
editpairdlg.cpp
Go to the documentation of this file.
1 /*
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
4  *
5  * $Revision: 10912 $
6  * $Id: editpairdlg.cpp 10912 2016-09-25 16:10:13Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/editpairdlg.cpp $
8  */
9 
10 #include "sdk_precomp.h"
11 
12 #ifndef CB_PRECOMP
13  #include <wx/xrc/xmlres.h>
14  #include <wx/button.h>
15  #include <wx/textctrl.h>
16  #include <wx/regex.h>
17  #include "globals.h"
18 #endif
19 
20 #include <wx/filedlg.h>
21 #include "editpairdlg.h"
22 #include "filefilters.h"
23 
24 static const wxRegEx reKey(wxT("^[[:alnum:]_]+$"), wxRE_EXTENDED);
25 
26 BEGIN_EVENT_TABLE(EditPairDlg, wxScrollingDialog)
27  EVT_BUTTON(XRCID("btnBrowse"), EditPairDlg::OnBrowse)
28  EVT_UPDATE_UI(-1, EditPairDlg::OnUpdateUI)
29 END_EVENT_TABLE()
30 
31 EditPairDlg::EditPairDlg(wxWindow* parent, wxString& key, wxString& value, const wxString& title, BrowseMode allowBrowse)
32  : m_Key(key),
33  m_Value(value),
34  m_BrowseMode(allowBrowse)
35 {
36  //ctor
37  wxXmlResource::Get()->LoadObject(this, parent, _T("dlgEditPair"),_T("wxScrollingDialog"));
38  XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
39  SetTitle(title);
40  XRCCTRL(*this, "btnBrowse", wxButton)->Enable(m_BrowseMode != bmDisable);
41  XRCCTRL(*this, "txtKey", wxTextCtrl)->SetValue(key);
42  XRCCTRL(*this, "txtValue", wxTextCtrl)->SetValue(value);
43 }
44 
46 {
47  //dtor
48 }
49 
51 {
52  const wxString &value = XRCCTRL(*this, "txtKey", wxTextCtrl)->GetValue();
53  bool enable = !value.IsEmpty();
54  if (enable)
55  enable = reKey.Matches(value);
56  XRCCTRL(*this, "wxID_OK", wxButton)->Enable(enable);
57 }
58 
59 void EditPairDlg::OnBrowse(cb_unused wxCommandEvent& event)
60 {
61  switch (m_BrowseMode)
62  {
63  case bmBrowseForFile:
64  {
65  wxFileDialog dlg(this,
66  _("Select file"),
67  XRCCTRL(*this, "txtValue", wxTextCtrl)->GetValue(),
68  _T(""),
70  wxFD_OPEN | compatibility::wxHideReadonly);
71  PlaceWindow(&dlg);
72  if (dlg.ShowModal() == wxID_OK)
73  XRCCTRL(*this, "txtValue", wxTextCtrl)->SetValue(dlg.GetPath());
74  break;
75  }
77  {
78  wxString dir = ChooseDirectory(this,
79  _("Select directory"),
80  XRCCTRL(*this, "txtValue", wxTextCtrl)->GetValue(),
81  _T(""),
82  false,
83  true);
84  if (!dir.IsEmpty())
85  XRCCTRL(*this, "txtValue", wxTextCtrl)->SetValue(dir);
86  break;
87  }
88  case bmDisable: // fall through
89  default: break;
90  }
91 }
92 
93 void EditPairDlg::EndModal(int retCode)
94 {
95  if (retCode == wxID_OK)
96  {
97  m_Key = XRCCTRL(*this, "txtKey", wxTextCtrl)->GetValue();
98  m_Value = XRCCTRL(*this, "txtValue", wxTextCtrl)->GetValue();
99  }
101 }
void EndModal(int retCode)
Definition: sc_dialog.cpp:112
virtual int ShowModal()
void OnUpdateUI(wxUpdateUIEvent &event)
Definition: editpairdlg.cpp:50
DLLIMPORT wxString ChooseDirectory(wxWindow *parent, const wxString &message=_("Select directory"), const wxString &initialPath=_T(""), const wxString &basePath=_T(""), bool askToMakeRelative=false, bool showCreateDirButton=false)
Definition: globals.cpp:639
bool Matches(const wxString &text, int flags=0) const
#define _T(string)
DLLIMPORT wxString GetFilterAll()
Generates a simple special filter "All files".
Definition: filefilters.cpp:98
#define wxT(string)
void OnBrowse(wxCommandEvent &event)
Definition: editpairdlg.cpp:59
void EndModal(int retCode) override
Definition: editpairdlg.cpp:93
virtual wxString GetPath() const
const wxString & _(const wxString &string)
bool IsEmpty() const
DLLIMPORT void PlaceWindow(wxTopLevelWindow *w, cbPlaceDialogMode mode=pdlBest, bool enforce=false)
Definition: globals.cpp:1177
static const wxRegEx reKey(wxT("^[[:alnum:]_]+$"), wxRE_EXTENDED)
static wxXmlResource * Get()
~EditPairDlg() override
Definition: editpairdlg.cpp:45
BrowseMode m_BrowseMode
Definition: editpairdlg.h:32
wxString & m_Key
Definition: editpairdlg.h:30
wxObject * LoadObject(wxWindow *parent, const wxString &name, const wxString &classname)
wxString & m_Value
Definition: editpairdlg.h:31