Code::Blocks  SVN r11506
gotofunctiondlg.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 
6 #include "sdk.h"
7 #include "gotofunctiondlg.h"
8 
9 #ifndef CB_PRECOMP
10  //(*InternalHeadersPCH(GotoFunctionDlg)
11  #include <wx/checkbox.h>
12  #include <wx/sizer.h>
13  #include <wx/listctrl.h>
14  #include <wx/string.h>
15  #include <wx/intl.h>
16  #include <wx/stattext.h>
17  #include <wx/textctrl.h>
18  //*)
19 
20  #include "configmanager.h"
21  #include <algorithm>
22 #endif
23 //(*InternalHeaders(GotoFunctionDlg)
24 //*)
25 
26 //(*IdInit(GotoFunctionDlg)
30 //*)
31 
32 GotoFunctionDlg::Iterator::Iterator() : m_columnLength{ 300, 100, 300 }, m_columnMode(false)
33 {
34 }
35 
37 {
38  m_tokens.push_back(token);
39 }
40 
41 auto GotoFunctionDlg::Iterator::GetToken(int index) const -> const FunctionToken*
42 {
43  if (index >= 0 && index < int(m_tokens.size()))
44  return &m_tokens[index];
45  else
46  return nullptr;
47 }
48 
50 {
51  return m_tokens.size();
52 }
53 
55 {
56  return m_tokens[index].displayName;
57 }
58 
60 {
61  if (m_columnMode)
62  {
63  const FunctionToken &t = m_tokens[m_indices[index]];
64  switch (column)
65  {
66  case 0:
67  return t.funcName;
68  case 1:
69  return t.paramsAndreturnType;
70 
71  default:
72  return wxT("<invalid>");
73  }
74  }
75  else
76  return m_tokens[m_indices[index]].displayName;
77 }
78 
80 {
81  m_columnMode = flag;
82 }
83 
85 {
87 
88  for (const auto &t : m_tokens)
89  {
90  m_columnLength[0] = std::max<int>(m_columnLength[0], t.displayName.length());
91  m_columnLength[1] = std::max<int>(m_columnLength[1], t.funcName.length());
92  m_columnLength[2] = std::max<int>(m_columnLength[2], t.paramsAndreturnType.length());
93  }
94 
95  for (int ii = 0; ii < 3; ++ii)
96  {
97  int x, y;
98  list.GetTextExtent(wxString(wxT('A'), m_columnLength[ii]), &x, &y);
99  m_columnLength[ii] = x;
100  }
101 }
102 
104 {
105  if (m_columnMode)
106  return m_columnLength[column + 1];
107  else
108  return m_columnLength[0];
109 }
110 
112 {
113  std::sort(m_tokens.begin(), m_tokens.end(), [] (const FunctionToken &a, const FunctionToken &b) {
114  return a.funcName.CmpNoCase(b.funcName)<0;
115  });
116 }
117 
118 BEGIN_EVENT_TABLE(GotoFunctionDlg, wxDialog)
119  //(*EventTable(GotoFunctionDlg)
120  //*)
121 END_EVENT_TABLE()
122 
124  m_handler(this, iterator),
125  m_iterator(iterator)
126 {
127  BuildContent(parent, iterator);
128 }
129 
131 {
132  //(*Initialize(GotoFunctionDlg)
133  wxBoxSizer* BoxSizer1;
134  wxBoxSizer* BoxSizer2;
135  wxStaticText* StaticText1;
136 
137  Create(parent, wxID_ANY, _("Select function..."), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX|wxMAXIMIZE_BOX, _T("wxID_ANY"));
138  BoxSizer1 = new wxBoxSizer(wxVERTICAL);
139  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
140  StaticText1 = new wxStaticText(this, wxID_ANY, _("Please select function to go to:"), wxDefaultPosition, wxDefaultSize, 0, _T("wxID_ANY"));
141  BoxSizer2->Add(StaticText1, 0, wxALIGN_CENTER_VERTICAL, 5);
142  BoxSizer2->Add(-1,-1,1, wxALL|wxEXPAND, 5);
143  m_mode = new wxCheckBox(this, ID_CHECKBOX1, _("Column Mode"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
144  m_mode->SetValue(false);
145  BoxSizer2->Add(m_mode, 0, wxEXPAND, 5);
146  BoxSizer1->Add(BoxSizer2, 0, wxLEFT|wxRIGHT|wxEXPAND, 8);
148  m_text->SetFocus();
149  BoxSizer1->Add(m_text, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 5);
151  m_list->SetMinSize(wxSize(500,300));
152  BoxSizer1->Add(m_list, 1, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 5);
153  SetSizer(BoxSizer1);
154  BoxSizer1->Fit(this);
155  BoxSizer1->SetSizeHints(this);
156 
157  Connect(ID_CHECKBOX1,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&GotoFunctionDlg::OnModeClick);
158  //*)
159 
160  if (Manager::Get()->GetConfigManager(_T("code_completion"))->ReadBool(_T("goto_function_window/column_mode")))
161  m_mode->SetValue(true);
162 
163  m_list->SetIterator(iterator);
164  SwitchMode();
166 }
167 
169 {
170  m_handler.DeInit(this);
171 
172  //(*Destroy(GotoFunctionDlg)
173  //*)
174 }
175 
177 {
178  bool columnMode = m_mode->IsChecked();
179  m_iterator->SetColumnMode(columnMode);
180 
181  while (m_list->GetColumnCount() > 0)
182  m_list->DeleteColumn(0);
183 
184  if (columnMode)
185  {
186  m_list->SetWindowStyleFlag(m_list->GetWindowStyleFlag() & ~wxLC_NO_HEADER);
187 
188  m_list->InsertColumn(0, _("Function name"), wxLIST_FORMAT_LEFT, m_iterator->GetColumnWidth(0));
189  m_list->InsertColumn(1, _("Parameters and return type"), wxLIST_FORMAT_LEFT, m_iterator->GetColumnWidth(1));
190  }
191  else
192  {
193  m_list->SetWindowStyleFlag(m_list->GetWindowStyleFlag() | wxLC_NO_HEADER);
194 
196  }
197 }
198 
200 {
201  ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("code_completion"));
202  cfg->Write(_T("goto_function_window/column_mode"), m_mode->IsChecked());
203 
204  SwitchMode();
206 
207  event.Skip();
208 }
209 
211 {
212  return m_handler.GetSelection();
213 }
const wxString & GetItemFilterString(int index) const override
wxSize Fit(wxWindow *window)
#define wxMAXIMIZE_BOX
int wxNewId()
Iterator * m_iterator
static const long ID_CHECKBOX1
bool m_columnMode
0 is for non-column mode, 1 and 2 are for column mode.
ConfigManager * GetConfigManager(const wxString &name_space) const
Definition: manager.cpp:474
const wxValidator wxDefaultValidator
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
virtual ~GotoFunctionDlg()
#define wxLC_REPORT
#define wxTE_PROCESS_ENTER
void CalcColumnWidth(wxListCtrl &list) override
#define _T(string)
#define wxHSCROLL
void Init(wxListCtrl *list, wxTextCtrl *text)
void AddToken(const FunctionToken &token)
#define wxT(string)
wxTextCtrl * m_text
int CmpNoCase(const wxString &s) const
void Write(const wxString &name, const wxString &value, bool ignoreEmpty=false)
void SetIterator(IncrementalSelectIterator *iterator)
void BuildContent(wxWindow *parent, Iterator *iterator)
bool DeleteColumn(int col)
wxSizerItem * Add(wxWindow *window, const wxSizerFlags &flags)
IncrementalListCtrl * m_list
const wxSize wxDefaultSize
const wxPoint wxDefaultPosition
int GetColumnWidth(int column) const override
static const long ID_LISTCTRL1
#define wxDEFAULT_DIALOG_STYLE
wxString wxEmptyString
#define wxLC_SINGLE_SEL
The goto function dialog allow user to type a function name, and filter out the functions.
const wxString & _(const wxString &string)
#define wxLC_NO_HEADER
bool IsChecked() const
Class that implements a virtual list control that uses an IncrementalSelectIterator to populate the l...
std::vector< FunctionToken > m_tokens
int GetColumnCount() const
#define wxCLOSE_BOX
long InsertColumn(long col, const wxListItem &info)
void SetSizeHints(wxWindow *window)
void SetWindowStyleFlag(long style)
#define wxLC_VIRTUAL
IncrementalSelectHandler m_handler
static const long ID_TEXTCTRL1
wxString GetDisplayText(int index, int column) const override
void OnModeClick(wxCommandEvent &event)
#define wxRESIZE_BORDER
const FunctionToken * GetToken(int index) const
virtual void SetValue(bool state)
int GetTotalCount() const override
#define wxVSCROLL
wxCheckBox * m_mode