Menu

[r6913]: / branches / wxsmith_addons / src / sdk / selecttargetdlg.cpp  Maximize  Restore  History

Download this file

160 lines (143 with data), 5.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
* http://www.gnu.org/licenses/lgpl-3.0.html
*
* $Revision$
* $Id$
* $HeadURL$
*/
#include "sdk_precomp.h"
#ifndef CB_PRECOMP
#include <wx/button.h>
#include <wx/checkbox.h>
#include <wx/filename.h>
#include <wx/intl.h>
#include <wx/listbox.h>
#include <wx/textctrl.h>
#include <wx/xrc/xmlres.h>
#include "projectbuildtarget.h"
#include "cbproject.h"
#endif
#include <wx/filedlg.h>
#include "selecttargetdlg.h"
BEGIN_EVENT_TABLE(SelectTargetDlg, wxScrollingDialog)
EVT_CHECKBOX(XRCID("chkSetAsDefaultExec"), SelectTargetDlg::OnCheckboxSelection)
EVT_LISTBOX(XRCID("lstItems"), SelectTargetDlg::OnListboxSelection)
EVT_LISTBOX_DCLICK(XRCID("lstItems"), SelectTargetDlg::OnListboxDClick)
EVT_BUTTON(XRCID("btnHostApplication"), SelectTargetDlg::OnHostApplicationButtonClick)
END_EVENT_TABLE()
SelectTargetDlg::SelectTargetDlg(wxWindow* parent, cbProject* project, int selected)
: m_pProject(project),
m_Selected(selected)
{
//ctor
wxXmlResource::Get()->LoadObject(this, parent, _T("dlgSelectTarget"),_T("wxScrollingDialog"));
wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
list->Clear();
for (int i = 0; i < m_pProject->GetBuildTargetsCount(); ++i)
{
ProjectBuildTarget* target = m_pProject->GetBuildTarget(i);
list->Append(target->GetTitle());
}
if (selected != -1)
list->SetSelection(selected);
else
{
int item = list->FindString(m_pProject->GetActiveBuildTarget());
if (item == wxNOT_FOUND)
item = list->FindString(m_pProject->GetDefaultExecuteTarget());
list->SetSelection(item);
}
UpdateSelected();
XRCCTRL(*this, "wxID_OK", wxButton)->MoveBeforeInTabOrder (XRCCTRL(*this, "lstItems", wxListBox));
}
SelectTargetDlg::~SelectTargetDlg()
{
//dtor
}
void SelectTargetDlg::UpdateSelected()
{
wxString name = XRCCTRL(*this, "lstItems", wxListBox)->GetStringSelection();
ProjectBuildTarget* target = m_pProject->GetBuildTarget(name);
if (target)
{
XRCCTRL(*this, "chkSetAsDefaultExec", wxCheckBox)->SetValue(name == m_pProject->GetDefaultExecuteTarget());
XRCCTRL(*this, "txtParams", wxTextCtrl)->SetValue(target->GetExecutionParameters());
XRCCTRL(*this, "txtHostApp", wxTextCtrl)->SetValue(target->GetHostApplication());
}
XRCCTRL(*this, "wxID_OK", wxButton)->Enable(target);
} // end of UpdateSelected
ProjectBuildTarget* SelectTargetDlg::GetSelectionTarget()
{
return m_pProject->GetBuildTarget(m_Selected);
}
// events
void SelectTargetDlg::OnListboxSelection(wxCommandEvent& /*event*/)
{
UpdateSelected();
} // end of OnListboxSelection
void SelectTargetDlg::OnListboxDClick(wxCommandEvent& /*event*/)
{
UpdateSelected();
EndModal(wxID_OK);
} // end of OnListboxDClick
void SelectTargetDlg::OnCheckboxSelection(wxCommandEvent& /*event*/)
{
if (XRCCTRL(*this, "chkSetAsDefaultExec", wxCheckBox)->GetValue())
{
wxString name = XRCCTRL(*this, "lstItems", wxListBox)->GetStringSelection();
m_pProject->SetDefaultExecuteTarget(name);
}
} // end of OnCheckboxSelection
void SelectTargetDlg::OnHostApplicationButtonClick(wxCommandEvent& /*event*/)
{
if(wxTextCtrl* obj = XRCCTRL(*this, "txtHostApp", wxTextCtrl))
{
wxFileDialog dlg(this,
_("Select host application"),
_T(""),
obj->GetValue(),
#ifdef __WXMSW__
_("Executable files (*.exe)|*.exe"),
#else
_("All files (*)|*"),
#endif
wxFD_OPEN | wxFD_FILE_MUST_EXIST | compatibility::wxHideReadonly);
dlg.SetFilterIndex(0);
PlaceWindow(&dlg);
if (dlg.ShowModal() != wxID_OK)
return;
wxFileName fname(dlg.GetPath());
if (fname.GetFullPath().StartsWith(m_pProject->GetCommonTopLevelPath()))
{
fname.MakeRelativeTo(m_pProject->GetCommonTopLevelPath());
obj->SetValue(fname.GetFullPath());
}
else
obj->SetValue(fname.GetFullPath());
}
} // end of OnHostApplicationButtonClick
void SelectTargetDlg::EndModal(int retCode)
{
if (retCode == wxID_OK)
{
m_Selected = XRCCTRL(*this, "lstItems", wxListBox)->GetSelection();
ProjectBuildTarget* target = m_pProject->GetBuildTarget(m_Selected);
if (target)
{
// Search all '\n' in the program-parameters and replace them by
// ' '. This is necessary because a multiline text control may add
// '\n' to the text but these characters must not be part of the
// parameters when executing the program.
wxString execution_parameters = XRCCTRL(*this, "txtParams", wxTextCtrl)->GetValue();
wxString::size_type pos = 0;
while ((pos = execution_parameters.find('\n', pos)) != wxString::npos)
{
execution_parameters[pos] = ' ';
}
target->SetExecutionParameters(execution_parameters);
target->SetHostApplication(XRCCTRL(*this, "txtHostApp", wxTextCtrl)->GetValue());
}
}
wxScrollingDialog::EndModal(retCode);
} // end of EndModal
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.