From: <pst...@us...> - 2008-06-11 15:12:19
|
Revision: 597 http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=597&view=rev Author: pstieber Date: 2008-06-11 08:12:17 -0700 (Wed, 11 Jun 2008) Log Message: ----------- Added code to register the generated help file. Modified Paths: -------------- trunk/jazz/src/JazzPlusPlusApplication.cpp trunk/jazz/src/JazzPlusPlusApplication.h Modified: trunk/jazz/src/JazzPlusPlusApplication.cpp =================================================================== --- trunk/jazz/src/JazzPlusPlusApplication.cpp 2008-06-11 15:03:03 UTC (rev 596) +++ trunk/jazz/src/JazzPlusPlusApplication.cpp 2008-06-11 15:12:17 UTC (rev 597) @@ -48,11 +48,19 @@ #endif +#include <fstream> + +using namespace std; + //***************************************************************************** // Description: // This is the JazzPlusPlus application class definition. //***************************************************************************** //----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +wxString JZJazzPlusPlusApplication::mHelpFileName = "jazz.hhp"; + +//----------------------------------------------------------------------------- // Description: // Create a new application object using the wxWidgets macro. This macro // will allow wxWidgets to create the application object during program @@ -143,11 +151,110 @@ // Show it and tell the application that it's our main window SetTopWindow(mpTrackFrame); + // Get the current working directory and append a directory separator. + wxString CurrentWorkingDirectory = + ::wxGetCwd() + wxFileName::GetPathSeparator(); + + // This code should be distributed with a HelpFiles subdirectory under + // the directory the executable is stored in. + wxString HelpFileDirectoryGuess = + CurrentWorkingDirectory + "HelpFiles" + wxFileName::GetPathSeparator(); + + // Attempt to obtain the path to the help file from configuration data. + wxString HelpFilePath; + bool WasHelpPathRead = false; + if (pConfig) + { + WasHelpPathRead = pConfig->Read( + "/Paths/Help", + &HelpFilePath, + HelpFileDirectoryGuess); + } + + // Construct a full file name. + wxString HelpFileNameAndPath = HelpFilePath + mHelpFileName; + + // Test for the existence of the help file. + bool HelpFileFound = true; + ifstream Is; + Is.open(HelpFileNameAndPath.c_str()); + if (!Is) + { + // Return a valid path to the data. + FindAndRegisterHelpFilePath(HelpFilePath); + HelpFileNameAndPath = HelpFilePath + mHelpFileName; + + // Try one more time. + Is.close(); + Is.clear(); + Is.open(HelpFileNameAndPath.c_str()); + if (!Is) + { + wxString Message = "Failed to add the IPVT book " + mHelpFileName; + ::wxMessageBox(Message); + HelpFileFound = false; + } + } + + if (HelpFileFound) + { + // The cached version of the help file will be placed in this location. + mHelp.SetTempDir(HelpFilePath); + + // Add the IPVT help file the the help system. + mHelp.AddBook(HelpFileNameAndPath); + + if (!WasHelpPathRead && pConfig) + { + // Register the help path. + pConfig->Write("/Paths/Help", HelpFilePath); + } + } + return true; } //----------------------------------------------------------------------------- +// Description: +// The help file was not found so let the user search for it. If it is +// found, create a configuration entry so the code can find the help file path +// the next time it starts. //----------------------------------------------------------------------------- +void JZJazzPlusPlusApplication::FindAndRegisterHelpFilePath( + wxString& HelpFilePath) +{ + wxString Message; + Message = "Unable to find " + mHelpFileName; + ::wxMessageBox(Message, "Please Locate This File!"); + + // Use an open dialog to find the help file. + wxFileDialog OpenDialog( + 0, + "Open the Help File", + "", + mHelpFileName, + "*.hhp", + wxFD_OPEN); + if (OpenDialog.ShowModal() == wxID_OK) + { + // Generate a c-style string that contains a path to the help file. + wxString TempHelpFilePath; + TempHelpFilePath = ::wxPathOnly(OpenDialog.GetPath()); + TempHelpFilePath += ::wxFileName::GetPathSeparator(); + + wxConfigBase* pConfig = wxConfigBase::Get(); + if (pConfig) + { + pConfig->Write("/Paths/Help", TempHelpFilePath); + } + + // Return the user selected help file path. + HelpFilePath = TempHelpFilePath; + } +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- int JZJazzPlusPlusApplication::OnExit() { delete mpProject; Modified: trunk/jazz/src/JazzPlusPlusApplication.h =================================================================== --- trunk/jazz/src/JazzPlusPlusApplication.h 2008-06-11 15:03:03 UTC (rev 596) +++ trunk/jazz/src/JazzPlusPlusApplication.h 2008-06-11 15:12:17 UTC (rev 597) @@ -90,6 +90,12 @@ private: + void FindAndRegisterHelpFilePath(wxString& HelpFilePath); + + private: + + static wxString mHelpFileName; + JZProject* mpProject; JZTrackFrame* mpTrackFrame; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |