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 <gestfich.h>
|
||||||
#include <settings/common_settings.h>
|
#include <settings/common_settings.h>
|
||||||
|
|
||||||
#include <wx/mimetype.h>
|
|
||||||
#include <wx/filename.h>
|
|
||||||
#include <wx/uri.h>
|
|
||||||
#include <wx/filedlg.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)
|
// Mime type extensions (PDF files are not considered here)
|
||||||
|
@ -65,28 +66,17 @@ bool GetAssociatedDocument( wxWindow* aParent, const wxString& aDocName, PROJECT
|
||||||
wxString command;
|
wxString command;
|
||||||
bool success = false;
|
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
|
// Replace before resolving as we might have a URL in a variable
|
||||||
docname = ResolveUriByEnvVars( aDocName, aProject );
|
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 );
|
wxURI uri( docname );
|
||||||
wxLaunchDefaultBrowser( uri.BuildURI() );
|
wxLogNull logNo; // Disable log messages
|
||||||
|
|
||||||
|
if( uri.HasScheme() && wxLaunchDefaultBrowser( docname ) )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
docname.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP );
|
docname.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP );
|
||||||
|
|
|
@ -1083,16 +1083,9 @@ bool EDA_TEXT::ValidateHyperlink( const wxString& aURL )
|
||||||
if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
|
if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Limit valid urls to file, http and https for now. Note wxURL doesn't support https
|
|
||||||
wxURI uri;
|
wxURI uri;
|
||||||
|
|
||||||
if( uri.Create( aURL ) && uri.HasScheme() )
|
return( uri.Create( aURL ) && uri.HasScheme() );
|
||||||
{
|
|
||||||
const wxString& scheme = uri.GetScheme();
|
|
||||||
return scheme == wxT( "file" ) || scheme == wxT( "http" ) || scheme == wxT( "https" );
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
|
double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
|
||||||
|
|
|
@ -35,8 +35,8 @@
|
||||||
* Open a document (file) with the suitable browser.
|
* Open a document (file) with the suitable browser.
|
||||||
*
|
*
|
||||||
* Environmental variables are substituted before the document name is resolved for
|
* 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
|
* either browser or file. If \a aDocName has an associated URI handler on the system,
|
||||||
* default internet browser is launched.
|
* the default handler will be launched.
|
||||||
*
|
*
|
||||||
* @param aParent main frame.
|
* @param aParent main frame.
|
||||||
* @param aDocName filename of file to open (Full filename or short filename).
|
* @param aDocName filename of file to open (Full filename or short filename).
|
||||||
|
|
Loading…
Reference in New Issue