App-Chart

 view release on metacpan or  search on metacpan

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

  my ($entry_or_button) = @_;
  my $self = $entry_or_button->get_toplevel;
  my $treeview = $self->{'symbols_treeview'};
  my $pos = treeview_pos_after_selected_or_top_of_visible ($treeview);

  my $entry = $self->{'symbol_entry'};
  my $symlist = $self->{'symlist'};
  if (! $symlist->can_edit) {  # supposed to be insensitive anyway
    $entry->error_bell;
    return;
  }

  # select text for ease of typing another
  Gtk2::Ex::EntryBits::select_region_noclip ($entry, 0, -1);

  my $symbol = $entry->get_text;
  if (my $path = $symlist->find_symbol_path ($symbol)) {
    # already exists, move to it
    Gtk2::Ex::TreeViewBits::scroll_cursor_to_path ($treeview, $path);
    return;
  }
  $symlist->insert_with_values ($pos, 0=>$symbol);

  my $path = Gtk2::TreePath->new_from_indices ($pos);
  Gtk2::Ex::TreeViewBits::scroll_cursor_to_path ($treeview, $path);

  # request this, everything else as extras
  if ($symbol ne '') {
    require App::Chart::Gtk2::Job::Latest;
    App::Chart::Gtk2::Job::Latest->start ([$symbol]);
  }
}

#------------------------------------------------------------------------------
# generic helpers

sub treeview_pos_after_selected_or_top_of_visible {
  my ($treeview) = @_;

  my ($lo_path, $hi_path) = $treeview->get_visible_range;
  my ($lo) = $lo_path ? $lo_path->get_indices : (-1);
  my ($hi) = $hi_path ? $hi_path->get_indices : (-1);
  my $pos = $lo + 1;

  my $selection = $treeview->get_selection;
  my ($sel_path) = $selection->get_selected_rows;
  if ($sel_path) {
    my ($sel) = $sel_path->get_indices;
    if ($sel >= $lo && $sel <= $hi) {
      $pos = $sel + 1;
    }
  }
  return $pos;
}

#------------------------------------------------------------------------------

sub main {
  my ($class, $args) = @_;

  Gtk2->disable_setlocale;  # leave LC_NUMERIC alone for version nums
  Gtk2->init;

  require Gtk2::Ex::ErrorTextDialog::Handler;
  Glib->install_exception_handler
    (\&Gtk2::Ex::ErrorTextDialog::Handler::exception_handler);
  ## no critic (RequireLocalizedPunctuationVars)
  $SIG{'__WARN__'} = \&Gtk2::Ex::ErrorTextDialog::Handler::exception_handler;
  ## use critic

  require App::Chart::Gtk2::TickerMain;
  my $symlist = App::Chart::Gtk2::TickerMain::args_to_symlist ($args);

  my $self = $class->new;
  $self->set (symlist => $symlist);
  $self->signal_connect (destroy =>
                         \&App::Chart::Gtk2::TickerMain::_do_destroy_main_quit);
  $self->show_all;
  Gtk2->main;
}

1;
__END__

=for stopwords watchlist Watchlist Popup

=head1 NAME

App::Chart::Gtk2::WatchlistDialog -- watchlist dialog module

=head1 SYNOPSIS

 use App::Chart::Gtk2::WatchlistDialog;

=head1 WIDGET HIERARCHY

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

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

=head1 DESCRIPTION

A C<App::Chart::Gtk2::WatchlistDialog> widget is a watchlist display and dialog.

=head1 FUNCTIONS

=over 4

=item C<< App::Chart::Gtk2::WatchlistDialog->new (key=>value,...) >>

Create and return a new Watchlist dialog widget.

=back

=head1 SEE ALSO



( run in 0.518 second using v1.01-cache-2.11-cpan-ceb78f64989 )