~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to parts/quickopen/quickopenclassdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 2003 Roberto Raggi (roberto@kdevelop.org)
3
 
 *
4
 
 *  This program is free software; you can redistribute it and/or
5
 
 *  modify it under the terms of the GNU General Public
6
 
 *  License as published by the Free Software Foundation; either
7
 
 *  version 2 of the License, or (at your option) any later version.
8
 
 *
9
 
 *  This program is distributed in the hope that it will be useful,
10
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
 *  Library General Public License for more details.
13
 
 *
14
 
 *  You should have received a copy of the GNU General Public License
15
 
 *  along with this program; see the file COPYING.LIB.  If not, write to
16
 
 *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
 
 *  Boston, MA 02111-1307, USA.
18
 
 *
19
 
 */
20
 
 
21
 
#include <kdevproject.h>
22
 
#include <kdevpartcontroller.h>
23
 
#include <kdevlanguagesupport.h>
24
 
 
25
 
#include <klistbox.h>
26
 
#include <klocale.h>
27
 
#include <kdebug.h>
28
 
#include <kcompletion.h>
29
 
#include <klineedit.h>
30
 
 
31
 
#include <qregexp.h>
32
 
#include <qlabel.h>
33
 
 
34
 
#include "quickopenclassdialog.h"
35
 
#include "quickopen_part.h"
36
 
#include "quickopenfunctionchooseform.h"
37
 
 
38
 
QuickOpenClassDialog::QuickOpenClassDialog(QuickOpenPart* part, QWidget* parent, const char* name, bool modal, WFlags fl)
39
 
    : QuickOpenDialog( part, parent, name, modal, fl )
40
 
{
41
 
    nameLabel->setText( i18n("Class &name:") );
42
 
    itemListLabel->setText( i18n("Class &list:") );
43
 
 
44
 
    findAllClasses( m_items );
45
 
    QStringList_unique( m_items );
46
 
 
47
 
    nameEdit->setFocus();
48
 
 
49
 
    itemList->insertStringList( m_items );
50
 
    itemList->setCurrentItem(0);
51
 
}
52
 
 
53
 
QuickOpenClassDialog::~QuickOpenClassDialog()
54
 
{
55
 
}
56
 
 
57
 
void QuickOpenClassDialog::slotExecuted( QListBoxItem* /*item*/ )
58
 
{
59
 
    accept();
60
 
}
61
 
 
62
 
void QuickOpenClassDialog::accept()
63
 
{
64
 
    if( QListBoxItem* item = itemList->selectedItem() )
65
 
    {
66
 
        ClassList klasses = findClass( item->text() );
67
 
        if( klasses.count() == 1 )
68
 
        {
69
 
            ClassDom klass = klasses.first();
70
 
            int startLine, startColumn;
71
 
            klass->getStartPosition( &startLine, &startColumn );
72
 
            m_part->partController()->editDocument( KURL( klass->fileName() ), startLine );
73
 
            selectClassViewItem( ItemDom(&(*klass)) );
74
 
        }
75
 
        else if (klasses.count() > 1 )
76
 
        {
77
 
            //several classes with the same name found
78
 
            QString fileStr;
79
 
 
80
 
            QuickOpenFunctionChooseForm fdlg( this, "" );
81
 
            fdlg.setCaption(i18n("Select The Location of Class %1").arg(klasses.first()->name()));
82
 
            fdlg.textLabel2->setText(i18n("Class name:"));
83
 
 
84
 
            for( ClassList::const_iterator it = klasses.constBegin(); it != klasses.constEnd() ; ++it )
85
 
            {
86
 
                ClassDom klass = *it;
87
 
                //assemble class name to display (maybe with scope info and specialization)
88
 
                QString classStr = m_part->languageSupport()->formatModelItem(klass);
89
 
                if(klass->hasSpecializationDeclaration())
90
 
                  classStr += klass->getSpecializationDeclaration();
91
 
                if(!klass->scope().isEmpty())
92
 
                  classStr += "   (in " + klass->scope().join("::") + ")";
93
 
                fdlg.argBox->insertItem(classStr);
94
 
 
95
 
                fileStr = KURL( klass->fileName() ).fileName();
96
 
                KURL full_url( klass->fileName() );
97
 
                KURL base_url( m_part->project()->projectDirectory()+"/" );
98
 
                fdlg.fileBox->insertItem(fileStr);
99
 
                fdlg.setRelativePath(fdlg.fileBox->count()-1,
100
 
                    KURL::relativeURL( base_url, full_url ));
101
 
            }
102
 
            if( fdlg.exec() ){
103
 
                int id = fdlg.argBox->currentItem();
104
 
                if( id>-1 && id < (int) klasses.count() ){
105
 
                    ClassDom model = klasses[id];
106
 
                    int line, col;
107
 
                    model->getStartPosition( &line, &col );
108
 
                    selectClassViewItem( ItemDom(&(*model)) );
109
 
                    QString fileNameStr = model->fileName();
110
 
                    m_part->partController()->editDocument( KURL(fileNameStr), line );
111
 
                }
112
 
            }
113
 
        }
114
 
    }
115
 
 
116
 
    QDialog::accept();
117
 
}
118
 
 
119
 
void QuickOpenClassDialog::slotReturnPressed( )
120
 
{
121
 
    maybeUpdateSelection();
122
 
    accept();
123
 
}
124
 
 
125
 
void QuickOpenClassDialog::findAllClasses( QStringList& lst )
126
 
{
127
 
    findAllClasses( lst, m_part->codeModel()->globalNamespace() );
128
 
}
129
 
 
130
 
void QuickOpenClassDialog::findAllClasses( QStringList& lst, const ClassDom klass )
131
 
{
132
 
    QStringList fullName = klass->scope();
133
 
    fullName << klass->name();
134
 
    lst << fullName.join( "::" );
135
 
 
136
 
    const ClassList classList = klass->classList();
137
 
    for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
138
 
        findAllClasses( lst, *it );
139
 
}
140
 
 
141
 
void QuickOpenClassDialog::findAllClasses( QStringList& lst, const NamespaceDom ns )
142
 
{
143
 
    const NamespaceList namespaceList = ns->namespaceList();
144
 
    for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
145
 
        findAllClasses( lst, *it );
146
 
 
147
 
    const ClassList classList = ns->classList();
148
 
    for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
149
 
        findAllClasses( lst, *it );
150
 
}
151
 
 
152
 
ClassList QuickOpenClassDialog::findClass( const QString& name )
153
 
{
154
 
    QStringList path = QStringList::split( "::", name );
155
 
    return findClass( path, m_part->codeModel()->globalNamespace() );
156
 
}
157
 
 
158
 
ClassList QuickOpenClassDialog::findClass( QStringList& path, const NamespaceDom ns )
159
 
{
160
 
    ClassList list;
161
 
    if( path.isEmpty() )
162
 
        return list;
163
 
 
164
 
    QString current = path.front();
165
 
    if( ns->hasNamespace(current) )
166
 
    {
167
 
        path.pop_front();
168
 
        list += findClass( path, ns->namespaceByName(current) );
169
 
        path.push_front( current );
170
 
    }
171
 
 
172
 
    if( ns->hasClass(current) )
173
 
    {
174
 
        path.pop_front();
175
 
        list += findClass( path, ns->classByName(current) );
176
 
    }
177
 
 
178
 
    return list;
179
 
}
180
 
 
181
 
ClassList QuickOpenClassDialog::findClass( QStringList& path, const ClassList klasses )
182
 
{
183
 
    ClassList list;
184
 
    if( path.isEmpty() )
185
 
    {
186
 
        list += klasses;
187
 
        return list;
188
 
    }
189
 
 
190
 
    for (ClassList::const_iterator it = klasses.constBegin(); it != klasses.constEnd(); ++it)
191
 
    {
192
 
        list += findClass(path, *it);
193
 
    }
194
 
 
195
 
    return list;
196
 
}
197
 
 
198
 
ClassList QuickOpenClassDialog::findClass( QStringList &path, const ClassDom klass )
199
 
{
200
 
    ClassList list;
201
 
    if( path.isEmpty() )
202
 
    {
203
 
        list << klass;
204
 
        return list;
205
 
    }
206
 
 
207
 
    QString current = path.front();
208
 
    if( klass->hasClass(current) )
209
 
    {
210
 
        path.pop_front();
211
 
        list += findClass( path, klass->classByName(current) );
212
 
        path.push_front(current);
213
 
    }
214
 
 
215
 
    return list;
216
 
}
217
 
 
218
 
#include "quickopenclassdialog.moc"
219