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 ),
66 wxString fullfilename;
81 wxString scheme = uri.GetScheme().Lower();
85 if( wxLaunchDefaultBrowser( docname ) )
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 );
104 docname = docname.Mid( 14 );
108 if( !temp_file.IsOk() )
110 wxLogTrace( wxT(
"KICAD_EMBED" ),
111 wxT(
"Failed to get temp file '%s' for kicad_embed URI" ), docname );
115 wxLogTrace( wxT(
"KICAD_EMBED" ),
116 wxT(
"Opening embedded file '%s' as '%s'" ),
117 docname, temp_file.GetFullPath() );
118 docname = temp_file.GetFullPath();
130 if( wxIsAbsolutePath( docname ) || aPaths ==
nullptr )
131 fullfilename = docname;
135 else if( wxFileName::FileExists( docname ) )
136 fullfilename = docname;
138 fullfilename = aPaths->FindValidPath( docname );
143 extension = wxT(
".*" );
146 if( wxIsWild( fullfilename ) )
148 fullfilename = wxFileSelector(
_(
"Documentation File" ), wxPathOnly( fullfilename ),
149 fullfilename, extension, wxFileSelectorDefaultWildcardStr,
150 wxFD_OPEN, aParent );
152 if( fullfilename.IsEmpty() )
156 if( !wxFileExists( fullfilename ) )
158 msg.Printf(
_(
"Documentation file '%s' not found." ), docname );
163 wxFileName currentFileName( fullfilename );
166 fullfilename = currentFileName.GetAbsolutePath();
168 wxString file_ext = currentFileName.GetExt();
170 if( file_ext.Lower() == wxT(
"pdf" ) )
172 success =
OpenPDF( fullfilename );
177 wxFileType* filetype;
180 filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( file_ext );
186 filetype =
mimeDatabase->GetFileTypeFromExtension( file_ext );
193 wxFileType::MessageParameters params( fullfilename, type );
195 success = filetype->GetOpenCommand( &command, params );
199 success = wxExecute( command );
204 msg.Printf(
_(
"Unknown MIME type for documentation file '%s'" ), fullfilename );
wxFileName GetTemporaryFileName(const wxString &aName) const
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 DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
This file is part of the common library.
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths, EMBEDDED_FILES *aFiles)
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