~ubuntu-branches/ubuntu/maverick/codelite/maverick

« back to all changes in this revision

Viewing changes to CodeLite/cl_calltip.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-02-10 02:27:55 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090210022755-m5692nfc1t5uf1w9
Tags: 1.0.2759+dfsg-0ubuntu1
* New upstream release (LP: #327216).
* debian/patches/series, debian/patches/00_fix-ia64-build.patch:
  + Dropped, applied upstream already.
* debian/patches/02_fix-desktop.patch,
  debian/patches/03_fix-sh.patch:
  + Refreshed to patch cleanly.
* debian/rules:
  + Make get-orig-source honour UPSTREAM_VERSION if set.
* debian/ctags-le.1,
  debian/codelite_indexer.1,
  debian/codelite.manpages:
  + Dropped ctags-le manpage, since ctags-le was replaced by
    codelite_indexer.
  + Added codelite_indexer manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
struct tagCallTipInfo {
37
37
        wxString sig;
38
38
        wxString retValue;
 
39
        std::vector<std::pair<int, int> > paramLen;
39
40
};
40
41
 
41
42
clCallTip::clCallTip(const std::vector<TagEntryPtr> &tips)
42
 
                : m_tips(tips)
43
 
                , m_curr(0)
 
43
                : m_curr(0)
44
44
{
 
45
        Initialize(tips);
45
46
}
46
47
 
47
48
clCallTip::clCallTip(const clCallTip& rhs)
68
69
wxString clCallTip::TipAt(int at)
69
70
{
70
71
        wxString tip;
71
 
        if ( m_tips.size() > 1 )
72
 
                tip << _T("\n\001 ") << static_cast<int>(m_curr)+1 << _T(" of ") << static_cast<int>(m_tips.size()) << _T(" \002 ")
73
 
                << m_tips.at(at) << _T("\n");
74
 
        else
75
 
                tip << _T("\n") << m_tips.at( 0 ) << _T("\n");
 
72
        if ( m_tips.size() > 1 ) {
 
73
                tip << _T("\001 ") << static_cast<int>(m_curr)+1 << _T(" of ") << static_cast<int>(m_tips.size()) << _T(" \002 ") << m_tips.at(at).str ;
 
74
        } else {
 
75
                tip << m_tips.at( 0 ).str;
 
76
        }
76
77
        return tip;
77
78
}
78
79
 
105
106
        return TipAt(m_curr);
106
107
}
107
108
 
 
109
wxString clCallTip::All()
 
110
{
 
111
        wxString tip;
 
112
        for (size_t i=0; i<m_tips.size(); i++) {
 
113
                tip << m_tips.at(i).str << wxT("\n");
 
114
        }
 
115
        tip.RemoveLast();
 
116
        return tip;
 
117
}
 
118
 
108
119
int clCallTip::Count() const
109
120
{
110
121
        return (int)m_tips.size();
111
122
}
112
123
 
113
 
wxString clCallTip::All()
 
124
void clCallTip::Initialize(const std::vector<TagEntryPtr> &tips)
114
125
{
115
 
        wxString tip;
116
126
        std::map<wxString, tagCallTipInfo> mymap;
117
 
        for (size_t i=0; i< m_tips.size(); i++) {
 
127
        for (size_t i=0; i< tips.size(); i++) {
118
128
                tagCallTipInfo cti;
119
 
                TagEntryPtr t = m_tips.at(i);
 
129
                TagEntryPtr t = tips.at(i);
120
130
                if (t->GetKind() == wxT("function") || t->GetKind() == wxT("prototype")) {
121
131
 
122
132
                        wxString raw_sig ( t->GetSignature().Trim().Trim(false) );
123
133
 
124
134
                        // evaluate the return value of the tag
125
 
                        clFunction foo;
126
 
                        if (LanguageST::Get()->FunctionFromPattern(t->GetPattern(), foo)) {
127
 
                                if (foo.m_retrunValusConst.empty() == false) {
128
 
                                        cti.retValue << _U(foo.m_retrunValusConst.c_str()) << wxT(" ");
129
 
                                }
130
 
 
131
 
                                if (foo.m_returnValue.m_typeScope.empty() == false) {
132
 
                                        cti.retValue << _U(foo.m_returnValue.m_typeScope.c_str()) << wxT("::");
133
 
                                }
134
 
 
135
 
                                if (foo.m_returnValue.m_type.empty() == false) {
136
 
                                        cti.retValue << _U(foo.m_returnValue.m_type.c_str());
137
 
                                        if (foo.m_returnValue.m_templateDecl.empty() == false) {
138
 
                                                cti.retValue << wxT("<") << _U(foo.m_returnValue.m_templateDecl.c_str()) << wxT(">");
139
 
                                        }
140
 
                                        cti.retValue << _U(foo.m_returnValue.m_starAmp.c_str());
141
 
                                        cti.retValue << wxT(" ");
142
 
                                }
143
 
                        }
 
135
                        cti.retValue = TagsManagerST::Get()->GetFunctionReturnValueFromPattern(t->GetPattern());
144
136
 
145
137
                        bool hasDefaultValues = (raw_sig.Find(wxT("=")) != wxNOT_FOUND);
146
 
                        wxString  normalizedSig = TagsManagerST::Get()->NormalizeFunctionSig(raw_sig);
147
 
                        cti.sig = normalizedSig;
 
138
 
 
139
                        // the key for unique entries is the function prototype without the variables names and
 
140
                        // any default values
 
141
                        wxString  key           = TagsManagerST::Get()->NormalizeFunctionSig(raw_sig, 0);
 
142
 
 
143
                        // the signature that we want to keep is one with name & default values, so try and get the maximum out of the
 
144
                        // function signature
 
145
                        wxString  full_signature = TagsManagerST::Get()->NormalizeFunctionSig(raw_sig, Normalize_Func_Name | Normalize_Func_Default_value, &cti.paramLen);
 
146
                        cti.sig                  = full_signature;
148
147
 
149
148
                        if (hasDefaultValues) {
150
 
                                //incase default values exist in this prototype,
151
 
                                //make it the tip instead of the existing one
152
 
                                cti.sig = raw_sig;
153
 
                                mymap[normalizedSig] = cti;
 
149
                                // incase default values exist in this prototype,
 
150
                                // update/insert this signature
 
151
                                mymap[key] = cti;
154
152
                        }
155
153
 
156
 
                        //make sure we dont add duplicates
157
 
                        if ( mymap.find(normalizedSig) == mymap.end() ) {
158
 
                                //add it
159
 
                                cti.sig = TagsManagerST::Get()->NormalizeFunctionSig(raw_sig, true);
160
 
                                mymap[normalizedSig] = cti;
 
154
                        // make sure we dont add duplicates
 
155
                        if ( mymap.find(key) == mymap.end() ) {
 
156
                                // add it
 
157
                                mymap[key] = cti;
161
158
                        }
162
159
 
163
160
                } else {
182
179
        }
183
180
 
184
181
        std::map<wxString, tagCallTipInfo>::iterator iter = mymap.begin();
185
 
        for ( ; iter != mymap.end(); iter++ ) {
186
 
                if( iter->second.retValue.empty() == false ) {
 
182
        m_tips.clear();
 
183
        for (; iter != mymap.end(); iter++) {
 
184
                wxString tip;
 
185
                if ( iter->second.retValue.empty() == false ) {
187
186
                        tip <<  iter->second.retValue.Trim(false).Trim() << wxT(" : ");
188
187
                }
189
 
                tip << iter->second.sig << wxT("\n");
190
 
        }
191
 
        tip = tip.BeforeLast(wxT('\n'));
192
 
        return tip;
 
188
                tip << iter->second.sig;
 
189
                clTipInfo ti;
 
190
                ti.paramLen = iter->second.paramLen;
 
191
                ti.str = tip;
 
192
                m_tips.push_back(ti);
 
193
        }
 
194
}
 
195
 
 
196
void clCallTip::GetHighlightPos(int index, int& start, int& len)
 
197
{
 
198
        start = wxNOT_FOUND;
 
199
        len = wxNOT_FOUND;
 
200
        if (m_curr >= 0 && m_curr < (int)m_tips.size()) {
 
201
                clTipInfo ti = m_tips.at(m_curr);
 
202
                int base = ti.str.Find(wxT("("));
 
203
 
 
204
                if (m_tips.size() > 1) {
 
205
                        // multiple tooltips exists, make sure we calculate the up and down arrows
 
206
                        wxString arrowsStr;
 
207
                        arrowsStr << _T("\001 ") << static_cast<int>(m_curr)+1 << _T(" of ") << static_cast<int>(m_tips.size()) << _T(" \002 ");
 
208
                        base += arrowsStr.Length();
 
209
                }
 
210
 
 
211
                // sanity
 
212
                if (base != wxNOT_FOUND && index < (int)ti.paramLen.size() && index >= 0) {
 
213
                        start = ti.paramLen.at(index).first + base;
 
214
                        len =  ti.paramLen.at(index).second;
 
215
                }
 
216
        }
193
217
}