summaryrefslogtreecommitdiff
path: root/MacBundler/macbundler.cpp
blob: 88d07cf605521bdb4b5ea782580bb446a72acd8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
#include "macbundler.h"
#include "wx/xrc/xmlres.h"
#include "wx/textfile.h"
#include "workspace.h"
#include "windowattrmanager.h"

static MacBundler* thePlugin = NULL;

//TODO: accept file drops
class IconPicker : public wxPanel
{
    wxBitmap m_image;
    wxString m_image_path;

public:
    IconPicker(wxWindow* parent) : wxPanel(parent, wxID_ANY)
    {
        //wxStaticBoxSizer* sizer = new wxStaticBoxSizer(wxHORIZONTAL, this);
        SetMinSize(wxSize(50,50));
        //SetSizer(sizer);
    }

    void setImage(wxString path)
    {
        m_image_path = path;

        if (path.EndsWith(wxT(".icns")))
        {
            wxExecute( wxT("sips -s format png '") + path + wxT("' --out /tmp/tmpicon.png"), wxEXEC_SYNC );
            path = wxT("/tmp/tmpicon.png");
        }

        m_image.LoadFile(path, wxBITMAP_TYPE_ANY);

        if (m_image.IsOk())
        {
            if (m_image.GetWidth() > 50 or m_image.GetHeight() > 50)
            {
                wxImage tmp = m_image.ConvertToImage();
                tmp.Rescale(50, 50, wxIMAGE_QUALITY_HIGH);
                m_image = wxBitmap(tmp);
            }

            const int w = m_image.GetWidth();
            const int h = m_image.GetHeight();
            SetMinSize(wxSize(w+20, h+20));
            SetMaxSize(wxSize(w+20, h+20));
            Refresh(); // repaint needed to see change
        }
        else
        {
            wxMessageBox(_("Failed to load image"));
        }
    }

    void paintEvent(wxPaintEvent & evt)
    {
        wxPaintDC dc(this);

        if (m_image.IsOk())
        {
            dc.DrawBitmap( m_image, 10, 10, false );
        }
    }

    void doubleClick(wxMouseEvent& evt)
    {
        wxString filename = wxFileSelector( _("Choose the icon file") );
        if (not filename.IsEmpty())
        {
            setImage(filename);
        }
    }

    wxString getImagePath()
    {
        return m_image_path;
    }


    DECLARE_EVENT_TABLE();
};

BEGIN_EVENT_TABLE(IconPicker, wxPanel)
// catch paint events
EVT_PAINT(IconPicker::paintEvent)
EVT_LEFT_DCLICK(IconPicker::doubleClick)
END_EVENT_TABLE()


class BundleConfigDialog : public wxDialog
{
    bool m_accepted;
    wxCheckListBox* m_choices_widget;
    wxCheckBox*     m_info_plist_cb;
    wxCheckBox*     m_icon_cb;
    IconPicker*     m_icon_picker;

    wxTextCtrl*     m_get_info_string;
    wxTextCtrl*     m_version;
    wxTextCtrl*     m_icon_file;
    wxTextCtrl*     m_identifier;
    wxTextCtrl*     m_signature;
	IManager *      m_pluginManager;

    wxString m_project_name;

public:

    BundleConfigDialog(ProjectPtr project, wxWindow* parent, const wxArrayString& choices, IManager *manager)
        : wxDialog( parent, wxID_ANY, _("Mac Bundler Configuration"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
		, m_pluginManager(manager)
    {
        m_accepted = false;

        m_project_name = project->GetName();

        wxStaticText*   titleLabel = new wxStaticText  ( this, wxID_ANY,    _("Choose which target(s) to \"bundle-ize\"") );
        m_choices_widget           = new wxCheckListBox( this, wxID_ANY,    wxDefaultPosition, wxDefaultSize, choices );
        m_info_plist_cb            = new wxCheckBox    ( this, wxID_ANY,    _("Generate Info.plist file") );
        m_get_info_string          = new wxTextCtrl    ( this, wxID_ANY,    m_project_name + wxT(", version 1.0, copyright myself") );
        m_version                  = new wxTextCtrl    ( this, wxID_ANY,    wxT("1.0") );
        m_icon_file                = new wxTextCtrl    ( this, wxID_ANY,    m_project_name + wxT(".icns") );
        m_identifier               = new wxTextCtrl    ( this, wxID_ANY,    wxT("com.mycompany.") + m_project_name.Lower());
        m_signature                = new wxTextCtrl    ( this, wxID_ANY,    (m_project_name + wxT("????")).Left(4).Upper() );
        m_icon_cb                  = new wxCheckBox    ( this, wxID_ANY,    _("Copy the following icon into the project") );
        wxStaticText*   warning    = new wxStaticText  ( this, wxID_ANY,    _("Warning : applying these changes cannot be undone automatically") );
        wxButton*       okBtn      = new wxButton      ( this, wxID_OK,     _("Apply changes") );
        wxButton*       cancelBtn  = new wxButton      ( this, wxID_CANCEL, _("Cancel") );

        okBtn->SetDefault();
        m_signature->SetMaxLength(4);
        m_info_plist_cb->SetValue(true);
        m_icon_cb->SetValue(true);

        wxBoxSizer*      sizer      = new wxBoxSizer(wxVERTICAL);
        wxBoxSizer*      subsizer   = new wxBoxSizer(wxHORIZONTAL);
        wxFlexGridSizer* plistSizer = new  wxFlexGridSizer(5, 2, 5, 5);

        plistSizer->AddGrowableCol(1, 1);
        plistSizer->Add( new wxStaticText(this, wxID_ANY, _("Get Info Version String")), 0, wxALIGN_RIGHT );
        plistSizer->Add( m_get_info_string, 1, wxEXPAND );
        plistSizer->Add( new wxStaticText(this, wxID_ANY, _("Version Number")), 0, wxALIGN_RIGHT );
        plistSizer->Add( m_version, 1, wxEXPAND );
        plistSizer->Add( new wxStaticText(this, wxID_ANY, _("Icon File")), 0, wxALIGN_RIGHT );
        plistSizer->Add( m_icon_file, 1, wxEXPAND );
        plistSizer->Add( new wxStaticText(this, wxID_ANY, _("Bundle Identifier")), 0, wxALIGN_RIGHT );
        plistSizer->Add( m_identifier, 1, wxEXPAND );
        plistSizer->Add( new wxStaticText(this, wxID_ANY, _("4-Character Signature")), 0, wxALIGN_RIGHT );
        plistSizer->Add( m_signature, 1, wxEXPAND );

        sizer   ->Add(titleLabel,       0, wxEXPAND | wxALL,   10);
        sizer   ->Add(m_choices_widget, 1, wxEXPAND | wxALL,   10);
        sizer   ->Add(m_info_plist_cb,  0, wxEXPAND | wxALL,   5 );
        sizer   ->Add(plistSizer,       1, wxEXPAND | wxALL,   5 );

        sizer   ->Add(m_icon_cb,        0, wxALL,              10);

        wxStaticBoxSizer* iconBox = new wxStaticBoxSizer(wxHORIZONTAL, this);
        m_icon_picker = new IconPicker(this);
        m_icon_picker->setImage( wxT("/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericApplicationIcon.icns") );
        iconBox ->Add(m_icon_picker,    1, wxEXPAND);
        sizer   ->Add(iconBox,          0, wxALL,              10);

        sizer   ->Add(warning,          0, wxEXPAND | wxALL,   10);
        subsizer->AddStretchSpacer();
        subsizer->Add(cancelBtn,        0, wxLEFT   | wxRIGHT, 5 );
        subsizer->Add(okBtn,            0, wxLEFT   | wxRIGHT, 5 );
        sizer   ->Add(subsizer,         0, wxEXPAND | wxALL,   10);

        okBtn          ->Connect( okBtn->GetId(),     wxEVT_COMMAND_BUTTON_CLICKED,
                                  wxCommandEventHandler(BundleConfigDialog::onOk),     NULL, this );
        cancelBtn      ->Connect( cancelBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED,
                                  wxCommandEventHandler(BundleConfigDialog::onCancel), NULL, this );
        m_info_plist_cb->Connect( m_info_plist_cb->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED,
                                  wxCommandEventHandler(BundleConfigDialog::onPlistCheckboxPressed), NULL, this );


        this->SetSizerAndFit(sizer);
        this->Centre();

		// Load last stored size & position from the configuration tool
		WindowAttrManager::Load(this, wxT("BundleConfigDialog"), m_pluginManager->GetConfigTool());
    }

	virtual ~BundleConfigDialog()
	{
		WindowAttrManager::Save(this, wxT("BundleConfigDialog"), m_pluginManager->GetConfigTool());
	}

    void onOk(wxCommandEvent& evt)
    {
        m_accepted = true;
        EndModal(GetReturnCode());
    }

    void onCancel(wxCommandEvent& evt)
    {
        m_accepted = false;
        EndModal(GetReturnCode());
    }

    void onPlistCheckboxPressed(wxCommandEvent& evt)
    {
        const bool on = m_info_plist_cb->IsChecked();

        m_get_info_string->Enable(on);
        m_version->Enable(on);
        m_icon_file->Enable(on);
        m_identifier->Enable(on);
        m_signature->Enable(on);
    }

    bool getResults(wxArrayString& out, bool* createInfoPlistFile, bool* createIcon)
    {
        if (not m_accepted) return false;

        *createInfoPlistFile = m_info_plist_cb->IsChecked();
        *createIcon = m_icon_cb->IsChecked();

        const wxArrayString& items = m_choices_widget->GetStrings();
        const int count = items.GetCount();
        for (int n=0; n<count; n++)
        {
            if (m_choices_widget->IsChecked(n)) out.Add(items[n]);
        }

        return true;
    }

    wxString getIconDestName()
    {
        return m_icon_file->GetValue();
    }

    wxString getIconSource()
    {
        return m_icon_picker->getImagePath();
    }

    void writeInfoPlistFile(wxTextFile& file)
    {
        if (not file.Exists())
        {
            wxMessageBox( _("Cannot access or create file!") );
            return;
        }

        file.AddLine(wxT( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ));
        file.AddLine(wxT( "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" ));
        file.AddLine(wxT( "<plist version=\"1.0\">" ));
        file.AddLine(wxT( "<dict>\n" ));
        file.AddLine(wxT( "    <key>CFBundleExecutable</key>" ));
        file.AddLine(wxT( "    <string>") + m_project_name + wxT("</string>\n" ));
        file.AddLine(wxT( "    <key>CFBundleGetInfoString</key>" ));
        file.AddLine(wxT( "    <string>") + m_get_info_string->GetValue() + wxT("</string>\n" ));
        file.AddLine(wxT( "    <key>CFBundleIconFile</key>" ));
        file.AddLine(wxT( "    <string>") + m_icon_file->GetValue() + wxT("</string>\n" ));
        file.AddLine(wxT( "    <key>CFBundleIdentifier</key>" ));
        file.AddLine(wxT( "    <string>") + m_identifier->GetValue() + wxT("</string>\n" ));
        file.AddLine(wxT( "    <key>CFBundleSignature</key>" ));
        file.AddLine(wxT( "    <string>") + m_signature->GetValue() + wxT("</string>\n" ));
        file.AddLine(wxT( "    <key>CFBundleVersion</key>" ));
        file.AddLine(wxT( "    <string>") + m_version->GetValue() + wxT("</string>\n" ));
        file.AddLine(wxT( "    <key>CFBundleInfoDictionaryVersion</key>" ));
        file.AddLine(wxT( "    <string>6.0</string>\n" ));
        file.AddLine(wxT( "    <key>CFBundleDevelopmentRegion</key>" ));
        file.AddLine(wxT( "    <string>English</string>\n" ));
        file.AddLine(wxT( "    <key>CFBundlePackageType</key>" ));
        file.AddLine(wxT( "    <string>APPL</string>\n" ));
        file.AddLine(wxT( "    <key>CFBundleShortVersionString</key>" ));
		file.AddLine(wxT( "    <string>" ) + m_version->GetValue()  + wxT("</string>\n"  ));
        file.AddLine(wxT( "</dict>"));
        file.AddLine(wxT( "</plist>"));

        if (not file.Write())
        {
            wxMessageBox( _("Failed to write Info.plist file!") );
            return;
        }
    }

};

//Define the plugin entry point
extern "C" EXPORT IPlugin *CreatePlugin(IManager *manager)
{
	if (thePlugin == NULL)
    {
		thePlugin = new MacBundler(manager);
	}
	return thePlugin;
}

extern "C" EXPORT PluginInfo GetPluginInfo()
{
	PluginInfo info;
	info.SetAuthor(wxT("Auria"));
	info.SetName(wxT("MacBundler"));
	info.SetDescription(wxT("MacBundler : manage OS X app bundles"));
	info.SetVersion(wxT("v0.1"));
	return info;
}

extern "C" EXPORT int GetPluginInterfaceVersion()
{
	return PLUGIN_INTERFACE_VERSION;
}

MacBundler::MacBundler(IManager *manager)
		: IPlugin(manager)
{
	m_longName = _("Manage OS X app bundles");
	m_shortName = wxT("MacBundler");
}

MacBundler::~MacBundler()
{
}

void MacBundler::onBundleInvoked_active(wxCommandEvent& evt)
{
    wxString activeProject = m_mgr->GetWorkspace()->GetActiveProjectName();

    if (activeProject == wxEmptyString)
    {
        wxMessageBox( _("No project is active, cannot continue.") );
    }
    else
    {
        wxString error;
        ProjectPtr project = m_mgr->GetWorkspace()->FindProjectByName(activeProject, error);
        if (!project )
        {
            wxMessageBox( _("Cannot retrieve active project, cannot continue.") );
        }
        else
        {
            showSettingsDialogFor(project);
        }
    }
}

void MacBundler::onBundleInvoked_selected(wxCommandEvent& evt)
{
    if (not m_mgr->GetWorkspace() or not m_mgr->IsWorkspaceOpen()) return;

    TreeItemInfo item = m_mgr->GetSelectedTreeItemInfo(TreeFileView);
	if (item.m_itemType == ProjectItem::TypeProject)
    {

        wxString    project_name (item.m_text);
		wxString    err_msg;

        ProjectPtr proj = m_mgr->GetWorkspace()->FindProjectByName(project_name, err_msg);
		if (not proj) return;

        showSettingsDialogFor(proj);
    }
    else
    {
        wxMessageBox( _("This menu item can only be invoked when right-clicking a project.") );
    }

}

void MacBundler::showSettingsDialogFor(ProjectPtr project)
{
    //project->GetSettings()->GetGlobalSettings();
    //project->GetSettings()->GetBuildConfiguration(name);

    ProjectSettingsCookie cookie;

    ProjectSettingsPtr settings = project->GetSettings();
    if (not settings)
    {
        wxMessageBox(_("Cannot continue, impossible to access project settings."));
        return;
    }

    std::map< wxString, BuildConfigPtr > configs;
    wxArrayString choices;

    //TODO: allow putting the rules in the config root and not in every target
    BuildConfigPtr buildConfig = settings->GetFirstBuildConfiguration(cookie);
    while (buildConfig)
    {

        configs[ buildConfig->GetName()  ] = buildConfig;
        choices.Add( buildConfig->GetName() );

        buildConfig = settings->GetNextBuildConfiguration(cookie);
    }

    bool accepted = false;
    bool generateInfoPlistFile = false;
    bool generateIcon = false;

    wxArrayString targetsToSet;

    wxString iconName( wxT("icon.icns") );

    {
        BundleConfigDialog configDlg(project, m_mgr->GetTheApp()->GetTopWindow(), choices, m_mgr);
        configDlg.ShowModal();
        accepted = configDlg.getResults( targetsToSet, &generateInfoPlistFile, &generateIcon );
        iconName = configDlg.getIconDestName();

        if (accepted and generateInfoPlistFile)
        {
            wxFileName projPath = project->GetFileName();
            projPath.SetFullName(wxT(""));
            const wxString projectDirName = projPath.GetFullPath();
            const wxString infoPlistFile = projectDirName + wxT("/Info.plist");

            if (wxFileExists(infoPlistFile))
            {
                int out = wxMessageBox( wxString::Format(_("The following file:\n%s\nalready exists, overwrite it?\n"), infoPlistFile.c_str()),
                                        _("Warning"), wxYES_NO );
                if (out == wxYES)
                {
                    wxTextFile file;
                    file.Open( infoPlistFile );
                    file.Clear();
                    configDlg.writeInfoPlistFile(file);
                    file.Close();
                }
            }
            else
            {
                wxTextFile file;
                if (not file.Create( infoPlistFile ))
                {
                    wxMessageBox( _("Could not create Info.plist file\n") + infoPlistFile );
                }
                else
                {
                    configDlg.writeInfoPlistFile(file);
                    file.Close();
                }
            }

            if (wxFileExists(infoPlistFile))
            {
                //FIXME: if the file was already present, it will be added again and appear twice in the file tree
                wxArrayString paths;
                paths.Add(infoPlistFile);
                m_mgr->CreateVirtualDirectory(project->GetName(), wxT("osx"));
                m_mgr->AddFilesToVirtualFolder(project->GetName() + wxT(":osx"), paths);
            }
        } // nend if create info.plist

        if (accepted and generateIcon)
        {
            wxString iconSourcePath = configDlg.getIconSource();
            if (not iconSourcePath.IsEmpty())
            {
                // sips doesn't like double slashes in path names
                iconSourcePath.Replace( wxT("//"), wxT("/") );

                wxFileName projPath = project->GetFileName();
                projPath.SetFullName(wxT(""));
                const wxString projectDirName = projPath.GetFullPath();
                wxString iconFileDest = projectDirName + wxT("/") + configDlg.getIconDestName();

                // sips doesn't like double slashes in path names
                iconFileDest.Replace( wxT("//"), wxT("/") );

                std::cout << "Copying icon '" << iconSourcePath.mb_str() << "' to project\n";

                if (iconSourcePath.EndsWith(wxT(".icns")))
                {
                    if (not wxCopyFile(iconSourcePath, iconFileDest))
                    {
                        wxMessageBox( _("Sorry, could not copy icon") );
                    }
                }
                else
                {
                    wxString cmd = wxT("sips -s format icns '") +  iconSourcePath + wxT("' --out '") + iconFileDest + wxT("'");
                    std::cout << cmd.mb_str() << std::endl;
                    wxExecute( cmd, wxEXEC_SYNC );
                    if (not wxFileExists(iconFileDest))
                    {
                        wxMessageBox( _("Sorry, could not convert selected icon to icns format") );
                    }
                }

                //FIXME: if the file was already present, it will be added again and appear twice in the file tree
                if (wxFileExists(iconFileDest))
                {
                    wxArrayString paths;
                    paths.Add(iconFileDest);
                    m_mgr->CreateVirtualDirectory(project->GetName(), wxT("osx"));
                    m_mgr->AddFilesToVirtualFolder(project->GetName() + wxT(":osx"), paths);
                }
            } // end if icon not null
        } // end if generate icon
    }
    if (!accepted) return;


    for (int n=0; n<targetsToSet.GetCount(); n++)
    {
        BuildConfigPtr buildConfig = configs[ targetsToSet[n] ];

        wxString outputFileName = buildConfig->GetOutputFileName();
        wxString output = wxT("$(ProjectName).app/Contents/MacOS/$(ProjectName)");
        buildConfig->SetOutputFileName( wxT("$(IntermediateDirectory)/") + output );
        buildConfig->SetCommand( wxT("./") + output );

        if (generateInfoPlistFile or generateIcon)
        {
            // get existing custom makefile targets, if any
            wxString customPreBuild = buildConfig->GetPreBuildCustom();

            wxString deps, rules;
            deps = customPreBuild.BeforeFirst(wxT('\n'));
            rules = customPreBuild.AfterFirst(wxT('\n'));

            rules = rules.Trim();
            rules = rules.Trim(false);

            deps = deps.Trim();
            deps = deps.Trim(false);


            if (generateInfoPlistFile)
            {
                        // augment existing rules with new rules to manage Info.plist file
                deps.Append( wxT(" $(IntermediateDirectory)/$(ProjectName).app/Contents/Info.plist") );
                rules.Append( wxString( wxT("\n## rule to copy the Info.plist file into the bundle\n") ) +
                              wxT("$(IntermediateDirectory)/$(ProjectName).app/Contents/Info.plist: Info.plist\n") +
                              wxT("\tmkdir -p '$(IntermediateDirectory)/$(ProjectName).app/Contents' && cp -f Info.plist '$(IntermediateDirectory)/$(ProjectName).app/Contents/Info.plist'") );
            }
            if (generateIcon)
            {
                // augment existing rules with new rules to manage Info.plist file
                deps.Append( wxT(" $(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/") + iconName );
                rules.Append( wxT("\n## rule to copy the icon file into the bundle\n$(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/") +
                             iconName + wxT(": ") + iconName  + wxT("\n\tmkdir -p '$(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/' && cp -f ") + iconName +
                             wxT(" '$(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/") + iconName + wxT("'") );
            }

            // set the new rules
            rules = rules.Trim();
            rules = rules.Trim(false);
            deps = deps.Trim();
            deps = deps.Trim(false);

            wxString prebuilstep;
            prebuilstep << deps << wxT("\n");
            prebuilstep << rules;
            prebuilstep << wxT("\n");

            // Set the content only if there is real content to add
            wxString tmpPreBuildStep(prebuilstep);
            tmpPreBuildStep.Trim().Trim(false);
            buildConfig->SetPreBuildCustom(prebuilstep);
        } // end if

        settings->SetBuildConfiguration(buildConfig);

    } // end for

    project->SetSettings(settings);
}

clToolBar *MacBundler::CreateToolBar(wxWindow *parent)
{
    return NULL;

	// Create the toolbar to be used by the plugin
	//clToolBar *tb(NULL);

/*
	// You can use the below code a snippet:
 	// First, check that CodeLite allows plugin to register plugins
	if (m_mgr->AllowToolbar()) {
		// Support both toolbars icon size
		int size = m_mgr->GetToolbarIconSize();

		// Allocate new toolbar, which will be freed later by CodeLite
		tb = new clToolBar(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, clTB_DEFAULT_STYLE);

		// Set the toolbar size
		tb->SetToolBitmapSize(wxSize(size, size));

		// Add tools to the plugins toolbar. You must provide 2 sets of icons: 24x24 and 16x16
		if (size == 24) {
			tb->AddTool(XRCID("new_plugin"), wxT("New CodeLite Plugin Project"), wxXmlResource::Get()->LoadBitmap(wxT("plugin24")), wxT("New Plugin Wizard..."));
			tb->AddTool(XRCID("new_class"), wxT("Create New Class"), wxXmlResource::Get()->LoadBitmap(wxT("class24")), wxT("New Class..."));
			tb->AddTool(XRCID("new_wx_project"), wxT("New wxWidget Project"), wxXmlResource::Get()->LoadBitmap(wxT("new_wx_project24")), wxT("New wxWidget Project"));
		} else {
			tb->AddTool(XRCID("new_plugin"), wxT("New CodeLite Plugin Project"), wxXmlResource::Get()->LoadBitmap(wxT("plugin16")), wxT("New Plugin Wizard..."));
			tb->AddTool(XRCID("new_class"), wxT("Create New Class"), wxXmlResource::Get()->LoadBitmap(wxT("class16")), wxT("New Class..."));
			tb->AddTool(XRCID("new_wx_project"), wxT("New wxWidget Project"), wxXmlResource::Get()->LoadBitmap(wxT("new_wx_project16")), wxT("New wxWidget Project"));
		}
		// And finally, we must call 'Realize()'
		tb->Realize();
	}

	// return the toolbar, it can be NULL if CodeLite does not allow plugins to register toolbars
	// or in case the plugin simply does not require toolbar
*/
	//return tb;
}

void MacBundler::CreatePluginMenu(wxMenu *pluginsMenu)
{
 	wxMenu* menu = new wxMenu();
	wxMenuItem* item = new wxMenuItem(menu, wxNewId(), _("Make active project output a bundle"), wxEmptyString, wxITEM_NORMAL);
	menu->Append(item);
	//item = new wxMenuItem(menu, wxID_ANY, _("New Class Wizard..."), wxEmptyString, wxITEM_NORMAL);
	//menu->Append(item);
	//item = new wxMenuItem(menu, wxID_ANY, _("New wxWidgets Project Wizard..."), wxEmptyString, wxITEM_NORMAL);
	//menu->Append(item);

    m_mgr->GetTheApp()->Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
                                 wxCommandEventHandler(MacBundler::onBundleInvoked_active), NULL, this );

	pluginsMenu->Append(wxID_ANY, _("MacBundler"), menu);

/*
	// You can use the below code a snippet:
 	wxMenu *menu = new wxMenu();
	wxMenuItem *item(NULL);
	item = new wxMenuItem(menu, XRCID("new_plugin"), _("New CodeLite Plugin Wizard..."), wxEmptyString, wxITEM_NORMAL);
	menu->Append(item);
	item = new wxMenuItem(menu, XRCID("new_class"), _("New Class Wizard..."), wxEmptyString, wxITEM_NORMAL);
	menu->Append(item);
	item = new wxMenuItem(menu, XRCID("new_wx_project"), _("New wxWidgets Project Wizard..."), wxEmptyString, wxITEM_NORMAL);
	menu->Append(item);
	pluginsMenu->Append(wxID_ANY, _("Gizmos"), menu);
*/
}

void MacBundler::HookPopupMenu(wxMenu *menu, MenuType type)
{
	if (type == MenuTypeFileView_Project) {
		if (!menu->FindItem(XRCID("MACBUNDLER_PROJECT_MENU"))) {
			menu->Append(XRCID("MACBUNDLER_PROJECT_MENU"),  _("Make this project output a bundle"), wxEmptyString, wxITEM_NORMAL);
			m_mgr->GetTheApp()->Connect( XRCID("MACBUNDLER_PROJECT_MENU"), wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(MacBundler::onBundleInvoked_selected), NULL, this );
		}
	}
}

void MacBundler::UnPlug()
{
}