2
* This file is part of wxSmith plugin for Code::Blocks Studio
3
* Copyright (C) 2006-2007 Bartlomiej Swiecki
5
* wxSmith is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* wxSmith is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
19
* $Id: wxwidgetsguiappadoptingdlg.cpp 10272 2015-05-15 10:57:25Z jenslody $
20
* $HeadURL: http://svn.code.sf.net/p/codeblocks/code/branches/release-16.xx/src/plugins/contrib/wxSmith/wxwidgets/wxwidgetsguiappadoptingdlg.cpp $
24
#include "wxwidgetsguiappadoptingdlg.h"
25
#include "wxwidgetsgui.h"
27
#include <wx/filedlg.h>
28
#include <projectmanager.h>
30
//(*InternalHeaders(wxWidgetsGUIAppAdoptingDlg)
31
#include <wx/string.h>
35
//(*IdInit(wxWidgetsGUIAppAdoptingDlg)
36
const long wxWidgetsGUIAppAdoptingDlg::ID_LISTBOX1 = wxNewId();
37
const long wxWidgetsGUIAppAdoptingDlg::ID_GAUGE1 = wxNewId();
38
const long wxWidgetsGUIAppAdoptingDlg::ID_STATICTEXT1 = wxNewId();
39
const long wxWidgetsGUIAppAdoptingDlg::ID_STATICTEXT2 = wxNewId();
40
const long wxWidgetsGUIAppAdoptingDlg::ID_BUTTON5 = wxNewId();
41
const long wxWidgetsGUIAppAdoptingDlg::ID_BUTTON2 = wxNewId();
42
const long wxWidgetsGUIAppAdoptingDlg::ID_BUTTON3 = wxNewId();
43
const long wxWidgetsGUIAppAdoptingDlg::ID_STATICLINE2 = wxNewId();
44
const long wxWidgetsGUIAppAdoptingDlg::ID_BUTTON4 = wxNewId();
45
const long wxWidgetsGUIAppAdoptingDlg::ID_STATICLINE1 = wxNewId();
46
const long wxWidgetsGUIAppAdoptingDlg::ID_BUTTON6 = wxNewId();
49
BEGIN_EVENT_TABLE(wxWidgetsGUIAppAdoptingDlg,wxScrollingDialog)
50
//(*EventTable(wxWidgetsGUIAppAdoptingDlg)
52
EVT_CLOSE(wxWidgetsGUIAppAdoptingDlg::OnClose)
53
EVT_TIMER(1,wxWidgetsGUIAppAdoptingDlg::OnTimer)
56
wxWidgetsGUIAppAdoptingDlg::wxWidgetsGUIAppAdoptingDlg(wxWindow* parent,wxWidgetsGUI* GUI,wxWindowID id):
57
m_Project(GUI->GetProject()->GetCBProject()),
62
//(*Initialize(wxWidgetsGUIAppAdoptingDlg)
63
wxBoxSizer* BoxSizer3;
64
wxBoxSizer* BoxSizer1;
65
wxStaticBoxSizer* StaticBoxSizer1;
67
Create(parent, id, _("Integrating application class with wxSmith"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER, _T("id"));
68
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
69
StaticBoxSizer1 = new wxStaticBoxSizer(wxVERTICAL, this, _("Files with application class:"));
70
FoundFiles = new wxListBox(this, ID_LISTBOX1, wxDefaultPosition, wxSize(198,166), 0, 0, 0, wxDefaultValidator, _T("ID_LISTBOX1"));
71
StaticBoxSizer1->Add(FoundFiles, 1, wxEXPAND, 4);
72
Progress = new wxGauge(this, ID_GAUGE1, 100, wxDefaultPosition, wxSize(90,13), wxGA_SMOOTH, wxDefaultValidator, _T("ID_GAUGE1"));
73
StaticBoxSizer1->Add(Progress, 0, wxTOP|wxEXPAND, 4);
74
BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
75
ScanningTxt = new wxStaticText(this, ID_STATICTEXT1, _("Scanning:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
76
BoxSizer2->Add(ScanningTxt, 0, wxEXPAND, 4);
77
ScanningFile = new wxStaticText(this, ID_STATICTEXT2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
78
BoxSizer2->Add(ScanningFile, 1, wxLEFT|wxEXPAND, 5);
79
StaticBoxSizer1->Add(BoxSizer2, 0, wxTOP|wxEXPAND, 4);
80
BoxSizer1->Add(StaticBoxSizer1, 1, wxALIGN_CENTER_VERTICAL, 5);
81
BoxSizer3 = new wxBoxSizer(wxVERTICAL);
82
UseFileBtn = new wxButton(this, ID_BUTTON5, _("Use selected file"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON5"));
83
UseFileBtn->Disable();
84
BoxSizer3->Add(UseFileBtn, 0, wxEXPAND, 5);
85
SelectBtn = new wxButton(this, ID_BUTTON2, _("Select file manually"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
86
BoxSizer3->Add(SelectBtn, 0, wxTOP|wxEXPAND, 5);
87
CreateBtn = new wxButton(this, ID_BUTTON3, _("Create new file"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
88
BoxSizer3->Add(CreateBtn, 0, wxTOP|wxEXPAND, 5);
89
StaticLine2 = new wxStaticLine(this, ID_STATICLINE2, wxDefaultPosition, wxSize(50,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE2"));
90
BoxSizer3->Add(StaticLine2, 0, wxTOP|wxEXPAND, 5);
91
Button4 = new wxButton(this, ID_BUTTON4, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
92
Button4->SetDefault();
93
BoxSizer3->Add(Button4, 0, wxTOP|wxEXPAND, 5);
94
StaticLine1 = new wxStaticLine(this, ID_STATICLINE1, wxDefaultPosition, wxSize(50,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE1"));
95
BoxSizer3->Add(StaticLine1, 0, wxTOP|wxEXPAND, 5);
96
Button6 = new wxButton(this, ID_BUTTON6, _("What\'s this for \?"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON6"));
97
BoxSizer3->Add(Button6, 0, wxTOP|wxEXPAND, 5);
98
BoxSizer1->Add(BoxSizer3, 0, wxTOP|wxLEFT|wxALIGN_TOP, 5);
100
BoxSizer1->Fit(this);
101
BoxSizer1->SetSizeHints(this);
104
Connect(ID_BUTTON5,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxWidgetsGUIAppAdoptingDlg::OnUseFileBtnClick);
105
Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxWidgetsGUIAppAdoptingDlg::OnSelectBtnClick);
106
Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxWidgetsGUIAppAdoptingDlg::OnCreateBtnClick);
107
Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxWidgetsGUIAppAdoptingDlg::OnButton4Click);
108
Connect(ID_BUTTON6,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxWidgetsGUIAppAdoptingDlg::OnButton6Click);
111
m_Timer.Start(100,true);
114
wxWidgetsGUIAppAdoptingDlg::~wxWidgetsGUIAppAdoptingDlg()
116
//(*Destroy(wxWidgetsGUIAppAdoptingDlg)
120
void wxWidgetsGUIAppAdoptingDlg::OnButton6Click(wxCommandEvent& event)
123
_("In order to fully integrate wxSmith with wxWidgets application\n"
124
"it's required to do some modifications to source files with\n"
125
"application class. This will allow wxSmith to automatically\n"
126
"generate application initializing code.\n"
127
"By default wxSmith scans for sources automatically\n"
128
"and is able to properly modify required sources.\n"
129
"You can also specify source file with application\n"
130
"class manually or request to create new one.\n"),
131
_("Integrating application class with wxSmith"),
132
wxICON_ASTERISK|wxOK);
135
void wxWidgetsGUIAppAdoptingDlg::OnButton4Click(wxCommandEvent& event)
137
EndModal(wxID_CANCEL);
140
void wxWidgetsGUIAppAdoptingDlg::OnClose(wxCloseEvent& event)
146
void wxWidgetsGUIAppAdoptingDlg::OnTimer(wxTimerEvent& event)
151
void wxWidgetsGUIAppAdoptingDlg::OnUseFileBtnClick(wxCommandEvent& event)
153
int Index = FoundFiles->GetSelection();
154
if ( Index < 0 ) return;
155
AddSmith(FoundFiles->GetStringSelection());
158
void wxWidgetsGUIAppAdoptingDlg::Run()
160
Progress->SetRange(m_Project->GetFilesCount());
162
for (FilesList::iterator it = m_Project->GetFilesList().begin(); it != m_Project->GetFilesList().end(); ++it)
165
ProjectFile* File = *it;
166
ScanningFile->SetLabel(File->relativeFilename);
167
Progress->SetValue(++i);
168
if ( ScanFile(File) )
170
FoundFiles->Append(File->relativeFilename);
171
UseFileBtn->Enable();
174
ScanningFile->SetLabel(_("*** Done ***"));
177
void wxWidgetsGUIAppAdoptingDlg::AddSmith(wxString RelativeFileName)
179
wxsCodingLang Lang = wxsCodeMarks::IdFromExt(wxFileName(RelativeFileName).GetExt());
180
if ( Lang == wxsUnknownLanguage ) return;
182
if ( m_GUI->AddSmithToApp(RelativeFileName,Lang) )
184
wxMessageBox(_("Application class has been adopted. Please check if it\n"
185
"works fine (some application initializing code could\n"
192
bool wxWidgetsGUIAppAdoptingDlg::ScanFile(ProjectFile* File)
194
return m_GUI->ScanForApp(File);
197
void wxWidgetsGUIAppAdoptingDlg::OnSelectBtnClick(wxCommandEvent& event)
199
wxString FileName = ::wxFileSelector(
200
_("Select file with implementation of application class"),
204
_("C++ sources (*.cpp)|*.cpp|All files|*.*"),
205
wxFD_OPEN | wxFD_FILE_MUST_EXIST | compatibility::wxHideReadonly);
206
if ( FileName.empty() )
210
ProjectFile* PF = m_Project->GetFileByFilename(FileName,false,false);
213
wxMessageBox(_("This file is not included in project.\n"
214
"Please add this file to project first."),
215
_("File outside project"));
221
wxMessageBox(_("wxSmith is not able to adopt this file\n"
222
"(Please check if it contains implementation\n"
223
"of application class)"));
227
AddSmith(PF->relativeFilename);
230
void wxWidgetsGUIAppAdoptingDlg::OnCreateBtnClick(wxCommandEvent& event)
232
wxString FileName = ::wxFileSelector(
233
_("Please select cpp file where application class should be created"),
234
m_GUI->GetProjectPath(),
237
_T("C++ source files|*.cpp|All files|*"),
238
wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
240
if ( FileName.empty() ) return;
242
if ( m_Project->GetFileByFilename(FileName,false) == 0 )
244
// Adding new file to project
246
Manager::Get()->GetProjectManager()->AddFileToProject(FileName,m_Project, targets);
247
Manager::Get()->GetProjectManager()->GetUI().RebuildTree();
250
if ( m_GUI->CreateNewApp(FileName) )
252
wxMessageBox(_("New application class created"));
258
wxMessageBox(_("Error occured while creating new files"));