1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2008 by Eran Ifrah
// file name : advanced_settings.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version May 5 2007)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "windowattrmanager.h"
#include "macros.h"
#include "buildsettingstab.h"
#include "advanced_settings.h"
#include "manager.h"
#include "editor_config.h"
#include <wx/xrc/xmlres.h>
#include "build_settings_config.h"
#include "build_page.h"
#include "globals.h"
#include "frame.h"
#include <wx/textdlg.h>
#include "advance_settings_base.h"
#include "NewCompilerDlg.h"
#include <CompilersDetectorManager.h>
#include "CompilersFoundDlg.h"
#include <cl_aui_notebook_art.h>
///////////////////////////////////////////////////////////////////////////
AdvancedDlg::AdvancedDlg( wxWindow* parent, size_t selected_page, int id, wxString title, wxPoint pos, wxSize size, int style )
: AdvancedDlgBase( parent )
, m_rightclickMenu(NULL)
{
#ifndef __WXGTK__
m_notebook->SetArtProvider(new clAuiGlossyTabArt);
#endif
m_compilersMainPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* bSizer5;
bSizer5 = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxHORIZONTAL );
bSizer5->Add( bSizer4, 0, wxALIGN_RIGHT|wxEXPAND, 5 );
m_compilersPage = new CompilerMainPage(m_compilersMainPanel);
bSizer5->Add( m_compilersPage, 1, wxALL|wxEXPAND, 5 );
m_compilersMainPanel->SetSizer( bSizer5 );
//m_compilersMainPanel->Layout();
m_notebook->AddPage( m_compilersMainPanel, _("Compilers"), true );
m_buildSettings = new BuildTabSetting(m_notebook);
m_notebook->AddPage(m_buildSettings, _("Build Output Appearance"), false);
m_buildPage = new BuildPage(m_notebook);
m_notebook->AddPage(m_buildPage, _("Build Systems"), false);
m_rightclickMenu = wxXmlResource::Get()->LoadMenu(wxT("delete_compiler_menu"));
LoadCompilers();
// center the dialog
Centre();
this->Layout();
WindowAttrManager::Load(this, wxT("BuildSettingsDlg"), NULL);
}
void AdvancedDlg::LoadCompilers()
{
m_compilersPage->LoadCompilers();
}
AdvancedDlg::~AdvancedDlg()
{
wxDELETE(m_rightclickMenu);
WindowAttrManager::Save(this, wxT("BuildSettingsDlg"), NULL);
}
void AdvancedDlg::OnButtonNewClicked()
{
NewCompilerDlg dlg(this);
if ( dlg.ShowModal() == wxID_OK ) {
CreateNewCompiler(dlg.GetCompilerName(), dlg.GetMasterCompiler());
LoadCompilers();
}
}
void AdvancedDlg::OnButtonOKClicked(wxCommandEvent &event)
{
wxUnusedVar(event);
//save all compiler pages
SaveCompilers();
//save the build page
m_buildPage->Save();
m_buildSettings->Save();
//mark all the projects as dirty
wxArrayString projects;
WorkspaceST::Get()->GetProjectList( projects );
for ( size_t i=0; i< projects.size(); i++ ) {
ProjectPtr proj = ManagerST::Get()->GetProject( projects.Item(i) );
if ( proj ) {
proj->SetModified( true );
}
}
EndModal(wxID_OK);
}
void AdvancedDlg::SaveCompilers()
{
std::map<wxString, std::vector<ICompilerSubPage*> >::iterator iter = m_compilerPagesMap.begin();
for(; iter != m_compilerPagesMap.end(); iter ++) {
std::vector<ICompilerSubPage*> items = iter->second;
wxString cmpname = iter->first;
CompilerPtr cmp = BuildSettingsConfigST::Get()->GetCompiler(cmpname);
if(cmp) {
for(size_t i=0; i<items.size(); i++) {
ICompilerSubPage* p = items.at(i);
p->Save(cmp);
}
BuildSettingsConfigST::Get()->SetCompiler(cmp);//save changes
}
}
}
bool AdvancedDlg::CreateNewCompiler (const wxString& name, const wxString& copyFrom)
{
if ( BuildSettingsConfigST::Get()->IsCompilerExist ( name ) ) {
wxMessageBox ( _( "A compiler with this name already exists" ), _( "Error" ), wxOK | wxICON_HAND );
return false;
}
CompilerPtr cmp;
if ( !copyFrom.IsEmpty() ) {
cmp = BuildSettingsConfigST::Get()->GetCompiler ( copyFrom );
} else {
cmp = BuildSettingsConfigST::Get()->GetCompiler ( name );
}
cmp->SetName ( name );
BuildSettingsConfigST::Get()->SetCompiler ( cmp );
return true;
}
bool AdvancedDlg::DeleteCompiler ( const wxString &name )
{
if ( wxMessageBox ( _( "Remove Compiler?" ), _( "Confirm" ), wxYES_NO | wxICON_QUESTION ) == wxYES ) {
BuildSettingsConfigST::Get()->DeleteCompiler ( name );
return true;
}
return false;
}
void AdvancedDlg::OnContextMenu(wxContextMenuEvent& e)
{
// wxTreeCtrl *tree = m_compilersNotebook->GetTreeCtrl();
// wxTreeItemId item = tree->GetSelection();
//
// // only compilers have children
// if(item.IsOk() && tree->HasChildren(item)) {
// PopupMenu(m_rightclickMenu);
// }
}
void AdvancedDlg::OnRestoreDefaults(wxCommandEvent&)
{
if(wxMessageBox(_("Are you sure you want to revert to the default settings?"),
wxT("CodeLite"),
wxYES_NO|wxCANCEL|wxCENTRE|wxICON_WARNING,
this) == wxYES) {
// restore the default settings of the build configuration
BuildSettingsConfigST::Get()->RestoreDefaults();
// Dismiss this dialog and reload it
wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, XRCID("advance_settings"));
clMainFrame::Get()->GetEventHandler()->AddPendingEvent(event);
EndModal(wxID_OK);
}
}
#define ID_MENU_AUTO_DETECT_COMPILERS 1001
#define ID_MENU_ADD_COMPILER_BY_PATH 1002
#define ID_MENU_CLONE_COMPILER 1003
void AdvancedDlg::OnAutoDetectCompilers( wxButton* btn )
{
// Launch the auto detect compilers code
wxMenu menu;
menu.Append(ID_MENU_ADD_COMPILER_BY_PATH, _("Add an existing compiler"));
menu.Append(ID_MENU_CLONE_COMPILER, _("Clone a compiler"));
menu.AppendSeparator();
menu.Append(ID_MENU_AUTO_DETECT_COMPILERS, _("Scan computer for installed compilers"));
// Menu will be shown in client coordinates
wxRect size = btn->GetSize();
wxPoint menuPos(0, size.GetHeight());
int res = btn->GetPopupMenuSelectionFromUser( menu, menuPos );
if ( res == ID_MENU_AUTO_DETECT_COMPILERS ) {
if ( m_compilersDetector.Locate() ) {
CallAfter( &AdvancedDlg::OnCompilersDetected, m_compilersDetector.GetCompilersFound() );
}
} else if ( res == ID_MENU_CLONE_COMPILER ) {
CallAfter( &AdvancedDlg::OnButtonNewClicked );
} else if ( res == ID_MENU_ADD_COMPILER_BY_PATH ) {
CallAfter( &AdvancedDlg::OnAddExistingCompiler );
}
}
void AdvancedDlg::OnCompilersDetected(const ICompilerLocator::CompilerVec_t& compilers)
{
CompilersFoundDlg dlg(this, compilers);
if ( dlg.ShowModal() == wxID_OK ) {
// Replace the current compilers with a new one
BuildSettingsConfigST::Get()->SetCompilers( compilers );
// update the code completion search paths
clMainFrame::Get()->CallAfter( &clMainFrame::UpdateParserSearchPathsFromDefaultCompiler );
// Dismiss this dialog and reload it
wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, XRCID("advance_settings"));
clMainFrame::Get()->GetEventHandler()->AddPendingEvent(event);
EndModal(wxID_OK);
}
}
void AdvancedDlg::OnApply(wxCommandEvent& event)
{
m_compilersPage->Save();
}
void AdvancedDlg::OnApplyUI(wxUpdateUIEvent& event)
{
event.Enable( m_compilersPage->IsDirty() );
}
void AdvancedDlg::OnAddExistingCompiler()
{
wxString folder = ::wxDirSelector(_("Select the compiler folder"));
if ( folder.IsEmpty() ) {
return;
}
CompilerPtr cmp = m_compilersDetector.Locate( folder );
if ( cmp ) {
// We found new compiler
// Prompt the user to give it a name
while ( true ) {
wxString name = ::wxGetTextFromUser(_("Compiler Name:"), _("Set a name to the compiler"), cmp->GetName());
if ( name.IsEmpty() ) {
return;
}
// Add the compiler
if ( BuildSettingsConfigST::Get()->IsCompilerExist(name) ) {
continue;
}
cmp->SetName( name );
break;
}
// Save the new compiler
BuildSettingsConfigST::Get()->SetCompiler( cmp );
// Reload the dialog
LoadCompilers();
}
}
|