improve help file finding after kiway breakage.

This commit is contained in:
Dick Hollenbeck 2014-04-14 13:49:52 -05:00
parent d2e56665f5
commit c39385a5cd
21 changed files with 485 additions and 448 deletions

View File

@ -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

View File

@ -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

View File

@ -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" ) )
{

View File

@ -0,0 +1,126 @@
#include <fctsys.h>
#include <pgm_base.h>
#include <macros.h>
#include <gestfich.h>
/**
* Function FindKicadHelpPath
* finds the absolute path for KiCad "help" (or "help/&ltlanguage&gt")
* 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; i<DIM(possibilities); ++i )
{
fullPath = possibilities[i];
if( wxDirExists( fullPath ) )
{
found = true;
break;
}
}
}
if( found )
{
wxString 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;
}

View File

@ -78,66 +78,6 @@
* like export KICAD=/my_path/kicad if /my_path/kicad is not a default path
*/
// Path list for online help
static wxString s_HelpPathList[] = {
#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
wxT( "end_list" ) // End of list symbol, do not change
};
// Path list for KiCad data files
static wxString s_KicadDataPathList[] = {
#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
wxT( "end_list" ) // End of list symbol, do not change
};
// Path list for KiCad binary files
static wxString s_KicadBinaryPathList[] = {
#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
wxT( "end_list" ) // End of list symbol, do not change
};
wxString MakeReducedFileName( const wxString& fullfilename,
const wxString& default_path,
@ -281,7 +221,7 @@ wxString EDA_FileSelector( const wxString& Title,
defaultname,
dotted_Ext,
Mask,
flag, /* open mode wxFD_OPEN, wxFD_SAVE .. */
flag, // open mode wxFD_OPEN, wxFD_SAVE ..
Frame,
Pos.x, Pos.y );
@ -292,123 +232,48 @@ wxString EDA_FileSelector( const wxString& Title,
}
wxString FindKicadHelpPath()
{
wxString FullPath, LangFullPath, tmp;
wxString LocaleString;
bool PathFound = false;
/* find kicad/help/ */
tmp = Pgm().GetExecutablePath();
if( tmp.Last() == '/' )
tmp.RemoveLast();
FullPath = tmp.BeforeLast( '/' ); // cd ..
FullPath += wxT( "/doc/help/" );
LocaleString = Pgm().GetLocale()->GetCanonicalName();
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<DIM(possibilities); ++i )
{
if( s_KicadBinaryPathList[ii] == wxT( "end_list" ) )
break;
fullFileName = possibilities[i] + shortname;
FullFileName = s_KicadBinaryPathList[ii++] + shortname;
if( wxFileExists( FullFileName ) )
return FullFileName;
if( wxFileExists( fullFileName ) )
return fullFileName;
}
return shortname;
@ -418,13 +283,13 @@ wxString FindKicadFile( const wxString& shortname )
int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param,
wxProcess *callback )
{
wxString FullFileName;
wxString fullFileName;
FullFileName = FindKicadFile( ExecFile );
fullFileName = FindKicadFile( ExecFile );
#ifdef __WXMAC__
if( wxFileExists( FullFileName ) || wxDir::Exists( FullFileName ) )
if( wxFileExists( fullFileName ) || wxDir::Exists( fullFileName ) )
{
return ProcessExecute( Pgm().GetExecutablePath() + wxT( "/" )
+ ExecFile + wxT( " " )
@ -435,16 +300,16 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& para
return ProcessExecute( wxT( "/usr/bin/open " ) + param, wxEXEC_ASYNC, callback );
}
#else
if( wxFileExists( FullFileName ) )
if( wxFileExists( fullFileName ) )
{
if( !param.IsEmpty() )
FullFileName += wxT( " " ) + param;
fullFileName += wxT( " " ) + param;
return ProcessExecute( FullFileName, wxEXEC_ASYNC, callback );
return ProcessExecute( fullFileName, wxEXEC_ASYNC, callback );
}
#endif
wxString msg;
msg.Printf( _( "Command <%s> 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<DIM(possibilities); ++i )
{
data_path = possibilities[i];
if( wxDirExists( data_path ) )
{
found = true;
break;
}
}
}
if( PathFound )
if( found )
{
data_path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
@ -569,38 +457,36 @@ bool OpenPDF( const wxString& file )
}
success = false;
command.Empty();
command.clear();
if( !success )
{
#ifndef __WINDOWS__
#if !defined(__WINDOWS__)
AddDelimiterString( filename );
/* here is a list of PDF viewers candidates */
const static wxString tries[] =
// here is a list of PDF viewers candidates
static const wxChar* tries[] =
{
wxT( "/usr/bin/evince" ),
wxT( "/usr/bin/okular" ),
wxT( "/usr/bin/gpdf" ),
wxT( "/usr/bin/konqueror" ),
wxT( "/usr/bin/kpdf" ),
wxT( "/usr/bin/xpdf" ),
wxT( "/usr/bin/open" ), // BSD and OSX file & dir opener
wxT( "/usr/bin/xdg-open" ), // Freedesktop file & dir opener
wxT( "" ),
};
for( int ii = 0; ; ii++ )
for( unsigned ii = 0; ii<DIM(tries); ii++ )
{
if( tries[ii].IsEmpty() )
break;
if( wxFileExists( tries[ii] ) )
{
command = tries[ii] + wxT( " " ) + filename;
command = tries[ii];
command += wxT( ' ' );
command += filename;
break;
}
}
#endif
}
}

View File

@ -55,10 +55,11 @@ static void setSearchPaths( SEARCH_STACK* aDst, KIWAY::FACE_T aId )
// we must add <kicad path>/library and <kicad path>/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 <install dir>/kicad/doc/help
// (often /usr/local/kicad/kicad/doc/help)
// <install dir>/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/<canonical name> like help/en_GB
* help/<short name> like help/en
* help/en
*/
wxLocale* i18n = Pgm().GetLocale();
// Step 1 : Try to find help file in help/<canonical name>
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/<short name>
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;
}

View File

@ -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();

View File

@ -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();

View File

@ -0,0 +1,128 @@
#include <pgm_base.h>
#include <common.h>
/**
* 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 "<CMAKE_INSTALL_PREFIX>/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 "<CMAKE_INSTALL_PREFIX>/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/<canonical name> like help/en_GB
* help/<short name> like help/en
* help/en
*/
wxLocale* i18n = Pgm().GetLocale();
// Step 1 : Try to find help file in help/<canonical name>
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/<short name>
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;
}

View File

@ -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() );

View File

@ -59,6 +59,8 @@ struct BIN_MOD
wxString m_help_file;
SEARCH_STACK m_search;
};
#endif // BIN_MOD_H_

View File

@ -589,4 +589,25 @@ wxString FormatDateLong( const wxDateTime &aDate );
*/
void SystemDirsAppend( SEARCH_STACK* aSearchStack );
/**
* Function SearchHelpFileFullPath
* returns the help file's full path.
* <p>
* 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/\<canonical name\> like help/en_GB
* help/\<short name\> like help/en
* help/en
* </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.
* @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_

View File

@ -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/&ltlanguage&gt")
* 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.

View File

@ -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.
* <p>
* 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/\<canonical name\> like help/en_GB
* help/\<short name\> like help/en
* help/en
* </p>
* 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;

View File

@ -86,9 +86,7 @@ public:
//----<Cross Module API>-----------------------------------------------------
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

View File

@ -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 );
};

View File

@ -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,

View File

@ -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;

View File

@ -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();

View File

@ -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

View File

@ -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