package Milkbone::Conf;

use Milkbone;

our $VERSION = '1.0';

use Tk::widgets qw(Frame TextUndo);
use base qw(Tk::Toplevel);
use strict;
use warnings;

Construct Tk::Widget 'MBConf';

sub ClassInit
{
    my ($class, $mw) = @_;
    $class->SUPER::ClassInit($mw);
}

sub init
{
    my ($self) = @_;
    $self->withdraw;

    $self->{text} = $self->Frame->pack(-expand => 1, -fill => 'both')->Scrolled(
                                                                                "TextUndo", -scrollbars => 'oe', -background => 'white', -wrap => 'word')->
                                                                                pack(-expand => 1, -fill => 'both');
    
    $self->Button(-text => "Close", -command => [$self, "destroy"])->pack(-side => 'right');
    $self->Button(-text => "Save", -command => [$self, "on_save"])->pack(-side => 'right');

    $self->{text}->bind('<MouseWheel>', 
                        [ sub { $_[0]->yview('scroll', -($_[1] / 120), 'units') }, Tk::Ev('D')]);

    $self->{text}->Load('mb.conf');

    $self->deiconify;
    $self->{text}->focus;
    hook("tk_seticon", -wnd => $self);
}

sub on_save
{
    my ($self) = @_;
    
    $self->{text}->Save;
    hook("load_options");
    
    $self->destroy;
}