gnome-scan r708 - in trunk: . lib



Author: bersace
Date: Sat Dec 20 14:53:19 2008
New Revision: 708
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=708&view=rev

Log:
Use freeze,thaw_notify instead of custom code.

Modified:
   trunk/ChangeLog
   trunk/lib/gnome-scan-checkbox-widget.vala
   trunk/lib/gnome-scan-combo-box-widget.vala
   trunk/lib/gnome-scan-entry-widget.vala
   trunk/lib/gnome-scan-scale-widget.vala

Modified: trunk/lib/gnome-scan-checkbox-widget.vala
==============================================================================
--- trunk/lib/gnome-scan-checkbox-widget.vala	(original)
+++ trunk/lib/gnome-scan-checkbox-widget.vala	Sat Dec 20 14:53:19 2008
@@ -25,7 +25,6 @@
 namespace Gnome.Scan {
 	public class CheckboxWidget : OptionWidget {
 		private CheckButton check;
-		private bool inhibit = false;
 
 		construct {
 			this.no_label = true;
@@ -34,30 +33,24 @@
 			this.pack_start(this.check, true, true, 0);
 
 			this.check.active = ((OptionBool)this.option).value;
-			this.check.toggled += this.update_option;
+			this.check.notify["active"] += this.update_option;
 			this.option.notify["value"] += this.update_widget;
 		}
 
 		private void update_option()
 		{
-			if (inhibit)
-				return;
-
 			var option = this.option as OptionBool;
-			inhibit = true;
+			option.freeze_notify();
 			option.value = this.check.active;
-			inhibit = false;
+			option.thaw_notify();
 		}
 
 		private void update_widget()
 		{
-			if (inhibit)
-				return;
-
 			var option = this.option as OptionBool;
-			inhibit = true;
+			option.freeze_notify();
 			this.check.active = option.value;
-			inhibit = false;
+			option.thaw_notify();
 		}
 	}
 }
\ No newline at end of file

Modified: trunk/lib/gnome-scan-combo-box-widget.vala
==============================================================================
--- trunk/lib/gnome-scan-combo-box-widget.vala	(original)
+++ trunk/lib/gnome-scan-combo-box-widget.vala	Sat Dec 20 14:53:19 2008
@@ -25,8 +25,7 @@
 	public class ComboBoxWidget : OptionWidget {
 		private ListStore store;
 		private ComboBox combo;
-		private bool inhibit = false;
-		private HashTable<Gnome.Scan.EnumValue?,string> strings;
+		private HashTable<string,string> strings;
 
 		enum Column {
 			LABEL,
@@ -38,7 +37,7 @@
 			TreeIter iter;
 			CellRenderer renderer;
 
-			strings = new HashTable<string,string>(GLib.direct_hash, GLib.direct_equal);
+			strings = new HashTable<string,string>(GLib.str_hash, GLib.str_equal);
 
 			this.store = new ListStore(Column.LENGTH, typeof(string), typeof(Gnome.Scan.EnumValue));
 			combo = new ComboBox.with_model(store);
@@ -55,13 +54,13 @@
 						  Column.LABEL, value.label,
 						  Column.VALUE, value);
 				
-				strings.insert(value, store.get_string_from_iter(iter));
+				strings.insert(value.label, store.get_string_from_iter(iter));
 
-				if (value.label == curval.label)
-					combo.set_active_iter(iter);
+				if (curval != null && value.label == curval.label)
+						combo.set_active_iter(iter);
 			}
 
-			combo.changed += this.on_combo_changed;
+			combo.notify["active"] += this.on_combo_changed;
 			option.changed += this.on_option_changed;
 
 			// don't show one option selector. Thanks Philipp for
@@ -76,37 +75,31 @@
 			weak Gnome.Scan.EnumValue? value;
 			weak string label;
 
-			if (inhibit)
-				return;
-
 			combo.get_active_iter(out iter);
 			store.get(iter,
 					  Column.VALUE, out value,
 					  Column.LABEL, out label);
 
-			inhibit = true;
+			option.freeze_notify();
 			var option = this.option as OptionEnum;
 			option.value = value;
-			option.changed();
-			inhibit = false;
+			option.thaw_notify();
 		}
 
 		private void on_option_changed()
 		{
 			TreeIter iter;
-
-			if (inhibit)
-				return;
-
-			string str = strings.lookup(((OptionEnum)option).value);
-
-			if (str == null)
+			string str = strings.lookup(((OptionEnum)option).value.label);
+			if (str == null) {
+				debug("No path for %s value", ((OptionEnum)option).value.label);
 				return;
+			}
 
 			store.get_iter_from_string(out iter, str);
-			inhibit = true;
+			
+			combo.freeze_notify();
 			combo.set_active_iter(iter);
-			inhibit = false;
+			combo.thaw_notify();
 		}
 	}
 } 
\ No newline at end of file

Modified: trunk/lib/gnome-scan-entry-widget.vala
==============================================================================
--- trunk/lib/gnome-scan-entry-widget.vala	(original)
+++ trunk/lib/gnome-scan-entry-widget.vala	Sat Dec 20 14:53:19 2008
@@ -24,7 +24,6 @@
 namespace Gnome.Scan {
 	public class EntryWidget : OptionWidget {
 		private Entry entry;
-		private bool inhibit = false;
 
 		construct {
 			var option = this.option as OptionString;
@@ -33,28 +32,22 @@
 			entry.text = option.value;
 			this.pack_start(entry, true, true, 0);
 
-			entry.changed += this.on_entry_changed;
+			entry.notify["text"] += this.on_entry_changed;
 			option.notify["value"] += this.on_option_changed;
 		}
 
 		private void on_entry_changed()
 		{
-			if (inhibit)
-				return;
-
-			inhibit = true;
+			option.freeze_notify();
 			((OptionString)option).value = entry.text;
-			inhibit = false;
+			option.thaw_notify();
 		}
 
 		private void on_option_changed()
 		{
-			if (inhibit)
-				return;
-
-			inhibit = true;
+			entry.freeze_notify();
 			entry.text = ((OptionString)option).value;
-			inhibit = false;
+			entry.thaw_notify();
 		}
 	}
 }
\ No newline at end of file

Modified: trunk/lib/gnome-scan-scale-widget.vala
==============================================================================
--- trunk/lib/gnome-scan-scale-widget.vala	(original)
+++ trunk/lib/gnome-scan-scale-widget.vala	Sat Dec 20 14:53:19 2008
@@ -24,7 +24,6 @@
 namespace Gnome.Scan {
 	public class ScaleWidget : OptionWidget {
 		private Adjustment adj;
-		private bool inhibit = false;
 
 		construct {
 			this.expand = false;
@@ -44,7 +43,7 @@
 
 				spin = new SpinButton(adj, option.step, digits);
 
-				adj.value_changed += this.on_int_adj_value_changed;
+				adj.notify["value"] += this.on_int_adj_value_changed;
 				option.notify["value"] += this.on_int_option_value_changed;
 			}
 			else if (option is OptionDouble) {
@@ -61,7 +60,7 @@
 
 				spin = new SpinButton(adj, option.step, digits);
 
-				adj.value_changed += this.on_double_adj_value_changed;
+				adj.notify["value"] += this.on_double_adj_value_changed;
 				option.notify["value"] += this.on_double_option_value_changed;
 			}
 
@@ -71,48 +70,26 @@
 
 		private void on_int_option_value_changed()
 		{
-			if (inhibit)
-				return;
-
 			var option = option as OptionInt;
-
-			inhibit = true;
 			adj.value = (double) option.value;
-			inhibit = false;
 		}
 
 		private void on_int_adj_value_changed()
 		{
-			if (inhibit)
-				return;
-
 			var option = option as OptionInt;
-			inhibit = true;
 			option.value = (int) adj.value;
-			inhibit = false;
 		}
 
 		private void on_double_option_value_changed()
 		{
-			if (inhibit)
-				return;
-
 			var option = option as OptionDouble;
-
-			inhibit = true;
 			adj.value = option.value;
-			inhibit = false;
 		}
 
 		private void on_double_adj_value_changed()
 		{
-			if (inhibit)
-				return;
-
 			var option = option as OptionDouble;
-			inhibit = true;
 			option.value = adj.value;
-			inhibit = false;
 		}
 	}
 }



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