Refactoring Plugin Admin codes

This commit is contained in:
Don HO 2018-06-12 03:20:37 +02:00
parent a99fa9ae50
commit c30c0de0fc
2 changed files with 140 additions and 167 deletions

View File

@ -147,57 +147,45 @@ bool findStrNoCase(const generic_string & strHaystack, const generic_string & st
return (it != strHaystack.end()); return (it != strHaystack.end());
} }
bool PluginsAdminDlg::isFoundInAvailableListFromIndex(int index, generic_string str2search, bool inWhichPart) const
{
PluginUpdateInfo* pui = _availableList.getPluginInfoFromIndex(index);
generic_string searchIn;
if (inWhichPart == _inNames)
searchIn = pui->_displayName;
else //(inWhichPart == inDescs)
searchIn = pui->_description;
return (findStrNoCase(searchIn, str2search));
}
long PluginsAdminDlg::searchFromCurrentSel(generic_string str2search, bool inWhichPart, bool isNextMode) const long PluginsAdminDlg::searchFromCurrentSel(generic_string str2search, bool inWhichPart, bool isNextMode) const
{ {
// search from curent selected item or from the beginning // search from curent selected item or from the beginning
long currentIndex = _availableListView.getSelectedIndex(); long currentIndex = _availableList.getSelectedIndex();
int nbItem = static_cast<int>(_availableListView.nbItem()); int nbItem = static_cast<int>(_availableList.nbItem());
if (currentIndex == -1) if (currentIndex == -1)
{ {
// no selection, let's search from 0 to the end // no selection, let's search from 0 to the end
for (int i = 0; i < nbItem; ++i) for (int i = 0; i < nbItem; ++i)
{ {
size_t j = _availableListView.getLParamFromIndex(i); if (isFoundInAvailableListFromIndex(i, str2search, inWhichPart))
generic_string searchIn;
if (inWhichPart == inNames)
searchIn = _availablePluginList[j]._name;
else //(inWhichPart == inDescs)
searchIn = _availablePluginList[j]._description;
if (findStrNoCase(searchIn, str2search))
return i; return i;
} }
} }
else else // with selection, let's search from currentIndex
{ {
// with selection, let's search from currentIndex
// from current position to the end // from current position to the end
for (int i = currentIndex + (isNextMode ? 1 : 0); i < nbItem; ++i) for (int i = currentIndex + (isNextMode ? 1 : 0); i < nbItem; ++i)
{ {
size_t j = _availableListView.getLParamFromIndex(i); if (isFoundInAvailableListFromIndex(i, str2search, inWhichPart))
generic_string searchIn;
if (inWhichPart == inNames)
searchIn = _availablePluginList[j]._name;
else //(inWhichPart == inDescs)
searchIn = _availablePluginList[j]._description;
if (findStrNoCase(searchIn, str2search))
return i; return i;
} }
// from to begining to current position // from to begining to current position
for (int i = 0; i < currentIndex + (isNextMode ? 1 : 0); ++i) for (int i = 0; i < currentIndex + (isNextMode ? 1 : 0); ++i)
{ {
size_t j = _availableListView.getLParamFromIndex(i); if (isFoundInAvailableListFromIndex(i, str2search, inWhichPart))
generic_string searchIn;
if (inWhichPart == inNames)
searchIn = _availablePluginList[j]._name;
else //(inWhichPart == inDescs)
searchIn = _availablePluginList[j]._description;
if (findStrNoCase(searchIn, str2search))
return i; return i;
} }
} }
@ -300,29 +288,29 @@ void PluginsAdminDlg::create(int dialogID, bool isRTL, bool msgDestParent)
generic_string vesionStr = pNativeSpeaker->getAttrNameStr(TEXT("Version"), "PluginAdmin", "Version"); generic_string vesionStr = pNativeSpeaker->getAttrNameStr(TEXT("Version"), "PluginAdmin", "Version");
generic_string stabilityStr = pNativeSpeaker->getAttrNameStr(TEXT("Stability"), "PluginAdmin", "Stability"); generic_string stabilityStr = pNativeSpeaker->getAttrNameStr(TEXT("Stability"), "PluginAdmin", "Stability");
_availableListView.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200))); _availableList.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200)));
_availableListView.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100))); _availableList.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100)));
_availableListView.addColumn(columnInfo(stabilityStr, nppParam->_dpiManager.scaleX(70))); _availableList.addColumn(columnInfo(stabilityStr, nppParam->_dpiManager.scaleX(70)));
_availableListView.setStyleOption(LVS_EX_CHECKBOXES); _availableList.setViewStyleOption(LVS_EX_CHECKBOXES);
_availableListView.init(_hInst, _hSelf); _availableList.initView(_hInst, _hSelf);
_availableListView.reSizeTo(listRect); _availableList.reSizeView(listRect);
_updateListView.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200))); _updateList.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200)));
_updateListView.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100))); _updateList.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100)));
_updateListView.addColumn(columnInfo(stabilityStr, nppParam->_dpiManager.scaleX(70))); _updateList.addColumn(columnInfo(stabilityStr, nppParam->_dpiManager.scaleX(70)));
_updateListView.setStyleOption(LVS_EX_CHECKBOXES); _updateList.setViewStyleOption(LVS_EX_CHECKBOXES);
_updateListView.init(_hInst, _hSelf); _updateList.initView(_hInst, _hSelf);
_updateListView.reSizeTo(listRect); _updateList.reSizeView(listRect);
_installedListView.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200))); _installedList.addColumn(columnInfo(pluginStr, nppParam->_dpiManager.scaleX(200)));
_installedListView.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100))); _installedList.addColumn(columnInfo(vesionStr, nppParam->_dpiManager.scaleX(100)));
_installedListView.addColumn(columnInfo(stabilityStr, nppParam->_dpiManager.scaleX(70))); _installedList.addColumn(columnInfo(stabilityStr, nppParam->_dpiManager.scaleX(70)));
_installedListView.setStyleOption(LVS_EX_CHECKBOXES); _installedList.setViewStyleOption(LVS_EX_CHECKBOXES);
_installedListView.init(_hInst, _hSelf); _installedList.initView(_hInst, _hSelf);
_installedListView.reSizeTo(listRect); _installedList.reSizeView(listRect);
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);
@ -351,6 +339,7 @@ void PluginsAdminDlg::collectNppCurrentStatusInfos()
bool PluginsAdminDlg::installPlugins() bool PluginsAdminDlg::installPlugins()
{ {
/*
vector<size_t> indexes = _availableListView.getCheckedIndexes(); vector<size_t> indexes = _availableListView.getCheckedIndexes();
NppParameters *pNppParameters = NppParameters::getInstance(); NppParameters *pNppParameters = NppParameters::getInstance();
@ -377,11 +366,13 @@ bool PluginsAdminDlg::installPlugins()
Process updater(updaterFullPath.c_str(), updaterParams.c_str(), updaterDir.c_str()); Process updater(updaterFullPath.c_str(), updaterParams.c_str(), updaterDir.c_str());
updater.run(); updater.run();
} }
*/
return true; return true;
} }
bool PluginsAdminDlg::updatePlugins() bool PluginsAdminDlg::updatePlugins()
{ {
/*
vector<size_t> indexes = _updateListView.getCheckedIndexes(); vector<size_t> indexes = _updateListView.getCheckedIndexes();
NppParameters *pNppParameters = NppParameters::getInstance(); NppParameters *pNppParameters = NppParameters::getInstance();
@ -406,11 +397,13 @@ bool PluginsAdminDlg::updatePlugins()
Process updater(updaterFullPath.c_str(), updaterParams.c_str(), updaterDir.c_str()); Process updater(updaterFullPath.c_str(), updaterParams.c_str(), updaterDir.c_str());
updater.run(); updater.run();
} }
*/
return true; return true;
} }
bool PluginsAdminDlg::removePlugins() bool PluginsAdminDlg::removePlugins()
{ {
/*
vector<size_t> indexes = _installedListView.getCheckedIndexes(); vector<size_t> indexes = _installedListView.getCheckedIndexes();
NppParameters *pNppParameters = NppParameters::getInstance(); NppParameters *pNppParameters = NppParameters::getInstance();
@ -433,11 +426,23 @@ bool PluginsAdminDlg::removePlugins()
Process updater(updaterFullPath.c_str(), updaterParams.c_str(), updaterDir.c_str()); Process updater(updaterFullPath.c_str(), updaterParams.c_str(), updaterDir.c_str());
updater.run(); updater.run();
} }
*/
return true; return true;
} }
void PluginViewList::pushBack(PluginUpdateInfo* pi)
{
_list.push_back(pi);
bool loadFromJson(vector<PluginUpdateInfo> & pl, const json& j) vector<generic_string> values2Add;
values2Add.push_back(pi->_displayName);
Version v = pi->_version;
values2Add.push_back(v.toString());
values2Add.push_back(TEXT("Yes"));
_ui.addLine(values2Add, reinterpret_cast<LPARAM>(pi));
}
bool loadFromJson(PluginViewList & pl, const json& j)
{ {
if (j.empty()) if (j.empty())
return false; return false;
@ -451,28 +456,29 @@ bool loadFromJson(vector<PluginUpdateInfo> & pl, const json& j)
for (const auto& i : jArray) for (const auto& i : jArray)
{ {
try { try {
PluginUpdateInfo pi; //std::unique_ptr<PluginUpdateInfo*> pi = make_unique<PluginUpdateInfo*>();
PluginUpdateInfo* pi = new PluginUpdateInfo();
string valStr = i.at("folder-name").get<std::string>(); string valStr = i.at("folder-name").get<std::string>();
pi._name = wmc->char2wchar(valStr.c_str(), CP_ACP); pi->_folderName = wmc->char2wchar(valStr.c_str(), CP_ACP);
valStr = i.at("display-name").get<std::string>(); valStr = i.at("display-name").get<std::string>();
pi._alias = wmc->char2wchar(valStr.c_str(), CP_ACP); pi->_displayName = wmc->char2wchar(valStr.c_str(), CP_ACP);
valStr = i.at("author").get<std::string>(); valStr = i.at("author").get<std::string>();
pi._author = wmc->char2wchar(valStr.c_str(), CP_ACP); pi->_author = wmc->char2wchar(valStr.c_str(), CP_ACP);
valStr = i.at("description").get<std::string>(); valStr = i.at("description").get<std::string>();
pi._description = wmc->char2wchar(valStr.c_str(), CP_ACP); pi->_description = wmc->char2wchar(valStr.c_str(), CP_ACP);
valStr = i.at("repository").get<std::string>(); valStr = i.at("repository").get<std::string>();
pi._repository = wmc->char2wchar(valStr.c_str(), CP_ACP); pi->_repository = wmc->char2wchar(valStr.c_str(), CP_ACP);
valStr = i.at("homepage").get<std::string>(); valStr = i.at("homepage").get<std::string>();
pi._homepage = wmc->char2wchar(valStr.c_str(), CP_ACP); pi->_homepage = wmc->char2wchar(valStr.c_str(), CP_ACP);
pl.push_back(pi); pl.pushBack(pi);
} }
catch (...) // Every field is mandatory. If one of property is missing, an exception is thrown then this plugin will be ignored catch (...) // Every field is mandatory. If one of property is missing, an exception is thrown then this plugin will be ignored
{ {
@ -511,72 +517,25 @@ bool PluginsAdminDlg::updateListAndLoadFromJson()
nppPluginListJson >> pluginsJson; nppPluginListJson >> pluginsJson;
// initialize available list view // initialize available list view
loadFromJson(_availablePluginList, pluginsJson); loadFromJson(_availableList, pluginsJson);
updateAvailableListView();
// initialize update list view // initialize update list view
checkUpdates(); checkUpdates();
updateUpdateListView();
// initialize installed list view // initialize installed list view
loadFromPluginInfos(); loadFromPluginInfos();
updateInstalledListView();
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);
Version v = pui._version;
values2Add.push_back(v.toString());
values2Add.push_back(TEXT("Yes"));
_availableListView.addLine(values2Add, i++);
}
}
void PluginsAdminDlg::updateInstalledListView()
{
size_t i = 0;
//
for (const auto& lpi : _installedPluginList)
{
vector<generic_string> values2Add;
values2Add.push_back(lpi._name);
Version v = lpi._version;
values2Add.push_back(v.toString());
values2Add.push_back(TEXT("Yes"));
_installedListView.addLine(values2Add, i++);
}
}
void PluginsAdminDlg::updateUpdateListView()
{
size_t i = 0;
//
for (const auto& pui : _updatePluginList)
{
vector<generic_string> values2Add;
values2Add.push_back(pui._name);
Version v = pui._version;
values2Add.push_back(v.toString());
values2Add.push_back(TEXT("Yes"));
_updateListView.addLine(values2Add, i++);
}
}
PluginUpdateInfo::PluginUpdateInfo(const generic_string& fullFilePath, const generic_string& filename) PluginUpdateInfo::PluginUpdateInfo(const generic_string& fullFilePath, const generic_string& filename)
{ {
if (not::PathFileExists(fullFilePath.c_str())) if (!::PathFileExists(fullFilePath.c_str()))
return; return;
_fullFilePath = fullFilePath; _fullFilePath = fullFilePath;
_name = filename; _displayName = filename;
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
const char *path = wmc->wchar2char(fullFilePath.c_str(), CP_ACP); const char *path = wmc->wchar2char(fullFilePath.c_str(), CP_ACP);
@ -594,8 +553,8 @@ bool PluginsAdminDlg::loadFromPluginInfos()
for (const auto& i : _pPluginsManager->_loadedDlls) for (const auto& i : _pPluginsManager->_loadedDlls)
{ {
PluginUpdateInfo pui(i._fullFilePath, i._fileName); PluginUpdateInfo* pui = new PluginUpdateInfo(i._fullFilePath, i._fileName);
_installedPluginList.push_back(pui); _installedList.pushBack(pui);
} }
return true; return true;
@ -622,7 +581,7 @@ bool PluginsAdminDlg::searchInPlugins(bool isNextMode) const
if (foundIndex == -1) if (foundIndex == -1)
return false; return false;
_availableListView.setSelection(foundIndex); _availableList.setSelection(foundIndex);
return true; return true;
} }
@ -639,9 +598,9 @@ void PluginsAdminDlg::switchDialog(int indexToSwitch)
showUpdate = false; showUpdate = false;
showInstalled = false; showInstalled = false;
long infoIndex = _availableListView.getSelectedIndex(); long infoIndex = _availableList.getSelectedIndex();
if (infoIndex != -1 && infoIndex < static_cast<long>(_availablePluginList.size())) if (infoIndex != -1 && infoIndex < static_cast<long>(_availableList.nbItem()))
desc = _availablePluginList.at(infoIndex).describe(); desc = _availableList.getPluginInfoFromIndex(infoIndex)->describe();
} }
break; break;
@ -651,9 +610,9 @@ void PluginsAdminDlg::switchDialog(int indexToSwitch)
showUpdate = true; showUpdate = true;
showInstalled = false; showInstalled = false;
long infoIndex = _updateListView.getSelectedIndex(); long infoIndex = _updateList.getSelectedIndex();
if (infoIndex != -1 && infoIndex < static_cast<long>(_updatePluginList.size())) if (infoIndex != -1 && infoIndex < static_cast<long>(_updateList.nbItem()))
desc = _updatePluginList.at(infoIndex).describe(); desc = _updateList.getPluginInfoFromIndex(infoIndex)->describe();
} }
break; break;
@ -663,9 +622,9 @@ void PluginsAdminDlg::switchDialog(int indexToSwitch)
showUpdate = false; showUpdate = false;
showInstalled = true; showInstalled = true;
long infoIndex = _installedListView.getSelectedIndex(); long infoIndex = _installedList.getSelectedIndex();
if (infoIndex != -1 && infoIndex < static_cast<long>(_installedPluginList.size())) if (infoIndex != -1 && infoIndex < static_cast<long>(_installedList.nbItem()))
desc = _installedPluginList.at(infoIndex).describe(); desc = _installedList.getPluginInfoFromIndex(infoIndex)->describe();
} }
break; break;
@ -673,9 +632,9 @@ void PluginsAdminDlg::switchDialog(int indexToSwitch)
return; return;
} }
_availableListView.display(showAvailable); _availableList.displayView(showAvailable);
_updateListView.display(showUpdate); _updateList.displayView(showUpdate);
_installedListView.display(showInstalled); _installedList.displayView(showInstalled);
::SetDlgItemText(_hSelf, IDC_PLUGINADM_EDIT, desc.c_str()); ::SetDlgItemText(_hSelf, IDC_PLUGINADM_EDIT, desc.c_str());
@ -686,7 +645,7 @@ void PluginsAdminDlg::switchDialog(int indexToSwitch)
::ShowWindow(hInstallButton, showAvailable ? SW_SHOW : SW_HIDE); ::ShowWindow(hInstallButton, showAvailable ? SW_SHOW : SW_HIDE);
if (showAvailable) if (showAvailable)
{ {
vector<size_t> checkedArray = _availableListView.getCheckedIndexes(); vector<size_t> checkedArray = _availableList.getCheckedIndexes();
showAvailable = checkedArray.size() > 0; showAvailable = checkedArray.size() > 0;
} }
::EnableWindow(hInstallButton, showAvailable); ::EnableWindow(hInstallButton, showAvailable);
@ -694,7 +653,7 @@ void PluginsAdminDlg::switchDialog(int indexToSwitch)
::ShowWindow(hUpdateButton, showUpdate ? SW_SHOW : SW_HIDE); ::ShowWindow(hUpdateButton, showUpdate ? SW_SHOW : SW_HIDE);
if (showUpdate) if (showUpdate)
{ {
vector<size_t> checkedArray = _updateListView.getCheckedIndexes(); vector<size_t> checkedArray = _updateList.getCheckedIndexes();
showUpdate = checkedArray.size() > 0; showUpdate = checkedArray.size() > 0;
} }
::EnableWindow(hUpdateButton, showUpdate); ::EnableWindow(hUpdateButton, showUpdate);
@ -702,7 +661,7 @@ void PluginsAdminDlg::switchDialog(int indexToSwitch)
::ShowWindow(hRemoveButton, showInstalled ? SW_SHOW : SW_HIDE); ::ShowWindow(hRemoveButton, showInstalled ? SW_SHOW : SW_HIDE);
if (showInstalled) if (showInstalled)
{ {
vector<size_t> checkedArray = _installedListView.getCheckedIndexes(); vector<size_t> checkedArray = _installedList.getCheckedIndexes();
showInstalled = checkedArray.size() > 0; showInstalled = checkedArray.size() > 0;
} }
::EnableWindow(hRemoveButton, showInstalled); ::EnableWindow(hRemoveButton, showInstalled);
@ -754,11 +713,9 @@ INT_PTR CALLBACK PluginsAdminDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
case IDC_PLUGINADM_REMOVE: case IDC_PLUGINADM_REMOVE:
{ {
removePlugins(); removePlugins();
return true; return true;
} }
default : default :
break; break;
} }
@ -777,30 +734,26 @@ INT_PTR CALLBACK PluginsAdminDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
switchDialog(indexClicked); switchDialog(indexClicked);
} }
} }
else if (pnmh->hwndFrom == _availableListView.getHSelf() || else if (pnmh->hwndFrom == _availableList.getViewHwnd() ||
pnmh->hwndFrom == _updateListView.getHSelf() || pnmh->hwndFrom == _updateList.getViewHwnd() ||
pnmh->hwndFrom == _installedListView.getHSelf()) pnmh->hwndFrom == _installedList.getViewHwnd())
{ {
ListView* pListView; PluginViewList* pViewList;
vector<PluginUpdateInfo>* pPluginInfos;
int buttonID; int buttonID;
if (pnmh->hwndFrom == _availableListView.getHSelf()) if (pnmh->hwndFrom == _availableList.getViewHwnd())
{ {
pListView = &_availableListView; pViewList = &_availableList;
pPluginInfos = &_availablePluginList;
buttonID = IDC_PLUGINADM_INSTALL; buttonID = IDC_PLUGINADM_INSTALL;
} }
else if (pnmh->hwndFrom == _updateListView.getHSelf()) else if (pnmh->hwndFrom == _updateList.getViewHwnd())
{ {
pListView = &_updateListView; pViewList = &_updateList;
pPluginInfos = &_updatePluginList;
buttonID = IDC_PLUGINADM_UPDATE; buttonID = IDC_PLUGINADM_UPDATE;
} }
else // pnmh->hwndFrom == _installedListView.getHSelf() else // pnmh->hwndFrom == _installedList.getViewHwnd()
{ {
pListView = &_installedListView; pViewList = &_installedList;
pPluginInfos = &_installedPluginList;
buttonID = IDC_PLUGINADM_REMOVE; buttonID = IDC_PLUGINADM_REMOVE;
} }
@ -814,15 +767,15 @@ INT_PTR CALLBACK PluginsAdminDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
(pnmv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK(1)) // unchecked (pnmv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK(1)) // unchecked
{ {
HWND hButton = ::GetDlgItem(_hSelf, buttonID); HWND hButton = ::GetDlgItem(_hSelf, buttonID);
vector<size_t> checkedArray = pListView->getCheckedIndexes(); vector<size_t> checkedArray = pViewList->getCheckedIndexes();
bool showButton = checkedArray.size() > 0; bool showButton = checkedArray.size() > 0;
::EnableWindow(hButton, showButton); ::EnableWindow(hButton, showButton);
} }
else if (pnmv->uNewState & LVIS_SELECTED) else if (pnmv->uNewState & LVIS_SELECTED)
{ {
size_t infoIndex = pListView->getLParamFromIndex(pnmv->iItem); PluginUpdateInfo* pui = pViewList->getPluginInfoFromIndex(pnmv->iItem);
generic_string desc = pPluginInfos->at(infoIndex).describe(); generic_string desc = pui->describe();
::SetDlgItemText(_hSelf, IDC_PLUGINADM_EDIT, desc.c_str()); ::SetDlgItemText(_hSelf, IDC_PLUGINADM_EDIT, desc.c_str());
} }
} }

View File

@ -50,15 +50,15 @@ struct PluginUpdateInfo
{ {
generic_string _fullFilePath; generic_string _fullFilePath;
generic_string _id; generic_string _folderName;
generic_string _name; generic_string _displayName;
Version _version; Version _version;
generic_string _homepage; generic_string _homepage;
generic_string _sourceUrl; generic_string _sourceUrl;
generic_string _description; generic_string _description;
generic_string _author; generic_string _author;
generic_string _md5; generic_string _md5;
generic_string _alias; generic_string _id;
generic_string _repository; generic_string _repository;
generic_string describe(); generic_string describe();
@ -84,15 +84,41 @@ struct NppCurrentStatus
bool shouldLaunchInAdmMode() { return _isInProgramFiles; }; bool shouldLaunchInAdmMode() { return _isInProgramFiles; };
}; };
class PluginViewList
{
public:
PluginViewList() {};
~PluginViewList() {
_ui.destroy();
for (auto i : _list)
{
delete i;
}
};
void pushBack(PluginUpdateInfo* pi);
HWND getViewHwnd() { return _ui.getHSelf(); };
void displayView(bool doShow) const { _ui.display(doShow); };
std::vector<size_t> getCheckedIndexes() const { return _ui.getCheckedIndexes(); };
long getSelectedIndex() const { return _ui.getSelectedIndex(); };
void setSelection(int index) const { _ui.setSelection(index); };
void initView(HINSTANCE hInst, HWND parent) { _ui.init(hInst, parent); };
void addColumn(const columnInfo & column2Add) { _ui.addColumn(column2Add); };
void reSizeView(RECT & rc) { _ui.reSizeTo(rc); }
void setViewStyleOption(int32_t extraStyle) { _ui.setStyleOption(extraStyle); };
size_t nbItem() const { return _ui.nbItem(); };
PluginUpdateInfo* getPluginInfoFromIndex(int index) const { return reinterpret_cast<PluginUpdateInfo*>(_ui.getLParamFromIndex(index)); };
private:
std::vector<PluginUpdateInfo*> _list;
ListView _ui;
};
class PluginsAdminDlg final : public StaticDialog class PluginsAdminDlg final : public StaticDialog
{ {
public : public :
PluginsAdminDlg() {}; PluginsAdminDlg() {};
~PluginsAdminDlg() { ~PluginsAdminDlg() {}
_availableListView.destroy();
_updateListView.destroy();
_installedListView.destroy();
}
void init(HINSTANCE hInst, HWND parent) { void init(HINSTANCE hInst, HWND parent) {
Window::init(hInst, parent); Window::init(hInst, parent);
}; };
@ -113,13 +139,9 @@ public :
}; };
void switchDialog(int indexToSwitch); void switchDialog(int indexToSwitch);
bool updateListAndLoadFromJson(); // call GitUup for the 1st time
void updateAvailableListView();
void updateInstalledListView();
void updateUpdateListView();
void setPluginsManager(PluginsManager *pluginsManager) { _pPluginsManager = pluginsManager; }; void setPluginsManager(PluginsManager *pluginsManager) { _pPluginsManager = pluginsManager; };
bool updateListAndLoadFromJson();
void setAdminMode(bool isAdm) { _nppCurrentStatus._isAdminMode = isAdm; }; void setAdminMode(bool isAdm) { _nppCurrentStatus._isAdminMode = isAdm; };
bool installPlugins(); bool installPlugins();
@ -132,27 +154,25 @@ protected:
private : private :
TabBar _tab; TabBar _tab;
ListView _availableListView; PluginViewList _availableList; // All plugins (pluginList.json) - installed plugins
ListView _updateListView; PluginViewList _updateList; // A list returned by gitup.exe
ListView _installedListView; PluginViewList _installedList; // for each installed plugin, check its json file
std::vector<PluginUpdateInfo> _availablePluginList; // All plugins (pluginList.json) - installed plugins
std::vector<PluginUpdateInfo> _updatePluginList; // A list returned by gitup.exe
std::vector<PluginUpdateInfo> _installedPluginList; // for each installed plugin, check its json file
PluginsManager *_pPluginsManager = nullptr; PluginsManager *_pPluginsManager = nullptr;
NppCurrentStatus _nppCurrentStatus; NppCurrentStatus _nppCurrentStatus;
void collectNppCurrentStatusInfos(); void collectNppCurrentStatusInfos();
bool searchInPlugins(bool isNextMode) const; bool searchInPlugins(bool isNextMode) const;
const bool inNames = true; const bool _inNames = true;
const bool inDescs = false; const bool _inDescs = false;
bool isFoundInAvailableListFromIndex(int index, generic_string str2search, bool inWhichPart) const;
long searchFromCurrentSel(generic_string str2search, bool inWhichPart, bool isNextMode) const; long searchFromCurrentSel(generic_string str2search, bool inWhichPart, bool isNextMode) const;
long searchInNamesFromCurrentSel(generic_string str2search, bool isNextMode) const { long searchInNamesFromCurrentSel(generic_string str2search, bool isNextMode) const {
return searchFromCurrentSel(str2search, inNames, isNextMode); return searchFromCurrentSel(str2search, _inNames, isNextMode);
}; };
long searchInDescsFromCurrentSel(generic_string str2search, bool isNextMode) const { long searchInDescsFromCurrentSel(generic_string str2search, bool isNextMode) const {
return searchFromCurrentSel(str2search, inDescs, isNextMode); return searchFromCurrentSel(str2search, _inDescs, isNextMode);
}; };
bool loadFromPluginInfos(); bool loadFromPluginInfos();