Refactor: Move DIALOG_PLUGIN_OPTIONS to common and use enum for event ID
This commit is contained in:
parent
d526362d31
commit
a119bd604d
|
@ -125,6 +125,8 @@ set( COMMON_DLG_SRCS
|
||||||
dialogs/dialog_page_settings_base.cpp
|
dialogs/dialog_page_settings_base.cpp
|
||||||
dialogs/dialog_paste_special.cpp
|
dialogs/dialog_paste_special.cpp
|
||||||
dialogs/dialog_paste_special_base.cpp
|
dialogs/dialog_paste_special_base.cpp
|
||||||
|
dialogs/dialog_plugin_options.cpp
|
||||||
|
dialogs/dialog_plugin_options_base.cpp
|
||||||
dialogs/dialog_text_entry_base.cpp
|
dialogs/dialog_text_entry_base.cpp
|
||||||
dialogs/dialog_page_settings.cpp
|
dialogs/dialog_page_settings.cpp
|
||||||
dialogs/dialog_print_generic.cpp
|
dialogs/dialog_print_generic.cpp
|
||||||
|
|
|
@ -0,0 +1,282 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
||||||
|
* Copyright (C) 2013 CERN
|
||||||
|
* Copyright (C) 2013-2023 KiCad Developers, see change_log.txt for contributors.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, you may find one here:
|
||||||
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||||
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||||
|
* or you may write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <dialogs/dialog_plugin_options.h>
|
||||||
|
#include <grid_tricks.h>
|
||||||
|
#include <lib_table_base.h>
|
||||||
|
#include <widgets/wx_grid.h>
|
||||||
|
#include <widgets/std_bitmap_button.h>
|
||||||
|
#include <bitmaps.h>
|
||||||
|
#include <macros.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define INITIAL_HELP \
|
||||||
|
_( "Select an <b>Option Choice</b> in the listbox above, and then click the <b>Append Selected Option</b> button." )
|
||||||
|
|
||||||
|
|
||||||
|
DIALOG_PLUGIN_OPTIONS::DIALOG_PLUGIN_OPTIONS( wxWindow* aParent,
|
||||||
|
const wxString& aNickname,
|
||||||
|
const STRING_UTF8_MAP& aPluginOptions,
|
||||||
|
const wxString& aFormattedOptions,
|
||||||
|
wxString* aResult ) :
|
||||||
|
DIALOG_PLUGIN_OPTIONS_BASE( aParent ),
|
||||||
|
m_choices( aPluginOptions ),
|
||||||
|
m_callers_options( aFormattedOptions ),
|
||||||
|
m_result( aResult ),
|
||||||
|
m_initial_help( INITIAL_HELP ),
|
||||||
|
m_grid_widths_dirty( true )
|
||||||
|
{
|
||||||
|
SetTitle( wxString::Format( _( "Options for Library '%s'" ), aNickname ) );
|
||||||
|
|
||||||
|
// Give a bit more room for combobox editors
|
||||||
|
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
|
||||||
|
|
||||||
|
m_grid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
|
||||||
|
|
||||||
|
// add Cut, Copy, and Paste to wxGrid
|
||||||
|
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
|
||||||
|
|
||||||
|
// Option Choices Panel:
|
||||||
|
if( m_choices.size() )
|
||||||
|
{
|
||||||
|
unsigned int row = 0;
|
||||||
|
|
||||||
|
for( STRING_UTF8_MAP::const_iterator it = m_choices.begin(); it != m_choices.end();
|
||||||
|
++it, ++row )
|
||||||
|
{
|
||||||
|
wxString item = FROM_UTF8( it->first.c_str() );
|
||||||
|
|
||||||
|
m_listbox->InsertItems( 1, &item, row );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_html->SetPage( m_initial_help );
|
||||||
|
|
||||||
|
// Configure button logos
|
||||||
|
m_append_button->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
||||||
|
m_delete_button->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
||||||
|
|
||||||
|
// initial focus on the grid please.
|
||||||
|
SetInitialFocus( m_grid );
|
||||||
|
|
||||||
|
SetupStandardButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DIALOG_PLUGIN_OPTIONS ::~DIALOG_PLUGIN_OPTIONS()
|
||||||
|
{
|
||||||
|
// destroy GRID_TRICKS before m_grid.
|
||||||
|
m_grid->PopEventHandler( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool DIALOG_PLUGIN_OPTIONS::TransferDataToWindow()
|
||||||
|
{
|
||||||
|
if( !DIALOG_SHIM::TransferDataToWindow() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Fill the grid with existing aOptions
|
||||||
|
std::string options = TO_UTF8( m_callers_options );
|
||||||
|
|
||||||
|
STRING_UTF8_MAP* props = LIB_TABLE::ParseOptions( options );
|
||||||
|
|
||||||
|
if( props )
|
||||||
|
{
|
||||||
|
if( (int) props->size() > m_grid->GetNumberRows() )
|
||||||
|
m_grid->AppendRows( props->size() - m_grid->GetNumberRows() );
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
|
||||||
|
for( STRING_UTF8_MAP::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, it->second );
|
||||||
|
}
|
||||||
|
|
||||||
|
delete props;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool DIALOG_PLUGIN_OPTIONS::TransferDataFromWindow()
|
||||||
|
{
|
||||||
|
if( !m_grid->CommitPendingChanges() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( !DIALOG_SHIM::TransferDataFromWindow() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
STRING_UTF8_MAP props;
|
||||||
|
const int rowCount = m_grid->GetNumberRows();
|
||||||
|
|
||||||
|
for( int row = 0; row<rowCount; ++row )
|
||||||
|
{
|
||||||
|
std::string name = TO_UTF8( m_grid->GetCellValue( row, 0 ).Trim( false ).Trim() );
|
||||||
|
UTF8 value = m_grid->GetCellValue( row, 1 ).Trim( false ).Trim();
|
||||||
|
|
||||||
|
if( name.size() )
|
||||||
|
{
|
||||||
|
props[name] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*m_result = LIB_TABLE::FormatOptions( &props );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int DIALOG_PLUGIN_OPTIONS::appendRow()
|
||||||
|
{
|
||||||
|
int row = m_grid->GetNumberRows();
|
||||||
|
|
||||||
|
m_grid->AppendRows( 1 );
|
||||||
|
|
||||||
|
// wx documentation is wrong, SetGridCursor does not make visible.
|
||||||
|
m_grid->MakeCellVisible( row, 0 );
|
||||||
|
m_grid->SetGridCursor( row, 0 );
|
||||||
|
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DIALOG_PLUGIN_OPTIONS::appendOption()
|
||||||
|
{
|
||||||
|
int selected_row = m_listbox->GetSelection();
|
||||||
|
if( selected_row != wxNOT_FOUND )
|
||||||
|
{
|
||||||
|
wxString option = m_listbox->GetString( selected_row );
|
||||||
|
|
||||||
|
int row_count = m_grid->GetNumberRows();
|
||||||
|
int row;
|
||||||
|
|
||||||
|
for( row=0; row<row_count; ++row )
|
||||||
|
{
|
||||||
|
wxString col0 = m_grid->GetCellValue( row, 0 );
|
||||||
|
|
||||||
|
if( !col0 ) // empty col0
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( row == row_count )
|
||||||
|
row = appendRow();
|
||||||
|
|
||||||
|
m_grid->SetCellValue( row, 0, option );
|
||||||
|
m_grid_widths_dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----<event handlers>------------------------------------------------------
|
||||||
|
|
||||||
|
void DIALOG_PLUGIN_OPTIONS::onListBoxItemSelected( wxCommandEvent& event )
|
||||||
|
{
|
||||||
|
// change the help text based on the m_listbox selection:
|
||||||
|
if( event.IsSelection() )
|
||||||
|
{
|
||||||
|
std::string option = TO_UTF8( event.GetString() );
|
||||||
|
UTF8 help_text;
|
||||||
|
|
||||||
|
if( m_choices.Value( option.c_str(), &help_text ) )
|
||||||
|
m_html->SetPage( help_text );
|
||||||
|
else
|
||||||
|
m_html->SetPage( m_initial_help );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DIALOG_PLUGIN_OPTIONS::onListBoxItemDoubleClicked( wxCommandEvent& event )
|
||||||
|
{
|
||||||
|
appendOption();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DIALOG_PLUGIN_OPTIONS::onAppendOption( wxCommandEvent& )
|
||||||
|
{
|
||||||
|
if( !m_grid->CommitPendingChanges() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
appendOption();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DIALOG_PLUGIN_OPTIONS::onAppendRow( wxCommandEvent& )
|
||||||
|
{
|
||||||
|
if( !m_grid->CommitPendingChanges() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
appendRow();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DIALOG_PLUGIN_OPTIONS::onDeleteRow( wxCommandEvent& )
|
||||||
|
{
|
||||||
|
if( !m_grid->CommitPendingChanges() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
int curRow = m_grid->GetGridCursorRow();
|
||||||
|
|
||||||
|
m_grid->DeleteRows( curRow );
|
||||||
|
m_grid_widths_dirty = true;
|
||||||
|
|
||||||
|
curRow = std::max( 0, curRow - 1 );
|
||||||
|
m_grid->MakeCellVisible( curRow, m_grid->GetGridCursorCol() );
|
||||||
|
m_grid->SetGridCursor( curRow, m_grid->GetGridCursorCol() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DIALOG_PLUGIN_OPTIONS::onGridCellChange( wxGridEvent& aEvent )
|
||||||
|
{
|
||||||
|
m_grid_widths_dirty = true;
|
||||||
|
|
||||||
|
aEvent.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DIALOG_PLUGIN_OPTIONS::onUpdateUI( wxUpdateUIEvent& )
|
||||||
|
{
|
||||||
|
if( m_grid_widths_dirty && !m_grid->IsCellEditControlShown() )
|
||||||
|
{
|
||||||
|
int width = m_grid->GetClientRect().GetWidth();
|
||||||
|
|
||||||
|
m_grid->AutoSizeColumn( 0 );
|
||||||
|
m_grid->SetColSize( 0, std::max( 72, m_grid->GetColSize( 0 ) ) );
|
||||||
|
|
||||||
|
m_grid->SetColSize( 1, std::max( 120, width - m_grid->GetColSize( 0 ) ) );
|
||||||
|
|
||||||
|
m_grid_widths_dirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DIALOG_PLUGIN_OPTIONS::onSize( wxSizeEvent& aEvent )
|
||||||
|
{
|
||||||
|
m_grid_widths_dirty = true;
|
||||||
|
|
||||||
|
aEvent.Skip();
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
|
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
|
||||||
// http://www.wxformbuilder.org/
|
// http://www.wxformbuilder.org/
|
||||||
//
|
//
|
||||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||||
|
@ -8,11 +8,11 @@
|
||||||
#include "widgets/std_bitmap_button.h"
|
#include "widgets/std_bitmap_button.h"
|
||||||
#include "widgets/wx_grid.h"
|
#include "widgets/wx_grid.h"
|
||||||
|
|
||||||
#include "dialog_fp_plugin_options_base.h"
|
#include "dialog_plugin_options_base.h"
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
DIALOG_FP_PLUGIN_OPTIONS_BASE::DIALOG_FP_PLUGIN_OPTIONS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
|
DIALOG_PLUGIN_OPTIONS_BASE::DIALOG_PLUGIN_OPTIONS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
|
||||||
{
|
{
|
||||||
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
||||||
|
|
||||||
|
@ -116,26 +116,26 @@ DIALOG_FP_PLUGIN_OPTIONS_BASE::DIALOG_FP_PLUGIN_OPTIONS_BASE( wxWindow* parent,
|
||||||
this->Centre( wxBOTH );
|
this->Centre( wxBOTH );
|
||||||
|
|
||||||
// Connect Events
|
// Connect Events
|
||||||
m_grid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onGridCellChange ), NULL, this );
|
m_grid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onGridCellChange ), NULL, this );
|
||||||
m_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onSize ), NULL, this );
|
m_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onSize ), NULL, this );
|
||||||
m_grid->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onUpdateUI ), NULL, this );
|
m_grid->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onUpdateUI ), NULL, this );
|
||||||
m_append_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendRow ), NULL, this );
|
m_append_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onAppendRow ), NULL, this );
|
||||||
m_delete_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this );
|
m_delete_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this );
|
||||||
m_listbox->Connect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onListBoxItemSelected ), NULL, this );
|
m_listbox->Connect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onListBoxItemSelected ), NULL, this );
|
||||||
m_listbox->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onListBoxItemDoubleClicked ), NULL, this );
|
m_listbox->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onListBoxItemDoubleClicked ), NULL, this );
|
||||||
m_append_choice_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendOption ), NULL, this );
|
m_append_choice_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onAppendOption ), NULL, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
DIALOG_FP_PLUGIN_OPTIONS_BASE::~DIALOG_FP_PLUGIN_OPTIONS_BASE()
|
DIALOG_PLUGIN_OPTIONS_BASE::~DIALOG_PLUGIN_OPTIONS_BASE()
|
||||||
{
|
{
|
||||||
// Disconnect Events
|
// Disconnect Events
|
||||||
m_grid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onGridCellChange ), NULL, this );
|
m_grid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onGridCellChange ), NULL, this );
|
||||||
m_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onSize ), NULL, this );
|
m_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onSize ), NULL, this );
|
||||||
m_grid->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onUpdateUI ), NULL, this );
|
m_grid->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onUpdateUI ), NULL, this );
|
||||||
m_append_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendRow ), NULL, this );
|
m_append_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onAppendRow ), NULL, this );
|
||||||
m_delete_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this );
|
m_delete_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this );
|
||||||
m_listbox->Disconnect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onListBoxItemSelected ), NULL, this );
|
m_listbox->Disconnect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onListBoxItemSelected ), NULL, this );
|
||||||
m_listbox->Disconnect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onListBoxItemDoubleClicked ), NULL, this );
|
m_listbox->Disconnect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onListBoxItemDoubleClicked ), NULL, this );
|
||||||
m_append_choice_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendOption ), NULL, this );
|
m_append_choice_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLUGIN_OPTIONS_BASE::onAppendOption ), NULL, this );
|
||||||
|
|
||||||
}
|
}
|
|
@ -11,13 +11,13 @@
|
||||||
<property name="embedded_files_path">res</property>
|
<property name="embedded_files_path">res</property>
|
||||||
<property name="encoding">UTF-8</property>
|
<property name="encoding">UTF-8</property>
|
||||||
<property name="event_generation">connect</property>
|
<property name="event_generation">connect</property>
|
||||||
<property name="file">dialog_fp_plugin_options_base</property>
|
<property name="file">dialog_plugin_options_base</property>
|
||||||
<property name="first_id">1000</property>
|
<property name="first_id">1000</property>
|
||||||
<property name="help_provider">none</property>
|
<property name="help_provider">none</property>
|
||||||
<property name="image_path_wrapper_function_name"></property>
|
<property name="image_path_wrapper_function_name"></property>
|
||||||
<property name="indent_with_spaces"></property>
|
<property name="indent_with_spaces"></property>
|
||||||
<property name="internationalize">1</property>
|
<property name="internationalize">1</property>
|
||||||
<property name="name">dialog_fp_plugin_options</property>
|
<property name="name">dialog_plugin_options</property>
|
||||||
<property name="namespace"></property>
|
<property name="namespace"></property>
|
||||||
<property name="path">.</property>
|
<property name="path">.</property>
|
||||||
<property name="precompiled_header"></property>
|
<property name="precompiled_header"></property>
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
<property name="id">wxID_ANY</property>
|
<property name="id">wxID_ANY</property>
|
||||||
<property name="maximum_size"></property>
|
<property name="maximum_size"></property>
|
||||||
<property name="minimum_size"></property>
|
<property name="minimum_size"></property>
|
||||||
<property name="name">DIALOG_FP_PLUGIN_OPTIONS_BASE</property>
|
<property name="name">DIALOG_PLUGIN_OPTIONS_BASE</property>
|
||||||
<property name="pos"></property>
|
<property name="pos"></property>
|
||||||
<property name="size">-1,-1</property>
|
<property name="size">-1,-1</property>
|
||||||
<property name="style">wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER</property>
|
<property name="style">wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER</property>
|
|
@ -1,5 +1,5 @@
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
|
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
|
||||||
// http://www.wxformbuilder.org/
|
// http://www.wxformbuilder.org/
|
||||||
//
|
//
|
||||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||||
|
@ -36,9 +36,9 @@ class WX_GRID;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
/// Class DIALOG_FP_PLUGIN_OPTIONS_BASE
|
/// Class DIALOG_PLUGIN_OPTIONS_BASE
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
class DIALOG_FP_PLUGIN_OPTIONS_BASE : public DIALOG_SHIM
|
class DIALOG_PLUGIN_OPTIONS_BASE : public DIALOG_SHIM
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -66,9 +66,9 @@ class DIALOG_FP_PLUGIN_OPTIONS_BASE : public DIALOG_SHIM
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DIALOG_FP_PLUGIN_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER );
|
DIALOG_PLUGIN_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER );
|
||||||
|
|
||||||
~DIALOG_FP_PLUGIN_OPTIONS_BASE();
|
~DIALOG_PLUGIN_OPTIONS_BASE();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "lib_table_grid_tricks.h"
|
#include "lib_table_grid_tricks.h"
|
||||||
#include "lib_table_grid.h"
|
#include "lib_table_grid.h"
|
||||||
|
|
||||||
|
|
||||||
LIB_TABLE_GRID_TRICKS::LIB_TABLE_GRID_TRICKS( WX_GRID* aGrid ) : GRID_TRICKS( aGrid )
|
LIB_TABLE_GRID_TRICKS::LIB_TABLE_GRID_TRICKS( WX_GRID* aGrid ) : GRID_TRICKS( aGrid )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -27,6 +28,14 @@ LIB_TABLE_GRID_TRICKS::LIB_TABLE_GRID_TRICKS( WX_GRID* aGrid ) : GRID_TRICKS( aG
|
||||||
|
|
||||||
void LIB_TABLE_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
|
void LIB_TABLE_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
|
||||||
{
|
{
|
||||||
|
if( m_grid->GetGridCursorCol() == COL_OPTIONS )
|
||||||
|
{
|
||||||
|
menu.Append( LIB_TABLE_GRID_TRICKS_OPTIONS_EDITOR,
|
||||||
|
_( "Options Editor..." ),
|
||||||
|
_( "Edit options" ) );
|
||||||
|
menu.AppendSeparator();
|
||||||
|
}
|
||||||
|
|
||||||
bool showActivate = false;
|
bool showActivate = false;
|
||||||
bool showDeactivate = false;
|
bool showDeactivate = false;
|
||||||
LIB_TABLE_GRID* tbl = static_cast<LIB_TABLE_GRID*>( m_grid->GetTable() );
|
LIB_TABLE_GRID* tbl = static_cast<LIB_TABLE_GRID*>( m_grid->GetTable() );
|
||||||
|
@ -73,8 +82,12 @@ void LIB_TABLE_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
|
||||||
int menu_id = event.GetId();
|
int menu_id = event.GetId();
|
||||||
LIB_TABLE_GRID* tbl = (LIB_TABLE_GRID*) m_grid->GetTable();
|
LIB_TABLE_GRID* tbl = (LIB_TABLE_GRID*) m_grid->GetTable();
|
||||||
|
|
||||||
if( menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED
|
if( menu_id == LIB_TABLE_GRID_TRICKS_OPTIONS_EDITOR )
|
||||||
|| menu_id == LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED )
|
{
|
||||||
|
optionsEditor( m_grid->GetGridCursorRow() );
|
||||||
|
}
|
||||||
|
else if( menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED
|
||||||
|
|| menu_id == LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED )
|
||||||
{
|
{
|
||||||
bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED;
|
bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED;
|
||||||
|
|
||||||
|
@ -95,3 +108,16 @@ void LIB_TABLE_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
|
||||||
GRID_TRICKS::doPopupSelection( event );
|
GRID_TRICKS::doPopupSelection( event );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool LIB_TABLE_GRID_TRICKS::handleDoubleClick( wxGridEvent& aEvent )
|
||||||
|
{
|
||||||
|
if( aEvent.GetCol() == COL_OPTIONS )
|
||||||
|
{
|
||||||
|
optionsEditor( aEvent.GetRow() );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,11 @@ public:
|
||||||
protected:
|
protected:
|
||||||
DIALOG_EDIT_LIBRARY_TABLES* m_dialog;
|
DIALOG_EDIT_LIBRARY_TABLES* m_dialog;
|
||||||
|
|
||||||
|
virtual void optionsEditor( int aRow )
|
||||||
|
{
|
||||||
|
DisplayError( m_dialog, _( "optionsEditor not implemented in SYMBOL_GRID_TRICKS" ) );
|
||||||
|
}
|
||||||
|
|
||||||
/// handle specialized clipboard text, with leading "(sym_lib_table" or
|
/// handle specialized clipboard text, with leading "(sym_lib_table" or
|
||||||
/// spreadsheet formatted text.
|
/// spreadsheet formatted text.
|
||||||
virtual void paste_text( const wxString& cb_text ) override
|
virtual void paste_text( const wxString& cb_text ) override
|
||||||
|
|
|
@ -432,7 +432,7 @@ public:
|
||||||
* <dd>This eventually is what shows up into the fp-lib-table "options"
|
* <dd>This eventually is what shows up into the fp-lib-table "options"
|
||||||
* field, possibly combined with others.</dd>
|
* field, possibly combined with others.</dd>
|
||||||
* <dt>internationalized description</dt>
|
* <dt>internationalized description</dt>
|
||||||
* <dd>The internationalized description is displayed in DIALOG_FP_SCH_PLUGIN_OPTIONS.
|
* <dd>The internationalized description is displayed in DIALOG_PLUGIN_OPTIONS.
|
||||||
* It may be multi-line and be quite explanatory of the option.</dd>
|
* It may be multi-line and be quite explanatory of the option.</dd>
|
||||||
* </dl>
|
* </dl>
|
||||||
* <br>
|
* <br>
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _DIALOG_PLUGIN_OPTIONS_H_
|
||||||
|
#define _DIALOG_PLUGIN_OPTIONS_H_
|
||||||
|
|
||||||
|
#include <dialog_plugin_options_base.h>
|
||||||
|
#include <string_utf8_map.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DIALOG_PLUGIN_OPTIONS
|
||||||
|
* is an options editor in the form of a two column name/value
|
||||||
|
* spreadsheet like (table) UI.
|
||||||
|
*/
|
||||||
|
class DIALOG_PLUGIN_OPTIONS : public DIALOG_PLUGIN_OPTIONS_BASE
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DIALOG_PLUGIN_OPTIONS( wxWindow* aParent, const wxString& aNickname,
|
||||||
|
const STRING_UTF8_MAP& aPluginOptions, const wxString& aFormattedOptions,
|
||||||
|
wxString* aResult );
|
||||||
|
|
||||||
|
~DIALOG_PLUGIN_OPTIONS() override;
|
||||||
|
|
||||||
|
bool TransferDataToWindow() override;
|
||||||
|
|
||||||
|
bool TransferDataFromWindow() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const wxString& m_callers_options;
|
||||||
|
wxString* m_result;
|
||||||
|
STRING_UTF8_MAP m_choices;
|
||||||
|
wxString m_initial_help;
|
||||||
|
bool m_grid_widths_dirty;
|
||||||
|
|
||||||
|
int appendRow();
|
||||||
|
|
||||||
|
void appendOption();
|
||||||
|
|
||||||
|
//-----<event handlers>------------------------------------------------------
|
||||||
|
void onListBoxItemSelected( wxCommandEvent& event ) override;
|
||||||
|
|
||||||
|
void onListBoxItemDoubleClicked( wxCommandEvent& event ) override;
|
||||||
|
|
||||||
|
void onAppendOption( wxCommandEvent& ) override;
|
||||||
|
|
||||||
|
void onAppendRow( wxCommandEvent& ) override;
|
||||||
|
|
||||||
|
void onDeleteRow( wxCommandEvent& ) override;
|
||||||
|
|
||||||
|
void onGridCellChange( wxGridEvent& aEvent ) override;
|
||||||
|
|
||||||
|
void onUpdateUI( wxUpdateUIEvent& ) override;
|
||||||
|
|
||||||
|
void onSize( wxSizeEvent& aEvent ) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _DIALOG_PLUGIN_OPTIONS_H_
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include <string_utils.h>
|
#include <string_utils.h>
|
||||||
#include <wx/grid.h>
|
#include <wx/grid.h>
|
||||||
|
|
||||||
|
class LIB_TABLE_GRID_TRICKS;
|
||||||
|
|
||||||
const wxColour COLOUR_ROW_ENABLED( 0, 0, 0 );
|
const wxColour COLOUR_ROW_ENABLED( 0, 0, 0 );
|
||||||
const wxColour COLOUR_ROW_DISABLED( 100, 100, 100 );
|
const wxColour COLOUR_ROW_DISABLED( 100, 100, 100 );
|
||||||
|
|
||||||
|
@ -47,6 +49,8 @@ enum COL_ORDER
|
||||||
*/
|
*/
|
||||||
class LIB_TABLE_GRID : public wxGridTableBase
|
class LIB_TABLE_GRID : public wxGridTableBase
|
||||||
{
|
{
|
||||||
|
friend class LIB_TABLE_GRID_TRICKS;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//-----<wxGridTableBase overloads>-------------------------------------------
|
//-----<wxGridTableBase overloads>-------------------------------------------
|
||||||
|
|
|
@ -25,12 +25,19 @@ class LIB_TABLE_GRID_TRICKS : public GRID_TRICKS
|
||||||
{
|
{
|
||||||
LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED = GRIDTRICKS_FIRST_CLIENT_ID,
|
LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED = GRIDTRICKS_FIRST_CLIENT_ID,
|
||||||
LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED,
|
LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED,
|
||||||
LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS
|
LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS,
|
||||||
|
LIB_TABLE_GRID_TRICKS_OPTIONS_EDITOR
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LIB_TABLE_GRID_TRICKS( WX_GRID* aGrid );
|
explicit LIB_TABLE_GRID_TRICKS( WX_GRID* aGrid );
|
||||||
|
|
||||||
|
virtual ~LIB_TABLE_GRID_TRICKS(){};
|
||||||
|
|
||||||
void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
|
void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
|
||||||
void doPopupSelection( wxCommandEvent& event ) override;
|
void doPopupSelection( wxCommandEvent& event ) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void optionsEditor( int aRow ) = 0;
|
||||||
|
bool handleDoubleClick( wxGridEvent& aEvent ) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -74,8 +74,6 @@ set( PCBNEW_DIALOGS
|
||||||
dialogs/dialog_find_base.cpp
|
dialogs/dialog_find_base.cpp
|
||||||
dialogs/dialog_footprint_wizard_list.cpp
|
dialogs/dialog_footprint_wizard_list.cpp
|
||||||
dialogs/dialog_footprint_wizard_list_base.cpp
|
dialogs/dialog_footprint_wizard_list_base.cpp
|
||||||
dialogs/dialog_fp_plugin_options.cpp
|
|
||||||
dialogs/dialog_fp_plugin_options_base.cpp
|
|
||||||
dialogs/dialog_gen_footprint_position.cpp
|
dialogs/dialog_gen_footprint_position.cpp
|
||||||
dialogs/dialog_gen_footprint_position_file_base.cpp
|
dialogs/dialog_gen_footprint_position_file_base.cpp
|
||||||
dialogs/dialog_gencad_export_options.cpp
|
dialogs/dialog_gencad_export_options.cpp
|
||||||
|
|
|
@ -1,304 +0,0 @@
|
||||||
/*
|
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
||||||
* Copyright (C) 2013 CERN
|
|
||||||
* Copyright (C) 2013-2022 KiCad Developers, see change_log.txt for contributors.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, you may find one here:
|
|
||||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
||||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
||||||
* or you may write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <invoke_pcb_dialog.h>
|
|
||||||
#include <dialog_fp_plugin_options_base.h>
|
|
||||||
#include <fp_lib_table.h>
|
|
||||||
#include <grid_tricks.h>
|
|
||||||
#include <widgets/wx_grid.h>
|
|
||||||
#include <widgets/std_bitmap_button.h>
|
|
||||||
#include <bitmaps.h>
|
|
||||||
#include <macros.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define INITIAL_HELP \
|
|
||||||
_( "Select an <b>Option Choice</b> in the listbox above, and then click the <b>Append Selected Option</b> button." )
|
|
||||||
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DIALOG_FP_PLUGIN_OPTIONS
|
|
||||||
* is an options editor in the form of a two column name/value
|
|
||||||
* spreadsheet like (table) UI. It takes hints from a pcbnew PLUGIN as to
|
|
||||||
* supported options.
|
|
||||||
*/
|
|
||||||
class DIALOG_FP_PLUGIN_OPTIONS : public DIALOG_FP_PLUGIN_OPTIONS_BASE
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
DIALOG_FP_PLUGIN_OPTIONS( wxWindow* aParent, const wxString& aNickname,
|
|
||||||
const wxString& aPluginType, const wxString& aOptions,
|
|
||||||
wxString* aResult ) :
|
|
||||||
DIALOG_FP_PLUGIN_OPTIONS_BASE( aParent ),
|
|
||||||
m_callers_options( aOptions ),
|
|
||||||
m_result( aResult ),
|
|
||||||
m_initial_help( INITIAL_HELP ),
|
|
||||||
m_grid_widths_dirty( true )
|
|
||||||
{
|
|
||||||
SetTitle( wxString::Format( _( "Options for Library '%s'" ), aNickname ) );
|
|
||||||
|
|
||||||
// Give a bit more room for combobox editors
|
|
||||||
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
|
|
||||||
|
|
||||||
m_grid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
|
|
||||||
|
|
||||||
// add Cut, Copy, and Paste to wxGrid
|
|
||||||
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
|
|
||||||
|
|
||||||
// Option Choices Panel:
|
|
||||||
|
|
||||||
IO_MGR::PCB_FILE_T pi_type = IO_MGR::EnumFromStr( aPluginType );
|
|
||||||
PLUGIN::RELEASER pi( IO_MGR::PluginFind( pi_type ) );
|
|
||||||
|
|
||||||
pi->FootprintLibOptions( &m_choices );
|
|
||||||
|
|
||||||
if( m_choices.size() )
|
|
||||||
{
|
|
||||||
unsigned int row = 0;
|
|
||||||
|
|
||||||
for( STRING_UTF8_MAP::const_iterator it = m_choices.begin(); it != m_choices.end();
|
|
||||||
++it, ++row )
|
|
||||||
{
|
|
||||||
wxString item = FROM_UTF8( it->first.c_str() );
|
|
||||||
|
|
||||||
m_listbox->InsertItems( 1, &item, row );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_html->SetPage( m_initial_help );
|
|
||||||
|
|
||||||
// Configure button logos
|
|
||||||
m_append_button->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
|
||||||
m_delete_button->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
|
||||||
|
|
||||||
// initial focus on the grid please.
|
|
||||||
SetInitialFocus( m_grid );
|
|
||||||
|
|
||||||
SetupStandardButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
~DIALOG_FP_PLUGIN_OPTIONS() override
|
|
||||||
{
|
|
||||||
// destroy GRID_TRICKS before m_grid.
|
|
||||||
m_grid->PopEventHandler( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TransferDataToWindow() override
|
|
||||||
{
|
|
||||||
if( !DIALOG_SHIM::TransferDataToWindow() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Fill the grid with existing aOptions
|
|
||||||
string options = TO_UTF8( m_callers_options );
|
|
||||||
|
|
||||||
STRING_UTF8_MAP* props = LIB_TABLE::ParseOptions( options );
|
|
||||||
|
|
||||||
if( props )
|
|
||||||
{
|
|
||||||
if( (int) props->size() > m_grid->GetNumberRows() )
|
|
||||||
m_grid->AppendRows( props->size() - m_grid->GetNumberRows() );
|
|
||||||
|
|
||||||
int row = 0;
|
|
||||||
|
|
||||||
for( STRING_UTF8_MAP::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, it->second );
|
|
||||||
}
|
|
||||||
|
|
||||||
delete props;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TransferDataFromWindow() override
|
|
||||||
{
|
|
||||||
if( !m_grid->CommitPendingChanges() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if( !DIALOG_SHIM::TransferDataFromWindow() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
STRING_UTF8_MAP 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() );
|
|
||||||
UTF8 value = m_grid->GetCellValue( row, 1 ).Trim( false ).Trim();
|
|
||||||
|
|
||||||
if( name.size() )
|
|
||||||
{
|
|
||||||
props[name] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*m_result = LIB_TABLE::FormatOptions( &props );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const wxString& m_callers_options;
|
|
||||||
wxString* m_result;
|
|
||||||
STRING_UTF8_MAP m_choices;
|
|
||||||
wxString m_initial_help;
|
|
||||||
bool m_grid_widths_dirty;
|
|
||||||
|
|
||||||
int appendRow()
|
|
||||||
{
|
|
||||||
int row = m_grid->GetNumberRows();
|
|
||||||
|
|
||||||
m_grid->AppendRows( 1 );
|
|
||||||
|
|
||||||
// wx documentation is wrong, SetGridCursor does not make visible.
|
|
||||||
m_grid->MakeCellVisible( row, 0 );
|
|
||||||
m_grid->SetGridCursor( row, 0 );
|
|
||||||
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
void appendOption()
|
|
||||||
{
|
|
||||||
int selected_row = m_listbox->GetSelection();
|
|
||||||
if( selected_row != wxNOT_FOUND )
|
|
||||||
{
|
|
||||||
wxString option = m_listbox->GetString( selected_row );
|
|
||||||
|
|
||||||
int row_count = m_grid->GetNumberRows();
|
|
||||||
int row;
|
|
||||||
|
|
||||||
for( row=0; row<row_count; ++row )
|
|
||||||
{
|
|
||||||
wxString col0 = m_grid->GetCellValue( row, 0 );
|
|
||||||
|
|
||||||
if( !col0 ) // empty col0
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( row == row_count )
|
|
||||||
row = appendRow();
|
|
||||||
|
|
||||||
m_grid->SetCellValue( row, 0, option );
|
|
||||||
m_grid_widths_dirty = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----<event handlers>------------------------------------------------------
|
|
||||||
|
|
||||||
void onListBoxItemSelected( wxCommandEvent& event ) override
|
|
||||||
{
|
|
||||||
// change the help text based on the m_listbox selection:
|
|
||||||
if( event.IsSelection() )
|
|
||||||
{
|
|
||||||
string option = TO_UTF8( event.GetString() );
|
|
||||||
UTF8 help_text;
|
|
||||||
|
|
||||||
if( m_choices.Value( option.c_str(), &help_text ) )
|
|
||||||
m_html->SetPage( help_text );
|
|
||||||
else
|
|
||||||
m_html->SetPage( m_initial_help );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void onListBoxItemDoubleClicked( wxCommandEvent& event ) override
|
|
||||||
{
|
|
||||||
appendOption();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onAppendOption( wxCommandEvent& ) override
|
|
||||||
{
|
|
||||||
if( !m_grid->CommitPendingChanges() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
appendOption();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onAppendRow( wxCommandEvent& ) override
|
|
||||||
{
|
|
||||||
if( !m_grid->CommitPendingChanges() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
appendRow();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onDeleteRow( wxCommandEvent& ) override
|
|
||||||
{
|
|
||||||
if( !m_grid->CommitPendingChanges() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
int curRow = m_grid->GetGridCursorRow();
|
|
||||||
|
|
||||||
m_grid->DeleteRows( curRow );
|
|
||||||
m_grid_widths_dirty = true;
|
|
||||||
|
|
||||||
curRow = std::max( 0, curRow - 1 );
|
|
||||||
m_grid->MakeCellVisible( curRow, m_grid->GetGridCursorCol() );
|
|
||||||
m_grid->SetGridCursor( curRow, m_grid->GetGridCursorCol() );
|
|
||||||
}
|
|
||||||
|
|
||||||
void onGridCellChange( wxGridEvent& aEvent ) override
|
|
||||||
{
|
|
||||||
m_grid_widths_dirty = true;
|
|
||||||
|
|
||||||
aEvent.Skip();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onUpdateUI( wxUpdateUIEvent& ) override
|
|
||||||
{
|
|
||||||
if( m_grid_widths_dirty && !m_grid->IsCellEditControlShown() )
|
|
||||||
{
|
|
||||||
int width = m_grid->GetClientRect().GetWidth();
|
|
||||||
|
|
||||||
m_grid->AutoSizeColumn( 0 );
|
|
||||||
m_grid->SetColSize( 0, std::max( 72, m_grid->GetColSize( 0 ) ) );
|
|
||||||
|
|
||||||
m_grid->SetColSize( 1, std::max( 120, width - m_grid->GetColSize( 0 ) ) );
|
|
||||||
|
|
||||||
m_grid_widths_dirty = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void onSize( wxSizeEvent& aEvent ) override
|
|
||||||
{
|
|
||||||
m_grid_widths_dirty = true;
|
|
||||||
|
|
||||||
aEvent.Skip();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void InvokePluginOptionsEditor( wxWindow* aCaller, const wxString& aNickname,
|
|
||||||
const wxString& aPluginType, const wxString& aOptions,
|
|
||||||
wxString* aResult )
|
|
||||||
{
|
|
||||||
DIALOG_FP_PLUGIN_OPTIONS dlg( aCaller, aNickname, aPluginType, aOptions, aResult );
|
|
||||||
|
|
||||||
dlg.ShowModal();
|
|
||||||
}
|
|
|
@ -56,6 +56,7 @@
|
||||||
#include <pcb_edit_frame.h>
|
#include <pcb_edit_frame.h>
|
||||||
#include <env_paths.h>
|
#include <env_paths.h>
|
||||||
#include <dialogs/dialog_edit_library_tables.h>
|
#include <dialogs/dialog_edit_library_tables.h>
|
||||||
|
#include <dialogs/dialog_plugin_options.h>
|
||||||
#include <footprint_viewer_frame.h>
|
#include <footprint_viewer_frame.h>
|
||||||
#include <footprint_edit_frame.h>
|
#include <footprint_edit_frame.h>
|
||||||
#include <kiway.h>
|
#include <kiway.h>
|
||||||
|
@ -251,8 +252,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define MYID_OPTIONS_EDITOR 15151
|
|
||||||
|
|
||||||
|
|
||||||
class FP_GRID_TRICKS : public LIB_TABLE_GRID_TRICKS
|
class FP_GRID_TRICKS : public LIB_TABLE_GRID_TRICKS
|
||||||
{
|
{
|
||||||
|
@ -264,7 +263,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
DIALOG_EDIT_LIBRARY_TABLES* m_dialog;
|
DIALOG_EDIT_LIBRARY_TABLES* m_dialog;
|
||||||
|
|
||||||
void optionsEditor( int aRow )
|
void optionsEditor( int aRow ) override
|
||||||
{
|
{
|
||||||
FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
|
FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
|
||||||
|
|
||||||
|
@ -273,9 +272,14 @@ protected:
|
||||||
LIB_TABLE_ROW* row = tbl->at( (size_t) aRow );
|
LIB_TABLE_ROW* row = tbl->at( (size_t) aRow );
|
||||||
const wxString& options = row->GetOptions();
|
const wxString& options = row->GetOptions();
|
||||||
wxString result = options;
|
wxString result = options;
|
||||||
|
STRING_UTF8_MAP choices;
|
||||||
|
|
||||||
InvokePluginOptionsEditor( m_dialog, row->GetNickName(), row->GetType(), options,
|
IO_MGR::PCB_FILE_T pi_type = IO_MGR::EnumFromStr( row->GetType() );
|
||||||
&result );
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( pi_type ) );
|
||||||
|
pi->FootprintLibOptions( &choices );
|
||||||
|
|
||||||
|
DIALOG_PLUGIN_OPTIONS dlg( m_dialog, row->GetNickName(), choices, options, &result );
|
||||||
|
dlg.ShowModal();
|
||||||
|
|
||||||
if( options != result )
|
if( options != result )
|
||||||
{
|
{
|
||||||
|
@ -285,36 +289,6 @@ protected:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handleDoubleClick( wxGridEvent& aEvent ) override
|
|
||||||
{
|
|
||||||
if( aEvent.GetCol() == COL_OPTIONS )
|
|
||||||
{
|
|
||||||
optionsEditor( aEvent.GetRow() );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override
|
|
||||||
{
|
|
||||||
if( m_grid->GetGridCursorCol() == COL_OPTIONS )
|
|
||||||
{
|
|
||||||
menu.Append( MYID_OPTIONS_EDITOR, _( "Options Editor..." ), _( "Edit options" ) );
|
|
||||||
menu.AppendSeparator();
|
|
||||||
}
|
|
||||||
|
|
||||||
LIB_TABLE_GRID_TRICKS::showPopupMenu( menu, aEvent );
|
|
||||||
}
|
|
||||||
|
|
||||||
void doPopupSelection( wxCommandEvent& event ) override
|
|
||||||
{
|
|
||||||
if( event.GetId() == MYID_OPTIONS_EDITOR )
|
|
||||||
optionsEditor( m_grid->GetGridCursorRow() );
|
|
||||||
else
|
|
||||||
LIB_TABLE_GRID_TRICKS::doPopupSelection( event );
|
|
||||||
}
|
|
||||||
|
|
||||||
/// handle specialized clipboard text, with leading "(fp_lib_table", OR
|
/// handle specialized clipboard text, with leading "(fp_lib_table", OR
|
||||||
/// spreadsheet formatted text.
|
/// spreadsheet formatted text.
|
||||||
void paste_text( const wxString& cb_text ) override
|
void paste_text( const wxString& cb_text ) override
|
||||||
|
|
|
@ -72,20 +72,6 @@ class KIWAY;
|
||||||
*/
|
*/
|
||||||
void InvokePcbLibTableEditor( KIWAY* aKiway, wxWindow* aCaller );
|
void InvokePcbLibTableEditor( KIWAY* aKiway, wxWindow* aCaller );
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function InvokePluginOptionsEditor
|
|
||||||
* calls DIALOG_FP_PLUGIN_OPTIONS dialog so that plugin options set can be edited.
|
|
||||||
*
|
|
||||||
* @param aCaller is the wxTopLevelWindow which is invoking the dialog.
|
|
||||||
* @param aNickname is the footprint library whose options are being edited.
|
|
||||||
* @param aPluginType is something that will pass through IO_MGR::EnumFromStr().
|
|
||||||
* @param aOptions is the options string on calling into this function.
|
|
||||||
* @param aResult is where to put the result of the editing.
|
|
||||||
*/
|
|
||||||
void InvokePluginOptionsEditor( wxWindow* aCaller, const wxString& aNickname,
|
|
||||||
const wxString& aPluginType, const wxString& aOptions, wxString* aResult );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function InvokeExportSVG
|
* Function InvokeExportSVG
|
||||||
* shows the Export SVG dialog
|
* shows the Export SVG dialog
|
||||||
|
|
|
@ -538,7 +538,7 @@ public:
|
||||||
* <dd>This eventually is what shows up into the fp-lib-table "options"
|
* <dd>This eventually is what shows up into the fp-lib-table "options"
|
||||||
* field, possibly combined with others.</dd>
|
* field, possibly combined with others.</dd>
|
||||||
* <dt>internationalized description</dt>
|
* <dt>internationalized description</dt>
|
||||||
* <dd>The internationalized description is displayed in DIALOG_FP_PLUGIN_OPTIONS.
|
* <dd>The internationalized description is displayed in DIALOG_PLUGIN_OPTIONS.
|
||||||
* It may be multi-line and be quite explanatory of the option.</dd>
|
* It may be multi-line and be quite explanatory of the option.</dd>
|
||||||
* </dl>
|
* </dl>
|
||||||
* <br>
|
* <br>
|
||||||
|
|
Loading…
Reference in New Issue