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:
Seth Hillbrand 2024-05-06 12:21:56 -07:00
parent 73681d08c5
commit c8375c151c
3 changed files with 12 additions and 29 deletions

View File

@ -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,27 +66,16 @@ 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 );
{ wxLogNull logNo; // Disable log messages
wxURI uri( docname );
wxLaunchDefaultBrowser( uri.BuildURI() ); if( uri.HasScheme() && wxLaunchDefaultBrowser( docname ) )
return true; return true;
}
} }
#ifdef __WINDOWS__ #ifdef __WINDOWS__

View File

@ -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

View File

@ -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).