#include "..\API\BBApi.h"
#include "..\Menu\MenuCommon.h"
#include "PluginsMenu.h"
#include "..\Menu\MenuItem.h"
#include "..\Menu\FolderItem.h"
#include "..\Settings\ConfigMenu.h"
#include "..\Dock\Dock.h"
#include "..\Settings\Settings.h"
#include "PluginManager.h"
extern MenuCommon *pMenuCommon;
extern Settings *pSettings;
extern PluginManager *pPluginManager;
PluginMenu::PluginMenu(char* pszTitle) : FolderItem(NULL, pszTitle, NULL)
{
}
PluginMenu::~PluginMenu()
{
m_pParent->RemoveChild(m_pSubMenu);
if (m_pSubMenu) delete m_pSubMenu;
m_pSubMenu = NULL;
}
bool PluginMenu::Active(bool bActivate)
{
if (bActivate && !m_bActive) UpdateFolder();
return FolderItem::Active(bActivate);
}
void PluginMenu::Attached(Menu* pMenu)
{
m_pParent = pMenu;
m_pSubMenu = new Menu(pMenuCommon->hInst);
m_pParent->AddChild(m_pSubMenu);
m_pSubMenu->SetParent(m_pParent);
}
void PluginMenu::UpdateFolder()
{
m_pSubMenu->DeleteMenuItems();
pMenuCommon->AddHeaderItem(m_pSubMenu, m_pszTitleANSI);
pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_COMMAND, "@xoblite LoadPlugin", NULL, "Load plugin...", false);
UnloadPluginMenu *UPMenu = new UnloadPluginMenu("Unload plugin");
UPMenu->SetHeight(pMenuCommon->m_nSubmenuHeight);
m_pSubMenu->AddMenuItem(UPMenu);
BroamMenu *BMenu = new BroamMenu("Bro@ms");
BMenu->SetHeight(pMenuCommon->m_nSubmenuHeight);
m_pSubMenu->AddMenuItem(BMenu);
pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_SEPARATOR, NULL, NULL, NULL, false);
pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_COMMAND, "@xoblite Edit Plugins", NULL, "Edit plugins.rc", false);
pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_COMMAND, "@xoblite CheckForUpdates", NULL, "Check for updates...", false);
pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_COMMAND, "@xoblite About Plugins", NULL, "About loaded plugins...", false);
pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_SEPARATOR, NULL, NULL, NULL, false);
pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_COMMAND, "[exec]", "http://xoblite.net/shell/plugins/", "Get plugins...", false);
pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_SEPARATOR, NULL, NULL, NULL, false);
pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_BOOLEAN, "@xoblite Plugins Toggle", NULL, "Hide Plugins", pSettings->pluginsHidden);
int numberOfPlugins = (int)pPluginManager->pluginList.size();
char gripText[255];
sprintf_s(gripText, sizeofArray(gripText), "(%d plugin", numberOfPlugins);
if (numberOfPlugins != 1) strcat_s(gripText, sizeofArray(gripText), "s");
strcat_s(gripText, sizeofArray(gripText), " loaded)");
pMenuCommon->AddFooterItem(m_pSubMenu, gripText);
m_pSubMenu->Invalidate();
m_pSubMenu->Validate();
}
UnloadPluginMenu::UnloadPluginMenu(char* pszTitle) : FolderItem(NULL, pszTitle, NULL)
{
}
UnloadPluginMenu::~UnloadPluginMenu()
{
m_pParent->RemoveChild(m_pSubMenu);
if (m_pSubMenu) delete m_pSubMenu;
m_pSubMenu = NULL;
}
bool UnloadPluginMenu::Active(bool bActivate)
{
if (bActivate && !m_bActive) UpdateFolder();
return FolderItem::Active(bActivate);
}
void UnloadPluginMenu::Attached(Menu* pMenu)
{
m_pParent = pMenu;
m_pSubMenu = new Menu(pMenuCommon->hInst);
m_pParent->AddChild(m_pSubMenu);
m_pSubMenu->SetParent(m_pParent);
}
void UnloadPluginMenu::UpdateFolder()
{
m_pSubMenu->DeleteMenuItems();
pMenuCommon->AddHeaderItem(m_pSubMenu, m_pszTitleANSI);
if ((int)pPluginManager->pluginList.size() > 0)
{
char pluginNumber[MAX_LINE_LENGTH], pluginName[MAX_LINE_LENGTH], tempArgument[MAX_LINE_LENGTH];
for (int i=0; i < (int)pPluginManager->pluginList.size(); i++)
{
strcpy_s(tempArgument, sizeofArray(tempArgument), "#");
strcat_s(tempArgument, sizeofArray(tempArgument), _itoa(i+1, pluginNumber, 10));
strcpy_s(pluginName, sizeofArray(pluginName), pPluginManager->GetPluginInfo(i, PLUGIN_NAME));
pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_COMMAND, "@xoblite UnloadPlugin", tempArgument, pluginName, false);
}
}
else pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_NOP, NULL, NULL, "(No plugins loaded)", false);
pMenuCommon->AddFooterItem(m_pSubMenu, "...?");
m_pSubMenu->Invalidate();
m_pSubMenu->Validate();
}
BroamMenu::BroamMenu(char* pszTitle) : FolderItem(NULL, pszTitle, NULL)
{
}
BroamMenu::~BroamMenu()
{
m_pParent->RemoveChild(m_pSubMenu);
if (m_pSubMenu) delete m_pSubMenu;
m_pSubMenu = NULL;
}
bool BroamMenu::Active(bool bActivate)
{
if (bActivate && !m_bActive) UpdateFolder();
return FolderItem::Active(bActivate);
}
void BroamMenu::Attached(Menu* pMenu)
{
m_pParent = pMenu;
m_pSubMenu = new Menu(pMenuCommon->hInst);
m_pParent->AddChild(m_pSubMenu);
m_pSubMenu->SetParent(m_pParent);
}
void BroamMenu::UpdateFolder()
{
m_pSubMenu->DeleteMenuItems();
pMenuCommon->AddHeaderItem(m_pSubMenu, m_pszTitleANSI);
if ((int)pPluginManager->pluginList.size() > 0)
{
char pluginName[MAX_LINE_LENGTH], pluginBroams[MAX_LINE_LENGTH];
for (int i=0; i < (int)pPluginManager->pluginList.size(); i++)
{
strcpy_s(pluginName, sizeofArray(pluginName), pPluginManager->GetPluginInfo(i, PLUGIN_NAME));
strcpy_s(pluginBroams, sizeofArray(pluginBroams), pPluginManager->GetPluginInfo(i, PLUGIN_BROAMS));
if (strnlen_s(pluginBroams, sizeofArray(pluginBroams)) && _stricmp(pluginBroams, pluginName) && strchr(pluginBroams, '@'))
{
PluginBroamList *PBList = new PluginBroamList(pluginName, i);
PBList->SetHeight(pMenuCommon->m_nSubmenuHeight);
m_pSubMenu->AddMenuItem(PBList);
}
else
{
pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_NOP, NULL, NULL, pluginName, false);
}
}
}
else pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_NOP, NULL, NULL, "(No plugins loaded)", false);
pMenuCommon->AddFooterItem(m_pSubMenu, "");
m_pSubMenu->Invalidate();
m_pSubMenu->Validate();
}
PluginBroamList::PluginBroamList(char* pszTitle, int pluginNumber) : FolderItem(NULL, pszTitle, NULL)
{
plugNumber = pluginNumber;
}
PluginBroamList::~PluginBroamList()
{
m_pParent->RemoveChild(m_pSubMenu);
if (m_pSubMenu) delete m_pSubMenu;
m_pSubMenu = NULL;
}
bool PluginBroamList::Active(bool bActivate)
{
if (bActivate && !m_bActive) UpdateFolder();
return FolderItem::Active(bActivate);
}
void PluginBroamList::Attached(Menu* pMenu)
{
m_pParent = pMenu;
m_pSubMenu = new Menu(pMenuCommon->hInst);
m_pParent->AddChild(m_pSubMenu);
m_pSubMenu->SetParent(m_pParent);
}
void PluginBroamList::UpdateFolder()
{
m_pSubMenu->DeleteMenuItems();
pMenuCommon->AddHeaderItem(m_pSubMenu, m_pszTitleANSI);
char pluginBroamList[MAX_LINE_LENGTH], broam[MAX_LINE_LENGTH];
strcpy_s(pluginBroamList, sizeofArray(pluginBroamList), pPluginManager->GetPluginInfo(plugNumber, PLUGIN_BROAMS));
int nLen = strnlen_s(pluginBroamList, sizeofArray(pluginBroamList)) - 1;
while (nLen)
{
nLen = strnlen_s(pluginBroamList, sizeofArray(pluginBroamList)) - 1;
while (nLen >0 && pluginBroamList[nLen] != '@') nLen--;
strcpy_s(broam, sizeofArray(broam), &pluginBroamList[nLen]);
pluginBroamList[nLen] = '\0';
if (!_stricmp(broam, "@---")) pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_SEPARATOR, NULL, NULL, NULL, false);
else pMenuCommon->CreateMenuItem(m_pSubMenu, MENUITEM_COMMAND, broam, NULL, broam, false);
}
pMenuCommon->AddFooterItem(m_pSubMenu, "");
m_pSubMenu->Invalidate();
m_pSubMenu->Validate();
}