Launch default URI handler if exists
Otherwise, handle as a normal file Fixes https://gitlab.com/kicad/code/kicad/-/issues/17902
This commit is contained in:
parent
73681d08c5
commit
c8375c151c
|
@ -28,10 +28,11 @@
|
|||
#include <gestfich.h>
|
||||
#include <settings/common_settings.h>
|
||||
|
||||
#include <wx/mimetype.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/uri.h>
|
||||
#include <wx/filedlg.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/mimetype.h>
|
||||
#include <wx/uri.h>
|
||||
|
||||
|
||||
// Mime type extensions (PDF files are not considered here)
|
||||
|
@ -65,27 +66,16 @@ bool GetAssociatedDocument( wxWindow* aParent, const wxString& aDocName, PROJECT
|
|||
wxString command;
|
||||
bool success = false;
|
||||
|
||||
// Is an internet url
|
||||
static const std::vector<wxString> url_header =
|
||||
{
|
||||
wxT( "http:" ),
|
||||
wxT( "https:" ),
|
||||
wxT( "ftp:" ),
|
||||
wxT( "www." ),
|
||||
wxT( "file:" )
|
||||
};
|
||||
|
||||
// Replace before resolving as we might have a URL in a variable
|
||||
docname = ResolveUriByEnvVars( aDocName, aProject );
|
||||
|
||||
for( const wxString& proc : url_header)
|
||||
// We don't want the wx error message about not being able to open the URI
|
||||
{
|
||||
if( docname.StartsWith( proc ) ) // looks like an internet url
|
||||
{
|
||||
wxURI uri( docname );
|
||||
wxLaunchDefaultBrowser( uri.BuildURI() );
|
||||
wxURI uri( docname );
|
||||
wxLogNull logNo; // Disable log messages
|
||||
|
||||
if( uri.HasScheme() && wxLaunchDefaultBrowser( docname ) )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
|
|
@ -1083,16 +1083,9 @@ bool EDA_TEXT::ValidateHyperlink( const wxString& aURL )
|
|||
if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
|
||||
return true;
|
||||
|
||||
// Limit valid urls to file, http and https for now. Note wxURL doesn't support https
|
||||
wxURI uri;
|
||||
|
||||
if( uri.Create( aURL ) && uri.HasScheme() )
|
||||
{
|
||||
const wxString& scheme = uri.GetScheme();
|
||||
return scheme == wxT( "file" ) || scheme == wxT( "http" ) || scheme == wxT( "https" );
|
||||
}
|
||||
|
||||
return false;
|
||||
return( uri.Create( aURL ) && uri.HasScheme() );
|
||||
}
|
||||
|
||||
double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
|
||||
|
|
|
@ -35,8 +35,8 @@
|
|||
* Open a document (file) with the suitable browser.
|
||||
*
|
||||
* Environmental variables are substituted before the document name is resolved for
|
||||
* either browser or file. If \a aDocName begins with http: or ftp: or www. the
|
||||
* default internet browser is launched.
|
||||
* either browser or file. If \a aDocName has an associated URI handler on the system,
|
||||
* the default handler will be launched.
|
||||
*
|
||||
* @param aParent main frame.
|
||||
* @param aDocName filename of file to open (Full filename or short filename).
|
||||
|
|
Loading…
Reference in New Issue