Discussion:
[PATCH 1/3] move tree_search_matches() down
Johannes Weißl
2011-09-03 12:47:02 UTC
Permalink
need static functions declared above in next commits
---
tree.c | 42 +++++++++++++++++++++++-------------------
1 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/tree.c b/tree.c
index 9c384e9..40ff04a 100644
--- a/tree.c
+++ b/tree.c
@@ -306,25 +306,7 @@ static inline struct tree_track *iter_to_tree_search_track(const struct iter *it
return iter->data1;
}

-static int tree_search_matches(void *data, struct iter *iter, const char *text)
-{
- struct tree_track *track;
- struct iter tmpiter;
- unsigned int flags = TI_MATCH_ARTIST | TI_MATCH_ALBUM | TI_MATCH_ALBUMARTIST;
-
- if (!search_restricted)
- flags |= TI_MATCH_TITLE;
- track = iter_to_tree_search_track(iter);
- if (!track_info_matches(tree_track_info(track), text, flags))
- return 0;
- track->album->artist->expanded = 1;
- album_to_iter(track->album, &tmpiter);
- window_set_sel(lib_tree_win, &tmpiter);
-
- tree_track_to_iter(track, &tmpiter);
- window_set_sel(lib_track_win, &tmpiter);
- return 1;
-}
+static int tree_search_matches(void *data, struct iter *iter, const char *text);

static const struct searchable_ops tree_search_ops = {
.get_prev = tree_search_get_prev,
@@ -573,6 +555,28 @@ static struct artist *do_find_artist(const struct artist *artist,
return NULL;
}

+/* search (tree) {{{ */
+static int tree_search_matches(void *data, struct iter *iter, const char *text)
+{
+ struct tree_track *track;
+ struct iter tmpiter;
+ unsigned int flags = TI_MATCH_ARTIST | TI_MATCH_ALBUM | TI_MATCH_ALBUMARTIST;
+
+ if (!search_restricted)
+ flags |= TI_MATCH_TITLE;
+ track = iter_to_tree_search_track(iter);
+ if (!track_info_matches(tree_track_info(track), text, flags))
+ return 0;
+ track->album->artist->expanded = 1;
+ album_to_iter(track->album, &tmpiter);
+ window_set_sel(lib_tree_win, &tmpiter);
+
+ tree_track_to_iter(track, &tmpiter);
+ window_set_sel(lib_track_win, &tmpiter);
+ return 1;
+}
+/* search (tree) }}} */
+
static void insert_artist(struct artist *artist, struct rb_root *root)
{
struct rb_node **new = &(root->rb_node), *parent = NULL;
--
1.7.6
Johannes Weißl
2011-09-03 12:47:03 UTC
Permalink
Instead of collapsing every artist the search passes, it now only
collapses artists that were expanded previously.

Suggested-by: Anonymous user
---
tree.c | 32 ++++++++++++++++++++++----------
1 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/tree.c b/tree.c
index 40ff04a..af461d1 100644
--- a/tree.c
+++ b/tree.c
@@ -86,7 +86,7 @@ static void tree_set_expand_artist(struct artist *artist, int expand)
static int tree_search_get_prev(struct iter *iter)
{
struct rb_root *root = iter->data0;
- struct tree_track *track = iter->data1, *old = track;
+ struct tree_track *track = iter->data1;
struct artist *artist;
struct album *album;

@@ -122,17 +122,13 @@ static int tree_search_get_prev(struct iter *iter)
track = to_tree_track(rb_prev(&track->tree_node));
}
iter->data1 = track;
- /* collapse old search result */
- artist = old->album->artist;
- if (artist != track->album->artist && artist->expanded)
- tree_set_expand_artist(artist, 0);
return 1;
}

static int tree_search_get_next(struct iter *iter)
{
struct rb_root *root = iter->data0;
- struct tree_track *track = iter->data1, *old = track;
+ struct tree_track *track = iter->data1;
struct artist *artist;
struct album *album;

@@ -168,10 +164,6 @@ static int tree_search_get_next(struct iter *iter)
track = to_tree_track(rb_next(&track->tree_node));
}
iter->data1 = track;
- /* collapse old search result */
- artist = old->album->artist;
- if (artist != track->album->artist && artist->expanded)
- tree_set_expand_artist(artist, 0);
return 1;
}
/* }}} */
@@ -390,6 +382,11 @@ static struct artist *artist_new(const char *name, const char *sort_name, int is
return a;
}

+static struct artist *artist_copy(const struct artist *artist)
+{
+ return artist_new(artist->name, artist->sort_name, artist->is_compilation);
+}
+
static void artist_free(struct artist *artist)
{
free(artist->name);
@@ -556,6 +553,8 @@ static struct artist *do_find_artist(const struct artist *artist,
}

/* search (tree) {{{ */
+static struct artist *collapse_artist;
+
static int tree_search_matches(void *data, struct iter *iter, const char *text)
{
struct tree_track *track;
@@ -567,6 +566,19 @@ static int tree_search_matches(void *data, struct iter *iter, const char *text)
track = iter_to_tree_search_track(iter);
if (!track_info_matches(tree_track_info(track), text, flags))
return 0;
+
+ /* collapse old search result */
+ if (collapse_artist) {
+ struct artist *artist = do_find_artist(collapse_artist, &lib_artist_root, NULL, NULL);
+ if (artist && artist != track->album->artist) {
+ if (artist->expanded)
+ tree_set_expand_artist(artist, 0);
+ artist_free(collapse_artist);
+ collapse_artist = (!track->album->artist->expanded) ? artist_copy(track->album->artist) : NULL;
+ }
+ } else if (!track->album->artist->expanded)
+ collapse_artist = artist_copy(track->album->artist);
+
track->album->artist->expanded = 1;
album_to_iter(track->album, &tmpiter);
window_set_sel(lib_tree_win, &tmpiter);
--
1.7.6
Johannes Weißl
2011-09-03 12:47:04 UTC
Permalink
Suggested-by: Anonymous user
---
options.c | 18 ++++++++++++++++++
options.h | 1 +
search.c | 5 +++++
3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/options.c b/options.c
index c87baf3..56d2cb9 100644
--- a/options.c
+++ b/options.c
@@ -64,6 +64,7 @@ int show_hidden = 0;
int show_current_bitrate = 0;
int show_remaining_time = 0;
int set_term_title = 1;
+int wrap_search = 1;
int play_library = 1;
int repeat = 0;
int shuffle = 0;
@@ -844,6 +845,22 @@ static void toggle_softvol(unsigned int id)
do_set_softvol(soft_vol ^ 1);
}

+static void get_wrap_search(unsigned int id, char *buf)
+{
+ strcpy(buf, bool_names[wrap_search]);
+}
+
+static void set_wrap_search(unsigned int id, const char *buf)
+{
+ parse_bool(buf, &wrap_search);
+}
+
+static void toggle_wrap_search(unsigned int id)
+{
+ wrap_search ^= 1;
+}
+
+
/* }}} */

/* special callbacks (id set) {{{ */
@@ -971,6 +988,7 @@ static const struct {
DT(softvol)
DN(softvol_state)
DN_FLAGS(status_display_program, OPT_PROGRAM_PATH)
+ DT(wrap_search)
{ NULL, NULL, NULL, NULL, 0 }
};

diff --git a/options.h b/options.h
index ceecca5..3fa6a6f 100644
--- a/options.h
+++ b/options.h
@@ -112,6 +112,7 @@ extern int show_hidden;
extern int show_current_bitrate;
extern int show_remaining_time;
extern int set_term_title;
+extern int wrap_search;
extern int play_library;
extern int repeat;
extern int shuffle;
diff --git a/search.c b/search.c
index 1e40cd3..199e055 100644
--- a/search.c
+++ b/search.c
@@ -21,6 +21,7 @@
#include "xmalloc.h"
#include "ui_curses.h"
#include "convert.h"
+#include "options.h"

struct searchable {
void *data;
@@ -52,6 +53,8 @@ static int do_u_search(struct searchable *s, struct iter *iter, const char *text
}
if (direction == SEARCH_FORWARD) {
if (!s->ops.get_next(iter)) {
+ if (!wrap_search)
+ return 0;
*iter = s->head;
if (!s->ops.get_next(iter))
return 0;
@@ -59,6 +62,8 @@ static int do_u_search(struct searchable *s, struct iter *iter, const char *text
}
} else {
if (!s->ops.get_prev(iter)) {
+ if (!wrap_search)
+ return 0;
*iter = s->head;
if (!s->ops.get_prev(iter))
return 0;
--
1.7.6
Gregory Petrosyan
2011-09-03 13:25:09 UTC
Permalink
Post by Johannes Weißl
Suggested-by: Anonymous user
Thanks to you and the anonymous user :-)
Post by Johannes Weißl
 options.c |   18 ++++++++++++++++++
 options.h |    1 +
 search.c  |    5 +++++
 3 files changed, 24 insertions(+), 0 deletions(-)
Can you please add the documentation as well?

                Gregory
Johannes Weißl
2011-09-03 13:35:18 UTC
Permalink
---
Doc/cmus.txt | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/Doc/cmus.txt b/Doc/cmus.txt
index 449b635..381176c 100644
--- a/Doc/cmus.txt
+++ b/Doc/cmus.txt
@@ -936,6 +936,9 @@ status_display_program () [command]
background or panel for example. See
`/usr/share/doc/cmus/examples/cmus-status-display`.

+wrap_search (true)
+ Controls whether the search wraps around the end.
+
@h2 Colors

Color is integer in range -1..255.
--
1.7.6
Johannes Weißl
2011-09-03 13:36:53 UTC
Permalink
Hi Gregory,
Post by Gregory Petrosyan
Can you please add the documentation as well?
Of course, how can I always forgot this... I sent a patch just now!

Johannes
Gregory Petrosyan
2011-09-03 19:21:55 UTC
Permalink
Post by Johannes Weißl
Hi Gregory,
Post by Gregory Petrosyan
Can you please add the documentation as well?
Of course, how can I always forgot this... I sent a patch just now!
Thanks a lot, merged them all!

Gregory

Loading...