App-Chart

 view release on metacpan or  search on metacpan

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

      App::Chart::Database->add_symbol ($symbol);
      $self->_do_open ($symbol);
      require App::Chart::Gtk2::DownloadDialog;
      App::Chart::Gtk2::DownloadDialog->popup_update ($symbol, $self);
    }

  } elsif ($response eq 'cancel' || $response eq 'delete-event') {
    $self->hide;

  } elsif ($response eq 'help') {
    require App::Chart::Manual;
    App::Chart::Manual->open(__p('manual-node','Open'), $self);
  }
}

# called:
#     entry widget 'activate'
#     enter button 'clicked'
#     dialog RESPONSE_OPEN
#
sub _do_entry_open {
  my ($widget) = @_;
  my $self = $widget->get_toplevel;
  my $str = $self->entry_str;
  if ($str eq '') {
    $widget->error_bell;
    return;
  }
  my $preferred_symlist = $self->tree_current_symlist;
  my ($symbol, $symlist)
    = App::Chart::SymbolMatch::find ($str, $preferred_symlist);
  if (! $symbol) { $symbol = $str; }
  $self->_do_open ($symbol, $symlist);
}

sub _do_open {
  my ($self, $symbol, $symlist) = @_;
  ### _do_open: $symbol
  ###  symlist: $symlist && $symlist->key
  my $notfound = $self->{'notfound'};
  if (! $notfound->visible

      && ! App::Chart::Database->symbol_exists($symbol)) {
    $self->{'entry'}->set_text ($symbol);
    $notfound->show;
    return;
  }
  $notfound->hide;
  require App::Chart::Gtk2::Main;
  my $main = App::Chart::Gtk2::Main->find_for_dialog ($self);
  $main->show;
  $self->hide;
  $main->goto_symbol ($symbol, $symlist);
}

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

sub tree_current_symlist {
  my ($self) = @_;
  my $treeview = $self->{'treeview'};
  my ($path, $focus_column) = $treeview->get_cursor;
  if (! $path) { return undef; }

  my $model = $self->{'model'};
  my $iter = $model->get_iter ($path) || return undef;

  # OpenModel
  return $model->get_value ($iter, $model->COL_SYMLIST_OBJECT);

#   if (! $model->iter_has_child ($iter)) {
#     $iter = $model->iter_parent ($iter);
#   }
#   my $key = $model->get_value ($iter, $model->COL_SYMLIST_KEY);
#   return App::Chart::Gtk2::Symlist->new_from_key ($key);
}

sub entry_str {
  my ($self) = @_;
  my $entry = $self->{'entry'};
  return App::Chart::collapse_whitespace ($entry->get_text());
}

sub _do_entry_changed {
  my ($entry) = @_;
  my $self = $entry->get_toplevel;
  $self->{'notfound'}->hide;

  my $str = $self->entry_str;
  # "New" button active when symbol entered
  $self->set_response_sensitive (RESPONSE_NEW, $str ne '');

  require App::Chart::SymbolMatch;
  my $preferred_symlist = $self->tree_current_symlist;
  my ($symbol, $symlist)
    = App::Chart::SymbolMatch::find ($str, $preferred_symlist);
  ### OpenDialog: $str
  ### $symbol
  ### symlist: $symlist && $symlist->name
  if ($symbol && $symlist) {
    $self->scroll_to_symbol_and_symlist ($symbol, $symlist);
  }
}

sub scroll_to_symbol_and_symlist {
  my ($self, $symbol, $symlist) = @_;
  my $treeview = $self->{'treeview'};
  my $model = $self->{'model'};
  my $path = $model->path_for_symbol_and_symlist ($symbol, $symlist);
  if (! $path) {
    die "OpenDialog: oops, no path for $symbol, $symlist";
  }
  ### OpenDialog scroll to: $path->to_string
  Gtk2::Ex::TreeViewBits::scroll_cursor_to_path ($treeview, $path);
}

# 'row-activated' signal on the TreeView
sub _do_row_activated {
  my ($treeview, $path, $treeviewcolumn) = @_;
  ### OpenDialog row_activated: $path->to_string
  my $self = $treeview->get_toplevel;
  my $model = $self->{'model'};
  my $iter = $model->get_iter ($path) || do {
    $self->error_bell;
    return;
  };
  $self->_do_open ($model->get ($iter, $model->COL_ITEM_SYMBOL),
                   $model->get ($iter, $model->COL_SYMLIST_OBJECT));
}

# data setup for the renderer
sub _cell_data_func {
  my ($self, $renderer, $model, $iter) = @_;
  my $path = $model->get_path ($iter);
  my $str;
  if ($path->get_depth == 1) {
    $str = $model->get_value ($iter, $model->COL_SYMLIST_NAME);
  } else {
    if (defined ($str = $model->get_value ($iter, $model->COL_ITEM_SYMBOL))) {
      if (my $name = App::Chart::Database->symbol_name ($str)) {
        $str .= " - $name";
      }
    } else {
      $str = 'oops, no symbol at path=' . $path->to_string;
    }
  }
  $renderer->set (text => $str);
}

1;
__END__


=head1 NAME

App::Chart::Gtk2::OpenDialog -- open dialog widget

=head1 SYNOPSIS

 use App::Chart::Gtk2::OpenDialog;
 my $dialog = App::Chart::Gtk2::OpenDialog->new;

=head1 WIDGET HIERARCHY

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

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

=head1 DESCRIPTION



( run in 0.693 second using v1.01-cache-2.11-cpan-39bf76dae61 )