Commit e8ad48ad authored by Dick Hollenbeck's avatar Dick Hollenbeck

more DIALOG_FP_PLUGIN_OPTIONS work, make PROPERTIES a map instead of a...

more DIALOG_FP_PLUGIN_OPTIONS work, make PROPERTIES a map instead of a hashtable for alphabetical iteration.
parent 75f2e544
...@@ -36,12 +36,6 @@ ...@@ -36,12 +36,6 @@
#include <unordered_map> #include <unordered_map>
/// Map a C string to a wxString, used in PLUGINs.
/// was typedef std::unordered_map< std::string, std::string > PROPERTIES;
class PROPERTIES : public std::unordered_map< std::string, std::string >
{
};
/// Map a C string to an integer. Used in DSNLEXER. /// Map a C string to an integer. Used in DSNLEXER.
typedef std::unordered_map< std::string, int > KEYWORD_MAP; typedef std::unordered_map< std::string, int > KEYWORD_MAP;
...@@ -60,13 +54,6 @@ typedef std::unordered_map< std::string, EDA_RECT > RECT_MAP; ...@@ -60,13 +54,6 @@ typedef std::unordered_map< std::string, EDA_RECT > RECT_MAP;
// see http://www.boost.org/doc/libs/1_49_0/doc/html/boost/unordered_map.html // see http://www.boost.org/doc/libs/1_49_0/doc/html/boost/unordered_map.html
/// Map a std::string to a wxString, used in PLUGINs.
/// was typedef boost::unordered_map< std::string, std::string > PROPERTIES;
class PROPERTIES : public boost::unordered_map< std::string, std::string >
{
};
/// Equality test for "const char*" type used in very specialized KEYWORD_MAP below /// Equality test for "const char*" type used in very specialized KEYWORD_MAP below
struct iequal_to : std::binary_function< const char*, const char*, bool > struct iequal_to : std::binary_function< const char*, const char*, bool >
{ {
......
...@@ -512,7 +512,10 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE ...@@ -512,7 +512,10 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE
InvokePluginOptionsEditor( this, row.GetNickName(), options, &result ); InvokePluginOptionsEditor( this, row.GetNickName(), options, &result );
if( options != result ) if( options != result )
{
row.SetOptions( result ); row.SetOptions( result );
m_cur_grid->AutoSizeColumn( COL_OPTIONS, false );
}
} }
void onCancelButtonClick( wxCommandEvent& event ) void onCancelButtonClick( wxCommandEvent& event )
......
...@@ -29,6 +29,12 @@ ...@@ -29,6 +29,12 @@
#include <fp_lib_table.h> #include <fp_lib_table.h>
#include <grid_tricks.h> #include <grid_tricks.h>
using std::string;
// re-enter the dialog with the column sizes preserved from last time.
static int col_width_option;
static int col_width_value;
class DIALOG_FP_PLUGIN_OPTIONS : public DIALOG_FP_PLUGIN_OPTIONS_BASE class DIALOG_FP_PLUGIN_OPTIONS : public DIALOG_FP_PLUGIN_OPTIONS_BASE
{ {
...@@ -38,7 +44,6 @@ public: ...@@ -38,7 +44,6 @@ public:
const wxString& aNickname, const wxString& aOptions, wxString* aResult ) : const wxString& aNickname, const wxString& aOptions, wxString* aResult ) :
DIALOG_FP_PLUGIN_OPTIONS_BASE( aParent ), DIALOG_FP_PLUGIN_OPTIONS_BASE( aParent ),
m_callers_options( aOptions ), m_callers_options( aOptions ),
m_options( aOptions ),
m_result( aResult ) m_result( aResult )
{ {
wxString title = wxString::Format( wxString title = wxString::Format(
...@@ -46,26 +51,85 @@ public: ...@@ -46,26 +51,85 @@ public:
SetTitle( title ); SetTitle( title );
m_grid->AutoSizeColumns( false );
// add Cut, Copy, and Paste to wxGrids // add Cut, Copy, and Paste to wxGrids
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) ); m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
string options = TO_UTF8( aOptions );
PROPERTIES* props = FP_LIB_TABLE::ParseOptions( options );
if( props )
{
m_grid->AppendRows( props->size() );
int row = 0;
for( PROPERTIES::const_iterator it = props->begin(); it != props->end(); ++it, ++row )
{
m_grid->SetCellValue( row, 0, FROM_UTF8( it->first.c_str() ) );
m_grid->SetCellValue( row, 1, FROM_UTF8( it->second.c_str() ) );
}
}
if( !col_width_option )
{
m_grid->AutoSizeColumns( false );
}
else
{
m_grid->SetColSize( 0, col_width_option );
m_grid->SetColSize( 1, col_width_value );
}
// initial focus on the grid please. // initial focus on the grid please.
m_grid->SetFocus(); m_grid->SetFocus();
} }
~DIALOG_FP_PLUGIN_OPTIONS() ~DIALOG_FP_PLUGIN_OPTIONS()
{ {
// destroy GRID_TRICKS before m_grid.
m_grid->PopEventHandler( true ); m_grid->PopEventHandler( true );
} }
private: private:
const wxString& m_callers_options; const wxString& m_callers_options;
wxString m_options;
wxString* m_result; wxString* m_result;
wxString makeResult()
{
PROPERTIES props;
const int rowCount = m_grid->GetNumberRows();
for( int row = 0; row<rowCount; ++row )
{
string name = TO_UTF8( m_grid->GetCellValue( row, 0 ).Trim( false ).Trim() );
string value = TO_UTF8( m_grid->GetCellValue( row, 1 ).Trim( false ).Trim() );
if( name.size() )
{
props[name] = value;
}
}
string options = FP_LIB_TABLE::FormatOptions( &props );
return FROM_UTF8( options.c_str() );
}
void saveColSizes()
{
col_width_option = m_grid->GetColSize( 0 );
col_width_value = m_grid->GetColSize( 1 );
}
void abort()
{
saveColSizes();
*m_result = m_callers_options; // tell caller "no change"
EndModal( 0 );
}
//-----<event handlers>------------------------------------------------------ //-----<event handlers>------------------------------------------------------
void onAddRow( wxCommandEvent& event ) void onAddRow( wxCommandEvent& event )
{ {
...@@ -85,25 +149,22 @@ private: ...@@ -85,25 +149,22 @@ private:
void onCancelButtonClick( wxCommandEvent& event ) void onCancelButtonClick( wxCommandEvent& event )
{ {
*m_result = m_callers_options; // no change abort();
EndModal( 0 );
} }
void onCancelButtonClick( wxCloseEvent& event ) void onCancelButtonClick( wxCloseEvent& event )
{ {
*m_result = m_callers_options; // no change abort();
EndModal( 0 );
} }
void onOKButtonClick( wxCommandEvent& event ) void onOKButtonClick( wxCommandEvent& event )
{ {
*m_result = m_options; // change from edits saveColSizes();
*m_result = makeResult(); // change from edits
EndModal( 1 ); EndModal( 1 );
} }
//-----</event handlers>----------------------------------------------------- //-----</event handlers>-----------------------------------------------------
}; };
......
...@@ -26,12 +26,23 @@ ...@@ -26,12 +26,23 @@
*/ */
#include <richio.h> #include <richio.h>
#include <hashtables.h> #include <map>
class BOARD; class BOARD;
class PLUGIN; class PLUGIN;
class MODULE; class MODULE;
/**
* Class PROPERTIES
* is a name/value tuple with unique names and optional values. The names
* may be iterated alphabetically.
*/
class PROPERTIES : public std::map< std::string, std::string >
{
// alphabetical tuple of name and value hereby defined.
};
/** /**
* Class IO_MGR * Class IO_MGR
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment