Skip to content

Commit

Permalink
plugins: reselect when toggling the current plugin
Browse files Browse the repository at this point in the history
When enabling/disabling pluxys in the PM dialog the list of available
plugins might change. If plugins before the pluxy go/come then the wrong
plugin becomes selected (the selected row number stays the same). Re-apply
the selection to the current one in the toggle callback to overcome this issue.
  • Loading branch information
kugel- committed Aug 26, 2015
1 parent a006f71 commit ce9fe0b
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/plugins.c
Expand Up @@ -1294,17 +1294,53 @@ static void pm_selection_changed(GtkTreeSelection *selection, gpointer user_data
}


static gboolean find_iter_for_plugin(Plugin *p, GtkTreeModel *model, GtkTreeIter *iter)
{
Plugin *pp;
gboolean valid;

for(valid = gtk_tree_model_get_iter_first(model, iter);
valid && p;
valid = gtk_tree_model_iter_next(model, iter))
{
gtk_tree_model_get(model, iter, PLUGIN_COLUMN_PLUGIN, &pp, -1);
if (p == pp)
return TRUE;
}

return FALSE;
}


static gboolean select_plugin(gpointer data)
{
GtkTreeIter iter;
Plugin *p = data;
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(pm_widgets.tree));

/* restore selection */
if (find_iter_for_plugin(p, model, &iter))
{
GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(pm_widgets.tree));
gtk_tree_selection_select_iter(sel, &iter);
}

return G_SOURCE_REMOVE;
}


static void pm_populate(GtkListStore *store);
static void pm_plugin_toggled(GtkCellRendererToggle *cell, gchar *pth, gpointer data)
{
gboolean old_state, state;
gboolean old_state, state, valid;
gchar *file_name;
GtkTreeIter iter;
GtkTreeIter store_iter;
GtkTreePath *path = gtk_tree_path_new_from_string(pth);
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(pm_widgets.tree));
Plugin *p;
Plugin *proxy;
guint prev_num_proxies;

gtk_tree_model_get_iter(model, &iter, path);
gtk_tree_path_free(path);
Expand All @@ -1325,6 +1361,7 @@ static void pm_plugin_toggled(GtkCellRendererToggle *cell, gchar *pth, gpointer
/* save the filename and proxy of the plugin */
file_name = g_strdup(p->filename);
proxy = p->proxy;
prev_num_proxies = supported_plugin_list->len;

/* unload plugin module */
if (!state)
Expand Down Expand Up @@ -1353,6 +1390,22 @@ static void pm_plugin_toggled(GtkCellRendererToggle *cell, gchar *pth, gpointer
/* set again the sensitiveness of the configure and help buttons */
pm_update_buttons(p);
}
/* We need to find out if a proxy was added or removed because that affects the plugin list
* presented by the plugin manager. The current solution counts supported_plugin_list twice,
* this suboptimal from an algorithmic POV, however most efficient for the extremely small
* number (at most 3) of pluxies we expect users to load */
if (prev_num_proxies != supported_plugin_list->len)
{
gboolean valid;
GtkTreeModel *store;
Plugin *pp;
/* Rescan the plugin list as we now support more */
if (prev_num_proxies < supported_plugin_list->len)
load_all_plugins();
pm_populate(pm_widgets.store);
/* restore selection. doesn't work if it's done immediately (same row keeps selected) */
g_idle_add(select_plugin, p);
}
g_free(file_name);
}

Expand Down Expand Up @@ -1516,6 +1569,9 @@ static gboolean pm_tree_filter_func(GtkTreeModel *model, GtkTreeIter *iter, gpoi
gchar *haystack, *filename;

gtk_tree_model_get(model, iter, PLUGIN_COLUMN_PLUGIN, &plugin, -1);

if (!plugin)
return FALSE;
key = gtk_entry_get_text(GTK_ENTRY(pm_widgets.filter_entry));

filename = g_path_get_basename(plugin->filename);
Expand Down

0 comments on commit ce9fe0b

Please sign in to comment.