| 1 | # Copyright 2008, 2009, 2010, 2011 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Chart. | ||
| 4 | # | ||
| 5 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 6 | # terms of the GNU General Public License as published by the Free Software | ||
| 7 | # Foundation; either version 3, or (at your option) any later version. | ||
| 8 | # | ||
| 9 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 12 | # details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | |||
| 17 | |||
| 18 | package App::Chart::Gtk2::Symlist::Glob; | ||
| 19 | use 5.008; | ||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | use Gtk2; | ||
| 23 | use Carp; | ||
| 24 | |||
| 25 | use App::Chart::Glib::Ex::MoreUtils; | ||
| 26 | use App::Chart; | ||
| 27 | |||
| 28 | use constant DEBUG => 0; | ||
| 29 | |||
| 30 | use Gtk2::Ex::TreeModelFilter::Draggable; | ||
| 31 | use Glib::Object::Subclass | ||
| 32 | 'Gtk2::Ex::TreeModelFilter::Draggable', | ||
| 33 | properties => [Glib::ParamSpec->string | ||
| 34 | ('pattern', | ||
| 35 | 'pattern', | ||
| 36 | '', | ||
| 37 | 'Glob style pattern of symbols.', | ||
| 38 | Glib::G_PARAM_READWRITE), | ||
| 39 | |||
| 40 | Glib::ParamSpec->string | ||
| 41 | ('key', | ||
| 42 | 'key', | ||
| 43 | 'The symlist database key.', | ||
| 44 | '', | ||
| 45 | Glib::G_PARAM_READWRITE), | ||
| 46 | |||
| 47 | Glib::ParamSpec->string | ||
| 48 | ('name', | ||
| 49 | 'name', | ||
| 50 | 'The symlist name.', | ||
| 51 | '', # default | ||
| 52 | Glib::G_PARAM_READWRITE) ]; | ||
| 53 | |||
| 54 | use App::Chart::Gtk2::Symlist; | ||
| 55 | use base 'App::Chart::Gtk2::Symlist'; | ||
| 56 | |||
| 57 | sub can_edit { return 0; } | ||
| 58 | sub can_destroy { return 0; } | ||
| 59 | |||
| 60 | sub new { | ||
| 61 | my ($class, $symlist, $pattern) = @_; | ||
| 62 | return $class->Glib::Object::new (child_model => $symlist, | ||
| 63 | pattern => $pattern); | ||
| 64 | } | ||
| 65 | |||
| 66 | my $counter = 0; | ||
| 67 | |||
| 68 | sub INIT_INSTANCE { | ||
| 69 | my ($self) = @_; | ||
| 70 | $self->{'key'} = '_glob_' . $counter++; | ||
| 71 | $self->{'regexp'} = qr//; | ||
| 72 | $self->set_visible_func (\&_visible_func, | ||
| 73 | App::Chart::Glib::Ex::MoreUtils::ref_weak($self)); | ||
| 74 | } | ||
| 75 | |||
| 76 | sub SET_PROPERTY { | ||
| 77 | my ($self, $pspec, $newval) = @_; | ||
| 78 | my $pname = $pspec->get_name; | ||
| 79 | $self->{$pname} = $newval; | ||
| 80 | |||
| 81 | if ($pname eq 'pattern') { | ||
| 82 | require Text::Glob; | ||
| 83 | $self->{'name'} = $newval; | ||
| 84 | $self->{'regexp'} = Text::Glob::glob_to_regex ($newval); | ||
| 85 | if (DEBUG) { print "regexp ",$self->{'regexp'},"\n"; } | ||
| 86 | $self->refilter; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | sub _visible_func { | ||
| 91 | my ($child_model, $child_iter, $ref_weak_self) = @_; | ||
| 92 | if (DEBUG) { print "test ",$child_model->get_value($child_iter,0),"\n"; } | ||
| 93 | my $self = $$ref_weak_self || return; | ||
| 94 | return ($child_model->get_value($child_iter,0) =~ $self->{'regexp'}); | ||
| 95 | } | ||
| 96 | |||
| 97 | 1; | ||
| 98 | __END__ |