Move the symbol editor to the new filedlg customize
This commit is contained in:
parent
cb44d97ed4
commit
08dbc3a53c
|
@ -44,108 +44,14 @@
|
|||
#include <wx/filedlg.h>
|
||||
#include <wx/log.h>
|
||||
#include <string_utils.h>
|
||||
#include "symbol_saveas_type.h"
|
||||
|
||||
|
||||
static int g_option = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Helper control to inquire user what to do on library save as operation.
|
||||
*/
|
||||
class SAVE_AS_HELPER : public wxPanel
|
||||
{
|
||||
public:
|
||||
SAVE_AS_HELPER( wxWindow* aParent ) :
|
||||
wxPanel( aParent )
|
||||
{
|
||||
m_simpleSaveAs = new wxRadioButton( this, wxID_ANY, _( "Do not update library tables" ),
|
||||
wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
|
||||
m_simpleSaveAs->SetToolTip( _( "Do not perform any additional operations after saving "
|
||||
"library." ) );
|
||||
m_replaceTableEntry = new wxRadioButton( this, wxID_ANY,
|
||||
_( "Update existing library table entry" ) );
|
||||
m_replaceTableEntry->SetToolTip( _( "Update symbol library table entry to point to new "
|
||||
"library.\n\n"
|
||||
"The original library will no longer be available "
|
||||
"for use." ) );
|
||||
m_addGlobalTableEntry = new wxRadioButton( this, wxID_ANY,
|
||||
_( "Add new global library table entry" ) );
|
||||
m_addGlobalTableEntry->SetToolTip( _( "Add new entry to the global symbol library table."
|
||||
"\n\nThe symbol library table nickname is suffixed "
|
||||
"with\nan integer to prevent duplicate table "
|
||||
"entries." ) );
|
||||
m_addProjectTableEntry = new wxRadioButton( this, wxID_ANY,
|
||||
_( "Add new project library table entry" ) );
|
||||
m_addProjectTableEntry->SetToolTip( _( "Add new entry to the project symbol library table."
|
||||
"\n\nThe symbol library table nickname is suffixed "
|
||||
"with\nan integer to prevent duplicate table "
|
||||
"entries." ) );
|
||||
|
||||
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
||||
sizer->Add( m_simpleSaveAs, 0, wxLEFT | wxRIGHT | wxTOP, 5 );
|
||||
sizer->Add( m_replaceTableEntry, 0, wxLEFT | wxRIGHT | wxTOP, 5 );
|
||||
sizer->Add( m_addGlobalTableEntry, 0, wxLEFT | wxRIGHT | wxTOP, 5 );
|
||||
sizer->Add( m_addProjectTableEntry, 0, wxLEFT | wxRIGHT | wxTOP | wxBOTTOM, 5 );
|
||||
|
||||
SetSizerAndFit( sizer );
|
||||
|
||||
SetOption( static_cast<SAH_TYPE>( g_option ) );
|
||||
}
|
||||
|
||||
~SAVE_AS_HELPER()
|
||||
{
|
||||
g_option = GetOption();
|
||||
}
|
||||
|
||||
enum SAH_TYPE
|
||||
{
|
||||
NORMAL_SAVE_AS = 0,
|
||||
REPLACE_TABLE_ENTRY,
|
||||
ADD_GLOBAL_TABLE_ENTRY,
|
||||
ADD_PROJECT_TABLE_ENTRY
|
||||
};
|
||||
|
||||
void SetOption( SAH_TYPE aOption )
|
||||
{
|
||||
m_simpleSaveAs->SetValue( aOption == NORMAL_SAVE_AS );
|
||||
m_replaceTableEntry->SetValue( aOption == REPLACE_TABLE_ENTRY );
|
||||
m_addGlobalTableEntry->SetValue( aOption == ADD_GLOBAL_TABLE_ENTRY );
|
||||
m_addProjectTableEntry->SetValue( aOption == ADD_PROJECT_TABLE_ENTRY );
|
||||
}
|
||||
|
||||
SAH_TYPE GetOption() const
|
||||
{
|
||||
if( m_replaceTableEntry->GetValue() )
|
||||
return SAH_TYPE::REPLACE_TABLE_ENTRY;
|
||||
else if( m_addGlobalTableEntry->GetValue() )
|
||||
return ADD_GLOBAL_TABLE_ENTRY;
|
||||
else if( m_addProjectTableEntry->GetValue() )
|
||||
return ADD_PROJECT_TABLE_ENTRY;
|
||||
else
|
||||
return SAH_TYPE::NORMAL_SAVE_AS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new panel to add to a wxFileDialog object.
|
||||
*
|
||||
* The caller owns the created object and is responsible for deleting it.
|
||||
*
|
||||
* @param aParent is the parent window that will own the created object.
|
||||
* @return the newly created panel to add to the wxFileDialog.
|
||||
*/
|
||||
static wxWindow* Create( wxWindow* aParent )
|
||||
{
|
||||
wxCHECK( aParent, nullptr );
|
||||
|
||||
return new SAVE_AS_HELPER( aParent );
|
||||
}
|
||||
|
||||
private:
|
||||
wxRadioButton* m_simpleSaveAs;
|
||||
wxRadioButton* m_replaceTableEntry;
|
||||
wxRadioButton* m_addGlobalTableEntry;
|
||||
wxRadioButton* m_addProjectTableEntry;
|
||||
};
|
||||
#if wxCHECK_VERSION( 3, 1, 7 )
|
||||
#include <widgets/symbol_filedlg_save_as.h>
|
||||
#else
|
||||
#include <widgets/symbol_legacyfiledlg_save_as.h>
|
||||
SYMBOL_SAVEAS_TYPE SYMBOL_LEGACYFILEDLG_SAVE_AS::m_option = SYMBOL_SAVEAS_TYPE::NORMAL_SAVE_AS;
|
||||
#endif
|
||||
|
||||
|
||||
void SYMBOL_EDIT_FRAME::updateTitle()
|
||||
|
@ -1102,7 +1008,7 @@ bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
|
|||
{
|
||||
wxFileName fn;
|
||||
wxString msg;
|
||||
SAVE_AS_HELPER::SAH_TYPE type = SAVE_AS_HELPER::SAH_TYPE::NORMAL_SAVE_AS;
|
||||
SYMBOL_SAVEAS_TYPE type = SYMBOL_SAVEAS_TYPE::NORMAL_SAVE_AS;
|
||||
SCH_IO_MGR::SCH_FILE_T fileType = SCH_IO_MGR::SCH_FILE_T::SCH_KICAD;
|
||||
PROJECT& prj = Prj();
|
||||
|
||||
|
@ -1133,7 +1039,12 @@ bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
|
|||
default_path, fn.GetFullName(), wildcards,
|
||||
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
||||
|
||||
dlg.SetExtraControlCreator( &SAVE_AS_HELPER::Create );
|
||||
#if wxCHECK_VERSION( 3, 1, 7 )
|
||||
SYMBOL_FILEDLG_SAVE_AS saveAsHook( type );
|
||||
dlg.SetCustomizeHook( saveAsHook );
|
||||
#else
|
||||
dlg.SetExtraControlCreator( &SYMBOL_LEGACYFILEDLG_SAVE_AS::Create );
|
||||
#endif
|
||||
|
||||
if( dlg.ShowModal() == wxID_CANCEL )
|
||||
return false;
|
||||
|
@ -1145,10 +1056,15 @@ bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
|
|||
if( fn.GetExt().IsEmpty() )
|
||||
fn.SetExt( KiCadSymbolLibFileExtension );
|
||||
|
||||
const SAVE_AS_HELPER* sah = dynamic_cast<const SAVE_AS_HELPER*>( dlg.GetExtraControl() );
|
||||
#if wxCHECK_VERSION( 3, 1, 7 )
|
||||
type = saveAsHook.GetOption();
|
||||
#else
|
||||
const SYMBOL_LEGACYFILEDLG_SAVE_AS* sah =
|
||||
dynamic_cast<const SYMBOL_LEGACYFILEDLG_SAVE_AS*>( dlg.GetExtraControl() );
|
||||
wxCHECK( sah, false );
|
||||
|
||||
type = sah->GetOption();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1186,16 +1102,16 @@ bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
|
|||
|
||||
switch( type )
|
||||
{
|
||||
case SAVE_AS_HELPER::SAH_TYPE::REPLACE_TABLE_ENTRY:
|
||||
case SYMBOL_SAVEAS_TYPE::REPLACE_TABLE_ENTRY:
|
||||
resyncLibTree = replaceLibTableEntry( originalLibNickname, fn.GetFullPath() );
|
||||
forceRefresh = originalLibNickname;
|
||||
break;
|
||||
|
||||
case SAVE_AS_HELPER::SAH_TYPE::ADD_GLOBAL_TABLE_ENTRY:
|
||||
case SYMBOL_SAVEAS_TYPE::ADD_GLOBAL_TABLE_ENTRY:
|
||||
resyncLibTree = addLibTableEntry( fn.GetFullPath() );
|
||||
break;
|
||||
|
||||
case SAVE_AS_HELPER::SAH_TYPE::ADD_PROJECT_TABLE_ENTRY:
|
||||
case SYMBOL_SAVEAS_TYPE::ADD_PROJECT_TABLE_ENTRY:
|
||||
resyncLibTree = addLibTableEntry( fn.GetFullPath(), PROJECT_LIB_TABLE );
|
||||
break;
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 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 SYMBOL_SAVEAS_TYPE_H
|
||||
#define SYMBOL_SAVEAS_TYPE_H
|
||||
|
||||
enum class SYMBOL_SAVEAS_TYPE
|
||||
{
|
||||
NORMAL_SAVE_AS = 0,
|
||||
REPLACE_TABLE_ENTRY,
|
||||
ADD_GLOBAL_TABLE_ENTRY,
|
||||
ADD_PROJECT_TABLE_ENTRY
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 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 SYMBOL_FILEDLG_SAVE_AS_
|
||||
#define SYMBOL_FILEDLG_SAVE_AS_
|
||||
|
||||
#include <symbol_editor/symbol_saveas_type.h>
|
||||
#include <wx/filedlgcustomize.h>
|
||||
|
||||
class SYMBOL_FILEDLG_SAVE_AS : public wxFileDialogCustomizeHook
|
||||
{
|
||||
public:
|
||||
SYMBOL_FILEDLG_SAVE_AS( SYMBOL_SAVEAS_TYPE aOption ) : m_option( aOption ){};
|
||||
|
||||
virtual void AddCustomControls( wxFileDialogCustomize& customizer ) override
|
||||
{
|
||||
m_simpleSaveAs = customizer.AddRadioButton( _( "Do not update library tables" ) );
|
||||
m_replaceTableEntry =
|
||||
customizer.AddRadioButton( _( "Update existing library table entry" ) );
|
||||
m_addGlobalTableEntry =
|
||||
customizer.AddRadioButton( _( "Add new global library table entry" ) );
|
||||
m_addProjectTableEntry =
|
||||
customizer.AddRadioButton( _( "Add new project library table entry" ) );
|
||||
|
||||
// Note, due to windows api, wx does not actually support calling SetValue( false ) (it asserts)
|
||||
if( m_option == SYMBOL_SAVEAS_TYPE::NORMAL_SAVE_AS )
|
||||
m_simpleSaveAs->SetValue( true );
|
||||
|
||||
if( m_option == SYMBOL_SAVEAS_TYPE::REPLACE_TABLE_ENTRY )
|
||||
m_replaceTableEntry->SetValue( true );
|
||||
|
||||
if( m_option == SYMBOL_SAVEAS_TYPE::ADD_GLOBAL_TABLE_ENTRY )
|
||||
m_addGlobalTableEntry->SetValue( true );
|
||||
|
||||
if( m_option == SYMBOL_SAVEAS_TYPE::ADD_PROJECT_TABLE_ENTRY )
|
||||
m_addProjectTableEntry->SetValue( true );
|
||||
}
|
||||
|
||||
virtual void TransferDataFromCustomControls() override
|
||||
{
|
||||
if( m_replaceTableEntry->GetValue() )
|
||||
m_option = SYMBOL_SAVEAS_TYPE::REPLACE_TABLE_ENTRY;
|
||||
else if( m_addGlobalTableEntry->GetValue() )
|
||||
m_option = SYMBOL_SAVEAS_TYPE::ADD_GLOBAL_TABLE_ENTRY;
|
||||
else if( m_addProjectTableEntry->GetValue() )
|
||||
m_option = SYMBOL_SAVEAS_TYPE::ADD_PROJECT_TABLE_ENTRY;
|
||||
else
|
||||
m_option = SYMBOL_SAVEAS_TYPE::NORMAL_SAVE_AS;
|
||||
}
|
||||
|
||||
SYMBOL_SAVEAS_TYPE GetOption() const { return m_option; }
|
||||
|
||||
private:
|
||||
SYMBOL_SAVEAS_TYPE m_option;
|
||||
|
||||
wxFileDialogRadioButton* m_simpleSaveAs;
|
||||
wxFileDialogRadioButton* m_replaceTableEntry;
|
||||
wxFileDialogRadioButton* m_addGlobalTableEntry;
|
||||
wxFileDialogRadioButton* m_addProjectTableEntry;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS( SYMBOL_FILEDLG_SAVE_AS );
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 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 SYMBOL_LEGACYFILEDLG_SAVE_AS_
|
||||
#define SYMBOL_LEGACYFILEDLG_SAVE_AS_
|
||||
|
||||
#include <symbol_editor/symbol_saveas_type.h>
|
||||
|
||||
#include <wx/panel.h>
|
||||
#include <wx/radiobut.h>
|
||||
#include <wx/sizer.h>
|
||||
|
||||
/**
|
||||
* Helper control to inquire user what to do on library save as operation.
|
||||
*/
|
||||
class SYMBOL_LEGACYFILEDLG_SAVE_AS : public wxPanel
|
||||
{
|
||||
public:
|
||||
SYMBOL_LEGACYFILEDLG_SAVE_AS( wxWindow* aParent ) : wxPanel( aParent )
|
||||
{
|
||||
m_simpleSaveAs = new wxRadioButton( this, wxID_ANY, _( "Do not update library tables" ),
|
||||
wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
|
||||
m_simpleSaveAs->SetToolTip( _( "Do not perform any additional operations after saving "
|
||||
"library." ) );
|
||||
m_replaceTableEntry =
|
||||
new wxRadioButton( this, wxID_ANY, _( "Update existing library table entry" ) );
|
||||
m_replaceTableEntry->SetToolTip( _( "Update symbol library table entry to point to new "
|
||||
"library.\n\n"
|
||||
"The original library will no longer be available "
|
||||
"for use." ) );
|
||||
m_addGlobalTableEntry =
|
||||
new wxRadioButton( this, wxID_ANY, _( "Add new global library table entry" ) );
|
||||
m_addGlobalTableEntry->SetToolTip( _( "Add new entry to the global symbol library table."
|
||||
"\n\nThe symbol library table nickname is suffixed "
|
||||
"with\nan integer to prevent duplicate table "
|
||||
"entries." ) );
|
||||
m_addProjectTableEntry =
|
||||
new wxRadioButton( this, wxID_ANY, _( "Add new project library table entry" ) );
|
||||
m_addProjectTableEntry->SetToolTip( _( "Add new entry to the project symbol library table."
|
||||
"\n\nThe symbol library table nickname is suffixed "
|
||||
"with\nan integer to prevent duplicate table "
|
||||
"entries." ) );
|
||||
|
||||
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
||||
sizer->Add( m_simpleSaveAs, 0, wxLEFT | wxRIGHT | wxTOP, 5 );
|
||||
sizer->Add( m_replaceTableEntry, 0, wxLEFT | wxRIGHT | wxTOP, 5 );
|
||||
sizer->Add( m_addGlobalTableEntry, 0, wxLEFT | wxRIGHT | wxTOP, 5 );
|
||||
sizer->Add( m_addProjectTableEntry, 0, wxLEFT | wxRIGHT | wxTOP | wxBOTTOM, 5 );
|
||||
|
||||
SetSizerAndFit( sizer );
|
||||
|
||||
SetOption( m_option );
|
||||
}
|
||||
|
||||
~SYMBOL_LEGACYFILEDLG_SAVE_AS() { m_option = GetOption(); }
|
||||
|
||||
void SetOption( SYMBOL_SAVEAS_TYPE aOption )
|
||||
{
|
||||
m_simpleSaveAs->SetValue( aOption == SYMBOL_SAVEAS_TYPE::NORMAL_SAVE_AS );
|
||||
m_replaceTableEntry->SetValue( aOption == SYMBOL_SAVEAS_TYPE::REPLACE_TABLE_ENTRY );
|
||||
m_addGlobalTableEntry->SetValue( aOption == SYMBOL_SAVEAS_TYPE::ADD_GLOBAL_TABLE_ENTRY );
|
||||
m_addProjectTableEntry->SetValue( aOption == SYMBOL_SAVEAS_TYPE::ADD_PROJECT_TABLE_ENTRY );
|
||||
}
|
||||
|
||||
SYMBOL_SAVEAS_TYPE GetOption() const
|
||||
{
|
||||
if( m_replaceTableEntry->GetValue() )
|
||||
return SYMBOL_SAVEAS_TYPE::REPLACE_TABLE_ENTRY;
|
||||
else if( m_addGlobalTableEntry->GetValue() )
|
||||
return SYMBOL_SAVEAS_TYPE::ADD_GLOBAL_TABLE_ENTRY;
|
||||
else if( m_addProjectTableEntry->GetValue() )
|
||||
return SYMBOL_SAVEAS_TYPE::ADD_PROJECT_TABLE_ENTRY;
|
||||
else
|
||||
return SYMBOL_SAVEAS_TYPE::NORMAL_SAVE_AS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new panel to add to a wxFileDialog object.
|
||||
*
|
||||
* The caller owns the created object and is responsible for deleting it.
|
||||
*
|
||||
* @param aParent is the parent window that will own the created object.
|
||||
* @return the newly created panel to add to the wxFileDialog.
|
||||
*/
|
||||
static wxWindow* Create( wxWindow* aParent )
|
||||
{
|
||||
wxCHECK( aParent, nullptr );
|
||||
|
||||
return new SYMBOL_LEGACYFILEDLG_SAVE_AS( aParent );
|
||||
}
|
||||
|
||||
private:
|
||||
static SYMBOL_SAVEAS_TYPE m_option;
|
||||
|
||||
wxRadioButton* m_simpleSaveAs;
|
||||
wxRadioButton* m_replaceTableEntry;
|
||||
wxRadioButton* m_addGlobalTableEntry;
|
||||
wxRadioButton* m_addProjectTableEntry;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue