Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for backend to fix #1633 #595

Merged
merged 1 commit into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ a number of read-only getters are available in order to access state information
* `getWordWrap()` - returns the current word wrap setting as a `Boolean` (i.e., enabled or disabled).
* `getTutorialExists()` - returns `true` or `false` depending on whether or not there is a tutorial in the project (i.e., if `tutorial.html` is present)
* `getTutorialVisible()` - returns `true` or `false` depending on whether or not the preview browser is showing a tutorial or not.
* `getAutoUpdate()` - returns `true` or `false` depending on whether or not the auto update preference is enabled or not.

**NOTE**: calling these getters before the `ready()` callback on the bramble instance
won't do what you want.
Expand Down Expand Up @@ -373,6 +374,7 @@ the following events:
* `"tutorialRemoved"` - triggered when an existing tutorial for the project is removed
* `"tutorialVisibilityChange"` - triggered when the tutorial preview is turned on or off. It includes an `Object` with a `visibility` property that indicates whether the tutorial is visible.
* `"inspectorChange"` - triggered whenever the inspector changes from enabled to disabled, or vice versa. It includes an `Object` with an `enabled` property set to `true` or `false`.
* `"autoUpdateChange"` - triggered whenever the auto update preference changes from enabled to disabled, or vice versa. It includes an `Object` with a `autoUpdate` property set to `true` or `false`

There are also high-level events for changes to files:

Expand Down
4 changes: 4 additions & 0 deletions src/bramble/client/StateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ define(function() {
allowJavaScript: {
get: function() { return getBool(storage, "allowJavaScript"); },
set: function(v) { storage.setItem(prefix("allowJavaScript"), v); }
},
autoUpdate: {
get: function() { return getBool(storage, "autoUpdate"); },
set: function(v) { storage.setItem(prefix("autoUpdate"), v); }
}
});
}
Expand Down
7 changes: 6 additions & 1 deletion src/bramble/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ define([
self.getRootDir = function() { return _root; };
self.getWordWrap = function() { return _state.wordWrap; };
self.getAllowJavaScript = function() { return _state.allowJavaScript; };
self.getAutoUpdate = function() { return _state.autoUpdate; };
self.getTutorialExists = function() { return _tutorialExists; };
self.getTutorialVisible = function() { return _tutorialVisible; };
self.getLayout = function() {
Expand Down Expand Up @@ -264,6 +265,7 @@ define([
_state.theme = data.theme;
_state.wordWrap = data.wordWrap;
_state.allowJavaScript = data.allowJavaScript;
_state.autoUpdate = data.autoUpdate;

setReadyState(Bramble.READY);
}
Expand Down Expand Up @@ -303,6 +305,8 @@ define([
_state.allowJavaScript = data.allowJavaScript;
} else if (eventName === "tutorialVisibilityChange") {
_tutorialVisible = data.visible;
} else if (eventName === "autoUpdateChange") {
_state.autoUpdate = data.autoUpdate;
}

debug("triggering remote event", eventName, data);
Expand Down Expand Up @@ -417,7 +421,8 @@ define([
secondPaneWidth: _state.secondPaneWidth,
previewMode: _state.previewMode,
wordWrap: _state.wordWrap,
allowJavaScript: _state.allowJavaScript
allowJavaScript: _state.allowJavaScript,
autoUpdate: _state.autoUpdate
}
};
_brambleWindow.postMessage(JSON.stringify(initMessage), _iframe.src);
Expand Down
1 change: 1 addition & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ define(function (require, exports, module) {
exports.TOGGLE_ACTIVE_LINE = "view.toggleActiveLine"; // EditorOptionHandlers.js _getToggler()
exports.TOGGLE_WORD_WRAP = "view.toggleWordWrap"; // EditorOptionHandlers.js _getToggler()
exports.TOGGLE_ALLOW_JAVASCRIPT = "cmd.toggleAllowJavaScript"; // EditorOptionsHandlers.js _getToggler()
exports.TOGGLE_AUTO_UPDATE = "cmd.toggleAutoUpdate"; // EditorOptionsHandlers.js _getToggler()

exports.CMD_OPEN = "cmd.open";
exports.CMD_ADD_TO_WORKINGSET_AND_OPEN = "cmd.addToWorkingSetAndOpen"; // DocumentCommandHandlers.js handleOpenDocumentInNewPane()
Expand Down
9 changes: 7 additions & 2 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ define(function (require, exports, module) {
UPPERCASE_COLORS = "uppercaseColors",
USE_TAB_CHAR = "useTabChar",
WORD_WRAP = "wordWrap",
INDENT_LINE_COMMENT = "indentLineComment",
ALLOW_JAVASCRIPT = "allowJavaScript";
INDENT_LINE_COMMENT = "indentLineComment",
ALLOW_JAVASCRIPT = "allowJavaScript",
AUTO_UPDATE = "autoUpdate";


var cmOptions = {};
Expand Down Expand Up @@ -221,6 +222,10 @@ define(function (require, exports, module) {
description: Strings.DESCRIPTION_ALLOW_JAVASCRIPT
});

PreferencesManager.definePreference(AUTO_UPDATE, "boolean", true, {
description: Strings.DESCRIPTION_AUTO_UPDATE
});


var editorOptions = Object.keys(cmOptions);

Expand Down
5 changes: 4 additions & 1 deletion src/editor/EditorOptionHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ define(function (require, exports, module) {
STYLE_ACTIVE_LINE = "styleActiveLine",
WORD_WRAP = "wordWrap",
ALLOW_JAVASCRIPT = "allowJavaScript",
CLOSE_BRACKETS = "closeBrackets";
CLOSE_BRACKETS = "closeBrackets",
AUTO_UPDATE = "autoUpdate";

/**
* @private
Expand All @@ -50,6 +51,7 @@ define(function (require, exports, module) {
_optionMapping[WORD_WRAP] = Commands.TOGGLE_WORD_WRAP;
_optionMapping[ALLOW_JAVASCRIPT] = Commands.TOGGLE_ALLOW_JAVASCRIPT;
_optionMapping[CLOSE_BRACKETS] = Commands.TOGGLE_CLOSE_BRACKETS;
_optionMapping[AUTO_UPDATE] = Commands.TOGGLE_AUTO_UPDATE;

/**
* @private
Expand Down Expand Up @@ -102,6 +104,7 @@ define(function (require, exports, module) {

// XXXBramble
CommandManager.registerInternal(Commands.TOGGLE_ALLOW_JAVASCRIPT, _getToggler(ALLOW_JAVASCRIPT));
CommandManager.registerInternal(Commands.TOGGLE_AUTO_UPDATE, _getToggler(AUTO_UPDATE));

AppInit.htmlReady(_init);
});
8 changes: 7 additions & 1 deletion src/extensions/default/bramble/lib/PostMessageTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ define(function (require, exports, module) {
LiveDevMultiBrowser = brackets.getModule("LiveDevelopment/LiveDevMultiBrowser"),
BlobUtils = brackets.getModule("filesystem/impls/filer/BlobUtils"),
BrambleEvents = brackets.getModule("bramble/BrambleEvents"),
Path = brackets.getModule("filesystem/impls/filer/BracketsFiler").Path;
Path = brackets.getModule("filesystem/impls/filer/BracketsFiler").Path,
BrambleStartupState = brackets.getModule("bramble/StartupState");

// The script that will be injected into the previewed HTML to handle the other side of the post message connection.
var PostMessageTransportRemote = require("text!lib/PostMessageTransportRemote.js");
Expand Down Expand Up @@ -105,6 +106,11 @@ define(function (require, exports, module) {
function start(){
window.addEventListener("message", _listener);

var autoUpdate = BrambleStartupState.ui("autoUpdate");
if(typeof autoUpdate === "boolean") {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a possibility that this is not a boolean? What are the values that it can take?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

literally anything I believe. BrambleStartupState is just a simple map currently that doesn't do any type checking.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean we should type check, or do we need to coerce with a !!?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just type check? I think for all the other properties, we don't do any coercion so maybe keep it like that for now?

Copy link

@Pomax Pomax Feb 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it feels odd to have to type check a value that we supposedly control. Would we at least be able to enforce that whetever it's set it is a boolean? Then we don't have to bother with the check here, and we can let the handler function do whatever it needs to do when it gets "not a bool" passed into it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually don't really control that, it sets it to whatever the hosting app sends us. But, I agree that we should probably enforce type checks as soon as the values are being set. We'll have to add that logic to BrambleStartupState which currently is pretty generic to store any kind of value. Filed #615 to fix that.

setAutoUpdate(autoUpdate);
}

// Reload whenever files are removed or renamed
BrambleEvents.on("fileRemoved", reload);
BrambleEvents.on("fileRenamed", reload);
Expand Down
2 changes: 2 additions & 0 deletions src/extensions/default/bramble/lib/RemoteCommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ define(function (require, exports, module) {
UI.disableFullscreenPreview();
break;
case "BRAMBLE_ENABLE_AUTO_UPDATE":
PreferencesManager.set("autoUpdate", true);
PostMessageTransport.setAutoUpdate(true);
break;
case "BRAMBLE_DISABLE_AUTO_UPDATE":
PreferencesManager.set("autoUpdate", false);
PostMessageTransport.setAutoUpdate(false);
break;
case "BRAMBLE_ENABLE_SCRIPTS":
Expand Down
11 changes: 10 additions & 1 deletion src/extensions/default/bramble/lib/RemoteEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ define(function (require, exports, module) {
allowJavaScript: PreferencesManager.get("allowJavaScript")
});
});

//Listen for changes to auto update
PreferencesManager.on("change", "autoUpdate", function () {
sendEvent({
type: "bramble:autoUpdateChange",
autoUpdate: PreferencesManager.get("autoUpdate")
});
});
}

/**
Expand Down Expand Up @@ -165,7 +173,8 @@ define(function (require, exports, module) {
fontSize: ViewCommandHandlers.getFontSize(),
theme: Theme.getTheme(),
wordWrap: PreferencesManager.get("wordWrap"),
allowJavaScript: PreferencesManager.get("allowJavaScript")
allowJavaScript: PreferencesManager.get("allowJavaScript"),
autoUpdate: PreferencesManager.get("autoUpdate")
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/extensions/default/bramble/lib/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ define(function (require, exports, module) {
PreferencesManager.set("allowJavaScript", allowJavaScript);
}

var autoUpdate = BrambleStartupState.ui("autoUpdate");
if(typeof autoUpdate === "boolean") {
PreferencesManager.set("autoUpdate", autoUpdate);
}

var sidebarWidth = BrambleStartupState.ui("sidebarWidth");
if(sidebarWidth) {
SidebarView.resize(sidebarWidth);
Expand Down
3 changes: 2 additions & 1 deletion src/extensions/default/bramble/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ define(function (require, exports, module) {
secondPaneWidth: data.state.secondPaneWidth,
previewMode: data.state.previewMode,
wordWrap: data.state.wordWrap,
allowJavaScript: data.state.allowJavaScript
allowJavaScript: data.state.allowJavaScript,
autoUpdate: data.state.autoUpdate
});

RemoteEvents.start();
Expand Down