Adapt json format for Plugin admin

This commit is contained in:
Don HO 2017-09-24 18:27:42 +02:00
parent cacc1500a9
commit 1c5e6191bd
4 changed files with 92 additions and 28 deletions

View File

@ -0,0 +1,31 @@
{
"name": "npp-pluginList",
"version": "1.0",
"id": "b7fce57c3485abbb3a3e6a1f5f9e4f1f3d712a84271e6e6552002be9d6b3bbae",
"npp-plugins" : [
{
"folder-name": "switcher",
"display-name": "switcher",
"repository": "https://github/npp_plugins/",
"description": "Switcher: a plugin to switch between 'associated' files. Currently it handles switching between asm, inc, cpp, h, cch and ch. Useful when assigned to a hotkey.",
"author":"f0dder",
"homepage": "http://f0dder.dcmembers.com/npp_plugins/"
},
{
"folder-name": "mime-tools",
"display-name": "Mime tools",
"repository": "https://github/npp_plugins/mimetools/",
"description": "MIME plugin for Notepad++ implements several main functionnalities defined in MIME (Multipurpose Internet Mail Extensions).",
"author":"Don HO",
"homepage": "https://github.com/npp-plugins/mimetools"
},
{
"folder-name": "nppConvert",
"display-name": "NppConvert",
"repository": "https://github.com/npp-plugins/converter",
"description": "NppConvert is a ASCII<->Hex converter plugin for Notepad++.",
"author":"Don HO",
"homepage": "https://github.com/npp-plugins/converter"
}
]
}

View File

@ -70,6 +70,7 @@ void Notepad_plus::command(int id)
case IDM_FILE_NEW:
{
fileNew();
/*
bool isFirstTime = ! _pluginsAdminDlg.isCreated();
_pluginsAdminDlg.setPluginsManager(&_pluginsManager);

View File

@ -294,7 +294,6 @@ void PluginsAdminDlg::create(int dialogID, bool isRTL)
_availableListView.init(_hInst, _hSelf);
_availableListView.reSizeTo(listRect);
//_availableListView.display();
_updateListView.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200)));
_updateListView.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100)));
@ -303,7 +302,6 @@ void PluginsAdminDlg::create(int dialogID, bool isRTL)
_updateListView.init(_hInst, _hSelf);
_updateListView.reSizeTo(listRect);
//_updateListView.display(false);
_installedListView.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200)));
_installedListView.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100)));
@ -312,7 +310,6 @@ void PluginsAdminDlg::create(int dialogID, bool isRTL)
_installedListView.init(_hInst, _hSelf);
_installedListView.reSizeTo(listRect);
//_installedListView.display(false);
HWND hDesc = ::GetDlgItem(_hSelf, IDC_PLUGINADM_EDIT);
::MoveWindow(hDesc, descRect.left, descRect.top, descRect.right, descRect.bottom, TRUE);
@ -366,42 +363,42 @@ bool loadFromJson(std::vector<PluginUpdateInfo> & pl, const json& j)
if (jArray.empty() || jArray.type() != json::value_t::array)
return false;
for (auto& i : jArray)
for (const auto& i : jArray)
{
PluginUpdateInfo pi;
string s = i["folder-name"];
std::wstring val = wmc->char2wchar(s.c_str(), CP_ACP);
pi.name = val;
try {
PluginUpdateInfo pi;
s = i["display-name"];
val = wmc->char2wchar(s.c_str(), CP_ACP);
pi.alias = val;
string valStr = i.at("folder-name").get<std::string>();
pi.name = wmc->char2wchar(valStr.c_str(), CP_ACP);
s = i["author"];
val = wmc->char2wchar(s.c_str(), CP_ACP);
pi.author = val;
valStr = i.at("display-name").get<std::string>();
pi.alias = wmc->char2wchar(valStr.c_str(), CP_ACP);
s = i["description"];
val = wmc->char2wchar(s.c_str(), CP_ACP);
pi.description = val;
valStr = i.at("author").get<std::string>();
pi.author = wmc->char2wchar(valStr.c_str(), CP_ACP);
s = i["repository"];
val = wmc->char2wchar(s.c_str(), CP_ACP);
pi.repository = val;
valStr = i.at("description").get<std::string>();
pi.description = wmc->char2wchar(valStr.c_str(), CP_ACP);
s = i["homepage"];
val = wmc->char2wchar(s.c_str(), CP_ACP);
pi.homepage = val;
valStr = i.at("repository").get<std::string>();
pi.repository = wmc->char2wchar(valStr.c_str(), CP_ACP);
s = i["version"];
val = wmc->char2wchar(s.c_str(), CP_ACP);
pi.version = val;
valStr = i.at("homepage").get<std::string>();
pi.homepage = wmc->char2wchar(valStr.c_str(), CP_ACP);
pl.push_back(pi);
pl.push_back(pi);
}
catch (...) // Every field is mandatory. If one of property is missing, an exception is thrown then this plugin will be ignored
{
continue;
}
}
return true;
}
bool PluginsAdminDlg::updateListAndLoadFromJson()
{
// check on default location : %APPDATA%\Notepad++\plugins\config\pl\pl.json or NPP_INST_DIR\plugins\config\pl\pl.json
@ -426,9 +423,26 @@ bool PluginsAdminDlg::updateListAndLoadFromJson()
loadFromJson(_availablePluginList, pluginsJson);
// update available list view
updateAvailableListView();
return true;
}
void PluginsAdminDlg::updateAvailableListView()
{
size_t i = 0;
//
for (const auto& pui : _availablePluginList)
{
vector<generic_string> values2Add;
values2Add.push_back(pui.name);
values2Add.push_back(pui.version);
values2Add.push_back(TEXT("Yes"));
_availableListView.addLine(values2Add, i++);
}
}
bool PluginsAdminDlg::getLoadedPluginInfos()
{
if (not _pPluginsManager)
@ -466,6 +480,9 @@ bool PluginsAdminDlg::searchInPlugins(bool isNextMode) const
void PluginsAdminDlg::switchDialog(int indexToSwitch)
{
std::vector<PluginUpdateInfo>* pUpiList = nullptr;
ListView* pListView = nullptr;
bool showAvailable, showUpdate, showInstalled;
switch (indexToSwitch)
{
@ -473,18 +490,24 @@ void PluginsAdminDlg::switchDialog(int indexToSwitch)
showAvailable = true;
showUpdate = false;
showInstalled = false;
pUpiList = &_availablePluginList;
pListView = &_availableListView;
break;
case 1: // to be updated plugins
showAvailable = false;
showUpdate = true;
showInstalled = false;
pUpiList = &_updatePluginList;
pListView = &_updateListView;
break;
case 2: // installed plugin
showAvailable = false;
showUpdate = false;
showInstalled = true;
pUpiList = &_installedPluginList;
pListView = &_installedListView;
break;
default:
@ -507,6 +530,13 @@ void PluginsAdminDlg::switchDialog(int indexToSwitch)
_availableListView.display(showAvailable);
_updateListView.display(showUpdate);
_installedListView.display(showInstalled);
generic_string desc;
long infoIndex = pListView->getSelectedIndex();
if (infoIndex != -1)
desc = pUpiList->at(infoIndex).describe();
::SetDlgItemText(_hSelf, IDC_PLUGINADM_EDIT, desc.c_str());
}
INT_PTR CALLBACK PluginsAdminDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)

View File

@ -121,6 +121,8 @@ public :
void switchDialog(int indexToSwitch);
bool updateListAndLoadFromJson(); // call GitUup for the 1st time
void updateAvailableListView();
void setPluginsManager(PluginsManager *pluginsManager) { _pPluginsManager = pluginsManager; };
void setAdminMode(bool isAdm) { _nppCurrentStatus._isAdminMode = isAdm; };