Re: Liststore sorting and update questions



On 6 February 2017 at 17:52, Mike Martin <mike redtux org uk> wrote:
I want to enable manual sorting by clicking on header, but disable the
automatic sorting that happens when you change a value

How about this:

#! /usr/bin/perl -w

use strict;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/;
use Gtk2::Ex::Simple::List;

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });

my $list = Gtk2::Ex::Simple::List->new(
  'int'     => 'int',
  'text'  => 'text',
);
$list->set_headers_visible(TRUE);
$list->set_column_editable( 0, TRUE );
$list->set_headers_clickable (TRUE);
my $column = $list->get_column(0);
$column->signal_connect('clicked' => sub {

                            # Deep copy the tied data so we can sort it.
                            # Otherwise, very bad things happen.
                            my @data = map { [ @{$_} ] } @{ $list->{data} };
                            @data = sort {$a->[0] <=> $b->[0]} @data;
                            @{ $list->{data} } = @data;
                        });

@{$list->{data}} = (
    [ 1, 'one' ],
    [ 2, 'two' ],
    [ 3, 'three' ],
);

my $vbox = Gtk2::VBox->new(FALSE,5);
$vbox->add($list);
$window->add($vbox);
$window->show_all();
Gtk2->main();

__END__


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