Add printing to RMB project items.

Fixes: lp:1836473
* https://bugs.launchpad.net/kicad/+bug/1836473
This commit is contained in:
Jeff Young 2019-08-28 17:01:06 +01:00
parent 494d0de9b8
commit 360a52399a
7 changed files with 111 additions and 204 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2017 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -28,12 +28,10 @@
* @brief Functions for file management
*/
#include <fctsys.h>
#include <wx/mimetype.h>
#include <wx/filename.h>
#include <wx/dir.h>
// For compilers that support precompilation, includes "wx.h".
#include <fctsys.h>
#include <pgm_base.h>
#include <confirm.h>
#include <common.h>
@ -51,34 +49,6 @@ void AddDelimiterString( wxString& string )
}
bool EDA_PATH_SELECTOR( const wxString& aTitle,
wxString& aPath,
int aFlags,
wxWindow* aParent,
const wxPoint& aPosition )
{
int ii;
bool selected = false;
wxDirDialog* DirFrame = new wxDirDialog( aParent,
aTitle,
aPath,
aFlags,
aPosition );
ii = DirFrame->ShowModal();
if( ii == wxID_OK )
{
aPath = DirFrame->GetPath();
selected = true;
}
DirFrame->Destroy();
return selected;
}
wxString EDA_FILE_SELECTOR( const wxString& aTitle,
const wxString& aPath,
const wxString& aFileName,
@ -236,112 +206,6 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& para
}
wxString KicadDatasPath()
{
bool found = false;
wxString data_path;
if( Pgm().IsKicadEnvVariableDefined() ) // Path defined by the KICAD environment variable.
{
data_path = Pgm().GetKicadEnvVariable();
found = true;
}
else // Path of executables.
{
#ifndef __WXMAC__
wxString tmp = Pgm().GetExecutablePath();
#ifdef __WINDOWS__
tmp.MakeLower();
#endif
if( tmp.Contains( wxT( "kicad" ) ) )
{
#ifdef __WINDOWS__
tmp = Pgm().GetExecutablePath();
#endif
if( tmp.Last() == '/' )
tmp.RemoveLast();
data_path = tmp.BeforeLast( '/' ); // id cd ../
data_path += UNIX_STRING_DIR_SEP;
// Old versions of KiCad use kicad/ as default for data
// and last versions kicad/share/
// So we search for kicad/share/ first
wxString old_path = data_path;
data_path += wxT( "share/" );
if( wxDirExists( data_path ) )
{
found = true;
}
else if( wxDirExists( old_path ) )
{
data_path = old_path;
found = true;
}
}
}
if( !found )
{
// find KiCad from possibilities list:
// /usr/local/kicad/ or c:/kicad/
const static wxChar* possibilities[] = {
#ifdef __WINDOWS__
wxT( "c:/kicad/share/" ),
wxT( "d:/kicad/share/" ),
wxT( "c:/kicad/" ),
wxT( "d:/kicad/" ),
wxT( "c:/Program Files/kicad/share/" ),
wxT( "d:/Program Files/kicad/share/" ),
wxT( "c:/Program Files/kicad/" ),
wxT( "d:/Program Files/kicad/" ),
#else
wxT( "/usr/share/kicad/" ),
wxT( "/usr/local/share/kicad/" ),
wxT( "/usr/local/kicad/share/" ), // default data path for "universal
// tarballs" and build for a server
// (new)
wxT( "/usr/local/kicad/" ), // default data path for "universal
// tarballs" and build for a server
// (old)
#endif
};
for( unsigned i=0; i<arrayDim(possibilities); ++i )
{
data_path = possibilities[i];
if( wxDirExists( data_path ) )
{
found = true;
break;
}
}
#else
// On OSX point to Contents/SharedSupport folder of main bundle
data_path = GetOSXKicadDataDir();
found = true;
#endif
}
if( found )
{
data_path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
if( data_path.Last() != '/' )
data_path += UNIX_STRING_DIR_SEP;
}
else
{
data_path.Empty();
}
return data_path;
}
bool OpenPDF( const wxString& file )
{
wxString command;
@ -391,29 +255,79 @@ bool OpenPDF( const wxString& file )
void OpenFile( const wxString& file )
{
wxFileName fileName( file );
wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( fileName.GetExt() );
if( !filetype )
return;
wxString command;
wxFileType::MessageParameters params( file );
wxFileName currentFileName( file );
wxString ext;
wxString type;
ext = currentFileName.GetExt();
wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext );
bool success = false;
wxFileType::MessageParameters params( file, type );
if( filetype )
success = filetype->GetOpenCommand( &command, params );
filetype->GetOpenCommand( &command, params );
delete filetype;
if( success && !command.IsEmpty() )
if( !command.IsEmpty() )
ProcessExecute( command );
}
void PrintFile( const wxString& file )
{
wxFileName fileName( file );
wxString ext = fileName.GetExt();
wxString command;
#ifdef __WXMAC__
wxString application;
if( ext == "ps" || ext == "pdf" )
application = "Preview";
else if( ext == "csv" )
application = "Numbers";
else if( ext == "txt" || ext == "rpt" )
application = "TextEdit";
if( !application.IsEmpty() )
{
command.Printf( "osascript -e 'tell application \"%s\"' "
"-e ' set srcFileRef to (open POSIX file \"%s\")' "
"-e ' activate' "
"-e ' print srcFileRef print dialog true' "
"-e 'end tell' ",
application,
file );
}
else
{
// Let the Finder find an associated application. Note that this method doesn't
// support opening the print dialog, and if the app doesn't support the AppleScript
// print command then it won't do that either -- but it's better than nothing.
command.Printf( "osascript -e 'tell application \"Finder\"' "
"-e ' set srcFileRef to (open POSIX file \"%s\")' "
"-e ' print srcFileRef' "
"-e 'end tell' ",
file );
}
system( command.c_str() );
#else
wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext );
if( !filetype )
return;
wxFileType::MessageParameters params( file );
filetype->GetPrintCommand( &command, params );
delete filetype;
if( !command.IsEmpty() )
ProcessExecute( command );
#endif
}
wxString QuoteFullPath( wxFileName& fn, wxPathFormat format )
{
return wxT( "\"" ) + fn.GetFullPath( format ) + wxT( "\"" );

View File

@ -57,25 +57,7 @@ bool OpenPDF( const wxString& file );
void OpenFile( const wxString& file );
/**
* Function EDA_PATH_SELECTOR
*
* is a helper function that wraps wxDirDialog.
*
* @param aTitle is a string to display in the dialog title bar.
* @param aPath is a string contain the default path for the path dialog. This string also
* contains the result of the wxDirDialog when the OK button is used to dismiss
* the dialog.
* @param aFlags is the style of the path dialog, wxDD_???.
* @param aParent is the parent window of the dialog.
* @param aPosition is the position of the dialog.
* @return true if a path was selected.
*/
bool EDA_PATH_SELECTOR( const wxString& aTitle,
wxString& aPath,
int aFlags, /* reserve */
wxWindow* aParent,
const wxPoint& aPosition = wxDefaultPosition );
void PrintFile( const wxString& file );
/**
* Function EDA_FILE_SELECTOR

View File

@ -61,20 +61,9 @@ enum id_kicad_frm {
ID_PROJECT_NEWDIR,
ID_PROJECT_OPEN_DIR,
ID_PROJECT_DELETE,
ID_PROJECT_PRINT,
ID_PROJECT_RENAME,
ID_PROJECT_OPEN_FILE_WITH_TEXT_EDITOR,
ID_TO_SCH,
ID_TO_SCH_LIB_EDITOR,
ID_TO_PCB,
ID_TO_PCB_FP_EDITOR,
ID_TO_CVPCB,
ID_TO_GERBVIEW,
ID_TO_BITMAP_CONVERTER,
ID_TO_PCB_CALCULATOR,
ID_TO_PL_EDITOR,
ID_TO_TEXT_EDITOR,
ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR,
ID_BROWSE_IN_FILE_EXPLORER,
ID_SAVE_AND_ZIP_FILES,

View File

@ -92,6 +92,7 @@ static const wxChar* s_allowedExtensionsToList[] =
wxT( "^.*\\.nc$" ), // Excellon NC drill files (alternate file ext)
wxT( "^.*\\.xnc$" ), // Excellon NC drill files (alternate file ext)
wxT( "^.*\\.svg$" ), // SVG print/plot files
wxT( "^.*\\.ps$" ), // Postscript plot files
NULL // end of list
};
@ -124,6 +125,7 @@ BEGIN_EVENT_TABLE( TREE_PROJECT_FRAME, wxSashLayoutWindow )
EVT_MENU( ID_PROJECT_NEWDIR, TREE_PROJECT_FRAME::OnCreateNewDirectory )
EVT_MENU( ID_PROJECT_OPEN_DIR, TREE_PROJECT_FRAME::OnOpenDirectory )
EVT_MENU( ID_PROJECT_DELETE, TREE_PROJECT_FRAME::OnDeleteFile )
EVT_MENU( ID_PROJECT_PRINT, TREE_PROJECT_FRAME::OnPrintFile )
EVT_MENU( ID_PROJECT_RENAME, TREE_PROJECT_FRAME::OnRenameFile )
END_EVENT_TABLE()
@ -317,14 +319,13 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName,
for( unsigned i = 0; i < m_filters.size(); i++ )
{
wxCHECK2_MSG( reg.Compile( m_filters[i], wxRE_ICASE ), continue,
wxT( "Regular expression " ) + m_filters[i] +
wxT( " failed to compile." ) );
wxString::Format( "Regex %s failed to compile.", m_filters[i] ) );
if( reg.Matches( aName ) )
{
addFile = true;
if( i==0 )
if( i == 0 )
isSchematic = true;
break;
@ -599,6 +600,8 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
_( "Opens the directory in the default system file manager" ),
#endif
KiBitmap( directory_browser_xpm ) );
popupMenu.AppendSeparator();
AddMenuItem( &popupMenu, ID_PROJECT_DELETE,
_( "&Delete Directory" ),
_( "Delete the Directory and its content" ),
@ -614,10 +617,18 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
_( "&Rename File..." ),
_( "Rename file" ),
KiBitmap( right_xpm ) );
popupMenu.AppendSeparator();
AddMenuItem( &popupMenu, ID_PROJECT_DELETE,
_( "&Delete File" ),
_( "Delete the Directory and its content" ),
_( "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 ) );
break;
}
@ -645,10 +656,17 @@ void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& )
{
TREEPROJECT_ITEM* tree_data = GetSelectedData();
if( !tree_data )
return;
if( tree_data )
tree_data->Delete();
}
tree_data->Delete();
void TREE_PROJECT_FRAME::OnPrintFile( wxCommandEvent& )
{
TREEPROJECT_ITEM* tree_data = GetSelectedData();
if( tree_data )
tree_data->Print();
}

View File

@ -110,22 +110,25 @@ private:
/**
* Function OnOpenSelectedFileWithTextEditor
* Called via the popup menu, when right clicking on a file name
* Call the text editor to open the selected file in the tree project
*/
void OnOpenSelectedFileWithTextEditor( wxCommandEvent& event );
/**
* Function OnDeleteFile
* Called via the popup menu, when right clicking on a file name or a directory name to
* delete the selected file or directory in the tree project
* Delete the selected file or directory in the tree project
*/
void OnDeleteFile( wxCommandEvent& event );
/**
* Function OnDeleteFile
* Print the selected file or directory in the tree project
*/
void OnPrintFile( wxCommandEvent& event );
/**
* Function OnRenameFile
* Called via the popup menu, when right clicking on a file name or a directory name to
* rename the selected file or directory in the tree project
* Rename the selected file or directory in the tree project
*/
void OnRenameFile( wxCommandEvent& event );

View File

@ -32,7 +32,6 @@
#include <wx/regex.h>
#include <gestfich.h>
#include <executable_names.h>
#include <kiway.h>
#include <tool/tool_manager.h>
#include <tools/kicad_manager_actions.h>
@ -127,12 +126,12 @@ bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check )
}
bool TREEPROJECT_ITEM::Delete( bool check )
void TREEPROJECT_ITEM::Delete()
{
wxString msg = wxString::Format( _( "Are you sure you want to delete '%s'?" ), GetFileName() );
wxMessageDialog dialog( m_parent, msg, _( "Delete File" ), wxYES_NO | wxICON_QUESTION );
if( !check || wxID_YES == dialog.ShowModal() )
if( dialog.ShowModal() == wxID_YES )
{
bool success;
@ -152,11 +151,13 @@ bool TREEPROJECT_ITEM::Delete( bool check )
if( success )
m_parent->Delete( GetId() );
return success;
}
}
return false;
void TREEPROJECT_ITEM::Print()
{
PrintFile( GetFileName() );
}
@ -246,7 +247,6 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* aTreePrjFrame )
break;
default:
AddDelimiterString( fullFileName );
OpenFile( fullFileName );
break;
}

View File

@ -73,7 +73,8 @@ public:
const wxString GetDir() const;
bool Rename( const wxString& name, bool check = true );
bool Delete( bool check = true );
void Delete();
void Print();
void Activate( TREE_PROJECT_FRAME* aTreePrjFrame );
void SetState( int state );