//
//  The Pimp      The Pathetic Image Manipulation Program
//  Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
//                All Rights Reserved
//
//  $Id$
//
//  This library is free software. It comes without any warranty, to
//  the extent permitted by applicable law. You can redistribute it
//  and/or modify it under the terms of the Do What The Fuck You Want
//  To Public License, Version 2, as published by Sam Hocevar. See
//  http://sam.zoy.org/wtfpl/COPYING for more details.
//

using System;
using Gtk;
using Pipi;
using ThePimp;

namespace ThePimp
{
    public partial class MainWindow: Gtk.Window
    {
        public MainWindow (): base (Gtk.WindowType.Toplevel)
        {
            Build ();
            Title += " v" + Libpipi.getVersion();
        }

        protected void OnDeleteEvent (object sender, DeleteEventArgs a)
        {
            Application.Quit ();
            a.RetVal = true;
        }

        protected virtual void OnOpenActionActivated (object sender, System.EventArgs e)
        {
            OpenFile open = new OpenFile();
            Pipi.Picture p = open.Load();
            open.Destroy();
            if(p != null)
            {
                while(notebook1.NPages > 0)
                    notebook1.RemovePage(0);
                int n = notebook1.AppendPage(new PictureView(p),
                                             new Label(p.FileName));
                notebook1.Page = n;
            }
        }

        protected virtual void OnQuitActionActivated (object sender, System.EventArgs e)
        {
            Application.Quit ();
        }

        protected virtual void OnSaveAsActionActivated (object sender, System.EventArgs e)
        {
            SaveFile save = new SaveFile();
            PictureView view = notebook1.CurrentPageWidget as PictureView;
            save.Save(view.Picture);
            save.Destroy();
        }

        protected virtual void OnAboutActionActivated (object sender, System.EventArgs e)
        {
            new About();
        }
    }
}