Add print preflight so the menu item is only shown when we can print.
Fixes: lp:1836473 * https://bugs.launchpad.net/kicad/+bug/1836473
This commit is contained in:
parent
83b2332f1f
commit
2274895acf
|
@ -274,14 +274,14 @@ void OpenFile( const wxString& file )
|
|||
}
|
||||
|
||||
|
||||
void PrintFile( const wxString& file )
|
||||
bool doPrintFile( const wxString& file, bool aDryRun )
|
||||
{
|
||||
wxFileName fileName( file );
|
||||
wxString ext = fileName.GetExt();
|
||||
wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext );
|
||||
|
||||
if( !filetype )
|
||||
return;
|
||||
return false;
|
||||
|
||||
wxString printCommand;
|
||||
wxString openCommand;
|
||||
|
@ -294,8 +294,10 @@ void PrintFile( const wxString& file )
|
|||
|
||||
if( !printCommand.IsEmpty() )
|
||||
{
|
||||
ProcessExecute( printCommand );
|
||||
return;
|
||||
if( !aDryRun )
|
||||
ProcessExecute( printCommand );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __WXMAC__
|
||||
|
@ -315,8 +317,11 @@ void PrintFile( const wxString& file )
|
|||
"-e 'end tell' ",
|
||||
application,
|
||||
file );
|
||||
system( printCommand.c_str() );
|
||||
return;
|
||||
|
||||
if( !aDryRun )
|
||||
system( printCommand.c_str() );
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -326,19 +331,27 @@ void PrintFile( const wxString& file )
|
|||
|| ext == "txt" || ext == "rpt" || ext == "pos" || ext == "cmp" || ext == "net" )
|
||||
{
|
||||
printCommand.Printf( "lp \"%s\"", file );
|
||||
ProcessExecute( printCommand );
|
||||
return;
|
||||
|
||||
if( !aDryRun )
|
||||
ProcessExecute( printCommand );
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// everything else failed; try to open the file
|
||||
if( !openCommand.IsEmpty() )
|
||||
{
|
||||
ProcessExecute( openCommand );
|
||||
return;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DisplayError( NULL, wxString::Format( _( "Cannot print '%s'.\n\nUnknown filetype." ), file ) );
|
||||
|
||||
void PrintFile( const wxString& file )
|
||||
{
|
||||
doPrintFile( file, false );
|
||||
}
|
||||
|
||||
|
||||
bool CanPrintFile( const wxString& file )
|
||||
{
|
||||
return doPrintFile( file, true );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,10 +54,10 @@ class EDA_LIST_DIALOG;
|
|||
* @return true is success, false if no PDF viewer found
|
||||
*/
|
||||
bool OpenPDF( const wxString& file );
|
||||
|
||||
void OpenFile( const wxString& file );
|
||||
|
||||
void PrintFile( const wxString& file );
|
||||
bool CanPrintFile( const wxString& file );
|
||||
|
||||
/**
|
||||
* Function EDA_FILE_SELECTOR
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
*/
|
||||
|
||||
#include <bitmaps.h>
|
||||
#include <hotkeys_basic.h>
|
||||
#include <menus_helpers.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <tool/action_toolbar.h>
|
||||
|
|
|
@ -624,11 +624,18 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
|
|||
_( "Delete the file and its content" ),
|
||||
KiBitmap( delete_xpm ) );
|
||||
|
||||
popupMenu.AppendSeparator();
|
||||
AddMenuItem( &popupMenu, ID_PROJECT_PRINT,
|
||||
_( "&Print..." ),
|
||||
_( "Print the cotnents of the file" ),
|
||||
KiBitmap( print_button_xpm ) );
|
||||
if( CanPrintFile( fullFileName ) )
|
||||
{
|
||||
popupMenu.AppendSeparator();
|
||||
AddMenuItem( &popupMenu, ID_PROJECT_PRINT,
|
||||
#ifdef __APPLE__
|
||||
_( "Print..." ),
|
||||
#else
|
||||
_( "&Print" ),
|
||||
#endif
|
||||
_( "Print the contents of the file" ),
|
||||
KiBitmap( print_button_xpm ) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue