~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/sdk/editpairdlg.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: 10307 $
 
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 $
 
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
    SetTitle(title);
 
39
    XRCCTRL(*this, "btnBrowse", wxButton)->Enable(m_BrowseMode != bmDisable);
 
40
    XRCCTRL(*this, "txtKey", wxTextCtrl)->SetValue(key);
 
41
    XRCCTRL(*this, "txtValue", wxTextCtrl)->SetValue(value);
 
42
}
 
43
 
 
44
EditPairDlg::~EditPairDlg()
 
45
{
 
46
    //dtor
 
47
}
 
48
 
 
49
void EditPairDlg::OnUpdateUI(cb_unused wxUpdateUIEvent& event)
 
50
{
 
51
    const wxString &value = XRCCTRL(*this, "txtKey", wxTextCtrl)->GetValue();
 
52
    bool enable = !value.IsEmpty();
 
53
    if (enable)
 
54
        enable = reKey.Matches(value);
 
55
    XRCCTRL(*this, "wxID_OK", wxButton)->Enable(enable);
 
56
}
 
57
 
 
58
void EditPairDlg::OnBrowse(cb_unused wxCommandEvent& event)
 
59
{
 
60
    switch (m_BrowseMode)
 
61
    {
 
62
        case bmBrowseForFile:
 
63
        {
 
64
            wxFileDialog dlg(this,
 
65
                            _("Select file"),
 
66
                            XRCCTRL(*this, "txtValue", wxTextCtrl)->GetValue(),
 
67
                            _T(""),
 
68
                            FileFilters::GetFilterAll(),
 
69
                            wxFD_OPEN | compatibility::wxHideReadonly);
 
70
            PlaceWindow(&dlg);
 
71
            if (dlg.ShowModal() == wxID_OK)
 
72
                XRCCTRL(*this, "txtValue", wxTextCtrl)->SetValue(dlg.GetPath());
 
73
            break;
 
74
        }
 
75
        case bmBrowseForDirectory:
 
76
        {
 
77
            wxString dir = ChooseDirectory(this,
 
78
                                            _("Select directory"),
 
79
                                            XRCCTRL(*this, "txtValue", wxTextCtrl)->GetValue(),
 
80
                                            _T(""),
 
81
                                            false,
 
82
                                            true);
 
83
            if (!dir.IsEmpty())
 
84
                XRCCTRL(*this, "txtValue", wxTextCtrl)->SetValue(dir);
 
85
            break;
 
86
        }
 
87
        case bmDisable: // fall through
 
88
        default: break;
 
89
    }
 
90
}
 
91
 
 
92
void EditPairDlg::EndModal(int retCode)
 
93
{
 
94
    if (retCode == wxID_OK)
 
95
    {
 
96
        m_Key = XRCCTRL(*this, "txtKey", wxTextCtrl)->GetValue();
 
97
        m_Value = XRCCTRL(*this, "txtValue", wxTextCtrl)->GetValue();
 
98
    }
 
99
    wxScrollingDialog::EndModal(retCode);
 
100
}