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: edittooldlg.cpp 4909 2008-02-27 13:15:26Z mortenmacfly $
7
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/sdk/edittooldlg.cpp $
10
#include "sdk_precomp.h"
13
#include <wx/button.h>
14
#include <wx/checkbox.h>
16
#include <wx/radiobox.h>
17
#include <wx/string.h>
18
#include <wx/textctrl.h>
19
#include <wx/xrc/xmlres.h>
21
#include "cbexception.h"
25
#include "edittooldlg.h"
26
#include <wx/filedlg.h>
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)
35
EditToolDlg::EditToolDlg(wxWindow* parent, cbTool* tool)
39
cbThrow(_T("Tool* parameter is mandatory in EditToolDlg()"));
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
49
EditToolDlg::~EditToolDlg()
56
void EditToolDlg::OnUpdateUI(wxUpdateUIEvent& /*event*/)
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
64
void EditToolDlg::OnBrowseCommand(wxCommandEvent& /*event*/)
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
72
void EditToolDlg::OnBrowseDir(wxCommandEvent& /*event*/)
74
const wxString dir = ChooseDirectory(this, _("Select working directory"), XRCCTRL(*this, "txtDir", wxTextCtrl)->GetValue());
76
XRCCTRL(*this, "txtDir", wxTextCtrl)->SetValue(dir);
77
} // end of OnBrowseDir
79
void EditToolDlg::EndModal(int retCode)
81
if (retCode == wxID_OK)
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()));
90
wxDialog::EndModal(retCode);