~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/FortranProject/docblock.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "docblock.h"
 
2
#include "cbcolourmanager.h"
 
3
 
 
4
#include <iostream>
 
5
 
 
6
DocBlock::DocBlock():
 
7
    m_Description(_T("**description**")),
 
8
    m_Brief(_T("**brief**"))
 
9
{
 
10
    //ctor
 
11
}
 
12
 
 
13
DocBlock::~DocBlock()
 
14
{
 
15
    //dtor
 
16
}
 
17
 
 
18
wxString DocBlock::GetDescription()
 
19
{
 
20
    if (m_DocMap.count(m_Description) == 1)
 
21
        return m_DocMap[m_Description];
 
22
 
 
23
    return wxEmptyString;
 
24
}
 
25
 
 
26
bool DocBlock::HasDescription()
 
27
{
 
28
    return (m_DocMap.count(m_Description) == 1);
 
29
}
 
30
 
 
31
void DocBlock::AddDescription(const wxString &descr)
 
32
{
 
33
    m_DocMap[m_Description] = descr;
 
34
}
 
35
 
 
36
wxString DocBlock::GetBrief()
 
37
{
 
38
    if (m_DocMap.count(m_Brief) == 1)
 
39
        return m_DocMap[m_Brief];
 
40
 
 
41
    return wxEmptyString;
 
42
}
 
43
 
 
44
bool DocBlock::HasBrief()
 
45
{
 
46
    return (m_DocMap.count(m_Brief) == 1);
 
47
}
 
48
 
 
49
int DocBlock::GetParamCount()
 
50
{
 
51
    int pc = 0;
 
52
    for (std::map<wxString,wxString>::iterator it = m_DocMap.begin(); it != m_DocMap.end(); ++it)
 
53
    {
 
54
        if (!it->first.IsSameAs(m_Description) && !it->first.IsSameAs(m_Brief))
 
55
            pc++;
 
56
    }
 
57
    return pc;
 
58
}
 
59
 
 
60
wxString DocBlock::GetValue(wxString& key)
 
61
{
 
62
    if (m_DocMap.count(key) == 1)
 
63
        return m_DocMap[key];
 
64
 
 
65
    return wxEmptyString;
 
66
}
 
67
 
 
68
void DocBlock::AddBrief(const wxString &bline)
 
69
{
 
70
    m_DocMap[_T("**brief**")] = bline;
 
71
}
 
72
 
 
73
void DocBlock::AddParam(const wxString &name, const wxString &descr)
 
74
{
 
75
    m_DocMap[name.Lower()] = descr;
 
76
}
 
77
 
 
78
void DocBlock::Clear()
 
79
{
 
80
    m_DocMap.clear();
 
81
}
 
82
 
 
83
//*****************************************
 
84
namespace HTMLTags
 
85
{
 
86
    static const wxString br = _T("<br>");
 
87
    static const wxString sep = _T(" ");
 
88
    static const wxString b1 = _T("<b>");
 
89
    static const wxString b0 = _T("</b>");
 
90
 
 
91
    static const wxString a1 = _T("<a>");
 
92
    static const wxString a0 = _T("</a>");
 
93
 
 
94
    static const wxString i1 = _T("<i>");
 
95
    static const wxString i0 = _T("</i>");
 
96
 
 
97
    static const wxString pre1 = _T("<pre>");
 
98
    static const wxString pre0 = _T("</pre>");
 
99
 
 
100
    static const wxString nbsp(_T("&nbsp;"));
 
101
    static const wxString tab = nbsp + nbsp + nbsp;
 
102
 
 
103
    static const wxString commandTag = _T("cmd=");
 
104
}
 
105
 
 
106
wxString HtmlDoc::GenerateHtmlDoc(TokenFlat* token, int token_idx, bool& hasDoc)
 
107
{
 
108
    //http://docs.wxwidgets.org/2.8/wx_wxhtml.html#htmltagssupported
 
109
    using namespace HTMLTags;
 
110
 
 
111
    ColourManager *colours = Manager::Get()->GetColourManager();
 
112
 
 
113
    wxString html = _T("<html><body bgcolor=\"");
 
114
    html += colours->GetColour(wxT("cc_docs_back")).GetAsString(wxC2S_HTML_SYNTAX) + _T("\" text=\"");
 
115
    html += colours->GetColour(wxT("cc_docs_fore")).GetAsString(wxC2S_HTML_SYNTAX) + _T("\" link=\"");
 
116
    html += colours->GetColour(wxT("cc_docs_link")).GetAsString(wxC2S_HTML_SYNTAX) + _T("\">");
 
117
 
 
118
    html += _T("<a name=\"top\"></a>");
 
119
 
 
120
    hasDoc = false;
 
121
    if (!token || token->m_DisplayName.IsEmpty())
 
122
        return wxEmptyString;
 
123
 
 
124
    // add parent:
 
125
    if (!token->m_ParentDisplayName.IsEmpty())
 
126
    {
 
127
        wxString parent;
 
128
        if (token->m_ParentTokenKind == tkModule)
 
129
            html += _T("module: ") + b1 + token->m_ParentDisplayName + b0 + br;
 
130
    }
 
131
 
 
132
    html += br;
 
133
    wxString moreInfo;
 
134
 
 
135
    //add scope and name:
 
136
    switch (token->m_TokenKind)
 
137
    {
 
138
    case tkFunction:
 
139
        html += token->m_PartFirst + _T(" function ") + b1 + token->m_DisplayName + b0;
 
140
        html += token->m_Args;
 
141
        html += sep + token->m_PartLast;
 
142
        html += br;
 
143
        break;
 
144
 
 
145
    case tkSubroutine:
 
146
        html += _T("subroutine ") + b1 + token->m_DisplayName + b0;
 
147
        html += sep + token->m_Args;
 
148
        html += br;
 
149
        if (token->m_ParentTokenKind == tkFile)
 
150
            moreInfo = _T("global");
 
151
        else if (token->m_TokenAccess == taPrivate)
 
152
            moreInfo = _T("private");
 
153
        break;
 
154
 
 
155
    case tkVariable:
 
156
        html += token->m_TypeDefinition + _T(" :: ") + b1 + token->m_DisplayName + b0 + token->m_Args + br;
 
157
        moreInfo = token->GetTokenKindString();
 
158
        break;
 
159
 
 
160
    case tkInterface:
 
161
        html += token->m_TypeDefinition + nbsp + b1 + token->m_DisplayName + b0 + br;
 
162
        if (token->m_TypeDefinition.IsEmpty())
 
163
            moreInfo = _T("interface");
 
164
        else
 
165
            moreInfo = _T("generic interface");
 
166
        break;
 
167
 
 
168
    default:
 
169
        html += b1 + token->m_DisplayName + b0 + br;
 
170
        moreInfo = token->GetTokenKindString();
 
171
    }
 
172
 
 
173
    //add kind:
 
174
    if (!moreInfo.IsEmpty())
 
175
        html += i1 + _T("<font color=\"green\" size=3>") + _T("(") +
 
176
                moreInfo +_T(")") + _T("</font>") + i0 + br;
 
177
 
 
178
    if (!token->m_DocString.IsEmpty())
 
179
    {
 
180
        const wxString brsep = _T("@brief_end@");
 
181
        size_t brf = token->m_DocString.find(brsep);
 
182
        size_t bre_idx = 11;
 
183
        if (brf != wxString::npos)
 
184
            bre_idx += brf;
 
185
        else
 
186
            bre_idx = 0;
 
187
 
 
188
        if (bre_idx > 11)
 
189
        {
 
190
            html += br + i1 + b1 + _T("Brief:") + b0 + i0 + br;
 
191
            html += tab + token->m_DocString.substr(0,brf) + br;
 
192
            hasDoc = true;
 
193
        }
 
194
 
 
195
        if (bre_idx < token->m_DocString.size())
 
196
        {
 
197
            html += br + i1 + b1 + _T("Description:") + b0 + i0 + br;
 
198
            html += tab + token->m_DocString.substr(bre_idx) + br;
 
199
            hasDoc = true;
 
200
        }
 
201
    }
 
202
 
 
203
    //add go to declaration
 
204
    html += br + br + _T("<a href=\"") + commandTag + _T("goto") + wxString::Format(_T("%i"), token_idx)
 
205
               + _T("\">") +  _T("Open declaration") + _T("</a>") + br + br;
 
206
 
 
207
    // Append 'close' link:
 
208
    html += _T("<a href=\"") + commandTag + _T("close")
 
209
               + _T("\">") +  _T("close") + _T("</a>"),
 
210
 
 
211
    html += _T("</body></html>");
 
212
 
 
213
    return html;
 
214
}
 
215
 
 
216
 
 
217
wxString HtmlDoc::OnDocumentationLink(wxHtmlLinkEvent &event, bool &dismissPopup, bool &isGoto, long int &tokenIdx)
 
218
{
 
219
    using namespace HTMLTags;
 
220
 
 
221
    const wxString& href = event.GetLinkInfo().GetHref();
 
222
    wxString args;
 
223
    wxString tidx_str;
 
224
 
 
225
    dismissPopup = false;
 
226
    isGoto = false;
 
227
 
 
228
    if (!href.StartsWith(commandTag, &args))
 
229
        return wxEmptyString;
 
230
 
 
231
    if (args.StartsWith(_T("goto"), &tidx_str))
 
232
    {
 
233
        if(tidx_str.ToLong(&tokenIdx))
 
234
        {
 
235
            dismissPopup = true;
 
236
            isGoto = true;
 
237
        }
 
238
    }
 
239
    else if (args.StartsWith(_T("close")))
 
240
        dismissPopup = true;
 
241
 
 
242
    return wxEmptyString;
 
243
}
 
244
 
 
245
wxString HtmlDoc::GetDocForTooltip(TokenFlat* token)
 
246
{
 
247
    return HtmlDoc::GetDocShort(token->m_DocString);
 
248
}
 
249
 
 
250
wxString HtmlDoc::GetDocShort(const wxString& tokDoc)
 
251
{
 
252
    wxString doc;
 
253
    if (!tokDoc.IsEmpty())
 
254
    {
 
255
        const wxString brsep = _T("@brief_end@");
 
256
        size_t brf = tokDoc.find(brsep);
 
257
        size_t bre_idx = 11;
 
258
        if (brf != wxString::npos)
 
259
            bre_idx += brf;
 
260
        else
 
261
            bre_idx = 0;
 
262
 
 
263
        if (bre_idx > 11)
 
264
        {
 
265
            doc = tokDoc.substr(0,brf);
 
266
        }
 
267
        else if (bre_idx < tokDoc.size())
 
268
        {
 
269
            doc = tokDoc.substr(bre_idx);
 
270
            if (doc.size() > 80) // limit length of doc
 
271
                doc = doc.substr(0,80) + _T("...");
 
272
        }
 
273
    }
 
274
    return doc;
 
275
}
 
276
 
 
277