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

Added logic to control autocomplete #678

Merged
merged 11 commits into from
Apr 6, 2017
4 changes: 4 additions & 0 deletions src/bramble/client/StateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ define(function() {
get: function() { return getBool(storage, "allowJavaScript"); },
set: function(v) { storage.setItem(prefix("allowJavaScript"), v); }
},
allowAutoComplete: {
Copy link

Choose a reason for hiding this comment

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

I have a general concern. In some places you use Autocomplete and in others AutoComplete. Once upon a time I implemented a bunch of code in Firefox related to the FullScreen API which later became the Fullscreen API, and it left me very nervous about the bugs that can creep in with such inconsistencies. When I Google this, most people seem to use "Autocomplete." Should we do that everywhere? I actually don't care as long as we're consistent in all places, here and in Thimble.

get: function() { return getBool(storage, "allowAutoComplete"); },
set: function(v) { storage.setItem(prefix("allowAutoComplete"), v); }
},
autoUpdate: {
get: function() { return getBool(storage, "autoUpdate"); },
set: function(v) { storage.setItem(prefix("autoUpdate"), v); }
Expand Down
19 changes: 19 additions & 0 deletions src/bramble/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ define([
self.getSidebarVisible = function() { return _state.sidebarVisible; };
self.getRootDir = function() { return _root; };
self.getWordWrap = function() { return _state.wordWrap; };
self.getAutoComplete = function() { return _state.allowAutoComplete; };
Copy link

Choose a reason for hiding this comment

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

Because you're changing the public API, please update the README as well, see https://github.com/mozilla/brackets#bramble-instance-getters

self.getAutoCloseTags = function() { return _state.autoCloseTags; };
self.getAllowJavaScript = function() { return _state.allowJavaScript; };
self.getAutoUpdate = function() { return _state.autoUpdate; };
Expand Down Expand Up @@ -267,6 +268,7 @@ define([
_state.wordWrap = data.wordWrap;
_state.autoCloseTags = data.autoCloseTags;
_state.allowJavaScript = data.allowJavaScript;
_state.autoComplete = data.autoComplete;
_state.autoUpdate = data.autoUpdate;

setReadyState(Bramble.READY);
Expand Down Expand Up @@ -309,6 +311,14 @@ define([
_state.allowJavaScript = data.allowJavaScript;
} else if (eventName === "tutorialVisibilityChange") {
_tutorialVisible = data.visible;
} else if (eventName === "TagHintsChange") {
Copy link

Choose a reason for hiding this comment

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

This is a leaky abstraction, and I'd like to harmonize these event types into a single autoCompleteChange event. See my comment below.

_state.allowAutoComplete = data.value;
} else if (eventName === "AttrHintsChange") {
_state.allowAutoComplete = data.value;
} else if (eventName === "JSHintsChange") {
_state.allowAutoComplete = data.value;
} else if (eventName === "CssPropHintsChange") {
_state.allowAutoComplete = data.value;
} else if (eventName === "autoUpdateChange") {
_state.autoUpdate = data.autoUpdate;
}
Expand Down Expand Up @@ -426,6 +436,7 @@ define([
previewMode: _state.previewMode,
wordWrap: _state.wordWrap,
allowJavaScript: _state.allowJavaScript,
allowAutoComplete: _state.allowAutoComplete,
autoCloseTags: _state.autoCloseTags,
autoUpdate: _state.autoUpdate
}
Expand Down Expand Up @@ -909,6 +920,14 @@ define([
this._executeRemoteCommand({commandCategory: "bramble", command: "BRAMBLE_DISABLE_SCRIPTS"}, callback);
};

BrambleProxy.prototype.startAutoComplete = function(callback) {
Copy link

Choose a reason for hiding this comment

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

Please change this to enable vs. start

this._executeRemoteCommand({commandCategory: "bramble", command: "START_AUTO_COMPLETE"}, callback);
Copy link

Choose a reason for hiding this comment

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

change the command name to BRAMBLE_ENABLE_AUTOCOMPLETE

};

BrambleProxy.prototype.stopAutoComplete = function(callback) {
Copy link

Choose a reason for hiding this comment

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

Please change this to disable vs. start

this._executeRemoteCommand({commandCategory: "bramble", command: "STOP_AUTO_COMPLETE"}, callback);
Copy link

Choose a reason for hiding this comment

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

change the command name to BRAMBLE_DISABLE_AUTOCOMPLETE

};

BrambleProxy.prototype.enableInspector = function(callback) {
this._executeRemoteCommand({commandCategory: "bramble", command: "BRAMBLE_ENABLE_INSPECTOR"}, callback);
};
Expand Down
13 changes: 13 additions & 0 deletions src/extensions/default/bramble/lib/RemoteCommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ define(function (require, exports, module) {
case "BRAMBLE_ENABLE_INSPECTOR":
MouseManager.enableInspector();
break;
case "STOP_AUTO_COMPLETE":
PreferencesManager.set("codehint.TagHints", true);
PreferencesManager.set("codehint.AttrHints", true);
PreferencesManager.set("codehint.JSHints", true);
PreferencesManager.set("codehint.CssPropHints", true);
break;
case "START_AUTO_COMPLETE":
PreferencesManager.set("codehint.TagHints", false);
PreferencesManager.set("codehint.AttrHints", false);
PreferencesManager.set("codehint.JSHints", false);
PreferencesManager.set("codehint.CssPropHints", false);
break;

case "BRAMBLE_DISABLE_INSPECTOR":
// Disable the inspector, and clear any marks in the preview/editor
MouseManager.disableInspector(true);
Expand Down
34 changes: 34 additions & 0 deletions src/extensions/default/bramble/lib/RemoteEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,40 @@ define(function (require, exports, module) {
});
});

// Listen for changes to TagHints
PreferencesManager.on("change", "codehint.TagHints", function () {
Copy link

Choose a reason for hiding this comment

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

I don't like the idea of sending 4 separate events for state changes on a variable that we're tracking in the StateManager as a single boolean. Can you harmonize these so they all send the same type: "bramble:autocompleteChange" with a single boolean? It will mean we fire this change event 4 times, but that shouldn't break anything, since Thimble will just set it true or false in all cases.

sendEvent({
type: "bramble:TagHintsChange",
value: PreferencesManager.get("codehint.TagHints")
});
});

// Listen for changes to AttrHints
PreferencesManager.on("change", "codehint.AttrHints", function () {
sendEvent({
type: "bramble:AttrHintsChange",
value: PreferencesManager.get("codehint.AttrHints")
});
});


// Listen for changes to JSHints
PreferencesManager.on("change", "codehint.JSHints", function () {
sendEvent({
type: "bramble:JSHintsChange",
value: PreferencesManager.get("codehint.JSHints")
});
});


// Listen for changes to CssPropHints
PreferencesManager.on("change", "codehint.CssPropHints", function () {
sendEvent({
type: "bramble:CssPropHintsChange",
value: PreferencesManager.get("codehint.CssPropHints")
});
});

//Listen for changes to auto update
PreferencesManager.on("change", "autoUpdate", function () {
sendEvent({
Expand Down
8 changes: 8 additions & 0 deletions src/extensions/default/bramble/lib/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ define(function (require, exports, module) {
PreferencesManager.set("allowJavaScript", allowJavaScript);
}

var allowAutoComplete = BrambleStartupState.ui("allowAutoComplete");
if(typeof allowAutoComplete === "boolean") {
PreferencesManager.set("codehint.AttrHints", allowAutoComplete);
PreferencesManager.set("codehint.TagHints", allowAutoComplete);
PreferencesManager.set("codehint.JSHints", allowAutoComplete);
PreferencesManager.set("codehint.CssPropHints", allowAutoComplete);
}

var autoUpdate = BrambleStartupState.ui("autoUpdate");
if(typeof autoUpdate === "boolean") {
PreferencesManager.set("autoUpdate", autoUpdate);
Expand Down
1 change: 1 addition & 0 deletions src/extensions/default/bramble/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ define(function (require, exports, module) {
previewMode: data.state.previewMode,
wordWrap: data.state.wordWrap,
allowJavaScript: data.state.allowJavaScript,
allowAutoComplete: data.state.allowAutoComplete,
autoCloseTags: data.state.autoCloseTags,
autoUpdate: data.state.autoUpdate
});
Expand Down