1 /*=========================================================================
3 Program: WXDialog - wxWidgets X-platform GUI Front-End for CMake
4 Module: $RCSfile: CMakeSetupFrame.cpp,v $
6 <<<<<<< CMakeSetupFrame.cpp
7 Date: $Date: 2007/11/05 19:47:20 $
8 Version: $Revision: 1.3 $
10 Date: $Date: 2009-03-05 20:17:07 $
11 Version: $Revision: 1.4 $
16 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
17 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
19 This software is distributed WITHOUT ANY WARRANTY; without even
20 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21 PURPOSE. See the above copyright notices for more information.
23 =========================================================================*/
25 #if defined(__GNUG__) && !defined(__APPLE__)
26 #pragma implementation "CMakeSetupFrame.h"
29 // For compilers that support precompilation, includes "wx/wx.h".
30 #include "wx/wxprec.h"
43 #include <wx/dirdlg.h>
44 #include <wx/msgdlg.h>
45 #include <wx/filename.h>
47 #include "CMakeSetupFrame.h"
48 #include "PropertyList.h"
49 #include "app_resources.h"
50 #include "CMakeIcon.xpm"
54 #include "../cmVersion.h"
55 #include "../cmListFileCache.h"
56 #include "../cmCacheManager.h"
57 #include "../cmGlobalGenerator.h"
58 #include "../cmDynamicLoader.h"
64 * CMakeSetupFrm type definition
67 IMPLEMENT_CLASS( CMakeSetupFrm
, wxFrame
)
70 * CMakeSetupFrm event table definition
73 BEGIN_EVENT_TABLE( CMakeSetupFrm
, wxFrame
)
75 ////@begin CMakeSetupFrm event table entries
76 EVT_CLOSE( CMakeSetupFrm::OnCloseWindow
)
78 EVT_SPLITTER_SASH_POS_CHANGING( ID_SPLITTERWINDOW
, CMakeSetupFrm::OnSplitterPosChanging
)
79 EVT_SPLITTER_DCLICK( ID_SPLITTERWINDOW
, CMakeSetupFrm::OnSplitterwindowSashDClick
)
81 EVT_BUTTON( ID_BROWSE_PROJECT
, CMakeSetupFrm::OnButtonBrowseProject
)
83 EVT_TEXT( ID_SOURCE_BUILD_PATH
, CMakeSetupFrm::OnSourceBuildPathUpdated
)
84 EVT_TEXT_ENTER( ID_SOURCE_BUILD_PATH
, CMakeSetupFrm::OnSourceBuildPathEnter
)
86 EVT_BUTTON( ID_BROWSE_BUILD
, CMakeSetupFrm::OnButtonBrowseBuild
)
88 EVT_COMBOBOX( ID_SEARCHQUERY
, CMakeSetupFrm::OnSearchquerySelected
)
89 EVT_TEXT( ID_SEARCHQUERY
, CMakeSetupFrm::OnSearchqueryUpdated
)
91 EVT_CHECKBOX( ID_SHOW_ADVANCED
, CMakeSetupFrm::OnShowAdvancedValues
)
93 EVT_GRID_CELL_CHANGE( CMakeSetupFrm::OnCellChange
)
94 EVT_GRID_SELECT_CELL( CMakeSetupFrm::OnGridSelectCell
)
95 EVT_MOTION( CMakeSetupFrm::OnPropertyMotion
)
97 EVT_BUTTON( ID_DO_CONFIGURE
, CMakeSetupFrm::OnButtonConfigure
)
99 EVT_BUTTON( ID_DO_OK
, CMakeSetupFrm::OnButtonOk
)
101 EVT_BUTTON( ID_DO_CANCEL
, CMakeSetupFrm::OnButtonCancel
)
103 EVT_BUTTON( ID_DO_DELETE_CACHE
, CMakeSetupFrm::OnButtonDeleteCache
)
105 EVT_BUTTON( ID_CLEAR_LOG
, CMakeSetupFrm::OnClearLogClick
)
107 EVT_BUTTON( ID_BROWSE_GRID
, CMakeSetupFrm::OnBrowseGridClick
)
109 EVT_MENU( ID_MENU_RELOAD_CACHE
, CMakeSetupFrm::OnMenuReloadCacheClick
)
111 EVT_MENU( ID_MENU_DELETE_CACHE
, CMakeSetupFrm::OnMenuDeleteCacheClick
)
113 EVT_MENU( ID_MENU_QUIT
, CMakeSetupFrm::OnMenuQuitClick
)
115 EVT_MENU( ID_MENU_CONFIGURE
, CMakeSetupFrm::OnMenuConfigureClick
)
117 EVT_MENU( ID_MENU_EXITGENERATE
, CMakeSetupFrm::OnMenuGenerateClick
)
119 EVT_MENU( ID_MENU_TOGGLE_ADVANCED
, CMakeSetupFrm::OnMenuToggleAdvancedClick
)
121 EVT_MENU( ID_CMAKE_OPTIONS
, CMakeSetupFrm::OnOptionsClick
)
123 EVT_MENU( ID_ABOUTDLG
, CMakeSetupFrm::OnAboutClick
)
125 ////@end CMakeSetupFrm event table entries
127 EVT_MENU_RANGE(CM_RECENT_BUILD_ITEM
, CM_RECENT_BUILD_ITEM
+ CM_MAX_RECENT_PATHS
, CMakeSetupFrm::OnRecentFileMenu
)
129 EVT_TEXT_ENTER(ID_SEARCHQUERY
, CMakeSetupFrm::OnAddQuery
)
133 /** Callback function for CMake generator, to tell user how
134 far the generation actually is */
135 void updateProgress(const char *msg
, float prog
, void *cd
)
137 // TODO: Make some kind of progress counter
139 CMakeSetupFrm
*fm
= (CMakeSetupFrm
*)cd
;
144 fm
->LogMessage(0, msg
);
147 fm
->UpdateProgress(prog
);
153 /** Callback function for CMake generator, to tell user about stuff. This should be
154 logged in the m_log window */
155 void MFCMessageCallback(const char* m
, const char* title
, bool& nomore
, void *clientdata
)
157 CMakeSetupFrm
*fm
= (CMakeSetupFrm
*)clientdata
;
161 wxString what
= m
, msg
;
162 if(what
.StartsWith("CMake Error: "))
163 fm
->LogMessage(-1, m
);
165 fm
->LogMessage(1, m
);
169 // Convert to Win32 path (slashes). This calls the system tools one and then
170 // removes the spaces. It is not in system tools because we don't want any
171 // generators accidentally use it
172 std::string
ConvertToWindowsPath(const char* path
)
174 // Convert to output path.
175 // Remove the "" around it (if any) since it's an output path for
176 // the shell. If another shell-oriented feature is not designed
177 // for a GUI use, then we are in trouble.
178 // save the value of the force to unix path option
179 bool saveForce
= cmSystemTools::GetForceUnixPaths();
180 // make sure we get windows paths no matter what for the GUI
181 cmSystemTools::SetForceUnixPaths(false);
182 std::string s
= cmSystemTools::ConvertToOutputPath(path
);
183 // now restore the force unix path to its previous value
184 cmSystemTools::SetForceUnixPaths(saveForce
);
187 std::string::iterator i
= s
.begin();
192 i
= s
.begin() + s
.length() - 1;
202 bool DnDFile::OnDropFiles(wxCoord
, wxCoord
, const wxArrayString
& filenames
)
204 size_t nFiles
= filenames
.GetCount();
206 // only one item allowed
212 // only one dir allowed
213 if(!wxDirExists(filenames
[0]))
216 // strip the seperator
218 name
.AssignDir(filenames
[0]);
220 // issue a 'drop' by changing text ctrl
221 m_pOwner
->SetValue(name
.GetFullPath());
230 * CMakeSetupFrm constructors
233 CMakeSetupFrm::CMakeSetupFrm( )
238 CMakeSetupFrm::CMakeSetupFrm( wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
241 Create( parent
, id
, caption
, pos
, size
, style
);
245 * CMakeSetupFrm creator
248 bool CMakeSetupFrm::Create( wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
250 ////@begin CMakeSetupFrm member initialisation
252 m_cmProjectPath
= NULL
;
253 m_BrowseProjectPathButton
= NULL
;
254 m_cmBuildPath
= NULL
;
255 m_BrowseSourcePathButton
= NULL
;
256 m_cmGeneratorChoice
= NULL
;
257 m_cmSearchQuery
= NULL
;
258 m_cmShowAdvanced
= NULL
;
261 m_cmDescription
= NULL
;
262 m_ConfigureButton
= NULL
;
264 m_CancelButton
= NULL
;
265 m_DeleteCacheButton
= NULL
;
266 m_ClearLogButton
= NULL
;
267 m_cmBrowseCell
= NULL
;
268 ////@end CMakeSetupFrm member initialisation
270 wxFrame::Create( parent
, id
, caption
, pos
, size
, style
);
272 // make sure the developer does not assign more then 100
273 // would be rediculous but also overlap other id's
274 wxASSERT(CM_MAX_RECENT_PATHS
< 100);
280 m_quitAfterGenerating
= false;
282 m_config
= new wxConfig("CMakeSetup");
284 wxIcon
icon(CMakeIcon_xpm
);
289 //SetIcon(GetIconResource(wxT("cmake_icon.xpm")));
290 //SetIcon(wxIcon("NGDialog.ico", wxBITMAP_TYPE_ICO_RESOURCE));
293 // is it needed to hide console?
294 m_RunningConfigure
= false;
295 cmSystemTools::SetRunCommandHideConsole(true);
296 cmSystemTools::SetErrorCallback(MFCMessageCallback
, (void *)this);
298 // create our cmake instance
300 m_cmake
->SetProgressCallback(updateProgress
, (void *)this);
305 CMakeSetupFrm::~CMakeSetupFrm()
309 // write configs back to disk
310 m_config
->Write(CM_LASTPROJECT_PATH
, m_cmProjectPath
->GetValue());
311 m_config
->Write(CM_LASTBUILD_PATH
, m_cmBuildPath
->GetValue());
313 // clear the config first
314 for(size_t i
= 0 ; i
< CM_MAX_RECENT_PATHS
; i
++)
316 str
.Printf("%s%i", _(CM_RECENT_BUILD_PATH
), i
);
317 m_config
->Write(str
, _(""));
320 // write the last CM_MAX_RECENT_PATHS items back to config
321 int i
= (m_recentPaths
.Count() >= CM_MAX_RECENT_PATHS
? CM_MAX_RECENT_PATHS
: m_recentPaths
.Count());
324 str
.Printf("%s%i", _(CM_RECENT_BUILD_PATH
), i
);
325 m_config
->Write(str
, m_recentPaths
[i
- 1]);
329 // write recent query list to config
330 for(int j
= 0; j
< m_cmSearchQuery
->GetCount(); j
++)
332 // allow max to be written
333 if(j
< CM_MAX_SEARCH_QUERIES
)
335 str
.Printf("%s%i", _(CM_SEARCH_QUERY
), j
);
336 m_config
->Write(str
, m_cmSearchQuery
->GetString(j
));
342 // set window pos + size in settings
343 if(!IsIconized() && !IsMaximized())
346 GetSize(&xsize
, &ysize
);
347 if(xsize
> 0 && ysize
> 0)
349 m_config
->Write(CM_XSIZE
, (long)xsize
);
350 m_config
->Write(CM_YSIZE
, (long)ysize
);
353 if(m_splitter
->GetSashPosition() > 0)
354 m_config
->Write(CM_SPLITTERPOS
, (long)m_splitter
->GetSashPosition());
356 GetPosition(&xsize
, &ysize
);
357 if(xsize
!= 0 && ysize
!= 0)
359 m_config
->Write(CM_XPOS
, (long)xsize
);
360 m_config
->Write(CM_YPOS
, (long)ysize
);
364 // write changes (will be done before deletion)
371 // delete our cmake instance again
376 void CMakeSetupFrm::UpdateWindowState()
378 bool dogenerate
= !m_RunningConfigure
&& !m_cmOptions
->IsCacheDirty() &&
379 (m_cmOptions
->GetCount() != 0);
381 // when configure is running, disable a lot of stuff
382 m_cmProjectPath
->Enable(!m_RunningConfigure
);
383 m_BrowseProjectPathButton
->Enable(!m_RunningConfigure
);
384 m_cmBuildPath
->Enable(!m_RunningConfigure
);
385 m_BrowseSourcePathButton
->Enable(!m_RunningConfigure
);
386 m_cmGeneratorChoice
->Enable(!m_RunningConfigure
);
387 m_cmShowAdvanced
->Enable(!m_RunningConfigure
);
388 m_cmOptions
->Enable(!m_RunningConfigure
);
389 m_ConfigureButton
->Enable(!m_RunningConfigure
);
390 m_OkButton
->Enable(dogenerate
);
391 m_CancelButton
->Enable(m_RunningConfigure
);
392 m_DeleteCacheButton
->Enable(!m_RunningConfigure
);
393 m_ClearLogButton
->Enable(!m_RunningConfigure
);
394 if(m_RunningConfigure
)
395 m_cmBrowseCell
->Enable(false);
397 // when cache loaded (items available show other control)
398 m_cmGeneratorChoice
->Enable(m_cmOptions
->GetCount() == 0 && !m_RunningConfigure
);
399 m_cmSearchQuery
->Enable(!m_RunningConfigure
);
400 m_cmBrowseCell
->Enable(!m_RunningConfigure
&& m_cmOptions
->IsSelectedItemBrowsable());
402 // disable the menus when configuring
405 // disable configure button when there is nothing, and generate and exit
406 // only when it is allowed to generate
407 GetMenuBar()->Enable(ID_MENU_EXITGENERATE
, dogenerate
);
408 GetMenuBar()->Enable(ID_MENU_CONFIGURE
, !m_RunningConfigure
);
410 for(size_t i
= 0; i
< GetMenuBar()->GetMenuCount(); i
++)
411 GetMenuBar()->EnableTop(i
, !m_RunningConfigure
);
415 void CMakeSetupFrm::LogMessage(int logkind
, const char *msg
)
417 // put CR first but prevent a CR at the end
419 if(m_cmLog
->IsModified())
420 (*m_cmLog
) << wxT("\n");
422 // Linux requires a different approach
423 if(!m_cmLog
->GetValue().IsEmpty())
424 (*m_cmLog
) << wxT("\n");
427 // log error, warning, or message
428 wxTextAttr defattr
= m_cmLog
->GetDefaultStyle();
435 wxTextAttr
colattr(*wxBLUE
);
436 m_cmLog
->SetDefaultStyle(colattr
);
438 m_cmLog
->SetDefaultStyle(defattr
);
450 wxTextAttr
colattr(*wxRED
);
451 m_cmLog
->SetDefaultStyle(colattr
);
453 m_cmLog
->SetDefaultStyle(defattr
);
461 void CMakeSetupFrm::IssueUpdate()
463 //::wxSafeYield(m_CancelButton, true);
466 // when we pressed cancel on the progress dialog
467 // stop all activities
470 if(m_progressDlg
->CancelPressed() && !m_progressDlg
->IsCancelling())
472 m_progressDlg
->CancelAcknowledged();
474 // send a button event to cancel the progress
475 wxCommandEvent
event( wxEVT_COMMAND_BUTTON_CLICKED
, ID_DO_CANCEL
);
476 wxPostEvent(this, event
);
482 * Control creation for CMakeSetupFrm
485 void CMakeSetupFrm::CreateControls()
487 ////@begin CMakeSetupFrm content construction
488 CMakeSetupFrm
* itemFrame1
= this;
490 wxMenuBar
* menuBar
= new wxMenuBar
;
491 wxMenu
* itemMenu37
= new wxMenu
;
492 itemMenu37
->Append(ID_MENU_RELOAD_CACHE
, _("&Reload Cache\tCtrl+R"), _("Reload the cache from disk"), wxITEM_NORMAL
);
493 itemMenu37
->Append(ID_MENU_DELETE_CACHE
, _("&Delete Cache\tCtrl+D"), _("Delete the cache on disk of the current path"), wxITEM_NORMAL
);
494 itemMenu37
->AppendSeparator();
495 itemMenu37
->Append(ID_MENU_QUIT
, _("E&xit\tAlt+F4"), _("Quit CMake Setup"), wxITEM_NORMAL
);
496 menuBar
->Append(itemMenu37
, _("&File"));
497 wxMenu
* itemMenu42
= new wxMenu
;
498 itemMenu42
->Append(ID_MENU_CONFIGURE
, _("&Configure\tCtrl+N"), _T(""), wxITEM_NORMAL
);
499 itemMenu42
->Append(ID_MENU_EXITGENERATE
, _("&Generate and Exit\tCtrl+G"), _T(""), wxITEM_NORMAL
);
500 itemMenu42
->Append(ID_MENU_TOGGLE_ADVANCED
, _("Toggle &Advanced\tCtrl+A"), _T(""), wxITEM_NORMAL
);
501 itemMenu42
->AppendSeparator();
502 itemMenu42
->Append(ID_CMAKE_OPTIONS
, _("&Options\tCtrl+O"), _T(""), wxITEM_NORMAL
);
503 menuBar
->Append(itemMenu42
, _("&Tools"));
504 wxMenu
* itemMenu48
= new wxMenu
;
505 itemMenu48
->Append(ID_ABOUTDLG
, _("&About ..."), _("Shows the about dialog ..."), wxITEM_NORMAL
);
506 menuBar
->Append(itemMenu48
, _("&Help"));
507 itemFrame1
->SetMenuBar(menuBar
);
509 m_splitter
= new wxSplitterWindow( itemFrame1
, ID_SPLITTERWINDOW
, wxDefaultPosition
, wxSize(100, 100), wxSP_3DBORDER
|wxSP_3DSASH
|wxNO_BORDER
);
511 wxPanel
* itemPanel3
= new wxPanel( m_splitter
, ID_MAINPANEL
, wxDefaultPosition
, wxSize(600, 400), wxNO_BORDER
|wxTAB_TRAVERSAL
);
512 itemPanel3
->SetExtraStyle(itemPanel3
->GetExtraStyle()|wxWS_EX_VALIDATE_RECURSIVELY
);
513 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxVERTICAL
);
514 itemPanel3
->SetSizer(itemBoxSizer4
);
516 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxHORIZONTAL
);
517 itemBoxSizer4
->Add(itemBoxSizer5
, 0, wxGROW
|wxTOP
|wxBOTTOM
, 5);
518 wxFlexGridSizer
* itemFlexGridSizer6
= new wxFlexGridSizer(2, 3, 0, 0);
519 itemFlexGridSizer6
->AddGrowableRow(1);
520 itemFlexGridSizer6
->AddGrowableCol(1);
521 itemBoxSizer5
->Add(itemFlexGridSizer6
, 1, wxALIGN_TOP
|wxLEFT
, 5);
522 wxStaticText
* itemStaticText7
= new wxStaticText( itemPanel3
, wxID_STATIC
, _("CMake project path"), wxDefaultPosition
, wxDefaultSize
, 0 );
523 itemFlexGridSizer6
->Add(itemStaticText7
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxRIGHT
|wxADJUST_MINSIZE
, 5);
525 m_cmProjectPath
= new wxTextCtrl( itemPanel3
, ID_PROJECT_PATH
, _T(""), wxDefaultPosition
, wxSize(50, -1), 0 );
526 itemFlexGridSizer6
->Add(m_cmProjectPath
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
, 5);
528 m_BrowseProjectPathButton
= new wxButton( itemPanel3
, ID_BROWSE_PROJECT
, _("Browse"), wxDefaultPosition
, wxSize(55, -1), 0 );
529 itemFlexGridSizer6
->Add(m_BrowseProjectPathButton
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
531 wxStaticText
* itemStaticText10
= new wxStaticText( itemPanel3
, wxID_STATIC
, _("Project build path"), wxDefaultPosition
, wxDefaultSize
, 0 );
532 itemFlexGridSizer6
->Add(itemStaticText10
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxRIGHT
|wxADJUST_MINSIZE
, 5);
534 m_cmBuildPath
= new wxTextCtrl( itemPanel3
, ID_SOURCE_BUILD_PATH
, _T(""), wxDefaultPosition
, wxSize(50, -1), 0 );
535 itemFlexGridSizer6
->Add(m_cmBuildPath
, 1, wxGROW
|wxALIGN_TOP
|wxTOP
|wxBOTTOM
, 5);
537 m_BrowseSourcePathButton
= new wxButton( itemPanel3
, ID_BROWSE_BUILD
, _("Browse"), wxDefaultPosition
, wxSize(55, -1), 0 );
538 itemFlexGridSizer6
->Add(m_BrowseSourcePathButton
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
540 wxBoxSizer
* itemBoxSizer13
= new wxBoxSizer(wxVERTICAL
);
541 itemBoxSizer5
->Add(itemBoxSizer13
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
542 wxFlexGridSizer
* itemFlexGridSizer14
= new wxFlexGridSizer(2, 2, 0, 0);
543 itemBoxSizer13
->Add(itemFlexGridSizer14
, 0, wxALIGN_CENTER_HORIZONTAL
|wxLEFT
|wxRIGHT
, 5);
544 wxStaticText
* itemStaticText15
= new wxStaticText( itemPanel3
, wxID_STATIC
, _("Generate"), wxDefaultPosition
, wxDefaultSize
, 0 );
545 itemFlexGridSizer14
->Add(itemStaticText15
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxADJUST_MINSIZE
, 5);
547 wxString
* m_cmGeneratorChoiceStrings
= NULL
;
548 m_cmGeneratorChoice
= new wxComboBox( itemPanel3
, ID_CHOOSE_GENERATOR
, _T(""), wxDefaultPosition
, wxSize(170, -1), 0, m_cmGeneratorChoiceStrings
, wxCB_READONLY
);
549 itemFlexGridSizer14
->Add(m_cmGeneratorChoice
, 1, wxALIGN_CENTER_HORIZONTAL
|wxGROW
|wxTOP
|wxBOTTOM
, 5);
551 wxStaticText
* itemStaticText17
= new wxStaticText( itemPanel3
, wxID_STATIC
, _("Search"), wxDefaultPosition
, wxDefaultSize
, 0 );
552 itemFlexGridSizer14
->Add(itemStaticText17
, 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxADJUST_MINSIZE
, 5);
554 wxString
* m_cmSearchQueryStrings
= NULL
;
555 m_cmSearchQuery
= new wxComboBox( itemPanel3
, ID_SEARCHQUERY
, _T(""), wxDefaultPosition
, wxSize(170, -1), 0, m_cmSearchQueryStrings
, wxWANTS_CHARS
);
556 itemFlexGridSizer14
->Add(m_cmSearchQuery
, 1, wxALIGN_CENTER_HORIZONTAL
|wxGROW
|wxTOP
|wxBOTTOM
, 5);
558 m_cmShowAdvanced
= new wxCheckBox( itemPanel3
, ID_SHOW_ADVANCED
, _("Show advanced values"), wxDefaultPosition
, wxDefaultSize
, wxCHK_2STATE
);
559 m_cmShowAdvanced
->SetValue(FALSE
);
560 itemBoxSizer13
->Add(m_cmShowAdvanced
, 0, wxALIGN_RIGHT
|wxLEFT
|wxRIGHT
, 5);
562 m_cmOptions
= new wxPropertyList( itemPanel3
, ID_OPTIONS
, wxDefaultPosition
, wxSize(200, 150), wxSTATIC_BORDER
|wxWANTS_CHARS
|wxVSCROLL
);
563 m_cmOptions
->SetDefaultColSize(250);
564 m_cmOptions
->SetDefaultRowSize(25);
565 m_cmOptions
->SetColLabelSize(20);
566 m_cmOptions
->SetRowLabelSize(0);
567 m_cmOptions
->CreateGrid(10, 2, wxGrid::wxGridSelectRows
);
568 itemBoxSizer4
->Add(m_cmOptions
, 1, wxGROW
|wxALL
, 5);
570 wxPanel
* itemPanel21
= new wxPanel( m_splitter
, ID_LOGPANEL
, wxDefaultPosition
, wxSize(-1, 100), wxNO_BORDER
|wxTAB_TRAVERSAL
);
571 wxBoxSizer
* itemBoxSizer22
= new wxBoxSizer(wxVERTICAL
);
572 itemPanel21
->SetSizer(itemBoxSizer22
);
574 wxBoxSizer
* itemBoxSizer23
= new wxBoxSizer(wxHORIZONTAL
);
575 itemBoxSizer22
->Add(itemBoxSizer23
, 1, wxGROW
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
576 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
);
577 itemBoxSizer23
->Add(m_cmLog
, 1, wxGROW
|wxRIGHT
, 5);
579 m_cmDescription
= new wxTextCtrl( itemPanel21
, ID_DESCRIPTION
, _T(""), wxDefaultPosition
, wxSize(200, -1), wxTE_MULTILINE
|wxTE_READONLY
|wxTE_RICH2
|wxSTATIC_BORDER
);
580 itemBoxSizer23
->Add(m_cmDescription
, 0, wxGROW
|wxLEFT
, 5);
582 wxBoxSizer
* itemBoxSizer26
= new wxBoxSizer(wxHORIZONTAL
);
583 itemBoxSizer22
->Add(itemBoxSizer26
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
584 m_ConfigureButton
= new wxButton( itemPanel21
, ID_DO_CONFIGURE
, _("Co&nfigure"), wxDefaultPosition
, wxDefaultSize
, 0 );
585 m_ConfigureButton
->SetDefault();
586 itemBoxSizer26
->Add(m_ConfigureButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
588 m_OkButton
= new wxButton( itemPanel21
, ID_DO_OK
, _("&Generate!"), wxDefaultPosition
, wxDefaultSize
, 0 );
589 itemBoxSizer26
->Add(m_OkButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
591 m_CancelButton
= new wxButton( itemPanel21
, ID_DO_CANCEL
, _("C&ancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
592 itemBoxSizer26
->Add(m_CancelButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
594 #if defined(__WXMSW__)
595 wxStaticLine
* itemStaticLine30
= new wxStaticLine( itemPanel21
, wxID_STATIC
, wxDefaultPosition
, wxDefaultSize
, wxLI_HORIZONTAL
);
596 itemBoxSizer26
->Add(itemStaticLine30
, 0, wxGROW
|wxALL
, 5);
599 m_DeleteCacheButton
= new wxButton( itemPanel21
, ID_DO_DELETE_CACHE
, _("&Delete Cache"), wxDefaultPosition
, wxDefaultSize
, 0 );
600 itemBoxSizer26
->Add(m_DeleteCacheButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
602 m_ClearLogButton
= new wxButton( itemPanel21
, ID_CLEAR_LOG
, _("Clear &Log"), wxDefaultPosition
, wxDefaultSize
, 0 );
603 itemBoxSizer26
->Add(m_ClearLogButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
605 #if defined(__WXMSW__)
606 wxStaticLine
* itemStaticLine33
= new wxStaticLine( itemPanel21
, wxID_STATIC
, wxDefaultPosition
, wxDefaultSize
, wxLI_HORIZONTAL
);
607 itemBoxSizer26
->Add(itemStaticLine33
, 0, wxGROW
|wxALL
, 5);
610 m_cmBrowseCell
= new wxButton( itemPanel21
, ID_BROWSE_GRID
, _("&Browse"), wxDefaultPosition
, wxDefaultSize
, 0 );
611 itemBoxSizer26
->Add(m_cmBrowseCell
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
613 m_splitter
->SplitHorizontally(itemPanel3
, itemPanel21
, 300);
615 wxStatusBar
* itemStatusBar35
= new wxStatusBar( itemFrame1
, ID_STATUSBAR
, wxST_SIZEGRIP
|wxNO_BORDER
);
616 itemStatusBar35
->SetFieldsCount(2);
617 itemFrame1
->SetStatusBar(itemStatusBar35
);
619 ////@end CMakeSetupFrm content construction
622 void CMakeSetupFrm::DoInitFrame(cmCommandLineInfo
&cm
, const wxString
&fn
)
624 // path to where cmake.exe is
625 // m_PathToExecutable = cm.GetPathToExecutable().c_str();
626 m_PathToExecutable
= fn
;
628 // adjust size of last bar, to display % progress
629 wxStatusBar
*bar
= GetStatusBar();
632 wxASSERT(bar
->GetFieldsCount() > 1);
634 // fill all with -1. Why this way? because the count of the status bars
635 // can change. All of the widths must be accounted for and initialised
636 int *widths
= new int[bar
->GetFieldsCount()];
637 for(int i
= 0; i
< bar
->GetFieldsCount(); i
++)
642 bar
->SetStatusWidths(bar
->GetFieldsCount(), widths
);
646 wxString name
, generator
;
647 std::vector
<std::string
> names
;
649 m_RunningConfigure
= false;
652 m_cmOptions
->SetColLabelValue(0, wxT("Cache Name"));
653 m_cmOptions
->SetColLabelValue(1, wxT("Cache Value"));
654 m_cmOptions
->SetProjectGenerated(false);
657 m_cmOptions
->SetDropTarget(new DnDFile(m_cmBuildPath
));
659 m_cmake
->GetRegisteredGenerators(names
);
660 for(std::vector
<std::string
>::iterator i
= names
.begin(); i
!= names
.end(); ++i
)
663 m_cmGeneratorChoice
->Append(name
);
666 // sync advanced option with grid
667 m_cmOptions
->SetShowAdvanced(m_cmShowAdvanced
->GetValue());
669 // if we have a command line query that a generator
670 // needs to be chosen instead of the default, take it
671 bool foundGivenGenerator
= false;
672 if(!cm
.m_GeneratorChoiceString
.IsEmpty())
674 // set proper discovered generator
675 foundGivenGenerator
= m_cmGeneratorChoice
->SetStringSelection(cm
.m_GeneratorChoiceString
);
678 // if none selected, we will see if VS8, VS7 or VS6 is present
679 if(!foundGivenGenerator
|| m_cmGeneratorChoice
->GetValue().IsEmpty())
682 mp
= "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\Setup;Dbghelp_path]";
683 cmSystemTools::ExpandRegistryValues(mp
);
684 if(mp
!= "/registry")
685 generator
= wxT("Visual Studio 8 2005");
688 mp
= "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.1;InstallDir]";
689 cmSystemTools::ExpandRegistryValues(mp
);
690 if (mp
!= "/registry")
691 generator
= wxT("Visual Studio 7 .NET 2003");
694 mp
= "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.0;InstallDir]";
695 cmSystemTools::ExpandRegistryValues(mp
);
696 if (mp
!= "/registry")
697 generator
= wxT("Visual Studio 7");
699 generator
= wxT("Visual Studio 6");
704 // set proper discovered generator
705 m_cmGeneratorChoice
->SetStringSelection(generator
);
708 str
.Printf("CMake %s", cmVersion::GetCMakeVersion());
709 str
.Printf("CMakeSetup v%i.%i%s", CMAKEGUI_MAJORVER
, CMAKEGUI_MINORVER
, CMAKEGUI_ADDVER
);
714 // get last 5 used projects
715 for(size_t i
= 0; i
< CM_MAX_RECENT_PATHS
; i
++)
717 path
.Printf("%s%i", _(CM_RECENT_BUILD_PATH
), i
);
718 if(m_config
->Read(path
, &str
))
719 AppendPathToRecentList(str
);
723 for(size_t i
= 0; i
< CM_MAX_SEARCH_QUERIES
; i
++)
725 path
.Printf("%s%i", _(CM_SEARCH_QUERY
), i
);
726 if(m_config
->Read(path
, &str
))
727 m_cmSearchQuery
->Append(str
);
731 // make sure the call to update grid is not executed
733 m_cmSearchQuery
->SetValue(_(""));
736 // Get the parameters from the command line info
737 // If an unknown parameter is found, try to interpret it too, since it
738 // is likely to be a file dropped on the shortcut :)
739 bool sourceDirLoaded
= false,
740 buildDirLoaded
= false;
742 if(cm
.m_LastUnknownParameter
.empty())
744 if(cm
.m_WhereSource
.size() > 0 )
746 m_cmProjectPath
->SetValue(cm
.m_WhereSource
.c_str());
747 sourceDirLoaded
= true;
750 if (cm
.m_WhereBuild
.size() > 0 )
752 m_cmBuildPath
->SetValue(cm
.m_WhereBuild
.c_str());
753 buildDirLoaded
= true;
756 m_cmShowAdvanced
->SetValue(cm
.m_AdvancedValues
);
760 m_cmShowAdvanced
->SetValue(false);
762 // TODO: Interpret directory from dropped shortcut
763 //this->ChangeDirectoriesFromFile(cmdInfo->m_LastUnknownParameter.c_str());
766 if (cm
.m_ExitAfterLoad
)
769 m_ExitTimer
= new wxTimer(this, id
);
770 m_ExitTimer
->Start(3000);
772 Connect( id
, wxEVT_TIMER
,(wxObjectEventFunction
) &CMakeSetupFrm::OnExitTimer
);
776 // retrieve settings, this needs to be done here
777 // because writing to the m_cmBuildPath triggers a cache reload
778 if(!sourceDirLoaded
&& m_config
->Read(CM_LASTPROJECT_PATH
, &str
))
779 m_cmProjectPath
->SetValue(str
);
783 m_cmOptions
->RemoveAll();
784 if(m_config
->Read(CM_LASTBUILD_PATH
, &str
))
785 m_cmBuildPath
->SetValue(str
);
788 // set window size from settings
789 long xsize
, ysize
, splitpos
;
790 if(m_config
->Read(CM_XSIZE
, &xsize
) && m_config
->Read(CM_YSIZE
, &ysize
) &&
791 m_config
->Read(CM_SPLITTERPOS
, &splitpos
))
793 SetSize(xsize
, ysize
);
794 m_splitter
->SetSashPosition(splitpos
);
797 if(m_config
->Read(CM_XPOS
, &xsize
) && m_config
->Read(CM_YPOS
, &ysize
))
798 SetSize(xsize
, ysize
, -1, -1, wxSIZE_USE_EXISTING
);
803 void CMakeSetupFrm::LoadCacheFromDiskToGUI()
805 wxString builddir
= m_cmBuildPath
->GetValue();
807 cmCacheManager
*cachem
= m_cmake
->GetCacheManager();
808 if(cachem
&& !builddir
.Trim().IsEmpty())
810 if(cachem
->LoadCache(builddir
.c_str()))
811 AppendPathToRecentList(builddir
);
813 // represent this cache in the grid, but not before we
814 // wiped all of the old items
815 FillCacheGUIFromCacheManager();
817 // set the generator string to the one used in the cache
818 cmCacheManager::CacheIterator it
= cachem
->GetCacheIterator("CMAKE_GENERATOR");
821 wxString curGen
= it
.GetValue();
822 m_cmGeneratorChoice
->SetStringSelection(curGen
);
827 void CMakeSetupFrm::AppendPathToRecentList(const wxString
&p
)
835 // cheap way to get rid of trailing seperators
837 str
= path
.GetPath();
839 // append the item, or add it to end to make sure
840 // it is remembered between sessions
841 for(size_t i
= 0; i
< m_recentPaths
.Count(); i
++)
843 if(m_recentPaths
[i
].IsSameAs(str
, false))
845 m_recentPaths
.RemoveAt(i
);
847 // only re-add when item is still valid
848 if(::wxDirExists(str
))
849 m_recentPaths
.Add(str
);
851 return; // no add when the item is not existing
861 wxMenu
*mnu
= GetMenuBar()->GetMenu(0);
864 if(::wxDirExists(str
))
867 if(m_recentPaths
.Count() == 0)
868 mnu
->AppendSeparator();
870 lastUsedID
= CM_RECENT_BUILD_ITEM
+ m_recentPaths
.Count();
871 m_recentPaths
.Add(str
);
873 // when we have more in list then we can display, prune and
874 // remove some menu items until we have room (and available ID's again)
875 if(m_recentPaths
.Count() > CM_MAX_RECENT_PATHS
)
878 while(m_recentPaths
.Count() > CM_MAX_RECENT_PATHS
)
879 m_recentPaths
.RemoveAt(0);
881 // now determine count, and remove until we have room
882 int index
= mnu
->GetMenuItemCount() - 1;
889 item
= mnu
->FindItemByPosition(index
);
892 if(item
->IsSeparator())
894 // next index is valid item
904 while(index
>= 0 && item
);
906 // ok, if count > CM_MAX_RECENT_PATHS then we are going to
907 // delete some items on the index position
908 if(count
>= CM_MAX_RECENT_PATHS
)
910 // delete items that are exceeding
911 while(count
>= CM_MAX_RECENT_PATHS
)
913 lastUsedID
= mnu
->FindItemByPosition(index
)->GetId();
914 mnu
->Delete(lastUsedID
);
921 mnu
->Append(lastUsedID
, str
);
926 bool CMakeSetupFrm::PerformCacheRun()
929 cmCacheManager
*cachem
= m_cmake
->GetCacheManager();
930 cmCacheManager::CacheIterator it
= cachem
->NewIterator();
932 // remove all items that are no longer present
934 while(j
< m_cmOptions
->GetCount())
936 // check to see if it is still in the CMake cache
937 // if it is still in the cache then it is no longer new
938 wxPropertyItem
*item
= m_cmOptions
->GetItem(j
);
939 if ( !it
.Find((const char*)item
->GetPropName().c_str()) )
940 m_cmOptions
->RemoveProperty(item
);
943 // ok we found it, mark as old
944 item
->SetNewValue(false);
945 int row
= m_cmOptions
->FindProperty(item
);
947 m_cmOptions
->UpdatePropertyItem(item
, row
);
952 if(cachem
->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag())
955 for(size_t i
= 0; i
< m_cmOptions
->GetCount(); i
++)
957 wxPropertyItem
* item
= m_cmOptions
->GetItem(i
);
958 if(item
->GetAdvanced())
960 if(item
->GetNewValue() && m_cmOptions
->GetShowAdvanced())
962 // if one new value then disable to OK button
969 if(item
->GetNewValue())
971 // if one new value then disable to OK button
982 void CMakeSetupFrm::FillCacheGUIFromCacheManager()
984 cmCacheManager
*cachem
= m_cmake
->GetCacheManager();
985 cmCacheManager::CacheIterator it
= cachem
->NewIterator();
987 // remove all items that are no longer present
989 while(j
< m_cmOptions
->GetCount())
991 // check to see if it is still in the CMake cache
992 // if it is still in the cache then it is no longer new
993 wxPropertyItem
*item
= m_cmOptions
->GetItem(j
);
994 if ( !it
.Find((const char*)item
->GetPropName().c_str()) )
995 m_cmOptions
->RemoveProperty(item
);
1000 // if there are already entries in the cache, then
1001 // put the new ones in the top, so they show up first
1002 bool reverseOrder
= false;
1003 for(cmCacheManager::CacheIterator i
= cachem
->NewIterator(); !i
.IsAtEnd(); i
.Next())
1005 const char* key
= i
.GetName();
1007 // if value has trailing space or tab, enclose it in single quotes
1008 // to enforce the fact that it has 'invisible' trailing stuff
1009 std::string value
= i
.GetValue();
1010 if (value
.size() && (value
[value
.size() - 1] == ' ' || value
[value
.size() - 1] == '\t'))
1011 value
= '\'' + value
+ '\'';
1013 bool advanced
= i
.GetPropertyAsBool("ADVANCED");
1014 switch(i
.GetType() )
1016 case cmCacheManager::BOOL
:
1020 if(cmSystemTools::IsOn(value
.c_str()))
1025 m_cmOptions
->AddProperty(key
,
1027 i
.GetProperty("HELPSTRING"),
1028 wxPropertyList::CHECKBOX
, "ON|OFF",
1034 case cmCacheManager::PATH
:
1035 m_cmOptions
->AddProperty(key
,
1037 i
.GetProperty("HELPSTRING"),
1038 wxPropertyList::PATH
,"",
1039 reverseOrder
, advanced
);
1042 case cmCacheManager::FILEPATH
:
1043 m_cmOptions
->AddProperty(key
,
1045 i
.GetProperty("HELPSTRING"),
1046 wxPropertyList::FILE,"",
1047 reverseOrder
, advanced
);
1050 case cmCacheManager::STRING
:
1051 m_cmOptions
->AddProperty(key
,
1053 i
.GetProperty("HELPSTRING"),
1054 wxPropertyList::EDIT
,"",
1055 reverseOrder
, advanced
);
1058 case cmCacheManager::INTERNAL
:
1060 wxPropertyItem
*pItem
= m_cmOptions
->FindPropertyByName(key
);
1062 m_cmOptions
->RemoveProperty(pItem
);
1069 void CMakeSetupFrm::OnExitTimer(wxTimerEvent
&event
)
1075 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSE_PROJECT
1078 void CMakeSetupFrm::OnButtonBrowseProject( wxCommandEvent
& event
)
1080 const wxString
& dir
= wxDirSelector("Select project directory", m_cmProjectPath
->GetValue());
1082 m_cmProjectPath
->SetValue(dir
);
1086 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSE_BUILD
1089 void CMakeSetupFrm::OnButtonBrowseBuild( wxCommandEvent
& event
)
1091 const wxString
& dir
= wxDirSelector("Select build directory", m_cmBuildPath
->GetValue());
1093 m_cmBuildPath
->SetValue(dir
);
1097 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_SHOW_ADVANCED
1100 void CMakeSetupFrm::OnShowAdvancedValues( wxCommandEvent
& event
)
1102 if(m_cmShowAdvanced
->GetValue())
1103 m_cmOptions
->ShowAdvanced();
1105 m_cmOptions
->HideAdvanced();
1109 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_CONFIGURE
1112 void CMakeSetupFrm::OnButtonConfigure( wxCommandEvent
& event
)
1117 void CMakeSetupFrm::DoConfigure()
1119 // enable error messages each time configure is pressed
1120 cmSystemTools::EnableMessages();
1121 m_cmOptions
->HideControls();
1123 cmSystemTools::ResetErrorOccuredFlag();
1125 // instantiate a dialog for the progress meter
1131 int CMakeSetupFrm::RunCMake(bool generateProjectFiles
)
1137 m_cmLog
->DiscardEdits();
1139 wxString builddir
= m_cmBuildPath
->GetValue(),
1140 sourcedir
= m_cmProjectPath
->GetValue(),
1141 err
= wxT("Error in configuration process, project files may be invalid");
1144 // sanity check for people pressing OK on empty dirs
1145 if(builddir
.Trim().IsEmpty() || sourcedir
.Trim().IsEmpty())
1147 wxMessageBox(wxT("Please enter a valid source directory and build directory"), wxT("Error"), wxOK
| wxICON_ERROR
, this);
1151 // check if the directory exists, if not, create it
1152 if(!cmSystemTools::FileExists(builddir
.c_str()))
1155 str
<< wxT("Build directory does not exist, should I create it?\n\nDirectory: ") << builddir
;
1157 int answer
= wxMessageBox(str
, wxT("Create directory"), wxYES_NO
, this);
1158 if (answer
== wxYES
)
1160 if(!cmSystemTools::MakeDirectory(builddir
.c_str()))
1162 // could not create, tell and abort
1163 wxMessageBox(wxT("Could not create directory"), wxT("Error"), wxOK
| wxICON_ERROR
, this);
1169 // we abort because the user did not want to make the directory
1170 wxMessageBox(wxT("Build Project aborted, nothing done."), wxT("Aborted"),
1171 wxOK
| wxICON_EXCLAMATION
, this);
1176 /** show progress dialog that informs the user with a progress bar */
1178 m_progressDlg
->Destroy();
1180 m_progressDlg
= new CMProgressDialog(this);
1181 m_progressDlg
->Show();
1183 // set the wait cursor
1184 m_RunningConfigure
= true;
1185 UpdateWindowState();
1187 // always save the current gui values to disk
1190 // Make sure we are working from the cache on disk
1191 LoadCacheFromDiskToGUI();
1193 // setup the cmake instance
1194 if (generateProjectFiles
)
1196 if(m_cmake
->Generate() != 0)
1198 wxMessageBox(err
, wxT("Error"), wxOK
| wxICON_ERROR
, this);
1199 cmSystemTools::Error(err
.c_str());
1205 m_cmOptions
->SetProjectGenerated(true); // clear cache dirty when generated
1211 m_cmake
->SetHomeDirectory(m_cmProjectPath
->GetValue().c_str());
1212 m_cmake
->SetStartDirectory(m_cmProjectPath
->GetValue().c_str());
1213 m_cmake
->SetHomeOutputDirectory(m_cmBuildPath
->GetValue().c_str());
1214 m_cmake
->SetStartOutputDirectory(m_cmBuildPath
->GetValue().c_str());
1216 m_cmake
->SetGlobalGenerator(m_cmake
->CreateGlobalGenerator(m_cmGeneratorChoice
->GetValue().c_str()));
1217 m_cmake
->SetCMakeCommand(m_PathToExecutable
.c_str());
1218 m_cmake
->LoadCache();
1219 if(m_cmake
->Configure() != 0)
1221 wxMessageBox(err
, wxT("Error"), wxOK
| wxICON_ERROR
, this);
1222 cmSystemTools::Error(err
.c_str());
1225 // update the GUI with any new values in the caused by the
1226 // generation process
1227 LoadCacheFromDiskToGUI();
1230 m_RunningConfigure
= false;
1233 cmSystemTools::ResetErrorOccuredFlag();
1235 m_progressDlg
->Destroy();
1238 // reset the statusbar progress
1239 wxStatusBar
*bar
= GetStatusBar();
1241 bar
->SetStatusText(wxEmptyString
, 1);
1243 UpdateWindowState();
1247 //! Save GUI values to cmCacheManager and then save to disk.
1248 void CMakeSetupFrm::SaveCacheFromGUI()
1250 cmCacheManager
*cachem
= m_cmake
->GetCacheManager();
1251 FillCacheManagerFromCacheGUI();
1253 // write the cache to disk
1254 if(!m_cmBuildPath
->GetValue().Trim().IsEmpty())
1255 cachem
->SaveCache(m_cmBuildPath
->GetValue().c_str());
1258 void CMakeSetupFrm::FillCacheManagerFromCacheGUI()
1260 cmCacheManager
*cachem
= m_cmake
->GetCacheManager();
1262 cmCacheManager::CacheIterator it
= cachem
->NewIterator();
1263 for(size_t i
= 0; i
< m_cmOptions
->GetCount(); i
++)
1265 wxPropertyItem
* item
= m_cmOptions
->GetItem(i
);
1266 if ( it
.Find((const char*)item
->GetPropName().c_str()) )
1268 // if value is enclosed in single quotes ('foo') then remove them
1269 // they were used to enforce the fact that it had 'invisible'
1271 if (item
->GetCurValue().Len() >= 2 &&
1272 item
->GetCurValue().GetChar(0) == '\'' &&
1273 item
->GetCurValue().GetChar(item
->GetCurValue().Len() - 1) == '\'')
1275 it
.SetValue(item
->GetCurValue().Mid(1, item
->GetCurValue().Len() - 2).c_str());
1278 it
.SetValue(item
->GetCurValue().c_str());
1285 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_OK
1288 void CMakeSetupFrm::OnButtonOk( wxCommandEvent
& event
)
1293 void CMakeSetupFrm::DoGenerate()
1295 cmSystemTools::EnableMessages();
1297 cmSystemTools::ResetErrorOccuredFlag();
1299 m_cmOptions
->HideControls();
1304 // issue a close when this is done (this is issued by menu "Generate and Exit"
1305 if(m_quitAfterGenerating
)
1307 else if(!wxGetKeyState(WXK_SHIFT
))
1310 m_config
->Read(CM_CLOSEAFTERGEN
, &close
, CM_CLOSEAFTERGEN_DEF
);
1313 wxMessageBox(wxT("Building of project files succesful!"), wxT("Success!"), wxOK
|wxICON_INFORMATION
);
1321 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_CANCEL
1324 void CMakeSetupFrm::OnButtonCancel( wxCommandEvent
& event
)
1329 void CMakeSetupFrm::DoCancelButton()
1331 if(m_RunningConfigure
)
1333 int result
= wxMessageBox(wxT("You are in the middle of a Configure.\n"
1334 "If you Cancel now the configure information will be lost.\n"
1335 "Are you sure you want to Cancel?"), wxT("Warning"), wxYES_NO
|wxICON_WARNING
);
1337 cmSystemTools::SetFatalErrorOccured();
1340 m_progressDlg
->ResetCancel();
1345 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_DELETE_CACHE
1348 void CMakeSetupFrm::OnButtonDeleteCache( wxCommandEvent
& event
)
1353 void CMakeSetupFrm::DoDeleteCache()
1355 bool deletecache
= true;
1356 if(m_cmOptions
->IsCacheDirty() || (m_cmOptions
->GetCount() > 0 && !m_cmOptions
->IsGenerated()))
1358 int result
= ::wxMessageBox(_("You have changed options, are you sure you want to delete all items?\n"),
1359 _("Warning"), wxYES_NO
|wxICON_QUESTION
);
1361 // when user wants to wait, wait.. else quit
1363 deletecache
= false;
1369 // indicate that we haven't generated a project yet
1370 m_cmOptions
->SetProjectGenerated(false);
1372 if(!m_cmBuildPath
->GetValue().Trim().IsEmpty() && m_cmake
!= 0)
1373 m_cmake
->GetCacheManager()->DeleteCache(m_cmBuildPath
->GetValue().Trim());
1375 LoadCacheFromDiskToGUI();
1376 UpdateWindowState();
1381 * Should we show tooltips?
1384 bool CMakeSetupFrm::ShowToolTips()
1390 * Get bitmap resources
1393 wxBitmap
CMakeSetupFrm::GetBitmapResource( const wxString
& name
)
1396 ////@begin CMakeSetupFrm bitmap retrieval
1397 return wxNullBitmap
;
1398 ////@end CMakeSetupFrm bitmap retrieval
1402 * Get icon resources
1405 wxIcon
CMakeSetupFrm::GetIconResource( const wxString
& name
)
1408 ////@begin CMakeSetupFrm icon retrieval
1409 if (name
== wxT("cmake_icon.xpm"))
1411 wxIcon
icon(_T("cmake_icon.xpm"), wxBITMAP_TYPE_XPM
);
1415 ////@end CMakeSetupFrm icon retrieval
1419 * wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING event handler for ID_SPLITTERWINDOW
1422 void CMakeSetupFrm::OnSplitterPosChanging( wxSplitterEvent
& event
)
1426 GetSize(&width
, &height
);
1430 if(event
.GetSashPosition() < 170)
1431 event
.SetSashPosition(170);
1434 if(event
.GetSashPosition() > (height
- 180))
1435 event
.SetSashPosition(height
- 180);
1445 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CLEAR_LOG
1448 void CMakeSetupFrm::OnClearLogClick( wxCommandEvent
& event
)
1450 // delete the log text
1452 m_cmLog
->DiscardEdits();
1457 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_SOURCE_BUILD_PATH
1460 void CMakeSetupFrm::OnSourceBuildPathUpdated( wxCommandEvent
& event
)
1465 void CMakeSetupFrm::DoReloadCache()
1467 wxString buildpath
= m_cmBuildPath
->GetValue();
1468 // The build dir has changed, check if there is a cache, and
1469 // grab the source dir from it
1471 // make sure the call to update grid is not executed
1473 m_cmSearchQuery
->SetValue(_(""));
1474 m_noRefresh
= false;
1476 std::string path
= buildpath
.c_str();
1477 cmSystemTools::ConvertToUnixSlashes(path
);
1479 // adjust the cmake instance
1480 m_cmake
->SetHomeOutputDirectory(buildpath
.c_str());
1481 m_cmake
->SetStartOutputDirectory(buildpath
.c_str());
1483 std::string cache_file
= path
;
1484 cache_file
+= "/CMakeCache.txt";
1486 // fill in the project path where the source is located, this is
1487 // read from the CMake cache
1488 cmCacheManager
*cachem
= m_cmake
->GetCacheManager();
1489 cmCacheManager::CacheIterator it
= cachem
->NewIterator();
1490 if (cmSystemTools::FileExists(cache_file
.c_str()) && cachem
->LoadCache(path
.c_str()) &&
1491 it
.Find("CMAKE_HOME_DIRECTORY"))
1493 path
= ConvertToWindowsPath(it
.GetValue());
1494 m_cmProjectPath
->SetValue(path
.c_str());
1497 m_cmOptions
->RemoveAll();
1498 LoadCacheFromDiskToGUI();
1499 UpdateWindowState();
1504 * wxEVT_COMMAND_TEXT_ENTER event handler for ID_SOURCE_BUILD_PATH
1507 void CMakeSetupFrm::OnSourceBuildPathEnter( wxCommandEvent
& event
)
1509 OnSourceBuildPathUpdated(event
);
1513 * wxEVT_MOTION event handler for ID_OPTIONS
1516 void CMakeSetupFrm::OnPropertyMotion( wxMouseEvent
& event
)
1518 ShowPropertyDescription(m_cmOptions
->YToRow(event
.GetY()));
1524 * wxEVT_GRID_SELECT_CELL event handler for ID_OPTIONS
1527 void CMakeSetupFrm::OnGridSelectCell( wxGridEvent
& event
)
1530 ShowPropertyDescription(event
.GetRow());
1532 // enable or disable the browse button
1533 m_cmBrowseCell
->Enable(m_cmOptions
->IsSelectedItemBrowsable(event
.GetRow()));
1537 void CMakeSetupFrm::ShowPropertyDescription(int row
)
1539 if(row
== wxNOT_FOUND
|| row
< 0)
1540 m_cmDescription
->SetValue(wxEmptyString
);
1543 wxPropertyItem
*pItem
= m_cmOptions
->GetPropertyItemFromRow(row
);
1545 m_cmDescription
->SetValue(pItem
->GetHelpString());
1547 m_cmDescription
->SetValue(wxEmptyString
);
1552 * wxEVT_GRID_CELL_CHANGE event handler for ID_OPTIONS
1555 void CMakeSetupFrm::OnCellChange( wxGridEvent
& event
)
1557 // update the button state when the cache is invalidated
1558 UpdateWindowState();
1561 void CMakeSetupFrm::OnRecentFileMenu( wxCommandEvent
&event
)
1566 wxMenu
*mnu
= GetMenuBar()->GetMenu(0);
1569 wxMenuItem
*item
= mnu
->FindItem(event
.GetId());
1571 m_cmBuildPath
->SetValue(item
->GetLabel());
1575 * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_COMBOBOX
1578 void CMakeSetupFrm::OnSearchquerySelected( wxCommandEvent
& event
)
1580 m_cmOptions
->SetQuery(m_cmSearchQuery
->GetValue());
1583 void CMakeSetupFrm::OnAddQuery ( wxCommandEvent
&event
)
1585 // add current text if not yet present
1586 if(m_cmSearchQuery
->FindString(m_cmSearchQuery
->GetValue()) == wxNOT_FOUND
)
1588 m_cmSearchQuery
->Append(m_cmSearchQuery
->GetValue());
1590 // if too many items are present, prune
1591 while(m_cmSearchQuery
->GetCount() > CM_MAX_SEARCH_QUERIES
)
1592 m_cmSearchQuery
->Delete(0);
1597 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_SEARCHQUERY
1600 void CMakeSetupFrm::OnSearchqueryUpdated( wxCommandEvent
& event
)
1602 // only refresh when this event was caused by user
1604 m_cmOptions
->SetQuery(m_cmSearchQuery
->GetValue());
1609 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSE_GRID
1612 void CMakeSetupFrm::OnBrowseGridClick( wxCommandEvent
& event
)
1614 m_cmOptions
->BrowseSelectedItem();
1619 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_RELOAD_CACHE
1622 void CMakeSetupFrm::OnMenuReloadCacheClick( wxCommandEvent
& event
)
1625 if(m_cmOptions
->IsCacheDirty() || (m_cmOptions
->GetCount() > 0 && !m_cmOptions
->IsGenerated()))
1627 int result
= ::wxMessageBox(_("You have changed options, are you sure you want to reload?\n"),
1628 _("Warning"), wxYES_NO
|wxICON_QUESTION
);
1630 // when user wants to wait, wait.. else quit
1641 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_DELETE_CACHE
1644 void CMakeSetupFrm::OnMenuDeleteCacheClick( wxCommandEvent
& event
)
1651 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_QUIT
1654 void CMakeSetupFrm::OnMenuQuitClick( wxCommandEvent
& event
)
1656 // the close event will veto if the user
1657 // did not want to quit due to unsaved changes
1663 * wxEVT_CLOSE_WINDOW event handler for ID_FRAME
1666 void CMakeSetupFrm::OnCloseWindow( wxCloseEvent
& event
)
1669 // - The cache is dirty
1670 // - Or the cache is OK and has some items, and no project was generated recently (configure -> generate)
1671 if(m_cmOptions
->IsCacheDirty() || (m_cmOptions
->GetCount() > 0 && !m_cmOptions
->IsGenerated()))
1673 int result
= ::wxMessageBox(_("You have changed options, but not yet generated the projects\n"
1674 "are you sure you want to quit?"), _("Warning"), wxYES_NO
|wxICON_QUESTION
);
1676 // when user wants to wait, wait.. else quit
1688 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_ABOUTDLG
1691 void CMakeSetupFrm::OnAboutClick( wxCommandEvent
& event
)
1693 CMAboutDlg
*dlg
= new CMAboutDlg(this);
1695 wxArrayString generators
;
1696 std::vector
<std::string
> names
;
1697 m_cmake
->GetRegisteredGenerators(names
);
1698 for(std::vector
<std::string
>::iterator i
= names
.begin(); i
!= names
.end(); ++i
)
1699 generators
.Add(i
->c_str());
1701 wxString cmversion
, cmsversion
;
1702 cmsversion
.Printf("v%i.%i%s", CMAKEGUI_MAJORVER
, CMAKEGUI_MINORVER
, CMAKEGUI_ADDVER
);
1704 dlg
->SetAboutText(cmversion
, cmsversion
, generators
);
1712 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_CMAKE_OPTIONS
1715 void CMakeSetupFrm::OnOptionsClick( wxCommandEvent
& event
)
1717 CMOptionsDlg
*dlg
= new CMOptionsDlg(this);
1719 dlg
->SetConfig(m_config
);
1720 if(dlg
->ShowModal() == wxID_OK
)
1722 // store volatile settings
1723 dlg
->GetConfig(m_config
);
1725 // apply non volatile setting such as clear search query, recent menu, etc.
1726 SyncFormOptions(dlg
);
1732 void CMakeSetupFrm::SyncFormOptions(CMOptionsDlg
*dlg
)
1734 // TODO: Clear search query etc.
1737 * wxEVT_COMMAND_SPLITTER_DOUBLECLICKED event handler for ID_SPLITTERWINDOW
1740 void CMakeSetupFrm::OnSplitterwindowSashDClick( wxSplitterEvent
& event
)
1747 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_CONFIGURE
1750 void CMakeSetupFrm::OnMenuConfigureClick( wxCommandEvent
& event
)
1756 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_EXITGENERATE
1759 void CMakeSetupFrm::OnMenuGenerateClick( wxCommandEvent
& event
)
1761 // set flag so that a close command is issued
1762 // after generating the cmake cache to projects
1763 m_quitAfterGenerating
= true;
1765 m_quitAfterGenerating
= false;
1770 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_TOGGLE_ADVANCED
1773 void CMakeSetupFrm::OnMenuToggleAdvancedClick( wxCommandEvent
& event
)
1775 // toggle the check box
1776 m_cmShowAdvanced
->SetValue(!m_cmShowAdvanced
->GetValue());
1777 OnShowAdvancedValues(event
);