32#include <wx/filedlg.h>
33#include <wx/filename.h>
35#include <wx/mimetype.h>
43 wxFileTypeInfo( wxT(
"text/html" ),
46 wxT(
"html document (from KiCad)" ),
48 wxT(
"html" ),wxNullPtr ),
50 wxFileTypeInfo( wxT(
"application/sch" ),
52 wxT(
"eeschema -p %s" ),
53 wxT(
"sch document (from KiCad)" ),
55 wxT(
"SCH" ), wxNullPtr ),
63 SEARCH_STACK* aPaths, std::vector<EMBEDDED_FILES*> aFilesStack )
66 wxString fullfilename;
81 wxString scheme = uri.GetScheme().Lower();
85 if( wxLaunchDefaultBrowser( docname ) )
90 if( aFilesStack.empty() )
92 wxLogTrace( wxT(
"KICAD_EMBED" ),
93 wxT(
"No EMBEDDED_FILES object provided for kicad_embed URI" ) );
99 wxLogTrace( wxT(
"KICAD_EMBED" ),
100 wxT(
"Invalid kicad_embed URI '%s'" ), docname );
106 wxFileName temp_file = aFilesStack[0]->GetTemporaryFileName( docname );
109 while( !temp_file.IsOk() && ii < (
int) aFilesStack.size() )
110 temp_file = aFilesStack[ii++]->GetTemporaryFileName( docname );
112 if( !temp_file.IsOk() )
114 wxLogTrace( wxT(
"KICAD_EMBED" ),
115 wxT(
"Failed to get temp file '%s' for kicad_embed URI" ), docname );
119 wxLogTrace( wxT(
"KICAD_EMBED" ),
120 wxT(
"Opening embedded file '%s' as '%s'" ),
122 temp_file.GetFullPath() );
123 docname = temp_file.GetFullPath();
135 if( wxIsAbsolutePath( docname ) || aPaths ==
nullptr )
136 fullfilename = docname;
140 else if( wxFileName::FileExists( docname ) )
141 fullfilename = docname;
143 fullfilename = aPaths->FindValidPath( docname );
148 extension = wxT(
".*" );
151 if( wxIsWild( fullfilename ) )
153 fullfilename = wxFileSelector(
_(
"Documentation File" ), wxPathOnly( fullfilename ),
154 fullfilename, extension, wxFileSelectorDefaultWildcardStr,
155 wxFD_OPEN, aParent );
157 if( fullfilename.IsEmpty() )
161 if( !wxFileExists( fullfilename ) )
163 msg.Printf(
_(
"Documentation file '%s' not found." ), docname );
168 wxFileName currentFileName( fullfilename );
171 fullfilename = currentFileName.GetAbsolutePath();
173 wxString file_ext = currentFileName.GetExt();
175 if( file_ext.Lower() == wxT(
"pdf" ) )
177 success =
OpenPDF( fullfilename );
182 wxFileType* filetype;
185 filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( file_ext );
191 filetype =
mimeDatabase->GetFileTypeFromExtension( file_ext );
198 wxFileType::MessageParameters params( fullfilename, type );
200 success = filetype->GetOpenCommand( &command, params );
204 success = wxExecute( command );
209 msg.Printf(
_(
"Unknown MIME type for documentation file '%s'" ), fullfilename );
Container for project specific data.
Look for files in a number of paths.
const wxString ResolveUriByEnvVars(const wxString &aUri, const PROJECT *aProject)
Replace any environment and/or text variables in URIs.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths, std::vector< EMBEDDED_FILES * > aFilesStack)
Open a document (file) with the suitable browser.
static const wxFileTypeInfo EDAfallbacks[]
static wxMimeTypesManager * mimeDatabase
bool OpenPDF(const wxString &file)
Run the PDF viewer and display a PDF file.
#define WIN_STRING_DIR_SEP
#define UNIX_STRING_DIR_SEP
static const std::string KiCadUriPrefix