| 1 | # Copyright 2007, 2008, 2009, 2010, 2011, 2013 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Chart. | ||
| 4 | # | ||
| 5 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 6 | # terms of the GNU General Public License as published by the Free Software | ||
| 7 | # Foundation; either version 3, or (at your option) any later version. | ||
| 8 | # | ||
| 9 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 12 | # details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | |||
| 17 | package App::Chart::Gtk2::DeleteSymlistDialog; | ||
| 18 | 1 | ▶ | use 5.010; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 0 | ▶ | use Glib; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 22 | use Gtk2; | ||
| 23 | use Locale::TextDomain ('App-Chart'); | ||
| 24 | |||
| 25 | use App::Chart::Glib::Ex::MoreUtils; | ||
| 26 | use Glib::Ex::SignalIds; | ||
| 27 | use App::Chart::Database; | ||
| 28 | use App::Chart::Gtk2::GUI; | ||
| 29 | |||
| 30 | use App::Chart::Gtk2::Symlist; | ||
| 31 | use Glib::Object::Subclass | ||
| 32 | 'Gtk2::MessageDialog', | ||
| 33 | properties => [Glib::ParamSpec->object | ||
| 34 | ('symlist', | ||
| 35 | 'symlist', | ||
| 36 | 'The symlist to ask about deleting', | ||
| 37 | 'App::Chart::Gtk2::Symlist', | ||
| 38 | Glib::G_PARAM_READWRITE)]; | ||
| 39 | |||
| 40 | sub INIT_INSTANCE { | ||
| 41 | my ($self) = @_; | ||
| 42 | |||
| 43 | $self->set (message_type => 'question', | ||
| 44 | modal => 1, | ||
| 45 | title => __('Chart: Delete Symlist')); | ||
| 46 | $self->add_buttons ('gtk-ok' => 'ok', | ||
| 47 | 'gtk-cancel' => 'close'); | ||
| 48 | $self->signal_connect (response => \&_do_response); | ||
| 49 | } | ||
| 50 | |||
| 51 | sub SET_PROPERTY { | ||
| 52 | my ($self, $pspec, $newval) = @_; | ||
| 53 | my $pname = $pspec->get_name; | ||
| 54 | $self->{$pname} = $newval; # per default GET_PROPERTY | ||
| 55 | |||
| 56 | if ($pname eq 'symlist') { | ||
| 57 | my $symlist = $newval; | ||
| 58 | _update_text ($self); | ||
| 59 | |||
| 60 | $self->{'symlist_ids'} = $symlist && do { | ||
| 61 | my $ref_weak_self = App::Chart::Glib::Ex::MoreUtils::ref_weak ($self); | ||
| 62 | Glib::Ex::SignalIds->new | ||
| 63 | ($symlist, | ||
| 64 | $symlist->signal_connect (row_inserted => \&_do_row_insdel, | ||
| 65 | $ref_weak_self), | ||
| 66 | $symlist->signal_connect (row_deleted => \&_do_row_insdel, | ||
| 67 | $ref_weak_self)) | ||
| 68 | }; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | sub _do_row_insdel { | ||
| 73 | my $ref_weak_self = $_[-1]; | ||
| 74 | my $self = $$ref_weak_self || return; | ||
| 75 | _update_text ($self); | ||
| 76 | } | ||
| 77 | |||
| 78 | sub _update_text { | ||
| 79 | my ($self) = @_; | ||
| 80 | my $symlist = $self->{'symlist'}; | ||
| 81 | my $text; | ||
| 82 | if ($symlist) { | ||
| 83 | my $length = $symlist->length; | ||
| 84 | $text = "\n" | ||
| 85 | . __x('Delete symlist "{name}" ?', name => $symlist->name) | ||
| 86 | . "\n\n" | ||
| 87 | . __nx('It has {length} symbol in it.', | ||
| 88 | 'It has {length} symbols in it.', | ||
| 89 | $length, | ||
| 90 | length => $length); | ||
| 91 | } else { | ||
| 92 | $text = '(No symlist)'; | ||
| 93 | } | ||
| 94 | $self->set (text => $text); | ||
| 95 | } | ||
| 96 | |||
| 97 | # 'response' signal handler | ||
| 98 | sub _do_response { | ||
| 99 | my ($self, $response) = @_; | ||
| 100 | if ($response eq 'ok') { | ||
| 101 | if (my $symlist = $self->{'symlist'}) { | ||
| 102 | $self->set (symlist => undef); | ||
| 103 | $symlist->delete_symlist; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | $self->destroy; | ||
| 107 | } | ||
| 108 | |||
| 109 | sub popup { | ||
| 110 | my ($class, $symlist, $parent) = @_; | ||
| 111 | |||
| 112 | # if "modal" is obeyed by the window manager then there won't be any other | ||
| 113 | # delete dialogs open, but it doesn't hurt to let popup() search | ||
| 114 | require App::Chart::Gtk2::Ex::ToplevelBits; | ||
| 115 | return App::Chart::Gtk2::Ex::ToplevelBits::popup | ||
| 116 | ($class, | ||
| 117 | transient_for => $parent, | ||
| 118 | properties => { symlist => $symlist }); | ||
| 119 | } | ||
| 120 | |||
| 121 | 1; | ||
| 122 | __END__ | ||