From c8375c151cd94634b6648b9a76939344064435e0 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand <seth@kipro-pcb.com> Date: Mon, 6 May 2024 12:21:56 -0700 Subject: [PATCH] Launch default URI handler if exists Otherwise, handle as a normal file Fixes https://gitlab.com/kicad/code/kicad/-/issues/17902 --- common/eda_doc.cpp | 28 +++++++++------------------- common/eda_text.cpp | 9 +-------- include/eda_doc.h | 4 ++-- 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/common/eda_doc.cpp b/common/eda_doc.cpp index 024d7cadb7..88f9c21dbb 100644 --- a/common/eda_doc.cpp +++ b/common/eda_doc.cpp @@ -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__ diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 61ccd67f19..16bc2f4e80 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -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 diff --git a/include/eda_doc.h b/include/eda_doc.h index e3caecd4a9..1d986155a3 100644 --- a/include/eda_doc.h +++ b/include/eda_doc.h @@ -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).