Code::Blocks  SVN r11506
compilersettingsdlg.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  *
5  * $Revision: 10931 $
6  * $Id: compilersettingsdlg.cpp 10931 2016-12-04 16:30:27Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/src/compilersettingsdlg.cpp $
8  */
9 
10 #include <sdk.h>
11 
12 #ifndef CB_PRECOMP
13  #include <manager.h>
14  #include <configmanager.h>
15  #include <pluginmanager.h>
16  #include <cbplugin.h>
17  #include <wx/button.h>
18  #include <wx/checklst.h>
19  #include <wx/filename.h>
20  #include <wx/imaglist.h>
21  #include <wx/intl.h>
22  #include <wx/listctrl.h>
23  #include <wx/sizer.h> // SetSizeHints
24  #include <wx/stattext.h> // wxStaticText
25  #include <wx/xrc/xmlres.h>
26 #endif // CB_PRECOMP
27 
28 #include <wx/listbook.h>
29 
30 #include "configurationpanel.h"
31 #include "compilersettingsdlg.h"
32 #include "appglobals.h"
33 #ifdef __WXMSW__
34  #include "associations.h"
35 #endif
36 
37 // images by order of pages
38 const wxString base_imgs[] =
39 {
40  _T("batch"),
41 };
42 const int IMAGES_COUNT = sizeof(base_imgs) / sizeof(wxString);
43 
44 BEGIN_EVENT_TABLE(CompilerSettingsDlg, wxScrollingDialog)
45 END_EVENT_TABLE()
46 
47 // This dialog initially contains only the batch-build settings.
48 // So we 'll add all compiler-related configuration before it
49 // and all debugger-related after it...
50 
52 {
53  wxXmlResource::Get()->LoadObject(this, parent, _T("dlgCompilerSettings"),_T("wxScrollingDialog"));
54  XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
55 
56  m_pImageList = new wxImageList(80, 80);
57 
58  Connect(XRCID("nbMain"),wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING,wxListbookEventHandler(CompilerSettingsDlg::OnPageChanging));
59  Connect(XRCID("nbMain"),wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, wxListbookEventHandler(CompilerSettingsDlg::OnPageChanged ));
60 
61  // tab "Batch builds"
62  if (platform::windows)
63  XRCCTRL(*this, "txtBatchBuildsCmdLine", wxTextCtrl)->SetValue(Manager::Get()->GetConfigManager(_T("app"))->Read(_T("/batch_build_args"), appglobals::DefaultBatchBuildArgs));
64  else
65  XRCCTRL(*this, "txtBatchBuildsCmdLine", wxTextCtrl)->Enable(false);
66 
67  // fill plugins list
68  const wxArrayString &bbplugins = cbReadBatchBuildPlugins();
69  wxCheckListBox* clb = XRCCTRL(*this, "chkBBPlugins", wxCheckListBox);
70  clb->Clear();
71  clb->SetMinSize(wxSize(-1, 150));
72  const PluginElementsArray& plugins = Manager::Get()->GetPluginManager()->GetPlugins();
73  for (size_t i = 0; i < plugins.GetCount(); ++i)
74  {
75  PluginElement* elem = plugins[i];
76  if (!elem)
77  continue;
78  cbPlugin* plugin = elem->plugin;
79  if (!plugin || !plugin->IsAttached())
80  continue;
81  wxString filename = wxFileName(elem->fileName).GetFullName();
82  size_t index = clb->Append(elem->info.title);
83  // check item if any wildcard matches
84  for (size_t n = 0; n < bbplugins.GetCount(); ++n)
85  {
86  if (filename.CmpNoCase(bbplugins[n]) == 0)
87  {
88  clb->Check(index, plugin->IsAttached());
89  break;
90  }
91  }
92  }
93 
94  // add all plugins configuration panels
95  AddPluginPanels();
96 
97  // make sure everything is laid out properly
98  GetSizer()->SetSizeHints(this);
99  CentreOnParent();
100  Layout();
101 }
102 
104 {
105  //dtor
106  delete m_pImageList;
107 }
108 
110 {
111  const wxString base = _T("images/settings/");
112  // for plugins who do not supply icons, use common generic icons
113  const wxString noimg = _T("images/settings/generic-plugin");
114  wxListbook* lb = XRCCTRL(*this, "nbMain", wxListbook);
115 
116  // we 'll remove the existing page and add it when appropriate
117  wxWindow* existingPage = lb->GetPage(0);
118  wxString existingTitle = lb->GetPageText(0);
119  lb->RemovePage(0);
120 
121  // we 'll do this in two steps:
122  // 1) get all compiler-related panels and put them before batch-builds
123  // 2) get all debugger panels and put them after batch-builds
124 
125  ConfigurationPanelsArray local;
126 
127  // step 1
129  for (size_t i = 0; i < local.GetCount(); ++i)
130  {
131  cbConfigurationPanel* panel = local[i];
132  panel->SetParentDialog(this);
133  lb->AddPage(panel, panel->GetTitle());
134 
135  wxString onFile = ConfigManager::LocateDataFile(base + panel->GetBitmapBaseName() + _T(".png"), sdDataGlobal | sdDataUser);
136  if (onFile.IsEmpty())
137  onFile = ConfigManager::LocateDataFile(noimg + _T(".png"), sdDataGlobal | sdDataUser);
138  wxString offFile = ConfigManager::LocateDataFile(base + panel->GetBitmapBaseName() + _T("-off.png"), sdDataGlobal | sdDataUser);
139  if (offFile.IsEmpty())
140  offFile = ConfigManager::LocateDataFile(noimg + _T("-off.png"), sdDataGlobal | sdDataUser);
141 
142  m_pImageList->Add(cbLoadBitmap(onFile));
143  m_pImageList->Add(cbLoadBitmap(offFile));
144  lb->SetPageImage(lb->GetPageCount() - 1, m_pImageList->GetImageCount() - 2);
145 
146  // add it in our central container too
147  m_PluginPanels.Add(panel);
148  }
149 
150  // now load the builtin pages' images
151  lb->AddPage(existingPage, existingTitle);
152  wxString onFile = ConfigManager::LocateDataFile(base + base_imgs[0] + _T(".png"), sdDataGlobal | sdDataUser);
153  if (onFile.IsEmpty())
154  onFile = ConfigManager::LocateDataFile(noimg + _T(".png"), sdDataGlobal | sdDataUser);
155  wxString offFile = ConfigManager::LocateDataFile(base + base_imgs[0] + _T("-off.png"), sdDataGlobal | sdDataUser);
156  if (offFile.IsEmpty())
157  offFile = ConfigManager::LocateDataFile(noimg + _T("-off.png"), sdDataGlobal | sdDataUser);
158 
159  m_pImageList->Add(cbLoadBitmap(onFile));
160  m_pImageList->Add(cbLoadBitmap(offFile));
161  lb->SetPageImage(lb->GetPageCount() -1, m_pImageList->GetImageCount() - 2);
162 
164 }
165 
167 {
168  wxListbook* lb = XRCCTRL(*this, "nbMain", wxListbook);
169  int sel = lb->GetSelection();
170 
171  if (SettingsIconsStyle(Manager::Get()->GetConfigManager(_T("app"))->ReadInt(_T("/environment/settings_size"), 0)))
172  {
174  lb->SetImageList(nullptr);
175  }
176  else
177  {
178  lb->SetImageList(m_pImageList);
179  // set page images according to their on/off status
180  for (size_t i = 0; i < IMAGES_COUNT + m_PluginPanels.GetCount(); ++i)
181  lb->SetPageImage(i, (i * 2) + (sel == (int)i ? 0 : 1));
183  }
184 
185  // update the page title
186  wxString label = lb->GetPageText(sel);
187  // replace any stray & with && because label makes it an underscore
188  while (label.Replace(_T(" & "), _T(" && ")))
189  ;
190  XRCCTRL(*this, "lblBigTitle", wxStaticText)->SetLabel(label);
191  XRCCTRL(*this, "pnlTitleInfo", wxPanel)->Layout();
192 }
193 
194 void CompilerSettingsDlg::OnPageChanging(cb_unused wxListbookEvent& event)
195 {
196 }
197 
198 void CompilerSettingsDlg::OnPageChanged(wxListbookEvent& event)
199 {
200  // update only on real change, not on dialog creation
201  if (event.GetOldSelection() != -1 && event.GetSelection() != -1)
203 }
204 
206 {
207  if (retCode == wxID_OK)
208  {
209  // tab "Batch builds"
210 #ifdef __WXMSW__ /* TODO: remove preprocessor when Associations::SetXXX are supported on non-Windows platforms */
211  ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("app"));
212  wxString bbargs = XRCCTRL(*this, "txtBatchBuildsCmdLine", wxTextCtrl)->GetValue();
213  if (bbargs != cfg->Read(_T("/batch_build_args"), appglobals::DefaultBatchBuildArgs))
214  {
215  cfg->Write(_T("/batch_build_args"), bbargs);
217  }
218 #endif //#ifdef __WXMSW__
219 
220  // batch build plugins
221  wxArrayString bbplugins;
222  wxCheckListBox* clb = XRCCTRL(*this, "chkBBPlugins", wxCheckListBox);
223  for (size_t i = 0; i < clb->GetCount(); ++i)
224  {
225  if (clb->IsChecked(i))
226  {
227  const PluginElementsArray& plugins = Manager::Get()->GetPluginManager()->GetPlugins();
228  for (size_t n = 0; n < plugins.GetCount(); ++n)
229  {
230  PluginElement* elem = plugins[n];
231  if (!elem)
232  continue;
233  if (elem->info.title == clb->GetString(i))
234  {
235  bbplugins.Add(wxFileName(elem->fileName).GetFullName());
236  break;
237  }
238  }
239  }
240  }
241 
242  cbWriteBatchBuildPlugins(bbplugins, this);
243 
244  // finally, apply settings in all plugins' panels
245  for (size_t i = 0; i < m_PluginPanels.GetCount(); ++i)
246  {
248  panel->OnApply();
249  }
250  }
251  else
252  {
253  // finally, cancel settings in all plugins' panels
254  for (size_t i = 0; i < m_PluginPanels.GetCount(); ++i)
255  {
257  panel->OnCancel();
258  }
259  }
260 
262 }
Base class for plugins.
Definition: cbplugin.h:84
void EndModal(int retCode)
Definition: sc_dialog.cpp:112
virtual bool AddPage(wxWindow *page, const wxString &text, bool select=false, int imageId=NO_IMAGE)
PluginManager * GetPluginManager() const
Definition: manager.cpp:444
wxString fileName
Definition: pluginmanager.h:55
virtual bool SetPageImage(size_t page, int image)=0
virtual int GetSelection() const=0
Data folder in user&#39;s dir.
Definition: configmanager.h:75
Large icons (default)
Definition: globals.h:299
ConfigManager * GetConfigManager(const wxString &name_space) const
Definition: manager.cpp:474
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
SettingsIconsStyle
Icons styles for settings dialogs.
Definition: globals.h:297
virtual wxString GetString(unsigned int n) const
DLLIMPORT wxBitmap cbLoadBitmap(const wxString &filename, wxBitmapType bitmapType=wxBITMAP_TYPE_PNG)
This function loads a bitmap from disk.
Definition: globals.cpp:1102
void GetConfigurationPanels(int group, wxWindow *parent, ConfigurationPanelsArray &arrayToFill)
static const int cgCompiler
Compiler related.
Definition: cbplugin.h:68
virtual wxString GetTitle() const =0
wxImageList * m_pImageList
const PluginElementsArray & GetPlugins() const
virtual size_t GetPageCount() const
virtual void OnApply()=0
Called when the user chooses to apply the configuration.
#define _T(string)
virtual void OnCancel()=0
Called when the user chooses to cancel the configuration.
wxString title
Definition: pluginmanager.h:41
PluginInfo info
Definition: pluginmanager.h:54
bool IsChecked(unsigned int item) const
int CmpNoCase(const wxString &s) const
static wxString LocateDataFile(const wxString &filename, int search_dirs=sdAllKnown)
Locate a file in an installation- and platform-independent way.
No icons, just text.
Definition: globals.h:300
void Write(const wxString &name, const wxString &value, bool ignoreEmpty=false)
virtual int GetImageCount() const
ConfigurationPanelsArray m_PluginPanels
void Check(unsigned int item, bool check=true)
void OnPageChanging(wxListbookEvent &event)
wxString Read(const wxString &key, const wxString &defaultVal=wxEmptyString)
void SetBatchBuildOnly()
Base class for plugin configuration panels.
virtual wxString GetBitmapBaseName() const =0
bool IsEmpty() const
DLLIMPORT wxArrayString cbReadBatchBuildPlugins()
Read the list of batch build plugins and return them.
wxString GetFullName() const
virtual void EndModal(int retCode)
DLLIMPORT void SetSettingsIconsStyle(wxListCtrl *lc, SettingsIconsStyle style)
Set the icons style for the supplied list control.
Definition: globals.cpp:1125
size_t Add(const wxString &str, size_t copies=1)
const wxString DefaultBatchBuildArgs
Definition: appglobals.cpp:72
int Add(const wxBitmap &bitmap, const wxBitmap &mask=wxNullBitmap)
virtual wxString GetPageText(size_t nPage) const=0
size_t GetCount() const
static wxXmlResource * Get()
bool IsAttached() const
See whether this plugin is attached or not.
Definition: cbplugin.h:187
const wxString base_imgs[]
cbPlugin * plugin
Definition: pluginmanager.h:58
Data folder in base dir.
Definition: configmanager.h:81
virtual bool RemovePage(size_t page)
DLLIMPORT void cbWriteBatchBuildPlugins(wxArrayString bbplugins, wxWindow *messageBoxParent)
Write the list of batch build plugins in the config.
void SetParentDialog(wxWindow *dialog)
Sets the panel&#39;s parent dialog.
wxListView * GetListView() const
wxObject * LoadObject(wxWindow *parent, const wxString &name, const wxString &classname)
virtual unsigned int GetCount() const
void OnPageChanged(wxListbookEvent &event)
const int IMAGES_COUNT