Plugin Admin - in progress

This commit is contained in:
Don HO 2018-07-19 02:03:17 +02:00
parent 7ce0ab04e6
commit eb4edb50ef
7 changed files with 117 additions and 40 deletions

View File

@ -498,19 +498,27 @@ void PluginsManager::addInMenuFromPMIndex(int i)
*/
}
HMENU PluginsManager::setMenu(HMENU hMenu, const TCHAR *menuName)
HMENU PluginsManager::setMenu(HMENU hMenu, const TCHAR *menuName, bool enablePluginAdmin)
{
if (hasPlugins())
{
const TCHAR *nom_menu = (menuName && menuName[0])?menuName:TEXT("&Plugins");
size_t nbPlugin = _pluginInfos.size();
if (!_hPluginsMenu)
{
_hPluginsMenu = ::CreateMenu();
::InsertMenu(hMenu, MENUINDEX_PLUGINS, MF_BYPOSITION | MF_POPUP, (UINT_PTR)_hPluginsMenu, nom_menu);
if (enablePluginAdmin)
{
if (nbPlugin > 0)
::InsertMenu(_hPluginsMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, TEXT(""));
::InsertMenu(_hPluginsMenu, 1, MF_BYPOSITION, IDM_SETTING_PLUGINADM, TEXT("Plugin Admin"));
}
}
for (size_t i = 0, len = _pluginInfos.size() ; i < len ; ++i)
for (size_t i = 0; i < nbPlugin; ++i)
{
addInMenuFromPMIndex(static_cast<int32_t>(i));
}

View File

@ -109,7 +109,7 @@ public:
void runPluginCommand(const TCHAR *pluginName, int commandID);
void addInMenuFromPMIndex(int i);
HMENU setMenu(HMENU hMenu, const TCHAR *menuName);
HMENU setMenu(HMENU hMenu, const TCHAR *menuName, bool enablePluginAdmin = false);
bool getShortcutByCmdID(int cmdID, ShortcutKey *sk);
void notify(const SCNotification *notification);

View File

@ -536,7 +536,10 @@ LRESULT Notepad_plus::init(HWND hwnd)
}
//Plugin menu
_pluginsManager.setMenu(_mainMenuHandle, NULL);
bool enablePluginAdmin = _pluginsAdminDlg.listExist();
_pluginsAdminDlg.setPluginsManager(&_pluginsManager);
_pluginsManager.setMenu(_mainMenuHandle, NULL, enablePluginAdmin);
//Main menu is loaded, now load context menu items
pNppParam->getContextMenuFromXmlTree(_mainMenuHandle, _pluginsManager.getMenuHandle());

View File

@ -70,17 +70,6 @@ void Notepad_plus::command(int id)
case IDM_FILE_NEW:
{
fileNew();
/*
bool isFirstTime = ! _pluginsAdminDlg.isCreated();
_pluginsAdminDlg.setPluginsManager(&_pluginsManager);
_pluginsAdminDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
{
_nativeLangSpeaker.changeConfigLang(_pluginsAdminDlg.getHSelf());
_pluginsAdminDlg.updateListAndLoadFromJson();
}
*/
}
break;
@ -2465,6 +2454,18 @@ void Notepad_plus::command(int id)
break;
}
case IDM_SETTING_PLUGINADM:
{
bool isFirstTime = !_pluginsAdminDlg.isCreated();
_pluginsAdminDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
{
_nativeLangSpeaker.changeConfigLang(_pluginsAdminDlg.getHSelf());
_pluginsAdminDlg.updateListAndLoadFromJson();
}
break;
}
case IDM_SETTING_SHORTCUT_MAPPER :
case IDM_SETTING_SHORTCUT_MAPPER_MACRO :
case IDM_SETTING_SHORTCUT_MAPPER_RUN :

View File

@ -580,34 +580,91 @@ PluginUpdateInfo::PluginUpdateInfo(const generic_string& fullFilePath, const gen
}
typedef const char * (__cdecl * PFUNCGETPLUGINLIST)();
bool PluginsAdminDlg::listExist()
{
#ifdef DEBUG // if not debug, then it's release
// load from nppPluginList.json instead of nppPluginList.dll
generic_string nppPluginListPath = TEXT("C:\\tmp\\nppPluginList.json");
#else //RELEASE
#ifdef _WIN64
generic_string nppPluginListPath = TEXT("C:\\sources\\nppPluginList\\vcxproj\\x64\\Debug\\nppPluginList.dll");
#else
generic_string nppPluginListPath = TEXT("C:\\sources\\nppPluginList\\vcxproj\\Debug\\nppPluginList.dll");
#endif
#endif
return ::PathFileExists(nppPluginListPath.c_str()) == TRUE;
}
bool PluginsAdminDlg::updateListAndLoadFromJson()
{
// check on default location : %APPDATA%\Notepad++\plugins\config\pl\pl.json or NPP_INST_DIR\plugins\config\pl\pl.json
try {
json j;
#ifdef DEBUG // if not debug, then it's release
// load from nppPluginList.json instead of nppPluginList.dll
generic_string nppPluginListJsonPath = TEXT("C:\\tmp\\nppPluginList.json");
if (!::PathFileExists(nppPluginListJsonPath.c_str()))
{
::MessageBox(NULL, TEXT("The file doesn't exist"), nppPluginListJsonPath.c_str(), MB_OK);
return false;
}
ifstream nppPluginListJson(nppPluginListJsonPath);
nppPluginListJson >> j;
#else //RELEASE
#ifdef _WIN64
generic_string nppPluginListDllPath = TEXT("C:\\sources\\nppPluginList\\vcxproj\\x64\\Debug\\nppPluginList.dll");
#else
generic_string nppPluginListDllPath = TEXT("C:\\sources\\nppPluginList\\vcxproj\\Debug\\nppPluginList.dll");
#endif
// check the signature on default location : %APPDATA%\Notepad++\plugins\config\pl\nppPluginList.dll or NPP_INST_DIR\plugins\config\pl\nppPluginList.dll
HINSTANCE hLib = ::LoadLibrary(nppPluginListDllPath.c_str());
if (!hLib)
{
// Error treatment
//printStr(TEXT("LoadLibrary PB!!!"));
return false;
}
PFUNCGETPLUGINLIST pGetListFunc = (PFUNCGETPLUGINLIST)GetProcAddress(hLib, "getList");
if (!pGetListFunc)
{
// Error treatment
//printStr(TEXT("getList PB!!!"));
return false;
}
const char* pl = pGetListFunc();
//MessageBoxA(NULL, pl, "", MB_OK);
j = j.parse(pl);
#endif
// if absent then download it
// check the update of pl.json
// check the update for nppPluginList.json
// download update if present
// check integrity of pl.json
// load pl.json
//
generic_string nppPluginListJsonPath = TEXT("C:\\tmp\\nppPluginList.json");
if (!::PathFileExists(nppPluginListJsonPath.c_str()))
return false;
ifstream nppPluginListJson(nppPluginListJsonPath);
json pluginsJson;
nppPluginListJson >> pluginsJson;
// initialize available list view
loadFromJson(_availableList, pluginsJson);
loadFromJson(_availableList, j);
// initialize update list view
checkUpdates();
@ -617,6 +674,12 @@ bool PluginsAdminDlg::updateListAndLoadFromJson()
return true;
}
catch (...)
{
// whichever exception
return false;
}
}
bool PluginsAdminDlg::loadFromPluginInfos()

View File

@ -148,6 +148,8 @@ public :
display();
};
bool listExist();
void switchDialog(int indexToSwitch);
void setPluginsManager(PluginsManager *pluginsManager) { _pPluginsManager = pluginsManager; };

View File

@ -547,7 +547,7 @@
#define IDM_SETTING_SHORTCUT_MAPPER (IDM_SETTING + 9)
#define IDM_SETTING_REMEMBER_LAST_SESSION (IDM_SETTING + 10)
#define IDM_SETTING_PREFERECE (IDM_SETTING + 11)
// #define IDM_SETTING_AUTOCNBCHAR (IDM_SETTING + 15)
#define IDM_SETTING_PLUGINADM (IDM_SETTING + 15)
#define IDM_SETTING_SHORTCUT_MAPPER_MACRO (IDM_SETTING + 16)
#define IDM_SETTING_SHORTCUT_MAPPER_RUN (IDM_SETTING + 17)
#define IDM_SETTING_EDITCONTEXTMENU (IDM_SETTING + 18)