#!/usr/local/bin/perl
use warnings;
use strict;
use Tk;
# Predeclaring the subroutines and variables
sub initialize_step_selection();
sub select_soln_step();
sub deselect_soln_step();
sub modify_remove_step_dialog();
# Building the GUI skeleton, i.e. predeclaring some widgets
my $MW = MainWindow->new;
my $StepFrame;
my $AvailListbox;
my $SelectListbox;
# Run the subroutines
initialize_step_selection();
MainLoop();
# Creates the solutions frame, and its contents
sub initialize_step_selection() {
# Frame for selecting solutions
$StepFrame = $MW->Frame();
$StepFrame->pack(-fill => 'both');
# Scrollbars for available solutions
my $AvailScroll = $StepFrame->Scrollbar(-orient => 'vertical');
# Listbox of available solutions
$AvailListbox = $StepFrame->Listbox(-yscrollcommand => ['set' => $AvailScroll]);
$AvailListbox->pack(-fill => 'y', -side => 'left');
$AvailScroll->configure(-command => ['yview' => $AvailListbox]);
$AvailScroll->pack(-fill => 'y',-side => 'left');
$AvailListbox->insert('end', "Just", "for", "testing", "purposes");
# Scrollbar for selected solutions
my $SelectScroll = $StepFrame->Scrollbar(-orient => 'vertical');
# Listbox of selected solutions
$SelectListbox = $StepFrame->Listbox(-yscrollcommand => ['set' => $SelectScroll]);
$SelectListbox->pack(-fill => 'y', -side => 'left');
$SelectScroll->configure(-command => ['yview' => $SelectListbox]);
$SelectScroll->pack(-fill => 'y',-side => 'left');
# Select/Deselect solutions buttons
my $SelectStep = $StepFrame->Button(-text => ">",-command => sub{select_soln_step();});
$SelectStep->pack();
my $DeselectStep = $StepFrame->Button(-text => "<",-command => sub{deselect_soln_step();});
$DeselectStep->pack();
my $ModRmvStep = $StepFrame->Button(
-text => "Modify/Remove a Step",
-command => sub{modify_remove_step_dialog();}
);
$ModRmvStep->pack(
-padx => 2,
-pady => 3);
} # Closing initialize_step_selection()
####
sub modify_remove_step_dialog() {
my $ModRmvStep = $MW->Toplevel();
$ModRmvStep->title("Modifier une étape");
my $MRSFrame1 = $ModRmvStep->Frame(-label => "Sélectionnez une étape à modifier");
$MRSFrame1->pack(-fill => 'both');
# Listbox of available solutions
my $StepModRmvScroll = $MRSFrame1->Scrollbar(-orient => 'vertical');
$AvailListbox = $MRSFrame1->Listbox(-yscrollcommand => ['set' => $StepModRmvScroll]);
$AvailListbox->pack(-fill => 'both', -side => 'left');
$AvailListbox->insert('end', "Just", "for", "testing", "purposes");
# Configuring available listbox scrollbars
$StepModRmvScroll->configure(-command => ['yview' => $AvailListbox]);
$StepModRmvScroll->pack(-fill => 'y', -side => 'left');
my $MRSFrame2 = $ModRmvStep->Frame();
$MRSFrame2->pack(-fill => 'both');
my $MRSMod = $MRSFrame2->Button(-text => 'Rien');
$MRSMod->pack();
my $MRSCancel = $MRSFrame2->Button(-text => 'Rien');
$MRSCancel->pack();
my $MRSRmv = $MRSFrame2->Button(-text => 'Cancel', -command => sub{$ModRmvStep->withdraw;});
$MRSRmv->pack();
}
####
# This subroutine will move the selected solution from the AvailListbox
# to the SelectListbox
sub select_soln_step() {
# Get the contents of the current selection
my $selIndex = $AvailListbox->curselection();
# If no item is selected, we do nothing.
unless($selIndex eq "") {
my $selection = $AvailListbox->get($selIndex);
# Remove the selected value from the AvailListbox, and add it to the SelectListbox
$SelectListbox->insert('end', $selection);
$AvailListbox->delete($selIndex);
}
}
# This subroutine will move the selected solution from the SelectListbox
# to the AvailListbox
sub deselect_soln_step() {
# Get the contents of the current selection
my $selIndex = $SelectListbox->curselection();
# If no item is selected, we do nothing.
unless($selIndex eq "") {
my $selection = $SelectListbox->get($selIndex);
# Remove the selected value from the AvailListbox, and add it to the SelectListbox
$AvailListbox->insert('end', $selection);
$SelectListbox->delete($selIndex);
}
}