~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/sdk/edittooldlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

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: 4909 $
 
6
 * $Id: edittooldlg.cpp 4909 2008-02-27 13:15:26Z mortenmacfly $
 
7
 * $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/sdk/edittooldlg.cpp $
 
8
 */
 
9
 
 
10
#include "sdk_precomp.h"
 
11
 
 
12
#ifndef CB_PRECOMP
 
13
    #include <wx/button.h>
 
14
    #include <wx/checkbox.h>
 
15
    #include <wx/intl.h>
 
16
    #include <wx/radiobox.h>
 
17
    #include <wx/string.h>
 
18
    #include <wx/textctrl.h>
 
19
    #include <wx/xrc/xmlres.h>
 
20
    #include "cbtool.h"
 
21
    #include "cbexception.h"
 
22
    #include "globals.h"
 
23
#endif
 
24
 
 
25
#include "edittooldlg.h"
 
26
#include <wx/filedlg.h>
 
27
 
 
28
 
 
29
BEGIN_EVENT_TABLE(EditToolDlg, wxDialog)
 
30
        EVT_BUTTON(XRCID("btnBrowseCommand"),   EditToolDlg::OnBrowseCommand)
 
31
        EVT_BUTTON(XRCID("btnBrowseDir"),               EditToolDlg::OnBrowseDir)
 
32
        EVT_UPDATE_UI(-1,                                               EditToolDlg::OnUpdateUI)
 
33
END_EVENT_TABLE()
 
34
 
 
35
EditToolDlg::EditToolDlg(wxWindow* parent, cbTool* tool)
 
36
        : m_Tool(tool)
 
37
{
 
38
    if (!tool)
 
39
        cbThrow(_T("Tool* parameter is mandatory in EditToolDlg()"));
 
40
 
 
41
        wxXmlResource::Get()->LoadDialog(this, parent, _T("dlgEditTool"));
 
42
        XRCCTRL(*this, "txtName", wxTextCtrl)->SetValue(m_Tool->GetName());
 
43
        XRCCTRL(*this, "txtCommand", wxTextCtrl)->SetValue(m_Tool->GetCommand());
 
44
        XRCCTRL(*this, "txtParams", wxTextCtrl)->SetValue(m_Tool->GetParams());
 
45
        XRCCTRL(*this, "txtDir", wxTextCtrl)->SetValue(m_Tool->GetWorkingDir());
 
46
        XRCCTRL(*this, "rbLaunchOptions", wxRadioBox)->SetSelection(static_cast<int>(m_Tool->GetLaunchOption()));
 
47
} // end of constructor
 
48
 
 
49
EditToolDlg::~EditToolDlg()
 
50
{
 
51
        //dtor
 
52
}
 
53
 
 
54
// events
 
55
 
 
56
void EditToolDlg::OnUpdateUI(wxUpdateUIEvent& /*event*/)
 
57
{
 
58
        const wxString name = XRCCTRL(*this, "txtName", wxTextCtrl)->GetValue();
 
59
        const wxString command = XRCCTRL(*this, "txtCommand", wxTextCtrl)->GetValue();
 
60
        bool en = !name.IsEmpty() && !command.IsEmpty();
 
61
        XRCCTRL(*this, "wxID_OK", wxButton)->Enable(en);
 
62
} // end of OnUpdateUI
 
63
 
 
64
void EditToolDlg::OnBrowseCommand(wxCommandEvent& /*event*/)
 
65
{
 
66
        const wxFileName file(XRCCTRL(*this, "txtCommand", wxTextCtrl)->GetValue());
 
67
        wxString filename = wxFileSelector(_("Select executable"), file.GetPath(wxPATH_GET_VOLUME), file.GetFullName());
 
68
        if (!filename.IsEmpty())
 
69
                XRCCTRL(*this, "txtCommand", wxTextCtrl)->SetValue(filename);
 
70
} // end of OnBrowseCommand
 
71
 
 
72
void EditToolDlg::OnBrowseDir(wxCommandEvent& /*event*/)
 
73
{
 
74
    const wxString dir = ChooseDirectory(this, _("Select working directory"), XRCCTRL(*this, "txtDir", wxTextCtrl)->GetValue());
 
75
        if (!dir.IsEmpty())
 
76
                XRCCTRL(*this, "txtDir", wxTextCtrl)->SetValue(dir);
 
77
} // end of OnBrowseDir
 
78
 
 
79
void EditToolDlg::EndModal(int retCode)
 
80
{
 
81
    if (retCode == wxID_OK)
 
82
    {
 
83
        m_Tool->SetName(XRCCTRL(*this, "txtName", wxTextCtrl)->GetValue());
 
84
        m_Tool->SetCommand(XRCCTRL(*this, "txtCommand", wxTextCtrl)->GetValue());
 
85
        m_Tool->SetParams(XRCCTRL(*this, "txtParams", wxTextCtrl)->GetValue());
 
86
        m_Tool->SetWorkingDir(XRCCTRL(*this, "txtDir", wxTextCtrl)->GetValue());
 
87
        m_Tool->SetLaunchOption(static_cast<cbTool::eLaunchOption>(XRCCTRL(*this, "rbLaunchOptions", wxRadioBox)->GetSelection()));
 
88
    }
 
89
 
 
90
        wxDialog::EndModal(retCode);
 
91
} // end of EndModal