Code::Blocks  SVN r11506
filepathpanel.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  *
5  * $Revision: 10270 $
6  * $Id: filepathpanel.cpp 10270 2015-05-15 10:57:08Z jenslody $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/scriptedwizard/filepathpanel.cpp $
8  */
9 
10 #include <sdk.h>
11 #ifndef CB_PRECOMP
12  #include <wx/filedlg.h>
13  //(*InternalHeadersPCH(FilePathPanel)
14  #include <wx/string.h>
15  #include <wx/intl.h>
16  //*)
17  #include <cbproject.h>
18  #include <projectbuildtarget.h>
19  #include <projectmanager.h>
20  #include <manager.h>
21 #endif
22 #include <wx/filefn.h>
23 #include "filepathpanel.h"
24 
25 //(*IdInit(FilePathPanel)
29 const long FilePathPanel::ID_BUTTON1 = wxNewId();
35 const long FilePathPanel::ID_BUTTON2 = wxNewId();
36 const long FilePathPanel::ID_BUTTON3 = wxNewId();
37 //*)
38 
39 BEGIN_EVENT_TABLE(FilePathPanel,wxPanel)
40  //(*EventTable(FilePathPanel)
41  //*)
42 END_EVENT_TABLE()
43 
45  m_Selection(-1)
46 {
47  //(*Initialize(FilePathPanel)
48  wxStaticText* StaticText1;
49  wxStaticText* StaticText4;
50  wxBoxSizer* BoxSizer1;
51  wxStaticText* StaticText2;
52 
53  Create(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("id"));
54  BoxSizer1 = new wxBoxSizer(wxVERTICAL);
55  StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Please enter the file\'s location and name and\nwhether to add it to the active project."), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
56  BoxSizer1->Add(StaticText1, 0, wxALL|wxALIGN_LEFT, 8);
57  StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Filename with full path:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
58  BoxSizer1->Add(StaticText2, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 8);
59  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
60  txtFilename = new wxTextCtrl(this, ID_TEXTCTRL1, _("Text"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
61  BoxSizer2->Add(txtFilename, 1, wxALL|wxALIGN_TOP, 0);
62  btnBrowse = new wxButton(this, ID_BUTTON1, _("..."), wxDefaultPosition, wxSize(22,22), 0, wxDefaultValidator, _T("ID_BUTTON1"));
63  BoxSizer2->Add(btnBrowse, 0, wxALL|wxALIGN_TOP, 0);
64  BoxSizer1->Add(BoxSizer2, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 8);
65  lblGuard = new wxStaticText(this, ID_STATICTEXT3, _("Header guard word:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
66  BoxSizer1->Add(lblGuard, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 8);
67  txtGuard = new wxTextCtrl(this, ID_TEXTCTRL2, _("Text"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
68  BoxSizer1->Add(txtGuard, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 8);
69  BoxSizer1->Add(-1,-1,0, wxALL|wxEXPAND, 0);
70  chkAddToProject = new wxCheckBox(this, ID_CHECKBOX1, _("Add file to active project"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
71  chkAddToProject->SetValue(false);
72  BoxSizer1->Add(chkAddToProject, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 8);
73  FlexGridSizer1 = new wxFlexGridSizer(0, 2, 0, 0);
74  FlexGridSizer1->AddGrowableCol(1);
75  FlexGridSizer1->AddGrowableRow(1);
76  FlexGridSizer1->Add(16,16,0, wxALL|wxALIGN_TOP, 0);
77  StaticText4 = new wxStaticText(this, ID_STATICTEXT4, _("In build target(s):"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
78  FlexGridSizer1->Add(StaticText4, 0, wxALL|wxEXPAND, 0);
79  FlexGridSizer1->Add(16,16,0, wxALL|wxALIGN_TOP, 0);
80  clbTargets = new wxCheckListBox(this, ID_CHECKLISTBOX2, wxDefaultPosition, wxSize(222,111), 0, 0, wxLB_SINGLE|wxLB_HSCROLL, wxDefaultValidator, _T("ID_CHECKLISTBOX2"));
81  clbTargets->Disable();
82  FlexGridSizer1->Add(clbTargets, 1, wxALL|wxEXPAND|wxFIXED_MINSIZE, 0);
83  FlexGridSizer1->Add(16,16,0, wxALL|wxALIGN_TOP, 0);
84  BoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
85  btnAll = new wxButton(this, ID_BUTTON2, _("All"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
86  btnAll->Disable();
87  BoxSizer6->Add(btnAll, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 4);
88  btnNone = new wxButton(this, ID_BUTTON3, _("None"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
89  btnNone->Disable();
90  BoxSizer6->Add(btnNone, 0, wxALIGN_CENTER_VERTICAL, 0);
91  FlexGridSizer1->Add(BoxSizer6, 0, wxALL|wxALIGN_TOP, 0);
92  BoxSizer1->Add(FlexGridSizer1, 1, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 8);
93  BoxSizer3 = new wxBoxSizer(wxVERTICAL);
94  BoxSizer1->Add(BoxSizer3, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 8);
95  SetSizer(BoxSizer1);
96  BoxSizer1->Fit(this);
97  BoxSizer1->SetSizeHints(this);
98 
99  Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&FilePathPanel::OntxtFilenameText);
100  Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&FilePathPanel::OnbtnBrowseClick);
101  Connect(ID_CHECKBOX1,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&FilePathPanel::OnchkAddToProjectChange);
102  Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&FilePathPanel::OnbtnAllClick);
103  Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&FilePathPanel::OnbtnNoneClick);
104  //*)
105 
106  txtFilename->SetValue(wxEmptyString);
107  txtGuard->SetValue(wxEmptyString);
108 
109  // fill targets list
111  if (prj)
112  {
113  clbTargets->Clear();
114  for (int i = 0; i < prj->GetBuildTargetsCount(); ++i)
115  {
116  ProjectBuildTarget* bt = prj->GetBuildTarget(i);
117  if (bt)
118  clbTargets->Append(bt->GetTitle());
119  }
120  clbTargets->SetSelection(clbTargets->FindString(prj->GetActiveBuildTarget()));
121  chkAddToProject->SetValue(true);
122  ToggleVisibility(true);
123  }
124  else
125  {
126  chkAddToProject->SetValue(false);
127  ToggleVisibility(false);
128  }
129 }
130 
132 {
133 }
134 
136 {
138  add = add && prj;
140 
141  ToggleVisibility(add);
142 }
143 
144 // note : design not so nice because the function is not const !!!
146 {
147  int selection = -1;
148 
149  if (m_Selection > static_cast<int>(clbTargets->GetCount()) - 2) // (m_Selection >= clbTargets->GetCount()-1)
150  {
151  m_Selection = -1; // Reset -> notify about "last item" with -1
152  return m_Selection;
153  }
154 
155  // start with next (x+1) or first (-1+1 = 0) item
156  for (selection = m_Selection + 1; selection < static_cast<int>(clbTargets->GetCount()); ++selection)
157  {
158  if (clbTargets->IsChecked(selection))
159  break; // selection found. break for-loop to save item's index
160  }
161 
162  m_Selection = selection; // return current selected items index (-1 if nothing selected)
163 
164  return m_Selection;
165 }
166 
168 {
169  if (!txtFilename || txtFilename->GetValue().IsEmpty())
170  return;
171  wxString name = wxFileNameFromPath(txtFilename->GetValue());
172  while (name.Replace(_T(" "), _T("_")))
173  ;
174  while (name.Replace(_T("\t"), _T("_")))
175  ;
176  while (name.Replace(_T("."), _T("_")))
177  ;
178  name.MakeUpper();
179  name << _T("_INCLUDED");
180  txtGuard->SetValue(name);
181 }
182 
184 {
186  wxFileDialog dlg(this,
187  _("Select filename"),
188  prj ? prj->GetBasePath() : _T(""),
189  txtFilename->GetValue(),
190  m_ExtFilter,
192  PlaceWindow(&dlg);
193  if (dlg.ShowModal() == wxID_OK)
194  txtFilename->SetValue(dlg.GetPath());
195 }
196 
198 {
199  SetAddToProject(event.IsChecked());
200 }
201 
203 {
204  for (int i = 0; i < static_cast<int>(clbTargets->GetCount()); ++i)
205  {
206  clbTargets->Check(i, true);
207  }
208 } // end of OnbtnAllClick
209 
211 {
212  for (int i = 0; i < static_cast<int>(clbTargets->GetCount()); ++i)
213  {
214  clbTargets->Check(i, false);
215  }
216 } // end of OnbtnNoneClick
217 
219 {
220  clbTargets->Enable(on);
221  btnAll->Enable(on);
222  btnNone->Enable(on);
223 }
wxSize Fit(wxWindow *window)
wxCheckBox * chkAddToProject
Definition: filepathpanel.h:72
static const long ID_BUTTON1
Definition: filepathpanel.h:45
int wxNewId()
wxButton * btnNone
Definition: filepathpanel.h:74
static const long ID_TEXTCTRL1
Definition: filepathpanel.h:44
const wxValidator wxDefaultValidator
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
static const long ID_BUTTON3
Definition: filepathpanel.h:52
wxButton * btnAll
Definition: filepathpanel.h:66
wxTextCtrl * txtFilename
Definition: filepathpanel.h:73
#define _T(string)
void OntxtFilenameText(wxCommandEvent &event)
static const long ID_STATICTEXT1
Definition: filepathpanel.h:42
bool IsChecked(unsigned int item) const
void ToggleVisibility(bool on)
const long ID_TEXTCTRL1
wxString m_ExtFilter
Definition: filepathpanel.h:80
ProjectManager * GetProjectManager() const
Functions returning pointers to the respective sub-manager instances.
Definition: manager.cpp:429
Represents a Code::Blocks project.
Definition: cbproject.h:96
const wxString & GetActiveBuildTarget() const
Definition: cbproject.cpp:1373
virtual const wxString & GetTitle() const
Read the target&#39;s title.
static const long ID_BUTTON2
Definition: filepathpanel.h:51
#define wxTAB_TRAVERSAL
wxSizerItem * Add(wxWindow *window, const wxSizerFlags &flags)
size_t Replace(const wxString &strOld, const wxString &strNew, bool replaceAll=true)
void Check(unsigned int item, bool check=true)
const wxSize wxDefaultSize
const wxPoint wxDefaultPosition
cbProject * GetActiveProject()
Retrieve the active project.
static const long ID_STATICTEXT2
Definition: filepathpanel.h:43
virtual wxString GetBasePath() const
Read the target&#39;s base path, e.g. if GetFilename() returns "/usr/local/bin/xxx", base path will retur...
#define wxLB_SINGLE
virtual ~FilePathPanel()
static const long ID_CHECKBOX1
Definition: filepathpanel.h:48
wxString wxEmptyString
void OnbtnAllClick(wxCommandEvent &event)
const wxString & _(const wxString &string)
void OnbtnBrowseClick(wxCommandEvent &event)
int GetBuildTargetsCount()
Definition: cbproject.h:200
static const long ID_CHECKLISTBOX2
Definition: filepathpanel.h:50
ProjectBuildTarget * GetBuildTarget(int index)
Access a build target.
Definition: cbproject.cpp:1392
static const long ID_TEXTCTRL2
Definition: filepathpanel.h:47
DLLIMPORT void PlaceWindow(wxTopLevelWindow *w, cbPlaceDialogMode mode=pdlBest, bool enforce=false)
Definition: globals.cpp:1177
void SetAddToProject(bool add)
void SetSizeHints(wxWindow *window)
#define wxLB_HSCROLL
static const long ID_STATICTEXT3
Definition: filepathpanel.h:46
Represents a Code::Blocks project build target.
wxTextCtrl * txtGuard
Definition: filepathpanel.h:76
static const long ID_STATICTEXT4
Definition: filepathpanel.h:49
wxCheckListBox * clbTargets
Definition: filepathpanel.h:70
virtual void SetValue(bool state)
int wxWindowID
void OnbtnNoneClick(wxCommandEvent &event)
wxString & MakeUpper()
virtual unsigned int GetCount() const
void OnchkAddToProjectChange(wxCommandEvent &event)
wxString wxFileNameFromPath(const wxString &path)