changeset 17029:359c5ca795cd

Display doc info pages using documentation browser when in GUI mode (Bug #39451) * scripts/help/doc.m: call __octave_link_show_doc if in gui mode. * libinterp/corefcn/octave-link.h, libinterp/corefcn/octave-link.cc (octave_link::show_doc): New function. (octave_link::do_show_doc): New virtual function. (__octave_link_show_doc__): New function. * libgui/src/octave-qt-link.h (octave_qt_link::show_doc_signal): New signal. (octave_qt_link::do_show_doc): New function. * libgui/src/documentation-dock-widget.cc, libgui/src/documentation-dock-widget.h (documentation_dock_widget::showDoc): New function. * libgui/src/main-window.cc, libgui/src/main-window.h (main_window::construct_octave_qt_link): connect handle_show_doc. (main_window::handle_show_doc): New function. (main_window::show_doc_signal): New signal. * libgui/src/qtinfo/parser.cc, libgui/src/qtinfo/parser.h (parser::find_ref): New function. * libgui/src/qtinfo/webinfo.cc, libgui/src/qtinfo/webinfo.h (webinfo::load_ref): New function.
author John Donoghue <john.donoghue@ieee.org>
date Sat, 20 Jul 2013 22:13:51 -0400
parents 89acf2cd9149
children 05b8ad3b7d12
files libgui/src/documentation-dock-widget.cc libgui/src/documentation-dock-widget.h libgui/src/main-window.cc libgui/src/main-window.h libgui/src/octave-qt-link.cc libgui/src/octave-qt-link.h libgui/src/qtinfo/parser.cc libgui/src/qtinfo/parser.h libgui/src/qtinfo/webinfo.cc libgui/src/qtinfo/webinfo.h libinterp/corefcn/octave-link.cc libinterp/corefcn/octave-link.h scripts/help/doc.m
diffstat 13 files changed, 156 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/documentation-dock-widget.cc	Sat Jul 20 13:01:45 2013 +0200
+++ b/libgui/src/documentation-dock-widget.cc	Sat Jul 20 22:13:51 2013 -0400
@@ -36,6 +36,9 @@
 
   _webinfo = new webinfo (this);
   setWidget (_webinfo);
+
+  connect (p, SIGNAL(show_doc_signal(const QString &)),
+   this, SLOT(showDoc(const QString &)));
 }
 
 void
@@ -48,3 +51,8 @@
 {
   _webinfo->pasteClipboard ();
 }
+void
+documentation_dock_widget::showDoc (const QString &name)
+{
+  _webinfo->load_ref (name);
+}
--- a/libgui/src/documentation-dock-widget.h	Sat Jul 20 13:01:45 2013 +0200
+++ b/libgui/src/documentation-dock-widget.h	Sat Jul 20 22:13:51 2013 -0400
@@ -39,6 +39,7 @@
   void copyClipboard ();
   void pasteClipboard ();
 
+  void showDoc (const QString & name);
 private:
 
   webinfo *_webinfo;
--- a/libgui/src/main-window.cc	Sat Jul 20 13:01:45 2013 +0200
+++ b/libgui/src/main-window.cc	Sat Jul 20 22:13:51 2013 -0400
@@ -938,6 +938,10 @@
            this,
            SLOT (handle_update_breakpoint_marker_request (bool, const QString&, int)));
 
+  connect (_octave_qt_link,
+           SIGNAL (show_doc_signal (const QString &)),
+           this, SLOT (handle_show_doc (const QString &)));
+
   connect (_workspace_model,
            SIGNAL (rename_variable (const QString&, const QString&)),
            this,
@@ -1612,3 +1616,12 @@
 
   emit set_widget_shortcuts_signal (set_shortcuts);
 }
+
+void
+main_window::handle_show_doc (const QString& file)
+{
+  doc_browser_window->setVisible (true);
+  emit show_doc_signal (file);
+}
+
+
--- a/libgui/src/main-window.h	Sat Jul 20 13:01:45 2013 +0200
+++ b/libgui/src/main-window.h	Sat Jul 20 22:13:51 2013 -0400
@@ -82,6 +82,8 @@
   void new_file_signal (const QString&);
   void open_file_signal (const QString&);
 
+  void show_doc_signal (const QString&);
+
   void insert_debugger_pointer_signal (const QString& file, int line);
   void delete_debugger_pointer_signal (const QString& file, int line);
   void update_breakpoint_marker_signal (bool insert, const QString& file,
@@ -171,6 +173,8 @@
                                  const QString &dirname,
                                  const QString& multimode);
 
+  void handle_show_doc (const QString &file);
+
   // find files dialog 
   void find_files(const QString &startdir=QDir::currentPath());
   void find_files_finished(int);
--- a/libgui/src/octave-qt-link.cc	Sat Jul 20 13:01:45 2013 +0200
+++ b/libgui/src/octave-qt-link.cc	Sat Jul 20 22:13:51 2013 -0400
@@ -498,4 +498,10 @@
   emit show_preferences_signal ();
 }
 
+void
+octave_qt_link::do_show_doc (const std::string& file)
+{
+  emit show_doc_signal (QString::fromStdString (file));
+}
 
+
--- a/libgui/src/octave-qt-link.h	Sat Jul 20 13:01:45 2013 +0200
+++ b/libgui/src/octave-qt-link.h	Sat Jul 20 22:13:51 2013 -0400
@@ -122,6 +122,8 @@
   static bool file_in_path (const std::string& file, const std::string& dir);
 
   void do_show_preferences (void);
+
+  void do_show_doc (const std::string& file);
 private:
 
   // No copying!
@@ -169,6 +171,8 @@
   void delete_debugger_pointer_signal (const QString&, int);
 
   void show_preferences_signal (void);
+
+  void show_doc_signal (const QString &file);
 };
 
 #endif
--- a/libgui/src/qtinfo/parser.cc	Sat Jul 20 13:01:45 2013 +0200
+++ b/libgui/src/qtinfo/parser.cc	Sat Jul 20 22:13:51 2013 -0400
@@ -592,3 +592,24 @@
   results.append ("</body></html>");
   return results;
 }
+
+QString 
+parser::find_ref (const QString &ref_name)
+{
+  QString text = "";
+
+  QHash<QString,node_position>::iterator it;
+  for (it=_ref_map.begin ();it!=_ref_map.end ();++it)
+    {
+      QString k = it.key ();
+      node_position p = it.value ();
+
+      if (k == "docX" + ref_name)
+        {
+          // found ref, so return its name
+          text = "docX" + ref_name;
+        }
+    }
+  return text;
+}
+
--- a/libgui/src/qtinfo/parser.h	Sat Jul 20 13:01:45 2013 +0200
+++ b/libgui/src/qtinfo/parser.h	Sat Jul 20 22:13:51 2013 -0400
@@ -57,6 +57,8 @@
   QString search_node (const QString& node);
   QString global_search (const QString& text, int maxFounds);
 
+  QString find_ref (const QString &name);
+
   /** Checks if this node is reference. If node is reference, it will be returned its position
     * in text, else  it will be returned -1.
     */
--- a/libgui/src/qtinfo/webinfo.cc	Sat Jul 20 13:01:45 2013 +0200
+++ b/libgui/src/qtinfo/webinfo.cc	Sat Jul 20 22:13:51 2013 -0400
@@ -93,6 +93,7 @@
   resize (500, 300);
 
   set_info_path (QString::fromStdString (Vinfo_file));
+
 }
 
 void
@@ -190,6 +191,21 @@
 }
 
 void
+webinfo::load_ref (const QString &ref_name)
+{
+  QString text = _parser.find_ref (ref_name);
+  if (text.length () > 0)
+    {
+      load_node (text);
+    }
+  else
+    {
+      // not found
+     load_node("Top");
+    }
+}
+
+void
 webinfo::search ()
 {
   if (_search_check_box->isChecked ())
--- a/libgui/src/qtinfo/webinfo.h	Sat Jul 20 13:01:45 2013 +0200
+++ b/libgui/src/qtinfo/webinfo.h	Sat Jul 20 22:13:51 2013 -0400
@@ -40,6 +40,8 @@
   webinfo (QWidget *parent = 0);
   void set_info_path (const QString& info_path);
   void load_node (const QString& node_name);
+ 
+  void load_ref (const QString &ref_name); 
 
 public slots:
   void link_clicked (const QUrl& link);
--- a/libinterp/corefcn/octave-link.cc	Sat Jul 20 13:01:45 2013 +0200
+++ b/libinterp/corefcn/octave-link.cc	Sat Jul 20 22:13:51 2013 -0400
@@ -416,4 +416,22 @@
   return retval;
 }
 
+DEFUN (__octave_link_show_doc__, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} __octave_link_show_doc__ ( @var{filename} )\n\
+Undocumented internal function.\n\
+@end deftypefn")
+{
+  octave_value retval;
+  std::string file;
 
+  if (args.length () >= 1)
+    file = args(0).string_value();
+
+  retval = octave_link::show_doc (file);
+
+  return retval;
+}
+
+
+
--- a/libinterp/corefcn/octave-link.h	Sat Jul 20 13:01:45 2013 +0200
+++ b/libinterp/corefcn/octave-link.h	Sat Jul 20 22:13:51 2013 -0400
@@ -319,6 +319,19 @@
       return false;
   }
 
+  static bool 
+  show_doc (const std::string & file)
+  {
+    if (enabled ())
+      { 
+        instance->do_show_doc (file);
+        return true;
+      }
+    else
+      return false;
+ 
+  }
+
 private:
 
   static octave_link *instance;
@@ -439,6 +452,8 @@
                                        std::string& ps4) = 0;
 
   virtual void do_show_preferences (void) = 0;
+
+  virtual void do_show_doc (const std::string &file) = 0;
 };
 
 #endif // OCTAVELINK_H
--- a/scripts/help/doc.m	Sat Jul 20 13:01:45 2013 +0200
+++ b/scripts/help/doc.m	Sat Jul 20 22:13:51 2013 -0400
@@ -53,53 +53,60 @@
       fname = "";
     endif
 
-    if (ftype == 2 || ftype == 3)
-      ffile = which (fname);
-    else
-      ffile = "";
-    endif
-
-    if (isempty (ffile))
-      info_dir = octave_config_info ("infodir");
+    # if GUI is running, let it display the function
+    if isguirunning ()
+      __octave_link_show_doc__ (fname);
     else
-      info_dir = fileparts (ffile);
-    endif
-
-    ## Determine if a file called doc.info exist in the same
-    ## directory as the function.
+  
+      if (ftype == 2 || ftype == 3)
+        ffile = which (fname);
+      else
+        ffile = "";
+      endif
 
-    info_file_name = fullfile (info_dir, "doc.info");
-
-    [stat_info, err] = stat (info_file_name);
+      if (isempty (ffile))
+        info_dir = octave_config_info ("infodir");
+      else
+        info_dir = fileparts (ffile);
+      endif
 
-    if (err < 0)
-      info_file_name = info_file ();
-    endif
+      ## Determine if a file called doc.info exist in the same
+      ## directory as the function.
+
+      info_file_name = fullfile (info_dir, "doc.info");
+
+      [stat_info, err] = stat (info_file_name);
 
-    ## FIXME -- don't change the order of the arguments below because
-    ## the info-emacs-info script currently expects --directory DIR as
-    ## the third and fourth arguments.  Someone should fix that.
+      if (err < 0)
+        info_file_name = info_file ();
+      endif
+
+      ## FIXME -- don't change the order of the arguments below because
+      ## the info-emacs-info script currently expects --directory DIR as
+      ## the third and fourth arguments.  Someone should fix that.
+
+      cmd = sprintf ("\"%s\" --file \"%s\" --directory \"%s\"",
+                     info_program (), info_file_name, info_dir);
+
+      have_fname = ! isempty (fname);
 
-    cmd = sprintf ("\"%s\" --file \"%s\" --directory \"%s\"",
-                   info_program (), info_file_name, info_dir);
+      if (have_fname)
+        status = system (sprintf ("%s --index-search \"%s\"", cmd, fname));
+      endif
+   
 
-    have_fname = ! isempty (fname);
+      if (! (have_fname && status == 0))
+        status = system (cmd);
+        if (status == 127)
+          warning ("unable to find info program '%s'", info_program ());
+        endif
+      endif
 
-    if (have_fname)
-      status = system (sprintf ("%s --index-search \"%s\"", cmd, fname));
+      if (nargout > 0)
+        retval = status;
+      endif
+
     endif
-
-    if (! (have_fname && status == 0))
-      status = system (cmd);
-      if (status == 127)
-        warning ("unable to find info program '%s'", info_program ());
-      endif
-    endif
-
-    if (nargout > 0)
-      retval = status;
-    endif
-
   else
     print_usage ();
   endif