mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-18 22:31:40 +00:00
ADDED: Implement Drag and Drop
dropping files to Kicad manager : *.kicad_pro, *.pro -> open project; gerber and job files -> open in Gerbview editor; Eagle and Cadstar files -> open project. dropping file to schematic editor -> append schematic; dropping library file to Symbol editor -> add library; dropping board file to PCB editor -> append board; dropping library or footprint file to Footprint editor -> add library or import footprint; dropping ZIP file or gerber files to Gerbview editor -> open files; dropping sheet file to Drawing Sheet editor -> open sheet. Fixes https://gitlab.com/kicad/code/kicad/-/issues/11638
This commit is contained in:
parent
78acb4f07f
commit
0180bcf90a
common
eeschema
gerbview
include
kicad
CMakeLists.txtimport_proj.cppimport_proj.himport_project.cppkicad_manager_frame.cppkicad_manager_frame.hproject_tree_pane.cpp
tools
pagelayout_editor
pcbnew
@ -313,6 +313,7 @@ set( COMMON_SRCS
|
||||
eda_pattern_match.cpp
|
||||
eda_shape.cpp
|
||||
eda_text.cpp
|
||||
eda_tools.cpp
|
||||
eda_units.cpp
|
||||
env_paths.cpp
|
||||
env_vars.cpp
|
||||
@ -713,4 +714,3 @@ make_lexer(
|
||||
# to build it, first enable #define STAND_ALONE at top of dsnlexer.cpp
|
||||
add_executable( dsntest EXCLUDE_FROM_ALL dsnlexer.cpp )
|
||||
target_link_libraries( dsntest common ${wxWidgets_LIBRARIES} rt )
|
||||
|
||||
|
@ -1123,6 +1123,36 @@ void EDA_BASE_FRAME::OnPreferences( wxCommandEvent& event )
|
||||
}
|
||||
|
||||
|
||||
void EDA_BASE_FRAME::OnDropFiles( wxDropFilesEvent& aEvent )
|
||||
{
|
||||
wxString* files = aEvent.GetFiles();
|
||||
for( int nb = 0; nb < aEvent.GetNumberOfFiles(); nb++ )
|
||||
{
|
||||
const wxFileName fn = wxFileName( files[nb] );
|
||||
for( const auto& [ext, tool] : m_acceptedExts )
|
||||
{
|
||||
if( IsExtensionAccepted( fn.GetExt(), { ext.ToStdString() } ) )
|
||||
{
|
||||
m_AcceptedFiles.emplace( m_AcceptedFiles.end(), fn );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
DoWithAcceptedFiles();
|
||||
m_AcceptedFiles.clear();
|
||||
}
|
||||
|
||||
|
||||
void EDA_BASE_FRAME::DoWithAcceptedFiles()
|
||||
{
|
||||
for( auto file : m_AcceptedFiles )
|
||||
{
|
||||
wxString fn = file.GetFullPath();
|
||||
m_toolManager->RunAction( *m_acceptedExts.at( file.GetExt() ), true, &fn );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName, bool aVerbose )
|
||||
{
|
||||
wxString msg;
|
||||
|
53
common/eda_tools.cpp
Normal file
53
common/eda_tools.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2013 CERN (www.cern.ch)
|
||||
* Copyright (C) 2004-2021 KiCad Developers, see change_log.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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <eda_tools.h>
|
||||
#include <wx/textfile.h>
|
||||
|
||||
bool IsFileFromEDATool( const wxFileName& aFileName, const EDA_TOOLS aTool )
|
||||
{
|
||||
wxTextFile textFile;
|
||||
|
||||
if( textFile.Open( aFileName.GetFullPath() ) )
|
||||
{
|
||||
switch( aTool )
|
||||
{
|
||||
case EAGLE:
|
||||
if( textFile.GetLineCount() > 2
|
||||
&& textFile[1].StartsWith( wxT( "<!DOCTYPE eagle SYSTEM" ) )
|
||||
&& textFile[2].StartsWith( wxT( "<eagle version" ) ) )
|
||||
{
|
||||
textFile.Close();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
textFile.Close();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -671,6 +671,9 @@ TOOL_ACTION ACTIONS::reportBug( "common.SuiteControl.reportBug",
|
||||
_( "Report a problem with KiCad" ),
|
||||
BITMAPS::bug );
|
||||
|
||||
TOOL_ACTION ACTIONS::ddAddLibrary( "common.Control.ddaddLibrary",
|
||||
AS_GLOBAL );
|
||||
|
||||
// System-wide selection Events
|
||||
|
||||
const TOOL_EVENT EVENTS::PointSelectedEvent( TC_MESSAGE, TA_ACTION, "common.Interactive.pointSelected" );
|
||||
@ -684,4 +687,3 @@ const TOOL_EVENT EVENTS::InhibitSelectionEditing( TC_MESSAGE, TA_ACTION, "common
|
||||
const TOOL_EVENT EVENTS::UninhibitSelectionEditing( TC_MESSAGE, TA_ACTION, "common.Interactive.uninhibit" );
|
||||
|
||||
const TOOL_EVENT EVENTS::DisambiguatePoint( TC_MESSAGE, TA_ACTION, "common.Interactive.disambiguate" );
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <wx/filedlg.h>
|
||||
#include <wx/regex.h>
|
||||
#include <wx/translation.h>
|
||||
#include <regex>
|
||||
|
||||
bool compareFileExtensions( const std::string& aExtension,
|
||||
const std::vector<std::string>& aReference, bool aCaseSensitive )
|
||||
@ -131,6 +132,8 @@ const std::string ProjectFileExtension( "kicad_pro" );
|
||||
const std::string LegacyProjectFileExtension( "pro" );
|
||||
const std::string ProjectLocalSettingsFileExtension( "kicad_prl" );
|
||||
const std::string LegacySchematicFileExtension( "sch" );
|
||||
const std::string EagleSchematicFileExtension( "sch" );
|
||||
const std::string CadstarSchematicFileExtension( "csa" );
|
||||
const std::string KiCadSchematicFileExtension( "kicad_sch" );
|
||||
const std::string OrCadPcb2NetlistFileExtension( "net" );
|
||||
const std::string NetlistFileExtension( "net" );
|
||||
@ -145,6 +148,8 @@ const std::string DatabaseLibraryFileExtension( "kicad_dbl" );
|
||||
const std::string ArchiveFileExtension( "zip" );
|
||||
|
||||
const std::string LegacyPcbFileExtension( "brd" );
|
||||
const std::string EaglePcbFileExtension( "brd" );
|
||||
const std::string CadstarPcbFileExtension( "cpa" );
|
||||
const std::string KiCadPcbFileExtension( "kicad_pcb" );
|
||||
const std::string DrawingSheetFileExtension( "kicad_wks" );
|
||||
const std::string DesignRulesFileExtension( "kicad_dru" );
|
||||
@ -174,6 +179,31 @@ const std::string TextFileExtension( "txt" );
|
||||
const std::string MarkdownFileExtension( "md" );
|
||||
const std::string CsvFileExtension( "csv" );
|
||||
|
||||
/**
|
||||
* Gerber files extensions Kicad is to open
|
||||
*/
|
||||
const std::vector<std::string> GerberFileExtensions =
|
||||
{
|
||||
GerberFileExtension, GerberJobFileExtension,
|
||||
"gbl", "gbo", "gbp", "gbs", "gko",
|
||||
"gm1", "gm2", "gm3", "gm4", "gm5", "gm6", "gm7", "gm8", "gm9",
|
||||
"g1", "g3",
|
||||
"gpt", "gpb", "gtl", "gto", "gtp", "gts", "pho", "pos"
|
||||
};
|
||||
|
||||
const wxString GerberFileExtensionWildCard( ".((gbr|gbrjob|(gb|gt)[alops])|pho)" );
|
||||
|
||||
|
||||
bool IsExtensionAccepted( const wxString& aExt, const std::vector<std::string> acceptedExts )
|
||||
{
|
||||
for( auto extPtr = acceptedExts.begin(); extPtr != acceptedExts.end(); extPtr++ )
|
||||
{
|
||||
if( aExt.ToStdString() == *extPtr )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool IsProtelExtension( const wxString& ext )
|
||||
{
|
||||
|
@ -524,7 +524,6 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
|
||||
|
||||
bool SCH_EDIT_FRAME::AppendSchematic()
|
||||
{
|
||||
wxString fullFileName;
|
||||
SCH_SCREEN* screen = GetScreen();
|
||||
|
||||
if( !screen )
|
||||
@ -542,9 +541,13 @@ bool SCH_EDIT_FRAME::AppendSchematic()
|
||||
if( dlg.ShowModal() == wxID_CANCEL )
|
||||
return false;
|
||||
|
||||
fullFileName = dlg.GetPath();
|
||||
return AddSheetAndUpdateDisplay( dlg.GetPath() );
|
||||
}
|
||||
|
||||
if( !LoadSheetFromFile( GetCurrentSheet().Last(), &GetCurrentSheet(), fullFileName ) )
|
||||
|
||||
bool SCH_EDIT_FRAME::AddSheetAndUpdateDisplay( const wxString aFullFileName )
|
||||
{
|
||||
if( !LoadSheetFromFile( GetCurrentSheet().Last(), &GetCurrentSheet(), aFullFileName ) )
|
||||
return false;
|
||||
|
||||
initScreenZoom();
|
||||
@ -1502,4 +1505,3 @@ const wxString& SCH_EDIT_FRAME::getAutoSaveFileName() const
|
||||
|
||||
return autoSaveFileName;
|
||||
}
|
||||
|
||||
|
@ -106,6 +106,9 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
|
||||
EVT_MENU( wxID_CLOSE, SCH_EDIT_FRAME::OnExit )
|
||||
|
||||
EVT_MENU( ID_GRID_SETTINGS, SCH_BASE_FRAME::OnGridSettings )
|
||||
|
||||
// Drop files event
|
||||
EVT_DROP_FILES( SCH_EDIT_FRAME::OnDropFiles )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
@ -265,6 +268,10 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
||||
// Default shutdown reason until a file is loaded
|
||||
KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New schematic file is unsaved" ) );
|
||||
|
||||
// Init for dropping files
|
||||
m_acceptedExts.emplace( KiCadSchematicFileExtension, &EE_ACTIONS::ddAppendFile );
|
||||
DragAcceptFiles( true );
|
||||
|
||||
// Ensure the window is on top
|
||||
Raise();
|
||||
|
||||
|
@ -464,6 +464,16 @@ public:
|
||||
*/
|
||||
bool AppendSchematic();
|
||||
|
||||
/**
|
||||
* Add a sheet file into the current sheet and updates display
|
||||
*
|
||||
* @note Used in AppendSchematic() and SCH_EDIT_TOOL::ddAppendFile() (so it is public)
|
||||
*
|
||||
* @param aFullFileName Path and name of sheet
|
||||
* @return True if the sheet was properly added
|
||||
*/
|
||||
bool AddSheetAndUpdateDisplay( const wxString aFullFileName );
|
||||
|
||||
/**
|
||||
* Check if any of the screens has unsaved changes and asks the user whether to save or
|
||||
* drop them.
|
||||
|
@ -91,6 +91,9 @@ BEGIN_EVENT_TABLE( SYMBOL_EDIT_FRAME, EDA_DRAW_FRAME )
|
||||
// Update user interface elements.
|
||||
EVT_UPDATE_UI( ID_LIBEDIT_SELECT_UNIT_NUMBER, SYMBOL_EDIT_FRAME::OnUpdateUnitNumber )
|
||||
|
||||
// Drop files event
|
||||
EVT_DROP_FILES( SYMBOL_EDIT_FRAME::OnDropFiles )
|
||||
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
@ -239,6 +242,9 @@ SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
||||
|
||||
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
|
||||
|
||||
m_acceptedExts.emplace( KiCadSymbolLibFileExtension, &ACTIONS::ddAddLibrary );
|
||||
DragAcceptFiles( true );
|
||||
|
||||
KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Library changes are unsaved" ) );
|
||||
|
||||
// Catch unhandled accelerator command characters that were no handled by the library tree
|
||||
@ -900,6 +906,41 @@ wxString SYMBOL_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_EDIT_FRAME::DdAddLibrary( wxString aLibFile )
|
||||
{
|
||||
// Select the target library table (global/project)
|
||||
SYMBOL_LIB_TABLE* libTable = selectSymLibTable();
|
||||
|
||||
if( !libTable )
|
||||
return;
|
||||
|
||||
wxFileName fn = wxFileName( aLibFile );
|
||||
|
||||
wxString libName = fn.GetName();
|
||||
|
||||
if( libName.IsEmpty() )
|
||||
return;
|
||||
|
||||
if( m_libMgr->LibraryExists( libName ) )
|
||||
{
|
||||
DisplayError( this, wxString::Format( _( "Library '%s' already exists." ), libName ) );
|
||||
return;
|
||||
}
|
||||
|
||||
if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
|
||||
{
|
||||
DisplayError( this, _( "Could not open the library file." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
|
||||
saveSymbolLibTables( globalTable, !globalTable );
|
||||
|
||||
std::string packet = fn.GetFullPath().ToStdString();
|
||||
this->Kiway().ExpressMail( FRAME_SCH_SYMBOL_EDITOR, MAIL_LIB_EDIT, packet );
|
||||
}
|
||||
|
||||
|
||||
LIB_ID SYMBOL_EDIT_FRAME::GetTreeLIBID( int* aUnit ) const
|
||||
{
|
||||
return m_treePane->GetLibTree()->GetSelectedLibId( aUnit );
|
||||
|
@ -124,6 +124,11 @@ public:
|
||||
*/
|
||||
wxString AddLibraryFile( bool aCreateNew );
|
||||
|
||||
/**
|
||||
* Add a library dropped file to the symbol library table.
|
||||
*/
|
||||
void DdAddLibrary( wxString aLibFile );
|
||||
|
||||
/**
|
||||
* Create a new symbol in the selected library.
|
||||
*/
|
||||
|
@ -901,3 +901,7 @@ TOOL_ACTION EE_ACTIONS::saveCurrSheetCopyAs( "eeschema.EditorControl.saveCurrShe
|
||||
0, "",
|
||||
_( "Save Current Sheet Copy As..." ), _( "Save a copy of the current sheet to another location or name" ),
|
||||
BITMAPS::save_as );
|
||||
|
||||
// Drag and drop
|
||||
TOOL_ACTION EE_ACTIONS::ddAppendFile( "eeschema.EditorControl.ddAppendFile",
|
||||
AS_GLOBAL );
|
@ -251,6 +251,9 @@ public:
|
||||
static TOOL_ACTION clearHighlight;
|
||||
static TOOL_ACTION updateNetHighlighting;
|
||||
static TOOL_ACTION highlightNetTool;
|
||||
|
||||
// Drag and drop
|
||||
static TOOL_ACTION ddAppendFile;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -2285,6 +2285,13 @@ int SCH_EDIT_TOOL::EditPageNumber( const TOOL_EVENT& aEvent )
|
||||
}
|
||||
|
||||
|
||||
int SCH_EDIT_TOOL::DdAppendFile( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
wxString aFileName = *aEvent.Parameter<wxString*>();
|
||||
return ( m_frame->AddSheetAndUpdateDisplay( aFileName ) ? 0 : 1 );
|
||||
}
|
||||
|
||||
|
||||
void SCH_EDIT_TOOL::setTransitions()
|
||||
{
|
||||
Go( &SCH_EDIT_TOOL::RepeatDrawItem, EE_ACTIONS::repeatDrawItem.MakeEvent() );
|
||||
@ -2321,4 +2328,6 @@ void SCH_EDIT_TOOL::setTransitions()
|
||||
Go( &SCH_EDIT_TOOL::CleanupSheetPins, EE_ACTIONS::cleanupSheetPins.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::GlobalEdit, EE_ACTIONS::editTextAndGraphics.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::EditPageNumber, EE_ACTIONS::editPageNumber.MakeEvent() );
|
||||
|
||||
Go( &SCH_EDIT_TOOL::DdAppendFile, EE_ACTIONS::ddAppendFile.MakeEvent() );
|
||||
}
|
||||
|
@ -78,6 +78,9 @@ public:
|
||||
///< Run the deletion tool.
|
||||
int DeleteItemCursor( const TOOL_EVENT& aEvent );
|
||||
|
||||
/// Drag and drop
|
||||
int DdAppendFile( const TOOL_EVENT& aEvent );
|
||||
|
||||
private:
|
||||
void editFieldText( SCH_FIELD* aField );
|
||||
|
||||
|
@ -139,6 +139,16 @@ int SYMBOL_EDITOR_CONTROL::AddLibrary( const TOOL_EVENT& aEvent )
|
||||
}
|
||||
|
||||
|
||||
int SYMBOL_EDITOR_CONTROL::DdAddLibrary( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
wxString libFile = *aEvent.Parameter<wxString*>();
|
||||
if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
|
||||
static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->DdAddLibrary( libFile );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int SYMBOL_EDITOR_CONTROL::EditSymbol( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
|
||||
@ -679,6 +689,8 @@ void SYMBOL_EDITOR_CONTROL::setTransitions()
|
||||
Go( &SYMBOL_EDITOR_CONTROL::AddSymbol, EE_ACTIONS::importSymbol.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_CONTROL::EditSymbol, EE_ACTIONS::editSymbol.MakeEvent() );
|
||||
|
||||
Go( &SYMBOL_EDITOR_CONTROL::DdAddLibrary, ACTIONS::ddAddLibrary.MakeEvent() );
|
||||
|
||||
Go( &SYMBOL_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_CONTROL::Save, EE_ACTIONS::saveLibraryAs.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_CONTROL::Save, EE_ACTIONS::saveSymbolAs.MakeEvent() );
|
||||
|
@ -70,6 +70,8 @@ public:
|
||||
int ToggleSymbolTree( const TOOL_EVENT& aEvent );
|
||||
int ToggleSyncedPinsMode( const TOOL_EVENT& aEvent );
|
||||
|
||||
int DdAddLibrary( const TOOL_EVENT& aEvent );
|
||||
|
||||
private:
|
||||
///< Set up handlers for various events.
|
||||
void setTransitions() override;
|
||||
|
@ -85,6 +85,9 @@ BEGIN_EVENT_TABLE( GERBVIEW_FRAME, EDA_DRAW_FRAME )
|
||||
EVT_UPDATE_UI_RANGE( ID_TB_OPTIONS_SHOW_GBR_MODE_0, ID_TB_OPTIONS_SHOW_GBR_MODE_2,
|
||||
GERBVIEW_FRAME::OnUpdateDrawMode )
|
||||
|
||||
// Drop files event
|
||||
EVT_DROP_FILES( GERBVIEW_FRAME::OnDropFiles )
|
||||
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <view/view.h>
|
||||
#include <widgets/wx_progress_reporters.h>
|
||||
#include "widgets/gerbview_layer_widget.h"
|
||||
#include <tool/tool_manager.h>
|
||||
|
||||
// HTML Messages used more than one time:
|
||||
#define MSG_NO_MORE_LAYER _( "<b>No more available layers</b> in GerbView to load files" )
|
||||
@ -672,3 +673,27 @@ bool GERBVIEW_FRAME::LoadZipArchiveFile( const wxString& aFullFileName )
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GERBVIEW_FRAME::DoWithAcceptedFiles()
|
||||
{
|
||||
wxString gerbFn; // param to be sent with action event.
|
||||
|
||||
for( auto file : m_AcceptedFiles )
|
||||
{
|
||||
if( IsExtensionAccepted( file.GetExt(), { ArchiveFileExtension } ) )
|
||||
{
|
||||
wxString fn = file.GetFullPath();
|
||||
// Open zip archive in editor
|
||||
m_toolManager->RunAction( *m_acceptedExts.at( ArchiveFileExtension ), true, &fn );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Store FileName in variable to open later
|
||||
gerbFn += '"' + file.GetFullPath() + '"';
|
||||
}
|
||||
}
|
||||
|
||||
// Open files in editor
|
||||
if( !gerbFn.IsEmpty() )
|
||||
m_toolManager->RunAction( *m_acceptedExts.at( DrillFileExtension ), true, &gerbFn );
|
||||
}
|
@ -177,6 +177,13 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent )
|
||||
m_LayersManager->ReFill();
|
||||
m_LayersManager->ReFillRender(); // Update colors in Render after the config is read
|
||||
|
||||
// Drag and drop
|
||||
m_acceptedExts.emplace( ArchiveFileExtension, &GERBVIEW_ACTIONS::loadZipFile );
|
||||
for( const auto& ext : GerberFileExtensions )
|
||||
m_acceptedExts.emplace( ext, &GERBVIEW_ACTIONS::loadGerbFiles );
|
||||
m_acceptedExts.emplace( DrillFileExtension, &GERBVIEW_ACTIONS::loadGerbFiles );
|
||||
DragAcceptFiles( true );
|
||||
|
||||
GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
|
||||
|
||||
// Ensure the window is on top
|
||||
|
@ -496,6 +496,8 @@ private:
|
||||
void OnClearDrlFileHistory( wxCommandEvent& aEvent );
|
||||
void OnClearGbrFileHistory( wxCommandEvent& aEvent );
|
||||
|
||||
void DoWithAcceptedFiles() override;
|
||||
|
||||
/**
|
||||
* Loads the file provided or shows a dialog to get the file(s) from the user.
|
||||
*
|
||||
|
@ -214,3 +214,10 @@ TOOL_ACTION GERBVIEW_ACTIONS::selectionClear( "gerbview.InteractiveSelection.Cle
|
||||
AS_GLOBAL );
|
||||
|
||||
|
||||
// Drag and drop
|
||||
//
|
||||
TOOL_ACTION GERBVIEW_ACTIONS::loadZipFile( "gerbview.Control.loadZipFile",
|
||||
AS_GLOBAL );
|
||||
|
||||
TOOL_ACTION GERBVIEW_ACTIONS::loadGerbFiles( "gerbview.Control.loadGerbFiles",
|
||||
AS_GLOBAL );
|
||||
|
@ -93,6 +93,10 @@ public:
|
||||
static TOOL_ACTION highlightComponent;
|
||||
static TOOL_ACTION highlightAttribute;
|
||||
static TOOL_ACTION highlightDCode;
|
||||
|
||||
// Drag and drop
|
||||
static TOOL_ACTION loadZipFile;
|
||||
static TOOL_ACTION loadGerbFiles;
|
||||
};
|
||||
|
||||
#endif // __GERBVIEW_ACTIONS_H
|
||||
|
@ -460,6 +460,46 @@ int GERBVIEW_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
|
||||
}
|
||||
|
||||
|
||||
int GERBVIEW_CONTROL::LoadZipfile( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
m_frame->LoadZipArchiveFile( *aEvent.Parameter<wxString*>() );
|
||||
canvas()->Refresh();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int GERBVIEW_CONTROL::LoadGerbFiles( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
// The event parameter is a string containing names of dropped files.
|
||||
// Each file name has been enclosed with "", so file names with space character are allowed.
|
||||
wxString files = *aEvent.Parameter<wxString*>();
|
||||
// ie : files = "file1""another file""file3"...
|
||||
|
||||
std::vector<wxString> aFileNameList;
|
||||
|
||||
// Isolate each file name, deletting ""
|
||||
files = files.AfterFirst( '"' );
|
||||
|
||||
// Gerber files are enclosed with "".
|
||||
// Load files names in array.
|
||||
while( !files.empty() )
|
||||
{
|
||||
wxString fileName = files.BeforeFirst( '"' );
|
||||
// Check if file exists. If not, keep on and ignore fileName
|
||||
if( wxFileName( fileName ).Exists() )
|
||||
aFileNameList.push_back( fileName );
|
||||
files = files.AfterFirst( '"' );
|
||||
files = files.AfterFirst( '"' );
|
||||
}
|
||||
|
||||
if( !aFileNameList.empty() )
|
||||
m_frame->OpenProjectFiles( aFileNameList, KICTL_CREATE );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void GERBVIEW_CONTROL::setTransitions()
|
||||
{
|
||||
Go( &GERBVIEW_CONTROL::OpenAutodetected, GERBVIEW_ACTIONS::openAutodetected.MakeEvent() );
|
||||
@ -499,4 +539,7 @@ void GERBVIEW_CONTROL::setTransitions()
|
||||
Go( &GERBVIEW_CONTROL::UpdateMessagePanel, EVENTS::UnselectedEvent );
|
||||
Go( &GERBVIEW_CONTROL::UpdateMessagePanel, EVENTS::ClearedEvent );
|
||||
Go( &GERBVIEW_CONTROL::UpdateMessagePanel, ACTIONS::updateUnits.MakeEvent() );
|
||||
|
||||
Go( &GERBVIEW_CONTROL::LoadZipfile, GERBVIEW_ACTIONS::loadZipFile.MakeEvent() );
|
||||
Go( &GERBVIEW_CONTROL::LoadGerbFiles, GERBVIEW_ACTIONS::loadGerbFiles.MakeEvent() );
|
||||
}
|
||||
|
@ -68,6 +68,10 @@ public:
|
||||
int UpdateMessagePanel( const TOOL_EVENT& aEvent );
|
||||
int Print( const TOOL_EVENT& aEvent );
|
||||
|
||||
// Drag and drop
|
||||
int LoadZipfile( const TOOL_EVENT& aEvent );
|
||||
int LoadGerbFiles( const TOOL_EVENT& aEvent );
|
||||
|
||||
///< Set up handlers for various events.
|
||||
void setTransitions() override;
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <wx/aui/aui.h>
|
||||
#include <layer_ids.h>
|
||||
@ -608,7 +609,7 @@ protected:
|
||||
|
||||
/**
|
||||
* Handle a window iconize event.
|
||||
*
|
||||
*
|
||||
* @param aEvent is the data for the event.
|
||||
*/
|
||||
virtual void handleIconizeEvent( wxIconizeEvent& aEvent ) {}
|
||||
@ -657,6 +658,21 @@ protected:
|
||||
|
||||
void ensureWindowIsOnScreen();
|
||||
|
||||
/**
|
||||
* Handles event fired when a file is dropped to the window.
|
||||
* In this base class, stores the path of files accepted.
|
||||
* Calls DoWithAcceptedFiles() to execute actions on files.
|
||||
*/
|
||||
virtual void OnDropFiles( wxDropFilesEvent& aEvent );
|
||||
|
||||
/**
|
||||
* Execute action on accepted dropped file.
|
||||
* Called in OnDropFiles and should be populated with
|
||||
* the action to execute in inherited classes.
|
||||
*/
|
||||
virtual void DoWithAcceptedFiles();
|
||||
std::vector<wxFileName> m_AcceptedFiles;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
private:
|
||||
@ -743,6 +759,11 @@ private:
|
||||
|
||||
///< Set by #NonUserClose() to indicate that the user did not request the current close.
|
||||
bool m_isNonUserClose;
|
||||
|
||||
/**
|
||||
* Associates files extensions with action to execute.
|
||||
*/
|
||||
std::map<const wxString, TOOL_ACTION*> m_acceptedExts;
|
||||
};
|
||||
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user