1
//////////////////////////////////////////////////////////////////////////////
2
//////////////////////////////////////////////////////////////////////////////
4
// copyright : (C) 2008 by Eran Ifrah
5
// file name : new_item_dlg.cpp
7
// -------------------------------------------------------------------------
10
// / __ \ | | | | (_) |
11
// | / \/ ___ __| | ___| | _| |_ ___
12
// | | / _ \ / _ |/ _ \ | | | __/ _ )
13
// | \__/\ (_) | (_| | __/ |___| | || __/
14
// \____/\___/ \__,_|\___\_____/_|\__\___|
18
// This program is free software; you can redistribute it and/or modify
19
// it under the terms of the GNU General Public License as published by
20
// the Free Software Foundation; either version 2 of the License, or
21
// (at your option) any later version.
23
//////////////////////////////////////////////////////////////////////////////
24
//////////////////////////////////////////////////////////////////////////////
25
///////////////////////////////////////////////////////////////////////////
26
// C++ code generated with wxFormBuilder (version Feb 1 2007)
27
// http://www.wxformbuilder.org/
29
// PLEASE DO "NOT" EDIT THIS FILE!
30
///////////////////////////////////////////////////////////////////////////
32
#include "wx/wxprec.h"
42
#include "new_item_dlg.h"
43
#include "windowattrmanager.h"
45
#include "wx/xrc/xmlres.h"
46
#include "wx/textctrl.h"
49
#include <wx/imaglist.h>
51
static const wxString FileTypeCpp = wxT("C++ Source File (.cpp)");
52
static const wxString FileTypeC = wxT("C Source File (.c)");
53
static const wxString FileTypeHeader = wxT("Header File (.h)");
54
static const wxString FileTypeAny = wxT("Any File");
56
///////////////////////////////////////////////////////////////////////////
58
BEGIN_EVENT_TABLE(NewItemDlg, NewItemBaseDlg)
59
EVT_CHAR_HOOK(NewItemDlg::OnCharHook)
62
NewItemDlg::NewItemDlg( wxWindow* parent, wxString cwd)
63
: NewItemBaseDlg(parent)
66
m_fileType->InsertColumn(0, _("File Type"));
67
m_fileType->SetColumnWidth(0, 300);
69
// Initialise images map
70
wxImageList *images = new wxImageList(16, 16, true);
71
images->Add(wxXmlResource::Get()->LoadBitmap(_T("page_white_c"))); //0
72
images->Add(wxXmlResource::Get()->LoadBitmap(_T("page_white_cplusplus"))); //1
73
images->Add(wxXmlResource::Get()->LoadBitmap(_T("page_white_h"))); //2
74
images->Add(wxXmlResource::Get()->LoadBitmap(_T("page_white_text"))); //3
76
m_fileType->AssignImageList( images, wxIMAGE_LIST_SMALL );
78
//-----------------------------------
80
m_fileTypeValue = FileTypeCpp;
82
long row = AppendListCtrlRow(m_fileType);
83
SetColumnText(m_fileType, row, 0, FileTypeCpp, 1);
85
row = AppendListCtrlRow(m_fileType);
86
SetColumnText(m_fileType, row, 0, FileTypeC, 0);
88
row = AppendListCtrlRow(m_fileType);
89
SetColumnText(m_fileType, row, 0, FileTypeHeader, 2);
91
row = AppendListCtrlRow(m_fileType);
92
SetColumnText(m_fileType, row, 0, FileTypeAny, 3);
93
m_fileTypeValue = FileTypeAny;
95
//select the last item
96
m_fileType->SetItemState(row, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
97
m_fileType->SetItemState(row, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
99
m_location->SetValue(m_cwd);
100
m_fileName->SetFocus();
104
WindowAttrManager::Load(this, wxT("NewItemDlg"), NULL);
107
void NewItemDlg::ConnectEvents()
109
m_cancel->Connect(m_cancel->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(NewItemDlg::OnClick), NULL, this);
110
m_okButton->Connect(m_okButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(NewItemDlg::OnClick), NULL, this);
111
m_browseBtn->Connect(m_browseBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(NewItemDlg::OnClick), NULL, this);
112
m_fileType->Connect(m_fileType->GetId(), wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler(NewItemDlg::OnListItemSelected), NULL, this);
116
void NewItemDlg::OnClick(wxCommandEvent &event)
118
int id = event.GetId();
119
if ( id == m_okButton->GetId() )
123
else if ( id == m_cancel->GetId() )
125
EndModal(wxID_CANCEL);
127
else if ( id == m_browseBtn->GetId() )
130
wxDirDialog *dlg = new wxDirDialog(this, wxT("Location:"), m_cwd);
131
if (dlg->ShowModal() == wxID_OK)
133
m_location->SetValue(dlg->GetPath());
139
void NewItemDlg::DoCreateFile()
142
if ( !Validate(errMsg) )
144
wxMessageBox(errMsg, wxT("CodeLite"), wxICON_INFORMATION | wxOK);
148
// Construct the file name
149
wxString fileName(m_fileName->GetValue());
150
TrimString(fileName);
152
if (m_fileTypeValue == FileTypeAny)
154
m_newFileName = wxFileName(m_location->GetValue(),fileName);
156
else if ( m_fileTypeValue == FileTypeC )
158
// If user already provided suffix, dont add another one on top of it
159
if (fileName.Find(wxT(".")) == wxNOT_FOUND )
161
m_newFileName = wxFileName(m_location->GetValue(),fileName, wxT("c"));
165
m_newFileName = wxFileName(m_location->GetValue(),fileName);
168
else if ( m_fileTypeValue == FileTypeCpp )
170
// If user already provided suffix, dont add another one on top of it
171
if (fileName.Find(wxT(".")) == wxNOT_FOUND )
173
m_newFileName = wxFileName(m_location->GetValue(),fileName, wxT("cpp"));
177
m_newFileName = wxFileName(m_location->GetValue(),fileName);
180
else if ( m_fileTypeValue == FileTypeHeader )
182
// If user already provided suffix, dont add another one on top of it
183
if (fileName.Find(wxT(".")) == wxNOT_FOUND )
185
m_newFileName = wxFileName(m_location->GetValue(),fileName, wxT("h"));
189
m_newFileName = wxFileName(m_location->GetValue(),fileName);
195
bool NewItemDlg::Validate(wxString &errMsg)
197
// make sure we have file name & path set up correctly
198
wxFileName fn(m_location->GetValue() + wxFileName::GetPathSeparator());
200
if ( m_location->GetValue().Trim().IsEmpty() )
202
errMsg = wxT("Missing location");
206
if ( !fn.DirExists() )
208
errMsg = wxT("Directory: ");
209
errMsg << fn.GetPath() << wxT(" does not exist");
213
fn = wxFileName(m_location->GetValue(), m_fileName->GetValue());
214
if ( fn.FileExists() )
216
errMsg = wxT("A file with that name already exist, please choose different name");
220
if ( m_fileName->GetValue().Trim().IsEmpty() )
222
errMsg = wxT("Missing file name");
229
void NewItemDlg::OnListItemSelected(wxListEvent &event)
231
m_fileTypeValue = event.GetText();
234
void NewItemDlg::OnCharHook(wxKeyEvent &event)
236
if (event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER)
243
NewItemDlg::~NewItemDlg()
245
WindowAttrManager::Save(this, wxT("NewItemDlg"), NULL);