App-Codit
view release on metacpan or search on metacpan
lib/App/Codit/SessionManager.pm view on Meta::CPAN
my @sessions = ();
$self->{SESSIONS} = \@sessions;
$self->{PLUGIN} = $plug;
my $lb = $self->Scrolled('Listbox',
-scrollbars => 'osoe',
-listvariable => \@sessions,
-selectmode => 'single',
)->pack(-side => 'left', @padding, -fill => 'y',);
$self->Advertise('Listbox', $lb);
my $bf = $self->Frame(
-relief => 'groove',
-borderwidth => 2,
)->pack(-side => 'left', -fill => 'y', @padding);
$bf->Button(
-image => $art->createCompound(
-text => 'Open',
-image => $art->getIcon('document-open', 22),
),
-anchor => 'w',
-command => ['Open', $self],
)->pack(@padding, -fill => 'x');
$bf->Button(
-image => $art->createCompound(
-text => 'New session',
-image => $art->getIcon('document-new', 22),
),
-anchor => 'w',
-command => ['NewSession', $self],
)->pack(@padding, -fill => 'x');
$bf->Label(-text => ' ')->pack(@padding);
$bf->Button(
-image => $art->createCompound(
-text => 'Duplicate',
-image => $art->createEmptyImage(22),
),
-anchor => 'w',
-command => ['Duplicate', $self],
)->pack(@padding, -fill => 'x');
$bf->Button(
-image => $art->createCompound(
-text => 'Rename',
-image => $art->createEmptyImage(22),
),
-anchor => 'w',
-command => ['Rename', $self],
)->pack(@padding, -fill => 'x');
$bf->Label(-text => ' ')->pack(@padding);
$bf->Button(
-image => $art->createCompound(
-text => 'Delete',
-image => $art->getIcon('edit-delete', 22),
),
-anchor => 'w',
-command => ['Delete', $self],
)->pack(@padding, -fill => 'x');
$self->ConfigSpecs(
-background => ['SELF', 'DESCENDANTS'],
DEFAULT => [$self],
);
$self->Refresh;
}
sub Delete {
my $self = shift;
my $sel = $self->GetSelected;
return unless defined $sel;
my $plug = $self->{PLUGIN};
return if $sel eq $plug->sessionCurrent;
my $q = $self->YAMessage(
-title => 'Deleting session',
-image => $plug->getArt('dialog-warning', 32),
-buttons => [qw(Yes No)],
-text => "Deleting $sel.\nAre you sure?",
-defaultbutton => 'No',
);
my $answer = $q->Show(-popover => $self);
if ($answer eq 'Yes') {
$plug->sessionDelete($sel);
$self->Refresh;
}
}
sub Duplicate {
my $self = shift;
my ($sel) = $self->GetSelected;
return unless defined $sel;
my $name = $self->NameDialog("Enter duplicate name:");
my $plug = $self->{PLUGIN};
return unless defined $name;
return if $plug->sessionExists($name);
my $f = $plug->sessionFolder;
copy("$f/$sel", "$f/$name");
$self->Refresh;
}
sub GetSelected {
my $self = shift;
my ($sel) = $self->Subwidget('Listbox')->curselection;
return unless defined $sel;
return $self->{SESSIONS}->[$sel]
}
sub NameDialog {
my ($self, $text) = @_;
return $self->{PLUGIN}->popEntry('Session name', $text);
}
sub NewSession {
my $self = shift;
$self->{PLUGIN}->sessionNew;
$self->Pressed('Close');
}
sub Open {
my $self = shift;
( run in 0.430 second using v1.01-cache-2.11-cpan-0d23b851a93 )