~ubuntu-branches/ubuntu/lucid/cmake/lucid

« back to all changes in this revision

Viewing changes to Source/WXDialog/CMakeSetupFrame.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2009-12-16 11:11:54 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091216111154-6accvv6yq86h2hkc
Tags: 2.8.0-5ubuntu1
* Merge from debian testing (LP: #497349). Remaining changes:
  - Keep the Replaces: on cmake-data to cover the Kubuntu version from
    Jaunty in case someone decides to do an (unsupported) Jaunty->Lucid
    upgrade.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*=========================================================================
2
 
 
3
 
  Program:   WXDialog - wxWidgets X-platform GUI Front-End for CMake
4
 
  Module:    $RCSfile: CMakeSetupFrame.cpp,v $
5
 
  Language:  C++
6
 
  Date:      $Date: 2007-11-05 19:47:20 $
7
 
  Version:   $Revision: 1.3 $
8
 
 
9
 
  Author:    Jorgen Bodde
10
 
 
11
 
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
12
 
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
13
 
 
14
 
     This software is distributed WITHOUT ANY WARRANTY; without even 
15
 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
16
 
     PURPOSE.  See the above copyright notices for more information.
17
 
 
18
 
=========================================================================*/
19
 
 
20
 
#if defined(__GNUG__) && !defined(__APPLE__)
21
 
#pragma implementation "CMakeSetupFrame.h"
22
 
#endif
23
 
 
24
 
// For compilers that support precompilation, includes "wx/wx.h".
25
 
#include "wx/wxprec.h"
26
 
 
27
 
#ifdef __BORLANDC__
28
 
#pragma hdrstop
29
 
#endif
30
 
 
31
 
#ifndef WX_PRECOMP
32
 
#include "wx/wx.h"
33
 
#endif
34
 
 
35
 
////@begin includes
36
 
////@end includes
37
 
 
38
 
#include <wx/dirdlg.h>
39
 
#include <wx/msgdlg.h>
40
 
#include <wx/filename.h>
41
 
 
42
 
#include "CMakeSetupFrame.h"
43
 
#include "PropertyList.h"
44
 
#include "app_resources.h"
45
 
#include "CMakeIcon.xpm"
46
 
#include "aboutdlg.h"
47
 
 
48
 
// cmake includes
49
 
#include "../cmVersion.h"
50
 
#include "../cmListFileCache.h"
51
 
#include "../cmCacheManager.h"
52
 
#include "../cmGlobalGenerator.h"
53
 
#include "../cmDynamicLoader.h"
54
 
 
55
 
////@begin XPM images
56
 
////@end XPM images
57
 
 
58
 
/*!
59
 
 * CMakeSetupFrm type definition
60
 
 */
61
 
 
62
 
IMPLEMENT_CLASS( CMakeSetupFrm, wxFrame )
63
 
 
64
 
/*!
65
 
 * CMakeSetupFrm event table definition
66
 
 */
67
 
 
68
 
BEGIN_EVENT_TABLE( CMakeSetupFrm, wxFrame )
69
 
 
70
 
////@begin CMakeSetupFrm event table entries
71
 
    EVT_CLOSE( CMakeSetupFrm::OnCloseWindow )
72
 
 
73
 
    EVT_SPLITTER_SASH_POS_CHANGING( ID_SPLITTERWINDOW, CMakeSetupFrm::OnSplitterPosChanging )
74
 
    EVT_SPLITTER_DCLICK( ID_SPLITTERWINDOW, CMakeSetupFrm::OnSplitterwindowSashDClick )
75
 
 
76
 
    EVT_BUTTON( ID_BROWSE_PROJECT, CMakeSetupFrm::OnButtonBrowseProject )
77
 
 
78
 
    EVT_TEXT( ID_SOURCE_BUILD_PATH, CMakeSetupFrm::OnSourceBuildPathUpdated )
79
 
    EVT_TEXT_ENTER( ID_SOURCE_BUILD_PATH, CMakeSetupFrm::OnSourceBuildPathEnter )
80
 
 
81
 
    EVT_BUTTON( ID_BROWSE_BUILD, CMakeSetupFrm::OnButtonBrowseBuild )
82
 
 
83
 
    EVT_COMBOBOX( ID_SEARCHQUERY, CMakeSetupFrm::OnSearchquerySelected )
84
 
    EVT_TEXT( ID_SEARCHQUERY, CMakeSetupFrm::OnSearchqueryUpdated )
85
 
 
86
 
    EVT_CHECKBOX( ID_SHOW_ADVANCED, CMakeSetupFrm::OnShowAdvancedValues )
87
 
 
88
 
    EVT_GRID_CELL_CHANGE( CMakeSetupFrm::OnCellChange )
89
 
    EVT_GRID_SELECT_CELL( CMakeSetupFrm::OnGridSelectCell )
90
 
    EVT_MOTION( CMakeSetupFrm::OnPropertyMotion )
91
 
 
92
 
    EVT_BUTTON( ID_DO_CONFIGURE, CMakeSetupFrm::OnButtonConfigure )
93
 
 
94
 
    EVT_BUTTON( ID_DO_OK, CMakeSetupFrm::OnButtonOk )
95
 
 
96
 
    EVT_BUTTON( ID_DO_CANCEL, CMakeSetupFrm::OnButtonCancel )
97
 
 
98
 
    EVT_BUTTON( ID_DO_DELETE_CACHE, CMakeSetupFrm::OnButtonDeleteCache )
99
 
 
100
 
    EVT_BUTTON( ID_CLEAR_LOG, CMakeSetupFrm::OnClearLogClick )
101
 
 
102
 
    EVT_BUTTON( ID_BROWSE_GRID, CMakeSetupFrm::OnBrowseGridClick )
103
 
 
104
 
    EVT_MENU( ID_MENU_RELOAD_CACHE, CMakeSetupFrm::OnMenuReloadCacheClick )
105
 
 
106
 
    EVT_MENU( ID_MENU_DELETE_CACHE, CMakeSetupFrm::OnMenuDeleteCacheClick )
107
 
 
108
 
    EVT_MENU( ID_MENU_QUIT, CMakeSetupFrm::OnMenuQuitClick )
109
 
 
110
 
    EVT_MENU( ID_MENU_CONFIGURE, CMakeSetupFrm::OnMenuConfigureClick )
111
 
 
112
 
    EVT_MENU( ID_MENU_EXITGENERATE, CMakeSetupFrm::OnMenuGenerateClick )
113
 
 
114
 
    EVT_MENU( ID_MENU_TOGGLE_ADVANCED, CMakeSetupFrm::OnMenuToggleAdvancedClick )
115
 
 
116
 
    EVT_MENU( ID_CMAKE_OPTIONS, CMakeSetupFrm::OnOptionsClick )
117
 
 
118
 
    EVT_MENU( ID_ABOUTDLG, CMakeSetupFrm::OnAboutClick )
119
 
 
120
 
////@end CMakeSetupFrm event table entries
121
 
 
122
 
    EVT_MENU_RANGE(CM_RECENT_BUILD_ITEM, CM_RECENT_BUILD_ITEM + CM_MAX_RECENT_PATHS, CMakeSetupFrm::OnRecentFileMenu)   
123
 
 
124
 
    EVT_TEXT_ENTER(ID_SEARCHQUERY, CMakeSetupFrm::OnAddQuery )
125
 
 
126
 
END_EVENT_TABLE()
127
 
 
128
 
/** Callback function for CMake generator, to tell user how
129
 
    far the generation actually is */
130
 
void updateProgress(const char *msg, float prog, void *cd)
131
 
{
132
 
    // TODO: Make some kind of progress counter 
133
 
    
134
 
    CMakeSetupFrm *fm = (CMakeSetupFrm *)cd;
135
 
 
136
 
    if(fm)
137
 
    {
138
 
        if(prog < 0)
139
 
            fm->LogMessage(0, msg);
140
 
        else
141
 
        {
142
 
            fm->UpdateProgress(prog);
143
 
            fm->IssueUpdate();
144
 
        }
145
 
    }
146
 
}
147
 
 
148
 
/** Callback function for CMake generator, to tell user about stuff. This should be
149
 
    logged in the m_log window */
150
 
void MFCMessageCallback(const char* m, const char* title, bool& nomore, void *clientdata)
151
 
152
 
    CMakeSetupFrm *fm = (CMakeSetupFrm *)clientdata;
153
 
 
154
 
    if(fm)
155
 
    {
156
 
        wxString what = m, msg;
157
 
        if(what.StartsWith("CMake Error: "))
158
 
            fm->LogMessage(-1, m);
159
 
        else
160
 
            fm->LogMessage(1, m);
161
 
    }
162
 
}
163
 
 
164
 
// Convert to Win32 path (slashes). This calls the system tools one and then
165
 
// removes the spaces. It is not in system tools because we don't want any
166
 
// generators accidentally use it
167
 
std::string ConvertToWindowsPath(const char* path)
168
 
{
169
 
  // Convert to output path.
170
 
  // Remove the "" around it (if any) since it's an output path for
171
 
  // the shell. If another shell-oriented feature is not designed 
172
 
  // for a GUI use, then we are in trouble.
173
 
  // save the value of the force to unix path option
174
 
  bool saveForce = cmSystemTools::GetForceUnixPaths();
175
 
  // make sure we get windows paths no matter what for the GUI
176
 
  cmSystemTools::SetForceUnixPaths(false);
177
 
  std::string s = cmSystemTools::ConvertToOutputPath(path);
178
 
  // now restore the force unix path to its previous value
179
 
  cmSystemTools::SetForceUnixPaths(saveForce);
180
 
  if (s.size())
181
 
    {
182
 
    std::string::iterator i = s.begin();
183
 
    if (*i == '\"')
184
 
      {
185
 
      s.erase(i, i + 1);
186
 
      }
187
 
    i = s.begin() + s.length() - 1;
188
 
    if (*i == '\"')
189
 
      {
190
 
      s.erase(i, i + 1);
191
 
      }
192
 
    }
193
 
  return s;
194
 
}
195
 
 
196
 
 
197
 
bool DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames)
198
 
{
199
 
    size_t nFiles = filenames.GetCount();
200
 
 
201
 
    // only one item allowed
202
 
    if(nFiles > 1)
203
 
        return false;
204
 
 
205
 
    if(nFiles == 1)
206
 
    {
207
 
        // only one dir allowed
208
 
        if(!wxDirExists(filenames[0]))
209
 
            return false;
210
 
 
211
 
        // strip the seperator
212
 
        wxFileName name;
213
 
        name.AssignDir(filenames[0]);       
214
 
        
215
 
        // issue a 'drop' by changing text ctrl
216
 
        m_pOwner->SetValue(name.GetFullPath());
217
 
 
218
 
        return true;
219
 
    }
220
 
 
221
 
    return false;
222
 
}
223
 
 
224
 
/*!
225
 
 * CMakeSetupFrm constructors
226
 
 */
227
 
 
228
 
CMakeSetupFrm::CMakeSetupFrm( )
229
 
    : m_cmake(0)
230
 
{
231
 
}
232
 
 
233
 
CMakeSetupFrm::CMakeSetupFrm( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
234
 
    : m_cmake(0)
235
 
{
236
 
    Create( parent, id, caption, pos, size, style );
237
 
}
238
 
 
239
 
/*!
240
 
 * CMakeSetupFrm creator
241
 
 */
242
 
 
243
 
bool CMakeSetupFrm::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
244
 
{
245
 
////@begin CMakeSetupFrm member initialisation
246
 
    m_splitter = NULL;
247
 
    m_cmProjectPath = NULL;
248
 
    m_BrowseProjectPathButton = NULL;
249
 
    m_cmBuildPath = NULL;
250
 
    m_BrowseSourcePathButton = NULL;
251
 
    m_cmGeneratorChoice = NULL;
252
 
    m_cmSearchQuery = NULL;
253
 
    m_cmShowAdvanced = NULL;
254
 
    m_cmOptions = NULL;
255
 
    m_cmLog = NULL;
256
 
    m_cmDescription = NULL;
257
 
    m_ConfigureButton = NULL;
258
 
    m_OkButton = NULL;
259
 
    m_CancelButton = NULL;
260
 
    m_DeleteCacheButton = NULL;
261
 
    m_ClearLogButton = NULL;
262
 
    m_cmBrowseCell = NULL;
263
 
////@end CMakeSetupFrm member initialisation
264
 
 
265
 
    wxFrame::Create( parent, id, caption, pos, size, style );
266
 
 
267
 
    // make sure the developer does not assign more then 100
268
 
    // would be rediculous but also overlap other id's
269
 
    wxASSERT(CM_MAX_RECENT_PATHS < 100);
270
 
 
271
 
    m_ExitTimer = 0;
272
 
 
273
 
    m_progressDlg = 0;
274
 
    m_noRefresh = false;
275
 
    m_quitAfterGenerating = false;
276
 
 
277
 
    m_config = new wxConfig("CMakeSetup");
278
 
 
279
 
    wxIcon icon(CMakeIcon_xpm);
280
 
    SetIcon(icon);
281
 
 
282
 
    CreateControls();
283
 
    
284
 
    //SetIcon(GetIconResource(wxT("cmake_icon.xpm")));
285
 
    //SetIcon(wxIcon("NGDialog.ico", wxBITMAP_TYPE_ICO_RESOURCE));
286
 
    Centre();
287
 
 
288
 
    // is it needed to hide console?
289
 
    m_RunningConfigure = false;
290
 
    cmSystemTools::SetRunCommandHideConsole(true);
291
 
    cmSystemTools::SetErrorCallback(MFCMessageCallback, (void *)this);
292
 
 
293
 
    // create our cmake instance
294
 
    m_cmake = new cmake;
295
 
    m_cmake->SetProgressCallback(updateProgress, (void *)this);
296
 
 
297
 
    return TRUE;
298
 
}
299
 
 
300
 
CMakeSetupFrm::~CMakeSetupFrm()
301
 
{
302
 
    wxString str;
303
 
 
304
 
    // write configs back to disk
305
 
    m_config->Write(CM_LASTPROJECT_PATH, m_cmProjectPath->GetValue());
306
 
    m_config->Write(CM_LASTBUILD_PATH, m_cmBuildPath->GetValue());
307
 
 
308
 
    // clear the config first
309
 
    for(size_t i = 0 ; i < CM_MAX_RECENT_PATHS; i++)
310
 
    {
311
 
        str.Printf("%s%i", _(CM_RECENT_BUILD_PATH), i);
312
 
        m_config->Write(str, _(""));
313
 
    }
314
 
 
315
 
    // write the last CM_MAX_RECENT_PATHS items back to config
316
 
    int i = (m_recentPaths.Count() >= CM_MAX_RECENT_PATHS ? CM_MAX_RECENT_PATHS : m_recentPaths.Count());
317
 
    while(i > 0)
318
 
    {
319
 
        str.Printf("%s%i", _(CM_RECENT_BUILD_PATH), i);
320
 
        m_config->Write(str, m_recentPaths[i - 1]);
321
 
        i--;
322
 
    }
323
 
    
324
 
    // write recent query list to config
325
 
    for(int j = 0; j < m_cmSearchQuery->GetCount(); j++)
326
 
    {
327
 
        // allow max to be written
328
 
        if(j < CM_MAX_SEARCH_QUERIES)
329
 
        {
330
 
            str.Printf("%s%i", _(CM_SEARCH_QUERY), j);
331
 
            m_config->Write(str, m_cmSearchQuery->GetString(j));
332
 
        }
333
 
        else
334
 
            break;
335
 
    }
336
 
 
337
 
    // set window pos + size in settings
338
 
    if(!IsIconized() && !IsMaximized())
339
 
    {
340
 
        int xsize, ysize;
341
 
        GetSize(&xsize, &ysize);
342
 
        if(xsize > 0 && ysize > 0) 
343
 
        {
344
 
            m_config->Write(CM_XSIZE, (long)xsize);
345
 
            m_config->Write(CM_YSIZE, (long)ysize);
346
 
        }
347
 
 
348
 
        if(m_splitter->GetSashPosition() > 0)
349
 
            m_config->Write(CM_SPLITTERPOS, (long)m_splitter->GetSashPosition());
350
 
 
351
 
        GetPosition(&xsize, &ysize);
352
 
        if(xsize != 0 && ysize != 0) 
353
 
        {
354
 
            m_config->Write(CM_XPOS, (long)xsize);
355
 
            m_config->Write(CM_YPOS, (long)ysize);
356
 
        }
357
 
    }
358
 
 
359
 
    // write changes (will be done before deletion)
360
 
    delete m_config;
361
 
    
362
 
    // delete timer
363
 
    if(m_ExitTimer)
364
 
        delete m_ExitTimer;
365
 
 
366
 
    // delete our cmake instance again
367
 
    if(m_cmake)
368
 
        delete m_cmake;
369
 
}
370
 
 
371
 
void CMakeSetupFrm::UpdateWindowState()
372
 
{
373
 
    bool dogenerate = !m_RunningConfigure && !m_cmOptions->IsCacheDirty() && 
374
 
                       (m_cmOptions->GetCount() != 0);
375
 
    
376
 
    // when configure is running, disable a lot of stuff
377
 
    m_cmProjectPath->Enable(!m_RunningConfigure);
378
 
    m_BrowseProjectPathButton->Enable(!m_RunningConfigure);
379
 
    m_cmBuildPath->Enable(!m_RunningConfigure);
380
 
    m_BrowseSourcePathButton->Enable(!m_RunningConfigure);
381
 
    m_cmGeneratorChoice->Enable(!m_RunningConfigure);
382
 
    m_cmShowAdvanced->Enable(!m_RunningConfigure);
383
 
    m_cmOptions->Enable(!m_RunningConfigure);
384
 
    m_ConfigureButton->Enable(!m_RunningConfigure);
385
 
    m_OkButton->Enable(dogenerate);
386
 
    m_CancelButton->Enable(m_RunningConfigure);
387
 
    m_DeleteCacheButton->Enable(!m_RunningConfigure);
388
 
    m_ClearLogButton->Enable(!m_RunningConfigure);
389
 
    if(m_RunningConfigure)
390
 
        m_cmBrowseCell->Enable(false);
391
 
 
392
 
    // when cache loaded (items available show other control)
393
 
    m_cmGeneratorChoice->Enable(m_cmOptions->GetCount() == 0 && !m_RunningConfigure);
394
 
    m_cmSearchQuery->Enable(!m_RunningConfigure);
395
 
    m_cmBrowseCell->Enable(!m_RunningConfigure && m_cmOptions->IsSelectedItemBrowsable());
396
 
 
397
 
    // disable the menus when configuring
398
 
    if(GetMenuBar())
399
 
    {
400
 
        // disable configure button when there is nothing, and generate and exit
401
 
        // only when it is allowed to generate
402
 
        GetMenuBar()->Enable(ID_MENU_EXITGENERATE, dogenerate);
403
 
        GetMenuBar()->Enable(ID_MENU_CONFIGURE, !m_RunningConfigure);
404
 
 
405
 
        for(size_t i = 0; i < GetMenuBar()->GetMenuCount(); i++)
406
 
            GetMenuBar()->EnableTop(i, !m_RunningConfigure); 
407
 
    }
408
 
}
409
 
 
410
 
void CMakeSetupFrm::LogMessage(int logkind, const char *msg)
411
 
{
412
 
    // put CR first but prevent a CR at the end
413
 
#ifndef __LINUX__   
414
 
    if(m_cmLog->IsModified())
415
 
        (*m_cmLog) << wxT("\n");
416
 
#else
417
 
    // Linux requires a different approach
418
 
    if(!m_cmLog->GetValue().IsEmpty())
419
 
        (*m_cmLog) << wxT("\n");
420
 
#endif        
421
 
 
422
 
    // log error, warning, or message
423
 
    wxTextAttr defattr = m_cmLog->GetDefaultStyle();
424
 
    
425
 
    switch(logkind)
426
 
    {
427
 
    // user message
428
 
    case 1:
429
 
        {
430
 
            wxTextAttr colattr(*wxBLUE);
431
 
            m_cmLog->SetDefaultStyle(colattr);
432
 
            (*m_cmLog) << msg;
433
 
            m_cmLog->SetDefaultStyle(defattr);
434
 
        }
435
 
        break;
436
 
 
437
 
    // progress
438
 
    case 0:
439
 
        (*m_cmLog) << msg;
440
 
        break;
441
 
 
442
 
    // error
443
 
    case -1:
444
 
        {
445
 
            wxTextAttr colattr(*wxRED);
446
 
            m_cmLog->SetDefaultStyle(colattr);
447
 
            (*m_cmLog) << msg;
448
 
            m_cmLog->SetDefaultStyle(defattr);
449
 
        }
450
 
        break;
451
 
    }
452
 
        
453
 
    IssueUpdate();
454
 
}
455
 
 
456
 
void CMakeSetupFrm::IssueUpdate()
457
 
{
458
 
    //::wxSafeYield(m_CancelButton, true);
459
 
    ::wxYield();
460
 
 
461
 
    // when we pressed cancel on the progress dialog
462
 
    // stop all activities
463
 
    if(m_progressDlg)
464
 
    {
465
 
        if(m_progressDlg->CancelPressed() && !m_progressDlg->IsCancelling())
466
 
        {           
467
 
            m_progressDlg->CancelAcknowledged();
468
 
 
469
 
            // send a button event to cancel the progress
470
 
            wxCommandEvent event( wxEVT_COMMAND_BUTTON_CLICKED, ID_DO_CANCEL);
471
 
            wxPostEvent(this, event);
472
 
        }
473
 
    }
474
 
}
475
 
 
476
 
/*!
477
 
 * Control creation for CMakeSetupFrm
478
 
 */
479
 
 
480
 
void CMakeSetupFrm::CreateControls()
481
 
{    
482
 
////@begin CMakeSetupFrm content construction
483
 
    CMakeSetupFrm* itemFrame1 = this;
484
 
 
485
 
    wxMenuBar* menuBar = new wxMenuBar;
486
 
    wxMenu* itemMenu37 = new wxMenu;
487
 
    itemMenu37->Append(ID_MENU_RELOAD_CACHE, _("&Reload Cache\tCtrl+R"), _("Reload the cache from disk"), wxITEM_NORMAL);
488
 
    itemMenu37->Append(ID_MENU_DELETE_CACHE, _("&Delete Cache\tCtrl+D"), _("Delete the cache on disk of the current path"), wxITEM_NORMAL);
489
 
    itemMenu37->AppendSeparator();
490
 
    itemMenu37->Append(ID_MENU_QUIT, _("E&xit\tAlt+F4"), _("Quit CMake Setup"), wxITEM_NORMAL);
491
 
    menuBar->Append(itemMenu37, _("&File"));
492
 
    wxMenu* itemMenu42 = new wxMenu;
493
 
    itemMenu42->Append(ID_MENU_CONFIGURE, _("&Configure\tCtrl+N"), _T(""), wxITEM_NORMAL);
494
 
    itemMenu42->Append(ID_MENU_EXITGENERATE, _("&Generate and Exit\tCtrl+G"), _T(""), wxITEM_NORMAL);
495
 
    itemMenu42->Append(ID_MENU_TOGGLE_ADVANCED, _("Toggle &Advanced\tCtrl+A"), _T(""), wxITEM_NORMAL);
496
 
    itemMenu42->AppendSeparator();
497
 
    itemMenu42->Append(ID_CMAKE_OPTIONS, _("&Options\tCtrl+O"), _T(""), wxITEM_NORMAL);
498
 
    menuBar->Append(itemMenu42, _("&Tools"));
499
 
    wxMenu* itemMenu48 = new wxMenu;
500
 
    itemMenu48->Append(ID_ABOUTDLG, _("&About ..."), _("Shows the about dialog ..."), wxITEM_NORMAL);
501
 
    menuBar->Append(itemMenu48, _("&Help"));
502
 
    itemFrame1->SetMenuBar(menuBar);
503
 
 
504
 
    m_splitter = new wxSplitterWindow( itemFrame1, ID_SPLITTERWINDOW, wxDefaultPosition, wxSize(100, 100), wxSP_3DBORDER|wxSP_3DSASH|wxNO_BORDER );
505
 
 
506
 
    wxPanel* itemPanel3 = new wxPanel( m_splitter, ID_MAINPANEL, wxDefaultPosition, wxSize(600, 400), wxNO_BORDER|wxTAB_TRAVERSAL );
507
 
    itemPanel3->SetExtraStyle(itemPanel3->GetExtraStyle()|wxWS_EX_VALIDATE_RECURSIVELY);
508
 
    wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
509
 
    itemPanel3->SetSizer(itemBoxSizer4);
510
 
 
511
 
    wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
512
 
    itemBoxSizer4->Add(itemBoxSizer5, 0, wxGROW|wxTOP|wxBOTTOM, 5);
513
 
    wxFlexGridSizer* itemFlexGridSizer6 = new wxFlexGridSizer(2, 3, 0, 0);
514
 
    itemFlexGridSizer6->AddGrowableRow(1);
515
 
    itemFlexGridSizer6->AddGrowableCol(1);
516
 
    itemBoxSizer5->Add(itemFlexGridSizer6, 1, wxALIGN_TOP|wxLEFT, 5);
517
 
    wxStaticText* itemStaticText7 = new wxStaticText( itemPanel3, wxID_STATIC, _("CMake project path"), wxDefaultPosition, wxDefaultSize, 0 );
518
 
    itemFlexGridSizer6->Add(itemStaticText7, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);
519
 
 
520
 
    m_cmProjectPath = new wxTextCtrl( itemPanel3, ID_PROJECT_PATH, _T(""), wxDefaultPosition, wxSize(50, -1), 0 );
521
 
    itemFlexGridSizer6->Add(m_cmProjectPath, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5);
522
 
 
523
 
    m_BrowseProjectPathButton = new wxButton( itemPanel3, ID_BROWSE_PROJECT, _("Browse"), wxDefaultPosition, wxSize(55, -1), 0 );
524
 
    itemFlexGridSizer6->Add(m_BrowseProjectPathButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
525
 
 
526
 
    wxStaticText* itemStaticText10 = new wxStaticText( itemPanel3, wxID_STATIC, _("Project build path"), wxDefaultPosition, wxDefaultSize, 0 );
527
 
    itemFlexGridSizer6->Add(itemStaticText10, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);
528
 
 
529
 
    m_cmBuildPath = new wxTextCtrl( itemPanel3, ID_SOURCE_BUILD_PATH, _T(""), wxDefaultPosition, wxSize(50, -1), 0 );
530
 
    itemFlexGridSizer6->Add(m_cmBuildPath, 1, wxGROW|wxALIGN_TOP|wxTOP|wxBOTTOM, 5);
531
 
 
532
 
    m_BrowseSourcePathButton = new wxButton( itemPanel3, ID_BROWSE_BUILD, _("Browse"), wxDefaultPosition, wxSize(55, -1), 0 );
533
 
    itemFlexGridSizer6->Add(m_BrowseSourcePathButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
534
 
 
535
 
    wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxVERTICAL);
536
 
    itemBoxSizer5->Add(itemBoxSizer13, 0, wxGROW|wxLEFT|wxRIGHT, 5);
537
 
    wxFlexGridSizer* itemFlexGridSizer14 = new wxFlexGridSizer(2, 2, 0, 0);
538
 
    itemBoxSizer13->Add(itemFlexGridSizer14, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT, 5);
539
 
    wxStaticText* itemStaticText15 = new wxStaticText( itemPanel3, wxID_STATIC, _("Generate"), wxDefaultPosition, wxDefaultSize, 0 );
540
 
    itemFlexGridSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxADJUST_MINSIZE, 5);
541
 
 
542
 
    wxString* m_cmGeneratorChoiceStrings = NULL;
543
 
    m_cmGeneratorChoice = new wxComboBox( itemPanel3, ID_CHOOSE_GENERATOR, _T(""), wxDefaultPosition, wxSize(170, -1), 0, m_cmGeneratorChoiceStrings, wxCB_READONLY );
544
 
    itemFlexGridSizer14->Add(m_cmGeneratorChoice, 1, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxTOP|wxBOTTOM, 5);
545
 
 
546
 
    wxStaticText* itemStaticText17 = new wxStaticText( itemPanel3, wxID_STATIC, _("Search"), wxDefaultPosition, wxDefaultSize, 0 );
547
 
    itemFlexGridSizer14->Add(itemStaticText17, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxADJUST_MINSIZE, 5);
548
 
 
549
 
    wxString* m_cmSearchQueryStrings = NULL;
550
 
    m_cmSearchQuery = new wxComboBox( itemPanel3, ID_SEARCHQUERY, _T(""), wxDefaultPosition, wxSize(170, -1), 0, m_cmSearchQueryStrings, wxWANTS_CHARS );
551
 
    itemFlexGridSizer14->Add(m_cmSearchQuery, 1, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxTOP|wxBOTTOM, 5);
552
 
 
553
 
    m_cmShowAdvanced = new wxCheckBox( itemPanel3, ID_SHOW_ADVANCED, _("Show advanced values"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE );
554
 
    m_cmShowAdvanced->SetValue(FALSE);
555
 
    itemBoxSizer13->Add(m_cmShowAdvanced, 0, wxALIGN_RIGHT|wxLEFT|wxRIGHT, 5);
556
 
 
557
 
    m_cmOptions = new wxPropertyList( itemPanel3, ID_OPTIONS, wxDefaultPosition, wxSize(200, 150), wxSTATIC_BORDER|wxWANTS_CHARS|wxVSCROLL );
558
 
    m_cmOptions->SetDefaultColSize(250);
559
 
    m_cmOptions->SetDefaultRowSize(25);
560
 
    m_cmOptions->SetColLabelSize(20);
561
 
    m_cmOptions->SetRowLabelSize(0);
562
 
    m_cmOptions->CreateGrid(10, 2, wxGrid::wxGridSelectRows);
563
 
    itemBoxSizer4->Add(m_cmOptions, 1, wxGROW|wxALL, 5);
564
 
 
565
 
    wxPanel* itemPanel21 = new wxPanel( m_splitter, ID_LOGPANEL, wxDefaultPosition, wxSize(-1, 100), wxNO_BORDER|wxTAB_TRAVERSAL );
566
 
    wxBoxSizer* itemBoxSizer22 = new wxBoxSizer(wxVERTICAL);
567
 
    itemPanel21->SetSizer(itemBoxSizer22);
568
 
 
569
 
    wxBoxSizer* itemBoxSizer23 = new wxBoxSizer(wxHORIZONTAL);
570
 
    itemBoxSizer22->Add(itemBoxSizer23, 1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
571
 
    m_cmLog = new wxTextCtrl( itemPanel21, ID_LOG_AREA, _("Select your project path (where CMakeLists.txt is) and then select the build path (where the projects should be saved), or select a previous build path.\n\nRight click on a cache value for additional options (delete and ignore). Press configure to update and display new values in red, press OK to generate the projects and exit."), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH2|wxSTATIC_BORDER );
572
 
    itemBoxSizer23->Add(m_cmLog, 1, wxGROW|wxRIGHT, 5);
573
 
 
574
 
    m_cmDescription = new wxTextCtrl( itemPanel21, ID_DESCRIPTION, _T(""), wxDefaultPosition, wxSize(200, -1), wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH2|wxSTATIC_BORDER );
575
 
    itemBoxSizer23->Add(m_cmDescription, 0, wxGROW|wxLEFT, 5);
576
 
 
577
 
    wxBoxSizer* itemBoxSizer26 = new wxBoxSizer(wxHORIZONTAL);
578
 
    itemBoxSizer22->Add(itemBoxSizer26, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
579
 
    m_ConfigureButton = new wxButton( itemPanel21, ID_DO_CONFIGURE, _("Co&nfigure"), wxDefaultPosition, wxDefaultSize, 0 );
580
 
    m_ConfigureButton->SetDefault();
581
 
    itemBoxSizer26->Add(m_ConfigureButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
582
 
 
583
 
    m_OkButton = new wxButton( itemPanel21, ID_DO_OK, _("&Generate!"), wxDefaultPosition, wxDefaultSize, 0 );
584
 
    itemBoxSizer26->Add(m_OkButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
585
 
 
586
 
    m_CancelButton = new wxButton( itemPanel21, ID_DO_CANCEL, _("C&ancel"), wxDefaultPosition, wxDefaultSize, 0 );
587
 
    itemBoxSizer26->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
588
 
 
589
 
#if defined(__WXMSW__)
590
 
    wxStaticLine* itemStaticLine30 = new wxStaticLine( itemPanel21, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
591
 
    itemBoxSizer26->Add(itemStaticLine30, 0, wxGROW|wxALL, 5);
592
 
#endif
593
 
 
594
 
    m_DeleteCacheButton = new wxButton( itemPanel21, ID_DO_DELETE_CACHE, _("&Delete Cache"), wxDefaultPosition, wxDefaultSize, 0 );
595
 
    itemBoxSizer26->Add(m_DeleteCacheButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
596
 
 
597
 
    m_ClearLogButton = new wxButton( itemPanel21, ID_CLEAR_LOG, _("Clear &Log"), wxDefaultPosition, wxDefaultSize, 0 );
598
 
    itemBoxSizer26->Add(m_ClearLogButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
599
 
 
600
 
#if defined(__WXMSW__)
601
 
    wxStaticLine* itemStaticLine33 = new wxStaticLine( itemPanel21, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
602
 
    itemBoxSizer26->Add(itemStaticLine33, 0, wxGROW|wxALL, 5);
603
 
#endif
604
 
 
605
 
    m_cmBrowseCell = new wxButton( itemPanel21, ID_BROWSE_GRID, _("&Browse"), wxDefaultPosition, wxDefaultSize, 0 );
606
 
    itemBoxSizer26->Add(m_cmBrowseCell, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
607
 
 
608
 
    m_splitter->SplitHorizontally(itemPanel3, itemPanel21, 300);
609
 
 
610
 
    wxStatusBar* itemStatusBar35 = new wxStatusBar( itemFrame1, ID_STATUSBAR, wxST_SIZEGRIP|wxNO_BORDER );
611
 
    itemStatusBar35->SetFieldsCount(2);
612
 
    itemFrame1->SetStatusBar(itemStatusBar35);
613
 
 
614
 
////@end CMakeSetupFrm content construction
615
 
}
616
 
 
617
 
void CMakeSetupFrm::DoInitFrame(cmCommandLineInfo &cm, const wxString &fn)
618
 
619
 
    // path to where cmake.exe is
620
 
    // m_PathToExecutable = cm.GetPathToExecutable().c_str();
621
 
    m_PathToExecutable = fn;
622
 
 
623
 
    // adjust size of last bar, to display % progress
624
 
    wxStatusBar *bar = GetStatusBar();
625
 
    if(bar)
626
 
    {
627
 
        wxASSERT(bar->GetFieldsCount() > 1);
628
 
        
629
 
        // fill all with -1. Why this way? because the count of the status bars
630
 
        // can change. All of the widths must be accounted for and initialised
631
 
        int *widths = new int[bar->GetFieldsCount()];
632
 
        for(int i = 0; i < bar->GetFieldsCount(); i++)
633
 
            widths[i] = -1;
634
 
 
635
 
        // the % field
636
 
        widths[1] = 75;
637
 
        bar->SetStatusWidths(bar->GetFieldsCount(), widths);
638
 
        delete widths;
639
 
    }
640
 
 
641
 
    wxString name, generator;
642
 
    std::vector<std::string> names;
643
 
  
644
 
    m_RunningConfigure = false;
645
 
 
646
 
    // set grid labels
647
 
    m_cmOptions->SetColLabelValue(0, wxT("Cache Name"));
648
 
    m_cmOptions->SetColLabelValue(1, wxT("Cache Value"));
649
 
    m_cmOptions->SetProjectGenerated(false);
650
 
 
651
 
    // set drop target
652
 
    m_cmOptions->SetDropTarget(new DnDFile(m_cmBuildPath));
653
 
 
654
 
    m_cmake->GetRegisteredGenerators(names);
655
 
    for(std::vector<std::string>::iterator i = names.begin(); i != names.end(); ++i)
656
 
    {
657
 
        name = i->c_str();
658
 
        m_cmGeneratorChoice->Append(name);
659
 
    }
660
 
    
661
 
    // sync advanced option with grid
662
 
    m_cmOptions->SetShowAdvanced(m_cmShowAdvanced->GetValue());
663
 
 
664
 
    // if we have a command line query that a generator 
665
 
    // needs to be chosen instead of the default, take it
666
 
    bool foundGivenGenerator = false;
667
 
    if(!cm.m_GeneratorChoiceString.IsEmpty())
668
 
    {
669
 
        // set proper discovered generator
670
 
        foundGivenGenerator = m_cmGeneratorChoice->SetStringSelection(cm.m_GeneratorChoiceString);  
671
 
    }
672
 
 
673
 
    // if none selected, we will see if VS8, VS7 or VS6 is present
674
 
    if(!foundGivenGenerator || m_cmGeneratorChoice->GetValue().IsEmpty())
675
 
    {
676
 
        std::string mp;
677
 
        mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\Setup;Dbghelp_path]";
678
 
        cmSystemTools::ExpandRegistryValues(mp);
679
 
        if(mp != "/registry")
680
 
            generator = wxT("Visual Studio 8 2005");
681
 
        else
682
 
        {
683
 
            mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.1;InstallDir]";
684
 
            cmSystemTools::ExpandRegistryValues(mp);
685
 
            if (mp != "/registry")
686
 
                generator = wxT("Visual Studio 7 .NET 2003");
687
 
            else
688
 
            {
689
 
                mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.0;InstallDir]";
690
 
                cmSystemTools::ExpandRegistryValues(mp);
691
 
                if (mp != "/registry")
692
 
                    generator = wxT("Visual Studio 7");
693
 
                else
694
 
                    generator = wxT("Visual Studio 6");         
695
 
            }
696
 
        }
697
 
    }
698
 
 
699
 
    // set proper discovered generator
700
 
    m_cmGeneratorChoice->SetStringSelection(generator);
701
 
    
702
 
    wxString str;
703
 
    str.Printf("CMake %d.%d - %s", cmVersion::GetMajorVersion(),
704
 
               cmVersion::GetMinorVersion(), 
705
 
               cmVersion::GetReleaseVersion().c_str());
706
 
    str.Printf("CMakeSetup v%i.%i%s", CMAKEGUI_MAJORVER, CMAKEGUI_MINORVER, CMAKEGUI_ADDVER);
707
 
 
708
 
    SetTitle(str);
709
 
    wxString path;
710
 
    
711
 
    // get last 5 used projects
712
 
    for(size_t i = 0; i < CM_MAX_RECENT_PATHS; i++)
713
 
    {
714
 
        path.Printf("%s%i", _(CM_RECENT_BUILD_PATH), i);
715
 
        if(m_config->Read(path, &str))
716
 
            AppendPathToRecentList(str);
717
 
    }
718
 
 
719
 
    // get query items
720
 
    for(size_t i = 0; i < CM_MAX_SEARCH_QUERIES; i++)
721
 
    {
722
 
        path.Printf("%s%i", _(CM_SEARCH_QUERY), i);
723
 
        if(m_config->Read(path, &str))
724
 
            m_cmSearchQuery->Append(str);
725
 
    }
726
 
 
727
 
 
728
 
    // make sure the call to update grid is not executed
729
 
    m_noRefresh = true;
730
 
    m_cmSearchQuery->SetValue(_(""));
731
 
    m_noRefresh = false;
732
 
 
733
 
    // Get the parameters from the command line info
734
 
    // If an unknown parameter is found, try to interpret it too, since it
735
 
    // is likely to be a file dropped on the shortcut :)
736
 
    bool sourceDirLoaded = false,
737
 
         buildDirLoaded = false;
738
 
    
739
 
    if(cm.m_LastUnknownParameter.empty())
740
 
    {
741
 
        if(cm.m_WhereSource.size() > 0 )
742
 
        {
743
 
            m_cmProjectPath->SetValue(cm.m_WhereSource.c_str());
744
 
            sourceDirLoaded = true;
745
 
        }   
746
 
    
747
 
        if (cm.m_WhereBuild.size() > 0 )
748
 
        {
749
 
            m_cmBuildPath->SetValue(cm.m_WhereBuild.c_str());
750
 
            buildDirLoaded = true;
751
 
        }
752
 
            
753
 
        m_cmShowAdvanced->SetValue(cm.m_AdvancedValues);
754
 
    }
755
 
    else
756
 
    {
757
 
        m_cmShowAdvanced->SetValue(false);
758
 
        
759
 
        // TODO: Interpret directory from dropped shortcut
760
 
        //this->ChangeDirectoriesFromFile(cmdInfo->m_LastUnknownParameter.c_str());
761
 
    }
762
 
 
763
 
    if (cm.m_ExitAfterLoad)
764
 
    {
765
 
        int id = GetId();
766
 
        m_ExitTimer = new wxTimer(this, id);
767
 
        m_ExitTimer->Start(3000);
768
 
 
769
 
        Connect( id, wxEVT_TIMER,(wxObjectEventFunction) &CMakeSetupFrm::OnExitTimer ); 
770
 
 
771
 
    } 
772
 
 
773
 
    // retrieve settings, this needs to be done here
774
 
    // because writing to the m_cmBuildPath triggers a cache reload
775
 
    if(!sourceDirLoaded && m_config->Read(CM_LASTPROJECT_PATH, &str))
776
 
        m_cmProjectPath->SetValue(str);
777
 
 
778
 
    if(!buildDirLoaded)
779
 
    {
780
 
        m_cmOptions->RemoveAll();
781
 
        if(m_config->Read(CM_LASTBUILD_PATH, &str))
782
 
            m_cmBuildPath->SetValue(str);
783
 
    }
784
 
 
785
 
    // set window size from settings
786
 
    long xsize, ysize, splitpos;
787
 
    if(m_config->Read(CM_XSIZE, &xsize) && m_config->Read(CM_YSIZE, &ysize) &&
788
 
       m_config->Read(CM_SPLITTERPOS, &splitpos))
789
 
    {
790
 
        SetSize(xsize, ysize);
791
 
        m_splitter->SetSashPosition(splitpos);
792
 
    }
793
 
 
794
 
    if(m_config->Read(CM_XPOS, &xsize) && m_config->Read(CM_YPOS, &ysize))
795
 
        SetSize(xsize, ysize, -1, -1, wxSIZE_USE_EXISTING);
796
 
 
797
 
    UpdateWindowState();
798
 
}
799
 
 
800
 
void CMakeSetupFrm::LoadCacheFromDiskToGUI()
801
 
{
802
 
    wxString builddir = m_cmBuildPath->GetValue();  
803
 
    
804
 
    cmCacheManager *cachem = m_cmake->GetCacheManager();
805
 
    if(cachem && !builddir.Trim().IsEmpty())
806
 
    {
807
 
        if(cachem->LoadCache(builddir.c_str()))
808
 
            AppendPathToRecentList(builddir);
809
 
 
810
 
        // represent this cache in the grid, but not before we
811
 
        // wiped all of the old items
812
 
        FillCacheGUIFromCacheManager();
813
 
    
814
 
        // set the generator string to the one used in the cache
815
 
        cmCacheManager::CacheIterator it = cachem->GetCacheIterator("CMAKE_GENERATOR");
816
 
        if(!it.IsAtEnd())
817
 
        {
818
 
            wxString curGen = it.GetValue();
819
 
            m_cmGeneratorChoice->SetStringSelection(curGen);
820
 
        }
821
 
    }
822
 
}
823
 
 
824
 
void CMakeSetupFrm::AppendPathToRecentList(const wxString &p)
825
 
{
826
 
    wxFileName path;
827
 
    wxString str;
828
 
 
829
 
    if(p.IsEmpty())
830
 
        return;
831
 
    
832
 
    // cheap way to get rid of trailing seperators
833
 
    path.AssignDir(p);
834
 
    str = path.GetPath();
835
 
 
836
 
    // append the item, or add it to end to make sure
837
 
    // it is remembered between sessions
838
 
    for(size_t i = 0; i < m_recentPaths.Count(); i++)
839
 
    {
840
 
        if(m_recentPaths[i].IsSameAs(str, false))
841
 
        {
842
 
            m_recentPaths.RemoveAt(i);
843
 
            
844
 
            // only re-add when item is still valid
845
 
            if(::wxDirExists(str))
846
 
                m_recentPaths.Add(str);
847
 
            else
848
 
                return;  // no add when the item is not existing
849
 
 
850
 
            return;
851
 
        }
852
 
    }
853
 
 
854
 
    if(GetMenuBar())
855
 
    {
856
 
        // get file menu
857
 
        int lastUsedID = 0;
858
 
        wxMenu *mnu = GetMenuBar()->GetMenu(0);
859
 
        wxASSERT(mnu != 0);
860
 
        
861
 
        if(::wxDirExists(str))
862
 
        {
863
 
            // add to array
864
 
            if(m_recentPaths.Count() == 0)
865
 
                mnu->AppendSeparator();
866
 
 
867
 
            lastUsedID = CM_RECENT_BUILD_ITEM + m_recentPaths.Count();
868
 
            m_recentPaths.Add(str);
869
 
 
870
 
            // when we have more in list then we can display, prune and 
871
 
            // remove some menu items until we have room (and available ID's again)
872
 
            if(m_recentPaths.Count() > CM_MAX_RECENT_PATHS)
873
 
            {
874
 
                // prune the list
875
 
                while(m_recentPaths.Count() > CM_MAX_RECENT_PATHS)
876
 
                    m_recentPaths.RemoveAt(0);  
877
 
 
878
 
                // now determine count, and remove until we have room
879
 
                int index = mnu->GetMenuItemCount() - 1;
880
 
                int count = 0;
881
 
                wxASSERT(index > 0);
882
 
                
883
 
                wxMenuItem *item;
884
 
                do
885
 
                {
886
 
                    item = mnu->FindItemByPosition(index);
887
 
                    if(item)
888
 
                    {
889
 
                        if(item->IsSeparator())
890
 
                        {
891
 
                            // next index is valid item
892
 
                            index ++;
893
 
                            break;
894
 
                        }
895
 
                        else
896
 
                            count ++;
897
 
                    }
898
 
 
899
 
                    index --;
900
 
                }
901
 
                while(index >= 0 && item);
902
 
 
903
 
                // ok, if count > CM_MAX_RECENT_PATHS then we are going to
904
 
                // delete some items on the index position
905
 
                if(count >= CM_MAX_RECENT_PATHS)
906
 
                {
907
 
                    // delete items that are exceeding
908
 
                    while(count >= CM_MAX_RECENT_PATHS)
909
 
                    {
910
 
                        lastUsedID = mnu->FindItemByPosition(index)->GetId();
911
 
                        mnu->Delete(lastUsedID);
912
 
                        count --;
913
 
                    }
914
 
                }
915
 
            }
916
 
 
917
 
            // append item
918
 
            mnu->Append(lastUsedID, str);
919
 
        }
920
 
    }
921
 
}
922
 
 
923
 
bool CMakeSetupFrm::PerformCacheRun()
924
 
{
925
 
    bool enable = false;
926
 
    cmCacheManager *cachem = m_cmake->GetCacheManager();
927
 
    cmCacheManager::CacheIterator it = cachem->NewIterator();
928
 
 
929
 
    // remove all items that are no longer present
930
 
    size_t j = 0;
931
 
    while(j < m_cmOptions->GetCount())
932
 
    {
933
 
        // check to see if it is still in the CMake cache
934
 
        // if it is still in the cache then it is no longer new
935
 
        wxPropertyItem *item = m_cmOptions->GetItem(j);
936
 
        if ( !it.Find((const char*)item->GetPropName().c_str()) )
937
 
            m_cmOptions->RemoveProperty(item);
938
 
        else
939
 
        {
940
 
            // ok we found it, mark as old
941
 
            item->SetNewValue(false);
942
 
            int row = m_cmOptions->FindProperty(item);
943
 
            if(row != -1) 
944
 
                m_cmOptions->UpdatePropertyItem(item, row);
945
 
            j++;
946
 
        }
947
 
    }
948
 
 
949
 
    if(cachem->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag())
950
 
    {
951
 
        bool enable = true;     
952
 
        for(size_t i = 0; i < m_cmOptions->GetCount(); i++)
953
 
        {
954
 
            wxPropertyItem* item = m_cmOptions->GetItem(i);
955
 
            if(item->GetAdvanced())
956
 
            {
957
 
                if(item->GetNewValue() && m_cmOptions->GetShowAdvanced())
958
 
                {
959
 
                    // if one new value then disable to OK button
960
 
                    enable = false;
961
 
                    break;
962
 
                }
963
 
            }
964
 
            else
965
 
            {
966
 
                if(item->GetNewValue())
967
 
                {
968
 
                    // if one new value then disable to OK button
969
 
                    enable = false;
970
 
                    break;
971
 
                }
972
 
            }
973
 
        }
974
 
    }
975
 
 
976
 
    return enable;  
977
 
}
978
 
 
979
 
void CMakeSetupFrm::FillCacheGUIFromCacheManager()
980
 
{
981
 
    cmCacheManager *cachem = m_cmake->GetCacheManager();
982
 
    cmCacheManager::CacheIterator it = cachem->NewIterator();
983
 
  
984
 
    // remove all items that are no longer present
985
 
    size_t j = 0;
986
 
    while(j < m_cmOptions->GetCount())
987
 
    {
988
 
        // check to see if it is still in the CMake cache
989
 
        // if it is still in the cache then it is no longer new
990
 
        wxPropertyItem *item = m_cmOptions->GetItem(j);
991
 
        if ( !it.Find((const char*)item->GetPropName().c_str()) )
992
 
            m_cmOptions->RemoveProperty(item);
993
 
        else
994
 
            j++;
995
 
    }
996
 
 
997
 
    // if there are already entries in the cache, then
998
 
    // put the new ones in the top, so they show up first
999
 
    bool reverseOrder = false;
1000
 
    for(cmCacheManager::CacheIterator i = cachem->NewIterator(); !i.IsAtEnd(); i.Next())
1001
 
    {
1002
 
        const char* key = i.GetName();
1003
 
 
1004
 
        // if value has trailing space or tab, enclose it in single quotes
1005
 
        // to enforce the fact that it has 'invisible' trailing stuff
1006
 
        std::string value = i.GetValue();
1007
 
        if (value.size() && (value[value.size() - 1] == ' ' ||  value[value.size() - 1] == '\t'))
1008
 
            value = '\'' + value +  '\'';
1009
 
 
1010
 
        bool advanced = i.GetPropertyAsBool("ADVANCED");
1011
 
        switch(i.GetType() )
1012
 
        {
1013
 
        case cmCacheManager::BOOL:
1014
 
            {
1015
 
                wxString OnOff;
1016
 
                
1017
 
                if(cmSystemTools::IsOn(value.c_str()))
1018
 
                    OnOff = wxT("ON");
1019
 
                else
1020
 
                    OnOff = wxT("OFF");
1021
 
 
1022
 
                m_cmOptions->AddProperty(key,
1023
 
                                         OnOff.c_str(),
1024
 
                                         i.GetProperty("HELPSTRING"),
1025
 
                                         wxPropertyList::CHECKBOX, "ON|OFF",
1026
 
                                         reverseOrder,
1027
 
                                         advanced );
1028
 
            }
1029
 
            break;
1030
 
 
1031
 
        case cmCacheManager::PATH:
1032
 
            m_cmOptions->AddProperty(key, 
1033
 
                                     value.c_str(),
1034
 
                                     i.GetProperty("HELPSTRING"),
1035
 
                                     wxPropertyList::PATH,"",
1036
 
                                     reverseOrder, advanced);
1037
 
            break;
1038
 
        
1039
 
        case cmCacheManager::FILEPATH:
1040
 
            m_cmOptions->AddProperty(key, 
1041
 
                                     value.c_str(),
1042
 
                                     i.GetProperty("HELPSTRING"),
1043
 
                                     wxPropertyList::FILE,"",
1044
 
                                     reverseOrder, advanced);
1045
 
            break;
1046
 
      
1047
 
        case cmCacheManager::STRING:
1048
 
            m_cmOptions->AddProperty(key,
1049
 
                                     value.c_str(),
1050
 
                                     i.GetProperty("HELPSTRING"),
1051
 
                                     wxPropertyList::EDIT,"",
1052
 
                                     reverseOrder, advanced);
1053
 
            break;
1054
 
      
1055
 
        case cmCacheManager::INTERNAL:
1056
 
            {
1057
 
                wxPropertyItem *pItem = m_cmOptions->FindPropertyByName(key);
1058
 
                if(pItem)
1059
 
                    m_cmOptions->RemoveProperty(pItem);
1060
 
            }
1061
 
            break;          
1062
 
        }
1063
 
    }
1064
 
}
1065
 
 
1066
 
void CMakeSetupFrm::OnExitTimer(wxTimerEvent &event)
1067
 
{
1068
 
    Close();
1069
 
1070
 
 
1071
 
/*!
1072
 
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSE_PROJECT
1073
 
 */
1074
 
 
1075
 
void CMakeSetupFrm::OnButtonBrowseProject( wxCommandEvent& event )
1076
 
{
1077
 
    const wxString& dir = wxDirSelector("Select project directory", m_cmProjectPath->GetValue());
1078
 
    if(!dir.IsEmpty())
1079
 
        m_cmProjectPath->SetValue(dir);
1080
 
}
1081
 
 
1082
 
/*!
1083
 
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSE_BUILD
1084
 
 */
1085
 
 
1086
 
void CMakeSetupFrm::OnButtonBrowseBuild( wxCommandEvent& event )
1087
 
{
1088
 
    const wxString& dir = wxDirSelector("Select build directory", m_cmBuildPath->GetValue());
1089
 
    if(!dir.IsEmpty())
1090
 
        m_cmBuildPath->SetValue(dir);
1091
 
}
1092
 
 
1093
 
/*!
1094
 
 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_SHOW_ADVANCED
1095
 
 */
1096
 
 
1097
 
void CMakeSetupFrm::OnShowAdvancedValues( wxCommandEvent& event )
1098
 
{
1099
 
    if(m_cmShowAdvanced->GetValue())
1100
 
        m_cmOptions->ShowAdvanced();
1101
 
    else
1102
 
        m_cmOptions->HideAdvanced();
1103
 
}
1104
 
 
1105
 
/*!
1106
 
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_CONFIGURE
1107
 
 */
1108
 
 
1109
 
void CMakeSetupFrm::OnButtonConfigure( wxCommandEvent& event )
1110
 
{
1111
 
    DoConfigure();
1112
 
}
1113
 
 
1114
 
void CMakeSetupFrm::DoConfigure()
1115
 
{
1116
 
    // enable error messages each time configure is pressed
1117
 
    cmSystemTools::EnableMessages();
1118
 
    m_cmOptions->HideControls();
1119
 
 
1120
 
    cmSystemTools::ResetErrorOccuredFlag(); 
1121
 
    
1122
 
    // instantiate a dialog for the progress meter
1123
 
 
1124
 
    PerformCacheRun();
1125
 
    RunCMake(false);
1126
 
}
1127
 
 
1128
 
int CMakeSetupFrm::RunCMake(bool generateProjectFiles)
1129
 
{
1130
 
    int value = -1;
1131
 
    
1132
 
    // clear log
1133
 
    m_cmLog->Clear();
1134
 
    m_cmLog->DiscardEdits();
1135
 
 
1136
 
    wxString builddir = m_cmBuildPath->GetValue(), 
1137
 
             sourcedir = m_cmProjectPath->GetValue(),
1138
 
             err = wxT("Error in configuration process, project files may be invalid");
1139
 
 
1140
 
 
1141
 
    // sanity check for people pressing OK on empty dirs
1142
 
    if(builddir.Trim().IsEmpty() || sourcedir.Trim().IsEmpty())
1143
 
    {
1144
 
        wxMessageBox(wxT("Please enter a valid source directory and build directory"), wxT("Error"), wxOK | wxICON_ERROR, this);
1145
 
        return -1;
1146
 
    }
1147
 
 
1148
 
    // check if the directory exists, if not, create it
1149
 
    if(!cmSystemTools::FileExists(builddir.c_str()))
1150
 
    {
1151
 
        wxString str;
1152
 
        str << wxT("Build directory does not exist, should I create it?\n\nDirectory: ") << builddir;
1153
 
    
1154
 
        int answer = wxMessageBox(str, wxT("Create directory"), wxYES_NO, this);
1155
 
        if (answer == wxYES)
1156
 
        {
1157
 
            if(!cmSystemTools::MakeDirectory(builddir.c_str()))
1158
 
            {
1159
 
                // could not create, tell and abort
1160
 
                wxMessageBox(wxT("Could not create directory"), wxT("Error"), wxOK | wxICON_ERROR, this);
1161
 
                return -1;
1162
 
            }
1163
 
        }
1164
 
        else
1165
 
        {
1166
 
            // we abort because the user did not want to make the directory
1167
 
            wxMessageBox(wxT("Build Project aborted, nothing done."), wxT("Aborted"), 
1168
 
                         wxOK | wxICON_EXCLAMATION, this);
1169
 
            return -1;
1170
 
        }
1171
 
    }
1172
 
 
1173
 
    /** show progress dialog that informs the user with a progress bar */ 
1174
 
    if(m_progressDlg)
1175
 
        m_progressDlg->Destroy();
1176
 
 
1177
 
    m_progressDlg = new CMProgressDialog(this);
1178
 
    m_progressDlg->Show();
1179
 
 
1180
 
    // set the wait cursor
1181
 
    m_RunningConfigure = true;
1182
 
    UpdateWindowState();
1183
 
 
1184
 
    // always save the current gui values to disk
1185
 
    SaveCacheFromGUI();
1186
 
  
1187
 
    // Make sure we are working from the cache on disk
1188
 
    LoadCacheFromDiskToGUI(); 
1189
 
 
1190
 
    // setup the cmake instance
1191
 
    if (generateProjectFiles)
1192
 
    {
1193
 
        if(m_cmake->Generate() != 0)
1194
 
        {
1195
 
            wxMessageBox(err, wxT("Error"), wxOK | wxICON_ERROR, this);
1196
 
            cmSystemTools::Error(err.c_str());
1197
 
            value = -1;
1198
 
        }
1199
 
        else
1200
 
        {
1201
 
            value = 0;
1202
 
            m_cmOptions->SetProjectGenerated(true); // clear cache dirty when generated
1203
 
        }
1204
 
    }
1205
 
    else
1206
 
    {
1207
 
        // set paths 
1208
 
        m_cmake->SetHomeDirectory(m_cmProjectPath->GetValue().c_str());
1209
 
        m_cmake->SetStartDirectory(m_cmProjectPath->GetValue().c_str());
1210
 
        m_cmake->SetHomeOutputDirectory(m_cmBuildPath->GetValue().c_str());
1211
 
        m_cmake->SetStartOutputDirectory(m_cmBuildPath->GetValue().c_str());
1212
 
        
1213
 
        m_cmake->SetGlobalGenerator(m_cmake->CreateGlobalGenerator(m_cmGeneratorChoice->GetValue().c_str()));
1214
 
        m_cmake->SetCMakeCommand(m_PathToExecutable.c_str());
1215
 
        m_cmake->LoadCache();
1216
 
        if(m_cmake->Configure() != 0)
1217
 
        {
1218
 
            wxMessageBox(err, wxT("Error"), wxOK | wxICON_ERROR, this);
1219
 
            cmSystemTools::Error(err.c_str());
1220
 
        }
1221
 
        
1222
 
        // update the GUI with any new values in the caused by the
1223
 
        // generation process
1224
 
        LoadCacheFromDiskToGUI();
1225
 
    }
1226
 
 
1227
 
    m_RunningConfigure = false;
1228
 
    
1229
 
    if(!value)
1230
 
        cmSystemTools::ResetErrorOccuredFlag();
1231
 
 
1232
 
    m_progressDlg->Destroy();
1233
 
    m_progressDlg = 0;
1234
 
 
1235
 
    // reset the statusbar progress 
1236
 
    wxStatusBar *bar = GetStatusBar();
1237
 
    if(bar)
1238
 
        bar->SetStatusText(wxEmptyString, 1);
1239
 
 
1240
 
    UpdateWindowState();
1241
 
    return value;
1242
 
}
1243
 
 
1244
 
//! Save GUI values to cmCacheManager and then save to disk.
1245
 
void CMakeSetupFrm::SaveCacheFromGUI()
1246
 
{
1247
 
    cmCacheManager *cachem = m_cmake->GetCacheManager();
1248
 
    FillCacheManagerFromCacheGUI();
1249
 
  
1250
 
    // write the cache to disk
1251
 
    if(!m_cmBuildPath->GetValue().Trim().IsEmpty())
1252
 
        cachem->SaveCache(m_cmBuildPath->GetValue().c_str());
1253
 
}
1254
 
 
1255
 
void CMakeSetupFrm::FillCacheManagerFromCacheGUI()
1256
 
1257
 
    cmCacheManager *cachem = m_cmake->GetCacheManager();
1258
 
    
1259
 
    cmCacheManager::CacheIterator it = cachem->NewIterator();
1260
 
    for(size_t i = 0; i < m_cmOptions->GetCount(); i++)
1261
 
    {
1262
 
        wxPropertyItem* item = m_cmOptions->GetItem(i); 
1263
 
        if ( it.Find((const char*)item->GetPropName().c_str()) )
1264
 
        {
1265
 
            // if value is enclosed in single quotes ('foo') then remove them
1266
 
            // they were used to enforce the fact that it had 'invisible' 
1267
 
            // trailing stuff
1268
 
            if (item->GetCurValue().Len() >= 2 &&
1269
 
                item->GetCurValue().GetChar(0) == '\'' && 
1270
 
                item->GetCurValue().GetChar(item->GetCurValue().Len() - 1) == '\'') 
1271
 
            {
1272
 
                it.SetValue(item->GetCurValue().Mid(1, item->GetCurValue().Len() - 2).c_str());
1273
 
            }
1274
 
            else
1275
 
                it.SetValue(item->GetCurValue().c_str());
1276
 
        }
1277
 
    }
1278
 
}
1279
 
 
1280
 
 
1281
 
/*!
1282
 
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_OK
1283
 
 */
1284
 
 
1285
 
void CMakeSetupFrm::OnButtonOk( wxCommandEvent& event )
1286
 
{
1287
 
    DoGenerate();
1288
 
}
1289
 
 
1290
 
void CMakeSetupFrm::DoGenerate()
1291
 
{
1292
 
    cmSystemTools::EnableMessages();
1293
 
    
1294
 
    cmSystemTools::ResetErrorOccuredFlag(); 
1295
 
    
1296
 
    m_cmOptions->HideControls();
1297
 
    PerformCacheRun();
1298
 
  
1299
 
    if(!RunCMake(true))
1300
 
    {
1301
 
        // issue a close when this is done (this is issued by menu "Generate and Exit"
1302
 
        if(m_quitAfterGenerating)
1303
 
            Close();
1304
 
        else if(!wxGetKeyState(WXK_SHIFT))
1305
 
        {
1306
 
            bool close;
1307
 
            m_config->Read(CM_CLOSEAFTERGEN, &close, CM_CLOSEAFTERGEN_DEF);
1308
 
            
1309
 
            if(!close)
1310
 
                wxMessageBox(wxT("Building of project files succesful!"), wxT("Success!"), wxOK|wxICON_INFORMATION);
1311
 
            else
1312
 
                Close();
1313
 
        }
1314
 
    }
1315
 
}
1316
 
 
1317
 
/*!
1318
 
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_CANCEL
1319
 
 */
1320
 
 
1321
 
void CMakeSetupFrm::OnButtonCancel( wxCommandEvent& event )
1322
 
{
1323
 
    DoCancelButton();
1324
 
}
1325
 
 
1326
 
void CMakeSetupFrm::DoCancelButton()
1327
 
{
1328
 
    if(m_RunningConfigure)
1329
 
    {
1330
 
        int result = wxMessageBox(wxT("You are in the middle of a Configure.\n"
1331
 
                                      "If you Cancel now the configure information will be lost.\n"
1332
 
                                      "Are you sure you want to Cancel?"), wxT("Warning"), wxYES_NO|wxICON_WARNING);
1333
 
        if(result == wxYES)
1334
 
            cmSystemTools::SetFatalErrorOccured();
1335
 
        else
1336
 
            if(m_progressDlg)
1337
 
                m_progressDlg->ResetCancel();
1338
 
    }
1339
 
}
1340
 
 
1341
 
/*!
1342
 
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_DELETE_CACHE
1343
 
 */
1344
 
 
1345
 
void CMakeSetupFrm::OnButtonDeleteCache( wxCommandEvent& event )
1346
 
{
1347
 
    DoDeleteCache();
1348
 
}
1349
 
 
1350
 
void CMakeSetupFrm::DoDeleteCache()
1351
 
{
1352
 
    bool deletecache = true;
1353
 
    if(m_cmOptions->IsCacheDirty() || (m_cmOptions->GetCount() > 0 && !m_cmOptions->IsGenerated()))
1354
 
    {
1355
 
        int result = ::wxMessageBox(_("You have changed options, are you sure you want to delete all items?\n"), 
1356
 
                                    _("Warning"), wxYES_NO|wxICON_QUESTION);
1357
 
        
1358
 
        // when user wants to wait, wait.. else quit
1359
 
        if(result == wxNO)
1360
 
            deletecache = false;
1361
 
            
1362
 
    }
1363
 
 
1364
 
    if(deletecache)
1365
 
    {
1366
 
        // indicate that we haven't generated a project yet
1367
 
        m_cmOptions->SetProjectGenerated(false);
1368
 
        
1369
 
        if(!m_cmBuildPath->GetValue().Trim().IsEmpty() && m_cmake != 0)
1370
 
            m_cmake->GetCacheManager()->DeleteCache(m_cmBuildPath->GetValue().Trim());
1371
 
      
1372
 
        LoadCacheFromDiskToGUI();   
1373
 
        UpdateWindowState();
1374
 
    }
1375
 
}
1376
 
 
1377
 
/*!
1378
 
 * Should we show tooltips?
1379
 
 */
1380
 
 
1381
 
bool CMakeSetupFrm::ShowToolTips()
1382
 
{
1383
 
    return TRUE;
1384
 
}
1385
 
 
1386
 
/*!
1387
 
 * Get bitmap resources
1388
 
 */
1389
 
 
1390
 
wxBitmap CMakeSetupFrm::GetBitmapResource( const wxString& name )
1391
 
{
1392
 
    // Bitmap retrieval
1393
 
////@begin CMakeSetupFrm bitmap retrieval
1394
 
    return wxNullBitmap;
1395
 
////@end CMakeSetupFrm bitmap retrieval
1396
 
}
1397
 
 
1398
 
/*!
1399
 
 * Get icon resources
1400
 
 */
1401
 
 
1402
 
wxIcon CMakeSetupFrm::GetIconResource( const wxString& name )
1403
 
{
1404
 
    // Icon retrieval
1405
 
////@begin CMakeSetupFrm icon retrieval
1406
 
    if (name == wxT("cmake_icon.xpm"))
1407
 
    {
1408
 
        wxIcon icon(_T("cmake_icon.xpm"), wxBITMAP_TYPE_XPM);
1409
 
        return icon;
1410
 
    }
1411
 
    return wxNullIcon;
1412
 
////@end CMakeSetupFrm icon retrieval
1413
 
}
1414
 
 
1415
 
/*!
1416
 
 * wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING event handler for ID_SPLITTERWINDOW
1417
 
 */
1418
 
 
1419
 
void CMakeSetupFrm::OnSplitterPosChanging( wxSplitterEvent& event )
1420
 
{
1421
 
    int width, height;
1422
 
 
1423
 
    GetSize(&width, &height);
1424
 
 
1425
 
    if((height > 100))
1426
 
    {
1427
 
        if(event.GetSashPosition() < 170)
1428
 
            event.SetSashPosition(170);
1429
 
        else
1430
 
        {
1431
 
            if(event.GetSashPosition() > (height - 180))
1432
 
                event.SetSashPosition(height - 180);
1433
 
        }
1434
 
    }
1435
 
    else
1436
 
        event.Veto();
1437
 
 
1438
 
}
1439
 
 
1440
 
 
1441
 
/*!
1442
 
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CLEAR_LOG
1443
 
 */
1444
 
 
1445
 
void CMakeSetupFrm::OnClearLogClick( wxCommandEvent& event )
1446
 
{
1447
 
    // delete the log text
1448
 
    m_cmLog->Clear();
1449
 
    m_cmLog->DiscardEdits();
1450
 
}
1451
 
 
1452
 
 
1453
 
/*!
1454
 
 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_SOURCE_BUILD_PATH
1455
 
 */
1456
 
 
1457
 
void CMakeSetupFrm::OnSourceBuildPathUpdated( wxCommandEvent& event )
1458
 
{
1459
 
    DoReloadCache();
1460
 
}
1461
 
 
1462
 
void CMakeSetupFrm::DoReloadCache()
1463
 
{
1464
 
    wxString buildpath = m_cmBuildPath->GetValue();
1465
 
    // The build dir has changed, check if there is a cache, and 
1466
 
    // grab the source dir from it
1467
 
 
1468
 
    // make sure the call to update grid is not executed
1469
 
    m_noRefresh = true;
1470
 
    m_cmSearchQuery->SetValue(_(""));
1471
 
    m_noRefresh = false;
1472
 
 
1473
 
    std::string path = buildpath.c_str();
1474
 
    cmSystemTools::ConvertToUnixSlashes(path);
1475
 
 
1476
 
    // adjust the cmake instance
1477
 
    m_cmake->SetHomeOutputDirectory(buildpath.c_str());
1478
 
    m_cmake->SetStartOutputDirectory(buildpath.c_str());
1479
 
 
1480
 
    std::string cache_file = path;
1481
 
    cache_file += "/CMakeCache.txt";
1482
 
 
1483
 
    // fill in the project path where the source is located, this is 
1484
 
    // read from the CMake cache
1485
 
    cmCacheManager *cachem = m_cmake->GetCacheManager();
1486
 
    cmCacheManager::CacheIterator it = cachem->NewIterator();
1487
 
    if (cmSystemTools::FileExists(cache_file.c_str()) && cachem->LoadCache(path.c_str()) && 
1488
 
        it.Find("CMAKE_HOME_DIRECTORY"))
1489
 
    {
1490
 
        path = ConvertToWindowsPath(it.GetValue());
1491
 
        m_cmProjectPath->SetValue(path.c_str());
1492
 
    }
1493
 
 
1494
 
    m_cmOptions->RemoveAll();
1495
 
    LoadCacheFromDiskToGUI();
1496
 
    UpdateWindowState();
1497
 
}
1498
 
 
1499
 
 
1500
 
/*!
1501
 
 * wxEVT_COMMAND_TEXT_ENTER event handler for ID_SOURCE_BUILD_PATH
1502
 
 */
1503
 
 
1504
 
void CMakeSetupFrm::OnSourceBuildPathEnter( wxCommandEvent& event )
1505
 
{
1506
 
    OnSourceBuildPathUpdated(event);
1507
 
}
1508
 
 
1509
 
/*!
1510
 
 * wxEVT_MOTION event handler for ID_OPTIONS
1511
 
 */
1512
 
 
1513
 
void CMakeSetupFrm::OnPropertyMotion( wxMouseEvent& event )
1514
 
{
1515
 
    ShowPropertyDescription(m_cmOptions->YToRow(event.GetY()));
1516
 
    event.Skip();
1517
 
}
1518
 
 
1519
 
 
1520
 
/*!
1521
 
 * wxEVT_GRID_SELECT_CELL event handler for ID_OPTIONS
1522
 
 */
1523
 
 
1524
 
void CMakeSetupFrm::OnGridSelectCell( wxGridEvent& event )
1525
 
{
1526
 
    // show description 
1527
 
    ShowPropertyDescription(event.GetRow());
1528
 
    
1529
 
    // enable or disable the browse button
1530
 
    m_cmBrowseCell->Enable(m_cmOptions->IsSelectedItemBrowsable(event.GetRow()));
1531
 
    event.Skip();
1532
 
}
1533
 
 
1534
 
void CMakeSetupFrm::ShowPropertyDescription(int row)
1535
 
{
1536
 
    if(row == wxNOT_FOUND || row < 0)
1537
 
        m_cmDescription->SetValue(wxEmptyString);
1538
 
    else
1539
 
    {
1540
 
        wxPropertyItem *pItem = m_cmOptions->GetPropertyItemFromRow(row);
1541
 
        if(pItem)
1542
 
            m_cmDescription->SetValue(pItem->GetHelpString());
1543
 
        else
1544
 
            m_cmDescription->SetValue(wxEmptyString);
1545
 
    }
1546
 
}
1547
 
 
1548
 
/*!
1549
 
 * wxEVT_GRID_CELL_CHANGE event handler for ID_OPTIONS
1550
 
 */
1551
 
 
1552
 
void CMakeSetupFrm::OnCellChange( wxGridEvent& event )
1553
 
{
1554
 
    // update the button state when the cache is invalidated
1555
 
    UpdateWindowState();
1556
 
}
1557
 
 
1558
 
void CMakeSetupFrm::OnRecentFileMenu( wxCommandEvent &event )
1559
 
{   
1560
 
    if(GetMenuBar())
1561
 
    {
1562
 
        // get file menu
1563
 
        wxMenu *mnu = GetMenuBar()->GetMenu(0);
1564
 
        wxASSERT(mnu != 0);
1565
 
 
1566
 
        wxMenuItem *item = mnu->FindItem(event.GetId());
1567
 
        if(item)
1568
 
            m_cmBuildPath->SetValue(item->GetLabel());
1569
 
    }
1570
 
}
1571
 
/*!
1572
 
 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_COMBOBOX
1573
 
 */
1574
 
 
1575
 
void CMakeSetupFrm::OnSearchquerySelected( wxCommandEvent& event )
1576
 
{
1577
 
    m_cmOptions->SetQuery(m_cmSearchQuery->GetValue());
1578
 
}
1579
 
 
1580
 
void CMakeSetupFrm::OnAddQuery ( wxCommandEvent &event )
1581
 
{
1582
 
    // add current text if not yet present
1583
 
    if(m_cmSearchQuery->FindString(m_cmSearchQuery->GetValue()) == wxNOT_FOUND)
1584
 
    {
1585
 
        m_cmSearchQuery->Append(m_cmSearchQuery->GetValue());
1586
 
        
1587
 
        // if too many items are present, prune
1588
 
        while(m_cmSearchQuery->GetCount() > CM_MAX_SEARCH_QUERIES)
1589
 
            m_cmSearchQuery->Delete(0);     
1590
 
    }
1591
 
}
1592
 
 
1593
 
/*!
1594
 
 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_SEARCHQUERY
1595
 
 */
1596
 
 
1597
 
void CMakeSetupFrm::OnSearchqueryUpdated( wxCommandEvent& event )
1598
 
{
1599
 
    // only refresh when this event was caused by user
1600
 
    if(!m_noRefresh)
1601
 
        m_cmOptions->SetQuery(m_cmSearchQuery->GetValue());
1602
 
}
1603
 
 
1604
 
 
1605
 
/*!
1606
 
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSE_GRID
1607
 
 */
1608
 
 
1609
 
void CMakeSetupFrm::OnBrowseGridClick( wxCommandEvent& event )
1610
 
{
1611
 
    m_cmOptions->BrowseSelectedItem();
1612
 
}
1613
 
 
1614
 
 
1615
 
/*!
1616
 
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_RELOAD_CACHE
1617
 
 */
1618
 
 
1619
 
void CMakeSetupFrm::OnMenuReloadCacheClick( wxCommandEvent& event )
1620
 
{
1621
 
    bool reload = true;
1622
 
    if(m_cmOptions->IsCacheDirty() || (m_cmOptions->GetCount() > 0 && !m_cmOptions->IsGenerated()))
1623
 
    {
1624
 
        int result = ::wxMessageBox(_("You have changed options, are you sure you want to reload?\n"), 
1625
 
                                    _("Warning"), wxYES_NO|wxICON_QUESTION);
1626
 
        
1627
 
        // when user wants to wait, wait.. else quit
1628
 
        if(result == wxNO)
1629
 
            reload = false;
1630
 
            
1631
 
    }
1632
 
 
1633
 
    if(reload) 
1634
 
        DoReloadCache();
1635
 
}
1636
 
 
1637
 
/*!
1638
 
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_DELETE_CACHE
1639
 
 */
1640
 
 
1641
 
void CMakeSetupFrm::OnMenuDeleteCacheClick( wxCommandEvent& event )
1642
 
{
1643
 
    DoDeleteCache();
1644
 
}
1645
 
 
1646
 
 
1647
 
/*!
1648
 
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_QUIT
1649
 
 */
1650
 
 
1651
 
void CMakeSetupFrm::OnMenuQuitClick( wxCommandEvent& event )
1652
 
{
1653
 
    // the close event will veto if the user 
1654
 
    // did not want to quit due to unsaved changes
1655
 
    Close();
1656
 
}
1657
 
 
1658
 
 
1659
 
/*!
1660
 
 * wxEVT_CLOSE_WINDOW event handler for ID_FRAME
1661
 
 */
1662
 
 
1663
 
void CMakeSetupFrm::OnCloseWindow( wxCloseEvent& event )
1664
 
{
1665
 
    // ask quit if:
1666
 
    //  - The cache is dirty
1667
 
    //  - Or the cache is OK and has some items, and no project was generated recently (configure -> generate)
1668
 
    if(m_cmOptions->IsCacheDirty() || (m_cmOptions->GetCount() > 0 && !m_cmOptions->IsGenerated()))
1669
 
    {
1670
 
        int result = ::wxMessageBox(_("You have changed options, but not yet generated the projects\n"
1671
 
                                      "are you sure you want to quit?"), _("Warning"), wxYES_NO|wxICON_QUESTION);
1672
 
        
1673
 
        // when user wants to wait, wait.. else quit
1674
 
        if(result == wxNO)
1675
 
            event.Veto();
1676
 
        else
1677
 
            event.Skip();
1678
 
    }
1679
 
    else
1680
 
        event.Skip();
1681
 
}
1682
 
 
1683
 
 
1684
 
/*!
1685
 
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_ABOUTDLG
1686
 
 */
1687
 
 
1688
 
void CMakeSetupFrm::OnAboutClick( wxCommandEvent& event )
1689
 
{
1690
 
    CMAboutDlg *dlg = new CMAboutDlg(this);
1691
 
    
1692
 
    wxArrayString generators;
1693
 
    std::vector<std::string> names; 
1694
 
    m_cmake->GetRegisteredGenerators(names);
1695
 
    for(std::vector<std::string>::iterator i = names.begin(); i != names.end(); ++i)
1696
 
        generators.Add(i->c_str());
1697
 
 
1698
 
    wxString cmversion, cmsversion;
1699
 
//    cmversion.Printf("v%i.%i %s", cmake::GetMajorVersion(), cmake::GetMinorVersion(), cmake::GetReleaseVersion());
1700
 
    cmsversion.Printf("v%i.%i%s", CMAKEGUI_MAJORVER, CMAKEGUI_MINORVER, CMAKEGUI_ADDVER);
1701
 
 
1702
 
    dlg->SetAboutText(cmversion, cmsversion, generators);
1703
 
 
1704
 
    dlg->ShowModal();
1705
 
    dlg->Destroy();
1706
 
}
1707
 
 
1708
 
 
1709
 
/*!
1710
 
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_CMAKE_OPTIONS
1711
 
 */
1712
 
 
1713
 
void CMakeSetupFrm::OnOptionsClick( wxCommandEvent& event )
1714
 
{
1715
 
    CMOptionsDlg *dlg = new CMOptionsDlg(this);
1716
 
 
1717
 
    dlg->SetConfig(m_config);
1718
 
    if(dlg->ShowModal() == wxID_OK)
1719
 
    {
1720
 
        // store volatile settings
1721
 
        dlg->GetConfig(m_config);
1722
 
        
1723
 
        // apply non volatile setting such as clear search query, recent menu, etc.
1724
 
        SyncFormOptions(dlg);
1725
 
    }
1726
 
 
1727
 
    dlg->Destroy();
1728
 
}
1729
 
 
1730
 
void CMakeSetupFrm::SyncFormOptions(CMOptionsDlg *dlg)
1731
 
{
1732
 
    // TODO: Clear search query etc.
1733
 
}
1734
 
/*!
1735
 
 * wxEVT_COMMAND_SPLITTER_DOUBLECLICKED event handler for ID_SPLITTERWINDOW
1736
 
 */
1737
 
 
1738
 
void CMakeSetupFrm::OnSplitterwindowSashDClick( wxSplitterEvent& event )
1739
 
{
1740
 
    event.Veto(); 
1741
 
}
1742
 
 
1743
 
 
1744
 
/*!
1745
 
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_CONFIGURE
1746
 
 */
1747
 
 
1748
 
void CMakeSetupFrm::OnMenuConfigureClick( wxCommandEvent& event )
1749
 
{
1750
 
    DoConfigure();
1751
 
}
1752
 
 
1753
 
/*!
1754
 
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_EXITGENERATE
1755
 
 */
1756
 
 
1757
 
void CMakeSetupFrm::OnMenuGenerateClick( wxCommandEvent& event )
1758
 
{
1759
 
    // set flag so that a close command is issued
1760
 
    // after generating the cmake cache to projects
1761
 
    m_quitAfterGenerating = true;
1762
 
    DoGenerate();
1763
 
    m_quitAfterGenerating = false;
1764
 
}
1765
 
 
1766
 
 
1767
 
/*!
1768
 
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_TOGGLE_ADVANCED
1769
 
 */
1770
 
 
1771
 
void CMakeSetupFrm::OnMenuToggleAdvancedClick( wxCommandEvent& event )
1772
 
{
1773
 
    // toggle the check box
1774
 
    m_cmShowAdvanced->SetValue(!m_cmShowAdvanced->GetValue());
1775
 
    OnShowAdvancedValues(event);
1776
 
}
1777
 
 
1778