new option for song format - right align (thx to Nathan Jones)
This commit is contained in:
@@ -40,6 +40,7 @@
|
|||||||
## %p - performer
|
## %p - performer
|
||||||
## %d - disc
|
## %d - disc
|
||||||
## %C - comment
|
## %C - comment
|
||||||
|
## %r - begin right align
|
||||||
##
|
##
|
||||||
## you can also put them in { } and then it will be displayed
|
## you can also put them in { } and then it will be displayed
|
||||||
## only if all requested values are available and/or define alternate
|
## only if all requested values are available and/or define alternate
|
||||||
|
|||||||
@@ -215,12 +215,12 @@ string TotalPlaylistLength()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string DisplayStringPair(const StringPair &pair, void *null)
|
string DisplayStringPair(const StringPair &pair, void *, const Menu<StringPair> *)
|
||||||
{
|
{
|
||||||
return pair.first;
|
return pair.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
string DisplayItem(const Item &item, void *)
|
string DisplayItem(const Item &item, void *, const Menu<Item> *menu)
|
||||||
{
|
{
|
||||||
switch (item.type)
|
switch (item.type)
|
||||||
{
|
{
|
||||||
@@ -232,7 +232,8 @@ string DisplayItem(const Item &item, void *)
|
|||||||
return "[" + (slash != string::npos ? item.name.substr(slash+1) : item.name) + "]";
|
return "[" + (slash != string::npos ? item.name.substr(slash+1) : item.name) + "]";
|
||||||
}
|
}
|
||||||
case itSong:
|
case itSong:
|
||||||
return DisplaySong(*item.song);
|
// I know casting that way is ugly etc., but it works.
|
||||||
|
return DisplaySong(*item.song, &Config.song_list_format, (const Menu<Song> *)menu);
|
||||||
case itPlaylist:
|
case itPlaylist:
|
||||||
return Config.browser_playlist_prefix + item.name;
|
return Config.browser_playlist_prefix + item.name;
|
||||||
}
|
}
|
||||||
@@ -310,7 +311,7 @@ string DisplayColumns(string song_template)
|
|||||||
return result.substr(0, COLS);
|
return result.substr(0, COLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
string DisplaySongInColumns(const Song &s, void *s_template)
|
string DisplaySongInColumns(const Song &s, void *s_template, const Menu<Song> *)
|
||||||
{
|
{
|
||||||
string song_template = s_template ? *static_cast<string *>(s_template) : "";
|
string song_template = s_template ? *static_cast<string *>(s_template) : "";
|
||||||
|
|
||||||
@@ -402,12 +403,14 @@ string DisplaySongInColumns(const Song &s, void *s_template)
|
|||||||
return TO_STRING(result);
|
return TO_STRING(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
string DisplaySong(const Song &s, void *s_template)
|
string DisplaySong(const Song &s, void *s_template, const Menu<Song> *menu)
|
||||||
{
|
{
|
||||||
const string &song_template = s_template ? *static_cast<string *>(s_template) : "";
|
const string &song_template = s_template ? *static_cast<string *>(s_template) : "";
|
||||||
string result;
|
string result;
|
||||||
|
string lresult;
|
||||||
bool link_tags = 0;
|
bool link_tags = 0;
|
||||||
bool tags_present = 0;
|
bool tags_present = 0;
|
||||||
|
bool right = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (string::const_iterator it = song_template.begin(); it != song_template.end(); it++)
|
for (string::const_iterator it = song_template.begin(); it != song_template.end(); it++)
|
||||||
@@ -656,10 +659,24 @@ string DisplaySong(const Song &s, void *s_template)
|
|||||||
result += s.GetTitle();
|
result += s.GetTitle();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'r':
|
||||||
|
{
|
||||||
|
if (!right)
|
||||||
|
{
|
||||||
|
right = 1;
|
||||||
|
lresult = result;
|
||||||
|
result = "";
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (right && menu)
|
||||||
|
{
|
||||||
|
result = lresult + "[." + IntoStr(menu->GetWidth()-Window::RealLength(result)) + "]" + result;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,11 +48,11 @@ bool Keypressed(int, const int *);
|
|||||||
void WindowTitle(const string &);
|
void WindowTitle(const string &);
|
||||||
|
|
||||||
string TotalPlaylistLength();
|
string TotalPlaylistLength();
|
||||||
string DisplayStringPair(const StringPair &, void * = NULL);
|
string DisplayStringPair(const StringPair &, void *, const Menu<StringPair> *);
|
||||||
string DisplayItem(const Item &, void * = NULL);
|
string DisplayItem(const Item &, void *, const Menu<Item> *);
|
||||||
string DisplayColumns(string);
|
string DisplayColumns(string);
|
||||||
string DisplaySongInColumns(const Song &, void *);
|
string DisplaySongInColumns(const Song &, void *, const Menu<Song> *);
|
||||||
string DisplaySong(const Song &, void * = &Config.song_list_format);
|
string DisplaySong(const Song &, void * = &Config.song_list_format, const Menu<Song> * = NULL);
|
||||||
string GetInfo(Song &);
|
string GetInfo(Song &);
|
||||||
void ShowMessage(const string &, int = Config.message_delay_time);
|
void ShowMessage(const string &, int = Config.message_delay_time);
|
||||||
void GetDirectory(string, string = "/");
|
void GetDirectory(string, string = "/");
|
||||||
|
|||||||
51
src/menu.h
51
src/menu.h
@@ -45,7 +45,7 @@ class Menu : public Window
|
|||||||
{
|
{
|
||||||
typedef typename vector<Option<T> *>::iterator T_iterator;
|
typedef typename vector<Option<T> *>::iterator T_iterator;
|
||||||
typedef typename vector<Option<T> *>::const_iterator T_const_iterator;
|
typedef typename vector<Option<T> *>::const_iterator T_const_iterator;
|
||||||
typedef string (*ItemDisplayer) (const T &, void *);
|
typedef string (*ItemDisplayer) (const T &, void *, const Menu<T> *);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Menu(int startx, int starty, int width, int height, string title, Color color, Border border) : itsItemDisplayer(0), itsItemDisplayerUserdata(0), Window(startx, starty, width, height, title, color, border), itsSelectedPrefix("[.r]"), itsSelectedSuffix("[/r]"), itsStaticsNumber(0), itsBeginning(0), itsHighlight(0), itsHighlightColor(itsBaseColor), itsHighlightEnabled(1) { }
|
Menu(int startx, int starty, int width, int height, string title, Color color, Border border) : itsItemDisplayer(0), itsItemDisplayerUserdata(0), Window(startx, starty, width, height, title, color, border), itsSelectedPrefix("[.r]"), itsSelectedSuffix("[/r]"), itsStaticsNumber(0), itsBeginning(0), itsHighlight(0), itsHighlightColor(itsBaseColor), itsHighlightEnabled(1) { }
|
||||||
@@ -100,6 +100,7 @@ class Menu : public Window
|
|||||||
const T & at(int i) const { return itsOptions.at(i)->item; }
|
const T & at(int i) const { return itsOptions.at(i)->item; }
|
||||||
const T & operator[](int i) const { return itsOptions[i]->item; }
|
const T & operator[](int i) const { return itsOptions[i]->item; }
|
||||||
T & operator[](int i) { return itsOptions[i]->item; }
|
T & operator[](int i) { return itsOptions[i]->item; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
string DisplayOption(const T &t) const;
|
string DisplayOption(const T &t) const;
|
||||||
ItemDisplayer itsItemDisplayer;
|
ItemDisplayer itsItemDisplayer;
|
||||||
@@ -112,7 +113,6 @@ class Menu : public Window
|
|||||||
string itsSelectedSuffix;
|
string itsSelectedSuffix;
|
||||||
|
|
||||||
int itsStaticsNumber;
|
int itsStaticsNumber;
|
||||||
int count_length(string);
|
|
||||||
|
|
||||||
void redraw_screen();
|
void redraw_screen();
|
||||||
bool is_static() { return itsOptions[itsHighlight]->is_static; }
|
bool is_static() { return itsOptions[itsHighlight]->is_static; }
|
||||||
@@ -152,49 +152,6 @@ Menu<T>::~Menu()
|
|||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
|
||||||
int Menu<T>::count_length(string str)
|
|
||||||
{
|
|
||||||
if (str.empty())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
bool collect = false;
|
|
||||||
int length = 0;
|
|
||||||
|
|
||||||
#ifdef UTF8_ENABLED
|
|
||||||
wstring str2 = ToWString(str);
|
|
||||||
wstring tmp;
|
|
||||||
#else
|
|
||||||
string &str2 = str;
|
|
||||||
string tmp;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (int i = 0; i < str2.length(); i++, length++)
|
|
||||||
{
|
|
||||||
if (str2[i] == '[' && (str2[i+1] == '.' || str2[i+1] == '/'))
|
|
||||||
collect = 1;
|
|
||||||
|
|
||||||
if (collect)
|
|
||||||
{
|
|
||||||
if (str2[i] != '[')
|
|
||||||
tmp += str2[i];
|
|
||||||
else
|
|
||||||
tmp = str2[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str2[i] == ']')
|
|
||||||
collect = 0;
|
|
||||||
|
|
||||||
if (!collect && !tmp.empty())
|
|
||||||
{
|
|
||||||
if (IsValidColor(TO_STRING(tmp)))
|
|
||||||
length -= tmp.length();
|
|
||||||
tmp.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void Menu<T>::AddOption(const T &item, bool bold, bool is_static, bool separator, Location location)
|
void Menu<T>::AddOption(const T &item, bool bold, bool is_static, bool separator, Location location)
|
||||||
{
|
{
|
||||||
@@ -399,7 +356,7 @@ void Menu<T>::Refresh(bool redraw_whole_window)
|
|||||||
|
|
||||||
string option = DisplayOption(itsOptions[*it]->item);
|
string option = DisplayOption(itsOptions[*it]->item);
|
||||||
|
|
||||||
int strlength = itsOptions[*it]->location != lLeft && BBEnabled ? count_length(option) : option.length();
|
int strlength = itsOptions[*it]->location != lLeft && BBEnabled ? Window::RealLength(option) : option.length();
|
||||||
|
|
||||||
if (strlength)
|
if (strlength)
|
||||||
{
|
{
|
||||||
@@ -733,7 +690,7 @@ Window * Menu<T>::EmptyClone() const
|
|||||||
template <class T>
|
template <class T>
|
||||||
string Menu<T>::DisplayOption(const T &t) const
|
string Menu<T>::DisplayOption(const T &t) const
|
||||||
{
|
{
|
||||||
return itsItemDisplayer ? itsItemDisplayer(t, itsItemDisplayerUserdata) : "";
|
return itsItemDisplayer ? itsItemDisplayer(t, itsItemDisplayerUserdata, this) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ extern Menu< std::pair<string, Song> > *mSearcher;
|
|||||||
bool search_match_to_pattern = 1;
|
bool search_match_to_pattern = 1;
|
||||||
bool search_case_sensitive = 1;
|
bool search_case_sensitive = 1;
|
||||||
|
|
||||||
string SearchEngineDisplayer(const std::pair<string, Song> &pair, void *null)
|
string SearchEngineDisplayer(const std::pair<string, Song> &pair, void *, const Menu< std::pair<string, Song> > *)
|
||||||
{
|
{
|
||||||
return pair.first == "." ? DisplaySong(pair.second) : pair.first;
|
return pair.first == "." ? DisplaySong(pair.second) : pair.first;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
const int search_engine_static_options = 17;
|
const int search_engine_static_options = 17;
|
||||||
|
|
||||||
string SearchEngineDisplayer(const std::pair<string, Song> &, void * = NULL);
|
string SearchEngineDisplayer(const std::pair<string, Song> &, void *, const Menu< std::pair<string, Song> > *);
|
||||||
void UpdateFoundList();
|
void UpdateFoundList();
|
||||||
void PrepareSearchEngine(Song &s);
|
void PrepareSearchEngine(Song &s);
|
||||||
void Search(Song &);
|
void Search(Song &);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ string FindSharedDir(const SongList &v)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string DisplayTag(const Song &s, void *data)
|
string DisplayTag(const Song &s, void *data, const Menu<Song> *null)
|
||||||
{
|
{
|
||||||
switch (static_cast<Menu<string> *>(data)->GetChoice())
|
switch (static_cast<Menu<string> *>(data)->GetChoice())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ typedef void (Song::*SongSetFunction)(const string &);
|
|||||||
|
|
||||||
string FindSharedDir(Menu<Song> *);
|
string FindSharedDir(Menu<Song> *);
|
||||||
string FindSharedDir(const SongList &);
|
string FindSharedDir(const SongList &);
|
||||||
string DisplayTag(const Song &, void *);
|
string DisplayTag(const Song &, void *, const Menu<Song> *);
|
||||||
|
|
||||||
bool GetSongTags(Song &);
|
bool GetSongTags(Song &);
|
||||||
bool WriteTags(Song &);
|
bool WriteTags(Song &);
|
||||||
|
|||||||
@@ -740,6 +740,48 @@ string Window::OmitBBCodes(const string &str)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Window::RealLength(const string &str)
|
||||||
|
{
|
||||||
|
if (str.empty())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
bool collect = false;
|
||||||
|
int length = 0;
|
||||||
|
|
||||||
|
#ifdef UTF8_ENABLED
|
||||||
|
wstring str2 = ToWString(str);
|
||||||
|
wstring tmp;
|
||||||
|
#else
|
||||||
|
const string &str2 = str;
|
||||||
|
string tmp;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int i = 0; i < str2.length(); i++, length++)
|
||||||
|
{
|
||||||
|
if (str2[i] == '[' && (str2[i+1] == '.' || str2[i+1] == '/'))
|
||||||
|
collect = 1;
|
||||||
|
|
||||||
|
if (collect)
|
||||||
|
{
|
||||||
|
if (str2[i] != '[')
|
||||||
|
tmp += str2[i];
|
||||||
|
else
|
||||||
|
tmp = str2[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str2[i] == ']')
|
||||||
|
collect = 0;
|
||||||
|
|
||||||
|
if (!collect && !tmp.empty())
|
||||||
|
{
|
||||||
|
if (isdigit(tmp[2]) || IsValidColor(TO_STRING(tmp)))
|
||||||
|
length -= tmp.length();
|
||||||
|
tmp.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
/*int CountBBCodes(const string &str)
|
/*int CountBBCodes(const string &str)
|
||||||
{
|
{
|
||||||
if (str.empty())
|
if (str.empty())
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ class Window
|
|||||||
static Coordinates IntoCoordinates(const string &);
|
static Coordinates IntoCoordinates(const string &);
|
||||||
static bool IsValidColor(const string &);
|
static bool IsValidColor(const string &);
|
||||||
static string OmitBBCodes(const string &);
|
static string OmitBBCodes(const string &);
|
||||||
|
static int RealLength(const string &);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Recreate();
|
virtual void Recreate();
|
||||||
|
|||||||
Reference in New Issue
Block a user