Code::Blocks  SVN r11506
edittooldlg.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: edittooldlg.cpp 10912 2016-09-25 16:10:13Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/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, wxScrollingDialog)
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 
36  : m_Tool(tool)
37 {
38  if (!tool)
39  cbThrow(_T("Tool* parameter is mandatory in EditToolDlg()"));
40 
41  wxXmlResource::Get()->LoadObject(this, parent, _T("dlgEditTool"),_T("wxScrollingDialog"));
42  XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
43  XRCCTRL(*this, "txtName", wxTextCtrl)->SetValue(m_Tool->GetName());
44  XRCCTRL(*this, "txtCommand", wxTextCtrl)->SetValue(m_Tool->GetCommand());
45  XRCCTRL(*this, "txtParams", wxTextCtrl)->SetValue(m_Tool->GetParams());
46  XRCCTRL(*this, "txtDir", wxTextCtrl)->SetValue(m_Tool->GetWorkingDir());
47  XRCCTRL(*this, "rbLaunchOptions", wxRadioBox)->SetSelection(static_cast<int>(m_Tool->GetLaunchOption()));
48 } // end of constructor
49 
51 {
52  //dtor
53 }
54 
55 // events
56 
58 {
59  const wxString name = XRCCTRL(*this, "txtName", wxTextCtrl)->GetValue();
60  const wxString command = XRCCTRL(*this, "txtCommand", wxTextCtrl)->GetValue();
61  bool en = !name.IsEmpty() && !command.IsEmpty();
62  XRCCTRL(*this, "wxID_OK", wxButton)->Enable(en);
63 } // end of OnUpdateUI
64 
66 {
67  const wxFileName file(XRCCTRL(*this, "txtCommand", wxTextCtrl)->GetValue());
68  wxString filename = wxFileSelector(_("Select executable"), file.GetPath(wxPATH_GET_VOLUME), file.GetFullName());
69  if (!filename.IsEmpty())
70  XRCCTRL(*this, "txtCommand", wxTextCtrl)->SetValue(filename);
71 } // end of OnBrowseCommand
72 
74 {
75  const wxString dir = ChooseDirectory(this, _("Select working directory"), XRCCTRL(*this, "txtDir", wxTextCtrl)->GetValue());
76  if (!dir.IsEmpty())
77  XRCCTRL(*this, "txtDir", wxTextCtrl)->SetValue(dir);
78 } // end of OnBrowseDir
79 
80 void EditToolDlg::EndModal(int retCode)
81 {
82  if (retCode == wxID_OK)
83  {
84  m_Tool->SetName(XRCCTRL(*this, "txtName", wxTextCtrl)->GetValue());
85  m_Tool->SetCommand(XRCCTRL(*this, "txtCommand", wxTextCtrl)->GetValue());
86  m_Tool->SetParams(XRCCTRL(*this, "txtParams", wxTextCtrl)->GetValue());
87  m_Tool->SetWorkingDir(XRCCTRL(*this, "txtDir", wxTextCtrl)->GetValue());
88  m_Tool->SetLaunchOption(static_cast<cbTool::eLaunchOption>(XRCCTRL(*this, "rbLaunchOptions", wxRadioBox)->GetSelection()));
89  }
90 
92 } // end of EndModal
void EndModal(int retCode)
Definition: sc_dialog.cpp:112
wxString wxFileSelector(const wxString &message, const wxString &default_path=wxEmptyString, const wxString &default_filename=wxEmptyString, const wxString &default_extension=wxEmptyString, const wxString &wildcard=wxFileSelectorDefaultWildcardStr, int flags=0, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
void OnBrowseDir(wxCommandEvent &event)
Definition: edittooldlg.cpp:73
~EditToolDlg() override
Definition: edittooldlg.cpp:50
Definition: cbtool.h:13
void OnUpdateUI(wxUpdateUIEvent &event)
Definition: edittooldlg.cpp:57
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
#define _T(string)
void OnBrowseCommand(wxCommandEvent &event)
Definition: edittooldlg.cpp:65
void EndModal(int retCode) override
Definition: edittooldlg.cpp:80
void SetWorkingDir(const wxString &WorkingDir)
Definition: cbtool.h:36
const wxString & _(const wxString &string)
#define cbThrow(message)
Definition: cbexception.h:42
void SetLaunchOption(eLaunchOption LaunchOption)
Definition: cbtool.h:37
bool IsEmpty() const
wxString GetPath(int flags=wxPATH_GET_VOLUME, wxPathFormat format=wxPATH_NATIVE) const
cbTool * m_Tool
the tool we are editing (setting up)
Definition: edittooldlg.h:26
wxString GetFullName() const
void SetCommand(const wxString &Command)
Definition: cbtool.h:34
void SetParams(const wxString &Params)
Definition: cbtool.h:35
static wxXmlResource * Get()
void SetName(const wxString &Name)
Definition: cbtool.h:33
wxObject * LoadObject(wxWindow *parent, const wxString &name, const wxString &classname)