# -*- Perl -*-
#
# This is part of X-RUST 1.0 Beta 4.
#
# Copyright (C) 1996 Craig Ruefenacht <ruefenac@cs.utah.edu> and the
#                    University of Utah, Department of Computer Scinece
#
#                    Shawn T. Amundson <amundson@cs.umn.edu> and the
#                    University of Minnesota Computer Science Department
#
# Abstract: This file contains definitions and subroutines which deal with
#           commenting a request in X-Rust.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with the source distribution of Inquire, in the license
# directory. If you don't have a copy of it, write to: 
#
# Free Software Foundation, Inc.
# 675 Mass Ave
# Cambridge, MA 02139, USA.
#

#
# $Id: xrust_comment.pl,v 1.1.1.1 2000/05/03 19:54:39 wright Exp $
#

use strict;
use vars qw(%REQUESTS $MW %QUEUE_INDEX %BIN %FONTS %GEOMETRY);

sub add_comments {

    my $queue_name = shift;
    my $request_num = shift;

    #
    # Raise and return if window already exists...
    #
    if ($REQUESTS{$queue_name}->{$request_num}->{'_comment_window'}) {
	$REQUESTS{$queue_name}->{$request_num}->{'_comment_window'}->raise;
	return;
    }

    #
    # Create the window...
    #
    my $CMW = $MW->Toplevel;
    $CMW->geometry($GEOMETRY{'COMMENT'});

    $REQUESTS{$queue_name}->{$request_num}->{'_comment_window'} = $CMW;
    $REQUESTS{$queue_name}->{$request_num}->{'_comment_window'}->bind('<Destroy>', 
		  sub {
		      undef $REQUESTS{$queue_name}->{$request_num}->{'_comment_window'};
		  });
    $REQUESTS{$queue_name}->{$request_num}->{'_comment_window'}->title("Commenting Request $queue_name #$request_num"); 

    my $comment_info = $CMW->Frame;
    $comment_info->pack(
			-side => 'top', 
			-fill => 'x',
			-pady => 4,
			-padx => 4
		       );	
    my $comment_info_t1 = $comment_info->Label(
                                            -font => $FONTS{'TEXT_FONT'},
					    -text => "Add comments to $queue_name #$request_num",
					    -relief => 'groove'
					   );
    $comment_info_t1->pack(
			   -side => 'top', 
			   -fill => 'x'
			  );

    my $subject = $comment_info->Frame;
    $subject->pack(-side => 'top', -fill => 'x');

    my $subject_label = $subject->Label(
                                        -font => $FONTS{'TEXT_FONT'},
					-text => 'Subject:'
					);
    $subject_label->pack(-side => 'left');
    
    my $subject_text = $subject->Label(
                                       -font => $FONTS{'TEXT_FONT'},
				       -text => $REQUESTS{$queue_name}->{$request_num}->{'subject'}
				       );
    $subject_text->pack(-side => 'left');

    my $text_frame = $CMW->Frame;
    $text_frame->pack(
		      -side => 'top',
		      -fill => 'both',
		      -expand => 1,
		      -padx => 2,
		      -pady => 2
		     );

    my $comment_vert_scroll = $text_frame->Scrollbar(-orient => 'vertical');
    $comment_vert_scroll->pack(-side => 'right', -fill => 'y');

    my $comment_text = $text_frame->Text(
                                         -font           => $FONTS{'TEXT_FONT'},
					 -yscrollcommand =>  [$comment_vert_scroll => 'set'],
					 -width          => 70,
					 -height         => 20, 
					 -wrap           => 'none',
					 -setgrid        => 1,
					);

    $comment_vert_scroll->configure(-command => [$comment_text => 'yview']);
    $comment_text->pack(-expand => 1, -fill => 'both', -padx=>2,-pady=>2);
    
    my $button_frame = $CMW->Frame;
    $button_frame->pack(
			-side => 'top',
			-padx => 2,
			-pady => 2,
			-fill => 'x',
			-expand => 1
		       );

    my $button_width = 10;
    my @buttons_left = (
			-side => 'left'
			);
    my $button_add = $button_frame->Button(
                                           -font => $FONTS{'BUTTON_FONT'},
					   -text => 'Add',
					   -width => $button_width,
					   -command => sub { 
					       my $text = $comment_text->get('1.0','end');
					       my @contents = split(/\n/,$text);
					       foreach (0..$#contents) {
						   $contents[$_] = $contents[$_] . "\n";
					       }
					       my $index = &set_queue_index(0, $queue_name);
					       my @array = &do_comment($caller,1,$request_num,$index,@contents);
					       
					       if (!$array[0]) {
						   $CMW->destroy;
					       }
					       &display_request($queue_name,$request_num);
					       &set_status_bar('main',"$array[1]");
					   }
					   
					  );
    $button_add->pack(@buttons_left);

#    my $button_insert = $button_frame->Button(
#					      -text => 'Insert File...',
#                                              -font => $FONTS{'BUTTON_FONT'},
#					      -width => $button_width,
#					      -state => 'disabled'
#					    );
#    $button_insert->pack(@buttons_left);

    my @buttons_right = (
			 -side => 'right'
			 );

    my $button_cancel = $button_frame->Button(
					      -text => 'Cancel',
                                              -font => $FONTS{'BUTTON_FONT'},
					      -width => $button_width,
					      -command => sub {$CMW->destroy;}
					  );
    $button_cancel->pack(@buttons_right);

    my $button_clear = $button_frame->Button(
					     -text => 'Clear',
                                             -font => $FONTS{'BUTTON_FONT'},
					     -width => $button_width,
					     -command => sub {
						 $comment_text->delete("0.0",'end');
					     }
					    );
    $button_clear->pack(@buttons_right);
}

1;




