Commit f13edb6a authored by Brian Sidebotham's avatar Brian Sidebotham
Browse files

* Intermediate changes before TRUNK merge

parent 230b60e6
Loading
Loading
Loading
Loading
+66 −29
Original line number Original line Diff line number Diff line
@@ -153,17 +153,20 @@ void DIALOG_EESCHEMA_OPTIONS::RefreshTemplateFieldView( void )
    {
    {
        long itemindex = templateFieldListCtrl->InsertItem( templateFieldListCtrl->GetItemCount(), fld->m_Name );
        long itemindex = templateFieldListCtrl->InsertItem( templateFieldListCtrl->GetItemCount(), fld->m_Name );
        templateFieldListCtrl->SetItem( itemindex, 1, fld->m_Value );
        templateFieldListCtrl->SetItem( itemindex, 1, fld->m_Value );
        templateFieldListCtrl->SetItem( itemindex, 2, ( fld->m_Visible == true ) ? wxT( "Visible" ) : wxT( "Hidden" ) );
        templateFieldListCtrl->SetItem( itemindex, 2, ( fld->m_Visible == true ) ? _( "Visible" ) : _( "Hidden" ) );
    }
}
}


    // If an item was selected, make sure we re-select it, or at least the

    // same position in the grid and then copy the data to the edit panel in
void DIALOG_EESCHEMA_OPTIONS::SelectTemplateField( int item )
    // case it has changed
    if( ( selectedField >= 0 ) && ( selectedField < templateFields.size() ) )
{
{
        templateFieldListCtrl->SetItemState( selectedField, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
    // Only select valid items!
        copySelectedToPanel();
    if( ( item < 0 ) || ( item >= templateFieldListCtrl->GetItemCount() ) )
    }
        return;

    // Make sure we select the new item
    ignoreSelection = true;
    templateFieldListCtrl->SetItemState( item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
}
}




@@ -175,37 +178,59 @@ void DIALOG_EESCHEMA_OPTIONS::OnAddButtonClick( wxCommandEvent& event )
        copyPanelToSelected();
        copyPanelToSelected();


    // Add a new fieldname to the fieldname list
    // Add a new fieldname to the fieldname list
    TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( "New Fieldname" );
    TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( "Fieldname" );
    newFieldname.m_Value = wxString::Format( wxT( "Default Value %d" ), templateFields.size() );
    newFieldname.m_Value = wxT( "Value" );
    newFieldname.m_Visible = false;
    newFieldname.m_Visible = false;
    templateFields.push_back( newFieldname );
    templateFields.push_back( newFieldname );


    // Update the display to reflect the new data
    RefreshTemplateFieldView();

    // Select the newly added field and then copy that data to the edit panel.
    // Select the newly added field and then copy that data to the edit panel.
    // Make sure any previously selected state is cleared and then select the
    // Make sure any previously selected state is cleared and then select the
    // new field
    // new field
    long selected = templateFieldListCtrl->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
    selectedField = templateFields.size() - 1;


    if( selected >= 0 )
    // Update the display to reflect the new data
        templateFieldListCtrl->SetItemState( selected, 0, wxLIST_STATE_SELECTED );
    RefreshTemplateFieldView();
    copySelectedToPanel();


    templateFieldListCtrl->SetItemState( templateFieldListCtrl->GetItemCount() - 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
    // Make sure we select the new item
    selectedField = templateFieldListCtrl->GetItemCount() - 1;
    SelectTemplateField( selectedField );


    event.Skip();
}


void DIALOG_EESCHEMA_OPTIONS::OnDeleteButtonClick( wxCommandEvent& event )
{
    // If there is currently a valid selection, delete the template field from
    // the template field list
    if( ( selectedField >= 0 ) && ( selectedField < templateFields.size() ) )
    {
        // Delete the fieldname from the fieldname list
        templateFields.erase( templateFields.begin() + selectedField );

        // If the selectedField is still not in the templateField range now,
        // make sure we stay in range and when there are no fields present
        // move to -1
        if( selectedField >= templateFields.size() )
            selectedField = templateFields.size() - 1;

        // Update the display to reflect the new data
        RefreshTemplateFieldView();
        copySelectedToPanel();
        copySelectedToPanel();


    event.Skip();
        // Make sure after the refresh that the selected item is correct
        SelectTemplateField( selectedField );
    }
    }


    event.Skip();
}


void DIALOG_EESCHEMA_OPTIONS::copyPanelToSelected( void )
void DIALOG_EESCHEMA_OPTIONS::copyPanelToSelected( void )
{
{
    if( ( selectedField < 0 ) || ( selectedField >= templateFields.size() ) )
    if( ( selectedField < 0 ) || ( selectedField >= templateFields.size() ) )
        return;
        return;


    // Update the template field data
    // Update the template field from the edit panel
    templateFields[selectedField].m_Name = fieldNameTextCtrl->GetValue();
    templateFields[selectedField].m_Name = fieldNameTextCtrl->GetValue();
    templateFields[selectedField].m_Value = fieldDefaultValueTextCtrl->GetValue();
    templateFields[selectedField].m_Value = fieldDefaultValueTextCtrl->GetValue();
    templateFields[selectedField].m_Visible = fieldVisibleCheckbox->GetValue();
    templateFields[selectedField].m_Visible = fieldVisibleCheckbox->GetValue();
@@ -217,20 +242,22 @@ void DIALOG_EESCHEMA_OPTIONS::copySelectedToPanel( void )
    if( ( selectedField < 0 ) || ( selectedField >= templateFields.size() ) )
    if( ( selectedField < 0 ) || ( selectedField >= templateFields.size() ) )
        return;
        return;


    // Update the panel data from the selected template field
    fieldNameTextCtrl->SetValue( templateFields[selectedField].m_Name );
    fieldNameTextCtrl->SetValue( templateFields[selectedField].m_Name );
    fieldDefaultValueTextCtrl->SetValue( templateFields[selectedField].m_Value );
    fieldDefaultValueTextCtrl->SetValue( templateFields[selectedField].m_Value );

    fieldVisibleCheckbox->SetValue( templateFields[selectedField].m_Visible );
    if( templateFields[selectedField].m_Visible == true )
        fieldVisibleCheckbox->SetValue( false );
    else
        fieldVisibleCheckbox->SetValue( true );
}
}




void DIALOG_EESCHEMA_OPTIONS::OnTemplateFieldSelected( wxListEvent& event )
void DIALOG_EESCHEMA_OPTIONS::OnTemplateFieldSelected( wxListEvent& event )
{
{
    if( ignoreSelection )
    {
        ignoreSelection = false;
        return;
    }

    // Before getting the new field data, make sure we save the old!
    // Before getting the new field data, make sure we save the old!
    if( selectedField >= 0 )
    copyPanelToSelected();
    copyPanelToSelected();


    // Now update the selected field and copy the data from the field to the
    // Now update the selected field and copy the data from the field to the
@@ -238,6 +265,16 @@ void DIALOG_EESCHEMA_OPTIONS::OnTemplateFieldSelected( wxListEvent& event )
    selectedField = event.GetIndex();
    selectedField = event.GetIndex();
    copySelectedToPanel();
    copySelectedToPanel();


    // Refresh the template field view - this deletes all fields and then
    // re-fills the entire data grid. It then re-selects the currently
    // selected field. This will be recursive, so disable this event while
    // we refresh the view
    RefreshTemplateFieldView();

    // If an item was selected, make sure we re-select it, or at least the
    // same position in the grid
    SelectTemplateField( selectedField );

    event.Skip();
    event.Skip();
}
}


+4 −1
Original line number Original line Diff line number Diff line
@@ -38,13 +38,16 @@ class DIALOG_EESCHEMA_OPTIONS : public DIALOG_EESCHEMA_OPTIONS_BASE
{
{
protected:
protected:
    TEMPLATE_FIELDNAMES templateFields;
    TEMPLATE_FIELDNAMES templateFields;
    int selectedField;
    int selectedField = -1;
    bool ignoreSelection = false;
    void OnAddButtonClick( wxCommandEvent& event );
    void OnAddButtonClick( wxCommandEvent& event );
    void OnDeleteButtonClick( wxCommandEvent& event );
    void copyPanelToSelected( void );
    void copyPanelToSelected( void );
    void copySelectedToPanel( void );
    void copySelectedToPanel( void );
    void OnTemplateFieldSelected( wxListEvent& event );
    void OnTemplateFieldSelected( wxListEvent& event );
    void OnTemplateFieldDeselected( wxListEvent& event );
    void OnTemplateFieldDeselected( wxListEvent& event );
    void RefreshTemplateFieldView( void );
    void RefreshTemplateFieldView( void );
    void SelectTemplateField( int item );
public:
public:
    DIALOG_EESCHEMA_OPTIONS( wxWindow* parent );
    DIALOG_EESCHEMA_OPTIONS( wxWindow* parent );