GDB (API)
/home/stan/gdb/src/gdb/gdbtk/library/helpviewer.tcl
Go to the documentation of this file.
00001 # Open a viewer for HTML help info
00002 # Copyright (C) 2002, 2008, Red Hat, Inc.
00003 #
00004 # This program is free software; you can redistribute it and/or modify it
00005 # under the terms of the GNU General Public License (GPL) as published by
00006 # the Free Software Foundation; either version 2 of the License, or (at
00007 # 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
00012 # GNU General Public License for more details.
00013 
00014 # ------------------------------------------------------------------------------
00015 # NAME:           public proc open_help
00016 # SYNOPSIS:       open_help file
00017 # DESC:           Opens html help file using an appropriate
00018 #         browser.
00019 # ------------------------------------------------------------------------------
00020 
00021 proc open_help {hfile} {
00022   debug $hfile
00023   # create full pathname link
00024   set link file://[file join $::GDBTK_LIBRARY help $hfile]
00025 
00026   # windows is easy
00027   if {$::gdbtk_platform(platform) == "windows"} {
00028     ide_shell_execute open $link
00029     return
00030   }
00031 
00032   #
00033   # for Unix, we never know what is installed
00034   #
00035 
00036   # set list of viewer apps to try
00037   switch [pref get gdb/compat] {
00038     "KDE" {
00039       set apps {htmlview khelpcenter firefox opera mozilla}
00040     }
00041     "GNOME" {
00042       set apps {htmlview firefox opera mozilla gnome-help khelpcenter}
00043     }      
00044     default {
00045       set apps {htmlview firefox opera mozilla gnome-help khelpcenter netscape}
00046     }
00047   }
00048 
00049   # If the user has previously entered a browser name, append it
00050   # to the list. Should it go first or last? 
00051   set bname [pref get gdb/help/browsername]
00052   if {$bname != ""} {
00053     lappend apps $bname
00054   }
00055   
00056   # now loop through list checking each application
00057   foreach app $apps {
00058     debug "app=$app"
00059     if {[catch "exec $app $link &" result]} {
00060       debug "$app failed: $result"
00061     } else {
00062       return
00063     }
00064   }
00065   
00066   # if we reached here, nothing worked, so prompt for a name
00067   set text "No help browser was found on your system.\n\
00068 Please enter the name of an HTML viewer application."
00069   while {[set app [prompt_helpname  $text]] != "0"} {
00070     if {$app != ""} {
00071       if {[catch "exec $app $link &" result]} {
00072   dbug W "$app failed: $result"
00073   set text "Could not run application $app.\n\
00074 Please enter the name of an HTML viewer application."
00075       } else {
00076   pref set gdb/help/browsername $app
00077   return
00078       }
00079     }
00080   }
00081 }
00082 
00083 # displays an entry dialog and asks for the name of an application
00084 # returns 0 on cancel
00085 #         name on success
00086 proc prompt_helpname {text} {
00087   iwidgets::promptdialog .pd -title "Browser Query" -modality application \
00088     -labeltext  $text
00089   if {[.pd activate]} {
00090     set app [string trim [.pd get]]
00091     destroy .pd
00092     return $app
00093   }
00094   destroy .pd
00095   debug "cancelled"
00096   return 0
00097 }
00098 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines