Commit e5e388f2 authored by jean-pierre charras's avatar jean-pierre charras

Help files: can now be html or pdf files: Kicad search first for a .html help...

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.
parent aff8c279
...@@ -395,18 +395,27 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event ) ...@@ -395,18 +395,27 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
*/ */
if( event.GetId() == wxID_INDEX ) if( event.GetId() == wxID_INDEX )
{ {
// Search for "getting_started_in_kicad.pdf" or "Getting_Started_in_KiCad.pdf" // List of possible names for Getting Started in KiCad
wxString helpFile = SearchHelpFileFullPath( search, wxT( "getting_started_in_kicad.pdf" ) ); const wxChar* names[2] = {
wxT( "getting_started_in_kicad" ),
wxT( "Getting_Started_in_KiCad" )
};
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 ) if( !helpFile.IsEmpty() )
helpFile = SearchHelpFileFullPath( search, wxT( "Getting_Started_in_KiCad.pdf" ) ); break;
}
if( !helpFile ) if( !helpFile )
{ {
wxString msg = wxString::Format( _( wxString msg = wxString::Format( _(
"Help file '%s' could not be found." ), "Html or pdf help file \n'%s'\n or\n'%s' could not be found." ), names[0], names[1] );
wxT( "getting_started_in_kicad.pdf" )
);
wxMessageBox( msg ); wxMessageBox( msg );
} }
else else
...@@ -418,24 +427,6 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event ) ...@@ -418,24 +427,6 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
} }
wxString base_name = help_name(); 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 ); wxString helpFile = SearchHelpFileFullPath( search, base_name );
if( !helpFile ) if( !helpFile )
...@@ -450,10 +441,6 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event ) ...@@ -450,10 +441,6 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
{ {
GetAssociatedDocument( this, helpFile ); GetAssociatedDocument( this, helpFile );
} }
#else
# error Help files format not defined
#endif
} }
......
...@@ -21,13 +21,11 @@ void BIN_MOD::Init() ...@@ -21,13 +21,11 @@ void BIN_MOD::Init()
// Prepare On Line Help. Use only lower case for help file names, in order to // 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. // avoid problems with upper/lower case file names under windows and unix.
#if defined ONLINE_HELP_FILES_FORMAT_IS_HTML // Help files are now using html format.
m_help_file = wxString::FromUTF8( m_name ) + wxT( ".html" ); // Old help files used pdf format.
#elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF // so when searching a help file, the .html file will be searched,
m_help_file = wxString::FromUTF8( m_name ) + wxT( ".pdf" ); // and if not found, the .pdf file will be searched.
#else m_help_file = wxString::FromUTF8( m_name ); // no ext given. can be .html or .pdf
#error Help files format not defined
#endif
} }
......
...@@ -263,7 +263,6 @@ PGM_BASE::PGM_BASE() ...@@ -263,7 +263,6 @@ PGM_BASE::PGM_BASE()
{ {
m_pgm_checker = NULL; m_pgm_checker = NULL;
m_file_checker = NULL; m_file_checker = NULL;
m_html_ctrl = NULL;
m_locale = NULL; m_locale = NULL;
m_common_settings = NULL; m_common_settings = NULL;
...@@ -296,16 +295,6 @@ void PGM_BASE::destroy() ...@@ -296,16 +295,6 @@ void PGM_BASE::destroy()
delete m_locale; delete m_locale;
m_locale = 0; 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() void PGM_BASE::ReleaseFile()
...@@ -431,40 +420,6 @@ bool PGM_BASE::initPgm() ...@@ -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() bool PGM_BASE::setExecutablePath()
{ {
......
...@@ -89,10 +89,20 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aB ...@@ -89,10 +89,20 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aB
printf( "%s: m_help_file:'%s'\n", __func__, TO_UTF8( aBaseName ) ); printf( "%s: m_help_file:'%s'\n", __func__, TO_UTF8( aBaseName ) );
#endif #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 + wxT(".pdf"), &altsubdirs );
if( !fn )
fn = FindFileInSearchPaths( ss, aBaseName + wxT(".html"), &subdirs );
if( !fn ) if( !fn )
fn = FindFileInSearchPaths( ss, aBaseName, &subdirs ); fn = FindFileInSearchPaths( ss, aBaseName + wxT(".pdf"), &subdirs );
// Step 2 : if not found Try to find help file in help/<short name> // Step 2 : if not found Try to find help file in help/<short name>
if( !fn ) if( !fn )
...@@ -104,10 +114,10 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aB ...@@ -104,10 +114,10 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aB
subdirs.Add( i18n->GetName().BeforeLast( '_' ) ); subdirs.Add( i18n->GetName().BeforeLast( '_' ) );
altsubdirs.Add( i18n->GetName().BeforeLast( '_' ) ); altsubdirs.Add( i18n->GetName().BeforeLast( '_' ) );
fn = FindFileInSearchPaths( ss, aBaseName, &altsubdirs ); fn = FindFileInSearchPaths( ss, aBaseName + wxT(".html"), &altsubdirs );
if( !fn ) 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 // 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 ...@@ -121,7 +131,13 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aB
fn = FindFileInSearchPaths( ss, aBaseName, &altsubdirs ); fn = FindFileInSearchPaths( ss, aBaseName, &altsubdirs );
if( !fn ) 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; return fn;
......
...@@ -590,7 +590,10 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack ); ...@@ -590,7 +590,10 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack );
* Function SearchHelpFileFullPath * Function SearchHelpFileFullPath
* returns the help file's full path. * returns the help file's full path.
* <p> * <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 * If the help file for the current locale is not found, an attempt to find
* the English version of the help file is made. * the English version of the help file is made.
* Help file is searched in directories in this order: * Help file is searched in directories in this order:
...@@ -600,7 +603,7 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack ); ...@@ -600,7 +603,7 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack );
* </p> * </p>
* @param aSearchStack contains some possible base dirs that may be above the * @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. * 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. * @return wxEmptyString is returned if aBaseName is not found, else the full path & filename.
*/ */
wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxString& aBaseName ); wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxString& aBaseName );
......
...@@ -8,10 +8,6 @@ ...@@ -8,10 +8,6 @@
/* /*
* KiCad uses HTML or PDF file format in the online help (help command) * 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 */ #endif /* #ifndef ONLINE_HELP_H */
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
class wxConfigBase; class wxConfigBase;
class wxSingleInstanceChecker; class wxSingleInstanceChecker;
class wxHtmlHelpController;
class wxApp; class wxApp;
class wxMenu; class wxMenu;
...@@ -86,8 +85,6 @@ public: ...@@ -86,8 +85,6 @@ public:
//----<Cross Module API>----------------------------------------------------- //----<Cross Module API>-----------------------------------------------------
VTBL_ENTRY wxHtmlHelpController* HtmlHelpController();
VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings; } VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings; }
VTBL_ENTRY void SetEditorName( const wxString& aFileName ); VTBL_ENTRY void SetEditorName( const wxString& aFileName );
...@@ -215,8 +212,6 @@ protected: ...@@ -215,8 +212,6 @@ protected:
*/ */
bool initPgm(); bool initPgm();
void initHtmlHelpController();
/** /**
* Function loadCommonSettings * Function loadCommonSettings
* loads the program (process) settings subset which are stored in .kicad_common * loads the program (process) settings subset which are stored in .kicad_common
...@@ -269,8 +264,6 @@ protected: ...@@ -269,8 +264,6 @@ protected:
wxString m_editor_name; wxString m_editor_name;
wxSize m_help_size; wxSize m_help_size;
wxHtmlHelpController* m_html_ctrl;
wxApp* m_wx_app; wxApp* m_wx_app;
// The PGM_* classes can have difficulties at termination if they // The PGM_* classes can have difficulties at termination if they
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment