commit:1c721a96d70dcffb50c33ee81c8df3d78ef0a28f
author:Chip Black
committer:Chip Black
date:Sun Sep 11 22:39:36 2011 -0500
parents:5045171980085a8227a7fdd2a04724a2fd9830b2
Clean up preferences style, add prefs reset
diff --git a/HackPreferences.js b/HackPreferences.js
line changes: +13/-4
index a8f9195..550dbc1
--- a/HackPreferences.js
+++ b/HackPreferences.js
@@ -6,9 +6,12 @@ enyo.kind({
 	},
 	components: [
 		{kind: "Header", content: "Preferences"},
-		{kind: "Scroller", flex: 1, horizontal: false, components: [
-			{kind: "VFlexBox", align: "center", components: [
-				{kind: "RowGroup", name: "prefsContainer", style: "width: 750px"}
+		{kind: "Scroller", flex: 1, components: [
+			{kind: "Control", className: "prefs-center", components: [
+				{kind: "RowGroup", name: "prefsContainer"},
+				{kind: "HFlexBox", pack: "center", components: [
+					{kind: "Button", className: "enyo-button-negative prefs-done-button", caption: "Reset to Defaults", onclick: "resetToDefaults"}
+				]}
 			]}
 		]},
 		{kind: "Toolbar", className: "enyo-toolbar-light", components: [
@@ -27,7 +30,6 @@ enyo.kind({
 			case 'Slider':
 				c = this.$.prefsContainer.createComponent({kind: "HFlexBox", align: "center", components: [{content: p.label, flex: 1}]});
 				var slider = c.createComponent(p, {owner: this.$.prefsContainer});
-				slider.setStyle('width: 400px');
 				slider.setPosition(values[p.name]);
 				break;
 			default:
@@ -54,6 +56,13 @@ enyo.kind({
 		}
 		this.doClose(o);
 
+		this.cleanup();
+	},
+	resetToDefaults: function() {
+		this.doClose(null);
+		this.cleanup();
+	},
+	cleanup: function() {
 		var controls = this.$.prefsContainer.getControls();
 		for (var i = 0; i < controls.length; i++) {
 			// We destroy the parent because we want to destroy the

diff --git a/Main.css b/Main.css
line changes: +9/-0
index 6a1d5c2..69308ae
--- a/Main.css
+++ b/Main.css
@@ -45,3 +45,12 @@
 .prefs-done-button {
 	width: 300px;
 }
+
+.prefs-center {
+	width: 500px;
+	margin: 23px auto 0 auto;
+}
+
+.prefs-center .enyo-slider {
+	width: 300px;
+}

diff --git a/Main.js b/Main.js
line changes: +11/-5
index c8a2c19..35c3a6c
--- a/Main.js
+++ b/Main.js
@@ -83,11 +83,17 @@ enyo.kind({
 		}
 	},
 	savePreferences: function(inSender, prefs) {
-		enyo.log("Saving prefs: " + JSON.stringify(prefs));
-		this.back();
 		var view = this.$.hacksCarousel.fetchView('center');
-		view.setPreferences(prefs);
-		view.start();
+		if (prefs == null) {
+			enyo.log("Clearing prefs");
+			view.resetPreferences(prefs);
+			this.selectHack(this, this.index);
+		} else {
+			enyo.log("Saving prefs: " + JSON.stringify(prefs));
+			view.setPreferences(prefs);
+			view.start();
+		}
+		this.back();
 	},
 	windowActivated: function() {
 		this.startHack();
@@ -95,7 +101,7 @@ enyo.kind({
 	windowDeactivated: function() {
 		this.stopHack();
 	},
-	selectHack: function(inSender, inValue, inOldValue) {
+	selectHack: function(inSender, inValue) {
 		this.stopHack();
 		this.index = inValue;
 		this.lastScrollPos = 0;

diff --git a/hacks/Hack.js b/hacks/Hack.js
line changes: +3/-0
index 2b0e5f7..13e1912
--- a/hacks/Hack.js
+++ b/hacks/Hack.js
@@ -51,5 +51,8 @@ enyo.kind({
 			enyo.log("Could not save prefs: " + e.toString());
 		}
 	},
+	resetPreferences: function() {
+		delete localStorage['hacks/' + this.kind];
+	},
 	preferencesChanged: function() { }
 });