Skip to content

Commit

Permalink
Added logic to control autocomplete (#678)
Browse files Browse the repository at this point in the history
* Included new state in StateManager.js

* Added events to implement AutoComplete toggle

* Added start and stop functions in bramble

* Added allowAutoCorrect to main.js

* Fixes typos

* Added toggle functionality to JS and CSS hints

* Changed all variable names to Autocomplete

* Emitted a single event(autocompleteChange) when Hints Change

* Added note in README related to new getAutocomplete function

* Modified Remote Command Strings
  • Loading branch information
hkirat authored and humphd committed Apr 6, 2017
1 parent 2d10c28 commit 2d99ca7
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ a number of read-only getters are available in order to access state information
* `getTheme()` - returns the name of the current theme.
* `getFontSize()` - returns the current font size as a string (e.g., `"12px"`).
* `getWordWrap()` - returns the current word wrap setting as a `Boolean` (i.e., enabled or disabled).
* `getAutocomplete()` - returns the current autocomplete settings as a `Boolean` (i.e., enabled or disabled).
* `getAutoCloseTags()` - returns the current close tags setting as an `Object` with three properties: `whenOpening` a boolean that determines whether opening tags are closed upon typing ">", `whenClosing` a boolean that determines whether closing tags are closed upon typing "/", and an array of tags `indentTags`, that when opened, has a blank line. These values default to, respectively: `true`, `true`, and an empty array.
* `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.
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 @@ -139,6 +139,10 @@ define(function() {
get: function() { return getBool(storage, "allowJavaScript"); },
set: function(v) { storage.setItem(prefix("allowJavaScript"), v); }
},
allowAutocomplete: {
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
13 changes: 13 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; };
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,8 @@ define([
_state.allowJavaScript = data.allowJavaScript;
} else if (eventName === "tutorialVisibilityChange") {
_tutorialVisible = data.visible;
} else if (eventName === "autocompleteChange") {
_state.allowAutocomplete = data.value;
} else if (eventName === "autoUpdateChange") {
_state.autoUpdate = data.autoUpdate;
}
Expand Down Expand Up @@ -426,6 +430,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 +914,14 @@ define([
this._executeRemoteCommand({commandCategory: "bramble", command: "BRAMBLE_DISABLE_SCRIPTS"}, callback);
};

BrambleProxy.prototype.enableAutocomplete = function(callback) {
this._executeRemoteCommand({commandCategory: "bramble", command: "BRAMBLE_ENABLE_AUTOCOMPLETE"}, callback);
};

BrambleProxy.prototype.disableAutocomplete = function(callback) {
this._executeRemoteCommand({commandCategory: "bramble", command: "BRAMBLE_DISABLE_AUTOCOMPLETE"}, callback);
};

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 "BRAMBLE_ENABLE_AUTOCOMPLETE":
PreferencesManager.set("codehint.TagHints", true);
PreferencesManager.set("codehint.AttrHints", true);
PreferencesManager.set("codehint.JSHints", true);
PreferencesManager.set("codehint.CssPropHints", true);
break;
case "BRAMBLE_DISABLE_AUTOCOMPLETE":
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 () {
sendEvent({
type: "bramble:autocompleteChange",
value: PreferencesManager.get("codehint.TagHints")
});
});

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


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


// Listen for changes to CssPropHints
PreferencesManager.on("change", "codehint.CssPropHints", function () {
sendEvent({
type: "bramble:autocompleteChange",
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

0 comments on commit 2d99ca7

Please sign in to comment.