File: Entry.pm

package info (click to toggle)
libcircle-be-perl 0.173320-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 388 kB
  • sloc: perl: 6,042; makefile: 2; sh: 1
file content (109 lines) | stat: -rw-r--r-- 2,046 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#  You may distribute under the terms of the GNU General Public License
#
#  (C) Paul Evans, 2008-2013 -- leonerd@leonerd.org.uk

package Circle::Widget::Entry;

use strict;
use warnings;
use base qw( Circle::Widget );

our $VERSION = '0.173320';

sub new
{
   my $class = shift;
   my %args = @_;

   my $self = $class->SUPER::new( @_ );

   $self->{on_enter} = $args{on_enter};
   $self->{history}  = $args{history};

   $self->set_prop_text( "" );
   $self->set_prop_autoclear( $args{autoclear} );

   return $self;
}

sub method_enter
{
   my $self = shift;
   my ( $ctx, $text ) = @_;
   $self->{on_enter}->( $text, $ctx );

   if( defined( my $history = $self->{history} ) ) {
      my $histqueue = $self->get_prop_history;

      my $overcount = @$histqueue + 1 - $history;

      $self->shift_prop_history( $overcount ) if $overcount > 0;

      $self->push_prop_history( $text );
   }
}

sub set_on_typing
{
   my $self = shift;
   my ( $on_typing ) = @_;

   $self->{on_typing} = $on_typing;

   $self->set_prop_want_typing( defined $self->{on_typing} );
}

sub method_typing
{
   my $self = shift;
   my ( $ctx, $typing ) = @_;
   $self->{on_typing}->( $typing ) if $self->{on_typing};
}

package Circle::Widget::Entry::CompleteGroup;

use base qw( Tangence::Object );

sub new
{
   my $class = shift;
   my %args = @_;

   my $self = $class->SUPER::new( @_ );

   $self->set_prop_only_at_sol( $args{only_at_sol} || 0 );
   $self->set_prop_prefix_sol( $args{prefix_sol} || '' );
   $self->set_prop_suffix_sol( $args{suffix_sol} || '' );

   return $self;
}

sub set
{
   my $self = shift;
   my ( @strings ) = @_;

   $self->set_prop_items( \@strings );
}

sub add
{
   my $self = shift;
   my ( $str ) = @_;

   grep { $_ eq $str } @{ $self->get_prop_items } or
      $self->push_prop_items( $str );
}

sub remove
{
   my $self = shift;
   my ( $str ) = @_;

   my $items = $self->get_prop_items;
   my @indices = grep { $items->[$_] eq $str } 0 .. $#$items;

   $self->splice_prop_items( $_, 1, () ) for reverse @indices;
}

0x55AA;