Skip to content

Commit

Permalink
Add backend support for word wrap - https://github.com/mozilla/thimbl…
Browse files Browse the repository at this point in the history
  • Loading branch information
humphd committed Jul 13, 2015
1 parent ec76aed commit 5bf8a0c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ a number of read-only getters are available in order to access state information
* `getLayout()` - returns an `Object` with three integer properties: `sidebarWidth`, `firstPaneWidth`, `secondPaneWidth`. The `firstPaneWidth` refers to the editor, where `secondPaneWidth` is the preview.
* `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).

**NOTE**: calling these getters before the `ready()` callback on the bramble instance
won't do what you want.
Expand Down Expand Up @@ -294,6 +295,8 @@ to be notified when the action completes:
* `useDesktopPreview([callback])` - uses a Desktop view in the preview, as it would look on a desktop computer (default)
* `enableJavaScript([callback])` - turns on JavaScript execution for the preview (default)
* `disableJavaScript([callback])` - turns off JavaScript execution for the preview
* `enableWordWrap([callback])` - turns on word wrap for the editor (default)
* `disableWordWrap([callback])` - turns off word wrap for the editor

## Bramble Instance Events

Expand All @@ -306,6 +309,7 @@ the following events:
* `"sidebarChange"` - triggered whenever the sidebar is hidden or shown. It includes an `Object` with a `visible` property set to `true` or `false`
* `"themeChange"` - triggered whenever the theme changes. It inclues an `Object` with a `theme` property that indicates the new theme
* `"fontSizeChange"` - triggered whenever the font size changes. It includes an `Object` with a `fontSize` property that indicates the new size (e.g., `"12px"`).
* `"wordWrapChange"` - triggered whenever the word wrap value changes. It includes an `Object` with a `wordWrap` property that indicates the new value (e.g., `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 @@ -97,6 +97,10 @@ define(function() {
fullPath: {
get: function() { return getString(storage, "fullPath"); },
set: function(v) { storage.setItem(prefix("fullPath"), v); }
},
wordWrap: {
get: function() { return getBool(storage, "wordWrap"); },
set: function(v) { storage.setItem(prefix("wordWrap"), v); }
}
});
}
Expand Down
15 changes: 14 additions & 1 deletion src/bramble/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ define([
self.getTheme = function() { return _state.theme; };
self.getFontSize = function() { return _state.fontSize; };
self.getSidebarVisible = function() { return _state.sidebarVisible; };
self.getWordWrap = function() { return _state.wordWrap; };
self.getLayout = function() {
return {
sidebarWidth: _state.sidebarWidth,
Expand Down Expand Up @@ -221,6 +222,7 @@ define([
_state.secondPaneWidth = data.secondPaneWidth;
_state.previewMode = data.previewMode;
_state.theme = data.theme;
_state.wordWrap = data.wordWrap;

setReadyState(Bramble.READY);
}
Expand Down Expand Up @@ -254,6 +256,8 @@ define([
_state.fontSize = data.fontSize;
} else if (eventName === "sidebarChange") {
_state.sidebarVisible = data.visible;
} else if (eventName === "wordWrapChange") {
_state.wordWrap = data.wordWrap;
}

debug("triggering remote event", eventName, data);
Expand Down Expand Up @@ -359,7 +363,8 @@ define([
sidebarWidth: _state.sidebarWidth,
firstPaneWidth: _state.firstPaneWidth,
secondPaneWidth: _state.secondPaneWidth,
previewMode: _state.previewMode
previewMode: _state.previewMode,
wordWrap: _state.wordWrap
}
};
_brambleWindow.postMessage(JSON.stringify(initMessage), _iframe.src);
Expand Down Expand Up @@ -602,5 +607,13 @@ define([
this._executeRemoteCommand({commandCategory: "bramble", command: "BRAMBLE_DISABLE_SCRIPTS"}, callback);
};

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

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

return Bramble;
});
9 changes: 8 additions & 1 deletion src/extensions/default/bramble/lib/RemoteCommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ define(function (require, exports, module) {
var StatusBar = brackets.getModule("widgets/StatusBar");
var WorkspaceManager = brackets.getModule("view/WorkspaceManager");
var BrambleEvents = brackets.getModule("bramble/BrambleEvents");

var PreferencesManager = brackets.getModule("preferences/PreferencesManager");

var PostMessageTransport = require("lib/PostMessageTransport");
var Theme = require("lib/Theme");
var UI = require("lib/UI");
Expand Down Expand Up @@ -95,6 +96,12 @@ define(function (require, exports, module) {
case "BRAMBLE_SHOW_STATUSBAR":
StatusBar.enable();
break;
case "BRAMBLE_ENABLE_WORD_WRAP":
PreferencesManager.set("wordWrap", true);
break;
case "BRAMBLE_DISABLE_WORD_WRAP":
PreferencesManager.set("wordWrap", false);
break;
case "RESIZE":
// The host window was resized, update all panes
WorkspaceManager.recomputeLayout(true);
Expand Down
12 changes: 11 additions & 1 deletion src/extensions/default/bramble/lib/RemoteEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define(function (require, exports, module) {
var MainViewManager = brackets.getModule("view/MainViewManager");
var ViewCommandHandlers = brackets.getModule("view/ViewCommandHandlers");
var Path = brackets.getModule("filesystem/impls/filer/FilerUtils").Path;
var PreferencesManager = brackets.getModule("preferences/PreferencesManager");
var UI = require("lib/UI");
var Theme = require("lib/Theme");

Expand Down Expand Up @@ -97,6 +98,14 @@ define(function (require, exports, module) {
fontSize: fontSize
});
});

// Listen for changes to word wrap
PreferencesManager.on("change", "wordWrap", function () {
sendEvent({
type: "bramble:wordWrapChange",
wordWrap: PreferencesManager.get("wordWrap")
});
});
}

/**
Expand All @@ -121,7 +130,8 @@ define(function (require, exports, module) {
filename: filename,
previewMode: UI.getPreviewMode(),
fontSize: ViewCommandHandlers.getFontSize(),
theme: Theme.getTheme()
theme: Theme.getTheme(),
wordWrap: PreferencesManager.get("wordWrap")
});
}

Expand Down
8 changes: 7 additions & 1 deletion src/extensions/default/bramble/lib/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ define(function (require, exports, module) {
FileSystem = brackets.getModule("filesystem/FileSystem"),
ViewCommandHandlers = brackets.getModule("view/ViewCommandHandlers"),
SidebarView = brackets.getModule("project/SidebarView"),
WorkspaceManager = brackets.getModule("view/WorkspaceManager");
WorkspaceManager = brackets.getModule("view/WorkspaceManager"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager");

var PhonePreview = require("text!lib/Mobile.html");
var PostMessageTransport = require("lib/PostMessageTransport");
Expand Down Expand Up @@ -90,6 +91,11 @@ define(function (require, exports, module) {
}
}

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

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 @@ -187,7 +187,8 @@ define(function (require, exports, module) {
sidebarWidth: data.state.sidebarWidth,
firstPaneWidth: data.state.firstPaneWidth,
secondPaneWidth: data.state.secondPaneWidth,
previewMode: data.state.previewMode
previewMode: data.state.previewMode,
wordWrap: data.state.wordWrap
});

deferred.resolve();
Expand Down

0 comments on commit 5bf8a0c

Please sign in to comment.