~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

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: 4850 $
 
19
* $Id: wxsitemres.cpp 4850 2008-01-29 21:45:49Z byo $
 
20
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/contrib/wxSmith/wxwidgets/wxsitemres.cpp $
 
21
*/
 
22
 
 
23
#include "wxsitemres.h"
 
24
#include "wxsitemeditor.h"
 
25
#include "wxsitemfactory.h"
 
26
#include "wxsitemresdata.h"
 
27
#include "wxsdeleteitemres.h"
 
28
#include "../wxscoder.h"
 
29
#include <manager.h>
 
30
#include <projectmanager.h>
 
31
#include <editormanager.h>
 
32
 
 
33
IMPLEMENT_CLASS(wxsItemRes,wxWidgetsRes)
 
34
 
 
35
namespace
 
36
{
 
37
    const wxString CppEmptySource =
 
38
        _T("$(PchCode)")
 
39
        _T("#include \"$(Include)\"\n")
 
40
        _T("\n")
 
41
        _T("$(InternalHeadersPch)")
 
42
        + wxsCodeMarks::Beg(wxsCPP,_T("InternalHeaders"),_T("$(ClassName)")) + _T("\n") +
 
43
        + wxsCodeMarks::End(wxsCPP) + _T("\n")
 
44
        _T("\n")
 
45
        + wxsCodeMarks::Beg(wxsCPP,_T("IdInit"),_T("$(ClassName)")) + _T("\n") +
 
46
        + wxsCodeMarks::End(wxsCPP) + _T("\n")
 
47
        _T("\n")
 
48
        _T("BEGIN_EVENT_TABLE($(ClassName),$(BaseClassName))\n")
 
49
        _T("\t") + wxsCodeMarks::Beg(wxsCPP,_T("EventTable"),_T("$(ClassName)")) + _T("\n")
 
50
        _T("\t") + wxsCodeMarks::End(wxsCPP) + _T("\n")
 
51
        _T("END_EVENT_TABLE()\n")
 
52
        _T("\n")
 
53
        _T("$(ClassName)::$(ClassName)($(CtorArgs))\n")
 
54
        _T("{\n")
 
55
        _T("$(CtorInit)\t") + wxsCodeMarks::Beg(wxsCPP,_T("Initialize"),_T("$(ClassName)")) + _T("\n")
 
56
        _T("\t") + wxsCodeMarks::End(wxsCPP) + _T("\n")
 
57
        _T("}\n")
 
58
        _T("\n")
 
59
        _T("$(ClassName)::~$(ClassName)()\n")
 
60
        _T("{\n")
 
61
        _T("\t") + wxsCodeMarks::Beg(wxsCPP,_T("Destroy"),_T("$(ClassName)")) + _T("\n")
 
62
        _T("\t") + wxsCodeMarks::End(wxsCPP) + _T("\n")
 
63
        _T("}\n")
 
64
        _T("\n");
 
65
 
 
66
    const wxString CppEmptyHeader =
 
67
        _T("#ifndef $(Guard)\n")
 
68
        _T("#define $(Guard)\n")
 
69
        _T("\n")
 
70
        _T("$(HeadersPch)")
 
71
        + wxsCodeMarks::Beg(wxsCPP,_T("Headers"),_T("$(ClassName)")) + _T("\n")
 
72
        + wxsCodeMarks::End(wxsCPP) + _T("\n")
 
73
        _T("\n")
 
74
        _T("class $(ClassName): public $(BaseClassName)\n")
 
75
        _T("{\n")
 
76
        _T("\tpublic:\n")
 
77
        _T("\n")
 
78
        _T("\t\t$(ClassName)($(CtorArgs));\n")
 
79
        _T("\t\tvirtual ~$(ClassName)();\n")
 
80
        _T("\n")
 
81
        _T("$(MembersScope)")
 
82
        _T("\t\t") + wxsCodeMarks::Beg(wxsCPP,_T("Declarations"),_T("$(ClassName)")) + _T("\n")
 
83
        _T("\t\t") + wxsCodeMarks::End(wxsCPP) + _T("\n")
 
84
        _T("\n")
 
85
        _T("$(IdsScope)")
 
86
        _T("\t\t") + wxsCodeMarks::Beg(wxsCPP,_T("Identifiers"),_T("$(ClassName)")) + _T("\n")
 
87
        _T("\t\t") + wxsCodeMarks::End(wxsCPP) + _T("\n")
 
88
        _T("\n")
 
89
        _T("$(HandlersScope)")
 
90
        _T("\t\t") + wxsCodeMarks::Beg(wxsCPP,_T("Handlers"),_T("$(ClassName)")) + _T("\n")
 
91
        _T("\t\t") + wxsCodeMarks::End(wxsCPP) + _T("\n")
 
92
        _T("\n")
 
93
        _T("$(InitFuncDecl)")
 
94
        _T("\t\tDECLARE_EVENT_TABLE()\n")
 
95
        _T("};\n")
 
96
        _T("\n")
 
97
        _T("#endif\n");
 
98
 
 
99
    const wxString EmptyXrc =
 
100
        _T("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
 
101
        _T("<resource xmlns=\"http://www.wxwidgets.org/wxxrc\">\n")
 
102
        _T("</resource>\n");
 
103
 
 
104
    const wxString EmptyWxs =
 
105
        _T("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
 
106
        _T("<wxsmith>\n")
 
107
        _T("\t<object class=\"$(BaseClassName)\" name=\"$(ClassName)\"/>\n")
 
108
        _T("\t<resource_extra/>\n")
 
109
        _T("</wxsmith>\n");
 
110
 
 
111
 
 
112
    const long GoToHeaderId = wxNewId();
 
113
    const long GoToSourceId = wxNewId();
 
114
}
 
115
 
 
116
wxsItemRes::wxsItemRes(wxsProject* Owner,const wxString& Type,bool CanBeMain):
 
117
    wxWidgetsRes(Owner,Type),
 
118
    m_WxsFileName(wxEmptyString),
 
119
    m_SrcFileName(wxEmptyString),
 
120
    m_HdrFileName(wxEmptyString),
 
121
    m_XrcFileName(wxEmptyString),
 
122
    m_UseForwardDeclarations(false),
 
123
    m_CanBeMain(CanBeMain)
 
124
{
 
125
}
 
126
 
 
127
 
 
128
wxsItemRes::wxsItemRes(const wxString& FileName,const TiXmlElement* XrcElem,const wxString& Type):
 
129
    wxWidgetsRes(0,Type),
 
130
    m_WxsFileName(wxEmptyString),
 
131
    m_SrcFileName(wxEmptyString),
 
132
    m_HdrFileName(wxEmptyString),
 
133
    m_XrcFileName(FileName),
 
134
    m_UseForwardDeclarations(false)
 
135
{
 
136
    SetResourceName(cbC2U(XrcElem->Attribute("name")));
 
137
}
 
138
 
 
139
wxsItemRes::~wxsItemRes()
 
140
{
 
141
}
 
142
 
 
143
wxsEditor* wxsItemRes::OnCreateEditor(wxWindow* Parent)
 
144
{
 
145
    return new wxsItemEditor(Parent,this);
 
146
}
 
147
 
 
148
bool wxsItemRes::OnReadConfig(const TiXmlElement* Node)
 
149
{
 
150
    m_WxsFileName = cbC2U(Node->Attribute("wxs"));
 
151
    m_SrcFileName = cbC2U(Node->Attribute("src"));
 
152
    m_HdrFileName = cbC2U(Node->Attribute("hdr"));
 
153
    m_XrcFileName = cbC2U(Node->Attribute("xrc"));
 
154
    m_UseForwardDeclarations = (cbC2U(Node->Attribute("fwddecl")) == _T("1"));
 
155
 
 
156
    // m_XrcFileName may be empty because it's not used when generating full source code
 
157
    return !m_WxsFileName.empty() &&
 
158
           !m_SrcFileName.empty() &&
 
159
           !m_HdrFileName.empty();
 
160
}
 
161
 
 
162
bool wxsItemRes::OnWriteConfig(TiXmlElement* Node)
 
163
{
 
164
    Node->SetAttribute("wxs",cbU2C(m_WxsFileName));
 
165
    Node->SetAttribute("src",cbU2C(m_SrcFileName));
 
166
    Node->SetAttribute("hdr",cbU2C(m_HdrFileName));
 
167
    if ( !m_XrcFileName.empty() )
 
168
    {
 
169
        Node->SetAttribute("xrc",cbU2C(m_XrcFileName));
 
170
    }
 
171
    if ( m_UseForwardDeclarations )
 
172
    {
 
173
        Node->SetAttribute("fwddecl","1");
 
174
    }
 
175
    return true;
 
176
}
 
177
 
 
178
bool wxsItemRes::OnCanHandleFile(const wxString& FileName)
 
179
{
 
180
    wxFileName Normalized(GetProjectPath()+m_WxsFileName);
 
181
    Normalized.Normalize(wxPATH_NORM_DOTS);
 
182
    if ( Normalized.GetFullPath() == FileName )
 
183
    {
 
184
        return true;
 
185
    }
 
186
    if ( m_XrcFileName.empty() )
 
187
    {
 
188
        return false;
 
189
    }
 
190
    Normalized.Assign(GetProjectPath()+m_XrcFileName);
 
191
    Normalized.Normalize(wxPATH_NORM_DOTS);
 
192
    if ( Normalized.GetFullPath() == FileName )
 
193
    {
 
194
        return true;
 
195
    }
 
196
    return false;
 
197
}
 
198
 
 
199
wxString wxsItemRes::OnGetDeclarationFile()
 
200
{
 
201
    return m_HdrFileName;
 
202
}
 
203
 
 
204
bool wxsItemRes::OnGetUsingXRC()
 
205
{
 
206
    return !m_XrcFileName.empty();
 
207
}
 
208
 
 
209
bool wxsItemRes::OnGetCanBeMain()
 
210
{
 
211
    return m_CanBeMain;
 
212
}
 
213
 
 
214
bool wxsItemRes::CreateNewResource(NewResourceParams& Params)
 
215
{
 
216
    wxFileName HFN(GetProjectPath()+Params.Hdr);
 
217
    SetLanguage(wxsCodeMarks::IdFromExt(HFN.GetExt()));
 
218
 
 
219
    switch ( GetLanguage() )
 
220
    {
 
221
        case wxsCPP:
 
222
        {
 
223
            SetResourceName(Params.Class);
 
224
 
 
225
            // Building arguments for constructor
 
226
            wxString CallArgs;
 
227
            wxString CtorArgs;
 
228
            wxString CtorArgsD;
 
229
 
 
230
            if ( Params.CtorParent )
 
231
            {
 
232
                CallArgs  << _T("parent");
 
233
                CtorArgs  << _T("wxWindow* parent");
 
234
                CtorArgsD << _T("wxWindow* parent");
 
235
                if ( Params.CtorParentDef )
 
236
                {
 
237
                    CtorArgsD << _T("=0");
 
238
                }
 
239
            }
 
240
 
 
241
            if ( Params.CtorId )
 
242
            {
 
243
                if ( !CtorArgs.IsEmpty() )
 
244
                {
 
245
                    CallArgs  << _T(",");
 
246
                    CtorArgs  << _T(",");
 
247
                    CtorArgsD << _T(",");
 
248
                }
 
249
                CallArgs  << _T("id");
 
250
                CtorArgs  << _T("wxWindowID id");
 
251
                CtorArgsD << _T("wxWindowID id");
 
252
                if ( Params.CtorIdDef )
 
253
                {
 
254
                    CtorArgsD << _T("=wxID_ANY");
 
255
                }
 
256
            }
 
257
 
 
258
            if ( Params.CtorPos )
 
259
            {
 
260
                if ( !CtorArgs.IsEmpty() )
 
261
                {
 
262
                    CallArgs  << _T(",");
 
263
                    CtorArgs  << _T(",");
 
264
                    CtorArgsD << _T(",");
 
265
                }
 
266
                CallArgs  << _T("pos");
 
267
                CtorArgs  << _T("const wxPoint& pos");
 
268
                CtorArgsD << _T("const wxPoint& pos");
 
269
                if ( Params.CtorPosDef )
 
270
                {
 
271
                    CtorArgsD << _T("=wxDefaultPosition");
 
272
                }
 
273
            }
 
274
 
 
275
            if ( Params.CtorSize )
 
276
            {
 
277
                if ( !CtorArgs.IsEmpty() )
 
278
                {
 
279
                    CallArgs  << _T(",");
 
280
                    CtorArgs  << _T(",");
 
281
                    CtorArgsD << _T(",");
 
282
                }
 
283
                CallArgs  << _T("size");
 
284
                CtorArgs  << _T("const wxSize& size");
 
285
                CtorArgsD << _T("const wxSize& size");
 
286
                if ( Params.CtorSizeDef )
 
287
                {
 
288
                    CtorArgsD << _T("=wxDefaultSize");
 
289
                }
 
290
            }
 
291
 
 
292
            wxString CtorArgsF = CtorArgs;
 
293
 
 
294
            if ( !Params.CustomCtorArgs.IsEmpty() )
 
295
            {
 
296
                if ( !CtorArgs.IsEmpty() )
 
297
                {
 
298
                    CtorArgs  << _T(",");
 
299
                    CtorArgsD << _T(",");
 
300
                }
 
301
                CtorArgs  << Params.CustomCtorArgs;
 
302
                CtorArgsD << Params.CustomCtorArgs;
 
303
            }
 
304
 
 
305
            // Generating code
 
306
 
 
307
            m_HdrFileName = Params.Hdr;
 
308
            if ( Params.GenHdr )
 
309
            {
 
310
                wxString Name = GetProjectPath()+Params.Hdr;
 
311
                wxFileName::Mkdir(wxFileName(Name).GetPath(),0777,wxPATH_MKDIR_FULL);
 
312
                wxFile File(Name,wxFile::write);
 
313
                wxString Guard = HFN.GetName().Upper() + _T("_H");
 
314
                wxString Header = CppEmptyHeader;
 
315
                wxString InitFuncDecl;
 
316
                wxString HeadersPch;
 
317
                if ( Params.UseInitFunc )
 
318
                {
 
319
                    InitFuncDecl <<
 
320
                        _T("\tprotected:\n\n")
 
321
                        _T("\t\tvoid ") << Params.InitFunc << _T("(") << CtorArgsF << _T(");\n\n");
 
322
                }
 
323
                if ( Params.UsePch && !Params.PchGuard.IsEmpty() )
 
324
                {
 
325
                    HeadersPch <<
 
326
                        _T("#ifndef ") + Params.PchGuard + _T("\n")
 
327
                        _T("\t") + wxsCodeMarks::Beg(wxsCPP,_T("HeadersPCH"),Params.Class) + _T("\n")
 
328
                        _T("\t") + wxsCodeMarks::End(wxsCPP) + _T("\n")
 
329
                        _T("#endif\n");
 
330
                }
 
331
                Header.Replace(_T("$(CtorArgs)"),CtorArgsD);
 
332
                Header.Replace(_T("$(Guard)"),Guard);
 
333
                Header.Replace(_T("$(ClassName)"),Params.Class);
 
334
                Header.Replace(_T("$(BaseClassName)"),Params.BaseClass);
 
335
                Header.Replace(_T("$(InitFuncDecl)"),InitFuncDecl);
 
336
                Header.Replace(_T("$(HeadersPch)"),HeadersPch);
 
337
 
 
338
                wxString Scope = _T("");
 
339
                switch ( Params.ScopeMembers )
 
340
                {
 
341
                    case NewResourceParams::Private:   Scope = _T("\tprivate:\n\n"); break;
 
342
                    case NewResourceParams::Protected: Scope = _T("\tprotected:\n\n"); break;
 
343
                    default:;
 
344
                }
 
345
                Header.Replace(_T("$(MembersScope)"),Scope);
 
346
                Scope = _T("");
 
347
                if ( Params.ScopeIds != Params.ScopeMembers )
 
348
                {
 
349
                    switch ( Params.ScopeIds )
 
350
                    {
 
351
                        case NewResourceParams::Public:    Scope = _T("\tpublic:\n\n"); break;
 
352
                        case NewResourceParams::Private:   Scope = _T("\tprivate:\n\n"); break;
 
353
                        case NewResourceParams::Protected: Scope = _T("\tprotected:\n\n"); break;
 
354
                    }
 
355
                }
 
356
                Header.Replace(_T("$(IdsScope)"),Scope);
 
357
                Scope = _T("");
 
358
                if ( Params.ScopeHandlers != Params.ScopeIds )
 
359
                {
 
360
                    switch ( Params.ScopeHandlers )
 
361
                    {
 
362
                        case NewResourceParams::Public:    Scope = _T("\tpublic:\n\n"); break;
 
363
                        case NewResourceParams::Private:   Scope = _T("\tprivate:\n\n"); break;
 
364
                        case NewResourceParams::Protected: Scope = _T("\tprotected:\n\n"); break;
 
365
                    }
 
366
                }
 
367
                Header.Replace(_T("$(HandlersScope)"),Scope);
 
368
 
 
369
                // TODO: Use wxsCoder to save file's content, so it will
 
370
                //       have proper encoding and EOL stuff
 
371
                if ( !File.Write(Header) ) return false;
 
372
            }
 
373
 
 
374
            m_SrcFileName = Params.Src;
 
375
            if ( Params.GenSrc )
 
376
            {
 
377
                wxString Name = GetProjectPath()+Params.Src;
 
378
                wxFileName::Mkdir(wxFileName(Name).GetPath(),0777,wxPATH_MKDIR_FULL);
 
379
                wxFile File(Name,wxFile::write);
 
380
                HFN.MakeRelativeTo(wxFileName(Name).GetPath());
 
381
                wxString Include = HFN.GetFullPath(wxPATH_UNIX);
 
382
                wxString PchCode;
 
383
                if ( Params.UsePch )
 
384
                {
 
385
                    wxFileName PCH(GetProjectPath()+Params.Pch);
 
386
                    PCH.MakeRelativeTo(wxFileName(Name).GetPath());
 
387
                    PchCode << _T("#include \"") << PCH.GetFullPath(wxPATH_UNIX) << _T("\"\n");
 
388
                }
 
389
                wxString CtorInitCode;
 
390
                if ( Params.UseInitFunc )
 
391
                {
 
392
                    CtorInitCode << _T("\t") << Params.InitFunc << _T("(") << CallArgs << _T(");\n");
 
393
                    CtorInitCode << _T("}\n\n");
 
394
                    CtorInitCode << _T("void ") << Params.Class << _T("::") << Params.InitFunc << _T("(") << CtorArgsF << _T(")\n");
 
395
                    CtorInitCode << _T("{\n");
 
396
                }
 
397
                wxString IntHeadersPch;
 
398
                if ( Params.UsePch && !Params.PchGuard.IsEmpty() )
 
399
                {
 
400
                    IntHeadersPch <<
 
401
                        _T("#ifndef ") + Params.PchGuard + _T("\n")
 
402
                        _T("\t") + wxsCodeMarks::Beg(wxsCPP,_T("InternalHeadersPCH"),Params.Class) + _T("\n")
 
403
                        _T("\t") + wxsCodeMarks::End(wxsCPP) + _T("\n")
 
404
                        _T("#endif\n");
 
405
                }
 
406
 
 
407
                wxString Source = CppEmptySource;
 
408
                Source.Replace(_T("$(PchCode)"),PchCode);
 
409
                Source.Replace(_T("$(CtorArgs)"),CtorArgs);
 
410
                Source.Replace(_T("$(Include)"),Include);
 
411
                Source.Replace(_T("$(ClassName)"),Params.Class);
 
412
                Source.Replace(_T("$(BaseClassName)"),Params.BaseClass);
 
413
                Source.Replace(_T("$(CtorInit)"),CtorInitCode);
 
414
                Source.Replace(_T("$(InternalHeadersPch)"),IntHeadersPch);
 
415
                // TODO: Use wxsCoder to save file's content, so it will
 
416
                //       have proper encoding and EOL stuff
 
417
                if ( !File.Write(Source) ) return false;
 
418
            }
 
419
 
 
420
            m_XrcFileName = Params.Xrc;
 
421
            if ( !Params.Xrc.IsEmpty() && Params.GenXrc )
 
422
            {
 
423
                wxString Name = GetProjectPath()+Params.Xrc;
 
424
                wxFileName::Mkdir(wxFileName(Name).GetPath(),0777,wxPATH_MKDIR_FULL);
 
425
                wxFile File(Name,wxFile::write);
 
426
                if ( !File.Write(EmptyXrc) ) return false;
 
427
            }
 
428
 
 
429
            if ( Params.Wxs.IsEmpty() )
 
430
            {
 
431
                // Searching for new wxs file name
 
432
                // TODO: Do not use constant folder name
 
433
                wxString WxsNameBase = _T("wxsmith");
 
434
                wxString WxsName;
 
435
                if ( !wxFileName::DirExists(GetProjectPath()+WxsNameBase) )
 
436
                {
 
437
                    if ( !wxFileName::Mkdir(GetProjectPath()+WxsNameBase,0777,wxPATH_MKDIR_FULL) )
 
438
                    {
 
439
                        return false;
 
440
                    }
 
441
                }
 
442
                WxsNameBase += _T("/") + Params.Class;
 
443
                WxsName = WxsNameBase + _T(".wxs");
 
444
                int Cnt = 0;
 
445
                for(;;)
 
446
                {
 
447
                    if ( !wxFileName::FileExists(GetProjectPath()+WxsName) &&
 
448
                         !wxFileName::DirExists(GetProjectPath()+WxsName) )
 
449
                    {
 
450
                        break;
 
451
                    }
 
452
                    Cnt++;
 
453
                    WxsName = wxString::Format(_T("%s%d.wxs"),WxsNameBase.c_str(),Cnt);
 
454
                }
 
455
 
 
456
                m_WxsFileName = WxsName;
 
457
                Params.Wxs = WxsName;
 
458
                {
 
459
                    wxString Name = GetProjectPath()+m_WxsFileName;
 
460
                    wxFile File(Name,wxFile::write);
 
461
                    wxString Content = EmptyWxs;
 
462
                    Content.Replace(_T("$(ClassName)"),Params.Class);
 
463
                    Content.Replace(_T("$(BaseClassName)"),GetResourceType());
 
464
                    if ( !File.Write(Content) )
 
465
                    {
 
466
                        return false;
 
467
                    }
 
468
                }
 
469
            }
 
470
            else
 
471
            {
 
472
                m_WxsFileName = Params.Wxs;
 
473
            }
 
474
            m_UseForwardDeclarations = Params.UseFwdDecl;
 
475
            return true;
 
476
        }
 
477
 
 
478
        default:;
 
479
    }
 
480
 
 
481
    SetLanguage(wxsUnknownLanguage);
 
482
    return false;
 
483
}
 
484
 
 
485
wxsItemRes::EditMode wxsItemRes::GetEditMode()
 
486
{
 
487
    if ( m_WxsFileName.empty() ) return File;
 
488
    if ( m_XrcFileName.empty() ) return Source;
 
489
    return Mixed;
 
490
}
 
491
 
 
492
int wxsItemRes::OnGetTreeIcon()
 
493
{
 
494
    const wxsItemInfo* Info = wxsItemFactory::GetInfo(GetResourceType());
 
495
    if ( Info ) return Info->TreeIconId;
 
496
    return wxsResource::OnGetTreeIcon();
 
497
}
 
498
 
 
499
wxsItemResData* wxsItemRes::BuildResData(wxsItemEditor* Editor)
 
500
{
 
501
    wxString ProjectPath = GetProjectPath();
 
502
 
 
503
    return new wxsItemResData(
 
504
        ProjectPath + GetWxsFileName(),
 
505
        ProjectPath + GetSrcFileName(),
 
506
        ProjectPath + GetHdrFileName(),
 
507
        GetXrcFileName().empty() ? _T("") : ProjectPath + GetXrcFileName(),
 
508
        GetResourceName(),
 
509
        GetResourceType(),
 
510
        GetLanguage(),
 
511
        m_UseForwardDeclarations,
 
512
        GetTreeItemId(),
 
513
        Editor,
 
514
        this);
 
515
}
 
516
 
 
517
bool wxsItemRes::OnDeleteCleanup(bool ShowDialog)
 
518
{
 
519
    bool PhisDeleteWXS = true;
 
520
    bool DeleteSources = false;
 
521
    bool PhisDeleteSources = false;
 
522
 
 
523
    if ( ShowDialog )
 
524
    {
 
525
        wxsDeleteItemRes Dlg;
 
526
        if ( Dlg.ShowModal() != wxID_OK )
 
527
        {
 
528
            return false;
 
529
        }
 
530
        PhisDeleteWXS = Dlg.m_PhisDeleteWXS->GetValue();
 
531
        DeleteSources = Dlg.m_DeleteSources->GetValue();
 
532
        PhisDeleteSources = Dlg.m_PhisDeleteSources->GetValue();
 
533
    }
 
534
 
 
535
    ProjectFile* Wxs = GetProject()->GetCBProject()->GetFileByFilename(m_WxsFileName,true);
 
536
    if ( Wxs )
 
537
    {
 
538
        GetProject()->GetCBProject()->RemoveFile(Wxs);
 
539
    }
 
540
 
 
541
    if ( PhisDeleteWXS )
 
542
    {
 
543
        wxRemoveFile(GetProjectPath() + m_WxsFileName);
 
544
    }
 
545
 
 
546
    if ( DeleteSources )
 
547
    {
 
548
        ProjectFile* Pf = GetProject()->GetCBProject()->GetFileByFilename(m_SrcFileName,true);
 
549
        if ( Pf )
 
550
        {
 
551
            GetProject()->GetCBProject()->RemoveFile(Pf);
 
552
        }
 
553
        Pf = GetProject()->GetCBProject()->GetFileByFilename(m_HdrFileName,true);
 
554
        if ( Pf )
 
555
        {
 
556
            GetProject()->GetCBProject()->RemoveFile(Pf);
 
557
        }
 
558
 
 
559
        if ( PhisDeleteSources )
 
560
        {
 
561
            wxRemoveFile(GetProjectPath() + m_SrcFileName);
 
562
            wxRemoveFile(GetProjectPath() + m_HdrFileName);
 
563
        }
 
564
    }
 
565
 
 
566
    Manager::Get()->GetProjectManager()->RebuildTree();
 
567
 
 
568
    // TODO: Check if we've deleted main resource of this app
 
569
 
 
570
    return true;
 
571
}
 
572
 
 
573
void wxsItemRes::OnFillPopupMenu(wxMenu* Menu)
 
574
{
 
575
    if ( !m_SrcFileName.IsEmpty() || !m_HdrFileName.IsEmpty() )
 
576
    {
 
577
        Menu->AppendSeparator();
 
578
        Menu->Append(GoToHeaderId,_("Go to header file"));
 
579
        Menu->Append(GoToSourceId,_("Go to source file"));
 
580
    }
 
581
}
 
582
 
 
583
bool wxsItemRes::OnPopupMenu(long Id)
 
584
{
 
585
    if ( Id == GoToHeaderId )
 
586
    {
 
587
        if ( !m_HdrFileName.IsEmpty() )
 
588
        {
 
589
            Manager::Get()->GetEditorManager()->Open(GetProjectPath() + m_HdrFileName);
 
590
        }
 
591
        return true;
 
592
    }
 
593
    if ( Id == GoToSourceId )
 
594
    {
 
595
        if ( !m_SrcFileName.IsEmpty() )
 
596
        {
 
597
            Manager::Get()->GetEditorManager()->Open(GetProjectPath() + m_SrcFileName);
 
598
        }
 
599
        return true;
 
600
    }
 
601
    return false;
 
602
}