summaryrefslogtreecommitdiff
path: root/gui.js
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-05-17 11:53:32 +0200
committerjmoenig <jens@moenig.org>2013-05-17 11:53:32 +0200
commit77c409cb3e428f89903d89e47618447513789c40 (patch)
tree528ebb52c93177bb7ff94c3328626d75b7dffa6d /gui.js
parente1a30927139796bf9d1cd70bdf3d0189385f4637 (diff)
downloadsnap-77c409cb3e428f89903d89e47618447513789c40.tar.gz
snap-77c409cb3e428f89903d89e47618447513789c40.zip
Remember user settings across sessions
most user settings (language, blocks zoom, long form input, clicking sound, design preference) are now made persistent in localStorage, so if the user closes and re-opens Snap! the settings stay the same
Diffstat (limited to 'gui.js')
-rw-r--r--gui.js84
1 files changed, 81 insertions, 3 deletions
diff --git a/gui.js b/gui.js
index e9d0251..61a92ad 100644
--- a/gui.js
+++ b/gui.js
@@ -68,7 +68,7 @@ sb, CommentMorph, CommandBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.gui = '2013-May-16';
+modules.gui = '2013-May-17';
// Declarations
@@ -183,6 +183,9 @@ IDE_Morph.prototype.init = function (isAutoFill) {
// global font setting
MorphicPreferences.globalFontFamily = 'Helvetica, Arial';
+ // restore saved user preferences
+ this.applySavedSettings();
+
// additional properties:
this.cloudMsg = null;
this.source = 'local';
@@ -739,7 +742,6 @@ IDE_Morph.prototype.createCategories = function () {
if (this.categories) {
this.categories.destroy();
}
-
this.categories = new Morph();
this.categories.color = this.groupColor;
this.categories.silentSetWidth(this.logo.width()); // width is fixed
@@ -1624,11 +1626,13 @@ IDE_Morph.prototype.selectSprite = function (sprite) {
IDE_Morph.prototype.defaultDesign = function () {
this.setDefaultDesign();
this.refreshIDE();
+ this.removeSetting('design');
};
IDE_Morph.prototype.flatDesign = function () {
this.setFlatDesign();
this.refreshIDE();
+ this.saveSetting('design', 'flat');
};
IDE_Morph.prototype.refreshIDE = function () {
@@ -1653,6 +1657,65 @@ IDE_Morph.prototype.refreshIDE = function () {
}
};
+// IDE_Morph settings persistance
+
+IDE_Morph.prototype.applySavedSettings = function () {
+ var design = this.getSetting('design'),
+ zoom = this.getSetting('zoom'),
+ language = this.getSetting('language'),
+ click = this.getSetting('click'),
+ longform = this.getSetting('longform');
+
+ // design
+ if (design === 'flat') {
+ this.setFlatDesign();
+ } else {
+ this.setDefaultDesign();
+ }
+
+ // blocks zoom
+ if (zoom) {
+ SyntaxElementMorph.prototype.setScale(zoom);
+ CommentMorph.prototype.refreshScale();
+ SpriteMorph.prototype.initBlocks();
+ }
+
+ // language
+ if (language && language !== 'en') {
+ this.loadNewProject = true;
+ this.setLanguage(language);
+ }
+
+ // click
+ if (click && !BlockMorph.prototype.snapSound) {
+ BlockMorph.prototype.toggleSnapSound();
+ }
+
+ // long form
+ if (longform) {
+ InputSlotDialogMorph.prototype.isLaunchingExpanded = true;
+ }
+};
+
+IDE_Morph.prototype.saveSetting = function (key, value) {
+ if (localStorage) {
+ localStorage['-snap-setting-' + key] = value;
+ }
+};
+
+IDE_Morph.prototype.getSetting = function (key) {
+ if (localStorage) {
+ return localStorage['-snap-setting-' + key];
+ }
+ return null;
+};
+
+IDE_Morph.prototype.removeSetting = function (key) {
+ if (localStorage) {
+ delete localStorage['-snap-setting-' + key];
+ }
+};
+
// IDE_Morph sprite list access
IDE_Morph.prototype.addNewSprite = function () {
@@ -2020,7 +2083,14 @@ IDE_Morph.prototype.settingsMenu = function () {
}
addPreference(
'Clicking sound',
- function () {BlockMorph.prototype.toggleSnapSound(); },
+ function () {
+ BlockMorph.prototype.toggleSnapSound();
+ if (BlockMorph.prototype.snapSound) {
+ myself.saveSetting('click', true);
+ } else {
+ myself.removeSetting('click');
+ }
+ },
BlockMorph.prototype.snapSound,
'uncheck to turn\nblock clicking\nsound off',
'check to turn\nblock clicking\nsound on'
@@ -2861,6 +2931,11 @@ IDE_Morph.prototype.toggleBlurredShadows = function () {
IDE_Morph.prototype.toggleLongFormInputDialog = function () {
InputSlotDialogMorph.prototype.isLaunchingExpanded =
!InputSlotDialogMorph.prototype.isLaunchingExpanded;
+ if (InputSlotDialogMorph.prototype.isLaunchingExpanded) {
+ this.saveSetting('longform', true);
+ } else {
+ this.removeSetting('longform');
+ }
};
IDE_Morph.prototype.togglePreferEmptySlotDrops = function () {
@@ -3046,9 +3121,11 @@ IDE_Morph.prototype.reflectLanguage = function (lang) {
this.fixLayout();
if (this.loadNewProject) {
this.newProject();
+ this.loadNewProject = false;
} else {
this.openProjectString(projectData);
}
+ this.saveSetting('language', lang);
};
// IDE_Morph blocks scaling
@@ -3153,6 +3230,7 @@ IDE_Morph.prototype.setBlocksScale = function (num) {
this.createCorralBar();
this.fixLayout();
this.openProjectString(projectData);
+ this.saveSetting('zoom', num);
};
// IDE_Morph cloud interface