2008-04-24 16:55:35 +00:00
|
|
|
|
/***************/
|
|
|
|
|
/* eda_doc.cpp */
|
|
|
|
|
/***************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
#include "appl_wxstruct.h"
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "confirm.h"
|
|
|
|
|
#include "gestfich.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
#include <wx/mimetype.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
#include <wx/tokenzr.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
#include <wx/filename.h>
|
2009-10-13 11:49:08 +00:00
|
|
|
|
#include "macros.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/*****************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
|
void WinEDA_App::ReadPdfBrowserInfos()
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/*****************************************/
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/* Read from Common config the Pdf browser choice
|
2008-04-24 16:55:35 +00:00
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
|
wxASSERT( m_EDA_CommonConfig != NULL );
|
|
|
|
|
|
|
|
|
|
m_PdfBrowserIsDefault = m_EDA_CommonConfig->Read( wxT( "PdfBrowserIsDefault" ),
|
|
|
|
|
true );
|
|
|
|
|
m_PdfBrowser = m_EDA_CommonConfig->Read( wxT( "PdfBrowserName" ),
|
|
|
|
|
wxEmptyString );
|
|
|
|
|
|
2008-04-24 16:55:35 +00:00
|
|
|
|
if( m_PdfBrowser.IsEmpty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
|
m_PdfBrowserIsDefault = true;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/*****************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
|
void WinEDA_App::WritePdfBrowserInfos()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/*****************************************/
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/* Write into Common config the Pdf browser choice
|
2008-04-24 16:55:35 +00:00
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
|
wxASSERT( m_EDA_CommonConfig != NULL );
|
|
|
|
|
|
2008-04-24 16:55:35 +00:00
|
|
|
|
if( m_PdfBrowser.IsEmpty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
|
m_PdfBrowserIsDefault = true;
|
|
|
|
|
|
|
|
|
|
m_EDA_CommonConfig->Write( wxT( "PdfBrowserIsDefault" ),
|
|
|
|
|
m_PdfBrowserIsDefault );
|
2008-04-24 16:55:35 +00:00
|
|
|
|
m_EDA_CommonConfig->Write( wxT( "PdfBrowserName" ), m_PdfBrowser );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
// Mime type extensions (PDF files are not considered here)
|
2008-04-24 16:55:35 +00:00
|
|
|
|
static wxMimeTypesManager* mimeDatabase;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
static const wxFileTypeInfo EDAfallbacks[] =
|
2008-04-24 16:55:35 +00:00
|
|
|
|
{
|
|
|
|
|
wxFileTypeInfo( wxT( "text/html" ),
|
|
|
|
|
wxT( "wxhtml %s" ),
|
|
|
|
|
wxT( "wxhtml %s" ),
|
|
|
|
|
wxT( "html document (from Kicad)" ),
|
2008-06-29 18:51:38 +00:00
|
|
|
|
wxT( "htm" ), wxT( "html" ),NULL ),
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
|
|
|
|
wxFileTypeInfo( wxT( "application/sch" ),
|
|
|
|
|
wxT( "eeschema %s" ),
|
|
|
|
|
wxT( "eeschema -p %s" ),
|
|
|
|
|
wxT( "sch document (from Kicad)" ),
|
2008-06-29 18:51:38 +00:00
|
|
|
|
wxT( "sch" ), wxT( "SCH" ), NULL ),
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
|
|
|
|
// must terminate the table with this!
|
|
|
|
|
wxFileTypeInfo()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2009-04-07 15:54:40 +00:00
|
|
|
|
/** Function GetAssociatedDocument
|
|
|
|
|
* open a document (file) with the suitable browser
|
|
|
|
|
* @param aFrame = main frame
|
2008-06-29 18:51:38 +00:00
|
|
|
|
* if DocName is starting by http: or ftp: or www. the default internet browser is launched
|
2009-04-07 15:54:40 +00:00
|
|
|
|
* @param aDocName = filename of file to open (Full filename or short filename)
|
|
|
|
|
* @param aPaths = a wxPathList to explore.
|
|
|
|
|
* if NULL or aDocName is a full filename, aPath is not used.
|
2009-04-12 14:39:54 +00:00
|
|
|
|
*/
|
|
|
|
|
bool GetAssociatedDocument( wxFrame* aFrame,
|
2009-04-07 15:54:40 +00:00
|
|
|
|
const wxString& aDocName,
|
|
|
|
|
const wxPathList* aPaths)
|
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2009-04-12 14:39:54 +00:00
|
|
|
|
wxString docname, fullfilename, file_ext;
|
2009-04-07 11:53:58 +00:00
|
|
|
|
wxString msg;
|
2008-04-24 16:55:35 +00:00
|
|
|
|
wxString command;
|
|
|
|
|
bool success = FALSE;
|
|
|
|
|
|
|
|
|
|
// Is an internet url
|
|
|
|
|
static const wxString url_header[3] = { wxT( "http:" ), wxT( "ftp:" ), wxT( "www." ) };
|
|
|
|
|
|
|
|
|
|
for( int ii = 0; ii < 3; ii++ )
|
|
|
|
|
{
|
2009-04-07 15:54:40 +00:00
|
|
|
|
if( aDocName.First( url_header[ii] ) == 0 ) //. seems an internet url
|
2008-04-24 16:55:35 +00:00
|
|
|
|
{
|
2009-04-07 15:54:40 +00:00
|
|
|
|
wxLaunchDefaultBrowser( aDocName );
|
2008-04-24 16:55:35 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
|
docname = aDocName;
|
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
|
docname.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP );
|
|
|
|
|
#else
|
|
|
|
|
docname.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2008-04-24 16:55:35 +00:00
|
|
|
|
/* Compute the full file name */
|
2009-04-07 15:54:40 +00:00
|
|
|
|
if( wxIsAbsolutePath( aDocName ) || aPaths == NULL)
|
|
|
|
|
fullfilename = aDocName;
|
2009-04-21 17:56:27 +00:00
|
|
|
|
/* If the file exists, this is a trivial case: return the filename "as this"
|
|
|
|
|
* the name can be an absolute path, or a relative path like ./filename or ../<filename>
|
|
|
|
|
*/
|
|
|
|
|
else if( wxFileName::FileExists( aDocName ) )
|
|
|
|
|
fullfilename = aDocName;
|
2008-04-24 16:55:35 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2009-04-07 15:54:40 +00:00
|
|
|
|
fullfilename = aPaths->FindValidPath( aDocName );
|
2008-04-24 16:55:35 +00:00
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2008-04-24 16:55:35 +00:00
|
|
|
|
wxString mask( wxT( "*" ) ), extension;
|
|
|
|
|
|
2007-06-13 15:35:40 +00:00
|
|
|
|
#ifdef __WINDOWS__
|
2008-04-24 16:55:35 +00:00
|
|
|
|
mask += wxT( ".*" );
|
|
|
|
|
extension = wxT( ".*" );
|
2007-06-13 15:35:40 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2008-04-24 16:55:35 +00:00
|
|
|
|
if( wxIsWild( fullfilename ) )
|
|
|
|
|
{
|
|
|
|
|
fullfilename =
|
|
|
|
|
EDA_FileSelector( _( "Doc Files" ), /* Titre de la fenetre */
|
|
|
|
|
wxPathOnly( fullfilename ), /* Chemin par defaut */
|
|
|
|
|
fullfilename, /* nom fichier par defaut */
|
|
|
|
|
extension, /* extension par defaut */
|
|
|
|
|
mask, /* Masque d'affichage */
|
2009-04-07 15:54:40 +00:00
|
|
|
|
aFrame, /* parent frame */
|
2008-04-24 16:55:35 +00:00
|
|
|
|
wxFD_OPEN, /* wxSAVE, wxFD_OPEN ..*/
|
|
|
|
|
TRUE, /* true = ne change pas le repertoire courant */
|
|
|
|
|
wxPoint( -1, -1 )
|
2008-06-29 18:51:38 +00:00
|
|
|
|
);
|
2008-04-24 16:55:35 +00:00
|
|
|
|
if( fullfilename.IsEmpty() )
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !wxFileExists( fullfilename ) )
|
|
|
|
|
{
|
2009-04-07 11:53:58 +00:00
|
|
|
|
msg = _( "Doc File " );
|
2009-04-23 15:02:18 +00:00
|
|
|
|
msg << wxT("\"") << aDocName << wxT("\"") << _( " not found" );
|
2009-04-07 15:54:40 +00:00
|
|
|
|
DisplayError( aFrame, msg );
|
2008-04-24 16:55:35 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
wxFileName CurrentFileName( fullfilename );
|
|
|
|
|
file_ext = CurrentFileName.GetExt();
|
|
|
|
|
if( file_ext == wxT( "pdf" ) )
|
2008-04-24 16:55:35 +00:00
|
|
|
|
{
|
2008-06-29 18:51:38 +00:00
|
|
|
|
success = OpenPDF( fullfilename );
|
|
|
|
|
return success;
|
|
|
|
|
}
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
/* Try to launch some browser (usefull under linux) */
|
|
|
|
|
wxFileType* filetype;
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
wxString type;
|
|
|
|
|
filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( file_ext );
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
if( !filetype ) // 2ieme tentative
|
|
|
|
|
{
|
|
|
|
|
mimeDatabase = new wxMimeTypesManager;
|
|
|
|
|
mimeDatabase->AddFallbacks( EDAfallbacks );
|
|
|
|
|
filetype = mimeDatabase->GetFileTypeFromExtension( file_ext );
|
|
|
|
|
delete mimeDatabase;
|
|
|
|
|
mimeDatabase = NULL;
|
|
|
|
|
}
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
if( filetype )
|
|
|
|
|
{
|
|
|
|
|
wxFileType::MessageParameters params( fullfilename, type );
|
|
|
|
|
|
|
|
|
|
success = filetype->GetOpenCommand( &command, params );
|
|
|
|
|
delete filetype;
|
|
|
|
|
if( success )
|
|
|
|
|
success = ProcessExecute( command );
|
2008-04-24 16:55:35 +00:00
|
|
|
|
}
|
2008-06-29 18:51:38 +00:00
|
|
|
|
|
|
|
|
|
if( !success )
|
2008-04-24 16:55:35 +00:00
|
|
|
|
{
|
2009-04-07 11:53:58 +00:00
|
|
|
|
msg.Printf( _( "Unknown MIME type for doc file <%s>" ),
|
2009-10-13 09:00:46 +00:00
|
|
|
|
GetChars( fullfilename ) );
|
2009-04-07 15:54:40 +00:00
|
|
|
|
DisplayError( aFrame, msg );
|
2008-04-24 16:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/******************************************************************/
|
2008-04-24 16:55:35 +00:00
|
|
|
|
int KeyWordOk( const wxString& KeyList, const wxString& Database )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/******************************************************************/
|
2008-04-24 16:55:35 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/* Recherche si dans le texte Database on retrouve tous les mots
|
2008-06-29 18:51:38 +00:00
|
|
|
|
* cles donnes dans KeyList ( KeyList = suite de mots cles
|
|
|
|
|
* separes par des espaces
|
|
|
|
|
* Retourne:
|
|
|
|
|
* 0 si aucun mot cle trouv<EFBFBD>
|
|
|
|
|
* 1 si mot cle trouv<EFBFBD>
|
2008-04-24 16:55:35 +00:00
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2008-04-24 16:55:35 +00:00
|
|
|
|
wxString KeysCopy, DataList;
|
|
|
|
|
|
|
|
|
|
if( KeyList.IsEmpty() )
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
KeysCopy = KeyList; KeysCopy.MakeUpper();
|
|
|
|
|
DataList = Database; DataList.MakeUpper();
|
|
|
|
|
|
|
|
|
|
wxStringTokenizer Token( KeysCopy, wxT( " \n\r" ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2008-04-24 16:55:35 +00:00
|
|
|
|
while( Token.HasMoreTokens() )
|
|
|
|
|
{
|
2008-06-29 18:51:38 +00:00
|
|
|
|
wxString Key = Token.GetNextToken();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2008-04-24 16:55:35 +00:00
|
|
|
|
// Search Key in Datalist:
|
|
|
|
|
wxStringTokenizer Data( DataList, wxT( " \n\r" ) );
|
|
|
|
|
|
|
|
|
|
while( Data.HasMoreTokens() )
|
|
|
|
|
{
|
|
|
|
|
wxString word = Data.GetNextToken();
|
|
|
|
|
if( word == Key )
|
2008-06-29 18:51:38 +00:00
|
|
|
|
return 1; // Key found !
|
2008-04-24 16:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// keyword not found
|
|
|
|
|
return 0;
|
|
|
|
|
}
|