From c39385a5cdb4e45ba007c4a00d26562040364972 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 14 Apr 2014 13:49:52 -0500 Subject: [PATCH] improve help file finding after kiway breakage. --- common/CMakeLists.txt | 2 + common/basicframe.cpp | 67 ++++--- common/eda_doc.cpp | 15 +- common/findkicadhelppath.cpp.notused | 126 ++++++++++++ common/gestfich.cpp | 286 ++++++++------------------- common/kiface_i.cpp | 90 +-------- common/pgm_base.cpp | 53 ++--- common/search_stack.cpp | 25 --- common/searchhelpfilefullpath.cpp | 128 ++++++++++++ cvpcb/cvframe.cpp | 7 - include/bin_mod.h | 2 + include/common.h | 21 ++ include/gestfich.h | 22 --- include/kiface_i.h | 26 +-- include/pgm_base.h | 12 +- include/search_stack.h | 9 - include/wxstruct.h | 9 + kicad/kicad.h | 5 + kicad/mainframe.cpp | 21 +- kicad/pgm_kicad.h | 2 + kicad/tree_project_frame.cpp | 5 +- 21 files changed, 485 insertions(+), 448 deletions(-) create mode 100644 common/findkicadhelppath.cpp.notused create mode 100644 common/searchhelpfilefullpath.cpp diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index f6deda5e49..cb3d0fceb6 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -172,6 +172,7 @@ set( COMMON_SRCS eda_dde.cpp eda_doc.cpp filter_reader.cpp +# findkicadhelppath.cpp.notused deprecated, use searchhelpfilefullpath.cpp gestfich.cpp getrunningmicrosecs.cpp grid_tricks.cpp @@ -189,6 +190,7 @@ set( COMMON_SRCS ptree.cpp reporter.cpp richio.cpp + searchhelpfilefullpath.cpp search_stack.cpp selcolor.cpp systemdirsappend.cpp diff --git a/common/basicframe.cpp b/common/basicframe.cpp index 3efb4af478..f8a170211a 100644 --- a/common/basicframe.cpp +++ b/common/basicframe.cpp @@ -271,6 +271,18 @@ wxConfigBase* EDA_BASE_FRAME::config() } +const SEARCH_STACK& EDA_BASE_FRAME::sys_search() +{ + return Kiface().KifaceSearch(); +} + + +wxString EDA_BASE_FRAME::help_name() +{ + return Kiface().GetHelpFileName(); +} + + void EDA_BASE_FRAME::PrintMsg( const wxString& text ) { SetStatusText( text ); @@ -327,33 +339,28 @@ wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type, void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event ) { - wxString msg; + const SEARCH_STACK& search = sys_search(); /* We have to get document for beginners, - * or the the full specific doc + * or the full specific doc * if event id is wxID_INDEX, we want the document for beginners. * else the specific doc file (its name is in Kiface().GetHelpFileName()) * The document for beginners is the same for all KiCad utilities */ if( event.GetId() == wxID_INDEX ) { - // Temporarily change the help filename - wxString tmp = Kiface().GetHelpFileName(); - // Search for "getting_started_in_kicad.pdf" or "Getting_Started_in_KiCad.pdf" - Kiface().SetHelpFileName( wxT( "getting_started_in_kicad.pdf" ) ); - wxString helpFile = Kiface().GetHelpFile(); + wxString helpFile = SearchHelpFileFullPath( search, wxT( "getting_started_in_kicad.pdf" ) ); if( !helpFile ) - { // Try to find "Getting_Started_in_KiCad.pdf" - Kiface().SetHelpFileName( wxT( "Getting_Started_in_KiCad.pdf" ) ); - helpFile = Kiface().GetHelpFile(); - } + helpFile = SearchHelpFileFullPath( search, wxT( "Getting_Started_in_KiCad.pdf" ) ); if( !helpFile ) { - msg.Printf( _( "Help file %s could not be found." ), - GetChars( Kiface().GetHelpFileName() ) ); + wxString msg = wxString::Format( _( + "Help file '%s' could not be found." ), + wxT( "getting_started_in_kicad.pdf" ) + ); wxMessageBox( msg ); } else @@ -361,36 +368,36 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event ) GetAssociatedDocument( this, helpFile ); } - Kiface().SetHelpFileName( tmp ); return; } + wxString base_name = help_name(); + #if defined ONLINE_HELP_FILES_FORMAT_IS_HTML - if( Kiface().GetHtmlHelpController() == NULL ) + wxHtmlHelpController* hc = Pgm().GetHtmlHelpController(); + + wxString helpFile = SearchHelpFileFullPath( search, ); + + if( !!helpFile ) { - Kiface().InitOnLineHelp(); + hc->UseConfig( Pgm().CommonSettings() ); + hc->SetTitleFormat( wxT( "KiCad Help" ) ); + hc->AddBook( helpFile ); } - - if( Kiface().GetHtmlHelpController() ) - { - Kiface().GetHtmlHelpController()->DisplayContents(); - Kiface().GetHtmlHelpController()->Display( Kiface().GetHelpFileName() ); - } - else - { - msg.Printf( _( "Help file %s could not be found." ), GetChars( Kiface().GetHelpFileName() ) ); - wxMessageBox( msg ); - } + hc->DisplayContents(); + hc->Display( helpFile ); #elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF - wxString helpFile = Kiface().GetHelpFile(); + wxString helpFile = SearchHelpFileFullPath( search, base_name ); if( !helpFile ) { - msg.Printf( _( "Help file %s could not be found." ), - GetChars( Kiface().GetHelpFileName() ) ); + wxString msg = wxString::Format( _( + "Help file '%s' could not be found." ), + GetChars( base_name ) + ); wxMessageBox( msg ); } else diff --git a/common/eda_doc.cpp b/common/eda_doc.cpp index 8a4dd423ee..407b1c5ed3 100644 --- a/common/eda_doc.cpp +++ b/common/eda_doc.cpp @@ -64,15 +64,19 @@ bool GetAssociatedDocument( wxFrame* aFrame, const wxPathList* aPaths) { - wxString docname, fullfilename, file_ext; + wxString docname, fullfilename; wxString msg; wxString command; bool success = false; // Is an internet url - static const wxString url_header[3] = { wxT( "http:" ), wxT( "ftp:" ), wxT( "www." ) }; + static const wxChar* url_header[3] = { + wxT( "http:" ), + wxT( "ftp:" ), + wxT( "www." ) + }; - for( int ii = 0; ii < 3; ii++ ) + for( unsigned ii = 0; ii < DIM(url_header); ii++ ) { if( aDocName.First( url_header[ii] ) == 0 ) //. seems an internet url { @@ -133,8 +137,9 @@ bool GetAssociatedDocument( wxFrame* aFrame, return false; } - wxFileName CurrentFileName( fullfilename ); - file_ext = CurrentFileName.GetExt(); + wxFileName currentFileName( fullfilename ); + + wxString file_ext = currentFileName.GetExt(); if( file_ext == wxT( "pdf" ) ) { diff --git a/common/findkicadhelppath.cpp.notused b/common/findkicadhelppath.cpp.notused new file mode 100644 index 0000000000..d2d781ef57 --- /dev/null +++ b/common/findkicadhelppath.cpp.notused @@ -0,0 +1,126 @@ + +#include +#include +#include +#include + + +/** + * Function FindKicadHelpPath + * finds the absolute path for KiCad "help" (or "help/<language>") + * Find path kicad/doc/help/xx/ or kicad/doc/help/: + * from BinDir + * else from environment variable KICAD + * else from one of s_HelpPathList + * typically c:/kicad/doc/help or /usr/share/kicad/help + * or /usr/local/share/kicad/help + * (must have kicad in path name) + * + * xx = iso639-1 language id (2 letters (generic) or 4 letters): + * fr = french (or fr_FR) + * en = English (or en_GB or en_US ...) + * de = deutch + * es = spanish + * pt = portuguese (or pt_BR ...) + * + * default = en (if not found = fr) + */ +wxString FindKicadHelpPath() +{ + bool found = false; + wxString bin_dir = Pgm().GetExecutablePath(); + + if( bin_dir.Last() == '/' ) + bin_dir.RemoveLast(); + + wxString fullPath = bin_dir.BeforeLast( '/' ); // cd .. + + fullPath += wxT( "/doc/help/" ); + + wxString localeString = Pgm().GetLocale()->GetCanonicalName(); + + wxString path_tmp = fullPath; + +#ifdef __WINDOWS__ + path_tmp.MakeLower(); +#endif + + if( path_tmp.Contains( wxT( "kicad" ) ) ) + { + if( wxDirExists( fullPath ) ) + found = true; + } + + // find kicad/help/ from environment variable KICAD + if( !found && Pgm().IsKicadEnvVariableDefined() ) + { + fullPath = Pgm().GetKicadEnvVariable() + wxT( "/doc/help/" ); + + if( wxDirExists( fullPath ) ) + found = true; + } + + if( !found ) + { + // Possibilities online help + const static wxChar* possibilities[] = { +#ifdef __WINDOWS__ + wxT( "c:/kicad/doc/help/" ), + wxT( "d:/kicad/doc/help/" ), + wxT( "c:/Program Files/kicad/doc/help/" ), + wxT( "d:/Program Files/kicad/doc/help/" ), +#else + wxT( "/usr/share/doc/kicad/help/" ), + wxT( "/usr/local/share/doc/kicad/help/" ), + wxT( "/usr/local/kicad/doc/help/" ), // default install for "universal + // tarballs" and build for a server + // (new) + wxT( "/usr/local/kicad/help/" ), // default install for "universal + // tarballs" and build for a server + // (old) +#endif + }; + + for( unsigned i=0; iGetCanonicalName(); - - wxString path_tmp = FullPath; -#ifdef __WINDOWS__ - path_tmp.MakeLower(); -#endif - if( path_tmp.Contains( wxT( "kicad" ) ) ) - { - if( wxDirExists( FullPath ) ) - PathFound = true; - } - - /* find kicad/help/ from environment variable KICAD */ - if( !PathFound && Pgm().IsKicadEnvVariableDefined() ) - { - FullPath = Pgm().GetKicadEnvVariable() + wxT( "/doc/help/" ); - - if( wxDirExists( FullPath ) ) - PathFound = true; - } - - /* find kicad/help/ from "s_HelpPathList" */ - int ii = 0; - - while( !PathFound ) - { - FullPath = s_HelpPathList[ii++]; - - if( FullPath == wxT( "end_list" ) ) - break; - - if( wxDirExists( FullPath ) ) - PathFound = true; - } - - if( PathFound ) - { - LangFullPath = FullPath + LocaleString + UNIX_STRING_DIR_SEP; - - if( wxDirExists( LangFullPath ) ) - return LangFullPath; - - LangFullPath = FullPath + LocaleString.Left( 2 ) + UNIX_STRING_DIR_SEP; - - if( wxDirExists( LangFullPath ) ) - return LangFullPath; - - LangFullPath = FullPath + wxT( "en/" ); - - if( wxDirExists( LangFullPath ) ) - { - return LangFullPath; - } - else - { - LangFullPath = FullPath + wxT( "fr/" ); - - if( wxDirExists( LangFullPath ) ) - return LangFullPath; - } - return FullPath; - } - return wxEmptyString; -} - - wxString FindKicadFile( const wxString& shortname ) { - wxString FullFileName; + // Test the presence of the file in the directory shortname of + // the KiCad binary path. + wxString fullFileName = Pgm().GetExecutablePath() + shortname; - /* Test the presence of the file in the directory shortname of - * the KiCad binary path. - */ - FullFileName = Pgm().GetExecutablePath() + shortname; + if( wxFileExists( fullFileName ) ) + return fullFileName; - if( wxFileExists( FullFileName ) ) - return FullFileName; - - /* Test the presence of the file in the directory shortname - * defined by the environment variable KiCad. - */ + // Test the presence of the file in the directory shortname + // defined by the environment variable KiCad. if( Pgm().IsKicadEnvVariableDefined() ) { - FullFileName = Pgm().GetKicadEnvVariable() + shortname; + fullFileName = Pgm().GetKicadEnvVariable() + shortname; - if( wxFileExists( FullFileName ) ) - return FullFileName; + if( wxFileExists( fullFileName ) ) + return fullFileName; } - /* find binary file from default path list: - * /usr/local/kicad/linux or c:/kicad/winexe - * (see s_KicadDataPathList) */ - int ii = 0; + // find binary file from possibilities list: + // /usr/local/kicad/linux or c:/kicad/winexe - while( 1 ) + // Path list for KiCad binary files + const static wxChar* possibilities[] = { +#ifdef __WINDOWS__ + wxT( "c:/kicad/bin/" ), + wxT( "d:/kicad/bin/" ), + wxT( "c:/Program Files/kicad/bin/" ), + wxT( "d:/Program Files/kicad/bin/" ), +#else + wxT( "/usr/bin/" ), + wxT( "/usr/local/bin/" ), + wxT( "/usr/local/kicad/bin/" ), +#endif + }; + + for( unsigned i=0; i could not found" ), GetChars( FullFileName ) ); + msg.Printf( _( "Command <%s> could not found" ), GetChars( fullFileName ) ); DisplayError( frame, msg, 20 ); return -1; } @@ -452,13 +317,13 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& para wxString KicadDatasPath() { - bool PathFound = false; + bool found = false; wxString data_path; if( Pgm().IsKicadEnvVariableDefined() ) // Path defined by the KICAD environment variable. { data_path = Pgm().GetKicadEnvVariable(); - PathFound = true; + found = true; } else // Path of executables. { @@ -485,33 +350,56 @@ wxString KicadDatasPath() if( wxDirExists( data_path ) ) { - PathFound = true; + found = true; } else if( wxDirExists( old_path ) ) { data_path = old_path; - PathFound = true; + found = true; } } } - /* find KiCad from default path list: - * /usr/local/kicad/ or c:/kicad/ - * (see s_KicadDataPathList) */ - int ii = 0; - - while( !PathFound ) + if( !found ) { - if( s_KicadDataPathList[ii] == wxT( "end_list" ) ) - break; + // find KiCad from possibilities list: + // /usr/local/kicad/ or c:/kicad/ - data_path = s_KicadDataPathList[ii++]; + const static wxChar* possibilities[] = { +#ifdef __WINDOWS__ + wxT( "c:/kicad/share/" ), + wxT( "d:/kicad/share/" ), + wxT( "c:/kicad/" ), + wxT( "d:/kicad/" ), + wxT( "c:/Program Files/kicad/share/" ), + wxT( "d:/Program Files/kicad/share/" ), + wxT( "c:/Program Files/kicad/" ), + wxT( "d:/Program Files/kicad/" ), +#else + wxT( "/usr/share/kicad/" ), + wxT( "/usr/local/share/kicad/" ), + wxT( "/usr/local/kicad/share/" ), // default data path for "universal + // tarballs" and build for a server + // (new) + wxT( "/usr/local/kicad/" ), // default data path for "universal + // tarballs" and build for a server + // (old) +#endif + }; - if( wxDirExists( data_path ) ) - PathFound = true; + for( unsigned i=0; i/library and /library/doc if( aId == KIWAY::FACE_SCH ) { + // Add schematic doc file path (library/doc) to search path list. + fn.AppendDir( wxT( "library" ) ); aDst->AddPaths( fn.GetPath() ); - // Add schematic doc file path (library/doc)to search path list. fn.AppendDir( wxT( "doc" ) ); aDst->AddPaths( fn.GetPath() ); @@ -85,8 +86,10 @@ static void setSearchPaths( SEARCH_STACK* aDst, KIWAY::FACE_T aId ) aDst->AddPaths( fn.GetPath() ); } + aDst->AddPaths( wxT( "/usr/local/share" ) ); + #if 1 && defined(DEBUG) - aDst->Show( "kiway" ); + aDst->Show( "kiface" ); #endif } @@ -121,86 +124,3 @@ void KIFACE_I::end_common() m_bm.End(); } - -wxString KIFACE_I::GetHelpFile() -{ - wxString fn; - wxArrayString subdirs; - wxArrayString altsubdirs; - - // FIXME: This is not the ideal way to handle this. Unfortunately, the - // CMake install paths seem to be a moving target so this crude - // hack solves the problem of install path differences between - // Windows and non-Windows platforms. - - // Partially fixed, but must be enhanced - - // Create subdir tree for "standard" linux distributions, when KiCad comes - // from a distribution files are in /usr/share/doc/kicad/help and binaries - // in /usr/bin or /usr/local/bin - subdirs.Add( wxT( "share" ) ); - subdirs.Add( wxT( "doc" ) ); - subdirs.Add( wxT( "kicad" ) ); - subdirs.Add( wxT( "help" ) ); - - // Create subdir tree for linux and Windows KiCad pack. - // Note the pack form under linux is also useful if a user wants to - // install KiCad to a server because there is only one path to mount - // or export (something like /usr/local/kicad). - // files are in /kicad/doc/help - // (often /usr/local/kicad/kicad/doc/help) - // /kicad/ is retrieved from m_BinDir - altsubdirs.Add( wxT( "doc" ) ); - altsubdirs.Add( wxT( "help" ) ); - - /* Search for a help file. - * we *must* find a help file. - * so help is searched in directories in this order: - * help/ like help/en_GB - * help/ like help/en - * help/en - */ - - wxLocale* i18n = Pgm().GetLocale(); - - // Step 1 : Try to find help file in help/ - subdirs.Add( i18n->GetCanonicalName() ); - altsubdirs.Add( i18n->GetCanonicalName() ); - - fn = m_bm.m_search.FindFileInSearchPaths( m_bm.m_help_file, &altsubdirs ); - - if( !fn ) - fn = m_bm.m_search.FindFileInSearchPaths( m_bm.m_help_file, &subdirs ); - - // Step 2 : if not found Try to find help file in help/ - if( !fn ) - { - subdirs.RemoveAt( subdirs.GetCount() - 1 ); - altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 ); - - // wxLocale::GetName() does not return always the short name - subdirs.Add( i18n->GetName().BeforeLast( '_' ) ); - altsubdirs.Add( i18n->GetName().BeforeLast( '_' ) ); - - fn = m_bm.m_search.FindFileInSearchPaths( m_bm.m_help_file, &altsubdirs ); - - if( !fn ) - fn = m_bm.m_search.FindFileInSearchPaths( m_bm.m_help_file, &subdirs ); - } - - // Step 3 : if not found Try to find help file in help/en - if( !fn ) - { - subdirs.RemoveAt( subdirs.GetCount() - 1 ); - altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 ); - subdirs.Add( wxT( "en" ) ); - altsubdirs.Add( wxT( "en" ) ); - - fn = m_bm.m_search.FindFileInSearchPaths( m_bm.m_help_file, &altsubdirs ); - - if( !fn ) - fn = m_bm.m_search.FindFileInSearchPaths( m_bm.m_help_file, &subdirs ); - } - - return fn; -} diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp index e0af909af6..1789f939ed 100644 --- a/common/pgm_base.cpp +++ b/common/pgm_base.cpp @@ -297,6 +297,13 @@ 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; } @@ -415,30 +422,18 @@ bool PGM_BASE::initPgm() } -void PGM_BASE::SetHtmlHelpController( wxHtmlHelpController* aController ) +void PGM_BASE::initHtmlHelpController() { - delete m_html_ctrl; - m_html_ctrl = aController; -} - - -void PGM_BASE::InitOnLineHelp() -{ - wxString fullfilename = FindKicadHelpPath(); - #if defined ONLINE_HELP_FILES_FORMAT_IS_HTML - m_HelpFileName = fullfilename + wxT( ".html" ); - fullfilename += wxT( "kicad.hhp" ); - if( wxFileExists( fullfilename ) ) - { - m_html_ctrl = new wxHtmlHelpController( wxHF_TOOLBAR | wxHF_CONTENTS | - wxHF_PRINT | wxHF_OPEN_FILES - /*| wxHF_SEARCH */ ); - m_html_ctrl->UseConfig( m_common_settings ); - m_html_ctrl->SetTitleFormat( wxT( "KiCad Help" ) ); - m_html_ctrl->AddBook( fullfilename ); - } + 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; @@ -449,10 +444,22 @@ void PGM_BASE::InitOnLineHelp() } +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() { -// Apple MacOSx -#ifdef __APPLE__ +#ifdef __APPLE__ // Apple MacOSx // Derive path from location of the app bundle CFBundleRef mainBundle = CFBundleGetMainBundle(); diff --git a/common/search_stack.cpp b/common/search_stack.cpp index f4792f89c2..d9f6a5c870 100644 --- a/common/search_stack.cpp +++ b/common/search_stack.cpp @@ -104,31 +104,6 @@ void SEARCH_STACK::AddPaths( const wxString& aPaths, int aIndex ) } -wxString SEARCH_STACK::FindFileInSearchPaths( - const wxString& aFilename, const wxArrayString* aSubdirs ) -{ - wxPathList paths; - - for( unsigned i = 0; i < GetCount(); ++i ) - { - wxFileName fn( (*this)[i] ); - - if( aSubdirs ) - { - for( unsigned j = 0; j < aSubdirs->GetCount(); j++ ) - fn.AppendDir( (*aSubdirs)[j] ); - } - - if( fn.DirExists() ) - { - paths.Add( fn.GetPath() ); - } - } - - return paths.FindValidPath( aFilename ); -} - - void RETAINED_PATH::Clear() { m_retained_path.Clear(); diff --git a/common/searchhelpfilefullpath.cpp b/common/searchhelpfilefullpath.cpp new file mode 100644 index 0000000000..3ce17dfbd2 --- /dev/null +++ b/common/searchhelpfilefullpath.cpp @@ -0,0 +1,128 @@ + +#include +#include + + + +/** + * Function FindFileInSearchPaths + * looks in "this" for \a aFilename, but first modifies every search + * path by appending a list of path fragments from aSubdirs. That modification + * is not rentative. + */ +wxString FindFileInSearchPaths( const SEARCH_STACK& aStack, + const wxString& aFilename, const wxArrayString* aSubdirs ) +{ + wxPathList paths; + + for( unsigned i = 0; i < aStack.GetCount(); ++i ) + { + wxFileName fn( aStack[i], wxEmptyString ); + + if( aSubdirs ) + { + for( unsigned j = 0; j < aSubdirs->GetCount(); j++ ) + fn.AppendDir( (*aSubdirs)[j] ); + } + + if( fn.DirExists() ) + { + paths.Add( fn.GetPath() ); + } + } + + return paths.FindValidPath( aFilename ); +} + + +// See also FindKicadHelpPath.cpp.notused. +wxString SearchHelpFileFullPath( const SEARCH_STACK& aSStack, const wxString& aBaseName ) +{ + wxArrayString subdirs; + wxArrayString altsubdirs; + SEARCH_STACK ss = aSStack; + + // It might already be in aSStack, but why depend on other code + // far away when it's so easy to add it again (to our copy) as the first place to look. + // This is CMAKE_INSTALL_PREFIX: + ss.AddPaths( wxT( DEFAULT_INSTALL_PATH ), 0 ); + + // If there's a KICAD environment variable set, use that guy's path also + ss.AddPaths( Pgm().GetKicadEnvVariable(), 0 ); + +#if 1 // && defined(__linux__) + // Based on kicad-doc.bzr/CMakeLists.txt, line 20, the help files are + // installed into "/share/doc/kicad/help" for linux. + // This is ${KICAD_HELP} var in that CMakeLists.txt file. + // Below we account for an international subdirectory. + subdirs.Add( wxT( "share" ) ); + subdirs.Add( wxT( "doc" ) ); + subdirs.Add( wxT( "kicad" ) ); + subdirs.Add( wxT( "help" ) ); +#endif + +#if 1 // && defined(__WINDOWS__) + // Based on kicad-doc.bzr/CMakeLists.txt, line 35, the help files are + // installed into "/doc/help" for Windows. + // This is ${KICAD_HELP} var in that CMakeLists.txt file. + // Below we account for an international subdirectory. + altsubdirs.Add( wxT( "doc" ) ); + altsubdirs.Add( wxT( "help" ) ); +#endif + + /* Search for a help file. + * we *must* find a help file. + * so help is searched in directories in this order: + * help/ like help/en_GB + * help/ like help/en + * help/en + */ + + wxLocale* i18n = Pgm().GetLocale(); + + // Step 1 : Try to find help file in help/ + subdirs.Add( i18n->GetCanonicalName() ); + altsubdirs.Add( i18n->GetCanonicalName() ); + +#if defined(DEBUG) && 0 + ss.Show( __func__ ); + printf( "%s: m_help_file:'%s'\n", __func__, TO_UTF8( aBaseName ) ); +#endif + + wxString fn = FindFileInSearchPaths( ss, aBaseName, &altsubdirs ); + + if( !fn ) + fn = FindFileInSearchPaths( ss, aBaseName, &subdirs ); + + // Step 2 : if not found Try to find help file in help/ + if( !fn ) + { + subdirs.RemoveAt( subdirs.GetCount() - 1 ); + altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 ); + + // wxLocale::GetName() does not return always the short name + subdirs.Add( i18n->GetName().BeforeLast( '_' ) ); + altsubdirs.Add( i18n->GetName().BeforeLast( '_' ) ); + + fn = FindFileInSearchPaths( ss, aBaseName, &altsubdirs ); + + if( !fn ) + fn = FindFileInSearchPaths( ss, aBaseName, &subdirs ); + } + + // Step 3 : if not found Try to find help file in help/en + if( !fn ) + { + subdirs.RemoveAt( subdirs.GetCount() - 1 ); + altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 ); + subdirs.Add( wxT( "en" ) ); + altsubdirs.Add( wxT( "en" ) ); + + fn = FindFileInSearchPaths( ss, aBaseName, &altsubdirs ); + + if( !fn ) + fn = FindFileInSearchPaths( ss, aBaseName, &subdirs ); + } + + return fn; +} diff --git a/cvpcb/cvframe.cpp b/cvpcb/cvframe.cpp index 6fc1292bc3..c878e61201 100644 --- a/cvpcb/cvframe.cpp +++ b/cvpcb/cvframe.cpp @@ -301,13 +301,6 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) } } - // Close the help frame - if( Pgm().GetHtmlHelpController() ) - { - if( Pgm().GetHtmlHelpController()->GetFrame() )// returns NULL if no help frame active - Pgm().GetHtmlHelpController()->GetFrame()->Close( true ); - } - if( m_NetlistFileName.IsOk() ) { UpdateFileHistory( m_NetlistFileName.GetFullPath() ); diff --git a/include/bin_mod.h b/include/bin_mod.h index edfc9cf8e7..1f687ad480 100644 --- a/include/bin_mod.h +++ b/include/bin_mod.h @@ -59,6 +59,8 @@ struct BIN_MOD wxString m_help_file; SEARCH_STACK m_search; + + }; #endif // BIN_MOD_H_ diff --git a/include/common.h b/include/common.h index a6b282df08..31d95c897f 100644 --- a/include/common.h +++ b/include/common.h @@ -589,4 +589,25 @@ wxString FormatDateLong( const wxDateTime &aDate ); */ void SystemDirsAppend( SEARCH_STACK* aSearchStack ); + +/** + * Function SearchHelpFileFullPath + * returns the help file's full path. + *

+ * Return the KiCad help file with 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: + * help/\ like help/en_GB + * help/\ like help/en + * help/en + *

+ * @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. + * @return wxEmptyString is returned if aBaseName is not found, else the full path & filename. + */ +wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxString& aBaseName ); + + #endif // INCLUDE__COMMON_H_ diff --git a/include/gestfich.h b/include/gestfich.h index 324a767eb0..6a972ea059 100644 --- a/include/gestfich.h +++ b/include/gestfich.h @@ -89,28 +89,6 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, */ void AddDelimiterString( wxString& string ); -/** - * Function FindKicadHelpPath - * finds the absolute path for KiCad "help" (or "help/<language>") - * Find path kicad/doc/help/xx/ or kicad/doc/help/: - * from BinDir - * else from environment variable KICAD - * else from one of s_HelpPathList - * typically c:/kicad/doc/help or /usr/share/kicad/help - * or /usr/local/share/kicad/help - * (must have kicad in path name) - * - * xx = iso639-1 language id (2 letters (generic) or 4 letters): - * fr = french (or fr_FR) - * en = English (or en_GB or en_US ...) - * de = deutch - * es = spanish - * pt = portuguese (or pt_BR ...) - * - * default = en (if not found = fr) - */ -wxString FindKicadHelpPath(); - /** * Function KicadDatasPath * returns the data path common to KiCad. diff --git a/include/kiface_i.h b/include/kiface_i.h index 23f89dffbf..d764c9de35 100644 --- a/include/kiface_i.h +++ b/include/kiface_i.h @@ -100,33 +100,17 @@ public: wxConfigBase* KifaceSettings() const { return m_bm.m_config; } - const wxString& GetHelpFileName() const { return m_bm.m_help_file; } - void SetHelpFileName( const wxString& aFileName ) { m_bm.m_help_file = aFileName; } - /** - * Function GetHelpFile - * gets the help file path. - *

- * Return the KiCad help file with path. The base paths defined in - * m_searchPaths are tested for a valid file. The path returned can - * be relative depending on the paths added to m_searchPaths. See the - * documentation for wxPathList for more information. If the help file - * for the current locale is not found, an attempt to find the English - * version of the help file is made. - * wxEmptyString is returned if help file not found. - * Help file is searched in directories in this order: - * help/\ like help/en_GB - * help/\ like help/en - * help/en - *

+ * Function GetHelpFileName + * returns just the basename portion of the current help file. */ - wxString GetHelpFile(); + const wxString& GetHelpFileName() const { return m_bm.m_help_file; } - wxFileHistory& GetFileHistory() { return m_bm.m_history; } + wxFileHistory& GetFileHistory() { return m_bm.m_history; } /// Only for DSO specific 'non-library' files. /// (The library search path is in the PROJECT class.) - SEARCH_STACK& KifaceSearch() { return m_bm.m_search; } + SEARCH_STACK& KifaceSearch() { return m_bm.m_search; } private: KIWAY::FACE_T m_id; diff --git a/include/pgm_base.h b/include/pgm_base.h index 9ffd028fc7..89587d00a1 100644 --- a/include/pgm_base.h +++ b/include/pgm_base.h @@ -86,9 +86,7 @@ public: //--------------------------------------------------------- - VTBL_ENTRY wxHtmlHelpController* GetHtmlHelpController() { return m_html_ctrl; } - - VTBL_ENTRY void SetHtmlHelpController( wxHtmlHelpController* aController ); + VTBL_ENTRY wxHtmlHelpController* HtmlHelpController(); VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings; } @@ -161,12 +159,6 @@ public: VTBL_ENTRY void SetLanguagePath(); - /** - * Function InitOnLineHelp - * initializes KiCad's online help. - */ - VTBL_ENTRY void InitOnLineHelp(); - /** * Function ReadPdfBrowserInfos * reads the PDF browser choice from the common configuration. @@ -217,6 +209,8 @@ protected: */ bool initPgm(); + void initHtmlHelpController(); + /** * Function loadCommonSettings * loads the program (process) settings subset which are stored in .kicad_common diff --git a/include/search_stack.h b/include/search_stack.h index c3dd9a1b9a..42534bb74a 100644 --- a/include/search_stack.h +++ b/include/search_stack.h @@ -57,15 +57,6 @@ public: * ";" on windows, or ":" | ";" on unix. */ void RemovePaths( const wxString& aPaths ); - - /** - * Function FindFileInSearchPaths - * looks in "this" for \a aFilename, but first modifies every search - * path by appending a list of path fragments from aSubdirs. That modification - * is not rentative. - */ - wxString FindFileInSearchPaths( const wxString& aFilename, - const wxArrayString* aSubdirs = NULL ); }; diff --git a/include/wxstruct.h b/include/wxstruct.h index fb79aae9a7..dbf8679ef5 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -186,6 +186,15 @@ protected: */ virtual wxConfigBase* config(); + /** + * Function sys_search + * returns a SEARCH_STACK pertaining to entire program, and is overloaded in + * KICAD_MANAGER_FRAME + */ + virtual const SEARCH_STACK& sys_search(); + + virtual wxString help_name(); + public: EDA_BASE_FRAME( wxWindow* aParent, ID_DRAWFRAME_TYPE aFrameType, const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize, diff --git a/kicad/kicad.h b/kicad/kicad.h index 129d29dc82..ffaac5afdc 100644 --- a/kicad/kicad.h +++ b/kicad/kicad.h @@ -123,6 +123,11 @@ class KICAD_MANAGER_FRAME : public EDA_BASE_FRAME protected: wxConfigBase* config(); // override EDA_BASE_FRAME virtual + const SEARCH_STACK& sys_search(); // override EDA_BASE_FRAME virtual + + wxString help_name(); // override EDA_BASE_FRAME virtual + + public: TREE_PROJECT_FRAME* m_LeftWin; LAUNCHER_PANEL* m_Launcher; diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp index 55f5f1ba0b..e74c471dc1 100644 --- a/kicad/mainframe.cpp +++ b/kicad/mainframe.cpp @@ -123,6 +123,18 @@ wxConfigBase* KICAD_MANAGER_FRAME::config() } +const SEARCH_STACK& KICAD_MANAGER_FRAME::sys_search() +{ + return Pgm().SysSearch(); +} + + +wxString KICAD_MANAGER_FRAME::help_name() +{ + return Pgm().GetHelpFileName(); +} + + void KICAD_MANAGER_FRAME::PrintMsg( const wxString& aText ) { m_MessagesBox->AppendText( aText ); @@ -157,15 +169,6 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event ) Event.SetCanVeto( true ); - // Close the help frame - if( Pgm().GetHtmlHelpController() ) - { - if( Pgm().GetHtmlHelpController()->GetFrame() ) // returns NULL if no help frame active - Pgm().GetHtmlHelpController()->GetFrame()->Close( true ); - - Pgm().SetHtmlHelpController( NULL ); - } - m_LeftWin->Show( false ); Destroy(); diff --git a/kicad/pgm_kicad.h b/kicad/pgm_kicad.h index 5de4cebbb7..bb1069efac 100644 --- a/kicad/pgm_kicad.h +++ b/kicad/pgm_kicad.h @@ -58,6 +58,8 @@ public: SEARCH_STACK& SysSearch() { return m_bm.m_search; } + wxString GetHelpFileName() { return m_bm.m_help_file; } + protected: // The PGM_* classes can have difficulties at termination if they diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index 6e6c706371..0cc4add54d 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -94,10 +94,10 @@ static const wxChar* s_allowedExtensionsToList[] = */ /* File extension definitions. */ -const wxString TextFileExtension( wxT( "txt" ) ); +const wxChar TextFileExtension[] = wxT( "txt" ); /* File wildcard definitions. */ -const wxString TextFileWildcard( wxT( "Text files (*.txt)|*.txt" ) ); +const wxChar TextFileWildcard[] = wxT( "Text files (*.txt)|*.txt" ); /** @@ -177,7 +177,6 @@ void TREE_PROJECT_FRAME::RemoveFilter( const wxString& filter ) } - /** * Called by the popup menu in the tree frame * Creates a new subdirectory inside the current kicad project directory