App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Gtk2/AnnotationsDialog.pm  view on Meta::CPAN

            undef,
            $symbol, $id);
  App::Chart::chart_dirbroadcast()->send ('data-changed', { $symbol => 1 });
}

# 'activate' on the Gtk2::Entry and 'clicked' on the Gtk2::Button "Add"
sub _do_entry_enter {
  my ($entry_or_button, $self) = @_;

  my $symbol = $self->{'symbol'} || return;
  my $date = $self->{'datespinner'}->get_value;
  my $str = $self->{'entry'}->get_text;

  my $dbh = App::Chart::DBI->instance;
  App::Chart::Database::call_with_transaction
      ($dbh, sub {
         my $id = App::Chart::Annotation::next_id ('annotation', $symbol);

         $dbh->do('INSERT INTO annotation (symbol, id, date, note)
            VALUES (?,?,?,?)',
                  undef,
                  $symbol, $id, $date, $str);
       });
  App::Chart::chart_dirbroadcast()->send ('data-changed', { $symbol => 1 });
}

# 'edited' signal on the Date column Gtk2::Ex::DateSpinner::CellRenderer
sub _do_date_cell_edited {
  my ($renderer, $pathstr, $newstr, $self) = @_;
  my $path = Gtk2::TreePath->new_from_string ($pathstr);
  my $model = $self->{'store'};
  my $iter = $model->get_iter ($path);

  my $symbol = $self->{'symbol'} || return;
  my $id = $model->get_value ($iter, COL_ID);

  my $dbh = App::Chart::DBI->instance;
  $dbh->do('UPDATE annotation SET date=? WHERE symbol=? AND id=?',
           undef,
           $newstr, $symbol, $id);
  App::Chart::chart_dirbroadcast()->send ('data-changed', { $symbol => 1 });
}

# 'edited' signal on the Notes column Gtk2::CellRendererText
sub _do_note_cell_edited {
  my ($renderer, $pathstr, $newstr, $self) = @_;
  my $path = Gtk2::TreePath->new_from_string ($pathstr);
  my $model = $self->{'store'};
  my $iter = $model->get_iter ($path);

  my $symbol = $self->{'symbol'} || return;
  my $id = $model->get_value ($iter, COL_ID);

  my $dbh = App::Chart::DBI->instance;
  $dbh->do('UPDATE annotation SET note=? WHERE symbol=? AND id=?',
           undef,
           $newstr, $symbol, $id);
  App::Chart::chart_dirbroadcast()->send ('data-changed', { $symbol => 1 });
}

sub popup {
  my ($class, $symbol, $parent) = @_;
  if (! defined $symbol) { $symbol = ''; }
  require App::Chart::Gtk2::Ex::ToplevelBits;
  my $dialog = App::Chart::Gtk2::Ex::ToplevelBits::popup
    ($class,
     hide_on_delete => 1,
     screen => $parent);
  $dialog->set (symbol => $symbol);
  return $dialog;
}


1;
__END__

=for stopwords Popup

=head1 NAME

App::Chart::Gtk2::AnnotationsDialog -- annotations editing dialog

=head1 SYNOPSIS

 use App::Chart::Gtk2::AnnotationsDialog;
 App::Chart::Gtk2::AnnotationsDialog->popup;

=head1 WIDGET HIERARCHY

C<App::Chart::Gtk2::AnnotationsDialog> is a subclass of C<Gtk2::Dialog>.

    Gtk2::Widget
      Gtk2::Container
        Gtk2::Bin
          Gtk2::Window
            Gtk2::Dialog
              App::Chart::Gtk2::AnnotationsDialog

=head1 DESCRIPTION

...

=head1 FUNCTIONS

=over 4

=item C<< App::Chart::Gtk2::AnnotationsDialog->popup () >>

=item C<< App::Chart::Gtk2::AnnotationsDialog->popup ($symbol) >>

Popup a C<AnnotationsDialog> dialog for C<$symbol>, either re-presenting any
existing one or otherwise creating a new one.

=back

=cut



( run in 1.691 second using v1.01-cache-2.11-cpan-364913b4093 )