2
* Copyright (C) 2003 Roberto Raggi (roberto@kdevelop.org)
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.
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.
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.
21
#include <kdevproject.h>
22
#include <kdevpartcontroller.h>
23
#include <kdevlanguagesupport.h>
28
#include <kcompletion.h>
29
#include <klineedit.h>
34
#include "quickopenclassdialog.h"
35
#include "quickopen_part.h"
36
#include "quickopenfunctionchooseform.h"
38
QuickOpenClassDialog::QuickOpenClassDialog(QuickOpenPart* part, QWidget* parent, const char* name, bool modal, WFlags fl)
39
: QuickOpenDialog( part, parent, name, modal, fl )
41
nameLabel->setText( i18n("Class &name:") );
42
itemListLabel->setText( i18n("Class &list:") );
44
findAllClasses( m_items );
45
QStringList_unique( m_items );
49
itemList->insertStringList( m_items );
50
itemList->setCurrentItem(0);
53
QuickOpenClassDialog::~QuickOpenClassDialog()
57
void QuickOpenClassDialog::slotExecuted( QListBoxItem* /*item*/ )
62
void QuickOpenClassDialog::accept()
64
if( QListBoxItem* item = itemList->selectedItem() )
66
ClassList klasses = findClass( item->text() );
67
if( klasses.count() == 1 )
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)) );
75
else if (klasses.count() > 1 )
77
//several classes with the same name found
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:"));
84
for( ClassList::const_iterator it = klasses.constBegin(); it != klasses.constEnd() ; ++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);
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 ));
103
int id = fdlg.argBox->currentItem();
104
if( id>-1 && id < (int) klasses.count() ){
105
ClassDom model = klasses[id];
107
model->getStartPosition( &line, &col );
108
selectClassViewItem( ItemDom(&(*model)) );
109
QString fileNameStr = model->fileName();
110
m_part->partController()->editDocument( KURL(fileNameStr), line );
119
void QuickOpenClassDialog::slotReturnPressed( )
121
maybeUpdateSelection();
125
void QuickOpenClassDialog::findAllClasses( QStringList& lst )
127
findAllClasses( lst, m_part->codeModel()->globalNamespace() );
130
void QuickOpenClassDialog::findAllClasses( QStringList& lst, const ClassDom klass )
132
QStringList fullName = klass->scope();
133
fullName << klass->name();
134
lst << fullName.join( "::" );
136
const ClassList classList = klass->classList();
137
for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
138
findAllClasses( lst, *it );
141
void QuickOpenClassDialog::findAllClasses( QStringList& lst, const NamespaceDom ns )
143
const NamespaceList namespaceList = ns->namespaceList();
144
for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
145
findAllClasses( lst, *it );
147
const ClassList classList = ns->classList();
148
for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
149
findAllClasses( lst, *it );
152
ClassList QuickOpenClassDialog::findClass( const QString& name )
154
QStringList path = QStringList::split( "::", name );
155
return findClass( path, m_part->codeModel()->globalNamespace() );
158
ClassList QuickOpenClassDialog::findClass( QStringList& path, const NamespaceDom ns )
164
QString current = path.front();
165
if( ns->hasNamespace(current) )
168
list += findClass( path, ns->namespaceByName(current) );
169
path.push_front( current );
172
if( ns->hasClass(current) )
175
list += findClass( path, ns->classByName(current) );
181
ClassList QuickOpenClassDialog::findClass( QStringList& path, const ClassList klasses )
190
for (ClassList::const_iterator it = klasses.constBegin(); it != klasses.constEnd(); ++it)
192
list += findClass(path, *it);
198
ClassList QuickOpenClassDialog::findClass( QStringList &path, const ClassDom klass )
207
QString current = path.front();
208
if( klass->hasClass(current) )
211
list += findClass( path, klass->classByName(current) );
212
path.push_front(current);
218
#include "quickopenclassdialog.moc"