mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 15:32:59 +02:00
CMenuOptionChooser: Add alphanumeric sort option
- default is false - Activate by OptionsSort = true
This commit is contained in:
@@ -1269,7 +1269,7 @@ int CMenuOptionNumberChooser::getWidth(void)
|
|||||||
return width + 10; /* min 10 pixels between option name and value. enough? */
|
return width + 10; /* min 10 pixels between option name and value. enough? */
|
||||||
}
|
}
|
||||||
|
|
||||||
CMenuOptionChooser::CMenuOptionChooser(const neutrino_locale_t OptionName, int * const OptionValue, const struct keyval * const Options, const unsigned Number_Of_Options, const bool Active, CChangeObserver * const Observ, const neutrino_msg_t DirectKey, const std::string & IconName, bool Pulldown)
|
CMenuOptionChooser::CMenuOptionChooser(const neutrino_locale_t OptionName, int * const OptionValue, const struct keyval * const Options, const unsigned Number_Of_Options, const bool Active, CChangeObserver * const Observ, const neutrino_msg_t DirectKey, const std::string & IconName, bool Pulldown, bool OptionsSort)
|
||||||
{
|
{
|
||||||
height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
|
height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
|
||||||
optionNameString = g_Locale->getText(OptionName);
|
optionNameString = g_Locale->getText(OptionName);
|
||||||
@@ -1280,7 +1280,8 @@ CMenuOptionChooser::CMenuOptionChooser(const neutrino_locale_t OptionName, int *
|
|||||||
observ = Observ;
|
observ = Observ;
|
||||||
directKey = DirectKey;
|
directKey = DirectKey;
|
||||||
iconName = IconName;
|
iconName = IconName;
|
||||||
pulldown = Pulldown;
|
pulldown = Pulldown;
|
||||||
|
optionsSort = OptionsSort;
|
||||||
for (unsigned int i = 0; i < number_of_options; i++)
|
for (unsigned int i = 0; i < number_of_options; i++)
|
||||||
{
|
{
|
||||||
struct keyval_ext opt;
|
struct keyval_ext opt;
|
||||||
@@ -1291,7 +1292,7 @@ CMenuOptionChooser::CMenuOptionChooser(const neutrino_locale_t OptionName, int *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CMenuOptionChooser::CMenuOptionChooser(const char* OptionName, int * const OptionValue, const struct keyval * const Options, const unsigned Number_Of_Options, const bool Active, CChangeObserver * const Observ, const neutrino_msg_t DirectKey, const std::string & IconName, bool Pulldown)
|
CMenuOptionChooser::CMenuOptionChooser(const char* OptionName, int * const OptionValue, const struct keyval * const Options, const unsigned Number_Of_Options, const bool Active, CChangeObserver * const Observ, const neutrino_msg_t DirectKey, const std::string & IconName, bool Pulldown, bool OptionsSort)
|
||||||
{
|
{
|
||||||
height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
|
height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
|
||||||
optionNameString = OptionName;
|
optionNameString = OptionName;
|
||||||
@@ -1302,7 +1303,8 @@ CMenuOptionChooser::CMenuOptionChooser(const char* OptionName, int * const Optio
|
|||||||
observ = Observ;
|
observ = Observ;
|
||||||
directKey = DirectKey;
|
directKey = DirectKey;
|
||||||
iconName = IconName;
|
iconName = IconName;
|
||||||
pulldown = Pulldown;
|
pulldown = Pulldown;
|
||||||
|
optionsSort = OptionsSort;
|
||||||
for (unsigned int i = 0; i < number_of_options; i++)
|
for (unsigned int i = 0; i < number_of_options; i++)
|
||||||
{
|
{
|
||||||
struct keyval_ext opt;
|
struct keyval_ext opt;
|
||||||
@@ -1315,7 +1317,7 @@ CMenuOptionChooser::CMenuOptionChooser(const char* OptionName, int * const Optio
|
|||||||
|
|
||||||
CMenuOptionChooser::CMenuOptionChooser(const neutrino_locale_t OptionName, int * const OptionValue, const struct keyval_ext * const Options,
|
CMenuOptionChooser::CMenuOptionChooser(const neutrino_locale_t OptionName, int * const OptionValue, const struct keyval_ext * const Options,
|
||||||
const unsigned Number_Of_Options, const bool Active, CChangeObserver * const Observ,
|
const unsigned Number_Of_Options, const bool Active, CChangeObserver * const Observ,
|
||||||
const neutrino_msg_t DirectKey, const std::string & IconName, bool Pulldown)
|
const neutrino_msg_t DirectKey, const std::string & IconName, bool Pulldown, bool OptionsSort)
|
||||||
{
|
{
|
||||||
height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
|
height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
|
||||||
optionNameString = g_Locale->getText(OptionName);
|
optionNameString = g_Locale->getText(OptionName);
|
||||||
@@ -1326,14 +1328,15 @@ CMenuOptionChooser::CMenuOptionChooser(const neutrino_locale_t OptionName, int *
|
|||||||
observ = Observ;
|
observ = Observ;
|
||||||
directKey = DirectKey;
|
directKey = DirectKey;
|
||||||
iconName = IconName;
|
iconName = IconName;
|
||||||
pulldown = Pulldown;
|
pulldown = Pulldown;
|
||||||
|
optionsSort = OptionsSort;
|
||||||
for (unsigned int i = 0; i < number_of_options; i++)
|
for (unsigned int i = 0; i < number_of_options; i++)
|
||||||
options.push_back(Options[i]);
|
options.push_back(Options[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMenuOptionChooser::CMenuOptionChooser(const char* OptionName, int * const OptionValue, const struct keyval_ext * const Options,
|
CMenuOptionChooser::CMenuOptionChooser(const char* OptionName, int * const OptionValue, const struct keyval_ext * const Options,
|
||||||
const unsigned Number_Of_Options, const bool Active, CChangeObserver * const Observ,
|
const unsigned Number_Of_Options, const bool Active, CChangeObserver * const Observ,
|
||||||
const neutrino_msg_t DirectKey, const std::string & IconName, bool Pulldown)
|
const neutrino_msg_t DirectKey, const std::string & IconName, bool Pulldown, bool OptionsSort)
|
||||||
{
|
{
|
||||||
height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
|
height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
|
||||||
optionNameString = OptionName;
|
optionNameString = OptionName;
|
||||||
@@ -1344,7 +1347,8 @@ CMenuOptionChooser::CMenuOptionChooser(const char* OptionName, int * const Optio
|
|||||||
observ = Observ;
|
observ = Observ;
|
||||||
directKey = DirectKey;
|
directKey = DirectKey;
|
||||||
iconName = IconName;
|
iconName = IconName;
|
||||||
pulldown = Pulldown;
|
pulldown = Pulldown;
|
||||||
|
optionsSort = OptionsSort;
|
||||||
for (unsigned int i = 0; i < number_of_options; i++)
|
for (unsigned int i = 0; i < number_of_options; i++)
|
||||||
options.push_back(Options[i]);
|
options.push_back(Options[i]);
|
||||||
}
|
}
|
||||||
@@ -1352,6 +1356,7 @@ CMenuOptionChooser::CMenuOptionChooser(const char* OptionName, int * const Optio
|
|||||||
CMenuOptionChooser::~CMenuOptionChooser()
|
CMenuOptionChooser::~CMenuOptionChooser()
|
||||||
{
|
{
|
||||||
options.clear();
|
options.clear();
|
||||||
|
clearChooserOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMenuOptionChooser::setOptionValue(const int newvalue)
|
void CMenuOptionChooser::setOptionValue(const int newvalue)
|
||||||
@@ -1364,12 +1369,41 @@ int CMenuOptionChooser::getOptionValue(void) const
|
|||||||
return *optionValue;
|
return *optionValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMenuOptionChooser::clearChooserOptions()
|
||||||
|
{
|
||||||
|
for (std::vector<CMenuOptionChooserOptions*>::iterator it = option_chooser_options_v.begin(); it != option_chooser_options_v.end(); ++it)
|
||||||
|
delete *it;
|
||||||
|
|
||||||
|
option_chooser_options_v.clear();
|
||||||
|
}
|
||||||
|
|
||||||
int CMenuOptionChooser::exec(CMenuTarget*)
|
int CMenuOptionChooser::exec(CMenuTarget*)
|
||||||
{
|
{
|
||||||
bool wantsRepaint = false;
|
bool wantsRepaint = false;
|
||||||
int ret = menu_return::RETURN_NONE;
|
int ret = menu_return::RETURN_NONE;
|
||||||
|
|
||||||
|
if (optionsSort) {
|
||||||
|
clearChooserOptions();
|
||||||
|
unsigned int i1;
|
||||||
|
for (i1 = 0; i1 < number_of_options; i1++)
|
||||||
|
{
|
||||||
|
CMenuOptionChooserOptions* co = new CMenuOptionChooserOptions();
|
||||||
|
co->key = options[i1].key;
|
||||||
|
co->valname = (options[i1].valname != 0) ? options[i1].valname : g_Locale->getText(options[i1].value);
|
||||||
|
option_chooser_options_v.push_back(co);
|
||||||
|
}
|
||||||
|
|
||||||
|
sort(option_chooser_options_v.begin(), option_chooser_options_v.end(), CMenuOptionChooserCompareItem());
|
||||||
|
|
||||||
|
i1 = 0;
|
||||||
|
for (std::vector<CMenuOptionChooserOptions*>::iterator it = option_chooser_options_v.begin(); it != option_chooser_options_v.end() && i1 < number_of_options; ++it) {
|
||||||
|
options[i1].key = (*it)->key;
|
||||||
|
options[i1].value = NONEXISTANT_LOCALE;
|
||||||
|
options[i1].valname = (*it)->valname.c_str();
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if((msg == CRCInput::RC_ok) && pulldown) {
|
if((msg == CRCInput::RC_ok) && pulldown) {
|
||||||
int select = -1;
|
int select = -1;
|
||||||
char cnt[5];
|
char cnt[5];
|
||||||
|
@@ -313,6 +313,26 @@ private:
|
|||||||
void setNumberFormat(std::string (*fun)(int)) { numberFormatFunction = fun; }
|
void setNumberFormat(std::string (*fun)(int)) { numberFormatFunction = fun; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CMenuOptionChooserOptions
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int key;
|
||||||
|
std::string valname;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CMenuOptionChooserCompareItem: public std::binary_function <const CMenuOptionChooserOptions * const, const CMenuOptionChooserOptions * const, bool>
|
||||||
|
{
|
||||||
|
static bool cmpToLower(const char a, const char b)
|
||||||
|
{
|
||||||
|
return tolower(a) < tolower(b);
|
||||||
|
};
|
||||||
|
|
||||||
|
bool operator() (const CMenuOptionChooserOptions * const c1, CMenuOptionChooserOptions * const c2)
|
||||||
|
{
|
||||||
|
return std::lexicographical_compare(c1->valname.begin(), c1->valname.end(), c2->valname.begin(), c2->valname.end(), cmpToLower);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
class CMenuOptionChooser : public CAbstractMenuOptionChooser
|
class CMenuOptionChooser : public CAbstractMenuOptionChooser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -331,28 +351,32 @@ class CMenuOptionChooser : public CAbstractMenuOptionChooser
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<keyval_ext> options;
|
std::vector<keyval_ext> options;
|
||||||
|
std::vector<CMenuOptionChooserOptions*> option_chooser_options_v;
|
||||||
unsigned number_of_options;
|
unsigned number_of_options;
|
||||||
CChangeObserver * observ;
|
CChangeObserver * observ;
|
||||||
std::string optionNameString;
|
std::string optionNameString;
|
||||||
bool pulldown;
|
bool pulldown;
|
||||||
|
bool optionsSort;
|
||||||
|
|
||||||
|
void clearChooserOptions();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CMenuOptionChooser(const neutrino_locale_t OptionName, int * const OptionValue, const struct keyval * const Options,
|
CMenuOptionChooser(const neutrino_locale_t OptionName, int * const OptionValue, const struct keyval * const Options,
|
||||||
const unsigned Number_Of_Options, const bool Active = false, CChangeObserver * const Observ = NULL,
|
const unsigned Number_Of_Options, const bool Active = false, CChangeObserver * const Observ = NULL,
|
||||||
const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const std::string & IconName= "",
|
const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const std::string & IconName= "",
|
||||||
bool Pulldown = false);
|
bool Pulldown = false, bool OptionsSort = false);
|
||||||
CMenuOptionChooser(const neutrino_locale_t OptionName, int * const OptionValue, const struct keyval_ext * const Options,
|
CMenuOptionChooser(const neutrino_locale_t OptionName, int * const OptionValue, const struct keyval_ext * const Options,
|
||||||
const unsigned Number_Of_Options, const bool Active = false, CChangeObserver * const Observ = NULL,
|
const unsigned Number_Of_Options, const bool Active = false, CChangeObserver * const Observ = NULL,
|
||||||
const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const std::string & IconName= "",
|
const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const std::string & IconName= "",
|
||||||
bool Pulldown = false);
|
bool Pulldown = false, bool OptionsSort = false);
|
||||||
CMenuOptionChooser(const char* OptionName, int * const OptionValue, const struct keyval * const Options,
|
CMenuOptionChooser(const char* OptionName, int * const OptionValue, const struct keyval * const Options,
|
||||||
const unsigned Number_Of_Options, const bool Active = false, CChangeObserver * const Observ = NULL,
|
const unsigned Number_Of_Options, const bool Active = false, CChangeObserver * const Observ = NULL,
|
||||||
const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const std::string & IconName= "",
|
const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const std::string & IconName= "",
|
||||||
bool Pulldown = false);
|
bool Pulldown = false, bool OptionsSort = false);
|
||||||
CMenuOptionChooser(const char* OptionName, int * const OptionValue, const struct keyval_ext * const Options,
|
CMenuOptionChooser(const char* OptionName, int * const OptionValue, const struct keyval_ext * const Options,
|
||||||
const unsigned Number_Of_Options, const bool Active = false, CChangeObserver * const Observ = NULL,
|
const unsigned Number_Of_Options, const bool Active = false, CChangeObserver * const Observ = NULL,
|
||||||
const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const std::string & IconName= "",
|
const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const std::string & IconName= "",
|
||||||
bool Pulldown = false);
|
bool Pulldown = false, bool OptionsSort = false);
|
||||||
~CMenuOptionChooser();
|
~CMenuOptionChooser();
|
||||||
|
|
||||||
void setOptionValue(const int newvalue);
|
void setOptionValue(const int newvalue);
|
||||||
|
Reference in New Issue
Block a user