Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for issue #1561 #1707

Merged
merged 7 commits into from

2 participants

@ckarande

For #1561, added logic to add / remove checkmark next to 'Live Preview' menu item.

The fix is added not exactly at TODOs, and outside of the if/else block to address the case of attempting to open non-htm files in live preview. In that case, the LiveDevelopment.status stays in STATUS_INACTIVE in the else block, so had to explicitly check it before adding the checkmark.

Please let me know if any suggestions.

Chetan Karande fix for issue 1561 f82a22a
@njx
Owner

Haven't tried this fix myself yet, but I think there might be a problem if the connection status changes due to something other than the menu command being executed. For example, if you open a live development connection, then go to the browser window and close it, the connection is closed, but this code won't get called (I think). The enablement logic should probably be in _setStatus() instead (which appears to be the bottleneck for status change notifications).

@ckarande

You are right, the code doesn't get called if user goes to browser and closes the Live Preview window directly.

One option could be to add checkmark in LiveDevelopment module's _onConnect() and remove it in _onDisconnect(). This would not be a bottleneck for status change notifications. This would require importing CommandManager and Commands in LiveDevelopment module though.

@njx
Owner

Ah, right, we should keep that dependency out of the LiveDevelopment module. The right thing to do is to set up a handler for the "statusChange" event to update the menu. You could add this in LiveDevelopment/main.js--take a look at _setupGoLiveButton() for how this works for the button in the toolbar. (You could create an analogous function, like _setupGoLiveMenu(), to attach the event handler, and move the registration of the command into that function. Or you could just go ahead and do it in the init() method below where we register the command.)

@ckarande

Thanks for the suggestion. I have added _setupGoLiveMenu() in LiveDevelopment/main.js that updates the checkmark based on "statusChange" event. The menu item checkmark works as expected with this fix and changes are available in ckarande:issue1561 branch.

About moving the registration of the FILE_LIVE_FILE_PREVIEW command into _setupGoLiveMenu(), in existing code, this registration happens outside of the init(). Moving it inside _setupGoLiveMenu() would cause exception while opening bracktets. Am I missing anything?

src/LiveDevelopment/main.js
@@ -155,6 +153,20 @@ define(function main(require, exports, module) {
// Initialize tooltip for 'not connected' state
_setLabel(_$btnGoLive, null, _statusStyle[1], _statusTooltip[1]);
}
+
+ /** maintains state of the menu item */
+ function _setupGoLiveMenu() {
+ $(LiveDevelopment).on("statusChange", function statusChange(event, status) {
+ //update the checkmark next to 'Live Preview' menu item
+ //add checkmark when status is STATUS_CONNECTING
+ if (status === LiveDevelopment.STATUS_CONNECTING) {
@njx Owner
njx added a note

I think it would be better to only show the checkmark when we actually finish establishing the connection (STATUS_ACTIVE).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@njx
Owner

Looks good--just had the one comment above.

@njx njx was assigned
@njx
Owner

FYI, if you reference the actual bug number with a "#" before it in the description or a comment (like this: #1561), it will link to the actual bug, and put a back-link to the pull request from the bug. (I edited your description to add it.)

src/LiveDevelopment/main.js
@@ -155,6 +153,20 @@ define(function main(require, exports, module) {
// Initialize tooltip for 'not connected' state
_setLabel(_$btnGoLive, null, _statusStyle[1], _statusTooltip[1]);
}
+
+ /** maintains state of the menu item */
+ function _setupGoLiveMenu() {
+ $(LiveDevelopment).on("statusChange", function statusChange(event, status) {
+ //update the checkmark next to 'Live Preview' menu item
+ //add checkmark when status is STATUS_CONNECTING
@njx Owner
njx added a note

Minor nit: we generally put one space after // and capitalize comments.

@njx Owner
njx added a note

Now that the following logic is simple, it would be cleaner to replace the whole if statement with:

CommandManager.get(Commands.FILE_LIVE_FILE_PREVIEW).setChecked(status === LiveDevelopment.STATUS_ACTIVE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/LiveDevelopment/main.js
@@ -155,6 +153,20 @@ define(function main(require, exports, module) {
// Initialize tooltip for 'not connected' state
_setLabel(_$btnGoLive, null, _statusStyle[1], _statusTooltip[1]);
}
+
+ /** maintains state of the menu item */
+ function _setupGoLiveMenu() {
+ $(LiveDevelopment).on("statusChange", function statusChange(event, status) {
+ //update the checkmark next to 'Live Preview' menu item
+ //add checkmark when status is STATUS_CONNECTING
+ if (status === LiveDevelopment.STATUS_CONNECTING) {
+ CommandManager.get(Commands.FILE_LIVE_FILE_PREVIEW).setChecked(true);
+ } else if (status < LiveDevelopment.STATUS_CONNECTING) {
+ //remove checkmark if status is STATUS_INACTIVE or STATUS_ERROR
+ CommandManager.get(Commands.FILE_LIVE_FILE_PREVIEW).setChecked(false);
@njx Owner
njx added a note

If we only show the checkmark when the status is STATUS_ACTIVE, then you could just remove it in all other cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@njx
Owner

Added a couple more notes

@ckarande

Thanks @njx! I have made change as per your comments.

@njx
Owner
njx commented

One more little refinement suggestion.

@ckarande

Ah..good point. Changed the code accordingly.

@njx
Owner
njx commented

Looks good, thanks. Merging.

@njx njx merged commit 238f3ec into from
@njx njx referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 24, 2012
  1. fix for issue 1561

    Chetan Karande authored
Commits on Sep 26, 2012
Commits on Sep 29, 2012
  1. Changes to add checkmark only for STATUS_ACTIVE

    Chetan Karande authored
  2. Unnecessary whitespace cleanup

    Chetan Karande authored
Commits on Oct 3, 2012
  1. Refined condition for adding checkmark

    Chetan Karande authored
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/LiveDevelopment/main.js
View
15 src/LiveDevelopment/main.js
@@ -118,7 +118,6 @@ define(function main(require, exports, module) {
function _handleGoLiveCommand() {
if (LiveDevelopment.status >= LiveDevelopment.STATUS_CONNECTING) {
LiveDevelopment.close();
- // TODO Ty: when checkmark support lands, remove checkmark
} else {
if (!params.get("skipLiveDevelopmentInfo") && !prefs.getValue("afterFirstLaunch")) {
prefs.setValue("afterFirstLaunch", "true");
@@ -132,7 +131,6 @@ define(function main(require, exports, module) {
} else {
LiveDevelopment.open();
}
- // TODO Ty: when checkmark support lands, add checkmark
}
}
@@ -155,6 +153,15 @@ define(function main(require, exports, module) {
// Initialize tooltip for 'not connected' state
_setLabel(_$btnGoLive, null, _statusStyle[1], _statusTooltip[1]);
}
+
+ /** Maintains state of the Live Preview menu item */
+ function _setupGoLiveMenu() {
+ $(LiveDevelopment).on("statusChange", function statusChange(event, status) {
+ // Update the checkmark next to 'Live Preview' menu item
+ // Add checkmark when status is STATUS_ACTIVE; otherwise remove it
+ CommandManager.get(Commands.FILE_LIVE_FILE_PREVIEW).setChecked(status === LiveDevelopment.STATUS_ACTIVE);
+ });
+ }
/** Create the menu item "Highlight" */
function _setupHighlightButton() {
@@ -191,6 +198,8 @@ define(function main(require, exports, module) {
LiveDevelopment.init(config);
_loadStyles();
_setupGoLiveButton();
+ _setupGoLiveMenu();
+
/* _setupHighlightButton(); FUTURE - Highlight button */
if (config.debug) {
_setupDebugHelpers();
@@ -211,7 +220,7 @@ define(function main(require, exports, module) {
}
}
window.setTimeout(init);
-
+
CommandManager.register(Strings.CMD_LIVE_FILE_PREVIEW, Commands.FILE_LIVE_FILE_PREVIEW, _handleGoLiveCommand);
// Export public functions
Something went wrong with that request. Please try again.