KDevelop API Documentation

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