-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Conversation
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 |
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 |
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 |
Thanks for the suggestion. I have added About moving the registration of the |
$(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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to only show the checkmark when we actually finish establishing the connection (STATUS_ACTIVE).
Looks good--just had the one comment above. |
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.) |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: we generally put one space after //
and capitalize comments.
Added a couple more notes |
Thanks @njx! I have made change as per your comments. |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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);
One more little refinement suggestion. |
Ah..good point. Changed the code accordingly. |
Looks good, thanks. Merging. |
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.