List plugins in alphabetical order in Plugins Admin dialog

This commit is contained in:
Don HO 2019-01-14 19:57:54 +01:00
parent 70dee50dc7
commit fd32585c14
5 changed files with 53 additions and 2 deletions

View File

@ -120,6 +120,37 @@ void ListView::addLine(const vector<generic_string> & values2Add, LPARAM lParam,
} }
} }
size_t ListView::findAlphabeticalOrderPos(const generic_string& string2Cmp, SortDirection sortDir)
{
size_t nbItem = ListView_GetItemCount(_hSelf);
if (!nbItem)
return 0;
for (size_t i = 0; i < nbItem; ++i)
{
TCHAR str[MAX_PATH];
ListView_GetItemText(_hSelf, i, 0, str, sizeof(str));
int res = lstrcmp(string2Cmp.c_str(), str);
if (res < 0) // string2Cmp < str
{
if (sortDir == sortEncrease)
{
return i;
}
}
else // str2Cmp >= str
{
if (sortDir == sortDecrease)
{
return i;
}
}
}
return nbItem;
}
LPARAM ListView::getLParamFromIndex(int itemIndex) const LPARAM ListView::getLParamFromIndex(int itemIndex) const
{ {

View File

@ -46,6 +46,10 @@ public:
ListView() : Window() {}; ListView() : Window() {};
virtual ~ListView() {}; virtual ~ListView() {};
enum SortDirection {
sortEncrease = 0,
sortDecrease = 1
};
// addColumn() should be called before init() // addColumn() should be called before init()
void addColumn(const columnInfo & column2Add) { void addColumn(const columnInfo & column2Add) {
_columnInfos.push_back(column2Add); _columnInfos.push_back(column2Add);
@ -63,6 +67,8 @@ public:
_extraStyle = extraStyle; _extraStyle = extraStyle;
}; };
size_t findAlphabeticalOrderPos(const generic_string& string2search, SortDirection sortDir);
void addLine(const std::vector<generic_string> & values2Add, LPARAM lParam = 0, int pos2insert = -1); void addLine(const std::vector<generic_string> & values2Add, LPARAM lParam = 0, int pos2insert = -1);
size_t nbItem() const { size_t nbItem() const {

View File

@ -607,7 +607,10 @@ void PluginViewList::pushBack(PluginUpdateInfo* pi)
Version v = pi->_version; Version v = pi->_version;
values2Add.push_back(v.toString()); values2Add.push_back(v.toString());
//values2Add.push_back(TEXT("Yes")); //values2Add.push_back(TEXT("Yes"));
_ui.addLine(values2Add, reinterpret_cast<LPARAM>(pi));
// add in order
size_t i = _ui.findAlphabeticalOrderPos(pi->_displayName, _sortType == DISPLAY_NAME_ALPHABET_ENCREASE ? _ui.sortEncrease : _ui.sortDecrease);
_ui.addLine(values2Add, reinterpret_cast<LPARAM>(pi), i);
} }
bool loadFromJson(PluginViewList & pl, const json& j) bool loadFromJson(PluginViewList & pl, const json& j)

View File

@ -112,6 +112,16 @@ struct NppCurrentStatus
}; };
enum COLUMN_TYPE { COLUMN_PLUGIN, COLUMN_VERSION }; enum COLUMN_TYPE { COLUMN_PLUGIN, COLUMN_VERSION };
enum SORT_TYPE { DISPLAY_NAME_ALPHABET_ENCREASE, DISPLAY_NAME_ALPHABET_DECREASE };
struct SortDisplayNameDecrease final
{
bool operator() (PluginUpdateInfo* l, PluginUpdateInfo* r)
{
return (l->_displayName.compare(r->_displayName) <= 0);
}
};
class PluginViewList class PluginViewList
{ {
@ -151,6 +161,8 @@ public:
private: private:
std::vector<PluginUpdateInfo*> _list; std::vector<PluginUpdateInfo*> _list;
ListView _ui; ListView _ui;
SORT_TYPE _sortType = DISPLAY_NAME_ALPHABET_ENCREASE;
}; };
enum LIST_TYPE { AVAILABLE_LIST, UPDATES_LIST, INSTALLED_LIST }; enum LIST_TYPE { AVAILABLE_LIST, UPDATES_LIST, INSTALLED_LIST };

View File

@ -30,7 +30,6 @@
#include "VerticalFileSwitcher.h" #include "VerticalFileSwitcher.h"
#include "menuCmdID.h" #include "menuCmdID.h"
#include "Parameters.h" #include "Parameters.h"
//#include "localization.h"
int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{ {