new option for song format - right align (thx to Nathan Jones)

This commit is contained in:
unK
2008-09-13 21:59:05 +02:00
parent 369bbf6b96
commit c54de64176
10 changed files with 78 additions and 60 deletions

View File

@@ -40,6 +40,7 @@
## %p - performer
## %d - disc
## %C - comment
## %r - begin right align
##
## you can also put them in { } and then it will be displayed
## only if all requested values are available and/or define alternate

View File

@@ -215,12 +215,12 @@ string TotalPlaylistLength()
return result;
}
string DisplayStringPair(const StringPair &pair, void *null)
string DisplayStringPair(const StringPair &pair, void *, const Menu<StringPair> *)
{
return pair.first;
}
string DisplayItem(const Item &item, void *)
string DisplayItem(const Item &item, void *, const Menu<Item> *menu)
{
switch (item.type)
{
@@ -232,7 +232,8 @@ string DisplayItem(const Item &item, void *)
return "[" + (slash != string::npos ? item.name.substr(slash+1) : item.name) + "]";
}
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:
return Config.browser_playlist_prefix + item.name;
}
@@ -310,7 +311,7 @@ string DisplayColumns(string song_template)
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) : "";
@@ -402,12 +403,14 @@ string DisplaySongInColumns(const Song &s, void *s_template)
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) : "";
string result;
string lresult;
bool link_tags = 0;
bool tags_present = 0;
bool right = 0;
int i = 0;
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();
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;
}

View File

@@ -48,11 +48,11 @@ bool Keypressed(int, const int *);
void WindowTitle(const string &);
string TotalPlaylistLength();
string DisplayStringPair(const StringPair &, void * = NULL);
string DisplayItem(const Item &, void * = NULL);
string DisplayStringPair(const StringPair &, void *, const Menu<StringPair> *);
string DisplayItem(const Item &, void *, const Menu<Item> *);
string DisplayColumns(string);
string DisplaySongInColumns(const Song &, void *);
string DisplaySong(const Song &, void * = &Config.song_list_format);
string DisplaySongInColumns(const Song &, void *, const Menu<Song> *);
string DisplaySong(const Song &, void * = &Config.song_list_format, const Menu<Song> * = NULL);
string GetInfo(Song &);
void ShowMessage(const string &, int = Config.message_delay_time);
void GetDirectory(string, string = "/");

View File

@@ -45,7 +45,7 @@ class Menu : public Window
{
typedef typename vector<Option<T> *>::iterator T_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:
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 & operator[](int i) const { return itsOptions[i]->item; }
T & operator[](int i) { return itsOptions[i]->item; }
protected:
string DisplayOption(const T &t) const;
ItemDisplayer itsItemDisplayer;
@@ -112,7 +113,6 @@ class Menu : public Window
string itsSelectedSuffix;
int itsStaticsNumber;
int count_length(string);
void redraw_screen();
bool is_static() { return itsOptions[itsHighlight]->is_static; }
@@ -152,49 +152,6 @@ Menu<T>::~Menu()
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>
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);
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)
{
@@ -733,7 +690,7 @@ Window * Menu<T>::EmptyClone() const
template <class T>
string Menu<T>::DisplayOption(const T &t) const
{
return itsItemDisplayer ? itsItemDisplayer(t, itsItemDisplayerUserdata) : "";
return itsItemDisplayer ? itsItemDisplayer(t, itsItemDisplayerUserdata, this) : "";
}
template <>

View File

@@ -28,7 +28,7 @@ extern Menu< std::pair<string, Song> > *mSearcher;
bool search_match_to_pattern = 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;
}

View File

@@ -26,7 +26,7 @@
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 PrepareSearchEngine(Song &s);
void Search(Song &);

View File

@@ -60,7 +60,7 @@ string FindSharedDir(const SongList &v)
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())
{

View File

@@ -36,7 +36,7 @@ typedef void (Song::*SongSetFunction)(const string &);
string FindSharedDir(Menu<Song> *);
string FindSharedDir(const SongList &);
string DisplayTag(const Song &, void *);
string DisplayTag(const Song &, void *, const Menu<Song> *);
bool GetSongTags(Song &);
bool WriteTags(Song &);

View File

@@ -740,6 +740,48 @@ string Window::OmitBBCodes(const string &str)
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)
{
if (str.empty())

View File

@@ -130,6 +130,7 @@ class Window
static Coordinates IntoCoordinates(const string &);
static bool IsValidColor(const string &);
static string OmitBBCodes(const string &);
static int RealLength(const string &);
protected:
virtual void Recreate();