summaryrefslogtreecommitdiff
path: root/Master/texmf/scripts/texlive/tlmgrgui/do_listframe.pl
blob: 3df4a668b6390341da05e4b1bce64e8eb907dced (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# guinb1.pl
# $Id$
#
# Copyright 2008 Tomasz Luczak
# Copyright 2008, 2009 Norbert Preining
#
# GUI for tlmgr
#


sub validate_search_input {
  my ($w, $iw, $str, @l) = @_;
  my $found = -1;
  for (my $i = 0; $i < @l; $i++) {
    my $pkg = $l[$i];
    $pkg =~ s/^\s*(\(i\) )?//;
    if ($pkg =~ m;$str;i) {
      $found = $i;
      last;
    }
  }
  if ($found >= 0) {
    $w->selectionClear(0,"end");
    $w->yview($found);
    $w->selectionSet($found);
    update_info_window($w, $iw, @l);
  } else {
    $w->selectionClear(0,"end");
  }
  return(1);
}
 
sub find_next_search_match {
  my ($w, $e, $iw, @l) = @_;
  # first get the current selection
  my @cursel = $w->curselection;
  if (!@cursel) {
    push @cursel, 0;
  }
  my $str = $e->get;
  my $found = -1;
  for (my $i = $cursel[0] + 1; $i < @l; $i++) {
    my $pkg = $l[$i];
    $pkg =~ s/^\s*(\(i\) )?//;
    if ($pkg =~ m;$str;i) {
      $found = $i;
      last;
    }
  }
  if ($found >= 0) {
    $w->selectionClear(0,"end");
    $w->yview($found);
    $w->selectionSet($found);
    update_info_window($w, $iw, @l);
  }
}

sub update_info_window {
  my ($lb, $iw, @l) = @_;
  my @selind = $lb->curselection;
  return if (!@selind);
  my $pkgname = $l[$selind[0]];
  $pkgname =~ s/^\s*(\(i\) )?//;
  my $tlp;
  my $longdesc;
  my $shortdesc;
  if (defined($tlmediatlpdb)) {
    $tlp = $tlmediatlpdb->get_package($pkgname);
  } else {
    $tlp = $localtlpdb->get_package($pkgname);
  }
  if (defined($tlp)) {
    $longdesc = $tlp->longdesc;
    $shortdesc = $tlp->shortdesc;
  }
  my $text = "";
  if ($shortdesc) {
    $text .= $shortdesc;
    $text .= "\n\n";
  }
  if ($longdesc) {
    my @words = split /\s+/, $longdesc;
    my $i = 0;
    while (@words) {
      my $w = shift @words;
      my $l = length($w);
      if ($i + $l + 1 < 45) {
        $text .= " $w";
        $i += $l + 1;
      } else {
        $text .= "\n$w";
        $i = $l;
      }
    }
  }
  if ($text eq "") {
    $text = ___"nodescription";
  }
  $iw->delete("0.0", "end");
  $iw->insert("0.0", "$text");
  $iw->see("0.0");
}

sub do_listframe {
  my ($f, $title, $listref, $buttonsref, $with_force, $with_deps) = @_;

  # row 1, column 1-2
  my $f_title = $f->Frame(-relief => 'ridge', -borderwidth => 2);
  $f_title->Label( -text => $title,
                   -foreground => "blue", 
                   -font => "helvetica 10 bold"
                 )->pack(-side => "top");
  $f_title->Label( -text => ___"ctrlshift"
                 )->pack(-side => "top");
  $f_title->grid( -row => 1, -column => 1, -columnspan => 2,
                  -padx => "2m", -pady => "2m", -sticky => "we");

  # column 1, row 2-3

  my $f_listf = $f->Labelframe(-text => ___"selpkg");
  $f_listf->grid( -row => 2, -column => 1, -rowspan => 2,
                  -sticky => "nswe", -padx => "2m", -pady => "1m");

  my $f_listf_lb;
  my $f_textf_text;
  my $f_listf_searchf = $f_listf->Frame;
  $f_listf_searchf->pack(-pady => "1m");
  my $f_listf_searchf_label = 
    $f_listf_searchf->Label(-text => ___"search")->pack( -anchor => "w", 
                                                      -side => "left", 
                                                      -padx => "1m", 
                                                      -pady => "1m");
  my $f_listf_searchf_entry = $f_listf_searchf->Entry( -validate => "key", 
    -validatecommand => 
      sub { validate_search_input($f_listf_lb, 
                                  $f_textf_text, 
                                  $_[0], 
                                  @$listref); });
  my $f_listf_searchf_button = $f_listf_searchf->Button(-text => ___"next", 
      -command => sub { find_next_search_match($f_listf_lb, 
                                               $f_listf_searchf_entry, 
                                               $f_textf_text, 
                                               @$listref);  });
  $f_listf_searchf_entry->pack(
    -anchor => "w", -side => "left", -padx => "1m", -pady => "1m");
  $f_listf_searchf_button->pack(
    -anchor => "w", -side => "left", -padx => "1m", -pady => "1m");

  $f_listf_lb = $f_listf->Scrolled("Listbox",
    -listvariable => $listref,
    -selectmode => "extended",
    -scrollbars => "ose"
  );
  $f_listf_lb->bind('<<ListboxSelect>>', 
    sub { update_info_window ($f_listf_lb, $f_textf_text, @$listref); });
  $f_listf_lb->pack(-fill => "both", -expand => 1);

  # row 2 column 2
  my $f_textf = $f->Labelframe(-text => ___"infoitem");
  $f_textf->grid(-row => 2, -column => 2, -sticky => "nswe", 
                 -padx => "2m", -pady => "1m");

  # we would like to have -scrollbars => "oe" here so that it does disappear
  # if the text is not too long, but this doesn't work since Windows Perl/Tk
  # is broken and does not update the scrollbar properly, you have to first
  # select something while scrolling, then finally it works. Ok, so show
  # it all the time ...
  $f_textf_text = $f_textf->Scrolled("ROText", 
    -scrollbars => "e",
    -width => 45, -wrap => "word");

  $f_textf_text->pack(-expand => 1, -fill => "both");

  # row 3 column 2
  my $f_buttonf = $f->Labelframe();
  $f_buttonf->grid(-row => 3, -column => 2, 
      -padx => "2m", -pady => "2m", -sticky => "we");

  my $f_buttonf_optionsf = $f_buttonf->Frame();
  if ($with_force) {
    my $foo = $f_buttonf_optionsf->Checkbutton(-text => ___"force", 
                                     -variable => \$opts{"force"}
                                    )->pack(-side => 'left');
    $balloon->attach($foo,-balloonmsg => ___"forceballoon");
  }
  if ($with_deps) {
    my $foo = $f_buttonf_optionsf->Checkbutton(-text => ___"withoutdep", 
                                   -variable => \$opts{"no-depends"}
                                  )->pack(-side => 'left');
    $balloon->attach($foo,-balloonmsg => ___"nodepballoon");
  }
  $f_buttonf_optionsf->pack;
  foreach my $k (keys %$buttonsref) {
    $f_buttonf->Button(-text => $buttonsref->{$k}{'-text'},
      -command => sub { my @l = $f_listf_lb->curselection;
                        my @pl;
                        foreach my $i (@l) {
                          my @all = @$listref;
                          my $foo = $all[$i];
                          $foo =~ s/^\s*(\(i\) )?//;
                          push @pl, $foo;
                        }
                        my $coderef = $buttonsref->{$k}{'-command'};
                        my @allargs;
                        if (defined($buttonsref->{$k}{'-args'})) {
                          push @allargs, @{$buttonsref->{$k}{'-args'}};
                        }
                        push @allargs, @pl;
                        &$coderef(@allargs);
                        $f_listf_lb->configure(-listvariable => $listref);
                      })->pack( -expand => 0, -fill => "both",
                                -padx => "2m", -pady => "2m");
  }
  $f->gridRowconfigure(1,-weight => 0);
  $f->gridRowconfigure(2,-weight => 1);
  $f->gridRowconfigure(3,-weight => 0);
  $f->gridColumnconfigure(1,-weight => 1);
  $f->gridColumnconfigure(2,-weight => 1);
  return($f_textf_text, $f_listf_lb);
}

1;

### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End:
# vim:set tabstop=2 expandtab: #