void PluginMgrDlg::Initialize() { clConfig conf("plugins.conf"); PluginInfoArray plugins; conf.ReadItem(&plugins); m_initialDisabledPlugins = plugins.GetDisabledPlugins(); std::sort(m_initialDisabledPlugins.begin(), m_initialDisabledPlugins.end()); const PluginInfo::PluginMap_t& pluginsMap = plugins.GetPlugins(); // Clear the list m_checkListPluginsList->Clear(); PluginInfo::PluginMap_t::const_iterator iter = pluginsMap.begin(); for(; iter != pluginsMap.end(); ++iter) { PluginInfo info = iter->second; int item = m_checkListPluginsList->Append(info.GetName()); if(item != wxNOT_FOUND) { m_checkListPluginsList->Check((unsigned int)item, plugins.CanLoad(info.GetName())); } } if(m_checkListPluginsList->IsEmpty() == false) { m_checkListPluginsList->Select(0); CreateInfoPage(0); } m_checkListPluginsList->SetFocus(); }
void PluginInfoArray::AddPlugin(const PluginInfo& plugin) { if ( m_plugins.count(plugin.GetName()) ) m_plugins.erase(plugin.GetName()); m_plugins.insert(std::make_pair(plugin.GetName(), plugin)); }
bool PluginInfoArray::CanLoad(const PluginInfo& plugin) const { if(m_disabledPlugins.Index(plugin.GetName()) != wxNOT_FOUND) { // If the plugin is in the "disabled plugins" list - return false return false; } return true; }
void PluginInfoArray::FromJSON(const JSONElement& json) { m_disabledPlugins = json.namedObject("disabledPlugins").toArrayString(); m_plugins.clear(); JSONElement arr = json.namedObject("installed-plugins"); for(int i=0; i<arr.arraySize(); ++i) { PluginInfo pi; pi.FromJSON( arr.arrayItem(i) ); m_plugins.insert(std::make_pair(pi.GetName(), pi)); } }
void PluginManager::Load() { wxString ext; #if defined(__WXGTK__) ext = wxT("so"); #elif defined(__WXMAC__) ext = wxT("dylib"); #else ext = wxT("dll"); #endif wxString fileSpec(wxT("*.") + ext); clConfig conf("plugins.conf"); conf.ReadItem(&m_pluginsData); // set the managers // this code assures us that the shared objects will see the same instances as the application // does LanguageST::Get()->SetTagsManager(GetTagsManager()); TagsManagerST::Get()->SetLanguage(LanguageST::Get()); // Plugin loading policy CodeLiteApp* app = static_cast<CodeLiteApp*>(GetTheApp()); CodeLiteApp::PluginPolicy pp = app->GetPluginLoadPolicy(); wxArrayString allowedPlugins; if(pp == CodeLiteApp::PP_None) { return; } else if(pp == CodeLiteApp::PP_FromList) allowedPlugins = app->GetAllowedPlugins(); wxString pluginsDir = clStandardPaths::Get().GetPluginsDirectory(); if(wxDir::Exists(pluginsDir)) { // get list of dlls wxArrayString files; wxDir::GetAllFiles(pluginsDir, &files, fileSpec, wxDIR_FILES); // Sort the plugins by A-Z std::sort(files.begin(), files.end()); for(size_t i = 0; i < files.GetCount(); i++) { wxString fileName(files.Item(i)); #if defined(__WXMSW__) && !defined(NDEBUG) // Under MSW loading a release plugin while in debug mode will cause a crash if(!fileName.EndsWith("-dbg.dll")) { continue; } #elif defined(__WXMSW__) // filter debug plugins if(fileName.EndsWith("-dbg.dll")) { continue; } #endif #ifdef __WXGTK__ wxFileName fnDLL(fileName); if(fnDLL.GetFullName().StartsWith("lib")) { // don't attempt to load a library continue; } #endif clDynamicLibrary* dl = new clDynamicLibrary(); if(!dl->Load(fileName)) { CL_ERROR(wxT("Failed to load plugin's dll: ") + fileName); if(!dl->GetError().IsEmpty()) { CL_ERROR(dl->GetError()); } continue; } bool success(false); GET_PLUGIN_INFO_FUNC pfnGetPluginInfo = (GET_PLUGIN_INFO_FUNC)dl->GetSymbol(wxT("GetPluginInfo"), &success); if(!success) { continue; } // load the plugin version method // if the methods does not exist, handle it as if it has value of 100 (lowest version API) int interface_version(100); GET_PLUGIN_INTERFACE_VERSION_FUNC pfnInterfaceVersion = (GET_PLUGIN_INTERFACE_VERSION_FUNC)dl->GetSymbol(wxT("GetPluginInterfaceVersion"), &success); if(success) { interface_version = pfnInterfaceVersion(); } else { CL_WARNING(wxT("Failed to find GetPluginInterfaceVersion() in dll: ") + fileName); if(!dl->GetError().IsEmpty()) { CL_WARNING(dl->GetError()); } } if(interface_version != PLUGIN_INTERFACE_VERSION) { CL_WARNING(wxString::Format(wxT("Version interface mismatch error for plugin '%s'. Plugin's interface " "version is '%d', CodeLite interface version is '%d'"), fileName.c_str(), interface_version, PLUGIN_INTERFACE_VERSION)); continue; } // Check if this dll can be loaded PluginInfo pluginInfo = pfnGetPluginInfo(); wxString pname = pluginInfo.GetName(); pname.MakeLower().Trim().Trim(false); // Check the policy if(pp == CodeLiteApp::PP_FromList && allowedPlugins.Index(pname) == wxNOT_FOUND) { // Policy is set to 'from list' and this plugin does not match any plugins from // the list, don't allow it to be loaded continue; } // Add the plugin information m_pluginsData.AddPlugin(pluginInfo); // Can we load it? if(!m_pluginsData.CanLoad(pluginInfo.GetName())) { CL_WARNING(wxT("Plugin ") + pluginInfo.GetName() + wxT(" is not enabled")); continue; } // try and load the plugin GET_PLUGIN_CREATE_FUNC pfn = (GET_PLUGIN_CREATE_FUNC)dl->GetSymbol(wxT("CreatePlugin"), &success); if(!success) { CL_WARNING(wxT("Failed to find CreatePlugin() in dll: ") + fileName); if(!dl->GetError().IsEmpty()) { CL_WARNING(dl->GetError()); } m_pluginsData.DisablePlugin(pluginInfo.GetName()); continue; } // Construct the plugin IPlugin* plugin = pfn((IManager*)this); CL_DEBUG(wxT("Loaded plugin: ") + plugin->GetLongName()); m_plugins[plugin->GetShortName()] = plugin; // Load the toolbar clToolBar* tb = plugin->CreateToolBar((wxWindow*)clMainFrame::Get()); if(tb) { #if USE_AUI_TOOLBAR // When using AUI toolbars, use our own custom art-provider tb->SetArtProvider(new CLMainAuiTBArt()); #endif clMainFrame::Get()->GetDockingManager().AddPane(tb, wxAuiPaneInfo() .Name(plugin->GetShortName()) .LeftDockable(true) .RightDockable(true) .Caption(plugin->GetShortName()) .ToolbarPane() .Top() .Row(0)); // Add menu entry at the 'View->Toolbars' menu for this toolbar wxMenuItem* item = clMainFrame::Get()->GetMenuBar()->FindItem(XRCID("toolbars_menu")); if(item) { wxMenu* submenu = NULL; submenu = item->GetSubMenu(); // add the new toolbar entry at the end of this menu int id = wxNewId(); wxString text(plugin->GetShortName()); text << _(" ToolBar"); wxMenuItem* newItem = new wxMenuItem(submenu, id, text, wxEmptyString, wxITEM_CHECK); submenu->Append(newItem); clMainFrame::Get()->RegisterToolbar(id, plugin->GetShortName()); } } // Keep the dynamic load library m_dl.push_back(dl); } clMainFrame::Get()->GetDockingManager().Update(); // Let the plugins plug their menu in the 'Plugins' menu at the menu bar // the create menu will be placed as a sub menu of the 'Plugin' menu wxMenu* pluginsMenu = NULL; wxMenuItem* menuitem = clMainFrame::Get()->GetMenuBar()->FindItem(XRCID("manage_plugins"), &pluginsMenu); if(pluginsMenu && menuitem) { std::map<wxString, IPlugin*>::iterator iter = m_plugins.begin(); for(; iter != m_plugins.end(); ++iter) { IPlugin* plugin = iter->second; plugin->CreatePluginMenu(pluginsMenu); } } // save the plugins data conf.WriteItem(&m_pluginsData); } // Now that all the plugins are loaded, load from the configuration file // list of visible tabs static wxArrayString DefaultArray; if(DefaultArray.IsEmpty()) { DefaultArray.Add("NOT-FOUND"); } { const wxArrayString& tabs = GetWorkspaceTabs(); wxArrayString visibleTabs = clConfig::Get().Read("VisibleWorkspaceTabs", DefaultArray); if(!((visibleTabs.size() == 1) && (visibleTabs.Item(0) == "NOT-FOUND"))) { for(size_t i = 0; i < tabs.size(); ++i) { if(visibleTabs.Index(tabs.Item(i)) == wxNOT_FOUND) { // hidden tab - post an event clCommandEvent eventHide(wxEVT_SHOW_WORKSPACE_TAB); eventHide.SetSelected(false).SetString(tabs.Item(i)); EventNotifier::Get()->AddPendingEvent(eventHide); } } } } { const wxArrayString& tabs = GetOutputTabs(); wxArrayString visibleTabs = clConfig::Get().Read("VisibleOutputTabs", DefaultArray); if(!((visibleTabs.size() == 1) && (visibleTabs.Item(0) == "NOT-FOUND"))) { for(size_t i = 0; i < tabs.size(); ++i) { if(visibleTabs.Index(tabs.Item(i)) == wxNOT_FOUND) { // hidden tab - post an event clCommandEvent eventHide(wxEVT_SHOW_OUTPUT_TAB); eventHide.SetSelected(false).SetString(tabs.Item(i)); EventNotifier::Get()->AddPendingEvent(eventHide); } } } } }
void PluginMgrDlg::CreateInfoPage(unsigned int index) { clConfig conf("plugins.conf"); PluginInfoArray plugins; conf.ReadItem(&plugins); // get the plugin name wxString pluginName = m_checkListPluginsList->GetString(index); PluginInfo::PluginMap_t::const_iterator iter = plugins.GetPlugins().find(pluginName); if(iter != plugins.GetPlugins().end()) { PluginInfo info = iter->second; wxString content; content << wxT("<html><body>"); content << wxT("<table border=0 width=\"100%\" >"); // create line with the plugin name content << wxT("<tr bgcolor=\"LIGHT GREY\">"); content << wxT("<td ALIGN=\"LEFT\" WIDTH=30%><font size=\"2\" " "face=\"Verdana\"><strong>$(PluginName)</strong></font></td>"); content << wxT("<td ALIGN=\"LEFT\" ><font size=\"2\" face=\"Verdana\">") << info.GetName() << wxT("</font></td>"); content << wxT("</tr>"); // plugin author content << wxT("<tr bgcolor=\"WHITE\">"); content << wxT( "<td ALIGN=\"LEFT\" WIDTH=30%><font size=\"2\" face=\"Verdana\"><strong>$(Author)</strong></font></td>"); content << wxT("<td ALIGN=\"LEFT\" ><font size=\"2\" face=\"Verdana\">") << info.GetAuthor() << wxT("</font></td>"); content << wxT("</tr>"); // plugin version content << wxT("<tr bgcolor=\"LIGHT GREY\">"); content << wxT( "<td ALIGN=\"LEFT\" WIDTH=30%><font size=\"2\" face=\"Verdana\"><strong>$(Version)</strong></font></td>"); content << wxT("<td ALIGN=\"LEFT\" ><font size=\"2\" face=\"Verdana\">") << info.GetVersion() << wxT("</font></td>"); content << wxT("</tr>"); // plugin description content << wxT("<tr bgcolor=\"WHITE\">"); content << wxT("<td ALIGN=\"LEFT\" WIDTH=30%><font size=\"2\" " "face=\"Verdana\"><strong>$(Description)</strong></font></td>"); content << wxT("<td ALIGN=\"LEFT\" ><font size=\"2\" face=\"Verdana\">") << info.GetDescription() << wxT("</font></td>"); content << wxT("</tr>"); content << wxT("<tr bgcolor=\"LIGHT GREY\">"); content << wxT( "<td ALIGN=\"LEFT\" WIDTH=30%><font size=\"2\" face=\"Verdana\"><strong>$(Status)</strong></font></td>"); content.Replace(wxT("$(PluginName)"), _("Plugin Name:")); content.Replace(wxT("$(Author)"), _("Author:")); content.Replace(wxT("$(Version)"), _("Version:")); content.Replace(wxT("$(Description)"), _("Description:")); content.Replace(wxT("$(Status)"), _("Status:")); wxString status; if(plugins.CanLoad(info.GetName())) { status = wxT("<img src=\"$(InstallPath)/images/plugin_ok.png\" ></img>"); } else { status = wxT("<img src=\"$(InstallPath)/images/plugin_not_ok.png\" > </img>"); } status.Replace(wxT("$(InstallPath)"), ManagerST::Get()->GetStartupDirectory()); content << wxT("<td ALIGN=\"LEFT\" ><font size=\"2\" face=\"Verdana\">") << status << wxT("</font></td>"); content << wxT("</tr>"); content << wxT("</table><html><body>"); m_htmlWinDesc->SetPage(content); } }