File: notes.pl

package info (click to toggle)
kildclient 2.5.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 5,540 kB
  • ctags: 1,595
  • sloc: ansic: 21,480; xml: 6,112; sh: 4,000; perl: 2,134; makefile: 178; sed: 16
file content (118 lines) | stat: -rw-r--r-- 2,596 bytes parent folder | download | duplicates (2)
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
package notes;
#: Version: 1.0.0
#: Description: Assing notes to worlds
#: Author: Eduardo M Kalinowski
#
# $Id: notes.pl,v 1.2 2005/04/02 21:10:09 ekalin Exp $

BEGIN {
  eval "use Gtk2 -init;";
  die "This plugin requires the gtk-perl bindings" if $@;
}

$::world->makepermanent('$notes::notetext');


our $window_created = 0;
our $window;
our $text_buffer;


sub help {
  $::world->echonl("",
  "This plugin allows you to assign notes to World. The notes are saved",
  "with the World and are restored when it is opened again.",
  "",
  "Run /notes::edit to open a window where you can edit the notes.",
  "",
  "Run /notes::clear to clear the contents of the notes.",
  "",
  "It is possible to append something to the notes with /notes::append('text')",
  "This is probably more useful in scripts."
  );
}


sub edit {
  unless ($window_created) {
    create_window();
    $window->show_all();
    $window_created = 1;
  }

  $window->present;
}


sub clear {
  $notetext = "";
  update_text_view();
}


sub append {
  my $newtext = $_[0];
  $newtext .= "\n" unless (substr($_[0], -1) eq "\n");

  $notetext .= $newtext;
  update_text_view();
}


sub UNLOAD {
  if ($window_created) {
    update_text();
    $window->destroy;
  }
}


sub create_window {
  $window = Gtk2::Window->new;
  $window->set_title("Notes for " . $::world->getname());
  $window->signal_connect(delete_event => sub {
                            update_text();
                            $window->hide();
                            return 1;
                          });
  $window->signal_connect(focus_out_event => sub {
                            update_text();
                          });

  my $vbox = Gtk2::VBox->new;

  my $scroll_win = Gtk2::ScrolledWindow->new;
  $scroll_win->set_policy('never', 'always');

  my $text_view = Gtk2::TextView->new;
  $text_view->set_size_request(400, 150);
  $text_buffer = $text_view->get_buffer;
  update_text_view();

  $scroll_win->add($text_view);
  $vbox->pack_start($scroll_win, 1, 1, 0);

  my $btn_close = Gtk2::Button->new_from_stock('gtk-close');
  $btn_close->signal_connect(clicked => sub {
                               update_text();
                               $window->hide;
                               $window_displayed = 0;
                             });
  $vbox->pack_start($btn_close, 0, 0, 0);

  $window->add($vbox);
}


sub update_text {
  $notetext = $text_buffer->get_text($text_buffer->get_bounds(), 0);
}


sub update_text_view {
  return unless $text_buffer;

  if (defined($notetext)) {
    $text_buffer->set_text($notetext);
  }
}