Commit e45ed220 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

DIALOG_FP_LIB_TABLE does not use wxSplitterWindow, it would not obey.

Paste popup menu in this dialog now allows pasting a (fp_lib_table)
s-expression element holding (lib) elements.  This provides an 
opportunity for GITHUB library publishers to put the table description
into their README.md file as a (fp_lib_table) element where it can
be quickly copied to clipboard and pasted into the fp lib table dialog.
This is a paste operation, and overwrites from the initial cursor position.
parent 8234966a
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -50,6 +50,22 @@ FP_LIB_TABLE::FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable ) :
}


/*
void FP_LIB_TABLE::Paste( const FP_LIB_TABLE& aOther, int aDestNdx )
{
    if( aDestNdx == -1 )
        aDestNdx = rows.size() - 1;
    else if( unsigned( aDestNdx ) >= rows.size() )
        return;     // bad caller.
    else
    {

        rows.assign( aOther.rows.begin(), aOther.rows.end() );
    }
}
*/


void FP_LIB_TABLE::Parse( FP_LIB_TABLE_LEXER* in ) throw( IO_ERROR, PARSE_ERROR )
{
    /*
@@ -142,9 +158,6 @@ void FP_LIB_TABLE::Parse( FP_LIB_TABLE_LEXER* in ) throw( IO_ERROR, PARSE_ERROR
                sawOpts = true;
                in->NeedSYMBOLorNUMBER();
                row.SetOptions( in->FromUTF8() );

                // create PROPERTIES* from options, set into the ROW
                row.properties = ParseOptions( in->CurStr() );
                break;

            case T_descr:
+26 −20
Original line number Diff line number Diff line
@@ -202,7 +202,13 @@ public:
        /**
         * Function SetOptions
         */
        void SetOptions( const wxString& aOptions ) { options = aOptions; }
        void SetOptions( const wxString& aOptions )
        {
            options = aOptions;

            // set PROPERTIES* from options
            setProperties( ParseOptions( TO_UTF8( aOptions ) ) );
        }

        /**
         * Function GetDescr
@@ -223,17 +229,6 @@ public:
         */
        const PROPERTIES* GetProperties() const     { return properties; }

        /**
         * Function SetProperties
         * sets this ROW's PROPERTIES by taking ownership of @a aProperties.
         * @param aProperties ownership is given over to this ROW.
         */
        void SetProperties( const PROPERTIES* aProperties )
        {
            delete properties;
            properties = aProperties;
        }

        //-----</accessors>-----------------------------------------------------

        /**
@@ -249,6 +244,17 @@ public:

    private:

        /**
         * Function setProperties
         * sets this ROW's PROPERTIES by taking ownership of @a aProperties.
         * @param aProperties ownership is given over to this ROW.
         */
        void setProperties( const PROPERTIES* aProperties )
        {
            delete properties;
            properties = aProperties;
        }

        wxString        nickName;
        wxString        uri;
        LIB_T           type;
@@ -258,7 +264,6 @@ public:
        PROPERTIES*     properties;
    };


    /**
     * Constructor FP_LIB_TABLE
     * builds a library table by pre-pending this table fragment in front of
@@ -395,15 +400,8 @@ public:
        return row ? &row->options : 0;
    }
#endif

    //----</read accessors>---------------------------------------------------

#if 1 || defined(DEBUG)
    /// implement the tests in here so we can honor the privilege levels of the
    /// accessors, something difficult to do from int main(int, char**)
    void Test();
#endif

    /**
     * Function InsertRow
     * adds aRow if it does not already exist or if doReplace is true.  If doReplace
@@ -443,6 +441,14 @@ public:
     */
    bool IsEmpty() const;

    /**
     * Function Assign
     * assigns new contents to ROWs of this table by copying ALL rows from aOther,
     * and modifying the size of this table if necessary.
     * @param aDestNdx is the starting index into this table.
    void Assign( const FP_LIB_TABLE& aOther, int aDestNdx );
     */

    /**
     * Function MissingLegacyLibs
     * tests the list of \a aLibNames by URI to determine if any of them are missing from
+77 −20
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@
#include <fctsys.h>
#include <dialog_fp_lib_table_base.h>
#include <fp_lib_table.h>
#include <fp_lib_table_lexer.h>
#include <wx/grid.h>
#include <wx/clipbrd.h>
#include <wx/tokenzr.h>
@@ -287,7 +288,7 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE
            selColCount = 0;
        }

        // D(printf("selRowStart:%d selColStart:%d selRowCount:%d selColCount:%d\n", selRowStart, selColStart, selRowCount, selColCount );)
        D(printf("selRowStart:%d selColStart:%d selRowCount:%d selColCount:%d\n", selRowStart, selColStart, selRowCount, selColCount );)
    }

    void rightClickCellPopupMenu()
@@ -300,15 +301,30 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE

        getSelectedArea();

        // if nothing is selected, diable cut and copy.
        // if nothing is selected, disable cut and copy.
        if( !selRowCount && !selColCount )
        {
            menu.Enable( ID_CUT,  false );
            menu.Enable( ID_COPY, false );
        }

        bool have_cb_text = false;
        if( wxTheClipboard->Open() )
        {
            if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
                have_cb_text = true;

            wxTheClipboard->Close();
        }

        if( !have_cb_text )
        {
            // if nothing on clipboard, disable paste.
            menu.Enable( ID_PASTE, false );
        }

        // if there is no current cell cursor, disable paste.
        if( m_cur_row == -1 || m_cur_col == -1 )
        else if( m_cur_row == -1 || m_cur_col == -1 )
            menu.Enable( ID_PASTE, false );

        PopupMenu( &menu );
@@ -362,12 +378,53 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE
            {
                if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
                {
                    wxGridTableBase*    tbl = m_cur_grid->GetTable();
                    wxTextDataObject    data;
                    FP_TBL_MODEL*       tbl = (FP_TBL_MODEL*) m_cur_grid->GetTable();

                    wxTheClipboard->GetData( data );

                    wxStringTokenizer   rows( data.GetText(), ROW_SEP, wxTOKEN_RET_EMPTY );
                    wxString    cb_text = data.GetText();
                    size_t      ndx = cb_text.find_first_of( wxT( "(fp_lib_table " ) );

                    if( ndx != std::string::npos )
                    {
                        // paste the ROWs of s-expression (fp_lib_table), starting
                        // at column 0 regardless of current cursor column.

                        STRING_LINE_READER  slr( TO_UTF8( cb_text ), wxT( "Clipboard" ) );
                        FP_LIB_TABLE_LEXER  lexer( &slr );
                        FP_LIB_TABLE        tmp_tbl;
                        bool                parsed = true;

                        try
                        {
                            tmp_tbl.Parse( &lexer );
                        }
                        catch( PARSE_ERROR& pe )
                        {
                            // @todo tell what line and offset
                            parsed = false;
                        }

                        if( parsed )
                        {
                            // if clipboard rows would extend past end of current table size...
                            if( int( tmp_tbl.rows.size() ) > tbl->GetNumberRows() - m_cur_row )
                            {
                                int newRowsNeeded = tmp_tbl.rows.size() - ( tbl->GetNumberRows() - m_cur_row );
                                tbl->AppendRows( newRowsNeeded );
                            }

                            for( int i = 0;  i < (int) tmp_tbl.rows.size();  ++i )
                            {
                                tbl->rows[m_cur_row+i] = tmp_tbl.rows[i];
                            }
                        }
                        m_cur_grid->AutoSizeColumns();
                    }
                    else
                    {
                        wxStringTokenizer   rows( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );

                        // if clipboard rows would extend past end of current table size...
                        if( int( rows.CountTokens() ) > tbl->GetNumberRows() - m_cur_row )
@@ -389,6 +446,7 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE
                            }
                        }
                    }
                }

                wxTheClipboard->Close();
                m_cur_grid->ForceRefresh();
@@ -730,8 +788,8 @@ public:
        m_project( aProject ),
        m_global_model( *aGlobal ),
        m_project_model( *aProject ),
        m_cur_row( -1 ),
        m_cur_col( -1 )
        m_cur_row( 0 ),
        m_cur_col( 0 )
    {
        m_global_grid->SetTable( (wxGridTableBase*) &m_global_model );
        m_project_grid->SetTable( (wxGridTableBase*) &m_project_model );
@@ -740,10 +798,9 @@ public:
        m_project_grid->AutoSizeColumns( false );

        wxArrayString choices;

        choices.Add( IO_MGR::ShowType( IO_MGR::KICAD ) );
#if defined(BUILD_GITHUB_PLUGIN)
        choices.Add( IO_MGR::ShowType( IO_MGR::GITHUB ) );
#endif
        choices.Add( IO_MGR::ShowType( IO_MGR::LEGACY ) );
        choices.Add( IO_MGR::ShowType( IO_MGR::EAGLE ) );
        choices.Add( IO_MGR::ShowType( IO_MGR::GEDA_PCB ) );
+26 −29
Original line number Diff line number Diff line
@@ -16,15 +16,10 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	wxBoxSizer* bSizer1;
	bSizer1 = new wxBoxSizer( wxVERTICAL );
	
	m_splitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3DSASH );
	m_splitter->Connect( wxEVT_IDLE, wxIdleEventHandler( DIALOG_FP_LIB_TABLE_BASE::m_splitterOnIdle ), NULL, this );
	m_splitter->SetMinimumPaneSize( 10 );
	
	m_top = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxStaticBoxSizer* m_top_sizer;
	m_top_sizer = new wxStaticBoxSizer( new wxStaticBox( m_top, wxID_ANY, _("Library Tables by Scope") ), wxVERTICAL );
	m_top_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Library Tables by Scope") ), wxVERTICAL );
	
	m_auinotebook = new wxAuiNotebook( m_top, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_BOTTOM );
	m_auinotebook = new wxAuiNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_BOTTOM );
	m_global_panel = new wxPanel( m_auinotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	m_global_panel->SetToolTip( _("Module libraries which  are visible for all projects") );
	
@@ -56,6 +51,8 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	
	// Cell Defaults
	m_global_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
	m_global_grid->SetToolTip( _("This table is associated with all projects") );
	
	m_global_sizer->Add( m_global_grid, 1, wxALL|wxEXPAND, 5 );
	
	
@@ -94,6 +91,8 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	
	// Cell Defaults
	m_project_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
	m_project_grid->SetToolTip( _("Libraries list in this table is associated with the current project") );
	
	m_project_sizer->Add( m_project_grid, 1, wxALL|wxEXPAND, 5 );
	
	
@@ -102,32 +101,32 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	m_project_sizer->Fit( m_project_panel );
	m_auinotebook->AddPage( m_project_panel, _("Project Specific Libraries"), false, wxNullBitmap );
	
	m_top_sizer->Add( m_auinotebook, 1, wxEXPAND | wxALL, 5 );
	m_top_sizer->Add( m_auinotebook, 6, wxEXPAND | wxALL, 5 );
	
	wxBoxSizer* bSizer51;
	bSizer51 = new wxBoxSizer( wxHORIZONTAL );
	
	m_append_button = new wxButton( m_top, wxID_ANY, _("Append Row"), wxDefaultPosition, wxDefaultSize, 0 );
	m_append_button = new wxButton( this, wxID_ANY, _("Append Row"), wxDefaultPosition, wxDefaultSize, 0 );
	m_append_button->SetToolTip( _("Add a PCB library row to this table") );
	
	bSizer51->Add( m_append_button, 0, wxALL, 5 );
	
	m_delete_button = new wxButton( m_top, wxID_ANY, _("Delete Row"), wxDefaultPosition, wxDefaultSize, 0 );
	m_delete_button = new wxButton( this, wxID_ANY, _("Delete Row"), wxDefaultPosition, wxDefaultSize, 0 );
	m_delete_button->SetToolTip( _("Remove a PCB library from this library table") );
	
	bSizer51->Add( m_delete_button, 0, wxALL, 5 );
	
	m_move_up_button = new wxButton( m_top, wxID_ANY, _("Move Up"), wxDefaultPosition, wxDefaultSize, 0 );
	m_move_up_button = new wxButton( this, wxID_ANY, _("Move Up"), wxDefaultPosition, wxDefaultSize, 0 );
	m_move_up_button->SetToolTip( _("Move the currently selected row up one position") );
	
	bSizer51->Add( m_move_up_button, 0, wxALL, 5 );
	
	m_move_down_button = new wxButton( m_top, wxID_ANY, _("Move Down"), wxDefaultPosition, wxDefaultSize, 0 );
	m_move_down_button = new wxButton( this, wxID_ANY, _("Move Down"), wxDefaultPosition, wxDefaultSize, 0 );
	m_move_down_button->SetToolTip( _("Move the currently selected row down one position") );
	
	bSizer51->Add( m_move_down_button, 0, wxALL, 5 );
	
	m_edit_options = new wxButton( m_top, wxID_ANY, _("Options Editor"), wxDefaultPosition, wxDefaultSize, 0 );
	m_edit_options = new wxButton( this, wxID_ANY, _("Options Editor"), wxDefaultPosition, wxDefaultSize, 0 );
	m_edit_options->SetToolTip( _("Zoom into the options table for current row") );
	
	bSizer51->Add( m_edit_options, 0, wxALL, 5 );
@@ -136,17 +135,12 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	m_top_sizer->Add( bSizer51, 0, wxALIGN_CENTER|wxBOTTOM, 8 );
	
	
	m_top->SetSizer( m_top_sizer );
	m_top->Layout();
	m_top_sizer->Fit( m_top );
	m_bottom = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxBoxSizer* m_bottom_sizer;
	m_bottom_sizer = new wxBoxSizer( wxVERTICAL );
	bSizer1->Add( m_top_sizer, 1, wxEXPAND, 5 );
	
	wxStaticBoxSizer* sbSizer1;
	sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( m_bottom, wxID_ANY, _("Path Substitutions") ), wxVERTICAL );
	sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Path Substitutions") ), wxVERTICAL );
	
	m_path_subs_grid = new wxGrid( m_bottom, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
	m_path_subs_grid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
	
	// Grid
	m_path_subs_grid->CreateGrid( 1, 2 );
@@ -175,26 +169,27 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	
	// Cell Defaults
	m_path_subs_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
	m_path_subs_grid->SetToolTip( _("This is a read-only table which shows pertinent environment variables.") );
	
	sbSizer1->Add( m_path_subs_grid, 1, wxALL|wxEXPAND, 5 );
	
	
	m_bottom_sizer->Add( sbSizer1, 1, wxALL|wxEXPAND, 5 );
	bSizer1->Add( sbSizer1, 0, wxALL|wxEXPAND, 5 );
	
	wxBoxSizer* m_bottom_sizer;
	m_bottom_sizer = new wxBoxSizer( wxVERTICAL );
	
	m_sdbSizer1 = new wxStdDialogButtonSizer();
	m_sdbSizer1OK = new wxButton( m_bottom, wxID_OK );
	m_sdbSizer1OK = new wxButton( this, wxID_OK );
	m_sdbSizer1->AddButton( m_sdbSizer1OK );
	m_sdbSizer1Cancel = new wxButton( m_bottom, wxID_CANCEL );
	m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL );
	m_sdbSizer1->AddButton( m_sdbSizer1Cancel );
	m_sdbSizer1->Realize();
	
	m_bottom_sizer->Add( m_sdbSizer1, 0, wxALL|wxEXPAND, 5 );
	
	
	m_bottom->SetSizer( m_bottom_sizer );
	m_bottom->Layout();
	m_bottom_sizer->Fit( m_bottom );
	m_splitter->SplitHorizontally( m_top, m_bottom, 398 );
	bSizer1->Add( m_splitter, 2, wxEXPAND, 5 );
	bSizer1->Add( m_bottom_sizer, 0, wxEXPAND, 5 );
	
	
	this->SetSizer( bSizer1 );
@@ -203,6 +198,7 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	this->Centre( wxBOTH );
	
	// Connect Events
	this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_FP_LIB_TABLE_BASE::onInitDialog ) );
	m_auinotebook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( DIALOG_FP_LIB_TABLE_BASE::pageChangedHandler ), NULL, this );
	m_global_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_FP_LIB_TABLE_BASE::onGridCellLeftClick ), NULL, this );
	m_global_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_FP_LIB_TABLE_BASE::onGridCellLeftDClick ), NULL, this );
@@ -224,6 +220,7 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
DIALOG_FP_LIB_TABLE_BASE::~DIALOG_FP_LIB_TABLE_BASE()
{
	// Disconnect Events
	this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_FP_LIB_TABLE_BASE::onInitDialog ) );
	m_auinotebook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( DIALOG_FP_LIB_TABLE_BASE::pageChangedHandler ), NULL, this );
	m_global_grid->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_FP_LIB_TABLE_BASE::onGridCellLeftClick ), NULL, this );
	m_global_grid->Disconnect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_FP_LIB_TABLE_BASE::onGridCellLeftDClick ), NULL, this );
+923 −1157

File changed.

Preview size limit exceeded, changes collapsed.

Loading