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

« back to all changes in this revision

Viewing changes to src/plugins/contrib/lib_finder/projectconfigurationpanel.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 lib_finder plugin for Code::Blocks Studio
 
3
* Copyright (C) 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 2 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, write to the Free Software
 
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 
18
*
 
19
* $Revision: 4504 $
 
20
* $Id: wxsmithpluginregistrants.cpp 4504 2007-10-02 21:52:30Z byo $
 
21
* $HeadURL: svn+ssh://byo@svn.berlios.de/svnroot/repos/codeblocks/trunk/src/plugins/contrib/wxSmith/plugin/wxsmithpluginregistrants.cpp $
 
22
*/
 
23
 
 
24
#include "projectconfigurationpanel.h"
 
25
 
 
26
//(*InternalHeaders(ProjectConfigurationPanel)
 
27
#include <wx/treectrl.h>
 
28
#include <wx/sizer.h>
 
29
#include <wx/stattext.h>
 
30
#include <wx/textctrl.h>
 
31
#include <wx/checkbox.h>
 
32
#include <wx/listbox.h>
 
33
#include <wx/intl.h>
 
34
#include <wx/button.h>
 
35
#include <wx/string.h>
 
36
//*)
 
37
 
 
38
#include <wx/tokenzr.h>
 
39
 
 
40
#include "lib_finder.h"
 
41
 
 
42
//(*IdInit(ProjectConfigurationPanel)
 
43
const long ProjectConfigurationPanel::ID_LISTBOX1 = wxNewId();
 
44
const long ProjectConfigurationPanel::ID_CHECKBOX2 = wxNewId();
 
45
const long ProjectConfigurationPanel::ID_BUTTON4 = wxNewId();
 
46
const long ProjectConfigurationPanel::ID_BUTTON1 = wxNewId();
 
47
const long ProjectConfigurationPanel::ID_BUTTON2 = wxNewId();
 
48
const long ProjectConfigurationPanel::ID_TREECTRL1 = wxNewId();
 
49
const long ProjectConfigurationPanel::ID_STATICTEXT1 = wxNewId();
 
50
const long ProjectConfigurationPanel::ID_TEXTCTRL2 = wxNewId();
 
51
const long ProjectConfigurationPanel::ID_CHECKBOX1 = wxNewId();
 
52
const long ProjectConfigurationPanel::ID_TEXTCTRL1 = wxNewId();
 
53
const long ProjectConfigurationPanel::ID_BUTTON3 = wxNewId();
 
54
const long ProjectConfigurationPanel::ID_STATICTEXT2 = wxNewId();
 
55
const long ProjectConfigurationPanel::ID_TIMER1 = wxNewId();
 
56
//*)
 
57
 
 
58
BEGIN_EVENT_TABLE(ProjectConfigurationPanel,cbConfigurationPanel)
 
59
        //(*EventTable(ProjectConfigurationPanel)
 
60
        //*)
 
61
END_EVENT_TABLE()
 
62
 
 
63
namespace
 
64
{
 
65
    class TreeItemData: public wxTreeItemData
 
66
    {
 
67
        // Warning: since we use reference to string instead of string itself,
 
68
        // the base string must exist as long as this item data exists
 
69
        public:
 
70
            TreeItemData(const wxString& ShortCode): m_ShortCode(ShortCode) {}
 
71
            ~TreeItemData() {}
 
72
 
 
73
            const wxString& m_ShortCode;
 
74
    };
 
75
 
 
76
    class ListItemData: public wxClientData
 
77
    {
 
78
        // We don't use string's reference here since project's libraries set
 
79
        // should be much smaller than list of known libraries
 
80
        public:
 
81
            ListItemData(const wxString& ShortCode): m_ShortCode(ShortCode) {}
 
82
            ~ListItemData() {}
 
83
 
 
84
            const wxString m_ShortCode;
 
85
    };
 
86
}
 
87
 
 
88
ProjectConfigurationPanel::ProjectConfigurationPanel(wxWindow* parent,ProjectConfiguration* Configuration,cbProject* Project,TypedResults& KnownLibs):
 
89
    m_Configuration(Configuration),
 
90
    m_Project(Project),
 
91
    m_KnownLibs(KnownLibs)
 
92
{
 
93
        //(*Initialize(ProjectConfigurationPanel)
 
94
        wxBoxSizer* BoxSizer4;
 
95
        wxStaticBoxSizer* StaticBoxSizer2;
 
96
        wxBoxSizer* BoxSizer6;
 
97
        wxBoxSizer* BoxSizer5;
 
98
        wxBoxSizer* BoxSizer2;
 
99
        wxStaticBoxSizer* StaticBoxSizer3;
 
100
        wxBoxSizer* BoxSizer1;
 
101
        wxStaticBoxSizer* StaticBoxSizer1;
 
102
        wxBoxSizer* BoxSizer3;
 
103
        wxStaticBoxSizer* m_DisableAuto;
 
104
 
 
105
        Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("wxID_ANY"));
 
106
        BoxSizer1 = new wxBoxSizer(wxVERTICAL);
 
107
        BoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
 
108
        BoxSizer5 = new wxBoxSizer(wxVERTICAL);
 
109
        StaticBoxSizer1 = new wxStaticBoxSizer(wxVERTICAL, this, _("Libraries used in project"));
 
110
        m_UsedLibraries = new wxListBox(this, ID_LISTBOX1, wxDefaultPosition, wxSize(147,123), 0, 0, 0, wxDefaultValidator, _T("ID_LISTBOX1"));
 
111
        StaticBoxSizer1->Add(m_UsedLibraries, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
112
        BoxSizer5->Add(StaticBoxSizer1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
113
        m_DisableAuto = new wxStaticBoxSizer(wxVERTICAL, this, _("Extra settings"));
 
114
        m_NoAuto = new wxCheckBox(this, ID_CHECKBOX2, _("Don\'t setup automatically"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX2"));
 
115
        m_NoAuto->SetValue(false);
 
116
        m_NoAuto->SetToolTip(_("If you check this option, lib_finder won\'t add settings of libraries automatically.\nNote that automatic setup is available only after applying extra patch to code::blocks available at forums."));
 
117
        m_DisableAuto->Add(m_NoAuto, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
118
        m_AddScript = new wxButton(this, ID_BUTTON4, _("Add manual build script"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
 
119
        m_AddScript->SetToolTip(_("When you use this option, extra script will be added to the project.\nThis script does invoke lib_finder and will add settings of libraries\njust as in case of automatic setup.\nIt may be usefull when no extra-event patch has been applied."));
 
120
        m_DisableAuto->Add(m_AddScript, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
121
        BoxSizer5->Add(m_DisableAuto, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
122
        BoxSizer6->Add(BoxSizer5, 3, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
123
        BoxSizer2 = new wxBoxSizer(wxVERTICAL);
 
124
        m_Add = new wxButton(this, ID_BUTTON1, _("<"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_BUTTON1"));
 
125
        m_Add->Disable();
 
126
        m_Add->SetToolTip(_("Add selected library to project"));
 
127
        BoxSizer2->Add(m_Add, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
128
        m_Remove = new wxButton(this, ID_BUTTON2, _(">"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_BUTTON2"));
 
129
        m_Remove->Disable();
 
130
        m_Remove->SetToolTip(_("Remove selected library from project"));
 
131
        BoxSizer2->Add(m_Remove, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
132
        BoxSizer6->Add(BoxSizer2, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
133
        BoxSizer3 = new wxBoxSizer(wxVERTICAL);
 
134
        StaticBoxSizer2 = new wxStaticBoxSizer(wxVERTICAL, this, _("Known libraries"));
 
135
        m_KnownLibrariesTree = new wxTreeCtrl(this, ID_TREECTRL1, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT|wxTR_SINGLE|wxTR_DEFAULT_STYLE|wxSUNKEN_BORDER, wxDefaultValidator, _T("ID_TREECTRL1"));
 
136
        StaticBoxSizer2->Add(m_KnownLibrariesTree, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
137
        BoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
 
138
        StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Filter:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
 
139
        BoxSizer4->Add(StaticText1, 0, wxTOP|wxBOTTOM|wxLEFT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
140
        m_Filter = new wxTextCtrl(this, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
 
141
        BoxSizer4->Add(m_Filter, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
142
        StaticBoxSizer2->Add(BoxSizer4, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
143
        m_Tree = new wxCheckBox(this, ID_CHECKBOX1, _("Show as tree"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
 
144
        m_Tree->SetValue(true);
 
145
        StaticBoxSizer2->Add(m_Tree, 0, wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
146
        BoxSizer3->Add(StaticBoxSizer2, 1, wxBOTTOM|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
147
        StaticBoxSizer3 = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Unknown library"));
 
148
        m_UnknownLibrary = new wxTextCtrl(this, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
 
149
        StaticBoxSizer3->Add(m_UnknownLibrary, 1, wxTOP|wxBOTTOM|wxLEFT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
150
        m_AddUnknown = new wxButton(this, ID_BUTTON3, _("Add"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_BUTTON3"));
 
151
        m_AddUnknown->Disable();
 
152
        StaticBoxSizer3->Add(m_AddUnknown, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
153
        BoxSizer3->Add(StaticBoxSizer3, 0, wxTOP|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
154
        BoxSizer6->Add(BoxSizer3, 4, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
155
        BoxSizer1->Add(BoxSizer6, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
156
        m_EventText = new wxStaticText(this, ID_STATICTEXT2, _("Note: Because there\'s not yet ability to update project\'s build options\nfrom plugin, the only way to automatically add library configurations\nis to use build script"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE, _T("ID_STATICTEXT2"));
 
157
        m_EventText->Hide();
 
158
        BoxSizer1->Add(m_EventText, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
 
159
        SetSizer(BoxSizer1);
 
160
        Timer1.SetOwner(this, ID_TIMER1);
 
161
        BoxSizer1->Fit(this);
 
162
        BoxSizer1->SetSizeHints(this);
 
163
 
 
164
        Connect(ID_LISTBOX1,wxEVT_COMMAND_LISTBOX_SELECTED,(wxObjectEventFunction)&ProjectConfigurationPanel::Onm_UsedLibrariesSelect);
 
165
        Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&ProjectConfigurationPanel::Onm_AddScriptClick);
 
166
        Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&ProjectConfigurationPanel::Onm_AddClick);
 
167
        Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&ProjectConfigurationPanel::Onm_RemoveClick);
 
168
        Connect(ID_TREECTRL1,wxEVT_COMMAND_TREE_SEL_CHANGED,(wxObjectEventFunction)&ProjectConfigurationPanel::Onm_KnownLibrariesTreeSelectionChanged);
 
169
        Connect(ID_TEXTCTRL2,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&ProjectConfigurationPanel::Onm_FilterText);
 
170
        Connect(ID_TEXTCTRL2,wxEVT_COMMAND_TEXT_ENTER,(wxObjectEventFunction)&ProjectConfigurationPanel::Onm_FilterTextEnter);
 
171
        Connect(ID_CHECKBOX1,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&ProjectConfigurationPanel::Onm_TreeClick);
 
172
        Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&ProjectConfigurationPanel::Onm_UnknownLibraryText);
 
173
        Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&ProjectConfigurationPanel::Onm_AddUnknownClick);
 
174
        Connect(ID_TIMER1,wxEVT_TIMER,(wxObjectEventFunction)&ProjectConfigurationPanel::OnTimer1Trigger);
 
175
        //*)
 
176
 
 
177
        m_EventText->Show(!lib_finder::IsExtraEvent());
 
178
 
 
179
        if ( m_Project->GetBuildScripts().Index(_T("lib_finder.script")) != wxNOT_FOUND )
 
180
        {
 
181
            // There's a build script yet
 
182
            m_AddScript->Disable();
 
183
        }
 
184
 
 
185
        m_ConfCopy = *m_Configuration;
 
186
        FillKnownLibraries();
 
187
        LoadData();
 
188
}
 
189
 
 
190
ProjectConfigurationPanel::~ProjectConfigurationPanel()
 
191
{
 
192
        //(*Destroy(ProjectConfigurationPanel)
 
193
        //*)
 
194
}
 
195
 
 
196
wxString ProjectConfigurationPanel::GetTitle() const
 
197
{
 
198
    return _T("Libraries");
 
199
}
 
200
 
 
201
wxString ProjectConfigurationPanel::GetBitmapBaseName() const
 
202
{
 
203
    return _T("");
 
204
}
 
205
 
 
206
void ProjectConfigurationPanel::OnApply()
 
207
{
 
208
    StoreData();
 
209
    *m_Configuration = m_ConfCopy;
 
210
}
 
211
 
 
212
void ProjectConfigurationPanel::OnCancel()
 
213
{
 
214
}
 
215
 
 
216
void ProjectConfigurationPanel::LoadData()
 
217
{
 
218
    m_UsedLibraries->Freeze();
 
219
    for ( size_t i=0; i<m_ConfCopy.m_GlobalUsedLibs.Count(); i++ )
 
220
    {
 
221
        wxString Name = m_ConfCopy.m_GlobalUsedLibs[i];
 
222
        m_UsedLibraries->Append(GetUserListName(Name),new ListItemData(Name));
 
223
    }
 
224
    m_UsedLibraries->Thaw();
 
225
    m_NoAuto->SetValue(m_ConfCopy.m_DisableAuto);
 
226
}
 
227
 
 
228
wxString ProjectConfigurationPanel::GetUserListName(const wxString& Name)
 
229
{
 
230
    for ( int i=0; i<rtCount; i++ )
 
231
    {
 
232
        if ( m_KnownLibs[i].IsShortCode(Name) )
 
233
        {
 
234
            switch ( i )
 
235
            {
 
236
                case rtPkgConfig:
 
237
                    return Name + _T(" (pkg-config)");
 
238
 
 
239
                default:
 
240
                    return Name + _T(": ") + m_KnownLibs[i].GetShortCode(Name)[0]->LibraryName;
 
241
            }
 
242
        }
 
243
    }
 
244
 
 
245
    return Name + _T(" (Unknown library)");
 
246
}
 
247
 
 
248
void ProjectConfigurationPanel::StoreData()
 
249
{
 
250
    m_ConfCopy.m_DisableAuto = m_NoAuto->GetValue();
 
251
}
 
252
 
 
253
void ProjectConfigurationPanel::FillKnownLibraries()
 
254
{
 
255
    Timer1.Stop();
 
256
    m_KnownLibrariesTree->Freeze();
 
257
    m_KnownLibrariesTree->DeleteAllItems();
 
258
    m_KnownLibrariesTree->AddRoot(_("Known libraries"));
 
259
 
 
260
    m_CategoryMap.clear();
 
261
    m_IsOtherCategory = false;
 
262
    m_IsPkgConfig = false;
 
263
 
 
264
    wxString Filter = m_Filter->GetValue().Upper();
 
265
    bool Tree = m_Tree->GetValue();
 
266
 
 
267
    // Collecting list of all global variable names,
 
268
    // currently without pkg-config entries (will be used later)
 
269
    wxArrayString Vars;
 
270
    for ( int i=0; i<rtCount; i++ )
 
271
    {
 
272
        if ( i==rtPkgConfig ) continue;
 
273
        m_KnownLibs[i].GetShortCodes(Vars);
 
274
    }
 
275
 
 
276
    for ( size_t i=0; i<Vars.Count(); i++ )
 
277
    {
 
278
        ResultArray* Array = 0;
 
279
        for ( int j=0; j<rtCount; j++ )
 
280
        {
 
281
            if ( j!=rtPkgConfig )
 
282
            {
 
283
                if ( m_KnownLibs[j].IsShortCode(Vars[i]) )
 
284
                {
 
285
                    Array = &m_KnownLibs[j].GetShortCode(Vars[i]);
 
286
                }
 
287
            }
 
288
        }
 
289
 
 
290
        if ( !Array || Array->IsEmpty() ) continue;
 
291
 
 
292
        if ( !Filter.IsEmpty() )
 
293
        {
 
294
            if ( (*Array)[0]->LibraryName.Upper().Find(Filter) == wxNOT_FOUND &&
 
295
                 (*Array)[0]->ShortCode.Upper().Find(Filter)   == wxNOT_FOUND )
 
296
            {
 
297
                // This result has been filtered
 
298
                continue;
 
299
            }
 
300
        }
 
301
 
 
302
        if ( Tree )
 
303
        {
 
304
            wxArrayString& Categories = (*Array)[0]->Categories;
 
305
            if ( Categories.IsEmpty() )
 
306
            {
 
307
                BuildEntry(OtherCategoryId(),*Array);
 
308
            }
 
309
            else
 
310
            {
 
311
                for ( size_t i=0; i<Categories.Count(); i++ )
 
312
                {
 
313
                    BuildEntry(CategoryId(Categories[i]),*Array);
 
314
                }
 
315
            }
 
316
        }
 
317
        else
 
318
        {
 
319
            BuildEntry(m_KnownLibrariesTree->GetRootItem(),*Array);
 
320
        }
 
321
    }
 
322
 
 
323
    // Now add pkg-config entries in separate category at the end
 
324
    Vars.Clear();
 
325
    m_KnownLibs[rtPkgConfig].GetShortCodes(Vars);
 
326
 
 
327
    if ( !Vars.IsEmpty() )
 
328
    {
 
329
        for ( size_t i=0; i<Vars.Count(); i++ )
 
330
        {
 
331
            ResultArray& Array = m_KnownLibs[rtPkgConfig].GetShortCode(Vars[i]);
 
332
            if ( Array.IsEmpty() ) continue;
 
333
 
 
334
            if ( !Filter.IsEmpty() )
 
335
            {
 
336
                if ( Array[0]->LibraryName.Upper().Find(Filter) == wxNOT_FOUND &&
 
337
                     Array[0]->ShortCode.Upper().Find(Filter)   == wxNOT_FOUND )
 
338
                {
 
339
                    // This result has been filtered
 
340
                    continue;
 
341
                }
 
342
            }
 
343
 
 
344
            BuildEntry(Tree ? PkgConfigId() : m_KnownLibrariesTree->GetRootItem(),Array);
 
345
        }
 
346
    }
 
347
 
 
348
    // Ok, let's present all results
 
349
    m_KnownLibrariesTree->ExpandAll();
 
350
    m_KnownLibrariesTree->Thaw();
 
351
}
 
352
 
 
353
void ProjectConfigurationPanel::BuildEntry(const wxTreeItemId& Id,ResultArray& Array)
 
354
{
 
355
    wxString Name = Array[0]->ShortCode;
 
356
    if ( !Array[0]->LibraryName.IsEmpty() )
 
357
    {
 
358
        Name = Name + _T(": ") + Array[0]->LibraryName;
 
359
    }
 
360
    m_KnownLibrariesTree->AppendItem(Id,Name,0,0,new TreeItemData(Array[0]->ShortCode));
 
361
}
 
362
 
 
363
wxTreeItemId ProjectConfigurationPanel::OtherCategoryId()
 
364
{
 
365
    if ( m_IsOtherCategory )
 
366
    {
 
367
        return m_CategoryMap[_T(".other")];
 
368
    }
 
369
 
 
370
    m_IsOtherCategory = true;
 
371
    return m_CategoryMap[_T(".other")] = m_KnownLibrariesTree->AppendItem(m_KnownLibrariesTree->GetRootItem(),_("Other"));
 
372
}
 
373
 
 
374
wxTreeItemId ProjectConfigurationPanel::PkgConfigId()
 
375
{
 
376
    if ( m_IsPkgConfig )
 
377
    {
 
378
        return m_CategoryMap[_T(".pkg-config")];
 
379
    }
 
380
    m_IsPkgConfig = true;
 
381
    return m_CategoryMap[_T(".pkg-config")] = m_KnownLibrariesTree->AppendItem(m_KnownLibrariesTree->GetRootItem(),_("Available in pkg-config"));
 
382
}
 
383
 
 
384
wxTreeItemId ProjectConfigurationPanel::CategoryId(const wxString& Category)
 
385
{
 
386
    if ( m_CategoryMap.find(Category.Lower()) != m_CategoryMap.end() )
 
387
    {
 
388
        return m_CategoryMap[Category.Lower()];
 
389
    }
 
390
 
 
391
    wxStringTokenizer Tokens(Category,_T("."),wxTOKEN_STRTOK);
 
392
    wxString PathSoFar = _T("");
 
393
    wxTreeItemId IdSoFar = m_KnownLibrariesTree->GetRootItem();
 
394
    bool FirstElem = true;
 
395
    while ( Tokens.HasMoreTokens() )
 
396
    {
 
397
        // Iterate through items already added to map
 
398
        wxString Part = Tokens.GetNextToken();
 
399
        PathSoFar += Part.Lower();
 
400
        if ( m_CategoryMap.find(PathSoFar) == m_CategoryMap.end() )
 
401
        {
 
402
            // Ok, found first node which is not yet added, this mean
 
403
            // that all subnodes are also not yet added
 
404
            int SkipLast = FirstElem ? (m_IsOtherCategory?1:0) + (m_IsPkgConfig?1:0) : 0;
 
405
 
 
406
            // First elem of the path must take into consideration
 
407
            // that some categoies must remain at the end
 
408
            if ( SkipLast )
 
409
            {
 
410
                IdSoFar = m_CategoryMap[PathSoFar] =
 
411
                    m_KnownLibrariesTree->InsertItem(
 
412
                        IdSoFar,
 
413
                        m_KnownLibrariesTree->GetChildrenCount(IdSoFar,false)-SkipLast,
 
414
                        Part);
 
415
                FirstElem = false;
 
416
            }
 
417
            else
 
418
            {
 
419
                IdSoFar = m_CategoryMap[PathSoFar] =
 
420
                    m_KnownLibrariesTree->AppendItem(IdSoFar,Part);
 
421
            }
 
422
 
 
423
            // Next items are always added at the end
 
424
            while ( Tokens.HasMoreTokens() )
 
425
            {
 
426
                Part = Tokens.GetNextToken();
 
427
                PathSoFar += _T(".");
 
428
                PathSoFar = Part.Lower();
 
429
                IdSoFar = m_CategoryMap[PathSoFar] =
 
430
                    m_KnownLibrariesTree->AppendItem(IdSoFar,Part);
 
431
            }
 
432
 
 
433
            // If we're here, all remaining path has been added, so we
 
434
            // finished here
 
435
            break;
 
436
        }
 
437
        FirstElem = false;
 
438
        PathSoFar += _T(".");
 
439
    }
 
440
    // Just for sure if there are multiple dots
 
441
    m_CategoryMap[Category.Lower()] = IdSoFar;
 
442
    return IdSoFar;
 
443
}
 
444
 
 
445
void ProjectConfigurationPanel::Onm_TreeClick(wxCommandEvent& event)
 
446
{
 
447
    FillKnownLibraries();
 
448
}
 
449
 
 
450
void ProjectConfigurationPanel::OnTimer1Trigger(wxTimerEvent& event)
 
451
{
 
452
    FillKnownLibraries();
 
453
}
 
454
 
 
455
void ProjectConfigurationPanel::Onm_FilterText(wxCommandEvent& event)
 
456
{
 
457
    Timer1.Start(500,true);
 
458
}
 
459
 
 
460
void ProjectConfigurationPanel::Onm_FilterTextEnter(wxCommandEvent& event)
 
461
{
 
462
    FillKnownLibraries();
 
463
}
 
464
 
 
465
void ProjectConfigurationPanel::Onm_KnownLibrariesTreeSelectionChanged(wxTreeEvent& event)
 
466
{
 
467
    if ( m_KnownLibrariesTree->GetSelection().IsOk() )
 
468
    {
 
469
        TreeItemData* Data = (TreeItemData*)m_KnownLibrariesTree->GetItemData(m_KnownLibrariesTree->GetSelection());
 
470
        if ( Data )
 
471
        {
 
472
            wxString Library = Data->m_ShortCode;
 
473
            if ( m_ConfCopy.m_GlobalUsedLibs.Index(Library) == wxNOT_FOUND )
 
474
            {
 
475
                m_Add->Enable();
 
476
                return;
 
477
            }
 
478
        }
 
479
    }
 
480
    m_Add->Disable();
 
481
}
 
482
 
 
483
void ProjectConfigurationPanel::Onm_UsedLibrariesSelect(wxCommandEvent& event)
 
484
{
 
485
    m_Remove->Enable( m_UsedLibraries->GetSelection() != wxNOT_FOUND );
 
486
}
 
487
 
 
488
void ProjectConfigurationPanel::Onm_RemoveClick(wxCommandEvent& event)
 
489
{
 
490
    if ( m_UsedLibraries->GetSelection() != wxNOT_FOUND )
 
491
    {
 
492
        wxString Library =
 
493
            ((ListItemData*)m_UsedLibraries->GetClientObject(
 
494
                m_UsedLibraries->GetSelection()))->m_ShortCode;
 
495
        m_ConfCopy.m_GlobalUsedLibs.Remove(Library);
 
496
        m_UsedLibraries->Delete(m_UsedLibraries->GetSelection());
 
497
        m_Remove->Disable();
 
498
        wxTreeEvent ev;
 
499
        Onm_KnownLibrariesTreeSelectionChanged(ev);
 
500
    }
 
501
}
 
502
 
 
503
void ProjectConfigurationPanel::Onm_AddClick(wxCommandEvent& event)
 
504
{
 
505
    if ( m_KnownLibrariesTree->GetSelection().IsOk() )
 
506
    {
 
507
        TreeItemData* Data = (TreeItemData*)m_KnownLibrariesTree->GetItemData(m_KnownLibrariesTree->GetSelection());
 
508
        if ( Data )
 
509
        {
 
510
            wxString Library = Data->m_ShortCode;
 
511
            if ( m_ConfCopy.m_GlobalUsedLibs.Index(Library) == wxNOT_FOUND )
 
512
            {
 
513
                m_ConfCopy.m_GlobalUsedLibs.Add(Library);
 
514
                m_UsedLibraries->Append(GetUserListName(Library),new ListItemData(Library));
 
515
                m_Add->Disable();
 
516
                return;
 
517
            }
 
518
        }
 
519
    }
 
520
}
 
521
 
 
522
void ProjectConfigurationPanel::Onm_UnknownLibraryText(wxCommandEvent& event)
 
523
{
 
524
    m_AddUnknown->Enable(m_UnknownLibrary->GetLastPosition()!=0);
 
525
}
 
526
 
 
527
void ProjectConfigurationPanel::Onm_AddUnknownClick(wxCommandEvent& event)
 
528
{
 
529
    wxString Library = m_UnknownLibrary->GetValue();
 
530
    if ( !Library.IsEmpty() )
 
531
    {
 
532
        if ( m_ConfCopy.m_GlobalUsedLibs.Index(Library) == wxNOT_FOUND )
 
533
        {
 
534
            m_ConfCopy.m_GlobalUsedLibs.Add(Library);
 
535
            m_UsedLibraries->Append(GetUserListName(Library),new ListItemData(Library));
 
536
            wxTreeEvent ev;
 
537
            Onm_KnownLibrariesTreeSelectionChanged(ev);
 
538
        }
 
539
    }
 
540
}
 
541
 
 
542
void ProjectConfigurationPanel::Onm_AddScriptClick(wxCommandEvent& event)
 
543
{
 
544
    wxFile Fl(m_Project->GetBasePath() + wxFileName::GetPathSeparator() + _T("lib_finder.script"),wxFile::write);
 
545
    if ( !Fl.IsOpened() )
 
546
    {
 
547
        wxMessageBox(_("Couldn't create file \"lib_finder.script\" in project's base path"),_("lib_finder.script error"),wxOK|wxICON_ERROR,this);
 
548
        return;
 
549
    }
 
550
 
 
551
    if ( !Fl.Write(
 
552
        _T("function SetBuildOptions(base)\n")
 
553
        _T("{\n")
 
554
        _T("\tif ( \"LibFinder\" in getroottable() )\n")
 
555
        _T("\t{\n")
 
556
        _T("\t\tLibFinder.SetupTarget(base);\n")
 
557
        _T("\t}\n")
 
558
        _T("}\n"),
 
559
        wxConvUTF8) )
 
560
    {
 
561
        wxMessageBox(_("Couldn't write script file \"lib_finder.script\"."),_("lib_finder.script error"),wxOK|wxICON_ERROR,this);
 
562
        return;
 
563
    }
 
564
    Fl.Close();
 
565
 
 
566
    m_Project->AddBuildScript(_T("lib_finder.script"));
 
567
    m_AddScript->Disable();
 
568
    m_NoAuto->SetValue(true);
 
569
 
 
570
    wxMessageBox(_("Script \"lib_finder.script\" successfully added."),_("lib_finder.script Success"),wxOK|wxICON_INFORMATION,this);
 
571
}