Permalink
Browse files

Merge pull request #45 from don-mccomb/SelectNewImageWidthText

Select width text when New Document dialog is shown.
  • Loading branch information...
2 parents f446bcc + da09903 commit cafa78f6d7dec371ce0208aa283348168b661fd5 @cameronwhite cameronwhite committed Dec 1, 2012
Showing with 35 additions and 19 deletions.
  1. +21 −10 Pinta/Actions/File/NewDocumentAction.cs
  2. +14 −9 Pinta/Dialogs/NewImageDialog.cs
View
31 Pinta/Actions/File/NewDocumentAction.cs
@@ -45,14 +45,21 @@ public void Uninitialize ()
private void Activated (object sender, EventArgs e)
{
- NewImageDialog dialog = new NewImageDialog ();
-
- if (!TryUseClipboardImageSize (dialog))
+ int imgWidth = 0;
+ int imgHeight = 0;
+
+ // Try to get the dimensions of an image on the clipboard
+ // for the initial width and height values on the NewImageDialog
+ if (!GetClipboardImageSize (out imgWidth, out imgHeight))
{
- dialog.NewImageWidth = PintaCore.Settings.GetSetting<int> ("new-image-width", 800);
- dialog.NewImageHeight = PintaCore.Settings.GetSetting<int> ("new-image-height", 600);
+ // An image was not on the clipboard,
+ // so use saved dimensions from settings
+ imgWidth = PintaCore.Settings.GetSetting<int> ("new-image-width", 800);
+ imgHeight = PintaCore.Settings.GetSetting<int> ("new-image-height", 600);
}
+ NewImageDialog dialog = new NewImageDialog (imgWidth, imgHeight);
+
dialog.WindowPosition = Gtk.WindowPosition.CenterOnParent;
int response = dialog.Run ();
@@ -69,12 +76,16 @@ private void Activated (object sender, EventArgs e)
}
/// <summary>
- /// Sets the dialog to use the clipboard image's dimensions, if possible.
+ /// Gets the width and height of an image on the clipboard,
+ /// if available.
/// </summary>
- /// <returns>True if an image was on the clipboard, false otherwise.</returns>
- private static bool TryUseClipboardImageSize (NewImageDialog dialog)
+ /// <param name="width">Destination for the image width.</param>
+ /// <param name="height">Destination for the image height.</param>
+ /// <returns>True if dimensions were available, false otherwise.</returns>
+ private static bool GetClipboardImageSize (out int width, out int height)
{
bool clipboardUsed = false;
+ width = height = 0;
Gtk.Clipboard cb = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
if (cb.WaitIsImageAvailable ())
@@ -83,8 +94,8 @@ private static bool TryUseClipboardImageSize (NewImageDialog dialog)
if (image != null)
{
clipboardUsed = true;
- dialog.NewImageWidth = image.Width;
- dialog.NewImageHeight = image.Height;
+ width = image.Width;
+ height = image.Height;
image.Dispose ();
}
}
View
23 Pinta/Dialogs/NewImageDialog.cs
@@ -32,7 +32,12 @@ namespace Pinta
{
public partial class NewImageDialog : Gtk.Dialog
{
- public NewImageDialog () : base (string.Empty, PintaCore.Chrome.MainWindow, DialogFlags.Modal)
+ /// <summary>
+ /// Configures and builds a NewImageDialog object.
+ /// </summary>
+ /// <param name="imgWidth">Initial value of the width spin control.</param>
+ /// <param name="imgHeight">nitial value of the height spin control.</param>
+ public NewImageDialog (int imgWidth, int imgHeight) : base (string.Empty, PintaCore.Chrome.MainWindow, DialogFlags.Modal)
{
this.Build ();
@@ -42,17 +47,17 @@ public NewImageDialog () : base (string.Empty, PintaCore.Chrome.MainWindow, Dial
widthSpinner.ActivatesDefault = true;
heightSpinner.ActivatesDefault = true;
- }
- public int NewImageWidth {
- get { return widthSpinner.ValueAsInt; }
- set { widthSpinner.Value = value; }
- }
+ // Initialize the spin control values
+ widthSpinner.Value = imgWidth;
+ heightSpinner.Value =imgHeight;
- public int NewImageHeight {
- get { return heightSpinner.ValueAsInt; }
- set { heightSpinner.Value = value; }
+ // Set focus to the width spin control and select it's text
+ widthSpinner.GrabFocus();
}
+
+ public int NewImageWidth { get { return widthSpinner.ValueAsInt; } }
+ public int NewImageHeight { get { return heightSpinner.ValueAsInt; } }
}
}

0 comments on commit cafa78f

Please sign in to comment.