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: case IDM_FILE_NEW:
{ {
fileNew(); fileNew();
/* /*
bool isFirstTime = ! _pluginsAdminDlg.isCreated(); bool isFirstTime = ! _pluginsAdminDlg.isCreated();
_pluginsAdminDlg.setPluginsManager(&_pluginsManager); _pluginsAdminDlg.setPluginsManager(&_pluginsManager);

View File

@ -294,7 +294,6 @@ void PluginsAdminDlg::create(int dialogID, bool isRTL)
_availableListView.init(_hInst, _hSelf); _availableListView.init(_hInst, _hSelf);
_availableListView.reSizeTo(listRect); _availableListView.reSizeTo(listRect);
//_availableListView.display();
_updateListView.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200))); _updateListView.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200)));
_updateListView.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100))); _updateListView.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100)));
@ -303,7 +302,6 @@ void PluginsAdminDlg::create(int dialogID, bool isRTL)
_updateListView.init(_hInst, _hSelf); _updateListView.init(_hInst, _hSelf);
_updateListView.reSizeTo(listRect); _updateListView.reSizeTo(listRect);
//_updateListView.display(false);
_installedListView.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200))); _installedListView.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200)));
_installedListView.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100))); _installedListView.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100)));
@ -312,7 +310,6 @@ void PluginsAdminDlg::create(int dialogID, bool isRTL)
_installedListView.init(_hInst, _hSelf); _installedListView.init(_hInst, _hSelf);
_installedListView.reSizeTo(listRect); _installedListView.reSizeTo(listRect);
//_installedListView.display(false);
HWND hDesc = ::GetDlgItem(_hSelf, IDC_PLUGINADM_EDIT); HWND hDesc = ::GetDlgItem(_hSelf, IDC_PLUGINADM_EDIT);
::MoveWindow(hDesc, descRect.left, descRect.top, descRect.right, descRect.bottom, TRUE); ::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) if (jArray.empty() || jArray.type() != json::value_t::array)
return false; return false;
for (auto& i : jArray) for (const auto& i : jArray)
{ {
try {
PluginUpdateInfo pi; PluginUpdateInfo pi;
string s = i["folder-name"];
std::wstring val = wmc->char2wchar(s.c_str(), CP_ACP);
pi.name = val;
s = i["display-name"]; string valStr = i.at("folder-name").get<std::string>();
val = wmc->char2wchar(s.c_str(), CP_ACP); pi.name = wmc->char2wchar(valStr.c_str(), CP_ACP);
pi.alias = val;
s = i["author"]; valStr = i.at("display-name").get<std::string>();
val = wmc->char2wchar(s.c_str(), CP_ACP); pi.alias = wmc->char2wchar(valStr.c_str(), CP_ACP);
pi.author = val;
s = i["description"]; valStr = i.at("author").get<std::string>();
val = wmc->char2wchar(s.c_str(), CP_ACP); pi.author = wmc->char2wchar(valStr.c_str(), CP_ACP);
pi.description = val;
s = i["repository"]; valStr = i.at("description").get<std::string>();
val = wmc->char2wchar(s.c_str(), CP_ACP); pi.description = wmc->char2wchar(valStr.c_str(), CP_ACP);
pi.repository = val;
s = i["homepage"]; valStr = i.at("repository").get<std::string>();
val = wmc->char2wchar(s.c_str(), CP_ACP); pi.repository = wmc->char2wchar(valStr.c_str(), CP_ACP);
pi.homepage = val;
valStr = i.at("homepage").get<std::string>();
pi.homepage = wmc->char2wchar(valStr.c_str(), CP_ACP);
s = i["version"];
val = wmc->char2wchar(s.c_str(), CP_ACP);
pi.version = val;
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; return 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 // 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); loadFromJson(_availablePluginList, pluginsJson);
// update available list view
updateAvailableListView();
return true; 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() bool PluginsAdminDlg::getLoadedPluginInfos()
{ {
if (not _pPluginsManager) if (not _pPluginsManager)
@ -466,6 +480,9 @@ bool PluginsAdminDlg::searchInPlugins(bool isNextMode) const
void PluginsAdminDlg::switchDialog(int indexToSwitch) void PluginsAdminDlg::switchDialog(int indexToSwitch)
{ {
std::vector<PluginUpdateInfo>* pUpiList = nullptr;
ListView* pListView = nullptr;
bool showAvailable, showUpdate, showInstalled; bool showAvailable, showUpdate, showInstalled;
switch (indexToSwitch) switch (indexToSwitch)
{ {
@ -473,18 +490,24 @@ void PluginsAdminDlg::switchDialog(int indexToSwitch)
showAvailable = true; showAvailable = true;
showUpdate = false; showUpdate = false;
showInstalled = false; showInstalled = false;
pUpiList = &_availablePluginList;
pListView = &_availableListView;
break; break;
case 1: // to be updated plugins case 1: // to be updated plugins
showAvailable = false; showAvailable = false;
showUpdate = true; showUpdate = true;
showInstalled = false; showInstalled = false;
pUpiList = &_updatePluginList;
pListView = &_updateListView;
break; break;
case 2: // installed plugin case 2: // installed plugin
showAvailable = false; showAvailable = false;
showUpdate = false; showUpdate = false;
showInstalled = true; showInstalled = true;
pUpiList = &_installedPluginList;
pListView = &_installedListView;
break; break;
default: default:
@ -507,6 +530,13 @@ void PluginsAdminDlg::switchDialog(int indexToSwitch)
_availableListView.display(showAvailable); _availableListView.display(showAvailable);
_updateListView.display(showUpdate); _updateListView.display(showUpdate);
_installedListView.display(showInstalled); _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) INT_PTR CALLBACK PluginsAdminDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)

View File

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