summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/gtkui/hotkeys.c2
-rw-r--r--plugins/pltbrowser/pltbrowser.c153
2 files changed, 76 insertions, 79 deletions
diff --git a/plugins/gtkui/hotkeys.c b/plugins/gtkui/hotkeys.c
index dcf17c09..d3026b5d 100644
--- a/plugins/gtkui/hotkeys.c
+++ b/plugins/gtkui/hotkeys.c
@@ -273,7 +273,7 @@ set_current_action (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, g
const char *name = g_value_get_string (&val);
if (name && binding->name && !strcmp (binding->name, name) && binding->ctx == g_value_get_int (&ctx_val)) {
gtk_tree_view_expand_to_path (GTK_TREE_VIEW (binding->treeview), path);
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (GTK_TREE_VIEW (binding->treeview)), path, NULL, FALSE);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (binding->treeview), path, NULL, FALSE);
return TRUE;
}
return FALSE;
diff --git a/plugins/pltbrowser/pltbrowser.c b/plugins/pltbrowser/pltbrowser.c
index 8959bd9b..41a46660 100644
--- a/plugins/pltbrowser/pltbrowser.c
+++ b/plugins/pltbrowser/pltbrowser.c
@@ -36,15 +36,82 @@ static ddb_gtkui_t *gtkui_plugin;
typedef struct {
ddb_gtkui_widget_t base;
GtkWidget *tree;
- int disable_handler;
int last_selected;
+ gulong cc_id;
+ gulong ri_id;
} w_pltbrowser_t;
+static void
+on_pltbrowser_row_inserted (GtkTreeModel *tree_model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) {
+ w_pltbrowser_t *plt = user_data;
+ int *indices = gtk_tree_path_get_indices (path);
+ int idx = *indices;
+ if (idx > plt->last_selected) {
+ idx--;
+ }
+ if (idx == plt->last_selected) {
+ return;
+ }
+
+ char str1[100];
+ char str2[100];
+ char strcursor1[100];
+ char strcursor2[100];
+ int pos1;
+ int pos2;
+ int cursor1;
+ int cursor2;
+ snprintf (str1, sizeof (str1), "playlist.scroll.%d", plt->last_selected);
+ pos1 = deadbeef->conf_get_int (str1, 0);
+ snprintf (str2, sizeof (str2), "playlist.scroll.%d", idx);
+ pos2 = deadbeef->conf_get_int (str2, 0);
+
+ snprintf (strcursor1, sizeof (strcursor1), "playlist.cursor.%d", plt->last_selected);
+ cursor1 = deadbeef->conf_get_int (strcursor1, 0);
+ snprintf (strcursor2, sizeof (strcursor2), "playlist.cursor.%d", idx);
+ cursor2 = deadbeef->conf_get_int (strcursor2, 0);
+
+ deadbeef->plt_move (plt->last_selected, idx);
+ deadbeef->conf_set_int (str1, pos2);
+ deadbeef->conf_set_int (str2, pos1);
+ deadbeef->conf_set_int (strcursor1, cursor2);
+ deadbeef->conf_set_int (strcursor2, cursor1);
+ plt->last_selected = idx;
+ deadbeef->conf_set_int ("playlist.current", idx);
+ deadbeef->sendmessage (DB_EV_PLAYLISTSWITCHED, 0, 0, 0);
+}
+
+static void
+on_pltbrowser_cursor_changed (GtkTreeView *treeview, gpointer user_data) {
+ w_pltbrowser_t *w = user_data;
+ GtkTreePath *path;
+ GtkTreeViewColumn *col;
+ gtk_tree_view_get_cursor (treeview, &path, &col);
+ if (!path) {
+ return;
+ }
+ int *indices = gtk_tree_path_get_indices (path);
+ if (indices) {
+ if (indices[0] >= 0) {
+ deadbeef->plt_set_curr_idx (indices[0]);
+ deadbeef->conf_set_int ("playlist.current", indices[0]);
+ w->last_selected = indices[0];
+ }
+ g_free (indices);
+ }
+}
+
static gboolean
fill_pltbrowser_cb (gpointer data) {
w_pltbrowser_t *w = data;
- deadbeef->pl_lock ();
+
GtkListStore *store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (w->tree)));
+ g_signal_handler_disconnect ((gpointer)w->tree, w->cc_id);
+ g_signal_handler_disconnect ((gpointer)store, w->ri_id);
+ w->cc_id = 0;
+ w->ri_id = 0;
+
+ deadbeef->pl_lock ();
gtk_list_store_clear (store);
int n = deadbeef->plt_get_count ();
int curr = deadbeef->plt_get_curr_idx ();
@@ -62,7 +129,8 @@ fill_pltbrowser_cb (gpointer data) {
gtk_tree_path_free (path);
}
deadbeef->pl_unlock ();
- w->disable_handler = 0;
+ w->ri_id = g_signal_connect ((gpointer)store, "row_inserted", G_CALLBACK (on_pltbrowser_row_inserted), w);
+ w->cc_id = g_signal_connect ((gpointer)w->tree, "cursor_changed", G_CALLBACK (on_pltbrowser_cursor_changed), w);
return FALSE;
}
@@ -70,7 +138,6 @@ static int
pltbrowser_message (ddb_gtkui_widget_t *w, uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) {
switch (id) {
case DB_EV_PLAYLISTSWITCHED:
- ((w_pltbrowser_t *)w)->disable_handler = 1;
g_idle_add (fill_pltbrowser_cb, w);
break;
}
@@ -80,35 +147,9 @@ pltbrowser_message (ddb_gtkui_widget_t *w, uint32_t id, uintptr_t ctx, uint32_t
static void
w_pltbrowser_init (struct ddb_gtkui_widget_s *w) {
- ((w_pltbrowser_t *)w)->disable_handler = 1;
fill_pltbrowser_cb (w);
}
-void
-on_pltbrowser_cursor_changed (GtkTreeView *treeview, gpointer user_data)
-{
- w_pltbrowser_t *w = user_data;
- if (w->disable_handler) {
- return;
- }
- GtkTreePath *path;
- GtkTreeViewColumn *col;
- gtk_tree_view_get_cursor (treeview, &path, &col);
- if (!path || !col) {
- // FIXME: must re-select the one unselected
- return;
- }
- int *indices = gtk_tree_path_get_indices (path);
- if (indices) {
- if (indices[0] >= 0) {
- deadbeef->plt_set_curr_idx (indices[0]);
- deadbeef->conf_set_int ("playlist.current", indices[0]);
- w->last_selected = indices[0];
- }
- g_free (indices);
- }
-}
-
gboolean
on_pltbrowser_button_press_event (GtkWidget *widget,
GdkEventButton *event,
@@ -142,52 +183,6 @@ on_pltbrowser_button_press_event (GtkWidget *widget,
}
static void
-on_pltbrowser_row_inserted (GtkTreeModel *tree_model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) {
- w_pltbrowser_t *plt = user_data;
- if (plt->disable_handler) {
- return;
- }
- int *indices = gtk_tree_path_get_indices (path);
- int idx = *indices;
- if (idx > plt->last_selected) {
- idx--;
- }
- if (idx == plt->last_selected) {
- return;
- }
-
- plt->disable_handler = 1;
-
- char str1[100];
- char str2[100];
- char strcursor1[100];
- char strcursor2[100];
- int pos1;
- int pos2;
- int cursor1;
- int cursor2;
- snprintf (str1, sizeof (str1), "playlist.scroll.%d", plt->last_selected);
- pos1 = deadbeef->conf_get_int (str1, 0);
- snprintf (str2, sizeof (str2), "playlist.scroll.%d", idx);
- pos2 = deadbeef->conf_get_int (str2, 0);
-
- snprintf (strcursor1, sizeof (strcursor1), "playlist.cursor.%d", plt->last_selected);
- cursor1 = deadbeef->conf_get_int (strcursor1, 0);
- snprintf (strcursor2, sizeof (strcursor2), "playlist.cursor.%d", idx);
- cursor2 = deadbeef->conf_get_int (strcursor2, 0);
-
- plt->disable_handler = 1;
- deadbeef->plt_move (plt->last_selected, idx);
- deadbeef->conf_set_int (str1, pos2);
- deadbeef->conf_set_int (str2, pos1);
- deadbeef->conf_set_int (strcursor1, cursor2);
- deadbeef->conf_set_int (strcursor2, cursor1);
- plt->last_selected = idx;
- deadbeef->conf_set_int ("playlist.current", idx);
- deadbeef->sendmessage (DB_EV_PLAYLISTSWITCHED, 0, 0, 0);
-}
-
-static void
on_pltbrowser_row_activated (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) {
deadbeef->sendmessage (DB_EV_PLAY_NUM, 0, 0, 0);
}
@@ -207,6 +202,8 @@ w_pltbrowser_create (void) {
gtk_tree_view_set_reorderable (GTK_TREE_VIEW (w->tree), TRUE);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (w->tree), FALSE);
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (w->tree), TRUE);
+ GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (w->tree));
+ gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
gtk_widget_show (w->tree);
gtk_container_add (GTK_CONTAINER (w->base.widget), w->tree);
@@ -214,7 +211,7 @@ w_pltbrowser_create (void) {
GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
gtk_tree_view_set_model (GTK_TREE_VIEW (w->tree), GTK_TREE_MODEL (store));
- g_signal_connect ((gpointer) store, "row_inserted", G_CALLBACK (on_pltbrowser_row_inserted), w);
+ w->ri_id = g_signal_connect ((gpointer) store, "row_inserted", G_CALLBACK (on_pltbrowser_row_inserted), w);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (w->tree), TRUE);
@@ -223,7 +220,7 @@ w_pltbrowser_create (void) {
gtk_tree_view_append_column (GTK_TREE_VIEW (w->tree), col1);
- g_signal_connect ((gpointer) w->tree, "cursor_changed",
+ w->cc_id = g_signal_connect ((gpointer) w->tree, "cursor_changed",
G_CALLBACK (on_pltbrowser_cursor_changed),
w);
g_signal_connect ((gpointer) w->tree, "event_after",