Help files: can now be html or pdf files: Kicad search first for a .html help file, and if not found in a path, search for the corresponding .pdf file.

Therefore our .pdf files can be replaced at any time  by .html corresponding files in kicad doc/help sub directories.
This commit is contained in:
jean-pierre charras 2014-09-02 18:44:53 +02:00
parent aff8c27942
commit e5e388f2b4
7 changed files with 47 additions and 99 deletions

View File

@ -395,18 +395,27 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
*/
if( event.GetId() == wxID_INDEX )
{
// Search for "getting_started_in_kicad.pdf" or "Getting_Started_in_KiCad.pdf"
wxString helpFile = SearchHelpFileFullPath( search, wxT( "getting_started_in_kicad.pdf" ) );
// List of possible names for Getting Started in KiCad
const wxChar* names[2] = {
wxT( "getting_started_in_kicad" ),
wxT( "Getting_Started_in_KiCad" )
};
if( !helpFile )
helpFile = SearchHelpFileFullPath( search, wxT( "Getting_Started_in_KiCad.pdf" ) );
wxString helpFile;
// Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
// or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
for( unsigned ii = 0; ii < DIM( names ); ii++ )
{
helpFile = SearchHelpFileFullPath( search, names[ii] );
if( !helpFile.IsEmpty() )
break;
}
if( !helpFile )
{
wxString msg = wxString::Format( _(
"Help file '%s' could not be found." ),
wxT( "getting_started_in_kicad.pdf" )
);
"Html or pdf help file \n'%s'\n or\n'%s' could not be found." ), names[0], names[1] );
wxMessageBox( msg );
}
else
@ -418,24 +427,6 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
}
wxString base_name = help_name();
#if defined ONLINE_HELP_FILES_FORMAT_IS_HTML
wxHtmlHelpController* hc = Pgm().GetHtmlHelpController();
wxString helpFile = SearchHelpFileFullPath( search, );
if( !!helpFile )
{
hc->UseConfig( Pgm().CommonSettings() );
hc->SetTitleFormat( wxT( "KiCad Help" ) );
hc->AddBook( helpFile );
}
hc->DisplayContents();
hc->Display( helpFile );
#elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF
wxString helpFile = SearchHelpFileFullPath( search, base_name );
if( !helpFile )
@ -450,10 +441,6 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
{
GetAssociatedDocument( this, helpFile );
}
#else
# error Help files format not defined
#endif
}

View File

@ -21,13 +21,11 @@ void BIN_MOD::Init()
// Prepare On Line Help. Use only lower case for help file names, in order to
// avoid problems with upper/lower case file names under windows and unix.
#if defined ONLINE_HELP_FILES_FORMAT_IS_HTML
m_help_file = wxString::FromUTF8( m_name ) + wxT( ".html" );
#elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF
m_help_file = wxString::FromUTF8( m_name ) + wxT( ".pdf" );
#else
#error Help files format not defined
#endif
// Help files are now using html format.
// Old help files used pdf format.
// so when searching a help file, the .html file will be searched,
// and if not found, the .pdf file will be searched.
m_help_file = wxString::FromUTF8( m_name ); // no ext given. can be .html or .pdf
}

View File

@ -263,7 +263,6 @@ PGM_BASE::PGM_BASE()
{
m_pgm_checker = NULL;
m_file_checker = NULL;
m_html_ctrl = NULL;
m_locale = NULL;
m_common_settings = NULL;
@ -296,16 +295,6 @@ void PGM_BASE::destroy()
delete m_locale;
m_locale = 0;
/*
// Close the help frame
if( m_html_ctrl && m_html_ctrl->GetFrame() ) // returns NULL if no help frame active
m_html_ctrl->GetFrame()->Close( true );
}
*/
delete m_html_ctrl;
m_html_ctrl = 0;
}
void PGM_BASE::ReleaseFile()
@ -431,40 +420,6 @@ bool PGM_BASE::initPgm()
}
void PGM_BASE::initHtmlHelpController()
{
#if defined ONLINE_HELP_FILES_FORMAT_IS_HTML
if( !m_html_ctrl )
m_html_ctrl = new wxHtmlHelpController(
wxHF_TOOLBAR | wxHF_CONTENTS |
wxHF_PRINT | wxHF_OPEN_FILES
// | wxHF_SEARCH
);
wxASSERT( m_html_ctrl ); // may not leave here as NULL
#elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF
m_html_ctrl = NULL;
#else
#error Help files format not defined
#endif
}
wxHtmlHelpController* PGM_BASE::HtmlHelpController()
{
if( !m_html_ctrl )
initHtmlHelpController();
// there should not be calls to this unless ONLINE_HELP_FILES_FORMAT_IS_HTML is defined
wxASSERT( m_html_ctrl );
return m_html_ctrl;
}
bool PGM_BASE::setExecutablePath()
{

View File

@ -89,10 +89,20 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aB
printf( "%s: m_help_file:'%s'\n", __func__, TO_UTF8( aBaseName ) );
#endif
wxString fn = FindFileInSearchPaths( ss, aBaseName, &altsubdirs );
// Help files can be html (.html ext) or pdf (.pdf ext) files.
// Therefore, <BaseName>.html file is searched and if not found,
// <BaseName>.pdf file is searched in the same paths
wxString fn = FindFileInSearchPaths( ss, aBaseName + wxT(".html"), &altsubdirs );
if( !fn )
fn = FindFileInSearchPaths( ss, aBaseName, &subdirs );
fn = FindFileInSearchPaths( ss, aBaseName + wxT(".pdf"), &altsubdirs );
if( !fn )
fn = FindFileInSearchPaths( ss, aBaseName + wxT(".html"), &subdirs );
if( !fn )
fn = FindFileInSearchPaths( ss, aBaseName + wxT(".pdf"), &subdirs );
// Step 2 : if not found Try to find help file in help/<short name>
if( !fn )
@ -104,10 +114,10 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aB
subdirs.Add( i18n->GetName().BeforeLast( '_' ) );
altsubdirs.Add( i18n->GetName().BeforeLast( '_' ) );
fn = FindFileInSearchPaths( ss, aBaseName, &altsubdirs );
fn = FindFileInSearchPaths( ss, aBaseName + wxT(".html"), &altsubdirs );
if( !fn )
fn = FindFileInSearchPaths( ss, aBaseName, &subdirs );
fn = FindFileInSearchPaths( ss, aBaseName + wxT(".pdf"), &subdirs );
}
// Step 3 : if not found Try to find help file in help/en
@ -121,7 +131,13 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aB
fn = FindFileInSearchPaths( ss, aBaseName, &altsubdirs );
if( !fn )
fn = FindFileInSearchPaths( ss, aBaseName, &subdirs );
fn = FindFileInSearchPaths( ss, aBaseName + wxT(".pdf"), &altsubdirs );
if( !fn )
fn = FindFileInSearchPaths( ss, aBaseName + wxT(".html"), &subdirs );
if( !fn )
fn = FindFileInSearchPaths( ss, aBaseName + wxT(".pdf"), &subdirs );
}
return fn;

View File

@ -590,7 +590,10 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack );
* Function SearchHelpFileFullPath
* returns the help file's full path.
* <p>
* Return the KiCad help file with path.
* Return the KiCad help file with path and extension.
* Help files can be html (.html ext) or pdf (.pdf ext) files.
* A <BaseName>.html file is searched and if not found,
* <BaseName>.pdf file is searched in the same path.
* If the help file for the current locale is not found, an attempt to find
* the English version of the help file is made.
* Help file is searched in directories in this order:
@ -600,7 +603,7 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack );
* </p>
* @param aSearchStack contains some possible base dirs that may be above the
* the one actually holding @a aBaseName. These are starting points for nested searches.
* @param aBaseName is the name of the help file to search for.
* @param aBaseName is the name of the help file to search for, <p>without extension</p>.
* @return wxEmptyString is returned if aBaseName is not found, else the full path & filename.
*/
wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxString& aBaseName );

View File

@ -8,10 +8,6 @@
/*
* KiCad uses HTML or PDF file format in the online help (help command)
* Comment one of these 2 lines
*/
#define ONLINE_HELP_FILES_FORMAT_IS_PDF
//#define ONLINE_HELP_FILES_FORMAT_IS_HTML
#endif /* #ifndef ONLINE_HELP_H */

View File

@ -38,7 +38,6 @@
class wxConfigBase;
class wxSingleInstanceChecker;
class wxHtmlHelpController;
class wxApp;
class wxMenu;
@ -86,8 +85,6 @@ public:
//----<Cross Module API>-----------------------------------------------------
VTBL_ENTRY wxHtmlHelpController* HtmlHelpController();
VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings; }
VTBL_ENTRY void SetEditorName( const wxString& aFileName );
@ -215,8 +212,6 @@ protected:
*/
bool initPgm();
void initHtmlHelpController();
/**
* Function loadCommonSettings
* loads the program (process) settings subset which are stored in .kicad_common
@ -269,8 +264,6 @@ protected:
wxString m_editor_name;
wxSize m_help_size;
wxHtmlHelpController* m_html_ctrl;
wxApp* m_wx_app;
// The PGM_* classes can have difficulties at termination if they