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
6
* $Id: insertclassmethoddlg.cpp 4909 2008-02-27 13:15:26Z mortenmacfly $
7
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/codecompletion/insertclassmethoddlg.cpp $
12
#include <wx/checkbox.h>
13
#include <wx/checklst.h>
15
#include <wx/listbox.h>
16
#include <wx/radiobox.h>
17
#include <wx/xrc/xmlres.h>
20
#include "logmanager.h"
22
#include "parser/parser.h"
23
#include "insertclassmethoddlg.h"
25
BEGIN_EVENT_TABLE(InsertClassMethodDlg, wxDialog)
26
EVT_LISTBOX(XRCID("lstClasses"), InsertClassMethodDlg::OnClassesChange)
27
EVT_RADIOBOX(XRCID("rbCode"), InsertClassMethodDlg::OnCodeChange)
28
EVT_CHECKBOX(XRCID("chkPrivate"), InsertClassMethodDlg::OnFilterChange)
29
EVT_CHECKBOX(XRCID("chkProtected"), InsertClassMethodDlg::OnFilterChange)
30
EVT_CHECKBOX(XRCID("chkPublic"), InsertClassMethodDlg::OnFilterChange)
33
InsertClassMethodDlg::InsertClassMethodDlg(wxWindow* parent, Parser* parser, const wxString& filename)
39
wxXmlResource::Get()->LoadDialog(this, parent, _T("dlgInsertClassMethod"));
40
XRCCTRL(*this, "rbCode", wxRadioBox)->SetSelection(0);
44
InsertClassMethodDlg::~InsertClassMethodDlg()
49
wxArrayString InsertClassMethodDlg::GetCode() const
52
const wxCheckListBox* clb = XRCCTRL(*this, "chklstMethods", wxCheckListBox);
54
for (int i = 0; i < (int)clb->GetCount(); ++i)
56
if (clb->IsChecked(i))
59
if (XRCCTRL(*this, "chkAddDoc", wxCheckBox)->IsChecked())
62
str << _T("/** @brief (one liner)\n *\n * (documentation goes here)\n */\n");
64
str << clb->GetString(i);
65
str.Replace(_T("&&"), _T("&"));
66
array.Add(str + (m_Decl ? _T(";\n") : _T("\n{\n\n}\n\n")));
73
void InsertClassMethodDlg::FillClasses()
75
if (!m_pParser || !m_pParser->Done())
78
wxListBox* lb = XRCCTRL(*this, "lstClasses", wxListBox);
81
TokensTree* tree = m_pParser->GetTokens();
82
for (size_t i = 0; i < tree->size(); ++i)
84
Token* token = tree->at(i);
85
//Manager::Get()->GetLogManager()->DebugLog("m_Filename=%s, token=%s", m_Filename.c_str(), token->m_Filename.c_str());
86
if (token && (token->m_TokenKind & (tkClass | tkTypedef))) //&&
87
//token->m_Filename == UnixFilename(m_Filename))
88
// TODO: check against file's pair too
89
lb->Append(token->m_Name, token);
95
void InsertClassMethodDlg::FillMethods()
97
if (!m_pParser || !m_pParser->Done())
100
wxListBox* lb = XRCCTRL(*this, "lstClasses", wxListBox);
101
wxCheckListBox* clb = XRCCTRL(*this, "chklstMethods", wxCheckListBox);
104
if (lb->GetSelection() == -1)
107
bool includePrivate = XRCCTRL(*this, "chkPrivate", wxCheckBox)->IsChecked();
108
bool includeProtected = XRCCTRL(*this, "chkProtected", wxCheckBox)->IsChecked();
109
bool includePublic = XRCCTRL(*this, "chkPublic", wxCheckBox)->IsChecked();
111
Token* parentToken = reinterpret_cast<Token*>(lb->GetClientData(lb->GetSelection()));
114
DoFillMethodsFor(clb,
116
parentToken ? parentToken->m_Name + _T("::") : _T(""),
123
void InsertClassMethodDlg::DoFillMethodsFor(wxCheckListBox* clb,
127
bool includeProtected,
132
TokensTree* tree = parentToken->GetTree();
135
//Manager::Get()->GetLogManager()->DebugLog("Fill methods for %s", parentToken->m_DisplayName.c_str());
137
// loop ascending the inheritance tree
139
for (TokenIdxSet::iterator it = parentToken->m_Children.begin(); it != parentToken->m_Children.end(); ++it)
142
Token* token = tree->at(idx);
146
//Manager::Get()->GetLogManager()->DebugLog("Evaluating %s", token->m_DisplayName.c_str());
147
bool valid = token->m_TokenKind & (tkFunction | tkConstructor | tkDestructor) &&
148
((includePrivate && token->m_Scope == tsPrivate) ||
149
(includeProtected && token->m_Scope == tsProtected) ||
150
(includePublic && token->m_Scope == tsPublic));
153
//Manager::Get()->GetLogManager()->DebugLog("Adding %s", token->m_DisplayName.c_str());
154
// BUG IN WXWIDGETS: wxCheckListBox::Append(string, data) crashes...
155
// wxCheckListBox::Append(string) does not...
157
str << token->m_Type << _T(" ") << ns << token->m_Name << token->m_Args;
158
str.Replace(_T("&"), _T("&&"));
159
if (clb->FindString(str) == wxNOT_FOUND)
165
for (TokenIdxSet::iterator it = parentToken->m_DirectAncestors.begin();it!=parentToken->m_DirectAncestors.end(); ++it)
168
Token* token = tree->at(idx);
171
DoFillMethodsFor(clb, token, ns, includePrivate, includeProtected, includePublic);
173
} // end of DoFillMethodsFor
177
void InsertClassMethodDlg::OnClassesChange(wxCommandEvent& /*event*/)
182
void InsertClassMethodDlg::OnCodeChange(wxCommandEvent& /*event*/)
184
m_Decl = XRCCTRL(*this, "rbCode", wxRadioBox)->GetSelection() == 0;
187
void InsertClassMethodDlg::OnFilterChange(wxCommandEvent& /*event*/)