Code::Blocks  SVN r11506
projectpathpanel.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: projectpathpanel.cpp 10270 2015-05-15 10:57:08Z jenslody $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/scriptedwizard/projectpathpanel.cpp $
8  */
9 
10 #include <sdk.h>
11 #ifndef CB_PRECOMP
12  #include <wx/filename.h>
13  //(*InternalHeadersPCH(ProjectPathPanel)
14  #include <wx/string.h>
15  #include <wx/intl.h>
16  //*)
17 #endif // CB_PRECOMP
18 #include <filefilters.h>
19 
20 #include "projectpathpanel.h"
21 
22 
23 //(*IdInit(ProjectPathPanel)
34 //*)
35 
36 BEGIN_EVENT_TABLE(ProjectPathPanel,wxPanel)
37  //(*EventTable(ProjectPathPanel)
38  //*)
39 END_EVENT_TABLE()
40 
42  m_LockUpdates(false)
43 {
44  //(*Initialize(ProjectPathPanel)
45  wxStaticText* StaticText1;
46  wxStaticText* StaticText3;
47  wxStaticText* StaticText4;
48  wxStaticText* StaticText5;
49  wxStaticText* StaticText2;
50 
51  Create(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("id"));
52  BoxSizer1 = new wxBoxSizer(wxVERTICAL);
53  StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Please select the folder where you want the new project\nto be created as well as its title."), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
54  BoxSizer1->Add(StaticText1, 0, wxALL|wxEXPAND, 8);
55  StaticText4 = new wxStaticText(this, ID_STATICTEXT4, _("Project title:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
56  BoxSizer1->Add(StaticText4, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 8);
57  txtPrjTitle = new wxTextCtrl(this, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
58  BoxSizer1->Add(txtPrjTitle, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 8);
59  StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Folder to create project in:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
60  BoxSizer1->Add(StaticText2, 0, wxLEFT|wxRIGHT|wxEXPAND, 8);
61  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
62  txtPrjPath = new wxTextCtrl(this, ID_TEXTCTRL1, _("Text"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
63  BoxSizer2->Add(txtPrjPath, 1, wxALIGN_CENTER_VERTICAL, 5);
64  btnPrjPathBrowse = new wxButton(this, ID_BUTTON1, _("..."), wxDefaultPosition, wxSize(22,22), 0, wxDefaultValidator, _T("ID_BUTTON1"));
65  BoxSizer2->Add(btnPrjPathBrowse, 0, wxALIGN_CENTER_VERTICAL, 5);
66  BoxSizer1->Add(BoxSizer2, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 8);
67  StaticText3 = new wxStaticText(this, ID_STATICTEXT3, _("Project filename:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
68  BoxSizer1->Add(StaticText3, 0, wxLEFT|wxRIGHT|wxEXPAND, 8);
69  txtPrjName = new wxTextCtrl(this, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
70  BoxSizer1->Add(txtPrjName, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 8);
71  StaticText5 = new wxStaticText(this, ID_STATICTEXT5, _("Resulting filename:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
72  BoxSizer1->Add(StaticText5, 0, wxLEFT|wxRIGHT|wxALIGN_LEFT, 8);
73  txtFinalDir = new wxTextCtrl(this, ID_TEXTCTRL4, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL4"));
74  BoxSizer1->Add(txtFinalDir, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 8);
75  SetSizer(BoxSizer1);
76  BoxSizer1->Fit(this);
77  BoxSizer1->SetSizeHints(this);
78 
79  Connect(ID_TEXTCTRL3,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&ProjectPathPanel::OntxtPrjTitleText);
80  Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&ProjectPathPanel::OnFullPathChanged);
81  Connect(ID_TEXTCTRL2,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&ProjectPathPanel::OnFullPathChanged);
82  Connect(ID_TEXTCTRL4,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&ProjectPathPanel::OntxtFinalDirText);
83  //*)
84 }
85 
87 {
88 }
89 
91 {
92  if (m_LockUpdates || !txtPrjPath || !txtPrjName || !txtFinalDir || txtFinalDir->GetValue().IsEmpty())
93  return; // not ready yet
94 
95  m_LockUpdates = true;
96  wxFileName fn = txtFinalDir->GetValue();
97  txtPrjPath->SetValue(fn.GetPath(wxPATH_GET_VOLUME));
98  txtPrjName->SetValue(fn.GetName());
99  m_LockUpdates = false;
100 }
101 
103 {
105  return; // not ready yet
106 
107  wxString final = txtPrjPath->GetValue();
108  if (!final.IsEmpty())
109  {
110  wxFileName fname(txtPrjName->GetValue());
111  wxFileName prjpath(final, wxEmptyString);
112  fname.MakeAbsolute(prjpath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + fname.GetName());
113  final = fname.GetFullPath();
114  }
115  if (final.IsEmpty() || txtPrjName->GetValue().IsEmpty())
116  final = _("<invalid path>");
117 
118  m_LockUpdates = true;
119  txtFinalDir->SetValue(final);
120  m_LockUpdates = false;
121 }
122 
124 {
125  Update();
126 }
127 
129 {
130  if (!txtPrjName->GetValue().StartsWith(_("<invalid path>")))
132 }
133 
135 {
136  wxString prjtitle = txtPrjTitle->GetValue();
137  // Make a check if the project title has any extension or not
138  if (!prjtitle.IsEmpty() &&
140  prjtitle = prjtitle + FileFilters::CODEBLOCKS_DOT_EXT;
141  txtPrjName->SetValue(prjtitle);
142 
143 // FIXME (Biplab#1#): In Linux, text update event is not thrown
144  if (!platform::windows)
145  Update();
146 }
void OntxtPrjTitleText(wxCommandEvent &event)
static const long ID_TEXTCTRL2
wxTextCtrl * txtPrjTitle
int wxNewId()
static const long ID_STATICTEXT1
static const long ID_TEXTCTRL3
const wxValidator wxDefaultValidator
static const long ID_BUTTON1
static const long ID_TEXTCTRL1
static const long ID_STATICTEXT5
static const long ID_STATICTEXT2
#define _T(string)
wxString GetName() const
wxTextCtrl * txtPrjPath
const long ID_TEXTCTRL1
void OnFullPathChanged(wxCommandEvent &event)
static const long ID_TEXTCTRL4
#define wxTAB_TRAVERSAL
const wxSize wxDefaultSize
const wxPoint wxDefaultPosition
bool IsSameAs(const wxString &s, bool caseSensitive=true) const
wxTextCtrl * txtPrjName
virtual ~ProjectPathPanel()
wxString wxEmptyString
wxString Right(size_t count) const
void OntxtFinalDirText(wxCommandEvent &event)
const wxString & _(const wxString &string)
static const long ID_STATICTEXT4
bool IsEmpty() const
wxString GetPath(int flags=wxPATH_GET_VOLUME, wxPathFormat format=wxPATH_NATIVE) const
wxTextCtrl * txtFinalDir
const DLLIMPORT wxString CODEBLOCKS_DOT_EXT
static const long ID_STATICTEXT3
int wxWindowID