~ubuntu-branches/ubuntu/intrepid/kdesdk/intrepid-updates

« back to all changes in this revision

Viewing changes to kate/plugins/symbolviewer/perl_parser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-28 10:11:43 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20080528101143-gzc3styjz1b70zxu
Tags: upstream-4.0.80
ImportĀ upstreamĀ versionĀ 4.0.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          perl_parser.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Apr 2 2003
 
5
    author               : 2003 Massimo Callegari
 
6
    email                : massimocallegari@yahoo.it
 
7
 ***************************************************************************/
 
8
 /***************************************************************************
 
9
 *                                                                         *
 
10
 *   This program is free software; you can redistribute it and/or modify  *
 
11
 *   it under the terms of the GNU General Public License as published by  *
 
12
 *   the Free Software Foundation; either version 2 of the License, or     *
 
13
 *   (at your option) any later version.                                   *
 
14
 *                                                                         *
 
15
 ***************************************************************************/
 
16
#include "plugin_katesymbolviewer.h"
 
17
 
 
18
void KatePluginSymbolViewerView::parsePerlSymbols(void)
 
19
{
 
20
 if (!win->activeView())
 
21
   return;
 
22
 
 
23
 popup->changeItem( popup->idAt(2),i18n("Show Uses"));
 
24
 popup->changeItem( popup->idAt(3),i18n("Show Pragmas"));
 
25
 popup->changeItem( popup->idAt(4),i18n("Show Subroutines"));
 
26
 QString cl; // Current Line
 
27
 QString stripped;
 
28
 char comment = 0;
 
29
 QPixmap cls( ( const char** ) class_xpm );
 
30
 QPixmap sct( ( const char** ) struct_xpm );
 
31
 QPixmap mcr( ( const char** ) macro_xpm );
 
32
 QPixmap cls_int( ( const char** ) class_int_xpm );
 
33
 QTreeWidgetItem *node = NULL;
 
34
 QTreeWidgetItem *mcrNode = NULL, *sctNode = NULL, *clsNode = NULL;
 
35
 QTreeWidgetItem *lastMcrNode = NULL, *lastSctNode = NULL, *lastClsNode = NULL;
 
36
 
 
37
 KTextEditor::Document *kv = win->activeView()->document();
 
38
 
 
39
     //kdDebug(13000)<<"Lines counted :"<<kv->numLines()<<endl;
 
40
 if(treeMode)
 
41
   {
 
42
    mcrNode = new QTreeWidgetItem(symbols, QStringList( i18n("Uses") ) );
 
43
    sctNode = new QTreeWidgetItem(symbols, QStringList( i18n("Pragmas") ) );
 
44
    clsNode = new QTreeWidgetItem(symbols, QStringList( i18n("Subroutines") ) );
 
45
    mcrNode->setIcon(0, QIcon(mcr));
 
46
    sctNode->setIcon(0, QIcon(sct));
 
47
    clsNode->setIcon(0, QIcon(cls));
 
48
 
 
49
    if (expanded_on)
 
50
      {
 
51
       symbols->expandItem(mcrNode);
 
52
       symbols->expandItem(sctNode);
 
53
       symbols->expandItem(clsNode);
 
54
      }
 
55
    lastMcrNode = mcrNode;
 
56
    lastSctNode = sctNode;
 
57
    lastClsNode = clsNode;
 
58
    symbols->setRootIsDecorated(1);
 
59
   }
 
60
 else
 
61
    symbols->setRootIsDecorated(0);
 
62
 
 
63
 for (int i=0; i<kv->lines(); i++)
 
64
   {
 
65
    cl = kv->line(i);
 
66
    cl = cl.trimmed();
 
67
 
 
68
    kDebug(13000)<<"Line " << i << " : "<< cl;
 
69
 
 
70
    if(cl == "" || cl.at(0) == '#') continue;
 
71
    if(cl.indexOf(QRegExp("^=")) >= 0) comment = 1;
 
72
    if(cl.indexOf(QRegExp("^=cut$")) >= 0)
 
73
       {
 
74
        comment = 0;
 
75
        continue;
 
76
       }
 
77
    if (comment==1)
 
78
        continue;
 
79
 
 
80
    if(cl.indexOf(QRegExp("^use +[A-Z]")) == 0 && macro_on)
 
81
      {
 
82
       QString stripped=cl.replace( QRegExp("^use +"), "" );
 
83
       //stripped=stripped.replace( QRegExp(";$"), "" ); // Doesn't work ??
 
84
       stripped = stripped.left(stripped.indexOf(';'));
 
85
       if (treeMode)
 
86
         {
 
87
          node = new QTreeWidgetItem(mcrNode, lastMcrNode);
 
88
          lastMcrNode = node;
 
89
         }
 
90
       else
 
91
          node = new QTreeWidgetItem(symbols);
 
92
 
 
93
       node->setText(0, stripped);
 
94
       node->setIcon(0, QIcon(mcr));
 
95
       node->setText(1, QString::number( i, 10));
 
96
      }
 
97
#if 1
 
98
    if(cl.indexOf(QRegExp("^use +[a-z]")) == 0 && struct_on)
 
99
      {
 
100
       QString stripped=cl.replace( QRegExp("^use +"), "" );
 
101
       stripped=stripped.replace( QRegExp(";$"), "" );
 
102
       if (treeMode)
 
103
         {
 
104
          node = new QTreeWidgetItem(sctNode, lastSctNode);
 
105
          lastMcrNode = node;
 
106
         }
 
107
       else
 
108
          node = new QTreeWidgetItem(symbols);
 
109
 
 
110
       node->setText(0, stripped);
 
111
       node->setIcon(0, QIcon(sct));
 
112
       node->setText(1, QString::number( i, 10));
 
113
      }
 
114
#endif
 
115
#if 1
 
116
    if(cl.indexOf(QRegExp("^sub +"))==0 && func_on)
 
117
      {
 
118
       QString stripped=cl.replace( QRegExp("^sub +"), "" );
 
119
       stripped=stripped.replace( QRegExp("[{;] *$"), "" );
 
120
       if (treeMode)
 
121
         {
 
122
          node = new QTreeWidgetItem(clsNode, lastClsNode);
 
123
          lastClsNode = node;
 
124
         }
 
125
       else
 
126
          node = new QTreeWidgetItem(symbols);
 
127
        node->setText(0, stripped);
 
128
 
 
129
        if (stripped.at(0)=='_')
 
130
             node->setIcon(0, QIcon(cls_int));
 
131
        else
 
132
             node->setIcon(0, QIcon(cls));
 
133
 
 
134
        node->setText(1, QString::number( i, 10));
 
135
       }
 
136
#endif
 
137
   }
 
138
}
 
139
 
 
140
 
 
141