mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-21 21:04:54 +02:00
Plugin Admin - in progress
This commit is contained in:
parent
7ce0ab04e6
commit
eb4edb50ef
@ -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())
|
if (hasPlugins())
|
||||||
{
|
{
|
||||||
const TCHAR *nom_menu = (menuName && menuName[0])?menuName:TEXT("&Plugins");
|
const TCHAR *nom_menu = (menuName && menuName[0])?menuName:TEXT("&Plugins");
|
||||||
|
size_t nbPlugin = _pluginInfos.size();
|
||||||
|
|
||||||
if (!_hPluginsMenu)
|
if (!_hPluginsMenu)
|
||||||
{
|
{
|
||||||
_hPluginsMenu = ::CreateMenu();
|
_hPluginsMenu = ::CreateMenu();
|
||||||
::InsertMenu(hMenu, MENUINDEX_PLUGINS, MF_BYPOSITION | MF_POPUP, (UINT_PTR)_hPluginsMenu, nom_menu);
|
::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));
|
addInMenuFromPMIndex(static_cast<int32_t>(i));
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ public:
|
|||||||
void runPluginCommand(const TCHAR *pluginName, int commandID);
|
void runPluginCommand(const TCHAR *pluginName, int commandID);
|
||||||
|
|
||||||
void addInMenuFromPMIndex(int i);
|
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);
|
bool getShortcutByCmdID(int cmdID, ShortcutKey *sk);
|
||||||
|
|
||||||
void notify(const SCNotification *notification);
|
void notify(const SCNotification *notification);
|
||||||
|
@ -536,7 +536,10 @@ LRESULT Notepad_plus::init(HWND hwnd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Plugin menu
|
//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
|
//Main menu is loaded, now load context menu items
|
||||||
pNppParam->getContextMenuFromXmlTree(_mainMenuHandle, _pluginsManager.getMenuHandle());
|
pNppParam->getContextMenuFromXmlTree(_mainMenuHandle, _pluginsManager.getMenuHandle());
|
||||||
|
@ -70,17 +70,6 @@ void Notepad_plus::command(int id)
|
|||||||
case IDM_FILE_NEW:
|
case IDM_FILE_NEW:
|
||||||
{
|
{
|
||||||
fileNew();
|
fileNew();
|
||||||
|
|
||||||
/*
|
|
||||||
bool isFirstTime = ! _pluginsAdminDlg.isCreated();
|
|
||||||
_pluginsAdminDlg.setPluginsManager(&_pluginsManager);
|
|
||||||
_pluginsAdminDlg.doDialog(_nativeLangSpeaker.isRTL());
|
|
||||||
if (isFirstTime)
|
|
||||||
{
|
|
||||||
_nativeLangSpeaker.changeConfigLang(_pluginsAdminDlg.getHSelf());
|
|
||||||
_pluginsAdminDlg.updateListAndLoadFromJson();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2465,6 +2454,18 @@ void Notepad_plus::command(int id)
|
|||||||
break;
|
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 :
|
||||||
case IDM_SETTING_SHORTCUT_MAPPER_MACRO :
|
case IDM_SETTING_SHORTCUT_MAPPER_MACRO :
|
||||||
case IDM_SETTING_SHORTCUT_MAPPER_RUN :
|
case IDM_SETTING_SHORTCUT_MAPPER_RUN :
|
||||||
|
@ -580,42 +580,105 @@ 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()
|
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
|
||||||
|
|
||||||
|
|
||||||
// if absent then download it
|
// check the update for nppPluginList.json
|
||||||
|
|
||||||
|
|
||||||
// check the update of pl.json
|
// download update if present
|
||||||
|
|
||||||
|
|
||||||
// download update if present
|
// load pl.json
|
||||||
|
//
|
||||||
|
|
||||||
// check integrity of pl.json
|
loadFromJson(_availableList, j);
|
||||||
|
|
||||||
// load pl.json
|
// initialize update list view
|
||||||
//
|
checkUpdates();
|
||||||
generic_string nppPluginListJsonPath = TEXT("C:\\tmp\\nppPluginList.json");
|
|
||||||
|
|
||||||
if (!::PathFileExists(nppPluginListJsonPath.c_str()))
|
// initialize installed list view
|
||||||
|
loadFromPluginInfos();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
// whichever exception
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
ifstream nppPluginListJson(nppPluginListJsonPath);
|
|
||||||
json pluginsJson;
|
|
||||||
nppPluginListJson >> pluginsJson;
|
|
||||||
|
|
||||||
// initialize available list view
|
|
||||||
loadFromJson(_availableList, pluginsJson);
|
|
||||||
|
|
||||||
// initialize update list view
|
|
||||||
checkUpdates();
|
|
||||||
|
|
||||||
// initialize installed list view
|
|
||||||
loadFromPluginInfos();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,6 +148,8 @@ public :
|
|||||||
display();
|
display();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool listExist();
|
||||||
|
|
||||||
void switchDialog(int indexToSwitch);
|
void switchDialog(int indexToSwitch);
|
||||||
void setPluginsManager(PluginsManager *pluginsManager) { _pPluginsManager = pluginsManager; };
|
void setPluginsManager(PluginsManager *pluginsManager) { _pPluginsManager = pluginsManager; };
|
||||||
|
|
||||||
|
@ -547,7 +547,7 @@
|
|||||||
#define IDM_SETTING_SHORTCUT_MAPPER (IDM_SETTING + 9)
|
#define IDM_SETTING_SHORTCUT_MAPPER (IDM_SETTING + 9)
|
||||||
#define IDM_SETTING_REMEMBER_LAST_SESSION (IDM_SETTING + 10)
|
#define IDM_SETTING_REMEMBER_LAST_SESSION (IDM_SETTING + 10)
|
||||||
#define IDM_SETTING_PREFERECE (IDM_SETTING + 11)
|
#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_MACRO (IDM_SETTING + 16)
|
||||||
#define IDM_SETTING_SHORTCUT_MAPPER_RUN (IDM_SETTING + 17)
|
#define IDM_SETTING_SHORTCUT_MAPPER_RUN (IDM_SETTING + 17)
|
||||||
#define IDM_SETTING_EDITCONTEXTMENU (IDM_SETTING + 18)
|
#define IDM_SETTING_EDITCONTEXTMENU (IDM_SETTING + 18)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user