~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmith/wxwidgets/wxwidgetsguiappadoptingdlg.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* This file is part of wxSmith plugin for Code::Blocks Studio
 
3
* Copyright (C) 2006-2007  Bartlomiej Swiecki
 
4
*
 
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.
 
9
*
 
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.
 
14
*
 
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/>.
 
17
*
 
18
* $Revision: 10272 $
 
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 $
 
21
*/
 
22
 
 
23
#include <prep.h>
 
24
#include "wxwidgetsguiappadoptingdlg.h"
 
25
#include "wxwidgetsgui.h"
 
26
 
 
27
#include <wx/filedlg.h>
 
28
#include <projectmanager.h>
 
29
 
 
30
//(*InternalHeaders(wxWidgetsGUIAppAdoptingDlg)
 
31
#include <wx/string.h>
 
32
#include <wx/intl.h>
 
33
//*)
 
34
 
 
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();
 
47
//*)
 
48
 
 
49
BEGIN_EVENT_TABLE(wxWidgetsGUIAppAdoptingDlg,wxScrollingDialog)
 
50
    //(*EventTable(wxWidgetsGUIAppAdoptingDlg)
 
51
    //*)
 
52
    EVT_CLOSE(wxWidgetsGUIAppAdoptingDlg::OnClose)
 
53
    EVT_TIMER(1,wxWidgetsGUIAppAdoptingDlg::OnTimer)
 
54
END_EVENT_TABLE()
 
55
 
 
56
wxWidgetsGUIAppAdoptingDlg::wxWidgetsGUIAppAdoptingDlg(wxWindow* parent,wxWidgetsGUI* GUI,wxWindowID id):
 
57
    m_Project(GUI->GetProject()->GetCBProject()),
 
58
    m_GUI(GUI),
 
59
    m_Timer(this,1),
 
60
    m_Run(true)
 
61
{
 
62
    //(*Initialize(wxWidgetsGUIAppAdoptingDlg)
 
63
    wxBoxSizer* BoxSizer3;
 
64
    wxBoxSizer* BoxSizer1;
 
65
    wxStaticBoxSizer* StaticBoxSizer1;
 
66
 
 
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);
 
99
    SetSizer(BoxSizer1);
 
100
    BoxSizer1->Fit(this);
 
101
    BoxSizer1->SetSizeHints(this);
 
102
    Center();
 
103
 
 
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);
 
109
    //*)
 
110
 
 
111
    m_Timer.Start(100,true);
 
112
}
 
113
 
 
114
wxWidgetsGUIAppAdoptingDlg::~wxWidgetsGUIAppAdoptingDlg()
 
115
{
 
116
    //(*Destroy(wxWidgetsGUIAppAdoptingDlg)
 
117
    //*)
 
118
}
 
119
 
 
120
void wxWidgetsGUIAppAdoptingDlg::OnButton6Click(wxCommandEvent& event)
 
121
{
 
122
    wxMessageBox(
 
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);
 
133
}
 
134
 
 
135
void wxWidgetsGUIAppAdoptingDlg::OnButton4Click(wxCommandEvent& event)
 
136
{
 
137
    EndModal(wxID_CANCEL);
 
138
}
 
139
 
 
140
void wxWidgetsGUIAppAdoptingDlg::OnClose(wxCloseEvent& event)
 
141
{
 
142
    m_Run = false;
 
143
    event.Skip();
 
144
}
 
145
 
 
146
void wxWidgetsGUIAppAdoptingDlg::OnTimer(wxTimerEvent& event)
 
147
{
 
148
    Run();
 
149
}
 
150
 
 
151
void wxWidgetsGUIAppAdoptingDlg::OnUseFileBtnClick(wxCommandEvent& event)
 
152
{
 
153
    int Index = FoundFiles->GetSelection();
 
154
    if ( Index < 0 ) return;
 
155
    AddSmith(FoundFiles->GetStringSelection());
 
156
}
 
157
 
 
158
void wxWidgetsGUIAppAdoptingDlg::Run()
 
159
{
 
160
    Progress->SetRange(m_Project->GetFilesCount());
 
161
    int i = 0;
 
162
    for (FilesList::iterator it = m_Project->GetFilesList().begin(); it != m_Project->GetFilesList().end(); ++it)
 
163
    {
 
164
        Manager::Yield();
 
165
        ProjectFile* File = *it;
 
166
        ScanningFile->SetLabel(File->relativeFilename);
 
167
        Progress->SetValue(++i);
 
168
        if ( ScanFile(File) )
 
169
        {
 
170
            FoundFiles->Append(File->relativeFilename);
 
171
            UseFileBtn->Enable();
 
172
        }
 
173
    }
 
174
    ScanningFile->SetLabel(_("*** Done ***"));
 
175
}
 
176
 
 
177
void wxWidgetsGUIAppAdoptingDlg::AddSmith(wxString RelativeFileName)
 
178
{
 
179
    wxsCodingLang Lang = wxsCodeMarks::IdFromExt(wxFileName(RelativeFileName).GetExt());
 
180
    if ( Lang == wxsUnknownLanguage ) return;
 
181
 
 
182
    if ( m_GUI->AddSmithToApp(RelativeFileName,Lang) )
 
183
    {
 
184
        wxMessageBox(_("Application class has been adopted. Please check if it\n"
 
185
                       "works fine (some application initializing code could\n"
 
186
                       "be skipped)."));
 
187
        m_Run = false;
 
188
        EndModal(wxID_OK);
 
189
    }
 
190
}
 
191
 
 
192
bool wxWidgetsGUIAppAdoptingDlg::ScanFile(ProjectFile* File)
 
193
{
 
194
    return m_GUI->ScanForApp(File);
 
195
}
 
196
 
 
197
void wxWidgetsGUIAppAdoptingDlg::OnSelectBtnClick(wxCommandEvent& event)
 
198
{
 
199
    wxString FileName = ::wxFileSelector(
 
200
        _("Select file with implementation of application class"),
 
201
        _T(""),
 
202
        _T(""),
 
203
        _T(""),
 
204
        _("C++ sources (*.cpp)|*.cpp|All files|*.*"),
 
205
        wxFD_OPEN | wxFD_FILE_MUST_EXIST | compatibility::wxHideReadonly);
 
206
    if ( FileName.empty() )
 
207
    {
 
208
        return;
 
209
    }
 
210
    ProjectFile* PF = m_Project->GetFileByFilename(FileName,false,false);
 
211
    if ( !PF )
 
212
    {
 
213
        wxMessageBox(_("This file is not included in project.\n"
 
214
                       "Please add this file to project first."),
 
215
                     _("File outside project"));
 
216
        return;
 
217
    }
 
218
 
 
219
    if ( !ScanFile(PF) )
 
220
    {
 
221
        wxMessageBox(_("wxSmith is not able to adopt this file\n"
 
222
                       "(Please check if it contains implementation\n"
 
223
                       "of application class)"));
 
224
        return;
 
225
    }
 
226
 
 
227
    AddSmith(PF->relativeFilename);
 
228
}
 
229
 
 
230
void wxWidgetsGUIAppAdoptingDlg::OnCreateBtnClick(wxCommandEvent& event)
 
231
{
 
232
    wxString FileName = ::wxFileSelector(
 
233
        _("Please select cpp file where application class should be created"),
 
234
        m_GUI->GetProjectPath(),
 
235
        _T("myapp.cpp"),
 
236
        _T("cpp"),
 
237
        _T("C++ source files|*.cpp|All files|*"),
 
238
        wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
 
239
 
 
240
    if ( FileName.empty() ) return;
 
241
 
 
242
    if ( m_Project->GetFileByFilename(FileName,false) == 0 )
 
243
    {
 
244
        // Adding new file to project
 
245
        wxArrayInt targets;
 
246
        Manager::Get()->GetProjectManager()->AddFileToProject(FileName,m_Project, targets);
 
247
        Manager::Get()->GetProjectManager()->GetUI().RebuildTree();
 
248
    }
 
249
 
 
250
    if ( m_GUI->CreateNewApp(FileName) )
 
251
    {
 
252
        wxMessageBox(_("New application class created"));
 
253
        m_Run = false;
 
254
        EndModal(wxID_OK);
 
255
    }
 
256
    else
 
257
    {
 
258
        wxMessageBox(_("Error occured while creating new files"));
 
259
    }
 
260
}