From 8c017c7503d530d0fb7900360bed033ac80eb12b Mon Sep 17 00:00:00 2001 From: jack2bs Date: Sun, 22 Jun 2025 12:26:57 +0000 Subject: [PATCH] bitmap2component: Adding file drag and drop --- bitmap2component/bitmap2cmp_panel.cpp | 39 ++++++++++++++++++++++++++- bitmap2component/bitmap2cmp_panel.h | 16 ++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/bitmap2component/bitmap2cmp_panel.cpp b/bitmap2component/bitmap2cmp_panel.cpp index ea88134a66..761f2b3f2b 100644 --- a/bitmap2component/bitmap2cmp_panel.cpp +++ b/bitmap2component/bitmap2cmp_panel.cpp @@ -30,11 +30,15 @@ #include #include // for KiROUND #include +#include +#include #include +#include #include #include #include #include +#include #define DEFAULT_DPI 300 // the image DPI used in formats that do not define a DPI @@ -58,8 +62,11 @@ BITMAP2CMP_PANEL::BITMAP2CMP_PANEL( BITMAP2CMP_FRAME* aParent ) : m_buttonExportFile->Enable( false ); m_buttonExportClipboard->Enable( false ); -} + m_InitialPicturePanel->SetDropTarget( new DROP_FILE( this ) ); + m_GreyscalePicturePanel->SetDropTarget( new DROP_FILE( this ) ); + m_BNPicturePanel->SetDropTarget( new DROP_FILE( this ) ); +} wxWindow* BITMAP2CMP_PANEL::GetCurrentPage() { @@ -562,3 +569,33 @@ void BITMAP2CMP_PANEL::OnFormatChange( wxCommandEvent& event ) m_layerLabel->Enable( m_rbFootprint->GetValue() ); m_layerCtrl->Enable( m_rbFootprint->GetValue() ); } + + +DROP_FILE::DROP_FILE( BITMAP2CMP_PANEL* panel ) : + m_panel( panel ) +{ +} + + +bool DROP_FILE::OnDropFiles( wxCoord x, wxCoord y, const wxArrayString& filenames ) +{ + m_panel->SetFocus(); + + // If a file is already loaded + if( m_panel->GetOutputSizeX().GetOriginalSizePixels() != 0 ) + { + wxString cap = _( "Replace Loaded File?" ); + wxString msg = _( "There is already a file loaded. Do you want to replace it?" ); + wxMessageDialog acceptFileDlg( m_panel, msg, cap, wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT ); + int replace = acceptFileDlg.ShowModal(); + + if( replace == wxID_NO ) + return false; + } + + std::vector fNameVec; + fNameVec.insert( fNameVec.begin(), filenames.begin(), filenames.end() ); + m_panel->OpenProjectFiles( fNameVec ); + + return true; +} diff --git a/bitmap2component/bitmap2cmp_panel.h b/bitmap2component/bitmap2cmp_panel.h index e83f76b4ad..c339cd3d5f 100644 --- a/bitmap2component/bitmap2cmp_panel.h +++ b/bitmap2component/bitmap2cmp_panel.h @@ -25,7 +25,7 @@ #include #include - +#include class BITMAP2CMP_FRAME; class BITMAP2CMP_SETTINGS; @@ -134,4 +134,18 @@ private: bool m_negative; double m_aspectRatio; }; + + +class DROP_FILE : public wxFileDropTarget +{ +public: + DROP_FILE( BITMAP2CMP_PANEL* panel ); + DROP_FILE() = delete; + + bool OnDropFiles( wxCoord x, wxCoord y, const wxArrayString& filenames ) override; + +private: + BITMAP2CMP_PANEL* m_panel; +}; + #endif// BITMAP2CMP_PANEL