Added support for completion
authorJoey Schulze <joey@infodrom.org>
Mon, 5 Nov 2007 19:50:31 +0000 (19:50 +0000)
committerJoey Schulze <joey@infodrom.org>
Mon, 5 Nov 2007 19:50:31 +0000 (19:50 +0000)
src/InfoCon/buch/infocon

index 45e64f5..5532276 100755 (executable)
@@ -167,6 +167,26 @@ sub sales_list
     }
 }
 
+sub get_descriptions
+{
+    my $query;
+    my @row;
+    my $sth;
+    my @arr = ();
+    my ($date_sec,$date_min,$date_hour,$date_mday,$date_mon,$date_year,$date_wday,$date_isdst)
+       = localtime;
+
+    $query  = sprintf("SELECT DISTINCT description FROM %s WHERE date LIKE '%d%%' ORDER by description",
+                     $table, $date_year+1900);
+    $sth = $dbh->prepare($query);
+    if ($sth && ($rc = $sth->execute) > 0) {
+       while (@row = $sth->fetchrow_array) {
+           push(@arr, $row[0]) if ($row[0]);
+       }
+    }
+    return @arr;
+}
+
 sub get_categories
 {
     my $query;
@@ -242,14 +262,30 @@ sub buchung_input
     my ($date_sec,$date_min,$date_hour,$date_mday,$date_mon,$date_year,$date_wday,$date_isdst)
        = localtime;
 
+    @categories = get_categories unless @categories;
+    my @descriptions = get_descriptions;
+
+    $term->addhistory($_) foreach (@categories);
+    $term->addhistory($_) foreach (@descriptions);
+
+    my $attribs = $term->Attribs;
+
     $sth = $dbh->prepare ("INSERT INTO $table VALUES (?,?,?,?,?,?,?,?,?)");
 
     print "Buchungseingabe\n\n";
     while ($weiter =~ /[JjYy1]/) {
        $i=0;while ($i <= $#fieldname) {
+           if ($fieldname[$i] eq "Category") {
+               $attribs->{completion_entry_function} = $attribs->{list_completion_function};
+               $attribs->{completion_word} = \@categories;
+           } elsif ($fieldname[$i] eq "Description") {
+               $attribs->{completion_entry_function} = $attribs->{list_completion_function};
+               $attribs->{completion_word} = \@descriptions;
+           } else {
+               $attribs->{completion_word} = undef;
+           }
            $ans = read_input($fieldname[$i],$input[$i]);
            if ($fieldname[$i] eq "Category" && $ans eq "?") {
-               @categories = get_categories unless @categories;
                printf "  %s\n", join (", ",@categories);
            } elsif ($fieldname[$i] eq "Datum") {
                if ($ans =~ /^\d+\.\d+.\d+$/) {