From 1c5e6191bdadb811922393280e96759c35b15799 Mon Sep 17 00:00:00 2001 From: Don HO Date: Sun, 24 Sep 2017 18:27:42 +0200 Subject: [PATCH] Adapt json format for Plugin admin --- PowerEditor/resources/nppPluginList.json | 31 +++++++ PowerEditor/src/NppCommands.cpp | 1 + .../WinControls/PluginsAdmin/pluginsAdmin.cpp | 86 +++++++++++++------ .../WinControls/PluginsAdmin/pluginsAdmin.h | 2 + 4 files changed, 92 insertions(+), 28 deletions(-) create mode 100644 PowerEditor/resources/nppPluginList.json diff --git a/PowerEditor/resources/nppPluginList.json b/PowerEditor/resources/nppPluginList.json new file mode 100644 index 00000000..2fa61d93 --- /dev/null +++ b/PowerEditor/resources/nppPluginList.json @@ -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" + } + ] +} diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 8b4c0a78..ed497322 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -70,6 +70,7 @@ void Notepad_plus::command(int id) case IDM_FILE_NEW: { fileNew(); + /* bool isFirstTime = ! _pluginsAdminDlg.isCreated(); _pluginsAdminDlg.setPluginsManager(&_pluginsManager); diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp index c7142814..e08e76a9 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp @@ -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); @@ -365,43 +362,43 @@ bool loadFromJson(std::vector & pl, const json& j) json jArray = j["npp-plugins"]; 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(); + 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(); + 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(); + 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(); + 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(); + 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(); + 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 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* 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) diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h index 280d6772..2048424c 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h @@ -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; };