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
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2008 by Eran Ifrah
// file name : renamesymboldlg.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.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "renamesymboldlg.h"
#include "globals.h"
RenameSymbol::RenameSymbol( wxWindow* parent, const std::list<CppToken>& candidates, const std::list<CppToken> &possCandidates, const wxString& oldname/* = wxT("")*/ )
:
RenameSymbolBase( parent )
{
m_preview->SetReadOnly(true);
m_tokens.clear();
std::list<CppToken>::const_iterator iter = candidates.begin();
for (; iter != candidates.end(); iter++) {
AddMatch(*iter, true);
m_tokens.push_back(*iter);
}
iter = possCandidates.begin();
for (; iter != possCandidates.end(); iter++) {
AddMatch(*iter, false);
m_tokens.push_back(*iter);
}
if (m_tokens.empty() == false) {
DoSelectFile(m_tokens.at((size_t)0));
}
m_textCtrlNewName->SetValue(oldname);
m_textCtrlNewName->SetFocus();
}
void RenameSymbol::OnItemSelected( wxCommandEvent& event )
{
int index = event.GetSelection();
if ( index != wxNOT_FOUND ) {
DoSelectFile(m_tokens.at((size_t)index));
}
}
void RenameSymbol::OnItemDClicked( wxCommandEvent& event )
{
wxUnusedVar(event);
}
void RenameSymbol::OnItemChecked( wxCommandEvent& event )
{
event.Skip();
}
void RenameSymbol::AddMatch(const CppToken& token, bool check)
{
wxString msg;
wxFileName fn(token.getFilename());
msg << token.getLine() << wxT(": At ") << fn.GetFullName() << wxString::Format( wxT(" line %u"), token.getLineNo() );
msg.Replace(wxT("\r\n"), wxT(" "));
msg.Replace(wxT("\n"), wxT(" "));
msg = msg.Trim().Trim(false);
int index = m_checkListCandidates->Append(msg);//, new CppToken(token));
m_checkListCandidates->Check((unsigned int)index, check);
m_checkListCandidates->Select(0);
}
void RenameSymbol::OnButtonOK(wxCommandEvent& e)
{
wxUnusedVar(e);
if(!IsValidCppIndetifier(m_textCtrlNewName->GetValue())){
wxMessageBox(_("Invalid C/C++ symbol name"), wxT("CodeLite"), wxICON_WARNING|wxOK);
return;
}
EndModal(wxID_OK);
}
void RenameSymbol::GetMatches(std::list<CppToken>& matches)
{
for (unsigned int i=0; i<m_checkListCandidates->GetCount(); i++) {
if (m_checkListCandidates->IsChecked(i)) {
matches.push_back(m_tokens.at(i));
}
}
}
void RenameSymbol::DoSelectFile(const CppToken& token)
{
m_preview->SetReadOnly(false);
m_preview->Create(wxEmptyString, token.getFilename());
m_preview->SetCaretAt(token.getOffset());
m_preview->SetSelection(token.getOffset(), token.getOffset()+token.getName().Len());
m_preview->SetReadOnly(true);
}
|