Implemented 3D search path configuration GUI

This commit is contained in:
Cirilo Bernardo 2016-01-18 19:53:35 +11:00
parent 7848b2a52e
commit 54940002f9
5 changed files with 228 additions and 164 deletions

View File

@ -150,20 +150,10 @@ bool S3D_FILENAME_RESOLVER::createPathList( void )
lpath.m_description = _( "Current project directory" ); lpath.m_description = _( "Current project directory" );
m_Paths.push_back( lpath ); m_Paths.push_back( lpath );
if( wxGetEnv( wxT( "KISYS3DMOD" ), &kmod ) && !kmod.empty() )
{
wxFileName tmp( kmod );
wxString kpath = tmp.GetFullPath();
if( tmp.Normalize() && lpath.m_pathexp.Cmp( kpath ) )
{
lpath.m_alias = wxT( "KISYS3DMOD" ); lpath.m_alias = wxT( "KISYS3DMOD" );
lpath.m_pathvar = wxT( "${KISYS3DMOD}" ); lpath.m_pathvar = wxT( "${KISYS3DMOD}" );
lpath.m_pathexp = kpath;
lpath.m_description = _( "Legacy 3D environment path" ); lpath.m_description = _( "Legacy 3D environment path" );
addPath( lpath ); addPath( lpath );
}
}
if( !m_ConfigDir.empty() ) if( !m_ConfigDir.empty() )
readPathList(); readPathList();
@ -499,6 +489,10 @@ bool S3D_FILENAME_RESOLVER::readPathList( void )
if( !getHollerith( cfgLine, idx, al.m_alias ) ) if( !getHollerith( cfgLine, idx, al.m_alias ) )
continue; continue;
// never add on KISYS3DMOD from a config file
if( !al.m_alias.Cmp( wxT( "KISYS3DMOD" ) ) )
continue;
if( !getHollerith( cfgLine, idx, al.m_pathvar ) ) if( !getHollerith( cfgLine, idx, al.m_pathvar ) )
continue; continue;
@ -524,16 +518,40 @@ bool S3D_FILENAME_RESOLVER::writePathList( void )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
wxString errmsg = _( "3D configuration directory is unknown" ); wxString errmsg = _( "3D configuration directory is unknown" );
std::cerr << " * " << errmsg.ToUTF8() << "\n"; std::cerr << " * " << errmsg.ToUTF8() << "\n";
wxMessageBox( errmsg, _T( "Write 3D search path list" ) );
return false; return false;
} }
if( m_Paths.empty() || 1 == m_Paths.size() )
return false;
wxFileName cfgpath( m_ConfigDir, S3D_RESOLVER_CONFIG ); wxFileName cfgpath( m_ConfigDir, S3D_RESOLVER_CONFIG );
wxString cfgname = cfgpath.GetFullPath(); wxString cfgname = cfgpath.GetFullPath();
std::ofstream cfgFile; std::ofstream cfgFile;
if( m_Paths.empty() || 1 == m_Paths.size() )
{
wxMessageDialog md( NULL,
_T( "3D search path list is empty;\ncontinue to write empty file?" ),
_T( "Write 3D search path list" ), wxYES_NO );
if( md.ShowModal() == wxID_YES )
{
cfgFile.open( cfgname.ToUTF8(), std::ios_base::trunc );
if( !cfgFile.is_open() )
{
wxMessageBox( _T( "Could not open configuration file" ),
_T( "Write 3D search path list" ) );
return false;
}
cfgFile.close();
return true;
}
return false;
}
cfgFile.open( cfgname.ToUTF8(), std::ios_base::trunc ); cfgFile.open( cfgname.ToUTF8(), std::ios_base::trunc );
if( !cfgFile.is_open() ) if( !cfgFile.is_open() )
@ -541,6 +559,9 @@ bool S3D_FILENAME_RESOLVER::writePathList( void )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
wxString errmsg = _( "could not open configuration file " ); wxString errmsg = _( "could not open configuration file " );
std::cerr << " * " << errmsg.ToUTF8() << " '" << cfgname.ToUTF8() << "'\n"; std::cerr << " * " << errmsg.ToUTF8() << " '" << cfgname.ToUTF8() << "'\n";
wxMessageBox( _T( "Could not open configuration file" ),
_T( "Write 3D search path list" ) );
return false; return false;
} }
@ -554,6 +575,13 @@ bool S3D_FILENAME_RESOLVER::writePathList( void )
while( sPL != ePL ) while( sPL != ePL )
{ {
// never write the KISYS3DMOD entry
if( !sPL->m_alias.Cmp( wxT( "KISYS3DMOD") ) )
{
++sPL;
continue;
}
tstr = sPL->m_alias.ToUTF8(); tstr = sPL->m_alias.ToUTF8();
cfgFile << "\"" << tstr.size() << ":" << tstr << "\","; cfgFile << "\"" << tstr.size() << ":" << tstr << "\",";
tstr = sPL->m_pathvar.ToUTF8(); tstr = sPL->m_pathvar.ToUTF8();
@ -567,7 +595,12 @@ bool S3D_FILENAME_RESOLVER::writePathList( void )
cfgFile.close(); cfgFile.close();
if( bad ) if( bad )
{
wxMessageBox( _T( "Problems writing configuration file" ),
_T( "Write 3D search path list" ) );
return false; return false;
}
return true; return true;
} }

View File

@ -29,6 +29,10 @@ DLG_3D_PATH_CONFIG::DLG_3D_PATH_CONFIG( wxWindow* aParent, S3D_FILENAME_RESOLVER
DLG_3D_PATH_CONFIG_BASE( aParent ), m_resolver( aResolver ) DLG_3D_PATH_CONFIG_BASE( aParent ), m_resolver( aResolver )
{ {
m_Aliases->EnableEditing( true ); m_Aliases->EnableEditing( true );
m_Aliases->SetColMinimalWidth( 0, 80 );
m_Aliases->SetColMinimalWidth( 1, 300 );
m_Aliases->SetColMinimalWidth( 2, 120 );
m_Aliases->SetColMinimalAcceptableWidth( 80 );
if( m_resolver ) if( m_resolver )
{ {
@ -42,10 +46,10 @@ DLG_3D_PATH_CONFIG::DLG_3D_PATH_CONFIG( wxWindow* aParent, S3D_FILENAME_RESOLVER
if( listsize > 0 ) if( listsize > 0 )
m_curdir = rpaths->front().m_pathexp; m_curdir = rpaths->front().m_pathexp;
if( listsize < 2 ) if( listsize < 3 )
return; return;
listsize = listsize - 1 - m_Aliases->GetNumberRows(); listsize = listsize - 2 - m_Aliases->GetNumberRows();
// note: if the list allocation fails we have bigger problems // note: if the list allocation fails we have bigger problems
// and there is no point in trying to notify the user here // and there is no point in trying to notify the user here
@ -56,7 +60,9 @@ DLG_3D_PATH_CONFIG::DLG_3D_PATH_CONFIG( wxWindow* aParent, S3D_FILENAME_RESOLVER
std::list< S3D_ALIAS >::const_iterator eL = rpaths->end(); std::list< S3D_ALIAS >::const_iterator eL = rpaths->end();
int nitems = 0; int nitems = 0;
// skip the first entry which is always the current project dir // skip the first 2 entries which are always the current project dir
// and KISYS3DMOD
++sL;
++sL; ++sL;
wxGridCellTextEditor* pEdAlias; wxGridCellTextEditor* pEdAlias;
@ -74,10 +80,9 @@ DLG_3D_PATH_CONFIG::DLG_3D_PATH_CONFIG( wxWindow* aParent, S3D_FILENAME_RESOLVER
++sL; ++sL;
} }
m_Aliases->AutoSizeColumns(); m_Aliases->AutoSize();
} }
Layout();
Fit(); Fit();
SetMinSize( GetSize() ); SetMinSize( GetSize() );
@ -88,7 +93,12 @@ DLG_3D_PATH_CONFIG::DLG_3D_PATH_CONFIG( wxWindow* aParent, S3D_FILENAME_RESOLVER
bool DLG_3D_PATH_CONFIG::TransferDataFromWindow() bool DLG_3D_PATH_CONFIG::TransferDataFromWindow()
{ {
if( NULL == m_resolver ) if( NULL == m_resolver )
{
wxMessageBox( _T( "[BUG] No valid resolver; data will not be updated" ),
_T( "Update 3D search path list" ) );
return false; return false;
}
std::vector<S3D_ALIAS> alist; std::vector<S3D_ALIAS> alist;
S3D_ALIAS alias; S3D_ALIAS alias;
@ -129,6 +139,8 @@ void DLG_3D_PATH_CONFIG::OnAddAlias( wxCommandEvent& event )
pEdAlias->SetValidator( m_aliasValidator ); pEdAlias->SetValidator( m_aliasValidator );
pEdAlias->DecRef(); pEdAlias->DecRef();
m_Aliases->SelectRow( ni, false ); m_Aliases->SelectRow( ni, false );
m_Aliases->AutoSize();
Fit();
// TODO: set the editors on any newly created rows // TODO: set the editors on any newly created rows
} }
@ -164,6 +176,8 @@ void DLG_3D_PATH_CONFIG::OnDelAlias( wxCommandEvent& event )
ni = m_Aliases->GetNumberRows() - 1; ni = m_Aliases->GetNumberRows() - 1;
m_Aliases->SelectRow( ni, false ); m_Aliases->SelectRow( ni, false );
m_Aliases->AutoSize();
Fit();
} }
else else
{ {

View File

@ -16,6 +16,9 @@ DLG_3D_PATH_CONFIG_BASE::DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID i
wxBoxSizer* bSizer1; wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer( wxVERTICAL ); bSizer1 = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bSizer3;
bSizer3 = new wxBoxSizer( wxHORIZONTAL );
m_Aliases = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); m_Aliases = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
// Grid // Grid
@ -26,7 +29,6 @@ DLG_3D_PATH_CONFIG_BASE::DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID i
m_Aliases->SetMargins( 0, 0 ); m_Aliases->SetMargins( 0, 0 );
// Columns // Columns
m_Aliases->AutoSizeColumns();
m_Aliases->EnableDragColMove( false ); m_Aliases->EnableDragColMove( false );
m_Aliases->EnableDragColSize( true ); m_Aliases->EnableDragColSize( true );
m_Aliases->SetColLabelSize( 30 ); m_Aliases->SetColLabelSize( 30 );
@ -36,7 +38,8 @@ DLG_3D_PATH_CONFIG_BASE::DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID i
m_Aliases->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); m_Aliases->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
// Rows // Rows
m_Aliases->EnableDragRowSize( true ); m_Aliases->AutoSizeRows();
m_Aliases->EnableDragRowSize( false );
m_Aliases->SetRowLabelSize( 80 ); m_Aliases->SetRowLabelSize( 80 );
m_Aliases->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); m_Aliases->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
@ -44,7 +47,10 @@ DLG_3D_PATH_CONFIG_BASE::DLG_3D_PATH_CONFIG_BASE( wxWindow* parent, wxWindowID i
// Cell Defaults // Cell Defaults
m_Aliases->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); m_Aliases->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
bSizer1->Add( m_Aliases, 0, wxALL, 5 ); bSizer3->Add( m_Aliases, 1, wxALL|wxEXPAND, 5 );
bSizer1->Add( bSizer3, 1, wxEXPAND, 5 );
wxBoxSizer* bSizer2; wxBoxSizer* bSizer2;
bSizer2 = new wxBoxSizer( wxHORIZONTAL ); bSizer2 = new wxBoxSizer( wxHORIZONTAL );

View File

@ -95,8 +95,17 @@
<property name="permission">none</property> <property name="permission">none</property>
<object class="sizeritem" expanded="1"> <object class="sizeritem" expanded="1">
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxALL</property> <property name="flag">wxEXPAND</property>
<property name="proportion">0</property> <property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer3</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxGrid" expanded="1"> <object class="wxGrid" expanded="1">
<property name="BottomDockable">1</property> <property name="BottomDockable">1</property>
<property name="LeftDockable">1</property> <property name="LeftDockable">1</property>
@ -106,8 +115,8 @@
<property name="aui_name"></property> <property name="aui_name"></property>
<property name="aui_position"></property> <property name="aui_position"></property>
<property name="aui_row"></property> <property name="aui_row"></property>
<property name="autosize_cols">1</property> <property name="autosize_cols">0</property>
<property name="autosize_rows">0</property> <property name="autosize_rows">1</property>
<property name="best_size"></property> <property name="best_size"></property>
<property name="bg"></property> <property name="bg"></property>
<property name="caption"></property> <property name="caption"></property>
@ -134,7 +143,7 @@
<property name="drag_col_move">0</property> <property name="drag_col_move">0</property>
<property name="drag_col_size">1</property> <property name="drag_col_size">1</property>
<property name="drag_grid_size">0</property> <property name="drag_grid_size">0</property>
<property name="drag_row_size">1</property> <property name="drag_row_size">0</property>
<property name="editing">1</property> <property name="editing">1</property>
<property name="enabled">1</property> <property name="enabled">1</property>
<property name="fg"></property> <property name="fg"></property>
@ -236,6 +245,8 @@
<event name="OnUpdateUI"></event> <event name="OnUpdateUI"></event>
</object> </object>
</object> </object>
</object>
</object>
<object class="sizeritem" expanded="1"> <object class="sizeritem" expanded="1">
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxEXPAND</property> <property name="flag">wxEXPAND</property>

View File

@ -20,8 +20,8 @@ class DIALOG_SHIM;
#include <wx/font.h> #include <wx/font.h>
#include <wx/grid.h> #include <wx/grid.h>
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
#include <wx/button.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/button.h>
#include <wx/frame.h> #include <wx/frame.h>
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////