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

Re: To share a dirty hack on a treeview



On Wed, 2005-02-16 at 23:43 -0500, muppet wrote:

> > The fact I hate most is that I need a dummy row (on top) and I can't 
> > find a way to hide it. This row is needed as an asylum for that 
> > incorrigible row-highlight-bar of the treeview. If I don't use this 
> > dummy row, I can still change the color of the cell but it will stay 
> > hidden under the row highlight till I click on another row.
> 
> Not sure why i didn't think of this in IRC, but if you're planning to 
> handle selection highlighting yourself, why not just disable the 
> built-in selection?  $tree_view->get_selection->set_mode ('none');
> 
> By the way, there's no way to clear the highlight you've set up.  ;-)

Because I felt like it, here's a patch to the original version that adds
those suggestions (plus a new gimmick :-).

-- 
Bye,
-Torsten
--- tree_mark_cell_orig.pl	2005-02-17 19:18:37.770007480 +0100
+++ tree_mark_cell.pl	2005-02-17 19:28:38.726648184 +0100
@@ -22,18 +22,8 @@
 	Glib::String Glib::String /
 );
 
-# Ouch ! We need to give a home to that unwanted row-highlight.
 my $iter = $model->append (undef);
 $model->set ($iter,
-			0, undef,	1, undef,
-			2, undef,	3, undef,
-			4, undef,	5, undef,
-			5, undef,	7, undef,
-			8, undef,	9, undef,
-);
-
-$iter = $model->append (undef);
-$model->set ($iter,
 			0, 'foo',	1, undef,
 			2, undef,	3, undef,
 			4, undef,	5, undef,
@@ -66,6 +56,7 @@
 	$tree_view->append_column($col);
 	push @tree_columns, $col;
 }
+$tree_view->get_selection->set_mode ('none');
 $tree_view->expand_all;
 
 my $clicked_cache;
@@ -113,17 +104,33 @@
 		if ($path) {
 			my $model = $tree_view->get_model;
 			my $i = $column->{column_number};
-			return 0 unless $i; # If the first column is clicked, 
-			                    # the user actually wants to higlight the whole row
-			return 0 if ($path->to_string eq "0"); # If the dummy row is clicked
-			return 0 if ($i>3); # If the hidden row is clicked
+
+			my $iter = $model->get_iter ($path);
+
+			# Change the background of all cells in the clicked row
+			if ($i == 0) {
+				my $color = undef;
+
+				foreach (1 .. $#columns - 1) {
+					unless (defined $model->get($iter, $_*2+1)) {
+						$color = 'green';
+						last;
+					}
+				}
+
+				foreach (1 .. $#columns - 1) {
+					$model->set($iter, $_*2+1, $color);
+				}
+
+				return 1;
+			}
 
 			# Change the background of the cell that was clicked
-			$model->set($model->get_iter ($path), $i*2+1, 'green');
+			$model->set($iter, $i*2+1, defined $model->get($iter, $i*2+1) ? undef : 'green');
 			
-			my $name = $model->get($model->get_iter ($path), 0);
+			my $name = $model->get($iter, 0);
 			my $col  = $columns[$i];
-			my $text = $model->get($model->get_iter ($path), $i*2);
+			my $text = $model->get($iter, $i*2);
 			push @$clicked_cache, 
 				{	path => $path->to_string, 
 					name => $name, 
@@ -131,10 +138,6 @@
 					column_number => $i,
 					text => $text
 				};
-			
-			# Send the cursor to the dummy row. Else the color change won't be seen
-			# The color change will be hidden under the row-higlight
-			$tree_view->set_cursor (Gtk2::TreePath->new_from_string("0"), undef, TRUE);
 
 			return 1;
 		}


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