Adding drag and drop project file feature.

ADDED Drag and drop of project file from file explorer to Kicad manager window.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8146
This commit is contained in:
lulu731 2022-05-12 22:38:45 +00:00 committed by Seth Hillbrand
parent bbc250720f
commit f4f3638103
2 changed files with 26 additions and 0 deletions

View File

@ -95,6 +95,10 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME )
// Special functions
EVT_MENU( ID_INIT_WATCHED_PATHS, KICAD_MANAGER_FRAME::OnChangeWatchedPaths )
// Drop files event
EVT_DROP_FILES( KICAD_MANAGER_FRAME::OnDropFiles )
END_EVENT_TABLE()
@ -198,6 +202,8 @@ KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& titl
// Do not let the messages window have initial focus
m_leftWin->SetFocus();
DragAcceptFiles( true );
// Ensure the window is on top
Raise();
}
@ -355,6 +361,19 @@ void KICAD_MANAGER_FRAME::OnSize( wxSizeEvent& event )
event.Skip();
}
void KICAD_MANAGER_FRAME::OnDropFiles( wxDropFilesEvent& aEvent )
{
wxString* files = aEvent.GetFiles();
for( int nb = 0; nb < aEvent.GetNumberOfFiles(); nb++ )
{
const wxFileName fn = wxFileName( files[nb] );
if( fn.GetExt() == "kicad_pro" || fn.GetExt() == "pro" )
{
LoadProject( fn );
break;
}
}
}
bool KICAD_MANAGER_FRAME::canCloseWindow( wxCloseEvent& aEvent )
{

View File

@ -28,6 +28,7 @@
#include <wx/process.h>
#include <kiway_player.h>
#include <wx/dnd.h>
class PROJECT_TREE;
class PROJECT_TREE_PANE;
@ -159,6 +160,12 @@ private:
void setupTools();
void setupActions();
/**
* Handles event fired when a file is dropped to window.
* Opens project file. Does nothing if it is not a kicad project file.
*/
void OnDropFiles( wxDropFilesEvent& aEvent );
APP_SETTINGS_BASE* config() const override;
KICAD_SETTINGS* kicadSettings() const;