From c3589b5558f9063fbc44c6f60d65aafcf8941f4d Mon Sep 17 00:00:00 2001 From: Simon Wells Date: Thu, 31 Dec 2015 22:03:47 +1300 Subject: [PATCH 1/5] Cleaned up the OpenPDF function, including removing workaround code added in commit 1085 that is no longer required. Added Quotes around the pdf program if a custom one is used in case there are spaces in the file name --- common/gestfich.cpp | 97 ++++++++------------------------------------- 1 file changed, 17 insertions(+), 80 deletions(-) diff --git a/common/gestfich.cpp b/common/gestfich.cpp index 04f5626af2..0c34f4e25f 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -44,17 +44,11 @@ void AddDelimiterString( wxString& string ) { - wxString text; - - if( !string.StartsWith( wxT( "\"" ) ) ) - text = wxT( "\"" ); - - text += string; - - if( (text.Last() != '"' ) || (text.length() <= 1) ) - text += wxT( "\"" ); - - string = text; + if ( string.length() > 0 && !string.StartsWith( wxT( "\"" ) ) ) + { + string.Prepend( "\"" ); + string.Append( "\"" ); + } } @@ -347,90 +341,34 @@ wxString KicadDatasPath() } -bool OpenPDF( const wxString& file ) +bool OpenPDF( const wxString& filename ) { wxString command; - wxString filename = file; - wxString type; - bool success = false; Pgm().ReadPdfBrowserInfos(); if( !Pgm().UseSystemPdfBrowser() ) // Run the preferred PDF Browser { AddDelimiterString( filename ); - command = Pgm().GetPdfBrowserName() + wxT( " " ) + filename; + command = AddDelimiterString( Pgm().GetPdfBrowserName() ) + wxT( " " ) + filename; } else { - wxFileType* filetype = NULL; - wxFileType::MessageParameters params( filename, type ); - filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) ); - - if( filetype ) - success = filetype->GetOpenCommand( &command, params ); - + wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) ); + command = filetype->GetOpenCommand( filename ); delete filetype; - -#ifndef __WINDOWS__ - - // Bug ? under linux wxWidgets returns acroread as PDF viewer, even if - // it does not exist. - if( command.StartsWith( wxT( "acroread" ) ) ) // Workaround - success = false; -#endif - - if( success && !command.IsEmpty() ) - { - success = ProcessExecute( command ); - - if( success ) - return success; - } - - success = false; - command.clear(); - - if( !success ) - { -#if !defined(__WINDOWS__) - AddDelimiterString( filename ); - - // here is a list of PDF viewers candidates - static const wxChar* tries[] = - { - wxT( "/usr/bin/evince" ), - wxT( "/usr/bin/okular" ), - wxT( "/usr/bin/gpdf" ), - wxT( "/usr/bin/konqueror" ), - wxT( "/usr/bin/kpdf" ), - wxT( "/usr/bin/xpdf" ), - wxT( "/usr/bin/open" ), // BSD and OSX file & dir opener - wxT( "/usr/bin/xdg-open" ), // Freedesktop file & dir opener - }; - - for( unsigned ii = 0; ii" ), GetChars( filename ) ); DisplayError( NULL, msg ); - success = false; } - return success; + return false; } From 57d4c90055e9a2e5af11311a3bd1461884a24907 Mon Sep 17 00:00:00 2001 From: Simon Wells Date: Thu, 31 Dec 2015 23:16:26 +1300 Subject: [PATCH 2/5] Fixed bug with a text editor with a space in the name on OSX --- common/gestfich.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/common/gestfich.cpp b/common/gestfich.cpp index 0c34f4e25f..da224f3262 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -44,10 +44,10 @@ void AddDelimiterString( wxString& string ) { - if ( string.length() > 0 && !string.StartsWith( wxT( "\"" ) ) ) + if ( !string.StartsWith( wxT( "\"" ) ) ) { - string.Prepend( "\"" ); - string.Append( "\"" ); + string.Prepend ( wxT( "\"" ) ); + string.Append ( wxT( "\"" ) ); } } @@ -221,6 +221,8 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& para #ifdef __WXMAC__ else { + AddDelimiterString( fullFileName ); + if( !param.IsEmpty() ) fullFileName += wxT( " " ) + param; @@ -341,16 +343,17 @@ wxString KicadDatasPath() } -bool OpenPDF( const wxString& filename ) +bool OpenPDF( const wxString& file ) { wxString command; + wxString filename = file; Pgm().ReadPdfBrowserInfos(); if( !Pgm().UseSystemPdfBrowser() ) // Run the preferred PDF Browser { AddDelimiterString( filename ); - command = AddDelimiterString( Pgm().GetPdfBrowserName() ) + wxT( " " ) + filename; + command = Pgm().GetPdfBrowserName() + wxT( " " ) + filename; } else { From 0d9ffb11fa09acda4ac51575ec409e4b7b7c9c11 Mon Sep 17 00:00:00 2001 From: Simon Wells Date: Fri, 1 Jan 2016 20:51:50 +1300 Subject: [PATCH 3/5] Ensure filetype is not null before using open command, Fixed if statements to follow coding guidelines --- common/gestfich.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/common/gestfich.cpp b/common/gestfich.cpp index da224f3262..adb71c5d4f 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -44,7 +44,7 @@ void AddDelimiterString( wxString& string ) { - if ( !string.StartsWith( wxT( "\"" ) ) ) + if( !string.StartsWith( wxT( "\"" ) ) ) { string.Prepend ( wxT( "\"" ) ); string.Append ( wxT( "\"" ) ); @@ -358,13 +358,16 @@ bool OpenPDF( const wxString& file ) else { wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) ); - command = filetype->GetOpenCommand( filename ); + + if( filetype ) + command = filetype->GetOpenCommand( filename ); + delete filetype; } - if ( !command.IsEmpty() ) + if( !command.IsEmpty() ) { - if ( ProcessExecute( command ) ) + if( ProcessExecute( command ) ) { return true; } From b02bc2bf50836da3942828354e25f9937ddb7f6d Mon Sep 17 00:00:00 2001 From: Simon Wells Date: Sun, 3 Jan 2016 01:55:38 +1300 Subject: [PATCH 4/5] Reorder includes to a more logical order --- common/gestfich.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/common/gestfich.cpp b/common/gestfich.cpp index adb71c5d4f..40bed948d3 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -28,19 +28,18 @@ * @brief Functions for file management */ -// For compilers that support precompilation, includes "wx.h". -#include -#include -#include - -#include -#include -#include - #include #include #include +// For compilers that support precompilation, includes "wx.h". +#include +#include +#include +#include +#include + +#include void AddDelimiterString( wxString& string ) { From 5caea3f599c2cedaf322c76d97c252c359e52f56 Mon Sep 17 00:00:00 2001 From: Simon Wells Date: Tue, 5 Jan 2016 06:12:37 +1300 Subject: [PATCH 5/5] Removed the space in the error message after the new line --- common/gestfich.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/gestfich.cpp b/common/gestfich.cpp index 40bed948d3..3a09576874 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -373,7 +373,7 @@ bool OpenPDF( const wxString& file ) else { wxString msg; - msg.Printf( _( "Problem while running the PDF viewer\n Command is '%s'" ), + msg.Printf( _( "Problem while running the PDF viewer\nCommand is '%s'" ), GetChars( command ) ); DisplayError( NULL, msg ); }