f-spot r3913 - in trunk: . src/UI.Dialog



Author: sdelcroix
Date: Wed May 14 08:19:49 2008
New Revision: 3913
URL: http://svn.gnome.org/viewvc/f-spot?rev=3913&view=rev

Log:
2008-05-14  Stephane Delcroix  <stephane delcroix org>

	* src/UI.Dialog/SelectionRatioDialog.cs: parse custom selection ratio
	like "16/9" or "16:9". Fixes bgo #533057.


Modified:
   trunk/ChangeLog
   trunk/src/UI.Dialog/SelectionRatioDialog.cs

Modified: trunk/src/UI.Dialog/SelectionRatioDialog.cs
==============================================================================
--- trunk/src/UI.Dialog/SelectionRatioDialog.cs	(original)
+++ trunk/src/UI.Dialog/SelectionRatioDialog.cs	Wed May 14 08:19:49 2008
@@ -137,9 +137,15 @@
 			if (!constraints_store.GetIterFromString (out iter, args.Path))
 				return;
 
-			double ratio = Convert.ToDouble (args.NewText);
-			if (ratio < 1.0)
+			double ratio;
+			try {
+				ratio = ParseRatio (args.NewText);
+			} catch (FormatException fe) {
+				Console.WriteLine (fe);
 				return;
+			}
+			if (ratio < 1.0)
+				ratio = 1.0 / ratio;
 
 			using (GLib.Value val = new GLib.Value (ratio))
 				constraints_store.SetValue (iter, 1, val);
@@ -147,6 +153,22 @@
 			args.RetVal = true;
 		}
 
+		private double ParseRatio (string text)
+		{
+			try {
+				return Convert.ToDouble (text);
+			} catch (FormatException) {
+				char [] separators = {'/', ':'};
+				foreach (char c in separators) {
+					if (text.IndexOf (c) != -1) {
+						double ratio = Convert.ToDouble (text.Substring (0, text.IndexOf (c)));
+						ratio /= Convert.ToDouble (text.Substring (text.IndexOf (c) + 1));
+						return ratio;
+					}
+				}
+				throw new FormatException (String.Format ("unable to parse {0}", text));
+			}
+		}
 
 		private void DeleteSelectedRows (object o, EventArgs e)
 		{



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]