Write changes back to grid after using file explorer.

Fixes https://gitlab.com/kicad/code/kicad/issues/7361
This commit is contained in:
Jeff Young 2021-02-17 14:06:19 +00:00
parent d66de5bb35
commit b6a7981e62
13 changed files with 60 additions and 39 deletions

View File

@ -449,7 +449,7 @@ void PANEL_PREV_3D::UpdateDummyFootprint( bool aReloadRequired )
{
m_dummyFootprint->Models().clear();
for( FP_3DMODEL& model : *m_parentModelList)
for( FP_3DMODEL& model : *m_parentModelList )
{
if( model.m_Show )
m_dummyFootprint->Models().push_back( model );

View File

@ -75,11 +75,11 @@ DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESO
m_EnvVars->UseNativeColHeader( true );
wxGridCellAttr* attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, &m_curdir, wxEmptyString ) );
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_EnvVars, &m_curdir, wxEmptyString ) );
m_EnvVars->SetColAttr( TV_VALUE_COL, attr );
attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, &m_curdir, wxEmptyString ) );
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_SearchPaths, &m_curdir, wxEmptyString ) );
m_SearchPaths->SetColAttr( TV_VALUE_COL, attr );
// Give a bit more room for combobox editors

View File

@ -1,7 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021 CERN
* Copyright (C) 2018-2021 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
@ -32,7 +33,7 @@
#include <dialog_shim.h>
#include <common.h>
#include <env_paths.h>
#include <widgets/wx_grid.h>
#include <widgets/grid_text_button_helpers.h>
#include <eda_doc.h>
@ -318,11 +319,13 @@ void GRID_CELL_URL_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
class TEXT_BUTTON_FILE_BROWSER : public wxComboCtrl
{
public:
TEXT_BUTTON_FILE_BROWSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg,
TEXT_BUTTON_FILE_BROWSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg, WX_GRID* aGrid,
wxString* aCurrentDir, wxString* aExt = nullptr,
bool aNormalize = false, wxString aNormalizeBasePath = wxEmptyString ) :
bool aNormalize = false,
wxString aNormalizeBasePath = wxEmptyString ) :
wxComboCtrl( aParent ),
m_dlg( aParentDlg ),
m_grid( aGrid ),
m_currentDir( aCurrentDir ),
m_ext( aExt ),
m_normalize( aNormalize ),
@ -370,6 +373,7 @@ protected:
relPath = filePath;
SetValue( relPath );
m_grid->CommitPendingChanges();
*m_currentDir = lastPath;
}
}
@ -393,12 +397,14 @@ protected:
relPath = filePath;
SetValue( relPath );
m_grid->CommitPendingChanges();
*m_currentDir = relPath;
}
}
}
DIALOG_SHIM* m_dlg;
WX_GRID* m_grid;
wxString* m_currentDir;
wxString* m_ext;
bool m_normalize;
@ -410,10 +416,10 @@ void GRID_CELL_PATH_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
wxEvtHandler* aEventHandler )
{
if( m_ext.IsEmpty() )
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_currentDir, nullptr,
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, nullptr,
m_normalize, m_normalizeBasePath );
else
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_currentDir, &m_ext,
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, &m_ext,
m_normalize, m_normalizeBasePath );
#if wxUSE_VALIDATORS

View File

@ -62,7 +62,7 @@ DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES( SYMBOL_EDIT_FRAME* a
{
// Give a bit more room for combobox editors
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
m_fields = new FIELDS_GRID_TABLE<LIB_FIELD>( this, aParent, m_libEntry );
m_fields = new FIELDS_GRID_TABLE<LIB_FIELD>( this, aParent, m_grid, m_libEntry );
m_grid->SetTable( m_fields );
m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this ) );

View File

@ -49,7 +49,7 @@ DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_S
m_dummySheetNameField( wxDefaultPosition, SHEETNAME, &m_dummySheet )
{
m_sheet = aSheet;
m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_sheet );
m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_grid, m_sheet );
m_width = 100; // Will be later set to a better value
m_delayedFocusRow = SHEETNAME;
m_delayedFocusColumn = FDC_VALUE;

View File

@ -286,7 +286,7 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent,
// so we need to handle m_part == nullptr
wxASSERT( m_part );
m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_part );
m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_fieldsGrid, m_part );
m_width = 0;
m_delayedFocusRow = REFERENCE_FIELD;

View File

@ -222,9 +222,9 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P
wxString wildcards = AllSymbolLibFilesWildcard()
+ "|" + KiCadSymbolLibFileWildcard()
+ "|" + LegacySymbolLibFileWildcard();
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, &cfg->m_lastSymbolLibDir,
wildcards, true,
m_project->GetProjectPath() ) );
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
&cfg->m_lastSymbolLibDir, wildcards,
true, m_project->GetProjectPath() ) );
aGrid->SetColAttr( COL_URI, attr );
attr = new wxGridCellAttr;

View File

@ -46,9 +46,10 @@ enum
template <class T>
FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame,
LIB_PART* aPart ) :
WX_GRID* aGrid, LIB_PART* aPart ) :
m_frame( aFrame ),
m_userUnits( aDialog->GetUserUnits() ),
m_grid( aGrid ),
m_parentType( SCH_COMPONENT_T ),
m_mandatoryFieldCount( MANDATORY_FIELDS ),
m_part( aPart ),
@ -60,15 +61,16 @@ FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a
m_nonUrlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ),
m_filepathValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETFILENAME )
{
initGrid( aDialog );
initGrid( aDialog, aGrid );
}
template <class T>
FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame,
SCH_SHEET* aSheet ) :
WX_GRID* aGrid, SCH_SHEET* aSheet ) :
m_frame( aFrame ),
m_userUnits( aDialog->GetUserUnits() ),
m_grid( aGrid ),
m_parentType( SCH_SHEET_T ),
m_mandatoryFieldCount( SHEET_MANDATORY_FIELDS ),
m_part( nullptr ),
@ -80,12 +82,12 @@ FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a
m_nonUrlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ),
m_filepathValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETFILENAME_V )
{
initGrid( aDialog );
initGrid( aDialog, aGrid );
}
template <class T>
void FIELDS_GRID_TABLE<T>::initGrid( DIALOG_SHIM* aDialog )
void FIELDS_GRID_TABLE<T>::initGrid( DIALOG_SHIM* aDialog, WX_GRID* aGrid )
{
// Build the various grid cell attributes.
// NOTE: validators and cellAttrs are member variables to get the destruction order
@ -133,7 +135,7 @@ void FIELDS_GRID_TABLE<T>::initGrid( DIALOG_SHIM* aDialog )
exts.push_back( KiCadSchematicFileExtension );
wildCard += AddFileExtListToFilter( exts );
auto filepathEditor = new GRID_CELL_PATH_EDITOR( aDialog, &m_curdir, wildCard );
auto filepathEditor = new GRID_CELL_PATH_EDITOR( aDialog, aGrid, &m_curdir, wildCard );
filepathEditor->SetValidator( m_filepathValidator );
m_filepathAttr->SetEditor( filepathEditor );

View File

@ -72,8 +72,10 @@ template <class T>
class FIELDS_GRID_TABLE : public wxGridTableBase, public std::vector<T>
{
public:
FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, LIB_PART* aPart );
FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, SCH_SHEET* aSheet );
FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid,
LIB_PART* aPart );
FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid,
SCH_SHEET* aSheet );
~FIELDS_GRID_TABLE();
int GetNumberRows() override { return (int) this->size(); }
@ -100,11 +102,12 @@ public:
bool BoolFromString( wxString aValue ) const;
protected:
void initGrid( DIALOG_SHIM* aDialog );
void initGrid( DIALOG_SHIM* aDialog, WX_GRID* aGrid );
private:
SCH_BASE_FRAME* m_frame;
EDA_UNITS m_userUnits;
WX_GRID* m_grid;
KICAD_T m_parentType;
int m_mandatoryFieldCount;
LIB_PART* m_part;

View File

@ -1,7 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021 CERN
* Copyright (C) 2018-2021 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
@ -30,6 +31,7 @@
class wxGrid;
class WX_GRID;
class DIALOG_SHIM;
@ -138,13 +140,18 @@ public:
* Constructor
*
* @param aCurrentDir is current directory the path editor will open at
* @param aExt is the file extension(s) to filter by. If empty, the path editor will switch to folder mode instead of file.
* @param aNormalize indicates whether to normalize the selected path (replace part of path with variables or relative path)
* @param aNormalizeBasePath is the path to use when trying to base variables (generally current project path)
* @param aExt is the file extension(s) to filter by. If empty, the path editor will switch
* to folder mode instead of file.
* @param aNormalize indicates whether to normalize the selected path (replace part of path
* with variables or relative path)
* @param aNormalizeBasePath is the path to use when trying to base variables (generally
* current project path)
*/
GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParent, wxString* aCurrentDir, const wxString& aExt,
bool aNormalize = false, wxString aNormalizeBasePath = wxEmptyString ) :
m_dlg( aParent ),
GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
const wxString& aExt, bool aNormalize = false,
wxString aNormalizeBasePath = wxEmptyString ) :
m_dlg( aParentDialog ),
m_grid( aGrid ),
m_currentDir( aCurrentDir ),
m_ext( aExt ),
m_normalize( aNormalize ),
@ -153,13 +160,14 @@ public:
wxGridCellEditor* Clone() const override
{
return new GRID_CELL_PATH_EDITOR( m_dlg, m_currentDir, m_ext );
return new GRID_CELL_PATH_EDITOR( m_dlg, m_grid, m_currentDir, m_ext );
}
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
protected:
DIALOG_SHIM* m_dlg;
WX_GRID* m_grid;
wxString* m_currentDir;
wxString m_ext;
bool m_normalize;

View File

@ -27,7 +27,6 @@
#include <confirm.h>
#include <dialogs/dialog_text_entry.h>
#include <3d_viewer/eda_3d_viewer.h>
#include <pcb_edit_frame.h>
#include <validators.h>
#include <board_design_settings.h>
#include <board_commit.h>
@ -96,8 +95,8 @@ DIALOG_FOOTPRINT_FP_EDITOR::DIALOG_FOOTPRINT_FP_EDITOR( FOOTPRINT_EDIT_FRAME* aP
}
wxGridCellAttr* attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, &cfg->m_lastFootprint3dDir, "*.*",
true, Prj().GetProjectPath() ) );
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_modelsGrid, &cfg->m_lastFootprint3dDir,
"*.*", true, Prj().GetProjectPath() ) );
m_modelsGrid->SetColAttr( 0, attr );
// Show checkbox
@ -315,6 +314,7 @@ bool DIALOG_FOOTPRINT_FP_EDITOR::TransferDataToWindow()
}
select3DModel( 0 ); // will clamp idx within bounds
m_PreviewPane->UpdateDummyFootprint();
for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
{

View File

@ -105,8 +105,8 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen
}
wxGridCellAttr* attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, &cfg->m_lastFootprint3dDir, "*.*",
true, Prj().GetProjectPath() ) );
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_modelsGrid, &cfg->m_lastFootprint3dDir,
"*.*", true, Prj().GetProjectPath() ) );
m_modelsGrid->SetColAttr( 0, attr );
// Show checkbox

View File

@ -407,8 +407,10 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent,
wxGridCellAttr* attr;
attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, &cfg->m_lastFootprintLibDir,
wxEmptyString, true, m_projectBasePath ) );
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
&cfg->m_lastFootprintLibDir,
wxEmptyString, true,
m_projectBasePath ) );
aGrid->SetColAttr( COL_URI, attr );
attr = new wxGridCellAttr;