1
0
Fork 0

Add generic "open-browser" command to show URLs or local HTML/text pages.

Replace deprecated "old-help-dialog" command with generic "open-browser".
Can also be used to add links to aircraft manuals in the menubar (local
file or http) , i.e.
<binding>
    <command>open-browser</command>
    <path>Aircraft/ogeL/FlightManual.html</path>
</binding>
This commit is contained in:
ThorstenB 2011-10-09 12:37:43 +02:00
parent 5b8ab277fd
commit 30e2db94b1
4 changed files with 50 additions and 29 deletions

View file

@ -42,6 +42,7 @@ class GraphicsContext;
// gui.cxx // gui.cxx
extern void guiStartInit(osg::GraphicsContext*); extern void guiStartInit(osg::GraphicsContext*);
extern bool guiFinishInit(); extern bool guiFinishInit();
extern bool openBrowser(string address);
extern void mkDialog(const char *txt); extern void mkDialog(const char *txt);
extern void guiErrorMessage(const char *txt); extern void guiErrorMessage(const char *txt);
extern void guiErrorMessage(const char *txt, const sg_throwable &throwable); extern void guiErrorMessage(const char *txt, const sg_throwable &throwable);

View file

@ -156,46 +156,60 @@ void guiErrorMessage (const char *txt, const sg_throwable &throwable)
the Gui callback functions the Gui callback functions
____________________________________________________________________*/ ____________________________________________________________________*/
void helpCb()
// Hier Neu :-) This is my newly added code
// Added by David Findlay <nedz@bigpond.com>
// on Sunday 3rd of December
void helpCb ()
{ {
string command; openBrowser( "Docs/index.html" );
}
SGPath path( globals->get_fg_root() );
path.append( "Docs/index.html" ); bool openBrowser(string address)
{
bool ok = true;
// do not resolve addresses with given protocol, i.e. "http://...", "ftp://..."
if (address.find("://")==string::npos)
{
// resolve local file path
SGPath path(address);
path = globals->resolve_maybe_aircraft_path(address);
if (!path.isNull())
address = path.str();
else
{
mkDialog ("Sorry, file not found!");
SG_LOG(SG_GENERAL, SG_ALERT, "openBrowser: Cannot find requested file '"
<< address << "'.");
return false;
}
}
#ifndef _WIN32 #ifndef _WIN32
command = globals->get_browser(); string command = globals->get_browser();
string::size_type pos; string::size_type pos;
if ((pos = command.find("%u", 0)) != string::npos) if ((pos = command.find("%u", 0)) != string::npos)
command.replace(pos, 2, path.str()); command.replace(pos, 2, address);
else else
command += " " + path.str(); command += " " + address;
command += " &"; command += " &";
system( command.c_str() ); ok = (system( command.c_str() ) == 0);
#else // _WIN32 #else // _WIN32
// Look for favorite browser // Look for favorite browser
char win32_name[1024]; char win32_name[1024];
# ifdef __CYGWIN__ # ifdef __CYGWIN__
cygwin32_conv_to_full_win32_path(path.c_str(),win32_name); cygwin32_conv_to_full_win32_path(address.c_str(),win32_name);
# else # else
strncpy(win32_name,path.c_str(), 1024); strncpy(win32_name,address.c_str(), 1024);
# endif # endif
ShellExecute ( NULL, "open", win32_name, NULL, NULL, ShellExecute ( NULL, "open", win32_name, NULL, NULL,
SW_SHOWNORMAL ) ; SW_SHOWNORMAL ) ;
#endif #endif
mkDialog ("Help started in your web browser window."); mkDialog("The file is shown in your web browser window.");
return ok;
} }
#if defined( TR_HIRES_SNAP) #if defined( TR_HIRES_SNAP)

View file

@ -37,14 +37,6 @@ do_hires_snapshot_dialog (const SGPropertyNode * arg)
} }
#endif // TR_HIRES_SNAP #endif // TR_HIRES_SNAP
extern void helpCb ();
static bool
do_help_dialog (const SGPropertyNode * arg)
{
helpCb();
return true;
}
static struct { static struct {
const char * name; const char * name;
SGCommandMgr::command_t command; SGCommandMgr::command_t command;
@ -52,7 +44,6 @@ static struct {
#if defined(TR_HIRES_SNAP) #if defined(TR_HIRES_SNAP)
{ "old-hires-snapshot-dialog", do_hires_snapshot_dialog }, { "old-hires-snapshot-dialog", do_hires_snapshot_dialog },
#endif #endif
{ "old-help-dialog", do_help_dialog },
{ 0, 0 } { 0, 0 }
}; };

View file

@ -1040,6 +1040,20 @@ do_dialog_update (const SGPropertyNode * arg)
} }
} }
static bool
do_open_browser (const SGPropertyNode * arg)
{
string path;
if (arg->hasValue("path"))
path = arg->getStringValue("path");
else
if (arg->hasValue("url"))
path = arg->getStringValue("url");
else
return false;
return openBrowser(path);
}
/** /**
* Apply a value in the active XML-configured dialog. * Apply a value in the active XML-configured dialog.
@ -1468,6 +1482,7 @@ static struct {
{ "dialog-close", do_dialog_close }, { "dialog-close", do_dialog_close },
{ "dialog-update", do_dialog_update }, { "dialog-update", do_dialog_update },
{ "dialog-apply", do_dialog_apply }, { "dialog-apply", do_dialog_apply },
{ "open-browser", do_open_browser },
{ "gui-redraw", do_gui_redraw }, { "gui-redraw", do_gui_redraw },
{ "add-model", do_add_model }, { "add-model", do_add_model },
{ "set-cursor", do_set_cursor }, { "set-cursor", do_set_cursor },