Code::Blocks  SVN r11506
ccoptionsprjdlg.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: 8541 $
6  * $Id: ccoptionsprjdlg.cpp 8541 2012-11-10 18:37:28Z thomasdenk $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/codecompletion/ccoptionsprjdlg.cpp $
8  */
9 
10 #include <sdk.h>
11 
12 #ifndef CB_PRECOMP
13  #include <wx/button.h>
14  #include <wx/intl.h>
15  #include <wx/listbox.h>
16  #include <wx/xrc/xmlres.h>
17 
18  #include <cbproject.h>
19  #include <cbstyledtextctrl.h>
20  #include <globals.h>
21  #include <logmanager.h>
22  #include <manager.h>
23 #endif
24 
25 #include <editpathdlg.h>
26 
27 #include "ccoptionsprjdlg.h"
28 
29 BEGIN_EVENT_TABLE(CCOptionsProjectDlg, wxPanel)
30  EVT_UPDATE_UI(-1, CCOptionsProjectDlg::OnUpdateUI)
31  EVT_BUTTON(XRCID("btnAdd"), CCOptionsProjectDlg::OnAdd)
32  EVT_BUTTON(XRCID("btnEdit"), CCOptionsProjectDlg::OnEdit)
33  EVT_BUTTON(XRCID("btnDelete"), CCOptionsProjectDlg::OnDelete)
34 END_EVENT_TABLE()
35 
37  m_Project(project),
38  m_NativeParser(np),
39  m_Parser(&np->GetParser())
40 {
41  wxXmlResource::Get()->LoadPanel(this, parent, _T("pnlProjectCCOptions"));
42  m_OldPaths = m_NativeParser->GetProjectSearchDirs(m_Project);
43 
44  wxListBox* control = XRCCTRL(*this, "lstPaths", wxListBox);
45  control->Clear();
46  for (size_t i = 0; i < m_OldPaths.GetCount(); ++i)
47  control->Append(m_OldPaths[i]);
48 }
49 
51 {
52 }
53 
55 {
56  wxListBox* control = XRCCTRL(*this, "lstPaths", wxListBox);
57 
58  EditPathDlg dlg(this,
59  m_Project ? m_Project->GetBasePath() : _T(""),
60  m_Project ? m_Project->GetBasePath() : _T(""),
61  _("Add directory"));
62 
63  PlaceWindow(&dlg);
64  if (dlg.ShowModal() == wxID_OK)
65  {
66  wxString path = dlg.GetPath();
67  control->Append(path);
68  }
69 }
70 
72 {
73  wxListBox* control = XRCCTRL(*this, "lstPaths", wxListBox);
74  int sel = control->GetSelection();
75  if (sel < 0)
76  return;
77 
78  EditPathDlg dlg(this,
79  control->GetString(sel),
80  m_Project ? m_Project->GetBasePath() : _T(""),
81  _("Edit directory"));
82 
83  PlaceWindow(&dlg);
84  if (dlg.ShowModal() == wxID_OK)
85  {
86  wxString path = dlg.GetPath();
87  control->SetString(sel, path);
88  }
89 }
90 
92 {
93  wxListBox* control = XRCCTRL(*this, "lstPaths", wxListBox);
94  int sel = control->GetSelection();
95  if (sel < 0)
96  return;
97 
98  control->Delete(sel);
99 }
100 
102 {
103  wxListBox* control = XRCCTRL(*this, "lstPaths", wxListBox);
104  bool en = control->GetSelection() >= 0;
105 
106  XRCCTRL(*this, "btnEdit", wxButton)->Enable(en);
107  XRCCTRL(*this, "btnDelete", wxButton)->Enable(en);
108 }
109 
111 {
112  wxArrayString newpaths;
113  wxListBox* control = XRCCTRL(*this, "lstPaths", wxListBox);
114  for (int i = 0; i < (int)control->GetCount(); ++i)
115  newpaths.Add(control->GetString(i));
116 
117  if (m_OldPaths != newpaths)
118  {
119  for (size_t i = 0; i < newpaths.GetCount(); ++i)
120  {
121  if (m_Parser)
122  m_Parser->AddIncludeDir(newpaths[i]);
123  }
124 
126  pdirs = newpaths;
127 
128  cbMessageBox(_("You have changed the C/C++ parser search paths for this project.\n"
129  "These paths will be taken into account for next parser runs.\n"
130  "If you want them to take effect immediately, you will have to close "
131  "and re-open your project."),
132  _("Information"), wxICON_INFORMATION);
133  }
134 }
void OnAdd(wxCommandEvent &event)
void OnEdit(wxCommandEvent &event)
void OnDelete(wxCommandEvent &event)
void OnUpdateUI(wxUpdateUIEvent &event)
#define _T(string)
#define wxICON_INFORMATION
virtual ~CCOptionsProjectDlg()
wxPanel * LoadPanel(wxWindow *parent, const wxString &name)
Represents a Code::Blocks project.
Definition: cbproject.h:96
virtual wxString GetBasePath() const
Read the target&#39;s base path, e.g. if GetFilename() returns "/usr/local/bin/xxx", base path will retur...
void AddIncludeDir(const wxString &dir)
add a directory to the Parser&#39;s include path database
const wxString & _(const wxString &string)
int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
Call global cbMessageBox with m_parentDialog as parent window when no parent window specified...
NativeParser class is just like a manager class to control Parser objects.
Definition: nativeparser.h:55
DLLIMPORT void PlaceWindow(wxTopLevelWindow *w, cbPlaceDialogMode mode=pdlBest, bool enforce=false)
Definition: globals.cpp:1177
wxArrayString m_OldPaths
ParserBase * m_Parser
size_t Add(const wxString &str, size_t copies=1)
size_t GetCount() const
static wxXmlResource * Get()
NativeParser * m_NativeParser
virtual void OnApply()
Called when the user chooses to apply the configuration.
wxArrayString & GetProjectSearchDirs(cbProject *project)
project search path is used for auto completion for #include <>