dialog_edit_components_libid: UI enhancements, and use viewlib for LIB_ID selection

This commit is contained in:
jean-pierre charras 2017-11-23 10:39:52 +01:00
parent c3015f4671
commit fea9d121b7
5 changed files with 160 additions and 8 deletions

View File

@ -111,6 +111,12 @@ private:
/// Reverts all changes already made /// Reverts all changes already made
void revertChanges(); void revertChanges();
/** run the lib browser and set the selected LIB_ID for row aRow
* @param aRow is the row to edit
* @return false if the command was aborted
*/
bool setLibIdByBrowser( int aRow );
// Events handlers // Events handlers
// called on a right click or a left double click: // called on a right click or a left double click:
@ -127,14 +133,23 @@ private:
event.Skip(); event.Skip();
} }
void onButtonBrowseLibraries( wxCommandEvent& event ) override;
// Undo all changes, and clear the list of new lib_ids // Undo all changes, and clear the list of new lib_ids
void onUndoChangesButton( wxCommandEvent& event ) override; void onUndoChangesButton( wxCommandEvent& event ) override;
// UI event, to enable/disable buttons
void updateUIChangesButton( wxUpdateUIEvent& event ) override void updateUIChangesButton( wxUpdateUIEvent& event ) override
{ {
m_buttonUndo->Enable( m_isModified ); m_buttonUndo->Enable( m_isModified );
} }
void updateUIBrowseButton( wxUpdateUIEvent& event ) override
{
wxArrayInt rows = m_grid->GetSelectedRows();
m_buttonBrowseLibs->Enable( rows.GetCount() == 1 );
}
// Automatically called when click on OK button // Automatically called when click on OK button
bool TransferDataFromWindow() override; bool TransferDataFromWindow() override;
}; };
@ -282,6 +297,9 @@ void DIALOG_EDIT_COMPONENTS_LIBID::initDlg()
// ensure the column title is correctly displayed // ensure the column title is correctly displayed
m_grid->SetColMinimalWidth( COL_NEW_LIBID, m_grid->GetColSize( COL_NEW_LIBID ) ); m_grid->SetColMinimalWidth( COL_NEW_LIBID, m_grid->GetColSize( COL_NEW_LIBID ) );
m_grid->AutoSizeColLabelSize( COL_NEW_LIBID ); m_grid->AutoSizeColLabelSize( COL_NEW_LIBID );
// Allows only the selection by row
m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
} }
@ -365,19 +383,51 @@ void DIALOG_EDIT_COMPONENTS_LIBID::onUndoChangesButton( wxCommandEvent& event )
void DIALOG_EDIT_COMPONENTS_LIBID::onCellBrowseLib( wxGridEvent& event ) void DIALOG_EDIT_COMPONENTS_LIBID::onCellBrowseLib( wxGridEvent& event )
{ {
int row = event.GetRow(); int row = event.GetRow();
m_grid->SelectRow( row ); // only for user, to show the selected line
SCH_BASE_FRAME::HISTORY_LIST dummy; setLibIdByBrowser( row );
auto sel = m_parent->SelectComponentFromLibrary( NULL, dummy, true, 0, 0 ); }
if( !sel.LibId.IsValid() )
void DIALOG_EDIT_COMPONENTS_LIBID::onButtonBrowseLibraries( wxCommandEvent& event )
{
wxArrayInt rows = m_grid->GetSelectedRows();
if( rows.GetCount() != 1 ) // Should not occur, because the button is disabled
return; return;
setLibIdByBrowser( rows[0] );
}
bool DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser( int aRow )
{
#if 0
SCH_BASE_FRAME::HISTORY_LIST dummy;
SCH_BASE_FRAME::COMPONENT_SELECTION sel =
m_parent->SelectComponentFromLibrary( NULL, dummy, true, 0, 0 );
#else
LIB_ID aPreselectedLibid;
SCH_BASE_FRAME::COMPONENT_SELECTION sel =
m_parent->SelectComponentFromLibBrowser( NULL, aPreselectedLibid, 0, 0 );
#endif
if( sel.LibId.empty() ) // command aborted
return false;
if( !sel.LibId.IsValid() ) // Should not occur
{
wxMessageBox( _( "Invalid symbol library identifier" ) );
return false;
}
wxString new_libid; wxString new_libid;
new_libid = sel.LibId.Format(); new_libid = sel.LibId.Format();
m_grid->SetCellValue( row, COL_NEW_LIBID, new_libid ); m_grid->SetCellValue( aRow, COL_NEW_LIBID, new_libid );
return true;
} }

View File

@ -92,6 +92,9 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::DIALOG_EDIT_COMPONENTS_LIBID_BASE( wxWindow*
m_buttonUndo = new wxButton( this, wxID_ANY, _("Undo Changes"), wxDefaultPosition, wxDefaultSize, 0 ); m_buttonUndo = new wxButton( this, wxID_ANY, _("Undo Changes"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerButtons->Add( m_buttonUndo, 0, wxTOP|wxBOTTOM|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 ); bSizerButtons->Add( m_buttonUndo, 0, wxTOP|wxBOTTOM|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 );
m_buttonBrowseLibs = new wxButton( this, wxID_ANY, _("Browse Libraries"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerButtons->Add( m_buttonBrowseLibs, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
bSizerMain->Add( bSizerButtons, 0, wxALIGN_RIGHT, 5 ); bSizerMain->Add( bSizerButtons, 0, wxALIGN_RIGHT, 5 );
@ -104,10 +107,14 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::DIALOG_EDIT_COMPONENTS_LIBID_BASE( wxWindow*
// Connect Events // Connect Events
m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this ); m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this ); m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_grid->Connect( wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_grid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_sdbSizerApply->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onApplyButton ), NULL, this ); m_sdbSizerApply->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onApplyButton ), NULL, this );
m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCancel ), NULL, this ); m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCancel ), NULL, this );
m_buttonUndo->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onUndoChangesButton ), NULL, this ); m_buttonUndo->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onUndoChangesButton ), NULL, this );
m_buttonUndo->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIChangesButton ), NULL, this ); m_buttonUndo->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIChangesButton ), NULL, this );
m_buttonBrowseLibs->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onButtonBrowseLibraries ), NULL, this );
m_buttonBrowseLibs->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIBrowseButton ), NULL, this );
} }
DIALOG_EDIT_COMPONENTS_LIBID_BASE::~DIALOG_EDIT_COMPONENTS_LIBID_BASE() DIALOG_EDIT_COMPONENTS_LIBID_BASE::~DIALOG_EDIT_COMPONENTS_LIBID_BASE()
@ -115,9 +122,13 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::~DIALOG_EDIT_COMPONENTS_LIBID_BASE()
// Disconnect Events // Disconnect Events
m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this ); m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_grid->Disconnect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this ); m_grid->Disconnect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_grid->Disconnect( wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_grid->Disconnect( wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_sdbSizerApply->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onApplyButton ), NULL, this ); m_sdbSizerApply->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onApplyButton ), NULL, this );
m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCancel ), NULL, this ); m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCancel ), NULL, this );
m_buttonUndo->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onUndoChangesButton ), NULL, this ); m_buttonUndo->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onUndoChangesButton ), NULL, this );
m_buttonUndo->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIChangesButton ), NULL, this ); m_buttonUndo->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIChangesButton ), NULL, this );
m_buttonBrowseLibs->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onButtonBrowseLibraries ), NULL, this );
m_buttonBrowseLibs->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIBrowseButton ), NULL, this );
} }

View File

@ -291,8 +291,8 @@
<event name="OnGridEditorHidden"></event> <event name="OnGridEditorHidden"></event>
<event name="OnGridEditorShown"></event> <event name="OnGridEditorShown"></event>
<event name="OnGridLabelLeftClick"></event> <event name="OnGridLabelLeftClick"></event>
<event name="OnGridLabelLeftDClick"></event> <event name="OnGridLabelLeftDClick">onCellBrowseLib</event>
<event name="OnGridLabelRightClick"></event> <event name="OnGridLabelRightClick">onCellBrowseLib</event>
<event name="OnGridLabelRightDClick"></event> <event name="OnGridLabelRightDClick"></event>
<event name="OnGridRangeSelect"></event> <event name="OnGridRangeSelect"></event>
<event name="OnGridRowSize"></event> <event name="OnGridRowSize"></event>
@ -620,6 +620,94 @@
<event name="OnUpdateUI">updateUIChangesButton</event> <event name="OnUpdateUI">updateUIChangesButton</event>
</object> </object>
</object> </object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Browse Libraries</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_buttonBrowseLibs</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">onButtonBrowseLibraries</event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI">updateUIBrowseButton</event>
</object>
</object>
</object> </object>
</object> </object>
</object> </object>

View File

@ -47,6 +47,7 @@ class DIALOG_EDIT_COMPONENTS_LIBID_BASE : public DIALOG_SHIM
wxButton* m_sdbSizerApply; wxButton* m_sdbSizerApply;
wxButton* m_sdbSizerCancel; wxButton* m_sdbSizerCancel;
wxButton* m_buttonUndo; wxButton* m_buttonUndo;
wxButton* m_buttonBrowseLibs;
// Virtual event handlers, overide them in your derived class // Virtual event handlers, overide them in your derived class
virtual void onCellBrowseLib( wxGridEvent& event ) { event.Skip(); } virtual void onCellBrowseLib( wxGridEvent& event ) { event.Skip(); }
@ -54,6 +55,8 @@ class DIALOG_EDIT_COMPONENTS_LIBID_BASE : public DIALOG_SHIM
virtual void onCancel( wxCommandEvent& event ) { event.Skip(); } virtual void onCancel( wxCommandEvent& event ) { event.Skip(); }
virtual void onUndoChangesButton( wxCommandEvent& event ) { event.Skip(); } virtual void onUndoChangesButton( wxCommandEvent& event ) { event.Skip(); }
virtual void updateUIChangesButton( wxUpdateUIEvent& event ) { event.Skip(); } virtual void updateUIChangesButton( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onButtonBrowseLibraries( wxCommandEvent& event ) { event.Skip(); }
virtual void updateUIBrowseButton( wxUpdateUIEvent& event ) { event.Skip(); }
public: public:

View File

@ -218,8 +218,6 @@ public:
LIB_PART* GetLibPart( const LIB_ID& aLibId, bool aUseCacheLib = false, LIB_PART* GetLibPart( const LIB_ID& aLibId, bool aUseCacheLib = false,
bool aShowErrorMsg = false ); bool aShowErrorMsg = false );
protected:
/** /**
* Function SelectComponentFromLibBrowser * Function SelectComponentFromLibBrowser
* Calls the library viewer to select component to import into schematic. * Calls the library viewer to select component to import into schematic.
@ -237,6 +235,8 @@ protected:
const LIB_ID& aPreselectedLibid, const LIB_ID& aPreselectedLibid,
int aUnit, int aConvert ); int aUnit, int aConvert );
protected:
/** /**
* Open the library viewer only to browse library contents. * Open the library viewer only to browse library contents.
* If the viewed is already opened from this, raise the viewer * If the viewed is already opened from this, raise the viewer