Bug 131450 - Documentation shortcuts don't work as expected
Summary: Documentation shortcuts don't work as expected
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Unclassified
Component: Documentation viewer (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-27 23:53 UTC by Gunther Piez
Modified: 2006-12-28 05:21 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gunther Piez 2006-07-27 23:53:36 UTC
Version:            (using KDE KDE 3.5.3)
Installed from:    Gentoo Packages

If the cursor is positioned in the source code in a type name, and the right-click context menu "Find in documentation", "Search in documentation" et al is selected, a window with the search result and hopefully the documentation is immediatly opened.

This is fine and ok.
(Actually it would be even more fine, if the documentation window opened somewhere else, and not directly where the source code was. But this is a different story.)

If I hit the shortcut ("Ctrl-Alt-F" or whatever), the documentation dock/browser opens, but without a search term. This makes the shortcuts kinda useless. I would expect the same behaviour like the mouse click.
Comment 1 Jens Dagerbo 2006-12-28 05:21:50 UTC
SVN commit 617133 by dagerbo:

If the text under the cursor of the active document resolves to a word when a document search tool is invoked, assume that word is interesting and use for the search. This should give the most intuitive and overall prefered behaviour. 

BUG: 131450

 M  +157 -46   documentation_part.cpp  
 M  +1 -0      documentation_part.h  
 M  +2 -1      kdevpart_documentation.rc  


--- branches/kdevelop/3.4/parts/documentation/documentation_part.cpp #617132:617133
@@ -46,6 +46,8 @@
 #include <kstringhandler.h>
 #include <kconfig.h>
 #include <kwin.h>
+#include <ktexteditor/editinterface.h>
+#include <ktexteditor/viewcursorinterface.h>
 
 #include "kdevplugininfo.h"
 #include "kdevcore.h"
@@ -217,6 +219,7 @@
                               "the documentation. For this to work, a "
                               "full text index must be created first, which can be done in the "
                               "configuration dialog of the documentation plugin."));    
+
     action = new KAction(i18n("&Look in Documentation Index..."), CTRL+ALT+Key_I,
                          this, SLOT(lookInDocumentationIndex()),
                          actionCollection(), "help_look_in_index" );
@@ -225,16 +228,29 @@
                               "Opens the documentation index tab. It allows "
                               "a term to be entered which will be looked for in "
                               "the documentation index."));    
+
     action = new KAction(i18n("Man Page..."), 0,
                          this, SLOT(manPage()),
                          actionCollection(), "help_manpage" );
     action->setToolTip(i18n("Show a manpage"));
     action->setWhatsThis(i18n("<b>Show a manpage</b><p>Opens a man page using embedded viewer."));
+
     action = new KAction(i18n("Info Page..."), 0,
                          this, SLOT(infoPage()),
                          actionCollection(), "help_infopage");
     action->setToolTip(i18n("Show an infopage"));
     action->setWhatsThis(i18n("<b>Show an infopage</b><p>Opens an info page using embedded viewer."));
+
+    action = new KAction(i18n("Find Documentation..."), 0,
+                         this, SLOT(findInDocumentation()),
+                         actionCollection(), "help_find_documentation");
+    action->setToolTip(i18n("Find Documentation"));
+    action->setWhatsThis(i18n("<b>Find documentation</b><p>"
+                                    "Opens the documentation finder tab and searches "
+                                    "all possible sources of documentation like "
+                                    "table of contents, index, man and info databases, "
+                                    "Google, etc."));
+    action->setWhatsThis(i18n("<b>Show an infopage</b><p>Opens an info page using embedded viewer."));
 }
 
 void DocumentationPart::emitBookmarkLocation(const QString &title, const KURL &url)
@@ -244,13 +260,28 @@
 
 void DocumentationPart::searchInDocumentation()
 {
-    if (isAssistantUsed())
-        callAssistant("KDevDocumentation", "searchInDocumentation()");
-    else    
+    QString word = currentWord();
+
+    if ( word.isEmpty() )
     {
-        mainWindow()->raiseView(m_widget);
-        m_widget->searchInDocumentation();
+        if ( isAssistantUsed() )
+            callAssistant ( "KDevDocumentation", "searchInDocumentation()" );
+        else
+        {
+            mainWindow()->raiseView ( m_widget );
+            m_widget->searchInDocumentation();
+        }
     }
+    else
+    {
+        if ( isAssistantUsed() )
+            callAssistant ( "KDevDocumentation", "searchInDocumentation(QString)", word );
+        else
+        {
+            mainWindow()->raiseView ( m_widget );
+            m_widget->searchInDocumentation ( word );
+        }
+    }
 }
 
 void DocumentationPart::searchInDocumentation(const QString &term)
@@ -269,27 +300,49 @@
 
 void DocumentationPart::manPage()
 {
-    if (isAssistantUsed())
-        callAssistant("KDevDocumentation", "manPage()");
-    else    
+    QString word = currentWord();
+
+    if ( isAssistantUsed() )
     {
+        if ( word.isEmpty() )
+        {
+            callAssistant ( "KDevDocumentation", "manPage()" );
+        }
+        else
+        {
+            callAssistant ( "KDevDocumentation", "manPage(QString)", word );
+        }
+    }
+    else
+    {
         bool ok;
-        QString manpage = KInputDialog::getText(i18n("Show Manual Page"), i18n("Show manpage on:"), "", &ok, 0);
-        if (ok && !manpage.isEmpty())
-            manPage(manpage);
+        QString manpage = KInputDialog::getText ( i18n ( "Show Manual Page" ), i18n ( "Show manpage on:" ), word, &ok, 0 );
+        if ( ok && !manpage.isEmpty() )
+            manPage ( manpage );
     }
 }
 
 void DocumentationPart::infoPage()
 {
-    if (isAssistantUsed())
-        callAssistant("KDevDocumentation", "infoPage()");
-    else    
+    QString word = currentWord();
+    
+    if ( isAssistantUsed() )
     {
+        if ( word.isEmpty() )
+        {
+            callAssistant ( "KDevDocumentation", "infoPage()" );
+        }
+        else
+        {
+            callAssistant ( "KDevDocumentation", "infoPage(QString)", word );
+        }
+    }
+    else
+    {
         bool ok;
-        QString infopage = KInputDialog::getText(i18n("Show Info Page"), i18n("Show infopage on:"), "", &ok, 0);
-        if (ok && !infopage.isEmpty())
-            infoPage(infopage);
+        QString infopage = KInputDialog::getText ( i18n ( "Show Info Page" ), i18n ( "Show infopage on:" ), word, &ok, 0 );
+        if ( ok && !infopage.isEmpty() )
+            infoPage ( infopage );
     }
 }
 
@@ -331,12 +384,27 @@
 
 void DocumentationPart::findInDocumentation()
 {
-    if (isAssistantUsed())
-        callAssistant("KDevDocumentation", "findInFinder()");
+    QString word = currentWord();
+    
+    if ( word.isEmpty() )
+    {
+        if ( isAssistantUsed() )
+            callAssistant ( "KDevDocumentation", "findInFinder()" );
+        else
+        {
+            mainWindow()->raiseView ( m_widget );
+            m_widget->findInDocumentation();
+        }
+    }
     else
     {
-        mainWindow()->raiseView(m_widget);
-        m_widget->findInDocumentation();
+        if ( isAssistantUsed() )
+            callAssistant ( "KDevDocumentation", "findInFinder(QString)", word );
+        else
+        {
+            mainWindow()->raiseView ( m_widget );
+            m_widget->findInDocumentation ( word );
+        }
     }
 }
 
@@ -346,6 +414,46 @@
     m_widget->findInDocumentation(term);
 }
 
+void DocumentationPart::lookInDocumentationIndex()
+{
+    QString word = currentWord();
+    
+    if ( word.isEmpty() )
+    {
+        if ( isAssistantUsed() )
+            callAssistant ( "KDevDocumentation", "lookupInIndex()" );
+        else
+        {
+            mainWindow()->raiseView ( m_widget );
+            m_widget->lookInDocumentationIndex();
+        }
+    }
+    else
+    {
+        if ( isAssistantUsed() )
+            callAssistant ( "KDevDocumentation", "lookupInIndex(QString)", word );
+        else
+        {
+            mainWindow()->raiseView ( m_widget );
+            m_widget->lookInDocumentationIndex ( word );
+        }
+    }
+}
+
+void DocumentationPart::lookInDocumentationIndex(const QString &term)
+{
+    mainWindow()->raiseView(m_widget);
+    m_widget->lookInDocumentationIndex(term);
+}
+
+void DocumentationPart::contextLookInDocumentationIndex()
+{
+    if (isAssistantUsed())
+        callAssistant("KDevDocumentation", "lookupInIndex(QString)", m_contextStr);
+    else
+        lookInDocumentationIndex(m_contextStr);
+}
+
 void DocumentationPart::contextMenu(QPopupMenu *popup, const Context *context)
 {
     if (context->hasType(Context::EditorContext))
@@ -455,31 +563,6 @@
     config->setGroup(group);
 }
 
-void DocumentationPart::lookInDocumentationIndex()
-{
-    if (isAssistantUsed())
-        callAssistant("KDevDocumentation", "lookupInIndex()");
-    else    
-    {
-        mainWindow()->raiseView(m_widget);
-        m_widget->lookInDocumentationIndex();
-    }
-}
-
-void DocumentationPart::lookInDocumentationIndex(const QString &term)
-{
-    mainWindow()->raiseView(m_widget);
-    m_widget->lookInDocumentationIndex(term);
-}
-
-void DocumentationPart::contextLookInDocumentationIndex()
-{
-    if (isAssistantUsed())
-        callAssistant("KDevDocumentation", "lookupInIndex(QString)", m_contextStr);
-    else
-        lookInDocumentationIndex(m_contextStr);
-}
-
 void DocumentationPart::projectOpened()
 {
     QString projectDocSystem = DomUtil::readEntry(*(projectDom()), "/kdevdocumentation/projectdoc/docsystem");
@@ -681,4 +764,32 @@
     loadSettings();
 }
 
+///@todo - duplicated from ctags part, which came from editorproxy. we also have a shorter version in other places..
+QString DocumentationPart::currentWord()
+{
+    KParts::ReadOnlyPart *ro_part = dynamic_cast<KParts::ReadOnlyPart*> ( partController()->activePart() );
+    if ( !ro_part || !ro_part->widget() ) return QString::null;
+
+    KTextEditor::ViewCursorInterface * cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*> ( ro_part->widget() );
+    KTextEditor::EditInterface * editIface = dynamic_cast<KTextEditor::EditInterface*> ( ro_part );
+
+    QString wordstr, linestr;
+    if ( cursorIface && editIface )
+    {
+        uint line, col;
+        line = col = 0;
+        cursorIface->cursorPositionReal ( &line, &col );
+        linestr = editIface->textLine ( line );
+        int startPos = QMAX ( QMIN ( ( int ) col, ( int ) linestr.length()-1 ), 0 );
+        int endPos = startPos;
+        while ( startPos >= 0 && ( linestr[startPos].isLetterOrNumber() || linestr[startPos] == '_' || linestr[startPos] == '~' ) )
+            startPos--;
+        while ( endPos < ( int ) linestr.length() && ( linestr[endPos].isLetterOrNumber() || linestr[endPos] == '_' ) )
+            endPos++;
+
+        return ( ( startPos == endPos ) ? QString::null : linestr.mid ( startPos+1, endPos-startPos-1 ) );
+    }
+    return QString::null;
+}
+
 #include "documentation_part.moc"
--- branches/kdevelop/3.4/parts/documentation/documentation_part.h #617132:617133
@@ -107,6 +107,7 @@
     QValueList<DocumentationPlugin*> m_plugins;
     ProjectDocumentationPlugin *m_projectDocumentationPlugin;
     ProjectDocumentationPlugin *m_userManualPlugin;
+    QString currentWord();
     
     QString m_contextStr;
     bool m_hasIndex;
--- branches/kdevelop/3.4/parts/documentation/kdevpart_documentation.rc #617132:617133
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui>
-<kpartplugin name="documentation" library="libdocumentationplugin" version="3">
+<kpartplugin name="documentation" library="libdocumentationplugin" version="4">
 <MenuBar>
 <!--  <Action name="doc_bookmarks"/> -->
 <!-- <Menu name="tools"><Text>&amp;Tools</Text>
@@ -10,6 +10,7 @@
   <Action name="help_search_in_doc"/>
   <Action name="help_manpage"/>
   <Action name="help_infopage"/>
+  <Action name="help_find_documentation" />
  </Menu>
 </MenuBar>
 <!--<ToolBar name="extraToolBar">