[gimp/soc-2011-gimpunitentry] GimpUnitEntry: Don't change unit to inch if the user didn't enter one



commit a451976909cc3cf143326c70972a7d96f325f49e
Author: Enrico SchroÌ?der <enni schroeder gmail com>
Date:   Tue Jun 7 22:16:14 2011 +0200

    GimpUnitEntry: Don't change unit to inch if the user didn't enter one
    
    Now the previously entered unit is maintained when the user does not enter a unit, instead of changing it to inch

 libgimpwidgets/gimpunitentry.c  |    2 ++
 libgimpwidgets/gimpunitparser.c |   12 ++++++++----
 libgimpwidgets/gimpunitparser.h |    1 +
 3 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/libgimpwidgets/gimpunitentry.c b/libgimpwidgets/gimpunitentry.c
index f6d338b..3606486 100644
--- a/libgimpwidgets/gimpunitentry.c
+++ b/libgimpwidgets/gimpunitentry.c
@@ -176,6 +176,8 @@ gimp_unit_entry_parse (GimpUnitEntry *entry)
 
   /* set resolution (important for correct calculation of px) */
   result.resolution = entry->unitAdjustment->resolution;
+  /* set unit (we want to use current unit if the user didn't enter one) */
+  result.unit = entry->unitAdjustment->unit;
 
   /* parse string of entry */
   success = gimp_unit_parser_parse (str, &result);
diff --git a/libgimpwidgets/gimpunitparser.c b/libgimpwidgets/gimpunitparser.c
index f8991be..1c93718 100644
--- a/libgimpwidgets/gimpunitparser.c
+++ b/libgimpwidgets/gimpunitparser.c
@@ -53,9 +53,9 @@ gimp_unit_parser_parse (const char *str, GimpUnitParserResult *result)
   if (strlen (str) <= 0)
     return FALSE;
   
-  /* set unit to -1 so we can determine the first unit the user entered and use that
+  /* set unitFound to FALSE so we can determine the first unit the user entered and use that
      as unit for our result */
-  result->unit = -1;
+  result->unitFound = FALSE;
 
   DEBUG (("parsing: %s", str));
 
@@ -113,7 +113,8 @@ gboolean unit_resolver (const gchar      *ident,
     else                          /* otherwise use factor */
       result->value = gimp_unit_get_factor (*unit);
 
-    resolved          = TRUE; 
+    parserResult->unitFound = TRUE;
+    resolved                = TRUE; 
     return resolved;
   }
 
@@ -130,8 +131,11 @@ gboolean unit_resolver (const gchar      *ident,
       else
         result->value = gimp_unit_get_factor (i);
 
-      if (*unit == -1)
+      if (!parserResult->unitFound)
+      {
         *unit = i;
+        parserResult->unitFound = TRUE;
+      }
 
       i = numUnits;
       resolved = TRUE;
diff --git a/libgimpwidgets/gimpunitparser.h b/libgimpwidgets/gimpunitparser.h
index 18f976b..09e463b 100644
--- a/libgimpwidgets/gimpunitparser.h
+++ b/libgimpwidgets/gimpunitparser.h
@@ -32,6 +32,7 @@ struct _GimpUnitParserResult
   gdouble   value;
   gdouble   resolution;
   GimpUnit  unit;
+  gboolean  unitFound;
 };
 
 /* parse given string */



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