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 @@
#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.
typedef std::unordered_map< std::string, int > KEYWORD_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
/// 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
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
InvokePluginOptionsEditor( this, row.GetNickName(), options, &result );
if( options != result )
{
row.SetOptions( result );
m_cur_grid->AutoSizeColumn( COL_OPTIONS, false );
}
}
void onCancelButtonClick( wxCommandEvent& event )
......
......@@ -29,6 +29,12 @@
#include <fp_lib_table.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
{
......@@ -38,7 +44,6 @@ public:
const wxString& aNickname, const wxString& aOptions, wxString* aResult ) :
DIALOG_FP_PLUGIN_OPTIONS_BASE( aParent ),
m_callers_options( aOptions ),
m_options( aOptions ),
m_result( aResult )
{
wxString title = wxString::Format(
......@@ -46,26 +51,85 @@ public:
SetTitle( title );
m_grid->AutoSizeColumns( false );
// add Cut, Copy, and Paste to wxGrids
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.
m_grid->SetFocus();
}
~DIALOG_FP_PLUGIN_OPTIONS()
{
// destroy GRID_TRICKS before m_grid.
m_grid->PopEventHandler( true );
}
private:
const wxString& m_callers_options;
wxString m_options;
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>------------------------------------------------------
void onAddRow( wxCommandEvent& event )
{
......@@ -85,25 +149,22 @@ private:
void onCancelButtonClick( wxCommandEvent& event )
{
*m_result = m_callers_options; // no change
EndModal( 0 );
abort();
}
void onCancelButtonClick( wxCloseEvent& event )
{
*m_result = m_callers_options; // no change
EndModal( 0 );
abort();
}
void onOKButtonClick( wxCommandEvent& event )
{
*m_result = m_options; // change from edits
saveColSizes();
*m_result = makeResult(); // change from edits
EndModal( 1 );
}
//-----</event handlers>-----------------------------------------------------
};
......
......@@ -26,12 +26,23 @@
*/
#include <richio.h>
#include <hashtables.h>
#include <map>
class BOARD;
class PLUGIN;
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
......
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