From 34c1e9816c87b5257bc2c4a0f2b162e639b31e33 Mon Sep 17 00:00:00 2001
From: Riley McGee <mcgeer@mcmaster.ca>
Date: Wed, 30 Nov 2016 13:33:52 -0500
Subject: [PATCH] Source Code Refactored to follow conventions, commented, and
 regions added to large files to help with code readability. (Closes #33)

---
 src/Gifitti/Gifitti/Models/GifModel.cs        | 109 ++++++-----
 src/Gifitti/Gifitti/Program.cs                |   3 -
 .../Gifitti/Properties/AssemblyInfo.cs        |   6 +-
 .../Gifitti/Transformation/TransformGif.cs    |  13 +-
 .../Gifitti/View_Models/HelpContext.cs        |  20 ++-
 .../Gifitti/View_Models/MainForm.Designer.cs  |  58 +++---
 src/Gifitti/Gifitti/View_Models/MainForm.cs   | 170 ++++++++----------
 .../Gifitti/View_Models/SaveAsXbyYPrompt.cs   |  49 +++--
 .../GifittiUnitTest/Helper/UnitTestHelper.cs  |   7 +-
 .../GifittiUnitTest/SubGif/SubGifUnitTest.cs  |   8 +-
 10 files changed, 223 insertions(+), 220 deletions(-)

diff --git a/src/Gifitti/Gifitti/Models/GifModel.cs b/src/Gifitti/Gifitti/Models/GifModel.cs
index cfeb6d4..68aedb7 100644
--- a/src/Gifitti/Gifitti/Models/GifModel.cs
+++ b/src/Gifitti/Gifitti/Models/GifModel.cs
@@ -1,13 +1,9 @@
 using ImageMagick;
 using System;
-using System.Collections.Generic;
 using System.Drawing;
 using System.Drawing.Imaging;
 using System.IO;
-using System.Linq;
-using System.Text;
 using System.Text.RegularExpressions;
-using System.Threading.Tasks;
 
 namespace Gifitti.Models
 {
@@ -16,20 +12,47 @@ namespace Gifitti.Models
     /// </summary>
     public class GifModel : IDisposable
     {
+        #region Public Instance Variables
+        /// <summary>
+        /// The currently handled GIF Image
+        /// </summary>
         public Image gifImage { get; set; }
+        /// <summary>
+        /// Originally loaded GIF, never Modified.
+        /// </summary>
         public Image originalGif { get; private set; }
-        private FrameDimension dimension;
+        /// <summary>
+        /// Number of frames in the GIF image
+        /// </summary>
         public int numberOfFrames { get; private set; }
+        /// <summary cref="numberOfFrames">
+        /// Start frame number for sub GIF, [0,numberOfFrames-1]
+        /// </summary>
+        public int startFrame = 0;
+        /// <summary cref="numberOfFrames">
+        /// End frame number for sub GIF, [0,numberOfFrames-1]
+        /// </summary>
+        public int endFrame = 0;
+        /// <summary>
+        /// ms Delay between frames
+        /// </summary>
+        public int delay { get; set; } = 0;
+        /// <summary>
+        /// Whether the gif should play backwards when it reaches the end
+        /// </summary>
+        public bool ReverseAtEnd { get; set; }
+        #endregion
+
+        #region Private Instance Variables
+        private FrameDimension dimension;
         private Image[] frames;
         private int step = 1;
         private int currentFrame = -1;
         private bool reverse;
-        public int startFrame = 0;
-        public int endFrame = 0;
         internal int originalDelay;
+        #endregion
 
-        public int delay { get; set; } = 0;
-
+        #region Instantiation and Disposal
         /// <summary>
         /// Load a GIF into the software model from the system path "path"
         /// </summary>
@@ -42,12 +65,20 @@ namespace Gifitti.Models
             PropertyItem item = originalGif.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
                                                              // Time is in 1/100ths of a second
             originalDelay = (item.Value[0] + item.Value[1] * 256) * 10;
-            delay = originalDelay;
+            delay = Math.Max(originalDelay, 20);
             this.gifImage = originalGif.Clone() as Image;
             dimension = new FrameDimension(originalGif.FrameDimensionsList[0]);
             frameConstruction(originalGif);
         }
 
+        /// <summary cref="IDisposable">
+        /// Frees system memory that may otherwise be left hanging.
+        /// </summary>
+        public void Dispose()
+        {
+            this.frames = null;
+        }
+
         /// <summary>
         /// Breaks GIF images into their frames.
         /// </summary>
@@ -73,7 +104,9 @@ namespace Gifitti.Models
         {
             gifImage = originalGif.Clone() as Image;
         }
+        #endregion
 
+        #region Saving
         /// <summary>
         /// Takes the full path of a GIF save location, 
         /// extension included
@@ -81,10 +114,6 @@ namespace Gifitti.Models
         /// <param name="path">String representation of path to save the gif to. 
         ///     Name and extension of gif mandatory.
         /// </param>
-        /// <exception cref="DirectoryNotFoundException">
-        /// Thrown if the path is not valid for the local system,
-        /// OR the file has an extension other than [G|g][I|i][F|f]
-        /// </exception>
         public void saveGif(string path)
         {
             //Error Handel on path
@@ -92,12 +121,9 @@ namespace Gifitti.Models
             Regex extensionTester = new Regex(@"^.*\.[g|G][i|I][f|F]$");
             //RE for path without extension
             Regex savePathTester = new Regex(@"^((?:(?:[^\/\\]+)*[\/\\]*)*)[\/\\]([^\/\\]*)$");
-            //if (!savePathTester.IsMatch(path) || !Directory.Exists(savePathTester.Match(path).Groups[1].ToString()))
-            //    throw new DirectoryNotFoundException();
-            //Handel non gif extensions
+
             if (!extensionTester.IsMatch(path))
                 path += ".gif"; 
-            //TODO take in image setting components as well as frames being viewed etc.
             //Build GIF
             using (MagickImageCollection collection = new MagickImageCollection())
             {
@@ -120,8 +146,20 @@ namespace Gifitti.Models
             }
         }
 
+        /// <summary>
+        /// Sets frame "index" in the GIF to "frame"
+        /// </summary>
+        /// <param name="frame">Image to replace index</param>
+        /// <param name="index">Frame number from [0, number of frames - 1]</param>
+        public void SetFrameFromImage(Image frame, int index)
+        {
+            if (index < 0 || index >= numberOfFrames)
+                throw new IndexOutOfRangeException();
+            frames[index] = frame;
+        }
+        #endregion
 
-
+        #region Sub GIF Handling
         /// <summary>
         /// Fetches a sub gif over frames start -> stop
         /// </summary>
@@ -149,26 +187,16 @@ namespace Gifitti.Models
                 collection.Write("temp.gif");
             }
         }
+        #endregion
 
-
-        /// <summary>
-        /// Whether the gif should play backwards when it reaches the end
-        /// </summary>
-        public bool ReverseAtEnd
-        {
-            get { return reverse; }
-            set { reverse = value; }
-        }
-
+        #region Fetch frames
         /// <summary>
         /// Fetches the GIFs next viewable frame
         /// </summary>
         /// <returns>Next frame to be returned to the control.</returns>
         public Image GetNextFrame()
         {
-
             currentFrame += step;
-
             //if the animation reaches a boundary...
             if (currentFrame >= numberOfFrames || currentFrame < 1 || currentFrame >= endFrame)
             {
@@ -182,7 +210,6 @@ namespace Gifitti.Models
                 else
                 {
                     currentFrame = startFrame;
-                    //...or start over
                 }
             }
             return GetFrame(currentFrame);
@@ -192,25 +219,19 @@ namespace Gifitti.Models
         /// Gets the frame index.
         /// </summary>
         /// <param name="index">Frame number to fetch</param>
+        /// <param name="isResize">Flag if the function is resizing</param>
         /// <returns>Frame number index in the model</returns>
         public Image GetFrame(int index, bool isResize = false)
         {
+            //Find Frame
             originalGif.SelectActiveFrame(dimension, index);
-            //find the frame
-            if(isResize)
+            //return a copy of it
+            if (isResize)
                 return (Image)originalGif.Clone();
+            //Return reference to it
             return originalGif;
-            //return a copy of it
-        }
-
-        public void SetFrameFromImage(Image frame, int index)
-        {
-            frames[index] = frame;
         }
+        #endregion
 
-        public void Dispose()
-        {
-            this.frames = null;
-        }
     }
 }
diff --git a/src/Gifitti/Gifitti/Program.cs b/src/Gifitti/Gifitti/Program.cs
index da7c796..a2b843d 100644
--- a/src/Gifitti/Gifitti/Program.cs
+++ b/src/Gifitti/Gifitti/Program.cs
@@ -1,7 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
 using System.Windows.Forms;
 using Gifitti.View_Models;
 
diff --git a/src/Gifitti/Gifitti/Properties/AssemblyInfo.cs b/src/Gifitti/Gifitti/Properties/AssemblyInfo.cs
index 8208d4e..5f52a7f 100644
--- a/src/Gifitti/Gifitti/Properties/AssemblyInfo.cs
+++ b/src/Gifitti/Gifitti/Properties/AssemblyInfo.cs
@@ -6,12 +6,12 @@ using System.Runtime.InteropServices;
 // set of attributes. Change these attribute values to modify the information
 // associated with an assembly.
 [assembly: AssemblyTitle("Gifitti")]
-[assembly: AssemblyDescription("")]
+[assembly: AssemblyDescription("GIF loading and modification solution. Authors: Pavle Arezina, Nicolai Kozel, Riley McGee")]
 [assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
+[assembly: AssemblyCompany("McMaster University")]
 [assembly: AssemblyProduct("Gifitti")]
 [assembly: AssemblyCopyright("Copyright ©  2016")]
-[assembly: AssemblyTrademark("")]
+[assembly: AssemblyTrademark("None")]
 [assembly: AssemblyCulture("")]
 
 // Setting ComVisible to false makes the types in this assembly not visible 
diff --git a/src/Gifitti/Gifitti/Transformation/TransformGif.cs b/src/Gifitti/Gifitti/Transformation/TransformGif.cs
index 8ca4566..a17363c 100644
--- a/src/Gifitti/Gifitti/Transformation/TransformGif.cs
+++ b/src/Gifitti/Gifitti/Transformation/TransformGif.cs
@@ -1,11 +1,6 @@
 using Gifitti.Models;
 using ImageMagick;
-using System;
-using System.Collections.Generic;
 using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Gifitti.Transformation
 {
@@ -32,7 +27,13 @@ namespace Gifitti.Transformation
                 }
             }
         }
-        public static void saveThePlayback(GifModel gm, int delay)
+
+        /// <summary>
+        /// Hiden function, for future development of delay requests by users.
+        /// </summary>
+        /// <param name="gm">System loaded GifModel</param>
+        /// <param name="delay">ms Delay between frames</param>
+        internal static void saveThePlayback(GifModel gm, int delay)
         {
             using (MagickImageCollection collection = new MagickImageCollection())
             {
diff --git a/src/Gifitti/Gifitti/View_Models/HelpContext.cs b/src/Gifitti/Gifitti/View_Models/HelpContext.cs
index 900c492..6329f44 100644
--- a/src/Gifitti/Gifitti/View_Models/HelpContext.cs
+++ b/src/Gifitti/Gifitti/View_Models/HelpContext.cs
@@ -1,12 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
+using System.Windows.Forms;
 
 namespace Gifitti.View_Models
 {
@@ -63,11 +55,21 @@ namespace Gifitti.View_Models
             richTextBox1.Text = "To select the range of frames, simply use the boxes in the bottom center of the window to adjust which frames are displayed and saved. If the range is out of bounds, the GIF may appear choppy or simply stop.";
         }
 
+        /// <summary>
+        /// Display playback speed information.
+        /// </summary>
+        /// <param name="sender">Caller object.</param>
+        /// <param name="e">Event arguments associated with the click event.</param>
         private void playbackSpeed_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
         {
             richTextBox1.Text = "To change the playback speed, simply slide the playback speed track bar left or right. Left slows down the GIF, and right speeds up the GIF.";
         }
 
+        /// <summary>
+        /// Display resize GIF information.
+        /// </summary>
+        /// <param name="sender">Caller object.</param>
+        /// <param name="e">Event arguments associated with the click event.</param>
         private void resize_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
         {
             richTextBox1.Text = "To resize and export the GIF, click File->Resize. A dialog window will appear prompting you for a new width and height. Enter the desired sizes and click save to save the GIF as normal.";
diff --git a/src/Gifitti/Gifitti/View_Models/MainForm.Designer.cs b/src/Gifitti/Gifitti/View_Models/MainForm.Designer.cs
index 1d8accd..9b1e8cb 100644
--- a/src/Gifitti/Gifitti/View_Models/MainForm.Designer.cs
+++ b/src/Gifitti/Gifitti/View_Models/MainForm.Designer.cs
@@ -62,14 +62,12 @@ namespace Gifitti.View_Models
             // openGifFileDialog
             // 
             this.openGifFileDialog.FileName = "openGifFileDialog";
-            this.openGifFileDialog.FileOk += new System.ComponentModel.CancelEventHandler(this.openGifDialog_FileOk);
             // 
             // gifView
             // 
-            this.gifView.Location = new System.Drawing.Point(9, 10);
-            this.gifView.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+            this.gifView.Location = new System.Drawing.Point(14, 15);
             this.gifView.Name = "gifView";
-            this.gifView.Size = new System.Drawing.Size(456, 382);
+            this.gifView.Size = new System.Drawing.Size(684, 588);
             this.gifView.TabIndex = 2;
             this.gifView.TabStop = false;
             // 
@@ -151,10 +149,9 @@ namespace Gifitti.View_Models
             // 
             this.textBox1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
             this.textBox1.Enabled = false;
-            this.textBox1.Location = new System.Drawing.Point(214, 448);
-            this.textBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+            this.textBox1.Location = new System.Drawing.Point(321, 689);
             this.textBox1.Name = "textBox1";
-            this.textBox1.Size = new System.Drawing.Size(23, 20);
+            this.textBox1.Size = new System.Drawing.Size(32, 26);
             this.textBox1.TabIndex = 3;
             this.textBox1.TextChanged += new System.EventHandler(this.StartFrameTextChanged);
             // 
@@ -162,10 +159,9 @@ namespace Gifitti.View_Models
             // 
             this.textBox2.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
             this.textBox2.Enabled = false;
-            this.textBox2.Location = new System.Drawing.Point(240, 448);
-            this.textBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+            this.textBox2.Location = new System.Drawing.Point(360, 689);
             this.textBox2.Name = "textBox2";
-            this.textBox2.Size = new System.Drawing.Size(23, 20);
+            this.textBox2.Size = new System.Drawing.Size(32, 26);
             this.textBox2.TabIndex = 4;
             this.textBox2.TextChanged += new System.EventHandler(this.StopFrameTextChanged);
             // 
@@ -173,10 +169,9 @@ namespace Gifitti.View_Models
             // 
             this.button3.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
             this.button3.Enabled = false;
-            this.button3.Location = new System.Drawing.Point(266, 445);
-            this.button3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+            this.button3.Location = new System.Drawing.Point(399, 685);
             this.button3.Name = "button3";
-            this.button3.Size = new System.Drawing.Size(50, 24);
+            this.button3.Size = new System.Drawing.Size(75, 37);
             this.button3.TabIndex = 5;
             this.button3.Text = "Stop";
             this.button3.UseVisualStyleBackColor = true;
@@ -186,10 +181,9 @@ namespace Gifitti.View_Models
             // 
             this.label1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
             this.label1.AutoSize = true;
-            this.label1.Location = new System.Drawing.Point(212, 432);
-            this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+            this.label1.Location = new System.Drawing.Point(318, 665);
             this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(29, 13);
+            this.label1.Size = new System.Drawing.Size(44, 20);
             this.label1.TabIndex = 6;
             this.label1.Text = "Start";
             // 
@@ -197,10 +191,9 @@ namespace Gifitti.View_Models
             // 
             this.label2.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
             this.label2.AutoSize = true;
-            this.label2.Location = new System.Drawing.Point(239, 432);
-            this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+            this.label2.Location = new System.Drawing.Point(358, 665);
             this.label2.Name = "label2";
-            this.label2.Size = new System.Drawing.Size(26, 13);
+            this.label2.Size = new System.Drawing.Size(38, 20);
             this.label2.TabIndex = 7;
             this.label2.Text = "End";
             // 
@@ -208,10 +201,9 @@ namespace Gifitti.View_Models
             // 
             this.label3.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
             this.label3.AutoSize = true;
-            this.label3.Location = new System.Drawing.Point(160, 443);
-            this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+            this.label3.Location = new System.Drawing.Point(240, 682);
             this.label3.Name = "label3";
-            this.label3.Size = new System.Drawing.Size(51, 26);
+            this.label3.Size = new System.Drawing.Size(75, 40);
             this.label3.TabIndex = 8;
             this.label3.Text = "Frame \r\nSelection";
             // 
@@ -223,23 +215,20 @@ namespace Gifitti.View_Models
             // trackBar1
             // 
             this.trackBar1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
-            this.trackBar1.Location = new System.Drawing.Point(328, 448);
-            this.trackBar1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+            this.trackBar1.Location = new System.Drawing.Point(492, 689);
             this.trackBar1.Name = "trackBar1";
-            this.trackBar1.Size = new System.Drawing.Size(137, 45);
+            this.trackBar1.Size = new System.Drawing.Size(206, 69);
             this.trackBar1.TabIndex = 9;
             this.trackBar1.Value = 10;
-            this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
             this.trackBar1.ValueChanged += new System.EventHandler(this.GifFPSSliderUpdate);
             // 
             // label4
             // 
             this.label4.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
             this.label4.AutoSize = true;
-            this.label4.Location = new System.Drawing.Point(354, 432);
-            this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+            this.label4.Location = new System.Drawing.Point(531, 665);
             this.label4.Name = "label4";
-            this.label4.Size = new System.Drawing.Size(85, 13);
+            this.label4.Size = new System.Drawing.Size(123, 20);
             this.label4.TabIndex = 10;
             this.label4.Text = "Playback Speed";
             // 
@@ -249,18 +238,17 @@ namespace Gifitti.View_Models
             this.label6.AutoSize = true;
             this.label6.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F);
-            this.label6.Location = new System.Drawing.Point(65, 442);
-            this.label6.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+            this.label6.Location = new System.Drawing.Point(98, 680);
             this.label6.Name = "label6";
-            this.label6.Size = new System.Drawing.Size(72, 24);
+            this.label6.Size = new System.Drawing.Size(109, 32);
             this.label6.TabIndex = 12;
             this.label6.Text = "GIFITTI";
             // 
             // MainForm
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(474, 469);
+            this.ClientSize = new System.Drawing.Size(711, 722);
             this.Controls.Add(this.label6);
             this.Controls.Add(this.label4);
             this.Controls.Add(this.trackBar1);
@@ -271,13 +259,11 @@ namespace Gifitti.View_Models
             this.Controls.Add(this.textBox2);
             this.Controls.Add(this.textBox1);
             this.Controls.Add(this.gifView);
-            this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.MaximizeBox = false;
             this.Menu = this.mainMenu1;
             this.Name = "MainForm";
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "Gifitti";
-            this.Load += new System.EventHandler(this.Form1_Load);
             ((System.ComponentModel.ISupportInitialize)(this.gifView)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
             this.ResumeLayout(false);
diff --git a/src/Gifitti/Gifitti/View_Models/MainForm.cs b/src/Gifitti/Gifitti/View_Models/MainForm.cs
index 4c54ab1..684ff2f 100644
--- a/src/Gifitti/Gifitti/View_Models/MainForm.cs
+++ b/src/Gifitti/Gifitti/View_Models/MainForm.cs
@@ -1,18 +1,11 @@
-using System;
+using Gifitti.Models;
+using System;
 using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
 using System.Drawing;
 using System.Drawing.Imaging;
 using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using Gifitti.Models;
 using System.Threading;
-using Gifitti.Transformation;
-using ImageMagick;
+using System.Windows.Forms;
 
 namespace Gifitti.View_Models
 {
@@ -24,13 +17,21 @@ namespace Gifitti.View_Models
     public partial class MainForm : Form
     {
         #region Fields
-        GifModel gm;
-        HelpContext f2 = new HelpContext();
-        // GifImage _currentGif; <- used to encapsulate info later 
+        private GifModel gm;
+        private HelpContext f2 = new HelpContext();
         private const int widthBuffer = 20;
         private const int heightBuffer = 60;
-        Image globalGif;
+        private Image globalGif;
+
+        private static Dictionary<ImageFormat, string> IMAGE_TO_EXTENSION = new Dictionary<ImageFormat, string>()
+        {
+            {ImageFormat.Bmp,   "bmp"   },
+            {ImageFormat.Tiff,  "tiff"  },
+            {ImageFormat.Jpeg,  "jpeg"  },
+            {ImageFormat.Png,   "png"   }
+        };
         #endregion
+        
         #region Constructors
         /// <summary>
         /// Returns a new MainForm instance, and initializes the view.
@@ -39,15 +40,32 @@ namespace Gifitti.View_Models
         {
             InitializeComponent();
         }
+        #endregion
 
-        private void Form1_Load(object sender, EventArgs e)
+        #region Buttons
+        /// <summary>
+        /// Controls the start stop behaviour. Execution of this command
+        /// toggles if the GIF is playing or paused.
+        /// </summary>
+        /// <param name="sender"> Caller of the event. </param>
+        /// <param name="e"> Event arguments associated with this event. </param>
+        private void StartStopClickEvent(object sender, EventArgs e)
         {
-
+            if (timer1.Enabled == true)
+            {
+                button3.Text = "Start";
+                gifView.Enabled = false;
+                timer1.Enabled = false;
+            }
+            else
+            {
+                button3.Text = "Stop";
+                gifView.Enabled = true;
+                timer1.Enabled = true;
+            }
         }
         #endregion
-        #region Buttons
-        
-        #endregion
+
         #region SystemChecks
         /// <summary>
         /// Validates that a GIF is loaded and in the model instance. 
@@ -68,7 +86,8 @@ namespace Gifitti.View_Models
             return false;
         }
         #endregion
-        #region MenuItems
+        
+        #region Frame Saving
 
         /// <summary>
         /// On event invocation the loaded gif is decomposed into its frames and saved to a specified folder as JPEG images.
@@ -90,14 +109,6 @@ namespace Gifitti.View_Models
             exportFrames(ImageFormat.Png);
         }
 
-        private static Dictionary<ImageFormat, string> IMAGE_TO_EXTENSION = new Dictionary<ImageFormat, string>()
-        {
-            {ImageFormat.Bmp,   "bmp"   },
-            {ImageFormat.Tiff,  "tiff"  },
-            {ImageFormat.Jpeg,  "jpeg"  },
-            {ImageFormat.Png,   "png"   }
-        };
-
         /// <summary>
         /// On event invocation the loaded gif is decomposed into its frames and saved to a specified folder as BMP (Bitmap) images.
         /// </summary>
@@ -108,8 +119,21 @@ namespace Gifitti.View_Models
             exportFrames(ImageFormat.Bmp);
         }
 
-    
-        public void exportFrames(ImageFormat format)
+        /// <summary>
+        /// On event invocation the loaded gif is decomposed into its frames and saved to a specified folder as TIFF images.
+        /// </summary>
+        /// <param name="sender"> Caller of the event. </param>
+        /// <param name="e"> Event arguments associated with this event. </param>
+        private void MenuItemExportTIFF(object sender, EventArgs e)
+        {
+            exportFrames(ImageFormat.Tiff);
+        }
+
+        /// <summary>
+        /// Exports all frames frome the GIF being represented as type "format".
+        /// </summary>
+        /// <param name="format">Image type being exported.</param>
+        private void exportFrames(ImageFormat format)
         {
             if (!chkImage())
                 return;
@@ -126,48 +150,31 @@ namespace Gifitti.View_Models
             }
         }
 
-        /// <summary>
-        /// On event invocation the loaded gif is decomposed into its frames and saved to a specified folder as TIFF images.
-        /// </summary>
-        /// <param name="sender"> Caller of the event. </param>
-        /// <param name="e"> Event arguments associated with this event. </param>
-        private void MenuItemExportTIFF(object sender, EventArgs e)
-        {
-            exportFrames(ImageFormat.Tiff);
-        }
+        #endregion
 
+        #region Frame Attribute Handler
         /// <summary>
-        /// Controls the start stop behaviour. Execution of this command
-        /// toggles if the GIF is playing or paused.
+        /// GIF playback controller
         /// </summary>
         /// <param name="sender"> Caller of the event. </param>
         /// <param name="e"> Event arguments associated with this event. </param>
-        private void StartStopClickEvent(object sender, EventArgs e)
+        private void AdvanceFrameTimer(object sender, EventArgs e)
         {
-            if (timer1.Enabled == true)
-            {
-                button3.Text = "Start";
-                gifView.Enabled = false;
-                timer1.Enabled = false;
-            }
-            else
-            {
-                button3.Text = "Stop";
-                gifView.Enabled = true;
-                timer1.Enabled = true;
-            }
+            //get next frame
+            Thread.Sleep(gm.delay);
+            gifView.Image = gm.GetNextFrame();
         }
 
         /// <summary>
-        /// GIF playback controller
+        /// Static Binding to the GIF Frame rate slider, slecting current frame rate.
+        /// Delay ranges from 0-100ms
         /// </summary>
         /// <param name="sender"> Caller of the event. </param>
         /// <param name="e"> Event arguments associated with this event. </param>
-        private void AdvanceFrameTimer(object sender, EventArgs e)
+        private void GifFPSSliderUpdate(object sender, EventArgs e)
         {
-            //get next frame
-            Thread.Sleep(gm.delay);
-            gifView.Image = gm.GetNextFrame();
+            if (gm != null)
+                gm.delay = (11 - trackBar1.Value) * gm.originalDelay;
         }
 
         /// <summary>
@@ -200,7 +207,9 @@ namespace Gifitti.View_Models
             }
 
         }
+        #endregion
 
+        #region Open Sub Forms
         /// <summary>
         /// Event controlling the Save File Dialog.
         /// </summary>
@@ -220,27 +229,16 @@ namespace Gifitti.View_Models
                 return;
             //TODO temp write
             Console.WriteLine(path);
-            try {
+            try
+            {
                 gm.saveGif(path);
-            } catch (DirectoryNotFoundException)
+            }
+            catch (DirectoryNotFoundException)
             {
                 MessageBox.Show("Save Path Invalid!");
             }
-            
-        }
-
-        #endregion
-        #region File Dialogs
-        /// <summary>
-        /// Statically binded function executed when openGifDialog has its button "Ok" clicked.
-        /// </summary>
-        /// <param name="sender"> Caller of the event. </param>
-        /// <param name="e"> Event arguments associated with this event. </param>
-        private void openGifDialog_FileOk(object sender, CancelEventArgs e)
-        {
 
         }
-        #endregion
 
         /// <summary>
         /// Launches a file dialog to load a GIF. Users can only select valid files.
@@ -310,39 +308,27 @@ namespace Gifitti.View_Models
         /// <param name="e"> Event arguments associated with this event. </param>
         private void menuOpenHelp(object sender, EventArgs e)
         {
-            if(f2.IsDisposed)
+            if (f2.IsDisposed)
                 f2 = new HelpContext();
             if (!f2.Visible)
                 f2.Show();
         }
 
         /// <summary>
-        /// Static Binding to the GIF Frame rate slider, slecting current frame rate.
-        /// Delay ranges from 0-100ms
+        /// Click event for selecting the menue item to resize a gif
         /// </summary>
         /// <param name="sender"> Caller of the event. </param>
         /// <param name="e"> Event arguments associated with this event. </param>
-        private void GifFPSSliderUpdate(object sender, EventArgs e)
-        {
-            if (gm != null)
-                gm.delay = (11-trackBar1.Value)*gm.originalDelay;
-        }
-
         private void MenuItemResize(object sender, EventArgs e)
         {
-            if (chkImage()) {
+            if (chkImage())
+            {
                 int height = gifView.Height;
                 int width = gifView.Width;
-                SaveAsXbyYPrompt save = new SaveAsXbyYPrompt(width,height,gm);
+                SaveAsXbyYPrompt save = new SaveAsXbyYPrompt(width, height, gm);
                 save.Show();
             }
         }
-
-        private void trackBar1_Scroll(object sender, EventArgs e)
-        {
-
-        }
-
-        
+        #endregion
     }
 }
diff --git a/src/Gifitti/Gifitti/View_Models/SaveAsXbyYPrompt.cs b/src/Gifitti/Gifitti/View_Models/SaveAsXbyYPrompt.cs
index f159d7f..d469713 100644
--- a/src/Gifitti/Gifitti/View_Models/SaveAsXbyYPrompt.cs
+++ b/src/Gifitti/Gifitti/View_Models/SaveAsXbyYPrompt.cs
@@ -1,26 +1,29 @@
 using Gifitti.Models;
 using Gifitti.Transformation;
 using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
 using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows.Forms;
 
 namespace Gifitti.View_Models
 {
+    /// <summary>
+    /// VM for View SaveAsXbyYPrompt
+    /// </summary>
     public partial class SaveAsXbyYPrompt : Form
     {
-        GifModel gm;
-        int orignalWidth = 0;
-        int originalHeight = 0;
-        int width = 0;
-        int height = 0;
+        private GifModel gm;
+        private int orignalWidth = 0;
+        private int originalHeight = 0;
+        private int width = 0;
+        private int height = 0;
 
+        /// <summary>
+        /// Creates a new formto andle saving gifs to a new size.
+        /// Aspect ratio is held using the smallest of the dimensions then scaling via aspect.
+        /// </summary>
+        /// <param name="width">Desired width in pixels</param>
+        /// <param name="height">Desired height in pixels</param>
+        /// <param name="gm">Gifmodel holding GIF desired to be modified</param>
         public SaveAsXbyYPrompt(int width, int height, GifModel gm)
         {
             InitializeComponent();
@@ -30,9 +33,14 @@ namespace Gifitti.View_Models
             this.height = originalHeight;
             WidthTextBox.Text = this.width.ToString();
             HeightTextBox.Text = this.height.ToString();
-            this.gm = gm; //make this a clone 
+            this.gm = gm;  
         }
 
+        /// <summary>
+        /// Handler for when the user selects to save the GIF to input specifications
+        /// </summary>
+        /// <param name="sender">Caller object.</param>
+        /// <param name="e">Event args associated with the function call, handled by .Net</param>
         private void SaveAsButtonClick(object sender, EventArgs e)
         {
             TransformGif.resizeGif(gm, width, height);
@@ -44,8 +52,7 @@ namespace Gifitti.View_Models
             //Handel Close
             if (path == null)
                 return;
-            //TODO temp write
-            Console.WriteLine(path);
+
             try
             {
                 TransformGif.resizeGif(gm, width, height);
@@ -60,6 +67,11 @@ namespace Gifitti.View_Models
             this.Close();
         }
 
+        /// <summary>
+        /// Validation and verification on the width text box in the form
+        /// </summary>
+        /// <param name="sender">Caller object.</param>
+        /// <param name="e">Event args associated with the function call, handled by .Net</param>
         private void widthChanged(object sender, EventArgs e)
         {
             int w = 0;
@@ -68,13 +80,16 @@ namespace Gifitti.View_Models
             }
         }
 
+        /// <summary>
+        /// Validation and verification on the height text box in the form
+        /// </summary>
+        /// <param name="sender">Caller object.</param>
+        /// <param name="e">Event args associated with the function call, handled by .Net</param>
         private void heightChanged(object sender, EventArgs e)
         {
             int h = 0;
             if (int.TryParse(HeightTextBox.Text,out h) & h >= 0)
-            {
                 height = h;
-            }
         }
     }
 }
diff --git a/src/Gifitti/GifittiUnitTest/Helper/UnitTestHelper.cs b/src/Gifitti/GifittiUnitTest/Helper/UnitTestHelper.cs
index a7733c9..940ba90 100644
--- a/src/Gifitti/GifittiUnitTest/Helper/UnitTestHelper.cs
+++ b/src/Gifitti/GifittiUnitTest/Helper/UnitTestHelper.cs
@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Drawing;
 
 namespace GifittiUnitTest.Helper
 {
diff --git a/src/Gifitti/GifittiUnitTest/SubGif/SubGifUnitTest.cs b/src/Gifitti/GifittiUnitTest/SubGif/SubGifUnitTest.cs
index 8fbc97e..9d8587b 100644
--- a/src/Gifitti/GifittiUnitTest/SubGif/SubGifUnitTest.cs
+++ b/src/Gifitti/GifittiUnitTest/SubGif/SubGifUnitTest.cs
@@ -1,9 +1,9 @@
-using System;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Gifitti.Models;
+using Gifitti.Models;
 using GifittiUnitTest.Helper;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 namespace GifittiUnitTest.SubGif
-{ 
+{
 
     [TestClass]
     public class SubGifUnitTest
-- 
GitLab