Add a cell editor for paths and use it in Configure Paths.

This commit is contained in:
Jeff Young 2018-08-24 19:28:11 +01:00
parent 030663d847
commit 895fc0b536
5 changed files with 114 additions and 9 deletions

View File

@ -30,7 +30,7 @@
#include <html_messagebox.h>
#include <filename_resolver.h>
#include <widgets/wx_grid.h>
#include <widgets/grid_text_button_helpers.h>
enum ENV_VAR_GRID_COLUMNS
{
@ -65,6 +65,24 @@ DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESO
m_EnvVars->HideCol( EV_FLAG_COL );
m_EnvVars->UseNativeColHeader( true );
wxGridCellAttr* attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, &m_curdir ) );
m_EnvVars->SetColAttr( EV_PATH_COL, attr );
attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, &m_curdir ) );
m_SearchPaths->SetColAttr( EV_PATH_COL, attr );
// Give a bit more room for combobox editors
m_EnvVars->SetDefaultRowSize( m_EnvVars->GetDefaultRowSize() + 4 );
m_SearchPaths->SetDefaultRowSize( m_SearchPaths->GetDefaultRowSize() + 4 );
m_EnvVars->PushEventHandler( new GRID_TRICKS( m_EnvVars ) );
m_SearchPaths->PushEventHandler( new GRID_TRICKS( m_SearchPaths ) );
m_EnvVars->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
m_SearchPaths->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
if( m_resolver )
{
m_SearchPaths->DeleteRows( 0, m_SearchPaths->GetNumberRows() );
@ -91,6 +109,10 @@ DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESO
DIALOG_CONFIGURE_PATHS::~DIALOG_CONFIGURE_PATHS()
{
// Delete the GRID_TRICKS.
m_SearchPaths->PopEventHandler( true );
m_EnvVars->PopEventHandler( true );
m_EnvVars->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), NULL, this );
m_SearchPaths->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), NULL, this );
}
@ -350,9 +372,6 @@ void DIALOG_CONFIGURE_PATHS::OnAddSearchPath( wxCommandEvent& event )
void DIALOG_CONFIGURE_PATHS::OnRemoveEnvVar( wxCommandEvent& event )
{
if( !m_EnvVars->CommitPendingChanges() )
return;
int curRow = m_EnvVars->GetGridCursorRow();
if( !m_EnvVars->HasFocus() || curRow < 0 )
@ -367,6 +386,7 @@ void DIALOG_CONFIGURE_PATHS::OnRemoveEnvVar( wxCommandEvent& event )
return;
}
m_EnvVars->CommitPendingChanges( true /* silent mode; we don't care if it's valid */ );
m_EnvVars->DeleteRows( curRow, 1 );
m_EnvVars->MakeCellVisible( std::max( 0, curRow-1 ), m_EnvVars->GetGridCursorCol() );
@ -376,9 +396,6 @@ void DIALOG_CONFIGURE_PATHS::OnRemoveEnvVar( wxCommandEvent& event )
void DIALOG_CONFIGURE_PATHS::OnDeleteSearchPath( wxCommandEvent& event )
{
if( !m_SearchPaths->CommitPendingChanges() )
return;
int curRow = m_SearchPaths->GetGridCursorRow();
if( !m_SearchPaths->HasFocus() || curRow < 0 )
@ -387,6 +404,7 @@ void DIALOG_CONFIGURE_PATHS::OnDeleteSearchPath( wxCommandEvent& event )
return;
}
m_SearchPaths->CommitPendingChanges( true /* silent mode; we don't care if it's valid */ );
m_SearchPaths->DeleteRows( curRow, 1 );
m_SearchPaths->MakeCellVisible( std::max( 0, curRow-1 ), m_SearchPaths->GetGridCursorCol() );
@ -413,6 +431,8 @@ void DIALOG_CONFIGURE_PATHS::OnSearchPathMoveUp( wxCommandEvent& event )
m_SearchPaths->SetGridCursor( prevRow, m_SearchPaths->GetGridCursorCol() );
}
else
wxBell();
}
@ -435,6 +455,8 @@ void DIALOG_CONFIGURE_PATHS::OnSearchPathMoveDown( wxCommandEvent& event )
m_SearchPaths->SetGridCursor( nextRow, m_SearchPaths->GetGridCursorCol() );
}
else
wxBell();
}

View File

@ -49,7 +49,7 @@ DIALOG_CONFIGURE_PATHS_BASE::DIALOG_CONFIGURE_PATHS_BASE( wxWindow* parent, wxWi
// Cell Defaults
m_EnvVars->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
m_EnvVars->SetMinSize( wxSize( 604,150 ) );
m_EnvVars->SetMinSize( wxSize( 604,170 ) );
sbEnvVars->Add( m_EnvVars, 1, wxEXPAND|wxBOTTOM, 5 );

View File

@ -168,7 +168,7 @@
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">604,150</property>
<property name="minimum_size">604,170</property>
<property name="moveable">1</property>
<property name="name">m_EnvVars</property>
<property name="pane_border">1</property>

View File

@ -149,6 +149,10 @@ void GRID_CELL_TEXT_BUTTON::Reset()
}
/**
* Footprint Picker
*/
class TEXT_BUTTON_FP_CHOOSER : public wxComboCtrl
{
public:
@ -190,6 +194,10 @@ void GRID_CELL_FOOTPRINT_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
}
/**
* URL Viewer
*/
class TEXT_BUTTON_URL : public wxComboCtrl
{
public:
@ -230,3 +238,57 @@ void GRID_CELL_URL_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
}
/**
* Path Picker
*/
class TEXT_BUTTON_FILE_BROWSER : public wxComboCtrl
{
public:
TEXT_BUTTON_FILE_BROWSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg, wxString* aCurrentDir ) :
wxComboCtrl( aParent ),
m_dlg( aParentDlg ),
m_currentDir( aCurrentDir )
{
SetButtonBitmaps( KiBitmap( folder_xpm ) );
}
protected:
void DoSetPopupControl( wxComboPopup* popup ) override
{
m_popup = nullptr;
}
void OnButtonClick() override
{
wxString path = GetValue();
if( path.IsEmpty() )
path = *m_currentDir;
else
path = ExpandEnvVarSubstitutions( path );
wxDirDialog dlg( nullptr, _( "Select Path" ), path,
wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
if( dlg.ShowModal() == wxID_OK )
{
SetValue( dlg.GetPath() );
*m_currentDir = dlg.GetPath();
}
}
DIALOG_SHIM* m_dlg;
wxString* m_currentDir;
};
void GRID_CELL_PATH_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
wxEvtHandler* aEventHandler )
{
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_currentDir );
wxGridCellEditor::Create(aParent, aId, aEventHandler);
}

View File

@ -95,4 +95,25 @@ protected:
};
class GRID_CELL_PATH_EDITOR : public GRID_CELL_TEXT_BUTTON
{
public:
GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParent, wxString* aCurrentDir ) :
m_dlg( aParent ),
m_currentDir( aCurrentDir )
{ }
wxGridCellEditor* Clone() const override
{
return new GRID_CELL_PATH_EDITOR( m_dlg, m_currentDir );
}
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
protected:
DIALOG_SHIM* m_dlg;
wxString* m_currentDir;
};
#endif // GRID_TEXT_BUTTON_HELPERS_H