2017-01-22 09:05:46 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-05-25 07:05:35 +00:00
|
|
|
* Copyright (C) 2017 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
|
|
|
|
*/
|
|
|
|
|
2018-01-30 14:34:09 +00:00
|
|
|
#include "action_plugin.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
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
// Load icon if supplied
|
2020-11-24 22:16:41 +00:00
|
|
|
if( !aAction->GetIconFileName().IsEmpty() )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
wxLogNull eat_errors;
|
|
|
|
aAction->iconBitmap.LoadFile( aAction->GetIconFileName() , wxBITMAP_TYPE_PNG );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !aAction->iconBitmap.IsOk() )
|
|
|
|
{
|
|
|
|
wxLogVerbose( "Failed to load icon " + aAction->GetIconFileName() + " for action plugin " );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
//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;
|
|
|
|
}
|