KDevelop API Documentation

quickopenfunctiondialog.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004 Ahn, Duk J.(adjj22@kornet.net) (adjj1@hanmail.net)
00003  *
00004  *  This program is free software; you can redistribute it and/or
00005  *  modify it under the terms of the GNU General Public
00006  *  License as published by the Free Software Foundation; either
00007  *  version 2 of the License, or (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  *  Boston, MA 02111-1307, USA.
00018  *
00019  */
00020 
00021 #include <klocale.h>
00022 #include <qlabel.h>
00023 #include <qvaluelist.h>
00024 
00025 #include <kcompletion.h>
00026 #include <kdebug.h>
00027 #include <klistbox.h>
00028 #include <kmessagebox.h>
00029 
00030 #include <kdevplugin.h>
00031 #include <codemodel_utils.h>
00032 #include <kdevpartcontroller.h>
00033 #include <kdevproject.h>
00034 #include <kdevlanguagesupport.h>
00035 
00036 #include <doclineedit.h>
00037 
00038 #include "quickopenfunctionchooseform.h"
00039 #include "quickopenfunctiondialog.h"
00040 
00041 QuickOpenFunctionDialog::QuickOpenFunctionDialog( QuickOpenPart *part, QWidget* parent, const char* name, bool modal, WFlags fl)
00042 : QuickOpenDialog(part, parent, name, modal, fl)
00043 {
00044         nameLabel->setText( i18n("Function &name:") );
00045         itemListLabel->setText( i18n("Function &list:") );
00046 
00047         FileList fileList = m_part->codeModel()->fileList();
00048         m_functionDefList = new FunctionDefinitionList();
00049         m_functionStrList = new QStringList();
00050 
00051         // for each one file, get all function list
00052         FileDom fileDom;
00053         for( FileList::Iterator it = fileList.begin() ; it!=fileList.end() ; ++it ){
00054                 fileDom = *it;
00055                 *m_functionDefList += CodeModelUtils::allFunctionDefinitionsDetailed( fileDom ).functionList;
00056         }
00057         for( FunctionDefinitionList::ConstIterator it = m_functionDefList->begin() ; it!=m_functionDefList->end(); ++it ){
00058                 const FunctionDefinitionModel *fmodel = (*it).data();
00059                 m_functionStrList->append( fmodel->name() );
00060         }
00061         m_completion = new KCompletion();
00062         //m_functionStrList->sort();
00063         m_completion->setOrder( KCompletion::Sorted );
00064         m_completion->setItems( *m_functionStrList );
00065 
00066         itemList->insertStringList( m_completion->items() );
00067         itemList->setCurrentItem( 0 );
00068 }
00069 
00070 QuickOpenFunctionDialog::~QuickOpenFunctionDialog()
00071 {
00072         delete m_completion;
00073         delete m_functionDefList;
00074         delete m_functionStrList;
00075         m_completion = 0;
00076         m_functionDefList = 0;
00077         m_functionStrList = 0;
00078 }
00079 
00080 void QuickOpenFunctionDialog::gotoFile( QString name )
00081 {
00082         FunctionDefinitionModel *fmodel;
00083         //FunctionDefinitionList *funcList = new FunctionDefinitionList();
00084         funcList = new FunctionDefinitionList();
00085         FunctionDefinitionDom fdom;
00086 
00087         for( FunctionDefinitionList::ConstIterator it = m_functionDefList->begin() ; it!=m_functionDefList->end() ; ++it ){
00088                 fdom = *it;
00089                 fmodel = fdom.data();
00090                 if( fmodel->name() == name ){
00091                         funcList->append( fdom );
00092                 }
00093         }
00094         if( funcList->count() == 1 ){
00095                 fdom = funcList->first();
00096                 fmodel = fdom.data();
00097                 QString fileNameStr = fmodel->fileName();
00098                 int startline, startcol;
00099                 fmodel->getStartPosition( &startline, &startcol );
00100                 m_part->partController()->editDocument( KURL( fileNameStr), startline, startcol );
00101 
00102         }else if( funcList->count() > 1 ){
00103                 QString fileStr;
00104 
00105                 QuickOpenFunctionChooseForm fdlg( this, name.ascii() );
00106 
00107                 for( FunctionDefinitionList::Iterator it = funcList->begin() ; it!=funcList->end() ; ++it ){
00108                         fmodel = (*it).data();
00109 
00110                         fdlg.argBox->insertItem( m_part->languageSupport()->formatModelItem(fmodel) );
00111                         fileStr = KURL( fmodel->fileName() ).fileName();
00112                         fdlg.fileBox->insertItem( fileStr );
00113                 }
00114                 if( fdlg.exec() ){
00115                         int id = fdlg.argBox->currentItem();
00116                         if( id>-1 && id < funcList->count() ){
00117                                 FunctionDefinitionModel *model = (*funcList)[id].data();
00118                                 int line, col;
00119                                 model->getStartPosition( &line, &col );
00120                                 QString fileNameStr = model->fileName();
00121                                 m_part->partController()->editDocument( KURL(fileNameStr), line );
00122                         }
00123                 }
00124         }
00125         else{
00126                 KMessageBox::error( this, i18n("Error: cannot find matching name function.") );
00127         }
00128 
00129         accept();
00130 }
00131 void QuickOpenFunctionDialog::slotExecuted(QListBoxItem* item)
00132 {
00133         if( item ){
00134                 gotoFile( item->text() );
00135         }
00136 }
00137 void QuickOpenFunctionDialog::executed(QListBoxItem*)
00138 {
00139 }
00140 
00141 void QuickOpenFunctionDialog::slotReturnPressed()
00142 {
00143         QListBoxItem *listboxItem = itemList->selectedItem();
00144         slotExecuted( listboxItem );
00145 }
00146 
00147 #include "quickopenfunctiondialog.moc"
00148 
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:58 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003