2017-01-22 09:05:46 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-01-22 09:05:46 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-01-30 14:34:09 +00:00
|
|
|
* @file action_plugin.cpp
|
2017-01-22 09:05:46 +00:00
|
|
|
* @brief Class ACTION_PLUGIN and ACTION_PLUGINS
|
|
|
|
*/
|
|
|
|
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
|
|
|
|
2018-01-30 14:34:09 +00:00
|
|
|
#include "action_plugin.h"
|
2021-03-22 04:50:42 +00:00
|
|
|
#include "bitmaps.h"
|
|
|
|
#include "bitmap_store.h"
|
2021-08-14 19:08:56 +00:00
|
|
|
#include <pgm_base.h>
|
2017-01-22 09:05:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
ACTION_PLUGIN::~ACTION_PLUGIN()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ACTION_PLUGIN::register_action()
|
|
|
|
{
|
|
|
|
ACTION_PLUGINS::register_action( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-22 19:23:00 +00:00
|
|
|
std::vector<ACTION_PLUGIN*> ACTION_PLUGINS::m_actionsList;
|
2017-01-22 09:05:46 +00:00
|
|
|
|
|
|
|
|
2018-03-06 08:28:57 +00:00
|
|
|
bool ACTION_PLUGINS::m_actionRunning = false;
|
|
|
|
|
|
|
|
|
2017-01-22 09:05:46 +00:00
|
|
|
ACTION_PLUGIN* ACTION_PLUGINS::GetAction( int aIndex )
|
|
|
|
{
|
2017-01-22 19:23:00 +00:00
|
|
|
return m_actionsList[aIndex];
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-22 19:23:00 +00:00
|
|
|
ACTION_PLUGIN* ACTION_PLUGINS::GetActionByMenu( int aMenu )
|
2017-01-22 09:05:46 +00:00
|
|
|
{
|
|
|
|
int max = GetActionsCount();
|
|
|
|
|
2017-01-22 19:23:00 +00:00
|
|
|
for( int i = 0; i < max; i++ )
|
2017-01-22 09:05:46 +00:00
|
|
|
{
|
2017-01-22 19:23:00 +00:00
|
|
|
if( m_actionsList[i]->m_actionMenuId == aMenu )
|
|
|
|
return m_actionsList[i];
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ACTION_PLUGINS::SetActionMenu( int aIndex, int idMenu )
|
|
|
|
{
|
2017-01-22 19:23:00 +00:00
|
|
|
m_actionsList[aIndex]->m_actionMenuId = idMenu;
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
ACTION_PLUGIN* ACTION_PLUGINS::GetActionByButton( int aButton )
|
2017-01-22 09:05:46 +00:00
|
|
|
{
|
2018-08-15 09:26:32 +00:00
|
|
|
int max = GetActionsCount();
|
|
|
|
|
|
|
|
for( int i = 0; i < max; i++ )
|
|
|
|
{
|
|
|
|
if( m_actionsList[i]->m_actionButtonId == aButton )
|
|
|
|
return m_actionsList[i];
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ACTION_PLUGINS::SetActionButton( ACTION_PLUGIN* aAction, int idButton )
|
|
|
|
{
|
|
|
|
aAction->m_actionButtonId = idButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ACTION_PLUGIN* ACTION_PLUGINS::GetActionByPath(const wxString& aPath)
|
|
|
|
{
|
|
|
|
for( int i = 0; i < GetActionsCount() ; i++ )
|
|
|
|
{
|
|
|
|
if( m_actionsList[i]->GetPluginPath() == aPath)
|
|
|
|
{
|
|
|
|
return m_actionsList[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
ACTION_PLUGIN* ACTION_PLUGINS::GetAction( const wxString& aName )
|
2017-01-22 09:05:46 +00:00
|
|
|
{
|
|
|
|
int max = GetActionsCount();
|
|
|
|
|
|
|
|
for( int i = 0; i<max; i++ )
|
|
|
|
{
|
|
|
|
ACTION_PLUGIN* action = GetAction( i );
|
|
|
|
|
|
|
|
wxString name = action->GetName();
|
|
|
|
|
|
|
|
if( name.Cmp( aName )==0 )
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ACTION_PLUGINS::GetActionsCount()
|
|
|
|
{
|
2017-01-22 19:23:00 +00:00
|
|
|
return m_actionsList.size();
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ACTION_PLUGINS::register_action( ACTION_PLUGIN* aAction )
|
|
|
|
{
|
|
|
|
// Search for this entry do not register twice this action:
|
|
|
|
for( int ii = 0; ii < GetActionsCount(); ii++ )
|
|
|
|
{
|
|
|
|
if( aAction == GetAction( ii ) ) // Already registered
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search for a action with the same name, and remove it if found
|
|
|
|
for( int ii = 0; ii < GetActionsCount(); ii++ )
|
|
|
|
{
|
|
|
|
ACTION_PLUGIN* action = GetAction( ii );
|
|
|
|
|
|
|
|
if( action->GetName() == aAction->GetName() )
|
|
|
|
{
|
2017-01-22 19:23:00 +00:00
|
|
|
m_actionsList.erase( m_actionsList.begin() + ii );
|
2017-01-22 09:05:46 +00:00
|
|
|
|
|
|
|
delete action;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-14 19:08:56 +00:00
|
|
|
wxASSERT( PgmOrNull() ); // PgmOrNull() returning nullptr should never happen,
|
|
|
|
// but it sometimes happens on msys2 build
|
2021-03-24 22:11:32 +00:00
|
|
|
|
2021-08-14 19:08:56 +00:00
|
|
|
if( PgmOrNull() ) // Hack for msys2. Must be removed when the root cause is fixed
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2021-08-14 19:08:56 +00:00
|
|
|
// Load icon if supplied
|
|
|
|
wxString icon_file_name = aAction->GetIconFileName( GetBitmapStore()->IsDarkTheme() );
|
2018-08-15 09:26:32 +00:00
|
|
|
|
2021-08-14 19:08:56 +00:00
|
|
|
if( !icon_file_name.IsEmpty() )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2021-08-14 19:08:56 +00:00
|
|
|
{
|
|
|
|
wxLogNull eat_errors;
|
|
|
|
aAction->iconBitmap.LoadFile( icon_file_name, wxBITMAP_TYPE_PNG );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !aAction->iconBitmap.IsOk() )
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
wxLogVerbose( wxT( "Failed to load icon " ) + icon_file_name + wxT( " for action plugin " ) );
|
2021-08-14 19:08:56 +00:00
|
|
|
}
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-22 19:23:00 +00:00
|
|
|
m_actionsList.push_back( aAction );
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ACTION_PLUGINS::deregister_object( void* aObject )
|
|
|
|
{
|
|
|
|
int max = GetActionsCount();
|
|
|
|
|
|
|
|
for( int i = 0; i<max; i++ )
|
|
|
|
{
|
|
|
|
ACTION_PLUGIN* action = GetAction( i );
|
|
|
|
|
|
|
|
if( action->GetObject() == aObject )
|
|
|
|
{
|
2017-01-22 19:23:00 +00:00
|
|
|
m_actionsList.erase( m_actionsList.begin() + i );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-01-22 19:23:00 +00:00
|
|
|
//m_actionsListMenu.erase( m_actionsListMenu.begin() + i );
|
2017-01-22 09:05:46 +00:00
|
|
|
delete action;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-06 08:28:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool ACTION_PLUGINS::IsActionRunning()
|
|
|
|
{
|
|
|
|
return ACTION_PLUGINS::m_actionRunning;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ACTION_PLUGINS::SetActionRunning( bool aRunning )
|
|
|
|
{
|
|
|
|
ACTION_PLUGINS::m_actionRunning = aRunning;
|
|
|
|
}
|
2021-02-20 16:19:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ACTION_PLUGINS::UnloadAll()
|
|
|
|
{
|
|
|
|
for( ACTION_PLUGIN* plugin : m_actionsList )
|
|
|
|
delete plugin;
|
|
|
|
|
|
|
|
m_actionsList.clear();
|
|
|
|
}
|