KDevelop API Documentation

parts/doctreeview/doctreeviewpart.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 1999-2001 by Bernd Gehrmann * 00003 * bernd@kdevelop.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include "doctreeviewpart.h" 00013 00014 #include <qpopupmenu.h> 00015 #include <qvbox.h> 00016 #include <qwhatsthis.h> 00017 #include <kapplication.h> 00018 #include <kdebug.h> 00019 #include <kdialogbase.h> 00020 #include <kiconloader.h> 00021 #include <klineeditdlg.h> 00022 #include <klocale.h> 00023 #include <kstandarddirs.h> 00024 #include <kstringhandler.h> 00025 #include <kaction.h> 00026 #include <configwidgetproxy.h> 00027 00028 #include "kdevcore.h" 00029 #include "misc.h" 00030 #include "kdevproject.h" 00031 #include "kdevmainwindow.h" 00032 #include "kdevpartcontroller.h" 00033 00034 #include "docsearchdlg.h" 00035 #include "docindexdlg.h" 00036 #include "doctreeviewfactory.h" 00037 #include "doctreeviewwidget.h" 00038 #include "doctreeglobalconfigwidget.h" 00039 #include "doctreeprojectconfigwidget.h" 00040 00041 #define GLOBALDOC_OPTIONS 1 00042 #define PROJECTDOC_OPTIONS 2 00043 00044 DocTreeViewPart::DocTreeViewPart( QObject *parent, const char *name, const QStringList & ) 00045 : KDevPlugin("DocTree", "doctree", parent, name ? name : "DocTreeViewPart") 00046 { 00047 setInstance(DocTreeViewFactory::instance()); 00048 00049 setXMLFile("kdevdoctreeview.rc"); 00050 00051 connect( core(), SIGNAL(projectOpened()), this, SLOT(projectOpened()) ); 00052 connect( core(), SIGNAL(projectClosed()), this, SLOT(projectClosed()) ); 00053 // connect( core(), SIGNAL(configWidget(KDialogBase*)), this, SLOT(configWidget(KDialogBase*)) ); 00054 // connect( core(), SIGNAL(projectConfigWidget(KDialogBase*)), this, SLOT(projectConfigWidget(KDialogBase*)) ); 00055 connect( core(), SIGNAL(contextMenu(QPopupMenu *, const Context *)), 00056 this, SLOT(contextMenu(QPopupMenu *, const Context *)) ); 00057 00058 _configProxy = new ConfigWidgetProxy( core() ); 00059 _configProxy->createGlobalConfigPage( i18n("Documentation Tree"), GLOBALDOC_OPTIONS ); 00060 _configProxy->createProjectConfigPage( i18n("Project Documentation"), PROJECTDOC_OPTIONS ); 00061 connect( _configProxy, SIGNAL(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int )), this, SLOT(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int )) ); 00062 00063 m_widget = new DocTreeViewWidget(this); 00064 m_widget->setIcon(SmallIcon("contents")); 00065 m_widget->setCaption(i18n("Documentation Tree")); 00066 QWhatsThis::add(m_widget, i18n("<b>Documentation tree</b><p>" 00067 "The documentation tree gives access to various " 00068 "documentation sources (Qt DCF, Doxygen, KDoc, KDevelopTOC and DevHelp " 00069 "documentation) and the KDevelop manuals. It also provides documentation index.")); 00070 00071 mainWindow()->embedSelectViewRight(m_widget, i18n("Documentation"), i18n("Documentation browser")); 00072 00073 KAction *action; 00074 00075 action = new KAction( i18n("Full Text &Search..."), 0, 00076 this, SLOT(slotSearchDocumentation()), 00077 actionCollection(), "help_fulltextsearch" ); 00078 action->setToolTip( i18n("Full text search in the documentation") ); 00079 action->setWhatsThis( i18n("<b>Full text search</b><p>" 00080 "Opens the Search in documentation dialog. It allows " 00081 "to enter a search term which will be searched for in " 00082 "the documentation. For this to work, a " 00083 "full text index must be created first, which can be done in the " 00084 "configuration dialog of the documentation tree.") ); 00085 00086 action = new KAction( i18n("Man Page..."), 0, 00087 this, SLOT(slotManpage()), 00088 actionCollection(), "help_manpage" ); 00089 action->setToolTip( i18n("Show a manpage") ); 00090 action->setWhatsThis(i18n("<b>Show a manpage</b><p>Opens a man page using embedded viewer.")); 00091 } 00092 00093 00094 DocTreeViewPart::~DocTreeViewPart() 00095 { 00096 if ( m_widget ) 00097 mainWindow()->removeView( m_widget ); 00098 delete (DocTreeViewWidget*) m_widget; 00099 } 00100 00101 00102 void DocTreeViewPart::projectOpened() 00103 { 00104 m_widget->projectChanged(project()); 00105 } 00106 00107 00108 void DocTreeViewPart::projectClosed() 00109 { 00110 m_widget->projectChanged(0); 00111 } 00112 /* 00113 void DocTreeViewPart::configWidget(KDialogBase *dlg) 00114 { 00115 QVBox *vbox; 00116 00117 vbox = dlg->addVBoxPage(i18n("Documentation Tree")); 00118 DocTreeGlobalConfigWidget *w1 = 00119 new DocTreeGlobalConfigWidget( this, m_widget, vbox, "doc tree config widget"); 00120 00121 connect( dlg, SIGNAL(okClicked()), w1, SLOT(accept()) ); 00122 } 00123 00124 00125 void DocTreeViewPart::projectConfigWidget(KDialogBase *dlg) { 00126 QVBox *vbox; 00127 00128 vbox = dlg->addVBoxPage(i18n("Project Documentation")); 00129 DocTreeProjectConfigWidget *w1 = 00130 new DocTreeProjectConfigWidget(m_widget, vbox, project(), "doc tree project config"); 00131 00132 connect( dlg, SIGNAL(okClicked()), w1, SLOT(accept()) ); 00133 //kdDebug(9002) << "**** ProjectConfigWidget ****" << endl; 00134 } 00135 */ 00136 00137 void DocTreeViewPart::contextMenu(QPopupMenu *popup, const Context *context) 00138 { 00139 kdDebug(9002) << "context in doctree" << endl; 00140 if (context->hasType( Context::EditorContext )) { 00141 const EditorContext *econtext = static_cast<const EditorContext*>(context); 00142 QString ident = econtext->currentWord(); 00143 if (!ident.isEmpty()) { 00144 m_popupstr = ident; 00145 QString squeezed = KStringHandler::csqueeze(m_popupstr, 20); 00146 popup->insertSeparator(); 00147 int id = popup->insertItem( i18n("Search in Documentation: %1").arg(squeezed), 00148 this, SLOT(slotContextFulltextSearch()) ); 00149 popup->setWhatsThis(id, i18n("<b>Search in documentation</b><p>Searches " 00150 "for a term under the cursor in " 00151 "the documentation. For this to work, " 00152 "a full text index must be created first, which can be done in the " 00153 "configuration dialog of the documentation tree.")); 00154 id = popup->insertItem( i18n("Goto Manpage: %1").arg(ident), 00155 this, SLOT(slotContextGotoManpage()) ); 00156 popup->setWhatsThis(id, i18n("<b>Goto manpage</b><p>Tries to open a man page for the term under the cursor.")); 00157 } 00158 } else if (context->hasType( Context::DocumentationContext )) { 00159 const DocumentationContext *dcontext = static_cast<const DocumentationContext*>(context); 00160 kdDebug(9002) << "documentation context in doctree" << endl; 00161 QString selection = dcontext->selection(); 00162 if (!selection.isEmpty()) { 00163 m_popupstr = selection; 00164 QString squeezed = KStringHandler::csqueeze(selection, 20); 00165 popup->insertSeparator(); 00166 int id = popup->insertItem( i18n("Search in Documentation: %1").arg(squeezed), 00167 this, SLOT(slotContextFulltextSearch()) ); 00168 popup->setWhatsThis(id, i18n("<b>Search in documentation</b><p>Searches " 00169 "for a text of currently selected documentation item in " 00170 "the documentation. For this to work, " 00171 "a full text index must be created first, which can be done in the " 00172 "configuration dialog of the documentation tree.")); 00173 } 00174 } 00175 } 00176 00177 void DocTreeViewPart::slotSearchDocumentation() 00178 { 00179 kdDebug(9002) << "Full text search requested" << endl; 00180 DocSearchDialog dlg(m_widget, "doc search dialog"); 00181 if (dlg.exec()) { 00182 QString indexdir = kapp->dirs()->saveLocation("data", "kdevdoctreeview/helpindex"); 00183 partController()->showDocument(KURL("file://" + indexdir + "/results.html")); 00184 } 00185 } 00186 00187 void DocTreeViewPart::slotManpage() 00188 { 00189 bool ok; 00190 QString manpage = KLineEditDlg::getText(i18n("Show manpage on:"), "", &ok, 0); 00191 if (ok && !manpage.isEmpty()) { 00192 QString url = QString::fromLatin1("man:/%1").arg(manpage); 00193 partController()->showDocument(KURL(url)); 00194 } 00195 } 00196 00197 void DocTreeViewPart::slotRaiseWidget() 00198 { 00199 mainWindow()->raiseView(m_widget); 00200 } 00201 00202 00203 void DocTreeViewPart::slotContextGotoManpage() 00204 { 00205 QString url = QString::fromLatin1("man:/%1").arg(m_popupstr); 00206 partController()->showDocument(KURL(url)); 00207 } 00208 00209 void DocTreeViewPart::slotContextFulltextSearch() 00210 { 00211 DocSearchDialog dlg(m_widget, "doc search dialog"); 00212 dlg.setSearchTerm(m_popupstr); 00213 if (dlg.performSearch()) { 00214 QString indexdir = kapp->dirs()->saveLocation("data", "kdevdoctreeview/helpindex"); 00215 partController()->showDocument(KURL("file://" + indexdir + "/results.html"), m_popupstr ); 00216 } 00217 } 00218 00219 void DocTreeViewPart::insertConfigWidget( const KDialogBase * dlg, QWidget * page, unsigned int pagenumber ) 00220 { 00221 switch ( pagenumber ) 00222 { 00223 case GLOBALDOC_OPTIONS: 00224 { 00225 DocTreeGlobalConfigWidget *w1 = new DocTreeGlobalConfigWidget( this, m_widget, page, "doc tree config widget"); 00226 connect( dlg, SIGNAL(okClicked()), w1, SLOT(accept()) ); 00227 00228 break; 00229 } 00230 case PROJECTDOC_OPTIONS: 00231 { 00232 DocTreeProjectConfigWidget *w1 = new DocTreeProjectConfigWidget(m_widget, page, project(), "doc tree project config"); 00233 connect( dlg, SIGNAL(okClicked()), w1, SLOT(accept()) ); 00234 00235 break; 00236 } 00237 } 00238 } 00239 00240 #include "doctreeviewpart.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:11 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003