2018-07-20 15:03:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-02-17 14:06:19 +00:00
|
|
|
* Copyright (C) 2021 CERN
|
2023-09-29 16:02:57 +00:00
|
|
|
* Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-07-20 15:03:43 +00:00
|
|
|
*
|
|
|
|
* 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 <wx/combo.h>
|
2020-10-18 11:31:07 +00:00
|
|
|
#include <wx/filedlg.h>
|
|
|
|
#include <wx/dirdlg.h>
|
2021-06-03 11:49:49 +00:00
|
|
|
#include <wx/textctrl.h>
|
2020-10-18 11:31:07 +00:00
|
|
|
|
2018-07-20 15:03:43 +00:00
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <kiway.h>
|
|
|
|
#include <kiway_player.h>
|
2022-07-24 22:40:47 +00:00
|
|
|
#include <kiway_express.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2018-07-20 15:03:43 +00:00
|
|
|
#include <dialog_shim.h>
|
2020-10-24 14:45:37 +00:00
|
|
|
#include <common.h>
|
2020-09-01 02:00:38 +00:00
|
|
|
#include <env_paths.h>
|
2021-06-09 01:56:00 +00:00
|
|
|
#include <pgm_base.h>
|
2021-02-17 14:06:19 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2018-07-20 15:03:43 +00:00
|
|
|
#include <widgets/grid_text_button_helpers.h>
|
|
|
|
#include <eda_doc.h>
|
|
|
|
|
|
|
|
|
|
|
|
//-------- Renderer ---------------------------------------------------------------------
|
|
|
|
// None required; just render as normal text.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------- Editor Base Class ------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Note: this implementation is an adaptation of wxGridCellChoiceEditor
|
|
|
|
|
|
|
|
|
|
|
|
wxString GRID_CELL_TEXT_BUTTON::GetValue() const
|
|
|
|
{
|
|
|
|
return Combo()->GetValue();
|
|
|
|
}
|
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
|
2018-07-20 15:03:43 +00:00
|
|
|
void GRID_CELL_TEXT_BUTTON::SetSize( const wxRect& aRect )
|
|
|
|
{
|
|
|
|
wxRect rect( aRect );
|
|
|
|
|
|
|
|
#if defined( __WXMAC__ )
|
2022-02-16 17:43:34 +00:00
|
|
|
rect.Inflate( 2 ); // ignore FOCUS_RING
|
|
|
|
#elif defined( __WXGTK__ )
|
|
|
|
rect.Inflate( -3 ); // The -3 is a very sad hack here. Some GTK themes overrun the
|
|
|
|
// default -1, preventing display. Unfortunately, we don't appear to
|
|
|
|
// have a good method of finding the current margin needed.
|
|
|
|
// Some GTK resize events seem to update the cell size but not all and
|
|
|
|
// not consistently.
|
|
|
|
#else
|
|
|
|
rect.Inflate( -1 );
|
2018-07-20 15:03:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
Combo()->SetSize( rect, wxSIZE_ALLOW_MINUS_ONE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-21 20:23:13 +00:00
|
|
|
void GRID_CELL_TEXT_BUTTON::StartingKey( wxKeyEvent& event )
|
|
|
|
{
|
|
|
|
// Note: this is a copy of wxGridCellTextEditor's StartingKey()
|
|
|
|
|
|
|
|
// Since this is now happening in the EVT_CHAR event EmulateKeyPress is no
|
|
|
|
// longer an appropriate way to get the character into the text control.
|
|
|
|
// Do it ourselves instead. We know that if we get this far that we have
|
|
|
|
// a valid character, so not a whole lot of testing needs to be done.
|
|
|
|
|
2021-05-27 18:19:06 +00:00
|
|
|
// wxComboCtrl inherits from wxTextEntry, so can statically cast
|
2020-01-12 19:45:37 +00:00
|
|
|
wxTextEntry* textEntry = static_cast<wxTextEntry*>( Combo() );
|
2018-07-21 20:23:13 +00:00
|
|
|
int ch;
|
|
|
|
|
|
|
|
bool isPrintable;
|
|
|
|
|
|
|
|
#if wxUSE_UNICODE
|
|
|
|
ch = event.GetUnicodeKey();
|
2019-05-10 12:21:08 +00:00
|
|
|
|
|
|
|
if( ch != WXK_NONE )
|
2018-07-21 20:23:13 +00:00
|
|
|
isPrintable = true;
|
|
|
|
else
|
|
|
|
#endif // wxUSE_UNICODE
|
|
|
|
{
|
|
|
|
ch = event.GetKeyCode();
|
|
|
|
isPrintable = ch >= WXK_SPACE && ch < WXK_START;
|
|
|
|
}
|
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
switch( ch )
|
2018-07-21 20:23:13 +00:00
|
|
|
{
|
|
|
|
case WXK_DELETE:
|
|
|
|
// Delete the initial character when starting to edit with DELETE.
|
2019-05-10 12:21:08 +00:00
|
|
|
textEntry->Remove( 0, 1 );
|
2018-07-21 20:23:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_BACK:
|
|
|
|
// Delete the last character when starting to edit with BACKSPACE.
|
|
|
|
{
|
|
|
|
const long pos = textEntry->GetLastPosition();
|
2019-05-10 12:21:08 +00:00
|
|
|
textEntry->Remove( pos - 1, pos );
|
2018-07-21 20:23:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-05-10 12:21:08 +00:00
|
|
|
if( isPrintable )
|
|
|
|
textEntry->WriteText( static_cast<wxChar>( ch ) );
|
2018-07-21 20:23:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 15:03:43 +00:00
|
|
|
void GRID_CELL_TEXT_BUTTON::BeginEdit( int aRow, int aCol, wxGrid* aGrid )
|
|
|
|
{
|
2019-05-10 12:21:08 +00:00
|
|
|
auto evtHandler = static_cast< wxGridCellEditorEvtHandler* >( m_control->GetEventHandler() );
|
2018-07-20 15:03:43 +00:00
|
|
|
|
|
|
|
// Don't immediately end if we get a kill focus event within BeginEdit
|
|
|
|
evtHandler->SetInSetFocus( true );
|
|
|
|
|
|
|
|
m_value = aGrid->GetTable()->GetValue( aRow, aCol );
|
|
|
|
|
|
|
|
Combo()->SetValue( m_value );
|
|
|
|
Combo()->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
bool GRID_CELL_TEXT_BUTTON::EndEdit( int, int, const wxGrid*, const wxString&, wxString *aNewVal )
|
2018-07-20 15:03:43 +00:00
|
|
|
{
|
|
|
|
const wxString value = Combo()->GetValue();
|
|
|
|
|
|
|
|
if( value == m_value )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_value = value;
|
|
|
|
|
|
|
|
if( aNewVal )
|
|
|
|
*aNewVal = value;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GRID_CELL_TEXT_BUTTON::ApplyEdit( int aRow, int aCol, wxGrid* aGrid )
|
|
|
|
{
|
|
|
|
aGrid->GetTable()->SetValue( aRow, aCol, m_value );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GRID_CELL_TEXT_BUTTON::Reset()
|
|
|
|
{
|
2019-01-16 13:16:26 +00:00
|
|
|
Combo()->SetValue( m_value );
|
2018-07-20 15:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
#if wxUSE_VALIDATORS
|
|
|
|
void GRID_CELL_TEXT_BUTTON::SetValidator( const wxValidator& validator )
|
|
|
|
{
|
|
|
|
m_validator.reset( static_cast< wxValidator* >( validator.Clone() ) );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-29 16:18:55 +00:00
|
|
|
|
|
|
|
class TEXT_BUTTON_SYMBOL_CHOOSER : public wxComboCtrl
|
|
|
|
{
|
|
|
|
public:
|
2019-01-31 01:07:53 +00:00
|
|
|
TEXT_BUTTON_SYMBOL_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg,
|
|
|
|
const wxString& aPreselect ) :
|
2018-09-29 16:18:55 +00:00
|
|
|
wxComboCtrl( aParent ),
|
2019-01-31 01:07:53 +00:00
|
|
|
m_dlg( aParentDlg ),
|
|
|
|
m_preselect( aPreselect )
|
2018-09-29 16:18:55 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
SetButtonBitmaps( KiBitmap( BITMAPS::small_library ) );
|
2021-04-15 02:54:40 +00:00
|
|
|
|
|
|
|
// win32 fix, avoids drawing the "native dropdown caret"
|
|
|
|
Customize( wxCC_IFLAG_HAS_NONSTANDARD_BUTTON );
|
2018-09-29 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void DoSetPopupControl( wxComboPopup* popup ) override
|
|
|
|
{
|
|
|
|
m_popup = nullptr;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:36:13 +00:00
|
|
|
wxString escapeLibId( const wxString& aRawValue )
|
|
|
|
{
|
|
|
|
wxString itemName;
|
|
|
|
wxString libName = aRawValue.BeforeFirst( ':', &itemName );
|
|
|
|
return EscapeString( libName, CTX_LIBID ) + ':' + EscapeString( itemName, CTX_LIBID );
|
|
|
|
}
|
|
|
|
|
2018-09-29 16:18:55 +00:00
|
|
|
void OnButtonClick() override
|
|
|
|
{
|
2021-07-28 17:36:13 +00:00
|
|
|
// pick a symbol using the symbol picker.
|
|
|
|
wxString rawValue = GetValue();
|
2019-01-31 01:07:53 +00:00
|
|
|
|
2021-07-28 17:36:13 +00:00
|
|
|
if( rawValue.IsEmpty() )
|
|
|
|
rawValue = m_preselect;
|
2019-01-31 01:07:53 +00:00
|
|
|
|
2021-07-28 17:36:13 +00:00
|
|
|
wxString symbolId = escapeLibId( rawValue );
|
2023-09-28 13:09:45 +00:00
|
|
|
KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_SYMBOL_CHOOSER, true, m_dlg );
|
2018-09-29 16:18:55 +00:00
|
|
|
|
2021-07-28 17:36:13 +00:00
|
|
|
if( frame->ShowModal( &symbolId, m_dlg ) )
|
2021-07-28 18:43:57 +00:00
|
|
|
SetValue( UnescapeString( symbolId ) );
|
2018-09-29 16:18:55 +00:00
|
|
|
|
|
|
|
frame->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
DIALOG_SHIM* m_dlg;
|
2019-01-31 01:07:53 +00:00
|
|
|
wxString m_preselect;
|
2018-09-29 16:18:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void GRID_CELL_SYMBOL_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
|
|
|
|
wxEvtHandler* aEventHandler )
|
|
|
|
{
|
2019-01-31 01:07:53 +00:00
|
|
|
m_control = new TEXT_BUTTON_SYMBOL_CHOOSER( aParent, m_dlg, m_preselect );
|
2018-09-29 16:18:55 +00:00
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
wxGridCellEditor::Create( aParent, aId, aEventHandler );
|
2018-09-29 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 15:03:43 +00:00
|
|
|
class TEXT_BUTTON_FP_CHOOSER : public wxComboCtrl
|
|
|
|
{
|
|
|
|
public:
|
2019-01-31 01:07:53 +00:00
|
|
|
TEXT_BUTTON_FP_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg,
|
2022-07-24 22:40:47 +00:00
|
|
|
const wxString& aSymbolNetlist, const wxString& aPreselect ) :
|
2021-04-16 14:07:03 +00:00
|
|
|
wxComboCtrl( aParent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
|
2021-04-15 01:37:21 +00:00
|
|
|
wxTE_PROCESS_ENTER ),
|
2019-01-31 01:07:53 +00:00
|
|
|
m_dlg( aParentDlg ),
|
2022-07-24 22:40:47 +00:00
|
|
|
m_preselect( aPreselect ),
|
|
|
|
m_symbolNetlist( aSymbolNetlist.ToStdString() )
|
2018-07-20 15:03:43 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
SetButtonBitmaps( KiBitmap( BITMAPS::small_library ) );
|
2021-04-15 02:54:40 +00:00
|
|
|
|
|
|
|
// win32 fix, avoids drawing the "native dropdown caret"
|
|
|
|
Customize( wxCC_IFLAG_HAS_NONSTANDARD_BUTTON );
|
2018-07-20 15:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void DoSetPopupControl( wxComboPopup* popup ) override
|
|
|
|
{
|
|
|
|
m_popup = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnButtonClick() override
|
|
|
|
{
|
|
|
|
// pick a footprint using the footprint picker.
|
2022-07-24 22:40:47 +00:00
|
|
|
wxString fpid = GetValue();
|
2019-01-31 01:07:53 +00:00
|
|
|
|
|
|
|
if( fpid.IsEmpty() )
|
|
|
|
fpid = m_preselect;
|
|
|
|
|
2023-09-26 17:31:45 +00:00
|
|
|
KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg );
|
2018-07-20 15:03:43 +00:00
|
|
|
|
2022-07-24 22:40:47 +00:00
|
|
|
if( !m_symbolNetlist.empty() )
|
|
|
|
{
|
2023-09-29 16:02:57 +00:00
|
|
|
KIWAY_EXPRESS event( FRAME_FOOTPRINT_CHOOSER, MAIL_SYMBOL_NETLIST, m_symbolNetlist );
|
2022-07-24 22:40:47 +00:00
|
|
|
frame->KiwayMailIn( event );
|
|
|
|
}
|
|
|
|
|
2018-07-20 15:03:43 +00:00
|
|
|
if( frame->ShowModal( &fpid, m_dlg ) )
|
|
|
|
SetValue( fpid );
|
|
|
|
|
|
|
|
frame->Destroy();
|
|
|
|
}
|
|
|
|
|
2023-09-29 16:02:57 +00:00
|
|
|
protected:
|
2018-07-20 15:03:43 +00:00
|
|
|
DIALOG_SHIM* m_dlg;
|
2019-01-31 01:07:53 +00:00
|
|
|
wxString m_preselect;
|
2022-07-24 22:40:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Symbol netlist format:
|
2024-03-09 11:58:23 +00:00
|
|
|
* pinNumber pinName <tab> pinNumber pinName...
|
|
|
|
* fpFilter fpFilter...
|
2022-07-24 22:40:47 +00:00
|
|
|
*/
|
|
|
|
std::string m_symbolNetlist;
|
2018-07-20 15:03:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-07-24 22:40:47 +00:00
|
|
|
void GRID_CELL_FPID_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
|
|
|
|
wxEvtHandler* aEventHandler )
|
2018-07-20 15:03:43 +00:00
|
|
|
{
|
2022-07-24 22:40:47 +00:00
|
|
|
m_control = new TEXT_BUTTON_FP_CHOOSER( aParent, m_dlg, m_symbolNetlist, m_preselect );
|
2018-07-20 15:03:43 +00:00
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
#if wxUSE_VALIDATORS
|
|
|
|
// validate text in textctrl, if validator is set
|
|
|
|
if ( m_validator )
|
|
|
|
{
|
|
|
|
Combo()->SetValidator( *m_validator );
|
|
|
|
}
|
|
|
|
#endif
|
2018-07-20 15:03:43 +00:00
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
wxGridCellEditor::Create( aParent, aId, aEventHandler );
|
|
|
|
}
|
2018-07-20 15:03:43 +00:00
|
|
|
|
2018-08-24 18:28:11 +00:00
|
|
|
|
2018-07-20 15:03:43 +00:00
|
|
|
class TEXT_BUTTON_URL : public wxComboCtrl
|
|
|
|
{
|
|
|
|
public:
|
2022-05-11 01:28:48 +00:00
|
|
|
TEXT_BUTTON_URL( wxWindow* aParent, DIALOG_SHIM* aParentDlg, SEARCH_STACK* aSearchStack ) :
|
2021-04-16 14:07:03 +00:00
|
|
|
wxComboCtrl( aParent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
|
2021-04-15 01:37:21 +00:00
|
|
|
wxTE_PROCESS_ENTER ),
|
2022-05-11 01:28:48 +00:00
|
|
|
m_dlg( aParentDlg ),
|
|
|
|
m_searchStack( aSearchStack )
|
2018-07-20 15:03:43 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
SetButtonBitmaps( KiBitmap( BITMAPS::www ) );
|
2021-04-15 02:54:40 +00:00
|
|
|
|
|
|
|
// win32 fix, avoids drawing the "native dropdown caret"
|
|
|
|
Customize( wxCC_IFLAG_HAS_NONSTANDARD_BUTTON );
|
2018-07-20 15:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void DoSetPopupControl( wxComboPopup* popup ) override
|
|
|
|
{
|
|
|
|
m_popup = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnButtonClick() override
|
|
|
|
{
|
2018-08-13 22:27:54 +00:00
|
|
|
wxString filename = GetValue();
|
|
|
|
|
|
|
|
if( !filename.IsEmpty() && filename != wxT( "~" ) )
|
2022-05-11 01:28:48 +00:00
|
|
|
GetAssociatedDocument( m_dlg, GetValue(), &m_dlg->Prj(), m_searchStack );
|
2018-07-20 15:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DIALOG_SHIM* m_dlg;
|
2022-05-11 01:28:48 +00:00
|
|
|
SEARCH_STACK* m_searchStack;
|
2018-07-20 15:03:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void GRID_CELL_URL_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
|
|
|
|
wxEvtHandler* aEventHandler )
|
|
|
|
{
|
2022-05-11 01:28:48 +00:00
|
|
|
m_control = new TEXT_BUTTON_URL( aParent, m_dlg, m_searchStack );
|
2018-07-20 15:03:43 +00:00
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
#if wxUSE_VALIDATORS
|
|
|
|
// validate text in textctrl, if validator is set
|
|
|
|
if ( m_validator )
|
|
|
|
{
|
|
|
|
Combo()->SetValidator( *m_validator );
|
|
|
|
}
|
|
|
|
#endif
|
2018-07-20 15:03:43 +00:00
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
wxGridCellEditor::Create( aParent, aId, aEventHandler );
|
|
|
|
}
|
2018-07-20 15:03:43 +00:00
|
|
|
|
2018-08-24 18:28:11 +00:00
|
|
|
|
|
|
|
class TEXT_BUTTON_FILE_BROWSER : public wxComboCtrl
|
|
|
|
{
|
|
|
|
public:
|
2021-02-17 14:06:19 +00:00
|
|
|
TEXT_BUTTON_FILE_BROWSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg, WX_GRID* aGrid,
|
2024-01-22 18:26:39 +00:00
|
|
|
wxString* aCurrentDir, const wxString& aFileFilter = wxEmptyString,
|
2021-02-17 14:06:19 +00:00
|
|
|
bool aNormalize = false,
|
2024-01-22 18:26:39 +00:00
|
|
|
const wxString& aNormalizeBasePath = wxEmptyString ) :
|
2021-04-16 14:07:03 +00:00
|
|
|
wxComboCtrl( aParent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
|
2021-04-15 01:37:21 +00:00
|
|
|
wxTE_PROCESS_ENTER ),
|
2018-08-24 18:28:11 +00:00
|
|
|
m_dlg( aParentDlg ),
|
2021-02-17 14:06:19 +00:00
|
|
|
m_grid( aGrid ),
|
2019-03-03 04:04:17 +00:00
|
|
|
m_currentDir( aCurrentDir ),
|
2020-09-01 02:00:38 +00:00
|
|
|
m_normalize( aNormalize ),
|
2024-01-22 18:26:39 +00:00
|
|
|
m_normalizeBasePath( aNormalizeBasePath ),
|
|
|
|
m_fileFilter( aFileFilter )
|
2018-08-24 18:28:11 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
SetButtonBitmaps( KiBitmap( BITMAPS::small_folder ) );
|
2021-04-15 02:54:40 +00:00
|
|
|
|
|
|
|
// win32 fix, avoids drawing the "native dropdown caret"
|
|
|
|
Customize( wxCC_IFLAG_HAS_NONSTANDARD_BUTTON );
|
2018-08-24 18:28:11 +00:00
|
|
|
}
|
|
|
|
|
2024-01-22 18:26:39 +00:00
|
|
|
TEXT_BUTTON_FILE_BROWSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg, WX_GRID* aGrid,
|
|
|
|
wxString* aCurrentDir,
|
|
|
|
std::function<wxString( WX_GRID* grid, int row )> aFileFilterFn,
|
|
|
|
bool aNormalize = false,
|
|
|
|
const wxString& aNormalizeBasePath = wxEmptyString ) :
|
|
|
|
wxComboCtrl( aParent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_PROCESS_ENTER ),
|
|
|
|
m_dlg( aParentDlg ),
|
|
|
|
m_grid( aGrid ),
|
|
|
|
m_currentDir( aCurrentDir ),
|
|
|
|
m_normalize( aNormalize ),
|
|
|
|
m_normalizeBasePath( aNormalizeBasePath ),
|
|
|
|
m_fileFilterFn( std::move( aFileFilterFn ) )
|
2023-12-07 11:14:10 +00:00
|
|
|
{
|
2024-01-22 18:26:39 +00:00
|
|
|
SetButtonBitmaps( KiBitmap( BITMAPS::small_folder ) );
|
|
|
|
|
|
|
|
// win32 fix, avoids drawing the "native dropdown caret"
|
|
|
|
Customize( wxCC_IFLAG_HAS_NONSTANDARD_BUTTON );
|
2023-12-07 11:14:10 +00:00
|
|
|
}
|
|
|
|
|
2024-01-22 18:26:39 +00:00
|
|
|
|
2018-08-24 18:28:11 +00:00
|
|
|
protected:
|
|
|
|
void DoSetPopupControl( wxComboPopup* popup ) override
|
|
|
|
{
|
|
|
|
m_popup = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnButtonClick() override
|
|
|
|
{
|
2024-01-22 18:26:39 +00:00
|
|
|
if( m_fileFilterFn )
|
|
|
|
m_fileFilter = m_fileFilterFn( m_grid, m_grid->GetGridCursorRow() );
|
|
|
|
|
2021-05-27 18:19:06 +00:00
|
|
|
wxFileName fn = GetValue();
|
2018-08-24 18:28:11 +00:00
|
|
|
|
2021-05-27 18:19:06 +00:00
|
|
|
if( fn.GetPath().IsEmpty() && m_currentDir )
|
|
|
|
fn.SetPath( *m_currentDir );
|
2018-08-24 18:28:11 +00:00
|
|
|
else
|
2021-05-27 18:19:06 +00:00
|
|
|
fn.SetPath( ExpandEnvVarSubstitutions( fn.GetPath(), &m_dlg->Prj() ) );
|
2018-08-24 18:28:11 +00:00
|
|
|
|
2024-01-22 18:26:39 +00:00
|
|
|
if( !m_fileFilter.IsEmpty() )
|
2019-03-03 04:04:17 +00:00
|
|
|
{
|
2023-10-27 22:24:24 +00:00
|
|
|
wxFileDialog dlg( m_dlg, _( "Select a File" ), fn.GetPath(), fn.GetFullName(),
|
2024-01-22 18:26:39 +00:00
|
|
|
m_fileFilter, wxFD_FILE_MUST_EXIST | wxFD_OPEN );
|
2019-03-03 04:04:17 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
2020-09-01 02:00:38 +00:00
|
|
|
wxString filePath = dlg.GetPath();
|
|
|
|
wxString lastPath = dlg.GetDirectory();
|
|
|
|
wxString relPath = wxEmptyString;
|
|
|
|
|
|
|
|
if( m_normalize )
|
|
|
|
{
|
2020-10-18 11:31:07 +00:00
|
|
|
relPath = NormalizePath( filePath, &Pgm().GetLocalEnvVariables(),
|
2020-09-01 02:00:38 +00:00
|
|
|
m_normalizeBasePath );
|
2020-10-18 11:31:07 +00:00
|
|
|
lastPath = NormalizePath( dlg.GetDirectory(), &Pgm().GetLocalEnvVariables(),
|
2020-09-01 02:00:38 +00:00
|
|
|
m_normalizeBasePath );
|
|
|
|
}
|
2021-10-11 16:11:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
relPath = filePath;
|
|
|
|
}
|
2020-09-01 02:00:38 +00:00
|
|
|
|
|
|
|
SetValue( relPath );
|
2021-02-18 10:34:55 +00:00
|
|
|
|
|
|
|
if( !m_grid->CommitPendingChanges() )
|
2021-02-18 18:36:16 +00:00
|
|
|
{;} // shouldn't happen, but Coverity doesn't know that
|
2021-02-18 10:34:55 +00:00
|
|
|
|
2021-05-27 18:19:06 +00:00
|
|
|
if( m_currentDir )
|
|
|
|
*m_currentDir = lastPath;
|
2019-03-03 04:04:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-27 18:19:06 +00:00
|
|
|
wxDirDialog dlg( m_dlg, _( "Select Path" ), fn.GetPath(),
|
2019-05-10 12:21:08 +00:00
|
|
|
wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
|
2018-08-24 18:28:11 +00:00
|
|
|
|
2019-03-03 04:04:17 +00:00
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
2020-09-01 02:00:38 +00:00
|
|
|
wxString filePath = dlg.GetPath();
|
|
|
|
wxString relPath = wxEmptyString;
|
|
|
|
|
|
|
|
if ( m_normalize )
|
|
|
|
{
|
2020-10-18 11:31:07 +00:00
|
|
|
relPath = NormalizePath( filePath, &Pgm().GetLocalEnvVariables(),
|
2020-09-01 02:00:38 +00:00
|
|
|
m_normalizeBasePath );
|
|
|
|
}
|
2021-10-11 16:11:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
relPath = filePath;
|
|
|
|
}
|
2020-09-01 02:00:38 +00:00
|
|
|
|
|
|
|
SetValue( relPath );
|
2021-02-18 10:34:55 +00:00
|
|
|
|
|
|
|
if( !m_grid->CommitPendingChanges() )
|
2021-02-18 18:36:16 +00:00
|
|
|
{;} // shouldn't happen, but Coverity doesn't know that
|
2021-02-18 10:34:55 +00:00
|
|
|
|
2020-09-01 02:00:38 +00:00
|
|
|
*m_currentDir = relPath;
|
2019-03-03 04:04:17 +00:00
|
|
|
}
|
2018-08-24 18:28:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DIALOG_SHIM* m_dlg;
|
2021-02-17 14:06:19 +00:00
|
|
|
WX_GRID* m_grid;
|
2018-08-24 18:28:11 +00:00
|
|
|
wxString* m_currentDir;
|
2020-09-01 02:00:38 +00:00
|
|
|
bool m_normalize;
|
|
|
|
wxString m_normalizeBasePath;
|
2024-01-22 18:26:39 +00:00
|
|
|
|
|
|
|
wxString m_fileFilter;
|
|
|
|
std::function<wxString( WX_GRID* aGrid, int aRow )> m_fileFilterFn;
|
2018-08-24 18:28:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void GRID_CELL_PATH_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
|
|
|
|
wxEvtHandler* aEventHandler )
|
|
|
|
{
|
2023-10-27 22:24:24 +00:00
|
|
|
if( m_fileFilterFn )
|
2024-01-22 18:26:39 +00:00
|
|
|
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, m_fileFilterFn,
|
2020-09-01 02:00:38 +00:00
|
|
|
m_normalize, m_normalizeBasePath );
|
2020-03-06 20:02:58 +00:00
|
|
|
else
|
2024-01-22 18:26:39 +00:00
|
|
|
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, m_fileFilter,
|
2020-09-01 02:00:38 +00:00
|
|
|
m_normalize, m_normalizeBasePath );
|
2019-03-03 04:04:17 +00:00
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
#if wxUSE_VALIDATORS
|
|
|
|
// validate text in textctrl, if validator is set
|
|
|
|
if ( m_validator )
|
|
|
|
{
|
|
|
|
Combo()->SetValidator( *m_validator );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wxGridCellEditor::Create( aParent, aId, aEventHandler );
|
2021-02-18 18:36:16 +00:00
|
|
|
}
|