From 12648346216711ed4479b1d2f19835d464f69e2c Mon Sep 17 00:00:00 2001
From: Riley McGee <mcgeer@mcmaster.ca>
Date: Tue, 15 Nov 2016 15:11:24 -0500
Subject: [PATCH] Prepared For merge closes #13

---
 .../Gifitti/View_Models/Form1.Designer.cs     | 86 +++++++++++--------
 src/Gifitti/Gifitti/View_Models/Form1.cs      | 76 ++++++++++++----
 src/Gifitti/Gifitti/View_Models/Form1.resx    | 11 ++-
 3 files changed, 112 insertions(+), 61 deletions(-)

diff --git a/src/Gifitti/Gifitti/View_Models/Form1.Designer.cs b/src/Gifitti/Gifitti/View_Models/Form1.Designer.cs
index 9955817..f2cf8fd 100644
--- a/src/Gifitti/Gifitti/View_Models/Form1.Designer.cs
+++ b/src/Gifitti/Gifitti/View_Models/Form1.Designer.cs
@@ -31,13 +31,13 @@
             this.components = new System.ComponentModel.Container();
             this.button1 = new System.Windows.Forms.Button();
             this.button2 = new System.Windows.Forms.Button();
-            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
-            this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
+            this.openGifFileDialog = new System.Windows.Forms.OpenFileDialog();
+            this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
             this.gifView = new System.Windows.Forms.PictureBox();
 
             this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
-            this.menuItem1 = new System.Windows.Forms.MenuItem();
-            this.menuItem2 = new System.Windows.Forms.MenuItem();
+            this.meneFile = new System.Windows.Forms.MenuItem();
+            this.menuFileExportAs = new System.Windows.Forms.MenuItem();
             this.JPEG = new System.Windows.Forms.MenuItem();
             this.PNG = new System.Windows.Forms.MenuItem();
             this.BMP = new System.Windows.Forms.MenuItem();
@@ -51,16 +51,17 @@
             this.label3 = new System.Windows.Forms.Label();
             this.timer1 = new System.Windows.Forms.Timer(this.components);
 
+            this.menuFileSaveAs = new System.Windows.Forms.MenuItem();
+            this.saveGifFileDialog = new System.Windows.Forms.SaveFileDialog();
             ((System.ComponentModel.ISupportInitialize)(this.gifView)).BeginInit();
             this.SuspendLayout();
             // 
             // button1
             // 
             this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
-            this.button1.Location = new System.Drawing.Point(9, 411);
-            this.button1.Margin = new System.Windows.Forms.Padding(2);
+            this.button1.Location = new System.Drawing.Point(14, 632);
             this.button1.Name = "button1";
-            this.button1.Size = new System.Drawing.Size(104, 28);
+            this.button1.Size = new System.Drawing.Size(156, 43);
             this.button1.TabIndex = 0;
             this.button1.Text = "Open GIF";
             this.button1.UseVisualStyleBackColor = true;
@@ -69,25 +70,24 @@
             // button2
             // 
             this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
-            this.button2.Location = new System.Drawing.Point(323, 411);
-            this.button2.Margin = new System.Windows.Forms.Padding(2);
+            this.button2.Location = new System.Drawing.Point(484, 632);
             this.button2.Name = "button2";
-            this.button2.Size = new System.Drawing.Size(104, 28);
+            this.button2.Size = new System.Drawing.Size(156, 43);
             this.button2.TabIndex = 1;
             this.button2.Text = "Save GIF";
             this.button2.UseVisualStyleBackColor = true;
             this.button2.Click += new System.EventHandler(this.button2_Click);
             // 
-            // openFileDialog1
+            // openGifFileDialog
             // 
-            this.openFileDialog1.FileName = "openFileDialog1";
+            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);
+            this.gifView.Location = new System.Drawing.Point(14, 15);
             this.gifView.Name = "gifView";
-            this.gifView.Size = new System.Drawing.Size(418, 396);
+            this.gifView.Size = new System.Drawing.Size(627, 609);
             this.gifView.TabIndex = 2;
             this.gifView.TabStop = false;
             // 
@@ -95,48 +95,49 @@
             // mainMenu1
             // 
             this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
-            this.menuItem1});
+            this.meneFile});
             // 
-            // menuItem1
+            // meneFile
             // 
-            this.menuItem1.Index = 0;
-            this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
-            this.menuItem2});
-            this.menuItem1.Text = "File";
+            this.meneFile.Index = 0;
+            this.meneFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
+            this.menuFileExportAs,
+            this.menuFileSaveAs});
+            this.meneFile.Text = "File";
             // 
-            // menuItem2
+            // menuFileExportAs
             // 
-            this.menuItem2.Index = 0;
-            this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
+            this.menuFileExportAs.Index = 0;
+            this.menuFileExportAs.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
             this.JPEG,
             this.PNG,
             this.BMP,
             this.TIFF});
-            this.menuItem2.Text = "Output As Image";
+            this.menuFileExportAs.Text = "Output As Image";
             // 
             // JPEG
             // 
             this.JPEG.Index = 0;
             this.JPEG.Text = "JPEG";
-            this.JPEG.Click += new System.EventHandler(this.menuItem3_Click);
+            this.JPEG.Click += new System.EventHandler(this.MenuItemExportJPEG);
             // 
             // PNG
             // 
             this.PNG.Index = 1;
             this.PNG.Text = "PNG";
-            this.PNG.Click += new System.EventHandler(this.menuItem4_Click);
+            this.PNG.Click += new System.EventHandler(this.MenuItemExportPNG);
             // 
             // BMP
             // 
             this.BMP.Index = 2;
             this.BMP.Text = "BMP";
-            this.BMP.Click += new System.EventHandler(this.menuItem5_Click);
+            this.BMP.Click += new System.EventHandler(this.MenuItemExportBMP);
             // 
             // TIFF
             // 
             this.TIFF.Index = 3;
             this.TIFF.Text = "TIFF";
-            this.TIFF.Click += new System.EventHandler(this.menuItem6_Click);
+            this.TIFF.Click += new System.EventHandler(this.MenuItemExportTIFF);
 
             // textBox1
             // 
@@ -205,15 +206,19 @@
             this.timer1.Interval = 20;
             this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
 
+            this.TIFF.Click += new System.EventHandler(this.MenuItemExportTIFF);
+            // 
+            // menuFileSaveAs
+            // 
+            this.menuFileSaveAs.Index = 1;
+            this.menuFileSaveAs.Text = "Save as...";
+            this.menuFileSaveAs.Click += new System.EventHandler(this.MenuItemFileSaveAs);
             // 
             // Form1
             // 
-            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(436, 449);
-
-            this.ClientSize = new System.Drawing.Size(582, 553);
             this.Controls.Add(this.label3);
             this.Controls.Add(this.label2);
             this.Controls.Add(this.label1);
@@ -221,10 +226,11 @@
             this.Controls.Add(this.textBox2);
             this.Controls.Add(this.textBox1);
 
+            this.ClientSize = new System.Drawing.Size(654, 691);
+
             this.Controls.Add(this.gifView);
             this.Controls.Add(this.button2);
             this.Controls.Add(this.button1);
-            this.Margin = new System.Windows.Forms.Padding(2);
             this.Menu = this.mainMenu1;
             this.Name = "Form1";
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
@@ -240,13 +246,13 @@
 
         private System.Windows.Forms.Button button1;
         private System.Windows.Forms.Button button2;
-        private System.Windows.Forms.OpenFileDialog openFileDialog1;
-        private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
+        private System.Windows.Forms.OpenFileDialog openGifFileDialog;
+        private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
         private System.Windows.Forms.PictureBox gifView;
 
         private System.Windows.Forms.MainMenu mainMenu1;
-        private System.Windows.Forms.MenuItem menuItem1;
-        private System.Windows.Forms.MenuItem menuItem2;
+        private System.Windows.Forms.MenuItem meneFile;
+        private System.Windows.Forms.MenuItem menuFileExportAs;
         private System.Windows.Forms.MenuItem JPEG;
         private System.Windows.Forms.MenuItem PNG;
         private System.Windows.Forms.MenuItem BMP;
@@ -259,6 +265,10 @@
         private System.Windows.Forms.Label label2;
         private System.Windows.Forms.Label label3;
         private System.Windows.Forms.Timer timer1;
+
+        private System.Windows.Forms.MenuItem menuFileSaveAs;
+        private System.Windows.Forms.SaveFileDialog saveGifFileDialog;
+
     }
 }
 
diff --git a/src/Gifitti/Gifitti/View_Models/Form1.cs b/src/Gifitti/Gifitti/View_Models/Form1.cs
index bce43cd..6e34e52 100644
--- a/src/Gifitti/Gifitti/View_Models/Form1.cs
+++ b/src/Gifitti/Gifitti/View_Models/Form1.cs
@@ -15,13 +15,15 @@ namespace Gifitti.View_Models
 {
     public partial class Form1 : Form
     {
+        #region Fields
         GifModel gm;
 
         // GifImage _currentGif; <- used to encapsulate info later 
         private const int widthBuffer = 20;
         private const int heightBuffer = 60;
         Image globalGif;
-
+        #endregion
+        #region Constructors
         public Form1()
         {
             InitializeComponent();
@@ -31,14 +33,15 @@ namespace Gifitti.View_Models
         {
 
         }
-
+        #endregion
+        #region Buttons
         private void button1_Click(object sender, EventArgs e)
         {
-            openFileDialog1.Filter = "GIF Files|*.gif";
-            DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
+            openGifFileDialog.Filter = "GIF Files|*.gif";
+            DialogResult result = openGifFileDialog.ShowDialog(); // Show the dialog.
             if (result == DialogResult.OK) // Test result.
             {
-                string file = openFileDialog1.FileName;
+                string file = openGifFileDialog.FileName;
                 try
                 {
                     gm = new GifModel(file);
@@ -80,9 +83,9 @@ namespace Gifitti.View_Models
         private void button2_Click(object sender, EventArgs e)
         {
             String x = "";
-            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
+            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
             {
-                x = folderBrowserDialog1.SelectedPath;
+                x = folderBrowserDialog.SelectedPath;
             }
 
             List<Image> IMGs = new List<Image>();
@@ -100,6 +103,8 @@ namespace Gifitti.View_Models
             }
         }
 
+        #endregion
+        #region SystemChecks
         private Boolean chkImage()
         {
             Boolean check = true;
@@ -115,14 +120,17 @@ namespace Gifitti.View_Models
 
             return (check);
         }
-        private void menuItem3_Click(object sender, EventArgs e)
+        #endregion
+        #region MenuItems
+
+        private void MenuItemExportJPEG(object sender, EventArgs e)
         {
             if(chkImage())
             {
                 String x = "";
-                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
+                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                 {
-                    x = folderBrowserDialog1.SelectedPath;
+                    x = folderBrowserDialog.SelectedPath;
                 }
                 
                 List<Image> IMGs = new List<Image>();
@@ -143,14 +151,14 @@ namespace Gifitti.View_Models
            
         }
 
-        private void menuItem4_Click(object sender, EventArgs e)
+        private void MenuItemExportPNG(object sender, EventArgs e)
         {
             if (chkImage())
             {
                 String x = "";
-                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
+                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                 {
-                    x = folderBrowserDialog1.SelectedPath;
+                    x = folderBrowserDialog.SelectedPath;
                 }
 
                 List<Image> IMGs = new List<Image>();
@@ -170,14 +178,14 @@ namespace Gifitti.View_Models
             }
         }
 
-        private void menuItem5_Click(object sender, EventArgs e)
+        private void MenuItemExportBMP(object sender, EventArgs e)
         {
             if (chkImage())
             {
                 String x = "";
-                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
+                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                 {
-                    x = folderBrowserDialog1.SelectedPath;
+                    x = folderBrowserDialog.SelectedPath;
                 }
 
                 List<Image> IMGs = new List<Image>();
@@ -197,14 +205,14 @@ namespace Gifitti.View_Models
             }
         }
 
-        private void menuItem6_Click(object sender, EventArgs e)
+        private void MenuItemExportTIFF(object sender, EventArgs e)
         {
             if (chkImage())
             {
                 String x = "";
-                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
+                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                 {
-                    x = folderBrowserDialog1.SelectedPath;
+                    x = folderBrowserDialog.SelectedPath;
                 }
 
                 List<Image> IMGs = new List<Image>();
@@ -254,5 +262,35 @@ namespace Gifitti.View_Models
         {
             gm.endFrame = int.Parse(textBox2.Text);
         }
+
+        private void MenuItemFileSaveAs(object sender, EventArgs e)
+        {
+            if (!chkImage())
+                return;
+            String path = null;
+            saveGifFileDialog.Filter = "GIF Files|*.gif";
+            if (saveGifFileDialog.ShowDialog() == DialogResult.OK)
+                path = saveGifFileDialog.FileName;
+            
+            //Handel Close
+            if (path.Equals(null))
+                return;
+            //TODO temp write
+            Console.WriteLine(path);
+            try {
+                gm.saveGif(path);
+            } catch (DirectoryNotFoundException)
+            {
+                MessageBox.Show("Save Path Invalid!");
+            }
+        }
+
+        #endregion
+        #region File Dialogs
+        private void openGifDialog_FileOk(object sender, CancelEventArgs e)
+        {
+
+        }
+        #endregion
     }
 }
diff --git a/src/Gifitti/Gifitti/View_Models/Form1.resx b/src/Gifitti/Gifitti/View_Models/Form1.resx
index 2055cdf..54ea478 100644
--- a/src/Gifitti/Gifitti/View_Models/Form1.resx
+++ b/src/Gifitti/Gifitti/View_Models/Form1.resx
@@ -117,14 +117,17 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-  <metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+  <metadata name="openGifFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>17, 17</value>
   </metadata>
-  <metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>184, 17</value>
+  <metadata name="folderBrowserDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>224, 17</value>
   </metadata>
   <metadata name="mainMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>353, 17</value>
+    <value>452, 17</value>
+  </metadata>
+  <metadata name="saveGifFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>611, 17</value>
   </metadata>
   <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>388, 17</value>
-- 
GitLab