summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tvignaud@mandriva.org>2004-08-02 04:24:38 +0000
committerThierry Vignaud <tvignaud@mandriva.org>2004-08-02 04:24:38 +0000
commit54ab2293e6e0fda2b83e04efb94eb77f649703cc (patch)
tree8524f0edb551805c025860a4994bc41180a17ad7
parent35073f623b908d09df89c00c55fbf5a5a796a727 (diff)
downloaddrakx-backup-do-not-use-54ab2293e6e0fda2b83e04efb94eb77f649703cc.tar
drakx-backup-do-not-use-54ab2293e6e0fda2b83e04efb94eb77f649703cc.tar.gz
drakx-backup-do-not-use-54ab2293e6e0fda2b83e04efb94eb77f649703cc.tar.bz2
drakx-backup-do-not-use-54ab2293e6e0fda2b83e04efb94eb77f649703cc.tar.xz
drakx-backup-do-not-use-54ab2293e6e0fda2b83e04efb94eb77f649703cc.zip
(gtktext_insert) merge with text_append() from logdrake:
- name parameters - provide fast text insertion by using named tags instead of anonymous tags. this is especially usefull in order to speed up programs that use quite a lot of identical tags such as logdrake (#8412) and rpmdrake
-rw-r--r--perl-install/ugtk2.pm50
1 files changed, 42 insertions, 8 deletions
diff --git a/perl-install/ugtk2.pm b/perl-install/ugtk2.pm
index 96672bb51..4c3ccf6e5 100644
--- a/perl-install/ugtk2.pm
+++ b/perl-install/ugtk2.pm
@@ -617,27 +617,61 @@ sub may_set_icon {
}
}
-# choose one of the two styles:
-# - gtktext_insert($textview, "My text..");
-# - gtktext_insert($textview, [ [ 'first text', { 'foreground' => 'blue', 'background' => 'green', ... } ],
+# gtktext_insert() can be used with any of choose one of theses styles:
+# - no tags:
+# gtktext_insert($textview, "My text..");
+# - anonymous tags:
+# gtktext_insert($textview, [ [ 'first text', { 'foreground' => 'blue', 'background' => 'green', ... } ],
# [ 'second text' ],
# [ 'third', { 'font' => 'Serif 15', ... } ],
# ... ]);
+# - named tags:
+# $textview->{tags} = {
+# 'blue_green' => { 'foreground' => 'blue', 'background' => 'green', ... },
+# 'big_font' => { 'font' => 'Serif 35', ... },
+# }
+# gtktext_insert($textview, [ [ 'first text', 'blue_green' ],
+# [ 'second', 'big_font' ],
+# ... ]);
+# - mixed anonymous and named tags:
+# $textview->{tags} = {
+# 'blue_green' => { 'foreground' => 'blue', 'background' => 'green', ... },
+# 'big_font' => { 'font' => 'Serif 35', ... },
+# }
+# gtktext_insert($textview, [ [ 'first text', 'blue_green' ],
+# [ 'second text' ],
+# [ 'third', 'big_font' ],
+# [ 'fourth', { 'font' => 'Serif 15', ... } ],
+# ... ]);
sub gtktext_insert {
my ($textview, $t, %opts) = @_;
my $buffer = $textview->get_buffer;
+ $buffer->{tags} ||= {};
+ $buffer->{gtk_tags} ||= {};
+ my $gtk_tags = $buffer->{gtk_tags};
+ my $tags = $buffer->{tags};
if (ref($t) eq 'ARRAY') {
$opts{append} or $buffer->set_text('');
foreach my $token (@$t) {
+ my ($item, $tag) = @$token;
my $iter1 = $buffer->get_end_iter;
- if ($token->[0] =~ /^Gtk2::Gdk::Pixbuf/) {
- $buffer->insert_pixbuf($iter1, $token->[0]);
+ if ($item =~ /^Gtk2::Gdk::Pixbuf/) {
+ $buffer->insert_pixbuf($iter1, $item);
next;
}
- if ($token->[1]) {
- $buffer->insert_with_tags($iter1, $token->[0], $buffer->create_tag(undef, %{$token->[1]}));
+ if ($tag) {
+ if (ref($tag)) {
+ # fast text insertion:
+ # since in some contexts (eg: localedrake, rpmdrake), we use quite a lot of identical tags,
+ # it's much more efficient and less memory pressure to use named tags
+ $buffer->insert_with_tags($iter1, $item, $buffer->create_tag(undef, %$tag));
+ } else {
+ # use anonymous tags
+ $gtk_tags->{$tag} ||= $buffer->create_tag($tag, %{$tags->{$token->[1]}});
+ $buffer->insert_with_tags($iter1, $item, $gtk_tags->{$tag});
+ }
} else {
- $buffer->insert($iter1, $token->[0]);
+ $buffer->insert($iter1, $item);
}
}
} else {