[Rhythmbox-devel] [PATCH] Making it possible to delete the last criterion in anautomatic playlist



I got annoyed when I tried to delete the last criterion in an automatic
playlist and found out I couldn't because the Remove button in that row
was actually an Add button. The only way to delete the last row is to
copy the contents of another row into the last row and then delete the
row you just copied. It seems that the last row would probably be one of
the most commonly removed rows, like when the user accidentally clicks
on add.

The patch below moves the add button onto its own row and puts it in the
first column. When there's only one criterion, its Remove button is
disabled. Adding criteria causes the Remove button for all rows to be
enabled. This way of doing things also has the advantage that the sizes
of the columns don't change when you go from one to two criteria.

I guess things were done the old way so that all of the add/remove
buttons would be in their own row. This way of doing things might not
look quite as nice, but I think it definitely works a lot better. I
tried making the add button take up a whole row, but that just looked
ugly to me.

I didn't remove priv->addbutton, but since we don't have to keep track
of and move the add button around anymore I don't know if there's a
reason to keep a special pointer to it.

Let me know if this patch needs any more work.

Jacques Fortier

--- orig/widgets/rb-query-creator.c
+++ mod/widgets/rb-query-creator.c
@@ -213,7 +213,9 @@
 	GtkWidget *first_option;
 	GtkWidget *first_criteria;
 	GtkWidget *first_entry;
+	GtkWidget *remove_button;
 
+	GtkBox *add_hbox;
 
 	klass = RB_QUERY_CREATOR_CLASS (g_type_class_peek (type));
 	parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
@@ -261,10 +263,6 @@
 	gtk_widget_set_sensitive (dlg->priv->limit_option, FALSE);
 
 	dlg->priv->vbox = GTK_BOX (glade_xml_get_widget (xml, "sub_vbox"));
-	dlg->priv->addbutton = gtk_button_new_from_stock (GTK_STOCK_ADD);
-	gtk_size_group_add_widget (dlg->priv->button_size_group, dlg->priv->addbutton);
-	g_signal_connect_object (G_OBJECT (dlg->priv->addbutton), "clicked", G_CALLBACK (add_button_click_cb),
-				 dlg, 0);
 	first_option = create_property_option_menu (dlg, property_options,
 						    G_N_ELEMENTS (property_options),
 						    FALSE);
@@ -275,12 +273,25 @@
 	gtk_size_group_add_widget (dlg->priv->criteria_size_group, first_criteria);
 	first_entry = gtk_entry_new ();
 	gtk_size_group_add_widget (dlg->priv->entry_size_group, first_entry);
+	remove_button = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
+	g_signal_connect_object (G_OBJECT (remove_button), "clicked", G_CALLBACK (remove_button_click_cb),
+				 dlg, 0);
+	gtk_widget_set_sensitive (remove_button, FALSE);
+	gtk_size_group_add_widget (dlg->priv->button_size_group, remove_button);
+
+	add_hbox = GTK_BOX (gtk_hbox_new (FALSE, 5));
+	dlg->priv->addbutton = gtk_button_new_from_stock (GTK_STOCK_ADD);
+	gtk_size_group_add_widget (dlg->priv->property_size_group, dlg->priv->addbutton);
+	g_signal_connect_object (G_OBJECT (dlg->priv->addbutton), "clicked", G_CALLBACK (add_button_click_cb),
+				 dlg, 0);
+	gtk_box_pack_start (add_hbox, GTK_WIDGET (dlg->priv->addbutton), FALSE, FALSE, 0);
+	gtk_box_pack_end_defaults (dlg->priv->vbox, GTK_WIDGET (add_hbox));
 
 	hbox = GTK_BOX (gtk_hbox_new (FALSE, 5));
 	gtk_box_pack_start_defaults (hbox, GTK_WIDGET (first_option));
 	gtk_box_pack_start_defaults (hbox, GTK_WIDGET (first_criteria));
 	gtk_box_pack_start_defaults (hbox, GTK_WIDGET (first_entry));
-	gtk_box_pack_start_defaults (hbox, GTK_WIDGET (dlg->priv->addbutton));
+	gtk_box_pack_start_defaults (hbox, GTK_WIDGET (remove_button));
 	gtk_box_pack_start_defaults (dlg->priv->vbox, GTK_WIDGET (hbox));
 	dlg->priv->rows = g_list_prepend (dlg->priv->rows, hbox);
 
@@ -667,12 +678,23 @@
 remove_button_click_cb (GtkWidget *button, RBQueryCreator *dialog)
 {
 	GtkWidget *row;
+	GtkWidget *only_remove_button;
+	GtkBox *only_hbox;
 
 	row = lookup_row_by_widget (dialog, button);
 	g_assert (row);
 	gtk_container_remove (GTK_CONTAINER (dialog->priv->vbox),
 			      GTK_WIDGET (row));
 	dialog->priv->rows = g_list_remove (dialog->priv->rows, row);
+
+	/* If we're down to one row, disable the remove button on that row*/
+	if (g_list_length (dialog->priv->rows) == 1) {
+		only_hbox = GTK_BOX ( dialog->priv->rows->data);
+		only_remove_button = get_box_widget_at_pos (only_hbox, 3);
+		g_assert (only_remove_button != NULL);
+		g_assert (GTK_IS_BUTTON (only_remove_button));
+		gtk_widget_set_sensitive (only_remove_button, FALSE);
+	}
 }
 
 static void
@@ -688,23 +710,23 @@
 	GtkWidget *criteria;
 	GtkWidget *entry;
 	GtkWidget *remove_button;
-	GtkBox *last_hbox;
 	GtkBox *hbox;
 	GList *rows;
 	guint len;
 
 	rows = dialog->priv->rows;
 	len = g_list_length (rows);
-	last_hbox = GTK_BOX (get_box_widget_at_pos (dialog->priv->vbox, len-1));
-	g_object_ref (G_OBJECT (dialog->priv->addbutton));
-	gtk_container_remove (GTK_CONTAINER (last_hbox),
-			      dialog->priv->addbutton);
 
-	remove_button = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
-	g_signal_connect_object (G_OBJECT (remove_button), "clicked", G_CALLBACK (remove_button_click_cb),
-				 dialog, 0);
-	gtk_size_group_add_widget (dialog->priv->button_size_group, remove_button);
-	gtk_box_pack_start_defaults (last_hbox, GTK_WIDGET (remove_button));
+	/* If there was only one row before the add, that row's remove
+	 * button needs to be enabled */
+	if (len == 1)
+	{
+		hbox = GTK_BOX (dialog->priv->rows->data);
+		remove_button = get_box_widget_at_pos (hbox, 3);
+		g_assert (remove_button != NULL);
+		g_assert (GTK_IS_BUTTON (remove_button));
+		gtk_widget_set_sensitive (remove_button, TRUE);
+	}
 
 	hbox = GTK_BOX (gtk_hbox_new (FALSE, 5));
 	gtk_box_pack_start_defaults (GTK_BOX (dialog->priv->vbox), GTK_WIDGET (hbox));
@@ -728,8 +750,11 @@
 	gtk_size_group_add_widget (dialog->priv->entry_size_group, entry);
 	gtk_box_pack_start_defaults (hbox, GTK_WIDGET (entry));
 
-	gtk_box_pack_start_defaults (hbox, GTK_WIDGET (dialog->priv->addbutton));
-	g_object_unref (G_OBJECT (dialog->priv->addbutton));
+	remove_button = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
+	g_signal_connect_object (G_OBJECT (remove_button), "clicked", G_CALLBACK (remove_button_click_cb),
+				 dialog, 0);
+	gtk_size_group_add_widget (dialog->priv->button_size_group, remove_button);
+	gtk_box_pack_start_defaults (hbox, GTK_WIDGET (remove_button));
 
 	gtk_widget_show_all (GTK_WIDGET (dialog->priv->vbox));
 	return GTK_WIDGET (hbox);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]