/* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2024 Jon Evans * Copyright (C) 2024 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 . */ #include #include #include #include #include #include /** * Flag to enable debug output related to the API plugin system * * Use "KICAD_API" to enable. * * @ingroup traceApi */ extern const KICOMMON_API wxChar* const traceApi; /// Internal event used for handling async tasks wxDECLARE_EVENT( EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, wxCommandEvent ); /// Notifies other parts of KiCad when plugin availability changes extern const KICOMMON_API wxEventTypeTag EDA_EVT_PLUGIN_AVAILABILITY_CHANGED; /** * Responsible for loading plugin definitions for API-based plugins (ones that do not run inside * KiCad itself, but instead are launched as external processes by KiCad) */ class KICOMMON_API API_PLUGIN_MANAGER : public wxEvtHandler { public: API_PLUGIN_MANAGER( wxEvtHandler* aParent ); void ReloadPlugins(); void InvokeAction( const wxString& aIdentifier ); std::vector GetActionsForScope( PLUGIN_ACTION_SCOPE aScope ); std::map& ButtonBindings() { return m_buttonBindings; } std::map& MenuBindings() { return m_menuBindings; } private: void processPluginDependencies(); void processNextJob( wxCommandEvent& aEvent ); wxEvtHandler* m_parent; std::set, CompareApiPluginIdentifiers> m_plugins; std::map m_pluginsCache; std::map m_actionsCache; /// Map of plugin identifier to a path for the plugin's virtual environment, if it has one std::map m_environmentCache; /// Map of button wx item id to action identifier std::map m_buttonBindings; /// Map of menu wx item id to action identifier std::map m_menuBindings; std::set m_readyPlugins; enum class JOB_TYPE { CREATE_ENV, INSTALL_REQUIREMENTS }; struct JOB { JOB_TYPE type; wxString identifier; wxString plugin_path; wxString env_path; }; std::deque m_jobs; };