Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #45 from don-mccomb/SelectNewImageWidthText

Select width text when New Document dialog is shown.
  • Loading branch information...
commit cafa78f6d7dec371ce0208aa283348168b661fd5 2 parents f446bcc + da09903
Cameron White authored December 01, 2012
31  Pinta/Actions/File/NewDocumentAction.cs
@@ -45,14 +45,21 @@ public void Uninitialize ()
45 45
 
46 46
 		private void Activated (object sender, EventArgs e)
47 47
 		{
48  
-			NewImageDialog dialog = new NewImageDialog ();
49  
-
50  
-			if (!TryUseClipboardImageSize (dialog))
  48
+			int imgWidth = 0;
  49
+			int imgHeight = 0;
  50
+			
  51
+			// Try to get the dimensions of an image on the clipboard
  52
+			// for the initial width and height values on the NewImageDialog
  53
+			if (!GetClipboardImageSize (out imgWidth, out imgHeight))
51 54
 			{
52  
-				dialog.NewImageWidth = PintaCore.Settings.GetSetting<int> ("new-image-width", 800);
53  
-				dialog.NewImageHeight = PintaCore.Settings.GetSetting<int> ("new-image-height", 600);
  55
+				// An image was not on the clipboard,
  56
+				// so use saved dimensions from settings
  57
+				imgWidth = PintaCore.Settings.GetSetting<int> ("new-image-width", 800);
  58
+				imgHeight = PintaCore.Settings.GetSetting<int> ("new-image-height", 600);
54 59
 			}
55 60
 
  61
+			NewImageDialog dialog = new NewImageDialog (imgWidth, imgHeight);
  62
+
56 63
 			dialog.WindowPosition = Gtk.WindowPosition.CenterOnParent;
57 64
 
58 65
 			int response = dialog.Run ();
@@ -69,12 +76,16 @@ private void Activated (object sender, EventArgs e)
69 76
 		}
70 77
 
71 78
 		/// <summary>
72  
-		/// Sets the dialog to use the clipboard image's dimensions, if possible.
  79
+		/// Gets the width and height of an image on the clipboard,
  80
+		/// if available.
73 81
 		/// </summary>
74  
-		/// <returns>True if an image was on the clipboard, false otherwise.</returns>
75  
-		private static bool TryUseClipboardImageSize (NewImageDialog dialog)
  82
+		/// <param name="width">Destination for the image width.</param>
  83
+		/// <param name="height">Destination for the image height.</param>
  84
+		/// <returns>True if dimensions were available, false otherwise.</returns>
  85
+		private static bool GetClipboardImageSize (out int width, out int height)
76 86
 		{
77 87
 			bool clipboardUsed = false;
  88
+			width = height = 0;
78 89
 
79 90
 			Gtk.Clipboard cb = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
80 91
 			if (cb.WaitIsImageAvailable ())
@@ -83,8 +94,8 @@ private static bool TryUseClipboardImageSize (NewImageDialog dialog)
83 94
 				if (image != null)
84 95
 				{
85 96
 					clipboardUsed = true;
86  
-					dialog.NewImageWidth = image.Width;
87  
-					dialog.NewImageHeight = image.Height;
  97
+					width = image.Width;
  98
+					height = image.Height;
88 99
 					image.Dispose ();
89 100
 				}
90 101
 			}
23  Pinta/Dialogs/NewImageDialog.cs
@@ -32,7 +32,12 @@ namespace Pinta
32 32
 {
33 33
 	public partial class NewImageDialog : Gtk.Dialog
34 34
 	{
35  
-		public NewImageDialog () : base (string.Empty, PintaCore.Chrome.MainWindow, DialogFlags.Modal)
  35
+		/// <summary>
  36
+		/// Configures and builds a NewImageDialog object.
  37
+		/// </summary>
  38
+		/// <param name="imgWidth">Initial value of the width spin control.</param>
  39
+		/// <param name="imgHeight">nitial value of the height spin control.</param>
  40
+		public NewImageDialog (int imgWidth, int imgHeight) : base (string.Empty, PintaCore.Chrome.MainWindow, DialogFlags.Modal)
36 41
 		{
37 42
 			this.Build ();
38 43
 
@@ -42,17 +47,17 @@ public NewImageDialog () : base (string.Empty, PintaCore.Chrome.MainWindow, Dial
42 47
 
43 48
 			widthSpinner.ActivatesDefault = true;
44 49
 			heightSpinner.ActivatesDefault = true;
45  
-		}
46 50
 
47  
-		public int NewImageWidth {
48  
-			get { return widthSpinner.ValueAsInt; }
49  
-			set { widthSpinner.Value = value; }
50  
-		}
  51
+			// Initialize the spin control values
  52
+			widthSpinner.Value = imgWidth;
  53
+			heightSpinner.Value =imgHeight;
51 54
 
52  
-		public int NewImageHeight {
53  
-			get { return heightSpinner.ValueAsInt; }
54  
-			set { heightSpinner.Value = value; }
  55
+			// Set focus to the width spin control and select it's text
  56
+			widthSpinner.GrabFocus();
55 57
 		}
  58
+
  59
+		public int NewImageWidth { get { return widthSpinner.ValueAsInt; } }
  60
+		public int NewImageHeight { get { return heightSpinner.ValueAsInt; } }
56 61
 	}
57 62
 }
58 63
 

0 notes on commit cafa78f

Please sign in to comment.
Something went wrong with that request. Please try again.